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> |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 47 | #include <linux/hwmon.h> |
| 48 | #include <linux/hwmon-sysfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #include <net/checksum.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 51 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Javier Martinez Canillas | 27fd9de | 2011-03-26 16:42:31 +0000 | [diff] [blame] | 53 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <asm/byteorder.h> |
Javier Martinez Canillas | 27fd9de | 2011-03-26 16:42:31 +0000 | [diff] [blame] | 55 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 57 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include <asm/idprom.h> |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 59 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #endif |
| 61 | |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 62 | #define BAR_0 0 |
| 63 | #define BAR_2 2 |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #include "tg3.h" |
| 66 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 67 | /* Functions & macros to verify TG3_FLAGS types */ |
| 68 | |
| 69 | static inline int _tg3_flag(enum TG3_FLAGS flag, unsigned long *bits) |
| 70 | { |
| 71 | return test_bit(flag, bits); |
| 72 | } |
| 73 | |
| 74 | static inline void _tg3_flag_set(enum TG3_FLAGS flag, unsigned long *bits) |
| 75 | { |
| 76 | set_bit(flag, bits); |
| 77 | } |
| 78 | |
| 79 | static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits) |
| 80 | { |
| 81 | clear_bit(flag, bits); |
| 82 | } |
| 83 | |
| 84 | #define tg3_flag(tp, flag) \ |
| 85 | _tg3_flag(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 86 | #define tg3_flag_set(tp, flag) \ |
| 87 | _tg3_flag_set(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 88 | #define tg3_flag_clear(tp, flag) \ |
| 89 | _tg3_flag_clear(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | #define DRV_MODULE_NAME "tg3" |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 92 | #define TG3_MAJ_NUM 3 |
Michael Chan | 0b3ba05 | 2012-11-14 14:44:29 +0000 | [diff] [blame^] | 93 | #define TG3_MIN_NUM 127 |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 94 | #define DRV_MODULE_VERSION \ |
| 95 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) |
Michael Chan | 0b3ba05 | 2012-11-14 14:44:29 +0000 | [diff] [blame^] | 96 | #define DRV_MODULE_RELDATE "November 14, 2012" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 98 | #define RESET_KIND_SHUTDOWN 0 |
| 99 | #define RESET_KIND_INIT 1 |
| 100 | #define RESET_KIND_SUSPEND 2 |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | #define TG3_DEF_RX_MODE 0 |
| 103 | #define TG3_DEF_TX_MODE 0 |
| 104 | #define TG3_DEF_MSG_ENABLE \ |
| 105 | (NETIF_MSG_DRV | \ |
| 106 | NETIF_MSG_PROBE | \ |
| 107 | NETIF_MSG_LINK | \ |
| 108 | NETIF_MSG_TIMER | \ |
| 109 | NETIF_MSG_IFDOWN | \ |
| 110 | NETIF_MSG_IFUP | \ |
| 111 | NETIF_MSG_RX_ERR | \ |
| 112 | NETIF_MSG_TX_ERR) |
| 113 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 114 | #define TG3_GRC_LCLCTL_PWRSW_DELAY 100 |
| 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | /* length of time before we decide the hardware is borked, |
| 117 | * and dev->tx_timeout() should be called to fix the problem |
| 118 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | #define TG3_TX_TIMEOUT (5 * HZ) |
| 121 | |
| 122 | /* hardware minimum and maximum for a single frame's data payload */ |
| 123 | #define TG3_MIN_MTU 60 |
| 124 | #define TG3_MAX_MTU(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 125 | (tg3_flag(tp, JUMBO_CAPABLE) ? 9000 : 1500) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | /* These numbers seem to be hard coded in the NIC firmware somehow. |
| 128 | * You can't change the ring sizes, but you can change where you place |
| 129 | * them in the NIC onboard memory. |
| 130 | */ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 131 | #define TG3_RX_STD_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 132 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 133 | TG3_RX_STD_MAX_SIZE_5717 : TG3_RX_STD_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | #define TG3_DEF_RX_RING_PENDING 200 |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 135 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 136 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 137 | TG3_RX_JMB_MAX_SIZE_5717 : TG3_RX_JMB_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
| 139 | |
| 140 | /* Do not place this n-ring entries value into the tp struct itself, |
| 141 | * we really want to expose these constants to GCC so that modulo et |
| 142 | * al. operations are done with shifts and masks instead of with |
| 143 | * hw multiply/modulo instructions. Another solution would be to |
| 144 | * replace things like '% foo' with '& (foo - 1)'. |
| 145 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
| 147 | #define TG3_TX_RING_SIZE 512 |
| 148 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) |
| 149 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 150 | #define TG3_RX_STD_RING_BYTES(tp) \ |
| 151 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) |
| 152 | #define TG3_RX_JMB_RING_BYTES(tp) \ |
| 153 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) |
| 154 | #define TG3_RX_RCB_RING_BYTES(tp) \ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 155 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
| 157 | TG3_TX_RING_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
| 159 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 160 | #define TG3_DMA_BYTE_ENAB 64 |
| 161 | |
| 162 | #define TG3_RX_STD_DMA_SZ 1536 |
| 163 | #define TG3_RX_JMB_DMA_SZ 9046 |
| 164 | |
| 165 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) |
| 166 | |
| 167 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) |
| 168 | #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] | 169 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 170 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
| 171 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 172 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 173 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
| 174 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 175 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 176 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
| 177 | * that are at least dword aligned when used in PCIX mode. The driver |
| 178 | * works around this bug by double copying the packet. This workaround |
| 179 | * is built into the normal double copy length check for efficiency. |
| 180 | * |
| 181 | * However, the double copy is only necessary on those architectures |
| 182 | * where unaligned memory accesses are inefficient. For those architectures |
| 183 | * where unaligned memory accesses incur little penalty, we can reintegrate |
| 184 | * the 5701 in the normal rx path. Doing so saves a device structure |
| 185 | * dereference by hardcoding the double copy threshold in place. |
| 186 | */ |
| 187 | #define TG3_RX_COPY_THRESHOLD 256 |
| 188 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 189 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD |
| 190 | #else |
| 191 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) |
| 192 | #endif |
| 193 | |
Matt Carlson | 81389f5 | 2011-08-31 11:44:49 +0000 | [diff] [blame] | 194 | #if (NET_IP_ALIGN != 0) |
| 195 | #define TG3_RX_OFFSET(tp) ((tp)->rx_offset) |
| 196 | #else |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 197 | #define TG3_RX_OFFSET(tp) (NET_SKB_PAD) |
Matt Carlson | 81389f5 | 2011-08-31 11:44:49 +0000 | [diff] [blame] | 198 | #endif |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | /* minimum number of free TX descriptors required to wake up TX process */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 201 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 202 | #define TG3_TX_BD_DMA_MAX_2K 2048 |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 203 | #define TG3_TX_BD_DMA_MAX_4K 4096 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 205 | #define TG3_RAW_IP_ALIGN 2 |
| 206 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 207 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 208 | #define TG3_FW_UPDATE_FREQ_SEC (TG3_FW_UPDATE_TIMEOUT_SEC / 2) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 209 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 210 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
| 211 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
| 212 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | static char version[] __devinitdata = |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 215 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); |
| 218 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); |
| 219 | MODULE_LICENSE("GPL"); |
| 220 | MODULE_VERSION(DRV_MODULE_VERSION); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 221 | MODULE_FIRMWARE(FIRMWARE_TG3); |
| 222 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); |
| 223 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); |
| 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
| 226 | module_param(tg3_debug, int, 0); |
| 227 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); |
| 228 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 229 | #define TG3_DRV_DATA_FLAG_10_100_ONLY 0x0001 |
| 230 | #define TG3_DRV_DATA_FLAG_5705_10_100 0x0002 |
| 231 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 232 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 233 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
| 234 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, |
| 235 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, |
| 236 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, |
| 237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, |
| 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, |
| 239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, |
| 240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, |
| 241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, |
| 242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, |
| 243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, |
| 244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, |
| 245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, |
| 246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, |
| 247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, |
| 248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, |
| 249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, |
| 250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901), |
| 252 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 253 | TG3_DRV_DATA_FLAG_5705_10_100}, |
| 254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2), |
| 255 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 256 | TG3_DRV_DATA_FLAG_5705_10_100}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 257 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 258 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F), |
| 259 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 260 | TG3_DRV_DATA_FLAG_5705_10_100}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 261 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 262 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 264 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 265 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F), |
| 266 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
| 268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, |
| 269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, |
| 270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F), |
| 272 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
| 274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, |
| 275 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, |
| 276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 277 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 278 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
| 279 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 280 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5787M, |
| 281 | PCI_VENDOR_ID_LENOVO, |
| 282 | TG3PCI_SUBDEVICE_ID_LENOVO_5787M), |
| 283 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 284 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 285 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F), |
| 286 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 287 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
| 288 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, |
| 289 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, |
| 290 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, |
| 291 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, |
| 292 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, |
| 293 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 294 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
| 295 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 296 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
| 297 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
Matt Carlson | 6c7af27 | 2007-10-21 16:12:02 -0700 | [diff] [blame] | 298 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 299 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
| 300 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
Matt Carlson | c88e668 | 2008-11-03 16:49:18 -0800 | [diff] [blame] | 301 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
| 302 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, |
Matt Carlson | 2befdce | 2009-08-28 12:28:45 +0000 | [diff] [blame] | 303 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
| 304 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 305 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780, |
| 306 | PCI_VENDOR_ID_AI, TG3PCI_SUBDEVICE_ID_ACER_57780_A), |
| 307 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 308 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780, |
| 309 | PCI_VENDOR_ID_AI, TG3PCI_SUBDEVICE_ID_ACER_57780_B), |
| 310 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 311 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
| 312 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 313 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790), |
| 314 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Matt Carlson | 5e7ccf2 | 2009-08-25 10:08:42 +0000 | [diff] [blame] | 315 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 316 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 317 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717_C)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 318 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
Matt Carlson | b0f7522 | 2010-01-20 16:58:11 +0000 | [diff] [blame] | 319 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
| 320 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, |
| 321 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, |
| 322 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 323 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791), |
| 324 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 325 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795), |
| 326 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 327 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
Matt Carlson | ba1f3c7 | 2011-04-05 14:22:50 +0000 | [diff] [blame] | 328 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, |
Greg KH | 02eca3f | 2012-07-12 15:39:44 +0000 | [diff] [blame] | 329 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57762)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 330 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
| 331 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, |
| 332 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, |
| 333 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, |
| 334 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, |
| 335 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, |
| 336 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, |
Meelis Roos | 1dcb14d | 2011-05-25 05:43:47 +0000 | [diff] [blame] | 337 | {PCI_DEVICE(0x10cf, 0x11a2)}, /* Fujitsu 1000base-SX with BCM5703SKHB */ |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 338 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); |
| 342 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 343 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 345 | } ethtool_stats_keys[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { "rx_octets" }, |
| 347 | { "rx_fragments" }, |
| 348 | { "rx_ucast_packets" }, |
| 349 | { "rx_mcast_packets" }, |
| 350 | { "rx_bcast_packets" }, |
| 351 | { "rx_fcs_errors" }, |
| 352 | { "rx_align_errors" }, |
| 353 | { "rx_xon_pause_rcvd" }, |
| 354 | { "rx_xoff_pause_rcvd" }, |
| 355 | { "rx_mac_ctrl_rcvd" }, |
| 356 | { "rx_xoff_entered" }, |
| 357 | { "rx_frame_too_long_errors" }, |
| 358 | { "rx_jabbers" }, |
| 359 | { "rx_undersize_packets" }, |
| 360 | { "rx_in_length_errors" }, |
| 361 | { "rx_out_length_errors" }, |
| 362 | { "rx_64_or_less_octet_packets" }, |
| 363 | { "rx_65_to_127_octet_packets" }, |
| 364 | { "rx_128_to_255_octet_packets" }, |
| 365 | { "rx_256_to_511_octet_packets" }, |
| 366 | { "rx_512_to_1023_octet_packets" }, |
| 367 | { "rx_1024_to_1522_octet_packets" }, |
| 368 | { "rx_1523_to_2047_octet_packets" }, |
| 369 | { "rx_2048_to_4095_octet_packets" }, |
| 370 | { "rx_4096_to_8191_octet_packets" }, |
| 371 | { "rx_8192_to_9022_octet_packets" }, |
| 372 | |
| 373 | { "tx_octets" }, |
| 374 | { "tx_collisions" }, |
| 375 | |
| 376 | { "tx_xon_sent" }, |
| 377 | { "tx_xoff_sent" }, |
| 378 | { "tx_flow_control" }, |
| 379 | { "tx_mac_errors" }, |
| 380 | { "tx_single_collisions" }, |
| 381 | { "tx_mult_collisions" }, |
| 382 | { "tx_deferred" }, |
| 383 | { "tx_excessive_collisions" }, |
| 384 | { "tx_late_collisions" }, |
| 385 | { "tx_collide_2times" }, |
| 386 | { "tx_collide_3times" }, |
| 387 | { "tx_collide_4times" }, |
| 388 | { "tx_collide_5times" }, |
| 389 | { "tx_collide_6times" }, |
| 390 | { "tx_collide_7times" }, |
| 391 | { "tx_collide_8times" }, |
| 392 | { "tx_collide_9times" }, |
| 393 | { "tx_collide_10times" }, |
| 394 | { "tx_collide_11times" }, |
| 395 | { "tx_collide_12times" }, |
| 396 | { "tx_collide_13times" }, |
| 397 | { "tx_collide_14times" }, |
| 398 | { "tx_collide_15times" }, |
| 399 | { "tx_ucast_packets" }, |
| 400 | { "tx_mcast_packets" }, |
| 401 | { "tx_bcast_packets" }, |
| 402 | { "tx_carrier_sense_errors" }, |
| 403 | { "tx_discards" }, |
| 404 | { "tx_errors" }, |
| 405 | |
| 406 | { "dma_writeq_full" }, |
| 407 | { "dma_write_prioq_full" }, |
| 408 | { "rxbds_empty" }, |
| 409 | { "rx_discards" }, |
| 410 | { "rx_errors" }, |
| 411 | { "rx_threshold_hit" }, |
| 412 | |
| 413 | { "dma_readq_full" }, |
| 414 | { "dma_read_prioq_full" }, |
| 415 | { "tx_comp_queue_full" }, |
| 416 | |
| 417 | { "ring_set_send_prod_index" }, |
| 418 | { "ring_status_update" }, |
| 419 | { "nic_irqs" }, |
| 420 | { "nic_avoided_irqs" }, |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 421 | { "nic_tx_threshold_hit" }, |
| 422 | |
| 423 | { "mbuf_lwm_thresh_hit" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | }; |
| 425 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 426 | #define TG3_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 427 | #define TG3_NVRAM_TEST 0 |
| 428 | #define TG3_LINK_TEST 1 |
| 429 | #define TG3_REGISTER_TEST 2 |
| 430 | #define TG3_MEMORY_TEST 3 |
| 431 | #define TG3_MAC_LOOPB_TEST 4 |
| 432 | #define TG3_PHY_LOOPB_TEST 5 |
| 433 | #define TG3_EXT_LOOPB_TEST 6 |
| 434 | #define TG3_INTERRUPT_TEST 7 |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 435 | |
| 436 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 437 | static const struct { |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 438 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 439 | } ethtool_test_keys[] = { |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 440 | [TG3_NVRAM_TEST] = { "nvram test (online) " }, |
| 441 | [TG3_LINK_TEST] = { "link test (online) " }, |
| 442 | [TG3_REGISTER_TEST] = { "register test (offline)" }, |
| 443 | [TG3_MEMORY_TEST] = { "memory test (offline)" }, |
| 444 | [TG3_MAC_LOOPB_TEST] = { "mac loopback test (offline)" }, |
| 445 | [TG3_PHY_LOOPB_TEST] = { "phy loopback test (offline)" }, |
| 446 | [TG3_EXT_LOOPB_TEST] = { "ext loopback test (offline)" }, |
| 447 | [TG3_INTERRUPT_TEST] = { "interrupt test (offline)" }, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 448 | }; |
| 449 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 450 | #define TG3_NUM_TEST ARRAY_SIZE(ethtool_test_keys) |
| 451 | |
| 452 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 453 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
| 454 | { |
| 455 | writel(val, tp->regs + off); |
| 456 | } |
| 457 | |
| 458 | static u32 tg3_read32(struct tg3 *tp, u32 off) |
| 459 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 460 | return readl(tp->regs + off); |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 463 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
| 464 | { |
| 465 | writel(val, tp->aperegs + off); |
| 466 | } |
| 467 | |
| 468 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) |
| 469 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 470 | return readl(tp->aperegs + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
| 474 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 475 | unsigned long flags; |
| 476 | |
| 477 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 478 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 479 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 480 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) |
| 484 | { |
| 485 | writel(val, tp->regs + off); |
| 486 | readl(tp->regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 489 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
| 490 | { |
| 491 | unsigned long flags; |
| 492 | u32 val; |
| 493 | |
| 494 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 495 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 496 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 497 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 498 | return val; |
| 499 | } |
| 500 | |
| 501 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) |
| 502 | { |
| 503 | unsigned long flags; |
| 504 | |
| 505 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { |
| 506 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + |
| 507 | TG3_64BIT_REG_LOW, val); |
| 508 | return; |
| 509 | } |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 510 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 511 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
| 512 | TG3_64BIT_REG_LOW, val); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 517 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 518 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 519 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 520 | |
| 521 | /* In indirect mode when disabling interrupts, we also need |
| 522 | * to clear the interrupt bit in the GRC local ctrl register. |
| 523 | */ |
| 524 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && |
| 525 | (val == 0x1)) { |
| 526 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, |
| 527 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) |
| 532 | { |
| 533 | unsigned long flags; |
| 534 | u32 val; |
| 535 | |
| 536 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 537 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 538 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 539 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 540 | return val; |
| 541 | } |
| 542 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 543 | /* usec_wait specifies the wait time in usec when writing to certain registers |
| 544 | * where it is unsafe to read back the register without some delay. |
| 545 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. |
| 546 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. |
| 547 | */ |
| 548 | 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] | 549 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 550 | if (tg3_flag(tp, PCIX_TARGET_HWBUG) || tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 551 | /* Non-posted methods */ |
| 552 | tp->write32(tp, off, val); |
| 553 | else { |
| 554 | /* Posted method */ |
| 555 | tg3_write32(tp, off, val); |
| 556 | if (usec_wait) |
| 557 | udelay(usec_wait); |
| 558 | tp->read32(tp, off); |
| 559 | } |
| 560 | /* Wait again after the read for the posted method to guarantee that |
| 561 | * the wait time is met. |
| 562 | */ |
| 563 | if (usec_wait) |
| 564 | udelay(usec_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 567 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
| 568 | { |
| 569 | tp->write32_mbox(tp, off, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 570 | if (!tg3_flag(tp, MBOX_WRITE_REORDER) && !tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 571 | tp->read32_mbox(tp, off); |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 574 | 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] | 575 | { |
| 576 | void __iomem *mbox = tp->regs + off; |
| 577 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 578 | if (tg3_flag(tp, TXD_MBOX_HWBUG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 580 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | readl(mbox); |
| 582 | } |
| 583 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 584 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
| 585 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 586 | return readl(tp->regs + off + GRCMBOX_BASE); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) |
| 590 | { |
| 591 | writel(val, tp->regs + off + GRCMBOX_BASE); |
| 592 | } |
| 593 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 594 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 595 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 596 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
| 597 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) |
| 598 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 599 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 600 | #define tw32(reg, val) tp->write32(tp, reg, val) |
| 601 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) |
| 602 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) |
| 603 | #define tr32(reg) tp->read32(tp, reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
| 605 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) |
| 606 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 607 | unsigned long flags; |
| 608 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 609 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 610 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
| 611 | return; |
| 612 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 613 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 614 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 615 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 616 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 618 | /* Always leave this as zero. */ |
| 619 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 620 | } else { |
| 621 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 622 | tw32_f(TG3PCI_MEM_WIN_DATA, val); |
| 623 | |
| 624 | /* Always leave this as zero. */ |
| 625 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 626 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 627 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
| 631 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 632 | unsigned long flags; |
| 633 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 634 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 635 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
| 636 | *val = 0; |
| 637 | return; |
| 638 | } |
| 639 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 640 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 641 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 642 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 643 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 645 | /* Always leave this as zero. */ |
| 646 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 647 | } else { |
| 648 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 649 | *val = tr32(TG3PCI_MEM_WIN_DATA); |
| 650 | |
| 651 | /* Always leave this as zero. */ |
| 652 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 653 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 654 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 657 | static void tg3_ape_lock_init(struct tg3 *tp) |
| 658 | { |
| 659 | int i; |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 660 | u32 regbase, bit; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 661 | |
| 662 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 663 | regbase = TG3_APE_LOCK_GRANT; |
| 664 | else |
| 665 | regbase = TG3_APE_PER_LOCK_GRANT; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 666 | |
| 667 | /* Make sure the driver hasn't any stale locks. */ |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 668 | for (i = TG3_APE_LOCK_PHY0; i <= TG3_APE_LOCK_GPIO; i++) { |
| 669 | switch (i) { |
| 670 | case TG3_APE_LOCK_PHY0: |
| 671 | case TG3_APE_LOCK_PHY1: |
| 672 | case TG3_APE_LOCK_PHY2: |
| 673 | case TG3_APE_LOCK_PHY3: |
| 674 | bit = APE_LOCK_GRANT_DRIVER; |
| 675 | break; |
| 676 | default: |
| 677 | if (!tp->pci_fn) |
| 678 | bit = APE_LOCK_GRANT_DRIVER; |
| 679 | else |
| 680 | bit = 1 << tp->pci_fn; |
| 681 | } |
| 682 | tg3_ape_write32(tp, regbase + 4 * i, bit); |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | static int tg3_ape_lock(struct tg3 *tp, int locknum) |
| 688 | { |
| 689 | int i, off; |
| 690 | int ret = 0; |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 691 | u32 status, req, gnt, bit; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 692 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 693 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 694 | return 0; |
| 695 | |
| 696 | switch (locknum) { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 697 | case TG3_APE_LOCK_GPIO: |
| 698 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 699 | return 0; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 700 | case TG3_APE_LOCK_GRC: |
| 701 | case TG3_APE_LOCK_MEM: |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 702 | if (!tp->pci_fn) |
| 703 | bit = APE_LOCK_REQ_DRIVER; |
| 704 | else |
| 705 | bit = 1 << tp->pci_fn; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 706 | break; |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 707 | case TG3_APE_LOCK_PHY0: |
| 708 | case TG3_APE_LOCK_PHY1: |
| 709 | case TG3_APE_LOCK_PHY2: |
| 710 | case TG3_APE_LOCK_PHY3: |
| 711 | bit = APE_LOCK_REQ_DRIVER; |
| 712 | break; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 713 | default: |
| 714 | return -EINVAL; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 717 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
| 718 | req = TG3_APE_LOCK_REQ; |
| 719 | gnt = TG3_APE_LOCK_GRANT; |
| 720 | } else { |
| 721 | req = TG3_APE_PER_LOCK_REQ; |
| 722 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 723 | } |
| 724 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 725 | off = 4 * locknum; |
| 726 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 727 | tg3_ape_write32(tp, req + off, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 728 | |
| 729 | /* Wait for up to 1 millisecond to acquire lock. */ |
| 730 | for (i = 0; i < 100; i++) { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 731 | status = tg3_ape_read32(tp, gnt + off); |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 732 | if (status == bit) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 733 | break; |
| 734 | udelay(10); |
| 735 | } |
| 736 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 737 | if (status != bit) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 738 | /* Revoke the lock request. */ |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 739 | tg3_ape_write32(tp, gnt + off, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 740 | ret = -EBUSY; |
| 741 | } |
| 742 | |
| 743 | return ret; |
| 744 | } |
| 745 | |
| 746 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) |
| 747 | { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 748 | u32 gnt, bit; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 749 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 750 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 751 | return; |
| 752 | |
| 753 | switch (locknum) { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 754 | case TG3_APE_LOCK_GPIO: |
| 755 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 756 | return; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 757 | case TG3_APE_LOCK_GRC: |
| 758 | case TG3_APE_LOCK_MEM: |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 759 | if (!tp->pci_fn) |
| 760 | bit = APE_LOCK_GRANT_DRIVER; |
| 761 | else |
| 762 | bit = 1 << tp->pci_fn; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 763 | break; |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 764 | case TG3_APE_LOCK_PHY0: |
| 765 | case TG3_APE_LOCK_PHY1: |
| 766 | case TG3_APE_LOCK_PHY2: |
| 767 | case TG3_APE_LOCK_PHY3: |
| 768 | bit = APE_LOCK_GRANT_DRIVER; |
| 769 | break; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 770 | default: |
| 771 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 774 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 775 | gnt = TG3_APE_LOCK_GRANT; |
| 776 | else |
| 777 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 778 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 779 | tg3_ape_write32(tp, gnt + 4 * locknum, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 782 | static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us) |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 783 | { |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 784 | u32 apedata; |
| 785 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 786 | while (timeout_us) { |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 787 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 788 | return -EBUSY; |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 789 | |
| 790 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 791 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 792 | break; |
| 793 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 794 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 795 | |
| 796 | udelay(10); |
| 797 | timeout_us -= (timeout_us > 10) ? 10 : timeout_us; |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 800 | return timeout_us ? 0 : -EBUSY; |
| 801 | } |
| 802 | |
Matt Carlson | cf8d55a | 2012-07-16 16:24:01 +0000 | [diff] [blame] | 803 | static int tg3_ape_wait_for_event(struct tg3 *tp, u32 timeout_us) |
| 804 | { |
| 805 | u32 i, apedata; |
| 806 | |
| 807 | for (i = 0; i < timeout_us / 10; i++) { |
| 808 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 809 | |
| 810 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 811 | break; |
| 812 | |
| 813 | udelay(10); |
| 814 | } |
| 815 | |
| 816 | return i == timeout_us / 10; |
| 817 | } |
| 818 | |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 819 | static int tg3_ape_scratchpad_read(struct tg3 *tp, u32 *data, u32 base_off, |
| 820 | u32 len) |
Matt Carlson | cf8d55a | 2012-07-16 16:24:01 +0000 | [diff] [blame] | 821 | { |
| 822 | int err; |
| 823 | u32 i, bufoff, msgoff, maxlen, apedata; |
| 824 | |
| 825 | if (!tg3_flag(tp, APE_HAS_NCSI)) |
| 826 | return 0; |
| 827 | |
| 828 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 829 | if (apedata != APE_SEG_SIG_MAGIC) |
| 830 | return -ENODEV; |
| 831 | |
| 832 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 833 | if (!(apedata & APE_FW_STATUS_READY)) |
| 834 | return -EAGAIN; |
| 835 | |
| 836 | bufoff = tg3_ape_read32(tp, TG3_APE_SEG_MSG_BUF_OFF) + |
| 837 | TG3_APE_SHMEM_BASE; |
| 838 | msgoff = bufoff + 2 * sizeof(u32); |
| 839 | maxlen = tg3_ape_read32(tp, TG3_APE_SEG_MSG_BUF_LEN); |
| 840 | |
| 841 | while (len) { |
| 842 | u32 length; |
| 843 | |
| 844 | /* Cap xfer sizes to scratchpad limits. */ |
| 845 | length = (len > maxlen) ? maxlen : len; |
| 846 | len -= length; |
| 847 | |
| 848 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 849 | if (!(apedata & APE_FW_STATUS_READY)) |
| 850 | return -EAGAIN; |
| 851 | |
| 852 | /* Wait for up to 1 msec for APE to service previous event. */ |
| 853 | err = tg3_ape_event_lock(tp, 1000); |
| 854 | if (err) |
| 855 | return err; |
| 856 | |
| 857 | apedata = APE_EVENT_STATUS_DRIVER_EVNT | |
| 858 | APE_EVENT_STATUS_SCRTCHPD_READ | |
| 859 | APE_EVENT_STATUS_EVENT_PENDING; |
| 860 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, apedata); |
| 861 | |
| 862 | tg3_ape_write32(tp, bufoff, base_off); |
| 863 | tg3_ape_write32(tp, bufoff + sizeof(u32), length); |
| 864 | |
| 865 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 866 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 867 | |
| 868 | base_off += length; |
| 869 | |
| 870 | if (tg3_ape_wait_for_event(tp, 30000)) |
| 871 | return -EAGAIN; |
| 872 | |
| 873 | for (i = 0; length; i += 4, length -= 4) { |
| 874 | u32 val = tg3_ape_read32(tp, msgoff + i); |
| 875 | memcpy(data, &val, sizeof(u32)); |
| 876 | data++; |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | return 0; |
| 881 | } |
| 882 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 883 | static int tg3_ape_send_event(struct tg3 *tp, u32 event) |
| 884 | { |
| 885 | int err; |
| 886 | u32 apedata; |
| 887 | |
| 888 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 889 | if (apedata != APE_SEG_SIG_MAGIC) |
| 890 | return -EAGAIN; |
| 891 | |
| 892 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 893 | if (!(apedata & APE_FW_STATUS_READY)) |
| 894 | return -EAGAIN; |
| 895 | |
| 896 | /* Wait for up to 1 millisecond for APE to service previous event. */ |
| 897 | err = tg3_ape_event_lock(tp, 1000); |
| 898 | if (err) |
| 899 | return err; |
| 900 | |
| 901 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
| 902 | event | APE_EVENT_STATUS_EVENT_PENDING); |
| 903 | |
| 904 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 905 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 906 | |
| 907 | return 0; |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
| 911 | { |
| 912 | u32 event; |
| 913 | u32 apedata; |
| 914 | |
| 915 | if (!tg3_flag(tp, ENABLE_APE)) |
| 916 | return; |
| 917 | |
| 918 | switch (kind) { |
| 919 | case RESET_KIND_INIT: |
| 920 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, |
| 921 | APE_HOST_SEG_SIG_MAGIC); |
| 922 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, |
| 923 | APE_HOST_SEG_LEN_MAGIC); |
| 924 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); |
| 925 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); |
| 926 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, |
| 927 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
| 928 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
| 929 | APE_HOST_BEHAV_NO_PHYLOCK); |
| 930 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, |
| 931 | TG3_APE_HOST_DRVR_STATE_START); |
| 932 | |
| 933 | event = APE_EVENT_STATUS_STATE_START; |
| 934 | break; |
| 935 | case RESET_KIND_SHUTDOWN: |
| 936 | /* With the interface we are currently using, |
| 937 | * APE does not track driver state. Wiping |
| 938 | * out the HOST SEGMENT SIGNATURE forces |
| 939 | * the APE to assume OS absent status. |
| 940 | */ |
| 941 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); |
| 942 | |
| 943 | if (device_may_wakeup(&tp->pdev->dev) && |
| 944 | tg3_flag(tp, WOL_ENABLE)) { |
| 945 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, |
| 946 | TG3_APE_HOST_WOL_SPEED_AUTO); |
| 947 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; |
| 948 | } else |
| 949 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; |
| 950 | |
| 951 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); |
| 952 | |
| 953 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
| 954 | break; |
| 955 | case RESET_KIND_SUSPEND: |
| 956 | event = APE_EVENT_STATUS_STATE_SUSPEND; |
| 957 | break; |
| 958 | default: |
| 959 | return; |
| 960 | } |
| 961 | |
| 962 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; |
| 963 | |
| 964 | tg3_ape_send_event(tp, event); |
| 965 | } |
| 966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | static void tg3_disable_ints(struct tg3 *tp) |
| 968 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 969 | int i; |
| 970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 972 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 973 | for (i = 0; i < tp->irq_max; i++) |
| 974 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | } |
| 976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | static void tg3_enable_ints(struct tg3 *tp) |
| 978 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 979 | int i; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 980 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 981 | tp->irq_sync = 0; |
| 982 | wmb(); |
| 983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 985 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 986 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 987 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 988 | for (i = 0; i < tp->irq_cnt; i++) { |
| 989 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 990 | |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 991 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 992 | if (tg3_flag(tp, 1SHOT_MSI)) |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 993 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 994 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 995 | tp->coal_now |= tnapi->coal_now; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 996 | } |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 997 | |
| 998 | /* Force an initial interrupt */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 999 | if (!tg3_flag(tp, TAGGED_STATUS) && |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 1000 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
| 1001 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 1002 | else |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 1003 | tw32(HOSTCC_MODE, tp->coal_now); |
| 1004 | |
| 1005 | 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] | 1006 | } |
| 1007 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1008 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1009 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1010 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 1011 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1012 | unsigned int work_exists = 0; |
| 1013 | |
| 1014 | /* check for phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1015 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1016 | if (sblk->status & SD_STATUS_LINK_CHG) |
| 1017 | work_exists = 1; |
| 1018 | } |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 1019 | |
| 1020 | /* check for TX work to do */ |
| 1021 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons) |
| 1022 | work_exists = 1; |
| 1023 | |
| 1024 | /* check for RX work to do */ |
| 1025 | if (tnapi->rx_rcb_prod_idx && |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 1026 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1027 | work_exists = 1; |
| 1028 | |
| 1029 | return work_exists; |
| 1030 | } |
| 1031 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1032 | /* tg3_int_reenable |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1033 | * similar to tg3_enable_ints, but it accurately determines whether there |
| 1034 | * is new work pending and can return without flushing the PIO write |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1035 | * which reenables interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1037 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1039 | struct tg3 *tp = tnapi->tp; |
| 1040 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 1041 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | mmiowb(); |
| 1043 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 1044 | /* When doing tagged status, this work check is unnecessary. |
| 1045 | * The last_tag we write above tells the chip which piece of |
| 1046 | * work we've completed. |
| 1047 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1048 | if (!tg3_flag(tp, TAGGED_STATUS) && tg3_has_work(tnapi)) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1049 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 1050 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | static void tg3_switch_clocks(struct tg3 *tp) |
| 1054 | { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 1055 | u32 clock_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | u32 orig_clock_ctrl; |
| 1057 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1058 | if (tg3_flag(tp, CPMU_PRESENT) || tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 1059 | return; |
| 1060 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 1061 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
| 1062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | orig_clock_ctrl = clock_ctrl; |
| 1064 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | |
| 1065 | CLOCK_CTRL_CLKRUN_OENABLE | |
| 1066 | 0x1f); |
| 1067 | tp->pci_clock_ctrl = clock_ctrl; |
| 1068 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1069 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 1071 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1072 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | } |
| 1074 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 1075 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1076 | clock_ctrl | |
| 1077 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), |
| 1078 | 40); |
| 1079 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1080 | clock_ctrl | (CLOCK_CTRL_ALTCLK), |
| 1081 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 1083 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | #define PHY_BUSY_LOOPS 5000 |
| 1087 | |
| 1088 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
| 1089 | { |
| 1090 | u32 frame_val; |
| 1091 | unsigned int loops; |
| 1092 | int ret; |
| 1093 | |
| 1094 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1095 | tw32_f(MAC_MI_MODE, |
| 1096 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 1097 | udelay(80); |
| 1098 | } |
| 1099 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1100 | tg3_ape_lock(tp, tp->phy_ape_lock); |
| 1101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | *val = 0x0; |
| 1103 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1104 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | MI_COM_PHY_ADDR_MASK); |
| 1106 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 1107 | MI_COM_REG_ADDR_MASK); |
| 1108 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | tw32_f(MAC_MI_COM, frame_val); |
| 1111 | |
| 1112 | loops = PHY_BUSY_LOOPS; |
| 1113 | while (loops != 0) { |
| 1114 | udelay(10); |
| 1115 | frame_val = tr32(MAC_MI_COM); |
| 1116 | |
| 1117 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 1118 | udelay(5); |
| 1119 | frame_val = tr32(MAC_MI_COM); |
| 1120 | break; |
| 1121 | } |
| 1122 | loops -= 1; |
| 1123 | } |
| 1124 | |
| 1125 | ret = -EBUSY; |
| 1126 | if (loops != 0) { |
| 1127 | *val = frame_val & MI_COM_DATA_MASK; |
| 1128 | ret = 0; |
| 1129 | } |
| 1130 | |
| 1131 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1132 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1133 | udelay(80); |
| 1134 | } |
| 1135 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1136 | tg3_ape_unlock(tp, tp->phy_ape_lock); |
| 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | return ret; |
| 1139 | } |
| 1140 | |
| 1141 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
| 1142 | { |
| 1143 | u32 frame_val; |
| 1144 | unsigned int loops; |
| 1145 | int ret; |
| 1146 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1147 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 1148 | (reg == MII_CTRL1000 || reg == MII_TG3_AUX_CTRL)) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 1149 | return 0; |
| 1150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1152 | tw32_f(MAC_MI_MODE, |
| 1153 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 1154 | udelay(80); |
| 1155 | } |
| 1156 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1157 | tg3_ape_lock(tp, tp->phy_ape_lock); |
| 1158 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1159 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | MI_COM_PHY_ADDR_MASK); |
| 1161 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 1162 | MI_COM_REG_ADDR_MASK); |
| 1163 | frame_val |= (val & MI_COM_DATA_MASK); |
| 1164 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | tw32_f(MAC_MI_COM, frame_val); |
| 1167 | |
| 1168 | loops = PHY_BUSY_LOOPS; |
| 1169 | while (loops != 0) { |
| 1170 | udelay(10); |
| 1171 | frame_val = tr32(MAC_MI_COM); |
| 1172 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 1173 | udelay(5); |
| 1174 | frame_val = tr32(MAC_MI_COM); |
| 1175 | break; |
| 1176 | } |
| 1177 | loops -= 1; |
| 1178 | } |
| 1179 | |
| 1180 | ret = -EBUSY; |
| 1181 | if (loops != 0) |
| 1182 | ret = 0; |
| 1183 | |
| 1184 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1185 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1186 | udelay(80); |
| 1187 | } |
| 1188 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1189 | tg3_ape_unlock(tp, tp->phy_ape_lock); |
| 1190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | return ret; |
| 1192 | } |
| 1193 | |
Matt Carlson | b0988c1 | 2011-04-20 07:57:39 +0000 | [diff] [blame] | 1194 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
| 1195 | { |
| 1196 | int err; |
| 1197 | |
| 1198 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1199 | if (err) |
| 1200 | goto done; |
| 1201 | |
| 1202 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1203 | if (err) |
| 1204 | goto done; |
| 1205 | |
| 1206 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1207 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1208 | if (err) |
| 1209 | goto done; |
| 1210 | |
| 1211 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1212 | |
| 1213 | done: |
| 1214 | return err; |
| 1215 | } |
| 1216 | |
| 1217 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) |
| 1218 | { |
| 1219 | int err; |
| 1220 | |
| 1221 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1222 | if (err) |
| 1223 | goto done; |
| 1224 | |
| 1225 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1226 | if (err) |
| 1227 | goto done; |
| 1228 | |
| 1229 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1230 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1231 | if (err) |
| 1232 | goto done; |
| 1233 | |
| 1234 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1235 | |
| 1236 | done: |
| 1237 | return err; |
| 1238 | } |
| 1239 | |
| 1240 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) |
| 1241 | { |
| 1242 | int err; |
| 1243 | |
| 1244 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1245 | if (!err) |
| 1246 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1247 | |
| 1248 | return err; |
| 1249 | } |
| 1250 | |
| 1251 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
| 1252 | { |
| 1253 | int err; |
| 1254 | |
| 1255 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1256 | if (!err) |
| 1257 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1258 | |
| 1259 | return err; |
| 1260 | } |
| 1261 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 1262 | static int tg3_phy_auxctl_read(struct tg3 *tp, int reg, u32 *val) |
| 1263 | { |
| 1264 | int err; |
| 1265 | |
| 1266 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 1267 | (reg << MII_TG3_AUXCTL_MISC_RDSEL_SHIFT) | |
| 1268 | MII_TG3_AUXCTL_SHDWSEL_MISC); |
| 1269 | if (!err) |
| 1270 | err = tg3_readphy(tp, MII_TG3_AUX_CTRL, val); |
| 1271 | |
| 1272 | return err; |
| 1273 | } |
| 1274 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 1275 | static int tg3_phy_auxctl_write(struct tg3 *tp, int reg, u32 set) |
| 1276 | { |
| 1277 | if (reg == MII_TG3_AUXCTL_SHDWSEL_MISC) |
| 1278 | set |= MII_TG3_AUXCTL_MISC_WREN; |
| 1279 | |
| 1280 | return tg3_writephy(tp, MII_TG3_AUX_CTRL, set | reg); |
| 1281 | } |
| 1282 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 1283 | #define TG3_PHY_AUXCTL_SMDSP_ENABLE(tp) \ |
| 1284 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ |
| 1285 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | \ |
| 1286 | MII_TG3_AUXCTL_ACTL_TX_6DB) |
| 1287 | |
| 1288 | #define TG3_PHY_AUXCTL_SMDSP_DISABLE(tp) \ |
| 1289 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ |
| 1290 | MII_TG3_AUXCTL_ACTL_TX_6DB); |
| 1291 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1292 | static int tg3_bmcr_reset(struct tg3 *tp) |
| 1293 | { |
| 1294 | u32 phy_control; |
| 1295 | int limit, err; |
| 1296 | |
| 1297 | /* OK, reset it, and poll the BMCR_RESET bit until it |
| 1298 | * clears or we time out. |
| 1299 | */ |
| 1300 | phy_control = BMCR_RESET; |
| 1301 | err = tg3_writephy(tp, MII_BMCR, phy_control); |
| 1302 | if (err != 0) |
| 1303 | return -EBUSY; |
| 1304 | |
| 1305 | limit = 5000; |
| 1306 | while (limit--) { |
| 1307 | err = tg3_readphy(tp, MII_BMCR, &phy_control); |
| 1308 | if (err != 0) |
| 1309 | return -EBUSY; |
| 1310 | |
| 1311 | if ((phy_control & BMCR_RESET) == 0) { |
| 1312 | udelay(40); |
| 1313 | break; |
| 1314 | } |
| 1315 | udelay(10); |
| 1316 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 1317 | if (limit < 0) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1318 | return -EBUSY; |
| 1319 | |
| 1320 | return 0; |
| 1321 | } |
| 1322 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1323 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
| 1324 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1325 | struct tg3 *tp = bp->priv; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1326 | u32 val; |
| 1327 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1328 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1329 | |
| 1330 | if (tg3_readphy(tp, reg, &val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1331 | val = -EIO; |
| 1332 | |
| 1333 | spin_unlock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1334 | |
| 1335 | return val; |
| 1336 | } |
| 1337 | |
| 1338 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) |
| 1339 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1340 | struct tg3 *tp = bp->priv; |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1341 | u32 ret = 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1342 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1343 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1344 | |
| 1345 | if (tg3_writephy(tp, reg, val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1346 | ret = -EIO; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1347 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1348 | spin_unlock_bh(&tp->lock); |
| 1349 | |
| 1350 | return ret; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | static int tg3_mdio_reset(struct mii_bus *bp) |
| 1354 | { |
| 1355 | return 0; |
| 1356 | } |
| 1357 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1358 | static void tg3_mdio_config_5785(struct tg3 *tp) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1359 | { |
| 1360 | u32 val; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1361 | struct phy_device *phydev; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1362 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1363 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1364 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1365 | case PHY_ID_BCM50610: |
| 1366 | case PHY_ID_BCM50610M: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1367 | val = MAC_PHYCFG2_50610_LED_MODES; |
| 1368 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1369 | case PHY_ID_BCMAC131: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1370 | val = MAC_PHYCFG2_AC131_LED_MODES; |
| 1371 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1372 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1373 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
| 1374 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1375 | case PHY_ID_RTL8201E: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1376 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
| 1377 | break; |
| 1378 | default: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1379 | return; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { |
| 1383 | tw32(MAC_PHYCFG2, val); |
| 1384 | |
| 1385 | val = tr32(MAC_PHYCFG1); |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1386 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
| 1387 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); |
| 1388 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1389 | tw32(MAC_PHYCFG1, val); |
| 1390 | |
| 1391 | return; |
| 1392 | } |
| 1393 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1394 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1395 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
| 1396 | MAC_PHYCFG2_FMODE_MASK_MASK | |
| 1397 | MAC_PHYCFG2_GMODE_MASK_MASK | |
| 1398 | MAC_PHYCFG2_ACT_MASK_MASK | |
| 1399 | MAC_PHYCFG2_QUAL_MASK_MASK | |
| 1400 | MAC_PHYCFG2_INBAND_ENABLE; |
| 1401 | |
| 1402 | tw32(MAC_PHYCFG2, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1403 | |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1404 | val = tr32(MAC_PHYCFG1); |
| 1405 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | |
| 1406 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1407 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1408 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1409 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1410 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1411 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
| 1412 | } |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1413 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
| 1414 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; |
| 1415 | tw32(MAC_PHYCFG1, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1416 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1417 | val = tr32(MAC_EXT_RGMII_MODE); |
| 1418 | val &= ~(MAC_RGMII_MODE_RX_INT_B | |
| 1419 | MAC_RGMII_MODE_RX_QUALITY | |
| 1420 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1421 | MAC_RGMII_MODE_RX_ENG_DET | |
| 1422 | MAC_RGMII_MODE_TX_ENABLE | |
| 1423 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1424 | MAC_RGMII_MODE_TX_RESET); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1425 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1426 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1427 | val |= MAC_RGMII_MODE_RX_INT_B | |
| 1428 | MAC_RGMII_MODE_RX_QUALITY | |
| 1429 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1430 | MAC_RGMII_MODE_RX_ENG_DET; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1431 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1432 | val |= MAC_RGMII_MODE_TX_ENABLE | |
| 1433 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1434 | MAC_RGMII_MODE_TX_RESET; |
| 1435 | } |
| 1436 | tw32(MAC_EXT_RGMII_MODE, val); |
| 1437 | } |
| 1438 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1439 | static void tg3_mdio_start(struct tg3 *tp) |
| 1440 | { |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1441 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
| 1442 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1443 | udelay(80); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1444 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1445 | if (tg3_flag(tp, MDIOBUS_INITED) && |
Matt Carlson | 9ea4818 | 2010-02-17 15:17:01 +0000 | [diff] [blame] | 1446 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1447 | tg3_mdio_config_5785(tp); |
| 1448 | } |
| 1449 | |
| 1450 | static int tg3_mdio_init(struct tg3 *tp) |
| 1451 | { |
| 1452 | int i; |
| 1453 | u32 reg; |
| 1454 | struct phy_device *phydev; |
| 1455 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1456 | if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1457 | u32 is_serdes; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1458 | |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 1459 | tp->phy_addr = tp->pci_fn + 1; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1460 | |
Matt Carlson | d1ec96a | 2010-01-12 10:11:38 +0000 | [diff] [blame] | 1461 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
| 1462 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
| 1463 | else |
| 1464 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & |
| 1465 | TG3_CPMU_PHY_STRAP_IS_SERDES; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1466 | if (is_serdes) |
| 1467 | tp->phy_addr += 7; |
| 1468 | } else |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1469 | tp->phy_addr = TG3_PHY_MII_ADDR; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1470 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1471 | tg3_mdio_start(tp); |
| 1472 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1473 | if (!tg3_flag(tp, USE_PHYLIB) || tg3_flag(tp, MDIOBUS_INITED)) |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1474 | return 0; |
| 1475 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1476 | tp->mdio_bus = mdiobus_alloc(); |
| 1477 | if (tp->mdio_bus == NULL) |
| 1478 | return -ENOMEM; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1479 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1480 | tp->mdio_bus->name = "tg3 mdio bus"; |
| 1481 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1482 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1483 | tp->mdio_bus->priv = tp; |
| 1484 | tp->mdio_bus->parent = &tp->pdev->dev; |
| 1485 | tp->mdio_bus->read = &tg3_mdio_read; |
| 1486 | tp->mdio_bus->write = &tg3_mdio_write; |
| 1487 | tp->mdio_bus->reset = &tg3_mdio_reset; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1488 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1489 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1490 | |
| 1491 | for (i = 0; i < PHY_MAX_ADDR; i++) |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1492 | tp->mdio_bus->irq[i] = PHY_POLL; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1493 | |
| 1494 | /* The bus registration will look for all the PHYs on the mdio bus. |
| 1495 | * Unfortunately, it does not ensure the PHY is powered up before |
| 1496 | * accessing the PHY ID registers. A chip reset is the |
| 1497 | * quickest way to bring the device back to an operational state.. |
| 1498 | */ |
| 1499 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
| 1500 | tg3_bmcr_reset(tp); |
| 1501 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1502 | i = mdiobus_register(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1503 | if (i) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1504 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1505 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1506 | return i; |
| 1507 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1508 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1509 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1510 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1511 | if (!phydev || !phydev->drv) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1512 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1513 | mdiobus_unregister(tp->mdio_bus); |
| 1514 | mdiobus_free(tp->mdio_bus); |
| 1515 | return -ENODEV; |
| 1516 | } |
| 1517 | |
| 1518 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1519 | case PHY_ID_BCM57780: |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1520 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1521 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1522 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1523 | case PHY_ID_BCM50610: |
| 1524 | case PHY_ID_BCM50610M: |
Matt Carlson | 32e5a8d | 2009-11-02 14:31:39 +0000 | [diff] [blame] | 1525 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1526 | PHY_BRCM_RX_REFCLK_UNUSED | |
Matt Carlson | 52fae08 | 2009-11-02 14:32:38 +0000 | [diff] [blame] | 1527 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1528 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1529 | if (tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1530 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1531 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1532 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1533 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1534 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1535 | /* fallthru */ |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1536 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1537 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1538 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1539 | case PHY_ID_RTL8201E: |
| 1540 | case PHY_ID_BCMAC131: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1541 | phydev->interface = PHY_INTERFACE_MODE_MII; |
Matt Carlson | cdd4e09d | 2009-11-02 14:31:11 +0000 | [diff] [blame] | 1542 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1543 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1544 | break; |
| 1545 | } |
| 1546 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1547 | tg3_flag_set(tp, MDIOBUS_INITED); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1548 | |
| 1549 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1550 | tg3_mdio_config_5785(tp); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1551 | |
| 1552 | return 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | static void tg3_mdio_fini(struct tg3 *tp) |
| 1556 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1557 | if (tg3_flag(tp, MDIOBUS_INITED)) { |
| 1558 | tg3_flag_clear(tp, MDIOBUS_INITED); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1559 | mdiobus_unregister(tp->mdio_bus); |
| 1560 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1564 | /* tp->lock is held. */ |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1565 | static inline void tg3_generate_fw_event(struct tg3 *tp) |
| 1566 | { |
| 1567 | u32 val; |
| 1568 | |
| 1569 | val = tr32(GRC_RX_CPU_EVENT); |
| 1570 | val |= GRC_RX_CPU_DRIVER_EVENT; |
| 1571 | tw32_f(GRC_RX_CPU_EVENT, val); |
| 1572 | |
| 1573 | tp->last_event_jiffies = jiffies; |
| 1574 | } |
| 1575 | |
| 1576 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 |
| 1577 | |
| 1578 | /* tp->lock is held. */ |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1579 | static void tg3_wait_for_event_ack(struct tg3 *tp) |
| 1580 | { |
| 1581 | int i; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1582 | unsigned int delay_cnt; |
| 1583 | long time_remain; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1584 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1585 | /* If enough time has passed, no wait is necessary. */ |
| 1586 | time_remain = (long)(tp->last_event_jiffies + 1 + |
| 1587 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - |
| 1588 | (long)jiffies; |
| 1589 | if (time_remain < 0) |
| 1590 | return; |
| 1591 | |
| 1592 | /* Check if we can shorten the wait time. */ |
| 1593 | delay_cnt = jiffies_to_usecs(time_remain); |
| 1594 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) |
| 1595 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; |
| 1596 | delay_cnt = (delay_cnt >> 3) + 1; |
| 1597 | |
| 1598 | for (i = 0; i < delay_cnt; i++) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1599 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
| 1600 | break; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1601 | udelay(8); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | /* tp->lock is held. */ |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1606 | static void tg3_phy_gather_ump_data(struct tg3 *tp, u32 *data) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1607 | { |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1608 | u32 reg, val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1609 | |
| 1610 | val = 0; |
| 1611 | if (!tg3_readphy(tp, MII_BMCR, ®)) |
| 1612 | val = reg << 16; |
| 1613 | if (!tg3_readphy(tp, MII_BMSR, ®)) |
| 1614 | val |= (reg & 0xffff); |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1615 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1616 | |
| 1617 | val = 0; |
| 1618 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) |
| 1619 | val = reg << 16; |
| 1620 | if (!tg3_readphy(tp, MII_LPA, ®)) |
| 1621 | val |= (reg & 0xffff); |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1622 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1623 | |
| 1624 | val = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1625 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1626 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
| 1627 | val = reg << 16; |
| 1628 | if (!tg3_readphy(tp, MII_STAT1000, ®)) |
| 1629 | val |= (reg & 0xffff); |
| 1630 | } |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1631 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1632 | |
| 1633 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) |
| 1634 | val = reg << 16; |
| 1635 | else |
| 1636 | val = 0; |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1637 | *data++ = val; |
| 1638 | } |
| 1639 | |
| 1640 | /* tp->lock is held. */ |
| 1641 | static void tg3_ump_link_report(struct tg3 *tp) |
| 1642 | { |
| 1643 | u32 data[4]; |
| 1644 | |
| 1645 | if (!tg3_flag(tp, 5780_CLASS) || !tg3_flag(tp, ENABLE_ASF)) |
| 1646 | return; |
| 1647 | |
| 1648 | tg3_phy_gather_ump_data(tp, data); |
| 1649 | |
| 1650 | tg3_wait_for_event_ack(tp); |
| 1651 | |
| 1652 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); |
| 1653 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); |
| 1654 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x0, data[0]); |
| 1655 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x4, data[1]); |
| 1656 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x8, data[2]); |
| 1657 | 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] | 1658 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1659 | tg3_generate_fw_event(tp); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Matt Carlson | 8d5a89b | 2011-08-31 11:44:51 +0000 | [diff] [blame] | 1662 | /* tp->lock is held. */ |
| 1663 | static void tg3_stop_fw(struct tg3 *tp) |
| 1664 | { |
| 1665 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
| 1666 | /* Wait for RX cpu to ACK the previous event. */ |
| 1667 | tg3_wait_for_event_ack(tp); |
| 1668 | |
| 1669 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); |
| 1670 | |
| 1671 | tg3_generate_fw_event(tp); |
| 1672 | |
| 1673 | /* Wait for RX cpu to ACK this event. */ |
| 1674 | tg3_wait_for_event_ack(tp); |
| 1675 | } |
| 1676 | } |
| 1677 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 1678 | /* tp->lock is held. */ |
| 1679 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) |
| 1680 | { |
| 1681 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
| 1682 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); |
| 1683 | |
| 1684 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1685 | switch (kind) { |
| 1686 | case RESET_KIND_INIT: |
| 1687 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1688 | DRV_STATE_START); |
| 1689 | break; |
| 1690 | |
| 1691 | case RESET_KIND_SHUTDOWN: |
| 1692 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1693 | DRV_STATE_UNLOAD); |
| 1694 | break; |
| 1695 | |
| 1696 | case RESET_KIND_SUSPEND: |
| 1697 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1698 | DRV_STATE_SUSPEND); |
| 1699 | break; |
| 1700 | |
| 1701 | default: |
| 1702 | break; |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | if (kind == RESET_KIND_INIT || |
| 1707 | kind == RESET_KIND_SUSPEND) |
| 1708 | tg3_ape_driver_state_change(tp, kind); |
| 1709 | } |
| 1710 | |
| 1711 | /* tp->lock is held. */ |
| 1712 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) |
| 1713 | { |
| 1714 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1715 | switch (kind) { |
| 1716 | case RESET_KIND_INIT: |
| 1717 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1718 | DRV_STATE_START_DONE); |
| 1719 | break; |
| 1720 | |
| 1721 | case RESET_KIND_SHUTDOWN: |
| 1722 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1723 | DRV_STATE_UNLOAD_DONE); |
| 1724 | break; |
| 1725 | |
| 1726 | default: |
| 1727 | break; |
| 1728 | } |
| 1729 | } |
| 1730 | |
| 1731 | if (kind == RESET_KIND_SHUTDOWN) |
| 1732 | tg3_ape_driver_state_change(tp, kind); |
| 1733 | } |
| 1734 | |
| 1735 | /* tp->lock is held. */ |
| 1736 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) |
| 1737 | { |
| 1738 | if (tg3_flag(tp, ENABLE_ASF)) { |
| 1739 | switch (kind) { |
| 1740 | case RESET_KIND_INIT: |
| 1741 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1742 | DRV_STATE_START); |
| 1743 | break; |
| 1744 | |
| 1745 | case RESET_KIND_SHUTDOWN: |
| 1746 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1747 | DRV_STATE_UNLOAD); |
| 1748 | break; |
| 1749 | |
| 1750 | case RESET_KIND_SUSPEND: |
| 1751 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1752 | DRV_STATE_SUSPEND); |
| 1753 | break; |
| 1754 | |
| 1755 | default: |
| 1756 | break; |
| 1757 | } |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | static int tg3_poll_fw(struct tg3 *tp) |
| 1762 | { |
| 1763 | int i; |
| 1764 | u32 val; |
| 1765 | |
| 1766 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 1767 | /* Wait up to 20ms for init done. */ |
| 1768 | for (i = 0; i < 200; i++) { |
| 1769 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
| 1770 | return 0; |
| 1771 | udelay(100); |
| 1772 | } |
| 1773 | return -ENODEV; |
| 1774 | } |
| 1775 | |
| 1776 | /* Wait for firmware initialization to complete. */ |
| 1777 | for (i = 0; i < 100000; i++) { |
| 1778 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); |
| 1779 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 1780 | break; |
| 1781 | udelay(10); |
| 1782 | } |
| 1783 | |
| 1784 | /* Chip might not be fitted with firmware. Some Sun onboard |
| 1785 | * parts are configured like that. So don't signal the timeout |
| 1786 | * of the above loop as an error, but do report the lack of |
| 1787 | * running firmware once. |
| 1788 | */ |
| 1789 | if (i >= 100000 && !tg3_flag(tp, NO_FWARE_REPORTED)) { |
| 1790 | tg3_flag_set(tp, NO_FWARE_REPORTED); |
| 1791 | |
| 1792 | netdev_info(tp->dev, "No firmware running\n"); |
| 1793 | } |
| 1794 | |
| 1795 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 1796 | /* The 57765 A0 needs a little more |
| 1797 | * time to do some important work. |
| 1798 | */ |
| 1799 | mdelay(10); |
| 1800 | } |
| 1801 | |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1805 | static void tg3_link_report(struct tg3 *tp) |
| 1806 | { |
| 1807 | if (!netif_carrier_ok(tp->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1808 | netif_info(tp, link, tp->dev, "Link is down\n"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1809 | tg3_ump_link_report(tp); |
| 1810 | } else if (netif_msg_link(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1811 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
| 1812 | (tp->link_config.active_speed == SPEED_1000 ? |
| 1813 | 1000 : |
| 1814 | (tp->link_config.active_speed == SPEED_100 ? |
| 1815 | 100 : 10)), |
| 1816 | (tp->link_config.active_duplex == DUPLEX_FULL ? |
| 1817 | "full" : "half")); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1818 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1819 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", |
| 1820 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? |
| 1821 | "on" : "off", |
| 1822 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? |
| 1823 | "on" : "off"); |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 1824 | |
| 1825 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) |
| 1826 | netdev_info(tp->dev, "EEE is %s\n", |
| 1827 | tp->setlpicnt ? "enabled" : "disabled"); |
| 1828 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1829 | tg3_ump_link_report(tp); |
| 1830 | } |
| 1831 | } |
| 1832 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1833 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
| 1834 | { |
| 1835 | u16 miireg; |
| 1836 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1837 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1838 | miireg = ADVERTISE_1000XPAUSE; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1839 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1840 | miireg = ADVERTISE_1000XPSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1841 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1842 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
| 1843 | else |
| 1844 | miireg = 0; |
| 1845 | |
| 1846 | return miireg; |
| 1847 | } |
| 1848 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1849 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
| 1850 | { |
| 1851 | u8 cap = 0; |
| 1852 | |
Matt Carlson | f3791cd | 2011-11-21 15:01:17 +0000 | [diff] [blame] | 1853 | if (lcladv & rmtadv & ADVERTISE_1000XPAUSE) { |
| 1854 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 1855 | } else if (lcladv & rmtadv & ADVERTISE_1000XPSE_ASYM) { |
| 1856 | if (lcladv & ADVERTISE_1000XPAUSE) |
| 1857 | cap = FLOW_CTRL_RX; |
| 1858 | if (rmtadv & ADVERTISE_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1859 | cap = FLOW_CTRL_TX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | return cap; |
| 1863 | } |
| 1864 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1865 | 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] | 1866 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1867 | u8 autoneg; |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1868 | u8 flowctrl = 0; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1869 | u32 old_rx_mode = tp->rx_mode; |
| 1870 | u32 old_tx_mode = tp->tx_mode; |
| 1871 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1872 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1873 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1874 | else |
| 1875 | autoneg = tp->link_config.autoneg; |
| 1876 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1877 | if (autoneg == AUTONEG_ENABLE && tg3_flag(tp, PAUSE_AUTONEG)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1878 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1879 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1880 | else |
Steve Glendinning | bc02ff9 | 2008-12-16 02:00:48 -0800 | [diff] [blame] | 1881 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1882 | } else |
| 1883 | flowctrl = tp->link_config.flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1884 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1885 | tp->link_config.active_flowctrl = flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1886 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1887 | if (flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1888 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
| 1889 | else |
| 1890 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; |
| 1891 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1892 | if (old_rx_mode != tp->rx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1893 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1894 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1895 | if (flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1896 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
| 1897 | else |
| 1898 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; |
| 1899 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1900 | if (old_tx_mode != tp->tx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1901 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1904 | static void tg3_adjust_link(struct net_device *dev) |
| 1905 | { |
| 1906 | u8 oldflowctrl, linkmesg = 0; |
| 1907 | u32 mac_mode, lcl_adv, rmt_adv; |
| 1908 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1909 | 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] | 1910 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1911 | spin_lock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1912 | |
| 1913 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | |
| 1914 | MAC_MODE_HALF_DUPLEX); |
| 1915 | |
| 1916 | oldflowctrl = tp->link_config.active_flowctrl; |
| 1917 | |
| 1918 | if (phydev->link) { |
| 1919 | lcl_adv = 0; |
| 1920 | rmt_adv = 0; |
| 1921 | |
| 1922 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) |
| 1923 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1924 | else if (phydev->speed == SPEED_1000 || |
| 1925 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1926 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1927 | else |
| 1928 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1929 | |
| 1930 | if (phydev->duplex == DUPLEX_HALF) |
| 1931 | mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 1932 | else { |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 1933 | lcl_adv = mii_advertise_flowctrl( |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1934 | tp->link_config.flowctrl); |
| 1935 | |
| 1936 | if (phydev->pause) |
| 1937 | rmt_adv = LPA_PAUSE_CAP; |
| 1938 | if (phydev->asym_pause) |
| 1939 | rmt_adv |= LPA_PAUSE_ASYM; |
| 1940 | } |
| 1941 | |
| 1942 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 1943 | } else |
| 1944 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 1945 | |
| 1946 | if (mac_mode != tp->mac_mode) { |
| 1947 | tp->mac_mode = mac_mode; |
| 1948 | tw32_f(MAC_MODE, tp->mac_mode); |
| 1949 | udelay(40); |
| 1950 | } |
| 1951 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1952 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
| 1953 | if (phydev->speed == SPEED_10) |
| 1954 | tw32(MAC_MI_STAT, |
| 1955 | MAC_MI_STAT_10MBPS_MODE | |
| 1956 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1957 | else |
| 1958 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1959 | } |
| 1960 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1961 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
| 1962 | tw32(MAC_TX_LENGTHS, |
| 1963 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1964 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1965 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1966 | else |
| 1967 | tw32(MAC_TX_LENGTHS, |
| 1968 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1969 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1970 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1971 | |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 1972 | if (phydev->link != tp->old_link || |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1973 | phydev->speed != tp->link_config.active_speed || |
| 1974 | phydev->duplex != tp->link_config.active_duplex || |
| 1975 | oldflowctrl != tp->link_config.active_flowctrl) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 1976 | linkmesg = 1; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1977 | |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 1978 | tp->old_link = phydev->link; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1979 | tp->link_config.active_speed = phydev->speed; |
| 1980 | tp->link_config.active_duplex = phydev->duplex; |
| 1981 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1982 | spin_unlock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1983 | |
| 1984 | if (linkmesg) |
| 1985 | tg3_link_report(tp); |
| 1986 | } |
| 1987 | |
| 1988 | static int tg3_phy_init(struct tg3 *tp) |
| 1989 | { |
| 1990 | struct phy_device *phydev; |
| 1991 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1992 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1993 | return 0; |
| 1994 | |
| 1995 | /* Bring the PHY back to a known state. */ |
| 1996 | tg3_bmcr_reset(tp); |
| 1997 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1998 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1999 | |
| 2000 | /* Attach the MAC to the PHY. */ |
Kay Sievers | fb28ad3 | 2008-11-10 13:55:14 -0800 | [diff] [blame] | 2001 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link, |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 2002 | phydev->dev_flags, phydev->interface); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2003 | if (IS_ERR(phydev)) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 2004 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2005 | return PTR_ERR(phydev); |
| 2006 | } |
| 2007 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2008 | /* Mask with MAC supported features. */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 2009 | switch (phydev->interface) { |
| 2010 | case PHY_INTERFACE_MODE_GMII: |
| 2011 | case PHY_INTERFACE_MODE_RGMII: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2012 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 2013 | phydev->supported &= (PHY_GBIT_FEATURES | |
| 2014 | SUPPORTED_Pause | |
| 2015 | SUPPORTED_Asym_Pause); |
| 2016 | break; |
| 2017 | } |
| 2018 | /* fallthru */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 2019 | case PHY_INTERFACE_MODE_MII: |
| 2020 | phydev->supported &= (PHY_BASIC_FEATURES | |
| 2021 | SUPPORTED_Pause | |
| 2022 | SUPPORTED_Asym_Pause); |
| 2023 | break; |
| 2024 | default: |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2025 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 2026 | return -EINVAL; |
| 2027 | } |
| 2028 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2029 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2030 | |
| 2031 | phydev->advertising = phydev->supported; |
| 2032 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2033 | return 0; |
| 2034 | } |
| 2035 | |
| 2036 | static void tg3_phy_start(struct tg3 *tp) |
| 2037 | { |
| 2038 | struct phy_device *phydev; |
| 2039 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2040 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2041 | return; |
| 2042 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2043 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2044 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2045 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 2046 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 2047 | phydev->speed = tp->link_config.speed; |
| 2048 | phydev->duplex = tp->link_config.duplex; |
| 2049 | phydev->autoneg = tp->link_config.autoneg; |
| 2050 | phydev->advertising = tp->link_config.advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | phy_start(phydev); |
| 2054 | |
| 2055 | phy_start_aneg(phydev); |
| 2056 | } |
| 2057 | |
| 2058 | static void tg3_phy_stop(struct tg3 *tp) |
| 2059 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2060 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2061 | return; |
| 2062 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2063 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | static void tg3_phy_fini(struct tg3 *tp) |
| 2067 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2068 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2069 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2070 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2071 | } |
| 2072 | } |
| 2073 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 2074 | static int tg3_phy_set_extloopbk(struct tg3 *tp) |
| 2075 | { |
| 2076 | int err; |
| 2077 | u32 val; |
| 2078 | |
| 2079 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 2080 | return 0; |
| 2081 | |
| 2082 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
| 2083 | /* Cannot do read-modify-write on 5401 */ |
| 2084 | err = tg3_phy_auxctl_write(tp, |
| 2085 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2086 | MII_TG3_AUXCTL_ACTL_EXTLOOPBK | |
| 2087 | 0x4c20); |
| 2088 | goto done; |
| 2089 | } |
| 2090 | |
| 2091 | err = tg3_phy_auxctl_read(tp, |
| 2092 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2093 | if (err) |
| 2094 | return err; |
| 2095 | |
| 2096 | val |= MII_TG3_AUXCTL_ACTL_EXTLOOPBK; |
| 2097 | err = tg3_phy_auxctl_write(tp, |
| 2098 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, val); |
| 2099 | |
| 2100 | done: |
| 2101 | return err; |
| 2102 | } |
| 2103 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 2104 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
| 2105 | { |
| 2106 | u32 phytest; |
| 2107 | |
| 2108 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2109 | u32 phy; |
| 2110 | |
| 2111 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2112 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2113 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { |
| 2114 | if (enable) |
| 2115 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 2116 | else |
| 2117 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 2118 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); |
| 2119 | } |
| 2120 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2121 | } |
| 2122 | } |
| 2123 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2124 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
| 2125 | { |
| 2126 | u32 reg; |
| 2127 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2128 | if (!tg3_flag(tp, 5705_PLUS) || |
| 2129 | (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2130 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2131 | return; |
| 2132 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2133 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 2134 | tg3_phy_fet_toggle_apd(tp, enable); |
| 2135 | return; |
| 2136 | } |
| 2137 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2138 | reg = MII_TG3_MISC_SHDW_WREN | |
| 2139 | MII_TG3_MISC_SHDW_SCR5_SEL | |
| 2140 | MII_TG3_MISC_SHDW_SCR5_LPED | |
| 2141 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | |
| 2142 | MII_TG3_MISC_SHDW_SCR5_SDTL | |
| 2143 | MII_TG3_MISC_SHDW_SCR5_C125OE; |
| 2144 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) |
| 2145 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
| 2146 | |
| 2147 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 2148 | |
| 2149 | |
| 2150 | reg = MII_TG3_MISC_SHDW_WREN | |
| 2151 | MII_TG3_MISC_SHDW_APD_SEL | |
| 2152 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; |
| 2153 | if (enable) |
| 2154 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; |
| 2155 | |
| 2156 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 2157 | } |
| 2158 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2159 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
| 2160 | { |
| 2161 | u32 phy; |
| 2162 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2163 | if (!tg3_flag(tp, 5705_PLUS) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2164 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2165 | return; |
| 2166 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2167 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2168 | u32 ephy; |
| 2169 | |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2170 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
| 2171 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; |
| 2172 | |
| 2173 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2174 | ephy | MII_TG3_FET_SHADOW_EN); |
| 2175 | if (!tg3_readphy(tp, reg, &phy)) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2176 | if (enable) |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2177 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2178 | else |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2179 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 2180 | tg3_writephy(tp, reg, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2181 | } |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2182 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2183 | } |
| 2184 | } else { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2185 | int ret; |
| 2186 | |
| 2187 | ret = tg3_phy_auxctl_read(tp, |
| 2188 | MII_TG3_AUXCTL_SHDWSEL_MISC, &phy); |
| 2189 | if (!ret) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2190 | if (enable) |
| 2191 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 2192 | else |
| 2193 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2194 | tg3_phy_auxctl_write(tp, |
| 2195 | MII_TG3_AUXCTL_SHDWSEL_MISC, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2196 | } |
| 2197 | } |
| 2198 | } |
| 2199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
| 2201 | { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2202 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | u32 val; |
| 2204 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2205 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | return; |
| 2207 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2208 | ret = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, &val); |
| 2209 | if (!ret) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2210 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, |
| 2211 | val | MII_TG3_AUXCTL_MISC_WIRESPD_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | } |
| 2213 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2214 | static void tg3_phy_apply_otp(struct tg3 *tp) |
| 2215 | { |
| 2216 | u32 otp, phy; |
| 2217 | |
| 2218 | if (!tp->phy_otp) |
| 2219 | return; |
| 2220 | |
| 2221 | otp = tp->phy_otp; |
| 2222 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2223 | if (TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) |
| 2224 | return; |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2225 | |
| 2226 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); |
| 2227 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; |
| 2228 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); |
| 2229 | |
| 2230 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | |
| 2231 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); |
| 2232 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); |
| 2233 | |
| 2234 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); |
| 2235 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; |
| 2236 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); |
| 2237 | |
| 2238 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); |
| 2239 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); |
| 2240 | |
| 2241 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); |
| 2242 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); |
| 2243 | |
| 2244 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | |
| 2245 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); |
| 2246 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); |
| 2247 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2248 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2251 | static void tg3_phy_eee_adjust(struct tg3 *tp, u32 current_link_up) |
| 2252 | { |
| 2253 | u32 val; |
| 2254 | |
| 2255 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 2256 | return; |
| 2257 | |
| 2258 | tp->setlpicnt = 0; |
| 2259 | |
| 2260 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 2261 | current_link_up == 1 && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 2262 | tp->link_config.active_duplex == DUPLEX_FULL && |
| 2263 | (tp->link_config.active_speed == SPEED_100 || |
| 2264 | tp->link_config.active_speed == SPEED_1000)) { |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2265 | u32 eeectl; |
| 2266 | |
| 2267 | if (tp->link_config.active_speed == SPEED_1000) |
| 2268 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; |
| 2269 | else |
| 2270 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; |
| 2271 | |
| 2272 | tw32(TG3_CPMU_EEE_CTRL, eeectl); |
| 2273 | |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 2274 | tg3_phy_cl45_read(tp, MDIO_MMD_AN, |
| 2275 | TG3_CL45_D7_EEERES_STAT, &val); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2276 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2277 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
| 2278 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2279 | tp->setlpicnt = 2; |
| 2280 | } |
| 2281 | |
| 2282 | if (!tp->setlpicnt) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2283 | if (current_link_up == 1 && |
| 2284 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2285 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, 0x0000); |
| 2286 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2287 | } |
| 2288 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2289 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2290 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2291 | } |
| 2292 | } |
| 2293 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2294 | static void tg3_phy_eee_enable(struct tg3 *tp) |
| 2295 | { |
| 2296 | u32 val; |
| 2297 | |
| 2298 | if (tp->link_config.active_speed == SPEED_1000 && |
| 2299 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2300 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 2301 | tg3_flag(tp, 57765_CLASS)) && |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2302 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2303 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 2304 | MII_TG3_DSP_TAP26_RMRXSTO; |
| 2305 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2306 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2307 | } |
| 2308 | |
| 2309 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2310 | tw32(TG3_CPMU_EEE_MODE, val | TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2311 | } |
| 2312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | static int tg3_wait_macro_done(struct tg3 *tp) |
| 2314 | { |
| 2315 | int limit = 100; |
| 2316 | |
| 2317 | while (limit--) { |
| 2318 | u32 tmp32; |
| 2319 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2320 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | if ((tmp32 & 0x1000) == 0) |
| 2322 | break; |
| 2323 | } |
| 2324 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 2325 | if (limit < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | return -EBUSY; |
| 2327 | |
| 2328 | return 0; |
| 2329 | } |
| 2330 | |
| 2331 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) |
| 2332 | { |
| 2333 | static const u32 test_pat[4][6] = { |
| 2334 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, |
| 2335 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, |
| 2336 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, |
| 2337 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } |
| 2338 | }; |
| 2339 | int chan; |
| 2340 | |
| 2341 | for (chan = 0; chan < 4; chan++) { |
| 2342 | int i; |
| 2343 | |
| 2344 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2345 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2346 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | |
| 2348 | for (i = 0; i < 6; i++) |
| 2349 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, |
| 2350 | test_pat[chan][i]); |
| 2351 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2352 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | if (tg3_wait_macro_done(tp)) { |
| 2354 | *resetp = 1; |
| 2355 | return -EBUSY; |
| 2356 | } |
| 2357 | |
| 2358 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2359 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2360 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | if (tg3_wait_macro_done(tp)) { |
| 2362 | *resetp = 1; |
| 2363 | return -EBUSY; |
| 2364 | } |
| 2365 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2366 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | if (tg3_wait_macro_done(tp)) { |
| 2368 | *resetp = 1; |
| 2369 | return -EBUSY; |
| 2370 | } |
| 2371 | |
| 2372 | for (i = 0; i < 6; i += 2) { |
| 2373 | u32 low, high; |
| 2374 | |
| 2375 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || |
| 2376 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || |
| 2377 | tg3_wait_macro_done(tp)) { |
| 2378 | *resetp = 1; |
| 2379 | return -EBUSY; |
| 2380 | } |
| 2381 | low &= 0x7fff; |
| 2382 | high &= 0x000f; |
| 2383 | if (low != test_pat[chan][i] || |
| 2384 | high != test_pat[chan][i+1]) { |
| 2385 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); |
| 2386 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); |
| 2387 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); |
| 2388 | |
| 2389 | return -EBUSY; |
| 2390 | } |
| 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | return 0; |
| 2395 | } |
| 2396 | |
| 2397 | static int tg3_phy_reset_chanpat(struct tg3 *tp) |
| 2398 | { |
| 2399 | int chan; |
| 2400 | |
| 2401 | for (chan = 0; chan < 4; chan++) { |
| 2402 | int i; |
| 2403 | |
| 2404 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2405 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2406 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | for (i = 0; i < 6; i++) |
| 2408 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2409 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | if (tg3_wait_macro_done(tp)) |
| 2411 | return -EBUSY; |
| 2412 | } |
| 2413 | |
| 2414 | return 0; |
| 2415 | } |
| 2416 | |
| 2417 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) |
| 2418 | { |
| 2419 | u32 reg32, phy9_orig; |
| 2420 | int retries, do_phy_reset, err; |
| 2421 | |
| 2422 | retries = 10; |
| 2423 | do_phy_reset = 1; |
| 2424 | do { |
| 2425 | if (do_phy_reset) { |
| 2426 | err = tg3_bmcr_reset(tp); |
| 2427 | if (err) |
| 2428 | return err; |
| 2429 | do_phy_reset = 0; |
| 2430 | } |
| 2431 | |
| 2432 | /* Disable transmitter and interrupt. */ |
| 2433 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) |
| 2434 | continue; |
| 2435 | |
| 2436 | reg32 |= 0x3000; |
| 2437 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2438 | |
| 2439 | /* Set full-duplex, 1000 mbps. */ |
| 2440 | tg3_writephy(tp, MII_BMCR, |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2441 | BMCR_FULLDPLX | BMCR_SPEED1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | |
| 2443 | /* Set to master mode. */ |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2444 | if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | continue; |
| 2446 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2447 | tg3_writephy(tp, MII_CTRL1000, |
| 2448 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2450 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
| 2451 | if (err) |
| 2452 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | |
| 2454 | /* Block the PHY control access. */ |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2455 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | |
| 2457 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); |
| 2458 | if (!err) |
| 2459 | break; |
| 2460 | } while (--retries); |
| 2461 | |
| 2462 | err = tg3_phy_reset_chanpat(tp); |
| 2463 | if (err) |
| 2464 | return err; |
| 2465 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2466 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | |
| 2468 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2469 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2471 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2473 | tg3_writephy(tp, MII_CTRL1000, phy9_orig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | |
| 2475 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { |
| 2476 | reg32 &= ~0x3000; |
| 2477 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2478 | } else if (!err) |
| 2479 | err = -EBUSY; |
| 2480 | |
| 2481 | return err; |
| 2482 | } |
| 2483 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 2484 | static void tg3_carrier_on(struct tg3 *tp) |
| 2485 | { |
| 2486 | netif_carrier_on(tp->dev); |
| 2487 | tp->link_up = true; |
| 2488 | } |
| 2489 | |
| 2490 | static void tg3_carrier_off(struct tg3 *tp) |
| 2491 | { |
| 2492 | netif_carrier_off(tp->dev); |
| 2493 | tp->link_up = false; |
| 2494 | } |
| 2495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | /* This will reset the tigon3 PHY if there is no valid |
| 2497 | * link unless the FORCE argument is non-zero. |
| 2498 | */ |
| 2499 | static int tg3_phy_reset(struct tg3 *tp) |
| 2500 | { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2501 | u32 val, cpmuctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | int err; |
| 2503 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2504 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2505 | val = tr32(GRC_MISC_CFG); |
| 2506 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); |
| 2507 | udelay(40); |
| 2508 | } |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2509 | err = tg3_readphy(tp, MII_BMSR, &val); |
| 2510 | err |= tg3_readphy(tp, MII_BMSR, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | if (err != 0) |
| 2512 | return -EBUSY; |
| 2513 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 2514 | if (netif_running(tp->dev) && tp->link_up) { |
| 2515 | tg3_carrier_off(tp); |
Michael Chan | c8e1e82 | 2006-04-29 18:55:17 -0700 | [diff] [blame] | 2516 | tg3_link_report(tp); |
| 2517 | } |
| 2518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 2520 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2521 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 2522 | err = tg3_phy_reset_5703_4_5(tp); |
| 2523 | if (err) |
| 2524 | return err; |
| 2525 | goto out; |
| 2526 | } |
| 2527 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2528 | cpmuctrl = 0; |
| 2529 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 2530 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 2531 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
| 2532 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) |
| 2533 | tw32(TG3_CPMU_CTRL, |
| 2534 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); |
| 2535 | } |
| 2536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | err = tg3_bmcr_reset(tp); |
| 2538 | if (err) |
| 2539 | return err; |
| 2540 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2541 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2542 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
| 2543 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2544 | |
| 2545 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 2546 | } |
| 2547 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2548 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2549 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2550 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2551 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == |
| 2552 | CPMU_LSPD_1000MB_MACCLK_12_5) { |
| 2553 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2554 | udelay(40); |
| 2555 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2556 | } |
| 2557 | } |
| 2558 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2559 | if (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2560 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 2561 | return 0; |
| 2562 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2563 | tg3_phy_apply_otp(tp); |
| 2564 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2565 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2566 | tg3_phy_toggle_apd(tp, true); |
| 2567 | else |
| 2568 | tg3_phy_toggle_apd(tp, false); |
| 2569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | out: |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2571 | if ((tp->phy_flags & TG3_PHYFLG_ADC_BUG) && |
| 2572 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2573 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
| 2574 | tg3_phydsp_write(tp, 0x000a, 0x0323); |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2575 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2577 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2578 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2579 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 2580 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2582 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2583 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2584 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2585 | tg3_phydsp_write(tp, 0x000a, 0x310b); |
| 2586 | tg3_phydsp_write(tp, 0x201f, 0x9506); |
| 2587 | tg3_phydsp_write(tp, 0x401f, 0x14e2); |
| 2588 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2589 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2590 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2591 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2592 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
| 2593 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { |
| 2594 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
| 2595 | tg3_writephy(tp, MII_TG3_TEST1, |
| 2596 | MII_TG3_TEST1_TRIM_EN | 0x4); |
| 2597 | } else |
| 2598 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); |
| 2599 | |
| 2600 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2601 | } |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 2602 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | /* Set Extended packet length bit (bit 14) on all chips that */ |
| 2605 | /* support jumbo frames */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2606 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | /* Cannot do read-modify-write on 5401 */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2608 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2609 | } else if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | /* Set bit 14 with read-modify-write to preserve other bits */ |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2611 | err = tg3_phy_auxctl_read(tp, |
| 2612 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2613 | if (!err) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2614 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2615 | val | MII_TG3_AUXCTL_ACTL_EXTPKTLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support |
| 2619 | * jumbo frames transmission. |
| 2620 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2621 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2622 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 2623 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2624 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2627 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2628 | /* adjust output voltage */ |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2629 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2632 | tg3_phy_toggle_automdix(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | tg3_phy_set_wirespeed(tp); |
| 2634 | return 0; |
| 2635 | } |
| 2636 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2637 | #define TG3_GPIO_MSG_DRVR_PRES 0x00000001 |
| 2638 | #define TG3_GPIO_MSG_NEED_VAUX 0x00000002 |
| 2639 | #define TG3_GPIO_MSG_MASK (TG3_GPIO_MSG_DRVR_PRES | \ |
| 2640 | TG3_GPIO_MSG_NEED_VAUX) |
| 2641 | #define TG3_GPIO_MSG_ALL_DRVR_PRES_MASK \ |
| 2642 | ((TG3_GPIO_MSG_DRVR_PRES << 0) | \ |
| 2643 | (TG3_GPIO_MSG_DRVR_PRES << 4) | \ |
| 2644 | (TG3_GPIO_MSG_DRVR_PRES << 8) | \ |
| 2645 | (TG3_GPIO_MSG_DRVR_PRES << 12)) |
| 2646 | |
| 2647 | #define TG3_GPIO_MSG_ALL_NEED_VAUX_MASK \ |
| 2648 | ((TG3_GPIO_MSG_NEED_VAUX << 0) | \ |
| 2649 | (TG3_GPIO_MSG_NEED_VAUX << 4) | \ |
| 2650 | (TG3_GPIO_MSG_NEED_VAUX << 8) | \ |
| 2651 | (TG3_GPIO_MSG_NEED_VAUX << 12)) |
| 2652 | |
| 2653 | static inline u32 tg3_set_function_status(struct tg3 *tp, u32 newstat) |
| 2654 | { |
| 2655 | u32 status, shift; |
| 2656 | |
| 2657 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2658 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 2659 | status = tg3_ape_read32(tp, TG3_APE_GPIO_MSG); |
| 2660 | else |
| 2661 | status = tr32(TG3_CPMU_DRV_STATUS); |
| 2662 | |
| 2663 | shift = TG3_APE_GPIO_MSG_SHIFT + 4 * tp->pci_fn; |
| 2664 | status &= ~(TG3_GPIO_MSG_MASK << shift); |
| 2665 | status |= (newstat << shift); |
| 2666 | |
| 2667 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2668 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 2669 | tg3_ape_write32(tp, TG3_APE_GPIO_MSG, status); |
| 2670 | else |
| 2671 | tw32(TG3_CPMU_DRV_STATUS, status); |
| 2672 | |
| 2673 | return status >> TG3_APE_GPIO_MSG_SHIFT; |
| 2674 | } |
| 2675 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2676 | static inline int tg3_pwrsrc_switch_to_vmain(struct tg3 *tp) |
| 2677 | { |
| 2678 | if (!tg3_flag(tp, IS_NIC)) |
| 2679 | return 0; |
| 2680 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2681 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2682 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 2683 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 2684 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2685 | return -EIO; |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2686 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2687 | tg3_set_function_status(tp, TG3_GPIO_MSG_DRVR_PRES); |
| 2688 | |
| 2689 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2690 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2691 | |
| 2692 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
| 2693 | } else { |
| 2694 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2695 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2696 | } |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2697 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2698 | return 0; |
| 2699 | } |
| 2700 | |
| 2701 | static void tg3_pwrsrc_die_with_vmain(struct tg3 *tp) |
| 2702 | { |
| 2703 | u32 grc_local_ctrl; |
| 2704 | |
| 2705 | if (!tg3_flag(tp, IS_NIC) || |
| 2706 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2707 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) |
| 2708 | return; |
| 2709 | |
| 2710 | grc_local_ctrl = tp->grc_local_ctrl | GRC_LCLCTRL_GPIO_OE1; |
| 2711 | |
| 2712 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2713 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2714 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2715 | |
| 2716 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2717 | grc_local_ctrl, |
| 2718 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2719 | |
| 2720 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2721 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2722 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2723 | } |
| 2724 | |
| 2725 | static void tg3_pwrsrc_switch_to_vaux(struct tg3 *tp) |
| 2726 | { |
| 2727 | if (!tg3_flag(tp, IS_NIC)) |
| 2728 | return; |
| 2729 | |
| 2730 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2731 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 2732 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2733 | (GRC_LCLCTRL_GPIO_OE0 | |
| 2734 | GRC_LCLCTRL_GPIO_OE1 | |
| 2735 | GRC_LCLCTRL_GPIO_OE2 | |
| 2736 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2737 | GRC_LCLCTRL_GPIO_OUTPUT1), |
| 2738 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2739 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 2740 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
| 2741 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
| 2742 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | |
| 2743 | GRC_LCLCTRL_GPIO_OE1 | |
| 2744 | GRC_LCLCTRL_GPIO_OE2 | |
| 2745 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2746 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2747 | tp->grc_local_ctrl; |
| 2748 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2749 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2750 | |
| 2751 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2752 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2753 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2754 | |
| 2755 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2756 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2757 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2758 | } else { |
| 2759 | u32 no_gpio2; |
| 2760 | u32 grc_local_ctrl = 0; |
| 2761 | |
| 2762 | /* Workaround to prevent overdrawing Amps. */ |
| 2763 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 2764 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
| 2765 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2766 | grc_local_ctrl, |
| 2767 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2768 | } |
| 2769 | |
| 2770 | /* On 5753 and variants, GPIO2 cannot be used. */ |
| 2771 | no_gpio2 = tp->nic_sram_data_cfg & |
| 2772 | NIC_SRAM_DATA_CFG_NO_GPIO2; |
| 2773 | |
| 2774 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 2775 | GRC_LCLCTRL_GPIO_OE1 | |
| 2776 | GRC_LCLCTRL_GPIO_OE2 | |
| 2777 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2778 | GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2779 | if (no_gpio2) { |
| 2780 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | |
| 2781 | GRC_LCLCTRL_GPIO_OUTPUT2); |
| 2782 | } |
| 2783 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2784 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2785 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2786 | |
| 2787 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2788 | |
| 2789 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2790 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2791 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2792 | |
| 2793 | if (!no_gpio2) { |
| 2794 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2795 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2796 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2797 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2798 | } |
| 2799 | } |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2800 | } |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2801 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2802 | 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] | 2803 | { |
| 2804 | u32 msg = 0; |
| 2805 | |
| 2806 | /* Serialize power state transitions */ |
| 2807 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2808 | return; |
| 2809 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2810 | 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] | 2811 | msg = TG3_GPIO_MSG_NEED_VAUX; |
| 2812 | |
| 2813 | msg = tg3_set_function_status(tp, msg); |
| 2814 | |
| 2815 | if (msg & TG3_GPIO_MSG_ALL_DRVR_PRES_MASK) |
| 2816 | goto done; |
| 2817 | |
| 2818 | if (msg & TG3_GPIO_MSG_ALL_NEED_VAUX_MASK) |
| 2819 | tg3_pwrsrc_switch_to_vaux(tp); |
| 2820 | else |
| 2821 | tg3_pwrsrc_die_with_vmain(tp); |
| 2822 | |
| 2823 | done: |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2824 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2827 | static void tg3_frob_aux_power(struct tg3 *tp, bool include_wol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | { |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2829 | bool need_vaux = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2831 | /* The GPIOs do something completely different on 57765. */ |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 2832 | if (!tg3_flag(tp, IS_NIC) || tg3_flag(tp, 57765_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | return; |
| 2834 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2835 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2836 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 2837 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2838 | tg3_frob_aux_power_5717(tp, include_wol ? |
| 2839 | tg3_flag(tp, WOL_ENABLE) != 0 : 0); |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2840 | return; |
| 2841 | } |
| 2842 | |
| 2843 | if (tp->pdev_peer && tp->pdev_peer != tp->pdev) { |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2844 | struct net_device *dev_peer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2846 | dev_peer = pci_get_drvdata(tp->pdev_peer); |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2847 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2848 | /* remove_one() may have been run on the peer. */ |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2849 | if (dev_peer) { |
| 2850 | struct tg3 *tp_peer = netdev_priv(dev_peer); |
| 2851 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2852 | if (tg3_flag(tp_peer, INIT_COMPLETE)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2853 | return; |
| 2854 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2855 | if ((include_wol && tg3_flag(tp_peer, WOL_ENABLE)) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2856 | tg3_flag(tp_peer, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2857 | need_vaux = true; |
| 2858 | } |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2861 | if ((include_wol && tg3_flag(tp, WOL_ENABLE)) || |
| 2862 | tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2863 | need_vaux = true; |
| 2864 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2865 | if (need_vaux) |
| 2866 | tg3_pwrsrc_switch_to_vaux(tp); |
| 2867 | else |
| 2868 | tg3_pwrsrc_die_with_vmain(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2871 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
| 2872 | { |
| 2873 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) |
| 2874 | return 1; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2875 | 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] | 2876 | if (speed != SPEED_10) |
| 2877 | return 1; |
| 2878 | } else if (speed == SPEED_10) |
| 2879 | return 1; |
| 2880 | |
| 2881 | return 0; |
| 2882 | } |
| 2883 | |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2884 | 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] | 2885 | { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2886 | u32 val; |
| 2887 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2888 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2889 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2890 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 2891 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); |
| 2892 | |
| 2893 | sg_dig_ctrl |= |
| 2894 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; |
| 2895 | tw32(SG_DIG_CTRL, sg_dig_ctrl); |
| 2896 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); |
| 2897 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2898 | return; |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2899 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2900 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2901 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2902 | tg3_bmcr_reset(tp); |
| 2903 | val = tr32(GRC_MISC_CFG); |
| 2904 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); |
| 2905 | udelay(40); |
| 2906 | return; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2907 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 0e5f784 | 2009-11-02 14:26:38 +0000 | [diff] [blame] | 2908 | u32 phytest; |
| 2909 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2910 | u32 phy; |
| 2911 | |
| 2912 | tg3_writephy(tp, MII_ADVERTISE, 0); |
| 2913 | tg3_writephy(tp, MII_BMCR, |
| 2914 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 2915 | |
| 2916 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2917 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2918 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { |
| 2919 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; |
| 2920 | tg3_writephy(tp, |
| 2921 | MII_TG3_FET_SHDW_AUXMODE4, |
| 2922 | phy); |
| 2923 | } |
| 2924 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2925 | } |
| 2926 | return; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2927 | } else if (do_low_power) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2928 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 2929 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2930 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2931 | val = MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 2932 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | |
| 2933 | MII_TG3_AUXCTL_PCTL_VREG_11V; |
| 2934 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, val); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2935 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2936 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2937 | /* The PHY should not be powered down on some chips because |
| 2938 | * of bugs. |
| 2939 | */ |
| 2940 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2941 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2942 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && |
Matt Carlson | 085f1af | 2012-04-02 09:01:40 +0000 | [diff] [blame] | 2943 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) || |
| 2944 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 && |
| 2945 | !tp->pci_fn)) |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2946 | return; |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2947 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2948 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2949 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2950 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2951 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2952 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; |
| 2953 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2954 | } |
| 2955 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2956 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 2957 | } |
| 2958 | |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2959 | /* tp->lock is held. */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2960 | static int tg3_nvram_lock(struct tg3 *tp) |
| 2961 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2962 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2963 | int i; |
| 2964 | |
| 2965 | if (tp->nvram_lock_cnt == 0) { |
| 2966 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); |
| 2967 | for (i = 0; i < 8000; i++) { |
| 2968 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) |
| 2969 | break; |
| 2970 | udelay(20); |
| 2971 | } |
| 2972 | if (i == 8000) { |
| 2973 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2974 | return -ENODEV; |
| 2975 | } |
| 2976 | } |
| 2977 | tp->nvram_lock_cnt++; |
| 2978 | } |
| 2979 | return 0; |
| 2980 | } |
| 2981 | |
| 2982 | /* tp->lock is held. */ |
| 2983 | static void tg3_nvram_unlock(struct tg3 *tp) |
| 2984 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2985 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2986 | if (tp->nvram_lock_cnt > 0) |
| 2987 | tp->nvram_lock_cnt--; |
| 2988 | if (tp->nvram_lock_cnt == 0) |
| 2989 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | /* tp->lock is held. */ |
| 2994 | static void tg3_enable_nvram_access(struct tg3 *tp) |
| 2995 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2996 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2997 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2998 | |
| 2999 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); |
| 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | /* tp->lock is held. */ |
| 3004 | static void tg3_disable_nvram_access(struct tg3 *tp) |
| 3005 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3006 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3007 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 3008 | |
| 3009 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); |
| 3010 | } |
| 3011 | } |
| 3012 | |
| 3013 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, |
| 3014 | u32 offset, u32 *val) |
| 3015 | { |
| 3016 | u32 tmp; |
| 3017 | int i; |
| 3018 | |
| 3019 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) |
| 3020 | return -EINVAL; |
| 3021 | |
| 3022 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | |
| 3023 | EEPROM_ADDR_DEVID_MASK | |
| 3024 | EEPROM_ADDR_READ); |
| 3025 | tw32(GRC_EEPROM_ADDR, |
| 3026 | tmp | |
| 3027 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 3028 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & |
| 3029 | EEPROM_ADDR_ADDR_MASK) | |
| 3030 | EEPROM_ADDR_READ | EEPROM_ADDR_START); |
| 3031 | |
| 3032 | for (i = 0; i < 1000; i++) { |
| 3033 | tmp = tr32(GRC_EEPROM_ADDR); |
| 3034 | |
| 3035 | if (tmp & EEPROM_ADDR_COMPLETE) |
| 3036 | break; |
| 3037 | msleep(1); |
| 3038 | } |
| 3039 | if (!(tmp & EEPROM_ADDR_COMPLETE)) |
| 3040 | return -EBUSY; |
| 3041 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 3042 | tmp = tr32(GRC_EEPROM_DATA); |
| 3043 | |
| 3044 | /* |
| 3045 | * The data will always be opposite the native endian |
| 3046 | * format. Perform a blind byteswap to compensate. |
| 3047 | */ |
| 3048 | *val = swab32(tmp); |
| 3049 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3050 | return 0; |
| 3051 | } |
| 3052 | |
| 3053 | #define NVRAM_CMD_TIMEOUT 10000 |
| 3054 | |
| 3055 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) |
| 3056 | { |
| 3057 | int i; |
| 3058 | |
| 3059 | tw32(NVRAM_CMD, nvram_cmd); |
| 3060 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { |
| 3061 | udelay(10); |
| 3062 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { |
| 3063 | udelay(10); |
| 3064 | break; |
| 3065 | } |
| 3066 | } |
| 3067 | |
| 3068 | if (i == NVRAM_CMD_TIMEOUT) |
| 3069 | return -EBUSY; |
| 3070 | |
| 3071 | return 0; |
| 3072 | } |
| 3073 | |
| 3074 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) |
| 3075 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3076 | if (tg3_flag(tp, NVRAM) && |
| 3077 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 3078 | tg3_flag(tp, FLASH) && |
| 3079 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3080 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 3081 | |
| 3082 | addr = ((addr / tp->nvram_pagesize) << |
| 3083 | ATMEL_AT45DB0X1B_PAGE_POS) + |
| 3084 | (addr % tp->nvram_pagesize); |
| 3085 | |
| 3086 | return addr; |
| 3087 | } |
| 3088 | |
| 3089 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) |
| 3090 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3091 | if (tg3_flag(tp, NVRAM) && |
| 3092 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 3093 | tg3_flag(tp, FLASH) && |
| 3094 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3095 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 3096 | |
| 3097 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * |
| 3098 | tp->nvram_pagesize) + |
| 3099 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); |
| 3100 | |
| 3101 | return addr; |
| 3102 | } |
| 3103 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 3104 | /* NOTE: Data read in from NVRAM is byteswapped according to |
| 3105 | * the byteswapping settings for all other register accesses. |
| 3106 | * tg3 devices are BE devices, so on a BE machine, the data |
| 3107 | * returned will be exactly as it is seen in NVRAM. On a LE |
| 3108 | * machine, the 32-bit value will be byteswapped. |
| 3109 | */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3110 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
| 3111 | { |
| 3112 | int ret; |
| 3113 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3114 | if (!tg3_flag(tp, NVRAM)) |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3115 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
| 3116 | |
| 3117 | offset = tg3_nvram_phys_addr(tp, offset); |
| 3118 | |
| 3119 | if (offset > NVRAM_ADDR_MSK) |
| 3120 | return -EINVAL; |
| 3121 | |
| 3122 | ret = tg3_nvram_lock(tp); |
| 3123 | if (ret) |
| 3124 | return ret; |
| 3125 | |
| 3126 | tg3_enable_nvram_access(tp); |
| 3127 | |
| 3128 | tw32(NVRAM_ADDR, offset); |
| 3129 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | |
| 3130 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); |
| 3131 | |
| 3132 | if (ret == 0) |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 3133 | *val = tr32(NVRAM_RDDATA); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3134 | |
| 3135 | tg3_disable_nvram_access(tp); |
| 3136 | |
| 3137 | tg3_nvram_unlock(tp); |
| 3138 | |
| 3139 | return ret; |
| 3140 | } |
| 3141 | |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 3142 | /* Ensures NVRAM data is in bytestream format. */ |
| 3143 | 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] | 3144 | { |
| 3145 | u32 v; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 3146 | int res = tg3_nvram_read(tp, offset, &v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3147 | if (!res) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 3148 | *val = cpu_to_be32(v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3149 | return res; |
| 3150 | } |
| 3151 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3152 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
| 3153 | u32 offset, u32 len, u8 *buf) |
| 3154 | { |
| 3155 | int i, j, rc = 0; |
| 3156 | u32 val; |
| 3157 | |
| 3158 | for (i = 0; i < len; i += 4) { |
| 3159 | u32 addr; |
| 3160 | __be32 data; |
| 3161 | |
| 3162 | addr = offset + i; |
| 3163 | |
| 3164 | memcpy(&data, buf + i, 4); |
| 3165 | |
| 3166 | /* |
| 3167 | * The SEEPROM interface expects the data to always be opposite |
| 3168 | * the native endian format. We accomplish this by reversing |
| 3169 | * all the operations that would have been performed on the |
| 3170 | * data from a call to tg3_nvram_read_be32(). |
| 3171 | */ |
| 3172 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); |
| 3173 | |
| 3174 | val = tr32(GRC_EEPROM_ADDR); |
| 3175 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); |
| 3176 | |
| 3177 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | |
| 3178 | EEPROM_ADDR_READ); |
| 3179 | tw32(GRC_EEPROM_ADDR, val | |
| 3180 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 3181 | (addr & EEPROM_ADDR_ADDR_MASK) | |
| 3182 | EEPROM_ADDR_START | |
| 3183 | EEPROM_ADDR_WRITE); |
| 3184 | |
| 3185 | for (j = 0; j < 1000; j++) { |
| 3186 | val = tr32(GRC_EEPROM_ADDR); |
| 3187 | |
| 3188 | if (val & EEPROM_ADDR_COMPLETE) |
| 3189 | break; |
| 3190 | msleep(1); |
| 3191 | } |
| 3192 | if (!(val & EEPROM_ADDR_COMPLETE)) { |
| 3193 | rc = -EBUSY; |
| 3194 | break; |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | return rc; |
| 3199 | } |
| 3200 | |
| 3201 | /* offset and length are dword aligned */ |
| 3202 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, |
| 3203 | u8 *buf) |
| 3204 | { |
| 3205 | int ret = 0; |
| 3206 | u32 pagesize = tp->nvram_pagesize; |
| 3207 | u32 pagemask = pagesize - 1; |
| 3208 | u32 nvram_cmd; |
| 3209 | u8 *tmp; |
| 3210 | |
| 3211 | tmp = kmalloc(pagesize, GFP_KERNEL); |
| 3212 | if (tmp == NULL) |
| 3213 | return -ENOMEM; |
| 3214 | |
| 3215 | while (len) { |
| 3216 | int j; |
| 3217 | u32 phy_addr, page_off, size; |
| 3218 | |
| 3219 | phy_addr = offset & ~pagemask; |
| 3220 | |
| 3221 | for (j = 0; j < pagesize; j += 4) { |
| 3222 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
| 3223 | (__be32 *) (tmp + j)); |
| 3224 | if (ret) |
| 3225 | break; |
| 3226 | } |
| 3227 | if (ret) |
| 3228 | break; |
| 3229 | |
| 3230 | page_off = offset & pagemask; |
| 3231 | size = pagesize; |
| 3232 | if (len < size) |
| 3233 | size = len; |
| 3234 | |
| 3235 | len -= size; |
| 3236 | |
| 3237 | memcpy(tmp + page_off, buf, size); |
| 3238 | |
| 3239 | offset = offset + (pagesize - page_off); |
| 3240 | |
| 3241 | tg3_enable_nvram_access(tp); |
| 3242 | |
| 3243 | /* |
| 3244 | * Before we can erase the flash page, we need |
| 3245 | * to issue a special "write enable" command. |
| 3246 | */ |
| 3247 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3248 | |
| 3249 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3250 | break; |
| 3251 | |
| 3252 | /* Erase the target page */ |
| 3253 | tw32(NVRAM_ADDR, phy_addr); |
| 3254 | |
| 3255 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | |
| 3256 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; |
| 3257 | |
| 3258 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3259 | break; |
| 3260 | |
| 3261 | /* Issue another write enable to start the write. */ |
| 3262 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3263 | |
| 3264 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3265 | break; |
| 3266 | |
| 3267 | for (j = 0; j < pagesize; j += 4) { |
| 3268 | __be32 data; |
| 3269 | |
| 3270 | data = *((__be32 *) (tmp + j)); |
| 3271 | |
| 3272 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3273 | |
| 3274 | tw32(NVRAM_ADDR, phy_addr + j); |
| 3275 | |
| 3276 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | |
| 3277 | NVRAM_CMD_WR; |
| 3278 | |
| 3279 | if (j == 0) |
| 3280 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 3281 | else if (j == (pagesize - 4)) |
| 3282 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3283 | |
| 3284 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3285 | if (ret) |
| 3286 | break; |
| 3287 | } |
| 3288 | if (ret) |
| 3289 | break; |
| 3290 | } |
| 3291 | |
| 3292 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3293 | tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3294 | |
| 3295 | kfree(tmp); |
| 3296 | |
| 3297 | return ret; |
| 3298 | } |
| 3299 | |
| 3300 | /* offset and length are dword aligned */ |
| 3301 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, |
| 3302 | u8 *buf) |
| 3303 | { |
| 3304 | int i, ret = 0; |
| 3305 | |
| 3306 | for (i = 0; i < len; i += 4, offset += 4) { |
| 3307 | u32 page_off, phy_addr, nvram_cmd; |
| 3308 | __be32 data; |
| 3309 | |
| 3310 | memcpy(&data, buf + i, 4); |
| 3311 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3312 | |
| 3313 | page_off = offset % tp->nvram_pagesize; |
| 3314 | |
| 3315 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
| 3316 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3317 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
| 3318 | |
| 3319 | if (page_off == 0 || i == 0) |
| 3320 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 3321 | if (page_off == (tp->nvram_pagesize - 4)) |
| 3322 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3323 | |
| 3324 | if (i == (len - 4)) |
| 3325 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3326 | |
Matt Carlson | 4227822 | 2012-02-13 15:20:11 +0000 | [diff] [blame] | 3327 | if ((nvram_cmd & NVRAM_CMD_FIRST) || |
| 3328 | !tg3_flag(tp, FLASH) || |
| 3329 | !tg3_flag(tp, 57765_PLUS)) |
| 3330 | tw32(NVRAM_ADDR, phy_addr); |
| 3331 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3332 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
| 3333 | !tg3_flag(tp, 5755_PLUS) && |
| 3334 | (tp->nvram_jedecnum == JEDEC_ST) && |
| 3335 | (nvram_cmd & NVRAM_CMD_FIRST)) { |
| 3336 | u32 cmd; |
| 3337 | |
| 3338 | cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3339 | ret = tg3_nvram_exec_cmd(tp, cmd); |
| 3340 | if (ret) |
| 3341 | break; |
| 3342 | } |
| 3343 | if (!tg3_flag(tp, FLASH)) { |
| 3344 | /* We always do complete word writes to eeprom. */ |
| 3345 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); |
| 3346 | } |
| 3347 | |
| 3348 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3349 | if (ret) |
| 3350 | break; |
| 3351 | } |
| 3352 | return ret; |
| 3353 | } |
| 3354 | |
| 3355 | /* offset and length are dword aligned */ |
| 3356 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) |
| 3357 | { |
| 3358 | int ret; |
| 3359 | |
| 3360 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3361 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
| 3362 | ~GRC_LCLCTRL_GPIO_OUTPUT1); |
| 3363 | udelay(40); |
| 3364 | } |
| 3365 | |
| 3366 | if (!tg3_flag(tp, NVRAM)) { |
| 3367 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
| 3368 | } else { |
| 3369 | u32 grc_mode; |
| 3370 | |
| 3371 | ret = tg3_nvram_lock(tp); |
| 3372 | if (ret) |
| 3373 | return ret; |
| 3374 | |
| 3375 | tg3_enable_nvram_access(tp); |
| 3376 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) |
| 3377 | tw32(NVRAM_WRITE1, 0x406); |
| 3378 | |
| 3379 | grc_mode = tr32(GRC_MODE); |
| 3380 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); |
| 3381 | |
| 3382 | if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) { |
| 3383 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
| 3384 | buf); |
| 3385 | } else { |
| 3386 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
| 3387 | buf); |
| 3388 | } |
| 3389 | |
| 3390 | grc_mode = tr32(GRC_MODE); |
| 3391 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); |
| 3392 | |
| 3393 | tg3_disable_nvram_access(tp); |
| 3394 | tg3_nvram_unlock(tp); |
| 3395 | } |
| 3396 | |
| 3397 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3398 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 3399 | udelay(40); |
| 3400 | } |
| 3401 | |
| 3402 | return ret; |
| 3403 | } |
| 3404 | |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3405 | #define RX_CPU_SCRATCH_BASE 0x30000 |
| 3406 | #define RX_CPU_SCRATCH_SIZE 0x04000 |
| 3407 | #define TX_CPU_SCRATCH_BASE 0x34000 |
| 3408 | #define TX_CPU_SCRATCH_SIZE 0x04000 |
| 3409 | |
| 3410 | /* tp->lock is held. */ |
| 3411 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) |
| 3412 | { |
| 3413 | int i; |
| 3414 | |
| 3415 | BUG_ON(offset == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)); |
| 3416 | |
| 3417 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 3418 | u32 val = tr32(GRC_VCPU_EXT_CTRL); |
| 3419 | |
| 3420 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 3421 | return 0; |
| 3422 | } |
| 3423 | if (offset == RX_CPU_BASE) { |
| 3424 | for (i = 0; i < 10000; i++) { |
| 3425 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3426 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 3427 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 3428 | break; |
| 3429 | } |
| 3430 | |
| 3431 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3432 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); |
| 3433 | udelay(10); |
| 3434 | } else { |
| 3435 | for (i = 0; i < 10000; i++) { |
| 3436 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3437 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 3438 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 3439 | break; |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | if (i >= 10000) { |
| 3444 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
| 3445 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); |
| 3446 | return -ENODEV; |
| 3447 | } |
| 3448 | |
| 3449 | /* Clear firmware's nvram arbitration. */ |
| 3450 | if (tg3_flag(tp, NVRAM)) |
| 3451 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
| 3452 | return 0; |
| 3453 | } |
| 3454 | |
| 3455 | struct fw_info { |
| 3456 | unsigned int fw_base; |
| 3457 | unsigned int fw_len; |
| 3458 | const __be32 *fw_data; |
| 3459 | }; |
| 3460 | |
| 3461 | /* tp->lock is held. */ |
| 3462 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, |
| 3463 | u32 cpu_scratch_base, int cpu_scratch_size, |
| 3464 | struct fw_info *info) |
| 3465 | { |
| 3466 | int err, lock_err, i; |
| 3467 | void (*write_op)(struct tg3 *, u32, u32); |
| 3468 | |
| 3469 | if (cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)) { |
| 3470 | netdev_err(tp->dev, |
| 3471 | "%s: Trying to load TX cpu firmware which is 5705\n", |
| 3472 | __func__); |
| 3473 | return -EINVAL; |
| 3474 | } |
| 3475 | |
| 3476 | if (tg3_flag(tp, 5705_PLUS)) |
| 3477 | write_op = tg3_write_mem; |
| 3478 | else |
| 3479 | write_op = tg3_write_indirect_reg32; |
| 3480 | |
| 3481 | /* It is possible that bootcode is still loading at this point. |
| 3482 | * Get the nvram lock first before halting the cpu. |
| 3483 | */ |
| 3484 | lock_err = tg3_nvram_lock(tp); |
| 3485 | err = tg3_halt_cpu(tp, cpu_base); |
| 3486 | if (!lock_err) |
| 3487 | tg3_nvram_unlock(tp); |
| 3488 | if (err) |
| 3489 | goto out; |
| 3490 | |
| 3491 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
| 3492 | write_op(tp, cpu_scratch_base + i, 0); |
| 3493 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3494 | tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT); |
| 3495 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
| 3496 | write_op(tp, (cpu_scratch_base + |
| 3497 | (info->fw_base & 0xffff) + |
| 3498 | (i * sizeof(u32))), |
| 3499 | be32_to_cpu(info->fw_data[i])); |
| 3500 | |
| 3501 | err = 0; |
| 3502 | |
| 3503 | out: |
| 3504 | return err; |
| 3505 | } |
| 3506 | |
| 3507 | /* tp->lock is held. */ |
| 3508 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) |
| 3509 | { |
| 3510 | struct fw_info info; |
| 3511 | const __be32 *fw_data; |
| 3512 | int err, i; |
| 3513 | |
| 3514 | fw_data = (void *)tp->fw->data; |
| 3515 | |
| 3516 | /* Firmware blob starts with version numbers, followed by |
| 3517 | start address and length. We are setting complete length. |
| 3518 | length = end_address_of_bss - start_address_of_text. |
| 3519 | Remainder is the blob to be loaded contiguously |
| 3520 | from start address. */ |
| 3521 | |
| 3522 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 3523 | info.fw_len = tp->fw->size - 12; |
| 3524 | info.fw_data = &fw_data[3]; |
| 3525 | |
| 3526 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
| 3527 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, |
| 3528 | &info); |
| 3529 | if (err) |
| 3530 | return err; |
| 3531 | |
| 3532 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, |
| 3533 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, |
| 3534 | &info); |
| 3535 | if (err) |
| 3536 | return err; |
| 3537 | |
| 3538 | /* Now startup only the RX cpu. */ |
| 3539 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3540 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
| 3541 | |
| 3542 | for (i = 0; i < 5; i++) { |
| 3543 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
| 3544 | break; |
| 3545 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3546 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); |
| 3547 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
| 3548 | udelay(1000); |
| 3549 | } |
| 3550 | if (i >= 5) { |
| 3551 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
| 3552 | "should be %08x\n", __func__, |
| 3553 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
| 3554 | return -ENODEV; |
| 3555 | } |
| 3556 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3557 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); |
| 3558 | |
| 3559 | return 0; |
| 3560 | } |
| 3561 | |
| 3562 | /* tp->lock is held. */ |
| 3563 | static int tg3_load_tso_firmware(struct tg3 *tp) |
| 3564 | { |
| 3565 | struct fw_info info; |
| 3566 | const __be32 *fw_data; |
| 3567 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
| 3568 | int err, i; |
| 3569 | |
| 3570 | if (tg3_flag(tp, HW_TSO_1) || |
| 3571 | tg3_flag(tp, HW_TSO_2) || |
| 3572 | tg3_flag(tp, HW_TSO_3)) |
| 3573 | return 0; |
| 3574 | |
| 3575 | fw_data = (void *)tp->fw->data; |
| 3576 | |
| 3577 | /* Firmware blob starts with version numbers, followed by |
| 3578 | start address and length. We are setting complete length. |
| 3579 | length = end_address_of_bss - start_address_of_text. |
| 3580 | Remainder is the blob to be loaded contiguously |
| 3581 | from start address. */ |
| 3582 | |
| 3583 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 3584 | cpu_scratch_size = tp->fw_len; |
| 3585 | info.fw_len = tp->fw->size - 12; |
| 3586 | info.fw_data = &fw_data[3]; |
| 3587 | |
| 3588 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 3589 | cpu_base = RX_CPU_BASE; |
| 3590 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; |
| 3591 | } else { |
| 3592 | cpu_base = TX_CPU_BASE; |
| 3593 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; |
| 3594 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; |
| 3595 | } |
| 3596 | |
| 3597 | err = tg3_load_firmware_cpu(tp, cpu_base, |
| 3598 | cpu_scratch_base, cpu_scratch_size, |
| 3599 | &info); |
| 3600 | if (err) |
| 3601 | return err; |
| 3602 | |
| 3603 | /* Now startup the cpu. */ |
| 3604 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3605 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
| 3606 | |
| 3607 | for (i = 0; i < 5; i++) { |
| 3608 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
| 3609 | break; |
| 3610 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3611 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
| 3612 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
| 3613 | udelay(1000); |
| 3614 | } |
| 3615 | if (i >= 5) { |
| 3616 | netdev_err(tp->dev, |
| 3617 | "%s fails to set CPU PC, is %08x should be %08x\n", |
| 3618 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
| 3619 | return -ENODEV; |
| 3620 | } |
| 3621 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3622 | tw32_f(cpu_base + CPU_MODE, 0x00000000); |
| 3623 | return 0; |
| 3624 | } |
| 3625 | |
| 3626 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3627 | /* tp->lock is held. */ |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 3628 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) |
| 3629 | { |
| 3630 | u32 addr_high, addr_low; |
| 3631 | int i; |
| 3632 | |
| 3633 | addr_high = ((tp->dev->dev_addr[0] << 8) | |
| 3634 | tp->dev->dev_addr[1]); |
| 3635 | addr_low = ((tp->dev->dev_addr[2] << 24) | |
| 3636 | (tp->dev->dev_addr[3] << 16) | |
| 3637 | (tp->dev->dev_addr[4] << 8) | |
| 3638 | (tp->dev->dev_addr[5] << 0)); |
| 3639 | for (i = 0; i < 4; i++) { |
| 3640 | if (i == 1 && skip_mac_1) |
| 3641 | continue; |
| 3642 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); |
| 3643 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); |
| 3644 | } |
| 3645 | |
| 3646 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 3647 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 3648 | for (i = 0; i < 12; i++) { |
| 3649 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); |
| 3650 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); |
| 3651 | } |
| 3652 | } |
| 3653 | |
| 3654 | addr_high = (tp->dev->dev_addr[0] + |
| 3655 | tp->dev->dev_addr[1] + |
| 3656 | tp->dev->dev_addr[2] + |
| 3657 | tp->dev->dev_addr[3] + |
| 3658 | tp->dev->dev_addr[4] + |
| 3659 | tp->dev->dev_addr[5]) & |
| 3660 | TX_BACKOFF_SEED_MASK; |
| 3661 | tw32(MAC_TX_BACKOFF_SEED, addr_high); |
| 3662 | } |
| 3663 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3664 | static void tg3_enable_register_access(struct tg3 *tp) |
| 3665 | { |
| 3666 | /* |
| 3667 | * Make sure register accesses (indirect or otherwise) will function |
| 3668 | * correctly. |
| 3669 | */ |
| 3670 | pci_write_config_dword(tp->pdev, |
| 3671 | TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl); |
| 3672 | } |
| 3673 | |
| 3674 | static int tg3_power_up(struct tg3 *tp) |
| 3675 | { |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3676 | int err; |
| 3677 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3678 | tg3_enable_register_access(tp); |
| 3679 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3680 | err = pci_set_power_state(tp->pdev, PCI_D0); |
| 3681 | if (!err) { |
| 3682 | /* Switch out of Vaux if it is a NIC */ |
| 3683 | tg3_pwrsrc_switch_to_vmain(tp); |
| 3684 | } else { |
| 3685 | netdev_err(tp->dev, "Transition to D0 failed\n"); |
| 3686 | } |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3687 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3688 | return err; |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3689 | } |
| 3690 | |
Matt Carlson | 4b40952 | 2012-02-13 10:20:11 +0000 | [diff] [blame] | 3691 | static int tg3_setup_phy(struct tg3 *, int); |
| 3692 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3693 | static int tg3_power_down_prepare(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | { |
| 3695 | u32 misc_host_ctrl; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3696 | bool device_should_wake, do_low_power; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3698 | tg3_enable_register_access(tp); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3699 | |
| 3700 | /* Restore the CLKREQ setting. */ |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 3701 | if (tg3_flag(tp, CLKREQ_BUG)) |
| 3702 | pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL, |
| 3703 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 3706 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 3707 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); |
| 3708 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3709 | device_should_wake = device_may_wakeup(&tp->pdev->dev) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3710 | tg3_flag(tp, WOL_ENABLE); |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3711 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3712 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3713 | do_low_power = false; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3714 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3715 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3716 | struct phy_device *phydev; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3717 | u32 phyid, advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3718 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 3719 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3720 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3721 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3722 | |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 3723 | tp->link_config.speed = phydev->speed; |
| 3724 | tp->link_config.duplex = phydev->duplex; |
| 3725 | tp->link_config.autoneg = phydev->autoneg; |
| 3726 | tp->link_config.advertising = phydev->advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3727 | |
| 3728 | advertising = ADVERTISED_TP | |
| 3729 | ADVERTISED_Pause | |
| 3730 | ADVERTISED_Autoneg | |
| 3731 | ADVERTISED_10baseT_Half; |
| 3732 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3733 | if (tg3_flag(tp, ENABLE_ASF) || device_should_wake) { |
| 3734 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3735 | advertising |= |
| 3736 | ADVERTISED_100baseT_Half | |
| 3737 | ADVERTISED_100baseT_Full | |
| 3738 | ADVERTISED_10baseT_Full; |
| 3739 | else |
| 3740 | advertising |= ADVERTISED_10baseT_Full; |
| 3741 | } |
| 3742 | |
| 3743 | phydev->advertising = advertising; |
| 3744 | |
| 3745 | phy_start_aneg(phydev); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3746 | |
| 3747 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 3748 | if (phyid != PHY_ID_BCMAC131) { |
| 3749 | phyid &= PHY_BCM_OUI_MASK; |
| 3750 | if (phyid == PHY_BCM_OUI_1 || |
| 3751 | phyid == PHY_BCM_OUI_2 || |
| 3752 | phyid == PHY_BCM_OUI_3) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3753 | do_low_power = true; |
| 3754 | } |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3755 | } |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3756 | } else { |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 3757 | do_low_power = true; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3758 | |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 3759 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3760 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | |
Matt Carlson | 2855b9f | 2012-02-13 15:20:14 +0000 | [diff] [blame] | 3762 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3763 | tg3_setup_phy(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | } |
| 3765 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 3766 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 3767 | u32 val; |
| 3768 | |
| 3769 | val = tr32(GRC_VCPU_EXT_CTRL); |
| 3770 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3771 | } else if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3772 | int i; |
| 3773 | u32 val; |
| 3774 | |
| 3775 | for (i = 0; i < 200; i++) { |
| 3776 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); |
| 3777 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 3778 | break; |
| 3779 | msleep(1); |
| 3780 | } |
| 3781 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3782 | if (tg3_flag(tp, WOL_CAP)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 3783 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
| 3784 | WOL_DRV_STATE_SHUTDOWN | |
| 3785 | WOL_DRV_WOL | |
| 3786 | WOL_SET_MAGIC_PKT); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3787 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3788 | if (device_should_wake) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | u32 mac_mode; |
| 3790 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3791 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 3792 | if (do_low_power && |
| 3793 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 3794 | tg3_phy_auxctl_write(tp, |
| 3795 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL, |
| 3796 | MII_TG3_AUXCTL_PCTL_WOL_EN | |
| 3797 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 3798 | MII_TG3_AUXCTL_PCTL_CL_AB_TXDAC); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3799 | udelay(40); |
| 3800 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3802 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 3803 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 3804 | else |
| 3805 | mac_mode = MAC_MODE_PORT_MODE_MII; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3807 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
| 3808 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 3809 | ASIC_REV_5700) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3810 | u32 speed = tg3_flag(tp, WOL_SPEED_100MB) ? |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3811 | SPEED_100 : SPEED_10; |
| 3812 | if (tg3_5700_link_polarity(tp, speed)) |
| 3813 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 3814 | else |
| 3815 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 3816 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | } else { |
| 3818 | mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 3819 | } |
| 3820 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3821 | if (!tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 3823 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3824 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3825 | if ((tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) && |
| 3826 | (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE))) |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3827 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3829 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 3830 | mac_mode |= MAC_MODE_APE_TX_EN | |
| 3831 | MAC_MODE_APE_RX_EN | |
| 3832 | MAC_MODE_TDE_ENABLE; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 3833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | tw32_f(MAC_MODE, mac_mode); |
| 3835 | udelay(100); |
| 3836 | |
| 3837 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); |
| 3838 | udelay(10); |
| 3839 | } |
| 3840 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3841 | if (!tg3_flag(tp, WOL_SPEED_100MB) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3843 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 3844 | u32 base_val; |
| 3845 | |
| 3846 | base_val = tp->pci_clock_ctrl; |
| 3847 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | |
| 3848 | CLOCK_CTRL_TXCLK_DISABLE); |
| 3849 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3850 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
| 3851 | CLOCK_CTRL_PWRDOWN_PLL133, 40); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3852 | } else if (tg3_flag(tp, 5780_CLASS) || |
| 3853 | tg3_flag(tp, CPMU_PRESENT) || |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 3854 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 3855 | /* do nothing */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3856 | } else if (!(tg3_flag(tp, 5750_PLUS) && tg3_flag(tp, ENABLE_ASF))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | u32 newbits1, newbits2; |
| 3858 | |
| 3859 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3860 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3861 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 3862 | CLOCK_CTRL_TXCLK_DISABLE | |
| 3863 | CLOCK_CTRL_ALTCLK); |
| 3864 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3865 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | newbits1 = CLOCK_CTRL_625_CORE; |
| 3867 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; |
| 3868 | } else { |
| 3869 | newbits1 = CLOCK_CTRL_ALTCLK; |
| 3870 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 3871 | } |
| 3872 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3873 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
| 3874 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3876 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
| 3877 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3879 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | u32 newbits3; |
| 3881 | |
| 3882 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3883 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3884 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 3885 | CLOCK_CTRL_TXCLK_DISABLE | |
| 3886 | CLOCK_CTRL_44MHZ_CORE); |
| 3887 | } else { |
| 3888 | newbits3 = CLOCK_CTRL_44MHZ_CORE; |
| 3889 | } |
| 3890 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3891 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 3892 | tp->pci_clock_ctrl | newbits3, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | } |
| 3894 | } |
| 3895 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3896 | if (!(device_should_wake) && !tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3897 | tg3_power_down_phy(tp, do_low_power); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3898 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 3899 | tg3_frob_aux_power(tp, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | |
| 3901 | /* Workaround for unstable PLL clock */ |
| 3902 | if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) || |
| 3903 | (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) { |
| 3904 | u32 val = tr32(0x7d00); |
| 3905 | |
| 3906 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); |
| 3907 | tw32(0x7d00, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3908 | if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 3909 | int err; |
| 3910 | |
| 3911 | err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 3913 | if (!err) |
| 3914 | tg3_nvram_unlock(tp); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3915 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 3918 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
| 3919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | return 0; |
| 3921 | } |
| 3922 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3923 | static void tg3_power_down(struct tg3 *tp) |
| 3924 | { |
| 3925 | tg3_power_down_prepare(tp); |
| 3926 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3927 | pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3928 | pci_set_power_state(tp->pdev, PCI_D3hot); |
| 3929 | } |
| 3930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
| 3932 | { |
| 3933 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { |
| 3934 | case MII_TG3_AUX_STAT_10HALF: |
| 3935 | *speed = SPEED_10; |
| 3936 | *duplex = DUPLEX_HALF; |
| 3937 | break; |
| 3938 | |
| 3939 | case MII_TG3_AUX_STAT_10FULL: |
| 3940 | *speed = SPEED_10; |
| 3941 | *duplex = DUPLEX_FULL; |
| 3942 | break; |
| 3943 | |
| 3944 | case MII_TG3_AUX_STAT_100HALF: |
| 3945 | *speed = SPEED_100; |
| 3946 | *duplex = DUPLEX_HALF; |
| 3947 | break; |
| 3948 | |
| 3949 | case MII_TG3_AUX_STAT_100FULL: |
| 3950 | *speed = SPEED_100; |
| 3951 | *duplex = DUPLEX_FULL; |
| 3952 | break; |
| 3953 | |
| 3954 | case MII_TG3_AUX_STAT_1000HALF: |
| 3955 | *speed = SPEED_1000; |
| 3956 | *duplex = DUPLEX_HALF; |
| 3957 | break; |
| 3958 | |
| 3959 | case MII_TG3_AUX_STAT_1000FULL: |
| 3960 | *speed = SPEED_1000; |
| 3961 | *duplex = DUPLEX_FULL; |
| 3962 | break; |
| 3963 | |
| 3964 | default: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3965 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 3966 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
| 3967 | SPEED_10; |
| 3968 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : |
| 3969 | DUPLEX_HALF; |
| 3970 | break; |
| 3971 | } |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 3972 | *speed = SPEED_UNKNOWN; |
| 3973 | *duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3975 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | } |
| 3977 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3978 | 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] | 3979 | { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3980 | int err = 0; |
| 3981 | u32 val, new_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3983 | new_adv = ADVERTISE_CSMA; |
Hiroaki SHIMODA | 202ff1c | 2011-11-22 04:05:41 +0000 | [diff] [blame] | 3984 | new_adv |= ethtool_adv_to_mii_adv_t(advertise) & ADVERTISE_ALL; |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 3985 | new_adv |= mii_advertise_flowctrl(flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3987 | err = tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 3988 | if (err) |
| 3989 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 3991 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 3992 | new_adv = ethtool_adv_to_mii_ctrl1000_t(advertise); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 3993 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 3994 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 3995 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) |
| 3996 | new_adv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 3997 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 3998 | err = tg3_writephy(tp, MII_CTRL1000, new_adv); |
| 3999 | if (err) |
| 4000 | goto done; |
| 4001 | } |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4002 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4003 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 4004 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4006 | tw32(TG3_CPMU_EEE_MODE, |
| 4007 | tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4008 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4009 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
| 4010 | if (!err) { |
| 4011 | u32 err2; |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4012 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 4013 | val = 0; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4014 | /* Advertise 100-BaseTX EEE ability */ |
| 4015 | if (advertise & ADVERTISED_100baseT_Full) |
| 4016 | val |= MDIO_AN_EEE_ADV_100TX; |
| 4017 | /* Advertise 1000-BaseT EEE ability */ |
| 4018 | if (advertise & ADVERTISED_1000baseT_Full) |
| 4019 | val |= MDIO_AN_EEE_ADV_1000T; |
| 4020 | 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] | 4021 | if (err) |
| 4022 | val = 0; |
| 4023 | |
| 4024 | switch (GET_ASIC_REV(tp->pci_chip_rev_id)) { |
| 4025 | case ASIC_REV_5717: |
| 4026 | case ASIC_REV_57765: |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 4027 | case ASIC_REV_57766: |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 4028 | case ASIC_REV_5719: |
| 4029 | /* If we advertised any eee advertisements above... */ |
| 4030 | if (val) |
| 4031 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 4032 | MII_TG3_DSP_TAP26_RMRXSTO | |
| 4033 | MII_TG3_DSP_TAP26_OPCSINPT; |
| 4034 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
| 4035 | /* Fall through */ |
| 4036 | case ASIC_REV_5720: |
| 4037 | if (!tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) |
| 4038 | tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, val | |
| 4039 | MII_TG3_DSP_CH34TP2_HIBW01); |
| 4040 | } |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4041 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4042 | err2 = TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 4043 | if (!err) |
| 4044 | err = err2; |
| 4045 | } |
| 4046 | |
| 4047 | done: |
| 4048 | return err; |
| 4049 | } |
| 4050 | |
| 4051 | static void tg3_phy_copper_begin(struct tg3 *tp) |
| 4052 | { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4053 | if (tp->link_config.autoneg == AUTONEG_ENABLE || |
| 4054 | (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 4055 | u32 adv, fc; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4056 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4057 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 4058 | adv = ADVERTISED_10baseT_Half | |
| 4059 | ADVERTISED_10baseT_Full; |
| 4060 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
| 4061 | adv |= ADVERTISED_100baseT_Half | |
| 4062 | ADVERTISED_100baseT_Full; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4063 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4064 | fc = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4065 | } else { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4066 | adv = tp->link_config.advertising; |
| 4067 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 4068 | adv &= ~(ADVERTISED_1000baseT_Half | |
| 4069 | ADVERTISED_1000baseT_Full); |
| 4070 | |
| 4071 | fc = tp->link_config.flowctrl; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4072 | } |
| 4073 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4074 | tg3_phy_autoneg_cfg(tp, adv, fc); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4075 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4076 | tg3_writephy(tp, MII_BMCR, |
| 4077 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 4078 | } else { |
| 4079 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | u32 bmcr, orig_bmcr; |
| 4081 | |
| 4082 | tp->link_config.active_speed = tp->link_config.speed; |
| 4083 | tp->link_config.active_duplex = tp->link_config.duplex; |
| 4084 | |
| 4085 | bmcr = 0; |
| 4086 | switch (tp->link_config.speed) { |
| 4087 | default: |
| 4088 | case SPEED_10: |
| 4089 | break; |
| 4090 | |
| 4091 | case SPEED_100: |
| 4092 | bmcr |= BMCR_SPEED100; |
| 4093 | break; |
| 4094 | |
| 4095 | case SPEED_1000: |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 4096 | bmcr |= BMCR_SPEED1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4098 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | |
| 4100 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 4101 | bmcr |= BMCR_FULLDPLX; |
| 4102 | |
| 4103 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && |
| 4104 | (bmcr != orig_bmcr)) { |
| 4105 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); |
| 4106 | for (i = 0; i < 1500; i++) { |
| 4107 | u32 tmp; |
| 4108 | |
| 4109 | udelay(10); |
| 4110 | if (tg3_readphy(tp, MII_BMSR, &tmp) || |
| 4111 | tg3_readphy(tp, MII_BMSR, &tmp)) |
| 4112 | continue; |
| 4113 | if (!(tmp & BMSR_LSTATUS)) { |
| 4114 | udelay(40); |
| 4115 | break; |
| 4116 | } |
| 4117 | } |
| 4118 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 4119 | udelay(40); |
| 4120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | } |
| 4122 | } |
| 4123 | |
| 4124 | static int tg3_init_5401phy_dsp(struct tg3 *tp) |
| 4125 | { |
| 4126 | int err; |
| 4127 | |
| 4128 | /* Turn off tap power management. */ |
| 4129 | /* Set Extended packet length bit */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4130 | err = tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 4132 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
| 4133 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); |
| 4134 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); |
| 4135 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); |
| 4136 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | |
| 4138 | udelay(40); |
| 4139 | |
| 4140 | return err; |
| 4141 | } |
| 4142 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4143 | 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] | 4144 | { |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4145 | u32 advmsk, tgtadv, advertising; |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 4146 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4147 | advertising = tp->link_config.advertising; |
| 4148 | tgtadv = ethtool_adv_to_mii_adv_t(advertising) & ADVERTISE_ALL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4150 | advmsk = ADVERTISE_ALL; |
| 4151 | if (tp->link_config.active_duplex == DUPLEX_FULL) { |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 4152 | tgtadv |= mii_advertise_flowctrl(tp->link_config.flowctrl); |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4153 | advmsk |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 4154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4156 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
| 4157 | return false; |
| 4158 | |
| 4159 | if ((*lcladv & advmsk) != tgtadv) |
| 4160 | return false; |
Matt Carlson | b99d2a5 | 2011-08-31 11:44:47 +0000 | [diff] [blame] | 4161 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4162 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | u32 tg3_ctrl; |
| 4164 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4165 | tgtadv = ethtool_adv_to_mii_ctrl1000_t(advertising); |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 4166 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 4167 | if (tg3_readphy(tp, MII_CTRL1000, &tg3_ctrl)) |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4168 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | |
Matt Carlson | 3198e07 | 2012-02-13 15:20:10 +0000 | [diff] [blame] | 4170 | if (tgtadv && |
| 4171 | (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 4172 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)) { |
| 4173 | tgtadv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
| 4174 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL | |
| 4175 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
| 4176 | } else { |
| 4177 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL); |
| 4178 | } |
| 4179 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4180 | if (tg3_ctrl != tgtadv) |
| 4181 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | } |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 4183 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4184 | return true; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4185 | } |
| 4186 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4187 | static bool tg3_phy_copper_fetch_rmtadv(struct tg3 *tp, u32 *rmtadv) |
| 4188 | { |
| 4189 | u32 lpeth = 0; |
| 4190 | |
| 4191 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4192 | u32 val; |
| 4193 | |
| 4194 | if (tg3_readphy(tp, MII_STAT1000, &val)) |
| 4195 | return false; |
| 4196 | |
| 4197 | lpeth = mii_stat1000_to_ethtool_lpa_t(val); |
| 4198 | } |
| 4199 | |
| 4200 | if (tg3_readphy(tp, MII_LPA, rmtadv)) |
| 4201 | return false; |
| 4202 | |
| 4203 | lpeth |= mii_lpa_to_ethtool_lpa_t(*rmtadv); |
| 4204 | tp->link_config.rmt_adv = lpeth; |
| 4205 | |
| 4206 | return true; |
| 4207 | } |
| 4208 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 4209 | static bool tg3_test_and_report_link_chg(struct tg3 *tp, int curr_link_up) |
| 4210 | { |
| 4211 | if (curr_link_up != tp->link_up) { |
| 4212 | if (curr_link_up) { |
| 4213 | tg3_carrier_on(tp); |
| 4214 | } else { |
| 4215 | tg3_carrier_off(tp); |
| 4216 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
| 4217 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 4218 | } |
| 4219 | |
| 4220 | tg3_link_report(tp); |
| 4221 | return true; |
| 4222 | } |
| 4223 | |
| 4224 | return false; |
| 4225 | } |
| 4226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
| 4228 | { |
| 4229 | int current_link_up; |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4230 | u32 bmsr, val; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4231 | u32 lcl_adv, rmt_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | u16 current_speed; |
| 4233 | u8 current_duplex; |
| 4234 | int i, err; |
| 4235 | |
| 4236 | tw32(MAC_EVENT, 0); |
| 4237 | |
| 4238 | tw32_f(MAC_STATUS, |
| 4239 | (MAC_STATUS_SYNC_CHANGED | |
| 4240 | MAC_STATUS_CFG_CHANGED | |
| 4241 | MAC_STATUS_MI_COMPLETION | |
| 4242 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4243 | udelay(40); |
| 4244 | |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 4245 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 4246 | tw32_f(MAC_MI_MODE, |
| 4247 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 4248 | udelay(80); |
| 4249 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4251 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | |
| 4253 | /* Some third-party PHYs need to be reset on link going |
| 4254 | * down. |
| 4255 | */ |
| 4256 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 4257 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 4258 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 4259 | tp->link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4261 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4262 | !(bmsr & BMSR_LSTATUS)) |
| 4263 | force_reset = 1; |
| 4264 | } |
| 4265 | if (force_reset) |
| 4266 | tg3_phy_reset(tp); |
| 4267 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4268 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4270 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4271 | !tg3_flag(tp, INIT_COMPLETE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | bmsr = 0; |
| 4273 | |
| 4274 | if (!(bmsr & BMSR_LSTATUS)) { |
| 4275 | err = tg3_init_5401phy_dsp(tp); |
| 4276 | if (err) |
| 4277 | return err; |
| 4278 | |
| 4279 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4280 | for (i = 0; i < 1000; i++) { |
| 4281 | udelay(10); |
| 4282 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4283 | (bmsr & BMSR_LSTATUS)) { |
| 4284 | udelay(40); |
| 4285 | break; |
| 4286 | } |
| 4287 | } |
| 4288 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4289 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
| 4290 | TG3_PHY_REV_BCM5401_B0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | !(bmsr & BMSR_LSTATUS) && |
| 4292 | tp->link_config.active_speed == SPEED_1000) { |
| 4293 | err = tg3_phy_reset(tp); |
| 4294 | if (!err) |
| 4295 | err = tg3_init_5401phy_dsp(tp); |
| 4296 | if (err) |
| 4297 | return err; |
| 4298 | } |
| 4299 | } |
| 4300 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 4301 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { |
| 4302 | /* 5701 {A0,B0} CRC bug workaround */ |
| 4303 | tg3_writephy(tp, 0x15, 0x0a75); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4304 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
| 4305 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 4306 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | } |
| 4308 | |
| 4309 | /* Clear pending interrupts... */ |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4310 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
| 4311 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4313 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4315 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
| 4317 | |
| 4318 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 4319 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 4320 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
| 4321 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 4322 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 4323 | else |
| 4324 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); |
| 4325 | } |
| 4326 | |
| 4327 | current_link_up = 0; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 4328 | current_speed = SPEED_UNKNOWN; |
| 4329 | current_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4330 | tp->phy_flags &= ~TG3_PHYFLG_MDIX_STATE; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4331 | tp->link_config.rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4333 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 4334 | err = tg3_phy_auxctl_read(tp, |
| 4335 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4336 | &val); |
| 4337 | if (!err && !(val & (1 << 10))) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4338 | tg3_phy_auxctl_write(tp, |
| 4339 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4340 | val | (1 << 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | goto relink; |
| 4342 | } |
| 4343 | } |
| 4344 | |
| 4345 | bmsr = 0; |
| 4346 | for (i = 0; i < 100; i++) { |
| 4347 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4348 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4349 | (bmsr & BMSR_LSTATUS)) |
| 4350 | break; |
| 4351 | udelay(40); |
| 4352 | } |
| 4353 | |
| 4354 | if (bmsr & BMSR_LSTATUS) { |
| 4355 | u32 aux_stat, bmcr; |
| 4356 | |
| 4357 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); |
| 4358 | for (i = 0; i < 2000; i++) { |
| 4359 | udelay(10); |
| 4360 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && |
| 4361 | aux_stat) |
| 4362 | break; |
| 4363 | } |
| 4364 | |
| 4365 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, |
| 4366 | ¤t_speed, |
| 4367 | ¤t_duplex); |
| 4368 | |
| 4369 | bmcr = 0; |
| 4370 | for (i = 0; i < 200; i++) { |
| 4371 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4372 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) |
| 4373 | continue; |
| 4374 | if (bmcr && bmcr != 0x7fff) |
| 4375 | break; |
| 4376 | udelay(10); |
| 4377 | } |
| 4378 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4379 | lcl_adv = 0; |
| 4380 | rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4382 | tp->link_config.active_speed = current_speed; |
| 4383 | tp->link_config.active_duplex = current_duplex; |
| 4384 | |
| 4385 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 4386 | if ((bmcr & BMCR_ANENABLE) && |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4387 | tg3_phy_copper_an_config_ok(tp, &lcl_adv) && |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4388 | tg3_phy_copper_fetch_rmtadv(tp, &rmt_adv)) |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4389 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | } else { |
| 4391 | if (!(bmcr & BMCR_ANENABLE) && |
| 4392 | tp->link_config.speed == current_speed && |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4393 | tp->link_config.duplex == current_duplex && |
| 4394 | tp->link_config.flowctrl == |
| 4395 | tp->link_config.active_flowctrl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | } |
| 4398 | } |
| 4399 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4400 | if (current_link_up == 1 && |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4401 | tp->link_config.active_duplex == DUPLEX_FULL) { |
| 4402 | u32 reg, bit; |
| 4403 | |
| 4404 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 4405 | reg = MII_TG3_FET_GEN_STAT; |
| 4406 | bit = MII_TG3_FET_GEN_STAT_MDIXSTAT; |
| 4407 | } else { |
| 4408 | reg = MII_TG3_EXT_STAT; |
| 4409 | bit = MII_TG3_EXT_STAT_MDIX; |
| 4410 | } |
| 4411 | |
| 4412 | if (!tg3_readphy(tp, reg, &val) && (val & bit)) |
| 4413 | tp->phy_flags |= TG3_PHYFLG_MDIX_STATE; |
| 4414 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4415 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | } |
| 4418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | relink: |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 4420 | 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] | 4421 | tg3_phy_copper_begin(tp); |
| 4422 | |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4423 | tg3_readphy(tp, MII_BMSR, &bmsr); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 4424 | if ((!tg3_readphy(tp, MII_BMSR, &bmsr) && (bmsr & BMSR_LSTATUS)) || |
| 4425 | (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | current_link_up = 1; |
| 4427 | } |
| 4428 | |
| 4429 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 4430 | if (current_link_up == 1) { |
| 4431 | if (tp->link_config.active_speed == SPEED_100 || |
| 4432 | tp->link_config.active_speed == SPEED_10) |
| 4433 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4434 | else |
| 4435 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4436 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 4437 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4438 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4440 | |
| 4441 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 4442 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 4443 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 4444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4446 | if (current_link_up == 1 && |
| 4447 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4449 | else |
| 4450 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | /* ??? Without this setting Netgear GA302T PHY does not |
| 4454 | * ??? send/receive packets... |
| 4455 | */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4456 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
| 4458 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
| 4459 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 4460 | udelay(80); |
| 4461 | } |
| 4462 | |
| 4463 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4464 | udelay(40); |
| 4465 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4466 | tg3_phy_eee_adjust(tp, current_link_up); |
| 4467 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4468 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | /* Polled via timer. */ |
| 4470 | tw32_f(MAC_EVENT, 0); |
| 4471 | } else { |
| 4472 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4473 | } |
| 4474 | udelay(40); |
| 4475 | |
| 4476 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && |
| 4477 | current_link_up == 1 && |
| 4478 | tp->link_config.active_speed == SPEED_1000 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4479 | (tg3_flag(tp, PCIX_MODE) || tg3_flag(tp, PCI_HIGH_SPEED))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | udelay(120); |
| 4481 | tw32_f(MAC_STATUS, |
| 4482 | (MAC_STATUS_SYNC_CHANGED | |
| 4483 | MAC_STATUS_CFG_CHANGED)); |
| 4484 | udelay(40); |
| 4485 | tg3_write_mem(tp, |
| 4486 | NIC_SRAM_FIRMWARE_MBOX, |
| 4487 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); |
| 4488 | } |
| 4489 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4490 | /* Prevent send BD corruption. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4491 | if (tg3_flag(tp, CLKREQ_BUG)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4492 | if (tp->link_config.active_speed == SPEED_100 || |
| 4493 | tp->link_config.active_speed == SPEED_10) |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 4494 | pcie_capability_clear_word(tp->pdev, PCI_EXP_LNKCTL, |
| 4495 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4496 | else |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 4497 | pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL, |
| 4498 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4499 | } |
| 4500 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 4501 | tg3_test_and_report_link_chg(tp, current_link_up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | |
| 4503 | return 0; |
| 4504 | } |
| 4505 | |
| 4506 | struct tg3_fiber_aneginfo { |
| 4507 | int state; |
| 4508 | #define ANEG_STATE_UNKNOWN 0 |
| 4509 | #define ANEG_STATE_AN_ENABLE 1 |
| 4510 | #define ANEG_STATE_RESTART_INIT 2 |
| 4511 | #define ANEG_STATE_RESTART 3 |
| 4512 | #define ANEG_STATE_DISABLE_LINK_OK 4 |
| 4513 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 |
| 4514 | #define ANEG_STATE_ABILITY_DETECT 6 |
| 4515 | #define ANEG_STATE_ACK_DETECT_INIT 7 |
| 4516 | #define ANEG_STATE_ACK_DETECT 8 |
| 4517 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 |
| 4518 | #define ANEG_STATE_COMPLETE_ACK 10 |
| 4519 | #define ANEG_STATE_IDLE_DETECT_INIT 11 |
| 4520 | #define ANEG_STATE_IDLE_DETECT 12 |
| 4521 | #define ANEG_STATE_LINK_OK 13 |
| 4522 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 |
| 4523 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 |
| 4524 | |
| 4525 | u32 flags; |
| 4526 | #define MR_AN_ENABLE 0x00000001 |
| 4527 | #define MR_RESTART_AN 0x00000002 |
| 4528 | #define MR_AN_COMPLETE 0x00000004 |
| 4529 | #define MR_PAGE_RX 0x00000008 |
| 4530 | #define MR_NP_LOADED 0x00000010 |
| 4531 | #define MR_TOGGLE_TX 0x00000020 |
| 4532 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 |
| 4533 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 |
| 4534 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 |
| 4535 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 |
| 4536 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 |
| 4537 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 |
| 4538 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 |
| 4539 | #define MR_TOGGLE_RX 0x00002000 |
| 4540 | #define MR_NP_RX 0x00004000 |
| 4541 | |
| 4542 | #define MR_LINK_OK 0x80000000 |
| 4543 | |
| 4544 | unsigned long link_time, cur_time; |
| 4545 | |
| 4546 | u32 ability_match_cfg; |
| 4547 | int ability_match_count; |
| 4548 | |
| 4549 | char ability_match, idle_match, ack_match; |
| 4550 | |
| 4551 | u32 txconfig, rxconfig; |
| 4552 | #define ANEG_CFG_NP 0x00000080 |
| 4553 | #define ANEG_CFG_ACK 0x00000040 |
| 4554 | #define ANEG_CFG_RF2 0x00000020 |
| 4555 | #define ANEG_CFG_RF1 0x00000010 |
| 4556 | #define ANEG_CFG_PS2 0x00000001 |
| 4557 | #define ANEG_CFG_PS1 0x00008000 |
| 4558 | #define ANEG_CFG_HD 0x00004000 |
| 4559 | #define ANEG_CFG_FD 0x00002000 |
| 4560 | #define ANEG_CFG_INVAL 0x00001f06 |
| 4561 | |
| 4562 | }; |
| 4563 | #define ANEG_OK 0 |
| 4564 | #define ANEG_DONE 1 |
| 4565 | #define ANEG_TIMER_ENAB 2 |
| 4566 | #define ANEG_FAILED -1 |
| 4567 | |
| 4568 | #define ANEG_STATE_SETTLE_TIME 10000 |
| 4569 | |
| 4570 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, |
| 4571 | struct tg3_fiber_aneginfo *ap) |
| 4572 | { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4573 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | unsigned long delta; |
| 4575 | u32 rx_cfg_reg; |
| 4576 | int ret; |
| 4577 | |
| 4578 | if (ap->state == ANEG_STATE_UNKNOWN) { |
| 4579 | ap->rxconfig = 0; |
| 4580 | ap->link_time = 0; |
| 4581 | ap->cur_time = 0; |
| 4582 | ap->ability_match_cfg = 0; |
| 4583 | ap->ability_match_count = 0; |
| 4584 | ap->ability_match = 0; |
| 4585 | ap->idle_match = 0; |
| 4586 | ap->ack_match = 0; |
| 4587 | } |
| 4588 | ap->cur_time++; |
| 4589 | |
| 4590 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { |
| 4591 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); |
| 4592 | |
| 4593 | if (rx_cfg_reg != ap->ability_match_cfg) { |
| 4594 | ap->ability_match_cfg = rx_cfg_reg; |
| 4595 | ap->ability_match = 0; |
| 4596 | ap->ability_match_count = 0; |
| 4597 | } else { |
| 4598 | if (++ap->ability_match_count > 1) { |
| 4599 | ap->ability_match = 1; |
| 4600 | ap->ability_match_cfg = rx_cfg_reg; |
| 4601 | } |
| 4602 | } |
| 4603 | if (rx_cfg_reg & ANEG_CFG_ACK) |
| 4604 | ap->ack_match = 1; |
| 4605 | else |
| 4606 | ap->ack_match = 0; |
| 4607 | |
| 4608 | ap->idle_match = 0; |
| 4609 | } else { |
| 4610 | ap->idle_match = 1; |
| 4611 | ap->ability_match_cfg = 0; |
| 4612 | ap->ability_match_count = 0; |
| 4613 | ap->ability_match = 0; |
| 4614 | ap->ack_match = 0; |
| 4615 | |
| 4616 | rx_cfg_reg = 0; |
| 4617 | } |
| 4618 | |
| 4619 | ap->rxconfig = rx_cfg_reg; |
| 4620 | ret = ANEG_OK; |
| 4621 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 4622 | switch (ap->state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | case ANEG_STATE_UNKNOWN: |
| 4624 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) |
| 4625 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4626 | |
| 4627 | /* fallthru */ |
| 4628 | case ANEG_STATE_AN_ENABLE: |
| 4629 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); |
| 4630 | if (ap->flags & MR_AN_ENABLE) { |
| 4631 | ap->link_time = 0; |
| 4632 | ap->cur_time = 0; |
| 4633 | ap->ability_match_cfg = 0; |
| 4634 | ap->ability_match_count = 0; |
| 4635 | ap->ability_match = 0; |
| 4636 | ap->idle_match = 0; |
| 4637 | ap->ack_match = 0; |
| 4638 | |
| 4639 | ap->state = ANEG_STATE_RESTART_INIT; |
| 4640 | } else { |
| 4641 | ap->state = ANEG_STATE_DISABLE_LINK_OK; |
| 4642 | } |
| 4643 | break; |
| 4644 | |
| 4645 | case ANEG_STATE_RESTART_INIT: |
| 4646 | ap->link_time = ap->cur_time; |
| 4647 | ap->flags &= ~(MR_NP_LOADED); |
| 4648 | ap->txconfig = 0; |
| 4649 | tw32(MAC_TX_AUTO_NEG, 0); |
| 4650 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4651 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4652 | udelay(40); |
| 4653 | |
| 4654 | ret = ANEG_TIMER_ENAB; |
| 4655 | ap->state = ANEG_STATE_RESTART; |
| 4656 | |
| 4657 | /* fallthru */ |
| 4658 | case ANEG_STATE_RESTART: |
| 4659 | delta = ap->cur_time - ap->link_time; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4660 | if (delta > ANEG_STATE_SETTLE_TIME) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4662 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | ret = ANEG_TIMER_ENAB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4664 | break; |
| 4665 | |
| 4666 | case ANEG_STATE_DISABLE_LINK_OK: |
| 4667 | ret = ANEG_DONE; |
| 4668 | break; |
| 4669 | |
| 4670 | case ANEG_STATE_ABILITY_DETECT_INIT: |
| 4671 | ap->flags &= ~(MR_TOGGLE_TX); |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4672 | ap->txconfig = ANEG_CFG_FD; |
| 4673 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 4674 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 4675 | ap->txconfig |= ANEG_CFG_PS1; |
| 4676 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 4677 | ap->txconfig |= ANEG_CFG_PS2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 4679 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4680 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4681 | udelay(40); |
| 4682 | |
| 4683 | ap->state = ANEG_STATE_ABILITY_DETECT; |
| 4684 | break; |
| 4685 | |
| 4686 | case ANEG_STATE_ABILITY_DETECT: |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4687 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4688 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | break; |
| 4690 | |
| 4691 | case ANEG_STATE_ACK_DETECT_INIT: |
| 4692 | ap->txconfig |= ANEG_CFG_ACK; |
| 4693 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 4694 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4695 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4696 | udelay(40); |
| 4697 | |
| 4698 | ap->state = ANEG_STATE_ACK_DETECT; |
| 4699 | |
| 4700 | /* fallthru */ |
| 4701 | case ANEG_STATE_ACK_DETECT: |
| 4702 | if (ap->ack_match != 0) { |
| 4703 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == |
| 4704 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { |
| 4705 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; |
| 4706 | } else { |
| 4707 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4708 | } |
| 4709 | } else if (ap->ability_match != 0 && |
| 4710 | ap->rxconfig == 0) { |
| 4711 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4712 | } |
| 4713 | break; |
| 4714 | |
| 4715 | case ANEG_STATE_COMPLETE_ACK_INIT: |
| 4716 | if (ap->rxconfig & ANEG_CFG_INVAL) { |
| 4717 | ret = ANEG_FAILED; |
| 4718 | break; |
| 4719 | } |
| 4720 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | |
| 4721 | MR_LP_ADV_HALF_DUPLEX | |
| 4722 | MR_LP_ADV_SYM_PAUSE | |
| 4723 | MR_LP_ADV_ASYM_PAUSE | |
| 4724 | MR_LP_ADV_REMOTE_FAULT1 | |
| 4725 | MR_LP_ADV_REMOTE_FAULT2 | |
| 4726 | MR_LP_ADV_NEXT_PAGE | |
| 4727 | MR_TOGGLE_RX | |
| 4728 | MR_NP_RX); |
| 4729 | if (ap->rxconfig & ANEG_CFG_FD) |
| 4730 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; |
| 4731 | if (ap->rxconfig & ANEG_CFG_HD) |
| 4732 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; |
| 4733 | if (ap->rxconfig & ANEG_CFG_PS1) |
| 4734 | ap->flags |= MR_LP_ADV_SYM_PAUSE; |
| 4735 | if (ap->rxconfig & ANEG_CFG_PS2) |
| 4736 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; |
| 4737 | if (ap->rxconfig & ANEG_CFG_RF1) |
| 4738 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; |
| 4739 | if (ap->rxconfig & ANEG_CFG_RF2) |
| 4740 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; |
| 4741 | if (ap->rxconfig & ANEG_CFG_NP) |
| 4742 | ap->flags |= MR_LP_ADV_NEXT_PAGE; |
| 4743 | |
| 4744 | ap->link_time = ap->cur_time; |
| 4745 | |
| 4746 | ap->flags ^= (MR_TOGGLE_TX); |
| 4747 | if (ap->rxconfig & 0x0008) |
| 4748 | ap->flags |= MR_TOGGLE_RX; |
| 4749 | if (ap->rxconfig & ANEG_CFG_NP) |
| 4750 | ap->flags |= MR_NP_RX; |
| 4751 | ap->flags |= MR_PAGE_RX; |
| 4752 | |
| 4753 | ap->state = ANEG_STATE_COMPLETE_ACK; |
| 4754 | ret = ANEG_TIMER_ENAB; |
| 4755 | break; |
| 4756 | |
| 4757 | case ANEG_STATE_COMPLETE_ACK: |
| 4758 | if (ap->ability_match != 0 && |
| 4759 | ap->rxconfig == 0) { |
| 4760 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4761 | break; |
| 4762 | } |
| 4763 | delta = ap->cur_time - ap->link_time; |
| 4764 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 4765 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { |
| 4766 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 4767 | } else { |
| 4768 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && |
| 4769 | !(ap->flags & MR_NP_RX)) { |
| 4770 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 4771 | } else { |
| 4772 | ret = ANEG_FAILED; |
| 4773 | } |
| 4774 | } |
| 4775 | } |
| 4776 | break; |
| 4777 | |
| 4778 | case ANEG_STATE_IDLE_DETECT_INIT: |
| 4779 | ap->link_time = ap->cur_time; |
| 4780 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 4781 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4782 | udelay(40); |
| 4783 | |
| 4784 | ap->state = ANEG_STATE_IDLE_DETECT; |
| 4785 | ret = ANEG_TIMER_ENAB; |
| 4786 | break; |
| 4787 | |
| 4788 | case ANEG_STATE_IDLE_DETECT: |
| 4789 | if (ap->ability_match != 0 && |
| 4790 | ap->rxconfig == 0) { |
| 4791 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4792 | break; |
| 4793 | } |
| 4794 | delta = ap->cur_time - ap->link_time; |
| 4795 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 4796 | /* XXX another gem from the Broadcom driver :( */ |
| 4797 | ap->state = ANEG_STATE_LINK_OK; |
| 4798 | } |
| 4799 | break; |
| 4800 | |
| 4801 | case ANEG_STATE_LINK_OK: |
| 4802 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); |
| 4803 | ret = ANEG_DONE; |
| 4804 | break; |
| 4805 | |
| 4806 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: |
| 4807 | /* ??? unimplemented */ |
| 4808 | break; |
| 4809 | |
| 4810 | case ANEG_STATE_NEXT_PAGE_WAIT: |
| 4811 | /* ??? unimplemented */ |
| 4812 | break; |
| 4813 | |
| 4814 | default: |
| 4815 | ret = ANEG_FAILED; |
| 4816 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4817 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | |
| 4819 | return ret; |
| 4820 | } |
| 4821 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4822 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | { |
| 4824 | int res = 0; |
| 4825 | struct tg3_fiber_aneginfo aninfo; |
| 4826 | int status = ANEG_FAILED; |
| 4827 | unsigned int tick; |
| 4828 | u32 tmp; |
| 4829 | |
| 4830 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 4831 | |
| 4832 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
| 4833 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); |
| 4834 | udelay(40); |
| 4835 | |
| 4836 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); |
| 4837 | udelay(40); |
| 4838 | |
| 4839 | memset(&aninfo, 0, sizeof(aninfo)); |
| 4840 | aninfo.flags |= MR_AN_ENABLE; |
| 4841 | aninfo.state = ANEG_STATE_UNKNOWN; |
| 4842 | aninfo.cur_time = 0; |
| 4843 | tick = 0; |
| 4844 | while (++tick < 195000) { |
| 4845 | status = tg3_fiber_aneg_smachine(tp, &aninfo); |
| 4846 | if (status == ANEG_DONE || status == ANEG_FAILED) |
| 4847 | break; |
| 4848 | |
| 4849 | udelay(1); |
| 4850 | } |
| 4851 | |
| 4852 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 4853 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4854 | udelay(40); |
| 4855 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4856 | *txflags = aninfo.txconfig; |
| 4857 | *rxflags = aninfo.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | |
| 4859 | if (status == ANEG_DONE && |
| 4860 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | |
| 4861 | MR_LP_ADV_FULL_DUPLEX))) |
| 4862 | res = 1; |
| 4863 | |
| 4864 | return res; |
| 4865 | } |
| 4866 | |
| 4867 | static void tg3_init_bcm8002(struct tg3 *tp) |
| 4868 | { |
| 4869 | u32 mac_status = tr32(MAC_STATUS); |
| 4870 | int i; |
| 4871 | |
| 4872 | /* Reset when initting first time or we have a link. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4873 | if (tg3_flag(tp, INIT_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 4875 | return; |
| 4876 | |
| 4877 | /* Set PLL lock range. */ |
| 4878 | tg3_writephy(tp, 0x16, 0x8007); |
| 4879 | |
| 4880 | /* SW reset */ |
| 4881 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); |
| 4882 | |
| 4883 | /* Wait for reset to complete. */ |
| 4884 | /* XXX schedule_timeout() ... */ |
| 4885 | for (i = 0; i < 500; i++) |
| 4886 | udelay(10); |
| 4887 | |
| 4888 | /* Config mode; select PMA/Ch 1 regs. */ |
| 4889 | tg3_writephy(tp, 0x10, 0x8411); |
| 4890 | |
| 4891 | /* Enable auto-lock and comdet, select txclk for tx. */ |
| 4892 | tg3_writephy(tp, 0x11, 0x0a10); |
| 4893 | |
| 4894 | tg3_writephy(tp, 0x18, 0x00a0); |
| 4895 | tg3_writephy(tp, 0x16, 0x41ff); |
| 4896 | |
| 4897 | /* Assert and deassert POR. */ |
| 4898 | tg3_writephy(tp, 0x13, 0x0400); |
| 4899 | udelay(40); |
| 4900 | tg3_writephy(tp, 0x13, 0x0000); |
| 4901 | |
| 4902 | tg3_writephy(tp, 0x11, 0x0a50); |
| 4903 | udelay(40); |
| 4904 | tg3_writephy(tp, 0x11, 0x0a10); |
| 4905 | |
| 4906 | /* Wait for signal to stabilize */ |
| 4907 | /* XXX schedule_timeout() ... */ |
| 4908 | for (i = 0; i < 15000; i++) |
| 4909 | udelay(10); |
| 4910 | |
| 4911 | /* Deselect the channel register so we can read the PHYID |
| 4912 | * later. |
| 4913 | */ |
| 4914 | tg3_writephy(tp, 0x10, 0x8011); |
| 4915 | } |
| 4916 | |
| 4917 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
| 4918 | { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4919 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | u32 sg_dig_ctrl, sg_dig_status; |
| 4921 | u32 serdes_cfg, expected_sg_dig_ctrl; |
| 4922 | int workaround, port_a; |
| 4923 | int current_link_up; |
| 4924 | |
| 4925 | serdes_cfg = 0; |
| 4926 | expected_sg_dig_ctrl = 0; |
| 4927 | workaround = 0; |
| 4928 | port_a = 1; |
| 4929 | current_link_up = 0; |
| 4930 | |
| 4931 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && |
| 4932 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { |
| 4933 | workaround = 1; |
| 4934 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 4935 | port_a = 0; |
| 4936 | |
| 4937 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ |
| 4938 | /* preserve bits 20-23 for voltage regulator */ |
| 4939 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; |
| 4940 | } |
| 4941 | |
| 4942 | sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 4943 | |
| 4944 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4945 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | if (workaround) { |
| 4947 | u32 val = serdes_cfg; |
| 4948 | |
| 4949 | if (port_a) |
| 4950 | val |= 0xc010000; |
| 4951 | else |
| 4952 | val |= 0x4010000; |
| 4953 | tw32_f(MAC_SERDES_CFG, val); |
| 4954 | } |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4955 | |
| 4956 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | } |
| 4958 | if (mac_status & MAC_STATUS_PCS_SYNCED) { |
| 4959 | tg3_setup_flow_control(tp, 0, 0); |
| 4960 | current_link_up = 1; |
| 4961 | } |
| 4962 | goto out; |
| 4963 | } |
| 4964 | |
| 4965 | /* Want auto-negotiation. */ |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4966 | 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] | 4967 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4968 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 4969 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 4970 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; |
| 4971 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 4972 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4973 | |
| 4974 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4975 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4976 | tp->serdes_counter && |
| 4977 | ((mac_status & (MAC_STATUS_PCS_SYNCED | |
| 4978 | MAC_STATUS_RCVD_CFG)) == |
| 4979 | MAC_STATUS_PCS_SYNCED)) { |
| 4980 | tp->serdes_counter--; |
| 4981 | current_link_up = 1; |
| 4982 | goto out; |
| 4983 | } |
| 4984 | restart_autoneg: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | if (workaround) |
| 4986 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4987 | 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] | 4988 | udelay(5); |
| 4989 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); |
| 4990 | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4991 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4992 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
| 4994 | MAC_STATUS_SIGNAL_DET)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4995 | sg_dig_status = tr32(SG_DIG_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | mac_status = tr32(MAC_STATUS); |
| 4997 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4998 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5000 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5001 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5002 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) |
| 5003 | local_adv |= ADVERTISE_1000XPAUSE; |
| 5004 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) |
| 5005 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 5006 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5007 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5008 | remote_adv |= LPA_1000XPAUSE; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5009 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5010 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5012 | tp->link_config.rmt_adv = |
| 5013 | mii_adv_to_ethtool_adv_x(remote_adv); |
| 5014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5015 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5016 | current_link_up = 1; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5017 | tp->serdes_counter = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5018 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5019 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5020 | if (tp->serdes_counter) |
| 5021 | tp->serdes_counter--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | else { |
| 5023 | if (workaround) { |
| 5024 | u32 val = serdes_cfg; |
| 5025 | |
| 5026 | if (port_a) |
| 5027 | val |= 0xc010000; |
| 5028 | else |
| 5029 | val |= 0x4010000; |
| 5030 | |
| 5031 | tw32_f(MAC_SERDES_CFG, val); |
| 5032 | } |
| 5033 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5034 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | udelay(40); |
| 5036 | |
| 5037 | /* Link parallel detection - link is up */ |
| 5038 | /* only if we have PCS_SYNC and not */ |
| 5039 | /* receiving config code words */ |
| 5040 | mac_status = tr32(MAC_STATUS); |
| 5041 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && |
| 5042 | !(mac_status & MAC_STATUS_RCVD_CFG)) { |
| 5043 | tg3_setup_flow_control(tp, 0, 0); |
| 5044 | current_link_up = 1; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5045 | tp->phy_flags |= |
| 5046 | TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5047 | tp->serdes_counter = |
| 5048 | SERDES_PARALLEL_DET_TIMEOUT; |
| 5049 | } else |
| 5050 | goto restart_autoneg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5051 | } |
| 5052 | } |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5053 | } else { |
| 5054 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5055 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | } |
| 5057 | |
| 5058 | out: |
| 5059 | return current_link_up; |
| 5060 | } |
| 5061 | |
| 5062 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
| 5063 | { |
| 5064 | int current_link_up = 0; |
| 5065 | |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 5066 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5068 | |
| 5069 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5070 | u32 txflags, rxflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 5072 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5073 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
| 5074 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5075 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5076 | if (txflags & ANEG_CFG_PS1) |
| 5077 | local_adv |= ADVERTISE_1000XPAUSE; |
| 5078 | if (txflags & ANEG_CFG_PS2) |
| 5079 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 5080 | |
| 5081 | if (rxflags & MR_LP_ADV_SYM_PAUSE) |
| 5082 | remote_adv |= LPA_1000XPAUSE; |
| 5083 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) |
| 5084 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5086 | tp->link_config.rmt_adv = |
| 5087 | mii_adv_to_ethtool_adv_x(remote_adv); |
| 5088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5089 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5091 | current_link_up = 1; |
| 5092 | } |
| 5093 | for (i = 0; i < 30; i++) { |
| 5094 | udelay(20); |
| 5095 | tw32_f(MAC_STATUS, |
| 5096 | (MAC_STATUS_SYNC_CHANGED | |
| 5097 | MAC_STATUS_CFG_CHANGED)); |
| 5098 | udelay(40); |
| 5099 | if ((tr32(MAC_STATUS) & |
| 5100 | (MAC_STATUS_SYNC_CHANGED | |
| 5101 | MAC_STATUS_CFG_CHANGED)) == 0) |
| 5102 | break; |
| 5103 | } |
| 5104 | |
| 5105 | mac_status = tr32(MAC_STATUS); |
| 5106 | if (current_link_up == 0 && |
| 5107 | (mac_status & MAC_STATUS_PCS_SYNCED) && |
| 5108 | !(mac_status & MAC_STATUS_RCVD_CFG)) |
| 5109 | current_link_up = 1; |
| 5110 | } else { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5111 | tg3_setup_flow_control(tp, 0, 0); |
| 5112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5113 | /* Forcing 1000FD link up. */ |
| 5114 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5115 | |
| 5116 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); |
| 5117 | udelay(40); |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 5118 | |
| 5119 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5120 | udelay(40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | out: |
| 5124 | return current_link_up; |
| 5125 | } |
| 5126 | |
| 5127 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) |
| 5128 | { |
| 5129 | u32 orig_pause_cfg; |
| 5130 | u16 orig_active_speed; |
| 5131 | u8 orig_active_duplex; |
| 5132 | u32 mac_status; |
| 5133 | int current_link_up; |
| 5134 | int i; |
| 5135 | |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 5136 | orig_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5137 | orig_active_speed = tp->link_config.active_speed; |
| 5138 | orig_active_duplex = tp->link_config.active_duplex; |
| 5139 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5140 | if (!tg3_flag(tp, HW_AUTONEG) && |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5141 | tp->link_up && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5142 | tg3_flag(tp, INIT_COMPLETE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | mac_status = tr32(MAC_STATUS); |
| 5144 | mac_status &= (MAC_STATUS_PCS_SYNCED | |
| 5145 | MAC_STATUS_SIGNAL_DET | |
| 5146 | MAC_STATUS_CFG_CHANGED | |
| 5147 | MAC_STATUS_RCVD_CFG); |
| 5148 | if (mac_status == (MAC_STATUS_PCS_SYNCED | |
| 5149 | MAC_STATUS_SIGNAL_DET)) { |
| 5150 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5151 | MAC_STATUS_CFG_CHANGED)); |
| 5152 | return 0; |
| 5153 | } |
| 5154 | } |
| 5155 | |
| 5156 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 5157 | |
| 5158 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 5159 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 5160 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5161 | udelay(40); |
| 5162 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 5163 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | tg3_init_bcm8002(tp); |
| 5165 | |
| 5166 | /* Enable link change event even when serdes polling. */ |
| 5167 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5168 | udelay(40); |
| 5169 | |
| 5170 | current_link_up = 0; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5171 | tp->link_config.rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | mac_status = tr32(MAC_STATUS); |
| 5173 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5174 | if (tg3_flag(tp, HW_AUTONEG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5175 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
| 5176 | else |
| 5177 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); |
| 5178 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5179 | tp->napi[0].hw_status->status = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5180 | (SD_STATUS_UPDATED | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5181 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | |
| 5183 | for (i = 0; i < 100; i++) { |
| 5184 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5185 | MAC_STATUS_CFG_CHANGED)); |
| 5186 | udelay(5); |
| 5187 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5188 | MAC_STATUS_CFG_CHANGED | |
| 5189 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5190 | break; |
| 5191 | } |
| 5192 | |
| 5193 | mac_status = tr32(MAC_STATUS); |
| 5194 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { |
| 5195 | current_link_up = 0; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5196 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 5197 | tp->serdes_counter == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | tw32_f(MAC_MODE, (tp->mac_mode | |
| 5199 | MAC_MODE_SEND_CONFIGS)); |
| 5200 | udelay(1); |
| 5201 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5202 | } |
| 5203 | } |
| 5204 | |
| 5205 | if (current_link_up == 1) { |
| 5206 | tp->link_config.active_speed = SPEED_1000; |
| 5207 | tp->link_config.active_duplex = DUPLEX_FULL; |
| 5208 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5209 | LED_CTRL_LNKLED_OVERRIDE | |
| 5210 | LED_CTRL_1000MBPS_ON)); |
| 5211 | } else { |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 5212 | tp->link_config.active_speed = SPEED_UNKNOWN; |
| 5213 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5214 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5215 | LED_CTRL_LNKLED_OVERRIDE | |
| 5216 | LED_CTRL_TRAFFIC_OVERRIDE)); |
| 5217 | } |
| 5218 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5219 | if (!tg3_test_and_report_link_chg(tp, current_link_up)) { |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 5220 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5221 | if (orig_pause_cfg != now_pause_cfg || |
| 5222 | orig_active_speed != tp->link_config.active_speed || |
| 5223 | orig_active_duplex != tp->link_config.active_duplex) |
| 5224 | tg3_link_report(tp); |
| 5225 | } |
| 5226 | |
| 5227 | return 0; |
| 5228 | } |
| 5229 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5230 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
| 5231 | { |
| 5232 | int current_link_up, err = 0; |
| 5233 | u32 bmsr, bmcr; |
| 5234 | u16 current_speed; |
| 5235 | u8 current_duplex; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5236 | u32 local_adv, remote_adv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5237 | |
| 5238 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 5239 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5240 | udelay(40); |
| 5241 | |
| 5242 | tw32(MAC_EVENT, 0); |
| 5243 | |
| 5244 | tw32_f(MAC_STATUS, |
| 5245 | (MAC_STATUS_SYNC_CHANGED | |
| 5246 | MAC_STATUS_CFG_CHANGED | |
| 5247 | MAC_STATUS_MI_COMPLETION | |
| 5248 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 5249 | udelay(40); |
| 5250 | |
| 5251 | if (force_reset) |
| 5252 | tg3_phy_reset(tp); |
| 5253 | |
| 5254 | current_link_up = 0; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 5255 | current_speed = SPEED_UNKNOWN; |
| 5256 | current_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5257 | tp->link_config.rmt_adv = 0; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5258 | |
| 5259 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5260 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 5261 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 5262 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5263 | bmsr |= BMSR_LSTATUS; |
| 5264 | else |
| 5265 | bmsr &= ~BMSR_LSTATUS; |
| 5266 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5267 | |
| 5268 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5269 | |
| 5270 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5271 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5272 | /* do nothing, just check for link up at the end */ |
| 5273 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5274 | u32 adv, newadv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5275 | |
| 5276 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5277 | newadv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
| 5278 | ADVERTISE_1000XPAUSE | |
| 5279 | ADVERTISE_1000XPSE_ASYM | |
| 5280 | ADVERTISE_SLCT); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5281 | |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5282 | newadv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
Matt Carlson | 37f0702 | 2011-11-17 14:30:55 +0000 | [diff] [blame] | 5283 | newadv |= ethtool_adv_to_mii_adv_x(tp->link_config.advertising); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5284 | |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5285 | if ((newadv != adv) || !(bmcr & BMCR_ANENABLE)) { |
| 5286 | tg3_writephy(tp, MII_ADVERTISE, newadv); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5287 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 5288 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 5289 | |
| 5290 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5291 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5292 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5293 | |
| 5294 | return err; |
| 5295 | } |
| 5296 | } else { |
| 5297 | u32 new_bmcr; |
| 5298 | |
| 5299 | bmcr &= ~BMCR_SPEED1000; |
| 5300 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); |
| 5301 | |
| 5302 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 5303 | new_bmcr |= BMCR_FULLDPLX; |
| 5304 | |
| 5305 | if (new_bmcr != bmcr) { |
| 5306 | /* BMCR_SPEED1000 is a reserved bit that needs |
| 5307 | * to be set on write. |
| 5308 | */ |
| 5309 | new_bmcr |= BMCR_SPEED1000; |
| 5310 | |
| 5311 | /* Force a linkdown */ |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5312 | if (tp->link_up) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5313 | u32 adv; |
| 5314 | |
| 5315 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 5316 | adv &= ~(ADVERTISE_1000XFULL | |
| 5317 | ADVERTISE_1000XHALF | |
| 5318 | ADVERTISE_SLCT); |
| 5319 | tg3_writephy(tp, MII_ADVERTISE, adv); |
| 5320 | tg3_writephy(tp, MII_BMCR, bmcr | |
| 5321 | BMCR_ANRESTART | |
| 5322 | BMCR_ANENABLE); |
| 5323 | udelay(10); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5324 | tg3_carrier_off(tp); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5325 | } |
| 5326 | tg3_writephy(tp, MII_BMCR, new_bmcr); |
| 5327 | bmcr = new_bmcr; |
| 5328 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5329 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 5330 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 5331 | ASIC_REV_5714) { |
| 5332 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5333 | bmsr |= BMSR_LSTATUS; |
| 5334 | else |
| 5335 | bmsr &= ~BMSR_LSTATUS; |
| 5336 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5337 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5338 | } |
| 5339 | } |
| 5340 | |
| 5341 | if (bmsr & BMSR_LSTATUS) { |
| 5342 | current_speed = SPEED_1000; |
| 5343 | current_link_up = 1; |
| 5344 | if (bmcr & BMCR_FULLDPLX) |
| 5345 | current_duplex = DUPLEX_FULL; |
| 5346 | else |
| 5347 | current_duplex = DUPLEX_HALF; |
| 5348 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5349 | local_adv = 0; |
| 5350 | remote_adv = 0; |
| 5351 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5352 | if (bmcr & BMCR_ANENABLE) { |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5353 | u32 common; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5354 | |
| 5355 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); |
| 5356 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); |
| 5357 | common = local_adv & remote_adv; |
| 5358 | if (common & (ADVERTISE_1000XHALF | |
| 5359 | ADVERTISE_1000XFULL)) { |
| 5360 | if (common & ADVERTISE_1000XFULL) |
| 5361 | current_duplex = DUPLEX_FULL; |
| 5362 | else |
| 5363 | current_duplex = DUPLEX_HALF; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5364 | |
| 5365 | tp->link_config.rmt_adv = |
| 5366 | mii_adv_to_ethtool_adv_x(remote_adv); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5367 | } else if (!tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 5368 | /* Link is up via parallel detect */ |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5369 | } else { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5370 | current_link_up = 0; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5371 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5372 | } |
| 5373 | } |
| 5374 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5375 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
| 5376 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5377 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5378 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 5379 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 5380 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 5381 | |
| 5382 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5383 | udelay(40); |
| 5384 | |
| 5385 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5386 | |
| 5387 | tp->link_config.active_speed = current_speed; |
| 5388 | tp->link_config.active_duplex = current_duplex; |
| 5389 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5390 | tg3_test_and_report_link_chg(tp, current_link_up); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5391 | return err; |
| 5392 | } |
| 5393 | |
| 5394 | static void tg3_serdes_parallel_detect(struct tg3 *tp) |
| 5395 | { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5396 | if (tp->serdes_counter) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5397 | /* Give autoneg time to complete. */ |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5398 | tp->serdes_counter--; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5399 | return; |
| 5400 | } |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5401 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5402 | if (!tp->link_up && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5403 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { |
| 5404 | u32 bmcr; |
| 5405 | |
| 5406 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5407 | if (bmcr & BMCR_ANENABLE) { |
| 5408 | u32 phy1, phy2; |
| 5409 | |
| 5410 | /* Select shadow register 0x1f */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5411 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
| 5412 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5413 | |
| 5414 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5415 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 5416 | MII_TG3_DSP_EXP1_INT_STAT); |
| 5417 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 5418 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5419 | |
| 5420 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { |
| 5421 | /* We have signal detect and not receiving |
| 5422 | * config code words, link is up by parallel |
| 5423 | * detection. |
| 5424 | */ |
| 5425 | |
| 5426 | bmcr &= ~BMCR_ANENABLE; |
| 5427 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; |
| 5428 | tg3_writephy(tp, MII_BMCR, bmcr); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5429 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5430 | } |
| 5431 | } |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5432 | } else if (tp->link_up && |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5433 | (tp->link_config.autoneg == AUTONEG_ENABLE) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5434 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5435 | u32 phy2; |
| 5436 | |
| 5437 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5438 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 5439 | MII_TG3_DSP_EXP1_INT_STAT); |
| 5440 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5441 | if (phy2 & 0x20) { |
| 5442 | u32 bmcr; |
| 5443 | |
| 5444 | /* Config code words received, turn on autoneg. */ |
| 5445 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5446 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); |
| 5447 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5448 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5449 | |
| 5450 | } |
| 5451 | } |
| 5452 | } |
| 5453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5454 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
| 5455 | { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5456 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5457 | int err; |
| 5458 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5459 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5460 | err = tg3_setup_fiber_phy(tp, force_reset); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5461 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5462 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5463 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 | err = tg3_setup_copper_phy(tp, force_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5465 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 5466 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5467 | u32 scale; |
Matt Carlson | aa6c91f | 2007-11-12 21:18:04 -0800 | [diff] [blame] | 5468 | |
| 5469 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; |
| 5470 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) |
| 5471 | scale = 65; |
| 5472 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) |
| 5473 | scale = 6; |
| 5474 | else |
| 5475 | scale = 12; |
| 5476 | |
| 5477 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; |
| 5478 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 5479 | tw32(GRC_MISC_CFG, val); |
| 5480 | } |
| 5481 | |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5482 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 5483 | (6 << TX_LENGTHS_IPG_SHIFT); |
| 5484 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 5485 | val |= tr32(MAC_TX_LENGTHS) & |
| 5486 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 5487 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 5488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5489 | if (tp->link_config.active_speed == SPEED_1000 && |
| 5490 | tp->link_config.active_duplex == DUPLEX_HALF) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5491 | tw32(MAC_TX_LENGTHS, val | |
| 5492 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | else |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5494 | tw32(MAC_TX_LENGTHS, val | |
| 5495 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5496 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5497 | if (!tg3_flag(tp, 5705_PLUS)) { |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5498 | if (tp->link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5499 | tw32(HOSTCC_STAT_COAL_TICKS, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 5500 | tp->coal.stats_block_coalesce_usecs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | } else { |
| 5502 | tw32(HOSTCC_STAT_COAL_TICKS, 0); |
| 5503 | } |
| 5504 | } |
| 5505 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5506 | if (tg3_flag(tp, ASPM_WORKAROUND)) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5507 | val = tr32(PCIE_PWR_MGMT_THRESH); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5508 | if (!tp->link_up) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 5509 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
| 5510 | tp->pwrmgmt_thresh; |
| 5511 | else |
| 5512 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 5513 | tw32(PCIE_PWR_MGMT_THRESH, val); |
| 5514 | } |
| 5515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | return err; |
| 5517 | } |
| 5518 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 5519 | static inline int tg3_irq_sync(struct tg3 *tp) |
| 5520 | { |
| 5521 | return tp->irq_sync; |
| 5522 | } |
| 5523 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5524 | static inline void tg3_rd32_loop(struct tg3 *tp, u32 *dst, u32 off, u32 len) |
| 5525 | { |
| 5526 | int i; |
| 5527 | |
| 5528 | dst = (u32 *)((u8 *)dst + off); |
| 5529 | for (i = 0; i < len; i += sizeof(u32)) |
| 5530 | *dst++ = tr32(off + i); |
| 5531 | } |
| 5532 | |
| 5533 | static void tg3_dump_legacy_regs(struct tg3 *tp, u32 *regs) |
| 5534 | { |
| 5535 | tg3_rd32_loop(tp, regs, TG3PCI_VENDOR, 0xb0); |
| 5536 | tg3_rd32_loop(tp, regs, MAILBOX_INTERRUPT_0, 0x200); |
| 5537 | tg3_rd32_loop(tp, regs, MAC_MODE, 0x4f0); |
| 5538 | tg3_rd32_loop(tp, regs, SNDDATAI_MODE, 0xe0); |
| 5539 | tg3_rd32_loop(tp, regs, SNDDATAC_MODE, 0x04); |
| 5540 | tg3_rd32_loop(tp, regs, SNDBDS_MODE, 0x80); |
| 5541 | tg3_rd32_loop(tp, regs, SNDBDI_MODE, 0x48); |
| 5542 | tg3_rd32_loop(tp, regs, SNDBDC_MODE, 0x04); |
| 5543 | tg3_rd32_loop(tp, regs, RCVLPC_MODE, 0x20); |
| 5544 | tg3_rd32_loop(tp, regs, RCVLPC_SELLST_BASE, 0x15c); |
| 5545 | tg3_rd32_loop(tp, regs, RCVDBDI_MODE, 0x0c); |
| 5546 | tg3_rd32_loop(tp, regs, RCVDBDI_JUMBO_BD, 0x3c); |
| 5547 | tg3_rd32_loop(tp, regs, RCVDBDI_BD_PROD_IDX_0, 0x44); |
| 5548 | tg3_rd32_loop(tp, regs, RCVDCC_MODE, 0x04); |
| 5549 | tg3_rd32_loop(tp, regs, RCVBDI_MODE, 0x20); |
| 5550 | tg3_rd32_loop(tp, regs, RCVCC_MODE, 0x14); |
| 5551 | tg3_rd32_loop(tp, regs, RCVLSC_MODE, 0x08); |
| 5552 | tg3_rd32_loop(tp, regs, MBFREE_MODE, 0x08); |
| 5553 | tg3_rd32_loop(tp, regs, HOSTCC_MODE, 0x100); |
| 5554 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5555 | if (tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5556 | tg3_rd32_loop(tp, regs, HOSTCC_RXCOL_TICKS_VEC1, 0x180); |
| 5557 | |
| 5558 | tg3_rd32_loop(tp, regs, MEMARB_MODE, 0x10); |
| 5559 | tg3_rd32_loop(tp, regs, BUFMGR_MODE, 0x58); |
| 5560 | tg3_rd32_loop(tp, regs, RDMAC_MODE, 0x08); |
| 5561 | tg3_rd32_loop(tp, regs, WDMAC_MODE, 0x08); |
| 5562 | tg3_rd32_loop(tp, regs, RX_CPU_MODE, 0x04); |
| 5563 | tg3_rd32_loop(tp, regs, RX_CPU_STATE, 0x04); |
| 5564 | tg3_rd32_loop(tp, regs, RX_CPU_PGMCTR, 0x04); |
| 5565 | tg3_rd32_loop(tp, regs, RX_CPU_HWBKPT, 0x04); |
| 5566 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5567 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5568 | tg3_rd32_loop(tp, regs, TX_CPU_MODE, 0x04); |
| 5569 | tg3_rd32_loop(tp, regs, TX_CPU_STATE, 0x04); |
| 5570 | tg3_rd32_loop(tp, regs, TX_CPU_PGMCTR, 0x04); |
| 5571 | } |
| 5572 | |
| 5573 | tg3_rd32_loop(tp, regs, GRCMBOX_INTERRUPT_0, 0x110); |
| 5574 | tg3_rd32_loop(tp, regs, FTQ_RESET, 0x120); |
| 5575 | tg3_rd32_loop(tp, regs, MSGINT_MODE, 0x0c); |
| 5576 | tg3_rd32_loop(tp, regs, DMAC_MODE, 0x04); |
| 5577 | tg3_rd32_loop(tp, regs, GRC_MODE, 0x4c); |
| 5578 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5579 | if (tg3_flag(tp, NVRAM)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5580 | tg3_rd32_loop(tp, regs, NVRAM_CMD, 0x24); |
| 5581 | } |
| 5582 | |
| 5583 | static void tg3_dump_state(struct tg3 *tp) |
| 5584 | { |
| 5585 | int i; |
| 5586 | u32 *regs; |
| 5587 | |
| 5588 | regs = kzalloc(TG3_REG_BLK_SIZE, GFP_ATOMIC); |
| 5589 | if (!regs) { |
| 5590 | netdev_err(tp->dev, "Failed allocating register dump buffer\n"); |
| 5591 | return; |
| 5592 | } |
| 5593 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5594 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5595 | /* Read up to but not including private PCI registers */ |
| 5596 | for (i = 0; i < TG3_PCIE_TLDLPL_PORT; i += sizeof(u32)) |
| 5597 | regs[i / sizeof(u32)] = tr32(i); |
| 5598 | } else |
| 5599 | tg3_dump_legacy_regs(tp, regs); |
| 5600 | |
| 5601 | for (i = 0; i < TG3_REG_BLK_SIZE / sizeof(u32); i += 4) { |
| 5602 | if (!regs[i + 0] && !regs[i + 1] && |
| 5603 | !regs[i + 2] && !regs[i + 3]) |
| 5604 | continue; |
| 5605 | |
| 5606 | netdev_err(tp->dev, "0x%08x: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", |
| 5607 | i * 4, |
| 5608 | regs[i + 0], regs[i + 1], regs[i + 2], regs[i + 3]); |
| 5609 | } |
| 5610 | |
| 5611 | kfree(regs); |
| 5612 | |
| 5613 | for (i = 0; i < tp->irq_cnt; i++) { |
| 5614 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 5615 | |
| 5616 | /* SW status block */ |
| 5617 | netdev_err(tp->dev, |
| 5618 | "%d: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", |
| 5619 | i, |
| 5620 | tnapi->hw_status->status, |
| 5621 | tnapi->hw_status->status_tag, |
| 5622 | tnapi->hw_status->rx_jumbo_consumer, |
| 5623 | tnapi->hw_status->rx_consumer, |
| 5624 | tnapi->hw_status->rx_mini_consumer, |
| 5625 | tnapi->hw_status->idx[0].rx_producer, |
| 5626 | tnapi->hw_status->idx[0].tx_consumer); |
| 5627 | |
| 5628 | netdev_err(tp->dev, |
| 5629 | "%d: NAPI info [%08x:%08x:(%04x:%04x:%04x):%04x:(%04x:%04x:%04x:%04x)]\n", |
| 5630 | i, |
| 5631 | tnapi->last_tag, tnapi->last_irq_tag, |
| 5632 | tnapi->tx_prod, tnapi->tx_cons, tnapi->tx_pending, |
| 5633 | tnapi->rx_rcb_ptr, |
| 5634 | tnapi->prodring.rx_std_prod_idx, |
| 5635 | tnapi->prodring.rx_std_cons_idx, |
| 5636 | tnapi->prodring.rx_jmb_prod_idx, |
| 5637 | tnapi->prodring.rx_jmb_cons_idx); |
| 5638 | } |
| 5639 | } |
| 5640 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5641 | /* This is called whenever we suspect that the system chipset is re- |
| 5642 | * ordering the sequence of MMIO to the tx send mailbox. The symptom |
| 5643 | * is bogus tx completions. We try to recover by setting the |
| 5644 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later |
| 5645 | * in the workqueue. |
| 5646 | */ |
| 5647 | static void tg3_tx_recover(struct tg3 *tp) |
| 5648 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5649 | BUG_ON(tg3_flag(tp, MBOX_WRITE_REORDER) || |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5650 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
| 5651 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5652 | netdev_warn(tp->dev, |
| 5653 | "The system may be re-ordering memory-mapped I/O " |
| 5654 | "cycles to the network device, attempting to recover. " |
| 5655 | "Please report the problem to the driver maintainer " |
| 5656 | "and include system chipset information.\n"); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5657 | |
| 5658 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5659 | tg3_flag_set(tp, TX_RECOVERY_PENDING); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5660 | spin_unlock(&tp->lock); |
| 5661 | } |
| 5662 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5663 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5664 | { |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 5665 | /* Tell compiler to fetch tx indices from memory. */ |
| 5666 | barrier(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5667 | return tnapi->tx_pending - |
| 5668 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5671 | /* Tigon3 never reports partial packet sends. So we do not |
| 5672 | * need special logic to handle SKBs that have not had all |
| 5673 | * of their frags sent yet, like SunGEM does. |
| 5674 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5675 | static void tg3_tx(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5676 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5677 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5678 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5679 | u32 sw_idx = tnapi->tx_cons; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5680 | struct netdev_queue *txq; |
| 5681 | int index = tnapi - tp->napi; |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5682 | unsigned int pkts_compl = 0, bytes_compl = 0; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5683 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5684 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5685 | index--; |
| 5686 | |
| 5687 | txq = netdev_get_tx_queue(tp->dev, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5688 | |
| 5689 | while (sw_idx != hw_idx) { |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 5690 | struct tg3_tx_ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5691 | struct sk_buff *skb = ri->skb; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5692 | int i, tx_bug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5693 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5694 | if (unlikely(skb == NULL)) { |
| 5695 | tg3_tx_recover(tp); |
| 5696 | return; |
| 5697 | } |
| 5698 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5699 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5700 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5701 | skb_headlen(skb), |
| 5702 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | |
| 5704 | ri->skb = NULL; |
| 5705 | |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 5706 | while (ri->fragmented) { |
| 5707 | ri->fragmented = false; |
| 5708 | sw_idx = NEXT_TX(sw_idx); |
| 5709 | ri = &tnapi->tx_buffers[sw_idx]; |
| 5710 | } |
| 5711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5712 | sw_idx = NEXT_TX(sw_idx); |
| 5713 | |
| 5714 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5715 | ri = &tnapi->tx_buffers[sw_idx]; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5716 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
| 5717 | tx_bug = 1; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5718 | |
| 5719 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5720 | dma_unmap_addr(ri, mapping), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5721 | skb_frag_size(&skb_shinfo(skb)->frags[i]), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5722 | PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 5723 | |
| 5724 | while (ri->fragmented) { |
| 5725 | ri->fragmented = false; |
| 5726 | sw_idx = NEXT_TX(sw_idx); |
| 5727 | ri = &tnapi->tx_buffers[sw_idx]; |
| 5728 | } |
| 5729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5730 | sw_idx = NEXT_TX(sw_idx); |
| 5731 | } |
| 5732 | |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5733 | pkts_compl++; |
| 5734 | bytes_compl += skb->len; |
| 5735 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5736 | dev_kfree_skb(skb); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5737 | |
| 5738 | if (unlikely(tx_bug)) { |
| 5739 | tg3_tx_recover(tp); |
| 5740 | return; |
| 5741 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | } |
| 5743 | |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 5744 | netdev_tx_completed_queue(txq, pkts_compl, bytes_compl); |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5745 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5746 | tnapi->tx_cons = sw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5747 | |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5748 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
| 5749 | * before checking for netif_queue_stopped(). Without the |
| 5750 | * memory barrier, there is a small possibility that tg3_start_xmit() |
| 5751 | * will miss it and cause the queue to be stopped forever. |
| 5752 | */ |
| 5753 | smp_mb(); |
| 5754 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5755 | if (unlikely(netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5756 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5757 | __netif_tx_lock(txq, smp_processor_id()); |
| 5758 | if (netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5759 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5760 | netif_tx_wake_queue(txq); |
| 5761 | __netif_tx_unlock(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 5762 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5763 | } |
| 5764 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5765 | static void tg3_frag_free(bool is_frag, void *data) |
| 5766 | { |
| 5767 | if (is_frag) |
| 5768 | put_page(virt_to_head_page(data)); |
| 5769 | else |
| 5770 | kfree(data); |
| 5771 | } |
| 5772 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5773 | 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] | 5774 | { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5775 | unsigned int skb_size = SKB_DATA_ALIGN(map_sz + TG3_RX_OFFSET(tp)) + |
| 5776 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 5777 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5778 | if (!ri->data) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5779 | return; |
| 5780 | |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5781 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5782 | map_sz, PCI_DMA_FROMDEVICE); |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 5783 | tg3_frag_free(skb_size <= PAGE_SIZE, ri->data); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5784 | ri->data = NULL; |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5785 | } |
| 5786 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5788 | /* Returns size of skb allocated or < 0 on error. |
| 5789 | * |
| 5790 | * We only need to fill in the address because the other members |
| 5791 | * of the RX descriptor are invariant, see tg3_init_rings. |
| 5792 | * |
| 5793 | * Note the purposeful assymetry of cpu vs. chip accesses. For |
| 5794 | * posting buffers we only dirty the first cache line of the RX |
| 5795 | * descriptor (containing the address). Whereas for the RX status |
| 5796 | * buffers the cpu only reads the last cacheline of the RX descriptor |
| 5797 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). |
| 5798 | */ |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5799 | 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] | 5800 | u32 opaque_key, u32 dest_idx_unmasked, |
| 5801 | unsigned int *frag_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5802 | { |
| 5803 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | f94e290 | 2010-10-14 10:37:42 +0000 | [diff] [blame] | 5804 | struct ring_info *map; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5805 | u8 *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | dma_addr_t mapping; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5807 | int skb_size, data_size, dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5809 | switch (opaque_key) { |
| 5810 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5811 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 5812 | desc = &tpr->rx_std[dest_idx]; |
| 5813 | map = &tpr->rx_std_buffers[dest_idx]; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5814 | data_size = tp->rx_pkt_map_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5815 | break; |
| 5816 | |
| 5817 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5818 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 5819 | desc = &tpr->rx_jmb[dest_idx].std; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 5820 | map = &tpr->rx_jmb_buffers[dest_idx]; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5821 | data_size = TG3_RX_JMB_MAP_SZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5822 | break; |
| 5823 | |
| 5824 | default: |
| 5825 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 5826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5827 | |
| 5828 | /* Do not overwrite any of the map or rp information |
| 5829 | * until we are sure we can commit to a new buffer. |
| 5830 | * |
| 5831 | * Callers depend upon this behavior and assume that |
| 5832 | * we leave everything unchanged if we fail. |
| 5833 | */ |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5834 | skb_size = SKB_DATA_ALIGN(data_size + TG3_RX_OFFSET(tp)) + |
| 5835 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 5836 | if (skb_size <= PAGE_SIZE) { |
| 5837 | data = netdev_alloc_frag(skb_size); |
| 5838 | *frag_size = skb_size; |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5839 | } else { |
| 5840 | data = kmalloc(skb_size, GFP_ATOMIC); |
| 5841 | *frag_size = 0; |
| 5842 | } |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5843 | if (!data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5844 | return -ENOMEM; |
| 5845 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5846 | mapping = pci_map_single(tp->pdev, |
| 5847 | data + TG3_RX_OFFSET(tp), |
| 5848 | data_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5849 | PCI_DMA_FROMDEVICE); |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5850 | if (unlikely(pci_dma_mapping_error(tp->pdev, mapping))) { |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 5851 | tg3_frag_free(skb_size <= PAGE_SIZE, data); |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 5852 | return -EIO; |
| 5853 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5854 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5855 | map->data = data; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5856 | dma_unmap_addr_set(map, mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5858 | desc->addr_hi = ((u64)mapping >> 32); |
| 5859 | desc->addr_lo = ((u64)mapping & 0xffffffff); |
| 5860 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5861 | return data_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | /* We only need to move over in the address because the other |
| 5865 | * members of the RX descriptor are invariant. See notes above |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5866 | * tg3_alloc_rx_data for full details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5867 | */ |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5868 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
| 5869 | struct tg3_rx_prodring_set *dpr, |
| 5870 | u32 opaque_key, int src_idx, |
| 5871 | u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5872 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5873 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5874 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
| 5875 | struct ring_info *src_map, *dest_map; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5876 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5877 | int dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5878 | |
| 5879 | switch (opaque_key) { |
| 5880 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5881 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5882 | dest_desc = &dpr->rx_std[dest_idx]; |
| 5883 | dest_map = &dpr->rx_std_buffers[dest_idx]; |
| 5884 | src_desc = &spr->rx_std[src_idx]; |
| 5885 | src_map = &spr->rx_std_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5886 | break; |
| 5887 | |
| 5888 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5889 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5890 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
| 5891 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; |
| 5892 | src_desc = &spr->rx_jmb[src_idx].std; |
| 5893 | src_map = &spr->rx_jmb_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5894 | break; |
| 5895 | |
| 5896 | default: |
| 5897 | return; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 5898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5899 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5900 | dest_map->data = src_map->data; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5901 | dma_unmap_addr_set(dest_map, mapping, |
| 5902 | dma_unmap_addr(src_map, mapping)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5903 | dest_desc->addr_hi = src_desc->addr_hi; |
| 5904 | dest_desc->addr_lo = src_desc->addr_lo; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5905 | |
| 5906 | /* Ensure that the update to the skb happens after the physical |
| 5907 | * addresses have been transferred to the new BD location. |
| 5908 | */ |
| 5909 | smp_wmb(); |
| 5910 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5911 | src_map->data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5912 | } |
| 5913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5914 | /* The RX ring scheme is composed of multiple rings which post fresh |
| 5915 | * buffers to the chip, and one special ring the chip uses to report |
| 5916 | * status back to the host. |
| 5917 | * |
| 5918 | * The special ring reports the status of received packets to the |
| 5919 | * host. The chip does not write into the original descriptor the |
| 5920 | * RX buffer was obtained from. The chip simply takes the original |
| 5921 | * descriptor as provided by the host, updates the status and length |
| 5922 | * field, then writes this into the next status ring entry. |
| 5923 | * |
| 5924 | * Each ring the host uses to post buffers to the chip is described |
| 5925 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, |
| 5926 | * it is first placed into the on-chip ram. When the packet's length |
| 5927 | * is known, it walks down the TG3_BDINFO entries to select the ring. |
| 5928 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO |
| 5929 | * which is within the range of the new packet's length is chosen. |
| 5930 | * |
| 5931 | * The "separate ring for rx status" scheme may sound queer, but it makes |
| 5932 | * sense from a cache coherency perspective. If only the host writes |
| 5933 | * to the buffer post rings, and only the chip writes to the rx status |
| 5934 | * rings, then cache lines never move beyond shared-modified state. |
| 5935 | * If both the host and chip were to write into the same ring, cache line |
| 5936 | * eviction could occur since both entities want it in an exclusive state. |
| 5937 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5938 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5940 | struct tg3 *tp = tnapi->tp; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5941 | u32 work_mask, rx_std_posted = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5942 | u32 std_prod_idx, jmb_prod_idx; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5943 | u32 sw_idx = tnapi->rx_rcb_ptr; |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 5944 | u16 hw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5945 | int received; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5946 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5947 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 5948 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5949 | /* |
| 5950 | * We need to order the read of hw_idx and the read of |
| 5951 | * the opaque cookie. |
| 5952 | */ |
| 5953 | rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5954 | work_mask = 0; |
| 5955 | received = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5956 | std_prod_idx = tpr->rx_std_prod_idx; |
| 5957 | jmb_prod_idx = tpr->rx_jmb_prod_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5958 | while (sw_idx != hw_idx && budget > 0) { |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 5959 | struct ring_info *ri; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5960 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5961 | unsigned int len; |
| 5962 | struct sk_buff *skb; |
| 5963 | dma_addr_t dma_addr; |
| 5964 | u32 opaque_key, desc_idx, *post_ptr; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5965 | u8 *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5966 | |
| 5967 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 5968 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 5969 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5970 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5971 | dma_addr = dma_unmap_addr(ri, mapping); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5972 | data = ri->data; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5973 | post_ptr = &std_prod_idx; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 5974 | rx_std_posted++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5975 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5976 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5977 | dma_addr = dma_unmap_addr(ri, mapping); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5978 | data = ri->data; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 5979 | post_ptr = &jmb_prod_idx; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 5980 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5981 | goto next_pkt_nopost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5982 | |
| 5983 | work_mask |= opaque_key; |
| 5984 | |
| 5985 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 5986 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { |
| 5987 | drop_it: |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 5988 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5989 | desc_idx, *post_ptr); |
| 5990 | drop_it_no_recycle: |
| 5991 | /* Other statistics kept track of by card. */ |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 5992 | tp->rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5993 | goto next_pkt; |
| 5994 | } |
| 5995 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5996 | prefetch(data + TG3_RX_OFFSET(tp)); |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 5997 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
| 5998 | ETH_FCS_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5999 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 6000 | if (len > TG3_RX_COPY_THRESH(tp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6001 | int skb_size; |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6002 | unsigned int frag_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6003 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6004 | skb_size = tg3_alloc_rx_data(tp, tpr, opaque_key, |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6005 | *post_ptr, &frag_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6006 | if (skb_size < 0) |
| 6007 | goto drop_it; |
| 6008 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6009 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | PCI_DMA_FROMDEVICE); |
| 6011 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6012 | skb = build_skb(data, frag_size); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6013 | if (!skb) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6014 | tg3_frag_free(frag_size != 0, data); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6015 | goto drop_it_no_recycle; |
| 6016 | } |
| 6017 | skb_reserve(skb, TG3_RX_OFFSET(tp)); |
| 6018 | /* Ensure that the update to the data happens |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 6019 | * after the usage of the old DMA mapping. |
| 6020 | */ |
| 6021 | smp_wmb(); |
| 6022 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6023 | ri->data = NULL; |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 6024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6025 | } else { |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6026 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6027 | desc_idx, *post_ptr); |
| 6028 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6029 | skb = netdev_alloc_skb(tp->dev, |
| 6030 | len + TG3_RAW_IP_ALIGN); |
| 6031 | if (skb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6032 | goto drop_it_no_recycle; |
| 6033 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6034 | skb_reserve(skb, TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6035 | 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] | 6036 | memcpy(skb->data, |
| 6037 | data + TG3_RX_OFFSET(tp), |
| 6038 | len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6039 | 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] | 6040 | } |
| 6041 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6042 | skb_put(skb, len); |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 6043 | if ((tp->dev->features & NETIF_F_RXCSUM) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6044 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 6045 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 6046 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) |
| 6047 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6048 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6049 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6050 | |
| 6051 | skb->protocol = eth_type_trans(skb, tp->dev); |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 6052 | |
| 6053 | if (len > (tp->dev->mtu + ETH_HLEN) && |
| 6054 | skb->protocol != htons(ETH_P_8021Q)) { |
| 6055 | dev_kfree_skb(skb); |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 6056 | goto drop_it_no_recycle; |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 6057 | } |
| 6058 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 6059 | if (desc->type_flags & RXD_FLAG_VLAN && |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 6060 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
| 6061 | __vlan_hwaccel_put_tag(skb, |
| 6062 | desc->err_vlan & RXD_VLAN_MASK); |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 6063 | |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 6064 | napi_gro_receive(&tnapi->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6065 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6066 | received++; |
| 6067 | budget--; |
| 6068 | |
| 6069 | next_pkt: |
| 6070 | (*post_ptr)++; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 6071 | |
| 6072 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6073 | tpr->rx_std_prod_idx = std_prod_idx & |
| 6074 | tp->rx_std_ring_mask; |
Matt Carlson | 86cfe4f | 2010-01-12 10:11:37 +0000 | [diff] [blame] | 6075 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6076 | tpr->rx_std_prod_idx); |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 6077 | work_mask &= ~RXD_OPAQUE_RING_STD; |
| 6078 | rx_std_posted = 0; |
| 6079 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6080 | next_pkt_nopost: |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 6081 | sw_idx++; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 6082 | sw_idx &= tp->rx_ret_ring_mask; |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 6083 | |
| 6084 | /* Refresh hw_idx to see if there is new work */ |
| 6085 | if (sw_idx == hw_idx) { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6086 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 6087 | rmb(); |
| 6088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | /* ACK the status ring. */ |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6092 | tnapi->rx_rcb_ptr = sw_idx; |
| 6093 | tw32_rx_mbox(tnapi->consmbox, sw_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6094 | |
| 6095 | /* Refill RX ring(s). */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6096 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 6097 | /* Sync BD data before updating mailbox */ |
| 6098 | wmb(); |
| 6099 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6100 | if (work_mask & RXD_OPAQUE_RING_STD) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6101 | tpr->rx_std_prod_idx = std_prod_idx & |
| 6102 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6103 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6104 | tpr->rx_std_prod_idx); |
| 6105 | } |
| 6106 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6107 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
| 6108 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6109 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 6110 | tpr->rx_jmb_prod_idx); |
| 6111 | } |
| 6112 | mmiowb(); |
| 6113 | } else if (work_mask) { |
| 6114 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be |
| 6115 | * updated before the producer indices can be updated. |
| 6116 | */ |
| 6117 | smp_wmb(); |
| 6118 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6119 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
| 6120 | 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] | 6121 | |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6122 | if (tnapi != &tp->napi[1]) { |
| 6123 | tp->rx_refill = true; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6124 | napi_schedule(&tp->napi[1].napi); |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6126 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6127 | |
| 6128 | return received; |
| 6129 | } |
| 6130 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6131 | static void tg3_poll_link(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6132 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6133 | /* handle link change and other phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6134 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6135 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
| 6136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6137 | if (sblk->status & SD_STATUS_LINK_CHG) { |
| 6138 | sblk->status = SD_STATUS_UPDATED | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6139 | (sblk->status & ~SD_STATUS_LINK_CHG); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6140 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6141 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 6142 | tw32_f(MAC_STATUS, |
| 6143 | (MAC_STATUS_SYNC_CHANGED | |
| 6144 | MAC_STATUS_CFG_CHANGED | |
| 6145 | MAC_STATUS_MI_COMPLETION | |
| 6146 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 6147 | udelay(40); |
| 6148 | } else |
| 6149 | tg3_setup_phy(tp, 0); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6150 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6151 | } |
| 6152 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6153 | } |
| 6154 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6155 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
| 6156 | struct tg3_rx_prodring_set *dpr, |
| 6157 | struct tg3_rx_prodring_set *spr) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6158 | { |
| 6159 | u32 si, di, cpycnt, src_prod_idx; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6160 | int i, err = 0; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6161 | |
| 6162 | while (1) { |
| 6163 | src_prod_idx = spr->rx_std_prod_idx; |
| 6164 | |
| 6165 | /* Make sure updates to the rx_std_buffers[] entries and the |
| 6166 | * standard producer index are seen in the correct order. |
| 6167 | */ |
| 6168 | smp_rmb(); |
| 6169 | |
| 6170 | if (spr->rx_std_cons_idx == src_prod_idx) |
| 6171 | break; |
| 6172 | |
| 6173 | if (spr->rx_std_cons_idx < src_prod_idx) |
| 6174 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; |
| 6175 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6176 | cpycnt = tp->rx_std_ring_mask + 1 - |
| 6177 | spr->rx_std_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6178 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6179 | cpycnt = min(cpycnt, |
| 6180 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6181 | |
| 6182 | si = spr->rx_std_cons_idx; |
| 6183 | di = dpr->rx_std_prod_idx; |
| 6184 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6185 | for (i = di; i < di + cpycnt; i++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6186 | if (dpr->rx_std_buffers[i].data) { |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6187 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6188 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6189 | break; |
| 6190 | } |
| 6191 | } |
| 6192 | |
| 6193 | if (!cpycnt) |
| 6194 | break; |
| 6195 | |
| 6196 | /* Ensure that updates to the rx_std_buffers ring and the |
| 6197 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 6198 | * ordered correctly WRT the skb check above. |
| 6199 | */ |
| 6200 | smp_rmb(); |
| 6201 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6202 | memcpy(&dpr->rx_std_buffers[di], |
| 6203 | &spr->rx_std_buffers[si], |
| 6204 | cpycnt * sizeof(struct ring_info)); |
| 6205 | |
| 6206 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 6207 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 6208 | sbd = &spr->rx_std[si]; |
| 6209 | dbd = &dpr->rx_std[di]; |
| 6210 | dbd->addr_hi = sbd->addr_hi; |
| 6211 | dbd->addr_lo = sbd->addr_lo; |
| 6212 | } |
| 6213 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6214 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
| 6215 | tp->rx_std_ring_mask; |
| 6216 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & |
| 6217 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6218 | } |
| 6219 | |
| 6220 | while (1) { |
| 6221 | src_prod_idx = spr->rx_jmb_prod_idx; |
| 6222 | |
| 6223 | /* Make sure updates to the rx_jmb_buffers[] entries and |
| 6224 | * the jumbo producer index are seen in the correct order. |
| 6225 | */ |
| 6226 | smp_rmb(); |
| 6227 | |
| 6228 | if (spr->rx_jmb_cons_idx == src_prod_idx) |
| 6229 | break; |
| 6230 | |
| 6231 | if (spr->rx_jmb_cons_idx < src_prod_idx) |
| 6232 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; |
| 6233 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6234 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
| 6235 | spr->rx_jmb_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6236 | |
| 6237 | cpycnt = min(cpycnt, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6238 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6239 | |
| 6240 | si = spr->rx_jmb_cons_idx; |
| 6241 | di = dpr->rx_jmb_prod_idx; |
| 6242 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6243 | for (i = di; i < di + cpycnt; i++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6244 | if (dpr->rx_jmb_buffers[i].data) { |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6245 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6246 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6247 | break; |
| 6248 | } |
| 6249 | } |
| 6250 | |
| 6251 | if (!cpycnt) |
| 6252 | break; |
| 6253 | |
| 6254 | /* Ensure that updates to the rx_jmb_buffers ring and the |
| 6255 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 6256 | * ordered correctly WRT the skb check above. |
| 6257 | */ |
| 6258 | smp_rmb(); |
| 6259 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6260 | memcpy(&dpr->rx_jmb_buffers[di], |
| 6261 | &spr->rx_jmb_buffers[si], |
| 6262 | cpycnt * sizeof(struct ring_info)); |
| 6263 | |
| 6264 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 6265 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 6266 | sbd = &spr->rx_jmb[si].std; |
| 6267 | dbd = &dpr->rx_jmb[di].std; |
| 6268 | dbd->addr_hi = sbd->addr_hi; |
| 6269 | dbd->addr_lo = sbd->addr_lo; |
| 6270 | } |
| 6271 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6272 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
| 6273 | tp->rx_jmb_ring_mask; |
| 6274 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & |
| 6275 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6276 | } |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6277 | |
| 6278 | return err; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6279 | } |
| 6280 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6281 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
| 6282 | { |
| 6283 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6284 | |
| 6285 | /* run TX completion thread */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6286 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6287 | tg3_tx(tnapi); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6288 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6289 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | } |
| 6291 | |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 6292 | if (!tnapi->rx_rcb_prod_idx) |
| 6293 | return work_done; |
| 6294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6295 | /* run RX thread, within the bounds set by NAPI. |
| 6296 | * All RX "locking" is done by ensuring outside |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6297 | * code synchronizes with tg3->napi.poll() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | */ |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6299 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6300 | work_done += tg3_rx(tnapi, budget - work_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6301 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6302 | if (tg3_flag(tp, ENABLE_RSS) && tnapi == &tp->napi[1]) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6303 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6304 | int i, err = 0; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6305 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
| 6306 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6307 | |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6308 | tp->rx_refill = false; |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 6309 | for (i = 1; i <= tp->rxq_cnt; i++) |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6310 | err |= tg3_rx_prodring_xfer(tp, dpr, |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6311 | &tp->napi[i].prodring); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6312 | |
| 6313 | wmb(); |
| 6314 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6315 | if (std_prod_idx != dpr->rx_std_prod_idx) |
| 6316 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6317 | dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6318 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6319 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
| 6320 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 6321 | dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6322 | |
| 6323 | mmiowb(); |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6324 | |
| 6325 | if (err) |
| 6326 | tw32_f(HOSTCC_MODE, tp->coal_now); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6327 | } |
| 6328 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6329 | return work_done; |
| 6330 | } |
David S. Miller | f7383c2 | 2005-05-18 22:50:53 -0700 | [diff] [blame] | 6331 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6332 | static inline void tg3_reset_task_schedule(struct tg3 *tp) |
| 6333 | { |
| 6334 | if (!test_and_set_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags)) |
| 6335 | schedule_work(&tp->reset_task); |
| 6336 | } |
| 6337 | |
| 6338 | static inline void tg3_reset_task_cancel(struct tg3 *tp) |
| 6339 | { |
| 6340 | cancel_work_sync(&tp->reset_task); |
| 6341 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
Matt Carlson | c710135 | 2012-02-22 12:35:20 +0000 | [diff] [blame] | 6342 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6343 | } |
| 6344 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6345 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
| 6346 | { |
| 6347 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 6348 | struct tg3 *tp = tnapi->tp; |
| 6349 | int work_done = 0; |
| 6350 | struct tg3_hw_status *sblk = tnapi->hw_status; |
| 6351 | |
| 6352 | while (1) { |
| 6353 | work_done = tg3_poll_work(tnapi, work_done, budget); |
| 6354 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6355 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6356 | goto tx_recovery; |
| 6357 | |
| 6358 | if (unlikely(work_done >= budget)) |
| 6359 | break; |
| 6360 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 6361 | /* tp->last_tag is used in tg3_int_reenable() below |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6362 | * to tell the hw how much work has been processed, |
| 6363 | * so we must read it before checking for more work. |
| 6364 | */ |
| 6365 | tnapi->last_tag = sblk->status_tag; |
| 6366 | tnapi->last_irq_tag = tnapi->last_tag; |
| 6367 | rmb(); |
| 6368 | |
| 6369 | /* check for RX/TX work to do */ |
Matt Carlson | 6d40db7 | 2010-04-05 10:19:20 +0000 | [diff] [blame] | 6370 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
| 6371 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6372 | |
| 6373 | /* This test here is not race free, but will reduce |
| 6374 | * the number of interrupts by looping again. |
| 6375 | */ |
| 6376 | if (tnapi == &tp->napi[1] && tp->rx_refill) |
| 6377 | continue; |
| 6378 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6379 | napi_complete(napi); |
| 6380 | /* Reenable interrupts. */ |
| 6381 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6382 | |
| 6383 | /* This test here is synchronized by napi_schedule() |
| 6384 | * and napi_complete() to close the race condition. |
| 6385 | */ |
| 6386 | if (unlikely(tnapi == &tp->napi[1] && tp->rx_refill)) { |
| 6387 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
| 6388 | HOSTCC_MODE_ENABLE | |
| 6389 | tnapi->coal_now); |
| 6390 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6391 | mmiowb(); |
| 6392 | break; |
| 6393 | } |
| 6394 | } |
| 6395 | |
| 6396 | return work_done; |
| 6397 | |
| 6398 | tx_recovery: |
| 6399 | /* work_done is guaranteed to be less than budget. */ |
| 6400 | napi_complete(napi); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6401 | tg3_reset_task_schedule(tp); |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6402 | return work_done; |
| 6403 | } |
| 6404 | |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6405 | static void tg3_process_error(struct tg3 *tp) |
| 6406 | { |
| 6407 | u32 val; |
| 6408 | bool real_error = false; |
| 6409 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6410 | if (tg3_flag(tp, ERROR_PROCESSED)) |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6411 | return; |
| 6412 | |
| 6413 | /* Check Flow Attention register */ |
| 6414 | val = tr32(HOSTCC_FLOW_ATTN); |
| 6415 | if (val & ~HOSTCC_FLOW_ATTN_MBUF_LWM) { |
| 6416 | netdev_err(tp->dev, "FLOW Attention error. Resetting chip.\n"); |
| 6417 | real_error = true; |
| 6418 | } |
| 6419 | |
| 6420 | if (tr32(MSGINT_STATUS) & ~MSGINT_STATUS_MSI_REQ) { |
| 6421 | netdev_err(tp->dev, "MSI Status error. Resetting chip.\n"); |
| 6422 | real_error = true; |
| 6423 | } |
| 6424 | |
| 6425 | if (tr32(RDMAC_STATUS) || tr32(WDMAC_STATUS)) { |
| 6426 | netdev_err(tp->dev, "DMA Status error. Resetting chip.\n"); |
| 6427 | real_error = true; |
| 6428 | } |
| 6429 | |
| 6430 | if (!real_error) |
| 6431 | return; |
| 6432 | |
| 6433 | tg3_dump_state(tp); |
| 6434 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6435 | tg3_flag_set(tp, ERROR_PROCESSED); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6436 | tg3_reset_task_schedule(tp); |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6437 | } |
| 6438 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6439 | static int tg3_poll(struct napi_struct *napi, int budget) |
| 6440 | { |
Matt Carlson | 8ef0442 | 2009-08-28 14:01:37 +0000 | [diff] [blame] | 6441 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 6442 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6443 | int work_done = 0; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6444 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6445 | |
| 6446 | while (1) { |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6447 | if (sblk->status & SD_STATUS_ERROR) |
| 6448 | tg3_process_error(tp); |
| 6449 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6450 | tg3_poll_link(tp); |
| 6451 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6452 | work_done = tg3_poll_work(tnapi, work_done, budget); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6453 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6454 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6455 | goto tx_recovery; |
| 6456 | |
| 6457 | if (unlikely(work_done >= budget)) |
| 6458 | break; |
| 6459 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6460 | if (tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6461 | /* tp->last_tag is used in tg3_int_reenable() below |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6462 | * to tell the hw how much work has been processed, |
| 6463 | * so we must read it before checking for more work. |
| 6464 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6465 | tnapi->last_tag = sblk->status_tag; |
| 6466 | tnapi->last_irq_tag = tnapi->last_tag; |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6467 | rmb(); |
| 6468 | } else |
| 6469 | sblk->status &= ~SD_STATUS_UPDATED; |
| 6470 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6471 | if (likely(!tg3_has_work(tnapi))) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 6472 | napi_complete(napi); |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6473 | tg3_int_reenable(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6474 | break; |
| 6475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6476 | } |
| 6477 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6478 | return work_done; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6479 | |
| 6480 | tx_recovery: |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6481 | /* work_done is guaranteed to be less than budget. */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 6482 | napi_complete(napi); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6483 | tg3_reset_task_schedule(tp); |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6484 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6485 | } |
| 6486 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6487 | static void tg3_napi_disable(struct tg3 *tp) |
| 6488 | { |
| 6489 | int i; |
| 6490 | |
| 6491 | for (i = tp->irq_cnt - 1; i >= 0; i--) |
| 6492 | napi_disable(&tp->napi[i].napi); |
| 6493 | } |
| 6494 | |
| 6495 | static void tg3_napi_enable(struct tg3 *tp) |
| 6496 | { |
| 6497 | int i; |
| 6498 | |
| 6499 | for (i = 0; i < tp->irq_cnt; i++) |
| 6500 | napi_enable(&tp->napi[i].napi); |
| 6501 | } |
| 6502 | |
| 6503 | static void tg3_napi_init(struct tg3 *tp) |
| 6504 | { |
| 6505 | int i; |
| 6506 | |
| 6507 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); |
| 6508 | for (i = 1; i < tp->irq_cnt; i++) |
| 6509 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); |
| 6510 | } |
| 6511 | |
| 6512 | static void tg3_napi_fini(struct tg3 *tp) |
| 6513 | { |
| 6514 | int i; |
| 6515 | |
| 6516 | for (i = 0; i < tp->irq_cnt; i++) |
| 6517 | netif_napi_del(&tp->napi[i].napi); |
| 6518 | } |
| 6519 | |
| 6520 | static inline void tg3_netif_stop(struct tg3 *tp) |
| 6521 | { |
| 6522 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 6523 | tg3_napi_disable(tp); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 6524 | netif_carrier_off(tp->dev); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6525 | netif_tx_disable(tp->dev); |
| 6526 | } |
| 6527 | |
| 6528 | static inline void tg3_netif_start(struct tg3 *tp) |
| 6529 | { |
| 6530 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
| 6531 | * appropriate so long as all callers are assured to |
| 6532 | * have free tx slots (such as after tg3_init_hw) |
| 6533 | */ |
| 6534 | netif_tx_wake_all_queues(tp->dev); |
| 6535 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 6536 | if (tp->link_up) |
| 6537 | netif_carrier_on(tp->dev); |
| 6538 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6539 | tg3_napi_enable(tp); |
| 6540 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; |
| 6541 | tg3_enable_ints(tp); |
| 6542 | } |
| 6543 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6544 | static void tg3_irq_quiesce(struct tg3 *tp) |
| 6545 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6546 | int i; |
| 6547 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6548 | BUG_ON(tp->irq_sync); |
| 6549 | |
| 6550 | tp->irq_sync = 1; |
| 6551 | smp_mb(); |
| 6552 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6553 | for (i = 0; i < tp->irq_cnt; i++) |
| 6554 | synchronize_irq(tp->napi[i].irq_vec); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6555 | } |
| 6556 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6557 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
| 6558 | * If irq_sync is non-zero, then the IRQ handler must be synchronized |
| 6559 | * with as well. Most of the time, this is not necessary except when |
| 6560 | * shutting down the device. |
| 6561 | */ |
| 6562 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) |
| 6563 | { |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 6564 | spin_lock_bh(&tp->lock); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6565 | if (irq_sync) |
| 6566 | tg3_irq_quiesce(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6567 | } |
| 6568 | |
| 6569 | static inline void tg3_full_unlock(struct tg3 *tp) |
| 6570 | { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6571 | spin_unlock_bh(&tp->lock); |
| 6572 | } |
| 6573 | |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6574 | /* One-shot MSI handler - Chip automatically disables interrupt |
| 6575 | * after sending MSI so driver doesn't have to do it. |
| 6576 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6577 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [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; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6581 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6582 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6583 | if (tnapi->rx_rcb) |
| 6584 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6585 | |
| 6586 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6587 | napi_schedule(&tnapi->napi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6588 | |
| 6589 | return IRQ_HANDLED; |
| 6590 | } |
| 6591 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6592 | /* MSI ISR - No need to check for interrupt sharing and no need to |
| 6593 | * flush status block and interrupt mailbox. PCI ordering rules |
| 6594 | * guarantee that MSI will arrive after the status block. |
| 6595 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6596 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6597 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6598 | struct tg3_napi *tnapi = dev_id; |
| 6599 | struct tg3 *tp = tnapi->tp; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6600 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6601 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6602 | if (tnapi->rx_rcb) |
| 6603 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6604 | /* |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6605 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6606 | * chip-internal interrupt pending events. |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6607 | * Writing non-zero to intr-mbox-0 additional tells the |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6608 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6609 | * event coalescing. |
| 6610 | */ |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 6611 | tw32_mailbox(tnapi->int_mbox, 0x00000001); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 6612 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6613 | napi_schedule(&tnapi->napi); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 6614 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6615 | return IRQ_RETVAL(1); |
| 6616 | } |
| 6617 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6618 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6619 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6620 | struct tg3_napi *tnapi = dev_id; |
| 6621 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6622 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6623 | unsigned int handled = 1; |
| 6624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6625 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 6626 | * the CPU before the status block posted prior to the interrupt. |
| 6627 | * Reading the PCI State register will confirm whether the |
| 6628 | * interrupt is ours and will flush the status block. |
| 6629 | */ |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6630 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6631 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6632 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 6633 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6634 | goto out; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6635 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6636 | } |
| 6637 | |
| 6638 | /* |
| 6639 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
| 6640 | * chip-internal interrupt pending events. |
| 6641 | * Writing non-zero to intr-mbox-0 additional tells the |
| 6642 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6643 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6644 | * |
| 6645 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 6646 | * spurious interrupts. The flush impacts performance but |
| 6647 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6648 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6649 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6650 | if (tg3_irq_sync(tp)) |
| 6651 | goto out; |
| 6652 | sblk->status &= ~SD_STATUS_UPDATED; |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6653 | if (likely(tg3_has_work(tnapi))) { |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6654 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6655 | napi_schedule(&tnapi->napi); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6656 | } else { |
| 6657 | /* No work, shared interrupt perhaps? re-enable |
| 6658 | * interrupts, and flush that PCI write |
| 6659 | */ |
| 6660 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, |
| 6661 | 0x00000000); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6662 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6663 | out: |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6664 | return IRQ_RETVAL(handled); |
| 6665 | } |
| 6666 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6667 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6668 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6669 | struct tg3_napi *tnapi = dev_id; |
| 6670 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6671 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6672 | unsigned int handled = 1; |
| 6673 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6674 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 6675 | * the CPU before the status block posted prior to the interrupt. |
| 6676 | * Reading the PCI State register will confirm whether the |
| 6677 | * interrupt is ours and will flush the status block. |
| 6678 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6679 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6680 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6681 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 6682 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6683 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6684 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6685 | } |
| 6686 | |
| 6687 | /* |
| 6688 | * writing any value to intr-mbox-0 clears PCI INTA# and |
| 6689 | * chip-internal interrupt pending events. |
| 6690 | * writing non-zero to intr-mbox-0 additional tells the |
| 6691 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6692 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6693 | * |
| 6694 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 6695 | * spurious interrupts. The flush impacts performance but |
| 6696 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6697 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6698 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6699 | |
| 6700 | /* |
| 6701 | * In a shared interrupt configuration, sometimes other devices' |
| 6702 | * interrupts will scream. We record the current status tag here |
| 6703 | * so that the above check can report that the screaming interrupts |
| 6704 | * are unhandled. Eventually they will be silenced. |
| 6705 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6706 | tnapi->last_irq_tag = sblk->status_tag; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6707 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6708 | if (tg3_irq_sync(tp)) |
| 6709 | goto out; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6710 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6711 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6712 | |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6713 | napi_schedule(&tnapi->napi); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6714 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6715 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6716 | return IRQ_RETVAL(handled); |
| 6717 | } |
| 6718 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6719 | /* ISR for interrupt test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6720 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6721 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6722 | struct tg3_napi *tnapi = dev_id; |
| 6723 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6724 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6725 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 6726 | if ((sblk->status & SD_STATUS_UPDATED) || |
| 6727 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 6728 | tg3_disable_ints(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6729 | return IRQ_RETVAL(1); |
| 6730 | } |
| 6731 | return IRQ_RETVAL(0); |
| 6732 | } |
| 6733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6734 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6735 | static void tg3_poll_controller(struct net_device *dev) |
| 6736 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6737 | int i; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6738 | struct tg3 *tp = netdev_priv(dev); |
| 6739 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6740 | for (i = 0; i < tp->irq_cnt; i++) |
Louis Rilling | fe234f0 | 2010-03-09 06:14:41 +0000 | [diff] [blame] | 6741 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6742 | } |
| 6743 | #endif |
| 6744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6745 | static void tg3_tx_timeout(struct net_device *dev) |
| 6746 | { |
| 6747 | struct tg3 *tp = netdev_priv(dev); |
| 6748 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 6749 | if (netif_msg_tx_err(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 6750 | netdev_err(dev, "transmit timed out, resetting\n"); |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6751 | tg3_dump_state(tp); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 6752 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6753 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6754 | tg3_reset_task_schedule(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6755 | } |
| 6756 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6757 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
| 6758 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) |
| 6759 | { |
| 6760 | u32 base = (u32) mapping & 0xffffffff; |
| 6761 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 6762 | return (base > 0xffffdcc0) && (base + len + 8 < base); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6763 | } |
| 6764 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6765 | /* Test for DMA addresses > 40-bit */ |
| 6766 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 6767 | int len) |
| 6768 | { |
| 6769 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6770 | if (tg3_flag(tp, 40BIT_DMA_BUG)) |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 6771 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6772 | return 0; |
| 6773 | #else |
| 6774 | return 0; |
| 6775 | #endif |
| 6776 | } |
| 6777 | |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6778 | 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] | 6779 | dma_addr_t mapping, u32 len, u32 flags, |
| 6780 | u32 mss, u32 vlan) |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6781 | { |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6782 | txbd->addr_hi = ((u64) mapping >> 32); |
| 6783 | txbd->addr_lo = ((u64) mapping & 0xffffffff); |
| 6784 | txbd->len_flags = (len << TXD_LEN_SHIFT) | (flags & 0x0000ffff); |
| 6785 | txbd->vlan_tag = (mss << TXD_MSS_SHIFT) | (vlan << TXD_VLAN_TAG_SHIFT); |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6786 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6787 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6788 | 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] | 6789 | dma_addr_t map, u32 len, u32 flags, |
| 6790 | u32 mss, u32 vlan) |
| 6791 | { |
| 6792 | struct tg3 *tp = tnapi->tp; |
| 6793 | bool hwbug = false; |
| 6794 | |
| 6795 | if (tg3_flag(tp, SHORT_DMA_BUG) && len <= 8) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6796 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6797 | |
| 6798 | if (tg3_4g_overflow_test(map, len)) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6799 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6800 | |
| 6801 | if (tg3_40bit_overflow_test(tp, map, len)) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6802 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6803 | |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 6804 | if (tp->dma_limit) { |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6805 | u32 prvidx = *entry; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6806 | u32 tmp_flag = flags & ~TXD_FLAG_END; |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 6807 | while (len > tp->dma_limit && *budget) { |
| 6808 | u32 frag_len = tp->dma_limit; |
| 6809 | len -= tp->dma_limit; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6810 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6811 | /* Avoid the 8byte DMA problem */ |
| 6812 | if (len <= 8) { |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 6813 | len += tp->dma_limit / 2; |
| 6814 | frag_len = tp->dma_limit / 2; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6815 | } |
| 6816 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6817 | tnapi->tx_buffers[*entry].fragmented = true; |
| 6818 | |
| 6819 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 6820 | frag_len, tmp_flag, mss, vlan); |
| 6821 | *budget -= 1; |
| 6822 | prvidx = *entry; |
| 6823 | *entry = NEXT_TX(*entry); |
| 6824 | |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6825 | map += frag_len; |
| 6826 | } |
| 6827 | |
| 6828 | if (len) { |
| 6829 | if (*budget) { |
| 6830 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 6831 | len, flags, mss, vlan); |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6832 | *budget -= 1; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6833 | *entry = NEXT_TX(*entry); |
| 6834 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 6835 | hwbug = true; |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6836 | tnapi->tx_buffers[prvidx].fragmented = false; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6837 | } |
| 6838 | } |
| 6839 | } else { |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6840 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 6841 | len, flags, mss, vlan); |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 6842 | *entry = NEXT_TX(*entry); |
| 6843 | } |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6844 | |
| 6845 | return hwbug; |
| 6846 | } |
| 6847 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 6848 | 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] | 6849 | { |
| 6850 | int i; |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 6851 | struct sk_buff *skb; |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 6852 | struct tg3_tx_ring_info *txb = &tnapi->tx_buffers[entry]; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6853 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 6854 | skb = txb->skb; |
| 6855 | txb->skb = NULL; |
| 6856 | |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6857 | pci_unmap_single(tnapi->tp->pdev, |
| 6858 | dma_unmap_addr(txb, mapping), |
| 6859 | skb_headlen(skb), |
| 6860 | PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 6861 | |
| 6862 | while (txb->fragmented) { |
| 6863 | txb->fragmented = false; |
| 6864 | entry = NEXT_TX(entry); |
| 6865 | txb = &tnapi->tx_buffers[entry]; |
| 6866 | } |
| 6867 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 6868 | for (i = 0; i <= last; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6869 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6870 | |
| 6871 | entry = NEXT_TX(entry); |
| 6872 | txb = &tnapi->tx_buffers[entry]; |
| 6873 | |
| 6874 | pci_unmap_page(tnapi->tp->pdev, |
| 6875 | dma_unmap_addr(txb, mapping), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6876 | skb_frag_size(frag), PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 6877 | |
| 6878 | while (txb->fragmented) { |
| 6879 | txb->fragmented = false; |
| 6880 | entry = NEXT_TX(entry); |
| 6881 | txb = &tnapi->tx_buffers[entry]; |
| 6882 | } |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6883 | } |
| 6884 | } |
| 6885 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6886 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6887 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6888 | struct sk_buff **pskb, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6889 | u32 *entry, u32 *budget, |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6890 | u32 base_flags, u32 mss, u32 vlan) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6891 | { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6892 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6893 | struct sk_buff *new_skb, *skb = *pskb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6894 | dma_addr_t new_addr = 0; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6895 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6896 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 6897 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 6898 | new_skb = skb_copy(skb, GFP_ATOMIC); |
| 6899 | else { |
| 6900 | int more_headroom = 4 - ((unsigned long)skb->data & 3); |
| 6901 | |
| 6902 | new_skb = skb_copy_expand(skb, |
| 6903 | skb_headroom(skb) + more_headroom, |
| 6904 | skb_tailroom(skb), GFP_ATOMIC); |
| 6905 | } |
| 6906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6907 | if (!new_skb) { |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6908 | ret = -1; |
| 6909 | } else { |
| 6910 | /* New SKB is guaranteed to be linear. */ |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6911 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
| 6912 | PCI_DMA_TODEVICE); |
| 6913 | /* Make sure the mapping succeeded */ |
| 6914 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6915 | dev_kfree_skb(new_skb); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6916 | ret = -1; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6917 | } else { |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 6918 | u32 save_entry = *entry; |
| 6919 | |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6920 | base_flags |= TXD_FLAG_END; |
| 6921 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6922 | tnapi->tx_buffers[*entry].skb = new_skb; |
| 6923 | dma_unmap_addr_set(&tnapi->tx_buffers[*entry], |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6924 | mapping, new_addr); |
| 6925 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6926 | if (tg3_tx_frag_set(tnapi, entry, budget, new_addr, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6927 | new_skb->len, base_flags, |
| 6928 | mss, vlan)) { |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 6929 | tg3_tx_skb_unmap(tnapi, save_entry, -1); |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6930 | dev_kfree_skb(new_skb); |
| 6931 | ret = -1; |
| 6932 | } |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6933 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6934 | } |
| 6935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6936 | dev_kfree_skb(skb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6937 | *pskb = new_skb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6938 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6939 | } |
| 6940 | |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6941 | 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] | 6942 | |
| 6943 | /* Use GSO to workaround a rare TSO bug that may be triggered when the |
| 6944 | * TSO header is greater than 80 bytes. |
| 6945 | */ |
| 6946 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) |
| 6947 | { |
| 6948 | struct sk_buff *segs, *nskb; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6949 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6950 | |
| 6951 | /* Estimate the number of fragments in the worst case */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6952 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6953 | netif_stop_queue(tp->dev); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 6954 | |
| 6955 | /* netif_tx_stop_queue() must be done before checking |
| 6956 | * checking tx index in tg3_tx_avail() below, because in |
| 6957 | * tg3_tx(), we update tx index before checking for |
| 6958 | * netif_tx_queue_stopped(). |
| 6959 | */ |
| 6960 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6961 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 6962 | return NETDEV_TX_BUSY; |
| 6963 | |
| 6964 | netif_wake_queue(tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6965 | } |
| 6966 | |
| 6967 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame] | 6968 | if (IS_ERR(segs)) |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6969 | goto tg3_tso_bug_end; |
| 6970 | |
| 6971 | do { |
| 6972 | nskb = segs; |
| 6973 | segs = segs->next; |
| 6974 | nskb->next = NULL; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6975 | tg3_start_xmit(nskb, tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6976 | } while (segs); |
| 6977 | |
| 6978 | tg3_tso_bug_end: |
| 6979 | dev_kfree_skb(skb); |
| 6980 | |
| 6981 | return NETDEV_TX_OK; |
| 6982 | } |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 6983 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 6984 | /* 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] | 6985 | * support TG3_FLAG_HW_TSO_1 or firmware TSO only. |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 6986 | */ |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 6987 | 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] | 6988 | { |
| 6989 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 6990 | u32 len, entry, base_flags, mss, vlan = 0; |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 6991 | u32 budget; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6992 | int i = -1, would_hit_hwbug; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 6993 | dma_addr_t mapping; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6994 | struct tg3_napi *tnapi; |
| 6995 | struct netdev_queue *txq; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 6996 | unsigned int last; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6997 | |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6998 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 6999 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7000 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7001 | tnapi++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7002 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7003 | budget = tg3_tx_avail(tnapi); |
| 7004 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 7005 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7006 | * 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] | 7007 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 7008 | * no IRQ context deadlocks to worry about either. Rejoice! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7009 | */ |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7010 | if (unlikely(budget <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7011 | if (!netif_tx_queue_stopped(txq)) { |
| 7012 | netif_tx_stop_queue(txq); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 7013 | |
| 7014 | /* This is a hard error, log it. */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7015 | netdev_err(dev, |
| 7016 | "BUG! Tx Ring full when queue awake!\n"); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 7017 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7018 | return NETDEV_TX_BUSY; |
| 7019 | } |
| 7020 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7021 | entry = tnapi->tx_prod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7022 | base_flags = 0; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 7023 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7024 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7025 | |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 7026 | mss = skb_shinfo(skb)->gso_size; |
| 7027 | if (mss) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7028 | struct iphdr *iph; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7029 | u32 tcp_opt_len, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7030 | |
| 7031 | if (skb_header_cloned(skb) && |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7032 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 7033 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7034 | |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7035 | iph = ip_hdr(skb); |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 7036 | tcp_opt_len = tcp_optlen(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7037 | |
Eric Dumazet | a5a1195 | 2012-01-23 01:22:09 +0000 | [diff] [blame] | 7038 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb) - ETH_HLEN; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7039 | |
Eric Dumazet | a5a1195 | 2012-01-23 01:22:09 +0000 | [diff] [blame] | 7040 | if (!skb_is_gso_v6(skb)) { |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7041 | iph->check = 0; |
| 7042 | iph->tot_len = htons(mss + hdr_len); |
| 7043 | } |
| 7044 | |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7045 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7046 | tg3_flag(tp, TSO_BUG)) |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 7047 | return tg3_tso_bug(tp, skb); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7049 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 7050 | TXD_FLAG_CPU_POST_DMA); |
| 7051 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7052 | if (tg3_flag(tp, HW_TSO_1) || |
| 7053 | tg3_flag(tp, HW_TSO_2) || |
| 7054 | tg3_flag(tp, HW_TSO_3)) { |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 7055 | tcp_hdr(skb)->check = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7056 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 7057 | } else |
| 7058 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 7059 | iph->daddr, 0, |
| 7060 | IPPROTO_TCP, |
| 7061 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7062 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7063 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 7064 | mss |= (hdr_len & 0xc) << 12; |
| 7065 | if (hdr_len & 0x10) |
| 7066 | base_flags |= 0x00000010; |
| 7067 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7068 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 7069 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7070 | else if (tg3_flag(tp, HW_TSO_1) || |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 7071 | 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] | 7072 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7073 | int tsflags; |
| 7074 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7075 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7076 | mss |= (tsflags << 11); |
| 7077 | } |
| 7078 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7079 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7080 | int tsflags; |
| 7081 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7082 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7083 | base_flags |= tsflags << 12; |
| 7084 | } |
| 7085 | } |
| 7086 | } |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 7087 | |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 7088 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 7089 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
| 7090 | base_flags |= TXD_FLAG_JMB_PKT; |
| 7091 | |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7092 | if (vlan_tx_tag_present(skb)) { |
| 7093 | base_flags |= TXD_FLAG_VLAN; |
| 7094 | vlan = vlan_tx_tag_get(skb); |
| 7095 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7096 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7097 | len = skb_headlen(skb); |
| 7098 | |
| 7099 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7100 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 7101 | goto drop; |
| 7102 | |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 7103 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7104 | tnapi->tx_buffers[entry].skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 7105 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7106 | |
| 7107 | would_hit_hwbug = 0; |
| 7108 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7109 | if (tg3_flag(tp, 5701_DMA_BUG)) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7110 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7111 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7112 | if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, len, base_flags | |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7113 | ((skb_shinfo(skb)->nr_frags == 0) ? TXD_FLAG_END : 0), |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7114 | mss, vlan)) { |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7115 | would_hit_hwbug = 1; |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7116 | } else if (skb_shinfo(skb)->nr_frags > 0) { |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7117 | u32 tmp_mss = mss; |
| 7118 | |
| 7119 | if (!tg3_flag(tp, HW_TSO_1) && |
| 7120 | !tg3_flag(tp, HW_TSO_2) && |
| 7121 | !tg3_flag(tp, HW_TSO_3)) |
| 7122 | tmp_mss = 0; |
| 7123 | |
Matt Carlson | c5665a5 | 2012-02-13 10:20:12 +0000 | [diff] [blame] | 7124 | /* Now loop through additional data |
| 7125 | * fragments, and queue them. |
| 7126 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7127 | last = skb_shinfo(skb)->nr_frags - 1; |
| 7128 | for (i = 0; i <= last; i++) { |
| 7129 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 7130 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7131 | len = skb_frag_size(frag); |
Ian Campbell | dc234d0 | 2011-08-24 22:28:11 +0000 | [diff] [blame] | 7132 | mapping = skb_frag_dma_map(&tp->pdev->dev, frag, 0, |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 7133 | len, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7134 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7135 | tnapi->tx_buffers[entry].skb = NULL; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 7136 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7137 | mapping); |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 7138 | if (dma_mapping_error(&tp->pdev->dev, mapping)) |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7139 | goto dma_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7140 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7141 | if (!budget || |
| 7142 | tg3_tx_frag_set(tnapi, &entry, &budget, mapping, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7143 | len, base_flags | |
| 7144 | ((i == last) ? TXD_FLAG_END : 0), |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7145 | tmp_mss, vlan)) { |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 7146 | would_hit_hwbug = 1; |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7147 | break; |
| 7148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7149 | } |
| 7150 | } |
| 7151 | |
| 7152 | if (would_hit_hwbug) { |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7153 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7154 | |
| 7155 | /* If the workaround fails due to memory/mapping |
| 7156 | * failure, silently drop this packet. |
| 7157 | */ |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7158 | entry = tnapi->tx_prod; |
| 7159 | budget = tg3_tx_avail(tnapi); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7160 | if (tigon3_dma_hwbug_workaround(tnapi, &skb, &entry, &budget, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7161 | base_flags, mss, vlan)) |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7162 | goto drop_nofree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7163 | } |
| 7164 | |
Richard Cochran | d515b45 | 2011-06-19 03:31:41 +0000 | [diff] [blame] | 7165 | skb_tx_timestamp(skb); |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 7166 | netdev_tx_sent_queue(txq, skb->len); |
Richard Cochran | d515b45 | 2011-06-19 03:31:41 +0000 | [diff] [blame] | 7167 | |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 7168 | /* Sync BD data before updating mailbox */ |
| 7169 | wmb(); |
| 7170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7171 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7172 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7173 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7174 | tnapi->tx_prod = entry; |
| 7175 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7176 | netif_tx_stop_queue(txq); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 7177 | |
| 7178 | /* netif_tx_stop_queue() must be done before checking |
| 7179 | * checking tx index in tg3_tx_avail() below, because in |
| 7180 | * tg3_tx(), we update tx index before checking for |
| 7181 | * netif_tx_queue_stopped(). |
| 7182 | */ |
| 7183 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7184 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7185 | netif_tx_wake_queue(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 7186 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7187 | |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 7188 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7189 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7190 | |
| 7191 | dma_error: |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7192 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, --i); |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7193 | tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7194 | drop: |
| 7195 | dev_kfree_skb(skb); |
| 7196 | drop_nofree: |
| 7197 | tp->tx_dropped++; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7198 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7199 | } |
| 7200 | |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7201 | static void tg3_mac_loopback(struct tg3 *tp, bool enable) |
| 7202 | { |
| 7203 | if (enable) { |
| 7204 | tp->mac_mode &= ~(MAC_MODE_HALF_DUPLEX | |
| 7205 | MAC_MODE_PORT_MODE_MASK); |
| 7206 | |
| 7207 | tp->mac_mode |= MAC_MODE_PORT_INT_LPBACK; |
| 7208 | |
| 7209 | if (!tg3_flag(tp, 5705_PLUS)) |
| 7210 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
| 7211 | |
| 7212 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 7213 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 7214 | else |
| 7215 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7216 | } else { |
| 7217 | tp->mac_mode &= ~MAC_MODE_PORT_INT_LPBACK; |
| 7218 | |
| 7219 | if (tg3_flag(tp, 5705_PLUS) || |
| 7220 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) || |
| 7221 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
| 7222 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 7223 | } |
| 7224 | |
| 7225 | tw32(MAC_MODE, tp->mac_mode); |
| 7226 | udelay(40); |
| 7227 | } |
| 7228 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7229 | 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] | 7230 | { |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7231 | u32 val, bmcr, mac_mode, ptest = 0; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7232 | |
| 7233 | tg3_phy_toggle_apd(tp, false); |
| 7234 | tg3_phy_toggle_automdix(tp, 0); |
| 7235 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7236 | if (extlpbk && tg3_phy_set_extloopbk(tp)) |
| 7237 | return -EIO; |
| 7238 | |
| 7239 | bmcr = BMCR_FULLDPLX; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7240 | switch (speed) { |
| 7241 | case SPEED_10: |
| 7242 | break; |
| 7243 | case SPEED_100: |
| 7244 | bmcr |= BMCR_SPEED100; |
| 7245 | break; |
| 7246 | case SPEED_1000: |
| 7247 | default: |
| 7248 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 7249 | speed = SPEED_100; |
| 7250 | bmcr |= BMCR_SPEED100; |
| 7251 | } else { |
| 7252 | speed = SPEED_1000; |
| 7253 | bmcr |= BMCR_SPEED1000; |
| 7254 | } |
| 7255 | } |
| 7256 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7257 | if (extlpbk) { |
| 7258 | if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 7259 | tg3_readphy(tp, MII_CTRL1000, &val); |
| 7260 | val |= CTL1000_AS_MASTER | |
| 7261 | CTL1000_ENABLE_MASTER; |
| 7262 | tg3_writephy(tp, MII_CTRL1000, val); |
| 7263 | } else { |
| 7264 | ptest = MII_TG3_FET_PTEST_TRIM_SEL | |
| 7265 | MII_TG3_FET_PTEST_TRIM_2; |
| 7266 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest); |
| 7267 | } |
| 7268 | } else |
| 7269 | bmcr |= BMCR_LOOPBACK; |
| 7270 | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7271 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 7272 | |
| 7273 | /* The write needs to be flushed for the FETs */ |
| 7274 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 7275 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 7276 | |
| 7277 | udelay(40); |
| 7278 | |
| 7279 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
| 7280 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7281 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7282 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
| 7283 | MII_TG3_FET_PTEST_FRC_TX_LOCK); |
| 7284 | |
| 7285 | /* The write needs to be flushed for the AC131 */ |
| 7286 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); |
| 7287 | } |
| 7288 | |
| 7289 | /* Reset to prevent losing 1st rx packet intermittently */ |
| 7290 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
| 7291 | tg3_flag(tp, 5780_CLASS)) { |
| 7292 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 7293 | udelay(10); |
| 7294 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 7295 | } |
| 7296 | |
| 7297 | mac_mode = tp->mac_mode & |
| 7298 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 7299 | if (speed == SPEED_1000) |
| 7300 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7301 | else |
| 7302 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 7303 | |
| 7304 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
| 7305 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
| 7306 | |
| 7307 | if (masked_phy_id == TG3_PHY_ID_BCM5401) |
| 7308 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 7309 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
| 7310 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 7311 | |
| 7312 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 7313 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 7314 | } |
| 7315 | |
| 7316 | tw32(MAC_MODE, mac_mode); |
| 7317 | udelay(40); |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7318 | |
| 7319 | return 0; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7320 | } |
| 7321 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7322 | 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] | 7323 | { |
| 7324 | struct tg3 *tp = netdev_priv(dev); |
| 7325 | |
| 7326 | if (features & NETIF_F_LOOPBACK) { |
| 7327 | if (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK) |
| 7328 | return; |
| 7329 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7330 | spin_lock_bh(&tp->lock); |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7331 | tg3_mac_loopback(tp, true); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7332 | netif_carrier_on(tp->dev); |
| 7333 | spin_unlock_bh(&tp->lock); |
| 7334 | netdev_info(dev, "Internal MAC loopback mode enabled.\n"); |
| 7335 | } else { |
| 7336 | if (!(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
| 7337 | return; |
| 7338 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7339 | spin_lock_bh(&tp->lock); |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7340 | tg3_mac_loopback(tp, false); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7341 | /* Force link status check */ |
| 7342 | tg3_setup_phy(tp, 1); |
| 7343 | spin_unlock_bh(&tp->lock); |
| 7344 | netdev_info(dev, "Internal MAC loopback mode disabled.\n"); |
| 7345 | } |
| 7346 | } |
| 7347 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7348 | static netdev_features_t tg3_fix_features(struct net_device *dev, |
| 7349 | netdev_features_t features) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 7350 | { |
| 7351 | struct tg3 *tp = netdev_priv(dev); |
| 7352 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7353 | if (dev->mtu > ETH_DATA_LEN && tg3_flag(tp, 5780_CLASS)) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 7354 | features &= ~NETIF_F_ALL_TSO; |
| 7355 | |
| 7356 | return features; |
| 7357 | } |
| 7358 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7359 | 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] | 7360 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7361 | netdev_features_t changed = dev->features ^ features; |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7362 | |
| 7363 | if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) |
| 7364 | tg3_set_loopback(dev, features); |
| 7365 | |
| 7366 | return 0; |
| 7367 | } |
| 7368 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7369 | static void tg3_rx_prodring_free(struct tg3 *tp, |
| 7370 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7371 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7372 | int i; |
| 7373 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7374 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7375 | 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] | 7376 | i = (i + 1) & tp->rx_std_ring_mask) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7377 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7378 | tp->rx_pkt_map_sz); |
| 7379 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7380 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7381 | for (i = tpr->rx_jmb_cons_idx; |
| 7382 | i != tpr->rx_jmb_prod_idx; |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7383 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7384 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7385 | TG3_RX_JMB_MAP_SZ); |
| 7386 | } |
| 7387 | } |
| 7388 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7389 | return; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7391 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7392 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7393 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7394 | tp->rx_pkt_map_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7395 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7396 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7397 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7398 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7399 | TG3_RX_JMB_MAP_SZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7400 | } |
| 7401 | } |
| 7402 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 7403 | /* Initialize rx rings for packet processing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7404 | * |
| 7405 | * The chip has been shut down and the driver detached from |
| 7406 | * the networking, so no interrupts or new tx packets will |
| 7407 | * end up in the driver. tp->{tx,}lock are held and thus |
| 7408 | * we may not sleep. |
| 7409 | */ |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7410 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
| 7411 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7412 | { |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7413 | u32 i, rx_pkt_dma_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7414 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7415 | tpr->rx_std_cons_idx = 0; |
| 7416 | tpr->rx_std_prod_idx = 0; |
| 7417 | tpr->rx_jmb_cons_idx = 0; |
| 7418 | tpr->rx_jmb_prod_idx = 0; |
| 7419 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7420 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7421 | memset(&tpr->rx_std_buffers[0], 0, |
| 7422 | TG3_RX_STD_BUFF_RING_SIZE(tp)); |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 7423 | if (tpr->rx_jmb_buffers) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7424 | memset(&tpr->rx_jmb_buffers[0], 0, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7425 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7426 | goto done; |
| 7427 | } |
| 7428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7429 | /* Zero out all descriptors. */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7430 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7431 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7432 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7433 | if (tg3_flag(tp, 5780_CLASS) && |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7434 | tp->dev->mtu > ETH_DATA_LEN) |
| 7435 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; |
| 7436 | 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] | 7437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7438 | /* Initialize invariants of the rings, we only set this |
| 7439 | * stuff once. This works because the card does not |
| 7440 | * write into the rx buffer posting rings. |
| 7441 | */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7442 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7443 | struct tg3_rx_buffer_desc *rxd; |
| 7444 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7445 | rxd = &tpr->rx_std[i]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7446 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7447 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
| 7448 | rxd->opaque = (RXD_OPAQUE_RING_STD | |
| 7449 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 7450 | } |
| 7451 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7452 | /* Now allocate fresh SKBs for each rx ring. */ |
| 7453 | for (i = 0; i < tp->rx_pending; i++) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 7454 | unsigned int frag_size; |
| 7455 | |
| 7456 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_STD, i, |
| 7457 | &frag_size) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7458 | netdev_warn(tp->dev, |
| 7459 | "Using a smaller RX standard ring. Only " |
| 7460 | "%d out of %d buffers were allocated " |
| 7461 | "successfully\n", i, tp->rx_pending); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7462 | if (i == 0) |
| 7463 | goto initfail; |
| 7464 | tp->rx_pending = i; |
| 7465 | break; |
| 7466 | } |
| 7467 | } |
| 7468 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7469 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7470 | goto done; |
| 7471 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7472 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7473 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7474 | if (!tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7475 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7476 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7477 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7478 | struct tg3_rx_buffer_desc *rxd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7479 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7480 | rxd = &tpr->rx_jmb[i].std; |
| 7481 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; |
| 7482 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | |
| 7483 | RXD_FLAG_JUMBO; |
| 7484 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | |
| 7485 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 7486 | } |
| 7487 | |
| 7488 | for (i = 0; i < tp->rx_jumbo_pending; i++) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 7489 | unsigned int frag_size; |
| 7490 | |
| 7491 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_JUMBO, i, |
| 7492 | &frag_size) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7493 | netdev_warn(tp->dev, |
| 7494 | "Using a smaller RX jumbo ring. Only %d " |
| 7495 | "out of %d buffers were allocated " |
| 7496 | "successfully\n", i, tp->rx_jumbo_pending); |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7497 | if (i == 0) |
| 7498 | goto initfail; |
| 7499 | tp->rx_jumbo_pending = i; |
| 7500 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7501 | } |
| 7502 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7503 | |
| 7504 | done: |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 7505 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7506 | |
| 7507 | initfail: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7508 | tg3_rx_prodring_free(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7509 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7510 | } |
| 7511 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7512 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
| 7513 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7514 | { |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7515 | kfree(tpr->rx_std_buffers); |
| 7516 | tpr->rx_std_buffers = NULL; |
| 7517 | kfree(tpr->rx_jmb_buffers); |
| 7518 | tpr->rx_jmb_buffers = NULL; |
| 7519 | if (tpr->rx_std) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7520 | dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
| 7521 | tpr->rx_std, tpr->rx_std_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7522 | tpr->rx_std = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7523 | } |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7524 | if (tpr->rx_jmb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7525 | dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
| 7526 | tpr->rx_jmb, tpr->rx_jmb_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7527 | tpr->rx_jmb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7528 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7529 | } |
| 7530 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7531 | static int tg3_rx_prodring_init(struct tg3 *tp, |
| 7532 | struct tg3_rx_prodring_set *tpr) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7533 | { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7534 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
| 7535 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7536 | if (!tpr->rx_std_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7537 | return -ENOMEM; |
| 7538 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7539 | tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
| 7540 | TG3_RX_STD_RING_BYTES(tp), |
| 7541 | &tpr->rx_std_mapping, |
| 7542 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7543 | if (!tpr->rx_std) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7544 | goto err_out; |
| 7545 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7546 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7547 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7548 | GFP_KERNEL); |
| 7549 | if (!tpr->rx_jmb_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7550 | goto err_out; |
| 7551 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7552 | tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
| 7553 | TG3_RX_JMB_RING_BYTES(tp), |
| 7554 | &tpr->rx_jmb_mapping, |
| 7555 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7556 | if (!tpr->rx_jmb) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7557 | goto err_out; |
| 7558 | } |
| 7559 | |
| 7560 | return 0; |
| 7561 | |
| 7562 | err_out: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7563 | tg3_rx_prodring_fini(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7564 | return -ENOMEM; |
| 7565 | } |
| 7566 | |
| 7567 | /* Free up pending packets in all rx/tx rings. |
| 7568 | * |
| 7569 | * The chip has been shut down and the driver detached from |
| 7570 | * the networking, so no interrupts or new tx packets will |
| 7571 | * end up in the driver. tp->{tx,}lock is not held and we are not |
| 7572 | * in an interrupt context and thus may sleep. |
| 7573 | */ |
| 7574 | static void tg3_free_rings(struct tg3 *tp) |
| 7575 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7576 | int i, j; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7577 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7578 | for (j = 0; j < tp->irq_cnt; j++) { |
| 7579 | struct tg3_napi *tnapi = &tp->napi[j]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7580 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7581 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
Matt Carlson | b28f642 | 2010-06-05 17:24:32 +0000 | [diff] [blame] | 7582 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7583 | if (!tnapi->tx_buffers) |
| 7584 | continue; |
| 7585 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7586 | for (i = 0; i < TG3_TX_RING_SIZE; i++) { |
| 7587 | struct sk_buff *skb = tnapi->tx_buffers[i].skb; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7588 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7589 | if (!skb) |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7590 | continue; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7591 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7592 | tg3_tx_skb_unmap(tnapi, i, |
| 7593 | skb_shinfo(skb)->nr_frags - 1); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7594 | |
| 7595 | dev_kfree_skb_any(skb); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7596 | } |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 7597 | netdev_tx_reset_queue(netdev_get_tx_queue(tp->dev, j)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7598 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7599 | } |
| 7600 | |
| 7601 | /* Initialize tx/rx rings for packet processing. |
| 7602 | * |
| 7603 | * The chip has been shut down and the driver detached from |
| 7604 | * the networking, so no interrupts or new tx packets will |
| 7605 | * end up in the driver. tp->{tx,}lock are held and thus |
| 7606 | * we may not sleep. |
| 7607 | */ |
| 7608 | static int tg3_init_rings(struct tg3 *tp) |
| 7609 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7610 | int i; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 7611 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7612 | /* Free up all the SKBs. */ |
| 7613 | tg3_free_rings(tp); |
| 7614 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7615 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7616 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7617 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7618 | tnapi->last_tag = 0; |
| 7619 | tnapi->last_irq_tag = 0; |
| 7620 | tnapi->hw_status->status = 0; |
| 7621 | tnapi->hw_status->status_tag = 0; |
| 7622 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7623 | |
| 7624 | tnapi->tx_prod = 0; |
| 7625 | tnapi->tx_cons = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7626 | if (tnapi->tx_ring) |
| 7627 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7628 | |
| 7629 | tnapi->rx_rcb_ptr = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7630 | if (tnapi->rx_rcb) |
| 7631 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7632 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7633 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7634 | tg3_free_rings(tp); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7635 | return -ENOMEM; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7636 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7637 | } |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 7638 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7639 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7640 | } |
| 7641 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 7642 | static void tg3_mem_tx_release(struct tg3 *tp) |
| 7643 | { |
| 7644 | int i; |
| 7645 | |
| 7646 | for (i = 0; i < tp->irq_max; i++) { |
| 7647 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7648 | |
| 7649 | if (tnapi->tx_ring) { |
| 7650 | dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
| 7651 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
| 7652 | tnapi->tx_ring = NULL; |
| 7653 | } |
| 7654 | |
| 7655 | kfree(tnapi->tx_buffers); |
| 7656 | tnapi->tx_buffers = NULL; |
| 7657 | } |
| 7658 | } |
| 7659 | |
| 7660 | static int tg3_mem_tx_acquire(struct tg3 *tp) |
| 7661 | { |
| 7662 | int i; |
| 7663 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 7664 | |
| 7665 | /* If multivector TSS is enabled, vector 0 does not handle |
| 7666 | * tx interrupts. Don't allocate any resources for it. |
| 7667 | */ |
| 7668 | if (tg3_flag(tp, ENABLE_TSS)) |
| 7669 | tnapi++; |
| 7670 | |
| 7671 | for (i = 0; i < tp->txq_cnt; i++, tnapi++) { |
| 7672 | tnapi->tx_buffers = kzalloc(sizeof(struct tg3_tx_ring_info) * |
| 7673 | TG3_TX_RING_SIZE, GFP_KERNEL); |
| 7674 | if (!tnapi->tx_buffers) |
| 7675 | goto err_out; |
| 7676 | |
| 7677 | tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, |
| 7678 | TG3_TX_RING_BYTES, |
| 7679 | &tnapi->tx_desc_mapping, |
| 7680 | GFP_KERNEL); |
| 7681 | if (!tnapi->tx_ring) |
| 7682 | goto err_out; |
| 7683 | } |
| 7684 | |
| 7685 | return 0; |
| 7686 | |
| 7687 | err_out: |
| 7688 | tg3_mem_tx_release(tp); |
| 7689 | return -ENOMEM; |
| 7690 | } |
| 7691 | |
| 7692 | static void tg3_mem_rx_release(struct tg3 *tp) |
| 7693 | { |
| 7694 | int i; |
| 7695 | |
| 7696 | for (i = 0; i < tp->irq_max; i++) { |
| 7697 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7698 | |
| 7699 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
| 7700 | |
| 7701 | if (!tnapi->rx_rcb) |
| 7702 | continue; |
| 7703 | |
| 7704 | dma_free_coherent(&tp->pdev->dev, |
| 7705 | TG3_RX_RCB_RING_BYTES(tp), |
| 7706 | tnapi->rx_rcb, |
| 7707 | tnapi->rx_rcb_mapping); |
| 7708 | tnapi->rx_rcb = NULL; |
| 7709 | } |
| 7710 | } |
| 7711 | |
| 7712 | static int tg3_mem_rx_acquire(struct tg3 *tp) |
| 7713 | { |
| 7714 | unsigned int i, limit; |
| 7715 | |
| 7716 | limit = tp->rxq_cnt; |
| 7717 | |
| 7718 | /* If RSS is enabled, we need a (dummy) producer ring |
| 7719 | * set on vector zero. This is the true hw prodring. |
| 7720 | */ |
| 7721 | if (tg3_flag(tp, ENABLE_RSS)) |
| 7722 | limit++; |
| 7723 | |
| 7724 | for (i = 0; i < limit; i++) { |
| 7725 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7726 | |
| 7727 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
| 7728 | goto err_out; |
| 7729 | |
| 7730 | /* If multivector RSS is enabled, vector 0 |
| 7731 | * does not handle rx or tx interrupts. |
| 7732 | * Don't allocate any resources for it. |
| 7733 | */ |
| 7734 | if (!i && tg3_flag(tp, ENABLE_RSS)) |
| 7735 | continue; |
| 7736 | |
| 7737 | tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, |
| 7738 | TG3_RX_RCB_RING_BYTES(tp), |
| 7739 | &tnapi->rx_rcb_mapping, |
| 7740 | GFP_KERNEL); |
| 7741 | if (!tnapi->rx_rcb) |
| 7742 | goto err_out; |
| 7743 | |
| 7744 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
| 7745 | } |
| 7746 | |
| 7747 | return 0; |
| 7748 | |
| 7749 | err_out: |
| 7750 | tg3_mem_rx_release(tp); |
| 7751 | return -ENOMEM; |
| 7752 | } |
| 7753 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7754 | /* |
| 7755 | * Must not be invoked with interrupt sources disabled and |
| 7756 | * the hardware shutdown down. |
| 7757 | */ |
| 7758 | static void tg3_free_consistent(struct tg3 *tp) |
| 7759 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7760 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7761 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7762 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7763 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7764 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7765 | if (tnapi->hw_status) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7766 | dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
| 7767 | tnapi->hw_status, |
| 7768 | tnapi->status_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7769 | tnapi->hw_status = NULL; |
| 7770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7771 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7772 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 7773 | tg3_mem_rx_release(tp); |
| 7774 | tg3_mem_tx_release(tp); |
| 7775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7776 | if (tp->hw_stats) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7777 | dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
| 7778 | tp->hw_stats, tp->stats_mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7779 | tp->hw_stats = NULL; |
| 7780 | } |
| 7781 | } |
| 7782 | |
| 7783 | /* |
| 7784 | * Must not be invoked with interrupt sources disabled and |
| 7785 | * the hardware shutdown down. Can sleep. |
| 7786 | */ |
| 7787 | static int tg3_alloc_consistent(struct tg3 *tp) |
| 7788 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7789 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7790 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7791 | tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
| 7792 | sizeof(struct tg3_hw_stats), |
| 7793 | &tp->stats_mapping, |
| 7794 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7795 | if (!tp->hw_stats) |
| 7796 | goto err_out; |
| 7797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7798 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 7799 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7800 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7801 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7802 | struct tg3_hw_status *sblk; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7803 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7804 | tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
| 7805 | TG3_HW_STATUS_SIZE, |
| 7806 | &tnapi->status_mapping, |
| 7807 | GFP_KERNEL); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7808 | if (!tnapi->hw_status) |
| 7809 | goto err_out; |
| 7810 | |
| 7811 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7812 | sblk = tnapi->hw_status; |
| 7813 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 7814 | if (tg3_flag(tp, ENABLE_RSS)) { |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 7815 | u16 *prodptr = NULL; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7816 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 7817 | /* |
| 7818 | * When RSS is enabled, the status block format changes |
| 7819 | * slightly. The "rx_jumbo_consumer", "reserved", |
| 7820 | * and "rx_mini_consumer" members get mapped to the |
| 7821 | * other three rx return ring producer indexes. |
| 7822 | */ |
| 7823 | switch (i) { |
| 7824 | case 1: |
| 7825 | prodptr = &sblk->idx[0].rx_producer; |
| 7826 | break; |
| 7827 | case 2: |
| 7828 | prodptr = &sblk->rx_jumbo_consumer; |
| 7829 | break; |
| 7830 | case 3: |
| 7831 | prodptr = &sblk->reserved; |
| 7832 | break; |
| 7833 | case 4: |
| 7834 | prodptr = &sblk->rx_mini_consumer; |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 7835 | break; |
| 7836 | } |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 7837 | tnapi->rx_rcb_prod_idx = prodptr; |
| 7838 | } else { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7839 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7840 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7841 | } |
| 7842 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 7843 | if (tg3_mem_tx_acquire(tp) || tg3_mem_rx_acquire(tp)) |
| 7844 | goto err_out; |
| 7845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7846 | return 0; |
| 7847 | |
| 7848 | err_out: |
| 7849 | tg3_free_consistent(tp); |
| 7850 | return -ENOMEM; |
| 7851 | } |
| 7852 | |
| 7853 | #define MAX_WAIT_CNT 1000 |
| 7854 | |
| 7855 | /* To stop a block, clear the enable bit and poll till it |
| 7856 | * clears. tp->lock is held. |
| 7857 | */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7858 | 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] | 7859 | { |
| 7860 | unsigned int i; |
| 7861 | u32 val; |
| 7862 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7863 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7864 | switch (ofs) { |
| 7865 | case RCVLSC_MODE: |
| 7866 | case DMAC_MODE: |
| 7867 | case MBFREE_MODE: |
| 7868 | case BUFMGR_MODE: |
| 7869 | case MEMARB_MODE: |
| 7870 | /* We can't enable/disable these bits of the |
| 7871 | * 5705/5750, just say success. |
| 7872 | */ |
| 7873 | return 0; |
| 7874 | |
| 7875 | default: |
| 7876 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 7877 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7878 | } |
| 7879 | |
| 7880 | val = tr32(ofs); |
| 7881 | val &= ~enable_bit; |
| 7882 | tw32_f(ofs, val); |
| 7883 | |
| 7884 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 7885 | udelay(100); |
| 7886 | val = tr32(ofs); |
| 7887 | if ((val & enable_bit) == 0) |
| 7888 | break; |
| 7889 | } |
| 7890 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7891 | if (i == MAX_WAIT_CNT && !silent) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 7892 | dev_err(&tp->pdev->dev, |
| 7893 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", |
| 7894 | ofs, enable_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7895 | return -ENODEV; |
| 7896 | } |
| 7897 | |
| 7898 | return 0; |
| 7899 | } |
| 7900 | |
| 7901 | /* tp->lock is held. */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7902 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7903 | { |
| 7904 | int i, err; |
| 7905 | |
| 7906 | tg3_disable_ints(tp); |
| 7907 | |
| 7908 | tp->rx_mode &= ~RX_MODE_ENABLE; |
| 7909 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 7910 | udelay(10); |
| 7911 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7912 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
| 7913 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); |
| 7914 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); |
| 7915 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); |
| 7916 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); |
| 7917 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7918 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7919 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); |
| 7920 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); |
| 7921 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); |
| 7922 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); |
| 7923 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); |
| 7924 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); |
| 7925 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7926 | |
| 7927 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 7928 | tw32_f(MAC_MODE, tp->mac_mode); |
| 7929 | udelay(40); |
| 7930 | |
| 7931 | tp->tx_mode &= ~TX_MODE_ENABLE; |
| 7932 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 7933 | |
| 7934 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 7935 | udelay(100); |
| 7936 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) |
| 7937 | break; |
| 7938 | } |
| 7939 | if (i >= MAX_WAIT_CNT) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 7940 | dev_err(&tp->pdev->dev, |
| 7941 | "%s timed out, TX_MODE_ENABLE will not clear " |
| 7942 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 7943 | err |= -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7944 | } |
| 7945 | |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 7946 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7947 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
| 7948 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7949 | |
| 7950 | tw32(FTQ_RESET, 0xffffffff); |
| 7951 | tw32(FTQ_RESET, 0x00000000); |
| 7952 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7953 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
| 7954 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7955 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7956 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7957 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7958 | if (tnapi->hw_status) |
| 7959 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7960 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7962 | return err; |
| 7963 | } |
| 7964 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7965 | /* Save PCI command register before chip reset */ |
| 7966 | static void tg3_save_pci_state(struct tg3 *tp) |
| 7967 | { |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 7968 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7969 | } |
| 7970 | |
| 7971 | /* Restore PCI state after chip reset */ |
| 7972 | static void tg3_restore_pci_state(struct tg3 *tp) |
| 7973 | { |
| 7974 | u32 val; |
| 7975 | |
| 7976 | /* Re-enable indirect register accesses. */ |
| 7977 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 7978 | tp->misc_host_ctrl); |
| 7979 | |
| 7980 | /* Set MAX PCI retry to zero. */ |
| 7981 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); |
| 7982 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7983 | tg3_flag(tp, PCIX_MODE)) |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7984 | val |= PCISTATE_RETRY_SAME_DMA; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7985 | /* Allow reads and writes to the APE register and memory space. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7986 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7987 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 7988 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 7989 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7990 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
| 7991 | |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 7992 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7993 | |
Matt Carlson | 2c55a3d | 2011-11-28 09:41:04 +0000 | [diff] [blame] | 7994 | if (!tg3_flag(tp, PCI_EXPRESS)) { |
| 7995 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 7996 | tp->pci_cacheline_sz); |
| 7997 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 7998 | tp->pci_lat_timer); |
Michael Chan | 114342f | 2007-10-15 02:12:26 -0700 | [diff] [blame] | 7999 | } |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 8000 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8001 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8002 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8003 | u16 pcix_cmd; |
| 8004 | |
| 8005 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8006 | &pcix_cmd); |
| 8007 | pcix_cmd &= ~PCI_X_CMD_ERO; |
| 8008 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8009 | pcix_cmd); |
| 8010 | } |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8011 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8012 | if (tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8013 | |
| 8014 | /* Chip reset on 5780 will reset MSI enable bit, |
| 8015 | * so need to restore it. |
| 8016 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8017 | if (tg3_flag(tp, USING_MSI)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8018 | u16 ctrl; |
| 8019 | |
| 8020 | pci_read_config_word(tp->pdev, |
| 8021 | tp->msi_cap + PCI_MSI_FLAGS, |
| 8022 | &ctrl); |
| 8023 | pci_write_config_word(tp->pdev, |
| 8024 | tp->msi_cap + PCI_MSI_FLAGS, |
| 8025 | ctrl | PCI_MSI_FLAGS_ENABLE); |
| 8026 | val = tr32(MSGINT_MODE); |
| 8027 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); |
| 8028 | } |
| 8029 | } |
| 8030 | } |
| 8031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8032 | /* tp->lock is held. */ |
| 8033 | static int tg3_chip_reset(struct tg3 *tp) |
| 8034 | { |
| 8035 | u32 val; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 8036 | void (*write_op)(struct tg3 *, u32, u32); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8037 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8038 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 8039 | tg3_nvram_lock(tp); |
| 8040 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 8041 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
| 8042 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 8043 | /* No matching tg3_nvram_unlock() after this because |
| 8044 | * chip reset below will undo the nvram lock. |
| 8045 | */ |
| 8046 | tp->nvram_lock_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8047 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8048 | /* GRC_MISC_CFG core clock reset will clear the memory |
| 8049 | * enable bit in PCI register 4 and the MSI enable bit |
| 8050 | * on some chips, so we save relevant registers here. |
| 8051 | */ |
| 8052 | tg3_save_pci_state(tp); |
| 8053 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8054 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8055 | tg3_flag(tp, 5755_PLUS)) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8056 | tw32(GRC_FASTBOOT_PC, 0); |
| 8057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8058 | /* |
| 8059 | * We must avoid the readl() that normally takes place. |
| 8060 | * It locks machines, causes machine checks, and other |
| 8061 | * fun things. So, temporarily disable the 5701 |
| 8062 | * hardware workaround, while we do the reset. |
| 8063 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 8064 | write_op = tp->write32; |
| 8065 | if (write_op == tg3_write_flush_reg32) |
| 8066 | tp->write32 = tg3_write32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8067 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8068 | /* Prevent the irq handler from reading or writing PCI registers |
| 8069 | * during chip reset when the memory enable bit in the PCI command |
| 8070 | * register may be cleared. The chip does not generate interrupt |
| 8071 | * at this time, but the irq handler may still be called due to irq |
| 8072 | * sharing or irqpoll. |
| 8073 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8074 | tg3_flag_set(tp, CHIP_RESETTING); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8075 | for (i = 0; i < tp->irq_cnt; i++) { |
| 8076 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8077 | if (tnapi->hw_status) { |
| 8078 | tnapi->hw_status->status = 0; |
| 8079 | tnapi->hw_status->status_tag = 0; |
| 8080 | } |
| 8081 | tnapi->last_tag = 0; |
| 8082 | tnapi->last_irq_tag = 0; |
Michael Chan | b8fa2f3 | 2007-04-06 17:35:37 -0700 | [diff] [blame] | 8083 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8084 | smp_mb(); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8085 | |
| 8086 | for (i = 0; i < tp->irq_cnt; i++) |
| 8087 | synchronize_irq(tp->napi[i].irq_vec); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8088 | |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 8089 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 8090 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 8091 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 8092 | } |
| 8093 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8094 | /* do the reset */ |
| 8095 | val = GRC_MISC_CFG_CORECLK_RESET; |
| 8096 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8097 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 8098 | /* Force PCIe 1.0a mode */ |
| 8099 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8100 | !tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 8101 | tr32(TG3_PCIE_PHY_TSTCTL) == |
| 8102 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) |
| 8103 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); |
| 8104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8105 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
| 8106 | tw32(GRC_MISC_CFG, (1 << 29)); |
| 8107 | val |= (1 << 29); |
| 8108 | } |
| 8109 | } |
| 8110 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 8111 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 8112 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
| 8113 | tw32(GRC_VCPU_EXT_CTRL, |
| 8114 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 8115 | } |
| 8116 | |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 8117 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8118 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, CPMU_PRESENT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8119 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 8120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8121 | tw32(GRC_MISC_CFG, val); |
| 8122 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 8123 | /* restore 5701 hardware bug workaround write method */ |
| 8124 | tp->write32 = write_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8125 | |
| 8126 | /* Unfortunately, we have to delay before the PCI read back. |
| 8127 | * Some 575X chips even will not respond to a PCI cfg access |
| 8128 | * when the reset command is given to the chip. |
| 8129 | * |
| 8130 | * How do these hardware designers expect things to work |
| 8131 | * properly if the PCI write is posted for a long period |
| 8132 | * of time? It is always necessary to have some method by |
| 8133 | * which a register read back can occur to push the write |
| 8134 | * out which does the reset. |
| 8135 | * |
| 8136 | * For most tg3 variants the trick below was working. |
| 8137 | * Ho hum... |
| 8138 | */ |
| 8139 | udelay(120); |
| 8140 | |
| 8141 | /* Flush PCI posted writes. The normal MMIO registers |
| 8142 | * are inaccessible at this time so this is the only |
| 8143 | * way to make this reliably (actually, this is no longer |
| 8144 | * the case, see above). I tried to use indirect |
| 8145 | * register read/write but this upset some 5701 variants. |
| 8146 | */ |
| 8147 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); |
| 8148 | |
| 8149 | udelay(120); |
| 8150 | |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8151 | if (tg3_flag(tp, PCI_EXPRESS) && pci_is_pcie(tp->pdev)) { |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 8152 | u16 val16; |
| 8153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8154 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 8155 | int j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8156 | u32 cfg_val; |
| 8157 | |
| 8158 | /* Wait for link training to complete. */ |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 8159 | for (j = 0; j < 5000; j++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8160 | udelay(100); |
| 8161 | |
| 8162 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); |
| 8163 | pci_write_config_dword(tp->pdev, 0xc4, |
| 8164 | cfg_val | (1 << 15)); |
| 8165 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8166 | |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 8167 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8168 | val16 = PCI_EXP_DEVCTL_RELAX_EN | PCI_EXP_DEVCTL_NOSNOOP_EN; |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 8169 | /* |
| 8170 | * Older PCIe devices only support the 128 byte |
| 8171 | * MPS setting. Enforce the restriction. |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8172 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8173 | if (!tg3_flag(tp, CPMU_PRESENT)) |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8174 | val16 |= PCI_EXP_DEVCTL_PAYLOAD; |
| 8175 | pcie_capability_clear_word(tp->pdev, PCI_EXP_DEVCTL, val16); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8176 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8177 | /* Clear error status */ |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8178 | pcie_capability_write_word(tp->pdev, PCI_EXP_DEVSTA, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8179 | PCI_EXP_DEVSTA_CED | |
| 8180 | PCI_EXP_DEVSTA_NFED | |
| 8181 | PCI_EXP_DEVSTA_FED | |
| 8182 | PCI_EXP_DEVSTA_URD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8183 | } |
| 8184 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8185 | tg3_restore_pci_state(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8186 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8187 | tg3_flag_clear(tp, CHIP_RESETTING); |
| 8188 | tg3_flag_clear(tp, ERROR_PROCESSED); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8189 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8190 | val = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8191 | if (tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 8192 | val = tr32(MEMARB_MODE); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8193 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8194 | |
| 8195 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { |
| 8196 | tg3_stop_fw(tp); |
| 8197 | tw32(0x5000, 0x400); |
| 8198 | } |
| 8199 | |
| 8200 | tw32(GRC_MODE, tp->grc_mode); |
| 8201 | |
| 8202 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 8203 | val = tr32(0xc4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8204 | |
| 8205 | tw32(0xc4, val | (1 << 15)); |
| 8206 | } |
| 8207 | |
| 8208 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && |
| 8209 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 8210 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
| 8211 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) |
| 8212 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
| 8213 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 8214 | } |
| 8215 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8216 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 8217 | tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8218 | val = tp->mac_mode; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8219 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 8220 | tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8221 | val = tp->mac_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8222 | } else |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8223 | val = 0; |
| 8224 | |
| 8225 | tw32_f(MAC_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8226 | udelay(40); |
| 8227 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 8228 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
| 8229 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 8230 | err = tg3_poll_fw(tp); |
| 8231 | if (err) |
| 8232 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8233 | |
Matt Carlson | 0a9140c | 2009-08-28 12:27:50 +0000 | [diff] [blame] | 8234 | tg3_mdio_start(tp); |
| 8235 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8236 | if (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8237 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 8238 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8239 | !tg3_flag(tp, 57765_PLUS)) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 8240 | val = tr32(0x7c00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8241 | |
| 8242 | tw32(0x7c00, val | (1 << 25)); |
| 8243 | } |
| 8244 | |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 8245 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 8246 | val = tr32(TG3_CPMU_CLCK_ORIDE); |
| 8247 | tw32(TG3_CPMU_CLCK_ORIDE, val & ~CPMU_CLCK_ORIDE_MAC_ORIDE_EN); |
| 8248 | } |
| 8249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8250 | /* Reprobe ASF enable state. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8251 | tg3_flag_clear(tp, ENABLE_ASF); |
| 8252 | tg3_flag_clear(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8253 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 8254 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 8255 | u32 nic_cfg; |
| 8256 | |
| 8257 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 8258 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8259 | tg3_flag_set(tp, ENABLE_ASF); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 8260 | tp->last_event_jiffies = jiffies; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8261 | if (tg3_flag(tp, 5750_PLUS)) |
| 8262 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8263 | } |
| 8264 | } |
| 8265 | |
| 8266 | return 0; |
| 8267 | } |
| 8268 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 8269 | static void tg3_get_nstats(struct tg3 *, struct rtnl_link_stats64 *); |
| 8270 | static void tg3_get_estats(struct tg3 *, struct tg3_ethtool_stats *); |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8272 | /* tp->lock is held. */ |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8273 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8274 | { |
| 8275 | int err; |
| 8276 | |
| 8277 | tg3_stop_fw(tp); |
| 8278 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8279 | tg3_write_sig_pre_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8280 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8281 | tg3_abort_hw(tp, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8282 | err = tg3_chip_reset(tp); |
| 8283 | |
Matt Carlson | daba2a6 | 2009-04-20 06:58:52 +0000 | [diff] [blame] | 8284 | __tg3_set_mac_addr(tp, 0); |
| 8285 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8286 | tg3_write_sig_legacy(tp, kind); |
| 8287 | tg3_write_sig_post_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8288 | |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8289 | if (tp->hw_stats) { |
| 8290 | /* Save the stats across chip resets... */ |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 8291 | tg3_get_nstats(tp, &tp->net_stats_prev); |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8292 | tg3_get_estats(tp, &tp->estats_prev); |
| 8293 | |
| 8294 | /* And make sure the next sample is new data */ |
| 8295 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 8296 | } |
| 8297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8298 | if (err) |
| 8299 | return err; |
| 8300 | |
| 8301 | return 0; |
| 8302 | } |
| 8303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8304 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
| 8305 | { |
| 8306 | struct tg3 *tp = netdev_priv(dev); |
| 8307 | struct sockaddr *addr = p; |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8308 | int err = 0, skip_mac_1 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8309 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 8310 | if (!is_valid_ether_addr(addr->sa_data)) |
Danny Kukawka | 504f9b5 | 2012-02-21 02:07:49 +0000 | [diff] [blame] | 8311 | return -EADDRNOTAVAIL; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 8312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8313 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 8314 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 8315 | if (!netif_running(dev)) |
| 8316 | return 0; |
| 8317 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8318 | if (tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8319 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 8320 | |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8321 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
| 8322 | addr0_low = tr32(MAC_ADDR_0_LOW); |
| 8323 | addr1_high = tr32(MAC_ADDR_1_HIGH); |
| 8324 | addr1_low = tr32(MAC_ADDR_1_LOW); |
| 8325 | |
| 8326 | /* Skip MAC addr 1 if ASF is using it. */ |
| 8327 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && |
| 8328 | !(addr1_high == 0 && addr1_low == 0)) |
| 8329 | skip_mac_1 = 1; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 8330 | } |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8331 | spin_lock_bh(&tp->lock); |
| 8332 | __tg3_set_mac_addr(tp, skip_mac_1); |
| 8333 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8334 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 8335 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8336 | } |
| 8337 | |
| 8338 | /* tp->lock is held. */ |
| 8339 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, |
| 8340 | dma_addr_t mapping, u32 maxlen_flags, |
| 8341 | u32 nic_addr) |
| 8342 | { |
| 8343 | tg3_write_mem(tp, |
| 8344 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 8345 | ((u64) mapping >> 32)); |
| 8346 | tg3_write_mem(tp, |
| 8347 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), |
| 8348 | ((u64) mapping & 0xffffffff)); |
| 8349 | tg3_write_mem(tp, |
| 8350 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), |
| 8351 | maxlen_flags); |
| 8352 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8353 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8354 | tg3_write_mem(tp, |
| 8355 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), |
| 8356 | nic_addr); |
| 8357 | } |
| 8358 | |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8359 | |
| 8360 | static void tg3_coal_tx_init(struct tg3 *tp, struct ethtool_coalesce *ec) |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8361 | { |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8362 | int i = 0; |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8363 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8364 | if (!tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8365 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
| 8366 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); |
| 8367 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8368 | } else { |
| 8369 | tw32(HOSTCC_TXCOL_TICKS, 0); |
| 8370 | tw32(HOSTCC_TXMAX_FRAMES, 0); |
| 8371 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8372 | |
| 8373 | for (; i < tp->txq_cnt; i++) { |
| 8374 | u32 reg; |
| 8375 | |
| 8376 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
| 8377 | tw32(reg, ec->tx_coalesce_usecs); |
| 8378 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; |
| 8379 | tw32(reg, ec->tx_max_coalesced_frames); |
| 8380 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 8381 | tw32(reg, ec->tx_max_coalesced_frames_irq); |
| 8382 | } |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8383 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8384 | |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8385 | for (; i < tp->irq_max - 1; i++) { |
| 8386 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 8387 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 8388 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 8389 | } |
| 8390 | } |
| 8391 | |
| 8392 | static void tg3_coal_rx_init(struct tg3 *tp, struct ethtool_coalesce *ec) |
| 8393 | { |
| 8394 | int i = 0; |
| 8395 | u32 limit = tp->rxq_cnt; |
| 8396 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8397 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8398 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
| 8399 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); |
| 8400 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8401 | limit--; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8402 | } else { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8403 | tw32(HOSTCC_RXCOL_TICKS, 0); |
| 8404 | tw32(HOSTCC_RXMAX_FRAMES, 0); |
| 8405 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8406 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8407 | |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8408 | for (; i < limit; i++) { |
| 8409 | u32 reg; |
| 8410 | |
| 8411 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; |
| 8412 | tw32(reg, ec->rx_coalesce_usecs); |
| 8413 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
| 8414 | tw32(reg, ec->rx_max_coalesced_frames); |
| 8415 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 8416 | tw32(reg, ec->rx_max_coalesced_frames_irq); |
| 8417 | } |
| 8418 | |
| 8419 | for (; i < tp->irq_max - 1; i++) { |
| 8420 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 8421 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 8422 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 8423 | } |
| 8424 | } |
| 8425 | |
| 8426 | static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) |
| 8427 | { |
| 8428 | tg3_coal_tx_init(tp, ec); |
| 8429 | tg3_coal_rx_init(tp, ec); |
| 8430 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8431 | if (!tg3_flag(tp, 5705_PLUS)) { |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8432 | u32 val = ec->stats_block_coalesce_usecs; |
| 8433 | |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8434 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
| 8435 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); |
| 8436 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 8437 | if (!tp->link_up) |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8438 | val = 0; |
| 8439 | |
| 8440 | tw32(HOSTCC_STAT_COAL_TICKS, val); |
| 8441 | } |
| 8442 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8443 | |
| 8444 | /* tp->lock is held. */ |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8445 | static void tg3_rings_reset(struct tg3 *tp) |
| 8446 | { |
| 8447 | int i; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8448 | u32 stblk, txrcb, rxrcb, limit; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8449 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 8450 | |
| 8451 | /* Disable all transmit rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8452 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8453 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8454 | else if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 3d37728 | 2010-10-14 10:37:39 +0000 | [diff] [blame] | 8455 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8456 | else if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8457 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8458 | else |
| 8459 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 8460 | |
| 8461 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 8462 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) |
| 8463 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 8464 | BDINFO_FLAGS_DISABLED); |
| 8465 | |
| 8466 | |
| 8467 | /* Disable all receive return rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8468 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8469 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8470 | else if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8471 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8472 | 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] | 8473 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8474 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
| 8475 | else |
| 8476 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 8477 | |
| 8478 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 8479 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) |
| 8480 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 8481 | BDINFO_FLAGS_DISABLED); |
| 8482 | |
| 8483 | /* Disable interrupts */ |
| 8484 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 8485 | tp->napi[0].chk_msi_cnt = 0; |
| 8486 | tp->napi[0].last_rx_cons = 0; |
| 8487 | tp->napi[0].last_tx_cons = 0; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8488 | |
| 8489 | /* Zero mailbox registers. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8490 | if (tg3_flag(tp, SUPPORT_MSIX)) { |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 8491 | for (i = 1; i < tp->irq_max; i++) { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8492 | tp->napi[i].tx_prod = 0; |
| 8493 | tp->napi[i].tx_cons = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8494 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 8495 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8496 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
| 8497 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); |
Matt Carlson | 7f23073 | 2011-08-31 11:44:48 +0000 | [diff] [blame] | 8498 | tp->napi[i].chk_msi_cnt = 0; |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 8499 | tp->napi[i].last_rx_cons = 0; |
| 8500 | tp->napi[i].last_tx_cons = 0; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8501 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8502 | if (!tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 8503 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8504 | } else { |
| 8505 | tp->napi[0].tx_prod = 0; |
| 8506 | tp->napi[0].tx_cons = 0; |
| 8507 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 8508 | tw32_rx_mbox(tp->napi[0].consmbox, 0); |
| 8509 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8510 | |
| 8511 | /* Make sure the NIC-based send BD rings are disabled. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8512 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8513 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 8514 | for (i = 0; i < 16; i++) |
| 8515 | tw32_tx_mbox(mbox + i * 8, 0); |
| 8516 | } |
| 8517 | |
| 8518 | txrcb = NIC_SRAM_SEND_RCB; |
| 8519 | rxrcb = NIC_SRAM_RCV_RET_RCB; |
| 8520 | |
| 8521 | /* Clear status block in ram. */ |
| 8522 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8523 | |
| 8524 | /* Set status block DMA address */ |
| 8525 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 8526 | ((u64) tnapi->status_mapping >> 32)); |
| 8527 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 8528 | ((u64) tnapi->status_mapping & 0xffffffff)); |
| 8529 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8530 | if (tnapi->tx_ring) { |
| 8531 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 8532 | (TG3_TX_RING_SIZE << |
| 8533 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 8534 | NIC_SRAM_TX_BUFFER_DESC); |
| 8535 | txrcb += TG3_BDINFO_SIZE; |
| 8536 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8537 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8538 | if (tnapi->rx_rcb) { |
| 8539 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8540 | (tp->rx_ret_ring_mask + 1) << |
| 8541 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8542 | rxrcb += TG3_BDINFO_SIZE; |
| 8543 | } |
| 8544 | |
| 8545 | stblk = HOSTCC_STATBLCK_RING1; |
| 8546 | |
| 8547 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
| 8548 | u64 mapping = (u64)tnapi->status_mapping; |
| 8549 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); |
| 8550 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); |
| 8551 | |
| 8552 | /* Clear status block in ram. */ |
| 8553 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8554 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8555 | if (tnapi->tx_ring) { |
| 8556 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 8557 | (TG3_TX_RING_SIZE << |
| 8558 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 8559 | NIC_SRAM_TX_BUFFER_DESC); |
| 8560 | txrcb += TG3_BDINFO_SIZE; |
| 8561 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8562 | |
| 8563 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8564 | ((tp->rx_ret_ring_mask + 1) << |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8565 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
| 8566 | |
| 8567 | stblk += 8; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8568 | rxrcb += TG3_BDINFO_SIZE; |
| 8569 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8570 | } |
| 8571 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8572 | static void tg3_setup_rxbd_thresholds(struct tg3 *tp) |
| 8573 | { |
| 8574 | u32 val, bdcache_maxcnt, host_rep_thresh, nic_rep_thresh; |
| 8575 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8576 | if (!tg3_flag(tp, 5750_PLUS) || |
| 8577 | tg3_flag(tp, 5780_CLASS) || |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8578 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
Matt Carlson | 513aa6e | 2011-11-21 15:01:18 +0000 | [diff] [blame] | 8579 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 8580 | tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8581 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5700; |
| 8582 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 8583 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) |
| 8584 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5755; |
| 8585 | else |
| 8586 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5906; |
| 8587 | |
| 8588 | nic_rep_thresh = min(bdcache_maxcnt / 2, tp->rx_std_max_post); |
| 8589 | host_rep_thresh = max_t(u32, tp->rx_pending / 8, 1); |
| 8590 | |
| 8591 | val = min(nic_rep_thresh, host_rep_thresh); |
| 8592 | tw32(RCVBDI_STD_THRESH, val); |
| 8593 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8594 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8595 | tw32(STD_REPLENISH_LWM, bdcache_maxcnt); |
| 8596 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8597 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8598 | return; |
| 8599 | |
Matt Carlson | 513aa6e | 2011-11-21 15:01:18 +0000 | [diff] [blame] | 8600 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5700; |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8601 | |
| 8602 | host_rep_thresh = max_t(u32, tp->rx_jumbo_pending / 8, 1); |
| 8603 | |
| 8604 | val = min(bdcache_maxcnt / 2, host_rep_thresh); |
| 8605 | tw32(RCVBDI_JUMBO_THRESH, val); |
| 8606 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8607 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8608 | tw32(JMB_REPLENISH_LWM, bdcache_maxcnt); |
| 8609 | } |
| 8610 | |
Matt Carlson | ccd5ba9 | 2012-02-13 10:20:08 +0000 | [diff] [blame] | 8611 | static inline u32 calc_crc(unsigned char *buf, int len) |
| 8612 | { |
| 8613 | u32 reg; |
| 8614 | u32 tmp; |
| 8615 | int j, k; |
| 8616 | |
| 8617 | reg = 0xffffffff; |
| 8618 | |
| 8619 | for (j = 0; j < len; j++) { |
| 8620 | reg ^= buf[j]; |
| 8621 | |
| 8622 | for (k = 0; k < 8; k++) { |
| 8623 | tmp = reg & 0x01; |
| 8624 | |
| 8625 | reg >>= 1; |
| 8626 | |
| 8627 | if (tmp) |
| 8628 | reg ^= 0xedb88320; |
| 8629 | } |
| 8630 | } |
| 8631 | |
| 8632 | return ~reg; |
| 8633 | } |
| 8634 | |
| 8635 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) |
| 8636 | { |
| 8637 | /* accept or reject all multicast frames */ |
| 8638 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); |
| 8639 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); |
| 8640 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); |
| 8641 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); |
| 8642 | } |
| 8643 | |
| 8644 | static void __tg3_set_rx_mode(struct net_device *dev) |
| 8645 | { |
| 8646 | struct tg3 *tp = netdev_priv(dev); |
| 8647 | u32 rx_mode; |
| 8648 | |
| 8649 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
| 8650 | RX_MODE_KEEP_VLAN_TAG); |
| 8651 | |
| 8652 | #if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) |
| 8653 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
| 8654 | * flag clear. |
| 8655 | */ |
| 8656 | if (!tg3_flag(tp, ENABLE_ASF)) |
| 8657 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 8658 | #endif |
| 8659 | |
| 8660 | if (dev->flags & IFF_PROMISC) { |
| 8661 | /* Promiscuous mode. */ |
| 8662 | rx_mode |= RX_MODE_PROMISC; |
| 8663 | } else if (dev->flags & IFF_ALLMULTI) { |
| 8664 | /* Accept all multicast. */ |
| 8665 | tg3_set_multi(tp, 1); |
| 8666 | } else if (netdev_mc_empty(dev)) { |
| 8667 | /* Reject all multicast. */ |
| 8668 | tg3_set_multi(tp, 0); |
| 8669 | } else { |
| 8670 | /* Accept one or more multicast(s). */ |
| 8671 | struct netdev_hw_addr *ha; |
| 8672 | u32 mc_filter[4] = { 0, }; |
| 8673 | u32 regidx; |
| 8674 | u32 bit; |
| 8675 | u32 crc; |
| 8676 | |
| 8677 | netdev_for_each_mc_addr(ha, dev) { |
| 8678 | crc = calc_crc(ha->addr, ETH_ALEN); |
| 8679 | bit = ~crc & 0x7f; |
| 8680 | regidx = (bit & 0x60) >> 5; |
| 8681 | bit &= 0x1f; |
| 8682 | mc_filter[regidx] |= (1 << bit); |
| 8683 | } |
| 8684 | |
| 8685 | tw32(MAC_HASH_REG_0, mc_filter[0]); |
| 8686 | tw32(MAC_HASH_REG_1, mc_filter[1]); |
| 8687 | tw32(MAC_HASH_REG_2, mc_filter[2]); |
| 8688 | tw32(MAC_HASH_REG_3, mc_filter[3]); |
| 8689 | } |
| 8690 | |
| 8691 | if (rx_mode != tp->rx_mode) { |
| 8692 | tp->rx_mode = rx_mode; |
| 8693 | tw32_f(MAC_RX_MODE, rx_mode); |
| 8694 | udelay(10); |
| 8695 | } |
| 8696 | } |
| 8697 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 8698 | static void tg3_rss_init_dflt_indir_tbl(struct tg3 *tp, u32 qcnt) |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8699 | { |
| 8700 | int i; |
| 8701 | |
| 8702 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 8703 | tp->rss_ind_tbl[i] = ethtool_rxfh_indir_default(i, qcnt); |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8704 | } |
| 8705 | |
| 8706 | static void tg3_rss_check_indir_tbl(struct tg3 *tp) |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8707 | { |
| 8708 | int i; |
| 8709 | |
| 8710 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 8711 | return; |
| 8712 | |
Michael Chan | 0b3ba05 | 2012-11-14 14:44:29 +0000 | [diff] [blame^] | 8713 | if (tp->rxq_cnt == 1) { |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8714 | memset(&tp->rss_ind_tbl[0], 0, sizeof(tp->rss_ind_tbl)); |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8715 | return; |
| 8716 | } |
| 8717 | |
| 8718 | /* Validate table against current IRQ count */ |
| 8719 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { |
Michael Chan | 0b3ba05 | 2012-11-14 14:44:29 +0000 | [diff] [blame^] | 8720 | if (tp->rss_ind_tbl[i] >= tp->rxq_cnt) |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8721 | break; |
| 8722 | } |
| 8723 | |
| 8724 | if (i != TG3_RSS_INDIR_TBL_SIZE) |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 8725 | tg3_rss_init_dflt_indir_tbl(tp, tp->rxq_cnt); |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8726 | } |
| 8727 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8728 | static void tg3_rss_write_indir_tbl(struct tg3 *tp) |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8729 | { |
| 8730 | int i = 0; |
| 8731 | u32 reg = MAC_RSS_INDIR_TBL_0; |
| 8732 | |
| 8733 | while (i < TG3_RSS_INDIR_TBL_SIZE) { |
| 8734 | u32 val = tp->rss_ind_tbl[i]; |
| 8735 | i++; |
| 8736 | for (; i % 8; i++) { |
| 8737 | val <<= 4; |
| 8738 | val |= tp->rss_ind_tbl[i]; |
| 8739 | } |
| 8740 | tw32(reg, val); |
| 8741 | reg += 4; |
| 8742 | } |
| 8743 | } |
| 8744 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8745 | /* tp->lock is held. */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8746 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8747 | { |
| 8748 | u32 val, rdmac_mode; |
| 8749 | int i, err, limit; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 8750 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8751 | |
| 8752 | tg3_disable_ints(tp); |
| 8753 | |
| 8754 | tg3_stop_fw(tp); |
| 8755 | |
| 8756 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); |
| 8757 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8758 | if (tg3_flag(tp, INIT_COMPLETE)) |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 8759 | tg3_abort_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8760 | |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 8761 | /* Enable MAC control of LPI */ |
| 8762 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { |
| 8763 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, |
| 8764 | TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | |
| 8765 | TG3_CPMU_EEE_LNKIDL_UART_IDL); |
| 8766 | |
| 8767 | tw32_f(TG3_CPMU_EEE_CTRL, |
| 8768 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); |
| 8769 | |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 8770 | val = TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
| 8771 | TG3_CPMU_EEEMD_LPI_IN_TX | |
| 8772 | TG3_CPMU_EEEMD_LPI_IN_RX | |
| 8773 | TG3_CPMU_EEEMD_EEE_ENABLE; |
| 8774 | |
| 8775 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
| 8776 | val |= TG3_CPMU_EEEMD_SND_IDX_DET_EN; |
| 8777 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8778 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 8779 | val |= TG3_CPMU_EEEMD_APE_TX_DET_EN; |
| 8780 | |
| 8781 | tw32_f(TG3_CPMU_EEE_MODE, val); |
| 8782 | |
| 8783 | tw32_f(TG3_CPMU_EEE_DBTMR1, |
| 8784 | TG3_CPMU_DBTMR1_PCIEXIT_2047US | |
| 8785 | TG3_CPMU_DBTMR1_LNKIDLE_2047US); |
| 8786 | |
| 8787 | tw32_f(TG3_CPMU_EEE_DBTMR2, |
Matt Carlson | d7f2ab2 | 2011-01-25 15:58:56 +0000 | [diff] [blame] | 8788 | TG3_CPMU_DBTMR2_APE_TX_2047US | |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 8789 | TG3_CPMU_DBTMR2_TXIDXEQ_2047US); |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 8790 | } |
| 8791 | |
Matt Carlson | 603f117 | 2010-02-12 14:47:10 +0000 | [diff] [blame] | 8792 | if (reset_phy) |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 8793 | tg3_phy_reset(tp); |
| 8794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8795 | err = tg3_chip_reset(tp); |
| 8796 | if (err) |
| 8797 | return err; |
| 8798 | |
| 8799 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); |
| 8800 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 8801 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8802 | val = tr32(TG3_CPMU_CTRL); |
| 8803 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); |
| 8804 | tw32(TG3_CPMU_CTRL, val); |
Matt Carlson | 9acb961 | 2007-11-12 21:10:06 -0800 | [diff] [blame] | 8805 | |
| 8806 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 8807 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 8808 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 8809 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 8810 | |
| 8811 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); |
| 8812 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; |
| 8813 | val |= CPMU_LNK_AWARE_MACCLK_6_25; |
| 8814 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); |
| 8815 | |
| 8816 | val = tr32(TG3_CPMU_HST_ACC); |
| 8817 | val &= ~CPMU_HST_ACC_MACCLK_MASK; |
| 8818 | val |= CPMU_HST_ACC_MACCLK_6_25; |
| 8819 | tw32(TG3_CPMU_HST_ACC, val); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8820 | } |
| 8821 | |
Matt Carlson | 33466d93 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 8822 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 8823 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 8824 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | |
| 8825 | PCIE_PWR_MGMT_L1_THRESH_4MS; |
| 8826 | tw32(PCIE_PWR_MGMT_THRESH, val); |
Matt Carlson | 521e6b9 | 2009-08-25 10:06:01 +0000 | [diff] [blame] | 8827 | |
| 8828 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; |
| 8829 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); |
| 8830 | |
| 8831 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); |
Matt Carlson | 33466d93 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 8832 | |
Matt Carlson | f40386c | 2009-11-02 14:24:02 +0000 | [diff] [blame] | 8833 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 8834 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 8835 | } |
| 8836 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8837 | if (tg3_flag(tp, L1PLLPD_EN)) { |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 8838 | u32 grc_mode = tr32(GRC_MODE); |
| 8839 | |
| 8840 | /* Access the lower 1K of PL PCIE block registers. */ |
| 8841 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 8842 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 8843 | |
| 8844 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); |
| 8845 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, |
| 8846 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); |
| 8847 | |
| 8848 | tw32(GRC_MODE, grc_mode); |
| 8849 | } |
| 8850 | |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8851 | if (tg3_flag(tp, 57765_CLASS)) { |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8852 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 8853 | u32 grc_mode = tr32(GRC_MODE); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8854 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8855 | /* Access the lower 1K of PL PCIE block registers. */ |
| 8856 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 8857 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8858 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8859 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 8860 | TG3_PCIE_PL_LO_PHYCTL5); |
| 8861 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, |
| 8862 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8863 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 8864 | tw32(GRC_MODE, grc_mode); |
| 8865 | } |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 8866 | |
Matt Carlson | 1ff30a5 | 2011-05-19 12:12:46 +0000 | [diff] [blame] | 8867 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_57765_AX) { |
| 8868 | u32 grc_mode = tr32(GRC_MODE); |
| 8869 | |
| 8870 | /* Access the lower 1K of DL PCIE block registers. */ |
| 8871 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 8872 | tw32(GRC_MODE, val | GRC_MODE_PCIE_DL_SEL); |
| 8873 | |
| 8874 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 8875 | TG3_PCIE_DL_LO_FTSMAX); |
| 8876 | val &= ~TG3_PCIE_DL_LO_FTSMAX_MSK; |
| 8877 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_DL_LO_FTSMAX, |
| 8878 | val | TG3_PCIE_DL_LO_FTSMAX_VAL); |
| 8879 | |
| 8880 | tw32(GRC_MODE, grc_mode); |
| 8881 | } |
| 8882 | |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 8883 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 8884 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 8885 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 8886 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 8887 | } |
| 8888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8889 | /* This works around an issue with Athlon chipsets on |
| 8890 | * B3 tigon3 silicon. This bit has no effect on any |
| 8891 | * other revision. But do not set this on PCI Express |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 8892 | * 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] | 8893 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8894 | if (!tg3_flag(tp, CPMU_PRESENT)) { |
| 8895 | if (!tg3_flag(tp, PCI_EXPRESS)) |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 8896 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
| 8897 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 8898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8899 | |
| 8900 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8901 | tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8902 | val = tr32(TG3PCI_PCISTATE); |
| 8903 | val |= PCISTATE_RETRY_SAME_DMA; |
| 8904 | tw32(TG3PCI_PCISTATE, val); |
| 8905 | } |
| 8906 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8907 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8908 | /* Allow reads and writes to the |
| 8909 | * APE register and memory space. |
| 8910 | */ |
| 8911 | val = tr32(TG3PCI_PCISTATE); |
| 8912 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 8913 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 8914 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8915 | tw32(TG3PCI_PCISTATE, val); |
| 8916 | } |
| 8917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8918 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
| 8919 | /* Enable some hw fixes. */ |
| 8920 | val = tr32(TG3PCI_MSI_DATA); |
| 8921 | val |= (1 << 26) | (1 << 28) | (1 << 29); |
| 8922 | tw32(TG3PCI_MSI_DATA, val); |
| 8923 | } |
| 8924 | |
| 8925 | /* Descriptor ring init may make accesses to the |
| 8926 | * NIC SRAM area to setup the TX descriptors, so we |
| 8927 | * can only do this after the hardware has been |
| 8928 | * successfully reset. |
| 8929 | */ |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 8930 | err = tg3_init_rings(tp); |
| 8931 | if (err) |
| 8932 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8933 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8934 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 8935 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
| 8936 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
Matt Carlson | 1a31902 | 2010-04-12 06:58:25 +0000 | [diff] [blame] | 8937 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
| 8938 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8939 | if (!tg3_flag(tp, 57765_CLASS) && |
Matt Carlson | 0aebff4 | 2011-04-25 12:42:45 +0000 | [diff] [blame] | 8940 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
| 8941 | val |= DMA_RWCTRL_TAGGED_STAT_WA; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 8942 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
| 8943 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && |
| 8944 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8945 | /* This value is determined during the probe time DMA |
| 8946 | * engine test, tg3_test_dma. |
| 8947 | */ |
| 8948 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 8949 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8950 | |
| 8951 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | |
| 8952 | GRC_MODE_4X_NIC_SEND_RINGS | |
| 8953 | GRC_MODE_NO_TX_PHDR_CSUM | |
| 8954 | GRC_MODE_NO_RX_PHDR_CSUM); |
| 8955 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; |
Michael Chan | d2d746f | 2006-04-06 21:45:39 -0700 | [diff] [blame] | 8956 | |
| 8957 | /* Pseudo-header checksum is done by hardware logic and not |
| 8958 | * the offload processers, so make the chip do the pseudo- |
| 8959 | * header checksums on receive. For transmit it is more |
| 8960 | * convenient to do the pseudo-header checksum in software |
| 8961 | * as Linux does that on transmit for us in all cases. |
| 8962 | */ |
| 8963 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8964 | |
| 8965 | tw32(GRC_MODE, |
| 8966 | tp->grc_mode | |
| 8967 | (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP)); |
| 8968 | |
| 8969 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ |
| 8970 | val = tr32(GRC_MISC_CFG); |
| 8971 | val &= ~0xff; |
| 8972 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 8973 | tw32(GRC_MISC_CFG, val); |
| 8974 | |
| 8975 | /* Initialize MBUF/DESC pool. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8976 | if (tg3_flag(tp, 5750_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8977 | /* Do nothing. */ |
| 8978 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { |
| 8979 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
| 8980 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 8981 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
| 8982 | else |
| 8983 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); |
| 8984 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); |
| 8985 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8986 | } else if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8987 | int fw_len; |
| 8988 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 8989 | fw_len = tp->fw_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8990 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
| 8991 | tw32(BUFMGR_MB_POOL_ADDR, |
| 8992 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); |
| 8993 | tw32(BUFMGR_MB_POOL_SIZE, |
| 8994 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); |
| 8995 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8996 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 8997 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8998 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8999 | tp->bufmgr_config.mbuf_read_dma_low_water); |
| 9000 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 9001 | tp->bufmgr_config.mbuf_mac_rx_low_water); |
| 9002 | tw32(BUFMGR_MB_HIGH_WATER, |
| 9003 | tp->bufmgr_config.mbuf_high_water); |
| 9004 | } else { |
| 9005 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 9006 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); |
| 9007 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 9008 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); |
| 9009 | tw32(BUFMGR_MB_HIGH_WATER, |
| 9010 | tp->bufmgr_config.mbuf_high_water_jumbo); |
| 9011 | } |
| 9012 | tw32(BUFMGR_DMA_LOW_WATER, |
| 9013 | tp->bufmgr_config.dma_low_water); |
| 9014 | tw32(BUFMGR_DMA_HIGH_WATER, |
| 9015 | tp->bufmgr_config.dma_high_water); |
| 9016 | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9017 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
| 9018 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 9019 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 9020 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 9021 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 9022 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) |
| 9023 | val |= BUFMGR_MODE_MBLOW_ATTN_ENAB; |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9024 | tw32(BUFMGR_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9025 | for (i = 0; i < 2000; i++) { |
| 9026 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) |
| 9027 | break; |
| 9028 | udelay(10); |
| 9029 | } |
| 9030 | if (i >= 2000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9031 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9032 | return -ENODEV; |
| 9033 | } |
| 9034 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9035 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) |
| 9036 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 9037 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9038 | tg3_setup_rxbd_thresholds(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9039 | |
| 9040 | /* Initialize TG3_BDINFO's at: |
| 9041 | * RCVDBDI_STD_BD: standard eth size rx ring |
| 9042 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring |
| 9043 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) |
| 9044 | * |
| 9045 | * like so: |
| 9046 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring |
| 9047 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | |
| 9048 | * ring attribute flags |
| 9049 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM |
| 9050 | * |
| 9051 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. |
| 9052 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. |
| 9053 | * |
| 9054 | * The size of each ring is fixed in the firmware, but the location is |
| 9055 | * configurable. |
| 9056 | */ |
| 9057 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9058 | ((u64) tpr->rx_std_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9059 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9060 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9061 | if (!tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 9062 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
| 9063 | NIC_SRAM_RX_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9064 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9065 | /* Disable the mini ring */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9066 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9067 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 9068 | BDINFO_FLAGS_DISABLED); |
| 9069 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9070 | /* Program the jumbo buffer descriptor ring control |
| 9071 | * blocks on those devices that have them. |
| 9072 | */ |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 9073 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9074 | (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9075 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9076 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9077 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9078 | ((u64) tpr->rx_jmb_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9079 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9080 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 9081 | val = TG3_RX_JMB_RING_SIZE(tp) << |
| 9082 | BDINFO_FLAGS_MAXLEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9083 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 9084 | val | BDINFO_FLAGS_USE_EXT_RECV); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9085 | if (!tg3_flag(tp, USE_JUMBO_BDFLAG) || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9086 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 9087 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
| 9088 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9089 | } else { |
| 9090 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 9091 | BDINFO_FLAGS_DISABLED); |
| 9092 | } |
| 9093 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9094 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | fa6b2aa | 2011-11-21 15:01:19 +0000 | [diff] [blame] | 9095 | val = TG3_RX_STD_RING_SIZE(tp); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9096 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
| 9097 | val |= (TG3_RX_STD_DMA_SZ << 2); |
| 9098 | } else |
Matt Carlson | 04380d4 | 2010-04-12 06:58:29 +0000 | [diff] [blame] | 9099 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9100 | } else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 9101 | val = TG3_RX_STD_MAX_SIZE_5700 << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9102 | |
| 9103 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9104 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 9105 | tpr->rx_std_prod_idx = tp->rx_pending; |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 9106 | 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] | 9107 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9108 | tpr->rx_jmb_prod_idx = |
| 9109 | tg3_flag(tp, JUMBO_RING_ENABLE) ? tp->rx_jumbo_pending : 0; |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 9110 | 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] | 9111 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9112 | tg3_rings_reset(tp); |
| 9113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9114 | /* Initialize MAC address and backoff seed. */ |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 9115 | __tg3_set_mac_addr(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9116 | |
| 9117 | /* MTU + ethernet header + FCS + optional VLAN tag */ |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 9118 | tw32(MAC_RX_MTU_SIZE, |
| 9119 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9120 | |
| 9121 | /* The slot time is changed by tg3_setup_phy if we |
| 9122 | * run at gigabit with half duplex. |
| 9123 | */ |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9124 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 9125 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 9126 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT); |
| 9127 | |
| 9128 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 9129 | val |= tr32(MAC_TX_LENGTHS) & |
| 9130 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 9131 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 9132 | |
| 9133 | tw32(MAC_TX_LENGTHS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9134 | |
| 9135 | /* Receive rules. */ |
| 9136 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); |
| 9137 | tw32(RCVLPC_CONFIG, 0x0181); |
| 9138 | |
| 9139 | /* Calculate RDMAC_MODE setting early, we need it to determine |
| 9140 | * the RCVLPC_STATE_ENABLE mask. |
| 9141 | */ |
| 9142 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | |
| 9143 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | |
| 9144 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | |
| 9145 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | |
| 9146 | RDMAC_MODE_LNGREAD_ENAB); |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 9147 | |
Matt Carlson | deabaac | 2010-11-24 08:31:50 +0000 | [diff] [blame] | 9148 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
Matt Carlson | 0339e4e | 2010-02-12 14:47:09 +0000 | [diff] [blame] | 9149 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
| 9150 | |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 9151 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 9152 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 9153 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 9154 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
| 9155 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | |
| 9156 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; |
| 9157 | |
Matt Carlson | c590893 | 2011-03-09 16:58:25 +0000 | [diff] [blame] | 9158 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 9159 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9160 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | c13e371 | 2007-05-05 11:50:04 -0700 | [diff] [blame] | 9161 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9162 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
| 9163 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9164 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9165 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 9166 | } |
| 9167 | } |
| 9168 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9169 | if (tg3_flag(tp, PCI_EXPRESS)) |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 9170 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 9171 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9172 | if (tg3_flag(tp, HW_TSO_1) || |
| 9173 | tg3_flag(tp, HW_TSO_2) || |
| 9174 | tg3_flag(tp, HW_TSO_3)) |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 9175 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
| 9176 | |
Matt Carlson | 108a6c1 | 2011-05-19 12:12:47 +0000 | [diff] [blame] | 9177 | if (tg3_flag(tp, 57765_PLUS) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 9178 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 9179 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
| 9180 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9181 | |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9182 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 9183 | rdmac_mode |= tr32(RDMAC_MODE) & RDMAC_MODE_H2BNC_VLAN_DET; |
| 9184 | |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 9185 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 9186 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 9187 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 9188 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9189 | tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 9190 | val = tr32(TG3_RDMA_RSRVCTRL_REG); |
Michael Chan | 10ce95d | 2012-07-29 19:15:42 +0000 | [diff] [blame] | 9191 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0) { |
Matt Carlson | b4495ed | 2011-01-25 15:58:47 +0000 | [diff] [blame] | 9192 | val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | |
| 9193 | TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | |
| 9194 | TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); |
| 9195 | val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B | |
| 9196 | TG3_RDMA_RSRVCTRL_FIFO_LWM_1_5K | |
| 9197 | TG3_RDMA_RSRVCTRL_FIFO_HWM_1_5K; |
Matt Carlson | b75cc0e | 2010-11-24 08:31:46 +0000 | [diff] [blame] | 9198 | } |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 9199 | tw32(TG3_RDMA_RSRVCTRL_REG, |
| 9200 | val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); |
| 9201 | } |
| 9202 | |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 9203 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 9204 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9205 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 9206 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val | |
| 9207 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | |
| 9208 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); |
| 9209 | } |
| 9210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9211 | /* Receive/send statistics. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9212 | if (tg3_flag(tp, 5750_PLUS)) { |
Michael Chan | 1661394 | 2006-06-29 20:15:13 -0700 | [diff] [blame] | 9213 | val = tr32(RCVLPC_STATS_ENABLE); |
| 9214 | val &= ~RCVLPC_STATSENAB_DACK_FIX; |
| 9215 | tw32(RCVLPC_STATS_ENABLE, val); |
| 9216 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9217 | tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9218 | val = tr32(RCVLPC_STATS_ENABLE); |
| 9219 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; |
| 9220 | tw32(RCVLPC_STATS_ENABLE, val); |
| 9221 | } else { |
| 9222 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); |
| 9223 | } |
| 9224 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); |
| 9225 | tw32(SNDDATAI_STATSENAB, 0xffffff); |
| 9226 | tw32(SNDDATAI_STATSCTRL, |
| 9227 | (SNDDATAI_SCTRL_ENABLE | |
| 9228 | SNDDATAI_SCTRL_FASTUPD)); |
| 9229 | |
| 9230 | /* Setup host coalescing engine. */ |
| 9231 | tw32(HOSTCC_MODE, 0); |
| 9232 | for (i = 0; i < 2000; i++) { |
| 9233 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) |
| 9234 | break; |
| 9235 | udelay(10); |
| 9236 | } |
| 9237 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 9238 | __tg3_set_coalesce(tp, &tp->coal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9239 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9240 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9241 | /* Status/statistics block address. See tg3_timer, |
| 9242 | * the tg3_periodic_fetch_stats call there, and |
| 9243 | * tg3_get_stats to see how this works for 5705/5750 chips. |
| 9244 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9245 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 9246 | ((u64) tp->stats_mapping >> 32)); |
| 9247 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 9248 | ((u64) tp->stats_mapping & 0xffffffff)); |
| 9249 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9251 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9252 | |
| 9253 | /* Clear statistics and status block memory areas */ |
| 9254 | for (i = NIC_SRAM_STATS_BLK; |
| 9255 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; |
| 9256 | i += sizeof(u32)) { |
| 9257 | tg3_write_mem(tp, i, 0); |
| 9258 | udelay(40); |
| 9259 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9260 | } |
| 9261 | |
| 9262 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); |
| 9263 | |
| 9264 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); |
| 9265 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9266 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9267 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
| 9268 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9269 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
| 9270 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 9271 | /* reset to prevent losing 1st rx packet intermittently */ |
| 9272 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 9273 | udelay(10); |
| 9274 | } |
| 9275 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 9276 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 9277 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | |
| 9278 | MAC_MODE_FHDE_ENABLE; |
| 9279 | if (tg3_flag(tp, ENABLE_APE)) |
| 9280 | 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] | 9281 | if (!tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9282 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 9283 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
| 9284 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9285 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
| 9286 | udelay(40); |
| 9287 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9288 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9289 | * If TG3_FLAG_IS_NIC is zero, we should read the |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9290 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
| 9291 | * whether used as inputs or outputs, are set by boot code after |
| 9292 | * reset. |
| 9293 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9294 | if (!tg3_flag(tp, IS_NIC)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9295 | u32 gpio_mask; |
| 9296 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 9297 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
| 9298 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 9299 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 9300 | |
| 9301 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 9302 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
| 9303 | GRC_LCLCTRL_GPIO_OUTPUT3; |
| 9304 | |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 9305 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 9306 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 9307 | |
Gary Zambrano | aaf8446 | 2007-05-05 11:51:45 -0700 | [diff] [blame] | 9308 | tp->grc_local_ctrl &= ~gpio_mask; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9309 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
| 9310 | |
| 9311 | /* GPIO1 must be driven high for eeprom write protect */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9312 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 9313 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 9314 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9315 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9316 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 9317 | udelay(100); |
| 9318 | |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9319 | if (tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9320 | val = tr32(MSGINT_MODE); |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9321 | val |= MSGINT_MODE_ENABLE; |
| 9322 | if (tp->irq_cnt > 1) |
| 9323 | val |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 9324 | if (!tg3_flag(tp, 1SHOT_MSI)) |
| 9325 | val |= MSGINT_MODE_ONE_SHOT_DISABLE; |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9326 | tw32(MSGINT_MODE, val); |
| 9327 | } |
| 9328 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9329 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9330 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
| 9331 | udelay(40); |
| 9332 | } |
| 9333 | |
| 9334 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | |
| 9335 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | |
| 9336 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | |
| 9337 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | |
| 9338 | WDMAC_MODE_LNGREAD_ENAB); |
| 9339 | |
Matt Carlson | c590893 | 2011-03-09 16:58:25 +0000 | [diff] [blame] | 9340 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 9341 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9342 | if (tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9343 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
| 9344 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { |
| 9345 | /* nothing */ |
| 9346 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9347 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9348 | val |= WDMAC_MODE_RX_ACCEL; |
| 9349 | } |
| 9350 | } |
| 9351 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 9352 | /* Enable host coalescing bug fix */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9353 | if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 9354 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 9355 | |
Matt Carlson | 788a035 | 2009-11-02 14:26:03 +0000 | [diff] [blame] | 9356 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 9357 | val |= WDMAC_MODE_BURST_ALL_DATA; |
| 9358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9359 | tw32_f(WDMAC_MODE, val); |
| 9360 | udelay(40); |
| 9361 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9362 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9363 | u16 pcix_cmd; |
| 9364 | |
| 9365 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 9366 | &pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9367 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9368 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
| 9369 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9370 | } 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] | 9371 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
| 9372 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9373 | } |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9374 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 9375 | pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9376 | } |
| 9377 | |
| 9378 | tw32_f(RDMAC_MODE, rdmac_mode); |
| 9379 | udelay(40); |
| 9380 | |
Michael Chan | 091f0ea | 2012-07-29 19:15:43 +0000 | [diff] [blame] | 9381 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
| 9382 | for (i = 0; i < TG3_NUM_RDMA_CHANNELS; i++) { |
| 9383 | if (tr32(TG3_RDMA_LENGTH + (i << 2)) > TG3_MAX_MTU(tp)) |
| 9384 | break; |
| 9385 | } |
| 9386 | if (i < TG3_NUM_RDMA_CHANNELS) { |
| 9387 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 9388 | val |= TG3_LSO_RD_DMA_TX_LENGTH_WA; |
| 9389 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val); |
| 9390 | tg3_flag_set(tp, 5719_RDMA_BUG); |
| 9391 | } |
| 9392 | } |
| 9393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9394 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9395 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9396 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 9397 | |
| 9398 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 9399 | tw32(SNDDATAC_MODE, |
| 9400 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); |
| 9401 | else |
| 9402 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); |
| 9403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9404 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
| 9405 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9406 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9407 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9408 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
| 9409 | tw32(RCVDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9410 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9411 | if (tg3_flag(tp, HW_TSO_1) || |
| 9412 | tg3_flag(tp, HW_TSO_2) || |
| 9413 | tg3_flag(tp, HW_TSO_3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9414 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9415 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9416 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9417 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
| 9418 | tw32(SNDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9419 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
| 9420 | |
| 9421 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 9422 | err = tg3_load_5701_a0_firmware_fix(tp); |
| 9423 | if (err) |
| 9424 | return err; |
| 9425 | } |
| 9426 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9427 | if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9428 | err = tg3_load_tso_firmware(tp); |
| 9429 | if (err) |
| 9430 | return err; |
| 9431 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9432 | |
| 9433 | tp->tx_mode = TX_MODE_ENABLE; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9434 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9435 | if (tg3_flag(tp, 5755_PLUS) || |
Matt Carlson | b1d0521 | 2010-06-05 17:24:31 +0000 | [diff] [blame] | 9436 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 9437 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9438 | |
| 9439 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 9440 | val = TX_MODE_JMB_FRM_LEN | TX_MODE_CNT_DN_MODE; |
| 9441 | tp->tx_mode &= ~val; |
| 9442 | tp->tx_mode |= tr32(MAC_TX_MODE) & val; |
| 9443 | } |
| 9444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9445 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 9446 | udelay(100); |
| 9447 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9448 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 9449 | tg3_rss_write_indir_tbl(tp); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9450 | |
| 9451 | /* Setup the "secret" hash key. */ |
| 9452 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); |
| 9453 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); |
| 9454 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); |
| 9455 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); |
| 9456 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); |
| 9457 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); |
| 9458 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); |
| 9459 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); |
| 9460 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); |
| 9461 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); |
| 9462 | } |
| 9463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9464 | tp->rx_mode = RX_MODE_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9465 | if (tg3_flag(tp, 5755_PLUS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 9466 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
| 9467 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9468 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9469 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
| 9470 | RX_MODE_RSS_ITBL_HASH_BITS_7 | |
| 9471 | RX_MODE_RSS_IPV6_HASH_EN | |
| 9472 | RX_MODE_RSS_TCP_IPV6_HASH_EN | |
| 9473 | RX_MODE_RSS_IPV4_HASH_EN | |
| 9474 | RX_MODE_RSS_TCP_IPV4_HASH_EN; |
| 9475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9476 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 9477 | udelay(10); |
| 9478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9479 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 9480 | |
| 9481 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9482 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9483 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 9484 | udelay(10); |
| 9485 | } |
| 9486 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 9487 | udelay(10); |
| 9488 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9489 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9490 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9491 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9492 | /* Set drive transmission level to 1.2V */ |
| 9493 | /* only if the signal pre-emphasis bit is not set */ |
| 9494 | val = tr32(MAC_SERDES_CFG); |
| 9495 | val &= 0xfffff000; |
| 9496 | val |= 0x880; |
| 9497 | tw32(MAC_SERDES_CFG, val); |
| 9498 | } |
| 9499 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) |
| 9500 | tw32(MAC_SERDES_CFG, 0x616000); |
| 9501 | } |
| 9502 | |
| 9503 | /* Prevent chip from dropping frames when flow control |
| 9504 | * is enabled. |
| 9505 | */ |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9506 | if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 9507 | val = 1; |
| 9508 | else |
| 9509 | val = 2; |
| 9510 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9511 | |
| 9512 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9513 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9514 | /* Use hardware link auto-negotiation */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9515 | tg3_flag_set(tp, HW_AUTONEG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9516 | } |
| 9517 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9518 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 9519 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 9520 | u32 tmp; |
| 9521 | |
| 9522 | tmp = tr32(SERDES_RX_CTRL); |
| 9523 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); |
| 9524 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; |
| 9525 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; |
| 9526 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 9527 | } |
| 9528 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9529 | if (!tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 9530 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9531 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9532 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9533 | err = tg3_setup_phy(tp, 0); |
| 9534 | if (err) |
| 9535 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9536 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9537 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 9538 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9539 | u32 tmp; |
| 9540 | |
| 9541 | /* Clear CRC stats. */ |
| 9542 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { |
| 9543 | tg3_writephy(tp, MII_TG3_TEST1, |
| 9544 | tmp | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 9545 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9547 | } |
| 9548 | } |
| 9549 | |
| 9550 | __tg3_set_rx_mode(tp->dev); |
| 9551 | |
| 9552 | /* Initialize receive rules. */ |
| 9553 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); |
| 9554 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 9555 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); |
| 9556 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 9557 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9558 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9559 | limit = 8; |
| 9560 | else |
| 9561 | limit = 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9562 | if (tg3_flag(tp, ENABLE_ASF)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9563 | limit -= 4; |
| 9564 | switch (limit) { |
| 9565 | case 16: |
| 9566 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); |
| 9567 | case 15: |
| 9568 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); |
| 9569 | case 14: |
| 9570 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); |
| 9571 | case 13: |
| 9572 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); |
| 9573 | case 12: |
| 9574 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); |
| 9575 | case 11: |
| 9576 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); |
| 9577 | case 10: |
| 9578 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); |
| 9579 | case 9: |
| 9580 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); |
| 9581 | case 8: |
| 9582 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); |
| 9583 | case 7: |
| 9584 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); |
| 9585 | case 6: |
| 9586 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); |
| 9587 | case 5: |
| 9588 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); |
| 9589 | case 4: |
| 9590 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ |
| 9591 | case 3: |
| 9592 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ |
| 9593 | case 2: |
| 9594 | case 1: |
| 9595 | |
| 9596 | default: |
| 9597 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 9598 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9599 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9600 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 9ce768e | 2007-10-11 19:49:11 -0700 | [diff] [blame] | 9601 | /* Write our heartbeat update interval to APE. */ |
| 9602 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, |
| 9603 | APE_HOST_HEARTBEAT_INT_DISABLE); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 9604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9605 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
| 9606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9607 | return 0; |
| 9608 | } |
| 9609 | |
| 9610 | /* Called at device open time to get the chip ready for |
| 9611 | * packet processing. Invoked with tp->lock held. |
| 9612 | */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 9613 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9614 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9615 | tg3_switch_clocks(tp); |
| 9616 | |
| 9617 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 9618 | |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 9619 | return tg3_reset_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9620 | } |
| 9621 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9622 | static void tg3_sd_scan_scratchpad(struct tg3 *tp, struct tg3_ocir *ocir) |
| 9623 | { |
| 9624 | int i; |
| 9625 | |
| 9626 | for (i = 0; i < TG3_SD_NUM_RECS; i++, ocir++) { |
| 9627 | u32 off = i * TG3_OCIR_LEN, len = TG3_OCIR_LEN; |
| 9628 | |
| 9629 | tg3_ape_scratchpad_read(tp, (u32 *) ocir, off, len); |
| 9630 | off += len; |
| 9631 | |
| 9632 | if (ocir->signature != TG3_OCIR_SIG_MAGIC || |
| 9633 | !(ocir->version_flags & TG3_OCIR_FLAG_ACTIVE)) |
| 9634 | memset(ocir, 0, TG3_OCIR_LEN); |
| 9635 | } |
| 9636 | } |
| 9637 | |
| 9638 | /* sysfs attributes for hwmon */ |
| 9639 | static ssize_t tg3_show_temp(struct device *dev, |
| 9640 | struct device_attribute *devattr, char *buf) |
| 9641 | { |
| 9642 | struct pci_dev *pdev = to_pci_dev(dev); |
| 9643 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 9644 | struct tg3 *tp = netdev_priv(netdev); |
| 9645 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 9646 | u32 temperature; |
| 9647 | |
| 9648 | spin_lock_bh(&tp->lock); |
| 9649 | tg3_ape_scratchpad_read(tp, &temperature, attr->index, |
| 9650 | sizeof(temperature)); |
| 9651 | spin_unlock_bh(&tp->lock); |
| 9652 | return sprintf(buf, "%u\n", temperature); |
| 9653 | } |
| 9654 | |
| 9655 | |
| 9656 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, tg3_show_temp, NULL, |
| 9657 | TG3_TEMP_SENSOR_OFFSET); |
| 9658 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, tg3_show_temp, NULL, |
| 9659 | TG3_TEMP_CAUTION_OFFSET); |
| 9660 | static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, tg3_show_temp, NULL, |
| 9661 | TG3_TEMP_MAX_OFFSET); |
| 9662 | |
| 9663 | static struct attribute *tg3_attributes[] = { |
| 9664 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 9665 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 9666 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 9667 | NULL |
| 9668 | }; |
| 9669 | |
| 9670 | static const struct attribute_group tg3_group = { |
| 9671 | .attrs = tg3_attributes, |
| 9672 | }; |
| 9673 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9674 | static void tg3_hwmon_close(struct tg3 *tp) |
| 9675 | { |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9676 | if (tp->hwmon_dev) { |
| 9677 | hwmon_device_unregister(tp->hwmon_dev); |
| 9678 | tp->hwmon_dev = NULL; |
| 9679 | sysfs_remove_group(&tp->pdev->dev.kobj, &tg3_group); |
| 9680 | } |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9681 | } |
| 9682 | |
| 9683 | static void tg3_hwmon_open(struct tg3 *tp) |
| 9684 | { |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9685 | int i, err; |
| 9686 | u32 size = 0; |
| 9687 | struct pci_dev *pdev = tp->pdev; |
| 9688 | struct tg3_ocir ocirs[TG3_SD_NUM_RECS]; |
| 9689 | |
| 9690 | tg3_sd_scan_scratchpad(tp, ocirs); |
| 9691 | |
| 9692 | for (i = 0; i < TG3_SD_NUM_RECS; i++) { |
| 9693 | if (!ocirs[i].src_data_length) |
| 9694 | continue; |
| 9695 | |
| 9696 | size += ocirs[i].src_hdr_length; |
| 9697 | size += ocirs[i].src_data_length; |
| 9698 | } |
| 9699 | |
| 9700 | if (!size) |
| 9701 | return; |
| 9702 | |
| 9703 | /* Register hwmon sysfs hooks */ |
| 9704 | err = sysfs_create_group(&pdev->dev.kobj, &tg3_group); |
| 9705 | if (err) { |
| 9706 | dev_err(&pdev->dev, "Cannot create sysfs group, aborting\n"); |
| 9707 | return; |
| 9708 | } |
| 9709 | |
| 9710 | tp->hwmon_dev = hwmon_device_register(&pdev->dev); |
| 9711 | if (IS_ERR(tp->hwmon_dev)) { |
| 9712 | tp->hwmon_dev = NULL; |
| 9713 | dev_err(&pdev->dev, "Cannot register hwmon device, aborting\n"); |
| 9714 | sysfs_remove_group(&pdev->dev.kobj, &tg3_group); |
| 9715 | } |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9716 | } |
| 9717 | |
| 9718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9719 | #define TG3_STAT_ADD32(PSTAT, REG) \ |
| 9720 | do { u32 __val = tr32(REG); \ |
| 9721 | (PSTAT)->low += __val; \ |
| 9722 | if ((PSTAT)->low < __val) \ |
| 9723 | (PSTAT)->high += 1; \ |
| 9724 | } while (0) |
| 9725 | |
| 9726 | static void tg3_periodic_fetch_stats(struct tg3 *tp) |
| 9727 | { |
| 9728 | struct tg3_hw_stats *sp = tp->hw_stats; |
| 9729 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 9730 | if (!tp->link_up) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9731 | return; |
| 9732 | |
| 9733 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); |
| 9734 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); |
| 9735 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); |
| 9736 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); |
| 9737 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); |
| 9738 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); |
| 9739 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); |
| 9740 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); |
| 9741 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); |
| 9742 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); |
| 9743 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); |
| 9744 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); |
| 9745 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); |
Michael Chan | 091f0ea | 2012-07-29 19:15:43 +0000 | [diff] [blame] | 9746 | if (unlikely(tg3_flag(tp, 5719_RDMA_BUG) && |
| 9747 | (sp->tx_ucast_packets.low + sp->tx_mcast_packets.low + |
| 9748 | sp->tx_bcast_packets.low) > TG3_NUM_RDMA_CHANNELS)) { |
| 9749 | u32 val; |
| 9750 | |
| 9751 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 9752 | val &= ~TG3_LSO_RD_DMA_TX_LENGTH_WA; |
| 9753 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val); |
| 9754 | tg3_flag_clear(tp, 5719_RDMA_BUG); |
| 9755 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9756 | |
| 9757 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); |
| 9758 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); |
| 9759 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); |
| 9760 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); |
| 9761 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); |
| 9762 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); |
| 9763 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); |
| 9764 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); |
| 9765 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); |
| 9766 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); |
| 9767 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); |
| 9768 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); |
| 9769 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); |
| 9770 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 9771 | |
| 9772 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); |
Matt Carlson | 310050f | 2011-05-19 12:12:55 +0000 | [diff] [blame] | 9773 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 9774 | tp->pci_chip_rev_id != CHIPREV_ID_5719_A0 && |
| 9775 | tp->pci_chip_rev_id != CHIPREV_ID_5720_A0) { |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 9776 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
| 9777 | } else { |
| 9778 | u32 val = tr32(HOSTCC_FLOW_ATTN); |
| 9779 | val = (val & HOSTCC_FLOW_ATTN_MBUF_LWM) ? 1 : 0; |
| 9780 | if (val) { |
| 9781 | tw32(HOSTCC_FLOW_ATTN, HOSTCC_FLOW_ATTN_MBUF_LWM); |
| 9782 | sp->rx_discards.low += val; |
| 9783 | if (sp->rx_discards.low < val) |
| 9784 | sp->rx_discards.high += 1; |
| 9785 | } |
| 9786 | sp->mbuf_lwm_thresh_hit = sp->rx_discards; |
| 9787 | } |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 9788 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9789 | } |
| 9790 | |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9791 | static void tg3_chk_missed_msi(struct tg3 *tp) |
| 9792 | { |
| 9793 | u32 i; |
| 9794 | |
| 9795 | for (i = 0; i < tp->irq_cnt; i++) { |
| 9796 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9797 | |
| 9798 | if (tg3_has_work(tnapi)) { |
| 9799 | if (tnapi->last_rx_cons == tnapi->rx_rcb_ptr && |
| 9800 | tnapi->last_tx_cons == tnapi->tx_cons) { |
| 9801 | if (tnapi->chk_msi_cnt < 1) { |
| 9802 | tnapi->chk_msi_cnt++; |
| 9803 | return; |
| 9804 | } |
Matt Carlson | 7f23073 | 2011-08-31 11:44:48 +0000 | [diff] [blame] | 9805 | tg3_msi(0, tnapi); |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9806 | } |
| 9807 | } |
| 9808 | tnapi->chk_msi_cnt = 0; |
| 9809 | tnapi->last_rx_cons = tnapi->rx_rcb_ptr; |
| 9810 | tnapi->last_tx_cons = tnapi->tx_cons; |
| 9811 | } |
| 9812 | } |
| 9813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9814 | static void tg3_timer(unsigned long __opaque) |
| 9815 | { |
| 9816 | struct tg3 *tp = (struct tg3 *) __opaque; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9817 | |
Matt Carlson | 5b19062 | 2011-11-04 09:15:04 +0000 | [diff] [blame] | 9818 | if (tp->irq_sync || tg3_flag(tp, RESET_TASK_PENDING)) |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 9819 | goto restart_timer; |
| 9820 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9821 | spin_lock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9822 | |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9823 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9824 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9825 | tg3_chk_missed_msi(tp); |
| 9826 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9827 | if (!tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9828 | /* All of this garbage is because when using non-tagged |
| 9829 | * IRQ status the mailbox/status_block protocol the chip |
| 9830 | * uses with the cpu is race prone. |
| 9831 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 9832 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9833 | tw32(GRC_LOCAL_CTRL, |
| 9834 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 9835 | } else { |
| 9836 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 9837 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9838 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9839 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9840 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9841 | spin_unlock(&tp->lock); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 9842 | tg3_reset_task_schedule(tp); |
Matt Carlson | 5b19062 | 2011-11-04 09:15:04 +0000 | [diff] [blame] | 9843 | goto restart_timer; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9844 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9845 | } |
| 9846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9847 | /* This part only runs once per second. */ |
| 9848 | if (!--tp->timer_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9849 | if (tg3_flag(tp, 5705_PLUS)) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9850 | tg3_periodic_fetch_stats(tp); |
| 9851 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 9852 | if (tp->setlpicnt && !--tp->setlpicnt) |
| 9853 | tg3_phy_eee_enable(tp); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 9854 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9855 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9856 | u32 mac_stat; |
| 9857 | int phy_event; |
| 9858 | |
| 9859 | mac_stat = tr32(MAC_STATUS); |
| 9860 | |
| 9861 | phy_event = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9862 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9863 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
| 9864 | phy_event = 1; |
| 9865 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) |
| 9866 | phy_event = 1; |
| 9867 | |
| 9868 | if (phy_event) |
| 9869 | tg3_setup_phy(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9870 | } else if (tg3_flag(tp, POLL_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9871 | u32 mac_stat = tr32(MAC_STATUS); |
| 9872 | int need_setup = 0; |
| 9873 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 9874 | if (tp->link_up && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9875 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
| 9876 | need_setup = 1; |
| 9877 | } |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 9878 | if (!tp->link_up && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9879 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
| 9880 | MAC_STATUS_SIGNAL_DET))) { |
| 9881 | need_setup = 1; |
| 9882 | } |
| 9883 | if (need_setup) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 9884 | if (!tp->serdes_counter) { |
| 9885 | tw32_f(MAC_MODE, |
| 9886 | (tp->mac_mode & |
| 9887 | ~MAC_MODE_PORT_MODE_MASK)); |
| 9888 | udelay(40); |
| 9889 | tw32_f(MAC_MODE, tp->mac_mode); |
| 9890 | udelay(40); |
| 9891 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9892 | tg3_setup_phy(tp, 0); |
| 9893 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9894 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9895 | tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 9896 | tg3_serdes_parallel_detect(tp); |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 9897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9898 | |
| 9899 | tp->timer_counter = tp->timer_multiplier; |
| 9900 | } |
| 9901 | |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 9902 | /* Heartbeat is only sent once every 2 seconds. |
| 9903 | * |
| 9904 | * The heartbeat is to tell the ASF firmware that the host |
| 9905 | * driver is still alive. In the event that the OS crashes, |
| 9906 | * ASF needs to reset the hardware to free up the FIFO space |
| 9907 | * that may be filled with rx packets destined for the host. |
| 9908 | * If the FIFO is full, ASF will no longer function properly. |
| 9909 | * |
| 9910 | * Unintended resets have been reported on real time kernels |
| 9911 | * where the timer doesn't run on time. Netpoll will also have |
| 9912 | * same problem. |
| 9913 | * |
| 9914 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware |
| 9915 | * to check the ring condition when the heartbeat is expiring |
| 9916 | * before doing the reset. This will prevent most unintended |
| 9917 | * resets. |
| 9918 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9919 | if (!--tp->asf_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9920 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 9921 | tg3_wait_for_event_ack(tp); |
| 9922 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 9923 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 9924 | FWCMD_NICDRV_ALIVE3); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 9925 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 9926 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
| 9927 | TG3_FW_UPDATE_TIMEOUT_SEC); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 9928 | |
| 9929 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9930 | } |
| 9931 | tp->asf_counter = tp->asf_multiplier; |
| 9932 | } |
| 9933 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9934 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9935 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 9936 | restart_timer: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9937 | tp->timer.expires = jiffies + tp->timer_offset; |
| 9938 | add_timer(&tp->timer); |
| 9939 | } |
| 9940 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 9941 | static void __devinit tg3_timer_init(struct tg3 *tp) |
| 9942 | { |
| 9943 | if (tg3_flag(tp, TAGGED_STATUS) && |
| 9944 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 9945 | !tg3_flag(tp, 57765_CLASS)) |
| 9946 | tp->timer_offset = HZ; |
| 9947 | else |
| 9948 | tp->timer_offset = HZ / 10; |
| 9949 | |
| 9950 | BUG_ON(tp->timer_offset > HZ); |
| 9951 | |
| 9952 | tp->timer_multiplier = (HZ / tp->timer_offset); |
| 9953 | tp->asf_multiplier = (HZ / tp->timer_offset) * |
| 9954 | TG3_FW_UPDATE_FREQ_SEC; |
| 9955 | |
| 9956 | init_timer(&tp->timer); |
| 9957 | tp->timer.data = (unsigned long) tp; |
| 9958 | tp->timer.function = tg3_timer; |
| 9959 | } |
| 9960 | |
| 9961 | static void tg3_timer_start(struct tg3 *tp) |
| 9962 | { |
| 9963 | tp->asf_counter = tp->asf_multiplier; |
| 9964 | tp->timer_counter = tp->timer_multiplier; |
| 9965 | |
| 9966 | tp->timer.expires = jiffies + tp->timer_offset; |
| 9967 | add_timer(&tp->timer); |
| 9968 | } |
| 9969 | |
| 9970 | static void tg3_timer_stop(struct tg3 *tp) |
| 9971 | { |
| 9972 | del_timer_sync(&tp->timer); |
| 9973 | } |
| 9974 | |
| 9975 | /* Restart hardware after configuration changes, self-test, etc. |
| 9976 | * Invoked with tp->lock held. |
| 9977 | */ |
| 9978 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) |
| 9979 | __releases(tp->lock) |
| 9980 | __acquires(tp->lock) |
| 9981 | { |
| 9982 | int err; |
| 9983 | |
| 9984 | err = tg3_init_hw(tp, reset_phy); |
| 9985 | if (err) { |
| 9986 | netdev_err(tp->dev, |
| 9987 | "Failed to re-initialize device, aborting\n"); |
| 9988 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 9989 | tg3_full_unlock(tp); |
| 9990 | tg3_timer_stop(tp); |
| 9991 | tp->irq_sync = 0; |
| 9992 | tg3_napi_enable(tp); |
| 9993 | dev_close(tp->dev); |
| 9994 | tg3_full_lock(tp, 0); |
| 9995 | } |
| 9996 | return err; |
| 9997 | } |
| 9998 | |
| 9999 | static void tg3_reset_task(struct work_struct *work) |
| 10000 | { |
| 10001 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
| 10002 | int err; |
| 10003 | |
| 10004 | tg3_full_lock(tp, 0); |
| 10005 | |
| 10006 | if (!netif_running(tp->dev)) { |
| 10007 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 10008 | tg3_full_unlock(tp); |
| 10009 | return; |
| 10010 | } |
| 10011 | |
| 10012 | tg3_full_unlock(tp); |
| 10013 | |
| 10014 | tg3_phy_stop(tp); |
| 10015 | |
| 10016 | tg3_netif_stop(tp); |
| 10017 | |
| 10018 | tg3_full_lock(tp, 1); |
| 10019 | |
| 10020 | if (tg3_flag(tp, TX_RECOVERY_PENDING)) { |
| 10021 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 10022 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 10023 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
| 10024 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
| 10025 | } |
| 10026 | |
| 10027 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 10028 | err = tg3_init_hw(tp, 1); |
| 10029 | if (err) |
| 10030 | goto out; |
| 10031 | |
| 10032 | tg3_netif_start(tp); |
| 10033 | |
| 10034 | out: |
| 10035 | tg3_full_unlock(tp); |
| 10036 | |
| 10037 | if (!err) |
| 10038 | tg3_phy_start(tp); |
| 10039 | |
| 10040 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 10041 | } |
| 10042 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10043 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10044 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 10045 | irq_handler_t fn; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10046 | unsigned long flags; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10047 | char *name; |
| 10048 | struct tg3_napi *tnapi = &tp->napi[irq_num]; |
| 10049 | |
| 10050 | if (tp->irq_cnt == 1) |
| 10051 | name = tp->dev->name; |
| 10052 | else { |
| 10053 | name = &tnapi->irq_lbl[0]; |
| 10054 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); |
| 10055 | name[IFNAMSIZ-1] = 0; |
| 10056 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10057 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10058 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10059 | fn = tg3_msi; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10060 | if (tg3_flag(tp, 1SHOT_MSI)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10061 | fn = tg3_msi_1shot; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 10062 | flags = 0; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10063 | } else { |
| 10064 | fn = tg3_interrupt; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10065 | if (tg3_flag(tp, TAGGED_STATUS)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10066 | fn = tg3_interrupt_tagged; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 10067 | flags = IRQF_SHARED; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10068 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10069 | |
| 10070 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10071 | } |
| 10072 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10073 | static int tg3_test_interrupt(struct tg3 *tp) |
| 10074 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 10075 | struct tg3_napi *tnapi = &tp->napi[0]; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10076 | struct net_device *dev = tp->dev; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10077 | int err, i, intr_ok = 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10078 | u32 val; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10079 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 10080 | if (!netif_running(dev)) |
| 10081 | return -ENODEV; |
| 10082 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10083 | tg3_disable_ints(tp); |
| 10084 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10085 | free_irq(tnapi->irq_vec, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10086 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10087 | /* |
| 10088 | * Turn off MSI one shot mode. Otherwise this test has no |
| 10089 | * observable way to know whether the interrupt was delivered. |
| 10090 | */ |
Matt Carlson | 3aa1cdf | 2011-07-20 10:20:55 +0000 | [diff] [blame] | 10091 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10092 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
| 10093 | tw32(MSGINT_MODE, val); |
| 10094 | } |
| 10095 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10096 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
Davidlohr Bueso | f274fd9 | 2012-02-22 03:06:54 +0000 | [diff] [blame] | 10097 | IRQF_SHARED, dev->name, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10098 | if (err) |
| 10099 | return err; |
| 10100 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10101 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10102 | tg3_enable_ints(tp); |
| 10103 | |
| 10104 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10105 | tnapi->coal_now); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10106 | |
| 10107 | for (i = 0; i < 5; i++) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10108 | u32 int_mbox, misc_host_ctrl; |
| 10109 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10110 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10111 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 10112 | |
| 10113 | if ((int_mbox != 0) || |
| 10114 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { |
| 10115 | intr_ok = 1; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10116 | break; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10117 | } |
| 10118 | |
Matt Carlson | 3aa1cdf | 2011-07-20 10:20:55 +0000 | [diff] [blame] | 10119 | if (tg3_flag(tp, 57765_PLUS) && |
| 10120 | tnapi->hw_status->status_tag != tnapi->last_tag) |
| 10121 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 10122 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10123 | msleep(10); |
| 10124 | } |
| 10125 | |
| 10126 | tg3_disable_ints(tp); |
| 10127 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10128 | free_irq(tnapi->irq_vec, tnapi); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10129 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10130 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10131 | |
| 10132 | if (err) |
| 10133 | return err; |
| 10134 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10135 | if (intr_ok) { |
| 10136 | /* Reenable MSI one shot mode. */ |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 10137 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, 1SHOT_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10138 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
| 10139 | tw32(MSGINT_MODE, val); |
| 10140 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10141 | return 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10142 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10143 | |
| 10144 | return -EIO; |
| 10145 | } |
| 10146 | |
| 10147 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is |
| 10148 | * successfully restored |
| 10149 | */ |
| 10150 | static int tg3_test_msi(struct tg3 *tp) |
| 10151 | { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10152 | int err; |
| 10153 | u16 pci_cmd; |
| 10154 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10155 | if (!tg3_flag(tp, USING_MSI)) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10156 | return 0; |
| 10157 | |
| 10158 | /* Turn off SERR reporting in case MSI terminates with Master |
| 10159 | * Abort. |
| 10160 | */ |
| 10161 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 10162 | pci_write_config_word(tp->pdev, PCI_COMMAND, |
| 10163 | pci_cmd & ~PCI_COMMAND_SERR); |
| 10164 | |
| 10165 | err = tg3_test_interrupt(tp); |
| 10166 | |
| 10167 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 10168 | |
| 10169 | if (!err) |
| 10170 | return 0; |
| 10171 | |
| 10172 | /* other failures */ |
| 10173 | if (err != -EIO) |
| 10174 | return err; |
| 10175 | |
| 10176 | /* MSI test failed, go back to INTx mode */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 10177 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
| 10178 | "to INTx mode. Please report this failure to the PCI " |
| 10179 | "maintainer and include system chipset information\n"); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10180 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10181 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 10182 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10183 | pci_disable_msi(tp->pdev); |
| 10184 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10185 | tg3_flag_clear(tp, USING_MSI); |
Andre Detsch | dc8bf1b | 2010-04-26 07:27:07 +0000 | [diff] [blame] | 10186 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10187 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10188 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10189 | if (err) |
| 10190 | return err; |
| 10191 | |
| 10192 | /* Need to reset the chip because the MSI cycle may have terminated |
| 10193 | * with Master Abort. |
| 10194 | */ |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10195 | tg3_full_lock(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10196 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10197 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 10198 | err = tg3_init_hw(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10199 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10200 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10201 | |
| 10202 | if (err) |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10203 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10204 | |
| 10205 | return err; |
| 10206 | } |
| 10207 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 10208 | static int tg3_request_firmware(struct tg3 *tp) |
| 10209 | { |
| 10210 | const __be32 *fw_data; |
| 10211 | |
| 10212 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 10213 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
| 10214 | tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 10215 | return -ENOENT; |
| 10216 | } |
| 10217 | |
| 10218 | fw_data = (void *)tp->fw->data; |
| 10219 | |
| 10220 | /* Firmware blob starts with version numbers, followed by |
| 10221 | * start address and _full_ length including BSS sections |
| 10222 | * (which must be longer than the actual data, of course |
| 10223 | */ |
| 10224 | |
| 10225 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ |
| 10226 | if (tp->fw_len < (tp->fw->size - 12)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 10227 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
| 10228 | tp->fw_len, tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 10229 | release_firmware(tp->fw); |
| 10230 | tp->fw = NULL; |
| 10231 | return -EINVAL; |
| 10232 | } |
| 10233 | |
| 10234 | /* We no longer need firmware; we have it. */ |
| 10235 | tp->fw_needed = NULL; |
| 10236 | return 0; |
| 10237 | } |
| 10238 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10239 | static u32 tg3_irq_count(struct tg3 *tp) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10240 | { |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10241 | u32 irq_cnt = max(tp->rxq_cnt, tp->txq_cnt); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10242 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10243 | if (irq_cnt > 1) { |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 10244 | /* We want as many rx rings enabled as there are cpus. |
| 10245 | * In multiqueue MSI-X mode, the first MSI-X vector |
| 10246 | * only deals with link interrupts, etc, so we add |
| 10247 | * one to the number of vectors we are requesting. |
| 10248 | */ |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10249 | irq_cnt = min_t(unsigned, irq_cnt + 1, tp->irq_max); |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 10250 | } |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10251 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10252 | return irq_cnt; |
| 10253 | } |
| 10254 | |
| 10255 | static bool tg3_enable_msix(struct tg3 *tp) |
| 10256 | { |
| 10257 | int i, rc; |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 10258 | struct msix_entry msix_ent[TG3_IRQ_MAX_VECS]; |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10259 | |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 10260 | tp->txq_cnt = tp->txq_req; |
| 10261 | tp->rxq_cnt = tp->rxq_req; |
| 10262 | if (!tp->rxq_cnt) |
| 10263 | tp->rxq_cnt = netif_get_num_default_rss_queues(); |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10264 | if (tp->rxq_cnt > tp->rxq_max) |
| 10265 | tp->rxq_cnt = tp->rxq_max; |
Michael Chan | cf6d6ea | 2012-09-28 07:12:43 +0000 | [diff] [blame] | 10266 | |
| 10267 | /* Disable multiple TX rings by default. Simple round-robin hardware |
| 10268 | * scheduling of the TX rings can cause starvation of rings with |
| 10269 | * small packets when other rings have TSO or jumbo packets. |
| 10270 | */ |
| 10271 | if (!tp->txq_req) |
| 10272 | tp->txq_cnt = 1; |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10273 | |
| 10274 | tp->irq_cnt = tg3_irq_count(tp); |
| 10275 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10276 | for (i = 0; i < tp->irq_max; i++) { |
| 10277 | msix_ent[i].entry = i; |
| 10278 | msix_ent[i].vector = 0; |
| 10279 | } |
| 10280 | |
| 10281 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 10282 | if (rc < 0) { |
| 10283 | return false; |
| 10284 | } else if (rc != 0) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10285 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
| 10286 | return false; |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 10287 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
| 10288 | tp->irq_cnt, rc); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10289 | tp->irq_cnt = rc; |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 10290 | tp->rxq_cnt = max(rc - 1, 1); |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10291 | if (tp->txq_cnt) |
| 10292 | tp->txq_cnt = min(tp->rxq_cnt, tp->txq_max); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10293 | } |
| 10294 | |
| 10295 | for (i = 0; i < tp->irq_max; i++) |
| 10296 | tp->napi[i].irq_vec = msix_ent[i].vector; |
| 10297 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 10298 | if (netif_set_real_num_rx_queues(tp->dev, tp->rxq_cnt)) { |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 10299 | pci_disable_msix(tp->pdev); |
| 10300 | return false; |
| 10301 | } |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 10302 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10303 | if (tp->irq_cnt == 1) |
| 10304 | return true; |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 10305 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10306 | tg3_flag_set(tp, ENABLE_RSS); |
| 10307 | |
| 10308 | if (tp->txq_cnt > 1) |
| 10309 | tg3_flag_set(tp, ENABLE_TSS); |
| 10310 | |
| 10311 | netif_set_real_num_tx_queues(tp->dev, tp->txq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 10312 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10313 | return true; |
| 10314 | } |
| 10315 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10316 | static void tg3_ints_init(struct tg3 *tp) |
| 10317 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10318 | if ((tg3_flag(tp, SUPPORT_MSI) || tg3_flag(tp, SUPPORT_MSIX)) && |
| 10319 | !tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10320 | /* All MSI supporting chips should support tagged |
| 10321 | * status. Assert that this is the case. |
| 10322 | */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 10323 | netdev_warn(tp->dev, |
| 10324 | "MSI without TAGGED_STATUS? Not using MSI\n"); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10325 | goto defcfg; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10326 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10327 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10328 | if (tg3_flag(tp, SUPPORT_MSIX) && tg3_enable_msix(tp)) |
| 10329 | tg3_flag_set(tp, USING_MSIX); |
| 10330 | else if (tg3_flag(tp, SUPPORT_MSI) && pci_enable_msi(tp->pdev) == 0) |
| 10331 | tg3_flag_set(tp, USING_MSI); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10332 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10333 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10334 | u32 msi_mode = tr32(MSGINT_MODE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10335 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 10336 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 10337 | if (!tg3_flag(tp, 1SHOT_MSI)) |
| 10338 | msi_mode |= MSGINT_MODE_ONE_SHOT_DISABLE; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10339 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
| 10340 | } |
| 10341 | defcfg: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10342 | if (!tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10343 | tp->irq_cnt = 1; |
| 10344 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 10345 | } |
| 10346 | |
| 10347 | if (tp->irq_cnt == 1) { |
| 10348 | tp->txq_cnt = 1; |
| 10349 | tp->rxq_cnt = 1; |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 10350 | netif_set_real_num_tx_queues(tp->dev, 1); |
Matt Carlson | 8540788 | 2010-10-06 13:40:58 -0700 | [diff] [blame] | 10351 | netif_set_real_num_rx_queues(tp->dev, 1); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10352 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10353 | } |
| 10354 | |
| 10355 | static void tg3_ints_fini(struct tg3 *tp) |
| 10356 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10357 | if (tg3_flag(tp, USING_MSIX)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10358 | pci_disable_msix(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10359 | else if (tg3_flag(tp, USING_MSI)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10360 | pci_disable_msi(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10361 | tg3_flag_clear(tp, USING_MSI); |
| 10362 | tg3_flag_clear(tp, USING_MSIX); |
| 10363 | tg3_flag_clear(tp, ENABLE_RSS); |
| 10364 | tg3_flag_clear(tp, ENABLE_TSS); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10365 | } |
| 10366 | |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10367 | static int tg3_start(struct tg3 *tp, bool reset_phy, bool test_irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10368 | { |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10369 | struct net_device *dev = tp->dev; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10370 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10371 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10372 | /* |
| 10373 | * Setup interrupts first so we know how |
| 10374 | * many NAPI resources to allocate |
| 10375 | */ |
| 10376 | tg3_ints_init(tp); |
| 10377 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 10378 | tg3_rss_check_indir_tbl(tp); |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 10379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10380 | /* The placement of this call is tied |
| 10381 | * to the setup and use of Host TX descriptors. |
| 10382 | */ |
| 10383 | err = tg3_alloc_consistent(tp); |
| 10384 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10385 | goto err_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10386 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10387 | tg3_napi_init(tp); |
| 10388 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 10389 | tg3_napi_enable(tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 10390 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10391 | for (i = 0; i < tp->irq_cnt; i++) { |
| 10392 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10393 | err = tg3_request_irq(tp, i); |
| 10394 | if (err) { |
Matt Carlson | 5bc0918 | 2011-11-04 09:15:01 +0000 | [diff] [blame] | 10395 | for (i--; i >= 0; i--) { |
| 10396 | tnapi = &tp->napi[i]; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10397 | free_irq(tnapi->irq_vec, tnapi); |
Matt Carlson | 5bc0918 | 2011-11-04 09:15:01 +0000 | [diff] [blame] | 10398 | } |
| 10399 | goto err_out2; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10400 | } |
| 10401 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10402 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10403 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10404 | |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10405 | err = tg3_init_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10406 | if (err) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10407 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10408 | tg3_free_rings(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10409 | } |
| 10410 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10411 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10412 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10413 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10414 | goto err_out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10415 | |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10416 | if (test_irq && tg3_flag(tp, USING_MSI)) { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10417 | err = tg3_test_msi(tp); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10418 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10419 | if (err) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10420 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10421 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10422 | tg3_free_rings(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10423 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10424 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10425 | goto err_out2; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10426 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10427 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10428 | if (!tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10429 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10430 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10431 | tw32(PCIE_TRANSACTION_CFG, |
| 10432 | val | PCIE_TRANS_CFG_1SHOT_MSI); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10433 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10434 | } |
| 10435 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10436 | tg3_phy_start(tp); |
| 10437 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 10438 | tg3_hwmon_open(tp); |
| 10439 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10440 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10441 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10442 | tg3_timer_start(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10443 | tg3_flag_set(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10444 | tg3_enable_ints(tp); |
| 10445 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10446 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10447 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 10448 | netif_tx_start_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10449 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 10450 | /* |
| 10451 | * Reset loopback feature if it was turned on while the device was down |
| 10452 | * make sure that it's installed properly now. |
| 10453 | */ |
| 10454 | if (dev->features & NETIF_F_LOOPBACK) |
| 10455 | tg3_set_loopback(dev, dev->features); |
| 10456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10457 | return 0; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10458 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10459 | err_out3: |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10460 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 10461 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10462 | free_irq(tnapi->irq_vec, tnapi); |
| 10463 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10464 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10465 | err_out2: |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 10466 | tg3_napi_disable(tp); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10467 | tg3_napi_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10468 | tg3_free_consistent(tp); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10469 | |
| 10470 | err_out1: |
| 10471 | tg3_ints_fini(tp); |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10472 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10473 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10474 | } |
| 10475 | |
Michael Chan | 6513859 | 2012-09-28 07:12:41 +0000 | [diff] [blame] | 10476 | static void tg3_stop(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10477 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10478 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10479 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 10480 | tg3_reset_task_cancel(tp); |
Nithin Nayak Sujir | bd473da | 2012-11-05 14:26:30 +0000 | [diff] [blame] | 10481 | tg3_netif_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10482 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10483 | tg3_timer_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10484 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 10485 | tg3_hwmon_close(tp); |
| 10486 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 10487 | tg3_phy_stop(tp); |
| 10488 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10489 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10490 | |
| 10491 | tg3_disable_ints(tp); |
| 10492 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10493 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10494 | tg3_free_rings(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10495 | tg3_flag_clear(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10496 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10497 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10498 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10499 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 10500 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10501 | free_irq(tnapi->irq_vec, tnapi); |
| 10502 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10503 | |
| 10504 | tg3_ints_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10505 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10506 | tg3_napi_fini(tp); |
| 10507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10508 | tg3_free_consistent(tp); |
Michael Chan | 6513859 | 2012-09-28 07:12:41 +0000 | [diff] [blame] | 10509 | } |
| 10510 | |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10511 | static int tg3_open(struct net_device *dev) |
| 10512 | { |
| 10513 | struct tg3 *tp = netdev_priv(dev); |
| 10514 | int err; |
| 10515 | |
| 10516 | if (tp->fw_needed) { |
| 10517 | err = tg3_request_firmware(tp); |
| 10518 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 10519 | if (err) |
| 10520 | return err; |
| 10521 | } else if (err) { |
| 10522 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
| 10523 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 10524 | } else if (!tg3_flag(tp, TSO_CAPABLE)) { |
| 10525 | netdev_notice(tp->dev, "TSO capability restored\n"); |
| 10526 | tg3_flag_set(tp, TSO_CAPABLE); |
| 10527 | } |
| 10528 | } |
| 10529 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 10530 | tg3_carrier_off(tp); |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10531 | |
| 10532 | err = tg3_power_up(tp); |
| 10533 | if (err) |
| 10534 | return err; |
| 10535 | |
| 10536 | tg3_full_lock(tp, 0); |
| 10537 | |
| 10538 | tg3_disable_ints(tp); |
| 10539 | tg3_flag_clear(tp, INIT_COMPLETE); |
| 10540 | |
| 10541 | tg3_full_unlock(tp); |
| 10542 | |
| 10543 | err = tg3_start(tp, true, true); |
| 10544 | if (err) { |
| 10545 | tg3_frob_aux_power(tp, false); |
| 10546 | pci_set_power_state(tp->pdev, PCI_D3hot); |
| 10547 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10548 | return err; |
| 10549 | } |
| 10550 | |
| 10551 | static int tg3_close(struct net_device *dev) |
| 10552 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10553 | struct tg3 *tp = netdev_priv(dev); |
| 10554 | |
Michael Chan | 6513859 | 2012-09-28 07:12:41 +0000 | [diff] [blame] | 10555 | tg3_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10556 | |
| 10557 | /* Clear stats across close / open calls */ |
| 10558 | memset(&tp->net_stats_prev, 0, sizeof(tp->net_stats_prev)); |
| 10559 | memset(&tp->estats_prev, 0, sizeof(tp->estats_prev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10560 | |
| 10561 | tg3_power_down(tp); |
| 10562 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 10563 | tg3_carrier_off(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10564 | |
| 10565 | return 0; |
| 10566 | } |
| 10567 | |
| 10568 | static inline u64 get_stat64(tg3_stat64_t *val) |
| 10569 | { |
| 10570 | return ((u64)val->high << 32) | ((u64)val->low); |
| 10571 | } |
| 10572 | |
| 10573 | static u64 tg3_calc_crc_errors(struct tg3 *tp) |
| 10574 | { |
| 10575 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10576 | |
| 10577 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 10578 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 10579 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 10580 | u32 val; |
| 10581 | |
| 10582 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
| 10583 | tg3_writephy(tp, MII_TG3_TEST1, |
| 10584 | val | MII_TG3_TEST1_CRC_EN); |
| 10585 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
| 10586 | } else |
| 10587 | val = 0; |
| 10588 | |
| 10589 | tp->phy_crc_errors += val; |
| 10590 | |
| 10591 | return tp->phy_crc_errors; |
| 10592 | } |
| 10593 | |
| 10594 | return get_stat64(&hw_stats->rx_fcs_errors); |
| 10595 | } |
| 10596 | |
| 10597 | #define ESTAT_ADD(member) \ |
| 10598 | estats->member = old_estats->member + \ |
| 10599 | get_stat64(&hw_stats->member) |
| 10600 | |
| 10601 | static void tg3_get_estats(struct tg3 *tp, struct tg3_ethtool_stats *estats) |
| 10602 | { |
| 10603 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
| 10604 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10605 | |
| 10606 | ESTAT_ADD(rx_octets); |
| 10607 | ESTAT_ADD(rx_fragments); |
| 10608 | ESTAT_ADD(rx_ucast_packets); |
| 10609 | ESTAT_ADD(rx_mcast_packets); |
| 10610 | ESTAT_ADD(rx_bcast_packets); |
| 10611 | ESTAT_ADD(rx_fcs_errors); |
| 10612 | ESTAT_ADD(rx_align_errors); |
| 10613 | ESTAT_ADD(rx_xon_pause_rcvd); |
| 10614 | ESTAT_ADD(rx_xoff_pause_rcvd); |
| 10615 | ESTAT_ADD(rx_mac_ctrl_rcvd); |
| 10616 | ESTAT_ADD(rx_xoff_entered); |
| 10617 | ESTAT_ADD(rx_frame_too_long_errors); |
| 10618 | ESTAT_ADD(rx_jabbers); |
| 10619 | ESTAT_ADD(rx_undersize_packets); |
| 10620 | ESTAT_ADD(rx_in_length_errors); |
| 10621 | ESTAT_ADD(rx_out_length_errors); |
| 10622 | ESTAT_ADD(rx_64_or_less_octet_packets); |
| 10623 | ESTAT_ADD(rx_65_to_127_octet_packets); |
| 10624 | ESTAT_ADD(rx_128_to_255_octet_packets); |
| 10625 | ESTAT_ADD(rx_256_to_511_octet_packets); |
| 10626 | ESTAT_ADD(rx_512_to_1023_octet_packets); |
| 10627 | ESTAT_ADD(rx_1024_to_1522_octet_packets); |
| 10628 | ESTAT_ADD(rx_1523_to_2047_octet_packets); |
| 10629 | ESTAT_ADD(rx_2048_to_4095_octet_packets); |
| 10630 | ESTAT_ADD(rx_4096_to_8191_octet_packets); |
| 10631 | ESTAT_ADD(rx_8192_to_9022_octet_packets); |
| 10632 | |
| 10633 | ESTAT_ADD(tx_octets); |
| 10634 | ESTAT_ADD(tx_collisions); |
| 10635 | ESTAT_ADD(tx_xon_sent); |
| 10636 | ESTAT_ADD(tx_xoff_sent); |
| 10637 | ESTAT_ADD(tx_flow_control); |
| 10638 | ESTAT_ADD(tx_mac_errors); |
| 10639 | ESTAT_ADD(tx_single_collisions); |
| 10640 | ESTAT_ADD(tx_mult_collisions); |
| 10641 | ESTAT_ADD(tx_deferred); |
| 10642 | ESTAT_ADD(tx_excessive_collisions); |
| 10643 | ESTAT_ADD(tx_late_collisions); |
| 10644 | ESTAT_ADD(tx_collide_2times); |
| 10645 | ESTAT_ADD(tx_collide_3times); |
| 10646 | ESTAT_ADD(tx_collide_4times); |
| 10647 | ESTAT_ADD(tx_collide_5times); |
| 10648 | ESTAT_ADD(tx_collide_6times); |
| 10649 | ESTAT_ADD(tx_collide_7times); |
| 10650 | ESTAT_ADD(tx_collide_8times); |
| 10651 | ESTAT_ADD(tx_collide_9times); |
| 10652 | ESTAT_ADD(tx_collide_10times); |
| 10653 | ESTAT_ADD(tx_collide_11times); |
| 10654 | ESTAT_ADD(tx_collide_12times); |
| 10655 | ESTAT_ADD(tx_collide_13times); |
| 10656 | ESTAT_ADD(tx_collide_14times); |
| 10657 | ESTAT_ADD(tx_collide_15times); |
| 10658 | ESTAT_ADD(tx_ucast_packets); |
| 10659 | ESTAT_ADD(tx_mcast_packets); |
| 10660 | ESTAT_ADD(tx_bcast_packets); |
| 10661 | ESTAT_ADD(tx_carrier_sense_errors); |
| 10662 | ESTAT_ADD(tx_discards); |
| 10663 | ESTAT_ADD(tx_errors); |
| 10664 | |
| 10665 | ESTAT_ADD(dma_writeq_full); |
| 10666 | ESTAT_ADD(dma_write_prioq_full); |
| 10667 | ESTAT_ADD(rxbds_empty); |
| 10668 | ESTAT_ADD(rx_discards); |
| 10669 | ESTAT_ADD(rx_errors); |
| 10670 | ESTAT_ADD(rx_threshold_hit); |
| 10671 | |
| 10672 | ESTAT_ADD(dma_readq_full); |
| 10673 | ESTAT_ADD(dma_read_prioq_full); |
| 10674 | ESTAT_ADD(tx_comp_queue_full); |
| 10675 | |
| 10676 | ESTAT_ADD(ring_set_send_prod_index); |
| 10677 | ESTAT_ADD(ring_status_update); |
| 10678 | ESTAT_ADD(nic_irqs); |
| 10679 | ESTAT_ADD(nic_avoided_irqs); |
| 10680 | ESTAT_ADD(nic_tx_threshold_hit); |
| 10681 | |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 10682 | ESTAT_ADD(mbuf_lwm_thresh_hit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10683 | } |
| 10684 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10685 | 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] | 10686 | { |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 10687 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10688 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10690 | stats->rx_packets = old_stats->rx_packets + |
| 10691 | get_stat64(&hw_stats->rx_ucast_packets) + |
| 10692 | get_stat64(&hw_stats->rx_mcast_packets) + |
| 10693 | get_stat64(&hw_stats->rx_bcast_packets); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10695 | stats->tx_packets = old_stats->tx_packets + |
| 10696 | get_stat64(&hw_stats->tx_ucast_packets) + |
| 10697 | get_stat64(&hw_stats->tx_mcast_packets) + |
| 10698 | get_stat64(&hw_stats->tx_bcast_packets); |
| 10699 | |
| 10700 | stats->rx_bytes = old_stats->rx_bytes + |
| 10701 | get_stat64(&hw_stats->rx_octets); |
| 10702 | stats->tx_bytes = old_stats->tx_bytes + |
| 10703 | get_stat64(&hw_stats->tx_octets); |
| 10704 | |
| 10705 | stats->rx_errors = old_stats->rx_errors + |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 10706 | get_stat64(&hw_stats->rx_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10707 | stats->tx_errors = old_stats->tx_errors + |
| 10708 | get_stat64(&hw_stats->tx_errors) + |
| 10709 | get_stat64(&hw_stats->tx_mac_errors) + |
| 10710 | get_stat64(&hw_stats->tx_carrier_sense_errors) + |
| 10711 | get_stat64(&hw_stats->tx_discards); |
| 10712 | |
| 10713 | stats->multicast = old_stats->multicast + |
| 10714 | get_stat64(&hw_stats->rx_mcast_packets); |
| 10715 | stats->collisions = old_stats->collisions + |
| 10716 | get_stat64(&hw_stats->tx_collisions); |
| 10717 | |
| 10718 | stats->rx_length_errors = old_stats->rx_length_errors + |
| 10719 | get_stat64(&hw_stats->rx_frame_too_long_errors) + |
| 10720 | get_stat64(&hw_stats->rx_undersize_packets); |
| 10721 | |
| 10722 | stats->rx_over_errors = old_stats->rx_over_errors + |
| 10723 | get_stat64(&hw_stats->rxbds_empty); |
| 10724 | stats->rx_frame_errors = old_stats->rx_frame_errors + |
| 10725 | get_stat64(&hw_stats->rx_align_errors); |
| 10726 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + |
| 10727 | get_stat64(&hw_stats->tx_discards); |
| 10728 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + |
| 10729 | get_stat64(&hw_stats->tx_carrier_sense_errors); |
| 10730 | |
| 10731 | stats->rx_crc_errors = old_stats->rx_crc_errors + |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10732 | tg3_calc_crc_errors(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10733 | |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 10734 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
| 10735 | get_stat64(&hw_stats->rx_discards); |
| 10736 | |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 10737 | stats->rx_dropped = tp->rx_dropped; |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 10738 | stats->tx_dropped = tp->tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10739 | } |
| 10740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10741 | static int tg3_get_regs_len(struct net_device *dev) |
| 10742 | { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 10743 | return TG3_REG_BLK_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10744 | } |
| 10745 | |
| 10746 | static void tg3_get_regs(struct net_device *dev, |
| 10747 | struct ethtool_regs *regs, void *_p) |
| 10748 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10749 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10750 | |
| 10751 | regs->version = 0; |
| 10752 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 10753 | memset(_p, 0, TG3_REG_BLK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10754 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 10755 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10756 | return; |
| 10757 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10758 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10759 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 10760 | tg3_dump_legacy_regs(tp, (u32 *)_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10761 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10762 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10763 | } |
| 10764 | |
| 10765 | static int tg3_get_eeprom_len(struct net_device *dev) |
| 10766 | { |
| 10767 | struct tg3 *tp = netdev_priv(dev); |
| 10768 | |
| 10769 | return tp->nvram_size; |
| 10770 | } |
| 10771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10772 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 10773 | { |
| 10774 | struct tg3 *tp = netdev_priv(dev); |
| 10775 | int ret; |
| 10776 | u8 *pd; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10777 | u32 i, offset, len, b_offset, b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10778 | __be32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10779 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10780 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 10781 | return -EINVAL; |
| 10782 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 10783 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10784 | return -EAGAIN; |
| 10785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10786 | offset = eeprom->offset; |
| 10787 | len = eeprom->len; |
| 10788 | eeprom->len = 0; |
| 10789 | |
| 10790 | eeprom->magic = TG3_EEPROM_MAGIC; |
| 10791 | |
| 10792 | if (offset & 3) { |
| 10793 | /* adjustments to start on required 4 byte boundary */ |
| 10794 | b_offset = offset & 3; |
| 10795 | b_count = 4 - b_offset; |
| 10796 | if (b_count > len) { |
| 10797 | /* i.e. offset=1 len=2 */ |
| 10798 | b_count = len; |
| 10799 | } |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10800 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10801 | if (ret) |
| 10802 | return ret; |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 10803 | memcpy(data, ((char *)&val) + b_offset, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10804 | len -= b_count; |
| 10805 | offset += b_count; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10806 | eeprom->len += b_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10807 | } |
| 10808 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10809 | /* read bytes up to the last 4 byte boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10810 | pd = &data[eeprom->len]; |
| 10811 | for (i = 0; i < (len - (len & 3)); i += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10812 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10813 | if (ret) { |
| 10814 | eeprom->len += i; |
| 10815 | return ret; |
| 10816 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10817 | memcpy(pd + i, &val, 4); |
| 10818 | } |
| 10819 | eeprom->len += i; |
| 10820 | |
| 10821 | if (len & 3) { |
| 10822 | /* read last bytes not ending on 4 byte boundary */ |
| 10823 | pd = &data[eeprom->len]; |
| 10824 | b_count = len & 3; |
| 10825 | b_offset = offset + len - b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10826 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10827 | if (ret) |
| 10828 | return ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10829 | memcpy(pd, &val, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10830 | eeprom->len += b_count; |
| 10831 | } |
| 10832 | return 0; |
| 10833 | } |
| 10834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10835 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 10836 | { |
| 10837 | struct tg3 *tp = netdev_priv(dev); |
| 10838 | int ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10839 | u32 offset, len, b_offset, odd_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10840 | u8 *buf; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10841 | __be32 start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10842 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 10843 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 10844 | return -EAGAIN; |
| 10845 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10846 | if (tg3_flag(tp, NO_NVRAM) || |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 10847 | eeprom->magic != TG3_EEPROM_MAGIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10848 | return -EINVAL; |
| 10849 | |
| 10850 | offset = eeprom->offset; |
| 10851 | len = eeprom->len; |
| 10852 | |
| 10853 | if ((b_offset = (offset & 3))) { |
| 10854 | /* adjustments to start on required 4 byte boundary */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10855 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10856 | if (ret) |
| 10857 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10858 | len += b_offset; |
| 10859 | offset &= ~3; |
Michael Chan | 1c8594b4 | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 10860 | if (len < 4) |
| 10861 | len = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10862 | } |
| 10863 | |
| 10864 | odd_len = 0; |
Michael Chan | 1c8594b4 | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 10865 | if (len & 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10866 | /* adjustments to end on required 4 byte boundary */ |
| 10867 | odd_len = 1; |
| 10868 | len = (len + 3) & ~3; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10869 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10870 | if (ret) |
| 10871 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10872 | } |
| 10873 | |
| 10874 | buf = data; |
| 10875 | if (b_offset || odd_len) { |
| 10876 | buf = kmalloc(len, GFP_KERNEL); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 10877 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10878 | return -ENOMEM; |
| 10879 | if (b_offset) |
| 10880 | memcpy(buf, &start, 4); |
| 10881 | if (odd_len) |
| 10882 | memcpy(buf+len-4, &end, 4); |
| 10883 | memcpy(buf + b_offset, data, eeprom->len); |
| 10884 | } |
| 10885 | |
| 10886 | ret = tg3_nvram_write_block(tp, offset, len, buf); |
| 10887 | |
| 10888 | if (buf != data) |
| 10889 | kfree(buf); |
| 10890 | |
| 10891 | return ret; |
| 10892 | } |
| 10893 | |
| 10894 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 10895 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10896 | struct tg3 *tp = netdev_priv(dev); |
| 10897 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10898 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10899 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10900 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10901 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10902 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 10903 | return phy_ethtool_gset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10904 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10906 | cmd->supported = (SUPPORTED_Autoneg); |
| 10907 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10908 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10909 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
| 10910 | SUPPORTED_1000baseT_Full); |
| 10911 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10912 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10913 | cmd->supported |= (SUPPORTED_100baseT_Half | |
| 10914 | SUPPORTED_100baseT_Full | |
| 10915 | SUPPORTED_10baseT_Half | |
| 10916 | SUPPORTED_10baseT_Full | |
Matt Carlson | 3bebab5 | 2007-11-12 21:22:40 -0800 | [diff] [blame] | 10917 | SUPPORTED_TP); |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 10918 | cmd->port = PORT_TP; |
| 10919 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10920 | cmd->supported |= SUPPORTED_FIBRE; |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 10921 | cmd->port = PORT_FIBRE; |
| 10922 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10924 | cmd->advertising = tp->link_config.advertising; |
Matt Carlson | 5bb0977 | 2011-06-13 13:39:00 +0000 | [diff] [blame] | 10925 | if (tg3_flag(tp, PAUSE_AUTONEG)) { |
| 10926 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) { |
| 10927 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 10928 | cmd->advertising |= ADVERTISED_Pause; |
| 10929 | } else { |
| 10930 | cmd->advertising |= ADVERTISED_Pause | |
| 10931 | ADVERTISED_Asym_Pause; |
| 10932 | } |
| 10933 | } else if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 10934 | cmd->advertising |= ADVERTISED_Asym_Pause; |
| 10935 | } |
| 10936 | } |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 10937 | if (netif_running(dev) && tp->link_up) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 10938 | ethtool_cmd_speed_set(cmd, tp->link_config.active_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10939 | cmd->duplex = tp->link_config.active_duplex; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 10940 | cmd->lp_advertising = tp->link_config.rmt_adv; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 10941 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 10942 | if (tp->phy_flags & TG3_PHYFLG_MDIX_STATE) |
| 10943 | cmd->eth_tp_mdix = ETH_TP_MDI_X; |
| 10944 | else |
| 10945 | cmd->eth_tp_mdix = ETH_TP_MDI; |
| 10946 | } |
Matt Carlson | 64c2218 | 2010-10-14 10:37:44 +0000 | [diff] [blame] | 10947 | } else { |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 10948 | ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN); |
| 10949 | cmd->duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 10950 | cmd->eth_tp_mdix = ETH_TP_MDI_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10951 | } |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 10952 | cmd->phy_address = tp->phy_addr; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10953 | cmd->transceiver = XCVR_INTERNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10954 | cmd->autoneg = tp->link_config.autoneg; |
| 10955 | cmd->maxtxpkt = 0; |
| 10956 | cmd->maxrxpkt = 0; |
| 10957 | return 0; |
| 10958 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10960 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 10961 | { |
| 10962 | struct tg3 *tp = netdev_priv(dev); |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 10963 | u32 speed = ethtool_cmd_speed(cmd); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10964 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10965 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10966 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10967 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10968 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10969 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 10970 | return phy_ethtool_sset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10971 | } |
| 10972 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10973 | if (cmd->autoneg != AUTONEG_ENABLE && |
| 10974 | cmd->autoneg != AUTONEG_DISABLE) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 10975 | return -EINVAL; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10976 | |
| 10977 | if (cmd->autoneg == AUTONEG_DISABLE && |
| 10978 | cmd->duplex != DUPLEX_FULL && |
| 10979 | cmd->duplex != DUPLEX_HALF) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 10980 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10981 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10982 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 10983 | u32 mask = ADVERTISED_Autoneg | |
| 10984 | ADVERTISED_Pause | |
| 10985 | ADVERTISED_Asym_Pause; |
| 10986 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10987 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10988 | mask |= ADVERTISED_1000baseT_Half | |
| 10989 | ADVERTISED_1000baseT_Full; |
| 10990 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10991 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 10992 | mask |= ADVERTISED_100baseT_Half | |
| 10993 | ADVERTISED_100baseT_Full | |
| 10994 | ADVERTISED_10baseT_Half | |
| 10995 | ADVERTISED_10baseT_Full | |
| 10996 | ADVERTISED_TP; |
| 10997 | else |
| 10998 | mask |= ADVERTISED_FIBRE; |
| 10999 | |
| 11000 | if (cmd->advertising & ~mask) |
| 11001 | return -EINVAL; |
| 11002 | |
| 11003 | mask &= (ADVERTISED_1000baseT_Half | |
| 11004 | ADVERTISED_1000baseT_Full | |
| 11005 | ADVERTISED_100baseT_Half | |
| 11006 | ADVERTISED_100baseT_Full | |
| 11007 | ADVERTISED_10baseT_Half | |
| 11008 | ADVERTISED_10baseT_Full); |
| 11009 | |
| 11010 | cmd->advertising &= mask; |
| 11011 | } else { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11012 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11013 | if (speed != SPEED_1000) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11014 | return -EINVAL; |
| 11015 | |
| 11016 | if (cmd->duplex != DUPLEX_FULL) |
| 11017 | return -EINVAL; |
| 11018 | } else { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11019 | if (speed != SPEED_100 && |
| 11020 | speed != SPEED_10) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11021 | return -EINVAL; |
| 11022 | } |
| 11023 | } |
| 11024 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11025 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11026 | |
| 11027 | tp->link_config.autoneg = cmd->autoneg; |
| 11028 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Andy Gospodarek | 405d8e5 | 2007-10-08 01:08:47 -0700 | [diff] [blame] | 11029 | tp->link_config.advertising = (cmd->advertising | |
| 11030 | ADVERTISED_Autoneg); |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 11031 | tp->link_config.speed = SPEED_UNKNOWN; |
| 11032 | tp->link_config.duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11033 | } else { |
| 11034 | tp->link_config.advertising = 0; |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11035 | tp->link_config.speed = speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11036 | tp->link_config.duplex = cmd->duplex; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11037 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11039 | if (netif_running(dev)) |
| 11040 | tg3_setup_phy(tp, 1); |
| 11041 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11042 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11044 | return 0; |
| 11045 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11047 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 11048 | { |
| 11049 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11050 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 11051 | strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); |
| 11052 | strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); |
| 11053 | strlcpy(info->fw_version, tp->fw_ver, sizeof(info->fw_version)); |
| 11054 | strlcpy(info->bus_info, pci_name(tp->pdev), sizeof(info->bus_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11055 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11057 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 11058 | { |
| 11059 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11060 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11061 | if (tg3_flag(tp, WOL_CAP) && device_can_wakeup(&tp->pdev->dev)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 11062 | wol->supported = WAKE_MAGIC; |
| 11063 | else |
| 11064 | wol->supported = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11065 | wol->wolopts = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11066 | if (tg3_flag(tp, WOL_ENABLE) && device_can_wakeup(&tp->pdev->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11067 | wol->wolopts = WAKE_MAGIC; |
| 11068 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 11069 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11071 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 11072 | { |
| 11073 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 11074 | struct device *dp = &tp->pdev->dev; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11076 | if (wol->wolopts & ~WAKE_MAGIC) |
| 11077 | return -EINVAL; |
| 11078 | if ((wol->wolopts & WAKE_MAGIC) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11079 | !(tg3_flag(tp, WOL_CAP) && device_can_wakeup(dp))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11080 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11081 | |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 11082 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
| 11083 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11084 | spin_lock_bh(&tp->lock); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 11085 | if (device_may_wakeup(dp)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11086 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 11087 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11088 | tg3_flag_clear(tp, WOL_ENABLE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11089 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11091 | return 0; |
| 11092 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11093 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11094 | static u32 tg3_get_msglevel(struct net_device *dev) |
| 11095 | { |
| 11096 | struct tg3 *tp = netdev_priv(dev); |
| 11097 | return tp->msg_enable; |
| 11098 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11100 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
| 11101 | { |
| 11102 | struct tg3 *tp = netdev_priv(dev); |
| 11103 | tp->msg_enable = value; |
| 11104 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11106 | static int tg3_nway_reset(struct net_device *dev) |
| 11107 | { |
| 11108 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11109 | int r; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11111 | if (!netif_running(dev)) |
| 11112 | return -EAGAIN; |
| 11113 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11114 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 11115 | return -EINVAL; |
| 11116 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11117 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11118 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11119 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11120 | 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] | 11121 | } else { |
| 11122 | u32 bmcr; |
| 11123 | |
| 11124 | spin_lock_bh(&tp->lock); |
| 11125 | r = -EINVAL; |
| 11126 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 11127 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && |
| 11128 | ((bmcr & BMCR_ANENABLE) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11129 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11130 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
| 11131 | BMCR_ANENABLE); |
| 11132 | r = 0; |
| 11133 | } |
| 11134 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11135 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11137 | return r; |
| 11138 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11140 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 11141 | { |
| 11142 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11143 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 11144 | ering->rx_max_pending = tp->rx_std_ring_mask; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11145 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 11146 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 11147 | else |
| 11148 | ering->rx_jumbo_max_pending = 0; |
| 11149 | |
| 11150 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11151 | |
| 11152 | ering->rx_pending = tp->rx_pending; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11153 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 11154 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
| 11155 | else |
| 11156 | ering->rx_jumbo_pending = 0; |
| 11157 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11158 | ering->tx_pending = tp->napi[0].tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11159 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11161 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 11162 | { |
| 11163 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 11164 | int i, irq_sync = 0, err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11165 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 11166 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
| 11167 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 11168 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
| 11169 | (ering->tx_pending <= MAX_SKB_FRAGS) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11170 | (tg3_flag(tp, TSO_BUG) && |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 11171 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11172 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11173 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11174 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11175 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11176 | tg3_netif_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11177 | irq_sync = 1; |
| 11178 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11179 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11180 | tg3_full_lock(tp, irq_sync); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11182 | tp->rx_pending = ering->rx_pending; |
| 11183 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11184 | if (tg3_flag(tp, MAX_RXPEND_64) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11185 | tp->rx_pending > 63) |
| 11186 | tp->rx_pending = 63; |
| 11187 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 11188 | |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 11189 | for (i = 0; i < tp->irq_max; i++) |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 11190 | tp->napi[i].tx_pending = ering->tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11191 | |
| 11192 | if (netif_running(dev)) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 11193 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11194 | err = tg3_restart_hw(tp, 1); |
| 11195 | if (!err) |
| 11196 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11197 | } |
| 11198 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11199 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11200 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11201 | if (irq_sync && !err) |
| 11202 | tg3_phy_start(tp); |
| 11203 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11204 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11205 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11207 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 11208 | { |
| 11209 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11210 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11211 | epause->autoneg = !!tg3_flag(tp, PAUSE_AUTONEG); |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 11212 | |
Matt Carlson | 4a2db50 | 2011-12-08 14:40:17 +0000 | [diff] [blame] | 11213 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 11214 | epause->rx_pause = 1; |
| 11215 | else |
| 11216 | epause->rx_pause = 0; |
| 11217 | |
Matt Carlson | 4a2db50 | 2011-12-08 14:40:17 +0000 | [diff] [blame] | 11218 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 11219 | epause->tx_pause = 1; |
| 11220 | else |
| 11221 | epause->tx_pause = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11222 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11224 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 11225 | { |
| 11226 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11227 | int err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11228 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11229 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11230 | u32 newadv; |
| 11231 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11232 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11233 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11234 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11235 | if (!(phydev->supported & SUPPORTED_Pause) || |
| 11236 | (!(phydev->supported & SUPPORTED_Asym_Pause) && |
Nicolas Kaiser | 2259dca | 2010-10-07 23:29:27 +0000 | [diff] [blame] | 11237 | (epause->rx_pause != epause->tx_pause))) |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11238 | return -EINVAL; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11239 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11240 | tp->link_config.flowctrl = 0; |
| 11241 | if (epause->rx_pause) { |
| 11242 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11243 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11244 | if (epause->tx_pause) { |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 11245 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11246 | newadv = ADVERTISED_Pause; |
| 11247 | } else |
| 11248 | newadv = ADVERTISED_Pause | |
| 11249 | ADVERTISED_Asym_Pause; |
| 11250 | } else if (epause->tx_pause) { |
| 11251 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 11252 | newadv = ADVERTISED_Asym_Pause; |
| 11253 | } else |
| 11254 | newadv = 0; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11255 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11256 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11257 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11258 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11259 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11260 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11261 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11262 | u32 oldadv = phydev->advertising & |
| 11263 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 11264 | if (oldadv != newadv) { |
| 11265 | phydev->advertising &= |
| 11266 | ~(ADVERTISED_Pause | |
| 11267 | ADVERTISED_Asym_Pause); |
| 11268 | phydev->advertising |= newadv; |
| 11269 | if (phydev->autoneg) { |
| 11270 | /* |
| 11271 | * Always renegotiate the link to |
| 11272 | * inform our link partner of our |
| 11273 | * flow control settings, even if the |
| 11274 | * flow control is forced. Let |
| 11275 | * tg3_adjust_link() do the final |
| 11276 | * flow control setup. |
| 11277 | */ |
| 11278 | return phy_start_aneg(phydev); |
| 11279 | } |
| 11280 | } |
| 11281 | |
| 11282 | if (!epause->autoneg) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11283 | tg3_setup_flow_control(tp, 0, 0); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11284 | } else { |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 11285 | tp->link_config.advertising &= |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11286 | ~(ADVERTISED_Pause | |
| 11287 | ADVERTISED_Asym_Pause); |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 11288 | tp->link_config.advertising |= newadv; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11289 | } |
| 11290 | } else { |
| 11291 | int irq_sync = 0; |
| 11292 | |
| 11293 | if (netif_running(dev)) { |
| 11294 | tg3_netif_stop(tp); |
| 11295 | irq_sync = 1; |
| 11296 | } |
| 11297 | |
| 11298 | tg3_full_lock(tp, irq_sync); |
| 11299 | |
| 11300 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11301 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11302 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11303 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11304 | if (epause->rx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 11305 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11306 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 11307 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11308 | if (epause->tx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 11309 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11310 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 11311 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11312 | |
| 11313 | if (netif_running(dev)) { |
| 11314 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11315 | err = tg3_restart_hw(tp, 1); |
| 11316 | if (!err) |
| 11317 | tg3_netif_start(tp); |
| 11318 | } |
| 11319 | |
| 11320 | tg3_full_unlock(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11322 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11323 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11324 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11325 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 11326 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11327 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 11328 | switch (sset) { |
| 11329 | case ETH_SS_TEST: |
| 11330 | return TG3_NUM_TEST; |
| 11331 | case ETH_SS_STATS: |
| 11332 | return TG3_NUM_STATS; |
| 11333 | default: |
| 11334 | return -EOPNOTSUPP; |
| 11335 | } |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11336 | } |
| 11337 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 11338 | static int tg3_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info, |
| 11339 | u32 *rules __always_unused) |
| 11340 | { |
| 11341 | struct tg3 *tp = netdev_priv(dev); |
| 11342 | |
| 11343 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 11344 | return -EOPNOTSUPP; |
| 11345 | |
| 11346 | switch (info->cmd) { |
| 11347 | case ETHTOOL_GRXRINGS: |
| 11348 | if (netif_running(tp->dev)) |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11349 | info->data = tp->rxq_cnt; |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 11350 | else { |
| 11351 | info->data = num_online_cpus(); |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11352 | if (info->data > TG3_RSS_MAX_NUM_QS) |
| 11353 | info->data = TG3_RSS_MAX_NUM_QS; |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 11354 | } |
| 11355 | |
| 11356 | /* The first interrupt vector only |
| 11357 | * handles link interrupts. |
| 11358 | */ |
| 11359 | info->data -= 1; |
| 11360 | return 0; |
| 11361 | |
| 11362 | default: |
| 11363 | return -EOPNOTSUPP; |
| 11364 | } |
| 11365 | } |
| 11366 | |
| 11367 | static u32 tg3_get_rxfh_indir_size(struct net_device *dev) |
| 11368 | { |
| 11369 | u32 size = 0; |
| 11370 | struct tg3 *tp = netdev_priv(dev); |
| 11371 | |
| 11372 | if (tg3_flag(tp, SUPPORT_MSIX)) |
| 11373 | size = TG3_RSS_INDIR_TBL_SIZE; |
| 11374 | |
| 11375 | return size; |
| 11376 | } |
| 11377 | |
| 11378 | static int tg3_get_rxfh_indir(struct net_device *dev, u32 *indir) |
| 11379 | { |
| 11380 | struct tg3 *tp = netdev_priv(dev); |
| 11381 | int i; |
| 11382 | |
| 11383 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 11384 | indir[i] = tp->rss_ind_tbl[i]; |
| 11385 | |
| 11386 | return 0; |
| 11387 | } |
| 11388 | |
| 11389 | static int tg3_set_rxfh_indir(struct net_device *dev, const u32 *indir) |
| 11390 | { |
| 11391 | struct tg3 *tp = netdev_priv(dev); |
| 11392 | size_t i; |
| 11393 | |
| 11394 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 11395 | tp->rss_ind_tbl[i] = indir[i]; |
| 11396 | |
| 11397 | if (!netif_running(dev) || !tg3_flag(tp, ENABLE_RSS)) |
| 11398 | return 0; |
| 11399 | |
| 11400 | /* It is legal to write the indirection |
| 11401 | * table while the device is running. |
| 11402 | */ |
| 11403 | tg3_full_lock(tp, 0); |
| 11404 | tg3_rss_write_indir_tbl(tp); |
| 11405 | tg3_full_unlock(tp); |
| 11406 | |
| 11407 | return 0; |
| 11408 | } |
| 11409 | |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 11410 | static void tg3_get_channels(struct net_device *dev, |
| 11411 | struct ethtool_channels *channel) |
| 11412 | { |
| 11413 | struct tg3 *tp = netdev_priv(dev); |
| 11414 | u32 deflt_qs = netif_get_num_default_rss_queues(); |
| 11415 | |
| 11416 | channel->max_rx = tp->rxq_max; |
| 11417 | channel->max_tx = tp->txq_max; |
| 11418 | |
| 11419 | if (netif_running(dev)) { |
| 11420 | channel->rx_count = tp->rxq_cnt; |
| 11421 | channel->tx_count = tp->txq_cnt; |
| 11422 | } else { |
| 11423 | if (tp->rxq_req) |
| 11424 | channel->rx_count = tp->rxq_req; |
| 11425 | else |
| 11426 | channel->rx_count = min(deflt_qs, tp->rxq_max); |
| 11427 | |
| 11428 | if (tp->txq_req) |
| 11429 | channel->tx_count = tp->txq_req; |
| 11430 | else |
| 11431 | channel->tx_count = min(deflt_qs, tp->txq_max); |
| 11432 | } |
| 11433 | } |
| 11434 | |
| 11435 | static int tg3_set_channels(struct net_device *dev, |
| 11436 | struct ethtool_channels *channel) |
| 11437 | { |
| 11438 | struct tg3 *tp = netdev_priv(dev); |
| 11439 | |
| 11440 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 11441 | return -EOPNOTSUPP; |
| 11442 | |
| 11443 | if (channel->rx_count > tp->rxq_max || |
| 11444 | channel->tx_count > tp->txq_max) |
| 11445 | return -EINVAL; |
| 11446 | |
| 11447 | tp->rxq_req = channel->rx_count; |
| 11448 | tp->txq_req = channel->tx_count; |
| 11449 | |
| 11450 | if (!netif_running(dev)) |
| 11451 | return 0; |
| 11452 | |
| 11453 | tg3_stop(tp); |
| 11454 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 11455 | tg3_carrier_off(tp); |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 11456 | |
| 11457 | tg3_start(tp, true, false); |
| 11458 | |
| 11459 | return 0; |
| 11460 | } |
| 11461 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 11462 | 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] | 11463 | { |
| 11464 | switch (stringset) { |
| 11465 | case ETH_SS_STATS: |
| 11466 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 11467 | break; |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11468 | case ETH_SS_TEST: |
| 11469 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); |
| 11470 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11471 | default: |
| 11472 | WARN_ON(1); /* we need a WARN() */ |
| 11473 | break; |
| 11474 | } |
| 11475 | } |
| 11476 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11477 | static int tg3_set_phys_id(struct net_device *dev, |
| 11478 | enum ethtool_phys_id_state state) |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11479 | { |
| 11480 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11481 | |
| 11482 | if (!netif_running(tp->dev)) |
| 11483 | return -EAGAIN; |
| 11484 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11485 | switch (state) { |
| 11486 | case ETHTOOL_ID_ACTIVE: |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 11487 | return 1; /* cycle on/off once per second */ |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11488 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11489 | case ETHTOOL_ID_ON: |
| 11490 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 11491 | LED_CTRL_1000MBPS_ON | |
| 11492 | LED_CTRL_100MBPS_ON | |
| 11493 | LED_CTRL_10MBPS_ON | |
| 11494 | LED_CTRL_TRAFFIC_OVERRIDE | |
| 11495 | LED_CTRL_TRAFFIC_BLINK | |
| 11496 | LED_CTRL_TRAFFIC_LED); |
| 11497 | break; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11498 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11499 | case ETHTOOL_ID_OFF: |
| 11500 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 11501 | LED_CTRL_TRAFFIC_OVERRIDE); |
| 11502 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11503 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11504 | case ETHTOOL_ID_INACTIVE: |
| 11505 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 11506 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11507 | } |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11508 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11509 | return 0; |
| 11510 | } |
| 11511 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 11512 | static void tg3_get_ethtool_stats(struct net_device *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11513 | struct ethtool_stats *estats, u64 *tmp_stats) |
| 11514 | { |
| 11515 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 0e6c9da | 2011-12-08 14:40:13 +0000 | [diff] [blame] | 11516 | |
Matt Carlson | b546e46 | 2012-02-13 15:20:09 +0000 | [diff] [blame] | 11517 | if (tp->hw_stats) |
| 11518 | tg3_get_estats(tp, (struct tg3_ethtool_stats *)tmp_stats); |
| 11519 | else |
| 11520 | memset(tmp_stats, 0, sizeof(struct tg3_ethtool_stats)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11521 | } |
| 11522 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11523 | static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11524 | { |
| 11525 | int i; |
| 11526 | __be32 *buf; |
| 11527 | u32 offset = 0, len = 0; |
| 11528 | u32 magic, val; |
| 11529 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11530 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &magic)) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11531 | return NULL; |
| 11532 | |
| 11533 | if (magic == TG3_EEPROM_MAGIC) { |
| 11534 | for (offset = TG3_NVM_DIR_START; |
| 11535 | offset < TG3_NVM_DIR_END; |
| 11536 | offset += TG3_NVM_DIRENT_SIZE) { |
| 11537 | if (tg3_nvram_read(tp, offset, &val)) |
| 11538 | return NULL; |
| 11539 | |
| 11540 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == |
| 11541 | TG3_NVM_DIRTYPE_EXTVPD) |
| 11542 | break; |
| 11543 | } |
| 11544 | |
| 11545 | if (offset != TG3_NVM_DIR_END) { |
| 11546 | len = (val & TG3_NVM_DIRTYPE_LENMSK) * 4; |
| 11547 | if (tg3_nvram_read(tp, offset + 4, &offset)) |
| 11548 | return NULL; |
| 11549 | |
| 11550 | offset = tg3_nvram_logical_addr(tp, offset); |
| 11551 | } |
| 11552 | } |
| 11553 | |
| 11554 | if (!offset || !len) { |
| 11555 | offset = TG3_NVM_VPD_OFF; |
| 11556 | len = TG3_NVM_VPD_LEN; |
| 11557 | } |
| 11558 | |
| 11559 | buf = kmalloc(len, GFP_KERNEL); |
| 11560 | if (buf == NULL) |
| 11561 | return NULL; |
| 11562 | |
| 11563 | if (magic == TG3_EEPROM_MAGIC) { |
| 11564 | for (i = 0; i < len; i += 4) { |
| 11565 | /* The data is in little-endian format in NVRAM. |
| 11566 | * Use the big-endian read routines to preserve |
| 11567 | * the byte order as it exists in NVRAM. |
| 11568 | */ |
| 11569 | if (tg3_nvram_read_be32(tp, offset + i, &buf[i/4])) |
| 11570 | goto error; |
| 11571 | } |
| 11572 | } else { |
| 11573 | u8 *ptr; |
| 11574 | ssize_t cnt; |
| 11575 | unsigned int pos = 0; |
| 11576 | |
| 11577 | ptr = (u8 *)&buf[0]; |
| 11578 | for (i = 0; pos < len && i < 3; i++, pos += cnt, ptr += cnt) { |
| 11579 | cnt = pci_read_vpd(tp->pdev, pos, |
| 11580 | len - pos, ptr); |
| 11581 | if (cnt == -ETIMEDOUT || cnt == -EINTR) |
| 11582 | cnt = 0; |
| 11583 | else if (cnt < 0) |
| 11584 | goto error; |
| 11585 | } |
| 11586 | if (pos != len) |
| 11587 | goto error; |
| 11588 | } |
| 11589 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11590 | *vpdlen = len; |
| 11591 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11592 | return buf; |
| 11593 | |
| 11594 | error: |
| 11595 | kfree(buf); |
| 11596 | return NULL; |
| 11597 | } |
| 11598 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11599 | #define NVRAM_TEST_SIZE 0x100 |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11600 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
| 11601 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 |
| 11602 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11603 | #define NVRAM_SELFBOOT_FORMAT1_4_SIZE 0x20 |
| 11604 | #define NVRAM_SELFBOOT_FORMAT1_5_SIZE 0x24 |
Matt Carlson | bda18fa | 2011-07-20 10:20:57 +0000 | [diff] [blame] | 11605 | #define NVRAM_SELFBOOT_FORMAT1_6_SIZE 0x50 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11606 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
| 11607 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11608 | |
| 11609 | static int tg3_test_nvram(struct tg3 *tp) |
| 11610 | { |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11611 | u32 csum, magic, len; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11612 | __be32 *buf; |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 11613 | int i, j, k, err = 0, size; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11614 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11615 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11616 | return 0; |
| 11617 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11618 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11619 | return -EIO; |
| 11620 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11621 | if (magic == TG3_EEPROM_MAGIC) |
| 11622 | size = NVRAM_TEST_SIZE; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11623 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11624 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
| 11625 | TG3_EEPROM_SB_FORMAT_1) { |
| 11626 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { |
| 11627 | case TG3_EEPROM_SB_REVISION_0: |
| 11628 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; |
| 11629 | break; |
| 11630 | case TG3_EEPROM_SB_REVISION_2: |
| 11631 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; |
| 11632 | break; |
| 11633 | case TG3_EEPROM_SB_REVISION_3: |
| 11634 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; |
| 11635 | break; |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11636 | case TG3_EEPROM_SB_REVISION_4: |
| 11637 | size = NVRAM_SELFBOOT_FORMAT1_4_SIZE; |
| 11638 | break; |
| 11639 | case TG3_EEPROM_SB_REVISION_5: |
| 11640 | size = NVRAM_SELFBOOT_FORMAT1_5_SIZE; |
| 11641 | break; |
| 11642 | case TG3_EEPROM_SB_REVISION_6: |
| 11643 | size = NVRAM_SELFBOOT_FORMAT1_6_SIZE; |
| 11644 | break; |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11645 | default: |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11646 | return -EIO; |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11647 | } |
| 11648 | } else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11649 | return 0; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11650 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 11651 | size = NVRAM_SELFBOOT_HW_SIZE; |
| 11652 | else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11653 | return -EIO; |
| 11654 | |
| 11655 | buf = kmalloc(size, GFP_KERNEL); |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11656 | if (buf == NULL) |
| 11657 | return -ENOMEM; |
| 11658 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11659 | err = -EIO; |
| 11660 | for (i = 0, j = 0; i < size; i += 4, j++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11661 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
| 11662 | if (err) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11663 | break; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11664 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11665 | if (i < size) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11666 | goto out; |
| 11667 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11668 | /* Selfboot format */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11669 | magic = be32_to_cpu(buf[0]); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11670 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11671 | TG3_EEPROM_MAGIC_FW) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11672 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
| 11673 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11674 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11675 | TG3_EEPROM_SB_REVISION_2) { |
| 11676 | /* For rev 2, the csum doesn't include the MBA. */ |
| 11677 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) |
| 11678 | csum8 += buf8[i]; |
| 11679 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) |
| 11680 | csum8 += buf8[i]; |
| 11681 | } else { |
| 11682 | for (i = 0; i < size; i++) |
| 11683 | csum8 += buf8[i]; |
| 11684 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11685 | |
Adrian Bunk | ad96b48 | 2006-04-05 22:21:04 -0700 | [diff] [blame] | 11686 | if (csum8 == 0) { |
| 11687 | err = 0; |
| 11688 | goto out; |
| 11689 | } |
| 11690 | |
| 11691 | err = -EIO; |
| 11692 | goto out; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11693 | } |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11694 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11695 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11696 | TG3_EEPROM_MAGIC_HW) { |
| 11697 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11698 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11699 | u8 *buf8 = (u8 *) buf; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11700 | |
| 11701 | /* Separate the parity bits and the data bytes. */ |
| 11702 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { |
| 11703 | if ((i == 0) || (i == 8)) { |
| 11704 | int l; |
| 11705 | u8 msk; |
| 11706 | |
| 11707 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) |
| 11708 | parity[k++] = buf8[i] & msk; |
| 11709 | i++; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 11710 | } else if (i == 16) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11711 | int l; |
| 11712 | u8 msk; |
| 11713 | |
| 11714 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) |
| 11715 | parity[k++] = buf8[i] & msk; |
| 11716 | i++; |
| 11717 | |
| 11718 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) |
| 11719 | parity[k++] = buf8[i] & msk; |
| 11720 | i++; |
| 11721 | } |
| 11722 | data[j++] = buf8[i]; |
| 11723 | } |
| 11724 | |
| 11725 | err = -EIO; |
| 11726 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { |
| 11727 | u8 hw8 = hweight8(data[i]); |
| 11728 | |
| 11729 | if ((hw8 & 0x1) && parity[i]) |
| 11730 | goto out; |
| 11731 | else if (!(hw8 & 0x1) && !parity[i]) |
| 11732 | goto out; |
| 11733 | } |
| 11734 | err = 0; |
| 11735 | goto out; |
| 11736 | } |
| 11737 | |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 11738 | err = -EIO; |
| 11739 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11740 | /* Bootstrap checksum at offset 0x10 */ |
| 11741 | csum = calc_crc((unsigned char *) buf, 0x10); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 11742 | if (csum != le32_to_cpu(buf[0x10/4])) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11743 | goto out; |
| 11744 | |
| 11745 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ |
| 11746 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 11747 | if (csum != le32_to_cpu(buf[0xfc/4])) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11748 | goto out; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11749 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11750 | kfree(buf); |
| 11751 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11752 | buf = tg3_vpd_readblock(tp, &len); |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11753 | if (!buf) |
| 11754 | return -ENOMEM; |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 11755 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11756 | 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] | 11757 | if (i > 0) { |
| 11758 | j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); |
| 11759 | if (j < 0) |
| 11760 | goto out; |
| 11761 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11762 | if (i + PCI_VPD_LRDT_TAG_SIZE + j > len) |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 11763 | goto out; |
| 11764 | |
| 11765 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 11766 | j = pci_vpd_find_info_keyword((u8 *)buf, i, j, |
| 11767 | PCI_VPD_RO_KEYWORD_CHKSUM); |
| 11768 | if (j > 0) { |
| 11769 | u8 csum8 = 0; |
| 11770 | |
| 11771 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 11772 | |
| 11773 | for (i = 0; i <= j; i++) |
| 11774 | csum8 += ((u8 *)buf)[i]; |
| 11775 | |
| 11776 | if (csum8) |
| 11777 | goto out; |
| 11778 | } |
| 11779 | } |
| 11780 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11781 | err = 0; |
| 11782 | |
| 11783 | out: |
| 11784 | kfree(buf); |
| 11785 | return err; |
| 11786 | } |
| 11787 | |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11788 | #define TG3_SERDES_TIMEOUT_SEC 2 |
| 11789 | #define TG3_COPPER_TIMEOUT_SEC 6 |
| 11790 | |
| 11791 | static int tg3_test_link(struct tg3 *tp) |
| 11792 | { |
| 11793 | int i, max; |
| 11794 | |
| 11795 | if (!netif_running(tp->dev)) |
| 11796 | return -ENODEV; |
| 11797 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11798 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11799 | max = TG3_SERDES_TIMEOUT_SEC; |
| 11800 | else |
| 11801 | max = TG3_COPPER_TIMEOUT_SEC; |
| 11802 | |
| 11803 | for (i = 0; i < max; i++) { |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 11804 | if (tp->link_up) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11805 | return 0; |
| 11806 | |
| 11807 | if (msleep_interruptible(1000)) |
| 11808 | break; |
| 11809 | } |
| 11810 | |
| 11811 | return -EIO; |
| 11812 | } |
| 11813 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11814 | /* Only test the commonly used registers */ |
David S. Miller | 30ca3e3 | 2006-03-20 23:02:36 -0800 | [diff] [blame] | 11815 | static int tg3_test_registers(struct tg3 *tp) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11816 | { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11817 | int i, is_5705, is_5750; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11818 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
| 11819 | static struct { |
| 11820 | u16 offset; |
| 11821 | u16 flags; |
| 11822 | #define TG3_FL_5705 0x1 |
| 11823 | #define TG3_FL_NOT_5705 0x2 |
| 11824 | #define TG3_FL_NOT_5788 0x4 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11825 | #define TG3_FL_NOT_5750 0x8 |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11826 | u32 read_mask; |
| 11827 | u32 write_mask; |
| 11828 | } reg_tbl[] = { |
| 11829 | /* MAC Control Registers */ |
| 11830 | { MAC_MODE, TG3_FL_NOT_5705, |
| 11831 | 0x00000000, 0x00ef6f8c }, |
| 11832 | { MAC_MODE, TG3_FL_5705, |
| 11833 | 0x00000000, 0x01ef6b8c }, |
| 11834 | { MAC_STATUS, TG3_FL_NOT_5705, |
| 11835 | 0x03800107, 0x00000000 }, |
| 11836 | { MAC_STATUS, TG3_FL_5705, |
| 11837 | 0x03800100, 0x00000000 }, |
| 11838 | { MAC_ADDR_0_HIGH, 0x0000, |
| 11839 | 0x00000000, 0x0000ffff }, |
| 11840 | { MAC_ADDR_0_LOW, 0x0000, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 11841 | 0x00000000, 0xffffffff }, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11842 | { MAC_RX_MTU_SIZE, 0x0000, |
| 11843 | 0x00000000, 0x0000ffff }, |
| 11844 | { MAC_TX_MODE, 0x0000, |
| 11845 | 0x00000000, 0x00000070 }, |
| 11846 | { MAC_TX_LENGTHS, 0x0000, |
| 11847 | 0x00000000, 0x00003fff }, |
| 11848 | { MAC_RX_MODE, TG3_FL_NOT_5705, |
| 11849 | 0x00000000, 0x000007fc }, |
| 11850 | { MAC_RX_MODE, TG3_FL_5705, |
| 11851 | 0x00000000, 0x000007dc }, |
| 11852 | { MAC_HASH_REG_0, 0x0000, |
| 11853 | 0x00000000, 0xffffffff }, |
| 11854 | { MAC_HASH_REG_1, 0x0000, |
| 11855 | 0x00000000, 0xffffffff }, |
| 11856 | { MAC_HASH_REG_2, 0x0000, |
| 11857 | 0x00000000, 0xffffffff }, |
| 11858 | { MAC_HASH_REG_3, 0x0000, |
| 11859 | 0x00000000, 0xffffffff }, |
| 11860 | |
| 11861 | /* Receive Data and Receive BD Initiator Control Registers. */ |
| 11862 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, |
| 11863 | 0x00000000, 0xffffffff }, |
| 11864 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, |
| 11865 | 0x00000000, 0xffffffff }, |
| 11866 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, |
| 11867 | 0x00000000, 0x00000003 }, |
| 11868 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, |
| 11869 | 0x00000000, 0xffffffff }, |
| 11870 | { RCVDBDI_STD_BD+0, 0x0000, |
| 11871 | 0x00000000, 0xffffffff }, |
| 11872 | { RCVDBDI_STD_BD+4, 0x0000, |
| 11873 | 0x00000000, 0xffffffff }, |
| 11874 | { RCVDBDI_STD_BD+8, 0x0000, |
| 11875 | 0x00000000, 0xffff0002 }, |
| 11876 | { RCVDBDI_STD_BD+0xc, 0x0000, |
| 11877 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11878 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11879 | /* Receive BD Initiator Control Registers. */ |
| 11880 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, |
| 11881 | 0x00000000, 0xffffffff }, |
| 11882 | { RCVBDI_STD_THRESH, TG3_FL_5705, |
| 11883 | 0x00000000, 0x000003ff }, |
| 11884 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, |
| 11885 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11886 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11887 | /* Host Coalescing Control Registers. */ |
| 11888 | { HOSTCC_MODE, TG3_FL_NOT_5705, |
| 11889 | 0x00000000, 0x00000004 }, |
| 11890 | { HOSTCC_MODE, TG3_FL_5705, |
| 11891 | 0x00000000, 0x000000f6 }, |
| 11892 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, |
| 11893 | 0x00000000, 0xffffffff }, |
| 11894 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, |
| 11895 | 0x00000000, 0x000003ff }, |
| 11896 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, |
| 11897 | 0x00000000, 0xffffffff }, |
| 11898 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, |
| 11899 | 0x00000000, 0x000003ff }, |
| 11900 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, |
| 11901 | 0x00000000, 0xffffffff }, |
| 11902 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11903 | 0x00000000, 0x000000ff }, |
| 11904 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, |
| 11905 | 0x00000000, 0xffffffff }, |
| 11906 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11907 | 0x00000000, 0x000000ff }, |
| 11908 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 11909 | 0x00000000, 0xffffffff }, |
| 11910 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 11911 | 0x00000000, 0xffffffff }, |
| 11912 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 11913 | 0x00000000, 0xffffffff }, |
| 11914 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11915 | 0x00000000, 0x000000ff }, |
| 11916 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 11917 | 0x00000000, 0xffffffff }, |
| 11918 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 11919 | 0x00000000, 0x000000ff }, |
| 11920 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, |
| 11921 | 0x00000000, 0xffffffff }, |
| 11922 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, |
| 11923 | 0x00000000, 0xffffffff }, |
| 11924 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, |
| 11925 | 0x00000000, 0xffffffff }, |
| 11926 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, |
| 11927 | 0x00000000, 0xffffffff }, |
| 11928 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, |
| 11929 | 0x00000000, 0xffffffff }, |
| 11930 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, |
| 11931 | 0xffffffff, 0x00000000 }, |
| 11932 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, |
| 11933 | 0xffffffff, 0x00000000 }, |
| 11934 | |
| 11935 | /* Buffer Manager Control Registers. */ |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11936 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11937 | 0x00000000, 0x007fff80 }, |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11938 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11939 | 0x00000000, 0x007fffff }, |
| 11940 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, |
| 11941 | 0x00000000, 0x0000003f }, |
| 11942 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, |
| 11943 | 0x00000000, 0x000001ff }, |
| 11944 | { BUFMGR_MB_HIGH_WATER, 0x0000, |
| 11945 | 0x00000000, 0x000001ff }, |
| 11946 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, |
| 11947 | 0xffffffff, 0x00000000 }, |
| 11948 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, |
| 11949 | 0xffffffff, 0x00000000 }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11950 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11951 | /* Mailbox Registers */ |
| 11952 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, |
| 11953 | 0x00000000, 0x000001ff }, |
| 11954 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, |
| 11955 | 0x00000000, 0x000001ff }, |
| 11956 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, |
| 11957 | 0x00000000, 0x000007ff }, |
| 11958 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, |
| 11959 | 0x00000000, 0x000001ff }, |
| 11960 | |
| 11961 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, |
| 11962 | }; |
| 11963 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11964 | is_5705 = is_5750 = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11965 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11966 | is_5705 = 1; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11967 | if (tg3_flag(tp, 5750_PLUS)) |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11968 | is_5750 = 1; |
| 11969 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11970 | |
| 11971 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { |
| 11972 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) |
| 11973 | continue; |
| 11974 | |
| 11975 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) |
| 11976 | continue; |
| 11977 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11978 | if (tg3_flag(tp, IS_5788) && |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11979 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
| 11980 | continue; |
| 11981 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11982 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
| 11983 | continue; |
| 11984 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11985 | offset = (u32) reg_tbl[i].offset; |
| 11986 | read_mask = reg_tbl[i].read_mask; |
| 11987 | write_mask = reg_tbl[i].write_mask; |
| 11988 | |
| 11989 | /* Save the original register content */ |
| 11990 | save_val = tr32(offset); |
| 11991 | |
| 11992 | /* Determine the read-only value. */ |
| 11993 | read_val = save_val & read_mask; |
| 11994 | |
| 11995 | /* Write zero to the register, then make sure the read-only bits |
| 11996 | * are not changed and the read/write bits are all zeros. |
| 11997 | */ |
| 11998 | tw32(offset, 0); |
| 11999 | |
| 12000 | val = tr32(offset); |
| 12001 | |
| 12002 | /* Test the read-only and read/write bits. */ |
| 12003 | if (((val & read_mask) != read_val) || (val & write_mask)) |
| 12004 | goto out; |
| 12005 | |
| 12006 | /* Write ones to all the bits defined by RdMask and WrMask, then |
| 12007 | * make sure the read-only bits are not changed and the |
| 12008 | * read/write bits are all ones. |
| 12009 | */ |
| 12010 | tw32(offset, read_mask | write_mask); |
| 12011 | |
| 12012 | val = tr32(offset); |
| 12013 | |
| 12014 | /* Test the read-only bits. */ |
| 12015 | if ((val & read_mask) != read_val) |
| 12016 | goto out; |
| 12017 | |
| 12018 | /* Test the read/write bits. */ |
| 12019 | if ((val & write_mask) != write_mask) |
| 12020 | goto out; |
| 12021 | |
| 12022 | tw32(offset, save_val); |
| 12023 | } |
| 12024 | |
| 12025 | return 0; |
| 12026 | |
| 12027 | out: |
Michael Chan | 9f88f29 | 2006-12-07 00:22:54 -0800 | [diff] [blame] | 12028 | if (netif_msg_hw(tp)) |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 12029 | netdev_err(tp->dev, |
| 12030 | "Register test failed at offset %x\n", offset); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12031 | tw32(offset, save_val); |
| 12032 | return -EIO; |
| 12033 | } |
| 12034 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12035 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
| 12036 | { |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 12037 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12038 | int i; |
| 12039 | u32 j; |
| 12040 | |
Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 12041 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12042 | for (j = 0; j < len; j += 4) { |
| 12043 | u32 val; |
| 12044 | |
| 12045 | tg3_write_mem(tp, offset + j, test_pattern[i]); |
| 12046 | tg3_read_mem(tp, offset + j, &val); |
| 12047 | if (val != test_pattern[i]) |
| 12048 | return -EIO; |
| 12049 | } |
| 12050 | } |
| 12051 | return 0; |
| 12052 | } |
| 12053 | |
| 12054 | static int tg3_test_memory(struct tg3 *tp) |
| 12055 | { |
| 12056 | static struct mem_entry { |
| 12057 | u32 offset; |
| 12058 | u32 len; |
| 12059 | } mem_tbl_570x[] = { |
Michael Chan | 3869019 | 2005-12-19 16:27:28 -0800 | [diff] [blame] | 12060 | { 0x00000000, 0x00b50}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12061 | { 0x00002000, 0x1c000}, |
| 12062 | { 0xffffffff, 0x00000} |
| 12063 | }, mem_tbl_5705[] = { |
| 12064 | { 0x00000100, 0x0000c}, |
| 12065 | { 0x00000200, 0x00008}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12066 | { 0x00004000, 0x00800}, |
| 12067 | { 0x00006000, 0x01000}, |
| 12068 | { 0x00008000, 0x02000}, |
| 12069 | { 0x00010000, 0x0e000}, |
| 12070 | { 0xffffffff, 0x00000} |
Michael Chan | 79f4d13 | 2006-03-20 22:28:57 -0800 | [diff] [blame] | 12071 | }, mem_tbl_5755[] = { |
| 12072 | { 0x00000200, 0x00008}, |
| 12073 | { 0x00004000, 0x00800}, |
| 12074 | { 0x00006000, 0x00800}, |
| 12075 | { 0x00008000, 0x02000}, |
| 12076 | { 0x00010000, 0x0c000}, |
| 12077 | { 0xffffffff, 0x00000} |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12078 | }, mem_tbl_5906[] = { |
| 12079 | { 0x00000200, 0x00008}, |
| 12080 | { 0x00004000, 0x00400}, |
| 12081 | { 0x00006000, 0x00400}, |
| 12082 | { 0x00008000, 0x01000}, |
| 12083 | { 0x00010000, 0x01000}, |
| 12084 | { 0xffffffff, 0x00000} |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 12085 | }, mem_tbl_5717[] = { |
| 12086 | { 0x00000200, 0x00008}, |
| 12087 | { 0x00010000, 0x0a000}, |
| 12088 | { 0x00020000, 0x13c00}, |
| 12089 | { 0xffffffff, 0x00000} |
| 12090 | }, mem_tbl_57765[] = { |
| 12091 | { 0x00000200, 0x00008}, |
| 12092 | { 0x00004000, 0x00800}, |
| 12093 | { 0x00006000, 0x09800}, |
| 12094 | { 0x00010000, 0x0a000}, |
| 12095 | { 0xffffffff, 0x00000} |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12096 | }; |
| 12097 | struct mem_entry *mem_tbl; |
| 12098 | int err = 0; |
| 12099 | int i; |
| 12100 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12101 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 12102 | mem_tbl = mem_tbl_5717; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 12103 | else if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 12104 | mem_tbl = mem_tbl_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12105 | else if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12106 | mem_tbl = mem_tbl_5755; |
| 12107 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 12108 | mem_tbl = mem_tbl_5906; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12109 | else if (tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12110 | mem_tbl = mem_tbl_5705; |
| 12111 | else |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12112 | mem_tbl = mem_tbl_570x; |
| 12113 | |
| 12114 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 12115 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
| 12116 | if (err) |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12117 | break; |
| 12118 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12119 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12120 | return err; |
| 12121 | } |
| 12122 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12123 | #define TG3_TSO_MSS 500 |
| 12124 | |
| 12125 | #define TG3_TSO_IP_HDR_LEN 20 |
| 12126 | #define TG3_TSO_TCP_HDR_LEN 20 |
| 12127 | #define TG3_TSO_TCP_OPT_LEN 12 |
| 12128 | |
| 12129 | static const u8 tg3_tso_header[] = { |
| 12130 | 0x08, 0x00, |
| 12131 | 0x45, 0x00, 0x00, 0x00, |
| 12132 | 0x00, 0x00, 0x40, 0x00, |
| 12133 | 0x40, 0x06, 0x00, 0x00, |
| 12134 | 0x0a, 0x00, 0x00, 0x01, |
| 12135 | 0x0a, 0x00, 0x00, 0x02, |
| 12136 | 0x0d, 0x00, 0xe0, 0x00, |
| 12137 | 0x00, 0x00, 0x01, 0x00, |
| 12138 | 0x00, 0x00, 0x02, 0x00, |
| 12139 | 0x80, 0x10, 0x10, 0x00, |
| 12140 | 0x14, 0x09, 0x00, 0x00, |
| 12141 | 0x01, 0x01, 0x08, 0x0a, |
| 12142 | 0x11, 0x11, 0x11, 0x11, |
| 12143 | 0x11, 0x11, 0x11, 0x11, |
| 12144 | }; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12145 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12146 | 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] | 12147 | { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12148 | u32 rx_start_idx, rx_idx, tx_idx, opaque_key; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12149 | 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] | 12150 | u32 budget; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12151 | struct sk_buff *skb; |
| 12152 | u8 *tx_data, *rx_data; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12153 | dma_addr_t map; |
| 12154 | int num_pkts, tx_len, rx_len, i, err; |
| 12155 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 12156 | struct tg3_napi *tnapi, *rnapi; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 12157 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12158 | |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 12159 | tnapi = &tp->napi[0]; |
| 12160 | rnapi = &tp->napi[0]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 12161 | if (tp->irq_cnt > 1) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12162 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | 1da85aa | 2010-09-30 10:34:34 +0000 | [diff] [blame] | 12163 | rnapi = &tp->napi[1]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12164 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 12165 | tnapi = &tp->napi[1]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 12166 | } |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 12167 | coal_now = tnapi->coal_now | rnapi->coal_now; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 12168 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12169 | err = -EIO; |
| 12170 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12171 | tx_len = pktsz; |
David S. Miller | a20e9c6 | 2006-07-31 22:38:16 -0700 | [diff] [blame] | 12172 | skb = netdev_alloc_skb(tp->dev, tx_len); |
Jesper Juhl | a50bb7b | 2006-05-09 23:14:35 -0700 | [diff] [blame] | 12173 | if (!skb) |
| 12174 | return -ENOMEM; |
| 12175 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12176 | tx_data = skb_put(skb, tx_len); |
| 12177 | memcpy(tx_data, tp->dev->dev_addr, 6); |
| 12178 | memset(tx_data + 6, 0x0, 8); |
| 12179 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12180 | tw32(MAC_RX_MTU_SIZE, tx_len + ETH_FCS_LEN); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12181 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12182 | if (tso_loopback) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12183 | struct iphdr *iph = (struct iphdr *)&tx_data[ETH_HLEN]; |
| 12184 | |
| 12185 | u32 hdr_len = TG3_TSO_IP_HDR_LEN + TG3_TSO_TCP_HDR_LEN + |
| 12186 | TG3_TSO_TCP_OPT_LEN; |
| 12187 | |
| 12188 | memcpy(tx_data + ETH_ALEN * 2, tg3_tso_header, |
| 12189 | sizeof(tg3_tso_header)); |
| 12190 | mss = TG3_TSO_MSS; |
| 12191 | |
| 12192 | val = tx_len - ETH_ALEN * 2 - sizeof(tg3_tso_header); |
| 12193 | num_pkts = DIV_ROUND_UP(val, TG3_TSO_MSS); |
| 12194 | |
| 12195 | /* Set the total length field in the IP header */ |
| 12196 | iph->tot_len = htons((u16)(mss + hdr_len)); |
| 12197 | |
| 12198 | base_flags = (TXD_FLAG_CPU_PRE_DMA | |
| 12199 | TXD_FLAG_CPU_POST_DMA); |
| 12200 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12201 | if (tg3_flag(tp, HW_TSO_1) || |
| 12202 | tg3_flag(tp, HW_TSO_2) || |
| 12203 | tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12204 | struct tcphdr *th; |
| 12205 | val = ETH_HLEN + TG3_TSO_IP_HDR_LEN; |
| 12206 | th = (struct tcphdr *)&tx_data[val]; |
| 12207 | th->check = 0; |
| 12208 | } else |
| 12209 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
| 12210 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12211 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12212 | mss |= (hdr_len & 0xc) << 12; |
| 12213 | if (hdr_len & 0x10) |
| 12214 | base_flags |= 0x00000010; |
| 12215 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12216 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12217 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12218 | else if (tg3_flag(tp, HW_TSO_1) || |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12219 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 12220 | mss |= (TG3_TSO_TCP_OPT_LEN << 9); |
| 12221 | } else { |
| 12222 | base_flags |= (TG3_TSO_TCP_OPT_LEN << 10); |
| 12223 | } |
| 12224 | |
| 12225 | data_off = ETH_ALEN * 2 + sizeof(tg3_tso_header); |
| 12226 | } else { |
| 12227 | num_pkts = 1; |
| 12228 | data_off = ETH_HLEN; |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12229 | |
| 12230 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 12231 | tx_len > VLAN_ETH_FRAME_LEN) |
| 12232 | base_flags |= TXD_FLAG_JMB_PKT; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12233 | } |
| 12234 | |
| 12235 | for (i = data_off; i < tx_len; i++) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12236 | tx_data[i] = (u8) (i & 0xff); |
| 12237 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 12238 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
| 12239 | if (pci_dma_mapping_error(tp->pdev, map)) { |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 12240 | dev_kfree_skb(skb); |
| 12241 | return -EIO; |
| 12242 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12243 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 12244 | val = tnapi->tx_prod; |
| 12245 | tnapi->tx_buffers[val].skb = skb; |
| 12246 | dma_unmap_addr_set(&tnapi->tx_buffers[val], mapping, map); |
| 12247 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12248 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 12249 | rnapi->coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12250 | |
| 12251 | udelay(10); |
| 12252 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 12253 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12254 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 12255 | budget = tg3_tx_avail(tnapi); |
| 12256 | if (tg3_tx_frag_set(tnapi, &val, &budget, map, tx_len, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 12257 | base_flags | TXD_FLAG_END, mss, 0)) { |
| 12258 | tnapi->tx_buffers[val].skb = NULL; |
| 12259 | dev_kfree_skb(skb); |
| 12260 | return -EIO; |
| 12261 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12262 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 12263 | tnapi->tx_prod++; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12264 | |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 12265 | /* Sync BD data before updating mailbox */ |
| 12266 | wmb(); |
| 12267 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 12268 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 12269 | tr32_mailbox(tnapi->prodmbox); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12270 | |
| 12271 | udelay(10); |
| 12272 | |
Matt Carlson | 303fc92 | 2009-11-02 14:27:34 +0000 | [diff] [blame] | 12273 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
| 12274 | for (i = 0; i < 35; i++) { |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12275 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 12276 | coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12277 | |
| 12278 | udelay(10); |
| 12279 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 12280 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 12281 | rx_idx = rnapi->hw_status->idx[0].rx_producer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 12282 | if ((tx_idx == tnapi->tx_prod) && |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12283 | (rx_idx == (rx_start_idx + num_pkts))) |
| 12284 | break; |
| 12285 | } |
| 12286 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 12287 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod - 1, -1); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12288 | dev_kfree_skb(skb); |
| 12289 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 12290 | if (tx_idx != tnapi->tx_prod) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12291 | goto out; |
| 12292 | |
| 12293 | if (rx_idx != rx_start_idx + num_pkts) |
| 12294 | goto out; |
| 12295 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12296 | val = data_off; |
| 12297 | while (rx_idx != rx_start_idx) { |
| 12298 | desc = &rnapi->rx_rcb[rx_start_idx++]; |
| 12299 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 12300 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12301 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12302 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 12303 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12304 | goto out; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12305 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12306 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) |
| 12307 | - ETH_FCS_LEN; |
| 12308 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12309 | if (!tso_loopback) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12310 | if (rx_len != tx_len) |
| 12311 | goto out; |
| 12312 | |
| 12313 | if (pktsz <= TG3_RX_STD_DMA_SZ - ETH_FCS_LEN) { |
| 12314 | if (opaque_key != RXD_OPAQUE_RING_STD) |
| 12315 | goto out; |
| 12316 | } else { |
| 12317 | if (opaque_key != RXD_OPAQUE_RING_JUMBO) |
| 12318 | goto out; |
| 12319 | } |
| 12320 | } else if ((desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 12321 | (desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
Matt Carlson | 54e0a67 | 2011-05-19 12:12:50 +0000 | [diff] [blame] | 12322 | >> RXD_TCPCSUM_SHIFT != 0xffff) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12323 | goto out; |
| 12324 | } |
| 12325 | |
| 12326 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12327 | rx_data = tpr->rx_std_buffers[desc_idx].data; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12328 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], |
| 12329 | mapping); |
| 12330 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12331 | rx_data = tpr->rx_jmb_buffers[desc_idx].data; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12332 | map = dma_unmap_addr(&tpr->rx_jmb_buffers[desc_idx], |
| 12333 | mapping); |
| 12334 | } else |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12335 | goto out; |
| 12336 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12337 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, |
| 12338 | PCI_DMA_FROMDEVICE); |
| 12339 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12340 | rx_data += TG3_RX_OFFSET(tp); |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12341 | for (i = data_off; i < rx_len; i++, val++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12342 | if (*(rx_data + i) != (u8) (val & 0xff)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12343 | goto out; |
| 12344 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12345 | } |
| 12346 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12347 | err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12348 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12349 | /* tg3_free_rings will unmap and free the rx_data */ |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12350 | out: |
| 12351 | return err; |
| 12352 | } |
| 12353 | |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 12354 | #define TG3_STD_LOOPBACK_FAILED 1 |
| 12355 | #define TG3_JMB_LOOPBACK_FAILED 2 |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12356 | #define TG3_TSO_LOOPBACK_FAILED 4 |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12357 | #define TG3_LOOPBACK_FAILED \ |
| 12358 | (TG3_STD_LOOPBACK_FAILED | \ |
| 12359 | TG3_JMB_LOOPBACK_FAILED | \ |
| 12360 | TG3_TSO_LOOPBACK_FAILED) |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 12361 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12362 | 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] | 12363 | { |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12364 | int err = -EIO; |
Matt Carlson | 2215e24 | 2011-08-19 13:58:19 +0000 | [diff] [blame] | 12365 | u32 eee_cap; |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12366 | u32 jmb_pkt_sz = 9000; |
| 12367 | |
| 12368 | if (tp->dma_limit) |
| 12369 | jmb_pkt_sz = tp->dma_limit - ETH_HLEN; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12370 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 12371 | eee_cap = tp->phy_flags & TG3_PHYFLG_EEE_CAP; |
| 12372 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; |
| 12373 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12374 | if (!netif_running(tp->dev)) { |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12375 | data[TG3_MAC_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 12376 | data[TG3_PHY_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12377 | if (do_extlpbk) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12378 | data[TG3_EXT_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12379 | goto done; |
| 12380 | } |
| 12381 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 12382 | err = tg3_reset_hw(tp, 1); |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 12383 | if (err) { |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12384 | data[TG3_MAC_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 12385 | data[TG3_PHY_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12386 | if (do_extlpbk) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12387 | data[TG3_EXT_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 12388 | goto done; |
| 12389 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12390 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12391 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 4a85f09 | 2011-04-20 07:57:37 +0000 | [diff] [blame] | 12392 | int i; |
| 12393 | |
| 12394 | /* Reroute all rx packets to the 1st queue */ |
| 12395 | for (i = MAC_RSS_INDIR_TBL_0; |
| 12396 | i < MAC_RSS_INDIR_TBL_0 + TG3_RSS_INDIR_TBL_SIZE; i += 4) |
| 12397 | tw32(i, 0x0); |
| 12398 | } |
| 12399 | |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 12400 | /* HW errata - mac loopback fails in some cases on 5780. |
| 12401 | * Normal traffic and PHY loopback are not affected by |
| 12402 | * errata. Also, the MAC loopback test is deprecated for |
| 12403 | * all newer ASIC revisions. |
| 12404 | */ |
| 12405 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && |
| 12406 | !tg3_flag(tp, CPMU_PRESENT)) { |
| 12407 | tg3_mac_loopback(tp, true); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 12408 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12409 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12410 | data[TG3_MAC_LOOPB_TEST] |= TG3_STD_LOOPBACK_FAILED; |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 12411 | |
| 12412 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12413 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12414 | data[TG3_MAC_LOOPB_TEST] |= TG3_JMB_LOOPBACK_FAILED; |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 12415 | |
| 12416 | tg3_mac_loopback(tp, false); |
| 12417 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12418 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12419 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12420 | !tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12421 | int i; |
| 12422 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12423 | tg3_phy_lpbk_set(tp, 0, false); |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12424 | |
| 12425 | /* Wait for link */ |
| 12426 | for (i = 0; i < 100; i++) { |
| 12427 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 12428 | break; |
| 12429 | mdelay(1); |
| 12430 | } |
| 12431 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12432 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12433 | data[TG3_PHY_LOOPB_TEST] |= TG3_STD_LOOPBACK_FAILED; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12434 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12435 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12436 | data[TG3_PHY_LOOPB_TEST] |= TG3_TSO_LOOPBACK_FAILED; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12437 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12438 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12439 | data[TG3_PHY_LOOPB_TEST] |= TG3_JMB_LOOPBACK_FAILED; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12440 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12441 | if (do_extlpbk) { |
| 12442 | tg3_phy_lpbk_set(tp, 0, true); |
| 12443 | |
| 12444 | /* All link indications report up, but the hardware |
| 12445 | * isn't really ready for about 20 msec. Double it |
| 12446 | * to be sure. |
| 12447 | */ |
| 12448 | mdelay(40); |
| 12449 | |
| 12450 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12451 | data[TG3_EXT_LOOPB_TEST] |= |
| 12452 | TG3_STD_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12453 | if (tg3_flag(tp, TSO_CAPABLE) && |
| 12454 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12455 | data[TG3_EXT_LOOPB_TEST] |= |
| 12456 | TG3_TSO_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12457 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12458 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12459 | data[TG3_EXT_LOOPB_TEST] |= |
| 12460 | TG3_JMB_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12461 | } |
| 12462 | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12463 | /* Re-enable gphy autopowerdown. */ |
| 12464 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
| 12465 | tg3_phy_toggle_apd(tp, true); |
| 12466 | } |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12467 | |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12468 | err = (data[TG3_MAC_LOOPB_TEST] | data[TG3_PHY_LOOPB_TEST] | |
| 12469 | data[TG3_EXT_LOOPB_TEST]) ? -EIO : 0; |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12470 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 12471 | done: |
| 12472 | tp->phy_flags |= eee_cap; |
| 12473 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12474 | return err; |
| 12475 | } |
| 12476 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12477 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
| 12478 | u64 *data) |
| 12479 | { |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12480 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12481 | bool doextlpbk = etest->flags & ETH_TEST_FL_EXTERNAL_LB; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12482 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 12483 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
| 12484 | tg3_power_up(tp)) { |
| 12485 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12486 | memset(data, 1, sizeof(u64) * TG3_NUM_TEST); |
| 12487 | return; |
| 12488 | } |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12489 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12490 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
| 12491 | |
| 12492 | if (tg3_test_nvram(tp) != 0) { |
| 12493 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12494 | data[TG3_NVRAM_TEST] = 1; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12495 | } |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12496 | if (!doextlpbk && tg3_test_link(tp)) { |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12497 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12498 | data[TG3_LINK_TEST] = 1; |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12499 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12500 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12501 | int err, err2 = 0, irq_sync = 0; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12502 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12503 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12504 | tg3_phy_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12505 | tg3_netif_stop(tp); |
| 12506 | irq_sync = 1; |
| 12507 | } |
| 12508 | |
| 12509 | tg3_full_lock(tp, irq_sync); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12510 | |
| 12511 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12512 | err = tg3_nvram_lock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12513 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12514 | if (!tg3_flag(tp, 5705_PLUS)) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12515 | tg3_halt_cpu(tp, TX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12516 | if (!err) |
| 12517 | tg3_nvram_unlock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12518 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12519 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 12520 | tg3_phy_reset(tp); |
| 12521 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12522 | if (tg3_test_registers(tp) != 0) { |
| 12523 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12524 | data[TG3_REGISTER_TEST] = 1; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12525 | } |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12526 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12527 | if (tg3_test_memory(tp) != 0) { |
| 12528 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12529 | data[TG3_MEMORY_TEST] = 1; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12530 | } |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12531 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12532 | if (doextlpbk) |
| 12533 | etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; |
| 12534 | |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12535 | if (tg3_test_loopback(tp, data, doextlpbk)) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12536 | etest->flags |= ETH_TEST_FL_FAILED; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12537 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12538 | tg3_full_unlock(tp); |
| 12539 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12540 | if (tg3_test_interrupt(tp) != 0) { |
| 12541 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12542 | data[TG3_INTERRUPT_TEST] = 1; |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12543 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12544 | |
| 12545 | tg3_full_lock(tp, 0); |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12546 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12547 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 12548 | if (netif_running(dev)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12549 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12550 | err2 = tg3_restart_hw(tp, 1); |
| 12551 | if (!err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 12552 | tg3_netif_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12553 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12554 | |
| 12555 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12556 | |
| 12557 | if (irq_sync && !err2) |
| 12558 | tg3_phy_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12559 | } |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 12560 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 12561 | tg3_power_down(tp); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12562 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12563 | } |
| 12564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12565 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 12566 | { |
| 12567 | struct mii_ioctl_data *data = if_mii(ifr); |
| 12568 | struct tg3 *tp = netdev_priv(dev); |
| 12569 | int err; |
| 12570 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12571 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 12572 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12573 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12574 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 12575 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 12576 | return phy_mii_ioctl(phydev, ifr, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12577 | } |
| 12578 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 12579 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12580 | case SIOCGMIIPHY: |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 12581 | data->phy_id = tp->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12582 | |
| 12583 | /* fallthru */ |
| 12584 | case SIOCGMIIREG: { |
| 12585 | u32 mii_regval; |
| 12586 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12587 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12588 | break; /* We have no PHY */ |
| 12589 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 12590 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12591 | return -EAGAIN; |
| 12592 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12593 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12594 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12595 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12596 | |
| 12597 | data->val_out = mii_regval; |
| 12598 | |
| 12599 | return err; |
| 12600 | } |
| 12601 | |
| 12602 | case SIOCSMIIREG: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12603 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12604 | break; /* We have no PHY */ |
| 12605 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 12606 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12607 | return -EAGAIN; |
| 12608 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12609 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12610 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12611 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12612 | |
| 12613 | return err; |
| 12614 | |
| 12615 | default: |
| 12616 | /* do nothing */ |
| 12617 | break; |
| 12618 | } |
| 12619 | return -EOPNOTSUPP; |
| 12620 | } |
| 12621 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 12622 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 12623 | { |
| 12624 | struct tg3 *tp = netdev_priv(dev); |
| 12625 | |
| 12626 | memcpy(ec, &tp->coal, sizeof(*ec)); |
| 12627 | return 0; |
| 12628 | } |
| 12629 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 12630 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 12631 | { |
| 12632 | struct tg3 *tp = netdev_priv(dev); |
| 12633 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; |
| 12634 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; |
| 12635 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12636 | if (!tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 12637 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
| 12638 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; |
| 12639 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; |
| 12640 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; |
| 12641 | } |
| 12642 | |
| 12643 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || |
| 12644 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || |
| 12645 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || |
| 12646 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || |
| 12647 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || |
| 12648 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || |
| 12649 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || |
| 12650 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || |
| 12651 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || |
| 12652 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) |
| 12653 | return -EINVAL; |
| 12654 | |
| 12655 | /* No rx interrupts will be generated if both are zero */ |
| 12656 | if ((ec->rx_coalesce_usecs == 0) && |
| 12657 | (ec->rx_max_coalesced_frames == 0)) |
| 12658 | return -EINVAL; |
| 12659 | |
| 12660 | /* No tx interrupts will be generated if both are zero */ |
| 12661 | if ((ec->tx_coalesce_usecs == 0) && |
| 12662 | (ec->tx_max_coalesced_frames == 0)) |
| 12663 | return -EINVAL; |
| 12664 | |
| 12665 | /* Only copy relevant parameters, ignore all others. */ |
| 12666 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; |
| 12667 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; |
| 12668 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; |
| 12669 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; |
| 12670 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; |
| 12671 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; |
| 12672 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; |
| 12673 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; |
| 12674 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; |
| 12675 | |
| 12676 | if (netif_running(dev)) { |
| 12677 | tg3_full_lock(tp, 0); |
| 12678 | __tg3_set_coalesce(tp, &tp->coal); |
| 12679 | tg3_full_unlock(tp); |
| 12680 | } |
| 12681 | return 0; |
| 12682 | } |
| 12683 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 12684 | static const struct ethtool_ops tg3_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12685 | .get_settings = tg3_get_settings, |
| 12686 | .set_settings = tg3_set_settings, |
| 12687 | .get_drvinfo = tg3_get_drvinfo, |
| 12688 | .get_regs_len = tg3_get_regs_len, |
| 12689 | .get_regs = tg3_get_regs, |
| 12690 | .get_wol = tg3_get_wol, |
| 12691 | .set_wol = tg3_set_wol, |
| 12692 | .get_msglevel = tg3_get_msglevel, |
| 12693 | .set_msglevel = tg3_set_msglevel, |
| 12694 | .nway_reset = tg3_nway_reset, |
| 12695 | .get_link = ethtool_op_get_link, |
| 12696 | .get_eeprom_len = tg3_get_eeprom_len, |
| 12697 | .get_eeprom = tg3_get_eeprom, |
| 12698 | .set_eeprom = tg3_set_eeprom, |
| 12699 | .get_ringparam = tg3_get_ringparam, |
| 12700 | .set_ringparam = tg3_set_ringparam, |
| 12701 | .get_pauseparam = tg3_get_pauseparam, |
| 12702 | .set_pauseparam = tg3_set_pauseparam, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12703 | .self_test = tg3_self_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12704 | .get_strings = tg3_get_strings, |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 12705 | .set_phys_id = tg3_set_phys_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12706 | .get_ethtool_stats = tg3_get_ethtool_stats, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 12707 | .get_coalesce = tg3_get_coalesce, |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 12708 | .set_coalesce = tg3_set_coalesce, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 12709 | .get_sset_count = tg3_get_sset_count, |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 12710 | .get_rxnfc = tg3_get_rxnfc, |
| 12711 | .get_rxfh_indir_size = tg3_get_rxfh_indir_size, |
| 12712 | .get_rxfh_indir = tg3_get_rxfh_indir, |
| 12713 | .set_rxfh_indir = tg3_set_rxfh_indir, |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 12714 | .get_channels = tg3_get_channels, |
| 12715 | .set_channels = tg3_set_channels, |
Richard Cochran | 3f84749 | 2012-04-03 22:59:39 +0000 | [diff] [blame] | 12716 | .get_ts_info = ethtool_op_get_ts_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12717 | }; |
| 12718 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 12719 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
| 12720 | struct rtnl_link_stats64 *stats) |
| 12721 | { |
| 12722 | struct tg3 *tp = netdev_priv(dev); |
| 12723 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 12724 | spin_lock_bh(&tp->lock); |
Michael Chan | 0f566b2 | 2012-07-29 19:15:44 +0000 | [diff] [blame] | 12725 | if (!tp->hw_stats) { |
| 12726 | spin_unlock_bh(&tp->lock); |
| 12727 | return &tp->net_stats_prev; |
| 12728 | } |
| 12729 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 12730 | tg3_get_nstats(tp, stats); |
| 12731 | spin_unlock_bh(&tp->lock); |
| 12732 | |
| 12733 | return stats; |
| 12734 | } |
| 12735 | |
Matt Carlson | ccd5ba9 | 2012-02-13 10:20:08 +0000 | [diff] [blame] | 12736 | static void tg3_set_rx_mode(struct net_device *dev) |
| 12737 | { |
| 12738 | struct tg3 *tp = netdev_priv(dev); |
| 12739 | |
| 12740 | if (!netif_running(dev)) |
| 12741 | return; |
| 12742 | |
| 12743 | tg3_full_lock(tp, 0); |
| 12744 | __tg3_set_rx_mode(dev); |
| 12745 | tg3_full_unlock(tp); |
| 12746 | } |
| 12747 | |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 12748 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
| 12749 | int new_mtu) |
| 12750 | { |
| 12751 | dev->mtu = new_mtu; |
| 12752 | |
| 12753 | if (new_mtu > ETH_DATA_LEN) { |
| 12754 | if (tg3_flag(tp, 5780_CLASS)) { |
| 12755 | netdev_update_features(dev); |
| 12756 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 12757 | } else { |
| 12758 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
| 12759 | } |
| 12760 | } else { |
| 12761 | if (tg3_flag(tp, 5780_CLASS)) { |
| 12762 | tg3_flag_set(tp, TSO_CAPABLE); |
| 12763 | netdev_update_features(dev); |
| 12764 | } |
| 12765 | tg3_flag_clear(tp, JUMBO_RING_ENABLE); |
| 12766 | } |
| 12767 | } |
| 12768 | |
| 12769 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) |
| 12770 | { |
| 12771 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 2fae5e3 | 2012-03-04 14:48:15 +0000 | [diff] [blame] | 12772 | int err, reset_phy = 0; |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 12773 | |
| 12774 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) |
| 12775 | return -EINVAL; |
| 12776 | |
| 12777 | if (!netif_running(dev)) { |
| 12778 | /* We'll just catch it later when the |
| 12779 | * device is up'd. |
| 12780 | */ |
| 12781 | tg3_set_mtu(dev, tp, new_mtu); |
| 12782 | return 0; |
| 12783 | } |
| 12784 | |
| 12785 | tg3_phy_stop(tp); |
| 12786 | |
| 12787 | tg3_netif_stop(tp); |
| 12788 | |
| 12789 | tg3_full_lock(tp, 1); |
| 12790 | |
| 12791 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 12792 | |
| 12793 | tg3_set_mtu(dev, tp, new_mtu); |
| 12794 | |
Michael Chan | 2fae5e3 | 2012-03-04 14:48:15 +0000 | [diff] [blame] | 12795 | /* Reset PHY, otherwise the read DMA engine will be in a mode that |
| 12796 | * breaks all requests to 256 bytes. |
| 12797 | */ |
| 12798 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) |
| 12799 | reset_phy = 1; |
| 12800 | |
| 12801 | err = tg3_restart_hw(tp, reset_phy); |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 12802 | |
| 12803 | if (!err) |
| 12804 | tg3_netif_start(tp); |
| 12805 | |
| 12806 | tg3_full_unlock(tp); |
| 12807 | |
| 12808 | if (!err) |
| 12809 | tg3_phy_start(tp); |
| 12810 | |
| 12811 | return err; |
| 12812 | } |
| 12813 | |
| 12814 | static const struct net_device_ops tg3_netdev_ops = { |
| 12815 | .ndo_open = tg3_open, |
| 12816 | .ndo_stop = tg3_close, |
| 12817 | .ndo_start_xmit = tg3_start_xmit, |
| 12818 | .ndo_get_stats64 = tg3_get_stats64, |
| 12819 | .ndo_validate_addr = eth_validate_addr, |
| 12820 | .ndo_set_rx_mode = tg3_set_rx_mode, |
| 12821 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 12822 | .ndo_do_ioctl = tg3_ioctl, |
| 12823 | .ndo_tx_timeout = tg3_tx_timeout, |
| 12824 | .ndo_change_mtu = tg3_change_mtu, |
| 12825 | .ndo_fix_features = tg3_fix_features, |
| 12826 | .ndo_set_features = tg3_set_features, |
| 12827 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 12828 | .ndo_poll_controller = tg3_poll_controller, |
| 12829 | #endif |
| 12830 | }; |
| 12831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12832 | static void __devinit tg3_get_eeprom_size(struct tg3 *tp) |
| 12833 | { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12834 | u32 cursize, val, magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12835 | |
| 12836 | tp->nvram_size = EEPROM_CHIP_SIZE; |
| 12837 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12838 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12839 | return; |
| 12840 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12841 | if ((magic != TG3_EEPROM_MAGIC) && |
| 12842 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && |
| 12843 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12844 | return; |
| 12845 | |
| 12846 | /* |
| 12847 | * Size the chip by reading offsets at increasing powers of two. |
| 12848 | * When we encounter our validation signature, we know the addressing |
| 12849 | * has wrapped around, and thus have our chip size. |
| 12850 | */ |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12851 | cursize = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12852 | |
| 12853 | while (cursize < tp->nvram_size) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12854 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12855 | return; |
| 12856 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12857 | if (val == magic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12858 | break; |
| 12859 | |
| 12860 | cursize <<= 1; |
| 12861 | } |
| 12862 | |
| 12863 | tp->nvram_size = cursize; |
| 12864 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12866 | static void __devinit tg3_get_nvram_size(struct tg3 *tp) |
| 12867 | { |
| 12868 | u32 val; |
| 12869 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12870 | 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] | 12871 | return; |
| 12872 | |
| 12873 | /* Selfboot format */ |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12874 | if (val != TG3_EEPROM_MAGIC) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12875 | tg3_get_eeprom_size(tp); |
| 12876 | return; |
| 12877 | } |
| 12878 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12879 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12880 | if (val != 0) { |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12881 | /* This is confusing. We want to operate on the |
| 12882 | * 16-bit value at offset 0xf2. The tg3_nvram_read() |
| 12883 | * call will read from NVRAM and byteswap the data |
| 12884 | * according to the byteswapping settings for all |
| 12885 | * other register accesses. This ensures the data we |
| 12886 | * want will always reside in the lower 16-bits. |
| 12887 | * However, the data in NVRAM is in LE format, which |
| 12888 | * means the data from the NVRAM read will always be |
| 12889 | * opposite the endianness of the CPU. The 16-bit |
| 12890 | * byteswap then brings the data to CPU endianness. |
| 12891 | */ |
| 12892 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12893 | return; |
| 12894 | } |
| 12895 | } |
Matt Carlson | fd1122a | 2008-05-02 16:48:36 -0700 | [diff] [blame] | 12896 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12897 | } |
| 12898 | |
| 12899 | static void __devinit tg3_get_nvram_info(struct tg3 *tp) |
| 12900 | { |
| 12901 | u32 nvcfg1; |
| 12902 | |
| 12903 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12904 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12905 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12906 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12907 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 12908 | tw32(NVRAM_CFG1, nvcfg1); |
| 12909 | } |
| 12910 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 12911 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12912 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12913 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12914 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
| 12915 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12916 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12917 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12918 | break; |
| 12919 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: |
| 12920 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12921 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; |
| 12922 | break; |
| 12923 | case FLASH_VENDOR_ATMEL_EEPROM: |
| 12924 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12925 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12926 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12927 | break; |
| 12928 | case FLASH_VENDOR_ST: |
| 12929 | tp->nvram_jedecnum = JEDEC_ST; |
| 12930 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12931 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12932 | break; |
| 12933 | case FLASH_VENDOR_SAIFUN: |
| 12934 | tp->nvram_jedecnum = JEDEC_SAIFUN; |
| 12935 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; |
| 12936 | break; |
| 12937 | case FLASH_VENDOR_SST_SMALL: |
| 12938 | case FLASH_VENDOR_SST_LARGE: |
| 12939 | tp->nvram_jedecnum = JEDEC_SST; |
| 12940 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; |
| 12941 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12942 | } |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12943 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12944 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 12945 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12946 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12947 | } |
| 12948 | } |
| 12949 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 12950 | static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
| 12951 | { |
| 12952 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { |
| 12953 | case FLASH_5752PAGE_SIZE_256: |
| 12954 | tp->nvram_pagesize = 256; |
| 12955 | break; |
| 12956 | case FLASH_5752PAGE_SIZE_512: |
| 12957 | tp->nvram_pagesize = 512; |
| 12958 | break; |
| 12959 | case FLASH_5752PAGE_SIZE_1K: |
| 12960 | tp->nvram_pagesize = 1024; |
| 12961 | break; |
| 12962 | case FLASH_5752PAGE_SIZE_2K: |
| 12963 | tp->nvram_pagesize = 2048; |
| 12964 | break; |
| 12965 | case FLASH_5752PAGE_SIZE_4K: |
| 12966 | tp->nvram_pagesize = 4096; |
| 12967 | break; |
| 12968 | case FLASH_5752PAGE_SIZE_264: |
| 12969 | tp->nvram_pagesize = 264; |
| 12970 | break; |
| 12971 | case FLASH_5752PAGE_SIZE_528: |
| 12972 | tp->nvram_pagesize = 528; |
| 12973 | break; |
| 12974 | } |
| 12975 | } |
| 12976 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12977 | static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp) |
| 12978 | { |
| 12979 | u32 nvcfg1; |
| 12980 | |
| 12981 | nvcfg1 = tr32(NVRAM_CFG1); |
| 12982 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12983 | /* NVRAM protection for TPM */ |
| 12984 | if (nvcfg1 & (1 << 27)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12985 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12986 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 12987 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12988 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
| 12989 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: |
| 12990 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12991 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12992 | break; |
| 12993 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 12994 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12995 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 12996 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 12997 | break; |
| 12998 | case FLASH_5752VENDOR_ST_M45PE10: |
| 12999 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13000 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13001 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13002 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13003 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13004 | break; |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13005 | } |
| 13006 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13007 | if (tg3_flag(tp, FLASH)) { |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13008 | tg3_nvram_get_pagesize(tp, nvcfg1); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13009 | } else { |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13010 | /* For eeprom, set pagesize to maximum eeprom size */ |
| 13011 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 13012 | |
| 13013 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13014 | tw32(NVRAM_CFG1, nvcfg1); |
| 13015 | } |
| 13016 | } |
| 13017 | |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13018 | static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp) |
| 13019 | { |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13020 | u32 nvcfg1, protect = 0; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13021 | |
| 13022 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13023 | |
| 13024 | /* NVRAM protection for TPM */ |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13025 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13026 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13027 | protect = 1; |
| 13028 | } |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13029 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13030 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 13031 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13032 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 13033 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 13034 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 13035 | case FLASH_5755VENDOR_ATMEL_FLASH_5: |
| 13036 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13037 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13038 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13039 | tp->nvram_pagesize = 264; |
| 13040 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || |
| 13041 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) |
| 13042 | tp->nvram_size = (protect ? 0x3e200 : |
| 13043 | TG3_NVRAM_SIZE_512KB); |
| 13044 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) |
| 13045 | tp->nvram_size = (protect ? 0x1f200 : |
| 13046 | TG3_NVRAM_SIZE_256KB); |
| 13047 | else |
| 13048 | tp->nvram_size = (protect ? 0x1f200 : |
| 13049 | TG3_NVRAM_SIZE_128KB); |
| 13050 | break; |
| 13051 | case FLASH_5752VENDOR_ST_M45PE10: |
| 13052 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13053 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13054 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13055 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13056 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13057 | tp->nvram_pagesize = 256; |
| 13058 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) |
| 13059 | tp->nvram_size = (protect ? |
| 13060 | TG3_NVRAM_SIZE_64KB : |
| 13061 | TG3_NVRAM_SIZE_128KB); |
| 13062 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) |
| 13063 | tp->nvram_size = (protect ? |
| 13064 | TG3_NVRAM_SIZE_64KB : |
| 13065 | TG3_NVRAM_SIZE_256KB); |
| 13066 | else |
| 13067 | tp->nvram_size = (protect ? |
| 13068 | TG3_NVRAM_SIZE_128KB : |
| 13069 | TG3_NVRAM_SIZE_512KB); |
| 13070 | break; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13071 | } |
| 13072 | } |
| 13073 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13074 | static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) |
| 13075 | { |
| 13076 | u32 nvcfg1; |
| 13077 | |
| 13078 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13079 | |
| 13080 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13081 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
| 13082 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 13083 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: |
| 13084 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 13085 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13086 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13087 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13088 | |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13089 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13090 | tw32(NVRAM_CFG1, nvcfg1); |
| 13091 | break; |
| 13092 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 13093 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 13094 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 13095 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 13096 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13097 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13098 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13099 | tp->nvram_pagesize = 264; |
| 13100 | break; |
| 13101 | case FLASH_5752VENDOR_ST_M45PE10: |
| 13102 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13103 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13104 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13105 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13106 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13107 | tp->nvram_pagesize = 256; |
| 13108 | break; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13109 | } |
| 13110 | } |
| 13111 | |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13112 | static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp) |
| 13113 | { |
| 13114 | u32 nvcfg1, protect = 0; |
| 13115 | |
| 13116 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13117 | |
| 13118 | /* NVRAM protection for TPM */ |
| 13119 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13120 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13121 | protect = 1; |
| 13122 | } |
| 13123 | |
| 13124 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 13125 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13126 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 13127 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 13128 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 13129 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 13130 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 13131 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 13132 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 13133 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 13134 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13135 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13136 | tg3_flag_set(tp, FLASH); |
| 13137 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13138 | tp->nvram_pagesize = 256; |
| 13139 | break; |
| 13140 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 13141 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 13142 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 13143 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 13144 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 13145 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 13146 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 13147 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 13148 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13149 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13150 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13151 | tp->nvram_pagesize = 256; |
| 13152 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13153 | } |
| 13154 | |
| 13155 | if (protect) { |
| 13156 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); |
| 13157 | } else { |
| 13158 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13159 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 13160 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 13161 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 13162 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 13163 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; |
| 13164 | break; |
| 13165 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 13166 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 13167 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 13168 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 13169 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 13170 | break; |
| 13171 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 13172 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 13173 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 13174 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 13175 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13176 | break; |
| 13177 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 13178 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 13179 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 13180 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 13181 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13182 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13183 | } |
| 13184 | } |
| 13185 | } |
| 13186 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13187 | static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp) |
| 13188 | { |
| 13189 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13190 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13191 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 13192 | } |
| 13193 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13194 | static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp) |
| 13195 | { |
| 13196 | u32 nvcfg1; |
| 13197 | |
| 13198 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13199 | |
| 13200 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13201 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 13202 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 13203 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13204 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13205 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 13206 | |
| 13207 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13208 | tw32(NVRAM_CFG1, nvcfg1); |
| 13209 | return; |
| 13210 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 13211 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 13212 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 13213 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 13214 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 13215 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 13216 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 13217 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13218 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13219 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13220 | |
| 13221 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13222 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 13223 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 13224 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 13225 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13226 | break; |
| 13227 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 13228 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 13229 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13230 | break; |
| 13231 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 13232 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 13233 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13234 | break; |
| 13235 | } |
| 13236 | break; |
| 13237 | case FLASH_5752VENDOR_ST_M45PE10: |
| 13238 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13239 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13240 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13241 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13242 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13243 | |
| 13244 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13245 | case FLASH_5752VENDOR_ST_M45PE10: |
| 13246 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13247 | break; |
| 13248 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13249 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13250 | break; |
| 13251 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13252 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13253 | break; |
| 13254 | } |
| 13255 | break; |
| 13256 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13257 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13258 | return; |
| 13259 | } |
| 13260 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13261 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 13262 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13263 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13264 | } |
| 13265 | |
| 13266 | |
| 13267 | static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp) |
| 13268 | { |
| 13269 | u32 nvcfg1; |
| 13270 | |
| 13271 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13272 | |
| 13273 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13274 | case FLASH_5717VENDOR_ATMEL_EEPROM: |
| 13275 | case FLASH_5717VENDOR_MICRO_EEPROM: |
| 13276 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13277 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13278 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 13279 | |
| 13280 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13281 | tw32(NVRAM_CFG1, nvcfg1); |
| 13282 | return; |
| 13283 | case FLASH_5717VENDOR_ATMEL_MDB011D: |
| 13284 | case FLASH_5717VENDOR_ATMEL_ADB011B: |
| 13285 | case FLASH_5717VENDOR_ATMEL_ADB011D: |
| 13286 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 13287 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 13288 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 13289 | case FLASH_5717VENDOR_ATMEL_45USPT: |
| 13290 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13291 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13292 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13293 | |
| 13294 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13295 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 13296 | /* Detect size with tg3_nvram_get_size() */ |
| 13297 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13298 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 13299 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 13300 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13301 | break; |
| 13302 | default: |
| 13303 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13304 | break; |
| 13305 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13306 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13307 | case FLASH_5717VENDOR_ST_M_M25PE10: |
| 13308 | case FLASH_5717VENDOR_ST_A_M25PE10: |
| 13309 | case FLASH_5717VENDOR_ST_M_M45PE10: |
| 13310 | case FLASH_5717VENDOR_ST_A_M45PE10: |
| 13311 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 13312 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 13313 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 13314 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 13315 | case FLASH_5717VENDOR_ST_25USPT: |
| 13316 | case FLASH_5717VENDOR_ST_45USPT: |
| 13317 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13318 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13319 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13320 | |
| 13321 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13322 | case FLASH_5717VENDOR_ST_M_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13323 | case FLASH_5717VENDOR_ST_M_M45PE20: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 13324 | /* Detect size with tg3_nvram_get_size() */ |
| 13325 | break; |
| 13326 | case FLASH_5717VENDOR_ST_A_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13327 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 13328 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13329 | break; |
| 13330 | default: |
| 13331 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13332 | break; |
| 13333 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13334 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13335 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13336 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13337 | return; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13338 | } |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13339 | |
| 13340 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 13341 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13342 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13343 | } |
| 13344 | |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13345 | static void __devinit tg3_get_5720_nvram_info(struct tg3 *tp) |
| 13346 | { |
| 13347 | u32 nvcfg1, nvmpinstrp; |
| 13348 | |
| 13349 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13350 | nvmpinstrp = nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK; |
| 13351 | |
| 13352 | switch (nvmpinstrp) { |
| 13353 | case FLASH_5720_EEPROM_HD: |
| 13354 | case FLASH_5720_EEPROM_LD: |
| 13355 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13356 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13357 | |
| 13358 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13359 | tw32(NVRAM_CFG1, nvcfg1); |
| 13360 | if (nvmpinstrp == FLASH_5720_EEPROM_HD) |
| 13361 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 13362 | else |
| 13363 | tp->nvram_pagesize = ATMEL_AT24C02_CHIP_SIZE; |
| 13364 | return; |
| 13365 | case FLASH_5720VENDOR_M_ATMEL_DB011D: |
| 13366 | case FLASH_5720VENDOR_A_ATMEL_DB011B: |
| 13367 | case FLASH_5720VENDOR_A_ATMEL_DB011D: |
| 13368 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 13369 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 13370 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 13371 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 13372 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 13373 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 13374 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 13375 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 13376 | case FLASH_5720VENDOR_ATMEL_45USPT: |
| 13377 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13378 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13379 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13380 | |
| 13381 | switch (nvmpinstrp) { |
| 13382 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 13383 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 13384 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 13385 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13386 | break; |
| 13387 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 13388 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 13389 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 13390 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13391 | break; |
| 13392 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 13393 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 13394 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 13395 | break; |
| 13396 | default: |
| 13397 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13398 | break; |
| 13399 | } |
| 13400 | break; |
| 13401 | case FLASH_5720VENDOR_M_ST_M25PE10: |
| 13402 | case FLASH_5720VENDOR_M_ST_M45PE10: |
| 13403 | case FLASH_5720VENDOR_A_ST_M25PE10: |
| 13404 | case FLASH_5720VENDOR_A_ST_M45PE10: |
| 13405 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 13406 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 13407 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 13408 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 13409 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 13410 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 13411 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 13412 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 13413 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 13414 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 13415 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 13416 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 13417 | case FLASH_5720VENDOR_ST_25USPT: |
| 13418 | case FLASH_5720VENDOR_ST_45USPT: |
| 13419 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13420 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13421 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13422 | |
| 13423 | switch (nvmpinstrp) { |
| 13424 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 13425 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 13426 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 13427 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 13428 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13429 | break; |
| 13430 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 13431 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 13432 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 13433 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 13434 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13435 | break; |
| 13436 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 13437 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 13438 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 13439 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 13440 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 13441 | break; |
| 13442 | default: |
| 13443 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13444 | break; |
| 13445 | } |
| 13446 | break; |
| 13447 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13448 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13449 | return; |
| 13450 | } |
| 13451 | |
| 13452 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 13453 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13454 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13455 | } |
| 13456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13457 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
| 13458 | static void __devinit tg3_nvram_init(struct tg3 *tp) |
| 13459 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13460 | tw32_f(GRC_EEPROM_ADDR, |
| 13461 | (EEPROM_ADDR_FSM_RESET | |
| 13462 | (EEPROM_DEFAULT_CLOCK_PERIOD << |
| 13463 | EEPROM_ADDR_CLKPERD_SHIFT))); |
| 13464 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 13465 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13466 | |
| 13467 | /* Enable seeprom accesses. */ |
| 13468 | tw32_f(GRC_LOCAL_CTRL, |
| 13469 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); |
| 13470 | udelay(100); |
| 13471 | |
| 13472 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13473 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13474 | tg3_flag_set(tp, NVRAM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13475 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 13476 | if (tg3_nvram_lock(tp)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 13477 | netdev_warn(tp->dev, |
| 13478 | "Cannot get nvram lock, %s failed\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 13479 | __func__); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 13480 | return; |
| 13481 | } |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13482 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13483 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13484 | tp->nvram_size = 0; |
| 13485 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13486 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 13487 | tg3_get_5752_nvram_info(tp); |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13488 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 13489 | tg3_get_5755_nvram_info(tp); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13490 | 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] | 13491 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 13492 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13493 | tg3_get_5787_nvram_info(tp); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13494 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 13495 | tg3_get_5761_nvram_info(tp); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13496 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 13497 | tg3_get_5906_nvram_info(tp); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13498 | 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] | 13499 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13500 | tg3_get_57780_nvram_info(tp); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13501 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13502 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13503 | tg3_get_5717_nvram_info(tp); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13504 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 13505 | tg3_get_5720_nvram_info(tp); |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13506 | else |
| 13507 | tg3_get_nvram_info(tp); |
| 13508 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13509 | if (tp->nvram_size == 0) |
| 13510 | tg3_get_nvram_size(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13511 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13512 | tg3_disable_nvram_access(tp); |
Michael Chan | 381291b | 2005-12-13 21:08:21 -0800 | [diff] [blame] | 13513 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13514 | |
| 13515 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13516 | tg3_flag_clear(tp, NVRAM); |
| 13517 | tg3_flag_clear(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13518 | |
| 13519 | tg3_get_eeprom_size(tp); |
| 13520 | } |
| 13521 | } |
| 13522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13523 | struct subsys_tbl_ent { |
| 13524 | u16 subsys_vendor, subsys_devid; |
| 13525 | u32 phy_id; |
| 13526 | }; |
| 13527 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13528 | static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13529 | /* Broadcom boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13530 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13531 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13532 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13533 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13534 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13535 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13536 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 13537 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, |
| 13538 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13539 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13540 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13541 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13542 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 13543 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, |
| 13544 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13545 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13546 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13547 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13548 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13549 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13550 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13551 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13552 | |
| 13553 | /* 3com boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13554 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13555 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13556 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13557 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13558 | { TG3PCI_SUBVENDOR_ID_3COM, |
| 13559 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, |
| 13560 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13561 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13562 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13563 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13564 | |
| 13565 | /* DELL boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13566 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13567 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13568 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13569 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13570 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13571 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13572 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13573 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13574 | |
| 13575 | /* Compaq boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13576 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13577 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13578 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13579 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13580 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 13581 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, |
| 13582 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13583 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13584 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13585 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13586 | |
| 13587 | /* IBM boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13588 | { TG3PCI_SUBVENDOR_ID_IBM, |
| 13589 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13590 | }; |
| 13591 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13592 | 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] | 13593 | { |
| 13594 | int i; |
| 13595 | |
| 13596 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { |
| 13597 | if ((subsys_id_to_phy_id[i].subsys_vendor == |
| 13598 | tp->pdev->subsystem_vendor) && |
| 13599 | (subsys_id_to_phy_id[i].subsys_devid == |
| 13600 | tp->pdev->subsystem_device)) |
| 13601 | return &subsys_id_to_phy_id[i]; |
| 13602 | } |
| 13603 | return NULL; |
| 13604 | } |
| 13605 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13606 | static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13607 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13608 | u32 val; |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 13609 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13610 | tp->phy_id = TG3_PHY_ID_INVALID; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13611 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 13612 | |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 13613 | /* Assume an onboard device and WOL capable by default. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13614 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
| 13615 | tg3_flag_set(tp, WOL_CAP); |
David S. Miller | 72b845e | 2006-03-14 14:11:48 -0800 | [diff] [blame] | 13616 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13617 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13618 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13619 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 13620 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13621 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 13622 | val = tr32(VCPU_CFGSHDW); |
| 13623 | if (val & VCPU_CFGSHDW_ASPM_DBNC) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13624 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 13625 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13626 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13627 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13628 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 13629 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 13630 | goto done; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13631 | } |
| 13632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13633 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 13634 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 13635 | u32 nic_cfg, led_cfg; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13636 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13637 | int eeprom_phy_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13638 | |
| 13639 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 13640 | tp->nic_sram_data_cfg = nic_cfg; |
| 13641 | |
| 13642 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); |
| 13643 | ver >>= NIC_SRAM_DATA_VER_SHIFT; |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 13644 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13645 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 13646 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13647 | (ver > 0) && (ver < 0x100)) |
| 13648 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); |
| 13649 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13650 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 13651 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
| 13652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13653 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
| 13654 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) |
| 13655 | eeprom_phy_serdes = 1; |
| 13656 | |
| 13657 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); |
| 13658 | if (nic_phy_id != 0) { |
| 13659 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; |
| 13660 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; |
| 13661 | |
| 13662 | eeprom_phy_id = (id1 >> 16) << 10; |
| 13663 | eeprom_phy_id |= (id2 & 0xfc00) << 16; |
| 13664 | eeprom_phy_id |= (id2 & 0x03ff) << 0; |
| 13665 | } else |
| 13666 | eeprom_phy_id = 0; |
| 13667 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13668 | tp->phy_id = eeprom_phy_id; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13669 | if (eeprom_phy_serdes) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13670 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13671 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13672 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13673 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13674 | } |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13675 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13676 | if (tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13677 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
| 13678 | SHASTA_EXT_LED_MODE_MASK); |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 13679 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13680 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
| 13681 | |
| 13682 | switch (led_cfg) { |
| 13683 | default: |
| 13684 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: |
| 13685 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 13686 | break; |
| 13687 | |
| 13688 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: |
| 13689 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 13690 | break; |
| 13691 | |
| 13692 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: |
| 13693 | tp->led_ctrl = LED_CTRL_MODE_MAC; |
Michael Chan | 9ba2779 | 2005-06-06 15:16:20 -0700 | [diff] [blame] | 13694 | |
| 13695 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is |
| 13696 | * read on some older 5700/5701 bootcode. |
| 13697 | */ |
| 13698 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 13699 | ASIC_REV_5700 || |
| 13700 | GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 13701 | ASIC_REV_5701) |
| 13702 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 13703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13704 | break; |
| 13705 | |
| 13706 | case SHASTA_EXT_LED_SHARED: |
| 13707 | tp->led_ctrl = LED_CTRL_MODE_SHARED; |
| 13708 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 13709 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) |
| 13710 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 13711 | LED_CTRL_MODE_PHY_2); |
| 13712 | break; |
| 13713 | |
| 13714 | case SHASTA_EXT_LED_MAC: |
| 13715 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; |
| 13716 | break; |
| 13717 | |
| 13718 | case SHASTA_EXT_LED_COMBO: |
| 13719 | tp->led_ctrl = LED_CTRL_MODE_COMBO; |
| 13720 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) |
| 13721 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 13722 | LED_CTRL_MODE_PHY_2); |
| 13723 | break; |
| 13724 | |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 13725 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13726 | |
| 13727 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 13728 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && |
| 13729 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
| 13730 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 13731 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 13732 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
| 13733 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
Matt Carlson | 5f60891 | 2007-11-12 21:17:07 -0800 | [diff] [blame] | 13734 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13735 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13736 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13737 | if ((tp->pdev->subsystem_vendor == |
| 13738 | PCI_VENDOR_ID_ARIMA) && |
| 13739 | (tp->pdev->subsystem_device == 0x205a || |
| 13740 | tp->pdev->subsystem_device == 0x2063)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13741 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13742 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13743 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 13744 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13745 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13746 | |
| 13747 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13748 | tg3_flag_set(tp, ENABLE_ASF); |
| 13749 | if (tg3_flag(tp, 5750_PLUS)) |
| 13750 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13751 | } |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 13752 | |
| 13753 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13754 | tg3_flag(tp, 5750_PLUS)) |
| 13755 | tg3_flag_set(tp, ENABLE_APE); |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 13756 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13757 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 13758 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13759 | tg3_flag_clear(tp, WOL_CAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13760 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13761 | if (tg3_flag(tp, WOL_CAP) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13762 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13763 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 13764 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 13765 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 13766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13767 | if (cfg2 & (1 << 17)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13768 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13769 | |
| 13770 | /* serdes signal pre-emphasis in register 0x590 set by */ |
| 13771 | /* bootcode if bit 18 is set */ |
| 13772 | if (cfg2 & (1 << 18)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13773 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13774 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13775 | if ((tg3_flag(tp, 57765_PLUS) || |
| 13776 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 13777 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) && |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 13778 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13779 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 13780 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13781 | if (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | 8c69b1e | 2010-08-02 11:26:00 +0000 | [diff] [blame] | 13782 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13783 | !tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13784 | u32 cfg3; |
| 13785 | |
| 13786 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); |
| 13787 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13788 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13789 | } |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13790 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 13791 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13792 | tg3_flag_set(tp, RGMII_INBAND_DISABLE); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13793 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13794 | tg3_flag_set(tp, RGMII_EXT_IBND_RX_EN); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 13795 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13796 | tg3_flag_set(tp, RGMII_EXT_IBND_TX_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13797 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 13798 | done: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13799 | if (tg3_flag(tp, WOL_CAP)) |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 13800 | device_set_wakeup_enable(&tp->pdev->dev, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13801 | tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 13802 | else |
| 13803 | device_set_wakeup_capable(&tp->pdev->dev, false); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13804 | } |
| 13805 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 13806 | static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
| 13807 | { |
| 13808 | int i; |
| 13809 | u32 val; |
| 13810 | |
| 13811 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); |
| 13812 | tw32(OTP_CTRL, cmd); |
| 13813 | |
| 13814 | /* Wait for up to 1 ms for command to execute. */ |
| 13815 | for (i = 0; i < 100; i++) { |
| 13816 | val = tr32(OTP_STATUS); |
| 13817 | if (val & OTP_STATUS_CMD_DONE) |
| 13818 | break; |
| 13819 | udelay(10); |
| 13820 | } |
| 13821 | |
| 13822 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; |
| 13823 | } |
| 13824 | |
| 13825 | /* Read the gphy configuration from the OTP region of the chip. The gphy |
| 13826 | * configuration is a 32-bit value that straddles the alignment boundary. |
| 13827 | * We do two 32-bit reads and then shift and merge the results. |
| 13828 | */ |
| 13829 | static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp) |
| 13830 | { |
| 13831 | u32 bhalf_otp, thalf_otp; |
| 13832 | |
| 13833 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); |
| 13834 | |
| 13835 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) |
| 13836 | return 0; |
| 13837 | |
| 13838 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); |
| 13839 | |
| 13840 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 13841 | return 0; |
| 13842 | |
| 13843 | thalf_otp = tr32(OTP_READ_DATA); |
| 13844 | |
| 13845 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); |
| 13846 | |
| 13847 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 13848 | return 0; |
| 13849 | |
| 13850 | bhalf_otp = tr32(OTP_READ_DATA); |
| 13851 | |
| 13852 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); |
| 13853 | } |
| 13854 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13855 | static void __devinit tg3_phy_init_link_config(struct tg3 *tp) |
| 13856 | { |
Hiroaki SHIMODA | 202ff1c | 2011-11-22 04:05:41 +0000 | [diff] [blame] | 13857 | u32 adv = ADVERTISED_Autoneg; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13858 | |
| 13859 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
| 13860 | adv |= ADVERTISED_1000baseT_Half | |
| 13861 | ADVERTISED_1000baseT_Full; |
| 13862 | |
| 13863 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 13864 | adv |= ADVERTISED_100baseT_Half | |
| 13865 | ADVERTISED_100baseT_Full | |
| 13866 | ADVERTISED_10baseT_Half | |
| 13867 | ADVERTISED_10baseT_Full | |
| 13868 | ADVERTISED_TP; |
| 13869 | else |
| 13870 | adv |= ADVERTISED_FIBRE; |
| 13871 | |
| 13872 | tp->link_config.advertising = adv; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 13873 | tp->link_config.speed = SPEED_UNKNOWN; |
| 13874 | tp->link_config.duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13875 | tp->link_config.autoneg = AUTONEG_ENABLE; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 13876 | tp->link_config.active_speed = SPEED_UNKNOWN; |
| 13877 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 13878 | |
| 13879 | tp->old_link = -1; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13880 | } |
| 13881 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13882 | static int __devinit tg3_phy_probe(struct tg3 *tp) |
| 13883 | { |
| 13884 | u32 hw_phy_id_1, hw_phy_id_2; |
| 13885 | u32 hw_phy_id, hw_phy_id_masked; |
| 13886 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13887 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13888 | /* flow control autonegotiation is default behavior */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13889 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13890 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 13891 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 13892 | if (tg3_flag(tp, ENABLE_APE)) { |
| 13893 | switch (tp->pci_fn) { |
| 13894 | case 0: |
| 13895 | tp->phy_ape_lock = TG3_APE_LOCK_PHY0; |
| 13896 | break; |
| 13897 | case 1: |
| 13898 | tp->phy_ape_lock = TG3_APE_LOCK_PHY1; |
| 13899 | break; |
| 13900 | case 2: |
| 13901 | tp->phy_ape_lock = TG3_APE_LOCK_PHY2; |
| 13902 | break; |
| 13903 | case 3: |
| 13904 | tp->phy_ape_lock = TG3_APE_LOCK_PHY3; |
| 13905 | break; |
| 13906 | } |
| 13907 | } |
| 13908 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13909 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13910 | return tg3_phy_init(tp); |
| 13911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13912 | /* Reading the PHY ID register can conflict with ASF |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 13913 | * firmware access to the PHY hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13914 | */ |
| 13915 | err = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13916 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13917 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13918 | } else { |
| 13919 | /* Now read the physical PHY_ID from the chip and verify |
| 13920 | * that it is sane. If it doesn't look good, we fall back |
| 13921 | * to either the hard-coded table based PHY_ID and failing |
| 13922 | * that the value found in the eeprom area. |
| 13923 | */ |
| 13924 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); |
| 13925 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); |
| 13926 | |
| 13927 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; |
| 13928 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; |
| 13929 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; |
| 13930 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13931 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13932 | } |
| 13933 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13934 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13935 | tp->phy_id = hw_phy_id; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13936 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13937 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Michael Chan | da6b2d0 | 2005-08-19 12:54:29 -0700 | [diff] [blame] | 13938 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13939 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13940 | } else { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13941 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13942 | /* Do nothing, phy ID already set up in |
| 13943 | * tg3_get_eeprom_hw_cfg(). |
| 13944 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13945 | } else { |
| 13946 | struct subsys_tbl_ent *p; |
| 13947 | |
| 13948 | /* No eeprom signature? Try the hardcoded |
| 13949 | * subsys device table. |
| 13950 | */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13951 | p = tg3_lookup_by_subsys(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13952 | if (!p) |
| 13953 | return -ENODEV; |
| 13954 | |
| 13955 | tp->phy_id = p->phy_id; |
| 13956 | if (!tp->phy_id || |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13957 | tp->phy_id == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13958 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13959 | } |
| 13960 | } |
| 13961 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 13962 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Matt Carlson | 5baa5e9 | 2011-07-20 10:20:53 +0000 | [diff] [blame] | 13963 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 13964 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 13965 | (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 13966 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) || |
| 13967 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 13968 | tp->pci_chip_rev_id != CHIPREV_ID_57765_A0))) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 13969 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 13970 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 13971 | tg3_phy_init_link_config(tp); |
| 13972 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13973 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13974 | !tg3_flag(tp, ENABLE_APE) && |
| 13975 | !tg3_flag(tp, ENABLE_ASF)) { |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 13976 | u32 bmsr, dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13977 | |
| 13978 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 13979 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 13980 | (bmsr & BMSR_LSTATUS)) |
| 13981 | goto skip_phy_reset; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13983 | err = tg3_phy_reset(tp); |
| 13984 | if (err) |
| 13985 | return err; |
| 13986 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 13987 | tg3_phy_set_wirespeed(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13988 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 13989 | if (!tg3_phy_copper_an_config_ok(tp, &dummy)) { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 13990 | tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, |
| 13991 | tp->link_config.flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13992 | |
| 13993 | tg3_writephy(tp, MII_BMCR, |
| 13994 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 13995 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13996 | } |
| 13997 | |
| 13998 | skip_phy_reset: |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13999 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14000 | err = tg3_init_5401phy_dsp(tp); |
| 14001 | if (err) |
| 14002 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14004 | err = tg3_init_5401phy_dsp(tp); |
| 14005 | } |
| 14006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14007 | return err; |
| 14008 | } |
| 14009 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 14010 | static void __devinit tg3_read_vpd(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14011 | { |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 14012 | u8 *vpd_data; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 14013 | unsigned int block_end, rosize, len; |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14014 | u32 vpdlen; |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 14015 | int j, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14016 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14017 | vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen); |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 14018 | if (!vpd_data) |
| 14019 | goto out_no_vpd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14020 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14021 | 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] | 14022 | if (i < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14023 | goto out_not_found; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 14024 | |
| 14025 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
| 14026 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; |
| 14027 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 14028 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14029 | if (block_end > vpdlen) |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 14030 | goto out_not_found; |
| 14031 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 14032 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 14033 | PCI_VPD_RO_KEYWORD_MFR_ID); |
| 14034 | if (j > 0) { |
| 14035 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 14036 | |
| 14037 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 14038 | if (j + len > block_end || len != 4 || |
| 14039 | memcmp(&vpd_data[j], "1028", 4)) |
| 14040 | goto partno; |
| 14041 | |
| 14042 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 14043 | PCI_VPD_RO_KEYWORD_VENDOR0); |
| 14044 | if (j < 0) |
| 14045 | goto partno; |
| 14046 | |
| 14047 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 14048 | |
| 14049 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 14050 | if (j + len > block_end) |
| 14051 | goto partno; |
| 14052 | |
| 14053 | memcpy(tp->fw_ver, &vpd_data[j], len); |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14054 | strncat(tp->fw_ver, " bc ", vpdlen - len - 1); |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 14055 | } |
| 14056 | |
| 14057 | partno: |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 14058 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 14059 | PCI_VPD_RO_KEYWORD_PARTNO); |
| 14060 | if (i < 0) |
| 14061 | goto out_not_found; |
| 14062 | |
| 14063 | len = pci_vpd_info_field_size(&vpd_data[i]); |
| 14064 | |
| 14065 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 14066 | if (len > TG3_BPN_SIZE || |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14067 | (len + i) > vpdlen) |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 14068 | goto out_not_found; |
| 14069 | |
| 14070 | memcpy(tp->board_part_number, &vpd_data[i], len); |
| 14071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14072 | out_not_found: |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 14073 | kfree(vpd_data); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14074 | if (tp->board_part_number[0]) |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 14075 | return; |
| 14076 | |
| 14077 | out_no_vpd: |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14078 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 14079 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 14080 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C) |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14081 | strcpy(tp->board_part_number, "BCM5717"); |
| 14082 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) |
| 14083 | strcpy(tp->board_part_number, "BCM5718"); |
| 14084 | else |
| 14085 | goto nomatch; |
| 14086 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 14087 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
| 14088 | strcpy(tp->board_part_number, "BCM57780"); |
| 14089 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) |
| 14090 | strcpy(tp->board_part_number, "BCM57760"); |
| 14091 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) |
| 14092 | strcpy(tp->board_part_number, "BCM57790"); |
| 14093 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) |
| 14094 | strcpy(tp->board_part_number, "BCM57788"); |
| 14095 | else |
| 14096 | goto nomatch; |
| 14097 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
| 14098 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
| 14099 | strcpy(tp->board_part_number, "BCM57761"); |
| 14100 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) |
| 14101 | strcpy(tp->board_part_number, "BCM57765"); |
| 14102 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) |
| 14103 | strcpy(tp->board_part_number, "BCM57781"); |
| 14104 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) |
| 14105 | strcpy(tp->board_part_number, "BCM57785"); |
| 14106 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) |
| 14107 | strcpy(tp->board_part_number, "BCM57791"); |
| 14108 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 14109 | strcpy(tp->board_part_number, "BCM57795"); |
| 14110 | else |
| 14111 | goto nomatch; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 14112 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) { |
| 14113 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762) |
| 14114 | strcpy(tp->board_part_number, "BCM57762"); |
| 14115 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766) |
| 14116 | strcpy(tp->board_part_number, "BCM57766"); |
| 14117 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782) |
| 14118 | strcpy(tp->board_part_number, "BCM57782"); |
| 14119 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 14120 | strcpy(tp->board_part_number, "BCM57786"); |
| 14121 | else |
| 14122 | goto nomatch; |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14123 | } 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] | 14124 | strcpy(tp->board_part_number, "BCM95906"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14125 | } else { |
| 14126 | nomatch: |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14127 | strcpy(tp->board_part_number, "none"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14129 | } |
| 14130 | |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14131 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
| 14132 | { |
| 14133 | u32 val; |
| 14134 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14135 | if (tg3_nvram_read(tp, offset, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14136 | (val & 0xfc000000) != 0x0c000000 || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14137 | tg3_nvram_read(tp, offset + 4, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14138 | val != 0) |
| 14139 | return 0; |
| 14140 | |
| 14141 | return 1; |
| 14142 | } |
| 14143 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14144 | static void __devinit tg3_read_bc_ver(struct tg3 *tp) |
| 14145 | { |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14146 | u32 val, offset, start, ver_offset; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14147 | int i, dst_off; |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14148 | bool newver = false; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14149 | |
| 14150 | if (tg3_nvram_read(tp, 0xc, &offset) || |
| 14151 | tg3_nvram_read(tp, 0x4, &start)) |
| 14152 | return; |
| 14153 | |
| 14154 | offset = tg3_nvram_logical_addr(tp, offset); |
| 14155 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14156 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14157 | return; |
| 14158 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14159 | if ((val & 0xfc000000) == 0x0c000000) { |
| 14160 | if (tg3_nvram_read(tp, offset + 4, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14161 | return; |
| 14162 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14163 | if (val == 0) |
| 14164 | newver = true; |
| 14165 | } |
| 14166 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14167 | dst_off = strlen(tp->fw_ver); |
| 14168 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14169 | if (newver) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14170 | if (TG3_VER_SIZE - dst_off < 16 || |
| 14171 | tg3_nvram_read(tp, offset + 8, &ver_offset)) |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14172 | return; |
| 14173 | |
| 14174 | offset = offset + ver_offset - start; |
| 14175 | for (i = 0; i < 16; i += 4) { |
| 14176 | __be32 v; |
| 14177 | if (tg3_nvram_read_be32(tp, offset + i, &v)) |
| 14178 | return; |
| 14179 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14180 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14181 | } |
| 14182 | } else { |
| 14183 | u32 major, minor; |
| 14184 | |
| 14185 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) |
| 14186 | return; |
| 14187 | |
| 14188 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> |
| 14189 | TG3_NVM_BCVER_MAJSFT; |
| 14190 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14191 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
| 14192 | "v%d.%02d", major, minor); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14193 | } |
| 14194 | } |
| 14195 | |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 14196 | static void __devinit tg3_read_hwsb_ver(struct tg3 *tp) |
| 14197 | { |
| 14198 | u32 val, major, minor; |
| 14199 | |
| 14200 | /* Use native endian representation */ |
| 14201 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) |
| 14202 | return; |
| 14203 | |
| 14204 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> |
| 14205 | TG3_NVM_HWSB_CFG1_MAJSFT; |
| 14206 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> |
| 14207 | TG3_NVM_HWSB_CFG1_MINSFT; |
| 14208 | |
| 14209 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); |
| 14210 | } |
| 14211 | |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 14212 | static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val) |
| 14213 | { |
| 14214 | u32 offset, major, minor, build; |
| 14215 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14216 | 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] | 14217 | |
| 14218 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) |
| 14219 | return; |
| 14220 | |
| 14221 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { |
| 14222 | case TG3_EEPROM_SB_REVISION_0: |
| 14223 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; |
| 14224 | break; |
| 14225 | case TG3_EEPROM_SB_REVISION_2: |
| 14226 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; |
| 14227 | break; |
| 14228 | case TG3_EEPROM_SB_REVISION_3: |
| 14229 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; |
| 14230 | break; |
Matt Carlson | a4153d4 | 2010-02-17 15:16:56 +0000 | [diff] [blame] | 14231 | case TG3_EEPROM_SB_REVISION_4: |
| 14232 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; |
| 14233 | break; |
| 14234 | case TG3_EEPROM_SB_REVISION_5: |
| 14235 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; |
| 14236 | break; |
Matt Carlson | bba226a | 2010-10-14 10:37:38 +0000 | [diff] [blame] | 14237 | case TG3_EEPROM_SB_REVISION_6: |
| 14238 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; |
| 14239 | break; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 14240 | default: |
| 14241 | return; |
| 14242 | } |
| 14243 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14244 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 14245 | return; |
| 14246 | |
| 14247 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> |
| 14248 | TG3_EEPROM_SB_EDH_BLD_SHFT; |
| 14249 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> |
| 14250 | TG3_EEPROM_SB_EDH_MAJ_SHFT; |
| 14251 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; |
| 14252 | |
| 14253 | if (minor > 99 || build > 26) |
| 14254 | return; |
| 14255 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14256 | offset = strlen(tp->fw_ver); |
| 14257 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, |
| 14258 | " v%d.%02d", major, minor); |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 14259 | |
| 14260 | if (build > 0) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14261 | offset = strlen(tp->fw_ver); |
| 14262 | if (offset < TG3_VER_SIZE - 1) |
| 14263 | tp->fw_ver[offset] = 'a' + build - 1; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 14264 | } |
| 14265 | } |
| 14266 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14267 | static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp) |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 14268 | { |
| 14269 | u32 val, offset, start; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14270 | int i, vlen; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14271 | |
| 14272 | for (offset = TG3_NVM_DIR_START; |
| 14273 | offset < TG3_NVM_DIR_END; |
| 14274 | offset += TG3_NVM_DIRENT_SIZE) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14275 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14276 | return; |
| 14277 | |
| 14278 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
| 14279 | break; |
| 14280 | } |
| 14281 | |
| 14282 | if (offset == TG3_NVM_DIR_END) |
| 14283 | return; |
| 14284 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14285 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14286 | start = 0x08000000; |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14287 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14288 | return; |
| 14289 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14290 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14291 | !tg3_fw_img_is_valid(tp, offset) || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14292 | tg3_nvram_read(tp, offset + 8, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14293 | return; |
| 14294 | |
| 14295 | offset += val - start; |
| 14296 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14297 | vlen = strlen(tp->fw_ver); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14298 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14299 | tp->fw_ver[vlen++] = ','; |
| 14300 | tp->fw_ver[vlen++] = ' '; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14301 | |
| 14302 | for (i = 0; i < 4; i++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 14303 | __be32 v; |
| 14304 | if (tg3_nvram_read_be32(tp, offset, &v)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14305 | return; |
| 14306 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 14307 | offset += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14308 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14309 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
| 14310 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14311 | break; |
| 14312 | } |
| 14313 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14314 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
| 14315 | vlen += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14316 | } |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14317 | } |
| 14318 | |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 14319 | static void __devinit tg3_probe_ncsi(struct tg3 *tp) |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14320 | { |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14321 | u32 apedata; |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14322 | |
| 14323 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 14324 | if (apedata != APE_SEG_SIG_MAGIC) |
| 14325 | return; |
| 14326 | |
| 14327 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 14328 | if (!(apedata & APE_FW_STATUS_READY)) |
| 14329 | return; |
| 14330 | |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 14331 | if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) |
| 14332 | tg3_flag_set(tp, APE_HAS_NCSI); |
| 14333 | } |
| 14334 | |
| 14335 | static void __devinit tg3_read_dash_ver(struct tg3 *tp) |
| 14336 | { |
| 14337 | int vlen; |
| 14338 | u32 apedata; |
| 14339 | char *fwtype; |
| 14340 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14341 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
| 14342 | |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 14343 | if (tg3_flag(tp, APE_HAS_NCSI)) |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 14344 | fwtype = "NCSI"; |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 14345 | else |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 14346 | fwtype = "DASH"; |
| 14347 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14348 | vlen = strlen(tp->fw_ver); |
| 14349 | |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 14350 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
| 14351 | fwtype, |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14352 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
| 14353 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, |
| 14354 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, |
| 14355 | (apedata & APE_FW_VERSION_BLDMSK)); |
| 14356 | } |
| 14357 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14358 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
| 14359 | { |
| 14360 | u32 val; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14361 | bool vpd_vers = false; |
| 14362 | |
| 14363 | if (tp->fw_ver[0] != 0) |
| 14364 | vpd_vers = true; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14365 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14366 | if (tg3_flag(tp, NO_NVRAM)) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14367 | strcat(tp->fw_ver, "sb"); |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 14368 | return; |
| 14369 | } |
| 14370 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14371 | if (tg3_nvram_read(tp, 0, &val)) |
| 14372 | return; |
| 14373 | |
| 14374 | if (val == TG3_EEPROM_MAGIC) |
| 14375 | tg3_read_bc_ver(tp); |
| 14376 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) |
| 14377 | tg3_read_sb_ver(tp, val); |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 14378 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 14379 | tg3_read_hwsb_ver(tp); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14380 | |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 14381 | if (tg3_flag(tp, ENABLE_ASF)) { |
| 14382 | if (tg3_flag(tp, ENABLE_APE)) { |
| 14383 | tg3_probe_ncsi(tp); |
| 14384 | if (!vpd_vers) |
| 14385 | tg3_read_dash_ver(tp); |
| 14386 | } else if (!vpd_vers) { |
| 14387 | tg3_read_mgmtfw_ver(tp); |
| 14388 | } |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 14389 | } |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14390 | |
| 14391 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 14392 | } |
| 14393 | |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 14394 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
| 14395 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14396 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 14397 | return TG3_RX_RET_MAX_SIZE_5717; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14398 | else if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 14399 | return TG3_RX_RET_MAX_SIZE_5700; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 14400 | else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 14401 | return TG3_RX_RET_MAX_SIZE_5705; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 14402 | } |
| 14403 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 14404 | static DEFINE_PCI_DEVICE_TABLE(tg3_write_reorder_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 14405 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
| 14406 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
| 14407 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8385_0) }, |
| 14408 | { }, |
| 14409 | }; |
| 14410 | |
Matt Carlson | 16c7fa7 | 2012-02-13 10:20:10 +0000 | [diff] [blame] | 14411 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp) |
| 14412 | { |
| 14413 | struct pci_dev *peer; |
| 14414 | unsigned int func, devnr = tp->pdev->devfn & ~7; |
| 14415 | |
| 14416 | for (func = 0; func < 8; func++) { |
| 14417 | peer = pci_get_slot(tp->pdev->bus, devnr | func); |
| 14418 | if (peer && peer != tp->pdev) |
| 14419 | break; |
| 14420 | pci_dev_put(peer); |
| 14421 | } |
| 14422 | /* 5704 can be configured in single-port mode, set peer to |
| 14423 | * tp->pdev in that case. |
| 14424 | */ |
| 14425 | if (!peer) { |
| 14426 | peer = tp->pdev; |
| 14427 | return peer; |
| 14428 | } |
| 14429 | |
| 14430 | /* |
| 14431 | * We don't need to keep the refcount elevated; there's no way |
| 14432 | * to remove one half of this device without removing the other |
| 14433 | */ |
| 14434 | pci_dev_put(peer); |
| 14435 | |
| 14436 | return peer; |
| 14437 | } |
| 14438 | |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14439 | static void __devinit tg3_detect_asic_rev(struct tg3 *tp, u32 misc_ctrl_reg) |
| 14440 | { |
| 14441 | tp->pci_chip_rev_id = misc_ctrl_reg >> MISC_HOST_CTRL_CHIPREV_SHIFT; |
| 14442 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
| 14443 | u32 reg; |
| 14444 | |
| 14445 | /* All devices that use the alternate |
| 14446 | * ASIC REV location have a CPMU. |
| 14447 | */ |
| 14448 | tg3_flag_set(tp, CPMU_PRESENT); |
| 14449 | |
| 14450 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 14451 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C || |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14452 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 14453 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
| 14454 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720) |
| 14455 | reg = TG3PCI_GEN2_PRODID_ASICREV; |
| 14456 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
| 14457 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || |
| 14458 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || |
| 14459 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || |
| 14460 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 14461 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
| 14462 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762 || |
| 14463 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766 || |
| 14464 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782 || |
| 14465 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 14466 | reg = TG3PCI_GEN15_PRODID_ASICREV; |
| 14467 | else |
| 14468 | reg = TG3PCI_PRODID_ASICREV; |
| 14469 | |
| 14470 | pci_read_config_dword(tp->pdev, reg, &tp->pci_chip_rev_id); |
| 14471 | } |
| 14472 | |
| 14473 | /* Wrong chip ID in 5752 A0. This code can be removed later |
| 14474 | * as A0 is not in production. |
| 14475 | */ |
| 14476 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) |
| 14477 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
| 14478 | |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 14479 | if (tp->pci_chip_rev_id == CHIPREV_ID_5717_C0) |
| 14480 | tp->pci_chip_rev_id = CHIPREV_ID_5720_A0; |
| 14481 | |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14482 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14483 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14484 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 14485 | tg3_flag_set(tp, 5717_PLUS); |
| 14486 | |
| 14487 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 || |
| 14488 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) |
| 14489 | tg3_flag_set(tp, 57765_CLASS); |
| 14490 | |
| 14491 | if (tg3_flag(tp, 57765_CLASS) || tg3_flag(tp, 5717_PLUS)) |
| 14492 | tg3_flag_set(tp, 57765_PLUS); |
| 14493 | |
| 14494 | /* Intentionally exclude ASIC_REV_5906 */ |
| 14495 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 14496 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
| 14497 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 14498 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 14499 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 14500 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 14501 | tg3_flag(tp, 57765_PLUS)) |
| 14502 | tg3_flag_set(tp, 5755_PLUS); |
| 14503 | |
| 14504 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
| 14505 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) |
| 14506 | tg3_flag_set(tp, 5780_CLASS); |
| 14507 | |
| 14508 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 14509 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 14510 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
| 14511 | tg3_flag(tp, 5755_PLUS) || |
| 14512 | tg3_flag(tp, 5780_CLASS)) |
| 14513 | tg3_flag_set(tp, 5750_PLUS); |
| 14514 | |
| 14515 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 14516 | tg3_flag(tp, 5750_PLUS)) |
| 14517 | tg3_flag_set(tp, 5705_PLUS); |
| 14518 | } |
| 14519 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 14520 | static bool tg3_10_100_only_device(struct tg3 *tp, |
| 14521 | const struct pci_device_id *ent) |
| 14522 | { |
| 14523 | u32 grc_misc_cfg = tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK; |
| 14524 | |
| 14525 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 14526 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || |
| 14527 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
| 14528 | return true; |
| 14529 | |
| 14530 | if (ent->driver_data & TG3_DRV_DATA_FLAG_10_100_ONLY) { |
| 14531 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 14532 | if (ent->driver_data & TG3_DRV_DATA_FLAG_5705_10_100) |
| 14533 | return true; |
| 14534 | } else { |
| 14535 | return true; |
| 14536 | } |
| 14537 | } |
| 14538 | |
| 14539 | return false; |
| 14540 | } |
| 14541 | |
| 14542 | static int __devinit tg3_get_invariants(struct tg3 *tp, |
| 14543 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14544 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14545 | u32 misc_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14546 | u32 pci_state_reg, grc_misc_cfg; |
| 14547 | u32 val; |
| 14548 | u16 pci_cmd; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14549 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14551 | /* Force memory write invalidate off. If we leave it on, |
| 14552 | * then on 5700_BX chips we have to enable a workaround. |
| 14553 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary |
| 14554 | * to match the cacheline size. The Broadcom driver have this |
| 14555 | * workaround but turns MWI off all the times so never uses |
| 14556 | * it. This seems to suggest that the workaround is insufficient. |
| 14557 | */ |
| 14558 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 14559 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; |
| 14560 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 14561 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14562 | /* Important! -- Make sure register accesses are byteswapped |
| 14563 | * correctly. Also, for those chips that require it, make |
| 14564 | * sure that indirect register accesses are enabled before |
| 14565 | * the first operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14566 | */ |
| 14567 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 14568 | &misc_ctrl_reg); |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14569 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
| 14570 | MISC_HOST_CTRL_CHIPREV); |
| 14571 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 14572 | tp->misc_host_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14573 | |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14574 | tg3_detect_asic_rev(tp, misc_ctrl_reg); |
Michael Chan | ff645be | 2005-04-21 17:09:53 -0700 | [diff] [blame] | 14575 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14576 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
| 14577 | * we need to disable memory and use config. cycles |
| 14578 | * only to access all registers. The 5702/03 chips |
| 14579 | * can mistakenly decode the special cycles from the |
| 14580 | * ICH chipsets as memory write cycles, causing corruption |
| 14581 | * of register and memory space. Only certain ICH bridges |
| 14582 | * will drive special cycles with non-zero data during the |
| 14583 | * address phase which can fall within the 5703's address |
| 14584 | * range. This is not an ICH bug as the PCI spec allows |
| 14585 | * non-zero address during special cycles. However, only |
| 14586 | * these ICH bridges are known to drive non-zero addresses |
| 14587 | * during special cycles. |
| 14588 | * |
| 14589 | * Since special cycles do not cross PCI bridges, we only |
| 14590 | * enable this workaround if the 5703 is on the secondary |
| 14591 | * bus of these ICH bridges. |
| 14592 | */ |
| 14593 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || |
| 14594 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { |
| 14595 | static struct tg3_dev_id { |
| 14596 | u32 vendor; |
| 14597 | u32 device; |
| 14598 | u32 rev; |
| 14599 | } ich_chipsets[] = { |
| 14600 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, |
| 14601 | PCI_ANY_ID }, |
| 14602 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, |
| 14603 | PCI_ANY_ID }, |
| 14604 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, |
| 14605 | 0xa }, |
| 14606 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, |
| 14607 | PCI_ANY_ID }, |
| 14608 | { }, |
| 14609 | }; |
| 14610 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; |
| 14611 | struct pci_dev *bridge = NULL; |
| 14612 | |
| 14613 | while (pci_id->vendor != 0) { |
| 14614 | bridge = pci_get_device(pci_id->vendor, pci_id->device, |
| 14615 | bridge); |
| 14616 | if (!bridge) { |
| 14617 | pci_id++; |
| 14618 | continue; |
| 14619 | } |
| 14620 | if (pci_id->rev != PCI_ANY_ID) { |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 14621 | if (bridge->revision > pci_id->rev) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14622 | continue; |
| 14623 | } |
| 14624 | if (bridge->subordinate && |
| 14625 | (bridge->subordinate->number == |
| 14626 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14627 | tg3_flag_set(tp, ICH_WORKAROUND); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14628 | pci_dev_put(bridge); |
| 14629 | break; |
| 14630 | } |
| 14631 | } |
| 14632 | } |
| 14633 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14634 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 14635 | static struct tg3_dev_id { |
| 14636 | u32 vendor; |
| 14637 | u32 device; |
| 14638 | } bridge_chipsets[] = { |
| 14639 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, |
| 14640 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, |
| 14641 | { }, |
| 14642 | }; |
| 14643 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; |
| 14644 | struct pci_dev *bridge = NULL; |
| 14645 | |
| 14646 | while (pci_id->vendor != 0) { |
| 14647 | bridge = pci_get_device(pci_id->vendor, |
| 14648 | pci_id->device, |
| 14649 | bridge); |
| 14650 | if (!bridge) { |
| 14651 | pci_id++; |
| 14652 | continue; |
| 14653 | } |
| 14654 | if (bridge->subordinate && |
| 14655 | (bridge->subordinate->number <= |
| 14656 | tp->pdev->bus->number) && |
Yinghai Lu | b918c62 | 2012-05-17 18:51:11 -0700 | [diff] [blame] | 14657 | (bridge->subordinate->busn_res.end >= |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 14658 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14659 | tg3_flag_set(tp, 5701_DMA_BUG); |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 14660 | pci_dev_put(bridge); |
| 14661 | break; |
| 14662 | } |
| 14663 | } |
| 14664 | } |
| 14665 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14666 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
| 14667 | * DMA addresses > 40-bit. This bridge may have other additional |
| 14668 | * 57xx devices behind it in some 4-port NIC designs for example. |
| 14669 | * Any tg3 device found behind the bridge will also need the 40-bit |
| 14670 | * DMA workaround. |
| 14671 | */ |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14672 | if (tg3_flag(tp, 5780_CLASS)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14673 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 14674 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14675 | } else { |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14676 | struct pci_dev *bridge = NULL; |
| 14677 | |
| 14678 | do { |
| 14679 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, |
| 14680 | PCI_DEVICE_ID_SERVERWORKS_EPB, |
| 14681 | bridge); |
| 14682 | if (bridge && bridge->subordinate && |
| 14683 | (bridge->subordinate->number <= |
| 14684 | tp->pdev->bus->number) && |
Yinghai Lu | b918c62 | 2012-05-17 18:51:11 -0700 | [diff] [blame] | 14685 | (bridge->subordinate->busn_res.end >= |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14686 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14687 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14688 | pci_dev_put(bridge); |
| 14689 | break; |
| 14690 | } |
| 14691 | } while (bridge); |
| 14692 | } |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 14693 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14694 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 14695 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 14696 | tp->pdev_peer = tg3_find_peer(tp); |
| 14697 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14698 | /* Determine TSO capabilities */ |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 14699 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0) |
Matt Carlson | 4d163b7 | 2011-01-25 15:58:48 +0000 | [diff] [blame] | 14700 | ; /* Do nothing. HW bug. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14701 | else if (tg3_flag(tp, 57765_PLUS)) |
| 14702 | tg3_flag_set(tp, HW_TSO_3); |
| 14703 | else if (tg3_flag(tp, 5755_PLUS) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14704 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14705 | tg3_flag_set(tp, HW_TSO_2); |
| 14706 | else if (tg3_flag(tp, 5750_PLUS)) { |
| 14707 | tg3_flag_set(tp, HW_TSO_1); |
| 14708 | tg3_flag_set(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14709 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && |
| 14710 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14711 | tg3_flag_clear(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14712 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14713 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 14714 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14715 | tg3_flag_set(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14716 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) |
| 14717 | tp->fw_needed = FIRMWARE_TG3TSO5; |
| 14718 | else |
| 14719 | tp->fw_needed = FIRMWARE_TG3TSO; |
| 14720 | } |
| 14721 | |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14722 | /* Selectively allow TSO based on operating conditions */ |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14723 | if (tg3_flag(tp, HW_TSO_1) || |
| 14724 | tg3_flag(tp, HW_TSO_2) || |
| 14725 | tg3_flag(tp, HW_TSO_3) || |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 14726 | tp->fw_needed) { |
| 14727 | /* For firmware TSO, assume ASF is disabled. |
| 14728 | * We'll disable TSO later if we discover ASF |
| 14729 | * is enabled in tg3_get_eeprom_hw_cfg(). |
| 14730 | */ |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14731 | tg3_flag_set(tp, TSO_CAPABLE); |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 14732 | } else { |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14733 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 14734 | tg3_flag_clear(tp, TSO_BUG); |
| 14735 | tp->fw_needed = NULL; |
| 14736 | } |
| 14737 | |
| 14738 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) |
| 14739 | tp->fw_needed = FIRMWARE_TG3; |
| 14740 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14741 | tp->irq_max = 1; |
| 14742 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14743 | if (tg3_flag(tp, 5750_PLUS)) { |
| 14744 | tg3_flag_set(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 14745 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || |
| 14746 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || |
| 14747 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && |
| 14748 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && |
| 14749 | tp->pdev_peer == tp->pdev)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14750 | tg3_flag_clear(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 14751 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14752 | if (tg3_flag(tp, 5755_PLUS) || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14753 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14754 | tg3_flag_set(tp, 1SHOT_MSI); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 14755 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14756 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14757 | if (tg3_flag(tp, 57765_PLUS)) { |
| 14758 | tg3_flag_set(tp, SUPPORT_MSIX); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14759 | tp->irq_max = TG3_IRQ_MAX_VECS; |
| 14760 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14761 | } |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 14762 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 14763 | tp->txq_max = 1; |
| 14764 | tp->rxq_max = 1; |
| 14765 | if (tp->irq_max > 1) { |
| 14766 | tp->rxq_max = TG3_RSS_MAX_NUM_QS; |
| 14767 | tg3_rss_init_dflt_indir_tbl(tp, TG3_RSS_MAX_NUM_QS); |
| 14768 | |
| 14769 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14770 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 14771 | tp->txq_max = tp->irq_max - 1; |
| 14772 | } |
| 14773 | |
Matt Carlson | b7abee6 | 2012-06-07 12:56:54 +0000 | [diff] [blame] | 14774 | if (tg3_flag(tp, 5755_PLUS) || |
| 14775 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14776 | tg3_flag_set(tp, SHORT_DMA_BUG); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 14777 | |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 14778 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 14779 | tp->dma_limit = TG3_TX_BD_DMA_MAX_4K; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 14780 | |
Matt Carlson | fa6b2aa | 2011-11-21 15:01:19 +0000 | [diff] [blame] | 14781 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14782 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14783 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14784 | tg3_flag_set(tp, LRG_PROD_RING_CAP); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 14785 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14786 | if (tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 14787 | tp->pci_chip_rev_id != CHIPREV_ID_5719_A0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14788 | tg3_flag_set(tp, USE_JUMBO_BDFLAG); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 14789 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14790 | if (!tg3_flag(tp, 5705_PLUS) || |
| 14791 | tg3_flag(tp, 5780_CLASS) || |
| 14792 | tg3_flag(tp, USE_JUMBO_BDFLAG)) |
| 14793 | tg3_flag_set(tp, JUMBO_CAPABLE); |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 14794 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14795 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 14796 | &pci_state_reg); |
| 14797 | |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 14798 | if (pci_is_pcie(tp->pdev)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14799 | u16 lnkctl; |
| 14800 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14801 | tg3_flag_set(tp, PCI_EXPRESS); |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 14802 | |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 14803 | pcie_capability_read_word(tp->pdev, PCI_EXP_LNKCTL, &lnkctl); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14804 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
Matt Carlson | 7196cd6 | 2011-05-19 16:02:44 +0000 | [diff] [blame] | 14805 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 14806 | ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14807 | tg3_flag_clear(tp, HW_TSO_2); |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 14808 | tg3_flag_clear(tp, TSO_CAPABLE); |
Matt Carlson | 7196cd6 | 2011-05-19 16:02:44 +0000 | [diff] [blame] | 14809 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 14810 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14811 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 9cf74eb | 2009-04-20 06:58:27 +0000 | [diff] [blame] | 14812 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
| 14813 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14814 | tg3_flag_set(tp, CLKREQ_BUG); |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 14815 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14816 | tg3_flag_set(tp, L1PLLPD_EN); |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 14817 | } |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14818 | } 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] | 14819 | /* BCM5785 devices are effectively PCIe devices, and should |
| 14820 | * follow PCIe codepaths, but do not have a PCIe capabilities |
| 14821 | * section. |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 14822 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14823 | tg3_flag_set(tp, PCI_EXPRESS); |
| 14824 | } else if (!tg3_flag(tp, 5705_PLUS) || |
| 14825 | tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14826 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
| 14827 | if (!tp->pcix_cap) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14828 | dev_err(&tp->pdev->dev, |
| 14829 | "Cannot find PCI-X capability, aborting\n"); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14830 | return -EIO; |
| 14831 | } |
| 14832 | |
| 14833 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14834 | tg3_flag_set(tp, PCIX_MODE); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14835 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14836 | |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 14837 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
| 14838 | * reordering to the mailbox registers done by the host |
| 14839 | * controller can cause major troubles. We read back from |
| 14840 | * every mailbox register write to force the writes to be |
| 14841 | * posted to the chip in order. |
| 14842 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 14843 | if (pci_dev_present(tg3_write_reorder_chipsets) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14844 | !tg3_flag(tp, PCI_EXPRESS)) |
| 14845 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 14846 | |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 14847 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 14848 | &tp->pci_cacheline_sz); |
| 14849 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 14850 | &tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14851 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 14852 | tp->pci_lat_timer < 64) { |
| 14853 | tp->pci_lat_timer = 64; |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 14854 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 14855 | tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14856 | } |
| 14857 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14858 | /* Important! -- It is critical that the PCI-X hw workaround |
| 14859 | * situation is decided before the first MMIO register access. |
| 14860 | */ |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14861 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
| 14862 | /* 5700 BX chips need to have their TX producer index |
| 14863 | * mailboxes written twice to workaround a bug. |
| 14864 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14865 | tg3_flag_set(tp, TXD_MBOX_HWBUG); |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 14866 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 14867 | /* If we are in PCI-X mode, enable register write workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14868 | * |
| 14869 | * The workaround is to use indirect register accesses |
| 14870 | * for all chip writes not to mailbox registers. |
| 14871 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14872 | if (tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14873 | u32 pm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14874 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14875 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14876 | |
| 14877 | /* The chip can have it's power management PCI config |
| 14878 | * space registers clobbered due to this bug. |
| 14879 | * So explicitly force the chip into D0 here. |
| 14880 | */ |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 14881 | pci_read_config_dword(tp->pdev, |
| 14882 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14883 | &pm_reg); |
| 14884 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; |
| 14885 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 14886 | pci_write_config_dword(tp->pdev, |
| 14887 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14888 | pm_reg); |
| 14889 | |
| 14890 | /* Also, force SERR#/PERR# in PCI command. */ |
| 14891 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 14892 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
| 14893 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 14894 | } |
| 14895 | } |
| 14896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14897 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14898 | tg3_flag_set(tp, PCI_HIGH_SPEED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14899 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14900 | tg3_flag_set(tp, PCI_32BIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14901 | |
| 14902 | /* Chip-specific fixup from Broadcom driver */ |
| 14903 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && |
| 14904 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
| 14905 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; |
| 14906 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); |
| 14907 | } |
| 14908 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14909 | /* Default fast path register access methods */ |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 14910 | tp->read32 = tg3_read32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14911 | tp->write32 = tg3_write32; |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 14912 | tp->read32_mbox = tg3_read32; |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 14913 | tp->write32_mbox = tg3_write32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14914 | tp->write32_tx_mbox = tg3_write32; |
| 14915 | tp->write32_rx_mbox = tg3_write32; |
| 14916 | |
| 14917 | /* Various workaround register access methods */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14918 | if (tg3_flag(tp, PCIX_TARGET_HWBUG)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14919 | tp->write32 = tg3_write_indirect_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 14920 | 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] | 14921 | (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 14922 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { |
| 14923 | /* |
| 14924 | * Back to back register writes can cause problems on these |
| 14925 | * chips, the workaround is to read back all reg writes |
| 14926 | * except those to mailbox regs. |
| 14927 | * |
| 14928 | * See tg3_write_indirect_reg32(). |
| 14929 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14930 | tp->write32 = tg3_write_flush_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 14931 | } |
| 14932 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14933 | 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] | 14934 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14935 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 14936 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 14937 | } |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 14938 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14939 | if (tg3_flag(tp, ICH_WORKAROUND)) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14940 | tp->read32 = tg3_read_indirect_reg32; |
| 14941 | tp->write32 = tg3_write_indirect_reg32; |
| 14942 | tp->read32_mbox = tg3_read_indirect_mbox; |
| 14943 | tp->write32_mbox = tg3_write_indirect_mbox; |
| 14944 | tp->write32_tx_mbox = tg3_write_indirect_mbox; |
| 14945 | tp->write32_rx_mbox = tg3_write_indirect_mbox; |
| 14946 | |
| 14947 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 14948 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14949 | |
| 14950 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 14951 | pci_cmd &= ~PCI_COMMAND_MEMORY; |
| 14952 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 14953 | } |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14954 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 14955 | tp->read32_mbox = tg3_read32_mbox_5906; |
| 14956 | tp->write32_mbox = tg3_write32_mbox_5906; |
| 14957 | tp->write32_tx_mbox = tg3_write32_mbox_5906; |
| 14958 | tp->write32_rx_mbox = tg3_write32_mbox_5906; |
| 14959 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14960 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 14961 | if (tp->write32 == tg3_write_indirect_reg32 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14962 | (tg3_flag(tp, PCIX_MODE) && |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 14963 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 14964 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14965 | tg3_flag_set(tp, SRAM_USE_CONFIG); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 14966 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 14967 | /* The memory arbiter has to be enabled in order for SRAM accesses |
| 14968 | * to succeed. Normally on powerup the tg3 chip firmware will make |
| 14969 | * sure it is enabled, but other entities such as system netboot |
| 14970 | * code might disable it. |
| 14971 | */ |
| 14972 | val = tr32(MEMARB_MODE); |
| 14973 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 14974 | |
Matt Carlson | 9dc5e34 | 2011-11-04 09:15:02 +0000 | [diff] [blame] | 14975 | tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3; |
| 14976 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 14977 | tg3_flag(tp, 5780_CLASS)) { |
| 14978 | if (tg3_flag(tp, PCIX_MODE)) { |
| 14979 | pci_read_config_dword(tp->pdev, |
| 14980 | tp->pcix_cap + PCI_X_STATUS, |
| 14981 | &val); |
| 14982 | tp->pci_fn = val & 0x7; |
| 14983 | } |
| 14984 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 14985 | tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val); |
| 14986 | if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) == |
| 14987 | NIC_SRAM_CPMUSTAT_SIG) { |
| 14988 | tp->pci_fn = val & TG3_CPMU_STATUS_FMSK_5717; |
| 14989 | tp->pci_fn = tp->pci_fn ? 1 : 0; |
| 14990 | } |
| 14991 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14992 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 14993 | tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val); |
| 14994 | if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) == |
| 14995 | NIC_SRAM_CPMUSTAT_SIG) { |
| 14996 | tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5719) >> |
| 14997 | TG3_CPMU_STATUS_FSHFT_5719; |
| 14998 | } |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 14999 | } |
| 15000 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 15001 | /* Get eeprom hw config before calling tg3_set_power_state(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15002 | * In particular, the TG3_FLAG_IS_NIC flag must be |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 15003 | * determined before calling tg3_set_power_state() so that |
| 15004 | * we know whether or not to switch out of Vaux power. |
| 15005 | * When the flag is set, it means that GPIO1 is used for eeprom |
| 15006 | * write protect and also implies that it is a LOM where GPIOs |
| 15007 | * are not used to switch power. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 15008 | */ |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 15009 | tg3_get_eeprom_hw_cfg(tp); |
| 15010 | |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 15011 | if (tp->fw_needed && tg3_flag(tp, ENABLE_ASF)) { |
| 15012 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 15013 | tg3_flag_clear(tp, TSO_BUG); |
| 15014 | tp->fw_needed = NULL; |
| 15015 | } |
| 15016 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15017 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15018 | /* Allow reads and writes to the |
| 15019 | * APE register and memory space. |
| 15020 | */ |
| 15021 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 15022 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 15023 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15024 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 15025 | pci_state_reg); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15026 | |
| 15027 | tg3_ape_lock_init(tp); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15028 | } |
| 15029 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15030 | /* Set up tp->grc_local_ctrl before calling |
| 15031 | * tg3_pwrsrc_switch_to_vmain(). GPIO1 driven high |
| 15032 | * will bring 5700's external PHY out of reset. |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 15033 | * It is also used as eeprom write protect on LOMs. |
| 15034 | */ |
| 15035 | 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] | 15036 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15037 | tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 15038 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 15039 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 15040 | /* Unused GPIO3 must be driven as output on 5752 because there |
| 15041 | * are no pull-up resistors on unused GPIO pins. |
| 15042 | */ |
| 15043 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 15044 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 15045 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 15046 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | cb4ed1f | 2010-01-20 16:58:09 +0000 | [diff] [blame] | 15047 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 15048 | tg3_flag(tp, 57765_CLASS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 15049 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 15050 | |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 15051 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 15052 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 15053 | /* Turn off the debug UART. */ |
| 15054 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15055 | if (tg3_flag(tp, IS_NIC)) |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 15056 | /* Keep VMain power. */ |
| 15057 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 15058 | GRC_LCLCTRL_GPIO_OUTPUT0; |
| 15059 | } |
| 15060 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15061 | /* Switch out of Vaux if it is a NIC */ |
| 15062 | tg3_pwrsrc_switch_to_vmain(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15064 | /* Derive initial jumbo mode from MTU assigned in |
| 15065 | * ether_setup() via the alloc_etherdev() call |
| 15066 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15067 | if (tp->dev->mtu > ETH_DATA_LEN && !tg3_flag(tp, 5780_CLASS)) |
| 15068 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15069 | |
| 15070 | /* Determine WakeOnLan speed to use. */ |
| 15071 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 15072 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 15073 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || |
| 15074 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15075 | tg3_flag_clear(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15076 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15077 | tg3_flag_set(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15078 | } |
| 15079 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 15080 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15081 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 15082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15083 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 15084 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 15085 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15086 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 15087 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15088 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
| 15089 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 15090 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15091 | |
| 15092 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || |
| 15093 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15094 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15095 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15096 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15097 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15098 | if (tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15099 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 15100 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 15101 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15102 | !tg3_flag(tp, 57765_PLUS)) { |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 15103 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 15104 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 15105 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 15106 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
Michael Chan | d4011ad | 2007-02-13 12:17:25 -0800 | [diff] [blame] | 15107 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
| 15108 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15109 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 15110 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15111 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 15112 | } else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15113 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 15114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15115 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 15116 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 15117 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 15118 | tp->phy_otp = tg3_read_otp_phycfg(tp); |
| 15119 | if (tp->phy_otp == 0) |
| 15120 | tp->phy_otp = TG3_OTP_DEFAULT; |
| 15121 | } |
| 15122 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15123 | if (tg3_flag(tp, CPMU_PRESENT)) |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 15124 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
| 15125 | else |
| 15126 | tp->mi_mode = MAC_MI_MODE_BASE; |
| 15127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15128 | tp->coalesce_mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15129 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
| 15130 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) |
| 15131 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
| 15132 | |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 15133 | /* Set these bits to enable statistics workaround. */ |
| 15134 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 15135 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 15136 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) { |
| 15137 | tp->coalesce_mode |= HOSTCC_MODE_ATTN; |
| 15138 | tp->grc_mode |= GRC_MODE_IRQ_ON_FLOW_ATTN; |
| 15139 | } |
| 15140 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 15141 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 15142 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15143 | tg3_flag_set(tp, USE_PHYLIB); |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 15144 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15145 | err = tg3_mdio_init(tp); |
| 15146 | if (err) |
| 15147 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15148 | |
| 15149 | /* Initialize data/descriptor byte/word swapping. */ |
| 15150 | val = tr32(GRC_MODE); |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 15151 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 15152 | val &= (GRC_MODE_BYTE_SWAP_B2HRX_DATA | |
| 15153 | GRC_MODE_WORD_SWAP_B2HRX_DATA | |
| 15154 | GRC_MODE_B2HRX_ENABLE | |
| 15155 | GRC_MODE_HTX2B_ENABLE | |
| 15156 | GRC_MODE_HOST_STACKUP); |
| 15157 | else |
| 15158 | val &= GRC_MODE_HOST_STACKUP; |
| 15159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15160 | tw32(GRC_MODE, val | tp->grc_mode); |
| 15161 | |
| 15162 | tg3_switch_clocks(tp); |
| 15163 | |
| 15164 | /* Clear this out for sanity. */ |
| 15165 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 15166 | |
| 15167 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 15168 | &pci_state_reg); |
| 15169 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15170 | !tg3_flag(tp, PCIX_TARGET_HWBUG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15171 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); |
| 15172 | |
| 15173 | if (chiprevid == CHIPREV_ID_5701_A0 || |
| 15174 | chiprevid == CHIPREV_ID_5701_B0 || |
| 15175 | chiprevid == CHIPREV_ID_5701_B2 || |
| 15176 | chiprevid == CHIPREV_ID_5701_B5) { |
| 15177 | void __iomem *sram_base; |
| 15178 | |
| 15179 | /* Write some dummy words into the SRAM status block |
| 15180 | * area, see if it reads back correctly. If the return |
| 15181 | * value is bad, force enable the PCIX workaround. |
| 15182 | */ |
| 15183 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; |
| 15184 | |
| 15185 | writel(0x00000000, sram_base); |
| 15186 | writel(0x00000000, sram_base + 4); |
| 15187 | writel(0xffffffff, sram_base + 4); |
| 15188 | if (readl(sram_base) != 0x00000000) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15189 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15190 | } |
| 15191 | } |
| 15192 | |
| 15193 | udelay(50); |
| 15194 | tg3_nvram_init(tp); |
| 15195 | |
| 15196 | grc_misc_cfg = tr32(GRC_MISC_CFG); |
| 15197 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; |
| 15198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15199 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 15200 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
| 15201 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15202 | tg3_flag_set(tp, IS_5788); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15203 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15204 | if (!tg3_flag(tp, IS_5788) && |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 15205 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15206 | tg3_flag_set(tp, TAGGED_STATUS); |
| 15207 | if (tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 15208 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
| 15209 | HOSTCC_MODE_CLRTICK_TXBD); |
| 15210 | |
| 15211 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; |
| 15212 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 15213 | tp->misc_host_ctrl); |
| 15214 | } |
| 15215 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 15216 | /* Preserve the APE MAC_MODE bits */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15217 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 15218 | 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] | 15219 | else |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 15220 | tp->mac_mode = 0; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 15221 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 15222 | if (tg3_10_100_only_device(tp, ent)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15223 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15224 | |
| 15225 | err = tg3_phy_probe(tp); |
| 15226 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15227 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15228 | /* ... but do not return immediately ... */ |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15229 | tg3_mdio_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15230 | } |
| 15231 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 15232 | tg3_read_vpd(tp); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 15233 | tg3_read_fw_ver(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15234 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15235 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 15236 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15237 | } else { |
| 15238 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15239 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15240 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15241 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15242 | } |
| 15243 | |
| 15244 | /* 5700 {AX,BX} chips have a broken status block link |
| 15245 | * change bit implementation, so we must use the |
| 15246 | * status register in those cases. |
| 15247 | */ |
| 15248 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15249 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15250 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15251 | tg3_flag_clear(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15252 | |
| 15253 | /* The led_ctrl is set during tg3_phy_probe, here we might |
| 15254 | * have to force the link status polling mechanism based |
| 15255 | * upon subsystem IDs. |
| 15256 | */ |
| 15257 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
Michael Chan | 007a880d | 2007-05-31 14:49:51 -0700 | [diff] [blame] | 15258 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15259 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 15260 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15261 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15262 | } |
| 15263 | |
| 15264 | /* For all SERDES we poll the MAC status register. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15265 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15266 | tg3_flag_set(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15267 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15268 | tg3_flag_clear(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15269 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 15270 | tp->rx_offset = NET_SKB_PAD + NET_IP_ALIGN; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 15271 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15272 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15273 | tg3_flag(tp, PCIX_MODE)) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 15274 | tp->rx_offset = NET_SKB_PAD; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 15275 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 15276 | tp->rx_copy_thresh = ~(u16)0; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 15277 | #endif |
| 15278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15279 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 15280 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
| 15281 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 15282 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
| 15283 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 15284 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 15285 | |
| 15286 | /* Increment the rx prod index on the rx std ring by at most |
| 15287 | * 8 for these chips to workaround hw errata. |
| 15288 | */ |
| 15289 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 15290 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 15291 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 15292 | tp->rx_std_max_post = 8; |
| 15293 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15294 | if (tg3_flag(tp, ASPM_WORKAROUND)) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 15295 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
| 15296 | PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 15297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15298 | return err; |
| 15299 | } |
| 15300 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15301 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15302 | static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp) |
| 15303 | { |
| 15304 | struct net_device *dev = tp->dev; |
| 15305 | struct pci_dev *pdev = tp->pdev; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15306 | struct device_node *dp = pci_device_to_OF_node(pdev); |
David S. Miller | 374d4ca | 2007-03-29 01:57:57 -0700 | [diff] [blame] | 15307 | const unsigned char *addr; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15308 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15309 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15310 | addr = of_get_property(dp, "local-mac-address", &len); |
| 15311 | if (addr && len == 6) { |
| 15312 | memcpy(dev->dev_addr, addr, 6); |
| 15313 | memcpy(dev->perm_addr, dev->dev_addr, 6); |
| 15314 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15315 | } |
| 15316 | return -ENODEV; |
| 15317 | } |
| 15318 | |
| 15319 | static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp) |
| 15320 | { |
| 15321 | struct net_device *dev = tp->dev; |
| 15322 | |
| 15323 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 15324 | memcpy(dev->perm_addr, idprom->id_ethaddr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15325 | return 0; |
| 15326 | } |
| 15327 | #endif |
| 15328 | |
| 15329 | static int __devinit tg3_get_device_address(struct tg3 *tp) |
| 15330 | { |
| 15331 | struct net_device *dev = tp->dev; |
| 15332 | u32 hi, lo, mac_offset; |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 15333 | int addr_ok = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15334 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15335 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15336 | if (!tg3_get_macaddr_sparc(tp)) |
| 15337 | return 0; |
| 15338 | #endif |
| 15339 | |
| 15340 | mac_offset = 0x7c; |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 15341 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15342 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15343 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 15344 | mac_offset = 0xcc; |
| 15345 | if (tg3_nvram_lock(tp)) |
| 15346 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); |
| 15347 | else |
| 15348 | tg3_nvram_unlock(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15349 | } else if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 15350 | if (tp->pci_fn & 1) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 15351 | mac_offset = 0xcc; |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 15352 | if (tp->pci_fn > 1) |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 15353 | mac_offset += 0x18c; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 15354 | } 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] | 15355 | mac_offset = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15356 | |
| 15357 | /* First try to get it from MAC address mailbox. */ |
| 15358 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); |
| 15359 | if ((hi >> 16) == 0x484b) { |
| 15360 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 15361 | dev->dev_addr[1] = (hi >> 0) & 0xff; |
| 15362 | |
| 15363 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); |
| 15364 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 15365 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 15366 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 15367 | dev->dev_addr[5] = (lo >> 0) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15368 | |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 15369 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
| 15370 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); |
| 15371 | } |
| 15372 | if (!addr_ok) { |
| 15373 | /* Next, try NVRAM. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15374 | if (!tg3_flag(tp, NO_NVRAM) && |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 15375 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 15376 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 15377 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
| 15378 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 15379 | } |
| 15380 | /* Finally just fetch it out of the MAC control regs. */ |
| 15381 | else { |
| 15382 | hi = tr32(MAC_ADDR_0_HIGH); |
| 15383 | lo = tr32(MAC_ADDR_0_LOW); |
| 15384 | |
| 15385 | dev->dev_addr[5] = lo & 0xff; |
| 15386 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 15387 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 15388 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 15389 | dev->dev_addr[1] = hi & 0xff; |
| 15390 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 15391 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15392 | } |
| 15393 | |
| 15394 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { |
David S. Miller | 7582a33 | 2008-03-20 15:53:15 -0700 | [diff] [blame] | 15395 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15396 | if (!tg3_get_default_macaddr_sparc(tp)) |
| 15397 | return 0; |
| 15398 | #endif |
| 15399 | return -EINVAL; |
| 15400 | } |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 15401 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15402 | return 0; |
| 15403 | } |
| 15404 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15405 | #define BOUNDARY_SINGLE_CACHELINE 1 |
| 15406 | #define BOUNDARY_MULTI_CACHELINE 2 |
| 15407 | |
| 15408 | static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
| 15409 | { |
| 15410 | int cacheline_size; |
| 15411 | u8 byte; |
| 15412 | int goal; |
| 15413 | |
| 15414 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); |
| 15415 | if (byte == 0) |
| 15416 | cacheline_size = 1024; |
| 15417 | else |
| 15418 | cacheline_size = (int) byte * 4; |
| 15419 | |
| 15420 | /* On 5703 and later chips, the boundary bits have no |
| 15421 | * effect. |
| 15422 | */ |
| 15423 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 15424 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15425 | !tg3_flag(tp, PCI_EXPRESS)) |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15426 | goto out; |
| 15427 | |
| 15428 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) |
| 15429 | goal = BOUNDARY_MULTI_CACHELINE; |
| 15430 | #else |
| 15431 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) |
| 15432 | goal = BOUNDARY_SINGLE_CACHELINE; |
| 15433 | #else |
| 15434 | goal = 0; |
| 15435 | #endif |
| 15436 | #endif |
| 15437 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15438 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 15439 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 15440 | goto out; |
| 15441 | } |
| 15442 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15443 | if (!goal) |
| 15444 | goto out; |
| 15445 | |
| 15446 | /* PCI controllers on most RISC systems tend to disconnect |
| 15447 | * when a device tries to burst across a cache-line boundary. |
| 15448 | * Therefore, letting tg3 do so just wastes PCI bandwidth. |
| 15449 | * |
| 15450 | * Unfortunately, for PCI-E there are only limited |
| 15451 | * write-side controls for this, and thus for reads |
| 15452 | * we will still get the disconnects. We'll also waste |
| 15453 | * these PCI cycles for both read and write for chips |
| 15454 | * other than 5700 and 5701 which do not implement the |
| 15455 | * boundary bits. |
| 15456 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15457 | if (tg3_flag(tp, PCIX_MODE) && !tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15458 | switch (cacheline_size) { |
| 15459 | case 16: |
| 15460 | case 32: |
| 15461 | case 64: |
| 15462 | case 128: |
| 15463 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15464 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | |
| 15465 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); |
| 15466 | } else { |
| 15467 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 15468 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 15469 | } |
| 15470 | break; |
| 15471 | |
| 15472 | case 256: |
| 15473 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | |
| 15474 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); |
| 15475 | break; |
| 15476 | |
| 15477 | default: |
| 15478 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 15479 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 15480 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15481 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15482 | } else if (tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15483 | switch (cacheline_size) { |
| 15484 | case 16: |
| 15485 | case 32: |
| 15486 | case 64: |
| 15487 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15488 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 15489 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; |
| 15490 | break; |
| 15491 | } |
| 15492 | /* fallthrough */ |
| 15493 | case 128: |
| 15494 | default: |
| 15495 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 15496 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; |
| 15497 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15498 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15499 | } else { |
| 15500 | switch (cacheline_size) { |
| 15501 | case 16: |
| 15502 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15503 | val |= (DMA_RWCTRL_READ_BNDRY_16 | |
| 15504 | DMA_RWCTRL_WRITE_BNDRY_16); |
| 15505 | break; |
| 15506 | } |
| 15507 | /* fallthrough */ |
| 15508 | case 32: |
| 15509 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15510 | val |= (DMA_RWCTRL_READ_BNDRY_32 | |
| 15511 | DMA_RWCTRL_WRITE_BNDRY_32); |
| 15512 | break; |
| 15513 | } |
| 15514 | /* fallthrough */ |
| 15515 | case 64: |
| 15516 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15517 | val |= (DMA_RWCTRL_READ_BNDRY_64 | |
| 15518 | DMA_RWCTRL_WRITE_BNDRY_64); |
| 15519 | break; |
| 15520 | } |
| 15521 | /* fallthrough */ |
| 15522 | case 128: |
| 15523 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15524 | val |= (DMA_RWCTRL_READ_BNDRY_128 | |
| 15525 | DMA_RWCTRL_WRITE_BNDRY_128); |
| 15526 | break; |
| 15527 | } |
| 15528 | /* fallthrough */ |
| 15529 | case 256: |
| 15530 | val |= (DMA_RWCTRL_READ_BNDRY_256 | |
| 15531 | DMA_RWCTRL_WRITE_BNDRY_256); |
| 15532 | break; |
| 15533 | case 512: |
| 15534 | val |= (DMA_RWCTRL_READ_BNDRY_512 | |
| 15535 | DMA_RWCTRL_WRITE_BNDRY_512); |
| 15536 | break; |
| 15537 | case 1024: |
| 15538 | default: |
| 15539 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | |
| 15540 | DMA_RWCTRL_WRITE_BNDRY_1024); |
| 15541 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15542 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15543 | } |
| 15544 | |
| 15545 | out: |
| 15546 | return val; |
| 15547 | } |
| 15548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15549 | static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) |
| 15550 | { |
| 15551 | struct tg3_internal_buffer_desc test_desc; |
| 15552 | u32 sram_dma_descs; |
| 15553 | int i, ret; |
| 15554 | |
| 15555 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; |
| 15556 | |
| 15557 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); |
| 15558 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); |
| 15559 | tw32(RDMAC_STATUS, 0); |
| 15560 | tw32(WDMAC_STATUS, 0); |
| 15561 | |
| 15562 | tw32(BUFMGR_MODE, 0); |
| 15563 | tw32(FTQ_RESET, 0); |
| 15564 | |
| 15565 | test_desc.addr_hi = ((u64) buf_dma) >> 32; |
| 15566 | test_desc.addr_lo = buf_dma & 0xffffffff; |
| 15567 | test_desc.nic_mbuf = 0x00002100; |
| 15568 | test_desc.len = size; |
| 15569 | |
| 15570 | /* |
| 15571 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz |
| 15572 | * the *second* time the tg3 driver was getting loaded after an |
| 15573 | * initial scan. |
| 15574 | * |
| 15575 | * Broadcom tells me: |
| 15576 | * ...the DMA engine is connected to the GRC block and a DMA |
| 15577 | * reset may affect the GRC block in some unpredictable way... |
| 15578 | * The behavior of resets to individual blocks has not been tested. |
| 15579 | * |
| 15580 | * Broadcom noted the GRC reset will also reset all sub-components. |
| 15581 | */ |
| 15582 | if (to_device) { |
| 15583 | test_desc.cqid_sqid = (13 << 8) | 2; |
| 15584 | |
| 15585 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); |
| 15586 | udelay(40); |
| 15587 | } else { |
| 15588 | test_desc.cqid_sqid = (16 << 8) | 7; |
| 15589 | |
| 15590 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); |
| 15591 | udelay(40); |
| 15592 | } |
| 15593 | test_desc.flags = 0x00000005; |
| 15594 | |
| 15595 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { |
| 15596 | u32 val; |
| 15597 | |
| 15598 | val = *(((u32 *)&test_desc) + i); |
| 15599 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, |
| 15600 | sram_dma_descs + (i * sizeof(u32))); |
| 15601 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 15602 | } |
| 15603 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 15604 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15605 | if (to_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15606 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15607 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15608 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15609 | |
| 15610 | ret = -ENODEV; |
| 15611 | for (i = 0; i < 40; i++) { |
| 15612 | u32 val; |
| 15613 | |
| 15614 | if (to_device) |
| 15615 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); |
| 15616 | else |
| 15617 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); |
| 15618 | if ((val & 0xffff) == sram_dma_descs) { |
| 15619 | ret = 0; |
| 15620 | break; |
| 15621 | } |
| 15622 | |
| 15623 | udelay(100); |
| 15624 | } |
| 15625 | |
| 15626 | return ret; |
| 15627 | } |
| 15628 | |
David S. Miller | ded7340 | 2005-05-23 13:59:47 -0700 | [diff] [blame] | 15629 | #define TEST_BUFFER_SIZE 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15630 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 15631 | static DEFINE_PCI_DEVICE_TABLE(tg3_dma_wait_state_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 15632 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
| 15633 | { }, |
| 15634 | }; |
| 15635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15636 | static int __devinit tg3_test_dma(struct tg3 *tp) |
| 15637 | { |
| 15638 | dma_addr_t buf_dma; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15639 | u32 *buf, saved_dma_rwctrl; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 15640 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15641 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 15642 | buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
| 15643 | &buf_dma, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15644 | if (!buf) { |
| 15645 | ret = -ENOMEM; |
| 15646 | goto out_nofree; |
| 15647 | } |
| 15648 | |
| 15649 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | |
| 15650 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); |
| 15651 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15652 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15653 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15654 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 15655 | goto out; |
| 15656 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15657 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15658 | /* DMA read watermark not used on PCIE */ |
| 15659 | tp->dma_rwctrl |= 0x00180000; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15660 | } else if (!tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 15661 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 15662 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15663 | tp->dma_rwctrl |= 0x003f0000; |
| 15664 | else |
| 15665 | tp->dma_rwctrl |= 0x003f000f; |
| 15666 | } else { |
| 15667 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 15668 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 15669 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 15670 | u32 read_water = 0x7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15671 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15672 | /* If the 5704 is behind the EPB bridge, we can |
| 15673 | * do the less restrictive ONE_DMA workaround for |
| 15674 | * better performance. |
| 15675 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15676 | if (tg3_flag(tp, 40BIT_DMA_BUG) && |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15677 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 15678 | tp->dma_rwctrl |= 0x8000; |
| 15679 | else if (ccval == 0x6 || ccval == 0x7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15680 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 15681 | |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 15682 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
| 15683 | read_water = 4; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15684 | /* Set bit 23 to enable PCIX hw bug fix */ |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 15685 | tp->dma_rwctrl |= |
| 15686 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | |
| 15687 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | |
| 15688 | (1 << 23); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 15689 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
| 15690 | /* 5780 always in PCIX mode */ |
| 15691 | tp->dma_rwctrl |= 0x00144000; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 15692 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 15693 | /* 5714 always in PCIX mode */ |
| 15694 | tp->dma_rwctrl |= 0x00148000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15695 | } else { |
| 15696 | tp->dma_rwctrl |= 0x001b000f; |
| 15697 | } |
| 15698 | } |
| 15699 | |
| 15700 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 15701 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 15702 | tp->dma_rwctrl &= 0xfffffff0; |
| 15703 | |
| 15704 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 15705 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 15706 | /* Remove this if it causes problems for some boards. */ |
| 15707 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; |
| 15708 | |
| 15709 | /* On 5700/5701 chips, we need to set this bit. |
| 15710 | * Otherwise the chip will issue cacheline transactions |
| 15711 | * to streamable DMA memory with not all the byte |
| 15712 | * enables turned on. This is an error on several |
| 15713 | * RISC PCI controllers, in particular sparc64. |
| 15714 | * |
| 15715 | * On 5703/5704 chips, this bit has been reassigned |
| 15716 | * a different meaning. In particular, it is used |
| 15717 | * on those chips to enable a PCI-X workaround. |
| 15718 | */ |
| 15719 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; |
| 15720 | } |
| 15721 | |
| 15722 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15723 | |
| 15724 | #if 0 |
| 15725 | /* Unneeded, already done by tg3_get_invariants. */ |
| 15726 | tg3_switch_clocks(tp); |
| 15727 | #endif |
| 15728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15729 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 15730 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 15731 | goto out; |
| 15732 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15733 | /* It is best to perform DMA test with maximum write burst size |
| 15734 | * to expose the 5700/5701 write DMA bug. |
| 15735 | */ |
| 15736 | saved_dma_rwctrl = tp->dma_rwctrl; |
| 15737 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 15738 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15740 | while (1) { |
| 15741 | u32 *p = buf, i; |
| 15742 | |
| 15743 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) |
| 15744 | p[i] = i; |
| 15745 | |
| 15746 | /* Send the buffer to the chip. */ |
| 15747 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); |
| 15748 | if (ret) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15749 | dev_err(&tp->pdev->dev, |
| 15750 | "%s: Buffer write failed. err = %d\n", |
| 15751 | __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15752 | break; |
| 15753 | } |
| 15754 | |
| 15755 | #if 0 |
| 15756 | /* validate data reached card RAM correctly. */ |
| 15757 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 15758 | u32 val; |
| 15759 | tg3_read_mem(tp, 0x2100 + (i*4), &val); |
| 15760 | if (le32_to_cpu(val) != p[i]) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15761 | dev_err(&tp->pdev->dev, |
| 15762 | "%s: Buffer corrupted on device! " |
| 15763 | "(%d != %d)\n", __func__, val, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15764 | /* ret = -ENODEV here? */ |
| 15765 | } |
| 15766 | p[i] = 0; |
| 15767 | } |
| 15768 | #endif |
| 15769 | /* Now read it back. */ |
| 15770 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); |
| 15771 | if (ret) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 15772 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
| 15773 | "err = %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15774 | break; |
| 15775 | } |
| 15776 | |
| 15777 | /* Verify it. */ |
| 15778 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 15779 | if (p[i] == i) |
| 15780 | continue; |
| 15781 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15782 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 15783 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 15784 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15785 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 15786 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15787 | break; |
| 15788 | } else { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15789 | dev_err(&tp->pdev->dev, |
| 15790 | "%s: Buffer corrupted on read back! " |
| 15791 | "(%d != %d)\n", __func__, p[i], i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15792 | ret = -ENODEV; |
| 15793 | goto out; |
| 15794 | } |
| 15795 | } |
| 15796 | |
| 15797 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { |
| 15798 | /* Success. */ |
| 15799 | ret = 0; |
| 15800 | break; |
| 15801 | } |
| 15802 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15803 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 15804 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 15805 | /* DMA test passed without adjusting DMA boundary, |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15806 | * now look for chipsets that are known to expose the |
| 15807 | * DMA bug without failing the test. |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15808 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 15809 | if (pci_dev_present(tg3_dma_wait_state_chipsets)) { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15810 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 15811 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15812 | } else { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15813 | /* Safe to use the calculated DMA boundary. */ |
| 15814 | tp->dma_rwctrl = saved_dma_rwctrl; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15815 | } |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 15816 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15817 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 15818 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15819 | |
| 15820 | out: |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 15821 | dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15822 | out_nofree: |
| 15823 | return ret; |
| 15824 | } |
| 15825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15826 | static void __devinit tg3_init_bufmgr_config(struct tg3 *tp) |
| 15827 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15828 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 15829 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 15830 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 15831 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15832 | DEFAULT_MB_MACRX_LOW_WATER_57765; |
| 15833 | tp->bufmgr_config.mbuf_high_water = |
| 15834 | DEFAULT_MB_HIGH_WATER_57765; |
| 15835 | |
| 15836 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 15837 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 15838 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 15839 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; |
| 15840 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 15841 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15842 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 15843 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 15844 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 15845 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15846 | DEFAULT_MB_MACRX_LOW_WATER_5705; |
| 15847 | tp->bufmgr_config.mbuf_high_water = |
| 15848 | DEFAULT_MB_HIGH_WATER_5705; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 15849 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 15850 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15851 | DEFAULT_MB_MACRX_LOW_WATER_5906; |
| 15852 | tp->bufmgr_config.mbuf_high_water = |
| 15853 | DEFAULT_MB_HIGH_WATER_5906; |
| 15854 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15855 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 15856 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 15857 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; |
| 15858 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 15859 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; |
| 15860 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 15861 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; |
| 15862 | } else { |
| 15863 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 15864 | DEFAULT_MB_RDMA_LOW_WATER; |
| 15865 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 15866 | DEFAULT_MB_MACRX_LOW_WATER; |
| 15867 | tp->bufmgr_config.mbuf_high_water = |
| 15868 | DEFAULT_MB_HIGH_WATER; |
| 15869 | |
| 15870 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 15871 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; |
| 15872 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 15873 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; |
| 15874 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 15875 | DEFAULT_MB_HIGH_WATER_JUMBO; |
| 15876 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15877 | |
| 15878 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; |
| 15879 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; |
| 15880 | } |
| 15881 | |
| 15882 | static char * __devinit tg3_phy_string(struct tg3 *tp) |
| 15883 | { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15884 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
| 15885 | case TG3_PHY_ID_BCM5400: return "5400"; |
| 15886 | case TG3_PHY_ID_BCM5401: return "5401"; |
| 15887 | case TG3_PHY_ID_BCM5411: return "5411"; |
| 15888 | case TG3_PHY_ID_BCM5701: return "5701"; |
| 15889 | case TG3_PHY_ID_BCM5703: return "5703"; |
| 15890 | case TG3_PHY_ID_BCM5704: return "5704"; |
| 15891 | case TG3_PHY_ID_BCM5705: return "5705"; |
| 15892 | case TG3_PHY_ID_BCM5750: return "5750"; |
| 15893 | case TG3_PHY_ID_BCM5752: return "5752"; |
| 15894 | case TG3_PHY_ID_BCM5714: return "5714"; |
| 15895 | case TG3_PHY_ID_BCM5780: return "5780"; |
| 15896 | case TG3_PHY_ID_BCM5755: return "5755"; |
| 15897 | case TG3_PHY_ID_BCM5787: return "5787"; |
| 15898 | case TG3_PHY_ID_BCM5784: return "5784"; |
| 15899 | case TG3_PHY_ID_BCM5756: return "5722/5756"; |
| 15900 | case TG3_PHY_ID_BCM5906: return "5906"; |
| 15901 | case TG3_PHY_ID_BCM5761: return "5761"; |
| 15902 | case TG3_PHY_ID_BCM5718C: return "5718C"; |
| 15903 | case TG3_PHY_ID_BCM5718S: return "5718S"; |
| 15904 | case TG3_PHY_ID_BCM57765: return "57765"; |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 15905 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
Matt Carlson | 6418f2c | 2011-04-05 14:22:49 +0000 | [diff] [blame] | 15906 | case TG3_PHY_ID_BCM5720C: return "5720C"; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15907 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15908 | case 0: return "serdes"; |
| 15909 | default: return "unknown"; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15910 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15911 | } |
| 15912 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15913 | static char * __devinit tg3_bus_string(struct tg3 *tp, char *str) |
| 15914 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15915 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15916 | strcpy(str, "PCI Express"); |
| 15917 | return str; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15918 | } else if (tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15919 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
| 15920 | |
| 15921 | strcpy(str, "PCIX:"); |
| 15922 | |
| 15923 | if ((clock_ctrl == 7) || |
| 15924 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == |
| 15925 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) |
| 15926 | strcat(str, "133MHz"); |
| 15927 | else if (clock_ctrl == 0) |
| 15928 | strcat(str, "33MHz"); |
| 15929 | else if (clock_ctrl == 2) |
| 15930 | strcat(str, "50MHz"); |
| 15931 | else if (clock_ctrl == 4) |
| 15932 | strcat(str, "66MHz"); |
| 15933 | else if (clock_ctrl == 6) |
| 15934 | strcat(str, "100MHz"); |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15935 | } else { |
| 15936 | strcpy(str, "PCI:"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15937 | if (tg3_flag(tp, PCI_HIGH_SPEED)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15938 | strcat(str, "66MHz"); |
| 15939 | else |
| 15940 | strcat(str, "33MHz"); |
| 15941 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15942 | if (tg3_flag(tp, PCI_32BIT)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15943 | strcat(str, ":32-bit"); |
| 15944 | else |
| 15945 | strcat(str, ":64-bit"); |
| 15946 | return str; |
| 15947 | } |
| 15948 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 15949 | static void __devinit tg3_init_coal(struct tg3 *tp) |
| 15950 | { |
| 15951 | struct ethtool_coalesce *ec = &tp->coal; |
| 15952 | |
| 15953 | memset(ec, 0, sizeof(*ec)); |
| 15954 | ec->cmd = ETHTOOL_GCOALESCE; |
| 15955 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; |
| 15956 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; |
| 15957 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; |
| 15958 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; |
| 15959 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; |
| 15960 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; |
| 15961 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; |
| 15962 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; |
| 15963 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; |
| 15964 | |
| 15965 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | |
| 15966 | HOSTCC_MODE_CLRTICK_TXBD)) { |
| 15967 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; |
| 15968 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; |
| 15969 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; |
| 15970 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; |
| 15971 | } |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 15972 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15973 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 15974 | ec->rx_coalesce_usecs_irq = 0; |
| 15975 | ec->tx_coalesce_usecs_irq = 0; |
| 15976 | ec->stats_block_coalesce_usecs = 0; |
| 15977 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 15978 | } |
| 15979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15980 | static int __devinit tg3_init_one(struct pci_dev *pdev, |
| 15981 | const struct pci_device_id *ent) |
| 15982 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15983 | struct net_device *dev; |
| 15984 | struct tg3 *tp; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 15985 | int i, err, pm_cap; |
| 15986 | u32 sndmbx, rcvmbx, intmbx; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 15987 | char str[40]; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 15988 | u64 dma_mask, persist_dma_mask; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 15989 | netdev_features_t features = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15990 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 15991 | printk_once(KERN_INFO "%s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15992 | |
| 15993 | err = pci_enable_device(pdev); |
| 15994 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15995 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15996 | return err; |
| 15997 | } |
| 15998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15999 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 16000 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16001 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16002 | goto err_out_disable_pdev; |
| 16003 | } |
| 16004 | |
| 16005 | pci_set_master(pdev); |
| 16006 | |
| 16007 | /* Find power-management capability. */ |
| 16008 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 16009 | if (pm_cap == 0) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16010 | dev_err(&pdev->dev, |
| 16011 | "Cannot find Power Management capability, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16012 | err = -EIO; |
| 16013 | goto err_out_free_res; |
| 16014 | } |
| 16015 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 16016 | err = pci_set_power_state(pdev, PCI_D0); |
| 16017 | if (err) { |
| 16018 | dev_err(&pdev->dev, "Transition to D0 failed, aborting\n"); |
| 16019 | goto err_out_free_res; |
| 16020 | } |
| 16021 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 16022 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16023 | if (!dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16024 | err = -ENOMEM; |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 16025 | goto err_out_power_down; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16026 | } |
| 16027 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16028 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 16029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16030 | tp = netdev_priv(dev); |
| 16031 | tp->pdev = pdev; |
| 16032 | tp->dev = dev; |
| 16033 | tp->pm_cap = pm_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16034 | tp->rx_mode = TG3_DEF_RX_MODE; |
| 16035 | tp->tx_mode = TG3_DEF_TX_MODE; |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 16036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16037 | if (tg3_debug > 0) |
| 16038 | tp->msg_enable = tg3_debug; |
| 16039 | else |
| 16040 | tp->msg_enable = TG3_DEF_MSG_ENABLE; |
| 16041 | |
| 16042 | /* The word/byte swap controls here control register access byte |
| 16043 | * swapping. DMA data byte swapping is controlled in the GRC_MODE |
| 16044 | * setting below. |
| 16045 | */ |
| 16046 | tp->misc_host_ctrl = |
| 16047 | MISC_HOST_CTRL_MASK_PCI_INT | |
| 16048 | MISC_HOST_CTRL_WORD_SWAP | |
| 16049 | MISC_HOST_CTRL_INDIR_ACCESS | |
| 16050 | MISC_HOST_CTRL_PCISTATE_RW; |
| 16051 | |
| 16052 | /* The NONFRM (non-frame) byte/word swap controls take effect |
| 16053 | * on descriptor entries, anything which isn't packet data. |
| 16054 | * |
| 16055 | * The StrongARM chips on the board (one for tx, one for rx) |
| 16056 | * are running in big-endian mode. |
| 16057 | */ |
| 16058 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | |
| 16059 | GRC_MODE_WSWAP_NONFRM_DATA); |
| 16060 | #ifdef __BIG_ENDIAN |
| 16061 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; |
| 16062 | #endif |
| 16063 | spin_lock_init(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16064 | spin_lock_init(&tp->indirect_lock); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 16065 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16066 | |
Matt Carlson | d5fe488 | 2008-11-21 17:20:32 -0800 | [diff] [blame] | 16067 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 16068 | if (!tp->regs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16069 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16070 | err = -ENOMEM; |
| 16071 | goto err_out_free_dev; |
| 16072 | } |
| 16073 | |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16074 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 16075 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761E || |
| 16076 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S || |
| 16077 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761SE || |
| 16078 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 16079 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C || |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16080 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 16081 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
| 16082 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720) { |
| 16083 | tg3_flag_set(tp, ENABLE_APE); |
| 16084 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
| 16085 | if (!tp->aperegs) { |
| 16086 | dev_err(&pdev->dev, |
| 16087 | "Cannot map APE registers, aborting\n"); |
| 16088 | err = -ENOMEM; |
| 16089 | goto err_out_iounmap; |
| 16090 | } |
| 16091 | } |
| 16092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16093 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
| 16094 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16096 | dev->ethtool_ops = &tg3_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16097 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 16098 | dev->netdev_ops = &tg3_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16099 | dev->irq = pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16100 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 16101 | err = tg3_get_invariants(tp, ent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16102 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16103 | dev_err(&pdev->dev, |
| 16104 | "Problem fetching invariants of chip, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16105 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16106 | } |
| 16107 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 16108 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
| 16109 | * device behind the EPB cannot support DMA addresses > 40-bit. |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16110 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
| 16111 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and |
| 16112 | * do DMA address check in tg3_start_xmit(). |
| 16113 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16114 | if (tg3_flag(tp, IS_5788)) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 16115 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16116 | else if (tg3_flag(tp, 40BIT_DMA_BUG)) { |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 16117 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16118 | #ifdef CONFIG_HIGHMEM |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 16119 | dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16120 | #endif |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 16121 | } else |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 16122 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16123 | |
| 16124 | /* Configure DMA attributes. */ |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 16125 | if (dma_mask > DMA_BIT_MASK(32)) { |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16126 | err = pci_set_dma_mask(pdev, dma_mask); |
| 16127 | if (!err) { |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16128 | features |= NETIF_F_HIGHDMA; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16129 | err = pci_set_consistent_dma_mask(pdev, |
| 16130 | persist_dma_mask); |
| 16131 | if (err < 0) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16132 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
| 16133 | "DMA for consistent allocations\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16134 | goto err_out_apeunmap; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16135 | } |
| 16136 | } |
| 16137 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 16138 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
| 16139 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16140 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16141 | dev_err(&pdev->dev, |
| 16142 | "No usable DMA configuration, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16143 | goto err_out_apeunmap; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16144 | } |
| 16145 | } |
| 16146 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 16147 | tg3_init_bufmgr_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16148 | |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16149 | features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 16150 | |
| 16151 | /* 5700 B0 chips do not support checksumming correctly due |
| 16152 | * to hardware bugs. |
| 16153 | */ |
| 16154 | if (tp->pci_chip_rev_id != CHIPREV_ID_5700_B0) { |
| 16155 | features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
| 16156 | |
| 16157 | if (tg3_flag(tp, 5755_PLUS)) |
| 16158 | features |= NETIF_F_IPV6_CSUM; |
| 16159 | } |
| 16160 | |
Michael Chan | 4e3a7aa | 2006-03-20 17:47:44 -0800 | [diff] [blame] | 16161 | /* TSO is on by default on chips that support hardware TSO. |
| 16162 | * Firmware TSO on older chips gives lower performance, so it |
| 16163 | * is off by default, but can be enabled using ethtool. |
| 16164 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16165 | if ((tg3_flag(tp, HW_TSO_1) || |
| 16166 | tg3_flag(tp, HW_TSO_2) || |
| 16167 | tg3_flag(tp, HW_TSO_3)) && |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16168 | (features & NETIF_F_IP_CSUM)) |
| 16169 | features |= NETIF_F_TSO; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16170 | 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] | 16171 | if (features & NETIF_F_IPV6_CSUM) |
| 16172 | features |= NETIF_F_TSO6; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16173 | if (tg3_flag(tp, HW_TSO_3) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 16174 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 16175 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 16176 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16177 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 16178 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16179 | features |= NETIF_F_TSO_ECN; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 16180 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16181 | |
Matt Carlson | d542fe2 | 2011-05-19 16:02:43 +0000 | [diff] [blame] | 16182 | dev->features |= features; |
| 16183 | dev->vlan_features |= features; |
| 16184 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 16185 | /* |
| 16186 | * Add loopback capability only for a subset of devices that support |
| 16187 | * MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY |
| 16188 | * loopback for the remaining devices. |
| 16189 | */ |
| 16190 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && |
| 16191 | !tg3_flag(tp, CPMU_PRESENT)) |
| 16192 | /* Add the loopback capability */ |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16193 | features |= NETIF_F_LOOPBACK; |
| 16194 | |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16195 | dev->hw_features |= features; |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 16196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16197 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16198 | !tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16199 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16200 | tg3_flag_set(tp, MAX_RXPEND_64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16201 | tp->rx_pending = 63; |
| 16202 | } |
| 16203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16204 | err = tg3_get_device_address(tp); |
| 16205 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16206 | dev_err(&pdev->dev, |
| 16207 | "Could not obtain valid ethernet address, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16208 | goto err_out_apeunmap; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16209 | } |
| 16210 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 16211 | /* |
| 16212 | * Reset chip in case UNDI or EFI driver did not shutdown |
| 16213 | * DMA self test will enable WDMAC and we'll see (spurious) |
| 16214 | * pending DMA on the PCI bus at that point. |
| 16215 | */ |
| 16216 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
| 16217 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 16218 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
| 16219 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 16220 | } |
| 16221 | |
| 16222 | err = tg3_test_dma(tp); |
| 16223 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16224 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 16225 | goto err_out_apeunmap; |
| 16226 | } |
| 16227 | |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16228 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
| 16229 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; |
| 16230 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 16231 | for (i = 0; i < tp->irq_max; i++) { |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16232 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 16233 | |
| 16234 | tnapi->tp = tp; |
| 16235 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; |
| 16236 | |
| 16237 | tnapi->int_mbox = intmbx; |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 16238 | if (i <= 4) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16239 | intmbx += 0x8; |
| 16240 | else |
| 16241 | intmbx += 0x4; |
| 16242 | |
| 16243 | tnapi->consmbox = rcvmbx; |
| 16244 | tnapi->prodmbox = sndmbx; |
| 16245 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 16246 | if (i) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16247 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 16248 | else |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16249 | tnapi->coal_now = HOSTCC_MODE_NOW; |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16250 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16251 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16252 | break; |
| 16253 | |
| 16254 | /* |
| 16255 | * If we support MSIX, we'll be using RSS. If we're using |
| 16256 | * RSS, the first vector only handles link interrupts and the |
| 16257 | * remaining vectors handle rx and tx interrupts. Reuse the |
| 16258 | * mailbox values for the next iteration. The values we setup |
| 16259 | * above are still useful for the single vectored mode. |
| 16260 | */ |
| 16261 | if (!i) |
| 16262 | continue; |
| 16263 | |
| 16264 | rcvmbx += 0x8; |
| 16265 | |
| 16266 | if (sndmbx & 0x4) |
| 16267 | sndmbx -= 0x4; |
| 16268 | else |
| 16269 | sndmbx += 0xc; |
| 16270 | } |
| 16271 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 16272 | tg3_init_coal(tp); |
| 16273 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 16274 | pci_set_drvdata(pdev, dev); |
| 16275 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 16276 | if (tg3_flag(tp, 5717_PLUS)) { |
| 16277 | /* Resume a low-power mode */ |
| 16278 | tg3_frob_aux_power(tp, false); |
| 16279 | } |
| 16280 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16281 | tg3_timer_init(tp); |
| 16282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16283 | err = register_netdev(dev); |
| 16284 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16285 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16286 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16287 | } |
| 16288 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 16289 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
| 16290 | tp->board_part_number, |
| 16291 | tp->pci_chip_rev_id, |
| 16292 | tg3_bus_string(tp, str), |
| 16293 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16294 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16295 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 16296 | struct phy_device *phydev; |
| 16297 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 16298 | netdev_info(dev, |
| 16299 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 16300 | phydev->drv->name, dev_name(&phydev->dev)); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16301 | } else { |
| 16302 | char *ethtype; |
| 16303 | |
| 16304 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 16305 | ethtype = "10/100Base-TX"; |
| 16306 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 16307 | ethtype = "1000Base-SX"; |
| 16308 | else |
| 16309 | ethtype = "10/100/1000Base-T"; |
| 16310 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 16311 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 16312 | "(WireSpeed[%d], EEE[%d])\n", |
| 16313 | tg3_phy_string(tp), ethtype, |
| 16314 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0, |
| 16315 | (tp->phy_flags & TG3_PHYFLG_EEE_CAP) != 0); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16316 | } |
Matt Carlson | df59c94 | 2008-11-03 16:52:56 -0800 | [diff] [blame] | 16317 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 16318 | 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] | 16319 | (dev->features & NETIF_F_RXCSUM) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16320 | tg3_flag(tp, USE_LINKCHG_REG) != 0, |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16321 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16322 | tg3_flag(tp, ENABLE_ASF) != 0, |
| 16323 | tg3_flag(tp, TSO_CAPABLE) != 0); |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 16324 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
| 16325 | tp->dma_rwctrl, |
| 16326 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : |
| 16327 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16328 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16329 | pci_save_state(pdev); |
| 16330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16331 | return 0; |
| 16332 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16333 | err_out_apeunmap: |
| 16334 | if (tp->aperegs) { |
| 16335 | iounmap(tp->aperegs); |
| 16336 | tp->aperegs = NULL; |
| 16337 | } |
| 16338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16339 | err_out_iounmap: |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16340 | if (tp->regs) { |
| 16341 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 16342 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16344 | |
| 16345 | err_out_free_dev: |
| 16346 | free_netdev(dev); |
| 16347 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 16348 | err_out_power_down: |
| 16349 | pci_set_power_state(pdev, PCI_D3hot); |
| 16350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16351 | err_out_free_res: |
| 16352 | pci_release_regions(pdev); |
| 16353 | |
| 16354 | err_out_disable_pdev: |
| 16355 | pci_disable_device(pdev); |
| 16356 | pci_set_drvdata(pdev, NULL); |
| 16357 | return err; |
| 16358 | } |
| 16359 | |
| 16360 | static void __devexit tg3_remove_one(struct pci_dev *pdev) |
| 16361 | { |
| 16362 | struct net_device *dev = pci_get_drvdata(pdev); |
| 16363 | |
| 16364 | if (dev) { |
| 16365 | struct tg3 *tp = netdev_priv(dev); |
| 16366 | |
Jesper Juhl | e3c5530 | 2012-04-09 22:50:15 +0200 | [diff] [blame] | 16367 | release_firmware(tp->fw); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 16368 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 16369 | tg3_reset_task_cancel(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 16370 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 16371 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16372 | tg3_phy_fini(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 16373 | tg3_mdio_fini(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16374 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 16375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16376 | unregister_netdev(dev); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16377 | if (tp->aperegs) { |
| 16378 | iounmap(tp->aperegs); |
| 16379 | tp->aperegs = NULL; |
| 16380 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16381 | if (tp->regs) { |
| 16382 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 16383 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16384 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16385 | free_netdev(dev); |
| 16386 | pci_release_regions(pdev); |
| 16387 | pci_disable_device(pdev); |
| 16388 | pci_set_drvdata(pdev, NULL); |
| 16389 | } |
| 16390 | } |
| 16391 | |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 16392 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16393 | static int tg3_suspend(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16394 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16395 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16396 | struct net_device *dev = pci_get_drvdata(pdev); |
| 16397 | struct tg3 *tp = netdev_priv(dev); |
| 16398 | int err; |
| 16399 | |
| 16400 | if (!netif_running(dev)) |
| 16401 | return 0; |
| 16402 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 16403 | tg3_reset_task_cancel(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16404 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16405 | tg3_netif_stop(tp); |
| 16406 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16407 | tg3_timer_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16408 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16409 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16410 | tg3_disable_ints(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16411 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16412 | |
| 16413 | netif_device_detach(dev); |
| 16414 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16415 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 16416 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16417 | tg3_flag_clear(tp, INIT_COMPLETE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16418 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16419 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16420 | err = tg3_power_down_prepare(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16421 | if (err) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16422 | int err2; |
| 16423 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16424 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16425 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16426 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16427 | err2 = tg3_restart_hw(tp, 1); |
| 16428 | if (err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16429 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16430 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16431 | tg3_timer_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16432 | |
| 16433 | netif_device_attach(dev); |
| 16434 | tg3_netif_start(tp); |
| 16435 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16436 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16437 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16438 | |
| 16439 | if (!err2) |
| 16440 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16441 | } |
| 16442 | |
| 16443 | return err; |
| 16444 | } |
| 16445 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16446 | static int tg3_resume(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16447 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16448 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16449 | struct net_device *dev = pci_get_drvdata(pdev); |
| 16450 | struct tg3 *tp = netdev_priv(dev); |
| 16451 | int err; |
| 16452 | |
| 16453 | if (!netif_running(dev)) |
| 16454 | return 0; |
| 16455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16456 | netif_device_attach(dev); |
| 16457 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16458 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16459 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16460 | tg3_flag_set(tp, INIT_COMPLETE); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16461 | err = tg3_restart_hw(tp, 1); |
| 16462 | if (err) |
| 16463 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16464 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16465 | tg3_timer_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16467 | tg3_netif_start(tp); |
| 16468 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16469 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16470 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16471 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16472 | if (!err) |
| 16473 | tg3_phy_start(tp); |
| 16474 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16475 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16476 | } |
| 16477 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16478 | static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 16479 | #define TG3_PM_OPS (&tg3_pm_ops) |
| 16480 | |
| 16481 | #else |
| 16482 | |
| 16483 | #define TG3_PM_OPS NULL |
| 16484 | |
| 16485 | #endif /* CONFIG_PM_SLEEP */ |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16486 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16487 | /** |
| 16488 | * tg3_io_error_detected - called when PCI error is detected |
| 16489 | * @pdev: Pointer to PCI device |
| 16490 | * @state: The current pci connection state |
| 16491 | * |
| 16492 | * This function is called after a PCI bus error affecting |
| 16493 | * this device has been detected. |
| 16494 | */ |
| 16495 | static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, |
| 16496 | pci_channel_state_t state) |
| 16497 | { |
| 16498 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 16499 | struct tg3 *tp = netdev_priv(netdev); |
| 16500 | pci_ers_result_t err = PCI_ERS_RESULT_NEED_RESET; |
| 16501 | |
| 16502 | netdev_info(netdev, "PCI I/O error detected\n"); |
| 16503 | |
| 16504 | rtnl_lock(); |
| 16505 | |
| 16506 | if (!netif_running(netdev)) |
| 16507 | goto done; |
| 16508 | |
| 16509 | tg3_phy_stop(tp); |
| 16510 | |
| 16511 | tg3_netif_stop(tp); |
| 16512 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16513 | tg3_timer_stop(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16514 | |
| 16515 | /* Want to make sure that the reset task doesn't run */ |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 16516 | tg3_reset_task_cancel(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16517 | |
| 16518 | netif_device_detach(netdev); |
| 16519 | |
| 16520 | /* Clean up software state, even if MMIO is blocked */ |
| 16521 | tg3_full_lock(tp, 0); |
| 16522 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 16523 | tg3_full_unlock(tp); |
| 16524 | |
| 16525 | done: |
| 16526 | if (state == pci_channel_io_perm_failure) |
| 16527 | err = PCI_ERS_RESULT_DISCONNECT; |
| 16528 | else |
| 16529 | pci_disable_device(pdev); |
| 16530 | |
| 16531 | rtnl_unlock(); |
| 16532 | |
| 16533 | return err; |
| 16534 | } |
| 16535 | |
| 16536 | /** |
| 16537 | * tg3_io_slot_reset - called after the pci bus has been reset. |
| 16538 | * @pdev: Pointer to PCI device |
| 16539 | * |
| 16540 | * Restart the card from scratch, as if from a cold-boot. |
| 16541 | * At this point, the card has exprienced a hard reset, |
| 16542 | * followed by fixups by BIOS, and has its config space |
| 16543 | * set up identically to what it was at cold boot. |
| 16544 | */ |
| 16545 | static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev) |
| 16546 | { |
| 16547 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 16548 | struct tg3 *tp = netdev_priv(netdev); |
| 16549 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 16550 | int err; |
| 16551 | |
| 16552 | rtnl_lock(); |
| 16553 | |
| 16554 | if (pci_enable_device(pdev)) { |
| 16555 | netdev_err(netdev, "Cannot re-enable PCI device after reset.\n"); |
| 16556 | goto done; |
| 16557 | } |
| 16558 | |
| 16559 | pci_set_master(pdev); |
| 16560 | pci_restore_state(pdev); |
| 16561 | pci_save_state(pdev); |
| 16562 | |
| 16563 | if (!netif_running(netdev)) { |
| 16564 | rc = PCI_ERS_RESULT_RECOVERED; |
| 16565 | goto done; |
| 16566 | } |
| 16567 | |
| 16568 | err = tg3_power_up(tp); |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 16569 | if (err) |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16570 | goto done; |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16571 | |
| 16572 | rc = PCI_ERS_RESULT_RECOVERED; |
| 16573 | |
| 16574 | done: |
| 16575 | rtnl_unlock(); |
| 16576 | |
| 16577 | return rc; |
| 16578 | } |
| 16579 | |
| 16580 | /** |
| 16581 | * tg3_io_resume - called when traffic can start flowing again. |
| 16582 | * @pdev: Pointer to PCI device |
| 16583 | * |
| 16584 | * This callback is called when the error recovery driver tells |
| 16585 | * us that its OK to resume normal operation. |
| 16586 | */ |
| 16587 | static void tg3_io_resume(struct pci_dev *pdev) |
| 16588 | { |
| 16589 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 16590 | struct tg3 *tp = netdev_priv(netdev); |
| 16591 | int err; |
| 16592 | |
| 16593 | rtnl_lock(); |
| 16594 | |
| 16595 | if (!netif_running(netdev)) |
| 16596 | goto done; |
| 16597 | |
| 16598 | tg3_full_lock(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16599 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16600 | err = tg3_restart_hw(tp, 1); |
| 16601 | tg3_full_unlock(tp); |
| 16602 | if (err) { |
| 16603 | netdev_err(netdev, "Cannot restart hardware after reset.\n"); |
| 16604 | goto done; |
| 16605 | } |
| 16606 | |
| 16607 | netif_device_attach(netdev); |
| 16608 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16609 | tg3_timer_start(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16610 | |
| 16611 | tg3_netif_start(tp); |
| 16612 | |
| 16613 | tg3_phy_start(tp); |
| 16614 | |
| 16615 | done: |
| 16616 | rtnl_unlock(); |
| 16617 | } |
| 16618 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 16619 | static const struct pci_error_handlers tg3_err_handler = { |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16620 | .error_detected = tg3_io_error_detected, |
| 16621 | .slot_reset = tg3_io_slot_reset, |
| 16622 | .resume = tg3_io_resume |
| 16623 | }; |
| 16624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16625 | static struct pci_driver tg3_driver = { |
| 16626 | .name = DRV_MODULE_NAME, |
| 16627 | .id_table = tg3_pci_tbl, |
| 16628 | .probe = tg3_init_one, |
| 16629 | .remove = __devexit_p(tg3_remove_one), |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16630 | .err_handler = &tg3_err_handler, |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 16631 | .driver.pm = TG3_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16632 | }; |
| 16633 | |
| 16634 | static int __init tg3_init(void) |
| 16635 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 16636 | return pci_register_driver(&tg3_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16637 | } |
| 16638 | |
| 16639 | static void __exit tg3_cleanup(void) |
| 16640 | { |
| 16641 | pci_unregister_driver(&tg3_driver); |
| 16642 | } |
| 16643 | |
| 16644 | module_init(tg3_init); |
| 16645 | module_exit(tg3_cleanup); |