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. |
Nithin Nayak Sujir | b681b65 | 2013-01-06 12:51:10 +0000 | [diff] [blame] | 7 | * Copyright (C) 2005-2013 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 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 57 | #include <uapi/linux/net_tstamp.h> |
| 58 | #include <linux/ptp_clock_kernel.h> |
| 59 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 60 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include <asm/idprom.h> |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 62 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #endif |
| 64 | |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 65 | #define BAR_0 0 |
| 66 | #define BAR_2 2 |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include "tg3.h" |
| 69 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 70 | /* Functions & macros to verify TG3_FLAGS types */ |
| 71 | |
| 72 | static inline int _tg3_flag(enum TG3_FLAGS flag, unsigned long *bits) |
| 73 | { |
| 74 | return test_bit(flag, bits); |
| 75 | } |
| 76 | |
| 77 | static inline void _tg3_flag_set(enum TG3_FLAGS flag, unsigned long *bits) |
| 78 | { |
| 79 | set_bit(flag, bits); |
| 80 | } |
| 81 | |
| 82 | static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits) |
| 83 | { |
| 84 | clear_bit(flag, bits); |
| 85 | } |
| 86 | |
| 87 | #define tg3_flag(tp, flag) \ |
| 88 | _tg3_flag(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 89 | #define tg3_flag_set(tp, flag) \ |
| 90 | _tg3_flag_set(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 91 | #define tg3_flag_clear(tp, flag) \ |
| 92 | _tg3_flag_clear(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #define DRV_MODULE_NAME "tg3" |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 95 | #define TG3_MAJ_NUM 3 |
Nithin Nayak Sujir | b681b65 | 2013-01-06 12:51:10 +0000 | [diff] [blame] | 96 | #define TG3_MIN_NUM 129 |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 97 | #define DRV_MODULE_VERSION \ |
| 98 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) |
Nithin Nayak Sujir | b681b65 | 2013-01-06 12:51:10 +0000 | [diff] [blame] | 99 | #define DRV_MODULE_RELDATE "January 06, 2013" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 101 | #define RESET_KIND_SHUTDOWN 0 |
| 102 | #define RESET_KIND_INIT 1 |
| 103 | #define RESET_KIND_SUSPEND 2 |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | #define TG3_DEF_RX_MODE 0 |
| 106 | #define TG3_DEF_TX_MODE 0 |
| 107 | #define TG3_DEF_MSG_ENABLE \ |
| 108 | (NETIF_MSG_DRV | \ |
| 109 | NETIF_MSG_PROBE | \ |
| 110 | NETIF_MSG_LINK | \ |
| 111 | NETIF_MSG_TIMER | \ |
| 112 | NETIF_MSG_IFDOWN | \ |
| 113 | NETIF_MSG_IFUP | \ |
| 114 | NETIF_MSG_RX_ERR | \ |
| 115 | NETIF_MSG_TX_ERR) |
| 116 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 117 | #define TG3_GRC_LCLCTL_PWRSW_DELAY 100 |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* length of time before we decide the hardware is borked, |
| 120 | * and dev->tx_timeout() should be called to fix the problem |
| 121 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | #define TG3_TX_TIMEOUT (5 * HZ) |
| 124 | |
| 125 | /* hardware minimum and maximum for a single frame's data payload */ |
| 126 | #define TG3_MIN_MTU 60 |
| 127 | #define TG3_MAX_MTU(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 128 | (tg3_flag(tp, JUMBO_CAPABLE) ? 9000 : 1500) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | /* These numbers seem to be hard coded in the NIC firmware somehow. |
| 131 | * You can't change the ring sizes, but you can change where you place |
| 132 | * them in the NIC onboard memory. |
| 133 | */ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 134 | #define TG3_RX_STD_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 135 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 136 | TG3_RX_STD_MAX_SIZE_5717 : TG3_RX_STD_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | #define TG3_DEF_RX_RING_PENDING 200 |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 138 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 139 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 140 | TG3_RX_JMB_MAX_SIZE_5717 : TG3_RX_JMB_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
| 142 | |
| 143 | /* Do not place this n-ring entries value into the tp struct itself, |
| 144 | * we really want to expose these constants to GCC so that modulo et |
| 145 | * al. operations are done with shifts and masks instead of with |
| 146 | * hw multiply/modulo instructions. Another solution would be to |
| 147 | * replace things like '% foo' with '& (foo - 1)'. |
| 148 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | #define TG3_TX_RING_SIZE 512 |
| 151 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) |
| 152 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 153 | #define TG3_RX_STD_RING_BYTES(tp) \ |
| 154 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) |
| 155 | #define TG3_RX_JMB_RING_BYTES(tp) \ |
| 156 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) |
| 157 | #define TG3_RX_RCB_RING_BYTES(tp) \ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 158 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
| 160 | TG3_TX_RING_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
| 162 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 163 | #define TG3_DMA_BYTE_ENAB 64 |
| 164 | |
| 165 | #define TG3_RX_STD_DMA_SZ 1536 |
| 166 | #define TG3_RX_JMB_DMA_SZ 9046 |
| 167 | |
| 168 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) |
| 169 | |
| 170 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) |
| 171 | #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] | 172 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 173 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
| 174 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 175 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 176 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
| 177 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 178 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 179 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
| 180 | * that are at least dword aligned when used in PCIX mode. The driver |
| 181 | * works around this bug by double copying the packet. This workaround |
| 182 | * is built into the normal double copy length check for efficiency. |
| 183 | * |
| 184 | * However, the double copy is only necessary on those architectures |
| 185 | * where unaligned memory accesses are inefficient. For those architectures |
| 186 | * where unaligned memory accesses incur little penalty, we can reintegrate |
| 187 | * the 5701 in the normal rx path. Doing so saves a device structure |
| 188 | * dereference by hardcoding the double copy threshold in place. |
| 189 | */ |
| 190 | #define TG3_RX_COPY_THRESHOLD 256 |
| 191 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 192 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD |
| 193 | #else |
| 194 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) |
| 195 | #endif |
| 196 | |
Matt Carlson | 81389f5 | 2011-08-31 11:44:49 +0000 | [diff] [blame] | 197 | #if (NET_IP_ALIGN != 0) |
| 198 | #define TG3_RX_OFFSET(tp) ((tp)->rx_offset) |
| 199 | #else |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 200 | #define TG3_RX_OFFSET(tp) (NET_SKB_PAD) |
Matt Carlson | 81389f5 | 2011-08-31 11:44:49 +0000 | [diff] [blame] | 201 | #endif |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | /* minimum number of free TX descriptors required to wake up TX process */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 204 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 205 | #define TG3_TX_BD_DMA_MAX_2K 2048 |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 206 | #define TG3_TX_BD_DMA_MAX_4K 4096 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 208 | #define TG3_RAW_IP_ALIGN 2 |
| 209 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 210 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 211 | #define TG3_FW_UPDATE_FREQ_SEC (TG3_FW_UPDATE_TIMEOUT_SEC / 2) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 212 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 213 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
| 214 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
| 215 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" |
| 216 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 217 | static char version[] = |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 218 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); |
| 221 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); |
| 222 | MODULE_LICENSE("GPL"); |
| 223 | MODULE_VERSION(DRV_MODULE_VERSION); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 224 | MODULE_FIRMWARE(FIRMWARE_TG3); |
| 225 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); |
| 226 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); |
| 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
| 229 | module_param(tg3_debug, int, 0); |
| 230 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); |
| 231 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 232 | #define TG3_DRV_DATA_FLAG_10_100_ONLY 0x0001 |
| 233 | #define TG3_DRV_DATA_FLAG_5705_10_100 0x0002 |
| 234 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 235 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 236 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
| 237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, |
| 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, |
| 239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, |
| 240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, |
| 241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, |
| 242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, |
| 243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, |
| 244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, |
| 245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, |
| 246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, |
| 247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, |
| 248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, |
| 249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, |
| 250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, |
| 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, |
| 252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, |
| 253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901), |
| 255 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 256 | TG3_DRV_DATA_FLAG_5705_10_100}, |
| 257 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2), |
| 258 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 259 | TG3_DRV_DATA_FLAG_5705_10_100}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 260 | {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] | 261 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F), |
| 262 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 263 | TG3_DRV_DATA_FLAG_5705_10_100}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 264 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 265 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F), |
| 269 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
| 271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, |
| 272 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, |
| 273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F), |
| 275 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
| 277 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, |
| 278 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, |
| 279 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 280 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 281 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
| 282 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 283 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5787M, |
| 284 | PCI_VENDOR_ID_LENOVO, |
| 285 | TG3PCI_SUBDEVICE_ID_LENOVO_5787M), |
| 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_5787M)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 288 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F), |
| 289 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 290 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
| 291 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, |
| 292 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, |
| 293 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, |
| 294 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, |
| 295 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, |
| 296 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 297 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
| 298 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 299 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
| 300 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
Matt Carlson | 6c7af27 | 2007-10-21 16:12:02 -0700 | [diff] [blame] | 301 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 302 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
| 303 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
Matt Carlson | c88e668 | 2008-11-03 16:49:18 -0800 | [diff] [blame] | 304 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
| 305 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, |
Matt Carlson | 2befdce | 2009-08-28 12:28:45 +0000 | [diff] [blame] | 306 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
| 307 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 308 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780, |
| 309 | PCI_VENDOR_ID_AI, TG3PCI_SUBDEVICE_ID_ACER_57780_A), |
| 310 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 311 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780, |
| 312 | PCI_VENDOR_ID_AI, TG3PCI_SUBDEVICE_ID_ACER_57780_B), |
| 313 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 314 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
| 315 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 316 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790), |
| 317 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Matt Carlson | 5e7ccf2 | 2009-08-25 10:08:42 +0000 | [diff] [blame] | 318 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 319 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 320 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717_C)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 321 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
Matt Carlson | b0f7522 | 2010-01-20 16:58:11 +0000 | [diff] [blame] | 322 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
| 323 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, |
| 324 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, |
| 325 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 326 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791), |
| 327 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 328 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795), |
| 329 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 330 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
Matt Carlson | ba1f3c7 | 2011-04-05 14:22:50 +0000 | [diff] [blame] | 331 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, |
Greg KH | 02eca3f | 2012-07-12 15:39:44 +0000 | [diff] [blame] | 332 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57762)}, |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 333 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5762)}, |
| 334 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5725)}, |
| 335 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5727)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 336 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
| 337 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, |
| 338 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, |
| 339 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, |
| 340 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, |
| 341 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, |
| 342 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, |
Meelis Roos | 1dcb14d | 2011-05-25 05:43:47 +0000 | [diff] [blame] | 343 | {PCI_DEVICE(0x10cf, 0x11a2)}, /* Fujitsu 1000base-SX with BCM5703SKHB */ |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 344 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); |
| 348 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 349 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 351 | } ethtool_stats_keys[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | { "rx_octets" }, |
| 353 | { "rx_fragments" }, |
| 354 | { "rx_ucast_packets" }, |
| 355 | { "rx_mcast_packets" }, |
| 356 | { "rx_bcast_packets" }, |
| 357 | { "rx_fcs_errors" }, |
| 358 | { "rx_align_errors" }, |
| 359 | { "rx_xon_pause_rcvd" }, |
| 360 | { "rx_xoff_pause_rcvd" }, |
| 361 | { "rx_mac_ctrl_rcvd" }, |
| 362 | { "rx_xoff_entered" }, |
| 363 | { "rx_frame_too_long_errors" }, |
| 364 | { "rx_jabbers" }, |
| 365 | { "rx_undersize_packets" }, |
| 366 | { "rx_in_length_errors" }, |
| 367 | { "rx_out_length_errors" }, |
| 368 | { "rx_64_or_less_octet_packets" }, |
| 369 | { "rx_65_to_127_octet_packets" }, |
| 370 | { "rx_128_to_255_octet_packets" }, |
| 371 | { "rx_256_to_511_octet_packets" }, |
| 372 | { "rx_512_to_1023_octet_packets" }, |
| 373 | { "rx_1024_to_1522_octet_packets" }, |
| 374 | { "rx_1523_to_2047_octet_packets" }, |
| 375 | { "rx_2048_to_4095_octet_packets" }, |
| 376 | { "rx_4096_to_8191_octet_packets" }, |
| 377 | { "rx_8192_to_9022_octet_packets" }, |
| 378 | |
| 379 | { "tx_octets" }, |
| 380 | { "tx_collisions" }, |
| 381 | |
| 382 | { "tx_xon_sent" }, |
| 383 | { "tx_xoff_sent" }, |
| 384 | { "tx_flow_control" }, |
| 385 | { "tx_mac_errors" }, |
| 386 | { "tx_single_collisions" }, |
| 387 | { "tx_mult_collisions" }, |
| 388 | { "tx_deferred" }, |
| 389 | { "tx_excessive_collisions" }, |
| 390 | { "tx_late_collisions" }, |
| 391 | { "tx_collide_2times" }, |
| 392 | { "tx_collide_3times" }, |
| 393 | { "tx_collide_4times" }, |
| 394 | { "tx_collide_5times" }, |
| 395 | { "tx_collide_6times" }, |
| 396 | { "tx_collide_7times" }, |
| 397 | { "tx_collide_8times" }, |
| 398 | { "tx_collide_9times" }, |
| 399 | { "tx_collide_10times" }, |
| 400 | { "tx_collide_11times" }, |
| 401 | { "tx_collide_12times" }, |
| 402 | { "tx_collide_13times" }, |
| 403 | { "tx_collide_14times" }, |
| 404 | { "tx_collide_15times" }, |
| 405 | { "tx_ucast_packets" }, |
| 406 | { "tx_mcast_packets" }, |
| 407 | { "tx_bcast_packets" }, |
| 408 | { "tx_carrier_sense_errors" }, |
| 409 | { "tx_discards" }, |
| 410 | { "tx_errors" }, |
| 411 | |
| 412 | { "dma_writeq_full" }, |
| 413 | { "dma_write_prioq_full" }, |
| 414 | { "rxbds_empty" }, |
| 415 | { "rx_discards" }, |
| 416 | { "rx_errors" }, |
| 417 | { "rx_threshold_hit" }, |
| 418 | |
| 419 | { "dma_readq_full" }, |
| 420 | { "dma_read_prioq_full" }, |
| 421 | { "tx_comp_queue_full" }, |
| 422 | |
| 423 | { "ring_set_send_prod_index" }, |
| 424 | { "ring_status_update" }, |
| 425 | { "nic_irqs" }, |
| 426 | { "nic_avoided_irqs" }, |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 427 | { "nic_tx_threshold_hit" }, |
| 428 | |
| 429 | { "mbuf_lwm_thresh_hit" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | }; |
| 431 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 432 | #define TG3_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 433 | #define TG3_NVRAM_TEST 0 |
| 434 | #define TG3_LINK_TEST 1 |
| 435 | #define TG3_REGISTER_TEST 2 |
| 436 | #define TG3_MEMORY_TEST 3 |
| 437 | #define TG3_MAC_LOOPB_TEST 4 |
| 438 | #define TG3_PHY_LOOPB_TEST 5 |
| 439 | #define TG3_EXT_LOOPB_TEST 6 |
| 440 | #define TG3_INTERRUPT_TEST 7 |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 441 | |
| 442 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 443 | static const struct { |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 444 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 445 | } ethtool_test_keys[] = { |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 446 | [TG3_NVRAM_TEST] = { "nvram test (online) " }, |
| 447 | [TG3_LINK_TEST] = { "link test (online) " }, |
| 448 | [TG3_REGISTER_TEST] = { "register test (offline)" }, |
| 449 | [TG3_MEMORY_TEST] = { "memory test (offline)" }, |
| 450 | [TG3_MAC_LOOPB_TEST] = { "mac loopback test (offline)" }, |
| 451 | [TG3_PHY_LOOPB_TEST] = { "phy loopback test (offline)" }, |
| 452 | [TG3_EXT_LOOPB_TEST] = { "ext loopback test (offline)" }, |
| 453 | [TG3_INTERRUPT_TEST] = { "interrupt test (offline)" }, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 454 | }; |
| 455 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 456 | #define TG3_NUM_TEST ARRAY_SIZE(ethtool_test_keys) |
| 457 | |
| 458 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 459 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
| 460 | { |
| 461 | writel(val, tp->regs + off); |
| 462 | } |
| 463 | |
| 464 | static u32 tg3_read32(struct tg3 *tp, u32 off) |
| 465 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 466 | return readl(tp->regs + off); |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 469 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
| 470 | { |
| 471 | writel(val, tp->aperegs + off); |
| 472 | } |
| 473 | |
| 474 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) |
| 475 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 476 | return readl(tp->aperegs + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
| 480 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 481 | unsigned long flags; |
| 482 | |
| 483 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 484 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 485 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 486 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) |
| 490 | { |
| 491 | writel(val, tp->regs + off); |
| 492 | readl(tp->regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 495 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
| 496 | { |
| 497 | unsigned long flags; |
| 498 | u32 val; |
| 499 | |
| 500 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 501 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 502 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 503 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 504 | return val; |
| 505 | } |
| 506 | |
| 507 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) |
| 508 | { |
| 509 | unsigned long flags; |
| 510 | |
| 511 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { |
| 512 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + |
| 513 | TG3_64BIT_REG_LOW, val); |
| 514 | return; |
| 515 | } |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 516 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 517 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
| 518 | TG3_64BIT_REG_LOW, val); |
| 519 | return; |
| 520 | } |
| 521 | |
| 522 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 523 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 524 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 525 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 526 | |
| 527 | /* In indirect mode when disabling interrupts, we also need |
| 528 | * to clear the interrupt bit in the GRC local ctrl register. |
| 529 | */ |
| 530 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && |
| 531 | (val == 0x1)) { |
| 532 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, |
| 533 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) |
| 538 | { |
| 539 | unsigned long flags; |
| 540 | u32 val; |
| 541 | |
| 542 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 543 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 544 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 545 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 546 | return val; |
| 547 | } |
| 548 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 549 | /* usec_wait specifies the wait time in usec when writing to certain registers |
| 550 | * where it is unsafe to read back the register without some delay. |
| 551 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. |
| 552 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. |
| 553 | */ |
| 554 | 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] | 555 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 556 | if (tg3_flag(tp, PCIX_TARGET_HWBUG) || tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 557 | /* Non-posted methods */ |
| 558 | tp->write32(tp, off, val); |
| 559 | else { |
| 560 | /* Posted method */ |
| 561 | tg3_write32(tp, off, val); |
| 562 | if (usec_wait) |
| 563 | udelay(usec_wait); |
| 564 | tp->read32(tp, off); |
| 565 | } |
| 566 | /* Wait again after the read for the posted method to guarantee that |
| 567 | * the wait time is met. |
| 568 | */ |
| 569 | if (usec_wait) |
| 570 | udelay(usec_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 573 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
| 574 | { |
| 575 | tp->write32_mbox(tp, off, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 576 | if (!tg3_flag(tp, MBOX_WRITE_REORDER) && !tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 577 | tp->read32_mbox(tp, off); |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 580 | 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] | 581 | { |
| 582 | void __iomem *mbox = tp->regs + off; |
| 583 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 584 | if (tg3_flag(tp, TXD_MBOX_HWBUG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 586 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | readl(mbox); |
| 588 | } |
| 589 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 590 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
| 591 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 592 | return readl(tp->regs + off + GRCMBOX_BASE); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) |
| 596 | { |
| 597 | writel(val, tp->regs + off + GRCMBOX_BASE); |
| 598 | } |
| 599 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 600 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 601 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 602 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
| 603 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) |
| 604 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 605 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 606 | #define tw32(reg, val) tp->write32(tp, reg, val) |
| 607 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) |
| 608 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) |
| 609 | #define tr32(reg) tp->read32(tp, reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
| 611 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) |
| 612 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 613 | unsigned long flags; |
| 614 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 615 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 616 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
| 617 | return; |
| 618 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 619 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 620 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 621 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 622 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 624 | /* Always leave this as zero. */ |
| 625 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 626 | } else { |
| 627 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 628 | tw32_f(TG3PCI_MEM_WIN_DATA, val); |
| 629 | |
| 630 | /* Always leave this as zero. */ |
| 631 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 632 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 633 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
| 637 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 638 | unsigned long flags; |
| 639 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 640 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 641 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
| 642 | *val = 0; |
| 643 | return; |
| 644 | } |
| 645 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 646 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 647 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 648 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 649 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 651 | /* Always leave this as zero. */ |
| 652 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 653 | } else { |
| 654 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 655 | *val = tr32(TG3PCI_MEM_WIN_DATA); |
| 656 | |
| 657 | /* Always leave this as zero. */ |
| 658 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 659 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 660 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 663 | static void tg3_ape_lock_init(struct tg3 *tp) |
| 664 | { |
| 665 | int i; |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 666 | u32 regbase, bit; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 667 | |
| 668 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 669 | regbase = TG3_APE_LOCK_GRANT; |
| 670 | else |
| 671 | regbase = TG3_APE_PER_LOCK_GRANT; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 672 | |
| 673 | /* Make sure the driver hasn't any stale locks. */ |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 674 | for (i = TG3_APE_LOCK_PHY0; i <= TG3_APE_LOCK_GPIO; i++) { |
| 675 | switch (i) { |
| 676 | case TG3_APE_LOCK_PHY0: |
| 677 | case TG3_APE_LOCK_PHY1: |
| 678 | case TG3_APE_LOCK_PHY2: |
| 679 | case TG3_APE_LOCK_PHY3: |
| 680 | bit = APE_LOCK_GRANT_DRIVER; |
| 681 | break; |
| 682 | default: |
| 683 | if (!tp->pci_fn) |
| 684 | bit = APE_LOCK_GRANT_DRIVER; |
| 685 | else |
| 686 | bit = 1 << tp->pci_fn; |
| 687 | } |
| 688 | tg3_ape_write32(tp, regbase + 4 * i, bit); |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | static int tg3_ape_lock(struct tg3 *tp, int locknum) |
| 694 | { |
| 695 | int i, off; |
| 696 | int ret = 0; |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 697 | u32 status, req, gnt, bit; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 698 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 699 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 700 | return 0; |
| 701 | |
| 702 | switch (locknum) { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 703 | case TG3_APE_LOCK_GPIO: |
| 704 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 705 | return 0; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 706 | case TG3_APE_LOCK_GRC: |
| 707 | case TG3_APE_LOCK_MEM: |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 708 | if (!tp->pci_fn) |
| 709 | bit = APE_LOCK_REQ_DRIVER; |
| 710 | else |
| 711 | bit = 1 << tp->pci_fn; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 712 | break; |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 713 | case TG3_APE_LOCK_PHY0: |
| 714 | case TG3_APE_LOCK_PHY1: |
| 715 | case TG3_APE_LOCK_PHY2: |
| 716 | case TG3_APE_LOCK_PHY3: |
| 717 | bit = APE_LOCK_REQ_DRIVER; |
| 718 | break; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 719 | default: |
| 720 | return -EINVAL; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 723 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
| 724 | req = TG3_APE_LOCK_REQ; |
| 725 | gnt = TG3_APE_LOCK_GRANT; |
| 726 | } else { |
| 727 | req = TG3_APE_PER_LOCK_REQ; |
| 728 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 729 | } |
| 730 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 731 | off = 4 * locknum; |
| 732 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 733 | tg3_ape_write32(tp, req + off, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 734 | |
| 735 | /* Wait for up to 1 millisecond to acquire lock. */ |
| 736 | for (i = 0; i < 100; i++) { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 737 | status = tg3_ape_read32(tp, gnt + off); |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 738 | if (status == bit) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 739 | break; |
| 740 | udelay(10); |
| 741 | } |
| 742 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 743 | if (status != bit) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 744 | /* Revoke the lock request. */ |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 745 | tg3_ape_write32(tp, gnt + off, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 746 | ret = -EBUSY; |
| 747 | } |
| 748 | |
| 749 | return ret; |
| 750 | } |
| 751 | |
| 752 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) |
| 753 | { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 754 | u32 gnt, bit; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 755 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 756 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 757 | return; |
| 758 | |
| 759 | switch (locknum) { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 760 | case TG3_APE_LOCK_GPIO: |
| 761 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 762 | return; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 763 | case TG3_APE_LOCK_GRC: |
| 764 | case TG3_APE_LOCK_MEM: |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 765 | if (!tp->pci_fn) |
| 766 | bit = APE_LOCK_GRANT_DRIVER; |
| 767 | else |
| 768 | bit = 1 << tp->pci_fn; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 769 | break; |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 770 | case TG3_APE_LOCK_PHY0: |
| 771 | case TG3_APE_LOCK_PHY1: |
| 772 | case TG3_APE_LOCK_PHY2: |
| 773 | case TG3_APE_LOCK_PHY3: |
| 774 | bit = APE_LOCK_GRANT_DRIVER; |
| 775 | break; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 776 | default: |
| 777 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 780 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 781 | gnt = TG3_APE_LOCK_GRANT; |
| 782 | else |
| 783 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 784 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 785 | tg3_ape_write32(tp, gnt + 4 * locknum, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 788 | static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us) |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 789 | { |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 790 | u32 apedata; |
| 791 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 792 | while (timeout_us) { |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 793 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 794 | return -EBUSY; |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 795 | |
| 796 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 797 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 798 | break; |
| 799 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 800 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 801 | |
| 802 | udelay(10); |
| 803 | timeout_us -= (timeout_us > 10) ? 10 : timeout_us; |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 804 | } |
| 805 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 806 | return timeout_us ? 0 : -EBUSY; |
| 807 | } |
| 808 | |
Matt Carlson | cf8d55a | 2012-07-16 16:24:01 +0000 | [diff] [blame] | 809 | static int tg3_ape_wait_for_event(struct tg3 *tp, u32 timeout_us) |
| 810 | { |
| 811 | u32 i, apedata; |
| 812 | |
| 813 | for (i = 0; i < timeout_us / 10; i++) { |
| 814 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 815 | |
| 816 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 817 | break; |
| 818 | |
| 819 | udelay(10); |
| 820 | } |
| 821 | |
| 822 | return i == timeout_us / 10; |
| 823 | } |
| 824 | |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 825 | static int tg3_ape_scratchpad_read(struct tg3 *tp, u32 *data, u32 base_off, |
| 826 | u32 len) |
Matt Carlson | cf8d55a | 2012-07-16 16:24:01 +0000 | [diff] [blame] | 827 | { |
| 828 | int err; |
| 829 | u32 i, bufoff, msgoff, maxlen, apedata; |
| 830 | |
| 831 | if (!tg3_flag(tp, APE_HAS_NCSI)) |
| 832 | return 0; |
| 833 | |
| 834 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 835 | if (apedata != APE_SEG_SIG_MAGIC) |
| 836 | return -ENODEV; |
| 837 | |
| 838 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 839 | if (!(apedata & APE_FW_STATUS_READY)) |
| 840 | return -EAGAIN; |
| 841 | |
| 842 | bufoff = tg3_ape_read32(tp, TG3_APE_SEG_MSG_BUF_OFF) + |
| 843 | TG3_APE_SHMEM_BASE; |
| 844 | msgoff = bufoff + 2 * sizeof(u32); |
| 845 | maxlen = tg3_ape_read32(tp, TG3_APE_SEG_MSG_BUF_LEN); |
| 846 | |
| 847 | while (len) { |
| 848 | u32 length; |
| 849 | |
| 850 | /* Cap xfer sizes to scratchpad limits. */ |
| 851 | length = (len > maxlen) ? maxlen : len; |
| 852 | len -= length; |
| 853 | |
| 854 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 855 | if (!(apedata & APE_FW_STATUS_READY)) |
| 856 | return -EAGAIN; |
| 857 | |
| 858 | /* Wait for up to 1 msec for APE to service previous event. */ |
| 859 | err = tg3_ape_event_lock(tp, 1000); |
| 860 | if (err) |
| 861 | return err; |
| 862 | |
| 863 | apedata = APE_EVENT_STATUS_DRIVER_EVNT | |
| 864 | APE_EVENT_STATUS_SCRTCHPD_READ | |
| 865 | APE_EVENT_STATUS_EVENT_PENDING; |
| 866 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, apedata); |
| 867 | |
| 868 | tg3_ape_write32(tp, bufoff, base_off); |
| 869 | tg3_ape_write32(tp, bufoff + sizeof(u32), length); |
| 870 | |
| 871 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 872 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 873 | |
| 874 | base_off += length; |
| 875 | |
| 876 | if (tg3_ape_wait_for_event(tp, 30000)) |
| 877 | return -EAGAIN; |
| 878 | |
| 879 | for (i = 0; length; i += 4, length -= 4) { |
| 880 | u32 val = tg3_ape_read32(tp, msgoff + i); |
| 881 | memcpy(data, &val, sizeof(u32)); |
| 882 | data++; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | return 0; |
| 887 | } |
| 888 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 889 | static int tg3_ape_send_event(struct tg3 *tp, u32 event) |
| 890 | { |
| 891 | int err; |
| 892 | u32 apedata; |
| 893 | |
| 894 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 895 | if (apedata != APE_SEG_SIG_MAGIC) |
| 896 | return -EAGAIN; |
| 897 | |
| 898 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 899 | if (!(apedata & APE_FW_STATUS_READY)) |
| 900 | return -EAGAIN; |
| 901 | |
| 902 | /* Wait for up to 1 millisecond for APE to service previous event. */ |
| 903 | err = tg3_ape_event_lock(tp, 1000); |
| 904 | if (err) |
| 905 | return err; |
| 906 | |
| 907 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
| 908 | event | APE_EVENT_STATUS_EVENT_PENDING); |
| 909 | |
| 910 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 911 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 912 | |
| 913 | return 0; |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
| 917 | { |
| 918 | u32 event; |
| 919 | u32 apedata; |
| 920 | |
| 921 | if (!tg3_flag(tp, ENABLE_APE)) |
| 922 | return; |
| 923 | |
| 924 | switch (kind) { |
| 925 | case RESET_KIND_INIT: |
| 926 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, |
| 927 | APE_HOST_SEG_SIG_MAGIC); |
| 928 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, |
| 929 | APE_HOST_SEG_LEN_MAGIC); |
| 930 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); |
| 931 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); |
| 932 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, |
| 933 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
| 934 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
| 935 | APE_HOST_BEHAV_NO_PHYLOCK); |
| 936 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, |
| 937 | TG3_APE_HOST_DRVR_STATE_START); |
| 938 | |
| 939 | event = APE_EVENT_STATUS_STATE_START; |
| 940 | break; |
| 941 | case RESET_KIND_SHUTDOWN: |
| 942 | /* With the interface we are currently using, |
| 943 | * APE does not track driver state. Wiping |
| 944 | * out the HOST SEGMENT SIGNATURE forces |
| 945 | * the APE to assume OS absent status. |
| 946 | */ |
| 947 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); |
| 948 | |
| 949 | if (device_may_wakeup(&tp->pdev->dev) && |
| 950 | tg3_flag(tp, WOL_ENABLE)) { |
| 951 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, |
| 952 | TG3_APE_HOST_WOL_SPEED_AUTO); |
| 953 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; |
| 954 | } else |
| 955 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; |
| 956 | |
| 957 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); |
| 958 | |
| 959 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
| 960 | break; |
| 961 | case RESET_KIND_SUSPEND: |
| 962 | event = APE_EVENT_STATUS_STATE_SUSPEND; |
| 963 | break; |
| 964 | default: |
| 965 | return; |
| 966 | } |
| 967 | |
| 968 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; |
| 969 | |
| 970 | tg3_ape_send_event(tp, event); |
| 971 | } |
| 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | static void tg3_disable_ints(struct tg3 *tp) |
| 974 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 975 | int i; |
| 976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 978 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 979 | for (i = 0; i < tp->irq_max; i++) |
| 980 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | } |
| 982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | static void tg3_enable_ints(struct tg3 *tp) |
| 984 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 985 | int i; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 986 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 987 | tp->irq_sync = 0; |
| 988 | wmb(); |
| 989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 991 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 992 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 993 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 994 | for (i = 0; i < tp->irq_cnt; i++) { |
| 995 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 996 | |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 997 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 998 | if (tg3_flag(tp, 1SHOT_MSI)) |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 999 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 1000 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 1001 | tp->coal_now |= tnapi->coal_now; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 1002 | } |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 1003 | |
| 1004 | /* Force an initial interrupt */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1005 | if (!tg3_flag(tp, TAGGED_STATUS) && |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 1006 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
| 1007 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 1008 | else |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 1009 | tw32(HOSTCC_MODE, tp->coal_now); |
| 1010 | |
| 1011 | 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] | 1012 | } |
| 1013 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1014 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1015 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1016 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 1017 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1018 | unsigned int work_exists = 0; |
| 1019 | |
| 1020 | /* check for phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1021 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1022 | if (sblk->status & SD_STATUS_LINK_CHG) |
| 1023 | work_exists = 1; |
| 1024 | } |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 1025 | |
| 1026 | /* check for TX work to do */ |
| 1027 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons) |
| 1028 | work_exists = 1; |
| 1029 | |
| 1030 | /* check for RX work to do */ |
| 1031 | if (tnapi->rx_rcb_prod_idx && |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 1032 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1033 | work_exists = 1; |
| 1034 | |
| 1035 | return work_exists; |
| 1036 | } |
| 1037 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1038 | /* tg3_int_reenable |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1039 | * similar to tg3_enable_ints, but it accurately determines whether there |
| 1040 | * is new work pending and can return without flushing the PIO write |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1041 | * which reenables interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1043 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1045 | struct tg3 *tp = tnapi->tp; |
| 1046 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 1047 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | mmiowb(); |
| 1049 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 1050 | /* When doing tagged status, this work check is unnecessary. |
| 1051 | * The last_tag we write above tells the chip which piece of |
| 1052 | * work we've completed. |
| 1053 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1054 | if (!tg3_flag(tp, TAGGED_STATUS) && tg3_has_work(tnapi)) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1055 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 1056 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | static void tg3_switch_clocks(struct tg3 *tp) |
| 1060 | { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 1061 | u32 clock_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | u32 orig_clock_ctrl; |
| 1063 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1064 | if (tg3_flag(tp, CPMU_PRESENT) || tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 1065 | return; |
| 1066 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 1067 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
| 1068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | orig_clock_ctrl = clock_ctrl; |
| 1070 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | |
| 1071 | CLOCK_CTRL_CLKRUN_OENABLE | |
| 1072 | 0x1f); |
| 1073 | tp->pci_clock_ctrl = clock_ctrl; |
| 1074 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1075 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 1077 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1078 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | } |
| 1080 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 1081 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1082 | clock_ctrl | |
| 1083 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), |
| 1084 | 40); |
| 1085 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1086 | clock_ctrl | (CLOCK_CTRL_ALTCLK), |
| 1087 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 1089 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | #define PHY_BUSY_LOOPS 5000 |
| 1093 | |
| 1094 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
| 1095 | { |
| 1096 | u32 frame_val; |
| 1097 | unsigned int loops; |
| 1098 | int ret; |
| 1099 | |
| 1100 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1101 | tw32_f(MAC_MI_MODE, |
| 1102 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 1103 | udelay(80); |
| 1104 | } |
| 1105 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1106 | tg3_ape_lock(tp, tp->phy_ape_lock); |
| 1107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | *val = 0x0; |
| 1109 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1110 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | MI_COM_PHY_ADDR_MASK); |
| 1112 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 1113 | MI_COM_REG_ADDR_MASK); |
| 1114 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | tw32_f(MAC_MI_COM, frame_val); |
| 1117 | |
| 1118 | loops = PHY_BUSY_LOOPS; |
| 1119 | while (loops != 0) { |
| 1120 | udelay(10); |
| 1121 | frame_val = tr32(MAC_MI_COM); |
| 1122 | |
| 1123 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 1124 | udelay(5); |
| 1125 | frame_val = tr32(MAC_MI_COM); |
| 1126 | break; |
| 1127 | } |
| 1128 | loops -= 1; |
| 1129 | } |
| 1130 | |
| 1131 | ret = -EBUSY; |
| 1132 | if (loops != 0) { |
| 1133 | *val = frame_val & MI_COM_DATA_MASK; |
| 1134 | ret = 0; |
| 1135 | } |
| 1136 | |
| 1137 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1138 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1139 | udelay(80); |
| 1140 | } |
| 1141 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1142 | tg3_ape_unlock(tp, tp->phy_ape_lock); |
| 1143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | return ret; |
| 1145 | } |
| 1146 | |
| 1147 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
| 1148 | { |
| 1149 | u32 frame_val; |
| 1150 | unsigned int loops; |
| 1151 | int ret; |
| 1152 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1153 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 1154 | (reg == MII_CTRL1000 || reg == MII_TG3_AUX_CTRL)) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 1155 | return 0; |
| 1156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1158 | tw32_f(MAC_MI_MODE, |
| 1159 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 1160 | udelay(80); |
| 1161 | } |
| 1162 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1163 | tg3_ape_lock(tp, tp->phy_ape_lock); |
| 1164 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1165 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | MI_COM_PHY_ADDR_MASK); |
| 1167 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 1168 | MI_COM_REG_ADDR_MASK); |
| 1169 | frame_val |= (val & MI_COM_DATA_MASK); |
| 1170 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | tw32_f(MAC_MI_COM, frame_val); |
| 1173 | |
| 1174 | loops = PHY_BUSY_LOOPS; |
| 1175 | while (loops != 0) { |
| 1176 | udelay(10); |
| 1177 | frame_val = tr32(MAC_MI_COM); |
| 1178 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 1179 | udelay(5); |
| 1180 | frame_val = tr32(MAC_MI_COM); |
| 1181 | break; |
| 1182 | } |
| 1183 | loops -= 1; |
| 1184 | } |
| 1185 | |
| 1186 | ret = -EBUSY; |
| 1187 | if (loops != 0) |
| 1188 | ret = 0; |
| 1189 | |
| 1190 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1191 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1192 | udelay(80); |
| 1193 | } |
| 1194 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1195 | tg3_ape_unlock(tp, tp->phy_ape_lock); |
| 1196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | return ret; |
| 1198 | } |
| 1199 | |
Matt Carlson | b0988c1 | 2011-04-20 07:57:39 +0000 | [diff] [blame] | 1200 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
| 1201 | { |
| 1202 | int err; |
| 1203 | |
| 1204 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1205 | if (err) |
| 1206 | goto done; |
| 1207 | |
| 1208 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1209 | if (err) |
| 1210 | goto done; |
| 1211 | |
| 1212 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1213 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1214 | if (err) |
| 1215 | goto done; |
| 1216 | |
| 1217 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1218 | |
| 1219 | done: |
| 1220 | return err; |
| 1221 | } |
| 1222 | |
| 1223 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) |
| 1224 | { |
| 1225 | int err; |
| 1226 | |
| 1227 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1228 | if (err) |
| 1229 | goto done; |
| 1230 | |
| 1231 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1232 | if (err) |
| 1233 | goto done; |
| 1234 | |
| 1235 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1236 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1237 | if (err) |
| 1238 | goto done; |
| 1239 | |
| 1240 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1241 | |
| 1242 | done: |
| 1243 | return err; |
| 1244 | } |
| 1245 | |
| 1246 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) |
| 1247 | { |
| 1248 | int err; |
| 1249 | |
| 1250 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1251 | if (!err) |
| 1252 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1253 | |
| 1254 | return err; |
| 1255 | } |
| 1256 | |
| 1257 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
| 1258 | { |
| 1259 | int err; |
| 1260 | |
| 1261 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1262 | if (!err) |
| 1263 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1264 | |
| 1265 | return err; |
| 1266 | } |
| 1267 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 1268 | static int tg3_phy_auxctl_read(struct tg3 *tp, int reg, u32 *val) |
| 1269 | { |
| 1270 | int err; |
| 1271 | |
| 1272 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 1273 | (reg << MII_TG3_AUXCTL_MISC_RDSEL_SHIFT) | |
| 1274 | MII_TG3_AUXCTL_SHDWSEL_MISC); |
| 1275 | if (!err) |
| 1276 | err = tg3_readphy(tp, MII_TG3_AUX_CTRL, val); |
| 1277 | |
| 1278 | return err; |
| 1279 | } |
| 1280 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 1281 | static int tg3_phy_auxctl_write(struct tg3 *tp, int reg, u32 set) |
| 1282 | { |
| 1283 | if (reg == MII_TG3_AUXCTL_SHDWSEL_MISC) |
| 1284 | set |= MII_TG3_AUXCTL_MISC_WREN; |
| 1285 | |
| 1286 | return tg3_writephy(tp, MII_TG3_AUX_CTRL, set | reg); |
| 1287 | } |
| 1288 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 1289 | #define TG3_PHY_AUXCTL_SMDSP_ENABLE(tp) \ |
| 1290 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ |
| 1291 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | \ |
| 1292 | MII_TG3_AUXCTL_ACTL_TX_6DB) |
| 1293 | |
| 1294 | #define TG3_PHY_AUXCTL_SMDSP_DISABLE(tp) \ |
| 1295 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ |
| 1296 | MII_TG3_AUXCTL_ACTL_TX_6DB); |
| 1297 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1298 | static int tg3_bmcr_reset(struct tg3 *tp) |
| 1299 | { |
| 1300 | u32 phy_control; |
| 1301 | int limit, err; |
| 1302 | |
| 1303 | /* OK, reset it, and poll the BMCR_RESET bit until it |
| 1304 | * clears or we time out. |
| 1305 | */ |
| 1306 | phy_control = BMCR_RESET; |
| 1307 | err = tg3_writephy(tp, MII_BMCR, phy_control); |
| 1308 | if (err != 0) |
| 1309 | return -EBUSY; |
| 1310 | |
| 1311 | limit = 5000; |
| 1312 | while (limit--) { |
| 1313 | err = tg3_readphy(tp, MII_BMCR, &phy_control); |
| 1314 | if (err != 0) |
| 1315 | return -EBUSY; |
| 1316 | |
| 1317 | if ((phy_control & BMCR_RESET) == 0) { |
| 1318 | udelay(40); |
| 1319 | break; |
| 1320 | } |
| 1321 | udelay(10); |
| 1322 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 1323 | if (limit < 0) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1324 | return -EBUSY; |
| 1325 | |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1329 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
| 1330 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1331 | struct tg3 *tp = bp->priv; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1332 | u32 val; |
| 1333 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1334 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1335 | |
| 1336 | if (tg3_readphy(tp, reg, &val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1337 | val = -EIO; |
| 1338 | |
| 1339 | spin_unlock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1340 | |
| 1341 | return val; |
| 1342 | } |
| 1343 | |
| 1344 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) |
| 1345 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1346 | struct tg3 *tp = bp->priv; |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1347 | u32 ret = 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1348 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1349 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1350 | |
| 1351 | if (tg3_writephy(tp, reg, val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1352 | ret = -EIO; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1353 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1354 | spin_unlock_bh(&tp->lock); |
| 1355 | |
| 1356 | return ret; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | static int tg3_mdio_reset(struct mii_bus *bp) |
| 1360 | { |
| 1361 | return 0; |
| 1362 | } |
| 1363 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1364 | static void tg3_mdio_config_5785(struct tg3 *tp) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1365 | { |
| 1366 | u32 val; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1367 | struct phy_device *phydev; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1368 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1369 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1370 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1371 | case PHY_ID_BCM50610: |
| 1372 | case PHY_ID_BCM50610M: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1373 | val = MAC_PHYCFG2_50610_LED_MODES; |
| 1374 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1375 | case PHY_ID_BCMAC131: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1376 | val = MAC_PHYCFG2_AC131_LED_MODES; |
| 1377 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1378 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1379 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
| 1380 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1381 | case PHY_ID_RTL8201E: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1382 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
| 1383 | break; |
| 1384 | default: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1385 | return; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { |
| 1389 | tw32(MAC_PHYCFG2, val); |
| 1390 | |
| 1391 | val = tr32(MAC_PHYCFG1); |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1392 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
| 1393 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); |
| 1394 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1395 | tw32(MAC_PHYCFG1, val); |
| 1396 | |
| 1397 | return; |
| 1398 | } |
| 1399 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1400 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1401 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
| 1402 | MAC_PHYCFG2_FMODE_MASK_MASK | |
| 1403 | MAC_PHYCFG2_GMODE_MASK_MASK | |
| 1404 | MAC_PHYCFG2_ACT_MASK_MASK | |
| 1405 | MAC_PHYCFG2_QUAL_MASK_MASK | |
| 1406 | MAC_PHYCFG2_INBAND_ENABLE; |
| 1407 | |
| 1408 | tw32(MAC_PHYCFG2, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1409 | |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1410 | val = tr32(MAC_PHYCFG1); |
| 1411 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | |
| 1412 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1413 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1414 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1415 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1416 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1417 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
| 1418 | } |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1419 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
| 1420 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; |
| 1421 | tw32(MAC_PHYCFG1, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1422 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1423 | val = tr32(MAC_EXT_RGMII_MODE); |
| 1424 | val &= ~(MAC_RGMII_MODE_RX_INT_B | |
| 1425 | MAC_RGMII_MODE_RX_QUALITY | |
| 1426 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1427 | MAC_RGMII_MODE_RX_ENG_DET | |
| 1428 | MAC_RGMII_MODE_TX_ENABLE | |
| 1429 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1430 | MAC_RGMII_MODE_TX_RESET); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1431 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1432 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1433 | val |= MAC_RGMII_MODE_RX_INT_B | |
| 1434 | MAC_RGMII_MODE_RX_QUALITY | |
| 1435 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1436 | MAC_RGMII_MODE_RX_ENG_DET; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1437 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1438 | val |= MAC_RGMII_MODE_TX_ENABLE | |
| 1439 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1440 | MAC_RGMII_MODE_TX_RESET; |
| 1441 | } |
| 1442 | tw32(MAC_EXT_RGMII_MODE, val); |
| 1443 | } |
| 1444 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1445 | static void tg3_mdio_start(struct tg3 *tp) |
| 1446 | { |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1447 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
| 1448 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1449 | udelay(80); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1450 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1451 | if (tg3_flag(tp, MDIOBUS_INITED) && |
Matt Carlson | 9ea4818 | 2010-02-17 15:17:01 +0000 | [diff] [blame] | 1452 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1453 | tg3_mdio_config_5785(tp); |
| 1454 | } |
| 1455 | |
| 1456 | static int tg3_mdio_init(struct tg3 *tp) |
| 1457 | { |
| 1458 | int i; |
| 1459 | u32 reg; |
| 1460 | struct phy_device *phydev; |
| 1461 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1462 | if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1463 | u32 is_serdes; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1464 | |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 1465 | tp->phy_addr = tp->pci_fn + 1; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1466 | |
Matt Carlson | d1ec96a | 2010-01-12 10:11:38 +0000 | [diff] [blame] | 1467 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
| 1468 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
| 1469 | else |
| 1470 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & |
| 1471 | TG3_CPMU_PHY_STRAP_IS_SERDES; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1472 | if (is_serdes) |
| 1473 | tp->phy_addr += 7; |
| 1474 | } else |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1475 | tp->phy_addr = TG3_PHY_MII_ADDR; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1476 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1477 | tg3_mdio_start(tp); |
| 1478 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1479 | if (!tg3_flag(tp, USE_PHYLIB) || tg3_flag(tp, MDIOBUS_INITED)) |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1480 | return 0; |
| 1481 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1482 | tp->mdio_bus = mdiobus_alloc(); |
| 1483 | if (tp->mdio_bus == NULL) |
| 1484 | return -ENOMEM; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1485 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1486 | tp->mdio_bus->name = "tg3 mdio bus"; |
| 1487 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1488 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1489 | tp->mdio_bus->priv = tp; |
| 1490 | tp->mdio_bus->parent = &tp->pdev->dev; |
| 1491 | tp->mdio_bus->read = &tg3_mdio_read; |
| 1492 | tp->mdio_bus->write = &tg3_mdio_write; |
| 1493 | tp->mdio_bus->reset = &tg3_mdio_reset; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1494 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1495 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1496 | |
| 1497 | for (i = 0; i < PHY_MAX_ADDR; i++) |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1498 | tp->mdio_bus->irq[i] = PHY_POLL; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1499 | |
| 1500 | /* The bus registration will look for all the PHYs on the mdio bus. |
| 1501 | * Unfortunately, it does not ensure the PHY is powered up before |
| 1502 | * accessing the PHY ID registers. A chip reset is the |
| 1503 | * quickest way to bring the device back to an operational state.. |
| 1504 | */ |
| 1505 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
| 1506 | tg3_bmcr_reset(tp); |
| 1507 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1508 | i = mdiobus_register(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1509 | if (i) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1510 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1511 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1512 | return i; |
| 1513 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1514 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1515 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1516 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1517 | if (!phydev || !phydev->drv) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1518 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1519 | mdiobus_unregister(tp->mdio_bus); |
| 1520 | mdiobus_free(tp->mdio_bus); |
| 1521 | return -ENODEV; |
| 1522 | } |
| 1523 | |
| 1524 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1525 | case PHY_ID_BCM57780: |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1526 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1527 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1528 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1529 | case PHY_ID_BCM50610: |
| 1530 | case PHY_ID_BCM50610M: |
Matt Carlson | 32e5a8d | 2009-11-02 14:31:39 +0000 | [diff] [blame] | 1531 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1532 | PHY_BRCM_RX_REFCLK_UNUSED | |
Matt Carlson | 52fae08 | 2009-11-02 14:32:38 +0000 | [diff] [blame] | 1533 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1534 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1535 | if (tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1536 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1537 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1538 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1539 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1540 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1541 | /* fallthru */ |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1542 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1543 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1544 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1545 | case PHY_ID_RTL8201E: |
| 1546 | case PHY_ID_BCMAC131: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1547 | phydev->interface = PHY_INTERFACE_MODE_MII; |
Matt Carlson | cdd4e09d | 2009-11-02 14:31:11 +0000 | [diff] [blame] | 1548 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1549 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1550 | break; |
| 1551 | } |
| 1552 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1553 | tg3_flag_set(tp, MDIOBUS_INITED); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1554 | |
| 1555 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1556 | tg3_mdio_config_5785(tp); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1557 | |
| 1558 | return 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | static void tg3_mdio_fini(struct tg3 *tp) |
| 1562 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1563 | if (tg3_flag(tp, MDIOBUS_INITED)) { |
| 1564 | tg3_flag_clear(tp, MDIOBUS_INITED); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1565 | mdiobus_unregister(tp->mdio_bus); |
| 1566 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1570 | /* tp->lock is held. */ |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1571 | static inline void tg3_generate_fw_event(struct tg3 *tp) |
| 1572 | { |
| 1573 | u32 val; |
| 1574 | |
| 1575 | val = tr32(GRC_RX_CPU_EVENT); |
| 1576 | val |= GRC_RX_CPU_DRIVER_EVENT; |
| 1577 | tw32_f(GRC_RX_CPU_EVENT, val); |
| 1578 | |
| 1579 | tp->last_event_jiffies = jiffies; |
| 1580 | } |
| 1581 | |
| 1582 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 |
| 1583 | |
| 1584 | /* tp->lock is held. */ |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1585 | static void tg3_wait_for_event_ack(struct tg3 *tp) |
| 1586 | { |
| 1587 | int i; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1588 | unsigned int delay_cnt; |
| 1589 | long time_remain; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1590 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1591 | /* If enough time has passed, no wait is necessary. */ |
| 1592 | time_remain = (long)(tp->last_event_jiffies + 1 + |
| 1593 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - |
| 1594 | (long)jiffies; |
| 1595 | if (time_remain < 0) |
| 1596 | return; |
| 1597 | |
| 1598 | /* Check if we can shorten the wait time. */ |
| 1599 | delay_cnt = jiffies_to_usecs(time_remain); |
| 1600 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) |
| 1601 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; |
| 1602 | delay_cnt = (delay_cnt >> 3) + 1; |
| 1603 | |
| 1604 | for (i = 0; i < delay_cnt; i++) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1605 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
| 1606 | break; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1607 | udelay(8); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | /* tp->lock is held. */ |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1612 | static void tg3_phy_gather_ump_data(struct tg3 *tp, u32 *data) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1613 | { |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1614 | u32 reg, val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1615 | |
| 1616 | val = 0; |
| 1617 | if (!tg3_readphy(tp, MII_BMCR, ®)) |
| 1618 | val = reg << 16; |
| 1619 | if (!tg3_readphy(tp, MII_BMSR, ®)) |
| 1620 | val |= (reg & 0xffff); |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1621 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1622 | |
| 1623 | val = 0; |
| 1624 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) |
| 1625 | val = reg << 16; |
| 1626 | if (!tg3_readphy(tp, MII_LPA, ®)) |
| 1627 | val |= (reg & 0xffff); |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1628 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1629 | |
| 1630 | val = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1631 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1632 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
| 1633 | val = reg << 16; |
| 1634 | if (!tg3_readphy(tp, MII_STAT1000, ®)) |
| 1635 | val |= (reg & 0xffff); |
| 1636 | } |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1637 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1638 | |
| 1639 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) |
| 1640 | val = reg << 16; |
| 1641 | else |
| 1642 | val = 0; |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1643 | *data++ = val; |
| 1644 | } |
| 1645 | |
| 1646 | /* tp->lock is held. */ |
| 1647 | static void tg3_ump_link_report(struct tg3 *tp) |
| 1648 | { |
| 1649 | u32 data[4]; |
| 1650 | |
| 1651 | if (!tg3_flag(tp, 5780_CLASS) || !tg3_flag(tp, ENABLE_ASF)) |
| 1652 | return; |
| 1653 | |
| 1654 | tg3_phy_gather_ump_data(tp, data); |
| 1655 | |
| 1656 | tg3_wait_for_event_ack(tp); |
| 1657 | |
| 1658 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); |
| 1659 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); |
| 1660 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x0, data[0]); |
| 1661 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x4, data[1]); |
| 1662 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x8, data[2]); |
| 1663 | 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] | 1664 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1665 | tg3_generate_fw_event(tp); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
Matt Carlson | 8d5a89b | 2011-08-31 11:44:51 +0000 | [diff] [blame] | 1668 | /* tp->lock is held. */ |
| 1669 | static void tg3_stop_fw(struct tg3 *tp) |
| 1670 | { |
| 1671 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
| 1672 | /* Wait for RX cpu to ACK the previous event. */ |
| 1673 | tg3_wait_for_event_ack(tp); |
| 1674 | |
| 1675 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); |
| 1676 | |
| 1677 | tg3_generate_fw_event(tp); |
| 1678 | |
| 1679 | /* Wait for RX cpu to ACK this event. */ |
| 1680 | tg3_wait_for_event_ack(tp); |
| 1681 | } |
| 1682 | } |
| 1683 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 1684 | /* tp->lock is held. */ |
| 1685 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) |
| 1686 | { |
| 1687 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
| 1688 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); |
| 1689 | |
| 1690 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1691 | switch (kind) { |
| 1692 | case RESET_KIND_INIT: |
| 1693 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1694 | DRV_STATE_START); |
| 1695 | break; |
| 1696 | |
| 1697 | case RESET_KIND_SHUTDOWN: |
| 1698 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1699 | DRV_STATE_UNLOAD); |
| 1700 | break; |
| 1701 | |
| 1702 | case RESET_KIND_SUSPEND: |
| 1703 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1704 | DRV_STATE_SUSPEND); |
| 1705 | break; |
| 1706 | |
| 1707 | default: |
| 1708 | break; |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | if (kind == RESET_KIND_INIT || |
| 1713 | kind == RESET_KIND_SUSPEND) |
| 1714 | tg3_ape_driver_state_change(tp, kind); |
| 1715 | } |
| 1716 | |
| 1717 | /* tp->lock is held. */ |
| 1718 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) |
| 1719 | { |
| 1720 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1721 | switch (kind) { |
| 1722 | case RESET_KIND_INIT: |
| 1723 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1724 | DRV_STATE_START_DONE); |
| 1725 | break; |
| 1726 | |
| 1727 | case RESET_KIND_SHUTDOWN: |
| 1728 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1729 | DRV_STATE_UNLOAD_DONE); |
| 1730 | break; |
| 1731 | |
| 1732 | default: |
| 1733 | break; |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | if (kind == RESET_KIND_SHUTDOWN) |
| 1738 | tg3_ape_driver_state_change(tp, kind); |
| 1739 | } |
| 1740 | |
| 1741 | /* tp->lock is held. */ |
| 1742 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) |
| 1743 | { |
| 1744 | if (tg3_flag(tp, ENABLE_ASF)) { |
| 1745 | switch (kind) { |
| 1746 | case RESET_KIND_INIT: |
| 1747 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1748 | DRV_STATE_START); |
| 1749 | break; |
| 1750 | |
| 1751 | case RESET_KIND_SHUTDOWN: |
| 1752 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1753 | DRV_STATE_UNLOAD); |
| 1754 | break; |
| 1755 | |
| 1756 | case RESET_KIND_SUSPEND: |
| 1757 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1758 | DRV_STATE_SUSPEND); |
| 1759 | break; |
| 1760 | |
| 1761 | default: |
| 1762 | break; |
| 1763 | } |
| 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | static int tg3_poll_fw(struct tg3 *tp) |
| 1768 | { |
| 1769 | int i; |
| 1770 | u32 val; |
| 1771 | |
| 1772 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 1773 | /* Wait up to 20ms for init done. */ |
| 1774 | for (i = 0; i < 200; i++) { |
| 1775 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
| 1776 | return 0; |
| 1777 | udelay(100); |
| 1778 | } |
| 1779 | return -ENODEV; |
| 1780 | } |
| 1781 | |
| 1782 | /* Wait for firmware initialization to complete. */ |
| 1783 | for (i = 0; i < 100000; i++) { |
| 1784 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); |
| 1785 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 1786 | break; |
| 1787 | udelay(10); |
| 1788 | } |
| 1789 | |
| 1790 | /* Chip might not be fitted with firmware. Some Sun onboard |
| 1791 | * parts are configured like that. So don't signal the timeout |
| 1792 | * of the above loop as an error, but do report the lack of |
| 1793 | * running firmware once. |
| 1794 | */ |
| 1795 | if (i >= 100000 && !tg3_flag(tp, NO_FWARE_REPORTED)) { |
| 1796 | tg3_flag_set(tp, NO_FWARE_REPORTED); |
| 1797 | |
| 1798 | netdev_info(tp->dev, "No firmware running\n"); |
| 1799 | } |
| 1800 | |
| 1801 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 1802 | /* The 57765 A0 needs a little more |
| 1803 | * time to do some important work. |
| 1804 | */ |
| 1805 | mdelay(10); |
| 1806 | } |
| 1807 | |
| 1808 | return 0; |
| 1809 | } |
| 1810 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1811 | static void tg3_link_report(struct tg3 *tp) |
| 1812 | { |
| 1813 | if (!netif_carrier_ok(tp->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1814 | netif_info(tp, link, tp->dev, "Link is down\n"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1815 | tg3_ump_link_report(tp); |
| 1816 | } else if (netif_msg_link(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1817 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
| 1818 | (tp->link_config.active_speed == SPEED_1000 ? |
| 1819 | 1000 : |
| 1820 | (tp->link_config.active_speed == SPEED_100 ? |
| 1821 | 100 : 10)), |
| 1822 | (tp->link_config.active_duplex == DUPLEX_FULL ? |
| 1823 | "full" : "half")); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1824 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1825 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", |
| 1826 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? |
| 1827 | "on" : "off", |
| 1828 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? |
| 1829 | "on" : "off"); |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 1830 | |
| 1831 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) |
| 1832 | netdev_info(tp->dev, "EEE is %s\n", |
| 1833 | tp->setlpicnt ? "enabled" : "disabled"); |
| 1834 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1835 | tg3_ump_link_report(tp); |
| 1836 | } |
| 1837 | } |
| 1838 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1839 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
| 1840 | { |
| 1841 | u16 miireg; |
| 1842 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1843 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1844 | miireg = ADVERTISE_1000XPAUSE; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1845 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1846 | miireg = ADVERTISE_1000XPSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1847 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1848 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
| 1849 | else |
| 1850 | miireg = 0; |
| 1851 | |
| 1852 | return miireg; |
| 1853 | } |
| 1854 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1855 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
| 1856 | { |
| 1857 | u8 cap = 0; |
| 1858 | |
Matt Carlson | f3791cd | 2011-11-21 15:01:17 +0000 | [diff] [blame] | 1859 | if (lcladv & rmtadv & ADVERTISE_1000XPAUSE) { |
| 1860 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 1861 | } else if (lcladv & rmtadv & ADVERTISE_1000XPSE_ASYM) { |
| 1862 | if (lcladv & ADVERTISE_1000XPAUSE) |
| 1863 | cap = FLOW_CTRL_RX; |
| 1864 | if (rmtadv & ADVERTISE_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1865 | cap = FLOW_CTRL_TX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | return cap; |
| 1869 | } |
| 1870 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1871 | 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] | 1872 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1873 | u8 autoneg; |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1874 | u8 flowctrl = 0; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1875 | u32 old_rx_mode = tp->rx_mode; |
| 1876 | u32 old_tx_mode = tp->tx_mode; |
| 1877 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1878 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1879 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1880 | else |
| 1881 | autoneg = tp->link_config.autoneg; |
| 1882 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1883 | if (autoneg == AUTONEG_ENABLE && tg3_flag(tp, PAUSE_AUTONEG)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1884 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1885 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1886 | else |
Steve Glendinning | bc02ff9 | 2008-12-16 02:00:48 -0800 | [diff] [blame] | 1887 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1888 | } else |
| 1889 | flowctrl = tp->link_config.flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1890 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1891 | tp->link_config.active_flowctrl = flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1892 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1893 | if (flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1894 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
| 1895 | else |
| 1896 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; |
| 1897 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1898 | if (old_rx_mode != tp->rx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1899 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1900 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1901 | if (flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1902 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
| 1903 | else |
| 1904 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; |
| 1905 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1906 | if (old_tx_mode != tp->tx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1907 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1908 | } |
| 1909 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1910 | static void tg3_adjust_link(struct net_device *dev) |
| 1911 | { |
| 1912 | u8 oldflowctrl, linkmesg = 0; |
| 1913 | u32 mac_mode, lcl_adv, rmt_adv; |
| 1914 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1915 | 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] | 1916 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1917 | spin_lock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1918 | |
| 1919 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | |
| 1920 | MAC_MODE_HALF_DUPLEX); |
| 1921 | |
| 1922 | oldflowctrl = tp->link_config.active_flowctrl; |
| 1923 | |
| 1924 | if (phydev->link) { |
| 1925 | lcl_adv = 0; |
| 1926 | rmt_adv = 0; |
| 1927 | |
| 1928 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) |
| 1929 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1930 | else if (phydev->speed == SPEED_1000 || |
| 1931 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1932 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1933 | else |
| 1934 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1935 | |
| 1936 | if (phydev->duplex == DUPLEX_HALF) |
| 1937 | mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 1938 | else { |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 1939 | lcl_adv = mii_advertise_flowctrl( |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1940 | tp->link_config.flowctrl); |
| 1941 | |
| 1942 | if (phydev->pause) |
| 1943 | rmt_adv = LPA_PAUSE_CAP; |
| 1944 | if (phydev->asym_pause) |
| 1945 | rmt_adv |= LPA_PAUSE_ASYM; |
| 1946 | } |
| 1947 | |
| 1948 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 1949 | } else |
| 1950 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 1951 | |
| 1952 | if (mac_mode != tp->mac_mode) { |
| 1953 | tp->mac_mode = mac_mode; |
| 1954 | tw32_f(MAC_MODE, tp->mac_mode); |
| 1955 | udelay(40); |
| 1956 | } |
| 1957 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1958 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
| 1959 | if (phydev->speed == SPEED_10) |
| 1960 | tw32(MAC_MI_STAT, |
| 1961 | MAC_MI_STAT_10MBPS_MODE | |
| 1962 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1963 | else |
| 1964 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1965 | } |
| 1966 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1967 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
| 1968 | tw32(MAC_TX_LENGTHS, |
| 1969 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1970 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1971 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1972 | else |
| 1973 | tw32(MAC_TX_LENGTHS, |
| 1974 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1975 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1976 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1977 | |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 1978 | if (phydev->link != tp->old_link || |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1979 | phydev->speed != tp->link_config.active_speed || |
| 1980 | phydev->duplex != tp->link_config.active_duplex || |
| 1981 | oldflowctrl != tp->link_config.active_flowctrl) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 1982 | linkmesg = 1; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1983 | |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 1984 | tp->old_link = phydev->link; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1985 | tp->link_config.active_speed = phydev->speed; |
| 1986 | tp->link_config.active_duplex = phydev->duplex; |
| 1987 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1988 | spin_unlock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1989 | |
| 1990 | if (linkmesg) |
| 1991 | tg3_link_report(tp); |
| 1992 | } |
| 1993 | |
| 1994 | static int tg3_phy_init(struct tg3 *tp) |
| 1995 | { |
| 1996 | struct phy_device *phydev; |
| 1997 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1998 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1999 | return 0; |
| 2000 | |
| 2001 | /* Bring the PHY back to a known state. */ |
| 2002 | tg3_bmcr_reset(tp); |
| 2003 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2004 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2005 | |
| 2006 | /* Attach the MAC to the PHY. */ |
Florian Fainelli | f9a8f83 | 2013-01-14 00:52:52 +0000 | [diff] [blame^] | 2007 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), |
| 2008 | tg3_adjust_link, phydev->interface); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2009 | if (IS_ERR(phydev)) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 2010 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2011 | return PTR_ERR(phydev); |
| 2012 | } |
| 2013 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2014 | /* Mask with MAC supported features. */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 2015 | switch (phydev->interface) { |
| 2016 | case PHY_INTERFACE_MODE_GMII: |
| 2017 | case PHY_INTERFACE_MODE_RGMII: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2018 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 2019 | phydev->supported &= (PHY_GBIT_FEATURES | |
| 2020 | SUPPORTED_Pause | |
| 2021 | SUPPORTED_Asym_Pause); |
| 2022 | break; |
| 2023 | } |
| 2024 | /* fallthru */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 2025 | case PHY_INTERFACE_MODE_MII: |
| 2026 | phydev->supported &= (PHY_BASIC_FEATURES | |
| 2027 | SUPPORTED_Pause | |
| 2028 | SUPPORTED_Asym_Pause); |
| 2029 | break; |
| 2030 | default: |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2031 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 2032 | return -EINVAL; |
| 2033 | } |
| 2034 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2035 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2036 | |
| 2037 | phydev->advertising = phydev->supported; |
| 2038 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2039 | return 0; |
| 2040 | } |
| 2041 | |
| 2042 | static void tg3_phy_start(struct tg3 *tp) |
| 2043 | { |
| 2044 | struct phy_device *phydev; |
| 2045 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2046 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2047 | return; |
| 2048 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2049 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2050 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2051 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 2052 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 2053 | phydev->speed = tp->link_config.speed; |
| 2054 | phydev->duplex = tp->link_config.duplex; |
| 2055 | phydev->autoneg = tp->link_config.autoneg; |
| 2056 | phydev->advertising = tp->link_config.advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | phy_start(phydev); |
| 2060 | |
| 2061 | phy_start_aneg(phydev); |
| 2062 | } |
| 2063 | |
| 2064 | static void tg3_phy_stop(struct tg3 *tp) |
| 2065 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2066 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2067 | return; |
| 2068 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2069 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | static void tg3_phy_fini(struct tg3 *tp) |
| 2073 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2074 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2075 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2076 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2077 | } |
| 2078 | } |
| 2079 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 2080 | static int tg3_phy_set_extloopbk(struct tg3 *tp) |
| 2081 | { |
| 2082 | int err; |
| 2083 | u32 val; |
| 2084 | |
| 2085 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 2086 | return 0; |
| 2087 | |
| 2088 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
| 2089 | /* Cannot do read-modify-write on 5401 */ |
| 2090 | err = tg3_phy_auxctl_write(tp, |
| 2091 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2092 | MII_TG3_AUXCTL_ACTL_EXTLOOPBK | |
| 2093 | 0x4c20); |
| 2094 | goto done; |
| 2095 | } |
| 2096 | |
| 2097 | err = tg3_phy_auxctl_read(tp, |
| 2098 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2099 | if (err) |
| 2100 | return err; |
| 2101 | |
| 2102 | val |= MII_TG3_AUXCTL_ACTL_EXTLOOPBK; |
| 2103 | err = tg3_phy_auxctl_write(tp, |
| 2104 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, val); |
| 2105 | |
| 2106 | done: |
| 2107 | return err; |
| 2108 | } |
| 2109 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 2110 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
| 2111 | { |
| 2112 | u32 phytest; |
| 2113 | |
| 2114 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2115 | u32 phy; |
| 2116 | |
| 2117 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2118 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2119 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { |
| 2120 | if (enable) |
| 2121 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 2122 | else |
| 2123 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 2124 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); |
| 2125 | } |
| 2126 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2127 | } |
| 2128 | } |
| 2129 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2130 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
| 2131 | { |
| 2132 | u32 reg; |
| 2133 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2134 | if (!tg3_flag(tp, 5705_PLUS) || |
| 2135 | (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2136 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2137 | return; |
| 2138 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2139 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 2140 | tg3_phy_fet_toggle_apd(tp, enable); |
| 2141 | return; |
| 2142 | } |
| 2143 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2144 | reg = MII_TG3_MISC_SHDW_WREN | |
| 2145 | MII_TG3_MISC_SHDW_SCR5_SEL | |
| 2146 | MII_TG3_MISC_SHDW_SCR5_LPED | |
| 2147 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | |
| 2148 | MII_TG3_MISC_SHDW_SCR5_SDTL | |
| 2149 | MII_TG3_MISC_SHDW_SCR5_C125OE; |
| 2150 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) |
| 2151 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
| 2152 | |
| 2153 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 2154 | |
| 2155 | |
| 2156 | reg = MII_TG3_MISC_SHDW_WREN | |
| 2157 | MII_TG3_MISC_SHDW_APD_SEL | |
| 2158 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; |
| 2159 | if (enable) |
| 2160 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; |
| 2161 | |
| 2162 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 2163 | } |
| 2164 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2165 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
| 2166 | { |
| 2167 | u32 phy; |
| 2168 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2169 | if (!tg3_flag(tp, 5705_PLUS) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2170 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2171 | return; |
| 2172 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2173 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2174 | u32 ephy; |
| 2175 | |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2176 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
| 2177 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; |
| 2178 | |
| 2179 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2180 | ephy | MII_TG3_FET_SHADOW_EN); |
| 2181 | if (!tg3_readphy(tp, reg, &phy)) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2182 | if (enable) |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2183 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2184 | else |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2185 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 2186 | tg3_writephy(tp, reg, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2187 | } |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2188 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2189 | } |
| 2190 | } else { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2191 | int ret; |
| 2192 | |
| 2193 | ret = tg3_phy_auxctl_read(tp, |
| 2194 | MII_TG3_AUXCTL_SHDWSEL_MISC, &phy); |
| 2195 | if (!ret) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2196 | if (enable) |
| 2197 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 2198 | else |
| 2199 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2200 | tg3_phy_auxctl_write(tp, |
| 2201 | MII_TG3_AUXCTL_SHDWSEL_MISC, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2202 | } |
| 2203 | } |
| 2204 | } |
| 2205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
| 2207 | { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2208 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | u32 val; |
| 2210 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2211 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | return; |
| 2213 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2214 | ret = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, &val); |
| 2215 | if (!ret) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2216 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, |
| 2217 | val | MII_TG3_AUXCTL_MISC_WIRESPD_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2220 | static void tg3_phy_apply_otp(struct tg3 *tp) |
| 2221 | { |
| 2222 | u32 otp, phy; |
| 2223 | |
| 2224 | if (!tp->phy_otp) |
| 2225 | return; |
| 2226 | |
| 2227 | otp = tp->phy_otp; |
| 2228 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2229 | if (TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) |
| 2230 | return; |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2231 | |
| 2232 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); |
| 2233 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; |
| 2234 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); |
| 2235 | |
| 2236 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | |
| 2237 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); |
| 2238 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); |
| 2239 | |
| 2240 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); |
| 2241 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; |
| 2242 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); |
| 2243 | |
| 2244 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); |
| 2245 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); |
| 2246 | |
| 2247 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); |
| 2248 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); |
| 2249 | |
| 2250 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | |
| 2251 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); |
| 2252 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); |
| 2253 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2254 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2257 | static void tg3_phy_eee_adjust(struct tg3 *tp, u32 current_link_up) |
| 2258 | { |
| 2259 | u32 val; |
| 2260 | |
| 2261 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 2262 | return; |
| 2263 | |
| 2264 | tp->setlpicnt = 0; |
| 2265 | |
| 2266 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 2267 | current_link_up == 1 && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 2268 | tp->link_config.active_duplex == DUPLEX_FULL && |
| 2269 | (tp->link_config.active_speed == SPEED_100 || |
| 2270 | tp->link_config.active_speed == SPEED_1000)) { |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2271 | u32 eeectl; |
| 2272 | |
| 2273 | if (tp->link_config.active_speed == SPEED_1000) |
| 2274 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; |
| 2275 | else |
| 2276 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; |
| 2277 | |
| 2278 | tw32(TG3_CPMU_EEE_CTRL, eeectl); |
| 2279 | |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 2280 | tg3_phy_cl45_read(tp, MDIO_MMD_AN, |
| 2281 | TG3_CL45_D7_EEERES_STAT, &val); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2282 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2283 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
| 2284 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2285 | tp->setlpicnt = 2; |
| 2286 | } |
| 2287 | |
| 2288 | if (!tp->setlpicnt) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2289 | if (current_link_up == 1 && |
| 2290 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2291 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, 0x0000); |
| 2292 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2293 | } |
| 2294 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2295 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2296 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2297 | } |
| 2298 | } |
| 2299 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2300 | static void tg3_phy_eee_enable(struct tg3 *tp) |
| 2301 | { |
| 2302 | u32 val; |
| 2303 | |
| 2304 | if (tp->link_config.active_speed == SPEED_1000 && |
| 2305 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2306 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 2307 | tg3_flag(tp, 57765_CLASS)) && |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2308 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2309 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 2310 | MII_TG3_DSP_TAP26_RMRXSTO; |
| 2311 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2312 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2313 | } |
| 2314 | |
| 2315 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2316 | tw32(TG3_CPMU_EEE_MODE, val | TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2317 | } |
| 2318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | static int tg3_wait_macro_done(struct tg3 *tp) |
| 2320 | { |
| 2321 | int limit = 100; |
| 2322 | |
| 2323 | while (limit--) { |
| 2324 | u32 tmp32; |
| 2325 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2326 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | if ((tmp32 & 0x1000) == 0) |
| 2328 | break; |
| 2329 | } |
| 2330 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 2331 | if (limit < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | return -EBUSY; |
| 2333 | |
| 2334 | return 0; |
| 2335 | } |
| 2336 | |
| 2337 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) |
| 2338 | { |
| 2339 | static const u32 test_pat[4][6] = { |
| 2340 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, |
| 2341 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, |
| 2342 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, |
| 2343 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } |
| 2344 | }; |
| 2345 | int chan; |
| 2346 | |
| 2347 | for (chan = 0; chan < 4; chan++) { |
| 2348 | int i; |
| 2349 | |
| 2350 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2351 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2352 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | |
| 2354 | for (i = 0; i < 6; i++) |
| 2355 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, |
| 2356 | test_pat[chan][i]); |
| 2357 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2358 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | if (tg3_wait_macro_done(tp)) { |
| 2360 | *resetp = 1; |
| 2361 | return -EBUSY; |
| 2362 | } |
| 2363 | |
| 2364 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2365 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2366 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
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 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2372 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | if (tg3_wait_macro_done(tp)) { |
| 2374 | *resetp = 1; |
| 2375 | return -EBUSY; |
| 2376 | } |
| 2377 | |
| 2378 | for (i = 0; i < 6; i += 2) { |
| 2379 | u32 low, high; |
| 2380 | |
| 2381 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || |
| 2382 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || |
| 2383 | tg3_wait_macro_done(tp)) { |
| 2384 | *resetp = 1; |
| 2385 | return -EBUSY; |
| 2386 | } |
| 2387 | low &= 0x7fff; |
| 2388 | high &= 0x000f; |
| 2389 | if (low != test_pat[chan][i] || |
| 2390 | high != test_pat[chan][i+1]) { |
| 2391 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); |
| 2392 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); |
| 2393 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); |
| 2394 | |
| 2395 | return -EBUSY; |
| 2396 | } |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | return 0; |
| 2401 | } |
| 2402 | |
| 2403 | static int tg3_phy_reset_chanpat(struct tg3 *tp) |
| 2404 | { |
| 2405 | int chan; |
| 2406 | |
| 2407 | for (chan = 0; chan < 4; chan++) { |
| 2408 | int i; |
| 2409 | |
| 2410 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2411 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2412 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | for (i = 0; i < 6; i++) |
| 2414 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2415 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | if (tg3_wait_macro_done(tp)) |
| 2417 | return -EBUSY; |
| 2418 | } |
| 2419 | |
| 2420 | return 0; |
| 2421 | } |
| 2422 | |
| 2423 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) |
| 2424 | { |
| 2425 | u32 reg32, phy9_orig; |
| 2426 | int retries, do_phy_reset, err; |
| 2427 | |
| 2428 | retries = 10; |
| 2429 | do_phy_reset = 1; |
| 2430 | do { |
| 2431 | if (do_phy_reset) { |
| 2432 | err = tg3_bmcr_reset(tp); |
| 2433 | if (err) |
| 2434 | return err; |
| 2435 | do_phy_reset = 0; |
| 2436 | } |
| 2437 | |
| 2438 | /* Disable transmitter and interrupt. */ |
| 2439 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) |
| 2440 | continue; |
| 2441 | |
| 2442 | reg32 |= 0x3000; |
| 2443 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2444 | |
| 2445 | /* Set full-duplex, 1000 mbps. */ |
| 2446 | tg3_writephy(tp, MII_BMCR, |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2447 | BMCR_FULLDPLX | BMCR_SPEED1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | |
| 2449 | /* Set to master mode. */ |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2450 | if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | continue; |
| 2452 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2453 | tg3_writephy(tp, MII_CTRL1000, |
| 2454 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2456 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
| 2457 | if (err) |
| 2458 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | |
| 2460 | /* Block the PHY control access. */ |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2461 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | |
| 2463 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); |
| 2464 | if (!err) |
| 2465 | break; |
| 2466 | } while (--retries); |
| 2467 | |
| 2468 | err = tg3_phy_reset_chanpat(tp); |
| 2469 | if (err) |
| 2470 | return err; |
| 2471 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2472 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | |
| 2474 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2475 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2477 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2479 | tg3_writephy(tp, MII_CTRL1000, phy9_orig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | |
| 2481 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { |
| 2482 | reg32 &= ~0x3000; |
| 2483 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2484 | } else if (!err) |
| 2485 | err = -EBUSY; |
| 2486 | |
| 2487 | return err; |
| 2488 | } |
| 2489 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 2490 | static void tg3_carrier_on(struct tg3 *tp) |
| 2491 | { |
| 2492 | netif_carrier_on(tp->dev); |
| 2493 | tp->link_up = true; |
| 2494 | } |
| 2495 | |
| 2496 | static void tg3_carrier_off(struct tg3 *tp) |
| 2497 | { |
| 2498 | netif_carrier_off(tp->dev); |
| 2499 | tp->link_up = false; |
| 2500 | } |
| 2501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | /* This will reset the tigon3 PHY if there is no valid |
| 2503 | * link unless the FORCE argument is non-zero. |
| 2504 | */ |
| 2505 | static int tg3_phy_reset(struct tg3 *tp) |
| 2506 | { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2507 | u32 val, cpmuctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | int err; |
| 2509 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2510 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2511 | val = tr32(GRC_MISC_CFG); |
| 2512 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); |
| 2513 | udelay(40); |
| 2514 | } |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2515 | err = tg3_readphy(tp, MII_BMSR, &val); |
| 2516 | err |= tg3_readphy(tp, MII_BMSR, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | if (err != 0) |
| 2518 | return -EBUSY; |
| 2519 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 2520 | if (netif_running(tp->dev) && tp->link_up) { |
| 2521 | tg3_carrier_off(tp); |
Michael Chan | c8e1e82 | 2006-04-29 18:55:17 -0700 | [diff] [blame] | 2522 | tg3_link_report(tp); |
| 2523 | } |
| 2524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 2526 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2527 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 2528 | err = tg3_phy_reset_5703_4_5(tp); |
| 2529 | if (err) |
| 2530 | return err; |
| 2531 | goto out; |
| 2532 | } |
| 2533 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2534 | cpmuctrl = 0; |
| 2535 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 2536 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 2537 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
| 2538 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) |
| 2539 | tw32(TG3_CPMU_CTRL, |
| 2540 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); |
| 2541 | } |
| 2542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | err = tg3_bmcr_reset(tp); |
| 2544 | if (err) |
| 2545 | return err; |
| 2546 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2547 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2548 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
| 2549 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2550 | |
| 2551 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 2552 | } |
| 2553 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2554 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2555 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2556 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2557 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == |
| 2558 | CPMU_LSPD_1000MB_MACCLK_12_5) { |
| 2559 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2560 | udelay(40); |
| 2561 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2562 | } |
| 2563 | } |
| 2564 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2565 | if (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2566 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 2567 | return 0; |
| 2568 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2569 | tg3_phy_apply_otp(tp); |
| 2570 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2571 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2572 | tg3_phy_toggle_apd(tp, true); |
| 2573 | else |
| 2574 | tg3_phy_toggle_apd(tp, false); |
| 2575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | out: |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2577 | if ((tp->phy_flags & TG3_PHYFLG_ADC_BUG) && |
| 2578 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2579 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
| 2580 | tg3_phydsp_write(tp, 0x000a, 0x0323); |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2581 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2583 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2584 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2585 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 2586 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2588 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2589 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2590 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2591 | tg3_phydsp_write(tp, 0x000a, 0x310b); |
| 2592 | tg3_phydsp_write(tp, 0x201f, 0x9506); |
| 2593 | tg3_phydsp_write(tp, 0x401f, 0x14e2); |
| 2594 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2595 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2596 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2597 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
| 2598 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
| 2599 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { |
| 2600 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
| 2601 | tg3_writephy(tp, MII_TG3_TEST1, |
| 2602 | MII_TG3_TEST1_TRIM_EN | 0x4); |
| 2603 | } else |
| 2604 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); |
| 2605 | |
| 2606 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 2607 | } |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 2608 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | /* Set Extended packet length bit (bit 14) on all chips that */ |
| 2611 | /* support jumbo frames */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2612 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | /* Cannot do read-modify-write on 5401 */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2614 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2615 | } else if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | /* Set bit 14 with read-modify-write to preserve other bits */ |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2617 | err = tg3_phy_auxctl_read(tp, |
| 2618 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2619 | if (!err) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2620 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2621 | val | MII_TG3_AUXCTL_ACTL_EXTPKTLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support |
| 2625 | * jumbo frames transmission. |
| 2626 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2627 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2628 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 2629 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2630 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | } |
| 2632 | |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2633 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2634 | /* adjust output voltage */ |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2635 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2636 | } |
| 2637 | |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 2638 | if (tp->pci_chip_rev_id == CHIPREV_ID_5762_A0) |
| 2639 | tg3_phydsp_write(tp, 0xffb, 0x4000); |
| 2640 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2641 | tg3_phy_toggle_automdix(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | tg3_phy_set_wirespeed(tp); |
| 2643 | return 0; |
| 2644 | } |
| 2645 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2646 | #define TG3_GPIO_MSG_DRVR_PRES 0x00000001 |
| 2647 | #define TG3_GPIO_MSG_NEED_VAUX 0x00000002 |
| 2648 | #define TG3_GPIO_MSG_MASK (TG3_GPIO_MSG_DRVR_PRES | \ |
| 2649 | TG3_GPIO_MSG_NEED_VAUX) |
| 2650 | #define TG3_GPIO_MSG_ALL_DRVR_PRES_MASK \ |
| 2651 | ((TG3_GPIO_MSG_DRVR_PRES << 0) | \ |
| 2652 | (TG3_GPIO_MSG_DRVR_PRES << 4) | \ |
| 2653 | (TG3_GPIO_MSG_DRVR_PRES << 8) | \ |
| 2654 | (TG3_GPIO_MSG_DRVR_PRES << 12)) |
| 2655 | |
| 2656 | #define TG3_GPIO_MSG_ALL_NEED_VAUX_MASK \ |
| 2657 | ((TG3_GPIO_MSG_NEED_VAUX << 0) | \ |
| 2658 | (TG3_GPIO_MSG_NEED_VAUX << 4) | \ |
| 2659 | (TG3_GPIO_MSG_NEED_VAUX << 8) | \ |
| 2660 | (TG3_GPIO_MSG_NEED_VAUX << 12)) |
| 2661 | |
| 2662 | static inline u32 tg3_set_function_status(struct tg3 *tp, u32 newstat) |
| 2663 | { |
| 2664 | u32 status, shift; |
| 2665 | |
| 2666 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2667 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 2668 | status = tg3_ape_read32(tp, TG3_APE_GPIO_MSG); |
| 2669 | else |
| 2670 | status = tr32(TG3_CPMU_DRV_STATUS); |
| 2671 | |
| 2672 | shift = TG3_APE_GPIO_MSG_SHIFT + 4 * tp->pci_fn; |
| 2673 | status &= ~(TG3_GPIO_MSG_MASK << shift); |
| 2674 | status |= (newstat << shift); |
| 2675 | |
| 2676 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2677 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 2678 | tg3_ape_write32(tp, TG3_APE_GPIO_MSG, status); |
| 2679 | else |
| 2680 | tw32(TG3_CPMU_DRV_STATUS, status); |
| 2681 | |
| 2682 | return status >> TG3_APE_GPIO_MSG_SHIFT; |
| 2683 | } |
| 2684 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2685 | static inline int tg3_pwrsrc_switch_to_vmain(struct tg3 *tp) |
| 2686 | { |
| 2687 | if (!tg3_flag(tp, IS_NIC)) |
| 2688 | return 0; |
| 2689 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2690 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2691 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 2692 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 2693 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2694 | return -EIO; |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2695 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2696 | tg3_set_function_status(tp, TG3_GPIO_MSG_DRVR_PRES); |
| 2697 | |
| 2698 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2699 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2700 | |
| 2701 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
| 2702 | } else { |
| 2703 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2704 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2705 | } |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2706 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2707 | return 0; |
| 2708 | } |
| 2709 | |
| 2710 | static void tg3_pwrsrc_die_with_vmain(struct tg3 *tp) |
| 2711 | { |
| 2712 | u32 grc_local_ctrl; |
| 2713 | |
| 2714 | if (!tg3_flag(tp, IS_NIC) || |
| 2715 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2716 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) |
| 2717 | return; |
| 2718 | |
| 2719 | grc_local_ctrl = tp->grc_local_ctrl | GRC_LCLCTRL_GPIO_OE1; |
| 2720 | |
| 2721 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2722 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2723 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2724 | |
| 2725 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2726 | grc_local_ctrl, |
| 2727 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2728 | |
| 2729 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2730 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2731 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2732 | } |
| 2733 | |
| 2734 | static void tg3_pwrsrc_switch_to_vaux(struct tg3 *tp) |
| 2735 | { |
| 2736 | if (!tg3_flag(tp, IS_NIC)) |
| 2737 | return; |
| 2738 | |
| 2739 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2740 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 2741 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2742 | (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 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2748 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 2749 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
| 2750 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
| 2751 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | |
| 2752 | GRC_LCLCTRL_GPIO_OE1 | |
| 2753 | GRC_LCLCTRL_GPIO_OE2 | |
| 2754 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2755 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2756 | tp->grc_local_ctrl; |
| 2757 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2758 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2759 | |
| 2760 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2761 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2762 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2763 | |
| 2764 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2765 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2766 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2767 | } else { |
| 2768 | u32 no_gpio2; |
| 2769 | u32 grc_local_ctrl = 0; |
| 2770 | |
| 2771 | /* Workaround to prevent overdrawing Amps. */ |
| 2772 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 2773 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
| 2774 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2775 | grc_local_ctrl, |
| 2776 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2777 | } |
| 2778 | |
| 2779 | /* On 5753 and variants, GPIO2 cannot be used. */ |
| 2780 | no_gpio2 = tp->nic_sram_data_cfg & |
| 2781 | NIC_SRAM_DATA_CFG_NO_GPIO2; |
| 2782 | |
| 2783 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 2784 | GRC_LCLCTRL_GPIO_OE1 | |
| 2785 | GRC_LCLCTRL_GPIO_OE2 | |
| 2786 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2787 | GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2788 | if (no_gpio2) { |
| 2789 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | |
| 2790 | GRC_LCLCTRL_GPIO_OUTPUT2); |
| 2791 | } |
| 2792 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2793 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2794 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2795 | |
| 2796 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2797 | |
| 2798 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2799 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2800 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2801 | |
| 2802 | if (!no_gpio2) { |
| 2803 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2804 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2805 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2806 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2807 | } |
| 2808 | } |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2809 | } |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2810 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2811 | 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] | 2812 | { |
| 2813 | u32 msg = 0; |
| 2814 | |
| 2815 | /* Serialize power state transitions */ |
| 2816 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2817 | return; |
| 2818 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2819 | 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] | 2820 | msg = TG3_GPIO_MSG_NEED_VAUX; |
| 2821 | |
| 2822 | msg = tg3_set_function_status(tp, msg); |
| 2823 | |
| 2824 | if (msg & TG3_GPIO_MSG_ALL_DRVR_PRES_MASK) |
| 2825 | goto done; |
| 2826 | |
| 2827 | if (msg & TG3_GPIO_MSG_ALL_NEED_VAUX_MASK) |
| 2828 | tg3_pwrsrc_switch_to_vaux(tp); |
| 2829 | else |
| 2830 | tg3_pwrsrc_die_with_vmain(tp); |
| 2831 | |
| 2832 | done: |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2833 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2836 | static void tg3_frob_aux_power(struct tg3 *tp, bool include_wol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | { |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2838 | bool need_vaux = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2840 | /* The GPIOs do something completely different on 57765. */ |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 2841 | if (!tg3_flag(tp, IS_NIC) || tg3_flag(tp, 57765_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | return; |
| 2843 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2844 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2845 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 2846 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2847 | tg3_frob_aux_power_5717(tp, include_wol ? |
| 2848 | tg3_flag(tp, WOL_ENABLE) != 0 : 0); |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2849 | return; |
| 2850 | } |
| 2851 | |
| 2852 | if (tp->pdev_peer && tp->pdev_peer != tp->pdev) { |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2853 | struct net_device *dev_peer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2855 | dev_peer = pci_get_drvdata(tp->pdev_peer); |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2856 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2857 | /* remove_one() may have been run on the peer. */ |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2858 | if (dev_peer) { |
| 2859 | struct tg3 *tp_peer = netdev_priv(dev_peer); |
| 2860 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2861 | if (tg3_flag(tp_peer, INIT_COMPLETE)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2862 | return; |
| 2863 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2864 | if ((include_wol && tg3_flag(tp_peer, WOL_ENABLE)) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2865 | tg3_flag(tp_peer, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2866 | need_vaux = true; |
| 2867 | } |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2870 | if ((include_wol && tg3_flag(tp, WOL_ENABLE)) || |
| 2871 | tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2872 | need_vaux = true; |
| 2873 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2874 | if (need_vaux) |
| 2875 | tg3_pwrsrc_switch_to_vaux(tp); |
| 2876 | else |
| 2877 | tg3_pwrsrc_die_with_vmain(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | } |
| 2879 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2880 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
| 2881 | { |
| 2882 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) |
| 2883 | return 1; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2884 | 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] | 2885 | if (speed != SPEED_10) |
| 2886 | return 1; |
| 2887 | } else if (speed == SPEED_10) |
| 2888 | return 1; |
| 2889 | |
| 2890 | return 0; |
| 2891 | } |
| 2892 | |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2893 | 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] | 2894 | { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2895 | u32 val; |
| 2896 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2897 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2898 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2899 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 2900 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); |
| 2901 | |
| 2902 | sg_dig_ctrl |= |
| 2903 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; |
| 2904 | tw32(SG_DIG_CTRL, sg_dig_ctrl); |
| 2905 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); |
| 2906 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2907 | return; |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2908 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2909 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2910 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2911 | tg3_bmcr_reset(tp); |
| 2912 | val = tr32(GRC_MISC_CFG); |
| 2913 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); |
| 2914 | udelay(40); |
| 2915 | return; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2916 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 0e5f784 | 2009-11-02 14:26:38 +0000 | [diff] [blame] | 2917 | u32 phytest; |
| 2918 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2919 | u32 phy; |
| 2920 | |
| 2921 | tg3_writephy(tp, MII_ADVERTISE, 0); |
| 2922 | tg3_writephy(tp, MII_BMCR, |
| 2923 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 2924 | |
| 2925 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2926 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2927 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { |
| 2928 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; |
| 2929 | tg3_writephy(tp, |
| 2930 | MII_TG3_FET_SHDW_AUXMODE4, |
| 2931 | phy); |
| 2932 | } |
| 2933 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2934 | } |
| 2935 | return; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2936 | } else if (do_low_power) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2937 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 2938 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2939 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2940 | val = MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 2941 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | |
| 2942 | MII_TG3_AUXCTL_PCTL_VREG_11V; |
| 2943 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, val); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2944 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2945 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2946 | /* The PHY should not be powered down on some chips because |
| 2947 | * of bugs. |
| 2948 | */ |
| 2949 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2950 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2951 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && |
Matt Carlson | 085f1af | 2012-04-02 09:01:40 +0000 | [diff] [blame] | 2952 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) || |
| 2953 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 && |
| 2954 | !tp->pci_fn)) |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2955 | return; |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2956 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2957 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2958 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2959 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2960 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2961 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; |
| 2962 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2963 | } |
| 2964 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2965 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 2966 | } |
| 2967 | |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2968 | /* tp->lock is held. */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2969 | static int tg3_nvram_lock(struct tg3 *tp) |
| 2970 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2971 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2972 | int i; |
| 2973 | |
| 2974 | if (tp->nvram_lock_cnt == 0) { |
| 2975 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); |
| 2976 | for (i = 0; i < 8000; i++) { |
| 2977 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) |
| 2978 | break; |
| 2979 | udelay(20); |
| 2980 | } |
| 2981 | if (i == 8000) { |
| 2982 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2983 | return -ENODEV; |
| 2984 | } |
| 2985 | } |
| 2986 | tp->nvram_lock_cnt++; |
| 2987 | } |
| 2988 | return 0; |
| 2989 | } |
| 2990 | |
| 2991 | /* tp->lock is held. */ |
| 2992 | static void tg3_nvram_unlock(struct tg3 *tp) |
| 2993 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2994 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2995 | if (tp->nvram_lock_cnt > 0) |
| 2996 | tp->nvram_lock_cnt--; |
| 2997 | if (tp->nvram_lock_cnt == 0) |
| 2998 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2999 | } |
| 3000 | } |
| 3001 | |
| 3002 | /* tp->lock is held. */ |
| 3003 | static void tg3_enable_nvram_access(struct tg3 *tp) |
| 3004 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3005 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3006 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 3007 | |
| 3008 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); |
| 3009 | } |
| 3010 | } |
| 3011 | |
| 3012 | /* tp->lock is held. */ |
| 3013 | static void tg3_disable_nvram_access(struct tg3 *tp) |
| 3014 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3015 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3016 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 3017 | |
| 3018 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); |
| 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, |
| 3023 | u32 offset, u32 *val) |
| 3024 | { |
| 3025 | u32 tmp; |
| 3026 | int i; |
| 3027 | |
| 3028 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) |
| 3029 | return -EINVAL; |
| 3030 | |
| 3031 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | |
| 3032 | EEPROM_ADDR_DEVID_MASK | |
| 3033 | EEPROM_ADDR_READ); |
| 3034 | tw32(GRC_EEPROM_ADDR, |
| 3035 | tmp | |
| 3036 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 3037 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & |
| 3038 | EEPROM_ADDR_ADDR_MASK) | |
| 3039 | EEPROM_ADDR_READ | EEPROM_ADDR_START); |
| 3040 | |
| 3041 | for (i = 0; i < 1000; i++) { |
| 3042 | tmp = tr32(GRC_EEPROM_ADDR); |
| 3043 | |
| 3044 | if (tmp & EEPROM_ADDR_COMPLETE) |
| 3045 | break; |
| 3046 | msleep(1); |
| 3047 | } |
| 3048 | if (!(tmp & EEPROM_ADDR_COMPLETE)) |
| 3049 | return -EBUSY; |
| 3050 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 3051 | tmp = tr32(GRC_EEPROM_DATA); |
| 3052 | |
| 3053 | /* |
| 3054 | * The data will always be opposite the native endian |
| 3055 | * format. Perform a blind byteswap to compensate. |
| 3056 | */ |
| 3057 | *val = swab32(tmp); |
| 3058 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3059 | return 0; |
| 3060 | } |
| 3061 | |
| 3062 | #define NVRAM_CMD_TIMEOUT 10000 |
| 3063 | |
| 3064 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) |
| 3065 | { |
| 3066 | int i; |
| 3067 | |
| 3068 | tw32(NVRAM_CMD, nvram_cmd); |
| 3069 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { |
| 3070 | udelay(10); |
| 3071 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { |
| 3072 | udelay(10); |
| 3073 | break; |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | if (i == NVRAM_CMD_TIMEOUT) |
| 3078 | return -EBUSY; |
| 3079 | |
| 3080 | return 0; |
| 3081 | } |
| 3082 | |
| 3083 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) |
| 3084 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3085 | if (tg3_flag(tp, NVRAM) && |
| 3086 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 3087 | tg3_flag(tp, FLASH) && |
| 3088 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3089 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 3090 | |
| 3091 | addr = ((addr / tp->nvram_pagesize) << |
| 3092 | ATMEL_AT45DB0X1B_PAGE_POS) + |
| 3093 | (addr % tp->nvram_pagesize); |
| 3094 | |
| 3095 | return addr; |
| 3096 | } |
| 3097 | |
| 3098 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) |
| 3099 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3100 | if (tg3_flag(tp, NVRAM) && |
| 3101 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 3102 | tg3_flag(tp, FLASH) && |
| 3103 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3104 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 3105 | |
| 3106 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * |
| 3107 | tp->nvram_pagesize) + |
| 3108 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); |
| 3109 | |
| 3110 | return addr; |
| 3111 | } |
| 3112 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 3113 | /* NOTE: Data read in from NVRAM is byteswapped according to |
| 3114 | * the byteswapping settings for all other register accesses. |
| 3115 | * tg3 devices are BE devices, so on a BE machine, the data |
| 3116 | * returned will be exactly as it is seen in NVRAM. On a LE |
| 3117 | * machine, the 32-bit value will be byteswapped. |
| 3118 | */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3119 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
| 3120 | { |
| 3121 | int ret; |
| 3122 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3123 | if (!tg3_flag(tp, NVRAM)) |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3124 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
| 3125 | |
| 3126 | offset = tg3_nvram_phys_addr(tp, offset); |
| 3127 | |
| 3128 | if (offset > NVRAM_ADDR_MSK) |
| 3129 | return -EINVAL; |
| 3130 | |
| 3131 | ret = tg3_nvram_lock(tp); |
| 3132 | if (ret) |
| 3133 | return ret; |
| 3134 | |
| 3135 | tg3_enable_nvram_access(tp); |
| 3136 | |
| 3137 | tw32(NVRAM_ADDR, offset); |
| 3138 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | |
| 3139 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); |
| 3140 | |
| 3141 | if (ret == 0) |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 3142 | *val = tr32(NVRAM_RDDATA); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3143 | |
| 3144 | tg3_disable_nvram_access(tp); |
| 3145 | |
| 3146 | tg3_nvram_unlock(tp); |
| 3147 | |
| 3148 | return ret; |
| 3149 | } |
| 3150 | |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 3151 | /* Ensures NVRAM data is in bytestream format. */ |
| 3152 | 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] | 3153 | { |
| 3154 | u32 v; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 3155 | int res = tg3_nvram_read(tp, offset, &v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3156 | if (!res) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 3157 | *val = cpu_to_be32(v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3158 | return res; |
| 3159 | } |
| 3160 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3161 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
| 3162 | u32 offset, u32 len, u8 *buf) |
| 3163 | { |
| 3164 | int i, j, rc = 0; |
| 3165 | u32 val; |
| 3166 | |
| 3167 | for (i = 0; i < len; i += 4) { |
| 3168 | u32 addr; |
| 3169 | __be32 data; |
| 3170 | |
| 3171 | addr = offset + i; |
| 3172 | |
| 3173 | memcpy(&data, buf + i, 4); |
| 3174 | |
| 3175 | /* |
| 3176 | * The SEEPROM interface expects the data to always be opposite |
| 3177 | * the native endian format. We accomplish this by reversing |
| 3178 | * all the operations that would have been performed on the |
| 3179 | * data from a call to tg3_nvram_read_be32(). |
| 3180 | */ |
| 3181 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); |
| 3182 | |
| 3183 | val = tr32(GRC_EEPROM_ADDR); |
| 3184 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); |
| 3185 | |
| 3186 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | |
| 3187 | EEPROM_ADDR_READ); |
| 3188 | tw32(GRC_EEPROM_ADDR, val | |
| 3189 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 3190 | (addr & EEPROM_ADDR_ADDR_MASK) | |
| 3191 | EEPROM_ADDR_START | |
| 3192 | EEPROM_ADDR_WRITE); |
| 3193 | |
| 3194 | for (j = 0; j < 1000; j++) { |
| 3195 | val = tr32(GRC_EEPROM_ADDR); |
| 3196 | |
| 3197 | if (val & EEPROM_ADDR_COMPLETE) |
| 3198 | break; |
| 3199 | msleep(1); |
| 3200 | } |
| 3201 | if (!(val & EEPROM_ADDR_COMPLETE)) { |
| 3202 | rc = -EBUSY; |
| 3203 | break; |
| 3204 | } |
| 3205 | } |
| 3206 | |
| 3207 | return rc; |
| 3208 | } |
| 3209 | |
| 3210 | /* offset and length are dword aligned */ |
| 3211 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, |
| 3212 | u8 *buf) |
| 3213 | { |
| 3214 | int ret = 0; |
| 3215 | u32 pagesize = tp->nvram_pagesize; |
| 3216 | u32 pagemask = pagesize - 1; |
| 3217 | u32 nvram_cmd; |
| 3218 | u8 *tmp; |
| 3219 | |
| 3220 | tmp = kmalloc(pagesize, GFP_KERNEL); |
| 3221 | if (tmp == NULL) |
| 3222 | return -ENOMEM; |
| 3223 | |
| 3224 | while (len) { |
| 3225 | int j; |
| 3226 | u32 phy_addr, page_off, size; |
| 3227 | |
| 3228 | phy_addr = offset & ~pagemask; |
| 3229 | |
| 3230 | for (j = 0; j < pagesize; j += 4) { |
| 3231 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
| 3232 | (__be32 *) (tmp + j)); |
| 3233 | if (ret) |
| 3234 | break; |
| 3235 | } |
| 3236 | if (ret) |
| 3237 | break; |
| 3238 | |
| 3239 | page_off = offset & pagemask; |
| 3240 | size = pagesize; |
| 3241 | if (len < size) |
| 3242 | size = len; |
| 3243 | |
| 3244 | len -= size; |
| 3245 | |
| 3246 | memcpy(tmp + page_off, buf, size); |
| 3247 | |
| 3248 | offset = offset + (pagesize - page_off); |
| 3249 | |
| 3250 | tg3_enable_nvram_access(tp); |
| 3251 | |
| 3252 | /* |
| 3253 | * Before we can erase the flash page, we need |
| 3254 | * to issue a special "write enable" command. |
| 3255 | */ |
| 3256 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3257 | |
| 3258 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3259 | break; |
| 3260 | |
| 3261 | /* Erase the target page */ |
| 3262 | tw32(NVRAM_ADDR, phy_addr); |
| 3263 | |
| 3264 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | |
| 3265 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; |
| 3266 | |
| 3267 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3268 | break; |
| 3269 | |
| 3270 | /* Issue another write enable to start the write. */ |
| 3271 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3272 | |
| 3273 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3274 | break; |
| 3275 | |
| 3276 | for (j = 0; j < pagesize; j += 4) { |
| 3277 | __be32 data; |
| 3278 | |
| 3279 | data = *((__be32 *) (tmp + j)); |
| 3280 | |
| 3281 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3282 | |
| 3283 | tw32(NVRAM_ADDR, phy_addr + j); |
| 3284 | |
| 3285 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | |
| 3286 | NVRAM_CMD_WR; |
| 3287 | |
| 3288 | if (j == 0) |
| 3289 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 3290 | else if (j == (pagesize - 4)) |
| 3291 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3292 | |
| 3293 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3294 | if (ret) |
| 3295 | break; |
| 3296 | } |
| 3297 | if (ret) |
| 3298 | break; |
| 3299 | } |
| 3300 | |
| 3301 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3302 | tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3303 | |
| 3304 | kfree(tmp); |
| 3305 | |
| 3306 | return ret; |
| 3307 | } |
| 3308 | |
| 3309 | /* offset and length are dword aligned */ |
| 3310 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, |
| 3311 | u8 *buf) |
| 3312 | { |
| 3313 | int i, ret = 0; |
| 3314 | |
| 3315 | for (i = 0; i < len; i += 4, offset += 4) { |
| 3316 | u32 page_off, phy_addr, nvram_cmd; |
| 3317 | __be32 data; |
| 3318 | |
| 3319 | memcpy(&data, buf + i, 4); |
| 3320 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3321 | |
| 3322 | page_off = offset % tp->nvram_pagesize; |
| 3323 | |
| 3324 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
| 3325 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3326 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
| 3327 | |
| 3328 | if (page_off == 0 || i == 0) |
| 3329 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 3330 | if (page_off == (tp->nvram_pagesize - 4)) |
| 3331 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3332 | |
| 3333 | if (i == (len - 4)) |
| 3334 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3335 | |
Matt Carlson | 4227822 | 2012-02-13 15:20:11 +0000 | [diff] [blame] | 3336 | if ((nvram_cmd & NVRAM_CMD_FIRST) || |
| 3337 | !tg3_flag(tp, FLASH) || |
| 3338 | !tg3_flag(tp, 57765_PLUS)) |
| 3339 | tw32(NVRAM_ADDR, phy_addr); |
| 3340 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3341 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
| 3342 | !tg3_flag(tp, 5755_PLUS) && |
| 3343 | (tp->nvram_jedecnum == JEDEC_ST) && |
| 3344 | (nvram_cmd & NVRAM_CMD_FIRST)) { |
| 3345 | u32 cmd; |
| 3346 | |
| 3347 | cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3348 | ret = tg3_nvram_exec_cmd(tp, cmd); |
| 3349 | if (ret) |
| 3350 | break; |
| 3351 | } |
| 3352 | if (!tg3_flag(tp, FLASH)) { |
| 3353 | /* We always do complete word writes to eeprom. */ |
| 3354 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); |
| 3355 | } |
| 3356 | |
| 3357 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3358 | if (ret) |
| 3359 | break; |
| 3360 | } |
| 3361 | return ret; |
| 3362 | } |
| 3363 | |
| 3364 | /* offset and length are dword aligned */ |
| 3365 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) |
| 3366 | { |
| 3367 | int ret; |
| 3368 | |
| 3369 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3370 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
| 3371 | ~GRC_LCLCTRL_GPIO_OUTPUT1); |
| 3372 | udelay(40); |
| 3373 | } |
| 3374 | |
| 3375 | if (!tg3_flag(tp, NVRAM)) { |
| 3376 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
| 3377 | } else { |
| 3378 | u32 grc_mode; |
| 3379 | |
| 3380 | ret = tg3_nvram_lock(tp); |
| 3381 | if (ret) |
| 3382 | return ret; |
| 3383 | |
| 3384 | tg3_enable_nvram_access(tp); |
| 3385 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) |
| 3386 | tw32(NVRAM_WRITE1, 0x406); |
| 3387 | |
| 3388 | grc_mode = tr32(GRC_MODE); |
| 3389 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); |
| 3390 | |
| 3391 | if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) { |
| 3392 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
| 3393 | buf); |
| 3394 | } else { |
| 3395 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
| 3396 | buf); |
| 3397 | } |
| 3398 | |
| 3399 | grc_mode = tr32(GRC_MODE); |
| 3400 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); |
| 3401 | |
| 3402 | tg3_disable_nvram_access(tp); |
| 3403 | tg3_nvram_unlock(tp); |
| 3404 | } |
| 3405 | |
| 3406 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3407 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 3408 | udelay(40); |
| 3409 | } |
| 3410 | |
| 3411 | return ret; |
| 3412 | } |
| 3413 | |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3414 | #define RX_CPU_SCRATCH_BASE 0x30000 |
| 3415 | #define RX_CPU_SCRATCH_SIZE 0x04000 |
| 3416 | #define TX_CPU_SCRATCH_BASE 0x34000 |
| 3417 | #define TX_CPU_SCRATCH_SIZE 0x04000 |
| 3418 | |
| 3419 | /* tp->lock is held. */ |
| 3420 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) |
| 3421 | { |
| 3422 | int i; |
| 3423 | |
| 3424 | BUG_ON(offset == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)); |
| 3425 | |
| 3426 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 3427 | u32 val = tr32(GRC_VCPU_EXT_CTRL); |
| 3428 | |
| 3429 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 3430 | return 0; |
| 3431 | } |
| 3432 | if (offset == RX_CPU_BASE) { |
| 3433 | for (i = 0; i < 10000; i++) { |
| 3434 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3435 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 3436 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 3437 | break; |
| 3438 | } |
| 3439 | |
| 3440 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3441 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); |
| 3442 | udelay(10); |
| 3443 | } else { |
| 3444 | for (i = 0; i < 10000; i++) { |
| 3445 | tw32(offset + CPU_STATE, 0xffffffff); |
| 3446 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 3447 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 3448 | break; |
| 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | if (i >= 10000) { |
| 3453 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
| 3454 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); |
| 3455 | return -ENODEV; |
| 3456 | } |
| 3457 | |
| 3458 | /* Clear firmware's nvram arbitration. */ |
| 3459 | if (tg3_flag(tp, NVRAM)) |
| 3460 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
| 3461 | return 0; |
| 3462 | } |
| 3463 | |
| 3464 | struct fw_info { |
| 3465 | unsigned int fw_base; |
| 3466 | unsigned int fw_len; |
| 3467 | const __be32 *fw_data; |
| 3468 | }; |
| 3469 | |
| 3470 | /* tp->lock is held. */ |
| 3471 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, |
| 3472 | u32 cpu_scratch_base, int cpu_scratch_size, |
| 3473 | struct fw_info *info) |
| 3474 | { |
| 3475 | int err, lock_err, i; |
| 3476 | void (*write_op)(struct tg3 *, u32, u32); |
| 3477 | |
| 3478 | if (cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)) { |
| 3479 | netdev_err(tp->dev, |
| 3480 | "%s: Trying to load TX cpu firmware which is 5705\n", |
| 3481 | __func__); |
| 3482 | return -EINVAL; |
| 3483 | } |
| 3484 | |
| 3485 | if (tg3_flag(tp, 5705_PLUS)) |
| 3486 | write_op = tg3_write_mem; |
| 3487 | else |
| 3488 | write_op = tg3_write_indirect_reg32; |
| 3489 | |
| 3490 | /* It is possible that bootcode is still loading at this point. |
| 3491 | * Get the nvram lock first before halting the cpu. |
| 3492 | */ |
| 3493 | lock_err = tg3_nvram_lock(tp); |
| 3494 | err = tg3_halt_cpu(tp, cpu_base); |
| 3495 | if (!lock_err) |
| 3496 | tg3_nvram_unlock(tp); |
| 3497 | if (err) |
| 3498 | goto out; |
| 3499 | |
| 3500 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
| 3501 | write_op(tp, cpu_scratch_base + i, 0); |
| 3502 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3503 | tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT); |
| 3504 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
| 3505 | write_op(tp, (cpu_scratch_base + |
| 3506 | (info->fw_base & 0xffff) + |
| 3507 | (i * sizeof(u32))), |
| 3508 | be32_to_cpu(info->fw_data[i])); |
| 3509 | |
| 3510 | err = 0; |
| 3511 | |
| 3512 | out: |
| 3513 | return err; |
| 3514 | } |
| 3515 | |
| 3516 | /* tp->lock is held. */ |
| 3517 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) |
| 3518 | { |
| 3519 | struct fw_info info; |
| 3520 | const __be32 *fw_data; |
| 3521 | int err, i; |
| 3522 | |
| 3523 | fw_data = (void *)tp->fw->data; |
| 3524 | |
| 3525 | /* Firmware blob starts with version numbers, followed by |
| 3526 | start address and length. We are setting complete length. |
| 3527 | length = end_address_of_bss - start_address_of_text. |
| 3528 | Remainder is the blob to be loaded contiguously |
| 3529 | from start address. */ |
| 3530 | |
| 3531 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 3532 | info.fw_len = tp->fw->size - 12; |
| 3533 | info.fw_data = &fw_data[3]; |
| 3534 | |
| 3535 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
| 3536 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, |
| 3537 | &info); |
| 3538 | if (err) |
| 3539 | return err; |
| 3540 | |
| 3541 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, |
| 3542 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, |
| 3543 | &info); |
| 3544 | if (err) |
| 3545 | return err; |
| 3546 | |
| 3547 | /* Now startup only the RX cpu. */ |
| 3548 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3549 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
| 3550 | |
| 3551 | for (i = 0; i < 5; i++) { |
| 3552 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
| 3553 | break; |
| 3554 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3555 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); |
| 3556 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
| 3557 | udelay(1000); |
| 3558 | } |
| 3559 | if (i >= 5) { |
| 3560 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
| 3561 | "should be %08x\n", __func__, |
| 3562 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
| 3563 | return -ENODEV; |
| 3564 | } |
| 3565 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3566 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); |
| 3567 | |
| 3568 | return 0; |
| 3569 | } |
| 3570 | |
| 3571 | /* tp->lock is held. */ |
| 3572 | static int tg3_load_tso_firmware(struct tg3 *tp) |
| 3573 | { |
| 3574 | struct fw_info info; |
| 3575 | const __be32 *fw_data; |
| 3576 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
| 3577 | int err, i; |
| 3578 | |
| 3579 | if (tg3_flag(tp, HW_TSO_1) || |
| 3580 | tg3_flag(tp, HW_TSO_2) || |
| 3581 | tg3_flag(tp, HW_TSO_3)) |
| 3582 | return 0; |
| 3583 | |
| 3584 | fw_data = (void *)tp->fw->data; |
| 3585 | |
| 3586 | /* Firmware blob starts with version numbers, followed by |
| 3587 | start address and length. We are setting complete length. |
| 3588 | length = end_address_of_bss - start_address_of_text. |
| 3589 | Remainder is the blob to be loaded contiguously |
| 3590 | from start address. */ |
| 3591 | |
| 3592 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 3593 | cpu_scratch_size = tp->fw_len; |
| 3594 | info.fw_len = tp->fw->size - 12; |
| 3595 | info.fw_data = &fw_data[3]; |
| 3596 | |
| 3597 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 3598 | cpu_base = RX_CPU_BASE; |
| 3599 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; |
| 3600 | } else { |
| 3601 | cpu_base = TX_CPU_BASE; |
| 3602 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; |
| 3603 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; |
| 3604 | } |
| 3605 | |
| 3606 | err = tg3_load_firmware_cpu(tp, cpu_base, |
| 3607 | cpu_scratch_base, cpu_scratch_size, |
| 3608 | &info); |
| 3609 | if (err) |
| 3610 | return err; |
| 3611 | |
| 3612 | /* Now startup the cpu. */ |
| 3613 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3614 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
| 3615 | |
| 3616 | for (i = 0; i < 5; i++) { |
| 3617 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
| 3618 | break; |
| 3619 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3620 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
| 3621 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
| 3622 | udelay(1000); |
| 3623 | } |
| 3624 | if (i >= 5) { |
| 3625 | netdev_err(tp->dev, |
| 3626 | "%s fails to set CPU PC, is %08x should be %08x\n", |
| 3627 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
| 3628 | return -ENODEV; |
| 3629 | } |
| 3630 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3631 | tw32_f(cpu_base + CPU_MODE, 0x00000000); |
| 3632 | return 0; |
| 3633 | } |
| 3634 | |
| 3635 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3636 | /* tp->lock is held. */ |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 3637 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) |
| 3638 | { |
| 3639 | u32 addr_high, addr_low; |
| 3640 | int i; |
| 3641 | |
| 3642 | addr_high = ((tp->dev->dev_addr[0] << 8) | |
| 3643 | tp->dev->dev_addr[1]); |
| 3644 | addr_low = ((tp->dev->dev_addr[2] << 24) | |
| 3645 | (tp->dev->dev_addr[3] << 16) | |
| 3646 | (tp->dev->dev_addr[4] << 8) | |
| 3647 | (tp->dev->dev_addr[5] << 0)); |
| 3648 | for (i = 0; i < 4; i++) { |
| 3649 | if (i == 1 && skip_mac_1) |
| 3650 | continue; |
| 3651 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); |
| 3652 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); |
| 3653 | } |
| 3654 | |
| 3655 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 3656 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 3657 | for (i = 0; i < 12; i++) { |
| 3658 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); |
| 3659 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); |
| 3660 | } |
| 3661 | } |
| 3662 | |
| 3663 | addr_high = (tp->dev->dev_addr[0] + |
| 3664 | tp->dev->dev_addr[1] + |
| 3665 | tp->dev->dev_addr[2] + |
| 3666 | tp->dev->dev_addr[3] + |
| 3667 | tp->dev->dev_addr[4] + |
| 3668 | tp->dev->dev_addr[5]) & |
| 3669 | TX_BACKOFF_SEED_MASK; |
| 3670 | tw32(MAC_TX_BACKOFF_SEED, addr_high); |
| 3671 | } |
| 3672 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3673 | static void tg3_enable_register_access(struct tg3 *tp) |
| 3674 | { |
| 3675 | /* |
| 3676 | * Make sure register accesses (indirect or otherwise) will function |
| 3677 | * correctly. |
| 3678 | */ |
| 3679 | pci_write_config_dword(tp->pdev, |
| 3680 | TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl); |
| 3681 | } |
| 3682 | |
| 3683 | static int tg3_power_up(struct tg3 *tp) |
| 3684 | { |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3685 | int err; |
| 3686 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3687 | tg3_enable_register_access(tp); |
| 3688 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3689 | err = pci_set_power_state(tp->pdev, PCI_D0); |
| 3690 | if (!err) { |
| 3691 | /* Switch out of Vaux if it is a NIC */ |
| 3692 | tg3_pwrsrc_switch_to_vmain(tp); |
| 3693 | } else { |
| 3694 | netdev_err(tp->dev, "Transition to D0 failed\n"); |
| 3695 | } |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3696 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3697 | return err; |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3698 | } |
| 3699 | |
Matt Carlson | 4b40952 | 2012-02-13 10:20:11 +0000 | [diff] [blame] | 3700 | static int tg3_setup_phy(struct tg3 *, int); |
| 3701 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3702 | static int tg3_power_down_prepare(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | { |
| 3704 | u32 misc_host_ctrl; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3705 | bool device_should_wake, do_low_power; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3707 | tg3_enable_register_access(tp); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3708 | |
| 3709 | /* Restore the CLKREQ setting. */ |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 3710 | if (tg3_flag(tp, CLKREQ_BUG)) |
| 3711 | pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL, |
| 3712 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 3715 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 3716 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); |
| 3717 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3718 | device_should_wake = device_may_wakeup(&tp->pdev->dev) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3719 | tg3_flag(tp, WOL_ENABLE); |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3720 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3721 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3722 | do_low_power = false; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3723 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3724 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3725 | struct phy_device *phydev; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3726 | u32 phyid, advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3727 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 3728 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3729 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3730 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3731 | |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 3732 | tp->link_config.speed = phydev->speed; |
| 3733 | tp->link_config.duplex = phydev->duplex; |
| 3734 | tp->link_config.autoneg = phydev->autoneg; |
| 3735 | tp->link_config.advertising = phydev->advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3736 | |
| 3737 | advertising = ADVERTISED_TP | |
| 3738 | ADVERTISED_Pause | |
| 3739 | ADVERTISED_Autoneg | |
| 3740 | ADVERTISED_10baseT_Half; |
| 3741 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3742 | if (tg3_flag(tp, ENABLE_ASF) || device_should_wake) { |
| 3743 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3744 | advertising |= |
| 3745 | ADVERTISED_100baseT_Half | |
| 3746 | ADVERTISED_100baseT_Full | |
| 3747 | ADVERTISED_10baseT_Full; |
| 3748 | else |
| 3749 | advertising |= ADVERTISED_10baseT_Full; |
| 3750 | } |
| 3751 | |
| 3752 | phydev->advertising = advertising; |
| 3753 | |
| 3754 | phy_start_aneg(phydev); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3755 | |
| 3756 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 3757 | if (phyid != PHY_ID_BCMAC131) { |
| 3758 | phyid &= PHY_BCM_OUI_MASK; |
| 3759 | if (phyid == PHY_BCM_OUI_1 || |
| 3760 | phyid == PHY_BCM_OUI_2 || |
| 3761 | phyid == PHY_BCM_OUI_3) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3762 | do_low_power = true; |
| 3763 | } |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3764 | } |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3765 | } else { |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 3766 | do_low_power = true; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3767 | |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 3768 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3769 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | |
Matt Carlson | 2855b9f | 2012-02-13 15:20:14 +0000 | [diff] [blame] | 3771 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3772 | tg3_setup_phy(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | } |
| 3774 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 3775 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 3776 | u32 val; |
| 3777 | |
| 3778 | val = tr32(GRC_VCPU_EXT_CTRL); |
| 3779 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3780 | } else if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3781 | int i; |
| 3782 | u32 val; |
| 3783 | |
| 3784 | for (i = 0; i < 200; i++) { |
| 3785 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); |
| 3786 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 3787 | break; |
| 3788 | msleep(1); |
| 3789 | } |
| 3790 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3791 | if (tg3_flag(tp, WOL_CAP)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 3792 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
| 3793 | WOL_DRV_STATE_SHUTDOWN | |
| 3794 | WOL_DRV_WOL | |
| 3795 | WOL_SET_MAGIC_PKT); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3796 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3797 | if (device_should_wake) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | u32 mac_mode; |
| 3799 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3800 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 3801 | if (do_low_power && |
| 3802 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 3803 | tg3_phy_auxctl_write(tp, |
| 3804 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL, |
| 3805 | MII_TG3_AUXCTL_PCTL_WOL_EN | |
| 3806 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 3807 | MII_TG3_AUXCTL_PCTL_CL_AB_TXDAC); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 3808 | udelay(40); |
| 3809 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3811 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 3812 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 3813 | else |
| 3814 | mac_mode = MAC_MODE_PORT_MODE_MII; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3816 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
| 3817 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 3818 | ASIC_REV_5700) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3819 | u32 speed = tg3_flag(tp, WOL_SPEED_100MB) ? |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3820 | SPEED_100 : SPEED_10; |
| 3821 | if (tg3_5700_link_polarity(tp, speed)) |
| 3822 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 3823 | else |
| 3824 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 3825 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | } else { |
| 3827 | mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 3828 | } |
| 3829 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3830 | if (!tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 3832 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3833 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3834 | if ((tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) && |
| 3835 | (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE))) |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3836 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3838 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 3839 | mac_mode |= MAC_MODE_APE_TX_EN | |
| 3840 | MAC_MODE_APE_RX_EN | |
| 3841 | MAC_MODE_TDE_ENABLE; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 3842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | tw32_f(MAC_MODE, mac_mode); |
| 3844 | udelay(100); |
| 3845 | |
| 3846 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); |
| 3847 | udelay(10); |
| 3848 | } |
| 3849 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3850 | if (!tg3_flag(tp, WOL_SPEED_100MB) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3852 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 3853 | u32 base_val; |
| 3854 | |
| 3855 | base_val = tp->pci_clock_ctrl; |
| 3856 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | |
| 3857 | CLOCK_CTRL_TXCLK_DISABLE); |
| 3858 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3859 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
| 3860 | CLOCK_CTRL_PWRDOWN_PLL133, 40); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3861 | } else if (tg3_flag(tp, 5780_CLASS) || |
| 3862 | tg3_flag(tp, CPMU_PRESENT) || |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 3863 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 3864 | /* do nothing */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3865 | } else if (!(tg3_flag(tp, 5750_PLUS) && tg3_flag(tp, ENABLE_ASF))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | u32 newbits1, newbits2; |
| 3867 | |
| 3868 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3869 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3870 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 3871 | CLOCK_CTRL_TXCLK_DISABLE | |
| 3872 | CLOCK_CTRL_ALTCLK); |
| 3873 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3874 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | newbits1 = CLOCK_CTRL_625_CORE; |
| 3876 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; |
| 3877 | } else { |
| 3878 | newbits1 = CLOCK_CTRL_ALTCLK; |
| 3879 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 3880 | } |
| 3881 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3882 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
| 3883 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3885 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
| 3886 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3888 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | u32 newbits3; |
| 3890 | |
| 3891 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3892 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3893 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 3894 | CLOCK_CTRL_TXCLK_DISABLE | |
| 3895 | CLOCK_CTRL_44MHZ_CORE); |
| 3896 | } else { |
| 3897 | newbits3 = CLOCK_CTRL_44MHZ_CORE; |
| 3898 | } |
| 3899 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 3900 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 3901 | tp->pci_clock_ctrl | newbits3, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | } |
| 3903 | } |
| 3904 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3905 | if (!(device_should_wake) && !tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3906 | tg3_power_down_phy(tp, do_low_power); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3907 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 3908 | tg3_frob_aux_power(tp, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | |
| 3910 | /* Workaround for unstable PLL clock */ |
| 3911 | if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) || |
| 3912 | (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) { |
| 3913 | u32 val = tr32(0x7d00); |
| 3914 | |
| 3915 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); |
| 3916 | tw32(0x7d00, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3917 | if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 3918 | int err; |
| 3919 | |
| 3920 | err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 3922 | if (!err) |
| 3923 | tg3_nvram_unlock(tp); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | } |
| 3926 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 3927 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
| 3928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | return 0; |
| 3930 | } |
| 3931 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3932 | static void tg3_power_down(struct tg3 *tp) |
| 3933 | { |
| 3934 | tg3_power_down_prepare(tp); |
| 3935 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3936 | pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3937 | pci_set_power_state(tp->pdev, PCI_D3hot); |
| 3938 | } |
| 3939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
| 3941 | { |
| 3942 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { |
| 3943 | case MII_TG3_AUX_STAT_10HALF: |
| 3944 | *speed = SPEED_10; |
| 3945 | *duplex = DUPLEX_HALF; |
| 3946 | break; |
| 3947 | |
| 3948 | case MII_TG3_AUX_STAT_10FULL: |
| 3949 | *speed = SPEED_10; |
| 3950 | *duplex = DUPLEX_FULL; |
| 3951 | break; |
| 3952 | |
| 3953 | case MII_TG3_AUX_STAT_100HALF: |
| 3954 | *speed = SPEED_100; |
| 3955 | *duplex = DUPLEX_HALF; |
| 3956 | break; |
| 3957 | |
| 3958 | case MII_TG3_AUX_STAT_100FULL: |
| 3959 | *speed = SPEED_100; |
| 3960 | *duplex = DUPLEX_FULL; |
| 3961 | break; |
| 3962 | |
| 3963 | case MII_TG3_AUX_STAT_1000HALF: |
| 3964 | *speed = SPEED_1000; |
| 3965 | *duplex = DUPLEX_HALF; |
| 3966 | break; |
| 3967 | |
| 3968 | case MII_TG3_AUX_STAT_1000FULL: |
| 3969 | *speed = SPEED_1000; |
| 3970 | *duplex = DUPLEX_FULL; |
| 3971 | break; |
| 3972 | |
| 3973 | default: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3974 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 3975 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
| 3976 | SPEED_10; |
| 3977 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : |
| 3978 | DUPLEX_HALF; |
| 3979 | break; |
| 3980 | } |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 3981 | *speed = SPEED_UNKNOWN; |
| 3982 | *duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3984 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3987 | 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] | 3988 | { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3989 | int err = 0; |
| 3990 | u32 val, new_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3992 | new_adv = ADVERTISE_CSMA; |
Hiroaki SHIMODA | 202ff1c | 2011-11-22 04:05:41 +0000 | [diff] [blame] | 3993 | new_adv |= ethtool_adv_to_mii_adv_t(advertise) & ADVERTISE_ALL; |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 3994 | new_adv |= mii_advertise_flowctrl(flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 3996 | err = tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 3997 | if (err) |
| 3998 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 4000 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4001 | new_adv = ethtool_adv_to_mii_ctrl1000_t(advertise); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4002 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 4003 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 4004 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) |
| 4005 | new_adv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4006 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 4007 | err = tg3_writephy(tp, MII_CTRL1000, new_adv); |
| 4008 | if (err) |
| 4009 | goto done; |
| 4010 | } |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4011 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4012 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 4013 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4015 | tw32(TG3_CPMU_EEE_MODE, |
| 4016 | tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4017 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4018 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
| 4019 | if (!err) { |
| 4020 | u32 err2; |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4021 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 4022 | val = 0; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4023 | /* Advertise 100-BaseTX EEE ability */ |
| 4024 | if (advertise & ADVERTISED_100baseT_Full) |
| 4025 | val |= MDIO_AN_EEE_ADV_100TX; |
| 4026 | /* Advertise 1000-BaseT EEE ability */ |
| 4027 | if (advertise & ADVERTISED_1000baseT_Full) |
| 4028 | val |= MDIO_AN_EEE_ADV_1000T; |
| 4029 | 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] | 4030 | if (err) |
| 4031 | val = 0; |
| 4032 | |
| 4033 | switch (GET_ASIC_REV(tp->pci_chip_rev_id)) { |
| 4034 | case ASIC_REV_5717: |
| 4035 | case ASIC_REV_57765: |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 4036 | case ASIC_REV_57766: |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 4037 | case ASIC_REV_5719: |
| 4038 | /* If we advertised any eee advertisements above... */ |
| 4039 | if (val) |
| 4040 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 4041 | MII_TG3_DSP_TAP26_RMRXSTO | |
| 4042 | MII_TG3_DSP_TAP26_OPCSINPT; |
| 4043 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
| 4044 | /* Fall through */ |
| 4045 | case ASIC_REV_5720: |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 4046 | case ASIC_REV_5762: |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 4047 | if (!tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) |
| 4048 | tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, val | |
| 4049 | MII_TG3_DSP_CH34TP2_HIBW01); |
| 4050 | } |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4051 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4052 | err2 = TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
| 4053 | if (!err) |
| 4054 | err = err2; |
| 4055 | } |
| 4056 | |
| 4057 | done: |
| 4058 | return err; |
| 4059 | } |
| 4060 | |
| 4061 | static void tg3_phy_copper_begin(struct tg3 *tp) |
| 4062 | { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4063 | if (tp->link_config.autoneg == AUTONEG_ENABLE || |
| 4064 | (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 4065 | u32 adv, fc; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4066 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4067 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 4068 | adv = ADVERTISED_10baseT_Half | |
| 4069 | ADVERTISED_10baseT_Full; |
| 4070 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
| 4071 | adv |= ADVERTISED_100baseT_Half | |
| 4072 | ADVERTISED_100baseT_Full; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4073 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4074 | fc = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4075 | } else { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4076 | adv = tp->link_config.advertising; |
| 4077 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 4078 | adv &= ~(ADVERTISED_1000baseT_Half | |
| 4079 | ADVERTISED_1000baseT_Full); |
| 4080 | |
| 4081 | fc = tp->link_config.flowctrl; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4082 | } |
| 4083 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4084 | tg3_phy_autoneg_cfg(tp, adv, fc); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4085 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4086 | tg3_writephy(tp, MII_BMCR, |
| 4087 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 4088 | } else { |
| 4089 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | u32 bmcr, orig_bmcr; |
| 4091 | |
| 4092 | tp->link_config.active_speed = tp->link_config.speed; |
| 4093 | tp->link_config.active_duplex = tp->link_config.duplex; |
| 4094 | |
| 4095 | bmcr = 0; |
| 4096 | switch (tp->link_config.speed) { |
| 4097 | default: |
| 4098 | case SPEED_10: |
| 4099 | break; |
| 4100 | |
| 4101 | case SPEED_100: |
| 4102 | bmcr |= BMCR_SPEED100; |
| 4103 | break; |
| 4104 | |
| 4105 | case SPEED_1000: |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 4106 | bmcr |= BMCR_SPEED1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4108 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | |
| 4110 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 4111 | bmcr |= BMCR_FULLDPLX; |
| 4112 | |
| 4113 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && |
| 4114 | (bmcr != orig_bmcr)) { |
| 4115 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); |
| 4116 | for (i = 0; i < 1500; i++) { |
| 4117 | u32 tmp; |
| 4118 | |
| 4119 | udelay(10); |
| 4120 | if (tg3_readphy(tp, MII_BMSR, &tmp) || |
| 4121 | tg3_readphy(tp, MII_BMSR, &tmp)) |
| 4122 | continue; |
| 4123 | if (!(tmp & BMSR_LSTATUS)) { |
| 4124 | udelay(40); |
| 4125 | break; |
| 4126 | } |
| 4127 | } |
| 4128 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 4129 | udelay(40); |
| 4130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | } |
| 4132 | } |
| 4133 | |
| 4134 | static int tg3_init_5401phy_dsp(struct tg3 *tp) |
| 4135 | { |
| 4136 | int err; |
| 4137 | |
| 4138 | /* Turn off tap power management. */ |
| 4139 | /* Set Extended packet length bit */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4140 | err = tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 4142 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
| 4143 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); |
| 4144 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); |
| 4145 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); |
| 4146 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | |
| 4148 | udelay(40); |
| 4149 | |
| 4150 | return err; |
| 4151 | } |
| 4152 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4153 | 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] | 4154 | { |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4155 | u32 advmsk, tgtadv, advertising; |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 4156 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4157 | advertising = tp->link_config.advertising; |
| 4158 | tgtadv = ethtool_adv_to_mii_adv_t(advertising) & ADVERTISE_ALL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4160 | advmsk = ADVERTISE_ALL; |
| 4161 | if (tp->link_config.active_duplex == DUPLEX_FULL) { |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 4162 | tgtadv |= mii_advertise_flowctrl(tp->link_config.flowctrl); |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4163 | advmsk |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 4164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4166 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
| 4167 | return false; |
| 4168 | |
| 4169 | if ((*lcladv & advmsk) != tgtadv) |
| 4170 | return false; |
Matt Carlson | b99d2a5 | 2011-08-31 11:44:47 +0000 | [diff] [blame] | 4171 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4172 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | u32 tg3_ctrl; |
| 4174 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4175 | tgtadv = ethtool_adv_to_mii_ctrl1000_t(advertising); |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 4176 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 4177 | if (tg3_readphy(tp, MII_CTRL1000, &tg3_ctrl)) |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4178 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | |
Matt Carlson | 3198e07 | 2012-02-13 15:20:10 +0000 | [diff] [blame] | 4180 | if (tgtadv && |
| 4181 | (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 4182 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)) { |
| 4183 | tgtadv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
| 4184 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL | |
| 4185 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
| 4186 | } else { |
| 4187 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL); |
| 4188 | } |
| 4189 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4190 | if (tg3_ctrl != tgtadv) |
| 4191 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | } |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 4193 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4194 | return true; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4195 | } |
| 4196 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4197 | static bool tg3_phy_copper_fetch_rmtadv(struct tg3 *tp, u32 *rmtadv) |
| 4198 | { |
| 4199 | u32 lpeth = 0; |
| 4200 | |
| 4201 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4202 | u32 val; |
| 4203 | |
| 4204 | if (tg3_readphy(tp, MII_STAT1000, &val)) |
| 4205 | return false; |
| 4206 | |
| 4207 | lpeth = mii_stat1000_to_ethtool_lpa_t(val); |
| 4208 | } |
| 4209 | |
| 4210 | if (tg3_readphy(tp, MII_LPA, rmtadv)) |
| 4211 | return false; |
| 4212 | |
| 4213 | lpeth |= mii_lpa_to_ethtool_lpa_t(*rmtadv); |
| 4214 | tp->link_config.rmt_adv = lpeth; |
| 4215 | |
| 4216 | return true; |
| 4217 | } |
| 4218 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 4219 | static bool tg3_test_and_report_link_chg(struct tg3 *tp, int curr_link_up) |
| 4220 | { |
| 4221 | if (curr_link_up != tp->link_up) { |
| 4222 | if (curr_link_up) { |
| 4223 | tg3_carrier_on(tp); |
| 4224 | } else { |
| 4225 | tg3_carrier_off(tp); |
| 4226 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
| 4227 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 4228 | } |
| 4229 | |
| 4230 | tg3_link_report(tp); |
| 4231 | return true; |
| 4232 | } |
| 4233 | |
| 4234 | return false; |
| 4235 | } |
| 4236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
| 4238 | { |
| 4239 | int current_link_up; |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4240 | u32 bmsr, val; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4241 | u32 lcl_adv, rmt_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | u16 current_speed; |
| 4243 | u8 current_duplex; |
| 4244 | int i, err; |
| 4245 | |
| 4246 | tw32(MAC_EVENT, 0); |
| 4247 | |
| 4248 | tw32_f(MAC_STATUS, |
| 4249 | (MAC_STATUS_SYNC_CHANGED | |
| 4250 | MAC_STATUS_CFG_CHANGED | |
| 4251 | MAC_STATUS_MI_COMPLETION | |
| 4252 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4253 | udelay(40); |
| 4254 | |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 4255 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 4256 | tw32_f(MAC_MI_MODE, |
| 4257 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 4258 | udelay(80); |
| 4259 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4261 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | |
| 4263 | /* Some third-party PHYs need to be reset on link going |
| 4264 | * down. |
| 4265 | */ |
| 4266 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 4267 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 4268 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 4269 | tp->link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4271 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4272 | !(bmsr & BMSR_LSTATUS)) |
| 4273 | force_reset = 1; |
| 4274 | } |
| 4275 | if (force_reset) |
| 4276 | tg3_phy_reset(tp); |
| 4277 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4278 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4280 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4281 | !tg3_flag(tp, INIT_COMPLETE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | bmsr = 0; |
| 4283 | |
| 4284 | if (!(bmsr & BMSR_LSTATUS)) { |
| 4285 | err = tg3_init_5401phy_dsp(tp); |
| 4286 | if (err) |
| 4287 | return err; |
| 4288 | |
| 4289 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4290 | for (i = 0; i < 1000; i++) { |
| 4291 | udelay(10); |
| 4292 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4293 | (bmsr & BMSR_LSTATUS)) { |
| 4294 | udelay(40); |
| 4295 | break; |
| 4296 | } |
| 4297 | } |
| 4298 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4299 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
| 4300 | TG3_PHY_REV_BCM5401_B0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | !(bmsr & BMSR_LSTATUS) && |
| 4302 | tp->link_config.active_speed == SPEED_1000) { |
| 4303 | err = tg3_phy_reset(tp); |
| 4304 | if (!err) |
| 4305 | err = tg3_init_5401phy_dsp(tp); |
| 4306 | if (err) |
| 4307 | return err; |
| 4308 | } |
| 4309 | } |
| 4310 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 4311 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { |
| 4312 | /* 5701 {A0,B0} CRC bug workaround */ |
| 4313 | tg3_writephy(tp, 0x15, 0x0a75); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4314 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
| 4315 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 4316 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | /* Clear pending interrupts... */ |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4320 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
| 4321 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4323 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4325 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
| 4327 | |
| 4328 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 4329 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 4330 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
| 4331 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 4332 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 4333 | else |
| 4334 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); |
| 4335 | } |
| 4336 | |
| 4337 | current_link_up = 0; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 4338 | current_speed = SPEED_UNKNOWN; |
| 4339 | current_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4340 | tp->phy_flags &= ~TG3_PHYFLG_MDIX_STATE; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4341 | tp->link_config.rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4343 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 4344 | err = tg3_phy_auxctl_read(tp, |
| 4345 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4346 | &val); |
| 4347 | if (!err && !(val & (1 << 10))) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4348 | tg3_phy_auxctl_write(tp, |
| 4349 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4350 | val | (1 << 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | goto relink; |
| 4352 | } |
| 4353 | } |
| 4354 | |
| 4355 | bmsr = 0; |
| 4356 | for (i = 0; i < 100; i++) { |
| 4357 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4358 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4359 | (bmsr & BMSR_LSTATUS)) |
| 4360 | break; |
| 4361 | udelay(40); |
| 4362 | } |
| 4363 | |
| 4364 | if (bmsr & BMSR_LSTATUS) { |
| 4365 | u32 aux_stat, bmcr; |
| 4366 | |
| 4367 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); |
| 4368 | for (i = 0; i < 2000; i++) { |
| 4369 | udelay(10); |
| 4370 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && |
| 4371 | aux_stat) |
| 4372 | break; |
| 4373 | } |
| 4374 | |
| 4375 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, |
| 4376 | ¤t_speed, |
| 4377 | ¤t_duplex); |
| 4378 | |
| 4379 | bmcr = 0; |
| 4380 | for (i = 0; i < 200; i++) { |
| 4381 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4382 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) |
| 4383 | continue; |
| 4384 | if (bmcr && bmcr != 0x7fff) |
| 4385 | break; |
| 4386 | udelay(10); |
| 4387 | } |
| 4388 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4389 | lcl_adv = 0; |
| 4390 | rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4392 | tp->link_config.active_speed = current_speed; |
| 4393 | tp->link_config.active_duplex = current_duplex; |
| 4394 | |
| 4395 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 4396 | if ((bmcr & BMCR_ANENABLE) && |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4397 | tg3_phy_copper_an_config_ok(tp, &lcl_adv) && |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4398 | tg3_phy_copper_fetch_rmtadv(tp, &rmt_adv)) |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4399 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | } else { |
| 4401 | if (!(bmcr & BMCR_ANENABLE) && |
| 4402 | tp->link_config.speed == current_speed && |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4403 | tp->link_config.duplex == current_duplex && |
| 4404 | tp->link_config.flowctrl == |
| 4405 | tp->link_config.active_flowctrl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | } |
| 4408 | } |
| 4409 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4410 | if (current_link_up == 1 && |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4411 | tp->link_config.active_duplex == DUPLEX_FULL) { |
| 4412 | u32 reg, bit; |
| 4413 | |
| 4414 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 4415 | reg = MII_TG3_FET_GEN_STAT; |
| 4416 | bit = MII_TG3_FET_GEN_STAT_MDIXSTAT; |
| 4417 | } else { |
| 4418 | reg = MII_TG3_EXT_STAT; |
| 4419 | bit = MII_TG3_EXT_STAT_MDIX; |
| 4420 | } |
| 4421 | |
| 4422 | if (!tg3_readphy(tp, reg, &val) && (val & bit)) |
| 4423 | tp->phy_flags |= TG3_PHYFLG_MDIX_STATE; |
| 4424 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4425 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4426 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | } |
| 4428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | relink: |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 4430 | 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] | 4431 | tg3_phy_copper_begin(tp); |
| 4432 | |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4433 | tg3_readphy(tp, MII_BMSR, &bmsr); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 4434 | if ((!tg3_readphy(tp, MII_BMSR, &bmsr) && (bmsr & BMSR_LSTATUS)) || |
| 4435 | (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | current_link_up = 1; |
| 4437 | } |
| 4438 | |
| 4439 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 4440 | if (current_link_up == 1) { |
| 4441 | if (tp->link_config.active_speed == SPEED_100 || |
| 4442 | tp->link_config.active_speed == SPEED_10) |
| 4443 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4444 | else |
| 4445 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4446 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 4447 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4448 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4450 | |
| 4451 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 4452 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 4453 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 4454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4456 | if (current_link_up == 1 && |
| 4457 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4459 | else |
| 4460 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | /* ??? Without this setting Netgear GA302T PHY does not |
| 4464 | * ??? send/receive packets... |
| 4465 | */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4466 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
| 4468 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
| 4469 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 4470 | udelay(80); |
| 4471 | } |
| 4472 | |
| 4473 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4474 | udelay(40); |
| 4475 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4476 | tg3_phy_eee_adjust(tp, current_link_up); |
| 4477 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4478 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | /* Polled via timer. */ |
| 4480 | tw32_f(MAC_EVENT, 0); |
| 4481 | } else { |
| 4482 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4483 | } |
| 4484 | udelay(40); |
| 4485 | |
| 4486 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && |
| 4487 | current_link_up == 1 && |
| 4488 | tp->link_config.active_speed == SPEED_1000 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4489 | (tg3_flag(tp, PCIX_MODE) || tg3_flag(tp, PCI_HIGH_SPEED))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | udelay(120); |
| 4491 | tw32_f(MAC_STATUS, |
| 4492 | (MAC_STATUS_SYNC_CHANGED | |
| 4493 | MAC_STATUS_CFG_CHANGED)); |
| 4494 | udelay(40); |
| 4495 | tg3_write_mem(tp, |
| 4496 | NIC_SRAM_FIRMWARE_MBOX, |
| 4497 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); |
| 4498 | } |
| 4499 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4500 | /* Prevent send BD corruption. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4501 | if (tg3_flag(tp, CLKREQ_BUG)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4502 | if (tp->link_config.active_speed == SPEED_100 || |
| 4503 | tp->link_config.active_speed == SPEED_10) |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 4504 | pcie_capability_clear_word(tp->pdev, PCI_EXP_LNKCTL, |
| 4505 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4506 | else |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 4507 | pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL, |
| 4508 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4509 | } |
| 4510 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 4511 | tg3_test_and_report_link_chg(tp, current_link_up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | |
| 4513 | return 0; |
| 4514 | } |
| 4515 | |
| 4516 | struct tg3_fiber_aneginfo { |
| 4517 | int state; |
| 4518 | #define ANEG_STATE_UNKNOWN 0 |
| 4519 | #define ANEG_STATE_AN_ENABLE 1 |
| 4520 | #define ANEG_STATE_RESTART_INIT 2 |
| 4521 | #define ANEG_STATE_RESTART 3 |
| 4522 | #define ANEG_STATE_DISABLE_LINK_OK 4 |
| 4523 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 |
| 4524 | #define ANEG_STATE_ABILITY_DETECT 6 |
| 4525 | #define ANEG_STATE_ACK_DETECT_INIT 7 |
| 4526 | #define ANEG_STATE_ACK_DETECT 8 |
| 4527 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 |
| 4528 | #define ANEG_STATE_COMPLETE_ACK 10 |
| 4529 | #define ANEG_STATE_IDLE_DETECT_INIT 11 |
| 4530 | #define ANEG_STATE_IDLE_DETECT 12 |
| 4531 | #define ANEG_STATE_LINK_OK 13 |
| 4532 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 |
| 4533 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 |
| 4534 | |
| 4535 | u32 flags; |
| 4536 | #define MR_AN_ENABLE 0x00000001 |
| 4537 | #define MR_RESTART_AN 0x00000002 |
| 4538 | #define MR_AN_COMPLETE 0x00000004 |
| 4539 | #define MR_PAGE_RX 0x00000008 |
| 4540 | #define MR_NP_LOADED 0x00000010 |
| 4541 | #define MR_TOGGLE_TX 0x00000020 |
| 4542 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 |
| 4543 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 |
| 4544 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 |
| 4545 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 |
| 4546 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 |
| 4547 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 |
| 4548 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 |
| 4549 | #define MR_TOGGLE_RX 0x00002000 |
| 4550 | #define MR_NP_RX 0x00004000 |
| 4551 | |
| 4552 | #define MR_LINK_OK 0x80000000 |
| 4553 | |
| 4554 | unsigned long link_time, cur_time; |
| 4555 | |
| 4556 | u32 ability_match_cfg; |
| 4557 | int ability_match_count; |
| 4558 | |
| 4559 | char ability_match, idle_match, ack_match; |
| 4560 | |
| 4561 | u32 txconfig, rxconfig; |
| 4562 | #define ANEG_CFG_NP 0x00000080 |
| 4563 | #define ANEG_CFG_ACK 0x00000040 |
| 4564 | #define ANEG_CFG_RF2 0x00000020 |
| 4565 | #define ANEG_CFG_RF1 0x00000010 |
| 4566 | #define ANEG_CFG_PS2 0x00000001 |
| 4567 | #define ANEG_CFG_PS1 0x00008000 |
| 4568 | #define ANEG_CFG_HD 0x00004000 |
| 4569 | #define ANEG_CFG_FD 0x00002000 |
| 4570 | #define ANEG_CFG_INVAL 0x00001f06 |
| 4571 | |
| 4572 | }; |
| 4573 | #define ANEG_OK 0 |
| 4574 | #define ANEG_DONE 1 |
| 4575 | #define ANEG_TIMER_ENAB 2 |
| 4576 | #define ANEG_FAILED -1 |
| 4577 | |
| 4578 | #define ANEG_STATE_SETTLE_TIME 10000 |
| 4579 | |
| 4580 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, |
| 4581 | struct tg3_fiber_aneginfo *ap) |
| 4582 | { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4583 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | unsigned long delta; |
| 4585 | u32 rx_cfg_reg; |
| 4586 | int ret; |
| 4587 | |
| 4588 | if (ap->state == ANEG_STATE_UNKNOWN) { |
| 4589 | ap->rxconfig = 0; |
| 4590 | ap->link_time = 0; |
| 4591 | ap->cur_time = 0; |
| 4592 | ap->ability_match_cfg = 0; |
| 4593 | ap->ability_match_count = 0; |
| 4594 | ap->ability_match = 0; |
| 4595 | ap->idle_match = 0; |
| 4596 | ap->ack_match = 0; |
| 4597 | } |
| 4598 | ap->cur_time++; |
| 4599 | |
| 4600 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { |
| 4601 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); |
| 4602 | |
| 4603 | if (rx_cfg_reg != ap->ability_match_cfg) { |
| 4604 | ap->ability_match_cfg = rx_cfg_reg; |
| 4605 | ap->ability_match = 0; |
| 4606 | ap->ability_match_count = 0; |
| 4607 | } else { |
| 4608 | if (++ap->ability_match_count > 1) { |
| 4609 | ap->ability_match = 1; |
| 4610 | ap->ability_match_cfg = rx_cfg_reg; |
| 4611 | } |
| 4612 | } |
| 4613 | if (rx_cfg_reg & ANEG_CFG_ACK) |
| 4614 | ap->ack_match = 1; |
| 4615 | else |
| 4616 | ap->ack_match = 0; |
| 4617 | |
| 4618 | ap->idle_match = 0; |
| 4619 | } else { |
| 4620 | ap->idle_match = 1; |
| 4621 | ap->ability_match_cfg = 0; |
| 4622 | ap->ability_match_count = 0; |
| 4623 | ap->ability_match = 0; |
| 4624 | ap->ack_match = 0; |
| 4625 | |
| 4626 | rx_cfg_reg = 0; |
| 4627 | } |
| 4628 | |
| 4629 | ap->rxconfig = rx_cfg_reg; |
| 4630 | ret = ANEG_OK; |
| 4631 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 4632 | switch (ap->state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | case ANEG_STATE_UNKNOWN: |
| 4634 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) |
| 4635 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4636 | |
| 4637 | /* fallthru */ |
| 4638 | case ANEG_STATE_AN_ENABLE: |
| 4639 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); |
| 4640 | if (ap->flags & MR_AN_ENABLE) { |
| 4641 | ap->link_time = 0; |
| 4642 | ap->cur_time = 0; |
| 4643 | ap->ability_match_cfg = 0; |
| 4644 | ap->ability_match_count = 0; |
| 4645 | ap->ability_match = 0; |
| 4646 | ap->idle_match = 0; |
| 4647 | ap->ack_match = 0; |
| 4648 | |
| 4649 | ap->state = ANEG_STATE_RESTART_INIT; |
| 4650 | } else { |
| 4651 | ap->state = ANEG_STATE_DISABLE_LINK_OK; |
| 4652 | } |
| 4653 | break; |
| 4654 | |
| 4655 | case ANEG_STATE_RESTART_INIT: |
| 4656 | ap->link_time = ap->cur_time; |
| 4657 | ap->flags &= ~(MR_NP_LOADED); |
| 4658 | ap->txconfig = 0; |
| 4659 | tw32(MAC_TX_AUTO_NEG, 0); |
| 4660 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4661 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4662 | udelay(40); |
| 4663 | |
| 4664 | ret = ANEG_TIMER_ENAB; |
| 4665 | ap->state = ANEG_STATE_RESTART; |
| 4666 | |
| 4667 | /* fallthru */ |
| 4668 | case ANEG_STATE_RESTART: |
| 4669 | delta = ap->cur_time - ap->link_time; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4670 | if (delta > ANEG_STATE_SETTLE_TIME) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4672 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | ret = ANEG_TIMER_ENAB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | break; |
| 4675 | |
| 4676 | case ANEG_STATE_DISABLE_LINK_OK: |
| 4677 | ret = ANEG_DONE; |
| 4678 | break; |
| 4679 | |
| 4680 | case ANEG_STATE_ABILITY_DETECT_INIT: |
| 4681 | ap->flags &= ~(MR_TOGGLE_TX); |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4682 | ap->txconfig = ANEG_CFG_FD; |
| 4683 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 4684 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 4685 | ap->txconfig |= ANEG_CFG_PS1; |
| 4686 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 4687 | ap->txconfig |= ANEG_CFG_PS2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4688 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 4689 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4690 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4691 | udelay(40); |
| 4692 | |
| 4693 | ap->state = ANEG_STATE_ABILITY_DETECT; |
| 4694 | break; |
| 4695 | |
| 4696 | case ANEG_STATE_ABILITY_DETECT: |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4697 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | break; |
| 4700 | |
| 4701 | case ANEG_STATE_ACK_DETECT_INIT: |
| 4702 | ap->txconfig |= ANEG_CFG_ACK; |
| 4703 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 4704 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 4705 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4706 | udelay(40); |
| 4707 | |
| 4708 | ap->state = ANEG_STATE_ACK_DETECT; |
| 4709 | |
| 4710 | /* fallthru */ |
| 4711 | case ANEG_STATE_ACK_DETECT: |
| 4712 | if (ap->ack_match != 0) { |
| 4713 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == |
| 4714 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { |
| 4715 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; |
| 4716 | } else { |
| 4717 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4718 | } |
| 4719 | } else if (ap->ability_match != 0 && |
| 4720 | ap->rxconfig == 0) { |
| 4721 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4722 | } |
| 4723 | break; |
| 4724 | |
| 4725 | case ANEG_STATE_COMPLETE_ACK_INIT: |
| 4726 | if (ap->rxconfig & ANEG_CFG_INVAL) { |
| 4727 | ret = ANEG_FAILED; |
| 4728 | break; |
| 4729 | } |
| 4730 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | |
| 4731 | MR_LP_ADV_HALF_DUPLEX | |
| 4732 | MR_LP_ADV_SYM_PAUSE | |
| 4733 | MR_LP_ADV_ASYM_PAUSE | |
| 4734 | MR_LP_ADV_REMOTE_FAULT1 | |
| 4735 | MR_LP_ADV_REMOTE_FAULT2 | |
| 4736 | MR_LP_ADV_NEXT_PAGE | |
| 4737 | MR_TOGGLE_RX | |
| 4738 | MR_NP_RX); |
| 4739 | if (ap->rxconfig & ANEG_CFG_FD) |
| 4740 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; |
| 4741 | if (ap->rxconfig & ANEG_CFG_HD) |
| 4742 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; |
| 4743 | if (ap->rxconfig & ANEG_CFG_PS1) |
| 4744 | ap->flags |= MR_LP_ADV_SYM_PAUSE; |
| 4745 | if (ap->rxconfig & ANEG_CFG_PS2) |
| 4746 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; |
| 4747 | if (ap->rxconfig & ANEG_CFG_RF1) |
| 4748 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; |
| 4749 | if (ap->rxconfig & ANEG_CFG_RF2) |
| 4750 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; |
| 4751 | if (ap->rxconfig & ANEG_CFG_NP) |
| 4752 | ap->flags |= MR_LP_ADV_NEXT_PAGE; |
| 4753 | |
| 4754 | ap->link_time = ap->cur_time; |
| 4755 | |
| 4756 | ap->flags ^= (MR_TOGGLE_TX); |
| 4757 | if (ap->rxconfig & 0x0008) |
| 4758 | ap->flags |= MR_TOGGLE_RX; |
| 4759 | if (ap->rxconfig & ANEG_CFG_NP) |
| 4760 | ap->flags |= MR_NP_RX; |
| 4761 | ap->flags |= MR_PAGE_RX; |
| 4762 | |
| 4763 | ap->state = ANEG_STATE_COMPLETE_ACK; |
| 4764 | ret = ANEG_TIMER_ENAB; |
| 4765 | break; |
| 4766 | |
| 4767 | case ANEG_STATE_COMPLETE_ACK: |
| 4768 | if (ap->ability_match != 0 && |
| 4769 | ap->rxconfig == 0) { |
| 4770 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4771 | break; |
| 4772 | } |
| 4773 | delta = ap->cur_time - ap->link_time; |
| 4774 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 4775 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { |
| 4776 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 4777 | } else { |
| 4778 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && |
| 4779 | !(ap->flags & MR_NP_RX)) { |
| 4780 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 4781 | } else { |
| 4782 | ret = ANEG_FAILED; |
| 4783 | } |
| 4784 | } |
| 4785 | } |
| 4786 | break; |
| 4787 | |
| 4788 | case ANEG_STATE_IDLE_DETECT_INIT: |
| 4789 | ap->link_time = ap->cur_time; |
| 4790 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 4791 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4792 | udelay(40); |
| 4793 | |
| 4794 | ap->state = ANEG_STATE_IDLE_DETECT; |
| 4795 | ret = ANEG_TIMER_ENAB; |
| 4796 | break; |
| 4797 | |
| 4798 | case ANEG_STATE_IDLE_DETECT: |
| 4799 | if (ap->ability_match != 0 && |
| 4800 | ap->rxconfig == 0) { |
| 4801 | ap->state = ANEG_STATE_AN_ENABLE; |
| 4802 | break; |
| 4803 | } |
| 4804 | delta = ap->cur_time - ap->link_time; |
| 4805 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 4806 | /* XXX another gem from the Broadcom driver :( */ |
| 4807 | ap->state = ANEG_STATE_LINK_OK; |
| 4808 | } |
| 4809 | break; |
| 4810 | |
| 4811 | case ANEG_STATE_LINK_OK: |
| 4812 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); |
| 4813 | ret = ANEG_DONE; |
| 4814 | break; |
| 4815 | |
| 4816 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: |
| 4817 | /* ??? unimplemented */ |
| 4818 | break; |
| 4819 | |
| 4820 | case ANEG_STATE_NEXT_PAGE_WAIT: |
| 4821 | /* ??? unimplemented */ |
| 4822 | break; |
| 4823 | |
| 4824 | default: |
| 4825 | ret = ANEG_FAILED; |
| 4826 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4827 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | |
| 4829 | return ret; |
| 4830 | } |
| 4831 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4832 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4833 | { |
| 4834 | int res = 0; |
| 4835 | struct tg3_fiber_aneginfo aninfo; |
| 4836 | int status = ANEG_FAILED; |
| 4837 | unsigned int tick; |
| 4838 | u32 tmp; |
| 4839 | |
| 4840 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 4841 | |
| 4842 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
| 4843 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); |
| 4844 | udelay(40); |
| 4845 | |
| 4846 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); |
| 4847 | udelay(40); |
| 4848 | |
| 4849 | memset(&aninfo, 0, sizeof(aninfo)); |
| 4850 | aninfo.flags |= MR_AN_ENABLE; |
| 4851 | aninfo.state = ANEG_STATE_UNKNOWN; |
| 4852 | aninfo.cur_time = 0; |
| 4853 | tick = 0; |
| 4854 | while (++tick < 195000) { |
| 4855 | status = tg3_fiber_aneg_smachine(tp, &aninfo); |
| 4856 | if (status == ANEG_DONE || status == ANEG_FAILED) |
| 4857 | break; |
| 4858 | |
| 4859 | udelay(1); |
| 4860 | } |
| 4861 | |
| 4862 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 4863 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4864 | udelay(40); |
| 4865 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4866 | *txflags = aninfo.txconfig; |
| 4867 | *rxflags = aninfo.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | |
| 4869 | if (status == ANEG_DONE && |
| 4870 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | |
| 4871 | MR_LP_ADV_FULL_DUPLEX))) |
| 4872 | res = 1; |
| 4873 | |
| 4874 | return res; |
| 4875 | } |
| 4876 | |
| 4877 | static void tg3_init_bcm8002(struct tg3 *tp) |
| 4878 | { |
| 4879 | u32 mac_status = tr32(MAC_STATUS); |
| 4880 | int i; |
| 4881 | |
| 4882 | /* Reset when initting first time or we have a link. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4883 | if (tg3_flag(tp, INIT_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 4885 | return; |
| 4886 | |
| 4887 | /* Set PLL lock range. */ |
| 4888 | tg3_writephy(tp, 0x16, 0x8007); |
| 4889 | |
| 4890 | /* SW reset */ |
| 4891 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); |
| 4892 | |
| 4893 | /* Wait for reset to complete. */ |
| 4894 | /* XXX schedule_timeout() ... */ |
| 4895 | for (i = 0; i < 500; i++) |
| 4896 | udelay(10); |
| 4897 | |
| 4898 | /* Config mode; select PMA/Ch 1 regs. */ |
| 4899 | tg3_writephy(tp, 0x10, 0x8411); |
| 4900 | |
| 4901 | /* Enable auto-lock and comdet, select txclk for tx. */ |
| 4902 | tg3_writephy(tp, 0x11, 0x0a10); |
| 4903 | |
| 4904 | tg3_writephy(tp, 0x18, 0x00a0); |
| 4905 | tg3_writephy(tp, 0x16, 0x41ff); |
| 4906 | |
| 4907 | /* Assert and deassert POR. */ |
| 4908 | tg3_writephy(tp, 0x13, 0x0400); |
| 4909 | udelay(40); |
| 4910 | tg3_writephy(tp, 0x13, 0x0000); |
| 4911 | |
| 4912 | tg3_writephy(tp, 0x11, 0x0a50); |
| 4913 | udelay(40); |
| 4914 | tg3_writephy(tp, 0x11, 0x0a10); |
| 4915 | |
| 4916 | /* Wait for signal to stabilize */ |
| 4917 | /* XXX schedule_timeout() ... */ |
| 4918 | for (i = 0; i < 15000; i++) |
| 4919 | udelay(10); |
| 4920 | |
| 4921 | /* Deselect the channel register so we can read the PHYID |
| 4922 | * later. |
| 4923 | */ |
| 4924 | tg3_writephy(tp, 0x10, 0x8011); |
| 4925 | } |
| 4926 | |
| 4927 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
| 4928 | { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4929 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | u32 sg_dig_ctrl, sg_dig_status; |
| 4931 | u32 serdes_cfg, expected_sg_dig_ctrl; |
| 4932 | int workaround, port_a; |
| 4933 | int current_link_up; |
| 4934 | |
| 4935 | serdes_cfg = 0; |
| 4936 | expected_sg_dig_ctrl = 0; |
| 4937 | workaround = 0; |
| 4938 | port_a = 1; |
| 4939 | current_link_up = 0; |
| 4940 | |
| 4941 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && |
| 4942 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { |
| 4943 | workaround = 1; |
| 4944 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 4945 | port_a = 0; |
| 4946 | |
| 4947 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ |
| 4948 | /* preserve bits 20-23 for voltage regulator */ |
| 4949 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; |
| 4950 | } |
| 4951 | |
| 4952 | sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 4953 | |
| 4954 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4955 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4956 | if (workaround) { |
| 4957 | u32 val = serdes_cfg; |
| 4958 | |
| 4959 | if (port_a) |
| 4960 | val |= 0xc010000; |
| 4961 | else |
| 4962 | val |= 0x4010000; |
| 4963 | tw32_f(MAC_SERDES_CFG, val); |
| 4964 | } |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4965 | |
| 4966 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | } |
| 4968 | if (mac_status & MAC_STATUS_PCS_SYNCED) { |
| 4969 | tg3_setup_flow_control(tp, 0, 0); |
| 4970 | current_link_up = 1; |
| 4971 | } |
| 4972 | goto out; |
| 4973 | } |
| 4974 | |
| 4975 | /* Want auto-negotiation. */ |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4976 | 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] | 4977 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 4978 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 4979 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 4980 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; |
| 4981 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 4982 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | |
| 4984 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4985 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4986 | tp->serdes_counter && |
| 4987 | ((mac_status & (MAC_STATUS_PCS_SYNCED | |
| 4988 | MAC_STATUS_RCVD_CFG)) == |
| 4989 | MAC_STATUS_PCS_SYNCED)) { |
| 4990 | tp->serdes_counter--; |
| 4991 | current_link_up = 1; |
| 4992 | goto out; |
| 4993 | } |
| 4994 | restart_autoneg: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | if (workaround) |
| 4996 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 4997 | 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] | 4998 | udelay(5); |
| 4999 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); |
| 5000 | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5001 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5002 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
| 5004 | MAC_STATUS_SIGNAL_DET)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5005 | sg_dig_status = tr32(SG_DIG_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | mac_status = tr32(MAC_STATUS); |
| 5007 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5008 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5009 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5010 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5012 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) |
| 5013 | local_adv |= ADVERTISE_1000XPAUSE; |
| 5014 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) |
| 5015 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 5016 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5017 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5018 | remote_adv |= LPA_1000XPAUSE; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5019 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5020 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5022 | tp->link_config.rmt_adv = |
| 5023 | mii_adv_to_ethtool_adv_x(remote_adv); |
| 5024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5026 | current_link_up = 1; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5027 | tp->serdes_counter = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5028 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5029 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5030 | if (tp->serdes_counter) |
| 5031 | tp->serdes_counter--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5032 | else { |
| 5033 | if (workaround) { |
| 5034 | u32 val = serdes_cfg; |
| 5035 | |
| 5036 | if (port_a) |
| 5037 | val |= 0xc010000; |
| 5038 | else |
| 5039 | val |= 0x4010000; |
| 5040 | |
| 5041 | tw32_f(MAC_SERDES_CFG, val); |
| 5042 | } |
| 5043 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5044 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | udelay(40); |
| 5046 | |
| 5047 | /* Link parallel detection - link is up */ |
| 5048 | /* only if we have PCS_SYNC and not */ |
| 5049 | /* receiving config code words */ |
| 5050 | mac_status = tr32(MAC_STATUS); |
| 5051 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && |
| 5052 | !(mac_status & MAC_STATUS_RCVD_CFG)) { |
| 5053 | tg3_setup_flow_control(tp, 0, 0); |
| 5054 | current_link_up = 1; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5055 | tp->phy_flags |= |
| 5056 | TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5057 | tp->serdes_counter = |
| 5058 | SERDES_PARALLEL_DET_TIMEOUT; |
| 5059 | } else |
| 5060 | goto restart_autoneg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5061 | } |
| 5062 | } |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5063 | } else { |
| 5064 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5065 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5066 | } |
| 5067 | |
| 5068 | out: |
| 5069 | return current_link_up; |
| 5070 | } |
| 5071 | |
| 5072 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
| 5073 | { |
| 5074 | int current_link_up = 0; |
| 5075 | |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 5076 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5078 | |
| 5079 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5080 | u32 txflags, rxflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 5082 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5083 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
| 5084 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5086 | if (txflags & ANEG_CFG_PS1) |
| 5087 | local_adv |= ADVERTISE_1000XPAUSE; |
| 5088 | if (txflags & ANEG_CFG_PS2) |
| 5089 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 5090 | |
| 5091 | if (rxflags & MR_LP_ADV_SYM_PAUSE) |
| 5092 | remote_adv |= LPA_1000XPAUSE; |
| 5093 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) |
| 5094 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5096 | tp->link_config.rmt_adv = |
| 5097 | mii_adv_to_ethtool_adv_x(remote_adv); |
| 5098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5099 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5101 | current_link_up = 1; |
| 5102 | } |
| 5103 | for (i = 0; i < 30; i++) { |
| 5104 | udelay(20); |
| 5105 | tw32_f(MAC_STATUS, |
| 5106 | (MAC_STATUS_SYNC_CHANGED | |
| 5107 | MAC_STATUS_CFG_CHANGED)); |
| 5108 | udelay(40); |
| 5109 | if ((tr32(MAC_STATUS) & |
| 5110 | (MAC_STATUS_SYNC_CHANGED | |
| 5111 | MAC_STATUS_CFG_CHANGED)) == 0) |
| 5112 | break; |
| 5113 | } |
| 5114 | |
| 5115 | mac_status = tr32(MAC_STATUS); |
| 5116 | if (current_link_up == 0 && |
| 5117 | (mac_status & MAC_STATUS_PCS_SYNCED) && |
| 5118 | !(mac_status & MAC_STATUS_RCVD_CFG)) |
| 5119 | current_link_up = 1; |
| 5120 | } else { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5121 | tg3_setup_flow_control(tp, 0, 0); |
| 5122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | /* Forcing 1000FD link up. */ |
| 5124 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | |
| 5126 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); |
| 5127 | udelay(40); |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 5128 | |
| 5129 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5130 | udelay(40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | out: |
| 5134 | return current_link_up; |
| 5135 | } |
| 5136 | |
| 5137 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) |
| 5138 | { |
| 5139 | u32 orig_pause_cfg; |
| 5140 | u16 orig_active_speed; |
| 5141 | u8 orig_active_duplex; |
| 5142 | u32 mac_status; |
| 5143 | int current_link_up; |
| 5144 | int i; |
| 5145 | |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 5146 | orig_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | orig_active_speed = tp->link_config.active_speed; |
| 5148 | orig_active_duplex = tp->link_config.active_duplex; |
| 5149 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5150 | if (!tg3_flag(tp, HW_AUTONEG) && |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5151 | tp->link_up && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5152 | tg3_flag(tp, INIT_COMPLETE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5153 | mac_status = tr32(MAC_STATUS); |
| 5154 | mac_status &= (MAC_STATUS_PCS_SYNCED | |
| 5155 | MAC_STATUS_SIGNAL_DET | |
| 5156 | MAC_STATUS_CFG_CHANGED | |
| 5157 | MAC_STATUS_RCVD_CFG); |
| 5158 | if (mac_status == (MAC_STATUS_PCS_SYNCED | |
| 5159 | MAC_STATUS_SIGNAL_DET)) { |
| 5160 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5161 | MAC_STATUS_CFG_CHANGED)); |
| 5162 | return 0; |
| 5163 | } |
| 5164 | } |
| 5165 | |
| 5166 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 5167 | |
| 5168 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 5169 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 5170 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5171 | udelay(40); |
| 5172 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 5173 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | tg3_init_bcm8002(tp); |
| 5175 | |
| 5176 | /* Enable link change event even when serdes polling. */ |
| 5177 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5178 | udelay(40); |
| 5179 | |
| 5180 | current_link_up = 0; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5181 | tp->link_config.rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | mac_status = tr32(MAC_STATUS); |
| 5183 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5184 | if (tg3_flag(tp, HW_AUTONEG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5185 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
| 5186 | else |
| 5187 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); |
| 5188 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5189 | tp->napi[0].hw_status->status = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5190 | (SD_STATUS_UPDATED | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5191 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5192 | |
| 5193 | for (i = 0; i < 100; i++) { |
| 5194 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5195 | MAC_STATUS_CFG_CHANGED)); |
| 5196 | udelay(5); |
| 5197 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5198 | MAC_STATUS_CFG_CHANGED | |
| 5199 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5200 | break; |
| 5201 | } |
| 5202 | |
| 5203 | mac_status = tr32(MAC_STATUS); |
| 5204 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { |
| 5205 | current_link_up = 0; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5206 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 5207 | tp->serdes_counter == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | tw32_f(MAC_MODE, (tp->mac_mode | |
| 5209 | MAC_MODE_SEND_CONFIGS)); |
| 5210 | udelay(1); |
| 5211 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5212 | } |
| 5213 | } |
| 5214 | |
| 5215 | if (current_link_up == 1) { |
| 5216 | tp->link_config.active_speed = SPEED_1000; |
| 5217 | tp->link_config.active_duplex = DUPLEX_FULL; |
| 5218 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5219 | LED_CTRL_LNKLED_OVERRIDE | |
| 5220 | LED_CTRL_1000MBPS_ON)); |
| 5221 | } else { |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 5222 | tp->link_config.active_speed = SPEED_UNKNOWN; |
| 5223 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5224 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5225 | LED_CTRL_LNKLED_OVERRIDE | |
| 5226 | LED_CTRL_TRAFFIC_OVERRIDE)); |
| 5227 | } |
| 5228 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5229 | if (!tg3_test_and_report_link_chg(tp, current_link_up)) { |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 5230 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5231 | if (orig_pause_cfg != now_pause_cfg || |
| 5232 | orig_active_speed != tp->link_config.active_speed || |
| 5233 | orig_active_duplex != tp->link_config.active_duplex) |
| 5234 | tg3_link_report(tp); |
| 5235 | } |
| 5236 | |
| 5237 | return 0; |
| 5238 | } |
| 5239 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5240 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
| 5241 | { |
| 5242 | int current_link_up, err = 0; |
| 5243 | u32 bmsr, bmcr; |
| 5244 | u16 current_speed; |
| 5245 | u8 current_duplex; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5246 | u32 local_adv, remote_adv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5247 | |
| 5248 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 5249 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5250 | udelay(40); |
| 5251 | |
| 5252 | tw32(MAC_EVENT, 0); |
| 5253 | |
| 5254 | tw32_f(MAC_STATUS, |
| 5255 | (MAC_STATUS_SYNC_CHANGED | |
| 5256 | MAC_STATUS_CFG_CHANGED | |
| 5257 | MAC_STATUS_MI_COMPLETION | |
| 5258 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 5259 | udelay(40); |
| 5260 | |
| 5261 | if (force_reset) |
| 5262 | tg3_phy_reset(tp); |
| 5263 | |
| 5264 | current_link_up = 0; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 5265 | current_speed = SPEED_UNKNOWN; |
| 5266 | current_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5267 | tp->link_config.rmt_adv = 0; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5268 | |
| 5269 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5270 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 5271 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 5272 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5273 | bmsr |= BMSR_LSTATUS; |
| 5274 | else |
| 5275 | bmsr &= ~BMSR_LSTATUS; |
| 5276 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5277 | |
| 5278 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5279 | |
| 5280 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5281 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5282 | /* do nothing, just check for link up at the end */ |
| 5283 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5284 | u32 adv, newadv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5285 | |
| 5286 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5287 | newadv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
| 5288 | ADVERTISE_1000XPAUSE | |
| 5289 | ADVERTISE_1000XPSE_ASYM | |
| 5290 | ADVERTISE_SLCT); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5291 | |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5292 | newadv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
Matt Carlson | 37f0702 | 2011-11-17 14:30:55 +0000 | [diff] [blame] | 5293 | newadv |= ethtool_adv_to_mii_adv_x(tp->link_config.advertising); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5294 | |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5295 | if ((newadv != adv) || !(bmcr & BMCR_ANENABLE)) { |
| 5296 | tg3_writephy(tp, MII_ADVERTISE, newadv); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5297 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 5298 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 5299 | |
| 5300 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5301 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5302 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5303 | |
| 5304 | return err; |
| 5305 | } |
| 5306 | } else { |
| 5307 | u32 new_bmcr; |
| 5308 | |
| 5309 | bmcr &= ~BMCR_SPEED1000; |
| 5310 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); |
| 5311 | |
| 5312 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 5313 | new_bmcr |= BMCR_FULLDPLX; |
| 5314 | |
| 5315 | if (new_bmcr != bmcr) { |
| 5316 | /* BMCR_SPEED1000 is a reserved bit that needs |
| 5317 | * to be set on write. |
| 5318 | */ |
| 5319 | new_bmcr |= BMCR_SPEED1000; |
| 5320 | |
| 5321 | /* Force a linkdown */ |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5322 | if (tp->link_up) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5323 | u32 adv; |
| 5324 | |
| 5325 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 5326 | adv &= ~(ADVERTISE_1000XFULL | |
| 5327 | ADVERTISE_1000XHALF | |
| 5328 | ADVERTISE_SLCT); |
| 5329 | tg3_writephy(tp, MII_ADVERTISE, adv); |
| 5330 | tg3_writephy(tp, MII_BMCR, bmcr | |
| 5331 | BMCR_ANRESTART | |
| 5332 | BMCR_ANENABLE); |
| 5333 | udelay(10); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5334 | tg3_carrier_off(tp); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5335 | } |
| 5336 | tg3_writephy(tp, MII_BMCR, new_bmcr); |
| 5337 | bmcr = new_bmcr; |
| 5338 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5339 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 5340 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 5341 | ASIC_REV_5714) { |
| 5342 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5343 | bmsr |= BMSR_LSTATUS; |
| 5344 | else |
| 5345 | bmsr &= ~BMSR_LSTATUS; |
| 5346 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5347 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5348 | } |
| 5349 | } |
| 5350 | |
| 5351 | if (bmsr & BMSR_LSTATUS) { |
| 5352 | current_speed = SPEED_1000; |
| 5353 | current_link_up = 1; |
| 5354 | if (bmcr & BMCR_FULLDPLX) |
| 5355 | current_duplex = DUPLEX_FULL; |
| 5356 | else |
| 5357 | current_duplex = DUPLEX_HALF; |
| 5358 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5359 | local_adv = 0; |
| 5360 | remote_adv = 0; |
| 5361 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5362 | if (bmcr & BMCR_ANENABLE) { |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5363 | u32 common; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5364 | |
| 5365 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); |
| 5366 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); |
| 5367 | common = local_adv & remote_adv; |
| 5368 | if (common & (ADVERTISE_1000XHALF | |
| 5369 | ADVERTISE_1000XFULL)) { |
| 5370 | if (common & ADVERTISE_1000XFULL) |
| 5371 | current_duplex = DUPLEX_FULL; |
| 5372 | else |
| 5373 | current_duplex = DUPLEX_HALF; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5374 | |
| 5375 | tp->link_config.rmt_adv = |
| 5376 | mii_adv_to_ethtool_adv_x(remote_adv); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5377 | } else if (!tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 5378 | /* Link is up via parallel detect */ |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5379 | } else { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5380 | current_link_up = 0; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5381 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5382 | } |
| 5383 | } |
| 5384 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5385 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
| 5386 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5387 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5388 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 5389 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 5390 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 5391 | |
| 5392 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5393 | udelay(40); |
| 5394 | |
| 5395 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5396 | |
| 5397 | tp->link_config.active_speed = current_speed; |
| 5398 | tp->link_config.active_duplex = current_duplex; |
| 5399 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5400 | tg3_test_and_report_link_chg(tp, current_link_up); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5401 | return err; |
| 5402 | } |
| 5403 | |
| 5404 | static void tg3_serdes_parallel_detect(struct tg3 *tp) |
| 5405 | { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5406 | if (tp->serdes_counter) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5407 | /* Give autoneg time to complete. */ |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5408 | tp->serdes_counter--; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5409 | return; |
| 5410 | } |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5411 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5412 | if (!tp->link_up && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5413 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { |
| 5414 | u32 bmcr; |
| 5415 | |
| 5416 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5417 | if (bmcr & BMCR_ANENABLE) { |
| 5418 | u32 phy1, phy2; |
| 5419 | |
| 5420 | /* Select shadow register 0x1f */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5421 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
| 5422 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5423 | |
| 5424 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5425 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 5426 | MII_TG3_DSP_EXP1_INT_STAT); |
| 5427 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 5428 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5429 | |
| 5430 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { |
| 5431 | /* We have signal detect and not receiving |
| 5432 | * config code words, link is up by parallel |
| 5433 | * detection. |
| 5434 | */ |
| 5435 | |
| 5436 | bmcr &= ~BMCR_ANENABLE; |
| 5437 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; |
| 5438 | tg3_writephy(tp, MII_BMCR, bmcr); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5439 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5440 | } |
| 5441 | } |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5442 | } else if (tp->link_up && |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5443 | (tp->link_config.autoneg == AUTONEG_ENABLE) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5444 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5445 | u32 phy2; |
| 5446 | |
| 5447 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5448 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 5449 | MII_TG3_DSP_EXP1_INT_STAT); |
| 5450 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5451 | if (phy2 & 0x20) { |
| 5452 | u32 bmcr; |
| 5453 | |
| 5454 | /* Config code words received, turn on autoneg. */ |
| 5455 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5456 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); |
| 5457 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5458 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5459 | |
| 5460 | } |
| 5461 | } |
| 5462 | } |
| 5463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
| 5465 | { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5466 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5467 | int err; |
| 5468 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5469 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5470 | err = tg3_setup_fiber_phy(tp, force_reset); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5471 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5472 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5473 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | err = tg3_setup_copper_phy(tp, force_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 5476 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5477 | u32 scale; |
Matt Carlson | aa6c91f | 2007-11-12 21:18:04 -0800 | [diff] [blame] | 5478 | |
| 5479 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; |
| 5480 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) |
| 5481 | scale = 65; |
| 5482 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) |
| 5483 | scale = 6; |
| 5484 | else |
| 5485 | scale = 12; |
| 5486 | |
| 5487 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; |
| 5488 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 5489 | tw32(GRC_MISC_CFG, val); |
| 5490 | } |
| 5491 | |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5492 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 5493 | (6 << TX_LENGTHS_IPG_SHIFT); |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 5494 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 5495 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5496 | val |= tr32(MAC_TX_LENGTHS) & |
| 5497 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 5498 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 5499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | if (tp->link_config.active_speed == SPEED_1000 && |
| 5501 | tp->link_config.active_duplex == DUPLEX_HALF) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5502 | tw32(MAC_TX_LENGTHS, val | |
| 5503 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5504 | else |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5505 | tw32(MAC_TX_LENGTHS, val | |
| 5506 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5507 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5508 | if (!tg3_flag(tp, 5705_PLUS)) { |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5509 | if (tp->link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5510 | tw32(HOSTCC_STAT_COAL_TICKS, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 5511 | tp->coal.stats_block_coalesce_usecs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | } else { |
| 5513 | tw32(HOSTCC_STAT_COAL_TICKS, 0); |
| 5514 | } |
| 5515 | } |
| 5516 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5517 | if (tg3_flag(tp, ASPM_WORKAROUND)) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5518 | val = tr32(PCIE_PWR_MGMT_THRESH); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5519 | if (!tp->link_up) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 5520 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
| 5521 | tp->pwrmgmt_thresh; |
| 5522 | else |
| 5523 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 5524 | tw32(PCIE_PWR_MGMT_THRESH, val); |
| 5525 | } |
| 5526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5527 | return err; |
| 5528 | } |
| 5529 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 5530 | /* tp->lock must be held */ |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 5531 | static u64 tg3_refclk_read(struct tg3 *tp) |
| 5532 | { |
| 5533 | u64 stamp = tr32(TG3_EAV_REF_CLCK_LSB); |
| 5534 | return stamp | (u64)tr32(TG3_EAV_REF_CLCK_MSB) << 32; |
| 5535 | } |
| 5536 | |
| 5537 | /* tp->lock must be held */ |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 5538 | static void tg3_refclk_write(struct tg3 *tp, u64 newval) |
| 5539 | { |
| 5540 | tw32(TG3_EAV_REF_CLCK_CTL, TG3_EAV_REF_CLCK_CTL_STOP); |
| 5541 | tw32(TG3_EAV_REF_CLCK_LSB, newval & 0xffffffff); |
| 5542 | tw32(TG3_EAV_REF_CLCK_MSB, newval >> 32); |
| 5543 | tw32_f(TG3_EAV_REF_CLCK_CTL, TG3_EAV_REF_CLCK_CTL_RESUME); |
| 5544 | } |
| 5545 | |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 5546 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync); |
| 5547 | static inline void tg3_full_unlock(struct tg3 *tp); |
| 5548 | static int tg3_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) |
| 5549 | { |
| 5550 | struct tg3 *tp = netdev_priv(dev); |
| 5551 | |
| 5552 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | |
| 5553 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 5554 | SOF_TIMESTAMPING_SOFTWARE | |
| 5555 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 5556 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 5557 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 5558 | |
| 5559 | if (tp->ptp_clock) |
| 5560 | info->phc_index = ptp_clock_index(tp->ptp_clock); |
| 5561 | else |
| 5562 | info->phc_index = -1; |
| 5563 | |
| 5564 | info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); |
| 5565 | |
| 5566 | info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | |
| 5567 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) | |
| 5568 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | |
| 5569 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT); |
| 5570 | return 0; |
| 5571 | } |
| 5572 | |
| 5573 | static int tg3_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) |
| 5574 | { |
| 5575 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 5576 | bool neg_adj = false; |
| 5577 | u32 correction = 0; |
| 5578 | |
| 5579 | if (ppb < 0) { |
| 5580 | neg_adj = true; |
| 5581 | ppb = -ppb; |
| 5582 | } |
| 5583 | |
| 5584 | /* Frequency adjustment is performed using hardware with a 24 bit |
| 5585 | * accumulator and a programmable correction value. On each clk, the |
| 5586 | * correction value gets added to the accumulator and when it |
| 5587 | * overflows, the time counter is incremented/decremented. |
| 5588 | * |
| 5589 | * So conversion from ppb to correction value is |
| 5590 | * ppb * (1 << 24) / 1000000000 |
| 5591 | */ |
| 5592 | correction = div_u64((u64)ppb * (1 << 24), 1000000000ULL) & |
| 5593 | TG3_EAV_REF_CLK_CORRECT_MASK; |
| 5594 | |
| 5595 | tg3_full_lock(tp, 0); |
| 5596 | |
| 5597 | if (correction) |
| 5598 | tw32(TG3_EAV_REF_CLK_CORRECT_CTL, |
| 5599 | TG3_EAV_REF_CLK_CORRECT_EN | |
| 5600 | (neg_adj ? TG3_EAV_REF_CLK_CORRECT_NEG : 0) | correction); |
| 5601 | else |
| 5602 | tw32(TG3_EAV_REF_CLK_CORRECT_CTL, 0); |
| 5603 | |
| 5604 | tg3_full_unlock(tp); |
| 5605 | |
| 5606 | return 0; |
| 5607 | } |
| 5608 | |
| 5609 | static int tg3_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) |
| 5610 | { |
| 5611 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 5612 | |
| 5613 | tg3_full_lock(tp, 0); |
| 5614 | tp->ptp_adjust += delta; |
| 5615 | tg3_full_unlock(tp); |
| 5616 | |
| 5617 | return 0; |
| 5618 | } |
| 5619 | |
| 5620 | static int tg3_ptp_gettime(struct ptp_clock_info *ptp, struct timespec *ts) |
| 5621 | { |
| 5622 | u64 ns; |
| 5623 | u32 remainder; |
| 5624 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 5625 | |
| 5626 | tg3_full_lock(tp, 0); |
| 5627 | ns = tg3_refclk_read(tp); |
| 5628 | ns += tp->ptp_adjust; |
| 5629 | tg3_full_unlock(tp); |
| 5630 | |
| 5631 | ts->tv_sec = div_u64_rem(ns, 1000000000, &remainder); |
| 5632 | ts->tv_nsec = remainder; |
| 5633 | |
| 5634 | return 0; |
| 5635 | } |
| 5636 | |
| 5637 | static int tg3_ptp_settime(struct ptp_clock_info *ptp, |
| 5638 | const struct timespec *ts) |
| 5639 | { |
| 5640 | u64 ns; |
| 5641 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 5642 | |
| 5643 | ns = timespec_to_ns(ts); |
| 5644 | |
| 5645 | tg3_full_lock(tp, 0); |
| 5646 | tg3_refclk_write(tp, ns); |
| 5647 | tp->ptp_adjust = 0; |
| 5648 | tg3_full_unlock(tp); |
| 5649 | |
| 5650 | return 0; |
| 5651 | } |
| 5652 | |
| 5653 | static int tg3_ptp_enable(struct ptp_clock_info *ptp, |
| 5654 | struct ptp_clock_request *rq, int on) |
| 5655 | { |
| 5656 | return -EOPNOTSUPP; |
| 5657 | } |
| 5658 | |
| 5659 | static const struct ptp_clock_info tg3_ptp_caps = { |
| 5660 | .owner = THIS_MODULE, |
| 5661 | .name = "tg3 clock", |
| 5662 | .max_adj = 250000000, |
| 5663 | .n_alarm = 0, |
| 5664 | .n_ext_ts = 0, |
| 5665 | .n_per_out = 0, |
| 5666 | .pps = 0, |
| 5667 | .adjfreq = tg3_ptp_adjfreq, |
| 5668 | .adjtime = tg3_ptp_adjtime, |
| 5669 | .gettime = tg3_ptp_gettime, |
| 5670 | .settime = tg3_ptp_settime, |
| 5671 | .enable = tg3_ptp_enable, |
| 5672 | }; |
| 5673 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 5674 | static void tg3_hwclock_to_timestamp(struct tg3 *tp, u64 hwclock, |
| 5675 | struct skb_shared_hwtstamps *timestamp) |
| 5676 | { |
| 5677 | memset(timestamp, 0, sizeof(struct skb_shared_hwtstamps)); |
| 5678 | timestamp->hwtstamp = ns_to_ktime((hwclock & TG3_TSTAMP_MASK) + |
| 5679 | tp->ptp_adjust); |
| 5680 | } |
| 5681 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 5682 | /* tp->lock must be held */ |
| 5683 | static void tg3_ptp_init(struct tg3 *tp) |
| 5684 | { |
| 5685 | if (!tg3_flag(tp, PTP_CAPABLE)) |
| 5686 | return; |
| 5687 | |
| 5688 | /* Initialize the hardware clock to the system time. */ |
| 5689 | tg3_refclk_write(tp, ktime_to_ns(ktime_get_real())); |
| 5690 | tp->ptp_adjust = 0; |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 5691 | tp->ptp_info = tg3_ptp_caps; |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 5692 | } |
| 5693 | |
| 5694 | /* tp->lock must be held */ |
| 5695 | static void tg3_ptp_resume(struct tg3 *tp) |
| 5696 | { |
| 5697 | if (!tg3_flag(tp, PTP_CAPABLE)) |
| 5698 | return; |
| 5699 | |
| 5700 | tg3_refclk_write(tp, ktime_to_ns(ktime_get_real()) + tp->ptp_adjust); |
| 5701 | tp->ptp_adjust = 0; |
| 5702 | } |
| 5703 | |
| 5704 | static void tg3_ptp_fini(struct tg3 *tp) |
| 5705 | { |
| 5706 | if (!tg3_flag(tp, PTP_CAPABLE) || !tp->ptp_clock) |
| 5707 | return; |
| 5708 | |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 5709 | ptp_clock_unregister(tp->ptp_clock); |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 5710 | tp->ptp_clock = NULL; |
| 5711 | tp->ptp_adjust = 0; |
| 5712 | } |
| 5713 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 5714 | static inline int tg3_irq_sync(struct tg3 *tp) |
| 5715 | { |
| 5716 | return tp->irq_sync; |
| 5717 | } |
| 5718 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5719 | static inline void tg3_rd32_loop(struct tg3 *tp, u32 *dst, u32 off, u32 len) |
| 5720 | { |
| 5721 | int i; |
| 5722 | |
| 5723 | dst = (u32 *)((u8 *)dst + off); |
| 5724 | for (i = 0; i < len; i += sizeof(u32)) |
| 5725 | *dst++ = tr32(off + i); |
| 5726 | } |
| 5727 | |
| 5728 | static void tg3_dump_legacy_regs(struct tg3 *tp, u32 *regs) |
| 5729 | { |
| 5730 | tg3_rd32_loop(tp, regs, TG3PCI_VENDOR, 0xb0); |
| 5731 | tg3_rd32_loop(tp, regs, MAILBOX_INTERRUPT_0, 0x200); |
| 5732 | tg3_rd32_loop(tp, regs, MAC_MODE, 0x4f0); |
| 5733 | tg3_rd32_loop(tp, regs, SNDDATAI_MODE, 0xe0); |
| 5734 | tg3_rd32_loop(tp, regs, SNDDATAC_MODE, 0x04); |
| 5735 | tg3_rd32_loop(tp, regs, SNDBDS_MODE, 0x80); |
| 5736 | tg3_rd32_loop(tp, regs, SNDBDI_MODE, 0x48); |
| 5737 | tg3_rd32_loop(tp, regs, SNDBDC_MODE, 0x04); |
| 5738 | tg3_rd32_loop(tp, regs, RCVLPC_MODE, 0x20); |
| 5739 | tg3_rd32_loop(tp, regs, RCVLPC_SELLST_BASE, 0x15c); |
| 5740 | tg3_rd32_loop(tp, regs, RCVDBDI_MODE, 0x0c); |
| 5741 | tg3_rd32_loop(tp, regs, RCVDBDI_JUMBO_BD, 0x3c); |
| 5742 | tg3_rd32_loop(tp, regs, RCVDBDI_BD_PROD_IDX_0, 0x44); |
| 5743 | tg3_rd32_loop(tp, regs, RCVDCC_MODE, 0x04); |
| 5744 | tg3_rd32_loop(tp, regs, RCVBDI_MODE, 0x20); |
| 5745 | tg3_rd32_loop(tp, regs, RCVCC_MODE, 0x14); |
| 5746 | tg3_rd32_loop(tp, regs, RCVLSC_MODE, 0x08); |
| 5747 | tg3_rd32_loop(tp, regs, MBFREE_MODE, 0x08); |
| 5748 | tg3_rd32_loop(tp, regs, HOSTCC_MODE, 0x100); |
| 5749 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5750 | if (tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5751 | tg3_rd32_loop(tp, regs, HOSTCC_RXCOL_TICKS_VEC1, 0x180); |
| 5752 | |
| 5753 | tg3_rd32_loop(tp, regs, MEMARB_MODE, 0x10); |
| 5754 | tg3_rd32_loop(tp, regs, BUFMGR_MODE, 0x58); |
| 5755 | tg3_rd32_loop(tp, regs, RDMAC_MODE, 0x08); |
| 5756 | tg3_rd32_loop(tp, regs, WDMAC_MODE, 0x08); |
| 5757 | tg3_rd32_loop(tp, regs, RX_CPU_MODE, 0x04); |
| 5758 | tg3_rd32_loop(tp, regs, RX_CPU_STATE, 0x04); |
| 5759 | tg3_rd32_loop(tp, regs, RX_CPU_PGMCTR, 0x04); |
| 5760 | tg3_rd32_loop(tp, regs, RX_CPU_HWBKPT, 0x04); |
| 5761 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5762 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5763 | tg3_rd32_loop(tp, regs, TX_CPU_MODE, 0x04); |
| 5764 | tg3_rd32_loop(tp, regs, TX_CPU_STATE, 0x04); |
| 5765 | tg3_rd32_loop(tp, regs, TX_CPU_PGMCTR, 0x04); |
| 5766 | } |
| 5767 | |
| 5768 | tg3_rd32_loop(tp, regs, GRCMBOX_INTERRUPT_0, 0x110); |
| 5769 | tg3_rd32_loop(tp, regs, FTQ_RESET, 0x120); |
| 5770 | tg3_rd32_loop(tp, regs, MSGINT_MODE, 0x0c); |
| 5771 | tg3_rd32_loop(tp, regs, DMAC_MODE, 0x04); |
| 5772 | tg3_rd32_loop(tp, regs, GRC_MODE, 0x4c); |
| 5773 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5774 | if (tg3_flag(tp, NVRAM)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5775 | tg3_rd32_loop(tp, regs, NVRAM_CMD, 0x24); |
| 5776 | } |
| 5777 | |
| 5778 | static void tg3_dump_state(struct tg3 *tp) |
| 5779 | { |
| 5780 | int i; |
| 5781 | u32 *regs; |
| 5782 | |
| 5783 | regs = kzalloc(TG3_REG_BLK_SIZE, GFP_ATOMIC); |
| 5784 | if (!regs) { |
| 5785 | netdev_err(tp->dev, "Failed allocating register dump buffer\n"); |
| 5786 | return; |
| 5787 | } |
| 5788 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5789 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 5790 | /* Read up to but not including private PCI registers */ |
| 5791 | for (i = 0; i < TG3_PCIE_TLDLPL_PORT; i += sizeof(u32)) |
| 5792 | regs[i / sizeof(u32)] = tr32(i); |
| 5793 | } else |
| 5794 | tg3_dump_legacy_regs(tp, regs); |
| 5795 | |
| 5796 | for (i = 0; i < TG3_REG_BLK_SIZE / sizeof(u32); i += 4) { |
| 5797 | if (!regs[i + 0] && !regs[i + 1] && |
| 5798 | !regs[i + 2] && !regs[i + 3]) |
| 5799 | continue; |
| 5800 | |
| 5801 | netdev_err(tp->dev, "0x%08x: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", |
| 5802 | i * 4, |
| 5803 | regs[i + 0], regs[i + 1], regs[i + 2], regs[i + 3]); |
| 5804 | } |
| 5805 | |
| 5806 | kfree(regs); |
| 5807 | |
| 5808 | for (i = 0; i < tp->irq_cnt; i++) { |
| 5809 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 5810 | |
| 5811 | /* SW status block */ |
| 5812 | netdev_err(tp->dev, |
| 5813 | "%d: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", |
| 5814 | i, |
| 5815 | tnapi->hw_status->status, |
| 5816 | tnapi->hw_status->status_tag, |
| 5817 | tnapi->hw_status->rx_jumbo_consumer, |
| 5818 | tnapi->hw_status->rx_consumer, |
| 5819 | tnapi->hw_status->rx_mini_consumer, |
| 5820 | tnapi->hw_status->idx[0].rx_producer, |
| 5821 | tnapi->hw_status->idx[0].tx_consumer); |
| 5822 | |
| 5823 | netdev_err(tp->dev, |
| 5824 | "%d: NAPI info [%08x:%08x:(%04x:%04x:%04x):%04x:(%04x:%04x:%04x:%04x)]\n", |
| 5825 | i, |
| 5826 | tnapi->last_tag, tnapi->last_irq_tag, |
| 5827 | tnapi->tx_prod, tnapi->tx_cons, tnapi->tx_pending, |
| 5828 | tnapi->rx_rcb_ptr, |
| 5829 | tnapi->prodring.rx_std_prod_idx, |
| 5830 | tnapi->prodring.rx_std_cons_idx, |
| 5831 | tnapi->prodring.rx_jmb_prod_idx, |
| 5832 | tnapi->prodring.rx_jmb_cons_idx); |
| 5833 | } |
| 5834 | } |
| 5835 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5836 | /* This is called whenever we suspect that the system chipset is re- |
| 5837 | * ordering the sequence of MMIO to the tx send mailbox. The symptom |
| 5838 | * is bogus tx completions. We try to recover by setting the |
| 5839 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later |
| 5840 | * in the workqueue. |
| 5841 | */ |
| 5842 | static void tg3_tx_recover(struct tg3 *tp) |
| 5843 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5844 | BUG_ON(tg3_flag(tp, MBOX_WRITE_REORDER) || |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5845 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
| 5846 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5847 | netdev_warn(tp->dev, |
| 5848 | "The system may be re-ordering memory-mapped I/O " |
| 5849 | "cycles to the network device, attempting to recover. " |
| 5850 | "Please report the problem to the driver maintainer " |
| 5851 | "and include system chipset information.\n"); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5852 | |
| 5853 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5854 | tg3_flag_set(tp, TX_RECOVERY_PENDING); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5855 | spin_unlock(&tp->lock); |
| 5856 | } |
| 5857 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5858 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5859 | { |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 5860 | /* Tell compiler to fetch tx indices from memory. */ |
| 5861 | barrier(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5862 | return tnapi->tx_pending - |
| 5863 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5866 | /* Tigon3 never reports partial packet sends. So we do not |
| 5867 | * need special logic to handle SKBs that have not had all |
| 5868 | * of their frags sent yet, like SunGEM does. |
| 5869 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5870 | static void tg3_tx(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5871 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5872 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5873 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5874 | u32 sw_idx = tnapi->tx_cons; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5875 | struct netdev_queue *txq; |
| 5876 | int index = tnapi - tp->napi; |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5877 | unsigned int pkts_compl = 0, bytes_compl = 0; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5878 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5879 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5880 | index--; |
| 5881 | |
| 5882 | txq = netdev_get_tx_queue(tp->dev, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5883 | |
| 5884 | while (sw_idx != hw_idx) { |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 5885 | struct tg3_tx_ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5886 | struct sk_buff *skb = ri->skb; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5887 | int i, tx_bug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5888 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5889 | if (unlikely(skb == NULL)) { |
| 5890 | tg3_tx_recover(tp); |
| 5891 | return; |
| 5892 | } |
| 5893 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 5894 | if (tnapi->tx_ring[sw_idx].len_flags & TXD_FLAG_HWTSTAMP) { |
| 5895 | struct skb_shared_hwtstamps timestamp; |
| 5896 | u64 hwclock = tr32(TG3_TX_TSTAMP_LSB); |
| 5897 | hwclock |= (u64)tr32(TG3_TX_TSTAMP_MSB) << 32; |
| 5898 | |
| 5899 | tg3_hwclock_to_timestamp(tp, hwclock, ×tamp); |
| 5900 | |
| 5901 | skb_tstamp_tx(skb, ×tamp); |
| 5902 | } |
| 5903 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5904 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5905 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5906 | skb_headlen(skb), |
| 5907 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5908 | |
| 5909 | ri->skb = NULL; |
| 5910 | |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 5911 | while (ri->fragmented) { |
| 5912 | ri->fragmented = false; |
| 5913 | sw_idx = NEXT_TX(sw_idx); |
| 5914 | ri = &tnapi->tx_buffers[sw_idx]; |
| 5915 | } |
| 5916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5917 | sw_idx = NEXT_TX(sw_idx); |
| 5918 | |
| 5919 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5920 | ri = &tnapi->tx_buffers[sw_idx]; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5921 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
| 5922 | tx_bug = 1; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5923 | |
| 5924 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5925 | dma_unmap_addr(ri, mapping), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5926 | skb_frag_size(&skb_shinfo(skb)->frags[i]), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5927 | PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 5928 | |
| 5929 | while (ri->fragmented) { |
| 5930 | ri->fragmented = false; |
| 5931 | sw_idx = NEXT_TX(sw_idx); |
| 5932 | ri = &tnapi->tx_buffers[sw_idx]; |
| 5933 | } |
| 5934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5935 | sw_idx = NEXT_TX(sw_idx); |
| 5936 | } |
| 5937 | |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5938 | pkts_compl++; |
| 5939 | bytes_compl += skb->len; |
| 5940 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5941 | dev_kfree_skb(skb); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5942 | |
| 5943 | if (unlikely(tx_bug)) { |
| 5944 | tg3_tx_recover(tp); |
| 5945 | return; |
| 5946 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 5949 | netdev_tx_completed_queue(txq, pkts_compl, bytes_compl); |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 5950 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5951 | tnapi->tx_cons = sw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5952 | |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 5953 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
| 5954 | * before checking for netif_queue_stopped(). Without the |
| 5955 | * memory barrier, there is a small possibility that tg3_start_xmit() |
| 5956 | * will miss it and cause the queue to be stopped forever. |
| 5957 | */ |
| 5958 | smp_mb(); |
| 5959 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5960 | if (unlikely(netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5961 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5962 | __netif_tx_lock(txq, smp_processor_id()); |
| 5963 | if (netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5964 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5965 | netif_tx_wake_queue(txq); |
| 5966 | __netif_tx_unlock(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 5967 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5968 | } |
| 5969 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5970 | static void tg3_frag_free(bool is_frag, void *data) |
| 5971 | { |
| 5972 | if (is_frag) |
| 5973 | put_page(virt_to_head_page(data)); |
| 5974 | else |
| 5975 | kfree(data); |
| 5976 | } |
| 5977 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5978 | 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] | 5979 | { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5980 | unsigned int skb_size = SKB_DATA_ALIGN(map_sz + TG3_RX_OFFSET(tp)) + |
| 5981 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 5982 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5983 | if (!ri->data) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5984 | return; |
| 5985 | |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5986 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5987 | map_sz, PCI_DMA_FROMDEVICE); |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 5988 | tg3_frag_free(skb_size <= PAGE_SIZE, ri->data); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 5989 | ri->data = NULL; |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5990 | } |
| 5991 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 5992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5993 | /* Returns size of skb allocated or < 0 on error. |
| 5994 | * |
| 5995 | * We only need to fill in the address because the other members |
| 5996 | * of the RX descriptor are invariant, see tg3_init_rings. |
| 5997 | * |
| 5998 | * Note the purposeful assymetry of cpu vs. chip accesses. For |
| 5999 | * posting buffers we only dirty the first cache line of the RX |
| 6000 | * descriptor (containing the address). Whereas for the RX status |
| 6001 | * buffers the cpu only reads the last cacheline of the RX descriptor |
| 6002 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). |
| 6003 | */ |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6004 | 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] | 6005 | u32 opaque_key, u32 dest_idx_unmasked, |
| 6006 | unsigned int *frag_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6007 | { |
| 6008 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | f94e290 | 2010-10-14 10:37:42 +0000 | [diff] [blame] | 6009 | struct ring_info *map; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6010 | u8 *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6011 | dma_addr_t mapping; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6012 | int skb_size, data_size, dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6014 | switch (opaque_key) { |
| 6015 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6016 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6017 | desc = &tpr->rx_std[dest_idx]; |
| 6018 | map = &tpr->rx_std_buffers[dest_idx]; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6019 | data_size = tp->rx_pkt_map_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | break; |
| 6021 | |
| 6022 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6023 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 6024 | desc = &tpr->rx_jmb[dest_idx].std; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6025 | map = &tpr->rx_jmb_buffers[dest_idx]; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6026 | data_size = TG3_RX_JMB_MAP_SZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6027 | break; |
| 6028 | |
| 6029 | default: |
| 6030 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6031 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6032 | |
| 6033 | /* Do not overwrite any of the map or rp information |
| 6034 | * until we are sure we can commit to a new buffer. |
| 6035 | * |
| 6036 | * Callers depend upon this behavior and assume that |
| 6037 | * we leave everything unchanged if we fail. |
| 6038 | */ |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6039 | skb_size = SKB_DATA_ALIGN(data_size + TG3_RX_OFFSET(tp)) + |
| 6040 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 6041 | if (skb_size <= PAGE_SIZE) { |
| 6042 | data = netdev_alloc_frag(skb_size); |
| 6043 | *frag_size = skb_size; |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6044 | } else { |
| 6045 | data = kmalloc(skb_size, GFP_ATOMIC); |
| 6046 | *frag_size = 0; |
| 6047 | } |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6048 | if (!data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6049 | return -ENOMEM; |
| 6050 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6051 | mapping = pci_map_single(tp->pdev, |
| 6052 | data + TG3_RX_OFFSET(tp), |
| 6053 | data_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6054 | PCI_DMA_FROMDEVICE); |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6055 | if (unlikely(pci_dma_mapping_error(tp->pdev, mapping))) { |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 6056 | tg3_frag_free(skb_size <= PAGE_SIZE, data); |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 6057 | return -EIO; |
| 6058 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6059 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6060 | map->data = data; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6061 | dma_unmap_addr_set(map, mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6063 | desc->addr_hi = ((u64)mapping >> 32); |
| 6064 | desc->addr_lo = ((u64)mapping & 0xffffffff); |
| 6065 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6066 | return data_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6067 | } |
| 6068 | |
| 6069 | /* We only need to move over in the address because the other |
| 6070 | * members of the RX descriptor are invariant. See notes above |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6071 | * tg3_alloc_rx_data for full details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6072 | */ |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6073 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
| 6074 | struct tg3_rx_prodring_set *dpr, |
| 6075 | u32 opaque_key, int src_idx, |
| 6076 | u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6077 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6078 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6079 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
| 6080 | struct ring_info *src_map, *dest_map; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6081 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 6082 | int dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6083 | |
| 6084 | switch (opaque_key) { |
| 6085 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6086 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6087 | dest_desc = &dpr->rx_std[dest_idx]; |
| 6088 | dest_map = &dpr->rx_std_buffers[dest_idx]; |
| 6089 | src_desc = &spr->rx_std[src_idx]; |
| 6090 | src_map = &spr->rx_std_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6091 | break; |
| 6092 | |
| 6093 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6094 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6095 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
| 6096 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; |
| 6097 | src_desc = &spr->rx_jmb[src_idx].std; |
| 6098 | src_map = &spr->rx_jmb_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6099 | break; |
| 6100 | |
| 6101 | default: |
| 6102 | return; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6104 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6105 | dest_map->data = src_map->data; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6106 | dma_unmap_addr_set(dest_map, mapping, |
| 6107 | dma_unmap_addr(src_map, mapping)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6108 | dest_desc->addr_hi = src_desc->addr_hi; |
| 6109 | dest_desc->addr_lo = src_desc->addr_lo; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6110 | |
| 6111 | /* Ensure that the update to the skb happens after the physical |
| 6112 | * addresses have been transferred to the new BD location. |
| 6113 | */ |
| 6114 | smp_wmb(); |
| 6115 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6116 | src_map->data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6117 | } |
| 6118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6119 | /* The RX ring scheme is composed of multiple rings which post fresh |
| 6120 | * buffers to the chip, and one special ring the chip uses to report |
| 6121 | * status back to the host. |
| 6122 | * |
| 6123 | * The special ring reports the status of received packets to the |
| 6124 | * host. The chip does not write into the original descriptor the |
| 6125 | * RX buffer was obtained from. The chip simply takes the original |
| 6126 | * descriptor as provided by the host, updates the status and length |
| 6127 | * field, then writes this into the next status ring entry. |
| 6128 | * |
| 6129 | * Each ring the host uses to post buffers to the chip is described |
| 6130 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, |
| 6131 | * it is first placed into the on-chip ram. When the packet's length |
| 6132 | * is known, it walks down the TG3_BDINFO entries to select the ring. |
| 6133 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO |
| 6134 | * which is within the range of the new packet's length is chosen. |
| 6135 | * |
| 6136 | * The "separate ring for rx status" scheme may sound queer, but it makes |
| 6137 | * sense from a cache coherency perspective. If only the host writes |
| 6138 | * to the buffer post rings, and only the chip writes to the rx status |
| 6139 | * rings, then cache lines never move beyond shared-modified state. |
| 6140 | * If both the host and chip were to write into the same ring, cache line |
| 6141 | * eviction could occur since both entities want it in an exclusive state. |
| 6142 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6143 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6144 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6145 | struct tg3 *tp = tnapi->tp; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 6146 | u32 work_mask, rx_std_posted = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 6147 | u32 std_prod_idx, jmb_prod_idx; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6148 | u32 sw_idx = tnapi->rx_rcb_ptr; |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 6149 | u16 hw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6150 | int received; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6151 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6153 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6154 | /* |
| 6155 | * We need to order the read of hw_idx and the read of |
| 6156 | * the opaque cookie. |
| 6157 | */ |
| 6158 | rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6159 | work_mask = 0; |
| 6160 | received = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 6161 | std_prod_idx = tpr->rx_std_prod_idx; |
| 6162 | jmb_prod_idx = tpr->rx_jmb_prod_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6163 | while (sw_idx != hw_idx && budget > 0) { |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 6164 | struct ring_info *ri; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6165 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6166 | unsigned int len; |
| 6167 | struct sk_buff *skb; |
| 6168 | dma_addr_t dma_addr; |
| 6169 | u32 opaque_key, desc_idx, *post_ptr; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6170 | u8 *data; |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 6171 | u64 tstamp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6172 | |
| 6173 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 6174 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 6175 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6176 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6177 | dma_addr = dma_unmap_addr(ri, mapping); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6178 | data = ri->data; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 6179 | post_ptr = &std_prod_idx; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 6180 | rx_std_posted++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6181 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6182 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6183 | dma_addr = dma_unmap_addr(ri, mapping); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6184 | data = ri->data; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 6185 | post_ptr = &jmb_prod_idx; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6186 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6187 | goto next_pkt_nopost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6188 | |
| 6189 | work_mask |= opaque_key; |
| 6190 | |
| 6191 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 6192 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { |
| 6193 | drop_it: |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6194 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6195 | desc_idx, *post_ptr); |
| 6196 | drop_it_no_recycle: |
| 6197 | /* Other statistics kept track of by card. */ |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 6198 | tp->rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6199 | goto next_pkt; |
| 6200 | } |
| 6201 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6202 | prefetch(data + TG3_RX_OFFSET(tp)); |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 6203 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
| 6204 | ETH_FCS_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6205 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 6206 | if ((desc->type_flags & RXD_FLAG_PTPSTAT_MASK) == |
| 6207 | RXD_FLAG_PTPSTAT_PTPV1 || |
| 6208 | (desc->type_flags & RXD_FLAG_PTPSTAT_MASK) == |
| 6209 | RXD_FLAG_PTPSTAT_PTPV2) { |
| 6210 | tstamp = tr32(TG3_RX_TSTAMP_LSB); |
| 6211 | tstamp |= (u64)tr32(TG3_RX_TSTAMP_MSB) << 32; |
| 6212 | } |
| 6213 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 6214 | if (len > TG3_RX_COPY_THRESH(tp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6215 | int skb_size; |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6216 | unsigned int frag_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6218 | skb_size = tg3_alloc_rx_data(tp, tpr, opaque_key, |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6219 | *post_ptr, &frag_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6220 | if (skb_size < 0) |
| 6221 | goto drop_it; |
| 6222 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6223 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6224 | PCI_DMA_FROMDEVICE); |
| 6225 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6226 | skb = build_skb(data, frag_size); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6227 | if (!skb) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6228 | tg3_frag_free(frag_size != 0, data); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6229 | goto drop_it_no_recycle; |
| 6230 | } |
| 6231 | skb_reserve(skb, TG3_RX_OFFSET(tp)); |
| 6232 | /* Ensure that the update to the data happens |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 6233 | * after the usage of the old DMA mapping. |
| 6234 | */ |
| 6235 | smp_wmb(); |
| 6236 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6237 | ri->data = NULL; |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 6238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6239 | } else { |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6240 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6241 | desc_idx, *post_ptr); |
| 6242 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6243 | skb = netdev_alloc_skb(tp->dev, |
| 6244 | len + TG3_RAW_IP_ALIGN); |
| 6245 | if (skb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6246 | goto drop_it_no_recycle; |
| 6247 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6248 | skb_reserve(skb, TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6249 | 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] | 6250 | memcpy(skb->data, |
| 6251 | data + TG3_RX_OFFSET(tp), |
| 6252 | len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6253 | 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] | 6254 | } |
| 6255 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6256 | skb_put(skb, len); |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 6257 | if (tstamp) |
| 6258 | tg3_hwclock_to_timestamp(tp, tstamp, |
| 6259 | skb_hwtstamps(skb)); |
| 6260 | |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 6261 | if ((tp->dev->features & NETIF_F_RXCSUM) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6262 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 6263 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 6264 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) |
| 6265 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6266 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6267 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6268 | |
| 6269 | skb->protocol = eth_type_trans(skb, tp->dev); |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 6270 | |
| 6271 | if (len > (tp->dev->mtu + ETH_HLEN) && |
| 6272 | skb->protocol != htons(ETH_P_8021Q)) { |
| 6273 | dev_kfree_skb(skb); |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 6274 | goto drop_it_no_recycle; |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 6275 | } |
| 6276 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 6277 | if (desc->type_flags & RXD_FLAG_VLAN && |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 6278 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
| 6279 | __vlan_hwaccel_put_tag(skb, |
| 6280 | desc->err_vlan & RXD_VLAN_MASK); |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 6281 | |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 6282 | napi_gro_receive(&tnapi->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6284 | received++; |
| 6285 | budget--; |
| 6286 | |
| 6287 | next_pkt: |
| 6288 | (*post_ptr)++; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 6289 | |
| 6290 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6291 | tpr->rx_std_prod_idx = std_prod_idx & |
| 6292 | tp->rx_std_ring_mask; |
Matt Carlson | 86cfe4f | 2010-01-12 10:11:37 +0000 | [diff] [blame] | 6293 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6294 | tpr->rx_std_prod_idx); |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 6295 | work_mask &= ~RXD_OPAQUE_RING_STD; |
| 6296 | rx_std_posted = 0; |
| 6297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | next_pkt_nopost: |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 6299 | sw_idx++; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 6300 | sw_idx &= tp->rx_ret_ring_mask; |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 6301 | |
| 6302 | /* Refresh hw_idx to see if there is new work */ |
| 6303 | if (sw_idx == hw_idx) { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6304 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 6305 | rmb(); |
| 6306 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6307 | } |
| 6308 | |
| 6309 | /* ACK the status ring. */ |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6310 | tnapi->rx_rcb_ptr = sw_idx; |
| 6311 | tw32_rx_mbox(tnapi->consmbox, sw_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6312 | |
| 6313 | /* Refill RX ring(s). */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6314 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 6315 | /* Sync BD data before updating mailbox */ |
| 6316 | wmb(); |
| 6317 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6318 | if (work_mask & RXD_OPAQUE_RING_STD) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6319 | tpr->rx_std_prod_idx = std_prod_idx & |
| 6320 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6321 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6322 | tpr->rx_std_prod_idx); |
| 6323 | } |
| 6324 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6325 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
| 6326 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6327 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 6328 | tpr->rx_jmb_prod_idx); |
| 6329 | } |
| 6330 | mmiowb(); |
| 6331 | } else if (work_mask) { |
| 6332 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be |
| 6333 | * updated before the producer indices can be updated. |
| 6334 | */ |
| 6335 | smp_wmb(); |
| 6336 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6337 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
| 6338 | 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] | 6339 | |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6340 | if (tnapi != &tp->napi[1]) { |
| 6341 | tp->rx_refill = true; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6342 | napi_schedule(&tp->napi[1].napi); |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6345 | |
| 6346 | return received; |
| 6347 | } |
| 6348 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6349 | static void tg3_poll_link(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6350 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6351 | /* handle link change and other phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6352 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6353 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
| 6354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6355 | if (sblk->status & SD_STATUS_LINK_CHG) { |
| 6356 | sblk->status = SD_STATUS_UPDATED | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6357 | (sblk->status & ~SD_STATUS_LINK_CHG); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6358 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6359 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 6360 | tw32_f(MAC_STATUS, |
| 6361 | (MAC_STATUS_SYNC_CHANGED | |
| 6362 | MAC_STATUS_CFG_CHANGED | |
| 6363 | MAC_STATUS_MI_COMPLETION | |
| 6364 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 6365 | udelay(40); |
| 6366 | } else |
| 6367 | tg3_setup_phy(tp, 0); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6368 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6369 | } |
| 6370 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6371 | } |
| 6372 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6373 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
| 6374 | struct tg3_rx_prodring_set *dpr, |
| 6375 | struct tg3_rx_prodring_set *spr) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6376 | { |
| 6377 | u32 si, di, cpycnt, src_prod_idx; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6378 | int i, err = 0; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6379 | |
| 6380 | while (1) { |
| 6381 | src_prod_idx = spr->rx_std_prod_idx; |
| 6382 | |
| 6383 | /* Make sure updates to the rx_std_buffers[] entries and the |
| 6384 | * standard producer index are seen in the correct order. |
| 6385 | */ |
| 6386 | smp_rmb(); |
| 6387 | |
| 6388 | if (spr->rx_std_cons_idx == src_prod_idx) |
| 6389 | break; |
| 6390 | |
| 6391 | if (spr->rx_std_cons_idx < src_prod_idx) |
| 6392 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; |
| 6393 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6394 | cpycnt = tp->rx_std_ring_mask + 1 - |
| 6395 | spr->rx_std_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6396 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6397 | cpycnt = min(cpycnt, |
| 6398 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6399 | |
| 6400 | si = spr->rx_std_cons_idx; |
| 6401 | di = dpr->rx_std_prod_idx; |
| 6402 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6403 | for (i = di; i < di + cpycnt; i++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6404 | if (dpr->rx_std_buffers[i].data) { |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6405 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6406 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6407 | break; |
| 6408 | } |
| 6409 | } |
| 6410 | |
| 6411 | if (!cpycnt) |
| 6412 | break; |
| 6413 | |
| 6414 | /* Ensure that updates to the rx_std_buffers ring and the |
| 6415 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 6416 | * ordered correctly WRT the skb check above. |
| 6417 | */ |
| 6418 | smp_rmb(); |
| 6419 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6420 | memcpy(&dpr->rx_std_buffers[di], |
| 6421 | &spr->rx_std_buffers[si], |
| 6422 | cpycnt * sizeof(struct ring_info)); |
| 6423 | |
| 6424 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 6425 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 6426 | sbd = &spr->rx_std[si]; |
| 6427 | dbd = &dpr->rx_std[di]; |
| 6428 | dbd->addr_hi = sbd->addr_hi; |
| 6429 | dbd->addr_lo = sbd->addr_lo; |
| 6430 | } |
| 6431 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6432 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
| 6433 | tp->rx_std_ring_mask; |
| 6434 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & |
| 6435 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | while (1) { |
| 6439 | src_prod_idx = spr->rx_jmb_prod_idx; |
| 6440 | |
| 6441 | /* Make sure updates to the rx_jmb_buffers[] entries and |
| 6442 | * the jumbo producer index are seen in the correct order. |
| 6443 | */ |
| 6444 | smp_rmb(); |
| 6445 | |
| 6446 | if (spr->rx_jmb_cons_idx == src_prod_idx) |
| 6447 | break; |
| 6448 | |
| 6449 | if (spr->rx_jmb_cons_idx < src_prod_idx) |
| 6450 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; |
| 6451 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6452 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
| 6453 | spr->rx_jmb_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6454 | |
| 6455 | cpycnt = min(cpycnt, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6456 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6457 | |
| 6458 | si = spr->rx_jmb_cons_idx; |
| 6459 | di = dpr->rx_jmb_prod_idx; |
| 6460 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6461 | for (i = di; i < di + cpycnt; i++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6462 | if (dpr->rx_jmb_buffers[i].data) { |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6463 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6464 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6465 | break; |
| 6466 | } |
| 6467 | } |
| 6468 | |
| 6469 | if (!cpycnt) |
| 6470 | break; |
| 6471 | |
| 6472 | /* Ensure that updates to the rx_jmb_buffers ring and the |
| 6473 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 6474 | * ordered correctly WRT the skb check above. |
| 6475 | */ |
| 6476 | smp_rmb(); |
| 6477 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6478 | memcpy(&dpr->rx_jmb_buffers[di], |
| 6479 | &spr->rx_jmb_buffers[si], |
| 6480 | cpycnt * sizeof(struct ring_info)); |
| 6481 | |
| 6482 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 6483 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 6484 | sbd = &spr->rx_jmb[si].std; |
| 6485 | dbd = &dpr->rx_jmb[di].std; |
| 6486 | dbd->addr_hi = sbd->addr_hi; |
| 6487 | dbd->addr_lo = sbd->addr_lo; |
| 6488 | } |
| 6489 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6490 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
| 6491 | tp->rx_jmb_ring_mask; |
| 6492 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & |
| 6493 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6494 | } |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6495 | |
| 6496 | return err; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6497 | } |
| 6498 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6499 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
| 6500 | { |
| 6501 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6502 | |
| 6503 | /* run TX completion thread */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6504 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6505 | tg3_tx(tnapi); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6506 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6507 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6508 | } |
| 6509 | |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 6510 | if (!tnapi->rx_rcb_prod_idx) |
| 6511 | return work_done; |
| 6512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6513 | /* run RX thread, within the bounds set by NAPI. |
| 6514 | * All RX "locking" is done by ensuring outside |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6515 | * code synchronizes with tg3->napi.poll() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6516 | */ |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6517 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6518 | work_done += tg3_rx(tnapi, budget - work_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6519 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6520 | if (tg3_flag(tp, ENABLE_RSS) && tnapi == &tp->napi[1]) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6521 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6522 | int i, err = 0; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6523 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
| 6524 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6525 | |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6526 | tp->rx_refill = false; |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 6527 | for (i = 1; i <= tp->rxq_cnt; i++) |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6528 | err |= tg3_rx_prodring_xfer(tp, dpr, |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6529 | &tp->napi[i].prodring); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6530 | |
| 6531 | wmb(); |
| 6532 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6533 | if (std_prod_idx != dpr->rx_std_prod_idx) |
| 6534 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6535 | dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6536 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6537 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
| 6538 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 6539 | dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6540 | |
| 6541 | mmiowb(); |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6542 | |
| 6543 | if (err) |
| 6544 | tw32_f(HOSTCC_MODE, tp->coal_now); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6545 | } |
| 6546 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6547 | return work_done; |
| 6548 | } |
David S. Miller | f7383c2 | 2005-05-18 22:50:53 -0700 | [diff] [blame] | 6549 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6550 | static inline void tg3_reset_task_schedule(struct tg3 *tp) |
| 6551 | { |
| 6552 | if (!test_and_set_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags)) |
| 6553 | schedule_work(&tp->reset_task); |
| 6554 | } |
| 6555 | |
| 6556 | static inline void tg3_reset_task_cancel(struct tg3 *tp) |
| 6557 | { |
| 6558 | cancel_work_sync(&tp->reset_task); |
| 6559 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
Matt Carlson | c710135 | 2012-02-22 12:35:20 +0000 | [diff] [blame] | 6560 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6561 | } |
| 6562 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6563 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
| 6564 | { |
| 6565 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 6566 | struct tg3 *tp = tnapi->tp; |
| 6567 | int work_done = 0; |
| 6568 | struct tg3_hw_status *sblk = tnapi->hw_status; |
| 6569 | |
| 6570 | while (1) { |
| 6571 | work_done = tg3_poll_work(tnapi, work_done, budget); |
| 6572 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6573 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6574 | goto tx_recovery; |
| 6575 | |
| 6576 | if (unlikely(work_done >= budget)) |
| 6577 | break; |
| 6578 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 6579 | /* tp->last_tag is used in tg3_int_reenable() below |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6580 | * to tell the hw how much work has been processed, |
| 6581 | * so we must read it before checking for more work. |
| 6582 | */ |
| 6583 | tnapi->last_tag = sblk->status_tag; |
| 6584 | tnapi->last_irq_tag = tnapi->last_tag; |
| 6585 | rmb(); |
| 6586 | |
| 6587 | /* check for RX/TX work to do */ |
Matt Carlson | 6d40db7 | 2010-04-05 10:19:20 +0000 | [diff] [blame] | 6588 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
| 6589 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6590 | |
| 6591 | /* This test here is not race free, but will reduce |
| 6592 | * the number of interrupts by looping again. |
| 6593 | */ |
| 6594 | if (tnapi == &tp->napi[1] && tp->rx_refill) |
| 6595 | continue; |
| 6596 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6597 | napi_complete(napi); |
| 6598 | /* Reenable interrupts. */ |
| 6599 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6600 | |
| 6601 | /* This test here is synchronized by napi_schedule() |
| 6602 | * and napi_complete() to close the race condition. |
| 6603 | */ |
| 6604 | if (unlikely(tnapi == &tp->napi[1] && tp->rx_refill)) { |
| 6605 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
| 6606 | HOSTCC_MODE_ENABLE | |
| 6607 | tnapi->coal_now); |
| 6608 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6609 | mmiowb(); |
| 6610 | break; |
| 6611 | } |
| 6612 | } |
| 6613 | |
| 6614 | return work_done; |
| 6615 | |
| 6616 | tx_recovery: |
| 6617 | /* work_done is guaranteed to be less than budget. */ |
| 6618 | napi_complete(napi); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6619 | tg3_reset_task_schedule(tp); |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6620 | return work_done; |
| 6621 | } |
| 6622 | |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6623 | static void tg3_process_error(struct tg3 *tp) |
| 6624 | { |
| 6625 | u32 val; |
| 6626 | bool real_error = false; |
| 6627 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6628 | if (tg3_flag(tp, ERROR_PROCESSED)) |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6629 | return; |
| 6630 | |
| 6631 | /* Check Flow Attention register */ |
| 6632 | val = tr32(HOSTCC_FLOW_ATTN); |
| 6633 | if (val & ~HOSTCC_FLOW_ATTN_MBUF_LWM) { |
| 6634 | netdev_err(tp->dev, "FLOW Attention error. Resetting chip.\n"); |
| 6635 | real_error = true; |
| 6636 | } |
| 6637 | |
| 6638 | if (tr32(MSGINT_STATUS) & ~MSGINT_STATUS_MSI_REQ) { |
| 6639 | netdev_err(tp->dev, "MSI Status error. Resetting chip.\n"); |
| 6640 | real_error = true; |
| 6641 | } |
| 6642 | |
| 6643 | if (tr32(RDMAC_STATUS) || tr32(WDMAC_STATUS)) { |
| 6644 | netdev_err(tp->dev, "DMA Status error. Resetting chip.\n"); |
| 6645 | real_error = true; |
| 6646 | } |
| 6647 | |
| 6648 | if (!real_error) |
| 6649 | return; |
| 6650 | |
| 6651 | tg3_dump_state(tp); |
| 6652 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6653 | tg3_flag_set(tp, ERROR_PROCESSED); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6654 | tg3_reset_task_schedule(tp); |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6655 | } |
| 6656 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6657 | static int tg3_poll(struct napi_struct *napi, int budget) |
| 6658 | { |
Matt Carlson | 8ef0442 | 2009-08-28 14:01:37 +0000 | [diff] [blame] | 6659 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 6660 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6661 | int work_done = 0; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6662 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6663 | |
| 6664 | while (1) { |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 6665 | if (sblk->status & SD_STATUS_ERROR) |
| 6666 | tg3_process_error(tp); |
| 6667 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6668 | tg3_poll_link(tp); |
| 6669 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6670 | work_done = tg3_poll_work(tnapi, work_done, budget); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6671 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6672 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6673 | goto tx_recovery; |
| 6674 | |
| 6675 | if (unlikely(work_done >= budget)) |
| 6676 | break; |
| 6677 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6678 | if (tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6679 | /* tp->last_tag is used in tg3_int_reenable() below |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6680 | * to tell the hw how much work has been processed, |
| 6681 | * so we must read it before checking for more work. |
| 6682 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6683 | tnapi->last_tag = sblk->status_tag; |
| 6684 | tnapi->last_irq_tag = tnapi->last_tag; |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6685 | rmb(); |
| 6686 | } else |
| 6687 | sblk->status &= ~SD_STATUS_UPDATED; |
| 6688 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6689 | if (likely(!tg3_has_work(tnapi))) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 6690 | napi_complete(napi); |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6691 | tg3_int_reenable(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6692 | break; |
| 6693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6694 | } |
| 6695 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6696 | return work_done; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 6697 | |
| 6698 | tx_recovery: |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6699 | /* work_done is guaranteed to be less than budget. */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 6700 | napi_complete(napi); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6701 | tg3_reset_task_schedule(tp); |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 6702 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6703 | } |
| 6704 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6705 | static void tg3_napi_disable(struct tg3 *tp) |
| 6706 | { |
| 6707 | int i; |
| 6708 | |
| 6709 | for (i = tp->irq_cnt - 1; i >= 0; i--) |
| 6710 | napi_disable(&tp->napi[i].napi); |
| 6711 | } |
| 6712 | |
| 6713 | static void tg3_napi_enable(struct tg3 *tp) |
| 6714 | { |
| 6715 | int i; |
| 6716 | |
| 6717 | for (i = 0; i < tp->irq_cnt; i++) |
| 6718 | napi_enable(&tp->napi[i].napi); |
| 6719 | } |
| 6720 | |
| 6721 | static void tg3_napi_init(struct tg3 *tp) |
| 6722 | { |
| 6723 | int i; |
| 6724 | |
| 6725 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); |
| 6726 | for (i = 1; i < tp->irq_cnt; i++) |
| 6727 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); |
| 6728 | } |
| 6729 | |
| 6730 | static void tg3_napi_fini(struct tg3 *tp) |
| 6731 | { |
| 6732 | int i; |
| 6733 | |
| 6734 | for (i = 0; i < tp->irq_cnt; i++) |
| 6735 | netif_napi_del(&tp->napi[i].napi); |
| 6736 | } |
| 6737 | |
| 6738 | static inline void tg3_netif_stop(struct tg3 *tp) |
| 6739 | { |
| 6740 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 6741 | tg3_napi_disable(tp); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 6742 | netif_carrier_off(tp->dev); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6743 | netif_tx_disable(tp->dev); |
| 6744 | } |
| 6745 | |
Nithin Nayak Sujir | 3576306 | 2012-12-03 19:36:56 +0000 | [diff] [blame] | 6746 | /* tp->lock must be held */ |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6747 | static inline void tg3_netif_start(struct tg3 *tp) |
| 6748 | { |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 6749 | tg3_ptp_resume(tp); |
| 6750 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6751 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
| 6752 | * appropriate so long as all callers are assured to |
| 6753 | * have free tx slots (such as after tg3_init_hw) |
| 6754 | */ |
| 6755 | netif_tx_wake_all_queues(tp->dev); |
| 6756 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 6757 | if (tp->link_up) |
| 6758 | netif_carrier_on(tp->dev); |
| 6759 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6760 | tg3_napi_enable(tp); |
| 6761 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; |
| 6762 | tg3_enable_ints(tp); |
| 6763 | } |
| 6764 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6765 | static void tg3_irq_quiesce(struct tg3 *tp) |
| 6766 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6767 | int i; |
| 6768 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6769 | BUG_ON(tp->irq_sync); |
| 6770 | |
| 6771 | tp->irq_sync = 1; |
| 6772 | smp_mb(); |
| 6773 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6774 | for (i = 0; i < tp->irq_cnt; i++) |
| 6775 | synchronize_irq(tp->napi[i].irq_vec); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6776 | } |
| 6777 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6778 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
| 6779 | * If irq_sync is non-zero, then the IRQ handler must be synchronized |
| 6780 | * with as well. Most of the time, this is not necessary except when |
| 6781 | * shutting down the device. |
| 6782 | */ |
| 6783 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) |
| 6784 | { |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 6785 | spin_lock_bh(&tp->lock); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6786 | if (irq_sync) |
| 6787 | tg3_irq_quiesce(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6788 | } |
| 6789 | |
| 6790 | static inline void tg3_full_unlock(struct tg3 *tp) |
| 6791 | { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6792 | spin_unlock_bh(&tp->lock); |
| 6793 | } |
| 6794 | |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6795 | /* One-shot MSI handler - Chip automatically disables interrupt |
| 6796 | * after sending MSI so driver doesn't have to do it. |
| 6797 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6798 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6799 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6800 | struct tg3_napi *tnapi = dev_id; |
| 6801 | struct tg3 *tp = tnapi->tp; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6802 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6803 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6804 | if (tnapi->rx_rcb) |
| 6805 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6806 | |
| 6807 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6808 | napi_schedule(&tnapi->napi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 6809 | |
| 6810 | return IRQ_HANDLED; |
| 6811 | } |
| 6812 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6813 | /* MSI ISR - No need to check for interrupt sharing and no need to |
| 6814 | * flush status block and interrupt mailbox. PCI ordering rules |
| 6815 | * guarantee that MSI will arrive after the status block. |
| 6816 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6817 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6818 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6819 | struct tg3_napi *tnapi = dev_id; |
| 6820 | struct tg3 *tp = tnapi->tp; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6821 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6822 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6823 | if (tnapi->rx_rcb) |
| 6824 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6825 | /* |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6826 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6827 | * chip-internal interrupt pending events. |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6828 | * Writing non-zero to intr-mbox-0 additional tells the |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6829 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6830 | * event coalescing. |
| 6831 | */ |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 6832 | tw32_mailbox(tnapi->int_mbox, 0x00000001); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 6833 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6834 | napi_schedule(&tnapi->napi); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 6835 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6836 | return IRQ_RETVAL(1); |
| 6837 | } |
| 6838 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6839 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6840 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6841 | struct tg3_napi *tnapi = dev_id; |
| 6842 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6843 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6844 | unsigned int handled = 1; |
| 6845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6846 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 6847 | * the CPU before the status block posted prior to the interrupt. |
| 6848 | * Reading the PCI State register will confirm whether the |
| 6849 | * interrupt is ours and will flush the status block. |
| 6850 | */ |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6851 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6852 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6853 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 6854 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6855 | goto out; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6856 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6857 | } |
| 6858 | |
| 6859 | /* |
| 6860 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
| 6861 | * chip-internal interrupt pending events. |
| 6862 | * Writing non-zero to intr-mbox-0 additional tells the |
| 6863 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6864 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6865 | * |
| 6866 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 6867 | * spurious interrupts. The flush impacts performance but |
| 6868 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6869 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6870 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6871 | if (tg3_irq_sync(tp)) |
| 6872 | goto out; |
| 6873 | sblk->status &= ~SD_STATUS_UPDATED; |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6874 | if (likely(tg3_has_work(tnapi))) { |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6875 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6876 | napi_schedule(&tnapi->napi); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6877 | } else { |
| 6878 | /* No work, shared interrupt perhaps? re-enable |
| 6879 | * interrupts, and flush that PCI write |
| 6880 | */ |
| 6881 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, |
| 6882 | 0x00000000); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6883 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6884 | out: |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6885 | return IRQ_RETVAL(handled); |
| 6886 | } |
| 6887 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6888 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6889 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6890 | struct tg3_napi *tnapi = dev_id; |
| 6891 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6892 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6893 | unsigned int handled = 1; |
| 6894 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 6895 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 6896 | * the CPU before the status block posted prior to the interrupt. |
| 6897 | * Reading the PCI State register will confirm whether the |
| 6898 | * interrupt is ours and will flush the status block. |
| 6899 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6900 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6901 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6902 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 6903 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6904 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6905 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6906 | } |
| 6907 | |
| 6908 | /* |
| 6909 | * writing any value to intr-mbox-0 clears PCI INTA# and |
| 6910 | * chip-internal interrupt pending events. |
| 6911 | * writing non-zero to intr-mbox-0 additional tells the |
| 6912 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 6913 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6914 | * |
| 6915 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 6916 | * spurious interrupts. The flush impacts performance but |
| 6917 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6918 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 6919 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6920 | |
| 6921 | /* |
| 6922 | * In a shared interrupt configuration, sometimes other devices' |
| 6923 | * interrupts will scream. We record the current status tag here |
| 6924 | * so that the above check can report that the screaming interrupts |
| 6925 | * are unhandled. Eventually they will be silenced. |
| 6926 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6927 | tnapi->last_irq_tag = sblk->status_tag; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6928 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6929 | if (tg3_irq_sync(tp)) |
| 6930 | goto out; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6931 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6932 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6933 | |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6934 | napi_schedule(&tnapi->napi); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 6935 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6936 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6937 | return IRQ_RETVAL(handled); |
| 6938 | } |
| 6939 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6940 | /* ISR for interrupt test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 6941 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6942 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 6943 | struct tg3_napi *tnapi = dev_id; |
| 6944 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6945 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6946 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 6947 | if ((sblk->status & SD_STATUS_UPDATED) || |
| 6948 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 6949 | tg3_disable_ints(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 6950 | return IRQ_RETVAL(1); |
| 6951 | } |
| 6952 | return IRQ_RETVAL(0); |
| 6953 | } |
| 6954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6955 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6956 | static void tg3_poll_controller(struct net_device *dev) |
| 6957 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6958 | int i; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 6959 | struct tg3 *tp = netdev_priv(dev); |
| 6960 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6961 | for (i = 0; i < tp->irq_cnt; i++) |
Louis Rilling | fe234f0 | 2010-03-09 06:14:41 +0000 | [diff] [blame] | 6962 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6963 | } |
| 6964 | #endif |
| 6965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6966 | static void tg3_tx_timeout(struct net_device *dev) |
| 6967 | { |
| 6968 | struct tg3 *tp = netdev_priv(dev); |
| 6969 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 6970 | if (netif_msg_tx_err(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 6971 | netdev_err(dev, "transmit timed out, resetting\n"); |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6972 | tg3_dump_state(tp); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 6973 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6974 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 6975 | tg3_reset_task_schedule(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6976 | } |
| 6977 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6978 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
| 6979 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) |
| 6980 | { |
| 6981 | u32 base = (u32) mapping & 0xffffffff; |
| 6982 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 6983 | return (base > 0xffffdcc0) && (base + len + 8 < base); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6984 | } |
| 6985 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6986 | /* Test for DMA addresses > 40-bit */ |
| 6987 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 6988 | int len) |
| 6989 | { |
| 6990 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6991 | if (tg3_flag(tp, 40BIT_DMA_BUG)) |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 6992 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6993 | return 0; |
| 6994 | #else |
| 6995 | return 0; |
| 6996 | #endif |
| 6997 | } |
| 6998 | |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 6999 | 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] | 7000 | dma_addr_t mapping, u32 len, u32 flags, |
| 7001 | u32 mss, u32 vlan) |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 7002 | { |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7003 | txbd->addr_hi = ((u64) mapping >> 32); |
| 7004 | txbd->addr_lo = ((u64) mapping & 0xffffffff); |
| 7005 | txbd->len_flags = (len << TXD_LEN_SHIFT) | (flags & 0x0000ffff); |
| 7006 | txbd->vlan_tag = (mss << TXD_MSS_SHIFT) | (vlan << TXD_VLAN_TAG_SHIFT); |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 7007 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7008 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7009 | 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] | 7010 | dma_addr_t map, u32 len, u32 flags, |
| 7011 | u32 mss, u32 vlan) |
| 7012 | { |
| 7013 | struct tg3 *tp = tnapi->tp; |
| 7014 | bool hwbug = false; |
| 7015 | |
| 7016 | if (tg3_flag(tp, SHORT_DMA_BUG) && len <= 8) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 7017 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7018 | |
| 7019 | if (tg3_4g_overflow_test(map, len)) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 7020 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7021 | |
| 7022 | if (tg3_40bit_overflow_test(tp, map, len)) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 7023 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7024 | |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 7025 | if (tp->dma_limit) { |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7026 | u32 prvidx = *entry; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7027 | u32 tmp_flag = flags & ~TXD_FLAG_END; |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 7028 | while (len > tp->dma_limit && *budget) { |
| 7029 | u32 frag_len = tp->dma_limit; |
| 7030 | len -= tp->dma_limit; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7031 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7032 | /* Avoid the 8byte DMA problem */ |
| 7033 | if (len <= 8) { |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 7034 | len += tp->dma_limit / 2; |
| 7035 | frag_len = tp->dma_limit / 2; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7036 | } |
| 7037 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7038 | tnapi->tx_buffers[*entry].fragmented = true; |
| 7039 | |
| 7040 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 7041 | frag_len, tmp_flag, mss, vlan); |
| 7042 | *budget -= 1; |
| 7043 | prvidx = *entry; |
| 7044 | *entry = NEXT_TX(*entry); |
| 7045 | |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7046 | map += frag_len; |
| 7047 | } |
| 7048 | |
| 7049 | if (len) { |
| 7050 | if (*budget) { |
| 7051 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 7052 | len, flags, mss, vlan); |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7053 | *budget -= 1; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7054 | *entry = NEXT_TX(*entry); |
| 7055 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 7056 | hwbug = true; |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7057 | tnapi->tx_buffers[prvidx].fragmented = false; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7058 | } |
| 7059 | } |
| 7060 | } else { |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7061 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 7062 | len, flags, mss, vlan); |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7063 | *entry = NEXT_TX(*entry); |
| 7064 | } |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7065 | |
| 7066 | return hwbug; |
| 7067 | } |
| 7068 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7069 | 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] | 7070 | { |
| 7071 | int i; |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7072 | struct sk_buff *skb; |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 7073 | struct tg3_tx_ring_info *txb = &tnapi->tx_buffers[entry]; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7074 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7075 | skb = txb->skb; |
| 7076 | txb->skb = NULL; |
| 7077 | |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7078 | pci_unmap_single(tnapi->tp->pdev, |
| 7079 | dma_unmap_addr(txb, mapping), |
| 7080 | skb_headlen(skb), |
| 7081 | PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 7082 | |
| 7083 | while (txb->fragmented) { |
| 7084 | txb->fragmented = false; |
| 7085 | entry = NEXT_TX(entry); |
| 7086 | txb = &tnapi->tx_buffers[entry]; |
| 7087 | } |
| 7088 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7089 | for (i = 0; i <= last; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7090 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7091 | |
| 7092 | entry = NEXT_TX(entry); |
| 7093 | txb = &tnapi->tx_buffers[entry]; |
| 7094 | |
| 7095 | pci_unmap_page(tnapi->tp->pdev, |
| 7096 | dma_unmap_addr(txb, mapping), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7097 | skb_frag_size(frag), PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 7098 | |
| 7099 | while (txb->fragmented) { |
| 7100 | txb->fragmented = false; |
| 7101 | entry = NEXT_TX(entry); |
| 7102 | txb = &tnapi->tx_buffers[entry]; |
| 7103 | } |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7104 | } |
| 7105 | } |
| 7106 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 7107 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7108 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7109 | struct sk_buff **pskb, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7110 | u32 *entry, u32 *budget, |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7111 | u32 base_flags, u32 mss, u32 vlan) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7112 | { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7113 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7114 | struct sk_buff *new_skb, *skb = *pskb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7115 | dma_addr_t new_addr = 0; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7116 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7117 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 7118 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 7119 | new_skb = skb_copy(skb, GFP_ATOMIC); |
| 7120 | else { |
| 7121 | int more_headroom = 4 - ((unsigned long)skb->data & 3); |
| 7122 | |
| 7123 | new_skb = skb_copy_expand(skb, |
| 7124 | skb_headroom(skb) + more_headroom, |
| 7125 | skb_tailroom(skb), GFP_ATOMIC); |
| 7126 | } |
| 7127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7128 | if (!new_skb) { |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7129 | ret = -1; |
| 7130 | } else { |
| 7131 | /* New SKB is guaranteed to be linear. */ |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7132 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
| 7133 | PCI_DMA_TODEVICE); |
| 7134 | /* Make sure the mapping succeeded */ |
| 7135 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7136 | dev_kfree_skb(new_skb); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7137 | ret = -1; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7138 | } else { |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7139 | u32 save_entry = *entry; |
| 7140 | |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7141 | base_flags |= TXD_FLAG_END; |
| 7142 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7143 | tnapi->tx_buffers[*entry].skb = new_skb; |
| 7144 | dma_unmap_addr_set(&tnapi->tx_buffers[*entry], |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7145 | mapping, new_addr); |
| 7146 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7147 | if (tg3_tx_frag_set(tnapi, entry, budget, new_addr, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7148 | new_skb->len, base_flags, |
| 7149 | mss, vlan)) { |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7150 | tg3_tx_skb_unmap(tnapi, save_entry, -1); |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7151 | dev_kfree_skb(new_skb); |
| 7152 | ret = -1; |
| 7153 | } |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7155 | } |
| 7156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7157 | dev_kfree_skb(skb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7158 | *pskb = new_skb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7159 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7160 | } |
| 7161 | |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 7162 | 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] | 7163 | |
| 7164 | /* Use GSO to workaround a rare TSO bug that may be triggered when the |
| 7165 | * TSO header is greater than 80 bytes. |
| 7166 | */ |
| 7167 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) |
| 7168 | { |
| 7169 | struct sk_buff *segs, *nskb; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7170 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7171 | |
| 7172 | /* Estimate the number of fragments in the worst case */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7173 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7174 | netif_stop_queue(tp->dev); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 7175 | |
| 7176 | /* netif_tx_stop_queue() must be done before checking |
| 7177 | * checking tx index in tg3_tx_avail() below, because in |
| 7178 | * tg3_tx(), we update tx index before checking for |
| 7179 | * netif_tx_queue_stopped(). |
| 7180 | */ |
| 7181 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7182 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 7183 | return NETDEV_TX_BUSY; |
| 7184 | |
| 7185 | netif_wake_queue(tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7186 | } |
| 7187 | |
| 7188 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame] | 7189 | if (IS_ERR(segs)) |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7190 | goto tg3_tso_bug_end; |
| 7191 | |
| 7192 | do { |
| 7193 | nskb = segs; |
| 7194 | segs = segs->next; |
| 7195 | nskb->next = NULL; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 7196 | tg3_start_xmit(nskb, tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7197 | } while (segs); |
| 7198 | |
| 7199 | tg3_tso_bug_end: |
| 7200 | dev_kfree_skb(skb); |
| 7201 | |
| 7202 | return NETDEV_TX_OK; |
| 7203 | } |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7204 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 7205 | /* 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] | 7206 | * support TG3_FLAG_HW_TSO_1 or firmware TSO only. |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 7207 | */ |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 7208 | 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] | 7209 | { |
| 7210 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7211 | u32 len, entry, base_flags, mss, vlan = 0; |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7212 | u32 budget; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7213 | int i = -1, would_hit_hwbug; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 7214 | dma_addr_t mapping; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7215 | struct tg3_napi *tnapi; |
| 7216 | struct netdev_queue *txq; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7217 | unsigned int last; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7218 | |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7219 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 7220 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7221 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7222 | tnapi++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7223 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7224 | budget = tg3_tx_avail(tnapi); |
| 7225 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 7226 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7227 | * 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] | 7228 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 7229 | * no IRQ context deadlocks to worry about either. Rejoice! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7230 | */ |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7231 | if (unlikely(budget <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7232 | if (!netif_tx_queue_stopped(txq)) { |
| 7233 | netif_tx_stop_queue(txq); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 7234 | |
| 7235 | /* This is a hard error, log it. */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7236 | netdev_err(dev, |
| 7237 | "BUG! Tx Ring full when queue awake!\n"); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 7238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7239 | return NETDEV_TX_BUSY; |
| 7240 | } |
| 7241 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7242 | entry = tnapi->tx_prod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7243 | base_flags = 0; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 7244 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7245 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7246 | |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 7247 | mss = skb_shinfo(skb)->gso_size; |
| 7248 | if (mss) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7249 | struct iphdr *iph; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7250 | u32 tcp_opt_len, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7251 | |
| 7252 | if (skb_header_cloned(skb) && |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7253 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 7254 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7255 | |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7256 | iph = ip_hdr(skb); |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 7257 | tcp_opt_len = tcp_optlen(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7258 | |
Eric Dumazet | a5a1195 | 2012-01-23 01:22:09 +0000 | [diff] [blame] | 7259 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb) - ETH_HLEN; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7260 | |
Eric Dumazet | a5a1195 | 2012-01-23 01:22:09 +0000 | [diff] [blame] | 7261 | if (!skb_is_gso_v6(skb)) { |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7262 | iph->check = 0; |
| 7263 | iph->tot_len = htons(mss + hdr_len); |
| 7264 | } |
| 7265 | |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7266 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7267 | tg3_flag(tp, TSO_BUG)) |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 7268 | return tg3_tso_bug(tp, skb); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7270 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 7271 | TXD_FLAG_CPU_POST_DMA); |
| 7272 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7273 | if (tg3_flag(tp, HW_TSO_1) || |
| 7274 | tg3_flag(tp, HW_TSO_2) || |
| 7275 | tg3_flag(tp, HW_TSO_3)) { |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 7276 | tcp_hdr(skb)->check = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7277 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 7278 | } else |
| 7279 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 7280 | iph->daddr, 0, |
| 7281 | IPPROTO_TCP, |
| 7282 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7283 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7284 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 7285 | mss |= (hdr_len & 0xc) << 12; |
| 7286 | if (hdr_len & 0x10) |
| 7287 | base_flags |= 0x00000010; |
| 7288 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7289 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 7290 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7291 | else if (tg3_flag(tp, HW_TSO_1) || |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 7292 | 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] | 7293 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7294 | int tsflags; |
| 7295 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7296 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7297 | mss |= (tsflags << 11); |
| 7298 | } |
| 7299 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7300 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7301 | int tsflags; |
| 7302 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7303 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7304 | base_flags |= tsflags << 12; |
| 7305 | } |
| 7306 | } |
| 7307 | } |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 7308 | |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 7309 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 7310 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
| 7311 | base_flags |= TXD_FLAG_JMB_PKT; |
| 7312 | |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7313 | if (vlan_tx_tag_present(skb)) { |
| 7314 | base_flags |= TXD_FLAG_VLAN; |
| 7315 | vlan = vlan_tx_tag_get(skb); |
| 7316 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7317 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 7318 | if ((unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) && |
| 7319 | tg3_flag(tp, TX_TSTAMP_EN)) { |
| 7320 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 7321 | base_flags |= TXD_FLAG_HWTSTAMP; |
| 7322 | } |
| 7323 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7324 | len = skb_headlen(skb); |
| 7325 | |
| 7326 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7327 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 7328 | goto drop; |
| 7329 | |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 7330 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7331 | tnapi->tx_buffers[entry].skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 7332 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7333 | |
| 7334 | would_hit_hwbug = 0; |
| 7335 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7336 | if (tg3_flag(tp, 5701_DMA_BUG)) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7337 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7338 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7339 | if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, len, base_flags | |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7340 | ((skb_shinfo(skb)->nr_frags == 0) ? TXD_FLAG_END : 0), |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7341 | mss, vlan)) { |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7342 | would_hit_hwbug = 1; |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7343 | } else if (skb_shinfo(skb)->nr_frags > 0) { |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7344 | u32 tmp_mss = mss; |
| 7345 | |
| 7346 | if (!tg3_flag(tp, HW_TSO_1) && |
| 7347 | !tg3_flag(tp, HW_TSO_2) && |
| 7348 | !tg3_flag(tp, HW_TSO_3)) |
| 7349 | tmp_mss = 0; |
| 7350 | |
Matt Carlson | c5665a5 | 2012-02-13 10:20:12 +0000 | [diff] [blame] | 7351 | /* Now loop through additional data |
| 7352 | * fragments, and queue them. |
| 7353 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7354 | last = skb_shinfo(skb)->nr_frags - 1; |
| 7355 | for (i = 0; i <= last; i++) { |
| 7356 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 7357 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7358 | len = skb_frag_size(frag); |
Ian Campbell | dc234d0 | 2011-08-24 22:28:11 +0000 | [diff] [blame] | 7359 | mapping = skb_frag_dma_map(&tp->pdev->dev, frag, 0, |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 7360 | len, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7361 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7362 | tnapi->tx_buffers[entry].skb = NULL; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 7363 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7364 | mapping); |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 7365 | if (dma_mapping_error(&tp->pdev->dev, mapping)) |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7366 | goto dma_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7367 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7368 | if (!budget || |
| 7369 | tg3_tx_frag_set(tnapi, &entry, &budget, mapping, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7370 | len, base_flags | |
| 7371 | ((i == last) ? TXD_FLAG_END : 0), |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7372 | tmp_mss, vlan)) { |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 7373 | would_hit_hwbug = 1; |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7374 | break; |
| 7375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7376 | } |
| 7377 | } |
| 7378 | |
| 7379 | if (would_hit_hwbug) { |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7380 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7381 | |
| 7382 | /* If the workaround fails due to memory/mapping |
| 7383 | * failure, silently drop this packet. |
| 7384 | */ |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7385 | entry = tnapi->tx_prod; |
| 7386 | budget = tg3_tx_avail(tnapi); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7387 | if (tigon3_dma_hwbug_workaround(tnapi, &skb, &entry, &budget, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7388 | base_flags, mss, vlan)) |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7389 | goto drop_nofree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7390 | } |
| 7391 | |
Richard Cochran | d515b45 | 2011-06-19 03:31:41 +0000 | [diff] [blame] | 7392 | skb_tx_timestamp(skb); |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 7393 | netdev_tx_sent_queue(txq, skb->len); |
Richard Cochran | d515b45 | 2011-06-19 03:31:41 +0000 | [diff] [blame] | 7394 | |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 7395 | /* Sync BD data before updating mailbox */ |
| 7396 | wmb(); |
| 7397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7398 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7399 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7400 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7401 | tnapi->tx_prod = entry; |
| 7402 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7403 | netif_tx_stop_queue(txq); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 7404 | |
| 7405 | /* netif_tx_stop_queue() must be done before checking |
| 7406 | * checking tx index in tg3_tx_avail() below, because in |
| 7407 | * tg3_tx(), we update tx index before checking for |
| 7408 | * netif_tx_queue_stopped(). |
| 7409 | */ |
| 7410 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7411 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7412 | netif_tx_wake_queue(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 7413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7414 | |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 7415 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7416 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7417 | |
| 7418 | dma_error: |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7419 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, --i); |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7420 | tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7421 | drop: |
| 7422 | dev_kfree_skb(skb); |
| 7423 | drop_nofree: |
| 7424 | tp->tx_dropped++; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7425 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7426 | } |
| 7427 | |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7428 | static void tg3_mac_loopback(struct tg3 *tp, bool enable) |
| 7429 | { |
| 7430 | if (enable) { |
| 7431 | tp->mac_mode &= ~(MAC_MODE_HALF_DUPLEX | |
| 7432 | MAC_MODE_PORT_MODE_MASK); |
| 7433 | |
| 7434 | tp->mac_mode |= MAC_MODE_PORT_INT_LPBACK; |
| 7435 | |
| 7436 | if (!tg3_flag(tp, 5705_PLUS)) |
| 7437 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
| 7438 | |
| 7439 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 7440 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 7441 | else |
| 7442 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7443 | } else { |
| 7444 | tp->mac_mode &= ~MAC_MODE_PORT_INT_LPBACK; |
| 7445 | |
| 7446 | if (tg3_flag(tp, 5705_PLUS) || |
| 7447 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) || |
| 7448 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
| 7449 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 7450 | } |
| 7451 | |
| 7452 | tw32(MAC_MODE, tp->mac_mode); |
| 7453 | udelay(40); |
| 7454 | } |
| 7455 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7456 | 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] | 7457 | { |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7458 | u32 val, bmcr, mac_mode, ptest = 0; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7459 | |
| 7460 | tg3_phy_toggle_apd(tp, false); |
| 7461 | tg3_phy_toggle_automdix(tp, 0); |
| 7462 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7463 | if (extlpbk && tg3_phy_set_extloopbk(tp)) |
| 7464 | return -EIO; |
| 7465 | |
| 7466 | bmcr = BMCR_FULLDPLX; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7467 | switch (speed) { |
| 7468 | case SPEED_10: |
| 7469 | break; |
| 7470 | case SPEED_100: |
| 7471 | bmcr |= BMCR_SPEED100; |
| 7472 | break; |
| 7473 | case SPEED_1000: |
| 7474 | default: |
| 7475 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 7476 | speed = SPEED_100; |
| 7477 | bmcr |= BMCR_SPEED100; |
| 7478 | } else { |
| 7479 | speed = SPEED_1000; |
| 7480 | bmcr |= BMCR_SPEED1000; |
| 7481 | } |
| 7482 | } |
| 7483 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7484 | if (extlpbk) { |
| 7485 | if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 7486 | tg3_readphy(tp, MII_CTRL1000, &val); |
| 7487 | val |= CTL1000_AS_MASTER | |
| 7488 | CTL1000_ENABLE_MASTER; |
| 7489 | tg3_writephy(tp, MII_CTRL1000, val); |
| 7490 | } else { |
| 7491 | ptest = MII_TG3_FET_PTEST_TRIM_SEL | |
| 7492 | MII_TG3_FET_PTEST_TRIM_2; |
| 7493 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest); |
| 7494 | } |
| 7495 | } else |
| 7496 | bmcr |= BMCR_LOOPBACK; |
| 7497 | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7498 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 7499 | |
| 7500 | /* The write needs to be flushed for the FETs */ |
| 7501 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 7502 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 7503 | |
| 7504 | udelay(40); |
| 7505 | |
| 7506 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
| 7507 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7508 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7509 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
| 7510 | MII_TG3_FET_PTEST_FRC_TX_LOCK); |
| 7511 | |
| 7512 | /* The write needs to be flushed for the AC131 */ |
| 7513 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); |
| 7514 | } |
| 7515 | |
| 7516 | /* Reset to prevent losing 1st rx packet intermittently */ |
| 7517 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
| 7518 | tg3_flag(tp, 5780_CLASS)) { |
| 7519 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 7520 | udelay(10); |
| 7521 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 7522 | } |
| 7523 | |
| 7524 | mac_mode = tp->mac_mode & |
| 7525 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 7526 | if (speed == SPEED_1000) |
| 7527 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7528 | else |
| 7529 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 7530 | |
| 7531 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
| 7532 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
| 7533 | |
| 7534 | if (masked_phy_id == TG3_PHY_ID_BCM5401) |
| 7535 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 7536 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
| 7537 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 7538 | |
| 7539 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 7540 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 7541 | } |
| 7542 | |
| 7543 | tw32(MAC_MODE, mac_mode); |
| 7544 | udelay(40); |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7545 | |
| 7546 | return 0; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7547 | } |
| 7548 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7549 | 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] | 7550 | { |
| 7551 | struct tg3 *tp = netdev_priv(dev); |
| 7552 | |
| 7553 | if (features & NETIF_F_LOOPBACK) { |
| 7554 | if (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK) |
| 7555 | return; |
| 7556 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7557 | spin_lock_bh(&tp->lock); |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7558 | tg3_mac_loopback(tp, true); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7559 | netif_carrier_on(tp->dev); |
| 7560 | spin_unlock_bh(&tp->lock); |
| 7561 | netdev_info(dev, "Internal MAC loopback mode enabled.\n"); |
| 7562 | } else { |
| 7563 | if (!(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
| 7564 | return; |
| 7565 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7566 | spin_lock_bh(&tp->lock); |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7567 | tg3_mac_loopback(tp, false); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7568 | /* Force link status check */ |
| 7569 | tg3_setup_phy(tp, 1); |
| 7570 | spin_unlock_bh(&tp->lock); |
| 7571 | netdev_info(dev, "Internal MAC loopback mode disabled.\n"); |
| 7572 | } |
| 7573 | } |
| 7574 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7575 | static netdev_features_t tg3_fix_features(struct net_device *dev, |
| 7576 | netdev_features_t features) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 7577 | { |
| 7578 | struct tg3 *tp = netdev_priv(dev); |
| 7579 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7580 | if (dev->mtu > ETH_DATA_LEN && tg3_flag(tp, 5780_CLASS)) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 7581 | features &= ~NETIF_F_ALL_TSO; |
| 7582 | |
| 7583 | return features; |
| 7584 | } |
| 7585 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7586 | 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] | 7587 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7588 | netdev_features_t changed = dev->features ^ features; |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 7589 | |
| 7590 | if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) |
| 7591 | tg3_set_loopback(dev, features); |
| 7592 | |
| 7593 | return 0; |
| 7594 | } |
| 7595 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7596 | static void tg3_rx_prodring_free(struct tg3 *tp, |
| 7597 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7598 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7599 | int i; |
| 7600 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7601 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7602 | 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] | 7603 | i = (i + 1) & tp->rx_std_ring_mask) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7604 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7605 | tp->rx_pkt_map_sz); |
| 7606 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7607 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7608 | for (i = tpr->rx_jmb_cons_idx; |
| 7609 | i != tpr->rx_jmb_prod_idx; |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7610 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7611 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7612 | TG3_RX_JMB_MAP_SZ); |
| 7613 | } |
| 7614 | } |
| 7615 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7616 | return; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7617 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7618 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7619 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7620 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7621 | tp->rx_pkt_map_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7622 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7623 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7624 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 7625 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7626 | TG3_RX_JMB_MAP_SZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7627 | } |
| 7628 | } |
| 7629 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 7630 | /* Initialize rx rings for packet processing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7631 | * |
| 7632 | * The chip has been shut down and the driver detached from |
| 7633 | * the networking, so no interrupts or new tx packets will |
| 7634 | * end up in the driver. tp->{tx,}lock are held and thus |
| 7635 | * we may not sleep. |
| 7636 | */ |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7637 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
| 7638 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7639 | { |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7640 | u32 i, rx_pkt_dma_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7641 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7642 | tpr->rx_std_cons_idx = 0; |
| 7643 | tpr->rx_std_prod_idx = 0; |
| 7644 | tpr->rx_jmb_cons_idx = 0; |
| 7645 | tpr->rx_jmb_prod_idx = 0; |
| 7646 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7647 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7648 | memset(&tpr->rx_std_buffers[0], 0, |
| 7649 | TG3_RX_STD_BUFF_RING_SIZE(tp)); |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 7650 | if (tpr->rx_jmb_buffers) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7651 | memset(&tpr->rx_jmb_buffers[0], 0, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7652 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7653 | goto done; |
| 7654 | } |
| 7655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7656 | /* Zero out all descriptors. */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7657 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7658 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7659 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7660 | if (tg3_flag(tp, 5780_CLASS) && |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7661 | tp->dev->mtu > ETH_DATA_LEN) |
| 7662 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; |
| 7663 | 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] | 7664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7665 | /* Initialize invariants of the rings, we only set this |
| 7666 | * stuff once. This works because the card does not |
| 7667 | * write into the rx buffer posting rings. |
| 7668 | */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7669 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7670 | struct tg3_rx_buffer_desc *rxd; |
| 7671 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7672 | rxd = &tpr->rx_std[i]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 7673 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7674 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
| 7675 | rxd->opaque = (RXD_OPAQUE_RING_STD | |
| 7676 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 7677 | } |
| 7678 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7679 | /* Now allocate fresh SKBs for each rx ring. */ |
| 7680 | for (i = 0; i < tp->rx_pending; i++) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 7681 | unsigned int frag_size; |
| 7682 | |
| 7683 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_STD, i, |
| 7684 | &frag_size) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7685 | netdev_warn(tp->dev, |
| 7686 | "Using a smaller RX standard ring. Only " |
| 7687 | "%d out of %d buffers were allocated " |
| 7688 | "successfully\n", i, tp->rx_pending); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7689 | if (i == 0) |
| 7690 | goto initfail; |
| 7691 | tp->rx_pending = i; |
| 7692 | break; |
| 7693 | } |
| 7694 | } |
| 7695 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7696 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7697 | goto done; |
| 7698 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7699 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7700 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7701 | if (!tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7702 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7703 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7704 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7705 | struct tg3_rx_buffer_desc *rxd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7706 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7707 | rxd = &tpr->rx_jmb[i].std; |
| 7708 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; |
| 7709 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | |
| 7710 | RXD_FLAG_JUMBO; |
| 7711 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | |
| 7712 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 7713 | } |
| 7714 | |
| 7715 | for (i = 0; i < tp->rx_jumbo_pending; i++) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 7716 | unsigned int frag_size; |
| 7717 | |
| 7718 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_JUMBO, i, |
| 7719 | &frag_size) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7720 | netdev_warn(tp->dev, |
| 7721 | "Using a smaller RX jumbo ring. Only %d " |
| 7722 | "out of %d buffers were allocated " |
| 7723 | "successfully\n", i, tp->rx_jumbo_pending); |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 7724 | if (i == 0) |
| 7725 | goto initfail; |
| 7726 | tp->rx_jumbo_pending = i; |
| 7727 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7728 | } |
| 7729 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7730 | |
| 7731 | done: |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 7732 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7733 | |
| 7734 | initfail: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7735 | tg3_rx_prodring_free(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7736 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7737 | } |
| 7738 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7739 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
| 7740 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7741 | { |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7742 | kfree(tpr->rx_std_buffers); |
| 7743 | tpr->rx_std_buffers = NULL; |
| 7744 | kfree(tpr->rx_jmb_buffers); |
| 7745 | tpr->rx_jmb_buffers = NULL; |
| 7746 | if (tpr->rx_std) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7747 | dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
| 7748 | tpr->rx_std, tpr->rx_std_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7749 | tpr->rx_std = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7750 | } |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7751 | if (tpr->rx_jmb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7752 | dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
| 7753 | tpr->rx_jmb, tpr->rx_jmb_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7754 | tpr->rx_jmb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7755 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7756 | } |
| 7757 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7758 | static int tg3_rx_prodring_init(struct tg3 *tp, |
| 7759 | struct tg3_rx_prodring_set *tpr) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7760 | { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7761 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
| 7762 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7763 | if (!tpr->rx_std_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7764 | return -ENOMEM; |
| 7765 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7766 | tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
| 7767 | TG3_RX_STD_RING_BYTES(tp), |
| 7768 | &tpr->rx_std_mapping, |
| 7769 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7770 | if (!tpr->rx_std) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7771 | goto err_out; |
| 7772 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7773 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7774 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7775 | GFP_KERNEL); |
| 7776 | if (!tpr->rx_jmb_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7777 | goto err_out; |
| 7778 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7779 | tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
| 7780 | TG3_RX_JMB_RING_BYTES(tp), |
| 7781 | &tpr->rx_jmb_mapping, |
| 7782 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7783 | if (!tpr->rx_jmb) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7784 | goto err_out; |
| 7785 | } |
| 7786 | |
| 7787 | return 0; |
| 7788 | |
| 7789 | err_out: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7790 | tg3_rx_prodring_fini(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7791 | return -ENOMEM; |
| 7792 | } |
| 7793 | |
| 7794 | /* Free up pending packets in all rx/tx rings. |
| 7795 | * |
| 7796 | * The chip has been shut down and the driver detached from |
| 7797 | * the networking, so no interrupts or new tx packets will |
| 7798 | * end up in the driver. tp->{tx,}lock is not held and we are not |
| 7799 | * in an interrupt context and thus may sleep. |
| 7800 | */ |
| 7801 | static void tg3_free_rings(struct tg3 *tp) |
| 7802 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7803 | int i, j; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7804 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7805 | for (j = 0; j < tp->irq_cnt; j++) { |
| 7806 | struct tg3_napi *tnapi = &tp->napi[j]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7807 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7808 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
Matt Carlson | b28f642 | 2010-06-05 17:24:32 +0000 | [diff] [blame] | 7809 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7810 | if (!tnapi->tx_buffers) |
| 7811 | continue; |
| 7812 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7813 | for (i = 0; i < TG3_TX_RING_SIZE; i++) { |
| 7814 | struct sk_buff *skb = tnapi->tx_buffers[i].skb; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7815 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7816 | if (!skb) |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7817 | continue; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7818 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7819 | tg3_tx_skb_unmap(tnapi, i, |
| 7820 | skb_shinfo(skb)->nr_frags - 1); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7821 | |
| 7822 | dev_kfree_skb_any(skb); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7823 | } |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 7824 | netdev_tx_reset_queue(netdev_get_tx_queue(tp->dev, j)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7825 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7826 | } |
| 7827 | |
| 7828 | /* Initialize tx/rx rings for packet processing. |
| 7829 | * |
| 7830 | * The chip has been shut down and the driver detached from |
| 7831 | * the networking, so no interrupts or new tx packets will |
| 7832 | * end up in the driver. tp->{tx,}lock are held and thus |
| 7833 | * we may not sleep. |
| 7834 | */ |
| 7835 | static int tg3_init_rings(struct tg3 *tp) |
| 7836 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7837 | int i; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 7838 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7839 | /* Free up all the SKBs. */ |
| 7840 | tg3_free_rings(tp); |
| 7841 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7842 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7843 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7844 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7845 | tnapi->last_tag = 0; |
| 7846 | tnapi->last_irq_tag = 0; |
| 7847 | tnapi->hw_status->status = 0; |
| 7848 | tnapi->hw_status->status_tag = 0; |
| 7849 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7850 | |
| 7851 | tnapi->tx_prod = 0; |
| 7852 | tnapi->tx_cons = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7853 | if (tnapi->tx_ring) |
| 7854 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7855 | |
| 7856 | tnapi->rx_rcb_ptr = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7857 | if (tnapi->rx_rcb) |
| 7858 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7859 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7860 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7861 | tg3_free_rings(tp); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7862 | return -ENOMEM; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7863 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7864 | } |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 7865 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 7866 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7867 | } |
| 7868 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 7869 | static void tg3_mem_tx_release(struct tg3 *tp) |
| 7870 | { |
| 7871 | int i; |
| 7872 | |
| 7873 | for (i = 0; i < tp->irq_max; i++) { |
| 7874 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7875 | |
| 7876 | if (tnapi->tx_ring) { |
| 7877 | dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
| 7878 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
| 7879 | tnapi->tx_ring = NULL; |
| 7880 | } |
| 7881 | |
| 7882 | kfree(tnapi->tx_buffers); |
| 7883 | tnapi->tx_buffers = NULL; |
| 7884 | } |
| 7885 | } |
| 7886 | |
| 7887 | static int tg3_mem_tx_acquire(struct tg3 *tp) |
| 7888 | { |
| 7889 | int i; |
| 7890 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 7891 | |
| 7892 | /* If multivector TSS is enabled, vector 0 does not handle |
| 7893 | * tx interrupts. Don't allocate any resources for it. |
| 7894 | */ |
| 7895 | if (tg3_flag(tp, ENABLE_TSS)) |
| 7896 | tnapi++; |
| 7897 | |
| 7898 | for (i = 0; i < tp->txq_cnt; i++, tnapi++) { |
| 7899 | tnapi->tx_buffers = kzalloc(sizeof(struct tg3_tx_ring_info) * |
| 7900 | TG3_TX_RING_SIZE, GFP_KERNEL); |
| 7901 | if (!tnapi->tx_buffers) |
| 7902 | goto err_out; |
| 7903 | |
| 7904 | tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, |
| 7905 | TG3_TX_RING_BYTES, |
| 7906 | &tnapi->tx_desc_mapping, |
| 7907 | GFP_KERNEL); |
| 7908 | if (!tnapi->tx_ring) |
| 7909 | goto err_out; |
| 7910 | } |
| 7911 | |
| 7912 | return 0; |
| 7913 | |
| 7914 | err_out: |
| 7915 | tg3_mem_tx_release(tp); |
| 7916 | return -ENOMEM; |
| 7917 | } |
| 7918 | |
| 7919 | static void tg3_mem_rx_release(struct tg3 *tp) |
| 7920 | { |
| 7921 | int i; |
| 7922 | |
| 7923 | for (i = 0; i < tp->irq_max; i++) { |
| 7924 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7925 | |
| 7926 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
| 7927 | |
| 7928 | if (!tnapi->rx_rcb) |
| 7929 | continue; |
| 7930 | |
| 7931 | dma_free_coherent(&tp->pdev->dev, |
| 7932 | TG3_RX_RCB_RING_BYTES(tp), |
| 7933 | tnapi->rx_rcb, |
| 7934 | tnapi->rx_rcb_mapping); |
| 7935 | tnapi->rx_rcb = NULL; |
| 7936 | } |
| 7937 | } |
| 7938 | |
| 7939 | static int tg3_mem_rx_acquire(struct tg3 *tp) |
| 7940 | { |
| 7941 | unsigned int i, limit; |
| 7942 | |
| 7943 | limit = tp->rxq_cnt; |
| 7944 | |
| 7945 | /* If RSS is enabled, we need a (dummy) producer ring |
| 7946 | * set on vector zero. This is the true hw prodring. |
| 7947 | */ |
| 7948 | if (tg3_flag(tp, ENABLE_RSS)) |
| 7949 | limit++; |
| 7950 | |
| 7951 | for (i = 0; i < limit; i++) { |
| 7952 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7953 | |
| 7954 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
| 7955 | goto err_out; |
| 7956 | |
| 7957 | /* If multivector RSS is enabled, vector 0 |
| 7958 | * does not handle rx or tx interrupts. |
| 7959 | * Don't allocate any resources for it. |
| 7960 | */ |
| 7961 | if (!i && tg3_flag(tp, ENABLE_RSS)) |
| 7962 | continue; |
| 7963 | |
| 7964 | tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, |
| 7965 | TG3_RX_RCB_RING_BYTES(tp), |
| 7966 | &tnapi->rx_rcb_mapping, |
| 7967 | GFP_KERNEL); |
| 7968 | if (!tnapi->rx_rcb) |
| 7969 | goto err_out; |
| 7970 | |
| 7971 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
| 7972 | } |
| 7973 | |
| 7974 | return 0; |
| 7975 | |
| 7976 | err_out: |
| 7977 | tg3_mem_rx_release(tp); |
| 7978 | return -ENOMEM; |
| 7979 | } |
| 7980 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 7981 | /* |
| 7982 | * Must not be invoked with interrupt sources disabled and |
| 7983 | * the hardware shutdown down. |
| 7984 | */ |
| 7985 | static void tg3_free_consistent(struct tg3 *tp) |
| 7986 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7987 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7988 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7989 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7990 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7991 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7992 | if (tnapi->hw_status) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 7993 | dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
| 7994 | tnapi->hw_status, |
| 7995 | tnapi->status_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7996 | tnapi->hw_status = NULL; |
| 7997 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7998 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7999 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8000 | tg3_mem_rx_release(tp); |
| 8001 | tg3_mem_tx_release(tp); |
| 8002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8003 | if (tp->hw_stats) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8004 | dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
| 8005 | tp->hw_stats, tp->stats_mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8006 | tp->hw_stats = NULL; |
| 8007 | } |
| 8008 | } |
| 8009 | |
| 8010 | /* |
| 8011 | * Must not be invoked with interrupt sources disabled and |
| 8012 | * the hardware shutdown down. Can sleep. |
| 8013 | */ |
| 8014 | static int tg3_alloc_consistent(struct tg3 *tp) |
| 8015 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8016 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8017 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8018 | tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
| 8019 | sizeof(struct tg3_hw_stats), |
| 8020 | &tp->stats_mapping, |
| 8021 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8022 | if (!tp->hw_stats) |
| 8023 | goto err_out; |
| 8024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8025 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 8026 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8027 | for (i = 0; i < tp->irq_cnt; i++) { |
| 8028 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 8029 | struct tg3_hw_status *sblk; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8030 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8031 | tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
| 8032 | TG3_HW_STATUS_SIZE, |
| 8033 | &tnapi->status_mapping, |
| 8034 | GFP_KERNEL); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8035 | if (!tnapi->hw_status) |
| 8036 | goto err_out; |
| 8037 | |
| 8038 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 8039 | sblk = tnapi->hw_status; |
| 8040 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8041 | if (tg3_flag(tp, ENABLE_RSS)) { |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 8042 | u16 *prodptr = NULL; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 8043 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8044 | /* |
| 8045 | * When RSS is enabled, the status block format changes |
| 8046 | * slightly. The "rx_jumbo_consumer", "reserved", |
| 8047 | * and "rx_mini_consumer" members get mapped to the |
| 8048 | * other three rx return ring producer indexes. |
| 8049 | */ |
| 8050 | switch (i) { |
| 8051 | case 1: |
| 8052 | prodptr = &sblk->idx[0].rx_producer; |
| 8053 | break; |
| 8054 | case 2: |
| 8055 | prodptr = &sblk->rx_jumbo_consumer; |
| 8056 | break; |
| 8057 | case 3: |
| 8058 | prodptr = &sblk->reserved; |
| 8059 | break; |
| 8060 | case 4: |
| 8061 | prodptr = &sblk->rx_mini_consumer; |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 8062 | break; |
| 8063 | } |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8064 | tnapi->rx_rcb_prod_idx = prodptr; |
| 8065 | } else { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 8066 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 8067 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8068 | } |
| 8069 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8070 | if (tg3_mem_tx_acquire(tp) || tg3_mem_rx_acquire(tp)) |
| 8071 | goto err_out; |
| 8072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8073 | return 0; |
| 8074 | |
| 8075 | err_out: |
| 8076 | tg3_free_consistent(tp); |
| 8077 | return -ENOMEM; |
| 8078 | } |
| 8079 | |
| 8080 | #define MAX_WAIT_CNT 1000 |
| 8081 | |
| 8082 | /* To stop a block, clear the enable bit and poll till it |
| 8083 | * clears. tp->lock is held. |
| 8084 | */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8085 | 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] | 8086 | { |
| 8087 | unsigned int i; |
| 8088 | u32 val; |
| 8089 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8090 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8091 | switch (ofs) { |
| 8092 | case RCVLSC_MODE: |
| 8093 | case DMAC_MODE: |
| 8094 | case MBFREE_MODE: |
| 8095 | case BUFMGR_MODE: |
| 8096 | case MEMARB_MODE: |
| 8097 | /* We can't enable/disable these bits of the |
| 8098 | * 5705/5750, just say success. |
| 8099 | */ |
| 8100 | return 0; |
| 8101 | |
| 8102 | default: |
| 8103 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 8104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8105 | } |
| 8106 | |
| 8107 | val = tr32(ofs); |
| 8108 | val &= ~enable_bit; |
| 8109 | tw32_f(ofs, val); |
| 8110 | |
| 8111 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 8112 | udelay(100); |
| 8113 | val = tr32(ofs); |
| 8114 | if ((val & enable_bit) == 0) |
| 8115 | break; |
| 8116 | } |
| 8117 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8118 | if (i == MAX_WAIT_CNT && !silent) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 8119 | dev_err(&tp->pdev->dev, |
| 8120 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", |
| 8121 | ofs, enable_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8122 | return -ENODEV; |
| 8123 | } |
| 8124 | |
| 8125 | return 0; |
| 8126 | } |
| 8127 | |
| 8128 | /* tp->lock is held. */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8129 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8130 | { |
| 8131 | int i, err; |
| 8132 | |
| 8133 | tg3_disable_ints(tp); |
| 8134 | |
| 8135 | tp->rx_mode &= ~RX_MODE_ENABLE; |
| 8136 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8137 | udelay(10); |
| 8138 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8139 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
| 8140 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); |
| 8141 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); |
| 8142 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); |
| 8143 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); |
| 8144 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8145 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8146 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); |
| 8147 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); |
| 8148 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); |
| 8149 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); |
| 8150 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); |
| 8151 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); |
| 8152 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8153 | |
| 8154 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 8155 | tw32_f(MAC_MODE, tp->mac_mode); |
| 8156 | udelay(40); |
| 8157 | |
| 8158 | tp->tx_mode &= ~TX_MODE_ENABLE; |
| 8159 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 8160 | |
| 8161 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 8162 | udelay(100); |
| 8163 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) |
| 8164 | break; |
| 8165 | } |
| 8166 | if (i >= MAX_WAIT_CNT) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 8167 | dev_err(&tp->pdev->dev, |
| 8168 | "%s timed out, TX_MODE_ENABLE will not clear " |
| 8169 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 8170 | err |= -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8171 | } |
| 8172 | |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 8173 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8174 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
| 8175 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8176 | |
| 8177 | tw32(FTQ_RESET, 0xffffffff); |
| 8178 | tw32(FTQ_RESET, 0x00000000); |
| 8179 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8180 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
| 8181 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8182 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8183 | for (i = 0; i < tp->irq_cnt; i++) { |
| 8184 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8185 | if (tnapi->hw_status) |
| 8186 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8189 | return err; |
| 8190 | } |
| 8191 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8192 | /* Save PCI command register before chip reset */ |
| 8193 | static void tg3_save_pci_state(struct tg3 *tp) |
| 8194 | { |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 8195 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8196 | } |
| 8197 | |
| 8198 | /* Restore PCI state after chip reset */ |
| 8199 | static void tg3_restore_pci_state(struct tg3 *tp) |
| 8200 | { |
| 8201 | u32 val; |
| 8202 | |
| 8203 | /* Re-enable indirect register accesses. */ |
| 8204 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 8205 | tp->misc_host_ctrl); |
| 8206 | |
| 8207 | /* Set MAX PCI retry to zero. */ |
| 8208 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); |
| 8209 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8210 | tg3_flag(tp, PCIX_MODE)) |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8211 | val |= PCISTATE_RETRY_SAME_DMA; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8212 | /* Allow reads and writes to the APE register and memory space. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8213 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8214 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 8215 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 8216 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8217 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
| 8218 | |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 8219 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8220 | |
Matt Carlson | 2c55a3d | 2011-11-28 09:41:04 +0000 | [diff] [blame] | 8221 | if (!tg3_flag(tp, PCI_EXPRESS)) { |
| 8222 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 8223 | tp->pci_cacheline_sz); |
| 8224 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 8225 | tp->pci_lat_timer); |
Michael Chan | 114342f | 2007-10-15 02:12:26 -0700 | [diff] [blame] | 8226 | } |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 8227 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8228 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8229 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8230 | u16 pcix_cmd; |
| 8231 | |
| 8232 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8233 | &pcix_cmd); |
| 8234 | pcix_cmd &= ~PCI_X_CMD_ERO; |
| 8235 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8236 | pcix_cmd); |
| 8237 | } |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8238 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8239 | if (tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8240 | |
| 8241 | /* Chip reset on 5780 will reset MSI enable bit, |
| 8242 | * so need to restore it. |
| 8243 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8244 | if (tg3_flag(tp, USING_MSI)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8245 | u16 ctrl; |
| 8246 | |
| 8247 | pci_read_config_word(tp->pdev, |
| 8248 | tp->msi_cap + PCI_MSI_FLAGS, |
| 8249 | &ctrl); |
| 8250 | pci_write_config_word(tp->pdev, |
| 8251 | tp->msi_cap + PCI_MSI_FLAGS, |
| 8252 | ctrl | PCI_MSI_FLAGS_ENABLE); |
| 8253 | val = tr32(MSGINT_MODE); |
| 8254 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); |
| 8255 | } |
| 8256 | } |
| 8257 | } |
| 8258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8259 | /* tp->lock is held. */ |
| 8260 | static int tg3_chip_reset(struct tg3 *tp) |
| 8261 | { |
| 8262 | u32 val; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 8263 | void (*write_op)(struct tg3 *, u32, u32); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8264 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8265 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 8266 | tg3_nvram_lock(tp); |
| 8267 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 8268 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
| 8269 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 8270 | /* No matching tg3_nvram_unlock() after this because |
| 8271 | * chip reset below will undo the nvram lock. |
| 8272 | */ |
| 8273 | tp->nvram_lock_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8274 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8275 | /* GRC_MISC_CFG core clock reset will clear the memory |
| 8276 | * enable bit in PCI register 4 and the MSI enable bit |
| 8277 | * on some chips, so we save relevant registers here. |
| 8278 | */ |
| 8279 | tg3_save_pci_state(tp); |
| 8280 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8281 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8282 | tg3_flag(tp, 5755_PLUS)) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8283 | tw32(GRC_FASTBOOT_PC, 0); |
| 8284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8285 | /* |
| 8286 | * We must avoid the readl() that normally takes place. |
| 8287 | * It locks machines, causes machine checks, and other |
| 8288 | * fun things. So, temporarily disable the 5701 |
| 8289 | * hardware workaround, while we do the reset. |
| 8290 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 8291 | write_op = tp->write32; |
| 8292 | if (write_op == tg3_write_flush_reg32) |
| 8293 | tp->write32 = tg3_write32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8294 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8295 | /* Prevent the irq handler from reading or writing PCI registers |
| 8296 | * during chip reset when the memory enable bit in the PCI command |
| 8297 | * register may be cleared. The chip does not generate interrupt |
| 8298 | * at this time, but the irq handler may still be called due to irq |
| 8299 | * sharing or irqpoll. |
| 8300 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8301 | tg3_flag_set(tp, CHIP_RESETTING); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8302 | for (i = 0; i < tp->irq_cnt; i++) { |
| 8303 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8304 | if (tnapi->hw_status) { |
| 8305 | tnapi->hw_status->status = 0; |
| 8306 | tnapi->hw_status->status_tag = 0; |
| 8307 | } |
| 8308 | tnapi->last_tag = 0; |
| 8309 | tnapi->last_irq_tag = 0; |
Michael Chan | b8fa2f3 | 2007-04-06 17:35:37 -0700 | [diff] [blame] | 8310 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8311 | smp_mb(); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8312 | |
| 8313 | for (i = 0; i < tp->irq_cnt; i++) |
| 8314 | synchronize_irq(tp->napi[i].irq_vec); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8315 | |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 8316 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 8317 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 8318 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 8319 | } |
| 8320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8321 | /* do the reset */ |
| 8322 | val = GRC_MISC_CFG_CORECLK_RESET; |
| 8323 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8324 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 8325 | /* Force PCIe 1.0a mode */ |
| 8326 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8327 | !tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 8328 | tr32(TG3_PCIE_PHY_TSTCTL) == |
| 8329 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) |
| 8330 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); |
| 8331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8332 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
| 8333 | tw32(GRC_MISC_CFG, (1 << 29)); |
| 8334 | val |= (1 << 29); |
| 8335 | } |
| 8336 | } |
| 8337 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 8338 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 8339 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
| 8340 | tw32(GRC_VCPU_EXT_CTRL, |
| 8341 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 8342 | } |
| 8343 | |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 8344 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8345 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, CPMU_PRESENT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8346 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 8347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8348 | tw32(GRC_MISC_CFG, val); |
| 8349 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 8350 | /* restore 5701 hardware bug workaround write method */ |
| 8351 | tp->write32 = write_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8352 | |
| 8353 | /* Unfortunately, we have to delay before the PCI read back. |
| 8354 | * Some 575X chips even will not respond to a PCI cfg access |
| 8355 | * when the reset command is given to the chip. |
| 8356 | * |
| 8357 | * How do these hardware designers expect things to work |
| 8358 | * properly if the PCI write is posted for a long period |
| 8359 | * of time? It is always necessary to have some method by |
| 8360 | * which a register read back can occur to push the write |
| 8361 | * out which does the reset. |
| 8362 | * |
| 8363 | * For most tg3 variants the trick below was working. |
| 8364 | * Ho hum... |
| 8365 | */ |
| 8366 | udelay(120); |
| 8367 | |
| 8368 | /* Flush PCI posted writes. The normal MMIO registers |
| 8369 | * are inaccessible at this time so this is the only |
| 8370 | * way to make this reliably (actually, this is no longer |
| 8371 | * the case, see above). I tried to use indirect |
| 8372 | * register read/write but this upset some 5701 variants. |
| 8373 | */ |
| 8374 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); |
| 8375 | |
| 8376 | udelay(120); |
| 8377 | |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8378 | if (tg3_flag(tp, PCI_EXPRESS) && pci_is_pcie(tp->pdev)) { |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 8379 | u16 val16; |
| 8380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8381 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 8382 | int j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8383 | u32 cfg_val; |
| 8384 | |
| 8385 | /* Wait for link training to complete. */ |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 8386 | for (j = 0; j < 5000; j++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8387 | udelay(100); |
| 8388 | |
| 8389 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); |
| 8390 | pci_write_config_dword(tp->pdev, 0xc4, |
| 8391 | cfg_val | (1 << 15)); |
| 8392 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8393 | |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 8394 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8395 | val16 = PCI_EXP_DEVCTL_RELAX_EN | PCI_EXP_DEVCTL_NOSNOOP_EN; |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 8396 | /* |
| 8397 | * Older PCIe devices only support the 128 byte |
| 8398 | * MPS setting. Enforce the restriction. |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8399 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8400 | if (!tg3_flag(tp, CPMU_PRESENT)) |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8401 | val16 |= PCI_EXP_DEVCTL_PAYLOAD; |
| 8402 | pcie_capability_clear_word(tp->pdev, PCI_EXP_DEVCTL, val16); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8403 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8404 | /* Clear error status */ |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8405 | pcie_capability_write_word(tp->pdev, PCI_EXP_DEVSTA, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8406 | PCI_EXP_DEVSTA_CED | |
| 8407 | PCI_EXP_DEVSTA_NFED | |
| 8408 | PCI_EXP_DEVSTA_FED | |
| 8409 | PCI_EXP_DEVSTA_URD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8410 | } |
| 8411 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8412 | tg3_restore_pci_state(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8413 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8414 | tg3_flag_clear(tp, CHIP_RESETTING); |
| 8415 | tg3_flag_clear(tp, ERROR_PROCESSED); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8416 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8417 | val = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8418 | if (tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 8419 | val = tr32(MEMARB_MODE); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8420 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8421 | |
| 8422 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { |
| 8423 | tg3_stop_fw(tp); |
| 8424 | tw32(0x5000, 0x400); |
| 8425 | } |
| 8426 | |
| 8427 | tw32(GRC_MODE, tp->grc_mode); |
| 8428 | |
| 8429 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 8430 | val = tr32(0xc4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8431 | |
| 8432 | tw32(0xc4, val | (1 << 15)); |
| 8433 | } |
| 8434 | |
| 8435 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && |
| 8436 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 8437 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
| 8438 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) |
| 8439 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
| 8440 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 8441 | } |
| 8442 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8443 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 8444 | tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8445 | val = tp->mac_mode; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8446 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 8447 | tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8448 | val = tp->mac_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8449 | } else |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8450 | val = 0; |
| 8451 | |
| 8452 | tw32_f(MAC_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8453 | udelay(40); |
| 8454 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 8455 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
| 8456 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 8457 | err = tg3_poll_fw(tp); |
| 8458 | if (err) |
| 8459 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8460 | |
Matt Carlson | 0a9140c | 2009-08-28 12:27:50 +0000 | [diff] [blame] | 8461 | tg3_mdio_start(tp); |
| 8462 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8463 | if (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8464 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 8465 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8466 | !tg3_flag(tp, 57765_PLUS)) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 8467 | val = tr32(0x7c00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8468 | |
| 8469 | tw32(0x7c00, val | (1 << 25)); |
| 8470 | } |
| 8471 | |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 8472 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 8473 | val = tr32(TG3_CPMU_CLCK_ORIDE); |
| 8474 | tw32(TG3_CPMU_CLCK_ORIDE, val & ~CPMU_CLCK_ORIDE_MAC_ORIDE_EN); |
| 8475 | } |
| 8476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8477 | /* Reprobe ASF enable state. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8478 | tg3_flag_clear(tp, ENABLE_ASF); |
| 8479 | tg3_flag_clear(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8480 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 8481 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 8482 | u32 nic_cfg; |
| 8483 | |
| 8484 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 8485 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8486 | tg3_flag_set(tp, ENABLE_ASF); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 8487 | tp->last_event_jiffies = jiffies; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8488 | if (tg3_flag(tp, 5750_PLUS)) |
| 8489 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8490 | } |
| 8491 | } |
| 8492 | |
| 8493 | return 0; |
| 8494 | } |
| 8495 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 8496 | static void tg3_get_nstats(struct tg3 *, struct rtnl_link_stats64 *); |
| 8497 | static void tg3_get_estats(struct tg3 *, struct tg3_ethtool_stats *); |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8499 | /* tp->lock is held. */ |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8500 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8501 | { |
| 8502 | int err; |
| 8503 | |
| 8504 | tg3_stop_fw(tp); |
| 8505 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8506 | tg3_write_sig_pre_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8507 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8508 | tg3_abort_hw(tp, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8509 | err = tg3_chip_reset(tp); |
| 8510 | |
Matt Carlson | daba2a6 | 2009-04-20 06:58:52 +0000 | [diff] [blame] | 8511 | __tg3_set_mac_addr(tp, 0); |
| 8512 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8513 | tg3_write_sig_legacy(tp, kind); |
| 8514 | tg3_write_sig_post_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8515 | |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8516 | if (tp->hw_stats) { |
| 8517 | /* Save the stats across chip resets... */ |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 8518 | tg3_get_nstats(tp, &tp->net_stats_prev); |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 8519 | tg3_get_estats(tp, &tp->estats_prev); |
| 8520 | |
| 8521 | /* And make sure the next sample is new data */ |
| 8522 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 8523 | } |
| 8524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8525 | if (err) |
| 8526 | return err; |
| 8527 | |
| 8528 | return 0; |
| 8529 | } |
| 8530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8531 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
| 8532 | { |
| 8533 | struct tg3 *tp = netdev_priv(dev); |
| 8534 | struct sockaddr *addr = p; |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8535 | int err = 0, skip_mac_1 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8536 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 8537 | if (!is_valid_ether_addr(addr->sa_data)) |
Danny Kukawka | 504f9b5 | 2012-02-21 02:07:49 +0000 | [diff] [blame] | 8538 | return -EADDRNOTAVAIL; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 8539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8540 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 8541 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 8542 | if (!netif_running(dev)) |
| 8543 | return 0; |
| 8544 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8545 | if (tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8546 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 8547 | |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8548 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
| 8549 | addr0_low = tr32(MAC_ADDR_0_LOW); |
| 8550 | addr1_high = tr32(MAC_ADDR_1_HIGH); |
| 8551 | addr1_low = tr32(MAC_ADDR_1_LOW); |
| 8552 | |
| 8553 | /* Skip MAC addr 1 if ASF is using it. */ |
| 8554 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && |
| 8555 | !(addr1_high == 0 && addr1_low == 0)) |
| 8556 | skip_mac_1 = 1; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 8557 | } |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8558 | spin_lock_bh(&tp->lock); |
| 8559 | __tg3_set_mac_addr(tp, skip_mac_1); |
| 8560 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8561 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 8562 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8563 | } |
| 8564 | |
| 8565 | /* tp->lock is held. */ |
| 8566 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, |
| 8567 | dma_addr_t mapping, u32 maxlen_flags, |
| 8568 | u32 nic_addr) |
| 8569 | { |
| 8570 | tg3_write_mem(tp, |
| 8571 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 8572 | ((u64) mapping >> 32)); |
| 8573 | tg3_write_mem(tp, |
| 8574 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), |
| 8575 | ((u64) mapping & 0xffffffff)); |
| 8576 | tg3_write_mem(tp, |
| 8577 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), |
| 8578 | maxlen_flags); |
| 8579 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8580 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8581 | tg3_write_mem(tp, |
| 8582 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), |
| 8583 | nic_addr); |
| 8584 | } |
| 8585 | |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8586 | |
| 8587 | 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] | 8588 | { |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8589 | int i = 0; |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8590 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8591 | if (!tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8592 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
| 8593 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); |
| 8594 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8595 | } else { |
| 8596 | tw32(HOSTCC_TXCOL_TICKS, 0); |
| 8597 | tw32(HOSTCC_TXMAX_FRAMES, 0); |
| 8598 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8599 | |
| 8600 | for (; i < tp->txq_cnt; i++) { |
| 8601 | u32 reg; |
| 8602 | |
| 8603 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
| 8604 | tw32(reg, ec->tx_coalesce_usecs); |
| 8605 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; |
| 8606 | tw32(reg, ec->tx_max_coalesced_frames); |
| 8607 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 8608 | tw32(reg, ec->tx_max_coalesced_frames_irq); |
| 8609 | } |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8610 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8611 | |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8612 | for (; i < tp->irq_max - 1; i++) { |
| 8613 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 8614 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 8615 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 8616 | } |
| 8617 | } |
| 8618 | |
| 8619 | static void tg3_coal_rx_init(struct tg3 *tp, struct ethtool_coalesce *ec) |
| 8620 | { |
| 8621 | int i = 0; |
| 8622 | u32 limit = tp->rxq_cnt; |
| 8623 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8624 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8625 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
| 8626 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); |
| 8627 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8628 | limit--; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8629 | } else { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8630 | tw32(HOSTCC_RXCOL_TICKS, 0); |
| 8631 | tw32(HOSTCC_RXMAX_FRAMES, 0); |
| 8632 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8633 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8634 | |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 8635 | for (; i < limit; i++) { |
| 8636 | u32 reg; |
| 8637 | |
| 8638 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; |
| 8639 | tw32(reg, ec->rx_coalesce_usecs); |
| 8640 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
| 8641 | tw32(reg, ec->rx_max_coalesced_frames); |
| 8642 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 8643 | tw32(reg, ec->rx_max_coalesced_frames_irq); |
| 8644 | } |
| 8645 | |
| 8646 | for (; i < tp->irq_max - 1; i++) { |
| 8647 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 8648 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 8649 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 8650 | } |
| 8651 | } |
| 8652 | |
| 8653 | static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) |
| 8654 | { |
| 8655 | tg3_coal_tx_init(tp, ec); |
| 8656 | tg3_coal_rx_init(tp, ec); |
| 8657 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8658 | if (!tg3_flag(tp, 5705_PLUS)) { |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8659 | u32 val = ec->stats_block_coalesce_usecs; |
| 8660 | |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 8661 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
| 8662 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); |
| 8663 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 8664 | if (!tp->link_up) |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 8665 | val = 0; |
| 8666 | |
| 8667 | tw32(HOSTCC_STAT_COAL_TICKS, val); |
| 8668 | } |
| 8669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8670 | |
| 8671 | /* tp->lock is held. */ |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8672 | static void tg3_rings_reset(struct tg3 *tp) |
| 8673 | { |
| 8674 | int i; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8675 | u32 stblk, txrcb, rxrcb, limit; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8676 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 8677 | |
| 8678 | /* Disable all transmit rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8679 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8680 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8681 | else if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 3d37728 | 2010-10-14 10:37:39 +0000 | [diff] [blame] | 8682 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 8683 | else if (tg3_flag(tp, 57765_CLASS) || |
| 8684 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8685 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8686 | else |
| 8687 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 8688 | |
| 8689 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 8690 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) |
| 8691 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 8692 | BDINFO_FLAGS_DISABLED); |
| 8693 | |
| 8694 | |
| 8695 | /* Disable all receive return rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8696 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8697 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8698 | else if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8699 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8700 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 8701 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 8702 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8703 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
| 8704 | else |
| 8705 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 8706 | |
| 8707 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 8708 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) |
| 8709 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 8710 | BDINFO_FLAGS_DISABLED); |
| 8711 | |
| 8712 | /* Disable interrupts */ |
| 8713 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 8714 | tp->napi[0].chk_msi_cnt = 0; |
| 8715 | tp->napi[0].last_rx_cons = 0; |
| 8716 | tp->napi[0].last_tx_cons = 0; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8717 | |
| 8718 | /* Zero mailbox registers. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8719 | if (tg3_flag(tp, SUPPORT_MSIX)) { |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 8720 | for (i = 1; i < tp->irq_max; i++) { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8721 | tp->napi[i].tx_prod = 0; |
| 8722 | tp->napi[i].tx_cons = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8723 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 8724 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8725 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
| 8726 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); |
Matt Carlson | 7f23073 | 2011-08-31 11:44:48 +0000 | [diff] [blame] | 8727 | tp->napi[i].chk_msi_cnt = 0; |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 8728 | tp->napi[i].last_rx_cons = 0; |
| 8729 | tp->napi[i].last_tx_cons = 0; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8730 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8731 | if (!tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 8732 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8733 | } else { |
| 8734 | tp->napi[0].tx_prod = 0; |
| 8735 | tp->napi[0].tx_cons = 0; |
| 8736 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 8737 | tw32_rx_mbox(tp->napi[0].consmbox, 0); |
| 8738 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8739 | |
| 8740 | /* Make sure the NIC-based send BD rings are disabled. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8741 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8742 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 8743 | for (i = 0; i < 16; i++) |
| 8744 | tw32_tx_mbox(mbox + i * 8, 0); |
| 8745 | } |
| 8746 | |
| 8747 | txrcb = NIC_SRAM_SEND_RCB; |
| 8748 | rxrcb = NIC_SRAM_RCV_RET_RCB; |
| 8749 | |
| 8750 | /* Clear status block in ram. */ |
| 8751 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8752 | |
| 8753 | /* Set status block DMA address */ |
| 8754 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 8755 | ((u64) tnapi->status_mapping >> 32)); |
| 8756 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 8757 | ((u64) tnapi->status_mapping & 0xffffffff)); |
| 8758 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8759 | if (tnapi->tx_ring) { |
| 8760 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 8761 | (TG3_TX_RING_SIZE << |
| 8762 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 8763 | NIC_SRAM_TX_BUFFER_DESC); |
| 8764 | txrcb += TG3_BDINFO_SIZE; |
| 8765 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8766 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8767 | if (tnapi->rx_rcb) { |
| 8768 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8769 | (tp->rx_ret_ring_mask + 1) << |
| 8770 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8771 | rxrcb += TG3_BDINFO_SIZE; |
| 8772 | } |
| 8773 | |
| 8774 | stblk = HOSTCC_STATBLCK_RING1; |
| 8775 | |
| 8776 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
| 8777 | u64 mapping = (u64)tnapi->status_mapping; |
| 8778 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); |
| 8779 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); |
| 8780 | |
| 8781 | /* Clear status block in ram. */ |
| 8782 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8783 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8784 | if (tnapi->tx_ring) { |
| 8785 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 8786 | (TG3_TX_RING_SIZE << |
| 8787 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 8788 | NIC_SRAM_TX_BUFFER_DESC); |
| 8789 | txrcb += TG3_BDINFO_SIZE; |
| 8790 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8791 | |
| 8792 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8793 | ((tp->rx_ret_ring_mask + 1) << |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8794 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
| 8795 | |
| 8796 | stblk += 8; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8797 | rxrcb += TG3_BDINFO_SIZE; |
| 8798 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8799 | } |
| 8800 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8801 | static void tg3_setup_rxbd_thresholds(struct tg3 *tp) |
| 8802 | { |
| 8803 | u32 val, bdcache_maxcnt, host_rep_thresh, nic_rep_thresh; |
| 8804 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8805 | if (!tg3_flag(tp, 5750_PLUS) || |
| 8806 | tg3_flag(tp, 5780_CLASS) || |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8807 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
Matt Carlson | 513aa6e | 2011-11-21 15:01:18 +0000 | [diff] [blame] | 8808 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 8809 | tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8810 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5700; |
| 8811 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 8812 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) |
| 8813 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5755; |
| 8814 | else |
| 8815 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5906; |
| 8816 | |
| 8817 | nic_rep_thresh = min(bdcache_maxcnt / 2, tp->rx_std_max_post); |
| 8818 | host_rep_thresh = max_t(u32, tp->rx_pending / 8, 1); |
| 8819 | |
| 8820 | val = min(nic_rep_thresh, host_rep_thresh); |
| 8821 | tw32(RCVBDI_STD_THRESH, val); |
| 8822 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8823 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8824 | tw32(STD_REPLENISH_LWM, bdcache_maxcnt); |
| 8825 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8826 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8827 | return; |
| 8828 | |
Matt Carlson | 513aa6e | 2011-11-21 15:01:18 +0000 | [diff] [blame] | 8829 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5700; |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8830 | |
| 8831 | host_rep_thresh = max_t(u32, tp->rx_jumbo_pending / 8, 1); |
| 8832 | |
| 8833 | val = min(bdcache_maxcnt / 2, host_rep_thresh); |
| 8834 | tw32(RCVBDI_JUMBO_THRESH, val); |
| 8835 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8836 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 8837 | tw32(JMB_REPLENISH_LWM, bdcache_maxcnt); |
| 8838 | } |
| 8839 | |
Matt Carlson | ccd5ba9 | 2012-02-13 10:20:08 +0000 | [diff] [blame] | 8840 | static inline u32 calc_crc(unsigned char *buf, int len) |
| 8841 | { |
| 8842 | u32 reg; |
| 8843 | u32 tmp; |
| 8844 | int j, k; |
| 8845 | |
| 8846 | reg = 0xffffffff; |
| 8847 | |
| 8848 | for (j = 0; j < len; j++) { |
| 8849 | reg ^= buf[j]; |
| 8850 | |
| 8851 | for (k = 0; k < 8; k++) { |
| 8852 | tmp = reg & 0x01; |
| 8853 | |
| 8854 | reg >>= 1; |
| 8855 | |
| 8856 | if (tmp) |
| 8857 | reg ^= 0xedb88320; |
| 8858 | } |
| 8859 | } |
| 8860 | |
| 8861 | return ~reg; |
| 8862 | } |
| 8863 | |
| 8864 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) |
| 8865 | { |
| 8866 | /* accept or reject all multicast frames */ |
| 8867 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); |
| 8868 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); |
| 8869 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); |
| 8870 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); |
| 8871 | } |
| 8872 | |
| 8873 | static void __tg3_set_rx_mode(struct net_device *dev) |
| 8874 | { |
| 8875 | struct tg3 *tp = netdev_priv(dev); |
| 8876 | u32 rx_mode; |
| 8877 | |
| 8878 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
| 8879 | RX_MODE_KEEP_VLAN_TAG); |
| 8880 | |
| 8881 | #if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) |
| 8882 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
| 8883 | * flag clear. |
| 8884 | */ |
| 8885 | if (!tg3_flag(tp, ENABLE_ASF)) |
| 8886 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 8887 | #endif |
| 8888 | |
| 8889 | if (dev->flags & IFF_PROMISC) { |
| 8890 | /* Promiscuous mode. */ |
| 8891 | rx_mode |= RX_MODE_PROMISC; |
| 8892 | } else if (dev->flags & IFF_ALLMULTI) { |
| 8893 | /* Accept all multicast. */ |
| 8894 | tg3_set_multi(tp, 1); |
| 8895 | } else if (netdev_mc_empty(dev)) { |
| 8896 | /* Reject all multicast. */ |
| 8897 | tg3_set_multi(tp, 0); |
| 8898 | } else { |
| 8899 | /* Accept one or more multicast(s). */ |
| 8900 | struct netdev_hw_addr *ha; |
| 8901 | u32 mc_filter[4] = { 0, }; |
| 8902 | u32 regidx; |
| 8903 | u32 bit; |
| 8904 | u32 crc; |
| 8905 | |
| 8906 | netdev_for_each_mc_addr(ha, dev) { |
| 8907 | crc = calc_crc(ha->addr, ETH_ALEN); |
| 8908 | bit = ~crc & 0x7f; |
| 8909 | regidx = (bit & 0x60) >> 5; |
| 8910 | bit &= 0x1f; |
| 8911 | mc_filter[regidx] |= (1 << bit); |
| 8912 | } |
| 8913 | |
| 8914 | tw32(MAC_HASH_REG_0, mc_filter[0]); |
| 8915 | tw32(MAC_HASH_REG_1, mc_filter[1]); |
| 8916 | tw32(MAC_HASH_REG_2, mc_filter[2]); |
| 8917 | tw32(MAC_HASH_REG_3, mc_filter[3]); |
| 8918 | } |
| 8919 | |
| 8920 | if (rx_mode != tp->rx_mode) { |
| 8921 | tp->rx_mode = rx_mode; |
| 8922 | tw32_f(MAC_RX_MODE, rx_mode); |
| 8923 | udelay(10); |
| 8924 | } |
| 8925 | } |
| 8926 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 8927 | 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] | 8928 | { |
| 8929 | int i; |
| 8930 | |
| 8931 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 8932 | tp->rss_ind_tbl[i] = ethtool_rxfh_indir_default(i, qcnt); |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8933 | } |
| 8934 | |
| 8935 | static void tg3_rss_check_indir_tbl(struct tg3 *tp) |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8936 | { |
| 8937 | int i; |
| 8938 | |
| 8939 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 8940 | return; |
| 8941 | |
Michael Chan | 0b3ba05 | 2012-11-14 14:44:29 +0000 | [diff] [blame] | 8942 | if (tp->rxq_cnt == 1) { |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8943 | memset(&tp->rss_ind_tbl[0], 0, sizeof(tp->rss_ind_tbl)); |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8944 | return; |
| 8945 | } |
| 8946 | |
| 8947 | /* Validate table against current IRQ count */ |
| 8948 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { |
Michael Chan | 0b3ba05 | 2012-11-14 14:44:29 +0000 | [diff] [blame] | 8949 | if (tp->rss_ind_tbl[i] >= tp->rxq_cnt) |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8950 | break; |
| 8951 | } |
| 8952 | |
| 8953 | if (i != TG3_RSS_INDIR_TBL_SIZE) |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 8954 | tg3_rss_init_dflt_indir_tbl(tp, tp->rxq_cnt); |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8955 | } |
| 8956 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 8957 | static void tg3_rss_write_indir_tbl(struct tg3 *tp) |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 8958 | { |
| 8959 | int i = 0; |
| 8960 | u32 reg = MAC_RSS_INDIR_TBL_0; |
| 8961 | |
| 8962 | while (i < TG3_RSS_INDIR_TBL_SIZE) { |
| 8963 | u32 val = tp->rss_ind_tbl[i]; |
| 8964 | i++; |
| 8965 | for (; i % 8; i++) { |
| 8966 | val <<= 4; |
| 8967 | val |= tp->rss_ind_tbl[i]; |
| 8968 | } |
| 8969 | tw32(reg, val); |
| 8970 | reg += 4; |
| 8971 | } |
| 8972 | } |
| 8973 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8974 | /* tp->lock is held. */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8975 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8976 | { |
| 8977 | u32 val, rdmac_mode; |
| 8978 | int i, err, limit; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 8979 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8980 | |
| 8981 | tg3_disable_ints(tp); |
| 8982 | |
| 8983 | tg3_stop_fw(tp); |
| 8984 | |
| 8985 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); |
| 8986 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8987 | if (tg3_flag(tp, INIT_COMPLETE)) |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 8988 | tg3_abort_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8989 | |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 8990 | /* Enable MAC control of LPI */ |
| 8991 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 8992 | val = TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | |
| 8993 | TG3_CPMU_EEE_LNKIDL_UART_IDL; |
| 8994 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
| 8995 | val |= TG3_CPMU_EEE_LNKIDL_APE_TX_MT; |
| 8996 | |
| 8997 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, val); |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 8998 | |
| 8999 | tw32_f(TG3_CPMU_EEE_CTRL, |
| 9000 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); |
| 9001 | |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 9002 | val = TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
| 9003 | TG3_CPMU_EEEMD_LPI_IN_TX | |
| 9004 | TG3_CPMU_EEEMD_LPI_IN_RX | |
| 9005 | TG3_CPMU_EEEMD_EEE_ENABLE; |
| 9006 | |
| 9007 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
| 9008 | val |= TG3_CPMU_EEEMD_SND_IDX_DET_EN; |
| 9009 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9010 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 9011 | val |= TG3_CPMU_EEEMD_APE_TX_DET_EN; |
| 9012 | |
| 9013 | tw32_f(TG3_CPMU_EEE_MODE, val); |
| 9014 | |
| 9015 | tw32_f(TG3_CPMU_EEE_DBTMR1, |
| 9016 | TG3_CPMU_DBTMR1_PCIEXIT_2047US | |
| 9017 | TG3_CPMU_DBTMR1_LNKIDLE_2047US); |
| 9018 | |
| 9019 | tw32_f(TG3_CPMU_EEE_DBTMR2, |
Matt Carlson | d7f2ab2 | 2011-01-25 15:58:56 +0000 | [diff] [blame] | 9020 | TG3_CPMU_DBTMR2_APE_TX_2047US | |
Matt Carlson | a386b90 | 2010-12-06 08:28:53 +0000 | [diff] [blame] | 9021 | TG3_CPMU_DBTMR2_TXIDXEQ_2047US); |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 9022 | } |
| 9023 | |
Matt Carlson | 603f117 | 2010-02-12 14:47:10 +0000 | [diff] [blame] | 9024 | if (reset_phy) |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 9025 | tg3_phy_reset(tp); |
| 9026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9027 | err = tg3_chip_reset(tp); |
| 9028 | if (err) |
| 9029 | return err; |
| 9030 | |
| 9031 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); |
| 9032 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 9033 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 9034 | val = tr32(TG3_CPMU_CTRL); |
| 9035 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); |
| 9036 | tw32(TG3_CPMU_CTRL, val); |
Matt Carlson | 9acb961 | 2007-11-12 21:10:06 -0800 | [diff] [blame] | 9037 | |
| 9038 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 9039 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 9040 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 9041 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 9042 | |
| 9043 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); |
| 9044 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; |
| 9045 | val |= CPMU_LNK_AWARE_MACCLK_6_25; |
| 9046 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); |
| 9047 | |
| 9048 | val = tr32(TG3_CPMU_HST_ACC); |
| 9049 | val &= ~CPMU_HST_ACC_MACCLK_MASK; |
| 9050 | val |= CPMU_HST_ACC_MACCLK_6_25; |
| 9051 | tw32(TG3_CPMU_HST_ACC, val); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 9052 | } |
| 9053 | |
Matt Carlson | 33466d93 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 9054 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 9055 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 9056 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | |
| 9057 | PCIE_PWR_MGMT_L1_THRESH_4MS; |
| 9058 | tw32(PCIE_PWR_MGMT_THRESH, val); |
Matt Carlson | 521e6b9 | 2009-08-25 10:06:01 +0000 | [diff] [blame] | 9059 | |
| 9060 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; |
| 9061 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); |
| 9062 | |
| 9063 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); |
Matt Carlson | 33466d93 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 9064 | |
Matt Carlson | f40386c | 2009-11-02 14:24:02 +0000 | [diff] [blame] | 9065 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 9066 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 9067 | } |
| 9068 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9069 | if (tg3_flag(tp, L1PLLPD_EN)) { |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 9070 | u32 grc_mode = tr32(GRC_MODE); |
| 9071 | |
| 9072 | /* Access the lower 1K of PL PCIE block registers. */ |
| 9073 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 9074 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 9075 | |
| 9076 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); |
| 9077 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, |
| 9078 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); |
| 9079 | |
| 9080 | tw32(GRC_MODE, grc_mode); |
| 9081 | } |
| 9082 | |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9083 | if (tg3_flag(tp, 57765_CLASS)) { |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 9084 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 9085 | u32 grc_mode = tr32(GRC_MODE); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 9086 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 9087 | /* Access the lower 1K of PL PCIE block registers. */ |
| 9088 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 9089 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 9090 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 9091 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 9092 | TG3_PCIE_PL_LO_PHYCTL5); |
| 9093 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, |
| 9094 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 9095 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 9096 | tw32(GRC_MODE, grc_mode); |
| 9097 | } |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 9098 | |
Matt Carlson | 1ff30a5 | 2011-05-19 12:12:46 +0000 | [diff] [blame] | 9099 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_57765_AX) { |
| 9100 | u32 grc_mode = tr32(GRC_MODE); |
| 9101 | |
| 9102 | /* Access the lower 1K of DL PCIE block registers. */ |
| 9103 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 9104 | tw32(GRC_MODE, val | GRC_MODE_PCIE_DL_SEL); |
| 9105 | |
| 9106 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 9107 | TG3_PCIE_DL_LO_FTSMAX); |
| 9108 | val &= ~TG3_PCIE_DL_LO_FTSMAX_MSK; |
| 9109 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_DL_LO_FTSMAX, |
| 9110 | val | TG3_PCIE_DL_LO_FTSMAX_VAL); |
| 9111 | |
| 9112 | tw32(GRC_MODE, grc_mode); |
| 9113 | } |
| 9114 | |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 9115 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 9116 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 9117 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 9118 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 9119 | } |
| 9120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9121 | /* This works around an issue with Athlon chipsets on |
| 9122 | * B3 tigon3 silicon. This bit has no effect on any |
| 9123 | * other revision. But do not set this on PCI Express |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 9124 | * 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] | 9125 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9126 | if (!tg3_flag(tp, CPMU_PRESENT)) { |
| 9127 | if (!tg3_flag(tp, PCI_EXPRESS)) |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 9128 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
| 9129 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 9130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9131 | |
| 9132 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9133 | tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9134 | val = tr32(TG3PCI_PCISTATE); |
| 9135 | val |= PCISTATE_RETRY_SAME_DMA; |
| 9136 | tw32(TG3PCI_PCISTATE, val); |
| 9137 | } |
| 9138 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9139 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 9140 | /* Allow reads and writes to the |
| 9141 | * APE register and memory space. |
| 9142 | */ |
| 9143 | val = tr32(TG3PCI_PCISTATE); |
| 9144 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 9145 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 9146 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 9147 | tw32(TG3PCI_PCISTATE, val); |
| 9148 | } |
| 9149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9150 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
| 9151 | /* Enable some hw fixes. */ |
| 9152 | val = tr32(TG3PCI_MSI_DATA); |
| 9153 | val |= (1 << 26) | (1 << 28) | (1 << 29); |
| 9154 | tw32(TG3PCI_MSI_DATA, val); |
| 9155 | } |
| 9156 | |
| 9157 | /* Descriptor ring init may make accesses to the |
| 9158 | * NIC SRAM area to setup the TX descriptors, so we |
| 9159 | * can only do this after the hardware has been |
| 9160 | * successfully reset. |
| 9161 | */ |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 9162 | err = tg3_init_rings(tp); |
| 9163 | if (err) |
| 9164 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9165 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9166 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 9167 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
| 9168 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
Matt Carlson | 1a31902 | 2010-04-12 06:58:25 +0000 | [diff] [blame] | 9169 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
| 9170 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9171 | if (!tg3_flag(tp, 57765_CLASS) && |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9172 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 9173 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5762) |
Matt Carlson | 0aebff4 | 2011-04-25 12:42:45 +0000 | [diff] [blame] | 9174 | val |= DMA_RWCTRL_TAGGED_STAT_WA; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 9175 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
| 9176 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && |
| 9177 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 9178 | /* This value is determined during the probe time DMA |
| 9179 | * engine test, tg3_test_dma. |
| 9180 | */ |
| 9181 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 9182 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9183 | |
| 9184 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | |
| 9185 | GRC_MODE_4X_NIC_SEND_RINGS | |
| 9186 | GRC_MODE_NO_TX_PHDR_CSUM | |
| 9187 | GRC_MODE_NO_RX_PHDR_CSUM); |
| 9188 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; |
Michael Chan | d2d746f | 2006-04-06 21:45:39 -0700 | [diff] [blame] | 9189 | |
| 9190 | /* Pseudo-header checksum is done by hardware logic and not |
| 9191 | * the offload processers, so make the chip do the pseudo- |
| 9192 | * header checksums on receive. For transmit it is more |
| 9193 | * convenient to do the pseudo-header checksum in software |
| 9194 | * as Linux does that on transmit for us in all cases. |
| 9195 | */ |
| 9196 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9197 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 9198 | val = GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP; |
| 9199 | if (tp->rxptpctl) |
| 9200 | tw32(TG3_RX_PTP_CTL, |
| 9201 | tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK); |
| 9202 | |
| 9203 | if (tg3_flag(tp, PTP_CAPABLE)) |
| 9204 | val |= GRC_MODE_TIME_SYNC_ENABLE; |
| 9205 | |
| 9206 | tw32(GRC_MODE, tp->grc_mode | val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9207 | |
| 9208 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ |
| 9209 | val = tr32(GRC_MISC_CFG); |
| 9210 | val &= ~0xff; |
| 9211 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 9212 | tw32(GRC_MISC_CFG, val); |
| 9213 | |
| 9214 | /* Initialize MBUF/DESC pool. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9215 | if (tg3_flag(tp, 5750_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9216 | /* Do nothing. */ |
| 9217 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { |
| 9218 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
| 9219 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 9220 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
| 9221 | else |
| 9222 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); |
| 9223 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); |
| 9224 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9225 | } else if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9226 | int fw_len; |
| 9227 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 9228 | fw_len = tp->fw_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9229 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
| 9230 | tw32(BUFMGR_MB_POOL_ADDR, |
| 9231 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); |
| 9232 | tw32(BUFMGR_MB_POOL_SIZE, |
| 9233 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); |
| 9234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9235 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 9236 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9237 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 9238 | tp->bufmgr_config.mbuf_read_dma_low_water); |
| 9239 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 9240 | tp->bufmgr_config.mbuf_mac_rx_low_water); |
| 9241 | tw32(BUFMGR_MB_HIGH_WATER, |
| 9242 | tp->bufmgr_config.mbuf_high_water); |
| 9243 | } else { |
| 9244 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 9245 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); |
| 9246 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 9247 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); |
| 9248 | tw32(BUFMGR_MB_HIGH_WATER, |
| 9249 | tp->bufmgr_config.mbuf_high_water_jumbo); |
| 9250 | } |
| 9251 | tw32(BUFMGR_DMA_LOW_WATER, |
| 9252 | tp->bufmgr_config.dma_low_water); |
| 9253 | tw32(BUFMGR_DMA_HIGH_WATER, |
| 9254 | tp->bufmgr_config.dma_high_water); |
| 9255 | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9256 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
| 9257 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 9258 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 9259 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 9260 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 9261 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) |
| 9262 | val |= BUFMGR_MODE_MBLOW_ATTN_ENAB; |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9263 | tw32(BUFMGR_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9264 | for (i = 0; i < 2000; i++) { |
| 9265 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) |
| 9266 | break; |
| 9267 | udelay(10); |
| 9268 | } |
| 9269 | if (i >= 2000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9270 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9271 | return -ENODEV; |
| 9272 | } |
| 9273 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9274 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) |
| 9275 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 9276 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9277 | tg3_setup_rxbd_thresholds(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9278 | |
| 9279 | /* Initialize TG3_BDINFO's at: |
| 9280 | * RCVDBDI_STD_BD: standard eth size rx ring |
| 9281 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring |
| 9282 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) |
| 9283 | * |
| 9284 | * like so: |
| 9285 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring |
| 9286 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | |
| 9287 | * ring attribute flags |
| 9288 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM |
| 9289 | * |
| 9290 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. |
| 9291 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. |
| 9292 | * |
| 9293 | * The size of each ring is fixed in the firmware, but the location is |
| 9294 | * configurable. |
| 9295 | */ |
| 9296 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9297 | ((u64) tpr->rx_std_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9298 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9299 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9300 | if (!tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 9301 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
| 9302 | NIC_SRAM_RX_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9303 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9304 | /* Disable the mini ring */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9305 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9306 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 9307 | BDINFO_FLAGS_DISABLED); |
| 9308 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9309 | /* Program the jumbo buffer descriptor ring control |
| 9310 | * blocks on those devices that have them. |
| 9311 | */ |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 9312 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9313 | (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9314 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9315 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9316 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9317 | ((u64) tpr->rx_jmb_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9318 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9319 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 9320 | val = TG3_RX_JMB_RING_SIZE(tp) << |
| 9321 | BDINFO_FLAGS_MAXLEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9322 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 9323 | val | BDINFO_FLAGS_USE_EXT_RECV); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9324 | if (!tg3_flag(tp, USE_JUMBO_BDFLAG) || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9325 | tg3_flag(tp, 57765_CLASS) || |
| 9326 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 9327 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
| 9328 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9329 | } else { |
| 9330 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 9331 | BDINFO_FLAGS_DISABLED); |
| 9332 | } |
| 9333 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9334 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | fa6b2aa | 2011-11-21 15:01:19 +0000 | [diff] [blame] | 9335 | val = TG3_RX_STD_RING_SIZE(tp); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9336 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
| 9337 | val |= (TG3_RX_STD_DMA_SZ << 2); |
| 9338 | } else |
Matt Carlson | 04380d4 | 2010-04-12 06:58:29 +0000 | [diff] [blame] | 9339 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9340 | } else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 9341 | val = TG3_RX_STD_MAX_SIZE_5700 << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9342 | |
| 9343 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9344 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 9345 | tpr->rx_std_prod_idx = tp->rx_pending; |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 9346 | 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] | 9347 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9348 | tpr->rx_jmb_prod_idx = |
| 9349 | tg3_flag(tp, JUMBO_RING_ENABLE) ? tp->rx_jumbo_pending : 0; |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 9350 | 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] | 9351 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9352 | tg3_rings_reset(tp); |
| 9353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9354 | /* Initialize MAC address and backoff seed. */ |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 9355 | __tg3_set_mac_addr(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9356 | |
| 9357 | /* MTU + ethernet header + FCS + optional VLAN tag */ |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 9358 | tw32(MAC_RX_MTU_SIZE, |
| 9359 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9360 | |
| 9361 | /* The slot time is changed by tg3_setup_phy if we |
| 9362 | * run at gigabit with half duplex. |
| 9363 | */ |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9364 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 9365 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 9366 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT); |
| 9367 | |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9368 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 9369 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9370 | val |= tr32(MAC_TX_LENGTHS) & |
| 9371 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 9372 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 9373 | |
| 9374 | tw32(MAC_TX_LENGTHS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9375 | |
| 9376 | /* Receive rules. */ |
| 9377 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); |
| 9378 | tw32(RCVLPC_CONFIG, 0x0181); |
| 9379 | |
| 9380 | /* Calculate RDMAC_MODE setting early, we need it to determine |
| 9381 | * the RCVLPC_STATE_ENABLE mask. |
| 9382 | */ |
| 9383 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | |
| 9384 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | |
| 9385 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | |
| 9386 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | |
| 9387 | RDMAC_MODE_LNGREAD_ENAB); |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 9388 | |
Matt Carlson | deabaac | 2010-11-24 08:31:50 +0000 | [diff] [blame] | 9389 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
Matt Carlson | 0339e4e | 2010-02-12 14:47:09 +0000 | [diff] [blame] | 9390 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
| 9391 | |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 9392 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 9393 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 9394 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 9395 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
| 9396 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | |
| 9397 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; |
| 9398 | |
Matt Carlson | c590893 | 2011-03-09 16:58:25 +0000 | [diff] [blame] | 9399 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 9400 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9401 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | c13e371 | 2007-05-05 11:50:04 -0700 | [diff] [blame] | 9402 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9403 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
| 9404 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9405 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9406 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 9407 | } |
| 9408 | } |
| 9409 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9410 | if (tg3_flag(tp, PCI_EXPRESS)) |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 9411 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 9412 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9413 | if (tg3_flag(tp, HW_TSO_1) || |
| 9414 | tg3_flag(tp, HW_TSO_2) || |
| 9415 | tg3_flag(tp, HW_TSO_3)) |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 9416 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
| 9417 | |
Matt Carlson | 108a6c1 | 2011-05-19 12:12:47 +0000 | [diff] [blame] | 9418 | if (tg3_flag(tp, 57765_PLUS) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 9419 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 9420 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
| 9421 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9422 | |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9423 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 9424 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9425 | rdmac_mode |= tr32(RDMAC_MODE) & RDMAC_MODE_H2BNC_VLAN_DET; |
| 9426 | |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 9427 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 9428 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 9429 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 9430 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9431 | tg3_flag(tp, 57765_PLUS)) { |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9432 | u32 tgtreg; |
| 9433 | |
| 9434 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
| 9435 | tgtreg = TG3_RDMA_RSRVCTRL_REG2; |
| 9436 | else |
| 9437 | tgtreg = TG3_RDMA_RSRVCTRL_REG; |
| 9438 | |
| 9439 | val = tr32(tgtreg); |
| 9440 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 9441 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) { |
Matt Carlson | b4495ed | 2011-01-25 15:58:47 +0000 | [diff] [blame] | 9442 | val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | |
| 9443 | TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | |
| 9444 | TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); |
| 9445 | val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B | |
| 9446 | TG3_RDMA_RSRVCTRL_FIFO_LWM_1_5K | |
| 9447 | TG3_RDMA_RSRVCTRL_FIFO_HWM_1_5K; |
Matt Carlson | b75cc0e | 2010-11-24 08:31:46 +0000 | [diff] [blame] | 9448 | } |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9449 | tw32(tgtreg, val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 9450 | } |
| 9451 | |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 9452 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9453 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 9454 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) { |
| 9455 | u32 tgtreg; |
| 9456 | |
| 9457 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
| 9458 | tgtreg = TG3_LSO_RD_DMA_CRPTEN_CTRL2; |
| 9459 | else |
| 9460 | tgtreg = TG3_LSO_RD_DMA_CRPTEN_CTRL; |
| 9461 | |
| 9462 | val = tr32(tgtreg); |
| 9463 | tw32(tgtreg, val | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9464 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | |
| 9465 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); |
| 9466 | } |
| 9467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9468 | /* Receive/send statistics. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9469 | if (tg3_flag(tp, 5750_PLUS)) { |
Michael Chan | 1661394 | 2006-06-29 20:15:13 -0700 | [diff] [blame] | 9470 | val = tr32(RCVLPC_STATS_ENABLE); |
| 9471 | val &= ~RCVLPC_STATSENAB_DACK_FIX; |
| 9472 | tw32(RCVLPC_STATS_ENABLE, val); |
| 9473 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9474 | tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9475 | val = tr32(RCVLPC_STATS_ENABLE); |
| 9476 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; |
| 9477 | tw32(RCVLPC_STATS_ENABLE, val); |
| 9478 | } else { |
| 9479 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); |
| 9480 | } |
| 9481 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); |
| 9482 | tw32(SNDDATAI_STATSENAB, 0xffffff); |
| 9483 | tw32(SNDDATAI_STATSCTRL, |
| 9484 | (SNDDATAI_SCTRL_ENABLE | |
| 9485 | SNDDATAI_SCTRL_FASTUPD)); |
| 9486 | |
| 9487 | /* Setup host coalescing engine. */ |
| 9488 | tw32(HOSTCC_MODE, 0); |
| 9489 | for (i = 0; i < 2000; i++) { |
| 9490 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) |
| 9491 | break; |
| 9492 | udelay(10); |
| 9493 | } |
| 9494 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 9495 | __tg3_set_coalesce(tp, &tp->coal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9496 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9497 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9498 | /* Status/statistics block address. See tg3_timer, |
| 9499 | * the tg3_periodic_fetch_stats call there, and |
| 9500 | * tg3_get_stats to see how this works for 5705/5750 chips. |
| 9501 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9502 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 9503 | ((u64) tp->stats_mapping >> 32)); |
| 9504 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 9505 | ((u64) tp->stats_mapping & 0xffffffff)); |
| 9506 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9508 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9509 | |
| 9510 | /* Clear statistics and status block memory areas */ |
| 9511 | for (i = NIC_SRAM_STATS_BLK; |
| 9512 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; |
| 9513 | i += sizeof(u32)) { |
| 9514 | tg3_write_mem(tp, i, 0); |
| 9515 | udelay(40); |
| 9516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9517 | } |
| 9518 | |
| 9519 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); |
| 9520 | |
| 9521 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); |
| 9522 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9523 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9524 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
| 9525 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9526 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
| 9527 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 9528 | /* reset to prevent losing 1st rx packet intermittently */ |
| 9529 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 9530 | udelay(10); |
| 9531 | } |
| 9532 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 9533 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 9534 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | |
| 9535 | MAC_MODE_FHDE_ENABLE; |
| 9536 | if (tg3_flag(tp, ENABLE_APE)) |
| 9537 | 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] | 9538 | if (!tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9539 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 9540 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
| 9541 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9542 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
| 9543 | udelay(40); |
| 9544 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9545 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9546 | * If TG3_FLAG_IS_NIC is zero, we should read the |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9547 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
| 9548 | * whether used as inputs or outputs, are set by boot code after |
| 9549 | * reset. |
| 9550 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9551 | if (!tg3_flag(tp, IS_NIC)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9552 | u32 gpio_mask; |
| 9553 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 9554 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
| 9555 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 9556 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 9557 | |
| 9558 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 9559 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
| 9560 | GRC_LCLCTRL_GPIO_OUTPUT3; |
| 9561 | |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 9562 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 9563 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 9564 | |
Gary Zambrano | aaf8446 | 2007-05-05 11:51:45 -0700 | [diff] [blame] | 9565 | tp->grc_local_ctrl &= ~gpio_mask; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9566 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
| 9567 | |
| 9568 | /* GPIO1 must be driven high for eeprom write protect */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9569 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 9570 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 9571 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 9572 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9573 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 9574 | udelay(100); |
| 9575 | |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9576 | if (tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9577 | val = tr32(MSGINT_MODE); |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 9578 | val |= MSGINT_MODE_ENABLE; |
| 9579 | if (tp->irq_cnt > 1) |
| 9580 | val |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 9581 | if (!tg3_flag(tp, 1SHOT_MSI)) |
| 9582 | val |= MSGINT_MODE_ONE_SHOT_DISABLE; |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9583 | tw32(MSGINT_MODE, val); |
| 9584 | } |
| 9585 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9586 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9587 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
| 9588 | udelay(40); |
| 9589 | } |
| 9590 | |
| 9591 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | |
| 9592 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | |
| 9593 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | |
| 9594 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | |
| 9595 | WDMAC_MODE_LNGREAD_ENAB); |
| 9596 | |
Matt Carlson | c590893 | 2011-03-09 16:58:25 +0000 | [diff] [blame] | 9597 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 9598 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9599 | if (tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9600 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
| 9601 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { |
| 9602 | /* nothing */ |
| 9603 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9604 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9605 | val |= WDMAC_MODE_RX_ACCEL; |
| 9606 | } |
| 9607 | } |
| 9608 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 9609 | /* Enable host coalescing bug fix */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9610 | if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 9611 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 9612 | |
Matt Carlson | 788a035 | 2009-11-02 14:26:03 +0000 | [diff] [blame] | 9613 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 9614 | val |= WDMAC_MODE_BURST_ALL_DATA; |
| 9615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9616 | tw32_f(WDMAC_MODE, val); |
| 9617 | udelay(40); |
| 9618 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9619 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9620 | u16 pcix_cmd; |
| 9621 | |
| 9622 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 9623 | &pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9624 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9625 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
| 9626 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9627 | } 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] | 9628 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
| 9629 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9630 | } |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 9631 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 9632 | pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9633 | } |
| 9634 | |
| 9635 | tw32_f(RDMAC_MODE, rdmac_mode); |
| 9636 | udelay(40); |
| 9637 | |
Michael Chan | 091f0ea | 2012-07-29 19:15:43 +0000 | [diff] [blame] | 9638 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
| 9639 | for (i = 0; i < TG3_NUM_RDMA_CHANNELS; i++) { |
| 9640 | if (tr32(TG3_RDMA_LENGTH + (i << 2)) > TG3_MAX_MTU(tp)) |
| 9641 | break; |
| 9642 | } |
| 9643 | if (i < TG3_NUM_RDMA_CHANNELS) { |
| 9644 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 9645 | val |= TG3_LSO_RD_DMA_TX_LENGTH_WA; |
| 9646 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val); |
| 9647 | tg3_flag_set(tp, 5719_RDMA_BUG); |
| 9648 | } |
| 9649 | } |
| 9650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9651 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9652 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9653 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 9654 | |
| 9655 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 9656 | tw32(SNDDATAC_MODE, |
| 9657 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); |
| 9658 | else |
| 9659 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); |
| 9660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9661 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
| 9662 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9663 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9664 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9665 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
| 9666 | tw32(RCVDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9667 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9668 | if (tg3_flag(tp, HW_TSO_1) || |
| 9669 | tg3_flag(tp, HW_TSO_2) || |
| 9670 | tg3_flag(tp, HW_TSO_3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9671 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9672 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9673 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9674 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
| 9675 | tw32(SNDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9676 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
| 9677 | |
| 9678 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 9679 | err = tg3_load_5701_a0_firmware_fix(tp); |
| 9680 | if (err) |
| 9681 | return err; |
| 9682 | } |
| 9683 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9684 | if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9685 | err = tg3_load_tso_firmware(tp); |
| 9686 | if (err) |
| 9687 | return err; |
| 9688 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9689 | |
| 9690 | tp->tx_mode = TX_MODE_ENABLE; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9691 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9692 | if (tg3_flag(tp, 5755_PLUS) || |
Matt Carlson | b1d0521 | 2010-06-05 17:24:31 +0000 | [diff] [blame] | 9693 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 9694 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9695 | |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9696 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 9697 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9698 | val = TX_MODE_JMB_FRM_LEN | TX_MODE_CNT_DN_MODE; |
| 9699 | tp->tx_mode &= ~val; |
| 9700 | tp->tx_mode |= tr32(MAC_TX_MODE) & val; |
| 9701 | } |
| 9702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9703 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 9704 | udelay(100); |
| 9705 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9706 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 9707 | tg3_rss_write_indir_tbl(tp); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9708 | |
| 9709 | /* Setup the "secret" hash key. */ |
| 9710 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); |
| 9711 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); |
| 9712 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); |
| 9713 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); |
| 9714 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); |
| 9715 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); |
| 9716 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); |
| 9717 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); |
| 9718 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); |
| 9719 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); |
| 9720 | } |
| 9721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9722 | tp->rx_mode = RX_MODE_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9723 | if (tg3_flag(tp, 5755_PLUS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 9724 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
| 9725 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9726 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9727 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
| 9728 | RX_MODE_RSS_ITBL_HASH_BITS_7 | |
| 9729 | RX_MODE_RSS_IPV6_HASH_EN | |
| 9730 | RX_MODE_RSS_TCP_IPV6_HASH_EN | |
| 9731 | RX_MODE_RSS_IPV4_HASH_EN | |
| 9732 | RX_MODE_RSS_TCP_IPV4_HASH_EN; |
| 9733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9734 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 9735 | udelay(10); |
| 9736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9737 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 9738 | |
| 9739 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9740 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9741 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 9742 | udelay(10); |
| 9743 | } |
| 9744 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 9745 | udelay(10); |
| 9746 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9747 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9748 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9749 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9750 | /* Set drive transmission level to 1.2V */ |
| 9751 | /* only if the signal pre-emphasis bit is not set */ |
| 9752 | val = tr32(MAC_SERDES_CFG); |
| 9753 | val &= 0xfffff000; |
| 9754 | val |= 0x880; |
| 9755 | tw32(MAC_SERDES_CFG, val); |
| 9756 | } |
| 9757 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) |
| 9758 | tw32(MAC_SERDES_CFG, 0x616000); |
| 9759 | } |
| 9760 | |
| 9761 | /* Prevent chip from dropping frames when flow control |
| 9762 | * is enabled. |
| 9763 | */ |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9764 | if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 9765 | val = 1; |
| 9766 | else |
| 9767 | val = 2; |
| 9768 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9769 | |
| 9770 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9771 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9772 | /* Use hardware link auto-negotiation */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9773 | tg3_flag_set(tp, HW_AUTONEG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9774 | } |
| 9775 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9776 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 9777 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 9778 | u32 tmp; |
| 9779 | |
| 9780 | tmp = tr32(SERDES_RX_CTRL); |
| 9781 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); |
| 9782 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; |
| 9783 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; |
| 9784 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 9785 | } |
| 9786 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9787 | if (!tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 9788 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9789 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9790 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9791 | err = tg3_setup_phy(tp, 0); |
| 9792 | if (err) |
| 9793 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9794 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9795 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 9796 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9797 | u32 tmp; |
| 9798 | |
| 9799 | /* Clear CRC stats. */ |
| 9800 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { |
| 9801 | tg3_writephy(tp, MII_TG3_TEST1, |
| 9802 | tmp | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 9803 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 9804 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9805 | } |
| 9806 | } |
| 9807 | |
| 9808 | __tg3_set_rx_mode(tp->dev); |
| 9809 | |
| 9810 | /* Initialize receive rules. */ |
| 9811 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); |
| 9812 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 9813 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); |
| 9814 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 9815 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9816 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9817 | limit = 8; |
| 9818 | else |
| 9819 | limit = 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9820 | if (tg3_flag(tp, ENABLE_ASF)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9821 | limit -= 4; |
| 9822 | switch (limit) { |
| 9823 | case 16: |
| 9824 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); |
| 9825 | case 15: |
| 9826 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); |
| 9827 | case 14: |
| 9828 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); |
| 9829 | case 13: |
| 9830 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); |
| 9831 | case 12: |
| 9832 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); |
| 9833 | case 11: |
| 9834 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); |
| 9835 | case 10: |
| 9836 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); |
| 9837 | case 9: |
| 9838 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); |
| 9839 | case 8: |
| 9840 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); |
| 9841 | case 7: |
| 9842 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); |
| 9843 | case 6: |
| 9844 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); |
| 9845 | case 5: |
| 9846 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); |
| 9847 | case 4: |
| 9848 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ |
| 9849 | case 3: |
| 9850 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ |
| 9851 | case 2: |
| 9852 | case 1: |
| 9853 | |
| 9854 | default: |
| 9855 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 9856 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9857 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9858 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 9ce768e | 2007-10-11 19:49:11 -0700 | [diff] [blame] | 9859 | /* Write our heartbeat update interval to APE. */ |
| 9860 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, |
| 9861 | APE_HOST_HEARTBEAT_INT_DISABLE); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 9862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9863 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
| 9864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9865 | return 0; |
| 9866 | } |
| 9867 | |
| 9868 | /* Called at device open time to get the chip ready for |
| 9869 | * packet processing. Invoked with tp->lock held. |
| 9870 | */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 9871 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9872 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9873 | tg3_switch_clocks(tp); |
| 9874 | |
| 9875 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 9876 | |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 9877 | return tg3_reset_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9878 | } |
| 9879 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9880 | static void tg3_sd_scan_scratchpad(struct tg3 *tp, struct tg3_ocir *ocir) |
| 9881 | { |
| 9882 | int i; |
| 9883 | |
| 9884 | for (i = 0; i < TG3_SD_NUM_RECS; i++, ocir++) { |
| 9885 | u32 off = i * TG3_OCIR_LEN, len = TG3_OCIR_LEN; |
| 9886 | |
| 9887 | tg3_ape_scratchpad_read(tp, (u32 *) ocir, off, len); |
| 9888 | off += len; |
| 9889 | |
| 9890 | if (ocir->signature != TG3_OCIR_SIG_MAGIC || |
| 9891 | !(ocir->version_flags & TG3_OCIR_FLAG_ACTIVE)) |
| 9892 | memset(ocir, 0, TG3_OCIR_LEN); |
| 9893 | } |
| 9894 | } |
| 9895 | |
| 9896 | /* sysfs attributes for hwmon */ |
| 9897 | static ssize_t tg3_show_temp(struct device *dev, |
| 9898 | struct device_attribute *devattr, char *buf) |
| 9899 | { |
| 9900 | struct pci_dev *pdev = to_pci_dev(dev); |
| 9901 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 9902 | struct tg3 *tp = netdev_priv(netdev); |
| 9903 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 9904 | u32 temperature; |
| 9905 | |
| 9906 | spin_lock_bh(&tp->lock); |
| 9907 | tg3_ape_scratchpad_read(tp, &temperature, attr->index, |
| 9908 | sizeof(temperature)); |
| 9909 | spin_unlock_bh(&tp->lock); |
| 9910 | return sprintf(buf, "%u\n", temperature); |
| 9911 | } |
| 9912 | |
| 9913 | |
| 9914 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, tg3_show_temp, NULL, |
| 9915 | TG3_TEMP_SENSOR_OFFSET); |
| 9916 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, tg3_show_temp, NULL, |
| 9917 | TG3_TEMP_CAUTION_OFFSET); |
| 9918 | static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, tg3_show_temp, NULL, |
| 9919 | TG3_TEMP_MAX_OFFSET); |
| 9920 | |
| 9921 | static struct attribute *tg3_attributes[] = { |
| 9922 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 9923 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 9924 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 9925 | NULL |
| 9926 | }; |
| 9927 | |
| 9928 | static const struct attribute_group tg3_group = { |
| 9929 | .attrs = tg3_attributes, |
| 9930 | }; |
| 9931 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9932 | static void tg3_hwmon_close(struct tg3 *tp) |
| 9933 | { |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9934 | if (tp->hwmon_dev) { |
| 9935 | hwmon_device_unregister(tp->hwmon_dev); |
| 9936 | tp->hwmon_dev = NULL; |
| 9937 | sysfs_remove_group(&tp->pdev->dev.kobj, &tg3_group); |
| 9938 | } |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9939 | } |
| 9940 | |
| 9941 | static void tg3_hwmon_open(struct tg3 *tp) |
| 9942 | { |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9943 | int i, err; |
| 9944 | u32 size = 0; |
| 9945 | struct pci_dev *pdev = tp->pdev; |
| 9946 | struct tg3_ocir ocirs[TG3_SD_NUM_RECS]; |
| 9947 | |
| 9948 | tg3_sd_scan_scratchpad(tp, ocirs); |
| 9949 | |
| 9950 | for (i = 0; i < TG3_SD_NUM_RECS; i++) { |
| 9951 | if (!ocirs[i].src_data_length) |
| 9952 | continue; |
| 9953 | |
| 9954 | size += ocirs[i].src_hdr_length; |
| 9955 | size += ocirs[i].src_data_length; |
| 9956 | } |
| 9957 | |
| 9958 | if (!size) |
| 9959 | return; |
| 9960 | |
| 9961 | /* Register hwmon sysfs hooks */ |
| 9962 | err = sysfs_create_group(&pdev->dev.kobj, &tg3_group); |
| 9963 | if (err) { |
| 9964 | dev_err(&pdev->dev, "Cannot create sysfs group, aborting\n"); |
| 9965 | return; |
| 9966 | } |
| 9967 | |
| 9968 | tp->hwmon_dev = hwmon_device_register(&pdev->dev); |
| 9969 | if (IS_ERR(tp->hwmon_dev)) { |
| 9970 | tp->hwmon_dev = NULL; |
| 9971 | dev_err(&pdev->dev, "Cannot register hwmon device, aborting\n"); |
| 9972 | sysfs_remove_group(&pdev->dev.kobj, &tg3_group); |
| 9973 | } |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 9974 | } |
| 9975 | |
| 9976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9977 | #define TG3_STAT_ADD32(PSTAT, REG) \ |
| 9978 | do { u32 __val = tr32(REG); \ |
| 9979 | (PSTAT)->low += __val; \ |
| 9980 | if ((PSTAT)->low < __val) \ |
| 9981 | (PSTAT)->high += 1; \ |
| 9982 | } while (0) |
| 9983 | |
| 9984 | static void tg3_periodic_fetch_stats(struct tg3 *tp) |
| 9985 | { |
| 9986 | struct tg3_hw_stats *sp = tp->hw_stats; |
| 9987 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 9988 | if (!tp->link_up) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9989 | return; |
| 9990 | |
| 9991 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); |
| 9992 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); |
| 9993 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); |
| 9994 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); |
| 9995 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); |
| 9996 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); |
| 9997 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); |
| 9998 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); |
| 9999 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); |
| 10000 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); |
| 10001 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); |
| 10002 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); |
| 10003 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); |
Michael Chan | 091f0ea | 2012-07-29 19:15:43 +0000 | [diff] [blame] | 10004 | if (unlikely(tg3_flag(tp, 5719_RDMA_BUG) && |
| 10005 | (sp->tx_ucast_packets.low + sp->tx_mcast_packets.low + |
| 10006 | sp->tx_bcast_packets.low) > TG3_NUM_RDMA_CHANNELS)) { |
| 10007 | u32 val; |
| 10008 | |
| 10009 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 10010 | val &= ~TG3_LSO_RD_DMA_TX_LENGTH_WA; |
| 10011 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val); |
| 10012 | tg3_flag_clear(tp, 5719_RDMA_BUG); |
| 10013 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10014 | |
| 10015 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); |
| 10016 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); |
| 10017 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); |
| 10018 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); |
| 10019 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); |
| 10020 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); |
| 10021 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); |
| 10022 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); |
| 10023 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); |
| 10024 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); |
| 10025 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); |
| 10026 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); |
| 10027 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); |
| 10028 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 10029 | |
| 10030 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); |
Matt Carlson | 310050f | 2011-05-19 12:12:55 +0000 | [diff] [blame] | 10031 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 10032 | tp->pci_chip_rev_id != CHIPREV_ID_5719_A0 && |
| 10033 | tp->pci_chip_rev_id != CHIPREV_ID_5720_A0) { |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 10034 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
| 10035 | } else { |
| 10036 | u32 val = tr32(HOSTCC_FLOW_ATTN); |
| 10037 | val = (val & HOSTCC_FLOW_ATTN_MBUF_LWM) ? 1 : 0; |
| 10038 | if (val) { |
| 10039 | tw32(HOSTCC_FLOW_ATTN, HOSTCC_FLOW_ATTN_MBUF_LWM); |
| 10040 | sp->rx_discards.low += val; |
| 10041 | if (sp->rx_discards.low < val) |
| 10042 | sp->rx_discards.high += 1; |
| 10043 | } |
| 10044 | sp->mbuf_lwm_thresh_hit = sp->rx_discards; |
| 10045 | } |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 10046 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10047 | } |
| 10048 | |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 10049 | static void tg3_chk_missed_msi(struct tg3 *tp) |
| 10050 | { |
| 10051 | u32 i; |
| 10052 | |
| 10053 | for (i = 0; i < tp->irq_cnt; i++) { |
| 10054 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10055 | |
| 10056 | if (tg3_has_work(tnapi)) { |
| 10057 | if (tnapi->last_rx_cons == tnapi->rx_rcb_ptr && |
| 10058 | tnapi->last_tx_cons == tnapi->tx_cons) { |
| 10059 | if (tnapi->chk_msi_cnt < 1) { |
| 10060 | tnapi->chk_msi_cnt++; |
| 10061 | return; |
| 10062 | } |
Matt Carlson | 7f23073 | 2011-08-31 11:44:48 +0000 | [diff] [blame] | 10063 | tg3_msi(0, tnapi); |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 10064 | } |
| 10065 | } |
| 10066 | tnapi->chk_msi_cnt = 0; |
| 10067 | tnapi->last_rx_cons = tnapi->rx_rcb_ptr; |
| 10068 | tnapi->last_tx_cons = tnapi->tx_cons; |
| 10069 | } |
| 10070 | } |
| 10071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10072 | static void tg3_timer(unsigned long __opaque) |
| 10073 | { |
| 10074 | struct tg3 *tp = (struct tg3 *) __opaque; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10075 | |
Matt Carlson | 5b19062 | 2011-11-04 09:15:04 +0000 | [diff] [blame] | 10076 | if (tp->irq_sync || tg3_flag(tp, RESET_TASK_PENDING)) |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 10077 | goto restart_timer; |
| 10078 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10079 | spin_lock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10080 | |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 10081 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 10082 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 10083 | tg3_chk_missed_msi(tp); |
| 10084 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10085 | if (!tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10086 | /* All of this garbage is because when using non-tagged |
| 10087 | * IRQ status the mailbox/status_block protocol the chip |
| 10088 | * uses with the cpu is race prone. |
| 10089 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10090 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10091 | tw32(GRC_LOCAL_CTRL, |
| 10092 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 10093 | } else { |
| 10094 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10095 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10096 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10097 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10098 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10099 | spin_unlock(&tp->lock); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 10100 | tg3_reset_task_schedule(tp); |
Matt Carlson | 5b19062 | 2011-11-04 09:15:04 +0000 | [diff] [blame] | 10101 | goto restart_timer; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10102 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10103 | } |
| 10104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10105 | /* This part only runs once per second. */ |
| 10106 | if (!--tp->timer_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10107 | if (tg3_flag(tp, 5705_PLUS)) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10108 | tg3_periodic_fetch_stats(tp); |
| 10109 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 10110 | if (tp->setlpicnt && !--tp->setlpicnt) |
| 10111 | tg3_phy_eee_enable(tp); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 10112 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10113 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10114 | u32 mac_stat; |
| 10115 | int phy_event; |
| 10116 | |
| 10117 | mac_stat = tr32(MAC_STATUS); |
| 10118 | |
| 10119 | phy_event = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10120 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10121 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
| 10122 | phy_event = 1; |
| 10123 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) |
| 10124 | phy_event = 1; |
| 10125 | |
| 10126 | if (phy_event) |
| 10127 | tg3_setup_phy(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10128 | } else if (tg3_flag(tp, POLL_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10129 | u32 mac_stat = tr32(MAC_STATUS); |
| 10130 | int need_setup = 0; |
| 10131 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 10132 | if (tp->link_up && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10133 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
| 10134 | need_setup = 1; |
| 10135 | } |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 10136 | if (!tp->link_up && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10137 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
| 10138 | MAC_STATUS_SIGNAL_DET))) { |
| 10139 | need_setup = 1; |
| 10140 | } |
| 10141 | if (need_setup) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 10142 | if (!tp->serdes_counter) { |
| 10143 | tw32_f(MAC_MODE, |
| 10144 | (tp->mac_mode & |
| 10145 | ~MAC_MODE_PORT_MODE_MASK)); |
| 10146 | udelay(40); |
| 10147 | tw32_f(MAC_MODE, tp->mac_mode); |
| 10148 | udelay(40); |
| 10149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10150 | tg3_setup_phy(tp, 0); |
| 10151 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10152 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10153 | tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 10154 | tg3_serdes_parallel_detect(tp); |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 10155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10156 | |
| 10157 | tp->timer_counter = tp->timer_multiplier; |
| 10158 | } |
| 10159 | |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 10160 | /* Heartbeat is only sent once every 2 seconds. |
| 10161 | * |
| 10162 | * The heartbeat is to tell the ASF firmware that the host |
| 10163 | * driver is still alive. In the event that the OS crashes, |
| 10164 | * ASF needs to reset the hardware to free up the FIFO space |
| 10165 | * that may be filled with rx packets destined for the host. |
| 10166 | * If the FIFO is full, ASF will no longer function properly. |
| 10167 | * |
| 10168 | * Unintended resets have been reported on real time kernels |
| 10169 | * where the timer doesn't run on time. Netpoll will also have |
| 10170 | * same problem. |
| 10171 | * |
| 10172 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware |
| 10173 | * to check the ring condition when the heartbeat is expiring |
| 10174 | * before doing the reset. This will prevent most unintended |
| 10175 | * resets. |
| 10176 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10177 | if (!--tp->asf_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10178 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 10179 | tg3_wait_for_event_ack(tp); |
| 10180 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 10181 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 10182 | FWCMD_NICDRV_ALIVE3); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 10183 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10184 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
| 10185 | TG3_FW_UPDATE_TIMEOUT_SEC); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 10186 | |
| 10187 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10188 | } |
| 10189 | tp->asf_counter = tp->asf_multiplier; |
| 10190 | } |
| 10191 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10192 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10193 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 10194 | restart_timer: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10195 | tp->timer.expires = jiffies + tp->timer_offset; |
| 10196 | add_timer(&tp->timer); |
| 10197 | } |
| 10198 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 10199 | static void tg3_timer_init(struct tg3 *tp) |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10200 | { |
| 10201 | if (tg3_flag(tp, TAGGED_STATUS) && |
| 10202 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 10203 | !tg3_flag(tp, 57765_CLASS)) |
| 10204 | tp->timer_offset = HZ; |
| 10205 | else |
| 10206 | tp->timer_offset = HZ / 10; |
| 10207 | |
| 10208 | BUG_ON(tp->timer_offset > HZ); |
| 10209 | |
| 10210 | tp->timer_multiplier = (HZ / tp->timer_offset); |
| 10211 | tp->asf_multiplier = (HZ / tp->timer_offset) * |
| 10212 | TG3_FW_UPDATE_FREQ_SEC; |
| 10213 | |
| 10214 | init_timer(&tp->timer); |
| 10215 | tp->timer.data = (unsigned long) tp; |
| 10216 | tp->timer.function = tg3_timer; |
| 10217 | } |
| 10218 | |
| 10219 | static void tg3_timer_start(struct tg3 *tp) |
| 10220 | { |
| 10221 | tp->asf_counter = tp->asf_multiplier; |
| 10222 | tp->timer_counter = tp->timer_multiplier; |
| 10223 | |
| 10224 | tp->timer.expires = jiffies + tp->timer_offset; |
| 10225 | add_timer(&tp->timer); |
| 10226 | } |
| 10227 | |
| 10228 | static void tg3_timer_stop(struct tg3 *tp) |
| 10229 | { |
| 10230 | del_timer_sync(&tp->timer); |
| 10231 | } |
| 10232 | |
| 10233 | /* Restart hardware after configuration changes, self-test, etc. |
| 10234 | * Invoked with tp->lock held. |
| 10235 | */ |
| 10236 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) |
| 10237 | __releases(tp->lock) |
| 10238 | __acquires(tp->lock) |
| 10239 | { |
| 10240 | int err; |
| 10241 | |
| 10242 | err = tg3_init_hw(tp, reset_phy); |
| 10243 | if (err) { |
| 10244 | netdev_err(tp->dev, |
| 10245 | "Failed to re-initialize device, aborting\n"); |
| 10246 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 10247 | tg3_full_unlock(tp); |
| 10248 | tg3_timer_stop(tp); |
| 10249 | tp->irq_sync = 0; |
| 10250 | tg3_napi_enable(tp); |
| 10251 | dev_close(tp->dev); |
| 10252 | tg3_full_lock(tp, 0); |
| 10253 | } |
| 10254 | return err; |
| 10255 | } |
| 10256 | |
| 10257 | static void tg3_reset_task(struct work_struct *work) |
| 10258 | { |
| 10259 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
| 10260 | int err; |
| 10261 | |
| 10262 | tg3_full_lock(tp, 0); |
| 10263 | |
| 10264 | if (!netif_running(tp->dev)) { |
| 10265 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 10266 | tg3_full_unlock(tp); |
| 10267 | return; |
| 10268 | } |
| 10269 | |
| 10270 | tg3_full_unlock(tp); |
| 10271 | |
| 10272 | tg3_phy_stop(tp); |
| 10273 | |
| 10274 | tg3_netif_stop(tp); |
| 10275 | |
| 10276 | tg3_full_lock(tp, 1); |
| 10277 | |
| 10278 | if (tg3_flag(tp, TX_RECOVERY_PENDING)) { |
| 10279 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 10280 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 10281 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
| 10282 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
| 10283 | } |
| 10284 | |
| 10285 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 10286 | err = tg3_init_hw(tp, 1); |
| 10287 | if (err) |
| 10288 | goto out; |
| 10289 | |
| 10290 | tg3_netif_start(tp); |
| 10291 | |
| 10292 | out: |
| 10293 | tg3_full_unlock(tp); |
| 10294 | |
| 10295 | if (!err) |
| 10296 | tg3_phy_start(tp); |
| 10297 | |
| 10298 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 10299 | } |
| 10300 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10301 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10302 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 10303 | irq_handler_t fn; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10304 | unsigned long flags; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10305 | char *name; |
| 10306 | struct tg3_napi *tnapi = &tp->napi[irq_num]; |
| 10307 | |
| 10308 | if (tp->irq_cnt == 1) |
| 10309 | name = tp->dev->name; |
| 10310 | else { |
| 10311 | name = &tnapi->irq_lbl[0]; |
| 10312 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); |
| 10313 | name[IFNAMSIZ-1] = 0; |
| 10314 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10315 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10316 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10317 | fn = tg3_msi; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10318 | if (tg3_flag(tp, 1SHOT_MSI)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10319 | fn = tg3_msi_1shot; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 10320 | flags = 0; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10321 | } else { |
| 10322 | fn = tg3_interrupt; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10323 | if (tg3_flag(tp, TAGGED_STATUS)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10324 | fn = tg3_interrupt_tagged; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 10325 | flags = IRQF_SHARED; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10326 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10327 | |
| 10328 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10329 | } |
| 10330 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10331 | static int tg3_test_interrupt(struct tg3 *tp) |
| 10332 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 10333 | struct tg3_napi *tnapi = &tp->napi[0]; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10334 | struct net_device *dev = tp->dev; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10335 | int err, i, intr_ok = 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10336 | u32 val; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10337 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 10338 | if (!netif_running(dev)) |
| 10339 | return -ENODEV; |
| 10340 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10341 | tg3_disable_ints(tp); |
| 10342 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10343 | free_irq(tnapi->irq_vec, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10344 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10345 | /* |
| 10346 | * Turn off MSI one shot mode. Otherwise this test has no |
| 10347 | * observable way to know whether the interrupt was delivered. |
| 10348 | */ |
Matt Carlson | 3aa1cdf | 2011-07-20 10:20:55 +0000 | [diff] [blame] | 10349 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10350 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
| 10351 | tw32(MSGINT_MODE, val); |
| 10352 | } |
| 10353 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10354 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
Davidlohr Bueso | f274fd9 | 2012-02-22 03:06:54 +0000 | [diff] [blame] | 10355 | IRQF_SHARED, dev->name, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10356 | if (err) |
| 10357 | return err; |
| 10358 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10359 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10360 | tg3_enable_ints(tp); |
| 10361 | |
| 10362 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10363 | tnapi->coal_now); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10364 | |
| 10365 | for (i = 0; i < 5; i++) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10366 | u32 int_mbox, misc_host_ctrl; |
| 10367 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10368 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10369 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 10370 | |
| 10371 | if ((int_mbox != 0) || |
| 10372 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { |
| 10373 | intr_ok = 1; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10374 | break; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10375 | } |
| 10376 | |
Matt Carlson | 3aa1cdf | 2011-07-20 10:20:55 +0000 | [diff] [blame] | 10377 | if (tg3_flag(tp, 57765_PLUS) && |
| 10378 | tnapi->hw_status->status_tag != tnapi->last_tag) |
| 10379 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 10380 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10381 | msleep(10); |
| 10382 | } |
| 10383 | |
| 10384 | tg3_disable_ints(tp); |
| 10385 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10386 | free_irq(tnapi->irq_vec, tnapi); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10387 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10388 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10389 | |
| 10390 | if (err) |
| 10391 | return err; |
| 10392 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10393 | if (intr_ok) { |
| 10394 | /* Reenable MSI one shot mode. */ |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 10395 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, 1SHOT_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10396 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
| 10397 | tw32(MSGINT_MODE, val); |
| 10398 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10399 | return 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10400 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10401 | |
| 10402 | return -EIO; |
| 10403 | } |
| 10404 | |
| 10405 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is |
| 10406 | * successfully restored |
| 10407 | */ |
| 10408 | static int tg3_test_msi(struct tg3 *tp) |
| 10409 | { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10410 | int err; |
| 10411 | u16 pci_cmd; |
| 10412 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10413 | if (!tg3_flag(tp, USING_MSI)) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10414 | return 0; |
| 10415 | |
| 10416 | /* Turn off SERR reporting in case MSI terminates with Master |
| 10417 | * Abort. |
| 10418 | */ |
| 10419 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 10420 | pci_write_config_word(tp->pdev, PCI_COMMAND, |
| 10421 | pci_cmd & ~PCI_COMMAND_SERR); |
| 10422 | |
| 10423 | err = tg3_test_interrupt(tp); |
| 10424 | |
| 10425 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 10426 | |
| 10427 | if (!err) |
| 10428 | return 0; |
| 10429 | |
| 10430 | /* other failures */ |
| 10431 | if (err != -EIO) |
| 10432 | return err; |
| 10433 | |
| 10434 | /* MSI test failed, go back to INTx mode */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 10435 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
| 10436 | "to INTx mode. Please report this failure to the PCI " |
| 10437 | "maintainer and include system chipset information\n"); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10438 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10439 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 10440 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10441 | pci_disable_msi(tp->pdev); |
| 10442 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10443 | tg3_flag_clear(tp, USING_MSI); |
Andre Detsch | dc8bf1b | 2010-04-26 07:27:07 +0000 | [diff] [blame] | 10444 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10445 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10446 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10447 | if (err) |
| 10448 | return err; |
| 10449 | |
| 10450 | /* Need to reset the chip because the MSI cycle may have terminated |
| 10451 | * with Master Abort. |
| 10452 | */ |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10453 | tg3_full_lock(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10454 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10455 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 10456 | err = tg3_init_hw(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10457 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10458 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10459 | |
| 10460 | if (err) |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10461 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10462 | |
| 10463 | return err; |
| 10464 | } |
| 10465 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 10466 | static int tg3_request_firmware(struct tg3 *tp) |
| 10467 | { |
| 10468 | const __be32 *fw_data; |
| 10469 | |
| 10470 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 10471 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
| 10472 | tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 10473 | return -ENOENT; |
| 10474 | } |
| 10475 | |
| 10476 | fw_data = (void *)tp->fw->data; |
| 10477 | |
| 10478 | /* Firmware blob starts with version numbers, followed by |
| 10479 | * start address and _full_ length including BSS sections |
| 10480 | * (which must be longer than the actual data, of course |
| 10481 | */ |
| 10482 | |
| 10483 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ |
| 10484 | if (tp->fw_len < (tp->fw->size - 12)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 10485 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
| 10486 | tp->fw_len, tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 10487 | release_firmware(tp->fw); |
| 10488 | tp->fw = NULL; |
| 10489 | return -EINVAL; |
| 10490 | } |
| 10491 | |
| 10492 | /* We no longer need firmware; we have it. */ |
| 10493 | tp->fw_needed = NULL; |
| 10494 | return 0; |
| 10495 | } |
| 10496 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10497 | static u32 tg3_irq_count(struct tg3 *tp) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10498 | { |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10499 | u32 irq_cnt = max(tp->rxq_cnt, tp->txq_cnt); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10500 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10501 | if (irq_cnt > 1) { |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 10502 | /* We want as many rx rings enabled as there are cpus. |
| 10503 | * In multiqueue MSI-X mode, the first MSI-X vector |
| 10504 | * only deals with link interrupts, etc, so we add |
| 10505 | * one to the number of vectors we are requesting. |
| 10506 | */ |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10507 | irq_cnt = min_t(unsigned, irq_cnt + 1, tp->irq_max); |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 10508 | } |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10509 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10510 | return irq_cnt; |
| 10511 | } |
| 10512 | |
| 10513 | static bool tg3_enable_msix(struct tg3 *tp) |
| 10514 | { |
| 10515 | int i, rc; |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 10516 | struct msix_entry msix_ent[TG3_IRQ_MAX_VECS]; |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10517 | |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 10518 | tp->txq_cnt = tp->txq_req; |
| 10519 | tp->rxq_cnt = tp->rxq_req; |
| 10520 | if (!tp->rxq_cnt) |
| 10521 | tp->rxq_cnt = netif_get_num_default_rss_queues(); |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10522 | if (tp->rxq_cnt > tp->rxq_max) |
| 10523 | tp->rxq_cnt = tp->rxq_max; |
Michael Chan | cf6d6ea | 2012-09-28 07:12:43 +0000 | [diff] [blame] | 10524 | |
| 10525 | /* Disable multiple TX rings by default. Simple round-robin hardware |
| 10526 | * scheduling of the TX rings can cause starvation of rings with |
| 10527 | * small packets when other rings have TSO or jumbo packets. |
| 10528 | */ |
| 10529 | if (!tp->txq_req) |
| 10530 | tp->txq_cnt = 1; |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10531 | |
| 10532 | tp->irq_cnt = tg3_irq_count(tp); |
| 10533 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10534 | for (i = 0; i < tp->irq_max; i++) { |
| 10535 | msix_ent[i].entry = i; |
| 10536 | msix_ent[i].vector = 0; |
| 10537 | } |
| 10538 | |
| 10539 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 10540 | if (rc < 0) { |
| 10541 | return false; |
| 10542 | } else if (rc != 0) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10543 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
| 10544 | return false; |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 10545 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
| 10546 | tp->irq_cnt, rc); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10547 | tp->irq_cnt = rc; |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 10548 | tp->rxq_cnt = max(rc - 1, 1); |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10549 | if (tp->txq_cnt) |
| 10550 | tp->txq_cnt = min(tp->rxq_cnt, tp->txq_max); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10551 | } |
| 10552 | |
| 10553 | for (i = 0; i < tp->irq_max; i++) |
| 10554 | tp->napi[i].irq_vec = msix_ent[i].vector; |
| 10555 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 10556 | if (netif_set_real_num_rx_queues(tp->dev, tp->rxq_cnt)) { |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 10557 | pci_disable_msix(tp->pdev); |
| 10558 | return false; |
| 10559 | } |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 10560 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10561 | if (tp->irq_cnt == 1) |
| 10562 | return true; |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 10563 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 10564 | tg3_flag_set(tp, ENABLE_RSS); |
| 10565 | |
| 10566 | if (tp->txq_cnt > 1) |
| 10567 | tg3_flag_set(tp, ENABLE_TSS); |
| 10568 | |
| 10569 | netif_set_real_num_tx_queues(tp->dev, tp->txq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 10570 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10571 | return true; |
| 10572 | } |
| 10573 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10574 | static void tg3_ints_init(struct tg3 *tp) |
| 10575 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10576 | if ((tg3_flag(tp, SUPPORT_MSI) || tg3_flag(tp, SUPPORT_MSIX)) && |
| 10577 | !tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10578 | /* All MSI supporting chips should support tagged |
| 10579 | * status. Assert that this is the case. |
| 10580 | */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 10581 | netdev_warn(tp->dev, |
| 10582 | "MSI without TAGGED_STATUS? Not using MSI\n"); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10583 | goto defcfg; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10584 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10585 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10586 | if (tg3_flag(tp, SUPPORT_MSIX) && tg3_enable_msix(tp)) |
| 10587 | tg3_flag_set(tp, USING_MSIX); |
| 10588 | else if (tg3_flag(tp, SUPPORT_MSI) && pci_enable_msi(tp->pdev) == 0) |
| 10589 | tg3_flag_set(tp, USING_MSI); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10590 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10591 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10592 | u32 msi_mode = tr32(MSGINT_MODE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10593 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 10594 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 10595 | if (!tg3_flag(tp, 1SHOT_MSI)) |
| 10596 | msi_mode |= MSGINT_MODE_ONE_SHOT_DISABLE; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10597 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
| 10598 | } |
| 10599 | defcfg: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10600 | if (!tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10601 | tp->irq_cnt = 1; |
| 10602 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 10603 | } |
| 10604 | |
| 10605 | if (tp->irq_cnt == 1) { |
| 10606 | tp->txq_cnt = 1; |
| 10607 | tp->rxq_cnt = 1; |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 10608 | netif_set_real_num_tx_queues(tp->dev, 1); |
Matt Carlson | 8540788 | 2010-10-06 13:40:58 -0700 | [diff] [blame] | 10609 | netif_set_real_num_rx_queues(tp->dev, 1); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10610 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10611 | } |
| 10612 | |
| 10613 | static void tg3_ints_fini(struct tg3 *tp) |
| 10614 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10615 | if (tg3_flag(tp, USING_MSIX)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10616 | pci_disable_msix(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10617 | else if (tg3_flag(tp, USING_MSI)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10618 | pci_disable_msi(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10619 | tg3_flag_clear(tp, USING_MSI); |
| 10620 | tg3_flag_clear(tp, USING_MSIX); |
| 10621 | tg3_flag_clear(tp, ENABLE_RSS); |
| 10622 | tg3_flag_clear(tp, ENABLE_TSS); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10623 | } |
| 10624 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 10625 | static int tg3_start(struct tg3 *tp, bool reset_phy, bool test_irq, |
| 10626 | bool init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10627 | { |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10628 | struct net_device *dev = tp->dev; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10629 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10630 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10631 | /* |
| 10632 | * Setup interrupts first so we know how |
| 10633 | * many NAPI resources to allocate |
| 10634 | */ |
| 10635 | tg3_ints_init(tp); |
| 10636 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 10637 | tg3_rss_check_indir_tbl(tp); |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 10638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10639 | /* The placement of this call is tied |
| 10640 | * to the setup and use of Host TX descriptors. |
| 10641 | */ |
| 10642 | err = tg3_alloc_consistent(tp); |
| 10643 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10644 | goto err_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10645 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10646 | tg3_napi_init(tp); |
| 10647 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 10648 | tg3_napi_enable(tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 10649 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10650 | for (i = 0; i < tp->irq_cnt; i++) { |
| 10651 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10652 | err = tg3_request_irq(tp, i); |
| 10653 | if (err) { |
Matt Carlson | 5bc0918 | 2011-11-04 09:15:01 +0000 | [diff] [blame] | 10654 | for (i--; i >= 0; i--) { |
| 10655 | tnapi = &tp->napi[i]; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10656 | free_irq(tnapi->irq_vec, tnapi); |
Matt Carlson | 5bc0918 | 2011-11-04 09:15:01 +0000 | [diff] [blame] | 10657 | } |
| 10658 | goto err_out2; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10659 | } |
| 10660 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10661 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10662 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10663 | |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10664 | err = tg3_init_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10665 | if (err) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10666 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10667 | tg3_free_rings(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10668 | } |
| 10669 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10670 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10671 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10672 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10673 | goto err_out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10674 | |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10675 | if (test_irq && tg3_flag(tp, USING_MSI)) { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10676 | err = tg3_test_msi(tp); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10677 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10678 | if (err) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10679 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10680 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10681 | tg3_free_rings(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10682 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10683 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10684 | goto err_out2; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10685 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10686 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10687 | if (!tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10688 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10689 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10690 | tw32(PCIE_TRANSACTION_CFG, |
| 10691 | val | PCIE_TRANS_CFG_1SHOT_MSI); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10692 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10693 | } |
| 10694 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10695 | tg3_phy_start(tp); |
| 10696 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 10697 | tg3_hwmon_open(tp); |
| 10698 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10699 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10700 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10701 | tg3_timer_start(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10702 | tg3_flag_set(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10703 | tg3_enable_ints(tp); |
| 10704 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 10705 | if (init) |
| 10706 | tg3_ptp_init(tp); |
| 10707 | else |
| 10708 | tg3_ptp_resume(tp); |
| 10709 | |
| 10710 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10711 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10712 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 10713 | netif_tx_start_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10714 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 10715 | /* |
| 10716 | * Reset loopback feature if it was turned on while the device was down |
| 10717 | * make sure that it's installed properly now. |
| 10718 | */ |
| 10719 | if (dev->features & NETIF_F_LOOPBACK) |
| 10720 | tg3_set_loopback(dev, dev->features); |
| 10721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10722 | return 0; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10723 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10724 | err_out3: |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10725 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 10726 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10727 | free_irq(tnapi->irq_vec, tnapi); |
| 10728 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10729 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10730 | err_out2: |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 10731 | tg3_napi_disable(tp); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10732 | tg3_napi_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10733 | tg3_free_consistent(tp); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 10734 | |
| 10735 | err_out1: |
| 10736 | tg3_ints_fini(tp); |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10737 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10738 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10739 | } |
| 10740 | |
Michael Chan | 6513859 | 2012-09-28 07:12:41 +0000 | [diff] [blame] | 10741 | static void tg3_stop(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10742 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10743 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10744 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 10745 | tg3_reset_task_cancel(tp); |
Nithin Nayak Sujir | bd473da | 2012-11-05 14:26:30 +0000 | [diff] [blame] | 10746 | tg3_netif_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10747 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10748 | tg3_timer_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10749 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 10750 | tg3_hwmon_close(tp); |
| 10751 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 10752 | tg3_phy_stop(tp); |
| 10753 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10754 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10755 | |
| 10756 | tg3_disable_ints(tp); |
| 10757 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10758 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10759 | tg3_free_rings(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10760 | tg3_flag_clear(tp, INIT_COMPLETE); |
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 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10764 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 10765 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10766 | free_irq(tnapi->irq_vec, tnapi); |
| 10767 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 10768 | |
| 10769 | tg3_ints_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10770 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 10771 | tg3_napi_fini(tp); |
| 10772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10773 | tg3_free_consistent(tp); |
Michael Chan | 6513859 | 2012-09-28 07:12:41 +0000 | [diff] [blame] | 10774 | } |
| 10775 | |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10776 | static int tg3_open(struct net_device *dev) |
| 10777 | { |
| 10778 | struct tg3 *tp = netdev_priv(dev); |
| 10779 | int err; |
| 10780 | |
| 10781 | if (tp->fw_needed) { |
| 10782 | err = tg3_request_firmware(tp); |
| 10783 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 10784 | if (err) |
| 10785 | return err; |
| 10786 | } else if (err) { |
| 10787 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
| 10788 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 10789 | } else if (!tg3_flag(tp, TSO_CAPABLE)) { |
| 10790 | netdev_notice(tp->dev, "TSO capability restored\n"); |
| 10791 | tg3_flag_set(tp, TSO_CAPABLE); |
| 10792 | } |
| 10793 | } |
| 10794 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 10795 | tg3_carrier_off(tp); |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10796 | |
| 10797 | err = tg3_power_up(tp); |
| 10798 | if (err) |
| 10799 | return err; |
| 10800 | |
| 10801 | tg3_full_lock(tp, 0); |
| 10802 | |
| 10803 | tg3_disable_ints(tp); |
| 10804 | tg3_flag_clear(tp, INIT_COMPLETE); |
| 10805 | |
| 10806 | tg3_full_unlock(tp); |
| 10807 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 10808 | err = tg3_start(tp, true, true, true); |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 10809 | if (err) { |
| 10810 | tg3_frob_aux_power(tp, false); |
| 10811 | pci_set_power_state(tp->pdev, PCI_D3hot); |
| 10812 | } |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 10813 | |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 10814 | if (tg3_flag(tp, PTP_CAPABLE)) { |
| 10815 | tp->ptp_clock = ptp_clock_register(&tp->ptp_info, |
| 10816 | &tp->pdev->dev); |
| 10817 | if (IS_ERR(tp->ptp_clock)) |
| 10818 | tp->ptp_clock = NULL; |
| 10819 | } |
| 10820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10821 | return err; |
| 10822 | } |
| 10823 | |
| 10824 | static int tg3_close(struct net_device *dev) |
| 10825 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10826 | struct tg3 *tp = netdev_priv(dev); |
| 10827 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 10828 | tg3_ptp_fini(tp); |
| 10829 | |
Michael Chan | 6513859 | 2012-09-28 07:12:41 +0000 | [diff] [blame] | 10830 | tg3_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10831 | |
| 10832 | /* Clear stats across close / open calls */ |
| 10833 | memset(&tp->net_stats_prev, 0, sizeof(tp->net_stats_prev)); |
| 10834 | memset(&tp->estats_prev, 0, sizeof(tp->estats_prev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10835 | |
| 10836 | tg3_power_down(tp); |
| 10837 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 10838 | tg3_carrier_off(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10839 | |
| 10840 | return 0; |
| 10841 | } |
| 10842 | |
| 10843 | static inline u64 get_stat64(tg3_stat64_t *val) |
| 10844 | { |
| 10845 | return ((u64)val->high << 32) | ((u64)val->low); |
| 10846 | } |
| 10847 | |
| 10848 | static u64 tg3_calc_crc_errors(struct tg3 *tp) |
| 10849 | { |
| 10850 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10851 | |
| 10852 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 10853 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 10854 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 10855 | u32 val; |
| 10856 | |
| 10857 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
| 10858 | tg3_writephy(tp, MII_TG3_TEST1, |
| 10859 | val | MII_TG3_TEST1_CRC_EN); |
| 10860 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
| 10861 | } else |
| 10862 | val = 0; |
| 10863 | |
| 10864 | tp->phy_crc_errors += val; |
| 10865 | |
| 10866 | return tp->phy_crc_errors; |
| 10867 | } |
| 10868 | |
| 10869 | return get_stat64(&hw_stats->rx_fcs_errors); |
| 10870 | } |
| 10871 | |
| 10872 | #define ESTAT_ADD(member) \ |
| 10873 | estats->member = old_estats->member + \ |
| 10874 | get_stat64(&hw_stats->member) |
| 10875 | |
| 10876 | static void tg3_get_estats(struct tg3 *tp, struct tg3_ethtool_stats *estats) |
| 10877 | { |
| 10878 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
| 10879 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10880 | |
| 10881 | ESTAT_ADD(rx_octets); |
| 10882 | ESTAT_ADD(rx_fragments); |
| 10883 | ESTAT_ADD(rx_ucast_packets); |
| 10884 | ESTAT_ADD(rx_mcast_packets); |
| 10885 | ESTAT_ADD(rx_bcast_packets); |
| 10886 | ESTAT_ADD(rx_fcs_errors); |
| 10887 | ESTAT_ADD(rx_align_errors); |
| 10888 | ESTAT_ADD(rx_xon_pause_rcvd); |
| 10889 | ESTAT_ADD(rx_xoff_pause_rcvd); |
| 10890 | ESTAT_ADD(rx_mac_ctrl_rcvd); |
| 10891 | ESTAT_ADD(rx_xoff_entered); |
| 10892 | ESTAT_ADD(rx_frame_too_long_errors); |
| 10893 | ESTAT_ADD(rx_jabbers); |
| 10894 | ESTAT_ADD(rx_undersize_packets); |
| 10895 | ESTAT_ADD(rx_in_length_errors); |
| 10896 | ESTAT_ADD(rx_out_length_errors); |
| 10897 | ESTAT_ADD(rx_64_or_less_octet_packets); |
| 10898 | ESTAT_ADD(rx_65_to_127_octet_packets); |
| 10899 | ESTAT_ADD(rx_128_to_255_octet_packets); |
| 10900 | ESTAT_ADD(rx_256_to_511_octet_packets); |
| 10901 | ESTAT_ADD(rx_512_to_1023_octet_packets); |
| 10902 | ESTAT_ADD(rx_1024_to_1522_octet_packets); |
| 10903 | ESTAT_ADD(rx_1523_to_2047_octet_packets); |
| 10904 | ESTAT_ADD(rx_2048_to_4095_octet_packets); |
| 10905 | ESTAT_ADD(rx_4096_to_8191_octet_packets); |
| 10906 | ESTAT_ADD(rx_8192_to_9022_octet_packets); |
| 10907 | |
| 10908 | ESTAT_ADD(tx_octets); |
| 10909 | ESTAT_ADD(tx_collisions); |
| 10910 | ESTAT_ADD(tx_xon_sent); |
| 10911 | ESTAT_ADD(tx_xoff_sent); |
| 10912 | ESTAT_ADD(tx_flow_control); |
| 10913 | ESTAT_ADD(tx_mac_errors); |
| 10914 | ESTAT_ADD(tx_single_collisions); |
| 10915 | ESTAT_ADD(tx_mult_collisions); |
| 10916 | ESTAT_ADD(tx_deferred); |
| 10917 | ESTAT_ADD(tx_excessive_collisions); |
| 10918 | ESTAT_ADD(tx_late_collisions); |
| 10919 | ESTAT_ADD(tx_collide_2times); |
| 10920 | ESTAT_ADD(tx_collide_3times); |
| 10921 | ESTAT_ADD(tx_collide_4times); |
| 10922 | ESTAT_ADD(tx_collide_5times); |
| 10923 | ESTAT_ADD(tx_collide_6times); |
| 10924 | ESTAT_ADD(tx_collide_7times); |
| 10925 | ESTAT_ADD(tx_collide_8times); |
| 10926 | ESTAT_ADD(tx_collide_9times); |
| 10927 | ESTAT_ADD(tx_collide_10times); |
| 10928 | ESTAT_ADD(tx_collide_11times); |
| 10929 | ESTAT_ADD(tx_collide_12times); |
| 10930 | ESTAT_ADD(tx_collide_13times); |
| 10931 | ESTAT_ADD(tx_collide_14times); |
| 10932 | ESTAT_ADD(tx_collide_15times); |
| 10933 | ESTAT_ADD(tx_ucast_packets); |
| 10934 | ESTAT_ADD(tx_mcast_packets); |
| 10935 | ESTAT_ADD(tx_bcast_packets); |
| 10936 | ESTAT_ADD(tx_carrier_sense_errors); |
| 10937 | ESTAT_ADD(tx_discards); |
| 10938 | ESTAT_ADD(tx_errors); |
| 10939 | |
| 10940 | ESTAT_ADD(dma_writeq_full); |
| 10941 | ESTAT_ADD(dma_write_prioq_full); |
| 10942 | ESTAT_ADD(rxbds_empty); |
| 10943 | ESTAT_ADD(rx_discards); |
| 10944 | ESTAT_ADD(rx_errors); |
| 10945 | ESTAT_ADD(rx_threshold_hit); |
| 10946 | |
| 10947 | ESTAT_ADD(dma_readq_full); |
| 10948 | ESTAT_ADD(dma_read_prioq_full); |
| 10949 | ESTAT_ADD(tx_comp_queue_full); |
| 10950 | |
| 10951 | ESTAT_ADD(ring_set_send_prod_index); |
| 10952 | ESTAT_ADD(ring_status_update); |
| 10953 | ESTAT_ADD(nic_irqs); |
| 10954 | ESTAT_ADD(nic_avoided_irqs); |
| 10955 | ESTAT_ADD(nic_tx_threshold_hit); |
| 10956 | |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 10957 | ESTAT_ADD(mbuf_lwm_thresh_hit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10958 | } |
| 10959 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 10960 | 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] | 10961 | { |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 10962 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10963 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 10964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10965 | stats->rx_packets = old_stats->rx_packets + |
| 10966 | get_stat64(&hw_stats->rx_ucast_packets) + |
| 10967 | get_stat64(&hw_stats->rx_mcast_packets) + |
| 10968 | get_stat64(&hw_stats->rx_bcast_packets); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10970 | stats->tx_packets = old_stats->tx_packets + |
| 10971 | get_stat64(&hw_stats->tx_ucast_packets) + |
| 10972 | get_stat64(&hw_stats->tx_mcast_packets) + |
| 10973 | get_stat64(&hw_stats->tx_bcast_packets); |
| 10974 | |
| 10975 | stats->rx_bytes = old_stats->rx_bytes + |
| 10976 | get_stat64(&hw_stats->rx_octets); |
| 10977 | stats->tx_bytes = old_stats->tx_bytes + |
| 10978 | get_stat64(&hw_stats->tx_octets); |
| 10979 | |
| 10980 | stats->rx_errors = old_stats->rx_errors + |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 10981 | get_stat64(&hw_stats->rx_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10982 | stats->tx_errors = old_stats->tx_errors + |
| 10983 | get_stat64(&hw_stats->tx_errors) + |
| 10984 | get_stat64(&hw_stats->tx_mac_errors) + |
| 10985 | get_stat64(&hw_stats->tx_carrier_sense_errors) + |
| 10986 | get_stat64(&hw_stats->tx_discards); |
| 10987 | |
| 10988 | stats->multicast = old_stats->multicast + |
| 10989 | get_stat64(&hw_stats->rx_mcast_packets); |
| 10990 | stats->collisions = old_stats->collisions + |
| 10991 | get_stat64(&hw_stats->tx_collisions); |
| 10992 | |
| 10993 | stats->rx_length_errors = old_stats->rx_length_errors + |
| 10994 | get_stat64(&hw_stats->rx_frame_too_long_errors) + |
| 10995 | get_stat64(&hw_stats->rx_undersize_packets); |
| 10996 | |
| 10997 | stats->rx_over_errors = old_stats->rx_over_errors + |
| 10998 | get_stat64(&hw_stats->rxbds_empty); |
| 10999 | stats->rx_frame_errors = old_stats->rx_frame_errors + |
| 11000 | get_stat64(&hw_stats->rx_align_errors); |
| 11001 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + |
| 11002 | get_stat64(&hw_stats->tx_discards); |
| 11003 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + |
| 11004 | get_stat64(&hw_stats->tx_carrier_sense_errors); |
| 11005 | |
| 11006 | stats->rx_crc_errors = old_stats->rx_crc_errors + |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 11007 | tg3_calc_crc_errors(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11008 | |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 11009 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
| 11010 | get_stat64(&hw_stats->rx_discards); |
| 11011 | |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 11012 | stats->rx_dropped = tp->rx_dropped; |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 11013 | stats->tx_dropped = tp->tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11014 | } |
| 11015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11016 | static int tg3_get_regs_len(struct net_device *dev) |
| 11017 | { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 11018 | return TG3_REG_BLK_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11019 | } |
| 11020 | |
| 11021 | static void tg3_get_regs(struct net_device *dev, |
| 11022 | struct ethtool_regs *regs, void *_p) |
| 11023 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11024 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11025 | |
| 11026 | regs->version = 0; |
| 11027 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 11028 | memset(_p, 0, TG3_REG_BLK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11029 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11030 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11031 | return; |
| 11032 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11033 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11034 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 11035 | tg3_dump_legacy_regs(tp, (u32 *)_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11036 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11037 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11038 | } |
| 11039 | |
| 11040 | static int tg3_get_eeprom_len(struct net_device *dev) |
| 11041 | { |
| 11042 | struct tg3 *tp = netdev_priv(dev); |
| 11043 | |
| 11044 | return tp->nvram_size; |
| 11045 | } |
| 11046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11047 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 11048 | { |
| 11049 | struct tg3 *tp = netdev_priv(dev); |
| 11050 | int ret; |
| 11051 | u8 *pd; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11052 | u32 i, offset, len, b_offset, b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11053 | __be32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11054 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11055 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11056 | return -EINVAL; |
| 11057 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11058 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11059 | return -EAGAIN; |
| 11060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11061 | offset = eeprom->offset; |
| 11062 | len = eeprom->len; |
| 11063 | eeprom->len = 0; |
| 11064 | |
| 11065 | eeprom->magic = TG3_EEPROM_MAGIC; |
| 11066 | |
| 11067 | if (offset & 3) { |
| 11068 | /* adjustments to start on required 4 byte boundary */ |
| 11069 | b_offset = offset & 3; |
| 11070 | b_count = 4 - b_offset; |
| 11071 | if (b_count > len) { |
| 11072 | /* i.e. offset=1 len=2 */ |
| 11073 | b_count = len; |
| 11074 | } |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11075 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11076 | if (ret) |
| 11077 | return ret; |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 11078 | memcpy(data, ((char *)&val) + b_offset, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11079 | len -= b_count; |
| 11080 | offset += b_count; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 11081 | eeprom->len += b_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11082 | } |
| 11083 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11084 | /* read bytes up to the last 4 byte boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11085 | pd = &data[eeprom->len]; |
| 11086 | for (i = 0; i < (len - (len & 3)); i += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11087 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11088 | if (ret) { |
| 11089 | eeprom->len += i; |
| 11090 | return ret; |
| 11091 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11092 | memcpy(pd + i, &val, 4); |
| 11093 | } |
| 11094 | eeprom->len += i; |
| 11095 | |
| 11096 | if (len & 3) { |
| 11097 | /* read last bytes not ending on 4 byte boundary */ |
| 11098 | pd = &data[eeprom->len]; |
| 11099 | b_count = len & 3; |
| 11100 | b_offset = offset + len - b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11101 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11102 | if (ret) |
| 11103 | return ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11104 | memcpy(pd, &val, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11105 | eeprom->len += b_count; |
| 11106 | } |
| 11107 | return 0; |
| 11108 | } |
| 11109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11110 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 11111 | { |
| 11112 | struct tg3 *tp = netdev_priv(dev); |
| 11113 | int ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11114 | u32 offset, len, b_offset, odd_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11115 | u8 *buf; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11116 | __be32 start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11117 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11118 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11119 | return -EAGAIN; |
| 11120 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11121 | if (tg3_flag(tp, NO_NVRAM) || |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11122 | eeprom->magic != TG3_EEPROM_MAGIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11123 | return -EINVAL; |
| 11124 | |
| 11125 | offset = eeprom->offset; |
| 11126 | len = eeprom->len; |
| 11127 | |
| 11128 | if ((b_offset = (offset & 3))) { |
| 11129 | /* adjustments to start on required 4 byte boundary */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11130 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11131 | if (ret) |
| 11132 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11133 | len += b_offset; |
| 11134 | offset &= ~3; |
Michael Chan | 1c8594b4 | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 11135 | if (len < 4) |
| 11136 | len = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11137 | } |
| 11138 | |
| 11139 | odd_len = 0; |
Michael Chan | 1c8594b4 | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 11140 | if (len & 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11141 | /* adjustments to end on required 4 byte boundary */ |
| 11142 | odd_len = 1; |
| 11143 | len = (len + 3) & ~3; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11144 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11145 | if (ret) |
| 11146 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11147 | } |
| 11148 | |
| 11149 | buf = data; |
| 11150 | if (b_offset || odd_len) { |
| 11151 | buf = kmalloc(len, GFP_KERNEL); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 11152 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11153 | return -ENOMEM; |
| 11154 | if (b_offset) |
| 11155 | memcpy(buf, &start, 4); |
| 11156 | if (odd_len) |
| 11157 | memcpy(buf+len-4, &end, 4); |
| 11158 | memcpy(buf + b_offset, data, eeprom->len); |
| 11159 | } |
| 11160 | |
| 11161 | ret = tg3_nvram_write_block(tp, offset, len, buf); |
| 11162 | |
| 11163 | if (buf != data) |
| 11164 | kfree(buf); |
| 11165 | |
| 11166 | return ret; |
| 11167 | } |
| 11168 | |
| 11169 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 11170 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11171 | struct tg3 *tp = netdev_priv(dev); |
| 11172 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11173 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11174 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11175 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11176 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11177 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 11178 | return phy_ethtool_gset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11179 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11181 | cmd->supported = (SUPPORTED_Autoneg); |
| 11182 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11183 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11184 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
| 11185 | SUPPORTED_1000baseT_Full); |
| 11186 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11187 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11188 | cmd->supported |= (SUPPORTED_100baseT_Half | |
| 11189 | SUPPORTED_100baseT_Full | |
| 11190 | SUPPORTED_10baseT_Half | |
| 11191 | SUPPORTED_10baseT_Full | |
Matt Carlson | 3bebab5 | 2007-11-12 21:22:40 -0800 | [diff] [blame] | 11192 | SUPPORTED_TP); |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 11193 | cmd->port = PORT_TP; |
| 11194 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11195 | cmd->supported |= SUPPORTED_FIBRE; |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 11196 | cmd->port = PORT_FIBRE; |
| 11197 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11199 | cmd->advertising = tp->link_config.advertising; |
Matt Carlson | 5bb0977 | 2011-06-13 13:39:00 +0000 | [diff] [blame] | 11200 | if (tg3_flag(tp, PAUSE_AUTONEG)) { |
| 11201 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) { |
| 11202 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 11203 | cmd->advertising |= ADVERTISED_Pause; |
| 11204 | } else { |
| 11205 | cmd->advertising |= ADVERTISED_Pause | |
| 11206 | ADVERTISED_Asym_Pause; |
| 11207 | } |
| 11208 | } else if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 11209 | cmd->advertising |= ADVERTISED_Asym_Pause; |
| 11210 | } |
| 11211 | } |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 11212 | if (netif_running(dev) && tp->link_up) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 11213 | ethtool_cmd_speed_set(cmd, tp->link_config.active_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11214 | cmd->duplex = tp->link_config.active_duplex; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 11215 | cmd->lp_advertising = tp->link_config.rmt_adv; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 11216 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 11217 | if (tp->phy_flags & TG3_PHYFLG_MDIX_STATE) |
| 11218 | cmd->eth_tp_mdix = ETH_TP_MDI_X; |
| 11219 | else |
| 11220 | cmd->eth_tp_mdix = ETH_TP_MDI; |
| 11221 | } |
Matt Carlson | 64c2218 | 2010-10-14 10:37:44 +0000 | [diff] [blame] | 11222 | } else { |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 11223 | ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN); |
| 11224 | cmd->duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 11225 | cmd->eth_tp_mdix = ETH_TP_MDI_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11226 | } |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 11227 | cmd->phy_address = tp->phy_addr; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11228 | cmd->transceiver = XCVR_INTERNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11229 | cmd->autoneg = tp->link_config.autoneg; |
| 11230 | cmd->maxtxpkt = 0; |
| 11231 | cmd->maxrxpkt = 0; |
| 11232 | return 0; |
| 11233 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11235 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 11236 | { |
| 11237 | struct tg3 *tp = netdev_priv(dev); |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11238 | u32 speed = ethtool_cmd_speed(cmd); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11239 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11240 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11241 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11242 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11243 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11244 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 11245 | return phy_ethtool_sset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11246 | } |
| 11247 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11248 | if (cmd->autoneg != AUTONEG_ENABLE && |
| 11249 | cmd->autoneg != AUTONEG_DISABLE) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 11250 | return -EINVAL; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11251 | |
| 11252 | if (cmd->autoneg == AUTONEG_DISABLE && |
| 11253 | cmd->duplex != DUPLEX_FULL && |
| 11254 | cmd->duplex != DUPLEX_HALF) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 11255 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11256 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11257 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 11258 | u32 mask = ADVERTISED_Autoneg | |
| 11259 | ADVERTISED_Pause | |
| 11260 | ADVERTISED_Asym_Pause; |
| 11261 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11262 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11263 | mask |= ADVERTISED_1000baseT_Half | |
| 11264 | ADVERTISED_1000baseT_Full; |
| 11265 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11266 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11267 | mask |= ADVERTISED_100baseT_Half | |
| 11268 | ADVERTISED_100baseT_Full | |
| 11269 | ADVERTISED_10baseT_Half | |
| 11270 | ADVERTISED_10baseT_Full | |
| 11271 | ADVERTISED_TP; |
| 11272 | else |
| 11273 | mask |= ADVERTISED_FIBRE; |
| 11274 | |
| 11275 | if (cmd->advertising & ~mask) |
| 11276 | return -EINVAL; |
| 11277 | |
| 11278 | mask &= (ADVERTISED_1000baseT_Half | |
| 11279 | ADVERTISED_1000baseT_Full | |
| 11280 | ADVERTISED_100baseT_Half | |
| 11281 | ADVERTISED_100baseT_Full | |
| 11282 | ADVERTISED_10baseT_Half | |
| 11283 | ADVERTISED_10baseT_Full); |
| 11284 | |
| 11285 | cmd->advertising &= mask; |
| 11286 | } else { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11287 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11288 | if (speed != SPEED_1000) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11289 | return -EINVAL; |
| 11290 | |
| 11291 | if (cmd->duplex != DUPLEX_FULL) |
| 11292 | return -EINVAL; |
| 11293 | } else { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11294 | if (speed != SPEED_100 && |
| 11295 | speed != SPEED_10) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11296 | return -EINVAL; |
| 11297 | } |
| 11298 | } |
| 11299 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11300 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11301 | |
| 11302 | tp->link_config.autoneg = cmd->autoneg; |
| 11303 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Andy Gospodarek | 405d8e5 | 2007-10-08 01:08:47 -0700 | [diff] [blame] | 11304 | tp->link_config.advertising = (cmd->advertising | |
| 11305 | ADVERTISED_Autoneg); |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 11306 | tp->link_config.speed = SPEED_UNKNOWN; |
| 11307 | tp->link_config.duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11308 | } else { |
| 11309 | tp->link_config.advertising = 0; |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11310 | tp->link_config.speed = speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11311 | tp->link_config.duplex = cmd->duplex; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11312 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11314 | if (netif_running(dev)) |
| 11315 | tg3_setup_phy(tp, 1); |
| 11316 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11317 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11319 | return 0; |
| 11320 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11322 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 11323 | { |
| 11324 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11325 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 11326 | strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); |
| 11327 | strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); |
| 11328 | strlcpy(info->fw_version, tp->fw_ver, sizeof(info->fw_version)); |
| 11329 | strlcpy(info->bus_info, pci_name(tp->pdev), sizeof(info->bus_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11330 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11332 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 11333 | { |
| 11334 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11335 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11336 | if (tg3_flag(tp, WOL_CAP) && device_can_wakeup(&tp->pdev->dev)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 11337 | wol->supported = WAKE_MAGIC; |
| 11338 | else |
| 11339 | wol->supported = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11340 | wol->wolopts = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11341 | if (tg3_flag(tp, WOL_ENABLE) && device_can_wakeup(&tp->pdev->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11342 | wol->wolopts = WAKE_MAGIC; |
| 11343 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 11344 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11346 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 11347 | { |
| 11348 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 11349 | struct device *dp = &tp->pdev->dev; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11351 | if (wol->wolopts & ~WAKE_MAGIC) |
| 11352 | return -EINVAL; |
| 11353 | if ((wol->wolopts & WAKE_MAGIC) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11354 | !(tg3_flag(tp, WOL_CAP) && device_can_wakeup(dp))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11355 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11356 | |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 11357 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
| 11358 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11359 | spin_lock_bh(&tp->lock); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 11360 | if (device_may_wakeup(dp)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11361 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 11362 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11363 | tg3_flag_clear(tp, WOL_ENABLE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11364 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11366 | return 0; |
| 11367 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11369 | static u32 tg3_get_msglevel(struct net_device *dev) |
| 11370 | { |
| 11371 | struct tg3 *tp = netdev_priv(dev); |
| 11372 | return tp->msg_enable; |
| 11373 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11375 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
| 11376 | { |
| 11377 | struct tg3 *tp = netdev_priv(dev); |
| 11378 | tp->msg_enable = value; |
| 11379 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11381 | static int tg3_nway_reset(struct net_device *dev) |
| 11382 | { |
| 11383 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11384 | int r; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11386 | if (!netif_running(dev)) |
| 11387 | return -EAGAIN; |
| 11388 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11389 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 11390 | return -EINVAL; |
| 11391 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11392 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11393 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11394 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11395 | 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] | 11396 | } else { |
| 11397 | u32 bmcr; |
| 11398 | |
| 11399 | spin_lock_bh(&tp->lock); |
| 11400 | r = -EINVAL; |
| 11401 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 11402 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && |
| 11403 | ((bmcr & BMCR_ANENABLE) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11404 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11405 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
| 11406 | BMCR_ANENABLE); |
| 11407 | r = 0; |
| 11408 | } |
| 11409 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11410 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11412 | return r; |
| 11413 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11415 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 11416 | { |
| 11417 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11418 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 11419 | ering->rx_max_pending = tp->rx_std_ring_mask; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11420 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 11421 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 11422 | else |
| 11423 | ering->rx_jumbo_max_pending = 0; |
| 11424 | |
| 11425 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11426 | |
| 11427 | ering->rx_pending = tp->rx_pending; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11428 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 11429 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
| 11430 | else |
| 11431 | ering->rx_jumbo_pending = 0; |
| 11432 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11433 | ering->tx_pending = tp->napi[0].tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11434 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11436 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 11437 | { |
| 11438 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 11439 | int i, irq_sync = 0, err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11440 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 11441 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
| 11442 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 11443 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
| 11444 | (ering->tx_pending <= MAX_SKB_FRAGS) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11445 | (tg3_flag(tp, TSO_BUG) && |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 11446 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11447 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11448 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11449 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11450 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11451 | tg3_netif_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11452 | irq_sync = 1; |
| 11453 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11454 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11455 | tg3_full_lock(tp, irq_sync); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11457 | tp->rx_pending = ering->rx_pending; |
| 11458 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11459 | if (tg3_flag(tp, MAX_RXPEND_64) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11460 | tp->rx_pending > 63) |
| 11461 | tp->rx_pending = 63; |
| 11462 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 11463 | |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 11464 | for (i = 0; i < tp->irq_max; i++) |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 11465 | tp->napi[i].tx_pending = ering->tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11466 | |
| 11467 | if (netif_running(dev)) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 11468 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11469 | err = tg3_restart_hw(tp, 1); |
| 11470 | if (!err) |
| 11471 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11472 | } |
| 11473 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11474 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11475 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11476 | if (irq_sync && !err) |
| 11477 | tg3_phy_start(tp); |
| 11478 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11479 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11480 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11482 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 11483 | { |
| 11484 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11485 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11486 | epause->autoneg = !!tg3_flag(tp, PAUSE_AUTONEG); |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 11487 | |
Matt Carlson | 4a2db50 | 2011-12-08 14:40:17 +0000 | [diff] [blame] | 11488 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 11489 | epause->rx_pause = 1; |
| 11490 | else |
| 11491 | epause->rx_pause = 0; |
| 11492 | |
Matt Carlson | 4a2db50 | 2011-12-08 14:40:17 +0000 | [diff] [blame] | 11493 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 11494 | epause->tx_pause = 1; |
| 11495 | else |
| 11496 | epause->tx_pause = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11497 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11499 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 11500 | { |
| 11501 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11502 | int err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11503 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11504 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11505 | u32 newadv; |
| 11506 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11507 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11508 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11509 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11510 | if (!(phydev->supported & SUPPORTED_Pause) || |
| 11511 | (!(phydev->supported & SUPPORTED_Asym_Pause) && |
Nicolas Kaiser | 2259dca | 2010-10-07 23:29:27 +0000 | [diff] [blame] | 11512 | (epause->rx_pause != epause->tx_pause))) |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11513 | return -EINVAL; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11514 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11515 | tp->link_config.flowctrl = 0; |
| 11516 | if (epause->rx_pause) { |
| 11517 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11518 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11519 | if (epause->tx_pause) { |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 11520 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11521 | newadv = ADVERTISED_Pause; |
| 11522 | } else |
| 11523 | newadv = ADVERTISED_Pause | |
| 11524 | ADVERTISED_Asym_Pause; |
| 11525 | } else if (epause->tx_pause) { |
| 11526 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 11527 | newadv = ADVERTISED_Asym_Pause; |
| 11528 | } else |
| 11529 | newadv = 0; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11530 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11531 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11532 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11533 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11534 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11535 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11536 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11537 | u32 oldadv = phydev->advertising & |
| 11538 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 11539 | if (oldadv != newadv) { |
| 11540 | phydev->advertising &= |
| 11541 | ~(ADVERTISED_Pause | |
| 11542 | ADVERTISED_Asym_Pause); |
| 11543 | phydev->advertising |= newadv; |
| 11544 | if (phydev->autoneg) { |
| 11545 | /* |
| 11546 | * Always renegotiate the link to |
| 11547 | * inform our link partner of our |
| 11548 | * flow control settings, even if the |
| 11549 | * flow control is forced. Let |
| 11550 | * tg3_adjust_link() do the final |
| 11551 | * flow control setup. |
| 11552 | */ |
| 11553 | return phy_start_aneg(phydev); |
| 11554 | } |
| 11555 | } |
| 11556 | |
| 11557 | if (!epause->autoneg) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11558 | tg3_setup_flow_control(tp, 0, 0); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11559 | } else { |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 11560 | tp->link_config.advertising &= |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 11561 | ~(ADVERTISED_Pause | |
| 11562 | ADVERTISED_Asym_Pause); |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 11563 | tp->link_config.advertising |= newadv; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11564 | } |
| 11565 | } else { |
| 11566 | int irq_sync = 0; |
| 11567 | |
| 11568 | if (netif_running(dev)) { |
| 11569 | tg3_netif_stop(tp); |
| 11570 | irq_sync = 1; |
| 11571 | } |
| 11572 | |
| 11573 | tg3_full_lock(tp, irq_sync); |
| 11574 | |
| 11575 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11576 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11577 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11578 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11579 | if (epause->rx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 11580 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11581 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 11582 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11583 | if (epause->tx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 11584 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11585 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 11586 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11587 | |
| 11588 | if (netif_running(dev)) { |
| 11589 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11590 | err = tg3_restart_hw(tp, 1); |
| 11591 | if (!err) |
| 11592 | tg3_netif_start(tp); |
| 11593 | } |
| 11594 | |
| 11595 | tg3_full_unlock(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11596 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11597 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11598 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11599 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11600 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 11601 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11602 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 11603 | switch (sset) { |
| 11604 | case ETH_SS_TEST: |
| 11605 | return TG3_NUM_TEST; |
| 11606 | case ETH_SS_STATS: |
| 11607 | return TG3_NUM_STATS; |
| 11608 | default: |
| 11609 | return -EOPNOTSUPP; |
| 11610 | } |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11611 | } |
| 11612 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 11613 | static int tg3_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info, |
| 11614 | u32 *rules __always_unused) |
| 11615 | { |
| 11616 | struct tg3 *tp = netdev_priv(dev); |
| 11617 | |
| 11618 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 11619 | return -EOPNOTSUPP; |
| 11620 | |
| 11621 | switch (info->cmd) { |
| 11622 | case ETHTOOL_GRXRINGS: |
| 11623 | if (netif_running(tp->dev)) |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11624 | info->data = tp->rxq_cnt; |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 11625 | else { |
| 11626 | info->data = num_online_cpus(); |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11627 | if (info->data > TG3_RSS_MAX_NUM_QS) |
| 11628 | info->data = TG3_RSS_MAX_NUM_QS; |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 11629 | } |
| 11630 | |
| 11631 | /* The first interrupt vector only |
| 11632 | * handles link interrupts. |
| 11633 | */ |
| 11634 | info->data -= 1; |
| 11635 | return 0; |
| 11636 | |
| 11637 | default: |
| 11638 | return -EOPNOTSUPP; |
| 11639 | } |
| 11640 | } |
| 11641 | |
| 11642 | static u32 tg3_get_rxfh_indir_size(struct net_device *dev) |
| 11643 | { |
| 11644 | u32 size = 0; |
| 11645 | struct tg3 *tp = netdev_priv(dev); |
| 11646 | |
| 11647 | if (tg3_flag(tp, SUPPORT_MSIX)) |
| 11648 | size = TG3_RSS_INDIR_TBL_SIZE; |
| 11649 | |
| 11650 | return size; |
| 11651 | } |
| 11652 | |
| 11653 | static int tg3_get_rxfh_indir(struct net_device *dev, u32 *indir) |
| 11654 | { |
| 11655 | struct tg3 *tp = netdev_priv(dev); |
| 11656 | int i; |
| 11657 | |
| 11658 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 11659 | indir[i] = tp->rss_ind_tbl[i]; |
| 11660 | |
| 11661 | return 0; |
| 11662 | } |
| 11663 | |
| 11664 | static int tg3_set_rxfh_indir(struct net_device *dev, const u32 *indir) |
| 11665 | { |
| 11666 | struct tg3 *tp = netdev_priv(dev); |
| 11667 | size_t i; |
| 11668 | |
| 11669 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 11670 | tp->rss_ind_tbl[i] = indir[i]; |
| 11671 | |
| 11672 | if (!netif_running(dev) || !tg3_flag(tp, ENABLE_RSS)) |
| 11673 | return 0; |
| 11674 | |
| 11675 | /* It is legal to write the indirection |
| 11676 | * table while the device is running. |
| 11677 | */ |
| 11678 | tg3_full_lock(tp, 0); |
| 11679 | tg3_rss_write_indir_tbl(tp); |
| 11680 | tg3_full_unlock(tp); |
| 11681 | |
| 11682 | return 0; |
| 11683 | } |
| 11684 | |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 11685 | static void tg3_get_channels(struct net_device *dev, |
| 11686 | struct ethtool_channels *channel) |
| 11687 | { |
| 11688 | struct tg3 *tp = netdev_priv(dev); |
| 11689 | u32 deflt_qs = netif_get_num_default_rss_queues(); |
| 11690 | |
| 11691 | channel->max_rx = tp->rxq_max; |
| 11692 | channel->max_tx = tp->txq_max; |
| 11693 | |
| 11694 | if (netif_running(dev)) { |
| 11695 | channel->rx_count = tp->rxq_cnt; |
| 11696 | channel->tx_count = tp->txq_cnt; |
| 11697 | } else { |
| 11698 | if (tp->rxq_req) |
| 11699 | channel->rx_count = tp->rxq_req; |
| 11700 | else |
| 11701 | channel->rx_count = min(deflt_qs, tp->rxq_max); |
| 11702 | |
| 11703 | if (tp->txq_req) |
| 11704 | channel->tx_count = tp->txq_req; |
| 11705 | else |
| 11706 | channel->tx_count = min(deflt_qs, tp->txq_max); |
| 11707 | } |
| 11708 | } |
| 11709 | |
| 11710 | static int tg3_set_channels(struct net_device *dev, |
| 11711 | struct ethtool_channels *channel) |
| 11712 | { |
| 11713 | struct tg3 *tp = netdev_priv(dev); |
| 11714 | |
| 11715 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 11716 | return -EOPNOTSUPP; |
| 11717 | |
| 11718 | if (channel->rx_count > tp->rxq_max || |
| 11719 | channel->tx_count > tp->txq_max) |
| 11720 | return -EINVAL; |
| 11721 | |
| 11722 | tp->rxq_req = channel->rx_count; |
| 11723 | tp->txq_req = channel->tx_count; |
| 11724 | |
| 11725 | if (!netif_running(dev)) |
| 11726 | return 0; |
| 11727 | |
| 11728 | tg3_stop(tp); |
| 11729 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 11730 | tg3_carrier_off(tp); |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 11731 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 11732 | tg3_start(tp, true, false, false); |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 11733 | |
| 11734 | return 0; |
| 11735 | } |
| 11736 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 11737 | 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] | 11738 | { |
| 11739 | switch (stringset) { |
| 11740 | case ETH_SS_STATS: |
| 11741 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 11742 | break; |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11743 | case ETH_SS_TEST: |
| 11744 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); |
| 11745 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11746 | default: |
| 11747 | WARN_ON(1); /* we need a WARN() */ |
| 11748 | break; |
| 11749 | } |
| 11750 | } |
| 11751 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11752 | static int tg3_set_phys_id(struct net_device *dev, |
| 11753 | enum ethtool_phys_id_state state) |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11754 | { |
| 11755 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11756 | |
| 11757 | if (!netif_running(tp->dev)) |
| 11758 | return -EAGAIN; |
| 11759 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11760 | switch (state) { |
| 11761 | case ETHTOOL_ID_ACTIVE: |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 11762 | return 1; /* cycle on/off once per second */ |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11763 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11764 | case ETHTOOL_ID_ON: |
| 11765 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 11766 | LED_CTRL_1000MBPS_ON | |
| 11767 | LED_CTRL_100MBPS_ON | |
| 11768 | LED_CTRL_10MBPS_ON | |
| 11769 | LED_CTRL_TRAFFIC_OVERRIDE | |
| 11770 | LED_CTRL_TRAFFIC_BLINK | |
| 11771 | LED_CTRL_TRAFFIC_LED); |
| 11772 | break; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11773 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11774 | case ETHTOOL_ID_OFF: |
| 11775 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 11776 | LED_CTRL_TRAFFIC_OVERRIDE); |
| 11777 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11778 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11779 | case ETHTOOL_ID_INACTIVE: |
| 11780 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 11781 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11782 | } |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 11783 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11784 | return 0; |
| 11785 | } |
| 11786 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 11787 | static void tg3_get_ethtool_stats(struct net_device *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11788 | struct ethtool_stats *estats, u64 *tmp_stats) |
| 11789 | { |
| 11790 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 0e6c9da | 2011-12-08 14:40:13 +0000 | [diff] [blame] | 11791 | |
Matt Carlson | b546e46 | 2012-02-13 15:20:09 +0000 | [diff] [blame] | 11792 | if (tp->hw_stats) |
| 11793 | tg3_get_estats(tp, (struct tg3_ethtool_stats *)tmp_stats); |
| 11794 | else |
| 11795 | memset(tmp_stats, 0, sizeof(struct tg3_ethtool_stats)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11796 | } |
| 11797 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11798 | static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11799 | { |
| 11800 | int i; |
| 11801 | __be32 *buf; |
| 11802 | u32 offset = 0, len = 0; |
| 11803 | u32 magic, val; |
| 11804 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11805 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &magic)) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11806 | return NULL; |
| 11807 | |
| 11808 | if (magic == TG3_EEPROM_MAGIC) { |
| 11809 | for (offset = TG3_NVM_DIR_START; |
| 11810 | offset < TG3_NVM_DIR_END; |
| 11811 | offset += TG3_NVM_DIRENT_SIZE) { |
| 11812 | if (tg3_nvram_read(tp, offset, &val)) |
| 11813 | return NULL; |
| 11814 | |
| 11815 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == |
| 11816 | TG3_NVM_DIRTYPE_EXTVPD) |
| 11817 | break; |
| 11818 | } |
| 11819 | |
| 11820 | if (offset != TG3_NVM_DIR_END) { |
| 11821 | len = (val & TG3_NVM_DIRTYPE_LENMSK) * 4; |
| 11822 | if (tg3_nvram_read(tp, offset + 4, &offset)) |
| 11823 | return NULL; |
| 11824 | |
| 11825 | offset = tg3_nvram_logical_addr(tp, offset); |
| 11826 | } |
| 11827 | } |
| 11828 | |
| 11829 | if (!offset || !len) { |
| 11830 | offset = TG3_NVM_VPD_OFF; |
| 11831 | len = TG3_NVM_VPD_LEN; |
| 11832 | } |
| 11833 | |
| 11834 | buf = kmalloc(len, GFP_KERNEL); |
| 11835 | if (buf == NULL) |
| 11836 | return NULL; |
| 11837 | |
| 11838 | if (magic == TG3_EEPROM_MAGIC) { |
| 11839 | for (i = 0; i < len; i += 4) { |
| 11840 | /* The data is in little-endian format in NVRAM. |
| 11841 | * Use the big-endian read routines to preserve |
| 11842 | * the byte order as it exists in NVRAM. |
| 11843 | */ |
| 11844 | if (tg3_nvram_read_be32(tp, offset + i, &buf[i/4])) |
| 11845 | goto error; |
| 11846 | } |
| 11847 | } else { |
| 11848 | u8 *ptr; |
| 11849 | ssize_t cnt; |
| 11850 | unsigned int pos = 0; |
| 11851 | |
| 11852 | ptr = (u8 *)&buf[0]; |
| 11853 | for (i = 0; pos < len && i < 3; i++, pos += cnt, ptr += cnt) { |
| 11854 | cnt = pci_read_vpd(tp->pdev, pos, |
| 11855 | len - pos, ptr); |
| 11856 | if (cnt == -ETIMEDOUT || cnt == -EINTR) |
| 11857 | cnt = 0; |
| 11858 | else if (cnt < 0) |
| 11859 | goto error; |
| 11860 | } |
| 11861 | if (pos != len) |
| 11862 | goto error; |
| 11863 | } |
| 11864 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11865 | *vpdlen = len; |
| 11866 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 11867 | return buf; |
| 11868 | |
| 11869 | error: |
| 11870 | kfree(buf); |
| 11871 | return NULL; |
| 11872 | } |
| 11873 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11874 | #define NVRAM_TEST_SIZE 0x100 |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11875 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
| 11876 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 |
| 11877 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11878 | #define NVRAM_SELFBOOT_FORMAT1_4_SIZE 0x20 |
| 11879 | #define NVRAM_SELFBOOT_FORMAT1_5_SIZE 0x24 |
Matt Carlson | bda18fa | 2011-07-20 10:20:57 +0000 | [diff] [blame] | 11880 | #define NVRAM_SELFBOOT_FORMAT1_6_SIZE 0x50 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11881 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
| 11882 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11883 | |
| 11884 | static int tg3_test_nvram(struct tg3 *tp) |
| 11885 | { |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 11886 | u32 csum, magic, len; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11887 | __be32 *buf; |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 11888 | int i, j, k, err = 0, size; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11889 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11890 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11891 | return 0; |
| 11892 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11893 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11894 | return -EIO; |
| 11895 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11896 | if (magic == TG3_EEPROM_MAGIC) |
| 11897 | size = NVRAM_TEST_SIZE; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11898 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11899 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
| 11900 | TG3_EEPROM_SB_FORMAT_1) { |
| 11901 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { |
| 11902 | case TG3_EEPROM_SB_REVISION_0: |
| 11903 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; |
| 11904 | break; |
| 11905 | case TG3_EEPROM_SB_REVISION_2: |
| 11906 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; |
| 11907 | break; |
| 11908 | case TG3_EEPROM_SB_REVISION_3: |
| 11909 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; |
| 11910 | break; |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11911 | case TG3_EEPROM_SB_REVISION_4: |
| 11912 | size = NVRAM_SELFBOOT_FORMAT1_4_SIZE; |
| 11913 | break; |
| 11914 | case TG3_EEPROM_SB_REVISION_5: |
| 11915 | size = NVRAM_SELFBOOT_FORMAT1_5_SIZE; |
| 11916 | break; |
| 11917 | case TG3_EEPROM_SB_REVISION_6: |
| 11918 | size = NVRAM_SELFBOOT_FORMAT1_6_SIZE; |
| 11919 | break; |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11920 | default: |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 11921 | return -EIO; |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11922 | } |
| 11923 | } else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11924 | return 0; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11925 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 11926 | size = NVRAM_SELFBOOT_HW_SIZE; |
| 11927 | else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11928 | return -EIO; |
| 11929 | |
| 11930 | buf = kmalloc(size, GFP_KERNEL); |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11931 | if (buf == NULL) |
| 11932 | return -ENOMEM; |
| 11933 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11934 | err = -EIO; |
| 11935 | for (i = 0, j = 0; i < size; i += 4, j++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11936 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
| 11937 | if (err) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11938 | break; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11939 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11940 | if (i < size) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11941 | goto out; |
| 11942 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11943 | /* Selfboot format */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11944 | magic = be32_to_cpu(buf[0]); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11945 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11946 | TG3_EEPROM_MAGIC_FW) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11947 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
| 11948 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11949 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 11950 | TG3_EEPROM_SB_REVISION_2) { |
| 11951 | /* For rev 2, the csum doesn't include the MBA. */ |
| 11952 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) |
| 11953 | csum8 += buf8[i]; |
| 11954 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) |
| 11955 | csum8 += buf8[i]; |
| 11956 | } else { |
| 11957 | for (i = 0; i < size; i++) |
| 11958 | csum8 += buf8[i]; |
| 11959 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11960 | |
Adrian Bunk | ad96b48 | 2006-04-05 22:21:04 -0700 | [diff] [blame] | 11961 | if (csum8 == 0) { |
| 11962 | err = 0; |
| 11963 | goto out; |
| 11964 | } |
| 11965 | |
| 11966 | err = -EIO; |
| 11967 | goto out; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11968 | } |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11969 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11970 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11971 | TG3_EEPROM_MAGIC_HW) { |
| 11972 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11973 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11974 | u8 *buf8 = (u8 *) buf; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11975 | |
| 11976 | /* Separate the parity bits and the data bytes. */ |
| 11977 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { |
| 11978 | if ((i == 0) || (i == 8)) { |
| 11979 | int l; |
| 11980 | u8 msk; |
| 11981 | |
| 11982 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) |
| 11983 | parity[k++] = buf8[i] & msk; |
| 11984 | i++; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 11985 | } else if (i == 16) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11986 | int l; |
| 11987 | u8 msk; |
| 11988 | |
| 11989 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) |
| 11990 | parity[k++] = buf8[i] & msk; |
| 11991 | i++; |
| 11992 | |
| 11993 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) |
| 11994 | parity[k++] = buf8[i] & msk; |
| 11995 | i++; |
| 11996 | } |
| 11997 | data[j++] = buf8[i]; |
| 11998 | } |
| 11999 | |
| 12000 | err = -EIO; |
| 12001 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { |
| 12002 | u8 hw8 = hweight8(data[i]); |
| 12003 | |
| 12004 | if ((hw8 & 0x1) && parity[i]) |
| 12005 | goto out; |
| 12006 | else if (!(hw8 & 0x1) && !parity[i]) |
| 12007 | goto out; |
| 12008 | } |
| 12009 | err = 0; |
| 12010 | goto out; |
| 12011 | } |
| 12012 | |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 12013 | err = -EIO; |
| 12014 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12015 | /* Bootstrap checksum at offset 0x10 */ |
| 12016 | csum = calc_crc((unsigned char *) buf, 0x10); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 12017 | if (csum != le32_to_cpu(buf[0x10/4])) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12018 | goto out; |
| 12019 | |
| 12020 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ |
| 12021 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 12022 | if (csum != le32_to_cpu(buf[0xfc/4])) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12023 | goto out; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12024 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 12025 | kfree(buf); |
| 12026 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 12027 | buf = tg3_vpd_readblock(tp, &len); |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 12028 | if (!buf) |
| 12029 | return -ENOMEM; |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 12030 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 12031 | 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] | 12032 | if (i > 0) { |
| 12033 | j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); |
| 12034 | if (j < 0) |
| 12035 | goto out; |
| 12036 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 12037 | if (i + PCI_VPD_LRDT_TAG_SIZE + j > len) |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 12038 | goto out; |
| 12039 | |
| 12040 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 12041 | j = pci_vpd_find_info_keyword((u8 *)buf, i, j, |
| 12042 | PCI_VPD_RO_KEYWORD_CHKSUM); |
| 12043 | if (j > 0) { |
| 12044 | u8 csum8 = 0; |
| 12045 | |
| 12046 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 12047 | |
| 12048 | for (i = 0; i <= j; i++) |
| 12049 | csum8 += ((u8 *)buf)[i]; |
| 12050 | |
| 12051 | if (csum8) |
| 12052 | goto out; |
| 12053 | } |
| 12054 | } |
| 12055 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12056 | err = 0; |
| 12057 | |
| 12058 | out: |
| 12059 | kfree(buf); |
| 12060 | return err; |
| 12061 | } |
| 12062 | |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12063 | #define TG3_SERDES_TIMEOUT_SEC 2 |
| 12064 | #define TG3_COPPER_TIMEOUT_SEC 6 |
| 12065 | |
| 12066 | static int tg3_test_link(struct tg3 *tp) |
| 12067 | { |
| 12068 | int i, max; |
| 12069 | |
| 12070 | if (!netif_running(tp->dev)) |
| 12071 | return -ENODEV; |
| 12072 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12073 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12074 | max = TG3_SERDES_TIMEOUT_SEC; |
| 12075 | else |
| 12076 | max = TG3_COPPER_TIMEOUT_SEC; |
| 12077 | |
| 12078 | for (i = 0; i < max; i++) { |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 12079 | if (tp->link_up) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12080 | return 0; |
| 12081 | |
| 12082 | if (msleep_interruptible(1000)) |
| 12083 | break; |
| 12084 | } |
| 12085 | |
| 12086 | return -EIO; |
| 12087 | } |
| 12088 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12089 | /* Only test the commonly used registers */ |
David S. Miller | 30ca3e3 | 2006-03-20 23:02:36 -0800 | [diff] [blame] | 12090 | static int tg3_test_registers(struct tg3 *tp) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12091 | { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12092 | int i, is_5705, is_5750; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12093 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
| 12094 | static struct { |
| 12095 | u16 offset; |
| 12096 | u16 flags; |
| 12097 | #define TG3_FL_5705 0x1 |
| 12098 | #define TG3_FL_NOT_5705 0x2 |
| 12099 | #define TG3_FL_NOT_5788 0x4 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12100 | #define TG3_FL_NOT_5750 0x8 |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12101 | u32 read_mask; |
| 12102 | u32 write_mask; |
| 12103 | } reg_tbl[] = { |
| 12104 | /* MAC Control Registers */ |
| 12105 | { MAC_MODE, TG3_FL_NOT_5705, |
| 12106 | 0x00000000, 0x00ef6f8c }, |
| 12107 | { MAC_MODE, TG3_FL_5705, |
| 12108 | 0x00000000, 0x01ef6b8c }, |
| 12109 | { MAC_STATUS, TG3_FL_NOT_5705, |
| 12110 | 0x03800107, 0x00000000 }, |
| 12111 | { MAC_STATUS, TG3_FL_5705, |
| 12112 | 0x03800100, 0x00000000 }, |
| 12113 | { MAC_ADDR_0_HIGH, 0x0000, |
| 12114 | 0x00000000, 0x0000ffff }, |
| 12115 | { MAC_ADDR_0_LOW, 0x0000, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12116 | 0x00000000, 0xffffffff }, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12117 | { MAC_RX_MTU_SIZE, 0x0000, |
| 12118 | 0x00000000, 0x0000ffff }, |
| 12119 | { MAC_TX_MODE, 0x0000, |
| 12120 | 0x00000000, 0x00000070 }, |
| 12121 | { MAC_TX_LENGTHS, 0x0000, |
| 12122 | 0x00000000, 0x00003fff }, |
| 12123 | { MAC_RX_MODE, TG3_FL_NOT_5705, |
| 12124 | 0x00000000, 0x000007fc }, |
| 12125 | { MAC_RX_MODE, TG3_FL_5705, |
| 12126 | 0x00000000, 0x000007dc }, |
| 12127 | { MAC_HASH_REG_0, 0x0000, |
| 12128 | 0x00000000, 0xffffffff }, |
| 12129 | { MAC_HASH_REG_1, 0x0000, |
| 12130 | 0x00000000, 0xffffffff }, |
| 12131 | { MAC_HASH_REG_2, 0x0000, |
| 12132 | 0x00000000, 0xffffffff }, |
| 12133 | { MAC_HASH_REG_3, 0x0000, |
| 12134 | 0x00000000, 0xffffffff }, |
| 12135 | |
| 12136 | /* Receive Data and Receive BD Initiator Control Registers. */ |
| 12137 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, |
| 12138 | 0x00000000, 0xffffffff }, |
| 12139 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, |
| 12140 | 0x00000000, 0xffffffff }, |
| 12141 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, |
| 12142 | 0x00000000, 0x00000003 }, |
| 12143 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, |
| 12144 | 0x00000000, 0xffffffff }, |
| 12145 | { RCVDBDI_STD_BD+0, 0x0000, |
| 12146 | 0x00000000, 0xffffffff }, |
| 12147 | { RCVDBDI_STD_BD+4, 0x0000, |
| 12148 | 0x00000000, 0xffffffff }, |
| 12149 | { RCVDBDI_STD_BD+8, 0x0000, |
| 12150 | 0x00000000, 0xffff0002 }, |
| 12151 | { RCVDBDI_STD_BD+0xc, 0x0000, |
| 12152 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12153 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12154 | /* Receive BD Initiator Control Registers. */ |
| 12155 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, |
| 12156 | 0x00000000, 0xffffffff }, |
| 12157 | { RCVBDI_STD_THRESH, TG3_FL_5705, |
| 12158 | 0x00000000, 0x000003ff }, |
| 12159 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, |
| 12160 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12161 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12162 | /* Host Coalescing Control Registers. */ |
| 12163 | { HOSTCC_MODE, TG3_FL_NOT_5705, |
| 12164 | 0x00000000, 0x00000004 }, |
| 12165 | { HOSTCC_MODE, TG3_FL_5705, |
| 12166 | 0x00000000, 0x000000f6 }, |
| 12167 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, |
| 12168 | 0x00000000, 0xffffffff }, |
| 12169 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, |
| 12170 | 0x00000000, 0x000003ff }, |
| 12171 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, |
| 12172 | 0x00000000, 0xffffffff }, |
| 12173 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, |
| 12174 | 0x00000000, 0x000003ff }, |
| 12175 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, |
| 12176 | 0x00000000, 0xffffffff }, |
| 12177 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 12178 | 0x00000000, 0x000000ff }, |
| 12179 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, |
| 12180 | 0x00000000, 0xffffffff }, |
| 12181 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 12182 | 0x00000000, 0x000000ff }, |
| 12183 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 12184 | 0x00000000, 0xffffffff }, |
| 12185 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 12186 | 0x00000000, 0xffffffff }, |
| 12187 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 12188 | 0x00000000, 0xffffffff }, |
| 12189 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 12190 | 0x00000000, 0x000000ff }, |
| 12191 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 12192 | 0x00000000, 0xffffffff }, |
| 12193 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 12194 | 0x00000000, 0x000000ff }, |
| 12195 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, |
| 12196 | 0x00000000, 0xffffffff }, |
| 12197 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, |
| 12198 | 0x00000000, 0xffffffff }, |
| 12199 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, |
| 12200 | 0x00000000, 0xffffffff }, |
| 12201 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, |
| 12202 | 0x00000000, 0xffffffff }, |
| 12203 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, |
| 12204 | 0x00000000, 0xffffffff }, |
| 12205 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, |
| 12206 | 0xffffffff, 0x00000000 }, |
| 12207 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, |
| 12208 | 0xffffffff, 0x00000000 }, |
| 12209 | |
| 12210 | /* Buffer Manager Control Registers. */ |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12211 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12212 | 0x00000000, 0x007fff80 }, |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12213 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12214 | 0x00000000, 0x007fffff }, |
| 12215 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, |
| 12216 | 0x00000000, 0x0000003f }, |
| 12217 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, |
| 12218 | 0x00000000, 0x000001ff }, |
| 12219 | { BUFMGR_MB_HIGH_WATER, 0x0000, |
| 12220 | 0x00000000, 0x000001ff }, |
| 12221 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, |
| 12222 | 0xffffffff, 0x00000000 }, |
| 12223 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, |
| 12224 | 0xffffffff, 0x00000000 }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12225 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12226 | /* Mailbox Registers */ |
| 12227 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, |
| 12228 | 0x00000000, 0x000001ff }, |
| 12229 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, |
| 12230 | 0x00000000, 0x000001ff }, |
| 12231 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, |
| 12232 | 0x00000000, 0x000007ff }, |
| 12233 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, |
| 12234 | 0x00000000, 0x000001ff }, |
| 12235 | |
| 12236 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, |
| 12237 | }; |
| 12238 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12239 | is_5705 = is_5750 = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12240 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12241 | is_5705 = 1; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12242 | if (tg3_flag(tp, 5750_PLUS)) |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12243 | is_5750 = 1; |
| 12244 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12245 | |
| 12246 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { |
| 12247 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) |
| 12248 | continue; |
| 12249 | |
| 12250 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) |
| 12251 | continue; |
| 12252 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12253 | if (tg3_flag(tp, IS_5788) && |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12254 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
| 12255 | continue; |
| 12256 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12257 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
| 12258 | continue; |
| 12259 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12260 | offset = (u32) reg_tbl[i].offset; |
| 12261 | read_mask = reg_tbl[i].read_mask; |
| 12262 | write_mask = reg_tbl[i].write_mask; |
| 12263 | |
| 12264 | /* Save the original register content */ |
| 12265 | save_val = tr32(offset); |
| 12266 | |
| 12267 | /* Determine the read-only value. */ |
| 12268 | read_val = save_val & read_mask; |
| 12269 | |
| 12270 | /* Write zero to the register, then make sure the read-only bits |
| 12271 | * are not changed and the read/write bits are all zeros. |
| 12272 | */ |
| 12273 | tw32(offset, 0); |
| 12274 | |
| 12275 | val = tr32(offset); |
| 12276 | |
| 12277 | /* Test the read-only and read/write bits. */ |
| 12278 | if (((val & read_mask) != read_val) || (val & write_mask)) |
| 12279 | goto out; |
| 12280 | |
| 12281 | /* Write ones to all the bits defined by RdMask and WrMask, then |
| 12282 | * make sure the read-only bits are not changed and the |
| 12283 | * read/write bits are all ones. |
| 12284 | */ |
| 12285 | tw32(offset, read_mask | write_mask); |
| 12286 | |
| 12287 | val = tr32(offset); |
| 12288 | |
| 12289 | /* Test the read-only bits. */ |
| 12290 | if ((val & read_mask) != read_val) |
| 12291 | goto out; |
| 12292 | |
| 12293 | /* Test the read/write bits. */ |
| 12294 | if ((val & write_mask) != write_mask) |
| 12295 | goto out; |
| 12296 | |
| 12297 | tw32(offset, save_val); |
| 12298 | } |
| 12299 | |
| 12300 | return 0; |
| 12301 | |
| 12302 | out: |
Michael Chan | 9f88f29 | 2006-12-07 00:22:54 -0800 | [diff] [blame] | 12303 | if (netif_msg_hw(tp)) |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 12304 | netdev_err(tp->dev, |
| 12305 | "Register test failed at offset %x\n", offset); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12306 | tw32(offset, save_val); |
| 12307 | return -EIO; |
| 12308 | } |
| 12309 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12310 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
| 12311 | { |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 12312 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12313 | int i; |
| 12314 | u32 j; |
| 12315 | |
Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 12316 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12317 | for (j = 0; j < len; j += 4) { |
| 12318 | u32 val; |
| 12319 | |
| 12320 | tg3_write_mem(tp, offset + j, test_pattern[i]); |
| 12321 | tg3_read_mem(tp, offset + j, &val); |
| 12322 | if (val != test_pattern[i]) |
| 12323 | return -EIO; |
| 12324 | } |
| 12325 | } |
| 12326 | return 0; |
| 12327 | } |
| 12328 | |
| 12329 | static int tg3_test_memory(struct tg3 *tp) |
| 12330 | { |
| 12331 | static struct mem_entry { |
| 12332 | u32 offset; |
| 12333 | u32 len; |
| 12334 | } mem_tbl_570x[] = { |
Michael Chan | 3869019 | 2005-12-19 16:27:28 -0800 | [diff] [blame] | 12335 | { 0x00000000, 0x00b50}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12336 | { 0x00002000, 0x1c000}, |
| 12337 | { 0xffffffff, 0x00000} |
| 12338 | }, mem_tbl_5705[] = { |
| 12339 | { 0x00000100, 0x0000c}, |
| 12340 | { 0x00000200, 0x00008}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12341 | { 0x00004000, 0x00800}, |
| 12342 | { 0x00006000, 0x01000}, |
| 12343 | { 0x00008000, 0x02000}, |
| 12344 | { 0x00010000, 0x0e000}, |
| 12345 | { 0xffffffff, 0x00000} |
Michael Chan | 79f4d13 | 2006-03-20 22:28:57 -0800 | [diff] [blame] | 12346 | }, mem_tbl_5755[] = { |
| 12347 | { 0x00000200, 0x00008}, |
| 12348 | { 0x00004000, 0x00800}, |
| 12349 | { 0x00006000, 0x00800}, |
| 12350 | { 0x00008000, 0x02000}, |
| 12351 | { 0x00010000, 0x0c000}, |
| 12352 | { 0xffffffff, 0x00000} |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12353 | }, mem_tbl_5906[] = { |
| 12354 | { 0x00000200, 0x00008}, |
| 12355 | { 0x00004000, 0x00400}, |
| 12356 | { 0x00006000, 0x00400}, |
| 12357 | { 0x00008000, 0x01000}, |
| 12358 | { 0x00010000, 0x01000}, |
| 12359 | { 0xffffffff, 0x00000} |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 12360 | }, mem_tbl_5717[] = { |
| 12361 | { 0x00000200, 0x00008}, |
| 12362 | { 0x00010000, 0x0a000}, |
| 12363 | { 0x00020000, 0x13c00}, |
| 12364 | { 0xffffffff, 0x00000} |
| 12365 | }, mem_tbl_57765[] = { |
| 12366 | { 0x00000200, 0x00008}, |
| 12367 | { 0x00004000, 0x00800}, |
| 12368 | { 0x00006000, 0x09800}, |
| 12369 | { 0x00010000, 0x0a000}, |
| 12370 | { 0xffffffff, 0x00000} |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12371 | }; |
| 12372 | struct mem_entry *mem_tbl; |
| 12373 | int err = 0; |
| 12374 | int i; |
| 12375 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12376 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 12377 | mem_tbl = mem_tbl_5717; |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 12378 | else if (tg3_flag(tp, 57765_CLASS) || |
| 12379 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 12380 | mem_tbl = mem_tbl_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12381 | else if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12382 | mem_tbl = mem_tbl_5755; |
| 12383 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 12384 | mem_tbl = mem_tbl_5906; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12385 | else if (tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12386 | mem_tbl = mem_tbl_5705; |
| 12387 | else |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12388 | mem_tbl = mem_tbl_570x; |
| 12389 | |
| 12390 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 12391 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
| 12392 | if (err) |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12393 | break; |
| 12394 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12395 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12396 | return err; |
| 12397 | } |
| 12398 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12399 | #define TG3_TSO_MSS 500 |
| 12400 | |
| 12401 | #define TG3_TSO_IP_HDR_LEN 20 |
| 12402 | #define TG3_TSO_TCP_HDR_LEN 20 |
| 12403 | #define TG3_TSO_TCP_OPT_LEN 12 |
| 12404 | |
| 12405 | static const u8 tg3_tso_header[] = { |
| 12406 | 0x08, 0x00, |
| 12407 | 0x45, 0x00, 0x00, 0x00, |
| 12408 | 0x00, 0x00, 0x40, 0x00, |
| 12409 | 0x40, 0x06, 0x00, 0x00, |
| 12410 | 0x0a, 0x00, 0x00, 0x01, |
| 12411 | 0x0a, 0x00, 0x00, 0x02, |
| 12412 | 0x0d, 0x00, 0xe0, 0x00, |
| 12413 | 0x00, 0x00, 0x01, 0x00, |
| 12414 | 0x00, 0x00, 0x02, 0x00, |
| 12415 | 0x80, 0x10, 0x10, 0x00, |
| 12416 | 0x14, 0x09, 0x00, 0x00, |
| 12417 | 0x01, 0x01, 0x08, 0x0a, |
| 12418 | 0x11, 0x11, 0x11, 0x11, |
| 12419 | 0x11, 0x11, 0x11, 0x11, |
| 12420 | }; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12421 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12422 | 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] | 12423 | { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12424 | u32 rx_start_idx, rx_idx, tx_idx, opaque_key; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12425 | 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] | 12426 | u32 budget; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12427 | struct sk_buff *skb; |
| 12428 | u8 *tx_data, *rx_data; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12429 | dma_addr_t map; |
| 12430 | int num_pkts, tx_len, rx_len, i, err; |
| 12431 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 12432 | struct tg3_napi *tnapi, *rnapi; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 12433 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12434 | |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 12435 | tnapi = &tp->napi[0]; |
| 12436 | rnapi = &tp->napi[0]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 12437 | if (tp->irq_cnt > 1) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12438 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | 1da85aa | 2010-09-30 10:34:34 +0000 | [diff] [blame] | 12439 | rnapi = &tp->napi[1]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12440 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 12441 | tnapi = &tp->napi[1]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 12442 | } |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 12443 | coal_now = tnapi->coal_now | rnapi->coal_now; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 12444 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12445 | err = -EIO; |
| 12446 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12447 | tx_len = pktsz; |
David S. Miller | a20e9c6 | 2006-07-31 22:38:16 -0700 | [diff] [blame] | 12448 | skb = netdev_alloc_skb(tp->dev, tx_len); |
Jesper Juhl | a50bb7b | 2006-05-09 23:14:35 -0700 | [diff] [blame] | 12449 | if (!skb) |
| 12450 | return -ENOMEM; |
| 12451 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12452 | tx_data = skb_put(skb, tx_len); |
| 12453 | memcpy(tx_data, tp->dev->dev_addr, 6); |
| 12454 | memset(tx_data + 6, 0x0, 8); |
| 12455 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12456 | tw32(MAC_RX_MTU_SIZE, tx_len + ETH_FCS_LEN); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12457 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12458 | if (tso_loopback) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12459 | struct iphdr *iph = (struct iphdr *)&tx_data[ETH_HLEN]; |
| 12460 | |
| 12461 | u32 hdr_len = TG3_TSO_IP_HDR_LEN + TG3_TSO_TCP_HDR_LEN + |
| 12462 | TG3_TSO_TCP_OPT_LEN; |
| 12463 | |
| 12464 | memcpy(tx_data + ETH_ALEN * 2, tg3_tso_header, |
| 12465 | sizeof(tg3_tso_header)); |
| 12466 | mss = TG3_TSO_MSS; |
| 12467 | |
| 12468 | val = tx_len - ETH_ALEN * 2 - sizeof(tg3_tso_header); |
| 12469 | num_pkts = DIV_ROUND_UP(val, TG3_TSO_MSS); |
| 12470 | |
| 12471 | /* Set the total length field in the IP header */ |
| 12472 | iph->tot_len = htons((u16)(mss + hdr_len)); |
| 12473 | |
| 12474 | base_flags = (TXD_FLAG_CPU_PRE_DMA | |
| 12475 | TXD_FLAG_CPU_POST_DMA); |
| 12476 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12477 | if (tg3_flag(tp, HW_TSO_1) || |
| 12478 | tg3_flag(tp, HW_TSO_2) || |
| 12479 | tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12480 | struct tcphdr *th; |
| 12481 | val = ETH_HLEN + TG3_TSO_IP_HDR_LEN; |
| 12482 | th = (struct tcphdr *)&tx_data[val]; |
| 12483 | th->check = 0; |
| 12484 | } else |
| 12485 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
| 12486 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12487 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12488 | mss |= (hdr_len & 0xc) << 12; |
| 12489 | if (hdr_len & 0x10) |
| 12490 | base_flags |= 0x00000010; |
| 12491 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12492 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12493 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12494 | else if (tg3_flag(tp, HW_TSO_1) || |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12495 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 12496 | mss |= (TG3_TSO_TCP_OPT_LEN << 9); |
| 12497 | } else { |
| 12498 | base_flags |= (TG3_TSO_TCP_OPT_LEN << 10); |
| 12499 | } |
| 12500 | |
| 12501 | data_off = ETH_ALEN * 2 + sizeof(tg3_tso_header); |
| 12502 | } else { |
| 12503 | num_pkts = 1; |
| 12504 | data_off = ETH_HLEN; |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12505 | |
| 12506 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 12507 | tx_len > VLAN_ETH_FRAME_LEN) |
| 12508 | base_flags |= TXD_FLAG_JMB_PKT; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12509 | } |
| 12510 | |
| 12511 | for (i = data_off; i < tx_len; i++) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12512 | tx_data[i] = (u8) (i & 0xff); |
| 12513 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 12514 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
| 12515 | if (pci_dma_mapping_error(tp->pdev, map)) { |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 12516 | dev_kfree_skb(skb); |
| 12517 | return -EIO; |
| 12518 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12519 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 12520 | val = tnapi->tx_prod; |
| 12521 | tnapi->tx_buffers[val].skb = skb; |
| 12522 | dma_unmap_addr_set(&tnapi->tx_buffers[val], mapping, map); |
| 12523 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12524 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 12525 | rnapi->coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12526 | |
| 12527 | udelay(10); |
| 12528 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 12529 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12530 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 12531 | budget = tg3_tx_avail(tnapi); |
| 12532 | if (tg3_tx_frag_set(tnapi, &val, &budget, map, tx_len, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 12533 | base_flags | TXD_FLAG_END, mss, 0)) { |
| 12534 | tnapi->tx_buffers[val].skb = NULL; |
| 12535 | dev_kfree_skb(skb); |
| 12536 | return -EIO; |
| 12537 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12538 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 12539 | tnapi->tx_prod++; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12540 | |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 12541 | /* Sync BD data before updating mailbox */ |
| 12542 | wmb(); |
| 12543 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 12544 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 12545 | tr32_mailbox(tnapi->prodmbox); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12546 | |
| 12547 | udelay(10); |
| 12548 | |
Matt Carlson | 303fc92 | 2009-11-02 14:27:34 +0000 | [diff] [blame] | 12549 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
| 12550 | for (i = 0; i < 35; i++) { |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12551 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 12552 | coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12553 | |
| 12554 | udelay(10); |
| 12555 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 12556 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 12557 | rx_idx = rnapi->hw_status->idx[0].rx_producer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 12558 | if ((tx_idx == tnapi->tx_prod) && |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12559 | (rx_idx == (rx_start_idx + num_pkts))) |
| 12560 | break; |
| 12561 | } |
| 12562 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 12563 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod - 1, -1); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12564 | dev_kfree_skb(skb); |
| 12565 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 12566 | if (tx_idx != tnapi->tx_prod) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12567 | goto out; |
| 12568 | |
| 12569 | if (rx_idx != rx_start_idx + num_pkts) |
| 12570 | goto out; |
| 12571 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12572 | val = data_off; |
| 12573 | while (rx_idx != rx_start_idx) { |
| 12574 | desc = &rnapi->rx_rcb[rx_start_idx++]; |
| 12575 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 12576 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12577 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12578 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 12579 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12580 | goto out; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12581 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12582 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) |
| 12583 | - ETH_FCS_LEN; |
| 12584 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12585 | if (!tso_loopback) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12586 | if (rx_len != tx_len) |
| 12587 | goto out; |
| 12588 | |
| 12589 | if (pktsz <= TG3_RX_STD_DMA_SZ - ETH_FCS_LEN) { |
| 12590 | if (opaque_key != RXD_OPAQUE_RING_STD) |
| 12591 | goto out; |
| 12592 | } else { |
| 12593 | if (opaque_key != RXD_OPAQUE_RING_JUMBO) |
| 12594 | goto out; |
| 12595 | } |
| 12596 | } else if ((desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 12597 | (desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
Matt Carlson | 54e0a67 | 2011-05-19 12:12:50 +0000 | [diff] [blame] | 12598 | >> RXD_TCPCSUM_SHIFT != 0xffff) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12599 | goto out; |
| 12600 | } |
| 12601 | |
| 12602 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12603 | rx_data = tpr->rx_std_buffers[desc_idx].data; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12604 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], |
| 12605 | mapping); |
| 12606 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12607 | rx_data = tpr->rx_jmb_buffers[desc_idx].data; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12608 | map = dma_unmap_addr(&tpr->rx_jmb_buffers[desc_idx], |
| 12609 | mapping); |
| 12610 | } else |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12611 | goto out; |
| 12612 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12613 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, |
| 12614 | PCI_DMA_FROMDEVICE); |
| 12615 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12616 | rx_data += TG3_RX_OFFSET(tp); |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12617 | for (i = data_off; i < rx_len; i++, val++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12618 | if (*(rx_data + i) != (u8) (val & 0xff)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12619 | goto out; |
| 12620 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12621 | } |
| 12622 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12623 | err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12624 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12625 | /* tg3_free_rings will unmap and free the rx_data */ |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12626 | out: |
| 12627 | return err; |
| 12628 | } |
| 12629 | |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 12630 | #define TG3_STD_LOOPBACK_FAILED 1 |
| 12631 | #define TG3_JMB_LOOPBACK_FAILED 2 |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12632 | #define TG3_TSO_LOOPBACK_FAILED 4 |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12633 | #define TG3_LOOPBACK_FAILED \ |
| 12634 | (TG3_STD_LOOPBACK_FAILED | \ |
| 12635 | TG3_JMB_LOOPBACK_FAILED | \ |
| 12636 | TG3_TSO_LOOPBACK_FAILED) |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 12637 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12638 | 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] | 12639 | { |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12640 | int err = -EIO; |
Matt Carlson | 2215e24 | 2011-08-19 13:58:19 +0000 | [diff] [blame] | 12641 | u32 eee_cap; |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12642 | u32 jmb_pkt_sz = 9000; |
| 12643 | |
| 12644 | if (tp->dma_limit) |
| 12645 | jmb_pkt_sz = tp->dma_limit - ETH_HLEN; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12646 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 12647 | eee_cap = tp->phy_flags & TG3_PHYFLG_EEE_CAP; |
| 12648 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; |
| 12649 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12650 | if (!netif_running(tp->dev)) { |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12651 | data[TG3_MAC_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 12652 | data[TG3_PHY_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12653 | if (do_extlpbk) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12654 | data[TG3_EXT_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12655 | goto done; |
| 12656 | } |
| 12657 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 12658 | err = tg3_reset_hw(tp, 1); |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 12659 | if (err) { |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12660 | data[TG3_MAC_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 12661 | data[TG3_PHY_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12662 | if (do_extlpbk) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12663 | data[TG3_EXT_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 12664 | goto done; |
| 12665 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12666 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12667 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 4a85f09 | 2011-04-20 07:57:37 +0000 | [diff] [blame] | 12668 | int i; |
| 12669 | |
| 12670 | /* Reroute all rx packets to the 1st queue */ |
| 12671 | for (i = MAC_RSS_INDIR_TBL_0; |
| 12672 | i < MAC_RSS_INDIR_TBL_0 + TG3_RSS_INDIR_TBL_SIZE; i += 4) |
| 12673 | tw32(i, 0x0); |
| 12674 | } |
| 12675 | |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 12676 | /* HW errata - mac loopback fails in some cases on 5780. |
| 12677 | * Normal traffic and PHY loopback are not affected by |
| 12678 | * errata. Also, the MAC loopback test is deprecated for |
| 12679 | * all newer ASIC revisions. |
| 12680 | */ |
| 12681 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && |
| 12682 | !tg3_flag(tp, CPMU_PRESENT)) { |
| 12683 | tg3_mac_loopback(tp, true); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 12684 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12685 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12686 | data[TG3_MAC_LOOPB_TEST] |= TG3_STD_LOOPBACK_FAILED; |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 12687 | |
| 12688 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12689 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12690 | data[TG3_MAC_LOOPB_TEST] |= TG3_JMB_LOOPBACK_FAILED; |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 12691 | |
| 12692 | tg3_mac_loopback(tp, false); |
| 12693 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 12694 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12695 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12696 | !tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12697 | int i; |
| 12698 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12699 | tg3_phy_lpbk_set(tp, 0, false); |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12700 | |
| 12701 | /* Wait for link */ |
| 12702 | for (i = 0; i < 100; i++) { |
| 12703 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 12704 | break; |
| 12705 | mdelay(1); |
| 12706 | } |
| 12707 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12708 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12709 | data[TG3_PHY_LOOPB_TEST] |= TG3_STD_LOOPBACK_FAILED; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12710 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12711 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12712 | data[TG3_PHY_LOOPB_TEST] |= TG3_TSO_LOOPBACK_FAILED; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12713 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12714 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12715 | data[TG3_PHY_LOOPB_TEST] |= TG3_JMB_LOOPBACK_FAILED; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12716 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12717 | if (do_extlpbk) { |
| 12718 | tg3_phy_lpbk_set(tp, 0, true); |
| 12719 | |
| 12720 | /* All link indications report up, but the hardware |
| 12721 | * isn't really ready for about 20 msec. Double it |
| 12722 | * to be sure. |
| 12723 | */ |
| 12724 | mdelay(40); |
| 12725 | |
| 12726 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12727 | data[TG3_EXT_LOOPB_TEST] |= |
| 12728 | TG3_STD_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12729 | if (tg3_flag(tp, TSO_CAPABLE) && |
| 12730 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12731 | data[TG3_EXT_LOOPB_TEST] |= |
| 12732 | TG3_TSO_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12733 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 12734 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12735 | data[TG3_EXT_LOOPB_TEST] |= |
| 12736 | TG3_JMB_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12737 | } |
| 12738 | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12739 | /* Re-enable gphy autopowerdown. */ |
| 12740 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
| 12741 | tg3_phy_toggle_apd(tp, true); |
| 12742 | } |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12743 | |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12744 | err = (data[TG3_MAC_LOOPB_TEST] | data[TG3_PHY_LOOPB_TEST] | |
| 12745 | data[TG3_EXT_LOOPB_TEST]) ? -EIO : 0; |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12746 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 12747 | done: |
| 12748 | tp->phy_flags |= eee_cap; |
| 12749 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12750 | return err; |
| 12751 | } |
| 12752 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12753 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
| 12754 | u64 *data) |
| 12755 | { |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12756 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12757 | bool doextlpbk = etest->flags & ETH_TEST_FL_EXTERNAL_LB; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12758 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 12759 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
| 12760 | tg3_power_up(tp)) { |
| 12761 | etest->flags |= ETH_TEST_FL_FAILED; |
| 12762 | memset(data, 1, sizeof(u64) * TG3_NUM_TEST); |
| 12763 | return; |
| 12764 | } |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12765 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12766 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
| 12767 | |
| 12768 | if (tg3_test_nvram(tp) != 0) { |
| 12769 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12770 | data[TG3_NVRAM_TEST] = 1; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12771 | } |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12772 | if (!doextlpbk && tg3_test_link(tp)) { |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12773 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12774 | data[TG3_LINK_TEST] = 1; |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12775 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12776 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12777 | int err, err2 = 0, irq_sync = 0; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12778 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12779 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12780 | tg3_phy_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12781 | tg3_netif_stop(tp); |
| 12782 | irq_sync = 1; |
| 12783 | } |
| 12784 | |
| 12785 | tg3_full_lock(tp, irq_sync); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12786 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12787 | err = tg3_nvram_lock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12788 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12789 | if (!tg3_flag(tp, 5705_PLUS)) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12790 | tg3_halt_cpu(tp, TX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12791 | if (!err) |
| 12792 | tg3_nvram_unlock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12793 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12794 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 12795 | tg3_phy_reset(tp); |
| 12796 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12797 | if (tg3_test_registers(tp) != 0) { |
| 12798 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12799 | data[TG3_REGISTER_TEST] = 1; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12800 | } |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12801 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12802 | if (tg3_test_memory(tp) != 0) { |
| 12803 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12804 | data[TG3_MEMORY_TEST] = 1; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12805 | } |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12806 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 12807 | if (doextlpbk) |
| 12808 | etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; |
| 12809 | |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12810 | if (tg3_test_loopback(tp, data, doextlpbk)) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12811 | etest->flags |= ETH_TEST_FL_FAILED; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12812 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12813 | tg3_full_unlock(tp); |
| 12814 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12815 | if (tg3_test_interrupt(tp) != 0) { |
| 12816 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 12817 | data[TG3_INTERRUPT_TEST] = 1; |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12818 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12819 | |
| 12820 | tg3_full_lock(tp, 0); |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 12821 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12822 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 12823 | if (netif_running(dev)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12824 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12825 | err2 = tg3_restart_hw(tp, 1); |
| 12826 | if (!err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 12827 | tg3_netif_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12828 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12829 | |
| 12830 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12831 | |
| 12832 | if (irq_sync && !err2) |
| 12833 | tg3_phy_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12834 | } |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 12835 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 12836 | tg3_power_down(tp); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12837 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12838 | } |
| 12839 | |
Matt Carlson | 0a633ac | 2012-12-03 19:36:59 +0000 | [diff] [blame] | 12840 | static int tg3_hwtstamp_ioctl(struct net_device *dev, |
| 12841 | struct ifreq *ifr, int cmd) |
| 12842 | { |
| 12843 | struct tg3 *tp = netdev_priv(dev); |
| 12844 | struct hwtstamp_config stmpconf; |
| 12845 | |
| 12846 | if (!tg3_flag(tp, PTP_CAPABLE)) |
| 12847 | return -EINVAL; |
| 12848 | |
| 12849 | if (copy_from_user(&stmpconf, ifr->ifr_data, sizeof(stmpconf))) |
| 12850 | return -EFAULT; |
| 12851 | |
| 12852 | if (stmpconf.flags) |
| 12853 | return -EINVAL; |
| 12854 | |
| 12855 | switch (stmpconf.tx_type) { |
| 12856 | case HWTSTAMP_TX_ON: |
| 12857 | tg3_flag_set(tp, TX_TSTAMP_EN); |
| 12858 | break; |
| 12859 | case HWTSTAMP_TX_OFF: |
| 12860 | tg3_flag_clear(tp, TX_TSTAMP_EN); |
| 12861 | break; |
| 12862 | default: |
| 12863 | return -ERANGE; |
| 12864 | } |
| 12865 | |
| 12866 | switch (stmpconf.rx_filter) { |
| 12867 | case HWTSTAMP_FILTER_NONE: |
| 12868 | tp->rxptpctl = 0; |
| 12869 | break; |
| 12870 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 12871 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | |
| 12872 | TG3_RX_PTP_CTL_ALL_V1_EVENTS; |
| 12873 | break; |
| 12874 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 12875 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | |
| 12876 | TG3_RX_PTP_CTL_SYNC_EVNT; |
| 12877 | break; |
| 12878 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 12879 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | |
| 12880 | TG3_RX_PTP_CTL_DELAY_REQ; |
| 12881 | break; |
| 12882 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 12883 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | |
| 12884 | TG3_RX_PTP_CTL_ALL_V2_EVENTS; |
| 12885 | break; |
| 12886 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 12887 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | |
| 12888 | TG3_RX_PTP_CTL_ALL_V2_EVENTS; |
| 12889 | break; |
| 12890 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 12891 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | |
| 12892 | TG3_RX_PTP_CTL_ALL_V2_EVENTS; |
| 12893 | break; |
| 12894 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 12895 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | |
| 12896 | TG3_RX_PTP_CTL_SYNC_EVNT; |
| 12897 | break; |
| 12898 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 12899 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | |
| 12900 | TG3_RX_PTP_CTL_SYNC_EVNT; |
| 12901 | break; |
| 12902 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 12903 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | |
| 12904 | TG3_RX_PTP_CTL_SYNC_EVNT; |
| 12905 | break; |
| 12906 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 12907 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | |
| 12908 | TG3_RX_PTP_CTL_DELAY_REQ; |
| 12909 | break; |
| 12910 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 12911 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | |
| 12912 | TG3_RX_PTP_CTL_DELAY_REQ; |
| 12913 | break; |
| 12914 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 12915 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | |
| 12916 | TG3_RX_PTP_CTL_DELAY_REQ; |
| 12917 | break; |
| 12918 | default: |
| 12919 | return -ERANGE; |
| 12920 | } |
| 12921 | |
| 12922 | if (netif_running(dev) && tp->rxptpctl) |
| 12923 | tw32(TG3_RX_PTP_CTL, |
| 12924 | tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK); |
| 12925 | |
| 12926 | return copy_to_user(ifr->ifr_data, &stmpconf, sizeof(stmpconf)) ? |
| 12927 | -EFAULT : 0; |
| 12928 | } |
| 12929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12930 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 12931 | { |
| 12932 | struct mii_ioctl_data *data = if_mii(ifr); |
| 12933 | struct tg3 *tp = netdev_priv(dev); |
| 12934 | int err; |
| 12935 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12936 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 12937 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12938 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12939 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 12940 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 12941 | return phy_mii_ioctl(phydev, ifr, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12942 | } |
| 12943 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 12944 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12945 | case SIOCGMIIPHY: |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 12946 | data->phy_id = tp->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12947 | |
| 12948 | /* fallthru */ |
| 12949 | case SIOCGMIIREG: { |
| 12950 | u32 mii_regval; |
| 12951 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12952 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12953 | break; /* We have no PHY */ |
| 12954 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 12955 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12956 | return -EAGAIN; |
| 12957 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12958 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12959 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12960 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12961 | |
| 12962 | data->val_out = mii_regval; |
| 12963 | |
| 12964 | return err; |
| 12965 | } |
| 12966 | |
| 12967 | case SIOCSMIIREG: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12968 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12969 | break; /* We have no PHY */ |
| 12970 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 12971 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 12972 | return -EAGAIN; |
| 12973 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12974 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12975 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12976 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12977 | |
| 12978 | return err; |
| 12979 | |
Matt Carlson | 0a633ac | 2012-12-03 19:36:59 +0000 | [diff] [blame] | 12980 | case SIOCSHWTSTAMP: |
| 12981 | return tg3_hwtstamp_ioctl(dev, ifr, cmd); |
| 12982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12983 | default: |
| 12984 | /* do nothing */ |
| 12985 | break; |
| 12986 | } |
| 12987 | return -EOPNOTSUPP; |
| 12988 | } |
| 12989 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 12990 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 12991 | { |
| 12992 | struct tg3 *tp = netdev_priv(dev); |
| 12993 | |
| 12994 | memcpy(ec, &tp->coal, sizeof(*ec)); |
| 12995 | return 0; |
| 12996 | } |
| 12997 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 12998 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 12999 | { |
| 13000 | struct tg3 *tp = netdev_priv(dev); |
| 13001 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; |
| 13002 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; |
| 13003 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13004 | if (!tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 13005 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
| 13006 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; |
| 13007 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; |
| 13008 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; |
| 13009 | } |
| 13010 | |
| 13011 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || |
| 13012 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || |
| 13013 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || |
| 13014 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || |
| 13015 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || |
| 13016 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || |
| 13017 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || |
| 13018 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || |
| 13019 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || |
| 13020 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) |
| 13021 | return -EINVAL; |
| 13022 | |
| 13023 | /* No rx interrupts will be generated if both are zero */ |
| 13024 | if ((ec->rx_coalesce_usecs == 0) && |
| 13025 | (ec->rx_max_coalesced_frames == 0)) |
| 13026 | return -EINVAL; |
| 13027 | |
| 13028 | /* No tx interrupts will be generated if both are zero */ |
| 13029 | if ((ec->tx_coalesce_usecs == 0) && |
| 13030 | (ec->tx_max_coalesced_frames == 0)) |
| 13031 | return -EINVAL; |
| 13032 | |
| 13033 | /* Only copy relevant parameters, ignore all others. */ |
| 13034 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; |
| 13035 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; |
| 13036 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; |
| 13037 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; |
| 13038 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; |
| 13039 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; |
| 13040 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; |
| 13041 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; |
| 13042 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; |
| 13043 | |
| 13044 | if (netif_running(dev)) { |
| 13045 | tg3_full_lock(tp, 0); |
| 13046 | __tg3_set_coalesce(tp, &tp->coal); |
| 13047 | tg3_full_unlock(tp); |
| 13048 | } |
| 13049 | return 0; |
| 13050 | } |
| 13051 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 13052 | static const struct ethtool_ops tg3_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13053 | .get_settings = tg3_get_settings, |
| 13054 | .set_settings = tg3_set_settings, |
| 13055 | .get_drvinfo = tg3_get_drvinfo, |
| 13056 | .get_regs_len = tg3_get_regs_len, |
| 13057 | .get_regs = tg3_get_regs, |
| 13058 | .get_wol = tg3_get_wol, |
| 13059 | .set_wol = tg3_set_wol, |
| 13060 | .get_msglevel = tg3_get_msglevel, |
| 13061 | .set_msglevel = tg3_set_msglevel, |
| 13062 | .nway_reset = tg3_nway_reset, |
| 13063 | .get_link = ethtool_op_get_link, |
| 13064 | .get_eeprom_len = tg3_get_eeprom_len, |
| 13065 | .get_eeprom = tg3_get_eeprom, |
| 13066 | .set_eeprom = tg3_set_eeprom, |
| 13067 | .get_ringparam = tg3_get_ringparam, |
| 13068 | .set_ringparam = tg3_set_ringparam, |
| 13069 | .get_pauseparam = tg3_get_pauseparam, |
| 13070 | .set_pauseparam = tg3_set_pauseparam, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 13071 | .self_test = tg3_self_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13072 | .get_strings = tg3_get_strings, |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 13073 | .set_phys_id = tg3_set_phys_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13074 | .get_ethtool_stats = tg3_get_ethtool_stats, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 13075 | .get_coalesce = tg3_get_coalesce, |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 13076 | .set_coalesce = tg3_set_coalesce, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 13077 | .get_sset_count = tg3_get_sset_count, |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 13078 | .get_rxnfc = tg3_get_rxnfc, |
| 13079 | .get_rxfh_indir_size = tg3_get_rxfh_indir_size, |
| 13080 | .get_rxfh_indir = tg3_get_rxfh_indir, |
| 13081 | .set_rxfh_indir = tg3_set_rxfh_indir, |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 13082 | .get_channels = tg3_get_channels, |
| 13083 | .set_channels = tg3_set_channels, |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 13084 | .get_ts_info = tg3_get_ts_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13085 | }; |
| 13086 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 13087 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
| 13088 | struct rtnl_link_stats64 *stats) |
| 13089 | { |
| 13090 | struct tg3 *tp = netdev_priv(dev); |
| 13091 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 13092 | spin_lock_bh(&tp->lock); |
Michael Chan | 0f566b2 | 2012-07-29 19:15:44 +0000 | [diff] [blame] | 13093 | if (!tp->hw_stats) { |
| 13094 | spin_unlock_bh(&tp->lock); |
| 13095 | return &tp->net_stats_prev; |
| 13096 | } |
| 13097 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 13098 | tg3_get_nstats(tp, stats); |
| 13099 | spin_unlock_bh(&tp->lock); |
| 13100 | |
| 13101 | return stats; |
| 13102 | } |
| 13103 | |
Matt Carlson | ccd5ba9 | 2012-02-13 10:20:08 +0000 | [diff] [blame] | 13104 | static void tg3_set_rx_mode(struct net_device *dev) |
| 13105 | { |
| 13106 | struct tg3 *tp = netdev_priv(dev); |
| 13107 | |
| 13108 | if (!netif_running(dev)) |
| 13109 | return; |
| 13110 | |
| 13111 | tg3_full_lock(tp, 0); |
| 13112 | __tg3_set_rx_mode(dev); |
| 13113 | tg3_full_unlock(tp); |
| 13114 | } |
| 13115 | |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 13116 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
| 13117 | int new_mtu) |
| 13118 | { |
| 13119 | dev->mtu = new_mtu; |
| 13120 | |
| 13121 | if (new_mtu > ETH_DATA_LEN) { |
| 13122 | if (tg3_flag(tp, 5780_CLASS)) { |
| 13123 | netdev_update_features(dev); |
| 13124 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 13125 | } else { |
| 13126 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
| 13127 | } |
| 13128 | } else { |
| 13129 | if (tg3_flag(tp, 5780_CLASS)) { |
| 13130 | tg3_flag_set(tp, TSO_CAPABLE); |
| 13131 | netdev_update_features(dev); |
| 13132 | } |
| 13133 | tg3_flag_clear(tp, JUMBO_RING_ENABLE); |
| 13134 | } |
| 13135 | } |
| 13136 | |
| 13137 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) |
| 13138 | { |
| 13139 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 2fae5e3 | 2012-03-04 14:48:15 +0000 | [diff] [blame] | 13140 | int err, reset_phy = 0; |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 13141 | |
| 13142 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) |
| 13143 | return -EINVAL; |
| 13144 | |
| 13145 | if (!netif_running(dev)) { |
| 13146 | /* We'll just catch it later when the |
| 13147 | * device is up'd. |
| 13148 | */ |
| 13149 | tg3_set_mtu(dev, tp, new_mtu); |
| 13150 | return 0; |
| 13151 | } |
| 13152 | |
| 13153 | tg3_phy_stop(tp); |
| 13154 | |
| 13155 | tg3_netif_stop(tp); |
| 13156 | |
| 13157 | tg3_full_lock(tp, 1); |
| 13158 | |
| 13159 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 13160 | |
| 13161 | tg3_set_mtu(dev, tp, new_mtu); |
| 13162 | |
Michael Chan | 2fae5e3 | 2012-03-04 14:48:15 +0000 | [diff] [blame] | 13163 | /* Reset PHY, otherwise the read DMA engine will be in a mode that |
| 13164 | * breaks all requests to 256 bytes. |
| 13165 | */ |
| 13166 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) |
| 13167 | reset_phy = 1; |
| 13168 | |
| 13169 | err = tg3_restart_hw(tp, reset_phy); |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 13170 | |
| 13171 | if (!err) |
| 13172 | tg3_netif_start(tp); |
| 13173 | |
| 13174 | tg3_full_unlock(tp); |
| 13175 | |
| 13176 | if (!err) |
| 13177 | tg3_phy_start(tp); |
| 13178 | |
| 13179 | return err; |
| 13180 | } |
| 13181 | |
| 13182 | static const struct net_device_ops tg3_netdev_ops = { |
| 13183 | .ndo_open = tg3_open, |
| 13184 | .ndo_stop = tg3_close, |
| 13185 | .ndo_start_xmit = tg3_start_xmit, |
| 13186 | .ndo_get_stats64 = tg3_get_stats64, |
| 13187 | .ndo_validate_addr = eth_validate_addr, |
| 13188 | .ndo_set_rx_mode = tg3_set_rx_mode, |
| 13189 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 13190 | .ndo_do_ioctl = tg3_ioctl, |
| 13191 | .ndo_tx_timeout = tg3_tx_timeout, |
| 13192 | .ndo_change_mtu = tg3_change_mtu, |
| 13193 | .ndo_fix_features = tg3_fix_features, |
| 13194 | .ndo_set_features = tg3_set_features, |
| 13195 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 13196 | .ndo_poll_controller = tg3_poll_controller, |
| 13197 | #endif |
| 13198 | }; |
| 13199 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13200 | static void tg3_get_eeprom_size(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13201 | { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13202 | u32 cursize, val, magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13203 | |
| 13204 | tp->nvram_size = EEPROM_CHIP_SIZE; |
| 13205 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13206 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13207 | return; |
| 13208 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 13209 | if ((magic != TG3_EEPROM_MAGIC) && |
| 13210 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && |
| 13211 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13212 | return; |
| 13213 | |
| 13214 | /* |
| 13215 | * Size the chip by reading offsets at increasing powers of two. |
| 13216 | * When we encounter our validation signature, we know the addressing |
| 13217 | * has wrapped around, and thus have our chip size. |
| 13218 | */ |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13219 | cursize = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13220 | |
| 13221 | while (cursize < tp->nvram_size) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13222 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13223 | return; |
| 13224 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 13225 | if (val == magic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13226 | break; |
| 13227 | |
| 13228 | cursize <<= 1; |
| 13229 | } |
| 13230 | |
| 13231 | tp->nvram_size = cursize; |
| 13232 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13233 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13234 | static void tg3_get_nvram_size(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13235 | { |
| 13236 | u32 val; |
| 13237 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13238 | 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] | 13239 | return; |
| 13240 | |
| 13241 | /* Selfboot format */ |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 13242 | if (val != TG3_EEPROM_MAGIC) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13243 | tg3_get_eeprom_size(tp); |
| 13244 | return; |
| 13245 | } |
| 13246 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 13247 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13248 | if (val != 0) { |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 13249 | /* This is confusing. We want to operate on the |
| 13250 | * 16-bit value at offset 0xf2. The tg3_nvram_read() |
| 13251 | * call will read from NVRAM and byteswap the data |
| 13252 | * according to the byteswapping settings for all |
| 13253 | * other register accesses. This ensures the data we |
| 13254 | * want will always reside in the lower 16-bits. |
| 13255 | * However, the data in NVRAM is in LE format, which |
| 13256 | * means the data from the NVRAM read will always be |
| 13257 | * opposite the endianness of the CPU. The 16-bit |
| 13258 | * byteswap then brings the data to CPU endianness. |
| 13259 | */ |
| 13260 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13261 | return; |
| 13262 | } |
| 13263 | } |
Matt Carlson | fd1122a | 2008-05-02 16:48:36 -0700 | [diff] [blame] | 13264 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13265 | } |
| 13266 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13267 | static void tg3_get_nvram_info(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13268 | { |
| 13269 | u32 nvcfg1; |
| 13270 | |
| 13271 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13272 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13273 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13274 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13275 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13276 | tw32(NVRAM_CFG1, nvcfg1); |
| 13277 | } |
| 13278 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 13279 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13280 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13281 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13282 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
| 13283 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 13284 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13285 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13286 | break; |
| 13287 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: |
| 13288 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 13289 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; |
| 13290 | break; |
| 13291 | case FLASH_VENDOR_ATMEL_EEPROM: |
| 13292 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 13293 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13294 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13295 | break; |
| 13296 | case FLASH_VENDOR_ST: |
| 13297 | tp->nvram_jedecnum = JEDEC_ST; |
| 13298 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13299 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13300 | break; |
| 13301 | case FLASH_VENDOR_SAIFUN: |
| 13302 | tp->nvram_jedecnum = JEDEC_SAIFUN; |
| 13303 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; |
| 13304 | break; |
| 13305 | case FLASH_VENDOR_SST_SMALL: |
| 13306 | case FLASH_VENDOR_SST_LARGE: |
| 13307 | tp->nvram_jedecnum = JEDEC_SST; |
| 13308 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; |
| 13309 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13310 | } |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13311 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13312 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 13313 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13314 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13315 | } |
| 13316 | } |
| 13317 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13318 | static void tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13319 | { |
| 13320 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { |
| 13321 | case FLASH_5752PAGE_SIZE_256: |
| 13322 | tp->nvram_pagesize = 256; |
| 13323 | break; |
| 13324 | case FLASH_5752PAGE_SIZE_512: |
| 13325 | tp->nvram_pagesize = 512; |
| 13326 | break; |
| 13327 | case FLASH_5752PAGE_SIZE_1K: |
| 13328 | tp->nvram_pagesize = 1024; |
| 13329 | break; |
| 13330 | case FLASH_5752PAGE_SIZE_2K: |
| 13331 | tp->nvram_pagesize = 2048; |
| 13332 | break; |
| 13333 | case FLASH_5752PAGE_SIZE_4K: |
| 13334 | tp->nvram_pagesize = 4096; |
| 13335 | break; |
| 13336 | case FLASH_5752PAGE_SIZE_264: |
| 13337 | tp->nvram_pagesize = 264; |
| 13338 | break; |
| 13339 | case FLASH_5752PAGE_SIZE_528: |
| 13340 | tp->nvram_pagesize = 528; |
| 13341 | break; |
| 13342 | } |
| 13343 | } |
| 13344 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13345 | static void tg3_get_5752_nvram_info(struct tg3 *tp) |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13346 | { |
| 13347 | u32 nvcfg1; |
| 13348 | |
| 13349 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13350 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13351 | /* NVRAM protection for TPM */ |
| 13352 | if (nvcfg1 & (1 << 27)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13353 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13354 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13355 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13356 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
| 13357 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: |
| 13358 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13359 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13360 | break; |
| 13361 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 13362 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13363 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13364 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13365 | break; |
| 13366 | case FLASH_5752VENDOR_ST_M45PE10: |
| 13367 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13368 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13369 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13370 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13371 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13372 | break; |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13373 | } |
| 13374 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13375 | if (tg3_flag(tp, FLASH)) { |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13376 | tg3_nvram_get_pagesize(tp, nvcfg1); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13377 | } else { |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13378 | /* For eeprom, set pagesize to maximum eeprom size */ |
| 13379 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 13380 | |
| 13381 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13382 | tw32(NVRAM_CFG1, nvcfg1); |
| 13383 | } |
| 13384 | } |
| 13385 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13386 | static void tg3_get_5755_nvram_info(struct tg3 *tp) |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13387 | { |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13388 | u32 nvcfg1, protect = 0; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13389 | |
| 13390 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13391 | |
| 13392 | /* NVRAM protection for TPM */ |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13393 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13394 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13395 | protect = 1; |
| 13396 | } |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13397 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13398 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 13399 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13400 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 13401 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 13402 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 13403 | case FLASH_5755VENDOR_ATMEL_FLASH_5: |
| 13404 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13405 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13406 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13407 | tp->nvram_pagesize = 264; |
| 13408 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || |
| 13409 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) |
| 13410 | tp->nvram_size = (protect ? 0x3e200 : |
| 13411 | TG3_NVRAM_SIZE_512KB); |
| 13412 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) |
| 13413 | tp->nvram_size = (protect ? 0x1f200 : |
| 13414 | TG3_NVRAM_SIZE_256KB); |
| 13415 | else |
| 13416 | tp->nvram_size = (protect ? 0x1f200 : |
| 13417 | TG3_NVRAM_SIZE_128KB); |
| 13418 | break; |
| 13419 | case FLASH_5752VENDOR_ST_M45PE10: |
| 13420 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13421 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13422 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13423 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13424 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13425 | tp->nvram_pagesize = 256; |
| 13426 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) |
| 13427 | tp->nvram_size = (protect ? |
| 13428 | TG3_NVRAM_SIZE_64KB : |
| 13429 | TG3_NVRAM_SIZE_128KB); |
| 13430 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) |
| 13431 | tp->nvram_size = (protect ? |
| 13432 | TG3_NVRAM_SIZE_64KB : |
| 13433 | TG3_NVRAM_SIZE_256KB); |
| 13434 | else |
| 13435 | tp->nvram_size = (protect ? |
| 13436 | TG3_NVRAM_SIZE_128KB : |
| 13437 | TG3_NVRAM_SIZE_512KB); |
| 13438 | break; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13439 | } |
| 13440 | } |
| 13441 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13442 | static void tg3_get_5787_nvram_info(struct tg3 *tp) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13443 | { |
| 13444 | u32 nvcfg1; |
| 13445 | |
| 13446 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13447 | |
| 13448 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13449 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
| 13450 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 13451 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: |
| 13452 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 13453 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13454 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13455 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13456 | |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13457 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13458 | tw32(NVRAM_CFG1, nvcfg1); |
| 13459 | break; |
| 13460 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 13461 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 13462 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 13463 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 13464 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13465 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13466 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13467 | tp->nvram_pagesize = 264; |
| 13468 | break; |
| 13469 | case FLASH_5752VENDOR_ST_M45PE10: |
| 13470 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13471 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13472 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13473 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13474 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13475 | tp->nvram_pagesize = 256; |
| 13476 | break; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13477 | } |
| 13478 | } |
| 13479 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13480 | static void tg3_get_5761_nvram_info(struct tg3 *tp) |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13481 | { |
| 13482 | u32 nvcfg1, protect = 0; |
| 13483 | |
| 13484 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13485 | |
| 13486 | /* NVRAM protection for TPM */ |
| 13487 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13488 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13489 | protect = 1; |
| 13490 | } |
| 13491 | |
| 13492 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 13493 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13494 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 13495 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 13496 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 13497 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 13498 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 13499 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 13500 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 13501 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 13502 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13503 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13504 | tg3_flag_set(tp, FLASH); |
| 13505 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13506 | tp->nvram_pagesize = 256; |
| 13507 | break; |
| 13508 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 13509 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 13510 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 13511 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 13512 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 13513 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 13514 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 13515 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 13516 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13517 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13518 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13519 | tp->nvram_pagesize = 256; |
| 13520 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13521 | } |
| 13522 | |
| 13523 | if (protect) { |
| 13524 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); |
| 13525 | } else { |
| 13526 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13527 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 13528 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 13529 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 13530 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 13531 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; |
| 13532 | break; |
| 13533 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 13534 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 13535 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 13536 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 13537 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 13538 | break; |
| 13539 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 13540 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 13541 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 13542 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 13543 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13544 | break; |
| 13545 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 13546 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 13547 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 13548 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 13549 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13550 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13551 | } |
| 13552 | } |
| 13553 | } |
| 13554 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13555 | static void tg3_get_5906_nvram_info(struct tg3 *tp) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13556 | { |
| 13557 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13558 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13559 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 13560 | } |
| 13561 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13562 | static void tg3_get_57780_nvram_info(struct tg3 *tp) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13563 | { |
| 13564 | u32 nvcfg1; |
| 13565 | |
| 13566 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13567 | |
| 13568 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13569 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 13570 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 13571 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13572 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13573 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 13574 | |
| 13575 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13576 | tw32(NVRAM_CFG1, nvcfg1); |
| 13577 | return; |
| 13578 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 13579 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 13580 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 13581 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 13582 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 13583 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 13584 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 13585 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13586 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13587 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13588 | |
| 13589 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13590 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 13591 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 13592 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 13593 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13594 | break; |
| 13595 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 13596 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 13597 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13598 | break; |
| 13599 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 13600 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 13601 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13602 | break; |
| 13603 | } |
| 13604 | break; |
| 13605 | case FLASH_5752VENDOR_ST_M45PE10: |
| 13606 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13607 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13608 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13609 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13610 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13611 | |
| 13612 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13613 | case FLASH_5752VENDOR_ST_M45PE10: |
| 13614 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13615 | break; |
| 13616 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13617 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13618 | break; |
| 13619 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13620 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13621 | break; |
| 13622 | } |
| 13623 | break; |
| 13624 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13625 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13626 | return; |
| 13627 | } |
| 13628 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13629 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 13630 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13631 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13632 | } |
| 13633 | |
| 13634 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13635 | static void tg3_get_5717_nvram_info(struct tg3 *tp) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13636 | { |
| 13637 | u32 nvcfg1; |
| 13638 | |
| 13639 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13640 | |
| 13641 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13642 | case FLASH_5717VENDOR_ATMEL_EEPROM: |
| 13643 | case FLASH_5717VENDOR_MICRO_EEPROM: |
| 13644 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13645 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13646 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 13647 | |
| 13648 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13649 | tw32(NVRAM_CFG1, nvcfg1); |
| 13650 | return; |
| 13651 | case FLASH_5717VENDOR_ATMEL_MDB011D: |
| 13652 | case FLASH_5717VENDOR_ATMEL_ADB011B: |
| 13653 | case FLASH_5717VENDOR_ATMEL_ADB011D: |
| 13654 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 13655 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 13656 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 13657 | case FLASH_5717VENDOR_ATMEL_45USPT: |
| 13658 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13659 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13660 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13661 | |
| 13662 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13663 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 13664 | /* Detect size with tg3_nvram_get_size() */ |
| 13665 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13666 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 13667 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 13668 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13669 | break; |
| 13670 | default: |
| 13671 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13672 | break; |
| 13673 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13674 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13675 | case FLASH_5717VENDOR_ST_M_M25PE10: |
| 13676 | case FLASH_5717VENDOR_ST_A_M25PE10: |
| 13677 | case FLASH_5717VENDOR_ST_M_M45PE10: |
| 13678 | case FLASH_5717VENDOR_ST_A_M45PE10: |
| 13679 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 13680 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 13681 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 13682 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 13683 | case FLASH_5717VENDOR_ST_25USPT: |
| 13684 | case FLASH_5717VENDOR_ST_45USPT: |
| 13685 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13686 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13687 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13688 | |
| 13689 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 13690 | case FLASH_5717VENDOR_ST_M_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13691 | case FLASH_5717VENDOR_ST_M_M45PE20: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 13692 | /* Detect size with tg3_nvram_get_size() */ |
| 13693 | break; |
| 13694 | case FLASH_5717VENDOR_ST_A_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13695 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 13696 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13697 | break; |
| 13698 | default: |
| 13699 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13700 | break; |
| 13701 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13702 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13703 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13704 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13705 | return; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13706 | } |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13707 | |
| 13708 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 13709 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13710 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13711 | } |
| 13712 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13713 | static void tg3_get_5720_nvram_info(struct tg3 *tp) |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13714 | { |
| 13715 | u32 nvcfg1, nvmpinstrp; |
| 13716 | |
| 13717 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13718 | nvmpinstrp = nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK; |
| 13719 | |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 13720 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) { |
| 13721 | if (!(nvcfg1 & NVRAM_CFG1_5762VENDOR_MASK)) { |
| 13722 | tg3_flag_set(tp, NO_NVRAM); |
| 13723 | return; |
| 13724 | } |
| 13725 | |
| 13726 | switch (nvmpinstrp) { |
| 13727 | case FLASH_5762_EEPROM_HD: |
| 13728 | nvmpinstrp = FLASH_5720_EEPROM_HD; |
Dan Carpenter | 17e1a42 | 2013-01-11 09:57:33 +0300 | [diff] [blame] | 13729 | break; |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 13730 | case FLASH_5762_EEPROM_LD: |
| 13731 | nvmpinstrp = FLASH_5720_EEPROM_LD; |
Dan Carpenter | 17e1a42 | 2013-01-11 09:57:33 +0300 | [diff] [blame] | 13732 | break; |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 13733 | } |
| 13734 | } |
| 13735 | |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13736 | switch (nvmpinstrp) { |
| 13737 | case FLASH_5720_EEPROM_HD: |
| 13738 | case FLASH_5720_EEPROM_LD: |
| 13739 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13740 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13741 | |
| 13742 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13743 | tw32(NVRAM_CFG1, nvcfg1); |
| 13744 | if (nvmpinstrp == FLASH_5720_EEPROM_HD) |
| 13745 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 13746 | else |
| 13747 | tp->nvram_pagesize = ATMEL_AT24C02_CHIP_SIZE; |
| 13748 | return; |
| 13749 | case FLASH_5720VENDOR_M_ATMEL_DB011D: |
| 13750 | case FLASH_5720VENDOR_A_ATMEL_DB011B: |
| 13751 | case FLASH_5720VENDOR_A_ATMEL_DB011D: |
| 13752 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 13753 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 13754 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 13755 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 13756 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 13757 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 13758 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 13759 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 13760 | case FLASH_5720VENDOR_ATMEL_45USPT: |
| 13761 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13762 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13763 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13764 | |
| 13765 | switch (nvmpinstrp) { |
| 13766 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 13767 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 13768 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 13769 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13770 | break; |
| 13771 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 13772 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 13773 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 13774 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13775 | break; |
| 13776 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 13777 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 13778 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 13779 | break; |
| 13780 | default: |
| 13781 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13782 | break; |
| 13783 | } |
| 13784 | break; |
| 13785 | case FLASH_5720VENDOR_M_ST_M25PE10: |
| 13786 | case FLASH_5720VENDOR_M_ST_M45PE10: |
| 13787 | case FLASH_5720VENDOR_A_ST_M25PE10: |
| 13788 | case FLASH_5720VENDOR_A_ST_M45PE10: |
| 13789 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 13790 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 13791 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 13792 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 13793 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 13794 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 13795 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 13796 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 13797 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 13798 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 13799 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 13800 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 13801 | case FLASH_5720VENDOR_ST_25USPT: |
| 13802 | case FLASH_5720VENDOR_ST_45USPT: |
| 13803 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13804 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13805 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13806 | |
| 13807 | switch (nvmpinstrp) { |
| 13808 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 13809 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 13810 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 13811 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 13812 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 13813 | break; |
| 13814 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 13815 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 13816 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 13817 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 13818 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 13819 | break; |
| 13820 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 13821 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 13822 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 13823 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 13824 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 13825 | break; |
| 13826 | default: |
| 13827 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 13828 | break; |
| 13829 | } |
| 13830 | break; |
| 13831 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13832 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13833 | return; |
| 13834 | } |
| 13835 | |
| 13836 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 13837 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13838 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 13839 | |
| 13840 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) { |
| 13841 | u32 val; |
| 13842 | |
| 13843 | if (tg3_nvram_read(tp, 0, &val)) |
| 13844 | return; |
| 13845 | |
| 13846 | if (val != TG3_EEPROM_MAGIC && |
| 13847 | (val & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) |
| 13848 | tg3_flag_set(tp, NO_NVRAM); |
| 13849 | } |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13850 | } |
| 13851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13852 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13853 | static void tg3_nvram_init(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13854 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13855 | tw32_f(GRC_EEPROM_ADDR, |
| 13856 | (EEPROM_ADDR_FSM_RESET | |
| 13857 | (EEPROM_DEFAULT_CLOCK_PERIOD << |
| 13858 | EEPROM_ADDR_CLKPERD_SHIFT))); |
| 13859 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 13860 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13861 | |
| 13862 | /* Enable seeprom accesses. */ |
| 13863 | tw32_f(GRC_LOCAL_CTRL, |
| 13864 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); |
| 13865 | udelay(100); |
| 13866 | |
| 13867 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13868 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13869 | tg3_flag_set(tp, NVRAM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13870 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 13871 | if (tg3_nvram_lock(tp)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 13872 | netdev_warn(tp->dev, |
| 13873 | "Cannot get nvram lock, %s failed\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 13874 | __func__); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 13875 | return; |
| 13876 | } |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13877 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13878 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13879 | tp->nvram_size = 0; |
| 13880 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13881 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 13882 | tg3_get_5752_nvram_info(tp); |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 13883 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 13884 | tg3_get_5755_nvram_info(tp); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13885 | 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] | 13886 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 13887 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13888 | tg3_get_5787_nvram_info(tp); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 13889 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 13890 | tg3_get_5761_nvram_info(tp); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13891 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 13892 | tg3_get_5906_nvram_info(tp); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13893 | 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] | 13894 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13895 | tg3_get_57780_nvram_info(tp); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13896 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13897 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13898 | tg3_get_5717_nvram_info(tp); |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 13899 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 13900 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 13901 | tg3_get_5720_nvram_info(tp); |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13902 | else |
| 13903 | tg3_get_nvram_info(tp); |
| 13904 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 13905 | if (tp->nvram_size == 0) |
| 13906 | tg3_get_nvram_size(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13907 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13908 | tg3_disable_nvram_access(tp); |
Michael Chan | 381291b | 2005-12-13 21:08:21 -0800 | [diff] [blame] | 13909 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13910 | |
| 13911 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13912 | tg3_flag_clear(tp, NVRAM); |
| 13913 | tg3_flag_clear(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13914 | |
| 13915 | tg3_get_eeprom_size(tp); |
| 13916 | } |
| 13917 | } |
| 13918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13919 | struct subsys_tbl_ent { |
| 13920 | u16 subsys_vendor, subsys_devid; |
| 13921 | u32 phy_id; |
| 13922 | }; |
| 13923 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13924 | static struct subsys_tbl_ent subsys_id_to_phy_id[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13925 | /* Broadcom boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13926 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13927 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13928 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13929 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13930 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13931 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13932 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 13933 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, |
| 13934 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13935 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13936 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13937 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13938 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 13939 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, |
| 13940 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13941 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13942 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13943 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13944 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13945 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13946 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13947 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13948 | |
| 13949 | /* 3com boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13950 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13951 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13952 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13953 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13954 | { TG3PCI_SUBVENDOR_ID_3COM, |
| 13955 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, |
| 13956 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13957 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13958 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13959 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13960 | |
| 13961 | /* DELL boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13962 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13963 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13964 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13965 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13966 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13967 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13968 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13969 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13970 | |
| 13971 | /* Compaq boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13972 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13973 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13974 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13975 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13976 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 13977 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, |
| 13978 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13979 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13980 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 13981 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13982 | |
| 13983 | /* IBM boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 13984 | { TG3PCI_SUBVENDOR_ID_IBM, |
| 13985 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13986 | }; |
| 13987 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13988 | static struct subsys_tbl_ent *tg3_lookup_by_subsys(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13989 | { |
| 13990 | int i; |
| 13991 | |
| 13992 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { |
| 13993 | if ((subsys_id_to_phy_id[i].subsys_vendor == |
| 13994 | tp->pdev->subsystem_vendor) && |
| 13995 | (subsys_id_to_phy_id[i].subsys_devid == |
| 13996 | tp->pdev->subsystem_device)) |
| 13997 | return &subsys_id_to_phy_id[i]; |
| 13998 | } |
| 13999 | return NULL; |
| 14000 | } |
| 14001 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14002 | static void tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
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 | u32 val; |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 14005 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14006 | tp->phy_id = TG3_PHY_ID_INVALID; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14007 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 14008 | |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 14009 | /* Assume an onboard device and WOL capable by default. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14010 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
| 14011 | tg3_flag_set(tp, WOL_CAP); |
David S. Miller | 72b845e | 2006-03-14 14:11:48 -0800 | [diff] [blame] | 14012 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14013 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14014 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14015 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 14016 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14017 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 14018 | val = tr32(VCPU_CFGSHDW); |
| 14019 | if (val & VCPU_CFGSHDW_ASPM_DBNC) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14020 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 14021 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 14022 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14023 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 14024 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 14025 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 14026 | goto done; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14027 | } |
| 14028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14029 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 14030 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 14031 | u32 nic_cfg, led_cfg; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 14032 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14033 | int eeprom_phy_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14034 | |
| 14035 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 14036 | tp->nic_sram_data_cfg = nic_cfg; |
| 14037 | |
| 14038 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); |
| 14039 | ver >>= NIC_SRAM_DATA_VER_SHIFT; |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 14040 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14041 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 14042 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14043 | (ver > 0) && (ver < 0x100)) |
| 14044 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); |
| 14045 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 14046 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 14047 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
| 14048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14049 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
| 14050 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) |
| 14051 | eeprom_phy_serdes = 1; |
| 14052 | |
| 14053 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); |
| 14054 | if (nic_phy_id != 0) { |
| 14055 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; |
| 14056 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; |
| 14057 | |
| 14058 | eeprom_phy_id = (id1 >> 16) << 10; |
| 14059 | eeprom_phy_id |= (id2 & 0xfc00) << 16; |
| 14060 | eeprom_phy_id |= (id2 & 0x03ff) << 0; |
| 14061 | } else |
| 14062 | eeprom_phy_id = 0; |
| 14063 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14064 | tp->phy_id = eeprom_phy_id; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 14065 | if (eeprom_phy_serdes) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14066 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14067 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 14068 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14069 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 14070 | } |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14071 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14072 | if (tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14073 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
| 14074 | SHASTA_EXT_LED_MODE_MASK); |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 14075 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14076 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
| 14077 | |
| 14078 | switch (led_cfg) { |
| 14079 | default: |
| 14080 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: |
| 14081 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 14082 | break; |
| 14083 | |
| 14084 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: |
| 14085 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 14086 | break; |
| 14087 | |
| 14088 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: |
| 14089 | tp->led_ctrl = LED_CTRL_MODE_MAC; |
Michael Chan | 9ba2779 | 2005-06-06 15:16:20 -0700 | [diff] [blame] | 14090 | |
| 14091 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is |
| 14092 | * read on some older 5700/5701 bootcode. |
| 14093 | */ |
| 14094 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 14095 | ASIC_REV_5700 || |
| 14096 | GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 14097 | ASIC_REV_5701) |
| 14098 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 14099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14100 | break; |
| 14101 | |
| 14102 | case SHASTA_EXT_LED_SHARED: |
| 14103 | tp->led_ctrl = LED_CTRL_MODE_SHARED; |
| 14104 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 14105 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) |
| 14106 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 14107 | LED_CTRL_MODE_PHY_2); |
| 14108 | break; |
| 14109 | |
| 14110 | case SHASTA_EXT_LED_MAC: |
| 14111 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; |
| 14112 | break; |
| 14113 | |
| 14114 | case SHASTA_EXT_LED_COMBO: |
| 14115 | tp->led_ctrl = LED_CTRL_MODE_COMBO; |
| 14116 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) |
| 14117 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 14118 | LED_CTRL_MODE_PHY_2); |
| 14119 | break; |
| 14120 | |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14122 | |
| 14123 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 14124 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && |
| 14125 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
| 14126 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 14127 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 14128 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
| 14129 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
Matt Carlson | 5f60891 | 2007-11-12 21:17:07 -0800 | [diff] [blame] | 14130 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14131 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14132 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14133 | if ((tp->pdev->subsystem_vendor == |
| 14134 | PCI_VENDOR_ID_ARIMA) && |
| 14135 | (tp->pdev->subsystem_device == 0x205a || |
| 14136 | tp->pdev->subsystem_device == 0x2063)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14137 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14138 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14139 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 14140 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14141 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14142 | |
| 14143 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14144 | tg3_flag_set(tp, ENABLE_ASF); |
| 14145 | if (tg3_flag(tp, 5750_PLUS)) |
| 14146 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14147 | } |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 14148 | |
| 14149 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14150 | tg3_flag(tp, 5750_PLUS)) |
| 14151 | tg3_flag_set(tp, ENABLE_APE); |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 14152 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14153 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 14154 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14155 | tg3_flag_clear(tp, WOL_CAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14156 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14157 | if (tg3_flag(tp, WOL_CAP) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 14158 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14159 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 14160 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 14161 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 14162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14163 | if (cfg2 & (1 << 17)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14164 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14165 | |
| 14166 | /* serdes signal pre-emphasis in register 0x590 set by */ |
| 14167 | /* bootcode if bit 18 is set */ |
| 14168 | if (cfg2 & (1 << 18)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14169 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 14170 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14171 | if ((tg3_flag(tp, 57765_PLUS) || |
| 14172 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 14173 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) && |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 14174 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14175 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 14176 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14177 | if (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | 8c69b1e | 2010-08-02 11:26:00 +0000 | [diff] [blame] | 14178 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14179 | !tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 14180 | u32 cfg3; |
| 14181 | |
| 14182 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); |
| 14183 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14184 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 14185 | } |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 14186 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 14187 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14188 | tg3_flag_set(tp, RGMII_INBAND_DISABLE); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 14189 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14190 | tg3_flag_set(tp, RGMII_EXT_IBND_RX_EN); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 14191 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14192 | tg3_flag_set(tp, RGMII_EXT_IBND_TX_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14193 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 14194 | done: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14195 | if (tg3_flag(tp, WOL_CAP)) |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 14196 | device_set_wakeup_enable(&tp->pdev->dev, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14197 | tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 14198 | else |
| 14199 | device_set_wakeup_capable(&tp->pdev->dev, false); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14200 | } |
| 14201 | |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 14202 | static int tg3_ape_otp_read(struct tg3 *tp, u32 offset, u32 *val) |
| 14203 | { |
| 14204 | int i, err; |
| 14205 | u32 val2, off = offset * 8; |
| 14206 | |
| 14207 | err = tg3_nvram_lock(tp); |
| 14208 | if (err) |
| 14209 | return err; |
| 14210 | |
| 14211 | tg3_ape_write32(tp, TG3_APE_OTP_ADDR, off | APE_OTP_ADDR_CPU_ENABLE); |
| 14212 | tg3_ape_write32(tp, TG3_APE_OTP_CTRL, APE_OTP_CTRL_PROG_EN | |
| 14213 | APE_OTP_CTRL_CMD_RD | APE_OTP_CTRL_START); |
| 14214 | tg3_ape_read32(tp, TG3_APE_OTP_CTRL); |
| 14215 | udelay(10); |
| 14216 | |
| 14217 | for (i = 0; i < 100; i++) { |
| 14218 | val2 = tg3_ape_read32(tp, TG3_APE_OTP_STATUS); |
| 14219 | if (val2 & APE_OTP_STATUS_CMD_DONE) { |
| 14220 | *val = tg3_ape_read32(tp, TG3_APE_OTP_RD_DATA); |
| 14221 | break; |
| 14222 | } |
| 14223 | udelay(10); |
| 14224 | } |
| 14225 | |
| 14226 | tg3_ape_write32(tp, TG3_APE_OTP_CTRL, 0); |
| 14227 | |
| 14228 | tg3_nvram_unlock(tp); |
| 14229 | if (val2 & APE_OTP_STATUS_CMD_DONE) |
| 14230 | return 0; |
| 14231 | |
| 14232 | return -EBUSY; |
| 14233 | } |
| 14234 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14235 | static int tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 14236 | { |
| 14237 | int i; |
| 14238 | u32 val; |
| 14239 | |
| 14240 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); |
| 14241 | tw32(OTP_CTRL, cmd); |
| 14242 | |
| 14243 | /* Wait for up to 1 ms for command to execute. */ |
| 14244 | for (i = 0; i < 100; i++) { |
| 14245 | val = tr32(OTP_STATUS); |
| 14246 | if (val & OTP_STATUS_CMD_DONE) |
| 14247 | break; |
| 14248 | udelay(10); |
| 14249 | } |
| 14250 | |
| 14251 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; |
| 14252 | } |
| 14253 | |
| 14254 | /* Read the gphy configuration from the OTP region of the chip. The gphy |
| 14255 | * configuration is a 32-bit value that straddles the alignment boundary. |
| 14256 | * We do two 32-bit reads and then shift and merge the results. |
| 14257 | */ |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14258 | static u32 tg3_read_otp_phycfg(struct tg3 *tp) |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 14259 | { |
| 14260 | u32 bhalf_otp, thalf_otp; |
| 14261 | |
| 14262 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); |
| 14263 | |
| 14264 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) |
| 14265 | return 0; |
| 14266 | |
| 14267 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); |
| 14268 | |
| 14269 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 14270 | return 0; |
| 14271 | |
| 14272 | thalf_otp = tr32(OTP_READ_DATA); |
| 14273 | |
| 14274 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); |
| 14275 | |
| 14276 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 14277 | return 0; |
| 14278 | |
| 14279 | bhalf_otp = tr32(OTP_READ_DATA); |
| 14280 | |
| 14281 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); |
| 14282 | } |
| 14283 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14284 | static void tg3_phy_init_link_config(struct tg3 *tp) |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14285 | { |
Hiroaki SHIMODA | 202ff1c | 2011-11-22 04:05:41 +0000 | [diff] [blame] | 14286 | u32 adv = ADVERTISED_Autoneg; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14287 | |
| 14288 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
| 14289 | adv |= ADVERTISED_1000baseT_Half | |
| 14290 | ADVERTISED_1000baseT_Full; |
| 14291 | |
| 14292 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 14293 | adv |= ADVERTISED_100baseT_Half | |
| 14294 | ADVERTISED_100baseT_Full | |
| 14295 | ADVERTISED_10baseT_Half | |
| 14296 | ADVERTISED_10baseT_Full | |
| 14297 | ADVERTISED_TP; |
| 14298 | else |
| 14299 | adv |= ADVERTISED_FIBRE; |
| 14300 | |
| 14301 | tp->link_config.advertising = adv; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 14302 | tp->link_config.speed = SPEED_UNKNOWN; |
| 14303 | tp->link_config.duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14304 | tp->link_config.autoneg = AUTONEG_ENABLE; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 14305 | tp->link_config.active_speed = SPEED_UNKNOWN; |
| 14306 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 14307 | |
| 14308 | tp->old_link = -1; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14309 | } |
| 14310 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14311 | static int tg3_phy_probe(struct tg3 *tp) |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14312 | { |
| 14313 | u32 hw_phy_id_1, hw_phy_id_2; |
| 14314 | u32 hw_phy_id, hw_phy_id_masked; |
| 14315 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14316 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14317 | /* flow control autonegotiation is default behavior */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14318 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14319 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 14320 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 14321 | if (tg3_flag(tp, ENABLE_APE)) { |
| 14322 | switch (tp->pci_fn) { |
| 14323 | case 0: |
| 14324 | tp->phy_ape_lock = TG3_APE_LOCK_PHY0; |
| 14325 | break; |
| 14326 | case 1: |
| 14327 | tp->phy_ape_lock = TG3_APE_LOCK_PHY1; |
| 14328 | break; |
| 14329 | case 2: |
| 14330 | tp->phy_ape_lock = TG3_APE_LOCK_PHY2; |
| 14331 | break; |
| 14332 | case 3: |
| 14333 | tp->phy_ape_lock = TG3_APE_LOCK_PHY3; |
| 14334 | break; |
| 14335 | } |
| 14336 | } |
| 14337 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14338 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14339 | return tg3_phy_init(tp); |
| 14340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14341 | /* Reading the PHY ID register can conflict with ASF |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 14342 | * firmware access to the PHY hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14343 | */ |
| 14344 | err = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14345 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14346 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14347 | } else { |
| 14348 | /* Now read the physical PHY_ID from the chip and verify |
| 14349 | * that it is sane. If it doesn't look good, we fall back |
| 14350 | * to either the hard-coded table based PHY_ID and failing |
| 14351 | * that the value found in the eeprom area. |
| 14352 | */ |
| 14353 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); |
| 14354 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); |
| 14355 | |
| 14356 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; |
| 14357 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; |
| 14358 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; |
| 14359 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14360 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14361 | } |
| 14362 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14363 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14364 | tp->phy_id = hw_phy_id; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14365 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14366 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Michael Chan | da6b2d0 | 2005-08-19 12:54:29 -0700 | [diff] [blame] | 14367 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14368 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14369 | } else { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14370 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14371 | /* Do nothing, phy ID already set up in |
| 14372 | * tg3_get_eeprom_hw_cfg(). |
| 14373 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14374 | } else { |
| 14375 | struct subsys_tbl_ent *p; |
| 14376 | |
| 14377 | /* No eeprom signature? Try the hardcoded |
| 14378 | * subsys device table. |
| 14379 | */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14380 | p = tg3_lookup_by_subsys(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14381 | if (!p) |
| 14382 | return -ENODEV; |
| 14383 | |
| 14384 | tp->phy_id = p->phy_id; |
| 14385 | if (!tp->phy_id || |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14386 | tp->phy_id == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14387 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14388 | } |
| 14389 | } |
| 14390 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 14391 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Matt Carlson | 5baa5e9 | 2011-07-20 10:20:53 +0000 | [diff] [blame] | 14392 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14393 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 14394 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762 || |
Matt Carlson | 5baa5e9 | 2011-07-20 10:20:53 +0000 | [diff] [blame] | 14395 | (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 14396 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) || |
| 14397 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 14398 | tp->pci_chip_rev_id != CHIPREV_ID_57765_A0))) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 14399 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 14400 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14401 | tg3_phy_init_link_config(tp); |
| 14402 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14403 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14404 | !tg3_flag(tp, ENABLE_APE) && |
| 14405 | !tg3_flag(tp, ENABLE_ASF)) { |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 14406 | u32 bmsr, dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14407 | |
| 14408 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 14409 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 14410 | (bmsr & BMSR_LSTATUS)) |
| 14411 | goto skip_phy_reset; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 14412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14413 | err = tg3_phy_reset(tp); |
| 14414 | if (err) |
| 14415 | return err; |
| 14416 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 14417 | tg3_phy_set_wirespeed(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14418 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 14419 | if (!tg3_phy_copper_an_config_ok(tp, &dummy)) { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 14420 | tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, |
| 14421 | tp->link_config.flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14422 | |
| 14423 | tg3_writephy(tp, MII_BMCR, |
| 14424 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 14425 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14426 | } |
| 14427 | |
| 14428 | skip_phy_reset: |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14429 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14430 | err = tg3_init_5401phy_dsp(tp); |
| 14431 | if (err) |
| 14432 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14434 | err = tg3_init_5401phy_dsp(tp); |
| 14435 | } |
| 14436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14437 | return err; |
| 14438 | } |
| 14439 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14440 | static void tg3_read_vpd(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14441 | { |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 14442 | u8 *vpd_data; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 14443 | unsigned int block_end, rosize, len; |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14444 | u32 vpdlen; |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 14445 | int j, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14446 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14447 | vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen); |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 14448 | if (!vpd_data) |
| 14449 | goto out_no_vpd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14450 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14451 | 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] | 14452 | if (i < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14453 | goto out_not_found; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 14454 | |
| 14455 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
| 14456 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; |
| 14457 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 14458 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14459 | if (block_end > vpdlen) |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 14460 | goto out_not_found; |
| 14461 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 14462 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 14463 | PCI_VPD_RO_KEYWORD_MFR_ID); |
| 14464 | if (j > 0) { |
| 14465 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 14466 | |
| 14467 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 14468 | if (j + len > block_end || len != 4 || |
| 14469 | memcmp(&vpd_data[j], "1028", 4)) |
| 14470 | goto partno; |
| 14471 | |
| 14472 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 14473 | PCI_VPD_RO_KEYWORD_VENDOR0); |
| 14474 | if (j < 0) |
| 14475 | goto partno; |
| 14476 | |
| 14477 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 14478 | |
| 14479 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 14480 | if (j + len > block_end) |
| 14481 | goto partno; |
| 14482 | |
| 14483 | memcpy(tp->fw_ver, &vpd_data[j], len); |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14484 | strncat(tp->fw_ver, " bc ", vpdlen - len - 1); |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 14485 | } |
| 14486 | |
| 14487 | partno: |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 14488 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 14489 | PCI_VPD_RO_KEYWORD_PARTNO); |
| 14490 | if (i < 0) |
| 14491 | goto out_not_found; |
| 14492 | |
| 14493 | len = pci_vpd_info_field_size(&vpd_data[i]); |
| 14494 | |
| 14495 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 14496 | if (len > TG3_BPN_SIZE || |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 14497 | (len + i) > vpdlen) |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 14498 | goto out_not_found; |
| 14499 | |
| 14500 | memcpy(tp->board_part_number, &vpd_data[i], len); |
| 14501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14502 | out_not_found: |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 14503 | kfree(vpd_data); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14504 | if (tp->board_part_number[0]) |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 14505 | return; |
| 14506 | |
| 14507 | out_no_vpd: |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14508 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 14509 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 14510 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C) |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14511 | strcpy(tp->board_part_number, "BCM5717"); |
| 14512 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) |
| 14513 | strcpy(tp->board_part_number, "BCM5718"); |
| 14514 | else |
| 14515 | goto nomatch; |
| 14516 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 14517 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
| 14518 | strcpy(tp->board_part_number, "BCM57780"); |
| 14519 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) |
| 14520 | strcpy(tp->board_part_number, "BCM57760"); |
| 14521 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) |
| 14522 | strcpy(tp->board_part_number, "BCM57790"); |
| 14523 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) |
| 14524 | strcpy(tp->board_part_number, "BCM57788"); |
| 14525 | else |
| 14526 | goto nomatch; |
| 14527 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
| 14528 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
| 14529 | strcpy(tp->board_part_number, "BCM57761"); |
| 14530 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) |
| 14531 | strcpy(tp->board_part_number, "BCM57765"); |
| 14532 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) |
| 14533 | strcpy(tp->board_part_number, "BCM57781"); |
| 14534 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) |
| 14535 | strcpy(tp->board_part_number, "BCM57785"); |
| 14536 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) |
| 14537 | strcpy(tp->board_part_number, "BCM57791"); |
| 14538 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 14539 | strcpy(tp->board_part_number, "BCM57795"); |
| 14540 | else |
| 14541 | goto nomatch; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 14542 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) { |
| 14543 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762) |
| 14544 | strcpy(tp->board_part_number, "BCM57762"); |
| 14545 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766) |
| 14546 | strcpy(tp->board_part_number, "BCM57766"); |
| 14547 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782) |
| 14548 | strcpy(tp->board_part_number, "BCM57782"); |
| 14549 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 14550 | strcpy(tp->board_part_number, "BCM57786"); |
| 14551 | else |
| 14552 | goto nomatch; |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14553 | } 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] | 14554 | strcpy(tp->board_part_number, "BCM95906"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14555 | } else { |
| 14556 | nomatch: |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14557 | strcpy(tp->board_part_number, "none"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 14558 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14559 | } |
| 14560 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14561 | static int tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14562 | { |
| 14563 | u32 val; |
| 14564 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14565 | if (tg3_nvram_read(tp, offset, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14566 | (val & 0xfc000000) != 0x0c000000 || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14567 | tg3_nvram_read(tp, offset + 4, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14568 | val != 0) |
| 14569 | return 0; |
| 14570 | |
| 14571 | return 1; |
| 14572 | } |
| 14573 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14574 | static void tg3_read_bc_ver(struct tg3 *tp) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14575 | { |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14576 | u32 val, offset, start, ver_offset; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14577 | int i, dst_off; |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14578 | bool newver = false; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14579 | |
| 14580 | if (tg3_nvram_read(tp, 0xc, &offset) || |
| 14581 | tg3_nvram_read(tp, 0x4, &start)) |
| 14582 | return; |
| 14583 | |
| 14584 | offset = tg3_nvram_logical_addr(tp, offset); |
| 14585 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14586 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14587 | return; |
| 14588 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14589 | if ((val & 0xfc000000) == 0x0c000000) { |
| 14590 | if (tg3_nvram_read(tp, offset + 4, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14591 | return; |
| 14592 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14593 | if (val == 0) |
| 14594 | newver = true; |
| 14595 | } |
| 14596 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14597 | dst_off = strlen(tp->fw_ver); |
| 14598 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14599 | if (newver) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14600 | if (TG3_VER_SIZE - dst_off < 16 || |
| 14601 | tg3_nvram_read(tp, offset + 8, &ver_offset)) |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14602 | return; |
| 14603 | |
| 14604 | offset = offset + ver_offset - start; |
| 14605 | for (i = 0; i < 16; i += 4) { |
| 14606 | __be32 v; |
| 14607 | if (tg3_nvram_read_be32(tp, offset + i, &v)) |
| 14608 | return; |
| 14609 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14610 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 14611 | } |
| 14612 | } else { |
| 14613 | u32 major, minor; |
| 14614 | |
| 14615 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) |
| 14616 | return; |
| 14617 | |
| 14618 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> |
| 14619 | TG3_NVM_BCVER_MAJSFT; |
| 14620 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14621 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
| 14622 | "v%d.%02d", major, minor); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14623 | } |
| 14624 | } |
| 14625 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14626 | static void tg3_read_hwsb_ver(struct tg3 *tp) |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 14627 | { |
| 14628 | u32 val, major, minor; |
| 14629 | |
| 14630 | /* Use native endian representation */ |
| 14631 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) |
| 14632 | return; |
| 14633 | |
| 14634 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> |
| 14635 | TG3_NVM_HWSB_CFG1_MAJSFT; |
| 14636 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> |
| 14637 | TG3_NVM_HWSB_CFG1_MINSFT; |
| 14638 | |
| 14639 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); |
| 14640 | } |
| 14641 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14642 | static void tg3_read_sb_ver(struct tg3 *tp, u32 val) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 14643 | { |
| 14644 | u32 offset, major, minor, build; |
| 14645 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14646 | 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] | 14647 | |
| 14648 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) |
| 14649 | return; |
| 14650 | |
| 14651 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { |
| 14652 | case TG3_EEPROM_SB_REVISION_0: |
| 14653 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; |
| 14654 | break; |
| 14655 | case TG3_EEPROM_SB_REVISION_2: |
| 14656 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; |
| 14657 | break; |
| 14658 | case TG3_EEPROM_SB_REVISION_3: |
| 14659 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; |
| 14660 | break; |
Matt Carlson | a4153d4 | 2010-02-17 15:16:56 +0000 | [diff] [blame] | 14661 | case TG3_EEPROM_SB_REVISION_4: |
| 14662 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; |
| 14663 | break; |
| 14664 | case TG3_EEPROM_SB_REVISION_5: |
| 14665 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; |
| 14666 | break; |
Matt Carlson | bba226a | 2010-10-14 10:37:38 +0000 | [diff] [blame] | 14667 | case TG3_EEPROM_SB_REVISION_6: |
| 14668 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; |
| 14669 | break; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 14670 | default: |
| 14671 | return; |
| 14672 | } |
| 14673 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14674 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 14675 | return; |
| 14676 | |
| 14677 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> |
| 14678 | TG3_EEPROM_SB_EDH_BLD_SHFT; |
| 14679 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> |
| 14680 | TG3_EEPROM_SB_EDH_MAJ_SHFT; |
| 14681 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; |
| 14682 | |
| 14683 | if (minor > 99 || build > 26) |
| 14684 | return; |
| 14685 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14686 | offset = strlen(tp->fw_ver); |
| 14687 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, |
| 14688 | " v%d.%02d", major, minor); |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 14689 | |
| 14690 | if (build > 0) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14691 | offset = strlen(tp->fw_ver); |
| 14692 | if (offset < TG3_VER_SIZE - 1) |
| 14693 | tp->fw_ver[offset] = 'a' + build - 1; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 14694 | } |
| 14695 | } |
| 14696 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14697 | static void tg3_read_mgmtfw_ver(struct tg3 *tp) |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 14698 | { |
| 14699 | u32 val, offset, start; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14700 | int i, vlen; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14701 | |
| 14702 | for (offset = TG3_NVM_DIR_START; |
| 14703 | offset < TG3_NVM_DIR_END; |
| 14704 | offset += TG3_NVM_DIRENT_SIZE) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14705 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14706 | return; |
| 14707 | |
| 14708 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
| 14709 | break; |
| 14710 | } |
| 14711 | |
| 14712 | if (offset == TG3_NVM_DIR_END) |
| 14713 | return; |
| 14714 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14715 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14716 | start = 0x08000000; |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14717 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14718 | return; |
| 14719 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14720 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14721 | !tg3_fw_img_is_valid(tp, offset) || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 14722 | tg3_nvram_read(tp, offset + 8, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14723 | return; |
| 14724 | |
| 14725 | offset += val - start; |
| 14726 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14727 | vlen = strlen(tp->fw_ver); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14728 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14729 | tp->fw_ver[vlen++] = ','; |
| 14730 | tp->fw_ver[vlen++] = ' '; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14731 | |
| 14732 | for (i = 0; i < 4; i++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 14733 | __be32 v; |
| 14734 | if (tg3_nvram_read_be32(tp, offset, &v)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14735 | return; |
| 14736 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 14737 | offset += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14738 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14739 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
| 14740 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14741 | break; |
| 14742 | } |
| 14743 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14744 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
| 14745 | vlen += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14746 | } |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14747 | } |
| 14748 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14749 | static void tg3_probe_ncsi(struct tg3 *tp) |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14750 | { |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14751 | u32 apedata; |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14752 | |
| 14753 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 14754 | if (apedata != APE_SEG_SIG_MAGIC) |
| 14755 | return; |
| 14756 | |
| 14757 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 14758 | if (!(apedata & APE_FW_STATUS_READY)) |
| 14759 | return; |
| 14760 | |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 14761 | if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) |
| 14762 | tg3_flag_set(tp, APE_HAS_NCSI); |
| 14763 | } |
| 14764 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14765 | static void tg3_read_dash_ver(struct tg3 *tp) |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 14766 | { |
| 14767 | int vlen; |
| 14768 | u32 apedata; |
| 14769 | char *fwtype; |
| 14770 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14771 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
| 14772 | |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 14773 | if (tg3_flag(tp, APE_HAS_NCSI)) |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 14774 | fwtype = "NCSI"; |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 14775 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725) |
| 14776 | fwtype = "SMASH"; |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 14777 | else |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 14778 | fwtype = "DASH"; |
| 14779 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14780 | vlen = strlen(tp->fw_ver); |
| 14781 | |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 14782 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
| 14783 | fwtype, |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14784 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
| 14785 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, |
| 14786 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, |
| 14787 | (apedata & APE_FW_VERSION_BLDMSK)); |
| 14788 | } |
| 14789 | |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 14790 | static void tg3_read_otp_ver(struct tg3 *tp) |
| 14791 | { |
| 14792 | u32 val, val2; |
| 14793 | |
| 14794 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5762) |
| 14795 | return; |
| 14796 | |
| 14797 | if (!tg3_ape_otp_read(tp, OTP_ADDRESS_MAGIC0, &val) && |
| 14798 | !tg3_ape_otp_read(tp, OTP_ADDRESS_MAGIC0 + 4, &val2) && |
| 14799 | TG3_OTP_MAGIC0_VALID(val)) { |
| 14800 | u64 val64 = (u64) val << 32 | val2; |
| 14801 | u32 ver = 0; |
| 14802 | int i, vlen; |
| 14803 | |
| 14804 | for (i = 0; i < 7; i++) { |
| 14805 | if ((val64 & 0xff) == 0) |
| 14806 | break; |
| 14807 | ver = val64 & 0xff; |
| 14808 | val64 >>= 8; |
| 14809 | } |
| 14810 | vlen = strlen(tp->fw_ver); |
| 14811 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " .%02d", ver); |
| 14812 | } |
| 14813 | } |
| 14814 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14815 | static void tg3_read_fw_ver(struct tg3 *tp) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14816 | { |
| 14817 | u32 val; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14818 | bool vpd_vers = false; |
| 14819 | |
| 14820 | if (tp->fw_ver[0] != 0) |
| 14821 | vpd_vers = true; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14822 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14823 | if (tg3_flag(tp, NO_NVRAM)) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 14824 | strcat(tp->fw_ver, "sb"); |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 14825 | tg3_read_otp_ver(tp); |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 14826 | return; |
| 14827 | } |
| 14828 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14829 | if (tg3_nvram_read(tp, 0, &val)) |
| 14830 | return; |
| 14831 | |
| 14832 | if (val == TG3_EEPROM_MAGIC) |
| 14833 | tg3_read_bc_ver(tp); |
| 14834 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) |
| 14835 | tg3_read_sb_ver(tp, val); |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 14836 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 14837 | tg3_read_hwsb_ver(tp); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 14838 | |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 14839 | if (tg3_flag(tp, ENABLE_ASF)) { |
| 14840 | if (tg3_flag(tp, ENABLE_APE)) { |
| 14841 | tg3_probe_ncsi(tp); |
| 14842 | if (!vpd_vers) |
| 14843 | tg3_read_dash_ver(tp); |
| 14844 | } else if (!vpd_vers) { |
| 14845 | tg3_read_mgmtfw_ver(tp); |
| 14846 | } |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 14847 | } |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 14848 | |
| 14849 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 14850 | } |
| 14851 | |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 14852 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
| 14853 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14854 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 14855 | return TG3_RX_RET_MAX_SIZE_5717; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14856 | else if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 14857 | return TG3_RX_RET_MAX_SIZE_5700; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 14858 | else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 14859 | return TG3_RX_RET_MAX_SIZE_5705; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 14860 | } |
| 14861 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 14862 | static DEFINE_PCI_DEVICE_TABLE(tg3_write_reorder_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 14863 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
| 14864 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
| 14865 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8385_0) }, |
| 14866 | { }, |
| 14867 | }; |
| 14868 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14869 | static struct pci_dev *tg3_find_peer(struct tg3 *tp) |
Matt Carlson | 16c7fa7 | 2012-02-13 10:20:10 +0000 | [diff] [blame] | 14870 | { |
| 14871 | struct pci_dev *peer; |
| 14872 | unsigned int func, devnr = tp->pdev->devfn & ~7; |
| 14873 | |
| 14874 | for (func = 0; func < 8; func++) { |
| 14875 | peer = pci_get_slot(tp->pdev->bus, devnr | func); |
| 14876 | if (peer && peer != tp->pdev) |
| 14877 | break; |
| 14878 | pci_dev_put(peer); |
| 14879 | } |
| 14880 | /* 5704 can be configured in single-port mode, set peer to |
| 14881 | * tp->pdev in that case. |
| 14882 | */ |
| 14883 | if (!peer) { |
| 14884 | peer = tp->pdev; |
| 14885 | return peer; |
| 14886 | } |
| 14887 | |
| 14888 | /* |
| 14889 | * We don't need to keep the refcount elevated; there's no way |
| 14890 | * to remove one half of this device without removing the other |
| 14891 | */ |
| 14892 | pci_dev_put(peer); |
| 14893 | |
| 14894 | return peer; |
| 14895 | } |
| 14896 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14897 | static void tg3_detect_asic_rev(struct tg3 *tp, u32 misc_ctrl_reg) |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14898 | { |
| 14899 | tp->pci_chip_rev_id = misc_ctrl_reg >> MISC_HOST_CTRL_CHIPREV_SHIFT; |
| 14900 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
| 14901 | u32 reg; |
| 14902 | |
| 14903 | /* All devices that use the alternate |
| 14904 | * ASIC REV location have a CPMU. |
| 14905 | */ |
| 14906 | tg3_flag_set(tp, CPMU_PRESENT); |
| 14907 | |
| 14908 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 14909 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C || |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14910 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 14911 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 14912 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720 || |
| 14913 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5762 || |
| 14914 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725 || |
| 14915 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5727) |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14916 | reg = TG3PCI_GEN2_PRODID_ASICREV; |
| 14917 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
| 14918 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || |
| 14919 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || |
| 14920 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || |
| 14921 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 14922 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
| 14923 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762 || |
| 14924 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766 || |
| 14925 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782 || |
| 14926 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 14927 | reg = TG3PCI_GEN15_PRODID_ASICREV; |
| 14928 | else |
| 14929 | reg = TG3PCI_PRODID_ASICREV; |
| 14930 | |
| 14931 | pci_read_config_dword(tp->pdev, reg, &tp->pci_chip_rev_id); |
| 14932 | } |
| 14933 | |
| 14934 | /* Wrong chip ID in 5752 A0. This code can be removed later |
| 14935 | * as A0 is not in production. |
| 14936 | */ |
| 14937 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) |
| 14938 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
| 14939 | |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 14940 | if (tp->pci_chip_rev_id == CHIPREV_ID_5717_C0) |
| 14941 | tp->pci_chip_rev_id = CHIPREV_ID_5720_A0; |
| 14942 | |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14943 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14944 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 14945 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 14946 | tg3_flag_set(tp, 5717_PLUS); |
| 14947 | |
| 14948 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 || |
| 14949 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57766) |
| 14950 | tg3_flag_set(tp, 57765_CLASS); |
| 14951 | |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 14952 | if (tg3_flag(tp, 57765_CLASS) || tg3_flag(tp, 5717_PLUS) || |
| 14953 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 14954 | tg3_flag_set(tp, 57765_PLUS); |
| 14955 | |
| 14956 | /* Intentionally exclude ASIC_REV_5906 */ |
| 14957 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 14958 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
| 14959 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 14960 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 14961 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 14962 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 14963 | tg3_flag(tp, 57765_PLUS)) |
| 14964 | tg3_flag_set(tp, 5755_PLUS); |
| 14965 | |
| 14966 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
| 14967 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) |
| 14968 | tg3_flag_set(tp, 5780_CLASS); |
| 14969 | |
| 14970 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 14971 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 14972 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
| 14973 | tg3_flag(tp, 5755_PLUS) || |
| 14974 | tg3_flag(tp, 5780_CLASS)) |
| 14975 | tg3_flag_set(tp, 5750_PLUS); |
| 14976 | |
| 14977 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 14978 | tg3_flag(tp, 5750_PLUS)) |
| 14979 | tg3_flag_set(tp, 5705_PLUS); |
| 14980 | } |
| 14981 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 14982 | static bool tg3_10_100_only_device(struct tg3 *tp, |
| 14983 | const struct pci_device_id *ent) |
| 14984 | { |
| 14985 | u32 grc_misc_cfg = tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK; |
| 14986 | |
| 14987 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 14988 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || |
| 14989 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
| 14990 | return true; |
| 14991 | |
| 14992 | if (ent->driver_data & TG3_DRV_DATA_FLAG_10_100_ONLY) { |
| 14993 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 14994 | if (ent->driver_data & TG3_DRV_DATA_FLAG_5705_10_100) |
| 14995 | return true; |
| 14996 | } else { |
| 14997 | return true; |
| 14998 | } |
| 14999 | } |
| 15000 | |
| 15001 | return false; |
| 15002 | } |
| 15003 | |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 15004 | static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15005 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15006 | u32 misc_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15007 | u32 pci_state_reg, grc_misc_cfg; |
| 15008 | u32 val; |
| 15009 | u16 pci_cmd; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 15010 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15012 | /* Force memory write invalidate off. If we leave it on, |
| 15013 | * then on 5700_BX chips we have to enable a workaround. |
| 15014 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary |
| 15015 | * to match the cacheline size. The Broadcom driver have this |
| 15016 | * workaround but turns MWI off all the times so never uses |
| 15017 | * it. This seems to suggest that the workaround is insufficient. |
| 15018 | */ |
| 15019 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 15020 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; |
| 15021 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 15022 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15023 | /* Important! -- Make sure register accesses are byteswapped |
| 15024 | * correctly. Also, for those chips that require it, make |
| 15025 | * sure that indirect register accesses are enabled before |
| 15026 | * the first operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15027 | */ |
| 15028 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 15029 | &misc_ctrl_reg); |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15030 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
| 15031 | MISC_HOST_CTRL_CHIPREV); |
| 15032 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 15033 | tp->misc_host_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15034 | |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15035 | tg3_detect_asic_rev(tp, misc_ctrl_reg); |
Michael Chan | ff645be | 2005-04-21 17:09:53 -0700 | [diff] [blame] | 15036 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15037 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
| 15038 | * we need to disable memory and use config. cycles |
| 15039 | * only to access all registers. The 5702/03 chips |
| 15040 | * can mistakenly decode the special cycles from the |
| 15041 | * ICH chipsets as memory write cycles, causing corruption |
| 15042 | * of register and memory space. Only certain ICH bridges |
| 15043 | * will drive special cycles with non-zero data during the |
| 15044 | * address phase which can fall within the 5703's address |
| 15045 | * range. This is not an ICH bug as the PCI spec allows |
| 15046 | * non-zero address during special cycles. However, only |
| 15047 | * these ICH bridges are known to drive non-zero addresses |
| 15048 | * during special cycles. |
| 15049 | * |
| 15050 | * Since special cycles do not cross PCI bridges, we only |
| 15051 | * enable this workaround if the 5703 is on the secondary |
| 15052 | * bus of these ICH bridges. |
| 15053 | */ |
| 15054 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || |
| 15055 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { |
| 15056 | static struct tg3_dev_id { |
| 15057 | u32 vendor; |
| 15058 | u32 device; |
| 15059 | u32 rev; |
| 15060 | } ich_chipsets[] = { |
| 15061 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, |
| 15062 | PCI_ANY_ID }, |
| 15063 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, |
| 15064 | PCI_ANY_ID }, |
| 15065 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, |
| 15066 | 0xa }, |
| 15067 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, |
| 15068 | PCI_ANY_ID }, |
| 15069 | { }, |
| 15070 | }; |
| 15071 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; |
| 15072 | struct pci_dev *bridge = NULL; |
| 15073 | |
| 15074 | while (pci_id->vendor != 0) { |
| 15075 | bridge = pci_get_device(pci_id->vendor, pci_id->device, |
| 15076 | bridge); |
| 15077 | if (!bridge) { |
| 15078 | pci_id++; |
| 15079 | continue; |
| 15080 | } |
| 15081 | if (pci_id->rev != PCI_ANY_ID) { |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 15082 | if (bridge->revision > pci_id->rev) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15083 | continue; |
| 15084 | } |
| 15085 | if (bridge->subordinate && |
| 15086 | (bridge->subordinate->number == |
| 15087 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15088 | tg3_flag_set(tp, ICH_WORKAROUND); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15089 | pci_dev_put(bridge); |
| 15090 | break; |
| 15091 | } |
| 15092 | } |
| 15093 | } |
| 15094 | |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 15095 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 15096 | static struct tg3_dev_id { |
| 15097 | u32 vendor; |
| 15098 | u32 device; |
| 15099 | } bridge_chipsets[] = { |
| 15100 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, |
| 15101 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, |
| 15102 | { }, |
| 15103 | }; |
| 15104 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; |
| 15105 | struct pci_dev *bridge = NULL; |
| 15106 | |
| 15107 | while (pci_id->vendor != 0) { |
| 15108 | bridge = pci_get_device(pci_id->vendor, |
| 15109 | pci_id->device, |
| 15110 | bridge); |
| 15111 | if (!bridge) { |
| 15112 | pci_id++; |
| 15113 | continue; |
| 15114 | } |
| 15115 | if (bridge->subordinate && |
| 15116 | (bridge->subordinate->number <= |
| 15117 | tp->pdev->bus->number) && |
Yinghai Lu | b918c62 | 2012-05-17 18:51:11 -0700 | [diff] [blame] | 15118 | (bridge->subordinate->busn_res.end >= |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 15119 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15120 | tg3_flag_set(tp, 5701_DMA_BUG); |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 15121 | pci_dev_put(bridge); |
| 15122 | break; |
| 15123 | } |
| 15124 | } |
| 15125 | } |
| 15126 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15127 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
| 15128 | * DMA addresses > 40-bit. This bridge may have other additional |
| 15129 | * 57xx devices behind it in some 4-port NIC designs for example. |
| 15130 | * Any tg3 device found behind the bridge will also need the 40-bit |
| 15131 | * DMA workaround. |
| 15132 | */ |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15133 | if (tg3_flag(tp, 5780_CLASS)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15134 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 15135 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15136 | } else { |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15137 | struct pci_dev *bridge = NULL; |
| 15138 | |
| 15139 | do { |
| 15140 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, |
| 15141 | PCI_DEVICE_ID_SERVERWORKS_EPB, |
| 15142 | bridge); |
| 15143 | if (bridge && bridge->subordinate && |
| 15144 | (bridge->subordinate->number <= |
| 15145 | tp->pdev->bus->number) && |
Yinghai Lu | b918c62 | 2012-05-17 18:51:11 -0700 | [diff] [blame] | 15146 | (bridge->subordinate->busn_res.end >= |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15147 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15148 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15149 | pci_dev_put(bridge); |
| 15150 | break; |
| 15151 | } |
| 15152 | } while (bridge); |
| 15153 | } |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 15154 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 15155 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 15156 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 15157 | tp->pdev_peer = tg3_find_peer(tp); |
| 15158 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 15159 | /* Determine TSO capabilities */ |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 15160 | if (tp->pci_chip_rev_id == CHIPREV_ID_5719_A0) |
Matt Carlson | 4d163b7 | 2011-01-25 15:58:48 +0000 | [diff] [blame] | 15161 | ; /* Do nothing. HW bug. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15162 | else if (tg3_flag(tp, 57765_PLUS)) |
| 15163 | tg3_flag_set(tp, HW_TSO_3); |
| 15164 | else if (tg3_flag(tp, 5755_PLUS) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 15165 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15166 | tg3_flag_set(tp, HW_TSO_2); |
| 15167 | else if (tg3_flag(tp, 5750_PLUS)) { |
| 15168 | tg3_flag_set(tp, HW_TSO_1); |
| 15169 | tg3_flag_set(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 15170 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && |
| 15171 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15172 | tg3_flag_clear(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 15173 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 15174 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 15175 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15176 | tg3_flag_set(tp, TSO_BUG); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 15177 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) |
| 15178 | tp->fw_needed = FIRMWARE_TG3TSO5; |
| 15179 | else |
| 15180 | tp->fw_needed = FIRMWARE_TG3TSO; |
| 15181 | } |
| 15182 | |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 15183 | /* Selectively allow TSO based on operating conditions */ |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 15184 | if (tg3_flag(tp, HW_TSO_1) || |
| 15185 | tg3_flag(tp, HW_TSO_2) || |
| 15186 | tg3_flag(tp, HW_TSO_3) || |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 15187 | tp->fw_needed) { |
| 15188 | /* For firmware TSO, assume ASF is disabled. |
| 15189 | * We'll disable TSO later if we discover ASF |
| 15190 | * is enabled in tg3_get_eeprom_hw_cfg(). |
| 15191 | */ |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 15192 | tg3_flag_set(tp, TSO_CAPABLE); |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 15193 | } else { |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 15194 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 15195 | tg3_flag_clear(tp, TSO_BUG); |
| 15196 | tp->fw_needed = NULL; |
| 15197 | } |
| 15198 | |
| 15199 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) |
| 15200 | tp->fw_needed = FIRMWARE_TG3; |
| 15201 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 15202 | tp->irq_max = 1; |
| 15203 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15204 | if (tg3_flag(tp, 5750_PLUS)) { |
| 15205 | tg3_flag_set(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 15206 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || |
| 15207 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || |
| 15208 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && |
| 15209 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && |
| 15210 | tp->pdev_peer == tp->pdev)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15211 | tg3_flag_clear(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 15212 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15213 | if (tg3_flag(tp, 5755_PLUS) || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 15214 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15215 | tg3_flag_set(tp, 1SHOT_MSI); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 15216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15217 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15218 | if (tg3_flag(tp, 57765_PLUS)) { |
| 15219 | tg3_flag_set(tp, SUPPORT_MSIX); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 15220 | tp->irq_max = TG3_IRQ_MAX_VECS; |
| 15221 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 15222 | } |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 15223 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 15224 | tp->txq_max = 1; |
| 15225 | tp->rxq_max = 1; |
| 15226 | if (tp->irq_max > 1) { |
| 15227 | tp->rxq_max = TG3_RSS_MAX_NUM_QS; |
| 15228 | tg3_rss_init_dflt_indir_tbl(tp, TG3_RSS_MAX_NUM_QS); |
| 15229 | |
| 15230 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 15231 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
| 15232 | tp->txq_max = tp->irq_max - 1; |
| 15233 | } |
| 15234 | |
Matt Carlson | b7abee6 | 2012-06-07 12:56:54 +0000 | [diff] [blame] | 15235 | if (tg3_flag(tp, 5755_PLUS) || |
| 15236 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15237 | tg3_flag_set(tp, SHORT_DMA_BUG); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 15238 | |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 15239 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 15240 | tp->dma_limit = TG3_TX_BD_DMA_MAX_4K; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 15241 | |
Matt Carlson | fa6b2aa | 2011-11-21 15:01:19 +0000 | [diff] [blame] | 15242 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 15243 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 15244 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 15245 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15246 | tg3_flag_set(tp, LRG_PROD_RING_CAP); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 15247 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15248 | if (tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | a051294 | 2011-07-27 14:20:54 +0000 | [diff] [blame] | 15249 | tp->pci_chip_rev_id != CHIPREV_ID_5719_A0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15250 | tg3_flag_set(tp, USE_JUMBO_BDFLAG); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 15251 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15252 | if (!tg3_flag(tp, 5705_PLUS) || |
| 15253 | tg3_flag(tp, 5780_CLASS) || |
| 15254 | tg3_flag(tp, USE_JUMBO_BDFLAG)) |
| 15255 | tg3_flag_set(tp, JUMBO_CAPABLE); |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 15256 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15257 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 15258 | &pci_state_reg); |
| 15259 | |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 15260 | if (pci_is_pcie(tp->pdev)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 15261 | u16 lnkctl; |
| 15262 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15263 | tg3_flag_set(tp, PCI_EXPRESS); |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 15264 | |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 15265 | pcie_capability_read_word(tp->pdev, PCI_EXP_LNKCTL, &lnkctl); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 15266 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
Matt Carlson | 7196cd6 | 2011-05-19 16:02:44 +0000 | [diff] [blame] | 15267 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 15268 | ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15269 | tg3_flag_clear(tp, HW_TSO_2); |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 15270 | tg3_flag_clear(tp, TSO_CAPABLE); |
Matt Carlson | 7196cd6 | 2011-05-19 16:02:44 +0000 | [diff] [blame] | 15271 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 15272 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 15273 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 9cf74eb | 2009-04-20 06:58:27 +0000 | [diff] [blame] | 15274 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
| 15275 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15276 | tg3_flag_set(tp, CLKREQ_BUG); |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 15277 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15278 | tg3_flag_set(tp, L1PLLPD_EN); |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 15279 | } |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15280 | } 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] | 15281 | /* BCM5785 devices are effectively PCIe devices, and should |
| 15282 | * follow PCIe codepaths, but do not have a PCIe capabilities |
| 15283 | * section. |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 15284 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15285 | tg3_flag_set(tp, PCI_EXPRESS); |
| 15286 | } else if (!tg3_flag(tp, 5705_PLUS) || |
| 15287 | tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15288 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
| 15289 | if (!tp->pcix_cap) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15290 | dev_err(&tp->pdev->dev, |
| 15291 | "Cannot find PCI-X capability, aborting\n"); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15292 | return -EIO; |
| 15293 | } |
| 15294 | |
| 15295 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15296 | tg3_flag_set(tp, PCIX_MODE); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15298 | |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 15299 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
| 15300 | * reordering to the mailbox registers done by the host |
| 15301 | * controller can cause major troubles. We read back from |
| 15302 | * every mailbox register write to force the writes to be |
| 15303 | * posted to the chip in order. |
| 15304 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 15305 | if (pci_dev_present(tg3_write_reorder_chipsets) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15306 | !tg3_flag(tp, PCI_EXPRESS)) |
| 15307 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 15308 | |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 15309 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 15310 | &tp->pci_cacheline_sz); |
| 15311 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 15312 | &tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15313 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 15314 | tp->pci_lat_timer < 64) { |
| 15315 | tp->pci_lat_timer = 64; |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 15316 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 15317 | tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15318 | } |
| 15319 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15320 | /* Important! -- It is critical that the PCI-X hw workaround |
| 15321 | * situation is decided before the first MMIO register access. |
| 15322 | */ |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15323 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
| 15324 | /* 5700 BX chips need to have their TX producer index |
| 15325 | * mailboxes written twice to workaround a bug. |
| 15326 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15327 | tg3_flag_set(tp, TXD_MBOX_HWBUG); |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 15328 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15329 | /* If we are in PCI-X mode, enable register write workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15330 | * |
| 15331 | * The workaround is to use indirect register accesses |
| 15332 | * for all chip writes not to mailbox registers. |
| 15333 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15334 | if (tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15335 | u32 pm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15336 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15337 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15338 | |
| 15339 | /* The chip can have it's power management PCI config |
| 15340 | * space registers clobbered due to this bug. |
| 15341 | * So explicitly force the chip into D0 here. |
| 15342 | */ |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 15343 | pci_read_config_dword(tp->pdev, |
| 15344 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15345 | &pm_reg); |
| 15346 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; |
| 15347 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 15348 | pci_write_config_dword(tp->pdev, |
| 15349 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15350 | pm_reg); |
| 15351 | |
| 15352 | /* Also, force SERR#/PERR# in PCI command. */ |
| 15353 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 15354 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
| 15355 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 15356 | } |
| 15357 | } |
| 15358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15359 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15360 | tg3_flag_set(tp, PCI_HIGH_SPEED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15361 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15362 | tg3_flag_set(tp, PCI_32BIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15363 | |
| 15364 | /* Chip-specific fixup from Broadcom driver */ |
| 15365 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && |
| 15366 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
| 15367 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; |
| 15368 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); |
| 15369 | } |
| 15370 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 15371 | /* Default fast path register access methods */ |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 15372 | tp->read32 = tg3_read32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 15373 | tp->write32 = tg3_write32; |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 15374 | tp->read32_mbox = tg3_read32; |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 15375 | tp->write32_mbox = tg3_write32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 15376 | tp->write32_tx_mbox = tg3_write32; |
| 15377 | tp->write32_rx_mbox = tg3_write32; |
| 15378 | |
| 15379 | /* Various workaround register access methods */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15380 | if (tg3_flag(tp, PCIX_TARGET_HWBUG)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 15381 | tp->write32 = tg3_write_indirect_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 15382 | 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] | 15383 | (tg3_flag(tp, PCI_EXPRESS) && |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 15384 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { |
| 15385 | /* |
| 15386 | * Back to back register writes can cause problems on these |
| 15387 | * chips, the workaround is to read back all reg writes |
| 15388 | * except those to mailbox regs. |
| 15389 | * |
| 15390 | * See tg3_write_indirect_reg32(). |
| 15391 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 15392 | tp->write32 = tg3_write_flush_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 15393 | } |
| 15394 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15395 | 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] | 15396 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15397 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 15398 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 15399 | } |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 15400 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15401 | if (tg3_flag(tp, ICH_WORKAROUND)) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15402 | tp->read32 = tg3_read_indirect_reg32; |
| 15403 | tp->write32 = tg3_write_indirect_reg32; |
| 15404 | tp->read32_mbox = tg3_read_indirect_mbox; |
| 15405 | tp->write32_mbox = tg3_write_indirect_mbox; |
| 15406 | tp->write32_tx_mbox = tg3_write_indirect_mbox; |
| 15407 | tp->write32_rx_mbox = tg3_write_indirect_mbox; |
| 15408 | |
| 15409 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 15410 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15411 | |
| 15412 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 15413 | pci_cmd &= ~PCI_COMMAND_MEMORY; |
| 15414 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 15415 | } |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 15416 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 15417 | tp->read32_mbox = tg3_read32_mbox_5906; |
| 15418 | tp->write32_mbox = tg3_write32_mbox_5906; |
| 15419 | tp->write32_tx_mbox = tg3_write32_mbox_5906; |
| 15420 | tp->write32_rx_mbox = tg3_write32_mbox_5906; |
| 15421 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15422 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 15423 | if (tp->write32 == tg3_write_indirect_reg32 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15424 | (tg3_flag(tp, PCIX_MODE) && |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 15425 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 15426 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15427 | tg3_flag_set(tp, SRAM_USE_CONFIG); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 15428 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15429 | /* The memory arbiter has to be enabled in order for SRAM accesses |
| 15430 | * to succeed. Normally on powerup the tg3 chip firmware will make |
| 15431 | * sure it is enabled, but other entities such as system netboot |
| 15432 | * code might disable it. |
| 15433 | */ |
| 15434 | val = tr32(MEMARB_MODE); |
| 15435 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 15436 | |
Matt Carlson | 9dc5e34 | 2011-11-04 09:15:02 +0000 | [diff] [blame] | 15437 | tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3; |
| 15438 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 15439 | tg3_flag(tp, 5780_CLASS)) { |
| 15440 | if (tg3_flag(tp, PCIX_MODE)) { |
| 15441 | pci_read_config_dword(tp->pdev, |
| 15442 | tp->pcix_cap + PCI_X_STATUS, |
| 15443 | &val); |
| 15444 | tp->pci_fn = val & 0x7; |
| 15445 | } |
Michael Chan | 857001f | 2013-01-06 12:51:09 +0000 | [diff] [blame] | 15446 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 15447 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Matt Carlson | 9dc5e34 | 2011-11-04 09:15:02 +0000 | [diff] [blame] | 15448 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
| 15449 | tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val); |
Michael Chan | 857001f | 2013-01-06 12:51:09 +0000 | [diff] [blame] | 15450 | if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) != NIC_SRAM_CPMUSTAT_SIG) |
| 15451 | val = tr32(TG3_CPMU_STATUS); |
| 15452 | |
| 15453 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
| 15454 | tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5717) ? 1 : 0; |
| 15455 | else |
Matt Carlson | 9dc5e34 | 2011-11-04 09:15:02 +0000 | [diff] [blame] | 15456 | tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5719) >> |
| 15457 | TG3_CPMU_STATUS_FSHFT_5719; |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 15458 | } |
| 15459 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 15460 | /* Get eeprom hw config before calling tg3_set_power_state(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15461 | * In particular, the TG3_FLAG_IS_NIC flag must be |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 15462 | * determined before calling tg3_set_power_state() so that |
| 15463 | * we know whether or not to switch out of Vaux power. |
| 15464 | * When the flag is set, it means that GPIO1 is used for eeprom |
| 15465 | * write protect and also implies that it is a LOM where GPIOs |
| 15466 | * are not used to switch power. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 15467 | */ |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 15468 | tg3_get_eeprom_hw_cfg(tp); |
| 15469 | |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 15470 | if (tp->fw_needed && tg3_flag(tp, ENABLE_ASF)) { |
| 15471 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 15472 | tg3_flag_clear(tp, TSO_BUG); |
| 15473 | tp->fw_needed = NULL; |
| 15474 | } |
| 15475 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15476 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15477 | /* Allow reads and writes to the |
| 15478 | * APE register and memory space. |
| 15479 | */ |
| 15480 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 15481 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 15482 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15483 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 15484 | pci_state_reg); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15485 | |
| 15486 | tg3_ape_lock_init(tp); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15487 | } |
| 15488 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15489 | /* Set up tp->grc_local_ctrl before calling |
| 15490 | * tg3_pwrsrc_switch_to_vmain(). GPIO1 driven high |
| 15491 | * will bring 5700's external PHY out of reset. |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 15492 | * It is also used as eeprom write protect on LOMs. |
| 15493 | */ |
| 15494 | 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] | 15495 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15496 | tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 15497 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 15498 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 15499 | /* Unused GPIO3 must be driven as output on 5752 because there |
| 15500 | * are no pull-up resistors on unused GPIO pins. |
| 15501 | */ |
| 15502 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 15503 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 15504 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 15505 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | cb4ed1f | 2010-01-20 16:58:09 +0000 | [diff] [blame] | 15506 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 15507 | tg3_flag(tp, 57765_CLASS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 15508 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 15509 | |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 15510 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 15511 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 15512 | /* Turn off the debug UART. */ |
| 15513 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15514 | if (tg3_flag(tp, IS_NIC)) |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 15515 | /* Keep VMain power. */ |
| 15516 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 15517 | GRC_LCLCTRL_GPIO_OUTPUT0; |
| 15518 | } |
| 15519 | |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 15520 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
| 15521 | tp->grc_local_ctrl |= |
| 15522 | tr32(GRC_LOCAL_CTRL) & GRC_LCLCTRL_GPIO_UART_SEL; |
| 15523 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15524 | /* Switch out of Vaux if it is a NIC */ |
| 15525 | tg3_pwrsrc_switch_to_vmain(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15527 | /* Derive initial jumbo mode from MTU assigned in |
| 15528 | * ether_setup() via the alloc_etherdev() call |
| 15529 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15530 | if (tp->dev->mtu > ETH_DATA_LEN && !tg3_flag(tp, 5780_CLASS)) |
| 15531 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15532 | |
| 15533 | /* Determine WakeOnLan speed to use. */ |
| 15534 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 15535 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 15536 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || |
| 15537 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15538 | tg3_flag_clear(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15539 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15540 | tg3_flag_set(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15541 | } |
| 15542 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 15543 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15544 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 15545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15546 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 15547 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 15548 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15549 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 15550 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15551 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
| 15552 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 15553 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15554 | |
| 15555 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || |
| 15556 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15557 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15558 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15559 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15560 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15561 | if (tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15562 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 15563 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 15564 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15565 | !tg3_flag(tp, 57765_PLUS)) { |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 15566 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 15567 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 15568 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 15569 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
Michael Chan | d4011ad | 2007-02-13 12:17:25 -0800 | [diff] [blame] | 15570 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
| 15571 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15572 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 15573 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15574 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 15575 | } else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15576 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 15577 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15578 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 15579 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 15580 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 15581 | tp->phy_otp = tg3_read_otp_phycfg(tp); |
| 15582 | if (tp->phy_otp == 0) |
| 15583 | tp->phy_otp = TG3_OTP_DEFAULT; |
| 15584 | } |
| 15585 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15586 | if (tg3_flag(tp, CPMU_PRESENT)) |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 15587 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
| 15588 | else |
| 15589 | tp->mi_mode = MAC_MI_MODE_BASE; |
| 15590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15591 | tp->coalesce_mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15592 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
| 15593 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) |
| 15594 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
| 15595 | |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 15596 | /* Set these bits to enable statistics workaround. */ |
| 15597 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 15598 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || |
| 15599 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) { |
| 15600 | tp->coalesce_mode |= HOSTCC_MODE_ATTN; |
| 15601 | tp->grc_mode |= GRC_MODE_IRQ_ON_FLOW_ATTN; |
| 15602 | } |
| 15603 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 15604 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 15605 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15606 | tg3_flag_set(tp, USE_PHYLIB); |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 15607 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15608 | err = tg3_mdio_init(tp); |
| 15609 | if (err) |
| 15610 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15611 | |
| 15612 | /* Initialize data/descriptor byte/word swapping. */ |
| 15613 | val = tr32(GRC_MODE); |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 15614 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 15615 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 15616 | val &= (GRC_MODE_BYTE_SWAP_B2HRX_DATA | |
| 15617 | GRC_MODE_WORD_SWAP_B2HRX_DATA | |
| 15618 | GRC_MODE_B2HRX_ENABLE | |
| 15619 | GRC_MODE_HTX2B_ENABLE | |
| 15620 | GRC_MODE_HOST_STACKUP); |
| 15621 | else |
| 15622 | val &= GRC_MODE_HOST_STACKUP; |
| 15623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15624 | tw32(GRC_MODE, val | tp->grc_mode); |
| 15625 | |
| 15626 | tg3_switch_clocks(tp); |
| 15627 | |
| 15628 | /* Clear this out for sanity. */ |
| 15629 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 15630 | |
| 15631 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 15632 | &pci_state_reg); |
| 15633 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15634 | !tg3_flag(tp, PCIX_TARGET_HWBUG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15635 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); |
| 15636 | |
| 15637 | if (chiprevid == CHIPREV_ID_5701_A0 || |
| 15638 | chiprevid == CHIPREV_ID_5701_B0 || |
| 15639 | chiprevid == CHIPREV_ID_5701_B2 || |
| 15640 | chiprevid == CHIPREV_ID_5701_B5) { |
| 15641 | void __iomem *sram_base; |
| 15642 | |
| 15643 | /* Write some dummy words into the SRAM status block |
| 15644 | * area, see if it reads back correctly. If the return |
| 15645 | * value is bad, force enable the PCIX workaround. |
| 15646 | */ |
| 15647 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; |
| 15648 | |
| 15649 | writel(0x00000000, sram_base); |
| 15650 | writel(0x00000000, sram_base + 4); |
| 15651 | writel(0xffffffff, sram_base + 4); |
| 15652 | if (readl(sram_base) != 0x00000000) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15653 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15654 | } |
| 15655 | } |
| 15656 | |
| 15657 | udelay(50); |
| 15658 | tg3_nvram_init(tp); |
| 15659 | |
| 15660 | grc_misc_cfg = tr32(GRC_MISC_CFG); |
| 15661 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; |
| 15662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15663 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 15664 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
| 15665 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15666 | tg3_flag_set(tp, IS_5788); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15667 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15668 | if (!tg3_flag(tp, IS_5788) && |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 15669 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15670 | tg3_flag_set(tp, TAGGED_STATUS); |
| 15671 | if (tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 15672 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
| 15673 | HOSTCC_MODE_CLRTICK_TXBD); |
| 15674 | |
| 15675 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; |
| 15676 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 15677 | tp->misc_host_ctrl); |
| 15678 | } |
| 15679 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 15680 | /* Preserve the APE MAC_MODE bits */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15681 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 15682 | 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] | 15683 | else |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 15684 | tp->mac_mode = 0; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 15685 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 15686 | if (tg3_10_100_only_device(tp, ent)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15687 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15688 | |
| 15689 | err = tg3_phy_probe(tp); |
| 15690 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15691 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15692 | /* ... but do not return immediately ... */ |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15693 | tg3_mdio_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15694 | } |
| 15695 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 15696 | tg3_read_vpd(tp); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 15697 | tg3_read_fw_ver(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15698 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15699 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 15700 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15701 | } else { |
| 15702 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15703 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15704 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15705 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15706 | } |
| 15707 | |
| 15708 | /* 5700 {AX,BX} chips have a broken status block link |
| 15709 | * change bit implementation, so we must use the |
| 15710 | * status register in those cases. |
| 15711 | */ |
| 15712 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15713 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15714 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15715 | tg3_flag_clear(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15716 | |
| 15717 | /* The led_ctrl is set during tg3_phy_probe, here we might |
| 15718 | * have to force the link status polling mechanism based |
| 15719 | * upon subsystem IDs. |
| 15720 | */ |
| 15721 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
Michael Chan | 007a880d | 2007-05-31 14:49:51 -0700 | [diff] [blame] | 15722 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15723 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 15724 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15725 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15726 | } |
| 15727 | |
| 15728 | /* For all SERDES we poll the MAC status register. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15729 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15730 | tg3_flag_set(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15731 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15732 | tg3_flag_clear(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15733 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 15734 | tp->rx_offset = NET_SKB_PAD + NET_IP_ALIGN; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 15735 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15736 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15737 | tg3_flag(tp, PCIX_MODE)) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 15738 | tp->rx_offset = NET_SKB_PAD; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 15739 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 15740 | tp->rx_copy_thresh = ~(u16)0; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 15741 | #endif |
| 15742 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15743 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 15744 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
| 15745 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 15746 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
| 15747 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 15748 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 15749 | |
| 15750 | /* Increment the rx prod index on the rx std ring by at most |
| 15751 | * 8 for these chips to workaround hw errata. |
| 15752 | */ |
| 15753 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 15754 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 15755 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 15756 | tp->rx_std_max_post = 8; |
| 15757 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15758 | if (tg3_flag(tp, ASPM_WORKAROUND)) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 15759 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
| 15760 | PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 15761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15762 | return err; |
| 15763 | } |
| 15764 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15765 | #ifdef CONFIG_SPARC |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15766 | static int tg3_get_macaddr_sparc(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15767 | { |
| 15768 | struct net_device *dev = tp->dev; |
| 15769 | struct pci_dev *pdev = tp->pdev; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15770 | struct device_node *dp = pci_device_to_OF_node(pdev); |
David S. Miller | 374d4ca | 2007-03-29 01:57:57 -0700 | [diff] [blame] | 15771 | const unsigned char *addr; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15772 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15773 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15774 | addr = of_get_property(dp, "local-mac-address", &len); |
| 15775 | if (addr && len == 6) { |
| 15776 | memcpy(dev->dev_addr, addr, 6); |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15777 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15778 | } |
| 15779 | return -ENODEV; |
| 15780 | } |
| 15781 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15782 | static int tg3_get_default_macaddr_sparc(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15783 | { |
| 15784 | struct net_device *dev = tp->dev; |
| 15785 | |
| 15786 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); |
| 15787 | return 0; |
| 15788 | } |
| 15789 | #endif |
| 15790 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15791 | static int tg3_get_device_address(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15792 | { |
| 15793 | struct net_device *dev = tp->dev; |
| 15794 | u32 hi, lo, mac_offset; |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 15795 | int addr_ok = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15796 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 15797 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15798 | if (!tg3_get_macaddr_sparc(tp)) |
| 15799 | return 0; |
| 15800 | #endif |
| 15801 | |
| 15802 | mac_offset = 0x7c; |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 15803 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15804 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15805 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 15806 | mac_offset = 0xcc; |
| 15807 | if (tg3_nvram_lock(tp)) |
| 15808 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); |
| 15809 | else |
| 15810 | tg3_nvram_unlock(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15811 | } else if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 15812 | if (tp->pci_fn & 1) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 15813 | mac_offset = 0xcc; |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 15814 | if (tp->pci_fn > 1) |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 15815 | mac_offset += 0x18c; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 15816 | } 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] | 15817 | mac_offset = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15818 | |
| 15819 | /* First try to get it from MAC address mailbox. */ |
| 15820 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); |
| 15821 | if ((hi >> 16) == 0x484b) { |
| 15822 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 15823 | dev->dev_addr[1] = (hi >> 0) & 0xff; |
| 15824 | |
| 15825 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); |
| 15826 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 15827 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 15828 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 15829 | dev->dev_addr[5] = (lo >> 0) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15830 | |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 15831 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
| 15832 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); |
| 15833 | } |
| 15834 | if (!addr_ok) { |
| 15835 | /* Next, try NVRAM. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15836 | if (!tg3_flag(tp, NO_NVRAM) && |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 15837 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 15838 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 15839 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
| 15840 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 15841 | } |
| 15842 | /* Finally just fetch it out of the MAC control regs. */ |
| 15843 | else { |
| 15844 | hi = tr32(MAC_ADDR_0_HIGH); |
| 15845 | lo = tr32(MAC_ADDR_0_LOW); |
| 15846 | |
| 15847 | dev->dev_addr[5] = lo & 0xff; |
| 15848 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 15849 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 15850 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 15851 | dev->dev_addr[1] = hi & 0xff; |
| 15852 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 15853 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15854 | } |
| 15855 | |
| 15856 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { |
David S. Miller | 7582a33 | 2008-03-20 15:53:15 -0700 | [diff] [blame] | 15857 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15858 | if (!tg3_get_default_macaddr_sparc(tp)) |
| 15859 | return 0; |
| 15860 | #endif |
| 15861 | return -EINVAL; |
| 15862 | } |
| 15863 | return 0; |
| 15864 | } |
| 15865 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15866 | #define BOUNDARY_SINGLE_CACHELINE 1 |
| 15867 | #define BOUNDARY_MULTI_CACHELINE 2 |
| 15868 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15869 | static u32 tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15870 | { |
| 15871 | int cacheline_size; |
| 15872 | u8 byte; |
| 15873 | int goal; |
| 15874 | |
| 15875 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); |
| 15876 | if (byte == 0) |
| 15877 | cacheline_size = 1024; |
| 15878 | else |
| 15879 | cacheline_size = (int) byte * 4; |
| 15880 | |
| 15881 | /* On 5703 and later chips, the boundary bits have no |
| 15882 | * effect. |
| 15883 | */ |
| 15884 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 15885 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15886 | !tg3_flag(tp, PCI_EXPRESS)) |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15887 | goto out; |
| 15888 | |
| 15889 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) |
| 15890 | goal = BOUNDARY_MULTI_CACHELINE; |
| 15891 | #else |
| 15892 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) |
| 15893 | goal = BOUNDARY_SINGLE_CACHELINE; |
| 15894 | #else |
| 15895 | goal = 0; |
| 15896 | #endif |
| 15897 | #endif |
| 15898 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15899 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 15900 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 15901 | goto out; |
| 15902 | } |
| 15903 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15904 | if (!goal) |
| 15905 | goto out; |
| 15906 | |
| 15907 | /* PCI controllers on most RISC systems tend to disconnect |
| 15908 | * when a device tries to burst across a cache-line boundary. |
| 15909 | * Therefore, letting tg3 do so just wastes PCI bandwidth. |
| 15910 | * |
| 15911 | * Unfortunately, for PCI-E there are only limited |
| 15912 | * write-side controls for this, and thus for reads |
| 15913 | * we will still get the disconnects. We'll also waste |
| 15914 | * these PCI cycles for both read and write for chips |
| 15915 | * other than 5700 and 5701 which do not implement the |
| 15916 | * boundary bits. |
| 15917 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15918 | if (tg3_flag(tp, PCIX_MODE) && !tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15919 | switch (cacheline_size) { |
| 15920 | case 16: |
| 15921 | case 32: |
| 15922 | case 64: |
| 15923 | case 128: |
| 15924 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15925 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | |
| 15926 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); |
| 15927 | } else { |
| 15928 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 15929 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 15930 | } |
| 15931 | break; |
| 15932 | |
| 15933 | case 256: |
| 15934 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | |
| 15935 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); |
| 15936 | break; |
| 15937 | |
| 15938 | default: |
| 15939 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 15940 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 15941 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15942 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15943 | } else if (tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15944 | switch (cacheline_size) { |
| 15945 | case 16: |
| 15946 | case 32: |
| 15947 | case 64: |
| 15948 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15949 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 15950 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; |
| 15951 | break; |
| 15952 | } |
| 15953 | /* fallthrough */ |
| 15954 | case 128: |
| 15955 | default: |
| 15956 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 15957 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; |
| 15958 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 15959 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 15960 | } else { |
| 15961 | switch (cacheline_size) { |
| 15962 | case 16: |
| 15963 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15964 | val |= (DMA_RWCTRL_READ_BNDRY_16 | |
| 15965 | DMA_RWCTRL_WRITE_BNDRY_16); |
| 15966 | break; |
| 15967 | } |
| 15968 | /* fallthrough */ |
| 15969 | case 32: |
| 15970 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15971 | val |= (DMA_RWCTRL_READ_BNDRY_32 | |
| 15972 | DMA_RWCTRL_WRITE_BNDRY_32); |
| 15973 | break; |
| 15974 | } |
| 15975 | /* fallthrough */ |
| 15976 | case 64: |
| 15977 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15978 | val |= (DMA_RWCTRL_READ_BNDRY_64 | |
| 15979 | DMA_RWCTRL_WRITE_BNDRY_64); |
| 15980 | break; |
| 15981 | } |
| 15982 | /* fallthrough */ |
| 15983 | case 128: |
| 15984 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 15985 | val |= (DMA_RWCTRL_READ_BNDRY_128 | |
| 15986 | DMA_RWCTRL_WRITE_BNDRY_128); |
| 15987 | break; |
| 15988 | } |
| 15989 | /* fallthrough */ |
| 15990 | case 256: |
| 15991 | val |= (DMA_RWCTRL_READ_BNDRY_256 | |
| 15992 | DMA_RWCTRL_WRITE_BNDRY_256); |
| 15993 | break; |
| 15994 | case 512: |
| 15995 | val |= (DMA_RWCTRL_READ_BNDRY_512 | |
| 15996 | DMA_RWCTRL_WRITE_BNDRY_512); |
| 15997 | break; |
| 15998 | case 1024: |
| 15999 | default: |
| 16000 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | |
| 16001 | DMA_RWCTRL_WRITE_BNDRY_1024); |
| 16002 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 16003 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16004 | } |
| 16005 | |
| 16006 | out: |
| 16007 | return val; |
| 16008 | } |
| 16009 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16010 | static int tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, |
| 16011 | int size, int to_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16012 | { |
| 16013 | struct tg3_internal_buffer_desc test_desc; |
| 16014 | u32 sram_dma_descs; |
| 16015 | int i, ret; |
| 16016 | |
| 16017 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; |
| 16018 | |
| 16019 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); |
| 16020 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); |
| 16021 | tw32(RDMAC_STATUS, 0); |
| 16022 | tw32(WDMAC_STATUS, 0); |
| 16023 | |
| 16024 | tw32(BUFMGR_MODE, 0); |
| 16025 | tw32(FTQ_RESET, 0); |
| 16026 | |
| 16027 | test_desc.addr_hi = ((u64) buf_dma) >> 32; |
| 16028 | test_desc.addr_lo = buf_dma & 0xffffffff; |
| 16029 | test_desc.nic_mbuf = 0x00002100; |
| 16030 | test_desc.len = size; |
| 16031 | |
| 16032 | /* |
| 16033 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz |
| 16034 | * the *second* time the tg3 driver was getting loaded after an |
| 16035 | * initial scan. |
| 16036 | * |
| 16037 | * Broadcom tells me: |
| 16038 | * ...the DMA engine is connected to the GRC block and a DMA |
| 16039 | * reset may affect the GRC block in some unpredictable way... |
| 16040 | * The behavior of resets to individual blocks has not been tested. |
| 16041 | * |
| 16042 | * Broadcom noted the GRC reset will also reset all sub-components. |
| 16043 | */ |
| 16044 | if (to_device) { |
| 16045 | test_desc.cqid_sqid = (13 << 8) | 2; |
| 16046 | |
| 16047 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); |
| 16048 | udelay(40); |
| 16049 | } else { |
| 16050 | test_desc.cqid_sqid = (16 << 8) | 7; |
| 16051 | |
| 16052 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); |
| 16053 | udelay(40); |
| 16054 | } |
| 16055 | test_desc.flags = 0x00000005; |
| 16056 | |
| 16057 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { |
| 16058 | u32 val; |
| 16059 | |
| 16060 | val = *(((u32 *)&test_desc) + i); |
| 16061 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, |
| 16062 | sram_dma_descs + (i * sizeof(u32))); |
| 16063 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 16064 | } |
| 16065 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 16066 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 16067 | if (to_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16068 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 16069 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16070 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16071 | |
| 16072 | ret = -ENODEV; |
| 16073 | for (i = 0; i < 40; i++) { |
| 16074 | u32 val; |
| 16075 | |
| 16076 | if (to_device) |
| 16077 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); |
| 16078 | else |
| 16079 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); |
| 16080 | if ((val & 0xffff) == sram_dma_descs) { |
| 16081 | ret = 0; |
| 16082 | break; |
| 16083 | } |
| 16084 | |
| 16085 | udelay(100); |
| 16086 | } |
| 16087 | |
| 16088 | return ret; |
| 16089 | } |
| 16090 | |
David S. Miller | ded7340 | 2005-05-23 13:59:47 -0700 | [diff] [blame] | 16091 | #define TEST_BUFFER_SIZE 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16092 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 16093 | static DEFINE_PCI_DEVICE_TABLE(tg3_dma_wait_state_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 16094 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
| 16095 | { }, |
| 16096 | }; |
| 16097 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16098 | static int tg3_test_dma(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16099 | { |
| 16100 | dma_addr_t buf_dma; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16101 | u32 *buf, saved_dma_rwctrl; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 16102 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16103 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 16104 | buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
| 16105 | &buf_dma, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16106 | if (!buf) { |
| 16107 | ret = -ENOMEM; |
| 16108 | goto out_nofree; |
| 16109 | } |
| 16110 | |
| 16111 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | |
| 16112 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); |
| 16113 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16114 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16115 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16116 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 16117 | goto out; |
| 16118 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16119 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16120 | /* DMA read watermark not used on PCIE */ |
| 16121 | tp->dma_rwctrl |= 0x00180000; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16122 | } else if (!tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 16123 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 16124 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16125 | tp->dma_rwctrl |= 0x003f0000; |
| 16126 | else |
| 16127 | tp->dma_rwctrl |= 0x003f000f; |
| 16128 | } else { |
| 16129 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 16130 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 16131 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 16132 | u32 read_water = 0x7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16133 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 16134 | /* If the 5704 is behind the EPB bridge, we can |
| 16135 | * do the less restrictive ONE_DMA workaround for |
| 16136 | * better performance. |
| 16137 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16138 | if (tg3_flag(tp, 40BIT_DMA_BUG) && |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 16139 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 16140 | tp->dma_rwctrl |= 0x8000; |
| 16141 | else if (ccval == 0x6 || ccval == 0x7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16142 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 16143 | |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 16144 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
| 16145 | read_water = 4; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16146 | /* Set bit 23 to enable PCIX hw bug fix */ |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 16147 | tp->dma_rwctrl |= |
| 16148 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | |
| 16149 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | |
| 16150 | (1 << 23); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 16151 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
| 16152 | /* 5780 always in PCIX mode */ |
| 16153 | tp->dma_rwctrl |= 0x00144000; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 16154 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 16155 | /* 5714 always in PCIX mode */ |
| 16156 | tp->dma_rwctrl |= 0x00148000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16157 | } else { |
| 16158 | tp->dma_rwctrl |= 0x001b000f; |
| 16159 | } |
| 16160 | } |
| 16161 | |
| 16162 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 16163 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 16164 | tp->dma_rwctrl &= 0xfffffff0; |
| 16165 | |
| 16166 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 16167 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 16168 | /* Remove this if it causes problems for some boards. */ |
| 16169 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; |
| 16170 | |
| 16171 | /* On 5700/5701 chips, we need to set this bit. |
| 16172 | * Otherwise the chip will issue cacheline transactions |
| 16173 | * to streamable DMA memory with not all the byte |
| 16174 | * enables turned on. This is an error on several |
| 16175 | * RISC PCI controllers, in particular sparc64. |
| 16176 | * |
| 16177 | * On 5703/5704 chips, this bit has been reassigned |
| 16178 | * a different meaning. In particular, it is used |
| 16179 | * on those chips to enable a PCI-X workaround. |
| 16180 | */ |
| 16181 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; |
| 16182 | } |
| 16183 | |
| 16184 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 16185 | |
| 16186 | #if 0 |
| 16187 | /* Unneeded, already done by tg3_get_invariants. */ |
| 16188 | tg3_switch_clocks(tp); |
| 16189 | #endif |
| 16190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16191 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 16192 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 16193 | goto out; |
| 16194 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16195 | /* It is best to perform DMA test with maximum write burst size |
| 16196 | * to expose the 5700/5701 write DMA bug. |
| 16197 | */ |
| 16198 | saved_dma_rwctrl = tp->dma_rwctrl; |
| 16199 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 16200 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 16201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16202 | while (1) { |
| 16203 | u32 *p = buf, i; |
| 16204 | |
| 16205 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) |
| 16206 | p[i] = i; |
| 16207 | |
| 16208 | /* Send the buffer to the chip. */ |
| 16209 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); |
| 16210 | if (ret) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16211 | dev_err(&tp->pdev->dev, |
| 16212 | "%s: Buffer write failed. err = %d\n", |
| 16213 | __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16214 | break; |
| 16215 | } |
| 16216 | |
| 16217 | #if 0 |
| 16218 | /* validate data reached card RAM correctly. */ |
| 16219 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 16220 | u32 val; |
| 16221 | tg3_read_mem(tp, 0x2100 + (i*4), &val); |
| 16222 | if (le32_to_cpu(val) != p[i]) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16223 | dev_err(&tp->pdev->dev, |
| 16224 | "%s: Buffer corrupted on device! " |
| 16225 | "(%d != %d)\n", __func__, val, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16226 | /* ret = -ENODEV here? */ |
| 16227 | } |
| 16228 | p[i] = 0; |
| 16229 | } |
| 16230 | #endif |
| 16231 | /* Now read it back. */ |
| 16232 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); |
| 16233 | if (ret) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 16234 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
| 16235 | "err = %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16236 | break; |
| 16237 | } |
| 16238 | |
| 16239 | /* Verify it. */ |
| 16240 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 16241 | if (p[i] == i) |
| 16242 | continue; |
| 16243 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16244 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 16245 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 16246 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16247 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 16248 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 16249 | break; |
| 16250 | } else { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16251 | dev_err(&tp->pdev->dev, |
| 16252 | "%s: Buffer corrupted on read back! " |
| 16253 | "(%d != %d)\n", __func__, p[i], i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16254 | ret = -ENODEV; |
| 16255 | goto out; |
| 16256 | } |
| 16257 | } |
| 16258 | |
| 16259 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { |
| 16260 | /* Success. */ |
| 16261 | ret = 0; |
| 16262 | break; |
| 16263 | } |
| 16264 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16265 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 16266 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 16267 | /* DMA test passed without adjusting DMA boundary, |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 16268 | * now look for chipsets that are known to expose the |
| 16269 | * DMA bug without failing the test. |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16270 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 16271 | if (pci_dev_present(tg3_dma_wait_state_chipsets)) { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 16272 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 16273 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 16274 | } else { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 16275 | /* Safe to use the calculated DMA boundary. */ |
| 16276 | tp->dma_rwctrl = saved_dma_rwctrl; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 16277 | } |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 16278 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16279 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 16280 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16281 | |
| 16282 | out: |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 16283 | dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16284 | out_nofree: |
| 16285 | return ret; |
| 16286 | } |
| 16287 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16288 | static void tg3_init_bufmgr_config(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16289 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16290 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 16291 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 16292 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 16293 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 16294 | DEFAULT_MB_MACRX_LOW_WATER_57765; |
| 16295 | tp->bufmgr_config.mbuf_high_water = |
| 16296 | DEFAULT_MB_HIGH_WATER_57765; |
| 16297 | |
| 16298 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 16299 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 16300 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 16301 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; |
| 16302 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 16303 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16304 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 16305 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 16306 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 16307 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 16308 | DEFAULT_MB_MACRX_LOW_WATER_5705; |
| 16309 | tp->bufmgr_config.mbuf_high_water = |
| 16310 | DEFAULT_MB_HIGH_WATER_5705; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 16311 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 16312 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 16313 | DEFAULT_MB_MACRX_LOW_WATER_5906; |
| 16314 | tp->bufmgr_config.mbuf_high_water = |
| 16315 | DEFAULT_MB_HIGH_WATER_5906; |
| 16316 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16317 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 16318 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 16319 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; |
| 16320 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 16321 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; |
| 16322 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 16323 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; |
| 16324 | } else { |
| 16325 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 16326 | DEFAULT_MB_RDMA_LOW_WATER; |
| 16327 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 16328 | DEFAULT_MB_MACRX_LOW_WATER; |
| 16329 | tp->bufmgr_config.mbuf_high_water = |
| 16330 | DEFAULT_MB_HIGH_WATER; |
| 16331 | |
| 16332 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 16333 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; |
| 16334 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 16335 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; |
| 16336 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 16337 | DEFAULT_MB_HIGH_WATER_JUMBO; |
| 16338 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16339 | |
| 16340 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; |
| 16341 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; |
| 16342 | } |
| 16343 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16344 | static char *tg3_phy_string(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16345 | { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 16346 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
| 16347 | case TG3_PHY_ID_BCM5400: return "5400"; |
| 16348 | case TG3_PHY_ID_BCM5401: return "5401"; |
| 16349 | case TG3_PHY_ID_BCM5411: return "5411"; |
| 16350 | case TG3_PHY_ID_BCM5701: return "5701"; |
| 16351 | case TG3_PHY_ID_BCM5703: return "5703"; |
| 16352 | case TG3_PHY_ID_BCM5704: return "5704"; |
| 16353 | case TG3_PHY_ID_BCM5705: return "5705"; |
| 16354 | case TG3_PHY_ID_BCM5750: return "5750"; |
| 16355 | case TG3_PHY_ID_BCM5752: return "5752"; |
| 16356 | case TG3_PHY_ID_BCM5714: return "5714"; |
| 16357 | case TG3_PHY_ID_BCM5780: return "5780"; |
| 16358 | case TG3_PHY_ID_BCM5755: return "5755"; |
| 16359 | case TG3_PHY_ID_BCM5787: return "5787"; |
| 16360 | case TG3_PHY_ID_BCM5784: return "5784"; |
| 16361 | case TG3_PHY_ID_BCM5756: return "5722/5756"; |
| 16362 | case TG3_PHY_ID_BCM5906: return "5906"; |
| 16363 | case TG3_PHY_ID_BCM5761: return "5761"; |
| 16364 | case TG3_PHY_ID_BCM5718C: return "5718C"; |
| 16365 | case TG3_PHY_ID_BCM5718S: return "5718S"; |
| 16366 | case TG3_PHY_ID_BCM57765: return "57765"; |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 16367 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
Matt Carlson | 6418f2c | 2011-04-05 14:22:49 +0000 | [diff] [blame] | 16368 | case TG3_PHY_ID_BCM5720C: return "5720C"; |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 16369 | case TG3_PHY_ID_BCM5762: return "5762C"; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 16370 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16371 | case 0: return "serdes"; |
| 16372 | default: return "unknown"; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 16373 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16374 | } |
| 16375 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16376 | static char *tg3_bus_string(struct tg3 *tp, char *str) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 16377 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16378 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 16379 | strcpy(str, "PCI Express"); |
| 16380 | return str; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16381 | } else if (tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 16382 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
| 16383 | |
| 16384 | strcpy(str, "PCIX:"); |
| 16385 | |
| 16386 | if ((clock_ctrl == 7) || |
| 16387 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == |
| 16388 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) |
| 16389 | strcat(str, "133MHz"); |
| 16390 | else if (clock_ctrl == 0) |
| 16391 | strcat(str, "33MHz"); |
| 16392 | else if (clock_ctrl == 2) |
| 16393 | strcat(str, "50MHz"); |
| 16394 | else if (clock_ctrl == 4) |
| 16395 | strcat(str, "66MHz"); |
| 16396 | else if (clock_ctrl == 6) |
| 16397 | strcat(str, "100MHz"); |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 16398 | } else { |
| 16399 | strcpy(str, "PCI:"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16400 | if (tg3_flag(tp, PCI_HIGH_SPEED)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 16401 | strcat(str, "66MHz"); |
| 16402 | else |
| 16403 | strcat(str, "33MHz"); |
| 16404 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16405 | if (tg3_flag(tp, PCI_32BIT)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 16406 | strcat(str, ":32-bit"); |
| 16407 | else |
| 16408 | strcat(str, ":64-bit"); |
| 16409 | return str; |
| 16410 | } |
| 16411 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16412 | static void tg3_init_coal(struct tg3 *tp) |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 16413 | { |
| 16414 | struct ethtool_coalesce *ec = &tp->coal; |
| 16415 | |
| 16416 | memset(ec, 0, sizeof(*ec)); |
| 16417 | ec->cmd = ETHTOOL_GCOALESCE; |
| 16418 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; |
| 16419 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; |
| 16420 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; |
| 16421 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; |
| 16422 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; |
| 16423 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; |
| 16424 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; |
| 16425 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; |
| 16426 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; |
| 16427 | |
| 16428 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | |
| 16429 | HOSTCC_MODE_CLRTICK_TXBD)) { |
| 16430 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; |
| 16431 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; |
| 16432 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; |
| 16433 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; |
| 16434 | } |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 16435 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16436 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 16437 | ec->rx_coalesce_usecs_irq = 0; |
| 16438 | ec->tx_coalesce_usecs_irq = 0; |
| 16439 | ec->stats_block_coalesce_usecs = 0; |
| 16440 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 16441 | } |
| 16442 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16443 | static int tg3_init_one(struct pci_dev *pdev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16444 | const struct pci_device_id *ent) |
| 16445 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16446 | struct net_device *dev; |
| 16447 | struct tg3 *tp; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 16448 | int i, err, pm_cap; |
| 16449 | u32 sndmbx, rcvmbx, intmbx; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 16450 | char str[40]; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16451 | u64 dma_mask, persist_dma_mask; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 16452 | netdev_features_t features = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16453 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 16454 | printk_once(KERN_INFO "%s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16455 | |
| 16456 | err = pci_enable_device(pdev); |
| 16457 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16458 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16459 | return err; |
| 16460 | } |
| 16461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16462 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 16463 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16464 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16465 | goto err_out_disable_pdev; |
| 16466 | } |
| 16467 | |
| 16468 | pci_set_master(pdev); |
| 16469 | |
| 16470 | /* Find power-management capability. */ |
| 16471 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 16472 | if (pm_cap == 0) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16473 | dev_err(&pdev->dev, |
| 16474 | "Cannot find Power Management capability, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16475 | err = -EIO; |
| 16476 | goto err_out_free_res; |
| 16477 | } |
| 16478 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 16479 | err = pci_set_power_state(pdev, PCI_D0); |
| 16480 | if (err) { |
| 16481 | dev_err(&pdev->dev, "Transition to D0 failed, aborting\n"); |
| 16482 | goto err_out_free_res; |
| 16483 | } |
| 16484 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 16485 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16486 | if (!dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16487 | err = -ENOMEM; |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 16488 | goto err_out_power_down; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16489 | } |
| 16490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16491 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 16492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16493 | tp = netdev_priv(dev); |
| 16494 | tp->pdev = pdev; |
| 16495 | tp->dev = dev; |
| 16496 | tp->pm_cap = pm_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16497 | tp->rx_mode = TG3_DEF_RX_MODE; |
| 16498 | tp->tx_mode = TG3_DEF_TX_MODE; |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 16499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16500 | if (tg3_debug > 0) |
| 16501 | tp->msg_enable = tg3_debug; |
| 16502 | else |
| 16503 | tp->msg_enable = TG3_DEF_MSG_ENABLE; |
| 16504 | |
| 16505 | /* The word/byte swap controls here control register access byte |
| 16506 | * swapping. DMA data byte swapping is controlled in the GRC_MODE |
| 16507 | * setting below. |
| 16508 | */ |
| 16509 | tp->misc_host_ctrl = |
| 16510 | MISC_HOST_CTRL_MASK_PCI_INT | |
| 16511 | MISC_HOST_CTRL_WORD_SWAP | |
| 16512 | MISC_HOST_CTRL_INDIR_ACCESS | |
| 16513 | MISC_HOST_CTRL_PCISTATE_RW; |
| 16514 | |
| 16515 | /* The NONFRM (non-frame) byte/word swap controls take effect |
| 16516 | * on descriptor entries, anything which isn't packet data. |
| 16517 | * |
| 16518 | * The StrongARM chips on the board (one for tx, one for rx) |
| 16519 | * are running in big-endian mode. |
| 16520 | */ |
| 16521 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | |
| 16522 | GRC_MODE_WSWAP_NONFRM_DATA); |
| 16523 | #ifdef __BIG_ENDIAN |
| 16524 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; |
| 16525 | #endif |
| 16526 | spin_lock_init(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16527 | spin_lock_init(&tp->indirect_lock); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 16528 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16529 | |
Matt Carlson | d5fe488 | 2008-11-21 17:20:32 -0800 | [diff] [blame] | 16530 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 16531 | if (!tp->regs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16532 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16533 | err = -ENOMEM; |
| 16534 | goto err_out_free_dev; |
| 16535 | } |
| 16536 | |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16537 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 16538 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761E || |
| 16539 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S || |
| 16540 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761SE || |
| 16541 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 16542 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C || |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16543 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 16544 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 16545 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720 || |
| 16546 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5762 || |
| 16547 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725 || |
| 16548 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5727) { |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16549 | tg3_flag_set(tp, ENABLE_APE); |
| 16550 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
| 16551 | if (!tp->aperegs) { |
| 16552 | dev_err(&pdev->dev, |
| 16553 | "Cannot map APE registers, aborting\n"); |
| 16554 | err = -ENOMEM; |
| 16555 | goto err_out_iounmap; |
| 16556 | } |
| 16557 | } |
| 16558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16559 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
| 16560 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16562 | dev->ethtool_ops = &tg3_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16563 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 16564 | dev->netdev_ops = &tg3_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16565 | dev->irq = pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16566 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 16567 | err = tg3_get_invariants(tp, ent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16568 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16569 | dev_err(&pdev->dev, |
| 16570 | "Problem fetching invariants of chip, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16571 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16572 | } |
| 16573 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 16574 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
| 16575 | * device behind the EPB cannot support DMA addresses > 40-bit. |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16576 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
| 16577 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and |
| 16578 | * do DMA address check in tg3_start_xmit(). |
| 16579 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16580 | if (tg3_flag(tp, IS_5788)) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 16581 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16582 | else if (tg3_flag(tp, 40BIT_DMA_BUG)) { |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 16583 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16584 | #ifdef CONFIG_HIGHMEM |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 16585 | dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16586 | #endif |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 16587 | } else |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 16588 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16589 | |
| 16590 | /* Configure DMA attributes. */ |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 16591 | if (dma_mask > DMA_BIT_MASK(32)) { |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16592 | err = pci_set_dma_mask(pdev, dma_mask); |
| 16593 | if (!err) { |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16594 | features |= NETIF_F_HIGHDMA; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16595 | err = pci_set_consistent_dma_mask(pdev, |
| 16596 | persist_dma_mask); |
| 16597 | if (err < 0) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16598 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
| 16599 | "DMA for consistent allocations\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16600 | goto err_out_apeunmap; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16601 | } |
| 16602 | } |
| 16603 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 16604 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
| 16605 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16606 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16607 | dev_err(&pdev->dev, |
| 16608 | "No usable DMA configuration, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16609 | goto err_out_apeunmap; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 16610 | } |
| 16611 | } |
| 16612 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 16613 | tg3_init_bufmgr_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16614 | |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16615 | features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 16616 | |
| 16617 | /* 5700 B0 chips do not support checksumming correctly due |
| 16618 | * to hardware bugs. |
| 16619 | */ |
| 16620 | if (tp->pci_chip_rev_id != CHIPREV_ID_5700_B0) { |
| 16621 | features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
| 16622 | |
| 16623 | if (tg3_flag(tp, 5755_PLUS)) |
| 16624 | features |= NETIF_F_IPV6_CSUM; |
| 16625 | } |
| 16626 | |
Michael Chan | 4e3a7aa | 2006-03-20 17:47:44 -0800 | [diff] [blame] | 16627 | /* TSO is on by default on chips that support hardware TSO. |
| 16628 | * Firmware TSO on older chips gives lower performance, so it |
| 16629 | * is off by default, but can be enabled using ethtool. |
| 16630 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16631 | if ((tg3_flag(tp, HW_TSO_1) || |
| 16632 | tg3_flag(tp, HW_TSO_2) || |
| 16633 | tg3_flag(tp, HW_TSO_3)) && |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16634 | (features & NETIF_F_IP_CSUM)) |
| 16635 | features |= NETIF_F_TSO; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16636 | 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] | 16637 | if (features & NETIF_F_IPV6_CSUM) |
| 16638 | features |= NETIF_F_TSO6; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16639 | if (tg3_flag(tp, HW_TSO_3) || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 16640 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 16641 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 16642 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16643 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 16644 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16645 | features |= NETIF_F_TSO_ECN; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 16646 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16647 | |
Matt Carlson | d542fe2 | 2011-05-19 16:02:43 +0000 | [diff] [blame] | 16648 | dev->features |= features; |
| 16649 | dev->vlan_features |= features; |
| 16650 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 16651 | /* |
| 16652 | * Add loopback capability only for a subset of devices that support |
| 16653 | * MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY |
| 16654 | * loopback for the remaining devices. |
| 16655 | */ |
| 16656 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && |
| 16657 | !tg3_flag(tp, CPMU_PRESENT)) |
| 16658 | /* Add the loopback capability */ |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16659 | features |= NETIF_F_LOOPBACK; |
| 16660 | |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 16661 | dev->hw_features |= features; |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 16662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16663 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16664 | !tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16665 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16666 | tg3_flag_set(tp, MAX_RXPEND_64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16667 | tp->rx_pending = 63; |
| 16668 | } |
| 16669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16670 | err = tg3_get_device_address(tp); |
| 16671 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16672 | dev_err(&pdev->dev, |
| 16673 | "Could not obtain valid ethernet address, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16674 | goto err_out_apeunmap; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16675 | } |
| 16676 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 16677 | /* |
| 16678 | * Reset chip in case UNDI or EFI driver did not shutdown |
| 16679 | * DMA self test will enable WDMAC and we'll see (spurious) |
| 16680 | * pending DMA on the PCI bus at that point. |
| 16681 | */ |
| 16682 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
| 16683 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 16684 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
| 16685 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 16686 | } |
| 16687 | |
| 16688 | err = tg3_test_dma(tp); |
| 16689 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16690 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 16691 | goto err_out_apeunmap; |
| 16692 | } |
| 16693 | |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16694 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
| 16695 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; |
| 16696 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 16697 | for (i = 0; i < tp->irq_max; i++) { |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16698 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 16699 | |
| 16700 | tnapi->tp = tp; |
| 16701 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; |
| 16702 | |
| 16703 | tnapi->int_mbox = intmbx; |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 16704 | if (i <= 4) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16705 | intmbx += 0x8; |
| 16706 | else |
| 16707 | intmbx += 0x4; |
| 16708 | |
| 16709 | tnapi->consmbox = rcvmbx; |
| 16710 | tnapi->prodmbox = sndmbx; |
| 16711 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 16712 | if (i) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16713 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 16714 | else |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16715 | tnapi->coal_now = HOSTCC_MODE_NOW; |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16716 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16717 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 16718 | break; |
| 16719 | |
| 16720 | /* |
| 16721 | * If we support MSIX, we'll be using RSS. If we're using |
| 16722 | * RSS, the first vector only handles link interrupts and the |
| 16723 | * remaining vectors handle rx and tx interrupts. Reuse the |
| 16724 | * mailbox values for the next iteration. The values we setup |
| 16725 | * above are still useful for the single vectored mode. |
| 16726 | */ |
| 16727 | if (!i) |
| 16728 | continue; |
| 16729 | |
| 16730 | rcvmbx += 0x8; |
| 16731 | |
| 16732 | if (sndmbx & 0x4) |
| 16733 | sndmbx -= 0x4; |
| 16734 | else |
| 16735 | sndmbx += 0xc; |
| 16736 | } |
| 16737 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 16738 | tg3_init_coal(tp); |
| 16739 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 16740 | pci_set_drvdata(pdev, dev); |
| 16741 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 16742 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 16743 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720 || |
| 16744 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5762) |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 16745 | tg3_flag_set(tp, PTP_CAPABLE); |
| 16746 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 16747 | if (tg3_flag(tp, 5717_PLUS)) { |
| 16748 | /* Resume a low-power mode */ |
| 16749 | tg3_frob_aux_power(tp, false); |
| 16750 | } |
| 16751 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16752 | tg3_timer_init(tp); |
| 16753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16754 | err = register_netdev(dev); |
| 16755 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 16756 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16757 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16758 | } |
| 16759 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 16760 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
| 16761 | tp->board_part_number, |
| 16762 | tp->pci_chip_rev_id, |
| 16763 | tg3_bus_string(tp, str), |
| 16764 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16765 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16766 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 16767 | struct phy_device *phydev; |
| 16768 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 16769 | netdev_info(dev, |
| 16770 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 16771 | phydev->drv->name, dev_name(&phydev->dev)); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16772 | } else { |
| 16773 | char *ethtype; |
| 16774 | |
| 16775 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 16776 | ethtype = "10/100Base-TX"; |
| 16777 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 16778 | ethtype = "1000Base-SX"; |
| 16779 | else |
| 16780 | ethtype = "10/100/1000Base-T"; |
| 16781 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 16782 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 16783 | "(WireSpeed[%d], EEE[%d])\n", |
| 16784 | tg3_phy_string(tp), ethtype, |
| 16785 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0, |
| 16786 | (tp->phy_flags & TG3_PHYFLG_EEE_CAP) != 0); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16787 | } |
Matt Carlson | df59c94 | 2008-11-03 16:52:56 -0800 | [diff] [blame] | 16788 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 16789 | 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] | 16790 | (dev->features & NETIF_F_RXCSUM) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16791 | tg3_flag(tp, USE_LINKCHG_REG) != 0, |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16792 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16793 | tg3_flag(tp, ENABLE_ASF) != 0, |
| 16794 | tg3_flag(tp, TSO_CAPABLE) != 0); |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 16795 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
| 16796 | tp->dma_rwctrl, |
| 16797 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : |
| 16798 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16799 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16800 | pci_save_state(pdev); |
| 16801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16802 | return 0; |
| 16803 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16804 | err_out_apeunmap: |
| 16805 | if (tp->aperegs) { |
| 16806 | iounmap(tp->aperegs); |
| 16807 | tp->aperegs = NULL; |
| 16808 | } |
| 16809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16810 | err_out_iounmap: |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16811 | if (tp->regs) { |
| 16812 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 16813 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16814 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16815 | |
| 16816 | err_out_free_dev: |
| 16817 | free_netdev(dev); |
| 16818 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 16819 | err_out_power_down: |
| 16820 | pci_set_power_state(pdev, PCI_D3hot); |
| 16821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16822 | err_out_free_res: |
| 16823 | pci_release_regions(pdev); |
| 16824 | |
| 16825 | err_out_disable_pdev: |
| 16826 | pci_disable_device(pdev); |
| 16827 | pci_set_drvdata(pdev, NULL); |
| 16828 | return err; |
| 16829 | } |
| 16830 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16831 | static void tg3_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16832 | { |
| 16833 | struct net_device *dev = pci_get_drvdata(pdev); |
| 16834 | |
| 16835 | if (dev) { |
| 16836 | struct tg3 *tp = netdev_priv(dev); |
| 16837 | |
Jesper Juhl | e3c5530 | 2012-04-09 22:50:15 +0200 | [diff] [blame] | 16838 | release_firmware(tp->fw); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 16839 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 16840 | tg3_reset_task_cancel(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 16841 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 16842 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16843 | tg3_phy_fini(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 16844 | tg3_mdio_fini(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16845 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 16846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16847 | unregister_netdev(dev); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16848 | if (tp->aperegs) { |
| 16849 | iounmap(tp->aperegs); |
| 16850 | tp->aperegs = NULL; |
| 16851 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16852 | if (tp->regs) { |
| 16853 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 16854 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16855 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16856 | free_netdev(dev); |
| 16857 | pci_release_regions(pdev); |
| 16858 | pci_disable_device(pdev); |
| 16859 | pci_set_drvdata(pdev, NULL); |
| 16860 | } |
| 16861 | } |
| 16862 | |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 16863 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16864 | static int tg3_suspend(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16865 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16866 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16867 | struct net_device *dev = pci_get_drvdata(pdev); |
| 16868 | struct tg3 *tp = netdev_priv(dev); |
| 16869 | int err; |
| 16870 | |
| 16871 | if (!netif_running(dev)) |
| 16872 | return 0; |
| 16873 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 16874 | tg3_reset_task_cancel(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16875 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16876 | tg3_netif_stop(tp); |
| 16877 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16878 | tg3_timer_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16879 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16880 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16881 | tg3_disable_ints(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16882 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16883 | |
| 16884 | netif_device_detach(dev); |
| 16885 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16886 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 16887 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16888 | tg3_flag_clear(tp, INIT_COMPLETE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16889 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16890 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16891 | err = tg3_power_down_prepare(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16892 | if (err) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16893 | int err2; |
| 16894 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16895 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16896 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16897 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16898 | err2 = tg3_restart_hw(tp, 1); |
| 16899 | if (err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16900 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16901 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16902 | tg3_timer_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16903 | |
| 16904 | netif_device_attach(dev); |
| 16905 | tg3_netif_start(tp); |
| 16906 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16907 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16908 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16909 | |
| 16910 | if (!err2) |
| 16911 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16912 | } |
| 16913 | |
| 16914 | return err; |
| 16915 | } |
| 16916 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16917 | static int tg3_resume(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16918 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16919 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16920 | struct net_device *dev = pci_get_drvdata(pdev); |
| 16921 | struct tg3 *tp = netdev_priv(dev); |
| 16922 | int err; |
| 16923 | |
| 16924 | if (!netif_running(dev)) |
| 16925 | return 0; |
| 16926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16927 | netif_device_attach(dev); |
| 16928 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16929 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16930 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16931 | tg3_flag_set(tp, INIT_COMPLETE); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16932 | err = tg3_restart_hw(tp, 1); |
| 16933 | if (err) |
| 16934 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16935 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16936 | tg3_timer_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16938 | tg3_netif_start(tp); |
| 16939 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16940 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 16941 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16942 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16943 | if (!err) |
| 16944 | tg3_phy_start(tp); |
| 16945 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 16946 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16947 | } |
| 16948 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16949 | static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 16950 | #define TG3_PM_OPS (&tg3_pm_ops) |
| 16951 | |
| 16952 | #else |
| 16953 | |
| 16954 | #define TG3_PM_OPS NULL |
| 16955 | |
| 16956 | #endif /* CONFIG_PM_SLEEP */ |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 16957 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16958 | /** |
| 16959 | * tg3_io_error_detected - called when PCI error is detected |
| 16960 | * @pdev: Pointer to PCI device |
| 16961 | * @state: The current pci connection state |
| 16962 | * |
| 16963 | * This function is called after a PCI bus error affecting |
| 16964 | * this device has been detected. |
| 16965 | */ |
| 16966 | static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, |
| 16967 | pci_channel_state_t state) |
| 16968 | { |
| 16969 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 16970 | struct tg3 *tp = netdev_priv(netdev); |
| 16971 | pci_ers_result_t err = PCI_ERS_RESULT_NEED_RESET; |
| 16972 | |
| 16973 | netdev_info(netdev, "PCI I/O error detected\n"); |
| 16974 | |
| 16975 | rtnl_lock(); |
| 16976 | |
| 16977 | if (!netif_running(netdev)) |
| 16978 | goto done; |
| 16979 | |
| 16980 | tg3_phy_stop(tp); |
| 16981 | |
| 16982 | tg3_netif_stop(tp); |
| 16983 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 16984 | tg3_timer_stop(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16985 | |
| 16986 | /* Want to make sure that the reset task doesn't run */ |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 16987 | tg3_reset_task_cancel(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 16988 | |
| 16989 | netif_device_detach(netdev); |
| 16990 | |
| 16991 | /* Clean up software state, even if MMIO is blocked */ |
| 16992 | tg3_full_lock(tp, 0); |
| 16993 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 16994 | tg3_full_unlock(tp); |
| 16995 | |
| 16996 | done: |
| 16997 | if (state == pci_channel_io_perm_failure) |
| 16998 | err = PCI_ERS_RESULT_DISCONNECT; |
| 16999 | else |
| 17000 | pci_disable_device(pdev); |
| 17001 | |
| 17002 | rtnl_unlock(); |
| 17003 | |
| 17004 | return err; |
| 17005 | } |
| 17006 | |
| 17007 | /** |
| 17008 | * tg3_io_slot_reset - called after the pci bus has been reset. |
| 17009 | * @pdev: Pointer to PCI device |
| 17010 | * |
| 17011 | * Restart the card from scratch, as if from a cold-boot. |
| 17012 | * At this point, the card has exprienced a hard reset, |
| 17013 | * followed by fixups by BIOS, and has its config space |
| 17014 | * set up identically to what it was at cold boot. |
| 17015 | */ |
| 17016 | static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev) |
| 17017 | { |
| 17018 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 17019 | struct tg3 *tp = netdev_priv(netdev); |
| 17020 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 17021 | int err; |
| 17022 | |
| 17023 | rtnl_lock(); |
| 17024 | |
| 17025 | if (pci_enable_device(pdev)) { |
| 17026 | netdev_err(netdev, "Cannot re-enable PCI device after reset.\n"); |
| 17027 | goto done; |
| 17028 | } |
| 17029 | |
| 17030 | pci_set_master(pdev); |
| 17031 | pci_restore_state(pdev); |
| 17032 | pci_save_state(pdev); |
| 17033 | |
| 17034 | if (!netif_running(netdev)) { |
| 17035 | rc = PCI_ERS_RESULT_RECOVERED; |
| 17036 | goto done; |
| 17037 | } |
| 17038 | |
| 17039 | err = tg3_power_up(tp); |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 17040 | if (err) |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17041 | goto done; |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17042 | |
| 17043 | rc = PCI_ERS_RESULT_RECOVERED; |
| 17044 | |
| 17045 | done: |
| 17046 | rtnl_unlock(); |
| 17047 | |
| 17048 | return rc; |
| 17049 | } |
| 17050 | |
| 17051 | /** |
| 17052 | * tg3_io_resume - called when traffic can start flowing again. |
| 17053 | * @pdev: Pointer to PCI device |
| 17054 | * |
| 17055 | * This callback is called when the error recovery driver tells |
| 17056 | * us that its OK to resume normal operation. |
| 17057 | */ |
| 17058 | static void tg3_io_resume(struct pci_dev *pdev) |
| 17059 | { |
| 17060 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 17061 | struct tg3 *tp = netdev_priv(netdev); |
| 17062 | int err; |
| 17063 | |
| 17064 | rtnl_lock(); |
| 17065 | |
| 17066 | if (!netif_running(netdev)) |
| 17067 | goto done; |
| 17068 | |
| 17069 | tg3_full_lock(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17070 | tg3_flag_set(tp, INIT_COMPLETE); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17071 | err = tg3_restart_hw(tp, 1); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17072 | if (err) { |
Nithin Nayak Sujir | 3576306 | 2012-12-03 19:36:56 +0000 | [diff] [blame] | 17073 | tg3_full_unlock(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17074 | netdev_err(netdev, "Cannot restart hardware after reset.\n"); |
| 17075 | goto done; |
| 17076 | } |
| 17077 | |
| 17078 | netif_device_attach(netdev); |
| 17079 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 17080 | tg3_timer_start(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17081 | |
| 17082 | tg3_netif_start(tp); |
| 17083 | |
Nithin Nayak Sujir | 3576306 | 2012-12-03 19:36:56 +0000 | [diff] [blame] | 17084 | tg3_full_unlock(tp); |
| 17085 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17086 | tg3_phy_start(tp); |
| 17087 | |
| 17088 | done: |
| 17089 | rtnl_unlock(); |
| 17090 | } |
| 17091 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 17092 | static const struct pci_error_handlers tg3_err_handler = { |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17093 | .error_detected = tg3_io_error_detected, |
| 17094 | .slot_reset = tg3_io_slot_reset, |
| 17095 | .resume = tg3_io_resume |
| 17096 | }; |
| 17097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17098 | static struct pci_driver tg3_driver = { |
| 17099 | .name = DRV_MODULE_NAME, |
| 17100 | .id_table = tg3_pci_tbl, |
| 17101 | .probe = tg3_init_one, |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 17102 | .remove = tg3_remove_one, |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17103 | .err_handler = &tg3_err_handler, |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 17104 | .driver.pm = TG3_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17105 | }; |
| 17106 | |
| 17107 | static int __init tg3_init(void) |
| 17108 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 17109 | return pci_register_driver(&tg3_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17110 | } |
| 17111 | |
| 17112 | static void __exit tg3_cleanup(void) |
| 17113 | { |
| 17114 | pci_unregister_driver(&tg3_driver); |
| 17115 | } |
| 17116 | |
| 17117 | module_init(tg3_init); |
| 17118 | module_exit(tg3_cleanup); |