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 | b86fb2c | 2011-01-25 15:58:57 +0000 | [diff] [blame] | 7 | * Copyright (C) 2005-2011 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> |
| 29 | #include <linux/ioport.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/etherdevice.h> |
| 33 | #include <linux/skbuff.h> |
| 34 | #include <linux/ethtool.h> |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 35 | #include <linux/mdio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/mii.h> |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 37 | #include <linux/phy.h> |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 38 | #include <linux/brcmphy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/if_vlan.h> |
| 40 | #include <linux/ip.h> |
| 41 | #include <linux/tcp.h> |
| 42 | #include <linux/workqueue.h> |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 43 | #include <linux/prefetch.h> |
Tobias Klauser | f9a5f7d | 2005-10-29 15:09:26 +0200 | [diff] [blame] | 44 | #include <linux/dma-mapping.h> |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 45 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #include <net/checksum.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 48 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #include <asm/system.h> |
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 |
Matt Carlson | 64cad2a | 2011-04-25 12:42:50 +0000 | [diff] [blame] | 91 | #define TG3_MIN_NUM 118 |
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) |
Matt Carlson | 64cad2a | 2011-04-25 12:42:50 +0000 | [diff] [blame] | 94 | #define DRV_MODULE_RELDATE "April 22, 2011" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | #define TG3_DEF_MAC_MODE 0 |
| 97 | #define TG3_DEF_RX_MODE 0 |
| 98 | #define TG3_DEF_TX_MODE 0 |
| 99 | #define TG3_DEF_MSG_ENABLE \ |
| 100 | (NETIF_MSG_DRV | \ |
| 101 | NETIF_MSG_PROBE | \ |
| 102 | NETIF_MSG_LINK | \ |
| 103 | NETIF_MSG_TIMER | \ |
| 104 | NETIF_MSG_IFDOWN | \ |
| 105 | NETIF_MSG_IFUP | \ |
| 106 | NETIF_MSG_RX_ERR | \ |
| 107 | NETIF_MSG_TX_ERR) |
| 108 | |
| 109 | /* length of time before we decide the hardware is borked, |
| 110 | * and dev->tx_timeout() should be called to fix the problem |
| 111 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | #define TG3_TX_TIMEOUT (5 * HZ) |
| 114 | |
| 115 | /* hardware minimum and maximum for a single frame's data payload */ |
| 116 | #define TG3_MIN_MTU 60 |
| 117 | #define TG3_MAX_MTU(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 118 | (tg3_flag(tp, JUMBO_CAPABLE) ? 9000 : 1500) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | /* These numbers seem to be hard coded in the NIC firmware somehow. |
| 121 | * You can't change the ring sizes, but you can change where you place |
| 122 | * them in the NIC onboard memory. |
| 123 | */ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 124 | #define TG3_RX_STD_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 125 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 126 | TG3_RX_STD_MAX_SIZE_5717 : TG3_RX_STD_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | #define TG3_DEF_RX_RING_PENDING 200 |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 128 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 129 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 130 | TG3_RX_JMB_MAX_SIZE_5717 : TG3_RX_JMB_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 132 | #define TG3_RSS_INDIR_TBL_SIZE 128 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /* Do not place this n-ring entries value into the tp struct itself, |
| 135 | * we really want to expose these constants to GCC so that modulo et |
| 136 | * al. operations are done with shifts and masks instead of with |
| 137 | * hw multiply/modulo instructions. Another solution would be to |
| 138 | * replace things like '% foo' with '& (foo - 1)'. |
| 139 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | #define TG3_TX_RING_SIZE 512 |
| 142 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) |
| 143 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 144 | #define TG3_RX_STD_RING_BYTES(tp) \ |
| 145 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) |
| 146 | #define TG3_RX_JMB_RING_BYTES(tp) \ |
| 147 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) |
| 148 | #define TG3_RX_RCB_RING_BYTES(tp) \ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 149 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
| 151 | TG3_TX_RING_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
| 153 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 154 | #define TG3_DMA_BYTE_ENAB 64 |
| 155 | |
| 156 | #define TG3_RX_STD_DMA_SZ 1536 |
| 157 | #define TG3_RX_JMB_DMA_SZ 9046 |
| 158 | |
| 159 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) |
| 160 | |
| 161 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) |
| 162 | #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] | 163 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 164 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
| 165 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 166 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 167 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
| 168 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 169 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 170 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
| 171 | * that are at least dword aligned when used in PCIX mode. The driver |
| 172 | * works around this bug by double copying the packet. This workaround |
| 173 | * is built into the normal double copy length check for efficiency. |
| 174 | * |
| 175 | * However, the double copy is only necessary on those architectures |
| 176 | * where unaligned memory accesses are inefficient. For those architectures |
| 177 | * where unaligned memory accesses incur little penalty, we can reintegrate |
| 178 | * the 5701 in the normal rx path. Doing so saves a device structure |
| 179 | * dereference by hardcoding the double copy threshold in place. |
| 180 | */ |
| 181 | #define TG3_RX_COPY_THRESHOLD 256 |
| 182 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 183 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD |
| 184 | #else |
| 185 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) |
| 186 | #endif |
| 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | /* minimum number of free TX descriptors required to wake up TX process */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 189 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 191 | #define TG3_RAW_IP_ALIGN 2 |
| 192 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 193 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
| 194 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 195 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
| 196 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
| 197 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" |
| 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | static char version[] __devinitdata = |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 200 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); |
| 203 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); |
| 204 | MODULE_LICENSE("GPL"); |
| 205 | MODULE_VERSION(DRV_MODULE_VERSION); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 206 | MODULE_FIRMWARE(FIRMWARE_TG3); |
| 207 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); |
| 208 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
| 211 | module_param(tg3_debug, int, 0); |
| 212 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); |
| 213 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 214 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 215 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
| 216 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, |
| 217 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, |
| 218 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, |
| 219 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, |
| 220 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, |
| 221 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, |
| 222 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, |
| 223 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, |
| 224 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, |
| 225 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, |
| 226 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, |
| 227 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, |
| 228 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, |
| 229 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, |
| 230 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, |
| 231 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, |
| 232 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, |
| 233 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)}, |
| 234 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)}, |
| 235 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, |
| 236 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
| 241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)}, |
| 242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
| 243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, |
| 244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, |
| 245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, |
| 246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)}, |
| 247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
| 248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, |
| 249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, |
| 250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
| 253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, |
| 254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 255 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 256 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
| 257 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, |
| 258 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, |
| 259 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, |
| 260 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, |
| 261 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, |
| 262 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
| 264 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 265 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
| 266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
Matt Carlson | 6c7af27 | 2007-10-21 16:12:02 -0700 | [diff] [blame] | 267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
| 269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
Matt Carlson | c88e668 | 2008-11-03 16:49:18 -0800 | [diff] [blame] | 270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
| 271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, |
Matt Carlson | 2befdce | 2009-08-28 12:28:45 +0000 | [diff] [blame] | 272 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
| 273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
| 275 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, |
| 276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790)}, |
Matt Carlson | 5e7ccf2 | 2009-08-25 10:08:42 +0000 | [diff] [blame] | 277 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 278 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
| 279 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
Matt Carlson | b0f7522 | 2010-01-20 16:58:11 +0000 | [diff] [blame] | 280 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
| 281 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, |
| 282 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, |
| 283 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, |
| 284 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791)}, |
| 285 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)}, |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 286 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
Matt Carlson | ba1f3c7 | 2011-04-05 14:22:50 +0000 | [diff] [blame] | 287 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 288 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
| 289 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, |
| 290 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, |
| 291 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, |
| 292 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, |
| 293 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, |
| 294 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, |
| 295 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); |
| 299 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 300 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 302 | } ethtool_stats_keys[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { "rx_octets" }, |
| 304 | { "rx_fragments" }, |
| 305 | { "rx_ucast_packets" }, |
| 306 | { "rx_mcast_packets" }, |
| 307 | { "rx_bcast_packets" }, |
| 308 | { "rx_fcs_errors" }, |
| 309 | { "rx_align_errors" }, |
| 310 | { "rx_xon_pause_rcvd" }, |
| 311 | { "rx_xoff_pause_rcvd" }, |
| 312 | { "rx_mac_ctrl_rcvd" }, |
| 313 | { "rx_xoff_entered" }, |
| 314 | { "rx_frame_too_long_errors" }, |
| 315 | { "rx_jabbers" }, |
| 316 | { "rx_undersize_packets" }, |
| 317 | { "rx_in_length_errors" }, |
| 318 | { "rx_out_length_errors" }, |
| 319 | { "rx_64_or_less_octet_packets" }, |
| 320 | { "rx_65_to_127_octet_packets" }, |
| 321 | { "rx_128_to_255_octet_packets" }, |
| 322 | { "rx_256_to_511_octet_packets" }, |
| 323 | { "rx_512_to_1023_octet_packets" }, |
| 324 | { "rx_1024_to_1522_octet_packets" }, |
| 325 | { "rx_1523_to_2047_octet_packets" }, |
| 326 | { "rx_2048_to_4095_octet_packets" }, |
| 327 | { "rx_4096_to_8191_octet_packets" }, |
| 328 | { "rx_8192_to_9022_octet_packets" }, |
| 329 | |
| 330 | { "tx_octets" }, |
| 331 | { "tx_collisions" }, |
| 332 | |
| 333 | { "tx_xon_sent" }, |
| 334 | { "tx_xoff_sent" }, |
| 335 | { "tx_flow_control" }, |
| 336 | { "tx_mac_errors" }, |
| 337 | { "tx_single_collisions" }, |
| 338 | { "tx_mult_collisions" }, |
| 339 | { "tx_deferred" }, |
| 340 | { "tx_excessive_collisions" }, |
| 341 | { "tx_late_collisions" }, |
| 342 | { "tx_collide_2times" }, |
| 343 | { "tx_collide_3times" }, |
| 344 | { "tx_collide_4times" }, |
| 345 | { "tx_collide_5times" }, |
| 346 | { "tx_collide_6times" }, |
| 347 | { "tx_collide_7times" }, |
| 348 | { "tx_collide_8times" }, |
| 349 | { "tx_collide_9times" }, |
| 350 | { "tx_collide_10times" }, |
| 351 | { "tx_collide_11times" }, |
| 352 | { "tx_collide_12times" }, |
| 353 | { "tx_collide_13times" }, |
| 354 | { "tx_collide_14times" }, |
| 355 | { "tx_collide_15times" }, |
| 356 | { "tx_ucast_packets" }, |
| 357 | { "tx_mcast_packets" }, |
| 358 | { "tx_bcast_packets" }, |
| 359 | { "tx_carrier_sense_errors" }, |
| 360 | { "tx_discards" }, |
| 361 | { "tx_errors" }, |
| 362 | |
| 363 | { "dma_writeq_full" }, |
| 364 | { "dma_write_prioq_full" }, |
| 365 | { "rxbds_empty" }, |
| 366 | { "rx_discards" }, |
| 367 | { "rx_errors" }, |
| 368 | { "rx_threshold_hit" }, |
| 369 | |
| 370 | { "dma_readq_full" }, |
| 371 | { "dma_read_prioq_full" }, |
| 372 | { "tx_comp_queue_full" }, |
| 373 | |
| 374 | { "ring_set_send_prod_index" }, |
| 375 | { "ring_status_update" }, |
| 376 | { "nic_irqs" }, |
| 377 | { "nic_avoided_irqs" }, |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 378 | { "nic_tx_threshold_hit" }, |
| 379 | |
| 380 | { "mbuf_lwm_thresh_hit" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | }; |
| 382 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 383 | #define TG3_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) |
| 384 | |
| 385 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 386 | static const struct { |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 387 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 388 | } ethtool_test_keys[] = { |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 389 | { "nvram test (online) " }, |
| 390 | { "link test (online) " }, |
| 391 | { "register test (offline)" }, |
| 392 | { "memory test (offline)" }, |
| 393 | { "loopback test (offline)" }, |
| 394 | { "interrupt test (offline)" }, |
| 395 | }; |
| 396 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 397 | #define TG3_NUM_TEST ARRAY_SIZE(ethtool_test_keys) |
| 398 | |
| 399 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 400 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
| 401 | { |
| 402 | writel(val, tp->regs + off); |
| 403 | } |
| 404 | |
| 405 | static u32 tg3_read32(struct tg3 *tp, u32 off) |
| 406 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 407 | return readl(tp->regs + off); |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 410 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
| 411 | { |
| 412 | writel(val, tp->aperegs + off); |
| 413 | } |
| 414 | |
| 415 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) |
| 416 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 417 | return readl(tp->aperegs + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
| 421 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 422 | unsigned long flags; |
| 423 | |
| 424 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 425 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 426 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 427 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) |
| 431 | { |
| 432 | writel(val, tp->regs + off); |
| 433 | readl(tp->regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 436 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
| 437 | { |
| 438 | unsigned long flags; |
| 439 | u32 val; |
| 440 | |
| 441 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 442 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 443 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 444 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 445 | return val; |
| 446 | } |
| 447 | |
| 448 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) |
| 449 | { |
| 450 | unsigned long flags; |
| 451 | |
| 452 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { |
| 453 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + |
| 454 | TG3_64BIT_REG_LOW, val); |
| 455 | return; |
| 456 | } |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 457 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 458 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
| 459 | TG3_64BIT_REG_LOW, val); |
| 460 | return; |
| 461 | } |
| 462 | |
| 463 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 464 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 465 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 466 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 467 | |
| 468 | /* In indirect mode when disabling interrupts, we also need |
| 469 | * to clear the interrupt bit in the GRC local ctrl register. |
| 470 | */ |
| 471 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && |
| 472 | (val == 0x1)) { |
| 473 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, |
| 474 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) |
| 479 | { |
| 480 | unsigned long flags; |
| 481 | u32 val; |
| 482 | |
| 483 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 484 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 485 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 486 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 487 | return val; |
| 488 | } |
| 489 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 490 | /* usec_wait specifies the wait time in usec when writing to certain registers |
| 491 | * where it is unsafe to read back the register without some delay. |
| 492 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. |
| 493 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. |
| 494 | */ |
| 495 | 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] | 496 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 497 | if (tg3_flag(tp, PCIX_TARGET_HWBUG) || tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 498 | /* Non-posted methods */ |
| 499 | tp->write32(tp, off, val); |
| 500 | else { |
| 501 | /* Posted method */ |
| 502 | tg3_write32(tp, off, val); |
| 503 | if (usec_wait) |
| 504 | udelay(usec_wait); |
| 505 | tp->read32(tp, off); |
| 506 | } |
| 507 | /* Wait again after the read for the posted method to guarantee that |
| 508 | * the wait time is met. |
| 509 | */ |
| 510 | if (usec_wait) |
| 511 | udelay(usec_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 514 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
| 515 | { |
| 516 | tp->write32_mbox(tp, off, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 517 | if (!tg3_flag(tp, MBOX_WRITE_REORDER) && !tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 518 | tp->read32_mbox(tp, off); |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 521 | 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] | 522 | { |
| 523 | void __iomem *mbox = tp->regs + off; |
| 524 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 525 | if (tg3_flag(tp, TXD_MBOX_HWBUG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 527 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | readl(mbox); |
| 529 | } |
| 530 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 531 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
| 532 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 533 | return readl(tp->regs + off + GRCMBOX_BASE); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) |
| 537 | { |
| 538 | writel(val, tp->regs + off + GRCMBOX_BASE); |
| 539 | } |
| 540 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 541 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 542 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 543 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
| 544 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) |
| 545 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 546 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 547 | #define tw32(reg, val) tp->write32(tp, reg, val) |
| 548 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) |
| 549 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) |
| 550 | #define tr32(reg) tp->read32(tp, reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) |
| 553 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 554 | unsigned long flags; |
| 555 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 556 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
| 557 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
| 558 | return; |
| 559 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 560 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 561 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 562 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 563 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 565 | /* Always leave this as zero. */ |
| 566 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 567 | } else { |
| 568 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 569 | tw32_f(TG3PCI_MEM_WIN_DATA, val); |
| 570 | |
| 571 | /* Always leave this as zero. */ |
| 572 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 573 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 574 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | static void tg3_read_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 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 581 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
| 582 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
| 583 | *val = 0; |
| 584 | return; |
| 585 | } |
| 586 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 587 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 588 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 589 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 590 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 592 | /* Always leave this as zero. */ |
| 593 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 594 | } else { |
| 595 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 596 | *val = tr32(TG3PCI_MEM_WIN_DATA); |
| 597 | |
| 598 | /* Always leave this as zero. */ |
| 599 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 600 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 601 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 604 | static void tg3_ape_lock_init(struct tg3 *tp) |
| 605 | { |
| 606 | int i; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 607 | u32 regbase; |
| 608 | |
| 609 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 610 | regbase = TG3_APE_LOCK_GRANT; |
| 611 | else |
| 612 | regbase = TG3_APE_PER_LOCK_GRANT; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 613 | |
| 614 | /* Make sure the driver hasn't any stale locks. */ |
| 615 | for (i = 0; i < 8; i++) |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 616 | tg3_ape_write32(tp, regbase + 4 * i, APE_LOCK_GRANT_DRIVER); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | static int tg3_ape_lock(struct tg3 *tp, int locknum) |
| 620 | { |
| 621 | int i, off; |
| 622 | int ret = 0; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 623 | u32 status, req, gnt; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 624 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 625 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 626 | return 0; |
| 627 | |
| 628 | switch (locknum) { |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 629 | case TG3_APE_LOCK_GRC: |
| 630 | case TG3_APE_LOCK_MEM: |
| 631 | break; |
| 632 | default: |
| 633 | return -EINVAL; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 634 | } |
| 635 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 636 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
| 637 | req = TG3_APE_LOCK_REQ; |
| 638 | gnt = TG3_APE_LOCK_GRANT; |
| 639 | } else { |
| 640 | req = TG3_APE_PER_LOCK_REQ; |
| 641 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 642 | } |
| 643 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 644 | off = 4 * locknum; |
| 645 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 646 | tg3_ape_write32(tp, req + off, APE_LOCK_REQ_DRIVER); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 647 | |
| 648 | /* Wait for up to 1 millisecond to acquire lock. */ |
| 649 | for (i = 0; i < 100; i++) { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 650 | status = tg3_ape_read32(tp, gnt + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 651 | if (status == APE_LOCK_GRANT_DRIVER) |
| 652 | break; |
| 653 | udelay(10); |
| 654 | } |
| 655 | |
| 656 | if (status != APE_LOCK_GRANT_DRIVER) { |
| 657 | /* Revoke the lock request. */ |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 658 | tg3_ape_write32(tp, gnt + off, |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 659 | APE_LOCK_GRANT_DRIVER); |
| 660 | |
| 661 | ret = -EBUSY; |
| 662 | } |
| 663 | |
| 664 | return ret; |
| 665 | } |
| 666 | |
| 667 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) |
| 668 | { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 669 | u32 gnt; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 670 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 671 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 672 | return; |
| 673 | |
| 674 | switch (locknum) { |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 675 | case TG3_APE_LOCK_GRC: |
| 676 | case TG3_APE_LOCK_MEM: |
| 677 | break; |
| 678 | default: |
| 679 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 682 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 683 | gnt = TG3_APE_LOCK_GRANT; |
| 684 | else |
| 685 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 686 | |
| 687 | tg3_ape_write32(tp, gnt + 4 * locknum, APE_LOCK_GRANT_DRIVER); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | static void tg3_disable_ints(struct tg3 *tp) |
| 691 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 692 | int i; |
| 693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 695 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 696 | for (i = 0; i < tp->irq_max; i++) |
| 697 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | static void tg3_enable_ints(struct tg3 *tp) |
| 701 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 702 | int i; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 703 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 704 | tp->irq_sync = 0; |
| 705 | wmb(); |
| 706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 708 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 709 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 710 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 711 | for (i = 0; i < tp->irq_cnt; i++) { |
| 712 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 713 | |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 714 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 715 | if (tg3_flag(tp, 1SHOT_MSI)) |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 716 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 717 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 718 | tp->coal_now |= tnapi->coal_now; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 719 | } |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 720 | |
| 721 | /* Force an initial interrupt */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 722 | if (!tg3_flag(tp, TAGGED_STATUS) && |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 723 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
| 724 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 725 | else |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 726 | tw32(HOSTCC_MODE, tp->coal_now); |
| 727 | |
| 728 | 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] | 729 | } |
| 730 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 731 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 732 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 733 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 734 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 735 | unsigned int work_exists = 0; |
| 736 | |
| 737 | /* check for phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 738 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 739 | if (sblk->status & SD_STATUS_LINK_CHG) |
| 740 | work_exists = 1; |
| 741 | } |
| 742 | /* check for RX/TX work to do */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 743 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons || |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 744 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 745 | work_exists = 1; |
| 746 | |
| 747 | return work_exists; |
| 748 | } |
| 749 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 750 | /* tg3_int_reenable |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 751 | * similar to tg3_enable_ints, but it accurately determines whether there |
| 752 | * is new work pending and can return without flushing the PIO write |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 753 | * which reenables interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 755 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 757 | struct tg3 *tp = tnapi->tp; |
| 758 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 759 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | mmiowb(); |
| 761 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 762 | /* When doing tagged status, this work check is unnecessary. |
| 763 | * The last_tag we write above tells the chip which piece of |
| 764 | * work we've completed. |
| 765 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 766 | if (!tg3_flag(tp, TAGGED_STATUS) && tg3_has_work(tnapi)) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 767 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 768 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | static void tg3_switch_clocks(struct tg3 *tp) |
| 772 | { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 773 | u32 clock_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | u32 orig_clock_ctrl; |
| 775 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 776 | if (tg3_flag(tp, CPMU_PRESENT) || tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 777 | return; |
| 778 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 779 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
| 780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | orig_clock_ctrl = clock_ctrl; |
| 782 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | |
| 783 | CLOCK_CTRL_CLKRUN_OENABLE | |
| 784 | 0x1f); |
| 785 | tp->pci_clock_ctrl = clock_ctrl; |
| 786 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 787 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 789 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 790 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
| 792 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 793 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 794 | clock_ctrl | |
| 795 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), |
| 796 | 40); |
| 797 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 798 | clock_ctrl | (CLOCK_CTRL_ALTCLK), |
| 799 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 801 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | #define PHY_BUSY_LOOPS 5000 |
| 805 | |
| 806 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
| 807 | { |
| 808 | u32 frame_val; |
| 809 | unsigned int loops; |
| 810 | int ret; |
| 811 | |
| 812 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 813 | tw32_f(MAC_MI_MODE, |
| 814 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 815 | udelay(80); |
| 816 | } |
| 817 | |
| 818 | *val = 0x0; |
| 819 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 820 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | MI_COM_PHY_ADDR_MASK); |
| 822 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 823 | MI_COM_REG_ADDR_MASK); |
| 824 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | tw32_f(MAC_MI_COM, frame_val); |
| 827 | |
| 828 | loops = PHY_BUSY_LOOPS; |
| 829 | while (loops != 0) { |
| 830 | udelay(10); |
| 831 | frame_val = tr32(MAC_MI_COM); |
| 832 | |
| 833 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 834 | udelay(5); |
| 835 | frame_val = tr32(MAC_MI_COM); |
| 836 | break; |
| 837 | } |
| 838 | loops -= 1; |
| 839 | } |
| 840 | |
| 841 | ret = -EBUSY; |
| 842 | if (loops != 0) { |
| 843 | *val = frame_val & MI_COM_DATA_MASK; |
| 844 | ret = 0; |
| 845 | } |
| 846 | |
| 847 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 848 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 849 | udelay(80); |
| 850 | } |
| 851 | |
| 852 | return ret; |
| 853 | } |
| 854 | |
| 855 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
| 856 | { |
| 857 | u32 frame_val; |
| 858 | unsigned int loops; |
| 859 | int ret; |
| 860 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 861 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 862 | (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL)) |
| 863 | return 0; |
| 864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 866 | tw32_f(MAC_MI_MODE, |
| 867 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 868 | udelay(80); |
| 869 | } |
| 870 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 871 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | MI_COM_PHY_ADDR_MASK); |
| 873 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 874 | MI_COM_REG_ADDR_MASK); |
| 875 | frame_val |= (val & MI_COM_DATA_MASK); |
| 876 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | tw32_f(MAC_MI_COM, frame_val); |
| 879 | |
| 880 | loops = PHY_BUSY_LOOPS; |
| 881 | while (loops != 0) { |
| 882 | udelay(10); |
| 883 | frame_val = tr32(MAC_MI_COM); |
| 884 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 885 | udelay(5); |
| 886 | frame_val = tr32(MAC_MI_COM); |
| 887 | break; |
| 888 | } |
| 889 | loops -= 1; |
| 890 | } |
| 891 | |
| 892 | ret = -EBUSY; |
| 893 | if (loops != 0) |
| 894 | ret = 0; |
| 895 | |
| 896 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 897 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 898 | udelay(80); |
| 899 | } |
| 900 | |
| 901 | return ret; |
| 902 | } |
| 903 | |
Matt Carlson | b0988c1 | 2011-04-20 07:57:39 +0000 | [diff] [blame] | 904 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
| 905 | { |
| 906 | int err; |
| 907 | |
| 908 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 909 | if (err) |
| 910 | goto done; |
| 911 | |
| 912 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 913 | if (err) |
| 914 | goto done; |
| 915 | |
| 916 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 917 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 918 | if (err) |
| 919 | goto done; |
| 920 | |
| 921 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); |
| 922 | |
| 923 | done: |
| 924 | return err; |
| 925 | } |
| 926 | |
| 927 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) |
| 928 | { |
| 929 | int err; |
| 930 | |
| 931 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 932 | if (err) |
| 933 | goto done; |
| 934 | |
| 935 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 936 | if (err) |
| 937 | goto done; |
| 938 | |
| 939 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 940 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 941 | if (err) |
| 942 | goto done; |
| 943 | |
| 944 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); |
| 945 | |
| 946 | done: |
| 947 | return err; |
| 948 | } |
| 949 | |
| 950 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) |
| 951 | { |
| 952 | int err; |
| 953 | |
| 954 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 955 | if (!err) |
| 956 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); |
| 957 | |
| 958 | return err; |
| 959 | } |
| 960 | |
| 961 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
| 962 | { |
| 963 | int err; |
| 964 | |
| 965 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 966 | if (!err) |
| 967 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); |
| 968 | |
| 969 | return err; |
| 970 | } |
| 971 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 972 | static int tg3_phy_auxctl_read(struct tg3 *tp, int reg, u32 *val) |
| 973 | { |
| 974 | int err; |
| 975 | |
| 976 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 977 | (reg << MII_TG3_AUXCTL_MISC_RDSEL_SHIFT) | |
| 978 | MII_TG3_AUXCTL_SHDWSEL_MISC); |
| 979 | if (!err) |
| 980 | err = tg3_readphy(tp, MII_TG3_AUX_CTRL, val); |
| 981 | |
| 982 | return err; |
| 983 | } |
| 984 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 985 | static int tg3_phy_auxctl_write(struct tg3 *tp, int reg, u32 set) |
| 986 | { |
| 987 | if (reg == MII_TG3_AUXCTL_SHDWSEL_MISC) |
| 988 | set |= MII_TG3_AUXCTL_MISC_WREN; |
| 989 | |
| 990 | return tg3_writephy(tp, MII_TG3_AUX_CTRL, set | reg); |
| 991 | } |
| 992 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 993 | #define TG3_PHY_AUXCTL_SMDSP_ENABLE(tp) \ |
| 994 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ |
| 995 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | \ |
| 996 | MII_TG3_AUXCTL_ACTL_TX_6DB) |
| 997 | |
| 998 | #define TG3_PHY_AUXCTL_SMDSP_DISABLE(tp) \ |
| 999 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ |
| 1000 | MII_TG3_AUXCTL_ACTL_TX_6DB); |
| 1001 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1002 | static int tg3_bmcr_reset(struct tg3 *tp) |
| 1003 | { |
| 1004 | u32 phy_control; |
| 1005 | int limit, err; |
| 1006 | |
| 1007 | /* OK, reset it, and poll the BMCR_RESET bit until it |
| 1008 | * clears or we time out. |
| 1009 | */ |
| 1010 | phy_control = BMCR_RESET; |
| 1011 | err = tg3_writephy(tp, MII_BMCR, phy_control); |
| 1012 | if (err != 0) |
| 1013 | return -EBUSY; |
| 1014 | |
| 1015 | limit = 5000; |
| 1016 | while (limit--) { |
| 1017 | err = tg3_readphy(tp, MII_BMCR, &phy_control); |
| 1018 | if (err != 0) |
| 1019 | return -EBUSY; |
| 1020 | |
| 1021 | if ((phy_control & BMCR_RESET) == 0) { |
| 1022 | udelay(40); |
| 1023 | break; |
| 1024 | } |
| 1025 | udelay(10); |
| 1026 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 1027 | if (limit < 0) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1028 | return -EBUSY; |
| 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1033 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
| 1034 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1035 | struct tg3 *tp = bp->priv; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1036 | u32 val; |
| 1037 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1038 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1039 | |
| 1040 | if (tg3_readphy(tp, reg, &val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1041 | val = -EIO; |
| 1042 | |
| 1043 | spin_unlock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1044 | |
| 1045 | return val; |
| 1046 | } |
| 1047 | |
| 1048 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) |
| 1049 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1050 | struct tg3 *tp = bp->priv; |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1051 | u32 ret = 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1052 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1053 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1054 | |
| 1055 | if (tg3_writephy(tp, reg, val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1056 | ret = -EIO; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1057 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1058 | spin_unlock_bh(&tp->lock); |
| 1059 | |
| 1060 | return ret; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | static int tg3_mdio_reset(struct mii_bus *bp) |
| 1064 | { |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1068 | static void tg3_mdio_config_5785(struct tg3 *tp) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1069 | { |
| 1070 | u32 val; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1071 | struct phy_device *phydev; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1072 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1073 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1074 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1075 | case PHY_ID_BCM50610: |
| 1076 | case PHY_ID_BCM50610M: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1077 | val = MAC_PHYCFG2_50610_LED_MODES; |
| 1078 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1079 | case PHY_ID_BCMAC131: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1080 | val = MAC_PHYCFG2_AC131_LED_MODES; |
| 1081 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1082 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1083 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
| 1084 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1085 | case PHY_ID_RTL8201E: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1086 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
| 1087 | break; |
| 1088 | default: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1089 | return; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { |
| 1093 | tw32(MAC_PHYCFG2, val); |
| 1094 | |
| 1095 | val = tr32(MAC_PHYCFG1); |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1096 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
| 1097 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); |
| 1098 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1099 | tw32(MAC_PHYCFG1, val); |
| 1100 | |
| 1101 | return; |
| 1102 | } |
| 1103 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1104 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1105 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
| 1106 | MAC_PHYCFG2_FMODE_MASK_MASK | |
| 1107 | MAC_PHYCFG2_GMODE_MASK_MASK | |
| 1108 | MAC_PHYCFG2_ACT_MASK_MASK | |
| 1109 | MAC_PHYCFG2_QUAL_MASK_MASK | |
| 1110 | MAC_PHYCFG2_INBAND_ENABLE; |
| 1111 | |
| 1112 | tw32(MAC_PHYCFG2, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1113 | |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1114 | val = tr32(MAC_PHYCFG1); |
| 1115 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | |
| 1116 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1117 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1118 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1119 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1120 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1121 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
| 1122 | } |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1123 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
| 1124 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; |
| 1125 | tw32(MAC_PHYCFG1, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1126 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1127 | val = tr32(MAC_EXT_RGMII_MODE); |
| 1128 | val &= ~(MAC_RGMII_MODE_RX_INT_B | |
| 1129 | MAC_RGMII_MODE_RX_QUALITY | |
| 1130 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1131 | MAC_RGMII_MODE_RX_ENG_DET | |
| 1132 | MAC_RGMII_MODE_TX_ENABLE | |
| 1133 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1134 | MAC_RGMII_MODE_TX_RESET); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1135 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1136 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1137 | val |= MAC_RGMII_MODE_RX_INT_B | |
| 1138 | MAC_RGMII_MODE_RX_QUALITY | |
| 1139 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1140 | MAC_RGMII_MODE_RX_ENG_DET; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1141 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1142 | val |= MAC_RGMII_MODE_TX_ENABLE | |
| 1143 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1144 | MAC_RGMII_MODE_TX_RESET; |
| 1145 | } |
| 1146 | tw32(MAC_EXT_RGMII_MODE, val); |
| 1147 | } |
| 1148 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1149 | static void tg3_mdio_start(struct tg3 *tp) |
| 1150 | { |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1151 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
| 1152 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1153 | udelay(80); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1154 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1155 | if (tg3_flag(tp, MDIOBUS_INITED) && |
Matt Carlson | 9ea4818 | 2010-02-17 15:17:01 +0000 | [diff] [blame] | 1156 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1157 | tg3_mdio_config_5785(tp); |
| 1158 | } |
| 1159 | |
| 1160 | static int tg3_mdio_init(struct tg3 *tp) |
| 1161 | { |
| 1162 | int i; |
| 1163 | u32 reg; |
| 1164 | struct phy_device *phydev; |
| 1165 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1166 | if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1167 | u32 is_serdes; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1168 | |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1169 | tp->phy_addr = PCI_FUNC(tp->pdev->devfn) + 1; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1170 | |
Matt Carlson | d1ec96a | 2010-01-12 10:11:38 +0000 | [diff] [blame] | 1171 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
| 1172 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
| 1173 | else |
| 1174 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & |
| 1175 | TG3_CPMU_PHY_STRAP_IS_SERDES; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1176 | if (is_serdes) |
| 1177 | tp->phy_addr += 7; |
| 1178 | } else |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1179 | tp->phy_addr = TG3_PHY_MII_ADDR; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1180 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1181 | tg3_mdio_start(tp); |
| 1182 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1183 | if (!tg3_flag(tp, USE_PHYLIB) || tg3_flag(tp, MDIOBUS_INITED)) |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1184 | return 0; |
| 1185 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1186 | tp->mdio_bus = mdiobus_alloc(); |
| 1187 | if (tp->mdio_bus == NULL) |
| 1188 | return -ENOMEM; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1189 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1190 | tp->mdio_bus->name = "tg3 mdio bus"; |
| 1191 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1192 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1193 | tp->mdio_bus->priv = tp; |
| 1194 | tp->mdio_bus->parent = &tp->pdev->dev; |
| 1195 | tp->mdio_bus->read = &tg3_mdio_read; |
| 1196 | tp->mdio_bus->write = &tg3_mdio_write; |
| 1197 | tp->mdio_bus->reset = &tg3_mdio_reset; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1198 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1199 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1200 | |
| 1201 | for (i = 0; i < PHY_MAX_ADDR; i++) |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1202 | tp->mdio_bus->irq[i] = PHY_POLL; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1203 | |
| 1204 | /* The bus registration will look for all the PHYs on the mdio bus. |
| 1205 | * Unfortunately, it does not ensure the PHY is powered up before |
| 1206 | * accessing the PHY ID registers. A chip reset is the |
| 1207 | * quickest way to bring the device back to an operational state.. |
| 1208 | */ |
| 1209 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
| 1210 | tg3_bmcr_reset(tp); |
| 1211 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1212 | i = mdiobus_register(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1213 | if (i) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1214 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1215 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1216 | return i; |
| 1217 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1218 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1219 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1220 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1221 | if (!phydev || !phydev->drv) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1222 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1223 | mdiobus_unregister(tp->mdio_bus); |
| 1224 | mdiobus_free(tp->mdio_bus); |
| 1225 | return -ENODEV; |
| 1226 | } |
| 1227 | |
| 1228 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1229 | case PHY_ID_BCM57780: |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1230 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1231 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1232 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1233 | case PHY_ID_BCM50610: |
| 1234 | case PHY_ID_BCM50610M: |
Matt Carlson | 32e5a8d | 2009-11-02 14:31:39 +0000 | [diff] [blame] | 1235 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1236 | PHY_BRCM_RX_REFCLK_UNUSED | |
Matt Carlson | 52fae08 | 2009-11-02 14:32:38 +0000 | [diff] [blame] | 1237 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1238 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1239 | if (tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1240 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1241 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1242 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1243 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1244 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1245 | /* fallthru */ |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1246 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1247 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1248 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1249 | case PHY_ID_RTL8201E: |
| 1250 | case PHY_ID_BCMAC131: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1251 | phydev->interface = PHY_INTERFACE_MODE_MII; |
Matt Carlson | cdd4e09d | 2009-11-02 14:31:11 +0000 | [diff] [blame] | 1252 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1253 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1254 | break; |
| 1255 | } |
| 1256 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1257 | tg3_flag_set(tp, MDIOBUS_INITED); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1258 | |
| 1259 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1260 | tg3_mdio_config_5785(tp); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1261 | |
| 1262 | return 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | static void tg3_mdio_fini(struct tg3 *tp) |
| 1266 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1267 | if (tg3_flag(tp, MDIOBUS_INITED)) { |
| 1268 | tg3_flag_clear(tp, MDIOBUS_INITED); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1269 | mdiobus_unregister(tp->mdio_bus); |
| 1270 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1274 | /* tp->lock is held. */ |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1275 | static inline void tg3_generate_fw_event(struct tg3 *tp) |
| 1276 | { |
| 1277 | u32 val; |
| 1278 | |
| 1279 | val = tr32(GRC_RX_CPU_EVENT); |
| 1280 | val |= GRC_RX_CPU_DRIVER_EVENT; |
| 1281 | tw32_f(GRC_RX_CPU_EVENT, val); |
| 1282 | |
| 1283 | tp->last_event_jiffies = jiffies; |
| 1284 | } |
| 1285 | |
| 1286 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 |
| 1287 | |
| 1288 | /* tp->lock is held. */ |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1289 | static void tg3_wait_for_event_ack(struct tg3 *tp) |
| 1290 | { |
| 1291 | int i; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1292 | unsigned int delay_cnt; |
| 1293 | long time_remain; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1294 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1295 | /* If enough time has passed, no wait is necessary. */ |
| 1296 | time_remain = (long)(tp->last_event_jiffies + 1 + |
| 1297 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - |
| 1298 | (long)jiffies; |
| 1299 | if (time_remain < 0) |
| 1300 | return; |
| 1301 | |
| 1302 | /* Check if we can shorten the wait time. */ |
| 1303 | delay_cnt = jiffies_to_usecs(time_remain); |
| 1304 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) |
| 1305 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; |
| 1306 | delay_cnt = (delay_cnt >> 3) + 1; |
| 1307 | |
| 1308 | for (i = 0; i < delay_cnt; i++) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1309 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
| 1310 | break; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1311 | udelay(8); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | /* tp->lock is held. */ |
| 1316 | static void tg3_ump_link_report(struct tg3 *tp) |
| 1317 | { |
| 1318 | u32 reg; |
| 1319 | u32 val; |
| 1320 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1321 | if (!tg3_flag(tp, 5780_CLASS) || !tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1322 | return; |
| 1323 | |
| 1324 | tg3_wait_for_event_ack(tp); |
| 1325 | |
| 1326 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); |
| 1327 | |
| 1328 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); |
| 1329 | |
| 1330 | val = 0; |
| 1331 | if (!tg3_readphy(tp, MII_BMCR, ®)) |
| 1332 | val = reg << 16; |
| 1333 | if (!tg3_readphy(tp, MII_BMSR, ®)) |
| 1334 | val |= (reg & 0xffff); |
| 1335 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, val); |
| 1336 | |
| 1337 | val = 0; |
| 1338 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) |
| 1339 | val = reg << 16; |
| 1340 | if (!tg3_readphy(tp, MII_LPA, ®)) |
| 1341 | val |= (reg & 0xffff); |
| 1342 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 4, val); |
| 1343 | |
| 1344 | val = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1345 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1346 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
| 1347 | val = reg << 16; |
| 1348 | if (!tg3_readphy(tp, MII_STAT1000, ®)) |
| 1349 | val |= (reg & 0xffff); |
| 1350 | } |
| 1351 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 8, val); |
| 1352 | |
| 1353 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) |
| 1354 | val = reg << 16; |
| 1355 | else |
| 1356 | val = 0; |
| 1357 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val); |
| 1358 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1359 | tg3_generate_fw_event(tp); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | static void tg3_link_report(struct tg3 *tp) |
| 1363 | { |
| 1364 | if (!netif_carrier_ok(tp->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1365 | netif_info(tp, link, tp->dev, "Link is down\n"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1366 | tg3_ump_link_report(tp); |
| 1367 | } else if (netif_msg_link(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1368 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
| 1369 | (tp->link_config.active_speed == SPEED_1000 ? |
| 1370 | 1000 : |
| 1371 | (tp->link_config.active_speed == SPEED_100 ? |
| 1372 | 100 : 10)), |
| 1373 | (tp->link_config.active_duplex == DUPLEX_FULL ? |
| 1374 | "full" : "half")); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1375 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1376 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", |
| 1377 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? |
| 1378 | "on" : "off", |
| 1379 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? |
| 1380 | "on" : "off"); |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 1381 | |
| 1382 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) |
| 1383 | netdev_info(tp->dev, "EEE is %s\n", |
| 1384 | tp->setlpicnt ? "enabled" : "disabled"); |
| 1385 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1386 | tg3_ump_link_report(tp); |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl) |
| 1391 | { |
| 1392 | u16 miireg; |
| 1393 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1394 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1395 | miireg = ADVERTISE_PAUSE_CAP; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1396 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1397 | miireg = ADVERTISE_PAUSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1398 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1399 | miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1400 | else |
| 1401 | miireg = 0; |
| 1402 | |
| 1403 | return miireg; |
| 1404 | } |
| 1405 | |
| 1406 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
| 1407 | { |
| 1408 | u16 miireg; |
| 1409 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1410 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1411 | miireg = ADVERTISE_1000XPAUSE; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1412 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1413 | miireg = ADVERTISE_1000XPSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1414 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1415 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
| 1416 | else |
| 1417 | miireg = 0; |
| 1418 | |
| 1419 | return miireg; |
| 1420 | } |
| 1421 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1422 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
| 1423 | { |
| 1424 | u8 cap = 0; |
| 1425 | |
| 1426 | if (lcladv & ADVERTISE_1000XPAUSE) { |
| 1427 | if (lcladv & ADVERTISE_1000XPSE_ASYM) { |
| 1428 | if (rmtadv & LPA_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1429 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1430 | else if (rmtadv & LPA_1000XPAUSE_ASYM) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1431 | cap = FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1432 | } else { |
| 1433 | if (rmtadv & LPA_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1434 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1435 | } |
| 1436 | } else if (lcladv & ADVERTISE_1000XPSE_ASYM) { |
| 1437 | if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM)) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1438 | cap = FLOW_CTRL_TX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | return cap; |
| 1442 | } |
| 1443 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1444 | 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] | 1445 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1446 | u8 autoneg; |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1447 | u8 flowctrl = 0; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1448 | u32 old_rx_mode = tp->rx_mode; |
| 1449 | u32 old_tx_mode = tp->tx_mode; |
| 1450 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1451 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1452 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1453 | else |
| 1454 | autoneg = tp->link_config.autoneg; |
| 1455 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1456 | if (autoneg == AUTONEG_ENABLE && tg3_flag(tp, PAUSE_AUTONEG)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1457 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1458 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1459 | else |
Steve Glendinning | bc02ff9 | 2008-12-16 02:00:48 -0800 | [diff] [blame] | 1460 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1461 | } else |
| 1462 | flowctrl = tp->link_config.flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1463 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1464 | tp->link_config.active_flowctrl = flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1465 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1466 | if (flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1467 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
| 1468 | else |
| 1469 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; |
| 1470 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1471 | if (old_rx_mode != tp->rx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1472 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1473 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1474 | if (flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1475 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
| 1476 | else |
| 1477 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; |
| 1478 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1479 | if (old_tx_mode != tp->tx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1480 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1483 | static void tg3_adjust_link(struct net_device *dev) |
| 1484 | { |
| 1485 | u8 oldflowctrl, linkmesg = 0; |
| 1486 | u32 mac_mode, lcl_adv, rmt_adv; |
| 1487 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1488 | 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] | 1489 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1490 | spin_lock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1491 | |
| 1492 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | |
| 1493 | MAC_MODE_HALF_DUPLEX); |
| 1494 | |
| 1495 | oldflowctrl = tp->link_config.active_flowctrl; |
| 1496 | |
| 1497 | if (phydev->link) { |
| 1498 | lcl_adv = 0; |
| 1499 | rmt_adv = 0; |
| 1500 | |
| 1501 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) |
| 1502 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1503 | else if (phydev->speed == SPEED_1000 || |
| 1504 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1505 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1506 | else |
| 1507 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1508 | |
| 1509 | if (phydev->duplex == DUPLEX_HALF) |
| 1510 | mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 1511 | else { |
| 1512 | lcl_adv = tg3_advert_flowctrl_1000T( |
| 1513 | tp->link_config.flowctrl); |
| 1514 | |
| 1515 | if (phydev->pause) |
| 1516 | rmt_adv = LPA_PAUSE_CAP; |
| 1517 | if (phydev->asym_pause) |
| 1518 | rmt_adv |= LPA_PAUSE_ASYM; |
| 1519 | } |
| 1520 | |
| 1521 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 1522 | } else |
| 1523 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 1524 | |
| 1525 | if (mac_mode != tp->mac_mode) { |
| 1526 | tp->mac_mode = mac_mode; |
| 1527 | tw32_f(MAC_MODE, tp->mac_mode); |
| 1528 | udelay(40); |
| 1529 | } |
| 1530 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1531 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
| 1532 | if (phydev->speed == SPEED_10) |
| 1533 | tw32(MAC_MI_STAT, |
| 1534 | MAC_MI_STAT_10MBPS_MODE | |
| 1535 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1536 | else |
| 1537 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1538 | } |
| 1539 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1540 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
| 1541 | tw32(MAC_TX_LENGTHS, |
| 1542 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1543 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1544 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1545 | else |
| 1546 | tw32(MAC_TX_LENGTHS, |
| 1547 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1548 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1549 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1550 | |
| 1551 | if ((phydev->link && tp->link_config.active_speed == SPEED_INVALID) || |
| 1552 | (!phydev->link && tp->link_config.active_speed != SPEED_INVALID) || |
| 1553 | phydev->speed != tp->link_config.active_speed || |
| 1554 | phydev->duplex != tp->link_config.active_duplex || |
| 1555 | oldflowctrl != tp->link_config.active_flowctrl) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 1556 | linkmesg = 1; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1557 | |
| 1558 | tp->link_config.active_speed = phydev->speed; |
| 1559 | tp->link_config.active_duplex = phydev->duplex; |
| 1560 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1561 | spin_unlock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1562 | |
| 1563 | if (linkmesg) |
| 1564 | tg3_link_report(tp); |
| 1565 | } |
| 1566 | |
| 1567 | static int tg3_phy_init(struct tg3 *tp) |
| 1568 | { |
| 1569 | struct phy_device *phydev; |
| 1570 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1571 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1572 | return 0; |
| 1573 | |
| 1574 | /* Bring the PHY back to a known state. */ |
| 1575 | tg3_bmcr_reset(tp); |
| 1576 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1577 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1578 | |
| 1579 | /* Attach the MAC to the PHY. */ |
Kay Sievers | fb28ad3 | 2008-11-10 13:55:14 -0800 | [diff] [blame] | 1580 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link, |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1581 | phydev->dev_flags, phydev->interface); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1582 | if (IS_ERR(phydev)) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1583 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1584 | return PTR_ERR(phydev); |
| 1585 | } |
| 1586 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1587 | /* Mask with MAC supported features. */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1588 | switch (phydev->interface) { |
| 1589 | case PHY_INTERFACE_MODE_GMII: |
| 1590 | case PHY_INTERFACE_MODE_RGMII: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1591 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1592 | phydev->supported &= (PHY_GBIT_FEATURES | |
| 1593 | SUPPORTED_Pause | |
| 1594 | SUPPORTED_Asym_Pause); |
| 1595 | break; |
| 1596 | } |
| 1597 | /* fallthru */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1598 | case PHY_INTERFACE_MODE_MII: |
| 1599 | phydev->supported &= (PHY_BASIC_FEATURES | |
| 1600 | SUPPORTED_Pause | |
| 1601 | SUPPORTED_Asym_Pause); |
| 1602 | break; |
| 1603 | default: |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1604 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1605 | return -EINVAL; |
| 1606 | } |
| 1607 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1608 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1609 | |
| 1610 | phydev->advertising = phydev->supported; |
| 1611 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1612 | return 0; |
| 1613 | } |
| 1614 | |
| 1615 | static void tg3_phy_start(struct tg3 *tp) |
| 1616 | { |
| 1617 | struct phy_device *phydev; |
| 1618 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1619 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1620 | return; |
| 1621 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1622 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1623 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 1624 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 1625 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1626 | phydev->speed = tp->link_config.orig_speed; |
| 1627 | phydev->duplex = tp->link_config.orig_duplex; |
| 1628 | phydev->autoneg = tp->link_config.orig_autoneg; |
| 1629 | phydev->advertising = tp->link_config.orig_advertising; |
| 1630 | } |
| 1631 | |
| 1632 | phy_start(phydev); |
| 1633 | |
| 1634 | phy_start_aneg(phydev); |
| 1635 | } |
| 1636 | |
| 1637 | static void tg3_phy_stop(struct tg3 *tp) |
| 1638 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1639 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1640 | return; |
| 1641 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1642 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | static void tg3_phy_fini(struct tg3 *tp) |
| 1646 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1647 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1648 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1649 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1650 | } |
| 1651 | } |
| 1652 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1653 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
| 1654 | { |
| 1655 | u32 phytest; |
| 1656 | |
| 1657 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 1658 | u32 phy; |
| 1659 | |
| 1660 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 1661 | phytest | MII_TG3_FET_SHADOW_EN); |
| 1662 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { |
| 1663 | if (enable) |
| 1664 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1665 | else |
| 1666 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1667 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); |
| 1668 | } |
| 1669 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 1670 | } |
| 1671 | } |
| 1672 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1673 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
| 1674 | { |
| 1675 | u32 reg; |
| 1676 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1677 | if (!tg3_flag(tp, 5705_PLUS) || |
| 1678 | (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1679 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1680 | return; |
| 1681 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1682 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1683 | tg3_phy_fet_toggle_apd(tp, enable); |
| 1684 | return; |
| 1685 | } |
| 1686 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1687 | reg = MII_TG3_MISC_SHDW_WREN | |
| 1688 | MII_TG3_MISC_SHDW_SCR5_SEL | |
| 1689 | MII_TG3_MISC_SHDW_SCR5_LPED | |
| 1690 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | |
| 1691 | MII_TG3_MISC_SHDW_SCR5_SDTL | |
| 1692 | MII_TG3_MISC_SHDW_SCR5_C125OE; |
| 1693 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) |
| 1694 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
| 1695 | |
| 1696 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 1697 | |
| 1698 | |
| 1699 | reg = MII_TG3_MISC_SHDW_WREN | |
| 1700 | MII_TG3_MISC_SHDW_APD_SEL | |
| 1701 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; |
| 1702 | if (enable) |
| 1703 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; |
| 1704 | |
| 1705 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 1706 | } |
| 1707 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1708 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
| 1709 | { |
| 1710 | u32 phy; |
| 1711 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1712 | if (!tg3_flag(tp, 5705_PLUS) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1713 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1714 | return; |
| 1715 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1716 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1717 | u32 ephy; |
| 1718 | |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1719 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
| 1720 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; |
| 1721 | |
| 1722 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 1723 | ephy | MII_TG3_FET_SHADOW_EN); |
| 1724 | if (!tg3_readphy(tp, reg, &phy)) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1725 | if (enable) |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1726 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1727 | else |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1728 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 1729 | tg3_writephy(tp, reg, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1730 | } |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1731 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1732 | } |
| 1733 | } else { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 1734 | int ret; |
| 1735 | |
| 1736 | ret = tg3_phy_auxctl_read(tp, |
| 1737 | MII_TG3_AUXCTL_SHDWSEL_MISC, &phy); |
| 1738 | if (!ret) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1739 | if (enable) |
| 1740 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 1741 | else |
| 1742 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 1743 | tg3_phy_auxctl_write(tp, |
| 1744 | MII_TG3_AUXCTL_SHDWSEL_MISC, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1745 | } |
| 1746 | } |
| 1747 | } |
| 1748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
| 1750 | { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 1751 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | u32 val; |
| 1753 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1754 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | return; |
| 1756 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 1757 | ret = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, &val); |
| 1758 | if (!ret) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 1759 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, |
| 1760 | val | MII_TG3_AUXCTL_MISC_WIRESPD_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1763 | static void tg3_phy_apply_otp(struct tg3 *tp) |
| 1764 | { |
| 1765 | u32 otp, phy; |
| 1766 | |
| 1767 | if (!tp->phy_otp) |
| 1768 | return; |
| 1769 | |
| 1770 | otp = tp->phy_otp; |
| 1771 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 1772 | if (TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) |
| 1773 | return; |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1774 | |
| 1775 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); |
| 1776 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; |
| 1777 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); |
| 1778 | |
| 1779 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | |
| 1780 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); |
| 1781 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); |
| 1782 | |
| 1783 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); |
| 1784 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; |
| 1785 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); |
| 1786 | |
| 1787 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); |
| 1788 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); |
| 1789 | |
| 1790 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); |
| 1791 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); |
| 1792 | |
| 1793 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | |
| 1794 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); |
| 1795 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); |
| 1796 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 1797 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 1800 | static void tg3_phy_eee_adjust(struct tg3 *tp, u32 current_link_up) |
| 1801 | { |
| 1802 | u32 val; |
| 1803 | |
| 1804 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 1805 | return; |
| 1806 | |
| 1807 | tp->setlpicnt = 0; |
| 1808 | |
| 1809 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 1810 | current_link_up == 1 && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 1811 | tp->link_config.active_duplex == DUPLEX_FULL && |
| 1812 | (tp->link_config.active_speed == SPEED_100 || |
| 1813 | tp->link_config.active_speed == SPEED_1000)) { |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 1814 | u32 eeectl; |
| 1815 | |
| 1816 | if (tp->link_config.active_speed == SPEED_1000) |
| 1817 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; |
| 1818 | else |
| 1819 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; |
| 1820 | |
| 1821 | tw32(TG3_CPMU_EEE_CTRL, eeectl); |
| 1822 | |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 1823 | tg3_phy_cl45_read(tp, MDIO_MMD_AN, |
| 1824 | TG3_CL45_D7_EEERES_STAT, &val); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 1825 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 1826 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
| 1827 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 1828 | tp->setlpicnt = 2; |
| 1829 | } |
| 1830 | |
| 1831 | if (!tp->setlpicnt) { |
| 1832 | val = tr32(TG3_CPMU_EEE_MODE); |
| 1833 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 1834 | } |
| 1835 | } |
| 1836 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 1837 | static void tg3_phy_eee_enable(struct tg3 *tp) |
| 1838 | { |
| 1839 | u32 val; |
| 1840 | |
| 1841 | if (tp->link_config.active_speed == SPEED_1000 && |
| 1842 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 1843 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 1844 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) && |
| 1845 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 1846 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, 0x0003); |
| 1847 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 1848 | } |
| 1849 | |
| 1850 | val = tr32(TG3_CPMU_EEE_MODE); |
| 1851 | tw32(TG3_CPMU_EEE_MODE, val | TG3_CPMU_EEEMD_LPI_ENABLE); |
| 1852 | } |
| 1853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | static int tg3_wait_macro_done(struct tg3 *tp) |
| 1855 | { |
| 1856 | int limit = 100; |
| 1857 | |
| 1858 | while (limit--) { |
| 1859 | u32 tmp32; |
| 1860 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1861 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | if ((tmp32 & 0x1000) == 0) |
| 1863 | break; |
| 1864 | } |
| 1865 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 1866 | if (limit < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | return -EBUSY; |
| 1868 | |
| 1869 | return 0; |
| 1870 | } |
| 1871 | |
| 1872 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) |
| 1873 | { |
| 1874 | static const u32 test_pat[4][6] = { |
| 1875 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, |
| 1876 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, |
| 1877 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, |
| 1878 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } |
| 1879 | }; |
| 1880 | int chan; |
| 1881 | |
| 1882 | for (chan = 0; chan < 4; chan++) { |
| 1883 | int i; |
| 1884 | |
| 1885 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1886 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1887 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | |
| 1889 | for (i = 0; i < 6; i++) |
| 1890 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, |
| 1891 | test_pat[chan][i]); |
| 1892 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1893 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | if (tg3_wait_macro_done(tp)) { |
| 1895 | *resetp = 1; |
| 1896 | return -EBUSY; |
| 1897 | } |
| 1898 | |
| 1899 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1900 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1901 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | if (tg3_wait_macro_done(tp)) { |
| 1903 | *resetp = 1; |
| 1904 | return -EBUSY; |
| 1905 | } |
| 1906 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1907 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | if (tg3_wait_macro_done(tp)) { |
| 1909 | *resetp = 1; |
| 1910 | return -EBUSY; |
| 1911 | } |
| 1912 | |
| 1913 | for (i = 0; i < 6; i += 2) { |
| 1914 | u32 low, high; |
| 1915 | |
| 1916 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || |
| 1917 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || |
| 1918 | tg3_wait_macro_done(tp)) { |
| 1919 | *resetp = 1; |
| 1920 | return -EBUSY; |
| 1921 | } |
| 1922 | low &= 0x7fff; |
| 1923 | high &= 0x000f; |
| 1924 | if (low != test_pat[chan][i] || |
| 1925 | high != test_pat[chan][i+1]) { |
| 1926 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); |
| 1927 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); |
| 1928 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); |
| 1929 | |
| 1930 | return -EBUSY; |
| 1931 | } |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
| 1938 | static int tg3_phy_reset_chanpat(struct tg3 *tp) |
| 1939 | { |
| 1940 | int chan; |
| 1941 | |
| 1942 | for (chan = 0; chan < 4; chan++) { |
| 1943 | int i; |
| 1944 | |
| 1945 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1946 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1947 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | for (i = 0; i < 6; i++) |
| 1949 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1950 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | if (tg3_wait_macro_done(tp)) |
| 1952 | return -EBUSY; |
| 1953 | } |
| 1954 | |
| 1955 | return 0; |
| 1956 | } |
| 1957 | |
| 1958 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) |
| 1959 | { |
| 1960 | u32 reg32, phy9_orig; |
| 1961 | int retries, do_phy_reset, err; |
| 1962 | |
| 1963 | retries = 10; |
| 1964 | do_phy_reset = 1; |
| 1965 | do { |
| 1966 | if (do_phy_reset) { |
| 1967 | err = tg3_bmcr_reset(tp); |
| 1968 | if (err) |
| 1969 | return err; |
| 1970 | do_phy_reset = 0; |
| 1971 | } |
| 1972 | |
| 1973 | /* Disable transmitter and interrupt. */ |
| 1974 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) |
| 1975 | continue; |
| 1976 | |
| 1977 | reg32 |= 0x3000; |
| 1978 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 1979 | |
| 1980 | /* Set full-duplex, 1000 mbps. */ |
| 1981 | tg3_writephy(tp, MII_BMCR, |
| 1982 | BMCR_FULLDPLX | TG3_BMCR_SPEED1000); |
| 1983 | |
| 1984 | /* Set to master mode. */ |
| 1985 | if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig)) |
| 1986 | continue; |
| 1987 | |
| 1988 | tg3_writephy(tp, MII_TG3_CTRL, |
| 1989 | (MII_TG3_CTRL_AS_MASTER | |
| 1990 | MII_TG3_CTRL_ENABLE_AS_MASTER)); |
| 1991 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 1992 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
| 1993 | if (err) |
| 1994 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | |
| 1996 | /* Block the PHY control access. */ |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 1997 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | |
| 1999 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); |
| 2000 | if (!err) |
| 2001 | break; |
| 2002 | } while (--retries); |
| 2003 | |
| 2004 | err = tg3_phy_reset_chanpat(tp); |
| 2005 | if (err) |
| 2006 | return err; |
| 2007 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2008 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | |
| 2010 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2011 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2013 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | |
| 2015 | tg3_writephy(tp, MII_TG3_CTRL, phy9_orig); |
| 2016 | |
| 2017 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { |
| 2018 | reg32 &= ~0x3000; |
| 2019 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2020 | } else if (!err) |
| 2021 | err = -EBUSY; |
| 2022 | |
| 2023 | return err; |
| 2024 | } |
| 2025 | |
| 2026 | /* This will reset the tigon3 PHY if there is no valid |
| 2027 | * link unless the FORCE argument is non-zero. |
| 2028 | */ |
| 2029 | static int tg3_phy_reset(struct tg3 *tp) |
| 2030 | { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2031 | u32 val, cpmuctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | int err; |
| 2033 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2034 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2035 | val = tr32(GRC_MISC_CFG); |
| 2036 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); |
| 2037 | udelay(40); |
| 2038 | } |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2039 | err = tg3_readphy(tp, MII_BMSR, &val); |
| 2040 | err |= tg3_readphy(tp, MII_BMSR, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | if (err != 0) |
| 2042 | return -EBUSY; |
| 2043 | |
Michael Chan | c8e1e82 | 2006-04-29 18:55:17 -0700 | [diff] [blame] | 2044 | if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) { |
| 2045 | netif_carrier_off(tp->dev); |
| 2046 | tg3_link_report(tp); |
| 2047 | } |
| 2048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 2050 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2051 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 2052 | err = tg3_phy_reset_5703_4_5(tp); |
| 2053 | if (err) |
| 2054 | return err; |
| 2055 | goto out; |
| 2056 | } |
| 2057 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2058 | cpmuctrl = 0; |
| 2059 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 2060 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 2061 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
| 2062 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) |
| 2063 | tw32(TG3_CPMU_CTRL, |
| 2064 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); |
| 2065 | } |
| 2066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | err = tg3_bmcr_reset(tp); |
| 2068 | if (err) |
| 2069 | return err; |
| 2070 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2071 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2072 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
| 2073 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2074 | |
| 2075 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 2076 | } |
| 2077 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2078 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2079 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2080 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2081 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == |
| 2082 | CPMU_LSPD_1000MB_MACCLK_12_5) { |
| 2083 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2084 | udelay(40); |
| 2085 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2086 | } |
| 2087 | } |
| 2088 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2089 | if (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2090 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 2091 | return 0; |
| 2092 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2093 | tg3_phy_apply_otp(tp); |
| 2094 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2095 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2096 | tg3_phy_toggle_apd(tp, true); |
| 2097 | else |
| 2098 | tg3_phy_toggle_apd(tp, false); |
| 2099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | out: |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2101 | if ((tp->phy_flags & TG3_PHYFLG_ADC_BUG) && |
| 2102 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2103 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
| 2104 | tg3_phydsp_write(tp, 0x000a, 0x0323); |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2105 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2107 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2108 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2109 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 2110 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2112 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2113 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2114 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2115 | tg3_phydsp_write(tp, 0x000a, 0x310b); |
| 2116 | tg3_phydsp_write(tp, 0x201f, 0x9506); |
| 2117 | tg3_phydsp_write(tp, 0x401f, 0x14e2); |
| 2118 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2119 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2120 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2121 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2122 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
| 2123 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { |
| 2124 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
| 2125 | tg3_writephy(tp, MII_TG3_TEST1, |
| 2126 | MII_TG3_TEST1_TRIM_EN | 0x4); |
| 2127 | } else |
| 2128 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); |
| 2129 | |
| 2130 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2131 | } |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 2132 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | /* Set Extended packet length bit (bit 14) on all chips that */ |
| 2135 | /* support jumbo frames */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2136 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | /* Cannot do read-modify-write on 5401 */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2138 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2139 | } else if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | /* Set bit 14 with read-modify-write to preserve other bits */ |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2141 | err = tg3_phy_auxctl_read(tp, |
| 2142 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2143 | if (!err) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2144 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2145 | val | MII_TG3_AUXCTL_ACTL_EXTPKTLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support |
| 2149 | * jumbo frames transmission. |
| 2150 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2151 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2152 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 2153 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2154 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | } |
| 2156 | |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2157 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2158 | /* adjust output voltage */ |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2159 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2162 | tg3_phy_toggle_automdix(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | tg3_phy_set_wirespeed(tp); |
| 2164 | return 0; |
| 2165 | } |
| 2166 | |
| 2167 | static void tg3_frob_aux_power(struct tg3 *tp) |
| 2168 | { |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2169 | bool need_vaux = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2171 | /* The GPIOs do something completely different on 57765. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2172 | if (!tg3_flag(tp, IS_NIC) || |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 2173 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2174 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | return; |
| 2176 | |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2177 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2178 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 2179 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2180 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) && |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2181 | tp->pdev_peer != tp->pdev) { |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2182 | struct net_device *dev_peer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2184 | dev_peer = pci_get_drvdata(tp->pdev_peer); |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2185 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2186 | /* remove_one() may have been run on the peer. */ |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2187 | if (dev_peer) { |
| 2188 | struct tg3 *tp_peer = netdev_priv(dev_peer); |
| 2189 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2190 | if (tg3_flag(tp_peer, INIT_COMPLETE)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2191 | return; |
| 2192 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2193 | if (tg3_flag(tp_peer, WOL_ENABLE) || |
| 2194 | tg3_flag(tp_peer, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2195 | need_vaux = true; |
| 2196 | } |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2199 | if (tg3_flag(tp, WOL_ENABLE) || tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2200 | need_vaux = true; |
| 2201 | |
| 2202 | if (need_vaux) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2204 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2205 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2206 | (GRC_LCLCTRL_GPIO_OE0 | |
| 2207 | GRC_LCLCTRL_GPIO_OE1 | |
| 2208 | GRC_LCLCTRL_GPIO_OE2 | |
| 2209 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2210 | GRC_LCLCTRL_GPIO_OUTPUT1), |
| 2211 | 100); |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 2212 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 2213 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 2214 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
| 2215 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | |
| 2216 | GRC_LCLCTRL_GPIO_OE1 | |
| 2217 | GRC_LCLCTRL_GPIO_OE2 | |
| 2218 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2219 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2220 | tp->grc_local_ctrl; |
| 2221 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
| 2222 | |
| 2223 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2224 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
| 2225 | |
| 2226 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2227 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | } else { |
| 2229 | u32 no_gpio2; |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2230 | u32 grc_local_ctrl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2232 | /* Workaround to prevent overdrawing Amps. */ |
| 2233 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 2234 | ASIC_REV_5714) { |
| 2235 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2236 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2237 | grc_local_ctrl, 100); |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2238 | } |
| 2239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | /* On 5753 and variants, GPIO2 cannot be used. */ |
| 2241 | no_gpio2 = tp->nic_sram_data_cfg & |
| 2242 | NIC_SRAM_DATA_CFG_NO_GPIO2; |
| 2243 | |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2244 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | GRC_LCLCTRL_GPIO_OE1 | |
| 2246 | GRC_LCLCTRL_GPIO_OE2 | |
| 2247 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2248 | GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2249 | if (no_gpio2) { |
| 2250 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | |
| 2251 | GRC_LCLCTRL_GPIO_OUTPUT2); |
| 2252 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2253 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2254 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | |
| 2256 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2257 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2258 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2259 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | |
| 2261 | if (!no_gpio2) { |
| 2262 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2263 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2264 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | } else { |
| 2268 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 2269 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2270 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2271 | (GRC_LCLCTRL_GPIO_OE1 | |
| 2272 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2274 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2275 | GRC_LCLCTRL_GPIO_OE1, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2277 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2278 | (GRC_LCLCTRL_GPIO_OE1 | |
| 2279 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | } |
| 2281 | } |
| 2282 | } |
| 2283 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2284 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
| 2285 | { |
| 2286 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) |
| 2287 | return 1; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2288 | 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] | 2289 | if (speed != SPEED_10) |
| 2290 | return 1; |
| 2291 | } else if (speed == SPEED_10) |
| 2292 | return 1; |
| 2293 | |
| 2294 | return 0; |
| 2295 | } |
| 2296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | static int tg3_setup_phy(struct tg3 *, int); |
| 2298 | |
| 2299 | #define RESET_KIND_SHUTDOWN 0 |
| 2300 | #define RESET_KIND_INIT 1 |
| 2301 | #define RESET_KIND_SUSPEND 2 |
| 2302 | |
| 2303 | static void tg3_write_sig_post_reset(struct tg3 *, int); |
| 2304 | static int tg3_halt_cpu(struct tg3 *, u32); |
| 2305 | |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2306 | 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] | 2307 | { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2308 | u32 val; |
| 2309 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2310 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2311 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2312 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 2313 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); |
| 2314 | |
| 2315 | sg_dig_ctrl |= |
| 2316 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; |
| 2317 | tw32(SG_DIG_CTRL, sg_dig_ctrl); |
| 2318 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); |
| 2319 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2320 | return; |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2321 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2322 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2323 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2324 | tg3_bmcr_reset(tp); |
| 2325 | val = tr32(GRC_MISC_CFG); |
| 2326 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); |
| 2327 | udelay(40); |
| 2328 | return; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2329 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 0e5f784 | 2009-11-02 14:26:38 +0000 | [diff] [blame] | 2330 | u32 phytest; |
| 2331 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2332 | u32 phy; |
| 2333 | |
| 2334 | tg3_writephy(tp, MII_ADVERTISE, 0); |
| 2335 | tg3_writephy(tp, MII_BMCR, |
| 2336 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 2337 | |
| 2338 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2339 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2340 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { |
| 2341 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; |
| 2342 | tg3_writephy(tp, |
| 2343 | MII_TG3_FET_SHDW_AUXMODE4, |
| 2344 | phy); |
| 2345 | } |
| 2346 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2347 | } |
| 2348 | return; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2349 | } else if (do_low_power) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2350 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 2351 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2352 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2353 | val = MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 2354 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | |
| 2355 | MII_TG3_AUXCTL_PCTL_VREG_11V; |
| 2356 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, val); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2357 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2358 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2359 | /* The PHY should not be powered down on some chips because |
| 2360 | * of bugs. |
| 2361 | */ |
| 2362 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2363 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2364 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2365 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2366 | return; |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2367 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2368 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2369 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2370 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2371 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2372 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; |
| 2373 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2374 | } |
| 2375 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2376 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 2377 | } |
| 2378 | |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2379 | /* tp->lock is held. */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2380 | static int tg3_nvram_lock(struct tg3 *tp) |
| 2381 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2382 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2383 | int i; |
| 2384 | |
| 2385 | if (tp->nvram_lock_cnt == 0) { |
| 2386 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); |
| 2387 | for (i = 0; i < 8000; i++) { |
| 2388 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) |
| 2389 | break; |
| 2390 | udelay(20); |
| 2391 | } |
| 2392 | if (i == 8000) { |
| 2393 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2394 | return -ENODEV; |
| 2395 | } |
| 2396 | } |
| 2397 | tp->nvram_lock_cnt++; |
| 2398 | } |
| 2399 | return 0; |
| 2400 | } |
| 2401 | |
| 2402 | /* tp->lock is held. */ |
| 2403 | static void tg3_nvram_unlock(struct tg3 *tp) |
| 2404 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2405 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2406 | if (tp->nvram_lock_cnt > 0) |
| 2407 | tp->nvram_lock_cnt--; |
| 2408 | if (tp->nvram_lock_cnt == 0) |
| 2409 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | /* tp->lock is held. */ |
| 2414 | static void tg3_enable_nvram_access(struct tg3 *tp) |
| 2415 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2416 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2417 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2418 | |
| 2419 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); |
| 2420 | } |
| 2421 | } |
| 2422 | |
| 2423 | /* tp->lock is held. */ |
| 2424 | static void tg3_disable_nvram_access(struct tg3 *tp) |
| 2425 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2426 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2427 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2428 | |
| 2429 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); |
| 2430 | } |
| 2431 | } |
| 2432 | |
| 2433 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, |
| 2434 | u32 offset, u32 *val) |
| 2435 | { |
| 2436 | u32 tmp; |
| 2437 | int i; |
| 2438 | |
| 2439 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) |
| 2440 | return -EINVAL; |
| 2441 | |
| 2442 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | |
| 2443 | EEPROM_ADDR_DEVID_MASK | |
| 2444 | EEPROM_ADDR_READ); |
| 2445 | tw32(GRC_EEPROM_ADDR, |
| 2446 | tmp | |
| 2447 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 2448 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & |
| 2449 | EEPROM_ADDR_ADDR_MASK) | |
| 2450 | EEPROM_ADDR_READ | EEPROM_ADDR_START); |
| 2451 | |
| 2452 | for (i = 0; i < 1000; i++) { |
| 2453 | tmp = tr32(GRC_EEPROM_ADDR); |
| 2454 | |
| 2455 | if (tmp & EEPROM_ADDR_COMPLETE) |
| 2456 | break; |
| 2457 | msleep(1); |
| 2458 | } |
| 2459 | if (!(tmp & EEPROM_ADDR_COMPLETE)) |
| 2460 | return -EBUSY; |
| 2461 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 2462 | tmp = tr32(GRC_EEPROM_DATA); |
| 2463 | |
| 2464 | /* |
| 2465 | * The data will always be opposite the native endian |
| 2466 | * format. Perform a blind byteswap to compensate. |
| 2467 | */ |
| 2468 | *val = swab32(tmp); |
| 2469 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2470 | return 0; |
| 2471 | } |
| 2472 | |
| 2473 | #define NVRAM_CMD_TIMEOUT 10000 |
| 2474 | |
| 2475 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) |
| 2476 | { |
| 2477 | int i; |
| 2478 | |
| 2479 | tw32(NVRAM_CMD, nvram_cmd); |
| 2480 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { |
| 2481 | udelay(10); |
| 2482 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { |
| 2483 | udelay(10); |
| 2484 | break; |
| 2485 | } |
| 2486 | } |
| 2487 | |
| 2488 | if (i == NVRAM_CMD_TIMEOUT) |
| 2489 | return -EBUSY; |
| 2490 | |
| 2491 | return 0; |
| 2492 | } |
| 2493 | |
| 2494 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) |
| 2495 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2496 | if (tg3_flag(tp, NVRAM) && |
| 2497 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 2498 | tg3_flag(tp, FLASH) && |
| 2499 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2500 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2501 | |
| 2502 | addr = ((addr / tp->nvram_pagesize) << |
| 2503 | ATMEL_AT45DB0X1B_PAGE_POS) + |
| 2504 | (addr % tp->nvram_pagesize); |
| 2505 | |
| 2506 | return addr; |
| 2507 | } |
| 2508 | |
| 2509 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) |
| 2510 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2511 | if (tg3_flag(tp, NVRAM) && |
| 2512 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 2513 | tg3_flag(tp, FLASH) && |
| 2514 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2515 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2516 | |
| 2517 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * |
| 2518 | tp->nvram_pagesize) + |
| 2519 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); |
| 2520 | |
| 2521 | return addr; |
| 2522 | } |
| 2523 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2524 | /* NOTE: Data read in from NVRAM is byteswapped according to |
| 2525 | * the byteswapping settings for all other register accesses. |
| 2526 | * tg3 devices are BE devices, so on a BE machine, the data |
| 2527 | * returned will be exactly as it is seen in NVRAM. On a LE |
| 2528 | * machine, the 32-bit value will be byteswapped. |
| 2529 | */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2530 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
| 2531 | { |
| 2532 | int ret; |
| 2533 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2534 | if (!tg3_flag(tp, NVRAM)) |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2535 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
| 2536 | |
| 2537 | offset = tg3_nvram_phys_addr(tp, offset); |
| 2538 | |
| 2539 | if (offset > NVRAM_ADDR_MSK) |
| 2540 | return -EINVAL; |
| 2541 | |
| 2542 | ret = tg3_nvram_lock(tp); |
| 2543 | if (ret) |
| 2544 | return ret; |
| 2545 | |
| 2546 | tg3_enable_nvram_access(tp); |
| 2547 | |
| 2548 | tw32(NVRAM_ADDR, offset); |
| 2549 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | |
| 2550 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); |
| 2551 | |
| 2552 | if (ret == 0) |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2553 | *val = tr32(NVRAM_RDDATA); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2554 | |
| 2555 | tg3_disable_nvram_access(tp); |
| 2556 | |
| 2557 | tg3_nvram_unlock(tp); |
| 2558 | |
| 2559 | return ret; |
| 2560 | } |
| 2561 | |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2562 | /* Ensures NVRAM data is in bytestream format. */ |
| 2563 | 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] | 2564 | { |
| 2565 | u32 v; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2566 | int res = tg3_nvram_read(tp, offset, &v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2567 | if (!res) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2568 | *val = cpu_to_be32(v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2569 | return res; |
| 2570 | } |
| 2571 | |
| 2572 | /* tp->lock is held. */ |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2573 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) |
| 2574 | { |
| 2575 | u32 addr_high, addr_low; |
| 2576 | int i; |
| 2577 | |
| 2578 | addr_high = ((tp->dev->dev_addr[0] << 8) | |
| 2579 | tp->dev->dev_addr[1]); |
| 2580 | addr_low = ((tp->dev->dev_addr[2] << 24) | |
| 2581 | (tp->dev->dev_addr[3] << 16) | |
| 2582 | (tp->dev->dev_addr[4] << 8) | |
| 2583 | (tp->dev->dev_addr[5] << 0)); |
| 2584 | for (i = 0; i < 4; i++) { |
| 2585 | if (i == 1 && skip_mac_1) |
| 2586 | continue; |
| 2587 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); |
| 2588 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); |
| 2589 | } |
| 2590 | |
| 2591 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 2592 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2593 | for (i = 0; i < 12; i++) { |
| 2594 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); |
| 2595 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); |
| 2596 | } |
| 2597 | } |
| 2598 | |
| 2599 | addr_high = (tp->dev->dev_addr[0] + |
| 2600 | tp->dev->dev_addr[1] + |
| 2601 | tp->dev->dev_addr[2] + |
| 2602 | tp->dev->dev_addr[3] + |
| 2603 | tp->dev->dev_addr[4] + |
| 2604 | tp->dev->dev_addr[5]) & |
| 2605 | TX_BACKOFF_SEED_MASK; |
| 2606 | tw32(MAC_TX_BACKOFF_SEED, addr_high); |
| 2607 | } |
| 2608 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 2609 | static void tg3_enable_register_access(struct tg3 *tp) |
| 2610 | { |
| 2611 | /* |
| 2612 | * Make sure register accesses (indirect or otherwise) will function |
| 2613 | * correctly. |
| 2614 | */ |
| 2615 | pci_write_config_dword(tp->pdev, |
| 2616 | TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl); |
| 2617 | } |
| 2618 | |
| 2619 | static int tg3_power_up(struct tg3 *tp) |
| 2620 | { |
| 2621 | tg3_enable_register_access(tp); |
| 2622 | |
| 2623 | pci_set_power_state(tp->pdev, PCI_D0); |
| 2624 | |
| 2625 | /* Switch out of Vaux if it is a NIC */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2626 | if (tg3_flag(tp, IS_NIC)) |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 2627 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100); |
| 2628 | |
| 2629 | return 0; |
| 2630 | } |
| 2631 | |
| 2632 | static int tg3_power_down_prepare(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | { |
| 2634 | u32 misc_host_ctrl; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2635 | bool device_should_wake, do_low_power; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 2637 | tg3_enable_register_access(tp); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 2638 | |
| 2639 | /* Restore the CLKREQ setting. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2640 | if (tg3_flag(tp, CLKREQ_BUG)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 2641 | u16 lnkctl; |
| 2642 | |
| 2643 | pci_read_config_word(tp->pdev, |
| 2644 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 2645 | &lnkctl); |
| 2646 | lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 2647 | pci_write_config_word(tp->pdev, |
| 2648 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 2649 | lnkctl); |
| 2650 | } |
| 2651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 2653 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 2654 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); |
| 2655 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 2656 | device_should_wake = device_may_wakeup(&tp->pdev->dev) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2657 | tg3_flag(tp, WOL_ENABLE); |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2658 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2659 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2660 | do_low_power = false; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2661 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2662 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2663 | struct phy_device *phydev; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2664 | u32 phyid, advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2665 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2666 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2667 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2668 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2669 | |
| 2670 | tp->link_config.orig_speed = phydev->speed; |
| 2671 | tp->link_config.orig_duplex = phydev->duplex; |
| 2672 | tp->link_config.orig_autoneg = phydev->autoneg; |
| 2673 | tp->link_config.orig_advertising = phydev->advertising; |
| 2674 | |
| 2675 | advertising = ADVERTISED_TP | |
| 2676 | ADVERTISED_Pause | |
| 2677 | ADVERTISED_Autoneg | |
| 2678 | ADVERTISED_10baseT_Half; |
| 2679 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2680 | if (tg3_flag(tp, ENABLE_ASF) || device_should_wake) { |
| 2681 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2682 | advertising |= |
| 2683 | ADVERTISED_100baseT_Half | |
| 2684 | ADVERTISED_100baseT_Full | |
| 2685 | ADVERTISED_10baseT_Full; |
| 2686 | else |
| 2687 | advertising |= ADVERTISED_10baseT_Full; |
| 2688 | } |
| 2689 | |
| 2690 | phydev->advertising = advertising; |
| 2691 | |
| 2692 | phy_start_aneg(phydev); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2693 | |
| 2694 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 2695 | if (phyid != PHY_ID_BCMAC131) { |
| 2696 | phyid &= PHY_BCM_OUI_MASK; |
| 2697 | if (phyid == PHY_BCM_OUI_1 || |
| 2698 | phyid == PHY_BCM_OUI_2 || |
| 2699 | phyid == PHY_BCM_OUI_3) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2700 | do_low_power = true; |
| 2701 | } |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2702 | } |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2703 | } else { |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 2704 | do_low_power = true; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2705 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2706 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 2707 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2708 | tp->link_config.orig_speed = tp->link_config.speed; |
| 2709 | tp->link_config.orig_duplex = tp->link_config.duplex; |
| 2710 | tp->link_config.orig_autoneg = tp->link_config.autoneg; |
| 2711 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2713 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2714 | tp->link_config.speed = SPEED_10; |
| 2715 | tp->link_config.duplex = DUPLEX_HALF; |
| 2716 | tp->link_config.autoneg = AUTONEG_ENABLE; |
| 2717 | tg3_setup_phy(tp, 0); |
| 2718 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 2721 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 2722 | u32 val; |
| 2723 | |
| 2724 | val = tr32(GRC_VCPU_EXT_CTRL); |
| 2725 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2726 | } else if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2727 | int i; |
| 2728 | u32 val; |
| 2729 | |
| 2730 | for (i = 0; i < 200; i++) { |
| 2731 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); |
| 2732 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 2733 | break; |
| 2734 | msleep(1); |
| 2735 | } |
| 2736 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2737 | if (tg3_flag(tp, WOL_CAP)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 2738 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
| 2739 | WOL_DRV_STATE_SHUTDOWN | |
| 2740 | WOL_DRV_WOL | |
| 2741 | WOL_SET_MAGIC_PKT); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2742 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2743 | if (device_should_wake) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | u32 mac_mode; |
| 2745 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2746 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2747 | if (do_low_power && |
| 2748 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 2749 | tg3_phy_auxctl_write(tp, |
| 2750 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL, |
| 2751 | MII_TG3_AUXCTL_PCTL_WOL_EN | |
| 2752 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 2753 | MII_TG3_AUXCTL_PCTL_CL_AB_TXDAC); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2754 | udelay(40); |
| 2755 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2757 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2758 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 2759 | else |
| 2760 | mac_mode = MAC_MODE_PORT_MODE_MII; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2762 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
| 2763 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 2764 | ASIC_REV_5700) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2765 | u32 speed = tg3_flag(tp, WOL_SPEED_100MB) ? |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2766 | SPEED_100 : SPEED_10; |
| 2767 | if (tg3_5700_link_polarity(tp, speed)) |
| 2768 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 2769 | else |
| 2770 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 2771 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | } else { |
| 2773 | mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 2774 | } |
| 2775 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2776 | if (!tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 2778 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2779 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2780 | if ((tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) && |
| 2781 | (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE))) |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2782 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2784 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 2785 | mac_mode |= MAC_MODE_APE_TX_EN | |
| 2786 | MAC_MODE_APE_RX_EN | |
| 2787 | MAC_MODE_TDE_ENABLE; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 2788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | tw32_f(MAC_MODE, mac_mode); |
| 2790 | udelay(100); |
| 2791 | |
| 2792 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); |
| 2793 | udelay(10); |
| 2794 | } |
| 2795 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2796 | if (!tg3_flag(tp, WOL_SPEED_100MB) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2798 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 2799 | u32 base_val; |
| 2800 | |
| 2801 | base_val = tp->pci_clock_ctrl; |
| 2802 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | |
| 2803 | CLOCK_CTRL_TXCLK_DISABLE); |
| 2804 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2805 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
| 2806 | CLOCK_CTRL_PWRDOWN_PLL133, 40); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2807 | } else if (tg3_flag(tp, 5780_CLASS) || |
| 2808 | tg3_flag(tp, CPMU_PRESENT) || |
Michael Chan | d7b0a85 | 2007-02-13 12:17:38 -0800 | [diff] [blame] | 2809 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) { |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 2810 | /* do nothing */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2811 | } else if (!(tg3_flag(tp, 5750_PLUS) && tg3_flag(tp, ENABLE_ASF))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | u32 newbits1, newbits2; |
| 2813 | |
| 2814 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2815 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 2816 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 2817 | CLOCK_CTRL_TXCLK_DISABLE | |
| 2818 | CLOCK_CTRL_ALTCLK); |
| 2819 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2820 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | newbits1 = CLOCK_CTRL_625_CORE; |
| 2822 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; |
| 2823 | } else { |
| 2824 | newbits1 = CLOCK_CTRL_ALTCLK; |
| 2825 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 2826 | } |
| 2827 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2828 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
| 2829 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2831 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
| 2832 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2834 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | u32 newbits3; |
| 2836 | |
| 2837 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2838 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 2839 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 2840 | CLOCK_CTRL_TXCLK_DISABLE | |
| 2841 | CLOCK_CTRL_44MHZ_CORE); |
| 2842 | } else { |
| 2843 | newbits3 = CLOCK_CTRL_44MHZ_CORE; |
| 2844 | } |
| 2845 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2846 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 2847 | tp->pci_clock_ctrl | newbits3, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | } |
| 2849 | } |
| 2850 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2851 | if (!(device_should_wake) && !tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2852 | tg3_power_down_phy(tp, do_low_power); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | tg3_frob_aux_power(tp); |
| 2855 | |
| 2856 | /* Workaround for unstable PLL clock */ |
| 2857 | if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) || |
| 2858 | (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) { |
| 2859 | u32 val = tr32(0x7d00); |
| 2860 | |
| 2861 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); |
| 2862 | tw32(0x7d00, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2863 | if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 2864 | int err; |
| 2865 | |
| 2866 | err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 2868 | if (!err) |
| 2869 | tg3_nvram_unlock(tp); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2870 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 2873 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
| 2874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | return 0; |
| 2876 | } |
| 2877 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 2878 | static void tg3_power_down(struct tg3 *tp) |
| 2879 | { |
| 2880 | tg3_power_down_prepare(tp); |
| 2881 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2882 | pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 2883 | pci_set_power_state(tp->pdev, PCI_D3hot); |
| 2884 | } |
| 2885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
| 2887 | { |
| 2888 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { |
| 2889 | case MII_TG3_AUX_STAT_10HALF: |
| 2890 | *speed = SPEED_10; |
| 2891 | *duplex = DUPLEX_HALF; |
| 2892 | break; |
| 2893 | |
| 2894 | case MII_TG3_AUX_STAT_10FULL: |
| 2895 | *speed = SPEED_10; |
| 2896 | *duplex = DUPLEX_FULL; |
| 2897 | break; |
| 2898 | |
| 2899 | case MII_TG3_AUX_STAT_100HALF: |
| 2900 | *speed = SPEED_100; |
| 2901 | *duplex = DUPLEX_HALF; |
| 2902 | break; |
| 2903 | |
| 2904 | case MII_TG3_AUX_STAT_100FULL: |
| 2905 | *speed = SPEED_100; |
| 2906 | *duplex = DUPLEX_FULL; |
| 2907 | break; |
| 2908 | |
| 2909 | case MII_TG3_AUX_STAT_1000HALF: |
| 2910 | *speed = SPEED_1000; |
| 2911 | *duplex = DUPLEX_HALF; |
| 2912 | break; |
| 2913 | |
| 2914 | case MII_TG3_AUX_STAT_1000FULL: |
| 2915 | *speed = SPEED_1000; |
| 2916 | *duplex = DUPLEX_FULL; |
| 2917 | break; |
| 2918 | |
| 2919 | default: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2920 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2921 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
| 2922 | SPEED_10; |
| 2923 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : |
| 2924 | DUPLEX_HALF; |
| 2925 | break; |
| 2926 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | *speed = SPEED_INVALID; |
| 2928 | *duplex = DUPLEX_INVALID; |
| 2929 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 2930 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | } |
| 2932 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2933 | 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] | 2934 | { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2935 | int err = 0; |
| 2936 | u32 val, new_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2938 | new_adv = ADVERTISE_CSMA; |
| 2939 | if (advertise & ADVERTISED_10baseT_Half) |
| 2940 | new_adv |= ADVERTISE_10HALF; |
| 2941 | if (advertise & ADVERTISED_10baseT_Full) |
| 2942 | new_adv |= ADVERTISE_10FULL; |
| 2943 | if (advertise & ADVERTISED_100baseT_Half) |
| 2944 | new_adv |= ADVERTISE_100HALF; |
| 2945 | if (advertise & ADVERTISED_100baseT_Full) |
| 2946 | new_adv |= ADVERTISE_100FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2948 | new_adv |= tg3_advert_flowctrl_1000T(flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2950 | err = tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 2951 | if (err) |
| 2952 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2954 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 2955 | goto done; |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2956 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2957 | new_adv = 0; |
| 2958 | if (advertise & ADVERTISED_1000baseT_Half) |
| 2959 | new_adv |= MII_TG3_CTRL_ADV_1000_HALF; |
| 2960 | if (advertise & ADVERTISED_1000baseT_Full) |
| 2961 | new_adv |= MII_TG3_CTRL_ADV_1000_FULL; |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2962 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2963 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 2964 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) |
| 2965 | new_adv |= (MII_TG3_CTRL_AS_MASTER | |
| 2966 | MII_TG3_CTRL_ENABLE_AS_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2968 | err = tg3_writephy(tp, MII_TG3_CTRL, new_adv); |
| 2969 | if (err) |
| 2970 | goto done; |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2971 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2972 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 2973 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2975 | tw32(TG3_CPMU_EEE_MODE, |
| 2976 | tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2977 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2978 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
| 2979 | if (!err) { |
| 2980 | u32 err2; |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2981 | |
Matt Carlson | 21a00ab | 2011-01-25 15:58:55 +0000 | [diff] [blame] | 2982 | switch (GET_ASIC_REV(tp->pci_chip_rev_id)) { |
| 2983 | case ASIC_REV_5717: |
| 2984 | case ASIC_REV_57765: |
| 2985 | if (!tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) |
| 2986 | tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, val | |
| 2987 | MII_TG3_DSP_CH34TP2_HIBW01); |
| 2988 | /* Fall through */ |
| 2989 | case ASIC_REV_5719: |
| 2990 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 2991 | MII_TG3_DSP_TAP26_RMRXSTO | |
| 2992 | MII_TG3_DSP_TAP26_OPCSINPT; |
| 2993 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
| 2994 | } |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2995 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 2996 | val = 0; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 2997 | /* Advertise 100-BaseTX EEE ability */ |
| 2998 | if (advertise & ADVERTISED_100baseT_Full) |
| 2999 | val |= MDIO_AN_EEE_ADV_100TX; |
| 3000 | /* Advertise 1000-BaseT EEE ability */ |
| 3001 | if (advertise & ADVERTISED_1000baseT_Full) |
| 3002 | val |= MDIO_AN_EEE_ADV_1000T; |
| 3003 | err = tg3_phy_cl45_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, val); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3004 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3005 | err2 = TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 3006 | if (!err) |
| 3007 | err = err2; |
| 3008 | } |
| 3009 | |
| 3010 | done: |
| 3011 | return err; |
| 3012 | } |
| 3013 | |
| 3014 | static void tg3_phy_copper_begin(struct tg3 *tp) |
| 3015 | { |
| 3016 | u32 new_adv; |
| 3017 | int i; |
| 3018 | |
| 3019 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 3020 | new_adv = ADVERTISED_10baseT_Half | |
| 3021 | ADVERTISED_10baseT_Full; |
| 3022 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
| 3023 | new_adv |= ADVERTISED_100baseT_Half | |
| 3024 | ADVERTISED_100baseT_Full; |
| 3025 | |
| 3026 | tg3_phy_autoneg_cfg(tp, new_adv, |
| 3027 | FLOW_CTRL_TX | FLOW_CTRL_RX); |
| 3028 | } else if (tp->link_config.speed == SPEED_INVALID) { |
| 3029 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 3030 | tp->link_config.advertising &= |
| 3031 | ~(ADVERTISED_1000baseT_Half | |
| 3032 | ADVERTISED_1000baseT_Full); |
| 3033 | |
| 3034 | tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, |
| 3035 | tp->link_config.flowctrl); |
| 3036 | } else { |
| 3037 | /* Asking for a specific link mode. */ |
| 3038 | if (tp->link_config.speed == SPEED_1000) { |
| 3039 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 3040 | new_adv = ADVERTISED_1000baseT_Full; |
| 3041 | else |
| 3042 | new_adv = ADVERTISED_1000baseT_Half; |
| 3043 | } else if (tp->link_config.speed == SPEED_100) { |
| 3044 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 3045 | new_adv = ADVERTISED_100baseT_Full; |
| 3046 | else |
| 3047 | new_adv = ADVERTISED_100baseT_Half; |
| 3048 | } else { |
| 3049 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 3050 | new_adv = ADVERTISED_10baseT_Full; |
| 3051 | else |
| 3052 | new_adv = ADVERTISED_10baseT_Half; |
| 3053 | } |
| 3054 | |
| 3055 | tg3_phy_autoneg_cfg(tp, new_adv, |
| 3056 | tp->link_config.flowctrl); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3057 | } |
| 3058 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | if (tp->link_config.autoneg == AUTONEG_DISABLE && |
| 3060 | tp->link_config.speed != SPEED_INVALID) { |
| 3061 | u32 bmcr, orig_bmcr; |
| 3062 | |
| 3063 | tp->link_config.active_speed = tp->link_config.speed; |
| 3064 | tp->link_config.active_duplex = tp->link_config.duplex; |
| 3065 | |
| 3066 | bmcr = 0; |
| 3067 | switch (tp->link_config.speed) { |
| 3068 | default: |
| 3069 | case SPEED_10: |
| 3070 | break; |
| 3071 | |
| 3072 | case SPEED_100: |
| 3073 | bmcr |= BMCR_SPEED100; |
| 3074 | break; |
| 3075 | |
| 3076 | case SPEED_1000: |
| 3077 | bmcr |= TG3_BMCR_SPEED1000; |
| 3078 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3079 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | |
| 3081 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 3082 | bmcr |= BMCR_FULLDPLX; |
| 3083 | |
| 3084 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && |
| 3085 | (bmcr != orig_bmcr)) { |
| 3086 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); |
| 3087 | for (i = 0; i < 1500; i++) { |
| 3088 | u32 tmp; |
| 3089 | |
| 3090 | udelay(10); |
| 3091 | if (tg3_readphy(tp, MII_BMSR, &tmp) || |
| 3092 | tg3_readphy(tp, MII_BMSR, &tmp)) |
| 3093 | continue; |
| 3094 | if (!(tmp & BMSR_LSTATUS)) { |
| 3095 | udelay(40); |
| 3096 | break; |
| 3097 | } |
| 3098 | } |
| 3099 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 3100 | udelay(40); |
| 3101 | } |
| 3102 | } else { |
| 3103 | tg3_writephy(tp, MII_BMCR, |
| 3104 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 3105 | } |
| 3106 | } |
| 3107 | |
| 3108 | static int tg3_init_5401phy_dsp(struct tg3 *tp) |
| 3109 | { |
| 3110 | int err; |
| 3111 | |
| 3112 | /* Turn off tap power management. */ |
| 3113 | /* Set Extended packet length bit */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 3114 | err = tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 3116 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
| 3117 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); |
| 3118 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); |
| 3119 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); |
| 3120 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | |
| 3122 | udelay(40); |
| 3123 | |
| 3124 | return err; |
| 3125 | } |
| 3126 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 3127 | static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | { |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 3129 | u32 adv_reg, all_mask = 0; |
| 3130 | |
| 3131 | if (mask & ADVERTISED_10baseT_Half) |
| 3132 | all_mask |= ADVERTISE_10HALF; |
| 3133 | if (mask & ADVERTISED_10baseT_Full) |
| 3134 | all_mask |= ADVERTISE_10FULL; |
| 3135 | if (mask & ADVERTISED_100baseT_Half) |
| 3136 | all_mask |= ADVERTISE_100HALF; |
| 3137 | if (mask & ADVERTISED_100baseT_Full) |
| 3138 | all_mask |= ADVERTISE_100FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | |
| 3140 | if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg)) |
| 3141 | return 0; |
| 3142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | if ((adv_reg & all_mask) != all_mask) |
| 3144 | return 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3145 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | u32 tg3_ctrl; |
| 3147 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 3148 | all_mask = 0; |
| 3149 | if (mask & ADVERTISED_1000baseT_Half) |
| 3150 | all_mask |= ADVERTISE_1000HALF; |
| 3151 | if (mask & ADVERTISED_1000baseT_Full) |
| 3152 | all_mask |= ADVERTISE_1000FULL; |
| 3153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl)) |
| 3155 | return 0; |
| 3156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | if ((tg3_ctrl & all_mask) != all_mask) |
| 3158 | return 0; |
| 3159 | } |
| 3160 | return 1; |
| 3161 | } |
| 3162 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3163 | static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv) |
| 3164 | { |
| 3165 | u32 curadv, reqadv; |
| 3166 | |
| 3167 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
| 3168 | return 1; |
| 3169 | |
| 3170 | curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
| 3171 | reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); |
| 3172 | |
| 3173 | if (tp->link_config.active_duplex == DUPLEX_FULL) { |
| 3174 | if (curadv != reqadv) |
| 3175 | return 0; |
| 3176 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3177 | if (tg3_flag(tp, PAUSE_AUTONEG)) |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3178 | tg3_readphy(tp, MII_LPA, rmtadv); |
| 3179 | } else { |
| 3180 | /* Reprogram the advertisement register, even if it |
| 3181 | * does not affect the current link. If the link |
| 3182 | * gets renegotiated in the future, we can save an |
| 3183 | * additional renegotiation cycle by advertising |
| 3184 | * it correctly in the first place. |
| 3185 | */ |
| 3186 | if (curadv != reqadv) { |
| 3187 | *lcladv &= ~(ADVERTISE_PAUSE_CAP | |
| 3188 | ADVERTISE_PAUSE_ASYM); |
| 3189 | tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv); |
| 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | return 1; |
| 3194 | } |
| 3195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
| 3197 | { |
| 3198 | int current_link_up; |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 3199 | u32 bmsr, val; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3200 | u32 lcl_adv, rmt_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | u16 current_speed; |
| 3202 | u8 current_duplex; |
| 3203 | int i, err; |
| 3204 | |
| 3205 | tw32(MAC_EVENT, 0); |
| 3206 | |
| 3207 | tw32_f(MAC_STATUS, |
| 3208 | (MAC_STATUS_SYNC_CHANGED | |
| 3209 | MAC_STATUS_CFG_CHANGED | |
| 3210 | MAC_STATUS_MI_COMPLETION | |
| 3211 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 3212 | udelay(40); |
| 3213 | |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 3214 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 3215 | tw32_f(MAC_MI_MODE, |
| 3216 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 3217 | udelay(80); |
| 3218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 3220 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | |
| 3222 | /* Some third-party PHYs need to be reset on link going |
| 3223 | * down. |
| 3224 | */ |
| 3225 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 3226 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 3227 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
| 3228 | netif_carrier_ok(tp->dev)) { |
| 3229 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3230 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3231 | !(bmsr & BMSR_LSTATUS)) |
| 3232 | force_reset = 1; |
| 3233 | } |
| 3234 | if (force_reset) |
| 3235 | tg3_phy_reset(tp); |
| 3236 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3237 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3239 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3240 | !tg3_flag(tp, INIT_COMPLETE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | bmsr = 0; |
| 3242 | |
| 3243 | if (!(bmsr & BMSR_LSTATUS)) { |
| 3244 | err = tg3_init_5401phy_dsp(tp); |
| 3245 | if (err) |
| 3246 | return err; |
| 3247 | |
| 3248 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3249 | for (i = 0; i < 1000; i++) { |
| 3250 | udelay(10); |
| 3251 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3252 | (bmsr & BMSR_LSTATUS)) { |
| 3253 | udelay(40); |
| 3254 | break; |
| 3255 | } |
| 3256 | } |
| 3257 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3258 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
| 3259 | TG3_PHY_REV_BCM5401_B0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | !(bmsr & BMSR_LSTATUS) && |
| 3261 | tp->link_config.active_speed == SPEED_1000) { |
| 3262 | err = tg3_phy_reset(tp); |
| 3263 | if (!err) |
| 3264 | err = tg3_init_5401phy_dsp(tp); |
| 3265 | if (err) |
| 3266 | return err; |
| 3267 | } |
| 3268 | } |
| 3269 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 3270 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { |
| 3271 | /* 5701 {A0,B0} CRC bug workaround */ |
| 3272 | tg3_writephy(tp, 0x15, 0x0a75); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 3273 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
| 3274 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 3275 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | /* Clear pending interrupts... */ |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 3279 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
| 3280 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3282 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3284 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
| 3286 | |
| 3287 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3288 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3289 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
| 3290 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 3291 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 3292 | else |
| 3293 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); |
| 3294 | } |
| 3295 | |
| 3296 | current_link_up = 0; |
| 3297 | current_speed = SPEED_INVALID; |
| 3298 | current_duplex = DUPLEX_INVALID; |
| 3299 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3300 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 3301 | err = tg3_phy_auxctl_read(tp, |
| 3302 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 3303 | &val); |
| 3304 | if (!err && !(val & (1 << 10))) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 3305 | tg3_phy_auxctl_write(tp, |
| 3306 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 3307 | val | (1 << 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | goto relink; |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | bmsr = 0; |
| 3313 | for (i = 0; i < 100; i++) { |
| 3314 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3315 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3316 | (bmsr & BMSR_LSTATUS)) |
| 3317 | break; |
| 3318 | udelay(40); |
| 3319 | } |
| 3320 | |
| 3321 | if (bmsr & BMSR_LSTATUS) { |
| 3322 | u32 aux_stat, bmcr; |
| 3323 | |
| 3324 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); |
| 3325 | for (i = 0; i < 2000; i++) { |
| 3326 | udelay(10); |
| 3327 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && |
| 3328 | aux_stat) |
| 3329 | break; |
| 3330 | } |
| 3331 | |
| 3332 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, |
| 3333 | ¤t_speed, |
| 3334 | ¤t_duplex); |
| 3335 | |
| 3336 | bmcr = 0; |
| 3337 | for (i = 0; i < 200; i++) { |
| 3338 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 3339 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) |
| 3340 | continue; |
| 3341 | if (bmcr && bmcr != 0x7fff) |
| 3342 | break; |
| 3343 | udelay(10); |
| 3344 | } |
| 3345 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3346 | lcl_adv = 0; |
| 3347 | rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3349 | tp->link_config.active_speed = current_speed; |
| 3350 | tp->link_config.active_duplex = current_duplex; |
| 3351 | |
| 3352 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 3353 | if ((bmcr & BMCR_ANENABLE) && |
| 3354 | tg3_copper_is_advertising_all(tp, |
| 3355 | tp->link_config.advertising)) { |
| 3356 | if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv, |
| 3357 | &rmt_adv)) |
| 3358 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | } |
| 3360 | } else { |
| 3361 | if (!(bmcr & BMCR_ANENABLE) && |
| 3362 | tp->link_config.speed == current_speed && |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3363 | tp->link_config.duplex == current_duplex && |
| 3364 | tp->link_config.flowctrl == |
| 3365 | tp->link_config.active_flowctrl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | } |
| 3368 | } |
| 3369 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3370 | if (current_link_up == 1 && |
| 3371 | tp->link_config.active_duplex == DUPLEX_FULL) |
| 3372 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | relink: |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3376 | 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] | 3377 | tg3_phy_copper_begin(tp); |
| 3378 | |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 3379 | tg3_readphy(tp, MII_BMSR, &bmsr); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 3380 | if ((!tg3_readphy(tp, MII_BMSR, &bmsr) && (bmsr & BMSR_LSTATUS)) || |
| 3381 | (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | current_link_up = 1; |
| 3383 | } |
| 3384 | |
| 3385 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 3386 | if (current_link_up == 1) { |
| 3387 | if (tp->link_config.active_speed == SPEED_100 || |
| 3388 | tp->link_config.active_speed == SPEED_10) |
| 3389 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 3390 | else |
| 3391 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3392 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 3393 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 3394 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 3396 | |
| 3397 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 3398 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 3399 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 3400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3402 | if (current_link_up == 1 && |
| 3403 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3405 | else |
| 3406 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | /* ??? Without this setting Netgear GA302T PHY does not |
| 3410 | * ??? send/receive packets... |
| 3411 | */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3412 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
| 3414 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
| 3415 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 3416 | udelay(80); |
| 3417 | } |
| 3418 | |
| 3419 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3420 | udelay(40); |
| 3421 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3422 | tg3_phy_eee_adjust(tp, current_link_up); |
| 3423 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3424 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | /* Polled via timer. */ |
| 3426 | tw32_f(MAC_EVENT, 0); |
| 3427 | } else { |
| 3428 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 3429 | } |
| 3430 | udelay(40); |
| 3431 | |
| 3432 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && |
| 3433 | current_link_up == 1 && |
| 3434 | tp->link_config.active_speed == SPEED_1000 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3435 | (tg3_flag(tp, PCIX_MODE) || tg3_flag(tp, PCI_HIGH_SPEED))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3436 | udelay(120); |
| 3437 | tw32_f(MAC_STATUS, |
| 3438 | (MAC_STATUS_SYNC_CHANGED | |
| 3439 | MAC_STATUS_CFG_CHANGED)); |
| 3440 | udelay(40); |
| 3441 | tg3_write_mem(tp, |
| 3442 | NIC_SRAM_FIRMWARE_MBOX, |
| 3443 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); |
| 3444 | } |
| 3445 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3446 | /* Prevent send BD corruption. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3447 | if (tg3_flag(tp, CLKREQ_BUG)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3448 | u16 oldlnkctl, newlnkctl; |
| 3449 | |
| 3450 | pci_read_config_word(tp->pdev, |
| 3451 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 3452 | &oldlnkctl); |
| 3453 | if (tp->link_config.active_speed == SPEED_100 || |
| 3454 | tp->link_config.active_speed == SPEED_10) |
| 3455 | newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3456 | else |
| 3457 | newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3458 | if (newlnkctl != oldlnkctl) |
| 3459 | pci_write_config_word(tp->pdev, |
| 3460 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 3461 | newlnkctl); |
| 3462 | } |
| 3463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 3465 | if (current_link_up) |
| 3466 | netif_carrier_on(tp->dev); |
| 3467 | else |
| 3468 | netif_carrier_off(tp->dev); |
| 3469 | tg3_link_report(tp); |
| 3470 | } |
| 3471 | |
| 3472 | return 0; |
| 3473 | } |
| 3474 | |
| 3475 | struct tg3_fiber_aneginfo { |
| 3476 | int state; |
| 3477 | #define ANEG_STATE_UNKNOWN 0 |
| 3478 | #define ANEG_STATE_AN_ENABLE 1 |
| 3479 | #define ANEG_STATE_RESTART_INIT 2 |
| 3480 | #define ANEG_STATE_RESTART 3 |
| 3481 | #define ANEG_STATE_DISABLE_LINK_OK 4 |
| 3482 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 |
| 3483 | #define ANEG_STATE_ABILITY_DETECT 6 |
| 3484 | #define ANEG_STATE_ACK_DETECT_INIT 7 |
| 3485 | #define ANEG_STATE_ACK_DETECT 8 |
| 3486 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 |
| 3487 | #define ANEG_STATE_COMPLETE_ACK 10 |
| 3488 | #define ANEG_STATE_IDLE_DETECT_INIT 11 |
| 3489 | #define ANEG_STATE_IDLE_DETECT 12 |
| 3490 | #define ANEG_STATE_LINK_OK 13 |
| 3491 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 |
| 3492 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 |
| 3493 | |
| 3494 | u32 flags; |
| 3495 | #define MR_AN_ENABLE 0x00000001 |
| 3496 | #define MR_RESTART_AN 0x00000002 |
| 3497 | #define MR_AN_COMPLETE 0x00000004 |
| 3498 | #define MR_PAGE_RX 0x00000008 |
| 3499 | #define MR_NP_LOADED 0x00000010 |
| 3500 | #define MR_TOGGLE_TX 0x00000020 |
| 3501 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 |
| 3502 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 |
| 3503 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 |
| 3504 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 |
| 3505 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 |
| 3506 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 |
| 3507 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 |
| 3508 | #define MR_TOGGLE_RX 0x00002000 |
| 3509 | #define MR_NP_RX 0x00004000 |
| 3510 | |
| 3511 | #define MR_LINK_OK 0x80000000 |
| 3512 | |
| 3513 | unsigned long link_time, cur_time; |
| 3514 | |
| 3515 | u32 ability_match_cfg; |
| 3516 | int ability_match_count; |
| 3517 | |
| 3518 | char ability_match, idle_match, ack_match; |
| 3519 | |
| 3520 | u32 txconfig, rxconfig; |
| 3521 | #define ANEG_CFG_NP 0x00000080 |
| 3522 | #define ANEG_CFG_ACK 0x00000040 |
| 3523 | #define ANEG_CFG_RF2 0x00000020 |
| 3524 | #define ANEG_CFG_RF1 0x00000010 |
| 3525 | #define ANEG_CFG_PS2 0x00000001 |
| 3526 | #define ANEG_CFG_PS1 0x00008000 |
| 3527 | #define ANEG_CFG_HD 0x00004000 |
| 3528 | #define ANEG_CFG_FD 0x00002000 |
| 3529 | #define ANEG_CFG_INVAL 0x00001f06 |
| 3530 | |
| 3531 | }; |
| 3532 | #define ANEG_OK 0 |
| 3533 | #define ANEG_DONE 1 |
| 3534 | #define ANEG_TIMER_ENAB 2 |
| 3535 | #define ANEG_FAILED -1 |
| 3536 | |
| 3537 | #define ANEG_STATE_SETTLE_TIME 10000 |
| 3538 | |
| 3539 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, |
| 3540 | struct tg3_fiber_aneginfo *ap) |
| 3541 | { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3542 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | unsigned long delta; |
| 3544 | u32 rx_cfg_reg; |
| 3545 | int ret; |
| 3546 | |
| 3547 | if (ap->state == ANEG_STATE_UNKNOWN) { |
| 3548 | ap->rxconfig = 0; |
| 3549 | ap->link_time = 0; |
| 3550 | ap->cur_time = 0; |
| 3551 | ap->ability_match_cfg = 0; |
| 3552 | ap->ability_match_count = 0; |
| 3553 | ap->ability_match = 0; |
| 3554 | ap->idle_match = 0; |
| 3555 | ap->ack_match = 0; |
| 3556 | } |
| 3557 | ap->cur_time++; |
| 3558 | |
| 3559 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { |
| 3560 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); |
| 3561 | |
| 3562 | if (rx_cfg_reg != ap->ability_match_cfg) { |
| 3563 | ap->ability_match_cfg = rx_cfg_reg; |
| 3564 | ap->ability_match = 0; |
| 3565 | ap->ability_match_count = 0; |
| 3566 | } else { |
| 3567 | if (++ap->ability_match_count > 1) { |
| 3568 | ap->ability_match = 1; |
| 3569 | ap->ability_match_cfg = rx_cfg_reg; |
| 3570 | } |
| 3571 | } |
| 3572 | if (rx_cfg_reg & ANEG_CFG_ACK) |
| 3573 | ap->ack_match = 1; |
| 3574 | else |
| 3575 | ap->ack_match = 0; |
| 3576 | |
| 3577 | ap->idle_match = 0; |
| 3578 | } else { |
| 3579 | ap->idle_match = 1; |
| 3580 | ap->ability_match_cfg = 0; |
| 3581 | ap->ability_match_count = 0; |
| 3582 | ap->ability_match = 0; |
| 3583 | ap->ack_match = 0; |
| 3584 | |
| 3585 | rx_cfg_reg = 0; |
| 3586 | } |
| 3587 | |
| 3588 | ap->rxconfig = rx_cfg_reg; |
| 3589 | ret = ANEG_OK; |
| 3590 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 3591 | switch (ap->state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | case ANEG_STATE_UNKNOWN: |
| 3593 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) |
| 3594 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3595 | |
| 3596 | /* fallthru */ |
| 3597 | case ANEG_STATE_AN_ENABLE: |
| 3598 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); |
| 3599 | if (ap->flags & MR_AN_ENABLE) { |
| 3600 | ap->link_time = 0; |
| 3601 | ap->cur_time = 0; |
| 3602 | ap->ability_match_cfg = 0; |
| 3603 | ap->ability_match_count = 0; |
| 3604 | ap->ability_match = 0; |
| 3605 | ap->idle_match = 0; |
| 3606 | ap->ack_match = 0; |
| 3607 | |
| 3608 | ap->state = ANEG_STATE_RESTART_INIT; |
| 3609 | } else { |
| 3610 | ap->state = ANEG_STATE_DISABLE_LINK_OK; |
| 3611 | } |
| 3612 | break; |
| 3613 | |
| 3614 | case ANEG_STATE_RESTART_INIT: |
| 3615 | ap->link_time = ap->cur_time; |
| 3616 | ap->flags &= ~(MR_NP_LOADED); |
| 3617 | ap->txconfig = 0; |
| 3618 | tw32(MAC_TX_AUTO_NEG, 0); |
| 3619 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3620 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3621 | udelay(40); |
| 3622 | |
| 3623 | ret = ANEG_TIMER_ENAB; |
| 3624 | ap->state = ANEG_STATE_RESTART; |
| 3625 | |
| 3626 | /* fallthru */ |
| 3627 | case ANEG_STATE_RESTART: |
| 3628 | delta = ap->cur_time - ap->link_time; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 3629 | if (delta > ANEG_STATE_SETTLE_TIME) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 3631 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | ret = ANEG_TIMER_ENAB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | break; |
| 3634 | |
| 3635 | case ANEG_STATE_DISABLE_LINK_OK: |
| 3636 | ret = ANEG_DONE; |
| 3637 | break; |
| 3638 | |
| 3639 | case ANEG_STATE_ABILITY_DETECT_INIT: |
| 3640 | ap->flags &= ~(MR_TOGGLE_TX); |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3641 | ap->txconfig = ANEG_CFG_FD; |
| 3642 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 3643 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 3644 | ap->txconfig |= ANEG_CFG_PS1; |
| 3645 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 3646 | ap->txconfig |= ANEG_CFG_PS2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 3648 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3649 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3650 | udelay(40); |
| 3651 | |
| 3652 | ap->state = ANEG_STATE_ABILITY_DETECT; |
| 3653 | break; |
| 3654 | |
| 3655 | case ANEG_STATE_ABILITY_DETECT: |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 3656 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | break; |
| 3659 | |
| 3660 | case ANEG_STATE_ACK_DETECT_INIT: |
| 3661 | ap->txconfig |= ANEG_CFG_ACK; |
| 3662 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 3663 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3664 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3665 | udelay(40); |
| 3666 | |
| 3667 | ap->state = ANEG_STATE_ACK_DETECT; |
| 3668 | |
| 3669 | /* fallthru */ |
| 3670 | case ANEG_STATE_ACK_DETECT: |
| 3671 | if (ap->ack_match != 0) { |
| 3672 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == |
| 3673 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { |
| 3674 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; |
| 3675 | } else { |
| 3676 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3677 | } |
| 3678 | } else if (ap->ability_match != 0 && |
| 3679 | ap->rxconfig == 0) { |
| 3680 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3681 | } |
| 3682 | break; |
| 3683 | |
| 3684 | case ANEG_STATE_COMPLETE_ACK_INIT: |
| 3685 | if (ap->rxconfig & ANEG_CFG_INVAL) { |
| 3686 | ret = ANEG_FAILED; |
| 3687 | break; |
| 3688 | } |
| 3689 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | |
| 3690 | MR_LP_ADV_HALF_DUPLEX | |
| 3691 | MR_LP_ADV_SYM_PAUSE | |
| 3692 | MR_LP_ADV_ASYM_PAUSE | |
| 3693 | MR_LP_ADV_REMOTE_FAULT1 | |
| 3694 | MR_LP_ADV_REMOTE_FAULT2 | |
| 3695 | MR_LP_ADV_NEXT_PAGE | |
| 3696 | MR_TOGGLE_RX | |
| 3697 | MR_NP_RX); |
| 3698 | if (ap->rxconfig & ANEG_CFG_FD) |
| 3699 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; |
| 3700 | if (ap->rxconfig & ANEG_CFG_HD) |
| 3701 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; |
| 3702 | if (ap->rxconfig & ANEG_CFG_PS1) |
| 3703 | ap->flags |= MR_LP_ADV_SYM_PAUSE; |
| 3704 | if (ap->rxconfig & ANEG_CFG_PS2) |
| 3705 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; |
| 3706 | if (ap->rxconfig & ANEG_CFG_RF1) |
| 3707 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; |
| 3708 | if (ap->rxconfig & ANEG_CFG_RF2) |
| 3709 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; |
| 3710 | if (ap->rxconfig & ANEG_CFG_NP) |
| 3711 | ap->flags |= MR_LP_ADV_NEXT_PAGE; |
| 3712 | |
| 3713 | ap->link_time = ap->cur_time; |
| 3714 | |
| 3715 | ap->flags ^= (MR_TOGGLE_TX); |
| 3716 | if (ap->rxconfig & 0x0008) |
| 3717 | ap->flags |= MR_TOGGLE_RX; |
| 3718 | if (ap->rxconfig & ANEG_CFG_NP) |
| 3719 | ap->flags |= MR_NP_RX; |
| 3720 | ap->flags |= MR_PAGE_RX; |
| 3721 | |
| 3722 | ap->state = ANEG_STATE_COMPLETE_ACK; |
| 3723 | ret = ANEG_TIMER_ENAB; |
| 3724 | break; |
| 3725 | |
| 3726 | case ANEG_STATE_COMPLETE_ACK: |
| 3727 | if (ap->ability_match != 0 && |
| 3728 | ap->rxconfig == 0) { |
| 3729 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3730 | break; |
| 3731 | } |
| 3732 | delta = ap->cur_time - ap->link_time; |
| 3733 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 3734 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { |
| 3735 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 3736 | } else { |
| 3737 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && |
| 3738 | !(ap->flags & MR_NP_RX)) { |
| 3739 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 3740 | } else { |
| 3741 | ret = ANEG_FAILED; |
| 3742 | } |
| 3743 | } |
| 3744 | } |
| 3745 | break; |
| 3746 | |
| 3747 | case ANEG_STATE_IDLE_DETECT_INIT: |
| 3748 | ap->link_time = ap->cur_time; |
| 3749 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 3750 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3751 | udelay(40); |
| 3752 | |
| 3753 | ap->state = ANEG_STATE_IDLE_DETECT; |
| 3754 | ret = ANEG_TIMER_ENAB; |
| 3755 | break; |
| 3756 | |
| 3757 | case ANEG_STATE_IDLE_DETECT: |
| 3758 | if (ap->ability_match != 0 && |
| 3759 | ap->rxconfig == 0) { |
| 3760 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3761 | break; |
| 3762 | } |
| 3763 | delta = ap->cur_time - ap->link_time; |
| 3764 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 3765 | /* XXX another gem from the Broadcom driver :( */ |
| 3766 | ap->state = ANEG_STATE_LINK_OK; |
| 3767 | } |
| 3768 | break; |
| 3769 | |
| 3770 | case ANEG_STATE_LINK_OK: |
| 3771 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); |
| 3772 | ret = ANEG_DONE; |
| 3773 | break; |
| 3774 | |
| 3775 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: |
| 3776 | /* ??? unimplemented */ |
| 3777 | break; |
| 3778 | |
| 3779 | case ANEG_STATE_NEXT_PAGE_WAIT: |
| 3780 | /* ??? unimplemented */ |
| 3781 | break; |
| 3782 | |
| 3783 | default: |
| 3784 | ret = ANEG_FAILED; |
| 3785 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3786 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | |
| 3788 | return ret; |
| 3789 | } |
| 3790 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3791 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | { |
| 3793 | int res = 0; |
| 3794 | struct tg3_fiber_aneginfo aninfo; |
| 3795 | int status = ANEG_FAILED; |
| 3796 | unsigned int tick; |
| 3797 | u32 tmp; |
| 3798 | |
| 3799 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 3800 | |
| 3801 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
| 3802 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); |
| 3803 | udelay(40); |
| 3804 | |
| 3805 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); |
| 3806 | udelay(40); |
| 3807 | |
| 3808 | memset(&aninfo, 0, sizeof(aninfo)); |
| 3809 | aninfo.flags |= MR_AN_ENABLE; |
| 3810 | aninfo.state = ANEG_STATE_UNKNOWN; |
| 3811 | aninfo.cur_time = 0; |
| 3812 | tick = 0; |
| 3813 | while (++tick < 195000) { |
| 3814 | status = tg3_fiber_aneg_smachine(tp, &aninfo); |
| 3815 | if (status == ANEG_DONE || status == ANEG_FAILED) |
| 3816 | break; |
| 3817 | |
| 3818 | udelay(1); |
| 3819 | } |
| 3820 | |
| 3821 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 3822 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3823 | udelay(40); |
| 3824 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3825 | *txflags = aninfo.txconfig; |
| 3826 | *rxflags = aninfo.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | |
| 3828 | if (status == ANEG_DONE && |
| 3829 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | |
| 3830 | MR_LP_ADV_FULL_DUPLEX))) |
| 3831 | res = 1; |
| 3832 | |
| 3833 | return res; |
| 3834 | } |
| 3835 | |
| 3836 | static void tg3_init_bcm8002(struct tg3 *tp) |
| 3837 | { |
| 3838 | u32 mac_status = tr32(MAC_STATUS); |
| 3839 | int i; |
| 3840 | |
| 3841 | /* Reset when initting first time or we have a link. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3842 | if (tg3_flag(tp, INIT_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 3844 | return; |
| 3845 | |
| 3846 | /* Set PLL lock range. */ |
| 3847 | tg3_writephy(tp, 0x16, 0x8007); |
| 3848 | |
| 3849 | /* SW reset */ |
| 3850 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); |
| 3851 | |
| 3852 | /* Wait for reset to complete. */ |
| 3853 | /* XXX schedule_timeout() ... */ |
| 3854 | for (i = 0; i < 500; i++) |
| 3855 | udelay(10); |
| 3856 | |
| 3857 | /* Config mode; select PMA/Ch 1 regs. */ |
| 3858 | tg3_writephy(tp, 0x10, 0x8411); |
| 3859 | |
| 3860 | /* Enable auto-lock and comdet, select txclk for tx. */ |
| 3861 | tg3_writephy(tp, 0x11, 0x0a10); |
| 3862 | |
| 3863 | tg3_writephy(tp, 0x18, 0x00a0); |
| 3864 | tg3_writephy(tp, 0x16, 0x41ff); |
| 3865 | |
| 3866 | /* Assert and deassert POR. */ |
| 3867 | tg3_writephy(tp, 0x13, 0x0400); |
| 3868 | udelay(40); |
| 3869 | tg3_writephy(tp, 0x13, 0x0000); |
| 3870 | |
| 3871 | tg3_writephy(tp, 0x11, 0x0a50); |
| 3872 | udelay(40); |
| 3873 | tg3_writephy(tp, 0x11, 0x0a10); |
| 3874 | |
| 3875 | /* Wait for signal to stabilize */ |
| 3876 | /* XXX schedule_timeout() ... */ |
| 3877 | for (i = 0; i < 15000; i++) |
| 3878 | udelay(10); |
| 3879 | |
| 3880 | /* Deselect the channel register so we can read the PHYID |
| 3881 | * later. |
| 3882 | */ |
| 3883 | tg3_writephy(tp, 0x10, 0x8011); |
| 3884 | } |
| 3885 | |
| 3886 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
| 3887 | { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3888 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | u32 sg_dig_ctrl, sg_dig_status; |
| 3890 | u32 serdes_cfg, expected_sg_dig_ctrl; |
| 3891 | int workaround, port_a; |
| 3892 | int current_link_up; |
| 3893 | |
| 3894 | serdes_cfg = 0; |
| 3895 | expected_sg_dig_ctrl = 0; |
| 3896 | workaround = 0; |
| 3897 | port_a = 1; |
| 3898 | current_link_up = 0; |
| 3899 | |
| 3900 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && |
| 3901 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { |
| 3902 | workaround = 1; |
| 3903 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 3904 | port_a = 0; |
| 3905 | |
| 3906 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ |
| 3907 | /* preserve bits 20-23 for voltage regulator */ |
| 3908 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; |
| 3909 | } |
| 3910 | |
| 3911 | sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 3912 | |
| 3913 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3914 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | if (workaround) { |
| 3916 | u32 val = serdes_cfg; |
| 3917 | |
| 3918 | if (port_a) |
| 3919 | val |= 0xc010000; |
| 3920 | else |
| 3921 | val |= 0x4010000; |
| 3922 | tw32_f(MAC_SERDES_CFG, val); |
| 3923 | } |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3924 | |
| 3925 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | } |
| 3927 | if (mac_status & MAC_STATUS_PCS_SYNCED) { |
| 3928 | tg3_setup_flow_control(tp, 0, 0); |
| 3929 | current_link_up = 1; |
| 3930 | } |
| 3931 | goto out; |
| 3932 | } |
| 3933 | |
| 3934 | /* Want auto-negotiation. */ |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3935 | 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] | 3936 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3937 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 3938 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 3939 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; |
| 3940 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 3941 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | |
| 3943 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3944 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3945 | tp->serdes_counter && |
| 3946 | ((mac_status & (MAC_STATUS_PCS_SYNCED | |
| 3947 | MAC_STATUS_RCVD_CFG)) == |
| 3948 | MAC_STATUS_PCS_SYNCED)) { |
| 3949 | tp->serdes_counter--; |
| 3950 | current_link_up = 1; |
| 3951 | goto out; |
| 3952 | } |
| 3953 | restart_autoneg: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | if (workaround) |
| 3955 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3956 | 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] | 3957 | udelay(5); |
| 3958 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); |
| 3959 | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3960 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3961 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
| 3963 | MAC_STATUS_SIGNAL_DET)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3964 | sg_dig_status = tr32(SG_DIG_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 | mac_status = tr32(MAC_STATUS); |
| 3966 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3967 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3969 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3971 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) |
| 3972 | local_adv |= ADVERTISE_1000XPAUSE; |
| 3973 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) |
| 3974 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 3975 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3976 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3977 | remote_adv |= LPA_1000XPAUSE; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3978 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3979 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | |
| 3981 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 3982 | current_link_up = 1; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3983 | tp->serdes_counter = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3984 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3985 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3986 | if (tp->serdes_counter) |
| 3987 | tp->serdes_counter--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | else { |
| 3989 | if (workaround) { |
| 3990 | u32 val = serdes_cfg; |
| 3991 | |
| 3992 | if (port_a) |
| 3993 | val |= 0xc010000; |
| 3994 | else |
| 3995 | val |= 0x4010000; |
| 3996 | |
| 3997 | tw32_f(MAC_SERDES_CFG, val); |
| 3998 | } |
| 3999 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4000 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | udelay(40); |
| 4002 | |
| 4003 | /* Link parallel detection - link is up */ |
| 4004 | /* only if we have PCS_SYNC and not */ |
| 4005 | /* receiving config code words */ |
| 4006 | mac_status = tr32(MAC_STATUS); |
| 4007 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && |
| 4008 | !(mac_status & MAC_STATUS_RCVD_CFG)) { |
| 4009 | tg3_setup_flow_control(tp, 0, 0); |
| 4010 | current_link_up = 1; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4011 | tp->phy_flags |= |
| 4012 | TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4013 | tp->serdes_counter = |
| 4014 | SERDES_PARALLEL_DET_TIMEOUT; |
| 4015 | } else |
| 4016 | goto restart_autoneg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | } |
| 4018 | } |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4019 | } else { |
| 4020 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4021 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | out: |
| 4025 | return current_link_up; |
| 4026 | } |
| 4027 | |
| 4028 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
| 4029 | { |
| 4030 | int current_link_up = 0; |
| 4031 | |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 4032 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | |
| 4035 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4036 | u32 txflags, rxflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 4038 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4039 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
| 4040 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4042 | if (txflags & ANEG_CFG_PS1) |
| 4043 | local_adv |= ADVERTISE_1000XPAUSE; |
| 4044 | if (txflags & ANEG_CFG_PS2) |
| 4045 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 4046 | |
| 4047 | if (rxflags & MR_LP_ADV_SYM_PAUSE) |
| 4048 | remote_adv |= LPA_1000XPAUSE; |
| 4049 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) |
| 4050 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | |
| 4052 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | current_link_up = 1; |
| 4055 | } |
| 4056 | for (i = 0; i < 30; i++) { |
| 4057 | udelay(20); |
| 4058 | tw32_f(MAC_STATUS, |
| 4059 | (MAC_STATUS_SYNC_CHANGED | |
| 4060 | MAC_STATUS_CFG_CHANGED)); |
| 4061 | udelay(40); |
| 4062 | if ((tr32(MAC_STATUS) & |
| 4063 | (MAC_STATUS_SYNC_CHANGED | |
| 4064 | MAC_STATUS_CFG_CHANGED)) == 0) |
| 4065 | break; |
| 4066 | } |
| 4067 | |
| 4068 | mac_status = tr32(MAC_STATUS); |
| 4069 | if (current_link_up == 0 && |
| 4070 | (mac_status & MAC_STATUS_PCS_SYNCED) && |
| 4071 | !(mac_status & MAC_STATUS_RCVD_CFG)) |
| 4072 | current_link_up = 1; |
| 4073 | } else { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4074 | tg3_setup_flow_control(tp, 0, 0); |
| 4075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | /* Forcing 1000FD link up. */ |
| 4077 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | |
| 4079 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); |
| 4080 | udelay(40); |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4081 | |
| 4082 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4083 | udelay(40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | out: |
| 4087 | return current_link_up; |
| 4088 | } |
| 4089 | |
| 4090 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) |
| 4091 | { |
| 4092 | u32 orig_pause_cfg; |
| 4093 | u16 orig_active_speed; |
| 4094 | u8 orig_active_duplex; |
| 4095 | u32 mac_status; |
| 4096 | int current_link_up; |
| 4097 | int i; |
| 4098 | |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 4099 | orig_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | orig_active_speed = tp->link_config.active_speed; |
| 4101 | orig_active_duplex = tp->link_config.active_duplex; |
| 4102 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4103 | if (!tg3_flag(tp, HW_AUTONEG) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | netif_carrier_ok(tp->dev) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4105 | tg3_flag(tp, INIT_COMPLETE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | mac_status = tr32(MAC_STATUS); |
| 4107 | mac_status &= (MAC_STATUS_PCS_SYNCED | |
| 4108 | MAC_STATUS_SIGNAL_DET | |
| 4109 | MAC_STATUS_CFG_CHANGED | |
| 4110 | MAC_STATUS_RCVD_CFG); |
| 4111 | if (mac_status == (MAC_STATUS_PCS_SYNCED | |
| 4112 | MAC_STATUS_SIGNAL_DET)) { |
| 4113 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 4114 | MAC_STATUS_CFG_CHANGED)); |
| 4115 | return 0; |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 4120 | |
| 4121 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 4122 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 4123 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4124 | udelay(40); |
| 4125 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4126 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | tg3_init_bcm8002(tp); |
| 4128 | |
| 4129 | /* Enable link change event even when serdes polling. */ |
| 4130 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4131 | udelay(40); |
| 4132 | |
| 4133 | current_link_up = 0; |
| 4134 | mac_status = tr32(MAC_STATUS); |
| 4135 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4136 | if (tg3_flag(tp, HW_AUTONEG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
| 4138 | else |
| 4139 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); |
| 4140 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 4141 | tp->napi[0].hw_status->status = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | (SD_STATUS_UPDATED | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 4143 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | |
| 4145 | for (i = 0; i < 100; i++) { |
| 4146 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 4147 | MAC_STATUS_CFG_CHANGED)); |
| 4148 | udelay(5); |
| 4149 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4150 | MAC_STATUS_CFG_CHANGED | |
| 4151 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | break; |
| 4153 | } |
| 4154 | |
| 4155 | mac_status = tr32(MAC_STATUS); |
| 4156 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { |
| 4157 | current_link_up = 0; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4158 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 4159 | tp->serdes_counter == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | tw32_f(MAC_MODE, (tp->mac_mode | |
| 4161 | MAC_MODE_SEND_CONFIGS)); |
| 4162 | udelay(1); |
| 4163 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4164 | } |
| 4165 | } |
| 4166 | |
| 4167 | if (current_link_up == 1) { |
| 4168 | tp->link_config.active_speed = SPEED_1000; |
| 4169 | tp->link_config.active_duplex = DUPLEX_FULL; |
| 4170 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 4171 | LED_CTRL_LNKLED_OVERRIDE | |
| 4172 | LED_CTRL_1000MBPS_ON)); |
| 4173 | } else { |
| 4174 | tp->link_config.active_speed = SPEED_INVALID; |
| 4175 | tp->link_config.active_duplex = DUPLEX_INVALID; |
| 4176 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 4177 | LED_CTRL_LNKLED_OVERRIDE | |
| 4178 | LED_CTRL_TRAFFIC_OVERRIDE)); |
| 4179 | } |
| 4180 | |
| 4181 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 4182 | if (current_link_up) |
| 4183 | netif_carrier_on(tp->dev); |
| 4184 | else |
| 4185 | netif_carrier_off(tp->dev); |
| 4186 | tg3_link_report(tp); |
| 4187 | } else { |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 4188 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | if (orig_pause_cfg != now_pause_cfg || |
| 4190 | orig_active_speed != tp->link_config.active_speed || |
| 4191 | orig_active_duplex != tp->link_config.active_duplex) |
| 4192 | tg3_link_report(tp); |
| 4193 | } |
| 4194 | |
| 4195 | return 0; |
| 4196 | } |
| 4197 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4198 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
| 4199 | { |
| 4200 | int current_link_up, err = 0; |
| 4201 | u32 bmsr, bmcr; |
| 4202 | u16 current_speed; |
| 4203 | u8 current_duplex; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4204 | u32 local_adv, remote_adv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4205 | |
| 4206 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4207 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4208 | udelay(40); |
| 4209 | |
| 4210 | tw32(MAC_EVENT, 0); |
| 4211 | |
| 4212 | tw32_f(MAC_STATUS, |
| 4213 | (MAC_STATUS_SYNC_CHANGED | |
| 4214 | MAC_STATUS_CFG_CHANGED | |
| 4215 | MAC_STATUS_MI_COMPLETION | |
| 4216 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4217 | udelay(40); |
| 4218 | |
| 4219 | if (force_reset) |
| 4220 | tg3_phy_reset(tp); |
| 4221 | |
| 4222 | current_link_up = 0; |
| 4223 | current_speed = SPEED_INVALID; |
| 4224 | current_duplex = DUPLEX_INVALID; |
| 4225 | |
| 4226 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4227 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 4228 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 4229 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 4230 | bmsr |= BMSR_LSTATUS; |
| 4231 | else |
| 4232 | bmsr &= ~BMSR_LSTATUS; |
| 4233 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4234 | |
| 4235 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4236 | |
| 4237 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4238 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4239 | /* do nothing, just check for link up at the end */ |
| 4240 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 4241 | u32 adv, new_adv; |
| 4242 | |
| 4243 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 4244 | new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
| 4245 | ADVERTISE_1000XPAUSE | |
| 4246 | ADVERTISE_1000XPSE_ASYM | |
| 4247 | ADVERTISE_SLCT); |
| 4248 | |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4249 | new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4250 | |
| 4251 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) |
| 4252 | new_adv |= ADVERTISE_1000XHALF; |
| 4253 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) |
| 4254 | new_adv |= ADVERTISE_1000XFULL; |
| 4255 | |
| 4256 | if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) { |
| 4257 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 4258 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 4259 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 4260 | |
| 4261 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4262 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4263 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4264 | |
| 4265 | return err; |
| 4266 | } |
| 4267 | } else { |
| 4268 | u32 new_bmcr; |
| 4269 | |
| 4270 | bmcr &= ~BMCR_SPEED1000; |
| 4271 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4272 | |
| 4273 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 4274 | new_bmcr |= BMCR_FULLDPLX; |
| 4275 | |
| 4276 | if (new_bmcr != bmcr) { |
| 4277 | /* BMCR_SPEED1000 is a reserved bit that needs |
| 4278 | * to be set on write. |
| 4279 | */ |
| 4280 | new_bmcr |= BMCR_SPEED1000; |
| 4281 | |
| 4282 | /* Force a linkdown */ |
| 4283 | if (netif_carrier_ok(tp->dev)) { |
| 4284 | u32 adv; |
| 4285 | |
| 4286 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 4287 | adv &= ~(ADVERTISE_1000XFULL | |
| 4288 | ADVERTISE_1000XHALF | |
| 4289 | ADVERTISE_SLCT); |
| 4290 | tg3_writephy(tp, MII_ADVERTISE, adv); |
| 4291 | tg3_writephy(tp, MII_BMCR, bmcr | |
| 4292 | BMCR_ANRESTART | |
| 4293 | BMCR_ANENABLE); |
| 4294 | udelay(10); |
| 4295 | netif_carrier_off(tp->dev); |
| 4296 | } |
| 4297 | tg3_writephy(tp, MII_BMCR, new_bmcr); |
| 4298 | bmcr = new_bmcr; |
| 4299 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4300 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 4301 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 4302 | ASIC_REV_5714) { |
| 4303 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 4304 | bmsr |= BMSR_LSTATUS; |
| 4305 | else |
| 4306 | bmsr &= ~BMSR_LSTATUS; |
| 4307 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4308 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4309 | } |
| 4310 | } |
| 4311 | |
| 4312 | if (bmsr & BMSR_LSTATUS) { |
| 4313 | current_speed = SPEED_1000; |
| 4314 | current_link_up = 1; |
| 4315 | if (bmcr & BMCR_FULLDPLX) |
| 4316 | current_duplex = DUPLEX_FULL; |
| 4317 | else |
| 4318 | current_duplex = DUPLEX_HALF; |
| 4319 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4320 | local_adv = 0; |
| 4321 | remote_adv = 0; |
| 4322 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4323 | if (bmcr & BMCR_ANENABLE) { |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4324 | u32 common; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4325 | |
| 4326 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); |
| 4327 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); |
| 4328 | common = local_adv & remote_adv; |
| 4329 | if (common & (ADVERTISE_1000XHALF | |
| 4330 | ADVERTISE_1000XFULL)) { |
| 4331 | if (common & ADVERTISE_1000XFULL) |
| 4332 | current_duplex = DUPLEX_FULL; |
| 4333 | else |
| 4334 | current_duplex = DUPLEX_HALF; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4335 | } else if (!tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 4336 | /* Link is up via parallel detect */ |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4337 | } else { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4338 | current_link_up = 0; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4339 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4340 | } |
| 4341 | } |
| 4342 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4343 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
| 4344 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4345 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4346 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 4347 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 4348 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 4349 | |
| 4350 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4351 | udelay(40); |
| 4352 | |
| 4353 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4354 | |
| 4355 | tp->link_config.active_speed = current_speed; |
| 4356 | tp->link_config.active_duplex = current_duplex; |
| 4357 | |
| 4358 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 4359 | if (current_link_up) |
| 4360 | netif_carrier_on(tp->dev); |
| 4361 | else { |
| 4362 | netif_carrier_off(tp->dev); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4363 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4364 | } |
| 4365 | tg3_link_report(tp); |
| 4366 | } |
| 4367 | return err; |
| 4368 | } |
| 4369 | |
| 4370 | static void tg3_serdes_parallel_detect(struct tg3 *tp) |
| 4371 | { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4372 | if (tp->serdes_counter) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4373 | /* Give autoneg time to complete. */ |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4374 | tp->serdes_counter--; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4375 | return; |
| 4376 | } |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 4377 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4378 | if (!netif_carrier_ok(tp->dev) && |
| 4379 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { |
| 4380 | u32 bmcr; |
| 4381 | |
| 4382 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4383 | if (bmcr & BMCR_ANENABLE) { |
| 4384 | u32 phy1, phy2; |
| 4385 | |
| 4386 | /* Select shadow register 0x1f */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4387 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
| 4388 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4389 | |
| 4390 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4391 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 4392 | MII_TG3_DSP_EXP1_INT_STAT); |
| 4393 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 4394 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4395 | |
| 4396 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { |
| 4397 | /* We have signal detect and not receiving |
| 4398 | * config code words, link is up by parallel |
| 4399 | * detection. |
| 4400 | */ |
| 4401 | |
| 4402 | bmcr &= ~BMCR_ANENABLE; |
| 4403 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; |
| 4404 | tg3_writephy(tp, MII_BMCR, bmcr); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4405 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4406 | } |
| 4407 | } |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4408 | } else if (netif_carrier_ok(tp->dev) && |
| 4409 | (tp->link_config.autoneg == AUTONEG_ENABLE) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4410 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4411 | u32 phy2; |
| 4412 | |
| 4413 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4414 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 4415 | MII_TG3_DSP_EXP1_INT_STAT); |
| 4416 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4417 | if (phy2 & 0x20) { |
| 4418 | u32 bmcr; |
| 4419 | |
| 4420 | /* Config code words received, turn on autoneg. */ |
| 4421 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4422 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); |
| 4423 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4424 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4425 | |
| 4426 | } |
| 4427 | } |
| 4428 | } |
| 4429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
| 4431 | { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 4432 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | int err; |
| 4434 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4435 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | err = tg3_setup_fiber_phy(tp, force_reset); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4437 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4438 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4439 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | err = tg3_setup_copper_phy(tp, force_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 4442 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 4443 | u32 scale; |
Matt Carlson | aa6c91f | 2007-11-12 21:18:04 -0800 | [diff] [blame] | 4444 | |
| 4445 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; |
| 4446 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) |
| 4447 | scale = 65; |
| 4448 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) |
| 4449 | scale = 6; |
| 4450 | else |
| 4451 | scale = 12; |
| 4452 | |
| 4453 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; |
| 4454 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 4455 | tw32(GRC_MISC_CFG, val); |
| 4456 | } |
| 4457 | |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 4458 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 4459 | (6 << TX_LENGTHS_IPG_SHIFT); |
| 4460 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 4461 | val |= tr32(MAC_TX_LENGTHS) & |
| 4462 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 4463 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 4464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | if (tp->link_config.active_speed == SPEED_1000 && |
| 4466 | tp->link_config.active_duplex == DUPLEX_HALF) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 4467 | tw32(MAC_TX_LENGTHS, val | |
| 4468 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | else |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 4470 | tw32(MAC_TX_LENGTHS, val | |
| 4471 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4473 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | if (netif_carrier_ok(tp->dev)) { |
| 4475 | tw32(HOSTCC_STAT_COAL_TICKS, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 4476 | tp->coal.stats_block_coalesce_usecs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | } else { |
| 4478 | tw32(HOSTCC_STAT_COAL_TICKS, 0); |
| 4479 | } |
| 4480 | } |
| 4481 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4482 | if (tg3_flag(tp, ASPM_WORKAROUND)) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 4483 | val = tr32(PCIE_PWR_MGMT_THRESH); |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 4484 | if (!netif_carrier_ok(tp->dev)) |
| 4485 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
| 4486 | tp->pwrmgmt_thresh; |
| 4487 | else |
| 4488 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 4489 | tw32(PCIE_PWR_MGMT_THRESH, val); |
| 4490 | } |
| 4491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | return err; |
| 4493 | } |
| 4494 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 4495 | static inline int tg3_irq_sync(struct tg3 *tp) |
| 4496 | { |
| 4497 | return tp->irq_sync; |
| 4498 | } |
| 4499 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 4500 | static inline void tg3_rd32_loop(struct tg3 *tp, u32 *dst, u32 off, u32 len) |
| 4501 | { |
| 4502 | int i; |
| 4503 | |
| 4504 | dst = (u32 *)((u8 *)dst + off); |
| 4505 | for (i = 0; i < len; i += sizeof(u32)) |
| 4506 | *dst++ = tr32(off + i); |
| 4507 | } |
| 4508 | |
| 4509 | static void tg3_dump_legacy_regs(struct tg3 *tp, u32 *regs) |
| 4510 | { |
| 4511 | tg3_rd32_loop(tp, regs, TG3PCI_VENDOR, 0xb0); |
| 4512 | tg3_rd32_loop(tp, regs, MAILBOX_INTERRUPT_0, 0x200); |
| 4513 | tg3_rd32_loop(tp, regs, MAC_MODE, 0x4f0); |
| 4514 | tg3_rd32_loop(tp, regs, SNDDATAI_MODE, 0xe0); |
| 4515 | tg3_rd32_loop(tp, regs, SNDDATAC_MODE, 0x04); |
| 4516 | tg3_rd32_loop(tp, regs, SNDBDS_MODE, 0x80); |
| 4517 | tg3_rd32_loop(tp, regs, SNDBDI_MODE, 0x48); |
| 4518 | tg3_rd32_loop(tp, regs, SNDBDC_MODE, 0x04); |
| 4519 | tg3_rd32_loop(tp, regs, RCVLPC_MODE, 0x20); |
| 4520 | tg3_rd32_loop(tp, regs, RCVLPC_SELLST_BASE, 0x15c); |
| 4521 | tg3_rd32_loop(tp, regs, RCVDBDI_MODE, 0x0c); |
| 4522 | tg3_rd32_loop(tp, regs, RCVDBDI_JUMBO_BD, 0x3c); |
| 4523 | tg3_rd32_loop(tp, regs, RCVDBDI_BD_PROD_IDX_0, 0x44); |
| 4524 | tg3_rd32_loop(tp, regs, RCVDCC_MODE, 0x04); |
| 4525 | tg3_rd32_loop(tp, regs, RCVBDI_MODE, 0x20); |
| 4526 | tg3_rd32_loop(tp, regs, RCVCC_MODE, 0x14); |
| 4527 | tg3_rd32_loop(tp, regs, RCVLSC_MODE, 0x08); |
| 4528 | tg3_rd32_loop(tp, regs, MBFREE_MODE, 0x08); |
| 4529 | tg3_rd32_loop(tp, regs, HOSTCC_MODE, 0x100); |
| 4530 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4531 | if (tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 4532 | tg3_rd32_loop(tp, regs, HOSTCC_RXCOL_TICKS_VEC1, 0x180); |
| 4533 | |
| 4534 | tg3_rd32_loop(tp, regs, MEMARB_MODE, 0x10); |
| 4535 | tg3_rd32_loop(tp, regs, BUFMGR_MODE, 0x58); |
| 4536 | tg3_rd32_loop(tp, regs, RDMAC_MODE, 0x08); |
| 4537 | tg3_rd32_loop(tp, regs, WDMAC_MODE, 0x08); |
| 4538 | tg3_rd32_loop(tp, regs, RX_CPU_MODE, 0x04); |
| 4539 | tg3_rd32_loop(tp, regs, RX_CPU_STATE, 0x04); |
| 4540 | tg3_rd32_loop(tp, regs, RX_CPU_PGMCTR, 0x04); |
| 4541 | tg3_rd32_loop(tp, regs, RX_CPU_HWBKPT, 0x04); |
| 4542 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4543 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 4544 | tg3_rd32_loop(tp, regs, TX_CPU_MODE, 0x04); |
| 4545 | tg3_rd32_loop(tp, regs, TX_CPU_STATE, 0x04); |
| 4546 | tg3_rd32_loop(tp, regs, TX_CPU_PGMCTR, 0x04); |
| 4547 | } |
| 4548 | |
| 4549 | tg3_rd32_loop(tp, regs, GRCMBOX_INTERRUPT_0, 0x110); |
| 4550 | tg3_rd32_loop(tp, regs, FTQ_RESET, 0x120); |
| 4551 | tg3_rd32_loop(tp, regs, MSGINT_MODE, 0x0c); |
| 4552 | tg3_rd32_loop(tp, regs, DMAC_MODE, 0x04); |
| 4553 | tg3_rd32_loop(tp, regs, GRC_MODE, 0x4c); |
| 4554 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4555 | if (tg3_flag(tp, NVRAM)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 4556 | tg3_rd32_loop(tp, regs, NVRAM_CMD, 0x24); |
| 4557 | } |
| 4558 | |
| 4559 | static void tg3_dump_state(struct tg3 *tp) |
| 4560 | { |
| 4561 | int i; |
| 4562 | u32 *regs; |
| 4563 | |
| 4564 | regs = kzalloc(TG3_REG_BLK_SIZE, GFP_ATOMIC); |
| 4565 | if (!regs) { |
| 4566 | netdev_err(tp->dev, "Failed allocating register dump buffer\n"); |
| 4567 | return; |
| 4568 | } |
| 4569 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4570 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 4571 | /* Read up to but not including private PCI registers */ |
| 4572 | for (i = 0; i < TG3_PCIE_TLDLPL_PORT; i += sizeof(u32)) |
| 4573 | regs[i / sizeof(u32)] = tr32(i); |
| 4574 | } else |
| 4575 | tg3_dump_legacy_regs(tp, regs); |
| 4576 | |
| 4577 | for (i = 0; i < TG3_REG_BLK_SIZE / sizeof(u32); i += 4) { |
| 4578 | if (!regs[i + 0] && !regs[i + 1] && |
| 4579 | !regs[i + 2] && !regs[i + 3]) |
| 4580 | continue; |
| 4581 | |
| 4582 | netdev_err(tp->dev, "0x%08x: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", |
| 4583 | i * 4, |
| 4584 | regs[i + 0], regs[i + 1], regs[i + 2], regs[i + 3]); |
| 4585 | } |
| 4586 | |
| 4587 | kfree(regs); |
| 4588 | |
| 4589 | for (i = 0; i < tp->irq_cnt; i++) { |
| 4590 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 4591 | |
| 4592 | /* SW status block */ |
| 4593 | netdev_err(tp->dev, |
| 4594 | "%d: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", |
| 4595 | i, |
| 4596 | tnapi->hw_status->status, |
| 4597 | tnapi->hw_status->status_tag, |
| 4598 | tnapi->hw_status->rx_jumbo_consumer, |
| 4599 | tnapi->hw_status->rx_consumer, |
| 4600 | tnapi->hw_status->rx_mini_consumer, |
| 4601 | tnapi->hw_status->idx[0].rx_producer, |
| 4602 | tnapi->hw_status->idx[0].tx_consumer); |
| 4603 | |
| 4604 | netdev_err(tp->dev, |
| 4605 | "%d: NAPI info [%08x:%08x:(%04x:%04x:%04x):%04x:(%04x:%04x:%04x:%04x)]\n", |
| 4606 | i, |
| 4607 | tnapi->last_tag, tnapi->last_irq_tag, |
| 4608 | tnapi->tx_prod, tnapi->tx_cons, tnapi->tx_pending, |
| 4609 | tnapi->rx_rcb_ptr, |
| 4610 | tnapi->prodring.rx_std_prod_idx, |
| 4611 | tnapi->prodring.rx_std_cons_idx, |
| 4612 | tnapi->prodring.rx_jmb_prod_idx, |
| 4613 | tnapi->prodring.rx_jmb_cons_idx); |
| 4614 | } |
| 4615 | } |
| 4616 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4617 | /* This is called whenever we suspect that the system chipset is re- |
| 4618 | * ordering the sequence of MMIO to the tx send mailbox. The symptom |
| 4619 | * is bogus tx completions. We try to recover by setting the |
| 4620 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later |
| 4621 | * in the workqueue. |
| 4622 | */ |
| 4623 | static void tg3_tx_recover(struct tg3 *tp) |
| 4624 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4625 | BUG_ON(tg3_flag(tp, MBOX_WRITE_REORDER) || |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4626 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
| 4627 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 4628 | netdev_warn(tp->dev, |
| 4629 | "The system may be re-ordering memory-mapped I/O " |
| 4630 | "cycles to the network device, attempting to recover. " |
| 4631 | "Please report the problem to the driver maintainer " |
| 4632 | "and include system chipset information.\n"); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4633 | |
| 4634 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4635 | tg3_flag_set(tp, TX_RECOVERY_PENDING); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4636 | spin_unlock(&tp->lock); |
| 4637 | } |
| 4638 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4639 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4640 | { |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 4641 | /* Tell compiler to fetch tx indices from memory. */ |
| 4642 | barrier(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4643 | return tnapi->tx_pending - |
| 4644 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4645 | } |
| 4646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | /* Tigon3 never reports partial packet sends. So we do not |
| 4648 | * need special logic to handle SKBs that have not had all |
| 4649 | * of their frags sent yet, like SunGEM does. |
| 4650 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4651 | static void tg3_tx(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4653 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 4654 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4655 | u32 sw_idx = tnapi->tx_cons; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4656 | struct netdev_queue *txq; |
| 4657 | int index = tnapi - tp->napi; |
| 4658 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4659 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4660 | index--; |
| 4661 | |
| 4662 | txq = netdev_get_tx_queue(tp->dev, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | |
| 4664 | while (sw_idx != hw_idx) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4665 | struct ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | struct sk_buff *skb = ri->skb; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4667 | int i, tx_bug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4669 | if (unlikely(skb == NULL)) { |
| 4670 | tg3_tx_recover(tp); |
| 4671 | return; |
| 4672 | } |
| 4673 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4674 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4675 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4676 | skb_headlen(skb), |
| 4677 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | |
| 4679 | ri->skb = NULL; |
| 4680 | |
| 4681 | sw_idx = NEXT_TX(sw_idx); |
| 4682 | |
| 4683 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4684 | ri = &tnapi->tx_buffers[sw_idx]; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4685 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
| 4686 | tx_bug = 1; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4687 | |
| 4688 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4689 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4690 | skb_shinfo(skb)->frags[i].size, |
| 4691 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4692 | sw_idx = NEXT_TX(sw_idx); |
| 4693 | } |
| 4694 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 4695 | dev_kfree_skb(skb); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4696 | |
| 4697 | if (unlikely(tx_bug)) { |
| 4698 | tg3_tx_recover(tp); |
| 4699 | return; |
| 4700 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | } |
| 4702 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4703 | tnapi->tx_cons = sw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4705 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
| 4706 | * before checking for netif_queue_stopped(). Without the |
| 4707 | * memory barrier, there is a small possibility that tg3_start_xmit() |
| 4708 | * will miss it and cause the queue to be stopped forever. |
| 4709 | */ |
| 4710 | smp_mb(); |
| 4711 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4712 | if (unlikely(netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4713 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4714 | __netif_tx_lock(txq, smp_processor_id()); |
| 4715 | if (netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4716 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4717 | netif_tx_wake_queue(txq); |
| 4718 | __netif_tx_unlock(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 4719 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | } |
| 4721 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 4722 | static void tg3_rx_skb_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
| 4723 | { |
| 4724 | if (!ri->skb) |
| 4725 | return; |
| 4726 | |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4727 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 4728 | map_sz, PCI_DMA_FROMDEVICE); |
| 4729 | dev_kfree_skb_any(ri->skb); |
| 4730 | ri->skb = NULL; |
| 4731 | } |
| 4732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | /* Returns size of skb allocated or < 0 on error. |
| 4734 | * |
| 4735 | * We only need to fill in the address because the other members |
| 4736 | * of the RX descriptor are invariant, see tg3_init_rings. |
| 4737 | * |
| 4738 | * Note the purposeful assymetry of cpu vs. chip accesses. For |
| 4739 | * posting buffers we only dirty the first cache line of the RX |
| 4740 | * descriptor (containing the address). Whereas for the RX status |
| 4741 | * buffers the cpu only reads the last cacheline of the RX descriptor |
| 4742 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). |
| 4743 | */ |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 4744 | static int tg3_alloc_rx_skb(struct tg3 *tp, struct tg3_rx_prodring_set *tpr, |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4745 | u32 opaque_key, u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4746 | { |
| 4747 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | f94e290 | 2010-10-14 10:37:42 +0000 | [diff] [blame] | 4748 | struct ring_info *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | struct sk_buff *skb; |
| 4750 | dma_addr_t mapping; |
| 4751 | int skb_size, dest_idx; |
| 4752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | switch (opaque_key) { |
| 4754 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4755 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4756 | desc = &tpr->rx_std[dest_idx]; |
| 4757 | map = &tpr->rx_std_buffers[dest_idx]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4758 | skb_size = tp->rx_pkt_map_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4759 | break; |
| 4760 | |
| 4761 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4762 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 4763 | desc = &tpr->rx_jmb[dest_idx].std; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4764 | map = &tpr->rx_jmb_buffers[dest_idx]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4765 | skb_size = TG3_RX_JMB_MAP_SZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | break; |
| 4767 | |
| 4768 | default: |
| 4769 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | |
| 4772 | /* Do not overwrite any of the map or rp information |
| 4773 | * until we are sure we can commit to a new buffer. |
| 4774 | * |
| 4775 | * Callers depend upon this behavior and assume that |
| 4776 | * we leave everything unchanged if we fail. |
| 4777 | */ |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4778 | skb = netdev_alloc_skb(tp->dev, skb_size + tp->rx_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | if (skb == NULL) |
| 4780 | return -ENOMEM; |
| 4781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | skb_reserve(skb, tp->rx_offset); |
| 4783 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4784 | mapping = pci_map_single(tp->pdev, skb->data, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | PCI_DMA_FROMDEVICE); |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 4786 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
| 4787 | dev_kfree_skb(skb); |
| 4788 | return -EIO; |
| 4789 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | |
| 4791 | map->skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4792 | dma_unmap_addr_set(map, mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | desc->addr_hi = ((u64)mapping >> 32); |
| 4795 | desc->addr_lo = ((u64)mapping & 0xffffffff); |
| 4796 | |
| 4797 | return skb_size; |
| 4798 | } |
| 4799 | |
| 4800 | /* We only need to move over in the address because the other |
| 4801 | * members of the RX descriptor are invariant. See notes above |
| 4802 | * tg3_alloc_rx_skb for full details. |
| 4803 | */ |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4804 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
| 4805 | struct tg3_rx_prodring_set *dpr, |
| 4806 | u32 opaque_key, int src_idx, |
| 4807 | u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4809 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
| 4811 | struct ring_info *src_map, *dest_map; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4812 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 4813 | int dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | |
| 4815 | switch (opaque_key) { |
| 4816 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4817 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4818 | dest_desc = &dpr->rx_std[dest_idx]; |
| 4819 | dest_map = &dpr->rx_std_buffers[dest_idx]; |
| 4820 | src_desc = &spr->rx_std[src_idx]; |
| 4821 | src_map = &spr->rx_std_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | break; |
| 4823 | |
| 4824 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4825 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4826 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
| 4827 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; |
| 4828 | src_desc = &spr->rx_jmb[src_idx].std; |
| 4829 | src_map = &spr->rx_jmb_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4830 | break; |
| 4831 | |
| 4832 | default: |
| 4833 | return; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | |
| 4836 | dest_map->skb = src_map->skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4837 | dma_unmap_addr_set(dest_map, mapping, |
| 4838 | dma_unmap_addr(src_map, mapping)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | dest_desc->addr_hi = src_desc->addr_hi; |
| 4840 | dest_desc->addr_lo = src_desc->addr_lo; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4841 | |
| 4842 | /* Ensure that the update to the skb happens after the physical |
| 4843 | * addresses have been transferred to the new BD location. |
| 4844 | */ |
| 4845 | smp_wmb(); |
| 4846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | src_map->skb = NULL; |
| 4848 | } |
| 4849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | /* The RX ring scheme is composed of multiple rings which post fresh |
| 4851 | * buffers to the chip, and one special ring the chip uses to report |
| 4852 | * status back to the host. |
| 4853 | * |
| 4854 | * The special ring reports the status of received packets to the |
| 4855 | * host. The chip does not write into the original descriptor the |
| 4856 | * RX buffer was obtained from. The chip simply takes the original |
| 4857 | * descriptor as provided by the host, updates the status and length |
| 4858 | * field, then writes this into the next status ring entry. |
| 4859 | * |
| 4860 | * Each ring the host uses to post buffers to the chip is described |
| 4861 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, |
| 4862 | * it is first placed into the on-chip ram. When the packet's length |
| 4863 | * is known, it walks down the TG3_BDINFO entries to select the ring. |
| 4864 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO |
| 4865 | * which is within the range of the new packet's length is chosen. |
| 4866 | * |
| 4867 | * The "separate ring for rx status" scheme may sound queer, but it makes |
| 4868 | * sense from a cache coherency perspective. If only the host writes |
| 4869 | * to the buffer post rings, and only the chip writes to the rx status |
| 4870 | * rings, then cache lines never move beyond shared-modified state. |
| 4871 | * If both the host and chip were to write into the same ring, cache line |
| 4872 | * eviction could occur since both entities want it in an exclusive state. |
| 4873 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4874 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4876 | struct tg3 *tp = tnapi->tp; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4877 | u32 work_mask, rx_std_posted = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4878 | u32 std_prod_idx, jmb_prod_idx; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4879 | u32 sw_idx = tnapi->rx_rcb_ptr; |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 4880 | u16 hw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | int received; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4882 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4883 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 4884 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | /* |
| 4886 | * We need to order the read of hw_idx and the read of |
| 4887 | * the opaque cookie. |
| 4888 | */ |
| 4889 | rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | work_mask = 0; |
| 4891 | received = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4892 | std_prod_idx = tpr->rx_std_prod_idx; |
| 4893 | jmb_prod_idx = tpr->rx_jmb_prod_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | while (sw_idx != hw_idx && budget > 0) { |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 4895 | struct ring_info *ri; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4896 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | unsigned int len; |
| 4898 | struct sk_buff *skb; |
| 4899 | dma_addr_t dma_addr; |
| 4900 | u32 opaque_key, desc_idx, *post_ptr; |
| 4901 | |
| 4902 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 4903 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 4904 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4905 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4906 | dma_addr = dma_unmap_addr(ri, mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4907 | skb = ri->skb; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4908 | post_ptr = &std_prod_idx; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4909 | rx_std_posted++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4910 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4911 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4912 | dma_addr = dma_unmap_addr(ri, mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4913 | skb = ri->skb; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4914 | post_ptr = &jmb_prod_idx; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4915 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | goto next_pkt_nopost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | |
| 4918 | work_mask |= opaque_key; |
| 4919 | |
| 4920 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 4921 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { |
| 4922 | drop_it: |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4923 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | desc_idx, *post_ptr); |
| 4925 | drop_it_no_recycle: |
| 4926 | /* Other statistics kept track of by card. */ |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 4927 | tp->rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | goto next_pkt; |
| 4929 | } |
| 4930 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 4931 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
| 4932 | ETH_FCS_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4933 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 4934 | if (len > TG3_RX_COPY_THRESH(tp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4935 | int skb_size; |
| 4936 | |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 4937 | skb_size = tg3_alloc_rx_skb(tp, tpr, opaque_key, |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 4938 | *post_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | if (skb_size < 0) |
| 4940 | goto drop_it; |
| 4941 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4942 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | PCI_DMA_FROMDEVICE); |
| 4944 | |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 4945 | /* Ensure that the update to the skb happens |
| 4946 | * after the usage of the old DMA mapping. |
| 4947 | */ |
| 4948 | smp_wmb(); |
| 4949 | |
| 4950 | ri->skb = NULL; |
| 4951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | skb_put(skb, len); |
| 4953 | } else { |
| 4954 | struct sk_buff *copy_skb; |
| 4955 | |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4956 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | desc_idx, *post_ptr); |
| 4958 | |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 4959 | copy_skb = netdev_alloc_skb(tp->dev, len + |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4960 | TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | if (copy_skb == NULL) |
| 4962 | goto drop_it_no_recycle; |
| 4963 | |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 4964 | skb_reserve(copy_skb, TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4965 | skb_put(copy_skb, len); |
| 4966 | pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 4967 | skb_copy_from_linear_data(skb, copy_skb->data, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4968 | pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
| 4969 | |
| 4970 | /* We'll reuse the original ring buffer. */ |
| 4971 | skb = copy_skb; |
| 4972 | } |
| 4973 | |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 4974 | if ((tp->dev->features & NETIF_F_RXCSUM) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 4976 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 4977 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) |
| 4978 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 4979 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 4980 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | |
| 4982 | skb->protocol = eth_type_trans(skb, tp->dev); |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 4983 | |
| 4984 | if (len > (tp->dev->mtu + ETH_HLEN) && |
| 4985 | skb->protocol != htons(ETH_P_8021Q)) { |
| 4986 | dev_kfree_skb(skb); |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 4987 | goto drop_it_no_recycle; |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 4988 | } |
| 4989 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4990 | if (desc->type_flags & RXD_FLAG_VLAN && |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 4991 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
| 4992 | __vlan_hwaccel_put_tag(skb, |
| 4993 | desc->err_vlan & RXD_VLAN_MASK); |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4994 | |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 4995 | napi_gro_receive(&tnapi->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4997 | received++; |
| 4998 | budget--; |
| 4999 | |
| 5000 | next_pkt: |
| 5001 | (*post_ptr)++; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5002 | |
| 5003 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5004 | tpr->rx_std_prod_idx = std_prod_idx & |
| 5005 | tp->rx_std_ring_mask; |
Matt Carlson | 86cfe4f | 2010-01-12 10:11:37 +0000 | [diff] [blame] | 5006 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 5007 | tpr->rx_std_prod_idx); |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5008 | work_mask &= ~RXD_OPAQUE_RING_STD; |
| 5009 | rx_std_posted = 0; |
| 5010 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | next_pkt_nopost: |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 5012 | sw_idx++; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 5013 | sw_idx &= tp->rx_ret_ring_mask; |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 5014 | |
| 5015 | /* Refresh hw_idx to see if there is new work */ |
| 5016 | if (sw_idx == hw_idx) { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 5017 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 5018 | rmb(); |
| 5019 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | /* ACK the status ring. */ |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5023 | tnapi->rx_rcb_ptr = sw_idx; |
| 5024 | tw32_rx_mbox(tnapi->consmbox, sw_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | |
| 5026 | /* Refill RX ring(s). */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5027 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5028 | if (work_mask & RXD_OPAQUE_RING_STD) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5029 | tpr->rx_std_prod_idx = std_prod_idx & |
| 5030 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5031 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 5032 | tpr->rx_std_prod_idx); |
| 5033 | } |
| 5034 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5035 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
| 5036 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5037 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 5038 | tpr->rx_jmb_prod_idx); |
| 5039 | } |
| 5040 | mmiowb(); |
| 5041 | } else if (work_mask) { |
| 5042 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be |
| 5043 | * updated before the producer indices can be updated. |
| 5044 | */ |
| 5045 | smp_wmb(); |
| 5046 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5047 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
| 5048 | 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] | 5049 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5050 | if (tnapi != &tp->napi[1]) |
| 5051 | napi_schedule(&tp->napi[1].napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | |
| 5054 | return received; |
| 5055 | } |
| 5056 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5057 | static void tg3_poll_link(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5059 | /* handle link change and other phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5060 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5061 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
| 5062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5063 | if (sblk->status & SD_STATUS_LINK_CHG) { |
| 5064 | sblk->status = SD_STATUS_UPDATED | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5065 | (sblk->status & ~SD_STATUS_LINK_CHG); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5066 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5067 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 5068 | tw32_f(MAC_STATUS, |
| 5069 | (MAC_STATUS_SYNC_CHANGED | |
| 5070 | MAC_STATUS_CFG_CHANGED | |
| 5071 | MAC_STATUS_MI_COMPLETION | |
| 5072 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 5073 | udelay(40); |
| 5074 | } else |
| 5075 | tg3_setup_phy(tp, 0); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5076 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | } |
| 5078 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5079 | } |
| 5080 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5081 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
| 5082 | struct tg3_rx_prodring_set *dpr, |
| 5083 | struct tg3_rx_prodring_set *spr) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5084 | { |
| 5085 | u32 si, di, cpycnt, src_prod_idx; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5086 | int i, err = 0; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5087 | |
| 5088 | while (1) { |
| 5089 | src_prod_idx = spr->rx_std_prod_idx; |
| 5090 | |
| 5091 | /* Make sure updates to the rx_std_buffers[] entries and the |
| 5092 | * standard producer index are seen in the correct order. |
| 5093 | */ |
| 5094 | smp_rmb(); |
| 5095 | |
| 5096 | if (spr->rx_std_cons_idx == src_prod_idx) |
| 5097 | break; |
| 5098 | |
| 5099 | if (spr->rx_std_cons_idx < src_prod_idx) |
| 5100 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; |
| 5101 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5102 | cpycnt = tp->rx_std_ring_mask + 1 - |
| 5103 | spr->rx_std_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5104 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5105 | cpycnt = min(cpycnt, |
| 5106 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5107 | |
| 5108 | si = spr->rx_std_cons_idx; |
| 5109 | di = dpr->rx_std_prod_idx; |
| 5110 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5111 | for (i = di; i < di + cpycnt; i++) { |
| 5112 | if (dpr->rx_std_buffers[i].skb) { |
| 5113 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5114 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5115 | break; |
| 5116 | } |
| 5117 | } |
| 5118 | |
| 5119 | if (!cpycnt) |
| 5120 | break; |
| 5121 | |
| 5122 | /* Ensure that updates to the rx_std_buffers ring and the |
| 5123 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 5124 | * ordered correctly WRT the skb check above. |
| 5125 | */ |
| 5126 | smp_rmb(); |
| 5127 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5128 | memcpy(&dpr->rx_std_buffers[di], |
| 5129 | &spr->rx_std_buffers[si], |
| 5130 | cpycnt * sizeof(struct ring_info)); |
| 5131 | |
| 5132 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 5133 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 5134 | sbd = &spr->rx_std[si]; |
| 5135 | dbd = &dpr->rx_std[di]; |
| 5136 | dbd->addr_hi = sbd->addr_hi; |
| 5137 | dbd->addr_lo = sbd->addr_lo; |
| 5138 | } |
| 5139 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5140 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
| 5141 | tp->rx_std_ring_mask; |
| 5142 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & |
| 5143 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | while (1) { |
| 5147 | src_prod_idx = spr->rx_jmb_prod_idx; |
| 5148 | |
| 5149 | /* Make sure updates to the rx_jmb_buffers[] entries and |
| 5150 | * the jumbo producer index are seen in the correct order. |
| 5151 | */ |
| 5152 | smp_rmb(); |
| 5153 | |
| 5154 | if (spr->rx_jmb_cons_idx == src_prod_idx) |
| 5155 | break; |
| 5156 | |
| 5157 | if (spr->rx_jmb_cons_idx < src_prod_idx) |
| 5158 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; |
| 5159 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5160 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
| 5161 | spr->rx_jmb_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5162 | |
| 5163 | cpycnt = min(cpycnt, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5164 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5165 | |
| 5166 | si = spr->rx_jmb_cons_idx; |
| 5167 | di = dpr->rx_jmb_prod_idx; |
| 5168 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5169 | for (i = di; i < di + cpycnt; i++) { |
| 5170 | if (dpr->rx_jmb_buffers[i].skb) { |
| 5171 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5172 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5173 | break; |
| 5174 | } |
| 5175 | } |
| 5176 | |
| 5177 | if (!cpycnt) |
| 5178 | break; |
| 5179 | |
| 5180 | /* Ensure that updates to the rx_jmb_buffers ring and the |
| 5181 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 5182 | * ordered correctly WRT the skb check above. |
| 5183 | */ |
| 5184 | smp_rmb(); |
| 5185 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5186 | memcpy(&dpr->rx_jmb_buffers[di], |
| 5187 | &spr->rx_jmb_buffers[si], |
| 5188 | cpycnt * sizeof(struct ring_info)); |
| 5189 | |
| 5190 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 5191 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 5192 | sbd = &spr->rx_jmb[si].std; |
| 5193 | dbd = &dpr->rx_jmb[di].std; |
| 5194 | dbd->addr_hi = sbd->addr_hi; |
| 5195 | dbd->addr_lo = sbd->addr_lo; |
| 5196 | } |
| 5197 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5198 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
| 5199 | tp->rx_jmb_ring_mask; |
| 5200 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & |
| 5201 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5202 | } |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5203 | |
| 5204 | return err; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5205 | } |
| 5206 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5207 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
| 5208 | { |
| 5209 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | |
| 5211 | /* run TX completion thread */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5212 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5213 | tg3_tx(tnapi); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5214 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5215 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5216 | } |
| 5217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5218 | /* run RX thread, within the bounds set by NAPI. |
| 5219 | * All RX "locking" is done by ensuring outside |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5220 | * code synchronizes with tg3->napi.poll() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5221 | */ |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 5222 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5223 | work_done += tg3_rx(tnapi, budget - work_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5224 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5225 | if (tg3_flag(tp, ENABLE_RSS) && tnapi == &tp->napi[1]) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5226 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5227 | int i, err = 0; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5228 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
| 5229 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5230 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5231 | for (i = 1; i < tp->irq_cnt; i++) |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5232 | err |= tg3_rx_prodring_xfer(tp, dpr, |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5233 | &tp->napi[i].prodring); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5234 | |
| 5235 | wmb(); |
| 5236 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5237 | if (std_prod_idx != dpr->rx_std_prod_idx) |
| 5238 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 5239 | dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5240 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5241 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
| 5242 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 5243 | dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5244 | |
| 5245 | mmiowb(); |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5246 | |
| 5247 | if (err) |
| 5248 | tw32_f(HOSTCC_MODE, tp->coal_now); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5249 | } |
| 5250 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5251 | return work_done; |
| 5252 | } |
David S. Miller | f7383c2 | 2005-05-18 22:50:53 -0700 | [diff] [blame] | 5253 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5254 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
| 5255 | { |
| 5256 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 5257 | struct tg3 *tp = tnapi->tp; |
| 5258 | int work_done = 0; |
| 5259 | struct tg3_hw_status *sblk = tnapi->hw_status; |
| 5260 | |
| 5261 | while (1) { |
| 5262 | work_done = tg3_poll_work(tnapi, work_done, budget); |
| 5263 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5264 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5265 | goto tx_recovery; |
| 5266 | |
| 5267 | if (unlikely(work_done >= budget)) |
| 5268 | break; |
| 5269 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5270 | /* tp->last_tag is used in tg3_int_reenable() below |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5271 | * to tell the hw how much work has been processed, |
| 5272 | * so we must read it before checking for more work. |
| 5273 | */ |
| 5274 | tnapi->last_tag = sblk->status_tag; |
| 5275 | tnapi->last_irq_tag = tnapi->last_tag; |
| 5276 | rmb(); |
| 5277 | |
| 5278 | /* check for RX/TX work to do */ |
Matt Carlson | 6d40db7 | 2010-04-05 10:19:20 +0000 | [diff] [blame] | 5279 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
| 5280 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5281 | napi_complete(napi); |
| 5282 | /* Reenable interrupts. */ |
| 5283 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
| 5284 | mmiowb(); |
| 5285 | break; |
| 5286 | } |
| 5287 | } |
| 5288 | |
| 5289 | return work_done; |
| 5290 | |
| 5291 | tx_recovery: |
| 5292 | /* work_done is guaranteed to be less than budget. */ |
| 5293 | napi_complete(napi); |
| 5294 | schedule_work(&tp->reset_task); |
| 5295 | return work_done; |
| 5296 | } |
| 5297 | |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 5298 | static void tg3_process_error(struct tg3 *tp) |
| 5299 | { |
| 5300 | u32 val; |
| 5301 | bool real_error = false; |
| 5302 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5303 | if (tg3_flag(tp, ERROR_PROCESSED)) |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 5304 | return; |
| 5305 | |
| 5306 | /* Check Flow Attention register */ |
| 5307 | val = tr32(HOSTCC_FLOW_ATTN); |
| 5308 | if (val & ~HOSTCC_FLOW_ATTN_MBUF_LWM) { |
| 5309 | netdev_err(tp->dev, "FLOW Attention error. Resetting chip.\n"); |
| 5310 | real_error = true; |
| 5311 | } |
| 5312 | |
| 5313 | if (tr32(MSGINT_STATUS) & ~MSGINT_STATUS_MSI_REQ) { |
| 5314 | netdev_err(tp->dev, "MSI Status error. Resetting chip.\n"); |
| 5315 | real_error = true; |
| 5316 | } |
| 5317 | |
| 5318 | if (tr32(RDMAC_STATUS) || tr32(WDMAC_STATUS)) { |
| 5319 | netdev_err(tp->dev, "DMA Status error. Resetting chip.\n"); |
| 5320 | real_error = true; |
| 5321 | } |
| 5322 | |
| 5323 | if (!real_error) |
| 5324 | return; |
| 5325 | |
| 5326 | tg3_dump_state(tp); |
| 5327 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5328 | tg3_flag_set(tp, ERROR_PROCESSED); |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 5329 | schedule_work(&tp->reset_task); |
| 5330 | } |
| 5331 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5332 | static int tg3_poll(struct napi_struct *napi, int budget) |
| 5333 | { |
Matt Carlson | 8ef0442 | 2009-08-28 14:01:37 +0000 | [diff] [blame] | 5334 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 5335 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5336 | int work_done = 0; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5337 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5338 | |
| 5339 | while (1) { |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 5340 | if (sblk->status & SD_STATUS_ERROR) |
| 5341 | tg3_process_error(tp); |
| 5342 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5343 | tg3_poll_link(tp); |
| 5344 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5345 | work_done = tg3_poll_work(tnapi, work_done, budget); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5346 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5347 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5348 | goto tx_recovery; |
| 5349 | |
| 5350 | if (unlikely(work_done >= budget)) |
| 5351 | break; |
| 5352 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5353 | if (tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5354 | /* tp->last_tag is used in tg3_int_reenable() below |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5355 | * to tell the hw how much work has been processed, |
| 5356 | * so we must read it before checking for more work. |
| 5357 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5358 | tnapi->last_tag = sblk->status_tag; |
| 5359 | tnapi->last_irq_tag = tnapi->last_tag; |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5360 | rmb(); |
| 5361 | } else |
| 5362 | sblk->status &= ~SD_STATUS_UPDATED; |
| 5363 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5364 | if (likely(!tg3_has_work(tnapi))) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5365 | napi_complete(napi); |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5366 | tg3_int_reenable(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5367 | break; |
| 5368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5369 | } |
| 5370 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5371 | return work_done; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5372 | |
| 5373 | tx_recovery: |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5374 | /* work_done is guaranteed to be less than budget. */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5375 | napi_complete(napi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5376 | schedule_work(&tp->reset_task); |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5377 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5378 | } |
| 5379 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 5380 | static void tg3_napi_disable(struct tg3 *tp) |
| 5381 | { |
| 5382 | int i; |
| 5383 | |
| 5384 | for (i = tp->irq_cnt - 1; i >= 0; i--) |
| 5385 | napi_disable(&tp->napi[i].napi); |
| 5386 | } |
| 5387 | |
| 5388 | static void tg3_napi_enable(struct tg3 *tp) |
| 5389 | { |
| 5390 | int i; |
| 5391 | |
| 5392 | for (i = 0; i < tp->irq_cnt; i++) |
| 5393 | napi_enable(&tp->napi[i].napi); |
| 5394 | } |
| 5395 | |
| 5396 | static void tg3_napi_init(struct tg3 *tp) |
| 5397 | { |
| 5398 | int i; |
| 5399 | |
| 5400 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); |
| 5401 | for (i = 1; i < tp->irq_cnt; i++) |
| 5402 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); |
| 5403 | } |
| 5404 | |
| 5405 | static void tg3_napi_fini(struct tg3 *tp) |
| 5406 | { |
| 5407 | int i; |
| 5408 | |
| 5409 | for (i = 0; i < tp->irq_cnt; i++) |
| 5410 | netif_napi_del(&tp->napi[i].napi); |
| 5411 | } |
| 5412 | |
| 5413 | static inline void tg3_netif_stop(struct tg3 *tp) |
| 5414 | { |
| 5415 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 5416 | tg3_napi_disable(tp); |
| 5417 | netif_tx_disable(tp->dev); |
| 5418 | } |
| 5419 | |
| 5420 | static inline void tg3_netif_start(struct tg3 *tp) |
| 5421 | { |
| 5422 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
| 5423 | * appropriate so long as all callers are assured to |
| 5424 | * have free tx slots (such as after tg3_init_hw) |
| 5425 | */ |
| 5426 | netif_tx_wake_all_queues(tp->dev); |
| 5427 | |
| 5428 | tg3_napi_enable(tp); |
| 5429 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; |
| 5430 | tg3_enable_ints(tp); |
| 5431 | } |
| 5432 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5433 | static void tg3_irq_quiesce(struct tg3 *tp) |
| 5434 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5435 | int i; |
| 5436 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5437 | BUG_ON(tp->irq_sync); |
| 5438 | |
| 5439 | tp->irq_sync = 1; |
| 5440 | smp_mb(); |
| 5441 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5442 | for (i = 0; i < tp->irq_cnt; i++) |
| 5443 | synchronize_irq(tp->napi[i].irq_vec); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5444 | } |
| 5445 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5446 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
| 5447 | * If irq_sync is non-zero, then the IRQ handler must be synchronized |
| 5448 | * with as well. Most of the time, this is not necessary except when |
| 5449 | * shutting down the device. |
| 5450 | */ |
| 5451 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) |
| 5452 | { |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 5453 | spin_lock_bh(&tp->lock); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5454 | if (irq_sync) |
| 5455 | tg3_irq_quiesce(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
| 5458 | static inline void tg3_full_unlock(struct tg3 *tp) |
| 5459 | { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5460 | spin_unlock_bh(&tp->lock); |
| 5461 | } |
| 5462 | |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5463 | /* One-shot MSI handler - Chip automatically disables interrupt |
| 5464 | * after sending MSI so driver doesn't have to do it. |
| 5465 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5466 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5467 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5468 | struct tg3_napi *tnapi = dev_id; |
| 5469 | struct tg3 *tp = tnapi->tp; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5470 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5471 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 5472 | if (tnapi->rx_rcb) |
| 5473 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5474 | |
| 5475 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5476 | napi_schedule(&tnapi->napi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5477 | |
| 5478 | return IRQ_HANDLED; |
| 5479 | } |
| 5480 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5481 | /* MSI ISR - No need to check for interrupt sharing and no need to |
| 5482 | * flush status block and interrupt mailbox. PCI ordering rules |
| 5483 | * guarantee that MSI will arrive after the status block. |
| 5484 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5485 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5486 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5487 | struct tg3_napi *tnapi = dev_id; |
| 5488 | struct tg3 *tp = tnapi->tp; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5489 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5490 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 5491 | if (tnapi->rx_rcb) |
| 5492 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5493 | /* |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5494 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5495 | * chip-internal interrupt pending events. |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5496 | * Writing non-zero to intr-mbox-0 additional tells the |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5497 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5498 | * event coalescing. |
| 5499 | */ |
| 5500 | tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 5501 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5502 | napi_schedule(&tnapi->napi); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 5503 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5504 | return IRQ_RETVAL(1); |
| 5505 | } |
| 5506 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5507 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5508 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5509 | struct tg3_napi *tnapi = dev_id; |
| 5510 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5511 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | unsigned int handled = 1; |
| 5513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 5515 | * the CPU before the status block posted prior to the interrupt. |
| 5516 | * Reading the PCI State register will confirm whether the |
| 5517 | * interrupt is ours and will flush the status block. |
| 5518 | */ |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5519 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5520 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5521 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 5522 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5523 | goto out; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5524 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | /* |
| 5528 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
| 5529 | * chip-internal interrupt pending events. |
| 5530 | * Writing non-zero to intr-mbox-0 additional tells the |
| 5531 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5532 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5533 | * |
| 5534 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 5535 | * spurious interrupts. The flush impacts performance but |
| 5536 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5537 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5538 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5539 | if (tg3_irq_sync(tp)) |
| 5540 | goto out; |
| 5541 | sblk->status &= ~SD_STATUS_UPDATED; |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5542 | if (likely(tg3_has_work(tnapi))) { |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5543 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5544 | napi_schedule(&tnapi->napi); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5545 | } else { |
| 5546 | /* No work, shared interrupt perhaps? re-enable |
| 5547 | * interrupts, and flush that PCI write |
| 5548 | */ |
| 5549 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, |
| 5550 | 0x00000000); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5551 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5552 | out: |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5553 | return IRQ_RETVAL(handled); |
| 5554 | } |
| 5555 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5556 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5557 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5558 | struct tg3_napi *tnapi = dev_id; |
| 5559 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5560 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5561 | unsigned int handled = 1; |
| 5562 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5563 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 5564 | * the CPU before the status block posted prior to the interrupt. |
| 5565 | * Reading the PCI State register will confirm whether the |
| 5566 | * interrupt is ours and will flush the status block. |
| 5567 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5568 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5569 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5570 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 5571 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5572 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | /* |
| 5577 | * writing any value to intr-mbox-0 clears PCI INTA# and |
| 5578 | * chip-internal interrupt pending events. |
| 5579 | * writing non-zero to intr-mbox-0 additional tells the |
| 5580 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5581 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5582 | * |
| 5583 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 5584 | * spurious interrupts. The flush impacts performance but |
| 5585 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5586 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5587 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5588 | |
| 5589 | /* |
| 5590 | * In a shared interrupt configuration, sometimes other devices' |
| 5591 | * interrupts will scream. We record the current status tag here |
| 5592 | * so that the above check can report that the screaming interrupts |
| 5593 | * are unhandled. Eventually they will be silenced. |
| 5594 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5595 | tnapi->last_irq_tag = sblk->status_tag; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5596 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5597 | if (tg3_irq_sync(tp)) |
| 5598 | goto out; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5599 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5600 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5601 | |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5602 | napi_schedule(&tnapi->napi); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5603 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5604 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | return IRQ_RETVAL(handled); |
| 5606 | } |
| 5607 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5608 | /* ISR for interrupt test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5609 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5610 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5611 | struct tg3_napi *tnapi = dev_id; |
| 5612 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5613 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5614 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 5615 | if ((sblk->status & SD_STATUS_UPDATED) || |
| 5616 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 5617 | tg3_disable_ints(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5618 | return IRQ_RETVAL(1); |
| 5619 | } |
| 5620 | return IRQ_RETVAL(0); |
| 5621 | } |
| 5622 | |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 5623 | static int tg3_init_hw(struct tg3 *, int); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 5624 | static int tg3_halt(struct tg3 *, int, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5625 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5626 | /* Restart hardware after configuration changes, self-test, etc. |
| 5627 | * Invoked with tp->lock held. |
| 5628 | */ |
| 5629 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) |
Eric Dumazet | 78c6146 | 2008-04-24 23:33:06 -0700 | [diff] [blame] | 5630 | __releases(tp->lock) |
| 5631 | __acquires(tp->lock) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5632 | { |
| 5633 | int err; |
| 5634 | |
| 5635 | err = tg3_init_hw(tp, reset_phy); |
| 5636 | if (err) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5637 | netdev_err(tp->dev, |
| 5638 | "Failed to re-initialize device, aborting\n"); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5639 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 5640 | tg3_full_unlock(tp); |
| 5641 | del_timer_sync(&tp->timer); |
| 5642 | tp->irq_sync = 0; |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 5643 | tg3_napi_enable(tp); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5644 | dev_close(tp->dev); |
| 5645 | tg3_full_lock(tp, 0); |
| 5646 | } |
| 5647 | return err; |
| 5648 | } |
| 5649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5650 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5651 | static void tg3_poll_controller(struct net_device *dev) |
| 5652 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5653 | int i; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5654 | struct tg3 *tp = netdev_priv(dev); |
| 5655 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5656 | for (i = 0; i < tp->irq_cnt; i++) |
Louis Rilling | fe234f0 | 2010-03-09 06:14:41 +0000 | [diff] [blame] | 5657 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5658 | } |
| 5659 | #endif |
| 5660 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5661 | static void tg3_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5662 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5663 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5664 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5665 | unsigned int restart_timer; |
| 5666 | |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5667 | tg3_full_lock(tp, 0); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5668 | |
| 5669 | if (!netif_running(tp->dev)) { |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5670 | tg3_full_unlock(tp); |
| 5671 | return; |
| 5672 | } |
| 5673 | |
| 5674 | tg3_full_unlock(tp); |
| 5675 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5676 | tg3_phy_stop(tp); |
| 5677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5678 | tg3_netif_stop(tp); |
| 5679 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5680 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5681 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5682 | restart_timer = tg3_flag(tp, RESTART_TIMER); |
| 5683 | tg3_flag_clear(tp, RESTART_TIMER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5685 | if (tg3_flag(tp, TX_RECOVERY_PENDING)) { |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5686 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 5687 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5688 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
| 5689 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5690 | } |
| 5691 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 5692 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5693 | err = tg3_init_hw(tp, 1); |
| 5694 | if (err) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5695 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5696 | |
| 5697 | tg3_netif_start(tp); |
| 5698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5699 | if (restart_timer) |
| 5700 | mod_timer(&tp->timer, jiffies + 1); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5701 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5702 | out: |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5703 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5704 | |
| 5705 | if (!err) |
| 5706 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5707 | } |
| 5708 | |
| 5709 | static void tg3_tx_timeout(struct net_device *dev) |
| 5710 | { |
| 5711 | struct tg3 *tp = netdev_priv(dev); |
| 5712 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5713 | if (netif_msg_tx_err(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 5714 | netdev_err(dev, "transmit timed out, resetting\n"); |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5715 | tg3_dump_state(tp); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5716 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | |
| 5718 | schedule_work(&tp->reset_task); |
| 5719 | } |
| 5720 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5721 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
| 5722 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) |
| 5723 | { |
| 5724 | u32 base = (u32) mapping & 0xffffffff; |
| 5725 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 5726 | return (base > 0xffffdcc0) && (base + len + 8 < base); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5727 | } |
| 5728 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5729 | /* Test for DMA addresses > 40-bit */ |
| 5730 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 5731 | int len) |
| 5732 | { |
| 5733 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5734 | if (tg3_flag(tp, 40BIT_DMA_BUG)) |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 5735 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5736 | return 0; |
| 5737 | #else |
| 5738 | return 0; |
| 5739 | #endif |
| 5740 | } |
| 5741 | |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 5742 | static void tg3_set_txd(struct tg3_napi *tnapi, int entry, |
| 5743 | dma_addr_t mapping, int len, u32 flags, |
| 5744 | u32 mss_and_is_end) |
| 5745 | { |
| 5746 | struct tg3_tx_buffer_desc *txd = &tnapi->tx_ring[entry]; |
| 5747 | int is_end = (mss_and_is_end & 0x1); |
| 5748 | u32 mss = (mss_and_is_end >> 1); |
| 5749 | u32 vlan_tag = 0; |
| 5750 | |
| 5751 | if (is_end) |
| 5752 | flags |= TXD_FLAG_END; |
| 5753 | if (flags & TXD_FLAG_VLAN) { |
| 5754 | vlan_tag = flags >> 16; |
| 5755 | flags &= 0xffff; |
| 5756 | } |
| 5757 | vlan_tag |= (mss << TXD_MSS_SHIFT); |
| 5758 | |
| 5759 | txd->addr_hi = ((u64) mapping >> 32); |
| 5760 | txd->addr_lo = ((u64) mapping & 0xffffffff); |
| 5761 | txd->len_flags = (len << TXD_LEN_SHIFT) | flags; |
| 5762 | txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT; |
| 5763 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 5765 | static void tg3_skb_error_unmap(struct tg3_napi *tnapi, |
| 5766 | struct sk_buff *skb, int last) |
| 5767 | { |
| 5768 | int i; |
| 5769 | u32 entry = tnapi->tx_prod; |
| 5770 | struct ring_info *txb = &tnapi->tx_buffers[entry]; |
| 5771 | |
| 5772 | pci_unmap_single(tnapi->tp->pdev, |
| 5773 | dma_unmap_addr(txb, mapping), |
| 5774 | skb_headlen(skb), |
| 5775 | PCI_DMA_TODEVICE); |
| 5776 | for (i = 0; i <= last; i++) { |
| 5777 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 5778 | |
| 5779 | entry = NEXT_TX(entry); |
| 5780 | txb = &tnapi->tx_buffers[entry]; |
| 5781 | |
| 5782 | pci_unmap_page(tnapi->tp->pdev, |
| 5783 | dma_unmap_addr(txb, mapping), |
| 5784 | frag->size, PCI_DMA_TODEVICE); |
| 5785 | } |
| 5786 | } |
| 5787 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5788 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5789 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 5790 | struct sk_buff *skb, |
| 5791 | u32 base_flags, u32 mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5792 | { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5793 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 5794 | struct sk_buff *new_skb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5795 | dma_addr_t new_addr = 0; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 5796 | u32 entry = tnapi->tx_prod; |
| 5797 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5798 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 5799 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 5800 | new_skb = skb_copy(skb, GFP_ATOMIC); |
| 5801 | else { |
| 5802 | int more_headroom = 4 - ((unsigned long)skb->data & 3); |
| 5803 | |
| 5804 | new_skb = skb_copy_expand(skb, |
| 5805 | skb_headroom(skb) + more_headroom, |
| 5806 | skb_tailroom(skb), GFP_ATOMIC); |
| 5807 | } |
| 5808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5809 | if (!new_skb) { |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5810 | ret = -1; |
| 5811 | } else { |
| 5812 | /* New SKB is guaranteed to be linear. */ |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5813 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
| 5814 | PCI_DMA_TODEVICE); |
| 5815 | /* Make sure the mapping succeeded */ |
| 5816 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { |
| 5817 | ret = -1; |
| 5818 | dev_kfree_skb(new_skb); |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5819 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5820 | /* Make sure new skb does not cross any 4G boundaries. |
| 5821 | * Drop the packet if it does. |
| 5822 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5823 | } else if (tg3_flag(tp, 4G_DMA_BNDRY_BUG) && |
| 5824 | tg3_4g_overflow_test(new_addr, new_skb->len)) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5825 | pci_unmap_single(tp->pdev, new_addr, new_skb->len, |
| 5826 | PCI_DMA_TODEVICE); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5827 | ret = -1; |
| 5828 | dev_kfree_skb(new_skb); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5829 | } else { |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 5830 | tnapi->tx_buffers[entry].skb = new_skb; |
| 5831 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], |
| 5832 | mapping, new_addr); |
| 5833 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5834 | tg3_set_txd(tnapi, entry, new_addr, new_skb->len, |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5835 | base_flags, 1 | (mss << 1)); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5836 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5837 | } |
| 5838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5839 | dev_kfree_skb(skb); |
| 5840 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5841 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | } |
| 5843 | |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 5844 | 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] | 5845 | |
| 5846 | /* Use GSO to workaround a rare TSO bug that may be triggered when the |
| 5847 | * TSO header is greater than 80 bytes. |
| 5848 | */ |
| 5849 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) |
| 5850 | { |
| 5851 | struct sk_buff *segs, *nskb; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5852 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5853 | |
| 5854 | /* Estimate the number of fragments in the worst case */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5855 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5856 | netif_stop_queue(tp->dev); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 5857 | |
| 5858 | /* netif_tx_stop_queue() must be done before checking |
| 5859 | * checking tx index in tg3_tx_avail() below, because in |
| 5860 | * tg3_tx(), we update tx index before checking for |
| 5861 | * netif_tx_queue_stopped(). |
| 5862 | */ |
| 5863 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5864 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 5865 | return NETDEV_TX_BUSY; |
| 5866 | |
| 5867 | netif_wake_queue(tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
| 5870 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame] | 5871 | if (IS_ERR(segs)) |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5872 | goto tg3_tso_bug_end; |
| 5873 | |
| 5874 | do { |
| 5875 | nskb = segs; |
| 5876 | segs = segs->next; |
| 5877 | nskb->next = NULL; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 5878 | tg3_start_xmit(nskb, tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5879 | } while (segs); |
| 5880 | |
| 5881 | tg3_tso_bug_end: |
| 5882 | dev_kfree_skb(skb); |
| 5883 | |
| 5884 | return NETDEV_TX_OK; |
| 5885 | } |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5886 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5887 | /* 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] | 5888 | * support TG3_FLAG_HW_TSO_1 or firmware TSO only. |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5889 | */ |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 5890 | 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] | 5891 | { |
| 5892 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5893 | u32 len, entry, base_flags, mss; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 5894 | int i = -1, would_hit_hwbug; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5895 | dma_addr_t mapping; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5896 | struct tg3_napi *tnapi; |
| 5897 | struct netdev_queue *txq; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 5898 | unsigned int last; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5899 | |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5900 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 5901 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5902 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5903 | tnapi++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5904 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 5905 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5906 | * 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] | 5907 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 5908 | * no IRQ context deadlocks to worry about either. Rejoice! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5909 | */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5910 | if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5911 | if (!netif_tx_queue_stopped(txq)) { |
| 5912 | netif_tx_stop_queue(txq); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 5913 | |
| 5914 | /* This is a hard error, log it. */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5915 | netdev_err(dev, |
| 5916 | "BUG! Tx Ring full when queue awake!\n"); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 5917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5918 | return NETDEV_TX_BUSY; |
| 5919 | } |
| 5920 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5921 | entry = tnapi->tx_prod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5922 | base_flags = 0; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 5923 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5924 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5925 | |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 5926 | mss = skb_shinfo(skb)->gso_size; |
| 5927 | if (mss) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5928 | struct iphdr *iph; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 5929 | u32 tcp_opt_len, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5930 | |
| 5931 | if (skb_header_cloned(skb) && |
| 5932 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { |
| 5933 | dev_kfree_skb(skb); |
| 5934 | goto out_unlock; |
| 5935 | } |
| 5936 | |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 5937 | iph = ip_hdr(skb); |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 5938 | tcp_opt_len = tcp_optlen(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | |
Matt Carlson | 02e9608 | 2010-09-15 08:59:59 +0000 | [diff] [blame] | 5940 | if (skb_is_gso_v6(skb)) { |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 5941 | hdr_len = skb_headlen(skb) - ETH_HLEN; |
| 5942 | } else { |
| 5943 | u32 ip_tcp_len; |
| 5944 | |
| 5945 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); |
| 5946 | hdr_len = ip_tcp_len + tcp_opt_len; |
| 5947 | |
| 5948 | iph->check = 0; |
| 5949 | iph->tot_len = htons(mss + hdr_len); |
| 5950 | } |
| 5951 | |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5952 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5953 | tg3_flag(tp, TSO_BUG)) |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 5954 | return tg3_tso_bug(tp, skb); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5956 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 5957 | TXD_FLAG_CPU_POST_DMA); |
| 5958 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5959 | if (tg3_flag(tp, HW_TSO_1) || |
| 5960 | tg3_flag(tp, HW_TSO_2) || |
| 5961 | tg3_flag(tp, HW_TSO_3)) { |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5962 | tcp_hdr(skb)->check = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5963 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5964 | } else |
| 5965 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 5966 | iph->daddr, 0, |
| 5967 | IPPROTO_TCP, |
| 5968 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5969 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5970 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 5971 | mss |= (hdr_len & 0xc) << 12; |
| 5972 | if (hdr_len & 0x10) |
| 5973 | base_flags |= 0x00000010; |
| 5974 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5975 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 5976 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5977 | else if (tg3_flag(tp, HW_TSO_1) || |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 5978 | 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] | 5979 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5980 | int tsflags; |
| 5981 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5982 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5983 | mss |= (tsflags << 11); |
| 5984 | } |
| 5985 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5986 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5987 | int tsflags; |
| 5988 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5989 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5990 | base_flags |= tsflags << 12; |
| 5991 | } |
| 5992 | } |
| 5993 | } |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 5994 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 5995 | if (vlan_tx_tag_present(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5996 | base_flags |= (TXD_FLAG_VLAN | |
| 5997 | (vlan_tx_tag_get(skb) << 16)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5998 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5999 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
Matt Carlson | 8fc2f99 | 2010-12-06 08:28:49 +0000 | [diff] [blame] | 6000 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 6001 | base_flags |= TXD_FLAG_JMB_PKT; |
| 6002 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6003 | len = skb_headlen(skb); |
| 6004 | |
| 6005 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
| 6006 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 6007 | dev_kfree_skb(skb); |
| 6008 | goto out_unlock; |
| 6009 | } |
| 6010 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6011 | tnapi->tx_buffers[entry].skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6012 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | |
| 6014 | would_hit_hwbug = 0; |
| 6015 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6016 | if (tg3_flag(tp, SHORT_DMA_BUG) && len <= 8) |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 6017 | would_hit_hwbug = 1; |
| 6018 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6019 | if (tg3_flag(tp, 4G_DMA_BNDRY_BUG) && |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6020 | tg3_4g_overflow_test(mapping, len)) |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 6021 | would_hit_hwbug = 1; |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6022 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6023 | if (tg3_flag(tp, 40BIT_DMA_LIMIT_BUG) && |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6024 | tg3_40bit_overflow_test(tp, mapping, len)) |
| 6025 | would_hit_hwbug = 1; |
| 6026 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6027 | if (tg3_flag(tp, 5701_DMA_BUG)) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6028 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6029 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6030 | tg3_set_txd(tnapi, entry, mapping, len, base_flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6031 | (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); |
| 6032 | |
| 6033 | entry = NEXT_TX(entry); |
| 6034 | |
| 6035 | /* Now loop through additional data fragments, and queue them. */ |
| 6036 | if (skb_shinfo(skb)->nr_frags > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6037 | last = skb_shinfo(skb)->nr_frags - 1; |
| 6038 | for (i = 0; i <= last; i++) { |
| 6039 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 6040 | |
| 6041 | len = frag->size; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6042 | mapping = pci_map_page(tp->pdev, |
| 6043 | frag->page, |
| 6044 | frag->page_offset, |
| 6045 | len, PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6046 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6047 | tnapi->tx_buffers[entry].skb = NULL; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6048 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6049 | mapping); |
| 6050 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 6051 | goto dma_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6052 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6053 | if (tg3_flag(tp, SHORT_DMA_BUG) && |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 6054 | len <= 8) |
| 6055 | would_hit_hwbug = 1; |
| 6056 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6057 | if (tg3_flag(tp, 4G_DMA_BNDRY_BUG) && |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6058 | tg3_4g_overflow_test(mapping, len)) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6059 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6060 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6061 | if (tg3_flag(tp, 40BIT_DMA_LIMIT_BUG) && |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6062 | tg3_40bit_overflow_test(tp, mapping, len)) |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6063 | would_hit_hwbug = 1; |
| 6064 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6065 | if (tg3_flag(tp, HW_TSO_1) || |
| 6066 | tg3_flag(tp, HW_TSO_2) || |
| 6067 | tg3_flag(tp, HW_TSO_3)) |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6068 | tg3_set_txd(tnapi, entry, mapping, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6069 | base_flags, (i == last)|(mss << 1)); |
| 6070 | else |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6071 | tg3_set_txd(tnapi, entry, mapping, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6072 | base_flags, (i == last)); |
| 6073 | |
| 6074 | entry = NEXT_TX(entry); |
| 6075 | } |
| 6076 | } |
| 6077 | |
| 6078 | if (would_hit_hwbug) { |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6079 | tg3_skb_error_unmap(tnapi, skb, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6080 | |
| 6081 | /* If the workaround fails due to memory/mapping |
| 6082 | * failure, silently drop this packet. |
| 6083 | */ |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6084 | if (tigon3_dma_hwbug_workaround(tnapi, skb, base_flags, mss)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6085 | goto out_unlock; |
| 6086 | |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6087 | entry = NEXT_TX(tnapi->tx_prod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6088 | } |
| 6089 | |
| 6090 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6091 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6092 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6093 | tnapi->tx_prod = entry; |
| 6094 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6095 | netif_tx_stop_queue(txq); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 6096 | |
| 6097 | /* netif_tx_stop_queue() must be done before checking |
| 6098 | * checking tx index in tg3_tx_avail() below, because in |
| 6099 | * tg3_tx(), we update tx index before checking for |
| 6100 | * netif_tx_queue_stopped(). |
| 6101 | */ |
| 6102 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6103 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6104 | netif_tx_wake_queue(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 6105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6106 | |
| 6107 | out_unlock: |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 6108 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6109 | |
| 6110 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6111 | |
| 6112 | dma_error: |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6113 | tg3_skb_error_unmap(tnapi, skb, i); |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6114 | dev_kfree_skb(skb); |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6115 | tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6116 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6117 | } |
| 6118 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 6119 | static void tg3_set_loopback(struct net_device *dev, u32 features) |
| 6120 | { |
| 6121 | struct tg3 *tp = netdev_priv(dev); |
| 6122 | |
| 6123 | if (features & NETIF_F_LOOPBACK) { |
| 6124 | if (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK) |
| 6125 | return; |
| 6126 | |
| 6127 | /* |
| 6128 | * Clear MAC_MODE_HALF_DUPLEX or you won't get packets back in |
| 6129 | * loopback mode if Half-Duplex mode was negotiated earlier. |
| 6130 | */ |
| 6131 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 6132 | |
| 6133 | /* Enable internal MAC loopback mode */ |
| 6134 | tp->mac_mode |= MAC_MODE_PORT_INT_LPBACK; |
| 6135 | spin_lock_bh(&tp->lock); |
| 6136 | tw32(MAC_MODE, tp->mac_mode); |
| 6137 | netif_carrier_on(tp->dev); |
| 6138 | spin_unlock_bh(&tp->lock); |
| 6139 | netdev_info(dev, "Internal MAC loopback mode enabled.\n"); |
| 6140 | } else { |
| 6141 | if (!(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
| 6142 | return; |
| 6143 | |
| 6144 | /* Disable internal MAC loopback mode */ |
| 6145 | tp->mac_mode &= ~MAC_MODE_PORT_INT_LPBACK; |
| 6146 | spin_lock_bh(&tp->lock); |
| 6147 | tw32(MAC_MODE, tp->mac_mode); |
| 6148 | /* Force link status check */ |
| 6149 | tg3_setup_phy(tp, 1); |
| 6150 | spin_unlock_bh(&tp->lock); |
| 6151 | netdev_info(dev, "Internal MAC loopback mode disabled.\n"); |
| 6152 | } |
| 6153 | } |
| 6154 | |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 6155 | static u32 tg3_fix_features(struct net_device *dev, u32 features) |
| 6156 | { |
| 6157 | struct tg3 *tp = netdev_priv(dev); |
| 6158 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6159 | if (dev->mtu > ETH_DATA_LEN && tg3_flag(tp, 5780_CLASS)) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 6160 | features &= ~NETIF_F_ALL_TSO; |
| 6161 | |
| 6162 | return features; |
| 6163 | } |
| 6164 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 6165 | static int tg3_set_features(struct net_device *dev, u32 features) |
| 6166 | { |
| 6167 | u32 changed = dev->features ^ features; |
| 6168 | |
| 6169 | if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) |
| 6170 | tg3_set_loopback(dev, features); |
| 6171 | |
| 6172 | return 0; |
| 6173 | } |
| 6174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6175 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
| 6176 | int new_mtu) |
| 6177 | { |
| 6178 | dev->mtu = new_mtu; |
| 6179 | |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6180 | if (new_mtu > ETH_DATA_LEN) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6181 | if (tg3_flag(tp, 5780_CLASS)) { |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 6182 | netdev_update_features(dev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6183 | tg3_flag_clear(tp, TSO_CAPABLE); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 6184 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6185 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 6186 | } |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6187 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6188 | if (tg3_flag(tp, 5780_CLASS)) { |
| 6189 | tg3_flag_set(tp, TSO_CAPABLE); |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 6190 | netdev_update_features(dev); |
| 6191 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6192 | tg3_flag_clear(tp, JUMBO_RING_ENABLE); |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6193 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) |
| 6197 | { |
| 6198 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6199 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6200 | |
| 6201 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) |
| 6202 | return -EINVAL; |
| 6203 | |
| 6204 | if (!netif_running(dev)) { |
| 6205 | /* We'll just catch it later when the |
| 6206 | * device is up'd. |
| 6207 | */ |
| 6208 | tg3_set_mtu(dev, tp, new_mtu); |
| 6209 | return 0; |
| 6210 | } |
| 6211 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 6212 | tg3_phy_stop(tp); |
| 6213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6214 | tg3_netif_stop(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6215 | |
| 6216 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 6218 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6219 | |
| 6220 | tg3_set_mtu(dev, tp, new_mtu); |
| 6221 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6222 | err = tg3_restart_hw(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6223 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6224 | if (!err) |
| 6225 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6226 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6227 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 6229 | if (!err) |
| 6230 | tg3_phy_start(tp); |
| 6231 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6232 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6233 | } |
| 6234 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6235 | static void tg3_rx_prodring_free(struct tg3 *tp, |
| 6236 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6237 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6238 | int i; |
| 6239 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6240 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6241 | 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] | 6242 | i = (i + 1) & tp->rx_std_ring_mask) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6243 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
| 6244 | tp->rx_pkt_map_sz); |
| 6245 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6246 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6247 | for (i = tpr->rx_jmb_cons_idx; |
| 6248 | i != tpr->rx_jmb_prod_idx; |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6249 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6250 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
| 6251 | TG3_RX_JMB_MAP_SZ); |
| 6252 | } |
| 6253 | } |
| 6254 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6255 | return; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6256 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6257 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6258 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6259 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
| 6260 | tp->rx_pkt_map_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6261 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6262 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6263 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6264 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
| 6265 | TG3_RX_JMB_MAP_SZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6266 | } |
| 6267 | } |
| 6268 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 6269 | /* Initialize rx rings for packet processing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6270 | * |
| 6271 | * The chip has been shut down and the driver detached from |
| 6272 | * the networking, so no interrupts or new tx packets will |
| 6273 | * end up in the driver. tp->{tx,}lock are held and thus |
| 6274 | * we may not sleep. |
| 6275 | */ |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6276 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
| 6277 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6278 | { |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6279 | u32 i, rx_pkt_dma_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6280 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6281 | tpr->rx_std_cons_idx = 0; |
| 6282 | tpr->rx_std_prod_idx = 0; |
| 6283 | tpr->rx_jmb_cons_idx = 0; |
| 6284 | tpr->rx_jmb_prod_idx = 0; |
| 6285 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6286 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6287 | memset(&tpr->rx_std_buffers[0], 0, |
| 6288 | TG3_RX_STD_BUFF_RING_SIZE(tp)); |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 6289 | if (tpr->rx_jmb_buffers) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6290 | memset(&tpr->rx_jmb_buffers[0], 0, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6291 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6292 | goto done; |
| 6293 | } |
| 6294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6295 | /* Zero out all descriptors. */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6296 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6297 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6298 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6299 | if (tg3_flag(tp, 5780_CLASS) && |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6300 | tp->dev->mtu > ETH_DATA_LEN) |
| 6301 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; |
| 6302 | 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] | 6303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6304 | /* Initialize invariants of the rings, we only set this |
| 6305 | * stuff once. This works because the card does not |
| 6306 | * write into the rx buffer posting rings. |
| 6307 | */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6308 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | struct tg3_rx_buffer_desc *rxd; |
| 6310 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6311 | rxd = &tpr->rx_std[i]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6312 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6313 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
| 6314 | rxd->opaque = (RXD_OPAQUE_RING_STD | |
| 6315 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 6316 | } |
| 6317 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6318 | /* Now allocate fresh SKBs for each rx ring. */ |
| 6319 | for (i = 0; i < tp->rx_pending; i++) { |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 6320 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_STD, i) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 6321 | netdev_warn(tp->dev, |
| 6322 | "Using a smaller RX standard ring. Only " |
| 6323 | "%d out of %d buffers were allocated " |
| 6324 | "successfully\n", i, tp->rx_pending); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6325 | if (i == 0) |
| 6326 | goto initfail; |
| 6327 | tp->rx_pending = i; |
| 6328 | break; |
| 6329 | } |
| 6330 | } |
| 6331 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6332 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6333 | goto done; |
| 6334 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6335 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6336 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6337 | if (!tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6338 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6339 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6340 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6341 | struct tg3_rx_buffer_desc *rxd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6342 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6343 | rxd = &tpr->rx_jmb[i].std; |
| 6344 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; |
| 6345 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | |
| 6346 | RXD_FLAG_JUMBO; |
| 6347 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | |
| 6348 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 6349 | } |
| 6350 | |
| 6351 | for (i = 0; i < tp->rx_jumbo_pending; i++) { |
| 6352 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_JUMBO, i) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 6353 | netdev_warn(tp->dev, |
| 6354 | "Using a smaller RX jumbo ring. Only %d " |
| 6355 | "out of %d buffers were allocated " |
| 6356 | "successfully\n", i, tp->rx_jumbo_pending); |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6357 | if (i == 0) |
| 6358 | goto initfail; |
| 6359 | tp->rx_jumbo_pending = i; |
| 6360 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6361 | } |
| 6362 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6363 | |
| 6364 | done: |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 6365 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6366 | |
| 6367 | initfail: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6368 | tg3_rx_prodring_free(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6369 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6370 | } |
| 6371 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6372 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
| 6373 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6374 | { |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6375 | kfree(tpr->rx_std_buffers); |
| 6376 | tpr->rx_std_buffers = NULL; |
| 6377 | kfree(tpr->rx_jmb_buffers); |
| 6378 | tpr->rx_jmb_buffers = NULL; |
| 6379 | if (tpr->rx_std) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6380 | dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
| 6381 | tpr->rx_std, tpr->rx_std_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6382 | tpr->rx_std = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6383 | } |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6384 | if (tpr->rx_jmb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6385 | dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
| 6386 | tpr->rx_jmb, tpr->rx_jmb_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6387 | tpr->rx_jmb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6388 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6389 | } |
| 6390 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6391 | static int tg3_rx_prodring_init(struct tg3 *tp, |
| 6392 | struct tg3_rx_prodring_set *tpr) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6393 | { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6394 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
| 6395 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6396 | if (!tpr->rx_std_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6397 | return -ENOMEM; |
| 6398 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6399 | tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
| 6400 | TG3_RX_STD_RING_BYTES(tp), |
| 6401 | &tpr->rx_std_mapping, |
| 6402 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6403 | if (!tpr->rx_std) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6404 | goto err_out; |
| 6405 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6406 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6407 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6408 | GFP_KERNEL); |
| 6409 | if (!tpr->rx_jmb_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6410 | goto err_out; |
| 6411 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6412 | tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
| 6413 | TG3_RX_JMB_RING_BYTES(tp), |
| 6414 | &tpr->rx_jmb_mapping, |
| 6415 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6416 | if (!tpr->rx_jmb) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6417 | goto err_out; |
| 6418 | } |
| 6419 | |
| 6420 | return 0; |
| 6421 | |
| 6422 | err_out: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6423 | tg3_rx_prodring_fini(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6424 | return -ENOMEM; |
| 6425 | } |
| 6426 | |
| 6427 | /* Free up pending packets in all rx/tx rings. |
| 6428 | * |
| 6429 | * The chip has been shut down and the driver detached from |
| 6430 | * the networking, so no interrupts or new tx packets will |
| 6431 | * end up in the driver. tp->{tx,}lock is not held and we are not |
| 6432 | * in an interrupt context and thus may sleep. |
| 6433 | */ |
| 6434 | static void tg3_free_rings(struct tg3 *tp) |
| 6435 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6436 | int i, j; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6437 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6438 | for (j = 0; j < tp->irq_cnt; j++) { |
| 6439 | struct tg3_napi *tnapi = &tp->napi[j]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6440 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6441 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
Matt Carlson | b28f642 | 2010-06-05 17:24:32 +0000 | [diff] [blame] | 6442 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6443 | if (!tnapi->tx_buffers) |
| 6444 | continue; |
| 6445 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6446 | for (i = 0; i < TG3_TX_RING_SIZE; ) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6447 | struct ring_info *txp; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6448 | struct sk_buff *skb; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6449 | unsigned int k; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6450 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6451 | txp = &tnapi->tx_buffers[i]; |
| 6452 | skb = txp->skb; |
| 6453 | |
| 6454 | if (skb == NULL) { |
| 6455 | i++; |
| 6456 | continue; |
| 6457 | } |
| 6458 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6459 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6460 | dma_unmap_addr(txp, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6461 | skb_headlen(skb), |
| 6462 | PCI_DMA_TODEVICE); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6463 | txp->skb = NULL; |
| 6464 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6465 | i++; |
| 6466 | |
| 6467 | for (k = 0; k < skb_shinfo(skb)->nr_frags; k++) { |
| 6468 | txp = &tnapi->tx_buffers[i & (TG3_TX_RING_SIZE - 1)]; |
| 6469 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6470 | dma_unmap_addr(txp, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6471 | skb_shinfo(skb)->frags[k].size, |
| 6472 | PCI_DMA_TODEVICE); |
| 6473 | i++; |
| 6474 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6475 | |
| 6476 | dev_kfree_skb_any(skb); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6477 | } |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6478 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | /* Initialize tx/rx rings for packet processing. |
| 6482 | * |
| 6483 | * The chip has been shut down and the driver detached from |
| 6484 | * the networking, so no interrupts or new tx packets will |
| 6485 | * end up in the driver. tp->{tx,}lock are held and thus |
| 6486 | * we may not sleep. |
| 6487 | */ |
| 6488 | static int tg3_init_rings(struct tg3 *tp) |
| 6489 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6490 | int i; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6491 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6492 | /* Free up all the SKBs. */ |
| 6493 | tg3_free_rings(tp); |
| 6494 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6495 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6496 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6497 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6498 | tnapi->last_tag = 0; |
| 6499 | tnapi->last_irq_tag = 0; |
| 6500 | tnapi->hw_status->status = 0; |
| 6501 | tnapi->hw_status->status_tag = 0; |
| 6502 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 6503 | |
| 6504 | tnapi->tx_prod = 0; |
| 6505 | tnapi->tx_cons = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6506 | if (tnapi->tx_ring) |
| 6507 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6508 | |
| 6509 | tnapi->rx_rcb_ptr = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6510 | if (tnapi->rx_rcb) |
| 6511 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6512 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6513 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6514 | tg3_free_rings(tp); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6515 | return -ENOMEM; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6516 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6517 | } |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6518 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6519 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6520 | } |
| 6521 | |
| 6522 | /* |
| 6523 | * Must not be invoked with interrupt sources disabled and |
| 6524 | * the hardware shutdown down. |
| 6525 | */ |
| 6526 | static void tg3_free_consistent(struct tg3 *tp) |
| 6527 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6528 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6529 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6530 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6531 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 6532 | |
| 6533 | if (tnapi->tx_ring) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6534 | dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6535 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
| 6536 | tnapi->tx_ring = NULL; |
| 6537 | } |
| 6538 | |
| 6539 | kfree(tnapi->tx_buffers); |
| 6540 | tnapi->tx_buffers = NULL; |
| 6541 | |
| 6542 | if (tnapi->rx_rcb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6543 | dma_free_coherent(&tp->pdev->dev, |
| 6544 | TG3_RX_RCB_RING_BYTES(tp), |
| 6545 | tnapi->rx_rcb, |
| 6546 | tnapi->rx_rcb_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6547 | tnapi->rx_rcb = NULL; |
| 6548 | } |
| 6549 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6550 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
| 6551 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6552 | if (tnapi->hw_status) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6553 | dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
| 6554 | tnapi->hw_status, |
| 6555 | tnapi->status_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6556 | tnapi->hw_status = NULL; |
| 6557 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6558 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6560 | if (tp->hw_stats) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6561 | dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
| 6562 | tp->hw_stats, tp->stats_mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6563 | tp->hw_stats = NULL; |
| 6564 | } |
| 6565 | } |
| 6566 | |
| 6567 | /* |
| 6568 | * Must not be invoked with interrupt sources disabled and |
| 6569 | * the hardware shutdown down. Can sleep. |
| 6570 | */ |
| 6571 | static int tg3_alloc_consistent(struct tg3 *tp) |
| 6572 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6573 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6574 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6575 | tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
| 6576 | sizeof(struct tg3_hw_stats), |
| 6577 | &tp->stats_mapping, |
| 6578 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6579 | if (!tp->hw_stats) |
| 6580 | goto err_out; |
| 6581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6582 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 6583 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6584 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6585 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6586 | struct tg3_hw_status *sblk; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6587 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6588 | tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
| 6589 | TG3_HW_STATUS_SIZE, |
| 6590 | &tnapi->status_mapping, |
| 6591 | GFP_KERNEL); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6592 | if (!tnapi->hw_status) |
| 6593 | goto err_out; |
| 6594 | |
| 6595 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6596 | sblk = tnapi->hw_status; |
| 6597 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6598 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
| 6599 | goto err_out; |
| 6600 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 6601 | /* If multivector TSS is enabled, vector 0 does not handle |
| 6602 | * tx interrupts. Don't allocate any resources for it. |
| 6603 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6604 | if ((!i && !tg3_flag(tp, ENABLE_TSS)) || |
| 6605 | (i && tg3_flag(tp, ENABLE_TSS))) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 6606 | tnapi->tx_buffers = kzalloc(sizeof(struct ring_info) * |
| 6607 | TG3_TX_RING_SIZE, |
| 6608 | GFP_KERNEL); |
| 6609 | if (!tnapi->tx_buffers) |
| 6610 | goto err_out; |
| 6611 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6612 | tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, |
| 6613 | TG3_TX_RING_BYTES, |
| 6614 | &tnapi->tx_desc_mapping, |
| 6615 | GFP_KERNEL); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 6616 | if (!tnapi->tx_ring) |
| 6617 | goto err_out; |
| 6618 | } |
| 6619 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6620 | /* |
| 6621 | * When RSS is enabled, the status block format changes |
| 6622 | * slightly. The "rx_jumbo_consumer", "reserved", |
| 6623 | * and "rx_mini_consumer" members get mapped to the |
| 6624 | * other three rx return ring producer indexes. |
| 6625 | */ |
| 6626 | switch (i) { |
| 6627 | default: |
| 6628 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
| 6629 | break; |
| 6630 | case 2: |
| 6631 | tnapi->rx_rcb_prod_idx = &sblk->rx_jumbo_consumer; |
| 6632 | break; |
| 6633 | case 3: |
| 6634 | tnapi->rx_rcb_prod_idx = &sblk->reserved; |
| 6635 | break; |
| 6636 | case 4: |
| 6637 | tnapi->rx_rcb_prod_idx = &sblk->rx_mini_consumer; |
| 6638 | break; |
| 6639 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6640 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6641 | /* |
| 6642 | * If multivector RSS is enabled, vector 0 does not handle |
| 6643 | * rx or tx interrupts. Don't allocate any resources for it. |
| 6644 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6645 | if (!i && tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6646 | continue; |
| 6647 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6648 | tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, |
| 6649 | TG3_RX_RCB_RING_BYTES(tp), |
| 6650 | &tnapi->rx_rcb_mapping, |
| 6651 | GFP_KERNEL); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6652 | if (!tnapi->rx_rcb) |
| 6653 | goto err_out; |
| 6654 | |
| 6655 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6656 | } |
| 6657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6658 | return 0; |
| 6659 | |
| 6660 | err_out: |
| 6661 | tg3_free_consistent(tp); |
| 6662 | return -ENOMEM; |
| 6663 | } |
| 6664 | |
| 6665 | #define MAX_WAIT_CNT 1000 |
| 6666 | |
| 6667 | /* To stop a block, clear the enable bit and poll till it |
| 6668 | * clears. tp->lock is held. |
| 6669 | */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6670 | 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] | 6671 | { |
| 6672 | unsigned int i; |
| 6673 | u32 val; |
| 6674 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6675 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6676 | switch (ofs) { |
| 6677 | case RCVLSC_MODE: |
| 6678 | case DMAC_MODE: |
| 6679 | case MBFREE_MODE: |
| 6680 | case BUFMGR_MODE: |
| 6681 | case MEMARB_MODE: |
| 6682 | /* We can't enable/disable these bits of the |
| 6683 | * 5705/5750, just say success. |
| 6684 | */ |
| 6685 | return 0; |
| 6686 | |
| 6687 | default: |
| 6688 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6689 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6690 | } |
| 6691 | |
| 6692 | val = tr32(ofs); |
| 6693 | val &= ~enable_bit; |
| 6694 | tw32_f(ofs, val); |
| 6695 | |
| 6696 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 6697 | udelay(100); |
| 6698 | val = tr32(ofs); |
| 6699 | if ((val & enable_bit) == 0) |
| 6700 | break; |
| 6701 | } |
| 6702 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6703 | if (i == MAX_WAIT_CNT && !silent) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 6704 | dev_err(&tp->pdev->dev, |
| 6705 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", |
| 6706 | ofs, enable_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6707 | return -ENODEV; |
| 6708 | } |
| 6709 | |
| 6710 | return 0; |
| 6711 | } |
| 6712 | |
| 6713 | /* tp->lock is held. */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6714 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6715 | { |
| 6716 | int i, err; |
| 6717 | |
| 6718 | tg3_disable_ints(tp); |
| 6719 | |
| 6720 | tp->rx_mode &= ~RX_MODE_ENABLE; |
| 6721 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 6722 | udelay(10); |
| 6723 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6724 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
| 6725 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); |
| 6726 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); |
| 6727 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); |
| 6728 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); |
| 6729 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6730 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6731 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); |
| 6732 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); |
| 6733 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); |
| 6734 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); |
| 6735 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); |
| 6736 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); |
| 6737 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6738 | |
| 6739 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 6740 | tw32_f(MAC_MODE, tp->mac_mode); |
| 6741 | udelay(40); |
| 6742 | |
| 6743 | tp->tx_mode &= ~TX_MODE_ENABLE; |
| 6744 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 6745 | |
| 6746 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 6747 | udelay(100); |
| 6748 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) |
| 6749 | break; |
| 6750 | } |
| 6751 | if (i >= MAX_WAIT_CNT) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 6752 | dev_err(&tp->pdev->dev, |
| 6753 | "%s timed out, TX_MODE_ENABLE will not clear " |
| 6754 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 6755 | err |= -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6756 | } |
| 6757 | |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 6758 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6759 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
| 6760 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6761 | |
| 6762 | tw32(FTQ_RESET, 0xffffffff); |
| 6763 | tw32(FTQ_RESET, 0x00000000); |
| 6764 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6765 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
| 6766 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6767 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6768 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6769 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 6770 | if (tnapi->hw_status) |
| 6771 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 6772 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6773 | if (tp->hw_stats) |
| 6774 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 6775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6776 | return err; |
| 6777 | } |
| 6778 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6779 | static void tg3_ape_send_event(struct tg3 *tp, u32 event) |
| 6780 | { |
| 6781 | int i; |
| 6782 | u32 apedata; |
| 6783 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6784 | /* NCSI does not support APE events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6785 | if (tg3_flag(tp, APE_HAS_NCSI)) |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6786 | return; |
| 6787 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6788 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 6789 | if (apedata != APE_SEG_SIG_MAGIC) |
| 6790 | return; |
| 6791 | |
| 6792 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
Matt Carlson | 731fd79 | 2008-08-15 14:07:51 -0700 | [diff] [blame] | 6793 | if (!(apedata & APE_FW_STATUS_READY)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6794 | return; |
| 6795 | |
| 6796 | /* Wait for up to 1 millisecond for APE to service previous event. */ |
| 6797 | for (i = 0; i < 10; i++) { |
| 6798 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) |
| 6799 | return; |
| 6800 | |
| 6801 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 6802 | |
| 6803 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6804 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
| 6805 | event | APE_EVENT_STATUS_EVENT_PENDING); |
| 6806 | |
| 6807 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 6808 | |
| 6809 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6810 | break; |
| 6811 | |
| 6812 | udelay(100); |
| 6813 | } |
| 6814 | |
| 6815 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6816 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 6817 | } |
| 6818 | |
| 6819 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
| 6820 | { |
| 6821 | u32 event; |
| 6822 | u32 apedata; |
| 6823 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6824 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6825 | return; |
| 6826 | |
| 6827 | switch (kind) { |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6828 | case RESET_KIND_INIT: |
| 6829 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, |
| 6830 | APE_HOST_SEG_SIG_MAGIC); |
| 6831 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, |
| 6832 | APE_HOST_SEG_LEN_MAGIC); |
| 6833 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); |
| 6834 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); |
| 6835 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 6836 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6837 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
| 6838 | APE_HOST_BEHAV_NO_PHYLOCK); |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6839 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, |
| 6840 | TG3_APE_HOST_DRVR_STATE_START); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6841 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6842 | event = APE_EVENT_STATUS_STATE_START; |
| 6843 | break; |
| 6844 | case RESET_KIND_SHUTDOWN: |
| 6845 | /* With the interface we are currently using, |
| 6846 | * APE does not track driver state. Wiping |
| 6847 | * out the HOST SEGMENT SIGNATURE forces |
| 6848 | * the APE to assume OS absent status. |
| 6849 | */ |
| 6850 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); |
Matt Carlson | b2aee15 | 2008-11-03 16:51:11 -0800 | [diff] [blame] | 6851 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6852 | if (device_may_wakeup(&tp->pdev->dev) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6853 | tg3_flag(tp, WOL_ENABLE)) { |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6854 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, |
| 6855 | TG3_APE_HOST_WOL_SPEED_AUTO); |
| 6856 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; |
| 6857 | } else |
| 6858 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; |
| 6859 | |
| 6860 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); |
| 6861 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6862 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
| 6863 | break; |
| 6864 | case RESET_KIND_SUSPEND: |
| 6865 | event = APE_EVENT_STATUS_STATE_SUSPEND; |
| 6866 | break; |
| 6867 | default: |
| 6868 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6869 | } |
| 6870 | |
| 6871 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; |
| 6872 | |
| 6873 | tg3_ape_send_event(tp, event); |
| 6874 | } |
| 6875 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 6876 | /* tp->lock is held. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6877 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) |
| 6878 | { |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 6879 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
| 6880 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6881 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6882 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6883 | switch (kind) { |
| 6884 | case RESET_KIND_INIT: |
| 6885 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6886 | DRV_STATE_START); |
| 6887 | break; |
| 6888 | |
| 6889 | case RESET_KIND_SHUTDOWN: |
| 6890 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6891 | DRV_STATE_UNLOAD); |
| 6892 | break; |
| 6893 | |
| 6894 | case RESET_KIND_SUSPEND: |
| 6895 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6896 | DRV_STATE_SUSPEND); |
| 6897 | break; |
| 6898 | |
| 6899 | default: |
| 6900 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6901 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6902 | } |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6903 | |
| 6904 | if (kind == RESET_KIND_INIT || |
| 6905 | kind == RESET_KIND_SUSPEND) |
| 6906 | tg3_ape_driver_state_change(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6907 | } |
| 6908 | |
| 6909 | /* tp->lock is held. */ |
| 6910 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) |
| 6911 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6912 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6913 | switch (kind) { |
| 6914 | case RESET_KIND_INIT: |
| 6915 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6916 | DRV_STATE_START_DONE); |
| 6917 | break; |
| 6918 | |
| 6919 | case RESET_KIND_SHUTDOWN: |
| 6920 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6921 | DRV_STATE_UNLOAD_DONE); |
| 6922 | break; |
| 6923 | |
| 6924 | default: |
| 6925 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6926 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6927 | } |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6928 | |
| 6929 | if (kind == RESET_KIND_SHUTDOWN) |
| 6930 | tg3_ape_driver_state_change(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6931 | } |
| 6932 | |
| 6933 | /* tp->lock is held. */ |
| 6934 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) |
| 6935 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6936 | if (tg3_flag(tp, ENABLE_ASF)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6937 | switch (kind) { |
| 6938 | case RESET_KIND_INIT: |
| 6939 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6940 | DRV_STATE_START); |
| 6941 | break; |
| 6942 | |
| 6943 | case RESET_KIND_SHUTDOWN: |
| 6944 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6945 | DRV_STATE_UNLOAD); |
| 6946 | break; |
| 6947 | |
| 6948 | case RESET_KIND_SUSPEND: |
| 6949 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6950 | DRV_STATE_SUSPEND); |
| 6951 | break; |
| 6952 | |
| 6953 | default: |
| 6954 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6955 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6956 | } |
| 6957 | } |
| 6958 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6959 | static int tg3_poll_fw(struct tg3 *tp) |
| 6960 | { |
| 6961 | int i; |
| 6962 | u32 val; |
| 6963 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6964 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Gary Zambrano | 0ccead1 | 2006-11-14 16:34:00 -0800 | [diff] [blame] | 6965 | /* Wait up to 20ms for init done. */ |
| 6966 | for (i = 0; i < 200; i++) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6967 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
| 6968 | return 0; |
Gary Zambrano | 0ccead1 | 2006-11-14 16:34:00 -0800 | [diff] [blame] | 6969 | udelay(100); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6970 | } |
| 6971 | return -ENODEV; |
| 6972 | } |
| 6973 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6974 | /* Wait for firmware initialization to complete. */ |
| 6975 | for (i = 0; i < 100000; i++) { |
| 6976 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); |
| 6977 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 6978 | break; |
| 6979 | udelay(10); |
| 6980 | } |
| 6981 | |
| 6982 | /* Chip might not be fitted with firmware. Some Sun onboard |
| 6983 | * parts are configured like that. So don't signal the timeout |
| 6984 | * of the above loop as an error, but do report the lack of |
| 6985 | * running firmware once. |
| 6986 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6987 | if (i >= 100000 && !tg3_flag(tp, NO_FWARE_REPORTED)) { |
| 6988 | tg3_flag_set(tp, NO_FWARE_REPORTED); |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6989 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 6990 | netdev_info(tp->dev, "No firmware running\n"); |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6991 | } |
| 6992 | |
Matt Carlson | 6b10c16 | 2010-02-12 14:47:08 +0000 | [diff] [blame] | 6993 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 6994 | /* The 57765 A0 needs a little more |
| 6995 | * time to do some important work. |
| 6996 | */ |
| 6997 | mdelay(10); |
| 6998 | } |
| 6999 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 7000 | return 0; |
| 7001 | } |
| 7002 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7003 | /* Save PCI command register before chip reset */ |
| 7004 | static void tg3_save_pci_state(struct tg3 *tp) |
| 7005 | { |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 7006 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7007 | } |
| 7008 | |
| 7009 | /* Restore PCI state after chip reset */ |
| 7010 | static void tg3_restore_pci_state(struct tg3 *tp) |
| 7011 | { |
| 7012 | u32 val; |
| 7013 | |
| 7014 | /* Re-enable indirect register accesses. */ |
| 7015 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 7016 | tp->misc_host_ctrl); |
| 7017 | |
| 7018 | /* Set MAX PCI retry to zero. */ |
| 7019 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); |
| 7020 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7021 | tg3_flag(tp, PCIX_MODE)) |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7022 | val |= PCISTATE_RETRY_SAME_DMA; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7023 | /* Allow reads and writes to the APE register and memory space. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7024 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7025 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 7026 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 7027 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7028 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
| 7029 | |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 7030 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7031 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 7032 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7033 | if (tg3_flag(tp, PCI_EXPRESS)) |
Matt Carlson | cf79003 | 2010-11-24 08:31:48 +0000 | [diff] [blame] | 7034 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 7035 | else { |
| 7036 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 7037 | tp->pci_cacheline_sz); |
| 7038 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 7039 | tp->pci_lat_timer); |
| 7040 | } |
Michael Chan | 114342f | 2007-10-15 02:12:26 -0700 | [diff] [blame] | 7041 | } |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 7042 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7043 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7044 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 7045 | u16 pcix_cmd; |
| 7046 | |
| 7047 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 7048 | &pcix_cmd); |
| 7049 | pcix_cmd &= ~PCI_X_CMD_ERO; |
| 7050 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 7051 | pcix_cmd); |
| 7052 | } |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7053 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7054 | if (tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7055 | |
| 7056 | /* Chip reset on 5780 will reset MSI enable bit, |
| 7057 | * so need to restore it. |
| 7058 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7059 | if (tg3_flag(tp, USING_MSI)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7060 | u16 ctrl; |
| 7061 | |
| 7062 | pci_read_config_word(tp->pdev, |
| 7063 | tp->msi_cap + PCI_MSI_FLAGS, |
| 7064 | &ctrl); |
| 7065 | pci_write_config_word(tp->pdev, |
| 7066 | tp->msi_cap + PCI_MSI_FLAGS, |
| 7067 | ctrl | PCI_MSI_FLAGS_ENABLE); |
| 7068 | val = tr32(MSGINT_MODE); |
| 7069 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); |
| 7070 | } |
| 7071 | } |
| 7072 | } |
| 7073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7074 | static void tg3_stop_fw(struct tg3 *); |
| 7075 | |
| 7076 | /* tp->lock is held. */ |
| 7077 | static int tg3_chip_reset(struct tg3 *tp) |
| 7078 | { |
| 7079 | u32 val; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7080 | void (*write_op)(struct tg3 *, u32, u32); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7081 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7082 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 7083 | tg3_nvram_lock(tp); |
| 7084 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 7085 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
| 7086 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 7087 | /* No matching tg3_nvram_unlock() after this because |
| 7088 | * chip reset below will undo the nvram lock. |
| 7089 | */ |
| 7090 | tp->nvram_lock_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7091 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7092 | /* GRC_MISC_CFG core clock reset will clear the memory |
| 7093 | * enable bit in PCI register 4 and the MSI enable bit |
| 7094 | * on some chips, so we save relevant registers here. |
| 7095 | */ |
| 7096 | tg3_save_pci_state(tp); |
| 7097 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 7098 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7099 | tg3_flag(tp, 5755_PLUS)) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 7100 | tw32(GRC_FASTBOOT_PC, 0); |
| 7101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7102 | /* |
| 7103 | * We must avoid the readl() that normally takes place. |
| 7104 | * It locks machines, causes machine checks, and other |
| 7105 | * fun things. So, temporarily disable the 5701 |
| 7106 | * hardware workaround, while we do the reset. |
| 7107 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7108 | write_op = tp->write32; |
| 7109 | if (write_op == tg3_write_flush_reg32) |
| 7110 | tp->write32 = tg3_write32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7111 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7112 | /* Prevent the irq handler from reading or writing PCI registers |
| 7113 | * during chip reset when the memory enable bit in the PCI command |
| 7114 | * register may be cleared. The chip does not generate interrupt |
| 7115 | * at this time, but the irq handler may still be called due to irq |
| 7116 | * sharing or irqpoll. |
| 7117 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7118 | tg3_flag_set(tp, CHIP_RESETTING); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7119 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7120 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7121 | if (tnapi->hw_status) { |
| 7122 | tnapi->hw_status->status = 0; |
| 7123 | tnapi->hw_status->status_tag = 0; |
| 7124 | } |
| 7125 | tnapi->last_tag = 0; |
| 7126 | tnapi->last_irq_tag = 0; |
Michael Chan | b8fa2f3 | 2007-04-06 17:35:37 -0700 | [diff] [blame] | 7127 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7128 | smp_mb(); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7129 | |
| 7130 | for (i = 0; i < tp->irq_cnt; i++) |
| 7131 | synchronize_irq(tp->napi[i].irq_vec); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7132 | |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 7133 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 7134 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 7135 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 7136 | } |
| 7137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7138 | /* do the reset */ |
| 7139 | val = GRC_MISC_CFG_CORECLK_RESET; |
| 7140 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7141 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 7142 | /* Force PCIe 1.0a mode */ |
| 7143 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7144 | !tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 7145 | tr32(TG3_PCIE_PHY_TSTCTL) == |
| 7146 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) |
| 7147 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); |
| 7148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7149 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
| 7150 | tw32(GRC_MISC_CFG, (1 << 29)); |
| 7151 | val |= (1 << 29); |
| 7152 | } |
| 7153 | } |
| 7154 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 7155 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 7156 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
| 7157 | tw32(GRC_VCPU_EXT_CTRL, |
| 7158 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 7159 | } |
| 7160 | |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 7161 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7162 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, CPMU_PRESENT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7163 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 7164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7165 | tw32(GRC_MISC_CFG, val); |
| 7166 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7167 | /* restore 5701 hardware bug workaround write method */ |
| 7168 | tp->write32 = write_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7169 | |
| 7170 | /* Unfortunately, we have to delay before the PCI read back. |
| 7171 | * Some 575X chips even will not respond to a PCI cfg access |
| 7172 | * when the reset command is given to the chip. |
| 7173 | * |
| 7174 | * How do these hardware designers expect things to work |
| 7175 | * properly if the PCI write is posted for a long period |
| 7176 | * of time? It is always necessary to have some method by |
| 7177 | * which a register read back can occur to push the write |
| 7178 | * out which does the reset. |
| 7179 | * |
| 7180 | * For most tg3 variants the trick below was working. |
| 7181 | * Ho hum... |
| 7182 | */ |
| 7183 | udelay(120); |
| 7184 | |
| 7185 | /* Flush PCI posted writes. The normal MMIO registers |
| 7186 | * are inaccessible at this time so this is the only |
| 7187 | * way to make this reliably (actually, this is no longer |
| 7188 | * the case, see above). I tried to use indirect |
| 7189 | * register read/write but this upset some 5701 variants. |
| 7190 | */ |
| 7191 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); |
| 7192 | |
| 7193 | udelay(120); |
| 7194 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7195 | if (tg3_flag(tp, PCI_EXPRESS) && tp->pcie_cap) { |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7196 | u16 val16; |
| 7197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7198 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
| 7199 | int i; |
| 7200 | u32 cfg_val; |
| 7201 | |
| 7202 | /* Wait for link training to complete. */ |
| 7203 | for (i = 0; i < 5000; i++) |
| 7204 | udelay(100); |
| 7205 | |
| 7206 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); |
| 7207 | pci_write_config_dword(tp->pdev, 0xc4, |
| 7208 | cfg_val | (1 << 15)); |
| 7209 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7210 | |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7211 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
| 7212 | pci_read_config_word(tp->pdev, |
| 7213 | tp->pcie_cap + PCI_EXP_DEVCTL, |
| 7214 | &val16); |
| 7215 | val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN | |
| 7216 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 7217 | /* |
| 7218 | * Older PCIe devices only support the 128 byte |
| 7219 | * MPS setting. Enforce the restriction. |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7220 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7221 | if (!tg3_flag(tp, CPMU_PRESENT)) |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7222 | val16 &= ~PCI_EXP_DEVCTL_PAYLOAD; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7223 | pci_write_config_word(tp->pdev, |
| 7224 | tp->pcie_cap + PCI_EXP_DEVCTL, |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7225 | val16); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7226 | |
Matt Carlson | cf79003 | 2010-11-24 08:31:48 +0000 | [diff] [blame] | 7227 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7228 | |
| 7229 | /* Clear error status */ |
| 7230 | pci_write_config_word(tp->pdev, |
| 7231 | tp->pcie_cap + PCI_EXP_DEVSTA, |
| 7232 | PCI_EXP_DEVSTA_CED | |
| 7233 | PCI_EXP_DEVSTA_NFED | |
| 7234 | PCI_EXP_DEVSTA_FED | |
| 7235 | PCI_EXP_DEVSTA_URD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7236 | } |
| 7237 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7238 | tg3_restore_pci_state(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7239 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7240 | tg3_flag_clear(tp, CHIP_RESETTING); |
| 7241 | tg3_flag_clear(tp, ERROR_PROCESSED); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7242 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7243 | val = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7244 | if (tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 7245 | val = tr32(MEMARB_MODE); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7246 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7247 | |
| 7248 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { |
| 7249 | tg3_stop_fw(tp); |
| 7250 | tw32(0x5000, 0x400); |
| 7251 | } |
| 7252 | |
| 7253 | tw32(GRC_MODE, tp->grc_mode); |
| 7254 | |
| 7255 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 7256 | val = tr32(0xc4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7257 | |
| 7258 | tw32(0xc4, val | (1 << 15)); |
| 7259 | } |
| 7260 | |
| 7261 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && |
| 7262 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 7263 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
| 7264 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) |
| 7265 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
| 7266 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 7267 | } |
| 7268 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7269 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 7270 | tp->mac_mode = MAC_MODE_APE_TX_EN | |
| 7271 | MAC_MODE_APE_RX_EN | |
| 7272 | MAC_MODE_TDE_ENABLE; |
| 7273 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 7274 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 7275 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 7276 | val = tp->mac_mode; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 7277 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 7278 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7279 | val = tp->mac_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7280 | } else |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 7281 | val = 0; |
| 7282 | |
| 7283 | tw32_f(MAC_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7284 | udelay(40); |
| 7285 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 7286 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
| 7287 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 7288 | err = tg3_poll_fw(tp); |
| 7289 | if (err) |
| 7290 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7291 | |
Matt Carlson | 0a9140c | 2009-08-28 12:27:50 +0000 | [diff] [blame] | 7292 | tg3_mdio_start(tp); |
| 7293 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7294 | if (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 7295 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 7296 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7297 | !tg3_flag(tp, 57765_PLUS)) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 7298 | val = tr32(0x7c00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7299 | |
| 7300 | tw32(0x7c00, val | (1 << 25)); |
| 7301 | } |
| 7302 | |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 7303 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 7304 | val = tr32(TG3_CPMU_CLCK_ORIDE); |
| 7305 | tw32(TG3_CPMU_CLCK_ORIDE, val & ~CPMU_CLCK_ORIDE_MAC_ORIDE_EN); |
| 7306 | } |
| 7307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7308 | /* Reprobe ASF enable state. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7309 | tg3_flag_clear(tp, ENABLE_ASF); |
| 7310 | tg3_flag_clear(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7311 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 7312 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 7313 | u32 nic_cfg; |
| 7314 | |
| 7315 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 7316 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7317 | tg3_flag_set(tp, ENABLE_ASF); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 7318 | tp->last_event_jiffies = jiffies; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7319 | if (tg3_flag(tp, 5750_PLUS)) |
| 7320 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7321 | } |
| 7322 | } |
| 7323 | |
| 7324 | return 0; |
| 7325 | } |
| 7326 | |
| 7327 | /* tp->lock is held. */ |
| 7328 | static void tg3_stop_fw(struct tg3 *tp) |
| 7329 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7330 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 7331 | /* Wait for RX cpu to ACK the previous event. */ |
| 7332 | tg3_wait_for_event_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7333 | |
| 7334 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 7335 | |
| 7336 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7337 | |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 7338 | /* Wait for RX cpu to ACK this event. */ |
| 7339 | tg3_wait_for_event_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | /* tp->lock is held. */ |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7344 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7345 | { |
| 7346 | int err; |
| 7347 | |
| 7348 | tg3_stop_fw(tp); |
| 7349 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7350 | tg3_write_sig_pre_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7351 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7352 | tg3_abort_hw(tp, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7353 | err = tg3_chip_reset(tp); |
| 7354 | |
Matt Carlson | daba2a6 | 2009-04-20 06:58:52 +0000 | [diff] [blame] | 7355 | __tg3_set_mac_addr(tp, 0); |
| 7356 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7357 | tg3_write_sig_legacy(tp, kind); |
| 7358 | tg3_write_sig_post_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7359 | |
| 7360 | if (err) |
| 7361 | return err; |
| 7362 | |
| 7363 | return 0; |
| 7364 | } |
| 7365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7366 | #define RX_CPU_SCRATCH_BASE 0x30000 |
| 7367 | #define RX_CPU_SCRATCH_SIZE 0x04000 |
| 7368 | #define TX_CPU_SCRATCH_BASE 0x34000 |
| 7369 | #define TX_CPU_SCRATCH_SIZE 0x04000 |
| 7370 | |
| 7371 | /* tp->lock is held. */ |
| 7372 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) |
| 7373 | { |
| 7374 | int i; |
| 7375 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7376 | BUG_ON(offset == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7377 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 7378 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 7379 | u32 val = tr32(GRC_VCPU_EXT_CTRL); |
| 7380 | |
| 7381 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 7382 | return 0; |
| 7383 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7384 | if (offset == RX_CPU_BASE) { |
| 7385 | for (i = 0; i < 10000; i++) { |
| 7386 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7387 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 7388 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 7389 | break; |
| 7390 | } |
| 7391 | |
| 7392 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7393 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); |
| 7394 | udelay(10); |
| 7395 | } else { |
| 7396 | for (i = 0; i < 10000; i++) { |
| 7397 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7398 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 7399 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 7400 | break; |
| 7401 | } |
| 7402 | } |
| 7403 | |
| 7404 | if (i >= 10000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7405 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
| 7406 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7407 | return -ENODEV; |
| 7408 | } |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7409 | |
| 7410 | /* Clear firmware's nvram arbitration. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7411 | if (tg3_flag(tp, NVRAM)) |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7412 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7413 | return 0; |
| 7414 | } |
| 7415 | |
| 7416 | struct fw_info { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7417 | unsigned int fw_base; |
| 7418 | unsigned int fw_len; |
| 7419 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7420 | }; |
| 7421 | |
| 7422 | /* tp->lock is held. */ |
| 7423 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base, |
| 7424 | int cpu_scratch_size, struct fw_info *info) |
| 7425 | { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7426 | int err, lock_err, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7427 | void (*write_op)(struct tg3 *, u32, u32); |
| 7428 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7429 | if (cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7430 | netdev_err(tp->dev, |
| 7431 | "%s: Trying to load TX cpu firmware which is 5705\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7432 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7433 | return -EINVAL; |
| 7434 | } |
| 7435 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7436 | if (tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7437 | write_op = tg3_write_mem; |
| 7438 | else |
| 7439 | write_op = tg3_write_indirect_reg32; |
| 7440 | |
Michael Chan | 1b62815 | 2005-05-29 14:59:49 -0700 | [diff] [blame] | 7441 | /* It is possible that bootcode is still loading at this point. |
| 7442 | * Get the nvram lock first before halting the cpu. |
| 7443 | */ |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7444 | lock_err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7445 | err = tg3_halt_cpu(tp, cpu_base); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7446 | if (!lock_err) |
| 7447 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7448 | if (err) |
| 7449 | goto out; |
| 7450 | |
| 7451 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
| 7452 | write_op(tp, cpu_scratch_base + i, 0); |
| 7453 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7454 | tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7455 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7456 | write_op(tp, (cpu_scratch_base + |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7457 | (info->fw_base & 0xffff) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7458 | (i * sizeof(u32))), |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7459 | be32_to_cpu(info->fw_data[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7460 | |
| 7461 | err = 0; |
| 7462 | |
| 7463 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7464 | return err; |
| 7465 | } |
| 7466 | |
| 7467 | /* tp->lock is held. */ |
| 7468 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) |
| 7469 | { |
| 7470 | struct fw_info info; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7471 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7472 | int err, i; |
| 7473 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7474 | fw_data = (void *)tp->fw->data; |
| 7475 | |
| 7476 | /* Firmware blob starts with version numbers, followed by |
| 7477 | start address and length. We are setting complete length. |
| 7478 | length = end_address_of_bss - start_address_of_text. |
| 7479 | Remainder is the blob to be loaded contiguously |
| 7480 | from start address. */ |
| 7481 | |
| 7482 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 7483 | info.fw_len = tp->fw->size - 12; |
| 7484 | info.fw_data = &fw_data[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7485 | |
| 7486 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
| 7487 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, |
| 7488 | &info); |
| 7489 | if (err) |
| 7490 | return err; |
| 7491 | |
| 7492 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, |
| 7493 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, |
| 7494 | &info); |
| 7495 | if (err) |
| 7496 | return err; |
| 7497 | |
| 7498 | /* Now startup only the RX cpu. */ |
| 7499 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7500 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7501 | |
| 7502 | for (i = 0; i < 5; i++) { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7503 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7504 | break; |
| 7505 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 7506 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7507 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7508 | udelay(1000); |
| 7509 | } |
| 7510 | if (i >= 5) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7511 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
| 7512 | "should be %08x\n", __func__, |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7513 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7514 | return -ENODEV; |
| 7515 | } |
| 7516 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 7517 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); |
| 7518 | |
| 7519 | return 0; |
| 7520 | } |
| 7521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7522 | /* tp->lock is held. */ |
| 7523 | static int tg3_load_tso_firmware(struct tg3 *tp) |
| 7524 | { |
| 7525 | struct fw_info info; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7526 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7527 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
| 7528 | int err, i; |
| 7529 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7530 | if (tg3_flag(tp, HW_TSO_1) || |
| 7531 | tg3_flag(tp, HW_TSO_2) || |
| 7532 | tg3_flag(tp, HW_TSO_3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7533 | return 0; |
| 7534 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7535 | fw_data = (void *)tp->fw->data; |
| 7536 | |
| 7537 | /* Firmware blob starts with version numbers, followed by |
| 7538 | start address and length. We are setting complete length. |
| 7539 | length = end_address_of_bss - start_address_of_text. |
| 7540 | Remainder is the blob to be loaded contiguously |
| 7541 | from start address. */ |
| 7542 | |
| 7543 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 7544 | cpu_scratch_size = tp->fw_len; |
| 7545 | info.fw_len = tp->fw->size - 12; |
| 7546 | info.fw_data = &fw_data[3]; |
| 7547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7548 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7549 | cpu_base = RX_CPU_BASE; |
| 7550 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7551 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7552 | cpu_base = TX_CPU_BASE; |
| 7553 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; |
| 7554 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; |
| 7555 | } |
| 7556 | |
| 7557 | err = tg3_load_firmware_cpu(tp, cpu_base, |
| 7558 | cpu_scratch_base, cpu_scratch_size, |
| 7559 | &info); |
| 7560 | if (err) |
| 7561 | return err; |
| 7562 | |
| 7563 | /* Now startup the cpu. */ |
| 7564 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7565 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7566 | |
| 7567 | for (i = 0; i < 5; i++) { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7568 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7569 | break; |
| 7570 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7571 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7572 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7573 | udelay(1000); |
| 7574 | } |
| 7575 | if (i >= 5) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7576 | netdev_err(tp->dev, |
| 7577 | "%s fails to set CPU PC, is %08x should be %08x\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7578 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7579 | return -ENODEV; |
| 7580 | } |
| 7581 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7582 | tw32_f(cpu_base + CPU_MODE, 0x00000000); |
| 7583 | return 0; |
| 7584 | } |
| 7585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7587 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
| 7588 | { |
| 7589 | struct tg3 *tp = netdev_priv(dev); |
| 7590 | struct sockaddr *addr = p; |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7591 | int err = 0, skip_mac_1 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7592 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 7593 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7594 | return -EINVAL; |
| 7595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7596 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 7597 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 7598 | if (!netif_running(dev)) |
| 7599 | return 0; |
| 7600 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7601 | if (tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7602 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7603 | |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7604 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
| 7605 | addr0_low = tr32(MAC_ADDR_0_LOW); |
| 7606 | addr1_high = tr32(MAC_ADDR_1_HIGH); |
| 7607 | addr1_low = tr32(MAC_ADDR_1_LOW); |
| 7608 | |
| 7609 | /* Skip MAC addr 1 if ASF is using it. */ |
| 7610 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && |
| 7611 | !(addr1_high == 0 && addr1_low == 0)) |
| 7612 | skip_mac_1 = 1; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7613 | } |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7614 | spin_lock_bh(&tp->lock); |
| 7615 | __tg3_set_mac_addr(tp, skip_mac_1); |
| 7616 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7617 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 7618 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7619 | } |
| 7620 | |
| 7621 | /* tp->lock is held. */ |
| 7622 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, |
| 7623 | dma_addr_t mapping, u32 maxlen_flags, |
| 7624 | u32 nic_addr) |
| 7625 | { |
| 7626 | tg3_write_mem(tp, |
| 7627 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 7628 | ((u64) mapping >> 32)); |
| 7629 | tg3_write_mem(tp, |
| 7630 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), |
| 7631 | ((u64) mapping & 0xffffffff)); |
| 7632 | tg3_write_mem(tp, |
| 7633 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), |
| 7634 | maxlen_flags); |
| 7635 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7636 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7637 | tg3_write_mem(tp, |
| 7638 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), |
| 7639 | nic_addr); |
| 7640 | } |
| 7641 | |
| 7642 | static void __tg3_set_rx_mode(struct net_device *); |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 7643 | 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] | 7644 | { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7645 | int i; |
| 7646 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7647 | if (!tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7648 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
| 7649 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); |
| 7650 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7651 | } else { |
| 7652 | tw32(HOSTCC_TXCOL_TICKS, 0); |
| 7653 | tw32(HOSTCC_TXMAX_FRAMES, 0); |
| 7654 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7655 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7656 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7657 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7658 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
| 7659 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); |
| 7660 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); |
| 7661 | } else { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7662 | tw32(HOSTCC_RXCOL_TICKS, 0); |
| 7663 | tw32(HOSTCC_RXMAX_FRAMES, 0); |
| 7664 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7665 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7666 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7667 | if (!tg3_flag(tp, 5705_PLUS)) { |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7668 | u32 val = ec->stats_block_coalesce_usecs; |
| 7669 | |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7670 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
| 7671 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); |
| 7672 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7673 | if (!netif_carrier_ok(tp->dev)) |
| 7674 | val = 0; |
| 7675 | |
| 7676 | tw32(HOSTCC_STAT_COAL_TICKS, val); |
| 7677 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7678 | |
| 7679 | for (i = 0; i < tp->irq_cnt - 1; i++) { |
| 7680 | u32 reg; |
| 7681 | |
| 7682 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; |
| 7683 | tw32(reg, ec->rx_coalesce_usecs); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7684 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
| 7685 | tw32(reg, ec->rx_max_coalesced_frames); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7686 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 7687 | tw32(reg, ec->rx_max_coalesced_frames_irq); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7688 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7689 | if (tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7690 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
| 7691 | tw32(reg, ec->tx_coalesce_usecs); |
| 7692 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; |
| 7693 | tw32(reg, ec->tx_max_coalesced_frames); |
| 7694 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 7695 | tw32(reg, ec->tx_max_coalesced_frames_irq); |
| 7696 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7697 | } |
| 7698 | |
| 7699 | for (; i < tp->irq_max - 1; i++) { |
| 7700 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7701 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7702 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7703 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7704 | if (tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7705 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 7706 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 7707 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 7708 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7709 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7710 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7711 | |
| 7712 | /* tp->lock is held. */ |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7713 | static void tg3_rings_reset(struct tg3 *tp) |
| 7714 | { |
| 7715 | int i; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7716 | u32 stblk, txrcb, rxrcb, limit; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7717 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 7718 | |
| 7719 | /* Disable all transmit rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7720 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7721 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7722 | else if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 3d37728 | 2010-10-14 10:37:39 +0000 | [diff] [blame] | 7723 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7724 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 7725 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7726 | else |
| 7727 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 7728 | |
| 7729 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 7730 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) |
| 7731 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 7732 | BDINFO_FLAGS_DISABLED); |
| 7733 | |
| 7734 | |
| 7735 | /* Disable all receive return rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7736 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 7737 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7738 | else if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7739 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7740 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 7741 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7742 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
| 7743 | else |
| 7744 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 7745 | |
| 7746 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 7747 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) |
| 7748 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 7749 | BDINFO_FLAGS_DISABLED); |
| 7750 | |
| 7751 | /* Disable interrupts */ |
| 7752 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); |
| 7753 | |
| 7754 | /* Zero mailbox registers. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7755 | if (tg3_flag(tp, SUPPORT_MSIX)) { |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 7756 | for (i = 1; i < tp->irq_max; i++) { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7757 | tp->napi[i].tx_prod = 0; |
| 7758 | tp->napi[i].tx_cons = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7759 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 7760 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7761 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
| 7762 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); |
| 7763 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7764 | if (!tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 7765 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7766 | } else { |
| 7767 | tp->napi[0].tx_prod = 0; |
| 7768 | tp->napi[0].tx_cons = 0; |
| 7769 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 7770 | tw32_rx_mbox(tp->napi[0].consmbox, 0); |
| 7771 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7772 | |
| 7773 | /* Make sure the NIC-based send BD rings are disabled. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7774 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7775 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 7776 | for (i = 0; i < 16; i++) |
| 7777 | tw32_tx_mbox(mbox + i * 8, 0); |
| 7778 | } |
| 7779 | |
| 7780 | txrcb = NIC_SRAM_SEND_RCB; |
| 7781 | rxrcb = NIC_SRAM_RCV_RET_RCB; |
| 7782 | |
| 7783 | /* Clear status block in ram. */ |
| 7784 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7785 | |
| 7786 | /* Set status block DMA address */ |
| 7787 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 7788 | ((u64) tnapi->status_mapping >> 32)); |
| 7789 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 7790 | ((u64) tnapi->status_mapping & 0xffffffff)); |
| 7791 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7792 | if (tnapi->tx_ring) { |
| 7793 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 7794 | (TG3_TX_RING_SIZE << |
| 7795 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 7796 | NIC_SRAM_TX_BUFFER_DESC); |
| 7797 | txrcb += TG3_BDINFO_SIZE; |
| 7798 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7799 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7800 | if (tnapi->rx_rcb) { |
| 7801 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 7802 | (tp->rx_ret_ring_mask + 1) << |
| 7803 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7804 | rxrcb += TG3_BDINFO_SIZE; |
| 7805 | } |
| 7806 | |
| 7807 | stblk = HOSTCC_STATBLCK_RING1; |
| 7808 | |
| 7809 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
| 7810 | u64 mapping = (u64)tnapi->status_mapping; |
| 7811 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); |
| 7812 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); |
| 7813 | |
| 7814 | /* Clear status block in ram. */ |
| 7815 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7816 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7817 | if (tnapi->tx_ring) { |
| 7818 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 7819 | (TG3_TX_RING_SIZE << |
| 7820 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 7821 | NIC_SRAM_TX_BUFFER_DESC); |
| 7822 | txrcb += TG3_BDINFO_SIZE; |
| 7823 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7824 | |
| 7825 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 7826 | ((tp->rx_ret_ring_mask + 1) << |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7827 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
| 7828 | |
| 7829 | stblk += 8; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7830 | rxrcb += TG3_BDINFO_SIZE; |
| 7831 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7832 | } |
| 7833 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 7834 | static void tg3_setup_rxbd_thresholds(struct tg3 *tp) |
| 7835 | { |
| 7836 | u32 val, bdcache_maxcnt, host_rep_thresh, nic_rep_thresh; |
| 7837 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7838 | if (!tg3_flag(tp, 5750_PLUS) || |
| 7839 | tg3_flag(tp, 5780_CLASS) || |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 7840 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 7841 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 7842 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5700; |
| 7843 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 7844 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) |
| 7845 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5755; |
| 7846 | else |
| 7847 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5906; |
| 7848 | |
| 7849 | nic_rep_thresh = min(bdcache_maxcnt / 2, tp->rx_std_max_post); |
| 7850 | host_rep_thresh = max_t(u32, tp->rx_pending / 8, 1); |
| 7851 | |
| 7852 | val = min(nic_rep_thresh, host_rep_thresh); |
| 7853 | tw32(RCVBDI_STD_THRESH, val); |
| 7854 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7855 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 7856 | tw32(STD_REPLENISH_LWM, bdcache_maxcnt); |
| 7857 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7858 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 7859 | return; |
| 7860 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7861 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 7862 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5700; |
| 7863 | else |
| 7864 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5717; |
| 7865 | |
| 7866 | host_rep_thresh = max_t(u32, tp->rx_jumbo_pending / 8, 1); |
| 7867 | |
| 7868 | val = min(bdcache_maxcnt / 2, host_rep_thresh); |
| 7869 | tw32(RCVBDI_JUMBO_THRESH, val); |
| 7870 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7871 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 7872 | tw32(JMB_REPLENISH_LWM, bdcache_maxcnt); |
| 7873 | } |
| 7874 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7875 | /* tp->lock is held. */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 7876 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7877 | { |
| 7878 | u32 val, rdmac_mode; |
| 7879 | int i, err, limit; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7880 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7881 | |
| 7882 | tg3_disable_ints(tp); |
| 7883 | |
| 7884 | tg3_stop_fw(tp); |
| 7885 | |
| 7886 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); |
| 7887 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7888 | if (tg3_flag(tp, INIT_COMPLETE)) |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 7889 | tg3_abort_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7890 | |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 7891 | /* Enable MAC control of LPI */ |
| 7892 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { |
| 7893 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, |
| 7894 | TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | |
| 7895 | TG3_CPMU_EEE_LNKIDL_UART_IDL); |
| 7896 | |
| 7897 | tw32_f(TG3_CPMU_EEE_CTRL, |
| 7898 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); |
| 7899 | |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 7900 | val = TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
| 7901 | TG3_CPMU_EEEMD_LPI_IN_TX | |
| 7902 | TG3_CPMU_EEEMD_LPI_IN_RX | |
| 7903 | TG3_CPMU_EEEMD_EEE_ENABLE; |
| 7904 | |
| 7905 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
| 7906 | val |= TG3_CPMU_EEEMD_SND_IDX_DET_EN; |
| 7907 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7908 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 7909 | val |= TG3_CPMU_EEEMD_APE_TX_DET_EN; |
| 7910 | |
| 7911 | tw32_f(TG3_CPMU_EEE_MODE, val); |
| 7912 | |
| 7913 | tw32_f(TG3_CPMU_EEE_DBTMR1, |
| 7914 | TG3_CPMU_DBTMR1_PCIEXIT_2047US | |
| 7915 | TG3_CPMU_DBTMR1_LNKIDLE_2047US); |
| 7916 | |
| 7917 | tw32_f(TG3_CPMU_EEE_DBTMR2, |
Matt Carlson | d7f2ab2 | 2011-01-25 15:58:56 +0000 | [diff] [blame] | 7918 | TG3_CPMU_DBTMR2_APE_TX_2047US | |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 7919 | TG3_CPMU_DBTMR2_TXIDXEQ_2047US); |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 7920 | } |
| 7921 | |
Matt Carlson | 603f117 | 2010-02-12 14:47:10 +0000 | [diff] [blame] | 7922 | if (reset_phy) |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 7923 | tg3_phy_reset(tp); |
| 7924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7925 | err = tg3_chip_reset(tp); |
| 7926 | if (err) |
| 7927 | return err; |
| 7928 | |
| 7929 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); |
| 7930 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 7931 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7932 | val = tr32(TG3_CPMU_CTRL); |
| 7933 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); |
| 7934 | tw32(TG3_CPMU_CTRL, val); |
Matt Carlson | 9acb961 | 2007-11-12 21:10:06 -0800 | [diff] [blame] | 7935 | |
| 7936 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 7937 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 7938 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 7939 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 7940 | |
| 7941 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); |
| 7942 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; |
| 7943 | val |= CPMU_LNK_AWARE_MACCLK_6_25; |
| 7944 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); |
| 7945 | |
| 7946 | val = tr32(TG3_CPMU_HST_ACC); |
| 7947 | val &= ~CPMU_HST_ACC_MACCLK_MASK; |
| 7948 | val |= CPMU_HST_ACC_MACCLK_6_25; |
| 7949 | tw32(TG3_CPMU_HST_ACC, val); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7950 | } |
| 7951 | |
Matt Carlson | 33466d9 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 7952 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 7953 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 7954 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | |
| 7955 | PCIE_PWR_MGMT_L1_THRESH_4MS; |
| 7956 | tw32(PCIE_PWR_MGMT_THRESH, val); |
Matt Carlson | 521e6b9 | 2009-08-25 10:06:01 +0000 | [diff] [blame] | 7957 | |
| 7958 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; |
| 7959 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); |
| 7960 | |
| 7961 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); |
Matt Carlson | 33466d9 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 7962 | |
Matt Carlson | f40386c | 2009-11-02 14:24:02 +0000 | [diff] [blame] | 7963 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 7964 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 7965 | } |
| 7966 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7967 | if (tg3_flag(tp, L1PLLPD_EN)) { |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 7968 | u32 grc_mode = tr32(GRC_MODE); |
| 7969 | |
| 7970 | /* Access the lower 1K of PL PCIE block registers. */ |
| 7971 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 7972 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 7973 | |
| 7974 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); |
| 7975 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, |
| 7976 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); |
| 7977 | |
| 7978 | tw32(GRC_MODE, grc_mode); |
| 7979 | } |
| 7980 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 7981 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
| 7982 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 7983 | u32 grc_mode = tr32(GRC_MODE); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 7984 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 7985 | /* Access the lower 1K of PL PCIE block registers. */ |
| 7986 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 7987 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 7988 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 7989 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 7990 | TG3_PCIE_PL_LO_PHYCTL5); |
| 7991 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, |
| 7992 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 7993 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 7994 | tw32(GRC_MODE, grc_mode); |
| 7995 | } |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 7996 | |
Matt Carlson | 1ff30a5 | 2011-05-19 12:12:46 +0000 | [diff] [blame] | 7997 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_57765_AX) { |
| 7998 | u32 grc_mode = tr32(GRC_MODE); |
| 7999 | |
| 8000 | /* Access the lower 1K of DL PCIE block registers. */ |
| 8001 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 8002 | tw32(GRC_MODE, val | GRC_MODE_PCIE_DL_SEL); |
| 8003 | |
| 8004 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 8005 | TG3_PCIE_DL_LO_FTSMAX); |
| 8006 | val &= ~TG3_PCIE_DL_LO_FTSMAX_MSK; |
| 8007 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_DL_LO_FTSMAX, |
| 8008 | val | TG3_PCIE_DL_LO_FTSMAX_VAL); |
| 8009 | |
| 8010 | tw32(GRC_MODE, grc_mode); |
| 8011 | } |
| 8012 | |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 8013 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 8014 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 8015 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 8016 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8017 | } |
| 8018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8019 | /* This works around an issue with Athlon chipsets on |
| 8020 | * B3 tigon3 silicon. This bit has no effect on any |
| 8021 | * other revision. But do not set this on PCI Express |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 8022 | * 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] | 8023 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8024 | if (!tg3_flag(tp, CPMU_PRESENT)) { |
| 8025 | if (!tg3_flag(tp, PCI_EXPRESS)) |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 8026 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
| 8027 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 8028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8029 | |
| 8030 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8031 | tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8032 | val = tr32(TG3PCI_PCISTATE); |
| 8033 | val |= PCISTATE_RETRY_SAME_DMA; |
| 8034 | tw32(TG3PCI_PCISTATE, val); |
| 8035 | } |
| 8036 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8037 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8038 | /* Allow reads and writes to the |
| 8039 | * APE register and memory space. |
| 8040 | */ |
| 8041 | val = tr32(TG3PCI_PCISTATE); |
| 8042 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 8043 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 8044 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8045 | tw32(TG3PCI_PCISTATE, val); |
| 8046 | } |
| 8047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8048 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
| 8049 | /* Enable some hw fixes. */ |
| 8050 | val = tr32(TG3PCI_MSI_DATA); |
| 8051 | val |= (1 << 26) | (1 << 28) | (1 << 29); |
| 8052 | tw32(TG3PCI_MSI_DATA, val); |
| 8053 | } |
| 8054 | |
| 8055 | /* Descriptor ring init may make accesses to the |
| 8056 | * NIC SRAM area to setup the TX descriptors, so we |
| 8057 | * can only do this after the hardware has been |
| 8058 | * successfully reset. |
| 8059 | */ |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 8060 | err = tg3_init_rings(tp); |
| 8061 | if (err) |
| 8062 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8063 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8064 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 8065 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
| 8066 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
Matt Carlson | 1a31902 | 2010-04-12 06:58:25 +0000 | [diff] [blame] | 8067 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
| 8068 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; |
Matt Carlson | 0aebff4 | 2011-04-25 12:42:45 +0000 | [diff] [blame] | 8069 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57765 && |
| 8070 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
| 8071 | val |= DMA_RWCTRL_TAGGED_STAT_WA; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 8072 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
| 8073 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && |
| 8074 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8075 | /* This value is determined during the probe time DMA |
| 8076 | * engine test, tg3_test_dma. |
| 8077 | */ |
| 8078 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 8079 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8080 | |
| 8081 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | |
| 8082 | GRC_MODE_4X_NIC_SEND_RINGS | |
| 8083 | GRC_MODE_NO_TX_PHDR_CSUM | |
| 8084 | GRC_MODE_NO_RX_PHDR_CSUM); |
| 8085 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; |
Michael Chan | d2d746f | 2006-04-06 21:45:39 -0700 | [diff] [blame] | 8086 | |
| 8087 | /* Pseudo-header checksum is done by hardware logic and not |
| 8088 | * the offload processers, so make the chip do the pseudo- |
| 8089 | * header checksums on receive. For transmit it is more |
| 8090 | * convenient to do the pseudo-header checksum in software |
| 8091 | * as Linux does that on transmit for us in all cases. |
| 8092 | */ |
| 8093 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8094 | |
| 8095 | tw32(GRC_MODE, |
| 8096 | tp->grc_mode | |
| 8097 | (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP)); |
| 8098 | |
| 8099 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ |
| 8100 | val = tr32(GRC_MISC_CFG); |
| 8101 | val &= ~0xff; |
| 8102 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 8103 | tw32(GRC_MISC_CFG, val); |
| 8104 | |
| 8105 | /* Initialize MBUF/DESC pool. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8106 | if (tg3_flag(tp, 5750_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8107 | /* Do nothing. */ |
| 8108 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { |
| 8109 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
| 8110 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 8111 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
| 8112 | else |
| 8113 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); |
| 8114 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); |
| 8115 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8116 | } else if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8117 | int fw_len; |
| 8118 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 8119 | fw_len = tp->fw_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8120 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
| 8121 | tw32(BUFMGR_MB_POOL_ADDR, |
| 8122 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); |
| 8123 | tw32(BUFMGR_MB_POOL_SIZE, |
| 8124 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); |
| 8125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8126 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 8127 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8128 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8129 | tp->bufmgr_config.mbuf_read_dma_low_water); |
| 8130 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 8131 | tp->bufmgr_config.mbuf_mac_rx_low_water); |
| 8132 | tw32(BUFMGR_MB_HIGH_WATER, |
| 8133 | tp->bufmgr_config.mbuf_high_water); |
| 8134 | } else { |
| 8135 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8136 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); |
| 8137 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 8138 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); |
| 8139 | tw32(BUFMGR_MB_HIGH_WATER, |
| 8140 | tp->bufmgr_config.mbuf_high_water_jumbo); |
| 8141 | } |
| 8142 | tw32(BUFMGR_DMA_LOW_WATER, |
| 8143 | tp->bufmgr_config.dma_low_water); |
| 8144 | tw32(BUFMGR_DMA_HIGH_WATER, |
| 8145 | tp->bufmgr_config.dma_high_water); |
| 8146 | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8147 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
| 8148 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 8149 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 8150 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 8151 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 8152 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) |
| 8153 | val |= BUFMGR_MODE_MBLOW_ATTN_ENAB; |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8154 | tw32(BUFMGR_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8155 | for (i = 0; i < 2000; i++) { |
| 8156 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) |
| 8157 | break; |
| 8158 | udelay(10); |
| 8159 | } |
| 8160 | if (i >= 2000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 8161 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8162 | return -ENODEV; |
| 8163 | } |
| 8164 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8165 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) |
| 8166 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 8167 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8168 | tg3_setup_rxbd_thresholds(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8169 | |
| 8170 | /* Initialize TG3_BDINFO's at: |
| 8171 | * RCVDBDI_STD_BD: standard eth size rx ring |
| 8172 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring |
| 8173 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) |
| 8174 | * |
| 8175 | * like so: |
| 8176 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring |
| 8177 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | |
| 8178 | * ring attribute flags |
| 8179 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM |
| 8180 | * |
| 8181 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. |
| 8182 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. |
| 8183 | * |
| 8184 | * The size of each ring is fixed in the firmware, but the location is |
| 8185 | * configurable. |
| 8186 | */ |
| 8187 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8188 | ((u64) tpr->rx_std_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8189 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8190 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8191 | if (!tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 8192 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
| 8193 | NIC_SRAM_RX_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8194 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8195 | /* Disable the mini ring */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8196 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8197 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 8198 | BDINFO_FLAGS_DISABLED); |
| 8199 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8200 | /* Program the jumbo buffer descriptor ring control |
| 8201 | * blocks on those devices that have them. |
| 8202 | */ |
Matt Carlson | bb18bb9 | 2011-03-09 16:58:19 +0000 | [diff] [blame] | 8203 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8204 | (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8205 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8206 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8207 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8208 | ((u64) tpr->rx_jmb_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8209 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8210 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8211 | val = TG3_RX_JMB_RING_SIZE(tp) << |
| 8212 | BDINFO_FLAGS_MAXLEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8213 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8214 | val | BDINFO_FLAGS_USE_EXT_RECV); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8215 | if (!tg3_flag(tp, USE_JUMBO_BDFLAG) || |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 8216 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 8217 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
| 8218 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8219 | } else { |
| 8220 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 8221 | BDINFO_FLAGS_DISABLED); |
| 8222 | } |
| 8223 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8224 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8225 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8226 | val = TG3_RX_STD_MAX_SIZE_5700; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8227 | else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8228 | val = TG3_RX_STD_MAX_SIZE_5717; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8229 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
| 8230 | val |= (TG3_RX_STD_DMA_SZ << 2); |
| 8231 | } else |
Matt Carlson | 04380d40 | 2010-04-12 06:58:29 +0000 | [diff] [blame] | 8232 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8233 | } else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8234 | val = TG3_RX_STD_MAX_SIZE_5700 << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8235 | |
| 8236 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8237 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 8238 | tpr->rx_std_prod_idx = tp->rx_pending; |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 8239 | 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] | 8240 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8241 | tpr->rx_jmb_prod_idx = |
| 8242 | tg3_flag(tp, JUMBO_RING_ENABLE) ? tp->rx_jumbo_pending : 0; |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 8243 | 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] | 8244 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8245 | tg3_rings_reset(tp); |
| 8246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8247 | /* Initialize MAC address and backoff seed. */ |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8248 | __tg3_set_mac_addr(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8249 | |
| 8250 | /* MTU + ethernet header + FCS + optional VLAN tag */ |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 8251 | tw32(MAC_RX_MTU_SIZE, |
| 8252 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8253 | |
| 8254 | /* The slot time is changed by tg3_setup_phy if we |
| 8255 | * run at gigabit with half duplex. |
| 8256 | */ |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 8257 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 8258 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 8259 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT); |
| 8260 | |
| 8261 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 8262 | val |= tr32(MAC_TX_LENGTHS) & |
| 8263 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 8264 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 8265 | |
| 8266 | tw32(MAC_TX_LENGTHS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8267 | |
| 8268 | /* Receive rules. */ |
| 8269 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); |
| 8270 | tw32(RCVLPC_CONFIG, 0x0181); |
| 8271 | |
| 8272 | /* Calculate RDMAC_MODE setting early, we need it to determine |
| 8273 | * the RCVLPC_STATE_ENABLE mask. |
| 8274 | */ |
| 8275 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | |
| 8276 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | |
| 8277 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | |
| 8278 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | |
| 8279 | RDMAC_MODE_LNGREAD_ENAB); |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8280 | |
Matt Carlson | deabaac | 2010-11-24 08:31:50 +0000 | [diff] [blame] | 8281 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
Matt Carlson | 0339e4e | 2010-02-12 14:47:09 +0000 | [diff] [blame] | 8282 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
| 8283 | |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 8284 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8285 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 8286 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8287 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
| 8288 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | |
| 8289 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; |
| 8290 | |
Matt Carlson | c590893 | 2011-03-09 16:58:25 +0000 | [diff] [blame] | 8291 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 8292 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8293 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | c13e371 | 2007-05-05 11:50:04 -0700 | [diff] [blame] | 8294 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8295 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
| 8296 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8297 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8298 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 8299 | } |
| 8300 | } |
| 8301 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8302 | if (tg3_flag(tp, PCI_EXPRESS)) |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8303 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 8304 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8305 | if (tg3_flag(tp, HW_TSO_1) || |
| 8306 | tg3_flag(tp, HW_TSO_2) || |
| 8307 | tg3_flag(tp, HW_TSO_3)) |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 8308 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
| 8309 | |
Matt Carlson | 108a6c1 | 2011-05-19 12:12:47 +0000 | [diff] [blame] | 8310 | if (tg3_flag(tp, 57765_PLUS) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 8311 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 8312 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
| 8313 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8314 | |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 8315 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 8316 | rdmac_mode |= tr32(RDMAC_MODE) & RDMAC_MODE_H2BNC_VLAN_DET; |
| 8317 | |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8318 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 8319 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 8320 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 8321 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8322 | tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8323 | val = tr32(TG3_RDMA_RSRVCTRL_REG); |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 8324 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 8325 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | b4495ed | 2011-01-25 15:58:47 +0000 | [diff] [blame] | 8326 | val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | |
| 8327 | TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | |
| 8328 | TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); |
| 8329 | val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B | |
| 8330 | TG3_RDMA_RSRVCTRL_FIFO_LWM_1_5K | |
| 8331 | TG3_RDMA_RSRVCTRL_FIFO_HWM_1_5K; |
Matt Carlson | b75cc0e | 2010-11-24 08:31:46 +0000 | [diff] [blame] | 8332 | } |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8333 | tw32(TG3_RDMA_RSRVCTRL_REG, |
| 8334 | val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); |
| 8335 | } |
| 8336 | |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 8337 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 8338 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8339 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 8340 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val | |
| 8341 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | |
| 8342 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); |
| 8343 | } |
| 8344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8345 | /* Receive/send statistics. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8346 | if (tg3_flag(tp, 5750_PLUS)) { |
Michael Chan | 1661394 | 2006-06-29 20:15:13 -0700 | [diff] [blame] | 8347 | val = tr32(RCVLPC_STATS_ENABLE); |
| 8348 | val &= ~RCVLPC_STATSENAB_DACK_FIX; |
| 8349 | tw32(RCVLPC_STATS_ENABLE, val); |
| 8350 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8351 | tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8352 | val = tr32(RCVLPC_STATS_ENABLE); |
| 8353 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; |
| 8354 | tw32(RCVLPC_STATS_ENABLE, val); |
| 8355 | } else { |
| 8356 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); |
| 8357 | } |
| 8358 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); |
| 8359 | tw32(SNDDATAI_STATSENAB, 0xffffff); |
| 8360 | tw32(SNDDATAI_STATSCTRL, |
| 8361 | (SNDDATAI_SCTRL_ENABLE | |
| 8362 | SNDDATAI_SCTRL_FASTUPD)); |
| 8363 | |
| 8364 | /* Setup host coalescing engine. */ |
| 8365 | tw32(HOSTCC_MODE, 0); |
| 8366 | for (i = 0; i < 2000; i++) { |
| 8367 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) |
| 8368 | break; |
| 8369 | udelay(10); |
| 8370 | } |
| 8371 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 8372 | __tg3_set_coalesce(tp, &tp->coal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8373 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8374 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8375 | /* Status/statistics block address. See tg3_timer, |
| 8376 | * the tg3_periodic_fetch_stats call there, and |
| 8377 | * tg3_get_stats to see how this works for 5705/5750 chips. |
| 8378 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8379 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 8380 | ((u64) tp->stats_mapping >> 32)); |
| 8381 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 8382 | ((u64) tp->stats_mapping & 0xffffffff)); |
| 8383 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8385 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8386 | |
| 8387 | /* Clear statistics and status block memory areas */ |
| 8388 | for (i = NIC_SRAM_STATS_BLK; |
| 8389 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; |
| 8390 | i += sizeof(u32)) { |
| 8391 | tg3_write_mem(tp, i, 0); |
| 8392 | udelay(40); |
| 8393 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8394 | } |
| 8395 | |
| 8396 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); |
| 8397 | |
| 8398 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); |
| 8399 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8400 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8401 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
| 8402 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8403 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
| 8404 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 8405 | /* reset to prevent losing 1st rx packet intermittently */ |
| 8406 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 8407 | udelay(10); |
| 8408 | } |
| 8409 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8410 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8411 | 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] | 8412 | else |
| 8413 | tp->mac_mode = 0; |
| 8414 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8415 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8416 | if (!tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8417 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 8418 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
| 8419 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8420 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
| 8421 | udelay(40); |
| 8422 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8423 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8424 | * If TG3_FLAG_IS_NIC is zero, we should read the |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8425 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
| 8426 | * whether used as inputs or outputs, are set by boot code after |
| 8427 | * reset. |
| 8428 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8429 | if (!tg3_flag(tp, IS_NIC)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8430 | u32 gpio_mask; |
| 8431 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8432 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
| 8433 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 8434 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 8435 | |
| 8436 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 8437 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
| 8438 | GRC_LCLCTRL_GPIO_OUTPUT3; |
| 8439 | |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 8440 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 8441 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 8442 | |
Gary Zambrano | aaf8446 | 2007-05-05 11:51:45 -0700 | [diff] [blame] | 8443 | tp->grc_local_ctrl &= ~gpio_mask; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8444 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
| 8445 | |
| 8446 | /* GPIO1 must be driven high for eeprom write protect */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8447 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8448 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 8449 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8451 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 8452 | udelay(100); |
| 8453 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8454 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) { |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8455 | val = tr32(MSGINT_MODE); |
| 8456 | val |= MSGINT_MODE_MULTIVEC_EN | MSGINT_MODE_ENABLE; |
| 8457 | tw32(MSGINT_MODE, val); |
| 8458 | } |
| 8459 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8460 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8461 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
| 8462 | udelay(40); |
| 8463 | } |
| 8464 | |
| 8465 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | |
| 8466 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | |
| 8467 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | |
| 8468 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | |
| 8469 | WDMAC_MODE_LNGREAD_ENAB); |
| 8470 | |
Matt Carlson | c590893 | 2011-03-09 16:58:25 +0000 | [diff] [blame] | 8471 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 8472 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8473 | if (tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8474 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
| 8475 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { |
| 8476 | /* nothing */ |
| 8477 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8478 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8479 | val |= WDMAC_MODE_RX_ACCEL; |
| 8480 | } |
| 8481 | } |
| 8482 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8483 | /* Enable host coalescing bug fix */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8484 | if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 8485 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8486 | |
Matt Carlson | 788a035 | 2009-11-02 14:26:03 +0000 | [diff] [blame] | 8487 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 8488 | val |= WDMAC_MODE_BURST_ALL_DATA; |
| 8489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8490 | tw32_f(WDMAC_MODE, val); |
| 8491 | udelay(40); |
| 8492 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8493 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8494 | u16 pcix_cmd; |
| 8495 | |
| 8496 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8497 | &pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8498 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8499 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
| 8500 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8501 | } 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] | 8502 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
| 8503 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8504 | } |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8505 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8506 | pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8507 | } |
| 8508 | |
| 8509 | tw32_f(RDMAC_MODE, rdmac_mode); |
| 8510 | udelay(40); |
| 8511 | |
| 8512 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8513 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8514 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 8515 | |
| 8516 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 8517 | tw32(SNDDATAC_MODE, |
| 8518 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); |
| 8519 | else |
| 8520 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); |
| 8521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8522 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
| 8523 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8524 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8525 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8526 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
| 8527 | tw32(RCVDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8528 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8529 | if (tg3_flag(tp, HW_TSO_1) || |
| 8530 | tg3_flag(tp, HW_TSO_2) || |
| 8531 | tg3_flag(tp, HW_TSO_3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8532 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8533 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8534 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8535 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
| 8536 | tw32(SNDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8537 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
| 8538 | |
| 8539 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 8540 | err = tg3_load_5701_a0_firmware_fix(tp); |
| 8541 | if (err) |
| 8542 | return err; |
| 8543 | } |
| 8544 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8545 | if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8546 | err = tg3_load_tso_firmware(tp); |
| 8547 | if (err) |
| 8548 | return err; |
| 8549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8550 | |
| 8551 | tp->tx_mode = TX_MODE_ENABLE; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 8552 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8553 | if (tg3_flag(tp, 5755_PLUS) || |
Matt Carlson | b1d0521 | 2010-06-05 17:24:31 +0000 | [diff] [blame] | 8554 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 8555 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 8556 | |
| 8557 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 8558 | val = TX_MODE_JMB_FRM_LEN | TX_MODE_CNT_DN_MODE; |
| 8559 | tp->tx_mode &= ~val; |
| 8560 | tp->tx_mode |= tr32(MAC_TX_MODE) & val; |
| 8561 | } |
| 8562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8563 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 8564 | udelay(100); |
| 8565 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8566 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8567 | u32 reg = MAC_RSS_INDIR_TBL_0; |
| 8568 | u8 *ent = (u8 *)&val; |
| 8569 | |
| 8570 | /* Setup the indirection table */ |
| 8571 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { |
| 8572 | int idx = i % sizeof(val); |
| 8573 | |
Matt Carlson | 5efeeea | 2010-07-11 09:31:40 +0000 | [diff] [blame] | 8574 | ent[idx] = i % (tp->irq_cnt - 1); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8575 | if (idx == sizeof(val) - 1) { |
| 8576 | tw32(reg, val); |
| 8577 | reg += 4; |
| 8578 | } |
| 8579 | } |
| 8580 | |
| 8581 | /* Setup the "secret" hash key. */ |
| 8582 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); |
| 8583 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); |
| 8584 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); |
| 8585 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); |
| 8586 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); |
| 8587 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); |
| 8588 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); |
| 8589 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); |
| 8590 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); |
| 8591 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); |
| 8592 | } |
| 8593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8594 | tp->rx_mode = RX_MODE_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8595 | if (tg3_flag(tp, 5755_PLUS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 8596 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
| 8597 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8598 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8599 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
| 8600 | RX_MODE_RSS_ITBL_HASH_BITS_7 | |
| 8601 | RX_MODE_RSS_IPV6_HASH_EN | |
| 8602 | RX_MODE_RSS_TCP_IPV6_HASH_EN | |
| 8603 | RX_MODE_RSS_IPV4_HASH_EN | |
| 8604 | RX_MODE_RSS_TCP_IPV4_HASH_EN; |
| 8605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8606 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8607 | udelay(10); |
| 8608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8609 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 8610 | |
| 8611 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8612 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8613 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 8614 | udelay(10); |
| 8615 | } |
| 8616 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8617 | udelay(10); |
| 8618 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8619 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8620 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8621 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8622 | /* Set drive transmission level to 1.2V */ |
| 8623 | /* only if the signal pre-emphasis bit is not set */ |
| 8624 | val = tr32(MAC_SERDES_CFG); |
| 8625 | val &= 0xfffff000; |
| 8626 | val |= 0x880; |
| 8627 | tw32(MAC_SERDES_CFG, val); |
| 8628 | } |
| 8629 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) |
| 8630 | tw32(MAC_SERDES_CFG, 0x616000); |
| 8631 | } |
| 8632 | |
| 8633 | /* Prevent chip from dropping frames when flow control |
| 8634 | * is enabled. |
| 8635 | */ |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 8636 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 8637 | val = 1; |
| 8638 | else |
| 8639 | val = 2; |
| 8640 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8641 | |
| 8642 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8643 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8644 | /* Use hardware link auto-negotiation */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8645 | tg3_flag_set(tp, HW_AUTONEG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8646 | } |
| 8647 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8648 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 8649 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) { |
| 8650 | u32 tmp; |
| 8651 | |
| 8652 | tmp = tr32(SERDES_RX_CTRL); |
| 8653 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); |
| 8654 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; |
| 8655 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; |
| 8656 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 8657 | } |
| 8658 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8659 | if (!tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 8660 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 8661 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8662 | tp->link_config.speed = tp->link_config.orig_speed; |
| 8663 | tp->link_config.duplex = tp->link_config.orig_duplex; |
| 8664 | tp->link_config.autoneg = tp->link_config.orig_autoneg; |
| 8665 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8666 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8667 | err = tg3_setup_phy(tp, 0); |
| 8668 | if (err) |
| 8669 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8670 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8671 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 8672 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8673 | u32 tmp; |
| 8674 | |
| 8675 | /* Clear CRC stats. */ |
| 8676 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { |
| 8677 | tg3_writephy(tp, MII_TG3_TEST1, |
| 8678 | tmp | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 8679 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8680 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8681 | } |
| 8682 | } |
| 8683 | |
| 8684 | __tg3_set_rx_mode(tp->dev); |
| 8685 | |
| 8686 | /* Initialize receive rules. */ |
| 8687 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); |
| 8688 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 8689 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); |
| 8690 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 8691 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8692 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8693 | limit = 8; |
| 8694 | else |
| 8695 | limit = 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8696 | if (tg3_flag(tp, ENABLE_ASF)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8697 | limit -= 4; |
| 8698 | switch (limit) { |
| 8699 | case 16: |
| 8700 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); |
| 8701 | case 15: |
| 8702 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); |
| 8703 | case 14: |
| 8704 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); |
| 8705 | case 13: |
| 8706 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); |
| 8707 | case 12: |
| 8708 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); |
| 8709 | case 11: |
| 8710 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); |
| 8711 | case 10: |
| 8712 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); |
| 8713 | case 9: |
| 8714 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); |
| 8715 | case 8: |
| 8716 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); |
| 8717 | case 7: |
| 8718 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); |
| 8719 | case 6: |
| 8720 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); |
| 8721 | case 5: |
| 8722 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); |
| 8723 | case 4: |
| 8724 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ |
| 8725 | case 3: |
| 8726 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ |
| 8727 | case 2: |
| 8728 | case 1: |
| 8729 | |
| 8730 | default: |
| 8731 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 8732 | } |
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, ENABLE_APE)) |
Matt Carlson | 9ce768e | 2007-10-11 19:49:11 -0700 | [diff] [blame] | 8735 | /* Write our heartbeat update interval to APE. */ |
| 8736 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, |
| 8737 | APE_HOST_HEARTBEAT_INT_DISABLE); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8739 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
| 8740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8741 | return 0; |
| 8742 | } |
| 8743 | |
| 8744 | /* Called at device open time to get the chip ready for |
| 8745 | * packet processing. Invoked with tp->lock held. |
| 8746 | */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8747 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8748 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8749 | tg3_switch_clocks(tp); |
| 8750 | |
| 8751 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 8752 | |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 8753 | return tg3_reset_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8754 | } |
| 8755 | |
| 8756 | #define TG3_STAT_ADD32(PSTAT, REG) \ |
| 8757 | do { u32 __val = tr32(REG); \ |
| 8758 | (PSTAT)->low += __val; \ |
| 8759 | if ((PSTAT)->low < __val) \ |
| 8760 | (PSTAT)->high += 1; \ |
| 8761 | } while (0) |
| 8762 | |
| 8763 | static void tg3_periodic_fetch_stats(struct tg3 *tp) |
| 8764 | { |
| 8765 | struct tg3_hw_stats *sp = tp->hw_stats; |
| 8766 | |
| 8767 | if (!netif_carrier_ok(tp->dev)) |
| 8768 | return; |
| 8769 | |
| 8770 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); |
| 8771 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); |
| 8772 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); |
| 8773 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); |
| 8774 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); |
| 8775 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); |
| 8776 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); |
| 8777 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); |
| 8778 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); |
| 8779 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); |
| 8780 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); |
| 8781 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); |
| 8782 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); |
| 8783 | |
| 8784 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); |
| 8785 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); |
| 8786 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); |
| 8787 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); |
| 8788 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); |
| 8789 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); |
| 8790 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); |
| 8791 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); |
| 8792 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); |
| 8793 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); |
| 8794 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); |
| 8795 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); |
| 8796 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); |
| 8797 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 8798 | |
| 8799 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 8800 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) { |
| 8801 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
| 8802 | } else { |
| 8803 | u32 val = tr32(HOSTCC_FLOW_ATTN); |
| 8804 | val = (val & HOSTCC_FLOW_ATTN_MBUF_LWM) ? 1 : 0; |
| 8805 | if (val) { |
| 8806 | tw32(HOSTCC_FLOW_ATTN, HOSTCC_FLOW_ATTN_MBUF_LWM); |
| 8807 | sp->rx_discards.low += val; |
| 8808 | if (sp->rx_discards.low < val) |
| 8809 | sp->rx_discards.high += 1; |
| 8810 | } |
| 8811 | sp->mbuf_lwm_thresh_hit = sp->rx_discards; |
| 8812 | } |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 8813 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8814 | } |
| 8815 | |
| 8816 | static void tg3_timer(unsigned long __opaque) |
| 8817 | { |
| 8818 | struct tg3 *tp = (struct tg3 *) __opaque; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8819 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 8820 | if (tp->irq_sync) |
| 8821 | goto restart_timer; |
| 8822 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8823 | spin_lock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8824 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8825 | if (!tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8826 | /* All of this garbage is because when using non-tagged |
| 8827 | * IRQ status the mailbox/status_block protocol the chip |
| 8828 | * uses with the cpu is race prone. |
| 8829 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8830 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8831 | tw32(GRC_LOCAL_CTRL, |
| 8832 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 8833 | } else { |
| 8834 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 8835 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8836 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8837 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8838 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8839 | tg3_flag_set(tp, RESTART_TIMER); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8840 | spin_unlock(&tp->lock); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8841 | schedule_work(&tp->reset_task); |
| 8842 | return; |
| 8843 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8844 | } |
| 8845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8846 | /* This part only runs once per second. */ |
| 8847 | if (!--tp->timer_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8848 | if (tg3_flag(tp, 5705_PLUS)) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8849 | tg3_periodic_fetch_stats(tp); |
| 8850 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 8851 | if (tp->setlpicnt && !--tp->setlpicnt) |
| 8852 | tg3_phy_eee_enable(tp); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 8853 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8854 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8855 | u32 mac_stat; |
| 8856 | int phy_event; |
| 8857 | |
| 8858 | mac_stat = tr32(MAC_STATUS); |
| 8859 | |
| 8860 | phy_event = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8861 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8862 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
| 8863 | phy_event = 1; |
| 8864 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) |
| 8865 | phy_event = 1; |
| 8866 | |
| 8867 | if (phy_event) |
| 8868 | tg3_setup_phy(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8869 | } else if (tg3_flag(tp, POLL_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8870 | u32 mac_stat = tr32(MAC_STATUS); |
| 8871 | int need_setup = 0; |
| 8872 | |
| 8873 | if (netif_carrier_ok(tp->dev) && |
| 8874 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
| 8875 | need_setup = 1; |
| 8876 | } |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 8877 | if (!netif_carrier_ok(tp->dev) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8878 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
| 8879 | MAC_STATUS_SIGNAL_DET))) { |
| 8880 | need_setup = 1; |
| 8881 | } |
| 8882 | if (need_setup) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 8883 | if (!tp->serdes_counter) { |
| 8884 | tw32_f(MAC_MODE, |
| 8885 | (tp->mac_mode & |
| 8886 | ~MAC_MODE_PORT_MODE_MASK)); |
| 8887 | udelay(40); |
| 8888 | tw32_f(MAC_MODE, tp->mac_mode); |
| 8889 | udelay(40); |
| 8890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8891 | tg3_setup_phy(tp, 0); |
| 8892 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8893 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8894 | tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 8895 | tg3_serdes_parallel_detect(tp); |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 8896 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8897 | |
| 8898 | tp->timer_counter = tp->timer_multiplier; |
| 8899 | } |
| 8900 | |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 8901 | /* Heartbeat is only sent once every 2 seconds. |
| 8902 | * |
| 8903 | * The heartbeat is to tell the ASF firmware that the host |
| 8904 | * driver is still alive. In the event that the OS crashes, |
| 8905 | * ASF needs to reset the hardware to free up the FIFO space |
| 8906 | * that may be filled with rx packets destined for the host. |
| 8907 | * If the FIFO is full, ASF will no longer function properly. |
| 8908 | * |
| 8909 | * Unintended resets have been reported on real time kernels |
| 8910 | * where the timer doesn't run on time. Netpoll will also have |
| 8911 | * same problem. |
| 8912 | * |
| 8913 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware |
| 8914 | * to check the ring condition when the heartbeat is expiring |
| 8915 | * before doing the reset. This will prevent most unintended |
| 8916 | * resets. |
| 8917 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8918 | if (!--tp->asf_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8919 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 8920 | tg3_wait_for_event_ack(tp); |
| 8921 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 8922 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 8923 | FWCMD_NICDRV_ALIVE3); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 8924 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 8925 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
| 8926 | TG3_FW_UPDATE_TIMEOUT_SEC); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 8927 | |
| 8928 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8929 | } |
| 8930 | tp->asf_counter = tp->asf_multiplier; |
| 8931 | } |
| 8932 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8933 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8934 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 8935 | restart_timer: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8936 | tp->timer.expires = jiffies + tp->timer_offset; |
| 8937 | add_timer(&tp->timer); |
| 8938 | } |
| 8939 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8940 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8941 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 8942 | irq_handler_t fn; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8943 | unsigned long flags; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8944 | char *name; |
| 8945 | struct tg3_napi *tnapi = &tp->napi[irq_num]; |
| 8946 | |
| 8947 | if (tp->irq_cnt == 1) |
| 8948 | name = tp->dev->name; |
| 8949 | else { |
| 8950 | name = &tnapi->irq_lbl[0]; |
| 8951 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); |
| 8952 | name[IFNAMSIZ-1] = 0; |
| 8953 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8954 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8955 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8956 | fn = tg3_msi; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8957 | if (tg3_flag(tp, 1SHOT_MSI)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8958 | fn = tg3_msi_1shot; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 8959 | flags = 0; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8960 | } else { |
| 8961 | fn = tg3_interrupt; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8962 | if (tg3_flag(tp, TAGGED_STATUS)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8963 | fn = tg3_interrupt_tagged; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 8964 | flags = IRQF_SHARED; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8965 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8966 | |
| 8967 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8968 | } |
| 8969 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8970 | static int tg3_test_interrupt(struct tg3 *tp) |
| 8971 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8972 | struct tg3_napi *tnapi = &tp->napi[0]; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8973 | struct net_device *dev = tp->dev; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8974 | int err, i, intr_ok = 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8975 | u32 val; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8976 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 8977 | if (!netif_running(dev)) |
| 8978 | return -ENODEV; |
| 8979 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8980 | tg3_disable_ints(tp); |
| 8981 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8982 | free_irq(tnapi->irq_vec, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8983 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8984 | /* |
| 8985 | * Turn off MSI one shot mode. Otherwise this test has no |
| 8986 | * observable way to know whether the interrupt was delivered. |
| 8987 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8988 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8989 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
| 8990 | tw32(MSGINT_MODE, val); |
| 8991 | } |
| 8992 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8993 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8994 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8995 | if (err) |
| 8996 | return err; |
| 8997 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8998 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8999 | tg3_enable_ints(tp); |
| 9000 | |
| 9001 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 9002 | tnapi->coal_now); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9003 | |
| 9004 | for (i = 0; i < 5; i++) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9005 | u32 int_mbox, misc_host_ctrl; |
| 9006 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 9007 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9008 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 9009 | |
| 9010 | if ((int_mbox != 0) || |
| 9011 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { |
| 9012 | intr_ok = 1; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9013 | break; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9014 | } |
| 9015 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9016 | msleep(10); |
| 9017 | } |
| 9018 | |
| 9019 | tg3_disable_ints(tp); |
| 9020 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9021 | free_irq(tnapi->irq_vec, tnapi); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9022 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9023 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9024 | |
| 9025 | if (err) |
| 9026 | return err; |
| 9027 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9028 | if (intr_ok) { |
| 9029 | /* Reenable MSI one shot mode. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9030 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9031 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
| 9032 | tw32(MSGINT_MODE, val); |
| 9033 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9034 | return 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9035 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9036 | |
| 9037 | return -EIO; |
| 9038 | } |
| 9039 | |
| 9040 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is |
| 9041 | * successfully restored |
| 9042 | */ |
| 9043 | static int tg3_test_msi(struct tg3 *tp) |
| 9044 | { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9045 | int err; |
| 9046 | u16 pci_cmd; |
| 9047 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9048 | if (!tg3_flag(tp, USING_MSI)) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9049 | return 0; |
| 9050 | |
| 9051 | /* Turn off SERR reporting in case MSI terminates with Master |
| 9052 | * Abort. |
| 9053 | */ |
| 9054 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 9055 | pci_write_config_word(tp->pdev, PCI_COMMAND, |
| 9056 | pci_cmd & ~PCI_COMMAND_SERR); |
| 9057 | |
| 9058 | err = tg3_test_interrupt(tp); |
| 9059 | |
| 9060 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 9061 | |
| 9062 | if (!err) |
| 9063 | return 0; |
| 9064 | |
| 9065 | /* other failures */ |
| 9066 | if (err != -EIO) |
| 9067 | return err; |
| 9068 | |
| 9069 | /* MSI test failed, go back to INTx mode */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 9070 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
| 9071 | "to INTx mode. Please report this failure to the PCI " |
| 9072 | "maintainer and include system chipset information\n"); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9073 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9074 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 9075 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9076 | pci_disable_msi(tp->pdev); |
| 9077 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9078 | tg3_flag_clear(tp, USING_MSI); |
Andre Detsch | dc8bf1b | 2010-04-26 07:27:07 +0000 | [diff] [blame] | 9079 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9080 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9081 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9082 | if (err) |
| 9083 | return err; |
| 9084 | |
| 9085 | /* Need to reset the chip because the MSI cycle may have terminated |
| 9086 | * with Master Abort. |
| 9087 | */ |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9088 | tg3_full_lock(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9089 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9090 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 9091 | err = tg3_init_hw(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9092 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9093 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9094 | |
| 9095 | if (err) |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9096 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9097 | |
| 9098 | return err; |
| 9099 | } |
| 9100 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9101 | static int tg3_request_firmware(struct tg3 *tp) |
| 9102 | { |
| 9103 | const __be32 *fw_data; |
| 9104 | |
| 9105 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9106 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
| 9107 | tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9108 | return -ENOENT; |
| 9109 | } |
| 9110 | |
| 9111 | fw_data = (void *)tp->fw->data; |
| 9112 | |
| 9113 | /* Firmware blob starts with version numbers, followed by |
| 9114 | * start address and _full_ length including BSS sections |
| 9115 | * (which must be longer than the actual data, of course |
| 9116 | */ |
| 9117 | |
| 9118 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ |
| 9119 | if (tp->fw_len < (tp->fw->size - 12)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9120 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
| 9121 | tp->fw_len, tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9122 | release_firmware(tp->fw); |
| 9123 | tp->fw = NULL; |
| 9124 | return -EINVAL; |
| 9125 | } |
| 9126 | |
| 9127 | /* We no longer need firmware; we have it. */ |
| 9128 | tp->fw_needed = NULL; |
| 9129 | return 0; |
| 9130 | } |
| 9131 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9132 | static bool tg3_enable_msix(struct tg3 *tp) |
| 9133 | { |
| 9134 | int i, rc, cpus = num_online_cpus(); |
| 9135 | struct msix_entry msix_ent[tp->irq_max]; |
| 9136 | |
| 9137 | if (cpus == 1) |
| 9138 | /* Just fallback to the simpler MSI mode. */ |
| 9139 | return false; |
| 9140 | |
| 9141 | /* |
| 9142 | * We want as many rx rings enabled as there are cpus. |
| 9143 | * The first MSIX vector only deals with link interrupts, etc, |
| 9144 | * so we add one to the number of vectors we are requesting. |
| 9145 | */ |
| 9146 | tp->irq_cnt = min_t(unsigned, cpus + 1, tp->irq_max); |
| 9147 | |
| 9148 | for (i = 0; i < tp->irq_max; i++) { |
| 9149 | msix_ent[i].entry = i; |
| 9150 | msix_ent[i].vector = 0; |
| 9151 | } |
| 9152 | |
| 9153 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9154 | if (rc < 0) { |
| 9155 | return false; |
| 9156 | } else if (rc != 0) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9157 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
| 9158 | return false; |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9159 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
| 9160 | tp->irq_cnt, rc); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9161 | tp->irq_cnt = rc; |
| 9162 | } |
| 9163 | |
| 9164 | for (i = 0; i < tp->irq_max; i++) |
| 9165 | tp->napi[i].irq_vec = msix_ent[i].vector; |
| 9166 | |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 9167 | netif_set_real_num_tx_queues(tp->dev, 1); |
| 9168 | rc = tp->irq_cnt > 1 ? tp->irq_cnt - 1 : 1; |
| 9169 | if (netif_set_real_num_rx_queues(tp->dev, rc)) { |
| 9170 | pci_disable_msix(tp->pdev); |
| 9171 | return false; |
| 9172 | } |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 9173 | |
| 9174 | if (tp->irq_cnt > 1) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9175 | tg3_flag_set(tp, ENABLE_RSS); |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 9176 | |
| 9177 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 9178 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9179 | tg3_flag_set(tp, ENABLE_TSS); |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 9180 | netif_set_real_num_tx_queues(tp->dev, tp->irq_cnt - 1); |
| 9181 | } |
| 9182 | } |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9183 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9184 | return true; |
| 9185 | } |
| 9186 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9187 | static void tg3_ints_init(struct tg3 *tp) |
| 9188 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9189 | if ((tg3_flag(tp, SUPPORT_MSI) || tg3_flag(tp, SUPPORT_MSIX)) && |
| 9190 | !tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9191 | /* All MSI supporting chips should support tagged |
| 9192 | * status. Assert that this is the case. |
| 9193 | */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 9194 | netdev_warn(tp->dev, |
| 9195 | "MSI without TAGGED_STATUS? Not using MSI\n"); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9196 | goto defcfg; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9197 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9198 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9199 | if (tg3_flag(tp, SUPPORT_MSIX) && tg3_enable_msix(tp)) |
| 9200 | tg3_flag_set(tp, USING_MSIX); |
| 9201 | else if (tg3_flag(tp, SUPPORT_MSI) && pci_enable_msi(tp->pdev) == 0) |
| 9202 | tg3_flag_set(tp, USING_MSI); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9203 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9204 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9205 | u32 msi_mode = tr32(MSGINT_MODE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9206 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9207 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9208 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
| 9209 | } |
| 9210 | defcfg: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9211 | if (!tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9212 | tp->irq_cnt = 1; |
| 9213 | tp->napi[0].irq_vec = tp->pdev->irq; |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 9214 | netif_set_real_num_tx_queues(tp->dev, 1); |
Matt Carlson | 8540788 | 2010-10-06 13:40:58 -0700 | [diff] [blame] | 9215 | netif_set_real_num_rx_queues(tp->dev, 1); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9216 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9217 | } |
| 9218 | |
| 9219 | static void tg3_ints_fini(struct tg3 *tp) |
| 9220 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9221 | if (tg3_flag(tp, USING_MSIX)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9222 | pci_disable_msix(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9223 | else if (tg3_flag(tp, USING_MSI)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9224 | pci_disable_msi(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9225 | tg3_flag_clear(tp, USING_MSI); |
| 9226 | tg3_flag_clear(tp, USING_MSIX); |
| 9227 | tg3_flag_clear(tp, ENABLE_RSS); |
| 9228 | tg3_flag_clear(tp, ENABLE_TSS); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9229 | } |
| 9230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9231 | static int tg3_open(struct net_device *dev) |
| 9232 | { |
| 9233 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9234 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9235 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9236 | if (tp->fw_needed) { |
| 9237 | err = tg3_request_firmware(tp); |
| 9238 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 9239 | if (err) |
| 9240 | return err; |
| 9241 | } else if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9242 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9243 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 9244 | } else if (!tg3_flag(tp, TSO_CAPABLE)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9245 | netdev_notice(tp->dev, "TSO capability restored\n"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9246 | tg3_flag_set(tp, TSO_CAPABLE); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9247 | } |
| 9248 | } |
| 9249 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 9250 | netif_carrier_off(tp->dev); |
| 9251 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 9252 | err = tg3_power_up(tp); |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 9253 | if (err) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9254 | return err; |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 9255 | |
| 9256 | tg3_full_lock(tp, 0); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9258 | tg3_disable_ints(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9259 | tg3_flag_clear(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9260 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9261 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9262 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9263 | /* |
| 9264 | * Setup interrupts first so we know how |
| 9265 | * many NAPI resources to allocate |
| 9266 | */ |
| 9267 | tg3_ints_init(tp); |
| 9268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9269 | /* The placement of this call is tied |
| 9270 | * to the setup and use of Host TX descriptors. |
| 9271 | */ |
| 9272 | err = tg3_alloc_consistent(tp); |
| 9273 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9274 | goto err_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9275 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 9276 | tg3_napi_init(tp); |
| 9277 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 9278 | tg3_napi_enable(tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 9279 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9280 | for (i = 0; i < tp->irq_cnt; i++) { |
| 9281 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9282 | err = tg3_request_irq(tp, i); |
| 9283 | if (err) { |
| 9284 | for (i--; i >= 0; i--) |
| 9285 | free_irq(tnapi->irq_vec, tnapi); |
| 9286 | break; |
| 9287 | } |
| 9288 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9289 | |
| 9290 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9291 | goto err_out2; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9292 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9293 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9294 | |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 9295 | err = tg3_init_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9296 | if (err) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9297 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9298 | tg3_free_rings(tp); |
| 9299 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9300 | if (tg3_flag(tp, TAGGED_STATUS)) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9301 | tp->timer_offset = HZ; |
| 9302 | else |
| 9303 | tp->timer_offset = HZ / 10; |
| 9304 | |
| 9305 | BUG_ON(tp->timer_offset > HZ); |
| 9306 | tp->timer_counter = tp->timer_multiplier = |
| 9307 | (HZ / tp->timer_offset); |
| 9308 | tp->asf_counter = tp->asf_multiplier = |
Michael Chan | 28fbef7 | 2005-10-26 15:48:35 -0700 | [diff] [blame] | 9309 | ((HZ / tp->timer_offset) * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9310 | |
| 9311 | init_timer(&tp->timer); |
| 9312 | tp->timer.expires = jiffies + tp->timer_offset; |
| 9313 | tp->timer.data = (unsigned long) tp; |
| 9314 | tp->timer.function = tg3_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9315 | } |
| 9316 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9317 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9318 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9319 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9320 | goto err_out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9321 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9322 | if (tg3_flag(tp, USING_MSI)) { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9323 | err = tg3_test_msi(tp); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9324 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9325 | if (err) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9326 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9327 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9328 | tg3_free_rings(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9329 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9330 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9331 | goto err_out2; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9332 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9333 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9334 | if (!tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9335 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9336 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9337 | tw32(PCIE_TRANSACTION_CFG, |
| 9338 | val | PCIE_TRANS_CFG_1SHOT_MSI); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9339 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9340 | } |
| 9341 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9342 | tg3_phy_start(tp); |
| 9343 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9344 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9345 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9346 | add_timer(&tp->timer); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9347 | tg3_flag_set(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9348 | tg3_enable_ints(tp); |
| 9349 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9350 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9351 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 9352 | netif_tx_start_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9353 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 9354 | /* |
| 9355 | * Reset loopback feature if it was turned on while the device was down |
| 9356 | * make sure that it's installed properly now. |
| 9357 | */ |
| 9358 | if (dev->features & NETIF_F_LOOPBACK) |
| 9359 | tg3_set_loopback(dev, dev->features); |
| 9360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9361 | return 0; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9362 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9363 | err_out3: |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9364 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 9365 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9366 | free_irq(tnapi->irq_vec, tnapi); |
| 9367 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9368 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9369 | err_out2: |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 9370 | tg3_napi_disable(tp); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 9371 | tg3_napi_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9372 | tg3_free_consistent(tp); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9373 | |
| 9374 | err_out1: |
| 9375 | tg3_ints_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9376 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9377 | } |
| 9378 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9379 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *, |
| 9380 | struct rtnl_link_stats64 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9381 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *); |
| 9382 | |
| 9383 | static int tg3_close(struct net_device *dev) |
| 9384 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9385 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9386 | struct tg3 *tp = netdev_priv(dev); |
| 9387 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 9388 | tg3_napi_disable(tp); |
Oleg Nesterov | 28e53bd | 2007-05-09 02:34:22 -0700 | [diff] [blame] | 9389 | cancel_work_sync(&tp->reset_task); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 9390 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 9391 | netif_tx_stop_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9392 | |
| 9393 | del_timer_sync(&tp->timer); |
| 9394 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 9395 | tg3_phy_stop(tp); |
| 9396 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9397 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9398 | |
| 9399 | tg3_disable_ints(tp); |
| 9400 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9401 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9402 | tg3_free_rings(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9403 | tg3_flag_clear(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9404 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9405 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9406 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9407 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 9408 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9409 | free_irq(tnapi->irq_vec, tnapi); |
| 9410 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9411 | |
| 9412 | tg3_ints_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9413 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9414 | tg3_get_stats64(tp->dev, &tp->net_stats_prev); |
| 9415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9416 | memcpy(&tp->estats_prev, tg3_get_estats(tp), |
| 9417 | sizeof(tp->estats_prev)); |
| 9418 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 9419 | tg3_napi_fini(tp); |
| 9420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9421 | tg3_free_consistent(tp); |
| 9422 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 9423 | tg3_power_down(tp); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9424 | |
| 9425 | netif_carrier_off(tp->dev); |
| 9426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9427 | return 0; |
| 9428 | } |
| 9429 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9430 | static inline u64 get_stat64(tg3_stat64_t *val) |
Stefan Buehler | 816f8b8 | 2008-08-15 14:10:54 -0700 | [diff] [blame] | 9431 | { |
| 9432 | return ((u64)val->high << 32) | ((u64)val->low); |
| 9433 | } |
| 9434 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9435 | static u64 calc_crc_errors(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9436 | { |
| 9437 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9438 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9439 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9440 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 9441 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9442 | u32 val; |
| 9443 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9444 | spin_lock_bh(&tp->lock); |
Michael Chan | 569a5df | 2007-02-13 12:18:15 -0800 | [diff] [blame] | 9445 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
| 9446 | tg3_writephy(tp, MII_TG3_TEST1, |
| 9447 | val | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 9448 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9449 | } else |
| 9450 | val = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9451 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9452 | |
| 9453 | tp->phy_crc_errors += val; |
| 9454 | |
| 9455 | return tp->phy_crc_errors; |
| 9456 | } |
| 9457 | |
| 9458 | return get_stat64(&hw_stats->rx_fcs_errors); |
| 9459 | } |
| 9460 | |
| 9461 | #define ESTAT_ADD(member) \ |
| 9462 | estats->member = old_estats->member + \ |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9463 | get_stat64(&hw_stats->member) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9464 | |
| 9465 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp) |
| 9466 | { |
| 9467 | struct tg3_ethtool_stats *estats = &tp->estats; |
| 9468 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
| 9469 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9470 | |
| 9471 | if (!hw_stats) |
| 9472 | return old_estats; |
| 9473 | |
| 9474 | ESTAT_ADD(rx_octets); |
| 9475 | ESTAT_ADD(rx_fragments); |
| 9476 | ESTAT_ADD(rx_ucast_packets); |
| 9477 | ESTAT_ADD(rx_mcast_packets); |
| 9478 | ESTAT_ADD(rx_bcast_packets); |
| 9479 | ESTAT_ADD(rx_fcs_errors); |
| 9480 | ESTAT_ADD(rx_align_errors); |
| 9481 | ESTAT_ADD(rx_xon_pause_rcvd); |
| 9482 | ESTAT_ADD(rx_xoff_pause_rcvd); |
| 9483 | ESTAT_ADD(rx_mac_ctrl_rcvd); |
| 9484 | ESTAT_ADD(rx_xoff_entered); |
| 9485 | ESTAT_ADD(rx_frame_too_long_errors); |
| 9486 | ESTAT_ADD(rx_jabbers); |
| 9487 | ESTAT_ADD(rx_undersize_packets); |
| 9488 | ESTAT_ADD(rx_in_length_errors); |
| 9489 | ESTAT_ADD(rx_out_length_errors); |
| 9490 | ESTAT_ADD(rx_64_or_less_octet_packets); |
| 9491 | ESTAT_ADD(rx_65_to_127_octet_packets); |
| 9492 | ESTAT_ADD(rx_128_to_255_octet_packets); |
| 9493 | ESTAT_ADD(rx_256_to_511_octet_packets); |
| 9494 | ESTAT_ADD(rx_512_to_1023_octet_packets); |
| 9495 | ESTAT_ADD(rx_1024_to_1522_octet_packets); |
| 9496 | ESTAT_ADD(rx_1523_to_2047_octet_packets); |
| 9497 | ESTAT_ADD(rx_2048_to_4095_octet_packets); |
| 9498 | ESTAT_ADD(rx_4096_to_8191_octet_packets); |
| 9499 | ESTAT_ADD(rx_8192_to_9022_octet_packets); |
| 9500 | |
| 9501 | ESTAT_ADD(tx_octets); |
| 9502 | ESTAT_ADD(tx_collisions); |
| 9503 | ESTAT_ADD(tx_xon_sent); |
| 9504 | ESTAT_ADD(tx_xoff_sent); |
| 9505 | ESTAT_ADD(tx_flow_control); |
| 9506 | ESTAT_ADD(tx_mac_errors); |
| 9507 | ESTAT_ADD(tx_single_collisions); |
| 9508 | ESTAT_ADD(tx_mult_collisions); |
| 9509 | ESTAT_ADD(tx_deferred); |
| 9510 | ESTAT_ADD(tx_excessive_collisions); |
| 9511 | ESTAT_ADD(tx_late_collisions); |
| 9512 | ESTAT_ADD(tx_collide_2times); |
| 9513 | ESTAT_ADD(tx_collide_3times); |
| 9514 | ESTAT_ADD(tx_collide_4times); |
| 9515 | ESTAT_ADD(tx_collide_5times); |
| 9516 | ESTAT_ADD(tx_collide_6times); |
| 9517 | ESTAT_ADD(tx_collide_7times); |
| 9518 | ESTAT_ADD(tx_collide_8times); |
| 9519 | ESTAT_ADD(tx_collide_9times); |
| 9520 | ESTAT_ADD(tx_collide_10times); |
| 9521 | ESTAT_ADD(tx_collide_11times); |
| 9522 | ESTAT_ADD(tx_collide_12times); |
| 9523 | ESTAT_ADD(tx_collide_13times); |
| 9524 | ESTAT_ADD(tx_collide_14times); |
| 9525 | ESTAT_ADD(tx_collide_15times); |
| 9526 | ESTAT_ADD(tx_ucast_packets); |
| 9527 | ESTAT_ADD(tx_mcast_packets); |
| 9528 | ESTAT_ADD(tx_bcast_packets); |
| 9529 | ESTAT_ADD(tx_carrier_sense_errors); |
| 9530 | ESTAT_ADD(tx_discards); |
| 9531 | ESTAT_ADD(tx_errors); |
| 9532 | |
| 9533 | ESTAT_ADD(dma_writeq_full); |
| 9534 | ESTAT_ADD(dma_write_prioq_full); |
| 9535 | ESTAT_ADD(rxbds_empty); |
| 9536 | ESTAT_ADD(rx_discards); |
| 9537 | ESTAT_ADD(rx_errors); |
| 9538 | ESTAT_ADD(rx_threshold_hit); |
| 9539 | |
| 9540 | ESTAT_ADD(dma_readq_full); |
| 9541 | ESTAT_ADD(dma_read_prioq_full); |
| 9542 | ESTAT_ADD(tx_comp_queue_full); |
| 9543 | |
| 9544 | ESTAT_ADD(ring_set_send_prod_index); |
| 9545 | ESTAT_ADD(ring_status_update); |
| 9546 | ESTAT_ADD(nic_irqs); |
| 9547 | ESTAT_ADD(nic_avoided_irqs); |
| 9548 | ESTAT_ADD(nic_tx_threshold_hit); |
| 9549 | |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 9550 | ESTAT_ADD(mbuf_lwm_thresh_hit); |
| 9551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9552 | return estats; |
| 9553 | } |
| 9554 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9555 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
| 9556 | struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9557 | { |
| 9558 | struct tg3 *tp = netdev_priv(dev); |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9559 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9560 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9561 | |
| 9562 | if (!hw_stats) |
| 9563 | return old_stats; |
| 9564 | |
| 9565 | stats->rx_packets = old_stats->rx_packets + |
| 9566 | get_stat64(&hw_stats->rx_ucast_packets) + |
| 9567 | get_stat64(&hw_stats->rx_mcast_packets) + |
| 9568 | get_stat64(&hw_stats->rx_bcast_packets); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9570 | stats->tx_packets = old_stats->tx_packets + |
| 9571 | get_stat64(&hw_stats->tx_ucast_packets) + |
| 9572 | get_stat64(&hw_stats->tx_mcast_packets) + |
| 9573 | get_stat64(&hw_stats->tx_bcast_packets); |
| 9574 | |
| 9575 | stats->rx_bytes = old_stats->rx_bytes + |
| 9576 | get_stat64(&hw_stats->rx_octets); |
| 9577 | stats->tx_bytes = old_stats->tx_bytes + |
| 9578 | get_stat64(&hw_stats->tx_octets); |
| 9579 | |
| 9580 | stats->rx_errors = old_stats->rx_errors + |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 9581 | get_stat64(&hw_stats->rx_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9582 | stats->tx_errors = old_stats->tx_errors + |
| 9583 | get_stat64(&hw_stats->tx_errors) + |
| 9584 | get_stat64(&hw_stats->tx_mac_errors) + |
| 9585 | get_stat64(&hw_stats->tx_carrier_sense_errors) + |
| 9586 | get_stat64(&hw_stats->tx_discards); |
| 9587 | |
| 9588 | stats->multicast = old_stats->multicast + |
| 9589 | get_stat64(&hw_stats->rx_mcast_packets); |
| 9590 | stats->collisions = old_stats->collisions + |
| 9591 | get_stat64(&hw_stats->tx_collisions); |
| 9592 | |
| 9593 | stats->rx_length_errors = old_stats->rx_length_errors + |
| 9594 | get_stat64(&hw_stats->rx_frame_too_long_errors) + |
| 9595 | get_stat64(&hw_stats->rx_undersize_packets); |
| 9596 | |
| 9597 | stats->rx_over_errors = old_stats->rx_over_errors + |
| 9598 | get_stat64(&hw_stats->rxbds_empty); |
| 9599 | stats->rx_frame_errors = old_stats->rx_frame_errors + |
| 9600 | get_stat64(&hw_stats->rx_align_errors); |
| 9601 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + |
| 9602 | get_stat64(&hw_stats->tx_discards); |
| 9603 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + |
| 9604 | get_stat64(&hw_stats->tx_carrier_sense_errors); |
| 9605 | |
| 9606 | stats->rx_crc_errors = old_stats->rx_crc_errors + |
| 9607 | calc_crc_errors(tp); |
| 9608 | |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 9609 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
| 9610 | get_stat64(&hw_stats->rx_discards); |
| 9611 | |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 9612 | stats->rx_dropped = tp->rx_dropped; |
| 9613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9614 | return stats; |
| 9615 | } |
| 9616 | |
| 9617 | static inline u32 calc_crc(unsigned char *buf, int len) |
| 9618 | { |
| 9619 | u32 reg; |
| 9620 | u32 tmp; |
| 9621 | int j, k; |
| 9622 | |
| 9623 | reg = 0xffffffff; |
| 9624 | |
| 9625 | for (j = 0; j < len; j++) { |
| 9626 | reg ^= buf[j]; |
| 9627 | |
| 9628 | for (k = 0; k < 8; k++) { |
| 9629 | tmp = reg & 0x01; |
| 9630 | |
| 9631 | reg >>= 1; |
| 9632 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 9633 | if (tmp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9634 | reg ^= 0xedb88320; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9635 | } |
| 9636 | } |
| 9637 | |
| 9638 | return ~reg; |
| 9639 | } |
| 9640 | |
| 9641 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) |
| 9642 | { |
| 9643 | /* accept or reject all multicast frames */ |
| 9644 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); |
| 9645 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); |
| 9646 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); |
| 9647 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); |
| 9648 | } |
| 9649 | |
| 9650 | static void __tg3_set_rx_mode(struct net_device *dev) |
| 9651 | { |
| 9652 | struct tg3 *tp = netdev_priv(dev); |
| 9653 | u32 rx_mode; |
| 9654 | |
| 9655 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
| 9656 | RX_MODE_KEEP_VLAN_TAG); |
| 9657 | |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 9658 | #if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9659 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
| 9660 | * flag clear. |
| 9661 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9662 | if (!tg3_flag(tp, ENABLE_ASF)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9663 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 9664 | #endif |
| 9665 | |
| 9666 | if (dev->flags & IFF_PROMISC) { |
| 9667 | /* Promiscuous mode. */ |
| 9668 | rx_mode |= RX_MODE_PROMISC; |
| 9669 | } else if (dev->flags & IFF_ALLMULTI) { |
| 9670 | /* Accept all multicast. */ |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 9671 | tg3_set_multi(tp, 1); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 9672 | } else if (netdev_mc_empty(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9673 | /* Reject all multicast. */ |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 9674 | tg3_set_multi(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9675 | } else { |
| 9676 | /* Accept one or more multicast(s). */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 9677 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9678 | u32 mc_filter[4] = { 0, }; |
| 9679 | u32 regidx; |
| 9680 | u32 bit; |
| 9681 | u32 crc; |
| 9682 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 9683 | netdev_for_each_mc_addr(ha, dev) { |
| 9684 | crc = calc_crc(ha->addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9685 | bit = ~crc & 0x7f; |
| 9686 | regidx = (bit & 0x60) >> 5; |
| 9687 | bit &= 0x1f; |
| 9688 | mc_filter[regidx] |= (1 << bit); |
| 9689 | } |
| 9690 | |
| 9691 | tw32(MAC_HASH_REG_0, mc_filter[0]); |
| 9692 | tw32(MAC_HASH_REG_1, mc_filter[1]); |
| 9693 | tw32(MAC_HASH_REG_2, mc_filter[2]); |
| 9694 | tw32(MAC_HASH_REG_3, mc_filter[3]); |
| 9695 | } |
| 9696 | |
| 9697 | if (rx_mode != tp->rx_mode) { |
| 9698 | tp->rx_mode = rx_mode; |
| 9699 | tw32_f(MAC_RX_MODE, rx_mode); |
| 9700 | udelay(10); |
| 9701 | } |
| 9702 | } |
| 9703 | |
| 9704 | static void tg3_set_rx_mode(struct net_device *dev) |
| 9705 | { |
| 9706 | struct tg3 *tp = netdev_priv(dev); |
| 9707 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 9708 | if (!netif_running(dev)) |
| 9709 | return; |
| 9710 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9711 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9712 | __tg3_set_rx_mode(dev); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9713 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9714 | } |
| 9715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9716 | static int tg3_get_regs_len(struct net_device *dev) |
| 9717 | { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 9718 | return TG3_REG_BLK_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9719 | } |
| 9720 | |
| 9721 | static void tg3_get_regs(struct net_device *dev, |
| 9722 | struct ethtool_regs *regs, void *_p) |
| 9723 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9724 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9725 | |
| 9726 | regs->version = 0; |
| 9727 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 9728 | memset(_p, 0, TG3_REG_BLK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9729 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9730 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9731 | return; |
| 9732 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9733 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9734 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 9735 | tg3_dump_legacy_regs(tp, (u32 *)_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9736 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9737 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9738 | } |
| 9739 | |
| 9740 | static int tg3_get_eeprom_len(struct net_device *dev) |
| 9741 | { |
| 9742 | struct tg3 *tp = netdev_priv(dev); |
| 9743 | |
| 9744 | return tp->nvram_size; |
| 9745 | } |
| 9746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9747 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 9748 | { |
| 9749 | struct tg3 *tp = netdev_priv(dev); |
| 9750 | int ret; |
| 9751 | u8 *pd; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9752 | u32 i, offset, len, b_offset, b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9753 | __be32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9754 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9755 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 9756 | return -EINVAL; |
| 9757 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9758 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9759 | return -EAGAIN; |
| 9760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9761 | offset = eeprom->offset; |
| 9762 | len = eeprom->len; |
| 9763 | eeprom->len = 0; |
| 9764 | |
| 9765 | eeprom->magic = TG3_EEPROM_MAGIC; |
| 9766 | |
| 9767 | if (offset & 3) { |
| 9768 | /* adjustments to start on required 4 byte boundary */ |
| 9769 | b_offset = offset & 3; |
| 9770 | b_count = 4 - b_offset; |
| 9771 | if (b_count > len) { |
| 9772 | /* i.e. offset=1 len=2 */ |
| 9773 | b_count = len; |
| 9774 | } |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9775 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9776 | if (ret) |
| 9777 | return ret; |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 9778 | memcpy(data, ((char *)&val) + b_offset, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9779 | len -= b_count; |
| 9780 | offset += b_count; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 9781 | eeprom->len += b_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9782 | } |
| 9783 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9784 | /* read bytes up to the last 4 byte boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9785 | pd = &data[eeprom->len]; |
| 9786 | for (i = 0; i < (len - (len & 3)); i += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9787 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9788 | if (ret) { |
| 9789 | eeprom->len += i; |
| 9790 | return ret; |
| 9791 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9792 | memcpy(pd + i, &val, 4); |
| 9793 | } |
| 9794 | eeprom->len += i; |
| 9795 | |
| 9796 | if (len & 3) { |
| 9797 | /* read last bytes not ending on 4 byte boundary */ |
| 9798 | pd = &data[eeprom->len]; |
| 9799 | b_count = len & 3; |
| 9800 | b_offset = offset + len - b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9801 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9802 | if (ret) |
| 9803 | return ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9804 | memcpy(pd, &val, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9805 | eeprom->len += b_count; |
| 9806 | } |
| 9807 | return 0; |
| 9808 | } |
| 9809 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9810 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9811 | |
| 9812 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 9813 | { |
| 9814 | struct tg3 *tp = netdev_priv(dev); |
| 9815 | int ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9816 | u32 offset, len, b_offset, odd_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9817 | u8 *buf; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9818 | __be32 start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9819 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9820 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9821 | return -EAGAIN; |
| 9822 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9823 | if (tg3_flag(tp, NO_NVRAM) || |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 9824 | eeprom->magic != TG3_EEPROM_MAGIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9825 | return -EINVAL; |
| 9826 | |
| 9827 | offset = eeprom->offset; |
| 9828 | len = eeprom->len; |
| 9829 | |
| 9830 | if ((b_offset = (offset & 3))) { |
| 9831 | /* adjustments to start on required 4 byte boundary */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9832 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9833 | if (ret) |
| 9834 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9835 | len += b_offset; |
| 9836 | offset &= ~3; |
Michael Chan | 1c8594b | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 9837 | if (len < 4) |
| 9838 | len = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9839 | } |
| 9840 | |
| 9841 | odd_len = 0; |
Michael Chan | 1c8594b | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 9842 | if (len & 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9843 | /* adjustments to end on required 4 byte boundary */ |
| 9844 | odd_len = 1; |
| 9845 | len = (len + 3) & ~3; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9846 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9847 | if (ret) |
| 9848 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9849 | } |
| 9850 | |
| 9851 | buf = data; |
| 9852 | if (b_offset || odd_len) { |
| 9853 | buf = kmalloc(len, GFP_KERNEL); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 9854 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9855 | return -ENOMEM; |
| 9856 | if (b_offset) |
| 9857 | memcpy(buf, &start, 4); |
| 9858 | if (odd_len) |
| 9859 | memcpy(buf+len-4, &end, 4); |
| 9860 | memcpy(buf + b_offset, data, eeprom->len); |
| 9861 | } |
| 9862 | |
| 9863 | ret = tg3_nvram_write_block(tp, offset, len, buf); |
| 9864 | |
| 9865 | if (buf != data) |
| 9866 | kfree(buf); |
| 9867 | |
| 9868 | return ret; |
| 9869 | } |
| 9870 | |
| 9871 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 9872 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9873 | struct tg3 *tp = netdev_priv(dev); |
| 9874 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9875 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9876 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9877 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9878 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9879 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 9880 | return phy_ethtool_gset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9881 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9883 | cmd->supported = (SUPPORTED_Autoneg); |
| 9884 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9885 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9886 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
| 9887 | SUPPORTED_1000baseT_Full); |
| 9888 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9889 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9890 | cmd->supported |= (SUPPORTED_100baseT_Half | |
| 9891 | SUPPORTED_100baseT_Full | |
| 9892 | SUPPORTED_10baseT_Half | |
| 9893 | SUPPORTED_10baseT_Full | |
Matt Carlson | 3bebab5 | 2007-11-12 21:22:40 -0800 | [diff] [blame] | 9894 | SUPPORTED_TP); |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 9895 | cmd->port = PORT_TP; |
| 9896 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9897 | cmd->supported |= SUPPORTED_FIBRE; |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 9898 | cmd->port = PORT_FIBRE; |
| 9899 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9901 | cmd->advertising = tp->link_config.advertising; |
| 9902 | if (netif_running(dev)) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 9903 | ethtool_cmd_speed_set(cmd, tp->link_config.active_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9904 | cmd->duplex = tp->link_config.active_duplex; |
Matt Carlson | 64c2218 | 2010-10-14 10:37:44 +0000 | [diff] [blame] | 9905 | } else { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 9906 | ethtool_cmd_speed_set(cmd, SPEED_INVALID); |
Matt Carlson | 64c2218 | 2010-10-14 10:37:44 +0000 | [diff] [blame] | 9907 | cmd->duplex = DUPLEX_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9908 | } |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 9909 | cmd->phy_address = tp->phy_addr; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9910 | cmd->transceiver = XCVR_INTERNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9911 | cmd->autoneg = tp->link_config.autoneg; |
| 9912 | cmd->maxtxpkt = 0; |
| 9913 | cmd->maxrxpkt = 0; |
| 9914 | return 0; |
| 9915 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9917 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 9918 | { |
| 9919 | struct tg3 *tp = netdev_priv(dev); |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 9920 | u32 speed = ethtool_cmd_speed(cmd); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9921 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9922 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9923 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9924 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9925 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9926 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 9927 | return phy_ethtool_sset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9928 | } |
| 9929 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9930 | if (cmd->autoneg != AUTONEG_ENABLE && |
| 9931 | cmd->autoneg != AUTONEG_DISABLE) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 9932 | return -EINVAL; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9933 | |
| 9934 | if (cmd->autoneg == AUTONEG_DISABLE && |
| 9935 | cmd->duplex != DUPLEX_FULL && |
| 9936 | cmd->duplex != DUPLEX_HALF) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 9937 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9938 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9939 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 9940 | u32 mask = ADVERTISED_Autoneg | |
| 9941 | ADVERTISED_Pause | |
| 9942 | ADVERTISED_Asym_Pause; |
| 9943 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9944 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9945 | mask |= ADVERTISED_1000baseT_Half | |
| 9946 | ADVERTISED_1000baseT_Full; |
| 9947 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9948 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9949 | mask |= ADVERTISED_100baseT_Half | |
| 9950 | ADVERTISED_100baseT_Full | |
| 9951 | ADVERTISED_10baseT_Half | |
| 9952 | ADVERTISED_10baseT_Full | |
| 9953 | ADVERTISED_TP; |
| 9954 | else |
| 9955 | mask |= ADVERTISED_FIBRE; |
| 9956 | |
| 9957 | if (cmd->advertising & ~mask) |
| 9958 | return -EINVAL; |
| 9959 | |
| 9960 | mask &= (ADVERTISED_1000baseT_Half | |
| 9961 | ADVERTISED_1000baseT_Full | |
| 9962 | ADVERTISED_100baseT_Half | |
| 9963 | ADVERTISED_100baseT_Full | |
| 9964 | ADVERTISED_10baseT_Half | |
| 9965 | ADVERTISED_10baseT_Full); |
| 9966 | |
| 9967 | cmd->advertising &= mask; |
| 9968 | } else { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9969 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 9970 | if (speed != SPEED_1000) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9971 | return -EINVAL; |
| 9972 | |
| 9973 | if (cmd->duplex != DUPLEX_FULL) |
| 9974 | return -EINVAL; |
| 9975 | } else { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 9976 | if (speed != SPEED_100 && |
| 9977 | speed != SPEED_10) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9978 | return -EINVAL; |
| 9979 | } |
| 9980 | } |
| 9981 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9982 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9983 | |
| 9984 | tp->link_config.autoneg = cmd->autoneg; |
| 9985 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Andy Gospodarek | 405d8e5 | 2007-10-08 01:08:47 -0700 | [diff] [blame] | 9986 | tp->link_config.advertising = (cmd->advertising | |
| 9987 | ADVERTISED_Autoneg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9988 | tp->link_config.speed = SPEED_INVALID; |
| 9989 | tp->link_config.duplex = DUPLEX_INVALID; |
| 9990 | } else { |
| 9991 | tp->link_config.advertising = 0; |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 9992 | tp->link_config.speed = speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9993 | tp->link_config.duplex = cmd->duplex; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9994 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9995 | |
Michael Chan | 24fcad6 | 2006-12-17 17:06:46 -0800 | [diff] [blame] | 9996 | tp->link_config.orig_speed = tp->link_config.speed; |
| 9997 | tp->link_config.orig_duplex = tp->link_config.duplex; |
| 9998 | tp->link_config.orig_autoneg = tp->link_config.autoneg; |
| 9999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10000 | if (netif_running(dev)) |
| 10001 | tg3_setup_phy(tp, 1); |
| 10002 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10003 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10005 | return 0; |
| 10006 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10008 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 10009 | { |
| 10010 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10012 | strcpy(info->driver, DRV_MODULE_NAME); |
| 10013 | strcpy(info->version, DRV_MODULE_VERSION); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 10014 | strcpy(info->fw_version, tp->fw_ver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10015 | strcpy(info->bus_info, pci_name(tp->pdev)); |
| 10016 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10018 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 10019 | { |
| 10020 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10021 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10022 | if (tg3_flag(tp, WOL_CAP) && device_can_wakeup(&tp->pdev->dev)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 10023 | wol->supported = WAKE_MAGIC; |
| 10024 | else |
| 10025 | wol->supported = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10026 | wol->wolopts = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10027 | if (tg3_flag(tp, WOL_ENABLE) && device_can_wakeup(&tp->pdev->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10028 | wol->wolopts = WAKE_MAGIC; |
| 10029 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 10030 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10032 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 10033 | { |
| 10034 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 10035 | struct device *dp = &tp->pdev->dev; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10037 | if (wol->wolopts & ~WAKE_MAGIC) |
| 10038 | return -EINVAL; |
| 10039 | if ((wol->wolopts & WAKE_MAGIC) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10040 | !(tg3_flag(tp, WOL_CAP) && device_can_wakeup(dp))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10041 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10042 | |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 10043 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
| 10044 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10045 | spin_lock_bh(&tp->lock); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 10046 | if (device_may_wakeup(dp)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10047 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 10048 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10049 | tg3_flag_clear(tp, WOL_ENABLE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10050 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10052 | return 0; |
| 10053 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10055 | static u32 tg3_get_msglevel(struct net_device *dev) |
| 10056 | { |
| 10057 | struct tg3 *tp = netdev_priv(dev); |
| 10058 | return tp->msg_enable; |
| 10059 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10061 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
| 10062 | { |
| 10063 | struct tg3 *tp = netdev_priv(dev); |
| 10064 | tp->msg_enable = value; |
| 10065 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10067 | static int tg3_nway_reset(struct net_device *dev) |
| 10068 | { |
| 10069 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10070 | int r; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10072 | if (!netif_running(dev)) |
| 10073 | return -EAGAIN; |
| 10074 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10075 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10076 | return -EINVAL; |
| 10077 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10078 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10079 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10080 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10081 | 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] | 10082 | } else { |
| 10083 | u32 bmcr; |
| 10084 | |
| 10085 | spin_lock_bh(&tp->lock); |
| 10086 | r = -EINVAL; |
| 10087 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 10088 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && |
| 10089 | ((bmcr & BMCR_ANENABLE) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10090 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10091 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
| 10092 | BMCR_ANENABLE); |
| 10093 | r = 0; |
| 10094 | } |
| 10095 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10096 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10098 | return r; |
| 10099 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10101 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 10102 | { |
| 10103 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10104 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10105 | ering->rx_max_pending = tp->rx_std_ring_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10106 | ering->rx_mini_max_pending = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10107 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10108 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10109 | else |
| 10110 | ering->rx_jumbo_max_pending = 0; |
| 10111 | |
| 10112 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10113 | |
| 10114 | ering->rx_pending = tp->rx_pending; |
| 10115 | ering->rx_mini_pending = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10116 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10117 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
| 10118 | else |
| 10119 | ering->rx_jumbo_pending = 0; |
| 10120 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10121 | ering->tx_pending = tp->napi[0].tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10122 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10124 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 10125 | { |
| 10126 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10127 | int i, irq_sync = 0, err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10128 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10129 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
| 10130 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10131 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
| 10132 | (ering->tx_pending <= MAX_SKB_FRAGS) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10133 | (tg3_flag(tp, TSO_BUG) && |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10134 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10135 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10136 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10137 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10138 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10139 | tg3_netif_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10140 | irq_sync = 1; |
| 10141 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10142 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10143 | tg3_full_lock(tp, irq_sync); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10145 | tp->rx_pending = ering->rx_pending; |
| 10146 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10147 | if (tg3_flag(tp, MAX_RXPEND_64) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10148 | tp->rx_pending > 63) |
| 10149 | tp->rx_pending = 63; |
| 10150 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10151 | |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 10152 | for (i = 0; i < tp->irq_max; i++) |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10153 | tp->napi[i].tx_pending = ering->tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10154 | |
| 10155 | if (netif_running(dev)) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10156 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10157 | err = tg3_restart_hw(tp, 1); |
| 10158 | if (!err) |
| 10159 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10160 | } |
| 10161 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10162 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10163 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10164 | if (irq_sync && !err) |
| 10165 | tg3_phy_start(tp); |
| 10166 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10167 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10168 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10170 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10171 | { |
| 10172 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10173 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10174 | epause->autoneg = !!tg3_flag(tp, PAUSE_AUTONEG); |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10175 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10176 | if (tp->link_config.active_flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10177 | epause->rx_pause = 1; |
| 10178 | else |
| 10179 | epause->rx_pause = 0; |
| 10180 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10181 | if (tp->link_config.active_flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10182 | epause->tx_pause = 1; |
| 10183 | else |
| 10184 | epause->tx_pause = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10185 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10187 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10188 | { |
| 10189 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10190 | int err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10191 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10192 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10193 | u32 newadv; |
| 10194 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10195 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10196 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10197 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10198 | if (!(phydev->supported & SUPPORTED_Pause) || |
| 10199 | (!(phydev->supported & SUPPORTED_Asym_Pause) && |
Nicolas Kaiser | 2259dca | 2010-10-07 23:29:27 +0000 | [diff] [blame] | 10200 | (epause->rx_pause != epause->tx_pause))) |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10201 | return -EINVAL; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10202 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10203 | tp->link_config.flowctrl = 0; |
| 10204 | if (epause->rx_pause) { |
| 10205 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10206 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10207 | if (epause->tx_pause) { |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10208 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10209 | newadv = ADVERTISED_Pause; |
| 10210 | } else |
| 10211 | newadv = ADVERTISED_Pause | |
| 10212 | ADVERTISED_Asym_Pause; |
| 10213 | } else if (epause->tx_pause) { |
| 10214 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 10215 | newadv = ADVERTISED_Asym_Pause; |
| 10216 | } else |
| 10217 | newadv = 0; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10218 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10219 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10220 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10221 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10222 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10223 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10224 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10225 | u32 oldadv = phydev->advertising & |
| 10226 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 10227 | if (oldadv != newadv) { |
| 10228 | phydev->advertising &= |
| 10229 | ~(ADVERTISED_Pause | |
| 10230 | ADVERTISED_Asym_Pause); |
| 10231 | phydev->advertising |= newadv; |
| 10232 | if (phydev->autoneg) { |
| 10233 | /* |
| 10234 | * Always renegotiate the link to |
| 10235 | * inform our link partner of our |
| 10236 | * flow control settings, even if the |
| 10237 | * flow control is forced. Let |
| 10238 | * tg3_adjust_link() do the final |
| 10239 | * flow control setup. |
| 10240 | */ |
| 10241 | return phy_start_aneg(phydev); |
| 10242 | } |
| 10243 | } |
| 10244 | |
| 10245 | if (!epause->autoneg) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10246 | tg3_setup_flow_control(tp, 0, 0); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10247 | } else { |
| 10248 | tp->link_config.orig_advertising &= |
| 10249 | ~(ADVERTISED_Pause | |
| 10250 | ADVERTISED_Asym_Pause); |
| 10251 | tp->link_config.orig_advertising |= newadv; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10252 | } |
| 10253 | } else { |
| 10254 | int irq_sync = 0; |
| 10255 | |
| 10256 | if (netif_running(dev)) { |
| 10257 | tg3_netif_stop(tp); |
| 10258 | irq_sync = 1; |
| 10259 | } |
| 10260 | |
| 10261 | tg3_full_lock(tp, irq_sync); |
| 10262 | |
| 10263 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10264 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10265 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10266 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10267 | if (epause->rx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10268 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10269 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10270 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10271 | if (epause->tx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10272 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10273 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10274 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10275 | |
| 10276 | if (netif_running(dev)) { |
| 10277 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 10278 | err = tg3_restart_hw(tp, 1); |
| 10279 | if (!err) |
| 10280 | tg3_netif_start(tp); |
| 10281 | } |
| 10282 | |
| 10283 | tg3_full_unlock(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10285 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10286 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10287 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10288 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10289 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10290 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 10291 | switch (sset) { |
| 10292 | case ETH_SS_TEST: |
| 10293 | return TG3_NUM_TEST; |
| 10294 | case ETH_SS_STATS: |
| 10295 | return TG3_NUM_STATS; |
| 10296 | default: |
| 10297 | return -EOPNOTSUPP; |
| 10298 | } |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10299 | } |
| 10300 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10301 | 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] | 10302 | { |
| 10303 | switch (stringset) { |
| 10304 | case ETH_SS_STATS: |
| 10305 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 10306 | break; |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10307 | case ETH_SS_TEST: |
| 10308 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); |
| 10309 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10310 | default: |
| 10311 | WARN_ON(1); /* we need a WARN() */ |
| 10312 | break; |
| 10313 | } |
| 10314 | } |
| 10315 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 10316 | static int tg3_set_phys_id(struct net_device *dev, |
| 10317 | enum ethtool_phys_id_state state) |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10318 | { |
| 10319 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10320 | |
| 10321 | if (!netif_running(tp->dev)) |
| 10322 | return -EAGAIN; |
| 10323 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 10324 | switch (state) { |
| 10325 | case ETHTOOL_ID_ACTIVE: |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 10326 | return 1; /* cycle on/off once per second */ |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10327 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 10328 | case ETHTOOL_ID_ON: |
| 10329 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 10330 | LED_CTRL_1000MBPS_ON | |
| 10331 | LED_CTRL_100MBPS_ON | |
| 10332 | LED_CTRL_10MBPS_ON | |
| 10333 | LED_CTRL_TRAFFIC_OVERRIDE | |
| 10334 | LED_CTRL_TRAFFIC_BLINK | |
| 10335 | LED_CTRL_TRAFFIC_LED); |
| 10336 | break; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10337 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 10338 | case ETHTOOL_ID_OFF: |
| 10339 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 10340 | LED_CTRL_TRAFFIC_OVERRIDE); |
| 10341 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10342 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 10343 | case ETHTOOL_ID_INACTIVE: |
| 10344 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 10345 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10346 | } |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 10347 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10348 | return 0; |
| 10349 | } |
| 10350 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10351 | static void tg3_get_ethtool_stats(struct net_device *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10352 | struct ethtool_stats *estats, u64 *tmp_stats) |
| 10353 | { |
| 10354 | struct tg3 *tp = netdev_priv(dev); |
| 10355 | memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats)); |
| 10356 | } |
| 10357 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 10358 | static __be32 * tg3_vpd_readblock(struct tg3 *tp) |
| 10359 | { |
| 10360 | int i; |
| 10361 | __be32 *buf; |
| 10362 | u32 offset = 0, len = 0; |
| 10363 | u32 magic, val; |
| 10364 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10365 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &magic)) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 10366 | return NULL; |
| 10367 | |
| 10368 | if (magic == TG3_EEPROM_MAGIC) { |
| 10369 | for (offset = TG3_NVM_DIR_START; |
| 10370 | offset < TG3_NVM_DIR_END; |
| 10371 | offset += TG3_NVM_DIRENT_SIZE) { |
| 10372 | if (tg3_nvram_read(tp, offset, &val)) |
| 10373 | return NULL; |
| 10374 | |
| 10375 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == |
| 10376 | TG3_NVM_DIRTYPE_EXTVPD) |
| 10377 | break; |
| 10378 | } |
| 10379 | |
| 10380 | if (offset != TG3_NVM_DIR_END) { |
| 10381 | len = (val & TG3_NVM_DIRTYPE_LENMSK) * 4; |
| 10382 | if (tg3_nvram_read(tp, offset + 4, &offset)) |
| 10383 | return NULL; |
| 10384 | |
| 10385 | offset = tg3_nvram_logical_addr(tp, offset); |
| 10386 | } |
| 10387 | } |
| 10388 | |
| 10389 | if (!offset || !len) { |
| 10390 | offset = TG3_NVM_VPD_OFF; |
| 10391 | len = TG3_NVM_VPD_LEN; |
| 10392 | } |
| 10393 | |
| 10394 | buf = kmalloc(len, GFP_KERNEL); |
| 10395 | if (buf == NULL) |
| 10396 | return NULL; |
| 10397 | |
| 10398 | if (magic == TG3_EEPROM_MAGIC) { |
| 10399 | for (i = 0; i < len; i += 4) { |
| 10400 | /* The data is in little-endian format in NVRAM. |
| 10401 | * Use the big-endian read routines to preserve |
| 10402 | * the byte order as it exists in NVRAM. |
| 10403 | */ |
| 10404 | if (tg3_nvram_read_be32(tp, offset + i, &buf[i/4])) |
| 10405 | goto error; |
| 10406 | } |
| 10407 | } else { |
| 10408 | u8 *ptr; |
| 10409 | ssize_t cnt; |
| 10410 | unsigned int pos = 0; |
| 10411 | |
| 10412 | ptr = (u8 *)&buf[0]; |
| 10413 | for (i = 0; pos < len && i < 3; i++, pos += cnt, ptr += cnt) { |
| 10414 | cnt = pci_read_vpd(tp->pdev, pos, |
| 10415 | len - pos, ptr); |
| 10416 | if (cnt == -ETIMEDOUT || cnt == -EINTR) |
| 10417 | cnt = 0; |
| 10418 | else if (cnt < 0) |
| 10419 | goto error; |
| 10420 | } |
| 10421 | if (pos != len) |
| 10422 | goto error; |
| 10423 | } |
| 10424 | |
| 10425 | return buf; |
| 10426 | |
| 10427 | error: |
| 10428 | kfree(buf); |
| 10429 | return NULL; |
| 10430 | } |
| 10431 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10432 | #define NVRAM_TEST_SIZE 0x100 |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10433 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
| 10434 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 |
| 10435 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10436 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
| 10437 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10438 | |
| 10439 | static int tg3_test_nvram(struct tg3 *tp) |
| 10440 | { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10441 | u32 csum, magic; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10442 | __be32 *buf; |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 10443 | int i, j, k, err = 0, size; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10444 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10445 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 10446 | return 0; |
| 10447 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 10448 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10449 | return -EIO; |
| 10450 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10451 | if (magic == TG3_EEPROM_MAGIC) |
| 10452 | size = NVRAM_TEST_SIZE; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10453 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10454 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
| 10455 | TG3_EEPROM_SB_FORMAT_1) { |
| 10456 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { |
| 10457 | case TG3_EEPROM_SB_REVISION_0: |
| 10458 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; |
| 10459 | break; |
| 10460 | case TG3_EEPROM_SB_REVISION_2: |
| 10461 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; |
| 10462 | break; |
| 10463 | case TG3_EEPROM_SB_REVISION_3: |
| 10464 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; |
| 10465 | break; |
| 10466 | default: |
| 10467 | return 0; |
| 10468 | } |
| 10469 | } else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10470 | return 0; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10471 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 10472 | size = NVRAM_SELFBOOT_HW_SIZE; |
| 10473 | else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10474 | return -EIO; |
| 10475 | |
| 10476 | buf = kmalloc(size, GFP_KERNEL); |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10477 | if (buf == NULL) |
| 10478 | return -ENOMEM; |
| 10479 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10480 | err = -EIO; |
| 10481 | for (i = 0, j = 0; i < size; i += 4, j++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10482 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
| 10483 | if (err) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10484 | break; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10485 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10486 | if (i < size) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10487 | goto out; |
| 10488 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10489 | /* Selfboot format */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10490 | magic = be32_to_cpu(buf[0]); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10491 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10492 | TG3_EEPROM_MAGIC_FW) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10493 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
| 10494 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10495 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10496 | TG3_EEPROM_SB_REVISION_2) { |
| 10497 | /* For rev 2, the csum doesn't include the MBA. */ |
| 10498 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) |
| 10499 | csum8 += buf8[i]; |
| 10500 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) |
| 10501 | csum8 += buf8[i]; |
| 10502 | } else { |
| 10503 | for (i = 0; i < size; i++) |
| 10504 | csum8 += buf8[i]; |
| 10505 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10506 | |
Adrian Bunk | ad96b48 | 2006-04-05 22:21:04 -0700 | [diff] [blame] | 10507 | if (csum8 == 0) { |
| 10508 | err = 0; |
| 10509 | goto out; |
| 10510 | } |
| 10511 | |
| 10512 | err = -EIO; |
| 10513 | goto out; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10514 | } |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10515 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10516 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10517 | TG3_EEPROM_MAGIC_HW) { |
| 10518 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10519 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10520 | u8 *buf8 = (u8 *) buf; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10521 | |
| 10522 | /* Separate the parity bits and the data bytes. */ |
| 10523 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { |
| 10524 | if ((i == 0) || (i == 8)) { |
| 10525 | int l; |
| 10526 | u8 msk; |
| 10527 | |
| 10528 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) |
| 10529 | parity[k++] = buf8[i] & msk; |
| 10530 | i++; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 10531 | } else if (i == 16) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10532 | int l; |
| 10533 | u8 msk; |
| 10534 | |
| 10535 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) |
| 10536 | parity[k++] = buf8[i] & msk; |
| 10537 | i++; |
| 10538 | |
| 10539 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) |
| 10540 | parity[k++] = buf8[i] & msk; |
| 10541 | i++; |
| 10542 | } |
| 10543 | data[j++] = buf8[i]; |
| 10544 | } |
| 10545 | |
| 10546 | err = -EIO; |
| 10547 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { |
| 10548 | u8 hw8 = hweight8(data[i]); |
| 10549 | |
| 10550 | if ((hw8 & 0x1) && parity[i]) |
| 10551 | goto out; |
| 10552 | else if (!(hw8 & 0x1) && !parity[i]) |
| 10553 | goto out; |
| 10554 | } |
| 10555 | err = 0; |
| 10556 | goto out; |
| 10557 | } |
| 10558 | |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 10559 | err = -EIO; |
| 10560 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10561 | /* Bootstrap checksum at offset 0x10 */ |
| 10562 | csum = calc_crc((unsigned char *) buf, 0x10); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 10563 | if (csum != le32_to_cpu(buf[0x10/4])) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10564 | goto out; |
| 10565 | |
| 10566 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ |
| 10567 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 10568 | if (csum != le32_to_cpu(buf[0xfc/4])) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10569 | goto out; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10570 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 10571 | kfree(buf); |
| 10572 | |
| 10573 | buf = tg3_vpd_readblock(tp); |
| 10574 | if (!buf) |
| 10575 | return -ENOMEM; |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 10576 | |
| 10577 | i = pci_vpd_find_tag((u8 *)buf, 0, TG3_NVM_VPD_LEN, |
| 10578 | PCI_VPD_LRDT_RO_DATA); |
| 10579 | if (i > 0) { |
| 10580 | j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); |
| 10581 | if (j < 0) |
| 10582 | goto out; |
| 10583 | |
| 10584 | if (i + PCI_VPD_LRDT_TAG_SIZE + j > TG3_NVM_VPD_LEN) |
| 10585 | goto out; |
| 10586 | |
| 10587 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 10588 | j = pci_vpd_find_info_keyword((u8 *)buf, i, j, |
| 10589 | PCI_VPD_RO_KEYWORD_CHKSUM); |
| 10590 | if (j > 0) { |
| 10591 | u8 csum8 = 0; |
| 10592 | |
| 10593 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 10594 | |
| 10595 | for (i = 0; i <= j; i++) |
| 10596 | csum8 += ((u8 *)buf)[i]; |
| 10597 | |
| 10598 | if (csum8) |
| 10599 | goto out; |
| 10600 | } |
| 10601 | } |
| 10602 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10603 | err = 0; |
| 10604 | |
| 10605 | out: |
| 10606 | kfree(buf); |
| 10607 | return err; |
| 10608 | } |
| 10609 | |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 10610 | #define TG3_SERDES_TIMEOUT_SEC 2 |
| 10611 | #define TG3_COPPER_TIMEOUT_SEC 6 |
| 10612 | |
| 10613 | static int tg3_test_link(struct tg3 *tp) |
| 10614 | { |
| 10615 | int i, max; |
| 10616 | |
| 10617 | if (!netif_running(tp->dev)) |
| 10618 | return -ENODEV; |
| 10619 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10620 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 10621 | max = TG3_SERDES_TIMEOUT_SEC; |
| 10622 | else |
| 10623 | max = TG3_COPPER_TIMEOUT_SEC; |
| 10624 | |
| 10625 | for (i = 0; i < max; i++) { |
| 10626 | if (netif_carrier_ok(tp->dev)) |
| 10627 | return 0; |
| 10628 | |
| 10629 | if (msleep_interruptible(1000)) |
| 10630 | break; |
| 10631 | } |
| 10632 | |
| 10633 | return -EIO; |
| 10634 | } |
| 10635 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10636 | /* Only test the commonly used registers */ |
David S. Miller | 30ca3e3 | 2006-03-20 23:02:36 -0800 | [diff] [blame] | 10637 | static int tg3_test_registers(struct tg3 *tp) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10638 | { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10639 | int i, is_5705, is_5750; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10640 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
| 10641 | static struct { |
| 10642 | u16 offset; |
| 10643 | u16 flags; |
| 10644 | #define TG3_FL_5705 0x1 |
| 10645 | #define TG3_FL_NOT_5705 0x2 |
| 10646 | #define TG3_FL_NOT_5788 0x4 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10647 | #define TG3_FL_NOT_5750 0x8 |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10648 | u32 read_mask; |
| 10649 | u32 write_mask; |
| 10650 | } reg_tbl[] = { |
| 10651 | /* MAC Control Registers */ |
| 10652 | { MAC_MODE, TG3_FL_NOT_5705, |
| 10653 | 0x00000000, 0x00ef6f8c }, |
| 10654 | { MAC_MODE, TG3_FL_5705, |
| 10655 | 0x00000000, 0x01ef6b8c }, |
| 10656 | { MAC_STATUS, TG3_FL_NOT_5705, |
| 10657 | 0x03800107, 0x00000000 }, |
| 10658 | { MAC_STATUS, TG3_FL_5705, |
| 10659 | 0x03800100, 0x00000000 }, |
| 10660 | { MAC_ADDR_0_HIGH, 0x0000, |
| 10661 | 0x00000000, 0x0000ffff }, |
| 10662 | { MAC_ADDR_0_LOW, 0x0000, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10663 | 0x00000000, 0xffffffff }, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10664 | { MAC_RX_MTU_SIZE, 0x0000, |
| 10665 | 0x00000000, 0x0000ffff }, |
| 10666 | { MAC_TX_MODE, 0x0000, |
| 10667 | 0x00000000, 0x00000070 }, |
| 10668 | { MAC_TX_LENGTHS, 0x0000, |
| 10669 | 0x00000000, 0x00003fff }, |
| 10670 | { MAC_RX_MODE, TG3_FL_NOT_5705, |
| 10671 | 0x00000000, 0x000007fc }, |
| 10672 | { MAC_RX_MODE, TG3_FL_5705, |
| 10673 | 0x00000000, 0x000007dc }, |
| 10674 | { MAC_HASH_REG_0, 0x0000, |
| 10675 | 0x00000000, 0xffffffff }, |
| 10676 | { MAC_HASH_REG_1, 0x0000, |
| 10677 | 0x00000000, 0xffffffff }, |
| 10678 | { MAC_HASH_REG_2, 0x0000, |
| 10679 | 0x00000000, 0xffffffff }, |
| 10680 | { MAC_HASH_REG_3, 0x0000, |
| 10681 | 0x00000000, 0xffffffff }, |
| 10682 | |
| 10683 | /* Receive Data and Receive BD Initiator Control Registers. */ |
| 10684 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, |
| 10685 | 0x00000000, 0xffffffff }, |
| 10686 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, |
| 10687 | 0x00000000, 0xffffffff }, |
| 10688 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, |
| 10689 | 0x00000000, 0x00000003 }, |
| 10690 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, |
| 10691 | 0x00000000, 0xffffffff }, |
| 10692 | { RCVDBDI_STD_BD+0, 0x0000, |
| 10693 | 0x00000000, 0xffffffff }, |
| 10694 | { RCVDBDI_STD_BD+4, 0x0000, |
| 10695 | 0x00000000, 0xffffffff }, |
| 10696 | { RCVDBDI_STD_BD+8, 0x0000, |
| 10697 | 0x00000000, 0xffff0002 }, |
| 10698 | { RCVDBDI_STD_BD+0xc, 0x0000, |
| 10699 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10700 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10701 | /* Receive BD Initiator Control Registers. */ |
| 10702 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, |
| 10703 | 0x00000000, 0xffffffff }, |
| 10704 | { RCVBDI_STD_THRESH, TG3_FL_5705, |
| 10705 | 0x00000000, 0x000003ff }, |
| 10706 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, |
| 10707 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10708 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10709 | /* Host Coalescing Control Registers. */ |
| 10710 | { HOSTCC_MODE, TG3_FL_NOT_5705, |
| 10711 | 0x00000000, 0x00000004 }, |
| 10712 | { HOSTCC_MODE, TG3_FL_5705, |
| 10713 | 0x00000000, 0x000000f6 }, |
| 10714 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, |
| 10715 | 0x00000000, 0xffffffff }, |
| 10716 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, |
| 10717 | 0x00000000, 0x000003ff }, |
| 10718 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, |
| 10719 | 0x00000000, 0xffffffff }, |
| 10720 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, |
| 10721 | 0x00000000, 0x000003ff }, |
| 10722 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, |
| 10723 | 0x00000000, 0xffffffff }, |
| 10724 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10725 | 0x00000000, 0x000000ff }, |
| 10726 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, |
| 10727 | 0x00000000, 0xffffffff }, |
| 10728 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10729 | 0x00000000, 0x000000ff }, |
| 10730 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 10731 | 0x00000000, 0xffffffff }, |
| 10732 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 10733 | 0x00000000, 0xffffffff }, |
| 10734 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 10735 | 0x00000000, 0xffffffff }, |
| 10736 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10737 | 0x00000000, 0x000000ff }, |
| 10738 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 10739 | 0x00000000, 0xffffffff }, |
| 10740 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10741 | 0x00000000, 0x000000ff }, |
| 10742 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, |
| 10743 | 0x00000000, 0xffffffff }, |
| 10744 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, |
| 10745 | 0x00000000, 0xffffffff }, |
| 10746 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, |
| 10747 | 0x00000000, 0xffffffff }, |
| 10748 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, |
| 10749 | 0x00000000, 0xffffffff }, |
| 10750 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, |
| 10751 | 0x00000000, 0xffffffff }, |
| 10752 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, |
| 10753 | 0xffffffff, 0x00000000 }, |
| 10754 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, |
| 10755 | 0xffffffff, 0x00000000 }, |
| 10756 | |
| 10757 | /* Buffer Manager Control Registers. */ |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10758 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10759 | 0x00000000, 0x007fff80 }, |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10760 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10761 | 0x00000000, 0x007fffff }, |
| 10762 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, |
| 10763 | 0x00000000, 0x0000003f }, |
| 10764 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, |
| 10765 | 0x00000000, 0x000001ff }, |
| 10766 | { BUFMGR_MB_HIGH_WATER, 0x0000, |
| 10767 | 0x00000000, 0x000001ff }, |
| 10768 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, |
| 10769 | 0xffffffff, 0x00000000 }, |
| 10770 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, |
| 10771 | 0xffffffff, 0x00000000 }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10772 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10773 | /* Mailbox Registers */ |
| 10774 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, |
| 10775 | 0x00000000, 0x000001ff }, |
| 10776 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, |
| 10777 | 0x00000000, 0x000001ff }, |
| 10778 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, |
| 10779 | 0x00000000, 0x000007ff }, |
| 10780 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, |
| 10781 | 0x00000000, 0x000001ff }, |
| 10782 | |
| 10783 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, |
| 10784 | }; |
| 10785 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10786 | is_5705 = is_5750 = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10787 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10788 | is_5705 = 1; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10789 | if (tg3_flag(tp, 5750_PLUS)) |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10790 | is_5750 = 1; |
| 10791 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10792 | |
| 10793 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { |
| 10794 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) |
| 10795 | continue; |
| 10796 | |
| 10797 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) |
| 10798 | continue; |
| 10799 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10800 | if (tg3_flag(tp, IS_5788) && |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10801 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
| 10802 | continue; |
| 10803 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10804 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
| 10805 | continue; |
| 10806 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10807 | offset = (u32) reg_tbl[i].offset; |
| 10808 | read_mask = reg_tbl[i].read_mask; |
| 10809 | write_mask = reg_tbl[i].write_mask; |
| 10810 | |
| 10811 | /* Save the original register content */ |
| 10812 | save_val = tr32(offset); |
| 10813 | |
| 10814 | /* Determine the read-only value. */ |
| 10815 | read_val = save_val & read_mask; |
| 10816 | |
| 10817 | /* Write zero to the register, then make sure the read-only bits |
| 10818 | * are not changed and the read/write bits are all zeros. |
| 10819 | */ |
| 10820 | tw32(offset, 0); |
| 10821 | |
| 10822 | val = tr32(offset); |
| 10823 | |
| 10824 | /* Test the read-only and read/write bits. */ |
| 10825 | if (((val & read_mask) != read_val) || (val & write_mask)) |
| 10826 | goto out; |
| 10827 | |
| 10828 | /* Write ones to all the bits defined by RdMask and WrMask, then |
| 10829 | * make sure the read-only bits are not changed and the |
| 10830 | * read/write bits are all ones. |
| 10831 | */ |
| 10832 | tw32(offset, read_mask | write_mask); |
| 10833 | |
| 10834 | val = tr32(offset); |
| 10835 | |
| 10836 | /* Test the read-only bits. */ |
| 10837 | if ((val & read_mask) != read_val) |
| 10838 | goto out; |
| 10839 | |
| 10840 | /* Test the read/write bits. */ |
| 10841 | if ((val & write_mask) != write_mask) |
| 10842 | goto out; |
| 10843 | |
| 10844 | tw32(offset, save_val); |
| 10845 | } |
| 10846 | |
| 10847 | return 0; |
| 10848 | |
| 10849 | out: |
Michael Chan | 9f88f29 | 2006-12-07 00:22:54 -0800 | [diff] [blame] | 10850 | if (netif_msg_hw(tp)) |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 10851 | netdev_err(tp->dev, |
| 10852 | "Register test failed at offset %x\n", offset); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10853 | tw32(offset, save_val); |
| 10854 | return -EIO; |
| 10855 | } |
| 10856 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10857 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
| 10858 | { |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 10859 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10860 | int i; |
| 10861 | u32 j; |
| 10862 | |
Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 10863 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10864 | for (j = 0; j < len; j += 4) { |
| 10865 | u32 val; |
| 10866 | |
| 10867 | tg3_write_mem(tp, offset + j, test_pattern[i]); |
| 10868 | tg3_read_mem(tp, offset + j, &val); |
| 10869 | if (val != test_pattern[i]) |
| 10870 | return -EIO; |
| 10871 | } |
| 10872 | } |
| 10873 | return 0; |
| 10874 | } |
| 10875 | |
| 10876 | static int tg3_test_memory(struct tg3 *tp) |
| 10877 | { |
| 10878 | static struct mem_entry { |
| 10879 | u32 offset; |
| 10880 | u32 len; |
| 10881 | } mem_tbl_570x[] = { |
Michael Chan | 3869019 | 2005-12-19 16:27:28 -0800 | [diff] [blame] | 10882 | { 0x00000000, 0x00b50}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10883 | { 0x00002000, 0x1c000}, |
| 10884 | { 0xffffffff, 0x00000} |
| 10885 | }, mem_tbl_5705[] = { |
| 10886 | { 0x00000100, 0x0000c}, |
| 10887 | { 0x00000200, 0x00008}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10888 | { 0x00004000, 0x00800}, |
| 10889 | { 0x00006000, 0x01000}, |
| 10890 | { 0x00008000, 0x02000}, |
| 10891 | { 0x00010000, 0x0e000}, |
| 10892 | { 0xffffffff, 0x00000} |
Michael Chan | 79f4d13 | 2006-03-20 22:28:57 -0800 | [diff] [blame] | 10893 | }, mem_tbl_5755[] = { |
| 10894 | { 0x00000200, 0x00008}, |
| 10895 | { 0x00004000, 0x00800}, |
| 10896 | { 0x00006000, 0x00800}, |
| 10897 | { 0x00008000, 0x02000}, |
| 10898 | { 0x00010000, 0x0c000}, |
| 10899 | { 0xffffffff, 0x00000} |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10900 | }, mem_tbl_5906[] = { |
| 10901 | { 0x00000200, 0x00008}, |
| 10902 | { 0x00004000, 0x00400}, |
| 10903 | { 0x00006000, 0x00400}, |
| 10904 | { 0x00008000, 0x01000}, |
| 10905 | { 0x00010000, 0x01000}, |
| 10906 | { 0xffffffff, 0x00000} |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 10907 | }, mem_tbl_5717[] = { |
| 10908 | { 0x00000200, 0x00008}, |
| 10909 | { 0x00010000, 0x0a000}, |
| 10910 | { 0x00020000, 0x13c00}, |
| 10911 | { 0xffffffff, 0x00000} |
| 10912 | }, mem_tbl_57765[] = { |
| 10913 | { 0x00000200, 0x00008}, |
| 10914 | { 0x00004000, 0x00800}, |
| 10915 | { 0x00006000, 0x09800}, |
| 10916 | { 0x00010000, 0x0a000}, |
| 10917 | { 0xffffffff, 0x00000} |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10918 | }; |
| 10919 | struct mem_entry *mem_tbl; |
| 10920 | int err = 0; |
| 10921 | int i; |
| 10922 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10923 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 10924 | mem_tbl = mem_tbl_5717; |
| 10925 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 10926 | mem_tbl = mem_tbl_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10927 | else if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10928 | mem_tbl = mem_tbl_5755; |
| 10929 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 10930 | mem_tbl = mem_tbl_5906; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10931 | else if (tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10932 | mem_tbl = mem_tbl_5705; |
| 10933 | else |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10934 | mem_tbl = mem_tbl_570x; |
| 10935 | |
| 10936 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 10937 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
| 10938 | if (err) |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10939 | break; |
| 10940 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10941 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10942 | return err; |
| 10943 | } |
| 10944 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10945 | #define TG3_MAC_LOOPBACK 0 |
| 10946 | #define TG3_PHY_LOOPBACK 1 |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 10947 | #define TG3_TSO_LOOPBACK 2 |
| 10948 | |
| 10949 | #define TG3_TSO_MSS 500 |
| 10950 | |
| 10951 | #define TG3_TSO_IP_HDR_LEN 20 |
| 10952 | #define TG3_TSO_TCP_HDR_LEN 20 |
| 10953 | #define TG3_TSO_TCP_OPT_LEN 12 |
| 10954 | |
| 10955 | static const u8 tg3_tso_header[] = { |
| 10956 | 0x08, 0x00, |
| 10957 | 0x45, 0x00, 0x00, 0x00, |
| 10958 | 0x00, 0x00, 0x40, 0x00, |
| 10959 | 0x40, 0x06, 0x00, 0x00, |
| 10960 | 0x0a, 0x00, 0x00, 0x01, |
| 10961 | 0x0a, 0x00, 0x00, 0x02, |
| 10962 | 0x0d, 0x00, 0xe0, 0x00, |
| 10963 | 0x00, 0x00, 0x01, 0x00, |
| 10964 | 0x00, 0x00, 0x02, 0x00, |
| 10965 | 0x80, 0x10, 0x10, 0x00, |
| 10966 | 0x14, 0x09, 0x00, 0x00, |
| 10967 | 0x01, 0x01, 0x08, 0x0a, |
| 10968 | 0x11, 0x11, 0x11, 0x11, |
| 10969 | 0x11, 0x11, 0x11, 0x11, |
| 10970 | }; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10971 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 10972 | static int tg3_run_loopback(struct tg3 *tp, u32 pktsz, int loopback_mode) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10973 | { |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10974 | u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 10975 | u32 base_flags = 0, mss = 0, desc_idx, coal_now, data_off, val; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10976 | struct sk_buff *skb, *rx_skb; |
| 10977 | u8 *tx_data; |
| 10978 | dma_addr_t map; |
| 10979 | int num_pkts, tx_len, rx_len, i, err; |
| 10980 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10981 | struct tg3_napi *tnapi, *rnapi; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 10982 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10983 | |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 10984 | tnapi = &tp->napi[0]; |
| 10985 | rnapi = &tp->napi[0]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 10986 | if (tp->irq_cnt > 1) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10987 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | 1da85aa | 2010-09-30 10:34:34 +0000 | [diff] [blame] | 10988 | rnapi = &tp->napi[1]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10989 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 10990 | tnapi = &tp->napi[1]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 10991 | } |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10992 | coal_now = tnapi->coal_now | rnapi->coal_now; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10993 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10994 | if (loopback_mode == TG3_MAC_LOOPBACK) { |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10995 | /* HW errata - mac loopback fails in some cases on 5780. |
| 10996 | * Normal traffic and PHY loopback are not affected by |
Matt Carlson | aba49f2 | 2011-01-25 15:58:53 +0000 | [diff] [blame] | 10997 | * errata. Also, the MAC loopback test is deprecated for |
| 10998 | * all newer ASIC revisions. |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10999 | */ |
Matt Carlson | aba49f2 | 2011-01-25 15:58:53 +0000 | [diff] [blame] | 11000 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11001 | tg3_flag(tp, CPMU_PRESENT)) |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 11002 | return 0; |
| 11003 | |
Matt Carlson | 49692ca | 2011-01-25 15:58:52 +0000 | [diff] [blame] | 11004 | mac_mode = tp->mac_mode & |
| 11005 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 11006 | mac_mode |= MAC_MODE_PORT_INT_LPBACK; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11007 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 11008 | mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11009 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 11010 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 11011 | else |
| 11012 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11013 | tw32(MAC_MODE, mac_mode); |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11014 | } else { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11015 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 11016 | tg3_phy_fet_toggle_apd(tp, false); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 11017 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100; |
| 11018 | } else |
| 11019 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000; |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 11020 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 11021 | tg3_phy_toggle_automdix(tp, 0); |
| 11022 | |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 11023 | tg3_writephy(tp, MII_BMCR, val); |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 11024 | udelay(40); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 11025 | |
Matt Carlson | 49692ca | 2011-01-25 15:58:52 +0000 | [diff] [blame] | 11026 | mac_mode = tp->mac_mode & |
| 11027 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11028 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 1061b7c | 2010-02-12 14:47:12 +0000 | [diff] [blame] | 11029 | tg3_writephy(tp, MII_TG3_FET_PTEST, |
| 11030 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
| 11031 | MII_TG3_FET_PTEST_FRC_TX_LOCK); |
| 11032 | /* The write needs to be flushed for the AC131 */ |
| 11033 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 11034 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 11035 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 11036 | } else |
| 11037 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11038 | |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 11039 | /* reset to prevent losing 1st rx packet intermittently */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11040 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 11041 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 11042 | udelay(10); |
| 11043 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 11044 | } |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 11045 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 11046 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
| 11047 | if (masked_phy_id == TG3_PHY_ID_BCM5401) |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 11048 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 11049 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 11050 | mac_mode |= MAC_MODE_LINK_POLARITY; |
Michael Chan | ff18ff0 | 2006-03-27 23:17:27 -0800 | [diff] [blame] | 11051 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 11052 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 11053 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11054 | tw32(MAC_MODE, mac_mode); |
Matt Carlson | 49692ca | 2011-01-25 15:58:52 +0000 | [diff] [blame] | 11055 | |
| 11056 | /* Wait for link */ |
| 11057 | for (i = 0; i < 100; i++) { |
| 11058 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 11059 | break; |
| 11060 | mdelay(1); |
| 11061 | } |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 11062 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11063 | |
| 11064 | err = -EIO; |
| 11065 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11066 | tx_len = pktsz; |
David S. Miller | a20e9c6 | 2006-07-31 22:38:16 -0700 | [diff] [blame] | 11067 | skb = netdev_alloc_skb(tp->dev, tx_len); |
Jesper Juhl | a50bb7b | 2006-05-09 23:14:35 -0700 | [diff] [blame] | 11068 | if (!skb) |
| 11069 | return -ENOMEM; |
| 11070 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11071 | tx_data = skb_put(skb, tx_len); |
| 11072 | memcpy(tx_data, tp->dev->dev_addr, 6); |
| 11073 | memset(tx_data + 6, 0x0, 8); |
| 11074 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11075 | tw32(MAC_RX_MTU_SIZE, tx_len + ETH_FCS_LEN); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11076 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11077 | if (loopback_mode == TG3_TSO_LOOPBACK) { |
| 11078 | struct iphdr *iph = (struct iphdr *)&tx_data[ETH_HLEN]; |
| 11079 | |
| 11080 | u32 hdr_len = TG3_TSO_IP_HDR_LEN + TG3_TSO_TCP_HDR_LEN + |
| 11081 | TG3_TSO_TCP_OPT_LEN; |
| 11082 | |
| 11083 | memcpy(tx_data + ETH_ALEN * 2, tg3_tso_header, |
| 11084 | sizeof(tg3_tso_header)); |
| 11085 | mss = TG3_TSO_MSS; |
| 11086 | |
| 11087 | val = tx_len - ETH_ALEN * 2 - sizeof(tg3_tso_header); |
| 11088 | num_pkts = DIV_ROUND_UP(val, TG3_TSO_MSS); |
| 11089 | |
| 11090 | /* Set the total length field in the IP header */ |
| 11091 | iph->tot_len = htons((u16)(mss + hdr_len)); |
| 11092 | |
| 11093 | base_flags = (TXD_FLAG_CPU_PRE_DMA | |
| 11094 | TXD_FLAG_CPU_POST_DMA); |
| 11095 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11096 | if (tg3_flag(tp, HW_TSO_1) || |
| 11097 | tg3_flag(tp, HW_TSO_2) || |
| 11098 | tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11099 | struct tcphdr *th; |
| 11100 | val = ETH_HLEN + TG3_TSO_IP_HDR_LEN; |
| 11101 | th = (struct tcphdr *)&tx_data[val]; |
| 11102 | th->check = 0; |
| 11103 | } else |
| 11104 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
| 11105 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11106 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11107 | mss |= (hdr_len & 0xc) << 12; |
| 11108 | if (hdr_len & 0x10) |
| 11109 | base_flags |= 0x00000010; |
| 11110 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11111 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11112 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11113 | else if (tg3_flag(tp, HW_TSO_1) || |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11114 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 11115 | mss |= (TG3_TSO_TCP_OPT_LEN << 9); |
| 11116 | } else { |
| 11117 | base_flags |= (TG3_TSO_TCP_OPT_LEN << 10); |
| 11118 | } |
| 11119 | |
| 11120 | data_off = ETH_ALEN * 2 + sizeof(tg3_tso_header); |
| 11121 | } else { |
| 11122 | num_pkts = 1; |
| 11123 | data_off = ETH_HLEN; |
| 11124 | } |
| 11125 | |
| 11126 | for (i = data_off; i < tx_len; i++) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11127 | tx_data[i] = (u8) (i & 0xff); |
| 11128 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 11129 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
| 11130 | if (pci_dma_mapping_error(tp->pdev, map)) { |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 11131 | dev_kfree_skb(skb); |
| 11132 | return -EIO; |
| 11133 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11134 | |
| 11135 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 11136 | rnapi->coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11137 | |
| 11138 | udelay(10); |
| 11139 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 11140 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11141 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11142 | tg3_set_txd(tnapi, tnapi->tx_prod, map, tx_len, |
| 11143 | base_flags, (mss << 1) | 1); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11144 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11145 | tnapi->tx_prod++; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11146 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11147 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 11148 | tr32_mailbox(tnapi->prodmbox); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11149 | |
| 11150 | udelay(10); |
| 11151 | |
Matt Carlson | 303fc92 | 2009-11-02 14:27:34 +0000 | [diff] [blame] | 11152 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
| 11153 | for (i = 0; i < 35; i++) { |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11154 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 11155 | coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11156 | |
| 11157 | udelay(10); |
| 11158 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 11159 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 11160 | rx_idx = rnapi->hw_status->idx[0].rx_producer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11161 | if ((tx_idx == tnapi->tx_prod) && |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11162 | (rx_idx == (rx_start_idx + num_pkts))) |
| 11163 | break; |
| 11164 | } |
| 11165 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 11166 | pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11167 | dev_kfree_skb(skb); |
| 11168 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11169 | if (tx_idx != tnapi->tx_prod) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11170 | goto out; |
| 11171 | |
| 11172 | if (rx_idx != rx_start_idx + num_pkts) |
| 11173 | goto out; |
| 11174 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11175 | val = data_off; |
| 11176 | while (rx_idx != rx_start_idx) { |
| 11177 | desc = &rnapi->rx_rcb[rx_start_idx++]; |
| 11178 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 11179 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11180 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11181 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 11182 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11183 | goto out; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11184 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11185 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) |
| 11186 | - ETH_FCS_LEN; |
| 11187 | |
| 11188 | if (loopback_mode != TG3_TSO_LOOPBACK) { |
| 11189 | if (rx_len != tx_len) |
| 11190 | goto out; |
| 11191 | |
| 11192 | if (pktsz <= TG3_RX_STD_DMA_SZ - ETH_FCS_LEN) { |
| 11193 | if (opaque_key != RXD_OPAQUE_RING_STD) |
| 11194 | goto out; |
| 11195 | } else { |
| 11196 | if (opaque_key != RXD_OPAQUE_RING_JUMBO) |
| 11197 | goto out; |
| 11198 | } |
| 11199 | } else if ((desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 11200 | (desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
Matt Carlson | 54e0a67 | 2011-05-19 12:12:50 +0000 | [diff] [blame] | 11201 | >> RXD_TCPCSUM_SHIFT != 0xffff) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11202 | goto out; |
| 11203 | } |
| 11204 | |
| 11205 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
| 11206 | rx_skb = tpr->rx_std_buffers[desc_idx].skb; |
| 11207 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], |
| 11208 | mapping); |
| 11209 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
| 11210 | rx_skb = tpr->rx_jmb_buffers[desc_idx].skb; |
| 11211 | map = dma_unmap_addr(&tpr->rx_jmb_buffers[desc_idx], |
| 11212 | mapping); |
| 11213 | } else |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11214 | goto out; |
| 11215 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11216 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, |
| 11217 | PCI_DMA_FROMDEVICE); |
| 11218 | |
| 11219 | for (i = data_off; i < rx_len; i++, val++) { |
| 11220 | if (*(rx_skb->data + i) != (u8) (val & 0xff)) |
| 11221 | goto out; |
| 11222 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11223 | } |
| 11224 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11225 | err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11226 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11227 | /* tg3_free_rings will unmap and free the rx_skb */ |
| 11228 | out: |
| 11229 | return err; |
| 11230 | } |
| 11231 | |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 11232 | #define TG3_STD_LOOPBACK_FAILED 1 |
| 11233 | #define TG3_JMB_LOOPBACK_FAILED 2 |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11234 | #define TG3_TSO_LOOPBACK_FAILED 4 |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 11235 | |
| 11236 | #define TG3_MAC_LOOPBACK_SHIFT 0 |
| 11237 | #define TG3_PHY_LOOPBACK_SHIFT 4 |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11238 | #define TG3_LOOPBACK_FAILED 0x00000077 |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11239 | |
| 11240 | static int tg3_test_loopback(struct tg3 *tp) |
| 11241 | { |
| 11242 | int err = 0; |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11243 | u32 eee_cap, cpmuctrl = 0; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11244 | |
| 11245 | if (!netif_running(tp->dev)) |
| 11246 | return TG3_LOOPBACK_FAILED; |
| 11247 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11248 | eee_cap = tp->phy_flags & TG3_PHYFLG_EEE_CAP; |
| 11249 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; |
| 11250 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11251 | err = tg3_reset_hw(tp, 1); |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11252 | if (err) { |
| 11253 | err = TG3_LOOPBACK_FAILED; |
| 11254 | goto done; |
| 11255 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11256 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11257 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 4a85f09 | 2011-04-20 07:57:37 +0000 | [diff] [blame] | 11258 | int i; |
| 11259 | |
| 11260 | /* Reroute all rx packets to the 1st queue */ |
| 11261 | for (i = MAC_RSS_INDIR_TBL_0; |
| 11262 | i < MAC_RSS_INDIR_TBL_0 + TG3_RSS_INDIR_TBL_SIZE; i += 4) |
| 11263 | tw32(i, 0x0); |
| 11264 | } |
| 11265 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11266 | /* Turn off gphy autopowerdown. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11267 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11268 | tg3_phy_toggle_apd(tp, false); |
| 11269 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11270 | if (tg3_flag(tp, CPMU_PRESENT)) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11271 | int i; |
| 11272 | u32 status; |
| 11273 | |
| 11274 | tw32(TG3_CPMU_MUTEX_REQ, CPMU_MUTEX_REQ_DRIVER); |
| 11275 | |
| 11276 | /* Wait for up to 40 microseconds to acquire lock. */ |
| 11277 | for (i = 0; i < 4; i++) { |
| 11278 | status = tr32(TG3_CPMU_MUTEX_GNT); |
| 11279 | if (status == CPMU_MUTEX_GNT_DRIVER) |
| 11280 | break; |
| 11281 | udelay(10); |
| 11282 | } |
| 11283 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11284 | if (status != CPMU_MUTEX_GNT_DRIVER) { |
| 11285 | err = TG3_LOOPBACK_FAILED; |
| 11286 | goto done; |
| 11287 | } |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11288 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 11289 | /* Turn off link-based power management. */ |
Matt Carlson | e875093 | 2007-11-12 21:11:51 -0800 | [diff] [blame] | 11290 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
Matt Carlson | 109115e | 2008-05-02 16:48:59 -0700 | [diff] [blame] | 11291 | tw32(TG3_CPMU_CTRL, |
| 11292 | cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE | |
| 11293 | CPMU_CTRL_LINK_AWARE_MODE)); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11294 | } |
| 11295 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11296 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, TG3_MAC_LOOPBACK)) |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 11297 | err |= TG3_STD_LOOPBACK_FAILED << TG3_MAC_LOOPBACK_SHIFT; |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11298 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11299 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11300 | tg3_run_loopback(tp, 9000 + ETH_HLEN, TG3_MAC_LOOPBACK)) |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 11301 | err |= TG3_JMB_LOOPBACK_FAILED << TG3_MAC_LOOPBACK_SHIFT; |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11302 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11303 | if (tg3_flag(tp, CPMU_PRESENT)) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11304 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 11305 | |
| 11306 | /* Release the mutex */ |
| 11307 | tw32(TG3_CPMU_MUTEX_GNT, CPMU_MUTEX_GNT_DRIVER); |
| 11308 | } |
| 11309 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11310 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11311 | !tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11312 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, TG3_PHY_LOOPBACK)) |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 11313 | err |= TG3_STD_LOOPBACK_FAILED << |
| 11314 | TG3_PHY_LOOPBACK_SHIFT; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11315 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11316 | tg3_run_loopback(tp, ETH_FRAME_LEN, TG3_TSO_LOOPBACK)) |
| 11317 | err |= TG3_TSO_LOOPBACK_FAILED << |
| 11318 | TG3_PHY_LOOPBACK_SHIFT; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11319 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11320 | tg3_run_loopback(tp, 9000 + ETH_HLEN, TG3_PHY_LOOPBACK)) |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 11321 | err |= TG3_JMB_LOOPBACK_FAILED << |
| 11322 | TG3_PHY_LOOPBACK_SHIFT; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11323 | } |
| 11324 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11325 | /* Re-enable gphy autopowerdown. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11326 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11327 | tg3_phy_toggle_apd(tp, true); |
| 11328 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11329 | done: |
| 11330 | tp->phy_flags |= eee_cap; |
| 11331 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11332 | return err; |
| 11333 | } |
| 11334 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11335 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
| 11336 | u64 *data) |
| 11337 | { |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11338 | struct tg3 *tp = netdev_priv(dev); |
| 11339 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11340 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 11341 | tg3_power_up(tp); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11342 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11343 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
| 11344 | |
| 11345 | if (tg3_test_nvram(tp) != 0) { |
| 11346 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11347 | data[0] = 1; |
| 11348 | } |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11349 | if (tg3_test_link(tp) != 0) { |
| 11350 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11351 | data[1] = 1; |
| 11352 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11353 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11354 | int err, err2 = 0, irq_sync = 0; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11355 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11356 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11357 | tg3_phy_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11358 | tg3_netif_stop(tp); |
| 11359 | irq_sync = 1; |
| 11360 | } |
| 11361 | |
| 11362 | tg3_full_lock(tp, irq_sync); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11363 | |
| 11364 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11365 | err = tg3_nvram_lock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11366 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11367 | if (!tg3_flag(tp, 5705_PLUS)) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11368 | tg3_halt_cpu(tp, TX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11369 | if (!err) |
| 11370 | tg3_nvram_unlock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11371 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11372 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 11373 | tg3_phy_reset(tp); |
| 11374 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11375 | if (tg3_test_registers(tp) != 0) { |
| 11376 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11377 | data[2] = 1; |
| 11378 | } |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11379 | if (tg3_test_memory(tp) != 0) { |
| 11380 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11381 | data[3] = 1; |
| 11382 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11383 | if ((data[4] = tg3_test_loopback(tp)) != 0) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11384 | etest->flags |= ETH_TEST_FL_FAILED; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11385 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11386 | tg3_full_unlock(tp); |
| 11387 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 11388 | if (tg3_test_interrupt(tp) != 0) { |
| 11389 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11390 | data[5] = 1; |
| 11391 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11392 | |
| 11393 | tg3_full_lock(tp, 0); |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 11394 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11395 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11396 | if (netif_running(dev)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11397 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11398 | err2 = tg3_restart_hw(tp, 1); |
| 11399 | if (!err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11400 | tg3_netif_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11401 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11402 | |
| 11403 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11404 | |
| 11405 | if (irq_sync && !err2) |
| 11406 | tg3_phy_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11407 | } |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11408 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 11409 | tg3_power_down(tp); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11410 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11411 | } |
| 11412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11413 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 11414 | { |
| 11415 | struct mii_ioctl_data *data = if_mii(ifr); |
| 11416 | struct tg3 *tp = netdev_priv(dev); |
| 11417 | int err; |
| 11418 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11419 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11420 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11421 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11422 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11423 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 11424 | return phy_mii_ioctl(phydev, ifr, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11425 | } |
| 11426 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 11427 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11428 | case SIOCGMIIPHY: |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 11429 | data->phy_id = tp->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11430 | |
| 11431 | /* fallthru */ |
| 11432 | case SIOCGMIIREG: { |
| 11433 | u32 mii_regval; |
| 11434 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11435 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11436 | break; /* We have no PHY */ |
| 11437 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 11438 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11439 | return -EAGAIN; |
| 11440 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11441 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11442 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11443 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11444 | |
| 11445 | data->val_out = mii_regval; |
| 11446 | |
| 11447 | return err; |
| 11448 | } |
| 11449 | |
| 11450 | case SIOCSMIIREG: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11451 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11452 | break; /* We have no PHY */ |
| 11453 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 11454 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11455 | return -EAGAIN; |
| 11456 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11457 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11458 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11459 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11460 | |
| 11461 | return err; |
| 11462 | |
| 11463 | default: |
| 11464 | /* do nothing */ |
| 11465 | break; |
| 11466 | } |
| 11467 | return -EOPNOTSUPP; |
| 11468 | } |
| 11469 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 11470 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 11471 | { |
| 11472 | struct tg3 *tp = netdev_priv(dev); |
| 11473 | |
| 11474 | memcpy(ec, &tp->coal, sizeof(*ec)); |
| 11475 | return 0; |
| 11476 | } |
| 11477 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 11478 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 11479 | { |
| 11480 | struct tg3 *tp = netdev_priv(dev); |
| 11481 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; |
| 11482 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; |
| 11483 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11484 | if (!tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 11485 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
| 11486 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; |
| 11487 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; |
| 11488 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; |
| 11489 | } |
| 11490 | |
| 11491 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || |
| 11492 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || |
| 11493 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || |
| 11494 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || |
| 11495 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || |
| 11496 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || |
| 11497 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || |
| 11498 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || |
| 11499 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || |
| 11500 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) |
| 11501 | return -EINVAL; |
| 11502 | |
| 11503 | /* No rx interrupts will be generated if both are zero */ |
| 11504 | if ((ec->rx_coalesce_usecs == 0) && |
| 11505 | (ec->rx_max_coalesced_frames == 0)) |
| 11506 | return -EINVAL; |
| 11507 | |
| 11508 | /* No tx interrupts will be generated if both are zero */ |
| 11509 | if ((ec->tx_coalesce_usecs == 0) && |
| 11510 | (ec->tx_max_coalesced_frames == 0)) |
| 11511 | return -EINVAL; |
| 11512 | |
| 11513 | /* Only copy relevant parameters, ignore all others. */ |
| 11514 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; |
| 11515 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; |
| 11516 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; |
| 11517 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; |
| 11518 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; |
| 11519 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; |
| 11520 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; |
| 11521 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; |
| 11522 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; |
| 11523 | |
| 11524 | if (netif_running(dev)) { |
| 11525 | tg3_full_lock(tp, 0); |
| 11526 | __tg3_set_coalesce(tp, &tp->coal); |
| 11527 | tg3_full_unlock(tp); |
| 11528 | } |
| 11529 | return 0; |
| 11530 | } |
| 11531 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 11532 | static const struct ethtool_ops tg3_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11533 | .get_settings = tg3_get_settings, |
| 11534 | .set_settings = tg3_set_settings, |
| 11535 | .get_drvinfo = tg3_get_drvinfo, |
| 11536 | .get_regs_len = tg3_get_regs_len, |
| 11537 | .get_regs = tg3_get_regs, |
| 11538 | .get_wol = tg3_get_wol, |
| 11539 | .set_wol = tg3_set_wol, |
| 11540 | .get_msglevel = tg3_get_msglevel, |
| 11541 | .set_msglevel = tg3_set_msglevel, |
| 11542 | .nway_reset = tg3_nway_reset, |
| 11543 | .get_link = ethtool_op_get_link, |
| 11544 | .get_eeprom_len = tg3_get_eeprom_len, |
| 11545 | .get_eeprom = tg3_get_eeprom, |
| 11546 | .set_eeprom = tg3_set_eeprom, |
| 11547 | .get_ringparam = tg3_get_ringparam, |
| 11548 | .set_ringparam = tg3_set_ringparam, |
| 11549 | .get_pauseparam = tg3_get_pauseparam, |
| 11550 | .set_pauseparam = tg3_set_pauseparam, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11551 | .self_test = tg3_self_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11552 | .get_strings = tg3_get_strings, |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11553 | .set_phys_id = tg3_set_phys_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11554 | .get_ethtool_stats = tg3_get_ethtool_stats, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 11555 | .get_coalesce = tg3_get_coalesce, |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 11556 | .set_coalesce = tg3_set_coalesce, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 11557 | .get_sset_count = tg3_get_sset_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11558 | }; |
| 11559 | |
| 11560 | static void __devinit tg3_get_eeprom_size(struct tg3 *tp) |
| 11561 | { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11562 | u32 cursize, val, magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11563 | |
| 11564 | tp->nvram_size = EEPROM_CHIP_SIZE; |
| 11565 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11566 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11567 | return; |
| 11568 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11569 | if ((magic != TG3_EEPROM_MAGIC) && |
| 11570 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && |
| 11571 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11572 | return; |
| 11573 | |
| 11574 | /* |
| 11575 | * Size the chip by reading offsets at increasing powers of two. |
| 11576 | * When we encounter our validation signature, we know the addressing |
| 11577 | * has wrapped around, and thus have our chip size. |
| 11578 | */ |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11579 | cursize = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11580 | |
| 11581 | while (cursize < tp->nvram_size) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11582 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11583 | return; |
| 11584 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 11585 | if (val == magic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11586 | break; |
| 11587 | |
| 11588 | cursize <<= 1; |
| 11589 | } |
| 11590 | |
| 11591 | tp->nvram_size = cursize; |
| 11592 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11594 | static void __devinit tg3_get_nvram_size(struct tg3 *tp) |
| 11595 | { |
| 11596 | u32 val; |
| 11597 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11598 | 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] | 11599 | return; |
| 11600 | |
| 11601 | /* Selfboot format */ |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 11602 | if (val != TG3_EEPROM_MAGIC) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11603 | tg3_get_eeprom_size(tp); |
| 11604 | return; |
| 11605 | } |
| 11606 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 11607 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11608 | if (val != 0) { |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 11609 | /* This is confusing. We want to operate on the |
| 11610 | * 16-bit value at offset 0xf2. The tg3_nvram_read() |
| 11611 | * call will read from NVRAM and byteswap the data |
| 11612 | * according to the byteswapping settings for all |
| 11613 | * other register accesses. This ensures the data we |
| 11614 | * want will always reside in the lower 16-bits. |
| 11615 | * However, the data in NVRAM is in LE format, which |
| 11616 | * means the data from the NVRAM read will always be |
| 11617 | * opposite the endianness of the CPU. The 16-bit |
| 11618 | * byteswap then brings the data to CPU endianness. |
| 11619 | */ |
| 11620 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11621 | return; |
| 11622 | } |
| 11623 | } |
Matt Carlson | fd1122a | 2008-05-02 16:48:36 -0700 | [diff] [blame] | 11624 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11625 | } |
| 11626 | |
| 11627 | static void __devinit tg3_get_nvram_info(struct tg3 *tp) |
| 11628 | { |
| 11629 | u32 nvcfg1; |
| 11630 | |
| 11631 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11632 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11633 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11634 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11635 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11636 | tw32(NVRAM_CFG1, nvcfg1); |
| 11637 | } |
| 11638 | |
Michael Chan | 4c98748 | 2005-09-05 17:52:38 -0700 | [diff] [blame] | 11639 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11640 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11641 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11642 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
| 11643 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11644 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11645 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11646 | break; |
| 11647 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: |
| 11648 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11649 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; |
| 11650 | break; |
| 11651 | case FLASH_VENDOR_ATMEL_EEPROM: |
| 11652 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11653 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11654 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11655 | break; |
| 11656 | case FLASH_VENDOR_ST: |
| 11657 | tp->nvram_jedecnum = JEDEC_ST; |
| 11658 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11659 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11660 | break; |
| 11661 | case FLASH_VENDOR_SAIFUN: |
| 11662 | tp->nvram_jedecnum = JEDEC_SAIFUN; |
| 11663 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; |
| 11664 | break; |
| 11665 | case FLASH_VENDOR_SST_SMALL: |
| 11666 | case FLASH_VENDOR_SST_LARGE: |
| 11667 | tp->nvram_jedecnum = JEDEC_SST; |
| 11668 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; |
| 11669 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11670 | } |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11671 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11672 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11673 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11674 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11675 | } |
| 11676 | } |
| 11677 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11678 | static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
| 11679 | { |
| 11680 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { |
| 11681 | case FLASH_5752PAGE_SIZE_256: |
| 11682 | tp->nvram_pagesize = 256; |
| 11683 | break; |
| 11684 | case FLASH_5752PAGE_SIZE_512: |
| 11685 | tp->nvram_pagesize = 512; |
| 11686 | break; |
| 11687 | case FLASH_5752PAGE_SIZE_1K: |
| 11688 | tp->nvram_pagesize = 1024; |
| 11689 | break; |
| 11690 | case FLASH_5752PAGE_SIZE_2K: |
| 11691 | tp->nvram_pagesize = 2048; |
| 11692 | break; |
| 11693 | case FLASH_5752PAGE_SIZE_4K: |
| 11694 | tp->nvram_pagesize = 4096; |
| 11695 | break; |
| 11696 | case FLASH_5752PAGE_SIZE_264: |
| 11697 | tp->nvram_pagesize = 264; |
| 11698 | break; |
| 11699 | case FLASH_5752PAGE_SIZE_528: |
| 11700 | tp->nvram_pagesize = 528; |
| 11701 | break; |
| 11702 | } |
| 11703 | } |
| 11704 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11705 | static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp) |
| 11706 | { |
| 11707 | u32 nvcfg1; |
| 11708 | |
| 11709 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11710 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11711 | /* NVRAM protection for TPM */ |
| 11712 | if (nvcfg1 & (1 << 27)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11713 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11714 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11715 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11716 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
| 11717 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: |
| 11718 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11719 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11720 | break; |
| 11721 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11722 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11723 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 11724 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11725 | break; |
| 11726 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11727 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11728 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11729 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11730 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 11731 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11732 | break; |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11733 | } |
| 11734 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11735 | if (tg3_flag(tp, FLASH)) { |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11736 | tg3_nvram_get_pagesize(tp, nvcfg1); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11737 | } else { |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11738 | /* For eeprom, set pagesize to maximum eeprom size */ |
| 11739 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11740 | |
| 11741 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11742 | tw32(NVRAM_CFG1, nvcfg1); |
| 11743 | } |
| 11744 | } |
| 11745 | |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11746 | static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp) |
| 11747 | { |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11748 | u32 nvcfg1, protect = 0; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11749 | |
| 11750 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11751 | |
| 11752 | /* NVRAM protection for TPM */ |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11753 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11754 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11755 | protect = 1; |
| 11756 | } |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11757 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11758 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 11759 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11760 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 11761 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 11762 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 11763 | case FLASH_5755VENDOR_ATMEL_FLASH_5: |
| 11764 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11765 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 11766 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11767 | tp->nvram_pagesize = 264; |
| 11768 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || |
| 11769 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) |
| 11770 | tp->nvram_size = (protect ? 0x3e200 : |
| 11771 | TG3_NVRAM_SIZE_512KB); |
| 11772 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) |
| 11773 | tp->nvram_size = (protect ? 0x1f200 : |
| 11774 | TG3_NVRAM_SIZE_256KB); |
| 11775 | else |
| 11776 | tp->nvram_size = (protect ? 0x1f200 : |
| 11777 | TG3_NVRAM_SIZE_128KB); |
| 11778 | break; |
| 11779 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11780 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11781 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11782 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11783 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 11784 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11785 | tp->nvram_pagesize = 256; |
| 11786 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) |
| 11787 | tp->nvram_size = (protect ? |
| 11788 | TG3_NVRAM_SIZE_64KB : |
| 11789 | TG3_NVRAM_SIZE_128KB); |
| 11790 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) |
| 11791 | tp->nvram_size = (protect ? |
| 11792 | TG3_NVRAM_SIZE_64KB : |
| 11793 | TG3_NVRAM_SIZE_256KB); |
| 11794 | else |
| 11795 | tp->nvram_size = (protect ? |
| 11796 | TG3_NVRAM_SIZE_128KB : |
| 11797 | TG3_NVRAM_SIZE_512KB); |
| 11798 | break; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11799 | } |
| 11800 | } |
| 11801 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11802 | static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) |
| 11803 | { |
| 11804 | u32 nvcfg1; |
| 11805 | |
| 11806 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11807 | |
| 11808 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11809 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
| 11810 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 11811 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: |
| 11812 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 11813 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11814 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11815 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11816 | |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11817 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11818 | tw32(NVRAM_CFG1, nvcfg1); |
| 11819 | break; |
| 11820 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11821 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 11822 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 11823 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 11824 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11825 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 11826 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11827 | tp->nvram_pagesize = 264; |
| 11828 | break; |
| 11829 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11830 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11831 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11832 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11833 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 11834 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11835 | tp->nvram_pagesize = 256; |
| 11836 | break; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11837 | } |
| 11838 | } |
| 11839 | |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11840 | static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp) |
| 11841 | { |
| 11842 | u32 nvcfg1, protect = 0; |
| 11843 | |
| 11844 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11845 | |
| 11846 | /* NVRAM protection for TPM */ |
| 11847 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11848 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11849 | protect = 1; |
| 11850 | } |
| 11851 | |
| 11852 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 11853 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11854 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 11855 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 11856 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 11857 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 11858 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 11859 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 11860 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 11861 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 11862 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11863 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 11864 | tg3_flag_set(tp, FLASH); |
| 11865 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11866 | tp->nvram_pagesize = 256; |
| 11867 | break; |
| 11868 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 11869 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 11870 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 11871 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 11872 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 11873 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 11874 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 11875 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 11876 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11877 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 11878 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11879 | tp->nvram_pagesize = 256; |
| 11880 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11881 | } |
| 11882 | |
| 11883 | if (protect) { |
| 11884 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); |
| 11885 | } else { |
| 11886 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11887 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 11888 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 11889 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 11890 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 11891 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; |
| 11892 | break; |
| 11893 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 11894 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 11895 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 11896 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 11897 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 11898 | break; |
| 11899 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 11900 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 11901 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 11902 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 11903 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11904 | break; |
| 11905 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 11906 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 11907 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 11908 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 11909 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11910 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11911 | } |
| 11912 | } |
| 11913 | } |
| 11914 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 11915 | static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp) |
| 11916 | { |
| 11917 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11918 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 11919 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11920 | } |
| 11921 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11922 | static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp) |
| 11923 | { |
| 11924 | u32 nvcfg1; |
| 11925 | |
| 11926 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11927 | |
| 11928 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11929 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 11930 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 11931 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11932 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11933 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11934 | |
| 11935 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11936 | tw32(NVRAM_CFG1, nvcfg1); |
| 11937 | return; |
| 11938 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11939 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 11940 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 11941 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 11942 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 11943 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 11944 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 11945 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11946 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 11947 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11948 | |
| 11949 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11950 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11951 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 11952 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 11953 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11954 | break; |
| 11955 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 11956 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 11957 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11958 | break; |
| 11959 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 11960 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 11961 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11962 | break; |
| 11963 | } |
| 11964 | break; |
| 11965 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11966 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11967 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11968 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11969 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 11970 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11971 | |
| 11972 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11973 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11974 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11975 | break; |
| 11976 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11977 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11978 | break; |
| 11979 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11980 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11981 | break; |
| 11982 | } |
| 11983 | break; |
| 11984 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11985 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11986 | return; |
| 11987 | } |
| 11988 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11989 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 11990 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11991 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11992 | } |
| 11993 | |
| 11994 | |
| 11995 | static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp) |
| 11996 | { |
| 11997 | u32 nvcfg1; |
| 11998 | |
| 11999 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12000 | |
| 12001 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12002 | case FLASH_5717VENDOR_ATMEL_EEPROM: |
| 12003 | case FLASH_5717VENDOR_MICRO_EEPROM: |
| 12004 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12005 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12006 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12007 | |
| 12008 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12009 | tw32(NVRAM_CFG1, nvcfg1); |
| 12010 | return; |
| 12011 | case FLASH_5717VENDOR_ATMEL_MDB011D: |
| 12012 | case FLASH_5717VENDOR_ATMEL_ADB011B: |
| 12013 | case FLASH_5717VENDOR_ATMEL_ADB011D: |
| 12014 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 12015 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 12016 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 12017 | case FLASH_5717VENDOR_ATMEL_45USPT: |
| 12018 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12019 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12020 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12021 | |
| 12022 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12023 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 12024 | /* Detect size with tg3_nvram_get_size() */ |
| 12025 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12026 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 12027 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 12028 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12029 | break; |
| 12030 | default: |
| 12031 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12032 | break; |
| 12033 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12034 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12035 | case FLASH_5717VENDOR_ST_M_M25PE10: |
| 12036 | case FLASH_5717VENDOR_ST_A_M25PE10: |
| 12037 | case FLASH_5717VENDOR_ST_M_M45PE10: |
| 12038 | case FLASH_5717VENDOR_ST_A_M45PE10: |
| 12039 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 12040 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 12041 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 12042 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 12043 | case FLASH_5717VENDOR_ST_25USPT: |
| 12044 | case FLASH_5717VENDOR_ST_45USPT: |
| 12045 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12046 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12047 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12048 | |
| 12049 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12050 | case FLASH_5717VENDOR_ST_M_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12051 | case FLASH_5717VENDOR_ST_M_M45PE20: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 12052 | /* Detect size with tg3_nvram_get_size() */ |
| 12053 | break; |
| 12054 | case FLASH_5717VENDOR_ST_A_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12055 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 12056 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12057 | break; |
| 12058 | default: |
| 12059 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12060 | break; |
| 12061 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12062 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12063 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12064 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12065 | return; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12066 | } |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12067 | |
| 12068 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 12069 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12070 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12071 | } |
| 12072 | |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12073 | static void __devinit tg3_get_5720_nvram_info(struct tg3 *tp) |
| 12074 | { |
| 12075 | u32 nvcfg1, nvmpinstrp; |
| 12076 | |
| 12077 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12078 | nvmpinstrp = nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK; |
| 12079 | |
| 12080 | switch (nvmpinstrp) { |
| 12081 | case FLASH_5720_EEPROM_HD: |
| 12082 | case FLASH_5720_EEPROM_LD: |
| 12083 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12084 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12085 | |
| 12086 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12087 | tw32(NVRAM_CFG1, nvcfg1); |
| 12088 | if (nvmpinstrp == FLASH_5720_EEPROM_HD) |
| 12089 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12090 | else |
| 12091 | tp->nvram_pagesize = ATMEL_AT24C02_CHIP_SIZE; |
| 12092 | return; |
| 12093 | case FLASH_5720VENDOR_M_ATMEL_DB011D: |
| 12094 | case FLASH_5720VENDOR_A_ATMEL_DB011B: |
| 12095 | case FLASH_5720VENDOR_A_ATMEL_DB011D: |
| 12096 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 12097 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 12098 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 12099 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 12100 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 12101 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 12102 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 12103 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 12104 | case FLASH_5720VENDOR_ATMEL_45USPT: |
| 12105 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12106 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12107 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12108 | |
| 12109 | switch (nvmpinstrp) { |
| 12110 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 12111 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 12112 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 12113 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12114 | break; |
| 12115 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 12116 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 12117 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 12118 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12119 | break; |
| 12120 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 12121 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 12122 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 12123 | break; |
| 12124 | default: |
| 12125 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12126 | break; |
| 12127 | } |
| 12128 | break; |
| 12129 | case FLASH_5720VENDOR_M_ST_M25PE10: |
| 12130 | case FLASH_5720VENDOR_M_ST_M45PE10: |
| 12131 | case FLASH_5720VENDOR_A_ST_M25PE10: |
| 12132 | case FLASH_5720VENDOR_A_ST_M45PE10: |
| 12133 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 12134 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 12135 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 12136 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 12137 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 12138 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 12139 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 12140 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 12141 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 12142 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 12143 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 12144 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 12145 | case FLASH_5720VENDOR_ST_25USPT: |
| 12146 | case FLASH_5720VENDOR_ST_45USPT: |
| 12147 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12148 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12149 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12150 | |
| 12151 | switch (nvmpinstrp) { |
| 12152 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 12153 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 12154 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 12155 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 12156 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12157 | break; |
| 12158 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 12159 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 12160 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 12161 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 12162 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12163 | break; |
| 12164 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 12165 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 12166 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 12167 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 12168 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 12169 | break; |
| 12170 | default: |
| 12171 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12172 | break; |
| 12173 | } |
| 12174 | break; |
| 12175 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12176 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12177 | return; |
| 12178 | } |
| 12179 | |
| 12180 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 12181 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12182 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12183 | } |
| 12184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12185 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
| 12186 | static void __devinit tg3_nvram_init(struct tg3 *tp) |
| 12187 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12188 | tw32_f(GRC_EEPROM_ADDR, |
| 12189 | (EEPROM_ADDR_FSM_RESET | |
| 12190 | (EEPROM_DEFAULT_CLOCK_PERIOD << |
| 12191 | EEPROM_ADDR_CLKPERD_SHIFT))); |
| 12192 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 12193 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12194 | |
| 12195 | /* Enable seeprom accesses. */ |
| 12196 | tw32_f(GRC_LOCAL_CTRL, |
| 12197 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); |
| 12198 | udelay(100); |
| 12199 | |
| 12200 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 12201 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12202 | tg3_flag_set(tp, NVRAM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12203 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12204 | if (tg3_nvram_lock(tp)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 12205 | netdev_warn(tp->dev, |
| 12206 | "Cannot get nvram lock, %s failed\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 12207 | __func__); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12208 | return; |
| 12209 | } |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12210 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12211 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 12212 | tp->nvram_size = 0; |
| 12213 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12214 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 12215 | tg3_get_5752_nvram_info(tp); |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 12216 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 12217 | tg3_get_5755_nvram_info(tp); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 12218 | 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] | 12219 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 12220 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12221 | tg3_get_5787_nvram_info(tp); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 12222 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 12223 | tg3_get_5761_nvram_info(tp); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12224 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 12225 | tg3_get_5906_nvram_info(tp); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 12226 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 12227 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12228 | tg3_get_57780_nvram_info(tp); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12229 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 12230 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12231 | tg3_get_5717_nvram_info(tp); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12232 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 12233 | tg3_get_5720_nvram_info(tp); |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12234 | else |
| 12235 | tg3_get_nvram_info(tp); |
| 12236 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 12237 | if (tp->nvram_size == 0) |
| 12238 | tg3_get_nvram_size(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12239 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12240 | tg3_disable_nvram_access(tp); |
Michael Chan | 381291b | 2005-12-13 21:08:21 -0800 | [diff] [blame] | 12241 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12242 | |
| 12243 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12244 | tg3_flag_clear(tp, NVRAM); |
| 12245 | tg3_flag_clear(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12246 | |
| 12247 | tg3_get_eeprom_size(tp); |
| 12248 | } |
| 12249 | } |
| 12250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12251 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
| 12252 | u32 offset, u32 len, u8 *buf) |
| 12253 | { |
| 12254 | int i, j, rc = 0; |
| 12255 | u32 val; |
| 12256 | |
| 12257 | for (i = 0; i < len; i += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12258 | u32 addr; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12259 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12260 | |
| 12261 | addr = offset + i; |
| 12262 | |
| 12263 | memcpy(&data, buf + i, 4); |
| 12264 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 12265 | /* |
| 12266 | * The SEEPROM interface expects the data to always be opposite |
| 12267 | * the native endian format. We accomplish this by reversing |
| 12268 | * all the operations that would have been performed on the |
| 12269 | * data from a call to tg3_nvram_read_be32(). |
| 12270 | */ |
| 12271 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12272 | |
| 12273 | val = tr32(GRC_EEPROM_ADDR); |
| 12274 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); |
| 12275 | |
| 12276 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | |
| 12277 | EEPROM_ADDR_READ); |
| 12278 | tw32(GRC_EEPROM_ADDR, val | |
| 12279 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 12280 | (addr & EEPROM_ADDR_ADDR_MASK) | |
| 12281 | EEPROM_ADDR_START | |
| 12282 | EEPROM_ADDR_WRITE); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12283 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 12284 | for (j = 0; j < 1000; j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12285 | val = tr32(GRC_EEPROM_ADDR); |
| 12286 | |
| 12287 | if (val & EEPROM_ADDR_COMPLETE) |
| 12288 | break; |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 12289 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12290 | } |
| 12291 | if (!(val & EEPROM_ADDR_COMPLETE)) { |
| 12292 | rc = -EBUSY; |
| 12293 | break; |
| 12294 | } |
| 12295 | } |
| 12296 | |
| 12297 | return rc; |
| 12298 | } |
| 12299 | |
| 12300 | /* offset and length are dword aligned */ |
| 12301 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, |
| 12302 | u8 *buf) |
| 12303 | { |
| 12304 | int ret = 0; |
| 12305 | u32 pagesize = tp->nvram_pagesize; |
| 12306 | u32 pagemask = pagesize - 1; |
| 12307 | u32 nvram_cmd; |
| 12308 | u8 *tmp; |
| 12309 | |
| 12310 | tmp = kmalloc(pagesize, GFP_KERNEL); |
| 12311 | if (tmp == NULL) |
| 12312 | return -ENOMEM; |
| 12313 | |
| 12314 | while (len) { |
| 12315 | int j; |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12316 | u32 phy_addr, page_off, size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12317 | |
| 12318 | phy_addr = offset & ~pagemask; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12320 | for (j = 0; j < pagesize; j += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12321 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
| 12322 | (__be32 *) (tmp + j)); |
| 12323 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12324 | break; |
| 12325 | } |
| 12326 | if (ret) |
| 12327 | break; |
| 12328 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12329 | page_off = offset & pagemask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12330 | size = pagesize; |
| 12331 | if (len < size) |
| 12332 | size = len; |
| 12333 | |
| 12334 | len -= size; |
| 12335 | |
| 12336 | memcpy(tmp + page_off, buf, size); |
| 12337 | |
| 12338 | offset = offset + (pagesize - page_off); |
| 12339 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12340 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12341 | |
| 12342 | /* |
| 12343 | * Before we can erase the flash page, we need |
| 12344 | * to issue a special "write enable" command. |
| 12345 | */ |
| 12346 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 12347 | |
| 12348 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 12349 | break; |
| 12350 | |
| 12351 | /* Erase the target page */ |
| 12352 | tw32(NVRAM_ADDR, phy_addr); |
| 12353 | |
| 12354 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | |
| 12355 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; |
| 12356 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12357 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12358 | break; |
| 12359 | |
| 12360 | /* Issue another write enable to start the write. */ |
| 12361 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 12362 | |
| 12363 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 12364 | break; |
| 12365 | |
| 12366 | for (j = 0; j < pagesize; j += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12367 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12368 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12369 | data = *((__be32 *) (tmp + j)); |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12370 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12371 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12372 | |
| 12373 | tw32(NVRAM_ADDR, phy_addr + j); |
| 12374 | |
| 12375 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | |
| 12376 | NVRAM_CMD_WR; |
| 12377 | |
| 12378 | if (j == 0) |
| 12379 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 12380 | else if (j == (pagesize - 4)) |
| 12381 | nvram_cmd |= NVRAM_CMD_LAST; |
| 12382 | |
| 12383 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) |
| 12384 | break; |
| 12385 | } |
| 12386 | if (ret) |
| 12387 | break; |
| 12388 | } |
| 12389 | |
| 12390 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 12391 | tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 12392 | |
| 12393 | kfree(tmp); |
| 12394 | |
| 12395 | return ret; |
| 12396 | } |
| 12397 | |
| 12398 | /* offset and length are dword aligned */ |
| 12399 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, |
| 12400 | u8 *buf) |
| 12401 | { |
| 12402 | int i, ret = 0; |
| 12403 | |
| 12404 | for (i = 0; i < len; i += 4, offset += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12405 | u32 page_off, phy_addr, nvram_cmd; |
| 12406 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12407 | |
| 12408 | memcpy(&data, buf + i, 4); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12409 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12410 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12411 | page_off = offset % tp->nvram_pagesize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12412 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12413 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12414 | |
| 12415 | tw32(NVRAM_ADDR, phy_addr); |
| 12416 | |
| 12417 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
| 12418 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12419 | if (page_off == 0 || i == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12420 | nvram_cmd |= NVRAM_CMD_FIRST; |
Michael Chan | f6d9a25 | 2006-04-29 19:00:24 -0700 | [diff] [blame] | 12421 | if (page_off == (tp->nvram_pagesize - 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12422 | nvram_cmd |= NVRAM_CMD_LAST; |
| 12423 | |
| 12424 | if (i == (len - 4)) |
| 12425 | nvram_cmd |= NVRAM_CMD_LAST; |
| 12426 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12427 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12428 | !tg3_flag(tp, 5755_PLUS) && |
Michael Chan | 4c98748 | 2005-09-05 17:52:38 -0700 | [diff] [blame] | 12429 | (tp->nvram_jedecnum == JEDEC_ST) && |
| 12430 | (nvram_cmd & NVRAM_CMD_FIRST)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12431 | |
| 12432 | if ((ret = tg3_nvram_exec_cmd(tp, |
| 12433 | NVRAM_CMD_WREN | NVRAM_CMD_GO | |
| 12434 | NVRAM_CMD_DONE))) |
| 12435 | |
| 12436 | break; |
| 12437 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12438 | if (!tg3_flag(tp, FLASH)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12439 | /* We always do complete word writes to eeprom. */ |
| 12440 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); |
| 12441 | } |
| 12442 | |
| 12443 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) |
| 12444 | break; |
| 12445 | } |
| 12446 | return ret; |
| 12447 | } |
| 12448 | |
| 12449 | /* offset and length are dword aligned */ |
| 12450 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) |
| 12451 | { |
| 12452 | int ret; |
| 12453 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12454 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 12455 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
| 12456 | ~GRC_LCLCTRL_GPIO_OUTPUT1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12457 | udelay(40); |
| 12458 | } |
| 12459 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12460 | if (!tg3_flag(tp, NVRAM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12461 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 12462 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12463 | u32 grc_mode; |
| 12464 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12465 | ret = tg3_nvram_lock(tp); |
| 12466 | if (ret) |
| 12467 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12468 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12469 | tg3_enable_nvram_access(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12470 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12471 | tw32(NVRAM_WRITE1, 0x406); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12472 | |
| 12473 | grc_mode = tr32(GRC_MODE); |
| 12474 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); |
| 12475 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12476 | if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12477 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
| 12478 | buf); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 12479 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12480 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
| 12481 | buf); |
| 12482 | } |
| 12483 | |
| 12484 | grc_mode = tr32(GRC_MODE); |
| 12485 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); |
| 12486 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12487 | tg3_disable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12488 | tg3_nvram_unlock(tp); |
| 12489 | } |
| 12490 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12491 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 12492 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12493 | udelay(40); |
| 12494 | } |
| 12495 | |
| 12496 | return ret; |
| 12497 | } |
| 12498 | |
| 12499 | struct subsys_tbl_ent { |
| 12500 | u16 subsys_vendor, subsys_devid; |
| 12501 | u32 phy_id; |
| 12502 | }; |
| 12503 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12504 | static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12505 | /* Broadcom boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12506 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12507 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12508 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12509 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12510 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12511 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12512 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 12513 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, |
| 12514 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12515 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12516 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12517 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12518 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 12519 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, |
| 12520 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12521 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12522 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12523 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12524 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12525 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12526 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12527 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12528 | |
| 12529 | /* 3com boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12530 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12531 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12532 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12533 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12534 | { TG3PCI_SUBVENDOR_ID_3COM, |
| 12535 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, |
| 12536 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12537 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12538 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12539 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12540 | |
| 12541 | /* DELL boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12542 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12543 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12544 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12545 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12546 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12547 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12548 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12549 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12550 | |
| 12551 | /* Compaq boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12552 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12553 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12554 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12555 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12556 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 12557 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, |
| 12558 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12559 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12560 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12561 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12562 | |
| 12563 | /* IBM boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12564 | { TG3PCI_SUBVENDOR_ID_IBM, |
| 12565 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12566 | }; |
| 12567 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12568 | 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] | 12569 | { |
| 12570 | int i; |
| 12571 | |
| 12572 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { |
| 12573 | if ((subsys_id_to_phy_id[i].subsys_vendor == |
| 12574 | tp->pdev->subsystem_vendor) && |
| 12575 | (subsys_id_to_phy_id[i].subsys_devid == |
| 12576 | tp->pdev->subsystem_device)) |
| 12577 | return &subsys_id_to_phy_id[i]; |
| 12578 | } |
| 12579 | return NULL; |
| 12580 | } |
| 12581 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12582 | static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12583 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12584 | u32 val; |
Michael Chan | caf636c7 | 2006-03-22 01:05:31 -0800 | [diff] [blame] | 12585 | u16 pmcsr; |
| 12586 | |
| 12587 | /* On some early chips the SRAM cannot be accessed in D3hot state, |
| 12588 | * so need make sure we're in D0. |
| 12589 | */ |
| 12590 | pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr); |
| 12591 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
| 12592 | pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr); |
| 12593 | msleep(1); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12594 | |
| 12595 | /* Make sure register accesses (indirect or otherwise) |
| 12596 | * will function correctly. |
| 12597 | */ |
| 12598 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 12599 | tp->misc_host_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12600 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12601 | /* The memory arbiter has to be enabled in order for SRAM accesses |
| 12602 | * to succeed. Normally on powerup the tg3 chip firmware will make |
| 12603 | * sure it is enabled, but other entities such as system netboot |
| 12604 | * code might disable it. |
| 12605 | */ |
| 12606 | val = tr32(MEMARB_MODE); |
| 12607 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 12608 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12609 | tp->phy_id = TG3_PHY_ID_INVALID; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12610 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12611 | |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 12612 | /* Assume an onboard device and WOL capable by default. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12613 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
| 12614 | tg3_flag_set(tp, WOL_CAP); |
David S. Miller | 72b845e | 2006-03-14 14:11:48 -0800 | [diff] [blame] | 12615 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12616 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12617 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12618 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 12619 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12620 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12621 | val = tr32(VCPU_CFGSHDW); |
| 12622 | if (val & VCPU_CFGSHDW_ASPM_DBNC) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12623 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12624 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 12625 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12626 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 12627 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 12628 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12629 | goto done; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12630 | } |
| 12631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12632 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 12633 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 12634 | u32 nic_cfg, led_cfg; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12635 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12636 | int eeprom_phy_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12637 | |
| 12638 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 12639 | tp->nic_sram_data_cfg = nic_cfg; |
| 12640 | |
| 12641 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); |
| 12642 | ver >>= NIC_SRAM_DATA_VER_SHIFT; |
| 12643 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) && |
| 12644 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) && |
| 12645 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) && |
| 12646 | (ver > 0) && (ver < 0x100)) |
| 12647 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); |
| 12648 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12649 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 12650 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
| 12651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12652 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
| 12653 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) |
| 12654 | eeprom_phy_serdes = 1; |
| 12655 | |
| 12656 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); |
| 12657 | if (nic_phy_id != 0) { |
| 12658 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; |
| 12659 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; |
| 12660 | |
| 12661 | eeprom_phy_id = (id1 >> 16) << 10; |
| 12662 | eeprom_phy_id |= (id2 & 0xfc00) << 16; |
| 12663 | eeprom_phy_id |= (id2 & 0x03ff) << 0; |
| 12664 | } else |
| 12665 | eeprom_phy_id = 0; |
| 12666 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12667 | tp->phy_id = eeprom_phy_id; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 12668 | if (eeprom_phy_serdes) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12669 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12670 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 12671 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12672 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 12673 | } |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12674 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12675 | if (tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12676 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
| 12677 | SHASTA_EXT_LED_MODE_MASK); |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 12678 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12679 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
| 12680 | |
| 12681 | switch (led_cfg) { |
| 12682 | default: |
| 12683 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: |
| 12684 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12685 | break; |
| 12686 | |
| 12687 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: |
| 12688 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 12689 | break; |
| 12690 | |
| 12691 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: |
| 12692 | tp->led_ctrl = LED_CTRL_MODE_MAC; |
Michael Chan | 9ba2779 | 2005-06-06 15:16:20 -0700 | [diff] [blame] | 12693 | |
| 12694 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is |
| 12695 | * read on some older 5700/5701 bootcode. |
| 12696 | */ |
| 12697 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 12698 | ASIC_REV_5700 || |
| 12699 | GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 12700 | ASIC_REV_5701) |
| 12701 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12703 | break; |
| 12704 | |
| 12705 | case SHASTA_EXT_LED_SHARED: |
| 12706 | tp->led_ctrl = LED_CTRL_MODE_SHARED; |
| 12707 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 12708 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) |
| 12709 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 12710 | LED_CTRL_MODE_PHY_2); |
| 12711 | break; |
| 12712 | |
| 12713 | case SHASTA_EXT_LED_MAC: |
| 12714 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; |
| 12715 | break; |
| 12716 | |
| 12717 | case SHASTA_EXT_LED_COMBO: |
| 12718 | tp->led_ctrl = LED_CTRL_MODE_COMBO; |
| 12719 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) |
| 12720 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 12721 | LED_CTRL_MODE_PHY_2); |
| 12722 | break; |
| 12723 | |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 12724 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12725 | |
| 12726 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 12727 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && |
| 12728 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
| 12729 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 12730 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 12731 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
| 12732 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
Matt Carlson | 5f60891 | 2007-11-12 21:17:07 -0800 | [diff] [blame] | 12733 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12734 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12735 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12736 | if ((tp->pdev->subsystem_vendor == |
| 12737 | PCI_VENDOR_ID_ARIMA) && |
| 12738 | (tp->pdev->subsystem_device == 0x205a || |
| 12739 | tp->pdev->subsystem_device == 0x2063)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12740 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12741 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12742 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 12743 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12744 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12745 | |
| 12746 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12747 | tg3_flag_set(tp, ENABLE_ASF); |
| 12748 | if (tg3_flag(tp, 5750_PLUS)) |
| 12749 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12750 | } |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 12751 | |
| 12752 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12753 | tg3_flag(tp, 5750_PLUS)) |
| 12754 | tg3_flag_set(tp, ENABLE_APE); |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 12755 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12756 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 12757 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12758 | tg3_flag_clear(tp, WOL_CAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12759 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12760 | if (tg3_flag(tp, WOL_CAP) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 12761 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12762 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 12763 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 12764 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12766 | if (cfg2 & (1 << 17)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12767 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12768 | |
| 12769 | /* serdes signal pre-emphasis in register 0x590 set by */ |
| 12770 | /* bootcode if bit 18 is set */ |
| 12771 | if (cfg2 & (1 << 18)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12772 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12773 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12774 | if ((tg3_flag(tp, 57765_PLUS) || |
| 12775 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 12776 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) && |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12777 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12778 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12779 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12780 | if (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | 8c69b1e | 2010-08-02 11:26:00 +0000 | [diff] [blame] | 12781 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12782 | !tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12783 | u32 cfg3; |
| 12784 | |
| 12785 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); |
| 12786 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12787 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12788 | } |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12789 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 12790 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12791 | tg3_flag_set(tp, RGMII_INBAND_DISABLE); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12792 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12793 | tg3_flag_set(tp, RGMII_EXT_IBND_RX_EN); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12794 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12795 | tg3_flag_set(tp, RGMII_EXT_IBND_TX_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12796 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12797 | done: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12798 | if (tg3_flag(tp, WOL_CAP)) |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 12799 | device_set_wakeup_enable(&tp->pdev->dev, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12800 | tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 12801 | else |
| 12802 | device_set_wakeup_capable(&tp->pdev->dev, false); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12803 | } |
| 12804 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 12805 | static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
| 12806 | { |
| 12807 | int i; |
| 12808 | u32 val; |
| 12809 | |
| 12810 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); |
| 12811 | tw32(OTP_CTRL, cmd); |
| 12812 | |
| 12813 | /* Wait for up to 1 ms for command to execute. */ |
| 12814 | for (i = 0; i < 100; i++) { |
| 12815 | val = tr32(OTP_STATUS); |
| 12816 | if (val & OTP_STATUS_CMD_DONE) |
| 12817 | break; |
| 12818 | udelay(10); |
| 12819 | } |
| 12820 | |
| 12821 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; |
| 12822 | } |
| 12823 | |
| 12824 | /* Read the gphy configuration from the OTP region of the chip. The gphy |
| 12825 | * configuration is a 32-bit value that straddles the alignment boundary. |
| 12826 | * We do two 32-bit reads and then shift and merge the results. |
| 12827 | */ |
| 12828 | static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp) |
| 12829 | { |
| 12830 | u32 bhalf_otp, thalf_otp; |
| 12831 | |
| 12832 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); |
| 12833 | |
| 12834 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) |
| 12835 | return 0; |
| 12836 | |
| 12837 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); |
| 12838 | |
| 12839 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 12840 | return 0; |
| 12841 | |
| 12842 | thalf_otp = tr32(OTP_READ_DATA); |
| 12843 | |
| 12844 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); |
| 12845 | |
| 12846 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 12847 | return 0; |
| 12848 | |
| 12849 | bhalf_otp = tr32(OTP_READ_DATA); |
| 12850 | |
| 12851 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); |
| 12852 | } |
| 12853 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 12854 | static void __devinit tg3_phy_init_link_config(struct tg3 *tp) |
| 12855 | { |
| 12856 | u32 adv = ADVERTISED_Autoneg | |
| 12857 | ADVERTISED_Pause; |
| 12858 | |
| 12859 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
| 12860 | adv |= ADVERTISED_1000baseT_Half | |
| 12861 | ADVERTISED_1000baseT_Full; |
| 12862 | |
| 12863 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 12864 | adv |= ADVERTISED_100baseT_Half | |
| 12865 | ADVERTISED_100baseT_Full | |
| 12866 | ADVERTISED_10baseT_Half | |
| 12867 | ADVERTISED_10baseT_Full | |
| 12868 | ADVERTISED_TP; |
| 12869 | else |
| 12870 | adv |= ADVERTISED_FIBRE; |
| 12871 | |
| 12872 | tp->link_config.advertising = adv; |
| 12873 | tp->link_config.speed = SPEED_INVALID; |
| 12874 | tp->link_config.duplex = DUPLEX_INVALID; |
| 12875 | tp->link_config.autoneg = AUTONEG_ENABLE; |
| 12876 | tp->link_config.active_speed = SPEED_INVALID; |
| 12877 | tp->link_config.active_duplex = DUPLEX_INVALID; |
| 12878 | tp->link_config.orig_speed = SPEED_INVALID; |
| 12879 | tp->link_config.orig_duplex = DUPLEX_INVALID; |
| 12880 | tp->link_config.orig_autoneg = AUTONEG_INVALID; |
| 12881 | } |
| 12882 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12883 | static int __devinit tg3_phy_probe(struct tg3 *tp) |
| 12884 | { |
| 12885 | u32 hw_phy_id_1, hw_phy_id_2; |
| 12886 | u32 hw_phy_id, hw_phy_id_masked; |
| 12887 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12888 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 12889 | /* flow control autonegotiation is default behavior */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12890 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 12891 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 12892 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12893 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12894 | return tg3_phy_init(tp); |
| 12895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12896 | /* Reading the PHY ID register can conflict with ASF |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 12897 | * firmware access to the PHY hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12898 | */ |
| 12899 | err = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12900 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12901 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12902 | } else { |
| 12903 | /* Now read the physical PHY_ID from the chip and verify |
| 12904 | * that it is sane. If it doesn't look good, we fall back |
| 12905 | * to either the hard-coded table based PHY_ID and failing |
| 12906 | * that the value found in the eeprom area. |
| 12907 | */ |
| 12908 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); |
| 12909 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); |
| 12910 | |
| 12911 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; |
| 12912 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; |
| 12913 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; |
| 12914 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12915 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12916 | } |
| 12917 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12918 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12919 | tp->phy_id = hw_phy_id; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12920 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12921 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Michael Chan | da6b2d0 | 2005-08-19 12:54:29 -0700 | [diff] [blame] | 12922 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12923 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12924 | } else { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12925 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12926 | /* Do nothing, phy ID already set up in |
| 12927 | * tg3_get_eeprom_hw_cfg(). |
| 12928 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12929 | } else { |
| 12930 | struct subsys_tbl_ent *p; |
| 12931 | |
| 12932 | /* No eeprom signature? Try the hardcoded |
| 12933 | * subsys device table. |
| 12934 | */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12935 | p = tg3_lookup_by_subsys(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12936 | if (!p) |
| 12937 | return -ENODEV; |
| 12938 | |
| 12939 | tp->phy_id = p->phy_id; |
| 12940 | if (!tp->phy_id || |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12941 | tp->phy_id == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12942 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12943 | } |
| 12944 | } |
| 12945 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 12946 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
| 12947 | ((tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 && |
| 12948 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) || |
| 12949 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 12950 | tp->pci_chip_rev_id != CHIPREV_ID_57765_A0))) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 12951 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 12952 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 12953 | tg3_phy_init_link_config(tp); |
| 12954 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12955 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12956 | !tg3_flag(tp, ENABLE_APE) && |
| 12957 | !tg3_flag(tp, ENABLE_ASF)) { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 12958 | u32 bmsr, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12959 | |
| 12960 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 12961 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 12962 | (bmsr & BMSR_LSTATUS)) |
| 12963 | goto skip_phy_reset; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12965 | err = tg3_phy_reset(tp); |
| 12966 | if (err) |
| 12967 | return err; |
| 12968 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 12969 | tg3_phy_set_wirespeed(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12970 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 12971 | mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 12972 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 12973 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full); |
| 12974 | if (!tg3_copper_is_advertising_all(tp, mask)) { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 12975 | tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, |
| 12976 | tp->link_config.flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12977 | |
| 12978 | tg3_writephy(tp, MII_BMCR, |
| 12979 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 12980 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12981 | } |
| 12982 | |
| 12983 | skip_phy_reset: |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12984 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12985 | err = tg3_init_5401phy_dsp(tp); |
| 12986 | if (err) |
| 12987 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12989 | err = tg3_init_5401phy_dsp(tp); |
| 12990 | } |
| 12991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12992 | return err; |
| 12993 | } |
| 12994 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 12995 | static void __devinit tg3_read_vpd(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12996 | { |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 12997 | u8 *vpd_data; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12998 | unsigned int block_end, rosize, len; |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 12999 | int j, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13000 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 13001 | vpd_data = (u8 *)tg3_vpd_readblock(tp); |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13002 | if (!vpd_data) |
| 13003 | goto out_no_vpd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13004 | |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13005 | i = pci_vpd_find_tag(vpd_data, 0, TG3_NVM_VPD_LEN, |
| 13006 | PCI_VPD_LRDT_RO_DATA); |
| 13007 | if (i < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13008 | goto out_not_found; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13009 | |
| 13010 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
| 13011 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; |
| 13012 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 13013 | |
| 13014 | if (block_end > TG3_NVM_VPD_LEN) |
| 13015 | goto out_not_found; |
| 13016 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13017 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 13018 | PCI_VPD_RO_KEYWORD_MFR_ID); |
| 13019 | if (j > 0) { |
| 13020 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 13021 | |
| 13022 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 13023 | if (j + len > block_end || len != 4 || |
| 13024 | memcmp(&vpd_data[j], "1028", 4)) |
| 13025 | goto partno; |
| 13026 | |
| 13027 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 13028 | PCI_VPD_RO_KEYWORD_VENDOR0); |
| 13029 | if (j < 0) |
| 13030 | goto partno; |
| 13031 | |
| 13032 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 13033 | |
| 13034 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 13035 | if (j + len > block_end) |
| 13036 | goto partno; |
| 13037 | |
| 13038 | memcpy(tp->fw_ver, &vpd_data[j], len); |
| 13039 | strncat(tp->fw_ver, " bc ", TG3_NVM_VPD_LEN - len - 1); |
| 13040 | } |
| 13041 | |
| 13042 | partno: |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13043 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 13044 | PCI_VPD_RO_KEYWORD_PARTNO); |
| 13045 | if (i < 0) |
| 13046 | goto out_not_found; |
| 13047 | |
| 13048 | len = pci_vpd_info_field_size(&vpd_data[i]); |
| 13049 | |
| 13050 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 13051 | if (len > TG3_BPN_SIZE || |
| 13052 | (len + i) > TG3_NVM_VPD_LEN) |
| 13053 | goto out_not_found; |
| 13054 | |
| 13055 | memcpy(tp->board_part_number, &vpd_data[i], len); |
| 13056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13057 | out_not_found: |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13058 | kfree(vpd_data); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13059 | if (tp->board_part_number[0]) |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13060 | return; |
| 13061 | |
| 13062 | out_no_vpd: |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13063 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 13064 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717) |
| 13065 | strcpy(tp->board_part_number, "BCM5717"); |
| 13066 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) |
| 13067 | strcpy(tp->board_part_number, "BCM5718"); |
| 13068 | else |
| 13069 | goto nomatch; |
| 13070 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 13071 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
| 13072 | strcpy(tp->board_part_number, "BCM57780"); |
| 13073 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) |
| 13074 | strcpy(tp->board_part_number, "BCM57760"); |
| 13075 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) |
| 13076 | strcpy(tp->board_part_number, "BCM57790"); |
| 13077 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) |
| 13078 | strcpy(tp->board_part_number, "BCM57788"); |
| 13079 | else |
| 13080 | goto nomatch; |
| 13081 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
| 13082 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
| 13083 | strcpy(tp->board_part_number, "BCM57761"); |
| 13084 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) |
| 13085 | strcpy(tp->board_part_number, "BCM57765"); |
| 13086 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) |
| 13087 | strcpy(tp->board_part_number, "BCM57781"); |
| 13088 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) |
| 13089 | strcpy(tp->board_part_number, "BCM57785"); |
| 13090 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) |
| 13091 | strcpy(tp->board_part_number, "BCM57791"); |
| 13092 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 13093 | strcpy(tp->board_part_number, "BCM57795"); |
| 13094 | else |
| 13095 | goto nomatch; |
| 13096 | } 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] | 13097 | strcpy(tp->board_part_number, "BCM95906"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13098 | } else { |
| 13099 | nomatch: |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13100 | strcpy(tp->board_part_number, "none"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13102 | } |
| 13103 | |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13104 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
| 13105 | { |
| 13106 | u32 val; |
| 13107 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13108 | if (tg3_nvram_read(tp, offset, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13109 | (val & 0xfc000000) != 0x0c000000 || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13110 | tg3_nvram_read(tp, offset + 4, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13111 | val != 0) |
| 13112 | return 0; |
| 13113 | |
| 13114 | return 1; |
| 13115 | } |
| 13116 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13117 | static void __devinit tg3_read_bc_ver(struct tg3 *tp) |
| 13118 | { |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13119 | u32 val, offset, start, ver_offset; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13120 | int i, dst_off; |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13121 | bool newver = false; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13122 | |
| 13123 | if (tg3_nvram_read(tp, 0xc, &offset) || |
| 13124 | tg3_nvram_read(tp, 0x4, &start)) |
| 13125 | return; |
| 13126 | |
| 13127 | offset = tg3_nvram_logical_addr(tp, offset); |
| 13128 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13129 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13130 | return; |
| 13131 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13132 | if ((val & 0xfc000000) == 0x0c000000) { |
| 13133 | if (tg3_nvram_read(tp, offset + 4, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13134 | return; |
| 13135 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13136 | if (val == 0) |
| 13137 | newver = true; |
| 13138 | } |
| 13139 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13140 | dst_off = strlen(tp->fw_ver); |
| 13141 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13142 | if (newver) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13143 | if (TG3_VER_SIZE - dst_off < 16 || |
| 13144 | tg3_nvram_read(tp, offset + 8, &ver_offset)) |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13145 | return; |
| 13146 | |
| 13147 | offset = offset + ver_offset - start; |
| 13148 | for (i = 0; i < 16; i += 4) { |
| 13149 | __be32 v; |
| 13150 | if (tg3_nvram_read_be32(tp, offset + i, &v)) |
| 13151 | return; |
| 13152 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13153 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13154 | } |
| 13155 | } else { |
| 13156 | u32 major, minor; |
| 13157 | |
| 13158 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) |
| 13159 | return; |
| 13160 | |
| 13161 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> |
| 13162 | TG3_NVM_BCVER_MAJSFT; |
| 13163 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13164 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
| 13165 | "v%d.%02d", major, minor); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13166 | } |
| 13167 | } |
| 13168 | |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 13169 | static void __devinit tg3_read_hwsb_ver(struct tg3 *tp) |
| 13170 | { |
| 13171 | u32 val, major, minor; |
| 13172 | |
| 13173 | /* Use native endian representation */ |
| 13174 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) |
| 13175 | return; |
| 13176 | |
| 13177 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> |
| 13178 | TG3_NVM_HWSB_CFG1_MAJSFT; |
| 13179 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> |
| 13180 | TG3_NVM_HWSB_CFG1_MINSFT; |
| 13181 | |
| 13182 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); |
| 13183 | } |
| 13184 | |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13185 | static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val) |
| 13186 | { |
| 13187 | u32 offset, major, minor, build; |
| 13188 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13189 | 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] | 13190 | |
| 13191 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) |
| 13192 | return; |
| 13193 | |
| 13194 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { |
| 13195 | case TG3_EEPROM_SB_REVISION_0: |
| 13196 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; |
| 13197 | break; |
| 13198 | case TG3_EEPROM_SB_REVISION_2: |
| 13199 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; |
| 13200 | break; |
| 13201 | case TG3_EEPROM_SB_REVISION_3: |
| 13202 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; |
| 13203 | break; |
Matt Carlson | a4153d4 | 2010-02-17 15:16:56 +0000 | [diff] [blame] | 13204 | case TG3_EEPROM_SB_REVISION_4: |
| 13205 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; |
| 13206 | break; |
| 13207 | case TG3_EEPROM_SB_REVISION_5: |
| 13208 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; |
| 13209 | break; |
Matt Carlson | bba226a | 2010-10-14 10:37:38 +0000 | [diff] [blame] | 13210 | case TG3_EEPROM_SB_REVISION_6: |
| 13211 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; |
| 13212 | break; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13213 | default: |
| 13214 | return; |
| 13215 | } |
| 13216 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13217 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13218 | return; |
| 13219 | |
| 13220 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> |
| 13221 | TG3_EEPROM_SB_EDH_BLD_SHFT; |
| 13222 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> |
| 13223 | TG3_EEPROM_SB_EDH_MAJ_SHFT; |
| 13224 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; |
| 13225 | |
| 13226 | if (minor > 99 || build > 26) |
| 13227 | return; |
| 13228 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13229 | offset = strlen(tp->fw_ver); |
| 13230 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, |
| 13231 | " v%d.%02d", major, minor); |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13232 | |
| 13233 | if (build > 0) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13234 | offset = strlen(tp->fw_ver); |
| 13235 | if (offset < TG3_VER_SIZE - 1) |
| 13236 | tp->fw_ver[offset] = 'a' + build - 1; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13237 | } |
| 13238 | } |
| 13239 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13240 | static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp) |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13241 | { |
| 13242 | u32 val, offset, start; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13243 | int i, vlen; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13244 | |
| 13245 | for (offset = TG3_NVM_DIR_START; |
| 13246 | offset < TG3_NVM_DIR_END; |
| 13247 | offset += TG3_NVM_DIRENT_SIZE) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13248 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13249 | return; |
| 13250 | |
| 13251 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
| 13252 | break; |
| 13253 | } |
| 13254 | |
| 13255 | if (offset == TG3_NVM_DIR_END) |
| 13256 | return; |
| 13257 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13258 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13259 | start = 0x08000000; |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13260 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13261 | return; |
| 13262 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13263 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13264 | !tg3_fw_img_is_valid(tp, offset) || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13265 | tg3_nvram_read(tp, offset + 8, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13266 | return; |
| 13267 | |
| 13268 | offset += val - start; |
| 13269 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13270 | vlen = strlen(tp->fw_ver); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13271 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13272 | tp->fw_ver[vlen++] = ','; |
| 13273 | tp->fw_ver[vlen++] = ' '; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13274 | |
| 13275 | for (i = 0; i < 4; i++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 13276 | __be32 v; |
| 13277 | if (tg3_nvram_read_be32(tp, offset, &v)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13278 | return; |
| 13279 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 13280 | offset += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13281 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13282 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
| 13283 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13284 | break; |
| 13285 | } |
| 13286 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13287 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
| 13288 | vlen += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13289 | } |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13290 | } |
| 13291 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13292 | static void __devinit tg3_read_dash_ver(struct tg3 *tp) |
| 13293 | { |
| 13294 | int vlen; |
| 13295 | u32 apedata; |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13296 | char *fwtype; |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13297 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13298 | if (!tg3_flag(tp, ENABLE_APE) || !tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13299 | return; |
| 13300 | |
| 13301 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 13302 | if (apedata != APE_SEG_SIG_MAGIC) |
| 13303 | return; |
| 13304 | |
| 13305 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 13306 | if (!(apedata & APE_FW_STATUS_READY)) |
| 13307 | return; |
| 13308 | |
| 13309 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
| 13310 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13311 | 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] | 13312 | tg3_flag_set(tp, APE_HAS_NCSI); |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13313 | fwtype = "NCSI"; |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13314 | } else { |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13315 | fwtype = "DASH"; |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13316 | } |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13317 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13318 | vlen = strlen(tp->fw_ver); |
| 13319 | |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13320 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
| 13321 | fwtype, |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13322 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
| 13323 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, |
| 13324 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, |
| 13325 | (apedata & APE_FW_VERSION_BLDMSK)); |
| 13326 | } |
| 13327 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13328 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
| 13329 | { |
| 13330 | u32 val; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13331 | bool vpd_vers = false; |
| 13332 | |
| 13333 | if (tp->fw_ver[0] != 0) |
| 13334 | vpd_vers = true; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13335 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13336 | if (tg3_flag(tp, NO_NVRAM)) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13337 | strcat(tp->fw_ver, "sb"); |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 13338 | return; |
| 13339 | } |
| 13340 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13341 | if (tg3_nvram_read(tp, 0, &val)) |
| 13342 | return; |
| 13343 | |
| 13344 | if (val == TG3_EEPROM_MAGIC) |
| 13345 | tg3_read_bc_ver(tp); |
| 13346 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) |
| 13347 | tg3_read_sb_ver(tp, val); |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 13348 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 13349 | tg3_read_hwsb_ver(tp); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13350 | else |
| 13351 | return; |
| 13352 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13353 | if (!tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE) || vpd_vers) |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13354 | goto done; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13355 | |
| 13356 | tg3_read_mgmtfw_ver(tp); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13357 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13358 | done: |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13359 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13360 | } |
| 13361 | |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13362 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *); |
| 13363 | |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13364 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
| 13365 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13366 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 13367 | return TG3_RX_RET_MAX_SIZE_5717; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13368 | else if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 13369 | return TG3_RX_RET_MAX_SIZE_5700; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13370 | else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 13371 | return TG3_RX_RET_MAX_SIZE_5705; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13372 | } |
| 13373 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 13374 | static DEFINE_PCI_DEVICE_TABLE(tg3_write_reorder_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 13375 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
| 13376 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
| 13377 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8385_0) }, |
| 13378 | { }, |
| 13379 | }; |
| 13380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13381 | static int __devinit tg3_get_invariants(struct tg3 *tp) |
| 13382 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13383 | u32 misc_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13384 | u32 pci_state_reg, grc_misc_cfg; |
| 13385 | u32 val; |
| 13386 | u16 pci_cmd; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13387 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13389 | /* Force memory write invalidate off. If we leave it on, |
| 13390 | * then on 5700_BX chips we have to enable a workaround. |
| 13391 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary |
| 13392 | * to match the cacheline size. The Broadcom driver have this |
| 13393 | * workaround but turns MWI off all the times so never uses |
| 13394 | * it. This seems to suggest that the workaround is insufficient. |
| 13395 | */ |
| 13396 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13397 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; |
| 13398 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13399 | |
| 13400 | /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL |
| 13401 | * has the register indirect write enable bit set before |
| 13402 | * we try to access any of the MMIO registers. It is also |
| 13403 | * critical that the PCI-X hw workaround situation is decided |
| 13404 | * before that as well. |
| 13405 | */ |
| 13406 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 13407 | &misc_ctrl_reg); |
| 13408 | |
| 13409 | tp->pci_chip_rev_id = (misc_ctrl_reg >> |
| 13410 | MISC_HOST_CTRL_CHIPREV_SHIFT); |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 13411 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
| 13412 | u32 prod_id_asic_rev; |
| 13413 | |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 13414 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 13415 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 13416 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
| 13417 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13418 | pci_read_config_dword(tp->pdev, |
| 13419 | TG3PCI_GEN2_PRODID_ASICREV, |
| 13420 | &prod_id_asic_rev); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13421 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
| 13422 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || |
| 13423 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || |
| 13424 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || |
| 13425 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 13426 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 13427 | pci_read_config_dword(tp->pdev, |
| 13428 | TG3PCI_GEN15_PRODID_ASICREV, |
| 13429 | &prod_id_asic_rev); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13430 | else |
| 13431 | pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV, |
| 13432 | &prod_id_asic_rev); |
| 13433 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13434 | tp->pci_chip_rev_id = prod_id_asic_rev; |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 13435 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13436 | |
Michael Chan | ff645be | 2005-04-21 17:09:53 -0700 | [diff] [blame] | 13437 | /* Wrong chip ID in 5752 A0. This code can be removed later |
| 13438 | * as A0 is not in production. |
| 13439 | */ |
| 13440 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) |
| 13441 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
| 13442 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13443 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
| 13444 | * we need to disable memory and use config. cycles |
| 13445 | * only to access all registers. The 5702/03 chips |
| 13446 | * can mistakenly decode the special cycles from the |
| 13447 | * ICH chipsets as memory write cycles, causing corruption |
| 13448 | * of register and memory space. Only certain ICH bridges |
| 13449 | * will drive special cycles with non-zero data during the |
| 13450 | * address phase which can fall within the 5703's address |
| 13451 | * range. This is not an ICH bug as the PCI spec allows |
| 13452 | * non-zero address during special cycles. However, only |
| 13453 | * these ICH bridges are known to drive non-zero addresses |
| 13454 | * during special cycles. |
| 13455 | * |
| 13456 | * Since special cycles do not cross PCI bridges, we only |
| 13457 | * enable this workaround if the 5703 is on the secondary |
| 13458 | * bus of these ICH bridges. |
| 13459 | */ |
| 13460 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || |
| 13461 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { |
| 13462 | static struct tg3_dev_id { |
| 13463 | u32 vendor; |
| 13464 | u32 device; |
| 13465 | u32 rev; |
| 13466 | } ich_chipsets[] = { |
| 13467 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, |
| 13468 | PCI_ANY_ID }, |
| 13469 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, |
| 13470 | PCI_ANY_ID }, |
| 13471 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, |
| 13472 | 0xa }, |
| 13473 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, |
| 13474 | PCI_ANY_ID }, |
| 13475 | { }, |
| 13476 | }; |
| 13477 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; |
| 13478 | struct pci_dev *bridge = NULL; |
| 13479 | |
| 13480 | while (pci_id->vendor != 0) { |
| 13481 | bridge = pci_get_device(pci_id->vendor, pci_id->device, |
| 13482 | bridge); |
| 13483 | if (!bridge) { |
| 13484 | pci_id++; |
| 13485 | continue; |
| 13486 | } |
| 13487 | if (pci_id->rev != PCI_ANY_ID) { |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 13488 | if (bridge->revision > pci_id->rev) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13489 | continue; |
| 13490 | } |
| 13491 | if (bridge->subordinate && |
| 13492 | (bridge->subordinate->number == |
| 13493 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13494 | tg3_flag_set(tp, ICH_WORKAROUND); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13495 | pci_dev_put(bridge); |
| 13496 | break; |
| 13497 | } |
| 13498 | } |
| 13499 | } |
| 13500 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 13501 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 13502 | static struct tg3_dev_id { |
| 13503 | u32 vendor; |
| 13504 | u32 device; |
| 13505 | } bridge_chipsets[] = { |
| 13506 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, |
| 13507 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, |
| 13508 | { }, |
| 13509 | }; |
| 13510 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; |
| 13511 | struct pci_dev *bridge = NULL; |
| 13512 | |
| 13513 | while (pci_id->vendor != 0) { |
| 13514 | bridge = pci_get_device(pci_id->vendor, |
| 13515 | pci_id->device, |
| 13516 | bridge); |
| 13517 | if (!bridge) { |
| 13518 | pci_id++; |
| 13519 | continue; |
| 13520 | } |
| 13521 | if (bridge->subordinate && |
| 13522 | (bridge->subordinate->number <= |
| 13523 | tp->pdev->bus->number) && |
| 13524 | (bridge->subordinate->subordinate >= |
| 13525 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13526 | tg3_flag_set(tp, 5701_DMA_BUG); |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 13527 | pci_dev_put(bridge); |
| 13528 | break; |
| 13529 | } |
| 13530 | } |
| 13531 | } |
| 13532 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13533 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
| 13534 | * DMA addresses > 40-bit. This bridge may have other additional |
| 13535 | * 57xx devices behind it in some 4-port NIC designs for example. |
| 13536 | * Any tg3 device found behind the bridge will also need the 40-bit |
| 13537 | * DMA workaround. |
| 13538 | */ |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13539 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
| 13540 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13541 | tg3_flag_set(tp, 5780_CLASS); |
| 13542 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 13543 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 13544 | } else { |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13545 | struct pci_dev *bridge = NULL; |
| 13546 | |
| 13547 | do { |
| 13548 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, |
| 13549 | PCI_DEVICE_ID_SERVERWORKS_EPB, |
| 13550 | bridge); |
| 13551 | if (bridge && bridge->subordinate && |
| 13552 | (bridge->subordinate->number <= |
| 13553 | tp->pdev->bus->number) && |
| 13554 | (bridge->subordinate->subordinate >= |
| 13555 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13556 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13557 | pci_dev_put(bridge); |
| 13558 | break; |
| 13559 | } |
| 13560 | } while (bridge); |
| 13561 | } |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 13562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13563 | /* Initialize misc host control in PCI block. */ |
| 13564 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
| 13565 | MISC_HOST_CTRL_CHIPREV); |
| 13566 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 13567 | tp->misc_host_ctrl); |
| 13568 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13569 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 13570 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 13571 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13572 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13573 | tp->pdev_peer = tg3_find_peer(tp); |
| 13574 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13575 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 13576 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 13577 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13578 | tg3_flag_set(tp, 5717_PLUS); |
Matt Carlson | 0a58d66 | 2011-04-05 14:22:45 +0000 | [diff] [blame] | 13579 | |
| 13580 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13581 | tg3_flag(tp, 5717_PLUS)) |
| 13582 | tg3_flag_set(tp, 57765_PLUS); |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13583 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13584 | /* Intentionally exclude ASIC_REV_5906 */ |
| 13585 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 13586 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13587 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13588 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13589 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13590 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13591 | tg3_flag(tp, 57765_PLUS)) |
| 13592 | tg3_flag_set(tp, 5755_PLUS); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13593 | |
| 13594 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 13595 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13596 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13597 | tg3_flag(tp, 5755_PLUS) || |
| 13598 | tg3_flag(tp, 5780_CLASS)) |
| 13599 | tg3_flag_set(tp, 5750_PLUS); |
John W. Linville | 6708e5c | 2005-04-21 17:00:52 -0700 | [diff] [blame] | 13600 | |
John W. Linville | 1b440c56 | 2005-04-21 17:03:18 -0700 | [diff] [blame] | 13601 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13602 | tg3_flag(tp, 5750_PLUS)) |
| 13603 | tg3_flag_set(tp, 5705_PLUS); |
John W. Linville | 1b440c56 | 2005-04-21 17:03:18 -0700 | [diff] [blame] | 13604 | |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13605 | /* 5700 B0 chips do not support checksumming correctly due |
| 13606 | * to hardware bugs. |
| 13607 | */ |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 13608 | if (tp->pci_chip_rev_id != CHIPREV_ID_5700_B0) { |
| 13609 | u32 features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 13610 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13611 | if (tg3_flag(tp, 5755_PLUS)) |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 13612 | features |= NETIF_F_IPV6_CSUM; |
| 13613 | tp->dev->features |= features; |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 13614 | tp->dev->hw_features |= features; |
| 13615 | tp->dev->vlan_features |= features; |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13616 | } |
| 13617 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13618 | /* Determine TSO capabilities */ |
Matt Carlson | 2866d95 | 2011-02-10 20:06:46 -0800 | [diff] [blame] | 13619 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | 4d163b7 | 2011-01-25 15:58:48 +0000 | [diff] [blame] | 13620 | ; /* Do nothing. HW bug. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13621 | else if (tg3_flag(tp, 57765_PLUS)) |
| 13622 | tg3_flag_set(tp, HW_TSO_3); |
| 13623 | else if (tg3_flag(tp, 5755_PLUS) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 13624 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13625 | tg3_flag_set(tp, HW_TSO_2); |
| 13626 | else if (tg3_flag(tp, 5750_PLUS)) { |
| 13627 | tg3_flag_set(tp, HW_TSO_1); |
| 13628 | tg3_flag_set(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13629 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && |
| 13630 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13631 | tg3_flag_clear(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13632 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13633 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 13634 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13635 | tg3_flag_set(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13636 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) |
| 13637 | tp->fw_needed = FIRMWARE_TG3TSO5; |
| 13638 | else |
| 13639 | tp->fw_needed = FIRMWARE_TG3TSO; |
| 13640 | } |
| 13641 | |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame^] | 13642 | /* Selectively allow TSO based on operating conditions */ |
| 13643 | if ((tg3_flag(tp, HW_TSO_1) || |
| 13644 | tg3_flag(tp, HW_TSO_2) || |
| 13645 | tg3_flag(tp, HW_TSO_3)) || |
| 13646 | (tp->fw_needed && !tg3_flag(tp, ENABLE_ASF))) |
| 13647 | tg3_flag_set(tp, TSO_CAPABLE); |
| 13648 | else { |
| 13649 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 13650 | tg3_flag_clear(tp, TSO_BUG); |
| 13651 | tp->fw_needed = NULL; |
| 13652 | } |
| 13653 | |
| 13654 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) |
| 13655 | tp->fw_needed = FIRMWARE_TG3; |
| 13656 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13657 | tp->irq_max = 1; |
| 13658 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13659 | if (tg3_flag(tp, 5750_PLUS)) { |
| 13660 | tg3_flag_set(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13661 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || |
| 13662 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || |
| 13663 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && |
| 13664 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && |
| 13665 | tp->pdev_peer == tp->pdev)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13666 | tg3_flag_clear(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13667 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13668 | if (tg3_flag(tp, 5755_PLUS) || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13669 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13670 | tg3_flag_set(tp, 1SHOT_MSI); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 13671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13672 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13673 | if (tg3_flag(tp, 57765_PLUS)) { |
| 13674 | tg3_flag_set(tp, SUPPORT_MSIX); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13675 | tp->irq_max = TG3_IRQ_MAX_VECS; |
| 13676 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13677 | } |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 13678 | |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 13679 | /* All chips can get confused if TX buffers |
| 13680 | * straddle the 4GB address boundary. |
| 13681 | */ |
| 13682 | tg3_flag_set(tp, 4G_DMA_BNDRY_BUG); |
| 13683 | |
| 13684 | if (tg3_flag(tp, 5755_PLUS)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13685 | tg3_flag_set(tp, SHORT_DMA_BUG); |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 13686 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13687 | tg3_flag_set(tp, 40BIT_DMA_LIMIT_BUG); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13688 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13689 | if (tg3_flag(tp, 5717_PLUS)) |
| 13690 | tg3_flag_set(tp, LRG_PROD_RING_CAP); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 13691 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13692 | if (tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | 2866d95 | 2011-02-10 20:06:46 -0800 | [diff] [blame] | 13693 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5719) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13694 | tg3_flag_set(tp, USE_JUMBO_BDFLAG); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13695 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13696 | if (!tg3_flag(tp, 5705_PLUS) || |
| 13697 | tg3_flag(tp, 5780_CLASS) || |
| 13698 | tg3_flag(tp, USE_JUMBO_BDFLAG)) |
| 13699 | tg3_flag_set(tp, JUMBO_CAPABLE); |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 13700 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13701 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13702 | &pci_state_reg); |
| 13703 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13704 | tp->pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP); |
| 13705 | if (tp->pcie_cap != 0) { |
| 13706 | u16 lnkctl; |
| 13707 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13708 | tg3_flag_set(tp, PCI_EXPRESS); |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 13709 | |
Matt Carlson | cf79003 | 2010-11-24 08:31:48 +0000 | [diff] [blame] | 13710 | tp->pcie_readrq = 4096; |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 13711 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 13712 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
Matt Carlson | b4495ed | 2011-01-25 15:58:47 +0000 | [diff] [blame] | 13713 | tp->pcie_readrq = 2048; |
Matt Carlson | cf79003 | 2010-11-24 08:31:48 +0000 | [diff] [blame] | 13714 | |
| 13715 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 13716 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13717 | pci_read_config_word(tp->pdev, |
| 13718 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 13719 | &lnkctl); |
| 13720 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
| 13721 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13722 | tg3_flag_clear(tp, HW_TSO_2); |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame^] | 13723 | tg3_flag_clear(tp, TSO_CAPABLE); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13724 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13725 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 9cf74eb | 2009-04-20 06:58:27 +0000 | [diff] [blame] | 13726 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
| 13727 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13728 | tg3_flag_set(tp, CLKREQ_BUG); |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 13729 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13730 | tg3_flag_set(tp, L1PLLPD_EN); |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 13731 | } |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13732 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13733 | tg3_flag_set(tp, PCI_EXPRESS); |
| 13734 | } else if (!tg3_flag(tp, 5705_PLUS) || |
| 13735 | tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13736 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
| 13737 | if (!tp->pcix_cap) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 13738 | dev_err(&tp->pdev->dev, |
| 13739 | "Cannot find PCI-X capability, aborting\n"); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13740 | return -EIO; |
| 13741 | } |
| 13742 | |
| 13743 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13744 | tg3_flag_set(tp, PCIX_MODE); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13745 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13746 | |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 13747 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
| 13748 | * reordering to the mailbox registers done by the host |
| 13749 | * controller can cause major troubles. We read back from |
| 13750 | * every mailbox register write to force the writes to be |
| 13751 | * posted to the chip in order. |
| 13752 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 13753 | if (pci_dev_present(tg3_write_reorder_chipsets) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13754 | !tg3_flag(tp, PCI_EXPRESS)) |
| 13755 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 13756 | |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 13757 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 13758 | &tp->pci_cacheline_sz); |
| 13759 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 13760 | &tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13761 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 13762 | tp->pci_lat_timer < 64) { |
| 13763 | tp->pci_lat_timer = 64; |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 13764 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 13765 | tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13766 | } |
| 13767 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13768 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
| 13769 | /* 5700 BX chips need to have their TX producer index |
| 13770 | * mailboxes written twice to workaround a bug. |
| 13771 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13772 | tg3_flag_set(tp, TXD_MBOX_HWBUG); |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13773 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13774 | /* If we are in PCI-X mode, enable register write workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13775 | * |
| 13776 | * The workaround is to use indirect register accesses |
| 13777 | * for all chip writes not to mailbox registers. |
| 13778 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13779 | if (tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13780 | u32 pm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13781 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13782 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13783 | |
| 13784 | /* The chip can have it's power management PCI config |
| 13785 | * space registers clobbered due to this bug. |
| 13786 | * So explicitly force the chip into D0 here. |
| 13787 | */ |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13788 | pci_read_config_dword(tp->pdev, |
| 13789 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13790 | &pm_reg); |
| 13791 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; |
| 13792 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13793 | pci_write_config_dword(tp->pdev, |
| 13794 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13795 | pm_reg); |
| 13796 | |
| 13797 | /* Also, force SERR#/PERR# in PCI command. */ |
| 13798 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13799 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
| 13800 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13801 | } |
| 13802 | } |
| 13803 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13804 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13805 | tg3_flag_set(tp, PCI_HIGH_SPEED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13806 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13807 | tg3_flag_set(tp, PCI_32BIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13808 | |
| 13809 | /* Chip-specific fixup from Broadcom driver */ |
| 13810 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && |
| 13811 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
| 13812 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; |
| 13813 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); |
| 13814 | } |
| 13815 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13816 | /* Default fast path register access methods */ |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13817 | tp->read32 = tg3_read32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13818 | tp->write32 = tg3_write32; |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 13819 | tp->read32_mbox = tg3_read32; |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13820 | tp->write32_mbox = tg3_write32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13821 | tp->write32_tx_mbox = tg3_write32; |
| 13822 | tp->write32_rx_mbox = tg3_write32; |
| 13823 | |
| 13824 | /* Various workaround register access methods */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13825 | if (tg3_flag(tp, PCIX_TARGET_HWBUG)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13826 | tp->write32 = tg3_write_indirect_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 13827 | 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] | 13828 | (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 13829 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { |
| 13830 | /* |
| 13831 | * Back to back register writes can cause problems on these |
| 13832 | * chips, the workaround is to read back all reg writes |
| 13833 | * except those to mailbox regs. |
| 13834 | * |
| 13835 | * See tg3_write_indirect_reg32(). |
| 13836 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13837 | tp->write32 = tg3_write_flush_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 13838 | } |
| 13839 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13840 | 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] | 13841 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13842 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13843 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 13844 | } |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13845 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13846 | if (tg3_flag(tp, ICH_WORKAROUND)) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13847 | tp->read32 = tg3_read_indirect_reg32; |
| 13848 | tp->write32 = tg3_write_indirect_reg32; |
| 13849 | tp->read32_mbox = tg3_read_indirect_mbox; |
| 13850 | tp->write32_mbox = tg3_write_indirect_mbox; |
| 13851 | tp->write32_tx_mbox = tg3_write_indirect_mbox; |
| 13852 | tp->write32_rx_mbox = tg3_write_indirect_mbox; |
| 13853 | |
| 13854 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 13855 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13856 | |
| 13857 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13858 | pci_cmd &= ~PCI_COMMAND_MEMORY; |
| 13859 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13860 | } |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13861 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 13862 | tp->read32_mbox = tg3_read32_mbox_5906; |
| 13863 | tp->write32_mbox = tg3_write32_mbox_5906; |
| 13864 | tp->write32_tx_mbox = tg3_write32_mbox_5906; |
| 13865 | tp->write32_rx_mbox = tg3_write32_mbox_5906; |
| 13866 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13867 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 13868 | if (tp->write32 == tg3_write_indirect_reg32 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13869 | (tg3_flag(tp, PCIX_MODE) && |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 13870 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 13871 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13872 | tg3_flag_set(tp, SRAM_USE_CONFIG); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 13873 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13874 | /* Get eeprom hw config before calling tg3_set_power_state(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13875 | * In particular, the TG3_FLAG_IS_NIC flag must be |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13876 | * determined before calling tg3_set_power_state() so that |
| 13877 | * we know whether or not to switch out of Vaux power. |
| 13878 | * When the flag is set, it means that GPIO1 is used for eeprom |
| 13879 | * write protect and also implies that it is a LOM where GPIOs |
| 13880 | * are not used to switch power. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13881 | */ |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13882 | tg3_get_eeprom_hw_cfg(tp); |
| 13883 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13884 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 13885 | /* Allow reads and writes to the |
| 13886 | * APE register and memory space. |
| 13887 | */ |
| 13888 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 13889 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 13890 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 13891 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13892 | pci_state_reg); |
| 13893 | } |
| 13894 | |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13895 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13896 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13897 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13898 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13899 | tg3_flag(tp, 57765_PLUS)) |
| 13900 | tg3_flag_set(tp, CPMU_PRESENT); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13901 | |
Matt Carlson | bea8a63 | 2011-04-25 12:42:49 +0000 | [diff] [blame] | 13902 | /* Set up tp->grc_local_ctrl before calling tg3_power_up(). |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 13903 | * GPIO1 driven high will bring 5700's external PHY out of reset. |
| 13904 | * It is also used as eeprom write protect on LOMs. |
| 13905 | */ |
| 13906 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; |
| 13907 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13908 | tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 13909 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 13910 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 13911 | /* Unused GPIO3 must be driven as output on 5752 because there |
| 13912 | * are no pull-up resistors on unused GPIO pins. |
| 13913 | */ |
| 13914 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 13915 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 13916 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13917 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | cb4ed1f | 2010-01-20 16:58:09 +0000 | [diff] [blame] | 13918 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 13919 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 13920 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 13921 | |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 13922 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 13923 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 13924 | /* Turn off the debug UART. */ |
| 13925 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13926 | if (tg3_flag(tp, IS_NIC)) |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 13927 | /* Keep VMain power. */ |
| 13928 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 13929 | GRC_LCLCTRL_GPIO_OUTPUT0; |
| 13930 | } |
| 13931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13932 | /* Force the chip into D0. */ |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 13933 | err = tg3_power_up(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13934 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 13935 | dev_err(&tp->pdev->dev, "Transition to D0 failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13936 | return err; |
| 13937 | } |
| 13938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13939 | /* Derive initial jumbo mode from MTU assigned in |
| 13940 | * ether_setup() via the alloc_etherdev() call |
| 13941 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13942 | if (tp->dev->mtu > ETH_DATA_LEN && !tg3_flag(tp, 5780_CLASS)) |
| 13943 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13944 | |
| 13945 | /* Determine WakeOnLan speed to use. */ |
| 13946 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 13947 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 13948 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || |
| 13949 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13950 | tg3_flag_clear(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13951 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13952 | tg3_flag_set(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13953 | } |
| 13954 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 13955 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13956 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 13957 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13958 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
| 13959 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || |
| 13960 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
| 13961 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13962 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13963 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
| 13964 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 13965 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13966 | |
| 13967 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || |
| 13968 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13969 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13970 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13971 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13972 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13973 | if (tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13974 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13975 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13976 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13977 | !tg3_flag(tp, 57765_PLUS)) { |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 13978 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13979 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13980 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 13981 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
Michael Chan | d4011ad | 2007-02-13 12:17:25 -0800 | [diff] [blame] | 13982 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
| 13983 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13984 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 13985 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13986 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13987 | } else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13988 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 13989 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13990 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 13991 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 13992 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 13993 | tp->phy_otp = tg3_read_otp_phycfg(tp); |
| 13994 | if (tp->phy_otp == 0) |
| 13995 | tp->phy_otp = TG3_OTP_DEFAULT; |
| 13996 | } |
| 13997 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13998 | if (tg3_flag(tp, CPMU_PRESENT)) |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 13999 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
| 14000 | else |
| 14001 | tp->mi_mode = MAC_MI_MODE_BASE; |
| 14002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14003 | tp->coalesce_mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14004 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
| 14005 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) |
| 14006 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
| 14007 | |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 14008 | /* Set these bits to enable statistics workaround. */ |
| 14009 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14010 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 14011 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) { |
| 14012 | tp->coalesce_mode |= HOSTCC_MODE_ATTN; |
| 14013 | tp->grc_mode |= GRC_MODE_IRQ_ON_FLOW_ATTN; |
| 14014 | } |
| 14015 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14016 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 14017 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14018 | tg3_flag_set(tp, USE_PHYLIB); |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 14019 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 14020 | err = tg3_mdio_init(tp); |
| 14021 | if (err) |
| 14022 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14023 | |
| 14024 | /* Initialize data/descriptor byte/word swapping. */ |
| 14025 | val = tr32(GRC_MODE); |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 14026 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 14027 | val &= (GRC_MODE_BYTE_SWAP_B2HRX_DATA | |
| 14028 | GRC_MODE_WORD_SWAP_B2HRX_DATA | |
| 14029 | GRC_MODE_B2HRX_ENABLE | |
| 14030 | GRC_MODE_HTX2B_ENABLE | |
| 14031 | GRC_MODE_HOST_STACKUP); |
| 14032 | else |
| 14033 | val &= GRC_MODE_HOST_STACKUP; |
| 14034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14035 | tw32(GRC_MODE, val | tp->grc_mode); |
| 14036 | |
| 14037 | tg3_switch_clocks(tp); |
| 14038 | |
| 14039 | /* Clear this out for sanity. */ |
| 14040 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 14041 | |
| 14042 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 14043 | &pci_state_reg); |
| 14044 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14045 | !tg3_flag(tp, PCIX_TARGET_HWBUG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14046 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); |
| 14047 | |
| 14048 | if (chiprevid == CHIPREV_ID_5701_A0 || |
| 14049 | chiprevid == CHIPREV_ID_5701_B0 || |
| 14050 | chiprevid == CHIPREV_ID_5701_B2 || |
| 14051 | chiprevid == CHIPREV_ID_5701_B5) { |
| 14052 | void __iomem *sram_base; |
| 14053 | |
| 14054 | /* Write some dummy words into the SRAM status block |
| 14055 | * area, see if it reads back correctly. If the return |
| 14056 | * value is bad, force enable the PCIX workaround. |
| 14057 | */ |
| 14058 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; |
| 14059 | |
| 14060 | writel(0x00000000, sram_base); |
| 14061 | writel(0x00000000, sram_base + 4); |
| 14062 | writel(0xffffffff, sram_base + 4); |
| 14063 | if (readl(sram_base) != 0x00000000) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14064 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14065 | } |
| 14066 | } |
| 14067 | |
| 14068 | udelay(50); |
| 14069 | tg3_nvram_init(tp); |
| 14070 | |
| 14071 | grc_misc_cfg = tr32(GRC_MISC_CFG); |
| 14072 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; |
| 14073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14074 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 14075 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
| 14076 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14077 | tg3_flag_set(tp, IS_5788); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14078 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14079 | if (!tg3_flag(tp, IS_5788) && |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 14080 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14081 | tg3_flag_set(tp, TAGGED_STATUS); |
| 14082 | if (tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 14083 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
| 14084 | HOSTCC_MODE_CLRTICK_TXBD); |
| 14085 | |
| 14086 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; |
| 14087 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 14088 | tp->misc_host_ctrl); |
| 14089 | } |
| 14090 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 14091 | /* Preserve the APE MAC_MODE bits */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14092 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 14093 | 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] | 14094 | else |
| 14095 | tp->mac_mode = TG3_DEF_MAC_MODE; |
| 14096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14097 | /* these are limited to 10/100 only */ |
| 14098 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 14099 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || |
| 14100 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 14101 | tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 14102 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 || |
| 14103 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 || |
| 14104 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) || |
| 14105 | (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 14106 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F || |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 14107 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F || |
| 14108 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14109 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790 || |
Matt Carlson | d110114 | 2010-02-17 15:16:55 +0000 | [diff] [blame] | 14110 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 14111 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14112 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
| 14113 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14114 | |
| 14115 | err = tg3_phy_probe(tp); |
| 14116 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14117 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14118 | /* ... but do not return immediately ... */ |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14119 | tg3_mdio_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14120 | } |
| 14121 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 14122 | tg3_read_vpd(tp); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 14123 | tg3_read_fw_ver(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14124 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14125 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 14126 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14127 | } else { |
| 14128 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14129 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14130 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14131 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14132 | } |
| 14133 | |
| 14134 | /* 5700 {AX,BX} chips have a broken status block link |
| 14135 | * change bit implementation, so we must use the |
| 14136 | * status register in those cases. |
| 14137 | */ |
| 14138 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14139 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14140 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14141 | tg3_flag_clear(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14142 | |
| 14143 | /* The led_ctrl is set during tg3_phy_probe, here we might |
| 14144 | * have to force the link status polling mechanism based |
| 14145 | * upon subsystem IDs. |
| 14146 | */ |
| 14147 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
Michael Chan | 007a880d | 2007-05-31 14:49:51 -0700 | [diff] [blame] | 14148 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14149 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 14150 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14151 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14152 | } |
| 14153 | |
| 14154 | /* For all SERDES we poll the MAC status register. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14155 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14156 | tg3_flag_set(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14157 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14158 | tg3_flag_clear(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14159 | |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 14160 | tp->rx_offset = NET_IP_ALIGN; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 14161 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14162 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14163 | tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 14164 | tp->rx_offset = 0; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 14165 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 14166 | tp->rx_copy_thresh = ~(u16)0; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 14167 | #endif |
| 14168 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14169 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 14170 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
| 14171 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 14172 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
| 14173 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 14174 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 14175 | |
| 14176 | /* Increment the rx prod index on the rx std ring by at most |
| 14177 | * 8 for these chips to workaround hw errata. |
| 14178 | */ |
| 14179 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 14180 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 14181 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 14182 | tp->rx_std_max_post = 8; |
| 14183 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14184 | if (tg3_flag(tp, ASPM_WORKAROUND)) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 14185 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
| 14186 | PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 14187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14188 | return err; |
| 14189 | } |
| 14190 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14191 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14192 | static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp) |
| 14193 | { |
| 14194 | struct net_device *dev = tp->dev; |
| 14195 | struct pci_dev *pdev = tp->pdev; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14196 | struct device_node *dp = pci_device_to_OF_node(pdev); |
David S. Miller | 374d4ca | 2007-03-29 01:57:57 -0700 | [diff] [blame] | 14197 | const unsigned char *addr; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14198 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14199 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14200 | addr = of_get_property(dp, "local-mac-address", &len); |
| 14201 | if (addr && len == 6) { |
| 14202 | memcpy(dev->dev_addr, addr, 6); |
| 14203 | memcpy(dev->perm_addr, dev->dev_addr, 6); |
| 14204 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14205 | } |
| 14206 | return -ENODEV; |
| 14207 | } |
| 14208 | |
| 14209 | static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp) |
| 14210 | { |
| 14211 | struct net_device *dev = tp->dev; |
| 14212 | |
| 14213 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 14214 | memcpy(dev->perm_addr, idprom->id_ethaddr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14215 | return 0; |
| 14216 | } |
| 14217 | #endif |
| 14218 | |
| 14219 | static int __devinit tg3_get_device_address(struct tg3 *tp) |
| 14220 | { |
| 14221 | struct net_device *dev = tp->dev; |
| 14222 | u32 hi, lo, mac_offset; |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 14223 | int addr_ok = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14224 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14225 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14226 | if (!tg3_get_macaddr_sparc(tp)) |
| 14227 | return 0; |
| 14228 | #endif |
| 14229 | |
| 14230 | mac_offset = 0x7c; |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 14231 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14232 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14233 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 14234 | mac_offset = 0xcc; |
| 14235 | if (tg3_nvram_lock(tp)) |
| 14236 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); |
| 14237 | else |
| 14238 | tg3_nvram_unlock(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14239 | } else if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 14240 | if (PCI_FUNC(tp->pdev->devfn) & 1) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14241 | mac_offset = 0xcc; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 14242 | if (PCI_FUNC(tp->pdev->devfn) > 1) |
| 14243 | mac_offset += 0x18c; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14244 | } 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] | 14245 | mac_offset = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14246 | |
| 14247 | /* First try to get it from MAC address mailbox. */ |
| 14248 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); |
| 14249 | if ((hi >> 16) == 0x484b) { |
| 14250 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 14251 | dev->dev_addr[1] = (hi >> 0) & 0xff; |
| 14252 | |
| 14253 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); |
| 14254 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 14255 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 14256 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 14257 | dev->dev_addr[5] = (lo >> 0) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14258 | |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 14259 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
| 14260 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); |
| 14261 | } |
| 14262 | if (!addr_ok) { |
| 14263 | /* Next, try NVRAM. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14264 | if (!tg3_flag(tp, NO_NVRAM) && |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 14265 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 14266 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 14267 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
| 14268 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 14269 | } |
| 14270 | /* Finally just fetch it out of the MAC control regs. */ |
| 14271 | else { |
| 14272 | hi = tr32(MAC_ADDR_0_HIGH); |
| 14273 | lo = tr32(MAC_ADDR_0_LOW); |
| 14274 | |
| 14275 | dev->dev_addr[5] = lo & 0xff; |
| 14276 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 14277 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 14278 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 14279 | dev->dev_addr[1] = hi & 0xff; |
| 14280 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 14281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14282 | } |
| 14283 | |
| 14284 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { |
David S. Miller | 7582a33 | 2008-03-20 15:53:15 -0700 | [diff] [blame] | 14285 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14286 | if (!tg3_get_default_macaddr_sparc(tp)) |
| 14287 | return 0; |
| 14288 | #endif |
| 14289 | return -EINVAL; |
| 14290 | } |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 14291 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14292 | return 0; |
| 14293 | } |
| 14294 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14295 | #define BOUNDARY_SINGLE_CACHELINE 1 |
| 14296 | #define BOUNDARY_MULTI_CACHELINE 2 |
| 14297 | |
| 14298 | static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
| 14299 | { |
| 14300 | int cacheline_size; |
| 14301 | u8 byte; |
| 14302 | int goal; |
| 14303 | |
| 14304 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); |
| 14305 | if (byte == 0) |
| 14306 | cacheline_size = 1024; |
| 14307 | else |
| 14308 | cacheline_size = (int) byte * 4; |
| 14309 | |
| 14310 | /* On 5703 and later chips, the boundary bits have no |
| 14311 | * effect. |
| 14312 | */ |
| 14313 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14314 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14315 | !tg3_flag(tp, PCI_EXPRESS)) |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14316 | goto out; |
| 14317 | |
| 14318 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) |
| 14319 | goal = BOUNDARY_MULTI_CACHELINE; |
| 14320 | #else |
| 14321 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) |
| 14322 | goal = BOUNDARY_SINGLE_CACHELINE; |
| 14323 | #else |
| 14324 | goal = 0; |
| 14325 | #endif |
| 14326 | #endif |
| 14327 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14328 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14329 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 14330 | goto out; |
| 14331 | } |
| 14332 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14333 | if (!goal) |
| 14334 | goto out; |
| 14335 | |
| 14336 | /* PCI controllers on most RISC systems tend to disconnect |
| 14337 | * when a device tries to burst across a cache-line boundary. |
| 14338 | * Therefore, letting tg3 do so just wastes PCI bandwidth. |
| 14339 | * |
| 14340 | * Unfortunately, for PCI-E there are only limited |
| 14341 | * write-side controls for this, and thus for reads |
| 14342 | * we will still get the disconnects. We'll also waste |
| 14343 | * these PCI cycles for both read and write for chips |
| 14344 | * other than 5700 and 5701 which do not implement the |
| 14345 | * boundary bits. |
| 14346 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14347 | if (tg3_flag(tp, PCIX_MODE) && !tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14348 | switch (cacheline_size) { |
| 14349 | case 16: |
| 14350 | case 32: |
| 14351 | case 64: |
| 14352 | case 128: |
| 14353 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14354 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | |
| 14355 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); |
| 14356 | } else { |
| 14357 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 14358 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 14359 | } |
| 14360 | break; |
| 14361 | |
| 14362 | case 256: |
| 14363 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | |
| 14364 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); |
| 14365 | break; |
| 14366 | |
| 14367 | default: |
| 14368 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 14369 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 14370 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14371 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14372 | } else if (tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14373 | switch (cacheline_size) { |
| 14374 | case 16: |
| 14375 | case 32: |
| 14376 | case 64: |
| 14377 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14378 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 14379 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; |
| 14380 | break; |
| 14381 | } |
| 14382 | /* fallthrough */ |
| 14383 | case 128: |
| 14384 | default: |
| 14385 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 14386 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; |
| 14387 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14388 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14389 | } else { |
| 14390 | switch (cacheline_size) { |
| 14391 | case 16: |
| 14392 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14393 | val |= (DMA_RWCTRL_READ_BNDRY_16 | |
| 14394 | DMA_RWCTRL_WRITE_BNDRY_16); |
| 14395 | break; |
| 14396 | } |
| 14397 | /* fallthrough */ |
| 14398 | case 32: |
| 14399 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14400 | val |= (DMA_RWCTRL_READ_BNDRY_32 | |
| 14401 | DMA_RWCTRL_WRITE_BNDRY_32); |
| 14402 | break; |
| 14403 | } |
| 14404 | /* fallthrough */ |
| 14405 | case 64: |
| 14406 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14407 | val |= (DMA_RWCTRL_READ_BNDRY_64 | |
| 14408 | DMA_RWCTRL_WRITE_BNDRY_64); |
| 14409 | break; |
| 14410 | } |
| 14411 | /* fallthrough */ |
| 14412 | case 128: |
| 14413 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14414 | val |= (DMA_RWCTRL_READ_BNDRY_128 | |
| 14415 | DMA_RWCTRL_WRITE_BNDRY_128); |
| 14416 | break; |
| 14417 | } |
| 14418 | /* fallthrough */ |
| 14419 | case 256: |
| 14420 | val |= (DMA_RWCTRL_READ_BNDRY_256 | |
| 14421 | DMA_RWCTRL_WRITE_BNDRY_256); |
| 14422 | break; |
| 14423 | case 512: |
| 14424 | val |= (DMA_RWCTRL_READ_BNDRY_512 | |
| 14425 | DMA_RWCTRL_WRITE_BNDRY_512); |
| 14426 | break; |
| 14427 | case 1024: |
| 14428 | default: |
| 14429 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | |
| 14430 | DMA_RWCTRL_WRITE_BNDRY_1024); |
| 14431 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14432 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14433 | } |
| 14434 | |
| 14435 | out: |
| 14436 | return val; |
| 14437 | } |
| 14438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14439 | static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) |
| 14440 | { |
| 14441 | struct tg3_internal_buffer_desc test_desc; |
| 14442 | u32 sram_dma_descs; |
| 14443 | int i, ret; |
| 14444 | |
| 14445 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; |
| 14446 | |
| 14447 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); |
| 14448 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); |
| 14449 | tw32(RDMAC_STATUS, 0); |
| 14450 | tw32(WDMAC_STATUS, 0); |
| 14451 | |
| 14452 | tw32(BUFMGR_MODE, 0); |
| 14453 | tw32(FTQ_RESET, 0); |
| 14454 | |
| 14455 | test_desc.addr_hi = ((u64) buf_dma) >> 32; |
| 14456 | test_desc.addr_lo = buf_dma & 0xffffffff; |
| 14457 | test_desc.nic_mbuf = 0x00002100; |
| 14458 | test_desc.len = size; |
| 14459 | |
| 14460 | /* |
| 14461 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz |
| 14462 | * the *second* time the tg3 driver was getting loaded after an |
| 14463 | * initial scan. |
| 14464 | * |
| 14465 | * Broadcom tells me: |
| 14466 | * ...the DMA engine is connected to the GRC block and a DMA |
| 14467 | * reset may affect the GRC block in some unpredictable way... |
| 14468 | * The behavior of resets to individual blocks has not been tested. |
| 14469 | * |
| 14470 | * Broadcom noted the GRC reset will also reset all sub-components. |
| 14471 | */ |
| 14472 | if (to_device) { |
| 14473 | test_desc.cqid_sqid = (13 << 8) | 2; |
| 14474 | |
| 14475 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); |
| 14476 | udelay(40); |
| 14477 | } else { |
| 14478 | test_desc.cqid_sqid = (16 << 8) | 7; |
| 14479 | |
| 14480 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); |
| 14481 | udelay(40); |
| 14482 | } |
| 14483 | test_desc.flags = 0x00000005; |
| 14484 | |
| 14485 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { |
| 14486 | u32 val; |
| 14487 | |
| 14488 | val = *(((u32 *)&test_desc) + i); |
| 14489 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, |
| 14490 | sram_dma_descs + (i * sizeof(u32))); |
| 14491 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 14492 | } |
| 14493 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 14494 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14495 | if (to_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14496 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14497 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14498 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14499 | |
| 14500 | ret = -ENODEV; |
| 14501 | for (i = 0; i < 40; i++) { |
| 14502 | u32 val; |
| 14503 | |
| 14504 | if (to_device) |
| 14505 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); |
| 14506 | else |
| 14507 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); |
| 14508 | if ((val & 0xffff) == sram_dma_descs) { |
| 14509 | ret = 0; |
| 14510 | break; |
| 14511 | } |
| 14512 | |
| 14513 | udelay(100); |
| 14514 | } |
| 14515 | |
| 14516 | return ret; |
| 14517 | } |
| 14518 | |
David S. Miller | ded7340 | 2005-05-23 13:59:47 -0700 | [diff] [blame] | 14519 | #define TEST_BUFFER_SIZE 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14520 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 14521 | static DEFINE_PCI_DEVICE_TABLE(tg3_dma_wait_state_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 14522 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
| 14523 | { }, |
| 14524 | }; |
| 14525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14526 | static int __devinit tg3_test_dma(struct tg3 *tp) |
| 14527 | { |
| 14528 | dma_addr_t buf_dma; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14529 | u32 *buf, saved_dma_rwctrl; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14530 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14531 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 14532 | buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
| 14533 | &buf_dma, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14534 | if (!buf) { |
| 14535 | ret = -ENOMEM; |
| 14536 | goto out_nofree; |
| 14537 | } |
| 14538 | |
| 14539 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | |
| 14540 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); |
| 14541 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14542 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14543 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14544 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14545 | goto out; |
| 14546 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14547 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14548 | /* DMA read watermark not used on PCIE */ |
| 14549 | tp->dma_rwctrl |= 0x00180000; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14550 | } else if (!tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 14551 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 14552 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14553 | tp->dma_rwctrl |= 0x003f0000; |
| 14554 | else |
| 14555 | tp->dma_rwctrl |= 0x003f000f; |
| 14556 | } else { |
| 14557 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 14558 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 14559 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14560 | u32 read_water = 0x7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14561 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14562 | /* If the 5704 is behind the EPB bridge, we can |
| 14563 | * do the less restrictive ONE_DMA workaround for |
| 14564 | * better performance. |
| 14565 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14566 | if (tg3_flag(tp, 40BIT_DMA_BUG) && |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14567 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 14568 | tp->dma_rwctrl |= 0x8000; |
| 14569 | else if (ccval == 0x6 || ccval == 0x7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14570 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 14571 | |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14572 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
| 14573 | read_water = 4; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14574 | /* Set bit 23 to enable PCIX hw bug fix */ |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14575 | tp->dma_rwctrl |= |
| 14576 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | |
| 14577 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | |
| 14578 | (1 << 23); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 14579 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
| 14580 | /* 5780 always in PCIX mode */ |
| 14581 | tp->dma_rwctrl |= 0x00144000; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 14582 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 14583 | /* 5714 always in PCIX mode */ |
| 14584 | tp->dma_rwctrl |= 0x00148000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14585 | } else { |
| 14586 | tp->dma_rwctrl |= 0x001b000f; |
| 14587 | } |
| 14588 | } |
| 14589 | |
| 14590 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 14591 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 14592 | tp->dma_rwctrl &= 0xfffffff0; |
| 14593 | |
| 14594 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 14595 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 14596 | /* Remove this if it causes problems for some boards. */ |
| 14597 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; |
| 14598 | |
| 14599 | /* On 5700/5701 chips, we need to set this bit. |
| 14600 | * Otherwise the chip will issue cacheline transactions |
| 14601 | * to streamable DMA memory with not all the byte |
| 14602 | * enables turned on. This is an error on several |
| 14603 | * RISC PCI controllers, in particular sparc64. |
| 14604 | * |
| 14605 | * On 5703/5704 chips, this bit has been reassigned |
| 14606 | * a different meaning. In particular, it is used |
| 14607 | * on those chips to enable a PCI-X workaround. |
| 14608 | */ |
| 14609 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; |
| 14610 | } |
| 14611 | |
| 14612 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14613 | |
| 14614 | #if 0 |
| 14615 | /* Unneeded, already done by tg3_get_invariants. */ |
| 14616 | tg3_switch_clocks(tp); |
| 14617 | #endif |
| 14618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14619 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14620 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 14621 | goto out; |
| 14622 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14623 | /* It is best to perform DMA test with maximum write burst size |
| 14624 | * to expose the 5700/5701 write DMA bug. |
| 14625 | */ |
| 14626 | saved_dma_rwctrl = tp->dma_rwctrl; |
| 14627 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 14628 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14630 | while (1) { |
| 14631 | u32 *p = buf, i; |
| 14632 | |
| 14633 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) |
| 14634 | p[i] = i; |
| 14635 | |
| 14636 | /* Send the buffer to the chip. */ |
| 14637 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); |
| 14638 | if (ret) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14639 | dev_err(&tp->pdev->dev, |
| 14640 | "%s: Buffer write failed. err = %d\n", |
| 14641 | __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14642 | break; |
| 14643 | } |
| 14644 | |
| 14645 | #if 0 |
| 14646 | /* validate data reached card RAM correctly. */ |
| 14647 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 14648 | u32 val; |
| 14649 | tg3_read_mem(tp, 0x2100 + (i*4), &val); |
| 14650 | if (le32_to_cpu(val) != p[i]) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14651 | dev_err(&tp->pdev->dev, |
| 14652 | "%s: Buffer corrupted on device! " |
| 14653 | "(%d != %d)\n", __func__, val, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14654 | /* ret = -ENODEV here? */ |
| 14655 | } |
| 14656 | p[i] = 0; |
| 14657 | } |
| 14658 | #endif |
| 14659 | /* Now read it back. */ |
| 14660 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); |
| 14661 | if (ret) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 14662 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
| 14663 | "err = %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14664 | break; |
| 14665 | } |
| 14666 | |
| 14667 | /* Verify it. */ |
| 14668 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 14669 | if (p[i] == i) |
| 14670 | continue; |
| 14671 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14672 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 14673 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 14674 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14675 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 14676 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14677 | break; |
| 14678 | } else { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14679 | dev_err(&tp->pdev->dev, |
| 14680 | "%s: Buffer corrupted on read back! " |
| 14681 | "(%d != %d)\n", __func__, p[i], i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14682 | ret = -ENODEV; |
| 14683 | goto out; |
| 14684 | } |
| 14685 | } |
| 14686 | |
| 14687 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { |
| 14688 | /* Success. */ |
| 14689 | ret = 0; |
| 14690 | break; |
| 14691 | } |
| 14692 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14693 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 14694 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 14695 | /* DMA test passed without adjusting DMA boundary, |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14696 | * now look for chipsets that are known to expose the |
| 14697 | * DMA bug without failing the test. |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14698 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 14699 | if (pci_dev_present(tg3_dma_wait_state_chipsets)) { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14700 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 14701 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14702 | } else { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14703 | /* Safe to use the calculated DMA boundary. */ |
| 14704 | tp->dma_rwctrl = saved_dma_rwctrl; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14705 | } |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14706 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14707 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14708 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14709 | |
| 14710 | out: |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 14711 | dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14712 | out_nofree: |
| 14713 | return ret; |
| 14714 | } |
| 14715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14716 | static void __devinit tg3_init_bufmgr_config(struct tg3 *tp) |
| 14717 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14718 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 14719 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14720 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14721 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14722 | DEFAULT_MB_MACRX_LOW_WATER_57765; |
| 14723 | tp->bufmgr_config.mbuf_high_water = |
| 14724 | DEFAULT_MB_HIGH_WATER_57765; |
| 14725 | |
| 14726 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14727 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14728 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14729 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; |
| 14730 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14731 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14732 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14733 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14734 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14735 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14736 | DEFAULT_MB_MACRX_LOW_WATER_5705; |
| 14737 | tp->bufmgr_config.mbuf_high_water = |
| 14738 | DEFAULT_MB_HIGH_WATER_5705; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14739 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 14740 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14741 | DEFAULT_MB_MACRX_LOW_WATER_5906; |
| 14742 | tp->bufmgr_config.mbuf_high_water = |
| 14743 | DEFAULT_MB_HIGH_WATER_5906; |
| 14744 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14745 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14746 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14747 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; |
| 14748 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14749 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; |
| 14750 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14751 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; |
| 14752 | } else { |
| 14753 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14754 | DEFAULT_MB_RDMA_LOW_WATER; |
| 14755 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14756 | DEFAULT_MB_MACRX_LOW_WATER; |
| 14757 | tp->bufmgr_config.mbuf_high_water = |
| 14758 | DEFAULT_MB_HIGH_WATER; |
| 14759 | |
| 14760 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14761 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; |
| 14762 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14763 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; |
| 14764 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14765 | DEFAULT_MB_HIGH_WATER_JUMBO; |
| 14766 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14767 | |
| 14768 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; |
| 14769 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; |
| 14770 | } |
| 14771 | |
| 14772 | static char * __devinit tg3_phy_string(struct tg3 *tp) |
| 14773 | { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14774 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
| 14775 | case TG3_PHY_ID_BCM5400: return "5400"; |
| 14776 | case TG3_PHY_ID_BCM5401: return "5401"; |
| 14777 | case TG3_PHY_ID_BCM5411: return "5411"; |
| 14778 | case TG3_PHY_ID_BCM5701: return "5701"; |
| 14779 | case TG3_PHY_ID_BCM5703: return "5703"; |
| 14780 | case TG3_PHY_ID_BCM5704: return "5704"; |
| 14781 | case TG3_PHY_ID_BCM5705: return "5705"; |
| 14782 | case TG3_PHY_ID_BCM5750: return "5750"; |
| 14783 | case TG3_PHY_ID_BCM5752: return "5752"; |
| 14784 | case TG3_PHY_ID_BCM5714: return "5714"; |
| 14785 | case TG3_PHY_ID_BCM5780: return "5780"; |
| 14786 | case TG3_PHY_ID_BCM5755: return "5755"; |
| 14787 | case TG3_PHY_ID_BCM5787: return "5787"; |
| 14788 | case TG3_PHY_ID_BCM5784: return "5784"; |
| 14789 | case TG3_PHY_ID_BCM5756: return "5722/5756"; |
| 14790 | case TG3_PHY_ID_BCM5906: return "5906"; |
| 14791 | case TG3_PHY_ID_BCM5761: return "5761"; |
| 14792 | case TG3_PHY_ID_BCM5718C: return "5718C"; |
| 14793 | case TG3_PHY_ID_BCM5718S: return "5718S"; |
| 14794 | case TG3_PHY_ID_BCM57765: return "57765"; |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 14795 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
Matt Carlson | 6418f2c | 2011-04-05 14:22:49 +0000 | [diff] [blame] | 14796 | case TG3_PHY_ID_BCM5720C: return "5720C"; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14797 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14798 | case 0: return "serdes"; |
| 14799 | default: return "unknown"; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14800 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14801 | } |
| 14802 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14803 | static char * __devinit tg3_bus_string(struct tg3 *tp, char *str) |
| 14804 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14805 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14806 | strcpy(str, "PCI Express"); |
| 14807 | return str; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14808 | } else if (tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14809 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
| 14810 | |
| 14811 | strcpy(str, "PCIX:"); |
| 14812 | |
| 14813 | if ((clock_ctrl == 7) || |
| 14814 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == |
| 14815 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) |
| 14816 | strcat(str, "133MHz"); |
| 14817 | else if (clock_ctrl == 0) |
| 14818 | strcat(str, "33MHz"); |
| 14819 | else if (clock_ctrl == 2) |
| 14820 | strcat(str, "50MHz"); |
| 14821 | else if (clock_ctrl == 4) |
| 14822 | strcat(str, "66MHz"); |
| 14823 | else if (clock_ctrl == 6) |
| 14824 | strcat(str, "100MHz"); |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14825 | } else { |
| 14826 | strcpy(str, "PCI:"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14827 | if (tg3_flag(tp, PCI_HIGH_SPEED)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14828 | strcat(str, "66MHz"); |
| 14829 | else |
| 14830 | strcat(str, "33MHz"); |
| 14831 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14832 | if (tg3_flag(tp, PCI_32BIT)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14833 | strcat(str, ":32-bit"); |
| 14834 | else |
| 14835 | strcat(str, ":64-bit"); |
| 14836 | return str; |
| 14837 | } |
| 14838 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 14839 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14840 | { |
| 14841 | struct pci_dev *peer; |
| 14842 | unsigned int func, devnr = tp->pdev->devfn & ~7; |
| 14843 | |
| 14844 | for (func = 0; func < 8; func++) { |
| 14845 | peer = pci_get_slot(tp->pdev->bus, devnr | func); |
| 14846 | if (peer && peer != tp->pdev) |
| 14847 | break; |
| 14848 | pci_dev_put(peer); |
| 14849 | } |
Michael Chan | 16fe9d7 | 2005-12-13 21:09:54 -0800 | [diff] [blame] | 14850 | /* 5704 can be configured in single-port mode, set peer to |
| 14851 | * tp->pdev in that case. |
| 14852 | */ |
| 14853 | if (!peer) { |
| 14854 | peer = tp->pdev; |
| 14855 | return peer; |
| 14856 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14857 | |
| 14858 | /* |
| 14859 | * We don't need to keep the refcount elevated; there's no way |
| 14860 | * to remove one half of this device without removing the other |
| 14861 | */ |
| 14862 | pci_dev_put(peer); |
| 14863 | |
| 14864 | return peer; |
| 14865 | } |
| 14866 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 14867 | static void __devinit tg3_init_coal(struct tg3 *tp) |
| 14868 | { |
| 14869 | struct ethtool_coalesce *ec = &tp->coal; |
| 14870 | |
| 14871 | memset(ec, 0, sizeof(*ec)); |
| 14872 | ec->cmd = ETHTOOL_GCOALESCE; |
| 14873 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; |
| 14874 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; |
| 14875 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; |
| 14876 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; |
| 14877 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; |
| 14878 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; |
| 14879 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; |
| 14880 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; |
| 14881 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; |
| 14882 | |
| 14883 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | |
| 14884 | HOSTCC_MODE_CLRTICK_TXBD)) { |
| 14885 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; |
| 14886 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; |
| 14887 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; |
| 14888 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; |
| 14889 | } |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 14890 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14891 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 14892 | ec->rx_coalesce_usecs_irq = 0; |
| 14893 | ec->tx_coalesce_usecs_irq = 0; |
| 14894 | ec->stats_block_coalesce_usecs = 0; |
| 14895 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 14896 | } |
| 14897 | |
Stephen Hemminger | 7c7d64b | 2008-11-19 22:25:36 -0800 | [diff] [blame] | 14898 | static const struct net_device_ops tg3_netdev_ops = { |
| 14899 | .ndo_open = tg3_open, |
| 14900 | .ndo_stop = tg3_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14901 | .ndo_start_xmit = tg3_start_xmit, |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 14902 | .ndo_get_stats64 = tg3_get_stats64, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14903 | .ndo_validate_addr = eth_validate_addr, |
| 14904 | .ndo_set_multicast_list = tg3_set_rx_mode, |
| 14905 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 14906 | .ndo_do_ioctl = tg3_ioctl, |
| 14907 | .ndo_tx_timeout = tg3_tx_timeout, |
| 14908 | .ndo_change_mtu = tg3_change_mtu, |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 14909 | .ndo_fix_features = tg3_fix_features, |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 14910 | .ndo_set_features = tg3_set_features, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14911 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 14912 | .ndo_poll_controller = tg3_poll_controller, |
| 14913 | #endif |
| 14914 | }; |
| 14915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14916 | static int __devinit tg3_init_one(struct pci_dev *pdev, |
| 14917 | const struct pci_device_id *ent) |
| 14918 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14919 | struct net_device *dev; |
| 14920 | struct tg3 *tp; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 14921 | int i, err, pm_cap; |
| 14922 | u32 sndmbx, rcvmbx, intmbx; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14923 | char str[40]; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14924 | u64 dma_mask, persist_dma_mask; |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 14925 | u32 hw_features = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14926 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14927 | printk_once(KERN_INFO "%s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14928 | |
| 14929 | err = pci_enable_device(pdev); |
| 14930 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14931 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14932 | return err; |
| 14933 | } |
| 14934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14935 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 14936 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14937 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14938 | goto err_out_disable_pdev; |
| 14939 | } |
| 14940 | |
| 14941 | pci_set_master(pdev); |
| 14942 | |
| 14943 | /* Find power-management capability. */ |
| 14944 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 14945 | if (pm_cap == 0) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14946 | dev_err(&pdev->dev, |
| 14947 | "Cannot find Power Management capability, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14948 | err = -EIO; |
| 14949 | goto err_out_free_res; |
| 14950 | } |
| 14951 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 14952 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14953 | if (!dev) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14954 | dev_err(&pdev->dev, "Etherdev alloc failed, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14955 | err = -ENOMEM; |
| 14956 | goto err_out_free_res; |
| 14957 | } |
| 14958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14959 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 14960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14961 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14962 | |
| 14963 | tp = netdev_priv(dev); |
| 14964 | tp->pdev = pdev; |
| 14965 | tp->dev = dev; |
| 14966 | tp->pm_cap = pm_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14967 | tp->rx_mode = TG3_DEF_RX_MODE; |
| 14968 | tp->tx_mode = TG3_DEF_TX_MODE; |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 14969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14970 | if (tg3_debug > 0) |
| 14971 | tp->msg_enable = tg3_debug; |
| 14972 | else |
| 14973 | tp->msg_enable = TG3_DEF_MSG_ENABLE; |
| 14974 | |
| 14975 | /* The word/byte swap controls here control register access byte |
| 14976 | * swapping. DMA data byte swapping is controlled in the GRC_MODE |
| 14977 | * setting below. |
| 14978 | */ |
| 14979 | tp->misc_host_ctrl = |
| 14980 | MISC_HOST_CTRL_MASK_PCI_INT | |
| 14981 | MISC_HOST_CTRL_WORD_SWAP | |
| 14982 | MISC_HOST_CTRL_INDIR_ACCESS | |
| 14983 | MISC_HOST_CTRL_PCISTATE_RW; |
| 14984 | |
| 14985 | /* The NONFRM (non-frame) byte/word swap controls take effect |
| 14986 | * on descriptor entries, anything which isn't packet data. |
| 14987 | * |
| 14988 | * The StrongARM chips on the board (one for tx, one for rx) |
| 14989 | * are running in big-endian mode. |
| 14990 | */ |
| 14991 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | |
| 14992 | GRC_MODE_WSWAP_NONFRM_DATA); |
| 14993 | #ifdef __BIG_ENDIAN |
| 14994 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; |
| 14995 | #endif |
| 14996 | spin_lock_init(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14997 | spin_lock_init(&tp->indirect_lock); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 14998 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14999 | |
Matt Carlson | d5fe488 | 2008-11-21 17:20:32 -0800 | [diff] [blame] | 15000 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 15001 | if (!tp->regs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15002 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15003 | err = -ENOMEM; |
| 15004 | goto err_out_free_dev; |
| 15005 | } |
| 15006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15007 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
| 15008 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15009 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15010 | dev->ethtool_ops = &tg3_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15011 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 15012 | dev->netdev_ops = &tg3_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15013 | dev->irq = pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15014 | |
| 15015 | err = tg3_get_invariants(tp); |
| 15016 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15017 | dev_err(&pdev->dev, |
| 15018 | "Problem fetching invariants of chip, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15019 | goto err_out_iounmap; |
| 15020 | } |
| 15021 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15022 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
| 15023 | * device behind the EPB cannot support DMA addresses > 40-bit. |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15024 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
| 15025 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and |
| 15026 | * do DMA address check in tg3_start_xmit(). |
| 15027 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15028 | if (tg3_flag(tp, IS_5788)) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 15029 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15030 | else if (tg3_flag(tp, 40BIT_DMA_BUG)) { |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 15031 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15032 | #ifdef CONFIG_HIGHMEM |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 15033 | dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15034 | #endif |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15035 | } else |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 15036 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15037 | |
| 15038 | /* Configure DMA attributes. */ |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 15039 | if (dma_mask > DMA_BIT_MASK(32)) { |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15040 | err = pci_set_dma_mask(pdev, dma_mask); |
| 15041 | if (!err) { |
| 15042 | dev->features |= NETIF_F_HIGHDMA; |
| 15043 | err = pci_set_consistent_dma_mask(pdev, |
| 15044 | persist_dma_mask); |
| 15045 | if (err < 0) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15046 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
| 15047 | "DMA for consistent allocations\n"); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15048 | goto err_out_iounmap; |
| 15049 | } |
| 15050 | } |
| 15051 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 15052 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
| 15053 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15054 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15055 | dev_err(&pdev->dev, |
| 15056 | "No usable DMA configuration, aborting\n"); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15057 | goto err_out_iounmap; |
| 15058 | } |
| 15059 | } |
| 15060 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 15061 | tg3_init_bufmgr_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15062 | |
Michael Chan | 4e3a7aa | 2006-03-20 17:47:44 -0800 | [diff] [blame] | 15063 | /* TSO is on by default on chips that support hardware TSO. |
| 15064 | * Firmware TSO on older chips gives lower performance, so it |
| 15065 | * is off by default, but can be enabled using ethtool. |
| 15066 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15067 | if ((tg3_flag(tp, HW_TSO_1) || |
| 15068 | tg3_flag(tp, HW_TSO_2) || |
| 15069 | tg3_flag(tp, HW_TSO_3)) && |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 15070 | (dev->features & NETIF_F_IP_CSUM)) |
| 15071 | hw_features |= NETIF_F_TSO; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15072 | if (tg3_flag(tp, HW_TSO_2) || tg3_flag(tp, HW_TSO_3)) { |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 15073 | if (dev->features & NETIF_F_IPV6_CSUM) |
| 15074 | hw_features |= NETIF_F_TSO6; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15075 | if (tg3_flag(tp, HW_TSO_3) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 15076 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 15077 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 15078 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15079 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 15080 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
| 15081 | hw_features |= NETIF_F_TSO_ECN; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 15082 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15083 | |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 15084 | dev->hw_features |= hw_features; |
| 15085 | dev->features |= hw_features; |
| 15086 | dev->vlan_features |= hw_features; |
| 15087 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 15088 | /* |
| 15089 | * Add loopback capability only for a subset of devices that support |
| 15090 | * MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY |
| 15091 | * loopback for the remaining devices. |
| 15092 | */ |
| 15093 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && |
| 15094 | !tg3_flag(tp, CPMU_PRESENT)) |
| 15095 | /* Add the loopback capability */ |
| 15096 | dev->hw_features |= NETIF_F_LOOPBACK; |
| 15097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15098 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15099 | !tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15100 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15101 | tg3_flag_set(tp, MAX_RXPEND_64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15102 | tp->rx_pending = 63; |
| 15103 | } |
| 15104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15105 | err = tg3_get_device_address(tp); |
| 15106 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15107 | dev_err(&pdev->dev, |
| 15108 | "Could not obtain valid ethernet address, aborting\n"); |
Matt Carlson | 026a6c2 | 2009-12-03 08:36:24 +0000 | [diff] [blame] | 15109 | goto err_out_iounmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15110 | } |
| 15111 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15112 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 15113 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 15114 | if (!tp->aperegs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15115 | dev_err(&pdev->dev, |
| 15116 | "Cannot map APE registers, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15117 | err = -ENOMEM; |
Matt Carlson | 026a6c2 | 2009-12-03 08:36:24 +0000 | [diff] [blame] | 15118 | goto err_out_iounmap; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15119 | } |
| 15120 | |
| 15121 | tg3_ape_lock_init(tp); |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 15122 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15123 | if (tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 15124 | tg3_read_dash_ver(tp); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15125 | } |
| 15126 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 15127 | /* |
| 15128 | * Reset chip in case UNDI or EFI driver did not shutdown |
| 15129 | * DMA self test will enable WDMAC and we'll see (spurious) |
| 15130 | * pending DMA on the PCI bus at that point. |
| 15131 | */ |
| 15132 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
| 15133 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 15134 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
| 15135 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 15136 | } |
| 15137 | |
| 15138 | err = tg3_test_dma(tp); |
| 15139 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15140 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 15141 | goto err_out_apeunmap; |
| 15142 | } |
| 15143 | |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15144 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
| 15145 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; |
| 15146 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 15147 | for (i = 0; i < tp->irq_max; i++) { |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15148 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 15149 | |
| 15150 | tnapi->tp = tp; |
| 15151 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; |
| 15152 | |
| 15153 | tnapi->int_mbox = intmbx; |
| 15154 | if (i < 4) |
| 15155 | intmbx += 0x8; |
| 15156 | else |
| 15157 | intmbx += 0x4; |
| 15158 | |
| 15159 | tnapi->consmbox = rcvmbx; |
| 15160 | tnapi->prodmbox = sndmbx; |
| 15161 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 15162 | if (i) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15163 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 15164 | else |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15165 | tnapi->coal_now = HOSTCC_MODE_NOW; |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15166 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15167 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15168 | break; |
| 15169 | |
| 15170 | /* |
| 15171 | * If we support MSIX, we'll be using RSS. If we're using |
| 15172 | * RSS, the first vector only handles link interrupts and the |
| 15173 | * remaining vectors handle rx and tx interrupts. Reuse the |
| 15174 | * mailbox values for the next iteration. The values we setup |
| 15175 | * above are still useful for the single vectored mode. |
| 15176 | */ |
| 15177 | if (!i) |
| 15178 | continue; |
| 15179 | |
| 15180 | rcvmbx += 0x8; |
| 15181 | |
| 15182 | if (sndmbx & 0x4) |
| 15183 | sndmbx -= 0x4; |
| 15184 | else |
| 15185 | sndmbx += 0xc; |
| 15186 | } |
| 15187 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 15188 | tg3_init_coal(tp); |
| 15189 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 15190 | pci_set_drvdata(pdev, dev); |
| 15191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15192 | err = register_netdev(dev); |
| 15193 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15194 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15195 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15196 | } |
| 15197 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15198 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
| 15199 | tp->board_part_number, |
| 15200 | tp->pci_chip_rev_id, |
| 15201 | tg3_bus_string(tp, str), |
| 15202 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15203 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15204 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 15205 | struct phy_device *phydev; |
| 15206 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 15207 | netdev_info(dev, |
| 15208 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15209 | phydev->drv->name, dev_name(&phydev->dev)); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15210 | } else { |
| 15211 | char *ethtype; |
| 15212 | |
| 15213 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 15214 | ethtype = "10/100Base-TX"; |
| 15215 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 15216 | ethtype = "1000Base-SX"; |
| 15217 | else |
| 15218 | ethtype = "10/100/1000Base-T"; |
| 15219 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 15220 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 15221 | "(WireSpeed[%d], EEE[%d])\n", |
| 15222 | tg3_phy_string(tp), ethtype, |
| 15223 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0, |
| 15224 | (tp->phy_flags & TG3_PHYFLG_EEE_CAP) != 0); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15225 | } |
Matt Carlson | df59c94 | 2008-11-03 16:52:56 -0800 | [diff] [blame] | 15226 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15227 | 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] | 15228 | (dev->features & NETIF_F_RXCSUM) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15229 | tg3_flag(tp, USE_LINKCHG_REG) != 0, |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15230 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15231 | tg3_flag(tp, ENABLE_ASF) != 0, |
| 15232 | tg3_flag(tp, TSO_CAPABLE) != 0); |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15233 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
| 15234 | tp->dma_rwctrl, |
| 15235 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : |
| 15236 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15237 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 15238 | pci_save_state(pdev); |
| 15239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15240 | return 0; |
| 15241 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15242 | err_out_apeunmap: |
| 15243 | if (tp->aperegs) { |
| 15244 | iounmap(tp->aperegs); |
| 15245 | tp->aperegs = NULL; |
| 15246 | } |
| 15247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15248 | err_out_iounmap: |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15249 | if (tp->regs) { |
| 15250 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 15251 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15253 | |
| 15254 | err_out_free_dev: |
| 15255 | free_netdev(dev); |
| 15256 | |
| 15257 | err_out_free_res: |
| 15258 | pci_release_regions(pdev); |
| 15259 | |
| 15260 | err_out_disable_pdev: |
| 15261 | pci_disable_device(pdev); |
| 15262 | pci_set_drvdata(pdev, NULL); |
| 15263 | return err; |
| 15264 | } |
| 15265 | |
| 15266 | static void __devexit tg3_remove_one(struct pci_dev *pdev) |
| 15267 | { |
| 15268 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15269 | |
| 15270 | if (dev) { |
| 15271 | struct tg3 *tp = netdev_priv(dev); |
| 15272 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 15273 | if (tp->fw) |
| 15274 | release_firmware(tp->fw); |
| 15275 | |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 15276 | cancel_work_sync(&tp->reset_task); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15277 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15278 | if (!tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15279 | tg3_phy_fini(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15280 | tg3_mdio_fini(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15281 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15283 | unregister_netdev(dev); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15284 | if (tp->aperegs) { |
| 15285 | iounmap(tp->aperegs); |
| 15286 | tp->aperegs = NULL; |
| 15287 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15288 | if (tp->regs) { |
| 15289 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 15290 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15291 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15292 | free_netdev(dev); |
| 15293 | pci_release_regions(pdev); |
| 15294 | pci_disable_device(pdev); |
| 15295 | pci_set_drvdata(pdev, NULL); |
| 15296 | } |
| 15297 | } |
| 15298 | |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 15299 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15300 | static int tg3_suspend(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15301 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15302 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15303 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15304 | struct tg3 *tp = netdev_priv(dev); |
| 15305 | int err; |
| 15306 | |
| 15307 | if (!netif_running(dev)) |
| 15308 | return 0; |
| 15309 | |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 15310 | flush_work_sync(&tp->reset_task); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15311 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15312 | tg3_netif_stop(tp); |
| 15313 | |
| 15314 | del_timer_sync(&tp->timer); |
| 15315 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15316 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15317 | tg3_disable_ints(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15318 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15319 | |
| 15320 | netif_device_detach(dev); |
| 15321 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15322 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 15323 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15324 | tg3_flag_clear(tp, INIT_COMPLETE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15325 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15326 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15327 | err = tg3_power_down_prepare(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15328 | if (err) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15329 | int err2; |
| 15330 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15331 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15332 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15333 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15334 | err2 = tg3_restart_hw(tp, 1); |
| 15335 | if (err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15336 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15337 | |
| 15338 | tp->timer.expires = jiffies + tp->timer_offset; |
| 15339 | add_timer(&tp->timer); |
| 15340 | |
| 15341 | netif_device_attach(dev); |
| 15342 | tg3_netif_start(tp); |
| 15343 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15344 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15345 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15346 | |
| 15347 | if (!err2) |
| 15348 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15349 | } |
| 15350 | |
| 15351 | return err; |
| 15352 | } |
| 15353 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15354 | static int tg3_resume(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15355 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15356 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15357 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15358 | struct tg3 *tp = netdev_priv(dev); |
| 15359 | int err; |
| 15360 | |
| 15361 | if (!netif_running(dev)) |
| 15362 | return 0; |
| 15363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15364 | netif_device_attach(dev); |
| 15365 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15366 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15367 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15368 | tg3_flag_set(tp, INIT_COMPLETE); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15369 | err = tg3_restart_hw(tp, 1); |
| 15370 | if (err) |
| 15371 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15372 | |
| 15373 | tp->timer.expires = jiffies + tp->timer_offset; |
| 15374 | add_timer(&tp->timer); |
| 15375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15376 | tg3_netif_start(tp); |
| 15377 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15378 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15379 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15380 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15381 | if (!err) |
| 15382 | tg3_phy_start(tp); |
| 15383 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15384 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15385 | } |
| 15386 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15387 | static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 15388 | #define TG3_PM_OPS (&tg3_pm_ops) |
| 15389 | |
| 15390 | #else |
| 15391 | |
| 15392 | #define TG3_PM_OPS NULL |
| 15393 | |
| 15394 | #endif /* CONFIG_PM_SLEEP */ |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15395 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 15396 | /** |
| 15397 | * tg3_io_error_detected - called when PCI error is detected |
| 15398 | * @pdev: Pointer to PCI device |
| 15399 | * @state: The current pci connection state |
| 15400 | * |
| 15401 | * This function is called after a PCI bus error affecting |
| 15402 | * this device has been detected. |
| 15403 | */ |
| 15404 | static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, |
| 15405 | pci_channel_state_t state) |
| 15406 | { |
| 15407 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 15408 | struct tg3 *tp = netdev_priv(netdev); |
| 15409 | pci_ers_result_t err = PCI_ERS_RESULT_NEED_RESET; |
| 15410 | |
| 15411 | netdev_info(netdev, "PCI I/O error detected\n"); |
| 15412 | |
| 15413 | rtnl_lock(); |
| 15414 | |
| 15415 | if (!netif_running(netdev)) |
| 15416 | goto done; |
| 15417 | |
| 15418 | tg3_phy_stop(tp); |
| 15419 | |
| 15420 | tg3_netif_stop(tp); |
| 15421 | |
| 15422 | del_timer_sync(&tp->timer); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15423 | tg3_flag_clear(tp, RESTART_TIMER); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 15424 | |
| 15425 | /* Want to make sure that the reset task doesn't run */ |
| 15426 | cancel_work_sync(&tp->reset_task); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15427 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
| 15428 | tg3_flag_clear(tp, RESTART_TIMER); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 15429 | |
| 15430 | netif_device_detach(netdev); |
| 15431 | |
| 15432 | /* Clean up software state, even if MMIO is blocked */ |
| 15433 | tg3_full_lock(tp, 0); |
| 15434 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 15435 | tg3_full_unlock(tp); |
| 15436 | |
| 15437 | done: |
| 15438 | if (state == pci_channel_io_perm_failure) |
| 15439 | err = PCI_ERS_RESULT_DISCONNECT; |
| 15440 | else |
| 15441 | pci_disable_device(pdev); |
| 15442 | |
| 15443 | rtnl_unlock(); |
| 15444 | |
| 15445 | return err; |
| 15446 | } |
| 15447 | |
| 15448 | /** |
| 15449 | * tg3_io_slot_reset - called after the pci bus has been reset. |
| 15450 | * @pdev: Pointer to PCI device |
| 15451 | * |
| 15452 | * Restart the card from scratch, as if from a cold-boot. |
| 15453 | * At this point, the card has exprienced a hard reset, |
| 15454 | * followed by fixups by BIOS, and has its config space |
| 15455 | * set up identically to what it was at cold boot. |
| 15456 | */ |
| 15457 | static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev) |
| 15458 | { |
| 15459 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 15460 | struct tg3 *tp = netdev_priv(netdev); |
| 15461 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 15462 | int err; |
| 15463 | |
| 15464 | rtnl_lock(); |
| 15465 | |
| 15466 | if (pci_enable_device(pdev)) { |
| 15467 | netdev_err(netdev, "Cannot re-enable PCI device after reset.\n"); |
| 15468 | goto done; |
| 15469 | } |
| 15470 | |
| 15471 | pci_set_master(pdev); |
| 15472 | pci_restore_state(pdev); |
| 15473 | pci_save_state(pdev); |
| 15474 | |
| 15475 | if (!netif_running(netdev)) { |
| 15476 | rc = PCI_ERS_RESULT_RECOVERED; |
| 15477 | goto done; |
| 15478 | } |
| 15479 | |
| 15480 | err = tg3_power_up(tp); |
| 15481 | if (err) { |
| 15482 | netdev_err(netdev, "Failed to restore register access.\n"); |
| 15483 | goto done; |
| 15484 | } |
| 15485 | |
| 15486 | rc = PCI_ERS_RESULT_RECOVERED; |
| 15487 | |
| 15488 | done: |
| 15489 | rtnl_unlock(); |
| 15490 | |
| 15491 | return rc; |
| 15492 | } |
| 15493 | |
| 15494 | /** |
| 15495 | * tg3_io_resume - called when traffic can start flowing again. |
| 15496 | * @pdev: Pointer to PCI device |
| 15497 | * |
| 15498 | * This callback is called when the error recovery driver tells |
| 15499 | * us that its OK to resume normal operation. |
| 15500 | */ |
| 15501 | static void tg3_io_resume(struct pci_dev *pdev) |
| 15502 | { |
| 15503 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 15504 | struct tg3 *tp = netdev_priv(netdev); |
| 15505 | int err; |
| 15506 | |
| 15507 | rtnl_lock(); |
| 15508 | |
| 15509 | if (!netif_running(netdev)) |
| 15510 | goto done; |
| 15511 | |
| 15512 | tg3_full_lock(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15513 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 15514 | err = tg3_restart_hw(tp, 1); |
| 15515 | tg3_full_unlock(tp); |
| 15516 | if (err) { |
| 15517 | netdev_err(netdev, "Cannot restart hardware after reset.\n"); |
| 15518 | goto done; |
| 15519 | } |
| 15520 | |
| 15521 | netif_device_attach(netdev); |
| 15522 | |
| 15523 | tp->timer.expires = jiffies + tp->timer_offset; |
| 15524 | add_timer(&tp->timer); |
| 15525 | |
| 15526 | tg3_netif_start(tp); |
| 15527 | |
| 15528 | tg3_phy_start(tp); |
| 15529 | |
| 15530 | done: |
| 15531 | rtnl_unlock(); |
| 15532 | } |
| 15533 | |
| 15534 | static struct pci_error_handlers tg3_err_handler = { |
| 15535 | .error_detected = tg3_io_error_detected, |
| 15536 | .slot_reset = tg3_io_slot_reset, |
| 15537 | .resume = tg3_io_resume |
| 15538 | }; |
| 15539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15540 | static struct pci_driver tg3_driver = { |
| 15541 | .name = DRV_MODULE_NAME, |
| 15542 | .id_table = tg3_pci_tbl, |
| 15543 | .probe = tg3_init_one, |
| 15544 | .remove = __devexit_p(tg3_remove_one), |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 15545 | .err_handler = &tg3_err_handler, |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 15546 | .driver.pm = TG3_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15547 | }; |
| 15548 | |
| 15549 | static int __init tg3_init(void) |
| 15550 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 15551 | return pci_register_driver(&tg3_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15552 | } |
| 15553 | |
| 15554 | static void __exit tg3_cleanup(void) |
| 15555 | { |
| 15556 | pci_unregister_driver(&tg3_driver); |
| 15557 | } |
| 15558 | |
| 15559 | module_init(tg3_init); |
| 15560 | module_exit(tg3_cleanup); |