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> |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 47 | #include <linux/ssb/ssb_driver_gige.h> |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 48 | #include <linux/hwmon.h> |
| 49 | #include <linux/hwmon-sysfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #include <net/checksum.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 52 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Javier Martinez Canillas | 27fd9de | 2011-03-26 16:42:31 +0000 | [diff] [blame] | 54 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <asm/byteorder.h> |
Javier Martinez Canillas | 27fd9de | 2011-03-26 16:42:31 +0000 | [diff] [blame] | 56 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 58 | #include <uapi/linux/net_tstamp.h> |
| 59 | #include <linux/ptp_clock_kernel.h> |
| 60 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 61 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include <asm/idprom.h> |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 63 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #endif |
| 65 | |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 66 | #define BAR_0 0 |
| 67 | #define BAR_2 2 |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #include "tg3.h" |
| 70 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 71 | /* Functions & macros to verify TG3_FLAGS types */ |
| 72 | |
| 73 | static inline int _tg3_flag(enum TG3_FLAGS flag, unsigned long *bits) |
| 74 | { |
| 75 | return test_bit(flag, bits); |
| 76 | } |
| 77 | |
| 78 | static inline void _tg3_flag_set(enum TG3_FLAGS flag, unsigned long *bits) |
| 79 | { |
| 80 | set_bit(flag, bits); |
| 81 | } |
| 82 | |
| 83 | static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits) |
| 84 | { |
| 85 | clear_bit(flag, bits); |
| 86 | } |
| 87 | |
| 88 | #define tg3_flag(tp, flag) \ |
| 89 | _tg3_flag(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 90 | #define tg3_flag_set(tp, flag) \ |
| 91 | _tg3_flag_set(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 92 | #define tg3_flag_clear(tp, flag) \ |
| 93 | _tg3_flag_clear(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #define DRV_MODULE_NAME "tg3" |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 96 | #define TG3_MAJ_NUM 3 |
Nithin Sujir | 7a28fde | 2013-04-09 08:48:10 +0000 | [diff] [blame] | 97 | #define TG3_MIN_NUM 131 |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 98 | #define DRV_MODULE_VERSION \ |
| 99 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) |
Nithin Sujir | 7a28fde | 2013-04-09 08:48:10 +0000 | [diff] [blame] | 100 | #define DRV_MODULE_RELDATE "April 09, 2013" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 102 | #define RESET_KIND_SHUTDOWN 0 |
| 103 | #define RESET_KIND_INIT 1 |
| 104 | #define RESET_KIND_SUSPEND 2 |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | #define TG3_DEF_RX_MODE 0 |
| 107 | #define TG3_DEF_TX_MODE 0 |
| 108 | #define TG3_DEF_MSG_ENABLE \ |
| 109 | (NETIF_MSG_DRV | \ |
| 110 | NETIF_MSG_PROBE | \ |
| 111 | NETIF_MSG_LINK | \ |
| 112 | NETIF_MSG_TIMER | \ |
| 113 | NETIF_MSG_IFDOWN | \ |
| 114 | NETIF_MSG_IFUP | \ |
| 115 | NETIF_MSG_RX_ERR | \ |
| 116 | NETIF_MSG_TX_ERR) |
| 117 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 118 | #define TG3_GRC_LCLCTL_PWRSW_DELAY 100 |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /* length of time before we decide the hardware is borked, |
| 121 | * and dev->tx_timeout() should be called to fix the problem |
| 122 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | #define TG3_TX_TIMEOUT (5 * HZ) |
| 125 | |
| 126 | /* hardware minimum and maximum for a single frame's data payload */ |
| 127 | #define TG3_MIN_MTU 60 |
| 128 | #define TG3_MAX_MTU(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 129 | (tg3_flag(tp, JUMBO_CAPABLE) ? 9000 : 1500) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /* These numbers seem to be hard coded in the NIC firmware somehow. |
| 132 | * You can't change the ring sizes, but you can change where you place |
| 133 | * them in the NIC onboard memory. |
| 134 | */ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 135 | #define TG3_RX_STD_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 136 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 137 | TG3_RX_STD_MAX_SIZE_5717 : TG3_RX_STD_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #define TG3_DEF_RX_RING_PENDING 200 |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 139 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 140 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 141 | TG3_RX_JMB_MAX_SIZE_5717 : TG3_RX_JMB_MAX_SIZE_5700) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
| 143 | |
| 144 | /* Do not place this n-ring entries value into the tp struct itself, |
| 145 | * we really want to expose these constants to GCC so that modulo et |
| 146 | * al. operations are done with shifts and masks instead of with |
| 147 | * hw multiply/modulo instructions. Another solution would be to |
| 148 | * replace things like '% foo' with '& (foo - 1)'. |
| 149 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | #define TG3_TX_RING_SIZE 512 |
| 152 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) |
| 153 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 154 | #define TG3_RX_STD_RING_BYTES(tp) \ |
| 155 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) |
| 156 | #define TG3_RX_JMB_RING_BYTES(tp) \ |
| 157 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) |
| 158 | #define TG3_RX_RCB_RING_BYTES(tp) \ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 159 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
| 161 | TG3_TX_RING_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
| 163 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 164 | #define TG3_DMA_BYTE_ENAB 64 |
| 165 | |
| 166 | #define TG3_RX_STD_DMA_SZ 1536 |
| 167 | #define TG3_RX_JMB_DMA_SZ 9046 |
| 168 | |
| 169 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) |
| 170 | |
| 171 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) |
| 172 | #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] | 173 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 174 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
| 175 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 176 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 177 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
| 178 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 179 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 180 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
| 181 | * that are at least dword aligned when used in PCIX mode. The driver |
| 182 | * works around this bug by double copying the packet. This workaround |
| 183 | * is built into the normal double copy length check for efficiency. |
| 184 | * |
| 185 | * However, the double copy is only necessary on those architectures |
| 186 | * where unaligned memory accesses are inefficient. For those architectures |
| 187 | * where unaligned memory accesses incur little penalty, we can reintegrate |
| 188 | * the 5701 in the normal rx path. Doing so saves a device structure |
| 189 | * dereference by hardcoding the double copy threshold in place. |
| 190 | */ |
| 191 | #define TG3_RX_COPY_THRESHOLD 256 |
| 192 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 193 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD |
| 194 | #else |
| 195 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) |
| 196 | #endif |
| 197 | |
Matt Carlson | 81389f5 | 2011-08-31 11:44:49 +0000 | [diff] [blame] | 198 | #if (NET_IP_ALIGN != 0) |
| 199 | #define TG3_RX_OFFSET(tp) ((tp)->rx_offset) |
| 200 | #else |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 201 | #define TG3_RX_OFFSET(tp) (NET_SKB_PAD) |
Matt Carlson | 81389f5 | 2011-08-31 11:44:49 +0000 | [diff] [blame] | 202 | #endif |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | /* minimum number of free TX descriptors required to wake up TX process */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 205 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 206 | #define TG3_TX_BD_DMA_MAX_2K 2048 |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 207 | #define TG3_TX_BD_DMA_MAX_4K 4096 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 209 | #define TG3_RAW_IP_ALIGN 2 |
| 210 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 211 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 212 | #define TG3_FW_UPDATE_FREQ_SEC (TG3_FW_UPDATE_TIMEOUT_SEC / 2) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 213 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 214 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 215 | #define FIRMWARE_TG357766 "tigon/tg357766.bin" |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 216 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
| 217 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" |
| 218 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 219 | static char version[] = |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 220 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); |
| 223 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); |
| 224 | MODULE_LICENSE("GPL"); |
| 225 | MODULE_VERSION(DRV_MODULE_VERSION); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 226 | MODULE_FIRMWARE(FIRMWARE_TG3); |
| 227 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); |
| 228 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); |
| 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
| 231 | module_param(tg3_debug, int, 0); |
| 232 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); |
| 233 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 234 | #define TG3_DRV_DATA_FLAG_10_100_ONLY 0x0001 |
| 235 | #define TG3_DRV_DATA_FLAG_5705_10_100 0x0002 |
| 236 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 237 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
| 239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, |
| 240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, |
| 241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, |
| 242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, |
| 243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, |
| 244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, |
| 245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, |
| 246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, |
| 247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, |
| 248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, |
| 249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, |
| 250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, |
| 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, |
| 252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, |
| 253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, |
| 254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, |
| 255 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 256 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901), |
| 257 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 258 | TG3_DRV_DATA_FLAG_5705_10_100}, |
| 259 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2), |
| 260 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 261 | TG3_DRV_DATA_FLAG_5705_10_100}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 262 | {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] | 263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F), |
| 264 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 265 | TG3_DRV_DATA_FLAG_5705_10_100}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F), |
| 272 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
| 274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, |
| 275 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, |
| 276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 277 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F), |
| 278 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 279 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
| 280 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, |
| 281 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, |
| 282 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 283 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 284 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
| 285 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 286 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5787M, |
| 287 | PCI_VENDOR_ID_LENOVO, |
| 288 | TG3PCI_SUBDEVICE_ID_LENOVO_5787M), |
| 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_5787M)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 291 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F), |
| 292 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 293 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
| 294 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, |
| 295 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, |
| 296 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, |
| 297 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, |
| 298 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, |
| 299 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 300 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
| 301 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 302 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
| 303 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
Matt Carlson | 6c7af27 | 2007-10-21 16:12:02 -0700 | [diff] [blame] | 304 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 305 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
| 306 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
Matt Carlson | c88e668 | 2008-11-03 16:49:18 -0800 | [diff] [blame] | 307 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
| 308 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, |
Matt Carlson | 2befdce | 2009-08-28 12:28:45 +0000 | [diff] [blame] | 309 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
| 310 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 311 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780, |
| 312 | PCI_VENDOR_ID_AI, TG3PCI_SUBDEVICE_ID_ACER_57780_A), |
| 313 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 314 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780, |
| 315 | PCI_VENDOR_ID_AI, TG3PCI_SUBDEVICE_ID_ACER_57780_B), |
| 316 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 317 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
| 318 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 319 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790), |
| 320 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Matt Carlson | 5e7ccf2 | 2009-08-25 10:08:42 +0000 | [diff] [blame] | 321 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 322 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 323 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717_C)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 324 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
Matt Carlson | b0f7522 | 2010-01-20 16:58:11 +0000 | [diff] [blame] | 325 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
| 326 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, |
| 327 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, |
| 328 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 329 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791), |
| 330 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 331 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795), |
| 332 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 333 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
Matt Carlson | ba1f3c7 | 2011-04-05 14:22:50 +0000 | [diff] [blame] | 334 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, |
Greg KH | 02eca3f | 2012-07-12 15:39:44 +0000 | [diff] [blame] | 335 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57762)}, |
Matt Carlson | d3f677a | 2013-02-14 14:27:51 +0000 | [diff] [blame] | 336 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57766)}, |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 337 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5762)}, |
| 338 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5725)}, |
| 339 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5727)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 340 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
| 341 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, |
| 342 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, |
| 343 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, |
| 344 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, |
| 345 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, |
| 346 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, |
Meelis Roos | 1dcb14d | 2011-05-25 05:43:47 +0000 | [diff] [blame] | 347 | {PCI_DEVICE(0x10cf, 0x11a2)}, /* Fujitsu 1000base-SX with BCM5703SKHB */ |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 348 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); |
| 352 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 353 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 355 | } ethtool_stats_keys[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { "rx_octets" }, |
| 357 | { "rx_fragments" }, |
| 358 | { "rx_ucast_packets" }, |
| 359 | { "rx_mcast_packets" }, |
| 360 | { "rx_bcast_packets" }, |
| 361 | { "rx_fcs_errors" }, |
| 362 | { "rx_align_errors" }, |
| 363 | { "rx_xon_pause_rcvd" }, |
| 364 | { "rx_xoff_pause_rcvd" }, |
| 365 | { "rx_mac_ctrl_rcvd" }, |
| 366 | { "rx_xoff_entered" }, |
| 367 | { "rx_frame_too_long_errors" }, |
| 368 | { "rx_jabbers" }, |
| 369 | { "rx_undersize_packets" }, |
| 370 | { "rx_in_length_errors" }, |
| 371 | { "rx_out_length_errors" }, |
| 372 | { "rx_64_or_less_octet_packets" }, |
| 373 | { "rx_65_to_127_octet_packets" }, |
| 374 | { "rx_128_to_255_octet_packets" }, |
| 375 | { "rx_256_to_511_octet_packets" }, |
| 376 | { "rx_512_to_1023_octet_packets" }, |
| 377 | { "rx_1024_to_1522_octet_packets" }, |
| 378 | { "rx_1523_to_2047_octet_packets" }, |
| 379 | { "rx_2048_to_4095_octet_packets" }, |
| 380 | { "rx_4096_to_8191_octet_packets" }, |
| 381 | { "rx_8192_to_9022_octet_packets" }, |
| 382 | |
| 383 | { "tx_octets" }, |
| 384 | { "tx_collisions" }, |
| 385 | |
| 386 | { "tx_xon_sent" }, |
| 387 | { "tx_xoff_sent" }, |
| 388 | { "tx_flow_control" }, |
| 389 | { "tx_mac_errors" }, |
| 390 | { "tx_single_collisions" }, |
| 391 | { "tx_mult_collisions" }, |
| 392 | { "tx_deferred" }, |
| 393 | { "tx_excessive_collisions" }, |
| 394 | { "tx_late_collisions" }, |
| 395 | { "tx_collide_2times" }, |
| 396 | { "tx_collide_3times" }, |
| 397 | { "tx_collide_4times" }, |
| 398 | { "tx_collide_5times" }, |
| 399 | { "tx_collide_6times" }, |
| 400 | { "tx_collide_7times" }, |
| 401 | { "tx_collide_8times" }, |
| 402 | { "tx_collide_9times" }, |
| 403 | { "tx_collide_10times" }, |
| 404 | { "tx_collide_11times" }, |
| 405 | { "tx_collide_12times" }, |
| 406 | { "tx_collide_13times" }, |
| 407 | { "tx_collide_14times" }, |
| 408 | { "tx_collide_15times" }, |
| 409 | { "tx_ucast_packets" }, |
| 410 | { "tx_mcast_packets" }, |
| 411 | { "tx_bcast_packets" }, |
| 412 | { "tx_carrier_sense_errors" }, |
| 413 | { "tx_discards" }, |
| 414 | { "tx_errors" }, |
| 415 | |
| 416 | { "dma_writeq_full" }, |
| 417 | { "dma_write_prioq_full" }, |
| 418 | { "rxbds_empty" }, |
| 419 | { "rx_discards" }, |
| 420 | { "rx_errors" }, |
| 421 | { "rx_threshold_hit" }, |
| 422 | |
| 423 | { "dma_readq_full" }, |
| 424 | { "dma_read_prioq_full" }, |
| 425 | { "tx_comp_queue_full" }, |
| 426 | |
| 427 | { "ring_set_send_prod_index" }, |
| 428 | { "ring_status_update" }, |
| 429 | { "nic_irqs" }, |
| 430 | { "nic_avoided_irqs" }, |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 431 | { "nic_tx_threshold_hit" }, |
| 432 | |
| 433 | { "mbuf_lwm_thresh_hit" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | }; |
| 435 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 436 | #define TG3_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 437 | #define TG3_NVRAM_TEST 0 |
| 438 | #define TG3_LINK_TEST 1 |
| 439 | #define TG3_REGISTER_TEST 2 |
| 440 | #define TG3_MEMORY_TEST 3 |
| 441 | #define TG3_MAC_LOOPB_TEST 4 |
| 442 | #define TG3_PHY_LOOPB_TEST 5 |
| 443 | #define TG3_EXT_LOOPB_TEST 6 |
| 444 | #define TG3_INTERRUPT_TEST 7 |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 445 | |
| 446 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 447 | static const struct { |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 448 | const char string[ETH_GSTRING_LEN]; |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 449 | } ethtool_test_keys[] = { |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 450 | [TG3_NVRAM_TEST] = { "nvram test (online) " }, |
| 451 | [TG3_LINK_TEST] = { "link test (online) " }, |
| 452 | [TG3_REGISTER_TEST] = { "register test (offline)" }, |
| 453 | [TG3_MEMORY_TEST] = { "memory test (offline)" }, |
| 454 | [TG3_MAC_LOOPB_TEST] = { "mac loopback test (offline)" }, |
| 455 | [TG3_PHY_LOOPB_TEST] = { "phy loopback test (offline)" }, |
| 456 | [TG3_EXT_LOOPB_TEST] = { "ext loopback test (offline)" }, |
| 457 | [TG3_INTERRUPT_TEST] = { "interrupt test (offline)" }, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 458 | }; |
| 459 | |
Matt Carlson | 48fa55a | 2011-04-13 11:05:06 +0000 | [diff] [blame] | 460 | #define TG3_NUM_TEST ARRAY_SIZE(ethtool_test_keys) |
| 461 | |
| 462 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 463 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
| 464 | { |
| 465 | writel(val, tp->regs + off); |
| 466 | } |
| 467 | |
| 468 | static u32 tg3_read32(struct tg3 *tp, u32 off) |
| 469 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 470 | return readl(tp->regs + off); |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 473 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
| 474 | { |
| 475 | writel(val, tp->aperegs + off); |
| 476 | } |
| 477 | |
| 478 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) |
| 479 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 480 | return readl(tp->aperegs + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
| 484 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 485 | unsigned long flags; |
| 486 | |
| 487 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 488 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 489 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 490 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) |
| 494 | { |
| 495 | writel(val, tp->regs + off); |
| 496 | readl(tp->regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 499 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
| 500 | { |
| 501 | unsigned long flags; |
| 502 | u32 val; |
| 503 | |
| 504 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 505 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 506 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 507 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 508 | return val; |
| 509 | } |
| 510 | |
| 511 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) |
| 512 | { |
| 513 | unsigned long flags; |
| 514 | |
| 515 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { |
| 516 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + |
| 517 | TG3_64BIT_REG_LOW, val); |
| 518 | return; |
| 519 | } |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 520 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 521 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
| 522 | TG3_64BIT_REG_LOW, val); |
| 523 | return; |
| 524 | } |
| 525 | |
| 526 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 527 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 528 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 529 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 530 | |
| 531 | /* In indirect mode when disabling interrupts, we also need |
| 532 | * to clear the interrupt bit in the GRC local ctrl register. |
| 533 | */ |
| 534 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && |
| 535 | (val == 0x1)) { |
| 536 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, |
| 537 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) |
| 542 | { |
| 543 | unsigned long flags; |
| 544 | u32 val; |
| 545 | |
| 546 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 547 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 548 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 549 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 550 | return val; |
| 551 | } |
| 552 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 553 | /* usec_wait specifies the wait time in usec when writing to certain registers |
| 554 | * where it is unsafe to read back the register without some delay. |
| 555 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. |
| 556 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. |
| 557 | */ |
| 558 | 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] | 559 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 560 | if (tg3_flag(tp, PCIX_TARGET_HWBUG) || tg3_flag(tp, ICH_WORKAROUND)) |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 561 | /* Non-posted methods */ |
| 562 | tp->write32(tp, off, val); |
| 563 | else { |
| 564 | /* Posted method */ |
| 565 | tg3_write32(tp, off, val); |
| 566 | if (usec_wait) |
| 567 | udelay(usec_wait); |
| 568 | tp->read32(tp, off); |
| 569 | } |
| 570 | /* Wait again after the read for the posted method to guarantee that |
| 571 | * the wait time is met. |
| 572 | */ |
| 573 | if (usec_wait) |
| 574 | udelay(usec_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 577 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
| 578 | { |
| 579 | tp->write32_mbox(tp, off, val); |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 580 | if (tg3_flag(tp, FLUSH_POSTED_WRITES) || |
| 581 | (!tg3_flag(tp, MBOX_WRITE_REORDER) && |
| 582 | !tg3_flag(tp, ICH_WORKAROUND))) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 583 | tp->read32_mbox(tp, off); |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 586 | 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] | 587 | { |
| 588 | void __iomem *mbox = tp->regs + off; |
| 589 | writel(val, mbox); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 590 | if (tg3_flag(tp, TXD_MBOX_HWBUG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | writel(val, mbox); |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 592 | if (tg3_flag(tp, MBOX_WRITE_REORDER) || |
| 593 | tg3_flag(tp, FLUSH_POSTED_WRITES)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | readl(mbox); |
| 595 | } |
| 596 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 597 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
| 598 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 599 | return readl(tp->regs + off + GRCMBOX_BASE); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) |
| 603 | { |
| 604 | writel(val, tp->regs + off + GRCMBOX_BASE); |
| 605 | } |
| 606 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 607 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 608 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 609 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
| 610 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) |
| 611 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 612 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 613 | #define tw32(reg, val) tp->write32(tp, reg, val) |
| 614 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) |
| 615 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) |
| 616 | #define tr32(reg) tp->read32(tp, reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
| 618 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) |
| 619 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 620 | unsigned long flags; |
| 621 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 622 | if (tg3_asic_rev(tp) == ASIC_REV_5906 && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 623 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
| 624 | return; |
| 625 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 626 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 627 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 628 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 629 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 631 | /* Always leave this as zero. */ |
| 632 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 633 | } else { |
| 634 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 635 | tw32_f(TG3PCI_MEM_WIN_DATA, val); |
| 636 | |
| 637 | /* Always leave this as zero. */ |
| 638 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 639 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 640 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
| 644 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 645 | unsigned long flags; |
| 646 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 647 | if (tg3_asic_rev(tp) == ASIC_REV_5906 && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 648 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
| 649 | *val = 0; |
| 650 | return; |
| 651 | } |
| 652 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 653 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 654 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 655 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 656 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 658 | /* Always leave this as zero. */ |
| 659 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 660 | } else { |
| 661 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 662 | *val = tr32(TG3PCI_MEM_WIN_DATA); |
| 663 | |
| 664 | /* Always leave this as zero. */ |
| 665 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 666 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 667 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 670 | static void tg3_ape_lock_init(struct tg3 *tp) |
| 671 | { |
| 672 | int i; |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 673 | u32 regbase, bit; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 674 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 675 | if (tg3_asic_rev(tp) == ASIC_REV_5761) |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 676 | regbase = TG3_APE_LOCK_GRANT; |
| 677 | else |
| 678 | regbase = TG3_APE_PER_LOCK_GRANT; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 679 | |
| 680 | /* Make sure the driver hasn't any stale locks. */ |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 681 | for (i = TG3_APE_LOCK_PHY0; i <= TG3_APE_LOCK_GPIO; i++) { |
| 682 | switch (i) { |
| 683 | case TG3_APE_LOCK_PHY0: |
| 684 | case TG3_APE_LOCK_PHY1: |
| 685 | case TG3_APE_LOCK_PHY2: |
| 686 | case TG3_APE_LOCK_PHY3: |
| 687 | bit = APE_LOCK_GRANT_DRIVER; |
| 688 | break; |
| 689 | default: |
| 690 | if (!tp->pci_fn) |
| 691 | bit = APE_LOCK_GRANT_DRIVER; |
| 692 | else |
| 693 | bit = 1 << tp->pci_fn; |
| 694 | } |
| 695 | tg3_ape_write32(tp, regbase + 4 * i, bit); |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 696 | } |
| 697 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | static int tg3_ape_lock(struct tg3 *tp, int locknum) |
| 701 | { |
| 702 | int i, off; |
| 703 | int ret = 0; |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 704 | u32 status, req, gnt, bit; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 705 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 706 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 707 | return 0; |
| 708 | |
| 709 | switch (locknum) { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 710 | case TG3_APE_LOCK_GPIO: |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 711 | if (tg3_asic_rev(tp) == ASIC_REV_5761) |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 712 | return 0; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 713 | case TG3_APE_LOCK_GRC: |
| 714 | case TG3_APE_LOCK_MEM: |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 715 | if (!tp->pci_fn) |
| 716 | bit = APE_LOCK_REQ_DRIVER; |
| 717 | else |
| 718 | bit = 1 << tp->pci_fn; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 719 | break; |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 720 | case TG3_APE_LOCK_PHY0: |
| 721 | case TG3_APE_LOCK_PHY1: |
| 722 | case TG3_APE_LOCK_PHY2: |
| 723 | case TG3_APE_LOCK_PHY3: |
| 724 | bit = APE_LOCK_REQ_DRIVER; |
| 725 | break; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 726 | default: |
| 727 | return -EINVAL; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 730 | if (tg3_asic_rev(tp) == ASIC_REV_5761) { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 731 | req = TG3_APE_LOCK_REQ; |
| 732 | gnt = TG3_APE_LOCK_GRANT; |
| 733 | } else { |
| 734 | req = TG3_APE_PER_LOCK_REQ; |
| 735 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 736 | } |
| 737 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 738 | off = 4 * locknum; |
| 739 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 740 | tg3_ape_write32(tp, req + off, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 741 | |
| 742 | /* Wait for up to 1 millisecond to acquire lock. */ |
| 743 | for (i = 0; i < 100; i++) { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 744 | status = tg3_ape_read32(tp, gnt + off); |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 745 | if (status == bit) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 746 | break; |
| 747 | udelay(10); |
| 748 | } |
| 749 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 750 | if (status != bit) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 751 | /* Revoke the lock request. */ |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 752 | tg3_ape_write32(tp, gnt + off, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 753 | ret = -EBUSY; |
| 754 | } |
| 755 | |
| 756 | return ret; |
| 757 | } |
| 758 | |
| 759 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) |
| 760 | { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 761 | u32 gnt, bit; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 762 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 763 | if (!tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 764 | return; |
| 765 | |
| 766 | switch (locknum) { |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 767 | case TG3_APE_LOCK_GPIO: |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 768 | if (tg3_asic_rev(tp) == ASIC_REV_5761) |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 769 | return; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 770 | case TG3_APE_LOCK_GRC: |
| 771 | case TG3_APE_LOCK_MEM: |
Matt Carlson | 78f94dc | 2011-11-04 09:14:58 +0000 | [diff] [blame] | 772 | if (!tp->pci_fn) |
| 773 | bit = APE_LOCK_GRANT_DRIVER; |
| 774 | else |
| 775 | bit = 1 << tp->pci_fn; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 776 | break; |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 777 | case TG3_APE_LOCK_PHY0: |
| 778 | case TG3_APE_LOCK_PHY1: |
| 779 | case TG3_APE_LOCK_PHY2: |
| 780 | case TG3_APE_LOCK_PHY3: |
| 781 | bit = APE_LOCK_GRANT_DRIVER; |
| 782 | break; |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 783 | default: |
| 784 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 787 | if (tg3_asic_rev(tp) == ASIC_REV_5761) |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 788 | gnt = TG3_APE_LOCK_GRANT; |
| 789 | else |
| 790 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 791 | |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 792 | tg3_ape_write32(tp, gnt + 4 * locknum, bit); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 795 | static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us) |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 796 | { |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 797 | u32 apedata; |
| 798 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 799 | while (timeout_us) { |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 800 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 801 | return -EBUSY; |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 802 | |
| 803 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 804 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 805 | break; |
| 806 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 807 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 808 | |
| 809 | udelay(10); |
| 810 | timeout_us -= (timeout_us > 10) ? 10 : timeout_us; |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 813 | return timeout_us ? 0 : -EBUSY; |
| 814 | } |
| 815 | |
Matt Carlson | cf8d55a | 2012-07-16 16:24:01 +0000 | [diff] [blame] | 816 | static int tg3_ape_wait_for_event(struct tg3 *tp, u32 timeout_us) |
| 817 | { |
| 818 | u32 i, apedata; |
| 819 | |
| 820 | for (i = 0; i < timeout_us / 10; i++) { |
| 821 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 822 | |
| 823 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 824 | break; |
| 825 | |
| 826 | udelay(10); |
| 827 | } |
| 828 | |
| 829 | return i == timeout_us / 10; |
| 830 | } |
| 831 | |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 832 | static int tg3_ape_scratchpad_read(struct tg3 *tp, u32 *data, u32 base_off, |
| 833 | u32 len) |
Matt Carlson | cf8d55a | 2012-07-16 16:24:01 +0000 | [diff] [blame] | 834 | { |
| 835 | int err; |
| 836 | u32 i, bufoff, msgoff, maxlen, apedata; |
| 837 | |
| 838 | if (!tg3_flag(tp, APE_HAS_NCSI)) |
| 839 | return 0; |
| 840 | |
| 841 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 842 | if (apedata != APE_SEG_SIG_MAGIC) |
| 843 | return -ENODEV; |
| 844 | |
| 845 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 846 | if (!(apedata & APE_FW_STATUS_READY)) |
| 847 | return -EAGAIN; |
| 848 | |
| 849 | bufoff = tg3_ape_read32(tp, TG3_APE_SEG_MSG_BUF_OFF) + |
| 850 | TG3_APE_SHMEM_BASE; |
| 851 | msgoff = bufoff + 2 * sizeof(u32); |
| 852 | maxlen = tg3_ape_read32(tp, TG3_APE_SEG_MSG_BUF_LEN); |
| 853 | |
| 854 | while (len) { |
| 855 | u32 length; |
| 856 | |
| 857 | /* Cap xfer sizes to scratchpad limits. */ |
| 858 | length = (len > maxlen) ? maxlen : len; |
| 859 | len -= length; |
| 860 | |
| 861 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 862 | if (!(apedata & APE_FW_STATUS_READY)) |
| 863 | return -EAGAIN; |
| 864 | |
| 865 | /* Wait for up to 1 msec for APE to service previous event. */ |
| 866 | err = tg3_ape_event_lock(tp, 1000); |
| 867 | if (err) |
| 868 | return err; |
| 869 | |
| 870 | apedata = APE_EVENT_STATUS_DRIVER_EVNT | |
| 871 | APE_EVENT_STATUS_SCRTCHPD_READ | |
| 872 | APE_EVENT_STATUS_EVENT_PENDING; |
| 873 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, apedata); |
| 874 | |
| 875 | tg3_ape_write32(tp, bufoff, base_off); |
| 876 | tg3_ape_write32(tp, bufoff + sizeof(u32), length); |
| 877 | |
| 878 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 879 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 880 | |
| 881 | base_off += length; |
| 882 | |
| 883 | if (tg3_ape_wait_for_event(tp, 30000)) |
| 884 | return -EAGAIN; |
| 885 | |
| 886 | for (i = 0; length; i += 4, length -= 4) { |
| 887 | u32 val = tg3_ape_read32(tp, msgoff + i); |
| 888 | memcpy(data, &val, sizeof(u32)); |
| 889 | data++; |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | return 0; |
| 894 | } |
| 895 | |
Matt Carlson | b65a372 | 2012-07-16 16:24:00 +0000 | [diff] [blame] | 896 | static int tg3_ape_send_event(struct tg3 *tp, u32 event) |
| 897 | { |
| 898 | int err; |
| 899 | u32 apedata; |
| 900 | |
| 901 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 902 | if (apedata != APE_SEG_SIG_MAGIC) |
| 903 | return -EAGAIN; |
| 904 | |
| 905 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 906 | if (!(apedata & APE_FW_STATUS_READY)) |
| 907 | return -EAGAIN; |
| 908 | |
| 909 | /* Wait for up to 1 millisecond for APE to service previous event. */ |
| 910 | err = tg3_ape_event_lock(tp, 1000); |
| 911 | if (err) |
| 912 | return err; |
| 913 | |
| 914 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
| 915 | event | APE_EVENT_STATUS_EVENT_PENDING); |
| 916 | |
| 917 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 918 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 919 | |
| 920 | return 0; |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
| 924 | { |
| 925 | u32 event; |
| 926 | u32 apedata; |
| 927 | |
| 928 | if (!tg3_flag(tp, ENABLE_APE)) |
| 929 | return; |
| 930 | |
| 931 | switch (kind) { |
| 932 | case RESET_KIND_INIT: |
| 933 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, |
| 934 | APE_HOST_SEG_SIG_MAGIC); |
| 935 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, |
| 936 | APE_HOST_SEG_LEN_MAGIC); |
| 937 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); |
| 938 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); |
| 939 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, |
| 940 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
| 941 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
| 942 | APE_HOST_BEHAV_NO_PHYLOCK); |
| 943 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, |
| 944 | TG3_APE_HOST_DRVR_STATE_START); |
| 945 | |
| 946 | event = APE_EVENT_STATUS_STATE_START; |
| 947 | break; |
| 948 | case RESET_KIND_SHUTDOWN: |
| 949 | /* With the interface we are currently using, |
| 950 | * APE does not track driver state. Wiping |
| 951 | * out the HOST SEGMENT SIGNATURE forces |
| 952 | * the APE to assume OS absent status. |
| 953 | */ |
| 954 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); |
| 955 | |
| 956 | if (device_may_wakeup(&tp->pdev->dev) && |
| 957 | tg3_flag(tp, WOL_ENABLE)) { |
| 958 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, |
| 959 | TG3_APE_HOST_WOL_SPEED_AUTO); |
| 960 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; |
| 961 | } else |
| 962 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; |
| 963 | |
| 964 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); |
| 965 | |
| 966 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
| 967 | break; |
| 968 | case RESET_KIND_SUSPEND: |
| 969 | event = APE_EVENT_STATUS_STATE_SUSPEND; |
| 970 | break; |
| 971 | default: |
| 972 | return; |
| 973 | } |
| 974 | |
| 975 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; |
| 976 | |
| 977 | tg3_ape_send_event(tp, event); |
| 978 | } |
| 979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | static void tg3_disable_ints(struct tg3 *tp) |
| 981 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 982 | int i; |
| 983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 985 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 986 | for (i = 0; i < tp->irq_max; i++) |
| 987 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | static void tg3_enable_ints(struct tg3 *tp) |
| 991 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 992 | int i; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 993 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 994 | tp->irq_sync = 0; |
| 995 | wmb(); |
| 996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 998 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 999 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 1000 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 1001 | for (i = 0; i < tp->irq_cnt; i++) { |
| 1002 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 1003 | |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 1004 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1005 | if (tg3_flag(tp, 1SHOT_MSI)) |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 1006 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 1007 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 1008 | tp->coal_now |= tnapi->coal_now; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 1009 | } |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 1010 | |
| 1011 | /* Force an initial interrupt */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1012 | if (!tg3_flag(tp, TAGGED_STATUS) && |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 1013 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
| 1014 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 1015 | else |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 1016 | tw32(HOSTCC_MODE, tp->coal_now); |
| 1017 | |
| 1018 | 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] | 1019 | } |
| 1020 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1021 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1022 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1023 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 1024 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1025 | unsigned int work_exists = 0; |
| 1026 | |
| 1027 | /* check for phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1028 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1029 | if (sblk->status & SD_STATUS_LINK_CHG) |
| 1030 | work_exists = 1; |
| 1031 | } |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 1032 | |
| 1033 | /* check for TX work to do */ |
| 1034 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons) |
| 1035 | work_exists = 1; |
| 1036 | |
| 1037 | /* check for RX work to do */ |
| 1038 | if (tnapi->rx_rcb_prod_idx && |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 1039 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1040 | work_exists = 1; |
| 1041 | |
| 1042 | return work_exists; |
| 1043 | } |
| 1044 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1045 | /* tg3_int_reenable |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1046 | * similar to tg3_enable_ints, but it accurately determines whether there |
| 1047 | * is new work pending and can return without flushing the PIO write |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1048 | * which reenables interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1050 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 1052 | struct tg3 *tp = tnapi->tp; |
| 1053 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 1054 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | mmiowb(); |
| 1056 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 1057 | /* When doing tagged status, this work check is unnecessary. |
| 1058 | * The last_tag we write above tells the chip which piece of |
| 1059 | * work we've completed. |
| 1060 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1061 | if (!tg3_flag(tp, TAGGED_STATUS) && tg3_has_work(tnapi)) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 1062 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 1063 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | static void tg3_switch_clocks(struct tg3 *tp) |
| 1067 | { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 1068 | u32 clock_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | u32 orig_clock_ctrl; |
| 1070 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1071 | if (tg3_flag(tp, CPMU_PRESENT) || tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 1072 | return; |
| 1073 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 1074 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
| 1075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | orig_clock_ctrl = clock_ctrl; |
| 1077 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | |
| 1078 | CLOCK_CTRL_CLKRUN_OENABLE | |
| 1079 | 0x1f); |
| 1080 | tp->pci_clock_ctrl = clock_ctrl; |
| 1081 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1082 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 1084 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1085 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | } |
| 1087 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 1088 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1089 | clock_ctrl | |
| 1090 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), |
| 1091 | 40); |
| 1092 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1093 | clock_ctrl | (CLOCK_CTRL_ALTCLK), |
| 1094 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 1096 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | #define PHY_BUSY_LOOPS 5000 |
| 1100 | |
Hauke Mehrtens | 5c35804 | 2013-02-07 05:37:38 +0000 | [diff] [blame] | 1101 | static int __tg3_readphy(struct tg3 *tp, unsigned int phy_addr, int reg, |
| 1102 | u32 *val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | { |
| 1104 | u32 frame_val; |
| 1105 | unsigned int loops; |
| 1106 | int ret; |
| 1107 | |
| 1108 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1109 | tw32_f(MAC_MI_MODE, |
| 1110 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 1111 | udelay(80); |
| 1112 | } |
| 1113 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1114 | tg3_ape_lock(tp, tp->phy_ape_lock); |
| 1115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | *val = 0x0; |
| 1117 | |
Hauke Mehrtens | 5c35804 | 2013-02-07 05:37:38 +0000 | [diff] [blame] | 1118 | frame_val = ((phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | MI_COM_PHY_ADDR_MASK); |
| 1120 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 1121 | MI_COM_REG_ADDR_MASK); |
| 1122 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | tw32_f(MAC_MI_COM, frame_val); |
| 1125 | |
| 1126 | loops = PHY_BUSY_LOOPS; |
| 1127 | while (loops != 0) { |
| 1128 | udelay(10); |
| 1129 | frame_val = tr32(MAC_MI_COM); |
| 1130 | |
| 1131 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 1132 | udelay(5); |
| 1133 | frame_val = tr32(MAC_MI_COM); |
| 1134 | break; |
| 1135 | } |
| 1136 | loops -= 1; |
| 1137 | } |
| 1138 | |
| 1139 | ret = -EBUSY; |
| 1140 | if (loops != 0) { |
| 1141 | *val = frame_val & MI_COM_DATA_MASK; |
| 1142 | ret = 0; |
| 1143 | } |
| 1144 | |
| 1145 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1146 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1147 | udelay(80); |
| 1148 | } |
| 1149 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1150 | tg3_ape_unlock(tp, tp->phy_ape_lock); |
| 1151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | return ret; |
| 1153 | } |
| 1154 | |
Hauke Mehrtens | 5c35804 | 2013-02-07 05:37:38 +0000 | [diff] [blame] | 1155 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
| 1156 | { |
| 1157 | return __tg3_readphy(tp, tp->phy_addr, reg, val); |
| 1158 | } |
| 1159 | |
| 1160 | static int __tg3_writephy(struct tg3 *tp, unsigned int phy_addr, int reg, |
| 1161 | u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | { |
| 1163 | u32 frame_val; |
| 1164 | unsigned int loops; |
| 1165 | int ret; |
| 1166 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1167 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 1168 | (reg == MII_CTRL1000 || reg == MII_TG3_AUX_CTRL)) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 1169 | return 0; |
| 1170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1172 | tw32_f(MAC_MI_MODE, |
| 1173 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 1174 | udelay(80); |
| 1175 | } |
| 1176 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1177 | tg3_ape_lock(tp, tp->phy_ape_lock); |
| 1178 | |
Hauke Mehrtens | 5c35804 | 2013-02-07 05:37:38 +0000 | [diff] [blame] | 1179 | frame_val = ((phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | MI_COM_PHY_ADDR_MASK); |
| 1181 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 1182 | MI_COM_REG_ADDR_MASK); |
| 1183 | frame_val |= (val & MI_COM_DATA_MASK); |
| 1184 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | tw32_f(MAC_MI_COM, frame_val); |
| 1187 | |
| 1188 | loops = PHY_BUSY_LOOPS; |
| 1189 | while (loops != 0) { |
| 1190 | udelay(10); |
| 1191 | frame_val = tr32(MAC_MI_COM); |
| 1192 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 1193 | udelay(5); |
| 1194 | frame_val = tr32(MAC_MI_COM); |
| 1195 | break; |
| 1196 | } |
| 1197 | loops -= 1; |
| 1198 | } |
| 1199 | |
| 1200 | ret = -EBUSY; |
| 1201 | if (loops != 0) |
| 1202 | ret = 0; |
| 1203 | |
| 1204 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1205 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1206 | udelay(80); |
| 1207 | } |
| 1208 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 1209 | tg3_ape_unlock(tp, tp->phy_ape_lock); |
| 1210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | return ret; |
| 1212 | } |
| 1213 | |
Hauke Mehrtens | 5c35804 | 2013-02-07 05:37:38 +0000 | [diff] [blame] | 1214 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
| 1215 | { |
| 1216 | return __tg3_writephy(tp, tp->phy_addr, reg, val); |
| 1217 | } |
| 1218 | |
Matt Carlson | b0988c1 | 2011-04-20 07:57:39 +0000 | [diff] [blame] | 1219 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
| 1220 | { |
| 1221 | int err; |
| 1222 | |
| 1223 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1224 | if (err) |
| 1225 | goto done; |
| 1226 | |
| 1227 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1228 | if (err) |
| 1229 | goto done; |
| 1230 | |
| 1231 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1232 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1233 | if (err) |
| 1234 | goto done; |
| 1235 | |
| 1236 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1237 | |
| 1238 | done: |
| 1239 | return err; |
| 1240 | } |
| 1241 | |
| 1242 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) |
| 1243 | { |
| 1244 | int err; |
| 1245 | |
| 1246 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1247 | if (err) |
| 1248 | goto done; |
| 1249 | |
| 1250 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1251 | if (err) |
| 1252 | goto done; |
| 1253 | |
| 1254 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1255 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1256 | if (err) |
| 1257 | goto done; |
| 1258 | |
| 1259 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1260 | |
| 1261 | done: |
| 1262 | return err; |
| 1263 | } |
| 1264 | |
| 1265 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) |
| 1266 | { |
| 1267 | int err; |
| 1268 | |
| 1269 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1270 | if (!err) |
| 1271 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1272 | |
| 1273 | return err; |
| 1274 | } |
| 1275 | |
| 1276 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
| 1277 | { |
| 1278 | int err; |
| 1279 | |
| 1280 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1281 | if (!err) |
| 1282 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1283 | |
| 1284 | return err; |
| 1285 | } |
| 1286 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 1287 | static int tg3_phy_auxctl_read(struct tg3 *tp, int reg, u32 *val) |
| 1288 | { |
| 1289 | int err; |
| 1290 | |
| 1291 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 1292 | (reg << MII_TG3_AUXCTL_MISC_RDSEL_SHIFT) | |
| 1293 | MII_TG3_AUXCTL_SHDWSEL_MISC); |
| 1294 | if (!err) |
| 1295 | err = tg3_readphy(tp, MII_TG3_AUX_CTRL, val); |
| 1296 | |
| 1297 | return err; |
| 1298 | } |
| 1299 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 1300 | static int tg3_phy_auxctl_write(struct tg3 *tp, int reg, u32 set) |
| 1301 | { |
| 1302 | if (reg == MII_TG3_AUXCTL_SHDWSEL_MISC) |
| 1303 | set |= MII_TG3_AUXCTL_MISC_WREN; |
| 1304 | |
| 1305 | return tg3_writephy(tp, MII_TG3_AUX_CTRL, set | reg); |
| 1306 | } |
| 1307 | |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 1308 | static int tg3_phy_toggle_auxctl_smdsp(struct tg3 *tp, bool enable) |
| 1309 | { |
| 1310 | u32 val; |
| 1311 | int err; |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 1312 | |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 1313 | err = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 1314 | |
| 1315 | if (err) |
| 1316 | return err; |
| 1317 | if (enable) |
| 1318 | |
| 1319 | val |= MII_TG3_AUXCTL_ACTL_SMDSP_ENA; |
| 1320 | else |
| 1321 | val &= ~MII_TG3_AUXCTL_ACTL_SMDSP_ENA; |
| 1322 | |
| 1323 | err = tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 1324 | val | MII_TG3_AUXCTL_ACTL_TX_6DB); |
| 1325 | |
| 1326 | return err; |
| 1327 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 1328 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1329 | static int tg3_bmcr_reset(struct tg3 *tp) |
| 1330 | { |
| 1331 | u32 phy_control; |
| 1332 | int limit, err; |
| 1333 | |
| 1334 | /* OK, reset it, and poll the BMCR_RESET bit until it |
| 1335 | * clears or we time out. |
| 1336 | */ |
| 1337 | phy_control = BMCR_RESET; |
| 1338 | err = tg3_writephy(tp, MII_BMCR, phy_control); |
| 1339 | if (err != 0) |
| 1340 | return -EBUSY; |
| 1341 | |
| 1342 | limit = 5000; |
| 1343 | while (limit--) { |
| 1344 | err = tg3_readphy(tp, MII_BMCR, &phy_control); |
| 1345 | if (err != 0) |
| 1346 | return -EBUSY; |
| 1347 | |
| 1348 | if ((phy_control & BMCR_RESET) == 0) { |
| 1349 | udelay(40); |
| 1350 | break; |
| 1351 | } |
| 1352 | udelay(10); |
| 1353 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 1354 | if (limit < 0) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1355 | return -EBUSY; |
| 1356 | |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1360 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
| 1361 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1362 | struct tg3 *tp = bp->priv; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1363 | u32 val; |
| 1364 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1365 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1366 | |
| 1367 | if (tg3_readphy(tp, reg, &val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1368 | val = -EIO; |
| 1369 | |
| 1370 | spin_unlock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1371 | |
| 1372 | return val; |
| 1373 | } |
| 1374 | |
| 1375 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) |
| 1376 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 1377 | struct tg3 *tp = bp->priv; |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1378 | u32 ret = 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1379 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1380 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1381 | |
| 1382 | if (tg3_writephy(tp, reg, val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1383 | ret = -EIO; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1384 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1385 | spin_unlock_bh(&tp->lock); |
| 1386 | |
| 1387 | return ret; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | static int tg3_mdio_reset(struct mii_bus *bp) |
| 1391 | { |
| 1392 | return 0; |
| 1393 | } |
| 1394 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1395 | static void tg3_mdio_config_5785(struct tg3 *tp) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1396 | { |
| 1397 | u32 val; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1398 | struct phy_device *phydev; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1399 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1400 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1401 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1402 | case PHY_ID_BCM50610: |
| 1403 | case PHY_ID_BCM50610M: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1404 | val = MAC_PHYCFG2_50610_LED_MODES; |
| 1405 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1406 | case PHY_ID_BCMAC131: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1407 | val = MAC_PHYCFG2_AC131_LED_MODES; |
| 1408 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1409 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1410 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
| 1411 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1412 | case PHY_ID_RTL8201E: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1413 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
| 1414 | break; |
| 1415 | default: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1416 | return; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { |
| 1420 | tw32(MAC_PHYCFG2, val); |
| 1421 | |
| 1422 | val = tr32(MAC_PHYCFG1); |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1423 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
| 1424 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); |
| 1425 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1426 | tw32(MAC_PHYCFG1, val); |
| 1427 | |
| 1428 | return; |
| 1429 | } |
| 1430 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1431 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1432 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
| 1433 | MAC_PHYCFG2_FMODE_MASK_MASK | |
| 1434 | MAC_PHYCFG2_GMODE_MASK_MASK | |
| 1435 | MAC_PHYCFG2_ACT_MASK_MASK | |
| 1436 | MAC_PHYCFG2_QUAL_MASK_MASK | |
| 1437 | MAC_PHYCFG2_INBAND_ENABLE; |
| 1438 | |
| 1439 | tw32(MAC_PHYCFG2, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1440 | |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1441 | val = tr32(MAC_PHYCFG1); |
| 1442 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | |
| 1443 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1444 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1445 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1446 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1447 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1448 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
| 1449 | } |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1450 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
| 1451 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; |
| 1452 | tw32(MAC_PHYCFG1, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1453 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1454 | val = tr32(MAC_EXT_RGMII_MODE); |
| 1455 | val &= ~(MAC_RGMII_MODE_RX_INT_B | |
| 1456 | MAC_RGMII_MODE_RX_QUALITY | |
| 1457 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1458 | MAC_RGMII_MODE_RX_ENG_DET | |
| 1459 | MAC_RGMII_MODE_TX_ENABLE | |
| 1460 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1461 | MAC_RGMII_MODE_TX_RESET); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1462 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1463 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1464 | val |= MAC_RGMII_MODE_RX_INT_B | |
| 1465 | MAC_RGMII_MODE_RX_QUALITY | |
| 1466 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1467 | MAC_RGMII_MODE_RX_ENG_DET; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1468 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1469 | val |= MAC_RGMII_MODE_TX_ENABLE | |
| 1470 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1471 | MAC_RGMII_MODE_TX_RESET; |
| 1472 | } |
| 1473 | tw32(MAC_EXT_RGMII_MODE, val); |
| 1474 | } |
| 1475 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1476 | static void tg3_mdio_start(struct tg3 *tp) |
| 1477 | { |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1478 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
| 1479 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1480 | udelay(80); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1481 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1482 | if (tg3_flag(tp, MDIOBUS_INITED) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 1483 | tg3_asic_rev(tp) == ASIC_REV_5785) |
Matt Carlson | 9ea4818 | 2010-02-17 15:17:01 +0000 | [diff] [blame] | 1484 | tg3_mdio_config_5785(tp); |
| 1485 | } |
| 1486 | |
| 1487 | static int tg3_mdio_init(struct tg3 *tp) |
| 1488 | { |
| 1489 | int i; |
| 1490 | u32 reg; |
| 1491 | struct phy_device *phydev; |
| 1492 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1493 | if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1494 | u32 is_serdes; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1495 | |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 1496 | tp->phy_addr = tp->pci_fn + 1; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1497 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 1498 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5717_A0) |
Matt Carlson | d1ec96a | 2010-01-12 10:11:38 +0000 | [diff] [blame] | 1499 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
| 1500 | else |
| 1501 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & |
| 1502 | TG3_CPMU_PHY_STRAP_IS_SERDES; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1503 | if (is_serdes) |
| 1504 | tp->phy_addr += 7; |
| 1505 | } else |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1506 | tp->phy_addr = TG3_PHY_MII_ADDR; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1507 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1508 | tg3_mdio_start(tp); |
| 1509 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1510 | if (!tg3_flag(tp, USE_PHYLIB) || tg3_flag(tp, MDIOBUS_INITED)) |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1511 | return 0; |
| 1512 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1513 | tp->mdio_bus = mdiobus_alloc(); |
| 1514 | if (tp->mdio_bus == NULL) |
| 1515 | return -ENOMEM; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1516 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1517 | tp->mdio_bus->name = "tg3 mdio bus"; |
| 1518 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1519 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1520 | tp->mdio_bus->priv = tp; |
| 1521 | tp->mdio_bus->parent = &tp->pdev->dev; |
| 1522 | tp->mdio_bus->read = &tg3_mdio_read; |
| 1523 | tp->mdio_bus->write = &tg3_mdio_write; |
| 1524 | tp->mdio_bus->reset = &tg3_mdio_reset; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1525 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1526 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1527 | |
| 1528 | for (i = 0; i < PHY_MAX_ADDR; i++) |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1529 | tp->mdio_bus->irq[i] = PHY_POLL; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1530 | |
| 1531 | /* The bus registration will look for all the PHYs on the mdio bus. |
| 1532 | * Unfortunately, it does not ensure the PHY is powered up before |
| 1533 | * accessing the PHY ID registers. A chip reset is the |
| 1534 | * quickest way to bring the device back to an operational state.. |
| 1535 | */ |
| 1536 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
| 1537 | tg3_bmcr_reset(tp); |
| 1538 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1539 | i = mdiobus_register(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1540 | if (i) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1541 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1542 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1543 | return i; |
| 1544 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1545 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1546 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1547 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1548 | if (!phydev || !phydev->drv) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1549 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1550 | mdiobus_unregister(tp->mdio_bus); |
| 1551 | mdiobus_free(tp->mdio_bus); |
| 1552 | return -ENODEV; |
| 1553 | } |
| 1554 | |
| 1555 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1556 | case PHY_ID_BCM57780: |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1557 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1558 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1559 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1560 | case PHY_ID_BCM50610: |
| 1561 | case PHY_ID_BCM50610M: |
Matt Carlson | 32e5a8d | 2009-11-02 14:31:39 +0000 | [diff] [blame] | 1562 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1563 | PHY_BRCM_RX_REFCLK_UNUSED | |
Matt Carlson | 52fae08 | 2009-11-02 14:32:38 +0000 | [diff] [blame] | 1564 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1565 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1566 | if (tg3_flag(tp, RGMII_INBAND_DISABLE)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1567 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1568 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1569 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1570 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1571 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1572 | /* fallthru */ |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1573 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1574 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1575 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1576 | case PHY_ID_RTL8201E: |
| 1577 | case PHY_ID_BCMAC131: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1578 | phydev->interface = PHY_INTERFACE_MODE_MII; |
Matt Carlson | cdd4e09d | 2009-11-02 14:31:11 +0000 | [diff] [blame] | 1579 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1580 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1581 | break; |
| 1582 | } |
| 1583 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1584 | tg3_flag_set(tp, MDIOBUS_INITED); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1585 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 1586 | if (tg3_asic_rev(tp) == ASIC_REV_5785) |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1587 | tg3_mdio_config_5785(tp); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1588 | |
| 1589 | return 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | static void tg3_mdio_fini(struct tg3 *tp) |
| 1593 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1594 | if (tg3_flag(tp, MDIOBUS_INITED)) { |
| 1595 | tg3_flag_clear(tp, MDIOBUS_INITED); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1596 | mdiobus_unregister(tp->mdio_bus); |
| 1597 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1598 | } |
| 1599 | } |
| 1600 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1601 | /* tp->lock is held. */ |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1602 | static inline void tg3_generate_fw_event(struct tg3 *tp) |
| 1603 | { |
| 1604 | u32 val; |
| 1605 | |
| 1606 | val = tr32(GRC_RX_CPU_EVENT); |
| 1607 | val |= GRC_RX_CPU_DRIVER_EVENT; |
| 1608 | tw32_f(GRC_RX_CPU_EVENT, val); |
| 1609 | |
| 1610 | tp->last_event_jiffies = jiffies; |
| 1611 | } |
| 1612 | |
| 1613 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 |
| 1614 | |
| 1615 | /* tp->lock is held. */ |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1616 | static void tg3_wait_for_event_ack(struct tg3 *tp) |
| 1617 | { |
| 1618 | int i; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1619 | unsigned int delay_cnt; |
| 1620 | long time_remain; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1621 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1622 | /* If enough time has passed, no wait is necessary. */ |
| 1623 | time_remain = (long)(tp->last_event_jiffies + 1 + |
| 1624 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - |
| 1625 | (long)jiffies; |
| 1626 | if (time_remain < 0) |
| 1627 | return; |
| 1628 | |
| 1629 | /* Check if we can shorten the wait time. */ |
| 1630 | delay_cnt = jiffies_to_usecs(time_remain); |
| 1631 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) |
| 1632 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; |
| 1633 | delay_cnt = (delay_cnt >> 3) + 1; |
| 1634 | |
| 1635 | for (i = 0; i < delay_cnt; i++) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1636 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
| 1637 | break; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1638 | udelay(8); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | /* tp->lock is held. */ |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1643 | static void tg3_phy_gather_ump_data(struct tg3 *tp, u32 *data) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1644 | { |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1645 | u32 reg, val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1646 | |
| 1647 | val = 0; |
| 1648 | if (!tg3_readphy(tp, MII_BMCR, ®)) |
| 1649 | val = reg << 16; |
| 1650 | if (!tg3_readphy(tp, MII_BMSR, ®)) |
| 1651 | val |= (reg & 0xffff); |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1652 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1653 | |
| 1654 | val = 0; |
| 1655 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) |
| 1656 | val = reg << 16; |
| 1657 | if (!tg3_readphy(tp, MII_LPA, ®)) |
| 1658 | val |= (reg & 0xffff); |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1659 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1660 | |
| 1661 | val = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1662 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1663 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
| 1664 | val = reg << 16; |
| 1665 | if (!tg3_readphy(tp, MII_STAT1000, ®)) |
| 1666 | val |= (reg & 0xffff); |
| 1667 | } |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1668 | *data++ = val; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1669 | |
| 1670 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) |
| 1671 | val = reg << 16; |
| 1672 | else |
| 1673 | val = 0; |
Matt Carlson | b28f389 | 2012-02-13 15:20:12 +0000 | [diff] [blame] | 1674 | *data++ = val; |
| 1675 | } |
| 1676 | |
| 1677 | /* tp->lock is held. */ |
| 1678 | static void tg3_ump_link_report(struct tg3 *tp) |
| 1679 | { |
| 1680 | u32 data[4]; |
| 1681 | |
| 1682 | if (!tg3_flag(tp, 5780_CLASS) || !tg3_flag(tp, ENABLE_ASF)) |
| 1683 | return; |
| 1684 | |
| 1685 | tg3_phy_gather_ump_data(tp, data); |
| 1686 | |
| 1687 | tg3_wait_for_event_ack(tp); |
| 1688 | |
| 1689 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); |
| 1690 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); |
| 1691 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x0, data[0]); |
| 1692 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x4, data[1]); |
| 1693 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x8, data[2]); |
| 1694 | 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] | 1695 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1696 | tg3_generate_fw_event(tp); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
Matt Carlson | 8d5a89b | 2011-08-31 11:44:51 +0000 | [diff] [blame] | 1699 | /* tp->lock is held. */ |
| 1700 | static void tg3_stop_fw(struct tg3 *tp) |
| 1701 | { |
| 1702 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
| 1703 | /* Wait for RX cpu to ACK the previous event. */ |
| 1704 | tg3_wait_for_event_ack(tp); |
| 1705 | |
| 1706 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); |
| 1707 | |
| 1708 | tg3_generate_fw_event(tp); |
| 1709 | |
| 1710 | /* Wait for RX cpu to ACK this event. */ |
| 1711 | tg3_wait_for_event_ack(tp); |
| 1712 | } |
| 1713 | } |
| 1714 | |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 1715 | /* tp->lock is held. */ |
| 1716 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) |
| 1717 | { |
| 1718 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
| 1719 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); |
| 1720 | |
| 1721 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1722 | switch (kind) { |
| 1723 | case RESET_KIND_INIT: |
| 1724 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1725 | DRV_STATE_START); |
| 1726 | break; |
| 1727 | |
| 1728 | case RESET_KIND_SHUTDOWN: |
| 1729 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1730 | DRV_STATE_UNLOAD); |
| 1731 | break; |
| 1732 | |
| 1733 | case RESET_KIND_SUSPEND: |
| 1734 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1735 | DRV_STATE_SUSPEND); |
| 1736 | break; |
| 1737 | |
| 1738 | default: |
| 1739 | break; |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | if (kind == RESET_KIND_INIT || |
| 1744 | kind == RESET_KIND_SUSPEND) |
| 1745 | tg3_ape_driver_state_change(tp, kind); |
| 1746 | } |
| 1747 | |
| 1748 | /* tp->lock is held. */ |
| 1749 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) |
| 1750 | { |
| 1751 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1752 | switch (kind) { |
| 1753 | case RESET_KIND_INIT: |
| 1754 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1755 | DRV_STATE_START_DONE); |
| 1756 | break; |
| 1757 | |
| 1758 | case RESET_KIND_SHUTDOWN: |
| 1759 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1760 | DRV_STATE_UNLOAD_DONE); |
| 1761 | break; |
| 1762 | |
| 1763 | default: |
| 1764 | break; |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | if (kind == RESET_KIND_SHUTDOWN) |
| 1769 | tg3_ape_driver_state_change(tp, kind); |
| 1770 | } |
| 1771 | |
| 1772 | /* tp->lock is held. */ |
| 1773 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) |
| 1774 | { |
| 1775 | if (tg3_flag(tp, ENABLE_ASF)) { |
| 1776 | switch (kind) { |
| 1777 | case RESET_KIND_INIT: |
| 1778 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1779 | DRV_STATE_START); |
| 1780 | break; |
| 1781 | |
| 1782 | case RESET_KIND_SHUTDOWN: |
| 1783 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1784 | DRV_STATE_UNLOAD); |
| 1785 | break; |
| 1786 | |
| 1787 | case RESET_KIND_SUSPEND: |
| 1788 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1789 | DRV_STATE_SUSPEND); |
| 1790 | break; |
| 1791 | |
| 1792 | default: |
| 1793 | break; |
| 1794 | } |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | static int tg3_poll_fw(struct tg3 *tp) |
| 1799 | { |
| 1800 | int i; |
| 1801 | u32 val; |
| 1802 | |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 1803 | if (tg3_flag(tp, IS_SSB_CORE)) { |
| 1804 | /* We don't use firmware. */ |
| 1805 | return 0; |
| 1806 | } |
| 1807 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 1808 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 1809 | /* Wait up to 20ms for init done. */ |
| 1810 | for (i = 0; i < 200; i++) { |
| 1811 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
| 1812 | return 0; |
| 1813 | udelay(100); |
| 1814 | } |
| 1815 | return -ENODEV; |
| 1816 | } |
| 1817 | |
| 1818 | /* Wait for firmware initialization to complete. */ |
| 1819 | for (i = 0; i < 100000; i++) { |
| 1820 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); |
| 1821 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 1822 | break; |
| 1823 | udelay(10); |
| 1824 | } |
| 1825 | |
| 1826 | /* Chip might not be fitted with firmware. Some Sun onboard |
| 1827 | * parts are configured like that. So don't signal the timeout |
| 1828 | * of the above loop as an error, but do report the lack of |
| 1829 | * running firmware once. |
| 1830 | */ |
| 1831 | if (i >= 100000 && !tg3_flag(tp, NO_FWARE_REPORTED)) { |
| 1832 | tg3_flag_set(tp, NO_FWARE_REPORTED); |
| 1833 | |
| 1834 | netdev_info(tp->dev, "No firmware running\n"); |
| 1835 | } |
| 1836 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 1837 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) { |
Matt Carlson | fd6d3f0 | 2011-08-31 11:44:52 +0000 | [diff] [blame] | 1838 | /* The 57765 A0 needs a little more |
| 1839 | * time to do some important work. |
| 1840 | */ |
| 1841 | mdelay(10); |
| 1842 | } |
| 1843 | |
| 1844 | return 0; |
| 1845 | } |
| 1846 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1847 | static void tg3_link_report(struct tg3 *tp) |
| 1848 | { |
| 1849 | if (!netif_carrier_ok(tp->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1850 | netif_info(tp, link, tp->dev, "Link is down\n"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1851 | tg3_ump_link_report(tp); |
| 1852 | } else if (netif_msg_link(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1853 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
| 1854 | (tp->link_config.active_speed == SPEED_1000 ? |
| 1855 | 1000 : |
| 1856 | (tp->link_config.active_speed == SPEED_100 ? |
| 1857 | 100 : 10)), |
| 1858 | (tp->link_config.active_duplex == DUPLEX_FULL ? |
| 1859 | "full" : "half")); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1860 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1861 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", |
| 1862 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? |
| 1863 | "on" : "off", |
| 1864 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? |
| 1865 | "on" : "off"); |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 1866 | |
| 1867 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) |
| 1868 | netdev_info(tp->dev, "EEE is %s\n", |
| 1869 | tp->setlpicnt ? "enabled" : "disabled"); |
| 1870 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1871 | tg3_ump_link_report(tp); |
| 1872 | } |
Nithin Sujir | 84421b9 | 2013-03-08 08:01:24 +0000 | [diff] [blame] | 1873 | |
| 1874 | tp->link_up = netif_carrier_ok(tp->dev); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
Nithin Sujir | fdad8de | 2013-04-09 08:48:08 +0000 | [diff] [blame] | 1877 | static u32 tg3_decode_flowctrl_1000T(u32 adv) |
| 1878 | { |
| 1879 | u32 flowctrl = 0; |
| 1880 | |
| 1881 | if (adv & ADVERTISE_PAUSE_CAP) { |
| 1882 | flowctrl |= FLOW_CTRL_RX; |
| 1883 | if (!(adv & ADVERTISE_PAUSE_ASYM)) |
| 1884 | flowctrl |= FLOW_CTRL_TX; |
| 1885 | } else if (adv & ADVERTISE_PAUSE_ASYM) |
| 1886 | flowctrl |= FLOW_CTRL_TX; |
| 1887 | |
| 1888 | return flowctrl; |
| 1889 | } |
| 1890 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1891 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
| 1892 | { |
| 1893 | u16 miireg; |
| 1894 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1895 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1896 | miireg = ADVERTISE_1000XPAUSE; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1897 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1898 | miireg = ADVERTISE_1000XPSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1899 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1900 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
| 1901 | else |
| 1902 | miireg = 0; |
| 1903 | |
| 1904 | return miireg; |
| 1905 | } |
| 1906 | |
Nithin Sujir | fdad8de | 2013-04-09 08:48:08 +0000 | [diff] [blame] | 1907 | static u32 tg3_decode_flowctrl_1000X(u32 adv) |
| 1908 | { |
| 1909 | u32 flowctrl = 0; |
| 1910 | |
| 1911 | if (adv & ADVERTISE_1000XPAUSE) { |
| 1912 | flowctrl |= FLOW_CTRL_RX; |
| 1913 | if (!(adv & ADVERTISE_1000XPSE_ASYM)) |
| 1914 | flowctrl |= FLOW_CTRL_TX; |
| 1915 | } else if (adv & ADVERTISE_1000XPSE_ASYM) |
| 1916 | flowctrl |= FLOW_CTRL_TX; |
| 1917 | |
| 1918 | return flowctrl; |
| 1919 | } |
| 1920 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1921 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
| 1922 | { |
| 1923 | u8 cap = 0; |
| 1924 | |
Matt Carlson | f3791cd | 2011-11-21 15:01:17 +0000 | [diff] [blame] | 1925 | if (lcladv & rmtadv & ADVERTISE_1000XPAUSE) { |
| 1926 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 1927 | } else if (lcladv & rmtadv & ADVERTISE_1000XPSE_ASYM) { |
| 1928 | if (lcladv & ADVERTISE_1000XPAUSE) |
| 1929 | cap = FLOW_CTRL_RX; |
| 1930 | if (rmtadv & ADVERTISE_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1931 | cap = FLOW_CTRL_TX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | return cap; |
| 1935 | } |
| 1936 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1937 | 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] | 1938 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1939 | u8 autoneg; |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1940 | u8 flowctrl = 0; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1941 | u32 old_rx_mode = tp->rx_mode; |
| 1942 | u32 old_tx_mode = tp->tx_mode; |
| 1943 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1944 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1945 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1946 | else |
| 1947 | autoneg = tp->link_config.autoneg; |
| 1948 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 1949 | if (autoneg == AUTONEG_ENABLE && tg3_flag(tp, PAUSE_AUTONEG)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1950 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1951 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1952 | else |
Steve Glendinning | bc02ff9 | 2008-12-16 02:00:48 -0800 | [diff] [blame] | 1953 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1954 | } else |
| 1955 | flowctrl = tp->link_config.flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1956 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1957 | tp->link_config.active_flowctrl = flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1958 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1959 | if (flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1960 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
| 1961 | else |
| 1962 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; |
| 1963 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1964 | if (old_rx_mode != tp->rx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1965 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1966 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1967 | if (flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1968 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
| 1969 | else |
| 1970 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; |
| 1971 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1972 | if (old_tx_mode != tp->tx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1973 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1976 | static void tg3_adjust_link(struct net_device *dev) |
| 1977 | { |
| 1978 | u8 oldflowctrl, linkmesg = 0; |
| 1979 | u32 mac_mode, lcl_adv, rmt_adv; |
| 1980 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1981 | 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] | 1982 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1983 | spin_lock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1984 | |
| 1985 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | |
| 1986 | MAC_MODE_HALF_DUPLEX); |
| 1987 | |
| 1988 | oldflowctrl = tp->link_config.active_flowctrl; |
| 1989 | |
| 1990 | if (phydev->link) { |
| 1991 | lcl_adv = 0; |
| 1992 | rmt_adv = 0; |
| 1993 | |
| 1994 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) |
| 1995 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1996 | else if (phydev->speed == SPEED_1000 || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 1997 | tg3_asic_rev(tp) != ASIC_REV_5785) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1998 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1999 | else |
| 2000 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2001 | |
| 2002 | if (phydev->duplex == DUPLEX_HALF) |
| 2003 | mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 2004 | else { |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 2005 | lcl_adv = mii_advertise_flowctrl( |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2006 | tp->link_config.flowctrl); |
| 2007 | |
| 2008 | if (phydev->pause) |
| 2009 | rmt_adv = LPA_PAUSE_CAP; |
| 2010 | if (phydev->asym_pause) |
| 2011 | rmt_adv |= LPA_PAUSE_ASYM; |
| 2012 | } |
| 2013 | |
| 2014 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 2015 | } else |
| 2016 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 2017 | |
| 2018 | if (mac_mode != tp->mac_mode) { |
| 2019 | tp->mac_mode = mac_mode; |
| 2020 | tw32_f(MAC_MODE, tp->mac_mode); |
| 2021 | udelay(40); |
| 2022 | } |
| 2023 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2024 | if (tg3_asic_rev(tp) == ASIC_REV_5785) { |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 2025 | if (phydev->speed == SPEED_10) |
| 2026 | tw32(MAC_MI_STAT, |
| 2027 | MAC_MI_STAT_10MBPS_MODE | |
| 2028 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 2029 | else |
| 2030 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 2031 | } |
| 2032 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2033 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
| 2034 | tw32(MAC_TX_LENGTHS, |
| 2035 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 2036 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 2037 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 2038 | else |
| 2039 | tw32(MAC_TX_LENGTHS, |
| 2040 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 2041 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 2042 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 2043 | |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 2044 | if (phydev->link != tp->old_link || |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2045 | phydev->speed != tp->link_config.active_speed || |
| 2046 | phydev->duplex != tp->link_config.active_duplex || |
| 2047 | oldflowctrl != tp->link_config.active_flowctrl) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 2048 | linkmesg = 1; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2049 | |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 2050 | tp->old_link = phydev->link; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2051 | tp->link_config.active_speed = phydev->speed; |
| 2052 | tp->link_config.active_duplex = phydev->duplex; |
| 2053 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 2054 | spin_unlock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2055 | |
| 2056 | if (linkmesg) |
| 2057 | tg3_link_report(tp); |
| 2058 | } |
| 2059 | |
| 2060 | static int tg3_phy_init(struct tg3 *tp) |
| 2061 | { |
| 2062 | struct phy_device *phydev; |
| 2063 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2064 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2065 | return 0; |
| 2066 | |
| 2067 | /* Bring the PHY back to a known state. */ |
| 2068 | tg3_bmcr_reset(tp); |
| 2069 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2070 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2071 | |
| 2072 | /* Attach the MAC to the PHY. */ |
Florian Fainelli | f9a8f83 | 2013-01-14 00:52:52 +0000 | [diff] [blame] | 2073 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), |
| 2074 | tg3_adjust_link, phydev->interface); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2075 | if (IS_ERR(phydev)) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 2076 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2077 | return PTR_ERR(phydev); |
| 2078 | } |
| 2079 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2080 | /* Mask with MAC supported features. */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 2081 | switch (phydev->interface) { |
| 2082 | case PHY_INTERFACE_MODE_GMII: |
| 2083 | case PHY_INTERFACE_MODE_RGMII: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2084 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 2085 | phydev->supported &= (PHY_GBIT_FEATURES | |
| 2086 | SUPPORTED_Pause | |
| 2087 | SUPPORTED_Asym_Pause); |
| 2088 | break; |
| 2089 | } |
| 2090 | /* fallthru */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 2091 | case PHY_INTERFACE_MODE_MII: |
| 2092 | phydev->supported &= (PHY_BASIC_FEATURES | |
| 2093 | SUPPORTED_Pause | |
| 2094 | SUPPORTED_Asym_Pause); |
| 2095 | break; |
| 2096 | default: |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2097 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 2098 | return -EINVAL; |
| 2099 | } |
| 2100 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2101 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2102 | |
| 2103 | phydev->advertising = phydev->supported; |
| 2104 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2105 | return 0; |
| 2106 | } |
| 2107 | |
| 2108 | static void tg3_phy_start(struct tg3 *tp) |
| 2109 | { |
| 2110 | struct phy_device *phydev; |
| 2111 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2112 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2113 | return; |
| 2114 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2115 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2116 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2117 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 2118 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 2119 | phydev->speed = tp->link_config.speed; |
| 2120 | phydev->duplex = tp->link_config.duplex; |
| 2121 | phydev->autoneg = tp->link_config.autoneg; |
| 2122 | phydev->advertising = tp->link_config.advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | phy_start(phydev); |
| 2126 | |
| 2127 | phy_start_aneg(phydev); |
| 2128 | } |
| 2129 | |
| 2130 | static void tg3_phy_stop(struct tg3 *tp) |
| 2131 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2132 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2133 | return; |
| 2134 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2135 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | static void tg3_phy_fini(struct tg3 *tp) |
| 2139 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2140 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2141 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2142 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2143 | } |
| 2144 | } |
| 2145 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 2146 | static int tg3_phy_set_extloopbk(struct tg3 *tp) |
| 2147 | { |
| 2148 | int err; |
| 2149 | u32 val; |
| 2150 | |
| 2151 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 2152 | return 0; |
| 2153 | |
| 2154 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
| 2155 | /* Cannot do read-modify-write on 5401 */ |
| 2156 | err = tg3_phy_auxctl_write(tp, |
| 2157 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2158 | MII_TG3_AUXCTL_ACTL_EXTLOOPBK | |
| 2159 | 0x4c20); |
| 2160 | goto done; |
| 2161 | } |
| 2162 | |
| 2163 | err = tg3_phy_auxctl_read(tp, |
| 2164 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2165 | if (err) |
| 2166 | return err; |
| 2167 | |
| 2168 | val |= MII_TG3_AUXCTL_ACTL_EXTLOOPBK; |
| 2169 | err = tg3_phy_auxctl_write(tp, |
| 2170 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, val); |
| 2171 | |
| 2172 | done: |
| 2173 | return err; |
| 2174 | } |
| 2175 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 2176 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
| 2177 | { |
| 2178 | u32 phytest; |
| 2179 | |
| 2180 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2181 | u32 phy; |
| 2182 | |
| 2183 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2184 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2185 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { |
| 2186 | if (enable) |
| 2187 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 2188 | else |
| 2189 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 2190 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); |
| 2191 | } |
| 2192 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2193 | } |
| 2194 | } |
| 2195 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2196 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
| 2197 | { |
| 2198 | u32 reg; |
| 2199 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2200 | if (!tg3_flag(tp, 5705_PLUS) || |
| 2201 | (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2202 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2203 | return; |
| 2204 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2205 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 2206 | tg3_phy_fet_toggle_apd(tp, enable); |
| 2207 | return; |
| 2208 | } |
| 2209 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2210 | reg = MII_TG3_MISC_SHDW_WREN | |
| 2211 | MII_TG3_MISC_SHDW_SCR5_SEL | |
| 2212 | MII_TG3_MISC_SHDW_SCR5_LPED | |
| 2213 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | |
| 2214 | MII_TG3_MISC_SHDW_SCR5_SDTL | |
| 2215 | MII_TG3_MISC_SHDW_SCR5_C125OE; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2216 | if (tg3_asic_rev(tp) != ASIC_REV_5784 || !enable) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2217 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
| 2218 | |
| 2219 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 2220 | |
| 2221 | |
| 2222 | reg = MII_TG3_MISC_SHDW_WREN | |
| 2223 | MII_TG3_MISC_SHDW_APD_SEL | |
| 2224 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; |
| 2225 | if (enable) |
| 2226 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; |
| 2227 | |
| 2228 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 2229 | } |
| 2230 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 2231 | static void tg3_phy_toggle_automdix(struct tg3 *tp, bool enable) |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2232 | { |
| 2233 | u32 phy; |
| 2234 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2235 | if (!tg3_flag(tp, 5705_PLUS) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2236 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2237 | return; |
| 2238 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2239 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2240 | u32 ephy; |
| 2241 | |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2242 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
| 2243 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; |
| 2244 | |
| 2245 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2246 | ephy | MII_TG3_FET_SHADOW_EN); |
| 2247 | if (!tg3_readphy(tp, reg, &phy)) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2248 | if (enable) |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2249 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2250 | else |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2251 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 2252 | tg3_writephy(tp, reg, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2253 | } |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2254 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2255 | } |
| 2256 | } else { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2257 | int ret; |
| 2258 | |
| 2259 | ret = tg3_phy_auxctl_read(tp, |
| 2260 | MII_TG3_AUXCTL_SHDWSEL_MISC, &phy); |
| 2261 | if (!ret) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2262 | if (enable) |
| 2263 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 2264 | else |
| 2265 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2266 | tg3_phy_auxctl_write(tp, |
| 2267 | MII_TG3_AUXCTL_SHDWSEL_MISC, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2268 | } |
| 2269 | } |
| 2270 | } |
| 2271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
| 2273 | { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2274 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | u32 val; |
| 2276 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2277 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | return; |
| 2279 | |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2280 | ret = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, &val); |
| 2281 | if (!ret) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2282 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, |
| 2283 | val | MII_TG3_AUXCTL_MISC_WIRESPD_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2286 | static void tg3_phy_apply_otp(struct tg3 *tp) |
| 2287 | { |
| 2288 | u32 otp, phy; |
| 2289 | |
| 2290 | if (!tp->phy_otp) |
| 2291 | return; |
| 2292 | |
| 2293 | otp = tp->phy_otp; |
| 2294 | |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2295 | if (tg3_phy_toggle_auxctl_smdsp(tp, true)) |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2296 | return; |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2297 | |
| 2298 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); |
| 2299 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; |
| 2300 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); |
| 2301 | |
| 2302 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | |
| 2303 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); |
| 2304 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); |
| 2305 | |
| 2306 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); |
| 2307 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; |
| 2308 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); |
| 2309 | |
| 2310 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); |
| 2311 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); |
| 2312 | |
| 2313 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); |
| 2314 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); |
| 2315 | |
| 2316 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | |
| 2317 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); |
| 2318 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); |
| 2319 | |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2320 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2321 | } |
| 2322 | |
Nithin Sujir | 400dfba | 2013-05-18 06:26:53 +0000 | [diff] [blame] | 2323 | static void tg3_eee_pull_config(struct tg3 *tp, struct ethtool_eee *eee) |
| 2324 | { |
| 2325 | u32 val; |
| 2326 | struct ethtool_eee *dest = &tp->eee; |
| 2327 | |
| 2328 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 2329 | return; |
| 2330 | |
| 2331 | if (eee) |
| 2332 | dest = eee; |
| 2333 | |
| 2334 | if (tg3_phy_cl45_read(tp, MDIO_MMD_AN, TG3_CL45_D7_EEERES_STAT, &val)) |
| 2335 | return; |
| 2336 | |
| 2337 | /* Pull eee_active */ |
| 2338 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
| 2339 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) { |
| 2340 | dest->eee_active = 1; |
| 2341 | } else |
| 2342 | dest->eee_active = 0; |
| 2343 | |
| 2344 | /* Pull lp advertised settings */ |
| 2345 | if (tg3_phy_cl45_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_LPABLE, &val)) |
| 2346 | return; |
| 2347 | dest->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(val); |
| 2348 | |
| 2349 | /* Pull advertised and eee_enabled settings */ |
| 2350 | if (tg3_phy_cl45_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, &val)) |
| 2351 | return; |
| 2352 | dest->eee_enabled = !!val; |
| 2353 | dest->advertised = mmd_eee_adv_to_ethtool_adv_t(val); |
| 2354 | |
| 2355 | /* Pull tx_lpi_enabled */ |
| 2356 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2357 | dest->tx_lpi_enabled = !!(val & TG3_CPMU_EEEMD_LPI_IN_TX); |
| 2358 | |
| 2359 | /* Pull lpi timer value */ |
| 2360 | dest->tx_lpi_timer = tr32(TG3_CPMU_EEE_DBTMR1) & 0xffff; |
| 2361 | } |
| 2362 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 2363 | static void tg3_phy_eee_adjust(struct tg3 *tp, bool current_link_up) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2364 | { |
| 2365 | u32 val; |
| 2366 | |
| 2367 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 2368 | return; |
| 2369 | |
| 2370 | tp->setlpicnt = 0; |
| 2371 | |
| 2372 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 2373 | current_link_up && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 2374 | tp->link_config.active_duplex == DUPLEX_FULL && |
| 2375 | (tp->link_config.active_speed == SPEED_100 || |
| 2376 | tp->link_config.active_speed == SPEED_1000)) { |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2377 | u32 eeectl; |
| 2378 | |
| 2379 | if (tp->link_config.active_speed == SPEED_1000) |
| 2380 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; |
| 2381 | else |
| 2382 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; |
| 2383 | |
| 2384 | tw32(TG3_CPMU_EEE_CTRL, eeectl); |
| 2385 | |
Nithin Sujir | 400dfba | 2013-05-18 06:26:53 +0000 | [diff] [blame] | 2386 | tg3_eee_pull_config(tp, NULL); |
| 2387 | if (tp->eee.eee_active) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2388 | tp->setlpicnt = 2; |
| 2389 | } |
| 2390 | |
| 2391 | if (!tp->setlpicnt) { |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 2392 | if (current_link_up && |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2393 | !tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2394 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, 0x0000); |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2395 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2398 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2399 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2400 | } |
| 2401 | } |
| 2402 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2403 | static void tg3_phy_eee_enable(struct tg3 *tp) |
| 2404 | { |
| 2405 | u32 val; |
| 2406 | |
| 2407 | if (tp->link_config.active_speed == SPEED_1000 && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2408 | (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 2409 | tg3_asic_rev(tp) == ASIC_REV_5719 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 2410 | tg3_flag(tp, 57765_CLASS)) && |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2411 | !tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 2412 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 2413 | MII_TG3_DSP_TAP26_RMRXSTO; |
| 2414 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2415 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | val = tr32(TG3_CPMU_EEE_MODE); |
| 2419 | tw32(TG3_CPMU_EEE_MODE, val | TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2420 | } |
| 2421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | static int tg3_wait_macro_done(struct tg3 *tp) |
| 2423 | { |
| 2424 | int limit = 100; |
| 2425 | |
| 2426 | while (limit--) { |
| 2427 | u32 tmp32; |
| 2428 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2429 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | if ((tmp32 & 0x1000) == 0) |
| 2431 | break; |
| 2432 | } |
| 2433 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 2434 | if (limit < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | return -EBUSY; |
| 2436 | |
| 2437 | return 0; |
| 2438 | } |
| 2439 | |
| 2440 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) |
| 2441 | { |
| 2442 | static const u32 test_pat[4][6] = { |
| 2443 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, |
| 2444 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, |
| 2445 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, |
| 2446 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } |
| 2447 | }; |
| 2448 | int chan; |
| 2449 | |
| 2450 | for (chan = 0; chan < 4; chan++) { |
| 2451 | int i; |
| 2452 | |
| 2453 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2454 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2455 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | |
| 2457 | for (i = 0; i < 6; i++) |
| 2458 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, |
| 2459 | test_pat[chan][i]); |
| 2460 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2461 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | if (tg3_wait_macro_done(tp)) { |
| 2463 | *resetp = 1; |
| 2464 | return -EBUSY; |
| 2465 | } |
| 2466 | |
| 2467 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2468 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2469 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | if (tg3_wait_macro_done(tp)) { |
| 2471 | *resetp = 1; |
| 2472 | return -EBUSY; |
| 2473 | } |
| 2474 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2475 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | if (tg3_wait_macro_done(tp)) { |
| 2477 | *resetp = 1; |
| 2478 | return -EBUSY; |
| 2479 | } |
| 2480 | |
| 2481 | for (i = 0; i < 6; i += 2) { |
| 2482 | u32 low, high; |
| 2483 | |
| 2484 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || |
| 2485 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || |
| 2486 | tg3_wait_macro_done(tp)) { |
| 2487 | *resetp = 1; |
| 2488 | return -EBUSY; |
| 2489 | } |
| 2490 | low &= 0x7fff; |
| 2491 | high &= 0x000f; |
| 2492 | if (low != test_pat[chan][i] || |
| 2493 | high != test_pat[chan][i+1]) { |
| 2494 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); |
| 2495 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); |
| 2496 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); |
| 2497 | |
| 2498 | return -EBUSY; |
| 2499 | } |
| 2500 | } |
| 2501 | } |
| 2502 | |
| 2503 | return 0; |
| 2504 | } |
| 2505 | |
| 2506 | static int tg3_phy_reset_chanpat(struct tg3 *tp) |
| 2507 | { |
| 2508 | int chan; |
| 2509 | |
| 2510 | for (chan = 0; chan < 4; chan++) { |
| 2511 | int i; |
| 2512 | |
| 2513 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2514 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2515 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | for (i = 0; i < 6; i++) |
| 2517 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2518 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | if (tg3_wait_macro_done(tp)) |
| 2520 | return -EBUSY; |
| 2521 | } |
| 2522 | |
| 2523 | return 0; |
| 2524 | } |
| 2525 | |
| 2526 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) |
| 2527 | { |
| 2528 | u32 reg32, phy9_orig; |
| 2529 | int retries, do_phy_reset, err; |
| 2530 | |
| 2531 | retries = 10; |
| 2532 | do_phy_reset = 1; |
| 2533 | do { |
| 2534 | if (do_phy_reset) { |
| 2535 | err = tg3_bmcr_reset(tp); |
| 2536 | if (err) |
| 2537 | return err; |
| 2538 | do_phy_reset = 0; |
| 2539 | } |
| 2540 | |
| 2541 | /* Disable transmitter and interrupt. */ |
| 2542 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) |
| 2543 | continue; |
| 2544 | |
| 2545 | reg32 |= 0x3000; |
| 2546 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2547 | |
| 2548 | /* Set full-duplex, 1000 mbps. */ |
| 2549 | tg3_writephy(tp, MII_BMCR, |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2550 | BMCR_FULLDPLX | BMCR_SPEED1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | |
| 2552 | /* Set to master mode. */ |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2553 | if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | continue; |
| 2555 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2556 | tg3_writephy(tp, MII_CTRL1000, |
| 2557 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2559 | err = tg3_phy_toggle_auxctl_smdsp(tp, true); |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2560 | if (err) |
| 2561 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | |
| 2563 | /* Block the PHY control access. */ |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2564 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | |
| 2566 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); |
| 2567 | if (!err) |
| 2568 | break; |
| 2569 | } while (--retries); |
| 2570 | |
| 2571 | err = tg3_phy_reset_chanpat(tp); |
| 2572 | if (err) |
| 2573 | return err; |
| 2574 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2575 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | |
| 2577 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2578 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2580 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 2582 | tg3_writephy(tp, MII_CTRL1000, phy9_orig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | |
| 2584 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { |
| 2585 | reg32 &= ~0x3000; |
| 2586 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2587 | } else if (!err) |
| 2588 | err = -EBUSY; |
| 2589 | |
| 2590 | return err; |
| 2591 | } |
| 2592 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 2593 | static void tg3_carrier_off(struct tg3 *tp) |
| 2594 | { |
| 2595 | netif_carrier_off(tp->dev); |
| 2596 | tp->link_up = false; |
| 2597 | } |
| 2598 | |
Nithin Sujir | ce20f16 | 2013-04-09 08:48:04 +0000 | [diff] [blame] | 2599 | static void tg3_warn_mgmt_link_flap(struct tg3 *tp) |
| 2600 | { |
| 2601 | if (tg3_flag(tp, ENABLE_ASF)) |
| 2602 | netdev_warn(tp->dev, |
| 2603 | "Management side-band traffic will be interrupted during phy settings change\n"); |
| 2604 | } |
| 2605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | /* This will reset the tigon3 PHY if there is no valid |
| 2607 | * link unless the FORCE argument is non-zero. |
| 2608 | */ |
| 2609 | static int tg3_phy_reset(struct tg3 *tp) |
| 2610 | { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2611 | u32 val, cpmuctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | int err; |
| 2613 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2614 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2615 | val = tr32(GRC_MISC_CFG); |
| 2616 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); |
| 2617 | udelay(40); |
| 2618 | } |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2619 | err = tg3_readphy(tp, MII_BMSR, &val); |
| 2620 | err |= tg3_readphy(tp, MII_BMSR, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | if (err != 0) |
| 2622 | return -EBUSY; |
| 2623 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 2624 | if (netif_running(tp->dev) && tp->link_up) { |
Nithin Sujir | 84421b9 | 2013-03-08 08:01:24 +0000 | [diff] [blame] | 2625 | netif_carrier_off(tp->dev); |
Michael Chan | c8e1e82 | 2006-04-29 18:55:17 -0700 | [diff] [blame] | 2626 | tg3_link_report(tp); |
| 2627 | } |
| 2628 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2629 | if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
| 2630 | tg3_asic_rev(tp) == ASIC_REV_5704 || |
| 2631 | tg3_asic_rev(tp) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | err = tg3_phy_reset_5703_4_5(tp); |
| 2633 | if (err) |
| 2634 | return err; |
| 2635 | goto out; |
| 2636 | } |
| 2637 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2638 | cpmuctrl = 0; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2639 | if (tg3_asic_rev(tp) == ASIC_REV_5784 && |
| 2640 | tg3_chip_rev(tp) != CHIPREV_5784_AX) { |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2641 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
| 2642 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) |
| 2643 | tw32(TG3_CPMU_CTRL, |
| 2644 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); |
| 2645 | } |
| 2646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | err = tg3_bmcr_reset(tp); |
| 2648 | if (err) |
| 2649 | return err; |
| 2650 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2651 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2652 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
| 2653 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2654 | |
| 2655 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 2656 | } |
| 2657 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2658 | if (tg3_chip_rev(tp) == CHIPREV_5784_AX || |
| 2659 | tg3_chip_rev(tp) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2660 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2661 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == |
| 2662 | CPMU_LSPD_1000MB_MACCLK_12_5) { |
| 2663 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2664 | udelay(40); |
| 2665 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2666 | } |
| 2667 | } |
| 2668 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2669 | if (tg3_flag(tp, 5717_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2670 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 2671 | return 0; |
| 2672 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2673 | tg3_phy_apply_otp(tp); |
| 2674 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2675 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2676 | tg3_phy_toggle_apd(tp, true); |
| 2677 | else |
| 2678 | tg3_phy_toggle_apd(tp, false); |
| 2679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | out: |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2681 | if ((tp->phy_flags & TG3_PHYFLG_ADC_BUG) && |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2682 | !tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2683 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
| 2684 | tg3_phydsp_write(tp, 0x000a, 0x0323); |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2685 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2687 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2688 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2689 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 2690 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2692 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2693 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2694 | if (!tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2695 | tg3_phydsp_write(tp, 0x000a, 0x310b); |
| 2696 | tg3_phydsp_write(tp, 0x201f, 0x9506); |
| 2697 | tg3_phydsp_write(tp, 0x401f, 0x14e2); |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2698 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2699 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2700 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2701 | if (!tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2702 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
| 2703 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { |
| 2704 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
| 2705 | tg3_writephy(tp, MII_TG3_TEST1, |
| 2706 | MII_TG3_TEST1_TRIM_EN | 0x4); |
| 2707 | } else |
| 2708 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); |
| 2709 | |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 2710 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2711 | } |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 2712 | } |
Matt Carlson | 1d36ba4 | 2011-04-20 07:57:42 +0000 | [diff] [blame] | 2713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | /* Set Extended packet length bit (bit 14) on all chips that */ |
| 2715 | /* support jumbo frames */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2716 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | /* Cannot do read-modify-write on 5401 */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2718 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2719 | } else if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | /* Set bit 14 with read-modify-write to preserve other bits */ |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 2721 | err = tg3_phy_auxctl_read(tp, |
| 2722 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2723 | if (!err) |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 2724 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2725 | val | MII_TG3_AUXCTL_ACTL_EXTPKTLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support |
| 2729 | * jumbo frames transmission. |
| 2730 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2731 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2732 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 2733 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2734 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2737 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2738 | /* adjust output voltage */ |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2739 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2740 | } |
| 2741 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2742 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5762_A0) |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 2743 | tg3_phydsp_write(tp, 0xffb, 0x4000); |
| 2744 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 2745 | tg3_phy_toggle_automdix(tp, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | tg3_phy_set_wirespeed(tp); |
| 2747 | return 0; |
| 2748 | } |
| 2749 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2750 | #define TG3_GPIO_MSG_DRVR_PRES 0x00000001 |
| 2751 | #define TG3_GPIO_MSG_NEED_VAUX 0x00000002 |
| 2752 | #define TG3_GPIO_MSG_MASK (TG3_GPIO_MSG_DRVR_PRES | \ |
| 2753 | TG3_GPIO_MSG_NEED_VAUX) |
| 2754 | #define TG3_GPIO_MSG_ALL_DRVR_PRES_MASK \ |
| 2755 | ((TG3_GPIO_MSG_DRVR_PRES << 0) | \ |
| 2756 | (TG3_GPIO_MSG_DRVR_PRES << 4) | \ |
| 2757 | (TG3_GPIO_MSG_DRVR_PRES << 8) | \ |
| 2758 | (TG3_GPIO_MSG_DRVR_PRES << 12)) |
| 2759 | |
| 2760 | #define TG3_GPIO_MSG_ALL_NEED_VAUX_MASK \ |
| 2761 | ((TG3_GPIO_MSG_NEED_VAUX << 0) | \ |
| 2762 | (TG3_GPIO_MSG_NEED_VAUX << 4) | \ |
| 2763 | (TG3_GPIO_MSG_NEED_VAUX << 8) | \ |
| 2764 | (TG3_GPIO_MSG_NEED_VAUX << 12)) |
| 2765 | |
| 2766 | static inline u32 tg3_set_function_status(struct tg3 *tp, u32 newstat) |
| 2767 | { |
| 2768 | u32 status, shift; |
| 2769 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2770 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 2771 | tg3_asic_rev(tp) == ASIC_REV_5719) |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2772 | status = tg3_ape_read32(tp, TG3_APE_GPIO_MSG); |
| 2773 | else |
| 2774 | status = tr32(TG3_CPMU_DRV_STATUS); |
| 2775 | |
| 2776 | shift = TG3_APE_GPIO_MSG_SHIFT + 4 * tp->pci_fn; |
| 2777 | status &= ~(TG3_GPIO_MSG_MASK << shift); |
| 2778 | status |= (newstat << shift); |
| 2779 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2780 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 2781 | tg3_asic_rev(tp) == ASIC_REV_5719) |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2782 | tg3_ape_write32(tp, TG3_APE_GPIO_MSG, status); |
| 2783 | else |
| 2784 | tw32(TG3_CPMU_DRV_STATUS, status); |
| 2785 | |
| 2786 | return status >> TG3_APE_GPIO_MSG_SHIFT; |
| 2787 | } |
| 2788 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2789 | static inline int tg3_pwrsrc_switch_to_vmain(struct tg3 *tp) |
| 2790 | { |
| 2791 | if (!tg3_flag(tp, IS_NIC)) |
| 2792 | return 0; |
| 2793 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2794 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 2795 | tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 2796 | tg3_asic_rev(tp) == ASIC_REV_5720) { |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2797 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2798 | return -EIO; |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2799 | |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2800 | tg3_set_function_status(tp, TG3_GPIO_MSG_DRVR_PRES); |
| 2801 | |
| 2802 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2803 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2804 | |
| 2805 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
| 2806 | } else { |
| 2807 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2808 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2809 | } |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2810 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2811 | return 0; |
| 2812 | } |
| 2813 | |
| 2814 | static void tg3_pwrsrc_die_with_vmain(struct tg3 *tp) |
| 2815 | { |
| 2816 | u32 grc_local_ctrl; |
| 2817 | |
| 2818 | if (!tg3_flag(tp, IS_NIC) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2819 | tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 2820 | tg3_asic_rev(tp) == ASIC_REV_5701) |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2821 | return; |
| 2822 | |
| 2823 | grc_local_ctrl = tp->grc_local_ctrl | GRC_LCLCTRL_GPIO_OE1; |
| 2824 | |
| 2825 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2826 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2827 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2828 | |
| 2829 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2830 | grc_local_ctrl, |
| 2831 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2832 | |
| 2833 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2834 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2835 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2836 | } |
| 2837 | |
| 2838 | static void tg3_pwrsrc_switch_to_vaux(struct tg3 *tp) |
| 2839 | { |
| 2840 | if (!tg3_flag(tp, IS_NIC)) |
| 2841 | return; |
| 2842 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2843 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 2844 | tg3_asic_rev(tp) == ASIC_REV_5701) { |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2845 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2846 | (GRC_LCLCTRL_GPIO_OE0 | |
| 2847 | GRC_LCLCTRL_GPIO_OE1 | |
| 2848 | GRC_LCLCTRL_GPIO_OE2 | |
| 2849 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2850 | GRC_LCLCTRL_GPIO_OUTPUT1), |
| 2851 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2852 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 2853 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
| 2854 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
| 2855 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | |
| 2856 | GRC_LCLCTRL_GPIO_OE1 | |
| 2857 | GRC_LCLCTRL_GPIO_OE2 | |
| 2858 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2859 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2860 | tp->grc_local_ctrl; |
| 2861 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2862 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2863 | |
| 2864 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2865 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2866 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2867 | |
| 2868 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2869 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2870 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2871 | } else { |
| 2872 | u32 no_gpio2; |
| 2873 | u32 grc_local_ctrl = 0; |
| 2874 | |
| 2875 | /* Workaround to prevent overdrawing Amps. */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2876 | if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2877 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
| 2878 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2879 | grc_local_ctrl, |
| 2880 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2881 | } |
| 2882 | |
| 2883 | /* On 5753 and variants, GPIO2 cannot be used. */ |
| 2884 | no_gpio2 = tp->nic_sram_data_cfg & |
| 2885 | NIC_SRAM_DATA_CFG_NO_GPIO2; |
| 2886 | |
| 2887 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 2888 | GRC_LCLCTRL_GPIO_OE1 | |
| 2889 | GRC_LCLCTRL_GPIO_OE2 | |
| 2890 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2891 | GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2892 | if (no_gpio2) { |
| 2893 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | |
| 2894 | GRC_LCLCTRL_GPIO_OUTPUT2); |
| 2895 | } |
| 2896 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2897 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2898 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2899 | |
| 2900 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2901 | |
| 2902 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2903 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2904 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2905 | |
| 2906 | if (!no_gpio2) { |
| 2907 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2908 | tw32_wait_f(GRC_LOCAL_CTRL, |
| 2909 | tp->grc_local_ctrl | grc_local_ctrl, |
| 2910 | TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2911 | } |
| 2912 | } |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2913 | } |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2914 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2915 | 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] | 2916 | { |
| 2917 | u32 msg = 0; |
| 2918 | |
| 2919 | /* Serialize power state transitions */ |
| 2920 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2921 | return; |
| 2922 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2923 | 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] | 2924 | msg = TG3_GPIO_MSG_NEED_VAUX; |
| 2925 | |
| 2926 | msg = tg3_set_function_status(tp, msg); |
| 2927 | |
| 2928 | if (msg & TG3_GPIO_MSG_ALL_DRVR_PRES_MASK) |
| 2929 | goto done; |
| 2930 | |
| 2931 | if (msg & TG3_GPIO_MSG_ALL_NEED_VAUX_MASK) |
| 2932 | tg3_pwrsrc_switch_to_vaux(tp); |
| 2933 | else |
| 2934 | tg3_pwrsrc_die_with_vmain(tp); |
| 2935 | |
| 2936 | done: |
Matt Carlson | 6f5c8f83 | 2011-07-13 09:27:31 +0000 | [diff] [blame] | 2937 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2938 | } |
| 2939 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2940 | static void tg3_frob_aux_power(struct tg3 *tp, bool include_wol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | { |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2942 | bool need_vaux = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2944 | /* The GPIOs do something completely different on 57765. */ |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 2945 | if (!tg3_flag(tp, IS_NIC) || tg3_flag(tp, 57765_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | return; |
| 2947 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 2948 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 2949 | tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 2950 | tg3_asic_rev(tp) == ASIC_REV_5720) { |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2951 | tg3_frob_aux_power_5717(tp, include_wol ? |
| 2952 | tg3_flag(tp, WOL_ENABLE) != 0 : 0); |
Matt Carlson | 3a1e19d | 2011-07-13 09:27:32 +0000 | [diff] [blame] | 2953 | return; |
| 2954 | } |
| 2955 | |
| 2956 | if (tp->pdev_peer && tp->pdev_peer != tp->pdev) { |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2957 | struct net_device *dev_peer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2959 | dev_peer = pci_get_drvdata(tp->pdev_peer); |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2960 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2961 | /* remove_one() may have been run on the peer. */ |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2962 | if (dev_peer) { |
| 2963 | struct tg3 *tp_peer = netdev_priv(dev_peer); |
| 2964 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2965 | if (tg3_flag(tp_peer, INIT_COMPLETE)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2966 | return; |
| 2967 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2968 | if ((include_wol && tg3_flag(tp_peer, WOL_ENABLE)) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 2969 | tg3_flag(tp_peer, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2970 | need_vaux = true; |
| 2971 | } |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2972 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 2974 | if ((include_wol && tg3_flag(tp, WOL_ENABLE)) || |
| 2975 | tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 683644b | 2011-03-09 16:58:23 +0000 | [diff] [blame] | 2976 | need_vaux = true; |
| 2977 | |
Matt Carlson | 520b275 | 2011-06-13 13:39:02 +0000 | [diff] [blame] | 2978 | if (need_vaux) |
| 2979 | tg3_pwrsrc_switch_to_vaux(tp); |
| 2980 | else |
| 2981 | tg3_pwrsrc_die_with_vmain(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2984 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
| 2985 | { |
| 2986 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) |
| 2987 | return 1; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2988 | 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] | 2989 | if (speed != SPEED_10) |
| 2990 | return 1; |
| 2991 | } else if (speed == SPEED_10) |
| 2992 | return 1; |
| 2993 | |
| 2994 | return 0; |
| 2995 | } |
| 2996 | |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2997 | 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] | 2998 | { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2999 | u32 val; |
| 3000 | |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 3001 | if (tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) |
| 3002 | return; |
| 3003 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3004 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 3005 | if (tg3_asic_rev(tp) == ASIC_REV_5704) { |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 3006 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 3007 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); |
| 3008 | |
| 3009 | sg_dig_ctrl |= |
| 3010 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; |
| 3011 | tw32(SG_DIG_CTRL, sg_dig_ctrl); |
| 3012 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); |
| 3013 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 3014 | return; |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 3015 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 3016 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 3017 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 3018 | tg3_bmcr_reset(tp); |
| 3019 | val = tr32(GRC_MISC_CFG); |
| 3020 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); |
| 3021 | udelay(40); |
| 3022 | return; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3023 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 0e5f784 | 2009-11-02 14:26:38 +0000 | [diff] [blame] | 3024 | u32 phytest; |
| 3025 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 3026 | u32 phy; |
| 3027 | |
| 3028 | tg3_writephy(tp, MII_ADVERTISE, 0); |
| 3029 | tg3_writephy(tp, MII_BMCR, |
| 3030 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 3031 | |
| 3032 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 3033 | phytest | MII_TG3_FET_SHADOW_EN); |
| 3034 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { |
| 3035 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; |
| 3036 | tg3_writephy(tp, |
| 3037 | MII_TG3_FET_SHDW_AUXMODE4, |
| 3038 | phy); |
| 3039 | } |
| 3040 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 3041 | } |
| 3042 | return; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3043 | } else if (do_low_power) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 3044 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 3045 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3046 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 3047 | val = MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 3048 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | |
| 3049 | MII_TG3_AUXCTL_PCTL_VREG_11V; |
| 3050 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, val); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 3051 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 3052 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 3053 | /* The PHY should not be powered down on some chips because |
| 3054 | * of bugs. |
| 3055 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 3056 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 3057 | tg3_asic_rev(tp) == ASIC_REV_5704 || |
| 3058 | (tg3_asic_rev(tp) == ASIC_REV_5780 && |
Matt Carlson | 085f1af | 2012-04-02 09:01:40 +0000 | [diff] [blame] | 3059 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 3060 | (tg3_asic_rev(tp) == ASIC_REV_5717 && |
Matt Carlson | 085f1af | 2012-04-02 09:01:40 +0000 | [diff] [blame] | 3061 | !tp->pci_fn)) |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 3062 | return; |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 3063 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 3064 | if (tg3_chip_rev(tp) == CHIPREV_5784_AX || |
| 3065 | tg3_chip_rev(tp) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 3066 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 3067 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 3068 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; |
| 3069 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 3070 | } |
| 3071 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 3072 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 3073 | } |
| 3074 | |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 3075 | /* tp->lock is held. */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3076 | static int tg3_nvram_lock(struct tg3 *tp) |
| 3077 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3078 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3079 | int i; |
| 3080 | |
| 3081 | if (tp->nvram_lock_cnt == 0) { |
| 3082 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); |
| 3083 | for (i = 0; i < 8000; i++) { |
| 3084 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) |
| 3085 | break; |
| 3086 | udelay(20); |
| 3087 | } |
| 3088 | if (i == 8000) { |
| 3089 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 3090 | return -ENODEV; |
| 3091 | } |
| 3092 | } |
| 3093 | tp->nvram_lock_cnt++; |
| 3094 | } |
| 3095 | return 0; |
| 3096 | } |
| 3097 | |
| 3098 | /* tp->lock is held. */ |
| 3099 | static void tg3_nvram_unlock(struct tg3 *tp) |
| 3100 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3101 | if (tg3_flag(tp, NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3102 | if (tp->nvram_lock_cnt > 0) |
| 3103 | tp->nvram_lock_cnt--; |
| 3104 | if (tp->nvram_lock_cnt == 0) |
| 3105 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | /* tp->lock is held. */ |
| 3110 | static void tg3_enable_nvram_access(struct tg3 *tp) |
| 3111 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3112 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3113 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 3114 | |
| 3115 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); |
| 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | /* tp->lock is held. */ |
| 3120 | static void tg3_disable_nvram_access(struct tg3 *tp) |
| 3121 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3122 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3123 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 3124 | |
| 3125 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, |
| 3130 | u32 offset, u32 *val) |
| 3131 | { |
| 3132 | u32 tmp; |
| 3133 | int i; |
| 3134 | |
| 3135 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) |
| 3136 | return -EINVAL; |
| 3137 | |
| 3138 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | |
| 3139 | EEPROM_ADDR_DEVID_MASK | |
| 3140 | EEPROM_ADDR_READ); |
| 3141 | tw32(GRC_EEPROM_ADDR, |
| 3142 | tmp | |
| 3143 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 3144 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & |
| 3145 | EEPROM_ADDR_ADDR_MASK) | |
| 3146 | EEPROM_ADDR_READ | EEPROM_ADDR_START); |
| 3147 | |
| 3148 | for (i = 0; i < 1000; i++) { |
| 3149 | tmp = tr32(GRC_EEPROM_ADDR); |
| 3150 | |
| 3151 | if (tmp & EEPROM_ADDR_COMPLETE) |
| 3152 | break; |
| 3153 | msleep(1); |
| 3154 | } |
| 3155 | if (!(tmp & EEPROM_ADDR_COMPLETE)) |
| 3156 | return -EBUSY; |
| 3157 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 3158 | tmp = tr32(GRC_EEPROM_DATA); |
| 3159 | |
| 3160 | /* |
| 3161 | * The data will always be opposite the native endian |
| 3162 | * format. Perform a blind byteswap to compensate. |
| 3163 | */ |
| 3164 | *val = swab32(tmp); |
| 3165 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3166 | return 0; |
| 3167 | } |
| 3168 | |
| 3169 | #define NVRAM_CMD_TIMEOUT 10000 |
| 3170 | |
| 3171 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) |
| 3172 | { |
| 3173 | int i; |
| 3174 | |
| 3175 | tw32(NVRAM_CMD, nvram_cmd); |
| 3176 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { |
| 3177 | udelay(10); |
| 3178 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { |
| 3179 | udelay(10); |
| 3180 | break; |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | if (i == NVRAM_CMD_TIMEOUT) |
| 3185 | return -EBUSY; |
| 3186 | |
| 3187 | return 0; |
| 3188 | } |
| 3189 | |
| 3190 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) |
| 3191 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3192 | if (tg3_flag(tp, NVRAM) && |
| 3193 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 3194 | tg3_flag(tp, FLASH) && |
| 3195 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3196 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 3197 | |
| 3198 | addr = ((addr / tp->nvram_pagesize) << |
| 3199 | ATMEL_AT45DB0X1B_PAGE_POS) + |
| 3200 | (addr % tp->nvram_pagesize); |
| 3201 | |
| 3202 | return addr; |
| 3203 | } |
| 3204 | |
| 3205 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) |
| 3206 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3207 | if (tg3_flag(tp, NVRAM) && |
| 3208 | tg3_flag(tp, NVRAM_BUFFERED) && |
| 3209 | tg3_flag(tp, FLASH) && |
| 3210 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3211 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 3212 | |
| 3213 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * |
| 3214 | tp->nvram_pagesize) + |
| 3215 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); |
| 3216 | |
| 3217 | return addr; |
| 3218 | } |
| 3219 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 3220 | /* NOTE: Data read in from NVRAM is byteswapped according to |
| 3221 | * the byteswapping settings for all other register accesses. |
| 3222 | * tg3 devices are BE devices, so on a BE machine, the data |
| 3223 | * returned will be exactly as it is seen in NVRAM. On a LE |
| 3224 | * machine, the 32-bit value will be byteswapped. |
| 3225 | */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3226 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
| 3227 | { |
| 3228 | int ret; |
| 3229 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3230 | if (!tg3_flag(tp, NVRAM)) |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3231 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
| 3232 | |
| 3233 | offset = tg3_nvram_phys_addr(tp, offset); |
| 3234 | |
| 3235 | if (offset > NVRAM_ADDR_MSK) |
| 3236 | return -EINVAL; |
| 3237 | |
| 3238 | ret = tg3_nvram_lock(tp); |
| 3239 | if (ret) |
| 3240 | return ret; |
| 3241 | |
| 3242 | tg3_enable_nvram_access(tp); |
| 3243 | |
| 3244 | tw32(NVRAM_ADDR, offset); |
| 3245 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | |
| 3246 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); |
| 3247 | |
| 3248 | if (ret == 0) |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 3249 | *val = tr32(NVRAM_RDDATA); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3250 | |
| 3251 | tg3_disable_nvram_access(tp); |
| 3252 | |
| 3253 | tg3_nvram_unlock(tp); |
| 3254 | |
| 3255 | return ret; |
| 3256 | } |
| 3257 | |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 3258 | /* Ensures NVRAM data is in bytestream format. */ |
| 3259 | 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] | 3260 | { |
| 3261 | u32 v; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 3262 | int res = tg3_nvram_read(tp, offset, &v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3263 | if (!res) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 3264 | *val = cpu_to_be32(v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3265 | return res; |
| 3266 | } |
| 3267 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3268 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
| 3269 | u32 offset, u32 len, u8 *buf) |
| 3270 | { |
| 3271 | int i, j, rc = 0; |
| 3272 | u32 val; |
| 3273 | |
| 3274 | for (i = 0; i < len; i += 4) { |
| 3275 | u32 addr; |
| 3276 | __be32 data; |
| 3277 | |
| 3278 | addr = offset + i; |
| 3279 | |
| 3280 | memcpy(&data, buf + i, 4); |
| 3281 | |
| 3282 | /* |
| 3283 | * The SEEPROM interface expects the data to always be opposite |
| 3284 | * the native endian format. We accomplish this by reversing |
| 3285 | * all the operations that would have been performed on the |
| 3286 | * data from a call to tg3_nvram_read_be32(). |
| 3287 | */ |
| 3288 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); |
| 3289 | |
| 3290 | val = tr32(GRC_EEPROM_ADDR); |
| 3291 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); |
| 3292 | |
| 3293 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | |
| 3294 | EEPROM_ADDR_READ); |
| 3295 | tw32(GRC_EEPROM_ADDR, val | |
| 3296 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 3297 | (addr & EEPROM_ADDR_ADDR_MASK) | |
| 3298 | EEPROM_ADDR_START | |
| 3299 | EEPROM_ADDR_WRITE); |
| 3300 | |
| 3301 | for (j = 0; j < 1000; j++) { |
| 3302 | val = tr32(GRC_EEPROM_ADDR); |
| 3303 | |
| 3304 | if (val & EEPROM_ADDR_COMPLETE) |
| 3305 | break; |
| 3306 | msleep(1); |
| 3307 | } |
| 3308 | if (!(val & EEPROM_ADDR_COMPLETE)) { |
| 3309 | rc = -EBUSY; |
| 3310 | break; |
| 3311 | } |
| 3312 | } |
| 3313 | |
| 3314 | return rc; |
| 3315 | } |
| 3316 | |
| 3317 | /* offset and length are dword aligned */ |
| 3318 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, |
| 3319 | u8 *buf) |
| 3320 | { |
| 3321 | int ret = 0; |
| 3322 | u32 pagesize = tp->nvram_pagesize; |
| 3323 | u32 pagemask = pagesize - 1; |
| 3324 | u32 nvram_cmd; |
| 3325 | u8 *tmp; |
| 3326 | |
| 3327 | tmp = kmalloc(pagesize, GFP_KERNEL); |
| 3328 | if (tmp == NULL) |
| 3329 | return -ENOMEM; |
| 3330 | |
| 3331 | while (len) { |
| 3332 | int j; |
| 3333 | u32 phy_addr, page_off, size; |
| 3334 | |
| 3335 | phy_addr = offset & ~pagemask; |
| 3336 | |
| 3337 | for (j = 0; j < pagesize; j += 4) { |
| 3338 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
| 3339 | (__be32 *) (tmp + j)); |
| 3340 | if (ret) |
| 3341 | break; |
| 3342 | } |
| 3343 | if (ret) |
| 3344 | break; |
| 3345 | |
| 3346 | page_off = offset & pagemask; |
| 3347 | size = pagesize; |
| 3348 | if (len < size) |
| 3349 | size = len; |
| 3350 | |
| 3351 | len -= size; |
| 3352 | |
| 3353 | memcpy(tmp + page_off, buf, size); |
| 3354 | |
| 3355 | offset = offset + (pagesize - page_off); |
| 3356 | |
| 3357 | tg3_enable_nvram_access(tp); |
| 3358 | |
| 3359 | /* |
| 3360 | * Before we can erase the flash page, we need |
| 3361 | * to issue a special "write enable" command. |
| 3362 | */ |
| 3363 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3364 | |
| 3365 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3366 | break; |
| 3367 | |
| 3368 | /* Erase the target page */ |
| 3369 | tw32(NVRAM_ADDR, phy_addr); |
| 3370 | |
| 3371 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | |
| 3372 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; |
| 3373 | |
| 3374 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3375 | break; |
| 3376 | |
| 3377 | /* Issue another write enable to start the write. */ |
| 3378 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3379 | |
| 3380 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3381 | break; |
| 3382 | |
| 3383 | for (j = 0; j < pagesize; j += 4) { |
| 3384 | __be32 data; |
| 3385 | |
| 3386 | data = *((__be32 *) (tmp + j)); |
| 3387 | |
| 3388 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3389 | |
| 3390 | tw32(NVRAM_ADDR, phy_addr + j); |
| 3391 | |
| 3392 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | |
| 3393 | NVRAM_CMD_WR; |
| 3394 | |
| 3395 | if (j == 0) |
| 3396 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 3397 | else if (j == (pagesize - 4)) |
| 3398 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3399 | |
| 3400 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3401 | if (ret) |
| 3402 | break; |
| 3403 | } |
| 3404 | if (ret) |
| 3405 | break; |
| 3406 | } |
| 3407 | |
| 3408 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3409 | tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3410 | |
| 3411 | kfree(tmp); |
| 3412 | |
| 3413 | return ret; |
| 3414 | } |
| 3415 | |
| 3416 | /* offset and length are dword aligned */ |
| 3417 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, |
| 3418 | u8 *buf) |
| 3419 | { |
| 3420 | int i, ret = 0; |
| 3421 | |
| 3422 | for (i = 0; i < len; i += 4, offset += 4) { |
| 3423 | u32 page_off, phy_addr, nvram_cmd; |
| 3424 | __be32 data; |
| 3425 | |
| 3426 | memcpy(&data, buf + i, 4); |
| 3427 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3428 | |
| 3429 | page_off = offset % tp->nvram_pagesize; |
| 3430 | |
| 3431 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
| 3432 | |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3433 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
| 3434 | |
| 3435 | if (page_off == 0 || i == 0) |
| 3436 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 3437 | if (page_off == (tp->nvram_pagesize - 4)) |
| 3438 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3439 | |
| 3440 | if (i == (len - 4)) |
| 3441 | nvram_cmd |= NVRAM_CMD_LAST; |
| 3442 | |
Matt Carlson | 4227822 | 2012-02-13 15:20:11 +0000 | [diff] [blame] | 3443 | if ((nvram_cmd & NVRAM_CMD_FIRST) || |
| 3444 | !tg3_flag(tp, FLASH) || |
| 3445 | !tg3_flag(tp, 57765_PLUS)) |
| 3446 | tw32(NVRAM_ADDR, phy_addr); |
| 3447 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 3448 | if (tg3_asic_rev(tp) != ASIC_REV_5752 && |
Matt Carlson | dbe9b92 | 2012-02-13 10:20:09 +0000 | [diff] [blame] | 3449 | !tg3_flag(tp, 5755_PLUS) && |
| 3450 | (tp->nvram_jedecnum == JEDEC_ST) && |
| 3451 | (nvram_cmd & NVRAM_CMD_FIRST)) { |
| 3452 | u32 cmd; |
| 3453 | |
| 3454 | cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3455 | ret = tg3_nvram_exec_cmd(tp, cmd); |
| 3456 | if (ret) |
| 3457 | break; |
| 3458 | } |
| 3459 | if (!tg3_flag(tp, FLASH)) { |
| 3460 | /* We always do complete word writes to eeprom. */ |
| 3461 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); |
| 3462 | } |
| 3463 | |
| 3464 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3465 | if (ret) |
| 3466 | break; |
| 3467 | } |
| 3468 | return ret; |
| 3469 | } |
| 3470 | |
| 3471 | /* offset and length are dword aligned */ |
| 3472 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) |
| 3473 | { |
| 3474 | int ret; |
| 3475 | |
| 3476 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3477 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
| 3478 | ~GRC_LCLCTRL_GPIO_OUTPUT1); |
| 3479 | udelay(40); |
| 3480 | } |
| 3481 | |
| 3482 | if (!tg3_flag(tp, NVRAM)) { |
| 3483 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
| 3484 | } else { |
| 3485 | u32 grc_mode; |
| 3486 | |
| 3487 | ret = tg3_nvram_lock(tp); |
| 3488 | if (ret) |
| 3489 | return ret; |
| 3490 | |
| 3491 | tg3_enable_nvram_access(tp); |
| 3492 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) |
| 3493 | tw32(NVRAM_WRITE1, 0x406); |
| 3494 | |
| 3495 | grc_mode = tr32(GRC_MODE); |
| 3496 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); |
| 3497 | |
| 3498 | if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) { |
| 3499 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
| 3500 | buf); |
| 3501 | } else { |
| 3502 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
| 3503 | buf); |
| 3504 | } |
| 3505 | |
| 3506 | grc_mode = tr32(GRC_MODE); |
| 3507 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); |
| 3508 | |
| 3509 | tg3_disable_nvram_access(tp); |
| 3510 | tg3_nvram_unlock(tp); |
| 3511 | } |
| 3512 | |
| 3513 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3514 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 3515 | udelay(40); |
| 3516 | } |
| 3517 | |
| 3518 | return ret; |
| 3519 | } |
| 3520 | |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3521 | #define RX_CPU_SCRATCH_BASE 0x30000 |
| 3522 | #define RX_CPU_SCRATCH_SIZE 0x04000 |
| 3523 | #define TX_CPU_SCRATCH_BASE 0x34000 |
| 3524 | #define TX_CPU_SCRATCH_SIZE 0x04000 |
| 3525 | |
| 3526 | /* tp->lock is held. */ |
Nithin Sujir | 837c45b | 2013-03-06 17:02:30 +0000 | [diff] [blame] | 3527 | static int tg3_pause_cpu(struct tg3 *tp, u32 cpu_base) |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3528 | { |
| 3529 | int i; |
Nithin Sujir | 837c45b | 2013-03-06 17:02:30 +0000 | [diff] [blame] | 3530 | const int iters = 10000; |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3531 | |
Nithin Sujir | 837c45b | 2013-03-06 17:02:30 +0000 | [diff] [blame] | 3532 | for (i = 0; i < iters; i++) { |
| 3533 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3534 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
| 3535 | if (tr32(cpu_base + CPU_MODE) & CPU_MODE_HALT) |
| 3536 | break; |
| 3537 | } |
| 3538 | |
| 3539 | return (i == iters) ? -EBUSY : 0; |
| 3540 | } |
| 3541 | |
| 3542 | /* tp->lock is held. */ |
| 3543 | static int tg3_rxcpu_pause(struct tg3 *tp) |
| 3544 | { |
| 3545 | int rc = tg3_pause_cpu(tp, RX_CPU_BASE); |
| 3546 | |
| 3547 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3548 | tw32_f(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); |
| 3549 | udelay(10); |
| 3550 | |
| 3551 | return rc; |
| 3552 | } |
| 3553 | |
| 3554 | /* tp->lock is held. */ |
| 3555 | static int tg3_txcpu_pause(struct tg3 *tp) |
| 3556 | { |
| 3557 | return tg3_pause_cpu(tp, TX_CPU_BASE); |
| 3558 | } |
| 3559 | |
| 3560 | /* tp->lock is held. */ |
| 3561 | static void tg3_resume_cpu(struct tg3 *tp, u32 cpu_base) |
| 3562 | { |
| 3563 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3564 | tw32_f(cpu_base + CPU_MODE, 0x00000000); |
| 3565 | } |
| 3566 | |
| 3567 | /* tp->lock is held. */ |
| 3568 | static void tg3_rxcpu_resume(struct tg3 *tp) |
| 3569 | { |
| 3570 | tg3_resume_cpu(tp, RX_CPU_BASE); |
| 3571 | } |
| 3572 | |
| 3573 | /* tp->lock is held. */ |
| 3574 | static int tg3_halt_cpu(struct tg3 *tp, u32 cpu_base) |
| 3575 | { |
| 3576 | int rc; |
| 3577 | |
| 3578 | BUG_ON(cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3579 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 3580 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3581 | u32 val = tr32(GRC_VCPU_EXT_CTRL); |
| 3582 | |
| 3583 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 3584 | return 0; |
| 3585 | } |
Nithin Sujir | 837c45b | 2013-03-06 17:02:30 +0000 | [diff] [blame] | 3586 | if (cpu_base == RX_CPU_BASE) { |
| 3587 | rc = tg3_rxcpu_pause(tp); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3588 | } else { |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 3589 | /* |
| 3590 | * There is only an Rx CPU for the 5750 derivative in the |
| 3591 | * BCM4785. |
| 3592 | */ |
| 3593 | if (tg3_flag(tp, IS_SSB_CORE)) |
| 3594 | return 0; |
| 3595 | |
Nithin Sujir | 837c45b | 2013-03-06 17:02:30 +0000 | [diff] [blame] | 3596 | rc = tg3_txcpu_pause(tp); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3597 | } |
| 3598 | |
Nithin Sujir | 837c45b | 2013-03-06 17:02:30 +0000 | [diff] [blame] | 3599 | if (rc) { |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3600 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
Nithin Sujir | 837c45b | 2013-03-06 17:02:30 +0000 | [diff] [blame] | 3601 | __func__, cpu_base == RX_CPU_BASE ? "RX" : "TX"); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3602 | return -ENODEV; |
| 3603 | } |
| 3604 | |
| 3605 | /* Clear firmware's nvram arbitration. */ |
| 3606 | if (tg3_flag(tp, NVRAM)) |
| 3607 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
| 3608 | return 0; |
| 3609 | } |
| 3610 | |
Nithin Sujir | 31f11a9 | 2013-03-06 17:02:33 +0000 | [diff] [blame] | 3611 | static int tg3_fw_data_len(struct tg3 *tp, |
| 3612 | const struct tg3_firmware_hdr *fw_hdr) |
| 3613 | { |
| 3614 | int fw_len; |
| 3615 | |
| 3616 | /* Non fragmented firmware have one firmware header followed by a |
| 3617 | * contiguous chunk of data to be written. The length field in that |
| 3618 | * header is not the length of data to be written but the complete |
| 3619 | * length of the bss. The data length is determined based on |
| 3620 | * tp->fw->size minus headers. |
| 3621 | * |
| 3622 | * Fragmented firmware have a main header followed by multiple |
| 3623 | * fragments. Each fragment is identical to non fragmented firmware |
| 3624 | * with a firmware header followed by a contiguous chunk of data. In |
| 3625 | * the main header, the length field is unused and set to 0xffffffff. |
| 3626 | * In each fragment header the length is the entire size of that |
| 3627 | * fragment i.e. fragment data + header length. Data length is |
| 3628 | * therefore length field in the header minus TG3_FW_HDR_LEN. |
| 3629 | */ |
| 3630 | if (tp->fw_len == 0xffffffff) |
| 3631 | fw_len = be32_to_cpu(fw_hdr->len); |
| 3632 | else |
| 3633 | fw_len = tp->fw->size; |
| 3634 | |
| 3635 | return (fw_len - TG3_FW_HDR_LEN) / sizeof(u32); |
| 3636 | } |
| 3637 | |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3638 | /* tp->lock is held. */ |
| 3639 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, |
| 3640 | u32 cpu_scratch_base, int cpu_scratch_size, |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3641 | const struct tg3_firmware_hdr *fw_hdr) |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3642 | { |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 3643 | int err, i; |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3644 | void (*write_op)(struct tg3 *, u32, u32); |
Nithin Sujir | 31f11a9 | 2013-03-06 17:02:33 +0000 | [diff] [blame] | 3645 | int total_len = tp->fw->size; |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3646 | |
| 3647 | if (cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)) { |
| 3648 | netdev_err(tp->dev, |
| 3649 | "%s: Trying to load TX cpu firmware which is 5705\n", |
| 3650 | __func__); |
| 3651 | return -EINVAL; |
| 3652 | } |
| 3653 | |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 3654 | if (tg3_flag(tp, 5705_PLUS) && tg3_asic_rev(tp) != ASIC_REV_57766) |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3655 | write_op = tg3_write_mem; |
| 3656 | else |
| 3657 | write_op = tg3_write_indirect_reg32; |
| 3658 | |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 3659 | if (tg3_asic_rev(tp) != ASIC_REV_57766) { |
| 3660 | /* It is possible that bootcode is still loading at this point. |
| 3661 | * Get the nvram lock first before halting the cpu. |
| 3662 | */ |
| 3663 | int lock_err = tg3_nvram_lock(tp); |
| 3664 | err = tg3_halt_cpu(tp, cpu_base); |
| 3665 | if (!lock_err) |
| 3666 | tg3_nvram_unlock(tp); |
| 3667 | if (err) |
| 3668 | goto out; |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3669 | |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 3670 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
| 3671 | write_op(tp, cpu_scratch_base + i, 0); |
| 3672 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3673 | tw32(cpu_base + CPU_MODE, |
| 3674 | tr32(cpu_base + CPU_MODE) | CPU_MODE_HALT); |
| 3675 | } else { |
| 3676 | /* Subtract additional main header for fragmented firmware and |
| 3677 | * advance to the first fragment |
| 3678 | */ |
| 3679 | total_len -= TG3_FW_HDR_LEN; |
| 3680 | fw_hdr++; |
| 3681 | } |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3682 | |
Nithin Sujir | 31f11a9 | 2013-03-06 17:02:33 +0000 | [diff] [blame] | 3683 | do { |
| 3684 | u32 *fw_data = (u32 *)(fw_hdr + 1); |
| 3685 | for (i = 0; i < tg3_fw_data_len(tp, fw_hdr); i++) |
| 3686 | write_op(tp, cpu_scratch_base + |
| 3687 | (be32_to_cpu(fw_hdr->base_addr) & 0xffff) + |
| 3688 | (i * sizeof(u32)), |
| 3689 | be32_to_cpu(fw_data[i])); |
| 3690 | |
| 3691 | total_len -= be32_to_cpu(fw_hdr->len); |
| 3692 | |
| 3693 | /* Advance to next fragment */ |
| 3694 | fw_hdr = (struct tg3_firmware_hdr *) |
| 3695 | ((void *)fw_hdr + be32_to_cpu(fw_hdr->len)); |
| 3696 | } while (total_len > 0); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3697 | |
| 3698 | err = 0; |
| 3699 | |
| 3700 | out: |
| 3701 | return err; |
| 3702 | } |
| 3703 | |
| 3704 | /* tp->lock is held. */ |
Nithin Sujir | f4bffb2 | 2013-03-06 17:02:31 +0000 | [diff] [blame] | 3705 | static int tg3_pause_cpu_and_set_pc(struct tg3 *tp, u32 cpu_base, u32 pc) |
| 3706 | { |
| 3707 | int i; |
| 3708 | const int iters = 5; |
| 3709 | |
| 3710 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3711 | tw32_f(cpu_base + CPU_PC, pc); |
| 3712 | |
| 3713 | for (i = 0; i < iters; i++) { |
| 3714 | if (tr32(cpu_base + CPU_PC) == pc) |
| 3715 | break; |
| 3716 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3717 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
| 3718 | tw32_f(cpu_base + CPU_PC, pc); |
| 3719 | udelay(1000); |
| 3720 | } |
| 3721 | |
| 3722 | return (i == iters) ? -EBUSY : 0; |
| 3723 | } |
| 3724 | |
| 3725 | /* tp->lock is held. */ |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3726 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) |
| 3727 | { |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3728 | const struct tg3_firmware_hdr *fw_hdr; |
Nithin Sujir | f4bffb2 | 2013-03-06 17:02:31 +0000 | [diff] [blame] | 3729 | int err; |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3730 | |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3731 | fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3732 | |
| 3733 | /* Firmware blob starts with version numbers, followed by |
| 3734 | start address and length. We are setting complete length. |
| 3735 | length = end_address_of_bss - start_address_of_text. |
| 3736 | Remainder is the blob to be loaded contiguously |
| 3737 | from start address. */ |
| 3738 | |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3739 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
| 3740 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3741 | fw_hdr); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3742 | if (err) |
| 3743 | return err; |
| 3744 | |
| 3745 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, |
| 3746 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3747 | fw_hdr); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3748 | if (err) |
| 3749 | return err; |
| 3750 | |
| 3751 | /* Now startup only the RX cpu. */ |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3752 | err = tg3_pause_cpu_and_set_pc(tp, RX_CPU_BASE, |
| 3753 | be32_to_cpu(fw_hdr->base_addr)); |
Nithin Sujir | f4bffb2 | 2013-03-06 17:02:31 +0000 | [diff] [blame] | 3754 | if (err) { |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3755 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
| 3756 | "should be %08x\n", __func__, |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3757 | tr32(RX_CPU_BASE + CPU_PC), |
| 3758 | be32_to_cpu(fw_hdr->base_addr)); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3759 | return -ENODEV; |
| 3760 | } |
Nithin Sujir | 837c45b | 2013-03-06 17:02:30 +0000 | [diff] [blame] | 3761 | |
| 3762 | tg3_rxcpu_resume(tp); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3763 | |
| 3764 | return 0; |
| 3765 | } |
| 3766 | |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 3767 | static int tg3_validate_rxcpu_state(struct tg3 *tp) |
| 3768 | { |
| 3769 | const int iters = 1000; |
| 3770 | int i; |
| 3771 | u32 val; |
| 3772 | |
| 3773 | /* Wait for boot code to complete initialization and enter service |
| 3774 | * loop. It is then safe to download service patches |
| 3775 | */ |
| 3776 | for (i = 0; i < iters; i++) { |
| 3777 | if (tr32(RX_CPU_HWBKPT) == TG3_SBROM_IN_SERVICE_LOOP) |
| 3778 | break; |
| 3779 | |
| 3780 | udelay(10); |
| 3781 | } |
| 3782 | |
| 3783 | if (i == iters) { |
| 3784 | netdev_err(tp->dev, "Boot code not ready for service patches\n"); |
| 3785 | return -EBUSY; |
| 3786 | } |
| 3787 | |
| 3788 | val = tg3_read_indirect_reg32(tp, TG3_57766_FW_HANDSHAKE); |
| 3789 | if (val & 0xff) { |
| 3790 | netdev_warn(tp->dev, |
| 3791 | "Other patches exist. Not downloading EEE patch\n"); |
| 3792 | return -EEXIST; |
| 3793 | } |
| 3794 | |
| 3795 | return 0; |
| 3796 | } |
| 3797 | |
| 3798 | /* tp->lock is held. */ |
| 3799 | static void tg3_load_57766_firmware(struct tg3 *tp) |
| 3800 | { |
| 3801 | struct tg3_firmware_hdr *fw_hdr; |
| 3802 | |
| 3803 | if (!tg3_flag(tp, NO_NVRAM)) |
| 3804 | return; |
| 3805 | |
| 3806 | if (tg3_validate_rxcpu_state(tp)) |
| 3807 | return; |
| 3808 | |
| 3809 | if (!tp->fw) |
| 3810 | return; |
| 3811 | |
| 3812 | /* This firmware blob has a different format than older firmware |
| 3813 | * releases as given below. The main difference is we have fragmented |
| 3814 | * data to be written to non-contiguous locations. |
| 3815 | * |
| 3816 | * In the beginning we have a firmware header identical to other |
| 3817 | * firmware which consists of version, base addr and length. The length |
| 3818 | * here is unused and set to 0xffffffff. |
| 3819 | * |
| 3820 | * This is followed by a series of firmware fragments which are |
| 3821 | * individually identical to previous firmware. i.e. they have the |
| 3822 | * firmware header and followed by data for that fragment. The version |
| 3823 | * field of the individual fragment header is unused. |
| 3824 | */ |
| 3825 | |
| 3826 | fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
| 3827 | if (be32_to_cpu(fw_hdr->base_addr) != TG3_57766_FW_BASE_ADDR) |
| 3828 | return; |
| 3829 | |
| 3830 | if (tg3_rxcpu_pause(tp)) |
| 3831 | return; |
| 3832 | |
| 3833 | /* tg3_load_firmware_cpu() will always succeed for the 57766 */ |
| 3834 | tg3_load_firmware_cpu(tp, 0, TG3_57766_FW_BASE_ADDR, 0, fw_hdr); |
| 3835 | |
| 3836 | tg3_rxcpu_resume(tp); |
| 3837 | } |
| 3838 | |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3839 | /* tp->lock is held. */ |
| 3840 | static int tg3_load_tso_firmware(struct tg3 *tp) |
| 3841 | { |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3842 | const struct tg3_firmware_hdr *fw_hdr; |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3843 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
Nithin Sujir | f4bffb2 | 2013-03-06 17:02:31 +0000 | [diff] [blame] | 3844 | int err; |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3845 | |
Matt Carlson | 1caf13e | 2013-03-06 17:02:29 +0000 | [diff] [blame] | 3846 | if (!tg3_flag(tp, FW_TSO)) |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3847 | return 0; |
| 3848 | |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3849 | fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3850 | |
| 3851 | /* Firmware blob starts with version numbers, followed by |
| 3852 | start address and length. We are setting complete length. |
| 3853 | length = end_address_of_bss - start_address_of_text. |
| 3854 | Remainder is the blob to be loaded contiguously |
| 3855 | from start address. */ |
| 3856 | |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3857 | cpu_scratch_size = tp->fw_len; |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3858 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 3859 | if (tg3_asic_rev(tp) == ASIC_REV_5705) { |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3860 | cpu_base = RX_CPU_BASE; |
| 3861 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; |
| 3862 | } else { |
| 3863 | cpu_base = TX_CPU_BASE; |
| 3864 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; |
| 3865 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; |
| 3866 | } |
| 3867 | |
| 3868 | err = tg3_load_firmware_cpu(tp, cpu_base, |
| 3869 | cpu_scratch_base, cpu_scratch_size, |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3870 | fw_hdr); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3871 | if (err) |
| 3872 | return err; |
| 3873 | |
| 3874 | /* Now startup the cpu. */ |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3875 | err = tg3_pause_cpu_and_set_pc(tp, cpu_base, |
| 3876 | be32_to_cpu(fw_hdr->base_addr)); |
Nithin Sujir | f4bffb2 | 2013-03-06 17:02:31 +0000 | [diff] [blame] | 3877 | if (err) { |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3878 | netdev_err(tp->dev, |
| 3879 | "%s fails to set CPU PC, is %08x should be %08x\n", |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 3880 | __func__, tr32(cpu_base + CPU_PC), |
| 3881 | be32_to_cpu(fw_hdr->base_addr)); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3882 | return -ENODEV; |
| 3883 | } |
Nithin Sujir | 837c45b | 2013-03-06 17:02:30 +0000 | [diff] [blame] | 3884 | |
| 3885 | tg3_resume_cpu(tp, cpu_base); |
Matt Carlson | 997b4f1 | 2011-08-31 11:44:53 +0000 | [diff] [blame] | 3886 | return 0; |
| 3887 | } |
| 3888 | |
| 3889 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 3890 | /* tp->lock is held. */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 3891 | static void __tg3_set_mac_addr(struct tg3 *tp, bool skip_mac_1) |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 3892 | { |
| 3893 | u32 addr_high, addr_low; |
| 3894 | int i; |
| 3895 | |
| 3896 | addr_high = ((tp->dev->dev_addr[0] << 8) | |
| 3897 | tp->dev->dev_addr[1]); |
| 3898 | addr_low = ((tp->dev->dev_addr[2] << 24) | |
| 3899 | (tp->dev->dev_addr[3] << 16) | |
| 3900 | (tp->dev->dev_addr[4] << 8) | |
| 3901 | (tp->dev->dev_addr[5] << 0)); |
| 3902 | for (i = 0; i < 4; i++) { |
| 3903 | if (i == 1 && skip_mac_1) |
| 3904 | continue; |
| 3905 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); |
| 3906 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); |
| 3907 | } |
| 3908 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 3909 | if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
| 3910 | tg3_asic_rev(tp) == ASIC_REV_5704) { |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 3911 | for (i = 0; i < 12; i++) { |
| 3912 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); |
| 3913 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); |
| 3914 | } |
| 3915 | } |
| 3916 | |
| 3917 | addr_high = (tp->dev->dev_addr[0] + |
| 3918 | tp->dev->dev_addr[1] + |
| 3919 | tp->dev->dev_addr[2] + |
| 3920 | tp->dev->dev_addr[3] + |
| 3921 | tp->dev->dev_addr[4] + |
| 3922 | tp->dev->dev_addr[5]) & |
| 3923 | TX_BACKOFF_SEED_MASK; |
| 3924 | tw32(MAC_TX_BACKOFF_SEED, addr_high); |
| 3925 | } |
| 3926 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3927 | static void tg3_enable_register_access(struct tg3 *tp) |
| 3928 | { |
| 3929 | /* |
| 3930 | * Make sure register accesses (indirect or otherwise) will function |
| 3931 | * correctly. |
| 3932 | */ |
| 3933 | pci_write_config_dword(tp->pdev, |
| 3934 | TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl); |
| 3935 | } |
| 3936 | |
| 3937 | static int tg3_power_up(struct tg3 *tp) |
| 3938 | { |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3939 | int err; |
| 3940 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3941 | tg3_enable_register_access(tp); |
| 3942 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3943 | err = pci_set_power_state(tp->pdev, PCI_D0); |
| 3944 | if (!err) { |
| 3945 | /* Switch out of Vaux if it is a NIC */ |
| 3946 | tg3_pwrsrc_switch_to_vmain(tp); |
| 3947 | } else { |
| 3948 | netdev_err(tp->dev, "Transition to D0 failed\n"); |
| 3949 | } |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3950 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 3951 | return err; |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3952 | } |
| 3953 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 3954 | static int tg3_setup_phy(struct tg3 *, bool); |
Matt Carlson | 4b40952 | 2012-02-13 10:20:11 +0000 | [diff] [blame] | 3955 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3956 | static int tg3_power_down_prepare(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | { |
| 3958 | u32 misc_host_ctrl; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3959 | bool device_should_wake, do_low_power; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3961 | tg3_enable_register_access(tp); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3962 | |
| 3963 | /* Restore the CLKREQ setting. */ |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 3964 | if (tg3_flag(tp, CLKREQ_BUG)) |
| 3965 | pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL, |
| 3966 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3967 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 3969 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 3970 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); |
| 3971 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 3972 | device_should_wake = device_may_wakeup(&tp->pdev->dev) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3973 | tg3_flag(tp, WOL_ENABLE); |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 3974 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3975 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3976 | do_low_power = false; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3977 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3978 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3979 | struct phy_device *phydev; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 3980 | u32 phyid, advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3981 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 3982 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3983 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3984 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3985 | |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 3986 | tp->link_config.speed = phydev->speed; |
| 3987 | tp->link_config.duplex = phydev->duplex; |
| 3988 | tp->link_config.autoneg = phydev->autoneg; |
| 3989 | tp->link_config.advertising = phydev->advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3990 | |
| 3991 | advertising = ADVERTISED_TP | |
| 3992 | ADVERTISED_Pause | |
| 3993 | ADVERTISED_Autoneg | |
| 3994 | ADVERTISED_10baseT_Half; |
| 3995 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 3996 | if (tg3_flag(tp, ENABLE_ASF) || device_should_wake) { |
| 3997 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 3998 | advertising |= |
| 3999 | ADVERTISED_100baseT_Half | |
| 4000 | ADVERTISED_100baseT_Full | |
| 4001 | ADVERTISED_10baseT_Full; |
| 4002 | else |
| 4003 | advertising |= ADVERTISED_10baseT_Full; |
| 4004 | } |
| 4005 | |
| 4006 | phydev->advertising = advertising; |
| 4007 | |
| 4008 | phy_start_aneg(phydev); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 4009 | |
| 4010 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 4011 | if (phyid != PHY_ID_BCMAC131) { |
| 4012 | phyid &= PHY_BCM_OUI_MASK; |
| 4013 | if (phyid == PHY_BCM_OUI_1 || |
| 4014 | phyid == PHY_BCM_OUI_2 || |
| 4015 | phyid == PHY_BCM_OUI_3) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 4016 | do_low_power = true; |
| 4017 | } |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 4018 | } |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 4019 | } else { |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 4020 | do_low_power = true; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 4021 | |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 4022 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 4023 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | |
Matt Carlson | 2855b9f | 2012-02-13 15:20:14 +0000 | [diff] [blame] | 4025 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4026 | tg3_setup_phy(tp, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4029 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 4030 | u32 val; |
| 4031 | |
| 4032 | val = tr32(GRC_VCPU_EXT_CTRL); |
| 4033 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4034 | } else if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 4035 | int i; |
| 4036 | u32 val; |
| 4037 | |
| 4038 | for (i = 0; i < 200; i++) { |
| 4039 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); |
| 4040 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 4041 | break; |
| 4042 | msleep(1); |
| 4043 | } |
| 4044 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4045 | if (tg3_flag(tp, WOL_CAP)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 4046 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
| 4047 | WOL_DRV_STATE_SHUTDOWN | |
| 4048 | WOL_DRV_WOL | |
| 4049 | WOL_SET_MAGIC_PKT); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 4050 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 4051 | if (device_should_wake) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | u32 mac_mode; |
| 4053 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4054 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4055 | if (do_low_power && |
| 4056 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 4057 | tg3_phy_auxctl_write(tp, |
| 4058 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL, |
| 4059 | MII_TG3_AUXCTL_PCTL_WOL_EN | |
| 4060 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 4061 | MII_TG3_AUXCTL_PCTL_CL_AB_TXDAC); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 4062 | udelay(40); |
| 4063 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4065 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 4066 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 4067 | else if (tp->phy_flags & |
| 4068 | TG3_PHYFLG_KEEP_LINK_ON_PWRDN) { |
| 4069 | if (tp->link_config.active_speed == SPEED_1000) |
| 4070 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 4071 | else |
| 4072 | mac_mode = MAC_MODE_PORT_MODE_MII; |
| 4073 | } else |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 4074 | mac_mode = MAC_MODE_PORT_MODE_MII; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4076 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4077 | if (tg3_asic_rev(tp) == ASIC_REV_5700) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4078 | u32 speed = tg3_flag(tp, WOL_SPEED_100MB) ? |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4079 | SPEED_100 : SPEED_10; |
| 4080 | if (tg3_5700_link_polarity(tp, speed)) |
| 4081 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 4082 | else |
| 4083 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 4084 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | } else { |
| 4086 | mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 4087 | } |
| 4088 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4089 | if (!tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 4091 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 4092 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4093 | if ((tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) && |
| 4094 | (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE))) |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 4095 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4097 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 4098 | mac_mode |= MAC_MODE_APE_TX_EN | |
| 4099 | MAC_MODE_APE_RX_EN | |
| 4100 | MAC_MODE_TDE_ENABLE; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 4101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | tw32_f(MAC_MODE, mac_mode); |
| 4103 | udelay(100); |
| 4104 | |
| 4105 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); |
| 4106 | udelay(10); |
| 4107 | } |
| 4108 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4109 | if (!tg3_flag(tp, WOL_SPEED_100MB) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4110 | (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 4111 | tg3_asic_rev(tp) == ASIC_REV_5701)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4112 | u32 base_val; |
| 4113 | |
| 4114 | base_val = tp->pci_clock_ctrl; |
| 4115 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | |
| 4116 | CLOCK_CTRL_TXCLK_DISABLE); |
| 4117 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 4118 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
| 4119 | CLOCK_CTRL_PWRDOWN_PLL133, 40); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4120 | } else if (tg3_flag(tp, 5780_CLASS) || |
| 4121 | tg3_flag(tp, CPMU_PRESENT) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4122 | tg3_asic_rev(tp) == ASIC_REV_5906) { |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 4123 | /* do nothing */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4124 | } else if (!(tg3_flag(tp, 5750_PLUS) && tg3_flag(tp, ENABLE_ASF))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | u32 newbits1, newbits2; |
| 4126 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4127 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 4128 | tg3_asic_rev(tp) == ASIC_REV_5701) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 4130 | CLOCK_CTRL_TXCLK_DISABLE | |
| 4131 | CLOCK_CTRL_ALTCLK); |
| 4132 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4133 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | newbits1 = CLOCK_CTRL_625_CORE; |
| 4135 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; |
| 4136 | } else { |
| 4137 | newbits1 = CLOCK_CTRL_ALTCLK; |
| 4138 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 4139 | } |
| 4140 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 4141 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
| 4142 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 4144 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
| 4145 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4147 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | u32 newbits3; |
| 4149 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4150 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 4151 | tg3_asic_rev(tp) == ASIC_REV_5701) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 4153 | CLOCK_CTRL_TXCLK_DISABLE | |
| 4154 | CLOCK_CTRL_44MHZ_CORE); |
| 4155 | } else { |
| 4156 | newbits3 = CLOCK_CTRL_44MHZ_CORE; |
| 4157 | } |
| 4158 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 4159 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 4160 | tp->pci_clock_ctrl | newbits3, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | } |
| 4162 | } |
| 4163 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4164 | if (!(device_should_wake) && !tg3_flag(tp, ENABLE_ASF)) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 4165 | tg3_power_down_phy(tp, do_low_power); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 4166 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 4167 | tg3_frob_aux_power(tp, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | |
| 4169 | /* Workaround for unstable PLL clock */ |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 4170 | if ((!tg3_flag(tp, IS_SSB_CORE)) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4171 | ((tg3_chip_rev(tp) == CHIPREV_5750_AX) || |
| 4172 | (tg3_chip_rev(tp) == CHIPREV_5750_BX))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | u32 val = tr32(0x7d00); |
| 4174 | |
| 4175 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); |
| 4176 | tw32(0x7d00, val); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4177 | if (!tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 4178 | int err; |
| 4179 | |
| 4180 | err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 4182 | if (!err) |
| 4183 | tg3_nvram_unlock(tp); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 4184 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | } |
| 4186 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 4187 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
| 4188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | return 0; |
| 4190 | } |
| 4191 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 4192 | static void tg3_power_down(struct tg3 *tp) |
| 4193 | { |
| 4194 | tg3_power_down_prepare(tp); |
| 4195 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4196 | pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 4197 | pci_set_power_state(tp->pdev, PCI_D3hot); |
| 4198 | } |
| 4199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
| 4201 | { |
| 4202 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { |
| 4203 | case MII_TG3_AUX_STAT_10HALF: |
| 4204 | *speed = SPEED_10; |
| 4205 | *duplex = DUPLEX_HALF; |
| 4206 | break; |
| 4207 | |
| 4208 | case MII_TG3_AUX_STAT_10FULL: |
| 4209 | *speed = SPEED_10; |
| 4210 | *duplex = DUPLEX_FULL; |
| 4211 | break; |
| 4212 | |
| 4213 | case MII_TG3_AUX_STAT_100HALF: |
| 4214 | *speed = SPEED_100; |
| 4215 | *duplex = DUPLEX_HALF; |
| 4216 | break; |
| 4217 | |
| 4218 | case MII_TG3_AUX_STAT_100FULL: |
| 4219 | *speed = SPEED_100; |
| 4220 | *duplex = DUPLEX_FULL; |
| 4221 | break; |
| 4222 | |
| 4223 | case MII_TG3_AUX_STAT_1000HALF: |
| 4224 | *speed = SPEED_1000; |
| 4225 | *duplex = DUPLEX_HALF; |
| 4226 | break; |
| 4227 | |
| 4228 | case MII_TG3_AUX_STAT_1000FULL: |
| 4229 | *speed = SPEED_1000; |
| 4230 | *duplex = DUPLEX_FULL; |
| 4231 | break; |
| 4232 | |
| 4233 | default: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4234 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 4235 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
| 4236 | SPEED_10; |
| 4237 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : |
| 4238 | DUPLEX_HALF; |
| 4239 | break; |
| 4240 | } |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 4241 | *speed = SPEED_UNKNOWN; |
| 4242 | *duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4243 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | } |
| 4246 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4247 | 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] | 4248 | { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4249 | int err = 0; |
| 4250 | u32 val, new_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4252 | new_adv = ADVERTISE_CSMA; |
Hiroaki SHIMODA | 202ff1c | 2011-11-22 04:05:41 +0000 | [diff] [blame] | 4253 | new_adv |= ethtool_adv_to_mii_adv_t(advertise) & ADVERTISE_ALL; |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 4254 | new_adv |= mii_advertise_flowctrl(flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4256 | err = tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 4257 | if (err) |
| 4258 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 4260 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4261 | new_adv = ethtool_adv_to_mii_ctrl1000_t(advertise); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4262 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4263 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
| 4264 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0) |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 4265 | new_adv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4266 | |
Matt Carlson | 4f27209 | 2011-12-14 11:09:57 +0000 | [diff] [blame] | 4267 | err = tg3_writephy(tp, MII_CTRL1000, new_adv); |
| 4268 | if (err) |
| 4269 | goto done; |
| 4270 | } |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4271 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4272 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 4273 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4275 | tw32(TG3_CPMU_EEE_MODE, |
| 4276 | tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4277 | |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 4278 | err = tg3_phy_toggle_auxctl_smdsp(tp, true); |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4279 | if (!err) { |
| 4280 | u32 err2; |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4281 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 4282 | val = 0; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4283 | /* Advertise 100-BaseTX EEE ability */ |
| 4284 | if (advertise & ADVERTISED_100baseT_Full) |
| 4285 | val |= MDIO_AN_EEE_ADV_100TX; |
| 4286 | /* Advertise 1000-BaseT EEE ability */ |
| 4287 | if (advertise & ADVERTISED_1000baseT_Full) |
| 4288 | val |= MDIO_AN_EEE_ADV_1000T; |
Nithin Sujir | 9e2ecbe | 2013-05-18 06:26:52 +0000 | [diff] [blame] | 4289 | |
| 4290 | if (!tp->eee.eee_enabled) { |
| 4291 | val = 0; |
| 4292 | tp->eee.advertised = 0; |
| 4293 | } else { |
| 4294 | tp->eee.advertised = advertise & |
| 4295 | (ADVERTISED_100baseT_Full | |
| 4296 | ADVERTISED_1000baseT_Full); |
| 4297 | } |
| 4298 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4299 | 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] | 4300 | if (err) |
| 4301 | val = 0; |
| 4302 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4303 | switch (tg3_asic_rev(tp)) { |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 4304 | case ASIC_REV_5717: |
| 4305 | case ASIC_REV_57765: |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 4306 | case ASIC_REV_57766: |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 4307 | case ASIC_REV_5719: |
| 4308 | /* If we advertised any eee advertisements above... */ |
| 4309 | if (val) |
| 4310 | val = MII_TG3_DSP_TAP26_ALNOKO | |
| 4311 | MII_TG3_DSP_TAP26_RMRXSTO | |
| 4312 | MII_TG3_DSP_TAP26_OPCSINPT; |
| 4313 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
| 4314 | /* Fall through */ |
| 4315 | case ASIC_REV_5720: |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 4316 | case ASIC_REV_5762: |
Matt Carlson | b715ce9 | 2011-07-20 10:20:52 +0000 | [diff] [blame] | 4317 | if (!tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) |
| 4318 | tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, val | |
| 4319 | MII_TG3_DSP_CH34TP2_HIBW01); |
| 4320 | } |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4321 | |
Nithin Nayak Sujir | daf3ec6 | 2013-01-14 17:11:00 +0000 | [diff] [blame] | 4322 | err2 = tg3_phy_toggle_auxctl_smdsp(tp, false); |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4323 | if (!err) |
| 4324 | err = err2; |
| 4325 | } |
| 4326 | |
| 4327 | done: |
| 4328 | return err; |
| 4329 | } |
| 4330 | |
| 4331 | static void tg3_phy_copper_begin(struct tg3 *tp) |
| 4332 | { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4333 | if (tp->link_config.autoneg == AUTONEG_ENABLE || |
| 4334 | (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 4335 | u32 adv, fc; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4336 | |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 4337 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
| 4338 | !(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN)) { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4339 | adv = ADVERTISED_10baseT_Half | |
| 4340 | ADVERTISED_10baseT_Full; |
| 4341 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
| 4342 | adv |= ADVERTISED_100baseT_Half | |
| 4343 | ADVERTISED_100baseT_Full; |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 4344 | if (tp->phy_flags & TG3_PHYFLG_1G_ON_VAUX_OK) |
| 4345 | adv |= ADVERTISED_1000baseT_Half | |
| 4346 | ADVERTISED_1000baseT_Full; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4347 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4348 | fc = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4349 | } else { |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4350 | adv = tp->link_config.advertising; |
| 4351 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 4352 | adv &= ~(ADVERTISED_1000baseT_Half | |
| 4353 | ADVERTISED_1000baseT_Full); |
| 4354 | |
| 4355 | fc = tp->link_config.flowctrl; |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 4356 | } |
| 4357 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4358 | tg3_phy_autoneg_cfg(tp, adv, fc); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4359 | |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 4360 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
| 4361 | (tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN)) { |
| 4362 | /* Normally during power down we want to autonegotiate |
| 4363 | * the lowest possible speed for WOL. However, to avoid |
| 4364 | * link flap, we leave it untouched. |
| 4365 | */ |
| 4366 | return; |
| 4367 | } |
| 4368 | |
Matt Carlson | d13ba51 | 2012-02-22 12:35:19 +0000 | [diff] [blame] | 4369 | tg3_writephy(tp, MII_BMCR, |
| 4370 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 4371 | } else { |
| 4372 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | u32 bmcr, orig_bmcr; |
| 4374 | |
| 4375 | tp->link_config.active_speed = tp->link_config.speed; |
| 4376 | tp->link_config.active_duplex = tp->link_config.duplex; |
| 4377 | |
Nithin Sujir | 7c6cdea | 2013-03-12 15:32:48 +0000 | [diff] [blame] | 4378 | if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
| 4379 | /* With autoneg disabled, 5715 only links up when the |
| 4380 | * advertisement register has the configured speed |
| 4381 | * enabled. |
| 4382 | */ |
| 4383 | tg3_writephy(tp, MII_ADVERTISE, ADVERTISE_ALL); |
| 4384 | } |
| 4385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | bmcr = 0; |
| 4387 | switch (tp->link_config.speed) { |
| 4388 | default: |
| 4389 | case SPEED_10: |
| 4390 | break; |
| 4391 | |
| 4392 | case SPEED_100: |
| 4393 | bmcr |= BMCR_SPEED100; |
| 4394 | break; |
| 4395 | |
| 4396 | case SPEED_1000: |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 4397 | bmcr |= BMCR_SPEED1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | |
| 4401 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 4402 | bmcr |= BMCR_FULLDPLX; |
| 4403 | |
| 4404 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && |
| 4405 | (bmcr != orig_bmcr)) { |
| 4406 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); |
| 4407 | for (i = 0; i < 1500; i++) { |
| 4408 | u32 tmp; |
| 4409 | |
| 4410 | udelay(10); |
| 4411 | if (tg3_readphy(tp, MII_BMSR, &tmp) || |
| 4412 | tg3_readphy(tp, MII_BMSR, &tmp)) |
| 4413 | continue; |
| 4414 | if (!(tmp & BMSR_LSTATUS)) { |
| 4415 | udelay(40); |
| 4416 | break; |
| 4417 | } |
| 4418 | } |
| 4419 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 4420 | udelay(40); |
| 4421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | } |
| 4423 | } |
| 4424 | |
Nithin Sujir | fdad8de | 2013-04-09 08:48:08 +0000 | [diff] [blame] | 4425 | static int tg3_phy_pull_config(struct tg3 *tp) |
| 4426 | { |
| 4427 | int err; |
| 4428 | u32 val; |
| 4429 | |
| 4430 | err = tg3_readphy(tp, MII_BMCR, &val); |
| 4431 | if (err) |
| 4432 | goto done; |
| 4433 | |
| 4434 | if (!(val & BMCR_ANENABLE)) { |
| 4435 | tp->link_config.autoneg = AUTONEG_DISABLE; |
| 4436 | tp->link_config.advertising = 0; |
| 4437 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
| 4438 | |
| 4439 | err = -EIO; |
| 4440 | |
| 4441 | switch (val & (BMCR_SPEED1000 | BMCR_SPEED100)) { |
| 4442 | case 0: |
| 4443 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 4444 | goto done; |
| 4445 | |
| 4446 | tp->link_config.speed = SPEED_10; |
| 4447 | break; |
| 4448 | case BMCR_SPEED100: |
| 4449 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 4450 | goto done; |
| 4451 | |
| 4452 | tp->link_config.speed = SPEED_100; |
| 4453 | break; |
| 4454 | case BMCR_SPEED1000: |
| 4455 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4456 | tp->link_config.speed = SPEED_1000; |
| 4457 | break; |
| 4458 | } |
| 4459 | /* Fall through */ |
| 4460 | default: |
| 4461 | goto done; |
| 4462 | } |
| 4463 | |
| 4464 | if (val & BMCR_FULLDPLX) |
| 4465 | tp->link_config.duplex = DUPLEX_FULL; |
| 4466 | else |
| 4467 | tp->link_config.duplex = DUPLEX_HALF; |
| 4468 | |
| 4469 | tp->link_config.flowctrl = FLOW_CTRL_RX | FLOW_CTRL_TX; |
| 4470 | |
| 4471 | err = 0; |
| 4472 | goto done; |
| 4473 | } |
| 4474 | |
| 4475 | tp->link_config.autoneg = AUTONEG_ENABLE; |
| 4476 | tp->link_config.advertising = ADVERTISED_Autoneg; |
| 4477 | tg3_flag_set(tp, PAUSE_AUTONEG); |
| 4478 | |
| 4479 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 4480 | u32 adv; |
| 4481 | |
| 4482 | err = tg3_readphy(tp, MII_ADVERTISE, &val); |
| 4483 | if (err) |
| 4484 | goto done; |
| 4485 | |
| 4486 | adv = mii_adv_to_ethtool_adv_t(val & ADVERTISE_ALL); |
| 4487 | tp->link_config.advertising |= adv | ADVERTISED_TP; |
| 4488 | |
| 4489 | tp->link_config.flowctrl = tg3_decode_flowctrl_1000T(val); |
| 4490 | } else { |
| 4491 | tp->link_config.advertising |= ADVERTISED_FIBRE; |
| 4492 | } |
| 4493 | |
| 4494 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4495 | u32 adv; |
| 4496 | |
| 4497 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 4498 | err = tg3_readphy(tp, MII_CTRL1000, &val); |
| 4499 | if (err) |
| 4500 | goto done; |
| 4501 | |
| 4502 | adv = mii_ctrl1000_to_ethtool_adv_t(val); |
| 4503 | } else { |
| 4504 | err = tg3_readphy(tp, MII_ADVERTISE, &val); |
| 4505 | if (err) |
| 4506 | goto done; |
| 4507 | |
| 4508 | adv = tg3_decode_flowctrl_1000X(val); |
| 4509 | tp->link_config.flowctrl = adv; |
| 4510 | |
| 4511 | val &= (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL); |
| 4512 | adv = mii_adv_to_ethtool_adv_x(val); |
| 4513 | } |
| 4514 | |
| 4515 | tp->link_config.advertising |= adv; |
| 4516 | } |
| 4517 | |
| 4518 | done: |
| 4519 | return err; |
| 4520 | } |
| 4521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | static int tg3_init_5401phy_dsp(struct tg3 *tp) |
| 4523 | { |
| 4524 | int err; |
| 4525 | |
| 4526 | /* Turn off tap power management. */ |
| 4527 | /* Set Extended packet length bit */ |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4528 | err = tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 4530 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
| 4531 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); |
| 4532 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); |
| 4533 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); |
| 4534 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | |
| 4536 | udelay(40); |
| 4537 | |
| 4538 | return err; |
| 4539 | } |
| 4540 | |
Nithin Sujir | ed1ff5c | 2013-04-09 08:48:09 +0000 | [diff] [blame] | 4541 | static bool tg3_phy_eee_config_ok(struct tg3 *tp) |
| 4542 | { |
Nithin Sujir | 5b6c273 | 2013-05-18 06:26:54 +0000 | [diff] [blame] | 4543 | struct ethtool_eee eee; |
Nithin Sujir | ed1ff5c | 2013-04-09 08:48:09 +0000 | [diff] [blame] | 4544 | |
| 4545 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 4546 | return true; |
| 4547 | |
Nithin Sujir | 5b6c273 | 2013-05-18 06:26:54 +0000 | [diff] [blame] | 4548 | tg3_eee_pull_config(tp, &eee); |
Nithin Sujir | ed1ff5c | 2013-04-09 08:48:09 +0000 | [diff] [blame] | 4549 | |
Nithin Sujir | 5b6c273 | 2013-05-18 06:26:54 +0000 | [diff] [blame] | 4550 | if (tp->eee.eee_enabled) { |
| 4551 | if (tp->eee.advertised != eee.advertised || |
| 4552 | tp->eee.tx_lpi_timer != eee.tx_lpi_timer || |
| 4553 | tp->eee.tx_lpi_enabled != eee.tx_lpi_enabled) |
| 4554 | return false; |
| 4555 | } else { |
| 4556 | /* EEE is disabled but we're advertising */ |
| 4557 | if (eee.advertised) |
| 4558 | return false; |
| 4559 | } |
Nithin Sujir | ed1ff5c | 2013-04-09 08:48:09 +0000 | [diff] [blame] | 4560 | |
| 4561 | return true; |
| 4562 | } |
| 4563 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4564 | 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] | 4565 | { |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4566 | u32 advmsk, tgtadv, advertising; |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 4567 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4568 | advertising = tp->link_config.advertising; |
| 4569 | tgtadv = ethtool_adv_to_mii_adv_t(advertising) & ADVERTISE_ALL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4571 | advmsk = ADVERTISE_ALL; |
| 4572 | if (tp->link_config.active_duplex == DUPLEX_FULL) { |
Matt Carlson | f88788f | 2011-12-14 11:10:00 +0000 | [diff] [blame] | 4573 | tgtadv |= mii_advertise_flowctrl(tp->link_config.flowctrl); |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4574 | advmsk |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 4575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4577 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
| 4578 | return false; |
| 4579 | |
| 4580 | if ((*lcladv & advmsk) != tgtadv) |
| 4581 | return false; |
Matt Carlson | b99d2a5 | 2011-08-31 11:44:47 +0000 | [diff] [blame] | 4582 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4583 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | u32 tg3_ctrl; |
| 4585 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4586 | tgtadv = ethtool_adv_to_mii_ctrl1000_t(advertising); |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 4587 | |
Matt Carlson | 221c563 | 2011-06-13 13:39:01 +0000 | [diff] [blame] | 4588 | if (tg3_readphy(tp, MII_CTRL1000, &tg3_ctrl)) |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4589 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | |
Matt Carlson | 3198e07 | 2012-02-13 15:20:10 +0000 | [diff] [blame] | 4591 | if (tgtadv && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4592 | (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
| 4593 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0)) { |
Matt Carlson | 3198e07 | 2012-02-13 15:20:10 +0000 | [diff] [blame] | 4594 | tgtadv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
| 4595 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL | |
| 4596 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
| 4597 | } else { |
| 4598 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL); |
| 4599 | } |
| 4600 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4601 | if (tg3_ctrl != tgtadv) |
| 4602 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | } |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 4604 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4605 | return true; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4606 | } |
| 4607 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4608 | static bool tg3_phy_copper_fetch_rmtadv(struct tg3 *tp, u32 *rmtadv) |
| 4609 | { |
| 4610 | u32 lpeth = 0; |
| 4611 | |
| 4612 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4613 | u32 val; |
| 4614 | |
| 4615 | if (tg3_readphy(tp, MII_STAT1000, &val)) |
| 4616 | return false; |
| 4617 | |
| 4618 | lpeth = mii_stat1000_to_ethtool_lpa_t(val); |
| 4619 | } |
| 4620 | |
| 4621 | if (tg3_readphy(tp, MII_LPA, rmtadv)) |
| 4622 | return false; |
| 4623 | |
| 4624 | lpeth |= mii_lpa_to_ethtool_lpa_t(*rmtadv); |
| 4625 | tp->link_config.rmt_adv = lpeth; |
| 4626 | |
| 4627 | return true; |
| 4628 | } |
| 4629 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4630 | static bool tg3_test_and_report_link_chg(struct tg3 *tp, bool curr_link_up) |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 4631 | { |
| 4632 | if (curr_link_up != tp->link_up) { |
| 4633 | if (curr_link_up) { |
Nithin Sujir | 84421b9 | 2013-03-08 08:01:24 +0000 | [diff] [blame] | 4634 | netif_carrier_on(tp->dev); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 4635 | } else { |
Nithin Sujir | 84421b9 | 2013-03-08 08:01:24 +0000 | [diff] [blame] | 4636 | netif_carrier_off(tp->dev); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 4637 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
| 4638 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 4639 | } |
| 4640 | |
| 4641 | tg3_link_report(tp); |
| 4642 | return true; |
| 4643 | } |
| 4644 | |
| 4645 | return false; |
| 4646 | } |
| 4647 | |
Michael Chan | 3310e24 | 2013-04-09 08:48:05 +0000 | [diff] [blame] | 4648 | static void tg3_clear_mac_status(struct tg3 *tp) |
| 4649 | { |
| 4650 | tw32(MAC_EVENT, 0); |
| 4651 | |
| 4652 | tw32_f(MAC_STATUS, |
| 4653 | MAC_STATUS_SYNC_CHANGED | |
| 4654 | MAC_STATUS_CFG_CHANGED | |
| 4655 | MAC_STATUS_MI_COMPLETION | |
| 4656 | MAC_STATUS_LNKSTATE_CHANGED); |
| 4657 | udelay(40); |
| 4658 | } |
| 4659 | |
Nithin Sujir | 9e2ecbe | 2013-05-18 06:26:52 +0000 | [diff] [blame] | 4660 | static void tg3_setup_eee(struct tg3 *tp) |
| 4661 | { |
| 4662 | u32 val; |
| 4663 | |
| 4664 | val = TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | |
| 4665 | TG3_CPMU_EEE_LNKIDL_UART_IDL; |
| 4666 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) |
| 4667 | val |= TG3_CPMU_EEE_LNKIDL_APE_TX_MT; |
| 4668 | |
| 4669 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, val); |
| 4670 | |
| 4671 | tw32_f(TG3_CPMU_EEE_CTRL, |
| 4672 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); |
| 4673 | |
| 4674 | val = TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
| 4675 | (tp->eee.tx_lpi_enabled ? TG3_CPMU_EEEMD_LPI_IN_TX : 0) | |
| 4676 | TG3_CPMU_EEEMD_LPI_IN_RX | |
| 4677 | TG3_CPMU_EEEMD_EEE_ENABLE; |
| 4678 | |
| 4679 | if (tg3_asic_rev(tp) != ASIC_REV_5717) |
| 4680 | val |= TG3_CPMU_EEEMD_SND_IDX_DET_EN; |
| 4681 | |
| 4682 | if (tg3_flag(tp, ENABLE_APE)) |
| 4683 | val |= TG3_CPMU_EEEMD_APE_TX_DET_EN; |
| 4684 | |
| 4685 | tw32_f(TG3_CPMU_EEE_MODE, tp->eee.eee_enabled ? val : 0); |
| 4686 | |
| 4687 | tw32_f(TG3_CPMU_EEE_DBTMR1, |
| 4688 | TG3_CPMU_DBTMR1_PCIEXIT_2047US | |
| 4689 | (tp->eee.tx_lpi_timer & 0xffff)); |
| 4690 | |
| 4691 | tw32_f(TG3_CPMU_EEE_DBTMR2, |
| 4692 | TG3_CPMU_DBTMR2_APE_TX_2047US | |
| 4693 | TG3_CPMU_DBTMR2_TXIDXEQ_2047US); |
| 4694 | } |
| 4695 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4696 | static int tg3_setup_copper_phy(struct tg3 *tp, bool force_reset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | { |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4698 | bool current_link_up; |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4699 | u32 bmsr, val; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4700 | u32 lcl_adv, rmt_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | u16 current_speed; |
| 4702 | u8 current_duplex; |
| 4703 | int i, err; |
| 4704 | |
Michael Chan | 3310e24 | 2013-04-09 08:48:05 +0000 | [diff] [blame] | 4705 | tg3_clear_mac_status(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4706 | |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 4707 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 4708 | tw32_f(MAC_MI_MODE, |
| 4709 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 4710 | udelay(80); |
| 4711 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4713 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | |
| 4715 | /* Some third-party PHYs need to be reset on link going |
| 4716 | * down. |
| 4717 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4718 | if ((tg3_asic_rev(tp) == ASIC_REV_5703 || |
| 4719 | tg3_asic_rev(tp) == ASIC_REV_5704 || |
| 4720 | tg3_asic_rev(tp) == ASIC_REV_5705) && |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 4721 | tp->link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4723 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4724 | !(bmsr & BMSR_LSTATUS)) |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4725 | force_reset = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | } |
| 4727 | if (force_reset) |
| 4728 | tg3_phy_reset(tp); |
| 4729 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4730 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4731 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4732 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4733 | !tg3_flag(tp, INIT_COMPLETE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | bmsr = 0; |
| 4735 | |
| 4736 | if (!(bmsr & BMSR_LSTATUS)) { |
| 4737 | err = tg3_init_5401phy_dsp(tp); |
| 4738 | if (err) |
| 4739 | return err; |
| 4740 | |
| 4741 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4742 | for (i = 0; i < 1000; i++) { |
| 4743 | udelay(10); |
| 4744 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4745 | (bmsr & BMSR_LSTATUS)) { |
| 4746 | udelay(40); |
| 4747 | break; |
| 4748 | } |
| 4749 | } |
| 4750 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4751 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
| 4752 | TG3_PHY_REV_BCM5401_B0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | !(bmsr & BMSR_LSTATUS) && |
| 4754 | tp->link_config.active_speed == SPEED_1000) { |
| 4755 | err = tg3_phy_reset(tp); |
| 4756 | if (!err) |
| 4757 | err = tg3_init_5401phy_dsp(tp); |
| 4758 | if (err) |
| 4759 | return err; |
| 4760 | } |
| 4761 | } |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4762 | } else if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
| 4763 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | /* 5701 {A0,B0} CRC bug workaround */ |
| 4765 | tg3_writephy(tp, 0x15, 0x0a75); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4766 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
| 4767 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 4768 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | /* Clear pending interrupts... */ |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4772 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
| 4773 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4775 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4776 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4777 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4778 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
| 4779 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4780 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 4781 | tg3_asic_rev(tp) == ASIC_REV_5701) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
| 4783 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 4784 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 4785 | else |
| 4786 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); |
| 4787 | } |
| 4788 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4789 | current_link_up = false; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 4790 | current_speed = SPEED_UNKNOWN; |
| 4791 | current_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4792 | tp->phy_flags &= ~TG3_PHYFLG_MDIX_STATE; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4793 | tp->link_config.rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4795 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
Matt Carlson | 15ee95c | 2011-04-20 07:57:40 +0000 | [diff] [blame] | 4796 | err = tg3_phy_auxctl_read(tp, |
| 4797 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4798 | &val); |
| 4799 | if (!err && !(val & (1 << 10))) { |
Matt Carlson | b4bd292 | 2011-04-20 07:57:41 +0000 | [diff] [blame] | 4800 | tg3_phy_auxctl_write(tp, |
| 4801 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4802 | val | (1 << 10)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4803 | goto relink; |
| 4804 | } |
| 4805 | } |
| 4806 | |
| 4807 | bmsr = 0; |
| 4808 | for (i = 0; i < 100; i++) { |
| 4809 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4810 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4811 | (bmsr & BMSR_LSTATUS)) |
| 4812 | break; |
| 4813 | udelay(40); |
| 4814 | } |
| 4815 | |
| 4816 | if (bmsr & BMSR_LSTATUS) { |
| 4817 | u32 aux_stat, bmcr; |
| 4818 | |
| 4819 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); |
| 4820 | for (i = 0; i < 2000; i++) { |
| 4821 | udelay(10); |
| 4822 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && |
| 4823 | aux_stat) |
| 4824 | break; |
| 4825 | } |
| 4826 | |
| 4827 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, |
| 4828 | ¤t_speed, |
| 4829 | ¤t_duplex); |
| 4830 | |
| 4831 | bmcr = 0; |
| 4832 | for (i = 0; i < 200; i++) { |
| 4833 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4834 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) |
| 4835 | continue; |
| 4836 | if (bmcr && bmcr != 0x7fff) |
| 4837 | break; |
| 4838 | udelay(10); |
| 4839 | } |
| 4840 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4841 | lcl_adv = 0; |
| 4842 | rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4843 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4844 | tp->link_config.active_speed = current_speed; |
| 4845 | tp->link_config.active_duplex = current_duplex; |
| 4846 | |
| 4847 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Nithin Sujir | ed1ff5c | 2013-04-09 08:48:09 +0000 | [diff] [blame] | 4848 | bool eee_config_ok = tg3_phy_eee_config_ok(tp); |
| 4849 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4850 | if ((bmcr & BMCR_ANENABLE) && |
Nithin Sujir | ed1ff5c | 2013-04-09 08:48:09 +0000 | [diff] [blame] | 4851 | eee_config_ok && |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 4852 | tg3_phy_copper_an_config_ok(tp, &lcl_adv) && |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 4853 | tg3_phy_copper_fetch_rmtadv(tp, &rmt_adv)) |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4854 | current_link_up = true; |
Nithin Sujir | ed1ff5c | 2013-04-09 08:48:09 +0000 | [diff] [blame] | 4855 | |
| 4856 | /* EEE settings changes take effect only after a phy |
| 4857 | * reset. If we have skipped a reset due to Link Flap |
| 4858 | * Avoidance being enabled, do it now. |
| 4859 | */ |
| 4860 | if (!eee_config_ok && |
| 4861 | (tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) && |
Nithin Sujir | 5b6c273 | 2013-05-18 06:26:54 +0000 | [diff] [blame] | 4862 | !force_reset) { |
| 4863 | tg3_setup_eee(tp); |
Nithin Sujir | ed1ff5c | 2013-04-09 08:48:09 +0000 | [diff] [blame] | 4864 | tg3_phy_reset(tp); |
Nithin Sujir | 5b6c273 | 2013-05-18 06:26:54 +0000 | [diff] [blame] | 4865 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | } else { |
| 4867 | if (!(bmcr & BMCR_ANENABLE) && |
| 4868 | tp->link_config.speed == current_speed && |
Nithin Sujir | f0fcd7a | 2013-04-09 08:48:01 +0000 | [diff] [blame] | 4869 | tp->link_config.duplex == current_duplex) { |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4870 | current_link_up = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | } |
| 4872 | } |
| 4873 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4874 | if (current_link_up && |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4875 | tp->link_config.active_duplex == DUPLEX_FULL) { |
| 4876 | u32 reg, bit; |
| 4877 | |
| 4878 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 4879 | reg = MII_TG3_FET_GEN_STAT; |
| 4880 | bit = MII_TG3_FET_GEN_STAT_MDIXSTAT; |
| 4881 | } else { |
| 4882 | reg = MII_TG3_EXT_STAT; |
| 4883 | bit = MII_TG3_EXT_STAT_MDIX; |
| 4884 | } |
| 4885 | |
| 4886 | if (!tg3_readphy(tp, reg, &val) && (val & bit)) |
| 4887 | tp->phy_flags |= TG3_PHYFLG_MDIX_STATE; |
| 4888 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4889 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 4890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | } |
| 4892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | relink: |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4894 | if (!current_link_up || (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4895 | tg3_phy_copper_begin(tp); |
| 4896 | |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 4897 | if (tg3_flag(tp, ROBOSWITCH)) { |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4898 | current_link_up = true; |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 4899 | /* FIXME: when BCM5325 switch is used use 100 MBit/s */ |
| 4900 | current_speed = SPEED_1000; |
| 4901 | current_duplex = DUPLEX_FULL; |
| 4902 | tp->link_config.active_speed = current_speed; |
| 4903 | tp->link_config.active_duplex = current_duplex; |
| 4904 | } |
| 4905 | |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 4906 | tg3_readphy(tp, MII_BMSR, &bmsr); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 4907 | if ((!tg3_readphy(tp, MII_BMSR, &bmsr) && (bmsr & BMSR_LSTATUS)) || |
| 4908 | (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4909 | current_link_up = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4913 | if (current_link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | if (tp->link_config.active_speed == SPEED_100 || |
| 4915 | tp->link_config.active_speed == SPEED_10) |
| 4916 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4917 | else |
| 4918 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4919 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 4920 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4921 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4923 | |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 4924 | /* In order for the 5750 core in BCM4785 chip to work properly |
| 4925 | * in RGMII mode, the Led Control Register must be set up. |
| 4926 | */ |
| 4927 | if (tg3_flag(tp, RGMII_MODE)) { |
| 4928 | u32 led_ctrl = tr32(MAC_LED_CTRL); |
| 4929 | led_ctrl &= ~(LED_CTRL_1000MBPS_ON | LED_CTRL_100MBPS_ON); |
| 4930 | |
| 4931 | if (tp->link_config.active_speed == SPEED_10) |
| 4932 | led_ctrl |= LED_CTRL_LNKLED_OVERRIDE; |
| 4933 | else if (tp->link_config.active_speed == SPEED_100) |
| 4934 | led_ctrl |= (LED_CTRL_LNKLED_OVERRIDE | |
| 4935 | LED_CTRL_100MBPS_ON); |
| 4936 | else if (tp->link_config.active_speed == SPEED_1000) |
| 4937 | led_ctrl |= (LED_CTRL_LNKLED_OVERRIDE | |
| 4938 | LED_CTRL_1000MBPS_ON); |
| 4939 | |
| 4940 | tw32(MAC_LED_CTRL, led_ctrl); |
| 4941 | udelay(40); |
| 4942 | } |
| 4943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 4945 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 4946 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 4947 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4948 | if (tg3_asic_rev(tp) == ASIC_REV_5700) { |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4949 | if (current_link_up && |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4950 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4952 | else |
| 4953 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | /* ??? Without this setting Netgear GA302T PHY does not |
| 4957 | * ??? send/receive packets... |
| 4958 | */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4959 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4960 | tg3_chip_rev_id(tp) == CHIPREV_ID_5700_ALTIMA) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
| 4962 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 4963 | udelay(80); |
| 4964 | } |
| 4965 | |
| 4966 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4967 | udelay(40); |
| 4968 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 4969 | tg3_phy_eee_adjust(tp, current_link_up); |
| 4970 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4971 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | /* Polled via timer. */ |
| 4973 | tw32_f(MAC_EVENT, 0); |
| 4974 | } else { |
| 4975 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4976 | } |
| 4977 | udelay(40); |
| 4978 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 4979 | if (tg3_asic_rev(tp) == ASIC_REV_5700 && |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 4980 | current_link_up && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | tp->link_config.active_speed == SPEED_1000 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4982 | (tg3_flag(tp, PCIX_MODE) || tg3_flag(tp, PCI_HIGH_SPEED))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | udelay(120); |
| 4984 | tw32_f(MAC_STATUS, |
| 4985 | (MAC_STATUS_SYNC_CHANGED | |
| 4986 | MAC_STATUS_CFG_CHANGED)); |
| 4987 | udelay(40); |
| 4988 | tg3_write_mem(tp, |
| 4989 | NIC_SRAM_FIRMWARE_MBOX, |
| 4990 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); |
| 4991 | } |
| 4992 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4993 | /* Prevent send BD corruption. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 4994 | if (tg3_flag(tp, CLKREQ_BUG)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4995 | if (tp->link_config.active_speed == SPEED_100 || |
| 4996 | tp->link_config.active_speed == SPEED_10) |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 4997 | pcie_capability_clear_word(tp->pdev, PCI_EXP_LNKCTL, |
| 4998 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 4999 | else |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 5000 | pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL, |
| 5001 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 5002 | } |
| 5003 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5004 | tg3_test_and_report_link_chg(tp, current_link_up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | |
| 5006 | return 0; |
| 5007 | } |
| 5008 | |
| 5009 | struct tg3_fiber_aneginfo { |
| 5010 | int state; |
| 5011 | #define ANEG_STATE_UNKNOWN 0 |
| 5012 | #define ANEG_STATE_AN_ENABLE 1 |
| 5013 | #define ANEG_STATE_RESTART_INIT 2 |
| 5014 | #define ANEG_STATE_RESTART 3 |
| 5015 | #define ANEG_STATE_DISABLE_LINK_OK 4 |
| 5016 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 |
| 5017 | #define ANEG_STATE_ABILITY_DETECT 6 |
| 5018 | #define ANEG_STATE_ACK_DETECT_INIT 7 |
| 5019 | #define ANEG_STATE_ACK_DETECT 8 |
| 5020 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 |
| 5021 | #define ANEG_STATE_COMPLETE_ACK 10 |
| 5022 | #define ANEG_STATE_IDLE_DETECT_INIT 11 |
| 5023 | #define ANEG_STATE_IDLE_DETECT 12 |
| 5024 | #define ANEG_STATE_LINK_OK 13 |
| 5025 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 |
| 5026 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 |
| 5027 | |
| 5028 | u32 flags; |
| 5029 | #define MR_AN_ENABLE 0x00000001 |
| 5030 | #define MR_RESTART_AN 0x00000002 |
| 5031 | #define MR_AN_COMPLETE 0x00000004 |
| 5032 | #define MR_PAGE_RX 0x00000008 |
| 5033 | #define MR_NP_LOADED 0x00000010 |
| 5034 | #define MR_TOGGLE_TX 0x00000020 |
| 5035 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 |
| 5036 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 |
| 5037 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 |
| 5038 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 |
| 5039 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 |
| 5040 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 |
| 5041 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 |
| 5042 | #define MR_TOGGLE_RX 0x00002000 |
| 5043 | #define MR_NP_RX 0x00004000 |
| 5044 | |
| 5045 | #define MR_LINK_OK 0x80000000 |
| 5046 | |
| 5047 | unsigned long link_time, cur_time; |
| 5048 | |
| 5049 | u32 ability_match_cfg; |
| 5050 | int ability_match_count; |
| 5051 | |
| 5052 | char ability_match, idle_match, ack_match; |
| 5053 | |
| 5054 | u32 txconfig, rxconfig; |
| 5055 | #define ANEG_CFG_NP 0x00000080 |
| 5056 | #define ANEG_CFG_ACK 0x00000040 |
| 5057 | #define ANEG_CFG_RF2 0x00000020 |
| 5058 | #define ANEG_CFG_RF1 0x00000010 |
| 5059 | #define ANEG_CFG_PS2 0x00000001 |
| 5060 | #define ANEG_CFG_PS1 0x00008000 |
| 5061 | #define ANEG_CFG_HD 0x00004000 |
| 5062 | #define ANEG_CFG_FD 0x00002000 |
| 5063 | #define ANEG_CFG_INVAL 0x00001f06 |
| 5064 | |
| 5065 | }; |
| 5066 | #define ANEG_OK 0 |
| 5067 | #define ANEG_DONE 1 |
| 5068 | #define ANEG_TIMER_ENAB 2 |
| 5069 | #define ANEG_FAILED -1 |
| 5070 | |
| 5071 | #define ANEG_STATE_SETTLE_TIME 10000 |
| 5072 | |
| 5073 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, |
| 5074 | struct tg3_fiber_aneginfo *ap) |
| 5075 | { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5076 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | unsigned long delta; |
| 5078 | u32 rx_cfg_reg; |
| 5079 | int ret; |
| 5080 | |
| 5081 | if (ap->state == ANEG_STATE_UNKNOWN) { |
| 5082 | ap->rxconfig = 0; |
| 5083 | ap->link_time = 0; |
| 5084 | ap->cur_time = 0; |
| 5085 | ap->ability_match_cfg = 0; |
| 5086 | ap->ability_match_count = 0; |
| 5087 | ap->ability_match = 0; |
| 5088 | ap->idle_match = 0; |
| 5089 | ap->ack_match = 0; |
| 5090 | } |
| 5091 | ap->cur_time++; |
| 5092 | |
| 5093 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { |
| 5094 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); |
| 5095 | |
| 5096 | if (rx_cfg_reg != ap->ability_match_cfg) { |
| 5097 | ap->ability_match_cfg = rx_cfg_reg; |
| 5098 | ap->ability_match = 0; |
| 5099 | ap->ability_match_count = 0; |
| 5100 | } else { |
| 5101 | if (++ap->ability_match_count > 1) { |
| 5102 | ap->ability_match = 1; |
| 5103 | ap->ability_match_cfg = rx_cfg_reg; |
| 5104 | } |
| 5105 | } |
| 5106 | if (rx_cfg_reg & ANEG_CFG_ACK) |
| 5107 | ap->ack_match = 1; |
| 5108 | else |
| 5109 | ap->ack_match = 0; |
| 5110 | |
| 5111 | ap->idle_match = 0; |
| 5112 | } else { |
| 5113 | ap->idle_match = 1; |
| 5114 | ap->ability_match_cfg = 0; |
| 5115 | ap->ability_match_count = 0; |
| 5116 | ap->ability_match = 0; |
| 5117 | ap->ack_match = 0; |
| 5118 | |
| 5119 | rx_cfg_reg = 0; |
| 5120 | } |
| 5121 | |
| 5122 | ap->rxconfig = rx_cfg_reg; |
| 5123 | ret = ANEG_OK; |
| 5124 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 5125 | switch (ap->state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5126 | case ANEG_STATE_UNKNOWN: |
| 5127 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) |
| 5128 | ap->state = ANEG_STATE_AN_ENABLE; |
| 5129 | |
| 5130 | /* fallthru */ |
| 5131 | case ANEG_STATE_AN_ENABLE: |
| 5132 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); |
| 5133 | if (ap->flags & MR_AN_ENABLE) { |
| 5134 | ap->link_time = 0; |
| 5135 | ap->cur_time = 0; |
| 5136 | ap->ability_match_cfg = 0; |
| 5137 | ap->ability_match_count = 0; |
| 5138 | ap->ability_match = 0; |
| 5139 | ap->idle_match = 0; |
| 5140 | ap->ack_match = 0; |
| 5141 | |
| 5142 | ap->state = ANEG_STATE_RESTART_INIT; |
| 5143 | } else { |
| 5144 | ap->state = ANEG_STATE_DISABLE_LINK_OK; |
| 5145 | } |
| 5146 | break; |
| 5147 | |
| 5148 | case ANEG_STATE_RESTART_INIT: |
| 5149 | ap->link_time = ap->cur_time; |
| 5150 | ap->flags &= ~(MR_NP_LOADED); |
| 5151 | ap->txconfig = 0; |
| 5152 | tw32(MAC_TX_AUTO_NEG, 0); |
| 5153 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 5154 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5155 | udelay(40); |
| 5156 | |
| 5157 | ret = ANEG_TIMER_ENAB; |
| 5158 | ap->state = ANEG_STATE_RESTART; |
| 5159 | |
| 5160 | /* fallthru */ |
| 5161 | case ANEG_STATE_RESTART: |
| 5162 | delta = ap->cur_time - ap->link_time; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5163 | if (delta > ANEG_STATE_SETTLE_TIME) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5165 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5166 | ret = ANEG_TIMER_ENAB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5167 | break; |
| 5168 | |
| 5169 | case ANEG_STATE_DISABLE_LINK_OK: |
| 5170 | ret = ANEG_DONE; |
| 5171 | break; |
| 5172 | |
| 5173 | case ANEG_STATE_ABILITY_DETECT_INIT: |
| 5174 | ap->flags &= ~(MR_TOGGLE_TX); |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5175 | ap->txconfig = ANEG_CFG_FD; |
| 5176 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 5177 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 5178 | ap->txconfig |= ANEG_CFG_PS1; |
| 5179 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 5180 | ap->txconfig |= ANEG_CFG_PS2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5181 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 5182 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 5183 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5184 | udelay(40); |
| 5185 | |
| 5186 | ap->state = ANEG_STATE_ABILITY_DETECT; |
| 5187 | break; |
| 5188 | |
| 5189 | case ANEG_STATE_ABILITY_DETECT: |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5190 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5191 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5192 | break; |
| 5193 | |
| 5194 | case ANEG_STATE_ACK_DETECT_INIT: |
| 5195 | ap->txconfig |= ANEG_CFG_ACK; |
| 5196 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 5197 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 5198 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5199 | udelay(40); |
| 5200 | |
| 5201 | ap->state = ANEG_STATE_ACK_DETECT; |
| 5202 | |
| 5203 | /* fallthru */ |
| 5204 | case ANEG_STATE_ACK_DETECT: |
| 5205 | if (ap->ack_match != 0) { |
| 5206 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == |
| 5207 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { |
| 5208 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; |
| 5209 | } else { |
| 5210 | ap->state = ANEG_STATE_AN_ENABLE; |
| 5211 | } |
| 5212 | } else if (ap->ability_match != 0 && |
| 5213 | ap->rxconfig == 0) { |
| 5214 | ap->state = ANEG_STATE_AN_ENABLE; |
| 5215 | } |
| 5216 | break; |
| 5217 | |
| 5218 | case ANEG_STATE_COMPLETE_ACK_INIT: |
| 5219 | if (ap->rxconfig & ANEG_CFG_INVAL) { |
| 5220 | ret = ANEG_FAILED; |
| 5221 | break; |
| 5222 | } |
| 5223 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | |
| 5224 | MR_LP_ADV_HALF_DUPLEX | |
| 5225 | MR_LP_ADV_SYM_PAUSE | |
| 5226 | MR_LP_ADV_ASYM_PAUSE | |
| 5227 | MR_LP_ADV_REMOTE_FAULT1 | |
| 5228 | MR_LP_ADV_REMOTE_FAULT2 | |
| 5229 | MR_LP_ADV_NEXT_PAGE | |
| 5230 | MR_TOGGLE_RX | |
| 5231 | MR_NP_RX); |
| 5232 | if (ap->rxconfig & ANEG_CFG_FD) |
| 5233 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; |
| 5234 | if (ap->rxconfig & ANEG_CFG_HD) |
| 5235 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; |
| 5236 | if (ap->rxconfig & ANEG_CFG_PS1) |
| 5237 | ap->flags |= MR_LP_ADV_SYM_PAUSE; |
| 5238 | if (ap->rxconfig & ANEG_CFG_PS2) |
| 5239 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; |
| 5240 | if (ap->rxconfig & ANEG_CFG_RF1) |
| 5241 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; |
| 5242 | if (ap->rxconfig & ANEG_CFG_RF2) |
| 5243 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; |
| 5244 | if (ap->rxconfig & ANEG_CFG_NP) |
| 5245 | ap->flags |= MR_LP_ADV_NEXT_PAGE; |
| 5246 | |
| 5247 | ap->link_time = ap->cur_time; |
| 5248 | |
| 5249 | ap->flags ^= (MR_TOGGLE_TX); |
| 5250 | if (ap->rxconfig & 0x0008) |
| 5251 | ap->flags |= MR_TOGGLE_RX; |
| 5252 | if (ap->rxconfig & ANEG_CFG_NP) |
| 5253 | ap->flags |= MR_NP_RX; |
| 5254 | ap->flags |= MR_PAGE_RX; |
| 5255 | |
| 5256 | ap->state = ANEG_STATE_COMPLETE_ACK; |
| 5257 | ret = ANEG_TIMER_ENAB; |
| 5258 | break; |
| 5259 | |
| 5260 | case ANEG_STATE_COMPLETE_ACK: |
| 5261 | if (ap->ability_match != 0 && |
| 5262 | ap->rxconfig == 0) { |
| 5263 | ap->state = ANEG_STATE_AN_ENABLE; |
| 5264 | break; |
| 5265 | } |
| 5266 | delta = ap->cur_time - ap->link_time; |
| 5267 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 5268 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { |
| 5269 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 5270 | } else { |
| 5271 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && |
| 5272 | !(ap->flags & MR_NP_RX)) { |
| 5273 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 5274 | } else { |
| 5275 | ret = ANEG_FAILED; |
| 5276 | } |
| 5277 | } |
| 5278 | } |
| 5279 | break; |
| 5280 | |
| 5281 | case ANEG_STATE_IDLE_DETECT_INIT: |
| 5282 | ap->link_time = ap->cur_time; |
| 5283 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 5284 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5285 | udelay(40); |
| 5286 | |
| 5287 | ap->state = ANEG_STATE_IDLE_DETECT; |
| 5288 | ret = ANEG_TIMER_ENAB; |
| 5289 | break; |
| 5290 | |
| 5291 | case ANEG_STATE_IDLE_DETECT: |
| 5292 | if (ap->ability_match != 0 && |
| 5293 | ap->rxconfig == 0) { |
| 5294 | ap->state = ANEG_STATE_AN_ENABLE; |
| 5295 | break; |
| 5296 | } |
| 5297 | delta = ap->cur_time - ap->link_time; |
| 5298 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 5299 | /* XXX another gem from the Broadcom driver :( */ |
| 5300 | ap->state = ANEG_STATE_LINK_OK; |
| 5301 | } |
| 5302 | break; |
| 5303 | |
| 5304 | case ANEG_STATE_LINK_OK: |
| 5305 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); |
| 5306 | ret = ANEG_DONE; |
| 5307 | break; |
| 5308 | |
| 5309 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: |
| 5310 | /* ??? unimplemented */ |
| 5311 | break; |
| 5312 | |
| 5313 | case ANEG_STATE_NEXT_PAGE_WAIT: |
| 5314 | /* ??? unimplemented */ |
| 5315 | break; |
| 5316 | |
| 5317 | default: |
| 5318 | ret = ANEG_FAILED; |
| 5319 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 5320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | |
| 5322 | return ret; |
| 5323 | } |
| 5324 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5325 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | { |
| 5327 | int res = 0; |
| 5328 | struct tg3_fiber_aneginfo aninfo; |
| 5329 | int status = ANEG_FAILED; |
| 5330 | unsigned int tick; |
| 5331 | u32 tmp; |
| 5332 | |
| 5333 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 5334 | |
| 5335 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
| 5336 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); |
| 5337 | udelay(40); |
| 5338 | |
| 5339 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); |
| 5340 | udelay(40); |
| 5341 | |
| 5342 | memset(&aninfo, 0, sizeof(aninfo)); |
| 5343 | aninfo.flags |= MR_AN_ENABLE; |
| 5344 | aninfo.state = ANEG_STATE_UNKNOWN; |
| 5345 | aninfo.cur_time = 0; |
| 5346 | tick = 0; |
| 5347 | while (++tick < 195000) { |
| 5348 | status = tg3_fiber_aneg_smachine(tp, &aninfo); |
| 5349 | if (status == ANEG_DONE || status == ANEG_FAILED) |
| 5350 | break; |
| 5351 | |
| 5352 | udelay(1); |
| 5353 | } |
| 5354 | |
| 5355 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 5356 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5357 | udelay(40); |
| 5358 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5359 | *txflags = aninfo.txconfig; |
| 5360 | *rxflags = aninfo.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | |
| 5362 | if (status == ANEG_DONE && |
| 5363 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | |
| 5364 | MR_LP_ADV_FULL_DUPLEX))) |
| 5365 | res = 1; |
| 5366 | |
| 5367 | return res; |
| 5368 | } |
| 5369 | |
| 5370 | static void tg3_init_bcm8002(struct tg3 *tp) |
| 5371 | { |
| 5372 | u32 mac_status = tr32(MAC_STATUS); |
| 5373 | int i; |
| 5374 | |
| 5375 | /* Reset when initting first time or we have a link. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5376 | if (tg3_flag(tp, INIT_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5377 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 5378 | return; |
| 5379 | |
| 5380 | /* Set PLL lock range. */ |
| 5381 | tg3_writephy(tp, 0x16, 0x8007); |
| 5382 | |
| 5383 | /* SW reset */ |
| 5384 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); |
| 5385 | |
| 5386 | /* Wait for reset to complete. */ |
| 5387 | /* XXX schedule_timeout() ... */ |
| 5388 | for (i = 0; i < 500; i++) |
| 5389 | udelay(10); |
| 5390 | |
| 5391 | /* Config mode; select PMA/Ch 1 regs. */ |
| 5392 | tg3_writephy(tp, 0x10, 0x8411); |
| 5393 | |
| 5394 | /* Enable auto-lock and comdet, select txclk for tx. */ |
| 5395 | tg3_writephy(tp, 0x11, 0x0a10); |
| 5396 | |
| 5397 | tg3_writephy(tp, 0x18, 0x00a0); |
| 5398 | tg3_writephy(tp, 0x16, 0x41ff); |
| 5399 | |
| 5400 | /* Assert and deassert POR. */ |
| 5401 | tg3_writephy(tp, 0x13, 0x0400); |
| 5402 | udelay(40); |
| 5403 | tg3_writephy(tp, 0x13, 0x0000); |
| 5404 | |
| 5405 | tg3_writephy(tp, 0x11, 0x0a50); |
| 5406 | udelay(40); |
| 5407 | tg3_writephy(tp, 0x11, 0x0a10); |
| 5408 | |
| 5409 | /* Wait for signal to stabilize */ |
| 5410 | /* XXX schedule_timeout() ... */ |
| 5411 | for (i = 0; i < 15000; i++) |
| 5412 | udelay(10); |
| 5413 | |
| 5414 | /* Deselect the channel register so we can read the PHYID |
| 5415 | * later. |
| 5416 | */ |
| 5417 | tg3_writephy(tp, 0x10, 0x8011); |
| 5418 | } |
| 5419 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5420 | static bool tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5421 | { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5422 | u16 flowctrl; |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5423 | bool current_link_up; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5424 | u32 sg_dig_ctrl, sg_dig_status; |
| 5425 | u32 serdes_cfg, expected_sg_dig_ctrl; |
| 5426 | int workaround, port_a; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | |
| 5428 | serdes_cfg = 0; |
| 5429 | expected_sg_dig_ctrl = 0; |
| 5430 | workaround = 0; |
| 5431 | port_a = 1; |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5432 | current_link_up = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5433 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 5434 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5704_A0 && |
| 5435 | tg3_chip_rev_id(tp) != CHIPREV_ID_5704_A1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5436 | workaround = 1; |
| 5437 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 5438 | port_a = 0; |
| 5439 | |
| 5440 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ |
| 5441 | /* preserve bits 20-23 for voltage regulator */ |
| 5442 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; |
| 5443 | } |
| 5444 | |
| 5445 | sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 5446 | |
| 5447 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5448 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5449 | if (workaround) { |
| 5450 | u32 val = serdes_cfg; |
| 5451 | |
| 5452 | if (port_a) |
| 5453 | val |= 0xc010000; |
| 5454 | else |
| 5455 | val |= 0x4010000; |
| 5456 | tw32_f(MAC_SERDES_CFG, val); |
| 5457 | } |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5458 | |
| 5459 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5460 | } |
| 5461 | if (mac_status & MAC_STATUS_PCS_SYNCED) { |
| 5462 | tg3_setup_flow_control(tp, 0, 0); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5463 | current_link_up = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 | } |
| 5465 | goto out; |
| 5466 | } |
| 5467 | |
| 5468 | /* Want auto-negotiation. */ |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5469 | 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] | 5470 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5471 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 5472 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 5473 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; |
| 5474 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 5475 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5476 | |
| 5477 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5478 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5479 | tp->serdes_counter && |
| 5480 | ((mac_status & (MAC_STATUS_PCS_SYNCED | |
| 5481 | MAC_STATUS_RCVD_CFG)) == |
| 5482 | MAC_STATUS_PCS_SYNCED)) { |
| 5483 | tp->serdes_counter--; |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5484 | current_link_up = true; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5485 | goto out; |
| 5486 | } |
| 5487 | restart_autoneg: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5488 | if (workaround) |
| 5489 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5490 | 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] | 5491 | udelay(5); |
| 5492 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); |
| 5493 | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5494 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5495 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5496 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
| 5497 | MAC_STATUS_SIGNAL_DET)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5498 | sg_dig_status = tr32(SG_DIG_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5499 | mac_status = tr32(MAC_STATUS); |
| 5500 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5501 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5502 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5503 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5504 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5505 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) |
| 5506 | local_adv |= ADVERTISE_1000XPAUSE; |
| 5507 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) |
| 5508 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 5509 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5510 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5511 | remote_adv |= LPA_1000XPAUSE; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5512 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 5513 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5515 | tp->link_config.rmt_adv = |
| 5516 | mii_adv_to_ethtool_adv_x(remote_adv); |
| 5517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5519 | current_link_up = true; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5520 | tp->serdes_counter = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5521 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5522 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5523 | if (tp->serdes_counter) |
| 5524 | tp->serdes_counter--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | else { |
| 5526 | if (workaround) { |
| 5527 | u32 val = serdes_cfg; |
| 5528 | |
| 5529 | if (port_a) |
| 5530 | val |= 0xc010000; |
| 5531 | else |
| 5532 | val |= 0x4010000; |
| 5533 | |
| 5534 | tw32_f(MAC_SERDES_CFG, val); |
| 5535 | } |
| 5536 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 5537 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | udelay(40); |
| 5539 | |
| 5540 | /* Link parallel detection - link is up */ |
| 5541 | /* only if we have PCS_SYNC and not */ |
| 5542 | /* receiving config code words */ |
| 5543 | mac_status = tr32(MAC_STATUS); |
| 5544 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && |
| 5545 | !(mac_status & MAC_STATUS_RCVD_CFG)) { |
| 5546 | tg3_setup_flow_control(tp, 0, 0); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5547 | current_link_up = true; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5548 | tp->phy_flags |= |
| 5549 | TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5550 | tp->serdes_counter = |
| 5551 | SERDES_PARALLEL_DET_TIMEOUT; |
| 5552 | } else |
| 5553 | goto restart_autoneg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5554 | } |
| 5555 | } |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5556 | } else { |
| 5557 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5558 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5559 | } |
| 5560 | |
| 5561 | out: |
| 5562 | return current_link_up; |
| 5563 | } |
| 5564 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5565 | static bool tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | { |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5567 | bool current_link_up = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5568 | |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 5569 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5570 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | |
| 5572 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5573 | u32 txflags, rxflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5574 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 5575 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5576 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
| 5577 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5579 | if (txflags & ANEG_CFG_PS1) |
| 5580 | local_adv |= ADVERTISE_1000XPAUSE; |
| 5581 | if (txflags & ANEG_CFG_PS2) |
| 5582 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 5583 | |
| 5584 | if (rxflags & MR_LP_ADV_SYM_PAUSE) |
| 5585 | remote_adv |= LPA_1000XPAUSE; |
| 5586 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) |
| 5587 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5588 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5589 | tp->link_config.rmt_adv = |
| 5590 | mii_adv_to_ethtool_adv_x(remote_adv); |
| 5591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5593 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5594 | current_link_up = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5595 | } |
| 5596 | for (i = 0; i < 30; i++) { |
| 5597 | udelay(20); |
| 5598 | tw32_f(MAC_STATUS, |
| 5599 | (MAC_STATUS_SYNC_CHANGED | |
| 5600 | MAC_STATUS_CFG_CHANGED)); |
| 5601 | udelay(40); |
| 5602 | if ((tr32(MAC_STATUS) & |
| 5603 | (MAC_STATUS_SYNC_CHANGED | |
| 5604 | MAC_STATUS_CFG_CHANGED)) == 0) |
| 5605 | break; |
| 5606 | } |
| 5607 | |
| 5608 | mac_status = tr32(MAC_STATUS); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5609 | if (!current_link_up && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | (mac_status & MAC_STATUS_PCS_SYNCED) && |
| 5611 | !(mac_status & MAC_STATUS_RCVD_CFG)) |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5612 | current_link_up = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5613 | } else { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 5614 | tg3_setup_flow_control(tp, 0, 0); |
| 5615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | /* Forcing 1000FD link up. */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5617 | current_link_up = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5618 | |
| 5619 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); |
| 5620 | udelay(40); |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 5621 | |
| 5622 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5623 | udelay(40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | out: |
| 5627 | return current_link_up; |
| 5628 | } |
| 5629 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5630 | static int tg3_setup_fiber_phy(struct tg3 *tp, bool force_reset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5631 | { |
| 5632 | u32 orig_pause_cfg; |
| 5633 | u16 orig_active_speed; |
| 5634 | u8 orig_active_duplex; |
| 5635 | u32 mac_status; |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5636 | bool current_link_up; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5637 | int i; |
| 5638 | |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 5639 | orig_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5640 | orig_active_speed = tp->link_config.active_speed; |
| 5641 | orig_active_duplex = tp->link_config.active_duplex; |
| 5642 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5643 | if (!tg3_flag(tp, HW_AUTONEG) && |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5644 | tp->link_up && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5645 | tg3_flag(tp, INIT_COMPLETE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5646 | mac_status = tr32(MAC_STATUS); |
| 5647 | mac_status &= (MAC_STATUS_PCS_SYNCED | |
| 5648 | MAC_STATUS_SIGNAL_DET | |
| 5649 | MAC_STATUS_CFG_CHANGED | |
| 5650 | MAC_STATUS_RCVD_CFG); |
| 5651 | if (mac_status == (MAC_STATUS_PCS_SYNCED | |
| 5652 | MAC_STATUS_SIGNAL_DET)) { |
| 5653 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5654 | MAC_STATUS_CFG_CHANGED)); |
| 5655 | return 0; |
| 5656 | } |
| 5657 | } |
| 5658 | |
| 5659 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 5660 | |
| 5661 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 5662 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 5663 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5664 | udelay(40); |
| 5665 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 5666 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | tg3_init_bcm8002(tp); |
| 5668 | |
| 5669 | /* Enable link change event even when serdes polling. */ |
| 5670 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5671 | udelay(40); |
| 5672 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5673 | current_link_up = false; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5674 | tp->link_config.rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5675 | mac_status = tr32(MAC_STATUS); |
| 5676 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5677 | if (tg3_flag(tp, HW_AUTONEG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5678 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
| 5679 | else |
| 5680 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); |
| 5681 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5682 | tp->napi[0].hw_status->status = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5683 | (SD_STATUS_UPDATED | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5684 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | |
| 5686 | for (i = 0; i < 100; i++) { |
| 5687 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5688 | MAC_STATUS_CFG_CHANGED)); |
| 5689 | udelay(5); |
| 5690 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5691 | MAC_STATUS_CFG_CHANGED | |
| 5692 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5693 | break; |
| 5694 | } |
| 5695 | |
| 5696 | mac_status = tr32(MAC_STATUS); |
| 5697 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5698 | current_link_up = false; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5699 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 5700 | tp->serdes_counter == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5701 | tw32_f(MAC_MODE, (tp->mac_mode | |
| 5702 | MAC_MODE_SEND_CONFIGS)); |
| 5703 | udelay(1); |
| 5704 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5705 | } |
| 5706 | } |
| 5707 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5708 | if (current_link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5709 | tp->link_config.active_speed = SPEED_1000; |
| 5710 | tp->link_config.active_duplex = DUPLEX_FULL; |
| 5711 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5712 | LED_CTRL_LNKLED_OVERRIDE | |
| 5713 | LED_CTRL_1000MBPS_ON)); |
| 5714 | } else { |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 5715 | tp->link_config.active_speed = SPEED_UNKNOWN; |
| 5716 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5718 | LED_CTRL_LNKLED_OVERRIDE | |
| 5719 | LED_CTRL_TRAFFIC_OVERRIDE)); |
| 5720 | } |
| 5721 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5722 | if (!tg3_test_and_report_link_chg(tp, current_link_up)) { |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 5723 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5724 | if (orig_pause_cfg != now_pause_cfg || |
| 5725 | orig_active_speed != tp->link_config.active_speed || |
| 5726 | orig_active_duplex != tp->link_config.active_duplex) |
| 5727 | tg3_link_report(tp); |
| 5728 | } |
| 5729 | |
| 5730 | return 0; |
| 5731 | } |
| 5732 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5733 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, bool force_reset) |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5734 | { |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5735 | int err = 0; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5736 | u32 bmsr, bmcr; |
Michael Chan | 85730a6 | 2013-04-09 08:48:06 +0000 | [diff] [blame] | 5737 | u16 current_speed = SPEED_UNKNOWN; |
| 5738 | u8 current_duplex = DUPLEX_UNKNOWN; |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5739 | bool current_link_up = false; |
Michael Chan | 85730a6 | 2013-04-09 08:48:06 +0000 | [diff] [blame] | 5740 | u32 local_adv, remote_adv, sgsr; |
| 5741 | |
| 5742 | if ((tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 5743 | tg3_asic_rev(tp) == ASIC_REV_5720) && |
| 5744 | !tg3_readphy(tp, SERDES_TG3_1000X_STATUS, &sgsr) && |
| 5745 | (sgsr & SERDES_TG3_SGMII_MODE)) { |
| 5746 | |
| 5747 | if (force_reset) |
| 5748 | tg3_phy_reset(tp); |
| 5749 | |
| 5750 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 5751 | |
| 5752 | if (!(sgsr & SERDES_TG3_LINK_UP)) { |
| 5753 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 5754 | } else { |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5755 | current_link_up = true; |
Michael Chan | 85730a6 | 2013-04-09 08:48:06 +0000 | [diff] [blame] | 5756 | if (sgsr & SERDES_TG3_SPEED_1000) { |
| 5757 | current_speed = SPEED_1000; |
| 5758 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 5759 | } else if (sgsr & SERDES_TG3_SPEED_100) { |
| 5760 | current_speed = SPEED_100; |
| 5761 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 5762 | } else { |
| 5763 | current_speed = SPEED_10; |
| 5764 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 5765 | } |
| 5766 | |
| 5767 | if (sgsr & SERDES_TG3_FULL_DUPLEX) |
| 5768 | current_duplex = DUPLEX_FULL; |
| 5769 | else |
| 5770 | current_duplex = DUPLEX_HALF; |
| 5771 | } |
| 5772 | |
| 5773 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5774 | udelay(40); |
| 5775 | |
| 5776 | tg3_clear_mac_status(tp); |
| 5777 | |
| 5778 | goto fiber_setup_done; |
| 5779 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5780 | |
| 5781 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 5782 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5783 | udelay(40); |
| 5784 | |
Michael Chan | 3310e24 | 2013-04-09 08:48:05 +0000 | [diff] [blame] | 5785 | tg3_clear_mac_status(tp); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5786 | |
| 5787 | if (force_reset) |
| 5788 | tg3_phy_reset(tp); |
| 5789 | |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5790 | tp->link_config.rmt_adv = 0; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5791 | |
| 5792 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5793 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 5794 | if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 5795 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5796 | bmsr |= BMSR_LSTATUS; |
| 5797 | else |
| 5798 | bmsr &= ~BMSR_LSTATUS; |
| 5799 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5800 | |
| 5801 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5802 | |
| 5803 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5804 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5805 | /* do nothing, just check for link up at the end */ |
| 5806 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5807 | u32 adv, newadv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5808 | |
| 5809 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5810 | newadv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
| 5811 | ADVERTISE_1000XPAUSE | |
| 5812 | ADVERTISE_1000XPSE_ASYM | |
| 5813 | ADVERTISE_SLCT); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5814 | |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5815 | newadv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
Matt Carlson | 37f0702 | 2011-11-17 14:30:55 +0000 | [diff] [blame] | 5816 | newadv |= ethtool_adv_to_mii_adv_x(tp->link_config.advertising); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5817 | |
Matt Carlson | 28011cf | 2011-11-16 18:36:59 -0500 | [diff] [blame] | 5818 | if ((newadv != adv) || !(bmcr & BMCR_ANENABLE)) { |
| 5819 | tg3_writephy(tp, MII_ADVERTISE, newadv); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5820 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 5821 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 5822 | |
| 5823 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5824 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5825 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5826 | |
| 5827 | return err; |
| 5828 | } |
| 5829 | } else { |
| 5830 | u32 new_bmcr; |
| 5831 | |
| 5832 | bmcr &= ~BMCR_SPEED1000; |
| 5833 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); |
| 5834 | |
| 5835 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 5836 | new_bmcr |= BMCR_FULLDPLX; |
| 5837 | |
| 5838 | if (new_bmcr != bmcr) { |
| 5839 | /* BMCR_SPEED1000 is a reserved bit that needs |
| 5840 | * to be set on write. |
| 5841 | */ |
| 5842 | new_bmcr |= BMCR_SPEED1000; |
| 5843 | |
| 5844 | /* Force a linkdown */ |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5845 | if (tp->link_up) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5846 | u32 adv; |
| 5847 | |
| 5848 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 5849 | adv &= ~(ADVERTISE_1000XFULL | |
| 5850 | ADVERTISE_1000XHALF | |
| 5851 | ADVERTISE_SLCT); |
| 5852 | tg3_writephy(tp, MII_ADVERTISE, adv); |
| 5853 | tg3_writephy(tp, MII_BMCR, bmcr | |
| 5854 | BMCR_ANRESTART | |
| 5855 | BMCR_ANENABLE); |
| 5856 | udelay(10); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5857 | tg3_carrier_off(tp); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5858 | } |
| 5859 | tg3_writephy(tp, MII_BMCR, new_bmcr); |
| 5860 | bmcr = new_bmcr; |
| 5861 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5862 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 5863 | if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 5864 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5865 | bmsr |= BMSR_LSTATUS; |
| 5866 | else |
| 5867 | bmsr &= ~BMSR_LSTATUS; |
| 5868 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5869 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5870 | } |
| 5871 | } |
| 5872 | |
| 5873 | if (bmsr & BMSR_LSTATUS) { |
| 5874 | current_speed = SPEED_1000; |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5875 | current_link_up = true; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5876 | if (bmcr & BMCR_FULLDPLX) |
| 5877 | current_duplex = DUPLEX_FULL; |
| 5878 | else |
| 5879 | current_duplex = DUPLEX_HALF; |
| 5880 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5881 | local_adv = 0; |
| 5882 | remote_adv = 0; |
| 5883 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5884 | if (bmcr & BMCR_ANENABLE) { |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5885 | u32 common; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5886 | |
| 5887 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); |
| 5888 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); |
| 5889 | common = local_adv & remote_adv; |
| 5890 | if (common & (ADVERTISE_1000XHALF | |
| 5891 | ADVERTISE_1000XFULL)) { |
| 5892 | if (common & ADVERTISE_1000XFULL) |
| 5893 | current_duplex = DUPLEX_FULL; |
| 5894 | else |
| 5895 | current_duplex = DUPLEX_HALF; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 5896 | |
| 5897 | tp->link_config.rmt_adv = |
| 5898 | mii_adv_to_ethtool_adv_x(remote_adv); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 5899 | } else if (!tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 5900 | /* Link is up via parallel detect */ |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5901 | } else { |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5902 | current_link_up = false; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5903 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5904 | } |
| 5905 | } |
| 5906 | |
Michael Chan | 85730a6 | 2013-04-09 08:48:06 +0000 | [diff] [blame] | 5907 | fiber_setup_done: |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5908 | if (current_link_up && current_duplex == DUPLEX_FULL) |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 5909 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5910 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5911 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 5912 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 5913 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 5914 | |
| 5915 | tw32_f(MAC_MODE, tp->mac_mode); |
| 5916 | udelay(40); |
| 5917 | |
| 5918 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5919 | |
| 5920 | tp->link_config.active_speed = current_speed; |
| 5921 | tp->link_config.active_duplex = current_duplex; |
| 5922 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5923 | tg3_test_and_report_link_chg(tp, current_link_up); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5924 | return err; |
| 5925 | } |
| 5926 | |
| 5927 | static void tg3_serdes_parallel_detect(struct tg3 *tp) |
| 5928 | { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5929 | if (tp->serdes_counter) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5930 | /* Give autoneg time to complete. */ |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 5931 | tp->serdes_counter--; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5932 | return; |
| 5933 | } |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5934 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5935 | if (!tp->link_up && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5936 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { |
| 5937 | u32 bmcr; |
| 5938 | |
| 5939 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5940 | if (bmcr & BMCR_ANENABLE) { |
| 5941 | u32 phy1, phy2; |
| 5942 | |
| 5943 | /* Select shadow register 0x1f */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5944 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
| 5945 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5946 | |
| 5947 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5948 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 5949 | MII_TG3_DSP_EXP1_INT_STAT); |
| 5950 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 5951 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5952 | |
| 5953 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { |
| 5954 | /* We have signal detect and not receiving |
| 5955 | * config code words, link is up by parallel |
| 5956 | * detection. |
| 5957 | */ |
| 5958 | |
| 5959 | bmcr &= ~BMCR_ANENABLE; |
| 5960 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; |
| 5961 | tg3_writephy(tp, MII_BMCR, bmcr); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5962 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5963 | } |
| 5964 | } |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 5965 | } else if (tp->link_up && |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5966 | (tp->link_config.autoneg == AUTONEG_ENABLE) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5967 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5968 | u32 phy2; |
| 5969 | |
| 5970 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 5971 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 5972 | MII_TG3_DSP_EXP1_INT_STAT); |
| 5973 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5974 | if (phy2 & 0x20) { |
| 5975 | u32 bmcr; |
| 5976 | |
| 5977 | /* Config code words received, turn on autoneg. */ |
| 5978 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5979 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); |
| 5980 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5981 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5982 | |
| 5983 | } |
| 5984 | } |
| 5985 | } |
| 5986 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 5987 | static int tg3_setup_phy(struct tg3 *tp, bool force_reset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5988 | { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 5989 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5990 | int err; |
| 5991 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5992 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5993 | err = tg3_setup_fiber_phy(tp, force_reset); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 5994 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 5995 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5996 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5997 | err = tg3_setup_copper_phy(tp, force_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5998 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 5999 | if (tg3_chip_rev(tp) == CHIPREV_5784_AX) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 6000 | u32 scale; |
Matt Carlson | aa6c91f | 2007-11-12 21:18:04 -0800 | [diff] [blame] | 6001 | |
| 6002 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; |
| 6003 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) |
| 6004 | scale = 65; |
| 6005 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) |
| 6006 | scale = 6; |
| 6007 | else |
| 6008 | scale = 12; |
| 6009 | |
| 6010 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; |
| 6011 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 6012 | tw32(GRC_MISC_CFG, val); |
| 6013 | } |
| 6014 | |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 6015 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 6016 | (6 << TX_LENGTHS_IPG_SHIFT); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 6017 | if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 6018 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 6019 | val |= tr32(MAC_TX_LENGTHS) & |
| 6020 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 6021 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 6022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6023 | if (tp->link_config.active_speed == SPEED_1000 && |
| 6024 | tp->link_config.active_duplex == DUPLEX_HALF) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 6025 | tw32(MAC_TX_LENGTHS, val | |
| 6026 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6027 | else |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 6028 | tw32(MAC_TX_LENGTHS, val | |
| 6029 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6030 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6031 | if (!tg3_flag(tp, 5705_PLUS)) { |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 6032 | if (tp->link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6033 | tw32(HOSTCC_STAT_COAL_TICKS, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 6034 | tp->coal.stats_block_coalesce_usecs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6035 | } else { |
| 6036 | tw32(HOSTCC_STAT_COAL_TICKS, 0); |
| 6037 | } |
| 6038 | } |
| 6039 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6040 | if (tg3_flag(tp, ASPM_WORKAROUND)) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 6041 | val = tr32(PCIE_PWR_MGMT_THRESH); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 6042 | if (!tp->link_up) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 6043 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
| 6044 | tp->pwrmgmt_thresh; |
| 6045 | else |
| 6046 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 6047 | tw32(PCIE_PWR_MGMT_THRESH, val); |
| 6048 | } |
| 6049 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6050 | return err; |
| 6051 | } |
| 6052 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 6053 | /* tp->lock must be held */ |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 6054 | static u64 tg3_refclk_read(struct tg3 *tp) |
| 6055 | { |
| 6056 | u64 stamp = tr32(TG3_EAV_REF_CLCK_LSB); |
| 6057 | return stamp | (u64)tr32(TG3_EAV_REF_CLCK_MSB) << 32; |
| 6058 | } |
| 6059 | |
| 6060 | /* tp->lock must be held */ |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 6061 | static void tg3_refclk_write(struct tg3 *tp, u64 newval) |
| 6062 | { |
| 6063 | tw32(TG3_EAV_REF_CLCK_CTL, TG3_EAV_REF_CLCK_CTL_STOP); |
| 6064 | tw32(TG3_EAV_REF_CLCK_LSB, newval & 0xffffffff); |
| 6065 | tw32(TG3_EAV_REF_CLCK_MSB, newval >> 32); |
| 6066 | tw32_f(TG3_EAV_REF_CLCK_CTL, TG3_EAV_REF_CLCK_CTL_RESUME); |
| 6067 | } |
| 6068 | |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 6069 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync); |
| 6070 | static inline void tg3_full_unlock(struct tg3 *tp); |
| 6071 | static int tg3_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) |
| 6072 | { |
| 6073 | struct tg3 *tp = netdev_priv(dev); |
| 6074 | |
| 6075 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | |
| 6076 | SOF_TIMESTAMPING_RX_SOFTWARE | |
Flavio Leitner | f233a97 | 2013-04-29 07:08:07 +0000 | [diff] [blame] | 6077 | SOF_TIMESTAMPING_SOFTWARE; |
| 6078 | |
| 6079 | if (tg3_flag(tp, PTP_CAPABLE)) { |
Flavio Leitner | 32e1927 | 2013-04-30 07:20:34 +0000 | [diff] [blame] | 6080 | info->so_timestamping |= SOF_TIMESTAMPING_TX_HARDWARE | |
Flavio Leitner | f233a97 | 2013-04-29 07:08:07 +0000 | [diff] [blame] | 6081 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 6082 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 6083 | } |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 6084 | |
| 6085 | if (tp->ptp_clock) |
| 6086 | info->phc_index = ptp_clock_index(tp->ptp_clock); |
| 6087 | else |
| 6088 | info->phc_index = -1; |
| 6089 | |
| 6090 | info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); |
| 6091 | |
| 6092 | info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | |
| 6093 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) | |
| 6094 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | |
| 6095 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT); |
| 6096 | return 0; |
| 6097 | } |
| 6098 | |
| 6099 | static int tg3_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) |
| 6100 | { |
| 6101 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 6102 | bool neg_adj = false; |
| 6103 | u32 correction = 0; |
| 6104 | |
| 6105 | if (ppb < 0) { |
| 6106 | neg_adj = true; |
| 6107 | ppb = -ppb; |
| 6108 | } |
| 6109 | |
| 6110 | /* Frequency adjustment is performed using hardware with a 24 bit |
| 6111 | * accumulator and a programmable correction value. On each clk, the |
| 6112 | * correction value gets added to the accumulator and when it |
| 6113 | * overflows, the time counter is incremented/decremented. |
| 6114 | * |
| 6115 | * So conversion from ppb to correction value is |
| 6116 | * ppb * (1 << 24) / 1000000000 |
| 6117 | */ |
| 6118 | correction = div_u64((u64)ppb * (1 << 24), 1000000000ULL) & |
| 6119 | TG3_EAV_REF_CLK_CORRECT_MASK; |
| 6120 | |
| 6121 | tg3_full_lock(tp, 0); |
| 6122 | |
| 6123 | if (correction) |
| 6124 | tw32(TG3_EAV_REF_CLK_CORRECT_CTL, |
| 6125 | TG3_EAV_REF_CLK_CORRECT_EN | |
| 6126 | (neg_adj ? TG3_EAV_REF_CLK_CORRECT_NEG : 0) | correction); |
| 6127 | else |
| 6128 | tw32(TG3_EAV_REF_CLK_CORRECT_CTL, 0); |
| 6129 | |
| 6130 | tg3_full_unlock(tp); |
| 6131 | |
| 6132 | return 0; |
| 6133 | } |
| 6134 | |
| 6135 | static int tg3_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) |
| 6136 | { |
| 6137 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 6138 | |
| 6139 | tg3_full_lock(tp, 0); |
| 6140 | tp->ptp_adjust += delta; |
| 6141 | tg3_full_unlock(tp); |
| 6142 | |
| 6143 | return 0; |
| 6144 | } |
| 6145 | |
| 6146 | static int tg3_ptp_gettime(struct ptp_clock_info *ptp, struct timespec *ts) |
| 6147 | { |
| 6148 | u64 ns; |
| 6149 | u32 remainder; |
| 6150 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 6151 | |
| 6152 | tg3_full_lock(tp, 0); |
| 6153 | ns = tg3_refclk_read(tp); |
| 6154 | ns += tp->ptp_adjust; |
| 6155 | tg3_full_unlock(tp); |
| 6156 | |
| 6157 | ts->tv_sec = div_u64_rem(ns, 1000000000, &remainder); |
| 6158 | ts->tv_nsec = remainder; |
| 6159 | |
| 6160 | return 0; |
| 6161 | } |
| 6162 | |
| 6163 | static int tg3_ptp_settime(struct ptp_clock_info *ptp, |
| 6164 | const struct timespec *ts) |
| 6165 | { |
| 6166 | u64 ns; |
| 6167 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 6168 | |
| 6169 | ns = timespec_to_ns(ts); |
| 6170 | |
| 6171 | tg3_full_lock(tp, 0); |
| 6172 | tg3_refclk_write(tp, ns); |
| 6173 | tp->ptp_adjust = 0; |
| 6174 | tg3_full_unlock(tp); |
| 6175 | |
| 6176 | return 0; |
| 6177 | } |
| 6178 | |
| 6179 | static int tg3_ptp_enable(struct ptp_clock_info *ptp, |
| 6180 | struct ptp_clock_request *rq, int on) |
| 6181 | { |
| 6182 | return -EOPNOTSUPP; |
| 6183 | } |
| 6184 | |
| 6185 | static const struct ptp_clock_info tg3_ptp_caps = { |
| 6186 | .owner = THIS_MODULE, |
| 6187 | .name = "tg3 clock", |
| 6188 | .max_adj = 250000000, |
| 6189 | .n_alarm = 0, |
| 6190 | .n_ext_ts = 0, |
| 6191 | .n_per_out = 0, |
| 6192 | .pps = 0, |
| 6193 | .adjfreq = tg3_ptp_adjfreq, |
| 6194 | .adjtime = tg3_ptp_adjtime, |
| 6195 | .gettime = tg3_ptp_gettime, |
| 6196 | .settime = tg3_ptp_settime, |
| 6197 | .enable = tg3_ptp_enable, |
| 6198 | }; |
| 6199 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 6200 | static void tg3_hwclock_to_timestamp(struct tg3 *tp, u64 hwclock, |
| 6201 | struct skb_shared_hwtstamps *timestamp) |
| 6202 | { |
| 6203 | memset(timestamp, 0, sizeof(struct skb_shared_hwtstamps)); |
| 6204 | timestamp->hwtstamp = ns_to_ktime((hwclock & TG3_TSTAMP_MASK) + |
| 6205 | tp->ptp_adjust); |
| 6206 | } |
| 6207 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 6208 | /* tp->lock must be held */ |
| 6209 | static void tg3_ptp_init(struct tg3 *tp) |
| 6210 | { |
| 6211 | if (!tg3_flag(tp, PTP_CAPABLE)) |
| 6212 | return; |
| 6213 | |
| 6214 | /* Initialize the hardware clock to the system time. */ |
| 6215 | tg3_refclk_write(tp, ktime_to_ns(ktime_get_real())); |
| 6216 | tp->ptp_adjust = 0; |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 6217 | tp->ptp_info = tg3_ptp_caps; |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 6218 | } |
| 6219 | |
| 6220 | /* tp->lock must be held */ |
| 6221 | static void tg3_ptp_resume(struct tg3 *tp) |
| 6222 | { |
| 6223 | if (!tg3_flag(tp, PTP_CAPABLE)) |
| 6224 | return; |
| 6225 | |
| 6226 | tg3_refclk_write(tp, ktime_to_ns(ktime_get_real()) + tp->ptp_adjust); |
| 6227 | tp->ptp_adjust = 0; |
| 6228 | } |
| 6229 | |
| 6230 | static void tg3_ptp_fini(struct tg3 *tp) |
| 6231 | { |
| 6232 | if (!tg3_flag(tp, PTP_CAPABLE) || !tp->ptp_clock) |
| 6233 | return; |
| 6234 | |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 6235 | ptp_clock_unregister(tp->ptp_clock); |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 6236 | tp->ptp_clock = NULL; |
| 6237 | tp->ptp_adjust = 0; |
| 6238 | } |
| 6239 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 6240 | static inline int tg3_irq_sync(struct tg3 *tp) |
| 6241 | { |
| 6242 | return tp->irq_sync; |
| 6243 | } |
| 6244 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6245 | static inline void tg3_rd32_loop(struct tg3 *tp, u32 *dst, u32 off, u32 len) |
| 6246 | { |
| 6247 | int i; |
| 6248 | |
| 6249 | dst = (u32 *)((u8 *)dst + off); |
| 6250 | for (i = 0; i < len; i += sizeof(u32)) |
| 6251 | *dst++ = tr32(off + i); |
| 6252 | } |
| 6253 | |
| 6254 | static void tg3_dump_legacy_regs(struct tg3 *tp, u32 *regs) |
| 6255 | { |
| 6256 | tg3_rd32_loop(tp, regs, TG3PCI_VENDOR, 0xb0); |
| 6257 | tg3_rd32_loop(tp, regs, MAILBOX_INTERRUPT_0, 0x200); |
| 6258 | tg3_rd32_loop(tp, regs, MAC_MODE, 0x4f0); |
| 6259 | tg3_rd32_loop(tp, regs, SNDDATAI_MODE, 0xe0); |
| 6260 | tg3_rd32_loop(tp, regs, SNDDATAC_MODE, 0x04); |
| 6261 | tg3_rd32_loop(tp, regs, SNDBDS_MODE, 0x80); |
| 6262 | tg3_rd32_loop(tp, regs, SNDBDI_MODE, 0x48); |
| 6263 | tg3_rd32_loop(tp, regs, SNDBDC_MODE, 0x04); |
| 6264 | tg3_rd32_loop(tp, regs, RCVLPC_MODE, 0x20); |
| 6265 | tg3_rd32_loop(tp, regs, RCVLPC_SELLST_BASE, 0x15c); |
| 6266 | tg3_rd32_loop(tp, regs, RCVDBDI_MODE, 0x0c); |
| 6267 | tg3_rd32_loop(tp, regs, RCVDBDI_JUMBO_BD, 0x3c); |
| 6268 | tg3_rd32_loop(tp, regs, RCVDBDI_BD_PROD_IDX_0, 0x44); |
| 6269 | tg3_rd32_loop(tp, regs, RCVDCC_MODE, 0x04); |
| 6270 | tg3_rd32_loop(tp, regs, RCVBDI_MODE, 0x20); |
| 6271 | tg3_rd32_loop(tp, regs, RCVCC_MODE, 0x14); |
| 6272 | tg3_rd32_loop(tp, regs, RCVLSC_MODE, 0x08); |
| 6273 | tg3_rd32_loop(tp, regs, MBFREE_MODE, 0x08); |
| 6274 | tg3_rd32_loop(tp, regs, HOSTCC_MODE, 0x100); |
| 6275 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6276 | if (tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6277 | tg3_rd32_loop(tp, regs, HOSTCC_RXCOL_TICKS_VEC1, 0x180); |
| 6278 | |
| 6279 | tg3_rd32_loop(tp, regs, MEMARB_MODE, 0x10); |
| 6280 | tg3_rd32_loop(tp, regs, BUFMGR_MODE, 0x58); |
| 6281 | tg3_rd32_loop(tp, regs, RDMAC_MODE, 0x08); |
| 6282 | tg3_rd32_loop(tp, regs, WDMAC_MODE, 0x08); |
| 6283 | tg3_rd32_loop(tp, regs, RX_CPU_MODE, 0x04); |
| 6284 | tg3_rd32_loop(tp, regs, RX_CPU_STATE, 0x04); |
| 6285 | tg3_rd32_loop(tp, regs, RX_CPU_PGMCTR, 0x04); |
| 6286 | tg3_rd32_loop(tp, regs, RX_CPU_HWBKPT, 0x04); |
| 6287 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6288 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6289 | tg3_rd32_loop(tp, regs, TX_CPU_MODE, 0x04); |
| 6290 | tg3_rd32_loop(tp, regs, TX_CPU_STATE, 0x04); |
| 6291 | tg3_rd32_loop(tp, regs, TX_CPU_PGMCTR, 0x04); |
| 6292 | } |
| 6293 | |
| 6294 | tg3_rd32_loop(tp, regs, GRCMBOX_INTERRUPT_0, 0x110); |
| 6295 | tg3_rd32_loop(tp, regs, FTQ_RESET, 0x120); |
| 6296 | tg3_rd32_loop(tp, regs, MSGINT_MODE, 0x0c); |
| 6297 | tg3_rd32_loop(tp, regs, DMAC_MODE, 0x04); |
| 6298 | tg3_rd32_loop(tp, regs, GRC_MODE, 0x4c); |
| 6299 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6300 | if (tg3_flag(tp, NVRAM)) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6301 | tg3_rd32_loop(tp, regs, NVRAM_CMD, 0x24); |
| 6302 | } |
| 6303 | |
| 6304 | static void tg3_dump_state(struct tg3 *tp) |
| 6305 | { |
| 6306 | int i; |
| 6307 | u32 *regs; |
| 6308 | |
| 6309 | regs = kzalloc(TG3_REG_BLK_SIZE, GFP_ATOMIC); |
Joe Perches | b2adaca | 2013-02-03 17:43:58 +0000 | [diff] [blame] | 6310 | if (!regs) |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6311 | return; |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6312 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6313 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 6314 | /* Read up to but not including private PCI registers */ |
| 6315 | for (i = 0; i < TG3_PCIE_TLDLPL_PORT; i += sizeof(u32)) |
| 6316 | regs[i / sizeof(u32)] = tr32(i); |
| 6317 | } else |
| 6318 | tg3_dump_legacy_regs(tp, regs); |
| 6319 | |
| 6320 | for (i = 0; i < TG3_REG_BLK_SIZE / sizeof(u32); i += 4) { |
| 6321 | if (!regs[i + 0] && !regs[i + 1] && |
| 6322 | !regs[i + 2] && !regs[i + 3]) |
| 6323 | continue; |
| 6324 | |
| 6325 | netdev_err(tp->dev, "0x%08x: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", |
| 6326 | i * 4, |
| 6327 | regs[i + 0], regs[i + 1], regs[i + 2], regs[i + 3]); |
| 6328 | } |
| 6329 | |
| 6330 | kfree(regs); |
| 6331 | |
| 6332 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6333 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 6334 | |
| 6335 | /* SW status block */ |
| 6336 | netdev_err(tp->dev, |
| 6337 | "%d: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", |
| 6338 | i, |
| 6339 | tnapi->hw_status->status, |
| 6340 | tnapi->hw_status->status_tag, |
| 6341 | tnapi->hw_status->rx_jumbo_consumer, |
| 6342 | tnapi->hw_status->rx_consumer, |
| 6343 | tnapi->hw_status->rx_mini_consumer, |
| 6344 | tnapi->hw_status->idx[0].rx_producer, |
| 6345 | tnapi->hw_status->idx[0].tx_consumer); |
| 6346 | |
| 6347 | netdev_err(tp->dev, |
| 6348 | "%d: NAPI info [%08x:%08x:(%04x:%04x:%04x):%04x:(%04x:%04x:%04x:%04x)]\n", |
| 6349 | i, |
| 6350 | tnapi->last_tag, tnapi->last_irq_tag, |
| 6351 | tnapi->tx_prod, tnapi->tx_cons, tnapi->tx_pending, |
| 6352 | tnapi->rx_rcb_ptr, |
| 6353 | tnapi->prodring.rx_std_prod_idx, |
| 6354 | tnapi->prodring.rx_std_cons_idx, |
| 6355 | tnapi->prodring.rx_jmb_prod_idx, |
| 6356 | tnapi->prodring.rx_jmb_cons_idx); |
| 6357 | } |
| 6358 | } |
| 6359 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 6360 | /* This is called whenever we suspect that the system chipset is re- |
| 6361 | * ordering the sequence of MMIO to the tx send mailbox. The symptom |
| 6362 | * is bogus tx completions. We try to recover by setting the |
| 6363 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later |
| 6364 | * in the workqueue. |
| 6365 | */ |
| 6366 | static void tg3_tx_recover(struct tg3 *tp) |
| 6367 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6368 | BUG_ON(tg3_flag(tp, MBOX_WRITE_REORDER) || |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 6369 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
| 6370 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 6371 | netdev_warn(tp->dev, |
| 6372 | "The system may be re-ordering memory-mapped I/O " |
| 6373 | "cycles to the network device, attempting to recover. " |
| 6374 | "Please report the problem to the driver maintainer " |
| 6375 | "and include system chipset information.\n"); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 6376 | |
| 6377 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6378 | tg3_flag_set(tp, TX_RECOVERY_PENDING); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 6379 | spin_unlock(&tp->lock); |
| 6380 | } |
| 6381 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6382 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 6383 | { |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 6384 | /* Tell compiler to fetch tx indices from memory. */ |
| 6385 | barrier(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6386 | return tnapi->tx_pending - |
| 6387 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 6388 | } |
| 6389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6390 | /* Tigon3 never reports partial packet sends. So we do not |
| 6391 | * need special logic to handle SKBs that have not had all |
| 6392 | * of their frags sent yet, like SunGEM does. |
| 6393 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6394 | static void tg3_tx(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6395 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6396 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6397 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6398 | u32 sw_idx = tnapi->tx_cons; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 6399 | struct netdev_queue *txq; |
| 6400 | int index = tnapi - tp->napi; |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 6401 | unsigned int pkts_compl = 0, bytes_compl = 0; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 6402 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6403 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 6404 | index--; |
| 6405 | |
| 6406 | txq = netdev_get_tx_queue(tp->dev, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6407 | |
| 6408 | while (sw_idx != hw_idx) { |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 6409 | struct tg3_tx_ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6410 | struct sk_buff *skb = ri->skb; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 6411 | int i, tx_bug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6412 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 6413 | if (unlikely(skb == NULL)) { |
| 6414 | tg3_tx_recover(tp); |
| 6415 | return; |
| 6416 | } |
| 6417 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 6418 | if (tnapi->tx_ring[sw_idx].len_flags & TXD_FLAG_HWTSTAMP) { |
| 6419 | struct skb_shared_hwtstamps timestamp; |
| 6420 | u64 hwclock = tr32(TG3_TX_TSTAMP_LSB); |
| 6421 | hwclock |= (u64)tr32(TG3_TX_TSTAMP_MSB) << 32; |
| 6422 | |
| 6423 | tg3_hwclock_to_timestamp(tp, hwclock, ×tamp); |
| 6424 | |
| 6425 | skb_tstamp_tx(skb, ×tamp); |
| 6426 | } |
| 6427 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6428 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6429 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6430 | skb_headlen(skb), |
| 6431 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6432 | |
| 6433 | ri->skb = NULL; |
| 6434 | |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 6435 | while (ri->fragmented) { |
| 6436 | ri->fragmented = false; |
| 6437 | sw_idx = NEXT_TX(sw_idx); |
| 6438 | ri = &tnapi->tx_buffers[sw_idx]; |
| 6439 | } |
| 6440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6441 | sw_idx = NEXT_TX(sw_idx); |
| 6442 | |
| 6443 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6444 | ri = &tnapi->tx_buffers[sw_idx]; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 6445 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
| 6446 | tx_bug = 1; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6447 | |
| 6448 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6449 | dma_unmap_addr(ri, mapping), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6450 | skb_frag_size(&skb_shinfo(skb)->frags[i]), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6451 | PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 6452 | |
| 6453 | while (ri->fragmented) { |
| 6454 | ri->fragmented = false; |
| 6455 | sw_idx = NEXT_TX(sw_idx); |
| 6456 | ri = &tnapi->tx_buffers[sw_idx]; |
| 6457 | } |
| 6458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6459 | sw_idx = NEXT_TX(sw_idx); |
| 6460 | } |
| 6461 | |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 6462 | pkts_compl++; |
| 6463 | bytes_compl += skb->len; |
| 6464 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6465 | dev_kfree_skb(skb); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 6466 | |
| 6467 | if (unlikely(tx_bug)) { |
| 6468 | tg3_tx_recover(tp); |
| 6469 | return; |
| 6470 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6471 | } |
| 6472 | |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 6473 | netdev_tx_completed_queue(txq, pkts_compl, bytes_compl); |
Tom Herbert | 298376d | 2011-11-28 16:33:30 +0000 | [diff] [blame] | 6474 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6475 | tnapi->tx_cons = sw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6476 | |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 6477 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
| 6478 | * before checking for netif_queue_stopped(). Without the |
| 6479 | * memory barrier, there is a small possibility that tg3_start_xmit() |
| 6480 | * will miss it and cause the queue to be stopped forever. |
| 6481 | */ |
| 6482 | smp_mb(); |
| 6483 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 6484 | if (unlikely(netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6485 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 6486 | __netif_tx_lock(txq, smp_processor_id()); |
| 6487 | if (netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6488 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 6489 | netif_tx_wake_queue(txq); |
| 6490 | __netif_tx_unlock(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 6491 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6492 | } |
| 6493 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6494 | static void tg3_frag_free(bool is_frag, void *data) |
| 6495 | { |
| 6496 | if (is_frag) |
| 6497 | put_page(virt_to_head_page(data)); |
| 6498 | else |
| 6499 | kfree(data); |
| 6500 | } |
| 6501 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6502 | 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] | 6503 | { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6504 | unsigned int skb_size = SKB_DATA_ALIGN(map_sz + TG3_RX_OFFSET(tp)) + |
| 6505 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 6506 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6507 | if (!ri->data) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6508 | return; |
| 6509 | |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6510 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6511 | map_sz, PCI_DMA_FROMDEVICE); |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 6512 | tg3_frag_free(skb_size <= PAGE_SIZE, ri->data); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6513 | ri->data = NULL; |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6514 | } |
| 6515 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6517 | /* Returns size of skb allocated or < 0 on error. |
| 6518 | * |
| 6519 | * We only need to fill in the address because the other members |
| 6520 | * of the RX descriptor are invariant, see tg3_init_rings. |
| 6521 | * |
| 6522 | * Note the purposeful assymetry of cpu vs. chip accesses. For |
| 6523 | * posting buffers we only dirty the first cache line of the RX |
| 6524 | * descriptor (containing the address). Whereas for the RX status |
| 6525 | * buffers the cpu only reads the last cacheline of the RX descriptor |
| 6526 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). |
| 6527 | */ |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6528 | 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] | 6529 | u32 opaque_key, u32 dest_idx_unmasked, |
| 6530 | unsigned int *frag_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6531 | { |
| 6532 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | f94e290 | 2010-10-14 10:37:42 +0000 | [diff] [blame] | 6533 | struct ring_info *map; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6534 | u8 *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6535 | dma_addr_t mapping; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6536 | int skb_size, data_size, dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6538 | switch (opaque_key) { |
| 6539 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6540 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6541 | desc = &tpr->rx_std[dest_idx]; |
| 6542 | map = &tpr->rx_std_buffers[dest_idx]; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6543 | data_size = tp->rx_pkt_map_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6544 | break; |
| 6545 | |
| 6546 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6547 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 6548 | desc = &tpr->rx_jmb[dest_idx].std; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6549 | map = &tpr->rx_jmb_buffers[dest_idx]; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6550 | data_size = TG3_RX_JMB_MAP_SZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6551 | break; |
| 6552 | |
| 6553 | default: |
| 6554 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6555 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6556 | |
| 6557 | /* Do not overwrite any of the map or rp information |
| 6558 | * until we are sure we can commit to a new buffer. |
| 6559 | * |
| 6560 | * Callers depend upon this behavior and assume that |
| 6561 | * we leave everything unchanged if we fail. |
| 6562 | */ |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6563 | skb_size = SKB_DATA_ALIGN(data_size + TG3_RX_OFFSET(tp)) + |
| 6564 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 6565 | if (skb_size <= PAGE_SIZE) { |
| 6566 | data = netdev_alloc_frag(skb_size); |
| 6567 | *frag_size = skb_size; |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6568 | } else { |
| 6569 | data = kmalloc(skb_size, GFP_ATOMIC); |
| 6570 | *frag_size = 0; |
| 6571 | } |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6572 | if (!data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6573 | return -ENOMEM; |
| 6574 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6575 | mapping = pci_map_single(tp->pdev, |
| 6576 | data + TG3_RX_OFFSET(tp), |
| 6577 | data_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6578 | PCI_DMA_FROMDEVICE); |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6579 | if (unlikely(pci_dma_mapping_error(tp->pdev, mapping))) { |
Eric Dumazet | a1e8b307 | 2012-05-18 21:33:39 +0000 | [diff] [blame] | 6580 | tg3_frag_free(skb_size <= PAGE_SIZE, data); |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 6581 | return -EIO; |
| 6582 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6583 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6584 | map->data = data; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6585 | dma_unmap_addr_set(map, mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6587 | desc->addr_hi = ((u64)mapping >> 32); |
| 6588 | desc->addr_lo = ((u64)mapping & 0xffffffff); |
| 6589 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6590 | return data_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6591 | } |
| 6592 | |
| 6593 | /* We only need to move over in the address because the other |
| 6594 | * members of the RX descriptor are invariant. See notes above |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6595 | * tg3_alloc_rx_data for full details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6596 | */ |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6597 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
| 6598 | struct tg3_rx_prodring_set *dpr, |
| 6599 | u32 opaque_key, int src_idx, |
| 6600 | u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6601 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6602 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6603 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
| 6604 | struct ring_info *src_map, *dest_map; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6605 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 6606 | int dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6607 | |
| 6608 | switch (opaque_key) { |
| 6609 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6610 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6611 | dest_desc = &dpr->rx_std[dest_idx]; |
| 6612 | dest_map = &dpr->rx_std_buffers[dest_idx]; |
| 6613 | src_desc = &spr->rx_std[src_idx]; |
| 6614 | src_map = &spr->rx_std_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6615 | break; |
| 6616 | |
| 6617 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6618 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6619 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
| 6620 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; |
| 6621 | src_desc = &spr->rx_jmb[src_idx].std; |
| 6622 | src_map = &spr->rx_jmb_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6623 | break; |
| 6624 | |
| 6625 | default: |
| 6626 | return; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6627 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6628 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6629 | dest_map->data = src_map->data; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6630 | dma_unmap_addr_set(dest_map, mapping, |
| 6631 | dma_unmap_addr(src_map, mapping)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6632 | dest_desc->addr_hi = src_desc->addr_hi; |
| 6633 | dest_desc->addr_lo = src_desc->addr_lo; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6634 | |
| 6635 | /* Ensure that the update to the skb happens after the physical |
| 6636 | * addresses have been transferred to the new BD location. |
| 6637 | */ |
| 6638 | smp_wmb(); |
| 6639 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6640 | src_map->data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6641 | } |
| 6642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6643 | /* The RX ring scheme is composed of multiple rings which post fresh |
| 6644 | * buffers to the chip, and one special ring the chip uses to report |
| 6645 | * status back to the host. |
| 6646 | * |
| 6647 | * The special ring reports the status of received packets to the |
| 6648 | * host. The chip does not write into the original descriptor the |
| 6649 | * RX buffer was obtained from. The chip simply takes the original |
| 6650 | * descriptor as provided by the host, updates the status and length |
| 6651 | * field, then writes this into the next status ring entry. |
| 6652 | * |
| 6653 | * Each ring the host uses to post buffers to the chip is described |
| 6654 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, |
| 6655 | * it is first placed into the on-chip ram. When the packet's length |
| 6656 | * is known, it walks down the TG3_BDINFO entries to select the ring. |
| 6657 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO |
| 6658 | * which is within the range of the new packet's length is chosen. |
| 6659 | * |
| 6660 | * The "separate ring for rx status" scheme may sound queer, but it makes |
| 6661 | * sense from a cache coherency perspective. If only the host writes |
| 6662 | * to the buffer post rings, and only the chip writes to the rx status |
| 6663 | * rings, then cache lines never move beyond shared-modified state. |
| 6664 | * If both the host and chip were to write into the same ring, cache line |
| 6665 | * eviction could occur since both entities want it in an exclusive state. |
| 6666 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6667 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6668 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 6669 | struct tg3 *tp = tnapi->tp; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 6670 | u32 work_mask, rx_std_posted = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 6671 | u32 std_prod_idx, jmb_prod_idx; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6672 | u32 sw_idx = tnapi->rx_rcb_ptr; |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 6673 | u16 hw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6674 | int received; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6675 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6676 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6677 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6678 | /* |
| 6679 | * We need to order the read of hw_idx and the read of |
| 6680 | * the opaque cookie. |
| 6681 | */ |
| 6682 | rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6683 | work_mask = 0; |
| 6684 | received = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 6685 | std_prod_idx = tpr->rx_std_prod_idx; |
| 6686 | jmb_prod_idx = tpr->rx_jmb_prod_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6687 | while (sw_idx != hw_idx && budget > 0) { |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 6688 | struct ring_info *ri; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6689 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6690 | unsigned int len; |
| 6691 | struct sk_buff *skb; |
| 6692 | dma_addr_t dma_addr; |
| 6693 | u32 opaque_key, desc_idx, *post_ptr; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6694 | u8 *data; |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 6695 | u64 tstamp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6696 | |
| 6697 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 6698 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 6699 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6700 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6701 | dma_addr = dma_unmap_addr(ri, mapping); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6702 | data = ri->data; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 6703 | post_ptr = &std_prod_idx; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 6704 | rx_std_posted++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6705 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6706 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6707 | dma_addr = dma_unmap_addr(ri, mapping); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6708 | data = ri->data; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 6709 | post_ptr = &jmb_prod_idx; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6710 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6711 | goto next_pkt_nopost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6712 | |
| 6713 | work_mask |= opaque_key; |
| 6714 | |
| 6715 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 6716 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { |
| 6717 | drop_it: |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6718 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6719 | desc_idx, *post_ptr); |
| 6720 | drop_it_no_recycle: |
| 6721 | /* Other statistics kept track of by card. */ |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 6722 | tp->rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6723 | goto next_pkt; |
| 6724 | } |
| 6725 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6726 | prefetch(data + TG3_RX_OFFSET(tp)); |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 6727 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
| 6728 | ETH_FCS_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6729 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 6730 | if ((desc->type_flags & RXD_FLAG_PTPSTAT_MASK) == |
| 6731 | RXD_FLAG_PTPSTAT_PTPV1 || |
| 6732 | (desc->type_flags & RXD_FLAG_PTPSTAT_MASK) == |
| 6733 | RXD_FLAG_PTPSTAT_PTPV2) { |
| 6734 | tstamp = tr32(TG3_RX_TSTAMP_LSB); |
| 6735 | tstamp |= (u64)tr32(TG3_RX_TSTAMP_MSB) << 32; |
| 6736 | } |
| 6737 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 6738 | if (len > TG3_RX_COPY_THRESH(tp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6739 | int skb_size; |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6740 | unsigned int frag_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6741 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6742 | skb_size = tg3_alloc_rx_data(tp, tpr, opaque_key, |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6743 | *post_ptr, &frag_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6744 | if (skb_size < 0) |
| 6745 | goto drop_it; |
| 6746 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6747 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6748 | PCI_DMA_FROMDEVICE); |
| 6749 | |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6750 | skb = build_skb(data, frag_size); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6751 | if (!skb) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 6752 | tg3_frag_free(frag_size != 0, data); |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6753 | goto drop_it_no_recycle; |
| 6754 | } |
| 6755 | skb_reserve(skb, TG3_RX_OFFSET(tp)); |
| 6756 | /* Ensure that the update to the data happens |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 6757 | * after the usage of the old DMA mapping. |
| 6758 | */ |
| 6759 | smp_wmb(); |
| 6760 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6761 | ri->data = NULL; |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 6762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6763 | } else { |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 6764 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6765 | desc_idx, *post_ptr); |
| 6766 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6767 | skb = netdev_alloc_skb(tp->dev, |
| 6768 | len + TG3_RAW_IP_ALIGN); |
| 6769 | if (skb == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6770 | goto drop_it_no_recycle; |
| 6771 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6772 | skb_reserve(skb, TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6773 | 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] | 6774 | memcpy(skb->data, |
| 6775 | data + TG3_RX_OFFSET(tp), |
| 6776 | len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6777 | 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] | 6778 | } |
| 6779 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6780 | skb_put(skb, len); |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 6781 | if (tstamp) |
| 6782 | tg3_hwclock_to_timestamp(tp, tstamp, |
| 6783 | skb_hwtstamps(skb)); |
| 6784 | |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 6785 | if ((tp->dev->features & NETIF_F_RXCSUM) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6786 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 6787 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 6788 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) |
| 6789 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6790 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6791 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6792 | |
| 6793 | skb->protocol = eth_type_trans(skb, tp->dev); |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 6794 | |
| 6795 | if (len > (tp->dev->mtu + ETH_HLEN) && |
| 6796 | skb->protocol != htons(ETH_P_8021Q)) { |
| 6797 | dev_kfree_skb(skb); |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 6798 | goto drop_it_no_recycle; |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 6799 | } |
| 6800 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 6801 | if (desc->type_flags & RXD_FLAG_VLAN && |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 6802 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 6803 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 6804 | desc->err_vlan & RXD_VLAN_MASK); |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 6805 | |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 6806 | napi_gro_receive(&tnapi->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6808 | received++; |
| 6809 | budget--; |
| 6810 | |
| 6811 | next_pkt: |
| 6812 | (*post_ptr)++; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 6813 | |
| 6814 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6815 | tpr->rx_std_prod_idx = std_prod_idx & |
| 6816 | tp->rx_std_ring_mask; |
Matt Carlson | 86cfe4f | 2010-01-12 10:11:37 +0000 | [diff] [blame] | 6817 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6818 | tpr->rx_std_prod_idx); |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 6819 | work_mask &= ~RXD_OPAQUE_RING_STD; |
| 6820 | rx_std_posted = 0; |
| 6821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6822 | next_pkt_nopost: |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 6823 | sw_idx++; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 6824 | sw_idx &= tp->rx_ret_ring_mask; |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 6825 | |
| 6826 | /* Refresh hw_idx to see if there is new work */ |
| 6827 | if (sw_idx == hw_idx) { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6828 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 6829 | rmb(); |
| 6830 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6831 | } |
| 6832 | |
| 6833 | /* ACK the status ring. */ |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6834 | tnapi->rx_rcb_ptr = sw_idx; |
| 6835 | tw32_rx_mbox(tnapi->consmbox, sw_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6836 | |
| 6837 | /* Refill RX ring(s). */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6838 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 6839 | /* Sync BD data before updating mailbox */ |
| 6840 | wmb(); |
| 6841 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6842 | if (work_mask & RXD_OPAQUE_RING_STD) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6843 | tpr->rx_std_prod_idx = std_prod_idx & |
| 6844 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6845 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6846 | tpr->rx_std_prod_idx); |
| 6847 | } |
| 6848 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6849 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
| 6850 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6851 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 6852 | tpr->rx_jmb_prod_idx); |
| 6853 | } |
| 6854 | mmiowb(); |
| 6855 | } else if (work_mask) { |
| 6856 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be |
| 6857 | * updated before the producer indices can be updated. |
| 6858 | */ |
| 6859 | smp_wmb(); |
| 6860 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6861 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
| 6862 | 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] | 6863 | |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6864 | if (tnapi != &tp->napi[1]) { |
| 6865 | tp->rx_refill = true; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6866 | napi_schedule(&tp->napi[1].napi); |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 6867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6869 | |
| 6870 | return received; |
| 6871 | } |
| 6872 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6873 | static void tg3_poll_link(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6874 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6875 | /* handle link change and other phy events */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6876 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6877 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
| 6878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6879 | if (sblk->status & SD_STATUS_LINK_CHG) { |
| 6880 | sblk->status = SD_STATUS_UPDATED | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6881 | (sblk->status & ~SD_STATUS_LINK_CHG); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6882 | spin_lock(&tp->lock); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 6883 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 6884 | tw32_f(MAC_STATUS, |
| 6885 | (MAC_STATUS_SYNC_CHANGED | |
| 6886 | MAC_STATUS_CFG_CHANGED | |
| 6887 | MAC_STATUS_MI_COMPLETION | |
| 6888 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 6889 | udelay(40); |
| 6890 | } else |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 6891 | tg3_setup_phy(tp, false); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6892 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6893 | } |
| 6894 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 6895 | } |
| 6896 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6897 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
| 6898 | struct tg3_rx_prodring_set *dpr, |
| 6899 | struct tg3_rx_prodring_set *spr) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6900 | { |
| 6901 | u32 si, di, cpycnt, src_prod_idx; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6902 | int i, err = 0; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6903 | |
| 6904 | while (1) { |
| 6905 | src_prod_idx = spr->rx_std_prod_idx; |
| 6906 | |
| 6907 | /* Make sure updates to the rx_std_buffers[] entries and the |
| 6908 | * standard producer index are seen in the correct order. |
| 6909 | */ |
| 6910 | smp_rmb(); |
| 6911 | |
| 6912 | if (spr->rx_std_cons_idx == src_prod_idx) |
| 6913 | break; |
| 6914 | |
| 6915 | if (spr->rx_std_cons_idx < src_prod_idx) |
| 6916 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; |
| 6917 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6918 | cpycnt = tp->rx_std_ring_mask + 1 - |
| 6919 | spr->rx_std_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6920 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6921 | cpycnt = min(cpycnt, |
| 6922 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6923 | |
| 6924 | si = spr->rx_std_cons_idx; |
| 6925 | di = dpr->rx_std_prod_idx; |
| 6926 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6927 | for (i = di; i < di + cpycnt; i++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6928 | if (dpr->rx_std_buffers[i].data) { |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6929 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6930 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6931 | break; |
| 6932 | } |
| 6933 | } |
| 6934 | |
| 6935 | if (!cpycnt) |
| 6936 | break; |
| 6937 | |
| 6938 | /* Ensure that updates to the rx_std_buffers ring and the |
| 6939 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 6940 | * ordered correctly WRT the skb check above. |
| 6941 | */ |
| 6942 | smp_rmb(); |
| 6943 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6944 | memcpy(&dpr->rx_std_buffers[di], |
| 6945 | &spr->rx_std_buffers[si], |
| 6946 | cpycnt * sizeof(struct ring_info)); |
| 6947 | |
| 6948 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 6949 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 6950 | sbd = &spr->rx_std[si]; |
| 6951 | dbd = &dpr->rx_std[di]; |
| 6952 | dbd->addr_hi = sbd->addr_hi; |
| 6953 | dbd->addr_lo = sbd->addr_lo; |
| 6954 | } |
| 6955 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6956 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
| 6957 | tp->rx_std_ring_mask; |
| 6958 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & |
| 6959 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6960 | } |
| 6961 | |
| 6962 | while (1) { |
| 6963 | src_prod_idx = spr->rx_jmb_prod_idx; |
| 6964 | |
| 6965 | /* Make sure updates to the rx_jmb_buffers[] entries and |
| 6966 | * the jumbo producer index are seen in the correct order. |
| 6967 | */ |
| 6968 | smp_rmb(); |
| 6969 | |
| 6970 | if (spr->rx_jmb_cons_idx == src_prod_idx) |
| 6971 | break; |
| 6972 | |
| 6973 | if (spr->rx_jmb_cons_idx < src_prod_idx) |
| 6974 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; |
| 6975 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6976 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
| 6977 | spr->rx_jmb_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6978 | |
| 6979 | cpycnt = min(cpycnt, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6980 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6981 | |
| 6982 | si = spr->rx_jmb_cons_idx; |
| 6983 | di = dpr->rx_jmb_prod_idx; |
| 6984 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6985 | for (i = di; i < di + cpycnt; i++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 6986 | if (dpr->rx_jmb_buffers[i].data) { |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6987 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 6988 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 6989 | break; |
| 6990 | } |
| 6991 | } |
| 6992 | |
| 6993 | if (!cpycnt) |
| 6994 | break; |
| 6995 | |
| 6996 | /* Ensure that updates to the rx_jmb_buffers ring and the |
| 6997 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 6998 | * ordered correctly WRT the skb check above. |
| 6999 | */ |
| 7000 | smp_rmb(); |
| 7001 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7002 | memcpy(&dpr->rx_jmb_buffers[di], |
| 7003 | &spr->rx_jmb_buffers[si], |
| 7004 | cpycnt * sizeof(struct ring_info)); |
| 7005 | |
| 7006 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 7007 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 7008 | sbd = &spr->rx_jmb[si].std; |
| 7009 | dbd = &dpr->rx_jmb[di].std; |
| 7010 | dbd->addr_hi = sbd->addr_hi; |
| 7011 | dbd->addr_lo = sbd->addr_lo; |
| 7012 | } |
| 7013 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 7014 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
| 7015 | tp->rx_jmb_ring_mask; |
| 7016 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & |
| 7017 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7018 | } |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 7019 | |
| 7020 | return err; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7021 | } |
| 7022 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 7023 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
| 7024 | { |
| 7025 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7026 | |
| 7027 | /* run TX completion thread */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7028 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 7029 | tg3_tx(tnapi); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7030 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 7031 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7032 | } |
| 7033 | |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 7034 | if (!tnapi->rx_rcb_prod_idx) |
| 7035 | return work_done; |
| 7036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7037 | /* run RX thread, within the bounds set by NAPI. |
| 7038 | * All RX "locking" is done by ensuring outside |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7039 | * code synchronizes with tg3->napi.poll() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7040 | */ |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 7041 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 7042 | work_done += tg3_rx(tnapi, budget - work_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7043 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7044 | if (tg3_flag(tp, ENABLE_RSS) && tnapi == &tp->napi[1]) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7045 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 7046 | int i, err = 0; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7047 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
| 7048 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7049 | |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 7050 | tp->rx_refill = false; |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 7051 | for (i = 1; i <= tp->rxq_cnt; i++) |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 7052 | err |= tg3_rx_prodring_xfer(tp, dpr, |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7053 | &tp->napi[i].prodring); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7054 | |
| 7055 | wmb(); |
| 7056 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7057 | if (std_prod_idx != dpr->rx_std_prod_idx) |
| 7058 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 7059 | dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7060 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 7061 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
| 7062 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 7063 | dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7064 | |
| 7065 | mmiowb(); |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 7066 | |
| 7067 | if (err) |
| 7068 | tw32_f(HOSTCC_MODE, tp->coal_now); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 7069 | } |
| 7070 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 7071 | return work_done; |
| 7072 | } |
David S. Miller | f7383c2 | 2005-05-18 22:50:53 -0700 | [diff] [blame] | 7073 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 7074 | static inline void tg3_reset_task_schedule(struct tg3 *tp) |
| 7075 | { |
| 7076 | if (!test_and_set_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags)) |
| 7077 | schedule_work(&tp->reset_task); |
| 7078 | } |
| 7079 | |
| 7080 | static inline void tg3_reset_task_cancel(struct tg3 *tp) |
| 7081 | { |
| 7082 | cancel_work_sync(&tp->reset_task); |
| 7083 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
Matt Carlson | c710135 | 2012-02-22 12:35:20 +0000 | [diff] [blame] | 7084 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 7085 | } |
| 7086 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 7087 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
| 7088 | { |
| 7089 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 7090 | struct tg3 *tp = tnapi->tp; |
| 7091 | int work_done = 0; |
| 7092 | struct tg3_hw_status *sblk = tnapi->hw_status; |
| 7093 | |
| 7094 | while (1) { |
| 7095 | work_done = tg3_poll_work(tnapi, work_done, budget); |
| 7096 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7097 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 7098 | goto tx_recovery; |
| 7099 | |
| 7100 | if (unlikely(work_done >= budget)) |
| 7101 | break; |
| 7102 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 7103 | /* tp->last_tag is used in tg3_int_reenable() below |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 7104 | * to tell the hw how much work has been processed, |
| 7105 | * so we must read it before checking for more work. |
| 7106 | */ |
| 7107 | tnapi->last_tag = sblk->status_tag; |
| 7108 | tnapi->last_irq_tag = tnapi->last_tag; |
| 7109 | rmb(); |
| 7110 | |
| 7111 | /* check for RX/TX work to do */ |
Matt Carlson | 6d40db7 | 2010-04-05 10:19:20 +0000 | [diff] [blame] | 7112 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
| 7113 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 7114 | |
| 7115 | /* This test here is not race free, but will reduce |
| 7116 | * the number of interrupts by looping again. |
| 7117 | */ |
| 7118 | if (tnapi == &tp->napi[1] && tp->rx_refill) |
| 7119 | continue; |
| 7120 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 7121 | napi_complete(napi); |
| 7122 | /* Reenable interrupts. */ |
| 7123 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Michael Chan | 7ae5289 | 2012-03-21 15:38:33 +0000 | [diff] [blame] | 7124 | |
| 7125 | /* This test here is synchronized by napi_schedule() |
| 7126 | * and napi_complete() to close the race condition. |
| 7127 | */ |
| 7128 | if (unlikely(tnapi == &tp->napi[1] && tp->rx_refill)) { |
| 7129 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
| 7130 | HOSTCC_MODE_ENABLE | |
| 7131 | tnapi->coal_now); |
| 7132 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 7133 | mmiowb(); |
| 7134 | break; |
| 7135 | } |
| 7136 | } |
| 7137 | |
| 7138 | return work_done; |
| 7139 | |
| 7140 | tx_recovery: |
| 7141 | /* work_done is guaranteed to be less than budget. */ |
| 7142 | napi_complete(napi); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 7143 | tg3_reset_task_schedule(tp); |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 7144 | return work_done; |
| 7145 | } |
| 7146 | |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 7147 | static void tg3_process_error(struct tg3 *tp) |
| 7148 | { |
| 7149 | u32 val; |
| 7150 | bool real_error = false; |
| 7151 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7152 | if (tg3_flag(tp, ERROR_PROCESSED)) |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 7153 | return; |
| 7154 | |
| 7155 | /* Check Flow Attention register */ |
| 7156 | val = tr32(HOSTCC_FLOW_ATTN); |
| 7157 | if (val & ~HOSTCC_FLOW_ATTN_MBUF_LWM) { |
| 7158 | netdev_err(tp->dev, "FLOW Attention error. Resetting chip.\n"); |
| 7159 | real_error = true; |
| 7160 | } |
| 7161 | |
| 7162 | if (tr32(MSGINT_STATUS) & ~MSGINT_STATUS_MSI_REQ) { |
| 7163 | netdev_err(tp->dev, "MSI Status error. Resetting chip.\n"); |
| 7164 | real_error = true; |
| 7165 | } |
| 7166 | |
| 7167 | if (tr32(RDMAC_STATUS) || tr32(WDMAC_STATUS)) { |
| 7168 | netdev_err(tp->dev, "DMA Status error. Resetting chip.\n"); |
| 7169 | real_error = true; |
| 7170 | } |
| 7171 | |
| 7172 | if (!real_error) |
| 7173 | return; |
| 7174 | |
| 7175 | tg3_dump_state(tp); |
| 7176 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7177 | tg3_flag_set(tp, ERROR_PROCESSED); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 7178 | tg3_reset_task_schedule(tp); |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 7179 | } |
| 7180 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 7181 | static int tg3_poll(struct napi_struct *napi, int budget) |
| 7182 | { |
Matt Carlson | 8ef0442 | 2009-08-28 14:01:37 +0000 | [diff] [blame] | 7183 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 7184 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 7185 | int work_done = 0; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7186 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 7187 | |
| 7188 | while (1) { |
Matt Carlson | e64de4e | 2011-04-13 11:05:05 +0000 | [diff] [blame] | 7189 | if (sblk->status & SD_STATUS_ERROR) |
| 7190 | tg3_process_error(tp); |
| 7191 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 7192 | tg3_poll_link(tp); |
| 7193 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 7194 | work_done = tg3_poll_work(tnapi, work_done, budget); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 7195 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7196 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 7197 | goto tx_recovery; |
| 7198 | |
| 7199 | if (unlikely(work_done >= budget)) |
| 7200 | break; |
| 7201 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7202 | if (tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 7203 | /* tp->last_tag is used in tg3_int_reenable() below |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 7204 | * to tell the hw how much work has been processed, |
| 7205 | * so we must read it before checking for more work. |
| 7206 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7207 | tnapi->last_tag = sblk->status_tag; |
| 7208 | tnapi->last_irq_tag = tnapi->last_tag; |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 7209 | rmb(); |
| 7210 | } else |
| 7211 | sblk->status &= ~SD_STATUS_UPDATED; |
| 7212 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 7213 | if (likely(!tg3_has_work(tnapi))) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 7214 | napi_complete(napi); |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 7215 | tg3_int_reenable(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 7216 | break; |
| 7217 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7218 | } |
| 7219 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7220 | return work_done; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 7221 | |
| 7222 | tx_recovery: |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 7223 | /* work_done is guaranteed to be less than budget. */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 7224 | napi_complete(napi); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 7225 | tg3_reset_task_schedule(tp); |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 7226 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7227 | } |
| 7228 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 7229 | static void tg3_napi_disable(struct tg3 *tp) |
| 7230 | { |
| 7231 | int i; |
| 7232 | |
| 7233 | for (i = tp->irq_cnt - 1; i >= 0; i--) |
| 7234 | napi_disable(&tp->napi[i].napi); |
| 7235 | } |
| 7236 | |
| 7237 | static void tg3_napi_enable(struct tg3 *tp) |
| 7238 | { |
| 7239 | int i; |
| 7240 | |
| 7241 | for (i = 0; i < tp->irq_cnt; i++) |
| 7242 | napi_enable(&tp->napi[i].napi); |
| 7243 | } |
| 7244 | |
| 7245 | static void tg3_napi_init(struct tg3 *tp) |
| 7246 | { |
| 7247 | int i; |
| 7248 | |
| 7249 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); |
| 7250 | for (i = 1; i < tp->irq_cnt; i++) |
| 7251 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); |
| 7252 | } |
| 7253 | |
| 7254 | static void tg3_napi_fini(struct tg3 *tp) |
| 7255 | { |
| 7256 | int i; |
| 7257 | |
| 7258 | for (i = 0; i < tp->irq_cnt; i++) |
| 7259 | netif_napi_del(&tp->napi[i].napi); |
| 7260 | } |
| 7261 | |
| 7262 | static inline void tg3_netif_stop(struct tg3 *tp) |
| 7263 | { |
| 7264 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 7265 | tg3_napi_disable(tp); |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 7266 | netif_carrier_off(tp->dev); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 7267 | netif_tx_disable(tp->dev); |
| 7268 | } |
| 7269 | |
Nithin Nayak Sujir | 3576306 | 2012-12-03 19:36:56 +0000 | [diff] [blame] | 7270 | /* tp->lock must be held */ |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 7271 | static inline void tg3_netif_start(struct tg3 *tp) |
| 7272 | { |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 7273 | tg3_ptp_resume(tp); |
| 7274 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 7275 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
| 7276 | * appropriate so long as all callers are assured to |
| 7277 | * have free tx slots (such as after tg3_init_hw) |
| 7278 | */ |
| 7279 | netif_tx_wake_all_queues(tp->dev); |
| 7280 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 7281 | if (tp->link_up) |
| 7282 | netif_carrier_on(tp->dev); |
| 7283 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 7284 | tg3_napi_enable(tp); |
| 7285 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; |
| 7286 | tg3_enable_ints(tp); |
| 7287 | } |
| 7288 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7289 | static void tg3_irq_quiesce(struct tg3 *tp) |
| 7290 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7291 | int i; |
| 7292 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7293 | BUG_ON(tp->irq_sync); |
| 7294 | |
| 7295 | tp->irq_sync = 1; |
| 7296 | smp_mb(); |
| 7297 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7298 | for (i = 0; i < tp->irq_cnt; i++) |
| 7299 | synchronize_irq(tp->napi[i].irq_vec); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7300 | } |
| 7301 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7302 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
| 7303 | * If irq_sync is non-zero, then the IRQ handler must be synchronized |
| 7304 | * with as well. Most of the time, this is not necessary except when |
| 7305 | * shutting down the device. |
| 7306 | */ |
| 7307 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) |
| 7308 | { |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 7309 | spin_lock_bh(&tp->lock); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7310 | if (irq_sync) |
| 7311 | tg3_irq_quiesce(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7312 | } |
| 7313 | |
| 7314 | static inline void tg3_full_unlock(struct tg3 *tp) |
| 7315 | { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7316 | spin_unlock_bh(&tp->lock); |
| 7317 | } |
| 7318 | |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 7319 | /* One-shot MSI handler - Chip automatically disables interrupt |
| 7320 | * after sending MSI so driver doesn't have to do it. |
| 7321 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 7322 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 7323 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 7324 | struct tg3_napi *tnapi = dev_id; |
| 7325 | struct tg3 *tp = tnapi->tp; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 7326 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7327 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7328 | if (tnapi->rx_rcb) |
| 7329 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 7330 | |
| 7331 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 7332 | napi_schedule(&tnapi->napi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 7333 | |
| 7334 | return IRQ_HANDLED; |
| 7335 | } |
| 7336 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 7337 | /* MSI ISR - No need to check for interrupt sharing and no need to |
| 7338 | * flush status block and interrupt mailbox. PCI ordering rules |
| 7339 | * guarantee that MSI will arrive after the status block. |
| 7340 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 7341 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 7342 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 7343 | struct tg3_napi *tnapi = dev_id; |
| 7344 | struct tg3 *tp = tnapi->tp; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 7345 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7346 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 7347 | if (tnapi->rx_rcb) |
| 7348 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 7349 | /* |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 7350 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 7351 | * chip-internal interrupt pending events. |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 7352 | * Writing non-zero to intr-mbox-0 additional tells the |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 7353 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 7354 | * event coalescing. |
| 7355 | */ |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 7356 | tw32_mailbox(tnapi->int_mbox, 0x00000001); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 7357 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 7358 | napi_schedule(&tnapi->napi); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 7359 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 7360 | return IRQ_RETVAL(1); |
| 7361 | } |
| 7362 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 7363 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7364 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 7365 | struct tg3_napi *tnapi = dev_id; |
| 7366 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7367 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7368 | unsigned int handled = 1; |
| 7369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7370 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 7371 | * the CPU before the status block posted prior to the interrupt. |
| 7372 | * Reading the PCI State register will confirm whether the |
| 7373 | * interrupt is ours and will flush the status block. |
| 7374 | */ |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7375 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7376 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7377 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 7378 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7379 | goto out; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 7380 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7381 | } |
| 7382 | |
| 7383 | /* |
| 7384 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
| 7385 | * chip-internal interrupt pending events. |
| 7386 | * Writing non-zero to intr-mbox-0 additional tells the |
| 7387 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 7388 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 7389 | * |
| 7390 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 7391 | * spurious interrupts. The flush impacts performance but |
| 7392 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7393 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 7394 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7395 | if (tg3_irq_sync(tp)) |
| 7396 | goto out; |
| 7397 | sblk->status &= ~SD_STATUS_UPDATED; |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 7398 | if (likely(tg3_has_work(tnapi))) { |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 7399 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 7400 | napi_schedule(&tnapi->napi); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7401 | } else { |
| 7402 | /* No work, shared interrupt perhaps? re-enable |
| 7403 | * interrupts, and flush that PCI write |
| 7404 | */ |
| 7405 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, |
| 7406 | 0x00000000); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 7407 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7408 | out: |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 7409 | return IRQ_RETVAL(handled); |
| 7410 | } |
| 7411 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 7412 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 7413 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 7414 | struct tg3_napi *tnapi = dev_id; |
| 7415 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7416 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 7417 | unsigned int handled = 1; |
| 7418 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 7419 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 7420 | * the CPU before the status block posted prior to the interrupt. |
| 7421 | * Reading the PCI State register will confirm whether the |
| 7422 | * interrupt is ours and will flush the status block. |
| 7423 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7424 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7425 | if (tg3_flag(tp, CHIP_RESETTING) || |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7426 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 7427 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7428 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7429 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7430 | } |
| 7431 | |
| 7432 | /* |
| 7433 | * writing any value to intr-mbox-0 clears PCI INTA# and |
| 7434 | * chip-internal interrupt pending events. |
| 7435 | * writing non-zero to intr-mbox-0 additional tells the |
| 7436 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 7437 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 7438 | * |
| 7439 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 7440 | * spurious interrupts. The flush impacts performance but |
| 7441 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7442 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 7443 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 7444 | |
| 7445 | /* |
| 7446 | * In a shared interrupt configuration, sometimes other devices' |
| 7447 | * interrupts will scream. We record the current status tag here |
| 7448 | * so that the above check can report that the screaming interrupts |
| 7449 | * are unhandled. Eventually they will be silenced. |
| 7450 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7451 | tnapi->last_irq_tag = sblk->status_tag; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 7452 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7453 | if (tg3_irq_sync(tp)) |
| 7454 | goto out; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 7455 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 7456 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 7457 | |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 7458 | napi_schedule(&tnapi->napi); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 7459 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 7460 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7461 | return IRQ_RETVAL(handled); |
| 7462 | } |
| 7463 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 7464 | /* ISR for interrupt test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 7465 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 7466 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 7467 | struct tg3_napi *tnapi = dev_id; |
| 7468 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 7469 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 7470 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 7471 | if ((sblk->status & SD_STATUS_UPDATED) || |
| 7472 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 7473 | tg3_disable_ints(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 7474 | return IRQ_RETVAL(1); |
| 7475 | } |
| 7476 | return IRQ_RETVAL(0); |
| 7477 | } |
| 7478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7479 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7480 | static void tg3_poll_controller(struct net_device *dev) |
| 7481 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7482 | int i; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 7483 | struct tg3 *tp = netdev_priv(dev); |
| 7484 | |
Nithin Nayak Sujir | 9c13cb8 | 2013-01-14 17:10:59 +0000 | [diff] [blame] | 7485 | if (tg3_irq_sync(tp)) |
| 7486 | return; |
| 7487 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7488 | for (i = 0; i < tp->irq_cnt; i++) |
Louis Rilling | fe234f0 | 2010-03-09 06:14:41 +0000 | [diff] [blame] | 7489 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7490 | } |
| 7491 | #endif |
| 7492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7493 | static void tg3_tx_timeout(struct net_device *dev) |
| 7494 | { |
| 7495 | struct tg3 *tp = netdev_priv(dev); |
| 7496 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 7497 | if (netif_msg_tx_err(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7498 | netdev_err(dev, "transmit timed out, resetting\n"); |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 7499 | tg3_dump_state(tp); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 7500 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7501 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 7502 | tg3_reset_task_schedule(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7503 | } |
| 7504 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7505 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
| 7506 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) |
| 7507 | { |
| 7508 | u32 base = (u32) mapping & 0xffffffff; |
| 7509 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 7510 | return (base > 0xffffdcc0) && (base + len + 8 < base); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7511 | } |
| 7512 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 7513 | /* Test for DMA addresses > 40-bit */ |
| 7514 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 7515 | int len) |
| 7516 | { |
| 7517 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7518 | if (tg3_flag(tp, 40BIT_DMA_BUG)) |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 7519 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 7520 | return 0; |
| 7521 | #else |
| 7522 | return 0; |
| 7523 | #endif |
| 7524 | } |
| 7525 | |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7526 | 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] | 7527 | dma_addr_t mapping, u32 len, u32 flags, |
| 7528 | u32 mss, u32 vlan) |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 7529 | { |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7530 | txbd->addr_hi = ((u64) mapping >> 32); |
| 7531 | txbd->addr_lo = ((u64) mapping & 0xffffffff); |
| 7532 | txbd->len_flags = (len << TXD_LEN_SHIFT) | (flags & 0x0000ffff); |
| 7533 | txbd->vlan_tag = (mss << TXD_MSS_SHIFT) | (vlan << TXD_VLAN_TAG_SHIFT); |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 7534 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7535 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7536 | 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] | 7537 | dma_addr_t map, u32 len, u32 flags, |
| 7538 | u32 mss, u32 vlan) |
| 7539 | { |
| 7540 | struct tg3 *tp = tnapi->tp; |
| 7541 | bool hwbug = false; |
| 7542 | |
| 7543 | if (tg3_flag(tp, SHORT_DMA_BUG) && len <= 8) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 7544 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7545 | |
| 7546 | if (tg3_4g_overflow_test(map, len)) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 7547 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7548 | |
| 7549 | if (tg3_40bit_overflow_test(tp, map, len)) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 7550 | hwbug = true; |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7551 | |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 7552 | if (tp->dma_limit) { |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7553 | u32 prvidx = *entry; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7554 | u32 tmp_flag = flags & ~TXD_FLAG_END; |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 7555 | while (len > tp->dma_limit && *budget) { |
| 7556 | u32 frag_len = tp->dma_limit; |
| 7557 | len -= tp->dma_limit; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7558 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7559 | /* Avoid the 8byte DMA problem */ |
| 7560 | if (len <= 8) { |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 7561 | len += tp->dma_limit / 2; |
| 7562 | frag_len = tp->dma_limit / 2; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7563 | } |
| 7564 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7565 | tnapi->tx_buffers[*entry].fragmented = true; |
| 7566 | |
| 7567 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 7568 | frag_len, tmp_flag, mss, vlan); |
| 7569 | *budget -= 1; |
| 7570 | prvidx = *entry; |
| 7571 | *entry = NEXT_TX(*entry); |
| 7572 | |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7573 | map += frag_len; |
| 7574 | } |
| 7575 | |
| 7576 | if (len) { |
| 7577 | if (*budget) { |
| 7578 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 7579 | len, flags, mss, vlan); |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7580 | *budget -= 1; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7581 | *entry = NEXT_TX(*entry); |
| 7582 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 7583 | hwbug = true; |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7584 | tnapi->tx_buffers[prvidx].fragmented = false; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7585 | } |
| 7586 | } |
| 7587 | } else { |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7588 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 7589 | len, flags, mss, vlan); |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 7590 | *entry = NEXT_TX(*entry); |
| 7591 | } |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7592 | |
| 7593 | return hwbug; |
| 7594 | } |
| 7595 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7596 | 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] | 7597 | { |
| 7598 | int i; |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7599 | struct sk_buff *skb; |
Matt Carlson | df8944c | 2011-07-27 14:20:46 +0000 | [diff] [blame] | 7600 | struct tg3_tx_ring_info *txb = &tnapi->tx_buffers[entry]; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7601 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7602 | skb = txb->skb; |
| 7603 | txb->skb = NULL; |
| 7604 | |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7605 | pci_unmap_single(tnapi->tp->pdev, |
| 7606 | dma_unmap_addr(txb, mapping), |
| 7607 | skb_headlen(skb), |
| 7608 | PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 7609 | |
| 7610 | while (txb->fragmented) { |
| 7611 | txb->fragmented = false; |
| 7612 | entry = NEXT_TX(entry); |
| 7613 | txb = &tnapi->tx_buffers[entry]; |
| 7614 | } |
| 7615 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7616 | for (i = 0; i <= last; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7617 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7618 | |
| 7619 | entry = NEXT_TX(entry); |
| 7620 | txb = &tnapi->tx_buffers[entry]; |
| 7621 | |
| 7622 | pci_unmap_page(tnapi->tp->pdev, |
| 7623 | dma_unmap_addr(txb, mapping), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7624 | skb_frag_size(frag), PCI_DMA_TODEVICE); |
Matt Carlson | e01ee14 | 2011-07-27 14:20:50 +0000 | [diff] [blame] | 7625 | |
| 7626 | while (txb->fragmented) { |
| 7627 | txb->fragmented = false; |
| 7628 | entry = NEXT_TX(entry); |
| 7629 | txb = &tnapi->tx_buffers[entry]; |
| 7630 | } |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7631 | } |
| 7632 | } |
| 7633 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 7634 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7635 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7636 | struct sk_buff **pskb, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7637 | u32 *entry, u32 *budget, |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7638 | u32 base_flags, u32 mss, u32 vlan) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7639 | { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7640 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7641 | struct sk_buff *new_skb, *skb = *pskb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7642 | dma_addr_t new_addr = 0; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7643 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7644 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 7645 | if (tg3_asic_rev(tp) != ASIC_REV_5701) |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 7646 | new_skb = skb_copy(skb, GFP_ATOMIC); |
| 7647 | else { |
| 7648 | int more_headroom = 4 - ((unsigned long)skb->data & 3); |
| 7649 | |
| 7650 | new_skb = skb_copy_expand(skb, |
| 7651 | skb_headroom(skb) + more_headroom, |
| 7652 | skb_tailroom(skb), GFP_ATOMIC); |
| 7653 | } |
| 7654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7655 | if (!new_skb) { |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7656 | ret = -1; |
| 7657 | } else { |
| 7658 | /* New SKB is guaranteed to be linear. */ |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7659 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
| 7660 | PCI_DMA_TODEVICE); |
| 7661 | /* Make sure the mapping succeeded */ |
| 7662 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7663 | dev_kfree_skb(new_skb); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7664 | ret = -1; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7665 | } else { |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7666 | u32 save_entry = *entry; |
| 7667 | |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7668 | base_flags |= TXD_FLAG_END; |
| 7669 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7670 | tnapi->tx_buffers[*entry].skb = new_skb; |
| 7671 | dma_unmap_addr_set(&tnapi->tx_buffers[*entry], |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7672 | mapping, new_addr); |
| 7673 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7674 | if (tg3_tx_frag_set(tnapi, entry, budget, new_addr, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7675 | new_skb->len, base_flags, |
| 7676 | mss, vlan)) { |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7677 | tg3_tx_skb_unmap(tnapi, save_entry, -1); |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7678 | dev_kfree_skb(new_skb); |
| 7679 | ret = -1; |
| 7680 | } |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7681 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7682 | } |
| 7683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7684 | dev_kfree_skb(skb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7685 | *pskb = new_skb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7686 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7687 | } |
| 7688 | |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 7689 | 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] | 7690 | |
| 7691 | /* Use GSO to workaround a rare TSO bug that may be triggered when the |
| 7692 | * TSO header is greater than 80 bytes. |
| 7693 | */ |
| 7694 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) |
| 7695 | { |
| 7696 | struct sk_buff *segs, *nskb; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7697 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7698 | |
| 7699 | /* Estimate the number of fragments in the worst case */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7700 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7701 | netif_stop_queue(tp->dev); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 7702 | |
| 7703 | /* netif_tx_stop_queue() must be done before checking |
| 7704 | * checking tx index in tg3_tx_avail() below, because in |
| 7705 | * tg3_tx(), we update tx index before checking for |
| 7706 | * netif_tx_queue_stopped(). |
| 7707 | */ |
| 7708 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7709 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 7710 | return NETDEV_TX_BUSY; |
| 7711 | |
| 7712 | netif_wake_queue(tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7713 | } |
| 7714 | |
| 7715 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame] | 7716 | if (IS_ERR(segs)) |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7717 | goto tg3_tso_bug_end; |
| 7718 | |
| 7719 | do { |
| 7720 | nskb = segs; |
| 7721 | segs = segs->next; |
| 7722 | nskb->next = NULL; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 7723 | tg3_start_xmit(nskb, tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7724 | } while (segs); |
| 7725 | |
| 7726 | tg3_tso_bug_end: |
| 7727 | dev_kfree_skb(skb); |
| 7728 | |
| 7729 | return NETDEV_TX_OK; |
| 7730 | } |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7731 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 7732 | /* 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] | 7733 | * support TG3_FLAG_HW_TSO_1 or firmware TSO only. |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 7734 | */ |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 7735 | 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] | 7736 | { |
| 7737 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7738 | u32 len, entry, base_flags, mss, vlan = 0; |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7739 | u32 budget; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7740 | int i = -1, would_hit_hwbug; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 7741 | dma_addr_t mapping; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7742 | struct tg3_napi *tnapi; |
| 7743 | struct netdev_queue *txq; |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7744 | unsigned int last; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7745 | |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7746 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 7747 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7748 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7749 | tnapi++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7750 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7751 | budget = tg3_tx_avail(tnapi); |
| 7752 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 7753 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7754 | * 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] | 7755 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 7756 | * no IRQ context deadlocks to worry about either. Rejoice! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7757 | */ |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7758 | if (unlikely(budget <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7759 | if (!netif_tx_queue_stopped(txq)) { |
| 7760 | netif_tx_stop_queue(txq); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 7761 | |
| 7762 | /* This is a hard error, log it. */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7763 | netdev_err(dev, |
| 7764 | "BUG! Tx Ring full when queue awake!\n"); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 7765 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7766 | return NETDEV_TX_BUSY; |
| 7767 | } |
| 7768 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7769 | entry = tnapi->tx_prod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7770 | base_flags = 0; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 7771 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7772 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7773 | |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 7774 | mss = skb_shinfo(skb)->gso_size; |
| 7775 | if (mss) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7776 | struct iphdr *iph; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7777 | u32 tcp_opt_len, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7778 | |
| 7779 | if (skb_header_cloned(skb) && |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7780 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 7781 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7782 | |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7783 | iph = ip_hdr(skb); |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 7784 | tcp_opt_len = tcp_optlen(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7785 | |
Eric Dumazet | a5a1195 | 2012-01-23 01:22:09 +0000 | [diff] [blame] | 7786 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb) - ETH_HLEN; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7787 | |
Eric Dumazet | a5a1195 | 2012-01-23 01:22:09 +0000 | [diff] [blame] | 7788 | if (!skb_is_gso_v6(skb)) { |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 7789 | iph->check = 0; |
| 7790 | iph->tot_len = htons(mss + hdr_len); |
| 7791 | } |
| 7792 | |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7793 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7794 | tg3_flag(tp, TSO_BUG)) |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 7795 | return tg3_tso_bug(tp, skb); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 7796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7797 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 7798 | TXD_FLAG_CPU_POST_DMA); |
| 7799 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7800 | if (tg3_flag(tp, HW_TSO_1) || |
| 7801 | tg3_flag(tp, HW_TSO_2) || |
| 7802 | tg3_flag(tp, HW_TSO_3)) { |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 7803 | tcp_hdr(skb)->check = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7804 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 7805 | } else |
| 7806 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 7807 | iph->daddr, 0, |
| 7808 | IPPROTO_TCP, |
| 7809 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7810 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7811 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 7812 | mss |= (hdr_len & 0xc) << 12; |
| 7813 | if (hdr_len & 0x10) |
| 7814 | base_flags |= 0x00000010; |
| 7815 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7816 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 7817 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7818 | else if (tg3_flag(tp, HW_TSO_1) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 7819 | tg3_asic_rev(tp) == ASIC_REV_5705) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7820 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7821 | int tsflags; |
| 7822 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7823 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7824 | mss |= (tsflags << 11); |
| 7825 | } |
| 7826 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7827 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7828 | int tsflags; |
| 7829 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 7830 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7831 | base_flags |= tsflags << 12; |
| 7832 | } |
| 7833 | } |
| 7834 | } |
Matt Carlson | bf933c8 | 2011-01-25 15:58:49 +0000 | [diff] [blame] | 7835 | |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 7836 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 7837 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
| 7838 | base_flags |= TXD_FLAG_JMB_PKT; |
| 7839 | |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7840 | if (vlan_tx_tag_present(skb)) { |
| 7841 | base_flags |= TXD_FLAG_VLAN; |
| 7842 | vlan = vlan_tx_tag_get(skb); |
| 7843 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7844 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 7845 | if ((unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) && |
| 7846 | tg3_flag(tp, TX_TSTAMP_EN)) { |
| 7847 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 7848 | base_flags |= TXD_FLAG_HWTSTAMP; |
| 7849 | } |
| 7850 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7851 | len = skb_headlen(skb); |
| 7852 | |
| 7853 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7854 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 7855 | goto drop; |
| 7856 | |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 7857 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7858 | tnapi->tx_buffers[entry].skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 7859 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7860 | |
| 7861 | would_hit_hwbug = 0; |
| 7862 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 7863 | if (tg3_flag(tp, 5701_DMA_BUG)) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 7864 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7865 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7866 | if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, len, base_flags | |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7867 | ((skb_shinfo(skb)->nr_frags == 0) ? TXD_FLAG_END : 0), |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7868 | mss, vlan)) { |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 7869 | would_hit_hwbug = 1; |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7870 | } else if (skb_shinfo(skb)->nr_frags > 0) { |
Matt Carlson | 92cd3a1 | 2011-07-27 14:20:47 +0000 | [diff] [blame] | 7871 | u32 tmp_mss = mss; |
| 7872 | |
| 7873 | if (!tg3_flag(tp, HW_TSO_1) && |
| 7874 | !tg3_flag(tp, HW_TSO_2) && |
| 7875 | !tg3_flag(tp, HW_TSO_3)) |
| 7876 | tmp_mss = 0; |
| 7877 | |
Matt Carlson | c5665a5 | 2012-02-13 10:20:12 +0000 | [diff] [blame] | 7878 | /* Now loop through additional data |
| 7879 | * fragments, and queue them. |
| 7880 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7881 | last = skb_shinfo(skb)->nr_frags - 1; |
| 7882 | for (i = 0; i <= last; i++) { |
| 7883 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 7884 | |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7885 | len = skb_frag_size(frag); |
Ian Campbell | dc234d0 | 2011-08-24 22:28:11 +0000 | [diff] [blame] | 7886 | mapping = skb_frag_dma_map(&tp->pdev->dev, frag, 0, |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 7887 | len, DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7888 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7889 | tnapi->tx_buffers[entry].skb = NULL; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 7890 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7891 | mapping); |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 7892 | if (dma_mapping_error(&tp->pdev->dev, mapping)) |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7893 | goto dma_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7894 | |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7895 | if (!budget || |
| 7896 | tg3_tx_frag_set(tnapi, &entry, &budget, mapping, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7897 | len, base_flags | |
| 7898 | ((i == last) ? TXD_FLAG_END : 0), |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7899 | tmp_mss, vlan)) { |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 7900 | would_hit_hwbug = 1; |
Matt Carlson | b9e4548 | 2011-11-04 09:14:59 +0000 | [diff] [blame] | 7901 | break; |
| 7902 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7903 | } |
| 7904 | } |
| 7905 | |
| 7906 | if (would_hit_hwbug) { |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 7907 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7908 | |
| 7909 | /* If the workaround fails due to memory/mapping |
| 7910 | * failure, silently drop this packet. |
| 7911 | */ |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7912 | entry = tnapi->tx_prod; |
| 7913 | budget = tg3_tx_avail(tnapi); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7914 | if (tigon3_dma_hwbug_workaround(tnapi, &skb, &entry, &budget, |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 7915 | base_flags, mss, vlan)) |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7916 | goto drop_nofree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7917 | } |
| 7918 | |
Richard Cochran | d515b45 | 2011-06-19 03:31:41 +0000 | [diff] [blame] | 7919 | skb_tx_timestamp(skb); |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 7920 | netdev_tx_sent_queue(txq, skb->len); |
Richard Cochran | d515b45 | 2011-06-19 03:31:41 +0000 | [diff] [blame] | 7921 | |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 7922 | /* Sync BD data before updating mailbox */ |
| 7923 | wmb(); |
| 7924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7925 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7926 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7927 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7928 | tnapi->tx_prod = entry; |
| 7929 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7930 | netif_tx_stop_queue(txq); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 7931 | |
| 7932 | /* netif_tx_stop_queue() must be done before checking |
| 7933 | * checking tx index in tg3_tx_avail() below, because in |
| 7934 | * tg3_tx(), we update tx index before checking for |
| 7935 | * netif_tx_queue_stopped(). |
| 7936 | */ |
| 7937 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 7938 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 7939 | netif_tx_wake_queue(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 7940 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7941 | |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 7942 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7943 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7944 | |
| 7945 | dma_error: |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 7946 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, --i); |
Matt Carlson | 432aa7e | 2011-05-19 12:12:45 +0000 | [diff] [blame] | 7947 | tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 7948 | drop: |
| 7949 | dev_kfree_skb(skb); |
| 7950 | drop_nofree: |
| 7951 | tp->tx_dropped++; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 7952 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7953 | } |
| 7954 | |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7955 | static void tg3_mac_loopback(struct tg3 *tp, bool enable) |
| 7956 | { |
| 7957 | if (enable) { |
| 7958 | tp->mac_mode &= ~(MAC_MODE_HALF_DUPLEX | |
| 7959 | MAC_MODE_PORT_MODE_MASK); |
| 7960 | |
| 7961 | tp->mac_mode |= MAC_MODE_PORT_INT_LPBACK; |
| 7962 | |
| 7963 | if (!tg3_flag(tp, 5705_PLUS)) |
| 7964 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
| 7965 | |
| 7966 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 7967 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 7968 | else |
| 7969 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7970 | } else { |
| 7971 | tp->mac_mode &= ~MAC_MODE_PORT_INT_LPBACK; |
| 7972 | |
| 7973 | if (tg3_flag(tp, 5705_PLUS) || |
| 7974 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 7975 | tg3_asic_rev(tp) == ASIC_REV_5700) |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 7976 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 7977 | } |
| 7978 | |
| 7979 | tw32(MAC_MODE, tp->mac_mode); |
| 7980 | udelay(40); |
| 7981 | } |
| 7982 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7983 | 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] | 7984 | { |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7985 | u32 val, bmcr, mac_mode, ptest = 0; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7986 | |
| 7987 | tg3_phy_toggle_apd(tp, false); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 7988 | tg3_phy_toggle_automdix(tp, false); |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7989 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 7990 | if (extlpbk && tg3_phy_set_extloopbk(tp)) |
| 7991 | return -EIO; |
| 7992 | |
| 7993 | bmcr = BMCR_FULLDPLX; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 7994 | switch (speed) { |
| 7995 | case SPEED_10: |
| 7996 | break; |
| 7997 | case SPEED_100: |
| 7998 | bmcr |= BMCR_SPEED100; |
| 7999 | break; |
| 8000 | case SPEED_1000: |
| 8001 | default: |
| 8002 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 8003 | speed = SPEED_100; |
| 8004 | bmcr |= BMCR_SPEED100; |
| 8005 | } else { |
| 8006 | speed = SPEED_1000; |
| 8007 | bmcr |= BMCR_SPEED1000; |
| 8008 | } |
| 8009 | } |
| 8010 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 8011 | if (extlpbk) { |
| 8012 | if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 8013 | tg3_readphy(tp, MII_CTRL1000, &val); |
| 8014 | val |= CTL1000_AS_MASTER | |
| 8015 | CTL1000_ENABLE_MASTER; |
| 8016 | tg3_writephy(tp, MII_CTRL1000, val); |
| 8017 | } else { |
| 8018 | ptest = MII_TG3_FET_PTEST_TRIM_SEL | |
| 8019 | MII_TG3_FET_PTEST_TRIM_2; |
| 8020 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest); |
| 8021 | } |
| 8022 | } else |
| 8023 | bmcr |= BMCR_LOOPBACK; |
| 8024 | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 8025 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 8026 | |
| 8027 | /* The write needs to be flushed for the FETs */ |
| 8028 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 8029 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 8030 | |
| 8031 | udelay(40); |
| 8032 | |
| 8033 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8034 | tg3_asic_rev(tp) == ASIC_REV_5785) { |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 8035 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 8036 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
| 8037 | MII_TG3_FET_PTEST_FRC_TX_LOCK); |
| 8038 | |
| 8039 | /* The write needs to be flushed for the AC131 */ |
| 8040 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); |
| 8041 | } |
| 8042 | |
| 8043 | /* Reset to prevent losing 1st rx packet intermittently */ |
| 8044 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
| 8045 | tg3_flag(tp, 5780_CLASS)) { |
| 8046 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 8047 | udelay(10); |
| 8048 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8049 | } |
| 8050 | |
| 8051 | mac_mode = tp->mac_mode & |
| 8052 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 8053 | if (speed == SPEED_1000) |
| 8054 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 8055 | else |
| 8056 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 8057 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8058 | if (tg3_asic_rev(tp) == ASIC_REV_5700) { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 8059 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
| 8060 | |
| 8061 | if (masked_phy_id == TG3_PHY_ID_BCM5401) |
| 8062 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 8063 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
| 8064 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 8065 | |
| 8066 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 8067 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 8068 | } |
| 8069 | |
| 8070 | tw32(MAC_MODE, mac_mode); |
| 8071 | udelay(40); |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 8072 | |
| 8073 | return 0; |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 8074 | } |
| 8075 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8076 | 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] | 8077 | { |
| 8078 | struct tg3 *tp = netdev_priv(dev); |
| 8079 | |
| 8080 | if (features & NETIF_F_LOOPBACK) { |
| 8081 | if (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK) |
| 8082 | return; |
| 8083 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 8084 | spin_lock_bh(&tp->lock); |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 8085 | tg3_mac_loopback(tp, true); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 8086 | netif_carrier_on(tp->dev); |
| 8087 | spin_unlock_bh(&tp->lock); |
| 8088 | netdev_info(dev, "Internal MAC loopback mode enabled.\n"); |
| 8089 | } else { |
| 8090 | if (!(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
| 8091 | return; |
| 8092 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 8093 | spin_lock_bh(&tp->lock); |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 8094 | tg3_mac_loopback(tp, false); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 8095 | /* Force link status check */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 8096 | tg3_setup_phy(tp, true); |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 8097 | spin_unlock_bh(&tp->lock); |
| 8098 | netdev_info(dev, "Internal MAC loopback mode disabled.\n"); |
| 8099 | } |
| 8100 | } |
| 8101 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8102 | static netdev_features_t tg3_fix_features(struct net_device *dev, |
| 8103 | netdev_features_t features) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 8104 | { |
| 8105 | struct tg3 *tp = netdev_priv(dev); |
| 8106 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8107 | if (dev->mtu > ETH_DATA_LEN && tg3_flag(tp, 5780_CLASS)) |
Michał Mirosław | dc66891 | 2011-04-07 03:35:07 +0000 | [diff] [blame] | 8108 | features &= ~NETIF_F_ALL_TSO; |
| 8109 | |
| 8110 | return features; |
| 8111 | } |
| 8112 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8113 | 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] | 8114 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 8115 | netdev_features_t changed = dev->features ^ features; |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 8116 | |
| 8117 | if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) |
| 8118 | tg3_set_loopback(dev, features); |
| 8119 | |
| 8120 | return 0; |
| 8121 | } |
| 8122 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8123 | static void tg3_rx_prodring_free(struct tg3 *tp, |
| 8124 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8125 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8126 | int i; |
| 8127 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 8128 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 8129 | 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] | 8130 | i = (i + 1) & tp->rx_std_ring_mask) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 8131 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 8132 | tp->rx_pkt_map_sz); |
| 8133 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8134 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 8135 | for (i = tpr->rx_jmb_cons_idx; |
| 8136 | i != tpr->rx_jmb_prod_idx; |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8137 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 8138 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 8139 | TG3_RX_JMB_MAP_SZ); |
| 8140 | } |
| 8141 | } |
| 8142 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 8143 | return; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 8144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8145 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8146 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 8147 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 8148 | tp->rx_pkt_map_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8149 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8150 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8151 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 8152 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 8153 | TG3_RX_JMB_MAP_SZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8154 | } |
| 8155 | } |
| 8156 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 8157 | /* Initialize rx rings for packet processing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8158 | * |
| 8159 | * The chip has been shut down and the driver detached from |
| 8160 | * the networking, so no interrupts or new tx packets will |
| 8161 | * end up in the driver. tp->{tx,}lock are held and thus |
| 8162 | * we may not sleep. |
| 8163 | */ |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8164 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
| 8165 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8166 | { |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 8167 | u32 i, rx_pkt_dma_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8168 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 8169 | tpr->rx_std_cons_idx = 0; |
| 8170 | tpr->rx_std_prod_idx = 0; |
| 8171 | tpr->rx_jmb_cons_idx = 0; |
| 8172 | tpr->rx_jmb_prod_idx = 0; |
| 8173 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 8174 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8175 | memset(&tpr->rx_std_buffers[0], 0, |
| 8176 | TG3_RX_STD_BUFF_RING_SIZE(tp)); |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 8177 | if (tpr->rx_jmb_buffers) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 8178 | memset(&tpr->rx_jmb_buffers[0], 0, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8179 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 8180 | goto done; |
| 8181 | } |
| 8182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8183 | /* Zero out all descriptors. */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8184 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8185 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 8186 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8187 | if (tg3_flag(tp, 5780_CLASS) && |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 8188 | tp->dev->mtu > ETH_DATA_LEN) |
| 8189 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; |
| 8190 | 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] | 8191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8192 | /* Initialize invariants of the rings, we only set this |
| 8193 | * stuff once. This works because the card does not |
| 8194 | * write into the rx buffer posting rings. |
| 8195 | */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8196 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8197 | struct tg3_rx_buffer_desc *rxd; |
| 8198 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8199 | rxd = &tpr->rx_std[i]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 8200 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8201 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
| 8202 | rxd->opaque = (RXD_OPAQUE_RING_STD | |
| 8203 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 8204 | } |
| 8205 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8206 | /* Now allocate fresh SKBs for each rx ring. */ |
| 8207 | for (i = 0; i < tp->rx_pending; i++) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 8208 | unsigned int frag_size; |
| 8209 | |
| 8210 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_STD, i, |
| 8211 | &frag_size) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 8212 | netdev_warn(tp->dev, |
| 8213 | "Using a smaller RX standard ring. Only " |
| 8214 | "%d out of %d buffers were allocated " |
| 8215 | "successfully\n", i, tp->rx_pending); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8216 | if (i == 0) |
| 8217 | goto initfail; |
| 8218 | tp->rx_pending = i; |
| 8219 | break; |
| 8220 | } |
| 8221 | } |
| 8222 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8223 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8224 | goto done; |
| 8225 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8226 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8227 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8228 | if (!tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 8229 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8230 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8231 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 8232 | struct tg3_rx_buffer_desc *rxd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8233 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 8234 | rxd = &tpr->rx_jmb[i].std; |
| 8235 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; |
| 8236 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | |
| 8237 | RXD_FLAG_JUMBO; |
| 8238 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | |
| 8239 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 8240 | } |
| 8241 | |
| 8242 | for (i = 0; i < tp->rx_jumbo_pending; i++) { |
Eric Dumazet | 8d4057a | 2012-04-27 00:34:49 +0000 | [diff] [blame] | 8243 | unsigned int frag_size; |
| 8244 | |
| 8245 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_JUMBO, i, |
| 8246 | &frag_size) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 8247 | netdev_warn(tp->dev, |
| 8248 | "Using a smaller RX jumbo ring. Only %d " |
| 8249 | "out of %d buffers were allocated " |
| 8250 | "successfully\n", i, tp->rx_jumbo_pending); |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 8251 | if (i == 0) |
| 8252 | goto initfail; |
| 8253 | tp->rx_jumbo_pending = i; |
| 8254 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8255 | } |
| 8256 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8257 | |
| 8258 | done: |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 8259 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8260 | |
| 8261 | initfail: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8262 | tg3_rx_prodring_free(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8263 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8264 | } |
| 8265 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8266 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
| 8267 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8268 | { |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8269 | kfree(tpr->rx_std_buffers); |
| 8270 | tpr->rx_std_buffers = NULL; |
| 8271 | kfree(tpr->rx_jmb_buffers); |
| 8272 | tpr->rx_jmb_buffers = NULL; |
| 8273 | if (tpr->rx_std) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8274 | dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
| 8275 | tpr->rx_std, tpr->rx_std_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8276 | tpr->rx_std = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8277 | } |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8278 | if (tpr->rx_jmb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8279 | dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
| 8280 | tpr->rx_jmb, tpr->rx_jmb_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8281 | tpr->rx_jmb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8282 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8283 | } |
| 8284 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8285 | static int tg3_rx_prodring_init(struct tg3 *tp, |
| 8286 | struct tg3_rx_prodring_set *tpr) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8287 | { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8288 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
| 8289 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8290 | if (!tpr->rx_std_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8291 | return -ENOMEM; |
| 8292 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8293 | tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
| 8294 | TG3_RX_STD_RING_BYTES(tp), |
| 8295 | &tpr->rx_std_mapping, |
| 8296 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8297 | if (!tpr->rx_std) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8298 | goto err_out; |
| 8299 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8300 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 8301 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8302 | GFP_KERNEL); |
| 8303 | if (!tpr->rx_jmb_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8304 | goto err_out; |
| 8305 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8306 | tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
| 8307 | TG3_RX_JMB_RING_BYTES(tp), |
| 8308 | &tpr->rx_jmb_mapping, |
| 8309 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8310 | if (!tpr->rx_jmb) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8311 | goto err_out; |
| 8312 | } |
| 8313 | |
| 8314 | return 0; |
| 8315 | |
| 8316 | err_out: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8317 | tg3_rx_prodring_fini(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8318 | return -ENOMEM; |
| 8319 | } |
| 8320 | |
| 8321 | /* Free up pending packets in all rx/tx rings. |
| 8322 | * |
| 8323 | * The chip has been shut down and the driver detached from |
| 8324 | * the networking, so no interrupts or new tx packets will |
| 8325 | * end up in the driver. tp->{tx,}lock is not held and we are not |
| 8326 | * in an interrupt context and thus may sleep. |
| 8327 | */ |
| 8328 | static void tg3_free_rings(struct tg3 *tp) |
| 8329 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8330 | int i, j; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8331 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8332 | for (j = 0; j < tp->irq_cnt; j++) { |
| 8333 | struct tg3_napi *tnapi = &tp->napi[j]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8334 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 8335 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
Matt Carlson | b28f642 | 2010-06-05 17:24:32 +0000 | [diff] [blame] | 8336 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 8337 | if (!tnapi->tx_buffers) |
| 8338 | continue; |
| 8339 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 8340 | for (i = 0; i < TG3_TX_RING_SIZE; i++) { |
| 8341 | struct sk_buff *skb = tnapi->tx_buffers[i].skb; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8342 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 8343 | if (!skb) |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8344 | continue; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8345 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 8346 | tg3_tx_skb_unmap(tnapi, i, |
| 8347 | skb_shinfo(skb)->nr_frags - 1); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8348 | |
| 8349 | dev_kfree_skb_any(skb); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8350 | } |
Tom Herbert | 5cb917b | 2012-03-05 19:53:50 +0000 | [diff] [blame] | 8351 | netdev_tx_reset_queue(netdev_get_tx_queue(tp->dev, j)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 8352 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8353 | } |
| 8354 | |
| 8355 | /* Initialize tx/rx rings for packet processing. |
| 8356 | * |
| 8357 | * The chip has been shut down and the driver detached from |
| 8358 | * the networking, so no interrupts or new tx packets will |
| 8359 | * end up in the driver. tp->{tx,}lock are held and thus |
| 8360 | * we may not sleep. |
| 8361 | */ |
| 8362 | static int tg3_init_rings(struct tg3 *tp) |
| 8363 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8364 | int i; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 8365 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8366 | /* Free up all the SKBs. */ |
| 8367 | tg3_free_rings(tp); |
| 8368 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8369 | for (i = 0; i < tp->irq_cnt; i++) { |
| 8370 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8371 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8372 | tnapi->last_tag = 0; |
| 8373 | tnapi->last_irq_tag = 0; |
| 8374 | tnapi->hw_status->status = 0; |
| 8375 | tnapi->hw_status->status_tag = 0; |
| 8376 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8377 | |
| 8378 | tnapi->tx_prod = 0; |
| 8379 | tnapi->tx_cons = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 8380 | if (tnapi->tx_ring) |
| 8381 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8382 | |
| 8383 | tnapi->rx_rcb_ptr = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 8384 | if (tnapi->rx_rcb) |
| 8385 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 8386 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 8387 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 8388 | tg3_free_rings(tp); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 8389 | return -ENOMEM; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 8390 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8391 | } |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 8392 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 8393 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8394 | } |
| 8395 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8396 | static void tg3_mem_tx_release(struct tg3 *tp) |
| 8397 | { |
| 8398 | int i; |
| 8399 | |
| 8400 | for (i = 0; i < tp->irq_max; i++) { |
| 8401 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8402 | |
| 8403 | if (tnapi->tx_ring) { |
| 8404 | dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
| 8405 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
| 8406 | tnapi->tx_ring = NULL; |
| 8407 | } |
| 8408 | |
| 8409 | kfree(tnapi->tx_buffers); |
| 8410 | tnapi->tx_buffers = NULL; |
| 8411 | } |
| 8412 | } |
| 8413 | |
| 8414 | static int tg3_mem_tx_acquire(struct tg3 *tp) |
| 8415 | { |
| 8416 | int i; |
| 8417 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 8418 | |
| 8419 | /* If multivector TSS is enabled, vector 0 does not handle |
| 8420 | * tx interrupts. Don't allocate any resources for it. |
| 8421 | */ |
| 8422 | if (tg3_flag(tp, ENABLE_TSS)) |
| 8423 | tnapi++; |
| 8424 | |
| 8425 | for (i = 0; i < tp->txq_cnt; i++, tnapi++) { |
| 8426 | tnapi->tx_buffers = kzalloc(sizeof(struct tg3_tx_ring_info) * |
| 8427 | TG3_TX_RING_SIZE, GFP_KERNEL); |
| 8428 | if (!tnapi->tx_buffers) |
| 8429 | goto err_out; |
| 8430 | |
| 8431 | tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, |
| 8432 | TG3_TX_RING_BYTES, |
| 8433 | &tnapi->tx_desc_mapping, |
| 8434 | GFP_KERNEL); |
| 8435 | if (!tnapi->tx_ring) |
| 8436 | goto err_out; |
| 8437 | } |
| 8438 | |
| 8439 | return 0; |
| 8440 | |
| 8441 | err_out: |
| 8442 | tg3_mem_tx_release(tp); |
| 8443 | return -ENOMEM; |
| 8444 | } |
| 8445 | |
| 8446 | static void tg3_mem_rx_release(struct tg3 *tp) |
| 8447 | { |
| 8448 | int i; |
| 8449 | |
| 8450 | for (i = 0; i < tp->irq_max; i++) { |
| 8451 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8452 | |
| 8453 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
| 8454 | |
| 8455 | if (!tnapi->rx_rcb) |
| 8456 | continue; |
| 8457 | |
| 8458 | dma_free_coherent(&tp->pdev->dev, |
| 8459 | TG3_RX_RCB_RING_BYTES(tp), |
| 8460 | tnapi->rx_rcb, |
| 8461 | tnapi->rx_rcb_mapping); |
| 8462 | tnapi->rx_rcb = NULL; |
| 8463 | } |
| 8464 | } |
| 8465 | |
| 8466 | static int tg3_mem_rx_acquire(struct tg3 *tp) |
| 8467 | { |
| 8468 | unsigned int i, limit; |
| 8469 | |
| 8470 | limit = tp->rxq_cnt; |
| 8471 | |
| 8472 | /* If RSS is enabled, we need a (dummy) producer ring |
| 8473 | * set on vector zero. This is the true hw prodring. |
| 8474 | */ |
| 8475 | if (tg3_flag(tp, ENABLE_RSS)) |
| 8476 | limit++; |
| 8477 | |
| 8478 | for (i = 0; i < limit; i++) { |
| 8479 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8480 | |
| 8481 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
| 8482 | goto err_out; |
| 8483 | |
| 8484 | /* If multivector RSS is enabled, vector 0 |
| 8485 | * does not handle rx or tx interrupts. |
| 8486 | * Don't allocate any resources for it. |
| 8487 | */ |
| 8488 | if (!i && tg3_flag(tp, ENABLE_RSS)) |
| 8489 | continue; |
| 8490 | |
| 8491 | tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, |
| 8492 | TG3_RX_RCB_RING_BYTES(tp), |
| 8493 | &tnapi->rx_rcb_mapping, |
Joe Perches | 1f9061d2 | 2013-03-15 07:23:58 +0000 | [diff] [blame] | 8494 | GFP_KERNEL | __GFP_ZERO); |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8495 | if (!tnapi->rx_rcb) |
| 8496 | goto err_out; |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8497 | } |
| 8498 | |
| 8499 | return 0; |
| 8500 | |
| 8501 | err_out: |
| 8502 | tg3_mem_rx_release(tp); |
| 8503 | return -ENOMEM; |
| 8504 | } |
| 8505 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 8506 | /* |
| 8507 | * Must not be invoked with interrupt sources disabled and |
| 8508 | * the hardware shutdown down. |
| 8509 | */ |
| 8510 | static void tg3_free_consistent(struct tg3 *tp) |
| 8511 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8512 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8513 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8514 | for (i = 0; i < tp->irq_cnt; i++) { |
| 8515 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8516 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8517 | if (tnapi->hw_status) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8518 | dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
| 8519 | tnapi->hw_status, |
| 8520 | tnapi->status_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8521 | tnapi->hw_status = NULL; |
| 8522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8523 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8524 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8525 | tg3_mem_rx_release(tp); |
| 8526 | tg3_mem_tx_release(tp); |
| 8527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8528 | if (tp->hw_stats) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8529 | dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
| 8530 | tp->hw_stats, tp->stats_mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8531 | tp->hw_stats = NULL; |
| 8532 | } |
| 8533 | } |
| 8534 | |
| 8535 | /* |
| 8536 | * Must not be invoked with interrupt sources disabled and |
| 8537 | * the hardware shutdown down. Can sleep. |
| 8538 | */ |
| 8539 | static int tg3_alloc_consistent(struct tg3 *tp) |
| 8540 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8541 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8542 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8543 | tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
| 8544 | sizeof(struct tg3_hw_stats), |
| 8545 | &tp->stats_mapping, |
Joe Perches | 1f9061d2 | 2013-03-15 07:23:58 +0000 | [diff] [blame] | 8546 | GFP_KERNEL | __GFP_ZERO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8547 | if (!tp->hw_stats) |
| 8548 | goto err_out; |
| 8549 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8550 | for (i = 0; i < tp->irq_cnt; i++) { |
| 8551 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 8552 | struct tg3_hw_status *sblk; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8553 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 8554 | tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
| 8555 | TG3_HW_STATUS_SIZE, |
| 8556 | &tnapi->status_mapping, |
Joe Perches | 1f9061d2 | 2013-03-15 07:23:58 +0000 | [diff] [blame] | 8557 | GFP_KERNEL | __GFP_ZERO); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8558 | if (!tnapi->hw_status) |
| 8559 | goto err_out; |
| 8560 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 8561 | sblk = tnapi->hw_status; |
| 8562 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8563 | if (tg3_flag(tp, ENABLE_RSS)) { |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 8564 | u16 *prodptr = NULL; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 8565 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8566 | /* |
| 8567 | * When RSS is enabled, the status block format changes |
| 8568 | * slightly. The "rx_jumbo_consumer", "reserved", |
| 8569 | * and "rx_mini_consumer" members get mapped to the |
| 8570 | * other three rx return ring producer indexes. |
| 8571 | */ |
| 8572 | switch (i) { |
| 8573 | case 1: |
| 8574 | prodptr = &sblk->idx[0].rx_producer; |
| 8575 | break; |
| 8576 | case 2: |
| 8577 | prodptr = &sblk->rx_jumbo_consumer; |
| 8578 | break; |
| 8579 | case 3: |
| 8580 | prodptr = &sblk->reserved; |
| 8581 | break; |
| 8582 | case 4: |
| 8583 | prodptr = &sblk->rx_mini_consumer; |
Matt Carlson | f891ea1 | 2012-04-24 13:37:01 +0000 | [diff] [blame] | 8584 | break; |
| 8585 | } |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8586 | tnapi->rx_rcb_prod_idx = prodptr; |
| 8587 | } else { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 8588 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 8589 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8590 | } |
| 8591 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 8592 | if (tg3_mem_tx_acquire(tp) || tg3_mem_rx_acquire(tp)) |
| 8593 | goto err_out; |
| 8594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8595 | return 0; |
| 8596 | |
| 8597 | err_out: |
| 8598 | tg3_free_consistent(tp); |
| 8599 | return -ENOMEM; |
| 8600 | } |
| 8601 | |
| 8602 | #define MAX_WAIT_CNT 1000 |
| 8603 | |
| 8604 | /* To stop a block, clear the enable bit and poll till it |
| 8605 | * clears. tp->lock is held. |
| 8606 | */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 8607 | static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, bool silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8608 | { |
| 8609 | unsigned int i; |
| 8610 | u32 val; |
| 8611 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8612 | if (tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8613 | switch (ofs) { |
| 8614 | case RCVLSC_MODE: |
| 8615 | case DMAC_MODE: |
| 8616 | case MBFREE_MODE: |
| 8617 | case BUFMGR_MODE: |
| 8618 | case MEMARB_MODE: |
| 8619 | /* We can't enable/disable these bits of the |
| 8620 | * 5705/5750, just say success. |
| 8621 | */ |
| 8622 | return 0; |
| 8623 | |
| 8624 | default: |
| 8625 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 8626 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8627 | } |
| 8628 | |
| 8629 | val = tr32(ofs); |
| 8630 | val &= ~enable_bit; |
| 8631 | tw32_f(ofs, val); |
| 8632 | |
| 8633 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 8634 | udelay(100); |
| 8635 | val = tr32(ofs); |
| 8636 | if ((val & enable_bit) == 0) |
| 8637 | break; |
| 8638 | } |
| 8639 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8640 | if (i == MAX_WAIT_CNT && !silent) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 8641 | dev_err(&tp->pdev->dev, |
| 8642 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", |
| 8643 | ofs, enable_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8644 | return -ENODEV; |
| 8645 | } |
| 8646 | |
| 8647 | return 0; |
| 8648 | } |
| 8649 | |
| 8650 | /* tp->lock is held. */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 8651 | static int tg3_abort_hw(struct tg3 *tp, bool silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8652 | { |
| 8653 | int i, err; |
| 8654 | |
| 8655 | tg3_disable_ints(tp); |
| 8656 | |
| 8657 | tp->rx_mode &= ~RX_MODE_ENABLE; |
| 8658 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8659 | udelay(10); |
| 8660 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8661 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
| 8662 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); |
| 8663 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); |
| 8664 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); |
| 8665 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); |
| 8666 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8667 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8668 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); |
| 8669 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); |
| 8670 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); |
| 8671 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); |
| 8672 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); |
| 8673 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); |
| 8674 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8675 | |
| 8676 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 8677 | tw32_f(MAC_MODE, tp->mac_mode); |
| 8678 | udelay(40); |
| 8679 | |
| 8680 | tp->tx_mode &= ~TX_MODE_ENABLE; |
| 8681 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 8682 | |
| 8683 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 8684 | udelay(100); |
| 8685 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) |
| 8686 | break; |
| 8687 | } |
| 8688 | if (i >= MAX_WAIT_CNT) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 8689 | dev_err(&tp->pdev->dev, |
| 8690 | "%s timed out, TX_MODE_ENABLE will not clear " |
| 8691 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 8692 | err |= -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8693 | } |
| 8694 | |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 8695 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8696 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
| 8697 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8698 | |
| 8699 | tw32(FTQ_RESET, 0xffffffff); |
| 8700 | tw32(FTQ_RESET, 0x00000000); |
| 8701 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 8702 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
| 8703 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8704 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8705 | for (i = 0; i < tp->irq_cnt; i++) { |
| 8706 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8707 | if (tnapi->hw_status) |
| 8708 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8709 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8711 | return err; |
| 8712 | } |
| 8713 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8714 | /* Save PCI command register before chip reset */ |
| 8715 | static void tg3_save_pci_state(struct tg3 *tp) |
| 8716 | { |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 8717 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8718 | } |
| 8719 | |
| 8720 | /* Restore PCI state after chip reset */ |
| 8721 | static void tg3_restore_pci_state(struct tg3 *tp) |
| 8722 | { |
| 8723 | u32 val; |
| 8724 | |
| 8725 | /* Re-enable indirect register accesses. */ |
| 8726 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 8727 | tp->misc_host_ctrl); |
| 8728 | |
| 8729 | /* Set MAX PCI retry to zero. */ |
| 8730 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8731 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8732 | tg3_flag(tp, PCIX_MODE)) |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8733 | val |= PCISTATE_RETRY_SAME_DMA; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8734 | /* Allow reads and writes to the APE register and memory space. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8735 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8736 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 8737 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 8738 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8739 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
| 8740 | |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 8741 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8742 | |
Matt Carlson | 2c55a3d | 2011-11-28 09:41:04 +0000 | [diff] [blame] | 8743 | if (!tg3_flag(tp, PCI_EXPRESS)) { |
| 8744 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 8745 | tp->pci_cacheline_sz); |
| 8746 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 8747 | tp->pci_lat_timer); |
Michael Chan | 114342f | 2007-10-15 02:12:26 -0700 | [diff] [blame] | 8748 | } |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 8749 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8750 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8751 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8752 | u16 pcix_cmd; |
| 8753 | |
| 8754 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8755 | &pcix_cmd); |
| 8756 | pcix_cmd &= ~PCI_X_CMD_ERO; |
| 8757 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8758 | pcix_cmd); |
| 8759 | } |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8760 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8761 | if (tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8762 | |
| 8763 | /* Chip reset on 5780 will reset MSI enable bit, |
| 8764 | * so need to restore it. |
| 8765 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8766 | if (tg3_flag(tp, USING_MSI)) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8767 | u16 ctrl; |
| 8768 | |
| 8769 | pci_read_config_word(tp->pdev, |
| 8770 | tp->msi_cap + PCI_MSI_FLAGS, |
| 8771 | &ctrl); |
| 8772 | pci_write_config_word(tp->pdev, |
| 8773 | tp->msi_cap + PCI_MSI_FLAGS, |
| 8774 | ctrl | PCI_MSI_FLAGS_ENABLE); |
| 8775 | val = tr32(MSGINT_MODE); |
| 8776 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); |
| 8777 | } |
| 8778 | } |
| 8779 | } |
| 8780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8781 | /* tp->lock is held. */ |
| 8782 | static int tg3_chip_reset(struct tg3 *tp) |
| 8783 | { |
| 8784 | u32 val; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 8785 | void (*write_op)(struct tg3 *, u32, u32); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8786 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8787 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 8788 | tg3_nvram_lock(tp); |
| 8789 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 8790 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
| 8791 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 8792 | /* No matching tg3_nvram_unlock() after this because |
| 8793 | * chip reset below will undo the nvram lock. |
| 8794 | */ |
| 8795 | tp->nvram_lock_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8796 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8797 | /* GRC_MISC_CFG core clock reset will clear the memory |
| 8798 | * enable bit in PCI register 4 and the MSI enable bit |
| 8799 | * on some chips, so we save relevant registers here. |
| 8800 | */ |
| 8801 | tg3_save_pci_state(tp); |
| 8802 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8803 | if (tg3_asic_rev(tp) == ASIC_REV_5752 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8804 | tg3_flag(tp, 5755_PLUS)) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8805 | tw32(GRC_FASTBOOT_PC, 0); |
| 8806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8807 | /* |
| 8808 | * We must avoid the readl() that normally takes place. |
| 8809 | * It locks machines, causes machine checks, and other |
| 8810 | * fun things. So, temporarily disable the 5701 |
| 8811 | * hardware workaround, while we do the reset. |
| 8812 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 8813 | write_op = tp->write32; |
| 8814 | if (write_op == tg3_write_flush_reg32) |
| 8815 | tp->write32 = tg3_write32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8816 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8817 | /* Prevent the irq handler from reading or writing PCI registers |
| 8818 | * during chip reset when the memory enable bit in the PCI command |
| 8819 | * register may be cleared. The chip does not generate interrupt |
| 8820 | * at this time, but the irq handler may still be called due to irq |
| 8821 | * sharing or irqpoll. |
| 8822 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8823 | tg3_flag_set(tp, CHIP_RESETTING); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 8824 | for (i = 0; i < tp->irq_cnt; i++) { |
| 8825 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8826 | if (tnapi->hw_status) { |
| 8827 | tnapi->hw_status->status = 0; |
| 8828 | tnapi->hw_status->status_tag = 0; |
| 8829 | } |
| 8830 | tnapi->last_tag = 0; |
| 8831 | tnapi->last_irq_tag = 0; |
Michael Chan | b8fa2f3 | 2007-04-06 17:35:37 -0700 | [diff] [blame] | 8832 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8833 | smp_mb(); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8834 | |
| 8835 | for (i = 0; i < tp->irq_cnt; i++) |
| 8836 | synchronize_irq(tp->napi[i].irq_vec); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8837 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8838 | if (tg3_asic_rev(tp) == ASIC_REV_57780) { |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 8839 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 8840 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 8841 | } |
| 8842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8843 | /* do the reset */ |
| 8844 | val = GRC_MISC_CFG_CORECLK_RESET; |
| 8845 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8846 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 8847 | /* Force PCIe 1.0a mode */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8848 | if (tg3_asic_rev(tp) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8849 | !tg3_flag(tp, 57765_PLUS) && |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 8850 | tr32(TG3_PCIE_PHY_TSTCTL) == |
| 8851 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) |
| 8852 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); |
| 8853 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8854 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8855 | tw32(GRC_MISC_CFG, (1 << 29)); |
| 8856 | val |= (1 << 29); |
| 8857 | } |
| 8858 | } |
| 8859 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8860 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 8861 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
| 8862 | tw32(GRC_VCPU_EXT_CTRL, |
| 8863 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 8864 | } |
| 8865 | |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 8866 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8867 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, CPMU_PRESENT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8868 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 8869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8870 | tw32(GRC_MISC_CFG, val); |
| 8871 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 8872 | /* restore 5701 hardware bug workaround write method */ |
| 8873 | tp->write32 = write_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8874 | |
| 8875 | /* Unfortunately, we have to delay before the PCI read back. |
| 8876 | * Some 575X chips even will not respond to a PCI cfg access |
| 8877 | * when the reset command is given to the chip. |
| 8878 | * |
| 8879 | * How do these hardware designers expect things to work |
| 8880 | * properly if the PCI write is posted for a long period |
| 8881 | * of time? It is always necessary to have some method by |
| 8882 | * which a register read back can occur to push the write |
| 8883 | * out which does the reset. |
| 8884 | * |
| 8885 | * For most tg3 variants the trick below was working. |
| 8886 | * Ho hum... |
| 8887 | */ |
| 8888 | udelay(120); |
| 8889 | |
| 8890 | /* Flush PCI posted writes. The normal MMIO registers |
| 8891 | * are inaccessible at this time so this is the only |
| 8892 | * way to make this reliably (actually, this is no longer |
| 8893 | * the case, see above). I tried to use indirect |
| 8894 | * register read/write but this upset some 5701 variants. |
| 8895 | */ |
| 8896 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); |
| 8897 | |
| 8898 | udelay(120); |
| 8899 | |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8900 | if (tg3_flag(tp, PCI_EXPRESS) && pci_is_pcie(tp->pdev)) { |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 8901 | u16 val16; |
| 8902 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8903 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5750_A0) { |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 8904 | int j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8905 | u32 cfg_val; |
| 8906 | |
| 8907 | /* Wait for link training to complete. */ |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 8908 | for (j = 0; j < 5000; j++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8909 | udelay(100); |
| 8910 | |
| 8911 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); |
| 8912 | pci_write_config_dword(tp->pdev, 0xc4, |
| 8913 | cfg_val | (1 << 15)); |
| 8914 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8915 | |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 8916 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8917 | val16 = PCI_EXP_DEVCTL_RELAX_EN | PCI_EXP_DEVCTL_NOSNOOP_EN; |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 8918 | /* |
| 8919 | * Older PCIe devices only support the 128 byte |
| 8920 | * MPS setting. Enforce the restriction. |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8921 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8922 | if (!tg3_flag(tp, CPMU_PRESENT)) |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8923 | val16 |= PCI_EXP_DEVCTL_PAYLOAD; |
| 8924 | pcie_capability_clear_word(tp->pdev, PCI_EXP_DEVCTL, val16); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8925 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8926 | /* Clear error status */ |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 8927 | pcie_capability_write_word(tp->pdev, PCI_EXP_DEVSTA, |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 8928 | PCI_EXP_DEVSTA_CED | |
| 8929 | PCI_EXP_DEVSTA_NFED | |
| 8930 | PCI_EXP_DEVSTA_FED | |
| 8931 | PCI_EXP_DEVSTA_URD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8932 | } |
| 8933 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8934 | tg3_restore_pci_state(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8935 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8936 | tg3_flag_clear(tp, CHIP_RESETTING); |
| 8937 | tg3_flag_clear(tp, ERROR_PROCESSED); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 8938 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8939 | val = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8940 | if (tg3_flag(tp, 5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 8941 | val = tr32(MEMARB_MODE); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 8942 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8943 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8944 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5750_A3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8945 | tg3_stop_fw(tp); |
| 8946 | tw32(0x5000, 0x400); |
| 8947 | } |
| 8948 | |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 8949 | if (tg3_flag(tp, IS_SSB_CORE)) { |
| 8950 | /* |
| 8951 | * BCM4785: In order to avoid repercussions from using |
| 8952 | * potentially defective internal ROM, stop the Rx RISC CPU, |
| 8953 | * which is not required. |
| 8954 | */ |
| 8955 | tg3_stop_fw(tp); |
| 8956 | tg3_halt_cpu(tp, RX_CPU_BASE); |
| 8957 | } |
| 8958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8959 | tw32(GRC_MODE, tp->grc_mode); |
| 8960 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8961 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A0) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 8962 | val = tr32(0xc4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8963 | |
| 8964 | tw32(0xc4, val | (1 << 15)); |
| 8965 | } |
| 8966 | |
| 8967 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8968 | tg3_asic_rev(tp) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8969 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8970 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8971 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
| 8972 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 8973 | } |
| 8974 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8975 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 8976 | tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8977 | val = tp->mac_mode; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8978 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 8979 | tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8980 | val = tp->mac_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8981 | } else |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8982 | val = 0; |
| 8983 | |
| 8984 | tw32_f(MAC_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8985 | udelay(40); |
| 8986 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 8987 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
| 8988 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 8989 | err = tg3_poll_fw(tp); |
| 8990 | if (err) |
| 8991 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8992 | |
Matt Carlson | 0a9140c | 2009-08-28 12:27:50 +0000 | [diff] [blame] | 8993 | tg3_mdio_start(tp); |
| 8994 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8995 | if (tg3_flag(tp, PCI_EXPRESS) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 8996 | tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0 && |
| 8997 | tg3_asic_rev(tp) != ASIC_REV_5785 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 8998 | !tg3_flag(tp, 57765_PLUS)) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 8999 | val = tr32(0x7c00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9000 | |
| 9001 | tw32(0x7c00, val | (1 << 25)); |
| 9002 | } |
| 9003 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9004 | if (tg3_asic_rev(tp) == ASIC_REV_5720) { |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 9005 | val = tr32(TG3_CPMU_CLCK_ORIDE); |
| 9006 | tw32(TG3_CPMU_CLCK_ORIDE, val & ~CPMU_CLCK_ORIDE_MAC_ORIDE_EN); |
| 9007 | } |
| 9008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9009 | /* Reprobe ASF enable state. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9010 | tg3_flag_clear(tp, ENABLE_ASF); |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 9011 | tp->phy_flags &= ~(TG3_PHYFLG_1G_ON_VAUX_OK | |
| 9012 | TG3_PHYFLG_KEEP_LINK_ON_PWRDN); |
| 9013 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9014 | tg3_flag_clear(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9015 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 9016 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 9017 | u32 nic_cfg; |
| 9018 | |
| 9019 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 9020 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9021 | tg3_flag_set(tp, ENABLE_ASF); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 9022 | tp->last_event_jiffies = jiffies; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9023 | if (tg3_flag(tp, 5750_PLUS)) |
| 9024 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 9025 | |
| 9026 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &nic_cfg); |
| 9027 | if (nic_cfg & NIC_SRAM_1G_ON_VAUX_OK) |
| 9028 | tp->phy_flags |= TG3_PHYFLG_1G_ON_VAUX_OK; |
| 9029 | if (nic_cfg & NIC_SRAM_LNK_FLAP_AVOID) |
| 9030 | tp->phy_flags |= TG3_PHYFLG_KEEP_LINK_ON_PWRDN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9031 | } |
| 9032 | } |
| 9033 | |
| 9034 | return 0; |
| 9035 | } |
| 9036 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 9037 | static void tg3_get_nstats(struct tg3 *, struct rtnl_link_stats64 *); |
| 9038 | static void tg3_get_estats(struct tg3 *, struct tg3_ethtool_stats *); |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 9039 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9040 | /* tp->lock is held. */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 9041 | static int tg3_halt(struct tg3 *tp, int kind, bool silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9042 | { |
| 9043 | int err; |
| 9044 | |
| 9045 | tg3_stop_fw(tp); |
| 9046 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9047 | tg3_write_sig_pre_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9048 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 9049 | tg3_abort_hw(tp, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9050 | err = tg3_chip_reset(tp); |
| 9051 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 9052 | __tg3_set_mac_addr(tp, false); |
Matt Carlson | daba2a6 | 2009-04-20 06:58:52 +0000 | [diff] [blame] | 9053 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9054 | tg3_write_sig_legacy(tp, kind); |
| 9055 | tg3_write_sig_post_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9056 | |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 9057 | if (tp->hw_stats) { |
| 9058 | /* Save the stats across chip resets... */ |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 9059 | tg3_get_nstats(tp, &tp->net_stats_prev); |
Matt Carlson | 92feeab | 2011-12-08 14:40:14 +0000 | [diff] [blame] | 9060 | tg3_get_estats(tp, &tp->estats_prev); |
| 9061 | |
| 9062 | /* And make sure the next sample is new data */ |
| 9063 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 9064 | } |
| 9065 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9066 | if (err) |
| 9067 | return err; |
| 9068 | |
| 9069 | return 0; |
| 9070 | } |
| 9071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9072 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
| 9073 | { |
| 9074 | struct tg3 *tp = netdev_priv(dev); |
| 9075 | struct sockaddr *addr = p; |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 9076 | int err = 0; |
| 9077 | bool skip_mac_1 = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9078 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 9079 | if (!is_valid_ether_addr(addr->sa_data)) |
Danny Kukawka | 504f9b5 | 2012-02-21 02:07:49 +0000 | [diff] [blame] | 9080 | return -EADDRNOTAVAIL; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 9081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9082 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 9083 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 9084 | if (!netif_running(dev)) |
| 9085 | return 0; |
| 9086 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9087 | if (tg3_flag(tp, ENABLE_ASF)) { |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 9088 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 9089 | |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 9090 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
| 9091 | addr0_low = tr32(MAC_ADDR_0_LOW); |
| 9092 | addr1_high = tr32(MAC_ADDR_1_HIGH); |
| 9093 | addr1_low = tr32(MAC_ADDR_1_LOW); |
| 9094 | |
| 9095 | /* Skip MAC addr 1 if ASF is using it. */ |
| 9096 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && |
| 9097 | !(addr1_high == 0 && addr1_low == 0)) |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 9098 | skip_mac_1 = true; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 9099 | } |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 9100 | spin_lock_bh(&tp->lock); |
| 9101 | __tg3_set_mac_addr(tp, skip_mac_1); |
| 9102 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9103 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 9104 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9105 | } |
| 9106 | |
| 9107 | /* tp->lock is held. */ |
| 9108 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, |
| 9109 | dma_addr_t mapping, u32 maxlen_flags, |
| 9110 | u32 nic_addr) |
| 9111 | { |
| 9112 | tg3_write_mem(tp, |
| 9113 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 9114 | ((u64) mapping >> 32)); |
| 9115 | tg3_write_mem(tp, |
| 9116 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), |
| 9117 | ((u64) mapping & 0xffffffff)); |
| 9118 | tg3_write_mem(tp, |
| 9119 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), |
| 9120 | maxlen_flags); |
| 9121 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9122 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9123 | tg3_write_mem(tp, |
| 9124 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), |
| 9125 | nic_addr); |
| 9126 | } |
| 9127 | |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 9128 | |
| 9129 | 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] | 9130 | { |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 9131 | int i = 0; |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 9132 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9133 | if (!tg3_flag(tp, ENABLE_TSS)) { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 9134 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
| 9135 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); |
| 9136 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 9137 | } else { |
| 9138 | tw32(HOSTCC_TXCOL_TICKS, 0); |
| 9139 | tw32(HOSTCC_TXMAX_FRAMES, 0); |
| 9140 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 9141 | |
| 9142 | for (; i < tp->txq_cnt; i++) { |
| 9143 | u32 reg; |
| 9144 | |
| 9145 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
| 9146 | tw32(reg, ec->tx_coalesce_usecs); |
| 9147 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; |
| 9148 | tw32(reg, ec->tx_max_coalesced_frames); |
| 9149 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 9150 | tw32(reg, ec->tx_max_coalesced_frames_irq); |
| 9151 | } |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 9152 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 9153 | |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 9154 | for (; i < tp->irq_max - 1; i++) { |
| 9155 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 9156 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 9157 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 9158 | } |
| 9159 | } |
| 9160 | |
| 9161 | static void tg3_coal_rx_init(struct tg3 *tp, struct ethtool_coalesce *ec) |
| 9162 | { |
| 9163 | int i = 0; |
| 9164 | u32 limit = tp->rxq_cnt; |
| 9165 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9166 | if (!tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 9167 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
| 9168 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); |
| 9169 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 9170 | limit--; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 9171 | } else { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 9172 | tw32(HOSTCC_RXCOL_TICKS, 0); |
| 9173 | tw32(HOSTCC_RXMAX_FRAMES, 0); |
| 9174 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 9175 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 9176 | |
Michael Chan | a489b6d | 2012-09-28 07:12:39 +0000 | [diff] [blame] | 9177 | for (; i < limit; i++) { |
| 9178 | u32 reg; |
| 9179 | |
| 9180 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; |
| 9181 | tw32(reg, ec->rx_coalesce_usecs); |
| 9182 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
| 9183 | tw32(reg, ec->rx_max_coalesced_frames); |
| 9184 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 9185 | tw32(reg, ec->rx_max_coalesced_frames_irq); |
| 9186 | } |
| 9187 | |
| 9188 | for (; i < tp->irq_max - 1; i++) { |
| 9189 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 9190 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 9191 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 9192 | } |
| 9193 | } |
| 9194 | |
| 9195 | static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) |
| 9196 | { |
| 9197 | tg3_coal_tx_init(tp, ec); |
| 9198 | tg3_coal_rx_init(tp, ec); |
| 9199 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9200 | if (!tg3_flag(tp, 5705_PLUS)) { |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 9201 | u32 val = ec->stats_block_coalesce_usecs; |
| 9202 | |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 9203 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
| 9204 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); |
| 9205 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 9206 | if (!tp->link_up) |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 9207 | val = 0; |
| 9208 | |
| 9209 | tw32(HOSTCC_STAT_COAL_TICKS, val); |
| 9210 | } |
| 9211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9212 | |
| 9213 | /* tp->lock is held. */ |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9214 | static void tg3_rings_reset(struct tg3 *tp) |
| 9215 | { |
| 9216 | int i; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9217 | u32 stblk, txrcb, rxrcb, limit; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9218 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 9219 | |
| 9220 | /* Disable all transmit rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9221 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9222 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9223 | else if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 3d37728 | 2010-10-14 10:37:39 +0000 | [diff] [blame] | 9224 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9225 | else if (tg3_flag(tp, 57765_CLASS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9226 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 9227 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9228 | else |
| 9229 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 9230 | |
| 9231 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 9232 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) |
| 9233 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 9234 | BDINFO_FLAGS_DISABLED); |
| 9235 | |
| 9236 | |
| 9237 | /* Disable all receive return rings but the first. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9238 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9239 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9240 | else if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9241 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9242 | else if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
| 9243 | tg3_asic_rev(tp) == ASIC_REV_5762 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9244 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9245 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
| 9246 | else |
| 9247 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 9248 | |
| 9249 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 9250 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) |
| 9251 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 9252 | BDINFO_FLAGS_DISABLED); |
| 9253 | |
| 9254 | /* Disable interrupts */ |
| 9255 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9256 | tp->napi[0].chk_msi_cnt = 0; |
| 9257 | tp->napi[0].last_rx_cons = 0; |
| 9258 | tp->napi[0].last_tx_cons = 0; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9259 | |
| 9260 | /* Zero mailbox registers. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9261 | if (tg3_flag(tp, SUPPORT_MSIX)) { |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 9262 | for (i = 1; i < tp->irq_max; i++) { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9263 | tp->napi[i].tx_prod = 0; |
| 9264 | tp->napi[i].tx_cons = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9265 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 9266 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9267 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
| 9268 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); |
Matt Carlson | 7f23073 | 2011-08-31 11:44:48 +0000 | [diff] [blame] | 9269 | tp->napi[i].chk_msi_cnt = 0; |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 9270 | tp->napi[i].last_rx_cons = 0; |
| 9271 | tp->napi[i].last_tx_cons = 0; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9272 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9273 | if (!tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 9274 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9275 | } else { |
| 9276 | tp->napi[0].tx_prod = 0; |
| 9277 | tp->napi[0].tx_cons = 0; |
| 9278 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 9279 | tw32_rx_mbox(tp->napi[0].consmbox, 0); |
| 9280 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9281 | |
| 9282 | /* Make sure the NIC-based send BD rings are disabled. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9283 | if (!tg3_flag(tp, 5705_PLUS)) { |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9284 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 9285 | for (i = 0; i < 16; i++) |
| 9286 | tw32_tx_mbox(mbox + i * 8, 0); |
| 9287 | } |
| 9288 | |
| 9289 | txrcb = NIC_SRAM_SEND_RCB; |
| 9290 | rxrcb = NIC_SRAM_RCV_RET_RCB; |
| 9291 | |
| 9292 | /* Clear status block in ram. */ |
| 9293 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 9294 | |
| 9295 | /* Set status block DMA address */ |
| 9296 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 9297 | ((u64) tnapi->status_mapping >> 32)); |
| 9298 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 9299 | ((u64) tnapi->status_mapping & 0xffffffff)); |
| 9300 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9301 | if (tnapi->tx_ring) { |
| 9302 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 9303 | (TG3_TX_RING_SIZE << |
| 9304 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 9305 | NIC_SRAM_TX_BUFFER_DESC); |
| 9306 | txrcb += TG3_BDINFO_SIZE; |
| 9307 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9308 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9309 | if (tnapi->rx_rcb) { |
| 9310 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9311 | (tp->rx_ret_ring_mask + 1) << |
| 9312 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9313 | rxrcb += TG3_BDINFO_SIZE; |
| 9314 | } |
| 9315 | |
| 9316 | stblk = HOSTCC_STATBLCK_RING1; |
| 9317 | |
| 9318 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
| 9319 | u64 mapping = (u64)tnapi->status_mapping; |
| 9320 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); |
| 9321 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); |
| 9322 | |
| 9323 | /* Clear status block in ram. */ |
| 9324 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 9325 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 9326 | if (tnapi->tx_ring) { |
| 9327 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 9328 | (TG3_TX_RING_SIZE << |
| 9329 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 9330 | NIC_SRAM_TX_BUFFER_DESC); |
| 9331 | txrcb += TG3_BDINFO_SIZE; |
| 9332 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9333 | |
| 9334 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9335 | ((tp->rx_ret_ring_mask + 1) << |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9336 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
| 9337 | |
| 9338 | stblk += 8; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 9339 | rxrcb += TG3_BDINFO_SIZE; |
| 9340 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9341 | } |
| 9342 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9343 | static void tg3_setup_rxbd_thresholds(struct tg3 *tp) |
| 9344 | { |
| 9345 | u32 val, bdcache_maxcnt, host_rep_thresh, nic_rep_thresh; |
| 9346 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9347 | if (!tg3_flag(tp, 5750_PLUS) || |
| 9348 | tg3_flag(tp, 5780_CLASS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9349 | tg3_asic_rev(tp) == ASIC_REV_5750 || |
| 9350 | tg3_asic_rev(tp) == ASIC_REV_5752 || |
Matt Carlson | 513aa6e | 2011-11-21 15:01:18 +0000 | [diff] [blame] | 9351 | tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9352 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5700; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9353 | else if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
| 9354 | tg3_asic_rev(tp) == ASIC_REV_5787) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9355 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5755; |
| 9356 | else |
| 9357 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5906; |
| 9358 | |
| 9359 | nic_rep_thresh = min(bdcache_maxcnt / 2, tp->rx_std_max_post); |
| 9360 | host_rep_thresh = max_t(u32, tp->rx_pending / 8, 1); |
| 9361 | |
| 9362 | val = min(nic_rep_thresh, host_rep_thresh); |
| 9363 | tw32(RCVBDI_STD_THRESH, val); |
| 9364 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9365 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9366 | tw32(STD_REPLENISH_LWM, bdcache_maxcnt); |
| 9367 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9368 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9369 | return; |
| 9370 | |
Matt Carlson | 513aa6e | 2011-11-21 15:01:18 +0000 | [diff] [blame] | 9371 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5700; |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9372 | |
| 9373 | host_rep_thresh = max_t(u32, tp->rx_jumbo_pending / 8, 1); |
| 9374 | |
| 9375 | val = min(bdcache_maxcnt / 2, host_rep_thresh); |
| 9376 | tw32(RCVBDI_JUMBO_THRESH, val); |
| 9377 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9378 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9379 | tw32(JMB_REPLENISH_LWM, bdcache_maxcnt); |
| 9380 | } |
| 9381 | |
Matt Carlson | ccd5ba9 | 2012-02-13 10:20:08 +0000 | [diff] [blame] | 9382 | static inline u32 calc_crc(unsigned char *buf, int len) |
| 9383 | { |
| 9384 | u32 reg; |
| 9385 | u32 tmp; |
| 9386 | int j, k; |
| 9387 | |
| 9388 | reg = 0xffffffff; |
| 9389 | |
| 9390 | for (j = 0; j < len; j++) { |
| 9391 | reg ^= buf[j]; |
| 9392 | |
| 9393 | for (k = 0; k < 8; k++) { |
| 9394 | tmp = reg & 0x01; |
| 9395 | |
| 9396 | reg >>= 1; |
| 9397 | |
| 9398 | if (tmp) |
| 9399 | reg ^= 0xedb88320; |
| 9400 | } |
| 9401 | } |
| 9402 | |
| 9403 | return ~reg; |
| 9404 | } |
| 9405 | |
| 9406 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) |
| 9407 | { |
| 9408 | /* accept or reject all multicast frames */ |
| 9409 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); |
| 9410 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); |
| 9411 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); |
| 9412 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); |
| 9413 | } |
| 9414 | |
| 9415 | static void __tg3_set_rx_mode(struct net_device *dev) |
| 9416 | { |
| 9417 | struct tg3 *tp = netdev_priv(dev); |
| 9418 | u32 rx_mode; |
| 9419 | |
| 9420 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
| 9421 | RX_MODE_KEEP_VLAN_TAG); |
| 9422 | |
| 9423 | #if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) |
| 9424 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
| 9425 | * flag clear. |
| 9426 | */ |
| 9427 | if (!tg3_flag(tp, ENABLE_ASF)) |
| 9428 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 9429 | #endif |
| 9430 | |
| 9431 | if (dev->flags & IFF_PROMISC) { |
| 9432 | /* Promiscuous mode. */ |
| 9433 | rx_mode |= RX_MODE_PROMISC; |
| 9434 | } else if (dev->flags & IFF_ALLMULTI) { |
| 9435 | /* Accept all multicast. */ |
| 9436 | tg3_set_multi(tp, 1); |
| 9437 | } else if (netdev_mc_empty(dev)) { |
| 9438 | /* Reject all multicast. */ |
| 9439 | tg3_set_multi(tp, 0); |
| 9440 | } else { |
| 9441 | /* Accept one or more multicast(s). */ |
| 9442 | struct netdev_hw_addr *ha; |
| 9443 | u32 mc_filter[4] = { 0, }; |
| 9444 | u32 regidx; |
| 9445 | u32 bit; |
| 9446 | u32 crc; |
| 9447 | |
| 9448 | netdev_for_each_mc_addr(ha, dev) { |
| 9449 | crc = calc_crc(ha->addr, ETH_ALEN); |
| 9450 | bit = ~crc & 0x7f; |
| 9451 | regidx = (bit & 0x60) >> 5; |
| 9452 | bit &= 0x1f; |
| 9453 | mc_filter[regidx] |= (1 << bit); |
| 9454 | } |
| 9455 | |
| 9456 | tw32(MAC_HASH_REG_0, mc_filter[0]); |
| 9457 | tw32(MAC_HASH_REG_1, mc_filter[1]); |
| 9458 | tw32(MAC_HASH_REG_2, mc_filter[2]); |
| 9459 | tw32(MAC_HASH_REG_3, mc_filter[3]); |
| 9460 | } |
| 9461 | |
| 9462 | if (rx_mode != tp->rx_mode) { |
| 9463 | tp->rx_mode = rx_mode; |
| 9464 | tw32_f(MAC_RX_MODE, rx_mode); |
| 9465 | udelay(10); |
| 9466 | } |
| 9467 | } |
| 9468 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 9469 | 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] | 9470 | { |
| 9471 | int i; |
| 9472 | |
| 9473 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 9474 | tp->rss_ind_tbl[i] = ethtool_rxfh_indir_default(i, qcnt); |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 9475 | } |
| 9476 | |
| 9477 | static void tg3_rss_check_indir_tbl(struct tg3 *tp) |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 9478 | { |
| 9479 | int i; |
| 9480 | |
| 9481 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 9482 | return; |
| 9483 | |
Michael Chan | 0b3ba05 | 2012-11-14 14:44:29 +0000 | [diff] [blame] | 9484 | if (tp->rxq_cnt == 1) { |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 9485 | memset(&tp->rss_ind_tbl[0], 0, sizeof(tp->rss_ind_tbl)); |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 9486 | return; |
| 9487 | } |
| 9488 | |
| 9489 | /* Validate table against current IRQ count */ |
| 9490 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { |
Michael Chan | 0b3ba05 | 2012-11-14 14:44:29 +0000 | [diff] [blame] | 9491 | if (tp->rss_ind_tbl[i] >= tp->rxq_cnt) |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 9492 | break; |
| 9493 | } |
| 9494 | |
| 9495 | if (i != TG3_RSS_INDIR_TBL_SIZE) |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 9496 | tg3_rss_init_dflt_indir_tbl(tp, tp->rxq_cnt); |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 9497 | } |
| 9498 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 9499 | static void tg3_rss_write_indir_tbl(struct tg3 *tp) |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 9500 | { |
| 9501 | int i = 0; |
| 9502 | u32 reg = MAC_RSS_INDIR_TBL_0; |
| 9503 | |
| 9504 | while (i < TG3_RSS_INDIR_TBL_SIZE) { |
| 9505 | u32 val = tp->rss_ind_tbl[i]; |
| 9506 | i++; |
| 9507 | for (; i % 8; i++) { |
| 9508 | val <<= 4; |
| 9509 | val |= tp->rss_ind_tbl[i]; |
| 9510 | } |
| 9511 | tw32(reg, val); |
| 9512 | reg += 4; |
| 9513 | } |
| 9514 | } |
| 9515 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9516 | /* tp->lock is held. */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 9517 | static int tg3_reset_hw(struct tg3 *tp, bool reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9518 | { |
| 9519 | u32 val, rdmac_mode; |
| 9520 | int i, err, limit; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 9521 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9522 | |
| 9523 | tg3_disable_ints(tp); |
| 9524 | |
| 9525 | tg3_stop_fw(tp); |
| 9526 | |
| 9527 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); |
| 9528 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9529 | if (tg3_flag(tp, INIT_COMPLETE)) |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 9530 | tg3_abort_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9531 | |
Nithin Sujir | fdad8de | 2013-04-09 08:48:08 +0000 | [diff] [blame] | 9532 | if ((tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) && |
| 9533 | !(tp->phy_flags & TG3_PHYFLG_USER_CONFIGURED)) { |
| 9534 | tg3_phy_pull_config(tp); |
Nithin Sujir | 400dfba | 2013-05-18 06:26:53 +0000 | [diff] [blame] | 9535 | tg3_eee_pull_config(tp, NULL); |
Nithin Sujir | fdad8de | 2013-04-09 08:48:08 +0000 | [diff] [blame] | 9536 | tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; |
| 9537 | } |
| 9538 | |
Nithin Sujir | 400dfba | 2013-05-18 06:26:53 +0000 | [diff] [blame] | 9539 | /* Enable MAC control of LPI */ |
| 9540 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) |
| 9541 | tg3_setup_eee(tp); |
| 9542 | |
Matt Carlson | 603f117 | 2010-02-12 14:47:10 +0000 | [diff] [blame] | 9543 | if (reset_phy) |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 9544 | tg3_phy_reset(tp); |
| 9545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9546 | err = tg3_chip_reset(tp); |
| 9547 | if (err) |
| 9548 | return err; |
| 9549 | |
| 9550 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); |
| 9551 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9552 | if (tg3_chip_rev(tp) == CHIPREV_5784_AX) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 9553 | val = tr32(TG3_CPMU_CTRL); |
| 9554 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); |
| 9555 | tw32(TG3_CPMU_CTRL, val); |
Matt Carlson | 9acb961 | 2007-11-12 21:10:06 -0800 | [diff] [blame] | 9556 | |
| 9557 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 9558 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 9559 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 9560 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 9561 | |
| 9562 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); |
| 9563 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; |
| 9564 | val |= CPMU_LNK_AWARE_MACCLK_6_25; |
| 9565 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); |
| 9566 | |
| 9567 | val = tr32(TG3_CPMU_HST_ACC); |
| 9568 | val &= ~CPMU_HST_ACC_MACCLK_MASK; |
| 9569 | val |= CPMU_HST_ACC_MACCLK_6_25; |
| 9570 | tw32(TG3_CPMU_HST_ACC, val); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 9571 | } |
| 9572 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9573 | if (tg3_asic_rev(tp) == ASIC_REV_57780) { |
Matt Carlson | 33466d93 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 9574 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 9575 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | |
| 9576 | PCIE_PWR_MGMT_L1_THRESH_4MS; |
| 9577 | tw32(PCIE_PWR_MGMT_THRESH, val); |
Matt Carlson | 521e6b9 | 2009-08-25 10:06:01 +0000 | [diff] [blame] | 9578 | |
| 9579 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; |
| 9580 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); |
| 9581 | |
| 9582 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); |
Matt Carlson | 33466d93 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 9583 | |
Matt Carlson | f40386c | 2009-11-02 14:24:02 +0000 | [diff] [blame] | 9584 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 9585 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 9586 | } |
| 9587 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9588 | if (tg3_flag(tp, L1PLLPD_EN)) { |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 9589 | u32 grc_mode = tr32(GRC_MODE); |
| 9590 | |
| 9591 | /* Access the lower 1K of PL PCIE block registers. */ |
| 9592 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 9593 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 9594 | |
| 9595 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); |
| 9596 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, |
| 9597 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); |
| 9598 | |
| 9599 | tw32(GRC_MODE, grc_mode); |
| 9600 | } |
| 9601 | |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9602 | if (tg3_flag(tp, 57765_CLASS)) { |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9603 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) { |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 9604 | u32 grc_mode = tr32(GRC_MODE); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 9605 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 9606 | /* Access the lower 1K of PL PCIE block registers. */ |
| 9607 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 9608 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 9609 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 9610 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 9611 | TG3_PCIE_PL_LO_PHYCTL5); |
| 9612 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, |
| 9613 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 9614 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 9615 | tw32(GRC_MODE, grc_mode); |
| 9616 | } |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 9617 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9618 | if (tg3_chip_rev(tp) != CHIPREV_57765_AX) { |
Matt Carlson | d3f677a | 2013-02-14 14:27:51 +0000 | [diff] [blame] | 9619 | u32 grc_mode; |
| 9620 | |
| 9621 | /* Fix transmit hangs */ |
| 9622 | val = tr32(TG3_CPMU_PADRNG_CTL); |
| 9623 | val |= TG3_CPMU_PADRNG_CTL_RDIV2; |
| 9624 | tw32(TG3_CPMU_PADRNG_CTL, val); |
| 9625 | |
| 9626 | grc_mode = tr32(GRC_MODE); |
Matt Carlson | 1ff30a5 | 2011-05-19 12:12:46 +0000 | [diff] [blame] | 9627 | |
| 9628 | /* Access the lower 1K of DL PCIE block registers. */ |
| 9629 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 9630 | tw32(GRC_MODE, val | GRC_MODE_PCIE_DL_SEL); |
| 9631 | |
| 9632 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 9633 | TG3_PCIE_DL_LO_FTSMAX); |
| 9634 | val &= ~TG3_PCIE_DL_LO_FTSMAX_MSK; |
| 9635 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_DL_LO_FTSMAX, |
| 9636 | val | TG3_PCIE_DL_LO_FTSMAX_VAL); |
| 9637 | |
| 9638 | tw32(GRC_MODE, grc_mode); |
| 9639 | } |
| 9640 | |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 9641 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 9642 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 9643 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 9644 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 9645 | } |
| 9646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9647 | /* This works around an issue with Athlon chipsets on |
| 9648 | * B3 tigon3 silicon. This bit has no effect on any |
| 9649 | * other revision. But do not set this on PCI Express |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 9650 | * 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] | 9651 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9652 | if (!tg3_flag(tp, CPMU_PRESENT)) { |
| 9653 | if (!tg3_flag(tp, PCI_EXPRESS)) |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 9654 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
| 9655 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 9656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9657 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9658 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9659 | tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9660 | val = tr32(TG3PCI_PCISTATE); |
| 9661 | val |= PCISTATE_RETRY_SAME_DMA; |
| 9662 | tw32(TG3PCI_PCISTATE, val); |
| 9663 | } |
| 9664 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9665 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 9666 | /* Allow reads and writes to the |
| 9667 | * APE register and memory space. |
| 9668 | */ |
| 9669 | val = tr32(TG3PCI_PCISTATE); |
| 9670 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 9671 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 9672 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 9673 | tw32(TG3PCI_PCISTATE, val); |
| 9674 | } |
| 9675 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9676 | if (tg3_chip_rev(tp) == CHIPREV_5704_BX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9677 | /* Enable some hw fixes. */ |
| 9678 | val = tr32(TG3PCI_MSI_DATA); |
| 9679 | val |= (1 << 26) | (1 << 28) | (1 << 29); |
| 9680 | tw32(TG3PCI_MSI_DATA, val); |
| 9681 | } |
| 9682 | |
| 9683 | /* Descriptor ring init may make accesses to the |
| 9684 | * NIC SRAM area to setup the TX descriptors, so we |
| 9685 | * can only do this after the hardware has been |
| 9686 | * successfully reset. |
| 9687 | */ |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 9688 | err = tg3_init_rings(tp); |
| 9689 | if (err) |
| 9690 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9691 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9692 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 9693 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
| 9694 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9695 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) |
Matt Carlson | 1a31902 | 2010-04-12 06:58:25 +0000 | [diff] [blame] | 9696 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 9697 | if (!tg3_flag(tp, 57765_CLASS) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9698 | tg3_asic_rev(tp) != ASIC_REV_5717 && |
| 9699 | tg3_asic_rev(tp) != ASIC_REV_5762) |
Matt Carlson | 0aebff4 | 2011-04-25 12:42:45 +0000 | [diff] [blame] | 9700 | val |= DMA_RWCTRL_TAGGED_STAT_WA; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 9701 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9702 | } else if (tg3_asic_rev(tp) != ASIC_REV_5784 && |
| 9703 | tg3_asic_rev(tp) != ASIC_REV_5761) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 9704 | /* This value is determined during the probe time DMA |
| 9705 | * engine test, tg3_test_dma. |
| 9706 | */ |
| 9707 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 9708 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9709 | |
| 9710 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | |
| 9711 | GRC_MODE_4X_NIC_SEND_RINGS | |
| 9712 | GRC_MODE_NO_TX_PHDR_CSUM | |
| 9713 | GRC_MODE_NO_RX_PHDR_CSUM); |
| 9714 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; |
Michael Chan | d2d746f | 2006-04-06 21:45:39 -0700 | [diff] [blame] | 9715 | |
| 9716 | /* Pseudo-header checksum is done by hardware logic and not |
| 9717 | * the offload processers, so make the chip do the pseudo- |
| 9718 | * header checksums on receive. For transmit it is more |
| 9719 | * convenient to do the pseudo-header checksum in software |
| 9720 | * as Linux does that on transmit for us in all cases. |
| 9721 | */ |
| 9722 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9723 | |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 9724 | val = GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP; |
| 9725 | if (tp->rxptpctl) |
| 9726 | tw32(TG3_RX_PTP_CTL, |
| 9727 | tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK); |
| 9728 | |
| 9729 | if (tg3_flag(tp, PTP_CAPABLE)) |
| 9730 | val |= GRC_MODE_TIME_SYNC_ENABLE; |
| 9731 | |
| 9732 | tw32(GRC_MODE, tp->grc_mode | val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9733 | |
| 9734 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ |
| 9735 | val = tr32(GRC_MISC_CFG); |
| 9736 | val &= ~0xff; |
| 9737 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 9738 | tw32(GRC_MISC_CFG, val); |
| 9739 | |
| 9740 | /* Initialize MBUF/DESC pool. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9741 | if (tg3_flag(tp, 5750_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9742 | /* Do nothing. */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9743 | } else if (tg3_asic_rev(tp) != ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9744 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9745 | if (tg3_asic_rev(tp) == ASIC_REV_5704) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9746 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
| 9747 | else |
| 9748 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); |
| 9749 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); |
| 9750 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9751 | } else if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9752 | int fw_len; |
| 9753 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 9754 | fw_len = tp->fw_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9755 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
| 9756 | tw32(BUFMGR_MB_POOL_ADDR, |
| 9757 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); |
| 9758 | tw32(BUFMGR_MB_POOL_SIZE, |
| 9759 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); |
| 9760 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9761 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 9762 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9763 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 9764 | tp->bufmgr_config.mbuf_read_dma_low_water); |
| 9765 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 9766 | tp->bufmgr_config.mbuf_mac_rx_low_water); |
| 9767 | tw32(BUFMGR_MB_HIGH_WATER, |
| 9768 | tp->bufmgr_config.mbuf_high_water); |
| 9769 | } else { |
| 9770 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 9771 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); |
| 9772 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 9773 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); |
| 9774 | tw32(BUFMGR_MB_HIGH_WATER, |
| 9775 | tp->bufmgr_config.mbuf_high_water_jumbo); |
| 9776 | } |
| 9777 | tw32(BUFMGR_DMA_LOW_WATER, |
| 9778 | tp->bufmgr_config.dma_low_water); |
| 9779 | tw32(BUFMGR_DMA_HIGH_WATER, |
| 9780 | tp->bufmgr_config.dma_high_water); |
| 9781 | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9782 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9783 | if (tg3_asic_rev(tp) == ASIC_REV_5719) |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9784 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9785 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 9786 | tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || |
| 9787 | tg3_chip_rev_id(tp) == CHIPREV_ID_5720_A0) |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 9788 | val |= BUFMGR_MODE_MBLOW_ATTN_ENAB; |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9789 | tw32(BUFMGR_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9790 | for (i = 0; i < 2000; i++) { |
| 9791 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) |
| 9792 | break; |
| 9793 | udelay(10); |
| 9794 | } |
| 9795 | if (i >= 2000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9796 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9797 | return -ENODEV; |
| 9798 | } |
| 9799 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9800 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5906_A1) |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9801 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 9802 | |
Matt Carlson | eb07a94 | 2011-04-20 07:57:36 +0000 | [diff] [blame] | 9803 | tg3_setup_rxbd_thresholds(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9804 | |
| 9805 | /* Initialize TG3_BDINFO's at: |
| 9806 | * RCVDBDI_STD_BD: standard eth size rx ring |
| 9807 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring |
| 9808 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) |
| 9809 | * |
| 9810 | * like so: |
| 9811 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring |
| 9812 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | |
| 9813 | * ring attribute flags |
| 9814 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM |
| 9815 | * |
| 9816 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. |
| 9817 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. |
| 9818 | * |
| 9819 | * The size of each ring is fixed in the firmware, but the location is |
| 9820 | * configurable. |
| 9821 | */ |
| 9822 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9823 | ((u64) tpr->rx_std_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9824 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9825 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9826 | if (!tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 9827 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
| 9828 | NIC_SRAM_RX_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9829 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9830 | /* Disable the mini ring */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9831 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9832 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 9833 | BDINFO_FLAGS_DISABLED); |
| 9834 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9835 | /* Program the jumbo buffer descriptor ring control |
| 9836 | * blocks on those devices that have them. |
| 9837 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9838 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9839 | (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9840 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9841 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9842 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9843 | ((u64) tpr->rx_jmb_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9844 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 9845 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 9846 | val = TG3_RX_JMB_RING_SIZE(tp) << |
| 9847 | BDINFO_FLAGS_MAXLEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9848 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 9849 | val | BDINFO_FLAGS_USE_EXT_RECV); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9850 | if (!tg3_flag(tp, USE_JUMBO_BDFLAG) || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9851 | tg3_flag(tp, 57765_CLASS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9852 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 9853 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
| 9854 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9855 | } else { |
| 9856 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 9857 | BDINFO_FLAGS_DISABLED); |
| 9858 | } |
| 9859 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9860 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | fa6b2aa | 2011-11-21 15:01:19 +0000 | [diff] [blame] | 9861 | val = TG3_RX_STD_RING_SIZE(tp); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 9862 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
| 9863 | val |= (TG3_RX_STD_DMA_SZ << 2); |
| 9864 | } else |
Matt Carlson | 04380d4 | 2010-04-12 06:58:29 +0000 | [diff] [blame] | 9865 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9866 | } else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 9867 | val = TG3_RX_STD_MAX_SIZE_5700 << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 9868 | |
| 9869 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9870 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 9871 | tpr->rx_std_prod_idx = tp->rx_pending; |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 9872 | 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] | 9873 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9874 | tpr->rx_jmb_prod_idx = |
| 9875 | tg3_flag(tp, JUMBO_RING_ENABLE) ? tp->rx_jumbo_pending : 0; |
Matt Carlson | 66711e66 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 9876 | 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] | 9877 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 9878 | tg3_rings_reset(tp); |
| 9879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9880 | /* Initialize MAC address and backoff seed. */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 9881 | __tg3_set_mac_addr(tp, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9882 | |
| 9883 | /* MTU + ethernet header + FCS + optional VLAN tag */ |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 9884 | tw32(MAC_RX_MTU_SIZE, |
| 9885 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9886 | |
| 9887 | /* The slot time is changed by tg3_setup_phy if we |
| 9888 | * run at gigabit with half duplex. |
| 9889 | */ |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9890 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 9891 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 9892 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT); |
| 9893 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9894 | if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 9895 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9896 | val |= tr32(MAC_TX_LENGTHS) & |
| 9897 | (TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 9898 | TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 9899 | |
| 9900 | tw32(MAC_TX_LENGTHS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9901 | |
| 9902 | /* Receive rules. */ |
| 9903 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); |
| 9904 | tw32(RCVLPC_CONFIG, 0x0181); |
| 9905 | |
| 9906 | /* Calculate RDMAC_MODE setting early, we need it to determine |
| 9907 | * the RCVLPC_STATE_ENABLE mask. |
| 9908 | */ |
| 9909 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | |
| 9910 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | |
| 9911 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | |
| 9912 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | |
| 9913 | RDMAC_MODE_LNGREAD_ENAB); |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 9914 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9915 | if (tg3_asic_rev(tp) == ASIC_REV_5717) |
Matt Carlson | 0339e4e | 2010-02-12 14:47:09 +0000 | [diff] [blame] | 9916 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
| 9917 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9918 | if (tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 9919 | tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 9920 | tg3_asic_rev(tp) == ASIC_REV_57780) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 9921 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
| 9922 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | |
| 9923 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; |
| 9924 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9925 | if (tg3_asic_rev(tp) == ASIC_REV_5705 && |
| 9926 | tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9927 | if (tg3_flag(tp, TSO_CAPABLE) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9928 | tg3_asic_rev(tp) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9929 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
| 9930 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9931 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9932 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 9933 | } |
| 9934 | } |
| 9935 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9936 | if (tg3_flag(tp, PCI_EXPRESS)) |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 9937 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 9938 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9939 | if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
Matt Carlson | d3f677a | 2013-02-14 14:27:51 +0000 | [diff] [blame] | 9940 | tp->dma_limit = 0; |
| 9941 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
| 9942 | rdmac_mode |= RDMAC_MODE_JMB_2K_MMRR; |
| 9943 | tp->dma_limit = TG3_TX_BD_DMA_MAX_2K; |
| 9944 | } |
| 9945 | } |
| 9946 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9947 | if (tg3_flag(tp, HW_TSO_1) || |
| 9948 | tg3_flag(tp, HW_TSO_2) || |
| 9949 | tg3_flag(tp, HW_TSO_3)) |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 9950 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
| 9951 | |
Matt Carlson | 108a6c1 | 2011-05-19 12:12:47 +0000 | [diff] [blame] | 9952 | if (tg3_flag(tp, 57765_PLUS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9953 | tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 9954 | tg3_asic_rev(tp) == ASIC_REV_57780) |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 9955 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9956 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9957 | if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 9958 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 9959 | rdmac_mode |= tr32(RDMAC_MODE) & RDMAC_MODE_H2BNC_VLAN_DET; |
| 9960 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9961 | if (tg3_asic_rev(tp) == ASIC_REV_5761 || |
| 9962 | tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 9963 | tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 9964 | tg3_asic_rev(tp) == ASIC_REV_57780 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 9965 | tg3_flag(tp, 57765_PLUS)) { |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9966 | u32 tgtreg; |
| 9967 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9968 | if (tg3_asic_rev(tp) == ASIC_REV_5762) |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9969 | tgtreg = TG3_RDMA_RSRVCTRL_REG2; |
| 9970 | else |
| 9971 | tgtreg = TG3_RDMA_RSRVCTRL_REG; |
| 9972 | |
| 9973 | val = tr32(tgtreg); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9974 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || |
| 9975 | tg3_asic_rev(tp) == ASIC_REV_5762) { |
Matt Carlson | b4495ed | 2011-01-25 15:58:47 +0000 | [diff] [blame] | 9976 | val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | |
| 9977 | TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | |
| 9978 | TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); |
| 9979 | val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B | |
| 9980 | TG3_RDMA_RSRVCTRL_FIFO_LWM_1_5K | |
| 9981 | TG3_RDMA_RSRVCTRL_FIFO_HWM_1_5K; |
Matt Carlson | b75cc0e | 2010-11-24 08:31:46 +0000 | [diff] [blame] | 9982 | } |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9983 | tw32(tgtreg, val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 9984 | } |
| 9985 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9986 | if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 9987 | tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 9988 | tg3_asic_rev(tp) == ASIC_REV_5762) { |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9989 | u32 tgtreg; |
| 9990 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 9991 | if (tg3_asic_rev(tp) == ASIC_REV_5762) |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 9992 | tgtreg = TG3_LSO_RD_DMA_CRPTEN_CTRL2; |
| 9993 | else |
| 9994 | tgtreg = TG3_LSO_RD_DMA_CRPTEN_CTRL; |
| 9995 | |
| 9996 | val = tr32(tgtreg); |
| 9997 | tw32(tgtreg, val | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 9998 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | |
| 9999 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); |
| 10000 | } |
| 10001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10002 | /* Receive/send statistics. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10003 | if (tg3_flag(tp, 5750_PLUS)) { |
Michael Chan | 1661394 | 2006-06-29 20:15:13 -0700 | [diff] [blame] | 10004 | val = tr32(RCVLPC_STATS_ENABLE); |
| 10005 | val &= ~RCVLPC_STATSENAB_DACK_FIX; |
| 10006 | tw32(RCVLPC_STATS_ENABLE, val); |
| 10007 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10008 | tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10009 | val = tr32(RCVLPC_STATS_ENABLE); |
| 10010 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; |
| 10011 | tw32(RCVLPC_STATS_ENABLE, val); |
| 10012 | } else { |
| 10013 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); |
| 10014 | } |
| 10015 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); |
| 10016 | tw32(SNDDATAI_STATSENAB, 0xffffff); |
| 10017 | tw32(SNDDATAI_STATSCTRL, |
| 10018 | (SNDDATAI_SCTRL_ENABLE | |
| 10019 | SNDDATAI_SCTRL_FASTUPD)); |
| 10020 | |
| 10021 | /* Setup host coalescing engine. */ |
| 10022 | tw32(HOSTCC_MODE, 0); |
| 10023 | for (i = 0; i < 2000; i++) { |
| 10024 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) |
| 10025 | break; |
| 10026 | udelay(10); |
| 10027 | } |
| 10028 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 10029 | __tg3_set_coalesce(tp, &tp->coal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10030 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10031 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10032 | /* Status/statistics block address. See tg3_timer, |
| 10033 | * the tg3_periodic_fetch_stats call there, and |
| 10034 | * tg3_get_stats to see how this works for 5705/5750 chips. |
| 10035 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10036 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 10037 | ((u64) tp->stats_mapping >> 32)); |
| 10038 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 10039 | ((u64) tp->stats_mapping & 0xffffffff)); |
| 10040 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 10041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10042 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 10043 | |
| 10044 | /* Clear statistics and status block memory areas */ |
| 10045 | for (i = NIC_SRAM_STATS_BLK; |
| 10046 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; |
| 10047 | i += sizeof(u32)) { |
| 10048 | tg3_write_mem(tp, i, 0); |
| 10049 | udelay(40); |
| 10050 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10051 | } |
| 10052 | |
| 10053 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); |
| 10054 | |
| 10055 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); |
| 10056 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10057 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10058 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
| 10059 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10060 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
| 10061 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10062 | /* reset to prevent losing 1st rx packet intermittently */ |
| 10063 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 10064 | udelay(10); |
| 10065 | } |
| 10066 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 10067 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
Matt Carlson | 9e975cc | 2011-07-20 10:20:50 +0000 | [diff] [blame] | 10068 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | |
| 10069 | MAC_MODE_FHDE_ENABLE; |
| 10070 | if (tg3_flag(tp, ENABLE_APE)) |
| 10071 | 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] | 10072 | if (!tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10073 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10074 | tg3_asic_rev(tp) != ASIC_REV_5700) |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10075 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10076 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
| 10077 | udelay(40); |
| 10078 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 10079 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10080 | * If TG3_FLAG_IS_NIC is zero, we should read the |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 10081 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
| 10082 | * whether used as inputs or outputs, are set by boot code after |
| 10083 | * reset. |
| 10084 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10085 | if (!tg3_flag(tp, IS_NIC)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 10086 | u32 gpio_mask; |
| 10087 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 10088 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
| 10089 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 10090 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 10091 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10092 | if (tg3_asic_rev(tp) == ASIC_REV_5752) |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 10093 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
| 10094 | GRC_LCLCTRL_GPIO_OUTPUT3; |
| 10095 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10096 | if (tg3_asic_rev(tp) == ASIC_REV_5755) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 10097 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 10098 | |
Gary Zambrano | aaf8446 | 2007-05-05 11:51:45 -0700 | [diff] [blame] | 10099 | tp->grc_local_ctrl &= ~gpio_mask; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 10100 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
| 10101 | |
| 10102 | /* GPIO1 must be driven high for eeprom write protect */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10103 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 10104 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 10105 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 10106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10107 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 10108 | udelay(100); |
| 10109 | |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 10110 | if (tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 10111 | val = tr32(MSGINT_MODE); |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 10112 | val |= MSGINT_MODE_ENABLE; |
| 10113 | if (tp->irq_cnt > 1) |
| 10114 | val |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 10115 | if (!tg3_flag(tp, 1SHOT_MSI)) |
| 10116 | val |= MSGINT_MODE_ONE_SHOT_DISABLE; |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 10117 | tw32(MSGINT_MODE, val); |
| 10118 | } |
| 10119 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10120 | if (!tg3_flag(tp, 5705_PLUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10121 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
| 10122 | udelay(40); |
| 10123 | } |
| 10124 | |
| 10125 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | |
| 10126 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | |
| 10127 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | |
| 10128 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | |
| 10129 | WDMAC_MODE_LNGREAD_ENAB); |
| 10130 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10131 | if (tg3_asic_rev(tp) == ASIC_REV_5705 && |
| 10132 | tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10133 | if (tg3_flag(tp, TSO_CAPABLE) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10134 | (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A1 || |
| 10135 | tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10136 | /* nothing */ |
| 10137 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10138 | !tg3_flag(tp, IS_5788)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10139 | val |= WDMAC_MODE_RX_ACCEL; |
| 10140 | } |
| 10141 | } |
| 10142 | |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 10143 | /* Enable host coalescing bug fix */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10144 | if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 10145 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 10146 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10147 | if (tg3_asic_rev(tp) == ASIC_REV_5785) |
Matt Carlson | 788a035 | 2009-11-02 14:26:03 +0000 | [diff] [blame] | 10148 | val |= WDMAC_MODE_BURST_ALL_DATA; |
| 10149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10150 | tw32_f(WDMAC_MODE, val); |
| 10151 | udelay(40); |
| 10152 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10153 | if (tg3_flag(tp, PCIX_MODE)) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 10154 | u16 pcix_cmd; |
| 10155 | |
| 10156 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 10157 | &pcix_cmd); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10158 | if (tg3_asic_rev(tp) == ASIC_REV_5703) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 10159 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
| 10160 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10161 | } else if (tg3_asic_rev(tp) == ASIC_REV_5704) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 10162 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
| 10163 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10164 | } |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 10165 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 10166 | pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10167 | } |
| 10168 | |
| 10169 | tw32_f(RDMAC_MODE, rdmac_mode); |
| 10170 | udelay(40); |
| 10171 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10172 | if (tg3_asic_rev(tp) == ASIC_REV_5719) { |
Michael Chan | 091f0ea | 2012-07-29 19:15:43 +0000 | [diff] [blame] | 10173 | for (i = 0; i < TG3_NUM_RDMA_CHANNELS; i++) { |
| 10174 | if (tr32(TG3_RDMA_LENGTH + (i << 2)) > TG3_MAX_MTU(tp)) |
| 10175 | break; |
| 10176 | } |
| 10177 | if (i < TG3_NUM_RDMA_CHANNELS) { |
| 10178 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 10179 | val |= TG3_LSO_RD_DMA_TX_LENGTH_WA; |
| 10180 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val); |
| 10181 | tg3_flag_set(tp, 5719_RDMA_BUG); |
| 10182 | } |
| 10183 | } |
| 10184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10185 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10186 | if (!tg3_flag(tp, 5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10187 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 10188 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10189 | if (tg3_asic_rev(tp) == ASIC_REV_5761) |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 10190 | tw32(SNDDATAC_MODE, |
| 10191 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); |
| 10192 | else |
| 10193 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); |
| 10194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10195 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
| 10196 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 10197 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10198 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 10199 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
| 10200 | tw32(RCVDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10201 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10202 | if (tg3_flag(tp, HW_TSO_1) || |
| 10203 | tg3_flag(tp, HW_TSO_2) || |
| 10204 | tg3_flag(tp, HW_TSO_3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10205 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 10206 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10207 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 10208 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
| 10209 | tw32(SNDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10210 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
| 10211 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10212 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10213 | err = tg3_load_5701_a0_firmware_fix(tp); |
| 10214 | if (err) |
| 10215 | return err; |
| 10216 | } |
| 10217 | |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 10218 | if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
| 10219 | /* Ignore any errors for the firmware download. If download |
| 10220 | * fails, the device will operate with EEE disabled |
| 10221 | */ |
| 10222 | tg3_load_57766_firmware(tp); |
| 10223 | } |
| 10224 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10225 | if (tg3_flag(tp, TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10226 | err = tg3_load_tso_firmware(tp); |
| 10227 | if (err) |
| 10228 | return err; |
| 10229 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10230 | |
| 10231 | tp->tx_mode = TX_MODE_ENABLE; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 10232 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10233 | if (tg3_flag(tp, 5755_PLUS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10234 | tg3_asic_rev(tp) == ASIC_REV_5906) |
Matt Carlson | b1d0521 | 2010-06-05 17:24:31 +0000 | [diff] [blame] | 10235 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 10236 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10237 | if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 10238 | tg3_asic_rev(tp) == ASIC_REV_5762) { |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 10239 | val = TX_MODE_JMB_FRM_LEN | TX_MODE_CNT_DN_MODE; |
| 10240 | tp->tx_mode &= ~val; |
| 10241 | tp->tx_mode |= tr32(MAC_TX_MODE) & val; |
| 10242 | } |
| 10243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10244 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 10245 | udelay(100); |
| 10246 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10247 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 10248 | tg3_rss_write_indir_tbl(tp); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 10249 | |
| 10250 | /* Setup the "secret" hash key. */ |
| 10251 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); |
| 10252 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); |
| 10253 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); |
| 10254 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); |
| 10255 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); |
| 10256 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); |
| 10257 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); |
| 10258 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); |
| 10259 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); |
| 10260 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); |
| 10261 | } |
| 10262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10263 | tp->rx_mode = RX_MODE_ENABLE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10264 | if (tg3_flag(tp, 5755_PLUS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 10265 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
| 10266 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10267 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 10268 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
| 10269 | RX_MODE_RSS_ITBL_HASH_BITS_7 | |
| 10270 | RX_MODE_RSS_IPV6_HASH_EN | |
| 10271 | RX_MODE_RSS_TCP_IPV6_HASH_EN | |
| 10272 | RX_MODE_RSS_IPV4_HASH_EN | |
| 10273 | RX_MODE_RSS_TCP_IPV4_HASH_EN; |
| 10274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10275 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 10276 | udelay(10); |
| 10277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10278 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 10279 | |
| 10280 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10281 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10282 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 10283 | udelay(10); |
| 10284 | } |
| 10285 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 10286 | udelay(10); |
| 10287 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10288 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10289 | if ((tg3_asic_rev(tp) == ASIC_REV_5704) && |
| 10290 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10291 | /* Set drive transmission level to 1.2V */ |
| 10292 | /* only if the signal pre-emphasis bit is not set */ |
| 10293 | val = tr32(MAC_SERDES_CFG); |
| 10294 | val &= 0xfffff000; |
| 10295 | val |= 0x880; |
| 10296 | tw32(MAC_SERDES_CFG, val); |
| 10297 | } |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10298 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5703_A1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10299 | tw32(MAC_SERDES_CFG, 0x616000); |
| 10300 | } |
| 10301 | |
| 10302 | /* Prevent chip from dropping frames when flow control |
| 10303 | * is enabled. |
| 10304 | */ |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 10305 | if (tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 10306 | val = 1; |
| 10307 | else |
| 10308 | val = 2; |
| 10309 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10310 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10311 | if (tg3_asic_rev(tp) == ASIC_REV_5704 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10312 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10313 | /* Use hardware link auto-negotiation */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10314 | tg3_flag_set(tp, HW_AUTONEG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10315 | } |
| 10316 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10317 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10318 | tg3_asic_rev(tp) == ASIC_REV_5714) { |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 10319 | u32 tmp; |
| 10320 | |
| 10321 | tmp = tr32(SERDES_RX_CTRL); |
| 10322 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); |
| 10323 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; |
| 10324 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; |
| 10325 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 10326 | } |
| 10327 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10328 | if (!tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 10329 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 10330 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10331 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 10332 | err = tg3_setup_phy(tp, false); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 10333 | if (err) |
| 10334 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10335 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10336 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 10337 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 10338 | u32 tmp; |
| 10339 | |
| 10340 | /* Clear CRC stats. */ |
| 10341 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { |
| 10342 | tg3_writephy(tp, MII_TG3_TEST1, |
| 10343 | tmp | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 10344 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 10345 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10346 | } |
| 10347 | } |
| 10348 | |
| 10349 | __tg3_set_rx_mode(tp->dev); |
| 10350 | |
| 10351 | /* Initialize receive rules. */ |
| 10352 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); |
| 10353 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 10354 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); |
| 10355 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 10356 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10357 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10358 | limit = 8; |
| 10359 | else |
| 10360 | limit = 16; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10361 | if (tg3_flag(tp, ENABLE_ASF)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10362 | limit -= 4; |
| 10363 | switch (limit) { |
| 10364 | case 16: |
| 10365 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); |
| 10366 | case 15: |
| 10367 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); |
| 10368 | case 14: |
| 10369 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); |
| 10370 | case 13: |
| 10371 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); |
| 10372 | case 12: |
| 10373 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); |
| 10374 | case 11: |
| 10375 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); |
| 10376 | case 10: |
| 10377 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); |
| 10378 | case 9: |
| 10379 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); |
| 10380 | case 8: |
| 10381 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); |
| 10382 | case 7: |
| 10383 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); |
| 10384 | case 6: |
| 10385 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); |
| 10386 | case 5: |
| 10387 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); |
| 10388 | case 4: |
| 10389 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ |
| 10390 | case 3: |
| 10391 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ |
| 10392 | case 2: |
| 10393 | case 1: |
| 10394 | |
| 10395 | default: |
| 10396 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 10397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10398 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10399 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | 9ce768e | 2007-10-11 19:49:11 -0700 | [diff] [blame] | 10400 | /* Write our heartbeat update interval to APE. */ |
| 10401 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, |
| 10402 | APE_HOST_HEARTBEAT_INT_DISABLE); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 10403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10404 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
| 10405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10406 | return 0; |
| 10407 | } |
| 10408 | |
| 10409 | /* Called at device open time to get the chip ready for |
| 10410 | * packet processing. Invoked with tp->lock held. |
| 10411 | */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 10412 | static int tg3_init_hw(struct tg3 *tp, bool reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10413 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10414 | tg3_switch_clocks(tp); |
| 10415 | |
| 10416 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 10417 | |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 10418 | return tg3_reset_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10419 | } |
| 10420 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 10421 | static void tg3_sd_scan_scratchpad(struct tg3 *tp, struct tg3_ocir *ocir) |
| 10422 | { |
| 10423 | int i; |
| 10424 | |
| 10425 | for (i = 0; i < TG3_SD_NUM_RECS; i++, ocir++) { |
| 10426 | u32 off = i * TG3_OCIR_LEN, len = TG3_OCIR_LEN; |
| 10427 | |
| 10428 | tg3_ape_scratchpad_read(tp, (u32 *) ocir, off, len); |
| 10429 | off += len; |
| 10430 | |
| 10431 | if (ocir->signature != TG3_OCIR_SIG_MAGIC || |
| 10432 | !(ocir->version_flags & TG3_OCIR_FLAG_ACTIVE)) |
| 10433 | memset(ocir, 0, TG3_OCIR_LEN); |
| 10434 | } |
| 10435 | } |
| 10436 | |
| 10437 | /* sysfs attributes for hwmon */ |
| 10438 | static ssize_t tg3_show_temp(struct device *dev, |
| 10439 | struct device_attribute *devattr, char *buf) |
| 10440 | { |
| 10441 | struct pci_dev *pdev = to_pci_dev(dev); |
| 10442 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 10443 | struct tg3 *tp = netdev_priv(netdev); |
| 10444 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 10445 | u32 temperature; |
| 10446 | |
| 10447 | spin_lock_bh(&tp->lock); |
| 10448 | tg3_ape_scratchpad_read(tp, &temperature, attr->index, |
| 10449 | sizeof(temperature)); |
| 10450 | spin_unlock_bh(&tp->lock); |
| 10451 | return sprintf(buf, "%u\n", temperature); |
| 10452 | } |
| 10453 | |
| 10454 | |
| 10455 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, tg3_show_temp, NULL, |
| 10456 | TG3_TEMP_SENSOR_OFFSET); |
| 10457 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, tg3_show_temp, NULL, |
| 10458 | TG3_TEMP_CAUTION_OFFSET); |
| 10459 | static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, tg3_show_temp, NULL, |
| 10460 | TG3_TEMP_MAX_OFFSET); |
| 10461 | |
| 10462 | static struct attribute *tg3_attributes[] = { |
| 10463 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 10464 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 10465 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 10466 | NULL |
| 10467 | }; |
| 10468 | |
| 10469 | static const struct attribute_group tg3_group = { |
| 10470 | .attrs = tg3_attributes, |
| 10471 | }; |
| 10472 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 10473 | static void tg3_hwmon_close(struct tg3 *tp) |
| 10474 | { |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 10475 | if (tp->hwmon_dev) { |
| 10476 | hwmon_device_unregister(tp->hwmon_dev); |
| 10477 | tp->hwmon_dev = NULL; |
| 10478 | sysfs_remove_group(&tp->pdev->dev.kobj, &tg3_group); |
| 10479 | } |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 10480 | } |
| 10481 | |
| 10482 | static void tg3_hwmon_open(struct tg3 *tp) |
| 10483 | { |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 10484 | int i, err; |
| 10485 | u32 size = 0; |
| 10486 | struct pci_dev *pdev = tp->pdev; |
| 10487 | struct tg3_ocir ocirs[TG3_SD_NUM_RECS]; |
| 10488 | |
| 10489 | tg3_sd_scan_scratchpad(tp, ocirs); |
| 10490 | |
| 10491 | for (i = 0; i < TG3_SD_NUM_RECS; i++) { |
| 10492 | if (!ocirs[i].src_data_length) |
| 10493 | continue; |
| 10494 | |
| 10495 | size += ocirs[i].src_hdr_length; |
| 10496 | size += ocirs[i].src_data_length; |
| 10497 | } |
| 10498 | |
| 10499 | if (!size) |
| 10500 | return; |
| 10501 | |
| 10502 | /* Register hwmon sysfs hooks */ |
| 10503 | err = sysfs_create_group(&pdev->dev.kobj, &tg3_group); |
| 10504 | if (err) { |
| 10505 | dev_err(&pdev->dev, "Cannot create sysfs group, aborting\n"); |
| 10506 | return; |
| 10507 | } |
| 10508 | |
| 10509 | tp->hwmon_dev = hwmon_device_register(&pdev->dev); |
| 10510 | if (IS_ERR(tp->hwmon_dev)) { |
| 10511 | tp->hwmon_dev = NULL; |
| 10512 | dev_err(&pdev->dev, "Cannot register hwmon device, aborting\n"); |
| 10513 | sysfs_remove_group(&pdev->dev.kobj, &tg3_group); |
| 10514 | } |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 10515 | } |
| 10516 | |
| 10517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10518 | #define TG3_STAT_ADD32(PSTAT, REG) \ |
| 10519 | do { u32 __val = tr32(REG); \ |
| 10520 | (PSTAT)->low += __val; \ |
| 10521 | if ((PSTAT)->low < __val) \ |
| 10522 | (PSTAT)->high += 1; \ |
| 10523 | } while (0) |
| 10524 | |
| 10525 | static void tg3_periodic_fetch_stats(struct tg3 *tp) |
| 10526 | { |
| 10527 | struct tg3_hw_stats *sp = tp->hw_stats; |
| 10528 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 10529 | if (!tp->link_up) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10530 | return; |
| 10531 | |
| 10532 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); |
| 10533 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); |
| 10534 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); |
| 10535 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); |
| 10536 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); |
| 10537 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); |
| 10538 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); |
| 10539 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); |
| 10540 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); |
| 10541 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); |
| 10542 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); |
| 10543 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); |
| 10544 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); |
Michael Chan | 091f0ea | 2012-07-29 19:15:43 +0000 | [diff] [blame] | 10545 | if (unlikely(tg3_flag(tp, 5719_RDMA_BUG) && |
| 10546 | (sp->tx_ucast_packets.low + sp->tx_mcast_packets.low + |
| 10547 | sp->tx_bcast_packets.low) > TG3_NUM_RDMA_CHANNELS)) { |
| 10548 | u32 val; |
| 10549 | |
| 10550 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 10551 | val &= ~TG3_LSO_RD_DMA_TX_LENGTH_WA; |
| 10552 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val); |
| 10553 | tg3_flag_clear(tp, 5719_RDMA_BUG); |
| 10554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10555 | |
| 10556 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); |
| 10557 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); |
| 10558 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); |
| 10559 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); |
| 10560 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); |
| 10561 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); |
| 10562 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); |
| 10563 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); |
| 10564 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); |
| 10565 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); |
| 10566 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); |
| 10567 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); |
| 10568 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); |
| 10569 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 10570 | |
| 10571 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10572 | if (tg3_asic_rev(tp) != ASIC_REV_5717 && |
| 10573 | tg3_chip_rev_id(tp) != CHIPREV_ID_5719_A0 && |
| 10574 | tg3_chip_rev_id(tp) != CHIPREV_ID_5720_A0) { |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 10575 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
| 10576 | } else { |
| 10577 | u32 val = tr32(HOSTCC_FLOW_ATTN); |
| 10578 | val = (val & HOSTCC_FLOW_ATTN_MBUF_LWM) ? 1 : 0; |
| 10579 | if (val) { |
| 10580 | tw32(HOSTCC_FLOW_ATTN, HOSTCC_FLOW_ATTN_MBUF_LWM); |
| 10581 | sp->rx_discards.low += val; |
| 10582 | if (sp->rx_discards.low < val) |
| 10583 | sp->rx_discards.high += 1; |
| 10584 | } |
| 10585 | sp->mbuf_lwm_thresh_hit = sp->rx_discards; |
| 10586 | } |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 10587 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10588 | } |
| 10589 | |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 10590 | static void tg3_chk_missed_msi(struct tg3 *tp) |
| 10591 | { |
| 10592 | u32 i; |
| 10593 | |
| 10594 | for (i = 0; i < tp->irq_cnt; i++) { |
| 10595 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 10596 | |
| 10597 | if (tg3_has_work(tnapi)) { |
| 10598 | if (tnapi->last_rx_cons == tnapi->rx_rcb_ptr && |
| 10599 | tnapi->last_tx_cons == tnapi->tx_cons) { |
| 10600 | if (tnapi->chk_msi_cnt < 1) { |
| 10601 | tnapi->chk_msi_cnt++; |
| 10602 | return; |
| 10603 | } |
Matt Carlson | 7f23073 | 2011-08-31 11:44:48 +0000 | [diff] [blame] | 10604 | tg3_msi(0, tnapi); |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 10605 | } |
| 10606 | } |
| 10607 | tnapi->chk_msi_cnt = 0; |
| 10608 | tnapi->last_rx_cons = tnapi->rx_rcb_ptr; |
| 10609 | tnapi->last_tx_cons = tnapi->tx_cons; |
| 10610 | } |
| 10611 | } |
| 10612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10613 | static void tg3_timer(unsigned long __opaque) |
| 10614 | { |
| 10615 | struct tg3 *tp = (struct tg3 *) __opaque; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10616 | |
Matt Carlson | 5b19062 | 2011-11-04 09:15:04 +0000 | [diff] [blame] | 10617 | if (tp->irq_sync || tg3_flag(tp, RESET_TASK_PENDING)) |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 10618 | goto restart_timer; |
| 10619 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10620 | spin_lock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10621 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10622 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 10623 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 0e6cf6a | 2011-06-13 13:38:55 +0000 | [diff] [blame] | 10624 | tg3_chk_missed_msi(tp); |
| 10625 | |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 10626 | if (tg3_flag(tp, FLUSH_POSTED_WRITES)) { |
| 10627 | /* BCM4785: Flush posted writes from GbE to host memory. */ |
| 10628 | tr32(HOSTCC_MODE); |
| 10629 | } |
| 10630 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10631 | if (!tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10632 | /* All of this garbage is because when using non-tagged |
| 10633 | * IRQ status the mailbox/status_block protocol the chip |
| 10634 | * uses with the cpu is race prone. |
| 10635 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10636 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10637 | tw32(GRC_LOCAL_CTRL, |
| 10638 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 10639 | } else { |
| 10640 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10641 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10642 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10643 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10644 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10645 | spin_unlock(&tp->lock); |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 10646 | tg3_reset_task_schedule(tp); |
Matt Carlson | 5b19062 | 2011-11-04 09:15:04 +0000 | [diff] [blame] | 10647 | goto restart_timer; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10649 | } |
| 10650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10651 | /* This part only runs once per second. */ |
| 10652 | if (!--tp->timer_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10653 | if (tg3_flag(tp, 5705_PLUS)) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 10654 | tg3_periodic_fetch_stats(tp); |
| 10655 | |
Matt Carlson | b0c5943 | 2011-05-19 12:12:48 +0000 | [diff] [blame] | 10656 | if (tp->setlpicnt && !--tp->setlpicnt) |
| 10657 | tg3_phy_eee_enable(tp); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 10658 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10659 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10660 | u32 mac_stat; |
| 10661 | int phy_event; |
| 10662 | |
| 10663 | mac_stat = tr32(MAC_STATUS); |
| 10664 | |
| 10665 | phy_event = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10666 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10667 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
| 10668 | phy_event = 1; |
| 10669 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) |
| 10670 | phy_event = 1; |
| 10671 | |
| 10672 | if (phy_event) |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 10673 | tg3_setup_phy(tp, false); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10674 | } else if (tg3_flag(tp, POLL_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10675 | u32 mac_stat = tr32(MAC_STATUS); |
| 10676 | int need_setup = 0; |
| 10677 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 10678 | if (tp->link_up && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10679 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
| 10680 | need_setup = 1; |
| 10681 | } |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 10682 | if (!tp->link_up && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10683 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
| 10684 | MAC_STATUS_SIGNAL_DET))) { |
| 10685 | need_setup = 1; |
| 10686 | } |
| 10687 | if (need_setup) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 10688 | if (!tp->serdes_counter) { |
| 10689 | tw32_f(MAC_MODE, |
| 10690 | (tp->mac_mode & |
| 10691 | ~MAC_MODE_PORT_MODE_MASK)); |
| 10692 | udelay(40); |
| 10693 | tw32_f(MAC_MODE, tp->mac_mode); |
| 10694 | udelay(40); |
| 10695 | } |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 10696 | tg3_setup_phy(tp, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10697 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10698 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10699 | tg3_flag(tp, 5780_CLASS)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 10700 | tg3_serdes_parallel_detect(tp); |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 10701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10702 | |
| 10703 | tp->timer_counter = tp->timer_multiplier; |
| 10704 | } |
| 10705 | |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 10706 | /* Heartbeat is only sent once every 2 seconds. |
| 10707 | * |
| 10708 | * The heartbeat is to tell the ASF firmware that the host |
| 10709 | * driver is still alive. In the event that the OS crashes, |
| 10710 | * ASF needs to reset the hardware to free up the FIFO space |
| 10711 | * that may be filled with rx packets destined for the host. |
| 10712 | * If the FIFO is full, ASF will no longer function properly. |
| 10713 | * |
| 10714 | * Unintended resets have been reported on real time kernels |
| 10715 | * where the timer doesn't run on time. Netpoll will also have |
| 10716 | * same problem. |
| 10717 | * |
| 10718 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware |
| 10719 | * to check the ring condition when the heartbeat is expiring |
| 10720 | * before doing the reset. This will prevent most unintended |
| 10721 | * resets. |
| 10722 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10723 | if (!--tp->asf_counter) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10724 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 10725 | tg3_wait_for_event_ack(tp); |
| 10726 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 10727 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 10728 | FWCMD_NICDRV_ALIVE3); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 10729 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10730 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
| 10731 | TG3_FW_UPDATE_TIMEOUT_SEC); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 10732 | |
| 10733 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10734 | } |
| 10735 | tp->asf_counter = tp->asf_multiplier; |
| 10736 | } |
| 10737 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10738 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10739 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 10740 | restart_timer: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10741 | tp->timer.expires = jiffies + tp->timer_offset; |
| 10742 | add_timer(&tp->timer); |
| 10743 | } |
| 10744 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 10745 | static void tg3_timer_init(struct tg3 *tp) |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10746 | { |
| 10747 | if (tg3_flag(tp, TAGGED_STATUS) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 10748 | tg3_asic_rev(tp) != ASIC_REV_5717 && |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10749 | !tg3_flag(tp, 57765_CLASS)) |
| 10750 | tp->timer_offset = HZ; |
| 10751 | else |
| 10752 | tp->timer_offset = HZ / 10; |
| 10753 | |
| 10754 | BUG_ON(tp->timer_offset > HZ); |
| 10755 | |
| 10756 | tp->timer_multiplier = (HZ / tp->timer_offset); |
| 10757 | tp->asf_multiplier = (HZ / tp->timer_offset) * |
| 10758 | TG3_FW_UPDATE_FREQ_SEC; |
| 10759 | |
| 10760 | init_timer(&tp->timer); |
| 10761 | tp->timer.data = (unsigned long) tp; |
| 10762 | tp->timer.function = tg3_timer; |
| 10763 | } |
| 10764 | |
| 10765 | static void tg3_timer_start(struct tg3 *tp) |
| 10766 | { |
| 10767 | tp->asf_counter = tp->asf_multiplier; |
| 10768 | tp->timer_counter = tp->timer_multiplier; |
| 10769 | |
| 10770 | tp->timer.expires = jiffies + tp->timer_offset; |
| 10771 | add_timer(&tp->timer); |
| 10772 | } |
| 10773 | |
| 10774 | static void tg3_timer_stop(struct tg3 *tp) |
| 10775 | { |
| 10776 | del_timer_sync(&tp->timer); |
| 10777 | } |
| 10778 | |
| 10779 | /* Restart hardware after configuration changes, self-test, etc. |
| 10780 | * Invoked with tp->lock held. |
| 10781 | */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 10782 | static int tg3_restart_hw(struct tg3 *tp, bool reset_phy) |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10783 | __releases(tp->lock) |
| 10784 | __acquires(tp->lock) |
| 10785 | { |
| 10786 | int err; |
| 10787 | |
| 10788 | err = tg3_init_hw(tp, reset_phy); |
| 10789 | if (err) { |
| 10790 | netdev_err(tp->dev, |
| 10791 | "Failed to re-initialize device, aborting\n"); |
| 10792 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 10793 | tg3_full_unlock(tp); |
| 10794 | tg3_timer_stop(tp); |
| 10795 | tp->irq_sync = 0; |
| 10796 | tg3_napi_enable(tp); |
| 10797 | dev_close(tp->dev); |
| 10798 | tg3_full_lock(tp, 0); |
| 10799 | } |
| 10800 | return err; |
| 10801 | } |
| 10802 | |
| 10803 | static void tg3_reset_task(struct work_struct *work) |
| 10804 | { |
| 10805 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
| 10806 | int err; |
| 10807 | |
| 10808 | tg3_full_lock(tp, 0); |
| 10809 | |
| 10810 | if (!netif_running(tp->dev)) { |
| 10811 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 10812 | tg3_full_unlock(tp); |
| 10813 | return; |
| 10814 | } |
| 10815 | |
| 10816 | tg3_full_unlock(tp); |
| 10817 | |
| 10818 | tg3_phy_stop(tp); |
| 10819 | |
| 10820 | tg3_netif_stop(tp); |
| 10821 | |
| 10822 | tg3_full_lock(tp, 1); |
| 10823 | |
| 10824 | if (tg3_flag(tp, TX_RECOVERY_PENDING)) { |
| 10825 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 10826 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 10827 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
| 10828 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
| 10829 | } |
| 10830 | |
| 10831 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 10832 | err = tg3_init_hw(tp, true); |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 10833 | if (err) |
| 10834 | goto out; |
| 10835 | |
| 10836 | tg3_netif_start(tp); |
| 10837 | |
| 10838 | out: |
| 10839 | tg3_full_unlock(tp); |
| 10840 | |
| 10841 | if (!err) |
| 10842 | tg3_phy_start(tp); |
| 10843 | |
| 10844 | tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 10845 | } |
| 10846 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10847 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10848 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 10849 | irq_handler_t fn; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10850 | unsigned long flags; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10851 | char *name; |
| 10852 | struct tg3_napi *tnapi = &tp->napi[irq_num]; |
| 10853 | |
| 10854 | if (tp->irq_cnt == 1) |
| 10855 | name = tp->dev->name; |
| 10856 | else { |
| 10857 | name = &tnapi->irq_lbl[0]; |
| 10858 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); |
| 10859 | name[IFNAMSIZ-1] = 0; |
| 10860 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10861 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10862 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10863 | fn = tg3_msi; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10864 | if (tg3_flag(tp, 1SHOT_MSI)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10865 | fn = tg3_msi_1shot; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 10866 | flags = 0; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10867 | } else { |
| 10868 | fn = tg3_interrupt; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10869 | if (tg3_flag(tp, TAGGED_STATUS)) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10870 | fn = tg3_interrupt_tagged; |
Javier Martinez Canillas | ab392d2 | 2011-03-28 16:27:31 +0000 | [diff] [blame] | 10871 | flags = IRQF_SHARED; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10872 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10873 | |
| 10874 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 10875 | } |
| 10876 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10877 | static int tg3_test_interrupt(struct tg3 *tp) |
| 10878 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 10879 | struct tg3_napi *tnapi = &tp->napi[0]; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10880 | struct net_device *dev = tp->dev; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10881 | int err, i, intr_ok = 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10882 | u32 val; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10883 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 10884 | if (!netif_running(dev)) |
| 10885 | return -ENODEV; |
| 10886 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10887 | tg3_disable_ints(tp); |
| 10888 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10889 | free_irq(tnapi->irq_vec, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10890 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10891 | /* |
| 10892 | * Turn off MSI one shot mode. Otherwise this test has no |
| 10893 | * observable way to know whether the interrupt was delivered. |
| 10894 | */ |
Matt Carlson | 3aa1cdf | 2011-07-20 10:20:55 +0000 | [diff] [blame] | 10895 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10896 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
| 10897 | tw32(MSGINT_MODE, val); |
| 10898 | } |
| 10899 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10900 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
Davidlohr Bueso | f274fd9 | 2012-02-22 03:06:54 +0000 | [diff] [blame] | 10901 | IRQF_SHARED, dev->name, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10902 | if (err) |
| 10903 | return err; |
| 10904 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10905 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10906 | tg3_enable_ints(tp); |
| 10907 | |
| 10908 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10909 | tnapi->coal_now); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10910 | |
| 10911 | for (i = 0; i < 5; i++) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10912 | u32 int_mbox, misc_host_ctrl; |
| 10913 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10914 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10915 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 10916 | |
| 10917 | if ((int_mbox != 0) || |
| 10918 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { |
| 10919 | intr_ok = 1; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10920 | break; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10921 | } |
| 10922 | |
Matt Carlson | 3aa1cdf | 2011-07-20 10:20:55 +0000 | [diff] [blame] | 10923 | if (tg3_flag(tp, 57765_PLUS) && |
| 10924 | tnapi->hw_status->status_tag != tnapi->last_tag) |
| 10925 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 10926 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10927 | msleep(10); |
| 10928 | } |
| 10929 | |
| 10930 | tg3_disable_ints(tp); |
| 10931 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10932 | free_irq(tnapi->irq_vec, tnapi); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10933 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10934 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10935 | |
| 10936 | if (err) |
| 10937 | return err; |
| 10938 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10939 | if (intr_ok) { |
| 10940 | /* Reenable MSI one shot mode. */ |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 10941 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, 1SHOT_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10942 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
| 10943 | tw32(MSGINT_MODE, val); |
| 10944 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10945 | return 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 10946 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10947 | |
| 10948 | return -EIO; |
| 10949 | } |
| 10950 | |
| 10951 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is |
| 10952 | * successfully restored |
| 10953 | */ |
| 10954 | static int tg3_test_msi(struct tg3 *tp) |
| 10955 | { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10956 | int err; |
| 10957 | u16 pci_cmd; |
| 10958 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10959 | if (!tg3_flag(tp, USING_MSI)) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10960 | return 0; |
| 10961 | |
| 10962 | /* Turn off SERR reporting in case MSI terminates with Master |
| 10963 | * Abort. |
| 10964 | */ |
| 10965 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 10966 | pci_write_config_word(tp->pdev, PCI_COMMAND, |
| 10967 | pci_cmd & ~PCI_COMMAND_SERR); |
| 10968 | |
| 10969 | err = tg3_test_interrupt(tp); |
| 10970 | |
| 10971 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 10972 | |
| 10973 | if (!err) |
| 10974 | return 0; |
| 10975 | |
| 10976 | /* other failures */ |
| 10977 | if (err != -EIO) |
| 10978 | return err; |
| 10979 | |
| 10980 | /* MSI test failed, go back to INTx mode */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 10981 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
| 10982 | "to INTx mode. Please report this failure to the PCI " |
| 10983 | "maintainer and include system chipset information\n"); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10984 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10985 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 10986 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10987 | pci_disable_msi(tp->pdev); |
| 10988 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 10989 | tg3_flag_clear(tp, USING_MSI); |
Andre Detsch | dc8bf1b | 2010-04-26 07:27:07 +0000 | [diff] [blame] | 10990 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10991 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 10992 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 10993 | if (err) |
| 10994 | return err; |
| 10995 | |
| 10996 | /* Need to reset the chip because the MSI cycle may have terminated |
| 10997 | * with Master Abort. |
| 10998 | */ |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10999 | tg3_full_lock(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 11000 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 11001 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 11002 | err = tg3_init_hw(tp, true); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 11003 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11004 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 11005 | |
| 11006 | if (err) |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 11007 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 11008 | |
| 11009 | return err; |
| 11010 | } |
| 11011 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 11012 | static int tg3_request_firmware(struct tg3 *tp) |
| 11013 | { |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 11014 | const struct tg3_firmware_hdr *fw_hdr; |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 11015 | |
| 11016 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 11017 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
| 11018 | tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 11019 | return -ENOENT; |
| 11020 | } |
| 11021 | |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 11022 | fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 11023 | |
| 11024 | /* Firmware blob starts with version numbers, followed by |
| 11025 | * start address and _full_ length including BSS sections |
| 11026 | * (which must be longer than the actual data, of course |
| 11027 | */ |
| 11028 | |
Nithin Sujir | 77997ea | 2013-03-06 17:02:32 +0000 | [diff] [blame] | 11029 | tp->fw_len = be32_to_cpu(fw_hdr->len); /* includes bss */ |
| 11030 | if (tp->fw_len < (tp->fw->size - TG3_FW_HDR_LEN)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 11031 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
| 11032 | tp->fw_len, tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 11033 | release_firmware(tp->fw); |
| 11034 | tp->fw = NULL; |
| 11035 | return -EINVAL; |
| 11036 | } |
| 11037 | |
| 11038 | /* We no longer need firmware; we have it. */ |
| 11039 | tp->fw_needed = NULL; |
| 11040 | return 0; |
| 11041 | } |
| 11042 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11043 | static u32 tg3_irq_count(struct tg3 *tp) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11044 | { |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11045 | u32 irq_cnt = max(tp->rxq_cnt, tp->txq_cnt); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11046 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11047 | if (irq_cnt > 1) { |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 11048 | /* We want as many rx rings enabled as there are cpus. |
| 11049 | * In multiqueue MSI-X mode, the first MSI-X vector |
| 11050 | * only deals with link interrupts, etc, so we add |
| 11051 | * one to the number of vectors we are requesting. |
| 11052 | */ |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11053 | irq_cnt = min_t(unsigned, irq_cnt + 1, tp->irq_max); |
Matt Carlson | c3b5003 | 2012-01-17 15:27:23 +0000 | [diff] [blame] | 11054 | } |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11055 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11056 | return irq_cnt; |
| 11057 | } |
| 11058 | |
| 11059 | static bool tg3_enable_msix(struct tg3 *tp) |
| 11060 | { |
| 11061 | int i, rc; |
Michael Chan | 8644994 | 2012-10-02 20:31:14 -0700 | [diff] [blame] | 11062 | struct msix_entry msix_ent[TG3_IRQ_MAX_VECS]; |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11063 | |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 11064 | tp->txq_cnt = tp->txq_req; |
| 11065 | tp->rxq_cnt = tp->rxq_req; |
| 11066 | if (!tp->rxq_cnt) |
| 11067 | tp->rxq_cnt = netif_get_num_default_rss_queues(); |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11068 | if (tp->rxq_cnt > tp->rxq_max) |
| 11069 | tp->rxq_cnt = tp->rxq_max; |
Michael Chan | cf6d6ea | 2012-09-28 07:12:43 +0000 | [diff] [blame] | 11070 | |
| 11071 | /* Disable multiple TX rings by default. Simple round-robin hardware |
| 11072 | * scheduling of the TX rings can cause starvation of rings with |
| 11073 | * small packets when other rings have TSO or jumbo packets. |
| 11074 | */ |
| 11075 | if (!tp->txq_req) |
| 11076 | tp->txq_cnt = 1; |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11077 | |
| 11078 | tp->irq_cnt = tg3_irq_count(tp); |
| 11079 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11080 | for (i = 0; i < tp->irq_max; i++) { |
| 11081 | msix_ent[i].entry = i; |
| 11082 | msix_ent[i].vector = 0; |
| 11083 | } |
| 11084 | |
| 11085 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 11086 | if (rc < 0) { |
| 11087 | return false; |
| 11088 | } else if (rc != 0) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11089 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
| 11090 | return false; |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 11091 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
| 11092 | tp->irq_cnt, rc); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11093 | tp->irq_cnt = rc; |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 11094 | tp->rxq_cnt = max(rc - 1, 1); |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11095 | if (tp->txq_cnt) |
| 11096 | tp->txq_cnt = min(tp->rxq_cnt, tp->txq_max); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11097 | } |
| 11098 | |
| 11099 | for (i = 0; i < tp->irq_max; i++) |
| 11100 | tp->napi[i].irq_vec = msix_ent[i].vector; |
| 11101 | |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 11102 | if (netif_set_real_num_rx_queues(tp->dev, tp->rxq_cnt)) { |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 11103 | pci_disable_msix(tp->pdev); |
| 11104 | return false; |
| 11105 | } |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 11106 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11107 | if (tp->irq_cnt == 1) |
| 11108 | return true; |
Matt Carlson | d78b59f | 2011-04-05 14:22:46 +0000 | [diff] [blame] | 11109 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 11110 | tg3_flag_set(tp, ENABLE_RSS); |
| 11111 | |
| 11112 | if (tp->txq_cnt > 1) |
| 11113 | tg3_flag_set(tp, ENABLE_TSS); |
| 11114 | |
| 11115 | netif_set_real_num_tx_queues(tp->dev, tp->txq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 11116 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11117 | return true; |
| 11118 | } |
| 11119 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11120 | static void tg3_ints_init(struct tg3 *tp) |
| 11121 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11122 | if ((tg3_flag(tp, SUPPORT_MSI) || tg3_flag(tp, SUPPORT_MSIX)) && |
| 11123 | !tg3_flag(tp, TAGGED_STATUS)) { |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11124 | /* All MSI supporting chips should support tagged |
| 11125 | * status. Assert that this is the case. |
| 11126 | */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 11127 | netdev_warn(tp->dev, |
| 11128 | "MSI without TAGGED_STATUS? Not using MSI\n"); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11129 | goto defcfg; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11130 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 11131 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11132 | if (tg3_flag(tp, SUPPORT_MSIX) && tg3_enable_msix(tp)) |
| 11133 | tg3_flag_set(tp, USING_MSIX); |
| 11134 | else if (tg3_flag(tp, SUPPORT_MSI) && pci_enable_msi(tp->pdev) == 0) |
| 11135 | tg3_flag_set(tp, USING_MSI); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11136 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11137 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11138 | u32 msi_mode = tr32(MSGINT_MODE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11139 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 11140 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 5b39de9 | 2011-08-31 11:44:50 +0000 | [diff] [blame] | 11141 | if (!tg3_flag(tp, 1SHOT_MSI)) |
| 11142 | msi_mode |= MSGINT_MODE_ONE_SHOT_DISABLE; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11143 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
| 11144 | } |
| 11145 | defcfg: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11146 | if (!tg3_flag(tp, USING_MSIX)) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11147 | tp->irq_cnt = 1; |
| 11148 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 49a359e | 2012-09-28 07:12:37 +0000 | [diff] [blame] | 11149 | } |
| 11150 | |
| 11151 | if (tp->irq_cnt == 1) { |
| 11152 | tp->txq_cnt = 1; |
| 11153 | tp->rxq_cnt = 1; |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 11154 | netif_set_real_num_tx_queues(tp->dev, 1); |
Matt Carlson | 8540788 | 2010-10-06 13:40:58 -0700 | [diff] [blame] | 11155 | netif_set_real_num_rx_queues(tp->dev, 1); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11156 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11157 | } |
| 11158 | |
| 11159 | static void tg3_ints_fini(struct tg3 *tp) |
| 11160 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11161 | if (tg3_flag(tp, USING_MSIX)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11162 | pci_disable_msix(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11163 | else if (tg3_flag(tp, USING_MSI)) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11164 | pci_disable_msi(tp->pdev); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11165 | tg3_flag_clear(tp, USING_MSI); |
| 11166 | tg3_flag_clear(tp, USING_MSIX); |
| 11167 | tg3_flag_clear(tp, ENABLE_RSS); |
| 11168 | tg3_flag_clear(tp, ENABLE_TSS); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11169 | } |
| 11170 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 11171 | static int tg3_start(struct tg3 *tp, bool reset_phy, bool test_irq, |
| 11172 | bool init) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11173 | { |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 11174 | struct net_device *dev = tp->dev; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 11175 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11176 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11177 | /* |
| 11178 | * Setup interrupts first so we know how |
| 11179 | * many NAPI resources to allocate |
| 11180 | */ |
| 11181 | tg3_ints_init(tp); |
| 11182 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 11183 | tg3_rss_check_indir_tbl(tp); |
Matt Carlson | bcebcc4 | 2011-12-14 11:10:01 +0000 | [diff] [blame] | 11184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11185 | /* The placement of this call is tied |
| 11186 | * to the setup and use of Host TX descriptors. |
| 11187 | */ |
| 11188 | err = tg3_alloc_consistent(tp); |
| 11189 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11190 | goto err_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11191 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 11192 | tg3_napi_init(tp); |
| 11193 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 11194 | tg3_napi_enable(tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 11195 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 11196 | for (i = 0; i < tp->irq_cnt; i++) { |
| 11197 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 11198 | err = tg3_request_irq(tp, i); |
| 11199 | if (err) { |
Matt Carlson | 5bc0918 | 2011-11-04 09:15:01 +0000 | [diff] [blame] | 11200 | for (i--; i >= 0; i--) { |
| 11201 | tnapi = &tp->napi[i]; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 11202 | free_irq(tnapi->irq_vec, tnapi); |
Matt Carlson | 5bc0918 | 2011-11-04 09:15:01 +0000 | [diff] [blame] | 11203 | } |
| 11204 | goto err_out2; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 11205 | } |
| 11206 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11207 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11208 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11209 | |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 11210 | err = tg3_init_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11211 | if (err) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 11212 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11213 | tg3_free_rings(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11214 | } |
| 11215 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11216 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11217 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11218 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11219 | goto err_out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11220 | |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 11221 | if (test_irq && tg3_flag(tp, USING_MSI)) { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 11222 | err = tg3_test_msi(tp); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 11223 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 11224 | if (err) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11225 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 11226 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 11227 | tg3_free_rings(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11228 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 11229 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11230 | goto err_out2; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 11231 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 11232 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11233 | if (!tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 11234 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 11235 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 11236 | tw32(PCIE_TRANSACTION_CFG, |
| 11237 | val | PCIE_TRANS_CFG_1SHOT_MSI); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 11238 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 11239 | } |
| 11240 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11241 | tg3_phy_start(tp); |
| 11242 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 11243 | tg3_hwmon_open(tp); |
| 11244 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11245 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11246 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 11247 | tg3_timer_start(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11248 | tg3_flag_set(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11249 | tg3_enable_ints(tp); |
| 11250 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 11251 | if (init) |
| 11252 | tg3_ptp_init(tp); |
| 11253 | else |
| 11254 | tg3_ptp_resume(tp); |
| 11255 | |
| 11256 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11257 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11258 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 11259 | netif_tx_start_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11260 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 11261 | /* |
| 11262 | * Reset loopback feature if it was turned on while the device was down |
| 11263 | * make sure that it's installed properly now. |
| 11264 | */ |
| 11265 | if (dev->features & NETIF_F_LOOPBACK) |
| 11266 | tg3_set_loopback(dev, dev->features); |
| 11267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11268 | return 0; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11269 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11270 | err_out3: |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 11271 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 11272 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 11273 | free_irq(tnapi->irq_vec, tnapi); |
| 11274 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11275 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11276 | err_out2: |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 11277 | tg3_napi_disable(tp); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 11278 | tg3_napi_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11279 | tg3_free_consistent(tp); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 11280 | |
| 11281 | err_out1: |
| 11282 | tg3_ints_fini(tp); |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 11283 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11284 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11285 | } |
| 11286 | |
Michael Chan | 6513859 | 2012-09-28 07:12:41 +0000 | [diff] [blame] | 11287 | static void tg3_stop(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11288 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 11289 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11290 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 11291 | tg3_reset_task_cancel(tp); |
Nithin Nayak Sujir | bd473da | 2012-11-05 14:26:30 +0000 | [diff] [blame] | 11292 | tg3_netif_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11293 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 11294 | tg3_timer_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11295 | |
Michael Chan | aed93e0 | 2012-07-16 16:24:02 +0000 | [diff] [blame] | 11296 | tg3_hwmon_close(tp); |
| 11297 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 11298 | tg3_phy_stop(tp); |
| 11299 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11300 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11301 | |
| 11302 | tg3_disable_ints(tp); |
| 11303 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 11304 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11305 | tg3_free_rings(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11306 | tg3_flag_clear(tp, INIT_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11307 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11308 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11309 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 11310 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 11311 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 11312 | free_irq(tnapi->irq_vec, tnapi); |
| 11313 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 11314 | |
| 11315 | tg3_ints_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11316 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 11317 | tg3_napi_fini(tp); |
| 11318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11319 | tg3_free_consistent(tp); |
Michael Chan | 6513859 | 2012-09-28 07:12:41 +0000 | [diff] [blame] | 11320 | } |
| 11321 | |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 11322 | static int tg3_open(struct net_device *dev) |
| 11323 | { |
| 11324 | struct tg3 *tp = netdev_priv(dev); |
| 11325 | int err; |
| 11326 | |
| 11327 | if (tp->fw_needed) { |
| 11328 | err = tg3_request_firmware(tp); |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 11329 | if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
| 11330 | if (err) { |
| 11331 | netdev_warn(tp->dev, "EEE capability disabled\n"); |
| 11332 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; |
| 11333 | } else if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) { |
| 11334 | netdev_warn(tp->dev, "EEE capability restored\n"); |
| 11335 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 11336 | } |
| 11337 | } else if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0) { |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 11338 | if (err) |
| 11339 | return err; |
| 11340 | } else if (err) { |
| 11341 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
| 11342 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 11343 | } else if (!tg3_flag(tp, TSO_CAPABLE)) { |
| 11344 | netdev_notice(tp->dev, "TSO capability restored\n"); |
| 11345 | tg3_flag_set(tp, TSO_CAPABLE); |
| 11346 | } |
| 11347 | } |
| 11348 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 11349 | tg3_carrier_off(tp); |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 11350 | |
| 11351 | err = tg3_power_up(tp); |
| 11352 | if (err) |
| 11353 | return err; |
| 11354 | |
| 11355 | tg3_full_lock(tp, 0); |
| 11356 | |
| 11357 | tg3_disable_ints(tp); |
| 11358 | tg3_flag_clear(tp, INIT_COMPLETE); |
| 11359 | |
| 11360 | tg3_full_unlock(tp); |
| 11361 | |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 11362 | err = tg3_start(tp, |
| 11363 | !(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN), |
| 11364 | true, true); |
Michael Chan | d8f4cd3 | 2012-09-28 07:12:40 +0000 | [diff] [blame] | 11365 | if (err) { |
| 11366 | tg3_frob_aux_power(tp, false); |
| 11367 | pci_set_power_state(tp->pdev, PCI_D3hot); |
| 11368 | } |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 11369 | |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 11370 | if (tg3_flag(tp, PTP_CAPABLE)) { |
| 11371 | tp->ptp_clock = ptp_clock_register(&tp->ptp_info, |
| 11372 | &tp->pdev->dev); |
| 11373 | if (IS_ERR(tp->ptp_clock)) |
| 11374 | tp->ptp_clock = NULL; |
| 11375 | } |
| 11376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11377 | return err; |
| 11378 | } |
| 11379 | |
| 11380 | static int tg3_close(struct net_device *dev) |
| 11381 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11382 | struct tg3 *tp = netdev_priv(dev); |
| 11383 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 11384 | tg3_ptp_fini(tp); |
| 11385 | |
Michael Chan | 6513859 | 2012-09-28 07:12:41 +0000 | [diff] [blame] | 11386 | tg3_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11387 | |
| 11388 | /* Clear stats across close / open calls */ |
| 11389 | memset(&tp->net_stats_prev, 0, sizeof(tp->net_stats_prev)); |
| 11390 | memset(&tp->estats_prev, 0, sizeof(tp->estats_prev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11391 | |
| 11392 | tg3_power_down(tp); |
| 11393 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 11394 | tg3_carrier_off(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11395 | |
| 11396 | return 0; |
| 11397 | } |
| 11398 | |
| 11399 | static inline u64 get_stat64(tg3_stat64_t *val) |
| 11400 | { |
| 11401 | return ((u64)val->high << 32) | ((u64)val->low); |
| 11402 | } |
| 11403 | |
| 11404 | static u64 tg3_calc_crc_errors(struct tg3 *tp) |
| 11405 | { |
| 11406 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 11407 | |
| 11408 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 11409 | (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 11410 | tg3_asic_rev(tp) == ASIC_REV_5701)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11411 | u32 val; |
| 11412 | |
| 11413 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
| 11414 | tg3_writephy(tp, MII_TG3_TEST1, |
| 11415 | val | MII_TG3_TEST1_CRC_EN); |
| 11416 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
| 11417 | } else |
| 11418 | val = 0; |
| 11419 | |
| 11420 | tp->phy_crc_errors += val; |
| 11421 | |
| 11422 | return tp->phy_crc_errors; |
| 11423 | } |
| 11424 | |
| 11425 | return get_stat64(&hw_stats->rx_fcs_errors); |
| 11426 | } |
| 11427 | |
| 11428 | #define ESTAT_ADD(member) \ |
| 11429 | estats->member = old_estats->member + \ |
| 11430 | get_stat64(&hw_stats->member) |
| 11431 | |
| 11432 | static void tg3_get_estats(struct tg3 *tp, struct tg3_ethtool_stats *estats) |
| 11433 | { |
| 11434 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
| 11435 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 11436 | |
| 11437 | ESTAT_ADD(rx_octets); |
| 11438 | ESTAT_ADD(rx_fragments); |
| 11439 | ESTAT_ADD(rx_ucast_packets); |
| 11440 | ESTAT_ADD(rx_mcast_packets); |
| 11441 | ESTAT_ADD(rx_bcast_packets); |
| 11442 | ESTAT_ADD(rx_fcs_errors); |
| 11443 | ESTAT_ADD(rx_align_errors); |
| 11444 | ESTAT_ADD(rx_xon_pause_rcvd); |
| 11445 | ESTAT_ADD(rx_xoff_pause_rcvd); |
| 11446 | ESTAT_ADD(rx_mac_ctrl_rcvd); |
| 11447 | ESTAT_ADD(rx_xoff_entered); |
| 11448 | ESTAT_ADD(rx_frame_too_long_errors); |
| 11449 | ESTAT_ADD(rx_jabbers); |
| 11450 | ESTAT_ADD(rx_undersize_packets); |
| 11451 | ESTAT_ADD(rx_in_length_errors); |
| 11452 | ESTAT_ADD(rx_out_length_errors); |
| 11453 | ESTAT_ADD(rx_64_or_less_octet_packets); |
| 11454 | ESTAT_ADD(rx_65_to_127_octet_packets); |
| 11455 | ESTAT_ADD(rx_128_to_255_octet_packets); |
| 11456 | ESTAT_ADD(rx_256_to_511_octet_packets); |
| 11457 | ESTAT_ADD(rx_512_to_1023_octet_packets); |
| 11458 | ESTAT_ADD(rx_1024_to_1522_octet_packets); |
| 11459 | ESTAT_ADD(rx_1523_to_2047_octet_packets); |
| 11460 | ESTAT_ADD(rx_2048_to_4095_octet_packets); |
| 11461 | ESTAT_ADD(rx_4096_to_8191_octet_packets); |
| 11462 | ESTAT_ADD(rx_8192_to_9022_octet_packets); |
| 11463 | |
| 11464 | ESTAT_ADD(tx_octets); |
| 11465 | ESTAT_ADD(tx_collisions); |
| 11466 | ESTAT_ADD(tx_xon_sent); |
| 11467 | ESTAT_ADD(tx_xoff_sent); |
| 11468 | ESTAT_ADD(tx_flow_control); |
| 11469 | ESTAT_ADD(tx_mac_errors); |
| 11470 | ESTAT_ADD(tx_single_collisions); |
| 11471 | ESTAT_ADD(tx_mult_collisions); |
| 11472 | ESTAT_ADD(tx_deferred); |
| 11473 | ESTAT_ADD(tx_excessive_collisions); |
| 11474 | ESTAT_ADD(tx_late_collisions); |
| 11475 | ESTAT_ADD(tx_collide_2times); |
| 11476 | ESTAT_ADD(tx_collide_3times); |
| 11477 | ESTAT_ADD(tx_collide_4times); |
| 11478 | ESTAT_ADD(tx_collide_5times); |
| 11479 | ESTAT_ADD(tx_collide_6times); |
| 11480 | ESTAT_ADD(tx_collide_7times); |
| 11481 | ESTAT_ADD(tx_collide_8times); |
| 11482 | ESTAT_ADD(tx_collide_9times); |
| 11483 | ESTAT_ADD(tx_collide_10times); |
| 11484 | ESTAT_ADD(tx_collide_11times); |
| 11485 | ESTAT_ADD(tx_collide_12times); |
| 11486 | ESTAT_ADD(tx_collide_13times); |
| 11487 | ESTAT_ADD(tx_collide_14times); |
| 11488 | ESTAT_ADD(tx_collide_15times); |
| 11489 | ESTAT_ADD(tx_ucast_packets); |
| 11490 | ESTAT_ADD(tx_mcast_packets); |
| 11491 | ESTAT_ADD(tx_bcast_packets); |
| 11492 | ESTAT_ADD(tx_carrier_sense_errors); |
| 11493 | ESTAT_ADD(tx_discards); |
| 11494 | ESTAT_ADD(tx_errors); |
| 11495 | |
| 11496 | ESTAT_ADD(dma_writeq_full); |
| 11497 | ESTAT_ADD(dma_write_prioq_full); |
| 11498 | ESTAT_ADD(rxbds_empty); |
| 11499 | ESTAT_ADD(rx_discards); |
| 11500 | ESTAT_ADD(rx_errors); |
| 11501 | ESTAT_ADD(rx_threshold_hit); |
| 11502 | |
| 11503 | ESTAT_ADD(dma_readq_full); |
| 11504 | ESTAT_ADD(dma_read_prioq_full); |
| 11505 | ESTAT_ADD(tx_comp_queue_full); |
| 11506 | |
| 11507 | ESTAT_ADD(ring_set_send_prod_index); |
| 11508 | ESTAT_ADD(ring_status_update); |
| 11509 | ESTAT_ADD(nic_irqs); |
| 11510 | ESTAT_ADD(nic_avoided_irqs); |
| 11511 | ESTAT_ADD(nic_tx_threshold_hit); |
| 11512 | |
Matt Carlson | 4452d09 | 2011-05-19 12:12:51 +0000 | [diff] [blame] | 11513 | ESTAT_ADD(mbuf_lwm_thresh_hit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11514 | } |
| 11515 | |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 11516 | 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] | 11517 | { |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 11518 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11519 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 11520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11521 | stats->rx_packets = old_stats->rx_packets + |
| 11522 | get_stat64(&hw_stats->rx_ucast_packets) + |
| 11523 | get_stat64(&hw_stats->rx_mcast_packets) + |
| 11524 | get_stat64(&hw_stats->rx_bcast_packets); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11526 | stats->tx_packets = old_stats->tx_packets + |
| 11527 | get_stat64(&hw_stats->tx_ucast_packets) + |
| 11528 | get_stat64(&hw_stats->tx_mcast_packets) + |
| 11529 | get_stat64(&hw_stats->tx_bcast_packets); |
| 11530 | |
| 11531 | stats->rx_bytes = old_stats->rx_bytes + |
| 11532 | get_stat64(&hw_stats->rx_octets); |
| 11533 | stats->tx_bytes = old_stats->tx_bytes + |
| 11534 | get_stat64(&hw_stats->tx_octets); |
| 11535 | |
| 11536 | stats->rx_errors = old_stats->rx_errors + |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 11537 | get_stat64(&hw_stats->rx_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11538 | stats->tx_errors = old_stats->tx_errors + |
| 11539 | get_stat64(&hw_stats->tx_errors) + |
| 11540 | get_stat64(&hw_stats->tx_mac_errors) + |
| 11541 | get_stat64(&hw_stats->tx_carrier_sense_errors) + |
| 11542 | get_stat64(&hw_stats->tx_discards); |
| 11543 | |
| 11544 | stats->multicast = old_stats->multicast + |
| 11545 | get_stat64(&hw_stats->rx_mcast_packets); |
| 11546 | stats->collisions = old_stats->collisions + |
| 11547 | get_stat64(&hw_stats->tx_collisions); |
| 11548 | |
| 11549 | stats->rx_length_errors = old_stats->rx_length_errors + |
| 11550 | get_stat64(&hw_stats->rx_frame_too_long_errors) + |
| 11551 | get_stat64(&hw_stats->rx_undersize_packets); |
| 11552 | |
| 11553 | stats->rx_over_errors = old_stats->rx_over_errors + |
| 11554 | get_stat64(&hw_stats->rxbds_empty); |
| 11555 | stats->rx_frame_errors = old_stats->rx_frame_errors + |
| 11556 | get_stat64(&hw_stats->rx_align_errors); |
| 11557 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + |
| 11558 | get_stat64(&hw_stats->tx_discards); |
| 11559 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + |
| 11560 | get_stat64(&hw_stats->tx_carrier_sense_errors); |
| 11561 | |
| 11562 | stats->rx_crc_errors = old_stats->rx_crc_errors + |
Matt Carlson | 65ec698 | 2012-02-28 23:33:37 +0000 | [diff] [blame] | 11563 | tg3_calc_crc_errors(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11564 | |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 11565 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
| 11566 | get_stat64(&hw_stats->rx_discards); |
| 11567 | |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 11568 | stats->rx_dropped = tp->rx_dropped; |
Eric Dumazet | 4885543 | 2011-10-24 07:53:03 +0000 | [diff] [blame] | 11569 | stats->tx_dropped = tp->tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11570 | } |
| 11571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11572 | static int tg3_get_regs_len(struct net_device *dev) |
| 11573 | { |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 11574 | return TG3_REG_BLK_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11575 | } |
| 11576 | |
| 11577 | static void tg3_get_regs(struct net_device *dev, |
| 11578 | struct ethtool_regs *regs, void *_p) |
| 11579 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11580 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11581 | |
| 11582 | regs->version = 0; |
| 11583 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 11584 | memset(_p, 0, TG3_REG_BLK_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11585 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11586 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11587 | return; |
| 11588 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11589 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11590 | |
Matt Carlson | 97bd8e4 | 2011-04-13 11:05:04 +0000 | [diff] [blame] | 11591 | tg3_dump_legacy_regs(tp, (u32 *)_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11592 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11593 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11594 | } |
| 11595 | |
| 11596 | static int tg3_get_eeprom_len(struct net_device *dev) |
| 11597 | { |
| 11598 | struct tg3 *tp = netdev_priv(dev); |
| 11599 | |
| 11600 | return tp->nvram_size; |
| 11601 | } |
| 11602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11603 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 11604 | { |
| 11605 | struct tg3 *tp = netdev_priv(dev); |
| 11606 | int ret; |
| 11607 | u8 *pd; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11608 | u32 i, offset, len, b_offset, b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11609 | __be32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11610 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11611 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11612 | return -EINVAL; |
| 11613 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11614 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11615 | return -EAGAIN; |
| 11616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11617 | offset = eeprom->offset; |
| 11618 | len = eeprom->len; |
| 11619 | eeprom->len = 0; |
| 11620 | |
| 11621 | eeprom->magic = TG3_EEPROM_MAGIC; |
| 11622 | |
| 11623 | if (offset & 3) { |
| 11624 | /* adjustments to start on required 4 byte boundary */ |
| 11625 | b_offset = offset & 3; |
| 11626 | b_count = 4 - b_offset; |
| 11627 | if (b_count > len) { |
| 11628 | /* i.e. offset=1 len=2 */ |
| 11629 | b_count = len; |
| 11630 | } |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11631 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11632 | if (ret) |
| 11633 | return ret; |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 11634 | memcpy(data, ((char *)&val) + b_offset, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11635 | len -= b_count; |
| 11636 | offset += b_count; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 11637 | eeprom->len += b_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11638 | } |
| 11639 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11640 | /* read bytes up to the last 4 byte boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11641 | pd = &data[eeprom->len]; |
| 11642 | for (i = 0; i < (len - (len & 3)); i += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11643 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11644 | if (ret) { |
| 11645 | eeprom->len += i; |
| 11646 | return ret; |
| 11647 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11648 | memcpy(pd + i, &val, 4); |
| 11649 | } |
| 11650 | eeprom->len += i; |
| 11651 | |
| 11652 | if (len & 3) { |
| 11653 | /* read last bytes not ending on 4 byte boundary */ |
| 11654 | pd = &data[eeprom->len]; |
| 11655 | b_count = len & 3; |
| 11656 | b_offset = offset + len - b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11657 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11658 | if (ret) |
| 11659 | return ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11660 | memcpy(pd, &val, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11661 | eeprom->len += b_count; |
| 11662 | } |
| 11663 | return 0; |
| 11664 | } |
| 11665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11666 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 11667 | { |
| 11668 | struct tg3 *tp = netdev_priv(dev); |
| 11669 | int ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11670 | u32 offset, len, b_offset, odd_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11671 | u8 *buf; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11672 | __be32 start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11673 | |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11674 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11675 | return -EAGAIN; |
| 11676 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11677 | if (tg3_flag(tp, NO_NVRAM) || |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11678 | eeprom->magic != TG3_EEPROM_MAGIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11679 | return -EINVAL; |
| 11680 | |
| 11681 | offset = eeprom->offset; |
| 11682 | len = eeprom->len; |
| 11683 | |
| 11684 | if ((b_offset = (offset & 3))) { |
| 11685 | /* adjustments to start on required 4 byte boundary */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11686 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11687 | if (ret) |
| 11688 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11689 | len += b_offset; |
| 11690 | offset &= ~3; |
Michael Chan | 1c8594b4 | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 11691 | if (len < 4) |
| 11692 | len = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11693 | } |
| 11694 | |
| 11695 | odd_len = 0; |
Michael Chan | 1c8594b4 | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 11696 | if (len & 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11697 | /* adjustments to end on required 4 byte boundary */ |
| 11698 | odd_len = 1; |
| 11699 | len = (len + 3) & ~3; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11700 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11701 | if (ret) |
| 11702 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11703 | } |
| 11704 | |
| 11705 | buf = data; |
| 11706 | if (b_offset || odd_len) { |
| 11707 | buf = kmalloc(len, GFP_KERNEL); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 11708 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11709 | return -ENOMEM; |
| 11710 | if (b_offset) |
| 11711 | memcpy(buf, &start, 4); |
| 11712 | if (odd_len) |
| 11713 | memcpy(buf+len-4, &end, 4); |
| 11714 | memcpy(buf + b_offset, data, eeprom->len); |
| 11715 | } |
| 11716 | |
| 11717 | ret = tg3_nvram_write_block(tp, offset, len, buf); |
| 11718 | |
| 11719 | if (buf != data) |
| 11720 | kfree(buf); |
| 11721 | |
| 11722 | return ret; |
| 11723 | } |
| 11724 | |
| 11725 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 11726 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11727 | struct tg3 *tp = netdev_priv(dev); |
| 11728 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11729 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11730 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11731 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11732 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11733 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 11734 | return phy_ethtool_gset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11735 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11737 | cmd->supported = (SUPPORTED_Autoneg); |
| 11738 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11739 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11740 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
| 11741 | SUPPORTED_1000baseT_Full); |
| 11742 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11743 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11744 | cmd->supported |= (SUPPORTED_100baseT_Half | |
| 11745 | SUPPORTED_100baseT_Full | |
| 11746 | SUPPORTED_10baseT_Half | |
| 11747 | SUPPORTED_10baseT_Full | |
Matt Carlson | 3bebab5 | 2007-11-12 21:22:40 -0800 | [diff] [blame] | 11748 | SUPPORTED_TP); |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 11749 | cmd->port = PORT_TP; |
| 11750 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11751 | cmd->supported |= SUPPORTED_FIBRE; |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 11752 | cmd->port = PORT_FIBRE; |
| 11753 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11754 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11755 | cmd->advertising = tp->link_config.advertising; |
Matt Carlson | 5bb0977 | 2011-06-13 13:39:00 +0000 | [diff] [blame] | 11756 | if (tg3_flag(tp, PAUSE_AUTONEG)) { |
| 11757 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) { |
| 11758 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 11759 | cmd->advertising |= ADVERTISED_Pause; |
| 11760 | } else { |
| 11761 | cmd->advertising |= ADVERTISED_Pause | |
| 11762 | ADVERTISED_Asym_Pause; |
| 11763 | } |
| 11764 | } else if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 11765 | cmd->advertising |= ADVERTISED_Asym_Pause; |
| 11766 | } |
| 11767 | } |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 11768 | if (netif_running(dev) && tp->link_up) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 11769 | ethtool_cmd_speed_set(cmd, tp->link_config.active_speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11770 | cmd->duplex = tp->link_config.active_duplex; |
Matt Carlson | 859edb2 | 2011-12-08 14:40:16 +0000 | [diff] [blame] | 11771 | cmd->lp_advertising = tp->link_config.rmt_adv; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 11772 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 11773 | if (tp->phy_flags & TG3_PHYFLG_MDIX_STATE) |
| 11774 | cmd->eth_tp_mdix = ETH_TP_MDI_X; |
| 11775 | else |
| 11776 | cmd->eth_tp_mdix = ETH_TP_MDI; |
| 11777 | } |
Matt Carlson | 64c2218 | 2010-10-14 10:37:44 +0000 | [diff] [blame] | 11778 | } else { |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 11779 | ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN); |
| 11780 | cmd->duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e348c5e | 2011-11-21 15:01:20 +0000 | [diff] [blame] | 11781 | cmd->eth_tp_mdix = ETH_TP_MDI_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11782 | } |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 11783 | cmd->phy_address = tp->phy_addr; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11784 | cmd->transceiver = XCVR_INTERNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11785 | cmd->autoneg = tp->link_config.autoneg; |
| 11786 | cmd->maxtxpkt = 0; |
| 11787 | cmd->maxrxpkt = 0; |
| 11788 | return 0; |
| 11789 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11791 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 11792 | { |
| 11793 | struct tg3 *tp = netdev_priv(dev); |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11794 | u32 speed = ethtool_cmd_speed(cmd); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11795 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11796 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11797 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11798 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11799 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11800 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 11801 | return phy_ethtool_sset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11802 | } |
| 11803 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11804 | if (cmd->autoneg != AUTONEG_ENABLE && |
| 11805 | cmd->autoneg != AUTONEG_DISABLE) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 11806 | return -EINVAL; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11807 | |
| 11808 | if (cmd->autoneg == AUTONEG_DISABLE && |
| 11809 | cmd->duplex != DUPLEX_FULL && |
| 11810 | cmd->duplex != DUPLEX_HALF) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 11811 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11812 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11813 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 11814 | u32 mask = ADVERTISED_Autoneg | |
| 11815 | ADVERTISED_Pause | |
| 11816 | ADVERTISED_Asym_Pause; |
| 11817 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11818 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11819 | mask |= ADVERTISED_1000baseT_Half | |
| 11820 | ADVERTISED_1000baseT_Full; |
| 11821 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11822 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11823 | mask |= ADVERTISED_100baseT_Half | |
| 11824 | ADVERTISED_100baseT_Full | |
| 11825 | ADVERTISED_10baseT_Half | |
| 11826 | ADVERTISED_10baseT_Full | |
| 11827 | ADVERTISED_TP; |
| 11828 | else |
| 11829 | mask |= ADVERTISED_FIBRE; |
| 11830 | |
| 11831 | if (cmd->advertising & ~mask) |
| 11832 | return -EINVAL; |
| 11833 | |
| 11834 | mask &= (ADVERTISED_1000baseT_Half | |
| 11835 | ADVERTISED_1000baseT_Full | |
| 11836 | ADVERTISED_100baseT_Half | |
| 11837 | ADVERTISED_100baseT_Full | |
| 11838 | ADVERTISED_10baseT_Half | |
| 11839 | ADVERTISED_10baseT_Full); |
| 11840 | |
| 11841 | cmd->advertising &= mask; |
| 11842 | } else { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11843 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11844 | if (speed != SPEED_1000) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11845 | return -EINVAL; |
| 11846 | |
| 11847 | if (cmd->duplex != DUPLEX_FULL) |
| 11848 | return -EINVAL; |
| 11849 | } else { |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11850 | if (speed != SPEED_100 && |
| 11851 | speed != SPEED_10) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 11852 | return -EINVAL; |
| 11853 | } |
| 11854 | } |
| 11855 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11856 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11857 | |
| 11858 | tp->link_config.autoneg = cmd->autoneg; |
| 11859 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Andy Gospodarek | 405d8e5 | 2007-10-08 01:08:47 -0700 | [diff] [blame] | 11860 | tp->link_config.advertising = (cmd->advertising | |
| 11861 | ADVERTISED_Autoneg); |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 11862 | tp->link_config.speed = SPEED_UNKNOWN; |
| 11863 | tp->link_config.duplex = DUPLEX_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11864 | } else { |
| 11865 | tp->link_config.advertising = 0; |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 11866 | tp->link_config.speed = speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11867 | tp->link_config.duplex = cmd->duplex; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11868 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11869 | |
Nithin Sujir | fdad8de | 2013-04-09 08:48:08 +0000 | [diff] [blame] | 11870 | tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; |
| 11871 | |
Nithin Sujir | ce20f16 | 2013-04-09 08:48:04 +0000 | [diff] [blame] | 11872 | tg3_warn_mgmt_link_flap(tp); |
| 11873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11874 | if (netif_running(dev)) |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 11875 | tg3_setup_phy(tp, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11876 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11877 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11879 | return 0; |
| 11880 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11882 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 11883 | { |
| 11884 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11885 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 11886 | strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); |
| 11887 | strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); |
| 11888 | strlcpy(info->fw_version, tp->fw_ver, sizeof(info->fw_version)); |
| 11889 | strlcpy(info->bus_info, pci_name(tp->pdev), sizeof(info->bus_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11890 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11892 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 11893 | { |
| 11894 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11895 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11896 | if (tg3_flag(tp, WOL_CAP) && device_can_wakeup(&tp->pdev->dev)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 11897 | wol->supported = WAKE_MAGIC; |
| 11898 | else |
| 11899 | wol->supported = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11900 | wol->wolopts = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11901 | if (tg3_flag(tp, WOL_ENABLE) && device_can_wakeup(&tp->pdev->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11902 | wol->wolopts = WAKE_MAGIC; |
| 11903 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 11904 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11906 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 11907 | { |
| 11908 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 11909 | struct device *dp = &tp->pdev->dev; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11911 | if (wol->wolopts & ~WAKE_MAGIC) |
| 11912 | return -EINVAL; |
| 11913 | if ((wol->wolopts & WAKE_MAGIC) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11914 | !(tg3_flag(tp, WOL_CAP) && device_can_wakeup(dp))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11915 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11916 | |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 11917 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
| 11918 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11919 | spin_lock_bh(&tp->lock); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 11920 | if (device_may_wakeup(dp)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11921 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 11922 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11923 | tg3_flag_clear(tp, WOL_ENABLE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11924 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11926 | return 0; |
| 11927 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11929 | static u32 tg3_get_msglevel(struct net_device *dev) |
| 11930 | { |
| 11931 | struct tg3 *tp = netdev_priv(dev); |
| 11932 | return tp->msg_enable; |
| 11933 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11935 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
| 11936 | { |
| 11937 | struct tg3 *tp = netdev_priv(dev); |
| 11938 | tp->msg_enable = value; |
| 11939 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11941 | static int tg3_nway_reset(struct net_device *dev) |
| 11942 | { |
| 11943 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11944 | int r; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11946 | if (!netif_running(dev)) |
| 11947 | return -EAGAIN; |
| 11948 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11949 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 11950 | return -EINVAL; |
| 11951 | |
Nithin Sujir | ce20f16 | 2013-04-09 08:48:04 +0000 | [diff] [blame] | 11952 | tg3_warn_mgmt_link_flap(tp); |
| 11953 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11954 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11955 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11956 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11957 | 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] | 11958 | } else { |
| 11959 | u32 bmcr; |
| 11960 | |
| 11961 | spin_lock_bh(&tp->lock); |
| 11962 | r = -EINVAL; |
| 11963 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 11964 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && |
| 11965 | ((bmcr & BMCR_ANENABLE) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11966 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11967 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
| 11968 | BMCR_ANENABLE); |
| 11969 | r = 0; |
| 11970 | } |
| 11971 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11972 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11973 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11974 | return r; |
| 11975 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11977 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 11978 | { |
| 11979 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11980 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 11981 | ering->rx_max_pending = tp->rx_std_ring_mask; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11982 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 11983 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 11984 | else |
| 11985 | ering->rx_jumbo_max_pending = 0; |
| 11986 | |
| 11987 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11988 | |
| 11989 | ering->rx_pending = tp->rx_pending; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 11990 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 11991 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
| 11992 | else |
| 11993 | ering->rx_jumbo_pending = 0; |
| 11994 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 11995 | ering->tx_pending = tp->napi[0].tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11996 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11998 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 11999 | { |
| 12000 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 12001 | int i, irq_sync = 0, err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12002 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 12003 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
| 12004 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 12005 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
| 12006 | (ering->tx_pending <= MAX_SKB_FRAGS) || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12007 | (tg3_flag(tp, TSO_BUG) && |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 12008 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12009 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12010 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12011 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12012 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12013 | tg3_netif_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12014 | irq_sync = 1; |
| 12015 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12016 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12017 | tg3_full_lock(tp, irq_sync); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12019 | tp->rx_pending = ering->rx_pending; |
| 12020 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12021 | if (tg3_flag(tp, MAX_RXPEND_64) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12022 | tp->rx_pending > 63) |
| 12023 | tp->rx_pending = 63; |
| 12024 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 12025 | |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 12026 | for (i = 0; i < tp->irq_max; i++) |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 12027 | tp->napi[i].tx_pending = ering->tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12028 | |
| 12029 | if (netif_running(dev)) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 12030 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 12031 | err = tg3_restart_hw(tp, false); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 12032 | if (!err) |
| 12033 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12034 | } |
| 12035 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 12036 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12037 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12038 | if (irq_sync && !err) |
| 12039 | tg3_phy_start(tp); |
| 12040 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 12041 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12042 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12044 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 12045 | { |
| 12046 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12047 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12048 | epause->autoneg = !!tg3_flag(tp, PAUSE_AUTONEG); |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 12049 | |
Matt Carlson | 4a2db50 | 2011-12-08 14:40:17 +0000 | [diff] [blame] | 12050 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 12051 | epause->rx_pause = 1; |
| 12052 | else |
| 12053 | epause->rx_pause = 0; |
| 12054 | |
Matt Carlson | 4a2db50 | 2011-12-08 14:40:17 +0000 | [diff] [blame] | 12055 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 12056 | epause->tx_pause = 1; |
| 12057 | else |
| 12058 | epause->tx_pause = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12059 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12061 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 12062 | { |
| 12063 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12064 | int err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12065 | |
Nithin Sujir | ce20f16 | 2013-04-09 08:48:04 +0000 | [diff] [blame] | 12066 | if (tp->link_config.autoneg == AUTONEG_ENABLE) |
| 12067 | tg3_warn_mgmt_link_flap(tp); |
| 12068 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12069 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12070 | u32 newadv; |
| 12071 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12072 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12073 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12074 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12075 | if (!(phydev->supported & SUPPORTED_Pause) || |
| 12076 | (!(phydev->supported & SUPPORTED_Asym_Pause) && |
Nicolas Kaiser | 2259dca | 2010-10-07 23:29:27 +0000 | [diff] [blame] | 12077 | (epause->rx_pause != epause->tx_pause))) |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12078 | return -EINVAL; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12079 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12080 | tp->link_config.flowctrl = 0; |
| 12081 | if (epause->rx_pause) { |
| 12082 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12083 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12084 | if (epause->tx_pause) { |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 12085 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12086 | newadv = ADVERTISED_Pause; |
| 12087 | } else |
| 12088 | newadv = ADVERTISED_Pause | |
| 12089 | ADVERTISED_Asym_Pause; |
| 12090 | } else if (epause->tx_pause) { |
| 12091 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 12092 | newadv = ADVERTISED_Asym_Pause; |
| 12093 | } else |
| 12094 | newadv = 0; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12095 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12096 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12097 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12098 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12099 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12100 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12101 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12102 | u32 oldadv = phydev->advertising & |
| 12103 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 12104 | if (oldadv != newadv) { |
| 12105 | phydev->advertising &= |
| 12106 | ~(ADVERTISED_Pause | |
| 12107 | ADVERTISED_Asym_Pause); |
| 12108 | phydev->advertising |= newadv; |
| 12109 | if (phydev->autoneg) { |
| 12110 | /* |
| 12111 | * Always renegotiate the link to |
| 12112 | * inform our link partner of our |
| 12113 | * flow control settings, even if the |
| 12114 | * flow control is forced. Let |
| 12115 | * tg3_adjust_link() do the final |
| 12116 | * flow control setup. |
| 12117 | */ |
| 12118 | return phy_start_aneg(phydev); |
| 12119 | } |
| 12120 | } |
| 12121 | |
| 12122 | if (!epause->autoneg) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12123 | tg3_setup_flow_control(tp, 0, 0); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12124 | } else { |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 12125 | tp->link_config.advertising &= |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 12126 | ~(ADVERTISED_Pause | |
| 12127 | ADVERTISED_Asym_Pause); |
Matt Carlson | c6700ce | 2012-02-13 15:20:15 +0000 | [diff] [blame] | 12128 | tp->link_config.advertising |= newadv; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12129 | } |
| 12130 | } else { |
| 12131 | int irq_sync = 0; |
| 12132 | |
| 12133 | if (netif_running(dev)) { |
| 12134 | tg3_netif_stop(tp); |
| 12135 | irq_sync = 1; |
| 12136 | } |
| 12137 | |
| 12138 | tg3_full_lock(tp, irq_sync); |
| 12139 | |
| 12140 | if (epause->autoneg) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12141 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12142 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12143 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12144 | if (epause->rx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 12145 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12146 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 12147 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12148 | if (epause->tx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 12149 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12150 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 12151 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12152 | |
| 12153 | if (netif_running(dev)) { |
| 12154 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 12155 | err = tg3_restart_hw(tp, false); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12156 | if (!err) |
| 12157 | tg3_netif_start(tp); |
| 12158 | } |
| 12159 | |
| 12160 | tg3_full_unlock(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 12161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12162 | |
Nithin Sujir | fdad8de | 2013-04-09 08:48:08 +0000 | [diff] [blame] | 12163 | tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; |
| 12164 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 12165 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12166 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12167 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 12168 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12169 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 12170 | switch (sset) { |
| 12171 | case ETH_SS_TEST: |
| 12172 | return TG3_NUM_TEST; |
| 12173 | case ETH_SS_STATS: |
| 12174 | return TG3_NUM_STATS; |
| 12175 | default: |
| 12176 | return -EOPNOTSUPP; |
| 12177 | } |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12178 | } |
| 12179 | |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 12180 | static int tg3_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info, |
| 12181 | u32 *rules __always_unused) |
| 12182 | { |
| 12183 | struct tg3 *tp = netdev_priv(dev); |
| 12184 | |
| 12185 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 12186 | return -EOPNOTSUPP; |
| 12187 | |
| 12188 | switch (info->cmd) { |
| 12189 | case ETHTOOL_GRXRINGS: |
| 12190 | if (netif_running(tp->dev)) |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 12191 | info->data = tp->rxq_cnt; |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 12192 | else { |
| 12193 | info->data = num_online_cpus(); |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 12194 | if (info->data > TG3_RSS_MAX_NUM_QS) |
| 12195 | info->data = TG3_RSS_MAX_NUM_QS; |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 12196 | } |
| 12197 | |
| 12198 | /* The first interrupt vector only |
| 12199 | * handles link interrupts. |
| 12200 | */ |
| 12201 | info->data -= 1; |
| 12202 | return 0; |
| 12203 | |
| 12204 | default: |
| 12205 | return -EOPNOTSUPP; |
| 12206 | } |
| 12207 | } |
| 12208 | |
| 12209 | static u32 tg3_get_rxfh_indir_size(struct net_device *dev) |
| 12210 | { |
| 12211 | u32 size = 0; |
| 12212 | struct tg3 *tp = netdev_priv(dev); |
| 12213 | |
| 12214 | if (tg3_flag(tp, SUPPORT_MSIX)) |
| 12215 | size = TG3_RSS_INDIR_TBL_SIZE; |
| 12216 | |
| 12217 | return size; |
| 12218 | } |
| 12219 | |
| 12220 | static int tg3_get_rxfh_indir(struct net_device *dev, u32 *indir) |
| 12221 | { |
| 12222 | struct tg3 *tp = netdev_priv(dev); |
| 12223 | int i; |
| 12224 | |
| 12225 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 12226 | indir[i] = tp->rss_ind_tbl[i]; |
| 12227 | |
| 12228 | return 0; |
| 12229 | } |
| 12230 | |
| 12231 | static int tg3_set_rxfh_indir(struct net_device *dev, const u32 *indir) |
| 12232 | { |
| 12233 | struct tg3 *tp = netdev_priv(dev); |
| 12234 | size_t i; |
| 12235 | |
| 12236 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 12237 | tp->rss_ind_tbl[i] = indir[i]; |
| 12238 | |
| 12239 | if (!netif_running(dev) || !tg3_flag(tp, ENABLE_RSS)) |
| 12240 | return 0; |
| 12241 | |
| 12242 | /* It is legal to write the indirection |
| 12243 | * table while the device is running. |
| 12244 | */ |
| 12245 | tg3_full_lock(tp, 0); |
| 12246 | tg3_rss_write_indir_tbl(tp); |
| 12247 | tg3_full_unlock(tp); |
| 12248 | |
| 12249 | return 0; |
| 12250 | } |
| 12251 | |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 12252 | static void tg3_get_channels(struct net_device *dev, |
| 12253 | struct ethtool_channels *channel) |
| 12254 | { |
| 12255 | struct tg3 *tp = netdev_priv(dev); |
| 12256 | u32 deflt_qs = netif_get_num_default_rss_queues(); |
| 12257 | |
| 12258 | channel->max_rx = tp->rxq_max; |
| 12259 | channel->max_tx = tp->txq_max; |
| 12260 | |
| 12261 | if (netif_running(dev)) { |
| 12262 | channel->rx_count = tp->rxq_cnt; |
| 12263 | channel->tx_count = tp->txq_cnt; |
| 12264 | } else { |
| 12265 | if (tp->rxq_req) |
| 12266 | channel->rx_count = tp->rxq_req; |
| 12267 | else |
| 12268 | channel->rx_count = min(deflt_qs, tp->rxq_max); |
| 12269 | |
| 12270 | if (tp->txq_req) |
| 12271 | channel->tx_count = tp->txq_req; |
| 12272 | else |
| 12273 | channel->tx_count = min(deflt_qs, tp->txq_max); |
| 12274 | } |
| 12275 | } |
| 12276 | |
| 12277 | static int tg3_set_channels(struct net_device *dev, |
| 12278 | struct ethtool_channels *channel) |
| 12279 | { |
| 12280 | struct tg3 *tp = netdev_priv(dev); |
| 12281 | |
| 12282 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 12283 | return -EOPNOTSUPP; |
| 12284 | |
| 12285 | if (channel->rx_count > tp->rxq_max || |
| 12286 | channel->tx_count > tp->txq_max) |
| 12287 | return -EINVAL; |
| 12288 | |
| 12289 | tp->rxq_req = channel->rx_count; |
| 12290 | tp->txq_req = channel->tx_count; |
| 12291 | |
| 12292 | if (!netif_running(dev)) |
| 12293 | return 0; |
| 12294 | |
| 12295 | tg3_stop(tp); |
| 12296 | |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 12297 | tg3_carrier_off(tp); |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 12298 | |
Matt Carlson | be94730 | 2012-12-03 19:36:57 +0000 | [diff] [blame] | 12299 | tg3_start(tp, true, false, false); |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 12300 | |
| 12301 | return 0; |
| 12302 | } |
| 12303 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 12304 | 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] | 12305 | { |
| 12306 | switch (stringset) { |
| 12307 | case ETH_SS_STATS: |
| 12308 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 12309 | break; |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 12310 | case ETH_SS_TEST: |
| 12311 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); |
| 12312 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12313 | default: |
| 12314 | WARN_ON(1); /* we need a WARN() */ |
| 12315 | break; |
| 12316 | } |
| 12317 | } |
| 12318 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 12319 | static int tg3_set_phys_id(struct net_device *dev, |
| 12320 | enum ethtool_phys_id_state state) |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 12321 | { |
| 12322 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 12323 | |
| 12324 | if (!netif_running(tp->dev)) |
| 12325 | return -EAGAIN; |
| 12326 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 12327 | switch (state) { |
| 12328 | case ETHTOOL_ID_ACTIVE: |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 12329 | return 1; /* cycle on/off once per second */ |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 12330 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 12331 | case ETHTOOL_ID_ON: |
| 12332 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 12333 | LED_CTRL_1000MBPS_ON | |
| 12334 | LED_CTRL_100MBPS_ON | |
| 12335 | LED_CTRL_10MBPS_ON | |
| 12336 | LED_CTRL_TRAFFIC_OVERRIDE | |
| 12337 | LED_CTRL_TRAFFIC_BLINK | |
| 12338 | LED_CTRL_TRAFFIC_LED); |
| 12339 | break; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12340 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 12341 | case ETHTOOL_ID_OFF: |
| 12342 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 12343 | LED_CTRL_TRAFFIC_OVERRIDE); |
| 12344 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 12345 | |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 12346 | case ETHTOOL_ID_INACTIVE: |
| 12347 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 12348 | break; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 12349 | } |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 12350 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 12351 | return 0; |
| 12352 | } |
| 12353 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 12354 | static void tg3_get_ethtool_stats(struct net_device *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12355 | struct ethtool_stats *estats, u64 *tmp_stats) |
| 12356 | { |
| 12357 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 0e6c9da | 2011-12-08 14:40:13 +0000 | [diff] [blame] | 12358 | |
Matt Carlson | b546e46 | 2012-02-13 15:20:09 +0000 | [diff] [blame] | 12359 | if (tp->hw_stats) |
| 12360 | tg3_get_estats(tp, (struct tg3_ethtool_stats *)tmp_stats); |
| 12361 | else |
| 12362 | memset(tmp_stats, 0, sizeof(struct tg3_ethtool_stats)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12363 | } |
| 12364 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 12365 | static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 12366 | { |
| 12367 | int i; |
| 12368 | __be32 *buf; |
| 12369 | u32 offset = 0, len = 0; |
| 12370 | u32 magic, val; |
| 12371 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12372 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &magic)) |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 12373 | return NULL; |
| 12374 | |
| 12375 | if (magic == TG3_EEPROM_MAGIC) { |
| 12376 | for (offset = TG3_NVM_DIR_START; |
| 12377 | offset < TG3_NVM_DIR_END; |
| 12378 | offset += TG3_NVM_DIRENT_SIZE) { |
| 12379 | if (tg3_nvram_read(tp, offset, &val)) |
| 12380 | return NULL; |
| 12381 | |
| 12382 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == |
| 12383 | TG3_NVM_DIRTYPE_EXTVPD) |
| 12384 | break; |
| 12385 | } |
| 12386 | |
| 12387 | if (offset != TG3_NVM_DIR_END) { |
| 12388 | len = (val & TG3_NVM_DIRTYPE_LENMSK) * 4; |
| 12389 | if (tg3_nvram_read(tp, offset + 4, &offset)) |
| 12390 | return NULL; |
| 12391 | |
| 12392 | offset = tg3_nvram_logical_addr(tp, offset); |
| 12393 | } |
| 12394 | } |
| 12395 | |
| 12396 | if (!offset || !len) { |
| 12397 | offset = TG3_NVM_VPD_OFF; |
| 12398 | len = TG3_NVM_VPD_LEN; |
| 12399 | } |
| 12400 | |
| 12401 | buf = kmalloc(len, GFP_KERNEL); |
| 12402 | if (buf == NULL) |
| 12403 | return NULL; |
| 12404 | |
| 12405 | if (magic == TG3_EEPROM_MAGIC) { |
| 12406 | for (i = 0; i < len; i += 4) { |
| 12407 | /* The data is in little-endian format in NVRAM. |
| 12408 | * Use the big-endian read routines to preserve |
| 12409 | * the byte order as it exists in NVRAM. |
| 12410 | */ |
| 12411 | if (tg3_nvram_read_be32(tp, offset + i, &buf[i/4])) |
| 12412 | goto error; |
| 12413 | } |
| 12414 | } else { |
| 12415 | u8 *ptr; |
| 12416 | ssize_t cnt; |
| 12417 | unsigned int pos = 0; |
| 12418 | |
| 12419 | ptr = (u8 *)&buf[0]; |
| 12420 | for (i = 0; pos < len && i < 3; i++, pos += cnt, ptr += cnt) { |
| 12421 | cnt = pci_read_vpd(tp->pdev, pos, |
| 12422 | len - pos, ptr); |
| 12423 | if (cnt == -ETIMEDOUT || cnt == -EINTR) |
| 12424 | cnt = 0; |
| 12425 | else if (cnt < 0) |
| 12426 | goto error; |
| 12427 | } |
| 12428 | if (pos != len) |
| 12429 | goto error; |
| 12430 | } |
| 12431 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 12432 | *vpdlen = len; |
| 12433 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 12434 | return buf; |
| 12435 | |
| 12436 | error: |
| 12437 | kfree(buf); |
| 12438 | return NULL; |
| 12439 | } |
| 12440 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12441 | #define NVRAM_TEST_SIZE 0x100 |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 12442 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
| 12443 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 |
| 12444 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 12445 | #define NVRAM_SELFBOOT_FORMAT1_4_SIZE 0x20 |
| 12446 | #define NVRAM_SELFBOOT_FORMAT1_5_SIZE 0x24 |
Matt Carlson | bda18fa | 2011-07-20 10:20:57 +0000 | [diff] [blame] | 12447 | #define NVRAM_SELFBOOT_FORMAT1_6_SIZE 0x50 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12448 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
| 12449 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12450 | |
| 12451 | static int tg3_test_nvram(struct tg3 *tp) |
| 12452 | { |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 12453 | u32 csum, magic, len; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12454 | __be32 *buf; |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 12455 | int i, j, k, err = 0, size; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12456 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12457 | if (tg3_flag(tp, NO_NVRAM)) |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 12458 | return 0; |
| 12459 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12460 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12461 | return -EIO; |
| 12462 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12463 | if (magic == TG3_EEPROM_MAGIC) |
| 12464 | size = NVRAM_TEST_SIZE; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12465 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 12466 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
| 12467 | TG3_EEPROM_SB_FORMAT_1) { |
| 12468 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { |
| 12469 | case TG3_EEPROM_SB_REVISION_0: |
| 12470 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; |
| 12471 | break; |
| 12472 | case TG3_EEPROM_SB_REVISION_2: |
| 12473 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; |
| 12474 | break; |
| 12475 | case TG3_EEPROM_SB_REVISION_3: |
| 12476 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; |
| 12477 | break; |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 12478 | case TG3_EEPROM_SB_REVISION_4: |
| 12479 | size = NVRAM_SELFBOOT_FORMAT1_4_SIZE; |
| 12480 | break; |
| 12481 | case TG3_EEPROM_SB_REVISION_5: |
| 12482 | size = NVRAM_SELFBOOT_FORMAT1_5_SIZE; |
| 12483 | break; |
| 12484 | case TG3_EEPROM_SB_REVISION_6: |
| 12485 | size = NVRAM_SELFBOOT_FORMAT1_6_SIZE; |
| 12486 | break; |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 12487 | default: |
Matt Carlson | 727a6d9 | 2011-06-13 13:38:58 +0000 | [diff] [blame] | 12488 | return -EIO; |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 12489 | } |
| 12490 | } else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12491 | return 0; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12492 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 12493 | size = NVRAM_SELFBOOT_HW_SIZE; |
| 12494 | else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12495 | return -EIO; |
| 12496 | |
| 12497 | buf = kmalloc(size, GFP_KERNEL); |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12498 | if (buf == NULL) |
| 12499 | return -ENOMEM; |
| 12500 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12501 | err = -EIO; |
| 12502 | for (i = 0, j = 0; i < size; i += 4, j++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12503 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
| 12504 | if (err) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12505 | break; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12506 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12507 | if (i < size) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12508 | goto out; |
| 12509 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12510 | /* Selfboot format */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12511 | magic = be32_to_cpu(buf[0]); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12512 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12513 | TG3_EEPROM_MAGIC_FW) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12514 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
| 12515 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12516 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 12517 | TG3_EEPROM_SB_REVISION_2) { |
| 12518 | /* For rev 2, the csum doesn't include the MBA. */ |
| 12519 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) |
| 12520 | csum8 += buf8[i]; |
| 12521 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) |
| 12522 | csum8 += buf8[i]; |
| 12523 | } else { |
| 12524 | for (i = 0; i < size; i++) |
| 12525 | csum8 += buf8[i]; |
| 12526 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12527 | |
Adrian Bunk | ad96b48 | 2006-04-05 22:21:04 -0700 | [diff] [blame] | 12528 | if (csum8 == 0) { |
| 12529 | err = 0; |
| 12530 | goto out; |
| 12531 | } |
| 12532 | |
| 12533 | err = -EIO; |
| 12534 | goto out; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12535 | } |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12536 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12537 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12538 | TG3_EEPROM_MAGIC_HW) { |
| 12539 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12540 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12541 | u8 *buf8 = (u8 *) buf; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12542 | |
| 12543 | /* Separate the parity bits and the data bytes. */ |
| 12544 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { |
| 12545 | if ((i == 0) || (i == 8)) { |
| 12546 | int l; |
| 12547 | u8 msk; |
| 12548 | |
| 12549 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) |
| 12550 | parity[k++] = buf8[i] & msk; |
| 12551 | i++; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 12552 | } else if (i == 16) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12553 | int l; |
| 12554 | u8 msk; |
| 12555 | |
| 12556 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) |
| 12557 | parity[k++] = buf8[i] & msk; |
| 12558 | i++; |
| 12559 | |
| 12560 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) |
| 12561 | parity[k++] = buf8[i] & msk; |
| 12562 | i++; |
| 12563 | } |
| 12564 | data[j++] = buf8[i]; |
| 12565 | } |
| 12566 | |
| 12567 | err = -EIO; |
| 12568 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { |
| 12569 | u8 hw8 = hweight8(data[i]); |
| 12570 | |
| 12571 | if ((hw8 & 0x1) && parity[i]) |
| 12572 | goto out; |
| 12573 | else if (!(hw8 & 0x1) && !parity[i]) |
| 12574 | goto out; |
| 12575 | } |
| 12576 | err = 0; |
| 12577 | goto out; |
| 12578 | } |
| 12579 | |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 12580 | err = -EIO; |
| 12581 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12582 | /* Bootstrap checksum at offset 0x10 */ |
| 12583 | csum = calc_crc((unsigned char *) buf, 0x10); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 12584 | if (csum != le32_to_cpu(buf[0x10/4])) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12585 | goto out; |
| 12586 | |
| 12587 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ |
| 12588 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); |
Matt Carlson | 01c3a39 | 2011-03-09 16:58:20 +0000 | [diff] [blame] | 12589 | if (csum != le32_to_cpu(buf[0xfc/4])) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12590 | goto out; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12591 | |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 12592 | kfree(buf); |
| 12593 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 12594 | buf = tg3_vpd_readblock(tp, &len); |
Matt Carlson | c3e9450 | 2011-04-13 11:05:08 +0000 | [diff] [blame] | 12595 | if (!buf) |
| 12596 | return -ENOMEM; |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 12597 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 12598 | 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] | 12599 | if (i > 0) { |
| 12600 | j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); |
| 12601 | if (j < 0) |
| 12602 | goto out; |
| 12603 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 12604 | if (i + PCI_VPD_LRDT_TAG_SIZE + j > len) |
Matt Carlson | d4894f3 | 2011-03-09 16:58:21 +0000 | [diff] [blame] | 12605 | goto out; |
| 12606 | |
| 12607 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 12608 | j = pci_vpd_find_info_keyword((u8 *)buf, i, j, |
| 12609 | PCI_VPD_RO_KEYWORD_CHKSUM); |
| 12610 | if (j > 0) { |
| 12611 | u8 csum8 = 0; |
| 12612 | |
| 12613 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 12614 | |
| 12615 | for (i = 0; i <= j; i++) |
| 12616 | csum8 += ((u8 *)buf)[i]; |
| 12617 | |
| 12618 | if (csum8) |
| 12619 | goto out; |
| 12620 | } |
| 12621 | } |
| 12622 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 12623 | err = 0; |
| 12624 | |
| 12625 | out: |
| 12626 | kfree(buf); |
| 12627 | return err; |
| 12628 | } |
| 12629 | |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12630 | #define TG3_SERDES_TIMEOUT_SEC 2 |
| 12631 | #define TG3_COPPER_TIMEOUT_SEC 6 |
| 12632 | |
| 12633 | static int tg3_test_link(struct tg3 *tp) |
| 12634 | { |
| 12635 | int i, max; |
| 12636 | |
| 12637 | if (!netif_running(tp->dev)) |
| 12638 | return -ENODEV; |
| 12639 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12640 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12641 | max = TG3_SERDES_TIMEOUT_SEC; |
| 12642 | else |
| 12643 | max = TG3_COPPER_TIMEOUT_SEC; |
| 12644 | |
| 12645 | for (i = 0; i < max; i++) { |
Nithin Nayak Sujir | f4a46d1 | 2012-11-14 14:44:27 +0000 | [diff] [blame] | 12646 | if (tp->link_up) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 12647 | return 0; |
| 12648 | |
| 12649 | if (msleep_interruptible(1000)) |
| 12650 | break; |
| 12651 | } |
| 12652 | |
| 12653 | return -EIO; |
| 12654 | } |
| 12655 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12656 | /* Only test the commonly used registers */ |
David S. Miller | 30ca3e3 | 2006-03-20 23:02:36 -0800 | [diff] [blame] | 12657 | static int tg3_test_registers(struct tg3 *tp) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12658 | { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12659 | int i, is_5705, is_5750; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12660 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
| 12661 | static struct { |
| 12662 | u16 offset; |
| 12663 | u16 flags; |
| 12664 | #define TG3_FL_5705 0x1 |
| 12665 | #define TG3_FL_NOT_5705 0x2 |
| 12666 | #define TG3_FL_NOT_5788 0x4 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12667 | #define TG3_FL_NOT_5750 0x8 |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12668 | u32 read_mask; |
| 12669 | u32 write_mask; |
| 12670 | } reg_tbl[] = { |
| 12671 | /* MAC Control Registers */ |
| 12672 | { MAC_MODE, TG3_FL_NOT_5705, |
| 12673 | 0x00000000, 0x00ef6f8c }, |
| 12674 | { MAC_MODE, TG3_FL_5705, |
| 12675 | 0x00000000, 0x01ef6b8c }, |
| 12676 | { MAC_STATUS, TG3_FL_NOT_5705, |
| 12677 | 0x03800107, 0x00000000 }, |
| 12678 | { MAC_STATUS, TG3_FL_5705, |
| 12679 | 0x03800100, 0x00000000 }, |
| 12680 | { MAC_ADDR_0_HIGH, 0x0000, |
| 12681 | 0x00000000, 0x0000ffff }, |
| 12682 | { MAC_ADDR_0_LOW, 0x0000, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12683 | 0x00000000, 0xffffffff }, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12684 | { MAC_RX_MTU_SIZE, 0x0000, |
| 12685 | 0x00000000, 0x0000ffff }, |
| 12686 | { MAC_TX_MODE, 0x0000, |
| 12687 | 0x00000000, 0x00000070 }, |
| 12688 | { MAC_TX_LENGTHS, 0x0000, |
| 12689 | 0x00000000, 0x00003fff }, |
| 12690 | { MAC_RX_MODE, TG3_FL_NOT_5705, |
| 12691 | 0x00000000, 0x000007fc }, |
| 12692 | { MAC_RX_MODE, TG3_FL_5705, |
| 12693 | 0x00000000, 0x000007dc }, |
| 12694 | { MAC_HASH_REG_0, 0x0000, |
| 12695 | 0x00000000, 0xffffffff }, |
| 12696 | { MAC_HASH_REG_1, 0x0000, |
| 12697 | 0x00000000, 0xffffffff }, |
| 12698 | { MAC_HASH_REG_2, 0x0000, |
| 12699 | 0x00000000, 0xffffffff }, |
| 12700 | { MAC_HASH_REG_3, 0x0000, |
| 12701 | 0x00000000, 0xffffffff }, |
| 12702 | |
| 12703 | /* Receive Data and Receive BD Initiator Control Registers. */ |
| 12704 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, |
| 12705 | 0x00000000, 0xffffffff }, |
| 12706 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, |
| 12707 | 0x00000000, 0xffffffff }, |
| 12708 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, |
| 12709 | 0x00000000, 0x00000003 }, |
| 12710 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, |
| 12711 | 0x00000000, 0xffffffff }, |
| 12712 | { RCVDBDI_STD_BD+0, 0x0000, |
| 12713 | 0x00000000, 0xffffffff }, |
| 12714 | { RCVDBDI_STD_BD+4, 0x0000, |
| 12715 | 0x00000000, 0xffffffff }, |
| 12716 | { RCVDBDI_STD_BD+8, 0x0000, |
| 12717 | 0x00000000, 0xffff0002 }, |
| 12718 | { RCVDBDI_STD_BD+0xc, 0x0000, |
| 12719 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12720 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12721 | /* Receive BD Initiator Control Registers. */ |
| 12722 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, |
| 12723 | 0x00000000, 0xffffffff }, |
| 12724 | { RCVBDI_STD_THRESH, TG3_FL_5705, |
| 12725 | 0x00000000, 0x000003ff }, |
| 12726 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, |
| 12727 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12728 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12729 | /* Host Coalescing Control Registers. */ |
| 12730 | { HOSTCC_MODE, TG3_FL_NOT_5705, |
| 12731 | 0x00000000, 0x00000004 }, |
| 12732 | { HOSTCC_MODE, TG3_FL_5705, |
| 12733 | 0x00000000, 0x000000f6 }, |
| 12734 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, |
| 12735 | 0x00000000, 0xffffffff }, |
| 12736 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, |
| 12737 | 0x00000000, 0x000003ff }, |
| 12738 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, |
| 12739 | 0x00000000, 0xffffffff }, |
| 12740 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, |
| 12741 | 0x00000000, 0x000003ff }, |
| 12742 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, |
| 12743 | 0x00000000, 0xffffffff }, |
| 12744 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 12745 | 0x00000000, 0x000000ff }, |
| 12746 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, |
| 12747 | 0x00000000, 0xffffffff }, |
| 12748 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 12749 | 0x00000000, 0x000000ff }, |
| 12750 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 12751 | 0x00000000, 0xffffffff }, |
| 12752 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 12753 | 0x00000000, 0xffffffff }, |
| 12754 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 12755 | 0x00000000, 0xffffffff }, |
| 12756 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 12757 | 0x00000000, 0x000000ff }, |
| 12758 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 12759 | 0x00000000, 0xffffffff }, |
| 12760 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 12761 | 0x00000000, 0x000000ff }, |
| 12762 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, |
| 12763 | 0x00000000, 0xffffffff }, |
| 12764 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, |
| 12765 | 0x00000000, 0xffffffff }, |
| 12766 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, |
| 12767 | 0x00000000, 0xffffffff }, |
| 12768 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, |
| 12769 | 0x00000000, 0xffffffff }, |
| 12770 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, |
| 12771 | 0x00000000, 0xffffffff }, |
| 12772 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, |
| 12773 | 0xffffffff, 0x00000000 }, |
| 12774 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, |
| 12775 | 0xffffffff, 0x00000000 }, |
| 12776 | |
| 12777 | /* Buffer Manager Control Registers. */ |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12778 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12779 | 0x00000000, 0x007fff80 }, |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12780 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12781 | 0x00000000, 0x007fffff }, |
| 12782 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, |
| 12783 | 0x00000000, 0x0000003f }, |
| 12784 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, |
| 12785 | 0x00000000, 0x000001ff }, |
| 12786 | { BUFMGR_MB_HIGH_WATER, 0x0000, |
| 12787 | 0x00000000, 0x000001ff }, |
| 12788 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, |
| 12789 | 0xffffffff, 0x00000000 }, |
| 12790 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, |
| 12791 | 0xffffffff, 0x00000000 }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12792 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12793 | /* Mailbox Registers */ |
| 12794 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, |
| 12795 | 0x00000000, 0x000001ff }, |
| 12796 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, |
| 12797 | 0x00000000, 0x000001ff }, |
| 12798 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, |
| 12799 | 0x00000000, 0x000007ff }, |
| 12800 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, |
| 12801 | 0x00000000, 0x000001ff }, |
| 12802 | |
| 12803 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, |
| 12804 | }; |
| 12805 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12806 | is_5705 = is_5750 = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12807 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12808 | is_5705 = 1; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12809 | if (tg3_flag(tp, 5750_PLUS)) |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12810 | is_5750 = 1; |
| 12811 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12812 | |
| 12813 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { |
| 12814 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) |
| 12815 | continue; |
| 12816 | |
| 12817 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) |
| 12818 | continue; |
| 12819 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12820 | if (tg3_flag(tp, IS_5788) && |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12821 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
| 12822 | continue; |
| 12823 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12824 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
| 12825 | continue; |
| 12826 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12827 | offset = (u32) reg_tbl[i].offset; |
| 12828 | read_mask = reg_tbl[i].read_mask; |
| 12829 | write_mask = reg_tbl[i].write_mask; |
| 12830 | |
| 12831 | /* Save the original register content */ |
| 12832 | save_val = tr32(offset); |
| 12833 | |
| 12834 | /* Determine the read-only value. */ |
| 12835 | read_val = save_val & read_mask; |
| 12836 | |
| 12837 | /* Write zero to the register, then make sure the read-only bits |
| 12838 | * are not changed and the read/write bits are all zeros. |
| 12839 | */ |
| 12840 | tw32(offset, 0); |
| 12841 | |
| 12842 | val = tr32(offset); |
| 12843 | |
| 12844 | /* Test the read-only and read/write bits. */ |
| 12845 | if (((val & read_mask) != read_val) || (val & write_mask)) |
| 12846 | goto out; |
| 12847 | |
| 12848 | /* Write ones to all the bits defined by RdMask and WrMask, then |
| 12849 | * make sure the read-only bits are not changed and the |
| 12850 | * read/write bits are all ones. |
| 12851 | */ |
| 12852 | tw32(offset, read_mask | write_mask); |
| 12853 | |
| 12854 | val = tr32(offset); |
| 12855 | |
| 12856 | /* Test the read-only bits. */ |
| 12857 | if ((val & read_mask) != read_val) |
| 12858 | goto out; |
| 12859 | |
| 12860 | /* Test the read/write bits. */ |
| 12861 | if ((val & write_mask) != write_mask) |
| 12862 | goto out; |
| 12863 | |
| 12864 | tw32(offset, save_val); |
| 12865 | } |
| 12866 | |
| 12867 | return 0; |
| 12868 | |
| 12869 | out: |
Michael Chan | 9f88f29 | 2006-12-07 00:22:54 -0800 | [diff] [blame] | 12870 | if (netif_msg_hw(tp)) |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 12871 | netdev_err(tp->dev, |
| 12872 | "Register test failed at offset %x\n", offset); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 12873 | tw32(offset, save_val); |
| 12874 | return -EIO; |
| 12875 | } |
| 12876 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12877 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
| 12878 | { |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 12879 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12880 | int i; |
| 12881 | u32 j; |
| 12882 | |
Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 12883 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12884 | for (j = 0; j < len; j += 4) { |
| 12885 | u32 val; |
| 12886 | |
| 12887 | tg3_write_mem(tp, offset + j, test_pattern[i]); |
| 12888 | tg3_read_mem(tp, offset + j, &val); |
| 12889 | if (val != test_pattern[i]) |
| 12890 | return -EIO; |
| 12891 | } |
| 12892 | } |
| 12893 | return 0; |
| 12894 | } |
| 12895 | |
| 12896 | static int tg3_test_memory(struct tg3 *tp) |
| 12897 | { |
| 12898 | static struct mem_entry { |
| 12899 | u32 offset; |
| 12900 | u32 len; |
| 12901 | } mem_tbl_570x[] = { |
Michael Chan | 3869019 | 2005-12-19 16:27:28 -0800 | [diff] [blame] | 12902 | { 0x00000000, 0x00b50}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12903 | { 0x00002000, 0x1c000}, |
| 12904 | { 0xffffffff, 0x00000} |
| 12905 | }, mem_tbl_5705[] = { |
| 12906 | { 0x00000100, 0x0000c}, |
| 12907 | { 0x00000200, 0x00008}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12908 | { 0x00004000, 0x00800}, |
| 12909 | { 0x00006000, 0x01000}, |
| 12910 | { 0x00008000, 0x02000}, |
| 12911 | { 0x00010000, 0x0e000}, |
| 12912 | { 0xffffffff, 0x00000} |
Michael Chan | 79f4d13 | 2006-03-20 22:28:57 -0800 | [diff] [blame] | 12913 | }, mem_tbl_5755[] = { |
| 12914 | { 0x00000200, 0x00008}, |
| 12915 | { 0x00004000, 0x00800}, |
| 12916 | { 0x00006000, 0x00800}, |
| 12917 | { 0x00008000, 0x02000}, |
| 12918 | { 0x00010000, 0x0c000}, |
| 12919 | { 0xffffffff, 0x00000} |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 12920 | }, mem_tbl_5906[] = { |
| 12921 | { 0x00000200, 0x00008}, |
| 12922 | { 0x00004000, 0x00400}, |
| 12923 | { 0x00006000, 0x00400}, |
| 12924 | { 0x00008000, 0x01000}, |
| 12925 | { 0x00010000, 0x01000}, |
| 12926 | { 0xffffffff, 0x00000} |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 12927 | }, mem_tbl_5717[] = { |
| 12928 | { 0x00000200, 0x00008}, |
| 12929 | { 0x00010000, 0x0a000}, |
| 12930 | { 0x00020000, 0x13c00}, |
| 12931 | { 0xffffffff, 0x00000} |
| 12932 | }, mem_tbl_57765[] = { |
| 12933 | { 0x00000200, 0x00008}, |
| 12934 | { 0x00004000, 0x00800}, |
| 12935 | { 0x00006000, 0x09800}, |
| 12936 | { 0x00010000, 0x0a000}, |
| 12937 | { 0xffffffff, 0x00000} |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12938 | }; |
| 12939 | struct mem_entry *mem_tbl; |
| 12940 | int err = 0; |
| 12941 | int i; |
| 12942 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12943 | if (tg3_flag(tp, 5717_PLUS)) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 12944 | mem_tbl = mem_tbl_5717; |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 12945 | else if (tg3_flag(tp, 57765_CLASS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 12946 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 12947 | mem_tbl = mem_tbl_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12948 | else if (tg3_flag(tp, 5755_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12949 | mem_tbl = mem_tbl_5755; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 12950 | else if (tg3_asic_rev(tp) == ASIC_REV_5906) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12951 | mem_tbl = mem_tbl_5906; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 12952 | else if (tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12953 | mem_tbl = mem_tbl_5705; |
| 12954 | else |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12955 | mem_tbl = mem_tbl_570x; |
| 12956 | |
| 12957 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 12958 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
| 12959 | if (err) |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12960 | break; |
| 12961 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12962 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 12963 | return err; |
| 12964 | } |
| 12965 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12966 | #define TG3_TSO_MSS 500 |
| 12967 | |
| 12968 | #define TG3_TSO_IP_HDR_LEN 20 |
| 12969 | #define TG3_TSO_TCP_HDR_LEN 20 |
| 12970 | #define TG3_TSO_TCP_OPT_LEN 12 |
| 12971 | |
| 12972 | static const u8 tg3_tso_header[] = { |
| 12973 | 0x08, 0x00, |
| 12974 | 0x45, 0x00, 0x00, 0x00, |
| 12975 | 0x00, 0x00, 0x40, 0x00, |
| 12976 | 0x40, 0x06, 0x00, 0x00, |
| 12977 | 0x0a, 0x00, 0x00, 0x01, |
| 12978 | 0x0a, 0x00, 0x00, 0x02, |
| 12979 | 0x0d, 0x00, 0xe0, 0x00, |
| 12980 | 0x00, 0x00, 0x01, 0x00, |
| 12981 | 0x00, 0x00, 0x02, 0x00, |
| 12982 | 0x80, 0x10, 0x10, 0x00, |
| 12983 | 0x14, 0x09, 0x00, 0x00, |
| 12984 | 0x01, 0x01, 0x08, 0x0a, |
| 12985 | 0x11, 0x11, 0x11, 0x11, |
| 12986 | 0x11, 0x11, 0x11, 0x11, |
| 12987 | }; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 12988 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 12989 | 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] | 12990 | { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 12991 | u32 rx_start_idx, rx_idx, tx_idx, opaque_key; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 12992 | 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] | 12993 | u32 budget; |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 12994 | struct sk_buff *skb; |
| 12995 | u8 *tx_data, *rx_data; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 12996 | dma_addr_t map; |
| 12997 | int num_pkts, tx_len, rx_len, i, err; |
| 12998 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 12999 | struct tg3_napi *tnapi, *rnapi; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 13000 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13001 | |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 13002 | tnapi = &tp->napi[0]; |
| 13003 | rnapi = &tp->napi[0]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 13004 | if (tp->irq_cnt > 1) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13005 | if (tg3_flag(tp, ENABLE_RSS)) |
Matt Carlson | 1da85aa | 2010-09-30 10:34:34 +0000 | [diff] [blame] | 13006 | rnapi = &tp->napi[1]; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13007 | if (tg3_flag(tp, ENABLE_TSS)) |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 13008 | tnapi = &tp->napi[1]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 13009 | } |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 13010 | coal_now = tnapi->coal_now | rnapi->coal_now; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 13011 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13012 | err = -EIO; |
| 13013 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 13014 | tx_len = pktsz; |
David S. Miller | a20e9c6 | 2006-07-31 22:38:16 -0700 | [diff] [blame] | 13015 | skb = netdev_alloc_skb(tp->dev, tx_len); |
Jesper Juhl | a50bb7b | 2006-05-09 23:14:35 -0700 | [diff] [blame] | 13016 | if (!skb) |
| 13017 | return -ENOMEM; |
| 13018 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13019 | tx_data = skb_put(skb, tx_len); |
| 13020 | memcpy(tx_data, tp->dev->dev_addr, 6); |
| 13021 | memset(tx_data + 6, 0x0, 8); |
| 13022 | |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 13023 | tw32(MAC_RX_MTU_SIZE, tx_len + ETH_FCS_LEN); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13024 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13025 | if (tso_loopback) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13026 | struct iphdr *iph = (struct iphdr *)&tx_data[ETH_HLEN]; |
| 13027 | |
| 13028 | u32 hdr_len = TG3_TSO_IP_HDR_LEN + TG3_TSO_TCP_HDR_LEN + |
| 13029 | TG3_TSO_TCP_OPT_LEN; |
| 13030 | |
| 13031 | memcpy(tx_data + ETH_ALEN * 2, tg3_tso_header, |
| 13032 | sizeof(tg3_tso_header)); |
| 13033 | mss = TG3_TSO_MSS; |
| 13034 | |
| 13035 | val = tx_len - ETH_ALEN * 2 - sizeof(tg3_tso_header); |
| 13036 | num_pkts = DIV_ROUND_UP(val, TG3_TSO_MSS); |
| 13037 | |
| 13038 | /* Set the total length field in the IP header */ |
| 13039 | iph->tot_len = htons((u16)(mss + hdr_len)); |
| 13040 | |
| 13041 | base_flags = (TXD_FLAG_CPU_PRE_DMA | |
| 13042 | TXD_FLAG_CPU_POST_DMA); |
| 13043 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13044 | if (tg3_flag(tp, HW_TSO_1) || |
| 13045 | tg3_flag(tp, HW_TSO_2) || |
| 13046 | tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13047 | struct tcphdr *th; |
| 13048 | val = ETH_HLEN + TG3_TSO_IP_HDR_LEN; |
| 13049 | th = (struct tcphdr *)&tx_data[val]; |
| 13050 | th->check = 0; |
| 13051 | } else |
| 13052 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
| 13053 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13054 | if (tg3_flag(tp, HW_TSO_3)) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13055 | mss |= (hdr_len & 0xc) << 12; |
| 13056 | if (hdr_len & 0x10) |
| 13057 | base_flags |= 0x00000010; |
| 13058 | base_flags |= (hdr_len & 0x3e0) << 5; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13059 | } else if (tg3_flag(tp, HW_TSO_2)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13060 | mss |= hdr_len << 9; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13061 | else if (tg3_flag(tp, HW_TSO_1) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 13062 | tg3_asic_rev(tp) == ASIC_REV_5705) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13063 | mss |= (TG3_TSO_TCP_OPT_LEN << 9); |
| 13064 | } else { |
| 13065 | base_flags |= (TG3_TSO_TCP_OPT_LEN << 10); |
| 13066 | } |
| 13067 | |
| 13068 | data_off = ETH_ALEN * 2 + sizeof(tg3_tso_header); |
| 13069 | } else { |
| 13070 | num_pkts = 1; |
| 13071 | data_off = ETH_HLEN; |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 13072 | |
| 13073 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 13074 | tx_len > VLAN_ETH_FRAME_LEN) |
| 13075 | base_flags |= TXD_FLAG_JMB_PKT; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13076 | } |
| 13077 | |
| 13078 | for (i = data_off; i < tx_len; i++) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13079 | tx_data[i] = (u8) (i & 0xff); |
| 13080 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 13081 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
| 13082 | if (pci_dma_mapping_error(tp->pdev, map)) { |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 13083 | dev_kfree_skb(skb); |
| 13084 | return -EIO; |
| 13085 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13086 | |
Matt Carlson | 0d681b2 | 2011-07-27 14:20:49 +0000 | [diff] [blame] | 13087 | val = tnapi->tx_prod; |
| 13088 | tnapi->tx_buffers[val].skb = skb; |
| 13089 | dma_unmap_addr_set(&tnapi->tx_buffers[val], mapping, map); |
| 13090 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13091 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 13092 | rnapi->coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13093 | |
| 13094 | udelay(10); |
| 13095 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 13096 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13097 | |
Matt Carlson | 84b67b2 | 2011-07-27 14:20:52 +0000 | [diff] [blame] | 13098 | budget = tg3_tx_avail(tnapi); |
| 13099 | if (tg3_tx_frag_set(tnapi, &val, &budget, map, tx_len, |
Matt Carlson | d1a3b73 | 2011-07-27 14:20:51 +0000 | [diff] [blame] | 13100 | base_flags | TXD_FLAG_END, mss, 0)) { |
| 13101 | tnapi->tx_buffers[val].skb = NULL; |
| 13102 | dev_kfree_skb(skb); |
| 13103 | return -EIO; |
| 13104 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13105 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 13106 | tnapi->tx_prod++; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13107 | |
Michael Chan | 6541b80 | 2012-03-04 14:48:14 +0000 | [diff] [blame] | 13108 | /* Sync BD data before updating mailbox */ |
| 13109 | wmb(); |
| 13110 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 13111 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 13112 | tr32_mailbox(tnapi->prodmbox); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13113 | |
| 13114 | udelay(10); |
| 13115 | |
Matt Carlson | 303fc92 | 2009-11-02 14:27:34 +0000 | [diff] [blame] | 13116 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
| 13117 | for (i = 0; i < 35; i++) { |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13118 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 13119 | coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13120 | |
| 13121 | udelay(10); |
| 13122 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 13123 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 13124 | rx_idx = rnapi->hw_status->idx[0].rx_producer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 13125 | if ((tx_idx == tnapi->tx_prod) && |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13126 | (rx_idx == (rx_start_idx + num_pkts))) |
| 13127 | break; |
| 13128 | } |
| 13129 | |
Matt Carlson | ba1142e | 2011-11-04 09:15:00 +0000 | [diff] [blame] | 13130 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod - 1, -1); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13131 | dev_kfree_skb(skb); |
| 13132 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 13133 | if (tx_idx != tnapi->tx_prod) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13134 | goto out; |
| 13135 | |
| 13136 | if (rx_idx != rx_start_idx + num_pkts) |
| 13137 | goto out; |
| 13138 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13139 | val = data_off; |
| 13140 | while (rx_idx != rx_start_idx) { |
| 13141 | desc = &rnapi->rx_rcb[rx_start_idx++]; |
| 13142 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 13143 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13144 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13145 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 13146 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 13147 | goto out; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13148 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13149 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) |
| 13150 | - ETH_FCS_LEN; |
| 13151 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13152 | if (!tso_loopback) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13153 | if (rx_len != tx_len) |
| 13154 | goto out; |
| 13155 | |
| 13156 | if (pktsz <= TG3_RX_STD_DMA_SZ - ETH_FCS_LEN) { |
| 13157 | if (opaque_key != RXD_OPAQUE_RING_STD) |
| 13158 | goto out; |
| 13159 | } else { |
| 13160 | if (opaque_key != RXD_OPAQUE_RING_JUMBO) |
| 13161 | goto out; |
| 13162 | } |
| 13163 | } else if ((desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 13164 | (desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
Matt Carlson | 54e0a67 | 2011-05-19 12:12:50 +0000 | [diff] [blame] | 13165 | >> RXD_TCPCSUM_SHIFT != 0xffff) { |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13166 | goto out; |
| 13167 | } |
| 13168 | |
| 13169 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 13170 | rx_data = tpr->rx_std_buffers[desc_idx].data; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13171 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], |
| 13172 | mapping); |
| 13173 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 13174 | rx_data = tpr->rx_jmb_buffers[desc_idx].data; |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13175 | map = dma_unmap_addr(&tpr->rx_jmb_buffers[desc_idx], |
| 13176 | mapping); |
| 13177 | } else |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 13178 | goto out; |
| 13179 | |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13180 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, |
| 13181 | PCI_DMA_FROMDEVICE); |
| 13182 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 13183 | rx_data += TG3_RX_OFFSET(tp); |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13184 | for (i = data_off; i < rx_len; i++, val++) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 13185 | if (*(rx_data + i) != (u8) (val & 0xff)) |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13186 | goto out; |
| 13187 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 13188 | } |
| 13189 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13190 | err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13191 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 13192 | /* tg3_free_rings will unmap and free the rx_data */ |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13193 | out: |
| 13194 | return err; |
| 13195 | } |
| 13196 | |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 13197 | #define TG3_STD_LOOPBACK_FAILED 1 |
| 13198 | #define TG3_JMB_LOOPBACK_FAILED 2 |
Matt Carlson | bb158d6 | 2011-04-25 12:42:47 +0000 | [diff] [blame] | 13199 | #define TG3_TSO_LOOPBACK_FAILED 4 |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13200 | #define TG3_LOOPBACK_FAILED \ |
| 13201 | (TG3_STD_LOOPBACK_FAILED | \ |
| 13202 | TG3_JMB_LOOPBACK_FAILED | \ |
| 13203 | TG3_TSO_LOOPBACK_FAILED) |
Matt Carlson | 00c266b | 2011-04-25 12:42:46 +0000 | [diff] [blame] | 13204 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13205 | 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] | 13206 | { |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13207 | int err = -EIO; |
Matt Carlson | 2215e24 | 2011-08-19 13:58:19 +0000 | [diff] [blame] | 13208 | u32 eee_cap; |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 13209 | u32 jmb_pkt_sz = 9000; |
| 13210 | |
| 13211 | if (tp->dma_limit) |
| 13212 | jmb_pkt_sz = tp->dma_limit - ETH_HLEN; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 13213 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 13214 | eee_cap = tp->phy_flags & TG3_PHYFLG_EEE_CAP; |
| 13215 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; |
| 13216 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13217 | if (!netif_running(tp->dev)) { |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13218 | data[TG3_MAC_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 13219 | data[TG3_PHY_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13220 | if (do_extlpbk) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13221 | data[TG3_EXT_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13222 | goto done; |
| 13223 | } |
| 13224 | |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 13225 | err = tg3_reset_hw(tp, true); |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 13226 | if (err) { |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13227 | data[TG3_MAC_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 13228 | data[TG3_PHY_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13229 | if (do_extlpbk) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13230 | data[TG3_EXT_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 13231 | goto done; |
| 13232 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 13233 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13234 | if (tg3_flag(tp, ENABLE_RSS)) { |
Matt Carlson | 4a85f09 | 2011-04-20 07:57:37 +0000 | [diff] [blame] | 13235 | int i; |
| 13236 | |
| 13237 | /* Reroute all rx packets to the 1st queue */ |
| 13238 | for (i = MAC_RSS_INDIR_TBL_0; |
| 13239 | i < MAC_RSS_INDIR_TBL_0 + TG3_RSS_INDIR_TBL_SIZE; i += 4) |
| 13240 | tw32(i, 0x0); |
| 13241 | } |
| 13242 | |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 13243 | /* HW errata - mac loopback fails in some cases on 5780. |
| 13244 | * Normal traffic and PHY loopback are not affected by |
| 13245 | * errata. Also, the MAC loopback test is deprecated for |
| 13246 | * all newer ASIC revisions. |
| 13247 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 13248 | if (tg3_asic_rev(tp) != ASIC_REV_5780 && |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 13249 | !tg3_flag(tp, CPMU_PRESENT)) { |
| 13250 | tg3_mac_loopback(tp, true); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13251 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13252 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13253 | data[TG3_MAC_LOOPB_TEST] |= TG3_STD_LOOPBACK_FAILED; |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 13254 | |
| 13255 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 13256 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13257 | data[TG3_MAC_LOOPB_TEST] |= TG3_JMB_LOOPBACK_FAILED; |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 13258 | |
| 13259 | tg3_mac_loopback(tp, false); |
| 13260 | } |
Matt Carlson | 4852a86 | 2011-04-13 11:05:07 +0000 | [diff] [blame] | 13261 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13262 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13263 | !tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 13264 | int i; |
| 13265 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13266 | tg3_phy_lpbk_set(tp, 0, false); |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 13267 | |
| 13268 | /* Wait for link */ |
| 13269 | for (i = 0; i < 100; i++) { |
| 13270 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 13271 | break; |
| 13272 | mdelay(1); |
| 13273 | } |
| 13274 | |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13275 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13276 | data[TG3_PHY_LOOPB_TEST] |= TG3_STD_LOOPBACK_FAILED; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13277 | if (tg3_flag(tp, TSO_CAPABLE) && |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13278 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13279 | data[TG3_PHY_LOOPB_TEST] |= TG3_TSO_LOOPBACK_FAILED; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13280 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 13281 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13282 | data[TG3_PHY_LOOPB_TEST] |= TG3_JMB_LOOPBACK_FAILED; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 13283 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13284 | if (do_extlpbk) { |
| 13285 | tg3_phy_lpbk_set(tp, 0, true); |
| 13286 | |
| 13287 | /* All link indications report up, but the hardware |
| 13288 | * isn't really ready for about 20 msec. Double it |
| 13289 | * to be sure. |
| 13290 | */ |
| 13291 | mdelay(40); |
| 13292 | |
| 13293 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13294 | data[TG3_EXT_LOOPB_TEST] |= |
| 13295 | TG3_STD_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13296 | if (tg3_flag(tp, TSO_CAPABLE) && |
| 13297 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13298 | data[TG3_EXT_LOOPB_TEST] |= |
| 13299 | TG3_TSO_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13300 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
Michael Chan | c441b45 | 2012-03-04 14:48:13 +0000 | [diff] [blame] | 13301 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13302 | data[TG3_EXT_LOOPB_TEST] |= |
| 13303 | TG3_JMB_LOOPBACK_FAILED; |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13304 | } |
| 13305 | |
Matt Carlson | 5e5a7f3 | 2011-08-19 13:58:21 +0000 | [diff] [blame] | 13306 | /* Re-enable gphy autopowerdown. */ |
| 13307 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
| 13308 | tg3_phy_toggle_apd(tp, true); |
| 13309 | } |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 13310 | |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13311 | err = (data[TG3_MAC_LOOPB_TEST] | data[TG3_PHY_LOOPB_TEST] | |
| 13312 | data[TG3_EXT_LOOPB_TEST]) ? -EIO : 0; |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13313 | |
Matt Carlson | ab78904 | 2011-01-25 15:58:54 +0000 | [diff] [blame] | 13314 | done: |
| 13315 | tp->phy_flags |= eee_cap; |
| 13316 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 13317 | return err; |
| 13318 | } |
| 13319 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 13320 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
| 13321 | u64 *data) |
| 13322 | { |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 13323 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13324 | bool doextlpbk = etest->flags & ETH_TEST_FL_EXTERNAL_LB; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 13325 | |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 13326 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
| 13327 | tg3_power_up(tp)) { |
| 13328 | etest->flags |= ETH_TEST_FL_FAILED; |
| 13329 | memset(data, 1, sizeof(u64) * TG3_NUM_TEST); |
| 13330 | return; |
| 13331 | } |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 13332 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 13333 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
| 13334 | |
| 13335 | if (tg3_test_nvram(tp) != 0) { |
| 13336 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13337 | data[TG3_NVRAM_TEST] = 1; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 13338 | } |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13339 | if (!doextlpbk && tg3_test_link(tp)) { |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 13340 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13341 | data[TG3_LINK_TEST] = 1; |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 13342 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13343 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13344 | int err, err2 = 0, irq_sync = 0; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13345 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 13346 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13347 | tg3_phy_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 13348 | tg3_netif_stop(tp); |
| 13349 | irq_sync = 1; |
| 13350 | } |
| 13351 | |
| 13352 | tg3_full_lock(tp, irq_sync); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13353 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 13354 | err = tg3_nvram_lock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13355 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13356 | if (!tg3_flag(tp, 5705_PLUS)) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13357 | tg3_halt_cpu(tp, TX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 13358 | if (!err) |
| 13359 | tg3_nvram_unlock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13360 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13361 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | d9ab5ad1 | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 13362 | tg3_phy_reset(tp); |
| 13363 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13364 | if (tg3_test_registers(tp) != 0) { |
| 13365 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13366 | data[TG3_REGISTER_TEST] = 1; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13367 | } |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13368 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 13369 | if (tg3_test_memory(tp) != 0) { |
| 13370 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13371 | data[TG3_MEMORY_TEST] = 1; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 13372 | } |
Matt Carlson | 28a4595 | 2011-08-19 13:58:22 +0000 | [diff] [blame] | 13373 | |
Matt Carlson | 941ec90 | 2011-08-19 13:58:23 +0000 | [diff] [blame] | 13374 | if (doextlpbk) |
| 13375 | etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; |
| 13376 | |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13377 | if (tg3_test_loopback(tp, data, doextlpbk)) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 13378 | etest->flags |= ETH_TEST_FL_FAILED; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13379 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 13380 | tg3_full_unlock(tp); |
| 13381 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 13382 | if (tg3_test_interrupt(tp) != 0) { |
| 13383 | etest->flags |= ETH_TEST_FL_FAILED; |
Nithin Nayak Sujir | 93df8b8 | 2012-11-14 14:44:28 +0000 | [diff] [blame] | 13384 | data[TG3_INTERRUPT_TEST] = 1; |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 13385 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 13386 | |
| 13387 | tg3_full_lock(tp, 0); |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 13388 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13389 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 13390 | if (netif_running(dev)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13391 | tg3_flag_set(tp, INIT_COMPLETE); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 13392 | err2 = tg3_restart_hw(tp, true); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13393 | if (!err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 13394 | tg3_netif_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13395 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 13396 | |
| 13397 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13398 | |
| 13399 | if (irq_sync && !err2) |
| 13400 | tg3_phy_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 13401 | } |
Matt Carlson | 8009606 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 13402 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 13403 | tg3_power_down(tp); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 13404 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 13405 | } |
| 13406 | |
Matt Carlson | 0a633ac | 2012-12-03 19:36:59 +0000 | [diff] [blame] | 13407 | static int tg3_hwtstamp_ioctl(struct net_device *dev, |
| 13408 | struct ifreq *ifr, int cmd) |
| 13409 | { |
| 13410 | struct tg3 *tp = netdev_priv(dev); |
| 13411 | struct hwtstamp_config stmpconf; |
| 13412 | |
| 13413 | if (!tg3_flag(tp, PTP_CAPABLE)) |
| 13414 | return -EINVAL; |
| 13415 | |
| 13416 | if (copy_from_user(&stmpconf, ifr->ifr_data, sizeof(stmpconf))) |
| 13417 | return -EFAULT; |
| 13418 | |
| 13419 | if (stmpconf.flags) |
| 13420 | return -EINVAL; |
| 13421 | |
| 13422 | switch (stmpconf.tx_type) { |
| 13423 | case HWTSTAMP_TX_ON: |
| 13424 | tg3_flag_set(tp, TX_TSTAMP_EN); |
| 13425 | break; |
| 13426 | case HWTSTAMP_TX_OFF: |
| 13427 | tg3_flag_clear(tp, TX_TSTAMP_EN); |
| 13428 | break; |
| 13429 | default: |
| 13430 | return -ERANGE; |
| 13431 | } |
| 13432 | |
| 13433 | switch (stmpconf.rx_filter) { |
| 13434 | case HWTSTAMP_FILTER_NONE: |
| 13435 | tp->rxptpctl = 0; |
| 13436 | break; |
| 13437 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 13438 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | |
| 13439 | TG3_RX_PTP_CTL_ALL_V1_EVENTS; |
| 13440 | break; |
| 13441 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 13442 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | |
| 13443 | TG3_RX_PTP_CTL_SYNC_EVNT; |
| 13444 | break; |
| 13445 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 13446 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | |
| 13447 | TG3_RX_PTP_CTL_DELAY_REQ; |
| 13448 | break; |
| 13449 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 13450 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | |
| 13451 | TG3_RX_PTP_CTL_ALL_V2_EVENTS; |
| 13452 | break; |
| 13453 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 13454 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | |
| 13455 | TG3_RX_PTP_CTL_ALL_V2_EVENTS; |
| 13456 | break; |
| 13457 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 13458 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | |
| 13459 | TG3_RX_PTP_CTL_ALL_V2_EVENTS; |
| 13460 | break; |
| 13461 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 13462 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | |
| 13463 | TG3_RX_PTP_CTL_SYNC_EVNT; |
| 13464 | break; |
| 13465 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 13466 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | |
| 13467 | TG3_RX_PTP_CTL_SYNC_EVNT; |
| 13468 | break; |
| 13469 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 13470 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | |
| 13471 | TG3_RX_PTP_CTL_SYNC_EVNT; |
| 13472 | break; |
| 13473 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 13474 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | |
| 13475 | TG3_RX_PTP_CTL_DELAY_REQ; |
| 13476 | break; |
| 13477 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 13478 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | |
| 13479 | TG3_RX_PTP_CTL_DELAY_REQ; |
| 13480 | break; |
| 13481 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 13482 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | |
| 13483 | TG3_RX_PTP_CTL_DELAY_REQ; |
| 13484 | break; |
| 13485 | default: |
| 13486 | return -ERANGE; |
| 13487 | } |
| 13488 | |
| 13489 | if (netif_running(dev) && tp->rxptpctl) |
| 13490 | tw32(TG3_RX_PTP_CTL, |
| 13491 | tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK); |
| 13492 | |
| 13493 | return copy_to_user(ifr->ifr_data, &stmpconf, sizeof(stmpconf)) ? |
| 13494 | -EFAULT : 0; |
| 13495 | } |
| 13496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13497 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 13498 | { |
| 13499 | struct mii_ioctl_data *data = if_mii(ifr); |
| 13500 | struct tg3 *tp = netdev_priv(dev); |
| 13501 | int err; |
| 13502 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13503 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 13504 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13505 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13506 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 13507 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 13508 | return phy_mii_ioctl(phydev, ifr, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13509 | } |
| 13510 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 13511 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13512 | case SIOCGMIIPHY: |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 13513 | data->phy_id = tp->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13514 | |
| 13515 | /* fallthru */ |
| 13516 | case SIOCGMIIREG: { |
| 13517 | u32 mii_regval; |
| 13518 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13519 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13520 | break; /* We have no PHY */ |
| 13521 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 13522 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 13523 | return -EAGAIN; |
| 13524 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 13525 | spin_lock_bh(&tp->lock); |
Hauke Mehrtens | 5c35804 | 2013-02-07 05:37:38 +0000 | [diff] [blame] | 13526 | err = __tg3_readphy(tp, data->phy_id & 0x1f, |
| 13527 | data->reg_num & 0x1f, &mii_regval); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 13528 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13529 | |
| 13530 | data->val_out = mii_regval; |
| 13531 | |
| 13532 | return err; |
| 13533 | } |
| 13534 | |
| 13535 | case SIOCSMIIREG: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13536 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13537 | break; /* We have no PHY */ |
| 13538 | |
Matt Carlson | 34eea5a | 2011-04-20 07:57:38 +0000 | [diff] [blame] | 13539 | if (!netif_running(dev)) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 13540 | return -EAGAIN; |
| 13541 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 13542 | spin_lock_bh(&tp->lock); |
Hauke Mehrtens | 5c35804 | 2013-02-07 05:37:38 +0000 | [diff] [blame] | 13543 | err = __tg3_writephy(tp, data->phy_id & 0x1f, |
| 13544 | data->reg_num & 0x1f, data->val_in); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 13545 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13546 | |
| 13547 | return err; |
| 13548 | |
Matt Carlson | 0a633ac | 2012-12-03 19:36:59 +0000 | [diff] [blame] | 13549 | case SIOCSHWTSTAMP: |
| 13550 | return tg3_hwtstamp_ioctl(dev, ifr, cmd); |
| 13551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13552 | default: |
| 13553 | /* do nothing */ |
| 13554 | break; |
| 13555 | } |
| 13556 | return -EOPNOTSUPP; |
| 13557 | } |
| 13558 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 13559 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 13560 | { |
| 13561 | struct tg3 *tp = netdev_priv(dev); |
| 13562 | |
| 13563 | memcpy(ec, &tp->coal, sizeof(*ec)); |
| 13564 | return 0; |
| 13565 | } |
| 13566 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 13567 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 13568 | { |
| 13569 | struct tg3 *tp = netdev_priv(dev); |
| 13570 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; |
| 13571 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; |
| 13572 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13573 | if (!tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 13574 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
| 13575 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; |
| 13576 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; |
| 13577 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; |
| 13578 | } |
| 13579 | |
| 13580 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || |
| 13581 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || |
| 13582 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || |
| 13583 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || |
| 13584 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || |
| 13585 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || |
| 13586 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || |
| 13587 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || |
| 13588 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || |
| 13589 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) |
| 13590 | return -EINVAL; |
| 13591 | |
| 13592 | /* No rx interrupts will be generated if both are zero */ |
| 13593 | if ((ec->rx_coalesce_usecs == 0) && |
| 13594 | (ec->rx_max_coalesced_frames == 0)) |
| 13595 | return -EINVAL; |
| 13596 | |
| 13597 | /* No tx interrupts will be generated if both are zero */ |
| 13598 | if ((ec->tx_coalesce_usecs == 0) && |
| 13599 | (ec->tx_max_coalesced_frames == 0)) |
| 13600 | return -EINVAL; |
| 13601 | |
| 13602 | /* Only copy relevant parameters, ignore all others. */ |
| 13603 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; |
| 13604 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; |
| 13605 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; |
| 13606 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; |
| 13607 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; |
| 13608 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; |
| 13609 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; |
| 13610 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; |
| 13611 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; |
| 13612 | |
| 13613 | if (netif_running(dev)) { |
| 13614 | tg3_full_lock(tp, 0); |
| 13615 | __tg3_set_coalesce(tp, &tp->coal); |
| 13616 | tg3_full_unlock(tp); |
| 13617 | } |
| 13618 | return 0; |
| 13619 | } |
| 13620 | |
Nithin Sujir | 1cbf9eb | 2013-05-18 06:26:55 +0000 | [diff] [blame] | 13621 | static int tg3_set_eee(struct net_device *dev, struct ethtool_eee *edata) |
| 13622 | { |
| 13623 | struct tg3 *tp = netdev_priv(dev); |
| 13624 | |
| 13625 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) { |
| 13626 | netdev_warn(tp->dev, "Board does not support EEE!\n"); |
| 13627 | return -EOPNOTSUPP; |
| 13628 | } |
| 13629 | |
| 13630 | if (edata->advertised != tp->eee.advertised) { |
| 13631 | netdev_warn(tp->dev, |
| 13632 | "Direct manipulation of EEE advertisement is not supported\n"); |
| 13633 | return -EINVAL; |
| 13634 | } |
| 13635 | |
| 13636 | if (edata->tx_lpi_timer > TG3_CPMU_DBTMR1_LNKIDLE_MAX) { |
| 13637 | netdev_warn(tp->dev, |
| 13638 | "Maximal Tx Lpi timer supported is %#x(u)\n", |
| 13639 | TG3_CPMU_DBTMR1_LNKIDLE_MAX); |
| 13640 | return -EINVAL; |
| 13641 | } |
| 13642 | |
| 13643 | tp->eee = *edata; |
| 13644 | |
| 13645 | tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; |
| 13646 | tg3_warn_mgmt_link_flap(tp); |
| 13647 | |
| 13648 | if (netif_running(tp->dev)) { |
| 13649 | tg3_full_lock(tp, 0); |
| 13650 | tg3_setup_eee(tp); |
| 13651 | tg3_phy_reset(tp); |
| 13652 | tg3_full_unlock(tp); |
| 13653 | } |
| 13654 | |
| 13655 | return 0; |
| 13656 | } |
| 13657 | |
| 13658 | static int tg3_get_eee(struct net_device *dev, struct ethtool_eee *edata) |
| 13659 | { |
| 13660 | struct tg3 *tp = netdev_priv(dev); |
| 13661 | |
| 13662 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) { |
| 13663 | netdev_warn(tp->dev, |
| 13664 | "Board does not support EEE!\n"); |
| 13665 | return -EOPNOTSUPP; |
| 13666 | } |
| 13667 | |
| 13668 | *edata = tp->eee; |
| 13669 | return 0; |
| 13670 | } |
| 13671 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 13672 | static const struct ethtool_ops tg3_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13673 | .get_settings = tg3_get_settings, |
| 13674 | .set_settings = tg3_set_settings, |
| 13675 | .get_drvinfo = tg3_get_drvinfo, |
| 13676 | .get_regs_len = tg3_get_regs_len, |
| 13677 | .get_regs = tg3_get_regs, |
| 13678 | .get_wol = tg3_get_wol, |
| 13679 | .set_wol = tg3_set_wol, |
| 13680 | .get_msglevel = tg3_get_msglevel, |
| 13681 | .set_msglevel = tg3_set_msglevel, |
| 13682 | .nway_reset = tg3_nway_reset, |
| 13683 | .get_link = ethtool_op_get_link, |
| 13684 | .get_eeprom_len = tg3_get_eeprom_len, |
| 13685 | .get_eeprom = tg3_get_eeprom, |
| 13686 | .set_eeprom = tg3_set_eeprom, |
| 13687 | .get_ringparam = tg3_get_ringparam, |
| 13688 | .set_ringparam = tg3_set_ringparam, |
| 13689 | .get_pauseparam = tg3_get_pauseparam, |
| 13690 | .set_pauseparam = tg3_set_pauseparam, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 13691 | .self_test = tg3_self_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13692 | .get_strings = tg3_get_strings, |
stephen hemminger | 81b8709 | 2011-04-04 08:43:50 +0000 | [diff] [blame] | 13693 | .set_phys_id = tg3_set_phys_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13694 | .get_ethtool_stats = tg3_get_ethtool_stats, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 13695 | .get_coalesce = tg3_get_coalesce, |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 13696 | .set_coalesce = tg3_set_coalesce, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 13697 | .get_sset_count = tg3_get_sset_count, |
Matt Carlson | 9041547 | 2011-12-16 13:33:23 +0000 | [diff] [blame] | 13698 | .get_rxnfc = tg3_get_rxnfc, |
| 13699 | .get_rxfh_indir_size = tg3_get_rxfh_indir_size, |
| 13700 | .get_rxfh_indir = tg3_get_rxfh_indir, |
| 13701 | .set_rxfh_indir = tg3_set_rxfh_indir, |
Michael Chan | 0968169 | 2012-09-28 07:12:42 +0000 | [diff] [blame] | 13702 | .get_channels = tg3_get_channels, |
| 13703 | .set_channels = tg3_set_channels, |
Matt Carlson | 7d41e49 | 2012-12-03 19:36:58 +0000 | [diff] [blame] | 13704 | .get_ts_info = tg3_get_ts_info, |
Nithin Sujir | 1cbf9eb | 2013-05-18 06:26:55 +0000 | [diff] [blame] | 13705 | .get_eee = tg3_get_eee, |
| 13706 | .set_eee = tg3_set_eee, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13707 | }; |
| 13708 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 13709 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
| 13710 | struct rtnl_link_stats64 *stats) |
| 13711 | { |
| 13712 | struct tg3 *tp = netdev_priv(dev); |
| 13713 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 13714 | spin_lock_bh(&tp->lock); |
Michael Chan | 0f566b2 | 2012-07-29 19:15:44 +0000 | [diff] [blame] | 13715 | if (!tp->hw_stats) { |
| 13716 | spin_unlock_bh(&tp->lock); |
| 13717 | return &tp->net_stats_prev; |
| 13718 | } |
| 13719 | |
David S. Miller | b4017c5 | 2012-03-01 17:57:40 -0500 | [diff] [blame] | 13720 | tg3_get_nstats(tp, stats); |
| 13721 | spin_unlock_bh(&tp->lock); |
| 13722 | |
| 13723 | return stats; |
| 13724 | } |
| 13725 | |
Matt Carlson | ccd5ba9 | 2012-02-13 10:20:08 +0000 | [diff] [blame] | 13726 | static void tg3_set_rx_mode(struct net_device *dev) |
| 13727 | { |
| 13728 | struct tg3 *tp = netdev_priv(dev); |
| 13729 | |
| 13730 | if (!netif_running(dev)) |
| 13731 | return; |
| 13732 | |
| 13733 | tg3_full_lock(tp, 0); |
| 13734 | __tg3_set_rx_mode(dev); |
| 13735 | tg3_full_unlock(tp); |
| 13736 | } |
| 13737 | |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 13738 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
| 13739 | int new_mtu) |
| 13740 | { |
| 13741 | dev->mtu = new_mtu; |
| 13742 | |
| 13743 | if (new_mtu > ETH_DATA_LEN) { |
| 13744 | if (tg3_flag(tp, 5780_CLASS)) { |
| 13745 | netdev_update_features(dev); |
| 13746 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 13747 | } else { |
| 13748 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
| 13749 | } |
| 13750 | } else { |
| 13751 | if (tg3_flag(tp, 5780_CLASS)) { |
| 13752 | tg3_flag_set(tp, TSO_CAPABLE); |
| 13753 | netdev_update_features(dev); |
| 13754 | } |
| 13755 | tg3_flag_clear(tp, JUMBO_RING_ENABLE); |
| 13756 | } |
| 13757 | } |
| 13758 | |
| 13759 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) |
| 13760 | { |
| 13761 | struct tg3 *tp = netdev_priv(dev); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 13762 | int err; |
| 13763 | bool reset_phy = false; |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 13764 | |
| 13765 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) |
| 13766 | return -EINVAL; |
| 13767 | |
| 13768 | if (!netif_running(dev)) { |
| 13769 | /* We'll just catch it later when the |
| 13770 | * device is up'd. |
| 13771 | */ |
| 13772 | tg3_set_mtu(dev, tp, new_mtu); |
| 13773 | return 0; |
| 13774 | } |
| 13775 | |
| 13776 | tg3_phy_stop(tp); |
| 13777 | |
| 13778 | tg3_netif_stop(tp); |
| 13779 | |
| 13780 | tg3_full_lock(tp, 1); |
| 13781 | |
| 13782 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 13783 | |
| 13784 | tg3_set_mtu(dev, tp, new_mtu); |
| 13785 | |
Michael Chan | 2fae5e3 | 2012-03-04 14:48:15 +0000 | [diff] [blame] | 13786 | /* Reset PHY, otherwise the read DMA engine will be in a mode that |
| 13787 | * breaks all requests to 256 bytes. |
| 13788 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 13789 | if (tg3_asic_rev(tp) == ASIC_REV_57766) |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 13790 | reset_phy = true; |
Michael Chan | 2fae5e3 | 2012-03-04 14:48:15 +0000 | [diff] [blame] | 13791 | |
| 13792 | err = tg3_restart_hw(tp, reset_phy); |
Matt Carlson | faf1627 | 2012-02-13 10:20:07 +0000 | [diff] [blame] | 13793 | |
| 13794 | if (!err) |
| 13795 | tg3_netif_start(tp); |
| 13796 | |
| 13797 | tg3_full_unlock(tp); |
| 13798 | |
| 13799 | if (!err) |
| 13800 | tg3_phy_start(tp); |
| 13801 | |
| 13802 | return err; |
| 13803 | } |
| 13804 | |
| 13805 | static const struct net_device_ops tg3_netdev_ops = { |
| 13806 | .ndo_open = tg3_open, |
| 13807 | .ndo_stop = tg3_close, |
| 13808 | .ndo_start_xmit = tg3_start_xmit, |
| 13809 | .ndo_get_stats64 = tg3_get_stats64, |
| 13810 | .ndo_validate_addr = eth_validate_addr, |
| 13811 | .ndo_set_rx_mode = tg3_set_rx_mode, |
| 13812 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 13813 | .ndo_do_ioctl = tg3_ioctl, |
| 13814 | .ndo_tx_timeout = tg3_tx_timeout, |
| 13815 | .ndo_change_mtu = tg3_change_mtu, |
| 13816 | .ndo_fix_features = tg3_fix_features, |
| 13817 | .ndo_set_features = tg3_set_features, |
| 13818 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 13819 | .ndo_poll_controller = tg3_poll_controller, |
| 13820 | #endif |
| 13821 | }; |
| 13822 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13823 | static void tg3_get_eeprom_size(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13824 | { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13825 | u32 cursize, val, magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13826 | |
| 13827 | tp->nvram_size = EEPROM_CHIP_SIZE; |
| 13828 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13829 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13830 | return; |
| 13831 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 13832 | if ((magic != TG3_EEPROM_MAGIC) && |
| 13833 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && |
| 13834 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13835 | return; |
| 13836 | |
| 13837 | /* |
| 13838 | * Size the chip by reading offsets at increasing powers of two. |
| 13839 | * When we encounter our validation signature, we know the addressing |
| 13840 | * has wrapped around, and thus have our chip size. |
| 13841 | */ |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13842 | cursize = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13843 | |
| 13844 | while (cursize < tp->nvram_size) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 13845 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13846 | return; |
| 13847 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 13848 | if (val == magic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13849 | break; |
| 13850 | |
| 13851 | cursize <<= 1; |
| 13852 | } |
| 13853 | |
| 13854 | tp->nvram_size = cursize; |
| 13855 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13856 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13857 | static void tg3_get_nvram_size(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13858 | { |
| 13859 | u32 val; |
| 13860 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13861 | 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] | 13862 | return; |
| 13863 | |
| 13864 | /* Selfboot format */ |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 13865 | if (val != TG3_EEPROM_MAGIC) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 13866 | tg3_get_eeprom_size(tp); |
| 13867 | return; |
| 13868 | } |
| 13869 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 13870 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13871 | if (val != 0) { |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 13872 | /* This is confusing. We want to operate on the |
| 13873 | * 16-bit value at offset 0xf2. The tg3_nvram_read() |
| 13874 | * call will read from NVRAM and byteswap the data |
| 13875 | * according to the byteswapping settings for all |
| 13876 | * other register accesses. This ensures the data we |
| 13877 | * want will always reside in the lower 16-bits. |
| 13878 | * However, the data in NVRAM is in LE format, which |
| 13879 | * means the data from the NVRAM read will always be |
| 13880 | * opposite the endianness of the CPU. The 16-bit |
| 13881 | * byteswap then brings the data to CPU endianness. |
| 13882 | */ |
| 13883 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13884 | return; |
| 13885 | } |
| 13886 | } |
Matt Carlson | fd1122a | 2008-05-02 16:48:36 -0700 | [diff] [blame] | 13887 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13888 | } |
| 13889 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13890 | static void tg3_get_nvram_info(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13891 | { |
| 13892 | u32 nvcfg1; |
| 13893 | |
| 13894 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13895 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13896 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13897 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13898 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 13899 | tw32(NVRAM_CFG1, nvcfg1); |
| 13900 | } |
| 13901 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 13902 | if (tg3_asic_rev(tp) == ASIC_REV_5750 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13903 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13904 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13905 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
| 13906 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 13907 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13908 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13909 | break; |
| 13910 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: |
| 13911 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 13912 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; |
| 13913 | break; |
| 13914 | case FLASH_VENDOR_ATMEL_EEPROM: |
| 13915 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 13916 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13917 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13918 | break; |
| 13919 | case FLASH_VENDOR_ST: |
| 13920 | tp->nvram_jedecnum = JEDEC_ST; |
| 13921 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13922 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13923 | break; |
| 13924 | case FLASH_VENDOR_SAIFUN: |
| 13925 | tp->nvram_jedecnum = JEDEC_SAIFUN; |
| 13926 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; |
| 13927 | break; |
| 13928 | case FLASH_VENDOR_SST_SMALL: |
| 13929 | case FLASH_VENDOR_SST_LARGE: |
| 13930 | tp->nvram_jedecnum = JEDEC_SST; |
| 13931 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; |
| 13932 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13933 | } |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13934 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13935 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 13936 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13937 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13938 | } |
| 13939 | } |
| 13940 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13941 | static void tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13942 | { |
| 13943 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { |
| 13944 | case FLASH_5752PAGE_SIZE_256: |
| 13945 | tp->nvram_pagesize = 256; |
| 13946 | break; |
| 13947 | case FLASH_5752PAGE_SIZE_512: |
| 13948 | tp->nvram_pagesize = 512; |
| 13949 | break; |
| 13950 | case FLASH_5752PAGE_SIZE_1K: |
| 13951 | tp->nvram_pagesize = 1024; |
| 13952 | break; |
| 13953 | case FLASH_5752PAGE_SIZE_2K: |
| 13954 | tp->nvram_pagesize = 2048; |
| 13955 | break; |
| 13956 | case FLASH_5752PAGE_SIZE_4K: |
| 13957 | tp->nvram_pagesize = 4096; |
| 13958 | break; |
| 13959 | case FLASH_5752PAGE_SIZE_264: |
| 13960 | tp->nvram_pagesize = 264; |
| 13961 | break; |
| 13962 | case FLASH_5752PAGE_SIZE_528: |
| 13963 | tp->nvram_pagesize = 528; |
| 13964 | break; |
| 13965 | } |
| 13966 | } |
| 13967 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 13968 | static void tg3_get_5752_nvram_info(struct tg3 *tp) |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13969 | { |
| 13970 | u32 nvcfg1; |
| 13971 | |
| 13972 | nvcfg1 = tr32(NVRAM_CFG1); |
| 13973 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13974 | /* NVRAM protection for TPM */ |
| 13975 | if (nvcfg1 & (1 << 27)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13976 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 13977 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13978 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13979 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
| 13980 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: |
| 13981 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13982 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13983 | break; |
| 13984 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 13985 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13986 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13987 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13988 | break; |
| 13989 | case FLASH_5752VENDOR_ST_M45PE10: |
| 13990 | case FLASH_5752VENDOR_ST_M45PE20: |
| 13991 | case FLASH_5752VENDOR_ST_M45PE40: |
| 13992 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13993 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 13994 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 13995 | break; |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 13996 | } |
| 13997 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 13998 | if (tg3_flag(tp, FLASH)) { |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13999 | tg3_nvram_get_pagesize(tp, nvcfg1); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14000 | } else { |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 14001 | /* For eeprom, set pagesize to maximum eeprom size */ |
| 14002 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14003 | |
| 14004 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14005 | tw32(NVRAM_CFG1, nvcfg1); |
| 14006 | } |
| 14007 | } |
| 14008 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14009 | static void tg3_get_5755_nvram_info(struct tg3 *tp) |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 14010 | { |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 14011 | u32 nvcfg1, protect = 0; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 14012 | |
| 14013 | nvcfg1 = tr32(NVRAM_CFG1); |
| 14014 | |
| 14015 | /* NVRAM protection for TPM */ |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 14016 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14017 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 14018 | protect = 1; |
| 14019 | } |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 14020 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 14021 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 14022 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14023 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 14024 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 14025 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 14026 | case FLASH_5755VENDOR_ATMEL_FLASH_5: |
| 14027 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14028 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14029 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14030 | tp->nvram_pagesize = 264; |
| 14031 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || |
| 14032 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) |
| 14033 | tp->nvram_size = (protect ? 0x3e200 : |
| 14034 | TG3_NVRAM_SIZE_512KB); |
| 14035 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) |
| 14036 | tp->nvram_size = (protect ? 0x1f200 : |
| 14037 | TG3_NVRAM_SIZE_256KB); |
| 14038 | else |
| 14039 | tp->nvram_size = (protect ? 0x1f200 : |
| 14040 | TG3_NVRAM_SIZE_128KB); |
| 14041 | break; |
| 14042 | case FLASH_5752VENDOR_ST_M45PE10: |
| 14043 | case FLASH_5752VENDOR_ST_M45PE20: |
| 14044 | case FLASH_5752VENDOR_ST_M45PE40: |
| 14045 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14046 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14047 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14048 | tp->nvram_pagesize = 256; |
| 14049 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) |
| 14050 | tp->nvram_size = (protect ? |
| 14051 | TG3_NVRAM_SIZE_64KB : |
| 14052 | TG3_NVRAM_SIZE_128KB); |
| 14053 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) |
| 14054 | tp->nvram_size = (protect ? |
| 14055 | TG3_NVRAM_SIZE_64KB : |
| 14056 | TG3_NVRAM_SIZE_256KB); |
| 14057 | else |
| 14058 | tp->nvram_size = (protect ? |
| 14059 | TG3_NVRAM_SIZE_128KB : |
| 14060 | TG3_NVRAM_SIZE_512KB); |
| 14061 | break; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 14062 | } |
| 14063 | } |
| 14064 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14065 | static void tg3_get_5787_nvram_info(struct tg3 *tp) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 14066 | { |
| 14067 | u32 nvcfg1; |
| 14068 | |
| 14069 | nvcfg1 = tr32(NVRAM_CFG1); |
| 14070 | |
| 14071 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14072 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
| 14073 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 14074 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: |
| 14075 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 14076 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14077 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14078 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 14079 | |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14080 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14081 | tw32(NVRAM_CFG1, nvcfg1); |
| 14082 | break; |
| 14083 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 14084 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 14085 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 14086 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 14087 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14088 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14089 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14090 | tp->nvram_pagesize = 264; |
| 14091 | break; |
| 14092 | case FLASH_5752VENDOR_ST_M45PE10: |
| 14093 | case FLASH_5752VENDOR_ST_M45PE20: |
| 14094 | case FLASH_5752VENDOR_ST_M45PE40: |
| 14095 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14096 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14097 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14098 | tp->nvram_pagesize = 256; |
| 14099 | break; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 14100 | } |
| 14101 | } |
| 14102 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14103 | static void tg3_get_5761_nvram_info(struct tg3 *tp) |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 14104 | { |
| 14105 | u32 nvcfg1, protect = 0; |
| 14106 | |
| 14107 | nvcfg1 = tr32(NVRAM_CFG1); |
| 14108 | |
| 14109 | /* NVRAM protection for TPM */ |
| 14110 | if (nvcfg1 & (1 << 27)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14111 | tg3_flag_set(tp, PROTECTED_NVRAM); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 14112 | protect = 1; |
| 14113 | } |
| 14114 | |
| 14115 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 14116 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14117 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 14118 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 14119 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 14120 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 14121 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 14122 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 14123 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 14124 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 14125 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14126 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14127 | tg3_flag_set(tp, FLASH); |
| 14128 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14129 | tp->nvram_pagesize = 256; |
| 14130 | break; |
| 14131 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 14132 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 14133 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 14134 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 14135 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 14136 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 14137 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 14138 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 14139 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14140 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14141 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14142 | tp->nvram_pagesize = 256; |
| 14143 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 14144 | } |
| 14145 | |
| 14146 | if (protect) { |
| 14147 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); |
| 14148 | } else { |
| 14149 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 14150 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 14151 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 14152 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 14153 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 14154 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; |
| 14155 | break; |
| 14156 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 14157 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 14158 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 14159 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 14160 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 14161 | break; |
| 14162 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 14163 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 14164 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 14165 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 14166 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 14167 | break; |
| 14168 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 14169 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 14170 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 14171 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 14172 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14173 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 14174 | } |
| 14175 | } |
| 14176 | } |
| 14177 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14178 | static void tg3_get_5906_nvram_info(struct tg3 *tp) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14179 | { |
| 14180 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14181 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14182 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14183 | } |
| 14184 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14185 | static void tg3_get_57780_nvram_info(struct tg3 *tp) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14186 | { |
| 14187 | u32 nvcfg1; |
| 14188 | |
| 14189 | nvcfg1 = tr32(NVRAM_CFG1); |
| 14190 | |
| 14191 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14192 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 14193 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 14194 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14195 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14196 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14197 | |
| 14198 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14199 | tw32(NVRAM_CFG1, nvcfg1); |
| 14200 | return; |
| 14201 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 14202 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 14203 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 14204 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 14205 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 14206 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 14207 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 14208 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14209 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14210 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14211 | |
| 14212 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14213 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 14214 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 14215 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 14216 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 14217 | break; |
| 14218 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 14219 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 14220 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14221 | break; |
| 14222 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 14223 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 14224 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 14225 | break; |
| 14226 | } |
| 14227 | break; |
| 14228 | case FLASH_5752VENDOR_ST_M45PE10: |
| 14229 | case FLASH_5752VENDOR_ST_M45PE20: |
| 14230 | case FLASH_5752VENDOR_ST_M45PE40: |
| 14231 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14232 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14233 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14234 | |
| 14235 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14236 | case FLASH_5752VENDOR_ST_M45PE10: |
| 14237 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 14238 | break; |
| 14239 | case FLASH_5752VENDOR_ST_M45PE20: |
| 14240 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14241 | break; |
| 14242 | case FLASH_5752VENDOR_ST_M45PE40: |
| 14243 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 14244 | break; |
| 14245 | } |
| 14246 | break; |
| 14247 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14248 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14249 | return; |
| 14250 | } |
| 14251 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14252 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 14253 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14254 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14255 | } |
| 14256 | |
| 14257 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14258 | static void tg3_get_5717_nvram_info(struct tg3 *tp) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14259 | { |
| 14260 | u32 nvcfg1; |
| 14261 | |
| 14262 | nvcfg1 = tr32(NVRAM_CFG1); |
| 14263 | |
| 14264 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14265 | case FLASH_5717VENDOR_ATMEL_EEPROM: |
| 14266 | case FLASH_5717VENDOR_MICRO_EEPROM: |
| 14267 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14268 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14269 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14270 | |
| 14271 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14272 | tw32(NVRAM_CFG1, nvcfg1); |
| 14273 | return; |
| 14274 | case FLASH_5717VENDOR_ATMEL_MDB011D: |
| 14275 | case FLASH_5717VENDOR_ATMEL_ADB011B: |
| 14276 | case FLASH_5717VENDOR_ATMEL_ADB011D: |
| 14277 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 14278 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 14279 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 14280 | case FLASH_5717VENDOR_ATMEL_45USPT: |
| 14281 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14282 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14283 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14284 | |
| 14285 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14286 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 14287 | /* Detect size with tg3_nvram_get_size() */ |
| 14288 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14289 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 14290 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 14291 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14292 | break; |
| 14293 | default: |
| 14294 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 14295 | break; |
| 14296 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14297 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14298 | case FLASH_5717VENDOR_ST_M_M25PE10: |
| 14299 | case FLASH_5717VENDOR_ST_A_M25PE10: |
| 14300 | case FLASH_5717VENDOR_ST_M_M45PE10: |
| 14301 | case FLASH_5717VENDOR_ST_A_M45PE10: |
| 14302 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 14303 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 14304 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 14305 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 14306 | case FLASH_5717VENDOR_ST_25USPT: |
| 14307 | case FLASH_5717VENDOR_ST_45USPT: |
| 14308 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14309 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14310 | tg3_flag_set(tp, FLASH); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14311 | |
| 14312 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14313 | case FLASH_5717VENDOR_ST_M_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14314 | case FLASH_5717VENDOR_ST_M_M45PE20: |
Matt Carlson | 66ee33b | 2011-04-05 14:22:51 +0000 | [diff] [blame] | 14315 | /* Detect size with tg3_nvram_get_size() */ |
| 14316 | break; |
| 14317 | case FLASH_5717VENDOR_ST_A_M25PE20: |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14318 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 14319 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14320 | break; |
| 14321 | default: |
| 14322 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 14323 | break; |
| 14324 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14325 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14326 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14327 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14328 | return; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14329 | } |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14330 | |
| 14331 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 14332 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14333 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14334 | } |
| 14335 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14336 | static void tg3_get_5720_nvram_info(struct tg3 *tp) |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 14337 | { |
| 14338 | u32 nvcfg1, nvmpinstrp; |
| 14339 | |
| 14340 | nvcfg1 = tr32(NVRAM_CFG1); |
| 14341 | nvmpinstrp = nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK; |
| 14342 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14343 | if (tg3_asic_rev(tp) == ASIC_REV_5762) { |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 14344 | if (!(nvcfg1 & NVRAM_CFG1_5762VENDOR_MASK)) { |
| 14345 | tg3_flag_set(tp, NO_NVRAM); |
| 14346 | return; |
| 14347 | } |
| 14348 | |
| 14349 | switch (nvmpinstrp) { |
| 14350 | case FLASH_5762_EEPROM_HD: |
| 14351 | nvmpinstrp = FLASH_5720_EEPROM_HD; |
Dan Carpenter | 17e1a42 | 2013-01-11 09:57:33 +0300 | [diff] [blame] | 14352 | break; |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 14353 | case FLASH_5762_EEPROM_LD: |
| 14354 | nvmpinstrp = FLASH_5720_EEPROM_LD; |
Dan Carpenter | 17e1a42 | 2013-01-11 09:57:33 +0300 | [diff] [blame] | 14355 | break; |
Michael Chan | f6334bb | 2013-04-09 08:48:02 +0000 | [diff] [blame] | 14356 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 14357 | /* This pinstrap supports multiple sizes, so force it |
| 14358 | * to read the actual size from location 0xf0. |
| 14359 | */ |
| 14360 | nvmpinstrp = FLASH_5720VENDOR_ST_45USPT; |
| 14361 | break; |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 14362 | } |
| 14363 | } |
| 14364 | |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 14365 | switch (nvmpinstrp) { |
| 14366 | case FLASH_5720_EEPROM_HD: |
| 14367 | case FLASH_5720_EEPROM_LD: |
| 14368 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14369 | tg3_flag_set(tp, NVRAM_BUFFERED); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 14370 | |
| 14371 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14372 | tw32(NVRAM_CFG1, nvcfg1); |
| 14373 | if (nvmpinstrp == FLASH_5720_EEPROM_HD) |
| 14374 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14375 | else |
| 14376 | tp->nvram_pagesize = ATMEL_AT24C02_CHIP_SIZE; |
| 14377 | return; |
| 14378 | case FLASH_5720VENDOR_M_ATMEL_DB011D: |
| 14379 | case FLASH_5720VENDOR_A_ATMEL_DB011B: |
| 14380 | case FLASH_5720VENDOR_A_ATMEL_DB011D: |
| 14381 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 14382 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 14383 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 14384 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 14385 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 14386 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 14387 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 14388 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 14389 | case FLASH_5720VENDOR_ATMEL_45USPT: |
| 14390 | tp->nvram_jedecnum = JEDEC_ATMEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14391 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14392 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 14393 | |
| 14394 | switch (nvmpinstrp) { |
| 14395 | case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 14396 | case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 14397 | case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 14398 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14399 | break; |
| 14400 | case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 14401 | case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 14402 | case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 14403 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 14404 | break; |
| 14405 | case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 14406 | case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 14407 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 14408 | break; |
| 14409 | default: |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14410 | if (tg3_asic_rev(tp) != ASIC_REV_5762) |
Michael Chan | c5d0b72 | 2013-02-14 12:13:40 +0000 | [diff] [blame] | 14411 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 14412 | break; |
| 14413 | } |
| 14414 | break; |
| 14415 | case FLASH_5720VENDOR_M_ST_M25PE10: |
| 14416 | case FLASH_5720VENDOR_M_ST_M45PE10: |
| 14417 | case FLASH_5720VENDOR_A_ST_M25PE10: |
| 14418 | case FLASH_5720VENDOR_A_ST_M45PE10: |
| 14419 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 14420 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 14421 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 14422 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 14423 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 14424 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 14425 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 14426 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 14427 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 14428 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 14429 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 14430 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 14431 | case FLASH_5720VENDOR_ST_25USPT: |
| 14432 | case FLASH_5720VENDOR_ST_45USPT: |
| 14433 | tp->nvram_jedecnum = JEDEC_ST; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14434 | tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14435 | tg3_flag_set(tp, FLASH); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 14436 | |
| 14437 | switch (nvmpinstrp) { |
| 14438 | case FLASH_5720VENDOR_M_ST_M25PE20: |
| 14439 | case FLASH_5720VENDOR_M_ST_M45PE20: |
| 14440 | case FLASH_5720VENDOR_A_ST_M25PE20: |
| 14441 | case FLASH_5720VENDOR_A_ST_M45PE20: |
| 14442 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14443 | break; |
| 14444 | case FLASH_5720VENDOR_M_ST_M25PE40: |
| 14445 | case FLASH_5720VENDOR_M_ST_M45PE40: |
| 14446 | case FLASH_5720VENDOR_A_ST_M25PE40: |
| 14447 | case FLASH_5720VENDOR_A_ST_M45PE40: |
| 14448 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 14449 | break; |
| 14450 | case FLASH_5720VENDOR_M_ST_M25PE80: |
| 14451 | case FLASH_5720VENDOR_M_ST_M45PE80: |
| 14452 | case FLASH_5720VENDOR_A_ST_M25PE80: |
| 14453 | case FLASH_5720VENDOR_A_ST_M45PE80: |
| 14454 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 14455 | break; |
| 14456 | default: |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14457 | if (tg3_asic_rev(tp) != ASIC_REV_5762) |
Michael Chan | c5d0b72 | 2013-02-14 12:13:40 +0000 | [diff] [blame] | 14458 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 14459 | break; |
| 14460 | } |
| 14461 | break; |
| 14462 | default: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14463 | tg3_flag_set(tp, NO_NVRAM); |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 14464 | return; |
| 14465 | } |
| 14466 | |
| 14467 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 14468 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14469 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 14470 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14471 | if (tg3_asic_rev(tp) == ASIC_REV_5762) { |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 14472 | u32 val; |
| 14473 | |
| 14474 | if (tg3_nvram_read(tp, 0, &val)) |
| 14475 | return; |
| 14476 | |
| 14477 | if (val != TG3_EEPROM_MAGIC && |
| 14478 | (val & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) |
| 14479 | tg3_flag_set(tp, NO_NVRAM); |
| 14480 | } |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 14481 | } |
| 14482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14483 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14484 | static void tg3_nvram_init(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14485 | { |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 14486 | if (tg3_flag(tp, IS_SSB_CORE)) { |
| 14487 | /* No NVRAM and EEPROM on the SSB Broadcom GigE core. */ |
| 14488 | tg3_flag_clear(tp, NVRAM); |
| 14489 | tg3_flag_clear(tp, NVRAM_BUFFERED); |
| 14490 | tg3_flag_set(tp, NO_NVRAM); |
| 14491 | return; |
| 14492 | } |
| 14493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14494 | tw32_f(GRC_EEPROM_ADDR, |
| 14495 | (EEPROM_ADDR_FSM_RESET | |
| 14496 | (EEPROM_DEFAULT_CLOCK_PERIOD << |
| 14497 | EEPROM_ADDR_CLKPERD_SHIFT))); |
| 14498 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 14499 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14500 | |
| 14501 | /* Enable seeprom accesses. */ |
| 14502 | tw32_f(GRC_LOCAL_CTRL, |
| 14503 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); |
| 14504 | udelay(100); |
| 14505 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14506 | if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
| 14507 | tg3_asic_rev(tp) != ASIC_REV_5701) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14508 | tg3_flag_set(tp, NVRAM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14509 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 14510 | if (tg3_nvram_lock(tp)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 14511 | netdev_warn(tp->dev, |
| 14512 | "Cannot get nvram lock, %s failed\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14513 | __func__); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 14514 | return; |
| 14515 | } |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 14516 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14517 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 14518 | tp->nvram_size = 0; |
| 14519 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14520 | if (tg3_asic_rev(tp) == ASIC_REV_5752) |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 14521 | tg3_get_5752_nvram_info(tp); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14522 | else if (tg3_asic_rev(tp) == ASIC_REV_5755) |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 14523 | tg3_get_5755_nvram_info(tp); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14524 | else if (tg3_asic_rev(tp) == ASIC_REV_5787 || |
| 14525 | tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 14526 | tg3_asic_rev(tp) == ASIC_REV_5785) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 14527 | tg3_get_5787_nvram_info(tp); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14528 | else if (tg3_asic_rev(tp) == ASIC_REV_5761) |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 14529 | tg3_get_5761_nvram_info(tp); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14530 | else if (tg3_asic_rev(tp) == ASIC_REV_5906) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14531 | tg3_get_5906_nvram_info(tp); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14532 | else if (tg3_asic_rev(tp) == ASIC_REV_57780 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 14533 | tg3_flag(tp, 57765_CLASS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14534 | tg3_get_57780_nvram_info(tp); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14535 | else if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 14536 | tg3_asic_rev(tp) == ASIC_REV_5719) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 14537 | tg3_get_5717_nvram_info(tp); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14538 | else if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 14539 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Matt Carlson | 9b91b5f | 2011-04-05 14:22:47 +0000 | [diff] [blame] | 14540 | tg3_get_5720_nvram_info(tp); |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 14541 | else |
| 14542 | tg3_get_nvram_info(tp); |
| 14543 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 14544 | if (tp->nvram_size == 0) |
| 14545 | tg3_get_nvram_size(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14546 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 14547 | tg3_disable_nvram_access(tp); |
Michael Chan | 381291b | 2005-12-13 21:08:21 -0800 | [diff] [blame] | 14548 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14549 | |
| 14550 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14551 | tg3_flag_clear(tp, NVRAM); |
| 14552 | tg3_flag_clear(tp, NVRAM_BUFFERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14553 | |
| 14554 | tg3_get_eeprom_size(tp); |
| 14555 | } |
| 14556 | } |
| 14557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14558 | struct subsys_tbl_ent { |
| 14559 | u16 subsys_vendor, subsys_devid; |
| 14560 | u32 phy_id; |
| 14561 | }; |
| 14562 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14563 | static struct subsys_tbl_ent subsys_id_to_phy_id[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14564 | /* Broadcom boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14565 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14566 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14567 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14568 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14569 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14570 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14571 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 14572 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, |
| 14573 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14574 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14575 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14576 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14577 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 14578 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, |
| 14579 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14580 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14581 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14582 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14583 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14584 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14585 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14586 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14587 | |
| 14588 | /* 3com boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14589 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14590 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14591 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14592 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14593 | { TG3PCI_SUBVENDOR_ID_3COM, |
| 14594 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, |
| 14595 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14596 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14597 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14598 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14599 | |
| 14600 | /* DELL boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14601 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14602 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14603 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14604 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14605 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14606 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14607 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14608 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14609 | |
| 14610 | /* Compaq boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14611 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14612 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14613 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14614 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14615 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 14616 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, |
| 14617 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14618 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14619 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14620 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14621 | |
| 14622 | /* IBM boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 14623 | { TG3PCI_SUBVENDOR_ID_IBM, |
| 14624 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14625 | }; |
| 14626 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14627 | static struct subsys_tbl_ent *tg3_lookup_by_subsys(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14628 | { |
| 14629 | int i; |
| 14630 | |
| 14631 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { |
| 14632 | if ((subsys_id_to_phy_id[i].subsys_vendor == |
| 14633 | tp->pdev->subsystem_vendor) && |
| 14634 | (subsys_id_to_phy_id[i].subsys_devid == |
| 14635 | tp->pdev->subsystem_device)) |
| 14636 | return &subsys_id_to_phy_id[i]; |
| 14637 | } |
| 14638 | return NULL; |
| 14639 | } |
| 14640 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14641 | static void tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14642 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14643 | u32 val; |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 14644 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14645 | tp->phy_id = TG3_PHY_ID_INVALID; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14646 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 14647 | |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 14648 | /* Assume an onboard device and WOL capable by default. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14649 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
| 14650 | tg3_flag_set(tp, WOL_CAP); |
David S. Miller | 72b845e | 2006-03-14 14:11:48 -0800 | [diff] [blame] | 14651 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14652 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14653 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14654 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 14655 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14656 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 14657 | val = tr32(VCPU_CFGSHDW); |
| 14658 | if (val & VCPU_CFGSHDW_ASPM_DBNC) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14659 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 14660 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 14661 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14662 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 14663 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 14664 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 14665 | goto done; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14666 | } |
| 14667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14668 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 14669 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 14670 | u32 nic_cfg, led_cfg; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 14671 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14672 | int eeprom_phy_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14673 | |
| 14674 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 14675 | tp->nic_sram_data_cfg = nic_cfg; |
| 14676 | |
| 14677 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); |
| 14678 | ver >>= NIC_SRAM_DATA_VER_SHIFT; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14679 | if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
| 14680 | tg3_asic_rev(tp) != ASIC_REV_5701 && |
| 14681 | tg3_asic_rev(tp) != ASIC_REV_5703 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14682 | (ver > 0) && (ver < 0x100)) |
| 14683 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); |
| 14684 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14685 | if (tg3_asic_rev(tp) == ASIC_REV_5785) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 14686 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
| 14687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14688 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
| 14689 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) |
| 14690 | eeprom_phy_serdes = 1; |
| 14691 | |
| 14692 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); |
| 14693 | if (nic_phy_id != 0) { |
| 14694 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; |
| 14695 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; |
| 14696 | |
| 14697 | eeprom_phy_id = (id1 >> 16) << 10; |
| 14698 | eeprom_phy_id |= (id2 & 0xfc00) << 16; |
| 14699 | eeprom_phy_id |= (id2 & 0x03ff) << 0; |
| 14700 | } else |
| 14701 | eeprom_phy_id = 0; |
| 14702 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14703 | tp->phy_id = eeprom_phy_id; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 14704 | if (eeprom_phy_serdes) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14705 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14706 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 14707 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14708 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 14709 | } |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14710 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14711 | if (tg3_flag(tp, 5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14712 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
| 14713 | SHASTA_EXT_LED_MODE_MASK); |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 14714 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14715 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
| 14716 | |
| 14717 | switch (led_cfg) { |
| 14718 | default: |
| 14719 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: |
| 14720 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 14721 | break; |
| 14722 | |
| 14723 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: |
| 14724 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 14725 | break; |
| 14726 | |
| 14727 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: |
| 14728 | tp->led_ctrl = LED_CTRL_MODE_MAC; |
Michael Chan | 9ba2779 | 2005-06-06 15:16:20 -0700 | [diff] [blame] | 14729 | |
| 14730 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is |
| 14731 | * read on some older 5700/5701 bootcode. |
| 14732 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14733 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 14734 | tg3_asic_rev(tp) == ASIC_REV_5701) |
Michael Chan | 9ba2779 | 2005-06-06 15:16:20 -0700 | [diff] [blame] | 14735 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 14736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14737 | break; |
| 14738 | |
| 14739 | case SHASTA_EXT_LED_SHARED: |
| 14740 | tp->led_ctrl = LED_CTRL_MODE_SHARED; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14741 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0 && |
| 14742 | tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14743 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 14744 | LED_CTRL_MODE_PHY_2); |
| 14745 | break; |
| 14746 | |
| 14747 | case SHASTA_EXT_LED_MAC: |
| 14748 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; |
| 14749 | break; |
| 14750 | |
| 14751 | case SHASTA_EXT_LED_COMBO: |
| 14752 | tp->led_ctrl = LED_CTRL_MODE_COMBO; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14753 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14754 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 14755 | LED_CTRL_MODE_PHY_2); |
| 14756 | break; |
| 14757 | |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14758 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14759 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14760 | if ((tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 14761 | tg3_asic_rev(tp) == ASIC_REV_5701) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14762 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
| 14763 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 14764 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14765 | if (tg3_chip_rev(tp) == CHIPREV_5784_AX) |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 14766 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
Matt Carlson | 5f60891 | 2007-11-12 21:17:07 -0800 | [diff] [blame] | 14767 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14768 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14769 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14770 | if ((tp->pdev->subsystem_vendor == |
| 14771 | PCI_VENDOR_ID_ARIMA) && |
| 14772 | (tp->pdev->subsystem_device == 0x205a || |
| 14773 | tp->pdev->subsystem_device == 0x2063)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14774 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14775 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14776 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 14777 | tg3_flag_set(tp, IS_NIC); |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 14778 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14779 | |
| 14780 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14781 | tg3_flag_set(tp, ENABLE_ASF); |
| 14782 | if (tg3_flag(tp, 5750_PLUS)) |
| 14783 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14784 | } |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 14785 | |
| 14786 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14787 | tg3_flag(tp, 5750_PLUS)) |
| 14788 | tg3_flag_set(tp, ENABLE_APE); |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 14789 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14790 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 14791 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14792 | tg3_flag_clear(tp, WOL_CAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14793 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14794 | if (tg3_flag(tp, WOL_CAP) && |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 14795 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14796 | tg3_flag_set(tp, WOL_ENABLE); |
Rafael J. Wysocki | 6fdbab9 | 2011-04-28 11:02:15 +0000 | [diff] [blame] | 14797 | device_set_wakeup_enable(&tp->pdev->dev, true); |
| 14798 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 14799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14800 | if (cfg2 & (1 << 17)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14801 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14802 | |
| 14803 | /* serdes signal pre-emphasis in register 0x590 set by */ |
| 14804 | /* bootcode if bit 18 is set */ |
| 14805 | if (cfg2 & (1 << 18)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14806 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 14807 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14808 | if ((tg3_flag(tp, 57765_PLUS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 14809 | (tg3_asic_rev(tp) == ASIC_REV_5784 && |
| 14810 | tg3_chip_rev(tp) != CHIPREV_5784_AX)) && |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 14811 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14812 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 14813 | |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 14814 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 14815 | u32 cfg3; |
| 14816 | |
| 14817 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 14818 | if (tg3_asic_rev(tp) != ASIC_REV_5785 && |
| 14819 | !tg3_flag(tp, 57765_PLUS) && |
| 14820 | (cfg3 & NIC_SRAM_ASPM_DEBOUNCE)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14821 | tg3_flag_set(tp, ASPM_WORKAROUND); |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 14822 | if (cfg3 & NIC_SRAM_LNK_FLAP_AVOID) |
| 14823 | tp->phy_flags |= TG3_PHYFLG_KEEP_LINK_ON_PWRDN; |
| 14824 | if (cfg3 & NIC_SRAM_1G_ON_VAUX_OK) |
| 14825 | tp->phy_flags |= TG3_PHYFLG_1G_ON_VAUX_OK; |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 14826 | } |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 14827 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 14828 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14829 | tg3_flag_set(tp, RGMII_INBAND_DISABLE); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 14830 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14831 | tg3_flag_set(tp, RGMII_EXT_IBND_RX_EN); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 14832 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14833 | tg3_flag_set(tp, RGMII_EXT_IBND_TX_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14834 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 14835 | done: |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14836 | if (tg3_flag(tp, WOL_CAP)) |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 14837 | device_set_wakeup_enable(&tp->pdev->dev, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14838 | tg3_flag(tp, WOL_ENABLE)); |
Rafael J. Wysocki | 43067ed | 2011-02-10 06:53:09 +0000 | [diff] [blame] | 14839 | else |
| 14840 | device_set_wakeup_capable(&tp->pdev->dev, false); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14841 | } |
| 14842 | |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 14843 | static int tg3_ape_otp_read(struct tg3 *tp, u32 offset, u32 *val) |
| 14844 | { |
| 14845 | int i, err; |
| 14846 | u32 val2, off = offset * 8; |
| 14847 | |
| 14848 | err = tg3_nvram_lock(tp); |
| 14849 | if (err) |
| 14850 | return err; |
| 14851 | |
| 14852 | tg3_ape_write32(tp, TG3_APE_OTP_ADDR, off | APE_OTP_ADDR_CPU_ENABLE); |
| 14853 | tg3_ape_write32(tp, TG3_APE_OTP_CTRL, APE_OTP_CTRL_PROG_EN | |
| 14854 | APE_OTP_CTRL_CMD_RD | APE_OTP_CTRL_START); |
| 14855 | tg3_ape_read32(tp, TG3_APE_OTP_CTRL); |
| 14856 | udelay(10); |
| 14857 | |
| 14858 | for (i = 0; i < 100; i++) { |
| 14859 | val2 = tg3_ape_read32(tp, TG3_APE_OTP_STATUS); |
| 14860 | if (val2 & APE_OTP_STATUS_CMD_DONE) { |
| 14861 | *val = tg3_ape_read32(tp, TG3_APE_OTP_RD_DATA); |
| 14862 | break; |
| 14863 | } |
| 14864 | udelay(10); |
| 14865 | } |
| 14866 | |
| 14867 | tg3_ape_write32(tp, TG3_APE_OTP_CTRL, 0); |
| 14868 | |
| 14869 | tg3_nvram_unlock(tp); |
| 14870 | if (val2 & APE_OTP_STATUS_CMD_DONE) |
| 14871 | return 0; |
| 14872 | |
| 14873 | return -EBUSY; |
| 14874 | } |
| 14875 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14876 | static int tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 14877 | { |
| 14878 | int i; |
| 14879 | u32 val; |
| 14880 | |
| 14881 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); |
| 14882 | tw32(OTP_CTRL, cmd); |
| 14883 | |
| 14884 | /* Wait for up to 1 ms for command to execute. */ |
| 14885 | for (i = 0; i < 100; i++) { |
| 14886 | val = tr32(OTP_STATUS); |
| 14887 | if (val & OTP_STATUS_CMD_DONE) |
| 14888 | break; |
| 14889 | udelay(10); |
| 14890 | } |
| 14891 | |
| 14892 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; |
| 14893 | } |
| 14894 | |
| 14895 | /* Read the gphy configuration from the OTP region of the chip. The gphy |
| 14896 | * configuration is a 32-bit value that straddles the alignment boundary. |
| 14897 | * We do two 32-bit reads and then shift and merge the results. |
| 14898 | */ |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14899 | static u32 tg3_read_otp_phycfg(struct tg3 *tp) |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 14900 | { |
| 14901 | u32 bhalf_otp, thalf_otp; |
| 14902 | |
| 14903 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); |
| 14904 | |
| 14905 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) |
| 14906 | return 0; |
| 14907 | |
| 14908 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); |
| 14909 | |
| 14910 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 14911 | return 0; |
| 14912 | |
| 14913 | thalf_otp = tr32(OTP_READ_DATA); |
| 14914 | |
| 14915 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); |
| 14916 | |
| 14917 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 14918 | return 0; |
| 14919 | |
| 14920 | bhalf_otp = tr32(OTP_READ_DATA); |
| 14921 | |
| 14922 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); |
| 14923 | } |
| 14924 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14925 | static void tg3_phy_init_link_config(struct tg3 *tp) |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14926 | { |
Hiroaki SHIMODA | 202ff1c | 2011-11-22 04:05:41 +0000 | [diff] [blame] | 14927 | u32 adv = ADVERTISED_Autoneg; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14928 | |
| 14929 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
| 14930 | adv |= ADVERTISED_1000baseT_Half | |
| 14931 | ADVERTISED_1000baseT_Full; |
| 14932 | |
| 14933 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 14934 | adv |= ADVERTISED_100baseT_Half | |
| 14935 | ADVERTISED_100baseT_Full | |
| 14936 | ADVERTISED_10baseT_Half | |
| 14937 | ADVERTISED_10baseT_Full | |
| 14938 | ADVERTISED_TP; |
| 14939 | else |
| 14940 | adv |= ADVERTISED_FIBRE; |
| 14941 | |
| 14942 | tp->link_config.advertising = adv; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 14943 | tp->link_config.speed = SPEED_UNKNOWN; |
| 14944 | tp->link_config.duplex = DUPLEX_UNKNOWN; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14945 | tp->link_config.autoneg = AUTONEG_ENABLE; |
Matt Carlson | e740522 | 2012-02-13 15:20:16 +0000 | [diff] [blame] | 14946 | tp->link_config.active_speed = SPEED_UNKNOWN; |
| 14947 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
Matt Carlson | 34655ad | 2012-02-22 12:35:18 +0000 | [diff] [blame] | 14948 | |
| 14949 | tp->old_link = -1; |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14950 | } |
| 14951 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 14952 | static int tg3_phy_probe(struct tg3 *tp) |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 14953 | { |
| 14954 | u32 hw_phy_id_1, hw_phy_id_2; |
| 14955 | u32 hw_phy_id, hw_phy_id_masked; |
| 14956 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14957 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14958 | /* flow control autonegotiation is default behavior */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14959 | tg3_flag_set(tp, PAUSE_AUTONEG); |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 14960 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 14961 | |
Michael Chan | 8151ad5 | 2012-07-29 19:15:41 +0000 | [diff] [blame] | 14962 | if (tg3_flag(tp, ENABLE_APE)) { |
| 14963 | switch (tp->pci_fn) { |
| 14964 | case 0: |
| 14965 | tp->phy_ape_lock = TG3_APE_LOCK_PHY0; |
| 14966 | break; |
| 14967 | case 1: |
| 14968 | tp->phy_ape_lock = TG3_APE_LOCK_PHY1; |
| 14969 | break; |
| 14970 | case 2: |
| 14971 | tp->phy_ape_lock = TG3_APE_LOCK_PHY2; |
| 14972 | break; |
| 14973 | case 3: |
| 14974 | tp->phy_ape_lock = TG3_APE_LOCK_PHY3; |
| 14975 | break; |
| 14976 | } |
| 14977 | } |
| 14978 | |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 14979 | if (!tg3_flag(tp, ENABLE_ASF) && |
| 14980 | !(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
| 14981 | !(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
| 14982 | tp->phy_flags &= ~(TG3_PHYFLG_1G_ON_VAUX_OK | |
| 14983 | TG3_PHYFLG_KEEP_LINK_ON_PWRDN); |
| 14984 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14985 | if (tg3_flag(tp, USE_PHYLIB)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14986 | return tg3_phy_init(tp); |
| 14987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14988 | /* Reading the PHY ID register can conflict with ASF |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 14989 | * firmware access to the PHY hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14990 | */ |
| 14991 | err = 0; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 14992 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14993 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14994 | } else { |
| 14995 | /* Now read the physical PHY_ID from the chip and verify |
| 14996 | * that it is sane. If it doesn't look good, we fall back |
| 14997 | * to either the hard-coded table based PHY_ID and failing |
| 14998 | * that the value found in the eeprom area. |
| 14999 | */ |
| 15000 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); |
| 15001 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); |
| 15002 | |
| 15003 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; |
| 15004 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; |
| 15005 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; |
| 15006 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15007 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15008 | } |
| 15009 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15010 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15011 | tp->phy_id = hw_phy_id; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15012 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15013 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Michael Chan | da6b2d0 | 2005-08-19 12:54:29 -0700 | [diff] [blame] | 15014 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15015 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15016 | } else { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15017 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 15018 | /* Do nothing, phy ID already set up in |
| 15019 | * tg3_get_eeprom_hw_cfg(). |
| 15020 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15021 | } else { |
| 15022 | struct subsys_tbl_ent *p; |
| 15023 | |
| 15024 | /* No eeprom signature? Try the hardcoded |
| 15025 | * subsys device table. |
| 15026 | */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 15027 | p = tg3_lookup_by_subsys(tp); |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 15028 | if (p) { |
| 15029 | tp->phy_id = p->phy_id; |
| 15030 | } else if (!tg3_flag(tp, IS_SSB_CORE)) { |
| 15031 | /* For now we saw the IDs 0xbc050cd0, |
| 15032 | * 0xbc050f80 and 0xbc050c30 on devices |
| 15033 | * connected to an BCM4785 and there are |
| 15034 | * probably more. Just assume that the phy is |
| 15035 | * supported when it is connected to a SSB core |
| 15036 | * for now. |
| 15037 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15038 | return -ENODEV; |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 15039 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15040 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15041 | if (!tp->phy_id || |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15042 | tp->phy_id == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 15043 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15044 | } |
| 15045 | } |
| 15046 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame] | 15047 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15048 | (tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 15049 | tg3_asic_rev(tp) == ASIC_REV_5720 || |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 15050 | tg3_asic_rev(tp) == ASIC_REV_57766 || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15051 | tg3_asic_rev(tp) == ASIC_REV_5762 || |
| 15052 | (tg3_asic_rev(tp) == ASIC_REV_5717 && |
| 15053 | tg3_chip_rev_id(tp) != CHIPREV_ID_5717_A0) || |
| 15054 | (tg3_asic_rev(tp) == ASIC_REV_57765 && |
Nithin Sujir | 9e2ecbe | 2013-05-18 06:26:52 +0000 | [diff] [blame] | 15055 | tg3_chip_rev_id(tp) != CHIPREV_ID_57765_A0))) { |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 15056 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 15057 | |
Nithin Sujir | 9e2ecbe | 2013-05-18 06:26:52 +0000 | [diff] [blame] | 15058 | tp->eee.supported = SUPPORTED_100baseT_Full | |
| 15059 | SUPPORTED_1000baseT_Full; |
| 15060 | tp->eee.advertised = ADVERTISED_100baseT_Full | |
| 15061 | ADVERTISED_1000baseT_Full; |
| 15062 | tp->eee.eee_enabled = 1; |
| 15063 | tp->eee.tx_lpi_enabled = 1; |
| 15064 | tp->eee.tx_lpi_timer = TG3_CPMU_DBTMR1_LNKIDLE_2047US; |
| 15065 | } |
| 15066 | |
Matt Carlson | e256f8a | 2011-03-09 16:58:24 +0000 | [diff] [blame] | 15067 | tg3_phy_init_link_config(tp); |
| 15068 | |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 15069 | if (!(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) && |
| 15070 | !(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15071 | !tg3_flag(tp, ENABLE_APE) && |
| 15072 | !tg3_flag(tp, ENABLE_ASF)) { |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 15073 | u32 bmsr, dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15074 | |
| 15075 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 15076 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 15077 | (bmsr & BMSR_LSTATUS)) |
| 15078 | goto skip_phy_reset; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 15079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15080 | err = tg3_phy_reset(tp); |
| 15081 | if (err) |
| 15082 | return err; |
| 15083 | |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 15084 | tg3_phy_set_wirespeed(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15085 | |
Matt Carlson | e2bf73e | 2011-12-08 14:40:15 +0000 | [diff] [blame] | 15086 | if (!tg3_phy_copper_an_config_ok(tp, &dummy)) { |
Matt Carlson | 42b64a4 | 2011-05-19 12:12:49 +0000 | [diff] [blame] | 15087 | tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, |
| 15088 | tp->link_config.flowctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15089 | |
| 15090 | tg3_writephy(tp, MII_BMCR, |
| 15091 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 15092 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15093 | } |
| 15094 | |
| 15095 | skip_phy_reset: |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 15096 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15097 | err = tg3_init_5401phy_dsp(tp); |
| 15098 | if (err) |
| 15099 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15101 | err = tg3_init_5401phy_dsp(tp); |
| 15102 | } |
| 15103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15104 | return err; |
| 15105 | } |
| 15106 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15107 | static void tg3_read_vpd(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15108 | { |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 15109 | u8 *vpd_data; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 15110 | unsigned int block_end, rosize, len; |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 15111 | u32 vpdlen; |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 15112 | int j, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15113 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 15114 | vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen); |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 15115 | if (!vpd_data) |
| 15116 | goto out_no_vpd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15117 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 15118 | 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] | 15119 | if (i < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15120 | goto out_not_found; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 15121 | |
| 15122 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
| 15123 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; |
| 15124 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 15125 | |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 15126 | if (block_end > vpdlen) |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 15127 | goto out_not_found; |
| 15128 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 15129 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 15130 | PCI_VPD_RO_KEYWORD_MFR_ID); |
| 15131 | if (j > 0) { |
| 15132 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 15133 | |
| 15134 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 15135 | if (j + len > block_end || len != 4 || |
| 15136 | memcmp(&vpd_data[j], "1028", 4)) |
| 15137 | goto partno; |
| 15138 | |
| 15139 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 15140 | PCI_VPD_RO_KEYWORD_VENDOR0); |
| 15141 | if (j < 0) |
| 15142 | goto partno; |
| 15143 | |
| 15144 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 15145 | |
| 15146 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 15147 | if (j + len > block_end) |
| 15148 | goto partno; |
| 15149 | |
Kees Cook | 715230a | 2013-03-27 06:40:50 +0000 | [diff] [blame] | 15150 | if (len >= sizeof(tp->fw_ver)) |
| 15151 | len = sizeof(tp->fw_ver) - 1; |
| 15152 | memset(tp->fw_ver, 0, sizeof(tp->fw_ver)); |
| 15153 | snprintf(tp->fw_ver, sizeof(tp->fw_ver), "%.*s bc ", len, |
| 15154 | &vpd_data[j]); |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 15155 | } |
| 15156 | |
| 15157 | partno: |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 15158 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 15159 | PCI_VPD_RO_KEYWORD_PARTNO); |
| 15160 | if (i < 0) |
| 15161 | goto out_not_found; |
| 15162 | |
| 15163 | len = pci_vpd_info_field_size(&vpd_data[i]); |
| 15164 | |
| 15165 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 15166 | if (len > TG3_BPN_SIZE || |
Matt Carlson | 535a490 | 2011-07-20 10:20:56 +0000 | [diff] [blame] | 15167 | (len + i) > vpdlen) |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 15168 | goto out_not_found; |
| 15169 | |
| 15170 | memcpy(tp->board_part_number, &vpd_data[i], len); |
| 15171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15172 | out_not_found: |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 15173 | kfree(vpd_data); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 15174 | if (tp->board_part_number[0]) |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 15175 | return; |
| 15176 | |
| 15177 | out_no_vpd: |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15178 | if (tg3_asic_rev(tp) == ASIC_REV_5717) { |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 15179 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 15180 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C) |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 15181 | strcpy(tp->board_part_number, "BCM5717"); |
| 15182 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) |
| 15183 | strcpy(tp->board_part_number, "BCM5718"); |
| 15184 | else |
| 15185 | goto nomatch; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15186 | } else if (tg3_asic_rev(tp) == ASIC_REV_57780) { |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 15187 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
| 15188 | strcpy(tp->board_part_number, "BCM57780"); |
| 15189 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) |
| 15190 | strcpy(tp->board_part_number, "BCM57760"); |
| 15191 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) |
| 15192 | strcpy(tp->board_part_number, "BCM57790"); |
| 15193 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) |
| 15194 | strcpy(tp->board_part_number, "BCM57788"); |
| 15195 | else |
| 15196 | goto nomatch; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15197 | } else if (tg3_asic_rev(tp) == ASIC_REV_57765) { |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 15198 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
| 15199 | strcpy(tp->board_part_number, "BCM57761"); |
| 15200 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) |
| 15201 | strcpy(tp->board_part_number, "BCM57765"); |
| 15202 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) |
| 15203 | strcpy(tp->board_part_number, "BCM57781"); |
| 15204 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) |
| 15205 | strcpy(tp->board_part_number, "BCM57785"); |
| 15206 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) |
| 15207 | strcpy(tp->board_part_number, "BCM57791"); |
| 15208 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 15209 | strcpy(tp->board_part_number, "BCM57795"); |
| 15210 | else |
| 15211 | goto nomatch; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15212 | } else if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 15213 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762) |
| 15214 | strcpy(tp->board_part_number, "BCM57762"); |
| 15215 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766) |
| 15216 | strcpy(tp->board_part_number, "BCM57766"); |
| 15217 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782) |
| 15218 | strcpy(tp->board_part_number, "BCM57782"); |
| 15219 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 15220 | strcpy(tp->board_part_number, "BCM57786"); |
| 15221 | else |
| 15222 | goto nomatch; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15223 | } else if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 15224 | strcpy(tp->board_part_number, "BCM95906"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 15225 | } else { |
| 15226 | nomatch: |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 15227 | strcpy(tp->board_part_number, "none"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 15228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15229 | } |
| 15230 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15231 | static int tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15232 | { |
| 15233 | u32 val; |
| 15234 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 15235 | if (tg3_nvram_read(tp, offset, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15236 | (val & 0xfc000000) != 0x0c000000 || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 15237 | tg3_nvram_read(tp, offset + 4, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15238 | val != 0) |
| 15239 | return 0; |
| 15240 | |
| 15241 | return 1; |
| 15242 | } |
| 15243 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15244 | static void tg3_read_bc_ver(struct tg3 *tp) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15245 | { |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 15246 | u32 val, offset, start, ver_offset; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 15247 | int i, dst_off; |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 15248 | bool newver = false; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15249 | |
| 15250 | if (tg3_nvram_read(tp, 0xc, &offset) || |
| 15251 | tg3_nvram_read(tp, 0x4, &start)) |
| 15252 | return; |
| 15253 | |
| 15254 | offset = tg3_nvram_logical_addr(tp, offset); |
| 15255 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 15256 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15257 | return; |
| 15258 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 15259 | if ((val & 0xfc000000) == 0x0c000000) { |
| 15260 | if (tg3_nvram_read(tp, offset + 4, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15261 | return; |
| 15262 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 15263 | if (val == 0) |
| 15264 | newver = true; |
| 15265 | } |
| 15266 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 15267 | dst_off = strlen(tp->fw_ver); |
| 15268 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 15269 | if (newver) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 15270 | if (TG3_VER_SIZE - dst_off < 16 || |
| 15271 | tg3_nvram_read(tp, offset + 8, &ver_offset)) |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 15272 | return; |
| 15273 | |
| 15274 | offset = offset + ver_offset - start; |
| 15275 | for (i = 0; i < 16; i += 4) { |
| 15276 | __be32 v; |
| 15277 | if (tg3_nvram_read_be32(tp, offset + i, &v)) |
| 15278 | return; |
| 15279 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 15280 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 15281 | } |
| 15282 | } else { |
| 15283 | u32 major, minor; |
| 15284 | |
| 15285 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) |
| 15286 | return; |
| 15287 | |
| 15288 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> |
| 15289 | TG3_NVM_BCVER_MAJSFT; |
| 15290 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 15291 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
| 15292 | "v%d.%02d", major, minor); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15293 | } |
| 15294 | } |
| 15295 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15296 | static void tg3_read_hwsb_ver(struct tg3 *tp) |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 15297 | { |
| 15298 | u32 val, major, minor; |
| 15299 | |
| 15300 | /* Use native endian representation */ |
| 15301 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) |
| 15302 | return; |
| 15303 | |
| 15304 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> |
| 15305 | TG3_NVM_HWSB_CFG1_MAJSFT; |
| 15306 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> |
| 15307 | TG3_NVM_HWSB_CFG1_MINSFT; |
| 15308 | |
| 15309 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); |
| 15310 | } |
| 15311 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15312 | static void tg3_read_sb_ver(struct tg3 *tp, u32 val) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 15313 | { |
| 15314 | u32 offset, major, minor, build; |
| 15315 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 15316 | 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] | 15317 | |
| 15318 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) |
| 15319 | return; |
| 15320 | |
| 15321 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { |
| 15322 | case TG3_EEPROM_SB_REVISION_0: |
| 15323 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; |
| 15324 | break; |
| 15325 | case TG3_EEPROM_SB_REVISION_2: |
| 15326 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; |
| 15327 | break; |
| 15328 | case TG3_EEPROM_SB_REVISION_3: |
| 15329 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; |
| 15330 | break; |
Matt Carlson | a4153d4 | 2010-02-17 15:16:56 +0000 | [diff] [blame] | 15331 | case TG3_EEPROM_SB_REVISION_4: |
| 15332 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; |
| 15333 | break; |
| 15334 | case TG3_EEPROM_SB_REVISION_5: |
| 15335 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; |
| 15336 | break; |
Matt Carlson | bba226a | 2010-10-14 10:37:38 +0000 | [diff] [blame] | 15337 | case TG3_EEPROM_SB_REVISION_6: |
| 15338 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; |
| 15339 | break; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 15340 | default: |
| 15341 | return; |
| 15342 | } |
| 15343 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 15344 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 15345 | return; |
| 15346 | |
| 15347 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> |
| 15348 | TG3_EEPROM_SB_EDH_BLD_SHFT; |
| 15349 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> |
| 15350 | TG3_EEPROM_SB_EDH_MAJ_SHFT; |
| 15351 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; |
| 15352 | |
| 15353 | if (minor > 99 || build > 26) |
| 15354 | return; |
| 15355 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 15356 | offset = strlen(tp->fw_ver); |
| 15357 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, |
| 15358 | " v%d.%02d", major, minor); |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 15359 | |
| 15360 | if (build > 0) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 15361 | offset = strlen(tp->fw_ver); |
| 15362 | if (offset < TG3_VER_SIZE - 1) |
| 15363 | tp->fw_ver[offset] = 'a' + build - 1; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 15364 | } |
| 15365 | } |
| 15366 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15367 | static void tg3_read_mgmtfw_ver(struct tg3 *tp) |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 15368 | { |
| 15369 | u32 val, offset, start; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15370 | int i, vlen; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15371 | |
| 15372 | for (offset = TG3_NVM_DIR_START; |
| 15373 | offset < TG3_NVM_DIR_END; |
| 15374 | offset += TG3_NVM_DIRENT_SIZE) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 15375 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15376 | return; |
| 15377 | |
| 15378 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
| 15379 | break; |
| 15380 | } |
| 15381 | |
| 15382 | if (offset == TG3_NVM_DIR_END) |
| 15383 | return; |
| 15384 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15385 | if (!tg3_flag(tp, 5705_PLUS)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15386 | start = 0x08000000; |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 15387 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15388 | return; |
| 15389 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 15390 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15391 | !tg3_fw_img_is_valid(tp, offset) || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 15392 | tg3_nvram_read(tp, offset + 8, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15393 | return; |
| 15394 | |
| 15395 | offset += val - start; |
| 15396 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15397 | vlen = strlen(tp->fw_ver); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15398 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15399 | tp->fw_ver[vlen++] = ','; |
| 15400 | tp->fw_ver[vlen++] = ' '; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15401 | |
| 15402 | for (i = 0; i < 4; i++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 15403 | __be32 v; |
| 15404 | if (tg3_nvram_read_be32(tp, offset, &v)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15405 | return; |
| 15406 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 15407 | offset += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15408 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15409 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
| 15410 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15411 | break; |
| 15412 | } |
| 15413 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15414 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
| 15415 | vlen += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15416 | } |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15417 | } |
| 15418 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15419 | static void tg3_probe_ncsi(struct tg3 *tp) |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 15420 | { |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 15421 | u32 apedata; |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 15422 | |
| 15423 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 15424 | if (apedata != APE_SEG_SIG_MAGIC) |
| 15425 | return; |
| 15426 | |
| 15427 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 15428 | if (!(apedata & APE_FW_STATUS_READY)) |
| 15429 | return; |
| 15430 | |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 15431 | if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) |
| 15432 | tg3_flag_set(tp, APE_HAS_NCSI); |
| 15433 | } |
| 15434 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15435 | static void tg3_read_dash_ver(struct tg3 *tp) |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 15436 | { |
| 15437 | int vlen; |
| 15438 | u32 apedata; |
| 15439 | char *fwtype; |
| 15440 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 15441 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
| 15442 | |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 15443 | if (tg3_flag(tp, APE_HAS_NCSI)) |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 15444 | fwtype = "NCSI"; |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 15445 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725) |
| 15446 | fwtype = "SMASH"; |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 15447 | else |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 15448 | fwtype = "DASH"; |
| 15449 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 15450 | vlen = strlen(tp->fw_ver); |
| 15451 | |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 15452 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
| 15453 | fwtype, |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 15454 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
| 15455 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, |
| 15456 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, |
| 15457 | (apedata & APE_FW_VERSION_BLDMSK)); |
| 15458 | } |
| 15459 | |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 15460 | static void tg3_read_otp_ver(struct tg3 *tp) |
| 15461 | { |
| 15462 | u32 val, val2; |
| 15463 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15464 | if (tg3_asic_rev(tp) != ASIC_REV_5762) |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 15465 | return; |
| 15466 | |
| 15467 | if (!tg3_ape_otp_read(tp, OTP_ADDRESS_MAGIC0, &val) && |
| 15468 | !tg3_ape_otp_read(tp, OTP_ADDRESS_MAGIC0 + 4, &val2) && |
| 15469 | TG3_OTP_MAGIC0_VALID(val)) { |
| 15470 | u64 val64 = (u64) val << 32 | val2; |
| 15471 | u32 ver = 0; |
| 15472 | int i, vlen; |
| 15473 | |
| 15474 | for (i = 0; i < 7; i++) { |
| 15475 | if ((val64 & 0xff) == 0) |
| 15476 | break; |
| 15477 | ver = val64 & 0xff; |
| 15478 | val64 >>= 8; |
| 15479 | } |
| 15480 | vlen = strlen(tp->fw_ver); |
| 15481 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " .%02d", ver); |
| 15482 | } |
| 15483 | } |
| 15484 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15485 | static void tg3_read_fw_ver(struct tg3 *tp) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15486 | { |
| 15487 | u32 val; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 15488 | bool vpd_vers = false; |
| 15489 | |
| 15490 | if (tp->fw_ver[0] != 0) |
| 15491 | vpd_vers = true; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15492 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15493 | if (tg3_flag(tp, NO_NVRAM)) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 15494 | strcat(tp->fw_ver, "sb"); |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 15495 | tg3_read_otp_ver(tp); |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 15496 | return; |
| 15497 | } |
| 15498 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15499 | if (tg3_nvram_read(tp, 0, &val)) |
| 15500 | return; |
| 15501 | |
| 15502 | if (val == TG3_EEPROM_MAGIC) |
| 15503 | tg3_read_bc_ver(tp); |
| 15504 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) |
| 15505 | tg3_read_sb_ver(tp, val); |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 15506 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 15507 | tg3_read_hwsb_ver(tp); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 15508 | |
Michael Chan | 165f4d1 | 2012-07-16 16:23:59 +0000 | [diff] [blame] | 15509 | if (tg3_flag(tp, ENABLE_ASF)) { |
| 15510 | if (tg3_flag(tp, ENABLE_APE)) { |
| 15511 | tg3_probe_ncsi(tp); |
| 15512 | if (!vpd_vers) |
| 15513 | tg3_read_dash_ver(tp); |
| 15514 | } else if (!vpd_vers) { |
| 15515 | tg3_read_mgmtfw_ver(tp); |
| 15516 | } |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 15517 | } |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 15518 | |
| 15519 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 15520 | } |
| 15521 | |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 15522 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
| 15523 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15524 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 15525 | return TG3_RX_RET_MAX_SIZE_5717; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15526 | else if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 15527 | return TG3_RX_RET_MAX_SIZE_5700; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 15528 | else |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 15529 | return TG3_RX_RET_MAX_SIZE_5705; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 15530 | } |
| 15531 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 15532 | static DEFINE_PCI_DEVICE_TABLE(tg3_write_reorder_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 15533 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
| 15534 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
| 15535 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8385_0) }, |
| 15536 | { }, |
| 15537 | }; |
| 15538 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15539 | static struct pci_dev *tg3_find_peer(struct tg3 *tp) |
Matt Carlson | 16c7fa7 | 2012-02-13 10:20:10 +0000 | [diff] [blame] | 15540 | { |
| 15541 | struct pci_dev *peer; |
| 15542 | unsigned int func, devnr = tp->pdev->devfn & ~7; |
| 15543 | |
| 15544 | for (func = 0; func < 8; func++) { |
| 15545 | peer = pci_get_slot(tp->pdev->bus, devnr | func); |
| 15546 | if (peer && peer != tp->pdev) |
| 15547 | break; |
| 15548 | pci_dev_put(peer); |
| 15549 | } |
| 15550 | /* 5704 can be configured in single-port mode, set peer to |
| 15551 | * tp->pdev in that case. |
| 15552 | */ |
| 15553 | if (!peer) { |
| 15554 | peer = tp->pdev; |
| 15555 | return peer; |
| 15556 | } |
| 15557 | |
| 15558 | /* |
| 15559 | * We don't need to keep the refcount elevated; there's no way |
| 15560 | * to remove one half of this device without removing the other |
| 15561 | */ |
| 15562 | pci_dev_put(peer); |
| 15563 | |
| 15564 | return peer; |
| 15565 | } |
| 15566 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 15567 | 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] | 15568 | { |
| 15569 | tp->pci_chip_rev_id = misc_ctrl_reg >> MISC_HOST_CTRL_CHIPREV_SHIFT; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15570 | if (tg3_asic_rev(tp) == ASIC_REV_USE_PROD_ID_REG) { |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15571 | u32 reg; |
| 15572 | |
| 15573 | /* All devices that use the alternate |
| 15574 | * ASIC REV location have a CPMU. |
| 15575 | */ |
| 15576 | tg3_flag_set(tp, CPMU_PRESENT); |
| 15577 | |
| 15578 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 15579 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C || |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15580 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 15581 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 15582 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720 || |
| 15583 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5762 || |
| 15584 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725 || |
| 15585 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5727) |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15586 | reg = TG3PCI_GEN2_PRODID_ASICREV; |
| 15587 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
| 15588 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || |
| 15589 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || |
| 15590 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || |
| 15591 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 15592 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
| 15593 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762 || |
| 15594 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766 || |
| 15595 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782 || |
| 15596 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 15597 | reg = TG3PCI_GEN15_PRODID_ASICREV; |
| 15598 | else |
| 15599 | reg = TG3PCI_PRODID_ASICREV; |
| 15600 | |
| 15601 | pci_read_config_dword(tp->pdev, reg, &tp->pci_chip_rev_id); |
| 15602 | } |
| 15603 | |
| 15604 | /* Wrong chip ID in 5752 A0. This code can be removed later |
| 15605 | * as A0 is not in production. |
| 15606 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15607 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5752_A0_HW) |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15608 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
| 15609 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15610 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5717_C0) |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 15611 | tp->pci_chip_rev_id = CHIPREV_ID_5720_A0; |
| 15612 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15613 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 15614 | tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 15615 | tg3_asic_rev(tp) == ASIC_REV_5720) |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15616 | tg3_flag_set(tp, 5717_PLUS); |
| 15617 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15618 | if (tg3_asic_rev(tp) == ASIC_REV_57765 || |
| 15619 | tg3_asic_rev(tp) == ASIC_REV_57766) |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15620 | tg3_flag_set(tp, 57765_CLASS); |
| 15621 | |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 15622 | if (tg3_flag(tp, 57765_CLASS) || tg3_flag(tp, 5717_PLUS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15623 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15624 | tg3_flag_set(tp, 57765_PLUS); |
| 15625 | |
| 15626 | /* Intentionally exclude ASIC_REV_5906 */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15627 | if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
| 15628 | tg3_asic_rev(tp) == ASIC_REV_5787 || |
| 15629 | tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 15630 | tg3_asic_rev(tp) == ASIC_REV_5761 || |
| 15631 | tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 15632 | tg3_asic_rev(tp) == ASIC_REV_57780 || |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15633 | tg3_flag(tp, 57765_PLUS)) |
| 15634 | tg3_flag_set(tp, 5755_PLUS); |
| 15635 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15636 | if (tg3_asic_rev(tp) == ASIC_REV_5780 || |
| 15637 | tg3_asic_rev(tp) == ASIC_REV_5714) |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15638 | tg3_flag_set(tp, 5780_CLASS); |
| 15639 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15640 | if (tg3_asic_rev(tp) == ASIC_REV_5750 || |
| 15641 | tg3_asic_rev(tp) == ASIC_REV_5752 || |
| 15642 | tg3_asic_rev(tp) == ASIC_REV_5906 || |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15643 | tg3_flag(tp, 5755_PLUS) || |
| 15644 | tg3_flag(tp, 5780_CLASS)) |
| 15645 | tg3_flag_set(tp, 5750_PLUS); |
| 15646 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15647 | if (tg3_asic_rev(tp) == ASIC_REV_5705 || |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15648 | tg3_flag(tp, 5750_PLUS)) |
| 15649 | tg3_flag_set(tp, 5705_PLUS); |
| 15650 | } |
| 15651 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 15652 | static bool tg3_10_100_only_device(struct tg3 *tp, |
| 15653 | const struct pci_device_id *ent) |
| 15654 | { |
| 15655 | u32 grc_misc_cfg = tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK; |
| 15656 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15657 | if ((tg3_asic_rev(tp) == ASIC_REV_5703 && |
| 15658 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 15659 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
| 15660 | return true; |
| 15661 | |
| 15662 | if (ent->driver_data & TG3_DRV_DATA_FLAG_10_100_ONLY) { |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15663 | if (tg3_asic_rev(tp) == ASIC_REV_5705) { |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 15664 | if (ent->driver_data & TG3_DRV_DATA_FLAG_5705_10_100) |
| 15665 | return true; |
| 15666 | } else { |
| 15667 | return true; |
| 15668 | } |
| 15669 | } |
| 15670 | |
| 15671 | return false; |
| 15672 | } |
| 15673 | |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 15674 | 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] | 15675 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15676 | u32 misc_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15677 | u32 pci_state_reg, grc_misc_cfg; |
| 15678 | u32 val; |
| 15679 | u16 pci_cmd; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 15680 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15682 | /* Force memory write invalidate off. If we leave it on, |
| 15683 | * then on 5700_BX chips we have to enable a workaround. |
| 15684 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary |
| 15685 | * to match the cacheline size. The Broadcom driver have this |
| 15686 | * workaround but turns MWI off all the times so never uses |
| 15687 | * it. This seems to suggest that the workaround is insufficient. |
| 15688 | */ |
| 15689 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 15690 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; |
| 15691 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 15692 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15693 | /* Important! -- Make sure register accesses are byteswapped |
| 15694 | * correctly. Also, for those chips that require it, make |
| 15695 | * sure that indirect register accesses are enabled before |
| 15696 | * the first operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15697 | */ |
| 15698 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 15699 | &misc_ctrl_reg); |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15700 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
| 15701 | MISC_HOST_CTRL_CHIPREV); |
| 15702 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 15703 | tp->misc_host_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15704 | |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15705 | tg3_detect_asic_rev(tp, misc_ctrl_reg); |
Michael Chan | ff645be | 2005-04-21 17:09:53 -0700 | [diff] [blame] | 15706 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15707 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
| 15708 | * we need to disable memory and use config. cycles |
| 15709 | * only to access all registers. The 5702/03 chips |
| 15710 | * can mistakenly decode the special cycles from the |
| 15711 | * ICH chipsets as memory write cycles, causing corruption |
| 15712 | * of register and memory space. Only certain ICH bridges |
| 15713 | * will drive special cycles with non-zero data during the |
| 15714 | * address phase which can fall within the 5703's address |
| 15715 | * range. This is not an ICH bug as the PCI spec allows |
| 15716 | * non-zero address during special cycles. However, only |
| 15717 | * these ICH bridges are known to drive non-zero addresses |
| 15718 | * during special cycles. |
| 15719 | * |
| 15720 | * Since special cycles do not cross PCI bridges, we only |
| 15721 | * enable this workaround if the 5703 is on the secondary |
| 15722 | * bus of these ICH bridges. |
| 15723 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15724 | if ((tg3_chip_rev_id(tp) == CHIPREV_ID_5703_A1) || |
| 15725 | (tg3_chip_rev_id(tp) == CHIPREV_ID_5703_A2)) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15726 | static struct tg3_dev_id { |
| 15727 | u32 vendor; |
| 15728 | u32 device; |
| 15729 | u32 rev; |
| 15730 | } ich_chipsets[] = { |
| 15731 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, |
| 15732 | PCI_ANY_ID }, |
| 15733 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, |
| 15734 | PCI_ANY_ID }, |
| 15735 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, |
| 15736 | 0xa }, |
| 15737 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, |
| 15738 | PCI_ANY_ID }, |
| 15739 | { }, |
| 15740 | }; |
| 15741 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; |
| 15742 | struct pci_dev *bridge = NULL; |
| 15743 | |
| 15744 | while (pci_id->vendor != 0) { |
| 15745 | bridge = pci_get_device(pci_id->vendor, pci_id->device, |
| 15746 | bridge); |
| 15747 | if (!bridge) { |
| 15748 | pci_id++; |
| 15749 | continue; |
| 15750 | } |
| 15751 | if (pci_id->rev != PCI_ANY_ID) { |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 15752 | if (bridge->revision > pci_id->rev) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15753 | continue; |
| 15754 | } |
| 15755 | if (bridge->subordinate && |
| 15756 | (bridge->subordinate->number == |
| 15757 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15758 | tg3_flag_set(tp, ICH_WORKAROUND); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15759 | pci_dev_put(bridge); |
| 15760 | break; |
| 15761 | } |
| 15762 | } |
| 15763 | } |
| 15764 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15765 | if (tg3_asic_rev(tp) == ASIC_REV_5701) { |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 15766 | static struct tg3_dev_id { |
| 15767 | u32 vendor; |
| 15768 | u32 device; |
| 15769 | } bridge_chipsets[] = { |
| 15770 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, |
| 15771 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, |
| 15772 | { }, |
| 15773 | }; |
| 15774 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; |
| 15775 | struct pci_dev *bridge = NULL; |
| 15776 | |
| 15777 | while (pci_id->vendor != 0) { |
| 15778 | bridge = pci_get_device(pci_id->vendor, |
| 15779 | pci_id->device, |
| 15780 | bridge); |
| 15781 | if (!bridge) { |
| 15782 | pci_id++; |
| 15783 | continue; |
| 15784 | } |
| 15785 | if (bridge->subordinate && |
| 15786 | (bridge->subordinate->number <= |
| 15787 | tp->pdev->bus->number) && |
Yinghai Lu | b918c62 | 2012-05-17 18:51:11 -0700 | [diff] [blame] | 15788 | (bridge->subordinate->busn_res.end >= |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 15789 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15790 | tg3_flag_set(tp, 5701_DMA_BUG); |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 15791 | pci_dev_put(bridge); |
| 15792 | break; |
| 15793 | } |
| 15794 | } |
| 15795 | } |
| 15796 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15797 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
| 15798 | * DMA addresses > 40-bit. This bridge may have other additional |
| 15799 | * 57xx devices behind it in some 4-port NIC designs for example. |
| 15800 | * Any tg3 device found behind the bridge will also need the 40-bit |
| 15801 | * DMA workaround. |
| 15802 | */ |
Matt Carlson | 42b123b | 2012-02-13 15:20:13 +0000 | [diff] [blame] | 15803 | if (tg3_flag(tp, 5780_CLASS)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15804 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 15805 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 15806 | } else { |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15807 | struct pci_dev *bridge = NULL; |
| 15808 | |
| 15809 | do { |
| 15810 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, |
| 15811 | PCI_DEVICE_ID_SERVERWORKS_EPB, |
| 15812 | bridge); |
| 15813 | if (bridge && bridge->subordinate && |
| 15814 | (bridge->subordinate->number <= |
| 15815 | tp->pdev->bus->number) && |
Yinghai Lu | b918c62 | 2012-05-17 18:51:11 -0700 | [diff] [blame] | 15816 | (bridge->subordinate->busn_res.end >= |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15817 | tp->pdev->bus->number)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15818 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 15819 | pci_dev_put(bridge); |
| 15820 | break; |
| 15821 | } |
| 15822 | } while (bridge); |
| 15823 | } |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 15824 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15825 | if (tg3_asic_rev(tp) == ASIC_REV_5704 || |
| 15826 | tg3_asic_rev(tp) == ASIC_REV_5714) |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 15827 | tp->pdev_peer = tg3_find_peer(tp); |
| 15828 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 15829 | /* Determine TSO capabilities */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15830 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0) |
Matt Carlson | 4d163b7 | 2011-01-25 15:58:48 +0000 | [diff] [blame] | 15831 | ; /* Do nothing. HW bug. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15832 | else if (tg3_flag(tp, 57765_PLUS)) |
| 15833 | tg3_flag_set(tp, HW_TSO_3); |
| 15834 | else if (tg3_flag(tp, 5755_PLUS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15835 | tg3_asic_rev(tp) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15836 | tg3_flag_set(tp, HW_TSO_2); |
| 15837 | else if (tg3_flag(tp, 5750_PLUS)) { |
| 15838 | tg3_flag_set(tp, HW_TSO_1); |
| 15839 | tg3_flag_set(tp, TSO_BUG); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15840 | if (tg3_asic_rev(tp) == ASIC_REV_5750 && |
| 15841 | tg3_chip_rev_id(tp) >= CHIPREV_ID_5750_C2) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15842 | tg3_flag_clear(tp, TSO_BUG); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15843 | } else if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
| 15844 | tg3_asic_rev(tp) != ASIC_REV_5701 && |
| 15845 | tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) { |
Matt Carlson | 1caf13e | 2013-03-06 17:02:29 +0000 | [diff] [blame] | 15846 | tg3_flag_set(tp, FW_TSO); |
| 15847 | tg3_flag_set(tp, TSO_BUG); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15848 | if (tg3_asic_rev(tp) == ASIC_REV_5705) |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 15849 | tp->fw_needed = FIRMWARE_TG3TSO5; |
| 15850 | else |
| 15851 | tp->fw_needed = FIRMWARE_TG3TSO; |
| 15852 | } |
| 15853 | |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 15854 | /* Selectively allow TSO based on operating conditions */ |
Matt Carlson | 6ff6f81 | 2011-05-19 12:12:54 +0000 | [diff] [blame] | 15855 | if (tg3_flag(tp, HW_TSO_1) || |
| 15856 | tg3_flag(tp, HW_TSO_2) || |
| 15857 | tg3_flag(tp, HW_TSO_3) || |
Matt Carlson | 1caf13e | 2013-03-06 17:02:29 +0000 | [diff] [blame] | 15858 | tg3_flag(tp, FW_TSO)) { |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 15859 | /* For firmware TSO, assume ASF is disabled. |
| 15860 | * We'll disable TSO later if we discover ASF |
| 15861 | * is enabled in tg3_get_eeprom_hw_cfg(). |
| 15862 | */ |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 15863 | tg3_flag_set(tp, TSO_CAPABLE); |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 15864 | } else { |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 15865 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 15866 | tg3_flag_clear(tp, TSO_BUG); |
| 15867 | tp->fw_needed = NULL; |
| 15868 | } |
| 15869 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15870 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0) |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 15871 | tp->fw_needed = FIRMWARE_TG3; |
| 15872 | |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 15873 | if (tg3_asic_rev(tp) == ASIC_REV_57766) |
| 15874 | tp->fw_needed = FIRMWARE_TG357766; |
| 15875 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 15876 | tp->irq_max = 1; |
| 15877 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15878 | if (tg3_flag(tp, 5750_PLUS)) { |
| 15879 | tg3_flag_set(tp, SUPPORT_MSI); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15880 | if (tg3_chip_rev(tp) == CHIPREV_5750_AX || |
| 15881 | tg3_chip_rev(tp) == CHIPREV_5750_BX || |
| 15882 | (tg3_asic_rev(tp) == ASIC_REV_5714 && |
| 15883 | tg3_chip_rev_id(tp) <= CHIPREV_ID_5714_A2 && |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 15884 | tp->pdev_peer == tp->pdev)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15885 | tg3_flag_clear(tp, SUPPORT_MSI); |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 15886 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15887 | if (tg3_flag(tp, 5755_PLUS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15888 | tg3_asic_rev(tp) == ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15889 | tg3_flag_set(tp, 1SHOT_MSI); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 15890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15891 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15892 | if (tg3_flag(tp, 57765_PLUS)) { |
| 15893 | tg3_flag_set(tp, SUPPORT_MSIX); |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 15894 | tp->irq_max = TG3_IRQ_MAX_VECS; |
| 15895 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 15896 | } |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 15897 | |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 15898 | tp->txq_max = 1; |
| 15899 | tp->rxq_max = 1; |
| 15900 | if (tp->irq_max > 1) { |
| 15901 | tp->rxq_max = TG3_RSS_MAX_NUM_QS; |
| 15902 | tg3_rss_init_dflt_indir_tbl(tp, TG3_RSS_MAX_NUM_QS); |
| 15903 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15904 | if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 15905 | tg3_asic_rev(tp) == ASIC_REV_5720) |
Michael Chan | 9102426 | 2012-09-28 07:12:38 +0000 | [diff] [blame] | 15906 | tp->txq_max = tp->irq_max - 1; |
| 15907 | } |
| 15908 | |
Matt Carlson | b7abee6 | 2012-06-07 12:56:54 +0000 | [diff] [blame] | 15909 | if (tg3_flag(tp, 5755_PLUS) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15910 | tg3_asic_rev(tp) == ASIC_REV_5906) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15911 | tg3_flag_set(tp, SHORT_DMA_BUG); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 15912 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15913 | if (tg3_asic_rev(tp) == ASIC_REV_5719) |
Matt Carlson | a4cb428 | 2011-12-14 11:09:58 +0000 | [diff] [blame] | 15914 | tp->dma_limit = TG3_TX_BD_DMA_MAX_4K; |
Matt Carlson | e31aa98 | 2011-07-27 14:20:53 +0000 | [diff] [blame] | 15915 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15916 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 15917 | tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 15918 | tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 15919 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15920 | tg3_flag_set(tp, LRG_PROD_RING_CAP); |
Matt Carlson | de9f523 | 2011-04-05 14:22:43 +0000 | [diff] [blame] | 15921 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15922 | if (tg3_flag(tp, 57765_PLUS) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15923 | tg3_chip_rev_id(tp) != CHIPREV_ID_5719_A0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15924 | tg3_flag_set(tp, USE_JUMBO_BDFLAG); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 15925 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15926 | if (!tg3_flag(tp, 5705_PLUS) || |
| 15927 | tg3_flag(tp, 5780_CLASS) || |
| 15928 | tg3_flag(tp, USE_JUMBO_BDFLAG)) |
| 15929 | tg3_flag_set(tp, JUMBO_CAPABLE); |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 15930 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15931 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 15932 | &pci_state_reg); |
| 15933 | |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 15934 | if (pci_is_pcie(tp->pdev)) { |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 15935 | u16 lnkctl; |
| 15936 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15937 | tg3_flag_set(tp, PCI_EXPRESS); |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 15938 | |
Jiang Liu | 0f49bfb | 2012-08-20 13:28:20 -0600 | [diff] [blame] | 15939 | pcie_capability_read_word(tp->pdev, PCI_EXP_LNKCTL, &lnkctl); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 15940 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15941 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15942 | tg3_flag_clear(tp, HW_TSO_2); |
Matt Carlson | dabc5c6 | 2011-05-19 12:12:52 +0000 | [diff] [blame] | 15943 | tg3_flag_clear(tp, TSO_CAPABLE); |
Matt Carlson | 7196cd6 | 2011-05-19 16:02:44 +0000 | [diff] [blame] | 15944 | } |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15945 | if (tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 15946 | tg3_asic_rev(tp) == ASIC_REV_5761 || |
| 15947 | tg3_chip_rev_id(tp) == CHIPREV_ID_57780_A0 || |
| 15948 | tg3_chip_rev_id(tp) == CHIPREV_ID_57780_A1) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15949 | tg3_flag_set(tp, CLKREQ_BUG); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15950 | } else if (tg3_chip_rev_id(tp) == CHIPREV_ID_5717_A0) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15951 | tg3_flag_set(tp, L1PLLPD_EN); |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 15952 | } |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15953 | } else if (tg3_asic_rev(tp) == ASIC_REV_5785) { |
Jon Mason | 708ebb3a | 2011-06-27 12:56:50 +0000 | [diff] [blame] | 15954 | /* BCM5785 devices are effectively PCIe devices, and should |
| 15955 | * follow PCIe codepaths, but do not have a PCIe capabilities |
| 15956 | * section. |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 15957 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15958 | tg3_flag_set(tp, PCI_EXPRESS); |
| 15959 | } else if (!tg3_flag(tp, 5705_PLUS) || |
| 15960 | tg3_flag(tp, 5780_CLASS)) { |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15961 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
| 15962 | if (!tp->pcix_cap) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 15963 | dev_err(&tp->pdev->dev, |
| 15964 | "Cannot find PCI-X capability, aborting\n"); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15965 | return -EIO; |
| 15966 | } |
| 15967 | |
| 15968 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15969 | tg3_flag_set(tp, PCIX_MODE); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15970 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15971 | |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 15972 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
| 15973 | * reordering to the mailbox registers done by the host |
| 15974 | * controller can cause major troubles. We read back from |
| 15975 | * every mailbox register write to force the writes to be |
| 15976 | * posted to the chip in order. |
| 15977 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 15978 | if (pci_dev_present(tg3_write_reorder_chipsets) && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 15979 | !tg3_flag(tp, PCI_EXPRESS)) |
| 15980 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 15981 | |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 15982 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 15983 | &tp->pci_cacheline_sz); |
| 15984 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 15985 | &tp->pci_lat_timer); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15986 | if (tg3_asic_rev(tp) == ASIC_REV_5703 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15987 | tp->pci_lat_timer < 64) { |
| 15988 | tp->pci_lat_timer = 64; |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 15989 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 15990 | tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15991 | } |
| 15992 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 15993 | /* Important! -- It is critical that the PCI-X hw workaround |
| 15994 | * situation is decided before the first MMIO register access. |
| 15995 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 15996 | if (tg3_chip_rev(tp) == CHIPREV_5700_BX) { |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 15997 | /* 5700 BX chips need to have their TX producer index |
| 15998 | * mailboxes written twice to workaround a bug. |
| 15999 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16000 | tg3_flag_set(tp, TXD_MBOX_HWBUG); |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 16001 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 16002 | /* If we are in PCI-X mode, enable register write workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16003 | * |
| 16004 | * The workaround is to use indirect register accesses |
| 16005 | * for all chip writes not to mailbox registers. |
| 16006 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16007 | if (tg3_flag(tp, PCIX_MODE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16008 | u32 pm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16009 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16010 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16011 | |
| 16012 | /* The chip can have it's power management PCI config |
| 16013 | * space registers clobbered due to this bug. |
| 16014 | * So explicitly force the chip into D0 here. |
| 16015 | */ |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 16016 | pci_read_config_dword(tp->pdev, |
| 16017 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16018 | &pm_reg); |
| 16019 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; |
| 16020 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 16021 | pci_write_config_dword(tp->pdev, |
| 16022 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16023 | pm_reg); |
| 16024 | |
| 16025 | /* Also, force SERR#/PERR# in PCI command. */ |
| 16026 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 16027 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
| 16028 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 16029 | } |
| 16030 | } |
| 16031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16032 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16033 | tg3_flag_set(tp, PCI_HIGH_SPEED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16034 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16035 | tg3_flag_set(tp, PCI_32BIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16036 | |
| 16037 | /* Chip-specific fixup from Broadcom driver */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16038 | if ((tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16039 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
| 16040 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; |
| 16041 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); |
| 16042 | } |
| 16043 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 16044 | /* Default fast path register access methods */ |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 16045 | tp->read32 = tg3_read32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 16046 | tp->write32 = tg3_write32; |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 16047 | tp->read32_mbox = tg3_read32; |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 16048 | tp->write32_mbox = tg3_write32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 16049 | tp->write32_tx_mbox = tg3_write32; |
| 16050 | tp->write32_rx_mbox = tg3_write32; |
| 16051 | |
| 16052 | /* Various workaround register access methods */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16053 | if (tg3_flag(tp, PCIX_TARGET_HWBUG)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 16054 | tp->write32 = tg3_write_indirect_reg32; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16055 | else if (tg3_asic_rev(tp) == ASIC_REV_5701 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16056 | (tg3_flag(tp, PCI_EXPRESS) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16057 | tg3_chip_rev_id(tp) == CHIPREV_ID_5750_A0)) { |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 16058 | /* |
| 16059 | * Back to back register writes can cause problems on these |
| 16060 | * chips, the workaround is to read back all reg writes |
| 16061 | * except those to mailbox regs. |
| 16062 | * |
| 16063 | * See tg3_write_indirect_reg32(). |
| 16064 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 16065 | tp->write32 = tg3_write_flush_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 16066 | } |
| 16067 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16068 | 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] | 16069 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16070 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 16071 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 16072 | } |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 16073 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16074 | if (tg3_flag(tp, ICH_WORKAROUND)) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16075 | tp->read32 = tg3_read_indirect_reg32; |
| 16076 | tp->write32 = tg3_write_indirect_reg32; |
| 16077 | tp->read32_mbox = tg3_read_indirect_mbox; |
| 16078 | tp->write32_mbox = tg3_write_indirect_mbox; |
| 16079 | tp->write32_tx_mbox = tg3_write_indirect_mbox; |
| 16080 | tp->write32_rx_mbox = tg3_write_indirect_mbox; |
| 16081 | |
| 16082 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 16083 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16084 | |
| 16085 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 16086 | pci_cmd &= ~PCI_COMMAND_MEMORY; |
| 16087 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 16088 | } |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16089 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 16090 | tp->read32_mbox = tg3_read32_mbox_5906; |
| 16091 | tp->write32_mbox = tg3_write32_mbox_5906; |
| 16092 | tp->write32_tx_mbox = tg3_write32_mbox_5906; |
| 16093 | tp->write32_rx_mbox = tg3_write32_mbox_5906; |
| 16094 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 16095 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 16096 | if (tp->write32 == tg3_write_indirect_reg32 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16097 | (tg3_flag(tp, PCIX_MODE) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16098 | (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 16099 | tg3_asic_rev(tp) == ASIC_REV_5701))) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16100 | tg3_flag_set(tp, SRAM_USE_CONFIG); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 16101 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 16102 | /* The memory arbiter has to be enabled in order for SRAM accesses |
| 16103 | * to succeed. Normally on powerup the tg3 chip firmware will make |
| 16104 | * sure it is enabled, but other entities such as system netboot |
| 16105 | * code might disable it. |
| 16106 | */ |
| 16107 | val = tr32(MEMARB_MODE); |
| 16108 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 16109 | |
Matt Carlson | 9dc5e34 | 2011-11-04 09:15:02 +0000 | [diff] [blame] | 16110 | tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16111 | if (tg3_asic_rev(tp) == ASIC_REV_5704 || |
Matt Carlson | 9dc5e34 | 2011-11-04 09:15:02 +0000 | [diff] [blame] | 16112 | tg3_flag(tp, 5780_CLASS)) { |
| 16113 | if (tg3_flag(tp, PCIX_MODE)) { |
| 16114 | pci_read_config_dword(tp->pdev, |
| 16115 | tp->pcix_cap + PCI_X_STATUS, |
| 16116 | &val); |
| 16117 | tp->pci_fn = val & 0x7; |
| 16118 | } |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16119 | } else if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 16120 | tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 16121 | tg3_asic_rev(tp) == ASIC_REV_5720) { |
Matt Carlson | 9dc5e34 | 2011-11-04 09:15:02 +0000 | [diff] [blame] | 16122 | tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val); |
Michael Chan | 857001f | 2013-01-06 12:51:09 +0000 | [diff] [blame] | 16123 | if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) != NIC_SRAM_CPMUSTAT_SIG) |
| 16124 | val = tr32(TG3_CPMU_STATUS); |
| 16125 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16126 | if (tg3_asic_rev(tp) == ASIC_REV_5717) |
Michael Chan | 857001f | 2013-01-06 12:51:09 +0000 | [diff] [blame] | 16127 | tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5717) ? 1 : 0; |
| 16128 | else |
Matt Carlson | 9dc5e34 | 2011-11-04 09:15:02 +0000 | [diff] [blame] | 16129 | tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5719) >> |
| 16130 | TG3_CPMU_STATUS_FSHFT_5719; |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 16131 | } |
| 16132 | |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 16133 | if (tg3_flag(tp, FLUSH_POSTED_WRITES)) { |
| 16134 | tp->write32_tx_mbox = tg3_write_flush_reg32; |
| 16135 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 16136 | } |
| 16137 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 16138 | /* Get eeprom hw config before calling tg3_set_power_state(). |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16139 | * In particular, the TG3_FLAG_IS_NIC flag must be |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 16140 | * determined before calling tg3_set_power_state() so that |
| 16141 | * we know whether or not to switch out of Vaux power. |
| 16142 | * When the flag is set, it means that GPIO1 is used for eeprom |
| 16143 | * write protect and also implies that it is a LOM where GPIOs |
| 16144 | * are not used to switch power. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 16145 | */ |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 16146 | tg3_get_eeprom_hw_cfg(tp); |
| 16147 | |
Matt Carlson | 1caf13e | 2013-03-06 17:02:29 +0000 | [diff] [blame] | 16148 | if (tg3_flag(tp, FW_TSO) && tg3_flag(tp, ENABLE_ASF)) { |
Matt Carlson | cf9ecf4 | 2011-11-28 09:41:03 +0000 | [diff] [blame] | 16149 | tg3_flag_clear(tp, TSO_CAPABLE); |
| 16150 | tg3_flag_clear(tp, TSO_BUG); |
| 16151 | tp->fw_needed = NULL; |
| 16152 | } |
| 16153 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16154 | if (tg3_flag(tp, ENABLE_APE)) { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16155 | /* Allow reads and writes to the |
| 16156 | * APE register and memory space. |
| 16157 | */ |
| 16158 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 16159 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 16160 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16161 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 16162 | pci_state_reg); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 16163 | |
| 16164 | tg3_ape_lock_init(tp); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 16165 | } |
| 16166 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 16167 | /* Set up tp->grc_local_ctrl before calling |
| 16168 | * tg3_pwrsrc_switch_to_vmain(). GPIO1 driven high |
| 16169 | * will bring 5700's external PHY out of reset. |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 16170 | * It is also used as eeprom write protect on LOMs. |
| 16171 | */ |
| 16172 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16173 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16174 | tg3_flag(tp, EEPROM_WRITE_PROT)) |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 16175 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 16176 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 16177 | /* Unused GPIO3 must be driven as output on 5752 because there |
| 16178 | * are no pull-up resistors on unused GPIO pins. |
| 16179 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16180 | else if (tg3_asic_rev(tp) == ASIC_REV_5752) |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 16181 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 16182 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16183 | if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
| 16184 | tg3_asic_rev(tp) == ASIC_REV_57780 || |
Matt Carlson | 55086ad | 2011-12-14 11:09:59 +0000 | [diff] [blame] | 16185 | tg3_flag(tp, 57765_CLASS)) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 16186 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 16187 | |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 16188 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 16189 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 16190 | /* Turn off the debug UART. */ |
| 16191 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16192 | if (tg3_flag(tp, IS_NIC)) |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 16193 | /* Keep VMain power. */ |
| 16194 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 16195 | GRC_LCLCTRL_GPIO_OUTPUT0; |
| 16196 | } |
| 16197 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16198 | if (tg3_asic_rev(tp) == ASIC_REV_5762) |
Michael Chan | c86a856 | 2013-01-06 12:51:08 +0000 | [diff] [blame] | 16199 | tp->grc_local_ctrl |= |
| 16200 | tr32(GRC_LOCAL_CTRL) & GRC_LCLCTRL_GPIO_UART_SEL; |
| 16201 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 16202 | /* Switch out of Vaux if it is a NIC */ |
| 16203 | tg3_pwrsrc_switch_to_vmain(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16205 | /* Derive initial jumbo mode from MTU assigned in |
| 16206 | * ether_setup() via the alloc_etherdev() call |
| 16207 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16208 | if (tp->dev->mtu > ETH_DATA_LEN && !tg3_flag(tp, 5780_CLASS)) |
| 16209 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16210 | |
| 16211 | /* Determine WakeOnLan speed to use. */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16212 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 16213 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
| 16214 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0 || |
| 16215 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B2) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16216 | tg3_flag_clear(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16217 | } else { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16218 | tg3_flag_set(tp, WOL_SPEED_100MB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16219 | } |
| 16220 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16221 | if (tg3_asic_rev(tp) == ASIC_REV_5906) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16222 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 16223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16224 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16225 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 16226 | (tg3_asic_rev(tp) == ASIC_REV_5705 && |
| 16227 | (tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) && |
| 16228 | (tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A1)) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16229 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
| 16230 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 16231 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16232 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16233 | if (tg3_chip_rev(tp) == CHIPREV_5703_AX || |
| 16234 | tg3_chip_rev(tp) == CHIPREV_5704_AX) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16235 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16236 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16237 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16238 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16239 | if (tg3_flag(tp, 5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16240 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16241 | tg3_asic_rev(tp) != ASIC_REV_5785 && |
| 16242 | tg3_asic_rev(tp) != ASIC_REV_57780 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16243 | !tg3_flag(tp, 57765_PLUS)) { |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16244 | if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
| 16245 | tg3_asic_rev(tp) == ASIC_REV_5787 || |
| 16246 | tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 16247 | tg3_asic_rev(tp) == ASIC_REV_5761) { |
Michael Chan | d4011ad | 2007-02-13 12:17:25 -0800 | [diff] [blame] | 16248 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
| 16249 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16250 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 16251 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16252 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 16253 | } else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16254 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 16255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16256 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16257 | if (tg3_asic_rev(tp) == ASIC_REV_5784 && |
| 16258 | tg3_chip_rev(tp) != CHIPREV_5784_AX) { |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 16259 | tp->phy_otp = tg3_read_otp_phycfg(tp); |
| 16260 | if (tp->phy_otp == 0) |
| 16261 | tp->phy_otp = TG3_OTP_DEFAULT; |
| 16262 | } |
| 16263 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16264 | if (tg3_flag(tp, CPMU_PRESENT)) |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 16265 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
| 16266 | else |
| 16267 | tp->mi_mode = MAC_MI_MODE_BASE; |
| 16268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16269 | tp->coalesce_mode = 0; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16270 | if (tg3_chip_rev(tp) != CHIPREV_5700_AX && |
| 16271 | tg3_chip_rev(tp) != CHIPREV_5700_BX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16272 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
| 16273 | |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 16274 | /* Set these bits to enable statistics workaround. */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16275 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 16276 | tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || |
| 16277 | tg3_chip_rev_id(tp) == CHIPREV_ID_5720_A0) { |
Matt Carlson | 4d95847 | 2011-04-20 07:57:35 +0000 | [diff] [blame] | 16278 | tp->coalesce_mode |= HOSTCC_MODE_ATTN; |
| 16279 | tp->grc_mode |= GRC_MODE_IRQ_ON_FLOW_ATTN; |
| 16280 | } |
| 16281 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16282 | if (tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 16283 | tg3_asic_rev(tp) == ASIC_REV_57780) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16284 | tg3_flag_set(tp, USE_PHYLIB); |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 16285 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 16286 | err = tg3_mdio_init(tp); |
| 16287 | if (err) |
| 16288 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16289 | |
| 16290 | /* Initialize data/descriptor byte/word swapping. */ |
| 16291 | val = tr32(GRC_MODE); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16292 | if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 16293 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Matt Carlson | f2096f9 | 2011-04-05 14:22:48 +0000 | [diff] [blame] | 16294 | val &= (GRC_MODE_BYTE_SWAP_B2HRX_DATA | |
| 16295 | GRC_MODE_WORD_SWAP_B2HRX_DATA | |
| 16296 | GRC_MODE_B2HRX_ENABLE | |
| 16297 | GRC_MODE_HTX2B_ENABLE | |
| 16298 | GRC_MODE_HOST_STACKUP); |
| 16299 | else |
| 16300 | val &= GRC_MODE_HOST_STACKUP; |
| 16301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16302 | tw32(GRC_MODE, val | tp->grc_mode); |
| 16303 | |
| 16304 | tg3_switch_clocks(tp); |
| 16305 | |
| 16306 | /* Clear this out for sanity. */ |
| 16307 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 16308 | |
| 16309 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 16310 | &pci_state_reg); |
| 16311 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16312 | !tg3_flag(tp, PCIX_TARGET_HWBUG)) { |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16313 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
| 16314 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0 || |
| 16315 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B2 || |
| 16316 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16317 | void __iomem *sram_base; |
| 16318 | |
| 16319 | /* Write some dummy words into the SRAM status block |
| 16320 | * area, see if it reads back correctly. If the return |
| 16321 | * value is bad, force enable the PCIX workaround. |
| 16322 | */ |
| 16323 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; |
| 16324 | |
| 16325 | writel(0x00000000, sram_base); |
| 16326 | writel(0x00000000, sram_base + 4); |
| 16327 | writel(0xffffffff, sram_base + 4); |
| 16328 | if (readl(sram_base) != 0x00000000) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16329 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16330 | } |
| 16331 | } |
| 16332 | |
| 16333 | udelay(50); |
| 16334 | tg3_nvram_init(tp); |
| 16335 | |
Nithin Sujir | c4dab50 | 2013-03-06 17:02:34 +0000 | [diff] [blame] | 16336 | /* If the device has an NVRAM, no need to load patch firmware */ |
| 16337 | if (tg3_asic_rev(tp) == ASIC_REV_57766 && |
| 16338 | !tg3_flag(tp, NO_NVRAM)) |
| 16339 | tp->fw_needed = NULL; |
| 16340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16341 | grc_misc_cfg = tr32(GRC_MISC_CFG); |
| 16342 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; |
| 16343 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16344 | if (tg3_asic_rev(tp) == ASIC_REV_5705 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16345 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
| 16346 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16347 | tg3_flag_set(tp, IS_5788); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16348 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16349 | if (!tg3_flag(tp, IS_5788) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16350 | tg3_asic_rev(tp) != ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16351 | tg3_flag_set(tp, TAGGED_STATUS); |
| 16352 | if (tg3_flag(tp, TAGGED_STATUS)) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 16353 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
| 16354 | HOSTCC_MODE_CLRTICK_TXBD); |
| 16355 | |
| 16356 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; |
| 16357 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 16358 | tp->misc_host_ctrl); |
| 16359 | } |
| 16360 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 16361 | /* Preserve the APE MAC_MODE bits */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16362 | if (tg3_flag(tp, ENABLE_APE)) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 16363 | 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] | 16364 | else |
Matt Carlson | 6e01b20 | 2011-08-19 13:58:20 +0000 | [diff] [blame] | 16365 | tp->mac_mode = 0; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 16366 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 16367 | if (tg3_10_100_only_device(tp, ent)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16368 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16369 | |
| 16370 | err = tg3_phy_probe(tp); |
| 16371 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16372 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16373 | /* ... but do not return immediately ... */ |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 16374 | tg3_mdio_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16375 | } |
| 16376 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 16377 | tg3_read_vpd(tp); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 16378 | tg3_read_fw_ver(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16379 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16380 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 16381 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16382 | } else { |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16383 | if (tg3_asic_rev(tp) == ASIC_REV_5700) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16384 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16385 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16386 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16387 | } |
| 16388 | |
| 16389 | /* 5700 {AX,BX} chips have a broken status block link |
| 16390 | * change bit implementation, so we must use the |
| 16391 | * status register in those cases. |
| 16392 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16393 | if (tg3_asic_rev(tp) == ASIC_REV_5700) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16394 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16395 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16396 | tg3_flag_clear(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16397 | |
| 16398 | /* The led_ctrl is set during tg3_phy_probe, here we might |
| 16399 | * have to force the link status polling mechanism based |
| 16400 | * upon subsystem IDs. |
| 16401 | */ |
| 16402 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16403 | tg3_asic_rev(tp) == ASIC_REV_5701 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16404 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 16405 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16406 | tg3_flag_set(tp, USE_LINKCHG_REG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16407 | } |
| 16408 | |
| 16409 | /* For all SERDES we poll the MAC status register. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 16410 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16411 | tg3_flag_set(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16412 | else |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16413 | tg3_flag_clear(tp, POLL_SERDES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16414 | |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 16415 | tp->rx_offset = NET_SKB_PAD + NET_IP_ALIGN; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 16416 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16417 | if (tg3_asic_rev(tp) == ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16418 | tg3_flag(tp, PCIX_MODE)) { |
Eric Dumazet | 9205fd9 | 2011-11-18 06:47:01 +0000 | [diff] [blame] | 16419 | tp->rx_offset = NET_SKB_PAD; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 16420 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 16421 | tp->rx_copy_thresh = ~(u16)0; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 16422 | #endif |
| 16423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16424 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 16425 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
| 16426 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 16427 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
| 16428 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 16429 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 16430 | |
| 16431 | /* Increment the rx prod index on the rx std ring by at most |
| 16432 | * 8 for these chips to workaround hw errata. |
| 16433 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16434 | if (tg3_asic_rev(tp) == ASIC_REV_5750 || |
| 16435 | tg3_asic_rev(tp) == ASIC_REV_5752 || |
| 16436 | tg3_asic_rev(tp) == ASIC_REV_5755) |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 16437 | tp->rx_std_max_post = 8; |
| 16438 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16439 | if (tg3_flag(tp, ASPM_WORKAROUND)) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 16440 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
| 16441 | PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 16442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16443 | return err; |
| 16444 | } |
| 16445 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 16446 | #ifdef CONFIG_SPARC |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16447 | static int tg3_get_macaddr_sparc(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16448 | { |
| 16449 | struct net_device *dev = tp->dev; |
| 16450 | struct pci_dev *pdev = tp->pdev; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 16451 | struct device_node *dp = pci_device_to_OF_node(pdev); |
David S. Miller | 374d4ca | 2007-03-29 01:57:57 -0700 | [diff] [blame] | 16452 | const unsigned char *addr; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 16453 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16454 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 16455 | addr = of_get_property(dp, "local-mac-address", &len); |
| 16456 | if (addr && len == 6) { |
| 16457 | memcpy(dev->dev_addr, addr, 6); |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 16458 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16459 | } |
| 16460 | return -ENODEV; |
| 16461 | } |
| 16462 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16463 | static int tg3_get_default_macaddr_sparc(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16464 | { |
| 16465 | struct net_device *dev = tp->dev; |
| 16466 | |
| 16467 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); |
| 16468 | return 0; |
| 16469 | } |
| 16470 | #endif |
| 16471 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16472 | static int tg3_get_device_address(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16473 | { |
| 16474 | struct net_device *dev = tp->dev; |
| 16475 | u32 hi, lo, mac_offset; |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 16476 | int addr_ok = 0; |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 16477 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16478 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 16479 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16480 | if (!tg3_get_macaddr_sparc(tp)) |
| 16481 | return 0; |
| 16482 | #endif |
| 16483 | |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 16484 | if (tg3_flag(tp, IS_SSB_CORE)) { |
| 16485 | err = ssb_gige_get_macaddr(tp->pdev, &dev->dev_addr[0]); |
| 16486 | if (!err && is_valid_ether_addr(&dev->dev_addr[0])) |
| 16487 | return 0; |
| 16488 | } |
| 16489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16490 | mac_offset = 0x7c; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16491 | if (tg3_asic_rev(tp) == ASIC_REV_5704 || |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16492 | tg3_flag(tp, 5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16493 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 16494 | mac_offset = 0xcc; |
| 16495 | if (tg3_nvram_lock(tp)) |
| 16496 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); |
| 16497 | else |
| 16498 | tg3_nvram_unlock(tp); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16499 | } else if (tg3_flag(tp, 5717_PLUS)) { |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 16500 | if (tp->pci_fn & 1) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 16501 | mac_offset = 0xcc; |
Matt Carlson | 69f11c9 | 2011-07-13 09:27:30 +0000 | [diff] [blame] | 16502 | if (tp->pci_fn > 1) |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 16503 | mac_offset += 0x18c; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16504 | } else if (tg3_asic_rev(tp) == ASIC_REV_5906) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 16505 | mac_offset = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16506 | |
| 16507 | /* First try to get it from MAC address mailbox. */ |
| 16508 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); |
| 16509 | if ((hi >> 16) == 0x484b) { |
| 16510 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 16511 | dev->dev_addr[1] = (hi >> 0) & 0xff; |
| 16512 | |
| 16513 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); |
| 16514 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 16515 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 16516 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 16517 | dev->dev_addr[5] = (lo >> 0) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16518 | |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 16519 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
| 16520 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); |
| 16521 | } |
| 16522 | if (!addr_ok) { |
| 16523 | /* Next, try NVRAM. */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16524 | if (!tg3_flag(tp, NO_NVRAM) && |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 16525 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 16526 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 16527 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
| 16528 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 16529 | } |
| 16530 | /* Finally just fetch it out of the MAC control regs. */ |
| 16531 | else { |
| 16532 | hi = tr32(MAC_ADDR_0_HIGH); |
| 16533 | lo = tr32(MAC_ADDR_0_LOW); |
| 16534 | |
| 16535 | dev->dev_addr[5] = lo & 0xff; |
| 16536 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 16537 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 16538 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 16539 | dev->dev_addr[1] = hi & 0xff; |
| 16540 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 16541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16542 | } |
| 16543 | |
| 16544 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { |
David S. Miller | 7582a33 | 2008-03-20 15:53:15 -0700 | [diff] [blame] | 16545 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16546 | if (!tg3_get_default_macaddr_sparc(tp)) |
| 16547 | return 0; |
| 16548 | #endif |
| 16549 | return -EINVAL; |
| 16550 | } |
| 16551 | return 0; |
| 16552 | } |
| 16553 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16554 | #define BOUNDARY_SINGLE_CACHELINE 1 |
| 16555 | #define BOUNDARY_MULTI_CACHELINE 2 |
| 16556 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16557 | static u32 tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16558 | { |
| 16559 | int cacheline_size; |
| 16560 | u8 byte; |
| 16561 | int goal; |
| 16562 | |
| 16563 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); |
| 16564 | if (byte == 0) |
| 16565 | cacheline_size = 1024; |
| 16566 | else |
| 16567 | cacheline_size = (int) byte * 4; |
| 16568 | |
| 16569 | /* On 5703 and later chips, the boundary bits have no |
| 16570 | * effect. |
| 16571 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16572 | if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
| 16573 | tg3_asic_rev(tp) != ASIC_REV_5701 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16574 | !tg3_flag(tp, PCI_EXPRESS)) |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16575 | goto out; |
| 16576 | |
| 16577 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) |
| 16578 | goal = BOUNDARY_MULTI_CACHELINE; |
| 16579 | #else |
| 16580 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) |
| 16581 | goal = BOUNDARY_SINGLE_CACHELINE; |
| 16582 | #else |
| 16583 | goal = 0; |
| 16584 | #endif |
| 16585 | #endif |
| 16586 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16587 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 16588 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 16589 | goto out; |
| 16590 | } |
| 16591 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16592 | if (!goal) |
| 16593 | goto out; |
| 16594 | |
| 16595 | /* PCI controllers on most RISC systems tend to disconnect |
| 16596 | * when a device tries to burst across a cache-line boundary. |
| 16597 | * Therefore, letting tg3 do so just wastes PCI bandwidth. |
| 16598 | * |
| 16599 | * Unfortunately, for PCI-E there are only limited |
| 16600 | * write-side controls for this, and thus for reads |
| 16601 | * we will still get the disconnects. We'll also waste |
| 16602 | * these PCI cycles for both read and write for chips |
| 16603 | * other than 5700 and 5701 which do not implement the |
| 16604 | * boundary bits. |
| 16605 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16606 | if (tg3_flag(tp, PCIX_MODE) && !tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16607 | switch (cacheline_size) { |
| 16608 | case 16: |
| 16609 | case 32: |
| 16610 | case 64: |
| 16611 | case 128: |
| 16612 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 16613 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | |
| 16614 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); |
| 16615 | } else { |
| 16616 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 16617 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 16618 | } |
| 16619 | break; |
| 16620 | |
| 16621 | case 256: |
| 16622 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | |
| 16623 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); |
| 16624 | break; |
| 16625 | |
| 16626 | default: |
| 16627 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 16628 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 16629 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 16630 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16631 | } else if (tg3_flag(tp, PCI_EXPRESS)) { |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16632 | switch (cacheline_size) { |
| 16633 | case 16: |
| 16634 | case 32: |
| 16635 | case 64: |
| 16636 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 16637 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 16638 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; |
| 16639 | break; |
| 16640 | } |
| 16641 | /* fallthrough */ |
| 16642 | case 128: |
| 16643 | default: |
| 16644 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 16645 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; |
| 16646 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 16647 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16648 | } else { |
| 16649 | switch (cacheline_size) { |
| 16650 | case 16: |
| 16651 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 16652 | val |= (DMA_RWCTRL_READ_BNDRY_16 | |
| 16653 | DMA_RWCTRL_WRITE_BNDRY_16); |
| 16654 | break; |
| 16655 | } |
| 16656 | /* fallthrough */ |
| 16657 | case 32: |
| 16658 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 16659 | val |= (DMA_RWCTRL_READ_BNDRY_32 | |
| 16660 | DMA_RWCTRL_WRITE_BNDRY_32); |
| 16661 | break; |
| 16662 | } |
| 16663 | /* fallthrough */ |
| 16664 | case 64: |
| 16665 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 16666 | val |= (DMA_RWCTRL_READ_BNDRY_64 | |
| 16667 | DMA_RWCTRL_WRITE_BNDRY_64); |
| 16668 | break; |
| 16669 | } |
| 16670 | /* fallthrough */ |
| 16671 | case 128: |
| 16672 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 16673 | val |= (DMA_RWCTRL_READ_BNDRY_128 | |
| 16674 | DMA_RWCTRL_WRITE_BNDRY_128); |
| 16675 | break; |
| 16676 | } |
| 16677 | /* fallthrough */ |
| 16678 | case 256: |
| 16679 | val |= (DMA_RWCTRL_READ_BNDRY_256 | |
| 16680 | DMA_RWCTRL_WRITE_BNDRY_256); |
| 16681 | break; |
| 16682 | case 512: |
| 16683 | val |= (DMA_RWCTRL_READ_BNDRY_512 | |
| 16684 | DMA_RWCTRL_WRITE_BNDRY_512); |
| 16685 | break; |
| 16686 | case 1024: |
| 16687 | default: |
| 16688 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | |
| 16689 | DMA_RWCTRL_WRITE_BNDRY_1024); |
| 16690 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 16691 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16692 | } |
| 16693 | |
| 16694 | out: |
| 16695 | return val; |
| 16696 | } |
| 16697 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16698 | static int tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 16699 | int size, bool to_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16700 | { |
| 16701 | struct tg3_internal_buffer_desc test_desc; |
| 16702 | u32 sram_dma_descs; |
| 16703 | int i, ret; |
| 16704 | |
| 16705 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; |
| 16706 | |
| 16707 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); |
| 16708 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); |
| 16709 | tw32(RDMAC_STATUS, 0); |
| 16710 | tw32(WDMAC_STATUS, 0); |
| 16711 | |
| 16712 | tw32(BUFMGR_MODE, 0); |
| 16713 | tw32(FTQ_RESET, 0); |
| 16714 | |
| 16715 | test_desc.addr_hi = ((u64) buf_dma) >> 32; |
| 16716 | test_desc.addr_lo = buf_dma & 0xffffffff; |
| 16717 | test_desc.nic_mbuf = 0x00002100; |
| 16718 | test_desc.len = size; |
| 16719 | |
| 16720 | /* |
| 16721 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz |
| 16722 | * the *second* time the tg3 driver was getting loaded after an |
| 16723 | * initial scan. |
| 16724 | * |
| 16725 | * Broadcom tells me: |
| 16726 | * ...the DMA engine is connected to the GRC block and a DMA |
| 16727 | * reset may affect the GRC block in some unpredictable way... |
| 16728 | * The behavior of resets to individual blocks has not been tested. |
| 16729 | * |
| 16730 | * Broadcom noted the GRC reset will also reset all sub-components. |
| 16731 | */ |
| 16732 | if (to_device) { |
| 16733 | test_desc.cqid_sqid = (13 << 8) | 2; |
| 16734 | |
| 16735 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); |
| 16736 | udelay(40); |
| 16737 | } else { |
| 16738 | test_desc.cqid_sqid = (16 << 8) | 7; |
| 16739 | |
| 16740 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); |
| 16741 | udelay(40); |
| 16742 | } |
| 16743 | test_desc.flags = 0x00000005; |
| 16744 | |
| 16745 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { |
| 16746 | u32 val; |
| 16747 | |
| 16748 | val = *(((u32 *)&test_desc) + i); |
| 16749 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, |
| 16750 | sram_dma_descs + (i * sizeof(u32))); |
| 16751 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 16752 | } |
| 16753 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 16754 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 16755 | if (to_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16756 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 16757 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16758 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16759 | |
| 16760 | ret = -ENODEV; |
| 16761 | for (i = 0; i < 40; i++) { |
| 16762 | u32 val; |
| 16763 | |
| 16764 | if (to_device) |
| 16765 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); |
| 16766 | else |
| 16767 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); |
| 16768 | if ((val & 0xffff) == sram_dma_descs) { |
| 16769 | ret = 0; |
| 16770 | break; |
| 16771 | } |
| 16772 | |
| 16773 | udelay(100); |
| 16774 | } |
| 16775 | |
| 16776 | return ret; |
| 16777 | } |
| 16778 | |
David S. Miller | ded7340 | 2005-05-23 13:59:47 -0700 | [diff] [blame] | 16779 | #define TEST_BUFFER_SIZE 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16780 | |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 16781 | static DEFINE_PCI_DEVICE_TABLE(tg3_dma_wait_state_chipsets) = { |
Joe Perches | 895950c | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 16782 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
| 16783 | { }, |
| 16784 | }; |
| 16785 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16786 | static int tg3_test_dma(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16787 | { |
| 16788 | dma_addr_t buf_dma; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16789 | u32 *buf, saved_dma_rwctrl; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 16790 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16791 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 16792 | buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
| 16793 | &buf_dma, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16794 | if (!buf) { |
| 16795 | ret = -ENOMEM; |
| 16796 | goto out_nofree; |
| 16797 | } |
| 16798 | |
| 16799 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | |
| 16800 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); |
| 16801 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16802 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16803 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16804 | if (tg3_flag(tp, 57765_PLUS)) |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 16805 | goto out; |
| 16806 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16807 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16808 | /* DMA read watermark not used on PCIE */ |
| 16809 | tp->dma_rwctrl |= 0x00180000; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16810 | } else if (!tg3_flag(tp, PCIX_MODE)) { |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16811 | if (tg3_asic_rev(tp) == ASIC_REV_5705 || |
| 16812 | tg3_asic_rev(tp) == ASIC_REV_5750) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16813 | tp->dma_rwctrl |= 0x003f0000; |
| 16814 | else |
| 16815 | tp->dma_rwctrl |= 0x003f000f; |
| 16816 | } else { |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16817 | if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
| 16818 | tg3_asic_rev(tp) == ASIC_REV_5704) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16819 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 16820 | u32 read_water = 0x7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16821 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 16822 | /* If the 5704 is behind the EPB bridge, we can |
| 16823 | * do the less restrictive ONE_DMA workaround for |
| 16824 | * better performance. |
| 16825 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16826 | if (tg3_flag(tp, 40BIT_DMA_BUG) && |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16827 | tg3_asic_rev(tp) == ASIC_REV_5704) |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 16828 | tp->dma_rwctrl |= 0x8000; |
| 16829 | else if (ccval == 0x6 || ccval == 0x7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16830 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 16831 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16832 | if (tg3_asic_rev(tp) == ASIC_REV_5703) |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 16833 | read_water = 4; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16834 | /* Set bit 23 to enable PCIX hw bug fix */ |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 16835 | tp->dma_rwctrl |= |
| 16836 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | |
| 16837 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | |
| 16838 | (1 << 23); |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16839 | } else if (tg3_asic_rev(tp) == ASIC_REV_5780) { |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 16840 | /* 5780 always in PCIX mode */ |
| 16841 | tp->dma_rwctrl |= 0x00144000; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16842 | } else if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 16843 | /* 5714 always in PCIX mode */ |
| 16844 | tp->dma_rwctrl |= 0x00148000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16845 | } else { |
| 16846 | tp->dma_rwctrl |= 0x001b000f; |
| 16847 | } |
| 16848 | } |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 16849 | if (tg3_flag(tp, ONE_DMA_AT_ONCE)) |
| 16850 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16851 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16852 | if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
| 16853 | tg3_asic_rev(tp) == ASIC_REV_5704) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16854 | tp->dma_rwctrl &= 0xfffffff0; |
| 16855 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16856 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 16857 | tg3_asic_rev(tp) == ASIC_REV_5701) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16858 | /* Remove this if it causes problems for some boards. */ |
| 16859 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; |
| 16860 | |
| 16861 | /* On 5700/5701 chips, we need to set this bit. |
| 16862 | * Otherwise the chip will issue cacheline transactions |
| 16863 | * to streamable DMA memory with not all the byte |
| 16864 | * enables turned on. This is an error on several |
| 16865 | * RISC PCI controllers, in particular sparc64. |
| 16866 | * |
| 16867 | * On 5703/5704 chips, this bit has been reassigned |
| 16868 | * a different meaning. In particular, it is used |
| 16869 | * on those chips to enable a PCI-X workaround. |
| 16870 | */ |
| 16871 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; |
| 16872 | } |
| 16873 | |
| 16874 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 16875 | |
| 16876 | #if 0 |
| 16877 | /* Unneeded, already done by tg3_get_invariants. */ |
| 16878 | tg3_switch_clocks(tp); |
| 16879 | #endif |
| 16880 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 16881 | if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
| 16882 | tg3_asic_rev(tp) != ASIC_REV_5701) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16883 | goto out; |
| 16884 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16885 | /* It is best to perform DMA test with maximum write burst size |
| 16886 | * to expose the 5700/5701 write DMA bug. |
| 16887 | */ |
| 16888 | saved_dma_rwctrl = tp->dma_rwctrl; |
| 16889 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 16890 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 16891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16892 | while (1) { |
| 16893 | u32 *p = buf, i; |
| 16894 | |
| 16895 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) |
| 16896 | p[i] = i; |
| 16897 | |
| 16898 | /* Send the buffer to the chip. */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 16899 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16900 | if (ret) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16901 | dev_err(&tp->pdev->dev, |
| 16902 | "%s: Buffer write failed. err = %d\n", |
| 16903 | __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16904 | break; |
| 16905 | } |
| 16906 | |
| 16907 | #if 0 |
| 16908 | /* validate data reached card RAM correctly. */ |
| 16909 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 16910 | u32 val; |
| 16911 | tg3_read_mem(tp, 0x2100 + (i*4), &val); |
| 16912 | if (le32_to_cpu(val) != p[i]) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16913 | dev_err(&tp->pdev->dev, |
| 16914 | "%s: Buffer corrupted on device! " |
| 16915 | "(%d != %d)\n", __func__, val, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16916 | /* ret = -ENODEV here? */ |
| 16917 | } |
| 16918 | p[i] = 0; |
| 16919 | } |
| 16920 | #endif |
| 16921 | /* Now read it back. */ |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 16922 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16923 | if (ret) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 16924 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
| 16925 | "err = %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16926 | break; |
| 16927 | } |
| 16928 | |
| 16929 | /* Verify it. */ |
| 16930 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 16931 | if (p[i] == i) |
| 16932 | continue; |
| 16933 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16934 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 16935 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 16936 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16937 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 16938 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 16939 | break; |
| 16940 | } else { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 16941 | dev_err(&tp->pdev->dev, |
| 16942 | "%s: Buffer corrupted on read back! " |
| 16943 | "(%d != %d)\n", __func__, p[i], i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16944 | ret = -ENODEV; |
| 16945 | goto out; |
| 16946 | } |
| 16947 | } |
| 16948 | |
| 16949 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { |
| 16950 | /* Success. */ |
| 16951 | ret = 0; |
| 16952 | break; |
| 16953 | } |
| 16954 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16955 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 16956 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 16957 | /* DMA test passed without adjusting DMA boundary, |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 16958 | * now look for chipsets that are known to expose the |
| 16959 | * DMA bug without failing the test. |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16960 | */ |
Matt Carlson | 4143470 | 2011-03-09 16:58:22 +0000 | [diff] [blame] | 16961 | if (pci_dev_present(tg3_dma_wait_state_chipsets)) { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 16962 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 16963 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 16964 | } else { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 16965 | /* Safe to use the calculated DMA boundary. */ |
| 16966 | tp->dma_rwctrl = saved_dma_rwctrl; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 16967 | } |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 16968 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 16969 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 16970 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16971 | |
| 16972 | out: |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 16973 | dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16974 | out_nofree: |
| 16975 | return ret; |
| 16976 | } |
| 16977 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 16978 | static void tg3_init_bufmgr_config(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16979 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16980 | if (tg3_flag(tp, 57765_PLUS)) { |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 16981 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 16982 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 16983 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 16984 | DEFAULT_MB_MACRX_LOW_WATER_57765; |
| 16985 | tp->bufmgr_config.mbuf_high_water = |
| 16986 | DEFAULT_MB_HIGH_WATER_57765; |
| 16987 | |
| 16988 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 16989 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 16990 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 16991 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; |
| 16992 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 16993 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 16994 | } else if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 16995 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 16996 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 16997 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 16998 | DEFAULT_MB_MACRX_LOW_WATER_5705; |
| 16999 | tp->bufmgr_config.mbuf_high_water = |
| 17000 | DEFAULT_MB_HIGH_WATER_5705; |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 17001 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 17002 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 17003 | DEFAULT_MB_MACRX_LOW_WATER_5906; |
| 17004 | tp->bufmgr_config.mbuf_high_water = |
| 17005 | DEFAULT_MB_HIGH_WATER_5906; |
| 17006 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17007 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 17008 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 17009 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; |
| 17010 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 17011 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; |
| 17012 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 17013 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; |
| 17014 | } else { |
| 17015 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 17016 | DEFAULT_MB_RDMA_LOW_WATER; |
| 17017 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 17018 | DEFAULT_MB_MACRX_LOW_WATER; |
| 17019 | tp->bufmgr_config.mbuf_high_water = |
| 17020 | DEFAULT_MB_HIGH_WATER; |
| 17021 | |
| 17022 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 17023 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; |
| 17024 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 17025 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; |
| 17026 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 17027 | DEFAULT_MB_HIGH_WATER_JUMBO; |
| 17028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17029 | |
| 17030 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; |
| 17031 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; |
| 17032 | } |
| 17033 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 17034 | static char *tg3_phy_string(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17035 | { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 17036 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
| 17037 | case TG3_PHY_ID_BCM5400: return "5400"; |
| 17038 | case TG3_PHY_ID_BCM5401: return "5401"; |
| 17039 | case TG3_PHY_ID_BCM5411: return "5411"; |
| 17040 | case TG3_PHY_ID_BCM5701: return "5701"; |
| 17041 | case TG3_PHY_ID_BCM5703: return "5703"; |
| 17042 | case TG3_PHY_ID_BCM5704: return "5704"; |
| 17043 | case TG3_PHY_ID_BCM5705: return "5705"; |
| 17044 | case TG3_PHY_ID_BCM5750: return "5750"; |
| 17045 | case TG3_PHY_ID_BCM5752: return "5752"; |
| 17046 | case TG3_PHY_ID_BCM5714: return "5714"; |
| 17047 | case TG3_PHY_ID_BCM5780: return "5780"; |
| 17048 | case TG3_PHY_ID_BCM5755: return "5755"; |
| 17049 | case TG3_PHY_ID_BCM5787: return "5787"; |
| 17050 | case TG3_PHY_ID_BCM5784: return "5784"; |
| 17051 | case TG3_PHY_ID_BCM5756: return "5722/5756"; |
| 17052 | case TG3_PHY_ID_BCM5906: return "5906"; |
| 17053 | case TG3_PHY_ID_BCM5761: return "5761"; |
| 17054 | case TG3_PHY_ID_BCM5718C: return "5718C"; |
| 17055 | case TG3_PHY_ID_BCM5718S: return "5718S"; |
| 17056 | case TG3_PHY_ID_BCM57765: return "57765"; |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 17057 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
Matt Carlson | 6418f2c | 2011-04-05 14:22:49 +0000 | [diff] [blame] | 17058 | case TG3_PHY_ID_BCM5720C: return "5720C"; |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 17059 | case TG3_PHY_ID_BCM5762: return "5762C"; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 17060 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17061 | case 0: return "serdes"; |
| 17062 | default: return "unknown"; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 17063 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17064 | } |
| 17065 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 17066 | static char *tg3_bus_string(struct tg3 *tp, char *str) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 17067 | { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17068 | if (tg3_flag(tp, PCI_EXPRESS)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 17069 | strcpy(str, "PCI Express"); |
| 17070 | return str; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17071 | } else if (tg3_flag(tp, PCIX_MODE)) { |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 17072 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
| 17073 | |
| 17074 | strcpy(str, "PCIX:"); |
| 17075 | |
| 17076 | if ((clock_ctrl == 7) || |
| 17077 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == |
| 17078 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) |
| 17079 | strcat(str, "133MHz"); |
| 17080 | else if (clock_ctrl == 0) |
| 17081 | strcat(str, "33MHz"); |
| 17082 | else if (clock_ctrl == 2) |
| 17083 | strcat(str, "50MHz"); |
| 17084 | else if (clock_ctrl == 4) |
| 17085 | strcat(str, "66MHz"); |
| 17086 | else if (clock_ctrl == 6) |
| 17087 | strcat(str, "100MHz"); |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 17088 | } else { |
| 17089 | strcpy(str, "PCI:"); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17090 | if (tg3_flag(tp, PCI_HIGH_SPEED)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 17091 | strcat(str, "66MHz"); |
| 17092 | else |
| 17093 | strcat(str, "33MHz"); |
| 17094 | } |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17095 | if (tg3_flag(tp, PCI_32BIT)) |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 17096 | strcat(str, ":32-bit"); |
| 17097 | else |
| 17098 | strcat(str, ":64-bit"); |
| 17099 | return str; |
| 17100 | } |
| 17101 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 17102 | static void tg3_init_coal(struct tg3 *tp) |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 17103 | { |
| 17104 | struct ethtool_coalesce *ec = &tp->coal; |
| 17105 | |
| 17106 | memset(ec, 0, sizeof(*ec)); |
| 17107 | ec->cmd = ETHTOOL_GCOALESCE; |
| 17108 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; |
| 17109 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; |
| 17110 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; |
| 17111 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; |
| 17112 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; |
| 17113 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; |
| 17114 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; |
| 17115 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; |
| 17116 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; |
| 17117 | |
| 17118 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | |
| 17119 | HOSTCC_MODE_CLRTICK_TXBD)) { |
| 17120 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; |
| 17121 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; |
| 17122 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; |
| 17123 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; |
| 17124 | } |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 17125 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17126 | if (tg3_flag(tp, 5705_PLUS)) { |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 17127 | ec->rx_coalesce_usecs_irq = 0; |
| 17128 | ec->tx_coalesce_usecs_irq = 0; |
| 17129 | ec->stats_block_coalesce_usecs = 0; |
| 17130 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 17131 | } |
| 17132 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 17133 | static int tg3_init_one(struct pci_dev *pdev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17134 | const struct pci_device_id *ent) |
| 17135 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17136 | struct net_device *dev; |
| 17137 | struct tg3 *tp; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 17138 | int i, err, pm_cap; |
| 17139 | u32 sndmbx, rcvmbx, intmbx; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 17140 | char str[40]; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 17141 | u64 dma_mask, persist_dma_mask; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 17142 | netdev_features_t features = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17143 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 17144 | printk_once(KERN_INFO "%s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17145 | |
| 17146 | err = pci_enable_device(pdev); |
| 17147 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 17148 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17149 | return err; |
| 17150 | } |
| 17151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17152 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 17153 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 17154 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17155 | goto err_out_disable_pdev; |
| 17156 | } |
| 17157 | |
| 17158 | pci_set_master(pdev); |
| 17159 | |
| 17160 | /* Find power-management capability. */ |
| 17161 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 17162 | if (pm_cap == 0) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 17163 | dev_err(&pdev->dev, |
| 17164 | "Cannot find Power Management capability, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17165 | err = -EIO; |
| 17166 | goto err_out_free_res; |
| 17167 | } |
| 17168 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 17169 | err = pci_set_power_state(pdev, PCI_D0); |
| 17170 | if (err) { |
| 17171 | dev_err(&pdev->dev, "Transition to D0 failed, aborting\n"); |
| 17172 | goto err_out_free_res; |
| 17173 | } |
| 17174 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 17175 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17176 | if (!dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17177 | err = -ENOMEM; |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 17178 | goto err_out_power_down; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17179 | } |
| 17180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17181 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 17182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17183 | tp = netdev_priv(dev); |
| 17184 | tp->pdev = pdev; |
| 17185 | tp->dev = dev; |
| 17186 | tp->pm_cap = pm_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17187 | tp->rx_mode = TG3_DEF_RX_MODE; |
| 17188 | tp->tx_mode = TG3_DEF_TX_MODE; |
Nithin Nayak Sujir | 9c13cb8 | 2013-01-14 17:10:59 +0000 | [diff] [blame] | 17189 | tp->irq_sync = 1; |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 17190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17191 | if (tg3_debug > 0) |
| 17192 | tp->msg_enable = tg3_debug; |
| 17193 | else |
| 17194 | tp->msg_enable = TG3_DEF_MSG_ENABLE; |
| 17195 | |
Hauke Mehrtens | 7e6c63f | 2013-02-07 05:37:39 +0000 | [diff] [blame] | 17196 | if (pdev_is_ssb_gige_core(pdev)) { |
| 17197 | tg3_flag_set(tp, IS_SSB_CORE); |
| 17198 | if (ssb_gige_must_flush_posted_writes(pdev)) |
| 17199 | tg3_flag_set(tp, FLUSH_POSTED_WRITES); |
| 17200 | if (ssb_gige_one_dma_at_once(pdev)) |
| 17201 | tg3_flag_set(tp, ONE_DMA_AT_ONCE); |
| 17202 | if (ssb_gige_have_roboswitch(pdev)) |
| 17203 | tg3_flag_set(tp, ROBOSWITCH); |
| 17204 | if (ssb_gige_is_rgmii(pdev)) |
| 17205 | tg3_flag_set(tp, RGMII_MODE); |
| 17206 | } |
| 17207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17208 | /* The word/byte swap controls here control register access byte |
| 17209 | * swapping. DMA data byte swapping is controlled in the GRC_MODE |
| 17210 | * setting below. |
| 17211 | */ |
| 17212 | tp->misc_host_ctrl = |
| 17213 | MISC_HOST_CTRL_MASK_PCI_INT | |
| 17214 | MISC_HOST_CTRL_WORD_SWAP | |
| 17215 | MISC_HOST_CTRL_INDIR_ACCESS | |
| 17216 | MISC_HOST_CTRL_PCISTATE_RW; |
| 17217 | |
| 17218 | /* The NONFRM (non-frame) byte/word swap controls take effect |
| 17219 | * on descriptor entries, anything which isn't packet data. |
| 17220 | * |
| 17221 | * The StrongARM chips on the board (one for tx, one for rx) |
| 17222 | * are running in big-endian mode. |
| 17223 | */ |
| 17224 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | |
| 17225 | GRC_MODE_WSWAP_NONFRM_DATA); |
| 17226 | #ifdef __BIG_ENDIAN |
| 17227 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; |
| 17228 | #endif |
| 17229 | spin_lock_init(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17230 | spin_lock_init(&tp->indirect_lock); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 17231 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17232 | |
Matt Carlson | d5fe488 | 2008-11-21 17:20:32 -0800 | [diff] [blame] | 17233 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 17234 | if (!tp->regs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 17235 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17236 | err = -ENOMEM; |
| 17237 | goto err_out_free_dev; |
| 17238 | } |
| 17239 | |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 17240 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 17241 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761E || |
| 17242 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S || |
| 17243 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761SE || |
| 17244 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
Michael Chan | 79d4969 | 2012-11-05 14:26:29 +0000 | [diff] [blame] | 17245 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C || |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 17246 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 17247 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
Michael Chan | c65a17f | 2013-01-06 12:51:07 +0000 | [diff] [blame] | 17248 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720 || |
| 17249 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5762 || |
| 17250 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725 || |
| 17251 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5727) { |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 17252 | tg3_flag_set(tp, ENABLE_APE); |
| 17253 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
| 17254 | if (!tp->aperegs) { |
| 17255 | dev_err(&pdev->dev, |
| 17256 | "Cannot map APE registers, aborting\n"); |
| 17257 | err = -ENOMEM; |
| 17258 | goto err_out_iounmap; |
| 17259 | } |
| 17260 | } |
| 17261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17262 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
| 17263 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17265 | dev->ethtool_ops = &tg3_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17266 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
Matt Carlson | 2ffcc98 | 2011-05-19 12:12:44 +0000 | [diff] [blame] | 17267 | dev->netdev_ops = &tg3_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17268 | dev->irq = pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17269 | |
Nithin Nayak Sujir | 3d567e0 | 2012-11-14 14:44:26 +0000 | [diff] [blame] | 17270 | err = tg3_get_invariants(tp, ent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17271 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 17272 | dev_err(&pdev->dev, |
| 17273 | "Problem fetching invariants of chip, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 17274 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17275 | } |
| 17276 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 17277 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
| 17278 | * device behind the EPB cannot support DMA addresses > 40-bit. |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 17279 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
| 17280 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and |
| 17281 | * do DMA address check in tg3_start_xmit(). |
| 17282 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17283 | if (tg3_flag(tp, IS_5788)) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 17284 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17285 | else if (tg3_flag(tp, 40BIT_DMA_BUG)) { |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 17286 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 17287 | #ifdef CONFIG_HIGHMEM |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 17288 | dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 17289 | #endif |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 17290 | } else |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 17291 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 17292 | |
| 17293 | /* Configure DMA attributes. */ |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 17294 | if (dma_mask > DMA_BIT_MASK(32)) { |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 17295 | err = pci_set_dma_mask(pdev, dma_mask); |
| 17296 | if (!err) { |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 17297 | features |= NETIF_F_HIGHDMA; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 17298 | err = pci_set_consistent_dma_mask(pdev, |
| 17299 | persist_dma_mask); |
| 17300 | if (err < 0) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 17301 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
| 17302 | "DMA for consistent allocations\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 17303 | goto err_out_apeunmap; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 17304 | } |
| 17305 | } |
| 17306 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 17307 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
| 17308 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 17309 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 17310 | dev_err(&pdev->dev, |
| 17311 | "No usable DMA configuration, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 17312 | goto err_out_apeunmap; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 17313 | } |
| 17314 | } |
| 17315 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 17316 | tg3_init_bufmgr_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17317 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 17318 | features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 17319 | |
| 17320 | /* 5700 B0 chips do not support checksumming correctly due |
| 17321 | * to hardware bugs. |
| 17322 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 17323 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5700_B0) { |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 17324 | features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
| 17325 | |
| 17326 | if (tg3_flag(tp, 5755_PLUS)) |
| 17327 | features |= NETIF_F_IPV6_CSUM; |
| 17328 | } |
| 17329 | |
Michael Chan | 4e3a7aa | 2006-03-20 17:47:44 -0800 | [diff] [blame] | 17330 | /* TSO is on by default on chips that support hardware TSO. |
| 17331 | * Firmware TSO on older chips gives lower performance, so it |
| 17332 | * is off by default, but can be enabled using ethtool. |
| 17333 | */ |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17334 | if ((tg3_flag(tp, HW_TSO_1) || |
| 17335 | tg3_flag(tp, HW_TSO_2) || |
| 17336 | tg3_flag(tp, HW_TSO_3)) && |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 17337 | (features & NETIF_F_IP_CSUM)) |
| 17338 | features |= NETIF_F_TSO; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17339 | 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] | 17340 | if (features & NETIF_F_IPV6_CSUM) |
| 17341 | features |= NETIF_F_TSO6; |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17342 | if (tg3_flag(tp, HW_TSO_3) || |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 17343 | tg3_asic_rev(tp) == ASIC_REV_5761 || |
| 17344 | (tg3_asic_rev(tp) == ASIC_REV_5784 && |
| 17345 | tg3_chip_rev(tp) != CHIPREV_5784_AX) || |
| 17346 | tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 17347 | tg3_asic_rev(tp) == ASIC_REV_57780) |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 17348 | features |= NETIF_F_TSO_ECN; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 17349 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17350 | |
Matt Carlson | d542fe2 | 2011-05-19 16:02:43 +0000 | [diff] [blame] | 17351 | dev->features |= features; |
| 17352 | dev->vlan_features |= features; |
| 17353 | |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 17354 | /* |
| 17355 | * Add loopback capability only for a subset of devices that support |
| 17356 | * MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY |
| 17357 | * loopback for the remaining devices. |
| 17358 | */ |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 17359 | if (tg3_asic_rev(tp) != ASIC_REV_5780 && |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 17360 | !tg3_flag(tp, CPMU_PRESENT)) |
| 17361 | /* Add the loopback capability */ |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 17362 | features |= NETIF_F_LOOPBACK; |
| 17363 | |
Matt Carlson | 0da0606 | 2011-05-19 12:12:53 +0000 | [diff] [blame] | 17364 | dev->hw_features |= features; |
Mahesh Bandewar | 06c03c0 | 2011-05-08 06:51:48 +0000 | [diff] [blame] | 17365 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 17366 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A1 && |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17367 | !tg3_flag(tp, TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17368 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17369 | tg3_flag_set(tp, MAX_RXPEND_64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17370 | tp->rx_pending = 63; |
| 17371 | } |
| 17372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17373 | err = tg3_get_device_address(tp); |
| 17374 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 17375 | dev_err(&pdev->dev, |
| 17376 | "Could not obtain valid ethernet address, aborting\n"); |
Matt Carlson | c9cab24 | 2011-07-13 09:27:27 +0000 | [diff] [blame] | 17377 | goto err_out_apeunmap; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 17378 | } |
| 17379 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 17380 | /* |
| 17381 | * Reset chip in case UNDI or EFI driver did not shutdown |
| 17382 | * DMA self test will enable WDMAC and we'll see (spurious) |
| 17383 | * pending DMA on the PCI bus at that point. |
| 17384 | */ |
| 17385 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
| 17386 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 17387 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
| 17388 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 17389 | } |
| 17390 | |
| 17391 | err = tg3_test_dma(tp); |
| 17392 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 17393 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 17394 | goto err_out_apeunmap; |
| 17395 | } |
| 17396 | |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 17397 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
| 17398 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; |
| 17399 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 17400 | for (i = 0; i < tp->irq_max; i++) { |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 17401 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 17402 | |
| 17403 | tnapi->tp = tp; |
| 17404 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; |
| 17405 | |
| 17406 | tnapi->int_mbox = intmbx; |
Matt Carlson | 93a700a | 2011-08-31 11:44:54 +0000 | [diff] [blame] | 17407 | if (i <= 4) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 17408 | intmbx += 0x8; |
| 17409 | else |
| 17410 | intmbx += 0x4; |
| 17411 | |
| 17412 | tnapi->consmbox = rcvmbx; |
| 17413 | tnapi->prodmbox = sndmbx; |
| 17414 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 17415 | if (i) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 17416 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 17417 | else |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 17418 | tnapi->coal_now = HOSTCC_MODE_NOW; |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 17419 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17420 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 17421 | break; |
| 17422 | |
| 17423 | /* |
| 17424 | * If we support MSIX, we'll be using RSS. If we're using |
| 17425 | * RSS, the first vector only handles link interrupts and the |
| 17426 | * remaining vectors handle rx and tx interrupts. Reuse the |
| 17427 | * mailbox values for the next iteration. The values we setup |
| 17428 | * above are still useful for the single vectored mode. |
| 17429 | */ |
| 17430 | if (!i) |
| 17431 | continue; |
| 17432 | |
| 17433 | rcvmbx += 0x8; |
| 17434 | |
| 17435 | if (sndmbx & 0x4) |
| 17436 | sndmbx -= 0x4; |
| 17437 | else |
| 17438 | sndmbx += 0xc; |
| 17439 | } |
| 17440 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 17441 | tg3_init_coal(tp); |
| 17442 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 17443 | pci_set_drvdata(pdev, dev); |
| 17444 | |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 17445 | if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 17446 | tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 17447 | tg3_asic_rev(tp) == ASIC_REV_5762) |
Matt Carlson | fb4ce8a | 2012-12-03 19:37:00 +0000 | [diff] [blame] | 17448 | tg3_flag_set(tp, PTP_CAPABLE); |
| 17449 | |
Matt Carlson | cd0d722 | 2011-07-13 09:27:33 +0000 | [diff] [blame] | 17450 | if (tg3_flag(tp, 5717_PLUS)) { |
| 17451 | /* Resume a low-power mode */ |
| 17452 | tg3_frob_aux_power(tp, false); |
| 17453 | } |
| 17454 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 17455 | tg3_timer_init(tp); |
| 17456 | |
Michael Chan | 402e139 | 2013-02-14 12:13:41 +0000 | [diff] [blame] | 17457 | tg3_carrier_off(tp); |
| 17458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17459 | err = register_netdev(dev); |
| 17460 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 17461 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 17462 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17463 | } |
| 17464 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 17465 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
| 17466 | tp->board_part_number, |
Joe Perches | 4153577 | 2013-02-16 11:20:04 +0000 | [diff] [blame] | 17467 | tg3_chip_rev_id(tp), |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 17468 | tg3_bus_string(tp, str), |
| 17469 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17470 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 17471 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 17472 | struct phy_device *phydev; |
| 17473 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 17474 | netdev_info(dev, |
| 17475 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 17476 | phydev->drv->name, dev_name(&phydev->dev)); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 17477 | } else { |
| 17478 | char *ethtype; |
| 17479 | |
| 17480 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 17481 | ethtype = "10/100Base-TX"; |
| 17482 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 17483 | ethtype = "1000Base-SX"; |
| 17484 | else |
| 17485 | ethtype = "10/100/1000Base-T"; |
| 17486 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 17487 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
Matt Carlson | 4700783 | 2011-04-20 07:57:43 +0000 | [diff] [blame] | 17488 | "(WireSpeed[%d], EEE[%d])\n", |
| 17489 | tg3_phy_string(tp), ethtype, |
| 17490 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0, |
| 17491 | (tp->phy_flags & TG3_PHYFLG_EEE_CAP) != 0); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 17492 | } |
Matt Carlson | df59c94 | 2008-11-03 16:52:56 -0800 | [diff] [blame] | 17493 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 17494 | 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] | 17495 | (dev->features & NETIF_F_RXCSUM) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17496 | tg3_flag(tp, USE_LINKCHG_REG) != 0, |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 17497 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17498 | tg3_flag(tp, ENABLE_ASF) != 0, |
| 17499 | tg3_flag(tp, TSO_CAPABLE) != 0); |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 17500 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
| 17501 | tp->dma_rwctrl, |
| 17502 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : |
| 17503 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17504 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17505 | pci_save_state(pdev); |
| 17506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17507 | return 0; |
| 17508 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 17509 | err_out_apeunmap: |
| 17510 | if (tp->aperegs) { |
| 17511 | iounmap(tp->aperegs); |
| 17512 | tp->aperegs = NULL; |
| 17513 | } |
| 17514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17515 | err_out_iounmap: |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 17516 | if (tp->regs) { |
| 17517 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 17518 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 17519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17520 | |
| 17521 | err_out_free_dev: |
| 17522 | free_netdev(dev); |
| 17523 | |
Matt Carlson | 1682128 | 2011-07-13 09:27:28 +0000 | [diff] [blame] | 17524 | err_out_power_down: |
| 17525 | pci_set_power_state(pdev, PCI_D3hot); |
| 17526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17527 | err_out_free_res: |
| 17528 | pci_release_regions(pdev); |
| 17529 | |
| 17530 | err_out_disable_pdev: |
| 17531 | pci_disable_device(pdev); |
| 17532 | pci_set_drvdata(pdev, NULL); |
| 17533 | return err; |
| 17534 | } |
| 17535 | |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 17536 | static void tg3_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17537 | { |
| 17538 | struct net_device *dev = pci_get_drvdata(pdev); |
| 17539 | |
| 17540 | if (dev) { |
| 17541 | struct tg3 *tp = netdev_priv(dev); |
| 17542 | |
Jesper Juhl | e3c5530 | 2012-04-09 22:50:15 +0200 | [diff] [blame] | 17543 | release_firmware(tp->fw); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 17544 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 17545 | tg3_reset_task_cancel(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 17546 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 17547 | if (tg3_flag(tp, USE_PHYLIB)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 17548 | tg3_phy_fini(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 17549 | tg3_mdio_fini(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 17550 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 17551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17552 | unregister_netdev(dev); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 17553 | if (tp->aperegs) { |
| 17554 | iounmap(tp->aperegs); |
| 17555 | tp->aperegs = NULL; |
| 17556 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 17557 | if (tp->regs) { |
| 17558 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 17559 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 17560 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17561 | free_netdev(dev); |
| 17562 | pci_release_regions(pdev); |
| 17563 | pci_disable_device(pdev); |
| 17564 | pci_set_drvdata(pdev, NULL); |
| 17565 | } |
| 17566 | } |
| 17567 | |
Eric Dumazet | aa6027c | 2011-01-01 05:22:46 +0000 | [diff] [blame] | 17568 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 17569 | static int tg3_suspend(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17570 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 17571 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17572 | struct net_device *dev = pci_get_drvdata(pdev); |
| 17573 | struct tg3 *tp = netdev_priv(dev); |
| 17574 | int err; |
| 17575 | |
| 17576 | if (!netif_running(dev)) |
| 17577 | return 0; |
| 17578 | |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 17579 | tg3_reset_task_cancel(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 17580 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17581 | tg3_netif_stop(tp); |
| 17582 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 17583 | tg3_timer_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17584 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 17585 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17586 | tg3_disable_ints(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 17587 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17588 | |
| 17589 | netif_device_detach(dev); |
| 17590 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 17591 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 17592 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17593 | tg3_flag_clear(tp, INIT_COMPLETE); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 17594 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17595 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 17596 | err = tg3_power_down_prepare(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17597 | if (err) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 17598 | int err2; |
| 17599 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 17600 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17601 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17602 | tg3_flag_set(tp, INIT_COMPLETE); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 17603 | err2 = tg3_restart_hw(tp, true); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 17604 | if (err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 17605 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17606 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 17607 | tg3_timer_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17608 | |
| 17609 | netif_device_attach(dev); |
| 17610 | tg3_netif_start(tp); |
| 17611 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 17612 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 17613 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 17614 | |
| 17615 | if (!err2) |
| 17616 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17617 | } |
| 17618 | |
| 17619 | return err; |
| 17620 | } |
| 17621 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 17622 | static int tg3_resume(struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17623 | { |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 17624 | struct pci_dev *pdev = to_pci_dev(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17625 | struct net_device *dev = pci_get_drvdata(pdev); |
| 17626 | struct tg3 *tp = netdev_priv(dev); |
| 17627 | int err; |
| 17628 | |
| 17629 | if (!netif_running(dev)) |
| 17630 | return 0; |
| 17631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17632 | netif_device_attach(dev); |
| 17633 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 17634 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17635 | |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17636 | tg3_flag_set(tp, INIT_COMPLETE); |
Nithin Sujir | 942d1af | 2013-04-09 08:48:07 +0000 | [diff] [blame] | 17637 | err = tg3_restart_hw(tp, |
| 17638 | !(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN)); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 17639 | if (err) |
| 17640 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17641 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 17642 | tg3_timer_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17644 | tg3_netif_start(tp); |
| 17645 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 17646 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 17647 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17648 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 17649 | if (!err) |
| 17650 | tg3_phy_start(tp); |
| 17651 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 17652 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17653 | } |
Fabio Estevam | 42df36a | 2013-04-16 09:28:29 +0000 | [diff] [blame] | 17654 | #endif /* CONFIG_PM_SLEEP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17655 | |
Rafael J. Wysocki | c866b7e | 2010-12-25 12:56:23 +0000 | [diff] [blame] | 17656 | static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); |
| 17657 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17658 | /** |
| 17659 | * tg3_io_error_detected - called when PCI error is detected |
| 17660 | * @pdev: Pointer to PCI device |
| 17661 | * @state: The current pci connection state |
| 17662 | * |
| 17663 | * This function is called after a PCI bus error affecting |
| 17664 | * this device has been detected. |
| 17665 | */ |
| 17666 | static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, |
| 17667 | pci_channel_state_t state) |
| 17668 | { |
| 17669 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 17670 | struct tg3 *tp = netdev_priv(netdev); |
| 17671 | pci_ers_result_t err = PCI_ERS_RESULT_NEED_RESET; |
| 17672 | |
| 17673 | netdev_info(netdev, "PCI I/O error detected\n"); |
| 17674 | |
| 17675 | rtnl_lock(); |
| 17676 | |
| 17677 | if (!netif_running(netdev)) |
| 17678 | goto done; |
| 17679 | |
| 17680 | tg3_phy_stop(tp); |
| 17681 | |
| 17682 | tg3_netif_stop(tp); |
| 17683 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 17684 | tg3_timer_stop(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17685 | |
| 17686 | /* Want to make sure that the reset task doesn't run */ |
Matt Carlson | db21997 | 2011-11-04 09:15:03 +0000 | [diff] [blame] | 17687 | tg3_reset_task_cancel(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17688 | |
| 17689 | netif_device_detach(netdev); |
| 17690 | |
| 17691 | /* Clean up software state, even if MMIO is blocked */ |
| 17692 | tg3_full_lock(tp, 0); |
| 17693 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 17694 | tg3_full_unlock(tp); |
| 17695 | |
| 17696 | done: |
| 17697 | if (state == pci_channel_io_perm_failure) |
| 17698 | err = PCI_ERS_RESULT_DISCONNECT; |
| 17699 | else |
| 17700 | pci_disable_device(pdev); |
| 17701 | |
| 17702 | rtnl_unlock(); |
| 17703 | |
| 17704 | return err; |
| 17705 | } |
| 17706 | |
| 17707 | /** |
| 17708 | * tg3_io_slot_reset - called after the pci bus has been reset. |
| 17709 | * @pdev: Pointer to PCI device |
| 17710 | * |
| 17711 | * Restart the card from scratch, as if from a cold-boot. |
| 17712 | * At this point, the card has exprienced a hard reset, |
| 17713 | * followed by fixups by BIOS, and has its config space |
| 17714 | * set up identically to what it was at cold boot. |
| 17715 | */ |
| 17716 | static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev) |
| 17717 | { |
| 17718 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 17719 | struct tg3 *tp = netdev_priv(netdev); |
| 17720 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 17721 | int err; |
| 17722 | |
| 17723 | rtnl_lock(); |
| 17724 | |
| 17725 | if (pci_enable_device(pdev)) { |
| 17726 | netdev_err(netdev, "Cannot re-enable PCI device after reset.\n"); |
| 17727 | goto done; |
| 17728 | } |
| 17729 | |
| 17730 | pci_set_master(pdev); |
| 17731 | pci_restore_state(pdev); |
| 17732 | pci_save_state(pdev); |
| 17733 | |
| 17734 | if (!netif_running(netdev)) { |
| 17735 | rc = PCI_ERS_RESULT_RECOVERED; |
| 17736 | goto done; |
| 17737 | } |
| 17738 | |
| 17739 | err = tg3_power_up(tp); |
Matt Carlson | bed9829 | 2011-07-13 09:27:29 +0000 | [diff] [blame] | 17740 | if (err) |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17741 | goto done; |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17742 | |
| 17743 | rc = PCI_ERS_RESULT_RECOVERED; |
| 17744 | |
| 17745 | done: |
| 17746 | rtnl_unlock(); |
| 17747 | |
| 17748 | return rc; |
| 17749 | } |
| 17750 | |
| 17751 | /** |
| 17752 | * tg3_io_resume - called when traffic can start flowing again. |
| 17753 | * @pdev: Pointer to PCI device |
| 17754 | * |
| 17755 | * This callback is called when the error recovery driver tells |
| 17756 | * us that its OK to resume normal operation. |
| 17757 | */ |
| 17758 | static void tg3_io_resume(struct pci_dev *pdev) |
| 17759 | { |
| 17760 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 17761 | struct tg3 *tp = netdev_priv(netdev); |
| 17762 | int err; |
| 17763 | |
| 17764 | rtnl_lock(); |
| 17765 | |
| 17766 | if (!netif_running(netdev)) |
| 17767 | goto done; |
| 17768 | |
| 17769 | tg3_full_lock(tp, 0); |
Joe Perches | 63c3a66 | 2011-04-26 08:12:10 +0000 | [diff] [blame] | 17770 | tg3_flag_set(tp, INIT_COMPLETE); |
Joe Perches | 953c96e | 2013-04-09 10:18:14 +0000 | [diff] [blame] | 17771 | err = tg3_restart_hw(tp, true); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17772 | if (err) { |
Nithin Nayak Sujir | 3576306 | 2012-12-03 19:36:56 +0000 | [diff] [blame] | 17773 | tg3_full_unlock(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17774 | netdev_err(netdev, "Cannot restart hardware after reset.\n"); |
| 17775 | goto done; |
| 17776 | } |
| 17777 | |
| 17778 | netif_device_attach(netdev); |
| 17779 | |
Matt Carlson | 21f7638 | 2012-02-22 12:35:21 +0000 | [diff] [blame] | 17780 | tg3_timer_start(tp); |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17781 | |
| 17782 | tg3_netif_start(tp); |
| 17783 | |
Nithin Nayak Sujir | 3576306 | 2012-12-03 19:36:56 +0000 | [diff] [blame] | 17784 | tg3_full_unlock(tp); |
| 17785 | |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17786 | tg3_phy_start(tp); |
| 17787 | |
| 17788 | done: |
| 17789 | rtnl_unlock(); |
| 17790 | } |
| 17791 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 17792 | static const struct pci_error_handlers tg3_err_handler = { |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17793 | .error_detected = tg3_io_error_detected, |
| 17794 | .slot_reset = tg3_io_slot_reset, |
| 17795 | .resume = tg3_io_resume |
| 17796 | }; |
| 17797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17798 | static struct pci_driver tg3_driver = { |
| 17799 | .name = DRV_MODULE_NAME, |
| 17800 | .id_table = tg3_pci_tbl, |
| 17801 | .probe = tg3_init_one, |
Bill Pemberton | 229b1ad | 2012-12-03 09:22:59 -0500 | [diff] [blame] | 17802 | .remove = tg3_remove_one, |
Matt Carlson | b45aa2f | 2011-04-25 12:42:48 +0000 | [diff] [blame] | 17803 | .err_handler = &tg3_err_handler, |
Fabio Estevam | 42df36a | 2013-04-16 09:28:29 +0000 | [diff] [blame] | 17804 | .driver.pm = &tg3_pm_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17805 | }; |
| 17806 | |
Peter Hüwe | 8dbb0dc | 2013-05-21 12:58:06 +0000 | [diff] [blame^] | 17807 | module_pci_driver(tg3_driver); |