Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * tg3.c: Broadcom Tigon3 ethernet driver. |
| 3 | * |
| 4 | * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com) |
| 5 | * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com) |
| 6 | * Copyright (C) 2004 Sun Microsystems Inc. |
Matt Carlson | 9e056c0 | 2012-02-13 15:20:17 +0000 | [diff] [blame] | 7 | * Copyright (C) 2005-2012 Broadcom Corporation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * Firmware is: |
Michael Chan | 49cabf4 | 2005-06-06 15:15:17 -0700 | [diff] [blame] | 10 | * Derived from proprietary unpublished source code, |
| 11 | * Copyright (C) 2000-2003 Broadcom Corporation. |
| 12 | * |
| 13 | * Permission is hereby granted for the distribution of this firmware |
| 14 | * data in hexadecimal or equivalent format, provided this copyright |
| 15 | * notice is accompanying it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/moduleparam.h> |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 21 | #include <linux/stringify.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/compiler.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/delay.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 27 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/init.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 29 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/ioport.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/etherdevice.h> |
| 34 | #include <linux/skbuff.h> |
| 35 | #include <linux/ethtool.h> |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 36 | #include <linux/mdio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/mii.h> |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 38 | #include <linux/phy.h> |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 39 | #include <linux/brcmphy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/if_vlan.h> |
| 41 | #include <linux/ip.h> |
| 42 | #include <linux/tcp.h> |
| 43 | #include <linux/workqueue.h> |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 44 | #include <linux/prefetch.h> |
Tobias Klauser | f9a5f7d | 2005-10-29 15:09:26 +0200 | [diff] [blame] | 45 | #include <linux/dma-mapping.h> |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 46 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | #include <net/checksum.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 49 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Javier Martinez Canillas | 27fd9de | 2011-03-26 16:42:31 +0000 | [diff] [blame] | 51 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/byteorder.h> |
Javier Martinez Canillas | 27fd9de | 2011-03-26 16:42:31 +0000 | [diff] [blame] | 53 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 55 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <asm/idprom.h> |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 57 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #endif |
| 59 | |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 60 | #define BAR_0 0 |
| 61 | #define BAR_2 2 |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #include "tg3.h" |
| 64 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 65 | /* Functions & macros to verify TG3_FLAGS types */ |
| 66 | |
| 67 | static inline int _tg3_flag(enum TG3_FLAGS flag, unsigned long *bits) |
| 68 | { |
| 69 | return test_bit(flag, bits); |
| 70 | } |
| 71 | |
| 72 | static inline void _tg3_flag_set(enum TG3_FLAGS flag, unsigned long *bits) |
| 73 | { |
| 74 | set_bit(flag, bits); |
| 75 | } |
| 76 | |
| 77 | static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits) |
| 78 | { |
| 79 | clear_bit(flag, bits); |
| 80 | } |
| 81 | |
| 82 | #define tg3_flag(tp, flag) \ |
| 83 | _tg3_flag(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 84 | #define tg3_flag_set(tp, flag) \ |
| 85 | _tg3_flag_set(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 86 | #define tg3_flag_clear(tp, flag) \ |
| 87 | _tg3_flag_clear(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #define DRV_MODULE_NAME "tg3" |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 90 | #define TG3_MAJ_NUM 3 |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 91 | #define TG3_MIN_NUM 123 |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 92 | #define DRV_MODULE_VERSION \ |
| 93 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 94 | #define DRV_MODULE_RELDATE "March 21, 2012" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 96 | #define RESET_KIND_SHUTDOWN 0 |
| 97 | #define RESET_KIND_INIT 1 |
| 98 | #define RESET_KIND_SUSPEND 2 |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #define TG3_DEF_RX_MODE 0 |
| 101 | #define TG3_DEF_TX_MODE 0 |
| 102 | #define TG3_DEF_MSG_ENABLE \ |
| 103 | (NETIF_MSG_DRV | \ |
| 104 | NETIF_MSG_PROBE | \ |
| 105 | NETIF_MSG_LINK | \ |
| 106 | NETIF_MSG_TIMER | \ |
| 107 | NETIF_MSG_IFDOWN | \ |
| 108 | NETIF_MSG_IFUP | \ |
| 109 | NETIF_MSG_RX_ERR | \ |
| 110 | NETIF_MSG_TX_ERR) |
| 111 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 112 | #define TG3_GRC_LCLCTL_PWRSW_DELAY 100 |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | /* length of time before we decide the hardware is borked, |
| 115 | * and dev->tx_timeout() should be called to fix the problem |
| 116 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #define TG3_TX_TIMEOUT (5 * HZ) |
| 119 | |
| 120 | /* hardware minimum and maximum for a single frame's data payload */ |
| 121 | #define TG3_MIN_MTU 60 |
| 122 | #define TG3_MAX_MTU(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 123 | (tg3_flag(tp, JUMBO_CAPABLE) ? 9000 : 1500) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | /* These numbers seem to be hard coded in the NIC firmware somehow. |
| 126 | * You can't change the ring sizes, but you can change where you place |
| 127 | * them in the NIC onboard memory. |
| 128 | */ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 129 | #define TG3_RX_STD_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 130 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 131 | TG3_RX_STD_MAX_SIZE_5717 : TG3_RX_STD_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #define TG3_DEF_RX_RING_PENDING 200 |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 133 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 134 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 135 | TG3_RX_JMB_MAX_SIZE_5717 : TG3_RX_JMB_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
| 137 | |
| 138 | /* Do not place this n-ring entries value into the tp struct itself, |
| 139 | * we really want to expose these constants to GCC so that modulo et |
| 140 | * al. operations are done with shifts and masks instead of with |
| 141 | * hw multiply/modulo instructions. Another solution would be to |
| 142 | * replace things like '% foo' with '& (foo - 1)'. |
| 143 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | #define TG3_TX_RING_SIZE 512 |
| 146 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) |
| 147 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 148 | #define TG3_RX_STD_RING_BYTES(tp) \ |
| 149 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) |
| 150 | #define TG3_RX_JMB_RING_BYTES(tp) \ |
| 151 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) |
| 152 | #define TG3_RX_RCB_RING_BYTES(tp) \ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 153 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
| 155 | TG3_TX_RING_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
| 157 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 158 | #define TG3_DMA_BYTE_ENAB 64 |
| 159 | |
| 160 | #define TG3_RX_STD_DMA_SZ 1536 |
| 161 | #define TG3_RX_JMB_DMA_SZ 9046 |
| 162 | |
| 163 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) |
| 164 | |
| 165 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) |
| 166 | #define TG3_RX_JMB_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_JMB_DMA_SZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 168 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
| 169 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 170 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 171 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
| 172 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 173 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 174 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
| 175 | * that are at least dword aligned when used in PCIX mode. The driver |
| 176 | * works around this bug by double copying the packet. This workaround |
| 177 | * is built into the normal double copy length check for efficiency. |
| 178 | * |
| 179 | * However, the double copy is only necessary on those architectures |
| 180 | * where unaligned memory accesses are inefficient. For those architectures |
| 181 | * where unaligned memory accesses incur little penalty, we can reintegrate |
| 182 | * the 5701 in the normal rx path. Doing so saves a device structure |
| 183 | * dereference by hardcoding the double copy threshold in place. |
| 184 | */ |
| 185 | #define TG3_RX_COPY_THRESHOLD 256 |
| 186 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 187 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD |
| 188 | #else |
| 189 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) |
| 190 | #endif |
| 191 | |
Matt Carlson | 81389f5 | 2011-08-31 11:44:49 +0000 | [diff] [blame] | 192 | #if (NET_IP_ALIGN != 0) |
| 193 | #define TG3_RX_OFFSET(tp) ((tp)->rx_offset) |
| 194 | #else |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 195 | #define TG3_RX_OFFSET(tp) (NET_SKB_PAD) |
Matt Carlson | 81389f5 | 2011-08-31 11:44:49 +0000 | [diff] [blame] | 196 | #endif |
| 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | /* minimum number of free TX descriptors required to wake up TX process */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 199 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 200 | #define TG3_TX_BD_DMA_MAX_2K 2048 |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 201 | #define TG3_TX_BD_DMA_MAX_4K 4096 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 203 | #define TG3_RAW_IP_ALIGN 2 |
| 204 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 205 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 206 | #define TG3_FW_UPDATE_FREQ_SEC (TG3_FW_UPDATE_TIMEOUT_SEC / 2) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 207 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 208 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
| 209 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
| 210 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" |
| 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | static char version[] __devinitdata = |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 213 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); |
| 216 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); |
| 217 | MODULE_LICENSE("GPL"); |
| 218 | MODULE_VERSION(DRV_MODULE_VERSION); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 219 | MODULE_FIRMWARE(FIRMWARE_TG3); |
| 220 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); |
| 221 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); |
| 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
| 224 | module_param(tg3_debug, int, 0); |
| 225 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); |
| 226 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 227 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 228 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
| 229 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, |
| 230 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, |
| 231 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, |
| 232 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, |
| 233 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, |
| 234 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, |
| 235 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, |
| 236 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, |
| 237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, |
| 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, |
| 239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, |
| 240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, |
| 241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, |
| 242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, |
| 243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, |
| 244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, |
| 245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, |
| 246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)}, |
| 247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)}, |
| 248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, |
| 249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
| 254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)}, |
| 255 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
| 256 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, |
| 257 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, |
| 258 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, |
| 259 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)}, |
| 260 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
| 261 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, |
| 262 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, |
| 263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 264 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 265 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
| 266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, |
| 267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
| 270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, |
| 271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, |
| 272 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, |
| 273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, |
| 274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, |
| 275 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
| 277 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 278 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
| 279 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
Matt Carlson | 6c7af27 | 2007-10-21 16:12:02 -0700 | [diff] [blame] | 280 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 281 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
| 282 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
Matt Carlson | c88e668 | 2008-11-03 16:49:18 -0800 | [diff] [blame] | 283 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
| 284 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, |
Matt Carlson | 2befdce | 2009-08-28 12:28:45 +0000 | [diff] [blame] | 285 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
| 286 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 287 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
| 288 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, |
| 289 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790)}, |
Matt Carlson | 5e7ccf2 | 2009-08-25 10:08:42 +0000 | [diff] [blame] | 290 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 291 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
| 292 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
Matt Carlson | b0f7522 | 2010-01-20 16:58:11 +0000 | [diff] [blame] | 293 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
| 294 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, |
| 295 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, |
| 296 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, |
| 297 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791)}, |
| 298 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)}, |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 299 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
Matt Carlson | ba1f3c7 | 2011-04-05 14:22:50 +0000 | [diff] [blame] | 300 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, |
Greg KH | 02eca3f | 2012-07-12 15:39:44 +0000 | [diff] [blame^] | 301 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57762)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 302 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
| 303 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, |
| 304 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, |
| 305 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, |
| 306 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, |
| 307 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, |
| 308 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, |
Meelis Roos | 1dcb14d | 2011-05-25 05:43:47 +0000 | [diff] [blame] | 309 | {PCI_DEVICE(0x10cf, 0x11a2)}, /* Fujitsu 1000base-SX with BCM5703SKHB */ |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 310 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
| 313 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); |
| 314 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 315 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 317 | } ethtool_stats_keys[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { "rx_octets" }, |
| 319 | { "rx_fragments" }, |
| 320 | { "rx_ucast_packets" }, |
| 321 | { "rx_mcast_packets" }, |
| 322 | { "rx_bcast_packets" }, |
| 323 | { "rx_fcs_errors" }, |
| 324 | { "rx_align_errors" }, |
| 325 | { "rx_xon_pause_rcvd" }, |
| 326 | { "rx_xoff_pause_rcvd" }, |
| 327 | { "rx_mac_ctrl_rcvd" }, |
| 328 | { "rx_xoff_entered" }, |
| 329 | { "rx_frame_too_long_errors" }, |
| 330 | { "rx_jabbers" }, |
| 331 | { "rx_undersize_packets" }, |
| 332 | { "rx_in_length_errors" }, |
| 333 | { "rx_out_length_errors" }, |
| 334 | { "rx_64_or_less_octet_packets" }, |
| 335 | { "rx_65_to_127_octet_packets" }, |
| 336 | { "rx_128_to_255_octet_packets" }, |
| 337 | { "rx_256_to_511_octet_packets" }, |
| 338 | { "rx_512_to_1023_octet_packets" }, |
| 339 | { "rx_1024_to_1522_octet_packets" }, |
| 340 | { "rx_1523_to_2047_octet_packets" }, |
| 341 | { "rx_2048_to_4095_octet_packets" }, |
| 342 | { "rx_4096_to_8191_octet_packets" }, |
| 343 | { "rx_8192_to_9022_octet_packets" }, |
| 344 | |
| 345 | { "tx_octets" }, |
| 346 | { "tx_collisions" }, |
| 347 | |
| 348 | { "tx_xon_sent" }, |
| 349 | { "tx_xoff_sent" }, |
| 350 | { "tx_flow_control" }, |
| 351 | { "tx_mac_errors" }, |
| 352 | { "tx_single_collisions" }, |
| 353 | { "tx_mult_collisions" }, |
| 354 | { "tx_deferred" }, |
| 355 | { "tx_excessive_collisions" }, |
| 356 | { "tx_late_collisions" }, |
| 357 | { "tx_collide_2times" }, |
| 358 | { "tx_collide_3times" }, |
| 359 | { "tx_collide_4times" }, |
| 360 | { "tx_collide_5times" }, |
| 361 | { "tx_collide_6times" }, |
| 362 | { "tx_collide_7times" }, |
| 363 | { "tx_collide_8times" }, |
| 364 | { "tx_collide_9times" }, |
| 365 | { "tx_collide_10times" }, |
| 366 | { "tx_collide_11times" }, |
| 367 | { "tx_collide_12times" }, |
| 368 | { "tx_collide_13times" }, |
| 369 | { "tx_collide_14times" }, |
| 370 | { "tx_collide_15times" }, |
| 371 | { "tx_ucast_packets" }, |
| 372 | { "tx_mcast_packets" }, |
| 373 | { "tx_bcast_packets" }, |
| 374 | { "tx_carrier_sense_errors" }, |
| 375 | { "tx_discards" }, |
| 376 | { "tx_errors" }, |
| 377 | |
| 378 | { "dma_writeq_full" }, |
| 379 | { "dma_write_prioq_full" }, |
| 380 | { "rxbds_empty" }, |
| 381 | { "rx_discards" }, |
| 382 | { "rx_errors" }, |
| 383 | { "rx_threshold_hit" }, |
| 384 | |
| 385 | { "dma_readq_full" }, |
| 386 | { "dma_read_prioq_full" }, |
| 387 | { "tx_comp_queue_full" }, |
| 388 | |
| 389 | { "ring_set_send_prod_index" }, |
| 390 | { "ring_status_update" }, |
| 391 | { "nic_irqs" }, |
| 392 | { "nic_avoided_irqs" }, |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 393 | { "nic_tx_threshold_hit" }, |
| 394 | |
| 395 | { "mbuf_lwm_thresh_hit" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | }; |
| 397 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 398 | #define TG3_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) |
| 399 | |
| 400 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 401 | static const struct { |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 402 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 403 | } ethtool_test_keys[] = { |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 404 | { "nvram test (online) " }, |
| 405 | { "link test (online) " }, |
| 406 | { "register test (offline)" }, |
| 407 | { "memory test (offline)" }, |
| 408 | { "mac loopback test (offline)" }, |
| 409 | { "phy loopback test (offline)" }, |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 410 | { "ext loopback test (offline)" }, |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 411 | { "interrupt test (offline)" }, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 412 | }; |
| 413 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 414 | #define TG3_NUM_TEST ARRAY_SIZE(ethtool_test_keys) |
| 415 | |
| 416 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 417 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
| 418 | { |
| 419 | writel(val, tp->regs + off); |
| 420 | } |
| 421 | |
| 422 | static u32 tg3_read32(struct tg3 *tp, u32 off) |
| 423 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 424 | return readl(tp->regs + off); |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 427 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
| 428 | { |
| 429 | writel(val, tp->aperegs + off); |
| 430 | } |
| 431 | |
| 432 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) |
| 433 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 434 | return readl(tp->aperegs + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
| 438 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 439 | unsigned long flags; |
| 440 | |
| 441 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 442 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 443 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 444 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) |
| 448 | { |
| 449 | writel(val, tp->regs + off); |
| 450 | readl(tp->regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 453 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
| 454 | { |
| 455 | unsigned long flags; |
| 456 | u32 val; |
| 457 | |
| 458 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 459 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 460 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 461 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 462 | return val; |
| 463 | } |
| 464 | |
| 465 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) |
| 466 | { |
| 467 | unsigned long flags; |
| 468 | |
| 469 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { |
| 470 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + |
| 471 | TG3_64BIT_REG_LOW, val); |
| 472 | return; |
| 473 | } |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 474 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 475 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
| 476 | TG3_64BIT_REG_LOW, val); |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 481 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 482 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 483 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 484 | |
| 485 | /* In indirect mode when disabling interrupts, we also need |
| 486 | * to clear the interrupt bit in the GRC local ctrl register. |
| 487 | */ |
| 488 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && |
| 489 | (val == 0x1)) { |
| 490 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, |
| 491 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) |
| 496 | { |
| 497 | unsigned long flags; |
| 498 | u32 val; |
| 499 | |
| 500 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 501 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 502 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 503 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 504 | return val; |
| 505 | } |
| 506 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 507 | /* usec_wait specifies the wait time in usec when writing to certain registers |
| 508 | * where it is unsafe to read back the register without some delay. |
| 509 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. |
| 510 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. |
| 511 | */ |
| 512 | 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] | 513 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 514 | if (tg3_flag(tp, PCIX_TARGET_HWBUG) || tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 515 | /* Non-posted methods */ |
| 516 | tp->write32(tp, off, val); |
| 517 | else { |
| 518 | /* Posted method */ |
| 519 | tg3_write32(tp, off, val); |
| 520 | if (usec_wait) |
| 521 | udelay(usec_wait); |
| 522 | tp->read32(tp, off); |
| 523 | } |
| 524 | /* Wait again after the read for the posted method to guarantee that |
| 525 | * the wait time is met. |
| 526 | */ |
| 527 | if (usec_wait) |
| 528 | udelay(usec_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 531 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
| 532 | { |
| 533 | tp->write32_mbox(tp, off, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 534 | if (!tg3_flag(tp, MBOX_WRITE_REORDER) && !tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 535 | tp->read32_mbox(tp, off); |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 538 | 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] | 539 | { |
| 540 | void __iomem *mbox = tp->regs + off; |
| 541 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 542 | if (tg3_flag(tp, TXD_MBOX_HWBUG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 544 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | readl(mbox); |
| 546 | } |
| 547 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 548 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
| 549 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 550 | return readl(tp->regs + off + GRCMBOX_BASE); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) |
| 554 | { |
| 555 | writel(val, tp->regs + off + GRCMBOX_BASE); |
| 556 | } |
| 557 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 558 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 559 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 560 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
| 561 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) |
| 562 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 563 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 564 | #define tw32(reg, val) tp->write32(tp, reg, val) |
| 565 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) |
| 566 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) |
| 567 | #define tr32(reg) tp->read32(tp, reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) |
| 570 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 571 | unsigned long flags; |
| 572 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 573 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 574 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
| 575 | return; |
| 576 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 577 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 578 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 579 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 580 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 582 | /* Always leave this as zero. */ |
| 583 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 584 | } else { |
| 585 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 586 | tw32_f(TG3PCI_MEM_WIN_DATA, val); |
| 587 | |
| 588 | /* Always leave this as zero. */ |
| 589 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 590 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 591 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
| 595 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 596 | unsigned long flags; |
| 597 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 598 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 599 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
| 600 | *val = 0; |
| 601 | return; |
| 602 | } |
| 603 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 604 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 605 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 606 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 607 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 609 | /* Always leave this as zero. */ |
| 610 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 611 | } else { |
| 612 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 613 | *val = tr32(TG3PCI_MEM_WIN_DATA); |
| 614 | |
| 615 | /* Always leave this as zero. */ |
| 616 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 617 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 618 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 621 | static void tg3_ape_lock_init(struct tg3 *tp) |
| 622 | { |
| 623 | int i; |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 624 | u32 regbase, bit; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 625 | |
| 626 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 627 | regbase = TG3_APE_LOCK_GRANT; |
| 628 | else |
| 629 | regbase = TG3_APE_PER_LOCK_GRANT; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 630 | |
| 631 | /* Make sure the driver hasn't any stale locks. */ |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 632 | for (i = TG3_APE_LOCK_PHY0; i <= TG3_APE_LOCK_GPIO; i++) { |
| 633 | switch (i) { |
| 634 | case TG3_APE_LOCK_PHY0: |
| 635 | case TG3_APE_LOCK_PHY1: |
| 636 | case TG3_APE_LOCK_PHY2: |
| 637 | case TG3_APE_LOCK_PHY3: |
| 638 | bit = APE_LOCK_GRANT_DRIVER; |
| 639 | break; |
| 640 | default: |
| 641 | if (!tp->pci_fn) |
| 642 | bit = APE_LOCK_GRANT_DRIVER; |
| 643 | else |
| 644 | bit = 1 << tp->pci_fn; |
| 645 | } |
| 646 | tg3_ape_write32(tp, regbase + 4 * i, bit); |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static int tg3_ape_lock(struct tg3 *tp, int locknum) |
| 652 | { |
| 653 | int i, off; |
| 654 | int ret = 0; |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 655 | u32 status, req, gnt, bit; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 656 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 657 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 658 | return 0; |
| 659 | |
| 660 | switch (locknum) { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 661 | case TG3_APE_LOCK_GPIO: |
| 662 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 663 | return 0; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 664 | case TG3_APE_LOCK_GRC: |
| 665 | case TG3_APE_LOCK_MEM: |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 666 | if (!tp->pci_fn) |
| 667 | bit = APE_LOCK_REQ_DRIVER; |
| 668 | else |
| 669 | bit = 1 << tp->pci_fn; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 670 | break; |
| 671 | default: |
| 672 | return -EINVAL; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 675 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
| 676 | req = TG3_APE_LOCK_REQ; |
| 677 | gnt = TG3_APE_LOCK_GRANT; |
| 678 | } else { |
| 679 | req = TG3_APE_PER_LOCK_REQ; |
| 680 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 681 | } |
| 682 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 683 | off = 4 * locknum; |
| 684 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 685 | tg3_ape_write32(tp, req + off, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 686 | |
| 687 | /* Wait for up to 1 millisecond to acquire lock. */ |
| 688 | for (i = 0; i < 100; i++) { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 689 | status = tg3_ape_read32(tp, gnt + off); |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 690 | if (status == bit) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 691 | break; |
| 692 | udelay(10); |
| 693 | } |
| 694 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 695 | if (status != bit) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 696 | /* Revoke the lock request. */ |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 697 | tg3_ape_write32(tp, gnt + off, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 698 | ret = -EBUSY; |
| 699 | } |
| 700 | |
| 701 | return ret; |
| 702 | } |
| 703 | |
| 704 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) |
| 705 | { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 706 | u32 gnt, bit; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 707 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 708 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 709 | return; |
| 710 | |
| 711 | switch (locknum) { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 712 | case TG3_APE_LOCK_GPIO: |
| 713 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 714 | return; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 715 | case TG3_APE_LOCK_GRC: |
| 716 | case TG3_APE_LOCK_MEM: |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 717 | if (!tp->pci_fn) |
| 718 | bit = APE_LOCK_GRANT_DRIVER; |
| 719 | else |
| 720 | bit = 1 << tp->pci_fn; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 721 | break; |
| 722 | default: |
| 723 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 726 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 727 | gnt = TG3_APE_LOCK_GRANT; |
| 728 | else |
| 729 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 730 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 731 | tg3_ape_write32(tp, gnt + 4 * locknum, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 734 | static void tg3_ape_send_event(struct tg3 *tp, u32 event) |
| 735 | { |
| 736 | int i; |
| 737 | u32 apedata; |
| 738 | |
| 739 | /* NCSI does not support APE events */ |
| 740 | if (tg3_flag(tp, APE_HAS_NCSI)) |
| 741 | return; |
| 742 | |
| 743 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 744 | if (apedata != APE_SEG_SIG_MAGIC) |
| 745 | return; |
| 746 | |
| 747 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 748 | if (!(apedata & APE_FW_STATUS_READY)) |
| 749 | return; |
| 750 | |
| 751 | /* Wait for up to 1 millisecond for APE to service previous event. */ |
| 752 | for (i = 0; i < 10; i++) { |
| 753 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) |
| 754 | return; |
| 755 | |
| 756 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 757 | |
| 758 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 759 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
| 760 | event | APE_EVENT_STATUS_EVENT_PENDING); |
| 761 | |
| 762 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 763 | |
| 764 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 765 | break; |
| 766 | |
| 767 | udelay(100); |
| 768 | } |
| 769 | |
| 770 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 771 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 772 | } |
| 773 | |
| 774 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
| 775 | { |
| 776 | u32 event; |
| 777 | u32 apedata; |
| 778 | |
| 779 | if (!tg3_flag(tp, ENABLE_APE)) |
| 780 | return; |
| 781 | |
| 782 | switch (kind) { |
| 783 | case RESET_KIND_INIT: |
| 784 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, |
| 785 | APE_HOST_SEG_SIG_MAGIC); |
| 786 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, |
| 787 | APE_HOST_SEG_LEN_MAGIC); |
| 788 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); |
| 789 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); |
| 790 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, |
| 791 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
| 792 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
| 793 | APE_HOST_BEHAV_NO_PHYLOCK); |
| 794 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, |
| 795 | TG3_APE_HOST_DRVR_STATE_START); |
| 796 | |
| 797 | event = APE_EVENT_STATUS_STATE_START; |
| 798 | break; |
| 799 | case RESET_KIND_SHUTDOWN: |
| 800 | /* With the interface we are currently using, |
| 801 | * APE does not track driver state. Wiping |
| 802 | * out the HOST SEGMENT SIGNATURE forces |
| 803 | * the APE to assume OS absent status. |
| 804 | */ |
| 805 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); |
| 806 | |
| 807 | if (device_may_wakeup(&tp->pdev->dev) && |
| 808 | tg3_flag(tp, WOL_ENABLE)) { |
| 809 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, |
| 810 | TG3_APE_HOST_WOL_SPEED_AUTO); |
| 811 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; |
| 812 | } else |
| 813 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; |
| 814 | |
| 815 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); |
| 816 | |
| 817 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
| 818 | break; |
| 819 | case RESET_KIND_SUSPEND: |
| 820 | event = APE_EVENT_STATUS_STATE_SUSPEND; |
| 821 | break; |
| 822 | default: |
| 823 | return; |
| 824 | } |
| 825 | |
| 826 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; |
| 827 | |
| 828 | tg3_ape_send_event(tp, event); |
| 829 | } |
| 830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | static void tg3_disable_ints(struct tg3 *tp) |
| 832 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 833 | int i; |
| 834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 836 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 837 | for (i = 0; i < tp->irq_max; i++) |
| 838 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | static void tg3_enable_ints(struct tg3 *tp) |
| 842 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 843 | int i; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 844 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 845 | tp->irq_sync = 0; |
| 846 | wmb(); |
| 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 849 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 850 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 851 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 852 | for (i = 0; i < tp->irq_cnt; i++) { |
| 853 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 854 | |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 855 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 856 | if (tg3_flag(tp, 1SHOT_MSI)) |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 857 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 858 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 859 | tp->coal_now |= tnapi->coal_now; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 860 | } |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 861 | |
| 862 | /* Force an initial interrupt */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 863 | if (!tg3_flag(tp, TAGGED_STATUS) && |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 864 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
| 865 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 866 | else |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 867 | tw32(HOSTCC_MODE, tp->coal_now); |
| 868 | |
| 869 | 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] | 870 | } |
| 871 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 872 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 873 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 874 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 875 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 876 | unsigned int work_exists = 0; |
| 877 | |
| 878 | /* check for phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 879 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 880 | if (sblk->status & SD_STATUS_LINK_CHG) |
| 881 | work_exists = 1; |
| 882 | } |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 883 | |
| 884 | /* check for TX work to do */ |
| 885 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons) |
| 886 | work_exists = 1; |
| 887 | |
| 888 | /* check for RX work to do */ |
| 889 | if (tnapi->rx_rcb_prod_idx && |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 890 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 891 | work_exists = 1; |
| 892 | |
| 893 | return work_exists; |
| 894 | } |
| 895 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 896 | /* tg3_int_reenable |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 897 | * similar to tg3_enable_ints, but it accurately determines whether there |
| 898 | * is new work pending and can return without flushing the PIO write |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 899 | * which reenables interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 901 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 903 | struct tg3 *tp = tnapi->tp; |
| 904 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 905 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | mmiowb(); |
| 907 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 908 | /* When doing tagged status, this work check is unnecessary. |
| 909 | * The last_tag we write above tells the chip which piece of |
| 910 | * work we've completed. |
| 911 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 912 | if (!tg3_flag(tp, TAGGED_STATUS) && tg3_has_work(tnapi)) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 913 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 914 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | static void tg3_switch_clocks(struct tg3 *tp) |
| 918 | { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 919 | u32 clock_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | u32 orig_clock_ctrl; |
| 921 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 922 | if (tg3_flag(tp, CPMU_PRESENT) || tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 923 | return; |
| 924 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 925 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
| 926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | orig_clock_ctrl = clock_ctrl; |
| 928 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | |
| 929 | CLOCK_CTRL_CLKRUN_OENABLE | |
| 930 | 0x1f); |
| 931 | tp->pci_clock_ctrl = clock_ctrl; |
| 932 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 933 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 935 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 936 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
| 938 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 939 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 940 | clock_ctrl | |
| 941 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), |
| 942 | 40); |
| 943 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 944 | clock_ctrl | (CLOCK_CTRL_ALTCLK), |
| 945 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 947 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | #define PHY_BUSY_LOOPS 5000 |
| 951 | |
| 952 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
| 953 | { |
| 954 | u32 frame_val; |
| 955 | unsigned int loops; |
| 956 | int ret; |
| 957 | |
| 958 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 959 | tw32_f(MAC_MI_MODE, |
| 960 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 961 | udelay(80); |
| 962 | } |
| 963 | |
| 964 | *val = 0x0; |
| 965 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 966 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | MI_COM_PHY_ADDR_MASK); |
| 968 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 969 | MI_COM_REG_ADDR_MASK); |
| 970 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | tw32_f(MAC_MI_COM, frame_val); |
| 973 | |
| 974 | loops = PHY_BUSY_LOOPS; |
| 975 | while (loops != 0) { |
| 976 | udelay(10); |
| 977 | frame_val = tr32(MAC_MI_COM); |
| 978 | |
| 979 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 980 | udelay(5); |
| 981 | frame_val = tr32(MAC_MI_COM); |
| 982 | break; |
| 983 | } |
| 984 | loops -= 1; |
| 985 | } |
| 986 | |
| 987 | ret = -EBUSY; |
| 988 | if (loops != 0) { |
| 989 | *val = frame_val & MI_COM_DATA_MASK; |
| 990 | ret = 0; |
| 991 | } |
| 992 | |
| 993 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 994 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 995 | udelay(80); |
| 996 | } |
| 997 | |
| 998 | return ret; |
| 999 | } |
| 1000 | |
| 1001 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
| 1002 | { |
| 1003 | u32 frame_val; |
| 1004 | unsigned int loops; |
| 1005 | int ret; |
| 1006 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1007 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 1008 | (reg == MII_CTRL1000 || reg == MII_TG3_AUX_CTRL)) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 1009 | return 0; |
| 1010 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1012 | tw32_f(MAC_MI_MODE, |
| 1013 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 1014 | udelay(80); |
| 1015 | } |
| 1016 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1017 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | MI_COM_PHY_ADDR_MASK); |
| 1019 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 1020 | MI_COM_REG_ADDR_MASK); |
| 1021 | frame_val |= (val & MI_COM_DATA_MASK); |
| 1022 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | tw32_f(MAC_MI_COM, frame_val); |
| 1025 | |
| 1026 | loops = PHY_BUSY_LOOPS; |
| 1027 | while (loops != 0) { |
| 1028 | udelay(10); |
| 1029 | frame_val = tr32(MAC_MI_COM); |
| 1030 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 1031 | udelay(5); |
| 1032 | frame_val = tr32(MAC_MI_COM); |
| 1033 | break; |
| 1034 | } |
| 1035 | loops -= 1; |
| 1036 | } |
| 1037 | |
| 1038 | ret = -EBUSY; |
| 1039 | if (loops != 0) |
| 1040 | ret = 0; |
| 1041 | |
| 1042 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1043 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1044 | udelay(80); |
| 1045 | } |
| 1046 | |
| 1047 | return ret; |
| 1048 | } |
| 1049 | |
Matt Carlson | b0988c1 | 2011-04-20 07:57:39 +0000 | [diff] [blame] | 1050 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
| 1051 | { |
| 1052 | int err; |
| 1053 | |
| 1054 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1055 | if (err) |
| 1056 | goto done; |
| 1057 | |
| 1058 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1059 | if (err) |
| 1060 | goto done; |
| 1061 | |
| 1062 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1063 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1064 | if (err) |
| 1065 | goto done; |
| 1066 | |
| 1067 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1068 | |
| 1069 | done: |
| 1070 | return err; |
| 1071 | } |
| 1072 | |
| 1073 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) |
| 1074 | { |
| 1075 | int err; |
| 1076 | |
| 1077 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1078 | if (err) |
| 1079 | goto done; |
| 1080 | |
| 1081 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1082 | if (err) |
| 1083 | goto done; |
| 1084 | |
| 1085 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1086 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1087 | if (err) |
| 1088 | goto done; |
| 1089 | |
| 1090 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1091 | |
| 1092 | done: |
| 1093 | return err; |
| 1094 | } |
| 1095 | |
| 1096 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) |
| 1097 | { |
| 1098 | int err; |
| 1099 | |
| 1100 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1101 | if (!err) |
| 1102 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1103 | |
| 1104 | return err; |
| 1105 | } |
| 1106 | |
| 1107 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
| 1108 | { |
| 1109 | int err; |
| 1110 | |
| 1111 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1112 | if (!err) |
| 1113 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1114 | |
| 1115 | return err; |
| 1116 | } |
| 1117 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 1118 | static int tg3_phy_auxctl_read(struct tg3 *tp, int reg, u32 *val) |
| 1119 | { |
| 1120 | int err; |
| 1121 | |
| 1122 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 1123 | (reg << MII_TG3_AUXCTL_MISC_RDSEL_SHIFT) | |
| 1124 | MII_TG3_AUXCTL_SHDWSEL_MISC); |
| 1125 | if (!err) |
| 1126 | err = tg3_readphy(tp, MII_TG3_AUX_CTRL, val); |
| 1127 | |
| 1128 | return err; |
| 1129 | } |
| 1130 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 1131 | static int tg3_phy_auxctl_write(struct tg3 *tp, int reg, u32 set) |
| 1132 | { |
| 1133 | if (reg == MII_TG3_AUXCTL_SHDWSEL_MISC) |
| 1134 | set |= MII_TG3_AUXCTL_MISC_WREN; |
| 1135 | |
| 1136 | return tg3_writephy(tp, MII_TG3_AUX_CTRL, set | reg); |
| 1137 | } |
| 1138 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 1139 | #define TG3_PHY_AUXCTL_SMDSP_ENABLE(tp) \ |
| 1140 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ |
| 1141 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | \ |
| 1142 | MII_TG3_AUXCTL_ACTL_TX_6DB) |
| 1143 | |
| 1144 | #define TG3_PHY_AUXCTL_SMDSP_DISABLE(tp) \ |
| 1145 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ |
| 1146 | MII_TG3_AUXCTL_ACTL_TX_6DB); |
| 1147 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1148 | static int tg3_bmcr_reset(struct tg3 *tp) |
| 1149 | { |
| 1150 | u32 phy_control; |
| 1151 | int limit, err; |
| 1152 | |
| 1153 | /* OK, reset it, and poll the BMCR_RESET bit until it |
| 1154 | * clears or we time out. |
| 1155 | */ |
| 1156 | phy_control = BMCR_RESET; |
| 1157 | err = tg3_writephy(tp, MII_BMCR, phy_control); |
| 1158 | if (err != 0) |
| 1159 | return -EBUSY; |
| 1160 | |
| 1161 | limit = 5000; |
| 1162 | while (limit--) { |
| 1163 | err = tg3_readphy(tp, MII_BMCR, &phy_control); |
| 1164 | if (err != 0) |
| 1165 | return -EBUSY; |
| 1166 | |
| 1167 | if ((phy_control & BMCR_RESET) == 0) { |
| 1168 | udelay(40); |
| 1169 | break; |
| 1170 | } |
| 1171 | udelay(10); |
| 1172 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 1173 | if (limit < 0) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1174 | return -EBUSY; |
| 1175 | |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1179 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
| 1180 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1181 | struct tg3 *tp = bp->priv; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1182 | u32 val; |
| 1183 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1184 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1185 | |
| 1186 | if (tg3_readphy(tp, reg, &val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1187 | val = -EIO; |
| 1188 | |
| 1189 | spin_unlock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1190 | |
| 1191 | return val; |
| 1192 | } |
| 1193 | |
| 1194 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) |
| 1195 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1196 | struct tg3 *tp = bp->priv; |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1197 | u32 ret = 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1198 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1199 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1200 | |
| 1201 | if (tg3_writephy(tp, reg, val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1202 | ret = -EIO; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1203 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1204 | spin_unlock_bh(&tp->lock); |
| 1205 | |
| 1206 | return ret; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | static int tg3_mdio_reset(struct mii_bus *bp) |
| 1210 | { |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1214 | static void tg3_mdio_config_5785(struct tg3 *tp) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1215 | { |
| 1216 | u32 val; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1217 | struct phy_device *phydev; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -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 | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1220 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1221 | case PHY_ID_BCM50610: |
| 1222 | case PHY_ID_BCM50610M: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1223 | val = MAC_PHYCFG2_50610_LED_MODES; |
| 1224 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1225 | case PHY_ID_BCMAC131: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1226 | val = MAC_PHYCFG2_AC131_LED_MODES; |
| 1227 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1228 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1229 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
| 1230 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1231 | case PHY_ID_RTL8201E: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1232 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
| 1233 | break; |
| 1234 | default: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1235 | return; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { |
| 1239 | tw32(MAC_PHYCFG2, val); |
| 1240 | |
| 1241 | val = tr32(MAC_PHYCFG1); |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1242 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
| 1243 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); |
| 1244 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1245 | tw32(MAC_PHYCFG1, val); |
| 1246 | |
| 1247 | return; |
| 1248 | } |
| 1249 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1250 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1251 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
| 1252 | MAC_PHYCFG2_FMODE_MASK_MASK | |
| 1253 | MAC_PHYCFG2_GMODE_MASK_MASK | |
| 1254 | MAC_PHYCFG2_ACT_MASK_MASK | |
| 1255 | MAC_PHYCFG2_QUAL_MASK_MASK | |
| 1256 | MAC_PHYCFG2_INBAND_ENABLE; |
| 1257 | |
| 1258 | tw32(MAC_PHYCFG2, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1259 | |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1260 | val = tr32(MAC_PHYCFG1); |
| 1261 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | |
| 1262 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1263 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1264 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1265 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1266 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1267 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
| 1268 | } |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1269 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
| 1270 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; |
| 1271 | tw32(MAC_PHYCFG1, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1272 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1273 | val = tr32(MAC_EXT_RGMII_MODE); |
| 1274 | val &= ~(MAC_RGMII_MODE_RX_INT_B | |
| 1275 | MAC_RGMII_MODE_RX_QUALITY | |
| 1276 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1277 | MAC_RGMII_MODE_RX_ENG_DET | |
| 1278 | MAC_RGMII_MODE_TX_ENABLE | |
| 1279 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1280 | MAC_RGMII_MODE_TX_RESET); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1281 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1282 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1283 | val |= MAC_RGMII_MODE_RX_INT_B | |
| 1284 | MAC_RGMII_MODE_RX_QUALITY | |
| 1285 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1286 | MAC_RGMII_MODE_RX_ENG_DET; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1287 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1288 | val |= MAC_RGMII_MODE_TX_ENABLE | |
| 1289 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1290 | MAC_RGMII_MODE_TX_RESET; |
| 1291 | } |
| 1292 | tw32(MAC_EXT_RGMII_MODE, val); |
| 1293 | } |
| 1294 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1295 | static void tg3_mdio_start(struct tg3 *tp) |
| 1296 | { |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1297 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
| 1298 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1299 | udelay(80); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1300 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1301 | if (tg3_flag(tp, MDIOBUS_INITED) && |
Matt Carlson | 9ea4818 | 2010-02-17 15:17:01 +0000 | [diff] [blame] | 1302 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1303 | tg3_mdio_config_5785(tp); |
| 1304 | } |
| 1305 | |
| 1306 | static int tg3_mdio_init(struct tg3 *tp) |
| 1307 | { |
| 1308 | int i; |
| 1309 | u32 reg; |
| 1310 | struct phy_device *phydev; |
| 1311 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1312 | if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1313 | u32 is_serdes; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1314 | |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 1315 | tp->phy_addr = tp->pci_fn + 1; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1316 | |
Matt Carlson | d1ec96a | 2010-01-12 10:11:38 +0000 | [diff] [blame] | 1317 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
| 1318 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
| 1319 | else |
| 1320 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & |
| 1321 | TG3_CPMU_PHY_STRAP_IS_SERDES; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1322 | if (is_serdes) |
| 1323 | tp->phy_addr += 7; |
| 1324 | } else |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1325 | tp->phy_addr = TG3_PHY_MII_ADDR; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1326 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1327 | tg3_mdio_start(tp); |
| 1328 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1329 | if (!tg3_flag(tp, USE_PHYLIB) || tg3_flag(tp, MDIOBUS_INITED)) |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1330 | return 0; |
| 1331 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1332 | tp->mdio_bus = mdiobus_alloc(); |
| 1333 | if (tp->mdio_bus == NULL) |
| 1334 | return -ENOMEM; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1335 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1336 | tp->mdio_bus->name = "tg3 mdio bus"; |
| 1337 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1338 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1339 | tp->mdio_bus->priv = tp; |
| 1340 | tp->mdio_bus->parent = &tp->pdev->dev; |
| 1341 | tp->mdio_bus->read = &tg3_mdio_read; |
| 1342 | tp->mdio_bus->write = &tg3_mdio_write; |
| 1343 | tp->mdio_bus->reset = &tg3_mdio_reset; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1344 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1345 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1346 | |
| 1347 | for (i = 0; i < PHY_MAX_ADDR; i++) |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1348 | tp->mdio_bus->irq[i] = PHY_POLL; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1349 | |
| 1350 | /* The bus registration will look for all the PHYs on the mdio bus. |
| 1351 | * Unfortunately, it does not ensure the PHY is powered up before |
| 1352 | * accessing the PHY ID registers. A chip reset is the |
| 1353 | * quickest way to bring the device back to an operational state.. |
| 1354 | */ |
| 1355 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
| 1356 | tg3_bmcr_reset(tp); |
| 1357 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1358 | i = mdiobus_register(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1359 | if (i) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1360 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1361 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1362 | return i; |
| 1363 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1364 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1365 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1366 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1367 | if (!phydev || !phydev->drv) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1368 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1369 | mdiobus_unregister(tp->mdio_bus); |
| 1370 | mdiobus_free(tp->mdio_bus); |
| 1371 | return -ENODEV; |
| 1372 | } |
| 1373 | |
| 1374 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1375 | case PHY_ID_BCM57780: |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1376 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1377 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1378 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1379 | case PHY_ID_BCM50610: |
| 1380 | case PHY_ID_BCM50610M: |
Matt Carlson | 32e5a8d | 2009-11-02 14:31:39 +0000 | [diff] [blame] | 1381 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1382 | PHY_BRCM_RX_REFCLK_UNUSED | |
Matt Carlson | 52fae08 | 2009-11-02 14:32:38 +0000 | [diff] [blame] | 1383 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1384 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1385 | if (tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1386 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1387 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1388 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1389 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1390 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1391 | /* fallthru */ |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1392 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1393 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1394 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1395 | case PHY_ID_RTL8201E: |
| 1396 | case PHY_ID_BCMAC131: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1397 | phydev->interface = PHY_INTERFACE_MODE_MII; |
Matt Carlson | cdd4e09d | 2009-11-02 14:31:11 +0000 | [diff] [blame] | 1398 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1399 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1400 | break; |
| 1401 | } |
| 1402 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1403 | tg3_flag_set(tp, MDIOBUS_INITED); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1404 | |
| 1405 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1406 | tg3_mdio_config_5785(tp); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1407 | |
| 1408 | return 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | static void tg3_mdio_fini(struct tg3 *tp) |
| 1412 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1413 | if (tg3_flag(tp, MDIOBUS_INITED)) { |
| 1414 | tg3_flag_clear(tp, MDIOBUS_INITED); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1415 | mdiobus_unregister(tp->mdio_bus); |
| 1416 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1417 | } |
| 1418 | } |
| 1419 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1420 | /* tp->lock is held. */ |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1421 | static inline void tg3_generate_fw_event(struct tg3 *tp) |
| 1422 | { |
| 1423 | u32 val; |
| 1424 | |
| 1425 | val = tr32(GRC_RX_CPU_EVENT); |
| 1426 | val |= GRC_RX_CPU_DRIVER_EVENT; |
| 1427 | tw32_f(GRC_RX_CPU_EVENT, val); |
| 1428 | |
| 1429 | tp->last_event_jiffies = jiffies; |
| 1430 | } |
| 1431 | |
| 1432 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 |
| 1433 | |
| 1434 | /* tp->lock is held. */ |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1435 | static void tg3_wait_for_event_ack(struct tg3 *tp) |
| 1436 | { |
| 1437 | int i; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1438 | unsigned int delay_cnt; |
| 1439 | long time_remain; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1440 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1441 | /* If enough time has passed, no wait is necessary. */ |
| 1442 | time_remain = (long)(tp->last_event_jiffies + 1 + |
| 1443 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - |
| 1444 | (long)jiffies; |
| 1445 | if (time_remain < 0) |
| 1446 | return; |
| 1447 | |
| 1448 | /* Check if we can shorten the wait time. */ |
| 1449 | delay_cnt = jiffies_to_usecs(time_remain); |
| 1450 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) |
| 1451 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; |
| 1452 | delay_cnt = (delay_cnt >> 3) + 1; |
| 1453 | |
| 1454 | for (i = 0; i < delay_cnt; i++) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1455 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
| 1456 | break; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1457 | udelay(8); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | /* tp->lock is held. */ |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1462 | static void tg3_phy_gather_ump_data(struct tg3 *tp, u32 *data) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1463 | { |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1464 | u32 reg, val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1465 | |
| 1466 | val = 0; |
| 1467 | if (!tg3_readphy(tp, MII_BMCR, ®)) |
| 1468 | val = reg << 16; |
| 1469 | if (!tg3_readphy(tp, MII_BMSR, ®)) |
| 1470 | val |= (reg & 0xffff); |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1471 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1472 | |
| 1473 | val = 0; |
| 1474 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) |
| 1475 | val = reg << 16; |
| 1476 | if (!tg3_readphy(tp, MII_LPA, ®)) |
| 1477 | val |= (reg & 0xffff); |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1478 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1479 | |
| 1480 | val = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1481 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1482 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
| 1483 | val = reg << 16; |
| 1484 | if (!tg3_readphy(tp, MII_STAT1000, ®)) |
| 1485 | val |= (reg & 0xffff); |
| 1486 | } |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1487 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1488 | |
| 1489 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) |
| 1490 | val = reg << 16; |
| 1491 | else |
| 1492 | val = 0; |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1493 | *data++ = val; |
| 1494 | } |
| 1495 | |
| 1496 | /* tp->lock is held. */ |
| 1497 | static void tg3_ump_link_report(struct tg3 *tp) |
| 1498 | { |
| 1499 | u32 data[4]; |
| 1500 | |
| 1501 | if (!tg3_flag(tp, 5780_CLASS) || !tg3_flag(tp, ENABLE_ASF)) |
| 1502 | return; |
| 1503 | |
| 1504 | tg3_phy_gather_ump_data(tp, data); |
| 1505 | |
| 1506 | tg3_wait_for_event_ack(tp); |
| 1507 | |
| 1508 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); |
| 1509 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); |
| 1510 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x0, data[0]); |
| 1511 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x4, data[1]); |
| 1512 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x8, data[2]); |
| 1513 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0xc, data[3]); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1514 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1515 | tg3_generate_fw_event(tp); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Matt Carlson | 8d5a89b | 2011-08-31 11:44:51 +0000 | [diff] [blame] | 1518 | /* tp->lock is held. */ |
| 1519 | static void tg3_stop_fw(struct tg3 *tp) |
| 1520 | { |
| 1521 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
| 1522 | /* Wait for RX cpu to ACK the previous event. */ |
| 1523 | tg3_wait_for_event_ack(tp); |
| 1524 | |
| 1525 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); |
| 1526 | |
| 1527 | tg3_generate_fw_event(tp); |
| 1528 | |
| 1529 | /* Wait for RX cpu to ACK this event. */ |
| 1530 | tg3_wait_for_event_ack(tp); |
| 1531 | } |
| 1532 | } |
| 1533 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 1534 | /* tp->lock is held. */ |
| 1535 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) |
| 1536 | { |
| 1537 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
| 1538 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); |
| 1539 | |
| 1540 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1541 | switch (kind) { |
| 1542 | case RESET_KIND_INIT: |
| 1543 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1544 | DRV_STATE_START); |
| 1545 | break; |
| 1546 | |
| 1547 | case RESET_KIND_SHUTDOWN: |
| 1548 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1549 | DRV_STATE_UNLOAD); |
| 1550 | break; |
| 1551 | |
| 1552 | case RESET_KIND_SUSPEND: |
| 1553 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1554 | DRV_STATE_SUSPEND); |
| 1555 | break; |
| 1556 | |
| 1557 | default: |
| 1558 | break; |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | if (kind == RESET_KIND_INIT || |
| 1563 | kind == RESET_KIND_SUSPEND) |
| 1564 | tg3_ape_driver_state_change(tp, kind); |
| 1565 | } |
| 1566 | |
| 1567 | /* tp->lock is held. */ |
| 1568 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) |
| 1569 | { |
| 1570 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1571 | switch (kind) { |
| 1572 | case RESET_KIND_INIT: |
| 1573 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1574 | DRV_STATE_START_DONE); |
| 1575 | break; |
| 1576 | |
| 1577 | case RESET_KIND_SHUTDOWN: |
| 1578 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1579 | DRV_STATE_UNLOAD_DONE); |
| 1580 | break; |
| 1581 | |
| 1582 | default: |
| 1583 | break; |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | if (kind == RESET_KIND_SHUTDOWN) |
| 1588 | tg3_ape_driver_state_change(tp, kind); |
| 1589 | } |
| 1590 | |
| 1591 | /* tp->lock is held. */ |
| 1592 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) |
| 1593 | { |
| 1594 | if (tg3_flag(tp, ENABLE_ASF)) { |
| 1595 | switch (kind) { |
| 1596 | case RESET_KIND_INIT: |
| 1597 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1598 | DRV_STATE_START); |
| 1599 | break; |
| 1600 | |
| 1601 | case RESET_KIND_SHUTDOWN: |
| 1602 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1603 | DRV_STATE_UNLOAD); |
| 1604 | break; |
| 1605 | |
| 1606 | case RESET_KIND_SUSPEND: |
| 1607 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1608 | DRV_STATE_SUSPEND); |
| 1609 | break; |
| 1610 | |
| 1611 | default: |
| 1612 | break; |
| 1613 | } |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | static int tg3_poll_fw(struct tg3 *tp) |
| 1618 | { |
| 1619 | int i; |
| 1620 | u32 val; |
| 1621 | |
| 1622 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 1623 | /* Wait up to 20ms for init done. */ |
| 1624 | for (i = 0; i < 200; i++) { |
| 1625 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
| 1626 | return 0; |
| 1627 | udelay(100); |
| 1628 | } |
| 1629 | return -ENODEV; |
| 1630 | } |
| 1631 | |
| 1632 | /* Wait for firmware initialization to complete. */ |
| 1633 | for (i = 0; i < 100000; i++) { |
| 1634 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); |
| 1635 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 1636 | break; |
| 1637 | udelay(10); |
| 1638 | } |
| 1639 | |
| 1640 | /* Chip might not be fitted with firmware. Some Sun onboard |
| 1641 | * parts are configured like that. So don't signal the timeout |
| 1642 | * of the above loop as an error, but do report the lack of |
| 1643 | * running firmware once. |
| 1644 | */ |
| 1645 | if (i >= 100000 && !tg3_flag(tp, NO_FWARE_REPORTED)) { |
| 1646 | tg3_flag_set(tp, NO_FWARE_REPORTED); |
| 1647 | |
| 1648 | netdev_info(tp->dev, "No firmware running\n"); |
| 1649 | } |
| 1650 | |
| 1651 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 1652 | /* The 57765 A0 needs a little more |
| 1653 | * time to do some important work. |
| 1654 | */ |
| 1655 | mdelay(10); |
| 1656 | } |
| 1657 | |
| 1658 | return 0; |
| 1659 | } |
| 1660 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1661 | static void tg3_link_report(struct tg3 *tp) |
| 1662 | { |
| 1663 | if (!netif_carrier_ok(tp->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1664 | netif_info(tp, link, tp->dev, "Link is down\n"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1665 | tg3_ump_link_report(tp); |
| 1666 | } else if (netif_msg_link(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1667 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
| 1668 | (tp->link_config.active_speed == SPEED_1000 ? |
| 1669 | 1000 : |
| 1670 | (tp->link_config.active_speed == SPEED_100 ? |
| 1671 | 100 : 10)), |
| 1672 | (tp->link_config.active_duplex == DUPLEX_FULL ? |
| 1673 | "full" : "half")); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1674 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1675 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", |
| 1676 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? |
| 1677 | "on" : "off", |
| 1678 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? |
| 1679 | "on" : "off"); |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 1680 | |
| 1681 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) |
| 1682 | netdev_info(tp->dev, "EEE is %s\n", |
| 1683 | tp->setlpicnt ? "enabled" : "disabled"); |
| 1684 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1685 | tg3_ump_link_report(tp); |
| 1686 | } |
| 1687 | } |
| 1688 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1689 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
| 1690 | { |
| 1691 | u16 miireg; |
| 1692 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1693 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1694 | miireg = ADVERTISE_1000XPAUSE; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1695 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1696 | miireg = ADVERTISE_1000XPSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1697 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1698 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
| 1699 | else |
| 1700 | miireg = 0; |
| 1701 | |
| 1702 | return miireg; |
| 1703 | } |
| 1704 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1705 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
| 1706 | { |
| 1707 | u8 cap = 0; |
| 1708 | |
Matt Carlson | f3791cd | 2011-11-21 15:01:17 +0000 | [diff] [blame] | 1709 | if (lcladv & rmtadv & ADVERTISE_1000XPAUSE) { |
| 1710 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 1711 | } else if (lcladv & rmtadv & ADVERTISE_1000XPSE_ASYM) { |
| 1712 | if (lcladv & ADVERTISE_1000XPAUSE) |
| 1713 | cap = FLOW_CTRL_RX; |
| 1714 | if (rmtadv & ADVERTISE_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1715 | cap = FLOW_CTRL_TX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | return cap; |
| 1719 | } |
| 1720 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1721 | 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] | 1722 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1723 | u8 autoneg; |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1724 | u8 flowctrl = 0; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1725 | u32 old_rx_mode = tp->rx_mode; |
| 1726 | u32 old_tx_mode = tp->tx_mode; |
| 1727 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1728 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1729 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1730 | else |
| 1731 | autoneg = tp->link_config.autoneg; |
| 1732 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1733 | if (autoneg == AUTONEG_ENABLE && tg3_flag(tp, PAUSE_AUTONEG)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1734 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1735 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1736 | else |
Steve Glendinning | bc02ff9 | 2008-12-16 02:00:48 -0800 | [diff] [blame] | 1737 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1738 | } else |
| 1739 | flowctrl = tp->link_config.flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1740 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1741 | tp->link_config.active_flowctrl = flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1742 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1743 | if (flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1744 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
| 1745 | else |
| 1746 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; |
| 1747 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1748 | if (old_rx_mode != tp->rx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1749 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1750 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1751 | if (flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1752 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
| 1753 | else |
| 1754 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; |
| 1755 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1756 | if (old_tx_mode != tp->tx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1757 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1760 | static void tg3_adjust_link(struct net_device *dev) |
| 1761 | { |
| 1762 | u8 oldflowctrl, linkmesg = 0; |
| 1763 | u32 mac_mode, lcl_adv, rmt_adv; |
| 1764 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1765 | 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] | 1766 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1767 | spin_lock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1768 | |
| 1769 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | |
| 1770 | MAC_MODE_HALF_DUPLEX); |
| 1771 | |
| 1772 | oldflowctrl = tp->link_config.active_flowctrl; |
| 1773 | |
| 1774 | if (phydev->link) { |
| 1775 | lcl_adv = 0; |
| 1776 | rmt_adv = 0; |
| 1777 | |
| 1778 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) |
| 1779 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1780 | else if (phydev->speed == SPEED_1000 || |
| 1781 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1782 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1783 | else |
| 1784 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1785 | |
| 1786 | if (phydev->duplex == DUPLEX_HALF) |
| 1787 | mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 1788 | else { |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 1789 | lcl_adv = mii_advertise_flowctrl( |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1790 | tp->link_config.flowctrl); |
| 1791 | |
| 1792 | if (phydev->pause) |
| 1793 | rmt_adv = LPA_PAUSE_CAP; |
| 1794 | if (phydev->asym_pause) |
| 1795 | rmt_adv |= LPA_PAUSE_ASYM; |
| 1796 | } |
| 1797 | |
| 1798 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 1799 | } else |
| 1800 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 1801 | |
| 1802 | if (mac_mode != tp->mac_mode) { |
| 1803 | tp->mac_mode = mac_mode; |
| 1804 | tw32_f(MAC_MODE, tp->mac_mode); |
| 1805 | udelay(40); |
| 1806 | } |
| 1807 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1808 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
| 1809 | if (phydev->speed == SPEED_10) |
| 1810 | tw32(MAC_MI_STAT, |
| 1811 | MAC_MI_STAT_10MBPS_MODE | |
| 1812 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1813 | else |
| 1814 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1815 | } |
| 1816 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1817 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
| 1818 | tw32(MAC_TX_LENGTHS, |
| 1819 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1820 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1821 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1822 | else |
| 1823 | tw32(MAC_TX_LENGTHS, |
| 1824 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1825 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1826 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1827 | |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 1828 | if (phydev->link != tp->old_link || |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1829 | phydev->speed != tp->link_config.active_speed || |
| 1830 | phydev->duplex != tp->link_config.active_duplex || |
| 1831 | oldflowctrl != tp->link_config.active_flowctrl) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 1832 | linkmesg = 1; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1833 | |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 1834 | tp->old_link = phydev->link; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1835 | tp->link_config.active_speed = phydev->speed; |
| 1836 | tp->link_config.active_duplex = phydev->duplex; |
| 1837 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1838 | spin_unlock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1839 | |
| 1840 | if (linkmesg) |
| 1841 | tg3_link_report(tp); |
| 1842 | } |
| 1843 | |
| 1844 | static int tg3_phy_init(struct tg3 *tp) |
| 1845 | { |
| 1846 | struct phy_device *phydev; |
| 1847 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1848 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1849 | return 0; |
| 1850 | |
| 1851 | /* Bring the PHY back to a known state. */ |
| 1852 | tg3_bmcr_reset(tp); |
| 1853 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1854 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1855 | |
| 1856 | /* Attach the MAC to the PHY. */ |
Kay Sievers | fb28ad3 | 2008-11-10 13:55:14 -0800 | [diff] [blame] | 1857 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link, |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1858 | phydev->dev_flags, phydev->interface); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1859 | if (IS_ERR(phydev)) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1860 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1861 | return PTR_ERR(phydev); |
| 1862 | } |
| 1863 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1864 | /* Mask with MAC supported features. */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1865 | switch (phydev->interface) { |
| 1866 | case PHY_INTERFACE_MODE_GMII: |
| 1867 | case PHY_INTERFACE_MODE_RGMII: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1868 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1869 | phydev->supported &= (PHY_GBIT_FEATURES | |
| 1870 | SUPPORTED_Pause | |
| 1871 | SUPPORTED_Asym_Pause); |
| 1872 | break; |
| 1873 | } |
| 1874 | /* fallthru */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1875 | case PHY_INTERFACE_MODE_MII: |
| 1876 | phydev->supported &= (PHY_BASIC_FEATURES | |
| 1877 | SUPPORTED_Pause | |
| 1878 | SUPPORTED_Asym_Pause); |
| 1879 | break; |
| 1880 | default: |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1881 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1882 | return -EINVAL; |
| 1883 | } |
| 1884 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1885 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1886 | |
| 1887 | phydev->advertising = phydev->supported; |
| 1888 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1889 | return 0; |
| 1890 | } |
| 1891 | |
| 1892 | static void tg3_phy_start(struct tg3 *tp) |
| 1893 | { |
| 1894 | struct phy_device *phydev; |
| 1895 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1896 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1897 | return; |
| 1898 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1899 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1900 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 1901 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 1902 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 1903 | phydev->speed = tp->link_config.speed; |
| 1904 | phydev->duplex = tp->link_config.duplex; |
| 1905 | phydev->autoneg = tp->link_config.autoneg; |
| 1906 | phydev->advertising = tp->link_config.advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | phy_start(phydev); |
| 1910 | |
| 1911 | phy_start_aneg(phydev); |
| 1912 | } |
| 1913 | |
| 1914 | static void tg3_phy_stop(struct tg3 *tp) |
| 1915 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1916 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1917 | return; |
| 1918 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1919 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | static void tg3_phy_fini(struct tg3 *tp) |
| 1923 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1924 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1925 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1926 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1927 | } |
| 1928 | } |
| 1929 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 1930 | static int tg3_phy_set_extloopbk(struct tg3 *tp) |
| 1931 | { |
| 1932 | int err; |
| 1933 | u32 val; |
| 1934 | |
| 1935 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 1936 | return 0; |
| 1937 | |
| 1938 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
| 1939 | /* Cannot do read-modify-write on 5401 */ |
| 1940 | err = tg3_phy_auxctl_write(tp, |
| 1941 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 1942 | MII_TG3_AUXCTL_ACTL_EXTLOOPBK | |
| 1943 | 0x4c20); |
| 1944 | goto done; |
| 1945 | } |
| 1946 | |
| 1947 | err = tg3_phy_auxctl_read(tp, |
| 1948 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 1949 | if (err) |
| 1950 | return err; |
| 1951 | |
| 1952 | val |= MII_TG3_AUXCTL_ACTL_EXTLOOPBK; |
| 1953 | err = tg3_phy_auxctl_write(tp, |
| 1954 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, val); |
| 1955 | |
| 1956 | done: |
| 1957 | return err; |
| 1958 | } |
| 1959 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1960 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
| 1961 | { |
| 1962 | u32 phytest; |
| 1963 | |
| 1964 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 1965 | u32 phy; |
| 1966 | |
| 1967 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 1968 | phytest | MII_TG3_FET_SHADOW_EN); |
| 1969 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { |
| 1970 | if (enable) |
| 1971 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1972 | else |
| 1973 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1974 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); |
| 1975 | } |
| 1976 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 1977 | } |
| 1978 | } |
| 1979 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1980 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
| 1981 | { |
| 1982 | u32 reg; |
| 1983 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1984 | if (!tg3_flag(tp, 5705_PLUS) || |
| 1985 | (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1986 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1987 | return; |
| 1988 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1989 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1990 | tg3_phy_fet_toggle_apd(tp, enable); |
| 1991 | return; |
| 1992 | } |
| 1993 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1994 | reg = MII_TG3_MISC_SHDW_WREN | |
| 1995 | MII_TG3_MISC_SHDW_SCR5_SEL | |
| 1996 | MII_TG3_MISC_SHDW_SCR5_LPED | |
| 1997 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | |
| 1998 | MII_TG3_MISC_SHDW_SCR5_SDTL | |
| 1999 | MII_TG3_MISC_SHDW_SCR5_C125OE; |
| 2000 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) |
| 2001 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
| 2002 | |
| 2003 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 2004 | |
| 2005 | |
| 2006 | reg = MII_TG3_MISC_SHDW_WREN | |
| 2007 | MII_TG3_MISC_SHDW_APD_SEL | |
| 2008 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; |
| 2009 | if (enable) |
| 2010 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; |
| 2011 | |
| 2012 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 2013 | } |
| 2014 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2015 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
| 2016 | { |
| 2017 | u32 phy; |
| 2018 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2019 | if (!tg3_flag(tp, 5705_PLUS) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2020 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2021 | return; |
| 2022 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2023 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2024 | u32 ephy; |
| 2025 | |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2026 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
| 2027 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; |
| 2028 | |
| 2029 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2030 | ephy | MII_TG3_FET_SHADOW_EN); |
| 2031 | if (!tg3_readphy(tp, reg, &phy)) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2032 | if (enable) |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2033 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2034 | else |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2035 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 2036 | tg3_writephy(tp, reg, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2037 | } |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2038 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2039 | } |
| 2040 | } else { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2041 | int ret; |
| 2042 | |
| 2043 | ret = tg3_phy_auxctl_read(tp, |
| 2044 | MII_TG3_AUXCTL_SHDWSEL_MISC, &phy); |
| 2045 | if (!ret) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2046 | if (enable) |
| 2047 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 2048 | else |
| 2049 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2050 | tg3_phy_auxctl_write(tp, |
| 2051 | MII_TG3_AUXCTL_SHDWSEL_MISC, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
| 2057 | { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2058 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | u32 val; |
| 2060 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2061 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | return; |
| 2063 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2064 | ret = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, &val); |
| 2065 | if (!ret) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2066 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, |
| 2067 | val | MII_TG3_AUXCTL_MISC_WIRESPD_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2070 | static void tg3_phy_apply_otp(struct tg3 *tp) |
| 2071 | { |
| 2072 | u32 otp, phy; |
| 2073 | |
| 2074 | if (!tp->phy_otp) |
| 2075 | return; |
| 2076 | |
| 2077 | otp = tp->phy_otp; |
| 2078 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2079 | if (TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) |
| 2080 | return; |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2081 | |
| 2082 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); |
| 2083 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; |
| 2084 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); |
| 2085 | |
| 2086 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | |
| 2087 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); |
| 2088 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); |
| 2089 | |
| 2090 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); |
| 2091 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; |
| 2092 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); |
| 2093 | |
| 2094 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); |
| 2095 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); |
| 2096 | |
| 2097 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); |
| 2098 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); |
| 2099 | |
| 2100 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | |
| 2101 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); |
| 2102 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); |
| 2103 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2104 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2107 | static void tg3_phy_eee_adjust(struct tg3 *tp, u32 current_link_up) |
| 2108 | { |
| 2109 | u32 val; |
| 2110 | |
| 2111 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 2112 | return; |
| 2113 | |
| 2114 | tp->setlpicnt = 0; |
| 2115 | |
| 2116 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 2117 | current_link_up == 1 && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 2118 | tp->link_config.active_duplex == DUPLEX_FULL && |
| 2119 | (tp->link_config.active_speed == SPEED_100 || |
| 2120 | tp->link_config.active_speed == SPEED_1000)) { |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2121 | u32 eeectl; |
| 2122 | |
| 2123 | if (tp->link_config.active_speed == SPEED_1000) |
| 2124 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; |
| 2125 | else |
| 2126 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; |
| 2127 | |
| 2128 | tw32(TG3_CPMU_EEE_CTRL, eeectl); |
| 2129 | |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 2130 | tg3_phy_cl45_read(tp, MDIO_MMD_AN, |
| 2131 | TG3_CL45_D7_EEERES_STAT, &val); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2132 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2133 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
| 2134 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2135 | tp->setlpicnt = 2; |
| 2136 | } |
| 2137 | |
| 2138 | if (!tp->setlpicnt) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2139 | if (current_link_up == 1 && |
| 2140 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2141 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, 0x0000); |
| 2142 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2143 | } |
| 2144 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2145 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2146 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2147 | } |
| 2148 | } |
| 2149 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2150 | static void tg3_phy_eee_enable(struct tg3 *tp) |
| 2151 | { |
| 2152 | u32 val; |
| 2153 | |
| 2154 | if (tp->link_config.active_speed == SPEED_1000 && |
| 2155 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2156 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 2157 | tg3_flag(tp, 57765_CLASS)) && |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2158 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2159 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 2160 | MII_TG3_DSP_TAP26_RMRXSTO; |
| 2161 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2162 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2163 | } |
| 2164 | |
| 2165 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2166 | tw32(TG3_CPMU_EEE_MODE, val | TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2167 | } |
| 2168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | static int tg3_wait_macro_done(struct tg3 *tp) |
| 2170 | { |
| 2171 | int limit = 100; |
| 2172 | |
| 2173 | while (limit--) { |
| 2174 | u32 tmp32; |
| 2175 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2176 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | if ((tmp32 & 0x1000) == 0) |
| 2178 | break; |
| 2179 | } |
| 2180 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 2181 | if (limit < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | return -EBUSY; |
| 2183 | |
| 2184 | return 0; |
| 2185 | } |
| 2186 | |
| 2187 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) |
| 2188 | { |
| 2189 | static const u32 test_pat[4][6] = { |
| 2190 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, |
| 2191 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, |
| 2192 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, |
| 2193 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } |
| 2194 | }; |
| 2195 | int chan; |
| 2196 | |
| 2197 | for (chan = 0; chan < 4; chan++) { |
| 2198 | int i; |
| 2199 | |
| 2200 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2201 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2202 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | |
| 2204 | for (i = 0; i < 6; i++) |
| 2205 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, |
| 2206 | test_pat[chan][i]); |
| 2207 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2208 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | if (tg3_wait_macro_done(tp)) { |
| 2210 | *resetp = 1; |
| 2211 | return -EBUSY; |
| 2212 | } |
| 2213 | |
| 2214 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2215 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2216 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | if (tg3_wait_macro_done(tp)) { |
| 2218 | *resetp = 1; |
| 2219 | return -EBUSY; |
| 2220 | } |
| 2221 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2222 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | if (tg3_wait_macro_done(tp)) { |
| 2224 | *resetp = 1; |
| 2225 | return -EBUSY; |
| 2226 | } |
| 2227 | |
| 2228 | for (i = 0; i < 6; i += 2) { |
| 2229 | u32 low, high; |
| 2230 | |
| 2231 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || |
| 2232 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || |
| 2233 | tg3_wait_macro_done(tp)) { |
| 2234 | *resetp = 1; |
| 2235 | return -EBUSY; |
| 2236 | } |
| 2237 | low &= 0x7fff; |
| 2238 | high &= 0x000f; |
| 2239 | if (low != test_pat[chan][i] || |
| 2240 | high != test_pat[chan][i+1]) { |
| 2241 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); |
| 2242 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); |
| 2243 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); |
| 2244 | |
| 2245 | return -EBUSY; |
| 2246 | } |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | return 0; |
| 2251 | } |
| 2252 | |
| 2253 | static int tg3_phy_reset_chanpat(struct tg3 *tp) |
| 2254 | { |
| 2255 | int chan; |
| 2256 | |
| 2257 | for (chan = 0; chan < 4; chan++) { |
| 2258 | int i; |
| 2259 | |
| 2260 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2261 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2262 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | for (i = 0; i < 6; i++) |
| 2264 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2265 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | if (tg3_wait_macro_done(tp)) |
| 2267 | return -EBUSY; |
| 2268 | } |
| 2269 | |
| 2270 | return 0; |
| 2271 | } |
| 2272 | |
| 2273 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) |
| 2274 | { |
| 2275 | u32 reg32, phy9_orig; |
| 2276 | int retries, do_phy_reset, err; |
| 2277 | |
| 2278 | retries = 10; |
| 2279 | do_phy_reset = 1; |
| 2280 | do { |
| 2281 | if (do_phy_reset) { |
| 2282 | err = tg3_bmcr_reset(tp); |
| 2283 | if (err) |
| 2284 | return err; |
| 2285 | do_phy_reset = 0; |
| 2286 | } |
| 2287 | |
| 2288 | /* Disable transmitter and interrupt. */ |
| 2289 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) |
| 2290 | continue; |
| 2291 | |
| 2292 | reg32 |= 0x3000; |
| 2293 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2294 | |
| 2295 | /* Set full-duplex, 1000 mbps. */ |
| 2296 | tg3_writephy(tp, MII_BMCR, |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2297 | BMCR_FULLDPLX | BMCR_SPEED1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | |
| 2299 | /* Set to master mode. */ |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2300 | if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | continue; |
| 2302 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2303 | tg3_writephy(tp, MII_CTRL1000, |
| 2304 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2306 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
| 2307 | if (err) |
| 2308 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
| 2310 | /* Block the PHY control access. */ |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2311 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | |
| 2313 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); |
| 2314 | if (!err) |
| 2315 | break; |
| 2316 | } while (--retries); |
| 2317 | |
| 2318 | err = tg3_phy_reset_chanpat(tp); |
| 2319 | if (err) |
| 2320 | return err; |
| 2321 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2322 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | |
| 2324 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2325 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2327 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2329 | tg3_writephy(tp, MII_CTRL1000, phy9_orig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | |
| 2331 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { |
| 2332 | reg32 &= ~0x3000; |
| 2333 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2334 | } else if (!err) |
| 2335 | err = -EBUSY; |
| 2336 | |
| 2337 | return err; |
| 2338 | } |
| 2339 | |
| 2340 | /* This will reset the tigon3 PHY if there is no valid |
| 2341 | * link unless the FORCE argument is non-zero. |
| 2342 | */ |
| 2343 | static int tg3_phy_reset(struct tg3 *tp) |
| 2344 | { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2345 | u32 val, cpmuctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | int err; |
| 2347 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2348 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2349 | val = tr32(GRC_MISC_CFG); |
| 2350 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); |
| 2351 | udelay(40); |
| 2352 | } |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2353 | err = tg3_readphy(tp, MII_BMSR, &val); |
| 2354 | err |= tg3_readphy(tp, MII_BMSR, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | if (err != 0) |
| 2356 | return -EBUSY; |
| 2357 | |
Michael Chan | c8e1e82 | 2006-04-29 18:55:17 -0700 | [diff] [blame] | 2358 | if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) { |
| 2359 | netif_carrier_off(tp->dev); |
| 2360 | tg3_link_report(tp); |
| 2361 | } |
| 2362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 2364 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2365 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 2366 | err = tg3_phy_reset_5703_4_5(tp); |
| 2367 | if (err) |
| 2368 | return err; |
| 2369 | goto out; |
| 2370 | } |
| 2371 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2372 | cpmuctrl = 0; |
| 2373 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 2374 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 2375 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
| 2376 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) |
| 2377 | tw32(TG3_CPMU_CTRL, |
| 2378 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); |
| 2379 | } |
| 2380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | err = tg3_bmcr_reset(tp); |
| 2382 | if (err) |
| 2383 | return err; |
| 2384 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2385 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2386 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
| 2387 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2388 | |
| 2389 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 2390 | } |
| 2391 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2392 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2393 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2394 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2395 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == |
| 2396 | CPMU_LSPD_1000MB_MACCLK_12_5) { |
| 2397 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2398 | udelay(40); |
| 2399 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2400 | } |
| 2401 | } |
| 2402 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2403 | if (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2404 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 2405 | return 0; |
| 2406 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2407 | tg3_phy_apply_otp(tp); |
| 2408 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2409 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2410 | tg3_phy_toggle_apd(tp, true); |
| 2411 | else |
| 2412 | tg3_phy_toggle_apd(tp, false); |
| 2413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | out: |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2415 | if ((tp->phy_flags & TG3_PHYFLG_ADC_BUG) && |
| 2416 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2417 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
| 2418 | tg3_phydsp_write(tp, 0x000a, 0x0323); |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2419 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2421 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2422 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2423 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 2424 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2426 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2427 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2428 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2429 | tg3_phydsp_write(tp, 0x000a, 0x310b); |
| 2430 | tg3_phydsp_write(tp, 0x201f, 0x9506); |
| 2431 | tg3_phydsp_write(tp, 0x401f, 0x14e2); |
| 2432 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2433 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2434 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2435 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2436 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
| 2437 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { |
| 2438 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
| 2439 | tg3_writephy(tp, MII_TG3_TEST1, |
| 2440 | MII_TG3_TEST1_TRIM_EN | 0x4); |
| 2441 | } else |
| 2442 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); |
| 2443 | |
| 2444 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2445 | } |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 2446 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | /* Set Extended packet length bit (bit 14) on all chips that */ |
| 2449 | /* support jumbo frames */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2450 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | /* Cannot do read-modify-write on 5401 */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2452 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2453 | } else if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | /* Set bit 14 with read-modify-write to preserve other bits */ |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2455 | err = tg3_phy_auxctl_read(tp, |
| 2456 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2457 | if (!err) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2458 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2459 | val | MII_TG3_AUXCTL_ACTL_EXTPKTLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support |
| 2463 | * jumbo frames transmission. |
| 2464 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2465 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2466 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 2467 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2468 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2471 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2472 | /* adjust output voltage */ |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2473 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2476 | tg3_phy_toggle_automdix(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | tg3_phy_set_wirespeed(tp); |
| 2478 | return 0; |
| 2479 | } |
| 2480 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2481 | #define TG3_GPIO_MSG_DRVR_PRES 0x00000001 |
| 2482 | #define TG3_GPIO_MSG_NEED_VAUX 0x00000002 |
| 2483 | #define TG3_GPIO_MSG_MASK (TG3_GPIO_MSG_DRVR_PRES | \ |
| 2484 | TG3_GPIO_MSG_NEED_VAUX) |
| 2485 | #define TG3_GPIO_MSG_ALL_DRVR_PRES_MASK \ |
| 2486 | ((TG3_GPIO_MSG_DRVR_PRES << 0) | \ |
| 2487 | (TG3_GPIO_MSG_DRVR_PRES << 4) | \ |
| 2488 | (TG3_GPIO_MSG_DRVR_PRES << 8) | \ |
| 2489 | (TG3_GPIO_MSG_DRVR_PRES << 12)) |
| 2490 | |
| 2491 | #define TG3_GPIO_MSG_ALL_NEED_VAUX_MASK \ |
| 2492 | ((TG3_GPIO_MSG_NEED_VAUX << 0) | \ |
| 2493 | (TG3_GPIO_MSG_NEED_VAUX << 4) | \ |
| 2494 | (TG3_GPIO_MSG_NEED_VAUX << 8) | \ |
| 2495 | (TG3_GPIO_MSG_NEED_VAUX << 12)) |
| 2496 | |
| 2497 | static inline u32 tg3_set_function_status(struct tg3 *tp, u32 newstat) |
| 2498 | { |
| 2499 | u32 status, shift; |
| 2500 | |
| 2501 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2502 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 2503 | status = tg3_ape_read32(tp, TG3_APE_GPIO_MSG); |
| 2504 | else |
| 2505 | status = tr32(TG3_CPMU_DRV_STATUS); |
| 2506 | |
| 2507 | shift = TG3_APE_GPIO_MSG_SHIFT + 4 * tp->pci_fn; |
| 2508 | status &= ~(TG3_GPIO_MSG_MASK << shift); |
| 2509 | status |= (newstat << shift); |
| 2510 | |
| 2511 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2512 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 2513 | tg3_ape_write32(tp, TG3_APE_GPIO_MSG, status); |
| 2514 | else |
| 2515 | tw32(TG3_CPMU_DRV_STATUS, status); |
| 2516 | |
| 2517 | return status >> TG3_APE_GPIO_MSG_SHIFT; |
| 2518 | } |
| 2519 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2520 | static inline int tg3_pwrsrc_switch_to_vmain(struct tg3 *tp) |
| 2521 | { |
| 2522 | if (!tg3_flag(tp, IS_NIC)) |
| 2523 | return 0; |
| 2524 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2525 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2526 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 2527 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 2528 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2529 | return -EIO; |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2530 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2531 | tg3_set_function_status(tp, TG3_GPIO_MSG_DRVR_PRES); |
| 2532 | |
| 2533 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2534 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2535 | |
| 2536 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
| 2537 | } else { |
| 2538 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2539 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2540 | } |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2541 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2542 | return 0; |
| 2543 | } |
| 2544 | |
| 2545 | static void tg3_pwrsrc_die_with_vmain(struct tg3 *tp) |
| 2546 | { |
| 2547 | u32 grc_local_ctrl; |
| 2548 | |
| 2549 | if (!tg3_flag(tp, IS_NIC) || |
| 2550 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2551 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) |
| 2552 | return; |
| 2553 | |
| 2554 | grc_local_ctrl = tp->grc_local_ctrl | GRC_LCLCTRL_GPIO_OE1; |
| 2555 | |
| 2556 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2557 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2558 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2559 | |
| 2560 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2561 | grc_local_ctrl, |
| 2562 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2563 | |
| 2564 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2565 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2566 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2567 | } |
| 2568 | |
| 2569 | static void tg3_pwrsrc_switch_to_vaux(struct tg3 *tp) |
| 2570 | { |
| 2571 | if (!tg3_flag(tp, IS_NIC)) |
| 2572 | return; |
| 2573 | |
| 2574 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2575 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 2576 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2577 | (GRC_LCLCTRL_GPIO_OE0 | |
| 2578 | GRC_LCLCTRL_GPIO_OE1 | |
| 2579 | GRC_LCLCTRL_GPIO_OE2 | |
| 2580 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2581 | GRC_LCLCTRL_GPIO_OUTPUT1), |
| 2582 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2583 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 2584 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
| 2585 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
| 2586 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | |
| 2587 | GRC_LCLCTRL_GPIO_OE1 | |
| 2588 | GRC_LCLCTRL_GPIO_OE2 | |
| 2589 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2590 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2591 | tp->grc_local_ctrl; |
| 2592 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2593 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2594 | |
| 2595 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2596 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2597 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2598 | |
| 2599 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2600 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2601 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2602 | } else { |
| 2603 | u32 no_gpio2; |
| 2604 | u32 grc_local_ctrl = 0; |
| 2605 | |
| 2606 | /* Workaround to prevent overdrawing Amps. */ |
| 2607 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 2608 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
| 2609 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2610 | grc_local_ctrl, |
| 2611 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2612 | } |
| 2613 | |
| 2614 | /* On 5753 and variants, GPIO2 cannot be used. */ |
| 2615 | no_gpio2 = tp->nic_sram_data_cfg & |
| 2616 | NIC_SRAM_DATA_CFG_NO_GPIO2; |
| 2617 | |
| 2618 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 2619 | GRC_LCLCTRL_GPIO_OE1 | |
| 2620 | GRC_LCLCTRL_GPIO_OE2 | |
| 2621 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2622 | GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2623 | if (no_gpio2) { |
| 2624 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | |
| 2625 | GRC_LCLCTRL_GPIO_OUTPUT2); |
| 2626 | } |
| 2627 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2628 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2629 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2630 | |
| 2631 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2632 | |
| 2633 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2634 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2635 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2636 | |
| 2637 | if (!no_gpio2) { |
| 2638 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2639 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2640 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2641 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2642 | } |
| 2643 | } |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2644 | } |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2645 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2646 | static void tg3_frob_aux_power_5717(struct tg3 *tp, bool wol_enable) |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2647 | { |
| 2648 | u32 msg = 0; |
| 2649 | |
| 2650 | /* Serialize power state transitions */ |
| 2651 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2652 | return; |
| 2653 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2654 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE) || wol_enable) |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2655 | msg = TG3_GPIO_MSG_NEED_VAUX; |
| 2656 | |
| 2657 | msg = tg3_set_function_status(tp, msg); |
| 2658 | |
| 2659 | if (msg & TG3_GPIO_MSG_ALL_DRVR_PRES_MASK) |
| 2660 | goto done; |
| 2661 | |
| 2662 | if (msg & TG3_GPIO_MSG_ALL_NEED_VAUX_MASK) |
| 2663 | tg3_pwrsrc_switch_to_vaux(tp); |
| 2664 | else |
| 2665 | tg3_pwrsrc_die_with_vmain(tp); |
| 2666 | |
| 2667 | done: |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2668 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2669 | } |
| 2670 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2671 | static void tg3_frob_aux_power(struct tg3 *tp, bool include_wol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | { |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2673 | bool need_vaux = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2675 | /* The GPIOs do something completely different on 57765. */ |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 2676 | if (!tg3_flag(tp, IS_NIC) || tg3_flag(tp, 57765_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | return; |
| 2678 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2679 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2680 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 2681 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2682 | tg3_frob_aux_power_5717(tp, include_wol ? |
| 2683 | tg3_flag(tp, WOL_ENABLE) != 0 : 0); |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2684 | return; |
| 2685 | } |
| 2686 | |
| 2687 | if (tp->pdev_peer && tp->pdev_peer != tp->pdev) { |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2688 | struct net_device *dev_peer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2690 | dev_peer = pci_get_drvdata(tp->pdev_peer); |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2691 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2692 | /* remove_one() may have been run on the peer. */ |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2693 | if (dev_peer) { |
| 2694 | struct tg3 *tp_peer = netdev_priv(dev_peer); |
| 2695 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2696 | if (tg3_flag(tp_peer, INIT_COMPLETE)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2697 | return; |
| 2698 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2699 | if ((include_wol && tg3_flag(tp_peer, WOL_ENABLE)) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2700 | tg3_flag(tp_peer, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2701 | need_vaux = true; |
| 2702 | } |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2703 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2705 | if ((include_wol && tg3_flag(tp, WOL_ENABLE)) || |
| 2706 | tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2707 | need_vaux = true; |
| 2708 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2709 | if (need_vaux) |
| 2710 | tg3_pwrsrc_switch_to_vaux(tp); |
| 2711 | else |
| 2712 | tg3_pwrsrc_die_with_vmain(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2715 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
| 2716 | { |
| 2717 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) |
| 2718 | return 1; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2719 | 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] | 2720 | if (speed != SPEED_10) |
| 2721 | return 1; |
| 2722 | } else if (speed == SPEED_10) |
| 2723 | return 1; |
| 2724 | |
| 2725 | return 0; |
| 2726 | } |
| 2727 | |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2728 | 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] | 2729 | { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2730 | u32 val; |
| 2731 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2732 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2733 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2734 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 2735 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); |
| 2736 | |
| 2737 | sg_dig_ctrl |= |
| 2738 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; |
| 2739 | tw32(SG_DIG_CTRL, sg_dig_ctrl); |
| 2740 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); |
| 2741 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2742 | return; |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2743 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2744 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2745 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2746 | tg3_bmcr_reset(tp); |
| 2747 | val = tr32(GRC_MISC_CFG); |
| 2748 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); |
| 2749 | udelay(40); |
| 2750 | return; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2751 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 0e5f784 | 2009-11-02 14:26:38 +0000 | [diff] [blame] | 2752 | u32 phytest; |
| 2753 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2754 | u32 phy; |
| 2755 | |
| 2756 | tg3_writephy(tp, MII_ADVERTISE, 0); |
| 2757 | tg3_writephy(tp, MII_BMCR, |
| 2758 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 2759 | |
| 2760 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2761 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2762 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { |
| 2763 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; |
| 2764 | tg3_writephy(tp, |
| 2765 | MII_TG3_FET_SHDW_AUXMODE4, |
| 2766 | phy); |
| 2767 | } |
| 2768 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2769 | } |
| 2770 | return; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2771 | } else if (do_low_power) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2772 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 2773 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2774 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2775 | val = MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 2776 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | |
| 2777 | MII_TG3_AUXCTL_PCTL_VREG_11V; |
| 2778 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, val); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2779 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2780 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2781 | /* The PHY should not be powered down on some chips because |
| 2782 | * of bugs. |
| 2783 | */ |
| 2784 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2785 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2786 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && |
Matt Carlson | 085f1af | 2012-04-02 09:01:40 +0000 | [diff] [blame] | 2787 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) || |
| 2788 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 && |
| 2789 | !tp->pci_fn)) |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2790 | return; |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2791 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2792 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2793 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2794 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2795 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2796 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; |
| 2797 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2798 | } |
| 2799 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2800 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 2801 | } |
| 2802 | |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2803 | /* tp->lock is held. */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2804 | static int tg3_nvram_lock(struct tg3 *tp) |
| 2805 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2806 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2807 | int i; |
| 2808 | |
| 2809 | if (tp->nvram_lock_cnt == 0) { |
| 2810 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); |
| 2811 | for (i = 0; i < 8000; i++) { |
| 2812 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) |
| 2813 | break; |
| 2814 | udelay(20); |
| 2815 | } |
| 2816 | if (i == 8000) { |
| 2817 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2818 | return -ENODEV; |
| 2819 | } |
| 2820 | } |
| 2821 | tp->nvram_lock_cnt++; |
| 2822 | } |
| 2823 | return 0; |
| 2824 | } |
| 2825 | |
| 2826 | /* tp->lock is held. */ |
| 2827 | static void tg3_nvram_unlock(struct tg3 *tp) |
| 2828 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2829 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2830 | if (tp->nvram_lock_cnt > 0) |
| 2831 | tp->nvram_lock_cnt--; |
| 2832 | if (tp->nvram_lock_cnt == 0) |
| 2833 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | /* tp->lock is held. */ |
| 2838 | static void tg3_enable_nvram_access(struct tg3 *tp) |
| 2839 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2840 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2841 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2842 | |
| 2843 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); |
| 2844 | } |
| 2845 | } |
| 2846 | |
| 2847 | /* tp->lock is held. */ |
| 2848 | static void tg3_disable_nvram_access(struct tg3 *tp) |
| 2849 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2850 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2851 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2852 | |
| 2853 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, |
| 2858 | u32 offset, u32 *val) |
| 2859 | { |
| 2860 | u32 tmp; |
| 2861 | int i; |
| 2862 | |
| 2863 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) |
| 2864 | return -EINVAL; |
| 2865 | |
| 2866 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | |
| 2867 | EEPROM_ADDR_DEVID_MASK | |
| 2868 | EEPROM_ADDR_READ); |
| 2869 | tw32(GRC_EEPROM_ADDR, |
| 2870 | tmp | |
| 2871 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 2872 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & |
| 2873 | EEPROM_ADDR_ADDR_MASK) | |
| 2874 | EEPROM_ADDR_READ | EEPROM_ADDR_START); |
| 2875 | |
| 2876 | for (i = 0; i < 1000; i++) { |
| 2877 | tmp = tr32(GRC_EEPROM_ADDR); |
| 2878 | |
| 2879 | if (tmp & EEPROM_ADDR_COMPLETE) |
| 2880 | break; |
| 2881 | msleep(1); |
| 2882 | } |
| 2883 | if (!(tmp & EEPROM_ADDR_COMPLETE)) |
| 2884 | return -EBUSY; |
| 2885 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 2886 | tmp = tr32(GRC_EEPROM_DATA); |
| 2887 | |
| 2888 | /* |
| 2889 | * The data will always be opposite the native endian |
| 2890 | * format. Perform a blind byteswap to compensate. |
| 2891 | */ |
| 2892 | *val = swab32(tmp); |
| 2893 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2894 | return 0; |
| 2895 | } |
| 2896 | |
| 2897 | #define NVRAM_CMD_TIMEOUT 10000 |
| 2898 | |
| 2899 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) |
| 2900 | { |
| 2901 | int i; |
| 2902 | |
| 2903 | tw32(NVRAM_CMD, nvram_cmd); |
| 2904 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { |
| 2905 | udelay(10); |
| 2906 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { |
| 2907 | udelay(10); |
| 2908 | break; |
| 2909 | } |
| 2910 | } |
| 2911 | |
| 2912 | if (i == NVRAM_CMD_TIMEOUT) |
| 2913 | return -EBUSY; |
| 2914 | |
| 2915 | return 0; |
| 2916 | } |
| 2917 | |
| 2918 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) |
| 2919 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2920 | if (tg3_flag(tp, NVRAM) && |
| 2921 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 2922 | tg3_flag(tp, FLASH) && |
| 2923 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2924 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2925 | |
| 2926 | addr = ((addr / tp->nvram_pagesize) << |
| 2927 | ATMEL_AT45DB0X1B_PAGE_POS) + |
| 2928 | (addr % tp->nvram_pagesize); |
| 2929 | |
| 2930 | return addr; |
| 2931 | } |
| 2932 | |
| 2933 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) |
| 2934 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2935 | if (tg3_flag(tp, NVRAM) && |
| 2936 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 2937 | tg3_flag(tp, FLASH) && |
| 2938 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2939 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2940 | |
| 2941 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * |
| 2942 | tp->nvram_pagesize) + |
| 2943 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); |
| 2944 | |
| 2945 | return addr; |
| 2946 | } |
| 2947 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2948 | /* NOTE: Data read in from NVRAM is byteswapped according to |
| 2949 | * the byteswapping settings for all other register accesses. |
| 2950 | * tg3 devices are BE devices, so on a BE machine, the data |
| 2951 | * returned will be exactly as it is seen in NVRAM. On a LE |
| 2952 | * machine, the 32-bit value will be byteswapped. |
| 2953 | */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2954 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
| 2955 | { |
| 2956 | int ret; |
| 2957 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2958 | if (!tg3_flag(tp, NVRAM)) |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2959 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
| 2960 | |
| 2961 | offset = tg3_nvram_phys_addr(tp, offset); |
| 2962 | |
| 2963 | if (offset > NVRAM_ADDR_MSK) |
| 2964 | return -EINVAL; |
| 2965 | |
| 2966 | ret = tg3_nvram_lock(tp); |
| 2967 | if (ret) |
| 2968 | return ret; |
| 2969 | |
| 2970 | tg3_enable_nvram_access(tp); |
| 2971 | |
| 2972 | tw32(NVRAM_ADDR, offset); |
| 2973 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | |
| 2974 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); |
| 2975 | |
| 2976 | if (ret == 0) |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2977 | *val = tr32(NVRAM_RDDATA); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2978 | |
| 2979 | tg3_disable_nvram_access(tp); |
| 2980 | |
| 2981 | tg3_nvram_unlock(tp); |
| 2982 | |
| 2983 | return ret; |
| 2984 | } |
| 2985 | |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2986 | /* Ensures NVRAM data is in bytestream format. */ |
| 2987 | 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] | 2988 | { |
| 2989 | u32 v; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2990 | int res = tg3_nvram_read(tp, offset, &v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2991 | if (!res) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2992 | *val = cpu_to_be32(v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2993 | return res; |
| 2994 | } |
| 2995 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 2996 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
| 2997 | u32 offset, u32 len, u8 *buf) |
| 2998 | { |
| 2999 | int i, j, rc = 0; |
| 3000 | u32 val; |
| 3001 | |
| 3002 | for (i = 0; i < len; i += 4) { |
| 3003 | u32 addr; |
| 3004 | __be32 data; |
| 3005 | |
| 3006 | addr = offset + i; |
| 3007 | |
| 3008 | memcpy(&data, buf + i, 4); |
| 3009 | |
| 3010 | /* |
| 3011 | * The SEEPROM interface expects the data to always be opposite |
| 3012 | * the native endian format. We accomplish this by reversing |
| 3013 | * all the operations that would have been performed on the |
| 3014 | * data from a call to tg3_nvram_read_be32(). |
| 3015 | */ |
| 3016 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); |
| 3017 | |
| 3018 | val = tr32(GRC_EEPROM_ADDR); |
| 3019 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); |
| 3020 | |
| 3021 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | |
| 3022 | EEPROM_ADDR_READ); |
| 3023 | tw32(GRC_EEPROM_ADDR, val | |
| 3024 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 3025 | (addr & EEPROM_ADDR_ADDR_MASK) | |
| 3026 | EEPROM_ADDR_START | |
| 3027 | EEPROM_ADDR_WRITE); |
| 3028 | |
| 3029 | for (j = 0; j < 1000; j++) { |
| 3030 | val = tr32(GRC_EEPROM_ADDR); |
| 3031 | |
| 3032 | if (val & EEPROM_ADDR_COMPLETE) |
| 3033 | break; |
| 3034 | msleep(1); |
| 3035 | } |
| 3036 | if (!(val & EEPROM_ADDR_COMPLETE)) { |
| 3037 | rc = -EBUSY; |
| 3038 | break; |
| 3039 | } |
| 3040 | } |
| 3041 | |
| 3042 | return rc; |
| 3043 | } |
| 3044 | |
| 3045 | /* offset and length are dword aligned */ |
| 3046 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, |
| 3047 | u8 *buf) |
| 3048 | { |
| 3049 | int ret = 0; |
| 3050 | u32 pagesize = tp->nvram_pagesize; |
| 3051 | u32 pagemask = pagesize - 1; |
| 3052 | u32 nvram_cmd; |
| 3053 | u8 *tmp; |
| 3054 | |
| 3055 | tmp = kmalloc(pagesize, GFP_KERNEL); |
| 3056 | if (tmp == NULL) |
| 3057 | return -ENOMEM; |
| 3058 | |
| 3059 | while (len) { |
| 3060 | int j; |
| 3061 | u32 phy_addr, page_off, size; |
| 3062 | |
| 3063 | phy_addr = offset & ~pagemask; |
| 3064 | |
| 3065 | for (j = 0; j < pagesize; j += 4) { |
| 3066 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
| 3067 | (__be32 *) (tmp + j)); |
| 3068 | if (ret) |
| 3069 | break; |
| 3070 | } |
| 3071 | if (ret) |
| 3072 | break; |
| 3073 | |
| 3074 | page_off = offset & pagemask; |
| 3075 | size = pagesize; |
| 3076 | if (len < size) |
| 3077 | size = len; |
| 3078 | |
| 3079 | len -= size; |
| 3080 | |
| 3081 | memcpy(tmp + page_off, buf, size); |
| 3082 | |
| 3083 | offset = offset + (pagesize - page_off); |
| 3084 | |
| 3085 | tg3_enable_nvram_access(tp); |
| 3086 | |
| 3087 | /* |
| 3088 | * Before we can erase the flash page, we need |
| 3089 | * to issue a special "write enable" command. |
| 3090 | */ |
| 3091 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3092 | |
| 3093 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3094 | break; |
| 3095 | |
| 3096 | /* Erase the target page */ |
| 3097 | tw32(NVRAM_ADDR, phy_addr); |
| 3098 | |
| 3099 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | |
| 3100 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; |
| 3101 | |
| 3102 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3103 | break; |
| 3104 | |
| 3105 | /* Issue another write enable to start the write. */ |
| 3106 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3107 | |
| 3108 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3109 | break; |
| 3110 | |
| 3111 | for (j = 0; j < pagesize; j += 4) { |
| 3112 | __be32 data; |
| 3113 | |
| 3114 | data = *((__be32 *) (tmp + j)); |
| 3115 | |
| 3116 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3117 | |
| 3118 | tw32(NVRAM_ADDR, phy_addr + j); |
| 3119 | |
| 3120 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | |
| 3121 | NVRAM_CMD_WR; |
| 3122 | |
| 3123 | if (j == 0) |
| 3124 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 3125 | else if (j == (pagesize - 4)) |
| 3126 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3127 | |
| 3128 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3129 | if (ret) |
| 3130 | break; |
| 3131 | } |
| 3132 | if (ret) |
| 3133 | break; |
| 3134 | } |
| 3135 | |
| 3136 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3137 | tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3138 | |
| 3139 | kfree(tmp); |
| 3140 | |
| 3141 | return ret; |
| 3142 | } |
| 3143 | |
| 3144 | /* offset and length are dword aligned */ |
| 3145 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, |
| 3146 | u8 *buf) |
| 3147 | { |
| 3148 | int i, ret = 0; |
| 3149 | |
| 3150 | for (i = 0; i < len; i += 4, offset += 4) { |
| 3151 | u32 page_off, phy_addr, nvram_cmd; |
| 3152 | __be32 data; |
| 3153 | |
| 3154 | memcpy(&data, buf + i, 4); |
| 3155 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3156 | |
| 3157 | page_off = offset % tp->nvram_pagesize; |
| 3158 | |
| 3159 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
| 3160 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3161 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
| 3162 | |
| 3163 | if (page_off == 0 || i == 0) |
| 3164 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 3165 | if (page_off == (tp->nvram_pagesize - 4)) |
| 3166 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3167 | |
| 3168 | if (i == (len - 4)) |
| 3169 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3170 | |
Matt Carlson | 4227822 | 2012-02-13 15:20:11 +0000 | [diff] [blame] | 3171 | if ((nvram_cmd & NVRAM_CMD_FIRST) || |
| 3172 | !tg3_flag(tp, FLASH) || |
| 3173 | !tg3_flag(tp, 57765_PLUS)) |
| 3174 | tw32(NVRAM_ADDR, phy_addr); |
| 3175 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3176 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
| 3177 | !tg3_flag(tp, 5755_PLUS) && |
| 3178 | (tp->nvram_jedecnum == JEDEC_ST) && |
| 3179 | (nvram_cmd & NVRAM_CMD_FIRST)) { |
| 3180 | u32 cmd; |
| 3181 | |
| 3182 | cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3183 | ret = tg3_nvram_exec_cmd(tp, cmd); |
| 3184 | if (ret) |
| 3185 | break; |
| 3186 | } |
| 3187 | if (!tg3_flag(tp, FLASH)) { |
| 3188 | /* We always do complete word writes to eeprom. */ |
| 3189 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); |
| 3190 | } |
| 3191 | |
| 3192 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3193 | if (ret) |
| 3194 | break; |
| 3195 | } |
| 3196 | return ret; |
| 3197 | } |
| 3198 | |
| 3199 | /* offset and length are dword aligned */ |
| 3200 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) |
| 3201 | { |
| 3202 | int ret; |
| 3203 | |
| 3204 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3205 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
| 3206 | ~GRC_LCLCTRL_GPIO_OUTPUT1); |
| 3207 | udelay(40); |
| 3208 | } |
| 3209 | |
| 3210 | if (!tg3_flag(tp, NVRAM)) { |
| 3211 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
| 3212 | } else { |
| 3213 | u32 grc_mode; |
| 3214 | |
| 3215 | ret = tg3_nvram_lock(tp); |
| 3216 | if (ret) |
| 3217 | return ret; |
| 3218 | |
| 3219 | tg3_enable_nvram_access(tp); |
| 3220 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) |
| 3221 | tw32(NVRAM_WRITE1, 0x406); |
| 3222 | |
| 3223 | grc_mode = tr32(GRC_MODE); |
| 3224 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); |
| 3225 | |
| 3226 | if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) { |
| 3227 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
| 3228 | buf); |
| 3229 | } else { |
| 3230 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
| 3231 | buf); |
| 3232 | } |
| 3233 | |
| 3234 | grc_mode = tr32(GRC_MODE); |
| 3235 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); |
| 3236 | |
| 3237 | tg3_disable_nvram_access(tp); |
| 3238 | tg3_nvram_unlock(tp); |
| 3239 | } |
| 3240 | |
| 3241 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3242 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 3243 | udelay(40); |
| 3244 | } |
| 3245 | |
| 3246 | return ret; |
| 3247 | } |
| 3248 | |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3249 | #define RX_CPU_SCRATCH_BASE 0x30000 |
| 3250 | #define RX_CPU_SCRATCH_SIZE 0x04000 |
| 3251 | #define TX_CPU_SCRATCH_BASE 0x34000 |
| 3252 | #define TX_CPU_SCRATCH_SIZE 0x04000 |
| 3253 | |
| 3254 | /* tp->lock is held. */ |
| 3255 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) |
| 3256 | { |
| 3257 | int i; |
| 3258 | |
| 3259 | BUG_ON(offset == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)); |
| 3260 | |
| 3261 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 3262 | u32 val = tr32(GRC_VCPU_EXT_CTRL); |
| 3263 | |
| 3264 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 3265 | return 0; |
| 3266 | } |
| 3267 | if (offset == RX_CPU_BASE) { |
| 3268 | for (i = 0; i < 10000; i++) { |
| 3269 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3270 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 3271 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 3272 | break; |
| 3273 | } |
| 3274 | |
| 3275 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3276 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); |
| 3277 | udelay(10); |
| 3278 | } else { |
| 3279 | for (i = 0; i < 10000; i++) { |
| 3280 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3281 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 3282 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 3283 | break; |
| 3284 | } |
| 3285 | } |
| 3286 | |
| 3287 | if (i >= 10000) { |
| 3288 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
| 3289 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); |
| 3290 | return -ENODEV; |
| 3291 | } |
| 3292 | |
| 3293 | /* Clear firmware's nvram arbitration. */ |
| 3294 | if (tg3_flag(tp, NVRAM)) |
| 3295 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
| 3296 | return 0; |
| 3297 | } |
| 3298 | |
| 3299 | struct fw_info { |
| 3300 | unsigned int fw_base; |
| 3301 | unsigned int fw_len; |
| 3302 | const __be32 *fw_data; |
| 3303 | }; |
| 3304 | |
| 3305 | /* tp->lock is held. */ |
| 3306 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, |
| 3307 | u32 cpu_scratch_base, int cpu_scratch_size, |
| 3308 | struct fw_info *info) |
| 3309 | { |
| 3310 | int err, lock_err, i; |
| 3311 | void (*write_op)(struct tg3 *, u32, u32); |
| 3312 | |
| 3313 | if (cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)) { |
| 3314 | netdev_err(tp->dev, |
| 3315 | "%s: Trying to load TX cpu firmware which is 5705\n", |
| 3316 | __func__); |
| 3317 | return -EINVAL; |
| 3318 | } |
| 3319 | |
| 3320 | if (tg3_flag(tp, 5705_PLUS)) |
| 3321 | write_op = tg3_write_mem; |
| 3322 | else |
| 3323 | write_op = tg3_write_indirect_reg32; |
| 3324 | |
| 3325 | /* It is possible that bootcode is still loading at this point. |
| 3326 | * Get the nvram lock first before halting the cpu. |
| 3327 | */ |
| 3328 | lock_err = tg3_nvram_lock(tp); |
| 3329 | err = tg3_halt_cpu(tp, cpu_base); |
| 3330 | if (!lock_err) |
| 3331 | tg3_nvram_unlock(tp); |
| 3332 | if (err) |
| 3333 | goto out; |
| 3334 | |
| 3335 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
| 3336 | write_op(tp, cpu_scratch_base + i, 0); |
| 3337 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3338 | tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT); |
| 3339 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
| 3340 | write_op(tp, (cpu_scratch_base + |
| 3341 | (info->fw_base & 0xffff) + |
| 3342 | (i * sizeof(u32))), |
| 3343 | be32_to_cpu(info->fw_data[i])); |
| 3344 | |
| 3345 | err = 0; |
| 3346 | |
| 3347 | out: |
| 3348 | return err; |
| 3349 | } |
| 3350 | |
| 3351 | /* tp->lock is held. */ |
| 3352 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) |
| 3353 | { |
| 3354 | struct fw_info info; |
| 3355 | const __be32 *fw_data; |
| 3356 | int err, i; |
| 3357 | |
| 3358 | fw_data = (void *)tp->fw->data; |
| 3359 | |
| 3360 | /* Firmware blob starts with version numbers, followed by |
| 3361 | start address and length. We are setting complete length. |
| 3362 | length = end_address_of_bss - start_address_of_text. |
| 3363 | Remainder is the blob to be loaded contiguously |
| 3364 | from start address. */ |
| 3365 | |
| 3366 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 3367 | info.fw_len = tp->fw->size - 12; |
| 3368 | info.fw_data = &fw_data[3]; |
| 3369 | |
| 3370 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
| 3371 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, |
| 3372 | &info); |
| 3373 | if (err) |
| 3374 | return err; |
| 3375 | |
| 3376 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, |
| 3377 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, |
| 3378 | &info); |
| 3379 | if (err) |
| 3380 | return err; |
| 3381 | |
| 3382 | /* Now startup only the RX cpu. */ |
| 3383 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3384 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
| 3385 | |
| 3386 | for (i = 0; i < 5; i++) { |
| 3387 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
| 3388 | break; |
| 3389 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3390 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); |
| 3391 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
| 3392 | udelay(1000); |
| 3393 | } |
| 3394 | if (i >= 5) { |
| 3395 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
| 3396 | "should be %08x\n", __func__, |
| 3397 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
| 3398 | return -ENODEV; |
| 3399 | } |
| 3400 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3401 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); |
| 3402 | |
| 3403 | return 0; |
| 3404 | } |
| 3405 | |
| 3406 | /* tp->lock is held. */ |
| 3407 | static int tg3_load_tso_firmware(struct tg3 *tp) |
| 3408 | { |
| 3409 | struct fw_info info; |
| 3410 | const __be32 *fw_data; |
| 3411 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
| 3412 | int err, i; |
| 3413 | |
| 3414 | if (tg3_flag(tp, HW_TSO_1) || |
| 3415 | tg3_flag(tp, HW_TSO_2) || |
| 3416 | tg3_flag(tp, HW_TSO_3)) |
| 3417 | return 0; |
| 3418 | |
| 3419 | fw_data = (void *)tp->fw->data; |
| 3420 | |
| 3421 | /* Firmware blob starts with version numbers, followed by |
| 3422 | start address and length. We are setting complete length. |
| 3423 | length = end_address_of_bss - start_address_of_text. |
| 3424 | Remainder is the blob to be loaded contiguously |
| 3425 | from start address. */ |
| 3426 | |
| 3427 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 3428 | cpu_scratch_size = tp->fw_len; |
| 3429 | info.fw_len = tp->fw->size - 12; |
| 3430 | info.fw_data = &fw_data[3]; |
| 3431 | |
| 3432 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 3433 | cpu_base = RX_CPU_BASE; |
| 3434 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; |
| 3435 | } else { |
| 3436 | cpu_base = TX_CPU_BASE; |
| 3437 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; |
| 3438 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; |
| 3439 | } |
| 3440 | |
| 3441 | err = tg3_load_firmware_cpu(tp, cpu_base, |
| 3442 | cpu_scratch_base, cpu_scratch_size, |
| 3443 | &info); |
| 3444 | if (err) |
| 3445 | return err; |
| 3446 | |
| 3447 | /* Now startup the cpu. */ |
| 3448 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3449 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
| 3450 | |
| 3451 | for (i = 0; i < 5; i++) { |
| 3452 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
| 3453 | break; |
| 3454 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3455 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
| 3456 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
| 3457 | udelay(1000); |
| 3458 | } |
| 3459 | if (i >= 5) { |
| 3460 | netdev_err(tp->dev, |
| 3461 | "%s fails to set CPU PC, is %08x should be %08x\n", |
| 3462 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
| 3463 | return -ENODEV; |
| 3464 | } |
| 3465 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3466 | tw32_f(cpu_base + CPU_MODE, 0x00000000); |
| 3467 | return 0; |
| 3468 | } |
| 3469 | |
| 3470 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3471 | /* tp->lock is held. */ |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 3472 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) |
| 3473 | { |
| 3474 | u32 addr_high, addr_low; |
| 3475 | int i; |
| 3476 | |
| 3477 | addr_high = ((tp->dev->dev_addr[0] << 8) | |
| 3478 | tp->dev->dev_addr[1]); |
| 3479 | addr_low = ((tp->dev->dev_addr[2] << 24) | |
| 3480 | (tp->dev->dev_addr[3] << 16) | |
| 3481 | (tp->dev->dev_addr[4] << 8) | |
| 3482 | (tp->dev->dev_addr[5] << 0)); |
| 3483 | for (i = 0; i < 4; i++) { |
| 3484 | if (i == 1 && skip_mac_1) |
| 3485 | continue; |
| 3486 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); |
| 3487 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); |
| 3488 | } |
| 3489 | |
| 3490 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 3491 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 3492 | for (i = 0; i < 12; i++) { |
| 3493 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); |
| 3494 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | addr_high = (tp->dev->dev_addr[0] + |
| 3499 | tp->dev->dev_addr[1] + |
| 3500 | tp->dev->dev_addr[2] + |
| 3501 | tp->dev->dev_addr[3] + |
| 3502 | tp->dev->dev_addr[4] + |
| 3503 | tp->dev->dev_addr[5]) & |
| 3504 | TX_BACKOFF_SEED_MASK; |
| 3505 | tw32(MAC_TX_BACKOFF_SEED, addr_high); |
| 3506 | } |
| 3507 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3508 | static void tg3_enable_register_access(struct tg3 *tp) |
| 3509 | { |
| 3510 | /* |
| 3511 | * Make sure register accesses (indirect or otherwise) will function |
| 3512 | * correctly. |
| 3513 | */ |
| 3514 | pci_write_config_dword(tp->pdev, |
| 3515 | TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl); |
| 3516 | } |
| 3517 | |
| 3518 | static int tg3_power_up(struct tg3 *tp) |
| 3519 | { |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3520 | int err; |
| 3521 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3522 | tg3_enable_register_access(tp); |
| 3523 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3524 | err = pci_set_power_state(tp->pdev, PCI_D0); |
| 3525 | if (!err) { |
| 3526 | /* Switch out of Vaux if it is a NIC */ |
| 3527 | tg3_pwrsrc_switch_to_vmain(tp); |
| 3528 | } else { |
| 3529 | netdev_err(tp->dev, "Transition to D0 failed\n"); |
| 3530 | } |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3531 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3532 | return err; |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3533 | } |
| 3534 | |
Matt Carlson | 4b40952 | 2012-02-13 10:20:11 +0000 | [diff] [blame] | 3535 | static int tg3_setup_phy(struct tg3 *, int); |
| 3536 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3537 | static int tg3_power_down_prepare(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | { |
| 3539 | u32 misc_host_ctrl; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3540 | bool device_should_wake, do_low_power; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3542 | tg3_enable_register_access(tp); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3543 | |
| 3544 | /* Restore the CLKREQ setting. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3545 | if (tg3_flag(tp, CLKREQ_BUG)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3546 | u16 lnkctl; |
| 3547 | |
| 3548 | pci_read_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 3549 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3550 | &lnkctl); |
| 3551 | lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3552 | pci_write_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 3553 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3554 | lnkctl); |
| 3555 | } |
| 3556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 3558 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 3559 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); |
| 3560 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3561 | device_should_wake = device_may_wakeup(&tp->pdev->dev) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3562 | tg3_flag(tp, WOL_ENABLE); |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3563 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3564 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3565 | do_low_power = false; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3566 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3567 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3568 | struct phy_device *phydev; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3569 | u32 phyid, advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3570 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 3571 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3572 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3573 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3574 | |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 3575 | tp->link_config.speed = phydev->speed; |
| 3576 | tp->link_config.duplex = phydev->duplex; |
| 3577 | tp->link_config.autoneg = phydev->autoneg; |
| 3578 | tp->link_config.advertising = phydev->advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3579 | |
| 3580 | advertising = ADVERTISED_TP | |
| 3581 | ADVERTISED_Pause | |
| 3582 | ADVERTISED_Autoneg | |
| 3583 | ADVERTISED_10baseT_Half; |
| 3584 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3585 | if (tg3_flag(tp, ENABLE_ASF) || device_should_wake) { |
| 3586 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3587 | advertising |= |
| 3588 | ADVERTISED_100baseT_Half | |
| 3589 | ADVERTISED_100baseT_Full | |
| 3590 | ADVERTISED_10baseT_Full; |
| 3591 | else |
| 3592 | advertising |= ADVERTISED_10baseT_Full; |
| 3593 | } |
| 3594 | |
| 3595 | phydev->advertising = advertising; |
| 3596 | |
| 3597 | phy_start_aneg(phydev); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3598 | |
| 3599 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 3600 | if (phyid != PHY_ID_BCMAC131) { |
| 3601 | phyid &= PHY_BCM_OUI_MASK; |
| 3602 | if (phyid == PHY_BCM_OUI_1 || |
| 3603 | phyid == PHY_BCM_OUI_2 || |
| 3604 | phyid == PHY_BCM_OUI_3) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3605 | do_low_power = true; |
| 3606 | } |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3607 | } |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3608 | } else { |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 3609 | do_low_power = true; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3610 | |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 3611 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3612 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | |
Matt Carlson | 2855b9f | 2012-02-13 15:20:14 +0000 | [diff] [blame] | 3614 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3615 | tg3_setup_phy(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 3618 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 3619 | u32 val; |
| 3620 | |
| 3621 | val = tr32(GRC_VCPU_EXT_CTRL); |
| 3622 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3623 | } else if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3624 | int i; |
| 3625 | u32 val; |
| 3626 | |
| 3627 | for (i = 0; i < 200; i++) { |
| 3628 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); |
| 3629 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 3630 | break; |
| 3631 | msleep(1); |
| 3632 | } |
| 3633 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3634 | if (tg3_flag(tp, WOL_CAP)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 3635 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
| 3636 | WOL_DRV_STATE_SHUTDOWN | |
| 3637 | WOL_DRV_WOL | |
| 3638 | WOL_SET_MAGIC_PKT); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3639 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3640 | if (device_should_wake) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | u32 mac_mode; |
| 3642 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3643 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 3644 | if (do_low_power && |
| 3645 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 3646 | tg3_phy_auxctl_write(tp, |
| 3647 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL, |
| 3648 | MII_TG3_AUXCTL_PCTL_WOL_EN | |
| 3649 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 3650 | MII_TG3_AUXCTL_PCTL_CL_AB_TXDAC); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3651 | udelay(40); |
| 3652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3654 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 3655 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 3656 | else |
| 3657 | mac_mode = MAC_MODE_PORT_MODE_MII; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3659 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
| 3660 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 3661 | ASIC_REV_5700) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3662 | u32 speed = tg3_flag(tp, WOL_SPEED_100MB) ? |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3663 | SPEED_100 : SPEED_10; |
| 3664 | if (tg3_5700_link_polarity(tp, speed)) |
| 3665 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 3666 | else |
| 3667 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 3668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | } else { |
| 3670 | mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 3671 | } |
| 3672 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3673 | if (!tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 3675 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3676 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3677 | if ((tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) && |
| 3678 | (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE))) |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3679 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3681 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 3682 | mac_mode |= MAC_MODE_APE_TX_EN | |
| 3683 | MAC_MODE_APE_RX_EN | |
| 3684 | MAC_MODE_TDE_ENABLE; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 3685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | tw32_f(MAC_MODE, mac_mode); |
| 3687 | udelay(100); |
| 3688 | |
| 3689 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); |
| 3690 | udelay(10); |
| 3691 | } |
| 3692 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3693 | if (!tg3_flag(tp, WOL_SPEED_100MB) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3695 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 3696 | u32 base_val; |
| 3697 | |
| 3698 | base_val = tp->pci_clock_ctrl; |
| 3699 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | |
| 3700 | CLOCK_CTRL_TXCLK_DISABLE); |
| 3701 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3702 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
| 3703 | CLOCK_CTRL_PWRDOWN_PLL133, 40); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3704 | } else if (tg3_flag(tp, 5780_CLASS) || |
| 3705 | tg3_flag(tp, CPMU_PRESENT) || |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 3706 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 3707 | /* do nothing */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3708 | } else if (!(tg3_flag(tp, 5750_PLUS) && tg3_flag(tp, ENABLE_ASF))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | u32 newbits1, newbits2; |
| 3710 | |
| 3711 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3712 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3713 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 3714 | CLOCK_CTRL_TXCLK_DISABLE | |
| 3715 | CLOCK_CTRL_ALTCLK); |
| 3716 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3717 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | newbits1 = CLOCK_CTRL_625_CORE; |
| 3719 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; |
| 3720 | } else { |
| 3721 | newbits1 = CLOCK_CTRL_ALTCLK; |
| 3722 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 3723 | } |
| 3724 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3725 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
| 3726 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3728 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
| 3729 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3731 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | u32 newbits3; |
| 3733 | |
| 3734 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3735 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3736 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 3737 | CLOCK_CTRL_TXCLK_DISABLE | |
| 3738 | CLOCK_CTRL_44MHZ_CORE); |
| 3739 | } else { |
| 3740 | newbits3 = CLOCK_CTRL_44MHZ_CORE; |
| 3741 | } |
| 3742 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3743 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 3744 | tp->pci_clock_ctrl | newbits3, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | } |
| 3746 | } |
| 3747 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3748 | if (!(device_should_wake) && !tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3749 | tg3_power_down_phy(tp, do_low_power); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3750 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 3751 | tg3_frob_aux_power(tp, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | |
| 3753 | /* Workaround for unstable PLL clock */ |
| 3754 | if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) || |
| 3755 | (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) { |
| 3756 | u32 val = tr32(0x7d00); |
| 3757 | |
| 3758 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); |
| 3759 | tw32(0x7d00, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3760 | if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 3761 | int err; |
| 3762 | |
| 3763 | err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 3765 | if (!err) |
| 3766 | tg3_nvram_unlock(tp); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3767 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | } |
| 3769 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 3770 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
| 3771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | return 0; |
| 3773 | } |
| 3774 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3775 | static void tg3_power_down(struct tg3 *tp) |
| 3776 | { |
| 3777 | tg3_power_down_prepare(tp); |
| 3778 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3779 | pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3780 | pci_set_power_state(tp->pdev, PCI_D3hot); |
| 3781 | } |
| 3782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
| 3784 | { |
| 3785 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { |
| 3786 | case MII_TG3_AUX_STAT_10HALF: |
| 3787 | *speed = SPEED_10; |
| 3788 | *duplex = DUPLEX_HALF; |
| 3789 | break; |
| 3790 | |
| 3791 | case MII_TG3_AUX_STAT_10FULL: |
| 3792 | *speed = SPEED_10; |
| 3793 | *duplex = DUPLEX_FULL; |
| 3794 | break; |
| 3795 | |
| 3796 | case MII_TG3_AUX_STAT_100HALF: |
| 3797 | *speed = SPEED_100; |
| 3798 | *duplex = DUPLEX_HALF; |
| 3799 | break; |
| 3800 | |
| 3801 | case MII_TG3_AUX_STAT_100FULL: |
| 3802 | *speed = SPEED_100; |
| 3803 | *duplex = DUPLEX_FULL; |
| 3804 | break; |
| 3805 | |
| 3806 | case MII_TG3_AUX_STAT_1000HALF: |
| 3807 | *speed = SPEED_1000; |
| 3808 | *duplex = DUPLEX_HALF; |
| 3809 | break; |
| 3810 | |
| 3811 | case MII_TG3_AUX_STAT_1000FULL: |
| 3812 | *speed = SPEED_1000; |
| 3813 | *duplex = DUPLEX_FULL; |
| 3814 | break; |
| 3815 | |
| 3816 | default: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3817 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 3818 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
| 3819 | SPEED_10; |
| 3820 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : |
| 3821 | DUPLEX_HALF; |
| 3822 | break; |
| 3823 | } |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 3824 | *speed = SPEED_UNKNOWN; |
| 3825 | *duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3827 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3830 | 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] | 3831 | { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3832 | int err = 0; |
| 3833 | u32 val, new_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3835 | new_adv = ADVERTISE_CSMA; |
Hiroaki SHIMODA | 202ff1c | 2011-11-22 04:05:41 +0000 | [diff] [blame] | 3836 | new_adv |= ethtool_adv_to_mii_adv_t(advertise) & ADVERTISE_ALL; |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 3837 | new_adv |= mii_advertise_flowctrl(flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3839 | err = tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 3840 | if (err) |
| 3841 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 3843 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 3844 | new_adv = ethtool_adv_to_mii_ctrl1000_t(advertise); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 3845 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 3846 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 3847 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) |
| 3848 | new_adv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 3849 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 3850 | err = tg3_writephy(tp, MII_CTRL1000, new_adv); |
| 3851 | if (err) |
| 3852 | goto done; |
| 3853 | } |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 3854 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3855 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 3856 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3858 | tw32(TG3_CPMU_EEE_MODE, |
| 3859 | tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 3860 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3861 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
| 3862 | if (!err) { |
| 3863 | u32 err2; |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3864 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 3865 | val = 0; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3866 | /* Advertise 100-BaseTX EEE ability */ |
| 3867 | if (advertise & ADVERTISED_100baseT_Full) |
| 3868 | val |= MDIO_AN_EEE_ADV_100TX; |
| 3869 | /* Advertise 1000-BaseT EEE ability */ |
| 3870 | if (advertise & ADVERTISED_1000baseT_Full) |
| 3871 | val |= MDIO_AN_EEE_ADV_1000T; |
| 3872 | err = tg3_phy_cl45_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, val); |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 3873 | if (err) |
| 3874 | val = 0; |
| 3875 | |
| 3876 | switch (GET_ASIC_REV(tp->pci_chip_rev_id)) { |
| 3877 | case ASIC_REV_5717: |
| 3878 | case ASIC_REV_57765: |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 3879 | case ASIC_REV_57766: |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 3880 | case ASIC_REV_5719: |
| 3881 | /* If we advertised any eee advertisements above... */ |
| 3882 | if (val) |
| 3883 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 3884 | MII_TG3_DSP_TAP26_RMRXSTO | |
| 3885 | MII_TG3_DSP_TAP26_OPCSINPT; |
| 3886 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
| 3887 | /* Fall through */ |
| 3888 | case ASIC_REV_5720: |
| 3889 | if (!tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) |
| 3890 | tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, val | |
| 3891 | MII_TG3_DSP_CH34TP2_HIBW01); |
| 3892 | } |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3893 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3894 | err2 = TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 3895 | if (!err) |
| 3896 | err = err2; |
| 3897 | } |
| 3898 | |
| 3899 | done: |
| 3900 | return err; |
| 3901 | } |
| 3902 | |
| 3903 | static void tg3_phy_copper_begin(struct tg3 *tp) |
| 3904 | { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3905 | if (tp->link_config.autoneg == AUTONEG_ENABLE || |
| 3906 | (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 3907 | u32 adv, fc; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3908 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3909 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 3910 | adv = ADVERTISED_10baseT_Half | |
| 3911 | ADVERTISED_10baseT_Full; |
| 3912 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
| 3913 | adv |= ADVERTISED_100baseT_Half | |
| 3914 | ADVERTISED_100baseT_Full; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3915 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3916 | fc = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3917 | } else { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3918 | adv = tp->link_config.advertising; |
| 3919 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 3920 | adv &= ~(ADVERTISED_1000baseT_Half | |
| 3921 | ADVERTISED_1000baseT_Full); |
| 3922 | |
| 3923 | fc = tp->link_config.flowctrl; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3924 | } |
| 3925 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3926 | tg3_phy_autoneg_cfg(tp, adv, fc); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3927 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 3928 | tg3_writephy(tp, MII_BMCR, |
| 3929 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 3930 | } else { |
| 3931 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | u32 bmcr, orig_bmcr; |
| 3933 | |
| 3934 | tp->link_config.active_speed = tp->link_config.speed; |
| 3935 | tp->link_config.active_duplex = tp->link_config.duplex; |
| 3936 | |
| 3937 | bmcr = 0; |
| 3938 | switch (tp->link_config.speed) { |
| 3939 | default: |
| 3940 | case SPEED_10: |
| 3941 | break; |
| 3942 | |
| 3943 | case SPEED_100: |
| 3944 | bmcr |= BMCR_SPEED100; |
| 3945 | break; |
| 3946 | |
| 3947 | case SPEED_1000: |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 3948 | bmcr |= BMCR_SPEED1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3950 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | |
| 3952 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 3953 | bmcr |= BMCR_FULLDPLX; |
| 3954 | |
| 3955 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && |
| 3956 | (bmcr != orig_bmcr)) { |
| 3957 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); |
| 3958 | for (i = 0; i < 1500; i++) { |
| 3959 | u32 tmp; |
| 3960 | |
| 3961 | udelay(10); |
| 3962 | if (tg3_readphy(tp, MII_BMSR, &tmp) || |
| 3963 | tg3_readphy(tp, MII_BMSR, &tmp)) |
| 3964 | continue; |
| 3965 | if (!(tmp & BMSR_LSTATUS)) { |
| 3966 | udelay(40); |
| 3967 | break; |
| 3968 | } |
| 3969 | } |
| 3970 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 3971 | udelay(40); |
| 3972 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | } |
| 3974 | } |
| 3975 | |
| 3976 | static int tg3_init_5401phy_dsp(struct tg3 *tp) |
| 3977 | { |
| 3978 | int err; |
| 3979 | |
| 3980 | /* Turn off tap power management. */ |
| 3981 | /* Set Extended packet length bit */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 3982 | err = tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 3984 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
| 3985 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); |
| 3986 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); |
| 3987 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); |
| 3988 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | |
| 3990 | udelay(40); |
| 3991 | |
| 3992 | return err; |
| 3993 | } |
| 3994 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 3995 | static bool tg3_phy_copper_an_config_ok(struct tg3 *tp, u32 *lcladv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | { |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 3997 | u32 advmsk, tgtadv, advertising; |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 3998 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 3999 | advertising = tp->link_config.advertising; |
| 4000 | tgtadv = ethtool_adv_to_mii_adv_t(advertising) & ADVERTISE_ALL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4002 | advmsk = ADVERTISE_ALL; |
| 4003 | if (tp->link_config.active_duplex == DUPLEX_FULL) { |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 4004 | tgtadv |= mii_advertise_flowctrl(tp->link_config.flowctrl); |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4005 | advmsk |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 4006 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4008 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
| 4009 | return false; |
| 4010 | |
| 4011 | if ((*lcladv & advmsk) != tgtadv) |
| 4012 | return false; |
Matt Carlson | b99d2a5 | 2011-08-31 11:44:47 +0000 | [diff] [blame] | 4013 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4014 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | u32 tg3_ctrl; |
| 4016 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4017 | tgtadv = ethtool_adv_to_mii_ctrl1000_t(advertising); |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 4018 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 4019 | if (tg3_readphy(tp, MII_CTRL1000, &tg3_ctrl)) |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4020 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | |
Matt Carlson | 3198e07 | 2012-02-13 15:20:10 +0000 | [diff] [blame] | 4022 | if (tgtadv && |
| 4023 | (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 4024 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)) { |
| 4025 | tgtadv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
| 4026 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL | |
| 4027 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
| 4028 | } else { |
| 4029 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL); |
| 4030 | } |
| 4031 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4032 | if (tg3_ctrl != tgtadv) |
| 4033 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | } |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 4035 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4036 | return true; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4037 | } |
| 4038 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4039 | static bool tg3_phy_copper_fetch_rmtadv(struct tg3 *tp, u32 *rmtadv) |
| 4040 | { |
| 4041 | u32 lpeth = 0; |
| 4042 | |
| 4043 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4044 | u32 val; |
| 4045 | |
| 4046 | if (tg3_readphy(tp, MII_STAT1000, &val)) |
| 4047 | return false; |
| 4048 | |
| 4049 | lpeth = mii_stat1000_to_ethtool_lpa_t(val); |
| 4050 | } |
| 4051 | |
| 4052 | if (tg3_readphy(tp, MII_LPA, rmtadv)) |
| 4053 | return false; |
| 4054 | |
| 4055 | lpeth |= mii_lpa_to_ethtool_lpa_t(*rmtadv); |
| 4056 | tp->link_config.rmt_adv = lpeth; |
| 4057 | |
| 4058 | return true; |
| 4059 | } |
| 4060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
| 4062 | { |
| 4063 | int current_link_up; |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4064 | u32 bmsr, val; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4065 | u32 lcl_adv, rmt_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | u16 current_speed; |
| 4067 | u8 current_duplex; |
| 4068 | int i, err; |
| 4069 | |
| 4070 | tw32(MAC_EVENT, 0); |
| 4071 | |
| 4072 | tw32_f(MAC_STATUS, |
| 4073 | (MAC_STATUS_SYNC_CHANGED | |
| 4074 | MAC_STATUS_CFG_CHANGED | |
| 4075 | MAC_STATUS_MI_COMPLETION | |
| 4076 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4077 | udelay(40); |
| 4078 | |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 4079 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 4080 | tw32_f(MAC_MI_MODE, |
| 4081 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 4082 | udelay(80); |
| 4083 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4085 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | |
| 4087 | /* Some third-party PHYs need to be reset on link going |
| 4088 | * down. |
| 4089 | */ |
| 4090 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 4091 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 4092 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
| 4093 | netif_carrier_ok(tp->dev)) { |
| 4094 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4095 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4096 | !(bmsr & BMSR_LSTATUS)) |
| 4097 | force_reset = 1; |
| 4098 | } |
| 4099 | if (force_reset) |
| 4100 | tg3_phy_reset(tp); |
| 4101 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4102 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4104 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || |
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 | bmsr = 0; |
| 4107 | |
| 4108 | if (!(bmsr & BMSR_LSTATUS)) { |
| 4109 | err = tg3_init_5401phy_dsp(tp); |
| 4110 | if (err) |
| 4111 | return err; |
| 4112 | |
| 4113 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4114 | for (i = 0; i < 1000; i++) { |
| 4115 | udelay(10); |
| 4116 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4117 | (bmsr & BMSR_LSTATUS)) { |
| 4118 | udelay(40); |
| 4119 | break; |
| 4120 | } |
| 4121 | } |
| 4122 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4123 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
| 4124 | TG3_PHY_REV_BCM5401_B0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | !(bmsr & BMSR_LSTATUS) && |
| 4126 | tp->link_config.active_speed == SPEED_1000) { |
| 4127 | err = tg3_phy_reset(tp); |
| 4128 | if (!err) |
| 4129 | err = tg3_init_5401phy_dsp(tp); |
| 4130 | if (err) |
| 4131 | return err; |
| 4132 | } |
| 4133 | } |
| 4134 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 4135 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { |
| 4136 | /* 5701 {A0,B0} CRC bug workaround */ |
| 4137 | tg3_writephy(tp, 0x15, 0x0a75); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4138 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
| 4139 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 4140 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | /* Clear pending interrupts... */ |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4144 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
| 4145 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4147 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4149 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
| 4151 | |
| 4152 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 4153 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 4154 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
| 4155 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 4156 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 4157 | else |
| 4158 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); |
| 4159 | } |
| 4160 | |
| 4161 | current_link_up = 0; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 4162 | current_speed = SPEED_UNKNOWN; |
| 4163 | current_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4164 | tp->phy_flags &= ~TG3_PHYFLG_MDIX_STATE; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4165 | tp->link_config.rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4167 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 4168 | err = tg3_phy_auxctl_read(tp, |
| 4169 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4170 | &val); |
| 4171 | if (!err && !(val & (1 << 10))) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4172 | tg3_phy_auxctl_write(tp, |
| 4173 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4174 | val | (1 << 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | goto relink; |
| 4176 | } |
| 4177 | } |
| 4178 | |
| 4179 | bmsr = 0; |
| 4180 | for (i = 0; i < 100; i++) { |
| 4181 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4182 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4183 | (bmsr & BMSR_LSTATUS)) |
| 4184 | break; |
| 4185 | udelay(40); |
| 4186 | } |
| 4187 | |
| 4188 | if (bmsr & BMSR_LSTATUS) { |
| 4189 | u32 aux_stat, bmcr; |
| 4190 | |
| 4191 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); |
| 4192 | for (i = 0; i < 2000; i++) { |
| 4193 | udelay(10); |
| 4194 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && |
| 4195 | aux_stat) |
| 4196 | break; |
| 4197 | } |
| 4198 | |
| 4199 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, |
| 4200 | ¤t_speed, |
| 4201 | ¤t_duplex); |
| 4202 | |
| 4203 | bmcr = 0; |
| 4204 | for (i = 0; i < 200; i++) { |
| 4205 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4206 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) |
| 4207 | continue; |
| 4208 | if (bmcr && bmcr != 0x7fff) |
| 4209 | break; |
| 4210 | udelay(10); |
| 4211 | } |
| 4212 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4213 | lcl_adv = 0; |
| 4214 | rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4216 | tp->link_config.active_speed = current_speed; |
| 4217 | tp->link_config.active_duplex = current_duplex; |
| 4218 | |
| 4219 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 4220 | if ((bmcr & BMCR_ANENABLE) && |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4221 | tg3_phy_copper_an_config_ok(tp, &lcl_adv) && |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4222 | tg3_phy_copper_fetch_rmtadv(tp, &rmt_adv)) |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4223 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | } else { |
| 4225 | if (!(bmcr & BMCR_ANENABLE) && |
| 4226 | tp->link_config.speed == current_speed && |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4227 | tp->link_config.duplex == current_duplex && |
| 4228 | tp->link_config.flowctrl == |
| 4229 | tp->link_config.active_flowctrl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | } |
| 4232 | } |
| 4233 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4234 | if (current_link_up == 1 && |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4235 | tp->link_config.active_duplex == DUPLEX_FULL) { |
| 4236 | u32 reg, bit; |
| 4237 | |
| 4238 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 4239 | reg = MII_TG3_FET_GEN_STAT; |
| 4240 | bit = MII_TG3_FET_GEN_STAT_MDIXSTAT; |
| 4241 | } else { |
| 4242 | reg = MII_TG3_EXT_STAT; |
| 4243 | bit = MII_TG3_EXT_STAT_MDIX; |
| 4244 | } |
| 4245 | |
| 4246 | if (!tg3_readphy(tp, reg, &val) && (val & bit)) |
| 4247 | tp->phy_flags |= TG3_PHYFLG_MDIX_STATE; |
| 4248 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4249 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | } |
| 4252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | relink: |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 4254 | 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] | 4255 | tg3_phy_copper_begin(tp); |
| 4256 | |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4257 | tg3_readphy(tp, MII_BMSR, &bmsr); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 4258 | if ((!tg3_readphy(tp, MII_BMSR, &bmsr) && (bmsr & BMSR_LSTATUS)) || |
| 4259 | (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | current_link_up = 1; |
| 4261 | } |
| 4262 | |
| 4263 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 4264 | if (current_link_up == 1) { |
| 4265 | if (tp->link_config.active_speed == SPEED_100 || |
| 4266 | tp->link_config.active_speed == SPEED_10) |
| 4267 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4268 | else |
| 4269 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4270 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 4271 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4272 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4274 | |
| 4275 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 4276 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 4277 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 4278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4280 | if (current_link_up == 1 && |
| 4281 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4283 | else |
| 4284 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | /* ??? Without this setting Netgear GA302T PHY does not |
| 4288 | * ??? send/receive packets... |
| 4289 | */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4290 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
| 4292 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
| 4293 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 4294 | udelay(80); |
| 4295 | } |
| 4296 | |
| 4297 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4298 | udelay(40); |
| 4299 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4300 | tg3_phy_eee_adjust(tp, current_link_up); |
| 4301 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4302 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | /* Polled via timer. */ |
| 4304 | tw32_f(MAC_EVENT, 0); |
| 4305 | } else { |
| 4306 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4307 | } |
| 4308 | udelay(40); |
| 4309 | |
| 4310 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && |
| 4311 | current_link_up == 1 && |
| 4312 | tp->link_config.active_speed == SPEED_1000 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4313 | (tg3_flag(tp, PCIX_MODE) || tg3_flag(tp, PCI_HIGH_SPEED))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | udelay(120); |
| 4315 | tw32_f(MAC_STATUS, |
| 4316 | (MAC_STATUS_SYNC_CHANGED | |
| 4317 | MAC_STATUS_CFG_CHANGED)); |
| 4318 | udelay(40); |
| 4319 | tg3_write_mem(tp, |
| 4320 | NIC_SRAM_FIRMWARE_MBOX, |
| 4321 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); |
| 4322 | } |
| 4323 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4324 | /* Prevent send BD corruption. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4325 | if (tg3_flag(tp, CLKREQ_BUG)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4326 | u16 oldlnkctl, newlnkctl; |
| 4327 | |
| 4328 | pci_read_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 4329 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4330 | &oldlnkctl); |
| 4331 | if (tp->link_config.active_speed == SPEED_100 || |
| 4332 | tp->link_config.active_speed == SPEED_10) |
| 4333 | newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN; |
| 4334 | else |
| 4335 | newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN; |
| 4336 | if (newlnkctl != oldlnkctl) |
| 4337 | pci_write_config_word(tp->pdev, |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 4338 | pci_pcie_cap(tp->pdev) + |
| 4339 | PCI_EXP_LNKCTL, newlnkctl); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4340 | } |
| 4341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 4343 | if (current_link_up) |
| 4344 | netif_carrier_on(tp->dev); |
| 4345 | else |
| 4346 | netif_carrier_off(tp->dev); |
| 4347 | tg3_link_report(tp); |
| 4348 | } |
| 4349 | |
| 4350 | return 0; |
| 4351 | } |
| 4352 | |
| 4353 | struct tg3_fiber_aneginfo { |
| 4354 | int state; |
| 4355 | #define ANEG_STATE_UNKNOWN 0 |
| 4356 | #define ANEG_STATE_AN_ENABLE 1 |
| 4357 | #define ANEG_STATE_RESTART_INIT 2 |
| 4358 | #define ANEG_STATE_RESTART 3 |
| 4359 | #define ANEG_STATE_DISABLE_LINK_OK 4 |
| 4360 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 |
| 4361 | #define ANEG_STATE_ABILITY_DETECT 6 |
| 4362 | #define ANEG_STATE_ACK_DETECT_INIT 7 |
| 4363 | #define ANEG_STATE_ACK_DETECT 8 |
| 4364 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 |
| 4365 | #define ANEG_STATE_COMPLETE_ACK 10 |
| 4366 | #define ANEG_STATE_IDLE_DETECT_INIT 11 |
| 4367 | #define ANEG_STATE_IDLE_DETECT 12 |
| 4368 | #define ANEG_STATE_LINK_OK 13 |
| 4369 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 |
| 4370 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 |
| 4371 | |
| 4372 | u32 flags; |
| 4373 | #define MR_AN_ENABLE 0x00000001 |
| 4374 | #define MR_RESTART_AN 0x00000002 |
| 4375 | #define MR_AN_COMPLETE 0x00000004 |
| 4376 | #define MR_PAGE_RX 0x00000008 |
| 4377 | #define MR_NP_LOADED 0x00000010 |
| 4378 | #define MR_TOGGLE_TX 0x00000020 |
| 4379 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 |
| 4380 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 |
| 4381 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 |
| 4382 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 |
| 4383 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 |
| 4384 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 |
| 4385 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 |
| 4386 | #define MR_TOGGLE_RX 0x00002000 |
| 4387 | #define MR_NP_RX 0x00004000 |
| 4388 | |
| 4389 | #define MR_LINK_OK 0x80000000 |
| 4390 | |
| 4391 | unsigned long link_time, cur_time; |
| 4392 | |
| 4393 | u32 ability_match_cfg; |
| 4394 | int ability_match_count; |
| 4395 | |
| 4396 | char ability_match, idle_match, ack_match; |
| 4397 | |
| 4398 | u32 txconfig, rxconfig; |
| 4399 | #define ANEG_CFG_NP 0x00000080 |
| 4400 | #define ANEG_CFG_ACK 0x00000040 |
| 4401 | #define ANEG_CFG_RF2 0x00000020 |
| 4402 | #define ANEG_CFG_RF1 0x00000010 |
| 4403 | #define ANEG_CFG_PS2 0x00000001 |
| 4404 | #define ANEG_CFG_PS1 0x00008000 |
| 4405 | #define ANEG_CFG_HD 0x00004000 |
| 4406 | #define ANEG_CFG_FD 0x00002000 |
| 4407 | #define ANEG_CFG_INVAL 0x00001f06 |
| 4408 | |
| 4409 | }; |
| 4410 | #define ANEG_OK 0 |
| 4411 | #define ANEG_DONE 1 |
| 4412 | #define ANEG_TIMER_ENAB 2 |
| 4413 | #define ANEG_FAILED -1 |
| 4414 | |
| 4415 | #define ANEG_STATE_SETTLE_TIME 10000 |
| 4416 | |
| 4417 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, |
| 4418 | struct tg3_fiber_aneginfo *ap) |
| 4419 | { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4420 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | unsigned long delta; |
| 4422 | u32 rx_cfg_reg; |
| 4423 | int ret; |
| 4424 | |
| 4425 | if (ap->state == ANEG_STATE_UNKNOWN) { |
| 4426 | ap->rxconfig = 0; |
| 4427 | ap->link_time = 0; |
| 4428 | ap->cur_time = 0; |
| 4429 | ap->ability_match_cfg = 0; |
| 4430 | ap->ability_match_count = 0; |
| 4431 | ap->ability_match = 0; |
| 4432 | ap->idle_match = 0; |
| 4433 | ap->ack_match = 0; |
| 4434 | } |
| 4435 | ap->cur_time++; |
| 4436 | |
| 4437 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { |
| 4438 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); |
| 4439 | |
| 4440 | if (rx_cfg_reg != ap->ability_match_cfg) { |
| 4441 | ap->ability_match_cfg = rx_cfg_reg; |
| 4442 | ap->ability_match = 0; |
| 4443 | ap->ability_match_count = 0; |
| 4444 | } else { |
| 4445 | if (++ap->ability_match_count > 1) { |
| 4446 | ap->ability_match = 1; |
| 4447 | ap->ability_match_cfg = rx_cfg_reg; |
| 4448 | } |
| 4449 | } |
| 4450 | if (rx_cfg_reg & ANEG_CFG_ACK) |
| 4451 | ap->ack_match = 1; |
| 4452 | else |
| 4453 | ap->ack_match = 0; |
| 4454 | |
| 4455 | ap->idle_match = 0; |
| 4456 | } else { |
| 4457 | ap->idle_match = 1; |
| 4458 | ap->ability_match_cfg = 0; |
| 4459 | ap->ability_match_count = 0; |
| 4460 | ap->ability_match = 0; |
| 4461 | ap->ack_match = 0; |
| 4462 | |
| 4463 | rx_cfg_reg = 0; |
| 4464 | } |
| 4465 | |
| 4466 | ap->rxconfig = rx_cfg_reg; |
| 4467 | ret = ANEG_OK; |
| 4468 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 4469 | switch (ap->state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | case ANEG_STATE_UNKNOWN: |
| 4471 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) |
| 4472 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4473 | |
| 4474 | /* fallthru */ |
| 4475 | case ANEG_STATE_AN_ENABLE: |
| 4476 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); |
| 4477 | if (ap->flags & MR_AN_ENABLE) { |
| 4478 | ap->link_time = 0; |
| 4479 | ap->cur_time = 0; |
| 4480 | ap->ability_match_cfg = 0; |
| 4481 | ap->ability_match_count = 0; |
| 4482 | ap->ability_match = 0; |
| 4483 | ap->idle_match = 0; |
| 4484 | ap->ack_match = 0; |
| 4485 | |
| 4486 | ap->state = ANEG_STATE_RESTART_INIT; |
| 4487 | } else { |
| 4488 | ap->state = ANEG_STATE_DISABLE_LINK_OK; |
| 4489 | } |
| 4490 | break; |
| 4491 | |
| 4492 | case ANEG_STATE_RESTART_INIT: |
| 4493 | ap->link_time = ap->cur_time; |
| 4494 | ap->flags &= ~(MR_NP_LOADED); |
| 4495 | ap->txconfig = 0; |
| 4496 | tw32(MAC_TX_AUTO_NEG, 0); |
| 4497 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4498 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4499 | udelay(40); |
| 4500 | |
| 4501 | ret = ANEG_TIMER_ENAB; |
| 4502 | ap->state = ANEG_STATE_RESTART; |
| 4503 | |
| 4504 | /* fallthru */ |
| 4505 | case ANEG_STATE_RESTART: |
| 4506 | delta = ap->cur_time - ap->link_time; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4507 | if (delta > ANEG_STATE_SETTLE_TIME) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4509 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | ret = ANEG_TIMER_ENAB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | break; |
| 4512 | |
| 4513 | case ANEG_STATE_DISABLE_LINK_OK: |
| 4514 | ret = ANEG_DONE; |
| 4515 | break; |
| 4516 | |
| 4517 | case ANEG_STATE_ABILITY_DETECT_INIT: |
| 4518 | ap->flags &= ~(MR_TOGGLE_TX); |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4519 | ap->txconfig = ANEG_CFG_FD; |
| 4520 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 4521 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 4522 | ap->txconfig |= ANEG_CFG_PS1; |
| 4523 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 4524 | ap->txconfig |= ANEG_CFG_PS2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 4526 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4527 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4528 | udelay(40); |
| 4529 | |
| 4530 | ap->state = ANEG_STATE_ABILITY_DETECT; |
| 4531 | break; |
| 4532 | |
| 4533 | case ANEG_STATE_ABILITY_DETECT: |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4534 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | break; |
| 4537 | |
| 4538 | case ANEG_STATE_ACK_DETECT_INIT: |
| 4539 | ap->txconfig |= ANEG_CFG_ACK; |
| 4540 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 4541 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4542 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4543 | udelay(40); |
| 4544 | |
| 4545 | ap->state = ANEG_STATE_ACK_DETECT; |
| 4546 | |
| 4547 | /* fallthru */ |
| 4548 | case ANEG_STATE_ACK_DETECT: |
| 4549 | if (ap->ack_match != 0) { |
| 4550 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == |
| 4551 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { |
| 4552 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; |
| 4553 | } else { |
| 4554 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4555 | } |
| 4556 | } else if (ap->ability_match != 0 && |
| 4557 | ap->rxconfig == 0) { |
| 4558 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4559 | } |
| 4560 | break; |
| 4561 | |
| 4562 | case ANEG_STATE_COMPLETE_ACK_INIT: |
| 4563 | if (ap->rxconfig & ANEG_CFG_INVAL) { |
| 4564 | ret = ANEG_FAILED; |
| 4565 | break; |
| 4566 | } |
| 4567 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | |
| 4568 | MR_LP_ADV_HALF_DUPLEX | |
| 4569 | MR_LP_ADV_SYM_PAUSE | |
| 4570 | MR_LP_ADV_ASYM_PAUSE | |
| 4571 | MR_LP_ADV_REMOTE_FAULT1 | |
| 4572 | MR_LP_ADV_REMOTE_FAULT2 | |
| 4573 | MR_LP_ADV_NEXT_PAGE | |
| 4574 | MR_TOGGLE_RX | |
| 4575 | MR_NP_RX); |
| 4576 | if (ap->rxconfig & ANEG_CFG_FD) |
| 4577 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; |
| 4578 | if (ap->rxconfig & ANEG_CFG_HD) |
| 4579 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; |
| 4580 | if (ap->rxconfig & ANEG_CFG_PS1) |
| 4581 | ap->flags |= MR_LP_ADV_SYM_PAUSE; |
| 4582 | if (ap->rxconfig & ANEG_CFG_PS2) |
| 4583 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; |
| 4584 | if (ap->rxconfig & ANEG_CFG_RF1) |
| 4585 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; |
| 4586 | if (ap->rxconfig & ANEG_CFG_RF2) |
| 4587 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; |
| 4588 | if (ap->rxconfig & ANEG_CFG_NP) |
| 4589 | ap->flags |= MR_LP_ADV_NEXT_PAGE; |
| 4590 | |
| 4591 | ap->link_time = ap->cur_time; |
| 4592 | |
| 4593 | ap->flags ^= (MR_TOGGLE_TX); |
| 4594 | if (ap->rxconfig & 0x0008) |
| 4595 | ap->flags |= MR_TOGGLE_RX; |
| 4596 | if (ap->rxconfig & ANEG_CFG_NP) |
| 4597 | ap->flags |= MR_NP_RX; |
| 4598 | ap->flags |= MR_PAGE_RX; |
| 4599 | |
| 4600 | ap->state = ANEG_STATE_COMPLETE_ACK; |
| 4601 | ret = ANEG_TIMER_ENAB; |
| 4602 | break; |
| 4603 | |
| 4604 | case ANEG_STATE_COMPLETE_ACK: |
| 4605 | if (ap->ability_match != 0 && |
| 4606 | ap->rxconfig == 0) { |
| 4607 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4608 | break; |
| 4609 | } |
| 4610 | delta = ap->cur_time - ap->link_time; |
| 4611 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 4612 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { |
| 4613 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 4614 | } else { |
| 4615 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && |
| 4616 | !(ap->flags & MR_NP_RX)) { |
| 4617 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 4618 | } else { |
| 4619 | ret = ANEG_FAILED; |
| 4620 | } |
| 4621 | } |
| 4622 | } |
| 4623 | break; |
| 4624 | |
| 4625 | case ANEG_STATE_IDLE_DETECT_INIT: |
| 4626 | ap->link_time = ap->cur_time; |
| 4627 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 4628 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4629 | udelay(40); |
| 4630 | |
| 4631 | ap->state = ANEG_STATE_IDLE_DETECT; |
| 4632 | ret = ANEG_TIMER_ENAB; |
| 4633 | break; |
| 4634 | |
| 4635 | case ANEG_STATE_IDLE_DETECT: |
| 4636 | if (ap->ability_match != 0 && |
| 4637 | ap->rxconfig == 0) { |
| 4638 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4639 | break; |
| 4640 | } |
| 4641 | delta = ap->cur_time - ap->link_time; |
| 4642 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 4643 | /* XXX another gem from the Broadcom driver :( */ |
| 4644 | ap->state = ANEG_STATE_LINK_OK; |
| 4645 | } |
| 4646 | break; |
| 4647 | |
| 4648 | case ANEG_STATE_LINK_OK: |
| 4649 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); |
| 4650 | ret = ANEG_DONE; |
| 4651 | break; |
| 4652 | |
| 4653 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: |
| 4654 | /* ??? unimplemented */ |
| 4655 | break; |
| 4656 | |
| 4657 | case ANEG_STATE_NEXT_PAGE_WAIT: |
| 4658 | /* ??? unimplemented */ |
| 4659 | break; |
| 4660 | |
| 4661 | default: |
| 4662 | ret = ANEG_FAILED; |
| 4663 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4664 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | |
| 4666 | return ret; |
| 4667 | } |
| 4668 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4669 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | { |
| 4671 | int res = 0; |
| 4672 | struct tg3_fiber_aneginfo aninfo; |
| 4673 | int status = ANEG_FAILED; |
| 4674 | unsigned int tick; |
| 4675 | u32 tmp; |
| 4676 | |
| 4677 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 4678 | |
| 4679 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
| 4680 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); |
| 4681 | udelay(40); |
| 4682 | |
| 4683 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); |
| 4684 | udelay(40); |
| 4685 | |
| 4686 | memset(&aninfo, 0, sizeof(aninfo)); |
| 4687 | aninfo.flags |= MR_AN_ENABLE; |
| 4688 | aninfo.state = ANEG_STATE_UNKNOWN; |
| 4689 | aninfo.cur_time = 0; |
| 4690 | tick = 0; |
| 4691 | while (++tick < 195000) { |
| 4692 | status = tg3_fiber_aneg_smachine(tp, &aninfo); |
| 4693 | if (status == ANEG_DONE || status == ANEG_FAILED) |
| 4694 | break; |
| 4695 | |
| 4696 | udelay(1); |
| 4697 | } |
| 4698 | |
| 4699 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 4700 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4701 | udelay(40); |
| 4702 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4703 | *txflags = aninfo.txconfig; |
| 4704 | *rxflags = aninfo.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | |
| 4706 | if (status == ANEG_DONE && |
| 4707 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | |
| 4708 | MR_LP_ADV_FULL_DUPLEX))) |
| 4709 | res = 1; |
| 4710 | |
| 4711 | return res; |
| 4712 | } |
| 4713 | |
| 4714 | static void tg3_init_bcm8002(struct tg3 *tp) |
| 4715 | { |
| 4716 | u32 mac_status = tr32(MAC_STATUS); |
| 4717 | int i; |
| 4718 | |
| 4719 | /* Reset when initting first time or we have a link. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4720 | if (tg3_flag(tp, INIT_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 4722 | return; |
| 4723 | |
| 4724 | /* Set PLL lock range. */ |
| 4725 | tg3_writephy(tp, 0x16, 0x8007); |
| 4726 | |
| 4727 | /* SW reset */ |
| 4728 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); |
| 4729 | |
| 4730 | /* Wait for reset to complete. */ |
| 4731 | /* XXX schedule_timeout() ... */ |
| 4732 | for (i = 0; i < 500; i++) |
| 4733 | udelay(10); |
| 4734 | |
| 4735 | /* Config mode; select PMA/Ch 1 regs. */ |
| 4736 | tg3_writephy(tp, 0x10, 0x8411); |
| 4737 | |
| 4738 | /* Enable auto-lock and comdet, select txclk for tx. */ |
| 4739 | tg3_writephy(tp, 0x11, 0x0a10); |
| 4740 | |
| 4741 | tg3_writephy(tp, 0x18, 0x00a0); |
| 4742 | tg3_writephy(tp, 0x16, 0x41ff); |
| 4743 | |
| 4744 | /* Assert and deassert POR. */ |
| 4745 | tg3_writephy(tp, 0x13, 0x0400); |
| 4746 | udelay(40); |
| 4747 | tg3_writephy(tp, 0x13, 0x0000); |
| 4748 | |
| 4749 | tg3_writephy(tp, 0x11, 0x0a50); |
| 4750 | udelay(40); |
| 4751 | tg3_writephy(tp, 0x11, 0x0a10); |
| 4752 | |
| 4753 | /* Wait for signal to stabilize */ |
| 4754 | /* XXX schedule_timeout() ... */ |
| 4755 | for (i = 0; i < 15000; i++) |
| 4756 | udelay(10); |
| 4757 | |
| 4758 | /* Deselect the channel register so we can read the PHYID |
| 4759 | * later. |
| 4760 | */ |
| 4761 | tg3_writephy(tp, 0x10, 0x8011); |
| 4762 | } |
| 4763 | |
| 4764 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
| 4765 | { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4766 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | u32 sg_dig_ctrl, sg_dig_status; |
| 4768 | u32 serdes_cfg, expected_sg_dig_ctrl; |
| 4769 | int workaround, port_a; |
| 4770 | int current_link_up; |
| 4771 | |
| 4772 | serdes_cfg = 0; |
| 4773 | expected_sg_dig_ctrl = 0; |
| 4774 | workaround = 0; |
| 4775 | port_a = 1; |
| 4776 | current_link_up = 0; |
| 4777 | |
| 4778 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && |
| 4779 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { |
| 4780 | workaround = 1; |
| 4781 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 4782 | port_a = 0; |
| 4783 | |
| 4784 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ |
| 4785 | /* preserve bits 20-23 for voltage regulator */ |
| 4786 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; |
| 4787 | } |
| 4788 | |
| 4789 | sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 4790 | |
| 4791 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4792 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | if (workaround) { |
| 4794 | u32 val = serdes_cfg; |
| 4795 | |
| 4796 | if (port_a) |
| 4797 | val |= 0xc010000; |
| 4798 | else |
| 4799 | val |= 0x4010000; |
| 4800 | tw32_f(MAC_SERDES_CFG, val); |
| 4801 | } |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4802 | |
| 4803 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 | } |
| 4805 | if (mac_status & MAC_STATUS_PCS_SYNCED) { |
| 4806 | tg3_setup_flow_control(tp, 0, 0); |
| 4807 | current_link_up = 1; |
| 4808 | } |
| 4809 | goto out; |
| 4810 | } |
| 4811 | |
| 4812 | /* Want auto-negotiation. */ |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4813 | 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] | 4814 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4815 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 4816 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 4817 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; |
| 4818 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 4819 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | |
| 4821 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4822 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4823 | tp->serdes_counter && |
| 4824 | ((mac_status & (MAC_STATUS_PCS_SYNCED | |
| 4825 | MAC_STATUS_RCVD_CFG)) == |
| 4826 | MAC_STATUS_PCS_SYNCED)) { |
| 4827 | tp->serdes_counter--; |
| 4828 | current_link_up = 1; |
| 4829 | goto out; |
| 4830 | } |
| 4831 | restart_autoneg: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | if (workaround) |
| 4833 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4834 | 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] | 4835 | udelay(5); |
| 4836 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); |
| 4837 | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4838 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4839 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
| 4841 | MAC_STATUS_SIGNAL_DET)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4842 | sg_dig_status = tr32(SG_DIG_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4843 | mac_status = tr32(MAC_STATUS); |
| 4844 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4845 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4847 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4849 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) |
| 4850 | local_adv |= ADVERTISE_1000XPAUSE; |
| 4851 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) |
| 4852 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 4853 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4854 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4855 | remote_adv |= LPA_1000XPAUSE; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4856 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4857 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4859 | tp->link_config.rmt_adv = |
| 4860 | mii_adv_to_ethtool_adv_x(remote_adv); |
| 4861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4863 | current_link_up = 1; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4864 | tp->serdes_counter = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4865 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4866 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4867 | if (tp->serdes_counter) |
| 4868 | tp->serdes_counter--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4869 | else { |
| 4870 | if (workaround) { |
| 4871 | u32 val = serdes_cfg; |
| 4872 | |
| 4873 | if (port_a) |
| 4874 | val |= 0xc010000; |
| 4875 | else |
| 4876 | val |= 0x4010000; |
| 4877 | |
| 4878 | tw32_f(MAC_SERDES_CFG, val); |
| 4879 | } |
| 4880 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4881 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | udelay(40); |
| 4883 | |
| 4884 | /* Link parallel detection - link is up */ |
| 4885 | /* only if we have PCS_SYNC and not */ |
| 4886 | /* receiving config code words */ |
| 4887 | mac_status = tr32(MAC_STATUS); |
| 4888 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && |
| 4889 | !(mac_status & MAC_STATUS_RCVD_CFG)) { |
| 4890 | tg3_setup_flow_control(tp, 0, 0); |
| 4891 | current_link_up = 1; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4892 | tp->phy_flags |= |
| 4893 | TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4894 | tp->serdes_counter = |
| 4895 | SERDES_PARALLEL_DET_TIMEOUT; |
| 4896 | } else |
| 4897 | goto restart_autoneg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | } |
| 4899 | } |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4900 | } else { |
| 4901 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4902 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4903 | } |
| 4904 | |
| 4905 | out: |
| 4906 | return current_link_up; |
| 4907 | } |
| 4908 | |
| 4909 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
| 4910 | { |
| 4911 | int current_link_up = 0; |
| 4912 | |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 4913 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | |
| 4916 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4917 | u32 txflags, rxflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 4919 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4920 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
| 4921 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4923 | if (txflags & ANEG_CFG_PS1) |
| 4924 | local_adv |= ADVERTISE_1000XPAUSE; |
| 4925 | if (txflags & ANEG_CFG_PS2) |
| 4926 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 4927 | |
| 4928 | if (rxflags & MR_LP_ADV_SYM_PAUSE) |
| 4929 | remote_adv |= LPA_1000XPAUSE; |
| 4930 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) |
| 4931 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4933 | tp->link_config.rmt_adv = |
| 4934 | mii_adv_to_ethtool_adv_x(remote_adv); |
| 4935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4936 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | current_link_up = 1; |
| 4939 | } |
| 4940 | for (i = 0; i < 30; i++) { |
| 4941 | udelay(20); |
| 4942 | tw32_f(MAC_STATUS, |
| 4943 | (MAC_STATUS_SYNC_CHANGED | |
| 4944 | MAC_STATUS_CFG_CHANGED)); |
| 4945 | udelay(40); |
| 4946 | if ((tr32(MAC_STATUS) & |
| 4947 | (MAC_STATUS_SYNC_CHANGED | |
| 4948 | MAC_STATUS_CFG_CHANGED)) == 0) |
| 4949 | break; |
| 4950 | } |
| 4951 | |
| 4952 | mac_status = tr32(MAC_STATUS); |
| 4953 | if (current_link_up == 0 && |
| 4954 | (mac_status & MAC_STATUS_PCS_SYNCED) && |
| 4955 | !(mac_status & MAC_STATUS_RCVD_CFG)) |
| 4956 | current_link_up = 1; |
| 4957 | } else { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4958 | tg3_setup_flow_control(tp, 0, 0); |
| 4959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | /* Forcing 1000FD link up. */ |
| 4961 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | |
| 4963 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); |
| 4964 | udelay(40); |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4965 | |
| 4966 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4967 | udelay(40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4968 | } |
| 4969 | |
| 4970 | out: |
| 4971 | return current_link_up; |
| 4972 | } |
| 4973 | |
| 4974 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) |
| 4975 | { |
| 4976 | u32 orig_pause_cfg; |
| 4977 | u16 orig_active_speed; |
| 4978 | u8 orig_active_duplex; |
| 4979 | u32 mac_status; |
| 4980 | int current_link_up; |
| 4981 | int i; |
| 4982 | |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 4983 | orig_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4984 | orig_active_speed = tp->link_config.active_speed; |
| 4985 | orig_active_duplex = tp->link_config.active_duplex; |
| 4986 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4987 | if (!tg3_flag(tp, HW_AUTONEG) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4988 | netif_carrier_ok(tp->dev) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4989 | tg3_flag(tp, INIT_COMPLETE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | mac_status = tr32(MAC_STATUS); |
| 4991 | mac_status &= (MAC_STATUS_PCS_SYNCED | |
| 4992 | MAC_STATUS_SIGNAL_DET | |
| 4993 | MAC_STATUS_CFG_CHANGED | |
| 4994 | MAC_STATUS_RCVD_CFG); |
| 4995 | if (mac_status == (MAC_STATUS_PCS_SYNCED | |
| 4996 | MAC_STATUS_SIGNAL_DET)) { |
| 4997 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 4998 | MAC_STATUS_CFG_CHANGED)); |
| 4999 | return 0; |
| 5000 | } |
| 5001 | } |
| 5002 | |
| 5003 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 5004 | |
| 5005 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 5006 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 5007 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5008 | udelay(40); |
| 5009 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 5010 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | tg3_init_bcm8002(tp); |
| 5012 | |
| 5013 | /* Enable link change event even when serdes polling. */ |
| 5014 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5015 | udelay(40); |
| 5016 | |
| 5017 | current_link_up = 0; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5018 | tp->link_config.rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | mac_status = tr32(MAC_STATUS); |
| 5020 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5021 | if (tg3_flag(tp, HW_AUTONEG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
| 5023 | else |
| 5024 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); |
| 5025 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5026 | tp->napi[0].hw_status->status = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5027 | (SD_STATUS_UPDATED | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5028 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | |
| 5030 | for (i = 0; i < 100; i++) { |
| 5031 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5032 | MAC_STATUS_CFG_CHANGED)); |
| 5033 | udelay(5); |
| 5034 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5035 | MAC_STATUS_CFG_CHANGED | |
| 5036 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | break; |
| 5038 | } |
| 5039 | |
| 5040 | mac_status = tr32(MAC_STATUS); |
| 5041 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { |
| 5042 | current_link_up = 0; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5043 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 5044 | tp->serdes_counter == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | tw32_f(MAC_MODE, (tp->mac_mode | |
| 5046 | MAC_MODE_SEND_CONFIGS)); |
| 5047 | udelay(1); |
| 5048 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5049 | } |
| 5050 | } |
| 5051 | |
| 5052 | if (current_link_up == 1) { |
| 5053 | tp->link_config.active_speed = SPEED_1000; |
| 5054 | tp->link_config.active_duplex = DUPLEX_FULL; |
| 5055 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5056 | LED_CTRL_LNKLED_OVERRIDE | |
| 5057 | LED_CTRL_1000MBPS_ON)); |
| 5058 | } else { |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 5059 | tp->link_config.active_speed = SPEED_UNKNOWN; |
| 5060 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5061 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5062 | LED_CTRL_LNKLED_OVERRIDE | |
| 5063 | LED_CTRL_TRAFFIC_OVERRIDE)); |
| 5064 | } |
| 5065 | |
| 5066 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 5067 | if (current_link_up) |
| 5068 | netif_carrier_on(tp->dev); |
| 5069 | else |
| 5070 | netif_carrier_off(tp->dev); |
| 5071 | tg3_link_report(tp); |
| 5072 | } else { |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 5073 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | if (orig_pause_cfg != now_pause_cfg || |
| 5075 | orig_active_speed != tp->link_config.active_speed || |
| 5076 | orig_active_duplex != tp->link_config.active_duplex) |
| 5077 | tg3_link_report(tp); |
| 5078 | } |
| 5079 | |
| 5080 | return 0; |
| 5081 | } |
| 5082 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5083 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
| 5084 | { |
| 5085 | int current_link_up, err = 0; |
| 5086 | u32 bmsr, bmcr; |
| 5087 | u16 current_speed; |
| 5088 | u8 current_duplex; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5089 | u32 local_adv, remote_adv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5090 | |
| 5091 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 5092 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5093 | udelay(40); |
| 5094 | |
| 5095 | tw32(MAC_EVENT, 0); |
| 5096 | |
| 5097 | tw32_f(MAC_STATUS, |
| 5098 | (MAC_STATUS_SYNC_CHANGED | |
| 5099 | MAC_STATUS_CFG_CHANGED | |
| 5100 | MAC_STATUS_MI_COMPLETION | |
| 5101 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 5102 | udelay(40); |
| 5103 | |
| 5104 | if (force_reset) |
| 5105 | tg3_phy_reset(tp); |
| 5106 | |
| 5107 | current_link_up = 0; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 5108 | current_speed = SPEED_UNKNOWN; |
| 5109 | current_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5110 | tp->link_config.rmt_adv = 0; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5111 | |
| 5112 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5113 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 5114 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 5115 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5116 | bmsr |= BMSR_LSTATUS; |
| 5117 | else |
| 5118 | bmsr &= ~BMSR_LSTATUS; |
| 5119 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5120 | |
| 5121 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5122 | |
| 5123 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5124 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5125 | /* do nothing, just check for link up at the end */ |
| 5126 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5127 | u32 adv, newadv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5128 | |
| 5129 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5130 | newadv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
| 5131 | ADVERTISE_1000XPAUSE | |
| 5132 | ADVERTISE_1000XPSE_ASYM | |
| 5133 | ADVERTISE_SLCT); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5134 | |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5135 | newadv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
Matt Carlson | 37f0702 | 2011-11-17 14:30:55 +0000 | [diff] [blame] | 5136 | newadv |= ethtool_adv_to_mii_adv_x(tp->link_config.advertising); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5137 | |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5138 | if ((newadv != adv) || !(bmcr & BMCR_ANENABLE)) { |
| 5139 | tg3_writephy(tp, MII_ADVERTISE, newadv); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5140 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 5141 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 5142 | |
| 5143 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5144 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5145 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5146 | |
| 5147 | return err; |
| 5148 | } |
| 5149 | } else { |
| 5150 | u32 new_bmcr; |
| 5151 | |
| 5152 | bmcr &= ~BMCR_SPEED1000; |
| 5153 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); |
| 5154 | |
| 5155 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 5156 | new_bmcr |= BMCR_FULLDPLX; |
| 5157 | |
| 5158 | if (new_bmcr != bmcr) { |
| 5159 | /* BMCR_SPEED1000 is a reserved bit that needs |
| 5160 | * to be set on write. |
| 5161 | */ |
| 5162 | new_bmcr |= BMCR_SPEED1000; |
| 5163 | |
| 5164 | /* Force a linkdown */ |
| 5165 | if (netif_carrier_ok(tp->dev)) { |
| 5166 | u32 adv; |
| 5167 | |
| 5168 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 5169 | adv &= ~(ADVERTISE_1000XFULL | |
| 5170 | ADVERTISE_1000XHALF | |
| 5171 | ADVERTISE_SLCT); |
| 5172 | tg3_writephy(tp, MII_ADVERTISE, adv); |
| 5173 | tg3_writephy(tp, MII_BMCR, bmcr | |
| 5174 | BMCR_ANRESTART | |
| 5175 | BMCR_ANENABLE); |
| 5176 | udelay(10); |
| 5177 | netif_carrier_off(tp->dev); |
| 5178 | } |
| 5179 | tg3_writephy(tp, MII_BMCR, new_bmcr); |
| 5180 | bmcr = new_bmcr; |
| 5181 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5182 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 5183 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 5184 | ASIC_REV_5714) { |
| 5185 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5186 | bmsr |= BMSR_LSTATUS; |
| 5187 | else |
| 5188 | bmsr &= ~BMSR_LSTATUS; |
| 5189 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5190 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5191 | } |
| 5192 | } |
| 5193 | |
| 5194 | if (bmsr & BMSR_LSTATUS) { |
| 5195 | current_speed = SPEED_1000; |
| 5196 | current_link_up = 1; |
| 5197 | if (bmcr & BMCR_FULLDPLX) |
| 5198 | current_duplex = DUPLEX_FULL; |
| 5199 | else |
| 5200 | current_duplex = DUPLEX_HALF; |
| 5201 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5202 | local_adv = 0; |
| 5203 | remote_adv = 0; |
| 5204 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5205 | if (bmcr & BMCR_ANENABLE) { |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5206 | u32 common; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5207 | |
| 5208 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); |
| 5209 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); |
| 5210 | common = local_adv & remote_adv; |
| 5211 | if (common & (ADVERTISE_1000XHALF | |
| 5212 | ADVERTISE_1000XFULL)) { |
| 5213 | if (common & ADVERTISE_1000XFULL) |
| 5214 | current_duplex = DUPLEX_FULL; |
| 5215 | else |
| 5216 | current_duplex = DUPLEX_HALF; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5217 | |
| 5218 | tp->link_config.rmt_adv = |
| 5219 | mii_adv_to_ethtool_adv_x(remote_adv); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5220 | } else if (!tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 5221 | /* Link is up via parallel detect */ |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5222 | } else { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5223 | current_link_up = 0; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5224 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5225 | } |
| 5226 | } |
| 5227 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5228 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
| 5229 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5230 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5231 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 5232 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 5233 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 5234 | |
| 5235 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5236 | udelay(40); |
| 5237 | |
| 5238 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5239 | |
| 5240 | tp->link_config.active_speed = current_speed; |
| 5241 | tp->link_config.active_duplex = current_duplex; |
| 5242 | |
| 5243 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 5244 | if (current_link_up) |
| 5245 | netif_carrier_on(tp->dev); |
| 5246 | else { |
| 5247 | netif_carrier_off(tp->dev); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5248 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5249 | } |
| 5250 | tg3_link_report(tp); |
| 5251 | } |
| 5252 | return err; |
| 5253 | } |
| 5254 | |
| 5255 | static void tg3_serdes_parallel_detect(struct tg3 *tp) |
| 5256 | { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5257 | if (tp->serdes_counter) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5258 | /* Give autoneg time to complete. */ |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5259 | tp->serdes_counter--; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5260 | return; |
| 5261 | } |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5262 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5263 | if (!netif_carrier_ok(tp->dev) && |
| 5264 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { |
| 5265 | u32 bmcr; |
| 5266 | |
| 5267 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5268 | if (bmcr & BMCR_ANENABLE) { |
| 5269 | u32 phy1, phy2; |
| 5270 | |
| 5271 | /* Select shadow register 0x1f */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5272 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
| 5273 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5274 | |
| 5275 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5276 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 5277 | MII_TG3_DSP_EXP1_INT_STAT); |
| 5278 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 5279 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5280 | |
| 5281 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { |
| 5282 | /* We have signal detect and not receiving |
| 5283 | * config code words, link is up by parallel |
| 5284 | * detection. |
| 5285 | */ |
| 5286 | |
| 5287 | bmcr &= ~BMCR_ANENABLE; |
| 5288 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; |
| 5289 | tg3_writephy(tp, MII_BMCR, bmcr); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5290 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5291 | } |
| 5292 | } |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5293 | } else if (netif_carrier_ok(tp->dev) && |
| 5294 | (tp->link_config.autoneg == AUTONEG_ENABLE) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5295 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5296 | u32 phy2; |
| 5297 | |
| 5298 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5299 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 5300 | MII_TG3_DSP_EXP1_INT_STAT); |
| 5301 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5302 | if (phy2 & 0x20) { |
| 5303 | u32 bmcr; |
| 5304 | |
| 5305 | /* Config code words received, turn on autoneg. */ |
| 5306 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5307 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); |
| 5308 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5309 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5310 | |
| 5311 | } |
| 5312 | } |
| 5313 | } |
| 5314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5315 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
| 5316 | { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5317 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | int err; |
| 5319 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5320 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | err = tg3_setup_fiber_phy(tp, force_reset); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5322 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5323 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5324 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | err = tg3_setup_copper_phy(tp, force_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 5327 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5328 | u32 scale; |
Matt Carlson | aa6c91f | 2007-11-12 21:18:04 -0800 | [diff] [blame] | 5329 | |
| 5330 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; |
| 5331 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) |
| 5332 | scale = 65; |
| 5333 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) |
| 5334 | scale = 6; |
| 5335 | else |
| 5336 | scale = 12; |
| 5337 | |
| 5338 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; |
| 5339 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 5340 | tw32(GRC_MISC_CFG, val); |
| 5341 | } |
| 5342 | |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5343 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 5344 | (6 << TX_LENGTHS_IPG_SHIFT); |
| 5345 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 5346 | val |= tr32(MAC_TX_LENGTHS) & |
| 5347 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 5348 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 5349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5350 | if (tp->link_config.active_speed == SPEED_1000 && |
| 5351 | tp->link_config.active_duplex == DUPLEX_HALF) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5352 | tw32(MAC_TX_LENGTHS, val | |
| 5353 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5354 | else |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5355 | tw32(MAC_TX_LENGTHS, val | |
| 5356 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5358 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5359 | if (netif_carrier_ok(tp->dev)) { |
| 5360 | tw32(HOSTCC_STAT_COAL_TICKS, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 5361 | tp->coal.stats_block_coalesce_usecs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5362 | } else { |
| 5363 | tw32(HOSTCC_STAT_COAL_TICKS, 0); |
| 5364 | } |
| 5365 | } |
| 5366 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5367 | if (tg3_flag(tp, ASPM_WORKAROUND)) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5368 | val = tr32(PCIE_PWR_MGMT_THRESH); |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 5369 | if (!netif_carrier_ok(tp->dev)) |
| 5370 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
| 5371 | tp->pwrmgmt_thresh; |
| 5372 | else |
| 5373 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 5374 | tw32(PCIE_PWR_MGMT_THRESH, val); |
| 5375 | } |
| 5376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5377 | return err; |
| 5378 | } |
| 5379 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 5380 | static inline int tg3_irq_sync(struct tg3 *tp) |
| 5381 | { |
| 5382 | return tp->irq_sync; |
| 5383 | } |
| 5384 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5385 | static inline void tg3_rd32_loop(struct tg3 *tp, u32 *dst, u32 off, u32 len) |
| 5386 | { |
| 5387 | int i; |
| 5388 | |
| 5389 | dst = (u32 *)((u8 *)dst + off); |
| 5390 | for (i = 0; i < len; i += sizeof(u32)) |
| 5391 | *dst++ = tr32(off + i); |
| 5392 | } |
| 5393 | |
| 5394 | static void tg3_dump_legacy_regs(struct tg3 *tp, u32 *regs) |
| 5395 | { |
| 5396 | tg3_rd32_loop(tp, regs, TG3PCI_VENDOR, 0xb0); |
| 5397 | tg3_rd32_loop(tp, regs, MAILBOX_INTERRUPT_0, 0x200); |
| 5398 | tg3_rd32_loop(tp, regs, MAC_MODE, 0x4f0); |
| 5399 | tg3_rd32_loop(tp, regs, SNDDATAI_MODE, 0xe0); |
| 5400 | tg3_rd32_loop(tp, regs, SNDDATAC_MODE, 0x04); |
| 5401 | tg3_rd32_loop(tp, regs, SNDBDS_MODE, 0x80); |
| 5402 | tg3_rd32_loop(tp, regs, SNDBDI_MODE, 0x48); |
| 5403 | tg3_rd32_loop(tp, regs, SNDBDC_MODE, 0x04); |
| 5404 | tg3_rd32_loop(tp, regs, RCVLPC_MODE, 0x20); |
| 5405 | tg3_rd32_loop(tp, regs, RCVLPC_SELLST_BASE, 0x15c); |
| 5406 | tg3_rd32_loop(tp, regs, RCVDBDI_MODE, 0x0c); |
| 5407 | tg3_rd32_loop(tp, regs, RCVDBDI_JUMBO_BD, 0x3c); |
| 5408 | tg3_rd32_loop(tp, regs, RCVDBDI_BD_PROD_IDX_0, 0x44); |
| 5409 | tg3_rd32_loop(tp, regs, RCVDCC_MODE, 0x04); |
| 5410 | tg3_rd32_loop(tp, regs, RCVBDI_MODE, 0x20); |
| 5411 | tg3_rd32_loop(tp, regs, RCVCC_MODE, 0x14); |
| 5412 | tg3_rd32_loop(tp, regs, RCVLSC_MODE, 0x08); |
| 5413 | tg3_rd32_loop(tp, regs, MBFREE_MODE, 0x08); |
| 5414 | tg3_rd32_loop(tp, regs, HOSTCC_MODE, 0x100); |
| 5415 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5416 | if (tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5417 | tg3_rd32_loop(tp, regs, HOSTCC_RXCOL_TICKS_VEC1, 0x180); |
| 5418 | |
| 5419 | tg3_rd32_loop(tp, regs, MEMARB_MODE, 0x10); |
| 5420 | tg3_rd32_loop(tp, regs, BUFMGR_MODE, 0x58); |
| 5421 | tg3_rd32_loop(tp, regs, RDMAC_MODE, 0x08); |
| 5422 | tg3_rd32_loop(tp, regs, WDMAC_MODE, 0x08); |
| 5423 | tg3_rd32_loop(tp, regs, RX_CPU_MODE, 0x04); |
| 5424 | tg3_rd32_loop(tp, regs, RX_CPU_STATE, 0x04); |
| 5425 | tg3_rd32_loop(tp, regs, RX_CPU_PGMCTR, 0x04); |
| 5426 | tg3_rd32_loop(tp, regs, RX_CPU_HWBKPT, 0x04); |
| 5427 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5428 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5429 | tg3_rd32_loop(tp, regs, TX_CPU_MODE, 0x04); |
| 5430 | tg3_rd32_loop(tp, regs, TX_CPU_STATE, 0x04); |
| 5431 | tg3_rd32_loop(tp, regs, TX_CPU_PGMCTR, 0x04); |
| 5432 | } |
| 5433 | |
| 5434 | tg3_rd32_loop(tp, regs, GRCMBOX_INTERRUPT_0, 0x110); |
| 5435 | tg3_rd32_loop(tp, regs, FTQ_RESET, 0x120); |
| 5436 | tg3_rd32_loop(tp, regs, MSGINT_MODE, 0x0c); |
| 5437 | tg3_rd32_loop(tp, regs, DMAC_MODE, 0x04); |
| 5438 | tg3_rd32_loop(tp, regs, GRC_MODE, 0x4c); |
| 5439 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5440 | if (tg3_flag(tp, NVRAM)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5441 | tg3_rd32_loop(tp, regs, NVRAM_CMD, 0x24); |
| 5442 | } |
| 5443 | |
| 5444 | static void tg3_dump_state(struct tg3 *tp) |
| 5445 | { |
| 5446 | int i; |
| 5447 | u32 *regs; |
| 5448 | |
| 5449 | regs = kzalloc(TG3_REG_BLK_SIZE, GFP_ATOMIC); |
| 5450 | if (!regs) { |
| 5451 | netdev_err(tp->dev, "Failed allocating register dump buffer\n"); |
| 5452 | return; |
| 5453 | } |
| 5454 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5455 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5456 | /* Read up to but not including private PCI registers */ |
| 5457 | for (i = 0; i < TG3_PCIE_TLDLPL_PORT; i += sizeof(u32)) |
| 5458 | regs[i / sizeof(u32)] = tr32(i); |
| 5459 | } else |
| 5460 | tg3_dump_legacy_regs(tp, regs); |
| 5461 | |
| 5462 | for (i = 0; i < TG3_REG_BLK_SIZE / sizeof(u32); i += 4) { |
| 5463 | if (!regs[i + 0] && !regs[i + 1] && |
| 5464 | !regs[i + 2] && !regs[i + 3]) |
| 5465 | continue; |
| 5466 | |
| 5467 | netdev_err(tp->dev, "0x%08x: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", |
| 5468 | i * 4, |
| 5469 | regs[i + 0], regs[i + 1], regs[i + 2], regs[i + 3]); |
| 5470 | } |
| 5471 | |
| 5472 | kfree(regs); |
| 5473 | |
| 5474 | for (i = 0; i < tp->irq_cnt; i++) { |
| 5475 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 5476 | |
| 5477 | /* SW status block */ |
| 5478 | netdev_err(tp->dev, |
| 5479 | "%d: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", |
| 5480 | i, |
| 5481 | tnapi->hw_status->status, |
| 5482 | tnapi->hw_status->status_tag, |
| 5483 | tnapi->hw_status->rx_jumbo_consumer, |
| 5484 | tnapi->hw_status->rx_consumer, |
| 5485 | tnapi->hw_status->rx_mini_consumer, |
| 5486 | tnapi->hw_status->idx[0].rx_producer, |
| 5487 | tnapi->hw_status->idx[0].tx_consumer); |
| 5488 | |
| 5489 | netdev_err(tp->dev, |
| 5490 | "%d: NAPI info [%08x:%08x:(%04x:%04x:%04x):%04x:(%04x:%04x:%04x:%04x)]\n", |
| 5491 | i, |
| 5492 | tnapi->last_tag, tnapi->last_irq_tag, |
| 5493 | tnapi->tx_prod, tnapi->tx_cons, tnapi->tx_pending, |
| 5494 | tnapi->rx_rcb_ptr, |
| 5495 | tnapi->prodring.rx_std_prod_idx, |
| 5496 | tnapi->prodring.rx_std_cons_idx, |
| 5497 | tnapi->prodring.rx_jmb_prod_idx, |
| 5498 | tnapi->prodring.rx_jmb_cons_idx); |
| 5499 | } |
| 5500 | } |
| 5501 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5502 | /* This is called whenever we suspect that the system chipset is re- |
| 5503 | * ordering the sequence of MMIO to the tx send mailbox. The symptom |
| 5504 | * is bogus tx completions. We try to recover by setting the |
| 5505 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later |
| 5506 | * in the workqueue. |
| 5507 | */ |
| 5508 | static void tg3_tx_recover(struct tg3 *tp) |
| 5509 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5510 | BUG_ON(tg3_flag(tp, MBOX_WRITE_REORDER) || |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5511 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
| 5512 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5513 | netdev_warn(tp->dev, |
| 5514 | "The system may be re-ordering memory-mapped I/O " |
| 5515 | "cycles to the network device, attempting to recover. " |
| 5516 | "Please report the problem to the driver maintainer " |
| 5517 | "and include system chipset information.\n"); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5518 | |
| 5519 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5520 | tg3_flag_set(tp, TX_RECOVERY_PENDING); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5521 | spin_unlock(&tp->lock); |
| 5522 | } |
| 5523 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5524 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5525 | { |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 5526 | /* Tell compiler to fetch tx indices from memory. */ |
| 5527 | barrier(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5528 | return tnapi->tx_pending - |
| 5529 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5530 | } |
| 5531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | /* Tigon3 never reports partial packet sends. So we do not |
| 5533 | * need special logic to handle SKBs that have not had all |
| 5534 | * of their frags sent yet, like SunGEM does. |
| 5535 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5536 | static void tg3_tx(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5537 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5538 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5539 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5540 | u32 sw_idx = tnapi->tx_cons; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5541 | struct netdev_queue *txq; |
| 5542 | int index = tnapi - tp->napi; |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5543 | unsigned int pkts_compl = 0, bytes_compl = 0; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5544 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5545 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5546 | index--; |
| 5547 | |
| 5548 | txq = netdev_get_tx_queue(tp->dev, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | |
| 5550 | while (sw_idx != hw_idx) { |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 5551 | struct tg3_tx_ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | struct sk_buff *skb = ri->skb; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5553 | int i, tx_bug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5554 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5555 | if (unlikely(skb == NULL)) { |
| 5556 | tg3_tx_recover(tp); |
| 5557 | return; |
| 5558 | } |
| 5559 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5560 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5561 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5562 | skb_headlen(skb), |
| 5563 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 | |
| 5565 | ri->skb = NULL; |
| 5566 | |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 5567 | while (ri->fragmented) { |
| 5568 | ri->fragmented = false; |
| 5569 | sw_idx = NEXT_TX(sw_idx); |
| 5570 | ri = &tnapi->tx_buffers[sw_idx]; |
| 5571 | } |
| 5572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | sw_idx = NEXT_TX(sw_idx); |
| 5574 | |
| 5575 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5576 | ri = &tnapi->tx_buffers[sw_idx]; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5577 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
| 5578 | tx_bug = 1; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5579 | |
| 5580 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5581 | dma_unmap_addr(ri, mapping), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5582 | skb_frag_size(&skb_shinfo(skb)->frags[i]), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5583 | PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 5584 | |
| 5585 | while (ri->fragmented) { |
| 5586 | ri->fragmented = false; |
| 5587 | sw_idx = NEXT_TX(sw_idx); |
| 5588 | ri = &tnapi->tx_buffers[sw_idx]; |
| 5589 | } |
| 5590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5591 | sw_idx = NEXT_TX(sw_idx); |
| 5592 | } |
| 5593 | |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5594 | pkts_compl++; |
| 5595 | bytes_compl += skb->len; |
| 5596 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5597 | dev_kfree_skb(skb); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5598 | |
| 5599 | if (unlikely(tx_bug)) { |
| 5600 | tg3_tx_recover(tp); |
| 5601 | return; |
| 5602 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 5605 | netdev_tx_completed_queue(txq, pkts_compl, bytes_compl); |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5606 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5607 | tnapi->tx_cons = sw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5608 | |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5609 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
| 5610 | * before checking for netif_queue_stopped(). Without the |
| 5611 | * memory barrier, there is a small possibility that tg3_start_xmit() |
| 5612 | * will miss it and cause the queue to be stopped forever. |
| 5613 | */ |
| 5614 | smp_mb(); |
| 5615 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5616 | if (unlikely(netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5617 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5618 | __netif_tx_lock(txq, smp_processor_id()); |
| 5619 | if (netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5620 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5621 | netif_tx_wake_queue(txq); |
| 5622 | __netif_tx_unlock(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 5623 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5624 | } |
| 5625 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5626 | static void tg3_frag_free(bool is_frag, void *data) |
| 5627 | { |
| 5628 | if (is_frag) |
| 5629 | put_page(virt_to_head_page(data)); |
| 5630 | else |
| 5631 | kfree(data); |
| 5632 | } |
| 5633 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5634 | static void tg3_rx_data_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5635 | { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5636 | unsigned int skb_size = SKB_DATA_ALIGN(map_sz + TG3_RX_OFFSET(tp)) + |
| 5637 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 5638 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5639 | if (!ri->data) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5640 | return; |
| 5641 | |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5642 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5643 | map_sz, PCI_DMA_FROMDEVICE); |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 5644 | tg3_frag_free(skb_size <= PAGE_SIZE, ri->data); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5645 | ri->data = NULL; |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5646 | } |
| 5647 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5649 | /* Returns size of skb allocated or < 0 on error. |
| 5650 | * |
| 5651 | * We only need to fill in the address because the other members |
| 5652 | * of the RX descriptor are invariant, see tg3_init_rings. |
| 5653 | * |
| 5654 | * Note the purposeful assymetry of cpu vs. chip accesses. For |
| 5655 | * posting buffers we only dirty the first cache line of the RX |
| 5656 | * descriptor (containing the address). Whereas for the RX status |
| 5657 | * buffers the cpu only reads the last cacheline of the RX descriptor |
| 5658 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). |
| 5659 | */ |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5660 | static int tg3_alloc_rx_data(struct tg3 *tp, struct tg3_rx_prodring_set *tpr, |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5661 | u32 opaque_key, u32 dest_idx_unmasked, |
| 5662 | unsigned int *frag_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5663 | { |
| 5664 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | f94e290 | 2010-10-14 10:37:42 +0000 | [diff] [blame] | 5665 | struct ring_info *map; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5666 | u8 *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | dma_addr_t mapping; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5668 | int skb_size, data_size, dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5670 | switch (opaque_key) { |
| 5671 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5672 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 5673 | desc = &tpr->rx_std[dest_idx]; |
| 5674 | map = &tpr->rx_std_buffers[dest_idx]; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5675 | data_size = tp->rx_pkt_map_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5676 | break; |
| 5677 | |
| 5678 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5679 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 5680 | desc = &tpr->rx_jmb[dest_idx].std; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 5681 | map = &tpr->rx_jmb_buffers[dest_idx]; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5682 | data_size = TG3_RX_JMB_MAP_SZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5683 | break; |
| 5684 | |
| 5685 | default: |
| 5686 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 5687 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5688 | |
| 5689 | /* Do not overwrite any of the map or rp information |
| 5690 | * until we are sure we can commit to a new buffer. |
| 5691 | * |
| 5692 | * Callers depend upon this behavior and assume that |
| 5693 | * we leave everything unchanged if we fail. |
| 5694 | */ |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5695 | skb_size = SKB_DATA_ALIGN(data_size + TG3_RX_OFFSET(tp)) + |
| 5696 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 5697 | if (skb_size <= PAGE_SIZE) { |
| 5698 | data = netdev_alloc_frag(skb_size); |
| 5699 | *frag_size = skb_size; |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5700 | } else { |
| 5701 | data = kmalloc(skb_size, GFP_ATOMIC); |
| 5702 | *frag_size = 0; |
| 5703 | } |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5704 | if (!data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5705 | return -ENOMEM; |
| 5706 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5707 | mapping = pci_map_single(tp->pdev, |
| 5708 | data + TG3_RX_OFFSET(tp), |
| 5709 | data_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5710 | PCI_DMA_FROMDEVICE); |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5711 | if (unlikely(pci_dma_mapping_error(tp->pdev, mapping))) { |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 5712 | tg3_frag_free(skb_size <= PAGE_SIZE, data); |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 5713 | return -EIO; |
| 5714 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5716 | map->data = data; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5717 | dma_unmap_addr_set(map, mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | desc->addr_hi = ((u64)mapping >> 32); |
| 5720 | desc->addr_lo = ((u64)mapping & 0xffffffff); |
| 5721 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5722 | return data_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | /* We only need to move over in the address because the other |
| 5726 | * members of the RX descriptor are invariant. See notes above |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5727 | * tg3_alloc_rx_data for full details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 | */ |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5729 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
| 5730 | struct tg3_rx_prodring_set *dpr, |
| 5731 | u32 opaque_key, int src_idx, |
| 5732 | u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5733 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5734 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
| 5736 | struct ring_info *src_map, *dest_map; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5737 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5738 | int dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5739 | |
| 5740 | switch (opaque_key) { |
| 5741 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5742 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5743 | dest_desc = &dpr->rx_std[dest_idx]; |
| 5744 | dest_map = &dpr->rx_std_buffers[dest_idx]; |
| 5745 | src_desc = &spr->rx_std[src_idx]; |
| 5746 | src_map = &spr->rx_std_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5747 | break; |
| 5748 | |
| 5749 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5750 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5751 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
| 5752 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; |
| 5753 | src_desc = &spr->rx_jmb[src_idx].std; |
| 5754 | src_map = &spr->rx_jmb_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5755 | break; |
| 5756 | |
| 5757 | default: |
| 5758 | return; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 5759 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5760 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5761 | dest_map->data = src_map->data; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5762 | dma_unmap_addr_set(dest_map, mapping, |
| 5763 | dma_unmap_addr(src_map, mapping)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | dest_desc->addr_hi = src_desc->addr_hi; |
| 5765 | dest_desc->addr_lo = src_desc->addr_lo; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5766 | |
| 5767 | /* Ensure that the update to the skb happens after the physical |
| 5768 | * addresses have been transferred to the new BD location. |
| 5769 | */ |
| 5770 | smp_wmb(); |
| 5771 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5772 | src_map->data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5773 | } |
| 5774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | /* The RX ring scheme is composed of multiple rings which post fresh |
| 5776 | * buffers to the chip, and one special ring the chip uses to report |
| 5777 | * status back to the host. |
| 5778 | * |
| 5779 | * The special ring reports the status of received packets to the |
| 5780 | * host. The chip does not write into the original descriptor the |
| 5781 | * RX buffer was obtained from. The chip simply takes the original |
| 5782 | * descriptor as provided by the host, updates the status and length |
| 5783 | * field, then writes this into the next status ring entry. |
| 5784 | * |
| 5785 | * Each ring the host uses to post buffers to the chip is described |
| 5786 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, |
| 5787 | * it is first placed into the on-chip ram. When the packet's length |
| 5788 | * is known, it walks down the TG3_BDINFO entries to select the ring. |
| 5789 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO |
| 5790 | * which is within the range of the new packet's length is chosen. |
| 5791 | * |
| 5792 | * The "separate ring for rx status" scheme may sound queer, but it makes |
| 5793 | * sense from a cache coherency perspective. If only the host writes |
| 5794 | * to the buffer post rings, and only the chip writes to the rx status |
| 5795 | * rings, then cache lines never move beyond shared-modified state. |
| 5796 | * If both the host and chip were to write into the same ring, cache line |
| 5797 | * eviction could occur since both entities want it in an exclusive state. |
| 5798 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5799 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5800 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5801 | struct tg3 *tp = tnapi->tp; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5802 | u32 work_mask, rx_std_posted = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5803 | u32 std_prod_idx, jmb_prod_idx; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5804 | u32 sw_idx = tnapi->rx_rcb_ptr; |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 5805 | u16 hw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | int received; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5807 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 5809 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5810 | /* |
| 5811 | * We need to order the read of hw_idx and the read of |
| 5812 | * the opaque cookie. |
| 5813 | */ |
| 5814 | rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5815 | work_mask = 0; |
| 5816 | received = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5817 | std_prod_idx = tpr->rx_std_prod_idx; |
| 5818 | jmb_prod_idx = tpr->rx_jmb_prod_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5819 | while (sw_idx != hw_idx && budget > 0) { |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 5820 | struct ring_info *ri; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5821 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5822 | unsigned int len; |
| 5823 | struct sk_buff *skb; |
| 5824 | dma_addr_t dma_addr; |
| 5825 | u32 opaque_key, desc_idx, *post_ptr; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5826 | u8 *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5827 | |
| 5828 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 5829 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 5830 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5831 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5832 | dma_addr = dma_unmap_addr(ri, mapping); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5833 | data = ri->data; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5834 | post_ptr = &std_prod_idx; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5835 | rx_std_posted++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5837 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5838 | dma_addr = dma_unmap_addr(ri, mapping); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5839 | data = ri->data; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5840 | post_ptr = &jmb_prod_idx; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 5841 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | goto next_pkt_nopost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5843 | |
| 5844 | work_mask |= opaque_key; |
| 5845 | |
| 5846 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 5847 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { |
| 5848 | drop_it: |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5849 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5850 | desc_idx, *post_ptr); |
| 5851 | drop_it_no_recycle: |
| 5852 | /* Other statistics kept track of by card. */ |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 5853 | tp->rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5854 | goto next_pkt; |
| 5855 | } |
| 5856 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5857 | prefetch(data + TG3_RX_OFFSET(tp)); |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 5858 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
| 5859 | ETH_FCS_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5860 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 5861 | if (len > TG3_RX_COPY_THRESH(tp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5862 | int skb_size; |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5863 | unsigned int frag_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5864 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5865 | skb_size = tg3_alloc_rx_data(tp, tpr, opaque_key, |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5866 | *post_ptr, &frag_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5867 | if (skb_size < 0) |
| 5868 | goto drop_it; |
| 5869 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 5870 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5871 | PCI_DMA_FROMDEVICE); |
| 5872 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5873 | skb = build_skb(data, frag_size); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5874 | if (!skb) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5875 | tg3_frag_free(frag_size != 0, data); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5876 | goto drop_it_no_recycle; |
| 5877 | } |
| 5878 | skb_reserve(skb, TG3_RX_OFFSET(tp)); |
| 5879 | /* Ensure that the update to the data happens |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 5880 | * after the usage of the old DMA mapping. |
| 5881 | */ |
| 5882 | smp_wmb(); |
| 5883 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5884 | ri->data = NULL; |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 5885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5886 | } else { |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5887 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5888 | desc_idx, *post_ptr); |
| 5889 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5890 | skb = netdev_alloc_skb(tp->dev, |
| 5891 | len + TG3_RAW_IP_ALIGN); |
| 5892 | if (skb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5893 | goto drop_it_no_recycle; |
| 5894 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5895 | skb_reserve(skb, TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5896 | pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5897 | memcpy(skb->data, |
| 5898 | data + TG3_RX_OFFSET(tp), |
| 5899 | len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5900 | pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5903 | skb_put(skb, len); |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 5904 | if ((tp->dev->features & NETIF_F_RXCSUM) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5905 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 5906 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 5907 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) |
| 5908 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 5909 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 5910 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5911 | |
| 5912 | skb->protocol = eth_type_trans(skb, tp->dev); |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 5913 | |
| 5914 | if (len > (tp->dev->mtu + ETH_HLEN) && |
| 5915 | skb->protocol != htons(ETH_P_8021Q)) { |
| 5916 | dev_kfree_skb(skb); |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 5917 | goto drop_it_no_recycle; |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 5918 | } |
| 5919 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 5920 | if (desc->type_flags & RXD_FLAG_VLAN && |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 5921 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
| 5922 | __vlan_hwaccel_put_tag(skb, |
| 5923 | desc->err_vlan & RXD_VLAN_MASK); |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 5924 | |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 5925 | napi_gro_receive(&tnapi->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5927 | received++; |
| 5928 | budget--; |
| 5929 | |
| 5930 | next_pkt: |
| 5931 | (*post_ptr)++; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5932 | |
| 5933 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5934 | tpr->rx_std_prod_idx = std_prod_idx & |
| 5935 | tp->rx_std_ring_mask; |
Matt Carlson | 86cfe4f | 2010-01-12 10:11:37 +0000 | [diff] [blame] | 5936 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 5937 | tpr->rx_std_prod_idx); |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5938 | work_mask &= ~RXD_OPAQUE_RING_STD; |
| 5939 | rx_std_posted = 0; |
| 5940 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5941 | next_pkt_nopost: |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 5942 | sw_idx++; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 5943 | sw_idx &= tp->rx_ret_ring_mask; |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 5944 | |
| 5945 | /* Refresh hw_idx to see if there is new work */ |
| 5946 | if (sw_idx == hw_idx) { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 5947 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 5948 | rmb(); |
| 5949 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5950 | } |
| 5951 | |
| 5952 | /* ACK the status ring. */ |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5953 | tnapi->rx_rcb_ptr = sw_idx; |
| 5954 | tw32_rx_mbox(tnapi->consmbox, sw_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5955 | |
| 5956 | /* Refill RX ring(s). */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5957 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 5958 | /* Sync BD data before updating mailbox */ |
| 5959 | wmb(); |
| 5960 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5961 | if (work_mask & RXD_OPAQUE_RING_STD) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5962 | tpr->rx_std_prod_idx = std_prod_idx & |
| 5963 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5964 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 5965 | tpr->rx_std_prod_idx); |
| 5966 | } |
| 5967 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5968 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
| 5969 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5970 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 5971 | tpr->rx_jmb_prod_idx); |
| 5972 | } |
| 5973 | mmiowb(); |
| 5974 | } else if (work_mask) { |
| 5975 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be |
| 5976 | * updated before the producer indices can be updated. |
| 5977 | */ |
| 5978 | smp_wmb(); |
| 5979 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5980 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
| 5981 | 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] | 5982 | |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 5983 | if (tnapi != &tp->napi[1]) { |
| 5984 | tp->rx_refill = true; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5985 | napi_schedule(&tp->napi[1].napi); |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 5986 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5987 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5988 | |
| 5989 | return received; |
| 5990 | } |
| 5991 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5992 | static void tg3_poll_link(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5993 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5994 | /* handle link change and other phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5995 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5996 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
| 5997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5998 | if (sblk->status & SD_STATUS_LINK_CHG) { |
| 5999 | sblk->status = SD_STATUS_UPDATED | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6000 | (sblk->status & ~SD_STATUS_LINK_CHG); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6001 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6002 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 6003 | tw32_f(MAC_STATUS, |
| 6004 | (MAC_STATUS_SYNC_CHANGED | |
| 6005 | MAC_STATUS_CFG_CHANGED | |
| 6006 | MAC_STATUS_MI_COMPLETION | |
| 6007 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 6008 | udelay(40); |
| 6009 | } else |
| 6010 | tg3_setup_phy(tp, 0); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6011 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6012 | } |
| 6013 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6014 | } |
| 6015 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6016 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
| 6017 | struct tg3_rx_prodring_set *dpr, |
| 6018 | struct tg3_rx_prodring_set *spr) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6019 | { |
| 6020 | u32 si, di, cpycnt, src_prod_idx; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6021 | int i, err = 0; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6022 | |
| 6023 | while (1) { |
| 6024 | src_prod_idx = spr->rx_std_prod_idx; |
| 6025 | |
| 6026 | /* Make sure updates to the rx_std_buffers[] entries and the |
| 6027 | * standard producer index are seen in the correct order. |
| 6028 | */ |
| 6029 | smp_rmb(); |
| 6030 | |
| 6031 | if (spr->rx_std_cons_idx == src_prod_idx) |
| 6032 | break; |
| 6033 | |
| 6034 | if (spr->rx_std_cons_idx < src_prod_idx) |
| 6035 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; |
| 6036 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6037 | cpycnt = tp->rx_std_ring_mask + 1 - |
| 6038 | spr->rx_std_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6039 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6040 | cpycnt = min(cpycnt, |
| 6041 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6042 | |
| 6043 | si = spr->rx_std_cons_idx; |
| 6044 | di = dpr->rx_std_prod_idx; |
| 6045 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6046 | for (i = di; i < di + cpycnt; i++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6047 | if (dpr->rx_std_buffers[i].data) { |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6048 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6049 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6050 | break; |
| 6051 | } |
| 6052 | } |
| 6053 | |
| 6054 | if (!cpycnt) |
| 6055 | break; |
| 6056 | |
| 6057 | /* Ensure that updates to the rx_std_buffers ring and the |
| 6058 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 6059 | * ordered correctly WRT the skb check above. |
| 6060 | */ |
| 6061 | smp_rmb(); |
| 6062 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6063 | memcpy(&dpr->rx_std_buffers[di], |
| 6064 | &spr->rx_std_buffers[si], |
| 6065 | cpycnt * sizeof(struct ring_info)); |
| 6066 | |
| 6067 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 6068 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 6069 | sbd = &spr->rx_std[si]; |
| 6070 | dbd = &dpr->rx_std[di]; |
| 6071 | dbd->addr_hi = sbd->addr_hi; |
| 6072 | dbd->addr_lo = sbd->addr_lo; |
| 6073 | } |
| 6074 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6075 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
| 6076 | tp->rx_std_ring_mask; |
| 6077 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & |
| 6078 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6079 | } |
| 6080 | |
| 6081 | while (1) { |
| 6082 | src_prod_idx = spr->rx_jmb_prod_idx; |
| 6083 | |
| 6084 | /* Make sure updates to the rx_jmb_buffers[] entries and |
| 6085 | * the jumbo producer index are seen in the correct order. |
| 6086 | */ |
| 6087 | smp_rmb(); |
| 6088 | |
| 6089 | if (spr->rx_jmb_cons_idx == src_prod_idx) |
| 6090 | break; |
| 6091 | |
| 6092 | if (spr->rx_jmb_cons_idx < src_prod_idx) |
| 6093 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; |
| 6094 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6095 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
| 6096 | spr->rx_jmb_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6097 | |
| 6098 | cpycnt = min(cpycnt, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6099 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6100 | |
| 6101 | si = spr->rx_jmb_cons_idx; |
| 6102 | di = dpr->rx_jmb_prod_idx; |
| 6103 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6104 | for (i = di; i < di + cpycnt; i++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6105 | if (dpr->rx_jmb_buffers[i].data) { |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6106 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6107 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6108 | break; |
| 6109 | } |
| 6110 | } |
| 6111 | |
| 6112 | if (!cpycnt) |
| 6113 | break; |
| 6114 | |
| 6115 | /* Ensure that updates to the rx_jmb_buffers ring and the |
| 6116 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 6117 | * ordered correctly WRT the skb check above. |
| 6118 | */ |
| 6119 | smp_rmb(); |
| 6120 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6121 | memcpy(&dpr->rx_jmb_buffers[di], |
| 6122 | &spr->rx_jmb_buffers[si], |
| 6123 | cpycnt * sizeof(struct ring_info)); |
| 6124 | |
| 6125 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 6126 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 6127 | sbd = &spr->rx_jmb[si].std; |
| 6128 | dbd = &dpr->rx_jmb[di].std; |
| 6129 | dbd->addr_hi = sbd->addr_hi; |
| 6130 | dbd->addr_lo = sbd->addr_lo; |
| 6131 | } |
| 6132 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6133 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
| 6134 | tp->rx_jmb_ring_mask; |
| 6135 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & |
| 6136 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6137 | } |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6138 | |
| 6139 | return err; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6140 | } |
| 6141 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6142 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
| 6143 | { |
| 6144 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6145 | |
| 6146 | /* run TX completion thread */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6147 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6148 | tg3_tx(tnapi); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6149 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6150 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6151 | } |
| 6152 | |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 6153 | if (!tnapi->rx_rcb_prod_idx) |
| 6154 | return work_done; |
| 6155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6156 | /* run RX thread, within the bounds set by NAPI. |
| 6157 | * All RX "locking" is done by ensuring outside |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6158 | * code synchronizes with tg3->napi.poll() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6159 | */ |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6160 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6161 | work_done += tg3_rx(tnapi, budget - work_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6162 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6163 | if (tg3_flag(tp, ENABLE_RSS) && tnapi == &tp->napi[1]) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6164 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6165 | int i, err = 0; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6166 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
| 6167 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6168 | |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6169 | tp->rx_refill = false; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6170 | for (i = 1; i < tp->irq_cnt; i++) |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6171 | err |= tg3_rx_prodring_xfer(tp, dpr, |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6172 | &tp->napi[i].prodring); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6173 | |
| 6174 | wmb(); |
| 6175 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6176 | if (std_prod_idx != dpr->rx_std_prod_idx) |
| 6177 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6178 | dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6179 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6180 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
| 6181 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 6182 | dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6183 | |
| 6184 | mmiowb(); |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6185 | |
| 6186 | if (err) |
| 6187 | tw32_f(HOSTCC_MODE, tp->coal_now); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6188 | } |
| 6189 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6190 | return work_done; |
| 6191 | } |
David S. Miller | f7383c2 | 2005-05-18 22:50:53 -0700 | [diff] [blame] | 6192 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6193 | static inline void tg3_reset_task_schedule(struct tg3 *tp) |
| 6194 | { |
| 6195 | if (!test_and_set_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags)) |
| 6196 | schedule_work(&tp->reset_task); |
| 6197 | } |
| 6198 | |
| 6199 | static inline void tg3_reset_task_cancel(struct tg3 *tp) |
| 6200 | { |
| 6201 | cancel_work_sync(&tp->reset_task); |
| 6202 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
Matt Carlson | c710135 | 2012-02-22 12:35:20 +0000 | [diff] [blame] | 6203 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6204 | } |
| 6205 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6206 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
| 6207 | { |
| 6208 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 6209 | struct tg3 *tp = tnapi->tp; |
| 6210 | int work_done = 0; |
| 6211 | struct tg3_hw_status *sblk = tnapi->hw_status; |
| 6212 | |
| 6213 | while (1) { |
| 6214 | work_done = tg3_poll_work(tnapi, work_done, budget); |
| 6215 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6216 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6217 | goto tx_recovery; |
| 6218 | |
| 6219 | if (unlikely(work_done >= budget)) |
| 6220 | break; |
| 6221 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 6222 | /* tp->last_tag is used in tg3_int_reenable() below |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6223 | * to tell the hw how much work has been processed, |
| 6224 | * so we must read it before checking for more work. |
| 6225 | */ |
| 6226 | tnapi->last_tag = sblk->status_tag; |
| 6227 | tnapi->last_irq_tag = tnapi->last_tag; |
| 6228 | rmb(); |
| 6229 | |
| 6230 | /* check for RX/TX work to do */ |
Matt Carlson | 6d40db7 | 2010-04-05 10:19:20 +0000 | [diff] [blame] | 6231 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
| 6232 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6233 | |
| 6234 | /* This test here is not race free, but will reduce |
| 6235 | * the number of interrupts by looping again. |
| 6236 | */ |
| 6237 | if (tnapi == &tp->napi[1] && tp->rx_refill) |
| 6238 | continue; |
| 6239 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6240 | napi_complete(napi); |
| 6241 | /* Reenable interrupts. */ |
| 6242 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6243 | |
| 6244 | /* This test here is synchronized by napi_schedule() |
| 6245 | * and napi_complete() to close the race condition. |
| 6246 | */ |
| 6247 | if (unlikely(tnapi == &tp->napi[1] && tp->rx_refill)) { |
| 6248 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
| 6249 | HOSTCC_MODE_ENABLE | |
| 6250 | tnapi->coal_now); |
| 6251 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6252 | mmiowb(); |
| 6253 | break; |
| 6254 | } |
| 6255 | } |
| 6256 | |
| 6257 | return work_done; |
| 6258 | |
| 6259 | tx_recovery: |
| 6260 | /* work_done is guaranteed to be less than budget. */ |
| 6261 | napi_complete(napi); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6262 | tg3_reset_task_schedule(tp); |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6263 | return work_done; |
| 6264 | } |
| 6265 | |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6266 | static void tg3_process_error(struct tg3 *tp) |
| 6267 | { |
| 6268 | u32 val; |
| 6269 | bool real_error = false; |
| 6270 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6271 | if (tg3_flag(tp, ERROR_PROCESSED)) |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6272 | return; |
| 6273 | |
| 6274 | /* Check Flow Attention register */ |
| 6275 | val = tr32(HOSTCC_FLOW_ATTN); |
| 6276 | if (val & ~HOSTCC_FLOW_ATTN_MBUF_LWM) { |
| 6277 | netdev_err(tp->dev, "FLOW Attention error. Resetting chip.\n"); |
| 6278 | real_error = true; |
| 6279 | } |
| 6280 | |
| 6281 | if (tr32(MSGINT_STATUS) & ~MSGINT_STATUS_MSI_REQ) { |
| 6282 | netdev_err(tp->dev, "MSI Status error. Resetting chip.\n"); |
| 6283 | real_error = true; |
| 6284 | } |
| 6285 | |
| 6286 | if (tr32(RDMAC_STATUS) || tr32(WDMAC_STATUS)) { |
| 6287 | netdev_err(tp->dev, "DMA Status error. Resetting chip.\n"); |
| 6288 | real_error = true; |
| 6289 | } |
| 6290 | |
| 6291 | if (!real_error) |
| 6292 | return; |
| 6293 | |
| 6294 | tg3_dump_state(tp); |
| 6295 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6296 | tg3_flag_set(tp, ERROR_PROCESSED); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6297 | tg3_reset_task_schedule(tp); |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6298 | } |
| 6299 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6300 | static int tg3_poll(struct napi_struct *napi, int budget) |
| 6301 | { |
Matt Carlson | 8ef0442 | 2009-08-28 14:01:37 +0000 | [diff] [blame] | 6302 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 6303 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6304 | int work_done = 0; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6305 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6306 | |
| 6307 | while (1) { |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6308 | if (sblk->status & SD_STATUS_ERROR) |
| 6309 | tg3_process_error(tp); |
| 6310 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6311 | tg3_poll_link(tp); |
| 6312 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6313 | work_done = tg3_poll_work(tnapi, work_done, budget); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6314 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6315 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6316 | goto tx_recovery; |
| 6317 | |
| 6318 | if (unlikely(work_done >= budget)) |
| 6319 | break; |
| 6320 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6321 | if (tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6322 | /* tp->last_tag is used in tg3_int_reenable() below |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6323 | * to tell the hw how much work has been processed, |
| 6324 | * so we must read it before checking for more work. |
| 6325 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6326 | tnapi->last_tag = sblk->status_tag; |
| 6327 | tnapi->last_irq_tag = tnapi->last_tag; |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6328 | rmb(); |
| 6329 | } else |
| 6330 | sblk->status &= ~SD_STATUS_UPDATED; |
| 6331 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6332 | if (likely(!tg3_has_work(tnapi))) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 6333 | napi_complete(napi); |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6334 | tg3_int_reenable(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6335 | break; |
| 6336 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6337 | } |
| 6338 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6339 | return work_done; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6340 | |
| 6341 | tx_recovery: |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6342 | /* work_done is guaranteed to be less than budget. */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 6343 | napi_complete(napi); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6344 | tg3_reset_task_schedule(tp); |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6345 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6346 | } |
| 6347 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6348 | static void tg3_napi_disable(struct tg3 *tp) |
| 6349 | { |
| 6350 | int i; |
| 6351 | |
| 6352 | for (i = tp->irq_cnt - 1; i >= 0; i--) |
| 6353 | napi_disable(&tp->napi[i].napi); |
| 6354 | } |
| 6355 | |
| 6356 | static void tg3_napi_enable(struct tg3 *tp) |
| 6357 | { |
| 6358 | int i; |
| 6359 | |
| 6360 | for (i = 0; i < tp->irq_cnt; i++) |
| 6361 | napi_enable(&tp->napi[i].napi); |
| 6362 | } |
| 6363 | |
| 6364 | static void tg3_napi_init(struct tg3 *tp) |
| 6365 | { |
| 6366 | int i; |
| 6367 | |
| 6368 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); |
| 6369 | for (i = 1; i < tp->irq_cnt; i++) |
| 6370 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); |
| 6371 | } |
| 6372 | |
| 6373 | static void tg3_napi_fini(struct tg3 *tp) |
| 6374 | { |
| 6375 | int i; |
| 6376 | |
| 6377 | for (i = 0; i < tp->irq_cnt; i++) |
| 6378 | netif_napi_del(&tp->napi[i].napi); |
| 6379 | } |
| 6380 | |
| 6381 | static inline void tg3_netif_stop(struct tg3 *tp) |
| 6382 | { |
| 6383 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 6384 | tg3_napi_disable(tp); |
| 6385 | netif_tx_disable(tp->dev); |
| 6386 | } |
| 6387 | |
| 6388 | static inline void tg3_netif_start(struct tg3 *tp) |
| 6389 | { |
| 6390 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
| 6391 | * appropriate so long as all callers are assured to |
| 6392 | * have free tx slots (such as after tg3_init_hw) |
| 6393 | */ |
| 6394 | netif_tx_wake_all_queues(tp->dev); |
| 6395 | |
| 6396 | tg3_napi_enable(tp); |
| 6397 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; |
| 6398 | tg3_enable_ints(tp); |
| 6399 | } |
| 6400 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6401 | static void tg3_irq_quiesce(struct tg3 *tp) |
| 6402 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6403 | int i; |
| 6404 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6405 | BUG_ON(tp->irq_sync); |
| 6406 | |
| 6407 | tp->irq_sync = 1; |
| 6408 | smp_mb(); |
| 6409 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6410 | for (i = 0; i < tp->irq_cnt; i++) |
| 6411 | synchronize_irq(tp->napi[i].irq_vec); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6412 | } |
| 6413 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6414 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
| 6415 | * If irq_sync is non-zero, then the IRQ handler must be synchronized |
| 6416 | * with as well. Most of the time, this is not necessary except when |
| 6417 | * shutting down the device. |
| 6418 | */ |
| 6419 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) |
| 6420 | { |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 6421 | spin_lock_bh(&tp->lock); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6422 | if (irq_sync) |
| 6423 | tg3_irq_quiesce(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | static inline void tg3_full_unlock(struct tg3 *tp) |
| 6427 | { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6428 | spin_unlock_bh(&tp->lock); |
| 6429 | } |
| 6430 | |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6431 | /* One-shot MSI handler - Chip automatically disables interrupt |
| 6432 | * after sending MSI so driver doesn't have to do it. |
| 6433 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6434 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6435 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6436 | struct tg3_napi *tnapi = dev_id; |
| 6437 | struct tg3 *tp = tnapi->tp; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6438 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6439 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6440 | if (tnapi->rx_rcb) |
| 6441 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6442 | |
| 6443 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6444 | napi_schedule(&tnapi->napi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6445 | |
| 6446 | return IRQ_HANDLED; |
| 6447 | } |
| 6448 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6449 | /* MSI ISR - No need to check for interrupt sharing and no need to |
| 6450 | * flush status block and interrupt mailbox. PCI ordering rules |
| 6451 | * guarantee that MSI will arrive after the status block. |
| 6452 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6453 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6454 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6455 | struct tg3_napi *tnapi = dev_id; |
| 6456 | struct tg3 *tp = tnapi->tp; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6457 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6458 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6459 | if (tnapi->rx_rcb) |
| 6460 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6461 | /* |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6462 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6463 | * chip-internal interrupt pending events. |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6464 | * Writing non-zero to intr-mbox-0 additional tells the |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6465 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6466 | * event coalescing. |
| 6467 | */ |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 6468 | tw32_mailbox(tnapi->int_mbox, 0x00000001); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 6469 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6470 | napi_schedule(&tnapi->napi); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 6471 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6472 | return IRQ_RETVAL(1); |
| 6473 | } |
| 6474 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6475 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6476 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6477 | struct tg3_napi *tnapi = dev_id; |
| 6478 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6479 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6480 | unsigned int handled = 1; |
| 6481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6482 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 6483 | * the CPU before the status block posted prior to the interrupt. |
| 6484 | * Reading the PCI State register will confirm whether the |
| 6485 | * interrupt is ours and will flush the status block. |
| 6486 | */ |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6487 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6488 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6489 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 6490 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6491 | goto out; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6492 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6493 | } |
| 6494 | |
| 6495 | /* |
| 6496 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
| 6497 | * chip-internal interrupt pending events. |
| 6498 | * Writing non-zero to intr-mbox-0 additional tells the |
| 6499 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6500 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6501 | * |
| 6502 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 6503 | * spurious interrupts. The flush impacts performance but |
| 6504 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6505 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6506 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6507 | if (tg3_irq_sync(tp)) |
| 6508 | goto out; |
| 6509 | sblk->status &= ~SD_STATUS_UPDATED; |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6510 | if (likely(tg3_has_work(tnapi))) { |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6511 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6512 | napi_schedule(&tnapi->napi); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6513 | } else { |
| 6514 | /* No work, shared interrupt perhaps? re-enable |
| 6515 | * interrupts, and flush that PCI write |
| 6516 | */ |
| 6517 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, |
| 6518 | 0x00000000); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6519 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6520 | out: |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6521 | return IRQ_RETVAL(handled); |
| 6522 | } |
| 6523 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6524 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6525 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6526 | struct tg3_napi *tnapi = dev_id; |
| 6527 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6528 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6529 | unsigned int handled = 1; |
| 6530 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6531 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 6532 | * the CPU before the status block posted prior to the interrupt. |
| 6533 | * Reading the PCI State register will confirm whether the |
| 6534 | * interrupt is ours and will flush the status block. |
| 6535 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6536 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6537 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6538 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 6539 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6540 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6541 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6542 | } |
| 6543 | |
| 6544 | /* |
| 6545 | * writing any value to intr-mbox-0 clears PCI INTA# and |
| 6546 | * chip-internal interrupt pending events. |
| 6547 | * writing non-zero to intr-mbox-0 additional tells the |
| 6548 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6549 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6550 | * |
| 6551 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 6552 | * spurious interrupts. The flush impacts performance but |
| 6553 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6554 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6555 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6556 | |
| 6557 | /* |
| 6558 | * In a shared interrupt configuration, sometimes other devices' |
| 6559 | * interrupts will scream. We record the current status tag here |
| 6560 | * so that the above check can report that the screaming interrupts |
| 6561 | * are unhandled. Eventually they will be silenced. |
| 6562 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6563 | tnapi->last_irq_tag = sblk->status_tag; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6564 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6565 | if (tg3_irq_sync(tp)) |
| 6566 | goto out; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6567 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6568 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6569 | |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6570 | napi_schedule(&tnapi->napi); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6571 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6572 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6573 | return IRQ_RETVAL(handled); |
| 6574 | } |
| 6575 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6576 | /* ISR for interrupt test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6577 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6578 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6579 | struct tg3_napi *tnapi = dev_id; |
| 6580 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6581 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6582 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 6583 | if ((sblk->status & SD_STATUS_UPDATED) || |
| 6584 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 6585 | tg3_disable_ints(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6586 | return IRQ_RETVAL(1); |
| 6587 | } |
| 6588 | return IRQ_RETVAL(0); |
| 6589 | } |
| 6590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6591 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6592 | static void tg3_poll_controller(struct net_device *dev) |
| 6593 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6594 | int i; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6595 | struct tg3 *tp = netdev_priv(dev); |
| 6596 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6597 | for (i = 0; i < tp->irq_cnt; i++) |
Louis Rilling | fe234f0 | 2010-03-09 06:14:41 +0000 | [diff] [blame] | 6598 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6599 | } |
| 6600 | #endif |
| 6601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6602 | static void tg3_tx_timeout(struct net_device *dev) |
| 6603 | { |
| 6604 | struct tg3 *tp = netdev_priv(dev); |
| 6605 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 6606 | if (netif_msg_tx_err(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 6607 | netdev_err(dev, "transmit timed out, resetting\n"); |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6608 | tg3_dump_state(tp); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 6609 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6610 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6611 | tg3_reset_task_schedule(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6612 | } |
| 6613 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6614 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
| 6615 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) |
| 6616 | { |
| 6617 | u32 base = (u32) mapping & 0xffffffff; |
| 6618 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 6619 | return (base > 0xffffdcc0) && (base + len + 8 < base); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6620 | } |
| 6621 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6622 | /* Test for DMA addresses > 40-bit */ |
| 6623 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 6624 | int len) |
| 6625 | { |
| 6626 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6627 | if (tg3_flag(tp, 40BIT_DMA_BUG)) |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 6628 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6629 | return 0; |
| 6630 | #else |
| 6631 | return 0; |
| 6632 | #endif |
| 6633 | } |
| 6634 | |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6635 | static inline void tg3_tx_set_bd(struct tg3_tx_buffer_desc *txbd, |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6636 | dma_addr_t mapping, u32 len, u32 flags, |
| 6637 | u32 mss, u32 vlan) |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6638 | { |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6639 | txbd->addr_hi = ((u64) mapping >> 32); |
| 6640 | txbd->addr_lo = ((u64) mapping & 0xffffffff); |
| 6641 | txbd->len_flags = (len << TXD_LEN_SHIFT) | (flags & 0x0000ffff); |
| 6642 | txbd->vlan_tag = (mss << TXD_MSS_SHIFT) | (vlan << TXD_VLAN_TAG_SHIFT); |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6644 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6645 | static bool tg3_tx_frag_set(struct tg3_napi *tnapi, u32 *entry, u32 *budget, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6646 | dma_addr_t map, u32 len, u32 flags, |
| 6647 | u32 mss, u32 vlan) |
| 6648 | { |
| 6649 | struct tg3 *tp = tnapi->tp; |
| 6650 | bool hwbug = false; |
| 6651 | |
| 6652 | if (tg3_flag(tp, SHORT_DMA_BUG) && len <= 8) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6653 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6654 | |
| 6655 | if (tg3_4g_overflow_test(map, len)) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6656 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6657 | |
| 6658 | if (tg3_40bit_overflow_test(tp, map, len)) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6659 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6660 | |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 6661 | if (tp->dma_limit) { |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6662 | u32 prvidx = *entry; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6663 | u32 tmp_flag = flags & ~TXD_FLAG_END; |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 6664 | while (len > tp->dma_limit && *budget) { |
| 6665 | u32 frag_len = tp->dma_limit; |
| 6666 | len -= tp->dma_limit; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6667 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6668 | /* Avoid the 8byte DMA problem */ |
| 6669 | if (len <= 8) { |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 6670 | len += tp->dma_limit / 2; |
| 6671 | frag_len = tp->dma_limit / 2; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6672 | } |
| 6673 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6674 | tnapi->tx_buffers[*entry].fragmented = true; |
| 6675 | |
| 6676 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 6677 | frag_len, tmp_flag, mss, vlan); |
| 6678 | *budget -= 1; |
| 6679 | prvidx = *entry; |
| 6680 | *entry = NEXT_TX(*entry); |
| 6681 | |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6682 | map += frag_len; |
| 6683 | } |
| 6684 | |
| 6685 | if (len) { |
| 6686 | if (*budget) { |
| 6687 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 6688 | len, flags, mss, vlan); |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6689 | *budget -= 1; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6690 | *entry = NEXT_TX(*entry); |
| 6691 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6692 | hwbug = true; |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6693 | tnapi->tx_buffers[prvidx].fragmented = false; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6694 | } |
| 6695 | } |
| 6696 | } else { |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6697 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 6698 | len, flags, mss, vlan); |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6699 | *entry = NEXT_TX(*entry); |
| 6700 | } |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6701 | |
| 6702 | return hwbug; |
| 6703 | } |
| 6704 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 6705 | static void tg3_tx_skb_unmap(struct tg3_napi *tnapi, u32 entry, int last) |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6706 | { |
| 6707 | int i; |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 6708 | struct sk_buff *skb; |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 6709 | struct tg3_tx_ring_info *txb = &tnapi->tx_buffers[entry]; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6710 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 6711 | skb = txb->skb; |
| 6712 | txb->skb = NULL; |
| 6713 | |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6714 | pci_unmap_single(tnapi->tp->pdev, |
| 6715 | dma_unmap_addr(txb, mapping), |
| 6716 | skb_headlen(skb), |
| 6717 | PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 6718 | |
| 6719 | while (txb->fragmented) { |
| 6720 | txb->fragmented = false; |
| 6721 | entry = NEXT_TX(entry); |
| 6722 | txb = &tnapi->tx_buffers[entry]; |
| 6723 | } |
| 6724 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 6725 | for (i = 0; i <= last; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6726 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6727 | |
| 6728 | entry = NEXT_TX(entry); |
| 6729 | txb = &tnapi->tx_buffers[entry]; |
| 6730 | |
| 6731 | pci_unmap_page(tnapi->tp->pdev, |
| 6732 | dma_unmap_addr(txb, mapping), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6733 | skb_frag_size(frag), PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 6734 | |
| 6735 | while (txb->fragmented) { |
| 6736 | txb->fragmented = false; |
| 6737 | entry = NEXT_TX(entry); |
| 6738 | txb = &tnapi->tx_buffers[entry]; |
| 6739 | } |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6740 | } |
| 6741 | } |
| 6742 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6743 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6744 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6745 | struct sk_buff **pskb, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6746 | u32 *entry, u32 *budget, |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6747 | u32 base_flags, u32 mss, u32 vlan) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6748 | { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6749 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6750 | struct sk_buff *new_skb, *skb = *pskb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6751 | dma_addr_t new_addr = 0; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6752 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6753 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 6754 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 6755 | new_skb = skb_copy(skb, GFP_ATOMIC); |
| 6756 | else { |
| 6757 | int more_headroom = 4 - ((unsigned long)skb->data & 3); |
| 6758 | |
| 6759 | new_skb = skb_copy_expand(skb, |
| 6760 | skb_headroom(skb) + more_headroom, |
| 6761 | skb_tailroom(skb), GFP_ATOMIC); |
| 6762 | } |
| 6763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6764 | if (!new_skb) { |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6765 | ret = -1; |
| 6766 | } else { |
| 6767 | /* New SKB is guaranteed to be linear. */ |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6768 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
| 6769 | PCI_DMA_TODEVICE); |
| 6770 | /* Make sure the mapping succeeded */ |
| 6771 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6772 | dev_kfree_skb(new_skb); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6773 | ret = -1; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6774 | } else { |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6775 | u32 save_entry = *entry; |
| 6776 | |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6777 | base_flags |= TXD_FLAG_END; |
| 6778 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6779 | tnapi->tx_buffers[*entry].skb = new_skb; |
| 6780 | dma_unmap_addr_set(&tnapi->tx_buffers[*entry], |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6781 | mapping, new_addr); |
| 6782 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6783 | if (tg3_tx_frag_set(tnapi, entry, budget, new_addr, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6784 | new_skb->len, base_flags, |
| 6785 | mss, vlan)) { |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 6786 | tg3_tx_skb_unmap(tnapi, save_entry, -1); |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6787 | dev_kfree_skb(new_skb); |
| 6788 | ret = -1; |
| 6789 | } |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6790 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6791 | } |
| 6792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6793 | dev_kfree_skb(skb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6794 | *pskb = new_skb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6795 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6796 | } |
| 6797 | |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6798 | 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] | 6799 | |
| 6800 | /* Use GSO to workaround a rare TSO bug that may be triggered when the |
| 6801 | * TSO header is greater than 80 bytes. |
| 6802 | */ |
| 6803 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) |
| 6804 | { |
| 6805 | struct sk_buff *segs, *nskb; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6806 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6807 | |
| 6808 | /* Estimate the number of fragments in the worst case */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6809 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6810 | netif_stop_queue(tp->dev); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 6811 | |
| 6812 | /* netif_tx_stop_queue() must be done before checking |
| 6813 | * checking tx index in tg3_tx_avail() below, because in |
| 6814 | * tg3_tx(), we update tx index before checking for |
| 6815 | * netif_tx_queue_stopped(). |
| 6816 | */ |
| 6817 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6818 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 6819 | return NETDEV_TX_BUSY; |
| 6820 | |
| 6821 | netif_wake_queue(tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6822 | } |
| 6823 | |
| 6824 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame] | 6825 | if (IS_ERR(segs)) |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6826 | goto tg3_tso_bug_end; |
| 6827 | |
| 6828 | do { |
| 6829 | nskb = segs; |
| 6830 | segs = segs->next; |
| 6831 | nskb->next = NULL; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6832 | tg3_start_xmit(nskb, tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6833 | } while (segs); |
| 6834 | |
| 6835 | tg3_tso_bug_end: |
| 6836 | dev_kfree_skb(skb); |
| 6837 | |
| 6838 | return NETDEV_TX_OK; |
| 6839 | } |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6840 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 6841 | /* 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] | 6842 | * support TG3_FLAG_HW_TSO_1 or firmware TSO only. |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 6843 | */ |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6844 | 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] | 6845 | { |
| 6846 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6847 | u32 len, entry, base_flags, mss, vlan = 0; |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6848 | u32 budget; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6849 | int i = -1, would_hit_hwbug; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 6850 | dma_addr_t mapping; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6851 | struct tg3_napi *tnapi; |
| 6852 | struct netdev_queue *txq; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6853 | unsigned int last; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6854 | |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6855 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 6856 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6857 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6858 | tnapi++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6859 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6860 | budget = tg3_tx_avail(tnapi); |
| 6861 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 6862 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6863 | * 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] | 6864 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 6865 | * no IRQ context deadlocks to worry about either. Rejoice! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6866 | */ |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6867 | if (unlikely(budget <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6868 | if (!netif_tx_queue_stopped(txq)) { |
| 6869 | netif_tx_stop_queue(txq); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 6870 | |
| 6871 | /* This is a hard error, log it. */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 6872 | netdev_err(dev, |
| 6873 | "BUG! Tx Ring full when queue awake!\n"); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 6874 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6875 | return NETDEV_TX_BUSY; |
| 6876 | } |
| 6877 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6878 | entry = tnapi->tx_prod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6879 | base_flags = 0; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 6880 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6881 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6882 | |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 6883 | mss = skb_shinfo(skb)->gso_size; |
| 6884 | if (mss) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 6885 | struct iphdr *iph; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 6886 | u32 tcp_opt_len, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6887 | |
| 6888 | if (skb_header_cloned(skb) && |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 6889 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 6890 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6891 | |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 6892 | iph = ip_hdr(skb); |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 6893 | tcp_opt_len = tcp_optlen(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6894 | |
Eric Dumazet | a5a1195 | 2012-01-23 01:22:09 +0000 | [diff] [blame] | 6895 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb) - ETH_HLEN; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 6896 | |
Eric Dumazet | a5a1195 | 2012-01-23 01:22:09 +0000 | [diff] [blame] | 6897 | if (!skb_is_gso_v6(skb)) { |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 6898 | iph->check = 0; |
| 6899 | iph->tot_len = htons(mss + hdr_len); |
| 6900 | } |
| 6901 | |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6902 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6903 | tg3_flag(tp, TSO_BUG)) |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 6904 | return tg3_tso_bug(tp, skb); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6906 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 6907 | TXD_FLAG_CPU_POST_DMA); |
| 6908 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6909 | if (tg3_flag(tp, HW_TSO_1) || |
| 6910 | tg3_flag(tp, HW_TSO_2) || |
| 6911 | tg3_flag(tp, HW_TSO_3)) { |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 6912 | tcp_hdr(skb)->check = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6913 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 6914 | } else |
| 6915 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6916 | iph->daddr, 0, |
| 6917 | IPPROTO_TCP, |
| 6918 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6919 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6920 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 6921 | mss |= (hdr_len & 0xc) << 12; |
| 6922 | if (hdr_len & 0x10) |
| 6923 | base_flags |= 0x00000010; |
| 6924 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6925 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 6926 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6927 | else if (tg3_flag(tp, HW_TSO_1) || |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 6928 | 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] | 6929 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6930 | int tsflags; |
| 6931 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 6932 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6933 | mss |= (tsflags << 11); |
| 6934 | } |
| 6935 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 6936 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6937 | int tsflags; |
| 6938 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 6939 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6940 | base_flags |= tsflags << 12; |
| 6941 | } |
| 6942 | } |
| 6943 | } |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 6944 | |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 6945 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 6946 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
| 6947 | base_flags |= TXD_FLAG_JMB_PKT; |
| 6948 | |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6949 | if (vlan_tx_tag_present(skb)) { |
| 6950 | base_flags |= TXD_FLAG_VLAN; |
| 6951 | vlan = vlan_tx_tag_get(skb); |
| 6952 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6953 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6954 | len = skb_headlen(skb); |
| 6955 | |
| 6956 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 6957 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 6958 | goto drop; |
| 6959 | |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 6960 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6961 | tnapi->tx_buffers[entry].skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6962 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6963 | |
| 6964 | would_hit_hwbug = 0; |
| 6965 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6966 | if (tg3_flag(tp, 5701_DMA_BUG)) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6967 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6968 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6969 | if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, len, base_flags | |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6970 | ((skb_shinfo(skb)->nr_frags == 0) ? TXD_FLAG_END : 0), |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 6971 | mss, vlan)) { |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6972 | would_hit_hwbug = 1; |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 6973 | } else if (skb_shinfo(skb)->nr_frags > 0) { |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6974 | u32 tmp_mss = mss; |
| 6975 | |
| 6976 | if (!tg3_flag(tp, HW_TSO_1) && |
| 6977 | !tg3_flag(tp, HW_TSO_2) && |
| 6978 | !tg3_flag(tp, HW_TSO_3)) |
| 6979 | tmp_mss = 0; |
| 6980 | |
Matt Carlson | c5665a5 | 2012-02-13 10:20:12 +0000 | [diff] [blame] | 6981 | /* Now loop through additional data |
| 6982 | * fragments, and queue them. |
| 6983 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6984 | last = skb_shinfo(skb)->nr_frags - 1; |
| 6985 | for (i = 0; i <= last; i++) { |
| 6986 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 6987 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6988 | len = skb_frag_size(frag); |
Ian Campbell | dc234d0 | 2011-08-24 22:28:11 +0000 | [diff] [blame] | 6989 | mapping = skb_frag_dma_map(&tp->pdev->dev, frag, 0, |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 6990 | len, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6991 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6992 | tnapi->tx_buffers[entry].skb = NULL; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6993 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6994 | mapping); |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 6995 | if (dma_mapping_error(&tp->pdev->dev, mapping)) |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6996 | goto dma_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6997 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6998 | if (!budget || |
| 6999 | tg3_tx_frag_set(tnapi, &entry, &budget, mapping, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7000 | len, base_flags | |
| 7001 | ((i == last) ? TXD_FLAG_END : 0), |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7002 | tmp_mss, vlan)) { |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 7003 | would_hit_hwbug = 1; |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7004 | break; |
| 7005 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7006 | } |
| 7007 | } |
| 7008 | |
| 7009 | if (would_hit_hwbug) { |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7010 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7011 | |
| 7012 | /* If the workaround fails due to memory/mapping |
| 7013 | * failure, silently drop this packet. |
| 7014 | */ |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7015 | entry = tnapi->tx_prod; |
| 7016 | budget = tg3_tx_avail(tnapi); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7017 | if (tigon3_dma_hwbug_workaround(tnapi, &skb, &entry, &budget, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7018 | base_flags, mss, vlan)) |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7019 | goto drop_nofree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7020 | } |
| 7021 | |
Richard Cochran | d515b45 | 2011-06-19 03:31:41 +0000 | [diff] [blame] | 7022 | skb_tx_timestamp(skb); |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 7023 | netdev_tx_sent_queue(txq, skb->len); |
Richard Cochran | d515b45 | 2011-06-19 03:31:41 +0000 | [diff] [blame] | 7024 | |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 7025 | /* Sync BD data before updating mailbox */ |
| 7026 | wmb(); |
| 7027 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7028 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7029 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7030 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7031 | tnapi->tx_prod = entry; |
| 7032 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7033 | netif_tx_stop_queue(txq); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 7034 | |
| 7035 | /* netif_tx_stop_queue() must be done before checking |
| 7036 | * checking tx index in tg3_tx_avail() below, because in |
| 7037 | * tg3_tx(), we update tx index before checking for |
| 7038 | * netif_tx_queue_stopped(). |
| 7039 | */ |
| 7040 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7041 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7042 | netif_tx_wake_queue(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 7043 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7044 | |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 7045 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7046 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7047 | |
| 7048 | dma_error: |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7049 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, --i); |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7050 | tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7051 | drop: |
| 7052 | dev_kfree_skb(skb); |
| 7053 | drop_nofree: |
| 7054 | tp->tx_dropped++; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7055 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7056 | } |
| 7057 | |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7058 | static void tg3_mac_loopback(struct tg3 *tp, bool enable) |
| 7059 | { |
| 7060 | if (enable) { |
| 7061 | tp->mac_mode &= ~(MAC_MODE_HALF_DUPLEX | |
| 7062 | MAC_MODE_PORT_MODE_MASK); |
| 7063 | |
| 7064 | tp->mac_mode |= MAC_MODE_PORT_INT_LPBACK; |
| 7065 | |
| 7066 | if (!tg3_flag(tp, 5705_PLUS)) |
| 7067 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
| 7068 | |
| 7069 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 7070 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 7071 | else |
| 7072 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7073 | } else { |
| 7074 | tp->mac_mode &= ~MAC_MODE_PORT_INT_LPBACK; |
| 7075 | |
| 7076 | if (tg3_flag(tp, 5705_PLUS) || |
| 7077 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) || |
| 7078 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
| 7079 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 7080 | } |
| 7081 | |
| 7082 | tw32(MAC_MODE, tp->mac_mode); |
| 7083 | udelay(40); |
| 7084 | } |
| 7085 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7086 | static int tg3_phy_lpbk_set(struct tg3 *tp, u32 speed, bool extlpbk) |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7087 | { |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7088 | u32 val, bmcr, mac_mode, ptest = 0; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7089 | |
| 7090 | tg3_phy_toggle_apd(tp, false); |
| 7091 | tg3_phy_toggle_automdix(tp, 0); |
| 7092 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7093 | if (extlpbk && tg3_phy_set_extloopbk(tp)) |
| 7094 | return -EIO; |
| 7095 | |
| 7096 | bmcr = BMCR_FULLDPLX; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7097 | switch (speed) { |
| 7098 | case SPEED_10: |
| 7099 | break; |
| 7100 | case SPEED_100: |
| 7101 | bmcr |= BMCR_SPEED100; |
| 7102 | break; |
| 7103 | case SPEED_1000: |
| 7104 | default: |
| 7105 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 7106 | speed = SPEED_100; |
| 7107 | bmcr |= BMCR_SPEED100; |
| 7108 | } else { |
| 7109 | speed = SPEED_1000; |
| 7110 | bmcr |= BMCR_SPEED1000; |
| 7111 | } |
| 7112 | } |
| 7113 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7114 | if (extlpbk) { |
| 7115 | if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 7116 | tg3_readphy(tp, MII_CTRL1000, &val); |
| 7117 | val |= CTL1000_AS_MASTER | |
| 7118 | CTL1000_ENABLE_MASTER; |
| 7119 | tg3_writephy(tp, MII_CTRL1000, val); |
| 7120 | } else { |
| 7121 | ptest = MII_TG3_FET_PTEST_TRIM_SEL | |
| 7122 | MII_TG3_FET_PTEST_TRIM_2; |
| 7123 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest); |
| 7124 | } |
| 7125 | } else |
| 7126 | bmcr |= BMCR_LOOPBACK; |
| 7127 | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7128 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 7129 | |
| 7130 | /* The write needs to be flushed for the FETs */ |
| 7131 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 7132 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 7133 | |
| 7134 | udelay(40); |
| 7135 | |
| 7136 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
| 7137 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7138 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7139 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
| 7140 | MII_TG3_FET_PTEST_FRC_TX_LOCK); |
| 7141 | |
| 7142 | /* The write needs to be flushed for the AC131 */ |
| 7143 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); |
| 7144 | } |
| 7145 | |
| 7146 | /* Reset to prevent losing 1st rx packet intermittently */ |
| 7147 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
| 7148 | tg3_flag(tp, 5780_CLASS)) { |
| 7149 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 7150 | udelay(10); |
| 7151 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 7152 | } |
| 7153 | |
| 7154 | mac_mode = tp->mac_mode & |
| 7155 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 7156 | if (speed == SPEED_1000) |
| 7157 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7158 | else |
| 7159 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 7160 | |
| 7161 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
| 7162 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
| 7163 | |
| 7164 | if (masked_phy_id == TG3_PHY_ID_BCM5401) |
| 7165 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 7166 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
| 7167 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 7168 | |
| 7169 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 7170 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 7171 | } |
| 7172 | |
| 7173 | tw32(MAC_MODE, mac_mode); |
| 7174 | udelay(40); |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7175 | |
| 7176 | return 0; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7177 | } |
| 7178 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7179 | static void tg3_set_loopback(struct net_device *dev, netdev_features_t features) |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7180 | { |
| 7181 | struct tg3 *tp = netdev_priv(dev); |
| 7182 | |
| 7183 | if (features & NETIF_F_LOOPBACK) { |
| 7184 | if (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK) |
| 7185 | return; |
| 7186 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7187 | spin_lock_bh(&tp->lock); |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7188 | tg3_mac_loopback(tp, true); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7189 | netif_carrier_on(tp->dev); |
| 7190 | spin_unlock_bh(&tp->lock); |
| 7191 | netdev_info(dev, "Internal MAC loopback mode enabled.\n"); |
| 7192 | } else { |
| 7193 | if (!(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
| 7194 | return; |
| 7195 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7196 | spin_lock_bh(&tp->lock); |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7197 | tg3_mac_loopback(tp, false); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7198 | /* Force link status check */ |
| 7199 | tg3_setup_phy(tp, 1); |
| 7200 | spin_unlock_bh(&tp->lock); |
| 7201 | netdev_info(dev, "Internal MAC loopback mode disabled.\n"); |
| 7202 | } |
| 7203 | } |
| 7204 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7205 | static netdev_features_t tg3_fix_features(struct net_device *dev, |
| 7206 | netdev_features_t features) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 7207 | { |
| 7208 | struct tg3 *tp = netdev_priv(dev); |
| 7209 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7210 | if (dev->mtu > ETH_DATA_LEN && tg3_flag(tp, 5780_CLASS)) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 7211 | features &= ~NETIF_F_ALL_TSO; |
| 7212 | |
| 7213 | return features; |
| 7214 | } |
| 7215 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7216 | static int tg3_set_features(struct net_device *dev, netdev_features_t features) |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7217 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7218 | netdev_features_t changed = dev->features ^ features; |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7219 | |
| 7220 | if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) |
| 7221 | tg3_set_loopback(dev, features); |
| 7222 | |
| 7223 | return 0; |
| 7224 | } |
| 7225 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7226 | static void tg3_rx_prodring_free(struct tg3 *tp, |
| 7227 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7228 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7229 | int i; |
| 7230 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7231 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7232 | 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] | 7233 | i = (i + 1) & tp->rx_std_ring_mask) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7234 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7235 | tp->rx_pkt_map_sz); |
| 7236 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7237 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7238 | for (i = tpr->rx_jmb_cons_idx; |
| 7239 | i != tpr->rx_jmb_prod_idx; |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7240 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7241 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7242 | TG3_RX_JMB_MAP_SZ); |
| 7243 | } |
| 7244 | } |
| 7245 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7246 | return; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7248 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7249 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7250 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7251 | tp->rx_pkt_map_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7252 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7253 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7254 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7255 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7256 | TG3_RX_JMB_MAP_SZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7257 | } |
| 7258 | } |
| 7259 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 7260 | /* Initialize rx rings for packet processing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7261 | * |
| 7262 | * The chip has been shut down and the driver detached from |
| 7263 | * the networking, so no interrupts or new tx packets will |
| 7264 | * end up in the driver. tp->{tx,}lock are held and thus |
| 7265 | * we may not sleep. |
| 7266 | */ |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7267 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
| 7268 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7269 | { |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7270 | u32 i, rx_pkt_dma_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7271 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7272 | tpr->rx_std_cons_idx = 0; |
| 7273 | tpr->rx_std_prod_idx = 0; |
| 7274 | tpr->rx_jmb_cons_idx = 0; |
| 7275 | tpr->rx_jmb_prod_idx = 0; |
| 7276 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7277 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7278 | memset(&tpr->rx_std_buffers[0], 0, |
| 7279 | TG3_RX_STD_BUFF_RING_SIZE(tp)); |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 7280 | if (tpr->rx_jmb_buffers) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7281 | memset(&tpr->rx_jmb_buffers[0], 0, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7282 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7283 | goto done; |
| 7284 | } |
| 7285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7286 | /* Zero out all descriptors. */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7287 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7288 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7289 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7290 | if (tg3_flag(tp, 5780_CLASS) && |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7291 | tp->dev->mtu > ETH_DATA_LEN) |
| 7292 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; |
| 7293 | 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] | 7294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7295 | /* Initialize invariants of the rings, we only set this |
| 7296 | * stuff once. This works because the card does not |
| 7297 | * write into the rx buffer posting rings. |
| 7298 | */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7299 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7300 | struct tg3_rx_buffer_desc *rxd; |
| 7301 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7302 | rxd = &tpr->rx_std[i]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7303 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7304 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
| 7305 | rxd->opaque = (RXD_OPAQUE_RING_STD | |
| 7306 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 7307 | } |
| 7308 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7309 | /* Now allocate fresh SKBs for each rx ring. */ |
| 7310 | for (i = 0; i < tp->rx_pending; i++) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 7311 | unsigned int frag_size; |
| 7312 | |
| 7313 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_STD, i, |
| 7314 | &frag_size) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7315 | netdev_warn(tp->dev, |
| 7316 | "Using a smaller RX standard ring. Only " |
| 7317 | "%d out of %d buffers were allocated " |
| 7318 | "successfully\n", i, tp->rx_pending); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7319 | if (i == 0) |
| 7320 | goto initfail; |
| 7321 | tp->rx_pending = i; |
| 7322 | break; |
| 7323 | } |
| 7324 | } |
| 7325 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7326 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7327 | goto done; |
| 7328 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7329 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7330 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7331 | if (!tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7332 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7333 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7334 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7335 | struct tg3_rx_buffer_desc *rxd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7336 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7337 | rxd = &tpr->rx_jmb[i].std; |
| 7338 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; |
| 7339 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | |
| 7340 | RXD_FLAG_JUMBO; |
| 7341 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | |
| 7342 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 7343 | } |
| 7344 | |
| 7345 | for (i = 0; i < tp->rx_jumbo_pending; i++) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 7346 | unsigned int frag_size; |
| 7347 | |
| 7348 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_JUMBO, i, |
| 7349 | &frag_size) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7350 | netdev_warn(tp->dev, |
| 7351 | "Using a smaller RX jumbo ring. Only %d " |
| 7352 | "out of %d buffers were allocated " |
| 7353 | "successfully\n", i, tp->rx_jumbo_pending); |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7354 | if (i == 0) |
| 7355 | goto initfail; |
| 7356 | tp->rx_jumbo_pending = i; |
| 7357 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7358 | } |
| 7359 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7360 | |
| 7361 | done: |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 7362 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7363 | |
| 7364 | initfail: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7365 | tg3_rx_prodring_free(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7366 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7367 | } |
| 7368 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7369 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
| 7370 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7371 | { |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7372 | kfree(tpr->rx_std_buffers); |
| 7373 | tpr->rx_std_buffers = NULL; |
| 7374 | kfree(tpr->rx_jmb_buffers); |
| 7375 | tpr->rx_jmb_buffers = NULL; |
| 7376 | if (tpr->rx_std) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7377 | dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
| 7378 | tpr->rx_std, tpr->rx_std_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7379 | tpr->rx_std = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7380 | } |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7381 | if (tpr->rx_jmb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7382 | dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
| 7383 | tpr->rx_jmb, tpr->rx_jmb_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7384 | tpr->rx_jmb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7385 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7386 | } |
| 7387 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7388 | static int tg3_rx_prodring_init(struct tg3 *tp, |
| 7389 | struct tg3_rx_prodring_set *tpr) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7390 | { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7391 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
| 7392 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7393 | if (!tpr->rx_std_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7394 | return -ENOMEM; |
| 7395 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7396 | tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
| 7397 | TG3_RX_STD_RING_BYTES(tp), |
| 7398 | &tpr->rx_std_mapping, |
| 7399 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7400 | if (!tpr->rx_std) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7401 | goto err_out; |
| 7402 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7403 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7404 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7405 | GFP_KERNEL); |
| 7406 | if (!tpr->rx_jmb_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7407 | goto err_out; |
| 7408 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7409 | tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
| 7410 | TG3_RX_JMB_RING_BYTES(tp), |
| 7411 | &tpr->rx_jmb_mapping, |
| 7412 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7413 | if (!tpr->rx_jmb) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7414 | goto err_out; |
| 7415 | } |
| 7416 | |
| 7417 | return 0; |
| 7418 | |
| 7419 | err_out: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7420 | tg3_rx_prodring_fini(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7421 | return -ENOMEM; |
| 7422 | } |
| 7423 | |
| 7424 | /* Free up pending packets in all rx/tx rings. |
| 7425 | * |
| 7426 | * The chip has been shut down and the driver detached from |
| 7427 | * the networking, so no interrupts or new tx packets will |
| 7428 | * end up in the driver. tp->{tx,}lock is not held and we are not |
| 7429 | * in an interrupt context and thus may sleep. |
| 7430 | */ |
| 7431 | static void tg3_free_rings(struct tg3 *tp) |
| 7432 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7433 | int i, j; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7434 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7435 | for (j = 0; j < tp->irq_cnt; j++) { |
| 7436 | struct tg3_napi *tnapi = &tp->napi[j]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7437 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7438 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
Matt Carlson | b28f642 | 2010-06-05 17:24:32 +0000 | [diff] [blame] | 7439 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7440 | if (!tnapi->tx_buffers) |
| 7441 | continue; |
| 7442 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7443 | for (i = 0; i < TG3_TX_RING_SIZE; i++) { |
| 7444 | struct sk_buff *skb = tnapi->tx_buffers[i].skb; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7445 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7446 | if (!skb) |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7447 | continue; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7448 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7449 | tg3_tx_skb_unmap(tnapi, i, |
| 7450 | skb_shinfo(skb)->nr_frags - 1); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7451 | |
| 7452 | dev_kfree_skb_any(skb); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7453 | } |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 7454 | netdev_tx_reset_queue(netdev_get_tx_queue(tp->dev, j)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7455 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7456 | } |
| 7457 | |
| 7458 | /* Initialize tx/rx rings for packet processing. |
| 7459 | * |
| 7460 | * The chip has been shut down and the driver detached from |
| 7461 | * the networking, so no interrupts or new tx packets will |
| 7462 | * end up in the driver. tp->{tx,}lock are held and thus |
| 7463 | * we may not sleep. |
| 7464 | */ |
| 7465 | static int tg3_init_rings(struct tg3 *tp) |
| 7466 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7467 | int i; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 7468 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7469 | /* Free up all the SKBs. */ |
| 7470 | tg3_free_rings(tp); |
| 7471 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7472 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7473 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7474 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7475 | tnapi->last_tag = 0; |
| 7476 | tnapi->last_irq_tag = 0; |
| 7477 | tnapi->hw_status->status = 0; |
| 7478 | tnapi->hw_status->status_tag = 0; |
| 7479 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7480 | |
| 7481 | tnapi->tx_prod = 0; |
| 7482 | tnapi->tx_cons = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7483 | if (tnapi->tx_ring) |
| 7484 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7485 | |
| 7486 | tnapi->rx_rcb_ptr = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7487 | if (tnapi->rx_rcb) |
| 7488 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7489 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7490 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7491 | tg3_free_rings(tp); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7492 | return -ENOMEM; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7493 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7494 | } |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 7495 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7496 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | /* |
| 7500 | * Must not be invoked with interrupt sources disabled and |
| 7501 | * the hardware shutdown down. |
| 7502 | */ |
| 7503 | static void tg3_free_consistent(struct tg3 *tp) |
| 7504 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7505 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7506 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7507 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7508 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7509 | |
| 7510 | if (tnapi->tx_ring) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7511 | dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7512 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
| 7513 | tnapi->tx_ring = NULL; |
| 7514 | } |
| 7515 | |
| 7516 | kfree(tnapi->tx_buffers); |
| 7517 | tnapi->tx_buffers = NULL; |
| 7518 | |
| 7519 | if (tnapi->rx_rcb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7520 | dma_free_coherent(&tp->pdev->dev, |
| 7521 | TG3_RX_RCB_RING_BYTES(tp), |
| 7522 | tnapi->rx_rcb, |
| 7523 | tnapi->rx_rcb_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7524 | tnapi->rx_rcb = NULL; |
| 7525 | } |
| 7526 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7527 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
| 7528 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7529 | if (tnapi->hw_status) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7530 | dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
| 7531 | tnapi->hw_status, |
| 7532 | tnapi->status_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7533 | tnapi->hw_status = NULL; |
| 7534 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7535 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7537 | if (tp->hw_stats) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7538 | dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
| 7539 | tp->hw_stats, tp->stats_mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7540 | tp->hw_stats = NULL; |
| 7541 | } |
| 7542 | } |
| 7543 | |
| 7544 | /* |
| 7545 | * Must not be invoked with interrupt sources disabled and |
| 7546 | * the hardware shutdown down. Can sleep. |
| 7547 | */ |
| 7548 | static int tg3_alloc_consistent(struct tg3 *tp) |
| 7549 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7550 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7551 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7552 | tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
| 7553 | sizeof(struct tg3_hw_stats), |
| 7554 | &tp->stats_mapping, |
| 7555 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7556 | if (!tp->hw_stats) |
| 7557 | goto err_out; |
| 7558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7559 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 7560 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7561 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7562 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7563 | struct tg3_hw_status *sblk; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7564 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7565 | tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
| 7566 | TG3_HW_STATUS_SIZE, |
| 7567 | &tnapi->status_mapping, |
| 7568 | GFP_KERNEL); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7569 | if (!tnapi->hw_status) |
| 7570 | goto err_out; |
| 7571 | |
| 7572 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7573 | sblk = tnapi->hw_status; |
| 7574 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7575 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
| 7576 | goto err_out; |
| 7577 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7578 | /* If multivector TSS is enabled, vector 0 does not handle |
| 7579 | * tx interrupts. Don't allocate any resources for it. |
| 7580 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7581 | if ((!i && !tg3_flag(tp, ENABLE_TSS)) || |
| 7582 | (i && tg3_flag(tp, ENABLE_TSS))) { |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 7583 | tnapi->tx_buffers = kzalloc( |
| 7584 | sizeof(struct tg3_tx_ring_info) * |
| 7585 | TG3_TX_RING_SIZE, GFP_KERNEL); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7586 | if (!tnapi->tx_buffers) |
| 7587 | goto err_out; |
| 7588 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7589 | tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, |
| 7590 | TG3_TX_RING_BYTES, |
| 7591 | &tnapi->tx_desc_mapping, |
| 7592 | GFP_KERNEL); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7593 | if (!tnapi->tx_ring) |
| 7594 | goto err_out; |
| 7595 | } |
| 7596 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7597 | /* |
| 7598 | * When RSS is enabled, the status block format changes |
| 7599 | * slightly. The "rx_jumbo_consumer", "reserved", |
| 7600 | * and "rx_mini_consumer" members get mapped to the |
| 7601 | * other three rx return ring producer indexes. |
| 7602 | */ |
| 7603 | switch (i) { |
| 7604 | default: |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 7605 | if (tg3_flag(tp, ENABLE_RSS)) { |
| 7606 | tnapi->rx_rcb_prod_idx = NULL; |
| 7607 | break; |
| 7608 | } |
| 7609 | /* Fall through */ |
| 7610 | case 1: |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7611 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
| 7612 | break; |
| 7613 | case 2: |
| 7614 | tnapi->rx_rcb_prod_idx = &sblk->rx_jumbo_consumer; |
| 7615 | break; |
| 7616 | case 3: |
| 7617 | tnapi->rx_rcb_prod_idx = &sblk->reserved; |
| 7618 | break; |
| 7619 | case 4: |
| 7620 | tnapi->rx_rcb_prod_idx = &sblk->rx_mini_consumer; |
| 7621 | break; |
| 7622 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7623 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7624 | /* |
| 7625 | * If multivector RSS is enabled, vector 0 does not handle |
| 7626 | * rx or tx interrupts. Don't allocate any resources for it. |
| 7627 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7628 | if (!i && tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7629 | continue; |
| 7630 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7631 | tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, |
| 7632 | TG3_RX_RCB_RING_BYTES(tp), |
| 7633 | &tnapi->rx_rcb_mapping, |
| 7634 | GFP_KERNEL); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7635 | if (!tnapi->rx_rcb) |
| 7636 | goto err_out; |
| 7637 | |
| 7638 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7639 | } |
| 7640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7641 | return 0; |
| 7642 | |
| 7643 | err_out: |
| 7644 | tg3_free_consistent(tp); |
| 7645 | return -ENOMEM; |
| 7646 | } |
| 7647 | |
| 7648 | #define MAX_WAIT_CNT 1000 |
| 7649 | |
| 7650 | /* To stop a block, clear the enable bit and poll till it |
| 7651 | * clears. tp->lock is held. |
| 7652 | */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7653 | 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] | 7654 | { |
| 7655 | unsigned int i; |
| 7656 | u32 val; |
| 7657 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7658 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7659 | switch (ofs) { |
| 7660 | case RCVLSC_MODE: |
| 7661 | case DMAC_MODE: |
| 7662 | case MBFREE_MODE: |
| 7663 | case BUFMGR_MODE: |
| 7664 | case MEMARB_MODE: |
| 7665 | /* We can't enable/disable these bits of the |
| 7666 | * 5705/5750, just say success. |
| 7667 | */ |
| 7668 | return 0; |
| 7669 | |
| 7670 | default: |
| 7671 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 7672 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7673 | } |
| 7674 | |
| 7675 | val = tr32(ofs); |
| 7676 | val &= ~enable_bit; |
| 7677 | tw32_f(ofs, val); |
| 7678 | |
| 7679 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 7680 | udelay(100); |
| 7681 | val = tr32(ofs); |
| 7682 | if ((val & enable_bit) == 0) |
| 7683 | break; |
| 7684 | } |
| 7685 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7686 | if (i == MAX_WAIT_CNT && !silent) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 7687 | dev_err(&tp->pdev->dev, |
| 7688 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", |
| 7689 | ofs, enable_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7690 | return -ENODEV; |
| 7691 | } |
| 7692 | |
| 7693 | return 0; |
| 7694 | } |
| 7695 | |
| 7696 | /* tp->lock is held. */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7697 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7698 | { |
| 7699 | int i, err; |
| 7700 | |
| 7701 | tg3_disable_ints(tp); |
| 7702 | |
| 7703 | tp->rx_mode &= ~RX_MODE_ENABLE; |
| 7704 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 7705 | udelay(10); |
| 7706 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7707 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
| 7708 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); |
| 7709 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); |
| 7710 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); |
| 7711 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); |
| 7712 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7713 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7714 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); |
| 7715 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); |
| 7716 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); |
| 7717 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); |
| 7718 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); |
| 7719 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); |
| 7720 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7721 | |
| 7722 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 7723 | tw32_f(MAC_MODE, tp->mac_mode); |
| 7724 | udelay(40); |
| 7725 | |
| 7726 | tp->tx_mode &= ~TX_MODE_ENABLE; |
| 7727 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 7728 | |
| 7729 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 7730 | udelay(100); |
| 7731 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) |
| 7732 | break; |
| 7733 | } |
| 7734 | if (i >= MAX_WAIT_CNT) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 7735 | dev_err(&tp->pdev->dev, |
| 7736 | "%s timed out, TX_MODE_ENABLE will not clear " |
| 7737 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 7738 | err |= -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7739 | } |
| 7740 | |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 7741 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7742 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
| 7743 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7744 | |
| 7745 | tw32(FTQ_RESET, 0xffffffff); |
| 7746 | tw32(FTQ_RESET, 0x00000000); |
| 7747 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7748 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
| 7749 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7750 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7751 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7752 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7753 | if (tnapi->hw_status) |
| 7754 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7755 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7757 | return err; |
| 7758 | } |
| 7759 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7760 | /* Save PCI command register before chip reset */ |
| 7761 | static void tg3_save_pci_state(struct tg3 *tp) |
| 7762 | { |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 7763 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7764 | } |
| 7765 | |
| 7766 | /* Restore PCI state after chip reset */ |
| 7767 | static void tg3_restore_pci_state(struct tg3 *tp) |
| 7768 | { |
| 7769 | u32 val; |
| 7770 | |
| 7771 | /* Re-enable indirect register accesses. */ |
| 7772 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 7773 | tp->misc_host_ctrl); |
| 7774 | |
| 7775 | /* Set MAX PCI retry to zero. */ |
| 7776 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); |
| 7777 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7778 | tg3_flag(tp, PCIX_MODE)) |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7779 | val |= PCISTATE_RETRY_SAME_DMA; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7780 | /* Allow reads and writes to the APE register and memory space. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7781 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7782 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 7783 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 7784 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7785 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
| 7786 | |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 7787 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7788 | |
Matt Carlson | 2c55a3d | 2011-11-28 09:41:04 +0000 | [diff] [blame] | 7789 | if (!tg3_flag(tp, PCI_EXPRESS)) { |
| 7790 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 7791 | tp->pci_cacheline_sz); |
| 7792 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 7793 | tp->pci_lat_timer); |
Michael Chan | 114342f | 2007-10-15 02:12:26 -0700 | [diff] [blame] | 7794 | } |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 7795 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7796 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7797 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 7798 | u16 pcix_cmd; |
| 7799 | |
| 7800 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 7801 | &pcix_cmd); |
| 7802 | pcix_cmd &= ~PCI_X_CMD_ERO; |
| 7803 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 7804 | pcix_cmd); |
| 7805 | } |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7806 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7807 | if (tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7808 | |
| 7809 | /* Chip reset on 5780 will reset MSI enable bit, |
| 7810 | * so need to restore it. |
| 7811 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7812 | if (tg3_flag(tp, USING_MSI)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7813 | u16 ctrl; |
| 7814 | |
| 7815 | pci_read_config_word(tp->pdev, |
| 7816 | tp->msi_cap + PCI_MSI_FLAGS, |
| 7817 | &ctrl); |
| 7818 | pci_write_config_word(tp->pdev, |
| 7819 | tp->msi_cap + PCI_MSI_FLAGS, |
| 7820 | ctrl | PCI_MSI_FLAGS_ENABLE); |
| 7821 | val = tr32(MSGINT_MODE); |
| 7822 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); |
| 7823 | } |
| 7824 | } |
| 7825 | } |
| 7826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7827 | /* tp->lock is held. */ |
| 7828 | static int tg3_chip_reset(struct tg3 *tp) |
| 7829 | { |
| 7830 | u32 val; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7831 | void (*write_op)(struct tg3 *, u32, u32); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7832 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7833 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 7834 | tg3_nvram_lock(tp); |
| 7835 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 7836 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
| 7837 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 7838 | /* No matching tg3_nvram_unlock() after this because |
| 7839 | * chip reset below will undo the nvram lock. |
| 7840 | */ |
| 7841 | tp->nvram_lock_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7842 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7843 | /* GRC_MISC_CFG core clock reset will clear the memory |
| 7844 | * enable bit in PCI register 4 and the MSI enable bit |
| 7845 | * on some chips, so we save relevant registers here. |
| 7846 | */ |
| 7847 | tg3_save_pci_state(tp); |
| 7848 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 7849 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7850 | tg3_flag(tp, 5755_PLUS)) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 7851 | tw32(GRC_FASTBOOT_PC, 0); |
| 7852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7853 | /* |
| 7854 | * We must avoid the readl() that normally takes place. |
| 7855 | * It locks machines, causes machine checks, and other |
| 7856 | * fun things. So, temporarily disable the 5701 |
| 7857 | * hardware workaround, while we do the reset. |
| 7858 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7859 | write_op = tp->write32; |
| 7860 | if (write_op == tg3_write_flush_reg32) |
| 7861 | tp->write32 = tg3_write32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7862 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7863 | /* Prevent the irq handler from reading or writing PCI registers |
| 7864 | * during chip reset when the memory enable bit in the PCI command |
| 7865 | * register may be cleared. The chip does not generate interrupt |
| 7866 | * at this time, but the irq handler may still be called due to irq |
| 7867 | * sharing or irqpoll. |
| 7868 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7869 | tg3_flag_set(tp, CHIP_RESETTING); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7870 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7871 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7872 | if (tnapi->hw_status) { |
| 7873 | tnapi->hw_status->status = 0; |
| 7874 | tnapi->hw_status->status_tag = 0; |
| 7875 | } |
| 7876 | tnapi->last_tag = 0; |
| 7877 | tnapi->last_irq_tag = 0; |
Michael Chan | b8fa2f3 | 2007-04-06 17:35:37 -0700 | [diff] [blame] | 7878 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7879 | smp_mb(); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7880 | |
| 7881 | for (i = 0; i < tp->irq_cnt; i++) |
| 7882 | synchronize_irq(tp->napi[i].irq_vec); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7883 | |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 7884 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 7885 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 7886 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 7887 | } |
| 7888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7889 | /* do the reset */ |
| 7890 | val = GRC_MISC_CFG_CORECLK_RESET; |
| 7891 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7892 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 7893 | /* Force PCIe 1.0a mode */ |
| 7894 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7895 | !tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 7896 | tr32(TG3_PCIE_PHY_TSTCTL) == |
| 7897 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) |
| 7898 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); |
| 7899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7900 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
| 7901 | tw32(GRC_MISC_CFG, (1 << 29)); |
| 7902 | val |= (1 << 29); |
| 7903 | } |
| 7904 | } |
| 7905 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 7906 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 7907 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
| 7908 | tw32(GRC_VCPU_EXT_CTRL, |
| 7909 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 7910 | } |
| 7911 | |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 7912 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7913 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, CPMU_PRESENT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7914 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 7915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7916 | tw32(GRC_MISC_CFG, val); |
| 7917 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7918 | /* restore 5701 hardware bug workaround write method */ |
| 7919 | tp->write32 = write_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7920 | |
| 7921 | /* Unfortunately, we have to delay before the PCI read back. |
| 7922 | * Some 575X chips even will not respond to a PCI cfg access |
| 7923 | * when the reset command is given to the chip. |
| 7924 | * |
| 7925 | * How do these hardware designers expect things to work |
| 7926 | * properly if the PCI write is posted for a long period |
| 7927 | * of time? It is always necessary to have some method by |
| 7928 | * which a register read back can occur to push the write |
| 7929 | * out which does the reset. |
| 7930 | * |
| 7931 | * For most tg3 variants the trick below was working. |
| 7932 | * Ho hum... |
| 7933 | */ |
| 7934 | udelay(120); |
| 7935 | |
| 7936 | /* Flush PCI posted writes. The normal MMIO registers |
| 7937 | * are inaccessible at this time so this is the only |
| 7938 | * way to make this reliably (actually, this is no longer |
| 7939 | * the case, see above). I tried to use indirect |
| 7940 | * register read/write but this upset some 5701 variants. |
| 7941 | */ |
| 7942 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); |
| 7943 | |
| 7944 | udelay(120); |
| 7945 | |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 7946 | if (tg3_flag(tp, PCI_EXPRESS) && pci_pcie_cap(tp->pdev)) { |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7947 | u16 val16; |
| 7948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7949 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
| 7950 | int i; |
| 7951 | u32 cfg_val; |
| 7952 | |
| 7953 | /* Wait for link training to complete. */ |
| 7954 | for (i = 0; i < 5000; i++) |
| 7955 | udelay(100); |
| 7956 | |
| 7957 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); |
| 7958 | pci_write_config_dword(tp->pdev, 0xc4, |
| 7959 | cfg_val | (1 << 15)); |
| 7960 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7961 | |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7962 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
| 7963 | pci_read_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 7964 | pci_pcie_cap(tp->pdev) + PCI_EXP_DEVCTL, |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7965 | &val16); |
| 7966 | val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN | |
| 7967 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 7968 | /* |
| 7969 | * Older PCIe devices only support the 128 byte |
| 7970 | * MPS setting. Enforce the restriction. |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7971 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7972 | if (!tg3_flag(tp, CPMU_PRESENT)) |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7973 | val16 &= ~PCI_EXP_DEVCTL_PAYLOAD; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7974 | pci_write_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 7975 | pci_pcie_cap(tp->pdev) + PCI_EXP_DEVCTL, |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7976 | val16); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7977 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7978 | /* Clear error status */ |
| 7979 | pci_write_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 7980 | pci_pcie_cap(tp->pdev) + PCI_EXP_DEVSTA, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7981 | PCI_EXP_DEVSTA_CED | |
| 7982 | PCI_EXP_DEVSTA_NFED | |
| 7983 | PCI_EXP_DEVSTA_FED | |
| 7984 | PCI_EXP_DEVSTA_URD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7985 | } |
| 7986 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7987 | tg3_restore_pci_state(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7988 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7989 | tg3_flag_clear(tp, CHIP_RESETTING); |
| 7990 | tg3_flag_clear(tp, ERROR_PROCESSED); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7991 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7992 | val = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7993 | if (tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 7994 | val = tr32(MEMARB_MODE); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7995 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7996 | |
| 7997 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { |
| 7998 | tg3_stop_fw(tp); |
| 7999 | tw32(0x5000, 0x400); |
| 8000 | } |
| 8001 | |
| 8002 | tw32(GRC_MODE, tp->grc_mode); |
| 8003 | |
| 8004 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 8005 | val = tr32(0xc4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8006 | |
| 8007 | tw32(0xc4, val | (1 << 15)); |
| 8008 | } |
| 8009 | |
| 8010 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && |
| 8011 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 8012 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
| 8013 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) |
| 8014 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
| 8015 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 8016 | } |
| 8017 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8018 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 8019 | tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8020 | val = tp->mac_mode; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8021 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 8022 | tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8023 | val = tp->mac_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8024 | } else |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8025 | val = 0; |
| 8026 | |
| 8027 | tw32_f(MAC_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8028 | udelay(40); |
| 8029 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 8030 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
| 8031 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 8032 | err = tg3_poll_fw(tp); |
| 8033 | if (err) |
| 8034 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8035 | |
Matt Carlson | 0a9140c | 2009-08-28 12:27:50 +0000 | [diff] [blame] | 8036 | tg3_mdio_start(tp); |
| 8037 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8038 | if (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8039 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 8040 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8041 | !tg3_flag(tp, 57765_PLUS)) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 8042 | val = tr32(0x7c00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8043 | |
| 8044 | tw32(0x7c00, val | (1 << 25)); |
| 8045 | } |
| 8046 | |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 8047 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 8048 | val = tr32(TG3_CPMU_CLCK_ORIDE); |
| 8049 | tw32(TG3_CPMU_CLCK_ORIDE, val & ~CPMU_CLCK_ORIDE_MAC_ORIDE_EN); |
| 8050 | } |
| 8051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8052 | /* Reprobe ASF enable state. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8053 | tg3_flag_clear(tp, ENABLE_ASF); |
| 8054 | tg3_flag_clear(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8055 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 8056 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 8057 | u32 nic_cfg; |
| 8058 | |
| 8059 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 8060 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8061 | tg3_flag_set(tp, ENABLE_ASF); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 8062 | tp->last_event_jiffies = jiffies; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8063 | if (tg3_flag(tp, 5750_PLUS)) |
| 8064 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8065 | } |
| 8066 | } |
| 8067 | |
| 8068 | return 0; |
| 8069 | } |
| 8070 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 8071 | static void tg3_get_nstats(struct tg3 *, struct rtnl_link_stats64 *); |
| 8072 | static void tg3_get_estats(struct tg3 *, struct tg3_ethtool_stats *); |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8074 | /* tp->lock is held. */ |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8075 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8076 | { |
| 8077 | int err; |
| 8078 | |
| 8079 | tg3_stop_fw(tp); |
| 8080 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8081 | tg3_write_sig_pre_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8082 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8083 | tg3_abort_hw(tp, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8084 | err = tg3_chip_reset(tp); |
| 8085 | |
Matt Carlson | daba2a6 | 2009-04-20 06:58:52 +0000 | [diff] [blame] | 8086 | __tg3_set_mac_addr(tp, 0); |
| 8087 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8088 | tg3_write_sig_legacy(tp, kind); |
| 8089 | tg3_write_sig_post_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8090 | |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8091 | if (tp->hw_stats) { |
| 8092 | /* Save the stats across chip resets... */ |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 8093 | tg3_get_nstats(tp, &tp->net_stats_prev); |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8094 | tg3_get_estats(tp, &tp->estats_prev); |
| 8095 | |
| 8096 | /* And make sure the next sample is new data */ |
| 8097 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 8098 | } |
| 8099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8100 | if (err) |
| 8101 | return err; |
| 8102 | |
| 8103 | return 0; |
| 8104 | } |
| 8105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8106 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
| 8107 | { |
| 8108 | struct tg3 *tp = netdev_priv(dev); |
| 8109 | struct sockaddr *addr = p; |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8110 | int err = 0, skip_mac_1 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8111 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 8112 | if (!is_valid_ether_addr(addr->sa_data)) |
Danny Kukawka | 504f9b5 | 2012-02-21 02:07:49 +0000 | [diff] [blame] | 8113 | return -EADDRNOTAVAIL; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 8114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8115 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 8116 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 8117 | if (!netif_running(dev)) |
| 8118 | return 0; |
| 8119 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8120 | if (tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8121 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 8122 | |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8123 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
| 8124 | addr0_low = tr32(MAC_ADDR_0_LOW); |
| 8125 | addr1_high = tr32(MAC_ADDR_1_HIGH); |
| 8126 | addr1_low = tr32(MAC_ADDR_1_LOW); |
| 8127 | |
| 8128 | /* Skip MAC addr 1 if ASF is using it. */ |
| 8129 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && |
| 8130 | !(addr1_high == 0 && addr1_low == 0)) |
| 8131 | skip_mac_1 = 1; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 8132 | } |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8133 | spin_lock_bh(&tp->lock); |
| 8134 | __tg3_set_mac_addr(tp, skip_mac_1); |
| 8135 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8136 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 8137 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8138 | } |
| 8139 | |
| 8140 | /* tp->lock is held. */ |
| 8141 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, |
| 8142 | dma_addr_t mapping, u32 maxlen_flags, |
| 8143 | u32 nic_addr) |
| 8144 | { |
| 8145 | tg3_write_mem(tp, |
| 8146 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 8147 | ((u64) mapping >> 32)); |
| 8148 | tg3_write_mem(tp, |
| 8149 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), |
| 8150 | ((u64) mapping & 0xffffffff)); |
| 8151 | tg3_write_mem(tp, |
| 8152 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), |
| 8153 | maxlen_flags); |
| 8154 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8155 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8156 | tg3_write_mem(tp, |
| 8157 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), |
| 8158 | nic_addr); |
| 8159 | } |
| 8160 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 8161 | 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] | 8162 | { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8163 | int i; |
| 8164 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8165 | if (!tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8166 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
| 8167 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); |
| 8168 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8169 | } else { |
| 8170 | tw32(HOSTCC_TXCOL_TICKS, 0); |
| 8171 | tw32(HOSTCC_TXMAX_FRAMES, 0); |
| 8172 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8173 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8174 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8175 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8176 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
| 8177 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); |
| 8178 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); |
| 8179 | } else { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8180 | tw32(HOSTCC_RXCOL_TICKS, 0); |
| 8181 | tw32(HOSTCC_RXMAX_FRAMES, 0); |
| 8182 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8183 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8184 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8185 | if (!tg3_flag(tp, 5705_PLUS)) { |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8186 | u32 val = ec->stats_block_coalesce_usecs; |
| 8187 | |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8188 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
| 8189 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); |
| 8190 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8191 | if (!netif_carrier_ok(tp->dev)) |
| 8192 | val = 0; |
| 8193 | |
| 8194 | tw32(HOSTCC_STAT_COAL_TICKS, val); |
| 8195 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8196 | |
| 8197 | for (i = 0; i < tp->irq_cnt - 1; i++) { |
| 8198 | u32 reg; |
| 8199 | |
| 8200 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; |
| 8201 | tw32(reg, ec->rx_coalesce_usecs); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8202 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
| 8203 | tw32(reg, ec->rx_max_coalesced_frames); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8204 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 8205 | tw32(reg, ec->rx_max_coalesced_frames_irq); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8206 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8207 | if (tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8208 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
| 8209 | tw32(reg, ec->tx_coalesce_usecs); |
| 8210 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; |
| 8211 | tw32(reg, ec->tx_max_coalesced_frames); |
| 8212 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 8213 | tw32(reg, ec->tx_max_coalesced_frames_irq); |
| 8214 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8215 | } |
| 8216 | |
| 8217 | for (; i < tp->irq_max - 1; i++) { |
| 8218 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8219 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8220 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8221 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8222 | if (tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8223 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 8224 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 8225 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 8226 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8227 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8229 | |
| 8230 | /* tp->lock is held. */ |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8231 | static void tg3_rings_reset(struct tg3 *tp) |
| 8232 | { |
| 8233 | int i; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8234 | u32 stblk, txrcb, rxrcb, limit; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8235 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 8236 | |
| 8237 | /* Disable all transmit rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8238 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8239 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8240 | else if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 3d37728 | 2010-10-14 10:37:39 +0000 | [diff] [blame] | 8241 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8242 | else if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8243 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8244 | else |
| 8245 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 8246 | |
| 8247 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 8248 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) |
| 8249 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 8250 | BDINFO_FLAGS_DISABLED); |
| 8251 | |
| 8252 | |
| 8253 | /* Disable all receive return rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8254 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8255 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8256 | else if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8257 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8258 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8259 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8260 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
| 8261 | else |
| 8262 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 8263 | |
| 8264 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 8265 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) |
| 8266 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 8267 | BDINFO_FLAGS_DISABLED); |
| 8268 | |
| 8269 | /* Disable interrupts */ |
| 8270 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 8271 | tp->napi[0].chk_msi_cnt = 0; |
| 8272 | tp->napi[0].last_rx_cons = 0; |
| 8273 | tp->napi[0].last_tx_cons = 0; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8274 | |
| 8275 | /* Zero mailbox registers. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8276 | if (tg3_flag(tp, SUPPORT_MSIX)) { |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 8277 | for (i = 1; i < tp->irq_max; i++) { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8278 | tp->napi[i].tx_prod = 0; |
| 8279 | tp->napi[i].tx_cons = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8280 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 8281 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8282 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
| 8283 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); |
Matt Carlson | 7f23073 | 2011-08-31 11:44:48 +0000 | [diff] [blame] | 8284 | tp->napi[i].chk_msi_cnt = 0; |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 8285 | tp->napi[i].last_rx_cons = 0; |
| 8286 | tp->napi[i].last_tx_cons = 0; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8287 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8288 | if (!tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 8289 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8290 | } else { |
| 8291 | tp->napi[0].tx_prod = 0; |
| 8292 | tp->napi[0].tx_cons = 0; |
| 8293 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 8294 | tw32_rx_mbox(tp->napi[0].consmbox, 0); |
| 8295 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8296 | |
| 8297 | /* Make sure the NIC-based send BD rings are disabled. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8298 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8299 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 8300 | for (i = 0; i < 16; i++) |
| 8301 | tw32_tx_mbox(mbox + i * 8, 0); |
| 8302 | } |
| 8303 | |
| 8304 | txrcb = NIC_SRAM_SEND_RCB; |
| 8305 | rxrcb = NIC_SRAM_RCV_RET_RCB; |
| 8306 | |
| 8307 | /* Clear status block in ram. */ |
| 8308 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8309 | |
| 8310 | /* Set status block DMA address */ |
| 8311 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 8312 | ((u64) tnapi->status_mapping >> 32)); |
| 8313 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 8314 | ((u64) tnapi->status_mapping & 0xffffffff)); |
| 8315 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8316 | if (tnapi->tx_ring) { |
| 8317 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 8318 | (TG3_TX_RING_SIZE << |
| 8319 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 8320 | NIC_SRAM_TX_BUFFER_DESC); |
| 8321 | txrcb += TG3_BDINFO_SIZE; |
| 8322 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8323 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8324 | if (tnapi->rx_rcb) { |
| 8325 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8326 | (tp->rx_ret_ring_mask + 1) << |
| 8327 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8328 | rxrcb += TG3_BDINFO_SIZE; |
| 8329 | } |
| 8330 | |
| 8331 | stblk = HOSTCC_STATBLCK_RING1; |
| 8332 | |
| 8333 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
| 8334 | u64 mapping = (u64)tnapi->status_mapping; |
| 8335 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); |
| 8336 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); |
| 8337 | |
| 8338 | /* Clear status block in ram. */ |
| 8339 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8340 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8341 | if (tnapi->tx_ring) { |
| 8342 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 8343 | (TG3_TX_RING_SIZE << |
| 8344 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 8345 | NIC_SRAM_TX_BUFFER_DESC); |
| 8346 | txrcb += TG3_BDINFO_SIZE; |
| 8347 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8348 | |
| 8349 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8350 | ((tp->rx_ret_ring_mask + 1) << |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8351 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
| 8352 | |
| 8353 | stblk += 8; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8354 | rxrcb += TG3_BDINFO_SIZE; |
| 8355 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8356 | } |
| 8357 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8358 | static void tg3_setup_rxbd_thresholds(struct tg3 *tp) |
| 8359 | { |
| 8360 | u32 val, bdcache_maxcnt, host_rep_thresh, nic_rep_thresh; |
| 8361 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8362 | if (!tg3_flag(tp, 5750_PLUS) || |
| 8363 | tg3_flag(tp, 5780_CLASS) || |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8364 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
Matt Carlson | 513aa6e | 2011-11-21 15:01:18 +0000 | [diff] [blame] | 8365 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 8366 | tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8367 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5700; |
| 8368 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 8369 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) |
| 8370 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5755; |
| 8371 | else |
| 8372 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5906; |
| 8373 | |
| 8374 | nic_rep_thresh = min(bdcache_maxcnt / 2, tp->rx_std_max_post); |
| 8375 | host_rep_thresh = max_t(u32, tp->rx_pending / 8, 1); |
| 8376 | |
| 8377 | val = min(nic_rep_thresh, host_rep_thresh); |
| 8378 | tw32(RCVBDI_STD_THRESH, val); |
| 8379 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8380 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8381 | tw32(STD_REPLENISH_LWM, bdcache_maxcnt); |
| 8382 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8383 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8384 | return; |
| 8385 | |
Matt Carlson | 513aa6e | 2011-11-21 15:01:18 +0000 | [diff] [blame] | 8386 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5700; |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8387 | |
| 8388 | host_rep_thresh = max_t(u32, tp->rx_jumbo_pending / 8, 1); |
| 8389 | |
| 8390 | val = min(bdcache_maxcnt / 2, host_rep_thresh); |
| 8391 | tw32(RCVBDI_JUMBO_THRESH, val); |
| 8392 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8393 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8394 | tw32(JMB_REPLENISH_LWM, bdcache_maxcnt); |
| 8395 | } |
| 8396 | |
Matt Carlson | ccd5ba9 | 2012-02-13 10:20:08 +0000 | [diff] [blame] | 8397 | static inline u32 calc_crc(unsigned char *buf, int len) |
| 8398 | { |
| 8399 | u32 reg; |
| 8400 | u32 tmp; |
| 8401 | int j, k; |
| 8402 | |
| 8403 | reg = 0xffffffff; |
| 8404 | |
| 8405 | for (j = 0; j < len; j++) { |
| 8406 | reg ^= buf[j]; |
| 8407 | |
| 8408 | for (k = 0; k < 8; k++) { |
| 8409 | tmp = reg & 0x01; |
| 8410 | |
| 8411 | reg >>= 1; |
| 8412 | |
| 8413 | if (tmp) |
| 8414 | reg ^= 0xedb88320; |
| 8415 | } |
| 8416 | } |
| 8417 | |
| 8418 | return ~reg; |
| 8419 | } |
| 8420 | |
| 8421 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) |
| 8422 | { |
| 8423 | /* accept or reject all multicast frames */ |
| 8424 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); |
| 8425 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); |
| 8426 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); |
| 8427 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); |
| 8428 | } |
| 8429 | |
| 8430 | static void __tg3_set_rx_mode(struct net_device *dev) |
| 8431 | { |
| 8432 | struct tg3 *tp = netdev_priv(dev); |
| 8433 | u32 rx_mode; |
| 8434 | |
| 8435 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
| 8436 | RX_MODE_KEEP_VLAN_TAG); |
| 8437 | |
| 8438 | #if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) |
| 8439 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
| 8440 | * flag clear. |
| 8441 | */ |
| 8442 | if (!tg3_flag(tp, ENABLE_ASF)) |
| 8443 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 8444 | #endif |
| 8445 | |
| 8446 | if (dev->flags & IFF_PROMISC) { |
| 8447 | /* Promiscuous mode. */ |
| 8448 | rx_mode |= RX_MODE_PROMISC; |
| 8449 | } else if (dev->flags & IFF_ALLMULTI) { |
| 8450 | /* Accept all multicast. */ |
| 8451 | tg3_set_multi(tp, 1); |
| 8452 | } else if (netdev_mc_empty(dev)) { |
| 8453 | /* Reject all multicast. */ |
| 8454 | tg3_set_multi(tp, 0); |
| 8455 | } else { |
| 8456 | /* Accept one or more multicast(s). */ |
| 8457 | struct netdev_hw_addr *ha; |
| 8458 | u32 mc_filter[4] = { 0, }; |
| 8459 | u32 regidx; |
| 8460 | u32 bit; |
| 8461 | u32 crc; |
| 8462 | |
| 8463 | netdev_for_each_mc_addr(ha, dev) { |
| 8464 | crc = calc_crc(ha->addr, ETH_ALEN); |
| 8465 | bit = ~crc & 0x7f; |
| 8466 | regidx = (bit & 0x60) >> 5; |
| 8467 | bit &= 0x1f; |
| 8468 | mc_filter[regidx] |= (1 << bit); |
| 8469 | } |
| 8470 | |
| 8471 | tw32(MAC_HASH_REG_0, mc_filter[0]); |
| 8472 | tw32(MAC_HASH_REG_1, mc_filter[1]); |
| 8473 | tw32(MAC_HASH_REG_2, mc_filter[2]); |
| 8474 | tw32(MAC_HASH_REG_3, mc_filter[3]); |
| 8475 | } |
| 8476 | |
| 8477 | if (rx_mode != tp->rx_mode) { |
| 8478 | tp->rx_mode = rx_mode; |
| 8479 | tw32_f(MAC_RX_MODE, rx_mode); |
| 8480 | udelay(10); |
| 8481 | } |
| 8482 | } |
| 8483 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8484 | static void tg3_rss_init_dflt_indir_tbl(struct tg3 *tp) |
| 8485 | { |
| 8486 | int i; |
| 8487 | |
| 8488 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 8489 | tp->rss_ind_tbl[i] = |
| 8490 | ethtool_rxfh_indir_default(i, tp->irq_cnt - 1); |
| 8491 | } |
| 8492 | |
| 8493 | static void tg3_rss_check_indir_tbl(struct tg3 *tp) |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8494 | { |
| 8495 | int i; |
| 8496 | |
| 8497 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 8498 | return; |
| 8499 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8500 | if (tp->irq_cnt <= 2) { |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8501 | memset(&tp->rss_ind_tbl[0], 0, sizeof(tp->rss_ind_tbl)); |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8502 | return; |
| 8503 | } |
| 8504 | |
| 8505 | /* Validate table against current IRQ count */ |
| 8506 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { |
| 8507 | if (tp->rss_ind_tbl[i] >= tp->irq_cnt - 1) |
| 8508 | break; |
| 8509 | } |
| 8510 | |
| 8511 | if (i != TG3_RSS_INDIR_TBL_SIZE) |
| 8512 | tg3_rss_init_dflt_indir_tbl(tp); |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8513 | } |
| 8514 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8515 | static void tg3_rss_write_indir_tbl(struct tg3 *tp) |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8516 | { |
| 8517 | int i = 0; |
| 8518 | u32 reg = MAC_RSS_INDIR_TBL_0; |
| 8519 | |
| 8520 | while (i < TG3_RSS_INDIR_TBL_SIZE) { |
| 8521 | u32 val = tp->rss_ind_tbl[i]; |
| 8522 | i++; |
| 8523 | for (; i % 8; i++) { |
| 8524 | val <<= 4; |
| 8525 | val |= tp->rss_ind_tbl[i]; |
| 8526 | } |
| 8527 | tw32(reg, val); |
| 8528 | reg += 4; |
| 8529 | } |
| 8530 | } |
| 8531 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8532 | /* tp->lock is held. */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8533 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8534 | { |
| 8535 | u32 val, rdmac_mode; |
| 8536 | int i, err, limit; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 8537 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8538 | |
| 8539 | tg3_disable_ints(tp); |
| 8540 | |
| 8541 | tg3_stop_fw(tp); |
| 8542 | |
| 8543 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); |
| 8544 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8545 | if (tg3_flag(tp, INIT_COMPLETE)) |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 8546 | tg3_abort_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8547 | |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 8548 | /* Enable MAC control of LPI */ |
| 8549 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { |
| 8550 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, |
| 8551 | TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | |
| 8552 | TG3_CPMU_EEE_LNKIDL_UART_IDL); |
| 8553 | |
| 8554 | tw32_f(TG3_CPMU_EEE_CTRL, |
| 8555 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); |
| 8556 | |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 8557 | val = TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
| 8558 | TG3_CPMU_EEEMD_LPI_IN_TX | |
| 8559 | TG3_CPMU_EEEMD_LPI_IN_RX | |
| 8560 | TG3_CPMU_EEEMD_EEE_ENABLE; |
| 8561 | |
| 8562 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
| 8563 | val |= TG3_CPMU_EEEMD_SND_IDX_DET_EN; |
| 8564 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8565 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 8566 | val |= TG3_CPMU_EEEMD_APE_TX_DET_EN; |
| 8567 | |
| 8568 | tw32_f(TG3_CPMU_EEE_MODE, val); |
| 8569 | |
| 8570 | tw32_f(TG3_CPMU_EEE_DBTMR1, |
| 8571 | TG3_CPMU_DBTMR1_PCIEXIT_2047US | |
| 8572 | TG3_CPMU_DBTMR1_LNKIDLE_2047US); |
| 8573 | |
| 8574 | tw32_f(TG3_CPMU_EEE_DBTMR2, |
Matt Carlson | d7f2ab2 | 2011-01-25 15:58:56 +0000 | [diff] [blame] | 8575 | TG3_CPMU_DBTMR2_APE_TX_2047US | |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 8576 | TG3_CPMU_DBTMR2_TXIDXEQ_2047US); |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 8577 | } |
| 8578 | |
Matt Carlson | 603f117 | 2010-02-12 14:47:10 +0000 | [diff] [blame] | 8579 | if (reset_phy) |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 8580 | tg3_phy_reset(tp); |
| 8581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8582 | err = tg3_chip_reset(tp); |
| 8583 | if (err) |
| 8584 | return err; |
| 8585 | |
| 8586 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); |
| 8587 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 8588 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8589 | val = tr32(TG3_CPMU_CTRL); |
| 8590 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); |
| 8591 | tw32(TG3_CPMU_CTRL, val); |
Matt Carlson | 9acb961 | 2007-11-12 21:10:06 -0800 | [diff] [blame] | 8592 | |
| 8593 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 8594 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 8595 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 8596 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 8597 | |
| 8598 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); |
| 8599 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; |
| 8600 | val |= CPMU_LNK_AWARE_MACCLK_6_25; |
| 8601 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); |
| 8602 | |
| 8603 | val = tr32(TG3_CPMU_HST_ACC); |
| 8604 | val &= ~CPMU_HST_ACC_MACCLK_MASK; |
| 8605 | val |= CPMU_HST_ACC_MACCLK_6_25; |
| 8606 | tw32(TG3_CPMU_HST_ACC, val); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8607 | } |
| 8608 | |
Matt Carlson | 33466d93 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 8609 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 8610 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 8611 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | |
| 8612 | PCIE_PWR_MGMT_L1_THRESH_4MS; |
| 8613 | tw32(PCIE_PWR_MGMT_THRESH, val); |
Matt Carlson | 521e6b9 | 2009-08-25 10:06:01 +0000 | [diff] [blame] | 8614 | |
| 8615 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; |
| 8616 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); |
| 8617 | |
| 8618 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); |
Matt Carlson | 33466d93 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 8619 | |
Matt Carlson | f40386c | 2009-11-02 14:24:02 +0000 | [diff] [blame] | 8620 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 8621 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 8622 | } |
| 8623 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8624 | if (tg3_flag(tp, L1PLLPD_EN)) { |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 8625 | u32 grc_mode = tr32(GRC_MODE); |
| 8626 | |
| 8627 | /* Access the lower 1K of PL PCIE block registers. */ |
| 8628 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 8629 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 8630 | |
| 8631 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); |
| 8632 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, |
| 8633 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); |
| 8634 | |
| 8635 | tw32(GRC_MODE, grc_mode); |
| 8636 | } |
| 8637 | |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8638 | if (tg3_flag(tp, 57765_CLASS)) { |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8639 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 8640 | u32 grc_mode = tr32(GRC_MODE); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8641 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8642 | /* Access the lower 1K of PL PCIE block registers. */ |
| 8643 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 8644 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8645 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8646 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 8647 | TG3_PCIE_PL_LO_PHYCTL5); |
| 8648 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, |
| 8649 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8650 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8651 | tw32(GRC_MODE, grc_mode); |
| 8652 | } |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 8653 | |
Matt Carlson | 1ff30a5 | 2011-05-19 12:12:46 +0000 | [diff] [blame] | 8654 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_57765_AX) { |
| 8655 | u32 grc_mode = tr32(GRC_MODE); |
| 8656 | |
| 8657 | /* Access the lower 1K of DL PCIE block registers. */ |
| 8658 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 8659 | tw32(GRC_MODE, val | GRC_MODE_PCIE_DL_SEL); |
| 8660 | |
| 8661 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 8662 | TG3_PCIE_DL_LO_FTSMAX); |
| 8663 | val &= ~TG3_PCIE_DL_LO_FTSMAX_MSK; |
| 8664 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_DL_LO_FTSMAX, |
| 8665 | val | TG3_PCIE_DL_LO_FTSMAX_VAL); |
| 8666 | |
| 8667 | tw32(GRC_MODE, grc_mode); |
| 8668 | } |
| 8669 | |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 8670 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 8671 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 8672 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 8673 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8674 | } |
| 8675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8676 | /* This works around an issue with Athlon chipsets on |
| 8677 | * B3 tigon3 silicon. This bit has no effect on any |
| 8678 | * other revision. But do not set this on PCI Express |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 8679 | * 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] | 8680 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8681 | if (!tg3_flag(tp, CPMU_PRESENT)) { |
| 8682 | if (!tg3_flag(tp, PCI_EXPRESS)) |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 8683 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
| 8684 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 8685 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8686 | |
| 8687 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8688 | tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8689 | val = tr32(TG3PCI_PCISTATE); |
| 8690 | val |= PCISTATE_RETRY_SAME_DMA; |
| 8691 | tw32(TG3PCI_PCISTATE, val); |
| 8692 | } |
| 8693 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8694 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8695 | /* Allow reads and writes to the |
| 8696 | * APE register and memory space. |
| 8697 | */ |
| 8698 | val = tr32(TG3PCI_PCISTATE); |
| 8699 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 8700 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 8701 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8702 | tw32(TG3PCI_PCISTATE, val); |
| 8703 | } |
| 8704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8705 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
| 8706 | /* Enable some hw fixes. */ |
| 8707 | val = tr32(TG3PCI_MSI_DATA); |
| 8708 | val |= (1 << 26) | (1 << 28) | (1 << 29); |
| 8709 | tw32(TG3PCI_MSI_DATA, val); |
| 8710 | } |
| 8711 | |
| 8712 | /* Descriptor ring init may make accesses to the |
| 8713 | * NIC SRAM area to setup the TX descriptors, so we |
| 8714 | * can only do this after the hardware has been |
| 8715 | * successfully reset. |
| 8716 | */ |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 8717 | err = tg3_init_rings(tp); |
| 8718 | if (err) |
| 8719 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8720 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8721 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 8722 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
| 8723 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
Matt Carlson | 1a31902 | 2010-04-12 06:58:25 +0000 | [diff] [blame] | 8724 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
| 8725 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8726 | if (!tg3_flag(tp, 57765_CLASS) && |
Matt Carlson | 0aebff4 | 2011-04-25 12:42:45 +0000 | [diff] [blame] | 8727 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
| 8728 | val |= DMA_RWCTRL_TAGGED_STAT_WA; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 8729 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
| 8730 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && |
| 8731 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8732 | /* This value is determined during the probe time DMA |
| 8733 | * engine test, tg3_test_dma. |
| 8734 | */ |
| 8735 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 8736 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8737 | |
| 8738 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | |
| 8739 | GRC_MODE_4X_NIC_SEND_RINGS | |
| 8740 | GRC_MODE_NO_TX_PHDR_CSUM | |
| 8741 | GRC_MODE_NO_RX_PHDR_CSUM); |
| 8742 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; |
Michael Chan | d2d746f | 2006-04-06 21:45:39 -0700 | [diff] [blame] | 8743 | |
| 8744 | /* Pseudo-header checksum is done by hardware logic and not |
| 8745 | * the offload processers, so make the chip do the pseudo- |
| 8746 | * header checksums on receive. For transmit it is more |
| 8747 | * convenient to do the pseudo-header checksum in software |
| 8748 | * as Linux does that on transmit for us in all cases. |
| 8749 | */ |
| 8750 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8751 | |
| 8752 | tw32(GRC_MODE, |
| 8753 | tp->grc_mode | |
| 8754 | (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP)); |
| 8755 | |
| 8756 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ |
| 8757 | val = tr32(GRC_MISC_CFG); |
| 8758 | val &= ~0xff; |
| 8759 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 8760 | tw32(GRC_MISC_CFG, val); |
| 8761 | |
| 8762 | /* Initialize MBUF/DESC pool. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8763 | if (tg3_flag(tp, 5750_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8764 | /* Do nothing. */ |
| 8765 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { |
| 8766 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
| 8767 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 8768 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
| 8769 | else |
| 8770 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); |
| 8771 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); |
| 8772 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8773 | } else if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8774 | int fw_len; |
| 8775 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 8776 | fw_len = tp->fw_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8777 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
| 8778 | tw32(BUFMGR_MB_POOL_ADDR, |
| 8779 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); |
| 8780 | tw32(BUFMGR_MB_POOL_SIZE, |
| 8781 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); |
| 8782 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8783 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 8784 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8785 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8786 | tp->bufmgr_config.mbuf_read_dma_low_water); |
| 8787 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 8788 | tp->bufmgr_config.mbuf_mac_rx_low_water); |
| 8789 | tw32(BUFMGR_MB_HIGH_WATER, |
| 8790 | tp->bufmgr_config.mbuf_high_water); |
| 8791 | } else { |
| 8792 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8793 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); |
| 8794 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 8795 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); |
| 8796 | tw32(BUFMGR_MB_HIGH_WATER, |
| 8797 | tp->bufmgr_config.mbuf_high_water_jumbo); |
| 8798 | } |
| 8799 | tw32(BUFMGR_DMA_LOW_WATER, |
| 8800 | tp->bufmgr_config.dma_low_water); |
| 8801 | tw32(BUFMGR_DMA_HIGH_WATER, |
| 8802 | tp->bufmgr_config.dma_high_water); |
| 8803 | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8804 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
| 8805 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 8806 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 8807 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 8808 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 8809 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) |
| 8810 | val |= BUFMGR_MODE_MBLOW_ATTN_ENAB; |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8811 | tw32(BUFMGR_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8812 | for (i = 0; i < 2000; i++) { |
| 8813 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) |
| 8814 | break; |
| 8815 | udelay(10); |
| 8816 | } |
| 8817 | if (i >= 2000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 8818 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8819 | return -ENODEV; |
| 8820 | } |
| 8821 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8822 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) |
| 8823 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 8824 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8825 | tg3_setup_rxbd_thresholds(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8826 | |
| 8827 | /* Initialize TG3_BDINFO's at: |
| 8828 | * RCVDBDI_STD_BD: standard eth size rx ring |
| 8829 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring |
| 8830 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) |
| 8831 | * |
| 8832 | * like so: |
| 8833 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring |
| 8834 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | |
| 8835 | * ring attribute flags |
| 8836 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM |
| 8837 | * |
| 8838 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. |
| 8839 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. |
| 8840 | * |
| 8841 | * The size of each ring is fixed in the firmware, but the location is |
| 8842 | * configurable. |
| 8843 | */ |
| 8844 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8845 | ((u64) tpr->rx_std_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8846 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8847 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8848 | if (!tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 8849 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
| 8850 | NIC_SRAM_RX_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8851 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8852 | /* Disable the mini ring */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8853 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8854 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 8855 | BDINFO_FLAGS_DISABLED); |
| 8856 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8857 | /* Program the jumbo buffer descriptor ring control |
| 8858 | * blocks on those devices that have them. |
| 8859 | */ |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 8860 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8861 | (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8862 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8863 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8864 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8865 | ((u64) tpr->rx_jmb_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8866 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8867 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8868 | val = TG3_RX_JMB_RING_SIZE(tp) << |
| 8869 | BDINFO_FLAGS_MAXLEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8870 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8871 | val | BDINFO_FLAGS_USE_EXT_RECV); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8872 | if (!tg3_flag(tp, USE_JUMBO_BDFLAG) || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8873 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 8874 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
| 8875 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8876 | } else { |
| 8877 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 8878 | BDINFO_FLAGS_DISABLED); |
| 8879 | } |
| 8880 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8881 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | fa6b2aa | 2011-11-21 15:01:19 +0000 | [diff] [blame] | 8882 | val = TG3_RX_STD_RING_SIZE(tp); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8883 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
| 8884 | val |= (TG3_RX_STD_DMA_SZ << 2); |
| 8885 | } else |
Matt Carlson | 04380d4 | 2010-04-12 06:58:29 +0000 | [diff] [blame] | 8886 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8887 | } else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 8888 | val = TG3_RX_STD_MAX_SIZE_5700 << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8889 | |
| 8890 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8891 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 8892 | tpr->rx_std_prod_idx = tp->rx_pending; |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 8893 | 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] | 8894 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8895 | tpr->rx_jmb_prod_idx = |
| 8896 | tg3_flag(tp, JUMBO_RING_ENABLE) ? tp->rx_jumbo_pending : 0; |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 8897 | 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] | 8898 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8899 | tg3_rings_reset(tp); |
| 8900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8901 | /* Initialize MAC address and backoff seed. */ |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8902 | __tg3_set_mac_addr(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8903 | |
| 8904 | /* MTU + ethernet header + FCS + optional VLAN tag */ |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 8905 | tw32(MAC_RX_MTU_SIZE, |
| 8906 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8907 | |
| 8908 | /* The slot time is changed by tg3_setup_phy if we |
| 8909 | * run at gigabit with half duplex. |
| 8910 | */ |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 8911 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 8912 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 8913 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT); |
| 8914 | |
| 8915 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 8916 | val |= tr32(MAC_TX_LENGTHS) & |
| 8917 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 8918 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 8919 | |
| 8920 | tw32(MAC_TX_LENGTHS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8921 | |
| 8922 | /* Receive rules. */ |
| 8923 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); |
| 8924 | tw32(RCVLPC_CONFIG, 0x0181); |
| 8925 | |
| 8926 | /* Calculate RDMAC_MODE setting early, we need it to determine |
| 8927 | * the RCVLPC_STATE_ENABLE mask. |
| 8928 | */ |
| 8929 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | |
| 8930 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | |
| 8931 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | |
| 8932 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | |
| 8933 | RDMAC_MODE_LNGREAD_ENAB); |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8934 | |
Matt Carlson | deabaac | 2010-11-24 08:31:50 +0000 | [diff] [blame] | 8935 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
Matt Carlson | 0339e4e | 2010-02-12 14:47:09 +0000 | [diff] [blame] | 8936 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
| 8937 | |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 8938 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8939 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 8940 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8941 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
| 8942 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | |
| 8943 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; |
| 8944 | |
Matt Carlson | c590893 | 2011-03-09 16:58:25 +0000 | [diff] [blame] | 8945 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 8946 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8947 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | c13e371 | 2007-05-05 11:50:04 -0700 | [diff] [blame] | 8948 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8949 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
| 8950 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8951 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8952 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 8953 | } |
| 8954 | } |
| 8955 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8956 | if (tg3_flag(tp, PCI_EXPRESS)) |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8957 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 8958 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8959 | if (tg3_flag(tp, HW_TSO_1) || |
| 8960 | tg3_flag(tp, HW_TSO_2) || |
| 8961 | tg3_flag(tp, HW_TSO_3)) |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 8962 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
| 8963 | |
Matt Carlson | 108a6c1 | 2011-05-19 12:12:47 +0000 | [diff] [blame] | 8964 | if (tg3_flag(tp, 57765_PLUS) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 8965 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 8966 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
| 8967 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8968 | |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 8969 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 8970 | rdmac_mode |= tr32(RDMAC_MODE) & RDMAC_MODE_H2BNC_VLAN_DET; |
| 8971 | |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8972 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 8973 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 8974 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 8975 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8976 | tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8977 | val = tr32(TG3_RDMA_RSRVCTRL_REG); |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 8978 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 8979 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | b4495ed | 2011-01-25 15:58:47 +0000 | [diff] [blame] | 8980 | val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | |
| 8981 | TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | |
| 8982 | TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); |
| 8983 | val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B | |
| 8984 | TG3_RDMA_RSRVCTRL_FIFO_LWM_1_5K | |
| 8985 | TG3_RDMA_RSRVCTRL_FIFO_HWM_1_5K; |
Matt Carlson | b75cc0e | 2010-11-24 08:31:46 +0000 | [diff] [blame] | 8986 | } |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8987 | tw32(TG3_RDMA_RSRVCTRL_REG, |
| 8988 | val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); |
| 8989 | } |
| 8990 | |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 8991 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 8992 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8993 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 8994 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val | |
| 8995 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | |
| 8996 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); |
| 8997 | } |
| 8998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8999 | /* Receive/send statistics. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9000 | if (tg3_flag(tp, 5750_PLUS)) { |
Michael Chan | 1661394 | 2006-06-29 20:15:13 -0700 | [diff] [blame] | 9001 | val = tr32(RCVLPC_STATS_ENABLE); |
| 9002 | val &= ~RCVLPC_STATSENAB_DACK_FIX; |
| 9003 | tw32(RCVLPC_STATS_ENABLE, val); |
| 9004 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9005 | tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9006 | val = tr32(RCVLPC_STATS_ENABLE); |
| 9007 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; |
| 9008 | tw32(RCVLPC_STATS_ENABLE, val); |
| 9009 | } else { |
| 9010 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); |
| 9011 | } |
| 9012 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); |
| 9013 | tw32(SNDDATAI_STATSENAB, 0xffffff); |
| 9014 | tw32(SNDDATAI_STATSCTRL, |
| 9015 | (SNDDATAI_SCTRL_ENABLE | |
| 9016 | SNDDATAI_SCTRL_FASTUPD)); |
| 9017 | |
| 9018 | /* Setup host coalescing engine. */ |
| 9019 | tw32(HOSTCC_MODE, 0); |
| 9020 | for (i = 0; i < 2000; i++) { |
| 9021 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) |
| 9022 | break; |
| 9023 | udelay(10); |
| 9024 | } |
| 9025 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 9026 | __tg3_set_coalesce(tp, &tp->coal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9027 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9028 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9029 | /* Status/statistics block address. See tg3_timer, |
| 9030 | * the tg3_periodic_fetch_stats call there, and |
| 9031 | * tg3_get_stats to see how this works for 5705/5750 chips. |
| 9032 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9033 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 9034 | ((u64) tp->stats_mapping >> 32)); |
| 9035 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 9036 | ((u64) tp->stats_mapping & 0xffffffff)); |
| 9037 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9039 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9040 | |
| 9041 | /* Clear statistics and status block memory areas */ |
| 9042 | for (i = NIC_SRAM_STATS_BLK; |
| 9043 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; |
| 9044 | i += sizeof(u32)) { |
| 9045 | tg3_write_mem(tp, i, 0); |
| 9046 | udelay(40); |
| 9047 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9048 | } |
| 9049 | |
| 9050 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); |
| 9051 | |
| 9052 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); |
| 9053 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9054 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9055 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
| 9056 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9057 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
| 9058 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 9059 | /* reset to prevent losing 1st rx packet intermittently */ |
| 9060 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 9061 | udelay(10); |
| 9062 | } |
| 9063 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 9064 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 9065 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | |
| 9066 | MAC_MODE_FHDE_ENABLE; |
| 9067 | if (tg3_flag(tp, ENABLE_APE)) |
| 9068 | tp->mac_mode |= MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9069 | if (!tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9070 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 9071 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
| 9072 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9073 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
| 9074 | udelay(40); |
| 9075 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9076 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9077 | * If TG3_FLAG_IS_NIC is zero, we should read the |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9078 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
| 9079 | * whether used as inputs or outputs, are set by boot code after |
| 9080 | * reset. |
| 9081 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9082 | if (!tg3_flag(tp, IS_NIC)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9083 | u32 gpio_mask; |
| 9084 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 9085 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
| 9086 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 9087 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 9088 | |
| 9089 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 9090 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
| 9091 | GRC_LCLCTRL_GPIO_OUTPUT3; |
| 9092 | |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 9093 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 9094 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 9095 | |
Gary Zambrano | aaf8446 | 2007-05-05 11:51:45 -0700 | [diff] [blame] | 9096 | tp->grc_local_ctrl &= ~gpio_mask; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9097 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
| 9098 | |
| 9099 | /* GPIO1 must be driven high for eeprom write protect */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9100 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 9101 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 9102 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9104 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 9105 | udelay(100); |
| 9106 | |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9107 | if (tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9108 | val = tr32(MSGINT_MODE); |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9109 | val |= MSGINT_MODE_ENABLE; |
| 9110 | if (tp->irq_cnt > 1) |
| 9111 | val |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 9112 | if (!tg3_flag(tp, 1SHOT_MSI)) |
| 9113 | val |= MSGINT_MODE_ONE_SHOT_DISABLE; |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9114 | tw32(MSGINT_MODE, val); |
| 9115 | } |
| 9116 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9117 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9118 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
| 9119 | udelay(40); |
| 9120 | } |
| 9121 | |
| 9122 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | |
| 9123 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | |
| 9124 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | |
| 9125 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | |
| 9126 | WDMAC_MODE_LNGREAD_ENAB); |
| 9127 | |
Matt Carlson | c590893 | 2011-03-09 16:58:25 +0000 | [diff] [blame] | 9128 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 9129 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9130 | if (tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9131 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
| 9132 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { |
| 9133 | /* nothing */ |
| 9134 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9135 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9136 | val |= WDMAC_MODE_RX_ACCEL; |
| 9137 | } |
| 9138 | } |
| 9139 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 9140 | /* Enable host coalescing bug fix */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9141 | if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 9142 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 9143 | |
Matt Carlson | 788a035 | 2009-11-02 14:26:03 +0000 | [diff] [blame] | 9144 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 9145 | val |= WDMAC_MODE_BURST_ALL_DATA; |
| 9146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9147 | tw32_f(WDMAC_MODE, val); |
| 9148 | udelay(40); |
| 9149 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9150 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9151 | u16 pcix_cmd; |
| 9152 | |
| 9153 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 9154 | &pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9155 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9156 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
| 9157 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9158 | } 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] | 9159 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
| 9160 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9161 | } |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9162 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 9163 | pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9164 | } |
| 9165 | |
| 9166 | tw32_f(RDMAC_MODE, rdmac_mode); |
| 9167 | udelay(40); |
| 9168 | |
| 9169 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9170 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9171 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 9172 | |
| 9173 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 9174 | tw32(SNDDATAC_MODE, |
| 9175 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); |
| 9176 | else |
| 9177 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); |
| 9178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9179 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
| 9180 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9181 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9182 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9183 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
| 9184 | tw32(RCVDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9185 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9186 | if (tg3_flag(tp, HW_TSO_1) || |
| 9187 | tg3_flag(tp, HW_TSO_2) || |
| 9188 | tg3_flag(tp, HW_TSO_3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9189 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9190 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9191 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9192 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
| 9193 | tw32(SNDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9194 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
| 9195 | |
| 9196 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 9197 | err = tg3_load_5701_a0_firmware_fix(tp); |
| 9198 | if (err) |
| 9199 | return err; |
| 9200 | } |
| 9201 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9202 | if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9203 | err = tg3_load_tso_firmware(tp); |
| 9204 | if (err) |
| 9205 | return err; |
| 9206 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9207 | |
| 9208 | tp->tx_mode = TX_MODE_ENABLE; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9209 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9210 | if (tg3_flag(tp, 5755_PLUS) || |
Matt Carlson | b1d0521 | 2010-06-05 17:24:31 +0000 | [diff] [blame] | 9211 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 9212 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9213 | |
| 9214 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 9215 | val = TX_MODE_JMB_FRM_LEN | TX_MODE_CNT_DN_MODE; |
| 9216 | tp->tx_mode &= ~val; |
| 9217 | tp->tx_mode |= tr32(MAC_TX_MODE) & val; |
| 9218 | } |
| 9219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9220 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 9221 | udelay(100); |
| 9222 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9223 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 9224 | tg3_rss_write_indir_tbl(tp); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9225 | |
| 9226 | /* Setup the "secret" hash key. */ |
| 9227 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); |
| 9228 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); |
| 9229 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); |
| 9230 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); |
| 9231 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); |
| 9232 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); |
| 9233 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); |
| 9234 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); |
| 9235 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); |
| 9236 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); |
| 9237 | } |
| 9238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9239 | tp->rx_mode = RX_MODE_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9240 | if (tg3_flag(tp, 5755_PLUS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 9241 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
| 9242 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9243 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9244 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
| 9245 | RX_MODE_RSS_ITBL_HASH_BITS_7 | |
| 9246 | RX_MODE_RSS_IPV6_HASH_EN | |
| 9247 | RX_MODE_RSS_TCP_IPV6_HASH_EN | |
| 9248 | RX_MODE_RSS_IPV4_HASH_EN | |
| 9249 | RX_MODE_RSS_TCP_IPV4_HASH_EN; |
| 9250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9251 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 9252 | udelay(10); |
| 9253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9254 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 9255 | |
| 9256 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9257 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9258 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 9259 | udelay(10); |
| 9260 | } |
| 9261 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 9262 | udelay(10); |
| 9263 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9264 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9265 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9266 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9267 | /* Set drive transmission level to 1.2V */ |
| 9268 | /* only if the signal pre-emphasis bit is not set */ |
| 9269 | val = tr32(MAC_SERDES_CFG); |
| 9270 | val &= 0xfffff000; |
| 9271 | val |= 0x880; |
| 9272 | tw32(MAC_SERDES_CFG, val); |
| 9273 | } |
| 9274 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) |
| 9275 | tw32(MAC_SERDES_CFG, 0x616000); |
| 9276 | } |
| 9277 | |
| 9278 | /* Prevent chip from dropping frames when flow control |
| 9279 | * is enabled. |
| 9280 | */ |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9281 | if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 9282 | val = 1; |
| 9283 | else |
| 9284 | val = 2; |
| 9285 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9286 | |
| 9287 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9288 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9289 | /* Use hardware link auto-negotiation */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9290 | tg3_flag_set(tp, HW_AUTONEG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9291 | } |
| 9292 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9293 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 9294 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 9295 | u32 tmp; |
| 9296 | |
| 9297 | tmp = tr32(SERDES_RX_CTRL); |
| 9298 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); |
| 9299 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; |
| 9300 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; |
| 9301 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 9302 | } |
| 9303 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9304 | if (!tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 9305 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9306 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9307 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9308 | err = tg3_setup_phy(tp, 0); |
| 9309 | if (err) |
| 9310 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9311 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9312 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 9313 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9314 | u32 tmp; |
| 9315 | |
| 9316 | /* Clear CRC stats. */ |
| 9317 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { |
| 9318 | tg3_writephy(tp, MII_TG3_TEST1, |
| 9319 | tmp | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 9320 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9322 | } |
| 9323 | } |
| 9324 | |
| 9325 | __tg3_set_rx_mode(tp->dev); |
| 9326 | |
| 9327 | /* Initialize receive rules. */ |
| 9328 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); |
| 9329 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 9330 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); |
| 9331 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 9332 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9333 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9334 | limit = 8; |
| 9335 | else |
| 9336 | limit = 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9337 | if (tg3_flag(tp, ENABLE_ASF)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9338 | limit -= 4; |
| 9339 | switch (limit) { |
| 9340 | case 16: |
| 9341 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); |
| 9342 | case 15: |
| 9343 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); |
| 9344 | case 14: |
| 9345 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); |
| 9346 | case 13: |
| 9347 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); |
| 9348 | case 12: |
| 9349 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); |
| 9350 | case 11: |
| 9351 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); |
| 9352 | case 10: |
| 9353 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); |
| 9354 | case 9: |
| 9355 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); |
| 9356 | case 8: |
| 9357 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); |
| 9358 | case 7: |
| 9359 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); |
| 9360 | case 6: |
| 9361 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); |
| 9362 | case 5: |
| 9363 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); |
| 9364 | case 4: |
| 9365 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ |
| 9366 | case 3: |
| 9367 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ |
| 9368 | case 2: |
| 9369 | case 1: |
| 9370 | |
| 9371 | default: |
| 9372 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 9373 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9374 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9375 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 9ce768e | 2007-10-11 19:49:11 -0700 | [diff] [blame] | 9376 | /* Write our heartbeat update interval to APE. */ |
| 9377 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, |
| 9378 | APE_HOST_HEARTBEAT_INT_DISABLE); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 9379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9380 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
| 9381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9382 | return 0; |
| 9383 | } |
| 9384 | |
| 9385 | /* Called at device open time to get the chip ready for |
| 9386 | * packet processing. Invoked with tp->lock held. |
| 9387 | */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 9388 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9389 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9390 | tg3_switch_clocks(tp); |
| 9391 | |
| 9392 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 9393 | |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 9394 | return tg3_reset_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9395 | } |
| 9396 | |
| 9397 | #define TG3_STAT_ADD32(PSTAT, REG) \ |
| 9398 | do { u32 __val = tr32(REG); \ |
| 9399 | (PSTAT)->low += __val; \ |
| 9400 | if ((PSTAT)->low < __val) \ |
| 9401 | (PSTAT)->high += 1; \ |
| 9402 | } while (0) |
| 9403 | |
| 9404 | static void tg3_periodic_fetch_stats(struct tg3 *tp) |
| 9405 | { |
| 9406 | struct tg3_hw_stats *sp = tp->hw_stats; |
| 9407 | |
| 9408 | if (!netif_carrier_ok(tp->dev)) |
| 9409 | return; |
| 9410 | |
| 9411 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); |
| 9412 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); |
| 9413 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); |
| 9414 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); |
| 9415 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); |
| 9416 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); |
| 9417 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); |
| 9418 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); |
| 9419 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); |
| 9420 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); |
| 9421 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); |
| 9422 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); |
| 9423 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); |
| 9424 | |
| 9425 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); |
| 9426 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); |
| 9427 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); |
| 9428 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); |
| 9429 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); |
| 9430 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); |
| 9431 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); |
| 9432 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); |
| 9433 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); |
| 9434 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); |
| 9435 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); |
| 9436 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); |
| 9437 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); |
| 9438 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 9439 | |
| 9440 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); |
Matt Carlson | 310050f | 2011-05-19 12:12:55 +0000 | [diff] [blame] | 9441 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 9442 | tp->pci_chip_rev_id != CHIPREV_ID_5719_A0 && |
| 9443 | tp->pci_chip_rev_id != CHIPREV_ID_5720_A0) { |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 9444 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
| 9445 | } else { |
| 9446 | u32 val = tr32(HOSTCC_FLOW_ATTN); |
| 9447 | val = (val & HOSTCC_FLOW_ATTN_MBUF_LWM) ? 1 : 0; |
| 9448 | if (val) { |
| 9449 | tw32(HOSTCC_FLOW_ATTN, HOSTCC_FLOW_ATTN_MBUF_LWM); |
| 9450 | sp->rx_discards.low += val; |
| 9451 | if (sp->rx_discards.low < val) |
| 9452 | sp->rx_discards.high += 1; |
| 9453 | } |
| 9454 | sp->mbuf_lwm_thresh_hit = sp->rx_discards; |
| 9455 | } |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 9456 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9457 | } |
| 9458 | |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9459 | static void tg3_chk_missed_msi(struct tg3 *tp) |
| 9460 | { |
| 9461 | u32 i; |
| 9462 | |
| 9463 | for (i = 0; i < tp->irq_cnt; i++) { |
| 9464 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9465 | |
| 9466 | if (tg3_has_work(tnapi)) { |
| 9467 | if (tnapi->last_rx_cons == tnapi->rx_rcb_ptr && |
| 9468 | tnapi->last_tx_cons == tnapi->tx_cons) { |
| 9469 | if (tnapi->chk_msi_cnt < 1) { |
| 9470 | tnapi->chk_msi_cnt++; |
| 9471 | return; |
| 9472 | } |
Matt Carlson | 7f23073 | 2011-08-31 11:44:48 +0000 | [diff] [blame] | 9473 | tg3_msi(0, tnapi); |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9474 | } |
| 9475 | } |
| 9476 | tnapi->chk_msi_cnt = 0; |
| 9477 | tnapi->last_rx_cons = tnapi->rx_rcb_ptr; |
| 9478 | tnapi->last_tx_cons = tnapi->tx_cons; |
| 9479 | } |
| 9480 | } |
| 9481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9482 | static void tg3_timer(unsigned long __opaque) |
| 9483 | { |
| 9484 | struct tg3 *tp = (struct tg3 *) __opaque; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9485 | |
Matt Carlson | 5b19062 | 2011-11-04 09:15:04 +0000 | [diff] [blame] | 9486 | if (tp->irq_sync || tg3_flag(tp, RESET_TASK_PENDING)) |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 9487 | goto restart_timer; |
| 9488 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9489 | spin_lock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9490 | |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9491 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9492 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9493 | tg3_chk_missed_msi(tp); |
| 9494 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9495 | if (!tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9496 | /* All of this garbage is because when using non-tagged |
| 9497 | * IRQ status the mailbox/status_block protocol the chip |
| 9498 | * uses with the cpu is race prone. |
| 9499 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 9500 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9501 | tw32(GRC_LOCAL_CTRL, |
| 9502 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 9503 | } else { |
| 9504 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 9505 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9506 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9507 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9508 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9509 | spin_unlock(&tp->lock); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 9510 | tg3_reset_task_schedule(tp); |
Matt Carlson | 5b19062 | 2011-11-04 09:15:04 +0000 | [diff] [blame] | 9511 | goto restart_timer; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9512 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9513 | } |
| 9514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9515 | /* This part only runs once per second. */ |
| 9516 | if (!--tp->timer_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9517 | if (tg3_flag(tp, 5705_PLUS)) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9518 | tg3_periodic_fetch_stats(tp); |
| 9519 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 9520 | if (tp->setlpicnt && !--tp->setlpicnt) |
| 9521 | tg3_phy_eee_enable(tp); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 9522 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9523 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9524 | u32 mac_stat; |
| 9525 | int phy_event; |
| 9526 | |
| 9527 | mac_stat = tr32(MAC_STATUS); |
| 9528 | |
| 9529 | phy_event = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9530 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9531 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
| 9532 | phy_event = 1; |
| 9533 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) |
| 9534 | phy_event = 1; |
| 9535 | |
| 9536 | if (phy_event) |
| 9537 | tg3_setup_phy(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9538 | } else if (tg3_flag(tp, POLL_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9539 | u32 mac_stat = tr32(MAC_STATUS); |
| 9540 | int need_setup = 0; |
| 9541 | |
| 9542 | if (netif_carrier_ok(tp->dev) && |
| 9543 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
| 9544 | need_setup = 1; |
| 9545 | } |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 9546 | if (!netif_carrier_ok(tp->dev) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9547 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
| 9548 | MAC_STATUS_SIGNAL_DET))) { |
| 9549 | need_setup = 1; |
| 9550 | } |
| 9551 | if (need_setup) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 9552 | if (!tp->serdes_counter) { |
| 9553 | tw32_f(MAC_MODE, |
| 9554 | (tp->mac_mode & |
| 9555 | ~MAC_MODE_PORT_MODE_MASK)); |
| 9556 | udelay(40); |
| 9557 | tw32_f(MAC_MODE, tp->mac_mode); |
| 9558 | udelay(40); |
| 9559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9560 | tg3_setup_phy(tp, 0); |
| 9561 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9562 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9563 | tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 9564 | tg3_serdes_parallel_detect(tp); |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 9565 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9566 | |
| 9567 | tp->timer_counter = tp->timer_multiplier; |
| 9568 | } |
| 9569 | |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 9570 | /* Heartbeat is only sent once every 2 seconds. |
| 9571 | * |
| 9572 | * The heartbeat is to tell the ASF firmware that the host |
| 9573 | * driver is still alive. In the event that the OS crashes, |
| 9574 | * ASF needs to reset the hardware to free up the FIFO space |
| 9575 | * that may be filled with rx packets destined for the host. |
| 9576 | * If the FIFO is full, ASF will no longer function properly. |
| 9577 | * |
| 9578 | * Unintended resets have been reported on real time kernels |
| 9579 | * where the timer doesn't run on time. Netpoll will also have |
| 9580 | * same problem. |
| 9581 | * |
| 9582 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware |
| 9583 | * to check the ring condition when the heartbeat is expiring |
| 9584 | * before doing the reset. This will prevent most unintended |
| 9585 | * resets. |
| 9586 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9587 | if (!--tp->asf_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9588 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 9589 | tg3_wait_for_event_ack(tp); |
| 9590 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 9591 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 9592 | FWCMD_NICDRV_ALIVE3); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 9593 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 9594 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
| 9595 | TG3_FW_UPDATE_TIMEOUT_SEC); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 9596 | |
| 9597 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9598 | } |
| 9599 | tp->asf_counter = tp->asf_multiplier; |
| 9600 | } |
| 9601 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9602 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9603 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 9604 | restart_timer: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9605 | tp->timer.expires = jiffies + tp->timer_offset; |
| 9606 | add_timer(&tp->timer); |
| 9607 | } |
| 9608 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 9609 | static void __devinit tg3_timer_init(struct tg3 *tp) |
| 9610 | { |
| 9611 | if (tg3_flag(tp, TAGGED_STATUS) && |
| 9612 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 9613 | !tg3_flag(tp, 57765_CLASS)) |
| 9614 | tp->timer_offset = HZ; |
| 9615 | else |
| 9616 | tp->timer_offset = HZ / 10; |
| 9617 | |
| 9618 | BUG_ON(tp->timer_offset > HZ); |
| 9619 | |
| 9620 | tp->timer_multiplier = (HZ / tp->timer_offset); |
| 9621 | tp->asf_multiplier = (HZ / tp->timer_offset) * |
| 9622 | TG3_FW_UPDATE_FREQ_SEC; |
| 9623 | |
| 9624 | init_timer(&tp->timer); |
| 9625 | tp->timer.data = (unsigned long) tp; |
| 9626 | tp->timer.function = tg3_timer; |
| 9627 | } |
| 9628 | |
| 9629 | static void tg3_timer_start(struct tg3 *tp) |
| 9630 | { |
| 9631 | tp->asf_counter = tp->asf_multiplier; |
| 9632 | tp->timer_counter = tp->timer_multiplier; |
| 9633 | |
| 9634 | tp->timer.expires = jiffies + tp->timer_offset; |
| 9635 | add_timer(&tp->timer); |
| 9636 | } |
| 9637 | |
| 9638 | static void tg3_timer_stop(struct tg3 *tp) |
| 9639 | { |
| 9640 | del_timer_sync(&tp->timer); |
| 9641 | } |
| 9642 | |
| 9643 | /* Restart hardware after configuration changes, self-test, etc. |
| 9644 | * Invoked with tp->lock held. |
| 9645 | */ |
| 9646 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) |
| 9647 | __releases(tp->lock) |
| 9648 | __acquires(tp->lock) |
| 9649 | { |
| 9650 | int err; |
| 9651 | |
| 9652 | err = tg3_init_hw(tp, reset_phy); |
| 9653 | if (err) { |
| 9654 | netdev_err(tp->dev, |
| 9655 | "Failed to re-initialize device, aborting\n"); |
| 9656 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 9657 | tg3_full_unlock(tp); |
| 9658 | tg3_timer_stop(tp); |
| 9659 | tp->irq_sync = 0; |
| 9660 | tg3_napi_enable(tp); |
| 9661 | dev_close(tp->dev); |
| 9662 | tg3_full_lock(tp, 0); |
| 9663 | } |
| 9664 | return err; |
| 9665 | } |
| 9666 | |
| 9667 | static void tg3_reset_task(struct work_struct *work) |
| 9668 | { |
| 9669 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
| 9670 | int err; |
| 9671 | |
| 9672 | tg3_full_lock(tp, 0); |
| 9673 | |
| 9674 | if (!netif_running(tp->dev)) { |
| 9675 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 9676 | tg3_full_unlock(tp); |
| 9677 | return; |
| 9678 | } |
| 9679 | |
| 9680 | tg3_full_unlock(tp); |
| 9681 | |
| 9682 | tg3_phy_stop(tp); |
| 9683 | |
| 9684 | tg3_netif_stop(tp); |
| 9685 | |
| 9686 | tg3_full_lock(tp, 1); |
| 9687 | |
| 9688 | if (tg3_flag(tp, TX_RECOVERY_PENDING)) { |
| 9689 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 9690 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 9691 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
| 9692 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
| 9693 | } |
| 9694 | |
| 9695 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 9696 | err = tg3_init_hw(tp, 1); |
| 9697 | if (err) |
| 9698 | goto out; |
| 9699 | |
| 9700 | tg3_netif_start(tp); |
| 9701 | |
| 9702 | out: |
| 9703 | tg3_full_unlock(tp); |
| 9704 | |
| 9705 | if (!err) |
| 9706 | tg3_phy_start(tp); |
| 9707 | |
| 9708 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 9709 | } |
| 9710 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9711 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9712 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 9713 | irq_handler_t fn; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9714 | unsigned long flags; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9715 | char *name; |
| 9716 | struct tg3_napi *tnapi = &tp->napi[irq_num]; |
| 9717 | |
| 9718 | if (tp->irq_cnt == 1) |
| 9719 | name = tp->dev->name; |
| 9720 | else { |
| 9721 | name = &tnapi->irq_lbl[0]; |
| 9722 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); |
| 9723 | name[IFNAMSIZ-1] = 0; |
| 9724 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9725 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9726 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9727 | fn = tg3_msi; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9728 | if (tg3_flag(tp, 1SHOT_MSI)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9729 | fn = tg3_msi_1shot; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 9730 | flags = 0; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9731 | } else { |
| 9732 | fn = tg3_interrupt; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9733 | if (tg3_flag(tp, TAGGED_STATUS)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9734 | fn = tg3_interrupt_tagged; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 9735 | flags = IRQF_SHARED; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9736 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9737 | |
| 9738 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9739 | } |
| 9740 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9741 | static int tg3_test_interrupt(struct tg3 *tp) |
| 9742 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 9743 | struct tg3_napi *tnapi = &tp->napi[0]; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9744 | struct net_device *dev = tp->dev; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9745 | int err, i, intr_ok = 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9746 | u32 val; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9747 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 9748 | if (!netif_running(dev)) |
| 9749 | return -ENODEV; |
| 9750 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9751 | tg3_disable_ints(tp); |
| 9752 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9753 | free_irq(tnapi->irq_vec, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9754 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9755 | /* |
| 9756 | * Turn off MSI one shot mode. Otherwise this test has no |
| 9757 | * observable way to know whether the interrupt was delivered. |
| 9758 | */ |
Matt Carlson | 3aa1cdf | 2011-07-20 10:20:55 +0000 | [diff] [blame] | 9759 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9760 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
| 9761 | tw32(MSGINT_MODE, val); |
| 9762 | } |
| 9763 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9764 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
Davidlohr Bueso | f274fd9 | 2012-02-22 03:06:54 +0000 | [diff] [blame] | 9765 | IRQF_SHARED, dev->name, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9766 | if (err) |
| 9767 | return err; |
| 9768 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 9769 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9770 | tg3_enable_ints(tp); |
| 9771 | |
| 9772 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 9773 | tnapi->coal_now); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9774 | |
| 9775 | for (i = 0; i < 5; i++) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9776 | u32 int_mbox, misc_host_ctrl; |
| 9777 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 9778 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9779 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 9780 | |
| 9781 | if ((int_mbox != 0) || |
| 9782 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { |
| 9783 | intr_ok = 1; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9784 | break; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 9785 | } |
| 9786 | |
Matt Carlson | 3aa1cdf | 2011-07-20 10:20:55 +0000 | [diff] [blame] | 9787 | if (tg3_flag(tp, 57765_PLUS) && |
| 9788 | tnapi->hw_status->status_tag != tnapi->last_tag) |
| 9789 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 9790 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9791 | msleep(10); |
| 9792 | } |
| 9793 | |
| 9794 | tg3_disable_ints(tp); |
| 9795 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9796 | free_irq(tnapi->irq_vec, tnapi); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9797 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9798 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9799 | |
| 9800 | if (err) |
| 9801 | return err; |
| 9802 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9803 | if (intr_ok) { |
| 9804 | /* Reenable MSI one shot mode. */ |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 9805 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, 1SHOT_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9806 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
| 9807 | tw32(MSGINT_MODE, val); |
| 9808 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9809 | return 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9810 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9811 | |
| 9812 | return -EIO; |
| 9813 | } |
| 9814 | |
| 9815 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is |
| 9816 | * successfully restored |
| 9817 | */ |
| 9818 | static int tg3_test_msi(struct tg3 *tp) |
| 9819 | { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9820 | int err; |
| 9821 | u16 pci_cmd; |
| 9822 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9823 | if (!tg3_flag(tp, USING_MSI)) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9824 | return 0; |
| 9825 | |
| 9826 | /* Turn off SERR reporting in case MSI terminates with Master |
| 9827 | * Abort. |
| 9828 | */ |
| 9829 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 9830 | pci_write_config_word(tp->pdev, PCI_COMMAND, |
| 9831 | pci_cmd & ~PCI_COMMAND_SERR); |
| 9832 | |
| 9833 | err = tg3_test_interrupt(tp); |
| 9834 | |
| 9835 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 9836 | |
| 9837 | if (!err) |
| 9838 | return 0; |
| 9839 | |
| 9840 | /* other failures */ |
| 9841 | if (err != -EIO) |
| 9842 | return err; |
| 9843 | |
| 9844 | /* MSI test failed, go back to INTx mode */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 9845 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
| 9846 | "to INTx mode. Please report this failure to the PCI " |
| 9847 | "maintainer and include system chipset information\n"); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9848 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9849 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 9850 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9851 | pci_disable_msi(tp->pdev); |
| 9852 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9853 | tg3_flag_clear(tp, USING_MSI); |
Andre Detsch | dc8bf1b | 2010-04-26 07:27:07 +0000 | [diff] [blame] | 9854 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9855 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9856 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9857 | if (err) |
| 9858 | return err; |
| 9859 | |
| 9860 | /* Need to reset the chip because the MSI cycle may have terminated |
| 9861 | * with Master Abort. |
| 9862 | */ |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9863 | tg3_full_lock(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9864 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9865 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 9866 | err = tg3_init_hw(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9867 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9868 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9869 | |
| 9870 | if (err) |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9871 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9872 | |
| 9873 | return err; |
| 9874 | } |
| 9875 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9876 | static int tg3_request_firmware(struct tg3 *tp) |
| 9877 | { |
| 9878 | const __be32 *fw_data; |
| 9879 | |
| 9880 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9881 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
| 9882 | tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9883 | return -ENOENT; |
| 9884 | } |
| 9885 | |
| 9886 | fw_data = (void *)tp->fw->data; |
| 9887 | |
| 9888 | /* Firmware blob starts with version numbers, followed by |
| 9889 | * start address and _full_ length including BSS sections |
| 9890 | * (which must be longer than the actual data, of course |
| 9891 | */ |
| 9892 | |
| 9893 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ |
| 9894 | if (tp->fw_len < (tp->fw->size - 12)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9895 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
| 9896 | tp->fw_len, tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9897 | release_firmware(tp->fw); |
| 9898 | tp->fw = NULL; |
| 9899 | return -EINVAL; |
| 9900 | } |
| 9901 | |
| 9902 | /* We no longer need firmware; we have it. */ |
| 9903 | tp->fw_needed = NULL; |
| 9904 | return 0; |
| 9905 | } |
| 9906 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9907 | static bool tg3_enable_msix(struct tg3 *tp) |
| 9908 | { |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9909 | int i, rc; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9910 | struct msix_entry msix_ent[tp->irq_max]; |
| 9911 | |
Yuval Mintz | 1180087 | 2012-07-01 03:18:57 +0000 | [diff] [blame] | 9912 | tp->irq_cnt = netif_get_num_default_rss_queues(); |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9913 | if (tp->irq_cnt > 1) { |
| 9914 | /* We want as many rx rings enabled as there are cpus. |
| 9915 | * In multiqueue MSI-X mode, the first MSI-X vector |
| 9916 | * only deals with link interrupts, etc, so we add |
| 9917 | * one to the number of vectors we are requesting. |
| 9918 | */ |
| 9919 | tp->irq_cnt = min_t(unsigned, tp->irq_cnt + 1, tp->irq_max); |
| 9920 | } |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9921 | |
| 9922 | for (i = 0; i < tp->irq_max; i++) { |
| 9923 | msix_ent[i].entry = i; |
| 9924 | msix_ent[i].vector = 0; |
| 9925 | } |
| 9926 | |
| 9927 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9928 | if (rc < 0) { |
| 9929 | return false; |
| 9930 | } else if (rc != 0) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9931 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
| 9932 | return false; |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9933 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
| 9934 | tp->irq_cnt, rc); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9935 | tp->irq_cnt = rc; |
| 9936 | } |
| 9937 | |
| 9938 | for (i = 0; i < tp->irq_max; i++) |
| 9939 | tp->napi[i].irq_vec = msix_ent[i].vector; |
| 9940 | |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 9941 | netif_set_real_num_tx_queues(tp->dev, 1); |
| 9942 | rc = tp->irq_cnt > 1 ? tp->irq_cnt - 1 : 1; |
| 9943 | if (netif_set_real_num_rx_queues(tp->dev, rc)) { |
| 9944 | pci_disable_msix(tp->pdev); |
| 9945 | return false; |
| 9946 | } |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 9947 | |
| 9948 | if (tp->irq_cnt > 1) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9949 | tg3_flag_set(tp, ENABLE_RSS); |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 9950 | |
| 9951 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 9952 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9953 | tg3_flag_set(tp, ENABLE_TSS); |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 9954 | netif_set_real_num_tx_queues(tp->dev, tp->irq_cnt - 1); |
| 9955 | } |
| 9956 | } |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9957 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9958 | return true; |
| 9959 | } |
| 9960 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9961 | static void tg3_ints_init(struct tg3 *tp) |
| 9962 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9963 | if ((tg3_flag(tp, SUPPORT_MSI) || tg3_flag(tp, SUPPORT_MSIX)) && |
| 9964 | !tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9965 | /* All MSI supporting chips should support tagged |
| 9966 | * status. Assert that this is the case. |
| 9967 | */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 9968 | netdev_warn(tp->dev, |
| 9969 | "MSI without TAGGED_STATUS? Not using MSI\n"); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9970 | goto defcfg; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9971 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9972 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9973 | if (tg3_flag(tp, SUPPORT_MSIX) && tg3_enable_msix(tp)) |
| 9974 | tg3_flag_set(tp, USING_MSIX); |
| 9975 | else if (tg3_flag(tp, SUPPORT_MSI) && pci_enable_msi(tp->pdev) == 0) |
| 9976 | tg3_flag_set(tp, USING_MSI); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9977 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9978 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9979 | u32 msi_mode = tr32(MSGINT_MODE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9980 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9981 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 9982 | if (!tg3_flag(tp, 1SHOT_MSI)) |
| 9983 | msi_mode |= MSGINT_MODE_ONE_SHOT_DISABLE; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9984 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
| 9985 | } |
| 9986 | defcfg: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9987 | if (!tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9988 | tp->irq_cnt = 1; |
| 9989 | tp->napi[0].irq_vec = tp->pdev->irq; |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 9990 | netif_set_real_num_tx_queues(tp->dev, 1); |
Matt Carlson | 8540788 | 2010-10-06 13:40:58 -0700 | [diff] [blame] | 9991 | netif_set_real_num_rx_queues(tp->dev, 1); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9992 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9993 | } |
| 9994 | |
| 9995 | static void tg3_ints_fini(struct tg3 *tp) |
| 9996 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9997 | if (tg3_flag(tp, USING_MSIX)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9998 | pci_disable_msix(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9999 | else if (tg3_flag(tp, USING_MSI)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10000 | pci_disable_msi(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10001 | tg3_flag_clear(tp, USING_MSI); |
| 10002 | tg3_flag_clear(tp, USING_MSIX); |
| 10003 | tg3_flag_clear(tp, ENABLE_RSS); |
| 10004 | tg3_flag_clear(tp, ENABLE_TSS); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10005 | } |
| 10006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10007 | static int tg3_open(struct net_device *dev) |
| 10008 | { |
| 10009 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10010 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10011 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 10012 | if (tp->fw_needed) { |
| 10013 | err = tg3_request_firmware(tp); |
| 10014 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 10015 | if (err) |
| 10016 | return err; |
| 10017 | } else if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 10018 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10019 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 10020 | } else if (!tg3_flag(tp, TSO_CAPABLE)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 10021 | netdev_notice(tp->dev, "TSO capability restored\n"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10022 | tg3_flag_set(tp, TSO_CAPABLE); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 10023 | } |
| 10024 | } |
| 10025 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 10026 | netif_carrier_off(tp->dev); |
| 10027 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 10028 | err = tg3_power_up(tp); |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 10029 | if (err) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10030 | return err; |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 10031 | |
| 10032 | tg3_full_lock(tp, 0); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10034 | tg3_disable_ints(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10035 | tg3_flag_clear(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10036 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10037 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10038 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10039 | /* |
| 10040 | * Setup interrupts first so we know how |
| 10041 | * many NAPI resources to allocate |
| 10042 | */ |
| 10043 | tg3_ints_init(tp); |
| 10044 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 10045 | tg3_rss_check_indir_tbl(tp); |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 10046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10047 | /* The placement of this call is tied |
| 10048 | * to the setup and use of Host TX descriptors. |
| 10049 | */ |
| 10050 | err = tg3_alloc_consistent(tp); |
| 10051 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10052 | goto err_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10053 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10054 | tg3_napi_init(tp); |
| 10055 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 10056 | tg3_napi_enable(tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 10057 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10058 | for (i = 0; i < tp->irq_cnt; i++) { |
| 10059 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10060 | err = tg3_request_irq(tp, i); |
| 10061 | if (err) { |
Matt Carlson | 5bc0918 | 2011-11-04 09:15:01 +0000 | [diff] [blame] | 10062 | for (i--; i >= 0; i--) { |
| 10063 | tnapi = &tp->napi[i]; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10064 | free_irq(tnapi->irq_vec, tnapi); |
Matt Carlson | 5bc0918 | 2011-11-04 09:15:01 +0000 | [diff] [blame] | 10065 | } |
| 10066 | goto err_out2; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10067 | } |
| 10068 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10069 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10070 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10071 | |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 10072 | err = tg3_init_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10073 | if (err) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10074 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10075 | tg3_free_rings(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10076 | } |
| 10077 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10078 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10079 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10080 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10081 | goto err_out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10082 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10083 | if (tg3_flag(tp, USING_MSI)) { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10084 | err = tg3_test_msi(tp); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10085 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10086 | if (err) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10087 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10088 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10089 | tg3_free_rings(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10090 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10091 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10092 | goto err_out2; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10093 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10094 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10095 | if (!tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10096 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10097 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10098 | tw32(PCIE_TRANSACTION_CFG, |
| 10099 | val | PCIE_TRANS_CFG_1SHOT_MSI); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10100 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10101 | } |
| 10102 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10103 | tg3_phy_start(tp); |
| 10104 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10105 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10106 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10107 | tg3_timer_start(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10108 | tg3_flag_set(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10109 | tg3_enable_ints(tp); |
| 10110 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10111 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10112 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 10113 | netif_tx_start_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10114 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 10115 | /* |
| 10116 | * Reset loopback feature if it was turned on while the device was down |
| 10117 | * make sure that it's installed properly now. |
| 10118 | */ |
| 10119 | if (dev->features & NETIF_F_LOOPBACK) |
| 10120 | tg3_set_loopback(dev, dev->features); |
| 10121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10122 | return 0; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10123 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10124 | err_out3: |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10125 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 10126 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10127 | free_irq(tnapi->irq_vec, tnapi); |
| 10128 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10129 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10130 | err_out2: |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 10131 | tg3_napi_disable(tp); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10132 | tg3_napi_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10133 | tg3_free_consistent(tp); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10134 | |
| 10135 | err_out1: |
| 10136 | tg3_ints_fini(tp); |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 10137 | tg3_frob_aux_power(tp, false); |
| 10138 | pci_set_power_state(tp->pdev, PCI_D3hot); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10139 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10140 | } |
| 10141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10142 | static int tg3_close(struct net_device *dev) |
| 10143 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10144 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10145 | struct tg3 *tp = netdev_priv(dev); |
| 10146 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 10147 | tg3_napi_disable(tp); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 10148 | tg3_reset_task_cancel(tp); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 10149 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 10150 | netif_tx_stop_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10151 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10152 | tg3_timer_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10153 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 10154 | tg3_phy_stop(tp); |
| 10155 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10156 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10157 | |
| 10158 | tg3_disable_ints(tp); |
| 10159 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10160 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10161 | tg3_free_rings(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10162 | tg3_flag_clear(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10163 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10164 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10165 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10166 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 10167 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10168 | free_irq(tnapi->irq_vec, tnapi); |
| 10169 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10170 | |
| 10171 | tg3_ints_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10172 | |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 10173 | /* Clear stats across close / open calls */ |
| 10174 | memset(&tp->net_stats_prev, 0, sizeof(tp->net_stats_prev)); |
| 10175 | memset(&tp->estats_prev, 0, sizeof(tp->estats_prev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10176 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10177 | tg3_napi_fini(tp); |
| 10178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10179 | tg3_free_consistent(tp); |
| 10180 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 10181 | tg3_power_down(tp); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10182 | |
| 10183 | netif_carrier_off(tp->dev); |
| 10184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10185 | return 0; |
| 10186 | } |
| 10187 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 10188 | static inline u64 get_stat64(tg3_stat64_t *val) |
Stefan Buehler | 816f8b8 | 2008-08-15 14:10:54 -0700 | [diff] [blame] | 10189 | { |
| 10190 | return ((u64)val->high << 32) | ((u64)val->low); |
| 10191 | } |
| 10192 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10193 | static u64 tg3_calc_crc_errors(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10194 | { |
| 10195 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10196 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10197 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10198 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 10199 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10200 | u32 val; |
| 10201 | |
Michael Chan | 569a5df | 2007-02-13 12:18:15 -0800 | [diff] [blame] | 10202 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
| 10203 | tg3_writephy(tp, MII_TG3_TEST1, |
| 10204 | val | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 10205 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10206 | } else |
| 10207 | val = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10208 | |
| 10209 | tp->phy_crc_errors += val; |
| 10210 | |
| 10211 | return tp->phy_crc_errors; |
| 10212 | } |
| 10213 | |
| 10214 | return get_stat64(&hw_stats->rx_fcs_errors); |
| 10215 | } |
| 10216 | |
| 10217 | #define ESTAT_ADD(member) \ |
| 10218 | estats->member = old_estats->member + \ |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 10219 | get_stat64(&hw_stats->member) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10220 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10221 | static void tg3_get_estats(struct tg3 *tp, struct tg3_ethtool_stats *estats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10222 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10223 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
| 10224 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10226 | ESTAT_ADD(rx_octets); |
| 10227 | ESTAT_ADD(rx_fragments); |
| 10228 | ESTAT_ADD(rx_ucast_packets); |
| 10229 | ESTAT_ADD(rx_mcast_packets); |
| 10230 | ESTAT_ADD(rx_bcast_packets); |
| 10231 | ESTAT_ADD(rx_fcs_errors); |
| 10232 | ESTAT_ADD(rx_align_errors); |
| 10233 | ESTAT_ADD(rx_xon_pause_rcvd); |
| 10234 | ESTAT_ADD(rx_xoff_pause_rcvd); |
| 10235 | ESTAT_ADD(rx_mac_ctrl_rcvd); |
| 10236 | ESTAT_ADD(rx_xoff_entered); |
| 10237 | ESTAT_ADD(rx_frame_too_long_errors); |
| 10238 | ESTAT_ADD(rx_jabbers); |
| 10239 | ESTAT_ADD(rx_undersize_packets); |
| 10240 | ESTAT_ADD(rx_in_length_errors); |
| 10241 | ESTAT_ADD(rx_out_length_errors); |
| 10242 | ESTAT_ADD(rx_64_or_less_octet_packets); |
| 10243 | ESTAT_ADD(rx_65_to_127_octet_packets); |
| 10244 | ESTAT_ADD(rx_128_to_255_octet_packets); |
| 10245 | ESTAT_ADD(rx_256_to_511_octet_packets); |
| 10246 | ESTAT_ADD(rx_512_to_1023_octet_packets); |
| 10247 | ESTAT_ADD(rx_1024_to_1522_octet_packets); |
| 10248 | ESTAT_ADD(rx_1523_to_2047_octet_packets); |
| 10249 | ESTAT_ADD(rx_2048_to_4095_octet_packets); |
| 10250 | ESTAT_ADD(rx_4096_to_8191_octet_packets); |
| 10251 | ESTAT_ADD(rx_8192_to_9022_octet_packets); |
| 10252 | |
| 10253 | ESTAT_ADD(tx_octets); |
| 10254 | ESTAT_ADD(tx_collisions); |
| 10255 | ESTAT_ADD(tx_xon_sent); |
| 10256 | ESTAT_ADD(tx_xoff_sent); |
| 10257 | ESTAT_ADD(tx_flow_control); |
| 10258 | ESTAT_ADD(tx_mac_errors); |
| 10259 | ESTAT_ADD(tx_single_collisions); |
| 10260 | ESTAT_ADD(tx_mult_collisions); |
| 10261 | ESTAT_ADD(tx_deferred); |
| 10262 | ESTAT_ADD(tx_excessive_collisions); |
| 10263 | ESTAT_ADD(tx_late_collisions); |
| 10264 | ESTAT_ADD(tx_collide_2times); |
| 10265 | ESTAT_ADD(tx_collide_3times); |
| 10266 | ESTAT_ADD(tx_collide_4times); |
| 10267 | ESTAT_ADD(tx_collide_5times); |
| 10268 | ESTAT_ADD(tx_collide_6times); |
| 10269 | ESTAT_ADD(tx_collide_7times); |
| 10270 | ESTAT_ADD(tx_collide_8times); |
| 10271 | ESTAT_ADD(tx_collide_9times); |
| 10272 | ESTAT_ADD(tx_collide_10times); |
| 10273 | ESTAT_ADD(tx_collide_11times); |
| 10274 | ESTAT_ADD(tx_collide_12times); |
| 10275 | ESTAT_ADD(tx_collide_13times); |
| 10276 | ESTAT_ADD(tx_collide_14times); |
| 10277 | ESTAT_ADD(tx_collide_15times); |
| 10278 | ESTAT_ADD(tx_ucast_packets); |
| 10279 | ESTAT_ADD(tx_mcast_packets); |
| 10280 | ESTAT_ADD(tx_bcast_packets); |
| 10281 | ESTAT_ADD(tx_carrier_sense_errors); |
| 10282 | ESTAT_ADD(tx_discards); |
| 10283 | ESTAT_ADD(tx_errors); |
| 10284 | |
| 10285 | ESTAT_ADD(dma_writeq_full); |
| 10286 | ESTAT_ADD(dma_write_prioq_full); |
| 10287 | ESTAT_ADD(rxbds_empty); |
| 10288 | ESTAT_ADD(rx_discards); |
| 10289 | ESTAT_ADD(rx_errors); |
| 10290 | ESTAT_ADD(rx_threshold_hit); |
| 10291 | |
| 10292 | ESTAT_ADD(dma_readq_full); |
| 10293 | ESTAT_ADD(dma_read_prioq_full); |
| 10294 | ESTAT_ADD(tx_comp_queue_full); |
| 10295 | |
| 10296 | ESTAT_ADD(ring_set_send_prod_index); |
| 10297 | ESTAT_ADD(ring_status_update); |
| 10298 | ESTAT_ADD(nic_irqs); |
| 10299 | ESTAT_ADD(nic_avoided_irqs); |
| 10300 | ESTAT_ADD(nic_tx_threshold_hit); |
| 10301 | |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 10302 | ESTAT_ADD(mbuf_lwm_thresh_hit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10303 | } |
| 10304 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10305 | static void tg3_get_nstats(struct tg3 *tp, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10306 | { |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 10307 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10308 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10310 | stats->rx_packets = old_stats->rx_packets + |
| 10311 | get_stat64(&hw_stats->rx_ucast_packets) + |
| 10312 | get_stat64(&hw_stats->rx_mcast_packets) + |
| 10313 | get_stat64(&hw_stats->rx_bcast_packets); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10315 | stats->tx_packets = old_stats->tx_packets + |
| 10316 | get_stat64(&hw_stats->tx_ucast_packets) + |
| 10317 | get_stat64(&hw_stats->tx_mcast_packets) + |
| 10318 | get_stat64(&hw_stats->tx_bcast_packets); |
| 10319 | |
| 10320 | stats->rx_bytes = old_stats->rx_bytes + |
| 10321 | get_stat64(&hw_stats->rx_octets); |
| 10322 | stats->tx_bytes = old_stats->tx_bytes + |
| 10323 | get_stat64(&hw_stats->tx_octets); |
| 10324 | |
| 10325 | stats->rx_errors = old_stats->rx_errors + |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 10326 | get_stat64(&hw_stats->rx_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10327 | stats->tx_errors = old_stats->tx_errors + |
| 10328 | get_stat64(&hw_stats->tx_errors) + |
| 10329 | get_stat64(&hw_stats->tx_mac_errors) + |
| 10330 | get_stat64(&hw_stats->tx_carrier_sense_errors) + |
| 10331 | get_stat64(&hw_stats->tx_discards); |
| 10332 | |
| 10333 | stats->multicast = old_stats->multicast + |
| 10334 | get_stat64(&hw_stats->rx_mcast_packets); |
| 10335 | stats->collisions = old_stats->collisions + |
| 10336 | get_stat64(&hw_stats->tx_collisions); |
| 10337 | |
| 10338 | stats->rx_length_errors = old_stats->rx_length_errors + |
| 10339 | get_stat64(&hw_stats->rx_frame_too_long_errors) + |
| 10340 | get_stat64(&hw_stats->rx_undersize_packets); |
| 10341 | |
| 10342 | stats->rx_over_errors = old_stats->rx_over_errors + |
| 10343 | get_stat64(&hw_stats->rxbds_empty); |
| 10344 | stats->rx_frame_errors = old_stats->rx_frame_errors + |
| 10345 | get_stat64(&hw_stats->rx_align_errors); |
| 10346 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + |
| 10347 | get_stat64(&hw_stats->tx_discards); |
| 10348 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + |
| 10349 | get_stat64(&hw_stats->tx_carrier_sense_errors); |
| 10350 | |
| 10351 | stats->rx_crc_errors = old_stats->rx_crc_errors + |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10352 | tg3_calc_crc_errors(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10353 | |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 10354 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
| 10355 | get_stat64(&hw_stats->rx_discards); |
| 10356 | |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 10357 | stats->rx_dropped = tp->rx_dropped; |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 10358 | stats->tx_dropped = tp->tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10359 | } |
| 10360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10361 | static int tg3_get_regs_len(struct net_device *dev) |
| 10362 | { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 10363 | return TG3_REG_BLK_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10364 | } |
| 10365 | |
| 10366 | static void tg3_get_regs(struct net_device *dev, |
| 10367 | struct ethtool_regs *regs, void *_p) |
| 10368 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10369 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10370 | |
| 10371 | regs->version = 0; |
| 10372 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 10373 | memset(_p, 0, TG3_REG_BLK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10374 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 10375 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10376 | return; |
| 10377 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10378 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10379 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 10380 | tg3_dump_legacy_regs(tp, (u32 *)_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10381 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10382 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10383 | } |
| 10384 | |
| 10385 | static int tg3_get_eeprom_len(struct net_device *dev) |
| 10386 | { |
| 10387 | struct tg3 *tp = netdev_priv(dev); |
| 10388 | |
| 10389 | return tp->nvram_size; |
| 10390 | } |
| 10391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10392 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 10393 | { |
| 10394 | struct tg3 *tp = netdev_priv(dev); |
| 10395 | int ret; |
| 10396 | u8 *pd; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10397 | u32 i, offset, len, b_offset, b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10398 | __be32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10399 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10400 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 10401 | return -EINVAL; |
| 10402 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 10403 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10404 | return -EAGAIN; |
| 10405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10406 | offset = eeprom->offset; |
| 10407 | len = eeprom->len; |
| 10408 | eeprom->len = 0; |
| 10409 | |
| 10410 | eeprom->magic = TG3_EEPROM_MAGIC; |
| 10411 | |
| 10412 | if (offset & 3) { |
| 10413 | /* adjustments to start on required 4 byte boundary */ |
| 10414 | b_offset = offset & 3; |
| 10415 | b_count = 4 - b_offset; |
| 10416 | if (b_count > len) { |
| 10417 | /* i.e. offset=1 len=2 */ |
| 10418 | b_count = len; |
| 10419 | } |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10420 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10421 | if (ret) |
| 10422 | return ret; |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 10423 | memcpy(data, ((char *)&val) + b_offset, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10424 | len -= b_count; |
| 10425 | offset += b_count; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10426 | eeprom->len += b_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10427 | } |
| 10428 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10429 | /* read bytes up to the last 4 byte boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10430 | pd = &data[eeprom->len]; |
| 10431 | for (i = 0; i < (len - (len & 3)); i += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10432 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10433 | if (ret) { |
| 10434 | eeprom->len += i; |
| 10435 | return ret; |
| 10436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10437 | memcpy(pd + i, &val, 4); |
| 10438 | } |
| 10439 | eeprom->len += i; |
| 10440 | |
| 10441 | if (len & 3) { |
| 10442 | /* read last bytes not ending on 4 byte boundary */ |
| 10443 | pd = &data[eeprom->len]; |
| 10444 | b_count = len & 3; |
| 10445 | b_offset = offset + len - b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10446 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10447 | if (ret) |
| 10448 | return ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10449 | memcpy(pd, &val, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10450 | eeprom->len += b_count; |
| 10451 | } |
| 10452 | return 0; |
| 10453 | } |
| 10454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10455 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 10456 | { |
| 10457 | struct tg3 *tp = netdev_priv(dev); |
| 10458 | int ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10459 | u32 offset, len, b_offset, odd_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10460 | u8 *buf; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10461 | __be32 start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10462 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 10463 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10464 | return -EAGAIN; |
| 10465 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10466 | if (tg3_flag(tp, NO_NVRAM) || |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 10467 | eeprom->magic != TG3_EEPROM_MAGIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10468 | return -EINVAL; |
| 10469 | |
| 10470 | offset = eeprom->offset; |
| 10471 | len = eeprom->len; |
| 10472 | |
| 10473 | if ((b_offset = (offset & 3))) { |
| 10474 | /* adjustments to start on required 4 byte boundary */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10475 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10476 | if (ret) |
| 10477 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10478 | len += b_offset; |
| 10479 | offset &= ~3; |
Michael Chan | 1c8594b4 | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 10480 | if (len < 4) |
| 10481 | len = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10482 | } |
| 10483 | |
| 10484 | odd_len = 0; |
Michael Chan | 1c8594b4 | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 10485 | if (len & 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10486 | /* adjustments to end on required 4 byte boundary */ |
| 10487 | odd_len = 1; |
| 10488 | len = (len + 3) & ~3; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10489 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10490 | if (ret) |
| 10491 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10492 | } |
| 10493 | |
| 10494 | buf = data; |
| 10495 | if (b_offset || odd_len) { |
| 10496 | buf = kmalloc(len, GFP_KERNEL); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 10497 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10498 | return -ENOMEM; |
| 10499 | if (b_offset) |
| 10500 | memcpy(buf, &start, 4); |
| 10501 | if (odd_len) |
| 10502 | memcpy(buf+len-4, &end, 4); |
| 10503 | memcpy(buf + b_offset, data, eeprom->len); |
| 10504 | } |
| 10505 | |
| 10506 | ret = tg3_nvram_write_block(tp, offset, len, buf); |
| 10507 | |
| 10508 | if (buf != data) |
| 10509 | kfree(buf); |
| 10510 | |
| 10511 | return ret; |
| 10512 | } |
| 10513 | |
| 10514 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 10515 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10516 | struct tg3 *tp = netdev_priv(dev); |
| 10517 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10518 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10519 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10520 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10521 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10522 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 10523 | return phy_ethtool_gset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10524 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10526 | cmd->supported = (SUPPORTED_Autoneg); |
| 10527 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10528 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10529 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
| 10530 | SUPPORTED_1000baseT_Full); |
| 10531 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10532 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10533 | cmd->supported |= (SUPPORTED_100baseT_Half | |
| 10534 | SUPPORTED_100baseT_Full | |
| 10535 | SUPPORTED_10baseT_Half | |
| 10536 | SUPPORTED_10baseT_Full | |
Matt Carlson | 3bebab5 | 2007-11-12 21:22:40 -0800 | [diff] [blame] | 10537 | SUPPORTED_TP); |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 10538 | cmd->port = PORT_TP; |
| 10539 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10540 | cmd->supported |= SUPPORTED_FIBRE; |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 10541 | cmd->port = PORT_FIBRE; |
| 10542 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10544 | cmd->advertising = tp->link_config.advertising; |
Matt Carlson | 5bb0977 | 2011-06-13 13:39:00 +0000 | [diff] [blame] | 10545 | if (tg3_flag(tp, PAUSE_AUTONEG)) { |
| 10546 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) { |
| 10547 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 10548 | cmd->advertising |= ADVERTISED_Pause; |
| 10549 | } else { |
| 10550 | cmd->advertising |= ADVERTISED_Pause | |
| 10551 | ADVERTISED_Asym_Pause; |
| 10552 | } |
| 10553 | } else if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 10554 | cmd->advertising |= ADVERTISED_Asym_Pause; |
| 10555 | } |
| 10556 | } |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 10557 | if (netif_running(dev) && netif_carrier_ok(dev)) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 10558 | ethtool_cmd_speed_set(cmd, tp->link_config.active_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10559 | cmd->duplex = tp->link_config.active_duplex; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 10560 | cmd->lp_advertising = tp->link_config.rmt_adv; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 10561 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 10562 | if (tp->phy_flags & TG3_PHYFLG_MDIX_STATE) |
| 10563 | cmd->eth_tp_mdix = ETH_TP_MDI_X; |
| 10564 | else |
| 10565 | cmd->eth_tp_mdix = ETH_TP_MDI; |
| 10566 | } |
Matt Carlson | 64c2218 | 2010-10-14 10:37:44 +0000 | [diff] [blame] | 10567 | } else { |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 10568 | ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN); |
| 10569 | cmd->duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 10570 | cmd->eth_tp_mdix = ETH_TP_MDI_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10571 | } |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 10572 | cmd->phy_address = tp->phy_addr; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10573 | cmd->transceiver = XCVR_INTERNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10574 | cmd->autoneg = tp->link_config.autoneg; |
| 10575 | cmd->maxtxpkt = 0; |
| 10576 | cmd->maxrxpkt = 0; |
| 10577 | return 0; |
| 10578 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10580 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 10581 | { |
| 10582 | struct tg3 *tp = netdev_priv(dev); |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 10583 | u32 speed = ethtool_cmd_speed(cmd); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10584 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10585 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10586 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10587 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10588 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10589 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 10590 | return phy_ethtool_sset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10591 | } |
| 10592 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10593 | if (cmd->autoneg != AUTONEG_ENABLE && |
| 10594 | cmd->autoneg != AUTONEG_DISABLE) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 10595 | return -EINVAL; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10596 | |
| 10597 | if (cmd->autoneg == AUTONEG_DISABLE && |
| 10598 | cmd->duplex != DUPLEX_FULL && |
| 10599 | cmd->duplex != DUPLEX_HALF) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 10600 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10601 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10602 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 10603 | u32 mask = ADVERTISED_Autoneg | |
| 10604 | ADVERTISED_Pause | |
| 10605 | ADVERTISED_Asym_Pause; |
| 10606 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10607 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10608 | mask |= ADVERTISED_1000baseT_Half | |
| 10609 | ADVERTISED_1000baseT_Full; |
| 10610 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10611 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10612 | mask |= ADVERTISED_100baseT_Half | |
| 10613 | ADVERTISED_100baseT_Full | |
| 10614 | ADVERTISED_10baseT_Half | |
| 10615 | ADVERTISED_10baseT_Full | |
| 10616 | ADVERTISED_TP; |
| 10617 | else |
| 10618 | mask |= ADVERTISED_FIBRE; |
| 10619 | |
| 10620 | if (cmd->advertising & ~mask) |
| 10621 | return -EINVAL; |
| 10622 | |
| 10623 | mask &= (ADVERTISED_1000baseT_Half | |
| 10624 | ADVERTISED_1000baseT_Full | |
| 10625 | ADVERTISED_100baseT_Half | |
| 10626 | ADVERTISED_100baseT_Full | |
| 10627 | ADVERTISED_10baseT_Half | |
| 10628 | ADVERTISED_10baseT_Full); |
| 10629 | |
| 10630 | cmd->advertising &= mask; |
| 10631 | } else { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10632 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 10633 | if (speed != SPEED_1000) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10634 | return -EINVAL; |
| 10635 | |
| 10636 | if (cmd->duplex != DUPLEX_FULL) |
| 10637 | return -EINVAL; |
| 10638 | } else { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 10639 | if (speed != SPEED_100 && |
| 10640 | speed != SPEED_10) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10641 | return -EINVAL; |
| 10642 | } |
| 10643 | } |
| 10644 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10645 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10646 | |
| 10647 | tp->link_config.autoneg = cmd->autoneg; |
| 10648 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Andy Gospodarek | 405d8e5 | 2007-10-08 01:08:47 -0700 | [diff] [blame] | 10649 | tp->link_config.advertising = (cmd->advertising | |
| 10650 | ADVERTISED_Autoneg); |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 10651 | tp->link_config.speed = SPEED_UNKNOWN; |
| 10652 | tp->link_config.duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10653 | } else { |
| 10654 | tp->link_config.advertising = 0; |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 10655 | tp->link_config.speed = speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10656 | tp->link_config.duplex = cmd->duplex; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10657 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10659 | if (netif_running(dev)) |
| 10660 | tg3_setup_phy(tp, 1); |
| 10661 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10662 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10664 | return 0; |
| 10665 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10667 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 10668 | { |
| 10669 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10670 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 10671 | strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); |
| 10672 | strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); |
| 10673 | strlcpy(info->fw_version, tp->fw_ver, sizeof(info->fw_version)); |
| 10674 | strlcpy(info->bus_info, pci_name(tp->pdev), sizeof(info->bus_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10675 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10677 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 10678 | { |
| 10679 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10680 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10681 | if (tg3_flag(tp, WOL_CAP) && device_can_wakeup(&tp->pdev->dev)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 10682 | wol->supported = WAKE_MAGIC; |
| 10683 | else |
| 10684 | wol->supported = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10685 | wol->wolopts = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10686 | if (tg3_flag(tp, WOL_ENABLE) && device_can_wakeup(&tp->pdev->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10687 | wol->wolopts = WAKE_MAGIC; |
| 10688 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 10689 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10691 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 10692 | { |
| 10693 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 10694 | struct device *dp = &tp->pdev->dev; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10695 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10696 | if (wol->wolopts & ~WAKE_MAGIC) |
| 10697 | return -EINVAL; |
| 10698 | if ((wol->wolopts & WAKE_MAGIC) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10699 | !(tg3_flag(tp, WOL_CAP) && device_can_wakeup(dp))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10700 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10701 | |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 10702 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
| 10703 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10704 | spin_lock_bh(&tp->lock); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 10705 | if (device_may_wakeup(dp)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10706 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 10707 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10708 | tg3_flag_clear(tp, WOL_ENABLE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10709 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10711 | return 0; |
| 10712 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10714 | static u32 tg3_get_msglevel(struct net_device *dev) |
| 10715 | { |
| 10716 | struct tg3 *tp = netdev_priv(dev); |
| 10717 | return tp->msg_enable; |
| 10718 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10720 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
| 10721 | { |
| 10722 | struct tg3 *tp = netdev_priv(dev); |
| 10723 | tp->msg_enable = value; |
| 10724 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10726 | static int tg3_nway_reset(struct net_device *dev) |
| 10727 | { |
| 10728 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10729 | int r; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10731 | if (!netif_running(dev)) |
| 10732 | return -EAGAIN; |
| 10733 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10734 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10735 | return -EINVAL; |
| 10736 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10737 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10738 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10739 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10740 | 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] | 10741 | } else { |
| 10742 | u32 bmcr; |
| 10743 | |
| 10744 | spin_lock_bh(&tp->lock); |
| 10745 | r = -EINVAL; |
| 10746 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 10747 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && |
| 10748 | ((bmcr & BMCR_ANENABLE) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10749 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10750 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
| 10751 | BMCR_ANENABLE); |
| 10752 | r = 0; |
| 10753 | } |
| 10754 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10755 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10757 | return r; |
| 10758 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10760 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 10761 | { |
| 10762 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10763 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10764 | ering->rx_max_pending = tp->rx_std_ring_mask; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10765 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10766 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10767 | else |
| 10768 | ering->rx_jumbo_max_pending = 0; |
| 10769 | |
| 10770 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10771 | |
| 10772 | ering->rx_pending = tp->rx_pending; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10773 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10774 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
| 10775 | else |
| 10776 | ering->rx_jumbo_pending = 0; |
| 10777 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10778 | ering->tx_pending = tp->napi[0].tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10779 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10781 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 10782 | { |
| 10783 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10784 | int i, irq_sync = 0, err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10785 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10786 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
| 10787 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10788 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
| 10789 | (ering->tx_pending <= MAX_SKB_FRAGS) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10790 | (tg3_flag(tp, TSO_BUG) && |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10791 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10792 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10793 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10794 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10795 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10796 | tg3_netif_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10797 | irq_sync = 1; |
| 10798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10799 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10800 | tg3_full_lock(tp, irq_sync); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10802 | tp->rx_pending = ering->rx_pending; |
| 10803 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10804 | if (tg3_flag(tp, MAX_RXPEND_64) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10805 | tp->rx_pending > 63) |
| 10806 | tp->rx_pending = 63; |
| 10807 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10808 | |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 10809 | for (i = 0; i < tp->irq_max; i++) |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10810 | tp->napi[i].tx_pending = ering->tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10811 | |
| 10812 | if (netif_running(dev)) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10813 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10814 | err = tg3_restart_hw(tp, 1); |
| 10815 | if (!err) |
| 10816 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10817 | } |
| 10818 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10819 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10820 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10821 | if (irq_sync && !err) |
| 10822 | tg3_phy_start(tp); |
| 10823 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10824 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10825 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10827 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10828 | { |
| 10829 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10830 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10831 | epause->autoneg = !!tg3_flag(tp, PAUSE_AUTONEG); |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10832 | |
Matt Carlson | 4a2db50 | 2011-12-08 14:40:17 +0000 | [diff] [blame] | 10833 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10834 | epause->rx_pause = 1; |
| 10835 | else |
| 10836 | epause->rx_pause = 0; |
| 10837 | |
Matt Carlson | 4a2db50 | 2011-12-08 14:40:17 +0000 | [diff] [blame] | 10838 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10839 | epause->tx_pause = 1; |
| 10840 | else |
| 10841 | epause->tx_pause = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10842 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10844 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10845 | { |
| 10846 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10847 | int err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10848 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10849 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10850 | u32 newadv; |
| 10851 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10852 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10853 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10854 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10855 | if (!(phydev->supported & SUPPORTED_Pause) || |
| 10856 | (!(phydev->supported & SUPPORTED_Asym_Pause) && |
Nicolas Kaiser | 2259dca | 2010-10-07 23:29:27 +0000 | [diff] [blame] | 10857 | (epause->rx_pause != epause->tx_pause))) |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10858 | return -EINVAL; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10859 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10860 | tp->link_config.flowctrl = 0; |
| 10861 | if (epause->rx_pause) { |
| 10862 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10863 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10864 | if (epause->tx_pause) { |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10865 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10866 | newadv = ADVERTISED_Pause; |
| 10867 | } else |
| 10868 | newadv = ADVERTISED_Pause | |
| 10869 | ADVERTISED_Asym_Pause; |
| 10870 | } else if (epause->tx_pause) { |
| 10871 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 10872 | newadv = ADVERTISED_Asym_Pause; |
| 10873 | } else |
| 10874 | newadv = 0; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10875 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10876 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10877 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10878 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10879 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10880 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10881 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10882 | u32 oldadv = phydev->advertising & |
| 10883 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 10884 | if (oldadv != newadv) { |
| 10885 | phydev->advertising &= |
| 10886 | ~(ADVERTISED_Pause | |
| 10887 | ADVERTISED_Asym_Pause); |
| 10888 | phydev->advertising |= newadv; |
| 10889 | if (phydev->autoneg) { |
| 10890 | /* |
| 10891 | * Always renegotiate the link to |
| 10892 | * inform our link partner of our |
| 10893 | * flow control settings, even if the |
| 10894 | * flow control is forced. Let |
| 10895 | * tg3_adjust_link() do the final |
| 10896 | * flow control setup. |
| 10897 | */ |
| 10898 | return phy_start_aneg(phydev); |
| 10899 | } |
| 10900 | } |
| 10901 | |
| 10902 | if (!epause->autoneg) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10903 | tg3_setup_flow_control(tp, 0, 0); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10904 | } else { |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 10905 | tp->link_config.advertising &= |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10906 | ~(ADVERTISED_Pause | |
| 10907 | ADVERTISED_Asym_Pause); |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 10908 | tp->link_config.advertising |= newadv; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10909 | } |
| 10910 | } else { |
| 10911 | int irq_sync = 0; |
| 10912 | |
| 10913 | if (netif_running(dev)) { |
| 10914 | tg3_netif_stop(tp); |
| 10915 | irq_sync = 1; |
| 10916 | } |
| 10917 | |
| 10918 | tg3_full_lock(tp, irq_sync); |
| 10919 | |
| 10920 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10921 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10922 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10923 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10924 | if (epause->rx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10925 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10926 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10927 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10928 | if (epause->tx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10929 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10930 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10931 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10932 | |
| 10933 | if (netif_running(dev)) { |
| 10934 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 10935 | err = tg3_restart_hw(tp, 1); |
| 10936 | if (!err) |
| 10937 | tg3_netif_start(tp); |
| 10938 | } |
| 10939 | |
| 10940 | tg3_full_unlock(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10941 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10942 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10943 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10944 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10945 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10946 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10947 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 10948 | switch (sset) { |
| 10949 | case ETH_SS_TEST: |
| 10950 | return TG3_NUM_TEST; |
| 10951 | case ETH_SS_STATS: |
| 10952 | return TG3_NUM_STATS; |
| 10953 | default: |
| 10954 | return -EOPNOTSUPP; |
| 10955 | } |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10956 | } |
| 10957 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 10958 | static int tg3_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info, |
| 10959 | u32 *rules __always_unused) |
| 10960 | { |
| 10961 | struct tg3 *tp = netdev_priv(dev); |
| 10962 | |
| 10963 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 10964 | return -EOPNOTSUPP; |
| 10965 | |
| 10966 | switch (info->cmd) { |
| 10967 | case ETHTOOL_GRXRINGS: |
| 10968 | if (netif_running(tp->dev)) |
| 10969 | info->data = tp->irq_cnt; |
| 10970 | else { |
| 10971 | info->data = num_online_cpus(); |
| 10972 | if (info->data > TG3_IRQ_MAX_VECS_RSS) |
| 10973 | info->data = TG3_IRQ_MAX_VECS_RSS; |
| 10974 | } |
| 10975 | |
| 10976 | /* The first interrupt vector only |
| 10977 | * handles link interrupts. |
| 10978 | */ |
| 10979 | info->data -= 1; |
| 10980 | return 0; |
| 10981 | |
| 10982 | default: |
| 10983 | return -EOPNOTSUPP; |
| 10984 | } |
| 10985 | } |
| 10986 | |
| 10987 | static u32 tg3_get_rxfh_indir_size(struct net_device *dev) |
| 10988 | { |
| 10989 | u32 size = 0; |
| 10990 | struct tg3 *tp = netdev_priv(dev); |
| 10991 | |
| 10992 | if (tg3_flag(tp, SUPPORT_MSIX)) |
| 10993 | size = TG3_RSS_INDIR_TBL_SIZE; |
| 10994 | |
| 10995 | return size; |
| 10996 | } |
| 10997 | |
| 10998 | static int tg3_get_rxfh_indir(struct net_device *dev, u32 *indir) |
| 10999 | { |
| 11000 | struct tg3 *tp = netdev_priv(dev); |
| 11001 | int i; |
| 11002 | |
| 11003 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 11004 | indir[i] = tp->rss_ind_tbl[i]; |
| 11005 | |
| 11006 | return 0; |
| 11007 | } |
| 11008 | |
| 11009 | static int tg3_set_rxfh_indir(struct net_device *dev, const u32 *indir) |
| 11010 | { |
| 11011 | struct tg3 *tp = netdev_priv(dev); |
| 11012 | size_t i; |
| 11013 | |
| 11014 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 11015 | tp->rss_ind_tbl[i] = indir[i]; |
| 11016 | |
| 11017 | if (!netif_running(dev) || !tg3_flag(tp, ENABLE_RSS)) |
| 11018 | return 0; |
| 11019 | |
| 11020 | /* It is legal to write the indirection |
| 11021 | * table while the device is running. |
| 11022 | */ |
| 11023 | tg3_full_lock(tp, 0); |
| 11024 | tg3_rss_write_indir_tbl(tp); |
| 11025 | tg3_full_unlock(tp); |
| 11026 | |
| 11027 | return 0; |
| 11028 | } |
| 11029 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 11030 | 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] | 11031 | { |
| 11032 | switch (stringset) { |
| 11033 | case ETH_SS_STATS: |
| 11034 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 11035 | break; |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11036 | case ETH_SS_TEST: |
| 11037 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); |
| 11038 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11039 | default: |
| 11040 | WARN_ON(1); /* we need a WARN() */ |
| 11041 | break; |
| 11042 | } |
| 11043 | } |
| 11044 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11045 | static int tg3_set_phys_id(struct net_device *dev, |
| 11046 | enum ethtool_phys_id_state state) |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11047 | { |
| 11048 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11049 | |
| 11050 | if (!netif_running(tp->dev)) |
| 11051 | return -EAGAIN; |
| 11052 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11053 | switch (state) { |
| 11054 | case ETHTOOL_ID_ACTIVE: |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 11055 | return 1; /* cycle on/off once per second */ |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11056 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11057 | case ETHTOOL_ID_ON: |
| 11058 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 11059 | LED_CTRL_1000MBPS_ON | |
| 11060 | LED_CTRL_100MBPS_ON | |
| 11061 | LED_CTRL_10MBPS_ON | |
| 11062 | LED_CTRL_TRAFFIC_OVERRIDE | |
| 11063 | LED_CTRL_TRAFFIC_BLINK | |
| 11064 | LED_CTRL_TRAFFIC_LED); |
| 11065 | break; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11066 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11067 | case ETHTOOL_ID_OFF: |
| 11068 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 11069 | LED_CTRL_TRAFFIC_OVERRIDE); |
| 11070 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11071 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11072 | case ETHTOOL_ID_INACTIVE: |
| 11073 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 11074 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11075 | } |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11076 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11077 | return 0; |
| 11078 | } |
| 11079 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 11080 | static void tg3_get_ethtool_stats(struct net_device *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11081 | struct ethtool_stats *estats, u64 *tmp_stats) |
| 11082 | { |
| 11083 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 0e6c9da | 2011-12-08 14:40:13 +0000 | [diff] [blame] | 11084 | |
Matt Carlson | b546e46 | 2012-02-13 15:20:09 +0000 | [diff] [blame] | 11085 | if (tp->hw_stats) |
| 11086 | tg3_get_estats(tp, (struct tg3_ethtool_stats *)tmp_stats); |
| 11087 | else |
| 11088 | memset(tmp_stats, 0, sizeof(struct tg3_ethtool_stats)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11089 | } |
| 11090 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11091 | static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11092 | { |
| 11093 | int i; |
| 11094 | __be32 *buf; |
| 11095 | u32 offset = 0, len = 0; |
| 11096 | u32 magic, val; |
| 11097 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11098 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &magic)) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11099 | return NULL; |
| 11100 | |
| 11101 | if (magic == TG3_EEPROM_MAGIC) { |
| 11102 | for (offset = TG3_NVM_DIR_START; |
| 11103 | offset < TG3_NVM_DIR_END; |
| 11104 | offset += TG3_NVM_DIRENT_SIZE) { |
| 11105 | if (tg3_nvram_read(tp, offset, &val)) |
| 11106 | return NULL; |
| 11107 | |
| 11108 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == |
| 11109 | TG3_NVM_DIRTYPE_EXTVPD) |
| 11110 | break; |
| 11111 | } |
| 11112 | |
| 11113 | if (offset != TG3_NVM_DIR_END) { |
| 11114 | len = (val & TG3_NVM_DIRTYPE_LENMSK) * 4; |
| 11115 | if (tg3_nvram_read(tp, offset + 4, &offset)) |
| 11116 | return NULL; |
| 11117 | |
| 11118 | offset = tg3_nvram_logical_addr(tp, offset); |
| 11119 | } |
| 11120 | } |
| 11121 | |
| 11122 | if (!offset || !len) { |
| 11123 | offset = TG3_NVM_VPD_OFF; |
| 11124 | len = TG3_NVM_VPD_LEN; |
| 11125 | } |
| 11126 | |
| 11127 | buf = kmalloc(len, GFP_KERNEL); |
| 11128 | if (buf == NULL) |
| 11129 | return NULL; |
| 11130 | |
| 11131 | if (magic == TG3_EEPROM_MAGIC) { |
| 11132 | for (i = 0; i < len; i += 4) { |
| 11133 | /* The data is in little-endian format in NVRAM. |
| 11134 | * Use the big-endian read routines to preserve |
| 11135 | * the byte order as it exists in NVRAM. |
| 11136 | */ |
| 11137 | if (tg3_nvram_read_be32(tp, offset + i, &buf[i/4])) |
| 11138 | goto error; |
| 11139 | } |
| 11140 | } else { |
| 11141 | u8 *ptr; |
| 11142 | ssize_t cnt; |
| 11143 | unsigned int pos = 0; |
| 11144 | |
| 11145 | ptr = (u8 *)&buf[0]; |
| 11146 | for (i = 0; pos < len && i < 3; i++, pos += cnt, ptr += cnt) { |
| 11147 | cnt = pci_read_vpd(tp->pdev, pos, |
| 11148 | len - pos, ptr); |
| 11149 | if (cnt == -ETIMEDOUT || cnt == -EINTR) |
| 11150 | cnt = 0; |
| 11151 | else if (cnt < 0) |
| 11152 | goto error; |
| 11153 | } |
| 11154 | if (pos != len) |
| 11155 | goto error; |
| 11156 | } |
| 11157 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11158 | *vpdlen = len; |
| 11159 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11160 | return buf; |
| 11161 | |
| 11162 | error: |
| 11163 | kfree(buf); |
| 11164 | return NULL; |
| 11165 | } |
| 11166 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11167 | #define NVRAM_TEST_SIZE 0x100 |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11168 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
| 11169 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 |
| 11170 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11171 | #define NVRAM_SELFBOOT_FORMAT1_4_SIZE 0x20 |
| 11172 | #define NVRAM_SELFBOOT_FORMAT1_5_SIZE 0x24 |
Matt Carlson | bda18fa | 2011-07-20 10:20:57 +0000 | [diff] [blame] | 11173 | #define NVRAM_SELFBOOT_FORMAT1_6_SIZE 0x50 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11174 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
| 11175 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11176 | |
| 11177 | static int tg3_test_nvram(struct tg3 *tp) |
| 11178 | { |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11179 | u32 csum, magic, len; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11180 | __be32 *buf; |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 11181 | int i, j, k, err = 0, size; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11182 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11183 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11184 | return 0; |
| 11185 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11186 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11187 | return -EIO; |
| 11188 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11189 | if (magic == TG3_EEPROM_MAGIC) |
| 11190 | size = NVRAM_TEST_SIZE; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11191 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11192 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
| 11193 | TG3_EEPROM_SB_FORMAT_1) { |
| 11194 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { |
| 11195 | case TG3_EEPROM_SB_REVISION_0: |
| 11196 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; |
| 11197 | break; |
| 11198 | case TG3_EEPROM_SB_REVISION_2: |
| 11199 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; |
| 11200 | break; |
| 11201 | case TG3_EEPROM_SB_REVISION_3: |
| 11202 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; |
| 11203 | break; |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11204 | case TG3_EEPROM_SB_REVISION_4: |
| 11205 | size = NVRAM_SELFBOOT_FORMAT1_4_SIZE; |
| 11206 | break; |
| 11207 | case TG3_EEPROM_SB_REVISION_5: |
| 11208 | size = NVRAM_SELFBOOT_FORMAT1_5_SIZE; |
| 11209 | break; |
| 11210 | case TG3_EEPROM_SB_REVISION_6: |
| 11211 | size = NVRAM_SELFBOOT_FORMAT1_6_SIZE; |
| 11212 | break; |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11213 | default: |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11214 | return -EIO; |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11215 | } |
| 11216 | } else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11217 | return 0; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11218 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 11219 | size = NVRAM_SELFBOOT_HW_SIZE; |
| 11220 | else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11221 | return -EIO; |
| 11222 | |
| 11223 | buf = kmalloc(size, GFP_KERNEL); |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11224 | if (buf == NULL) |
| 11225 | return -ENOMEM; |
| 11226 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11227 | err = -EIO; |
| 11228 | for (i = 0, j = 0; i < size; i += 4, j++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11229 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
| 11230 | if (err) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11231 | break; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11232 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11233 | if (i < size) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11234 | goto out; |
| 11235 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11236 | /* Selfboot format */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11237 | magic = be32_to_cpu(buf[0]); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11238 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11239 | TG3_EEPROM_MAGIC_FW) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11240 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
| 11241 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11242 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11243 | TG3_EEPROM_SB_REVISION_2) { |
| 11244 | /* For rev 2, the csum doesn't include the MBA. */ |
| 11245 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) |
| 11246 | csum8 += buf8[i]; |
| 11247 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) |
| 11248 | csum8 += buf8[i]; |
| 11249 | } else { |
| 11250 | for (i = 0; i < size; i++) |
| 11251 | csum8 += buf8[i]; |
| 11252 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11253 | |
Adrian Bunk | ad96b48 | 2006-04-05 22:21:04 -0700 | [diff] [blame] | 11254 | if (csum8 == 0) { |
| 11255 | err = 0; |
| 11256 | goto out; |
| 11257 | } |
| 11258 | |
| 11259 | err = -EIO; |
| 11260 | goto out; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11261 | } |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11262 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11263 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11264 | TG3_EEPROM_MAGIC_HW) { |
| 11265 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11266 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11267 | u8 *buf8 = (u8 *) buf; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11268 | |
| 11269 | /* Separate the parity bits and the data bytes. */ |
| 11270 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { |
| 11271 | if ((i == 0) || (i == 8)) { |
| 11272 | int l; |
| 11273 | u8 msk; |
| 11274 | |
| 11275 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) |
| 11276 | parity[k++] = buf8[i] & msk; |
| 11277 | i++; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 11278 | } else if (i == 16) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11279 | int l; |
| 11280 | u8 msk; |
| 11281 | |
| 11282 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) |
| 11283 | parity[k++] = buf8[i] & msk; |
| 11284 | i++; |
| 11285 | |
| 11286 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) |
| 11287 | parity[k++] = buf8[i] & msk; |
| 11288 | i++; |
| 11289 | } |
| 11290 | data[j++] = buf8[i]; |
| 11291 | } |
| 11292 | |
| 11293 | err = -EIO; |
| 11294 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { |
| 11295 | u8 hw8 = hweight8(data[i]); |
| 11296 | |
| 11297 | if ((hw8 & 0x1) && parity[i]) |
| 11298 | goto out; |
| 11299 | else if (!(hw8 & 0x1) && !parity[i]) |
| 11300 | goto out; |
| 11301 | } |
| 11302 | err = 0; |
| 11303 | goto out; |
| 11304 | } |
| 11305 | |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 11306 | err = -EIO; |
| 11307 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11308 | /* Bootstrap checksum at offset 0x10 */ |
| 11309 | csum = calc_crc((unsigned char *) buf, 0x10); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 11310 | if (csum != le32_to_cpu(buf[0x10/4])) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11311 | goto out; |
| 11312 | |
| 11313 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ |
| 11314 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 11315 | if (csum != le32_to_cpu(buf[0xfc/4])) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11316 | goto out; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11317 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11318 | kfree(buf); |
| 11319 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11320 | buf = tg3_vpd_readblock(tp, &len); |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11321 | if (!buf) |
| 11322 | return -ENOMEM; |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 11323 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11324 | i = pci_vpd_find_tag((u8 *)buf, 0, len, PCI_VPD_LRDT_RO_DATA); |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 11325 | if (i > 0) { |
| 11326 | j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); |
| 11327 | if (j < 0) |
| 11328 | goto out; |
| 11329 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11330 | if (i + PCI_VPD_LRDT_TAG_SIZE + j > len) |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 11331 | goto out; |
| 11332 | |
| 11333 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 11334 | j = pci_vpd_find_info_keyword((u8 *)buf, i, j, |
| 11335 | PCI_VPD_RO_KEYWORD_CHKSUM); |
| 11336 | if (j > 0) { |
| 11337 | u8 csum8 = 0; |
| 11338 | |
| 11339 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 11340 | |
| 11341 | for (i = 0; i <= j; i++) |
| 11342 | csum8 += ((u8 *)buf)[i]; |
| 11343 | |
| 11344 | if (csum8) |
| 11345 | goto out; |
| 11346 | } |
| 11347 | } |
| 11348 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11349 | err = 0; |
| 11350 | |
| 11351 | out: |
| 11352 | kfree(buf); |
| 11353 | return err; |
| 11354 | } |
| 11355 | |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11356 | #define TG3_SERDES_TIMEOUT_SEC 2 |
| 11357 | #define TG3_COPPER_TIMEOUT_SEC 6 |
| 11358 | |
| 11359 | static int tg3_test_link(struct tg3 *tp) |
| 11360 | { |
| 11361 | int i, max; |
| 11362 | |
| 11363 | if (!netif_running(tp->dev)) |
| 11364 | return -ENODEV; |
| 11365 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11366 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11367 | max = TG3_SERDES_TIMEOUT_SEC; |
| 11368 | else |
| 11369 | max = TG3_COPPER_TIMEOUT_SEC; |
| 11370 | |
| 11371 | for (i = 0; i < max; i++) { |
| 11372 | if (netif_carrier_ok(tp->dev)) |
| 11373 | return 0; |
| 11374 | |
| 11375 | if (msleep_interruptible(1000)) |
| 11376 | break; |
| 11377 | } |
| 11378 | |
| 11379 | return -EIO; |
| 11380 | } |
| 11381 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11382 | /* Only test the commonly used registers */ |
David S. Miller | 30ca3e3 | 2006-03-20 23:02:36 -0800 | [diff] [blame] | 11383 | static int tg3_test_registers(struct tg3 *tp) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11384 | { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11385 | int i, is_5705, is_5750; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11386 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
| 11387 | static struct { |
| 11388 | u16 offset; |
| 11389 | u16 flags; |
| 11390 | #define TG3_FL_5705 0x1 |
| 11391 | #define TG3_FL_NOT_5705 0x2 |
| 11392 | #define TG3_FL_NOT_5788 0x4 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11393 | #define TG3_FL_NOT_5750 0x8 |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11394 | u32 read_mask; |
| 11395 | u32 write_mask; |
| 11396 | } reg_tbl[] = { |
| 11397 | /* MAC Control Registers */ |
| 11398 | { MAC_MODE, TG3_FL_NOT_5705, |
| 11399 | 0x00000000, 0x00ef6f8c }, |
| 11400 | { MAC_MODE, TG3_FL_5705, |
| 11401 | 0x00000000, 0x01ef6b8c }, |
| 11402 | { MAC_STATUS, TG3_FL_NOT_5705, |
| 11403 | 0x03800107, 0x00000000 }, |
| 11404 | { MAC_STATUS, TG3_FL_5705, |
| 11405 | 0x03800100, 0x00000000 }, |
| 11406 | { MAC_ADDR_0_HIGH, 0x0000, |
| 11407 | 0x00000000, 0x0000ffff }, |
| 11408 | { MAC_ADDR_0_LOW, 0x0000, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 11409 | 0x00000000, 0xffffffff }, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11410 | { MAC_RX_MTU_SIZE, 0x0000, |
| 11411 | 0x00000000, 0x0000ffff }, |
| 11412 | { MAC_TX_MODE, 0x0000, |
| 11413 | 0x00000000, 0x00000070 }, |
| 11414 | { MAC_TX_LENGTHS, 0x0000, |
| 11415 | 0x00000000, 0x00003fff }, |
| 11416 | { MAC_RX_MODE, TG3_FL_NOT_5705, |
| 11417 | 0x00000000, 0x000007fc }, |
| 11418 | { MAC_RX_MODE, TG3_FL_5705, |
| 11419 | 0x00000000, 0x000007dc }, |
| 11420 | { MAC_HASH_REG_0, 0x0000, |
| 11421 | 0x00000000, 0xffffffff }, |
| 11422 | { MAC_HASH_REG_1, 0x0000, |
| 11423 | 0x00000000, 0xffffffff }, |
| 11424 | { MAC_HASH_REG_2, 0x0000, |
| 11425 | 0x00000000, 0xffffffff }, |
| 11426 | { MAC_HASH_REG_3, 0x0000, |
| 11427 | 0x00000000, 0xffffffff }, |
| 11428 | |
| 11429 | /* Receive Data and Receive BD Initiator Control Registers. */ |
| 11430 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, |
| 11431 | 0x00000000, 0xffffffff }, |
| 11432 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, |
| 11433 | 0x00000000, 0xffffffff }, |
| 11434 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, |
| 11435 | 0x00000000, 0x00000003 }, |
| 11436 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, |
| 11437 | 0x00000000, 0xffffffff }, |
| 11438 | { RCVDBDI_STD_BD+0, 0x0000, |
| 11439 | 0x00000000, 0xffffffff }, |
| 11440 | { RCVDBDI_STD_BD+4, 0x0000, |
| 11441 | 0x00000000, 0xffffffff }, |
| 11442 | { RCVDBDI_STD_BD+8, 0x0000, |
| 11443 | 0x00000000, 0xffff0002 }, |
| 11444 | { RCVDBDI_STD_BD+0xc, 0x0000, |
| 11445 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11446 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11447 | /* Receive BD Initiator Control Registers. */ |
| 11448 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, |
| 11449 | 0x00000000, 0xffffffff }, |
| 11450 | { RCVBDI_STD_THRESH, TG3_FL_5705, |
| 11451 | 0x00000000, 0x000003ff }, |
| 11452 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, |
| 11453 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11454 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11455 | /* Host Coalescing Control Registers. */ |
| 11456 | { HOSTCC_MODE, TG3_FL_NOT_5705, |
| 11457 | 0x00000000, 0x00000004 }, |
| 11458 | { HOSTCC_MODE, TG3_FL_5705, |
| 11459 | 0x00000000, 0x000000f6 }, |
| 11460 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, |
| 11461 | 0x00000000, 0xffffffff }, |
| 11462 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, |
| 11463 | 0x00000000, 0x000003ff }, |
| 11464 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, |
| 11465 | 0x00000000, 0xffffffff }, |
| 11466 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, |
| 11467 | 0x00000000, 0x000003ff }, |
| 11468 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, |
| 11469 | 0x00000000, 0xffffffff }, |
| 11470 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11471 | 0x00000000, 0x000000ff }, |
| 11472 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, |
| 11473 | 0x00000000, 0xffffffff }, |
| 11474 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11475 | 0x00000000, 0x000000ff }, |
| 11476 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 11477 | 0x00000000, 0xffffffff }, |
| 11478 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 11479 | 0x00000000, 0xffffffff }, |
| 11480 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 11481 | 0x00000000, 0xffffffff }, |
| 11482 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11483 | 0x00000000, 0x000000ff }, |
| 11484 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 11485 | 0x00000000, 0xffffffff }, |
| 11486 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11487 | 0x00000000, 0x000000ff }, |
| 11488 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, |
| 11489 | 0x00000000, 0xffffffff }, |
| 11490 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, |
| 11491 | 0x00000000, 0xffffffff }, |
| 11492 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, |
| 11493 | 0x00000000, 0xffffffff }, |
| 11494 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, |
| 11495 | 0x00000000, 0xffffffff }, |
| 11496 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, |
| 11497 | 0x00000000, 0xffffffff }, |
| 11498 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, |
| 11499 | 0xffffffff, 0x00000000 }, |
| 11500 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, |
| 11501 | 0xffffffff, 0x00000000 }, |
| 11502 | |
| 11503 | /* Buffer Manager Control Registers. */ |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11504 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11505 | 0x00000000, 0x007fff80 }, |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11506 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11507 | 0x00000000, 0x007fffff }, |
| 11508 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, |
| 11509 | 0x00000000, 0x0000003f }, |
| 11510 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, |
| 11511 | 0x00000000, 0x000001ff }, |
| 11512 | { BUFMGR_MB_HIGH_WATER, 0x0000, |
| 11513 | 0x00000000, 0x000001ff }, |
| 11514 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, |
| 11515 | 0xffffffff, 0x00000000 }, |
| 11516 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, |
| 11517 | 0xffffffff, 0x00000000 }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11518 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11519 | /* Mailbox Registers */ |
| 11520 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, |
| 11521 | 0x00000000, 0x000001ff }, |
| 11522 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, |
| 11523 | 0x00000000, 0x000001ff }, |
| 11524 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, |
| 11525 | 0x00000000, 0x000007ff }, |
| 11526 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, |
| 11527 | 0x00000000, 0x000001ff }, |
| 11528 | |
| 11529 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, |
| 11530 | }; |
| 11531 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11532 | is_5705 = is_5750 = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11533 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11534 | is_5705 = 1; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11535 | if (tg3_flag(tp, 5750_PLUS)) |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11536 | is_5750 = 1; |
| 11537 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11538 | |
| 11539 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { |
| 11540 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) |
| 11541 | continue; |
| 11542 | |
| 11543 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) |
| 11544 | continue; |
| 11545 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11546 | if (tg3_flag(tp, IS_5788) && |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11547 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
| 11548 | continue; |
| 11549 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11550 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
| 11551 | continue; |
| 11552 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11553 | offset = (u32) reg_tbl[i].offset; |
| 11554 | read_mask = reg_tbl[i].read_mask; |
| 11555 | write_mask = reg_tbl[i].write_mask; |
| 11556 | |
| 11557 | /* Save the original register content */ |
| 11558 | save_val = tr32(offset); |
| 11559 | |
| 11560 | /* Determine the read-only value. */ |
| 11561 | read_val = save_val & read_mask; |
| 11562 | |
| 11563 | /* Write zero to the register, then make sure the read-only bits |
| 11564 | * are not changed and the read/write bits are all zeros. |
| 11565 | */ |
| 11566 | tw32(offset, 0); |
| 11567 | |
| 11568 | val = tr32(offset); |
| 11569 | |
| 11570 | /* Test the read-only and read/write bits. */ |
| 11571 | if (((val & read_mask) != read_val) || (val & write_mask)) |
| 11572 | goto out; |
| 11573 | |
| 11574 | /* Write ones to all the bits defined by RdMask and WrMask, then |
| 11575 | * make sure the read-only bits are not changed and the |
| 11576 | * read/write bits are all ones. |
| 11577 | */ |
| 11578 | tw32(offset, read_mask | write_mask); |
| 11579 | |
| 11580 | val = tr32(offset); |
| 11581 | |
| 11582 | /* Test the read-only bits. */ |
| 11583 | if ((val & read_mask) != read_val) |
| 11584 | goto out; |
| 11585 | |
| 11586 | /* Test the read/write bits. */ |
| 11587 | if ((val & write_mask) != write_mask) |
| 11588 | goto out; |
| 11589 | |
| 11590 | tw32(offset, save_val); |
| 11591 | } |
| 11592 | |
| 11593 | return 0; |
| 11594 | |
| 11595 | out: |
Michael Chan | 9f88f29 | 2006-12-07 00:22:54 -0800 | [diff] [blame] | 11596 | if (netif_msg_hw(tp)) |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 11597 | netdev_err(tp->dev, |
| 11598 | "Register test failed at offset %x\n", offset); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11599 | tw32(offset, save_val); |
| 11600 | return -EIO; |
| 11601 | } |
| 11602 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11603 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
| 11604 | { |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 11605 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11606 | int i; |
| 11607 | u32 j; |
| 11608 | |
Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 11609 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11610 | for (j = 0; j < len; j += 4) { |
| 11611 | u32 val; |
| 11612 | |
| 11613 | tg3_write_mem(tp, offset + j, test_pattern[i]); |
| 11614 | tg3_read_mem(tp, offset + j, &val); |
| 11615 | if (val != test_pattern[i]) |
| 11616 | return -EIO; |
| 11617 | } |
| 11618 | } |
| 11619 | return 0; |
| 11620 | } |
| 11621 | |
| 11622 | static int tg3_test_memory(struct tg3 *tp) |
| 11623 | { |
| 11624 | static struct mem_entry { |
| 11625 | u32 offset; |
| 11626 | u32 len; |
| 11627 | } mem_tbl_570x[] = { |
Michael Chan | 3869019 | 2005-12-19 16:27:28 -0800 | [diff] [blame] | 11628 | { 0x00000000, 0x00b50}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11629 | { 0x00002000, 0x1c000}, |
| 11630 | { 0xffffffff, 0x00000} |
| 11631 | }, mem_tbl_5705[] = { |
| 11632 | { 0x00000100, 0x0000c}, |
| 11633 | { 0x00000200, 0x00008}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11634 | { 0x00004000, 0x00800}, |
| 11635 | { 0x00006000, 0x01000}, |
| 11636 | { 0x00008000, 0x02000}, |
| 11637 | { 0x00010000, 0x0e000}, |
| 11638 | { 0xffffffff, 0x00000} |
Michael Chan | 79f4d13 | 2006-03-20 22:28:57 -0800 | [diff] [blame] | 11639 | }, mem_tbl_5755[] = { |
| 11640 | { 0x00000200, 0x00008}, |
| 11641 | { 0x00004000, 0x00800}, |
| 11642 | { 0x00006000, 0x00800}, |
| 11643 | { 0x00008000, 0x02000}, |
| 11644 | { 0x00010000, 0x0c000}, |
| 11645 | { 0xffffffff, 0x00000} |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11646 | }, mem_tbl_5906[] = { |
| 11647 | { 0x00000200, 0x00008}, |
| 11648 | { 0x00004000, 0x00400}, |
| 11649 | { 0x00006000, 0x00400}, |
| 11650 | { 0x00008000, 0x01000}, |
| 11651 | { 0x00010000, 0x01000}, |
| 11652 | { 0xffffffff, 0x00000} |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 11653 | }, mem_tbl_5717[] = { |
| 11654 | { 0x00000200, 0x00008}, |
| 11655 | { 0x00010000, 0x0a000}, |
| 11656 | { 0x00020000, 0x13c00}, |
| 11657 | { 0xffffffff, 0x00000} |
| 11658 | }, mem_tbl_57765[] = { |
| 11659 | { 0x00000200, 0x00008}, |
| 11660 | { 0x00004000, 0x00800}, |
| 11661 | { 0x00006000, 0x09800}, |
| 11662 | { 0x00010000, 0x0a000}, |
| 11663 | { 0xffffffff, 0x00000} |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11664 | }; |
| 11665 | struct mem_entry *mem_tbl; |
| 11666 | int err = 0; |
| 11667 | int i; |
| 11668 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11669 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 11670 | mem_tbl = mem_tbl_5717; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 11671 | else if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 11672 | mem_tbl = mem_tbl_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11673 | else if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11674 | mem_tbl = mem_tbl_5755; |
| 11675 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 11676 | mem_tbl = mem_tbl_5906; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11677 | else if (tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11678 | mem_tbl = mem_tbl_5705; |
| 11679 | else |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11680 | mem_tbl = mem_tbl_570x; |
| 11681 | |
| 11682 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 11683 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
| 11684 | if (err) |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11685 | break; |
| 11686 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11687 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11688 | return err; |
| 11689 | } |
| 11690 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11691 | #define TG3_TSO_MSS 500 |
| 11692 | |
| 11693 | #define TG3_TSO_IP_HDR_LEN 20 |
| 11694 | #define TG3_TSO_TCP_HDR_LEN 20 |
| 11695 | #define TG3_TSO_TCP_OPT_LEN 12 |
| 11696 | |
| 11697 | static const u8 tg3_tso_header[] = { |
| 11698 | 0x08, 0x00, |
| 11699 | 0x45, 0x00, 0x00, 0x00, |
| 11700 | 0x00, 0x00, 0x40, 0x00, |
| 11701 | 0x40, 0x06, 0x00, 0x00, |
| 11702 | 0x0a, 0x00, 0x00, 0x01, |
| 11703 | 0x0a, 0x00, 0x00, 0x02, |
| 11704 | 0x0d, 0x00, 0xe0, 0x00, |
| 11705 | 0x00, 0x00, 0x01, 0x00, |
| 11706 | 0x00, 0x00, 0x02, 0x00, |
| 11707 | 0x80, 0x10, 0x10, 0x00, |
| 11708 | 0x14, 0x09, 0x00, 0x00, |
| 11709 | 0x01, 0x01, 0x08, 0x0a, |
| 11710 | 0x11, 0x11, 0x11, 0x11, |
| 11711 | 0x11, 0x11, 0x11, 0x11, |
| 11712 | }; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11713 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11714 | static int tg3_run_loopback(struct tg3 *tp, u32 pktsz, bool tso_loopback) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11715 | { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 11716 | u32 rx_start_idx, rx_idx, tx_idx, opaque_key; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11717 | u32 base_flags = 0, mss = 0, desc_idx, coal_now, data_off, val; |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 11718 | u32 budget; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11719 | struct sk_buff *skb; |
| 11720 | u8 *tx_data, *rx_data; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11721 | dma_addr_t map; |
| 11722 | int num_pkts, tx_len, rx_len, i, err; |
| 11723 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 11724 | struct tg3_napi *tnapi, *rnapi; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 11725 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11726 | |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 11727 | tnapi = &tp->napi[0]; |
| 11728 | rnapi = &tp->napi[0]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 11729 | if (tp->irq_cnt > 1) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11730 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | 1da85aa | 2010-09-30 10:34:34 +0000 | [diff] [blame] | 11731 | rnapi = &tp->napi[1]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11732 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 11733 | tnapi = &tp->napi[1]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 11734 | } |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 11735 | coal_now = tnapi->coal_now | rnapi->coal_now; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 11736 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11737 | err = -EIO; |
| 11738 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11739 | tx_len = pktsz; |
David S. Miller | a20e9c6 | 2006-07-31 22:38:16 -0700 | [diff] [blame] | 11740 | skb = netdev_alloc_skb(tp->dev, tx_len); |
Jesper Juhl | a50bb7b | 2006-05-09 23:14:35 -0700 | [diff] [blame] | 11741 | if (!skb) |
| 11742 | return -ENOMEM; |
| 11743 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11744 | tx_data = skb_put(skb, tx_len); |
| 11745 | memcpy(tx_data, tp->dev->dev_addr, 6); |
| 11746 | memset(tx_data + 6, 0x0, 8); |
| 11747 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11748 | tw32(MAC_RX_MTU_SIZE, tx_len + ETH_FCS_LEN); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11749 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11750 | if (tso_loopback) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11751 | struct iphdr *iph = (struct iphdr *)&tx_data[ETH_HLEN]; |
| 11752 | |
| 11753 | u32 hdr_len = TG3_TSO_IP_HDR_LEN + TG3_TSO_TCP_HDR_LEN + |
| 11754 | TG3_TSO_TCP_OPT_LEN; |
| 11755 | |
| 11756 | memcpy(tx_data + ETH_ALEN * 2, tg3_tso_header, |
| 11757 | sizeof(tg3_tso_header)); |
| 11758 | mss = TG3_TSO_MSS; |
| 11759 | |
| 11760 | val = tx_len - ETH_ALEN * 2 - sizeof(tg3_tso_header); |
| 11761 | num_pkts = DIV_ROUND_UP(val, TG3_TSO_MSS); |
| 11762 | |
| 11763 | /* Set the total length field in the IP header */ |
| 11764 | iph->tot_len = htons((u16)(mss + hdr_len)); |
| 11765 | |
| 11766 | base_flags = (TXD_FLAG_CPU_PRE_DMA | |
| 11767 | TXD_FLAG_CPU_POST_DMA); |
| 11768 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11769 | if (tg3_flag(tp, HW_TSO_1) || |
| 11770 | tg3_flag(tp, HW_TSO_2) || |
| 11771 | tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11772 | struct tcphdr *th; |
| 11773 | val = ETH_HLEN + TG3_TSO_IP_HDR_LEN; |
| 11774 | th = (struct tcphdr *)&tx_data[val]; |
| 11775 | th->check = 0; |
| 11776 | } else |
| 11777 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
| 11778 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11779 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11780 | mss |= (hdr_len & 0xc) << 12; |
| 11781 | if (hdr_len & 0x10) |
| 11782 | base_flags |= 0x00000010; |
| 11783 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11784 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11785 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11786 | else if (tg3_flag(tp, HW_TSO_1) || |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11787 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 11788 | mss |= (TG3_TSO_TCP_OPT_LEN << 9); |
| 11789 | } else { |
| 11790 | base_flags |= (TG3_TSO_TCP_OPT_LEN << 10); |
| 11791 | } |
| 11792 | |
| 11793 | data_off = ETH_ALEN * 2 + sizeof(tg3_tso_header); |
| 11794 | } else { |
| 11795 | num_pkts = 1; |
| 11796 | data_off = ETH_HLEN; |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 11797 | |
| 11798 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 11799 | tx_len > VLAN_ETH_FRAME_LEN) |
| 11800 | base_flags |= TXD_FLAG_JMB_PKT; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11801 | } |
| 11802 | |
| 11803 | for (i = data_off; i < tx_len; i++) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11804 | tx_data[i] = (u8) (i & 0xff); |
| 11805 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 11806 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
| 11807 | if (pci_dma_mapping_error(tp->pdev, map)) { |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 11808 | dev_kfree_skb(skb); |
| 11809 | return -EIO; |
| 11810 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11811 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 11812 | val = tnapi->tx_prod; |
| 11813 | tnapi->tx_buffers[val].skb = skb; |
| 11814 | dma_unmap_addr_set(&tnapi->tx_buffers[val], mapping, map); |
| 11815 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11816 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 11817 | rnapi->coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11818 | |
| 11819 | udelay(10); |
| 11820 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 11821 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11822 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 11823 | budget = tg3_tx_avail(tnapi); |
| 11824 | if (tg3_tx_frag_set(tnapi, &val, &budget, map, tx_len, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 11825 | base_flags | TXD_FLAG_END, mss, 0)) { |
| 11826 | tnapi->tx_buffers[val].skb = NULL; |
| 11827 | dev_kfree_skb(skb); |
| 11828 | return -EIO; |
| 11829 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11830 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11831 | tnapi->tx_prod++; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11832 | |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 11833 | /* Sync BD data before updating mailbox */ |
| 11834 | wmb(); |
| 11835 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11836 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 11837 | tr32_mailbox(tnapi->prodmbox); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11838 | |
| 11839 | udelay(10); |
| 11840 | |
Matt Carlson | 303fc92 | 2009-11-02 14:27:34 +0000 | [diff] [blame] | 11841 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
| 11842 | for (i = 0; i < 35; i++) { |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11843 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 11844 | coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11845 | |
| 11846 | udelay(10); |
| 11847 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 11848 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 11849 | rx_idx = rnapi->hw_status->idx[0].rx_producer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11850 | if ((tx_idx == tnapi->tx_prod) && |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11851 | (rx_idx == (rx_start_idx + num_pkts))) |
| 11852 | break; |
| 11853 | } |
| 11854 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 11855 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod - 1, -1); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11856 | dev_kfree_skb(skb); |
| 11857 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11858 | if (tx_idx != tnapi->tx_prod) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11859 | goto out; |
| 11860 | |
| 11861 | if (rx_idx != rx_start_idx + num_pkts) |
| 11862 | goto out; |
| 11863 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11864 | val = data_off; |
| 11865 | while (rx_idx != rx_start_idx) { |
| 11866 | desc = &rnapi->rx_rcb[rx_start_idx++]; |
| 11867 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 11868 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11869 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11870 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 11871 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11872 | goto out; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11873 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11874 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) |
| 11875 | - ETH_FCS_LEN; |
| 11876 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11877 | if (!tso_loopback) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11878 | if (rx_len != tx_len) |
| 11879 | goto out; |
| 11880 | |
| 11881 | if (pktsz <= TG3_RX_STD_DMA_SZ - ETH_FCS_LEN) { |
| 11882 | if (opaque_key != RXD_OPAQUE_RING_STD) |
| 11883 | goto out; |
| 11884 | } else { |
| 11885 | if (opaque_key != RXD_OPAQUE_RING_JUMBO) |
| 11886 | goto out; |
| 11887 | } |
| 11888 | } else if ((desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 11889 | (desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
Matt Carlson | 54e0a67 | 2011-05-19 12:12:50 +0000 | [diff] [blame] | 11890 | >> RXD_TCPCSUM_SHIFT != 0xffff) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11891 | goto out; |
| 11892 | } |
| 11893 | |
| 11894 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11895 | rx_data = tpr->rx_std_buffers[desc_idx].data; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11896 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], |
| 11897 | mapping); |
| 11898 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11899 | rx_data = tpr->rx_jmb_buffers[desc_idx].data; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11900 | map = dma_unmap_addr(&tpr->rx_jmb_buffers[desc_idx], |
| 11901 | mapping); |
| 11902 | } else |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11903 | goto out; |
| 11904 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11905 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, |
| 11906 | PCI_DMA_FROMDEVICE); |
| 11907 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11908 | rx_data += TG3_RX_OFFSET(tp); |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11909 | for (i = data_off; i < rx_len; i++, val++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11910 | if (*(rx_data + i) != (u8) (val & 0xff)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11911 | goto out; |
| 11912 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11913 | } |
| 11914 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11915 | err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11916 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 11917 | /* tg3_free_rings will unmap and free the rx_data */ |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11918 | out: |
| 11919 | return err; |
| 11920 | } |
| 11921 | |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 11922 | #define TG3_STD_LOOPBACK_FAILED 1 |
| 11923 | #define TG3_JMB_LOOPBACK_FAILED 2 |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 11924 | #define TG3_TSO_LOOPBACK_FAILED 4 |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11925 | #define TG3_LOOPBACK_FAILED \ |
| 11926 | (TG3_STD_LOOPBACK_FAILED | \ |
| 11927 | TG3_JMB_LOOPBACK_FAILED | \ |
| 11928 | TG3_TSO_LOOPBACK_FAILED) |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 11929 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 11930 | static int tg3_test_loopback(struct tg3 *tp, u64 *data, bool do_extlpbk) |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11931 | { |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11932 | int err = -EIO; |
Matt Carlson | 2215e24 | 2011-08-19 13:58:19 +0000 | [diff] [blame] | 11933 | u32 eee_cap; |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 11934 | u32 jmb_pkt_sz = 9000; |
| 11935 | |
| 11936 | if (tp->dma_limit) |
| 11937 | jmb_pkt_sz = tp->dma_limit - ETH_HLEN; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11938 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11939 | eee_cap = tp->phy_flags & TG3_PHYFLG_EEE_CAP; |
| 11940 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; |
| 11941 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11942 | if (!netif_running(tp->dev)) { |
| 11943 | data[0] = TG3_LOOPBACK_FAILED; |
| 11944 | data[1] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 11945 | if (do_extlpbk) |
| 11946 | data[2] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11947 | goto done; |
| 11948 | } |
| 11949 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11950 | err = tg3_reset_hw(tp, 1); |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11951 | if (err) { |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11952 | data[0] = TG3_LOOPBACK_FAILED; |
| 11953 | data[1] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 11954 | if (do_extlpbk) |
| 11955 | data[2] = TG3_LOOPBACK_FAILED; |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 11956 | goto done; |
| 11957 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11958 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11959 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 4a85f09 | 2011-04-20 07:57:37 +0000 | [diff] [blame] | 11960 | int i; |
| 11961 | |
| 11962 | /* Reroute all rx packets to the 1st queue */ |
| 11963 | for (i = MAC_RSS_INDIR_TBL_0; |
| 11964 | i < MAC_RSS_INDIR_TBL_0 + TG3_RSS_INDIR_TBL_SIZE; i += 4) |
| 11965 | tw32(i, 0x0); |
| 11966 | } |
| 11967 | |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 11968 | /* HW errata - mac loopback fails in some cases on 5780. |
| 11969 | * Normal traffic and PHY loopback are not affected by |
| 11970 | * errata. Also, the MAC loopback test is deprecated for |
| 11971 | * all newer ASIC revisions. |
| 11972 | */ |
| 11973 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && |
| 11974 | !tg3_flag(tp, CPMU_PRESENT)) { |
| 11975 | tg3_mac_loopback(tp, true); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11976 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11977 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
| 11978 | data[0] |= TG3_STD_LOOPBACK_FAILED; |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 11979 | |
| 11980 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 11981 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 11982 | data[0] |= TG3_JMB_LOOPBACK_FAILED; |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 11983 | |
| 11984 | tg3_mac_loopback(tp, false); |
| 11985 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 11986 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11987 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11988 | !tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 11989 | int i; |
| 11990 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 11991 | tg3_phy_lpbk_set(tp, 0, false); |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 11992 | |
| 11993 | /* Wait for link */ |
| 11994 | for (i = 0; i < 100; i++) { |
| 11995 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 11996 | break; |
| 11997 | mdelay(1); |
| 11998 | } |
| 11999 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12000 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
| 12001 | data[1] |= TG3_STD_LOOPBACK_FAILED; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12002 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12003 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
| 12004 | data[1] |= TG3_TSO_LOOPBACK_FAILED; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12005 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12006 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12007 | data[1] |= TG3_JMB_LOOPBACK_FAILED; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12008 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12009 | if (do_extlpbk) { |
| 12010 | tg3_phy_lpbk_set(tp, 0, true); |
| 12011 | |
| 12012 | /* All link indications report up, but the hardware |
| 12013 | * isn't really ready for about 20 msec. Double it |
| 12014 | * to be sure. |
| 12015 | */ |
| 12016 | mdelay(40); |
| 12017 | |
| 12018 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
| 12019 | data[2] |= TG3_STD_LOOPBACK_FAILED; |
| 12020 | if (tg3_flag(tp, TSO_CAPABLE) && |
| 12021 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
| 12022 | data[2] |= TG3_TSO_LOOPBACK_FAILED; |
| 12023 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12024 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12025 | data[2] |= TG3_JMB_LOOPBACK_FAILED; |
| 12026 | } |
| 12027 | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12028 | /* Re-enable gphy autopowerdown. */ |
| 12029 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
| 12030 | tg3_phy_toggle_apd(tp, true); |
| 12031 | } |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12032 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12033 | err = (data[0] | data[1] | data[2]) ? -EIO : 0; |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12034 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 12035 | done: |
| 12036 | tp->phy_flags |= eee_cap; |
| 12037 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12038 | return err; |
| 12039 | } |
| 12040 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12041 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
| 12042 | u64 *data) |
| 12043 | { |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12044 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12045 | bool doextlpbk = etest->flags & ETH_TEST_FL_EXTERNAL_LB; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12046 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 12047 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
| 12048 | tg3_power_up(tp)) { |
| 12049 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12050 | memset(data, 1, sizeof(u64) * TG3_NUM_TEST); |
| 12051 | return; |
| 12052 | } |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12053 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12054 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
| 12055 | |
| 12056 | if (tg3_test_nvram(tp) != 0) { |
| 12057 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12058 | data[0] = 1; |
| 12059 | } |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12060 | if (!doextlpbk && tg3_test_link(tp)) { |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12061 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12062 | data[1] = 1; |
| 12063 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12064 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12065 | int err, err2 = 0, irq_sync = 0; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12066 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12067 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12068 | tg3_phy_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12069 | tg3_netif_stop(tp); |
| 12070 | irq_sync = 1; |
| 12071 | } |
| 12072 | |
| 12073 | tg3_full_lock(tp, irq_sync); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12074 | |
| 12075 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12076 | err = tg3_nvram_lock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12077 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12078 | if (!tg3_flag(tp, 5705_PLUS)) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12079 | tg3_halt_cpu(tp, TX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12080 | if (!err) |
| 12081 | tg3_nvram_unlock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12082 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12083 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 12084 | tg3_phy_reset(tp); |
| 12085 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12086 | if (tg3_test_registers(tp) != 0) { |
| 12087 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12088 | data[2] = 1; |
| 12089 | } |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12090 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12091 | if (tg3_test_memory(tp) != 0) { |
| 12092 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12093 | data[3] = 1; |
| 12094 | } |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12095 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12096 | if (doextlpbk) |
| 12097 | etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; |
| 12098 | |
| 12099 | if (tg3_test_loopback(tp, &data[4], doextlpbk)) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12100 | etest->flags |= ETH_TEST_FL_FAILED; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12101 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12102 | tg3_full_unlock(tp); |
| 12103 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12104 | if (tg3_test_interrupt(tp) != 0) { |
| 12105 | etest->flags |= ETH_TEST_FL_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12106 | data[7] = 1; |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12107 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12108 | |
| 12109 | tg3_full_lock(tp, 0); |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12110 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12111 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 12112 | if (netif_running(dev)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12113 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12114 | err2 = tg3_restart_hw(tp, 1); |
| 12115 | if (!err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 12116 | tg3_netif_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12117 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12118 | |
| 12119 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12120 | |
| 12121 | if (irq_sync && !err2) |
| 12122 | tg3_phy_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12123 | } |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 12124 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 12125 | tg3_power_down(tp); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12126 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12127 | } |
| 12128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12129 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 12130 | { |
| 12131 | struct mii_ioctl_data *data = if_mii(ifr); |
| 12132 | struct tg3 *tp = netdev_priv(dev); |
| 12133 | int err; |
| 12134 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12135 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 12136 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12137 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12138 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 12139 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 12140 | return phy_mii_ioctl(phydev, ifr, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12141 | } |
| 12142 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 12143 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12144 | case SIOCGMIIPHY: |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 12145 | data->phy_id = tp->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12146 | |
| 12147 | /* fallthru */ |
| 12148 | case SIOCGMIIREG: { |
| 12149 | u32 mii_regval; |
| 12150 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12151 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12152 | break; /* We have no PHY */ |
| 12153 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 12154 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12155 | return -EAGAIN; |
| 12156 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12157 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12158 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12159 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12160 | |
| 12161 | data->val_out = mii_regval; |
| 12162 | |
| 12163 | return err; |
| 12164 | } |
| 12165 | |
| 12166 | case SIOCSMIIREG: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12167 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12168 | break; /* We have no PHY */ |
| 12169 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 12170 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12171 | return -EAGAIN; |
| 12172 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12173 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12174 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12175 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12176 | |
| 12177 | return err; |
| 12178 | |
| 12179 | default: |
| 12180 | /* do nothing */ |
| 12181 | break; |
| 12182 | } |
| 12183 | return -EOPNOTSUPP; |
| 12184 | } |
| 12185 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 12186 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 12187 | { |
| 12188 | struct tg3 *tp = netdev_priv(dev); |
| 12189 | |
| 12190 | memcpy(ec, &tp->coal, sizeof(*ec)); |
| 12191 | return 0; |
| 12192 | } |
| 12193 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 12194 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 12195 | { |
| 12196 | struct tg3 *tp = netdev_priv(dev); |
| 12197 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; |
| 12198 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; |
| 12199 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12200 | if (!tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 12201 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
| 12202 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; |
| 12203 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; |
| 12204 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; |
| 12205 | } |
| 12206 | |
| 12207 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || |
| 12208 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || |
| 12209 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || |
| 12210 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || |
| 12211 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || |
| 12212 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || |
| 12213 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || |
| 12214 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || |
| 12215 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || |
| 12216 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) |
| 12217 | return -EINVAL; |
| 12218 | |
| 12219 | /* No rx interrupts will be generated if both are zero */ |
| 12220 | if ((ec->rx_coalesce_usecs == 0) && |
| 12221 | (ec->rx_max_coalesced_frames == 0)) |
| 12222 | return -EINVAL; |
| 12223 | |
| 12224 | /* No tx interrupts will be generated if both are zero */ |
| 12225 | if ((ec->tx_coalesce_usecs == 0) && |
| 12226 | (ec->tx_max_coalesced_frames == 0)) |
| 12227 | return -EINVAL; |
| 12228 | |
| 12229 | /* Only copy relevant parameters, ignore all others. */ |
| 12230 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; |
| 12231 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; |
| 12232 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; |
| 12233 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; |
| 12234 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; |
| 12235 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; |
| 12236 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; |
| 12237 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; |
| 12238 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; |
| 12239 | |
| 12240 | if (netif_running(dev)) { |
| 12241 | tg3_full_lock(tp, 0); |
| 12242 | __tg3_set_coalesce(tp, &tp->coal); |
| 12243 | tg3_full_unlock(tp); |
| 12244 | } |
| 12245 | return 0; |
| 12246 | } |
| 12247 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 12248 | static const struct ethtool_ops tg3_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12249 | .get_settings = tg3_get_settings, |
| 12250 | .set_settings = tg3_set_settings, |
| 12251 | .get_drvinfo = tg3_get_drvinfo, |
| 12252 | .get_regs_len = tg3_get_regs_len, |
| 12253 | .get_regs = tg3_get_regs, |
| 12254 | .get_wol = tg3_get_wol, |
| 12255 | .set_wol = tg3_set_wol, |
| 12256 | .get_msglevel = tg3_get_msglevel, |
| 12257 | .set_msglevel = tg3_set_msglevel, |
| 12258 | .nway_reset = tg3_nway_reset, |
| 12259 | .get_link = ethtool_op_get_link, |
| 12260 | .get_eeprom_len = tg3_get_eeprom_len, |
| 12261 | .get_eeprom = tg3_get_eeprom, |
| 12262 | .set_eeprom = tg3_set_eeprom, |
| 12263 | .get_ringparam = tg3_get_ringparam, |
| 12264 | .set_ringparam = tg3_set_ringparam, |
| 12265 | .get_pauseparam = tg3_get_pauseparam, |
| 12266 | .set_pauseparam = tg3_set_pauseparam, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12267 | .self_test = tg3_self_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12268 | .get_strings = tg3_get_strings, |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 12269 | .set_phys_id = tg3_set_phys_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12270 | .get_ethtool_stats = tg3_get_ethtool_stats, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 12271 | .get_coalesce = tg3_get_coalesce, |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 12272 | .set_coalesce = tg3_set_coalesce, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 12273 | .get_sset_count = tg3_get_sset_count, |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 12274 | .get_rxnfc = tg3_get_rxnfc, |
| 12275 | .get_rxfh_indir_size = tg3_get_rxfh_indir_size, |
| 12276 | .get_rxfh_indir = tg3_get_rxfh_indir, |
| 12277 | .set_rxfh_indir = tg3_set_rxfh_indir, |
Richard Cochran | 3f84749 | 2012-04-03 22:59:39 +0000 | [diff] [blame] | 12278 | .get_ts_info = ethtool_op_get_ts_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12279 | }; |
| 12280 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 12281 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
| 12282 | struct rtnl_link_stats64 *stats) |
| 12283 | { |
| 12284 | struct tg3 *tp = netdev_priv(dev); |
| 12285 | |
| 12286 | if (!tp->hw_stats) |
| 12287 | return &tp->net_stats_prev; |
| 12288 | |
| 12289 | spin_lock_bh(&tp->lock); |
| 12290 | tg3_get_nstats(tp, stats); |
| 12291 | spin_unlock_bh(&tp->lock); |
| 12292 | |
| 12293 | return stats; |
| 12294 | } |
| 12295 | |
Matt Carlson | ccd5ba9 | 2012-02-13 10:20:08 +0000 | [diff] [blame] | 12296 | static void tg3_set_rx_mode(struct net_device *dev) |
| 12297 | { |
| 12298 | struct tg3 *tp = netdev_priv(dev); |
| 12299 | |
| 12300 | if (!netif_running(dev)) |
| 12301 | return; |
| 12302 | |
| 12303 | tg3_full_lock(tp, 0); |
| 12304 | __tg3_set_rx_mode(dev); |
| 12305 | tg3_full_unlock(tp); |
| 12306 | } |
| 12307 | |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 12308 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
| 12309 | int new_mtu) |
| 12310 | { |
| 12311 | dev->mtu = new_mtu; |
| 12312 | |
| 12313 | if (new_mtu > ETH_DATA_LEN) { |
| 12314 | if (tg3_flag(tp, 5780_CLASS)) { |
| 12315 | netdev_update_features(dev); |
| 12316 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 12317 | } else { |
| 12318 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
| 12319 | } |
| 12320 | } else { |
| 12321 | if (tg3_flag(tp, 5780_CLASS)) { |
| 12322 | tg3_flag_set(tp, TSO_CAPABLE); |
| 12323 | netdev_update_features(dev); |
| 12324 | } |
| 12325 | tg3_flag_clear(tp, JUMBO_RING_ENABLE); |
| 12326 | } |
| 12327 | } |
| 12328 | |
| 12329 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) |
| 12330 | { |
| 12331 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 2fae5e3 | 2012-03-04 14:48:15 +0000 | [diff] [blame] | 12332 | int err, reset_phy = 0; |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 12333 | |
| 12334 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) |
| 12335 | return -EINVAL; |
| 12336 | |
| 12337 | if (!netif_running(dev)) { |
| 12338 | /* We'll just catch it later when the |
| 12339 | * device is up'd. |
| 12340 | */ |
| 12341 | tg3_set_mtu(dev, tp, new_mtu); |
| 12342 | return 0; |
| 12343 | } |
| 12344 | |
| 12345 | tg3_phy_stop(tp); |
| 12346 | |
| 12347 | tg3_netif_stop(tp); |
| 12348 | |
| 12349 | tg3_full_lock(tp, 1); |
| 12350 | |
| 12351 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 12352 | |
| 12353 | tg3_set_mtu(dev, tp, new_mtu); |
| 12354 | |
Michael Chan | 2fae5e3 | 2012-03-04 14:48:15 +0000 | [diff] [blame] | 12355 | /* Reset PHY, otherwise the read DMA engine will be in a mode that |
| 12356 | * breaks all requests to 256 bytes. |
| 12357 | */ |
| 12358 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) |
| 12359 | reset_phy = 1; |
| 12360 | |
| 12361 | err = tg3_restart_hw(tp, reset_phy); |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 12362 | |
| 12363 | if (!err) |
| 12364 | tg3_netif_start(tp); |
| 12365 | |
| 12366 | tg3_full_unlock(tp); |
| 12367 | |
| 12368 | if (!err) |
| 12369 | tg3_phy_start(tp); |
| 12370 | |
| 12371 | return err; |
| 12372 | } |
| 12373 | |
| 12374 | static const struct net_device_ops tg3_netdev_ops = { |
| 12375 | .ndo_open = tg3_open, |
| 12376 | .ndo_stop = tg3_close, |
| 12377 | .ndo_start_xmit = tg3_start_xmit, |
| 12378 | .ndo_get_stats64 = tg3_get_stats64, |
| 12379 | .ndo_validate_addr = eth_validate_addr, |
| 12380 | .ndo_set_rx_mode = tg3_set_rx_mode, |
| 12381 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 12382 | .ndo_do_ioctl = tg3_ioctl, |
| 12383 | .ndo_tx_timeout = tg3_tx_timeout, |
| 12384 | .ndo_change_mtu = tg3_change_mtu, |
| 12385 | .ndo_fix_features = tg3_fix_features, |
| 12386 | .ndo_set_features = tg3_set_features, |
| 12387 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 12388 | .ndo_poll_controller = tg3_poll_controller, |
| 12389 | #endif |
| 12390 | }; |
| 12391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12392 | static void __devinit tg3_get_eeprom_size(struct tg3 *tp) |
| 12393 | { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12394 | u32 cursize, val, magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12395 | |
| 12396 | tp->nvram_size = EEPROM_CHIP_SIZE; |
| 12397 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12398 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12399 | return; |
| 12400 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12401 | if ((magic != TG3_EEPROM_MAGIC) && |
| 12402 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && |
| 12403 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12404 | return; |
| 12405 | |
| 12406 | /* |
| 12407 | * Size the chip by reading offsets at increasing powers of two. |
| 12408 | * When we encounter our validation signature, we know the addressing |
| 12409 | * has wrapped around, and thus have our chip size. |
| 12410 | */ |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12411 | cursize = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12412 | |
| 12413 | while (cursize < tp->nvram_size) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12414 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12415 | return; |
| 12416 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12417 | if (val == magic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12418 | break; |
| 12419 | |
| 12420 | cursize <<= 1; |
| 12421 | } |
| 12422 | |
| 12423 | tp->nvram_size = cursize; |
| 12424 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12426 | static void __devinit tg3_get_nvram_size(struct tg3 *tp) |
| 12427 | { |
| 12428 | u32 val; |
| 12429 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12430 | 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] | 12431 | return; |
| 12432 | |
| 12433 | /* Selfboot format */ |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12434 | if (val != TG3_EEPROM_MAGIC) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12435 | tg3_get_eeprom_size(tp); |
| 12436 | return; |
| 12437 | } |
| 12438 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12439 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12440 | if (val != 0) { |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12441 | /* This is confusing. We want to operate on the |
| 12442 | * 16-bit value at offset 0xf2. The tg3_nvram_read() |
| 12443 | * call will read from NVRAM and byteswap the data |
| 12444 | * according to the byteswapping settings for all |
| 12445 | * other register accesses. This ensures the data we |
| 12446 | * want will always reside in the lower 16-bits. |
| 12447 | * However, the data in NVRAM is in LE format, which |
| 12448 | * means the data from the NVRAM read will always be |
| 12449 | * opposite the endianness of the CPU. The 16-bit |
| 12450 | * byteswap then brings the data to CPU endianness. |
| 12451 | */ |
| 12452 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12453 | return; |
| 12454 | } |
| 12455 | } |
Matt Carlson | fd1122a | 2008-05-02 16:48:36 -0700 | [diff] [blame] | 12456 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12457 | } |
| 12458 | |
| 12459 | static void __devinit tg3_get_nvram_info(struct tg3 *tp) |
| 12460 | { |
| 12461 | u32 nvcfg1; |
| 12462 | |
| 12463 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12464 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12465 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12466 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12467 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12468 | tw32(NVRAM_CFG1, nvcfg1); |
| 12469 | } |
| 12470 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 12471 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12472 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12473 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12474 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
| 12475 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12476 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12477 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12478 | break; |
| 12479 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: |
| 12480 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12481 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; |
| 12482 | break; |
| 12483 | case FLASH_VENDOR_ATMEL_EEPROM: |
| 12484 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12485 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12486 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12487 | break; |
| 12488 | case FLASH_VENDOR_ST: |
| 12489 | tp->nvram_jedecnum = JEDEC_ST; |
| 12490 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12491 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12492 | break; |
| 12493 | case FLASH_VENDOR_SAIFUN: |
| 12494 | tp->nvram_jedecnum = JEDEC_SAIFUN; |
| 12495 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; |
| 12496 | break; |
| 12497 | case FLASH_VENDOR_SST_SMALL: |
| 12498 | case FLASH_VENDOR_SST_LARGE: |
| 12499 | tp->nvram_jedecnum = JEDEC_SST; |
| 12500 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; |
| 12501 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12502 | } |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12503 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12504 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12505 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12506 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12507 | } |
| 12508 | } |
| 12509 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12510 | static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
| 12511 | { |
| 12512 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { |
| 12513 | case FLASH_5752PAGE_SIZE_256: |
| 12514 | tp->nvram_pagesize = 256; |
| 12515 | break; |
| 12516 | case FLASH_5752PAGE_SIZE_512: |
| 12517 | tp->nvram_pagesize = 512; |
| 12518 | break; |
| 12519 | case FLASH_5752PAGE_SIZE_1K: |
| 12520 | tp->nvram_pagesize = 1024; |
| 12521 | break; |
| 12522 | case FLASH_5752PAGE_SIZE_2K: |
| 12523 | tp->nvram_pagesize = 2048; |
| 12524 | break; |
| 12525 | case FLASH_5752PAGE_SIZE_4K: |
| 12526 | tp->nvram_pagesize = 4096; |
| 12527 | break; |
| 12528 | case FLASH_5752PAGE_SIZE_264: |
| 12529 | tp->nvram_pagesize = 264; |
| 12530 | break; |
| 12531 | case FLASH_5752PAGE_SIZE_528: |
| 12532 | tp->nvram_pagesize = 528; |
| 12533 | break; |
| 12534 | } |
| 12535 | } |
| 12536 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12537 | static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp) |
| 12538 | { |
| 12539 | u32 nvcfg1; |
| 12540 | |
| 12541 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12542 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12543 | /* NVRAM protection for TPM */ |
| 12544 | if (nvcfg1 & (1 << 27)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12545 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12546 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12547 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12548 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
| 12549 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: |
| 12550 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12551 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12552 | break; |
| 12553 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 12554 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12555 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12556 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12557 | break; |
| 12558 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12559 | case FLASH_5752VENDOR_ST_M45PE20: |
| 12560 | case FLASH_5752VENDOR_ST_M45PE40: |
| 12561 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12562 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12563 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12564 | break; |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12565 | } |
| 12566 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12567 | if (tg3_flag(tp, FLASH)) { |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12568 | tg3_nvram_get_pagesize(tp, nvcfg1); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12569 | } else { |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12570 | /* For eeprom, set pagesize to maximum eeprom size */ |
| 12571 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12572 | |
| 12573 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12574 | tw32(NVRAM_CFG1, nvcfg1); |
| 12575 | } |
| 12576 | } |
| 12577 | |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 12578 | static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp) |
| 12579 | { |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 12580 | u32 nvcfg1, protect = 0; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 12581 | |
| 12582 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12583 | |
| 12584 | /* NVRAM protection for TPM */ |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 12585 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12586 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 12587 | protect = 1; |
| 12588 | } |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 12589 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 12590 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 12591 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12592 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 12593 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 12594 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 12595 | case FLASH_5755VENDOR_ATMEL_FLASH_5: |
| 12596 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12597 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12598 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12599 | tp->nvram_pagesize = 264; |
| 12600 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || |
| 12601 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) |
| 12602 | tp->nvram_size = (protect ? 0x3e200 : |
| 12603 | TG3_NVRAM_SIZE_512KB); |
| 12604 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) |
| 12605 | tp->nvram_size = (protect ? 0x1f200 : |
| 12606 | TG3_NVRAM_SIZE_256KB); |
| 12607 | else |
| 12608 | tp->nvram_size = (protect ? 0x1f200 : |
| 12609 | TG3_NVRAM_SIZE_128KB); |
| 12610 | break; |
| 12611 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12612 | case FLASH_5752VENDOR_ST_M45PE20: |
| 12613 | case FLASH_5752VENDOR_ST_M45PE40: |
| 12614 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12615 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12616 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12617 | tp->nvram_pagesize = 256; |
| 12618 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) |
| 12619 | tp->nvram_size = (protect ? |
| 12620 | TG3_NVRAM_SIZE_64KB : |
| 12621 | TG3_NVRAM_SIZE_128KB); |
| 12622 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) |
| 12623 | tp->nvram_size = (protect ? |
| 12624 | TG3_NVRAM_SIZE_64KB : |
| 12625 | TG3_NVRAM_SIZE_256KB); |
| 12626 | else |
| 12627 | tp->nvram_size = (protect ? |
| 12628 | TG3_NVRAM_SIZE_128KB : |
| 12629 | TG3_NVRAM_SIZE_512KB); |
| 12630 | break; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 12631 | } |
| 12632 | } |
| 12633 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12634 | static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) |
| 12635 | { |
| 12636 | u32 nvcfg1; |
| 12637 | |
| 12638 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12639 | |
| 12640 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12641 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
| 12642 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 12643 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: |
| 12644 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 12645 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12646 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12647 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12648 | |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12649 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12650 | tw32(NVRAM_CFG1, nvcfg1); |
| 12651 | break; |
| 12652 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 12653 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 12654 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 12655 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 12656 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12657 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12658 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12659 | tp->nvram_pagesize = 264; |
| 12660 | break; |
| 12661 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12662 | case FLASH_5752VENDOR_ST_M45PE20: |
| 12663 | case FLASH_5752VENDOR_ST_M45PE40: |
| 12664 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12665 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12666 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12667 | tp->nvram_pagesize = 256; |
| 12668 | break; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12669 | } |
| 12670 | } |
| 12671 | |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 12672 | static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp) |
| 12673 | { |
| 12674 | u32 nvcfg1, protect = 0; |
| 12675 | |
| 12676 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12677 | |
| 12678 | /* NVRAM protection for TPM */ |
| 12679 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12680 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 12681 | protect = 1; |
| 12682 | } |
| 12683 | |
| 12684 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 12685 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12686 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 12687 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 12688 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 12689 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 12690 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 12691 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 12692 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 12693 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 12694 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12695 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12696 | tg3_flag_set(tp, FLASH); |
| 12697 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12698 | tp->nvram_pagesize = 256; |
| 12699 | break; |
| 12700 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 12701 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 12702 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 12703 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 12704 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 12705 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 12706 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 12707 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 12708 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12709 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12710 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12711 | tp->nvram_pagesize = 256; |
| 12712 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 12713 | } |
| 12714 | |
| 12715 | if (protect) { |
| 12716 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); |
| 12717 | } else { |
| 12718 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12719 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 12720 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 12721 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 12722 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 12723 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; |
| 12724 | break; |
| 12725 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 12726 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 12727 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 12728 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 12729 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 12730 | break; |
| 12731 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 12732 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 12733 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 12734 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 12735 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12736 | break; |
| 12737 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 12738 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 12739 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 12740 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 12741 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12742 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 12743 | } |
| 12744 | } |
| 12745 | } |
| 12746 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12747 | static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp) |
| 12748 | { |
| 12749 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12750 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12751 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12752 | } |
| 12753 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12754 | static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp) |
| 12755 | { |
| 12756 | u32 nvcfg1; |
| 12757 | |
| 12758 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12759 | |
| 12760 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12761 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 12762 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 12763 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12764 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12765 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12766 | |
| 12767 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12768 | tw32(NVRAM_CFG1, nvcfg1); |
| 12769 | return; |
| 12770 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 12771 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 12772 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 12773 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 12774 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 12775 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 12776 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 12777 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12778 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12779 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12780 | |
| 12781 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12782 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 12783 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 12784 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 12785 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12786 | break; |
| 12787 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 12788 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 12789 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12790 | break; |
| 12791 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 12792 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 12793 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12794 | break; |
| 12795 | } |
| 12796 | break; |
| 12797 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12798 | case FLASH_5752VENDOR_ST_M45PE20: |
| 12799 | case FLASH_5752VENDOR_ST_M45PE40: |
| 12800 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12801 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12802 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12803 | |
| 12804 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12805 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12806 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12807 | break; |
| 12808 | case FLASH_5752VENDOR_ST_M45PE20: |
| 12809 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12810 | break; |
| 12811 | case FLASH_5752VENDOR_ST_M45PE40: |
| 12812 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12813 | break; |
| 12814 | } |
| 12815 | break; |
| 12816 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12817 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12818 | return; |
| 12819 | } |
| 12820 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12821 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 12822 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12823 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12824 | } |
| 12825 | |
| 12826 | |
| 12827 | static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp) |
| 12828 | { |
| 12829 | u32 nvcfg1; |
| 12830 | |
| 12831 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12832 | |
| 12833 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12834 | case FLASH_5717VENDOR_ATMEL_EEPROM: |
| 12835 | case FLASH_5717VENDOR_MICRO_EEPROM: |
| 12836 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12837 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12838 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12839 | |
| 12840 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12841 | tw32(NVRAM_CFG1, nvcfg1); |
| 12842 | return; |
| 12843 | case FLASH_5717VENDOR_ATMEL_MDB011D: |
| 12844 | case FLASH_5717VENDOR_ATMEL_ADB011B: |
| 12845 | case FLASH_5717VENDOR_ATMEL_ADB011D: |
| 12846 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 12847 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 12848 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 12849 | case FLASH_5717VENDOR_ATMEL_45USPT: |
| 12850 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12851 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12852 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12853 | |
| 12854 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12855 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 12856 | /* Detect size with tg3_nvram_get_size() */ |
| 12857 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12858 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 12859 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 12860 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12861 | break; |
| 12862 | default: |
| 12863 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12864 | break; |
| 12865 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12866 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12867 | case FLASH_5717VENDOR_ST_M_M25PE10: |
| 12868 | case FLASH_5717VENDOR_ST_A_M25PE10: |
| 12869 | case FLASH_5717VENDOR_ST_M_M45PE10: |
| 12870 | case FLASH_5717VENDOR_ST_A_M45PE10: |
| 12871 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 12872 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 12873 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 12874 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 12875 | case FLASH_5717VENDOR_ST_25USPT: |
| 12876 | case FLASH_5717VENDOR_ST_45USPT: |
| 12877 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12878 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12879 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12880 | |
| 12881 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 12882 | case FLASH_5717VENDOR_ST_M_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12883 | case FLASH_5717VENDOR_ST_M_M45PE20: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 12884 | /* Detect size with tg3_nvram_get_size() */ |
| 12885 | break; |
| 12886 | case FLASH_5717VENDOR_ST_A_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12887 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 12888 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12889 | break; |
| 12890 | default: |
| 12891 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12892 | break; |
| 12893 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12894 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12895 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12896 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12897 | return; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12898 | } |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12899 | |
| 12900 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 12901 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12902 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12903 | } |
| 12904 | |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12905 | static void __devinit tg3_get_5720_nvram_info(struct tg3 *tp) |
| 12906 | { |
| 12907 | u32 nvcfg1, nvmpinstrp; |
| 12908 | |
| 12909 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12910 | nvmpinstrp = nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK; |
| 12911 | |
| 12912 | switch (nvmpinstrp) { |
| 12913 | case FLASH_5720_EEPROM_HD: |
| 12914 | case FLASH_5720_EEPROM_LD: |
| 12915 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12916 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12917 | |
| 12918 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12919 | tw32(NVRAM_CFG1, nvcfg1); |
| 12920 | if (nvmpinstrp == FLASH_5720_EEPROM_HD) |
| 12921 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 12922 | else |
| 12923 | tp->nvram_pagesize = ATMEL_AT24C02_CHIP_SIZE; |
| 12924 | return; |
| 12925 | case FLASH_5720VENDOR_M_ATMEL_DB011D: |
| 12926 | case FLASH_5720VENDOR_A_ATMEL_DB011B: |
| 12927 | case FLASH_5720VENDOR_A_ATMEL_DB011D: |
| 12928 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 12929 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 12930 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 12931 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 12932 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 12933 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 12934 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 12935 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 12936 | case FLASH_5720VENDOR_ATMEL_45USPT: |
| 12937 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12938 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12939 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12940 | |
| 12941 | switch (nvmpinstrp) { |
| 12942 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 12943 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 12944 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 12945 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12946 | break; |
| 12947 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 12948 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 12949 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 12950 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12951 | break; |
| 12952 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 12953 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 12954 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 12955 | break; |
| 12956 | default: |
| 12957 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 12958 | break; |
| 12959 | } |
| 12960 | break; |
| 12961 | case FLASH_5720VENDOR_M_ST_M25PE10: |
| 12962 | case FLASH_5720VENDOR_M_ST_M45PE10: |
| 12963 | case FLASH_5720VENDOR_A_ST_M25PE10: |
| 12964 | case FLASH_5720VENDOR_A_ST_M45PE10: |
| 12965 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 12966 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 12967 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 12968 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 12969 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 12970 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 12971 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 12972 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 12973 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 12974 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 12975 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 12976 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 12977 | case FLASH_5720VENDOR_ST_25USPT: |
| 12978 | case FLASH_5720VENDOR_ST_45USPT: |
| 12979 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12980 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12981 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 12982 | |
| 12983 | switch (nvmpinstrp) { |
| 12984 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 12985 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 12986 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 12987 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 12988 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 12989 | break; |
| 12990 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 12991 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 12992 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 12993 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 12994 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 12995 | break; |
| 12996 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 12997 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 12998 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 12999 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 13000 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 13001 | break; |
| 13002 | default: |
| 13003 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13004 | break; |
| 13005 | } |
| 13006 | break; |
| 13007 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13008 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13009 | return; |
| 13010 | } |
| 13011 | |
| 13012 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 13013 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13014 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13015 | } |
| 13016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13017 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
| 13018 | static void __devinit tg3_nvram_init(struct tg3 *tp) |
| 13019 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13020 | tw32_f(GRC_EEPROM_ADDR, |
| 13021 | (EEPROM_ADDR_FSM_RESET | |
| 13022 | (EEPROM_DEFAULT_CLOCK_PERIOD << |
| 13023 | EEPROM_ADDR_CLKPERD_SHIFT))); |
| 13024 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 13025 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13026 | |
| 13027 | /* Enable seeprom accesses. */ |
| 13028 | tw32_f(GRC_LOCAL_CTRL, |
| 13029 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); |
| 13030 | udelay(100); |
| 13031 | |
| 13032 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13033 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13034 | tg3_flag_set(tp, NVRAM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13035 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 13036 | if (tg3_nvram_lock(tp)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 13037 | netdev_warn(tp->dev, |
| 13038 | "Cannot get nvram lock, %s failed\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 13039 | __func__); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 13040 | return; |
| 13041 | } |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13042 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13043 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13044 | tp->nvram_size = 0; |
| 13045 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13046 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 13047 | tg3_get_5752_nvram_info(tp); |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13048 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 13049 | tg3_get_5755_nvram_info(tp); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13050 | 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] | 13051 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 13052 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13053 | tg3_get_5787_nvram_info(tp); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13054 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 13055 | tg3_get_5761_nvram_info(tp); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13056 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 13057 | tg3_get_5906_nvram_info(tp); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13058 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 13059 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13060 | tg3_get_57780_nvram_info(tp); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13061 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13062 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13063 | tg3_get_5717_nvram_info(tp); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13064 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 13065 | tg3_get_5720_nvram_info(tp); |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13066 | else |
| 13067 | tg3_get_nvram_info(tp); |
| 13068 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13069 | if (tp->nvram_size == 0) |
| 13070 | tg3_get_nvram_size(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13071 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13072 | tg3_disable_nvram_access(tp); |
Michael Chan | 381291b | 2005-12-13 21:08:21 -0800 | [diff] [blame] | 13073 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13074 | |
| 13075 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13076 | tg3_flag_clear(tp, NVRAM); |
| 13077 | tg3_flag_clear(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13078 | |
| 13079 | tg3_get_eeprom_size(tp); |
| 13080 | } |
| 13081 | } |
| 13082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13083 | struct subsys_tbl_ent { |
| 13084 | u16 subsys_vendor, subsys_devid; |
| 13085 | u32 phy_id; |
| 13086 | }; |
| 13087 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13088 | static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13089 | /* Broadcom boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13090 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13091 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13092 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13093 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13094 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13095 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13096 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 13097 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, |
| 13098 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13099 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13100 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13101 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13102 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 13103 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, |
| 13104 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13105 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13106 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13107 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13108 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13109 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13110 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13111 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13112 | |
| 13113 | /* 3com boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13114 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13115 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13116 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13117 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13118 | { TG3PCI_SUBVENDOR_ID_3COM, |
| 13119 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, |
| 13120 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13121 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13122 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13123 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13124 | |
| 13125 | /* DELL boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13126 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13127 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13128 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13129 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13130 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13131 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13132 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13133 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13134 | |
| 13135 | /* Compaq boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13136 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13137 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13138 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13139 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13140 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 13141 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, |
| 13142 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13143 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13144 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13145 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13146 | |
| 13147 | /* IBM boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13148 | { TG3PCI_SUBVENDOR_ID_IBM, |
| 13149 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13150 | }; |
| 13151 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13152 | 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] | 13153 | { |
| 13154 | int i; |
| 13155 | |
| 13156 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { |
| 13157 | if ((subsys_id_to_phy_id[i].subsys_vendor == |
| 13158 | tp->pdev->subsystem_vendor) && |
| 13159 | (subsys_id_to_phy_id[i].subsys_devid == |
| 13160 | tp->pdev->subsystem_device)) |
| 13161 | return &subsys_id_to_phy_id[i]; |
| 13162 | } |
| 13163 | return NULL; |
| 13164 | } |
| 13165 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13166 | static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13167 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13168 | u32 val; |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 13169 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13170 | tp->phy_id = TG3_PHY_ID_INVALID; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13171 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 13172 | |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 13173 | /* Assume an onboard device and WOL capable by default. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13174 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
| 13175 | tg3_flag_set(tp, WOL_CAP); |
David S. Miller | 72b845e | 2006-03-14 14:11:48 -0800 | [diff] [blame] | 13176 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13177 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13178 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13179 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 13180 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13181 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 13182 | val = tr32(VCPU_CFGSHDW); |
| 13183 | if (val & VCPU_CFGSHDW_ASPM_DBNC) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13184 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 13185 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13186 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13187 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13188 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 13189 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 13190 | goto done; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13191 | } |
| 13192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13193 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 13194 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 13195 | u32 nic_cfg, led_cfg; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13196 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13197 | int eeprom_phy_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13198 | |
| 13199 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 13200 | tp->nic_sram_data_cfg = nic_cfg; |
| 13201 | |
| 13202 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); |
| 13203 | ver >>= NIC_SRAM_DATA_VER_SHIFT; |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 13204 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13205 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 13206 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13207 | (ver > 0) && (ver < 0x100)) |
| 13208 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); |
| 13209 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13210 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 13211 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
| 13212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13213 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
| 13214 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) |
| 13215 | eeprom_phy_serdes = 1; |
| 13216 | |
| 13217 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); |
| 13218 | if (nic_phy_id != 0) { |
| 13219 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; |
| 13220 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; |
| 13221 | |
| 13222 | eeprom_phy_id = (id1 >> 16) << 10; |
| 13223 | eeprom_phy_id |= (id2 & 0xfc00) << 16; |
| 13224 | eeprom_phy_id |= (id2 & 0x03ff) << 0; |
| 13225 | } else |
| 13226 | eeprom_phy_id = 0; |
| 13227 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13228 | tp->phy_id = eeprom_phy_id; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13229 | if (eeprom_phy_serdes) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13230 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13231 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13232 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13233 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13234 | } |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13235 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13236 | if (tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13237 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
| 13238 | SHASTA_EXT_LED_MODE_MASK); |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 13239 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13240 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
| 13241 | |
| 13242 | switch (led_cfg) { |
| 13243 | default: |
| 13244 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: |
| 13245 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 13246 | break; |
| 13247 | |
| 13248 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: |
| 13249 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 13250 | break; |
| 13251 | |
| 13252 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: |
| 13253 | tp->led_ctrl = LED_CTRL_MODE_MAC; |
Michael Chan | 9ba2779 | 2005-06-06 15:16:20 -0700 | [diff] [blame] | 13254 | |
| 13255 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is |
| 13256 | * read on some older 5700/5701 bootcode. |
| 13257 | */ |
| 13258 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 13259 | ASIC_REV_5700 || |
| 13260 | GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 13261 | ASIC_REV_5701) |
| 13262 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 13263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13264 | break; |
| 13265 | |
| 13266 | case SHASTA_EXT_LED_SHARED: |
| 13267 | tp->led_ctrl = LED_CTRL_MODE_SHARED; |
| 13268 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 13269 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) |
| 13270 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 13271 | LED_CTRL_MODE_PHY_2); |
| 13272 | break; |
| 13273 | |
| 13274 | case SHASTA_EXT_LED_MAC: |
| 13275 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; |
| 13276 | break; |
| 13277 | |
| 13278 | case SHASTA_EXT_LED_COMBO: |
| 13279 | tp->led_ctrl = LED_CTRL_MODE_COMBO; |
| 13280 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) |
| 13281 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 13282 | LED_CTRL_MODE_PHY_2); |
| 13283 | break; |
| 13284 | |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 13285 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13286 | |
| 13287 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 13288 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && |
| 13289 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
| 13290 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 13291 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 13292 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
| 13293 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
Matt Carlson | 5f60891 | 2007-11-12 21:17:07 -0800 | [diff] [blame] | 13294 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13295 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13296 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13297 | if ((tp->pdev->subsystem_vendor == |
| 13298 | PCI_VENDOR_ID_ARIMA) && |
| 13299 | (tp->pdev->subsystem_device == 0x205a || |
| 13300 | tp->pdev->subsystem_device == 0x2063)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13301 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13302 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13303 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 13304 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13306 | |
| 13307 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13308 | tg3_flag_set(tp, ENABLE_ASF); |
| 13309 | if (tg3_flag(tp, 5750_PLUS)) |
| 13310 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13311 | } |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 13312 | |
| 13313 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13314 | tg3_flag(tp, 5750_PLUS)) |
| 13315 | tg3_flag_set(tp, ENABLE_APE); |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 13316 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13317 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 13318 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13319 | tg3_flag_clear(tp, WOL_CAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13320 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13321 | if (tg3_flag(tp, WOL_CAP) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13322 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13323 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13324 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 13325 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 13326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13327 | if (cfg2 & (1 << 17)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13328 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13329 | |
| 13330 | /* serdes signal pre-emphasis in register 0x590 set by */ |
| 13331 | /* bootcode if bit 18 is set */ |
| 13332 | if (cfg2 & (1 << 18)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13333 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13334 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13335 | if ((tg3_flag(tp, 57765_PLUS) || |
| 13336 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 13337 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) && |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 13338 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13339 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 13340 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13341 | if (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | 8c69b1e | 2010-08-02 11:26:00 +0000 | [diff] [blame] | 13342 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13343 | !tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13344 | u32 cfg3; |
| 13345 | |
| 13346 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); |
| 13347 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13348 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13349 | } |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13350 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 13351 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13352 | tg3_flag_set(tp, RGMII_INBAND_DISABLE); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13353 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13354 | tg3_flag_set(tp, RGMII_EXT_IBND_RX_EN); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13355 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13356 | tg3_flag_set(tp, RGMII_EXT_IBND_TX_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13357 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 13358 | done: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13359 | if (tg3_flag(tp, WOL_CAP)) |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 13360 | device_set_wakeup_enable(&tp->pdev->dev, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13361 | tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 13362 | else |
| 13363 | device_set_wakeup_capable(&tp->pdev->dev, false); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13364 | } |
| 13365 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 13366 | static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
| 13367 | { |
| 13368 | int i; |
| 13369 | u32 val; |
| 13370 | |
| 13371 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); |
| 13372 | tw32(OTP_CTRL, cmd); |
| 13373 | |
| 13374 | /* Wait for up to 1 ms for command to execute. */ |
| 13375 | for (i = 0; i < 100; i++) { |
| 13376 | val = tr32(OTP_STATUS); |
| 13377 | if (val & OTP_STATUS_CMD_DONE) |
| 13378 | break; |
| 13379 | udelay(10); |
| 13380 | } |
| 13381 | |
| 13382 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; |
| 13383 | } |
| 13384 | |
| 13385 | /* Read the gphy configuration from the OTP region of the chip. The gphy |
| 13386 | * configuration is a 32-bit value that straddles the alignment boundary. |
| 13387 | * We do two 32-bit reads and then shift and merge the results. |
| 13388 | */ |
| 13389 | static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp) |
| 13390 | { |
| 13391 | u32 bhalf_otp, thalf_otp; |
| 13392 | |
| 13393 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); |
| 13394 | |
| 13395 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) |
| 13396 | return 0; |
| 13397 | |
| 13398 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); |
| 13399 | |
| 13400 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 13401 | return 0; |
| 13402 | |
| 13403 | thalf_otp = tr32(OTP_READ_DATA); |
| 13404 | |
| 13405 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); |
| 13406 | |
| 13407 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 13408 | return 0; |
| 13409 | |
| 13410 | bhalf_otp = tr32(OTP_READ_DATA); |
| 13411 | |
| 13412 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); |
| 13413 | } |
| 13414 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13415 | static void __devinit tg3_phy_init_link_config(struct tg3 *tp) |
| 13416 | { |
Hiroaki SHIMODA | 202ff1c | 2011-11-22 04:05:41 +0000 | [diff] [blame] | 13417 | u32 adv = ADVERTISED_Autoneg; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13418 | |
| 13419 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
| 13420 | adv |= ADVERTISED_1000baseT_Half | |
| 13421 | ADVERTISED_1000baseT_Full; |
| 13422 | |
| 13423 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 13424 | adv |= ADVERTISED_100baseT_Half | |
| 13425 | ADVERTISED_100baseT_Full | |
| 13426 | ADVERTISED_10baseT_Half | |
| 13427 | ADVERTISED_10baseT_Full | |
| 13428 | ADVERTISED_TP; |
| 13429 | else |
| 13430 | adv |= ADVERTISED_FIBRE; |
| 13431 | |
| 13432 | tp->link_config.advertising = adv; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 13433 | tp->link_config.speed = SPEED_UNKNOWN; |
| 13434 | tp->link_config.duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13435 | tp->link_config.autoneg = AUTONEG_ENABLE; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 13436 | tp->link_config.active_speed = SPEED_UNKNOWN; |
| 13437 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 13438 | |
| 13439 | tp->old_link = -1; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13440 | } |
| 13441 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13442 | static int __devinit tg3_phy_probe(struct tg3 *tp) |
| 13443 | { |
| 13444 | u32 hw_phy_id_1, hw_phy_id_2; |
| 13445 | u32 hw_phy_id, hw_phy_id_masked; |
| 13446 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13447 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13448 | /* flow control autonegotiation is default behavior */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13449 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13450 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 13451 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13452 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13453 | return tg3_phy_init(tp); |
| 13454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13455 | /* Reading the PHY ID register can conflict with ASF |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 13456 | * firmware access to the PHY hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13457 | */ |
| 13458 | err = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13459 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13460 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13461 | } else { |
| 13462 | /* Now read the physical PHY_ID from the chip and verify |
| 13463 | * that it is sane. If it doesn't look good, we fall back |
| 13464 | * to either the hard-coded table based PHY_ID and failing |
| 13465 | * that the value found in the eeprom area. |
| 13466 | */ |
| 13467 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); |
| 13468 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); |
| 13469 | |
| 13470 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; |
| 13471 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; |
| 13472 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; |
| 13473 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13474 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13475 | } |
| 13476 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13477 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13478 | tp->phy_id = hw_phy_id; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13479 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13480 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Michael Chan | da6b2d0 | 2005-08-19 12:54:29 -0700 | [diff] [blame] | 13481 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13482 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13483 | } else { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13484 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13485 | /* Do nothing, phy ID already set up in |
| 13486 | * tg3_get_eeprom_hw_cfg(). |
| 13487 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13488 | } else { |
| 13489 | struct subsys_tbl_ent *p; |
| 13490 | |
| 13491 | /* No eeprom signature? Try the hardcoded |
| 13492 | * subsys device table. |
| 13493 | */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13494 | p = tg3_lookup_by_subsys(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13495 | if (!p) |
| 13496 | return -ENODEV; |
| 13497 | |
| 13498 | tp->phy_id = p->phy_id; |
| 13499 | if (!tp->phy_id || |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13500 | tp->phy_id == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13501 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13502 | } |
| 13503 | } |
| 13504 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 13505 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Matt Carlson | 5baa5e9 | 2011-07-20 10:20:53 +0000 | [diff] [blame] | 13506 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 13507 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 13508 | (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 13509 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) || |
| 13510 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 13511 | tp->pci_chip_rev_id != CHIPREV_ID_57765_A0))) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 13512 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 13513 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13514 | tg3_phy_init_link_config(tp); |
| 13515 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13516 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13517 | !tg3_flag(tp, ENABLE_APE) && |
| 13518 | !tg3_flag(tp, ENABLE_ASF)) { |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 13519 | u32 bmsr, dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13520 | |
| 13521 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 13522 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 13523 | (bmsr & BMSR_LSTATUS)) |
| 13524 | goto skip_phy_reset; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13526 | err = tg3_phy_reset(tp); |
| 13527 | if (err) |
| 13528 | return err; |
| 13529 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 13530 | tg3_phy_set_wirespeed(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13531 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 13532 | if (!tg3_phy_copper_an_config_ok(tp, &dummy)) { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 13533 | tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, |
| 13534 | tp->link_config.flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13535 | |
| 13536 | tg3_writephy(tp, MII_BMCR, |
| 13537 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 13538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13539 | } |
| 13540 | |
| 13541 | skip_phy_reset: |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13542 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13543 | err = tg3_init_5401phy_dsp(tp); |
| 13544 | if (err) |
| 13545 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13547 | err = tg3_init_5401phy_dsp(tp); |
| 13548 | } |
| 13549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13550 | return err; |
| 13551 | } |
| 13552 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13553 | static void __devinit tg3_read_vpd(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13554 | { |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13555 | u8 *vpd_data; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13556 | unsigned int block_end, rosize, len; |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13557 | u32 vpdlen; |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13558 | int j, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13559 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13560 | vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen); |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13561 | if (!vpd_data) |
| 13562 | goto out_no_vpd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13563 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13564 | i = pci_vpd_find_tag(vpd_data, 0, vpdlen, PCI_VPD_LRDT_RO_DATA); |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13565 | if (i < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13566 | goto out_not_found; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13567 | |
| 13568 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
| 13569 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; |
| 13570 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 13571 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13572 | if (block_end > vpdlen) |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13573 | goto out_not_found; |
| 13574 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13575 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 13576 | PCI_VPD_RO_KEYWORD_MFR_ID); |
| 13577 | if (j > 0) { |
| 13578 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 13579 | |
| 13580 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 13581 | if (j + len > block_end || len != 4 || |
| 13582 | memcmp(&vpd_data[j], "1028", 4)) |
| 13583 | goto partno; |
| 13584 | |
| 13585 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 13586 | PCI_VPD_RO_KEYWORD_VENDOR0); |
| 13587 | if (j < 0) |
| 13588 | goto partno; |
| 13589 | |
| 13590 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 13591 | |
| 13592 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 13593 | if (j + len > block_end) |
| 13594 | goto partno; |
| 13595 | |
| 13596 | memcpy(tp->fw_ver, &vpd_data[j], len); |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13597 | strncat(tp->fw_ver, " bc ", vpdlen - len - 1); |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13598 | } |
| 13599 | |
| 13600 | partno: |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13601 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 13602 | PCI_VPD_RO_KEYWORD_PARTNO); |
| 13603 | if (i < 0) |
| 13604 | goto out_not_found; |
| 13605 | |
| 13606 | len = pci_vpd_info_field_size(&vpd_data[i]); |
| 13607 | |
| 13608 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 13609 | if (len > TG3_BPN_SIZE || |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 13610 | (len + i) > vpdlen) |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 13611 | goto out_not_found; |
| 13612 | |
| 13613 | memcpy(tp->board_part_number, &vpd_data[i], len); |
| 13614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13615 | out_not_found: |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13616 | kfree(vpd_data); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13617 | if (tp->board_part_number[0]) |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 13618 | return; |
| 13619 | |
| 13620 | out_no_vpd: |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13621 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 13622 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717) |
| 13623 | strcpy(tp->board_part_number, "BCM5717"); |
| 13624 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) |
| 13625 | strcpy(tp->board_part_number, "BCM5718"); |
| 13626 | else |
| 13627 | goto nomatch; |
| 13628 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 13629 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
| 13630 | strcpy(tp->board_part_number, "BCM57780"); |
| 13631 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) |
| 13632 | strcpy(tp->board_part_number, "BCM57760"); |
| 13633 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) |
| 13634 | strcpy(tp->board_part_number, "BCM57790"); |
| 13635 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) |
| 13636 | strcpy(tp->board_part_number, "BCM57788"); |
| 13637 | else |
| 13638 | goto nomatch; |
| 13639 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
| 13640 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
| 13641 | strcpy(tp->board_part_number, "BCM57761"); |
| 13642 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) |
| 13643 | strcpy(tp->board_part_number, "BCM57765"); |
| 13644 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) |
| 13645 | strcpy(tp->board_part_number, "BCM57781"); |
| 13646 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) |
| 13647 | strcpy(tp->board_part_number, "BCM57785"); |
| 13648 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) |
| 13649 | strcpy(tp->board_part_number, "BCM57791"); |
| 13650 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 13651 | strcpy(tp->board_part_number, "BCM57795"); |
| 13652 | else |
| 13653 | goto nomatch; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 13654 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) { |
| 13655 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762) |
| 13656 | strcpy(tp->board_part_number, "BCM57762"); |
| 13657 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766) |
| 13658 | strcpy(tp->board_part_number, "BCM57766"); |
| 13659 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782) |
| 13660 | strcpy(tp->board_part_number, "BCM57782"); |
| 13661 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 13662 | strcpy(tp->board_part_number, "BCM57786"); |
| 13663 | else |
| 13664 | goto nomatch; |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13665 | } 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] | 13666 | strcpy(tp->board_part_number, "BCM95906"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13667 | } else { |
| 13668 | nomatch: |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13669 | strcpy(tp->board_part_number, "none"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 13670 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13671 | } |
| 13672 | |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13673 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
| 13674 | { |
| 13675 | u32 val; |
| 13676 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13677 | if (tg3_nvram_read(tp, offset, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13678 | (val & 0xfc000000) != 0x0c000000 || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13679 | tg3_nvram_read(tp, offset + 4, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13680 | val != 0) |
| 13681 | return 0; |
| 13682 | |
| 13683 | return 1; |
| 13684 | } |
| 13685 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13686 | static void __devinit tg3_read_bc_ver(struct tg3 *tp) |
| 13687 | { |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13688 | u32 val, offset, start, ver_offset; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13689 | int i, dst_off; |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13690 | bool newver = false; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13691 | |
| 13692 | if (tg3_nvram_read(tp, 0xc, &offset) || |
| 13693 | tg3_nvram_read(tp, 0x4, &start)) |
| 13694 | return; |
| 13695 | |
| 13696 | offset = tg3_nvram_logical_addr(tp, offset); |
| 13697 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13698 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13699 | return; |
| 13700 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13701 | if ((val & 0xfc000000) == 0x0c000000) { |
| 13702 | if (tg3_nvram_read(tp, offset + 4, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13703 | return; |
| 13704 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13705 | if (val == 0) |
| 13706 | newver = true; |
| 13707 | } |
| 13708 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13709 | dst_off = strlen(tp->fw_ver); |
| 13710 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13711 | if (newver) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13712 | if (TG3_VER_SIZE - dst_off < 16 || |
| 13713 | tg3_nvram_read(tp, offset + 8, &ver_offset)) |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13714 | return; |
| 13715 | |
| 13716 | offset = offset + ver_offset - start; |
| 13717 | for (i = 0; i < 16; i += 4) { |
| 13718 | __be32 v; |
| 13719 | if (tg3_nvram_read_be32(tp, offset + i, &v)) |
| 13720 | return; |
| 13721 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13722 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 13723 | } |
| 13724 | } else { |
| 13725 | u32 major, minor; |
| 13726 | |
| 13727 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) |
| 13728 | return; |
| 13729 | |
| 13730 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> |
| 13731 | TG3_NVM_BCVER_MAJSFT; |
| 13732 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13733 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
| 13734 | "v%d.%02d", major, minor); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13735 | } |
| 13736 | } |
| 13737 | |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 13738 | static void __devinit tg3_read_hwsb_ver(struct tg3 *tp) |
| 13739 | { |
| 13740 | u32 val, major, minor; |
| 13741 | |
| 13742 | /* Use native endian representation */ |
| 13743 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) |
| 13744 | return; |
| 13745 | |
| 13746 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> |
| 13747 | TG3_NVM_HWSB_CFG1_MAJSFT; |
| 13748 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> |
| 13749 | TG3_NVM_HWSB_CFG1_MINSFT; |
| 13750 | |
| 13751 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); |
| 13752 | } |
| 13753 | |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13754 | static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val) |
| 13755 | { |
| 13756 | u32 offset, major, minor, build; |
| 13757 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13758 | 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] | 13759 | |
| 13760 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) |
| 13761 | return; |
| 13762 | |
| 13763 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { |
| 13764 | case TG3_EEPROM_SB_REVISION_0: |
| 13765 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; |
| 13766 | break; |
| 13767 | case TG3_EEPROM_SB_REVISION_2: |
| 13768 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; |
| 13769 | break; |
| 13770 | case TG3_EEPROM_SB_REVISION_3: |
| 13771 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; |
| 13772 | break; |
Matt Carlson | a4153d4 | 2010-02-17 15:16:56 +0000 | [diff] [blame] | 13773 | case TG3_EEPROM_SB_REVISION_4: |
| 13774 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; |
| 13775 | break; |
| 13776 | case TG3_EEPROM_SB_REVISION_5: |
| 13777 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; |
| 13778 | break; |
Matt Carlson | bba226a | 2010-10-14 10:37:38 +0000 | [diff] [blame] | 13779 | case TG3_EEPROM_SB_REVISION_6: |
| 13780 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; |
| 13781 | break; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13782 | default: |
| 13783 | return; |
| 13784 | } |
| 13785 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13786 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13787 | return; |
| 13788 | |
| 13789 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> |
| 13790 | TG3_EEPROM_SB_EDH_BLD_SHFT; |
| 13791 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> |
| 13792 | TG3_EEPROM_SB_EDH_MAJ_SHFT; |
| 13793 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; |
| 13794 | |
| 13795 | if (minor > 99 || build > 26) |
| 13796 | return; |
| 13797 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13798 | offset = strlen(tp->fw_ver); |
| 13799 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, |
| 13800 | " v%d.%02d", major, minor); |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13801 | |
| 13802 | if (build > 0) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13803 | offset = strlen(tp->fw_ver); |
| 13804 | if (offset < TG3_VER_SIZE - 1) |
| 13805 | tp->fw_ver[offset] = 'a' + build - 1; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 13806 | } |
| 13807 | } |
| 13808 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13809 | static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp) |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13810 | { |
| 13811 | u32 val, offset, start; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13812 | int i, vlen; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13813 | |
| 13814 | for (offset = TG3_NVM_DIR_START; |
| 13815 | offset < TG3_NVM_DIR_END; |
| 13816 | offset += TG3_NVM_DIRENT_SIZE) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13817 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13818 | return; |
| 13819 | |
| 13820 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
| 13821 | break; |
| 13822 | } |
| 13823 | |
| 13824 | if (offset == TG3_NVM_DIR_END) |
| 13825 | return; |
| 13826 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13827 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13828 | start = 0x08000000; |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13829 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13830 | return; |
| 13831 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13832 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13833 | !tg3_fw_img_is_valid(tp, offset) || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13834 | tg3_nvram_read(tp, offset + 8, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13835 | return; |
| 13836 | |
| 13837 | offset += val - start; |
| 13838 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13839 | vlen = strlen(tp->fw_ver); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13840 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13841 | tp->fw_ver[vlen++] = ','; |
| 13842 | tp->fw_ver[vlen++] = ' '; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13843 | |
| 13844 | for (i = 0; i < 4; i++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 13845 | __be32 v; |
| 13846 | if (tg3_nvram_read_be32(tp, offset, &v)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13847 | return; |
| 13848 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 13849 | offset += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13850 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13851 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
| 13852 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13853 | break; |
| 13854 | } |
| 13855 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13856 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
| 13857 | vlen += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13858 | } |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13859 | } |
| 13860 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13861 | static void __devinit tg3_read_dash_ver(struct tg3 *tp) |
| 13862 | { |
| 13863 | int vlen; |
| 13864 | u32 apedata; |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13865 | char *fwtype; |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13866 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13867 | if (!tg3_flag(tp, ENABLE_APE) || !tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13868 | return; |
| 13869 | |
| 13870 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 13871 | if (apedata != APE_SEG_SIG_MAGIC) |
| 13872 | return; |
| 13873 | |
| 13874 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 13875 | if (!(apedata & APE_FW_STATUS_READY)) |
| 13876 | return; |
| 13877 | |
| 13878 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
| 13879 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13880 | 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] | 13881 | tg3_flag_set(tp, APE_HAS_NCSI); |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13882 | fwtype = "NCSI"; |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13883 | } else { |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13884 | fwtype = "DASH"; |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13885 | } |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13886 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13887 | vlen = strlen(tp->fw_ver); |
| 13888 | |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13889 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
| 13890 | fwtype, |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13891 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
| 13892 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, |
| 13893 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, |
| 13894 | (apedata & APE_FW_VERSION_BLDMSK)); |
| 13895 | } |
| 13896 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13897 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
| 13898 | { |
| 13899 | u32 val; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13900 | bool vpd_vers = false; |
| 13901 | |
| 13902 | if (tp->fw_ver[0] != 0) |
| 13903 | vpd_vers = true; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13904 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13905 | if (tg3_flag(tp, NO_NVRAM)) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13906 | strcat(tp->fw_ver, "sb"); |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 13907 | return; |
| 13908 | } |
| 13909 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13910 | if (tg3_nvram_read(tp, 0, &val)) |
| 13911 | return; |
| 13912 | |
| 13913 | if (val == TG3_EEPROM_MAGIC) |
| 13914 | tg3_read_bc_ver(tp); |
| 13915 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) |
| 13916 | tg3_read_sb_ver(tp, val); |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 13917 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 13918 | tg3_read_hwsb_ver(tp); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13919 | else |
| 13920 | return; |
| 13921 | |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 13922 | if (vpd_vers) |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13923 | goto done; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13924 | |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 13925 | if (tg3_flag(tp, ENABLE_APE)) { |
| 13926 | if (tg3_flag(tp, ENABLE_ASF)) |
| 13927 | tg3_read_dash_ver(tp); |
| 13928 | } else if (tg3_flag(tp, ENABLE_ASF)) { |
| 13929 | tg3_read_mgmtfw_ver(tp); |
| 13930 | } |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13931 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13932 | done: |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13933 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13934 | } |
| 13935 | |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13936 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
| 13937 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13938 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 13939 | return TG3_RX_RET_MAX_SIZE_5717; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13940 | else if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 13941 | return TG3_RX_RET_MAX_SIZE_5700; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13942 | else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 13943 | return TG3_RX_RET_MAX_SIZE_5705; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13944 | } |
| 13945 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 13946 | static DEFINE_PCI_DEVICE_TABLE(tg3_write_reorder_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 13947 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
| 13948 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
| 13949 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8385_0) }, |
| 13950 | { }, |
| 13951 | }; |
| 13952 | |
Matt Carlson | 16c7fa7 | 2012-02-13 10:20:10 +0000 | [diff] [blame] | 13953 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp) |
| 13954 | { |
| 13955 | struct pci_dev *peer; |
| 13956 | unsigned int func, devnr = tp->pdev->devfn & ~7; |
| 13957 | |
| 13958 | for (func = 0; func < 8; func++) { |
| 13959 | peer = pci_get_slot(tp->pdev->bus, devnr | func); |
| 13960 | if (peer && peer != tp->pdev) |
| 13961 | break; |
| 13962 | pci_dev_put(peer); |
| 13963 | } |
| 13964 | /* 5704 can be configured in single-port mode, set peer to |
| 13965 | * tp->pdev in that case. |
| 13966 | */ |
| 13967 | if (!peer) { |
| 13968 | peer = tp->pdev; |
| 13969 | return peer; |
| 13970 | } |
| 13971 | |
| 13972 | /* |
| 13973 | * We don't need to keep the refcount elevated; there's no way |
| 13974 | * to remove one half of this device without removing the other |
| 13975 | */ |
| 13976 | pci_dev_put(peer); |
| 13977 | |
| 13978 | return peer; |
| 13979 | } |
| 13980 | |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 13981 | static void __devinit tg3_detect_asic_rev(struct tg3 *tp, u32 misc_ctrl_reg) |
| 13982 | { |
| 13983 | tp->pci_chip_rev_id = misc_ctrl_reg >> MISC_HOST_CTRL_CHIPREV_SHIFT; |
| 13984 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
| 13985 | u32 reg; |
| 13986 | |
| 13987 | /* All devices that use the alternate |
| 13988 | * ASIC REV location have a CPMU. |
| 13989 | */ |
| 13990 | tg3_flag_set(tp, CPMU_PRESENT); |
| 13991 | |
| 13992 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 13993 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 13994 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
| 13995 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720) |
| 13996 | reg = TG3PCI_GEN2_PRODID_ASICREV; |
| 13997 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
| 13998 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || |
| 13999 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || |
| 14000 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || |
| 14001 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 14002 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
| 14003 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762 || |
| 14004 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766 || |
| 14005 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782 || |
| 14006 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 14007 | reg = TG3PCI_GEN15_PRODID_ASICREV; |
| 14008 | else |
| 14009 | reg = TG3PCI_PRODID_ASICREV; |
| 14010 | |
| 14011 | pci_read_config_dword(tp->pdev, reg, &tp->pci_chip_rev_id); |
| 14012 | } |
| 14013 | |
| 14014 | /* Wrong chip ID in 5752 A0. This code can be removed later |
| 14015 | * as A0 is not in production. |
| 14016 | */ |
| 14017 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) |
| 14018 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
| 14019 | |
| 14020 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14021 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14022 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 14023 | tg3_flag_set(tp, 5717_PLUS); |
| 14024 | |
| 14025 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 || |
| 14026 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) |
| 14027 | tg3_flag_set(tp, 57765_CLASS); |
| 14028 | |
| 14029 | if (tg3_flag(tp, 57765_CLASS) || tg3_flag(tp, 5717_PLUS)) |
| 14030 | tg3_flag_set(tp, 57765_PLUS); |
| 14031 | |
| 14032 | /* Intentionally exclude ASIC_REV_5906 */ |
| 14033 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 14034 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
| 14035 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 14036 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 14037 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 14038 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 14039 | tg3_flag(tp, 57765_PLUS)) |
| 14040 | tg3_flag_set(tp, 5755_PLUS); |
| 14041 | |
| 14042 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
| 14043 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) |
| 14044 | tg3_flag_set(tp, 5780_CLASS); |
| 14045 | |
| 14046 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 14047 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 14048 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
| 14049 | tg3_flag(tp, 5755_PLUS) || |
| 14050 | tg3_flag(tp, 5780_CLASS)) |
| 14051 | tg3_flag_set(tp, 5750_PLUS); |
| 14052 | |
| 14053 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 14054 | tg3_flag(tp, 5750_PLUS)) |
| 14055 | tg3_flag_set(tp, 5705_PLUS); |
| 14056 | } |
| 14057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14058 | static int __devinit tg3_get_invariants(struct tg3 *tp) |
| 14059 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14060 | u32 misc_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14061 | u32 pci_state_reg, grc_misc_cfg; |
| 14062 | u32 val; |
| 14063 | u16 pci_cmd; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14064 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14065 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14066 | /* Force memory write invalidate off. If we leave it on, |
| 14067 | * then on 5700_BX chips we have to enable a workaround. |
| 14068 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary |
| 14069 | * to match the cacheline size. The Broadcom driver have this |
| 14070 | * workaround but turns MWI off all the times so never uses |
| 14071 | * it. This seems to suggest that the workaround is insufficient. |
| 14072 | */ |
| 14073 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 14074 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; |
| 14075 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 14076 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14077 | /* Important! -- Make sure register accesses are byteswapped |
| 14078 | * correctly. Also, for those chips that require it, make |
| 14079 | * sure that indirect register accesses are enabled before |
| 14080 | * the first operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14081 | */ |
| 14082 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 14083 | &misc_ctrl_reg); |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14084 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
| 14085 | MISC_HOST_CTRL_CHIPREV); |
| 14086 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 14087 | tp->misc_host_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14088 | |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14089 | tg3_detect_asic_rev(tp, misc_ctrl_reg); |
Michael Chan | ff645be | 2005-04-21 17:09:53 -0700 | [diff] [blame] | 14090 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14091 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
| 14092 | * we need to disable memory and use config. cycles |
| 14093 | * only to access all registers. The 5702/03 chips |
| 14094 | * can mistakenly decode the special cycles from the |
| 14095 | * ICH chipsets as memory write cycles, causing corruption |
| 14096 | * of register and memory space. Only certain ICH bridges |
| 14097 | * will drive special cycles with non-zero data during the |
| 14098 | * address phase which can fall within the 5703's address |
| 14099 | * range. This is not an ICH bug as the PCI spec allows |
| 14100 | * non-zero address during special cycles. However, only |
| 14101 | * these ICH bridges are known to drive non-zero addresses |
| 14102 | * during special cycles. |
| 14103 | * |
| 14104 | * Since special cycles do not cross PCI bridges, we only |
| 14105 | * enable this workaround if the 5703 is on the secondary |
| 14106 | * bus of these ICH bridges. |
| 14107 | */ |
| 14108 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || |
| 14109 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { |
| 14110 | static struct tg3_dev_id { |
| 14111 | u32 vendor; |
| 14112 | u32 device; |
| 14113 | u32 rev; |
| 14114 | } ich_chipsets[] = { |
| 14115 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, |
| 14116 | PCI_ANY_ID }, |
| 14117 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, |
| 14118 | PCI_ANY_ID }, |
| 14119 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, |
| 14120 | 0xa }, |
| 14121 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, |
| 14122 | PCI_ANY_ID }, |
| 14123 | { }, |
| 14124 | }; |
| 14125 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; |
| 14126 | struct pci_dev *bridge = NULL; |
| 14127 | |
| 14128 | while (pci_id->vendor != 0) { |
| 14129 | bridge = pci_get_device(pci_id->vendor, pci_id->device, |
| 14130 | bridge); |
| 14131 | if (!bridge) { |
| 14132 | pci_id++; |
| 14133 | continue; |
| 14134 | } |
| 14135 | if (pci_id->rev != PCI_ANY_ID) { |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 14136 | if (bridge->revision > pci_id->rev) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14137 | continue; |
| 14138 | } |
| 14139 | if (bridge->subordinate && |
| 14140 | (bridge->subordinate->number == |
| 14141 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14142 | tg3_flag_set(tp, ICH_WORKAROUND); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14143 | pci_dev_put(bridge); |
| 14144 | break; |
| 14145 | } |
| 14146 | } |
| 14147 | } |
| 14148 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14149 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 14150 | static struct tg3_dev_id { |
| 14151 | u32 vendor; |
| 14152 | u32 device; |
| 14153 | } bridge_chipsets[] = { |
| 14154 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, |
| 14155 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, |
| 14156 | { }, |
| 14157 | }; |
| 14158 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; |
| 14159 | struct pci_dev *bridge = NULL; |
| 14160 | |
| 14161 | while (pci_id->vendor != 0) { |
| 14162 | bridge = pci_get_device(pci_id->vendor, |
| 14163 | pci_id->device, |
| 14164 | bridge); |
| 14165 | if (!bridge) { |
| 14166 | pci_id++; |
| 14167 | continue; |
| 14168 | } |
| 14169 | if (bridge->subordinate && |
| 14170 | (bridge->subordinate->number <= |
| 14171 | tp->pdev->bus->number) && |
| 14172 | (bridge->subordinate->subordinate >= |
| 14173 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14174 | tg3_flag_set(tp, 5701_DMA_BUG); |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 14175 | pci_dev_put(bridge); |
| 14176 | break; |
| 14177 | } |
| 14178 | } |
| 14179 | } |
| 14180 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14181 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
| 14182 | * DMA addresses > 40-bit. This bridge may have other additional |
| 14183 | * 57xx devices behind it in some 4-port NIC designs for example. |
| 14184 | * Any tg3 device found behind the bridge will also need the 40-bit |
| 14185 | * DMA workaround. |
| 14186 | */ |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14187 | if (tg3_flag(tp, 5780_CLASS)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14188 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 14189 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14190 | } else { |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14191 | struct pci_dev *bridge = NULL; |
| 14192 | |
| 14193 | do { |
| 14194 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, |
| 14195 | PCI_DEVICE_ID_SERVERWORKS_EPB, |
| 14196 | bridge); |
| 14197 | if (bridge && bridge->subordinate && |
| 14198 | (bridge->subordinate->number <= |
| 14199 | tp->pdev->bus->number) && |
| 14200 | (bridge->subordinate->subordinate >= |
| 14201 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14202 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14203 | pci_dev_put(bridge); |
| 14204 | break; |
| 14205 | } |
| 14206 | } while (bridge); |
| 14207 | } |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 14208 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14209 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 14210 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 14211 | tp->pdev_peer = tg3_find_peer(tp); |
| 14212 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14213 | /* Determine TSO capabilities */ |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 14214 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0) |
Matt Carlson | 4d163b7 | 2011-01-25 15:58:48 +0000 | [diff] [blame] | 14215 | ; /* Do nothing. HW bug. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14216 | else if (tg3_flag(tp, 57765_PLUS)) |
| 14217 | tg3_flag_set(tp, HW_TSO_3); |
| 14218 | else if (tg3_flag(tp, 5755_PLUS) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14219 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14220 | tg3_flag_set(tp, HW_TSO_2); |
| 14221 | else if (tg3_flag(tp, 5750_PLUS)) { |
| 14222 | tg3_flag_set(tp, HW_TSO_1); |
| 14223 | tg3_flag_set(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14224 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && |
| 14225 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14226 | tg3_flag_clear(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14227 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14228 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 14229 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14230 | tg3_flag_set(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14231 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) |
| 14232 | tp->fw_needed = FIRMWARE_TG3TSO5; |
| 14233 | else |
| 14234 | tp->fw_needed = FIRMWARE_TG3TSO; |
| 14235 | } |
| 14236 | |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14237 | /* Selectively allow TSO based on operating conditions */ |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14238 | if (tg3_flag(tp, HW_TSO_1) || |
| 14239 | tg3_flag(tp, HW_TSO_2) || |
| 14240 | tg3_flag(tp, HW_TSO_3) || |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 14241 | tp->fw_needed) { |
| 14242 | /* For firmware TSO, assume ASF is disabled. |
| 14243 | * We'll disable TSO later if we discover ASF |
| 14244 | * is enabled in tg3_get_eeprom_hw_cfg(). |
| 14245 | */ |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14246 | tg3_flag_set(tp, TSO_CAPABLE); |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 14247 | } else { |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14248 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 14249 | tg3_flag_clear(tp, TSO_BUG); |
| 14250 | tp->fw_needed = NULL; |
| 14251 | } |
| 14252 | |
| 14253 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) |
| 14254 | tp->fw_needed = FIRMWARE_TG3; |
| 14255 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14256 | tp->irq_max = 1; |
| 14257 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14258 | if (tg3_flag(tp, 5750_PLUS)) { |
| 14259 | tg3_flag_set(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 14260 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || |
| 14261 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || |
| 14262 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && |
| 14263 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && |
| 14264 | tp->pdev_peer == tp->pdev)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14265 | tg3_flag_clear(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 14266 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14267 | if (tg3_flag(tp, 5755_PLUS) || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14268 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14269 | tg3_flag_set(tp, 1SHOT_MSI); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 14270 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14271 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14272 | if (tg3_flag(tp, 57765_PLUS)) { |
| 14273 | tg3_flag_set(tp, SUPPORT_MSIX); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14274 | tp->irq_max = TG3_IRQ_MAX_VECS; |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 14275 | tg3_rss_init_dflt_indir_tbl(tp); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14276 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14277 | } |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 14278 | |
Matt Carlson | b7abee6 | 2012-06-07 12:56:54 +0000 | [diff] [blame] | 14279 | if (tg3_flag(tp, 5755_PLUS) || |
| 14280 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14281 | tg3_flag_set(tp, SHORT_DMA_BUG); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14282 | |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 14283 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 14284 | tp->dma_limit = TG3_TX_BD_DMA_MAX_4K; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 14285 | |
Matt Carlson | fa6b2aa | 2011-11-21 15:01:19 +0000 | [diff] [blame] | 14286 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14287 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14288 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14289 | tg3_flag_set(tp, LRG_PROD_RING_CAP); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 14290 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14291 | if (tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 14292 | tp->pci_chip_rev_id != CHIPREV_ID_5719_A0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14293 | tg3_flag_set(tp, USE_JUMBO_BDFLAG); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 14294 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14295 | if (!tg3_flag(tp, 5705_PLUS) || |
| 14296 | tg3_flag(tp, 5780_CLASS) || |
| 14297 | tg3_flag(tp, USE_JUMBO_BDFLAG)) |
| 14298 | tg3_flag_set(tp, JUMBO_CAPABLE); |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 14299 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14300 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 14301 | &pci_state_reg); |
| 14302 | |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 14303 | if (pci_is_pcie(tp->pdev)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14304 | u16 lnkctl; |
| 14305 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14306 | tg3_flag_set(tp, PCI_EXPRESS); |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 14307 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14308 | pci_read_config_word(tp->pdev, |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 14309 | pci_pcie_cap(tp->pdev) + PCI_EXP_LNKCTL, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14310 | &lnkctl); |
| 14311 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
Matt Carlson | 7196cd6 | 2011-05-19 16:02:44 +0000 | [diff] [blame] | 14312 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 14313 | ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14314 | tg3_flag_clear(tp, HW_TSO_2); |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14315 | tg3_flag_clear(tp, TSO_CAPABLE); |
Matt Carlson | 7196cd6 | 2011-05-19 16:02:44 +0000 | [diff] [blame] | 14316 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14317 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14318 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 9cf74eb | 2009-04-20 06:58:27 +0000 | [diff] [blame] | 14319 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
| 14320 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14321 | tg3_flag_set(tp, CLKREQ_BUG); |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 14322 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14323 | tg3_flag_set(tp, L1PLLPD_EN); |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 14324 | } |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14325 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 14326 | /* BCM5785 devices are effectively PCIe devices, and should |
| 14327 | * follow PCIe codepaths, but do not have a PCIe capabilities |
| 14328 | * section. |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 14329 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14330 | tg3_flag_set(tp, PCI_EXPRESS); |
| 14331 | } else if (!tg3_flag(tp, 5705_PLUS) || |
| 14332 | tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14333 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
| 14334 | if (!tp->pcix_cap) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14335 | dev_err(&tp->pdev->dev, |
| 14336 | "Cannot find PCI-X capability, aborting\n"); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14337 | return -EIO; |
| 14338 | } |
| 14339 | |
| 14340 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14341 | tg3_flag_set(tp, PCIX_MODE); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14342 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14343 | |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 14344 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
| 14345 | * reordering to the mailbox registers done by the host |
| 14346 | * controller can cause major troubles. We read back from |
| 14347 | * every mailbox register write to force the writes to be |
| 14348 | * posted to the chip in order. |
| 14349 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 14350 | if (pci_dev_present(tg3_write_reorder_chipsets) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14351 | !tg3_flag(tp, PCI_EXPRESS)) |
| 14352 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 14353 | |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 14354 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 14355 | &tp->pci_cacheline_sz); |
| 14356 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 14357 | &tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14358 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 14359 | tp->pci_lat_timer < 64) { |
| 14360 | tp->pci_lat_timer = 64; |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 14361 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 14362 | tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14363 | } |
| 14364 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14365 | /* Important! -- It is critical that the PCI-X hw workaround |
| 14366 | * situation is decided before the first MMIO register access. |
| 14367 | */ |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14368 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
| 14369 | /* 5700 BX chips need to have their TX producer index |
| 14370 | * mailboxes written twice to workaround a bug. |
| 14371 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14372 | tg3_flag_set(tp, TXD_MBOX_HWBUG); |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 14373 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14374 | /* If we are in PCI-X mode, enable register write workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14375 | * |
| 14376 | * The workaround is to use indirect register accesses |
| 14377 | * for all chip writes not to mailbox registers. |
| 14378 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14379 | if (tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14380 | u32 pm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14381 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14382 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14383 | |
| 14384 | /* The chip can have it's power management PCI config |
| 14385 | * space registers clobbered due to this bug. |
| 14386 | * So explicitly force the chip into D0 here. |
| 14387 | */ |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 14388 | pci_read_config_dword(tp->pdev, |
| 14389 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14390 | &pm_reg); |
| 14391 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; |
| 14392 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 14393 | pci_write_config_dword(tp->pdev, |
| 14394 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14395 | pm_reg); |
| 14396 | |
| 14397 | /* Also, force SERR#/PERR# in PCI command. */ |
| 14398 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 14399 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
| 14400 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 14401 | } |
| 14402 | } |
| 14403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14404 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14405 | tg3_flag_set(tp, PCI_HIGH_SPEED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14406 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14407 | tg3_flag_set(tp, PCI_32BIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14408 | |
| 14409 | /* Chip-specific fixup from Broadcom driver */ |
| 14410 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && |
| 14411 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
| 14412 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; |
| 14413 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); |
| 14414 | } |
| 14415 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14416 | /* Default fast path register access methods */ |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 14417 | tp->read32 = tg3_read32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14418 | tp->write32 = tg3_write32; |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 14419 | tp->read32_mbox = tg3_read32; |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 14420 | tp->write32_mbox = tg3_write32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14421 | tp->write32_tx_mbox = tg3_write32; |
| 14422 | tp->write32_rx_mbox = tg3_write32; |
| 14423 | |
| 14424 | /* Various workaround register access methods */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14425 | if (tg3_flag(tp, PCIX_TARGET_HWBUG)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14426 | tp->write32 = tg3_write_indirect_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 14427 | 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] | 14428 | (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 14429 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { |
| 14430 | /* |
| 14431 | * Back to back register writes can cause problems on these |
| 14432 | * chips, the workaround is to read back all reg writes |
| 14433 | * except those to mailbox regs. |
| 14434 | * |
| 14435 | * See tg3_write_indirect_reg32(). |
| 14436 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14437 | tp->write32 = tg3_write_flush_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 14438 | } |
| 14439 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14440 | 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] | 14441 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14442 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14443 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 14444 | } |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 14445 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14446 | if (tg3_flag(tp, ICH_WORKAROUND)) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14447 | tp->read32 = tg3_read_indirect_reg32; |
| 14448 | tp->write32 = tg3_write_indirect_reg32; |
| 14449 | tp->read32_mbox = tg3_read_indirect_mbox; |
| 14450 | tp->write32_mbox = tg3_write_indirect_mbox; |
| 14451 | tp->write32_tx_mbox = tg3_write_indirect_mbox; |
| 14452 | tp->write32_rx_mbox = tg3_write_indirect_mbox; |
| 14453 | |
| 14454 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 14455 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14456 | |
| 14457 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 14458 | pci_cmd &= ~PCI_COMMAND_MEMORY; |
| 14459 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 14460 | } |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14461 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 14462 | tp->read32_mbox = tg3_read32_mbox_5906; |
| 14463 | tp->write32_mbox = tg3_write32_mbox_5906; |
| 14464 | tp->write32_tx_mbox = tg3_write32_mbox_5906; |
| 14465 | tp->write32_rx_mbox = tg3_write32_mbox_5906; |
| 14466 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14467 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 14468 | if (tp->write32 == tg3_write_indirect_reg32 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14469 | (tg3_flag(tp, PCIX_MODE) && |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 14470 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 14471 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14472 | tg3_flag_set(tp, SRAM_USE_CONFIG); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 14473 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14474 | /* The memory arbiter has to be enabled in order for SRAM accesses |
| 14475 | * to succeed. Normally on powerup the tg3 chip firmware will make |
| 14476 | * sure it is enabled, but other entities such as system netboot |
| 14477 | * code might disable it. |
| 14478 | */ |
| 14479 | val = tr32(MEMARB_MODE); |
| 14480 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 14481 | |
Matt Carlson | 9dc5e34 | 2011-11-04 09:15:02 +0000 | [diff] [blame] | 14482 | tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3; |
| 14483 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 14484 | tg3_flag(tp, 5780_CLASS)) { |
| 14485 | if (tg3_flag(tp, PCIX_MODE)) { |
| 14486 | pci_read_config_dword(tp->pdev, |
| 14487 | tp->pcix_cap + PCI_X_STATUS, |
| 14488 | &val); |
| 14489 | tp->pci_fn = val & 0x7; |
| 14490 | } |
| 14491 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 14492 | tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val); |
| 14493 | if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) == |
| 14494 | NIC_SRAM_CPMUSTAT_SIG) { |
| 14495 | tp->pci_fn = val & TG3_CPMU_STATUS_FMSK_5717; |
| 14496 | tp->pci_fn = tp->pci_fn ? 1 : 0; |
| 14497 | } |
| 14498 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14499 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 14500 | tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val); |
| 14501 | if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) == |
| 14502 | NIC_SRAM_CPMUSTAT_SIG) { |
| 14503 | tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5719) >> |
| 14504 | TG3_CPMU_STATUS_FSHFT_5719; |
| 14505 | } |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 14506 | } |
| 14507 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14508 | /* Get eeprom hw config before calling tg3_set_power_state(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14509 | * In particular, the TG3_FLAG_IS_NIC flag must be |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14510 | * determined before calling tg3_set_power_state() so that |
| 14511 | * we know whether or not to switch out of Vaux power. |
| 14512 | * When the flag is set, it means that GPIO1 is used for eeprom |
| 14513 | * write protect and also implies that it is a LOM where GPIOs |
| 14514 | * are not used to switch power. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 14515 | */ |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14516 | tg3_get_eeprom_hw_cfg(tp); |
| 14517 | |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 14518 | if (tp->fw_needed && tg3_flag(tp, ENABLE_ASF)) { |
| 14519 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 14520 | tg3_flag_clear(tp, TSO_BUG); |
| 14521 | tp->fw_needed = NULL; |
| 14522 | } |
| 14523 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14524 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14525 | /* Allow reads and writes to the |
| 14526 | * APE register and memory space. |
| 14527 | */ |
| 14528 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 14529 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 14530 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14531 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 14532 | pci_state_reg); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 14533 | |
| 14534 | tg3_ape_lock_init(tp); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14535 | } |
| 14536 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14537 | /* Set up tp->grc_local_ctrl before calling |
| 14538 | * tg3_pwrsrc_switch_to_vmain(). GPIO1 driven high |
| 14539 | * will bring 5700's external PHY out of reset. |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 14540 | * It is also used as eeprom write protect on LOMs. |
| 14541 | */ |
| 14542 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14543 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14544 | tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 14545 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 14546 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 14547 | /* Unused GPIO3 must be driven as output on 5752 because there |
| 14548 | * are no pull-up resistors on unused GPIO pins. |
| 14549 | */ |
| 14550 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 14551 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 14552 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14553 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | cb4ed1f | 2010-01-20 16:58:09 +0000 | [diff] [blame] | 14554 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 14555 | tg3_flag(tp, 57765_CLASS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 14556 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 14557 | |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 14558 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 14559 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 14560 | /* Turn off the debug UART. */ |
| 14561 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14562 | if (tg3_flag(tp, IS_NIC)) |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 14563 | /* Keep VMain power. */ |
| 14564 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 14565 | GRC_LCLCTRL_GPIO_OUTPUT0; |
| 14566 | } |
| 14567 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14568 | /* Switch out of Vaux if it is a NIC */ |
| 14569 | tg3_pwrsrc_switch_to_vmain(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14571 | /* Derive initial jumbo mode from MTU assigned in |
| 14572 | * ether_setup() via the alloc_etherdev() call |
| 14573 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14574 | if (tp->dev->mtu > ETH_DATA_LEN && !tg3_flag(tp, 5780_CLASS)) |
| 14575 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14576 | |
| 14577 | /* Determine WakeOnLan speed to use. */ |
| 14578 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 14579 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 14580 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || |
| 14581 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14582 | tg3_flag_clear(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14583 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14584 | tg3_flag_set(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14585 | } |
| 14586 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 14587 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14588 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 14589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14590 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14591 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 14592 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14593 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 14594 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14595 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
| 14596 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 14597 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14598 | |
| 14599 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || |
| 14600 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14601 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14602 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14603 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14604 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14605 | if (tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14606 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14607 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14608 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14609 | !tg3_flag(tp, 57765_PLUS)) { |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 14610 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 14611 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 14612 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 14613 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
Michael Chan | d4011ad | 2007-02-13 12:17:25 -0800 | [diff] [blame] | 14614 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
| 14615 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14616 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 14617 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14618 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14619 | } else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14620 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 14621 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14622 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 14623 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 14624 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 14625 | tp->phy_otp = tg3_read_otp_phycfg(tp); |
| 14626 | if (tp->phy_otp == 0) |
| 14627 | tp->phy_otp = TG3_OTP_DEFAULT; |
| 14628 | } |
| 14629 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14630 | if (tg3_flag(tp, CPMU_PRESENT)) |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 14631 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
| 14632 | else |
| 14633 | tp->mi_mode = MAC_MI_MODE_BASE; |
| 14634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14635 | tp->coalesce_mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14636 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
| 14637 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) |
| 14638 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
| 14639 | |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 14640 | /* Set these bits to enable statistics workaround. */ |
| 14641 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14642 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 14643 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) { |
| 14644 | tp->coalesce_mode |= HOSTCC_MODE_ATTN; |
| 14645 | tp->grc_mode |= GRC_MODE_IRQ_ON_FLOW_ATTN; |
| 14646 | } |
| 14647 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14648 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 14649 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14650 | tg3_flag_set(tp, USE_PHYLIB); |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 14651 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 14652 | err = tg3_mdio_init(tp); |
| 14653 | if (err) |
| 14654 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14655 | |
| 14656 | /* Initialize data/descriptor byte/word swapping. */ |
| 14657 | val = tr32(GRC_MODE); |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 14658 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 14659 | val &= (GRC_MODE_BYTE_SWAP_B2HRX_DATA | |
| 14660 | GRC_MODE_WORD_SWAP_B2HRX_DATA | |
| 14661 | GRC_MODE_B2HRX_ENABLE | |
| 14662 | GRC_MODE_HTX2B_ENABLE | |
| 14663 | GRC_MODE_HOST_STACKUP); |
| 14664 | else |
| 14665 | val &= GRC_MODE_HOST_STACKUP; |
| 14666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14667 | tw32(GRC_MODE, val | tp->grc_mode); |
| 14668 | |
| 14669 | tg3_switch_clocks(tp); |
| 14670 | |
| 14671 | /* Clear this out for sanity. */ |
| 14672 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 14673 | |
| 14674 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 14675 | &pci_state_reg); |
| 14676 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14677 | !tg3_flag(tp, PCIX_TARGET_HWBUG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14678 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); |
| 14679 | |
| 14680 | if (chiprevid == CHIPREV_ID_5701_A0 || |
| 14681 | chiprevid == CHIPREV_ID_5701_B0 || |
| 14682 | chiprevid == CHIPREV_ID_5701_B2 || |
| 14683 | chiprevid == CHIPREV_ID_5701_B5) { |
| 14684 | void __iomem *sram_base; |
| 14685 | |
| 14686 | /* Write some dummy words into the SRAM status block |
| 14687 | * area, see if it reads back correctly. If the return |
| 14688 | * value is bad, force enable the PCIX workaround. |
| 14689 | */ |
| 14690 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; |
| 14691 | |
| 14692 | writel(0x00000000, sram_base); |
| 14693 | writel(0x00000000, sram_base + 4); |
| 14694 | writel(0xffffffff, sram_base + 4); |
| 14695 | if (readl(sram_base) != 0x00000000) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14696 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14697 | } |
| 14698 | } |
| 14699 | |
| 14700 | udelay(50); |
| 14701 | tg3_nvram_init(tp); |
| 14702 | |
| 14703 | grc_misc_cfg = tr32(GRC_MISC_CFG); |
| 14704 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; |
| 14705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14706 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 14707 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
| 14708 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14709 | tg3_flag_set(tp, IS_5788); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14710 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14711 | if (!tg3_flag(tp, IS_5788) && |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14712 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14713 | tg3_flag_set(tp, TAGGED_STATUS); |
| 14714 | if (tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 14715 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
| 14716 | HOSTCC_MODE_CLRTICK_TXBD); |
| 14717 | |
| 14718 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; |
| 14719 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 14720 | tp->misc_host_ctrl); |
| 14721 | } |
| 14722 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 14723 | /* Preserve the APE MAC_MODE bits */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14724 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 14725 | 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] | 14726 | else |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 14727 | tp->mac_mode = 0; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 14728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14729 | /* these are limited to 10/100 only */ |
| 14730 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 14731 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || |
| 14732 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 14733 | tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 14734 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 || |
| 14735 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 || |
| 14736 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) || |
| 14737 | (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 14738 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F || |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 14739 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F || |
| 14740 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14741 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790 || |
Matt Carlson | d110114 | 2010-02-17 15:16:55 +0000 | [diff] [blame] | 14742 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 14743 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14744 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
| 14745 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14746 | |
| 14747 | err = tg3_phy_probe(tp); |
| 14748 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14749 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14750 | /* ... but do not return immediately ... */ |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14751 | tg3_mdio_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14752 | } |
| 14753 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 14754 | tg3_read_vpd(tp); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 14755 | tg3_read_fw_ver(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14756 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14757 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 14758 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14759 | } else { |
| 14760 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14761 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14762 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14763 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14764 | } |
| 14765 | |
| 14766 | /* 5700 {AX,BX} chips have a broken status block link |
| 14767 | * change bit implementation, so we must use the |
| 14768 | * status register in those cases. |
| 14769 | */ |
| 14770 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14771 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14772 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14773 | tg3_flag_clear(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14774 | |
| 14775 | /* The led_ctrl is set during tg3_phy_probe, here we might |
| 14776 | * have to force the link status polling mechanism based |
| 14777 | * upon subsystem IDs. |
| 14778 | */ |
| 14779 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
Michael Chan | 007a880d | 2007-05-31 14:49:51 -0700 | [diff] [blame] | 14780 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14781 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 14782 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14783 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14784 | } |
| 14785 | |
| 14786 | /* For all SERDES we poll the MAC status register. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14787 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14788 | tg3_flag_set(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14789 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14790 | tg3_flag_clear(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14791 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 14792 | tp->rx_offset = NET_SKB_PAD + NET_IP_ALIGN; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 14793 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14794 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14795 | tg3_flag(tp, PCIX_MODE)) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 14796 | tp->rx_offset = NET_SKB_PAD; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 14797 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 14798 | tp->rx_copy_thresh = ~(u16)0; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 14799 | #endif |
| 14800 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14801 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 14802 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
| 14803 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 14804 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
| 14805 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 14806 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 14807 | |
| 14808 | /* Increment the rx prod index on the rx std ring by at most |
| 14809 | * 8 for these chips to workaround hw errata. |
| 14810 | */ |
| 14811 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 14812 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 14813 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 14814 | tp->rx_std_max_post = 8; |
| 14815 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14816 | if (tg3_flag(tp, ASPM_WORKAROUND)) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 14817 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
| 14818 | PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 14819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14820 | return err; |
| 14821 | } |
| 14822 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14823 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14824 | static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp) |
| 14825 | { |
| 14826 | struct net_device *dev = tp->dev; |
| 14827 | struct pci_dev *pdev = tp->pdev; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14828 | struct device_node *dp = pci_device_to_OF_node(pdev); |
David S. Miller | 374d4ca | 2007-03-29 01:57:57 -0700 | [diff] [blame] | 14829 | const unsigned char *addr; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14830 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14831 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14832 | addr = of_get_property(dp, "local-mac-address", &len); |
| 14833 | if (addr && len == 6) { |
| 14834 | memcpy(dev->dev_addr, addr, 6); |
| 14835 | memcpy(dev->perm_addr, dev->dev_addr, 6); |
| 14836 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14837 | } |
| 14838 | return -ENODEV; |
| 14839 | } |
| 14840 | |
| 14841 | static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp) |
| 14842 | { |
| 14843 | struct net_device *dev = tp->dev; |
| 14844 | |
| 14845 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 14846 | memcpy(dev->perm_addr, idprom->id_ethaddr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14847 | return 0; |
| 14848 | } |
| 14849 | #endif |
| 14850 | |
| 14851 | static int __devinit tg3_get_device_address(struct tg3 *tp) |
| 14852 | { |
| 14853 | struct net_device *dev = tp->dev; |
| 14854 | u32 hi, lo, mac_offset; |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 14855 | int addr_ok = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14856 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 14857 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14858 | if (!tg3_get_macaddr_sparc(tp)) |
| 14859 | return 0; |
| 14860 | #endif |
| 14861 | |
| 14862 | mac_offset = 0x7c; |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14863 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14864 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14865 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 14866 | mac_offset = 0xcc; |
| 14867 | if (tg3_nvram_lock(tp)) |
| 14868 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); |
| 14869 | else |
| 14870 | tg3_nvram_unlock(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14871 | } else if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 14872 | if (tp->pci_fn & 1) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14873 | mac_offset = 0xcc; |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 14874 | if (tp->pci_fn > 1) |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 14875 | mac_offset += 0x18c; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14876 | } 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] | 14877 | mac_offset = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14878 | |
| 14879 | /* First try to get it from MAC address mailbox. */ |
| 14880 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); |
| 14881 | if ((hi >> 16) == 0x484b) { |
| 14882 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 14883 | dev->dev_addr[1] = (hi >> 0) & 0xff; |
| 14884 | |
| 14885 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); |
| 14886 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 14887 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 14888 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 14889 | dev->dev_addr[5] = (lo >> 0) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14890 | |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 14891 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
| 14892 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); |
| 14893 | } |
| 14894 | if (!addr_ok) { |
| 14895 | /* Next, try NVRAM. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14896 | if (!tg3_flag(tp, NO_NVRAM) && |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 14897 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 14898 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 14899 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
| 14900 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 14901 | } |
| 14902 | /* Finally just fetch it out of the MAC control regs. */ |
| 14903 | else { |
| 14904 | hi = tr32(MAC_ADDR_0_HIGH); |
| 14905 | lo = tr32(MAC_ADDR_0_LOW); |
| 14906 | |
| 14907 | dev->dev_addr[5] = lo & 0xff; |
| 14908 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 14909 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 14910 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 14911 | dev->dev_addr[1] = hi & 0xff; |
| 14912 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 14913 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14914 | } |
| 14915 | |
| 14916 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { |
David S. Miller | 7582a33 | 2008-03-20 15:53:15 -0700 | [diff] [blame] | 14917 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14918 | if (!tg3_get_default_macaddr_sparc(tp)) |
| 14919 | return 0; |
| 14920 | #endif |
| 14921 | return -EINVAL; |
| 14922 | } |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 14923 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14924 | return 0; |
| 14925 | } |
| 14926 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14927 | #define BOUNDARY_SINGLE_CACHELINE 1 |
| 14928 | #define BOUNDARY_MULTI_CACHELINE 2 |
| 14929 | |
| 14930 | static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
| 14931 | { |
| 14932 | int cacheline_size; |
| 14933 | u8 byte; |
| 14934 | int goal; |
| 14935 | |
| 14936 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); |
| 14937 | if (byte == 0) |
| 14938 | cacheline_size = 1024; |
| 14939 | else |
| 14940 | cacheline_size = (int) byte * 4; |
| 14941 | |
| 14942 | /* On 5703 and later chips, the boundary bits have no |
| 14943 | * effect. |
| 14944 | */ |
| 14945 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14946 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14947 | !tg3_flag(tp, PCI_EXPRESS)) |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14948 | goto out; |
| 14949 | |
| 14950 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) |
| 14951 | goal = BOUNDARY_MULTI_CACHELINE; |
| 14952 | #else |
| 14953 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) |
| 14954 | goal = BOUNDARY_SINGLE_CACHELINE; |
| 14955 | #else |
| 14956 | goal = 0; |
| 14957 | #endif |
| 14958 | #endif |
| 14959 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14960 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14961 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 14962 | goto out; |
| 14963 | } |
| 14964 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14965 | if (!goal) |
| 14966 | goto out; |
| 14967 | |
| 14968 | /* PCI controllers on most RISC systems tend to disconnect |
| 14969 | * when a device tries to burst across a cache-line boundary. |
| 14970 | * Therefore, letting tg3 do so just wastes PCI bandwidth. |
| 14971 | * |
| 14972 | * Unfortunately, for PCI-E there are only limited |
| 14973 | * write-side controls for this, and thus for reads |
| 14974 | * we will still get the disconnects. We'll also waste |
| 14975 | * these PCI cycles for both read and write for chips |
| 14976 | * other than 5700 and 5701 which do not implement the |
| 14977 | * boundary bits. |
| 14978 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14979 | if (tg3_flag(tp, PCIX_MODE) && !tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14980 | switch (cacheline_size) { |
| 14981 | case 16: |
| 14982 | case 32: |
| 14983 | case 64: |
| 14984 | case 128: |
| 14985 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14986 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | |
| 14987 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); |
| 14988 | } else { |
| 14989 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 14990 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 14991 | } |
| 14992 | break; |
| 14993 | |
| 14994 | case 256: |
| 14995 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | |
| 14996 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); |
| 14997 | break; |
| 14998 | |
| 14999 | default: |
| 15000 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 15001 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 15002 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15003 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15004 | } else if (tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15005 | switch (cacheline_size) { |
| 15006 | case 16: |
| 15007 | case 32: |
| 15008 | case 64: |
| 15009 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15010 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 15011 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; |
| 15012 | break; |
| 15013 | } |
| 15014 | /* fallthrough */ |
| 15015 | case 128: |
| 15016 | default: |
| 15017 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 15018 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; |
| 15019 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15020 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15021 | } else { |
| 15022 | switch (cacheline_size) { |
| 15023 | case 16: |
| 15024 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15025 | val |= (DMA_RWCTRL_READ_BNDRY_16 | |
| 15026 | DMA_RWCTRL_WRITE_BNDRY_16); |
| 15027 | break; |
| 15028 | } |
| 15029 | /* fallthrough */ |
| 15030 | case 32: |
| 15031 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15032 | val |= (DMA_RWCTRL_READ_BNDRY_32 | |
| 15033 | DMA_RWCTRL_WRITE_BNDRY_32); |
| 15034 | break; |
| 15035 | } |
| 15036 | /* fallthrough */ |
| 15037 | case 64: |
| 15038 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15039 | val |= (DMA_RWCTRL_READ_BNDRY_64 | |
| 15040 | DMA_RWCTRL_WRITE_BNDRY_64); |
| 15041 | break; |
| 15042 | } |
| 15043 | /* fallthrough */ |
| 15044 | case 128: |
| 15045 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15046 | val |= (DMA_RWCTRL_READ_BNDRY_128 | |
| 15047 | DMA_RWCTRL_WRITE_BNDRY_128); |
| 15048 | break; |
| 15049 | } |
| 15050 | /* fallthrough */ |
| 15051 | case 256: |
| 15052 | val |= (DMA_RWCTRL_READ_BNDRY_256 | |
| 15053 | DMA_RWCTRL_WRITE_BNDRY_256); |
| 15054 | break; |
| 15055 | case 512: |
| 15056 | val |= (DMA_RWCTRL_READ_BNDRY_512 | |
| 15057 | DMA_RWCTRL_WRITE_BNDRY_512); |
| 15058 | break; |
| 15059 | case 1024: |
| 15060 | default: |
| 15061 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | |
| 15062 | DMA_RWCTRL_WRITE_BNDRY_1024); |
| 15063 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15064 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15065 | } |
| 15066 | |
| 15067 | out: |
| 15068 | return val; |
| 15069 | } |
| 15070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15071 | static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) |
| 15072 | { |
| 15073 | struct tg3_internal_buffer_desc test_desc; |
| 15074 | u32 sram_dma_descs; |
| 15075 | int i, ret; |
| 15076 | |
| 15077 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; |
| 15078 | |
| 15079 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); |
| 15080 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); |
| 15081 | tw32(RDMAC_STATUS, 0); |
| 15082 | tw32(WDMAC_STATUS, 0); |
| 15083 | |
| 15084 | tw32(BUFMGR_MODE, 0); |
| 15085 | tw32(FTQ_RESET, 0); |
| 15086 | |
| 15087 | test_desc.addr_hi = ((u64) buf_dma) >> 32; |
| 15088 | test_desc.addr_lo = buf_dma & 0xffffffff; |
| 15089 | test_desc.nic_mbuf = 0x00002100; |
| 15090 | test_desc.len = size; |
| 15091 | |
| 15092 | /* |
| 15093 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz |
| 15094 | * the *second* time the tg3 driver was getting loaded after an |
| 15095 | * initial scan. |
| 15096 | * |
| 15097 | * Broadcom tells me: |
| 15098 | * ...the DMA engine is connected to the GRC block and a DMA |
| 15099 | * reset may affect the GRC block in some unpredictable way... |
| 15100 | * The behavior of resets to individual blocks has not been tested. |
| 15101 | * |
| 15102 | * Broadcom noted the GRC reset will also reset all sub-components. |
| 15103 | */ |
| 15104 | if (to_device) { |
| 15105 | test_desc.cqid_sqid = (13 << 8) | 2; |
| 15106 | |
| 15107 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); |
| 15108 | udelay(40); |
| 15109 | } else { |
| 15110 | test_desc.cqid_sqid = (16 << 8) | 7; |
| 15111 | |
| 15112 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); |
| 15113 | udelay(40); |
| 15114 | } |
| 15115 | test_desc.flags = 0x00000005; |
| 15116 | |
| 15117 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { |
| 15118 | u32 val; |
| 15119 | |
| 15120 | val = *(((u32 *)&test_desc) + i); |
| 15121 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, |
| 15122 | sram_dma_descs + (i * sizeof(u32))); |
| 15123 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 15124 | } |
| 15125 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 15126 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15127 | if (to_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15128 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15129 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15130 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15131 | |
| 15132 | ret = -ENODEV; |
| 15133 | for (i = 0; i < 40; i++) { |
| 15134 | u32 val; |
| 15135 | |
| 15136 | if (to_device) |
| 15137 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); |
| 15138 | else |
| 15139 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); |
| 15140 | if ((val & 0xffff) == sram_dma_descs) { |
| 15141 | ret = 0; |
| 15142 | break; |
| 15143 | } |
| 15144 | |
| 15145 | udelay(100); |
| 15146 | } |
| 15147 | |
| 15148 | return ret; |
| 15149 | } |
| 15150 | |
David S. Miller | ded7340 | 2005-05-23 13:59:47 -0700 | [diff] [blame] | 15151 | #define TEST_BUFFER_SIZE 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15152 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 15153 | static DEFINE_PCI_DEVICE_TABLE(tg3_dma_wait_state_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 15154 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
| 15155 | { }, |
| 15156 | }; |
| 15157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15158 | static int __devinit tg3_test_dma(struct tg3 *tp) |
| 15159 | { |
| 15160 | dma_addr_t buf_dma; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15161 | u32 *buf, saved_dma_rwctrl; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 15162 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15163 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 15164 | buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
| 15165 | &buf_dma, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15166 | if (!buf) { |
| 15167 | ret = -ENOMEM; |
| 15168 | goto out_nofree; |
| 15169 | } |
| 15170 | |
| 15171 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | |
| 15172 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); |
| 15173 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15174 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15175 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15176 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 15177 | goto out; |
| 15178 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15179 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15180 | /* DMA read watermark not used on PCIE */ |
| 15181 | tp->dma_rwctrl |= 0x00180000; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15182 | } else if (!tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 15183 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 15184 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15185 | tp->dma_rwctrl |= 0x003f0000; |
| 15186 | else |
| 15187 | tp->dma_rwctrl |= 0x003f000f; |
| 15188 | } else { |
| 15189 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 15190 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 15191 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 15192 | u32 read_water = 0x7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15193 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15194 | /* If the 5704 is behind the EPB bridge, we can |
| 15195 | * do the less restrictive ONE_DMA workaround for |
| 15196 | * better performance. |
| 15197 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15198 | if (tg3_flag(tp, 40BIT_DMA_BUG) && |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15199 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 15200 | tp->dma_rwctrl |= 0x8000; |
| 15201 | else if (ccval == 0x6 || ccval == 0x7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15202 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 15203 | |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 15204 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
| 15205 | read_water = 4; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15206 | /* Set bit 23 to enable PCIX hw bug fix */ |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 15207 | tp->dma_rwctrl |= |
| 15208 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | |
| 15209 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | |
| 15210 | (1 << 23); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 15211 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
| 15212 | /* 5780 always in PCIX mode */ |
| 15213 | tp->dma_rwctrl |= 0x00144000; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 15214 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 15215 | /* 5714 always in PCIX mode */ |
| 15216 | tp->dma_rwctrl |= 0x00148000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15217 | } else { |
| 15218 | tp->dma_rwctrl |= 0x001b000f; |
| 15219 | } |
| 15220 | } |
| 15221 | |
| 15222 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 15223 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 15224 | tp->dma_rwctrl &= 0xfffffff0; |
| 15225 | |
| 15226 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 15227 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 15228 | /* Remove this if it causes problems for some boards. */ |
| 15229 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; |
| 15230 | |
| 15231 | /* On 5700/5701 chips, we need to set this bit. |
| 15232 | * Otherwise the chip will issue cacheline transactions |
| 15233 | * to streamable DMA memory with not all the byte |
| 15234 | * enables turned on. This is an error on several |
| 15235 | * RISC PCI controllers, in particular sparc64. |
| 15236 | * |
| 15237 | * On 5703/5704 chips, this bit has been reassigned |
| 15238 | * a different meaning. In particular, it is used |
| 15239 | * on those chips to enable a PCI-X workaround. |
| 15240 | */ |
| 15241 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; |
| 15242 | } |
| 15243 | |
| 15244 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15245 | |
| 15246 | #if 0 |
| 15247 | /* Unneeded, already done by tg3_get_invariants. */ |
| 15248 | tg3_switch_clocks(tp); |
| 15249 | #endif |
| 15250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15251 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 15252 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 15253 | goto out; |
| 15254 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15255 | /* It is best to perform DMA test with maximum write burst size |
| 15256 | * to expose the 5700/5701 write DMA bug. |
| 15257 | */ |
| 15258 | saved_dma_rwctrl = tp->dma_rwctrl; |
| 15259 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 15260 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15262 | while (1) { |
| 15263 | u32 *p = buf, i; |
| 15264 | |
| 15265 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) |
| 15266 | p[i] = i; |
| 15267 | |
| 15268 | /* Send the buffer to the chip. */ |
| 15269 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); |
| 15270 | if (ret) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15271 | dev_err(&tp->pdev->dev, |
| 15272 | "%s: Buffer write failed. err = %d\n", |
| 15273 | __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15274 | break; |
| 15275 | } |
| 15276 | |
| 15277 | #if 0 |
| 15278 | /* validate data reached card RAM correctly. */ |
| 15279 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 15280 | u32 val; |
| 15281 | tg3_read_mem(tp, 0x2100 + (i*4), &val); |
| 15282 | if (le32_to_cpu(val) != p[i]) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15283 | dev_err(&tp->pdev->dev, |
| 15284 | "%s: Buffer corrupted on device! " |
| 15285 | "(%d != %d)\n", __func__, val, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15286 | /* ret = -ENODEV here? */ |
| 15287 | } |
| 15288 | p[i] = 0; |
| 15289 | } |
| 15290 | #endif |
| 15291 | /* Now read it back. */ |
| 15292 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); |
| 15293 | if (ret) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 15294 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
| 15295 | "err = %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15296 | break; |
| 15297 | } |
| 15298 | |
| 15299 | /* Verify it. */ |
| 15300 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 15301 | if (p[i] == i) |
| 15302 | continue; |
| 15303 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15304 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 15305 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 15306 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15307 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 15308 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15309 | break; |
| 15310 | } else { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15311 | dev_err(&tp->pdev->dev, |
| 15312 | "%s: Buffer corrupted on read back! " |
| 15313 | "(%d != %d)\n", __func__, p[i], i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15314 | ret = -ENODEV; |
| 15315 | goto out; |
| 15316 | } |
| 15317 | } |
| 15318 | |
| 15319 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { |
| 15320 | /* Success. */ |
| 15321 | ret = 0; |
| 15322 | break; |
| 15323 | } |
| 15324 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15325 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 15326 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 15327 | /* DMA test passed without adjusting DMA boundary, |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15328 | * now look for chipsets that are known to expose the |
| 15329 | * DMA bug without failing the test. |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15330 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 15331 | if (pci_dev_present(tg3_dma_wait_state_chipsets)) { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15332 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 15333 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15334 | } else { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15335 | /* Safe to use the calculated DMA boundary. */ |
| 15336 | tp->dma_rwctrl = saved_dma_rwctrl; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15337 | } |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15338 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15339 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15341 | |
| 15342 | out: |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 15343 | dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15344 | out_nofree: |
| 15345 | return ret; |
| 15346 | } |
| 15347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15348 | static void __devinit tg3_init_bufmgr_config(struct tg3 *tp) |
| 15349 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15350 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 15351 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 15352 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 15353 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15354 | DEFAULT_MB_MACRX_LOW_WATER_57765; |
| 15355 | tp->bufmgr_config.mbuf_high_water = |
| 15356 | DEFAULT_MB_HIGH_WATER_57765; |
| 15357 | |
| 15358 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 15359 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 15360 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 15361 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; |
| 15362 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 15363 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15364 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 15365 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 15366 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 15367 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15368 | DEFAULT_MB_MACRX_LOW_WATER_5705; |
| 15369 | tp->bufmgr_config.mbuf_high_water = |
| 15370 | DEFAULT_MB_HIGH_WATER_5705; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 15371 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 15372 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15373 | DEFAULT_MB_MACRX_LOW_WATER_5906; |
| 15374 | tp->bufmgr_config.mbuf_high_water = |
| 15375 | DEFAULT_MB_HIGH_WATER_5906; |
| 15376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15377 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 15378 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 15379 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; |
| 15380 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 15381 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; |
| 15382 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 15383 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; |
| 15384 | } else { |
| 15385 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 15386 | DEFAULT_MB_RDMA_LOW_WATER; |
| 15387 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15388 | DEFAULT_MB_MACRX_LOW_WATER; |
| 15389 | tp->bufmgr_config.mbuf_high_water = |
| 15390 | DEFAULT_MB_HIGH_WATER; |
| 15391 | |
| 15392 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 15393 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; |
| 15394 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 15395 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; |
| 15396 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 15397 | DEFAULT_MB_HIGH_WATER_JUMBO; |
| 15398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15399 | |
| 15400 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; |
| 15401 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; |
| 15402 | } |
| 15403 | |
| 15404 | static char * __devinit tg3_phy_string(struct tg3 *tp) |
| 15405 | { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15406 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
| 15407 | case TG3_PHY_ID_BCM5400: return "5400"; |
| 15408 | case TG3_PHY_ID_BCM5401: return "5401"; |
| 15409 | case TG3_PHY_ID_BCM5411: return "5411"; |
| 15410 | case TG3_PHY_ID_BCM5701: return "5701"; |
| 15411 | case TG3_PHY_ID_BCM5703: return "5703"; |
| 15412 | case TG3_PHY_ID_BCM5704: return "5704"; |
| 15413 | case TG3_PHY_ID_BCM5705: return "5705"; |
| 15414 | case TG3_PHY_ID_BCM5750: return "5750"; |
| 15415 | case TG3_PHY_ID_BCM5752: return "5752"; |
| 15416 | case TG3_PHY_ID_BCM5714: return "5714"; |
| 15417 | case TG3_PHY_ID_BCM5780: return "5780"; |
| 15418 | case TG3_PHY_ID_BCM5755: return "5755"; |
| 15419 | case TG3_PHY_ID_BCM5787: return "5787"; |
| 15420 | case TG3_PHY_ID_BCM5784: return "5784"; |
| 15421 | case TG3_PHY_ID_BCM5756: return "5722/5756"; |
| 15422 | case TG3_PHY_ID_BCM5906: return "5906"; |
| 15423 | case TG3_PHY_ID_BCM5761: return "5761"; |
| 15424 | case TG3_PHY_ID_BCM5718C: return "5718C"; |
| 15425 | case TG3_PHY_ID_BCM5718S: return "5718S"; |
| 15426 | case TG3_PHY_ID_BCM57765: return "57765"; |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 15427 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
Matt Carlson | 6418f2c | 2011-04-05 14:22:49 +0000 | [diff] [blame] | 15428 | case TG3_PHY_ID_BCM5720C: return "5720C"; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15429 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15430 | case 0: return "serdes"; |
| 15431 | default: return "unknown"; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15433 | } |
| 15434 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15435 | static char * __devinit tg3_bus_string(struct tg3 *tp, char *str) |
| 15436 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15437 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15438 | strcpy(str, "PCI Express"); |
| 15439 | return str; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15440 | } else if (tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15441 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
| 15442 | |
| 15443 | strcpy(str, "PCIX:"); |
| 15444 | |
| 15445 | if ((clock_ctrl == 7) || |
| 15446 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == |
| 15447 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) |
| 15448 | strcat(str, "133MHz"); |
| 15449 | else if (clock_ctrl == 0) |
| 15450 | strcat(str, "33MHz"); |
| 15451 | else if (clock_ctrl == 2) |
| 15452 | strcat(str, "50MHz"); |
| 15453 | else if (clock_ctrl == 4) |
| 15454 | strcat(str, "66MHz"); |
| 15455 | else if (clock_ctrl == 6) |
| 15456 | strcat(str, "100MHz"); |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15457 | } else { |
| 15458 | strcpy(str, "PCI:"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15459 | if (tg3_flag(tp, PCI_HIGH_SPEED)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15460 | strcat(str, "66MHz"); |
| 15461 | else |
| 15462 | strcat(str, "33MHz"); |
| 15463 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15464 | if (tg3_flag(tp, PCI_32BIT)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15465 | strcat(str, ":32-bit"); |
| 15466 | else |
| 15467 | strcat(str, ":64-bit"); |
| 15468 | return str; |
| 15469 | } |
| 15470 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 15471 | static void __devinit tg3_init_coal(struct tg3 *tp) |
| 15472 | { |
| 15473 | struct ethtool_coalesce *ec = &tp->coal; |
| 15474 | |
| 15475 | memset(ec, 0, sizeof(*ec)); |
| 15476 | ec->cmd = ETHTOOL_GCOALESCE; |
| 15477 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; |
| 15478 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; |
| 15479 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; |
| 15480 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; |
| 15481 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; |
| 15482 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; |
| 15483 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; |
| 15484 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; |
| 15485 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; |
| 15486 | |
| 15487 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | |
| 15488 | HOSTCC_MODE_CLRTICK_TXBD)) { |
| 15489 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; |
| 15490 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; |
| 15491 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; |
| 15492 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; |
| 15493 | } |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 15494 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15495 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 15496 | ec->rx_coalesce_usecs_irq = 0; |
| 15497 | ec->tx_coalesce_usecs_irq = 0; |
| 15498 | ec->stats_block_coalesce_usecs = 0; |
| 15499 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 15500 | } |
| 15501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15502 | static int __devinit tg3_init_one(struct pci_dev *pdev, |
| 15503 | const struct pci_device_id *ent) |
| 15504 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15505 | struct net_device *dev; |
| 15506 | struct tg3 *tp; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 15507 | int i, err, pm_cap; |
| 15508 | u32 sndmbx, rcvmbx, intmbx; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15509 | char str[40]; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15510 | u64 dma_mask, persist_dma_mask; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 15511 | netdev_features_t features = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15512 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15513 | printk_once(KERN_INFO "%s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15514 | |
| 15515 | err = pci_enable_device(pdev); |
| 15516 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15517 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15518 | return err; |
| 15519 | } |
| 15520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15521 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 15522 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15523 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15524 | goto err_out_disable_pdev; |
| 15525 | } |
| 15526 | |
| 15527 | pci_set_master(pdev); |
| 15528 | |
| 15529 | /* Find power-management capability. */ |
| 15530 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 15531 | if (pm_cap == 0) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15532 | dev_err(&pdev->dev, |
| 15533 | "Cannot find Power Management capability, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15534 | err = -EIO; |
| 15535 | goto err_out_free_res; |
| 15536 | } |
| 15537 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15538 | err = pci_set_power_state(pdev, PCI_D0); |
| 15539 | if (err) { |
| 15540 | dev_err(&pdev->dev, "Transition to D0 failed, aborting\n"); |
| 15541 | goto err_out_free_res; |
| 15542 | } |
| 15543 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 15544 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15545 | if (!dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15546 | err = -ENOMEM; |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15547 | goto err_out_power_down; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15548 | } |
| 15549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15550 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 15551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15552 | tp = netdev_priv(dev); |
| 15553 | tp->pdev = pdev; |
| 15554 | tp->dev = dev; |
| 15555 | tp->pm_cap = pm_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15556 | tp->rx_mode = TG3_DEF_RX_MODE; |
| 15557 | tp->tx_mode = TG3_DEF_TX_MODE; |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 15558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15559 | if (tg3_debug > 0) |
| 15560 | tp->msg_enable = tg3_debug; |
| 15561 | else |
| 15562 | tp->msg_enable = TG3_DEF_MSG_ENABLE; |
| 15563 | |
| 15564 | /* The word/byte swap controls here control register access byte |
| 15565 | * swapping. DMA data byte swapping is controlled in the GRC_MODE |
| 15566 | * setting below. |
| 15567 | */ |
| 15568 | tp->misc_host_ctrl = |
| 15569 | MISC_HOST_CTRL_MASK_PCI_INT | |
| 15570 | MISC_HOST_CTRL_WORD_SWAP | |
| 15571 | MISC_HOST_CTRL_INDIR_ACCESS | |
| 15572 | MISC_HOST_CTRL_PCISTATE_RW; |
| 15573 | |
| 15574 | /* The NONFRM (non-frame) byte/word swap controls take effect |
| 15575 | * on descriptor entries, anything which isn't packet data. |
| 15576 | * |
| 15577 | * The StrongARM chips on the board (one for tx, one for rx) |
| 15578 | * are running in big-endian mode. |
| 15579 | */ |
| 15580 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | |
| 15581 | GRC_MODE_WSWAP_NONFRM_DATA); |
| 15582 | #ifdef __BIG_ENDIAN |
| 15583 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; |
| 15584 | #endif |
| 15585 | spin_lock_init(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15586 | spin_lock_init(&tp->indirect_lock); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 15587 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15588 | |
Matt Carlson | d5fe488 | 2008-11-21 17:20:32 -0800 | [diff] [blame] | 15589 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 15590 | if (!tp->regs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15591 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15592 | err = -ENOMEM; |
| 15593 | goto err_out_free_dev; |
| 15594 | } |
| 15595 | |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15596 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 15597 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761E || |
| 15598 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S || |
| 15599 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761SE || |
| 15600 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 15601 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 15602 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
| 15603 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720) { |
| 15604 | tg3_flag_set(tp, ENABLE_APE); |
| 15605 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
| 15606 | if (!tp->aperegs) { |
| 15607 | dev_err(&pdev->dev, |
| 15608 | "Cannot map APE registers, aborting\n"); |
| 15609 | err = -ENOMEM; |
| 15610 | goto err_out_iounmap; |
| 15611 | } |
| 15612 | } |
| 15613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15614 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
| 15615 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15617 | dev->ethtool_ops = &tg3_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15618 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 15619 | dev->netdev_ops = &tg3_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15620 | dev->irq = pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15621 | |
| 15622 | err = tg3_get_invariants(tp); |
| 15623 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15624 | dev_err(&pdev->dev, |
| 15625 | "Problem fetching invariants of chip, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15626 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15627 | } |
| 15628 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15629 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
| 15630 | * device behind the EPB cannot support DMA addresses > 40-bit. |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15631 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
| 15632 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and |
| 15633 | * do DMA address check in tg3_start_xmit(). |
| 15634 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15635 | if (tg3_flag(tp, IS_5788)) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 15636 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15637 | else if (tg3_flag(tp, 40BIT_DMA_BUG)) { |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 15638 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15639 | #ifdef CONFIG_HIGHMEM |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 15640 | dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15641 | #endif |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15642 | } else |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 15643 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15644 | |
| 15645 | /* Configure DMA attributes. */ |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 15646 | if (dma_mask > DMA_BIT_MASK(32)) { |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15647 | err = pci_set_dma_mask(pdev, dma_mask); |
| 15648 | if (!err) { |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15649 | features |= NETIF_F_HIGHDMA; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15650 | err = pci_set_consistent_dma_mask(pdev, |
| 15651 | persist_dma_mask); |
| 15652 | if (err < 0) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15653 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
| 15654 | "DMA for consistent allocations\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15655 | goto err_out_apeunmap; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15656 | } |
| 15657 | } |
| 15658 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 15659 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
| 15660 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15661 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15662 | dev_err(&pdev->dev, |
| 15663 | "No usable DMA configuration, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15664 | goto err_out_apeunmap; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15665 | } |
| 15666 | } |
| 15667 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 15668 | tg3_init_bufmgr_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15669 | |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15670 | features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 15671 | |
| 15672 | /* 5700 B0 chips do not support checksumming correctly due |
| 15673 | * to hardware bugs. |
| 15674 | */ |
| 15675 | if (tp->pci_chip_rev_id != CHIPREV_ID_5700_B0) { |
| 15676 | features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
| 15677 | |
| 15678 | if (tg3_flag(tp, 5755_PLUS)) |
| 15679 | features |= NETIF_F_IPV6_CSUM; |
| 15680 | } |
| 15681 | |
Michael Chan | 4e3a7aa | 2006-03-20 17:47:44 -0800 | [diff] [blame] | 15682 | /* TSO is on by default on chips that support hardware TSO. |
| 15683 | * Firmware TSO on older chips gives lower performance, so it |
| 15684 | * is off by default, but can be enabled using ethtool. |
| 15685 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15686 | if ((tg3_flag(tp, HW_TSO_1) || |
| 15687 | tg3_flag(tp, HW_TSO_2) || |
| 15688 | tg3_flag(tp, HW_TSO_3)) && |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15689 | (features & NETIF_F_IP_CSUM)) |
| 15690 | features |= NETIF_F_TSO; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15691 | if (tg3_flag(tp, HW_TSO_2) || tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15692 | if (features & NETIF_F_IPV6_CSUM) |
| 15693 | features |= NETIF_F_TSO6; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15694 | if (tg3_flag(tp, HW_TSO_3) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 15695 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 15696 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 15697 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15698 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 15699 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15700 | features |= NETIF_F_TSO_ECN; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 15701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15702 | |
Matt Carlson | d542fe2 | 2011-05-19 16:02:43 +0000 | [diff] [blame] | 15703 | dev->features |= features; |
| 15704 | dev->vlan_features |= features; |
| 15705 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 15706 | /* |
| 15707 | * Add loopback capability only for a subset of devices that support |
| 15708 | * MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY |
| 15709 | * loopback for the remaining devices. |
| 15710 | */ |
| 15711 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && |
| 15712 | !tg3_flag(tp, CPMU_PRESENT)) |
| 15713 | /* Add the loopback capability */ |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15714 | features |= NETIF_F_LOOPBACK; |
| 15715 | |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 15716 | dev->hw_features |= features; |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 15717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15718 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15719 | !tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15720 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15721 | tg3_flag_set(tp, MAX_RXPEND_64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15722 | tp->rx_pending = 63; |
| 15723 | } |
| 15724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15725 | err = tg3_get_device_address(tp); |
| 15726 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15727 | dev_err(&pdev->dev, |
| 15728 | "Could not obtain valid ethernet address, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15729 | goto err_out_apeunmap; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15730 | } |
| 15731 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 15732 | /* |
| 15733 | * Reset chip in case UNDI or EFI driver did not shutdown |
| 15734 | * DMA self test will enable WDMAC and we'll see (spurious) |
| 15735 | * pending DMA on the PCI bus at that point. |
| 15736 | */ |
| 15737 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
| 15738 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 15739 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
| 15740 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 15741 | } |
| 15742 | |
| 15743 | err = tg3_test_dma(tp); |
| 15744 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15745 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 15746 | goto err_out_apeunmap; |
| 15747 | } |
| 15748 | |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15749 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
| 15750 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; |
| 15751 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 15752 | for (i = 0; i < tp->irq_max; i++) { |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15753 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 15754 | |
| 15755 | tnapi->tp = tp; |
| 15756 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; |
| 15757 | |
| 15758 | tnapi->int_mbox = intmbx; |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 15759 | if (i <= 4) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15760 | intmbx += 0x8; |
| 15761 | else |
| 15762 | intmbx += 0x4; |
| 15763 | |
| 15764 | tnapi->consmbox = rcvmbx; |
| 15765 | tnapi->prodmbox = sndmbx; |
| 15766 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 15767 | if (i) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15768 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 15769 | else |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15770 | tnapi->coal_now = HOSTCC_MODE_NOW; |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15771 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15772 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 15773 | break; |
| 15774 | |
| 15775 | /* |
| 15776 | * If we support MSIX, we'll be using RSS. If we're using |
| 15777 | * RSS, the first vector only handles link interrupts and the |
| 15778 | * remaining vectors handle rx and tx interrupts. Reuse the |
| 15779 | * mailbox values for the next iteration. The values we setup |
| 15780 | * above are still useful for the single vectored mode. |
| 15781 | */ |
| 15782 | if (!i) |
| 15783 | continue; |
| 15784 | |
| 15785 | rcvmbx += 0x8; |
| 15786 | |
| 15787 | if (sndmbx & 0x4) |
| 15788 | sndmbx -= 0x4; |
| 15789 | else |
| 15790 | sndmbx += 0xc; |
| 15791 | } |
| 15792 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 15793 | tg3_init_coal(tp); |
| 15794 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 15795 | pci_set_drvdata(pdev, dev); |
| 15796 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 15797 | if (tg3_flag(tp, 5717_PLUS)) { |
| 15798 | /* Resume a low-power mode */ |
| 15799 | tg3_frob_aux_power(tp, false); |
| 15800 | } |
| 15801 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 15802 | tg3_timer_init(tp); |
| 15803 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15804 | err = register_netdev(dev); |
| 15805 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 15806 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15807 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15808 | } |
| 15809 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15810 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
| 15811 | tp->board_part_number, |
| 15812 | tp->pci_chip_rev_id, |
| 15813 | tg3_bus_string(tp, str), |
| 15814 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15815 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15816 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 15817 | struct phy_device *phydev; |
| 15818 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 15819 | netdev_info(dev, |
| 15820 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15821 | phydev->drv->name, dev_name(&phydev->dev)); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15822 | } else { |
| 15823 | char *ethtype; |
| 15824 | |
| 15825 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 15826 | ethtype = "10/100Base-TX"; |
| 15827 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 15828 | ethtype = "1000Base-SX"; |
| 15829 | else |
| 15830 | ethtype = "10/100/1000Base-T"; |
| 15831 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 15832 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 15833 | "(WireSpeed[%d], EEE[%d])\n", |
| 15834 | tg3_phy_string(tp), ethtype, |
| 15835 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0, |
| 15836 | (tp->phy_flags & TG3_PHYFLG_EEE_CAP) != 0); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15837 | } |
Matt Carlson | df59c94 | 2008-11-03 16:52:56 -0800 | [diff] [blame] | 15838 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15839 | 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] | 15840 | (dev->features & NETIF_F_RXCSUM) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15841 | tg3_flag(tp, USE_LINKCHG_REG) != 0, |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15842 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15843 | tg3_flag(tp, ENABLE_ASF) != 0, |
| 15844 | tg3_flag(tp, TSO_CAPABLE) != 0); |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15845 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
| 15846 | tp->dma_rwctrl, |
| 15847 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : |
| 15848 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15849 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 15850 | pci_save_state(pdev); |
| 15851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15852 | return 0; |
| 15853 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15854 | err_out_apeunmap: |
| 15855 | if (tp->aperegs) { |
| 15856 | iounmap(tp->aperegs); |
| 15857 | tp->aperegs = NULL; |
| 15858 | } |
| 15859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15860 | err_out_iounmap: |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15861 | if (tp->regs) { |
| 15862 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 15863 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15865 | |
| 15866 | err_out_free_dev: |
| 15867 | free_netdev(dev); |
| 15868 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15869 | err_out_power_down: |
| 15870 | pci_set_power_state(pdev, PCI_D3hot); |
| 15871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15872 | err_out_free_res: |
| 15873 | pci_release_regions(pdev); |
| 15874 | |
| 15875 | err_out_disable_pdev: |
| 15876 | pci_disable_device(pdev); |
| 15877 | pci_set_drvdata(pdev, NULL); |
| 15878 | return err; |
| 15879 | } |
| 15880 | |
| 15881 | static void __devexit tg3_remove_one(struct pci_dev *pdev) |
| 15882 | { |
| 15883 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15884 | |
| 15885 | if (dev) { |
| 15886 | struct tg3 *tp = netdev_priv(dev); |
| 15887 | |
Jesper Juhl | e3c5530 | 2012-04-09 22:50:15 +0200 | [diff] [blame] | 15888 | release_firmware(tp->fw); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 15889 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 15890 | tg3_reset_task_cancel(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15891 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 15892 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15893 | tg3_phy_fini(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15894 | tg3_mdio_fini(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15895 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15897 | unregister_netdev(dev); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15898 | if (tp->aperegs) { |
| 15899 | iounmap(tp->aperegs); |
| 15900 | tp->aperegs = NULL; |
| 15901 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15902 | if (tp->regs) { |
| 15903 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 15904 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15906 | free_netdev(dev); |
| 15907 | pci_release_regions(pdev); |
| 15908 | pci_disable_device(pdev); |
| 15909 | pci_set_drvdata(pdev, NULL); |
| 15910 | } |
| 15911 | } |
| 15912 | |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 15913 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15914 | static int tg3_suspend(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15915 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15916 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15917 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15918 | struct tg3 *tp = netdev_priv(dev); |
| 15919 | int err; |
| 15920 | |
| 15921 | if (!netif_running(dev)) |
| 15922 | return 0; |
| 15923 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 15924 | tg3_reset_task_cancel(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15925 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15926 | tg3_netif_stop(tp); |
| 15927 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 15928 | tg3_timer_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15929 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15930 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15931 | tg3_disable_ints(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15932 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15933 | |
| 15934 | netif_device_detach(dev); |
| 15935 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15936 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 15937 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15938 | tg3_flag_clear(tp, INIT_COMPLETE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15939 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15940 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15941 | err = tg3_power_down_prepare(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15942 | if (err) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15943 | int err2; |
| 15944 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15945 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15946 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15947 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15948 | err2 = tg3_restart_hw(tp, 1); |
| 15949 | if (err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15950 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15951 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 15952 | tg3_timer_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15953 | |
| 15954 | netif_device_attach(dev); |
| 15955 | tg3_netif_start(tp); |
| 15956 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15957 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15958 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15959 | |
| 15960 | if (!err2) |
| 15961 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15962 | } |
| 15963 | |
| 15964 | return err; |
| 15965 | } |
| 15966 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15967 | static int tg3_resume(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15968 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15969 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15970 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15971 | struct tg3 *tp = netdev_priv(dev); |
| 15972 | int err; |
| 15973 | |
| 15974 | if (!netif_running(dev)) |
| 15975 | return 0; |
| 15976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15977 | netif_device_attach(dev); |
| 15978 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15979 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15980 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15981 | tg3_flag_set(tp, INIT_COMPLETE); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15982 | err = tg3_restart_hw(tp, 1); |
| 15983 | if (err) |
| 15984 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15985 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 15986 | tg3_timer_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15988 | tg3_netif_start(tp); |
| 15989 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15990 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15991 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15992 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15993 | if (!err) |
| 15994 | tg3_phy_start(tp); |
| 15995 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15996 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15997 | } |
| 15998 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 15999 | static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 16000 | #define TG3_PM_OPS (&tg3_pm_ops) |
| 16001 | |
| 16002 | #else |
| 16003 | |
| 16004 | #define TG3_PM_OPS NULL |
| 16005 | |
| 16006 | #endif /* CONFIG_PM_SLEEP */ |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16007 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16008 | /** |
| 16009 | * tg3_io_error_detected - called when PCI error is detected |
| 16010 | * @pdev: Pointer to PCI device |
| 16011 | * @state: The current pci connection state |
| 16012 | * |
| 16013 | * This function is called after a PCI bus error affecting |
| 16014 | * this device has been detected. |
| 16015 | */ |
| 16016 | static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, |
| 16017 | pci_channel_state_t state) |
| 16018 | { |
| 16019 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 16020 | struct tg3 *tp = netdev_priv(netdev); |
| 16021 | pci_ers_result_t err = PCI_ERS_RESULT_NEED_RESET; |
| 16022 | |
| 16023 | netdev_info(netdev, "PCI I/O error detected\n"); |
| 16024 | |
| 16025 | rtnl_lock(); |
| 16026 | |
| 16027 | if (!netif_running(netdev)) |
| 16028 | goto done; |
| 16029 | |
| 16030 | tg3_phy_stop(tp); |
| 16031 | |
| 16032 | tg3_netif_stop(tp); |
| 16033 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16034 | tg3_timer_stop(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16035 | |
| 16036 | /* Want to make sure that the reset task doesn't run */ |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 16037 | tg3_reset_task_cancel(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16038 | |
| 16039 | netif_device_detach(netdev); |
| 16040 | |
| 16041 | /* Clean up software state, even if MMIO is blocked */ |
| 16042 | tg3_full_lock(tp, 0); |
| 16043 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 16044 | tg3_full_unlock(tp); |
| 16045 | |
| 16046 | done: |
| 16047 | if (state == pci_channel_io_perm_failure) |
| 16048 | err = PCI_ERS_RESULT_DISCONNECT; |
| 16049 | else |
| 16050 | pci_disable_device(pdev); |
| 16051 | |
| 16052 | rtnl_unlock(); |
| 16053 | |
| 16054 | return err; |
| 16055 | } |
| 16056 | |
| 16057 | /** |
| 16058 | * tg3_io_slot_reset - called after the pci bus has been reset. |
| 16059 | * @pdev: Pointer to PCI device |
| 16060 | * |
| 16061 | * Restart the card from scratch, as if from a cold-boot. |
| 16062 | * At this point, the card has exprienced a hard reset, |
| 16063 | * followed by fixups by BIOS, and has its config space |
| 16064 | * set up identically to what it was at cold boot. |
| 16065 | */ |
| 16066 | static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev) |
| 16067 | { |
| 16068 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 16069 | struct tg3 *tp = netdev_priv(netdev); |
| 16070 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 16071 | int err; |
| 16072 | |
| 16073 | rtnl_lock(); |
| 16074 | |
| 16075 | if (pci_enable_device(pdev)) { |
| 16076 | netdev_err(netdev, "Cannot re-enable PCI device after reset.\n"); |
| 16077 | goto done; |
| 16078 | } |
| 16079 | |
| 16080 | pci_set_master(pdev); |
| 16081 | pci_restore_state(pdev); |
| 16082 | pci_save_state(pdev); |
| 16083 | |
| 16084 | if (!netif_running(netdev)) { |
| 16085 | rc = PCI_ERS_RESULT_RECOVERED; |
| 16086 | goto done; |
| 16087 | } |
| 16088 | |
| 16089 | err = tg3_power_up(tp); |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 16090 | if (err) |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16091 | goto done; |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16092 | |
| 16093 | rc = PCI_ERS_RESULT_RECOVERED; |
| 16094 | |
| 16095 | done: |
| 16096 | rtnl_unlock(); |
| 16097 | |
| 16098 | return rc; |
| 16099 | } |
| 16100 | |
| 16101 | /** |
| 16102 | * tg3_io_resume - called when traffic can start flowing again. |
| 16103 | * @pdev: Pointer to PCI device |
| 16104 | * |
| 16105 | * This callback is called when the error recovery driver tells |
| 16106 | * us that its OK to resume normal operation. |
| 16107 | */ |
| 16108 | static void tg3_io_resume(struct pci_dev *pdev) |
| 16109 | { |
| 16110 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 16111 | struct tg3 *tp = netdev_priv(netdev); |
| 16112 | int err; |
| 16113 | |
| 16114 | rtnl_lock(); |
| 16115 | |
| 16116 | if (!netif_running(netdev)) |
| 16117 | goto done; |
| 16118 | |
| 16119 | tg3_full_lock(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16120 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16121 | err = tg3_restart_hw(tp, 1); |
| 16122 | tg3_full_unlock(tp); |
| 16123 | if (err) { |
| 16124 | netdev_err(netdev, "Cannot restart hardware after reset.\n"); |
| 16125 | goto done; |
| 16126 | } |
| 16127 | |
| 16128 | netif_device_attach(netdev); |
| 16129 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16130 | tg3_timer_start(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16131 | |
| 16132 | tg3_netif_start(tp); |
| 16133 | |
| 16134 | tg3_phy_start(tp); |
| 16135 | |
| 16136 | done: |
| 16137 | rtnl_unlock(); |
| 16138 | } |
| 16139 | |
| 16140 | static struct pci_error_handlers tg3_err_handler = { |
| 16141 | .error_detected = tg3_io_error_detected, |
| 16142 | .slot_reset = tg3_io_slot_reset, |
| 16143 | .resume = tg3_io_resume |
| 16144 | }; |
| 16145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16146 | static struct pci_driver tg3_driver = { |
| 16147 | .name = DRV_MODULE_NAME, |
| 16148 | .id_table = tg3_pci_tbl, |
| 16149 | .probe = tg3_init_one, |
| 16150 | .remove = __devexit_p(tg3_remove_one), |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16151 | .err_handler = &tg3_err_handler, |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 16152 | .driver.pm = TG3_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16153 | }; |
| 16154 | |
| 16155 | static int __init tg3_init(void) |
| 16156 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 16157 | return pci_register_driver(&tg3_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16158 | } |
| 16159 | |
| 16160 | static void __exit tg3_cleanup(void) |
| 16161 | { |
| 16162 | pci_unregister_driver(&tg3_driver); |
| 16163 | } |
| 16164 | |
| 16165 | module_init(tg3_init); |
| 16166 | module_exit(tg3_cleanup); |