Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * tg3.c: Broadcom Tigon3 ethernet driver. |
| 3 | * |
| 4 | * Copyright (C) 2001, 2002, 2003, 2004 David S. Miller (davem@redhat.com) |
| 5 | * Copyright (C) 2001, 2002, 2003 Jeff Garzik (jgarzik@pobox.com) |
| 6 | * Copyright (C) 2004 Sun Microsystems Inc. |
Matt Carlson | ba5b0bf | 2010-01-12 10:11:40 +0000 | [diff] [blame] | 7 | * Copyright (C) 2005-2010 Broadcom Corporation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * Firmware is: |
Michael Chan | 49cabf4 | 2005-06-06 15:15:17 -0700 | [diff] [blame] | 10 | * Derived from proprietary unpublished source code, |
| 11 | * Copyright (C) 2000-2003 Broadcom Corporation. |
| 12 | * |
| 13 | * Permission is hereby granted for the distribution of this firmware |
| 14 | * data in hexadecimal or equivalent format, provided this copyright |
| 15 | * notice is accompanying it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/moduleparam.h> |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 21 | #include <linux/stringify.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/compiler.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/delay.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 27 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/init.h> |
| 29 | #include <linux/ioport.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/etherdevice.h> |
| 33 | #include <linux/skbuff.h> |
| 34 | #include <linux/ethtool.h> |
| 35 | #include <linux/mii.h> |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 36 | #include <linux/phy.h> |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 37 | #include <linux/brcmphy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/if_vlan.h> |
| 39 | #include <linux/ip.h> |
| 40 | #include <linux/tcp.h> |
| 41 | #include <linux/workqueue.h> |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 42 | #include <linux/prefetch.h> |
Tobias Klauser | f9a5f7d | 2005-10-29 15:09:26 +0200 | [diff] [blame] | 43 | #include <linux/dma-mapping.h> |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 44 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #include <net/checksum.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 47 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #include <asm/system.h> |
| 50 | #include <asm/io.h> |
| 51 | #include <asm/byteorder.h> |
| 52 | #include <asm/uaccess.h> |
| 53 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 54 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <asm/idprom.h> |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 56 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #endif |
| 58 | |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 59 | #define BAR_0 0 |
| 60 | #define BAR_2 2 |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
| 63 | #define TG3_VLAN_TAG_USED 1 |
| 64 | #else |
| 65 | #define TG3_VLAN_TAG_USED 0 |
| 66 | #endif |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include "tg3.h" |
| 69 | |
| 70 | #define DRV_MODULE_NAME "tg3" |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 71 | #define TG3_MAJ_NUM 3 |
Matt Carlson | 7c1a96a | 2010-10-14 10:37:45 +0000 | [diff] [blame] | 72 | #define TG3_MIN_NUM 115 |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 73 | #define DRV_MODULE_VERSION \ |
| 74 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) |
Matt Carlson | 7c1a96a | 2010-10-14 10:37:45 +0000 | [diff] [blame] | 75 | #define DRV_MODULE_RELDATE "October 14, 2010" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | #define TG3_DEF_MAC_MODE 0 |
| 78 | #define TG3_DEF_RX_MODE 0 |
| 79 | #define TG3_DEF_TX_MODE 0 |
| 80 | #define TG3_DEF_MSG_ENABLE \ |
| 81 | (NETIF_MSG_DRV | \ |
| 82 | NETIF_MSG_PROBE | \ |
| 83 | NETIF_MSG_LINK | \ |
| 84 | NETIF_MSG_TIMER | \ |
| 85 | NETIF_MSG_IFDOWN | \ |
| 86 | NETIF_MSG_IFUP | \ |
| 87 | NETIF_MSG_RX_ERR | \ |
| 88 | NETIF_MSG_TX_ERR) |
| 89 | |
| 90 | /* length of time before we decide the hardware is borked, |
| 91 | * and dev->tx_timeout() should be called to fix the problem |
| 92 | */ |
| 93 | #define TG3_TX_TIMEOUT (5 * HZ) |
| 94 | |
| 95 | /* hardware minimum and maximum for a single frame's data payload */ |
| 96 | #define TG3_MIN_MTU 60 |
| 97 | #define TG3_MAX_MTU(tp) \ |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 98 | ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) ? 9000 : 1500) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | /* These numbers seem to be hard coded in the NIC firmware somehow. |
| 101 | * You can't change the ring sizes, but you can change where you place |
| 102 | * them in the NIC onboard memory. |
| 103 | */ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 104 | #define TG3_RX_STD_RING_SIZE(tp) \ |
| 105 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || \ |
| 106 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) ? \ |
| 107 | RX_STD_MAX_SIZE_5717 : 512) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #define TG3_DEF_RX_RING_PENDING 200 |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 109 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
| 110 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || \ |
| 111 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) ? \ |
| 112 | 1024 : 256) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 114 | #define TG3_RSS_INDIR_TBL_SIZE 128 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | /* Do not place this n-ring entries value into the tp struct itself, |
| 117 | * we really want to expose these constants to GCC so that modulo et |
| 118 | * al. operations are done with shifts and masks instead of with |
| 119 | * hw multiply/modulo instructions. Another solution would be to |
| 120 | * replace things like '% foo' with '& (foo - 1)'. |
| 121 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | #define TG3_TX_RING_SIZE 512 |
| 124 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) |
| 125 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 126 | #define TG3_RX_STD_RING_BYTES(tp) \ |
| 127 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) |
| 128 | #define TG3_RX_JMB_RING_BYTES(tp) \ |
| 129 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) |
| 130 | #define TG3_RX_RCB_RING_BYTES(tp) \ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 131 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
| 133 | TG3_TX_RING_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
| 135 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 136 | #define TG3_RX_DMA_ALIGN 16 |
| 137 | #define TG3_RX_HEADROOM ALIGN(VLAN_HLEN, TG3_RX_DMA_ALIGN) |
| 138 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 139 | #define TG3_DMA_BYTE_ENAB 64 |
| 140 | |
| 141 | #define TG3_RX_STD_DMA_SZ 1536 |
| 142 | #define TG3_RX_JMB_DMA_SZ 9046 |
| 143 | |
| 144 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) |
| 145 | |
| 146 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) |
| 147 | #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] | 148 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 149 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
| 150 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 151 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 152 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
| 153 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 154 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 155 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
| 156 | * that are at least dword aligned when used in PCIX mode. The driver |
| 157 | * works around this bug by double copying the packet. This workaround |
| 158 | * is built into the normal double copy length check for efficiency. |
| 159 | * |
| 160 | * However, the double copy is only necessary on those architectures |
| 161 | * where unaligned memory accesses are inefficient. For those architectures |
| 162 | * where unaligned memory accesses incur little penalty, we can reintegrate |
| 163 | * the 5701 in the normal rx path. Doing so saves a device structure |
| 164 | * dereference by hardcoding the double copy threshold in place. |
| 165 | */ |
| 166 | #define TG3_RX_COPY_THRESHOLD 256 |
| 167 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 168 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD |
| 169 | #else |
| 170 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) |
| 171 | #endif |
| 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | /* minimum number of free TX descriptors required to wake up TX process */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 174 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 176 | #define TG3_RAW_IP_ALIGN 2 |
| 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /* number of ETHTOOL_GSTATS u64's */ |
| 179 | #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64)) |
| 180 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 181 | #define TG3_NUM_TEST 6 |
| 182 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 183 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
| 184 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 185 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
| 186 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
| 187 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" |
| 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | static char version[] __devinitdata = |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 190 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); |
| 193 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); |
| 194 | MODULE_LICENSE("GPL"); |
| 195 | MODULE_VERSION(DRV_MODULE_VERSION); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 196 | MODULE_FIRMWARE(FIRMWARE_TG3); |
| 197 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); |
| 198 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
| 201 | module_param(tg3_debug, int, 0); |
| 202 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); |
| 203 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 204 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 205 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
| 206 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, |
| 207 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, |
| 208 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, |
| 209 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, |
| 210 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, |
| 211 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, |
| 212 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, |
| 213 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, |
| 214 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, |
| 215 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, |
| 216 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, |
| 217 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, |
| 218 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, |
| 219 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, |
| 220 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, |
| 221 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, |
| 222 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, |
| 223 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)}, |
| 224 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)}, |
| 225 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, |
| 226 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 227 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 228 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 229 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 230 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
| 231 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)}, |
| 232 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
| 233 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, |
| 234 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, |
| 235 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, |
| 236 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)}, |
| 237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
| 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, |
| 239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, |
| 240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
| 243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, |
| 244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
| 247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, |
| 248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, |
| 249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, |
| 250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, |
| 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, |
| 252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
| 254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 255 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
| 256 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
Matt Carlson | 6c7af27 | 2007-10-21 16:12:02 -0700 | [diff] [blame] | 257 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 258 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
| 259 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
Matt Carlson | c88e668 | 2008-11-03 16:49:18 -0800 | [diff] [blame] | 260 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
| 261 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, |
Matt Carlson | 2befdce | 2009-08-28 12:28:45 +0000 | [diff] [blame] | 262 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
| 263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 264 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
| 265 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, |
| 266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790)}, |
Matt Carlson | 5e7ccf2 | 2009-08-25 10:08:42 +0000 | [diff] [blame] | 267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
| 269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
Matt Carlson | b0f7522 | 2010-01-20 16:58:11 +0000 | [diff] [blame] | 270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
| 271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, |
| 272 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, |
| 273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, |
| 274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791)}, |
| 275 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)}, |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 277 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
| 278 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, |
| 279 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, |
| 280 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, |
| 281 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, |
| 282 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, |
| 283 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, |
| 284 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); |
| 288 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 289 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | const char string[ETH_GSTRING_LEN]; |
| 291 | } ethtool_stats_keys[TG3_NUM_STATS] = { |
| 292 | { "rx_octets" }, |
| 293 | { "rx_fragments" }, |
| 294 | { "rx_ucast_packets" }, |
| 295 | { "rx_mcast_packets" }, |
| 296 | { "rx_bcast_packets" }, |
| 297 | { "rx_fcs_errors" }, |
| 298 | { "rx_align_errors" }, |
| 299 | { "rx_xon_pause_rcvd" }, |
| 300 | { "rx_xoff_pause_rcvd" }, |
| 301 | { "rx_mac_ctrl_rcvd" }, |
| 302 | { "rx_xoff_entered" }, |
| 303 | { "rx_frame_too_long_errors" }, |
| 304 | { "rx_jabbers" }, |
| 305 | { "rx_undersize_packets" }, |
| 306 | { "rx_in_length_errors" }, |
| 307 | { "rx_out_length_errors" }, |
| 308 | { "rx_64_or_less_octet_packets" }, |
| 309 | { "rx_65_to_127_octet_packets" }, |
| 310 | { "rx_128_to_255_octet_packets" }, |
| 311 | { "rx_256_to_511_octet_packets" }, |
| 312 | { "rx_512_to_1023_octet_packets" }, |
| 313 | { "rx_1024_to_1522_octet_packets" }, |
| 314 | { "rx_1523_to_2047_octet_packets" }, |
| 315 | { "rx_2048_to_4095_octet_packets" }, |
| 316 | { "rx_4096_to_8191_octet_packets" }, |
| 317 | { "rx_8192_to_9022_octet_packets" }, |
| 318 | |
| 319 | { "tx_octets" }, |
| 320 | { "tx_collisions" }, |
| 321 | |
| 322 | { "tx_xon_sent" }, |
| 323 | { "tx_xoff_sent" }, |
| 324 | { "tx_flow_control" }, |
| 325 | { "tx_mac_errors" }, |
| 326 | { "tx_single_collisions" }, |
| 327 | { "tx_mult_collisions" }, |
| 328 | { "tx_deferred" }, |
| 329 | { "tx_excessive_collisions" }, |
| 330 | { "tx_late_collisions" }, |
| 331 | { "tx_collide_2times" }, |
| 332 | { "tx_collide_3times" }, |
| 333 | { "tx_collide_4times" }, |
| 334 | { "tx_collide_5times" }, |
| 335 | { "tx_collide_6times" }, |
| 336 | { "tx_collide_7times" }, |
| 337 | { "tx_collide_8times" }, |
| 338 | { "tx_collide_9times" }, |
| 339 | { "tx_collide_10times" }, |
| 340 | { "tx_collide_11times" }, |
| 341 | { "tx_collide_12times" }, |
| 342 | { "tx_collide_13times" }, |
| 343 | { "tx_collide_14times" }, |
| 344 | { "tx_collide_15times" }, |
| 345 | { "tx_ucast_packets" }, |
| 346 | { "tx_mcast_packets" }, |
| 347 | { "tx_bcast_packets" }, |
| 348 | { "tx_carrier_sense_errors" }, |
| 349 | { "tx_discards" }, |
| 350 | { "tx_errors" }, |
| 351 | |
| 352 | { "dma_writeq_full" }, |
| 353 | { "dma_write_prioq_full" }, |
| 354 | { "rxbds_empty" }, |
| 355 | { "rx_discards" }, |
| 356 | { "rx_errors" }, |
| 357 | { "rx_threshold_hit" }, |
| 358 | |
| 359 | { "dma_readq_full" }, |
| 360 | { "dma_read_prioq_full" }, |
| 361 | { "tx_comp_queue_full" }, |
| 362 | |
| 363 | { "ring_set_send_prod_index" }, |
| 364 | { "ring_status_update" }, |
| 365 | { "nic_irqs" }, |
| 366 | { "nic_avoided_irqs" }, |
| 367 | { "nic_tx_threshold_hit" } |
| 368 | }; |
| 369 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 370 | static const struct { |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 371 | const char string[ETH_GSTRING_LEN]; |
| 372 | } ethtool_test_keys[TG3_NUM_TEST] = { |
| 373 | { "nvram test (online) " }, |
| 374 | { "link test (online) " }, |
| 375 | { "register test (offline)" }, |
| 376 | { "memory test (offline)" }, |
| 377 | { "loopback test (offline)" }, |
| 378 | { "interrupt test (offline)" }, |
| 379 | }; |
| 380 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 381 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
| 382 | { |
| 383 | writel(val, tp->regs + off); |
| 384 | } |
| 385 | |
| 386 | static u32 tg3_read32(struct tg3 *tp, u32 off) |
| 387 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 388 | return readl(tp->regs + off); |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 391 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
| 392 | { |
| 393 | writel(val, tp->aperegs + off); |
| 394 | } |
| 395 | |
| 396 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) |
| 397 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 398 | return readl(tp->aperegs + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
| 402 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 403 | unsigned long flags; |
| 404 | |
| 405 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 406 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 407 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 408 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) |
| 412 | { |
| 413 | writel(val, tp->regs + off); |
| 414 | readl(tp->regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 417 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
| 418 | { |
| 419 | unsigned long flags; |
| 420 | u32 val; |
| 421 | |
| 422 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 423 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 424 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 425 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 426 | return val; |
| 427 | } |
| 428 | |
| 429 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) |
| 430 | { |
| 431 | unsigned long flags; |
| 432 | |
| 433 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { |
| 434 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + |
| 435 | TG3_64BIT_REG_LOW, val); |
| 436 | return; |
| 437 | } |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 438 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 439 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
| 440 | TG3_64BIT_REG_LOW, val); |
| 441 | return; |
| 442 | } |
| 443 | |
| 444 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 445 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 446 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 447 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 448 | |
| 449 | /* In indirect mode when disabling interrupts, we also need |
| 450 | * to clear the interrupt bit in the GRC local ctrl register. |
| 451 | */ |
| 452 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && |
| 453 | (val == 0x1)) { |
| 454 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, |
| 455 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) |
| 460 | { |
| 461 | unsigned long flags; |
| 462 | u32 val; |
| 463 | |
| 464 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 465 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 466 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 467 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 468 | return val; |
| 469 | } |
| 470 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 471 | /* usec_wait specifies the wait time in usec when writing to certain registers |
| 472 | * where it is unsafe to read back the register without some delay. |
| 473 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. |
| 474 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. |
| 475 | */ |
| 476 | 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] | 477 | { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 478 | if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) || |
| 479 | (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND)) |
| 480 | /* Non-posted methods */ |
| 481 | tp->write32(tp, off, val); |
| 482 | else { |
| 483 | /* Posted method */ |
| 484 | tg3_write32(tp, off, val); |
| 485 | if (usec_wait) |
| 486 | udelay(usec_wait); |
| 487 | tp->read32(tp, off); |
| 488 | } |
| 489 | /* Wait again after the read for the posted method to guarantee that |
| 490 | * the wait time is met. |
| 491 | */ |
| 492 | if (usec_wait) |
| 493 | udelay(usec_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 496 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
| 497 | { |
| 498 | tp->write32_mbox(tp, off, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 499 | if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) && |
| 500 | !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND)) |
| 501 | tp->read32_mbox(tp, off); |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 504 | 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] | 505 | { |
| 506 | void __iomem *mbox = tp->regs + off; |
| 507 | writel(val, mbox); |
| 508 | if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) |
| 509 | writel(val, mbox); |
| 510 | if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) |
| 511 | readl(mbox); |
| 512 | } |
| 513 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 514 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
| 515 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 516 | return readl(tp->regs + off + GRCMBOX_BASE); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) |
| 520 | { |
| 521 | writel(val, tp->regs + off + GRCMBOX_BASE); |
| 522 | } |
| 523 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 524 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 525 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 526 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
| 527 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) |
| 528 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 529 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 530 | #define tw32(reg, val) tp->write32(tp, reg, val) |
| 531 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) |
| 532 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) |
| 533 | #define tr32(reg) tp->read32(tp, reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) |
| 536 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 537 | unsigned long flags; |
| 538 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 539 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
| 540 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
| 541 | return; |
| 542 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 543 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 544 | if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) { |
| 545 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 546 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 548 | /* Always leave this as zero. */ |
| 549 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 550 | } else { |
| 551 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 552 | tw32_f(TG3PCI_MEM_WIN_DATA, val); |
| 553 | |
| 554 | /* Always leave this as zero. */ |
| 555 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 556 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 557 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
| 561 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 562 | unsigned long flags; |
| 563 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 564 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
| 565 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
| 566 | *val = 0; |
| 567 | return; |
| 568 | } |
| 569 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 570 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 571 | if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) { |
| 572 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 573 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 575 | /* Always leave this as zero. */ |
| 576 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 577 | } else { |
| 578 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 579 | *val = tr32(TG3PCI_MEM_WIN_DATA); |
| 580 | |
| 581 | /* Always leave this as zero. */ |
| 582 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 583 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 584 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 587 | static void tg3_ape_lock_init(struct tg3 *tp) |
| 588 | { |
| 589 | int i; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 590 | u32 regbase; |
| 591 | |
| 592 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 593 | regbase = TG3_APE_LOCK_GRANT; |
| 594 | else |
| 595 | regbase = TG3_APE_PER_LOCK_GRANT; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 596 | |
| 597 | /* Make sure the driver hasn't any stale locks. */ |
| 598 | for (i = 0; i < 8; i++) |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 599 | tg3_ape_write32(tp, regbase + 4 * i, APE_LOCK_GRANT_DRIVER); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | static int tg3_ape_lock(struct tg3 *tp, int locknum) |
| 603 | { |
| 604 | int i, off; |
| 605 | int ret = 0; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 606 | u32 status, req, gnt; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 607 | |
| 608 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) |
| 609 | return 0; |
| 610 | |
| 611 | switch (locknum) { |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 612 | case TG3_APE_LOCK_GRC: |
| 613 | case TG3_APE_LOCK_MEM: |
| 614 | break; |
| 615 | default: |
| 616 | return -EINVAL; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 619 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
| 620 | req = TG3_APE_LOCK_REQ; |
| 621 | gnt = TG3_APE_LOCK_GRANT; |
| 622 | } else { |
| 623 | req = TG3_APE_PER_LOCK_REQ; |
| 624 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 625 | } |
| 626 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 627 | off = 4 * locknum; |
| 628 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 629 | tg3_ape_write32(tp, req + off, APE_LOCK_REQ_DRIVER); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 630 | |
| 631 | /* Wait for up to 1 millisecond to acquire lock. */ |
| 632 | for (i = 0; i < 100; i++) { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 633 | status = tg3_ape_read32(tp, gnt + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 634 | if (status == APE_LOCK_GRANT_DRIVER) |
| 635 | break; |
| 636 | udelay(10); |
| 637 | } |
| 638 | |
| 639 | if (status != APE_LOCK_GRANT_DRIVER) { |
| 640 | /* Revoke the lock request. */ |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 641 | tg3_ape_write32(tp, gnt + off, |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 642 | APE_LOCK_GRANT_DRIVER); |
| 643 | |
| 644 | ret = -EBUSY; |
| 645 | } |
| 646 | |
| 647 | return ret; |
| 648 | } |
| 649 | |
| 650 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) |
| 651 | { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 652 | u32 gnt; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 653 | |
| 654 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) |
| 655 | return; |
| 656 | |
| 657 | switch (locknum) { |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 658 | case TG3_APE_LOCK_GRC: |
| 659 | case TG3_APE_LOCK_MEM: |
| 660 | break; |
| 661 | default: |
| 662 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 665 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 666 | gnt = TG3_APE_LOCK_GRANT; |
| 667 | else |
| 668 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 669 | |
| 670 | tg3_ape_write32(tp, gnt + 4 * locknum, APE_LOCK_GRANT_DRIVER); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | static void tg3_disable_ints(struct tg3 *tp) |
| 674 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 675 | int i; |
| 676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 678 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 679 | for (i = 0; i < tp->irq_max; i++) |
| 680 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | static void tg3_enable_ints(struct tg3 *tp) |
| 684 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 685 | int i; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 686 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 687 | tp->irq_sync = 0; |
| 688 | wmb(); |
| 689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 691 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 692 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 693 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 694 | for (i = 0; i < tp->irq_cnt; i++) { |
| 695 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 696 | |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 697 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 698 | if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) |
| 699 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 700 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 701 | tp->coal_now |= tnapi->coal_now; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 702 | } |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 703 | |
| 704 | /* Force an initial interrupt */ |
| 705 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) && |
| 706 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
| 707 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 708 | else |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 709 | tw32(HOSTCC_MODE, tp->coal_now); |
| 710 | |
| 711 | 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] | 712 | } |
| 713 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 714 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 715 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 716 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 717 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 718 | unsigned int work_exists = 0; |
| 719 | |
| 720 | /* check for phy events */ |
| 721 | if (!(tp->tg3_flags & |
| 722 | (TG3_FLAG_USE_LINKCHG_REG | |
| 723 | TG3_FLAG_POLL_SERDES))) { |
| 724 | if (sblk->status & SD_STATUS_LINK_CHG) |
| 725 | work_exists = 1; |
| 726 | } |
| 727 | /* check for RX/TX work to do */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 728 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons || |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 729 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 730 | work_exists = 1; |
| 731 | |
| 732 | return work_exists; |
| 733 | } |
| 734 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 735 | /* tg3_int_reenable |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 736 | * similar to tg3_enable_ints, but it accurately determines whether there |
| 737 | * is new work pending and can return without flushing the PIO write |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 738 | * which reenables interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 740 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 742 | struct tg3 *tp = tnapi->tp; |
| 743 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 744 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | mmiowb(); |
| 746 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 747 | /* When doing tagged status, this work check is unnecessary. |
| 748 | * The last_tag we write above tells the chip which piece of |
| 749 | * work we've completed. |
| 750 | */ |
| 751 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) && |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 752 | tg3_has_work(tnapi)) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 753 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 754 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | static void tg3_switch_clocks(struct tg3 *tp) |
| 758 | { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 759 | u32 clock_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | u32 orig_clock_ctrl; |
| 761 | |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 762 | if ((tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) || |
| 763 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 764 | return; |
| 765 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 766 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
| 767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | orig_clock_ctrl = clock_ctrl; |
| 769 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | |
| 770 | CLOCK_CTRL_CLKRUN_OENABLE | |
| 771 | 0x1f); |
| 772 | tp->pci_clock_ctrl = clock_ctrl; |
| 773 | |
| 774 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 775 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 776 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 777 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | } |
| 779 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 780 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 781 | clock_ctrl | |
| 782 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), |
| 783 | 40); |
| 784 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 785 | clock_ctrl | (CLOCK_CTRL_ALTCLK), |
| 786 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 788 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | #define PHY_BUSY_LOOPS 5000 |
| 792 | |
| 793 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
| 794 | { |
| 795 | u32 frame_val; |
| 796 | unsigned int loops; |
| 797 | int ret; |
| 798 | |
| 799 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 800 | tw32_f(MAC_MI_MODE, |
| 801 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 802 | udelay(80); |
| 803 | } |
| 804 | |
| 805 | *val = 0x0; |
| 806 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 807 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | MI_COM_PHY_ADDR_MASK); |
| 809 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 810 | MI_COM_REG_ADDR_MASK); |
| 811 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | tw32_f(MAC_MI_COM, frame_val); |
| 814 | |
| 815 | loops = PHY_BUSY_LOOPS; |
| 816 | while (loops != 0) { |
| 817 | udelay(10); |
| 818 | frame_val = tr32(MAC_MI_COM); |
| 819 | |
| 820 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 821 | udelay(5); |
| 822 | frame_val = tr32(MAC_MI_COM); |
| 823 | break; |
| 824 | } |
| 825 | loops -= 1; |
| 826 | } |
| 827 | |
| 828 | ret = -EBUSY; |
| 829 | if (loops != 0) { |
| 830 | *val = frame_val & MI_COM_DATA_MASK; |
| 831 | ret = 0; |
| 832 | } |
| 833 | |
| 834 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 835 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 836 | udelay(80); |
| 837 | } |
| 838 | |
| 839 | return ret; |
| 840 | } |
| 841 | |
| 842 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
| 843 | { |
| 844 | u32 frame_val; |
| 845 | unsigned int loops; |
| 846 | int ret; |
| 847 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 848 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 849 | (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL)) |
| 850 | return 0; |
| 851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 853 | tw32_f(MAC_MI_MODE, |
| 854 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 855 | udelay(80); |
| 856 | } |
| 857 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 858 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | MI_COM_PHY_ADDR_MASK); |
| 860 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 861 | MI_COM_REG_ADDR_MASK); |
| 862 | frame_val |= (val & MI_COM_DATA_MASK); |
| 863 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | tw32_f(MAC_MI_COM, frame_val); |
| 866 | |
| 867 | loops = PHY_BUSY_LOOPS; |
| 868 | while (loops != 0) { |
| 869 | udelay(10); |
| 870 | frame_val = tr32(MAC_MI_COM); |
| 871 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 872 | udelay(5); |
| 873 | frame_val = tr32(MAC_MI_COM); |
| 874 | break; |
| 875 | } |
| 876 | loops -= 1; |
| 877 | } |
| 878 | |
| 879 | ret = -EBUSY; |
| 880 | if (loops != 0) |
| 881 | ret = 0; |
| 882 | |
| 883 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 884 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 885 | udelay(80); |
| 886 | } |
| 887 | |
| 888 | return ret; |
| 889 | } |
| 890 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 891 | static int tg3_bmcr_reset(struct tg3 *tp) |
| 892 | { |
| 893 | u32 phy_control; |
| 894 | int limit, err; |
| 895 | |
| 896 | /* OK, reset it, and poll the BMCR_RESET bit until it |
| 897 | * clears or we time out. |
| 898 | */ |
| 899 | phy_control = BMCR_RESET; |
| 900 | err = tg3_writephy(tp, MII_BMCR, phy_control); |
| 901 | if (err != 0) |
| 902 | return -EBUSY; |
| 903 | |
| 904 | limit = 5000; |
| 905 | while (limit--) { |
| 906 | err = tg3_readphy(tp, MII_BMCR, &phy_control); |
| 907 | if (err != 0) |
| 908 | return -EBUSY; |
| 909 | |
| 910 | if ((phy_control & BMCR_RESET) == 0) { |
| 911 | udelay(40); |
| 912 | break; |
| 913 | } |
| 914 | udelay(10); |
| 915 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 916 | if (limit < 0) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 917 | return -EBUSY; |
| 918 | |
| 919 | return 0; |
| 920 | } |
| 921 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 922 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
| 923 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 924 | struct tg3 *tp = bp->priv; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 925 | u32 val; |
| 926 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 927 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 928 | |
| 929 | if (tg3_readphy(tp, reg, &val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 930 | val = -EIO; |
| 931 | |
| 932 | spin_unlock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 933 | |
| 934 | return val; |
| 935 | } |
| 936 | |
| 937 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) |
| 938 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 939 | struct tg3 *tp = bp->priv; |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 940 | u32 ret = 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 941 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 942 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 943 | |
| 944 | if (tg3_writephy(tp, reg, val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 945 | ret = -EIO; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 946 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 947 | spin_unlock_bh(&tp->lock); |
| 948 | |
| 949 | return ret; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static int tg3_mdio_reset(struct mii_bus *bp) |
| 953 | { |
| 954 | return 0; |
| 955 | } |
| 956 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 957 | static void tg3_mdio_config_5785(struct tg3 *tp) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 958 | { |
| 959 | u32 val; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 960 | struct phy_device *phydev; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 961 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 962 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 963 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 964 | case PHY_ID_BCM50610: |
| 965 | case PHY_ID_BCM50610M: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 966 | val = MAC_PHYCFG2_50610_LED_MODES; |
| 967 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 968 | case PHY_ID_BCMAC131: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 969 | val = MAC_PHYCFG2_AC131_LED_MODES; |
| 970 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 971 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 972 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
| 973 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 974 | case PHY_ID_RTL8201E: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 975 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
| 976 | break; |
| 977 | default: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 978 | return; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { |
| 982 | tw32(MAC_PHYCFG2, val); |
| 983 | |
| 984 | val = tr32(MAC_PHYCFG1); |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 985 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
| 986 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); |
| 987 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 988 | tw32(MAC_PHYCFG1, val); |
| 989 | |
| 990 | return; |
| 991 | } |
| 992 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 993 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 994 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
| 995 | MAC_PHYCFG2_FMODE_MASK_MASK | |
| 996 | MAC_PHYCFG2_GMODE_MASK_MASK | |
| 997 | MAC_PHYCFG2_ACT_MASK_MASK | |
| 998 | MAC_PHYCFG2_QUAL_MASK_MASK | |
| 999 | MAC_PHYCFG2_INBAND_ENABLE; |
| 1000 | |
| 1001 | tw32(MAC_PHYCFG2, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1002 | |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1003 | val = tr32(MAC_PHYCFG1); |
| 1004 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | |
| 1005 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 1006 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) { |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1007 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
| 1008 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
| 1009 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) |
| 1010 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
| 1011 | } |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1012 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
| 1013 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; |
| 1014 | tw32(MAC_PHYCFG1, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1015 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1016 | val = tr32(MAC_EXT_RGMII_MODE); |
| 1017 | val &= ~(MAC_RGMII_MODE_RX_INT_B | |
| 1018 | MAC_RGMII_MODE_RX_QUALITY | |
| 1019 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1020 | MAC_RGMII_MODE_RX_ENG_DET | |
| 1021 | MAC_RGMII_MODE_TX_ENABLE | |
| 1022 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1023 | MAC_RGMII_MODE_TX_RESET); |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 1024 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) { |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1025 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
| 1026 | val |= MAC_RGMII_MODE_RX_INT_B | |
| 1027 | MAC_RGMII_MODE_RX_QUALITY | |
| 1028 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1029 | MAC_RGMII_MODE_RX_ENG_DET; |
| 1030 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) |
| 1031 | val |= MAC_RGMII_MODE_TX_ENABLE | |
| 1032 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1033 | MAC_RGMII_MODE_TX_RESET; |
| 1034 | } |
| 1035 | tw32(MAC_EXT_RGMII_MODE, val); |
| 1036 | } |
| 1037 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1038 | static void tg3_mdio_start(struct tg3 *tp) |
| 1039 | { |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1040 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
| 1041 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1042 | udelay(80); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1043 | |
Matt Carlson | 9ea4818 | 2010-02-17 15:17:01 +0000 | [diff] [blame] | 1044 | if ((tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) && |
| 1045 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1046 | tg3_mdio_config_5785(tp); |
| 1047 | } |
| 1048 | |
| 1049 | static int tg3_mdio_init(struct tg3 *tp) |
| 1050 | { |
| 1051 | int i; |
| 1052 | u32 reg; |
| 1053 | struct phy_device *phydev; |
| 1054 | |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 1055 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 1056 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1057 | u32 is_serdes; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1058 | |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1059 | tp->phy_addr = PCI_FUNC(tp->pdev->devfn) + 1; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1060 | |
Matt Carlson | d1ec96a | 2010-01-12 10:11:38 +0000 | [diff] [blame] | 1061 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
| 1062 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
| 1063 | else |
| 1064 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & |
| 1065 | TG3_CPMU_PHY_STRAP_IS_SERDES; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1066 | if (is_serdes) |
| 1067 | tp->phy_addr += 7; |
| 1068 | } else |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1069 | tp->phy_addr = TG3_PHY_MII_ADDR; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1070 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1071 | tg3_mdio_start(tp); |
| 1072 | |
| 1073 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) || |
| 1074 | (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED)) |
| 1075 | return 0; |
| 1076 | |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1077 | tp->mdio_bus = mdiobus_alloc(); |
| 1078 | if (tp->mdio_bus == NULL) |
| 1079 | return -ENOMEM; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1080 | |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1081 | tp->mdio_bus->name = "tg3 mdio bus"; |
| 1082 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1083 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1084 | tp->mdio_bus->priv = tp; |
| 1085 | tp->mdio_bus->parent = &tp->pdev->dev; |
| 1086 | tp->mdio_bus->read = &tg3_mdio_read; |
| 1087 | tp->mdio_bus->write = &tg3_mdio_write; |
| 1088 | tp->mdio_bus->reset = &tg3_mdio_reset; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1089 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1090 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1091 | |
| 1092 | for (i = 0; i < PHY_MAX_ADDR; i++) |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1093 | tp->mdio_bus->irq[i] = PHY_POLL; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1094 | |
| 1095 | /* The bus registration will look for all the PHYs on the mdio bus. |
| 1096 | * Unfortunately, it does not ensure the PHY is powered up before |
| 1097 | * accessing the PHY ID registers. A chip reset is the |
| 1098 | * quickest way to bring the device back to an operational state.. |
| 1099 | */ |
| 1100 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
| 1101 | tg3_bmcr_reset(tp); |
| 1102 | |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1103 | i = mdiobus_register(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1104 | if (i) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1105 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1106 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1107 | return i; |
| 1108 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1109 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1110 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1111 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1112 | if (!phydev || !phydev->drv) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1113 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1114 | mdiobus_unregister(tp->mdio_bus); |
| 1115 | mdiobus_free(tp->mdio_bus); |
| 1116 | return -ENODEV; |
| 1117 | } |
| 1118 | |
| 1119 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1120 | case PHY_ID_BCM57780: |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1121 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1122 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1123 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1124 | case PHY_ID_BCM50610: |
| 1125 | case PHY_ID_BCM50610M: |
Matt Carlson | 32e5a8d | 2009-11-02 14:31:39 +0000 | [diff] [blame] | 1126 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1127 | PHY_BRCM_RX_REFCLK_UNUSED | |
Matt Carlson | 52fae08 | 2009-11-02 14:32:38 +0000 | [diff] [blame] | 1128 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1129 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 1130 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1131 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
| 1132 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
| 1133 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
| 1134 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) |
| 1135 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1136 | /* fallthru */ |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1137 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1138 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1139 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1140 | case PHY_ID_RTL8201E: |
| 1141 | case PHY_ID_BCMAC131: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1142 | phydev->interface = PHY_INTERFACE_MODE_MII; |
Matt Carlson | cdd4e09d | 2009-11-02 14:31:11 +0000 | [diff] [blame] | 1143 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1144 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1145 | break; |
| 1146 | } |
| 1147 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1148 | tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_INITED; |
| 1149 | |
| 1150 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1151 | tg3_mdio_config_5785(tp); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1152 | |
| 1153 | return 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | static void tg3_mdio_fini(struct tg3 *tp) |
| 1157 | { |
| 1158 | if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { |
| 1159 | tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_INITED; |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1160 | mdiobus_unregister(tp->mdio_bus); |
| 1161 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | |
Matt Carlson | ddfc87b | 2010-10-14 10:37:40 +0000 | [diff] [blame] | 1165 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
| 1166 | { |
| 1167 | int err; |
| 1168 | |
| 1169 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1170 | if (err) |
| 1171 | goto done; |
| 1172 | |
| 1173 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1174 | if (err) |
| 1175 | goto done; |
| 1176 | |
| 1177 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1178 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1179 | if (err) |
| 1180 | goto done; |
| 1181 | |
| 1182 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1183 | |
| 1184 | done: |
| 1185 | return err; |
| 1186 | } |
| 1187 | |
| 1188 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) |
| 1189 | { |
| 1190 | int err; |
| 1191 | |
| 1192 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1193 | if (err) |
| 1194 | goto done; |
| 1195 | |
| 1196 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1197 | if (err) |
| 1198 | goto done; |
| 1199 | |
| 1200 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1201 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1202 | if (err) |
| 1203 | goto done; |
| 1204 | |
| 1205 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1206 | |
| 1207 | done: |
| 1208 | return err; |
| 1209 | } |
| 1210 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1211 | /* tp->lock is held. */ |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1212 | static inline void tg3_generate_fw_event(struct tg3 *tp) |
| 1213 | { |
| 1214 | u32 val; |
| 1215 | |
| 1216 | val = tr32(GRC_RX_CPU_EVENT); |
| 1217 | val |= GRC_RX_CPU_DRIVER_EVENT; |
| 1218 | tw32_f(GRC_RX_CPU_EVENT, val); |
| 1219 | |
| 1220 | tp->last_event_jiffies = jiffies; |
| 1221 | } |
| 1222 | |
| 1223 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 |
| 1224 | |
| 1225 | /* tp->lock is held. */ |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1226 | static void tg3_wait_for_event_ack(struct tg3 *tp) |
| 1227 | { |
| 1228 | int i; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1229 | unsigned int delay_cnt; |
| 1230 | long time_remain; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1231 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1232 | /* If enough time has passed, no wait is necessary. */ |
| 1233 | time_remain = (long)(tp->last_event_jiffies + 1 + |
| 1234 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - |
| 1235 | (long)jiffies; |
| 1236 | if (time_remain < 0) |
| 1237 | return; |
| 1238 | |
| 1239 | /* Check if we can shorten the wait time. */ |
| 1240 | delay_cnt = jiffies_to_usecs(time_remain); |
| 1241 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) |
| 1242 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; |
| 1243 | delay_cnt = (delay_cnt >> 3) + 1; |
| 1244 | |
| 1245 | for (i = 0; i < delay_cnt; i++) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1246 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
| 1247 | break; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1248 | udelay(8); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | /* tp->lock is held. */ |
| 1253 | static void tg3_ump_link_report(struct tg3 *tp) |
| 1254 | { |
| 1255 | u32 reg; |
| 1256 | u32 val; |
| 1257 | |
| 1258 | if (!(tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
| 1259 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 1260 | return; |
| 1261 | |
| 1262 | tg3_wait_for_event_ack(tp); |
| 1263 | |
| 1264 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); |
| 1265 | |
| 1266 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); |
| 1267 | |
| 1268 | val = 0; |
| 1269 | if (!tg3_readphy(tp, MII_BMCR, ®)) |
| 1270 | val = reg << 16; |
| 1271 | if (!tg3_readphy(tp, MII_BMSR, ®)) |
| 1272 | val |= (reg & 0xffff); |
| 1273 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, val); |
| 1274 | |
| 1275 | val = 0; |
| 1276 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) |
| 1277 | val = reg << 16; |
| 1278 | if (!tg3_readphy(tp, MII_LPA, ®)) |
| 1279 | val |= (reg & 0xffff); |
| 1280 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 4, val); |
| 1281 | |
| 1282 | val = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1283 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1284 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
| 1285 | val = reg << 16; |
| 1286 | if (!tg3_readphy(tp, MII_STAT1000, ®)) |
| 1287 | val |= (reg & 0xffff); |
| 1288 | } |
| 1289 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 8, val); |
| 1290 | |
| 1291 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) |
| 1292 | val = reg << 16; |
| 1293 | else |
| 1294 | val = 0; |
| 1295 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val); |
| 1296 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1297 | tg3_generate_fw_event(tp); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | static void tg3_link_report(struct tg3 *tp) |
| 1301 | { |
| 1302 | if (!netif_carrier_ok(tp->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1303 | netif_info(tp, link, tp->dev, "Link is down\n"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1304 | tg3_ump_link_report(tp); |
| 1305 | } else if (netif_msg_link(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1306 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
| 1307 | (tp->link_config.active_speed == SPEED_1000 ? |
| 1308 | 1000 : |
| 1309 | (tp->link_config.active_speed == SPEED_100 ? |
| 1310 | 100 : 10)), |
| 1311 | (tp->link_config.active_duplex == DUPLEX_FULL ? |
| 1312 | "full" : "half")); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1313 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1314 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", |
| 1315 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? |
| 1316 | "on" : "off", |
| 1317 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? |
| 1318 | "on" : "off"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1319 | tg3_ump_link_report(tp); |
| 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl) |
| 1324 | { |
| 1325 | u16 miireg; |
| 1326 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1327 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1328 | miireg = ADVERTISE_PAUSE_CAP; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1329 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1330 | miireg = ADVERTISE_PAUSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1331 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1332 | miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1333 | else |
| 1334 | miireg = 0; |
| 1335 | |
| 1336 | return miireg; |
| 1337 | } |
| 1338 | |
| 1339 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
| 1340 | { |
| 1341 | u16 miireg; |
| 1342 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1343 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1344 | miireg = ADVERTISE_1000XPAUSE; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1345 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1346 | miireg = ADVERTISE_1000XPSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1347 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1348 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
| 1349 | else |
| 1350 | miireg = 0; |
| 1351 | |
| 1352 | return miireg; |
| 1353 | } |
| 1354 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1355 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
| 1356 | { |
| 1357 | u8 cap = 0; |
| 1358 | |
| 1359 | if (lcladv & ADVERTISE_1000XPAUSE) { |
| 1360 | if (lcladv & ADVERTISE_1000XPSE_ASYM) { |
| 1361 | if (rmtadv & LPA_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1362 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1363 | else if (rmtadv & LPA_1000XPAUSE_ASYM) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1364 | cap = FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1365 | } else { |
| 1366 | if (rmtadv & LPA_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1367 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1368 | } |
| 1369 | } else if (lcladv & ADVERTISE_1000XPSE_ASYM) { |
| 1370 | if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM)) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1371 | cap = FLOW_CTRL_TX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | return cap; |
| 1375 | } |
| 1376 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1377 | 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] | 1378 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1379 | u8 autoneg; |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1380 | u8 flowctrl = 0; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1381 | u32 old_rx_mode = tp->rx_mode; |
| 1382 | u32 old_tx_mode = tp->tx_mode; |
| 1383 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1384 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1385 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1386 | else |
| 1387 | autoneg = tp->link_config.autoneg; |
| 1388 | |
| 1389 | if (autoneg == AUTONEG_ENABLE && |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1390 | (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1391 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1392 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1393 | else |
Steve Glendinning | bc02ff9 | 2008-12-16 02:00:48 -0800 | [diff] [blame] | 1394 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1395 | } else |
| 1396 | flowctrl = tp->link_config.flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1397 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1398 | tp->link_config.active_flowctrl = flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1399 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1400 | if (flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1401 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
| 1402 | else |
| 1403 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; |
| 1404 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1405 | if (old_rx_mode != tp->rx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1406 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1407 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1408 | if (flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1409 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
| 1410 | else |
| 1411 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; |
| 1412 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1413 | if (old_tx_mode != tp->tx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1414 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1417 | static void tg3_adjust_link(struct net_device *dev) |
| 1418 | { |
| 1419 | u8 oldflowctrl, linkmesg = 0; |
| 1420 | u32 mac_mode, lcl_adv, rmt_adv; |
| 1421 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1422 | 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] | 1423 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1424 | spin_lock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1425 | |
| 1426 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | |
| 1427 | MAC_MODE_HALF_DUPLEX); |
| 1428 | |
| 1429 | oldflowctrl = tp->link_config.active_flowctrl; |
| 1430 | |
| 1431 | if (phydev->link) { |
| 1432 | lcl_adv = 0; |
| 1433 | rmt_adv = 0; |
| 1434 | |
| 1435 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) |
| 1436 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1437 | else if (phydev->speed == SPEED_1000 || |
| 1438 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1439 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1440 | else |
| 1441 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1442 | |
| 1443 | if (phydev->duplex == DUPLEX_HALF) |
| 1444 | mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 1445 | else { |
| 1446 | lcl_adv = tg3_advert_flowctrl_1000T( |
| 1447 | tp->link_config.flowctrl); |
| 1448 | |
| 1449 | if (phydev->pause) |
| 1450 | rmt_adv = LPA_PAUSE_CAP; |
| 1451 | if (phydev->asym_pause) |
| 1452 | rmt_adv |= LPA_PAUSE_ASYM; |
| 1453 | } |
| 1454 | |
| 1455 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 1456 | } else |
| 1457 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 1458 | |
| 1459 | if (mac_mode != tp->mac_mode) { |
| 1460 | tp->mac_mode = mac_mode; |
| 1461 | tw32_f(MAC_MODE, tp->mac_mode); |
| 1462 | udelay(40); |
| 1463 | } |
| 1464 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1465 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
| 1466 | if (phydev->speed == SPEED_10) |
| 1467 | tw32(MAC_MI_STAT, |
| 1468 | MAC_MI_STAT_10MBPS_MODE | |
| 1469 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1470 | else |
| 1471 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1472 | } |
| 1473 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1474 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
| 1475 | tw32(MAC_TX_LENGTHS, |
| 1476 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1477 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1478 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1479 | else |
| 1480 | tw32(MAC_TX_LENGTHS, |
| 1481 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1482 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1483 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1484 | |
| 1485 | if ((phydev->link && tp->link_config.active_speed == SPEED_INVALID) || |
| 1486 | (!phydev->link && tp->link_config.active_speed != SPEED_INVALID) || |
| 1487 | phydev->speed != tp->link_config.active_speed || |
| 1488 | phydev->duplex != tp->link_config.active_duplex || |
| 1489 | oldflowctrl != tp->link_config.active_flowctrl) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 1490 | linkmesg = 1; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1491 | |
| 1492 | tp->link_config.active_speed = phydev->speed; |
| 1493 | tp->link_config.active_duplex = phydev->duplex; |
| 1494 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1495 | spin_unlock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1496 | |
| 1497 | if (linkmesg) |
| 1498 | tg3_link_report(tp); |
| 1499 | } |
| 1500 | |
| 1501 | static int tg3_phy_init(struct tg3 *tp) |
| 1502 | { |
| 1503 | struct phy_device *phydev; |
| 1504 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1505 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1506 | return 0; |
| 1507 | |
| 1508 | /* Bring the PHY back to a known state. */ |
| 1509 | tg3_bmcr_reset(tp); |
| 1510 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1511 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1512 | |
| 1513 | /* Attach the MAC to the PHY. */ |
Kay Sievers | fb28ad3 | 2008-11-10 13:55:14 -0800 | [diff] [blame] | 1514 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link, |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1515 | phydev->dev_flags, phydev->interface); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1516 | if (IS_ERR(phydev)) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1517 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1518 | return PTR_ERR(phydev); |
| 1519 | } |
| 1520 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1521 | /* Mask with MAC supported features. */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1522 | switch (phydev->interface) { |
| 1523 | case PHY_INTERFACE_MODE_GMII: |
| 1524 | case PHY_INTERFACE_MODE_RGMII: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1525 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1526 | phydev->supported &= (PHY_GBIT_FEATURES | |
| 1527 | SUPPORTED_Pause | |
| 1528 | SUPPORTED_Asym_Pause); |
| 1529 | break; |
| 1530 | } |
| 1531 | /* fallthru */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1532 | case PHY_INTERFACE_MODE_MII: |
| 1533 | phydev->supported &= (PHY_BASIC_FEATURES | |
| 1534 | SUPPORTED_Pause | |
| 1535 | SUPPORTED_Asym_Pause); |
| 1536 | break; |
| 1537 | default: |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1538 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1539 | return -EINVAL; |
| 1540 | } |
| 1541 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1542 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1543 | |
| 1544 | phydev->advertising = phydev->supported; |
| 1545 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1546 | return 0; |
| 1547 | } |
| 1548 | |
| 1549 | static void tg3_phy_start(struct tg3 *tp) |
| 1550 | { |
| 1551 | struct phy_device *phydev; |
| 1552 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1553 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1554 | return; |
| 1555 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1556 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1557 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 1558 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 1559 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1560 | phydev->speed = tp->link_config.orig_speed; |
| 1561 | phydev->duplex = tp->link_config.orig_duplex; |
| 1562 | phydev->autoneg = tp->link_config.orig_autoneg; |
| 1563 | phydev->advertising = tp->link_config.orig_advertising; |
| 1564 | } |
| 1565 | |
| 1566 | phy_start(phydev); |
| 1567 | |
| 1568 | phy_start_aneg(phydev); |
| 1569 | } |
| 1570 | |
| 1571 | static void tg3_phy_stop(struct tg3 *tp) |
| 1572 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1573 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1574 | return; |
| 1575 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1576 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | static void tg3_phy_fini(struct tg3 *tp) |
| 1580 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1581 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1582 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1583 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1584 | } |
| 1585 | } |
| 1586 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 1587 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) |
| 1588 | { |
| 1589 | int err; |
| 1590 | |
| 1591 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1592 | if (!err) |
| 1593 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1594 | |
| 1595 | return err; |
| 1596 | } |
| 1597 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 1598 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1599 | { |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 1600 | int err; |
| 1601 | |
| 1602 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1603 | if (!err) |
| 1604 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1605 | |
| 1606 | return err; |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1609 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
| 1610 | { |
| 1611 | u32 phytest; |
| 1612 | |
| 1613 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 1614 | u32 phy; |
| 1615 | |
| 1616 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 1617 | phytest | MII_TG3_FET_SHADOW_EN); |
| 1618 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { |
| 1619 | if (enable) |
| 1620 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1621 | else |
| 1622 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1623 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); |
| 1624 | } |
| 1625 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 1626 | } |
| 1627 | } |
| 1628 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1629 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
| 1630 | { |
| 1631 | u32 reg; |
| 1632 | |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 1633 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 1634 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 1635 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1636 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1637 | return; |
| 1638 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1639 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1640 | tg3_phy_fet_toggle_apd(tp, enable); |
| 1641 | return; |
| 1642 | } |
| 1643 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1644 | reg = MII_TG3_MISC_SHDW_WREN | |
| 1645 | MII_TG3_MISC_SHDW_SCR5_SEL | |
| 1646 | MII_TG3_MISC_SHDW_SCR5_LPED | |
| 1647 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | |
| 1648 | MII_TG3_MISC_SHDW_SCR5_SDTL | |
| 1649 | MII_TG3_MISC_SHDW_SCR5_C125OE; |
| 1650 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) |
| 1651 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
| 1652 | |
| 1653 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 1654 | |
| 1655 | |
| 1656 | reg = MII_TG3_MISC_SHDW_WREN | |
| 1657 | MII_TG3_MISC_SHDW_APD_SEL | |
| 1658 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; |
| 1659 | if (enable) |
| 1660 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; |
| 1661 | |
| 1662 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 1663 | } |
| 1664 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1665 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
| 1666 | { |
| 1667 | u32 phy; |
| 1668 | |
| 1669 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1670 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1671 | return; |
| 1672 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1673 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1674 | u32 ephy; |
| 1675 | |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1676 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
| 1677 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; |
| 1678 | |
| 1679 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 1680 | ephy | MII_TG3_FET_SHADOW_EN); |
| 1681 | if (!tg3_readphy(tp, reg, &phy)) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1682 | if (enable) |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1683 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1684 | else |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1685 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 1686 | tg3_writephy(tp, reg, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1687 | } |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1688 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1689 | } |
| 1690 | } else { |
| 1691 | phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC | |
| 1692 | MII_TG3_AUXCTL_SHDWSEL_MISC; |
| 1693 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) && |
| 1694 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) { |
| 1695 | if (enable) |
| 1696 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 1697 | else |
| 1698 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 1699 | phy |= MII_TG3_AUXCTL_MISC_WREN; |
| 1700 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); |
| 1701 | } |
| 1702 | } |
| 1703 | } |
| 1704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
| 1706 | { |
| 1707 | u32 val; |
| 1708 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1709 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | return; |
| 1711 | |
| 1712 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) && |
| 1713 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val)) |
| 1714 | tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 1715 | (val | (1 << 15) | (1 << 4))); |
| 1716 | } |
| 1717 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1718 | static void tg3_phy_apply_otp(struct tg3 *tp) |
| 1719 | { |
| 1720 | u32 otp, phy; |
| 1721 | |
| 1722 | if (!tp->phy_otp) |
| 1723 | return; |
| 1724 | |
| 1725 | otp = tp->phy_otp; |
| 1726 | |
| 1727 | /* Enable SM_DSP clock and tx 6dB coding. */ |
| 1728 | phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | |
| 1729 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | |
| 1730 | MII_TG3_AUXCTL_ACTL_TX_6DB; |
| 1731 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); |
| 1732 | |
| 1733 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); |
| 1734 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; |
| 1735 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); |
| 1736 | |
| 1737 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | |
| 1738 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); |
| 1739 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); |
| 1740 | |
| 1741 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); |
| 1742 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; |
| 1743 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); |
| 1744 | |
| 1745 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); |
| 1746 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); |
| 1747 | |
| 1748 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); |
| 1749 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); |
| 1750 | |
| 1751 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | |
| 1752 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); |
| 1753 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); |
| 1754 | |
| 1755 | /* Turn off SM_DSP clock. */ |
| 1756 | phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | |
| 1757 | MII_TG3_AUXCTL_ACTL_TX_6DB; |
| 1758 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); |
| 1759 | } |
| 1760 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 1761 | static void tg3_phy_eee_adjust(struct tg3 *tp, u32 current_link_up) |
| 1762 | { |
| 1763 | u32 val; |
| 1764 | |
| 1765 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 1766 | return; |
| 1767 | |
| 1768 | tp->setlpicnt = 0; |
| 1769 | |
| 1770 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 1771 | current_link_up == 1 && |
| 1772 | (tp->link_config.active_speed == SPEED_1000 || |
| 1773 | (tp->link_config.active_speed == SPEED_100 && |
| 1774 | tp->link_config.active_duplex == DUPLEX_FULL))) { |
| 1775 | u32 eeectl; |
| 1776 | |
| 1777 | if (tp->link_config.active_speed == SPEED_1000) |
| 1778 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; |
| 1779 | else |
| 1780 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; |
| 1781 | |
| 1782 | tw32(TG3_CPMU_EEE_CTRL, eeectl); |
| 1783 | |
| 1784 | tg3_phy_cl45_read(tp, 0x7, TG3_CL45_D7_EEERES_STAT, &val); |
| 1785 | |
| 1786 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
| 1787 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) |
| 1788 | tp->setlpicnt = 2; |
| 1789 | } |
| 1790 | |
| 1791 | if (!tp->setlpicnt) { |
| 1792 | val = tr32(TG3_CPMU_EEE_MODE); |
| 1793 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 1794 | } |
| 1795 | } |
| 1796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | static int tg3_wait_macro_done(struct tg3 *tp) |
| 1798 | { |
| 1799 | int limit = 100; |
| 1800 | |
| 1801 | while (limit--) { |
| 1802 | u32 tmp32; |
| 1803 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1804 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | if ((tmp32 & 0x1000) == 0) |
| 1806 | break; |
| 1807 | } |
| 1808 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 1809 | if (limit < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | return -EBUSY; |
| 1811 | |
| 1812 | return 0; |
| 1813 | } |
| 1814 | |
| 1815 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) |
| 1816 | { |
| 1817 | static const u32 test_pat[4][6] = { |
| 1818 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, |
| 1819 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, |
| 1820 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, |
| 1821 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } |
| 1822 | }; |
| 1823 | int chan; |
| 1824 | |
| 1825 | for (chan = 0; chan < 4; chan++) { |
| 1826 | int i; |
| 1827 | |
| 1828 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1829 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1830 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | |
| 1832 | for (i = 0; i < 6; i++) |
| 1833 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, |
| 1834 | test_pat[chan][i]); |
| 1835 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1836 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | if (tg3_wait_macro_done(tp)) { |
| 1838 | *resetp = 1; |
| 1839 | return -EBUSY; |
| 1840 | } |
| 1841 | |
| 1842 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1843 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1844 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | if (tg3_wait_macro_done(tp)) { |
| 1846 | *resetp = 1; |
| 1847 | return -EBUSY; |
| 1848 | } |
| 1849 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1850 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | if (tg3_wait_macro_done(tp)) { |
| 1852 | *resetp = 1; |
| 1853 | return -EBUSY; |
| 1854 | } |
| 1855 | |
| 1856 | for (i = 0; i < 6; i += 2) { |
| 1857 | u32 low, high; |
| 1858 | |
| 1859 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || |
| 1860 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || |
| 1861 | tg3_wait_macro_done(tp)) { |
| 1862 | *resetp = 1; |
| 1863 | return -EBUSY; |
| 1864 | } |
| 1865 | low &= 0x7fff; |
| 1866 | high &= 0x000f; |
| 1867 | if (low != test_pat[chan][i] || |
| 1868 | high != test_pat[chan][i+1]) { |
| 1869 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); |
| 1870 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); |
| 1871 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); |
| 1872 | |
| 1873 | return -EBUSY; |
| 1874 | } |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | return 0; |
| 1879 | } |
| 1880 | |
| 1881 | static int tg3_phy_reset_chanpat(struct tg3 *tp) |
| 1882 | { |
| 1883 | int chan; |
| 1884 | |
| 1885 | for (chan = 0; chan < 4; chan++) { |
| 1886 | int i; |
| 1887 | |
| 1888 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1889 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1890 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | for (i = 0; i < 6; i++) |
| 1892 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1893 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | if (tg3_wait_macro_done(tp)) |
| 1895 | return -EBUSY; |
| 1896 | } |
| 1897 | |
| 1898 | return 0; |
| 1899 | } |
| 1900 | |
| 1901 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) |
| 1902 | { |
| 1903 | u32 reg32, phy9_orig; |
| 1904 | int retries, do_phy_reset, err; |
| 1905 | |
| 1906 | retries = 10; |
| 1907 | do_phy_reset = 1; |
| 1908 | do { |
| 1909 | if (do_phy_reset) { |
| 1910 | err = tg3_bmcr_reset(tp); |
| 1911 | if (err) |
| 1912 | return err; |
| 1913 | do_phy_reset = 0; |
| 1914 | } |
| 1915 | |
| 1916 | /* Disable transmitter and interrupt. */ |
| 1917 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) |
| 1918 | continue; |
| 1919 | |
| 1920 | reg32 |= 0x3000; |
| 1921 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 1922 | |
| 1923 | /* Set full-duplex, 1000 mbps. */ |
| 1924 | tg3_writephy(tp, MII_BMCR, |
| 1925 | BMCR_FULLDPLX | TG3_BMCR_SPEED1000); |
| 1926 | |
| 1927 | /* Set to master mode. */ |
| 1928 | if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig)) |
| 1929 | continue; |
| 1930 | |
| 1931 | tg3_writephy(tp, MII_TG3_CTRL, |
| 1932 | (MII_TG3_CTRL_AS_MASTER | |
| 1933 | MII_TG3_CTRL_ENABLE_AS_MASTER)); |
| 1934 | |
| 1935 | /* Enable SM_DSP_CLOCK and 6dB. */ |
| 1936 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
| 1937 | |
| 1938 | /* Block the PHY control access. */ |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 1939 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | |
| 1941 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); |
| 1942 | if (!err) |
| 1943 | break; |
| 1944 | } while (--retries); |
| 1945 | |
| 1946 | err = tg3_phy_reset_chanpat(tp); |
| 1947 | if (err) |
| 1948 | return err; |
| 1949 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 1950 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | |
| 1952 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1953 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | |
| 1955 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 1956 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 1957 | /* Set Extended packet length bit for jumbo frames */ |
| 1958 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400); |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 1959 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
| 1961 | } |
| 1962 | |
| 1963 | tg3_writephy(tp, MII_TG3_CTRL, phy9_orig); |
| 1964 | |
| 1965 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { |
| 1966 | reg32 &= ~0x3000; |
| 1967 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 1968 | } else if (!err) |
| 1969 | err = -EBUSY; |
| 1970 | |
| 1971 | return err; |
| 1972 | } |
| 1973 | |
| 1974 | /* This will reset the tigon3 PHY if there is no valid |
| 1975 | * link unless the FORCE argument is non-zero. |
| 1976 | */ |
| 1977 | static int tg3_phy_reset(struct tg3 *tp) |
| 1978 | { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 1979 | u32 val, cpmuctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | int err; |
| 1981 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 1982 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 1983 | val = tr32(GRC_MISC_CFG); |
| 1984 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); |
| 1985 | udelay(40); |
| 1986 | } |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 1987 | err = tg3_readphy(tp, MII_BMSR, &val); |
| 1988 | err |= tg3_readphy(tp, MII_BMSR, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | if (err != 0) |
| 1990 | return -EBUSY; |
| 1991 | |
Michael Chan | c8e1e82 | 2006-04-29 18:55:17 -0700 | [diff] [blame] | 1992 | if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) { |
| 1993 | netif_carrier_off(tp->dev); |
| 1994 | tg3_link_report(tp); |
| 1995 | } |
| 1996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 1998 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 1999 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 2000 | err = tg3_phy_reset_5703_4_5(tp); |
| 2001 | if (err) |
| 2002 | return err; |
| 2003 | goto out; |
| 2004 | } |
| 2005 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2006 | cpmuctrl = 0; |
| 2007 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 2008 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 2009 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
| 2010 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) |
| 2011 | tw32(TG3_CPMU_CTRL, |
| 2012 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); |
| 2013 | } |
| 2014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | err = tg3_bmcr_reset(tp); |
| 2016 | if (err) |
| 2017 | return err; |
| 2018 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2019 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2020 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
| 2021 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2022 | |
| 2023 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 2024 | } |
| 2025 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2026 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2027 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2028 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2029 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == |
| 2030 | CPMU_LSPD_1000MB_MACCLK_12_5) { |
| 2031 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2032 | udelay(40); |
| 2033 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2034 | } |
| 2035 | } |
| 2036 | |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 2037 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2038 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2039 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 2040 | return 0; |
| 2041 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2042 | tg3_phy_apply_otp(tp); |
| 2043 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2044 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2045 | tg3_phy_toggle_apd(tp, true); |
| 2046 | else |
| 2047 | tg3_phy_toggle_apd(tp, false); |
| 2048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | out: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2050 | if (tp->phy_flags & TG3_PHYFLG_ADC_BUG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2052 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
| 2053 | tg3_phydsp_write(tp, 0x000a, 0x0323); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
| 2055 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2056 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2057 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 2058 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2060 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2062 | tg3_phydsp_write(tp, 0x000a, 0x310b); |
| 2063 | tg3_phydsp_write(tp, 0x201f, 0x9506); |
| 2064 | tg3_phydsp_write(tp, 0x401f, 0x14e2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2066 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 2067 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
| 2068 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2069 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 2070 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
| 2071 | tg3_writephy(tp, MII_TG3_TEST1, |
| 2072 | MII_TG3_TEST1_TRIM_EN | 0x4); |
| 2073 | } else |
| 2074 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 2075 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
| 2076 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | /* Set Extended packet length bit (bit 14) on all chips that */ |
| 2078 | /* support jumbo frames */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2079 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | /* Cannot do read-modify-write on 5401 */ |
| 2081 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20); |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 2082 | } else if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | /* Set bit 14 with read-modify-write to preserve other bits */ |
| 2084 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) && |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2085 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val)) |
| 2086 | tg3_writephy(tp, MII_TG3_AUX_CTRL, val | 0x4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support |
| 2090 | * jumbo frames transmission. |
| 2091 | */ |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 2092 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2093 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 2094 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2095 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2098 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2099 | /* adjust output voltage */ |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2100 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2103 | tg3_phy_toggle_automdix(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | tg3_phy_set_wirespeed(tp); |
| 2105 | return 0; |
| 2106 | } |
| 2107 | |
| 2108 | static void tg3_frob_aux_power(struct tg3 *tp) |
| 2109 | { |
| 2110 | struct tg3 *tp_peer = tp; |
| 2111 | |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2112 | /* The GPIOs do something completely different on 57765. */ |
| 2113 | if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0 || |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 2114 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2115 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | return; |
| 2117 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 2118 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2119 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || |
| 2120 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2121 | struct net_device *dev_peer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2123 | dev_peer = pci_get_drvdata(tp->pdev_peer); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2124 | /* remove_one() may have been run on the peer. */ |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2125 | if (!dev_peer) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2126 | tp_peer = tp; |
| 2127 | else |
| 2128 | tp_peer = netdev_priv(dev_peer); |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | |
| 2131 | if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 || |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2132 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 || |
| 2133 | (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 || |
| 2134 | (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2136 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2137 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2138 | (GRC_LCLCTRL_GPIO_OE0 | |
| 2139 | GRC_LCLCTRL_GPIO_OE1 | |
| 2140 | GRC_LCLCTRL_GPIO_OE2 | |
| 2141 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2142 | GRC_LCLCTRL_GPIO_OUTPUT1), |
| 2143 | 100); |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 2144 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 2145 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 2146 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
| 2147 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | |
| 2148 | GRC_LCLCTRL_GPIO_OE1 | |
| 2149 | GRC_LCLCTRL_GPIO_OE2 | |
| 2150 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2151 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2152 | tp->grc_local_ctrl; |
| 2153 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
| 2154 | |
| 2155 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2156 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
| 2157 | |
| 2158 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2159 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | } else { |
| 2161 | u32 no_gpio2; |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2162 | u32 grc_local_ctrl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | |
| 2164 | if (tp_peer != tp && |
| 2165 | (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0) |
| 2166 | return; |
| 2167 | |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2168 | /* Workaround to prevent overdrawing Amps. */ |
| 2169 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 2170 | ASIC_REV_5714) { |
| 2171 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2172 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2173 | grc_local_ctrl, 100); |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2174 | } |
| 2175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | /* On 5753 and variants, GPIO2 cannot be used. */ |
| 2177 | no_gpio2 = tp->nic_sram_data_cfg & |
| 2178 | NIC_SRAM_DATA_CFG_NO_GPIO2; |
| 2179 | |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2180 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | GRC_LCLCTRL_GPIO_OE1 | |
| 2182 | GRC_LCLCTRL_GPIO_OE2 | |
| 2183 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2184 | GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2185 | if (no_gpio2) { |
| 2186 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | |
| 2187 | GRC_LCLCTRL_GPIO_OUTPUT2); |
| 2188 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2189 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2190 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | |
| 2192 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2193 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2194 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2195 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | |
| 2197 | if (!no_gpio2) { |
| 2198 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2199 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2200 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | } |
| 2202 | } |
| 2203 | } else { |
| 2204 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 2205 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
| 2206 | if (tp_peer != tp && |
| 2207 | (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0) |
| 2208 | return; |
| 2209 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2210 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2211 | (GRC_LCLCTRL_GPIO_OE1 | |
| 2212 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2214 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2215 | GRC_LCLCTRL_GPIO_OE1, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2217 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2218 | (GRC_LCLCTRL_GPIO_OE1 | |
| 2219 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | } |
| 2221 | } |
| 2222 | } |
| 2223 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2224 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
| 2225 | { |
| 2226 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) |
| 2227 | return 1; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2228 | 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] | 2229 | if (speed != SPEED_10) |
| 2230 | return 1; |
| 2231 | } else if (speed == SPEED_10) |
| 2232 | return 1; |
| 2233 | |
| 2234 | return 0; |
| 2235 | } |
| 2236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | static int tg3_setup_phy(struct tg3 *, int); |
| 2238 | |
| 2239 | #define RESET_KIND_SHUTDOWN 0 |
| 2240 | #define RESET_KIND_INIT 1 |
| 2241 | #define RESET_KIND_SUSPEND 2 |
| 2242 | |
| 2243 | static void tg3_write_sig_post_reset(struct tg3 *, int); |
| 2244 | static int tg3_halt_cpu(struct tg3 *, u32); |
| 2245 | |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2246 | 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] | 2247 | { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2248 | u32 val; |
| 2249 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2250 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2251 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2252 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 2253 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); |
| 2254 | |
| 2255 | sg_dig_ctrl |= |
| 2256 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; |
| 2257 | tw32(SG_DIG_CTRL, sg_dig_ctrl); |
| 2258 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); |
| 2259 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2260 | return; |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2261 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2262 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2263 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2264 | tg3_bmcr_reset(tp); |
| 2265 | val = tr32(GRC_MISC_CFG); |
| 2266 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); |
| 2267 | udelay(40); |
| 2268 | return; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2269 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 0e5f784 | 2009-11-02 14:26:38 +0000 | [diff] [blame] | 2270 | u32 phytest; |
| 2271 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2272 | u32 phy; |
| 2273 | |
| 2274 | tg3_writephy(tp, MII_ADVERTISE, 0); |
| 2275 | tg3_writephy(tp, MII_BMCR, |
| 2276 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 2277 | |
| 2278 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2279 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2280 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { |
| 2281 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; |
| 2282 | tg3_writephy(tp, |
| 2283 | MII_TG3_FET_SHDW_AUXMODE4, |
| 2284 | phy); |
| 2285 | } |
| 2286 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2287 | } |
| 2288 | return; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2289 | } else if (do_low_power) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2290 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 2291 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2292 | |
| 2293 | tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 2294 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL | |
| 2295 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 2296 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | |
| 2297 | MII_TG3_AUXCTL_PCTL_VREG_11V); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2298 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2299 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2300 | /* The PHY should not be powered down on some chips because |
| 2301 | * of bugs. |
| 2302 | */ |
| 2303 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2304 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2305 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2306 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2307 | return; |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2308 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2309 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2310 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2311 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2312 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2313 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; |
| 2314 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2315 | } |
| 2316 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2317 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 2318 | } |
| 2319 | |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2320 | /* tp->lock is held. */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2321 | static int tg3_nvram_lock(struct tg3 *tp) |
| 2322 | { |
| 2323 | if (tp->tg3_flags & TG3_FLAG_NVRAM) { |
| 2324 | int i; |
| 2325 | |
| 2326 | if (tp->nvram_lock_cnt == 0) { |
| 2327 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); |
| 2328 | for (i = 0; i < 8000; i++) { |
| 2329 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) |
| 2330 | break; |
| 2331 | udelay(20); |
| 2332 | } |
| 2333 | if (i == 8000) { |
| 2334 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2335 | return -ENODEV; |
| 2336 | } |
| 2337 | } |
| 2338 | tp->nvram_lock_cnt++; |
| 2339 | } |
| 2340 | return 0; |
| 2341 | } |
| 2342 | |
| 2343 | /* tp->lock is held. */ |
| 2344 | static void tg3_nvram_unlock(struct tg3 *tp) |
| 2345 | { |
| 2346 | if (tp->tg3_flags & TG3_FLAG_NVRAM) { |
| 2347 | if (tp->nvram_lock_cnt > 0) |
| 2348 | tp->nvram_lock_cnt--; |
| 2349 | if (tp->nvram_lock_cnt == 0) |
| 2350 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2351 | } |
| 2352 | } |
| 2353 | |
| 2354 | /* tp->lock is held. */ |
| 2355 | static void tg3_enable_nvram_access(struct tg3 *tp) |
| 2356 | { |
| 2357 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 2358 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2359 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2360 | |
| 2361 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | /* tp->lock is held. */ |
| 2366 | static void tg3_disable_nvram_access(struct tg3 *tp) |
| 2367 | { |
| 2368 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 2369 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2370 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2371 | |
| 2372 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); |
| 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, |
| 2377 | u32 offset, u32 *val) |
| 2378 | { |
| 2379 | u32 tmp; |
| 2380 | int i; |
| 2381 | |
| 2382 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) |
| 2383 | return -EINVAL; |
| 2384 | |
| 2385 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | |
| 2386 | EEPROM_ADDR_DEVID_MASK | |
| 2387 | EEPROM_ADDR_READ); |
| 2388 | tw32(GRC_EEPROM_ADDR, |
| 2389 | tmp | |
| 2390 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 2391 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & |
| 2392 | EEPROM_ADDR_ADDR_MASK) | |
| 2393 | EEPROM_ADDR_READ | EEPROM_ADDR_START); |
| 2394 | |
| 2395 | for (i = 0; i < 1000; i++) { |
| 2396 | tmp = tr32(GRC_EEPROM_ADDR); |
| 2397 | |
| 2398 | if (tmp & EEPROM_ADDR_COMPLETE) |
| 2399 | break; |
| 2400 | msleep(1); |
| 2401 | } |
| 2402 | if (!(tmp & EEPROM_ADDR_COMPLETE)) |
| 2403 | return -EBUSY; |
| 2404 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 2405 | tmp = tr32(GRC_EEPROM_DATA); |
| 2406 | |
| 2407 | /* |
| 2408 | * The data will always be opposite the native endian |
| 2409 | * format. Perform a blind byteswap to compensate. |
| 2410 | */ |
| 2411 | *val = swab32(tmp); |
| 2412 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2413 | return 0; |
| 2414 | } |
| 2415 | |
| 2416 | #define NVRAM_CMD_TIMEOUT 10000 |
| 2417 | |
| 2418 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) |
| 2419 | { |
| 2420 | int i; |
| 2421 | |
| 2422 | tw32(NVRAM_CMD, nvram_cmd); |
| 2423 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { |
| 2424 | udelay(10); |
| 2425 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { |
| 2426 | udelay(10); |
| 2427 | break; |
| 2428 | } |
| 2429 | } |
| 2430 | |
| 2431 | if (i == NVRAM_CMD_TIMEOUT) |
| 2432 | return -EBUSY; |
| 2433 | |
| 2434 | return 0; |
| 2435 | } |
| 2436 | |
| 2437 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) |
| 2438 | { |
| 2439 | if ((tp->tg3_flags & TG3_FLAG_NVRAM) && |
| 2440 | (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) && |
| 2441 | (tp->tg3_flags2 & TG3_FLG2_FLASH) && |
| 2442 | !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) && |
| 2443 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2444 | |
| 2445 | addr = ((addr / tp->nvram_pagesize) << |
| 2446 | ATMEL_AT45DB0X1B_PAGE_POS) + |
| 2447 | (addr % tp->nvram_pagesize); |
| 2448 | |
| 2449 | return addr; |
| 2450 | } |
| 2451 | |
| 2452 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) |
| 2453 | { |
| 2454 | if ((tp->tg3_flags & TG3_FLAG_NVRAM) && |
| 2455 | (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) && |
| 2456 | (tp->tg3_flags2 & TG3_FLG2_FLASH) && |
| 2457 | !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) && |
| 2458 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2459 | |
| 2460 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * |
| 2461 | tp->nvram_pagesize) + |
| 2462 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); |
| 2463 | |
| 2464 | return addr; |
| 2465 | } |
| 2466 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2467 | /* NOTE: Data read in from NVRAM is byteswapped according to |
| 2468 | * the byteswapping settings for all other register accesses. |
| 2469 | * tg3 devices are BE devices, so on a BE machine, the data |
| 2470 | * returned will be exactly as it is seen in NVRAM. On a LE |
| 2471 | * machine, the 32-bit value will be byteswapped. |
| 2472 | */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2473 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
| 2474 | { |
| 2475 | int ret; |
| 2476 | |
| 2477 | if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) |
| 2478 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
| 2479 | |
| 2480 | offset = tg3_nvram_phys_addr(tp, offset); |
| 2481 | |
| 2482 | if (offset > NVRAM_ADDR_MSK) |
| 2483 | return -EINVAL; |
| 2484 | |
| 2485 | ret = tg3_nvram_lock(tp); |
| 2486 | if (ret) |
| 2487 | return ret; |
| 2488 | |
| 2489 | tg3_enable_nvram_access(tp); |
| 2490 | |
| 2491 | tw32(NVRAM_ADDR, offset); |
| 2492 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | |
| 2493 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); |
| 2494 | |
| 2495 | if (ret == 0) |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2496 | *val = tr32(NVRAM_RDDATA); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2497 | |
| 2498 | tg3_disable_nvram_access(tp); |
| 2499 | |
| 2500 | tg3_nvram_unlock(tp); |
| 2501 | |
| 2502 | return ret; |
| 2503 | } |
| 2504 | |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2505 | /* Ensures NVRAM data is in bytestream format. */ |
| 2506 | 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] | 2507 | { |
| 2508 | u32 v; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2509 | int res = tg3_nvram_read(tp, offset, &v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2510 | if (!res) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2511 | *val = cpu_to_be32(v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2512 | return res; |
| 2513 | } |
| 2514 | |
| 2515 | /* tp->lock is held. */ |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2516 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) |
| 2517 | { |
| 2518 | u32 addr_high, addr_low; |
| 2519 | int i; |
| 2520 | |
| 2521 | addr_high = ((tp->dev->dev_addr[0] << 8) | |
| 2522 | tp->dev->dev_addr[1]); |
| 2523 | addr_low = ((tp->dev->dev_addr[2] << 24) | |
| 2524 | (tp->dev->dev_addr[3] << 16) | |
| 2525 | (tp->dev->dev_addr[4] << 8) | |
| 2526 | (tp->dev->dev_addr[5] << 0)); |
| 2527 | for (i = 0; i < 4; i++) { |
| 2528 | if (i == 1 && skip_mac_1) |
| 2529 | continue; |
| 2530 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); |
| 2531 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); |
| 2532 | } |
| 2533 | |
| 2534 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 2535 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2536 | for (i = 0; i < 12; i++) { |
| 2537 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); |
| 2538 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); |
| 2539 | } |
| 2540 | } |
| 2541 | |
| 2542 | addr_high = (tp->dev->dev_addr[0] + |
| 2543 | tp->dev->dev_addr[1] + |
| 2544 | tp->dev->dev_addr[2] + |
| 2545 | tp->dev->dev_addr[3] + |
| 2546 | tp->dev->dev_addr[4] + |
| 2547 | tp->dev->dev_addr[5]) & |
| 2548 | TX_BACKOFF_SEED_MASK; |
| 2549 | tw32(MAC_TX_BACKOFF_SEED, addr_high); |
| 2550 | } |
| 2551 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2552 | static int tg3_set_power_state(struct tg3 *tp, pci_power_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | { |
| 2554 | u32 misc_host_ctrl; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2555 | bool device_should_wake, do_low_power; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | |
| 2557 | /* Make sure register accesses (indirect or otherwise) |
| 2558 | * will function correctly. |
| 2559 | */ |
| 2560 | pci_write_config_dword(tp->pdev, |
| 2561 | TG3PCI_MISC_HOST_CTRL, |
| 2562 | tp->misc_host_ctrl); |
| 2563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | switch (state) { |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2565 | case PCI_D0: |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 2566 | pci_enable_wake(tp->pdev, state, false); |
| 2567 | pci_set_power_state(tp->pdev, PCI_D0); |
Michael Chan | 8c6bda1 | 2005-04-21 17:09:08 -0700 | [diff] [blame] | 2568 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 2569 | /* Switch out of Vaux if it is a NIC */ |
| 2570 | if (tp->tg3_flags2 & TG3_FLG2_IS_NIC) |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2571 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | |
| 2573 | return 0; |
| 2574 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2575 | case PCI_D1: |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2576 | case PCI_D2: |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2577 | case PCI_D3hot: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | break; |
| 2579 | |
| 2580 | default: |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 2581 | netdev_err(tp->dev, "Invalid power state (D%d) requested\n", |
| 2582 | state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 2584 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 2585 | |
| 2586 | /* Restore the CLKREQ setting. */ |
| 2587 | if (tp->tg3_flags3 & TG3_FLG3_CLKREQ_BUG) { |
| 2588 | u16 lnkctl; |
| 2589 | |
| 2590 | pci_read_config_word(tp->pdev, |
| 2591 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 2592 | &lnkctl); |
| 2593 | lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 2594 | pci_write_config_word(tp->pdev, |
| 2595 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 2596 | lnkctl); |
| 2597 | } |
| 2598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 2600 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 2601 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); |
| 2602 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2603 | device_should_wake = pci_pme_capable(tp->pdev, state) && |
| 2604 | device_may_wakeup(&tp->pdev->dev) && |
| 2605 | (tp->tg3_flags & TG3_FLAG_WOL_ENABLE); |
| 2606 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2607 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2608 | do_low_power = false; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2609 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2610 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2611 | struct phy_device *phydev; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2612 | u32 phyid, advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2613 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2614 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2615 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2616 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2617 | |
| 2618 | tp->link_config.orig_speed = phydev->speed; |
| 2619 | tp->link_config.orig_duplex = phydev->duplex; |
| 2620 | tp->link_config.orig_autoneg = phydev->autoneg; |
| 2621 | tp->link_config.orig_advertising = phydev->advertising; |
| 2622 | |
| 2623 | advertising = ADVERTISED_TP | |
| 2624 | ADVERTISED_Pause | |
| 2625 | ADVERTISED_Autoneg | |
| 2626 | ADVERTISED_10baseT_Half; |
| 2627 | |
| 2628 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2629 | device_should_wake) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2630 | if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) |
| 2631 | advertising |= |
| 2632 | ADVERTISED_100baseT_Half | |
| 2633 | ADVERTISED_100baseT_Full | |
| 2634 | ADVERTISED_10baseT_Full; |
| 2635 | else |
| 2636 | advertising |= ADVERTISED_10baseT_Full; |
| 2637 | } |
| 2638 | |
| 2639 | phydev->advertising = advertising; |
| 2640 | |
| 2641 | phy_start_aneg(phydev); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2642 | |
| 2643 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 2644 | if (phyid != PHY_ID_BCMAC131) { |
| 2645 | phyid &= PHY_BCM_OUI_MASK; |
| 2646 | if (phyid == PHY_BCM_OUI_1 || |
| 2647 | phyid == PHY_BCM_OUI_2 || |
| 2648 | phyid == PHY_BCM_OUI_3) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2649 | do_low_power = true; |
| 2650 | } |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2651 | } |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2652 | } else { |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 2653 | do_low_power = true; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2654 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2655 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 2656 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2657 | tp->link_config.orig_speed = tp->link_config.speed; |
| 2658 | tp->link_config.orig_duplex = tp->link_config.duplex; |
| 2659 | tp->link_config.orig_autoneg = tp->link_config.autoneg; |
| 2660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2662 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2663 | tp->link_config.speed = SPEED_10; |
| 2664 | tp->link_config.duplex = DUPLEX_HALF; |
| 2665 | tp->link_config.autoneg = AUTONEG_ENABLE; |
| 2666 | tg3_setup_phy(tp, 0); |
| 2667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | } |
| 2669 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 2670 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 2671 | u32 val; |
| 2672 | |
| 2673 | val = tr32(GRC_VCPU_EXT_CTRL); |
| 2674 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); |
| 2675 | } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2676 | int i; |
| 2677 | u32 val; |
| 2678 | |
| 2679 | for (i = 0; i < 200; i++) { |
| 2680 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); |
| 2681 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 2682 | break; |
| 2683 | msleep(1); |
| 2684 | } |
| 2685 | } |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 2686 | if (tp->tg3_flags & TG3_FLAG_WOL_CAP) |
| 2687 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
| 2688 | WOL_DRV_STATE_SHUTDOWN | |
| 2689 | WOL_DRV_WOL | |
| 2690 | WOL_SET_MAGIC_PKT); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2691 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2692 | if (device_should_wake) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | u32 mac_mode; |
| 2694 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2695 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2696 | if (do_low_power) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2697 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a); |
| 2698 | udelay(40); |
| 2699 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2701 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2702 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 2703 | else |
| 2704 | mac_mode = MAC_MODE_PORT_MODE_MII; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2706 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
| 2707 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 2708 | ASIC_REV_5700) { |
| 2709 | u32 speed = (tp->tg3_flags & |
| 2710 | TG3_FLAG_WOL_SPEED_100MB) ? |
| 2711 | SPEED_100 : SPEED_10; |
| 2712 | if (tg3_5700_link_polarity(tp, speed)) |
| 2713 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 2714 | else |
| 2715 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 2716 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | } else { |
| 2718 | mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 2719 | } |
| 2720 | |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 2721 | if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 2723 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2724 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
| 2725 | if (((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
| 2726 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) && |
| 2727 | ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
| 2728 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))) |
| 2729 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 2731 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
| 2732 | mac_mode |= tp->mac_mode & |
| 2733 | (MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN); |
| 2734 | if (mac_mode & MAC_MODE_APE_TX_EN) |
| 2735 | mac_mode |= MAC_MODE_TDE_ENABLE; |
| 2736 | } |
| 2737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | tw32_f(MAC_MODE, mac_mode); |
| 2739 | udelay(100); |
| 2740 | |
| 2741 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); |
| 2742 | udelay(10); |
| 2743 | } |
| 2744 | |
| 2745 | if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) && |
| 2746 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2747 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 2748 | u32 base_val; |
| 2749 | |
| 2750 | base_val = tp->pci_clock_ctrl; |
| 2751 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | |
| 2752 | CLOCK_CTRL_TXCLK_DISABLE); |
| 2753 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2754 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
| 2755 | CLOCK_CTRL_PWRDOWN_PLL133, 40); |
Michael Chan | d7b0a85 | 2007-02-13 12:17:38 -0800 | [diff] [blame] | 2756 | } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 2757 | (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) || |
Michael Chan | d7b0a85 | 2007-02-13 12:17:38 -0800 | [diff] [blame] | 2758 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) { |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 2759 | /* do nothing */ |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 2760 | } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) { |
| 2762 | u32 newbits1, newbits2; |
| 2763 | |
| 2764 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2765 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 2766 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 2767 | CLOCK_CTRL_TXCLK_DISABLE | |
| 2768 | CLOCK_CTRL_ALTCLK); |
| 2769 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 2770 | } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 2771 | newbits1 = CLOCK_CTRL_625_CORE; |
| 2772 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; |
| 2773 | } else { |
| 2774 | newbits1 = CLOCK_CTRL_ALTCLK; |
| 2775 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 2776 | } |
| 2777 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2778 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
| 2779 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2781 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
| 2782 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | |
| 2784 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 2785 | u32 newbits3; |
| 2786 | |
| 2787 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2788 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 2789 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 2790 | CLOCK_CTRL_TXCLK_DISABLE | |
| 2791 | CLOCK_CTRL_44MHZ_CORE); |
| 2792 | } else { |
| 2793 | newbits3 = CLOCK_CTRL_44MHZ_CORE; |
| 2794 | } |
| 2795 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2796 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 2797 | tp->pci_clock_ctrl | newbits3, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | } |
| 2799 | } |
| 2800 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2801 | if (!(device_should_wake) && |
Matt Carlson | 2243584 | 2008-11-21 17:21:13 -0800 | [diff] [blame] | 2802 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2803 | tg3_power_down_phy(tp, do_low_power); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | tg3_frob_aux_power(tp); |
| 2806 | |
| 2807 | /* Workaround for unstable PLL clock */ |
| 2808 | if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) || |
| 2809 | (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) { |
| 2810 | u32 val = tr32(0x7d00); |
| 2811 | |
| 2812 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); |
| 2813 | tw32(0x7d00, val); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2814 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 2815 | int err; |
| 2816 | |
| 2817 | err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 2819 | if (!err) |
| 2820 | tg3_nvram_unlock(tp); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | } |
| 2823 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 2824 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
| 2825 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2826 | if (device_should_wake) |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 2827 | pci_enable_wake(tp->pdev, state, true); |
| 2828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | /* Finally, set the new power state. */ |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 2830 | pci_set_power_state(tp->pdev, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | return 0; |
| 2833 | } |
| 2834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
| 2836 | { |
| 2837 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { |
| 2838 | case MII_TG3_AUX_STAT_10HALF: |
| 2839 | *speed = SPEED_10; |
| 2840 | *duplex = DUPLEX_HALF; |
| 2841 | break; |
| 2842 | |
| 2843 | case MII_TG3_AUX_STAT_10FULL: |
| 2844 | *speed = SPEED_10; |
| 2845 | *duplex = DUPLEX_FULL; |
| 2846 | break; |
| 2847 | |
| 2848 | case MII_TG3_AUX_STAT_100HALF: |
| 2849 | *speed = SPEED_100; |
| 2850 | *duplex = DUPLEX_HALF; |
| 2851 | break; |
| 2852 | |
| 2853 | case MII_TG3_AUX_STAT_100FULL: |
| 2854 | *speed = SPEED_100; |
| 2855 | *duplex = DUPLEX_FULL; |
| 2856 | break; |
| 2857 | |
| 2858 | case MII_TG3_AUX_STAT_1000HALF: |
| 2859 | *speed = SPEED_1000; |
| 2860 | *duplex = DUPLEX_HALF; |
| 2861 | break; |
| 2862 | |
| 2863 | case MII_TG3_AUX_STAT_1000FULL: |
| 2864 | *speed = SPEED_1000; |
| 2865 | *duplex = DUPLEX_FULL; |
| 2866 | break; |
| 2867 | |
| 2868 | default: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2869 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2870 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
| 2871 | SPEED_10; |
| 2872 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : |
| 2873 | DUPLEX_HALF; |
| 2874 | break; |
| 2875 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | *speed = SPEED_INVALID; |
| 2877 | *duplex = DUPLEX_INVALID; |
| 2878 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 2879 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | } |
| 2881 | |
| 2882 | static void tg3_phy_copper_begin(struct tg3 *tp) |
| 2883 | { |
| 2884 | u32 new_adv; |
| 2885 | int i; |
| 2886 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2887 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | /* Entering low power mode. Disable gigabit and |
| 2889 | * 100baseT advertisements. |
| 2890 | */ |
| 2891 | tg3_writephy(tp, MII_TG3_CTRL, 0); |
| 2892 | |
| 2893 | new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 2894 | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); |
| 2895 | if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) |
| 2896 | new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 2897 | |
| 2898 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 2899 | } else if (tp->link_config.speed == SPEED_INVALID) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2900 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | tp->link_config.advertising &= |
| 2902 | ~(ADVERTISED_1000baseT_Half | |
| 2903 | ADVERTISED_1000baseT_Full); |
| 2904 | |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2905 | new_adv = ADVERTISE_CSMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | if (tp->link_config.advertising & ADVERTISED_10baseT_Half) |
| 2907 | new_adv |= ADVERTISE_10HALF; |
| 2908 | if (tp->link_config.advertising & ADVERTISED_10baseT_Full) |
| 2909 | new_adv |= ADVERTISE_10FULL; |
| 2910 | if (tp->link_config.advertising & ADVERTISED_100baseT_Half) |
| 2911 | new_adv |= ADVERTISE_100HALF; |
| 2912 | if (tp->link_config.advertising & ADVERTISED_100baseT_Full) |
| 2913 | new_adv |= ADVERTISE_100FULL; |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2914 | |
| 2915 | new_adv |= tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); |
| 2916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 2918 | |
| 2919 | if (tp->link_config.advertising & |
| 2920 | (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) { |
| 2921 | new_adv = 0; |
| 2922 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) |
| 2923 | new_adv |= MII_TG3_CTRL_ADV_1000_HALF; |
| 2924 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) |
| 2925 | new_adv |= MII_TG3_CTRL_ADV_1000_FULL; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2926 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 2928 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)) |
| 2929 | new_adv |= (MII_TG3_CTRL_AS_MASTER | |
| 2930 | MII_TG3_CTRL_ENABLE_AS_MASTER); |
| 2931 | tg3_writephy(tp, MII_TG3_CTRL, new_adv); |
| 2932 | } else { |
| 2933 | tg3_writephy(tp, MII_TG3_CTRL, 0); |
| 2934 | } |
| 2935 | } else { |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2936 | new_adv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); |
| 2937 | new_adv |= ADVERTISE_CSMA; |
| 2938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | /* Asking for a specific link mode. */ |
| 2940 | if (tp->link_config.speed == SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 2942 | |
| 2943 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 2944 | new_adv = MII_TG3_CTRL_ADV_1000_FULL; |
| 2945 | else |
| 2946 | new_adv = MII_TG3_CTRL_ADV_1000_HALF; |
| 2947 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 2948 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) |
| 2949 | new_adv |= (MII_TG3_CTRL_AS_MASTER | |
| 2950 | MII_TG3_CTRL_ENABLE_AS_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | if (tp->link_config.speed == SPEED_100) { |
| 2953 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 2954 | new_adv |= ADVERTISE_100FULL; |
| 2955 | else |
| 2956 | new_adv |= ADVERTISE_100HALF; |
| 2957 | } else { |
| 2958 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 2959 | new_adv |= ADVERTISE_10FULL; |
| 2960 | else |
| 2961 | new_adv |= ADVERTISE_10HALF; |
| 2962 | } |
| 2963 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2964 | |
| 2965 | new_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | } |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2967 | |
| 2968 | tg3_writephy(tp, MII_TG3_CTRL, new_adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2971 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { |
| 2972 | u32 val = 0; |
| 2973 | |
| 2974 | tw32(TG3_CPMU_EEE_MODE, |
| 2975 | tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2976 | |
| 2977 | /* Enable SM_DSP clock and tx 6dB coding. */ |
| 2978 | val = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | |
| 2979 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | |
| 2980 | MII_TG3_AUXCTL_ACTL_TX_6DB; |
| 2981 | tg3_writephy(tp, MII_TG3_AUX_CTRL, val); |
| 2982 | |
| 2983 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2984 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) && |
| 2985 | !tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) |
| 2986 | tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, |
| 2987 | val | MII_TG3_DSP_CH34TP2_HIBW01); |
| 2988 | |
| 2989 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 2990 | /* Advertise 100-BaseTX EEE ability */ |
| 2991 | if (tp->link_config.advertising & |
| 2992 | (ADVERTISED_100baseT_Half | |
| 2993 | ADVERTISED_100baseT_Full)) |
| 2994 | val |= TG3_CL45_D7_EEEADV_CAP_100TX; |
| 2995 | /* Advertise 1000-BaseT EEE ability */ |
| 2996 | if (tp->link_config.advertising & |
| 2997 | (ADVERTISED_1000baseT_Half | |
| 2998 | ADVERTISED_1000baseT_Full)) |
| 2999 | val |= TG3_CL45_D7_EEEADV_CAP_1000T; |
| 3000 | } |
| 3001 | tg3_phy_cl45_write(tp, 0x7, TG3_CL45_D7_EEEADV_CAP, val); |
| 3002 | |
| 3003 | /* Turn off SM_DSP clock. */ |
| 3004 | val = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | |
| 3005 | MII_TG3_AUXCTL_ACTL_TX_6DB; |
| 3006 | tg3_writephy(tp, MII_TG3_AUX_CTRL, val); |
| 3007 | } |
| 3008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | if (tp->link_config.autoneg == AUTONEG_DISABLE && |
| 3010 | tp->link_config.speed != SPEED_INVALID) { |
| 3011 | u32 bmcr, orig_bmcr; |
| 3012 | |
| 3013 | tp->link_config.active_speed = tp->link_config.speed; |
| 3014 | tp->link_config.active_duplex = tp->link_config.duplex; |
| 3015 | |
| 3016 | bmcr = 0; |
| 3017 | switch (tp->link_config.speed) { |
| 3018 | default: |
| 3019 | case SPEED_10: |
| 3020 | break; |
| 3021 | |
| 3022 | case SPEED_100: |
| 3023 | bmcr |= BMCR_SPEED100; |
| 3024 | break; |
| 3025 | |
| 3026 | case SPEED_1000: |
| 3027 | bmcr |= TG3_BMCR_SPEED1000; |
| 3028 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3029 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | |
| 3031 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 3032 | bmcr |= BMCR_FULLDPLX; |
| 3033 | |
| 3034 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && |
| 3035 | (bmcr != orig_bmcr)) { |
| 3036 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); |
| 3037 | for (i = 0; i < 1500; i++) { |
| 3038 | u32 tmp; |
| 3039 | |
| 3040 | udelay(10); |
| 3041 | if (tg3_readphy(tp, MII_BMSR, &tmp) || |
| 3042 | tg3_readphy(tp, MII_BMSR, &tmp)) |
| 3043 | continue; |
| 3044 | if (!(tmp & BMSR_LSTATUS)) { |
| 3045 | udelay(40); |
| 3046 | break; |
| 3047 | } |
| 3048 | } |
| 3049 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 3050 | udelay(40); |
| 3051 | } |
| 3052 | } else { |
| 3053 | tg3_writephy(tp, MII_BMCR, |
| 3054 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | static int tg3_init_5401phy_dsp(struct tg3 *tp) |
| 3059 | { |
| 3060 | int err; |
| 3061 | |
| 3062 | /* Turn off tap power management. */ |
| 3063 | /* Set Extended packet length bit */ |
| 3064 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20); |
| 3065 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 3066 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
| 3067 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); |
| 3068 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); |
| 3069 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); |
| 3070 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | |
| 3072 | udelay(40); |
| 3073 | |
| 3074 | return err; |
| 3075 | } |
| 3076 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 3077 | static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | { |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 3079 | u32 adv_reg, all_mask = 0; |
| 3080 | |
| 3081 | if (mask & ADVERTISED_10baseT_Half) |
| 3082 | all_mask |= ADVERTISE_10HALF; |
| 3083 | if (mask & ADVERTISED_10baseT_Full) |
| 3084 | all_mask |= ADVERTISE_10FULL; |
| 3085 | if (mask & ADVERTISED_100baseT_Half) |
| 3086 | all_mask |= ADVERTISE_100HALF; |
| 3087 | if (mask & ADVERTISED_100baseT_Full) |
| 3088 | all_mask |= ADVERTISE_100FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | |
| 3090 | if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg)) |
| 3091 | return 0; |
| 3092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | if ((adv_reg & all_mask) != all_mask) |
| 3094 | return 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3095 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | u32 tg3_ctrl; |
| 3097 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 3098 | all_mask = 0; |
| 3099 | if (mask & ADVERTISED_1000baseT_Half) |
| 3100 | all_mask |= ADVERTISE_1000HALF; |
| 3101 | if (mask & ADVERTISED_1000baseT_Full) |
| 3102 | all_mask |= ADVERTISE_1000FULL; |
| 3103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl)) |
| 3105 | return 0; |
| 3106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | if ((tg3_ctrl & all_mask) != all_mask) |
| 3108 | return 0; |
| 3109 | } |
| 3110 | return 1; |
| 3111 | } |
| 3112 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3113 | static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv) |
| 3114 | { |
| 3115 | u32 curadv, reqadv; |
| 3116 | |
| 3117 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
| 3118 | return 1; |
| 3119 | |
| 3120 | curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
| 3121 | reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); |
| 3122 | |
| 3123 | if (tp->link_config.active_duplex == DUPLEX_FULL) { |
| 3124 | if (curadv != reqadv) |
| 3125 | return 0; |
| 3126 | |
| 3127 | if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) |
| 3128 | tg3_readphy(tp, MII_LPA, rmtadv); |
| 3129 | } else { |
| 3130 | /* Reprogram the advertisement register, even if it |
| 3131 | * does not affect the current link. If the link |
| 3132 | * gets renegotiated in the future, we can save an |
| 3133 | * additional renegotiation cycle by advertising |
| 3134 | * it correctly in the first place. |
| 3135 | */ |
| 3136 | if (curadv != reqadv) { |
| 3137 | *lcladv &= ~(ADVERTISE_PAUSE_CAP | |
| 3138 | ADVERTISE_PAUSE_ASYM); |
| 3139 | tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv); |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | return 1; |
| 3144 | } |
| 3145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
| 3147 | { |
| 3148 | int current_link_up; |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 3149 | u32 bmsr, val; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3150 | u32 lcl_adv, rmt_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | u16 current_speed; |
| 3152 | u8 current_duplex; |
| 3153 | int i, err; |
| 3154 | |
| 3155 | tw32(MAC_EVENT, 0); |
| 3156 | |
| 3157 | tw32_f(MAC_STATUS, |
| 3158 | (MAC_STATUS_SYNC_CHANGED | |
| 3159 | MAC_STATUS_CFG_CHANGED | |
| 3160 | MAC_STATUS_MI_COMPLETION | |
| 3161 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 3162 | udelay(40); |
| 3163 | |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 3164 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 3165 | tw32_f(MAC_MI_MODE, |
| 3166 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 3167 | udelay(80); |
| 3168 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | |
| 3170 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02); |
| 3171 | |
| 3172 | /* Some third-party PHYs need to be reset on link going |
| 3173 | * down. |
| 3174 | */ |
| 3175 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 3176 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 3177 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
| 3178 | netif_carrier_ok(tp->dev)) { |
| 3179 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3180 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3181 | !(bmsr & BMSR_LSTATUS)) |
| 3182 | force_reset = 1; |
| 3183 | } |
| 3184 | if (force_reset) |
| 3185 | tg3_phy_reset(tp); |
| 3186 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3187 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3189 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || |
| 3190 | !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) |
| 3191 | bmsr = 0; |
| 3192 | |
| 3193 | if (!(bmsr & BMSR_LSTATUS)) { |
| 3194 | err = tg3_init_5401phy_dsp(tp); |
| 3195 | if (err) |
| 3196 | return err; |
| 3197 | |
| 3198 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3199 | for (i = 0; i < 1000; i++) { |
| 3200 | udelay(10); |
| 3201 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3202 | (bmsr & BMSR_LSTATUS)) { |
| 3203 | udelay(40); |
| 3204 | break; |
| 3205 | } |
| 3206 | } |
| 3207 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3208 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
| 3209 | TG3_PHY_REV_BCM5401_B0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | !(bmsr & BMSR_LSTATUS) && |
| 3211 | tp->link_config.active_speed == SPEED_1000) { |
| 3212 | err = tg3_phy_reset(tp); |
| 3213 | if (!err) |
| 3214 | err = tg3_init_5401phy_dsp(tp); |
| 3215 | if (err) |
| 3216 | return err; |
| 3217 | } |
| 3218 | } |
| 3219 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 3220 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { |
| 3221 | /* 5701 {A0,B0} CRC bug workaround */ |
| 3222 | tg3_writephy(tp, 0x15, 0x0a75); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 3223 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
| 3224 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 3225 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | /* Clear pending interrupts... */ |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 3229 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
| 3230 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3232 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3234 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
| 3236 | |
| 3237 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3238 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3239 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
| 3240 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 3241 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 3242 | else |
| 3243 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); |
| 3244 | } |
| 3245 | |
| 3246 | current_link_up = 0; |
| 3247 | current_speed = SPEED_INVALID; |
| 3248 | current_duplex = DUPLEX_INVALID; |
| 3249 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3250 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007); |
| 3252 | tg3_readphy(tp, MII_TG3_AUX_CTRL, &val); |
| 3253 | if (!(val & (1 << 10))) { |
| 3254 | val |= (1 << 10); |
| 3255 | tg3_writephy(tp, MII_TG3_AUX_CTRL, val); |
| 3256 | goto relink; |
| 3257 | } |
| 3258 | } |
| 3259 | |
| 3260 | bmsr = 0; |
| 3261 | for (i = 0; i < 100; i++) { |
| 3262 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3263 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3264 | (bmsr & BMSR_LSTATUS)) |
| 3265 | break; |
| 3266 | udelay(40); |
| 3267 | } |
| 3268 | |
| 3269 | if (bmsr & BMSR_LSTATUS) { |
| 3270 | u32 aux_stat, bmcr; |
| 3271 | |
| 3272 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); |
| 3273 | for (i = 0; i < 2000; i++) { |
| 3274 | udelay(10); |
| 3275 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && |
| 3276 | aux_stat) |
| 3277 | break; |
| 3278 | } |
| 3279 | |
| 3280 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, |
| 3281 | ¤t_speed, |
| 3282 | ¤t_duplex); |
| 3283 | |
| 3284 | bmcr = 0; |
| 3285 | for (i = 0; i < 200; i++) { |
| 3286 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 3287 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) |
| 3288 | continue; |
| 3289 | if (bmcr && bmcr != 0x7fff) |
| 3290 | break; |
| 3291 | udelay(10); |
| 3292 | } |
| 3293 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3294 | lcl_adv = 0; |
| 3295 | rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3297 | tp->link_config.active_speed = current_speed; |
| 3298 | tp->link_config.active_duplex = current_duplex; |
| 3299 | |
| 3300 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 3301 | if ((bmcr & BMCR_ANENABLE) && |
| 3302 | tg3_copper_is_advertising_all(tp, |
| 3303 | tp->link_config.advertising)) { |
| 3304 | if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv, |
| 3305 | &rmt_adv)) |
| 3306 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | } |
| 3308 | } else { |
| 3309 | if (!(bmcr & BMCR_ANENABLE) && |
| 3310 | tp->link_config.speed == current_speed && |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3311 | tp->link_config.duplex == current_duplex && |
| 3312 | tp->link_config.flowctrl == |
| 3313 | tp->link_config.active_flowctrl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | } |
| 3316 | } |
| 3317 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3318 | if (current_link_up == 1 && |
| 3319 | tp->link_config.active_duplex == DUPLEX_FULL) |
| 3320 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | } |
| 3322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | relink: |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3324 | if (current_link_up == 0 || (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | tg3_phy_copper_begin(tp); |
| 3326 | |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 3327 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3328 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3329 | (bmsr & BMSR_LSTATUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | current_link_up = 1; |
| 3331 | } |
| 3332 | |
| 3333 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 3334 | if (current_link_up == 1) { |
| 3335 | if (tp->link_config.active_speed == SPEED_100 || |
| 3336 | tp->link_config.active_speed == SPEED_10) |
| 3337 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 3338 | else |
| 3339 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3340 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 3341 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 3342 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 3344 | |
| 3345 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 3346 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 3347 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 3348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3350 | if (current_link_up == 1 && |
| 3351 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3353 | else |
| 3354 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | /* ??? Without this setting Netgear GA302T PHY does not |
| 3358 | * ??? send/receive packets... |
| 3359 | */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3360 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
| 3362 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
| 3363 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 3364 | udelay(80); |
| 3365 | } |
| 3366 | |
| 3367 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3368 | udelay(40); |
| 3369 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3370 | tg3_phy_eee_adjust(tp, current_link_up); |
| 3371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) { |
| 3373 | /* Polled via timer. */ |
| 3374 | tw32_f(MAC_EVENT, 0); |
| 3375 | } else { |
| 3376 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 3377 | } |
| 3378 | udelay(40); |
| 3379 | |
| 3380 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && |
| 3381 | current_link_up == 1 && |
| 3382 | tp->link_config.active_speed == SPEED_1000 && |
| 3383 | ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) || |
| 3384 | (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) { |
| 3385 | udelay(120); |
| 3386 | tw32_f(MAC_STATUS, |
| 3387 | (MAC_STATUS_SYNC_CHANGED | |
| 3388 | MAC_STATUS_CFG_CHANGED)); |
| 3389 | udelay(40); |
| 3390 | tg3_write_mem(tp, |
| 3391 | NIC_SRAM_FIRMWARE_MBOX, |
| 3392 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); |
| 3393 | } |
| 3394 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3395 | /* Prevent send BD corruption. */ |
| 3396 | if (tp->tg3_flags3 & TG3_FLG3_CLKREQ_BUG) { |
| 3397 | u16 oldlnkctl, newlnkctl; |
| 3398 | |
| 3399 | pci_read_config_word(tp->pdev, |
| 3400 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 3401 | &oldlnkctl); |
| 3402 | if (tp->link_config.active_speed == SPEED_100 || |
| 3403 | tp->link_config.active_speed == SPEED_10) |
| 3404 | newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3405 | else |
| 3406 | newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3407 | if (newlnkctl != oldlnkctl) |
| 3408 | pci_write_config_word(tp->pdev, |
| 3409 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 3410 | newlnkctl); |
| 3411 | } |
| 3412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 3414 | if (current_link_up) |
| 3415 | netif_carrier_on(tp->dev); |
| 3416 | else |
| 3417 | netif_carrier_off(tp->dev); |
| 3418 | tg3_link_report(tp); |
| 3419 | } |
| 3420 | |
| 3421 | return 0; |
| 3422 | } |
| 3423 | |
| 3424 | struct tg3_fiber_aneginfo { |
| 3425 | int state; |
| 3426 | #define ANEG_STATE_UNKNOWN 0 |
| 3427 | #define ANEG_STATE_AN_ENABLE 1 |
| 3428 | #define ANEG_STATE_RESTART_INIT 2 |
| 3429 | #define ANEG_STATE_RESTART 3 |
| 3430 | #define ANEG_STATE_DISABLE_LINK_OK 4 |
| 3431 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 |
| 3432 | #define ANEG_STATE_ABILITY_DETECT 6 |
| 3433 | #define ANEG_STATE_ACK_DETECT_INIT 7 |
| 3434 | #define ANEG_STATE_ACK_DETECT 8 |
| 3435 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 |
| 3436 | #define ANEG_STATE_COMPLETE_ACK 10 |
| 3437 | #define ANEG_STATE_IDLE_DETECT_INIT 11 |
| 3438 | #define ANEG_STATE_IDLE_DETECT 12 |
| 3439 | #define ANEG_STATE_LINK_OK 13 |
| 3440 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 |
| 3441 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 |
| 3442 | |
| 3443 | u32 flags; |
| 3444 | #define MR_AN_ENABLE 0x00000001 |
| 3445 | #define MR_RESTART_AN 0x00000002 |
| 3446 | #define MR_AN_COMPLETE 0x00000004 |
| 3447 | #define MR_PAGE_RX 0x00000008 |
| 3448 | #define MR_NP_LOADED 0x00000010 |
| 3449 | #define MR_TOGGLE_TX 0x00000020 |
| 3450 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 |
| 3451 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 |
| 3452 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 |
| 3453 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 |
| 3454 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 |
| 3455 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 |
| 3456 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 |
| 3457 | #define MR_TOGGLE_RX 0x00002000 |
| 3458 | #define MR_NP_RX 0x00004000 |
| 3459 | |
| 3460 | #define MR_LINK_OK 0x80000000 |
| 3461 | |
| 3462 | unsigned long link_time, cur_time; |
| 3463 | |
| 3464 | u32 ability_match_cfg; |
| 3465 | int ability_match_count; |
| 3466 | |
| 3467 | char ability_match, idle_match, ack_match; |
| 3468 | |
| 3469 | u32 txconfig, rxconfig; |
| 3470 | #define ANEG_CFG_NP 0x00000080 |
| 3471 | #define ANEG_CFG_ACK 0x00000040 |
| 3472 | #define ANEG_CFG_RF2 0x00000020 |
| 3473 | #define ANEG_CFG_RF1 0x00000010 |
| 3474 | #define ANEG_CFG_PS2 0x00000001 |
| 3475 | #define ANEG_CFG_PS1 0x00008000 |
| 3476 | #define ANEG_CFG_HD 0x00004000 |
| 3477 | #define ANEG_CFG_FD 0x00002000 |
| 3478 | #define ANEG_CFG_INVAL 0x00001f06 |
| 3479 | |
| 3480 | }; |
| 3481 | #define ANEG_OK 0 |
| 3482 | #define ANEG_DONE 1 |
| 3483 | #define ANEG_TIMER_ENAB 2 |
| 3484 | #define ANEG_FAILED -1 |
| 3485 | |
| 3486 | #define ANEG_STATE_SETTLE_TIME 10000 |
| 3487 | |
| 3488 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, |
| 3489 | struct tg3_fiber_aneginfo *ap) |
| 3490 | { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3491 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | unsigned long delta; |
| 3493 | u32 rx_cfg_reg; |
| 3494 | int ret; |
| 3495 | |
| 3496 | if (ap->state == ANEG_STATE_UNKNOWN) { |
| 3497 | ap->rxconfig = 0; |
| 3498 | ap->link_time = 0; |
| 3499 | ap->cur_time = 0; |
| 3500 | ap->ability_match_cfg = 0; |
| 3501 | ap->ability_match_count = 0; |
| 3502 | ap->ability_match = 0; |
| 3503 | ap->idle_match = 0; |
| 3504 | ap->ack_match = 0; |
| 3505 | } |
| 3506 | ap->cur_time++; |
| 3507 | |
| 3508 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { |
| 3509 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); |
| 3510 | |
| 3511 | if (rx_cfg_reg != ap->ability_match_cfg) { |
| 3512 | ap->ability_match_cfg = rx_cfg_reg; |
| 3513 | ap->ability_match = 0; |
| 3514 | ap->ability_match_count = 0; |
| 3515 | } else { |
| 3516 | if (++ap->ability_match_count > 1) { |
| 3517 | ap->ability_match = 1; |
| 3518 | ap->ability_match_cfg = rx_cfg_reg; |
| 3519 | } |
| 3520 | } |
| 3521 | if (rx_cfg_reg & ANEG_CFG_ACK) |
| 3522 | ap->ack_match = 1; |
| 3523 | else |
| 3524 | ap->ack_match = 0; |
| 3525 | |
| 3526 | ap->idle_match = 0; |
| 3527 | } else { |
| 3528 | ap->idle_match = 1; |
| 3529 | ap->ability_match_cfg = 0; |
| 3530 | ap->ability_match_count = 0; |
| 3531 | ap->ability_match = 0; |
| 3532 | ap->ack_match = 0; |
| 3533 | |
| 3534 | rx_cfg_reg = 0; |
| 3535 | } |
| 3536 | |
| 3537 | ap->rxconfig = rx_cfg_reg; |
| 3538 | ret = ANEG_OK; |
| 3539 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 3540 | switch (ap->state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | case ANEG_STATE_UNKNOWN: |
| 3542 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) |
| 3543 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3544 | |
| 3545 | /* fallthru */ |
| 3546 | case ANEG_STATE_AN_ENABLE: |
| 3547 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); |
| 3548 | if (ap->flags & MR_AN_ENABLE) { |
| 3549 | ap->link_time = 0; |
| 3550 | ap->cur_time = 0; |
| 3551 | ap->ability_match_cfg = 0; |
| 3552 | ap->ability_match_count = 0; |
| 3553 | ap->ability_match = 0; |
| 3554 | ap->idle_match = 0; |
| 3555 | ap->ack_match = 0; |
| 3556 | |
| 3557 | ap->state = ANEG_STATE_RESTART_INIT; |
| 3558 | } else { |
| 3559 | ap->state = ANEG_STATE_DISABLE_LINK_OK; |
| 3560 | } |
| 3561 | break; |
| 3562 | |
| 3563 | case ANEG_STATE_RESTART_INIT: |
| 3564 | ap->link_time = ap->cur_time; |
| 3565 | ap->flags &= ~(MR_NP_LOADED); |
| 3566 | ap->txconfig = 0; |
| 3567 | tw32(MAC_TX_AUTO_NEG, 0); |
| 3568 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3569 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3570 | udelay(40); |
| 3571 | |
| 3572 | ret = ANEG_TIMER_ENAB; |
| 3573 | ap->state = ANEG_STATE_RESTART; |
| 3574 | |
| 3575 | /* fallthru */ |
| 3576 | case ANEG_STATE_RESTART: |
| 3577 | delta = ap->cur_time - ap->link_time; |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 3578 | if (delta > ANEG_STATE_SETTLE_TIME) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 3580 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | ret = ANEG_TIMER_ENAB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | break; |
| 3583 | |
| 3584 | case ANEG_STATE_DISABLE_LINK_OK: |
| 3585 | ret = ANEG_DONE; |
| 3586 | break; |
| 3587 | |
| 3588 | case ANEG_STATE_ABILITY_DETECT_INIT: |
| 3589 | ap->flags &= ~(MR_TOGGLE_TX); |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3590 | ap->txconfig = ANEG_CFG_FD; |
| 3591 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 3592 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 3593 | ap->txconfig |= ANEG_CFG_PS1; |
| 3594 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 3595 | ap->txconfig |= ANEG_CFG_PS2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 3597 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3598 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3599 | udelay(40); |
| 3600 | |
| 3601 | ap->state = ANEG_STATE_ABILITY_DETECT; |
| 3602 | break; |
| 3603 | |
| 3604 | case ANEG_STATE_ABILITY_DETECT: |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 3605 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | break; |
| 3608 | |
| 3609 | case ANEG_STATE_ACK_DETECT_INIT: |
| 3610 | ap->txconfig |= ANEG_CFG_ACK; |
| 3611 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 3612 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3613 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3614 | udelay(40); |
| 3615 | |
| 3616 | ap->state = ANEG_STATE_ACK_DETECT; |
| 3617 | |
| 3618 | /* fallthru */ |
| 3619 | case ANEG_STATE_ACK_DETECT: |
| 3620 | if (ap->ack_match != 0) { |
| 3621 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == |
| 3622 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { |
| 3623 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; |
| 3624 | } else { |
| 3625 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3626 | } |
| 3627 | } else if (ap->ability_match != 0 && |
| 3628 | ap->rxconfig == 0) { |
| 3629 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3630 | } |
| 3631 | break; |
| 3632 | |
| 3633 | case ANEG_STATE_COMPLETE_ACK_INIT: |
| 3634 | if (ap->rxconfig & ANEG_CFG_INVAL) { |
| 3635 | ret = ANEG_FAILED; |
| 3636 | break; |
| 3637 | } |
| 3638 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | |
| 3639 | MR_LP_ADV_HALF_DUPLEX | |
| 3640 | MR_LP_ADV_SYM_PAUSE | |
| 3641 | MR_LP_ADV_ASYM_PAUSE | |
| 3642 | MR_LP_ADV_REMOTE_FAULT1 | |
| 3643 | MR_LP_ADV_REMOTE_FAULT2 | |
| 3644 | MR_LP_ADV_NEXT_PAGE | |
| 3645 | MR_TOGGLE_RX | |
| 3646 | MR_NP_RX); |
| 3647 | if (ap->rxconfig & ANEG_CFG_FD) |
| 3648 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; |
| 3649 | if (ap->rxconfig & ANEG_CFG_HD) |
| 3650 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; |
| 3651 | if (ap->rxconfig & ANEG_CFG_PS1) |
| 3652 | ap->flags |= MR_LP_ADV_SYM_PAUSE; |
| 3653 | if (ap->rxconfig & ANEG_CFG_PS2) |
| 3654 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; |
| 3655 | if (ap->rxconfig & ANEG_CFG_RF1) |
| 3656 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; |
| 3657 | if (ap->rxconfig & ANEG_CFG_RF2) |
| 3658 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; |
| 3659 | if (ap->rxconfig & ANEG_CFG_NP) |
| 3660 | ap->flags |= MR_LP_ADV_NEXT_PAGE; |
| 3661 | |
| 3662 | ap->link_time = ap->cur_time; |
| 3663 | |
| 3664 | ap->flags ^= (MR_TOGGLE_TX); |
| 3665 | if (ap->rxconfig & 0x0008) |
| 3666 | ap->flags |= MR_TOGGLE_RX; |
| 3667 | if (ap->rxconfig & ANEG_CFG_NP) |
| 3668 | ap->flags |= MR_NP_RX; |
| 3669 | ap->flags |= MR_PAGE_RX; |
| 3670 | |
| 3671 | ap->state = ANEG_STATE_COMPLETE_ACK; |
| 3672 | ret = ANEG_TIMER_ENAB; |
| 3673 | break; |
| 3674 | |
| 3675 | case ANEG_STATE_COMPLETE_ACK: |
| 3676 | if (ap->ability_match != 0 && |
| 3677 | ap->rxconfig == 0) { |
| 3678 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3679 | break; |
| 3680 | } |
| 3681 | delta = ap->cur_time - ap->link_time; |
| 3682 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 3683 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { |
| 3684 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 3685 | } else { |
| 3686 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && |
| 3687 | !(ap->flags & MR_NP_RX)) { |
| 3688 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 3689 | } else { |
| 3690 | ret = ANEG_FAILED; |
| 3691 | } |
| 3692 | } |
| 3693 | } |
| 3694 | break; |
| 3695 | |
| 3696 | case ANEG_STATE_IDLE_DETECT_INIT: |
| 3697 | ap->link_time = ap->cur_time; |
| 3698 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 3699 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3700 | udelay(40); |
| 3701 | |
| 3702 | ap->state = ANEG_STATE_IDLE_DETECT; |
| 3703 | ret = ANEG_TIMER_ENAB; |
| 3704 | break; |
| 3705 | |
| 3706 | case ANEG_STATE_IDLE_DETECT: |
| 3707 | if (ap->ability_match != 0 && |
| 3708 | ap->rxconfig == 0) { |
| 3709 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3710 | break; |
| 3711 | } |
| 3712 | delta = ap->cur_time - ap->link_time; |
| 3713 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 3714 | /* XXX another gem from the Broadcom driver :( */ |
| 3715 | ap->state = ANEG_STATE_LINK_OK; |
| 3716 | } |
| 3717 | break; |
| 3718 | |
| 3719 | case ANEG_STATE_LINK_OK: |
| 3720 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); |
| 3721 | ret = ANEG_DONE; |
| 3722 | break; |
| 3723 | |
| 3724 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: |
| 3725 | /* ??? unimplemented */ |
| 3726 | break; |
| 3727 | |
| 3728 | case ANEG_STATE_NEXT_PAGE_WAIT: |
| 3729 | /* ??? unimplemented */ |
| 3730 | break; |
| 3731 | |
| 3732 | default: |
| 3733 | ret = ANEG_FAILED; |
| 3734 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3735 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | |
| 3737 | return ret; |
| 3738 | } |
| 3739 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3740 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | { |
| 3742 | int res = 0; |
| 3743 | struct tg3_fiber_aneginfo aninfo; |
| 3744 | int status = ANEG_FAILED; |
| 3745 | unsigned int tick; |
| 3746 | u32 tmp; |
| 3747 | |
| 3748 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 3749 | |
| 3750 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
| 3751 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); |
| 3752 | udelay(40); |
| 3753 | |
| 3754 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); |
| 3755 | udelay(40); |
| 3756 | |
| 3757 | memset(&aninfo, 0, sizeof(aninfo)); |
| 3758 | aninfo.flags |= MR_AN_ENABLE; |
| 3759 | aninfo.state = ANEG_STATE_UNKNOWN; |
| 3760 | aninfo.cur_time = 0; |
| 3761 | tick = 0; |
| 3762 | while (++tick < 195000) { |
| 3763 | status = tg3_fiber_aneg_smachine(tp, &aninfo); |
| 3764 | if (status == ANEG_DONE || status == ANEG_FAILED) |
| 3765 | break; |
| 3766 | |
| 3767 | udelay(1); |
| 3768 | } |
| 3769 | |
| 3770 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 3771 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3772 | udelay(40); |
| 3773 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3774 | *txflags = aninfo.txconfig; |
| 3775 | *rxflags = aninfo.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | |
| 3777 | if (status == ANEG_DONE && |
| 3778 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | |
| 3779 | MR_LP_ADV_FULL_DUPLEX))) |
| 3780 | res = 1; |
| 3781 | |
| 3782 | return res; |
| 3783 | } |
| 3784 | |
| 3785 | static void tg3_init_bcm8002(struct tg3 *tp) |
| 3786 | { |
| 3787 | u32 mac_status = tr32(MAC_STATUS); |
| 3788 | int i; |
| 3789 | |
| 3790 | /* Reset when initting first time or we have a link. */ |
| 3791 | if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) && |
| 3792 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 3793 | return; |
| 3794 | |
| 3795 | /* Set PLL lock range. */ |
| 3796 | tg3_writephy(tp, 0x16, 0x8007); |
| 3797 | |
| 3798 | /* SW reset */ |
| 3799 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); |
| 3800 | |
| 3801 | /* Wait for reset to complete. */ |
| 3802 | /* XXX schedule_timeout() ... */ |
| 3803 | for (i = 0; i < 500; i++) |
| 3804 | udelay(10); |
| 3805 | |
| 3806 | /* Config mode; select PMA/Ch 1 regs. */ |
| 3807 | tg3_writephy(tp, 0x10, 0x8411); |
| 3808 | |
| 3809 | /* Enable auto-lock and comdet, select txclk for tx. */ |
| 3810 | tg3_writephy(tp, 0x11, 0x0a10); |
| 3811 | |
| 3812 | tg3_writephy(tp, 0x18, 0x00a0); |
| 3813 | tg3_writephy(tp, 0x16, 0x41ff); |
| 3814 | |
| 3815 | /* Assert and deassert POR. */ |
| 3816 | tg3_writephy(tp, 0x13, 0x0400); |
| 3817 | udelay(40); |
| 3818 | tg3_writephy(tp, 0x13, 0x0000); |
| 3819 | |
| 3820 | tg3_writephy(tp, 0x11, 0x0a50); |
| 3821 | udelay(40); |
| 3822 | tg3_writephy(tp, 0x11, 0x0a10); |
| 3823 | |
| 3824 | /* Wait for signal to stabilize */ |
| 3825 | /* XXX schedule_timeout() ... */ |
| 3826 | for (i = 0; i < 15000; i++) |
| 3827 | udelay(10); |
| 3828 | |
| 3829 | /* Deselect the channel register so we can read the PHYID |
| 3830 | * later. |
| 3831 | */ |
| 3832 | tg3_writephy(tp, 0x10, 0x8011); |
| 3833 | } |
| 3834 | |
| 3835 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
| 3836 | { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3837 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | u32 sg_dig_ctrl, sg_dig_status; |
| 3839 | u32 serdes_cfg, expected_sg_dig_ctrl; |
| 3840 | int workaround, port_a; |
| 3841 | int current_link_up; |
| 3842 | |
| 3843 | serdes_cfg = 0; |
| 3844 | expected_sg_dig_ctrl = 0; |
| 3845 | workaround = 0; |
| 3846 | port_a = 1; |
| 3847 | current_link_up = 0; |
| 3848 | |
| 3849 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && |
| 3850 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { |
| 3851 | workaround = 1; |
| 3852 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 3853 | port_a = 0; |
| 3854 | |
| 3855 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ |
| 3856 | /* preserve bits 20-23 for voltage regulator */ |
| 3857 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; |
| 3858 | } |
| 3859 | |
| 3860 | sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 3861 | |
| 3862 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3863 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | if (workaround) { |
| 3865 | u32 val = serdes_cfg; |
| 3866 | |
| 3867 | if (port_a) |
| 3868 | val |= 0xc010000; |
| 3869 | else |
| 3870 | val |= 0x4010000; |
| 3871 | tw32_f(MAC_SERDES_CFG, val); |
| 3872 | } |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3873 | |
| 3874 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | } |
| 3876 | if (mac_status & MAC_STATUS_PCS_SYNCED) { |
| 3877 | tg3_setup_flow_control(tp, 0, 0); |
| 3878 | current_link_up = 1; |
| 3879 | } |
| 3880 | goto out; |
| 3881 | } |
| 3882 | |
| 3883 | /* Want auto-negotiation. */ |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3884 | 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] | 3885 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3886 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 3887 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 3888 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; |
| 3889 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 3890 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | |
| 3892 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3893 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3894 | tp->serdes_counter && |
| 3895 | ((mac_status & (MAC_STATUS_PCS_SYNCED | |
| 3896 | MAC_STATUS_RCVD_CFG)) == |
| 3897 | MAC_STATUS_PCS_SYNCED)) { |
| 3898 | tp->serdes_counter--; |
| 3899 | current_link_up = 1; |
| 3900 | goto out; |
| 3901 | } |
| 3902 | restart_autoneg: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | if (workaround) |
| 3904 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3905 | 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] | 3906 | udelay(5); |
| 3907 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); |
| 3908 | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3909 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3910 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
| 3912 | MAC_STATUS_SIGNAL_DET)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3913 | sg_dig_status = tr32(SG_DIG_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | mac_status = tr32(MAC_STATUS); |
| 3915 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3916 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3918 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3920 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) |
| 3921 | local_adv |= ADVERTISE_1000XPAUSE; |
| 3922 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) |
| 3923 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 3924 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3925 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3926 | remote_adv |= LPA_1000XPAUSE; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3927 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3928 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | |
| 3930 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 3931 | current_link_up = 1; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3932 | tp->serdes_counter = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3933 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3934 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3935 | if (tp->serdes_counter) |
| 3936 | tp->serdes_counter--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | else { |
| 3938 | if (workaround) { |
| 3939 | u32 val = serdes_cfg; |
| 3940 | |
| 3941 | if (port_a) |
| 3942 | val |= 0xc010000; |
| 3943 | else |
| 3944 | val |= 0x4010000; |
| 3945 | |
| 3946 | tw32_f(MAC_SERDES_CFG, val); |
| 3947 | } |
| 3948 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3949 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | udelay(40); |
| 3951 | |
| 3952 | /* Link parallel detection - link is up */ |
| 3953 | /* only if we have PCS_SYNC and not */ |
| 3954 | /* receiving config code words */ |
| 3955 | mac_status = tr32(MAC_STATUS); |
| 3956 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && |
| 3957 | !(mac_status & MAC_STATUS_RCVD_CFG)) { |
| 3958 | tg3_setup_flow_control(tp, 0, 0); |
| 3959 | current_link_up = 1; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3960 | tp->phy_flags |= |
| 3961 | TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3962 | tp->serdes_counter = |
| 3963 | SERDES_PARALLEL_DET_TIMEOUT; |
| 3964 | } else |
| 3965 | goto restart_autoneg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | } |
| 3967 | } |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3968 | } else { |
| 3969 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3970 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | out: |
| 3974 | return current_link_up; |
| 3975 | } |
| 3976 | |
| 3977 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
| 3978 | { |
| 3979 | int current_link_up = 0; |
| 3980 | |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 3981 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | |
| 3984 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3985 | u32 txflags, rxflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3987 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3988 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
| 3989 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3991 | if (txflags & ANEG_CFG_PS1) |
| 3992 | local_adv |= ADVERTISE_1000XPAUSE; |
| 3993 | if (txflags & ANEG_CFG_PS2) |
| 3994 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 3995 | |
| 3996 | if (rxflags & MR_LP_ADV_SYM_PAUSE) |
| 3997 | remote_adv |= LPA_1000XPAUSE; |
| 3998 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) |
| 3999 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | |
| 4001 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | current_link_up = 1; |
| 4004 | } |
| 4005 | for (i = 0; i < 30; i++) { |
| 4006 | udelay(20); |
| 4007 | tw32_f(MAC_STATUS, |
| 4008 | (MAC_STATUS_SYNC_CHANGED | |
| 4009 | MAC_STATUS_CFG_CHANGED)); |
| 4010 | udelay(40); |
| 4011 | if ((tr32(MAC_STATUS) & |
| 4012 | (MAC_STATUS_SYNC_CHANGED | |
| 4013 | MAC_STATUS_CFG_CHANGED)) == 0) |
| 4014 | break; |
| 4015 | } |
| 4016 | |
| 4017 | mac_status = tr32(MAC_STATUS); |
| 4018 | if (current_link_up == 0 && |
| 4019 | (mac_status & MAC_STATUS_PCS_SYNCED) && |
| 4020 | !(mac_status & MAC_STATUS_RCVD_CFG)) |
| 4021 | current_link_up = 1; |
| 4022 | } else { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4023 | tg3_setup_flow_control(tp, 0, 0); |
| 4024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | /* Forcing 1000FD link up. */ |
| 4026 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | |
| 4028 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); |
| 4029 | udelay(40); |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4030 | |
| 4031 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4032 | udelay(40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | out: |
| 4036 | return current_link_up; |
| 4037 | } |
| 4038 | |
| 4039 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) |
| 4040 | { |
| 4041 | u32 orig_pause_cfg; |
| 4042 | u16 orig_active_speed; |
| 4043 | u8 orig_active_duplex; |
| 4044 | u32 mac_status; |
| 4045 | int current_link_up; |
| 4046 | int i; |
| 4047 | |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 4048 | orig_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | orig_active_speed = tp->link_config.active_speed; |
| 4050 | orig_active_duplex = tp->link_config.active_duplex; |
| 4051 | |
| 4052 | if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) && |
| 4053 | netif_carrier_ok(tp->dev) && |
| 4054 | (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) { |
| 4055 | mac_status = tr32(MAC_STATUS); |
| 4056 | mac_status &= (MAC_STATUS_PCS_SYNCED | |
| 4057 | MAC_STATUS_SIGNAL_DET | |
| 4058 | MAC_STATUS_CFG_CHANGED | |
| 4059 | MAC_STATUS_RCVD_CFG); |
| 4060 | if (mac_status == (MAC_STATUS_PCS_SYNCED | |
| 4061 | MAC_STATUS_SIGNAL_DET)) { |
| 4062 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 4063 | MAC_STATUS_CFG_CHANGED)); |
| 4064 | return 0; |
| 4065 | } |
| 4066 | } |
| 4067 | |
| 4068 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 4069 | |
| 4070 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 4071 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 4072 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4073 | udelay(40); |
| 4074 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4075 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | tg3_init_bcm8002(tp); |
| 4077 | |
| 4078 | /* Enable link change event even when serdes polling. */ |
| 4079 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4080 | udelay(40); |
| 4081 | |
| 4082 | current_link_up = 0; |
| 4083 | mac_status = tr32(MAC_STATUS); |
| 4084 | |
| 4085 | if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) |
| 4086 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
| 4087 | else |
| 4088 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); |
| 4089 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 4090 | tp->napi[0].hw_status->status = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | (SD_STATUS_UPDATED | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 4092 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | |
| 4094 | for (i = 0; i < 100; i++) { |
| 4095 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 4096 | MAC_STATUS_CFG_CHANGED)); |
| 4097 | udelay(5); |
| 4098 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4099 | MAC_STATUS_CFG_CHANGED | |
| 4100 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | break; |
| 4102 | } |
| 4103 | |
| 4104 | mac_status = tr32(MAC_STATUS); |
| 4105 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { |
| 4106 | current_link_up = 0; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4107 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 4108 | tp->serdes_counter == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | tw32_f(MAC_MODE, (tp->mac_mode | |
| 4110 | MAC_MODE_SEND_CONFIGS)); |
| 4111 | udelay(1); |
| 4112 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | if (current_link_up == 1) { |
| 4117 | tp->link_config.active_speed = SPEED_1000; |
| 4118 | tp->link_config.active_duplex = DUPLEX_FULL; |
| 4119 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 4120 | LED_CTRL_LNKLED_OVERRIDE | |
| 4121 | LED_CTRL_1000MBPS_ON)); |
| 4122 | } else { |
| 4123 | tp->link_config.active_speed = SPEED_INVALID; |
| 4124 | tp->link_config.active_duplex = DUPLEX_INVALID; |
| 4125 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 4126 | LED_CTRL_LNKLED_OVERRIDE | |
| 4127 | LED_CTRL_TRAFFIC_OVERRIDE)); |
| 4128 | } |
| 4129 | |
| 4130 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 4131 | if (current_link_up) |
| 4132 | netif_carrier_on(tp->dev); |
| 4133 | else |
| 4134 | netif_carrier_off(tp->dev); |
| 4135 | tg3_link_report(tp); |
| 4136 | } else { |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 4137 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | if (orig_pause_cfg != now_pause_cfg || |
| 4139 | orig_active_speed != tp->link_config.active_speed || |
| 4140 | orig_active_duplex != tp->link_config.active_duplex) |
| 4141 | tg3_link_report(tp); |
| 4142 | } |
| 4143 | |
| 4144 | return 0; |
| 4145 | } |
| 4146 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4147 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
| 4148 | { |
| 4149 | int current_link_up, err = 0; |
| 4150 | u32 bmsr, bmcr; |
| 4151 | u16 current_speed; |
| 4152 | u8 current_duplex; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4153 | u32 local_adv, remote_adv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4154 | |
| 4155 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4156 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4157 | udelay(40); |
| 4158 | |
| 4159 | tw32(MAC_EVENT, 0); |
| 4160 | |
| 4161 | tw32_f(MAC_STATUS, |
| 4162 | (MAC_STATUS_SYNC_CHANGED | |
| 4163 | MAC_STATUS_CFG_CHANGED | |
| 4164 | MAC_STATUS_MI_COMPLETION | |
| 4165 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4166 | udelay(40); |
| 4167 | |
| 4168 | if (force_reset) |
| 4169 | tg3_phy_reset(tp); |
| 4170 | |
| 4171 | current_link_up = 0; |
| 4172 | current_speed = SPEED_INVALID; |
| 4173 | current_duplex = DUPLEX_INVALID; |
| 4174 | |
| 4175 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4176 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 4177 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 4178 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 4179 | bmsr |= BMSR_LSTATUS; |
| 4180 | else |
| 4181 | bmsr &= ~BMSR_LSTATUS; |
| 4182 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4183 | |
| 4184 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4185 | |
| 4186 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4187 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4188 | /* do nothing, just check for link up at the end */ |
| 4189 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 4190 | u32 adv, new_adv; |
| 4191 | |
| 4192 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 4193 | new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
| 4194 | ADVERTISE_1000XPAUSE | |
| 4195 | ADVERTISE_1000XPSE_ASYM | |
| 4196 | ADVERTISE_SLCT); |
| 4197 | |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4198 | new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4199 | |
| 4200 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) |
| 4201 | new_adv |= ADVERTISE_1000XHALF; |
| 4202 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) |
| 4203 | new_adv |= ADVERTISE_1000XFULL; |
| 4204 | |
| 4205 | if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) { |
| 4206 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 4207 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 4208 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 4209 | |
| 4210 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4211 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4212 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4213 | |
| 4214 | return err; |
| 4215 | } |
| 4216 | } else { |
| 4217 | u32 new_bmcr; |
| 4218 | |
| 4219 | bmcr &= ~BMCR_SPEED1000; |
| 4220 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4221 | |
| 4222 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 4223 | new_bmcr |= BMCR_FULLDPLX; |
| 4224 | |
| 4225 | if (new_bmcr != bmcr) { |
| 4226 | /* BMCR_SPEED1000 is a reserved bit that needs |
| 4227 | * to be set on write. |
| 4228 | */ |
| 4229 | new_bmcr |= BMCR_SPEED1000; |
| 4230 | |
| 4231 | /* Force a linkdown */ |
| 4232 | if (netif_carrier_ok(tp->dev)) { |
| 4233 | u32 adv; |
| 4234 | |
| 4235 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 4236 | adv &= ~(ADVERTISE_1000XFULL | |
| 4237 | ADVERTISE_1000XHALF | |
| 4238 | ADVERTISE_SLCT); |
| 4239 | tg3_writephy(tp, MII_ADVERTISE, adv); |
| 4240 | tg3_writephy(tp, MII_BMCR, bmcr | |
| 4241 | BMCR_ANRESTART | |
| 4242 | BMCR_ANENABLE); |
| 4243 | udelay(10); |
| 4244 | netif_carrier_off(tp->dev); |
| 4245 | } |
| 4246 | tg3_writephy(tp, MII_BMCR, new_bmcr); |
| 4247 | bmcr = new_bmcr; |
| 4248 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4249 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 4250 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 4251 | ASIC_REV_5714) { |
| 4252 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 4253 | bmsr |= BMSR_LSTATUS; |
| 4254 | else |
| 4255 | bmsr &= ~BMSR_LSTATUS; |
| 4256 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4257 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4258 | } |
| 4259 | } |
| 4260 | |
| 4261 | if (bmsr & BMSR_LSTATUS) { |
| 4262 | current_speed = SPEED_1000; |
| 4263 | current_link_up = 1; |
| 4264 | if (bmcr & BMCR_FULLDPLX) |
| 4265 | current_duplex = DUPLEX_FULL; |
| 4266 | else |
| 4267 | current_duplex = DUPLEX_HALF; |
| 4268 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4269 | local_adv = 0; |
| 4270 | remote_adv = 0; |
| 4271 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4272 | if (bmcr & BMCR_ANENABLE) { |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4273 | u32 common; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4274 | |
| 4275 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); |
| 4276 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); |
| 4277 | common = local_adv & remote_adv; |
| 4278 | if (common & (ADVERTISE_1000XHALF | |
| 4279 | ADVERTISE_1000XFULL)) { |
| 4280 | if (common & ADVERTISE_1000XFULL) |
| 4281 | current_duplex = DUPLEX_FULL; |
| 4282 | else |
| 4283 | current_duplex = DUPLEX_HALF; |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 4284 | } else if (!(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
| 4285 | /* Link is up via parallel detect */ |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4286 | } else { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4287 | current_link_up = 0; |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4288 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4289 | } |
| 4290 | } |
| 4291 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4292 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
| 4293 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4294 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4295 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 4296 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 4297 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 4298 | |
| 4299 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4300 | udelay(40); |
| 4301 | |
| 4302 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4303 | |
| 4304 | tp->link_config.active_speed = current_speed; |
| 4305 | tp->link_config.active_duplex = current_duplex; |
| 4306 | |
| 4307 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 4308 | if (current_link_up) |
| 4309 | netif_carrier_on(tp->dev); |
| 4310 | else { |
| 4311 | netif_carrier_off(tp->dev); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4312 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4313 | } |
| 4314 | tg3_link_report(tp); |
| 4315 | } |
| 4316 | return err; |
| 4317 | } |
| 4318 | |
| 4319 | static void tg3_serdes_parallel_detect(struct tg3 *tp) |
| 4320 | { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4321 | if (tp->serdes_counter) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4322 | /* Give autoneg time to complete. */ |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4323 | tp->serdes_counter--; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4324 | return; |
| 4325 | } |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 4326 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4327 | if (!netif_carrier_ok(tp->dev) && |
| 4328 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { |
| 4329 | u32 bmcr; |
| 4330 | |
| 4331 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4332 | if (bmcr & BMCR_ANENABLE) { |
| 4333 | u32 phy1, phy2; |
| 4334 | |
| 4335 | /* Select shadow register 0x1f */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4336 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
| 4337 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4338 | |
| 4339 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4340 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 4341 | MII_TG3_DSP_EXP1_INT_STAT); |
| 4342 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 4343 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4344 | |
| 4345 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { |
| 4346 | /* We have signal detect and not receiving |
| 4347 | * config code words, link is up by parallel |
| 4348 | * detection. |
| 4349 | */ |
| 4350 | |
| 4351 | bmcr &= ~BMCR_ANENABLE; |
| 4352 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; |
| 4353 | tg3_writephy(tp, MII_BMCR, bmcr); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4354 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4355 | } |
| 4356 | } |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4357 | } else if (netif_carrier_ok(tp->dev) && |
| 4358 | (tp->link_config.autoneg == AUTONEG_ENABLE) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4359 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4360 | u32 phy2; |
| 4361 | |
| 4362 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4363 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 4364 | MII_TG3_DSP_EXP1_INT_STAT); |
| 4365 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4366 | if (phy2 & 0x20) { |
| 4367 | u32 bmcr; |
| 4368 | |
| 4369 | /* Config code words received, turn on autoneg. */ |
| 4370 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4371 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); |
| 4372 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4373 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4374 | |
| 4375 | } |
| 4376 | } |
| 4377 | } |
| 4378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
| 4380 | { |
| 4381 | int err; |
| 4382 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4383 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | err = tg3_setup_fiber_phy(tp, force_reset); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4385 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4386 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4387 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | err = tg3_setup_copper_phy(tp, force_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 4390 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | aa6c91f | 2007-11-12 21:18:04 -0800 | [diff] [blame] | 4391 | u32 val, scale; |
| 4392 | |
| 4393 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; |
| 4394 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) |
| 4395 | scale = 65; |
| 4396 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) |
| 4397 | scale = 6; |
| 4398 | else |
| 4399 | scale = 12; |
| 4400 | |
| 4401 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; |
| 4402 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 4403 | tw32(GRC_MISC_CFG, val); |
| 4404 | } |
| 4405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | if (tp->link_config.active_speed == SPEED_1000 && |
| 4407 | tp->link_config.active_duplex == DUPLEX_HALF) |
| 4408 | tw32(MAC_TX_LENGTHS, |
| 4409 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 4410 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 4411 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 4412 | else |
| 4413 | tw32(MAC_TX_LENGTHS, |
| 4414 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 4415 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 4416 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 4417 | |
| 4418 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 4419 | if (netif_carrier_ok(tp->dev)) { |
| 4420 | tw32(HOSTCC_STAT_COAL_TICKS, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 4421 | tp->coal.stats_block_coalesce_usecs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | } else { |
| 4423 | tw32(HOSTCC_STAT_COAL_TICKS, 0); |
| 4424 | } |
| 4425 | } |
| 4426 | |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 4427 | if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) { |
| 4428 | u32 val = tr32(PCIE_PWR_MGMT_THRESH); |
| 4429 | if (!netif_carrier_ok(tp->dev)) |
| 4430 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
| 4431 | tp->pwrmgmt_thresh; |
| 4432 | else |
| 4433 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 4434 | tw32(PCIE_PWR_MGMT_THRESH, val); |
| 4435 | } |
| 4436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | return err; |
| 4438 | } |
| 4439 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 4440 | static inline int tg3_irq_sync(struct tg3 *tp) |
| 4441 | { |
| 4442 | return tp->irq_sync; |
| 4443 | } |
| 4444 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4445 | /* This is called whenever we suspect that the system chipset is re- |
| 4446 | * ordering the sequence of MMIO to the tx send mailbox. The symptom |
| 4447 | * is bogus tx completions. We try to recover by setting the |
| 4448 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later |
| 4449 | * in the workqueue. |
| 4450 | */ |
| 4451 | static void tg3_tx_recover(struct tg3 *tp) |
| 4452 | { |
| 4453 | BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) || |
| 4454 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
| 4455 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 4456 | netdev_warn(tp->dev, |
| 4457 | "The system may be re-ordering memory-mapped I/O " |
| 4458 | "cycles to the network device, attempting to recover. " |
| 4459 | "Please report the problem to the driver maintainer " |
| 4460 | "and include system chipset information.\n"); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4461 | |
| 4462 | spin_lock(&tp->lock); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4463 | tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4464 | spin_unlock(&tp->lock); |
| 4465 | } |
| 4466 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4467 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4468 | { |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 4469 | /* Tell compiler to fetch tx indices from memory. */ |
| 4470 | barrier(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4471 | return tnapi->tx_pending - |
| 4472 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4473 | } |
| 4474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | /* Tigon3 never reports partial packet sends. So we do not |
| 4476 | * need special logic to handle SKBs that have not had all |
| 4477 | * of their frags sent yet, like SunGEM does. |
| 4478 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4479 | static void tg3_tx(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4481 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 4482 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4483 | u32 sw_idx = tnapi->tx_cons; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4484 | struct netdev_queue *txq; |
| 4485 | int index = tnapi - tp->napi; |
| 4486 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 4487 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4488 | index--; |
| 4489 | |
| 4490 | txq = netdev_get_tx_queue(tp->dev, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | |
| 4492 | while (sw_idx != hw_idx) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4493 | struct ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | struct sk_buff *skb = ri->skb; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4495 | int i, tx_bug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4497 | if (unlikely(skb == NULL)) { |
| 4498 | tg3_tx_recover(tp); |
| 4499 | return; |
| 4500 | } |
| 4501 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4502 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4503 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4504 | skb_headlen(skb), |
| 4505 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | |
| 4507 | ri->skb = NULL; |
| 4508 | |
| 4509 | sw_idx = NEXT_TX(sw_idx); |
| 4510 | |
| 4511 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4512 | ri = &tnapi->tx_buffers[sw_idx]; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4513 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
| 4514 | tx_bug = 1; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4515 | |
| 4516 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4517 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4518 | skb_shinfo(skb)->frags[i].size, |
| 4519 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | sw_idx = NEXT_TX(sw_idx); |
| 4521 | } |
| 4522 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 4523 | dev_kfree_skb(skb); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4524 | |
| 4525 | if (unlikely(tx_bug)) { |
| 4526 | tg3_tx_recover(tp); |
| 4527 | return; |
| 4528 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | } |
| 4530 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4531 | tnapi->tx_cons = sw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4533 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
| 4534 | * before checking for netif_queue_stopped(). Without the |
| 4535 | * memory barrier, there is a small possibility that tg3_start_xmit() |
| 4536 | * will miss it and cause the queue to be stopped forever. |
| 4537 | */ |
| 4538 | smp_mb(); |
| 4539 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4540 | if (unlikely(netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4541 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4542 | __netif_tx_lock(txq, smp_processor_id()); |
| 4543 | if (netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4544 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4545 | netif_tx_wake_queue(txq); |
| 4546 | __netif_tx_unlock(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 4547 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | } |
| 4549 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 4550 | static void tg3_rx_skb_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
| 4551 | { |
| 4552 | if (!ri->skb) |
| 4553 | return; |
| 4554 | |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4555 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 4556 | map_sz, PCI_DMA_FROMDEVICE); |
| 4557 | dev_kfree_skb_any(ri->skb); |
| 4558 | ri->skb = NULL; |
| 4559 | } |
| 4560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | /* Returns size of skb allocated or < 0 on error. |
| 4562 | * |
| 4563 | * We only need to fill in the address because the other members |
| 4564 | * of the RX descriptor are invariant, see tg3_init_rings. |
| 4565 | * |
| 4566 | * Note the purposeful assymetry of cpu vs. chip accesses. For |
| 4567 | * posting buffers we only dirty the first cache line of the RX |
| 4568 | * descriptor (containing the address). Whereas for the RX status |
| 4569 | * buffers the cpu only reads the last cacheline of the RX descriptor |
| 4570 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). |
| 4571 | */ |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 4572 | static int tg3_alloc_rx_skb(struct tg3 *tp, struct tg3_rx_prodring_set *tpr, |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4573 | u32 opaque_key, u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | { |
| 4575 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | f94e290 | 2010-10-14 10:37:42 +0000 | [diff] [blame] | 4576 | struct ring_info *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | struct sk_buff *skb; |
| 4578 | dma_addr_t mapping; |
| 4579 | int skb_size, dest_idx; |
| 4580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | switch (opaque_key) { |
| 4582 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4583 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4584 | desc = &tpr->rx_std[dest_idx]; |
| 4585 | map = &tpr->rx_std_buffers[dest_idx]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4586 | skb_size = tp->rx_pkt_map_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | break; |
| 4588 | |
| 4589 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4590 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 4591 | desc = &tpr->rx_jmb[dest_idx].std; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4592 | map = &tpr->rx_jmb_buffers[dest_idx]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4593 | skb_size = TG3_RX_JMB_MAP_SZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | break; |
| 4595 | |
| 4596 | default: |
| 4597 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4598 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4599 | |
| 4600 | /* Do not overwrite any of the map or rp information |
| 4601 | * until we are sure we can commit to a new buffer. |
| 4602 | * |
| 4603 | * Callers depend upon this behavior and assume that |
| 4604 | * we leave everything unchanged if we fail. |
| 4605 | */ |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4606 | skb = netdev_alloc_skb(tp->dev, skb_size + tp->rx_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | if (skb == NULL) |
| 4608 | return -ENOMEM; |
| 4609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4610 | skb_reserve(skb, tp->rx_offset); |
| 4611 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4612 | mapping = pci_map_single(tp->pdev, skb->data, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | PCI_DMA_FROMDEVICE); |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 4614 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
| 4615 | dev_kfree_skb(skb); |
| 4616 | return -EIO; |
| 4617 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | |
| 4619 | map->skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4620 | dma_unmap_addr_set(map, mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | desc->addr_hi = ((u64)mapping >> 32); |
| 4623 | desc->addr_lo = ((u64)mapping & 0xffffffff); |
| 4624 | |
| 4625 | return skb_size; |
| 4626 | } |
| 4627 | |
| 4628 | /* We only need to move over in the address because the other |
| 4629 | * members of the RX descriptor are invariant. See notes above |
| 4630 | * tg3_alloc_rx_skb for full details. |
| 4631 | */ |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4632 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
| 4633 | struct tg3_rx_prodring_set *dpr, |
| 4634 | u32 opaque_key, int src_idx, |
| 4635 | u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4636 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4637 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
| 4639 | struct ring_info *src_map, *dest_map; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4640 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 4641 | int dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | |
| 4643 | switch (opaque_key) { |
| 4644 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4645 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4646 | dest_desc = &dpr->rx_std[dest_idx]; |
| 4647 | dest_map = &dpr->rx_std_buffers[dest_idx]; |
| 4648 | src_desc = &spr->rx_std[src_idx]; |
| 4649 | src_map = &spr->rx_std_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4650 | break; |
| 4651 | |
| 4652 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4653 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4654 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
| 4655 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; |
| 4656 | src_desc = &spr->rx_jmb[src_idx].std; |
| 4657 | src_map = &spr->rx_jmb_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | break; |
| 4659 | |
| 4660 | default: |
| 4661 | return; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | |
| 4664 | dest_map->skb = src_map->skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4665 | dma_unmap_addr_set(dest_map, mapping, |
| 4666 | dma_unmap_addr(src_map, mapping)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4667 | dest_desc->addr_hi = src_desc->addr_hi; |
| 4668 | dest_desc->addr_lo = src_desc->addr_lo; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4669 | |
| 4670 | /* Ensure that the update to the skb happens after the physical |
| 4671 | * addresses have been transferred to the new BD location. |
| 4672 | */ |
| 4673 | smp_wmb(); |
| 4674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4675 | src_map->skb = NULL; |
| 4676 | } |
| 4677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | /* The RX ring scheme is composed of multiple rings which post fresh |
| 4679 | * buffers to the chip, and one special ring the chip uses to report |
| 4680 | * status back to the host. |
| 4681 | * |
| 4682 | * The special ring reports the status of received packets to the |
| 4683 | * host. The chip does not write into the original descriptor the |
| 4684 | * RX buffer was obtained from. The chip simply takes the original |
| 4685 | * descriptor as provided by the host, updates the status and length |
| 4686 | * field, then writes this into the next status ring entry. |
| 4687 | * |
| 4688 | * Each ring the host uses to post buffers to the chip is described |
| 4689 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, |
| 4690 | * it is first placed into the on-chip ram. When the packet's length |
| 4691 | * is known, it walks down the TG3_BDINFO entries to select the ring. |
| 4692 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO |
| 4693 | * which is within the range of the new packet's length is chosen. |
| 4694 | * |
| 4695 | * The "separate ring for rx status" scheme may sound queer, but it makes |
| 4696 | * sense from a cache coherency perspective. If only the host writes |
| 4697 | * to the buffer post rings, and only the chip writes to the rx status |
| 4698 | * rings, then cache lines never move beyond shared-modified state. |
| 4699 | * If both the host and chip were to write into the same ring, cache line |
| 4700 | * eviction could occur since both entities want it in an exclusive state. |
| 4701 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4702 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4704 | struct tg3 *tp = tnapi->tp; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4705 | u32 work_mask, rx_std_posted = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4706 | u32 std_prod_idx, jmb_prod_idx; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4707 | u32 sw_idx = tnapi->rx_rcb_ptr; |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 4708 | u16 hw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4709 | int received; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4710 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 4712 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | /* |
| 4714 | * We need to order the read of hw_idx and the read of |
| 4715 | * the opaque cookie. |
| 4716 | */ |
| 4717 | rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4718 | work_mask = 0; |
| 4719 | received = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4720 | std_prod_idx = tpr->rx_std_prod_idx; |
| 4721 | jmb_prod_idx = tpr->rx_jmb_prod_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | while (sw_idx != hw_idx && budget > 0) { |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 4723 | struct ring_info *ri; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4724 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | unsigned int len; |
| 4726 | struct sk_buff *skb; |
| 4727 | dma_addr_t dma_addr; |
| 4728 | u32 opaque_key, desc_idx, *post_ptr; |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4729 | bool hw_vlan __maybe_unused = false; |
| 4730 | u16 vtag __maybe_unused = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4731 | |
| 4732 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 4733 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 4734 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4735 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4736 | dma_addr = dma_unmap_addr(ri, mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4737 | skb = ri->skb; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4738 | post_ptr = &std_prod_idx; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4739 | rx_std_posted++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4741 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4742 | dma_addr = dma_unmap_addr(ri, mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4743 | skb = ri->skb; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4744 | post_ptr = &jmb_prod_idx; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4745 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4746 | goto next_pkt_nopost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | |
| 4748 | work_mask |= opaque_key; |
| 4749 | |
| 4750 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 4751 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { |
| 4752 | drop_it: |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4753 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | desc_idx, *post_ptr); |
| 4755 | drop_it_no_recycle: |
| 4756 | /* Other statistics kept track of by card. */ |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 4757 | tp->rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | goto next_pkt; |
| 4759 | } |
| 4760 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 4761 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
| 4762 | ETH_FCS_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 4764 | if (len > TG3_RX_COPY_THRESH(tp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | int skb_size; |
| 4766 | |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 4767 | skb_size = tg3_alloc_rx_skb(tp, tpr, opaque_key, |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 4768 | *post_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | if (skb_size < 0) |
| 4770 | goto drop_it; |
| 4771 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4772 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | PCI_DMA_FROMDEVICE); |
| 4774 | |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 4775 | /* Ensure that the update to the skb happens |
| 4776 | * after the usage of the old DMA mapping. |
| 4777 | */ |
| 4778 | smp_wmb(); |
| 4779 | |
| 4780 | ri->skb = NULL; |
| 4781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | skb_put(skb, len); |
| 4783 | } else { |
| 4784 | struct sk_buff *copy_skb; |
| 4785 | |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4786 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4787 | desc_idx, *post_ptr); |
| 4788 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4789 | copy_skb = netdev_alloc_skb(tp->dev, len + VLAN_HLEN + |
| 4790 | TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | if (copy_skb == NULL) |
| 4792 | goto drop_it_no_recycle; |
| 4793 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4794 | skb_reserve(copy_skb, TG3_RAW_IP_ALIGN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4795 | skb_put(copy_skb, len); |
| 4796 | pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 4797 | skb_copy_from_linear_data(skb, copy_skb->data, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
| 4799 | |
| 4800 | /* We'll reuse the original ring buffer. */ |
| 4801 | skb = copy_skb; |
| 4802 | } |
| 4803 | |
| 4804 | if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) && |
| 4805 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 4806 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 4807 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) |
| 4808 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 4809 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 4810 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | |
| 4812 | skb->protocol = eth_type_trans(skb, tp->dev); |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 4813 | |
| 4814 | if (len > (tp->dev->mtu + ETH_HLEN) && |
| 4815 | skb->protocol != htons(ETH_P_8021Q)) { |
| 4816 | dev_kfree_skb(skb); |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 4817 | goto drop_it_no_recycle; |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 4818 | } |
| 4819 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4820 | if (desc->type_flags & RXD_FLAG_VLAN && |
| 4821 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) { |
| 4822 | vtag = desc->err_vlan & RXD_VLAN_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | #if TG3_VLAN_TAG_USED |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4824 | if (tp->vlgrp) |
| 4825 | hw_vlan = true; |
| 4826 | else |
| 4827 | #endif |
| 4828 | { |
| 4829 | struct vlan_ethhdr *ve = (struct vlan_ethhdr *) |
| 4830 | __skb_push(skb, VLAN_HLEN); |
| 4831 | |
| 4832 | memmove(ve, skb->data + VLAN_HLEN, |
| 4833 | ETH_ALEN * 2); |
| 4834 | ve->h_vlan_proto = htons(ETH_P_8021Q); |
| 4835 | ve->h_vlan_TCI = htons(vtag); |
| 4836 | } |
| 4837 | } |
| 4838 | |
| 4839 | #if TG3_VLAN_TAG_USED |
| 4840 | if (hw_vlan) |
| 4841 | vlan_gro_receive(&tnapi->napi, tp->vlgrp, vtag, skb); |
| 4842 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4843 | #endif |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4844 | napi_gro_receive(&tnapi->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | received++; |
| 4847 | budget--; |
| 4848 | |
| 4849 | next_pkt: |
| 4850 | (*post_ptr)++; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4851 | |
| 4852 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4853 | tpr->rx_std_prod_idx = std_prod_idx & |
| 4854 | tp->rx_std_ring_mask; |
Matt Carlson | 86cfe4f | 2010-01-12 10:11:37 +0000 | [diff] [blame] | 4855 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 4856 | tpr->rx_std_prod_idx); |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4857 | work_mask &= ~RXD_OPAQUE_RING_STD; |
| 4858 | rx_std_posted = 0; |
| 4859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | next_pkt_nopost: |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 4861 | sw_idx++; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 4862 | sw_idx &= tp->rx_ret_ring_mask; |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 4863 | |
| 4864 | /* Refresh hw_idx to see if there is new work */ |
| 4865 | if (sw_idx == hw_idx) { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 4866 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 4867 | rmb(); |
| 4868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | /* ACK the status ring. */ |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4872 | tnapi->rx_rcb_ptr = sw_idx; |
| 4873 | tw32_rx_mbox(tnapi->consmbox, sw_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | |
| 4875 | /* Refill RX ring(s). */ |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4876 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4877 | if (work_mask & RXD_OPAQUE_RING_STD) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4878 | tpr->rx_std_prod_idx = std_prod_idx & |
| 4879 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4880 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 4881 | tpr->rx_std_prod_idx); |
| 4882 | } |
| 4883 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4884 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
| 4885 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4886 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 4887 | tpr->rx_jmb_prod_idx); |
| 4888 | } |
| 4889 | mmiowb(); |
| 4890 | } else if (work_mask) { |
| 4891 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be |
| 4892 | * updated before the producer indices can be updated. |
| 4893 | */ |
| 4894 | smp_wmb(); |
| 4895 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4896 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
| 4897 | 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] | 4898 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4899 | if (tnapi != &tp->napi[1]) |
| 4900 | napi_schedule(&tp->napi[1].napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | |
| 4903 | return received; |
| 4904 | } |
| 4905 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4906 | static void tg3_poll_link(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | /* handle link change and other phy events */ |
| 4909 | if (!(tp->tg3_flags & |
| 4910 | (TG3_FLAG_USE_LINKCHG_REG | |
| 4911 | TG3_FLAG_POLL_SERDES))) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4912 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
| 4913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | if (sblk->status & SD_STATUS_LINK_CHG) { |
| 4915 | sblk->status = SD_STATUS_UPDATED | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4916 | (sblk->status & ~SD_STATUS_LINK_CHG); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 4917 | spin_lock(&tp->lock); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 4918 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
| 4919 | tw32_f(MAC_STATUS, |
| 4920 | (MAC_STATUS_SYNC_CHANGED | |
| 4921 | MAC_STATUS_CFG_CHANGED | |
| 4922 | MAC_STATUS_MI_COMPLETION | |
| 4923 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4924 | udelay(40); |
| 4925 | } else |
| 4926 | tg3_setup_phy(tp, 0); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 4927 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | } |
| 4929 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4930 | } |
| 4931 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4932 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
| 4933 | struct tg3_rx_prodring_set *dpr, |
| 4934 | struct tg3_rx_prodring_set *spr) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4935 | { |
| 4936 | u32 si, di, cpycnt, src_prod_idx; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4937 | int i, err = 0; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4938 | |
| 4939 | while (1) { |
| 4940 | src_prod_idx = spr->rx_std_prod_idx; |
| 4941 | |
| 4942 | /* Make sure updates to the rx_std_buffers[] entries and the |
| 4943 | * standard producer index are seen in the correct order. |
| 4944 | */ |
| 4945 | smp_rmb(); |
| 4946 | |
| 4947 | if (spr->rx_std_cons_idx == src_prod_idx) |
| 4948 | break; |
| 4949 | |
| 4950 | if (spr->rx_std_cons_idx < src_prod_idx) |
| 4951 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; |
| 4952 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4953 | cpycnt = tp->rx_std_ring_mask + 1 - |
| 4954 | spr->rx_std_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4955 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4956 | cpycnt = min(cpycnt, |
| 4957 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4958 | |
| 4959 | si = spr->rx_std_cons_idx; |
| 4960 | di = dpr->rx_std_prod_idx; |
| 4961 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4962 | for (i = di; i < di + cpycnt; i++) { |
| 4963 | if (dpr->rx_std_buffers[i].skb) { |
| 4964 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4965 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4966 | break; |
| 4967 | } |
| 4968 | } |
| 4969 | |
| 4970 | if (!cpycnt) |
| 4971 | break; |
| 4972 | |
| 4973 | /* Ensure that updates to the rx_std_buffers ring and the |
| 4974 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 4975 | * ordered correctly WRT the skb check above. |
| 4976 | */ |
| 4977 | smp_rmb(); |
| 4978 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4979 | memcpy(&dpr->rx_std_buffers[di], |
| 4980 | &spr->rx_std_buffers[si], |
| 4981 | cpycnt * sizeof(struct ring_info)); |
| 4982 | |
| 4983 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 4984 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 4985 | sbd = &spr->rx_std[si]; |
| 4986 | dbd = &dpr->rx_std[di]; |
| 4987 | dbd->addr_hi = sbd->addr_hi; |
| 4988 | dbd->addr_lo = sbd->addr_lo; |
| 4989 | } |
| 4990 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4991 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
| 4992 | tp->rx_std_ring_mask; |
| 4993 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & |
| 4994 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4995 | } |
| 4996 | |
| 4997 | while (1) { |
| 4998 | src_prod_idx = spr->rx_jmb_prod_idx; |
| 4999 | |
| 5000 | /* Make sure updates to the rx_jmb_buffers[] entries and |
| 5001 | * the jumbo producer index are seen in the correct order. |
| 5002 | */ |
| 5003 | smp_rmb(); |
| 5004 | |
| 5005 | if (spr->rx_jmb_cons_idx == src_prod_idx) |
| 5006 | break; |
| 5007 | |
| 5008 | if (spr->rx_jmb_cons_idx < src_prod_idx) |
| 5009 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; |
| 5010 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5011 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
| 5012 | spr->rx_jmb_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5013 | |
| 5014 | cpycnt = min(cpycnt, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5015 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5016 | |
| 5017 | si = spr->rx_jmb_cons_idx; |
| 5018 | di = dpr->rx_jmb_prod_idx; |
| 5019 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5020 | for (i = di; i < di + cpycnt; i++) { |
| 5021 | if (dpr->rx_jmb_buffers[i].skb) { |
| 5022 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5023 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5024 | break; |
| 5025 | } |
| 5026 | } |
| 5027 | |
| 5028 | if (!cpycnt) |
| 5029 | break; |
| 5030 | |
| 5031 | /* Ensure that updates to the rx_jmb_buffers ring and the |
| 5032 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 5033 | * ordered correctly WRT the skb check above. |
| 5034 | */ |
| 5035 | smp_rmb(); |
| 5036 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5037 | memcpy(&dpr->rx_jmb_buffers[di], |
| 5038 | &spr->rx_jmb_buffers[si], |
| 5039 | cpycnt * sizeof(struct ring_info)); |
| 5040 | |
| 5041 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 5042 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 5043 | sbd = &spr->rx_jmb[si].std; |
| 5044 | dbd = &dpr->rx_jmb[di].std; |
| 5045 | dbd->addr_hi = sbd->addr_hi; |
| 5046 | dbd->addr_lo = sbd->addr_lo; |
| 5047 | } |
| 5048 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5049 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
| 5050 | tp->rx_jmb_ring_mask; |
| 5051 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & |
| 5052 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5053 | } |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5054 | |
| 5055 | return err; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5056 | } |
| 5057 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5058 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
| 5059 | { |
| 5060 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5061 | |
| 5062 | /* run TX completion thread */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5063 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5064 | tg3_tx(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5065 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5066 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | } |
| 5068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | /* run RX thread, within the bounds set by NAPI. |
| 5070 | * All RX "locking" is done by ensuring outside |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5071 | * code synchronizes with tg3->napi.poll() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5072 | */ |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 5073 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5074 | work_done += tg3_rx(tnapi, budget - work_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5075 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5076 | if ((tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) && tnapi == &tp->napi[1]) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5077 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5078 | int i, err = 0; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5079 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
| 5080 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5081 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5082 | for (i = 1; i < tp->irq_cnt; i++) |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5083 | err |= tg3_rx_prodring_xfer(tp, dpr, |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5084 | &tp->napi[i].prodring); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5085 | |
| 5086 | wmb(); |
| 5087 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5088 | if (std_prod_idx != dpr->rx_std_prod_idx) |
| 5089 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 5090 | dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5091 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5092 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
| 5093 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 5094 | dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5095 | |
| 5096 | mmiowb(); |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5097 | |
| 5098 | if (err) |
| 5099 | tw32_f(HOSTCC_MODE, tp->coal_now); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5100 | } |
| 5101 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5102 | return work_done; |
| 5103 | } |
David S. Miller | f7383c2 | 2005-05-18 22:50:53 -0700 | [diff] [blame] | 5104 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5105 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
| 5106 | { |
| 5107 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 5108 | struct tg3 *tp = tnapi->tp; |
| 5109 | int work_done = 0; |
| 5110 | struct tg3_hw_status *sblk = tnapi->hw_status; |
| 5111 | |
| 5112 | while (1) { |
| 5113 | work_done = tg3_poll_work(tnapi, work_done, budget); |
| 5114 | |
| 5115 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) |
| 5116 | goto tx_recovery; |
| 5117 | |
| 5118 | if (unlikely(work_done >= budget)) |
| 5119 | break; |
| 5120 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5121 | /* tp->last_tag is used in tg3_int_reenable() below |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5122 | * to tell the hw how much work has been processed, |
| 5123 | * so we must read it before checking for more work. |
| 5124 | */ |
| 5125 | tnapi->last_tag = sblk->status_tag; |
| 5126 | tnapi->last_irq_tag = tnapi->last_tag; |
| 5127 | rmb(); |
| 5128 | |
| 5129 | /* check for RX/TX work to do */ |
Matt Carlson | 6d40db7 | 2010-04-05 10:19:20 +0000 | [diff] [blame] | 5130 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
| 5131 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5132 | napi_complete(napi); |
| 5133 | /* Reenable interrupts. */ |
| 5134 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
| 5135 | mmiowb(); |
| 5136 | break; |
| 5137 | } |
| 5138 | } |
| 5139 | |
| 5140 | return work_done; |
| 5141 | |
| 5142 | tx_recovery: |
| 5143 | /* work_done is guaranteed to be less than budget. */ |
| 5144 | napi_complete(napi); |
| 5145 | schedule_work(&tp->reset_task); |
| 5146 | return work_done; |
| 5147 | } |
| 5148 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5149 | static int tg3_poll(struct napi_struct *napi, int budget) |
| 5150 | { |
Matt Carlson | 8ef0442 | 2009-08-28 14:01:37 +0000 | [diff] [blame] | 5151 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 5152 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5153 | int work_done = 0; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5154 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5155 | |
| 5156 | while (1) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5157 | tg3_poll_link(tp); |
| 5158 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5159 | work_done = tg3_poll_work(tnapi, work_done, budget); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5160 | |
| 5161 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) |
| 5162 | goto tx_recovery; |
| 5163 | |
| 5164 | if (unlikely(work_done >= budget)) |
| 5165 | break; |
| 5166 | |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5167 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5168 | /* tp->last_tag is used in tg3_int_reenable() below |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5169 | * to tell the hw how much work has been processed, |
| 5170 | * so we must read it before checking for more work. |
| 5171 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5172 | tnapi->last_tag = sblk->status_tag; |
| 5173 | tnapi->last_irq_tag = tnapi->last_tag; |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5174 | rmb(); |
| 5175 | } else |
| 5176 | sblk->status &= ~SD_STATUS_UPDATED; |
| 5177 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5178 | if (likely(!tg3_has_work(tnapi))) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5179 | napi_complete(napi); |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5180 | tg3_int_reenable(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5181 | break; |
| 5182 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5183 | } |
| 5184 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5185 | return work_done; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5186 | |
| 5187 | tx_recovery: |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5188 | /* work_done is guaranteed to be less than budget. */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5189 | napi_complete(napi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5190 | schedule_work(&tp->reset_task); |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5191 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5192 | } |
| 5193 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 5194 | static void tg3_napi_disable(struct tg3 *tp) |
| 5195 | { |
| 5196 | int i; |
| 5197 | |
| 5198 | for (i = tp->irq_cnt - 1; i >= 0; i--) |
| 5199 | napi_disable(&tp->napi[i].napi); |
| 5200 | } |
| 5201 | |
| 5202 | static void tg3_napi_enable(struct tg3 *tp) |
| 5203 | { |
| 5204 | int i; |
| 5205 | |
| 5206 | for (i = 0; i < tp->irq_cnt; i++) |
| 5207 | napi_enable(&tp->napi[i].napi); |
| 5208 | } |
| 5209 | |
| 5210 | static void tg3_napi_init(struct tg3 *tp) |
| 5211 | { |
| 5212 | int i; |
| 5213 | |
| 5214 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); |
| 5215 | for (i = 1; i < tp->irq_cnt; i++) |
| 5216 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); |
| 5217 | } |
| 5218 | |
| 5219 | static void tg3_napi_fini(struct tg3 *tp) |
| 5220 | { |
| 5221 | int i; |
| 5222 | |
| 5223 | for (i = 0; i < tp->irq_cnt; i++) |
| 5224 | netif_napi_del(&tp->napi[i].napi); |
| 5225 | } |
| 5226 | |
| 5227 | static inline void tg3_netif_stop(struct tg3 *tp) |
| 5228 | { |
| 5229 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 5230 | tg3_napi_disable(tp); |
| 5231 | netif_tx_disable(tp->dev); |
| 5232 | } |
| 5233 | |
| 5234 | static inline void tg3_netif_start(struct tg3 *tp) |
| 5235 | { |
| 5236 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
| 5237 | * appropriate so long as all callers are assured to |
| 5238 | * have free tx slots (such as after tg3_init_hw) |
| 5239 | */ |
| 5240 | netif_tx_wake_all_queues(tp->dev); |
| 5241 | |
| 5242 | tg3_napi_enable(tp); |
| 5243 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; |
| 5244 | tg3_enable_ints(tp); |
| 5245 | } |
| 5246 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5247 | static void tg3_irq_quiesce(struct tg3 *tp) |
| 5248 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5249 | int i; |
| 5250 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5251 | BUG_ON(tp->irq_sync); |
| 5252 | |
| 5253 | tp->irq_sync = 1; |
| 5254 | smp_mb(); |
| 5255 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5256 | for (i = 0; i < tp->irq_cnt; i++) |
| 5257 | synchronize_irq(tp->napi[i].irq_vec); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5258 | } |
| 5259 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5260 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
| 5261 | * If irq_sync is non-zero, then the IRQ handler must be synchronized |
| 5262 | * with as well. Most of the time, this is not necessary except when |
| 5263 | * shutting down the device. |
| 5264 | */ |
| 5265 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) |
| 5266 | { |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 5267 | spin_lock_bh(&tp->lock); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5268 | if (irq_sync) |
| 5269 | tg3_irq_quiesce(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5270 | } |
| 5271 | |
| 5272 | static inline void tg3_full_unlock(struct tg3 *tp) |
| 5273 | { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5274 | spin_unlock_bh(&tp->lock); |
| 5275 | } |
| 5276 | |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5277 | /* One-shot MSI handler - Chip automatically disables interrupt |
| 5278 | * after sending MSI so driver doesn't have to do it. |
| 5279 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5280 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5281 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5282 | struct tg3_napi *tnapi = dev_id; |
| 5283 | struct tg3 *tp = tnapi->tp; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5284 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5285 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 5286 | if (tnapi->rx_rcb) |
| 5287 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5288 | |
| 5289 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5290 | napi_schedule(&tnapi->napi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5291 | |
| 5292 | return IRQ_HANDLED; |
| 5293 | } |
| 5294 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5295 | /* MSI ISR - No need to check for interrupt sharing and no need to |
| 5296 | * flush status block and interrupt mailbox. PCI ordering rules |
| 5297 | * guarantee that MSI will arrive after the status block. |
| 5298 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5299 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5300 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5301 | struct tg3_napi *tnapi = dev_id; |
| 5302 | struct tg3 *tp = tnapi->tp; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5303 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5304 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 5305 | if (tnapi->rx_rcb) |
| 5306 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5307 | /* |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5308 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5309 | * chip-internal interrupt pending events. |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5310 | * Writing non-zero to intr-mbox-0 additional tells the |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5311 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5312 | * event coalescing. |
| 5313 | */ |
| 5314 | tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 5315 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5316 | napi_schedule(&tnapi->napi); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 5317 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5318 | return IRQ_RETVAL(1); |
| 5319 | } |
| 5320 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5321 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5322 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5323 | struct tg3_napi *tnapi = dev_id; |
| 5324 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5325 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | unsigned int handled = 1; |
| 5327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5328 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 5329 | * the CPU before the status block posted prior to the interrupt. |
| 5330 | * Reading the PCI State register will confirm whether the |
| 5331 | * interrupt is ours and will flush the status block. |
| 5332 | */ |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5333 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
| 5334 | if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) || |
| 5335 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 5336 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5337 | goto out; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5338 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5339 | } |
| 5340 | |
| 5341 | /* |
| 5342 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
| 5343 | * chip-internal interrupt pending events. |
| 5344 | * Writing non-zero to intr-mbox-0 additional tells the |
| 5345 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5346 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5347 | * |
| 5348 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 5349 | * spurious interrupts. The flush impacts performance but |
| 5350 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5351 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5352 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5353 | if (tg3_irq_sync(tp)) |
| 5354 | goto out; |
| 5355 | sblk->status &= ~SD_STATUS_UPDATED; |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5356 | if (likely(tg3_has_work(tnapi))) { |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5357 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5358 | napi_schedule(&tnapi->napi); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5359 | } else { |
| 5360 | /* No work, shared interrupt perhaps? re-enable |
| 5361 | * interrupts, and flush that PCI write |
| 5362 | */ |
| 5363 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, |
| 5364 | 0x00000000); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5365 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5366 | out: |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5367 | return IRQ_RETVAL(handled); |
| 5368 | } |
| 5369 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5370 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5371 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5372 | struct tg3_napi *tnapi = dev_id; |
| 5373 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5374 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5375 | unsigned int handled = 1; |
| 5376 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5377 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 5378 | * the CPU before the status block posted prior to the interrupt. |
| 5379 | * Reading the PCI State register will confirm whether the |
| 5380 | * interrupt is ours and will flush the status block. |
| 5381 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5382 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5383 | if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) || |
| 5384 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 5385 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5386 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5387 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | /* |
| 5391 | * writing any value to intr-mbox-0 clears PCI INTA# and |
| 5392 | * chip-internal interrupt pending events. |
| 5393 | * writing non-zero to intr-mbox-0 additional tells the |
| 5394 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5395 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5396 | * |
| 5397 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 5398 | * spurious interrupts. The flush impacts performance but |
| 5399 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5400 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5401 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5402 | |
| 5403 | /* |
| 5404 | * In a shared interrupt configuration, sometimes other devices' |
| 5405 | * interrupts will scream. We record the current status tag here |
| 5406 | * so that the above check can report that the screaming interrupts |
| 5407 | * are unhandled. Eventually they will be silenced. |
| 5408 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5409 | tnapi->last_irq_tag = sblk->status_tag; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5410 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5411 | if (tg3_irq_sync(tp)) |
| 5412 | goto out; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5413 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5414 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5415 | |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5416 | napi_schedule(&tnapi->napi); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5417 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5418 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5419 | return IRQ_RETVAL(handled); |
| 5420 | } |
| 5421 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5422 | /* ISR for interrupt test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5423 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5424 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5425 | struct tg3_napi *tnapi = dev_id; |
| 5426 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5427 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5428 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 5429 | if ((sblk->status & SD_STATUS_UPDATED) || |
| 5430 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 5431 | tg3_disable_ints(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5432 | return IRQ_RETVAL(1); |
| 5433 | } |
| 5434 | return IRQ_RETVAL(0); |
| 5435 | } |
| 5436 | |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 5437 | static int tg3_init_hw(struct tg3 *, int); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 5438 | static int tg3_halt(struct tg3 *, int, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5439 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5440 | /* Restart hardware after configuration changes, self-test, etc. |
| 5441 | * Invoked with tp->lock held. |
| 5442 | */ |
| 5443 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) |
Eric Dumazet | 78c6146 | 2008-04-24 23:33:06 -0700 | [diff] [blame] | 5444 | __releases(tp->lock) |
| 5445 | __acquires(tp->lock) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5446 | { |
| 5447 | int err; |
| 5448 | |
| 5449 | err = tg3_init_hw(tp, reset_phy); |
| 5450 | if (err) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5451 | netdev_err(tp->dev, |
| 5452 | "Failed to re-initialize device, aborting\n"); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5453 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 5454 | tg3_full_unlock(tp); |
| 5455 | del_timer_sync(&tp->timer); |
| 5456 | tp->irq_sync = 0; |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 5457 | tg3_napi_enable(tp); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5458 | dev_close(tp->dev); |
| 5459 | tg3_full_lock(tp, 0); |
| 5460 | } |
| 5461 | return err; |
| 5462 | } |
| 5463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5465 | static void tg3_poll_controller(struct net_device *dev) |
| 5466 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5467 | int i; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5468 | struct tg3 *tp = netdev_priv(dev); |
| 5469 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5470 | for (i = 0; i < tp->irq_cnt; i++) |
Louis Rilling | fe234f0 | 2010-03-09 06:14:41 +0000 | [diff] [blame] | 5471 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5472 | } |
| 5473 | #endif |
| 5474 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5475 | static void tg3_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5476 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5477 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5478 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | unsigned int restart_timer; |
| 5480 | |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5481 | tg3_full_lock(tp, 0); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5482 | |
| 5483 | if (!netif_running(tp->dev)) { |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5484 | tg3_full_unlock(tp); |
| 5485 | return; |
| 5486 | } |
| 5487 | |
| 5488 | tg3_full_unlock(tp); |
| 5489 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5490 | tg3_phy_stop(tp); |
| 5491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | tg3_netif_stop(tp); |
| 5493 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5494 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5495 | |
| 5496 | restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER; |
| 5497 | tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER; |
| 5498 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5499 | if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) { |
| 5500 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 5501 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 5502 | tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER; |
| 5503 | tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING; |
| 5504 | } |
| 5505 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 5506 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5507 | err = tg3_init_hw(tp, 1); |
| 5508 | if (err) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5509 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5510 | |
| 5511 | tg3_netif_start(tp); |
| 5512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5513 | if (restart_timer) |
| 5514 | mod_timer(&tp->timer, jiffies + 1); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5515 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5516 | out: |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5517 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5518 | |
| 5519 | if (!err) |
| 5520 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5521 | } |
| 5522 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5523 | static void tg3_dump_short_state(struct tg3 *tp) |
| 5524 | { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 5525 | netdev_err(tp->dev, "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n", |
| 5526 | tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS)); |
| 5527 | netdev_err(tp->dev, "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n", |
| 5528 | tr32(RDMAC_STATUS), tr32(WDMAC_STATUS)); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5529 | } |
| 5530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | static void tg3_tx_timeout(struct net_device *dev) |
| 5532 | { |
| 5533 | struct tg3 *tp = netdev_priv(dev); |
| 5534 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5535 | if (netif_msg_tx_err(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 5536 | netdev_err(dev, "transmit timed out, resetting\n"); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5537 | tg3_dump_short_state(tp); |
| 5538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | |
| 5540 | schedule_work(&tp->reset_task); |
| 5541 | } |
| 5542 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5543 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
| 5544 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) |
| 5545 | { |
| 5546 | u32 base = (u32) mapping & 0xffffffff; |
| 5547 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 5548 | return (base > 0xffffdcc0) && (base + len + 8 < base); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5549 | } |
| 5550 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5551 | /* Test for DMA addresses > 40-bit */ |
| 5552 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 5553 | int len) |
| 5554 | { |
| 5555 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) |
Michael Chan | 6728a8e | 2006-03-27 23:16:49 -0800 | [diff] [blame] | 5556 | if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 5557 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5558 | return 0; |
| 5559 | #else |
| 5560 | return 0; |
| 5561 | #endif |
| 5562 | } |
| 5563 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5564 | static void tg3_set_txd(struct tg3_napi *, int, dma_addr_t, int, u32, u32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5565 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5566 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5567 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
| 5568 | struct sk_buff *skb, u32 last_plus_one, |
| 5569 | u32 *start, u32 base_flags, u32 mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5570 | { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5571 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 5572 | struct sk_buff *new_skb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5573 | dma_addr_t new_addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5574 | u32 entry = *start; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5575 | int i, ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5576 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 5577 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 5578 | new_skb = skb_copy(skb, GFP_ATOMIC); |
| 5579 | else { |
| 5580 | int more_headroom = 4 - ((unsigned long)skb->data & 3); |
| 5581 | |
| 5582 | new_skb = skb_copy_expand(skb, |
| 5583 | skb_headroom(skb) + more_headroom, |
| 5584 | skb_tailroom(skb), GFP_ATOMIC); |
| 5585 | } |
| 5586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | if (!new_skb) { |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5588 | ret = -1; |
| 5589 | } else { |
| 5590 | /* New SKB is guaranteed to be linear. */ |
| 5591 | entry = *start; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5592 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
| 5593 | PCI_DMA_TODEVICE); |
| 5594 | /* Make sure the mapping succeeded */ |
| 5595 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { |
| 5596 | ret = -1; |
| 5597 | dev_kfree_skb(new_skb); |
| 5598 | new_skb = NULL; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5599 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5600 | /* Make sure new skb does not cross any 4G boundaries. |
| 5601 | * Drop the packet if it does. |
| 5602 | */ |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5603 | } else if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
| 5604 | tg3_4g_overflow_test(new_addr, new_skb->len)) { |
| 5605 | pci_unmap_single(tp->pdev, new_addr, new_skb->len, |
| 5606 | PCI_DMA_TODEVICE); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5607 | ret = -1; |
| 5608 | dev_kfree_skb(new_skb); |
| 5609 | new_skb = NULL; |
| 5610 | } else { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5611 | tg3_set_txd(tnapi, entry, new_addr, new_skb->len, |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5612 | base_flags, 1 | (mss << 1)); |
| 5613 | *start = NEXT_TX(entry); |
| 5614 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5615 | } |
| 5616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | /* Now clean up the sw ring entries. */ |
| 5618 | i = 0; |
| 5619 | while (entry != last_plus_one) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5620 | int len; |
| 5621 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5622 | if (i == 0) |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5623 | len = skb_headlen(skb); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5624 | else |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5625 | len = skb_shinfo(skb)->frags[i-1].size; |
| 5626 | |
| 5627 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5628 | dma_unmap_addr(&tnapi->tx_buffers[entry], |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5629 | mapping), |
| 5630 | len, PCI_DMA_TODEVICE); |
| 5631 | if (i == 0) { |
| 5632 | tnapi->tx_buffers[entry].skb = new_skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5633 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5634 | new_addr); |
| 5635 | } else { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5636 | tnapi->tx_buffers[entry].skb = NULL; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5638 | entry = NEXT_TX(entry); |
| 5639 | i++; |
| 5640 | } |
| 5641 | |
| 5642 | dev_kfree_skb(skb); |
| 5643 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5644 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5645 | } |
| 5646 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5647 | static void tg3_set_txd(struct tg3_napi *tnapi, int entry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5648 | dma_addr_t mapping, int len, u32 flags, |
| 5649 | u32 mss_and_is_end) |
| 5650 | { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5651 | struct tg3_tx_buffer_desc *txd = &tnapi->tx_ring[entry]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5652 | int is_end = (mss_and_is_end & 0x1); |
| 5653 | u32 mss = (mss_and_is_end >> 1); |
| 5654 | u32 vlan_tag = 0; |
| 5655 | |
| 5656 | if (is_end) |
| 5657 | flags |= TXD_FLAG_END; |
| 5658 | if (flags & TXD_FLAG_VLAN) { |
| 5659 | vlan_tag = flags >> 16; |
| 5660 | flags &= 0xffff; |
| 5661 | } |
| 5662 | vlan_tag |= (mss << TXD_MSS_SHIFT); |
| 5663 | |
| 5664 | txd->addr_hi = ((u64) mapping >> 32); |
| 5665 | txd->addr_lo = ((u64) mapping & 0xffffffff); |
| 5666 | txd->len_flags = (len << TXD_LEN_SHIFT) | flags; |
| 5667 | txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT; |
| 5668 | } |
| 5669 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5670 | /* hard_start_xmit for devices that don't have any bugs and |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 5671 | * support TG3_FLG2_HW_TSO_2 and TG3_FLG2_HW_TSO_3 only. |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5672 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5673 | static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, |
| 5674 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5675 | { |
| 5676 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 | u32 len, entry, base_flags, mss; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5678 | dma_addr_t mapping; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5679 | struct tg3_napi *tnapi; |
| 5680 | struct netdev_queue *txq; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5681 | unsigned int i, last; |
| 5682 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5683 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 5684 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 5685 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5686 | tnapi++; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5687 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 5688 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5689 | * and TX reclaim runs via tp->napi.poll inside of a software |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5690 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 5691 | * no IRQ context deadlocks to worry about either. Rejoice! |
| 5692 | */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5693 | if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5694 | if (!netif_tx_queue_stopped(txq)) { |
| 5695 | netif_tx_stop_queue(txq); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5696 | |
| 5697 | /* This is a hard error, log it. */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5698 | netdev_err(dev, |
| 5699 | "BUG! Tx Ring full when queue awake!\n"); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5700 | } |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5701 | return NETDEV_TX_BUSY; |
| 5702 | } |
| 5703 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5704 | entry = tnapi->tx_prod; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5705 | base_flags = 0; |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 5706 | mss = skb_shinfo(skb)->gso_size; |
| 5707 | if (mss) { |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5708 | int tcp_opt_len, ip_tcp_len; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5709 | u32 hdrlen; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5710 | |
| 5711 | if (skb_header_cloned(skb) && |
| 5712 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { |
| 5713 | dev_kfree_skb(skb); |
| 5714 | goto out_unlock; |
| 5715 | } |
| 5716 | |
Matt Carlson | 02e9608 | 2010-09-15 08:59:59 +0000 | [diff] [blame] | 5717 | if (skb_is_gso_v6(skb)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5718 | hdrlen = skb_headlen(skb) - ETH_HLEN; |
Matt Carlson | 02e9608 | 2010-09-15 08:59:59 +0000 | [diff] [blame] | 5719 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5720 | struct iphdr *iph = ip_hdr(skb); |
| 5721 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 5722 | tcp_opt_len = tcp_optlen(skb); |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 5723 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 5724 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5725 | iph->check = 0; |
| 5726 | iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5727 | hdrlen = ip_tcp_len + tcp_opt_len; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 5728 | } |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5729 | |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 5730 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5731 | mss |= (hdrlen & 0xc) << 12; |
| 5732 | if (hdrlen & 0x10) |
| 5733 | base_flags |= 0x00000010; |
| 5734 | base_flags |= (hdrlen & 0x3e0) << 5; |
| 5735 | } else |
| 5736 | mss |= hdrlen << 9; |
| 5737 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5738 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 5739 | TXD_FLAG_CPU_POST_DMA); |
| 5740 | |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5741 | tcp_hdr(skb)->check = 0; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5742 | |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5743 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5744 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5745 | } |
| 5746 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5747 | #if TG3_VLAN_TAG_USED |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 5748 | if (vlan_tx_tag_present(skb)) |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5749 | base_flags |= (TXD_FLAG_VLAN | |
| 5750 | (vlan_tx_tag_get(skb) << 16)); |
| 5751 | #endif |
| 5752 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5753 | len = skb_headlen(skb); |
| 5754 | |
| 5755 | /* Queue skb data, a.k.a. the main skb fragment. */ |
| 5756 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
| 5757 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5758 | dev_kfree_skb(skb); |
| 5759 | goto out_unlock; |
| 5760 | } |
| 5761 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5762 | tnapi->tx_buffers[entry].skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5763 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5764 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 5765 | if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5766 | !mss && skb->len > ETH_DATA_LEN) |
| 5767 | base_flags |= TXD_FLAG_JMB_PKT; |
| 5768 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5769 | tg3_set_txd(tnapi, entry, mapping, len, base_flags, |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5770 | (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); |
| 5771 | |
| 5772 | entry = NEXT_TX(entry); |
| 5773 | |
| 5774 | /* Now loop through additional data fragments, and queue them. */ |
| 5775 | if (skb_shinfo(skb)->nr_frags > 0) { |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5776 | last = skb_shinfo(skb)->nr_frags - 1; |
| 5777 | for (i = 0; i <= last; i++) { |
| 5778 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 5779 | |
| 5780 | len = frag->size; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5781 | mapping = pci_map_page(tp->pdev, |
| 5782 | frag->page, |
| 5783 | frag->page_offset, |
| 5784 | len, PCI_DMA_TODEVICE); |
| 5785 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 5786 | goto dma_error; |
| 5787 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5788 | tnapi->tx_buffers[entry].skb = NULL; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5789 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5790 | mapping); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5791 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5792 | tg3_set_txd(tnapi, entry, mapping, len, |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5793 | base_flags, (i == last) | (mss << 1)); |
| 5794 | |
| 5795 | entry = NEXT_TX(entry); |
| 5796 | } |
| 5797 | } |
| 5798 | |
| 5799 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5800 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5801 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5802 | tnapi->tx_prod = entry; |
| 5803 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5804 | netif_tx_stop_queue(txq); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 5805 | |
| 5806 | /* netif_tx_stop_queue() must be done before checking |
| 5807 | * checking tx index in tg3_tx_avail() below, because in |
| 5808 | * tg3_tx(), we update tx index before checking for |
| 5809 | * netif_tx_queue_stopped(). |
| 5810 | */ |
| 5811 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5812 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5813 | netif_tx_wake_queue(txq); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | out_unlock: |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 5817 | mmiowb(); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5818 | |
| 5819 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5820 | |
| 5821 | dma_error: |
| 5822 | last = i; |
| 5823 | entry = tnapi->tx_prod; |
| 5824 | tnapi->tx_buffers[entry].skb = NULL; |
| 5825 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5826 | dma_unmap_addr(&tnapi->tx_buffers[entry], mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5827 | skb_headlen(skb), |
| 5828 | PCI_DMA_TODEVICE); |
| 5829 | for (i = 0; i <= last; i++) { |
| 5830 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 5831 | entry = NEXT_TX(entry); |
| 5832 | |
| 5833 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5834 | dma_unmap_addr(&tnapi->tx_buffers[entry], |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5835 | mapping), |
| 5836 | frag->size, PCI_DMA_TODEVICE); |
| 5837 | } |
| 5838 | |
| 5839 | dev_kfree_skb(skb); |
| 5840 | return NETDEV_TX_OK; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5841 | } |
| 5842 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5843 | static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *, |
| 5844 | struct net_device *); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5845 | |
| 5846 | /* Use GSO to workaround a rare TSO bug that may be triggered when the |
| 5847 | * TSO header is greater than 80 bytes. |
| 5848 | */ |
| 5849 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) |
| 5850 | { |
| 5851 | struct sk_buff *segs, *nskb; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5852 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5853 | |
| 5854 | /* Estimate the number of fragments in the worst case */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5855 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5856 | netif_stop_queue(tp->dev); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 5857 | |
| 5858 | /* netif_tx_stop_queue() must be done before checking |
| 5859 | * checking tx index in tg3_tx_avail() below, because in |
| 5860 | * tg3_tx(), we update tx index before checking for |
| 5861 | * netif_tx_queue_stopped(). |
| 5862 | */ |
| 5863 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5864 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 5865 | return NETDEV_TX_BUSY; |
| 5866 | |
| 5867 | netif_wake_queue(tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
| 5870 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame] | 5871 | if (IS_ERR(segs)) |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5872 | goto tg3_tso_bug_end; |
| 5873 | |
| 5874 | do { |
| 5875 | nskb = segs; |
| 5876 | segs = segs->next; |
| 5877 | nskb->next = NULL; |
| 5878 | tg3_start_xmit_dma_bug(nskb, tp->dev); |
| 5879 | } while (segs); |
| 5880 | |
| 5881 | tg3_tso_bug_end: |
| 5882 | dev_kfree_skb(skb); |
| 5883 | |
| 5884 | return NETDEV_TX_OK; |
| 5885 | } |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5886 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5887 | /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and |
| 5888 | * support TG3_FLG2_HW_TSO_1 or firmware TSO only. |
| 5889 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5890 | static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *skb, |
| 5891 | struct net_device *dev) |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5892 | { |
| 5893 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5894 | u32 len, entry, base_flags, mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5895 | int would_hit_hwbug; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5896 | dma_addr_t mapping; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5897 | struct tg3_napi *tnapi; |
| 5898 | struct netdev_queue *txq; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5899 | unsigned int i, last; |
| 5900 | |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5901 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 5902 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 5903 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5904 | tnapi++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5905 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 5906 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5907 | * 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] | 5908 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 5909 | * no IRQ context deadlocks to worry about either. Rejoice! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5910 | */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5911 | if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5912 | if (!netif_tx_queue_stopped(txq)) { |
| 5913 | netif_tx_stop_queue(txq); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 5914 | |
| 5915 | /* This is a hard error, log it. */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5916 | netdev_err(dev, |
| 5917 | "BUG! Tx Ring full when queue awake!\n"); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 5918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5919 | return NETDEV_TX_BUSY; |
| 5920 | } |
| 5921 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5922 | entry = tnapi->tx_prod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5923 | base_flags = 0; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 5924 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5925 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5926 | |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 5927 | mss = skb_shinfo(skb)->gso_size; |
| 5928 | if (mss) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5929 | struct iphdr *iph; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 5930 | u32 tcp_opt_len, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5931 | |
| 5932 | if (skb_header_cloned(skb) && |
| 5933 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { |
| 5934 | dev_kfree_skb(skb); |
| 5935 | goto out_unlock; |
| 5936 | } |
| 5937 | |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 5938 | iph = ip_hdr(skb); |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 5939 | tcp_opt_len = tcp_optlen(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5940 | |
Matt Carlson | 02e9608 | 2010-09-15 08:59:59 +0000 | [diff] [blame] | 5941 | if (skb_is_gso_v6(skb)) { |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 5942 | hdr_len = skb_headlen(skb) - ETH_HLEN; |
| 5943 | } else { |
| 5944 | u32 ip_tcp_len; |
| 5945 | |
| 5946 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); |
| 5947 | hdr_len = ip_tcp_len + tcp_opt_len; |
| 5948 | |
| 5949 | iph->check = 0; |
| 5950 | iph->tot_len = htons(mss + hdr_len); |
| 5951 | } |
| 5952 | |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5953 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 5954 | (tp->tg3_flags2 & TG3_FLG2_TSO_BUG)) |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 5955 | return tg3_tso_bug(tp, skb); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5956 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5957 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 5958 | TXD_FLAG_CPU_POST_DMA); |
| 5959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5960 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) { |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5961 | tcp_hdr(skb)->check = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5962 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5963 | } else |
| 5964 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 5965 | iph->daddr, 0, |
| 5966 | IPPROTO_TCP, |
| 5967 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5968 | |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 5969 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) { |
| 5970 | mss |= (hdr_len & 0xc) << 12; |
| 5971 | if (hdr_len & 0x10) |
| 5972 | base_flags |= 0x00000010; |
| 5973 | base_flags |= (hdr_len & 0x3e0) << 5; |
| 5974 | } else if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 5975 | mss |= hdr_len << 9; |
| 5976 | else if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_1) || |
| 5977 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5978 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5979 | int tsflags; |
| 5980 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5981 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5982 | mss |= (tsflags << 11); |
| 5983 | } |
| 5984 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5985 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5986 | int tsflags; |
| 5987 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5988 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5989 | base_flags |= tsflags << 12; |
| 5990 | } |
| 5991 | } |
| 5992 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5993 | #if TG3_VLAN_TAG_USED |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 5994 | if (vlan_tx_tag_present(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5995 | base_flags |= (TXD_FLAG_VLAN | |
| 5996 | (vlan_tx_tag_get(skb) << 16)); |
| 5997 | #endif |
| 5998 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 5999 | if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) && |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 6000 | !mss && skb->len > ETH_DATA_LEN) |
| 6001 | base_flags |= TXD_FLAG_JMB_PKT; |
| 6002 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6003 | len = skb_headlen(skb); |
| 6004 | |
| 6005 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
| 6006 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 6007 | dev_kfree_skb(skb); |
| 6008 | goto out_unlock; |
| 6009 | } |
| 6010 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6011 | tnapi->tx_buffers[entry].skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6012 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | |
| 6014 | would_hit_hwbug = 0; |
| 6015 | |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 6016 | if ((tp->tg3_flags3 & TG3_FLG3_SHORT_DMA_BUG) && len <= 8) |
| 6017 | would_hit_hwbug = 1; |
| 6018 | |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6019 | if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
| 6020 | tg3_4g_overflow_test(mapping, len)) |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 6021 | would_hit_hwbug = 1; |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6022 | |
| 6023 | if ((tp->tg3_flags3 & TG3_FLG3_40BIT_DMA_LIMIT_BUG) && |
| 6024 | tg3_40bit_overflow_test(tp, mapping, len)) |
| 6025 | would_hit_hwbug = 1; |
| 6026 | |
| 6027 | if (tp->tg3_flags3 & TG3_FLG3_5701_DMA_BUG) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6028 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6029 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6030 | tg3_set_txd(tnapi, entry, mapping, len, base_flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6031 | (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); |
| 6032 | |
| 6033 | entry = NEXT_TX(entry); |
| 6034 | |
| 6035 | /* Now loop through additional data fragments, and queue them. */ |
| 6036 | if (skb_shinfo(skb)->nr_frags > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6037 | last = skb_shinfo(skb)->nr_frags - 1; |
| 6038 | for (i = 0; i <= last; i++) { |
| 6039 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 6040 | |
| 6041 | len = frag->size; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6042 | mapping = pci_map_page(tp->pdev, |
| 6043 | frag->page, |
| 6044 | frag->page_offset, |
| 6045 | len, PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6046 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6047 | tnapi->tx_buffers[entry].skb = NULL; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6048 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6049 | mapping); |
| 6050 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 6051 | goto dma_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6052 | |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 6053 | if ((tp->tg3_flags3 & TG3_FLG3_SHORT_DMA_BUG) && |
| 6054 | len <= 8) |
| 6055 | would_hit_hwbug = 1; |
| 6056 | |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6057 | if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
| 6058 | tg3_4g_overflow_test(mapping, len)) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6059 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6060 | |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6061 | if ((tp->tg3_flags3 & TG3_FLG3_40BIT_DMA_LIMIT_BUG) && |
| 6062 | tg3_40bit_overflow_test(tp, mapping, len)) |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6063 | would_hit_hwbug = 1; |
| 6064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6065 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6066 | tg3_set_txd(tnapi, entry, mapping, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6067 | base_flags, (i == last)|(mss << 1)); |
| 6068 | else |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6069 | tg3_set_txd(tnapi, entry, mapping, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6070 | base_flags, (i == last)); |
| 6071 | |
| 6072 | entry = NEXT_TX(entry); |
| 6073 | } |
| 6074 | } |
| 6075 | |
| 6076 | if (would_hit_hwbug) { |
| 6077 | u32 last_plus_one = entry; |
| 6078 | u32 start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6079 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6080 | start = entry - 1 - skb_shinfo(skb)->nr_frags; |
| 6081 | start &= (TG3_TX_RING_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6082 | |
| 6083 | /* If the workaround fails due to memory/mapping |
| 6084 | * failure, silently drop this packet. |
| 6085 | */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6086 | if (tigon3_dma_hwbug_workaround(tnapi, skb, last_plus_one, |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6087 | &start, base_flags, mss)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6088 | goto out_unlock; |
| 6089 | |
| 6090 | entry = start; |
| 6091 | } |
| 6092 | |
| 6093 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6094 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6095 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6096 | tnapi->tx_prod = entry; |
| 6097 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6098 | netif_tx_stop_queue(txq); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 6099 | |
| 6100 | /* netif_tx_stop_queue() must be done before checking |
| 6101 | * checking tx index in tg3_tx_avail() below, because in |
| 6102 | * tg3_tx(), we update tx index before checking for |
| 6103 | * netif_tx_queue_stopped(). |
| 6104 | */ |
| 6105 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6106 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6107 | netif_tx_wake_queue(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 6108 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6109 | |
| 6110 | out_unlock: |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 6111 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6112 | |
| 6113 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6114 | |
| 6115 | dma_error: |
| 6116 | last = i; |
| 6117 | entry = tnapi->tx_prod; |
| 6118 | tnapi->tx_buffers[entry].skb = NULL; |
| 6119 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6120 | dma_unmap_addr(&tnapi->tx_buffers[entry], mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6121 | skb_headlen(skb), |
| 6122 | PCI_DMA_TODEVICE); |
| 6123 | for (i = 0; i <= last; i++) { |
| 6124 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 6125 | entry = NEXT_TX(entry); |
| 6126 | |
| 6127 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6128 | dma_unmap_addr(&tnapi->tx_buffers[entry], |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6129 | mapping), |
| 6130 | frag->size, PCI_DMA_TODEVICE); |
| 6131 | } |
| 6132 | |
| 6133 | dev_kfree_skb(skb); |
| 6134 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6135 | } |
| 6136 | |
| 6137 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
| 6138 | int new_mtu) |
| 6139 | { |
| 6140 | dev->mtu = new_mtu; |
| 6141 | |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6142 | if (new_mtu > ETH_DATA_LEN) { |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 6143 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) { |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6144 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE; |
| 6145 | ethtool_op_set_tso(dev, 0); |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 6146 | } else { |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6147 | tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE; |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 6148 | } |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6149 | } else { |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 6150 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6151 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 6152 | tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE; |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6153 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6154 | } |
| 6155 | |
| 6156 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) |
| 6157 | { |
| 6158 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6159 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6160 | |
| 6161 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) |
| 6162 | return -EINVAL; |
| 6163 | |
| 6164 | if (!netif_running(dev)) { |
| 6165 | /* We'll just catch it later when the |
| 6166 | * device is up'd. |
| 6167 | */ |
| 6168 | tg3_set_mtu(dev, tp, new_mtu); |
| 6169 | return 0; |
| 6170 | } |
| 6171 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 6172 | tg3_phy_stop(tp); |
| 6173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6174 | tg3_netif_stop(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6175 | |
| 6176 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6177 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 6178 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6179 | |
| 6180 | tg3_set_mtu(dev, tp, new_mtu); |
| 6181 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6182 | err = tg3_restart_hw(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6183 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6184 | if (!err) |
| 6185 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6186 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6187 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6188 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 6189 | if (!err) |
| 6190 | tg3_phy_start(tp); |
| 6191 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6192 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6193 | } |
| 6194 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6195 | static void tg3_rx_prodring_free(struct tg3 *tp, |
| 6196 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6197 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6198 | int i; |
| 6199 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6200 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6201 | 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] | 6202 | i = (i + 1) & tp->rx_std_ring_mask) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6203 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
| 6204 | tp->rx_pkt_map_sz); |
| 6205 | |
| 6206 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
| 6207 | for (i = tpr->rx_jmb_cons_idx; |
| 6208 | i != tpr->rx_jmb_prod_idx; |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6209 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6210 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
| 6211 | TG3_RX_JMB_MAP_SZ); |
| 6212 | } |
| 6213 | } |
| 6214 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6215 | return; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6218 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6219 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
| 6220 | tp->rx_pkt_map_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6221 | |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 6222 | if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && |
| 6223 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6224 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6225 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
| 6226 | TG3_RX_JMB_MAP_SZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6227 | } |
| 6228 | } |
| 6229 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 6230 | /* Initialize rx rings for packet processing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6231 | * |
| 6232 | * The chip has been shut down and the driver detached from |
| 6233 | * the networking, so no interrupts or new tx packets will |
| 6234 | * end up in the driver. tp->{tx,}lock are held and thus |
| 6235 | * we may not sleep. |
| 6236 | */ |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6237 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
| 6238 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6239 | { |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6240 | u32 i, rx_pkt_dma_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6241 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6242 | tpr->rx_std_cons_idx = 0; |
| 6243 | tpr->rx_std_prod_idx = 0; |
| 6244 | tpr->rx_jmb_cons_idx = 0; |
| 6245 | tpr->rx_jmb_prod_idx = 0; |
| 6246 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6247 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6248 | memset(&tpr->rx_std_buffers[0], 0, |
| 6249 | TG3_RX_STD_BUFF_RING_SIZE(tp)); |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 6250 | if (tpr->rx_jmb_buffers) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6251 | memset(&tpr->rx_jmb_buffers[0], 0, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6252 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6253 | goto done; |
| 6254 | } |
| 6255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6256 | /* Zero out all descriptors. */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6257 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6258 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6259 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 6260 | if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) && |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6261 | tp->dev->mtu > ETH_DATA_LEN) |
| 6262 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; |
| 6263 | 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] | 6264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6265 | /* Initialize invariants of the rings, we only set this |
| 6266 | * stuff once. This works because the card does not |
| 6267 | * write into the rx buffer posting rings. |
| 6268 | */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6269 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6270 | struct tg3_rx_buffer_desc *rxd; |
| 6271 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6272 | rxd = &tpr->rx_std[i]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6273 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6274 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
| 6275 | rxd->opaque = (RXD_OPAQUE_RING_STD | |
| 6276 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 6277 | } |
| 6278 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6279 | /* Now allocate fresh SKBs for each rx ring. */ |
| 6280 | for (i = 0; i < tp->rx_pending; i++) { |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 6281 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_STD, i) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 6282 | netdev_warn(tp->dev, |
| 6283 | "Using a smaller RX standard ring. Only " |
| 6284 | "%d out of %d buffers were allocated " |
| 6285 | "successfully\n", i, tp->rx_pending); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6286 | if (i == 0) |
| 6287 | goto initfail; |
| 6288 | tp->rx_pending = i; |
| 6289 | break; |
| 6290 | } |
| 6291 | } |
| 6292 | |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 6293 | if (!(tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) || |
| 6294 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6295 | goto done; |
| 6296 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6297 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6298 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6299 | if (!(tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)) |
| 6300 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6301 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6302 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6303 | struct tg3_rx_buffer_desc *rxd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6304 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6305 | rxd = &tpr->rx_jmb[i].std; |
| 6306 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; |
| 6307 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | |
| 6308 | RXD_FLAG_JUMBO; |
| 6309 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | |
| 6310 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 6311 | } |
| 6312 | |
| 6313 | for (i = 0; i < tp->rx_jumbo_pending; i++) { |
| 6314 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_JUMBO, i) < 0) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 6315 | netdev_warn(tp->dev, |
| 6316 | "Using a smaller RX jumbo ring. Only %d " |
| 6317 | "out of %d buffers were allocated " |
| 6318 | "successfully\n", i, tp->rx_jumbo_pending); |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6319 | if (i == 0) |
| 6320 | goto initfail; |
| 6321 | tp->rx_jumbo_pending = i; |
| 6322 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6323 | } |
| 6324 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6325 | |
| 6326 | done: |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 6327 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6328 | |
| 6329 | initfail: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6330 | tg3_rx_prodring_free(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6331 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6332 | } |
| 6333 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6334 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
| 6335 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6336 | { |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6337 | kfree(tpr->rx_std_buffers); |
| 6338 | tpr->rx_std_buffers = NULL; |
| 6339 | kfree(tpr->rx_jmb_buffers); |
| 6340 | tpr->rx_jmb_buffers = NULL; |
| 6341 | if (tpr->rx_std) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6342 | pci_free_consistent(tp->pdev, TG3_RX_STD_RING_BYTES(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6343 | tpr->rx_std, tpr->rx_std_mapping); |
| 6344 | tpr->rx_std = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6345 | } |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6346 | if (tpr->rx_jmb) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6347 | pci_free_consistent(tp->pdev, TG3_RX_JMB_RING_BYTES(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6348 | tpr->rx_jmb, tpr->rx_jmb_mapping); |
| 6349 | tpr->rx_jmb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6350 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6351 | } |
| 6352 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6353 | static int tg3_rx_prodring_init(struct tg3 *tp, |
| 6354 | struct tg3_rx_prodring_set *tpr) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6355 | { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6356 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
| 6357 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6358 | if (!tpr->rx_std_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6359 | return -ENOMEM; |
| 6360 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6361 | tpr->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_STD_RING_BYTES(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6362 | &tpr->rx_std_mapping); |
| 6363 | if (!tpr->rx_std) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6364 | goto err_out; |
| 6365 | |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 6366 | if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && |
| 6367 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6368 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6369 | GFP_KERNEL); |
| 6370 | if (!tpr->rx_jmb_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6371 | goto err_out; |
| 6372 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6373 | tpr->rx_jmb = pci_alloc_consistent(tp->pdev, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6374 | TG3_RX_JMB_RING_BYTES(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6375 | &tpr->rx_jmb_mapping); |
| 6376 | if (!tpr->rx_jmb) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6377 | goto err_out; |
| 6378 | } |
| 6379 | |
| 6380 | return 0; |
| 6381 | |
| 6382 | err_out: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6383 | tg3_rx_prodring_fini(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6384 | return -ENOMEM; |
| 6385 | } |
| 6386 | |
| 6387 | /* Free up pending packets in all rx/tx rings. |
| 6388 | * |
| 6389 | * The chip has been shut down and the driver detached from |
| 6390 | * the networking, so no interrupts or new tx packets will |
| 6391 | * end up in the driver. tp->{tx,}lock is not held and we are not |
| 6392 | * in an interrupt context and thus may sleep. |
| 6393 | */ |
| 6394 | static void tg3_free_rings(struct tg3 *tp) |
| 6395 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6396 | int i, j; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6397 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6398 | for (j = 0; j < tp->irq_cnt; j++) { |
| 6399 | struct tg3_napi *tnapi = &tp->napi[j]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6400 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6401 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
Matt Carlson | b28f642 | 2010-06-05 17:24:32 +0000 | [diff] [blame] | 6402 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6403 | if (!tnapi->tx_buffers) |
| 6404 | continue; |
| 6405 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6406 | for (i = 0; i < TG3_TX_RING_SIZE; ) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6407 | struct ring_info *txp; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6408 | struct sk_buff *skb; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6409 | unsigned int k; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6410 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6411 | txp = &tnapi->tx_buffers[i]; |
| 6412 | skb = txp->skb; |
| 6413 | |
| 6414 | if (skb == NULL) { |
| 6415 | i++; |
| 6416 | continue; |
| 6417 | } |
| 6418 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6419 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6420 | dma_unmap_addr(txp, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6421 | skb_headlen(skb), |
| 6422 | PCI_DMA_TODEVICE); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6423 | txp->skb = NULL; |
| 6424 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6425 | i++; |
| 6426 | |
| 6427 | for (k = 0; k < skb_shinfo(skb)->nr_frags; k++) { |
| 6428 | txp = &tnapi->tx_buffers[i & (TG3_TX_RING_SIZE - 1)]; |
| 6429 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6430 | dma_unmap_addr(txp, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6431 | skb_shinfo(skb)->frags[k].size, |
| 6432 | PCI_DMA_TODEVICE); |
| 6433 | i++; |
| 6434 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6435 | |
| 6436 | dev_kfree_skb_any(skb); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6437 | } |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6438 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6439 | } |
| 6440 | |
| 6441 | /* Initialize tx/rx rings for packet processing. |
| 6442 | * |
| 6443 | * The chip has been shut down and the driver detached from |
| 6444 | * the networking, so no interrupts or new tx packets will |
| 6445 | * end up in the driver. tp->{tx,}lock are held and thus |
| 6446 | * we may not sleep. |
| 6447 | */ |
| 6448 | static int tg3_init_rings(struct tg3 *tp) |
| 6449 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6450 | int i; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6451 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6452 | /* Free up all the SKBs. */ |
| 6453 | tg3_free_rings(tp); |
| 6454 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6455 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6456 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6457 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6458 | tnapi->last_tag = 0; |
| 6459 | tnapi->last_irq_tag = 0; |
| 6460 | tnapi->hw_status->status = 0; |
| 6461 | tnapi->hw_status->status_tag = 0; |
| 6462 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 6463 | |
| 6464 | tnapi->tx_prod = 0; |
| 6465 | tnapi->tx_cons = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6466 | if (tnapi->tx_ring) |
| 6467 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6468 | |
| 6469 | tnapi->rx_rcb_ptr = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6470 | if (tnapi->rx_rcb) |
| 6471 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6472 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6473 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6474 | tg3_free_rings(tp); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6475 | return -ENOMEM; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6476 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6477 | } |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6478 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6479 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6480 | } |
| 6481 | |
| 6482 | /* |
| 6483 | * Must not be invoked with interrupt sources disabled and |
| 6484 | * the hardware shutdown down. |
| 6485 | */ |
| 6486 | static void tg3_free_consistent(struct tg3 *tp) |
| 6487 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6488 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6489 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6490 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6491 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 6492 | |
| 6493 | if (tnapi->tx_ring) { |
| 6494 | pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES, |
| 6495 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
| 6496 | tnapi->tx_ring = NULL; |
| 6497 | } |
| 6498 | |
| 6499 | kfree(tnapi->tx_buffers); |
| 6500 | tnapi->tx_buffers = NULL; |
| 6501 | |
| 6502 | if (tnapi->rx_rcb) { |
| 6503 | pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp), |
| 6504 | tnapi->rx_rcb, |
| 6505 | tnapi->rx_rcb_mapping); |
| 6506 | tnapi->rx_rcb = NULL; |
| 6507 | } |
| 6508 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6509 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
| 6510 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6511 | if (tnapi->hw_status) { |
| 6512 | pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE, |
| 6513 | tnapi->hw_status, |
| 6514 | tnapi->status_mapping); |
| 6515 | tnapi->hw_status = NULL; |
| 6516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6517 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6519 | if (tp->hw_stats) { |
| 6520 | pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats), |
| 6521 | tp->hw_stats, tp->stats_mapping); |
| 6522 | tp->hw_stats = NULL; |
| 6523 | } |
| 6524 | } |
| 6525 | |
| 6526 | /* |
| 6527 | * Must not be invoked with interrupt sources disabled and |
| 6528 | * the hardware shutdown down. Can sleep. |
| 6529 | */ |
| 6530 | static int tg3_alloc_consistent(struct tg3 *tp) |
| 6531 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6532 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6534 | tp->hw_stats = pci_alloc_consistent(tp->pdev, |
| 6535 | sizeof(struct tg3_hw_stats), |
| 6536 | &tp->stats_mapping); |
| 6537 | if (!tp->hw_stats) |
| 6538 | goto err_out; |
| 6539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6540 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 6541 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6542 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6543 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6544 | struct tg3_hw_status *sblk; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6545 | |
| 6546 | tnapi->hw_status = pci_alloc_consistent(tp->pdev, |
| 6547 | TG3_HW_STATUS_SIZE, |
| 6548 | &tnapi->status_mapping); |
| 6549 | if (!tnapi->hw_status) |
| 6550 | goto err_out; |
| 6551 | |
| 6552 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6553 | sblk = tnapi->hw_status; |
| 6554 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6555 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
| 6556 | goto err_out; |
| 6557 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 6558 | /* If multivector TSS is enabled, vector 0 does not handle |
| 6559 | * tx interrupts. Don't allocate any resources for it. |
| 6560 | */ |
| 6561 | if ((!i && !(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) || |
| 6562 | (i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS))) { |
| 6563 | tnapi->tx_buffers = kzalloc(sizeof(struct ring_info) * |
| 6564 | TG3_TX_RING_SIZE, |
| 6565 | GFP_KERNEL); |
| 6566 | if (!tnapi->tx_buffers) |
| 6567 | goto err_out; |
| 6568 | |
| 6569 | tnapi->tx_ring = pci_alloc_consistent(tp->pdev, |
| 6570 | TG3_TX_RING_BYTES, |
| 6571 | &tnapi->tx_desc_mapping); |
| 6572 | if (!tnapi->tx_ring) |
| 6573 | goto err_out; |
| 6574 | } |
| 6575 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6576 | /* |
| 6577 | * When RSS is enabled, the status block format changes |
| 6578 | * slightly. The "rx_jumbo_consumer", "reserved", |
| 6579 | * and "rx_mini_consumer" members get mapped to the |
| 6580 | * other three rx return ring producer indexes. |
| 6581 | */ |
| 6582 | switch (i) { |
| 6583 | default: |
| 6584 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
| 6585 | break; |
| 6586 | case 2: |
| 6587 | tnapi->rx_rcb_prod_idx = &sblk->rx_jumbo_consumer; |
| 6588 | break; |
| 6589 | case 3: |
| 6590 | tnapi->rx_rcb_prod_idx = &sblk->reserved; |
| 6591 | break; |
| 6592 | case 4: |
| 6593 | tnapi->rx_rcb_prod_idx = &sblk->rx_mini_consumer; |
| 6594 | break; |
| 6595 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6596 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6597 | /* |
| 6598 | * If multivector RSS is enabled, vector 0 does not handle |
| 6599 | * rx or tx interrupts. Don't allocate any resources for it. |
| 6600 | */ |
| 6601 | if (!i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) |
| 6602 | continue; |
| 6603 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6604 | tnapi->rx_rcb = pci_alloc_consistent(tp->pdev, |
| 6605 | TG3_RX_RCB_RING_BYTES(tp), |
| 6606 | &tnapi->rx_rcb_mapping); |
| 6607 | if (!tnapi->rx_rcb) |
| 6608 | goto err_out; |
| 6609 | |
| 6610 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6611 | } |
| 6612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6613 | return 0; |
| 6614 | |
| 6615 | err_out: |
| 6616 | tg3_free_consistent(tp); |
| 6617 | return -ENOMEM; |
| 6618 | } |
| 6619 | |
| 6620 | #define MAX_WAIT_CNT 1000 |
| 6621 | |
| 6622 | /* To stop a block, clear the enable bit and poll till it |
| 6623 | * clears. tp->lock is held. |
| 6624 | */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6625 | static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6626 | { |
| 6627 | unsigned int i; |
| 6628 | u32 val; |
| 6629 | |
| 6630 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 6631 | switch (ofs) { |
| 6632 | case RCVLSC_MODE: |
| 6633 | case DMAC_MODE: |
| 6634 | case MBFREE_MODE: |
| 6635 | case BUFMGR_MODE: |
| 6636 | case MEMARB_MODE: |
| 6637 | /* We can't enable/disable these bits of the |
| 6638 | * 5705/5750, just say success. |
| 6639 | */ |
| 6640 | return 0; |
| 6641 | |
| 6642 | default: |
| 6643 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6644 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6645 | } |
| 6646 | |
| 6647 | val = tr32(ofs); |
| 6648 | val &= ~enable_bit; |
| 6649 | tw32_f(ofs, val); |
| 6650 | |
| 6651 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 6652 | udelay(100); |
| 6653 | val = tr32(ofs); |
| 6654 | if ((val & enable_bit) == 0) |
| 6655 | break; |
| 6656 | } |
| 6657 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6658 | if (i == MAX_WAIT_CNT && !silent) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 6659 | dev_err(&tp->pdev->dev, |
| 6660 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", |
| 6661 | ofs, enable_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6662 | return -ENODEV; |
| 6663 | } |
| 6664 | |
| 6665 | return 0; |
| 6666 | } |
| 6667 | |
| 6668 | /* tp->lock is held. */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6669 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6670 | { |
| 6671 | int i, err; |
| 6672 | |
| 6673 | tg3_disable_ints(tp); |
| 6674 | |
| 6675 | tp->rx_mode &= ~RX_MODE_ENABLE; |
| 6676 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 6677 | udelay(10); |
| 6678 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6679 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
| 6680 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); |
| 6681 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); |
| 6682 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); |
| 6683 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); |
| 6684 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6685 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6686 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); |
| 6687 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); |
| 6688 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); |
| 6689 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); |
| 6690 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); |
| 6691 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); |
| 6692 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6693 | |
| 6694 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 6695 | tw32_f(MAC_MODE, tp->mac_mode); |
| 6696 | udelay(40); |
| 6697 | |
| 6698 | tp->tx_mode &= ~TX_MODE_ENABLE; |
| 6699 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 6700 | |
| 6701 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 6702 | udelay(100); |
| 6703 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) |
| 6704 | break; |
| 6705 | } |
| 6706 | if (i >= MAX_WAIT_CNT) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 6707 | dev_err(&tp->pdev->dev, |
| 6708 | "%s timed out, TX_MODE_ENABLE will not clear " |
| 6709 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 6710 | err |= -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6711 | } |
| 6712 | |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 6713 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6714 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
| 6715 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6716 | |
| 6717 | tw32(FTQ_RESET, 0xffffffff); |
| 6718 | tw32(FTQ_RESET, 0x00000000); |
| 6719 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6720 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
| 6721 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6722 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6723 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6724 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 6725 | if (tnapi->hw_status) |
| 6726 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 6727 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6728 | if (tp->hw_stats) |
| 6729 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 6730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6731 | return err; |
| 6732 | } |
| 6733 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6734 | static void tg3_ape_send_event(struct tg3 *tp, u32 event) |
| 6735 | { |
| 6736 | int i; |
| 6737 | u32 apedata; |
| 6738 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6739 | /* NCSI does not support APE events */ |
| 6740 | if (tp->tg3_flags3 & TG3_FLG3_APE_HAS_NCSI) |
| 6741 | return; |
| 6742 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6743 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 6744 | if (apedata != APE_SEG_SIG_MAGIC) |
| 6745 | return; |
| 6746 | |
| 6747 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
Matt Carlson | 731fd79 | 2008-08-15 14:07:51 -0700 | [diff] [blame] | 6748 | if (!(apedata & APE_FW_STATUS_READY)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6749 | return; |
| 6750 | |
| 6751 | /* Wait for up to 1 millisecond for APE to service previous event. */ |
| 6752 | for (i = 0; i < 10; i++) { |
| 6753 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) |
| 6754 | return; |
| 6755 | |
| 6756 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 6757 | |
| 6758 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6759 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
| 6760 | event | APE_EVENT_STATUS_EVENT_PENDING); |
| 6761 | |
| 6762 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 6763 | |
| 6764 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6765 | break; |
| 6766 | |
| 6767 | udelay(100); |
| 6768 | } |
| 6769 | |
| 6770 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6771 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 6772 | } |
| 6773 | |
| 6774 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
| 6775 | { |
| 6776 | u32 event; |
| 6777 | u32 apedata; |
| 6778 | |
| 6779 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) |
| 6780 | return; |
| 6781 | |
| 6782 | switch (kind) { |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6783 | case RESET_KIND_INIT: |
| 6784 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, |
| 6785 | APE_HOST_SEG_SIG_MAGIC); |
| 6786 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, |
| 6787 | APE_HOST_SEG_LEN_MAGIC); |
| 6788 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); |
| 6789 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); |
| 6790 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 6791 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6792 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
| 6793 | APE_HOST_BEHAV_NO_PHYLOCK); |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6794 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, |
| 6795 | TG3_APE_HOST_DRVR_STATE_START); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6796 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6797 | event = APE_EVENT_STATUS_STATE_START; |
| 6798 | break; |
| 6799 | case RESET_KIND_SHUTDOWN: |
| 6800 | /* With the interface we are currently using, |
| 6801 | * APE does not track driver state. Wiping |
| 6802 | * out the HOST SEGMENT SIGNATURE forces |
| 6803 | * the APE to assume OS absent status. |
| 6804 | */ |
| 6805 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); |
Matt Carlson | b2aee15 | 2008-11-03 16:51:11 -0800 | [diff] [blame] | 6806 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6807 | if (device_may_wakeup(&tp->pdev->dev) && |
| 6808 | (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)) { |
| 6809 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, |
| 6810 | TG3_APE_HOST_WOL_SPEED_AUTO); |
| 6811 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; |
| 6812 | } else |
| 6813 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; |
| 6814 | |
| 6815 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); |
| 6816 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6817 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
| 6818 | break; |
| 6819 | case RESET_KIND_SUSPEND: |
| 6820 | event = APE_EVENT_STATUS_STATE_SUSPEND; |
| 6821 | break; |
| 6822 | default: |
| 6823 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; |
| 6827 | |
| 6828 | tg3_ape_send_event(tp, event); |
| 6829 | } |
| 6830 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 6831 | /* tp->lock is held. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6832 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) |
| 6833 | { |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 6834 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
| 6835 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6836 | |
| 6837 | if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) { |
| 6838 | switch (kind) { |
| 6839 | case RESET_KIND_INIT: |
| 6840 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6841 | DRV_STATE_START); |
| 6842 | break; |
| 6843 | |
| 6844 | case RESET_KIND_SHUTDOWN: |
| 6845 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6846 | DRV_STATE_UNLOAD); |
| 6847 | break; |
| 6848 | |
| 6849 | case RESET_KIND_SUSPEND: |
| 6850 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6851 | DRV_STATE_SUSPEND); |
| 6852 | break; |
| 6853 | |
| 6854 | default: |
| 6855 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6856 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6857 | } |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6858 | |
| 6859 | if (kind == RESET_KIND_INIT || |
| 6860 | kind == RESET_KIND_SUSPEND) |
| 6861 | tg3_ape_driver_state_change(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6862 | } |
| 6863 | |
| 6864 | /* tp->lock is held. */ |
| 6865 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) |
| 6866 | { |
| 6867 | if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) { |
| 6868 | switch (kind) { |
| 6869 | case RESET_KIND_INIT: |
| 6870 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6871 | DRV_STATE_START_DONE); |
| 6872 | break; |
| 6873 | |
| 6874 | case RESET_KIND_SHUTDOWN: |
| 6875 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6876 | DRV_STATE_UNLOAD_DONE); |
| 6877 | break; |
| 6878 | |
| 6879 | default: |
| 6880 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6881 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6882 | } |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6883 | |
| 6884 | if (kind == RESET_KIND_SHUTDOWN) |
| 6885 | tg3_ape_driver_state_change(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6886 | } |
| 6887 | |
| 6888 | /* tp->lock is held. */ |
| 6889 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) |
| 6890 | { |
| 6891 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { |
| 6892 | switch (kind) { |
| 6893 | case RESET_KIND_INIT: |
| 6894 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6895 | DRV_STATE_START); |
| 6896 | break; |
| 6897 | |
| 6898 | case RESET_KIND_SHUTDOWN: |
| 6899 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6900 | DRV_STATE_UNLOAD); |
| 6901 | break; |
| 6902 | |
| 6903 | case RESET_KIND_SUSPEND: |
| 6904 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6905 | DRV_STATE_SUSPEND); |
| 6906 | break; |
| 6907 | |
| 6908 | default: |
| 6909 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6910 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6911 | } |
| 6912 | } |
| 6913 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6914 | static int tg3_poll_fw(struct tg3 *tp) |
| 6915 | { |
| 6916 | int i; |
| 6917 | u32 val; |
| 6918 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6919 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Gary Zambrano | 0ccead1 | 2006-11-14 16:34:00 -0800 | [diff] [blame] | 6920 | /* Wait up to 20ms for init done. */ |
| 6921 | for (i = 0; i < 200; i++) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6922 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
| 6923 | return 0; |
Gary Zambrano | 0ccead1 | 2006-11-14 16:34:00 -0800 | [diff] [blame] | 6924 | udelay(100); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6925 | } |
| 6926 | return -ENODEV; |
| 6927 | } |
| 6928 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6929 | /* Wait for firmware initialization to complete. */ |
| 6930 | for (i = 0; i < 100000; i++) { |
| 6931 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); |
| 6932 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 6933 | break; |
| 6934 | udelay(10); |
| 6935 | } |
| 6936 | |
| 6937 | /* Chip might not be fitted with firmware. Some Sun onboard |
| 6938 | * parts are configured like that. So don't signal the timeout |
| 6939 | * of the above loop as an error, but do report the lack of |
| 6940 | * running firmware once. |
| 6941 | */ |
| 6942 | if (i >= 100000 && |
| 6943 | !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) { |
| 6944 | tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED; |
| 6945 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 6946 | netdev_info(tp->dev, "No firmware running\n"); |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6947 | } |
| 6948 | |
Matt Carlson | 6b10c16 | 2010-02-12 14:47:08 +0000 | [diff] [blame] | 6949 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 6950 | /* The 57765 A0 needs a little more |
| 6951 | * time to do some important work. |
| 6952 | */ |
| 6953 | mdelay(10); |
| 6954 | } |
| 6955 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6956 | return 0; |
| 6957 | } |
| 6958 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6959 | /* Save PCI command register before chip reset */ |
| 6960 | static void tg3_save_pci_state(struct tg3 *tp) |
| 6961 | { |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 6962 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | /* Restore PCI state after chip reset */ |
| 6966 | static void tg3_restore_pci_state(struct tg3 *tp) |
| 6967 | { |
| 6968 | u32 val; |
| 6969 | |
| 6970 | /* Re-enable indirect register accesses. */ |
| 6971 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 6972 | tp->misc_host_ctrl); |
| 6973 | |
| 6974 | /* Set MAX PCI retry to zero. */ |
| 6975 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); |
| 6976 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
| 6977 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) |
| 6978 | val |= PCISTATE_RETRY_SAME_DMA; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6979 | /* Allow reads and writes to the APE register and memory space. */ |
| 6980 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 6981 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 6982 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 6983 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6984 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
| 6985 | |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 6986 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6987 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 6988 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) { |
| 6989 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) |
| 6990 | pcie_set_readrq(tp->pdev, 4096); |
| 6991 | else { |
| 6992 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 6993 | tp->pci_cacheline_sz); |
| 6994 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 6995 | tp->pci_lat_timer); |
| 6996 | } |
Michael Chan | 114342f | 2007-10-15 02:12:26 -0700 | [diff] [blame] | 6997 | } |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 6998 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6999 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 7000 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 7001 | u16 pcix_cmd; |
| 7002 | |
| 7003 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 7004 | &pcix_cmd); |
| 7005 | pcix_cmd &= ~PCI_X_CMD_ERO; |
| 7006 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 7007 | pcix_cmd); |
| 7008 | } |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7009 | |
| 7010 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7011 | |
| 7012 | /* Chip reset on 5780 will reset MSI enable bit, |
| 7013 | * so need to restore it. |
| 7014 | */ |
| 7015 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { |
| 7016 | u16 ctrl; |
| 7017 | |
| 7018 | pci_read_config_word(tp->pdev, |
| 7019 | tp->msi_cap + PCI_MSI_FLAGS, |
| 7020 | &ctrl); |
| 7021 | pci_write_config_word(tp->pdev, |
| 7022 | tp->msi_cap + PCI_MSI_FLAGS, |
| 7023 | ctrl | PCI_MSI_FLAGS_ENABLE); |
| 7024 | val = tr32(MSGINT_MODE); |
| 7025 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); |
| 7026 | } |
| 7027 | } |
| 7028 | } |
| 7029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7030 | static void tg3_stop_fw(struct tg3 *); |
| 7031 | |
| 7032 | /* tp->lock is held. */ |
| 7033 | static int tg3_chip_reset(struct tg3 *tp) |
| 7034 | { |
| 7035 | u32 val; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7036 | void (*write_op)(struct tg3 *, u32, u32); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7037 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7038 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 7039 | tg3_nvram_lock(tp); |
| 7040 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 7041 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
| 7042 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 7043 | /* No matching tg3_nvram_unlock() after this because |
| 7044 | * chip reset below will undo the nvram lock. |
| 7045 | */ |
| 7046 | tp->nvram_lock_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7047 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7048 | /* GRC_MISC_CFG core clock reset will clear the memory |
| 7049 | * enable bit in PCI register 4 and the MSI enable bit |
| 7050 | * on some chips, so we save relevant registers here. |
| 7051 | */ |
| 7052 | tg3_save_pci_state(tp); |
| 7053 | |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 7054 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 7055 | (tp->tg3_flags3 & TG3_FLG3_5755_PLUS)) |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 7056 | tw32(GRC_FASTBOOT_PC, 0); |
| 7057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7058 | /* |
| 7059 | * We must avoid the readl() that normally takes place. |
| 7060 | * It locks machines, causes machine checks, and other |
| 7061 | * fun things. So, temporarily disable the 5701 |
| 7062 | * hardware workaround, while we do the reset. |
| 7063 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7064 | write_op = tp->write32; |
| 7065 | if (write_op == tg3_write_flush_reg32) |
| 7066 | tp->write32 = tg3_write32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7067 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7068 | /* Prevent the irq handler from reading or writing PCI registers |
| 7069 | * during chip reset when the memory enable bit in the PCI command |
| 7070 | * register may be cleared. The chip does not generate interrupt |
| 7071 | * at this time, but the irq handler may still be called due to irq |
| 7072 | * sharing or irqpoll. |
| 7073 | */ |
| 7074 | tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7075 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7076 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7077 | if (tnapi->hw_status) { |
| 7078 | tnapi->hw_status->status = 0; |
| 7079 | tnapi->hw_status->status_tag = 0; |
| 7080 | } |
| 7081 | tnapi->last_tag = 0; |
| 7082 | tnapi->last_irq_tag = 0; |
Michael Chan | b8fa2f3 | 2007-04-06 17:35:37 -0700 | [diff] [blame] | 7083 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7084 | smp_mb(); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7085 | |
| 7086 | for (i = 0; i < tp->irq_cnt; i++) |
| 7087 | synchronize_irq(tp->napi[i].irq_vec); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7088 | |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 7089 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 7090 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 7091 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 7092 | } |
| 7093 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7094 | /* do the reset */ |
| 7095 | val = GRC_MISC_CFG_CORECLK_RESET; |
| 7096 | |
| 7097 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 7098 | /* Force PCIe 1.0a mode */ |
| 7099 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
| 7100 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
| 7101 | tr32(TG3_PCIE_PHY_TSTCTL) == |
| 7102 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) |
| 7103 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); |
| 7104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7105 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
| 7106 | tw32(GRC_MISC_CFG, (1 << 29)); |
| 7107 | val |= (1 << 29); |
| 7108 | } |
| 7109 | } |
| 7110 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 7111 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 7112 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
| 7113 | tw32(GRC_VCPU_EXT_CTRL, |
| 7114 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 7115 | } |
| 7116 | |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 7117 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
| 7118 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
| 7119 | !(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7120 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 7121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7122 | tw32(GRC_MISC_CFG, val); |
| 7123 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7124 | /* restore 5701 hardware bug workaround write method */ |
| 7125 | tp->write32 = write_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7126 | |
| 7127 | /* Unfortunately, we have to delay before the PCI read back. |
| 7128 | * Some 575X chips even will not respond to a PCI cfg access |
| 7129 | * when the reset command is given to the chip. |
| 7130 | * |
| 7131 | * How do these hardware designers expect things to work |
| 7132 | * properly if the PCI write is posted for a long period |
| 7133 | * of time? It is always necessary to have some method by |
| 7134 | * which a register read back can occur to push the write |
| 7135 | * out which does the reset. |
| 7136 | * |
| 7137 | * For most tg3 variants the trick below was working. |
| 7138 | * Ho hum... |
| 7139 | */ |
| 7140 | udelay(120); |
| 7141 | |
| 7142 | /* Flush PCI posted writes. The normal MMIO registers |
| 7143 | * are inaccessible at this time so this is the only |
| 7144 | * way to make this reliably (actually, this is no longer |
| 7145 | * the case, see above). I tried to use indirect |
| 7146 | * register read/write but this upset some 5701 variants. |
| 7147 | */ |
| 7148 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); |
| 7149 | |
| 7150 | udelay(120); |
| 7151 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7152 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && tp->pcie_cap) { |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7153 | u16 val16; |
| 7154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7155 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
| 7156 | int i; |
| 7157 | u32 cfg_val; |
| 7158 | |
| 7159 | /* Wait for link training to complete. */ |
| 7160 | for (i = 0; i < 5000; i++) |
| 7161 | udelay(100); |
| 7162 | |
| 7163 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); |
| 7164 | pci_write_config_dword(tp->pdev, 0xc4, |
| 7165 | cfg_val | (1 << 15)); |
| 7166 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7167 | |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7168 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
| 7169 | pci_read_config_word(tp->pdev, |
| 7170 | tp->pcie_cap + PCI_EXP_DEVCTL, |
| 7171 | &val16); |
| 7172 | val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN | |
| 7173 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 7174 | /* |
| 7175 | * Older PCIe devices only support the 128 byte |
| 7176 | * MPS setting. Enforce the restriction. |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7177 | */ |
Matt Carlson | 6de34cb | 2010-08-02 11:25:55 +0000 | [diff] [blame] | 7178 | if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7179 | val16 &= ~PCI_EXP_DEVCTL_PAYLOAD; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7180 | pci_write_config_word(tp->pdev, |
| 7181 | tp->pcie_cap + PCI_EXP_DEVCTL, |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7182 | val16); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7183 | |
| 7184 | pcie_set_readrq(tp->pdev, 4096); |
| 7185 | |
| 7186 | /* Clear error status */ |
| 7187 | pci_write_config_word(tp->pdev, |
| 7188 | tp->pcie_cap + PCI_EXP_DEVSTA, |
| 7189 | PCI_EXP_DEVSTA_CED | |
| 7190 | PCI_EXP_DEVSTA_NFED | |
| 7191 | PCI_EXP_DEVSTA_FED | |
| 7192 | PCI_EXP_DEVSTA_URD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7193 | } |
| 7194 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7195 | tg3_restore_pci_state(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7196 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7197 | tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING; |
| 7198 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7199 | val = 0; |
| 7200 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 7201 | val = tr32(MEMARB_MODE); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7202 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7203 | |
| 7204 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { |
| 7205 | tg3_stop_fw(tp); |
| 7206 | tw32(0x5000, 0x400); |
| 7207 | } |
| 7208 | |
| 7209 | tw32(GRC_MODE, tp->grc_mode); |
| 7210 | |
| 7211 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 7212 | val = tr32(0xc4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7213 | |
| 7214 | tw32(0xc4, val | (1 << 15)); |
| 7215 | } |
| 7216 | |
| 7217 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && |
| 7218 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 7219 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
| 7220 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) |
| 7221 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
| 7222 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 7223 | } |
| 7224 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 7225 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7226 | tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 7227 | tw32_f(MAC_MODE, tp->mac_mode); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 7228 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 7229 | tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 7230 | tw32_f(MAC_MODE, tp->mac_mode); |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 7231 | } else if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
| 7232 | tp->mac_mode &= (MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN); |
| 7233 | if (tp->mac_mode & MAC_MODE_APE_TX_EN) |
| 7234 | tp->mac_mode |= MAC_MODE_TDE_ENABLE; |
| 7235 | tw32_f(MAC_MODE, tp->mac_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7236 | } else |
| 7237 | tw32_f(MAC_MODE, 0); |
| 7238 | udelay(40); |
| 7239 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 7240 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
| 7241 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 7242 | err = tg3_poll_fw(tp); |
| 7243 | if (err) |
| 7244 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7245 | |
Matt Carlson | 0a9140c | 2009-08-28 12:27:50 +0000 | [diff] [blame] | 7246 | tg3_mdio_start(tp); |
| 7247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7248 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 7249 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 7250 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 7251 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 7252 | val = tr32(0x7c00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7253 | |
| 7254 | tw32(0x7c00, val | (1 << 25)); |
| 7255 | } |
| 7256 | |
| 7257 | /* Reprobe ASF enable state. */ |
| 7258 | tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF; |
| 7259 | tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE; |
| 7260 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 7261 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 7262 | u32 nic_cfg; |
| 7263 | |
| 7264 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 7265 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
| 7266 | tp->tg3_flags |= TG3_FLAG_ENABLE_ASF; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 7267 | tp->last_event_jiffies = jiffies; |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 7268 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7269 | tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE; |
| 7270 | } |
| 7271 | } |
| 7272 | |
| 7273 | return 0; |
| 7274 | } |
| 7275 | |
| 7276 | /* tp->lock is held. */ |
| 7277 | static void tg3_stop_fw(struct tg3 *tp) |
| 7278 | { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7279 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) && |
| 7280 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 7281 | /* Wait for RX cpu to ACK the previous event. */ |
| 7282 | tg3_wait_for_event_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7283 | |
| 7284 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 7285 | |
| 7286 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7287 | |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 7288 | /* Wait for RX cpu to ACK this event. */ |
| 7289 | tg3_wait_for_event_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7290 | } |
| 7291 | } |
| 7292 | |
| 7293 | /* tp->lock is held. */ |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7294 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7295 | { |
| 7296 | int err; |
| 7297 | |
| 7298 | tg3_stop_fw(tp); |
| 7299 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7300 | tg3_write_sig_pre_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7301 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7302 | tg3_abort_hw(tp, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7303 | err = tg3_chip_reset(tp); |
| 7304 | |
Matt Carlson | daba2a6 | 2009-04-20 06:58:52 +0000 | [diff] [blame] | 7305 | __tg3_set_mac_addr(tp, 0); |
| 7306 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7307 | tg3_write_sig_legacy(tp, kind); |
| 7308 | tg3_write_sig_post_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7309 | |
| 7310 | if (err) |
| 7311 | return err; |
| 7312 | |
| 7313 | return 0; |
| 7314 | } |
| 7315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7316 | #define RX_CPU_SCRATCH_BASE 0x30000 |
| 7317 | #define RX_CPU_SCRATCH_SIZE 0x04000 |
| 7318 | #define TX_CPU_SCRATCH_BASE 0x34000 |
| 7319 | #define TX_CPU_SCRATCH_SIZE 0x04000 |
| 7320 | |
| 7321 | /* tp->lock is held. */ |
| 7322 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) |
| 7323 | { |
| 7324 | int i; |
| 7325 | |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 7326 | BUG_ON(offset == TX_CPU_BASE && |
| 7327 | (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7328 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 7329 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 7330 | u32 val = tr32(GRC_VCPU_EXT_CTRL); |
| 7331 | |
| 7332 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 7333 | return 0; |
| 7334 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7335 | if (offset == RX_CPU_BASE) { |
| 7336 | for (i = 0; i < 10000; i++) { |
| 7337 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7338 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 7339 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 7340 | break; |
| 7341 | } |
| 7342 | |
| 7343 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7344 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); |
| 7345 | udelay(10); |
| 7346 | } else { |
| 7347 | for (i = 0; i < 10000; i++) { |
| 7348 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7349 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 7350 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 7351 | break; |
| 7352 | } |
| 7353 | } |
| 7354 | |
| 7355 | if (i >= 10000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7356 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
| 7357 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7358 | return -ENODEV; |
| 7359 | } |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7360 | |
| 7361 | /* Clear firmware's nvram arbitration. */ |
| 7362 | if (tp->tg3_flags & TG3_FLAG_NVRAM) |
| 7363 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7364 | return 0; |
| 7365 | } |
| 7366 | |
| 7367 | struct fw_info { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7368 | unsigned int fw_base; |
| 7369 | unsigned int fw_len; |
| 7370 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7371 | }; |
| 7372 | |
| 7373 | /* tp->lock is held. */ |
| 7374 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base, |
| 7375 | int cpu_scratch_size, struct fw_info *info) |
| 7376 | { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7377 | int err, lock_err, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7378 | void (*write_op)(struct tg3 *, u32, u32); |
| 7379 | |
| 7380 | if (cpu_base == TX_CPU_BASE && |
| 7381 | (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7382 | netdev_err(tp->dev, |
| 7383 | "%s: Trying to load TX cpu firmware which is 5705\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7384 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7385 | return -EINVAL; |
| 7386 | } |
| 7387 | |
| 7388 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
| 7389 | write_op = tg3_write_mem; |
| 7390 | else |
| 7391 | write_op = tg3_write_indirect_reg32; |
| 7392 | |
Michael Chan | 1b62815 | 2005-05-29 14:59:49 -0700 | [diff] [blame] | 7393 | /* It is possible that bootcode is still loading at this point. |
| 7394 | * Get the nvram lock first before halting the cpu. |
| 7395 | */ |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7396 | lock_err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7397 | err = tg3_halt_cpu(tp, cpu_base); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7398 | if (!lock_err) |
| 7399 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7400 | if (err) |
| 7401 | goto out; |
| 7402 | |
| 7403 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
| 7404 | write_op(tp, cpu_scratch_base + i, 0); |
| 7405 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7406 | tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7407 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7408 | write_op(tp, (cpu_scratch_base + |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7409 | (info->fw_base & 0xffff) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7410 | (i * sizeof(u32))), |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7411 | be32_to_cpu(info->fw_data[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7412 | |
| 7413 | err = 0; |
| 7414 | |
| 7415 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7416 | return err; |
| 7417 | } |
| 7418 | |
| 7419 | /* tp->lock is held. */ |
| 7420 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) |
| 7421 | { |
| 7422 | struct fw_info info; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7423 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7424 | int err, i; |
| 7425 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7426 | fw_data = (void *)tp->fw->data; |
| 7427 | |
| 7428 | /* Firmware blob starts with version numbers, followed by |
| 7429 | start address and length. We are setting complete length. |
| 7430 | length = end_address_of_bss - start_address_of_text. |
| 7431 | Remainder is the blob to be loaded contiguously |
| 7432 | from start address. */ |
| 7433 | |
| 7434 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 7435 | info.fw_len = tp->fw->size - 12; |
| 7436 | info.fw_data = &fw_data[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7437 | |
| 7438 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
| 7439 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, |
| 7440 | &info); |
| 7441 | if (err) |
| 7442 | return err; |
| 7443 | |
| 7444 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, |
| 7445 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, |
| 7446 | &info); |
| 7447 | if (err) |
| 7448 | return err; |
| 7449 | |
| 7450 | /* Now startup only the RX cpu. */ |
| 7451 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7452 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7453 | |
| 7454 | for (i = 0; i < 5; i++) { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7455 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7456 | break; |
| 7457 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 7458 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7459 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7460 | udelay(1000); |
| 7461 | } |
| 7462 | if (i >= 5) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7463 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
| 7464 | "should be %08x\n", __func__, |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7465 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7466 | return -ENODEV; |
| 7467 | } |
| 7468 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 7469 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); |
| 7470 | |
| 7471 | return 0; |
| 7472 | } |
| 7473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7474 | /* 5705 needs a special version of the TSO firmware. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7475 | |
| 7476 | /* tp->lock is held. */ |
| 7477 | static int tg3_load_tso_firmware(struct tg3 *tp) |
| 7478 | { |
| 7479 | struct fw_info info; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7480 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7481 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
| 7482 | int err, i; |
| 7483 | |
| 7484 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
| 7485 | return 0; |
| 7486 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7487 | fw_data = (void *)tp->fw->data; |
| 7488 | |
| 7489 | /* Firmware blob starts with version numbers, followed by |
| 7490 | start address and length. We are setting complete length. |
| 7491 | length = end_address_of_bss - start_address_of_text. |
| 7492 | Remainder is the blob to be loaded contiguously |
| 7493 | from start address. */ |
| 7494 | |
| 7495 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 7496 | cpu_scratch_size = tp->fw_len; |
| 7497 | info.fw_len = tp->fw->size - 12; |
| 7498 | info.fw_data = &fw_data[3]; |
| 7499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7500 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7501 | cpu_base = RX_CPU_BASE; |
| 7502 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7503 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7504 | cpu_base = TX_CPU_BASE; |
| 7505 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; |
| 7506 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; |
| 7507 | } |
| 7508 | |
| 7509 | err = tg3_load_firmware_cpu(tp, cpu_base, |
| 7510 | cpu_scratch_base, cpu_scratch_size, |
| 7511 | &info); |
| 7512 | if (err) |
| 7513 | return err; |
| 7514 | |
| 7515 | /* Now startup the cpu. */ |
| 7516 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7517 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7518 | |
| 7519 | for (i = 0; i < 5; i++) { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7520 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7521 | break; |
| 7522 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7523 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7524 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7525 | udelay(1000); |
| 7526 | } |
| 7527 | if (i >= 5) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7528 | netdev_err(tp->dev, |
| 7529 | "%s fails to set CPU PC, is %08x should be %08x\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7530 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7531 | return -ENODEV; |
| 7532 | } |
| 7533 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7534 | tw32_f(cpu_base + CPU_MODE, 0x00000000); |
| 7535 | return 0; |
| 7536 | } |
| 7537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7539 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
| 7540 | { |
| 7541 | struct tg3 *tp = netdev_priv(dev); |
| 7542 | struct sockaddr *addr = p; |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7543 | int err = 0, skip_mac_1 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7544 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 7545 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7546 | return -EINVAL; |
| 7547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7548 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 7549 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 7550 | if (!netif_running(dev)) |
| 7551 | return 0; |
| 7552 | |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7553 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7554 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7555 | |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7556 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
| 7557 | addr0_low = tr32(MAC_ADDR_0_LOW); |
| 7558 | addr1_high = tr32(MAC_ADDR_1_HIGH); |
| 7559 | addr1_low = tr32(MAC_ADDR_1_LOW); |
| 7560 | |
| 7561 | /* Skip MAC addr 1 if ASF is using it. */ |
| 7562 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && |
| 7563 | !(addr1_high == 0 && addr1_low == 0)) |
| 7564 | skip_mac_1 = 1; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7565 | } |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7566 | spin_lock_bh(&tp->lock); |
| 7567 | __tg3_set_mac_addr(tp, skip_mac_1); |
| 7568 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7569 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 7570 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7571 | } |
| 7572 | |
| 7573 | /* tp->lock is held. */ |
| 7574 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, |
| 7575 | dma_addr_t mapping, u32 maxlen_flags, |
| 7576 | u32 nic_addr) |
| 7577 | { |
| 7578 | tg3_write_mem(tp, |
| 7579 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 7580 | ((u64) mapping >> 32)); |
| 7581 | tg3_write_mem(tp, |
| 7582 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), |
| 7583 | ((u64) mapping & 0xffffffff)); |
| 7584 | tg3_write_mem(tp, |
| 7585 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), |
| 7586 | maxlen_flags); |
| 7587 | |
| 7588 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 7589 | tg3_write_mem(tp, |
| 7590 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), |
| 7591 | nic_addr); |
| 7592 | } |
| 7593 | |
| 7594 | static void __tg3_set_rx_mode(struct net_device *); |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 7595 | static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7596 | { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7597 | int i; |
| 7598 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7599 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7600 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
| 7601 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); |
| 7602 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7603 | } else { |
| 7604 | tw32(HOSTCC_TXCOL_TICKS, 0); |
| 7605 | tw32(HOSTCC_TXMAX_FRAMES, 0); |
| 7606 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7607 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7608 | |
Matt Carlson | 20d7375 | 2010-07-11 09:31:41 +0000 | [diff] [blame] | 7609 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7610 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
| 7611 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); |
| 7612 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); |
| 7613 | } else { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7614 | tw32(HOSTCC_RXCOL_TICKS, 0); |
| 7615 | tw32(HOSTCC_RXMAX_FRAMES, 0); |
| 7616 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7617 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7618 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7619 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 7620 | u32 val = ec->stats_block_coalesce_usecs; |
| 7621 | |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7622 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
| 7623 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); |
| 7624 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7625 | if (!netif_carrier_ok(tp->dev)) |
| 7626 | val = 0; |
| 7627 | |
| 7628 | tw32(HOSTCC_STAT_COAL_TICKS, val); |
| 7629 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7630 | |
| 7631 | for (i = 0; i < tp->irq_cnt - 1; i++) { |
| 7632 | u32 reg; |
| 7633 | |
| 7634 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; |
| 7635 | tw32(reg, ec->rx_coalesce_usecs); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7636 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
| 7637 | tw32(reg, ec->rx_max_coalesced_frames); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7638 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 7639 | tw32(reg, ec->rx_max_coalesced_frames_irq); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7640 | |
| 7641 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) { |
| 7642 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
| 7643 | tw32(reg, ec->tx_coalesce_usecs); |
| 7644 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; |
| 7645 | tw32(reg, ec->tx_max_coalesced_frames); |
| 7646 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 7647 | tw32(reg, ec->tx_max_coalesced_frames_irq); |
| 7648 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7649 | } |
| 7650 | |
| 7651 | for (; i < tp->irq_max - 1; i++) { |
| 7652 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7653 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7654 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7655 | |
| 7656 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) { |
| 7657 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 7658 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 7659 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 7660 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7661 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7663 | |
| 7664 | /* tp->lock is held. */ |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7665 | static void tg3_rings_reset(struct tg3 *tp) |
| 7666 | { |
| 7667 | int i; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7668 | u32 stblk, txrcb, rxrcb, limit; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7669 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 7670 | |
| 7671 | /* Disable all transmit rings but the first. */ |
| 7672 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 7673 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | 3d37728 | 2010-10-14 10:37:39 +0000 | [diff] [blame] | 7674 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 7675 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 7676 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7677 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 7678 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7679 | else |
| 7680 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 7681 | |
| 7682 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 7683 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) |
| 7684 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 7685 | BDINFO_FLAGS_DISABLED); |
| 7686 | |
| 7687 | |
| 7688 | /* Disable all receive return rings but the first. */ |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 7689 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 7690 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 7691 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
| 7692 | else if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7693 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7694 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 7695 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7696 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
| 7697 | else |
| 7698 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 7699 | |
| 7700 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 7701 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) |
| 7702 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 7703 | BDINFO_FLAGS_DISABLED); |
| 7704 | |
| 7705 | /* Disable interrupts */ |
| 7706 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); |
| 7707 | |
| 7708 | /* Zero mailbox registers. */ |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7709 | if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX) { |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 7710 | for (i = 1; i < tp->irq_max; i++) { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7711 | tp->napi[i].tx_prod = 0; |
| 7712 | tp->napi[i].tx_cons = 0; |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 7713 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
| 7714 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7715 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
| 7716 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); |
| 7717 | } |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 7718 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) |
| 7719 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7720 | } else { |
| 7721 | tp->napi[0].tx_prod = 0; |
| 7722 | tp->napi[0].tx_cons = 0; |
| 7723 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 7724 | tw32_rx_mbox(tp->napi[0].consmbox, 0); |
| 7725 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7726 | |
| 7727 | /* Make sure the NIC-based send BD rings are disabled. */ |
| 7728 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 7729 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 7730 | for (i = 0; i < 16; i++) |
| 7731 | tw32_tx_mbox(mbox + i * 8, 0); |
| 7732 | } |
| 7733 | |
| 7734 | txrcb = NIC_SRAM_SEND_RCB; |
| 7735 | rxrcb = NIC_SRAM_RCV_RET_RCB; |
| 7736 | |
| 7737 | /* Clear status block in ram. */ |
| 7738 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7739 | |
| 7740 | /* Set status block DMA address */ |
| 7741 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 7742 | ((u64) tnapi->status_mapping >> 32)); |
| 7743 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 7744 | ((u64) tnapi->status_mapping & 0xffffffff)); |
| 7745 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7746 | if (tnapi->tx_ring) { |
| 7747 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 7748 | (TG3_TX_RING_SIZE << |
| 7749 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 7750 | NIC_SRAM_TX_BUFFER_DESC); |
| 7751 | txrcb += TG3_BDINFO_SIZE; |
| 7752 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7753 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7754 | if (tnapi->rx_rcb) { |
| 7755 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 7756 | (tp->rx_ret_ring_mask + 1) << |
| 7757 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7758 | rxrcb += TG3_BDINFO_SIZE; |
| 7759 | } |
| 7760 | |
| 7761 | stblk = HOSTCC_STATBLCK_RING1; |
| 7762 | |
| 7763 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
| 7764 | u64 mapping = (u64)tnapi->status_mapping; |
| 7765 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); |
| 7766 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); |
| 7767 | |
| 7768 | /* Clear status block in ram. */ |
| 7769 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7770 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7771 | if (tnapi->tx_ring) { |
| 7772 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 7773 | (TG3_TX_RING_SIZE << |
| 7774 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 7775 | NIC_SRAM_TX_BUFFER_DESC); |
| 7776 | txrcb += TG3_BDINFO_SIZE; |
| 7777 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7778 | |
| 7779 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 7780 | ((tp->rx_ret_ring_mask + 1) << |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7781 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
| 7782 | |
| 7783 | stblk += 8; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7784 | rxrcb += TG3_BDINFO_SIZE; |
| 7785 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7786 | } |
| 7787 | |
| 7788 | /* tp->lock is held. */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 7789 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7790 | { |
| 7791 | u32 val, rdmac_mode; |
| 7792 | int i, err, limit; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7793 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7794 | |
| 7795 | tg3_disable_ints(tp); |
| 7796 | |
| 7797 | tg3_stop_fw(tp); |
| 7798 | |
| 7799 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); |
| 7800 | |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 7801 | if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 7802 | tg3_abort_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7803 | |
Matt Carlson | 603f117 | 2010-02-12 14:47:10 +0000 | [diff] [blame] | 7804 | if (reset_phy) |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 7805 | tg3_phy_reset(tp); |
| 7806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7807 | err = tg3_chip_reset(tp); |
| 7808 | if (err) |
| 7809 | return err; |
| 7810 | |
| 7811 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); |
| 7812 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 7813 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7814 | val = tr32(TG3_CPMU_CTRL); |
| 7815 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); |
| 7816 | tw32(TG3_CPMU_CTRL, val); |
Matt Carlson | 9acb961 | 2007-11-12 21:10:06 -0800 | [diff] [blame] | 7817 | |
| 7818 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 7819 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 7820 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 7821 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 7822 | |
| 7823 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); |
| 7824 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; |
| 7825 | val |= CPMU_LNK_AWARE_MACCLK_6_25; |
| 7826 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); |
| 7827 | |
| 7828 | val = tr32(TG3_CPMU_HST_ACC); |
| 7829 | val &= ~CPMU_HST_ACC_MACCLK_MASK; |
| 7830 | val |= CPMU_HST_ACC_MACCLK_6_25; |
| 7831 | tw32(TG3_CPMU_HST_ACC, val); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7832 | } |
| 7833 | |
Matt Carlson | 33466d9 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 7834 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 7835 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 7836 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | |
| 7837 | PCIE_PWR_MGMT_L1_THRESH_4MS; |
| 7838 | tw32(PCIE_PWR_MGMT_THRESH, val); |
Matt Carlson | 521e6b9 | 2009-08-25 10:06:01 +0000 | [diff] [blame] | 7839 | |
| 7840 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; |
| 7841 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); |
| 7842 | |
| 7843 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); |
Matt Carlson | 33466d9 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 7844 | |
Matt Carlson | f40386c | 2009-11-02 14:24:02 +0000 | [diff] [blame] | 7845 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 7846 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 7847 | } |
| 7848 | |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 7849 | if (tp->tg3_flags3 & TG3_FLG3_L1PLLPD_EN) { |
| 7850 | u32 grc_mode = tr32(GRC_MODE); |
| 7851 | |
| 7852 | /* Access the lower 1K of PL PCIE block registers. */ |
| 7853 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 7854 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 7855 | |
| 7856 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); |
| 7857 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, |
| 7858 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); |
| 7859 | |
| 7860 | tw32(GRC_MODE, grc_mode); |
| 7861 | } |
| 7862 | |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 7863 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 7864 | u32 grc_mode = tr32(GRC_MODE); |
| 7865 | |
| 7866 | /* Access the lower 1K of PL PCIE block registers. */ |
| 7867 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 7868 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 7869 | |
| 7870 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5); |
| 7871 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, |
| 7872 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); |
| 7873 | |
| 7874 | tw32(GRC_MODE, grc_mode); |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 7875 | |
| 7876 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 7877 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 7878 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 7879 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 7880 | } |
| 7881 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 7882 | /* Enable MAC control of LPI */ |
| 7883 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { |
| 7884 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, |
| 7885 | TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | |
| 7886 | TG3_CPMU_EEE_LNKIDL_UART_IDL); |
| 7887 | |
| 7888 | tw32_f(TG3_CPMU_EEE_CTRL, |
| 7889 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); |
| 7890 | |
| 7891 | tw32_f(TG3_CPMU_EEE_MODE, |
| 7892 | TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
| 7893 | TG3_CPMU_EEEMD_LPI_IN_TX | |
| 7894 | TG3_CPMU_EEEMD_LPI_IN_RX | |
| 7895 | TG3_CPMU_EEEMD_EEE_ENABLE); |
| 7896 | } |
| 7897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7898 | /* This works around an issue with Athlon chipsets on |
| 7899 | * B3 tigon3 silicon. This bit has no effect on any |
| 7900 | * other revision. But do not set this on PCI Express |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 7901 | * 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] | 7902 | */ |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 7903 | if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) { |
| 7904 | if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) |
| 7905 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
| 7906 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 7907 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7908 | |
| 7909 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
| 7910 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) { |
| 7911 | val = tr32(TG3PCI_PCISTATE); |
| 7912 | val |= PCISTATE_RETRY_SAME_DMA; |
| 7913 | tw32(TG3PCI_PCISTATE, val); |
| 7914 | } |
| 7915 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7916 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
| 7917 | /* Allow reads and writes to the |
| 7918 | * APE register and memory space. |
| 7919 | */ |
| 7920 | val = tr32(TG3PCI_PCISTATE); |
| 7921 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 7922 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 7923 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7924 | tw32(TG3PCI_PCISTATE, val); |
| 7925 | } |
| 7926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7927 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
| 7928 | /* Enable some hw fixes. */ |
| 7929 | val = tr32(TG3PCI_MSI_DATA); |
| 7930 | val |= (1 << 26) | (1 << 28) | (1 << 29); |
| 7931 | tw32(TG3PCI_MSI_DATA, val); |
| 7932 | } |
| 7933 | |
| 7934 | /* Descriptor ring init may make accesses to the |
| 7935 | * NIC SRAM area to setup the TX descriptors, so we |
| 7936 | * can only do this after the hardware has been |
| 7937 | * successfully reset. |
| 7938 | */ |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 7939 | err = tg3_init_rings(tp); |
| 7940 | if (err) |
| 7941 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7942 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 7943 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 7944 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
| 7945 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
Matt Carlson | 1a31902 | 2010-04-12 06:58:25 +0000 | [diff] [blame] | 7946 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
| 7947 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 7948 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
| 7949 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && |
| 7950 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7951 | /* This value is determined during the probe time DMA |
| 7952 | * engine test, tg3_test_dma. |
| 7953 | */ |
| 7954 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 7955 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7956 | |
| 7957 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | |
| 7958 | GRC_MODE_4X_NIC_SEND_RINGS | |
| 7959 | GRC_MODE_NO_TX_PHDR_CSUM | |
| 7960 | GRC_MODE_NO_RX_PHDR_CSUM); |
| 7961 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; |
Michael Chan | d2d746f | 2006-04-06 21:45:39 -0700 | [diff] [blame] | 7962 | |
| 7963 | /* Pseudo-header checksum is done by hardware logic and not |
| 7964 | * the offload processers, so make the chip do the pseudo- |
| 7965 | * header checksums on receive. For transmit it is more |
| 7966 | * convenient to do the pseudo-header checksum in software |
| 7967 | * as Linux does that on transmit for us in all cases. |
| 7968 | */ |
| 7969 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7970 | |
| 7971 | tw32(GRC_MODE, |
| 7972 | tp->grc_mode | |
| 7973 | (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP)); |
| 7974 | |
| 7975 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ |
| 7976 | val = tr32(GRC_MISC_CFG); |
| 7977 | val &= ~0xff; |
| 7978 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 7979 | tw32(GRC_MISC_CFG, val); |
| 7980 | |
| 7981 | /* Initialize MBUF/DESC pool. */ |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 7982 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7983 | /* Do nothing. */ |
| 7984 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { |
| 7985 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
| 7986 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 7987 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
| 7988 | else |
| 7989 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); |
| 7990 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); |
| 7991 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 7992 | } else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7993 | int fw_len; |
| 7994 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7995 | fw_len = tp->fw_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7996 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
| 7997 | tw32(BUFMGR_MB_POOL_ADDR, |
| 7998 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); |
| 7999 | tw32(BUFMGR_MB_POOL_SIZE, |
| 8000 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); |
| 8001 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8002 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 8003 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8004 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8005 | tp->bufmgr_config.mbuf_read_dma_low_water); |
| 8006 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 8007 | tp->bufmgr_config.mbuf_mac_rx_low_water); |
| 8008 | tw32(BUFMGR_MB_HIGH_WATER, |
| 8009 | tp->bufmgr_config.mbuf_high_water); |
| 8010 | } else { |
| 8011 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8012 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); |
| 8013 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 8014 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); |
| 8015 | tw32(BUFMGR_MB_HIGH_WATER, |
| 8016 | tp->bufmgr_config.mbuf_high_water_jumbo); |
| 8017 | } |
| 8018 | tw32(BUFMGR_DMA_LOW_WATER, |
| 8019 | tp->bufmgr_config.dma_low_water); |
| 8020 | tw32(BUFMGR_DMA_HIGH_WATER, |
| 8021 | tp->bufmgr_config.dma_high_water); |
| 8022 | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8023 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
| 8024 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 8025 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; |
| 8026 | tw32(BUFMGR_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8027 | for (i = 0; i < 2000; i++) { |
| 8028 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) |
| 8029 | break; |
| 8030 | udelay(10); |
| 8031 | } |
| 8032 | if (i >= 2000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 8033 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8034 | return -ENODEV; |
| 8035 | } |
| 8036 | |
| 8037 | /* Setup replenish threshold. */ |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 8038 | val = tp->rx_pending / 8; |
| 8039 | if (val == 0) |
| 8040 | val = 1; |
| 8041 | else if (val > tp->rx_std_max_post) |
| 8042 | val = tp->rx_std_max_post; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 8043 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 8044 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) |
| 8045 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
| 8046 | |
| 8047 | if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2)) |
| 8048 | val = TG3_RX_INTERNAL_RING_SZ_5906 / 2; |
| 8049 | } |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 8050 | |
| 8051 | tw32(RCVBDI_STD_THRESH, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8052 | |
| 8053 | /* Initialize TG3_BDINFO's at: |
| 8054 | * RCVDBDI_STD_BD: standard eth size rx ring |
| 8055 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring |
| 8056 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) |
| 8057 | * |
| 8058 | * like so: |
| 8059 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring |
| 8060 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | |
| 8061 | * ring attribute flags |
| 8062 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM |
| 8063 | * |
| 8064 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. |
| 8065 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. |
| 8066 | * |
| 8067 | * The size of each ring is fixed in the firmware, but the location is |
| 8068 | * configurable. |
| 8069 | */ |
| 8070 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8071 | ((u64) tpr->rx_std_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8072 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8073 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 8074 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 8075 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5719) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 8076 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
| 8077 | NIC_SRAM_RX_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8078 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8079 | /* Disable the mini ring */ |
| 8080 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8081 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 8082 | BDINFO_FLAGS_DISABLED); |
| 8083 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8084 | /* Program the jumbo buffer descriptor ring control |
| 8085 | * blocks on those devices that have them. |
| 8086 | */ |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 8087 | if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8088 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8089 | /* Setup replenish threshold. */ |
| 8090 | tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8); |
| 8091 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 8092 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8093 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8094 | ((u64) tpr->rx_jmb_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8095 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8096 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8097 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 8098 | (RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT) | |
| 8099 | BDINFO_FLAGS_USE_EXT_RECV); |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 8100 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) || |
| 8101 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 8102 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
| 8103 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8104 | } else { |
| 8105 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 8106 | BDINFO_FLAGS_DISABLED); |
| 8107 | } |
| 8108 | |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8109 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
| 8110 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 8111 | val = RX_STD_MAX_SIZE_5705; |
| 8112 | else |
| 8113 | val = RX_STD_MAX_SIZE_5717; |
| 8114 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
| 8115 | val |= (TG3_RX_STD_DMA_SZ << 2); |
| 8116 | } else |
Matt Carlson | 04380d4 | 2010-04-12 06:58:29 +0000 | [diff] [blame] | 8117 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8118 | } else |
| 8119 | val = RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT; |
| 8120 | |
| 8121 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8122 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 8123 | tpr->rx_std_prod_idx = tp->rx_pending; |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 8124 | 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] | 8125 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 8126 | tpr->rx_jmb_prod_idx = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ? |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8127 | tp->rx_jumbo_pending : 0; |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 8128 | 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] | 8129 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 8130 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8131 | tw32(STD_REPLENISH_LWM, 32); |
| 8132 | tw32(JMB_REPLENISH_LWM, 16); |
| 8133 | } |
| 8134 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8135 | tg3_rings_reset(tp); |
| 8136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8137 | /* Initialize MAC address and backoff seed. */ |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8138 | __tg3_set_mac_addr(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8139 | |
| 8140 | /* MTU + ethernet header + FCS + optional VLAN tag */ |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 8141 | tw32(MAC_RX_MTU_SIZE, |
| 8142 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8143 | |
| 8144 | /* The slot time is changed by tg3_setup_phy if we |
| 8145 | * run at gigabit with half duplex. |
| 8146 | */ |
| 8147 | tw32(MAC_TX_LENGTHS, |
| 8148 | (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 8149 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 8150 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); |
| 8151 | |
| 8152 | /* Receive rules. */ |
| 8153 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); |
| 8154 | tw32(RCVLPC_CONFIG, 0x0181); |
| 8155 | |
| 8156 | /* Calculate RDMAC_MODE setting early, we need it to determine |
| 8157 | * the RCVLPC_STATE_ENABLE mask. |
| 8158 | */ |
| 8159 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | |
| 8160 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | |
| 8161 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | |
| 8162 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | |
| 8163 | RDMAC_MODE_LNGREAD_ENAB); |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8164 | |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 8165 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 8166 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | 0339e4e | 2010-02-12 14:47:09 +0000 | [diff] [blame] | 8167 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
| 8168 | |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 8169 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8170 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 8171 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8172 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
| 8173 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | |
| 8174 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; |
| 8175 | |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8176 | /* If statement applies to 5705 and 5750 PCI devices only */ |
| 8177 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 8178 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) || |
| 8179 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8180 | if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE && |
Matt Carlson | c13e371 | 2007-05-05 11:50:04 -0700 | [diff] [blame] | 8181 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8182 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
| 8183 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
| 8184 | !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) { |
| 8185 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 8186 | } |
| 8187 | } |
| 8188 | |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8189 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) |
| 8190 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 8191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8192 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 8193 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
| 8194 | |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 8195 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
| 8196 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 8197 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
| 8198 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8199 | |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8200 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 8201 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 8202 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 8203 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 8204 | (tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { |
| 8205 | val = tr32(TG3_RDMA_RSRVCTRL_REG); |
| 8206 | tw32(TG3_RDMA_RSRVCTRL_REG, |
| 8207 | val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); |
| 8208 | } |
| 8209 | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8210 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
| 8211 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 8212 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val | |
| 8213 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | |
| 8214 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); |
| 8215 | } |
| 8216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8217 | /* Receive/send statistics. */ |
Michael Chan | 1661394 | 2006-06-29 20:15:13 -0700 | [diff] [blame] | 8218 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
| 8219 | val = tr32(RCVLPC_STATS_ENABLE); |
| 8220 | val &= ~RCVLPC_STATSENAB_DACK_FIX; |
| 8221 | tw32(RCVLPC_STATS_ENABLE, val); |
| 8222 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && |
| 8223 | (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8224 | val = tr32(RCVLPC_STATS_ENABLE); |
| 8225 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; |
| 8226 | tw32(RCVLPC_STATS_ENABLE, val); |
| 8227 | } else { |
| 8228 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); |
| 8229 | } |
| 8230 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); |
| 8231 | tw32(SNDDATAI_STATSENAB, 0xffffff); |
| 8232 | tw32(SNDDATAI_STATSCTRL, |
| 8233 | (SNDDATAI_SCTRL_ENABLE | |
| 8234 | SNDDATAI_SCTRL_FASTUPD)); |
| 8235 | |
| 8236 | /* Setup host coalescing engine. */ |
| 8237 | tw32(HOSTCC_MODE, 0); |
| 8238 | for (i = 0; i < 2000; i++) { |
| 8239 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) |
| 8240 | break; |
| 8241 | udelay(10); |
| 8242 | } |
| 8243 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 8244 | __tg3_set_coalesce(tp, &tp->coal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8246 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 8247 | /* Status/statistics block address. See tg3_timer, |
| 8248 | * the tg3_periodic_fetch_stats call there, and |
| 8249 | * tg3_get_stats to see how this works for 5705/5750 chips. |
| 8250 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8251 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 8252 | ((u64) tp->stats_mapping >> 32)); |
| 8253 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 8254 | ((u64) tp->stats_mapping & 0xffffffff)); |
| 8255 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8257 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8258 | |
| 8259 | /* Clear statistics and status block memory areas */ |
| 8260 | for (i = NIC_SRAM_STATS_BLK; |
| 8261 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; |
| 8262 | i += sizeof(u32)) { |
| 8263 | tg3_write_mem(tp, i, 0); |
| 8264 | udelay(40); |
| 8265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8266 | } |
| 8267 | |
| 8268 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); |
| 8269 | |
| 8270 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); |
| 8271 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); |
| 8272 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 8273 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
| 8274 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8275 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
| 8276 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 8277 | /* reset to prevent losing 1st rx packet intermittently */ |
| 8278 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 8279 | udelay(10); |
| 8280 | } |
| 8281 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 8282 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 8283 | tp->mac_mode &= MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
| 8284 | else |
| 8285 | tp->mac_mode = 0; |
| 8286 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8287 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 8288 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8289 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 8290 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
| 8291 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8292 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
| 8293 | udelay(40); |
| 8294 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8295 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8296 | * If TG3_FLG2_IS_NIC is zero, we should read the |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8297 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
| 8298 | * whether used as inputs or outputs, are set by boot code after |
| 8299 | * reset. |
| 8300 | */ |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8301 | if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8302 | u32 gpio_mask; |
| 8303 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8304 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
| 8305 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 8306 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 8307 | |
| 8308 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 8309 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
| 8310 | GRC_LCLCTRL_GPIO_OUTPUT3; |
| 8311 | |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 8312 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 8313 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 8314 | |
Gary Zambrano | aaf8446 | 2007-05-05 11:51:45 -0700 | [diff] [blame] | 8315 | tp->grc_local_ctrl &= ~gpio_mask; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8316 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
| 8317 | |
| 8318 | /* GPIO1 must be driven high for eeprom write protect */ |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8319 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) |
| 8320 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 8321 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8323 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 8324 | udelay(100); |
| 8325 | |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8326 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) { |
| 8327 | val = tr32(MSGINT_MODE); |
| 8328 | val |= MSGINT_MODE_MULTIVEC_EN | MSGINT_MODE_ENABLE; |
| 8329 | tw32(MSGINT_MODE, val); |
| 8330 | } |
| 8331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8332 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 8333 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
| 8334 | udelay(40); |
| 8335 | } |
| 8336 | |
| 8337 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | |
| 8338 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | |
| 8339 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | |
| 8340 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | |
| 8341 | WDMAC_MODE_LNGREAD_ENAB); |
| 8342 | |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8343 | /* If statement applies to 5705 and 5750 PCI devices only */ |
| 8344 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 8345 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) || |
| 8346 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) { |
Matt Carlson | 29ea095 | 2009-08-25 10:07:54 +0000 | [diff] [blame] | 8347 | if ((tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8348 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
| 8349 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { |
| 8350 | /* nothing */ |
| 8351 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
| 8352 | !(tp->tg3_flags2 & TG3_FLG2_IS_5788) && |
| 8353 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) { |
| 8354 | val |= WDMAC_MODE_RX_ACCEL; |
| 8355 | } |
| 8356 | } |
| 8357 | |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8358 | /* Enable host coalescing bug fix */ |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8359 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 8360 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8361 | |
Matt Carlson | 788a035 | 2009-11-02 14:26:03 +0000 | [diff] [blame] | 8362 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 8363 | val |= WDMAC_MODE_BURST_ALL_DATA; |
| 8364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8365 | tw32_f(WDMAC_MODE, val); |
| 8366 | udelay(40); |
| 8367 | |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8368 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
| 8369 | u16 pcix_cmd; |
| 8370 | |
| 8371 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8372 | &pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8373 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8374 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
| 8375 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8376 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8377 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
| 8378 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8379 | } |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8380 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8381 | pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8382 | } |
| 8383 | |
| 8384 | tw32_f(RDMAC_MODE, rdmac_mode); |
| 8385 | udelay(40); |
| 8386 | |
| 8387 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
| 8388 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 8389 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 8390 | |
| 8391 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 8392 | tw32(SNDDATAC_MODE, |
| 8393 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); |
| 8394 | else |
| 8395 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); |
| 8396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8397 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
| 8398 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8399 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
| 8400 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 8401 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 8402 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
| 8403 | tw32(RCVDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8404 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8405 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
| 8406 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8407 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8408 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8409 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
| 8410 | tw32(SNDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8411 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
| 8412 | |
| 8413 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 8414 | err = tg3_load_5701_a0_firmware_fix(tp); |
| 8415 | if (err) |
| 8416 | return err; |
| 8417 | } |
| 8418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8419 | if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) { |
| 8420 | err = tg3_load_tso_firmware(tp); |
| 8421 | if (err) |
| 8422 | return err; |
| 8423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8424 | |
| 8425 | tp->tx_mode = TX_MODE_ENABLE; |
Matt Carlson | b1d0521 | 2010-06-05 17:24:31 +0000 | [diff] [blame] | 8426 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
| 8427 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 8428 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8429 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 8430 | udelay(100); |
| 8431 | |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8432 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) { |
| 8433 | u32 reg = MAC_RSS_INDIR_TBL_0; |
| 8434 | u8 *ent = (u8 *)&val; |
| 8435 | |
| 8436 | /* Setup the indirection table */ |
| 8437 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { |
| 8438 | int idx = i % sizeof(val); |
| 8439 | |
Matt Carlson | 5efeeea | 2010-07-11 09:31:40 +0000 | [diff] [blame] | 8440 | ent[idx] = i % (tp->irq_cnt - 1); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8441 | if (idx == sizeof(val) - 1) { |
| 8442 | tw32(reg, val); |
| 8443 | reg += 4; |
| 8444 | } |
| 8445 | } |
| 8446 | |
| 8447 | /* Setup the "secret" hash key. */ |
| 8448 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); |
| 8449 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); |
| 8450 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); |
| 8451 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); |
| 8452 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); |
| 8453 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); |
| 8454 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); |
| 8455 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); |
| 8456 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); |
| 8457 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); |
| 8458 | } |
| 8459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8460 | tp->rx_mode = RX_MODE_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8461 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 8462 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
| 8463 | |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8464 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) |
| 8465 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
| 8466 | RX_MODE_RSS_ITBL_HASH_BITS_7 | |
| 8467 | RX_MODE_RSS_IPV6_HASH_EN | |
| 8468 | RX_MODE_RSS_TCP_IPV6_HASH_EN | |
| 8469 | RX_MODE_RSS_IPV4_HASH_EN | |
| 8470 | RX_MODE_RSS_TCP_IPV4_HASH_EN; |
| 8471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8472 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8473 | udelay(10); |
| 8474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8475 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 8476 | |
| 8477 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8478 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8479 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 8480 | udelay(10); |
| 8481 | } |
| 8482 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8483 | udelay(10); |
| 8484 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8485 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8486 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8487 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8488 | /* Set drive transmission level to 1.2V */ |
| 8489 | /* only if the signal pre-emphasis bit is not set */ |
| 8490 | val = tr32(MAC_SERDES_CFG); |
| 8491 | val &= 0xfffff000; |
| 8492 | val |= 0x880; |
| 8493 | tw32(MAC_SERDES_CFG, val); |
| 8494 | } |
| 8495 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) |
| 8496 | tw32(MAC_SERDES_CFG, 0x616000); |
| 8497 | } |
| 8498 | |
| 8499 | /* Prevent chip from dropping frames when flow control |
| 8500 | * is enabled. |
| 8501 | */ |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 8502 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 8503 | val = 1; |
| 8504 | else |
| 8505 | val = 2; |
| 8506 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8507 | |
| 8508 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8509 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8510 | /* Use hardware link auto-negotiation */ |
| 8511 | tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG; |
| 8512 | } |
| 8513 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8514 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 8515 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) { |
| 8516 | u32 tmp; |
| 8517 | |
| 8518 | tmp = tr32(SERDES_RX_CTRL); |
| 8519 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); |
| 8520 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; |
| 8521 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; |
| 8522 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 8523 | } |
| 8524 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8525 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)) { |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 8526 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 8527 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8528 | tp->link_config.speed = tp->link_config.orig_speed; |
| 8529 | tp->link_config.duplex = tp->link_config.orig_duplex; |
| 8530 | tp->link_config.autoneg = tp->link_config.orig_autoneg; |
| 8531 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8532 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8533 | err = tg3_setup_phy(tp, 0); |
| 8534 | if (err) |
| 8535 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8536 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8537 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 8538 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8539 | u32 tmp; |
| 8540 | |
| 8541 | /* Clear CRC stats. */ |
| 8542 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { |
| 8543 | tg3_writephy(tp, MII_TG3_TEST1, |
| 8544 | tmp | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 8545 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8547 | } |
| 8548 | } |
| 8549 | |
| 8550 | __tg3_set_rx_mode(tp->dev); |
| 8551 | |
| 8552 | /* Initialize receive rules. */ |
| 8553 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); |
| 8554 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 8555 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); |
| 8556 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 8557 | |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 8558 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 8559 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8560 | limit = 8; |
| 8561 | else |
| 8562 | limit = 16; |
| 8563 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) |
| 8564 | limit -= 4; |
| 8565 | switch (limit) { |
| 8566 | case 16: |
| 8567 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); |
| 8568 | case 15: |
| 8569 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); |
| 8570 | case 14: |
| 8571 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); |
| 8572 | case 13: |
| 8573 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); |
| 8574 | case 12: |
| 8575 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); |
| 8576 | case 11: |
| 8577 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); |
| 8578 | case 10: |
| 8579 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); |
| 8580 | case 9: |
| 8581 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); |
| 8582 | case 8: |
| 8583 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); |
| 8584 | case 7: |
| 8585 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); |
| 8586 | case 6: |
| 8587 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); |
| 8588 | case 5: |
| 8589 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); |
| 8590 | case 4: |
| 8591 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ |
| 8592 | case 3: |
| 8593 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ |
| 8594 | case 2: |
| 8595 | case 1: |
| 8596 | |
| 8597 | default: |
| 8598 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 8599 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8600 | |
Matt Carlson | 9ce768e | 2007-10-11 19:49:11 -0700 | [diff] [blame] | 8601 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 8602 | /* Write our heartbeat update interval to APE. */ |
| 8603 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, |
| 8604 | APE_HOST_HEARTBEAT_INT_DISABLE); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8606 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
| 8607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8608 | return 0; |
| 8609 | } |
| 8610 | |
| 8611 | /* Called at device open time to get the chip ready for |
| 8612 | * packet processing. Invoked with tp->lock held. |
| 8613 | */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8614 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8615 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8616 | tg3_switch_clocks(tp); |
| 8617 | |
| 8618 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 8619 | |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 8620 | return tg3_reset_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8621 | } |
| 8622 | |
| 8623 | #define TG3_STAT_ADD32(PSTAT, REG) \ |
| 8624 | do { u32 __val = tr32(REG); \ |
| 8625 | (PSTAT)->low += __val; \ |
| 8626 | if ((PSTAT)->low < __val) \ |
| 8627 | (PSTAT)->high += 1; \ |
| 8628 | } while (0) |
| 8629 | |
| 8630 | static void tg3_periodic_fetch_stats(struct tg3 *tp) |
| 8631 | { |
| 8632 | struct tg3_hw_stats *sp = tp->hw_stats; |
| 8633 | |
| 8634 | if (!netif_carrier_ok(tp->dev)) |
| 8635 | return; |
| 8636 | |
| 8637 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); |
| 8638 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); |
| 8639 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); |
| 8640 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); |
| 8641 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); |
| 8642 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); |
| 8643 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); |
| 8644 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); |
| 8645 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); |
| 8646 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); |
| 8647 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); |
| 8648 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); |
| 8649 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); |
| 8650 | |
| 8651 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); |
| 8652 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); |
| 8653 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); |
| 8654 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); |
| 8655 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); |
| 8656 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); |
| 8657 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); |
| 8658 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); |
| 8659 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); |
| 8660 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); |
| 8661 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); |
| 8662 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); |
| 8663 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); |
| 8664 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 8665 | |
| 8666 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); |
| 8667 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
| 8668 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8669 | } |
| 8670 | |
| 8671 | static void tg3_timer(unsigned long __opaque) |
| 8672 | { |
| 8673 | struct tg3 *tp = (struct tg3 *) __opaque; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8674 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 8675 | if (tp->irq_sync) |
| 8676 | goto restart_timer; |
| 8677 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8678 | spin_lock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8679 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8680 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) { |
| 8681 | /* All of this garbage is because when using non-tagged |
| 8682 | * IRQ status the mailbox/status_block protocol the chip |
| 8683 | * uses with the cpu is race prone. |
| 8684 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8685 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8686 | tw32(GRC_LOCAL_CTRL, |
| 8687 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 8688 | } else { |
| 8689 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 8690 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8691 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8692 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8693 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 8694 | tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8695 | spin_unlock(&tp->lock); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8696 | schedule_work(&tp->reset_task); |
| 8697 | return; |
| 8698 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8699 | } |
| 8700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8701 | /* This part only runs once per second. */ |
| 8702 | if (!--tp->timer_counter) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8703 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
| 8704 | tg3_periodic_fetch_stats(tp); |
| 8705 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 8706 | if (tp->setlpicnt && !--tp->setlpicnt) { |
| 8707 | u32 val = tr32(TG3_CPMU_EEE_MODE); |
| 8708 | tw32(TG3_CPMU_EEE_MODE, |
| 8709 | val | TG3_CPMU_EEEMD_LPI_ENABLE); |
| 8710 | } |
| 8711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8712 | if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) { |
| 8713 | u32 mac_stat; |
| 8714 | int phy_event; |
| 8715 | |
| 8716 | mac_stat = tr32(MAC_STATUS); |
| 8717 | |
| 8718 | phy_event = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8719 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8720 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
| 8721 | phy_event = 1; |
| 8722 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) |
| 8723 | phy_event = 1; |
| 8724 | |
| 8725 | if (phy_event) |
| 8726 | tg3_setup_phy(tp, 0); |
| 8727 | } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) { |
| 8728 | u32 mac_stat = tr32(MAC_STATUS); |
| 8729 | int need_setup = 0; |
| 8730 | |
| 8731 | if (netif_carrier_ok(tp->dev) && |
| 8732 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
| 8733 | need_setup = 1; |
| 8734 | } |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 8735 | if (!netif_carrier_ok(tp->dev) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8736 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
| 8737 | MAC_STATUS_SIGNAL_DET))) { |
| 8738 | need_setup = 1; |
| 8739 | } |
| 8740 | if (need_setup) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 8741 | if (!tp->serdes_counter) { |
| 8742 | tw32_f(MAC_MODE, |
| 8743 | (tp->mac_mode & |
| 8744 | ~MAC_MODE_PORT_MODE_MASK)); |
| 8745 | udelay(40); |
| 8746 | tw32_f(MAC_MODE, tp->mac_mode); |
| 8747 | udelay(40); |
| 8748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8749 | tg3_setup_phy(tp, 0); |
| 8750 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8751 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Matt Carlson | 2138c00 | 2010-07-11 09:31:43 +0000 | [diff] [blame] | 8752 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 8753 | tg3_serdes_parallel_detect(tp); |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 8754 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8755 | |
| 8756 | tp->timer_counter = tp->timer_multiplier; |
| 8757 | } |
| 8758 | |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 8759 | /* Heartbeat is only sent once every 2 seconds. |
| 8760 | * |
| 8761 | * The heartbeat is to tell the ASF firmware that the host |
| 8762 | * driver is still alive. In the event that the OS crashes, |
| 8763 | * ASF needs to reset the hardware to free up the FIFO space |
| 8764 | * that may be filled with rx packets destined for the host. |
| 8765 | * If the FIFO is full, ASF will no longer function properly. |
| 8766 | * |
| 8767 | * Unintended resets have been reported on real time kernels |
| 8768 | * where the timer doesn't run on time. Netpoll will also have |
| 8769 | * same problem. |
| 8770 | * |
| 8771 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware |
| 8772 | * to check the ring condition when the heartbeat is expiring |
| 8773 | * before doing the reset. This will prevent most unintended |
| 8774 | * resets. |
| 8775 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8776 | if (!--tp->asf_counter) { |
Matt Carlson | bc7959b | 2008-08-15 14:08:55 -0700 | [diff] [blame] | 8777 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) && |
| 8778 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 8779 | tg3_wait_for_event_ack(tp); |
| 8780 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 8781 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 8782 | FWCMD_NICDRV_ALIVE3); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 8783 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 8784 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
| 8785 | TG3_FW_UPDATE_TIMEOUT_SEC); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 8786 | |
| 8787 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8788 | } |
| 8789 | tp->asf_counter = tp->asf_multiplier; |
| 8790 | } |
| 8791 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8792 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8793 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 8794 | restart_timer: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8795 | tp->timer.expires = jiffies + tp->timer_offset; |
| 8796 | add_timer(&tp->timer); |
| 8797 | } |
| 8798 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8799 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8800 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 8801 | irq_handler_t fn; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8802 | unsigned long flags; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8803 | char *name; |
| 8804 | struct tg3_napi *tnapi = &tp->napi[irq_num]; |
| 8805 | |
| 8806 | if (tp->irq_cnt == 1) |
| 8807 | name = tp->dev->name; |
| 8808 | else { |
| 8809 | name = &tnapi->irq_lbl[0]; |
| 8810 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); |
| 8811 | name[IFNAMSIZ-1] = 0; |
| 8812 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8813 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8814 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI_OR_MSIX) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8815 | fn = tg3_msi; |
| 8816 | if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) |
| 8817 | fn = tg3_msi_1shot; |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 8818 | flags = IRQF_SAMPLE_RANDOM; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8819 | } else { |
| 8820 | fn = tg3_interrupt; |
| 8821 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) |
| 8822 | fn = tg3_interrupt_tagged; |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 8823 | flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8824 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8825 | |
| 8826 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8827 | } |
| 8828 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8829 | static int tg3_test_interrupt(struct tg3 *tp) |
| 8830 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8831 | struct tg3_napi *tnapi = &tp->napi[0]; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8832 | struct net_device *dev = tp->dev; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8833 | int err, i, intr_ok = 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8834 | u32 val; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8835 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 8836 | if (!netif_running(dev)) |
| 8837 | return -ENODEV; |
| 8838 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8839 | tg3_disable_ints(tp); |
| 8840 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8841 | free_irq(tnapi->irq_vec, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8842 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8843 | /* |
| 8844 | * Turn off MSI one shot mode. Otherwise this test has no |
| 8845 | * observable way to know whether the interrupt was delivered. |
| 8846 | */ |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 8847 | if ((tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8848 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { |
| 8849 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
| 8850 | tw32(MSGINT_MODE, val); |
| 8851 | } |
| 8852 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8853 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8854 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8855 | if (err) |
| 8856 | return err; |
| 8857 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8858 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8859 | tg3_enable_ints(tp); |
| 8860 | |
| 8861 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 8862 | tnapi->coal_now); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8863 | |
| 8864 | for (i = 0; i < 5; i++) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8865 | u32 int_mbox, misc_host_ctrl; |
| 8866 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8867 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8868 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 8869 | |
| 8870 | if ((int_mbox != 0) || |
| 8871 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { |
| 8872 | intr_ok = 1; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8873 | break; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8874 | } |
| 8875 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8876 | msleep(10); |
| 8877 | } |
| 8878 | |
| 8879 | tg3_disable_ints(tp); |
| 8880 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8881 | free_irq(tnapi->irq_vec, tnapi); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 8882 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8883 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8884 | |
| 8885 | if (err) |
| 8886 | return err; |
| 8887 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8888 | if (intr_ok) { |
| 8889 | /* Reenable MSI one shot mode. */ |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 8890 | if ((tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8891 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { |
| 8892 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
| 8893 | tw32(MSGINT_MODE, val); |
| 8894 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8895 | return 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8896 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8897 | |
| 8898 | return -EIO; |
| 8899 | } |
| 8900 | |
| 8901 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is |
| 8902 | * successfully restored |
| 8903 | */ |
| 8904 | static int tg3_test_msi(struct tg3 *tp) |
| 8905 | { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8906 | int err; |
| 8907 | u16 pci_cmd; |
| 8908 | |
| 8909 | if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI)) |
| 8910 | return 0; |
| 8911 | |
| 8912 | /* Turn off SERR reporting in case MSI terminates with Master |
| 8913 | * Abort. |
| 8914 | */ |
| 8915 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 8916 | pci_write_config_word(tp->pdev, PCI_COMMAND, |
| 8917 | pci_cmd & ~PCI_COMMAND_SERR); |
| 8918 | |
| 8919 | err = tg3_test_interrupt(tp); |
| 8920 | |
| 8921 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 8922 | |
| 8923 | if (!err) |
| 8924 | return 0; |
| 8925 | |
| 8926 | /* other failures */ |
| 8927 | if (err != -EIO) |
| 8928 | return err; |
| 8929 | |
| 8930 | /* MSI test failed, go back to INTx mode */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 8931 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
| 8932 | "to INTx mode. Please report this failure to the PCI " |
| 8933 | "maintainer and include system chipset information\n"); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8934 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8935 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8936 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8937 | pci_disable_msi(tp->pdev); |
| 8938 | |
| 8939 | tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI; |
Andre Detsch | dc8bf1b | 2010-04-26 07:27:07 +0000 | [diff] [blame] | 8940 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8941 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8942 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8943 | if (err) |
| 8944 | return err; |
| 8945 | |
| 8946 | /* Need to reset the chip because the MSI cycle may have terminated |
| 8947 | * with Master Abort. |
| 8948 | */ |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8949 | tg3_full_lock(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8950 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8951 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8952 | err = tg3_init_hw(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8953 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8954 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8955 | |
| 8956 | if (err) |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8957 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8958 | |
| 8959 | return err; |
| 8960 | } |
| 8961 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8962 | static int tg3_request_firmware(struct tg3 *tp) |
| 8963 | { |
| 8964 | const __be32 *fw_data; |
| 8965 | |
| 8966 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 8967 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
| 8968 | tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8969 | return -ENOENT; |
| 8970 | } |
| 8971 | |
| 8972 | fw_data = (void *)tp->fw->data; |
| 8973 | |
| 8974 | /* Firmware blob starts with version numbers, followed by |
| 8975 | * start address and _full_ length including BSS sections |
| 8976 | * (which must be longer than the actual data, of course |
| 8977 | */ |
| 8978 | |
| 8979 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ |
| 8980 | if (tp->fw_len < (tp->fw->size - 12)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 8981 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
| 8982 | tp->fw_len, tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8983 | release_firmware(tp->fw); |
| 8984 | tp->fw = NULL; |
| 8985 | return -EINVAL; |
| 8986 | } |
| 8987 | |
| 8988 | /* We no longer need firmware; we have it. */ |
| 8989 | tp->fw_needed = NULL; |
| 8990 | return 0; |
| 8991 | } |
| 8992 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8993 | static bool tg3_enable_msix(struct tg3 *tp) |
| 8994 | { |
| 8995 | int i, rc, cpus = num_online_cpus(); |
| 8996 | struct msix_entry msix_ent[tp->irq_max]; |
| 8997 | |
| 8998 | if (cpus == 1) |
| 8999 | /* Just fallback to the simpler MSI mode. */ |
| 9000 | return false; |
| 9001 | |
| 9002 | /* |
| 9003 | * We want as many rx rings enabled as there are cpus. |
| 9004 | * The first MSIX vector only deals with link interrupts, etc, |
| 9005 | * so we add one to the number of vectors we are requesting. |
| 9006 | */ |
| 9007 | tp->irq_cnt = min_t(unsigned, cpus + 1, tp->irq_max); |
| 9008 | |
| 9009 | for (i = 0; i < tp->irq_max; i++) { |
| 9010 | msix_ent[i].entry = i; |
| 9011 | msix_ent[i].vector = 0; |
| 9012 | } |
| 9013 | |
| 9014 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9015 | if (rc < 0) { |
| 9016 | return false; |
| 9017 | } else if (rc != 0) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9018 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
| 9019 | return false; |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9020 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
| 9021 | tp->irq_cnt, rc); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9022 | tp->irq_cnt = rc; |
| 9023 | } |
| 9024 | |
| 9025 | for (i = 0; i < tp->irq_max; i++) |
| 9026 | tp->napi[i].irq_vec = msix_ent[i].vector; |
| 9027 | |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 9028 | netif_set_real_num_tx_queues(tp->dev, 1); |
| 9029 | rc = tp->irq_cnt > 1 ? tp->irq_cnt - 1 : 1; |
| 9030 | if (netif_set_real_num_rx_queues(tp->dev, rc)) { |
| 9031 | pci_disable_msix(tp->pdev); |
| 9032 | return false; |
| 9033 | } |
Matt Carlson | f0392d2 | 2010-09-15 08:59:54 +0000 | [diff] [blame] | 9034 | if (tp->irq_cnt > 1) |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9035 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_RSS; |
| 9036 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9037 | return true; |
| 9038 | } |
| 9039 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9040 | static void tg3_ints_init(struct tg3 *tp) |
| 9041 | { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9042 | if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSI_OR_MSIX) && |
| 9043 | !(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) { |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9044 | /* All MSI supporting chips should support tagged |
| 9045 | * status. Assert that this is the case. |
| 9046 | */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 9047 | netdev_warn(tp->dev, |
| 9048 | "MSI without TAGGED_STATUS? Not using MSI\n"); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9049 | goto defcfg; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9050 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9051 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9052 | if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX) && tg3_enable_msix(tp)) |
| 9053 | tp->tg3_flags2 |= TG3_FLG2_USING_MSIX; |
| 9054 | else if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) && |
| 9055 | pci_enable_msi(tp->pdev) == 0) |
| 9056 | tp->tg3_flags2 |= TG3_FLG2_USING_MSI; |
| 9057 | |
| 9058 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI_OR_MSIX) { |
| 9059 | u32 msi_mode = tr32(MSGINT_MODE); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9060 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) |
| 9061 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9062 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
| 9063 | } |
| 9064 | defcfg: |
| 9065 | if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSIX)) { |
| 9066 | tp->irq_cnt = 1; |
| 9067 | tp->napi[0].irq_vec = tp->pdev->irq; |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 9068 | netif_set_real_num_tx_queues(tp->dev, 1); |
Matt Carlson | 8540788 | 2010-10-06 13:40:58 -0700 | [diff] [blame] | 9069 | netif_set_real_num_rx_queues(tp->dev, 1); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9070 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9071 | } |
| 9072 | |
| 9073 | static void tg3_ints_fini(struct tg3 *tp) |
| 9074 | { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9075 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) |
| 9076 | pci_disable_msix(tp->pdev); |
| 9077 | else if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) |
| 9078 | pci_disable_msi(tp->pdev); |
| 9079 | tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI_OR_MSIX; |
Matt Carlson | 774ee75 | 2010-08-02 11:25:56 +0000 | [diff] [blame] | 9080 | tp->tg3_flags3 &= ~(TG3_FLG3_ENABLE_RSS | TG3_FLG3_ENABLE_TSS); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9081 | } |
| 9082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9083 | static int tg3_open(struct net_device *dev) |
| 9084 | { |
| 9085 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9086 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9087 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9088 | if (tp->fw_needed) { |
| 9089 | err = tg3_request_firmware(tp); |
| 9090 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 9091 | if (err) |
| 9092 | return err; |
| 9093 | } else if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9094 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9095 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE; |
| 9096 | } else if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9097 | netdev_notice(tp->dev, "TSO capability restored\n"); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9098 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
| 9099 | } |
| 9100 | } |
| 9101 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 9102 | netif_carrier_off(tp->dev); |
| 9103 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9104 | err = tg3_set_power_state(tp, PCI_D0); |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 9105 | if (err) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9106 | return err; |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 9107 | |
| 9108 | tg3_full_lock(tp, 0); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9110 | tg3_disable_ints(tp); |
| 9111 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
| 9112 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9113 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9114 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9115 | /* |
| 9116 | * Setup interrupts first so we know how |
| 9117 | * many NAPI resources to allocate |
| 9118 | */ |
| 9119 | tg3_ints_init(tp); |
| 9120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9121 | /* The placement of this call is tied |
| 9122 | * to the setup and use of Host TX descriptors. |
| 9123 | */ |
| 9124 | err = tg3_alloc_consistent(tp); |
| 9125 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9126 | goto err_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9127 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 9128 | tg3_napi_init(tp); |
| 9129 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 9130 | tg3_napi_enable(tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 9131 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9132 | for (i = 0; i < tp->irq_cnt; i++) { |
| 9133 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9134 | err = tg3_request_irq(tp, i); |
| 9135 | if (err) { |
| 9136 | for (i--; i >= 0; i--) |
| 9137 | free_irq(tnapi->irq_vec, tnapi); |
| 9138 | break; |
| 9139 | } |
| 9140 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9141 | |
| 9142 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9143 | goto err_out2; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9144 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9145 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9146 | |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 9147 | err = tg3_init_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9148 | if (err) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9149 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9150 | tg3_free_rings(tp); |
| 9151 | } else { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9152 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) |
| 9153 | tp->timer_offset = HZ; |
| 9154 | else |
| 9155 | tp->timer_offset = HZ / 10; |
| 9156 | |
| 9157 | BUG_ON(tp->timer_offset > HZ); |
| 9158 | tp->timer_counter = tp->timer_multiplier = |
| 9159 | (HZ / tp->timer_offset); |
| 9160 | tp->asf_counter = tp->asf_multiplier = |
Michael Chan | 28fbef7 | 2005-10-26 15:48:35 -0700 | [diff] [blame] | 9161 | ((HZ / tp->timer_offset) * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9162 | |
| 9163 | init_timer(&tp->timer); |
| 9164 | tp->timer.expires = jiffies + tp->timer_offset; |
| 9165 | tp->timer.data = (unsigned long) tp; |
| 9166 | tp->timer.function = tg3_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9167 | } |
| 9168 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9169 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9170 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9171 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9172 | goto err_out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9173 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9174 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { |
| 9175 | err = tg3_test_msi(tp); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9176 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9177 | if (err) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9178 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9179 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9180 | tg3_free_rings(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9181 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9182 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9183 | goto err_out2; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9184 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9185 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 9186 | if (!(tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
| 9187 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9188 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9189 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9190 | tw32(PCIE_TRANSACTION_CFG, |
| 9191 | val | PCIE_TRANS_CFG_1SHOT_MSI); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9192 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9193 | } |
| 9194 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9195 | tg3_phy_start(tp); |
| 9196 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9197 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9198 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9199 | add_timer(&tp->timer); |
| 9200 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9201 | tg3_enable_ints(tp); |
| 9202 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9203 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9204 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 9205 | netif_tx_start_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9206 | |
| 9207 | return 0; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9208 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9209 | err_out3: |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9210 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 9211 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9212 | free_irq(tnapi->irq_vec, tnapi); |
| 9213 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9214 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9215 | err_out2: |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 9216 | tg3_napi_disable(tp); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 9217 | tg3_napi_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9218 | tg3_free_consistent(tp); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9219 | |
| 9220 | err_out1: |
| 9221 | tg3_ints_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9222 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9223 | } |
| 9224 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9225 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *, |
| 9226 | struct rtnl_link_stats64 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9227 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *); |
| 9228 | |
| 9229 | static int tg3_close(struct net_device *dev) |
| 9230 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9231 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9232 | struct tg3 *tp = netdev_priv(dev); |
| 9233 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 9234 | tg3_napi_disable(tp); |
Oleg Nesterov | 28e53bd | 2007-05-09 02:34:22 -0700 | [diff] [blame] | 9235 | cancel_work_sync(&tp->reset_task); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 9236 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 9237 | netif_tx_stop_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9238 | |
| 9239 | del_timer_sync(&tp->timer); |
| 9240 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 9241 | tg3_phy_stop(tp); |
| 9242 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9243 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9244 | |
| 9245 | tg3_disable_ints(tp); |
| 9246 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9247 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9248 | tg3_free_rings(tp); |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 9249 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9250 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9251 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9252 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9253 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 9254 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9255 | free_irq(tnapi->irq_vec, tnapi); |
| 9256 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9257 | |
| 9258 | tg3_ints_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9259 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9260 | tg3_get_stats64(tp->dev, &tp->net_stats_prev); |
| 9261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9262 | memcpy(&tp->estats_prev, tg3_get_estats(tp), |
| 9263 | sizeof(tp->estats_prev)); |
| 9264 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 9265 | tg3_napi_fini(tp); |
| 9266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9267 | tg3_free_consistent(tp); |
| 9268 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9269 | tg3_set_power_state(tp, PCI_D3hot); |
| 9270 | |
| 9271 | netif_carrier_off(tp->dev); |
| 9272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9273 | return 0; |
| 9274 | } |
| 9275 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9276 | static inline u64 get_stat64(tg3_stat64_t *val) |
Stefan Buehler | 816f8b8 | 2008-08-15 14:10:54 -0700 | [diff] [blame] | 9277 | { |
| 9278 | return ((u64)val->high << 32) | ((u64)val->low); |
| 9279 | } |
| 9280 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9281 | static u64 calc_crc_errors(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9282 | { |
| 9283 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9284 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9285 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9286 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 9287 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9288 | u32 val; |
| 9289 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9290 | spin_lock_bh(&tp->lock); |
Michael Chan | 569a5df | 2007-02-13 12:18:15 -0800 | [diff] [blame] | 9291 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
| 9292 | tg3_writephy(tp, MII_TG3_TEST1, |
| 9293 | val | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 9294 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9295 | } else |
| 9296 | val = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9297 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9298 | |
| 9299 | tp->phy_crc_errors += val; |
| 9300 | |
| 9301 | return tp->phy_crc_errors; |
| 9302 | } |
| 9303 | |
| 9304 | return get_stat64(&hw_stats->rx_fcs_errors); |
| 9305 | } |
| 9306 | |
| 9307 | #define ESTAT_ADD(member) \ |
| 9308 | estats->member = old_estats->member + \ |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9309 | get_stat64(&hw_stats->member) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9310 | |
| 9311 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp) |
| 9312 | { |
| 9313 | struct tg3_ethtool_stats *estats = &tp->estats; |
| 9314 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
| 9315 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9316 | |
| 9317 | if (!hw_stats) |
| 9318 | return old_estats; |
| 9319 | |
| 9320 | ESTAT_ADD(rx_octets); |
| 9321 | ESTAT_ADD(rx_fragments); |
| 9322 | ESTAT_ADD(rx_ucast_packets); |
| 9323 | ESTAT_ADD(rx_mcast_packets); |
| 9324 | ESTAT_ADD(rx_bcast_packets); |
| 9325 | ESTAT_ADD(rx_fcs_errors); |
| 9326 | ESTAT_ADD(rx_align_errors); |
| 9327 | ESTAT_ADD(rx_xon_pause_rcvd); |
| 9328 | ESTAT_ADD(rx_xoff_pause_rcvd); |
| 9329 | ESTAT_ADD(rx_mac_ctrl_rcvd); |
| 9330 | ESTAT_ADD(rx_xoff_entered); |
| 9331 | ESTAT_ADD(rx_frame_too_long_errors); |
| 9332 | ESTAT_ADD(rx_jabbers); |
| 9333 | ESTAT_ADD(rx_undersize_packets); |
| 9334 | ESTAT_ADD(rx_in_length_errors); |
| 9335 | ESTAT_ADD(rx_out_length_errors); |
| 9336 | ESTAT_ADD(rx_64_or_less_octet_packets); |
| 9337 | ESTAT_ADD(rx_65_to_127_octet_packets); |
| 9338 | ESTAT_ADD(rx_128_to_255_octet_packets); |
| 9339 | ESTAT_ADD(rx_256_to_511_octet_packets); |
| 9340 | ESTAT_ADD(rx_512_to_1023_octet_packets); |
| 9341 | ESTAT_ADD(rx_1024_to_1522_octet_packets); |
| 9342 | ESTAT_ADD(rx_1523_to_2047_octet_packets); |
| 9343 | ESTAT_ADD(rx_2048_to_4095_octet_packets); |
| 9344 | ESTAT_ADD(rx_4096_to_8191_octet_packets); |
| 9345 | ESTAT_ADD(rx_8192_to_9022_octet_packets); |
| 9346 | |
| 9347 | ESTAT_ADD(tx_octets); |
| 9348 | ESTAT_ADD(tx_collisions); |
| 9349 | ESTAT_ADD(tx_xon_sent); |
| 9350 | ESTAT_ADD(tx_xoff_sent); |
| 9351 | ESTAT_ADD(tx_flow_control); |
| 9352 | ESTAT_ADD(tx_mac_errors); |
| 9353 | ESTAT_ADD(tx_single_collisions); |
| 9354 | ESTAT_ADD(tx_mult_collisions); |
| 9355 | ESTAT_ADD(tx_deferred); |
| 9356 | ESTAT_ADD(tx_excessive_collisions); |
| 9357 | ESTAT_ADD(tx_late_collisions); |
| 9358 | ESTAT_ADD(tx_collide_2times); |
| 9359 | ESTAT_ADD(tx_collide_3times); |
| 9360 | ESTAT_ADD(tx_collide_4times); |
| 9361 | ESTAT_ADD(tx_collide_5times); |
| 9362 | ESTAT_ADD(tx_collide_6times); |
| 9363 | ESTAT_ADD(tx_collide_7times); |
| 9364 | ESTAT_ADD(tx_collide_8times); |
| 9365 | ESTAT_ADD(tx_collide_9times); |
| 9366 | ESTAT_ADD(tx_collide_10times); |
| 9367 | ESTAT_ADD(tx_collide_11times); |
| 9368 | ESTAT_ADD(tx_collide_12times); |
| 9369 | ESTAT_ADD(tx_collide_13times); |
| 9370 | ESTAT_ADD(tx_collide_14times); |
| 9371 | ESTAT_ADD(tx_collide_15times); |
| 9372 | ESTAT_ADD(tx_ucast_packets); |
| 9373 | ESTAT_ADD(tx_mcast_packets); |
| 9374 | ESTAT_ADD(tx_bcast_packets); |
| 9375 | ESTAT_ADD(tx_carrier_sense_errors); |
| 9376 | ESTAT_ADD(tx_discards); |
| 9377 | ESTAT_ADD(tx_errors); |
| 9378 | |
| 9379 | ESTAT_ADD(dma_writeq_full); |
| 9380 | ESTAT_ADD(dma_write_prioq_full); |
| 9381 | ESTAT_ADD(rxbds_empty); |
| 9382 | ESTAT_ADD(rx_discards); |
| 9383 | ESTAT_ADD(rx_errors); |
| 9384 | ESTAT_ADD(rx_threshold_hit); |
| 9385 | |
| 9386 | ESTAT_ADD(dma_readq_full); |
| 9387 | ESTAT_ADD(dma_read_prioq_full); |
| 9388 | ESTAT_ADD(tx_comp_queue_full); |
| 9389 | |
| 9390 | ESTAT_ADD(ring_set_send_prod_index); |
| 9391 | ESTAT_ADD(ring_status_update); |
| 9392 | ESTAT_ADD(nic_irqs); |
| 9393 | ESTAT_ADD(nic_avoided_irqs); |
| 9394 | ESTAT_ADD(nic_tx_threshold_hit); |
| 9395 | |
| 9396 | return estats; |
| 9397 | } |
| 9398 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9399 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
| 9400 | struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9401 | { |
| 9402 | struct tg3 *tp = netdev_priv(dev); |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9403 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9404 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9405 | |
| 9406 | if (!hw_stats) |
| 9407 | return old_stats; |
| 9408 | |
| 9409 | stats->rx_packets = old_stats->rx_packets + |
| 9410 | get_stat64(&hw_stats->rx_ucast_packets) + |
| 9411 | get_stat64(&hw_stats->rx_mcast_packets) + |
| 9412 | get_stat64(&hw_stats->rx_bcast_packets); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9414 | stats->tx_packets = old_stats->tx_packets + |
| 9415 | get_stat64(&hw_stats->tx_ucast_packets) + |
| 9416 | get_stat64(&hw_stats->tx_mcast_packets) + |
| 9417 | get_stat64(&hw_stats->tx_bcast_packets); |
| 9418 | |
| 9419 | stats->rx_bytes = old_stats->rx_bytes + |
| 9420 | get_stat64(&hw_stats->rx_octets); |
| 9421 | stats->tx_bytes = old_stats->tx_bytes + |
| 9422 | get_stat64(&hw_stats->tx_octets); |
| 9423 | |
| 9424 | stats->rx_errors = old_stats->rx_errors + |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 9425 | get_stat64(&hw_stats->rx_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9426 | stats->tx_errors = old_stats->tx_errors + |
| 9427 | get_stat64(&hw_stats->tx_errors) + |
| 9428 | get_stat64(&hw_stats->tx_mac_errors) + |
| 9429 | get_stat64(&hw_stats->tx_carrier_sense_errors) + |
| 9430 | get_stat64(&hw_stats->tx_discards); |
| 9431 | |
| 9432 | stats->multicast = old_stats->multicast + |
| 9433 | get_stat64(&hw_stats->rx_mcast_packets); |
| 9434 | stats->collisions = old_stats->collisions + |
| 9435 | get_stat64(&hw_stats->tx_collisions); |
| 9436 | |
| 9437 | stats->rx_length_errors = old_stats->rx_length_errors + |
| 9438 | get_stat64(&hw_stats->rx_frame_too_long_errors) + |
| 9439 | get_stat64(&hw_stats->rx_undersize_packets); |
| 9440 | |
| 9441 | stats->rx_over_errors = old_stats->rx_over_errors + |
| 9442 | get_stat64(&hw_stats->rxbds_empty); |
| 9443 | stats->rx_frame_errors = old_stats->rx_frame_errors + |
| 9444 | get_stat64(&hw_stats->rx_align_errors); |
| 9445 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + |
| 9446 | get_stat64(&hw_stats->tx_discards); |
| 9447 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + |
| 9448 | get_stat64(&hw_stats->tx_carrier_sense_errors); |
| 9449 | |
| 9450 | stats->rx_crc_errors = old_stats->rx_crc_errors + |
| 9451 | calc_crc_errors(tp); |
| 9452 | |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 9453 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
| 9454 | get_stat64(&hw_stats->rx_discards); |
| 9455 | |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 9456 | stats->rx_dropped = tp->rx_dropped; |
| 9457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9458 | return stats; |
| 9459 | } |
| 9460 | |
| 9461 | static inline u32 calc_crc(unsigned char *buf, int len) |
| 9462 | { |
| 9463 | u32 reg; |
| 9464 | u32 tmp; |
| 9465 | int j, k; |
| 9466 | |
| 9467 | reg = 0xffffffff; |
| 9468 | |
| 9469 | for (j = 0; j < len; j++) { |
| 9470 | reg ^= buf[j]; |
| 9471 | |
| 9472 | for (k = 0; k < 8; k++) { |
| 9473 | tmp = reg & 0x01; |
| 9474 | |
| 9475 | reg >>= 1; |
| 9476 | |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 9477 | if (tmp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9478 | reg ^= 0xedb88320; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9479 | } |
| 9480 | } |
| 9481 | |
| 9482 | return ~reg; |
| 9483 | } |
| 9484 | |
| 9485 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) |
| 9486 | { |
| 9487 | /* accept or reject all multicast frames */ |
| 9488 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); |
| 9489 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); |
| 9490 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); |
| 9491 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); |
| 9492 | } |
| 9493 | |
| 9494 | static void __tg3_set_rx_mode(struct net_device *dev) |
| 9495 | { |
| 9496 | struct tg3 *tp = netdev_priv(dev); |
| 9497 | u32 rx_mode; |
| 9498 | |
| 9499 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
| 9500 | RX_MODE_KEEP_VLAN_TAG); |
| 9501 | |
| 9502 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
| 9503 | * flag clear. |
| 9504 | */ |
| 9505 | #if TG3_VLAN_TAG_USED |
| 9506 | if (!tp->vlgrp && |
| 9507 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 9508 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 9509 | #else |
| 9510 | /* By definition, VLAN is disabled always in this |
| 9511 | * case. |
| 9512 | */ |
| 9513 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 9514 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 9515 | #endif |
| 9516 | |
| 9517 | if (dev->flags & IFF_PROMISC) { |
| 9518 | /* Promiscuous mode. */ |
| 9519 | rx_mode |= RX_MODE_PROMISC; |
| 9520 | } else if (dev->flags & IFF_ALLMULTI) { |
| 9521 | /* Accept all multicast. */ |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 9522 | tg3_set_multi(tp, 1); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 9523 | } else if (netdev_mc_empty(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9524 | /* Reject all multicast. */ |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 9525 | tg3_set_multi(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9526 | } else { |
| 9527 | /* Accept one or more multicast(s). */ |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 9528 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9529 | u32 mc_filter[4] = { 0, }; |
| 9530 | u32 regidx; |
| 9531 | u32 bit; |
| 9532 | u32 crc; |
| 9533 | |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 9534 | netdev_for_each_mc_addr(ha, dev) { |
| 9535 | crc = calc_crc(ha->addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9536 | bit = ~crc & 0x7f; |
| 9537 | regidx = (bit & 0x60) >> 5; |
| 9538 | bit &= 0x1f; |
| 9539 | mc_filter[regidx] |= (1 << bit); |
| 9540 | } |
| 9541 | |
| 9542 | tw32(MAC_HASH_REG_0, mc_filter[0]); |
| 9543 | tw32(MAC_HASH_REG_1, mc_filter[1]); |
| 9544 | tw32(MAC_HASH_REG_2, mc_filter[2]); |
| 9545 | tw32(MAC_HASH_REG_3, mc_filter[3]); |
| 9546 | } |
| 9547 | |
| 9548 | if (rx_mode != tp->rx_mode) { |
| 9549 | tp->rx_mode = rx_mode; |
| 9550 | tw32_f(MAC_RX_MODE, rx_mode); |
| 9551 | udelay(10); |
| 9552 | } |
| 9553 | } |
| 9554 | |
| 9555 | static void tg3_set_rx_mode(struct net_device *dev) |
| 9556 | { |
| 9557 | struct tg3 *tp = netdev_priv(dev); |
| 9558 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 9559 | if (!netif_running(dev)) |
| 9560 | return; |
| 9561 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9562 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9563 | __tg3_set_rx_mode(dev); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9564 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9565 | } |
| 9566 | |
| 9567 | #define TG3_REGDUMP_LEN (32 * 1024) |
| 9568 | |
| 9569 | static int tg3_get_regs_len(struct net_device *dev) |
| 9570 | { |
| 9571 | return TG3_REGDUMP_LEN; |
| 9572 | } |
| 9573 | |
| 9574 | static void tg3_get_regs(struct net_device *dev, |
| 9575 | struct ethtool_regs *regs, void *_p) |
| 9576 | { |
| 9577 | u32 *p = _p; |
| 9578 | struct tg3 *tp = netdev_priv(dev); |
| 9579 | u8 *orig_p = _p; |
| 9580 | int i; |
| 9581 | |
| 9582 | regs->version = 0; |
| 9583 | |
| 9584 | memset(p, 0, TG3_REGDUMP_LEN); |
| 9585 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9586 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9587 | return; |
| 9588 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9589 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9590 | |
| 9591 | #define __GET_REG32(reg) (*(p)++ = tr32(reg)) |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 9592 | #define GET_REG32_LOOP(base, len) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9593 | do { p = (u32 *)(orig_p + (base)); \ |
| 9594 | for (i = 0; i < len; i += 4) \ |
| 9595 | __GET_REG32((base) + i); \ |
| 9596 | } while (0) |
| 9597 | #define GET_REG32_1(reg) \ |
| 9598 | do { p = (u32 *)(orig_p + (reg)); \ |
| 9599 | __GET_REG32((reg)); \ |
| 9600 | } while (0) |
| 9601 | |
| 9602 | GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0); |
| 9603 | GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200); |
| 9604 | GET_REG32_LOOP(MAC_MODE, 0x4f0); |
| 9605 | GET_REG32_LOOP(SNDDATAI_MODE, 0xe0); |
| 9606 | GET_REG32_1(SNDDATAC_MODE); |
| 9607 | GET_REG32_LOOP(SNDBDS_MODE, 0x80); |
| 9608 | GET_REG32_LOOP(SNDBDI_MODE, 0x48); |
| 9609 | GET_REG32_1(SNDBDC_MODE); |
| 9610 | GET_REG32_LOOP(RCVLPC_MODE, 0x20); |
| 9611 | GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c); |
| 9612 | GET_REG32_LOOP(RCVDBDI_MODE, 0x0c); |
| 9613 | GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c); |
| 9614 | GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44); |
| 9615 | GET_REG32_1(RCVDCC_MODE); |
| 9616 | GET_REG32_LOOP(RCVBDI_MODE, 0x20); |
| 9617 | GET_REG32_LOOP(RCVCC_MODE, 0x14); |
| 9618 | GET_REG32_LOOP(RCVLSC_MODE, 0x08); |
| 9619 | GET_REG32_1(MBFREE_MODE); |
| 9620 | GET_REG32_LOOP(HOSTCC_MODE, 0x100); |
| 9621 | GET_REG32_LOOP(MEMARB_MODE, 0x10); |
| 9622 | GET_REG32_LOOP(BUFMGR_MODE, 0x58); |
| 9623 | GET_REG32_LOOP(RDMAC_MODE, 0x08); |
| 9624 | GET_REG32_LOOP(WDMAC_MODE, 0x08); |
Chris Elmquist | 091465d | 2005-12-20 13:25:19 -0800 | [diff] [blame] | 9625 | GET_REG32_1(RX_CPU_MODE); |
| 9626 | GET_REG32_1(RX_CPU_STATE); |
| 9627 | GET_REG32_1(RX_CPU_PGMCTR); |
| 9628 | GET_REG32_1(RX_CPU_HWBKPT); |
| 9629 | GET_REG32_1(TX_CPU_MODE); |
| 9630 | GET_REG32_1(TX_CPU_STATE); |
| 9631 | GET_REG32_1(TX_CPU_PGMCTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9632 | GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110); |
| 9633 | GET_REG32_LOOP(FTQ_RESET, 0x120); |
| 9634 | GET_REG32_LOOP(MSGINT_MODE, 0x0c); |
| 9635 | GET_REG32_1(DMAC_MODE); |
| 9636 | GET_REG32_LOOP(GRC_MODE, 0x4c); |
| 9637 | if (tp->tg3_flags & TG3_FLAG_NVRAM) |
| 9638 | GET_REG32_LOOP(NVRAM_CMD, 0x24); |
| 9639 | |
| 9640 | #undef __GET_REG32 |
| 9641 | #undef GET_REG32_LOOP |
| 9642 | #undef GET_REG32_1 |
| 9643 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9644 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9645 | } |
| 9646 | |
| 9647 | static int tg3_get_eeprom_len(struct net_device *dev) |
| 9648 | { |
| 9649 | struct tg3 *tp = netdev_priv(dev); |
| 9650 | |
| 9651 | return tp->nvram_size; |
| 9652 | } |
| 9653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9654 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 9655 | { |
| 9656 | struct tg3 *tp = netdev_priv(dev); |
| 9657 | int ret; |
| 9658 | u8 *pd; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9659 | u32 i, offset, len, b_offset, b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9660 | __be32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9661 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 9662 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) |
| 9663 | return -EINVAL; |
| 9664 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9665 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9666 | return -EAGAIN; |
| 9667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9668 | offset = eeprom->offset; |
| 9669 | len = eeprom->len; |
| 9670 | eeprom->len = 0; |
| 9671 | |
| 9672 | eeprom->magic = TG3_EEPROM_MAGIC; |
| 9673 | |
| 9674 | if (offset & 3) { |
| 9675 | /* adjustments to start on required 4 byte boundary */ |
| 9676 | b_offset = offset & 3; |
| 9677 | b_count = 4 - b_offset; |
| 9678 | if (b_count > len) { |
| 9679 | /* i.e. offset=1 len=2 */ |
| 9680 | b_count = len; |
| 9681 | } |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9682 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9683 | if (ret) |
| 9684 | return ret; |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 9685 | memcpy(data, ((char *)&val) + b_offset, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9686 | len -= b_count; |
| 9687 | offset += b_count; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 9688 | eeprom->len += b_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9689 | } |
| 9690 | |
| 9691 | /* read bytes upto the last 4 byte boundary */ |
| 9692 | pd = &data[eeprom->len]; |
| 9693 | for (i = 0; i < (len - (len & 3)); i += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9694 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9695 | if (ret) { |
| 9696 | eeprom->len += i; |
| 9697 | return ret; |
| 9698 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9699 | memcpy(pd + i, &val, 4); |
| 9700 | } |
| 9701 | eeprom->len += i; |
| 9702 | |
| 9703 | if (len & 3) { |
| 9704 | /* read last bytes not ending on 4 byte boundary */ |
| 9705 | pd = &data[eeprom->len]; |
| 9706 | b_count = len & 3; |
| 9707 | b_offset = offset + len - b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9708 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9709 | if (ret) |
| 9710 | return ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9711 | memcpy(pd, &val, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9712 | eeprom->len += b_count; |
| 9713 | } |
| 9714 | return 0; |
| 9715 | } |
| 9716 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9717 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9718 | |
| 9719 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 9720 | { |
| 9721 | struct tg3 *tp = netdev_priv(dev); |
| 9722 | int ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9723 | u32 offset, len, b_offset, odd_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9724 | u8 *buf; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9725 | __be32 start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9726 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9727 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9728 | return -EAGAIN; |
| 9729 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 9730 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
| 9731 | eeprom->magic != TG3_EEPROM_MAGIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9732 | return -EINVAL; |
| 9733 | |
| 9734 | offset = eeprom->offset; |
| 9735 | len = eeprom->len; |
| 9736 | |
| 9737 | if ((b_offset = (offset & 3))) { |
| 9738 | /* adjustments to start on required 4 byte boundary */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9739 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9740 | if (ret) |
| 9741 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9742 | len += b_offset; |
| 9743 | offset &= ~3; |
Michael Chan | 1c8594b | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 9744 | if (len < 4) |
| 9745 | len = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9746 | } |
| 9747 | |
| 9748 | odd_len = 0; |
Michael Chan | 1c8594b | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 9749 | if (len & 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9750 | /* adjustments to end on required 4 byte boundary */ |
| 9751 | odd_len = 1; |
| 9752 | len = (len + 3) & ~3; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9753 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9754 | if (ret) |
| 9755 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9756 | } |
| 9757 | |
| 9758 | buf = data; |
| 9759 | if (b_offset || odd_len) { |
| 9760 | buf = kmalloc(len, GFP_KERNEL); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 9761 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9762 | return -ENOMEM; |
| 9763 | if (b_offset) |
| 9764 | memcpy(buf, &start, 4); |
| 9765 | if (odd_len) |
| 9766 | memcpy(buf+len-4, &end, 4); |
| 9767 | memcpy(buf + b_offset, data, eeprom->len); |
| 9768 | } |
| 9769 | |
| 9770 | ret = tg3_nvram_write_block(tp, offset, len, buf); |
| 9771 | |
| 9772 | if (buf != data) |
| 9773 | kfree(buf); |
| 9774 | |
| 9775 | return ret; |
| 9776 | } |
| 9777 | |
| 9778 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 9779 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9780 | struct tg3 *tp = netdev_priv(dev); |
| 9781 | |
| 9782 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9783 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9784 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9785 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9786 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 9787 | return phy_ethtool_gset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9788 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9790 | cmd->supported = (SUPPORTED_Autoneg); |
| 9791 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9792 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9793 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
| 9794 | SUPPORTED_1000baseT_Full); |
| 9795 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9796 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9797 | cmd->supported |= (SUPPORTED_100baseT_Half | |
| 9798 | SUPPORTED_100baseT_Full | |
| 9799 | SUPPORTED_10baseT_Half | |
| 9800 | SUPPORTED_10baseT_Full | |
Matt Carlson | 3bebab5 | 2007-11-12 21:22:40 -0800 | [diff] [blame] | 9801 | SUPPORTED_TP); |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 9802 | cmd->port = PORT_TP; |
| 9803 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9804 | cmd->supported |= SUPPORTED_FIBRE; |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 9805 | cmd->port = PORT_FIBRE; |
| 9806 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9808 | cmd->advertising = tp->link_config.advertising; |
| 9809 | if (netif_running(dev)) { |
| 9810 | cmd->speed = tp->link_config.active_speed; |
| 9811 | cmd->duplex = tp->link_config.active_duplex; |
Matt Carlson | 64c2218 | 2010-10-14 10:37:44 +0000 | [diff] [blame] | 9812 | } else { |
| 9813 | cmd->speed = SPEED_INVALID; |
| 9814 | cmd->duplex = DUPLEX_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9815 | } |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 9816 | cmd->phy_address = tp->phy_addr; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9817 | cmd->transceiver = XCVR_INTERNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9818 | cmd->autoneg = tp->link_config.autoneg; |
| 9819 | cmd->maxtxpkt = 0; |
| 9820 | cmd->maxrxpkt = 0; |
| 9821 | return 0; |
| 9822 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9824 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 9825 | { |
| 9826 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9827 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9828 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9829 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9830 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9831 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9832 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 9833 | return phy_ethtool_sset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9834 | } |
| 9835 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9836 | if (cmd->autoneg != AUTONEG_ENABLE && |
| 9837 | cmd->autoneg != AUTONEG_DISABLE) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 9838 | return -EINVAL; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9839 | |
| 9840 | if (cmd->autoneg == AUTONEG_DISABLE && |
| 9841 | cmd->duplex != DUPLEX_FULL && |
| 9842 | cmd->duplex != DUPLEX_HALF) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 9843 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9844 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9845 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 9846 | u32 mask = ADVERTISED_Autoneg | |
| 9847 | ADVERTISED_Pause | |
| 9848 | ADVERTISED_Asym_Pause; |
| 9849 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9850 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9851 | mask |= ADVERTISED_1000baseT_Half | |
| 9852 | ADVERTISED_1000baseT_Full; |
| 9853 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9854 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9855 | mask |= ADVERTISED_100baseT_Half | |
| 9856 | ADVERTISED_100baseT_Full | |
| 9857 | ADVERTISED_10baseT_Half | |
| 9858 | ADVERTISED_10baseT_Full | |
| 9859 | ADVERTISED_TP; |
| 9860 | else |
| 9861 | mask |= ADVERTISED_FIBRE; |
| 9862 | |
| 9863 | if (cmd->advertising & ~mask) |
| 9864 | return -EINVAL; |
| 9865 | |
| 9866 | mask &= (ADVERTISED_1000baseT_Half | |
| 9867 | ADVERTISED_1000baseT_Full | |
| 9868 | ADVERTISED_100baseT_Half | |
| 9869 | ADVERTISED_100baseT_Full | |
| 9870 | ADVERTISED_10baseT_Half | |
| 9871 | ADVERTISED_10baseT_Full); |
| 9872 | |
| 9873 | cmd->advertising &= mask; |
| 9874 | } else { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9875 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9876 | if (cmd->speed != SPEED_1000) |
| 9877 | return -EINVAL; |
| 9878 | |
| 9879 | if (cmd->duplex != DUPLEX_FULL) |
| 9880 | return -EINVAL; |
| 9881 | } else { |
| 9882 | if (cmd->speed != SPEED_100 && |
| 9883 | cmd->speed != SPEED_10) |
| 9884 | return -EINVAL; |
| 9885 | } |
| 9886 | } |
| 9887 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9888 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9889 | |
| 9890 | tp->link_config.autoneg = cmd->autoneg; |
| 9891 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Andy Gospodarek | 405d8e5 | 2007-10-08 01:08:47 -0700 | [diff] [blame] | 9892 | tp->link_config.advertising = (cmd->advertising | |
| 9893 | ADVERTISED_Autoneg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9894 | tp->link_config.speed = SPEED_INVALID; |
| 9895 | tp->link_config.duplex = DUPLEX_INVALID; |
| 9896 | } else { |
| 9897 | tp->link_config.advertising = 0; |
| 9898 | tp->link_config.speed = cmd->speed; |
| 9899 | tp->link_config.duplex = cmd->duplex; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9900 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9901 | |
Michael Chan | 24fcad6 | 2006-12-17 17:06:46 -0800 | [diff] [blame] | 9902 | tp->link_config.orig_speed = tp->link_config.speed; |
| 9903 | tp->link_config.orig_duplex = tp->link_config.duplex; |
| 9904 | tp->link_config.orig_autoneg = tp->link_config.autoneg; |
| 9905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9906 | if (netif_running(dev)) |
| 9907 | tg3_setup_phy(tp, 1); |
| 9908 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9909 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9911 | return 0; |
| 9912 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9914 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 9915 | { |
| 9916 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9918 | strcpy(info->driver, DRV_MODULE_NAME); |
| 9919 | strcpy(info->version, DRV_MODULE_VERSION); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 9920 | strcpy(info->fw_version, tp->fw_ver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9921 | strcpy(info->bus_info, pci_name(tp->pdev)); |
| 9922 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9924 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 9925 | { |
| 9926 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9927 | |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9928 | if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) && |
| 9929 | device_can_wakeup(&tp->pdev->dev)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 9930 | wol->supported = WAKE_MAGIC; |
| 9931 | else |
| 9932 | wol->supported = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9933 | wol->wolopts = 0; |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 9934 | if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) && |
| 9935 | device_can_wakeup(&tp->pdev->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9936 | wol->wolopts = WAKE_MAGIC; |
| 9937 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 9938 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9940 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 9941 | { |
| 9942 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9943 | struct device *dp = &tp->pdev->dev; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9945 | if (wol->wolopts & ~WAKE_MAGIC) |
| 9946 | return -EINVAL; |
| 9947 | if ((wol->wolopts & WAKE_MAGIC) && |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9948 | !((tp->tg3_flags & TG3_FLAG_WOL_CAP) && device_can_wakeup(dp))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9949 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9950 | |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 9951 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
| 9952 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9953 | spin_lock_bh(&tp->lock); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 9954 | if (device_may_wakeup(dp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9955 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 9956 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9957 | tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9958 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9959 | |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 9960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9961 | return 0; |
| 9962 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9964 | static u32 tg3_get_msglevel(struct net_device *dev) |
| 9965 | { |
| 9966 | struct tg3 *tp = netdev_priv(dev); |
| 9967 | return tp->msg_enable; |
| 9968 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9970 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
| 9971 | { |
| 9972 | struct tg3 *tp = netdev_priv(dev); |
| 9973 | tp->msg_enable = value; |
| 9974 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9976 | static int tg3_set_tso(struct net_device *dev, u32 value) |
| 9977 | { |
| 9978 | struct tg3 *tp = netdev_priv(dev); |
| 9979 | |
| 9980 | if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { |
| 9981 | if (value) |
| 9982 | return -EINVAL; |
| 9983 | return 0; |
| 9984 | } |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 9985 | if ((dev->features & NETIF_F_IPV6_CSUM) && |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 9986 | ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) || |
| 9987 | (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3))) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 9988 | if (value) { |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 9989 | dev->features |= NETIF_F_TSO6; |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 9990 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
| 9991 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 9992 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 9993 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 9994 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 9995 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 9996 | dev->features |= NETIF_F_TSO_ECN; |
| 9997 | } else |
| 9998 | dev->features &= ~(NETIF_F_TSO6 | NETIF_F_TSO_ECN); |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 9999 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10000 | return ethtool_op_set_tso(dev, value); |
| 10001 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10003 | static int tg3_nway_reset(struct net_device *dev) |
| 10004 | { |
| 10005 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10006 | int r; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10008 | if (!netif_running(dev)) |
| 10009 | return -EAGAIN; |
| 10010 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10011 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10012 | return -EINVAL; |
| 10013 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10014 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10015 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10016 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10017 | 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] | 10018 | } else { |
| 10019 | u32 bmcr; |
| 10020 | |
| 10021 | spin_lock_bh(&tp->lock); |
| 10022 | r = -EINVAL; |
| 10023 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 10024 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && |
| 10025 | ((bmcr & BMCR_ANENABLE) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10026 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10027 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
| 10028 | BMCR_ANENABLE); |
| 10029 | r = 0; |
| 10030 | } |
| 10031 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10032 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10034 | return r; |
| 10035 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10037 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 10038 | { |
| 10039 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10040 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10041 | ering->rx_max_pending = tp->rx_std_ring_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10042 | ering->rx_mini_max_pending = 0; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10043 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10044 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10045 | else |
| 10046 | ering->rx_jumbo_max_pending = 0; |
| 10047 | |
| 10048 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10049 | |
| 10050 | ering->rx_pending = tp->rx_pending; |
| 10051 | ering->rx_mini_pending = 0; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10052 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) |
| 10053 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
| 10054 | else |
| 10055 | ering->rx_jumbo_pending = 0; |
| 10056 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10057 | ering->tx_pending = tp->napi[0].tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10058 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10060 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 10061 | { |
| 10062 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10063 | int i, irq_sync = 0, err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10064 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10065 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
| 10066 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10067 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
| 10068 | (ering->tx_pending <= MAX_SKB_FRAGS) || |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 10069 | ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) && |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10070 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10071 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10072 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10073 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10074 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10075 | tg3_netif_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10076 | irq_sync = 1; |
| 10077 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10078 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10079 | tg3_full_lock(tp, irq_sync); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10081 | tp->rx_pending = ering->rx_pending; |
| 10082 | |
| 10083 | if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) && |
| 10084 | tp->rx_pending > 63) |
| 10085 | tp->rx_pending = 63; |
| 10086 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10087 | |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 10088 | for (i = 0; i < tp->irq_max; i++) |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10089 | tp->napi[i].tx_pending = ering->tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10090 | |
| 10091 | if (netif_running(dev)) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10092 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10093 | err = tg3_restart_hw(tp, 1); |
| 10094 | if (!err) |
| 10095 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10096 | } |
| 10097 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10098 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10099 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10100 | if (irq_sync && !err) |
| 10101 | tg3_phy_start(tp); |
| 10102 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10103 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10104 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10106 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10107 | { |
| 10108 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10110 | epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0; |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10111 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10112 | if (tp->link_config.active_flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10113 | epause->rx_pause = 1; |
| 10114 | else |
| 10115 | epause->rx_pause = 0; |
| 10116 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10117 | if (tp->link_config.active_flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10118 | epause->tx_pause = 1; |
| 10119 | else |
| 10120 | epause->tx_pause = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10121 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10123 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10124 | { |
| 10125 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10126 | int err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10127 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10128 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10129 | u32 newadv; |
| 10130 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10131 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10132 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10133 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10134 | if (!(phydev->supported & SUPPORTED_Pause) || |
| 10135 | (!(phydev->supported & SUPPORTED_Asym_Pause) && |
Nicolas Kaiser | 2259dca | 2010-10-07 23:29:27 +0000 | [diff] [blame] | 10136 | (epause->rx_pause != epause->tx_pause))) |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10137 | return -EINVAL; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10138 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10139 | tp->link_config.flowctrl = 0; |
| 10140 | if (epause->rx_pause) { |
| 10141 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10142 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10143 | if (epause->tx_pause) { |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10144 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10145 | newadv = ADVERTISED_Pause; |
| 10146 | } else |
| 10147 | newadv = ADVERTISED_Pause | |
| 10148 | ADVERTISED_Asym_Pause; |
| 10149 | } else if (epause->tx_pause) { |
| 10150 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 10151 | newadv = ADVERTISED_Asym_Pause; |
| 10152 | } else |
| 10153 | newadv = 0; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10154 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10155 | if (epause->autoneg) |
| 10156 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; |
| 10157 | else |
| 10158 | tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG; |
| 10159 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10160 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10161 | u32 oldadv = phydev->advertising & |
| 10162 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 10163 | if (oldadv != newadv) { |
| 10164 | phydev->advertising &= |
| 10165 | ~(ADVERTISED_Pause | |
| 10166 | ADVERTISED_Asym_Pause); |
| 10167 | phydev->advertising |= newadv; |
| 10168 | if (phydev->autoneg) { |
| 10169 | /* |
| 10170 | * Always renegotiate the link to |
| 10171 | * inform our link partner of our |
| 10172 | * flow control settings, even if the |
| 10173 | * flow control is forced. Let |
| 10174 | * tg3_adjust_link() do the final |
| 10175 | * flow control setup. |
| 10176 | */ |
| 10177 | return phy_start_aneg(phydev); |
| 10178 | } |
| 10179 | } |
| 10180 | |
| 10181 | if (!epause->autoneg) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10182 | tg3_setup_flow_control(tp, 0, 0); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10183 | } else { |
| 10184 | tp->link_config.orig_advertising &= |
| 10185 | ~(ADVERTISED_Pause | |
| 10186 | ADVERTISED_Asym_Pause); |
| 10187 | tp->link_config.orig_advertising |= newadv; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10188 | } |
| 10189 | } else { |
| 10190 | int irq_sync = 0; |
| 10191 | |
| 10192 | if (netif_running(dev)) { |
| 10193 | tg3_netif_stop(tp); |
| 10194 | irq_sync = 1; |
| 10195 | } |
| 10196 | |
| 10197 | tg3_full_lock(tp, irq_sync); |
| 10198 | |
| 10199 | if (epause->autoneg) |
| 10200 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; |
| 10201 | else |
| 10202 | tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG; |
| 10203 | if (epause->rx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10204 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10205 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10206 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10207 | if (epause->tx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10208 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10209 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10210 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10211 | |
| 10212 | if (netif_running(dev)) { |
| 10213 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 10214 | err = tg3_restart_hw(tp, 1); |
| 10215 | if (!err) |
| 10216 | tg3_netif_start(tp); |
| 10217 | } |
| 10218 | |
| 10219 | tg3_full_unlock(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10220 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10221 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10222 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10223 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10225 | static u32 tg3_get_rx_csum(struct net_device *dev) |
| 10226 | { |
| 10227 | struct tg3 *tp = netdev_priv(dev); |
| 10228 | return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0; |
| 10229 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10231 | static int tg3_set_rx_csum(struct net_device *dev, u32 data) |
| 10232 | { |
| 10233 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10235 | if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) { |
| 10236 | if (data != 0) |
| 10237 | return -EINVAL; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10238 | return 0; |
| 10239 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10240 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10241 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10242 | if (data) |
| 10243 | tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; |
| 10244 | else |
| 10245 | tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10246 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10248 | return 0; |
| 10249 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10251 | static int tg3_set_tx_csum(struct net_device *dev, u32 data) |
| 10252 | { |
| 10253 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10255 | if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) { |
| 10256 | if (data != 0) |
| 10257 | return -EINVAL; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10258 | return 0; |
| 10259 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10260 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10261 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Michael Chan | 6460d94 | 2007-07-14 19:07:52 -0700 | [diff] [blame] | 10262 | ethtool_op_set_tx_ipv6_csum(dev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10263 | else |
Michael Chan | 9c27dbd | 2006-03-20 22:28:27 -0800 | [diff] [blame] | 10264 | ethtool_op_set_tx_csum(dev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10265 | |
| 10266 | return 0; |
| 10267 | } |
| 10268 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10269 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10270 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 10271 | switch (sset) { |
| 10272 | case ETH_SS_TEST: |
| 10273 | return TG3_NUM_TEST; |
| 10274 | case ETH_SS_STATS: |
| 10275 | return TG3_NUM_STATS; |
| 10276 | default: |
| 10277 | return -EOPNOTSUPP; |
| 10278 | } |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10279 | } |
| 10280 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10281 | 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] | 10282 | { |
| 10283 | switch (stringset) { |
| 10284 | case ETH_SS_STATS: |
| 10285 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 10286 | break; |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10287 | case ETH_SS_TEST: |
| 10288 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); |
| 10289 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10290 | default: |
| 10291 | WARN_ON(1); /* we need a WARN() */ |
| 10292 | break; |
| 10293 | } |
| 10294 | } |
| 10295 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10296 | static int tg3_phys_id(struct net_device *dev, u32 data) |
| 10297 | { |
| 10298 | struct tg3 *tp = netdev_priv(dev); |
| 10299 | int i; |
| 10300 | |
| 10301 | if (!netif_running(tp->dev)) |
| 10302 | return -EAGAIN; |
| 10303 | |
| 10304 | if (data == 0) |
Stephen Hemminger | 759afc3 | 2008-02-23 19:51:59 -0800 | [diff] [blame] | 10305 | data = UINT_MAX / 2; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10306 | |
| 10307 | for (i = 0; i < (data * 2); i++) { |
| 10308 | if ((i % 2) == 0) |
| 10309 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 10310 | LED_CTRL_1000MBPS_ON | |
| 10311 | LED_CTRL_100MBPS_ON | |
| 10312 | LED_CTRL_10MBPS_ON | |
| 10313 | LED_CTRL_TRAFFIC_OVERRIDE | |
| 10314 | LED_CTRL_TRAFFIC_BLINK | |
| 10315 | LED_CTRL_TRAFFIC_LED); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10316 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10317 | else |
| 10318 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 10319 | LED_CTRL_TRAFFIC_OVERRIDE); |
| 10320 | |
| 10321 | if (msleep_interruptible(500)) |
| 10322 | break; |
| 10323 | } |
| 10324 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 10325 | return 0; |
| 10326 | } |
| 10327 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10328 | static void tg3_get_ethtool_stats(struct net_device *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10329 | struct ethtool_stats *estats, u64 *tmp_stats) |
| 10330 | { |
| 10331 | struct tg3 *tp = netdev_priv(dev); |
| 10332 | memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats)); |
| 10333 | } |
| 10334 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10335 | #define NVRAM_TEST_SIZE 0x100 |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10336 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
| 10337 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 |
| 10338 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10339 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
| 10340 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10341 | |
| 10342 | static int tg3_test_nvram(struct tg3 *tp) |
| 10343 | { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10344 | u32 csum, magic; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10345 | __be32 *buf; |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 10346 | int i, j, k, err = 0, size; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10347 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 10348 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) |
| 10349 | return 0; |
| 10350 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 10351 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10352 | return -EIO; |
| 10353 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10354 | if (magic == TG3_EEPROM_MAGIC) |
| 10355 | size = NVRAM_TEST_SIZE; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10356 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10357 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
| 10358 | TG3_EEPROM_SB_FORMAT_1) { |
| 10359 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { |
| 10360 | case TG3_EEPROM_SB_REVISION_0: |
| 10361 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; |
| 10362 | break; |
| 10363 | case TG3_EEPROM_SB_REVISION_2: |
| 10364 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; |
| 10365 | break; |
| 10366 | case TG3_EEPROM_SB_REVISION_3: |
| 10367 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; |
| 10368 | break; |
| 10369 | default: |
| 10370 | return 0; |
| 10371 | } |
| 10372 | } else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10373 | return 0; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10374 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 10375 | size = NVRAM_SELFBOOT_HW_SIZE; |
| 10376 | else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10377 | return -EIO; |
| 10378 | |
| 10379 | buf = kmalloc(size, GFP_KERNEL); |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10380 | if (buf == NULL) |
| 10381 | return -ENOMEM; |
| 10382 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10383 | err = -EIO; |
| 10384 | for (i = 0, j = 0; i < size; i += 4, j++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10385 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
| 10386 | if (err) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10387 | break; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10388 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10389 | if (i < size) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10390 | goto out; |
| 10391 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10392 | /* Selfboot format */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10393 | magic = be32_to_cpu(buf[0]); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10394 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10395 | TG3_EEPROM_MAGIC_FW) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10396 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
| 10397 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10398 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10399 | TG3_EEPROM_SB_REVISION_2) { |
| 10400 | /* For rev 2, the csum doesn't include the MBA. */ |
| 10401 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) |
| 10402 | csum8 += buf8[i]; |
| 10403 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) |
| 10404 | csum8 += buf8[i]; |
| 10405 | } else { |
| 10406 | for (i = 0; i < size; i++) |
| 10407 | csum8 += buf8[i]; |
| 10408 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10409 | |
Adrian Bunk | ad96b48 | 2006-04-05 22:21:04 -0700 | [diff] [blame] | 10410 | if (csum8 == 0) { |
| 10411 | err = 0; |
| 10412 | goto out; |
| 10413 | } |
| 10414 | |
| 10415 | err = -EIO; |
| 10416 | goto out; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10417 | } |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10418 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10419 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10420 | TG3_EEPROM_MAGIC_HW) { |
| 10421 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10422 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10423 | u8 *buf8 = (u8 *) buf; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10424 | |
| 10425 | /* Separate the parity bits and the data bytes. */ |
| 10426 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { |
| 10427 | if ((i == 0) || (i == 8)) { |
| 10428 | int l; |
| 10429 | u8 msk; |
| 10430 | |
| 10431 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) |
| 10432 | parity[k++] = buf8[i] & msk; |
| 10433 | i++; |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 10434 | } else if (i == 16) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10435 | int l; |
| 10436 | u8 msk; |
| 10437 | |
| 10438 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) |
| 10439 | parity[k++] = buf8[i] & msk; |
| 10440 | i++; |
| 10441 | |
| 10442 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) |
| 10443 | parity[k++] = buf8[i] & msk; |
| 10444 | i++; |
| 10445 | } |
| 10446 | data[j++] = buf8[i]; |
| 10447 | } |
| 10448 | |
| 10449 | err = -EIO; |
| 10450 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { |
| 10451 | u8 hw8 = hweight8(data[i]); |
| 10452 | |
| 10453 | if ((hw8 & 0x1) && parity[i]) |
| 10454 | goto out; |
| 10455 | else if (!(hw8 & 0x1) && !parity[i]) |
| 10456 | goto out; |
| 10457 | } |
| 10458 | err = 0; |
| 10459 | goto out; |
| 10460 | } |
| 10461 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10462 | /* Bootstrap checksum at offset 0x10 */ |
| 10463 | csum = calc_crc((unsigned char *) buf, 0x10); |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10464 | if (csum != be32_to_cpu(buf[0x10/4])) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10465 | goto out; |
| 10466 | |
| 10467 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ |
| 10468 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10469 | if (csum != be32_to_cpu(buf[0xfc/4])) |
| 10470 | goto out; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10471 | |
| 10472 | err = 0; |
| 10473 | |
| 10474 | out: |
| 10475 | kfree(buf); |
| 10476 | return err; |
| 10477 | } |
| 10478 | |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 10479 | #define TG3_SERDES_TIMEOUT_SEC 2 |
| 10480 | #define TG3_COPPER_TIMEOUT_SEC 6 |
| 10481 | |
| 10482 | static int tg3_test_link(struct tg3 *tp) |
| 10483 | { |
| 10484 | int i, max; |
| 10485 | |
| 10486 | if (!netif_running(tp->dev)) |
| 10487 | return -ENODEV; |
| 10488 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10489 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 10490 | max = TG3_SERDES_TIMEOUT_SEC; |
| 10491 | else |
| 10492 | max = TG3_COPPER_TIMEOUT_SEC; |
| 10493 | |
| 10494 | for (i = 0; i < max; i++) { |
| 10495 | if (netif_carrier_ok(tp->dev)) |
| 10496 | return 0; |
| 10497 | |
| 10498 | if (msleep_interruptible(1000)) |
| 10499 | break; |
| 10500 | } |
| 10501 | |
| 10502 | return -EIO; |
| 10503 | } |
| 10504 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10505 | /* Only test the commonly used registers */ |
David S. Miller | 30ca3e3 | 2006-03-20 23:02:36 -0800 | [diff] [blame] | 10506 | static int tg3_test_registers(struct tg3 *tp) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10507 | { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10508 | int i, is_5705, is_5750; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10509 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
| 10510 | static struct { |
| 10511 | u16 offset; |
| 10512 | u16 flags; |
| 10513 | #define TG3_FL_5705 0x1 |
| 10514 | #define TG3_FL_NOT_5705 0x2 |
| 10515 | #define TG3_FL_NOT_5788 0x4 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10516 | #define TG3_FL_NOT_5750 0x8 |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10517 | u32 read_mask; |
| 10518 | u32 write_mask; |
| 10519 | } reg_tbl[] = { |
| 10520 | /* MAC Control Registers */ |
| 10521 | { MAC_MODE, TG3_FL_NOT_5705, |
| 10522 | 0x00000000, 0x00ef6f8c }, |
| 10523 | { MAC_MODE, TG3_FL_5705, |
| 10524 | 0x00000000, 0x01ef6b8c }, |
| 10525 | { MAC_STATUS, TG3_FL_NOT_5705, |
| 10526 | 0x03800107, 0x00000000 }, |
| 10527 | { MAC_STATUS, TG3_FL_5705, |
| 10528 | 0x03800100, 0x00000000 }, |
| 10529 | { MAC_ADDR_0_HIGH, 0x0000, |
| 10530 | 0x00000000, 0x0000ffff }, |
| 10531 | { MAC_ADDR_0_LOW, 0x0000, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10532 | 0x00000000, 0xffffffff }, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10533 | { MAC_RX_MTU_SIZE, 0x0000, |
| 10534 | 0x00000000, 0x0000ffff }, |
| 10535 | { MAC_TX_MODE, 0x0000, |
| 10536 | 0x00000000, 0x00000070 }, |
| 10537 | { MAC_TX_LENGTHS, 0x0000, |
| 10538 | 0x00000000, 0x00003fff }, |
| 10539 | { MAC_RX_MODE, TG3_FL_NOT_5705, |
| 10540 | 0x00000000, 0x000007fc }, |
| 10541 | { MAC_RX_MODE, TG3_FL_5705, |
| 10542 | 0x00000000, 0x000007dc }, |
| 10543 | { MAC_HASH_REG_0, 0x0000, |
| 10544 | 0x00000000, 0xffffffff }, |
| 10545 | { MAC_HASH_REG_1, 0x0000, |
| 10546 | 0x00000000, 0xffffffff }, |
| 10547 | { MAC_HASH_REG_2, 0x0000, |
| 10548 | 0x00000000, 0xffffffff }, |
| 10549 | { MAC_HASH_REG_3, 0x0000, |
| 10550 | 0x00000000, 0xffffffff }, |
| 10551 | |
| 10552 | /* Receive Data and Receive BD Initiator Control Registers. */ |
| 10553 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, |
| 10554 | 0x00000000, 0xffffffff }, |
| 10555 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, |
| 10556 | 0x00000000, 0xffffffff }, |
| 10557 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, |
| 10558 | 0x00000000, 0x00000003 }, |
| 10559 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, |
| 10560 | 0x00000000, 0xffffffff }, |
| 10561 | { RCVDBDI_STD_BD+0, 0x0000, |
| 10562 | 0x00000000, 0xffffffff }, |
| 10563 | { RCVDBDI_STD_BD+4, 0x0000, |
| 10564 | 0x00000000, 0xffffffff }, |
| 10565 | { RCVDBDI_STD_BD+8, 0x0000, |
| 10566 | 0x00000000, 0xffff0002 }, |
| 10567 | { RCVDBDI_STD_BD+0xc, 0x0000, |
| 10568 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10569 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10570 | /* Receive BD Initiator Control Registers. */ |
| 10571 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, |
| 10572 | 0x00000000, 0xffffffff }, |
| 10573 | { RCVBDI_STD_THRESH, TG3_FL_5705, |
| 10574 | 0x00000000, 0x000003ff }, |
| 10575 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, |
| 10576 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10577 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10578 | /* Host Coalescing Control Registers. */ |
| 10579 | { HOSTCC_MODE, TG3_FL_NOT_5705, |
| 10580 | 0x00000000, 0x00000004 }, |
| 10581 | { HOSTCC_MODE, TG3_FL_5705, |
| 10582 | 0x00000000, 0x000000f6 }, |
| 10583 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, |
| 10584 | 0x00000000, 0xffffffff }, |
| 10585 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, |
| 10586 | 0x00000000, 0x000003ff }, |
| 10587 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, |
| 10588 | 0x00000000, 0xffffffff }, |
| 10589 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, |
| 10590 | 0x00000000, 0x000003ff }, |
| 10591 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, |
| 10592 | 0x00000000, 0xffffffff }, |
| 10593 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10594 | 0x00000000, 0x000000ff }, |
| 10595 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, |
| 10596 | 0x00000000, 0xffffffff }, |
| 10597 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10598 | 0x00000000, 0x000000ff }, |
| 10599 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 10600 | 0x00000000, 0xffffffff }, |
| 10601 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 10602 | 0x00000000, 0xffffffff }, |
| 10603 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 10604 | 0x00000000, 0xffffffff }, |
| 10605 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10606 | 0x00000000, 0x000000ff }, |
| 10607 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 10608 | 0x00000000, 0xffffffff }, |
| 10609 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10610 | 0x00000000, 0x000000ff }, |
| 10611 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, |
| 10612 | 0x00000000, 0xffffffff }, |
| 10613 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, |
| 10614 | 0x00000000, 0xffffffff }, |
| 10615 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, |
| 10616 | 0x00000000, 0xffffffff }, |
| 10617 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, |
| 10618 | 0x00000000, 0xffffffff }, |
| 10619 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, |
| 10620 | 0x00000000, 0xffffffff }, |
| 10621 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, |
| 10622 | 0xffffffff, 0x00000000 }, |
| 10623 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, |
| 10624 | 0xffffffff, 0x00000000 }, |
| 10625 | |
| 10626 | /* Buffer Manager Control Registers. */ |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10627 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10628 | 0x00000000, 0x007fff80 }, |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10629 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10630 | 0x00000000, 0x007fffff }, |
| 10631 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, |
| 10632 | 0x00000000, 0x0000003f }, |
| 10633 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, |
| 10634 | 0x00000000, 0x000001ff }, |
| 10635 | { BUFMGR_MB_HIGH_WATER, 0x0000, |
| 10636 | 0x00000000, 0x000001ff }, |
| 10637 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, |
| 10638 | 0xffffffff, 0x00000000 }, |
| 10639 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, |
| 10640 | 0xffffffff, 0x00000000 }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10641 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10642 | /* Mailbox Registers */ |
| 10643 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, |
| 10644 | 0x00000000, 0x000001ff }, |
| 10645 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, |
| 10646 | 0x00000000, 0x000001ff }, |
| 10647 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, |
| 10648 | 0x00000000, 0x000007ff }, |
| 10649 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, |
| 10650 | 0x00000000, 0x000001ff }, |
| 10651 | |
| 10652 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, |
| 10653 | }; |
| 10654 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10655 | is_5705 = is_5750 = 0; |
| 10656 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10657 | is_5705 = 1; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10658 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
| 10659 | is_5750 = 1; |
| 10660 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10661 | |
| 10662 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { |
| 10663 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) |
| 10664 | continue; |
| 10665 | |
| 10666 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) |
| 10667 | continue; |
| 10668 | |
| 10669 | if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) && |
| 10670 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
| 10671 | continue; |
| 10672 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10673 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
| 10674 | continue; |
| 10675 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10676 | offset = (u32) reg_tbl[i].offset; |
| 10677 | read_mask = reg_tbl[i].read_mask; |
| 10678 | write_mask = reg_tbl[i].write_mask; |
| 10679 | |
| 10680 | /* Save the original register content */ |
| 10681 | save_val = tr32(offset); |
| 10682 | |
| 10683 | /* Determine the read-only value. */ |
| 10684 | read_val = save_val & read_mask; |
| 10685 | |
| 10686 | /* Write zero to the register, then make sure the read-only bits |
| 10687 | * are not changed and the read/write bits are all zeros. |
| 10688 | */ |
| 10689 | tw32(offset, 0); |
| 10690 | |
| 10691 | val = tr32(offset); |
| 10692 | |
| 10693 | /* Test the read-only and read/write bits. */ |
| 10694 | if (((val & read_mask) != read_val) || (val & write_mask)) |
| 10695 | goto out; |
| 10696 | |
| 10697 | /* Write ones to all the bits defined by RdMask and WrMask, then |
| 10698 | * make sure the read-only bits are not changed and the |
| 10699 | * read/write bits are all ones. |
| 10700 | */ |
| 10701 | tw32(offset, read_mask | write_mask); |
| 10702 | |
| 10703 | val = tr32(offset); |
| 10704 | |
| 10705 | /* Test the read-only bits. */ |
| 10706 | if ((val & read_mask) != read_val) |
| 10707 | goto out; |
| 10708 | |
| 10709 | /* Test the read/write bits. */ |
| 10710 | if ((val & write_mask) != write_mask) |
| 10711 | goto out; |
| 10712 | |
| 10713 | tw32(offset, save_val); |
| 10714 | } |
| 10715 | |
| 10716 | return 0; |
| 10717 | |
| 10718 | out: |
Michael Chan | 9f88f29 | 2006-12-07 00:22:54 -0800 | [diff] [blame] | 10719 | if (netif_msg_hw(tp)) |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 10720 | netdev_err(tp->dev, |
| 10721 | "Register test failed at offset %x\n", offset); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10722 | tw32(offset, save_val); |
| 10723 | return -EIO; |
| 10724 | } |
| 10725 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10726 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
| 10727 | { |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 10728 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10729 | int i; |
| 10730 | u32 j; |
| 10731 | |
Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 10732 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10733 | for (j = 0; j < len; j += 4) { |
| 10734 | u32 val; |
| 10735 | |
| 10736 | tg3_write_mem(tp, offset + j, test_pattern[i]); |
| 10737 | tg3_read_mem(tp, offset + j, &val); |
| 10738 | if (val != test_pattern[i]) |
| 10739 | return -EIO; |
| 10740 | } |
| 10741 | } |
| 10742 | return 0; |
| 10743 | } |
| 10744 | |
| 10745 | static int tg3_test_memory(struct tg3 *tp) |
| 10746 | { |
| 10747 | static struct mem_entry { |
| 10748 | u32 offset; |
| 10749 | u32 len; |
| 10750 | } mem_tbl_570x[] = { |
Michael Chan | 3869019 | 2005-12-19 16:27:28 -0800 | [diff] [blame] | 10751 | { 0x00000000, 0x00b50}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10752 | { 0x00002000, 0x1c000}, |
| 10753 | { 0xffffffff, 0x00000} |
| 10754 | }, mem_tbl_5705[] = { |
| 10755 | { 0x00000100, 0x0000c}, |
| 10756 | { 0x00000200, 0x00008}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10757 | { 0x00004000, 0x00800}, |
| 10758 | { 0x00006000, 0x01000}, |
| 10759 | { 0x00008000, 0x02000}, |
| 10760 | { 0x00010000, 0x0e000}, |
| 10761 | { 0xffffffff, 0x00000} |
Michael Chan | 79f4d13 | 2006-03-20 22:28:57 -0800 | [diff] [blame] | 10762 | }, mem_tbl_5755[] = { |
| 10763 | { 0x00000200, 0x00008}, |
| 10764 | { 0x00004000, 0x00800}, |
| 10765 | { 0x00006000, 0x00800}, |
| 10766 | { 0x00008000, 0x02000}, |
| 10767 | { 0x00010000, 0x0c000}, |
| 10768 | { 0xffffffff, 0x00000} |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10769 | }, mem_tbl_5906[] = { |
| 10770 | { 0x00000200, 0x00008}, |
| 10771 | { 0x00004000, 0x00400}, |
| 10772 | { 0x00006000, 0x00400}, |
| 10773 | { 0x00008000, 0x01000}, |
| 10774 | { 0x00010000, 0x01000}, |
| 10775 | { 0xffffffff, 0x00000} |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 10776 | }, mem_tbl_5717[] = { |
| 10777 | { 0x00000200, 0x00008}, |
| 10778 | { 0x00010000, 0x0a000}, |
| 10779 | { 0x00020000, 0x13c00}, |
| 10780 | { 0xffffffff, 0x00000} |
| 10781 | }, mem_tbl_57765[] = { |
| 10782 | { 0x00000200, 0x00008}, |
| 10783 | { 0x00004000, 0x00800}, |
| 10784 | { 0x00006000, 0x09800}, |
| 10785 | { 0x00010000, 0x0a000}, |
| 10786 | { 0xffffffff, 0x00000} |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10787 | }; |
| 10788 | struct mem_entry *mem_tbl; |
| 10789 | int err = 0; |
| 10790 | int i; |
| 10791 | |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 10792 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 10793 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 10794 | mem_tbl = mem_tbl_5717; |
| 10795 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 10796 | mem_tbl = mem_tbl_57765; |
| 10797 | else if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10798 | mem_tbl = mem_tbl_5755; |
| 10799 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 10800 | mem_tbl = mem_tbl_5906; |
| 10801 | else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
| 10802 | mem_tbl = mem_tbl_5705; |
| 10803 | else |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10804 | mem_tbl = mem_tbl_570x; |
| 10805 | |
| 10806 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 10807 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
| 10808 | if (err) |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10809 | break; |
| 10810 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10811 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10812 | return err; |
| 10813 | } |
| 10814 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10815 | #define TG3_MAC_LOOPBACK 0 |
| 10816 | #define TG3_PHY_LOOPBACK 1 |
| 10817 | |
| 10818 | static int tg3_run_loopback(struct tg3 *tp, int loopback_mode) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10819 | { |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10820 | u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key; |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10821 | u32 desc_idx, coal_now; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10822 | struct sk_buff *skb, *rx_skb; |
| 10823 | u8 *tx_data; |
| 10824 | dma_addr_t map; |
| 10825 | int num_pkts, tx_len, rx_len, i, err; |
| 10826 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10827 | struct tg3_napi *tnapi, *rnapi; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 10828 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10829 | |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 10830 | tnapi = &tp->napi[0]; |
| 10831 | rnapi = &tp->napi[0]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 10832 | if (tp->irq_cnt > 1) { |
Matt Carlson | 1da85aa | 2010-09-30 10:34:34 +0000 | [diff] [blame] | 10833 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) |
| 10834 | rnapi = &tp->napi[1]; |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 10835 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
| 10836 | tnapi = &tp->napi[1]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 10837 | } |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10838 | coal_now = tnapi->coal_now | rnapi->coal_now; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10839 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10840 | if (loopback_mode == TG3_MAC_LOOPBACK) { |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10841 | /* HW errata - mac loopback fails in some cases on 5780. |
| 10842 | * Normal traffic and PHY loopback are not affected by |
| 10843 | * errata. |
| 10844 | */ |
| 10845 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) |
| 10846 | return 0; |
| 10847 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10848 | mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10849 | MAC_MODE_PORT_INT_LPBACK; |
| 10850 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 10851 | mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10852 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10853 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 10854 | else |
| 10855 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10856 | tw32(MAC_MODE, mac_mode); |
| 10857 | } else if (loopback_mode == TG3_PHY_LOOPBACK) { |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10858 | u32 val; |
| 10859 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10860 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 10861 | tg3_phy_fet_toggle_apd(tp, false); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 10862 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100; |
| 10863 | } else |
| 10864 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000; |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10865 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 10866 | tg3_phy_toggle_automdix(tp, 0); |
| 10867 | |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10868 | tg3_writephy(tp, MII_BMCR, val); |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10869 | udelay(40); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 10870 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10871 | mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10872 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 1061b7c | 2010-02-12 14:47:12 +0000 | [diff] [blame] | 10873 | tg3_writephy(tp, MII_TG3_FET_PTEST, |
| 10874 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
| 10875 | MII_TG3_FET_PTEST_FRC_TX_LOCK); |
| 10876 | /* The write needs to be flushed for the AC131 */ |
| 10877 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 10878 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 10879 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 10880 | } else |
| 10881 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10882 | |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10883 | /* reset to prevent losing 1st rx packet intermittently */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10884 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10885 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 10886 | udelay(10); |
| 10887 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 10888 | } |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10889 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 10890 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
| 10891 | if (masked_phy_id == TG3_PHY_ID_BCM5401) |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10892 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 10893 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10894 | mac_mode |= MAC_MODE_LINK_POLARITY; |
Michael Chan | ff18ff0 | 2006-03-27 23:17:27 -0800 | [diff] [blame] | 10895 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 10896 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 10897 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10898 | tw32(MAC_MODE, mac_mode); |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 10899 | } else { |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10900 | return -EINVAL; |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 10901 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10902 | |
| 10903 | err = -EIO; |
| 10904 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10905 | tx_len = 1514; |
David S. Miller | a20e9c6 | 2006-07-31 22:38:16 -0700 | [diff] [blame] | 10906 | skb = netdev_alloc_skb(tp->dev, tx_len); |
Jesper Juhl | a50bb7b | 2006-05-09 23:14:35 -0700 | [diff] [blame] | 10907 | if (!skb) |
| 10908 | return -ENOMEM; |
| 10909 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10910 | tx_data = skb_put(skb, tx_len); |
| 10911 | memcpy(tx_data, tp->dev->dev_addr, 6); |
| 10912 | memset(tx_data + 6, 0x0, 8); |
| 10913 | |
| 10914 | tw32(MAC_RX_MTU_SIZE, tx_len + 4); |
| 10915 | |
| 10916 | for (i = 14; i < tx_len; i++) |
| 10917 | tx_data[i] = (u8) (i & 0xff); |
| 10918 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 10919 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
| 10920 | if (pci_dma_mapping_error(tp->pdev, map)) { |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 10921 | dev_kfree_skb(skb); |
| 10922 | return -EIO; |
| 10923 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10924 | |
| 10925 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10926 | rnapi->coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10927 | |
| 10928 | udelay(10); |
| 10929 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10930 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10931 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10932 | num_pkts = 0; |
| 10933 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 10934 | tg3_set_txd(tnapi, tnapi->tx_prod, map, tx_len, 0, 1); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10935 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10936 | tnapi->tx_prod++; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10937 | num_pkts++; |
| 10938 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10939 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 10940 | tr32_mailbox(tnapi->prodmbox); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10941 | |
| 10942 | udelay(10); |
| 10943 | |
Matt Carlson | 303fc92 | 2009-11-02 14:27:34 +0000 | [diff] [blame] | 10944 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
| 10945 | for (i = 0; i < 35; i++) { |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10946 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10947 | coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10948 | |
| 10949 | udelay(10); |
| 10950 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10951 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 10952 | rx_idx = rnapi->hw_status->idx[0].rx_producer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10953 | if ((tx_idx == tnapi->tx_prod) && |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10954 | (rx_idx == (rx_start_idx + num_pkts))) |
| 10955 | break; |
| 10956 | } |
| 10957 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 10958 | pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10959 | dev_kfree_skb(skb); |
| 10960 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10961 | if (tx_idx != tnapi->tx_prod) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10962 | goto out; |
| 10963 | |
| 10964 | if (rx_idx != rx_start_idx + num_pkts) |
| 10965 | goto out; |
| 10966 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 10967 | desc = &rnapi->rx_rcb[rx_start_idx]; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10968 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 10969 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 10970 | if (opaque_key != RXD_OPAQUE_RING_STD) |
| 10971 | goto out; |
| 10972 | |
| 10973 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 10974 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) |
| 10975 | goto out; |
| 10976 | |
| 10977 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; |
| 10978 | if (rx_len != tx_len) |
| 10979 | goto out; |
| 10980 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 10981 | rx_skb = tpr->rx_std_buffers[desc_idx].skb; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10982 | |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 10983 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], mapping); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10984 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE); |
| 10985 | |
| 10986 | for (i = 14; i < tx_len; i++) { |
| 10987 | if (*(rx_skb->data + i) != (u8) (i & 0xff)) |
| 10988 | goto out; |
| 10989 | } |
| 10990 | err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10991 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10992 | /* tg3_free_rings will unmap and free the rx_skb */ |
| 10993 | out: |
| 10994 | return err; |
| 10995 | } |
| 10996 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10997 | #define TG3_MAC_LOOPBACK_FAILED 1 |
| 10998 | #define TG3_PHY_LOOPBACK_FAILED 2 |
| 10999 | #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \ |
| 11000 | TG3_PHY_LOOPBACK_FAILED) |
| 11001 | |
| 11002 | static int tg3_test_loopback(struct tg3 *tp) |
| 11003 | { |
| 11004 | int err = 0; |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11005 | u32 cpmuctrl = 0; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11006 | |
| 11007 | if (!netif_running(tp->dev)) |
| 11008 | return TG3_LOOPBACK_FAILED; |
| 11009 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11010 | err = tg3_reset_hw(tp, 1); |
| 11011 | if (err) |
| 11012 | return TG3_LOOPBACK_FAILED; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11013 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11014 | /* Turn off gphy autopowerdown. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11015 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11016 | tg3_phy_toggle_apd(tp, false); |
| 11017 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11018 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11019 | int i; |
| 11020 | u32 status; |
| 11021 | |
| 11022 | tw32(TG3_CPMU_MUTEX_REQ, CPMU_MUTEX_REQ_DRIVER); |
| 11023 | |
| 11024 | /* Wait for up to 40 microseconds to acquire lock. */ |
| 11025 | for (i = 0; i < 4; i++) { |
| 11026 | status = tr32(TG3_CPMU_MUTEX_GNT); |
| 11027 | if (status == CPMU_MUTEX_GNT_DRIVER) |
| 11028 | break; |
| 11029 | udelay(10); |
| 11030 | } |
| 11031 | |
| 11032 | if (status != CPMU_MUTEX_GNT_DRIVER) |
| 11033 | return TG3_LOOPBACK_FAILED; |
| 11034 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 11035 | /* Turn off link-based power management. */ |
Matt Carlson | e875093 | 2007-11-12 21:11:51 -0800 | [diff] [blame] | 11036 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
Matt Carlson | 109115e | 2008-05-02 16:48:59 -0700 | [diff] [blame] | 11037 | tw32(TG3_CPMU_CTRL, |
| 11038 | cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE | |
| 11039 | CPMU_CTRL_LINK_AWARE_MODE)); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11040 | } |
| 11041 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11042 | if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK)) |
| 11043 | err |= TG3_MAC_LOOPBACK_FAILED; |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11044 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11045 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11046 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 11047 | |
| 11048 | /* Release the mutex */ |
| 11049 | tw32(TG3_CPMU_MUTEX_GNT, CPMU_MUTEX_GNT_DRIVER); |
| 11050 | } |
| 11051 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11052 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 11053 | !(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)) { |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11054 | if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK)) |
| 11055 | err |= TG3_PHY_LOOPBACK_FAILED; |
| 11056 | } |
| 11057 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11058 | /* Re-enable gphy autopowerdown. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11059 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11060 | tg3_phy_toggle_apd(tp, true); |
| 11061 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11062 | return err; |
| 11063 | } |
| 11064 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11065 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
| 11066 | u64 *data) |
| 11067 | { |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11068 | struct tg3 *tp = netdev_priv(dev); |
| 11069 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11070 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11071 | tg3_set_power_state(tp, PCI_D0); |
| 11072 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11073 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
| 11074 | |
| 11075 | if (tg3_test_nvram(tp) != 0) { |
| 11076 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11077 | data[0] = 1; |
| 11078 | } |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11079 | if (tg3_test_link(tp) != 0) { |
| 11080 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11081 | data[1] = 1; |
| 11082 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11083 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11084 | int err, err2 = 0, irq_sync = 0; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11085 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11086 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11087 | tg3_phy_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11088 | tg3_netif_stop(tp); |
| 11089 | irq_sync = 1; |
| 11090 | } |
| 11091 | |
| 11092 | tg3_full_lock(tp, irq_sync); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11093 | |
| 11094 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11095 | err = tg3_nvram_lock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11096 | tg3_halt_cpu(tp, RX_CPU_BASE); |
| 11097 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 11098 | tg3_halt_cpu(tp, TX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11099 | if (!err) |
| 11100 | tg3_nvram_unlock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11101 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11102 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 11103 | tg3_phy_reset(tp); |
| 11104 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11105 | if (tg3_test_registers(tp) != 0) { |
| 11106 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11107 | data[2] = 1; |
| 11108 | } |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11109 | if (tg3_test_memory(tp) != 0) { |
| 11110 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11111 | data[3] = 1; |
| 11112 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11113 | if ((data[4] = tg3_test_loopback(tp)) != 0) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11114 | etest->flags |= ETH_TEST_FL_FAILED; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11115 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11116 | tg3_full_unlock(tp); |
| 11117 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 11118 | if (tg3_test_interrupt(tp) != 0) { |
| 11119 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11120 | data[5] = 1; |
| 11121 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11122 | |
| 11123 | tg3_full_lock(tp, 0); |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 11124 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11125 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11126 | if (netif_running(dev)) { |
| 11127 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11128 | err2 = tg3_restart_hw(tp, 1); |
| 11129 | if (!err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11130 | tg3_netif_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11131 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11132 | |
| 11133 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11134 | |
| 11135 | if (irq_sync && !err2) |
| 11136 | tg3_phy_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11137 | } |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11138 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11139 | tg3_set_power_state(tp, PCI_D3hot); |
| 11140 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11141 | } |
| 11142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11143 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 11144 | { |
| 11145 | struct mii_ioctl_data *data = if_mii(ifr); |
| 11146 | struct tg3 *tp = netdev_priv(dev); |
| 11147 | int err; |
| 11148 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11149 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11150 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11151 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11152 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11153 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 11154 | return phy_mii_ioctl(phydev, ifr, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11155 | } |
| 11156 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 11157 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11158 | case SIOCGMIIPHY: |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 11159 | data->phy_id = tp->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11160 | |
| 11161 | /* fallthru */ |
| 11162 | case SIOCGMIIREG: { |
| 11163 | u32 mii_regval; |
| 11164 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11165 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11166 | break; /* We have no PHY */ |
| 11167 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11168 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11169 | return -EAGAIN; |
| 11170 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11171 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11172 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11173 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11174 | |
| 11175 | data->val_out = mii_regval; |
| 11176 | |
| 11177 | return err; |
| 11178 | } |
| 11179 | |
| 11180 | case SIOCSMIIREG: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11181 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11182 | break; /* We have no PHY */ |
| 11183 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11184 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11185 | return -EAGAIN; |
| 11186 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11187 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11188 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11189 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11190 | |
| 11191 | return err; |
| 11192 | |
| 11193 | default: |
| 11194 | /* do nothing */ |
| 11195 | break; |
| 11196 | } |
| 11197 | return -EOPNOTSUPP; |
| 11198 | } |
| 11199 | |
| 11200 | #if TG3_VLAN_TAG_USED |
| 11201 | static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) |
| 11202 | { |
| 11203 | struct tg3 *tp = netdev_priv(dev); |
| 11204 | |
Matt Carlson | 844b3ee | 2009-02-25 14:23:56 +0000 | [diff] [blame] | 11205 | if (!netif_running(dev)) { |
| 11206 | tp->vlgrp = grp; |
| 11207 | return; |
| 11208 | } |
| 11209 | |
| 11210 | tg3_netif_stop(tp); |
Michael Chan | 29315e8 | 2006-06-29 20:12:30 -0700 | [diff] [blame] | 11211 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11212 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11213 | |
| 11214 | tp->vlgrp = grp; |
| 11215 | |
| 11216 | /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */ |
| 11217 | __tg3_set_rx_mode(dev); |
| 11218 | |
Matt Carlson | 844b3ee | 2009-02-25 14:23:56 +0000 | [diff] [blame] | 11219 | tg3_netif_start(tp); |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 11220 | |
| 11221 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11223 | #endif |
| 11224 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 11225 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 11226 | { |
| 11227 | struct tg3 *tp = netdev_priv(dev); |
| 11228 | |
| 11229 | memcpy(ec, &tp->coal, sizeof(*ec)); |
| 11230 | return 0; |
| 11231 | } |
| 11232 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 11233 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 11234 | { |
| 11235 | struct tg3 *tp = netdev_priv(dev); |
| 11236 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; |
| 11237 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; |
| 11238 | |
| 11239 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 11240 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
| 11241 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; |
| 11242 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; |
| 11243 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; |
| 11244 | } |
| 11245 | |
| 11246 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || |
| 11247 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || |
| 11248 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || |
| 11249 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || |
| 11250 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || |
| 11251 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || |
| 11252 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || |
| 11253 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || |
| 11254 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || |
| 11255 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) |
| 11256 | return -EINVAL; |
| 11257 | |
| 11258 | /* No rx interrupts will be generated if both are zero */ |
| 11259 | if ((ec->rx_coalesce_usecs == 0) && |
| 11260 | (ec->rx_max_coalesced_frames == 0)) |
| 11261 | return -EINVAL; |
| 11262 | |
| 11263 | /* No tx interrupts will be generated if both are zero */ |
| 11264 | if ((ec->tx_coalesce_usecs == 0) && |
| 11265 | (ec->tx_max_coalesced_frames == 0)) |
| 11266 | return -EINVAL; |
| 11267 | |
| 11268 | /* Only copy relevant parameters, ignore all others. */ |
| 11269 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; |
| 11270 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; |
| 11271 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; |
| 11272 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; |
| 11273 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; |
| 11274 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; |
| 11275 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; |
| 11276 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; |
| 11277 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; |
| 11278 | |
| 11279 | if (netif_running(dev)) { |
| 11280 | tg3_full_lock(tp, 0); |
| 11281 | __tg3_set_coalesce(tp, &tp->coal); |
| 11282 | tg3_full_unlock(tp); |
| 11283 | } |
| 11284 | return 0; |
| 11285 | } |
| 11286 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 11287 | static const struct ethtool_ops tg3_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11288 | .get_settings = tg3_get_settings, |
| 11289 | .set_settings = tg3_set_settings, |
| 11290 | .get_drvinfo = tg3_get_drvinfo, |
| 11291 | .get_regs_len = tg3_get_regs_len, |
| 11292 | .get_regs = tg3_get_regs, |
| 11293 | .get_wol = tg3_get_wol, |
| 11294 | .set_wol = tg3_set_wol, |
| 11295 | .get_msglevel = tg3_get_msglevel, |
| 11296 | .set_msglevel = tg3_set_msglevel, |
| 11297 | .nway_reset = tg3_nway_reset, |
| 11298 | .get_link = ethtool_op_get_link, |
| 11299 | .get_eeprom_len = tg3_get_eeprom_len, |
| 11300 | .get_eeprom = tg3_get_eeprom, |
| 11301 | .set_eeprom = tg3_set_eeprom, |
| 11302 | .get_ringparam = tg3_get_ringparam, |
| 11303 | .set_ringparam = tg3_set_ringparam, |
| 11304 | .get_pauseparam = tg3_get_pauseparam, |
| 11305 | .set_pauseparam = tg3_set_pauseparam, |
| 11306 | .get_rx_csum = tg3_get_rx_csum, |
| 11307 | .set_rx_csum = tg3_set_rx_csum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11308 | .set_tx_csum = tg3_set_tx_csum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11309 | .set_sg = ethtool_op_set_sg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11310 | .set_tso = tg3_set_tso, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11311 | .self_test = tg3_self_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11312 | .get_strings = tg3_get_strings, |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11313 | .phys_id = tg3_phys_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11314 | .get_ethtool_stats = tg3_get_ethtool_stats, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 11315 | .get_coalesce = tg3_get_coalesce, |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 11316 | .set_coalesce = tg3_set_coalesce, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 11317 | .get_sset_count = tg3_get_sset_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11318 | }; |
| 11319 | |
| 11320 | static void __devinit tg3_get_eeprom_size(struct tg3 *tp) |
| 11321 | { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11322 | u32 cursize, val, magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11323 | |
| 11324 | tp->nvram_size = EEPROM_CHIP_SIZE; |
| 11325 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11326 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11327 | return; |
| 11328 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11329 | if ((magic != TG3_EEPROM_MAGIC) && |
| 11330 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && |
| 11331 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11332 | return; |
| 11333 | |
| 11334 | /* |
| 11335 | * Size the chip by reading offsets at increasing powers of two. |
| 11336 | * When we encounter our validation signature, we know the addressing |
| 11337 | * has wrapped around, and thus have our chip size. |
| 11338 | */ |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11339 | cursize = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11340 | |
| 11341 | while (cursize < tp->nvram_size) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11342 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11343 | return; |
| 11344 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 11345 | if (val == magic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11346 | break; |
| 11347 | |
| 11348 | cursize <<= 1; |
| 11349 | } |
| 11350 | |
| 11351 | tp->nvram_size = cursize; |
| 11352 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11354 | static void __devinit tg3_get_nvram_size(struct tg3 *tp) |
| 11355 | { |
| 11356 | u32 val; |
| 11357 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11358 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
| 11359 | tg3_nvram_read(tp, 0, &val) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11360 | return; |
| 11361 | |
| 11362 | /* Selfboot format */ |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 11363 | if (val != TG3_EEPROM_MAGIC) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11364 | tg3_get_eeprom_size(tp); |
| 11365 | return; |
| 11366 | } |
| 11367 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 11368 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11369 | if (val != 0) { |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 11370 | /* This is confusing. We want to operate on the |
| 11371 | * 16-bit value at offset 0xf2. The tg3_nvram_read() |
| 11372 | * call will read from NVRAM and byteswap the data |
| 11373 | * according to the byteswapping settings for all |
| 11374 | * other register accesses. This ensures the data we |
| 11375 | * want will always reside in the lower 16-bits. |
| 11376 | * However, the data in NVRAM is in LE format, which |
| 11377 | * means the data from the NVRAM read will always be |
| 11378 | * opposite the endianness of the CPU. The 16-bit |
| 11379 | * byteswap then brings the data to CPU endianness. |
| 11380 | */ |
| 11381 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11382 | return; |
| 11383 | } |
| 11384 | } |
Matt Carlson | fd1122a | 2008-05-02 16:48:36 -0700 | [diff] [blame] | 11385 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11386 | } |
| 11387 | |
| 11388 | static void __devinit tg3_get_nvram_info(struct tg3 *tp) |
| 11389 | { |
| 11390 | u32 nvcfg1; |
| 11391 | |
| 11392 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11393 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { |
| 11394 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11395 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11396 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11397 | tw32(NVRAM_CFG1, nvcfg1); |
| 11398 | } |
| 11399 | |
Michael Chan | 4c98748 | 2005-09-05 17:52:38 -0700 | [diff] [blame] | 11400 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) || |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 11401 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11402 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11403 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
| 11404 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11405 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
| 11406 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11407 | break; |
| 11408 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: |
| 11409 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11410 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; |
| 11411 | break; |
| 11412 | case FLASH_VENDOR_ATMEL_EEPROM: |
| 11413 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11414 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11415 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11416 | break; |
| 11417 | case FLASH_VENDOR_ST: |
| 11418 | tp->nvram_jedecnum = JEDEC_ST; |
| 11419 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; |
| 11420 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11421 | break; |
| 11422 | case FLASH_VENDOR_SAIFUN: |
| 11423 | tp->nvram_jedecnum = JEDEC_SAIFUN; |
| 11424 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; |
| 11425 | break; |
| 11426 | case FLASH_VENDOR_SST_SMALL: |
| 11427 | case FLASH_VENDOR_SST_LARGE: |
| 11428 | tp->nvram_jedecnum = JEDEC_SST; |
| 11429 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; |
| 11430 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11431 | } |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11432 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11433 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11434 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
| 11435 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11436 | } |
| 11437 | } |
| 11438 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11439 | static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
| 11440 | { |
| 11441 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { |
| 11442 | case FLASH_5752PAGE_SIZE_256: |
| 11443 | tp->nvram_pagesize = 256; |
| 11444 | break; |
| 11445 | case FLASH_5752PAGE_SIZE_512: |
| 11446 | tp->nvram_pagesize = 512; |
| 11447 | break; |
| 11448 | case FLASH_5752PAGE_SIZE_1K: |
| 11449 | tp->nvram_pagesize = 1024; |
| 11450 | break; |
| 11451 | case FLASH_5752PAGE_SIZE_2K: |
| 11452 | tp->nvram_pagesize = 2048; |
| 11453 | break; |
| 11454 | case FLASH_5752PAGE_SIZE_4K: |
| 11455 | tp->nvram_pagesize = 4096; |
| 11456 | break; |
| 11457 | case FLASH_5752PAGE_SIZE_264: |
| 11458 | tp->nvram_pagesize = 264; |
| 11459 | break; |
| 11460 | case FLASH_5752PAGE_SIZE_528: |
| 11461 | tp->nvram_pagesize = 528; |
| 11462 | break; |
| 11463 | } |
| 11464 | } |
| 11465 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11466 | static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp) |
| 11467 | { |
| 11468 | u32 nvcfg1; |
| 11469 | |
| 11470 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11471 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11472 | /* NVRAM protection for TPM */ |
| 11473 | if (nvcfg1 & (1 << 27)) |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 11474 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11475 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11476 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11477 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
| 11478 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: |
| 11479 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11480 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11481 | break; |
| 11482 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11483 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11484 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11485 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11486 | break; |
| 11487 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11488 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11489 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11490 | tp->nvram_jedecnum = JEDEC_ST; |
| 11491 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11492 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11493 | break; |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11494 | } |
| 11495 | |
| 11496 | if (tp->tg3_flags2 & TG3_FLG2_FLASH) { |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11497 | tg3_nvram_get_pagesize(tp, nvcfg1); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11498 | } else { |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11499 | /* For eeprom, set pagesize to maximum eeprom size */ |
| 11500 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11501 | |
| 11502 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11503 | tw32(NVRAM_CFG1, nvcfg1); |
| 11504 | } |
| 11505 | } |
| 11506 | |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11507 | static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp) |
| 11508 | { |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11509 | u32 nvcfg1, protect = 0; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11510 | |
| 11511 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11512 | |
| 11513 | /* NVRAM protection for TPM */ |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11514 | if (nvcfg1 & (1 << 27)) { |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 11515 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11516 | protect = 1; |
| 11517 | } |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11518 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11519 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 11520 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11521 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 11522 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 11523 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 11524 | case FLASH_5755VENDOR_ATMEL_FLASH_5: |
| 11525 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11526 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11527 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11528 | tp->nvram_pagesize = 264; |
| 11529 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || |
| 11530 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) |
| 11531 | tp->nvram_size = (protect ? 0x3e200 : |
| 11532 | TG3_NVRAM_SIZE_512KB); |
| 11533 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) |
| 11534 | tp->nvram_size = (protect ? 0x1f200 : |
| 11535 | TG3_NVRAM_SIZE_256KB); |
| 11536 | else |
| 11537 | tp->nvram_size = (protect ? 0x1f200 : |
| 11538 | TG3_NVRAM_SIZE_128KB); |
| 11539 | break; |
| 11540 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11541 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11542 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11543 | tp->nvram_jedecnum = JEDEC_ST; |
| 11544 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11545 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11546 | tp->nvram_pagesize = 256; |
| 11547 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) |
| 11548 | tp->nvram_size = (protect ? |
| 11549 | TG3_NVRAM_SIZE_64KB : |
| 11550 | TG3_NVRAM_SIZE_128KB); |
| 11551 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) |
| 11552 | tp->nvram_size = (protect ? |
| 11553 | TG3_NVRAM_SIZE_64KB : |
| 11554 | TG3_NVRAM_SIZE_256KB); |
| 11555 | else |
| 11556 | tp->nvram_size = (protect ? |
| 11557 | TG3_NVRAM_SIZE_128KB : |
| 11558 | TG3_NVRAM_SIZE_512KB); |
| 11559 | break; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11560 | } |
| 11561 | } |
| 11562 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11563 | static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) |
| 11564 | { |
| 11565 | u32 nvcfg1; |
| 11566 | |
| 11567 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11568 | |
| 11569 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11570 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
| 11571 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 11572 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: |
| 11573 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 11574 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11575 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11576 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11577 | |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11578 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11579 | tw32(NVRAM_CFG1, nvcfg1); |
| 11580 | break; |
| 11581 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11582 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 11583 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 11584 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 11585 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11586 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11587 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11588 | tp->nvram_pagesize = 264; |
| 11589 | break; |
| 11590 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11591 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11592 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11593 | tp->nvram_jedecnum = JEDEC_ST; |
| 11594 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11595 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11596 | tp->nvram_pagesize = 256; |
| 11597 | break; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11598 | } |
| 11599 | } |
| 11600 | |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11601 | static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp) |
| 11602 | { |
| 11603 | u32 nvcfg1, protect = 0; |
| 11604 | |
| 11605 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11606 | |
| 11607 | /* NVRAM protection for TPM */ |
| 11608 | if (nvcfg1 & (1 << 27)) { |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 11609 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11610 | protect = 1; |
| 11611 | } |
| 11612 | |
| 11613 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 11614 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11615 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 11616 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 11617 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 11618 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 11619 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 11620 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 11621 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 11622 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 11623 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11624 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11625 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11626 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; |
| 11627 | tp->nvram_pagesize = 256; |
| 11628 | break; |
| 11629 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 11630 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 11631 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 11632 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 11633 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 11634 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 11635 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 11636 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 11637 | tp->nvram_jedecnum = JEDEC_ST; |
| 11638 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11639 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11640 | tp->nvram_pagesize = 256; |
| 11641 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11642 | } |
| 11643 | |
| 11644 | if (protect) { |
| 11645 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); |
| 11646 | } else { |
| 11647 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11648 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 11649 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 11650 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 11651 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 11652 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; |
| 11653 | break; |
| 11654 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 11655 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 11656 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 11657 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 11658 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 11659 | break; |
| 11660 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 11661 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 11662 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 11663 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 11664 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11665 | break; |
| 11666 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 11667 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 11668 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 11669 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 11670 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11671 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11672 | } |
| 11673 | } |
| 11674 | } |
| 11675 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 11676 | static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp) |
| 11677 | { |
| 11678 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11679 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11680 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11681 | } |
| 11682 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11683 | static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp) |
| 11684 | { |
| 11685 | u32 nvcfg1; |
| 11686 | |
| 11687 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11688 | |
| 11689 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11690 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 11691 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 11692 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11693 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11694 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11695 | |
| 11696 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11697 | tw32(NVRAM_CFG1, nvcfg1); |
| 11698 | return; |
| 11699 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11700 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 11701 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 11702 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 11703 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 11704 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 11705 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 11706 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11707 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11708 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11709 | |
| 11710 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11711 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11712 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 11713 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 11714 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11715 | break; |
| 11716 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 11717 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 11718 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11719 | break; |
| 11720 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 11721 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 11722 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11723 | break; |
| 11724 | } |
| 11725 | break; |
| 11726 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11727 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11728 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11729 | tp->nvram_jedecnum = JEDEC_ST; |
| 11730 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11731 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11732 | |
| 11733 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11734 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11735 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11736 | break; |
| 11737 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11738 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11739 | break; |
| 11740 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11741 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11742 | break; |
| 11743 | } |
| 11744 | break; |
| 11745 | default: |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11746 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11747 | return; |
| 11748 | } |
| 11749 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11750 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 11751 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11752 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11753 | } |
| 11754 | |
| 11755 | |
| 11756 | static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp) |
| 11757 | { |
| 11758 | u32 nvcfg1; |
| 11759 | |
| 11760 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11761 | |
| 11762 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11763 | case FLASH_5717VENDOR_ATMEL_EEPROM: |
| 11764 | case FLASH_5717VENDOR_MICRO_EEPROM: |
| 11765 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11766 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11767 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11768 | |
| 11769 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11770 | tw32(NVRAM_CFG1, nvcfg1); |
| 11771 | return; |
| 11772 | case FLASH_5717VENDOR_ATMEL_MDB011D: |
| 11773 | case FLASH_5717VENDOR_ATMEL_ADB011B: |
| 11774 | case FLASH_5717VENDOR_ATMEL_ADB011D: |
| 11775 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 11776 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 11777 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 11778 | case FLASH_5717VENDOR_ATMEL_45USPT: |
| 11779 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11780 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11781 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11782 | |
| 11783 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11784 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 11785 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 11786 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 11787 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11788 | break; |
| 11789 | default: |
| 11790 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11791 | break; |
| 11792 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11793 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11794 | case FLASH_5717VENDOR_ST_M_M25PE10: |
| 11795 | case FLASH_5717VENDOR_ST_A_M25PE10: |
| 11796 | case FLASH_5717VENDOR_ST_M_M45PE10: |
| 11797 | case FLASH_5717VENDOR_ST_A_M45PE10: |
| 11798 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 11799 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 11800 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 11801 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 11802 | case FLASH_5717VENDOR_ST_25USPT: |
| 11803 | case FLASH_5717VENDOR_ST_45USPT: |
| 11804 | tp->nvram_jedecnum = JEDEC_ST; |
| 11805 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11806 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11807 | |
| 11808 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11809 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 11810 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 11811 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 11812 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 11813 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11814 | break; |
| 11815 | default: |
| 11816 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11817 | break; |
| 11818 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11819 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11820 | default: |
| 11821 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM; |
| 11822 | return; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11823 | } |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11824 | |
| 11825 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 11826 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
| 11827 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11828 | } |
| 11829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11830 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
| 11831 | static void __devinit tg3_nvram_init(struct tg3 *tp) |
| 11832 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11833 | tw32_f(GRC_EEPROM_ADDR, |
| 11834 | (EEPROM_ADDR_FSM_RESET | |
| 11835 | (EEPROM_DEFAULT_CLOCK_PERIOD << |
| 11836 | EEPROM_ADDR_CLKPERD_SHIFT))); |
| 11837 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 11838 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11839 | |
| 11840 | /* Enable seeprom accesses. */ |
| 11841 | tw32_f(GRC_LOCAL_CTRL, |
| 11842 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); |
| 11843 | udelay(100); |
| 11844 | |
| 11845 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 11846 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
| 11847 | tp->tg3_flags |= TG3_FLAG_NVRAM; |
| 11848 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11849 | if (tg3_nvram_lock(tp)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 11850 | netdev_warn(tp->dev, |
| 11851 | "Cannot get nvram lock, %s failed\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 11852 | __func__); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11853 | return; |
| 11854 | } |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11855 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11856 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11857 | tp->nvram_size = 0; |
| 11858 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11859 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 11860 | tg3_get_5752_nvram_info(tp); |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11861 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 11862 | tg3_get_5755_nvram_info(tp); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 11863 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 11864 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 11865 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11866 | tg3_get_5787_nvram_info(tp); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11867 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 11868 | tg3_get_5761_nvram_info(tp); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 11869 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 11870 | tg3_get_5906_nvram_info(tp); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 11871 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 11872 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11873 | tg3_get_57780_nvram_info(tp); |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 11874 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 11875 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11876 | tg3_get_5717_nvram_info(tp); |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11877 | else |
| 11878 | tg3_get_nvram_info(tp); |
| 11879 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11880 | if (tp->nvram_size == 0) |
| 11881 | tg3_get_nvram_size(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11882 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11883 | tg3_disable_nvram_access(tp); |
Michael Chan | 381291b | 2005-12-13 21:08:21 -0800 | [diff] [blame] | 11884 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11885 | |
| 11886 | } else { |
| 11887 | tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED); |
| 11888 | |
| 11889 | tg3_get_eeprom_size(tp); |
| 11890 | } |
| 11891 | } |
| 11892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11893 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
| 11894 | u32 offset, u32 len, u8 *buf) |
| 11895 | { |
| 11896 | int i, j, rc = 0; |
| 11897 | u32 val; |
| 11898 | |
| 11899 | for (i = 0; i < len; i += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11900 | u32 addr; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11901 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11902 | |
| 11903 | addr = offset + i; |
| 11904 | |
| 11905 | memcpy(&data, buf + i, 4); |
| 11906 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 11907 | /* |
| 11908 | * The SEEPROM interface expects the data to always be opposite |
| 11909 | * the native endian format. We accomplish this by reversing |
| 11910 | * all the operations that would have been performed on the |
| 11911 | * data from a call to tg3_nvram_read_be32(). |
| 11912 | */ |
| 11913 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11914 | |
| 11915 | val = tr32(GRC_EEPROM_ADDR); |
| 11916 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); |
| 11917 | |
| 11918 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | |
| 11919 | EEPROM_ADDR_READ); |
| 11920 | tw32(GRC_EEPROM_ADDR, val | |
| 11921 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 11922 | (addr & EEPROM_ADDR_ADDR_MASK) | |
| 11923 | EEPROM_ADDR_START | |
| 11924 | EEPROM_ADDR_WRITE); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11925 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 11926 | for (j = 0; j < 1000; j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11927 | val = tr32(GRC_EEPROM_ADDR); |
| 11928 | |
| 11929 | if (val & EEPROM_ADDR_COMPLETE) |
| 11930 | break; |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 11931 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11932 | } |
| 11933 | if (!(val & EEPROM_ADDR_COMPLETE)) { |
| 11934 | rc = -EBUSY; |
| 11935 | break; |
| 11936 | } |
| 11937 | } |
| 11938 | |
| 11939 | return rc; |
| 11940 | } |
| 11941 | |
| 11942 | /* offset and length are dword aligned */ |
| 11943 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, |
| 11944 | u8 *buf) |
| 11945 | { |
| 11946 | int ret = 0; |
| 11947 | u32 pagesize = tp->nvram_pagesize; |
| 11948 | u32 pagemask = pagesize - 1; |
| 11949 | u32 nvram_cmd; |
| 11950 | u8 *tmp; |
| 11951 | |
| 11952 | tmp = kmalloc(pagesize, GFP_KERNEL); |
| 11953 | if (tmp == NULL) |
| 11954 | return -ENOMEM; |
| 11955 | |
| 11956 | while (len) { |
| 11957 | int j; |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11958 | u32 phy_addr, page_off, size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11959 | |
| 11960 | phy_addr = offset & ~pagemask; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11962 | for (j = 0; j < pagesize; j += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11963 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
| 11964 | (__be32 *) (tmp + j)); |
| 11965 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11966 | break; |
| 11967 | } |
| 11968 | if (ret) |
| 11969 | break; |
| 11970 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 11971 | page_off = offset & pagemask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11972 | size = pagesize; |
| 11973 | if (len < size) |
| 11974 | size = len; |
| 11975 | |
| 11976 | len -= size; |
| 11977 | |
| 11978 | memcpy(tmp + page_off, buf, size); |
| 11979 | |
| 11980 | offset = offset + (pagesize - page_off); |
| 11981 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11982 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11983 | |
| 11984 | /* |
| 11985 | * Before we can erase the flash page, we need |
| 11986 | * to issue a special "write enable" command. |
| 11987 | */ |
| 11988 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 11989 | |
| 11990 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 11991 | break; |
| 11992 | |
| 11993 | /* Erase the target page */ |
| 11994 | tw32(NVRAM_ADDR, phy_addr); |
| 11995 | |
| 11996 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | |
| 11997 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; |
| 11998 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 11999 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12000 | break; |
| 12001 | |
| 12002 | /* Issue another write enable to start the write. */ |
| 12003 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 12004 | |
| 12005 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 12006 | break; |
| 12007 | |
| 12008 | for (j = 0; j < pagesize; j += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12009 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12010 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12011 | data = *((__be32 *) (tmp + j)); |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12012 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12013 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12014 | |
| 12015 | tw32(NVRAM_ADDR, phy_addr + j); |
| 12016 | |
| 12017 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | |
| 12018 | NVRAM_CMD_WR; |
| 12019 | |
| 12020 | if (j == 0) |
| 12021 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 12022 | else if (j == (pagesize - 4)) |
| 12023 | nvram_cmd |= NVRAM_CMD_LAST; |
| 12024 | |
| 12025 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) |
| 12026 | break; |
| 12027 | } |
| 12028 | if (ret) |
| 12029 | break; |
| 12030 | } |
| 12031 | |
| 12032 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 12033 | tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 12034 | |
| 12035 | kfree(tmp); |
| 12036 | |
| 12037 | return ret; |
| 12038 | } |
| 12039 | |
| 12040 | /* offset and length are dword aligned */ |
| 12041 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, |
| 12042 | u8 *buf) |
| 12043 | { |
| 12044 | int i, ret = 0; |
| 12045 | |
| 12046 | for (i = 0; i < len; i += 4, offset += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12047 | u32 page_off, phy_addr, nvram_cmd; |
| 12048 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12049 | |
| 12050 | memcpy(&data, buf + i, 4); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12051 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12052 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12053 | page_off = offset % tp->nvram_pagesize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12054 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12055 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12056 | |
| 12057 | tw32(NVRAM_ADDR, phy_addr); |
| 12058 | |
| 12059 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
| 12060 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12061 | if (page_off == 0 || i == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12062 | nvram_cmd |= NVRAM_CMD_FIRST; |
Michael Chan | f6d9a25 | 2006-04-29 19:00:24 -0700 | [diff] [blame] | 12063 | if (page_off == (tp->nvram_pagesize - 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12064 | nvram_cmd |= NVRAM_CMD_LAST; |
| 12065 | |
| 12066 | if (i == (len - 4)) |
| 12067 | nvram_cmd |= NVRAM_CMD_LAST; |
| 12068 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12069 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
| 12070 | !(tp->tg3_flags3 & TG3_FLG3_5755_PLUS) && |
Michael Chan | 4c98748 | 2005-09-05 17:52:38 -0700 | [diff] [blame] | 12071 | (tp->nvram_jedecnum == JEDEC_ST) && |
| 12072 | (nvram_cmd & NVRAM_CMD_FIRST)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12073 | |
| 12074 | if ((ret = tg3_nvram_exec_cmd(tp, |
| 12075 | NVRAM_CMD_WREN | NVRAM_CMD_GO | |
| 12076 | NVRAM_CMD_DONE))) |
| 12077 | |
| 12078 | break; |
| 12079 | } |
| 12080 | if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) { |
| 12081 | /* We always do complete word writes to eeprom. */ |
| 12082 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); |
| 12083 | } |
| 12084 | |
| 12085 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) |
| 12086 | break; |
| 12087 | } |
| 12088 | return ret; |
| 12089 | } |
| 12090 | |
| 12091 | /* offset and length are dword aligned */ |
| 12092 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) |
| 12093 | { |
| 12094 | int ret; |
| 12095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12096 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 12097 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
| 12098 | ~GRC_LCLCTRL_GPIO_OUTPUT1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12099 | udelay(40); |
| 12100 | } |
| 12101 | |
| 12102 | if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) { |
| 12103 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 12104 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12105 | u32 grc_mode; |
| 12106 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12107 | ret = tg3_nvram_lock(tp); |
| 12108 | if (ret) |
| 12109 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12110 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12111 | tg3_enable_nvram_access(tp); |
| 12112 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 12113 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12114 | tw32(NVRAM_WRITE1, 0x406); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12115 | |
| 12116 | grc_mode = tr32(GRC_MODE); |
| 12117 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); |
| 12118 | |
| 12119 | if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) || |
| 12120 | !(tp->tg3_flags2 & TG3_FLG2_FLASH)) { |
| 12121 | |
| 12122 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
| 12123 | buf); |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 12124 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12125 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
| 12126 | buf); |
| 12127 | } |
| 12128 | |
| 12129 | grc_mode = tr32(GRC_MODE); |
| 12130 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); |
| 12131 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12132 | tg3_disable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12133 | tg3_nvram_unlock(tp); |
| 12134 | } |
| 12135 | |
| 12136 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 12137 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12138 | udelay(40); |
| 12139 | } |
| 12140 | |
| 12141 | return ret; |
| 12142 | } |
| 12143 | |
| 12144 | struct subsys_tbl_ent { |
| 12145 | u16 subsys_vendor, subsys_devid; |
| 12146 | u32 phy_id; |
| 12147 | }; |
| 12148 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12149 | static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12150 | /* Broadcom boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12151 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12152 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12153 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12154 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12155 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12156 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12157 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 12158 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, |
| 12159 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12160 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12161 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12162 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12163 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 12164 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, |
| 12165 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12166 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12167 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12168 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12169 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12170 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12171 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12172 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12173 | |
| 12174 | /* 3com boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12175 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12176 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12177 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12178 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12179 | { TG3PCI_SUBVENDOR_ID_3COM, |
| 12180 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, |
| 12181 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12182 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12183 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12184 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12185 | |
| 12186 | /* DELL boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12187 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12188 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12189 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12190 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12191 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12192 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12193 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12194 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12195 | |
| 12196 | /* Compaq boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12197 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12198 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12199 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12200 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12201 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 12202 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, |
| 12203 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12204 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12205 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12206 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12207 | |
| 12208 | /* IBM boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12209 | { TG3PCI_SUBVENDOR_ID_IBM, |
| 12210 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12211 | }; |
| 12212 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12213 | static struct subsys_tbl_ent * __devinit tg3_lookup_by_subsys(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12214 | { |
| 12215 | int i; |
| 12216 | |
| 12217 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { |
| 12218 | if ((subsys_id_to_phy_id[i].subsys_vendor == |
| 12219 | tp->pdev->subsystem_vendor) && |
| 12220 | (subsys_id_to_phy_id[i].subsys_devid == |
| 12221 | tp->pdev->subsystem_device)) |
| 12222 | return &subsys_id_to_phy_id[i]; |
| 12223 | } |
| 12224 | return NULL; |
| 12225 | } |
| 12226 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12227 | static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12228 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12229 | u32 val; |
Michael Chan | caf636c7 | 2006-03-22 01:05:31 -0800 | [diff] [blame] | 12230 | u16 pmcsr; |
| 12231 | |
| 12232 | /* On some early chips the SRAM cannot be accessed in D3hot state, |
| 12233 | * so need make sure we're in D0. |
| 12234 | */ |
| 12235 | pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr); |
| 12236 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
| 12237 | pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr); |
| 12238 | msleep(1); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12239 | |
| 12240 | /* Make sure register accesses (indirect or otherwise) |
| 12241 | * will function correctly. |
| 12242 | */ |
| 12243 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 12244 | tp->misc_host_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12245 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12246 | /* The memory arbiter has to be enabled in order for SRAM accesses |
| 12247 | * to succeed. Normally on powerup the tg3 chip firmware will make |
| 12248 | * sure it is enabled, but other entities such as system netboot |
| 12249 | * code might disable it. |
| 12250 | */ |
| 12251 | val = tr32(MEMARB_MODE); |
| 12252 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 12253 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12254 | tp->phy_id = TG3_PHY_ID_INVALID; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12255 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12256 | |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 12257 | /* Assume an onboard device and WOL capable by default. */ |
| 12258 | tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT | TG3_FLAG_WOL_CAP; |
David S. Miller | 72b845e | 2006-03-14 14:11:48 -0800 | [diff] [blame] | 12259 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12260 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12261 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12262 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12263 | tp->tg3_flags2 |= TG3_FLG2_IS_NIC; |
| 12264 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12265 | val = tr32(VCPU_CFGSHDW); |
| 12266 | if (val & VCPU_CFGSHDW_ASPM_DBNC) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12267 | tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND; |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12268 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 12269 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12270 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12271 | goto done; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12272 | } |
| 12273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12274 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 12275 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 12276 | u32 nic_cfg, led_cfg; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12277 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12278 | int eeprom_phy_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12279 | |
| 12280 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 12281 | tp->nic_sram_data_cfg = nic_cfg; |
| 12282 | |
| 12283 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); |
| 12284 | ver >>= NIC_SRAM_DATA_VER_SHIFT; |
| 12285 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) && |
| 12286 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) && |
| 12287 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) && |
| 12288 | (ver > 0) && (ver < 0x100)) |
| 12289 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); |
| 12290 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12291 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 12292 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
| 12293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12294 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
| 12295 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) |
| 12296 | eeprom_phy_serdes = 1; |
| 12297 | |
| 12298 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); |
| 12299 | if (nic_phy_id != 0) { |
| 12300 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; |
| 12301 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; |
| 12302 | |
| 12303 | eeprom_phy_id = (id1 >> 16) << 10; |
| 12304 | eeprom_phy_id |= (id2 & 0xfc00) << 16; |
| 12305 | eeprom_phy_id |= (id2 & 0x03ff) << 0; |
| 12306 | } else |
| 12307 | eeprom_phy_id = 0; |
| 12308 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12309 | tp->phy_id = eeprom_phy_id; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 12310 | if (eeprom_phy_serdes) { |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 12311 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12312 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 12313 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12314 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 12315 | } |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12316 | |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 12317 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12318 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
| 12319 | SHASTA_EXT_LED_MODE_MASK); |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 12320 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12321 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
| 12322 | |
| 12323 | switch (led_cfg) { |
| 12324 | default: |
| 12325 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: |
| 12326 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12327 | break; |
| 12328 | |
| 12329 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: |
| 12330 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 12331 | break; |
| 12332 | |
| 12333 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: |
| 12334 | tp->led_ctrl = LED_CTRL_MODE_MAC; |
Michael Chan | 9ba2779 | 2005-06-06 15:16:20 -0700 | [diff] [blame] | 12335 | |
| 12336 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is |
| 12337 | * read on some older 5700/5701 bootcode. |
| 12338 | */ |
| 12339 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 12340 | ASIC_REV_5700 || |
| 12341 | GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 12342 | ASIC_REV_5701) |
| 12343 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12345 | break; |
| 12346 | |
| 12347 | case SHASTA_EXT_LED_SHARED: |
| 12348 | tp->led_ctrl = LED_CTRL_MODE_SHARED; |
| 12349 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 12350 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) |
| 12351 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 12352 | LED_CTRL_MODE_PHY_2); |
| 12353 | break; |
| 12354 | |
| 12355 | case SHASTA_EXT_LED_MAC: |
| 12356 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; |
| 12357 | break; |
| 12358 | |
| 12359 | case SHASTA_EXT_LED_COMBO: |
| 12360 | tp->led_ctrl = LED_CTRL_MODE_COMBO; |
| 12361 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) |
| 12362 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 12363 | LED_CTRL_MODE_PHY_2); |
| 12364 | break; |
| 12365 | |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 12366 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12367 | |
| 12368 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 12369 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && |
| 12370 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
| 12371 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 12372 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 12373 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
| 12374 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
Matt Carlson | 5f60891 | 2007-11-12 21:17:07 -0800 | [diff] [blame] | 12375 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12376 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12377 | tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT; |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12378 | if ((tp->pdev->subsystem_vendor == |
| 12379 | PCI_VENDOR_ID_ARIMA) && |
| 12380 | (tp->pdev->subsystem_device == 0x205a || |
| 12381 | tp->pdev->subsystem_device == 0x2063)) |
| 12382 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
| 12383 | } else { |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12384 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12385 | tp->tg3_flags2 |= TG3_FLG2_IS_NIC; |
| 12386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12387 | |
| 12388 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
| 12389 | tp->tg3_flags |= TG3_FLAG_ENABLE_ASF; |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 12390 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12391 | tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE; |
| 12392 | } |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 12393 | |
| 12394 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && |
| 12395 | (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 12396 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_APE; |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 12397 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12398 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 12399 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
| 12400 | tp->tg3_flags &= ~TG3_FLAG_WOL_CAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12401 | |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 12402 | if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) && |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12403 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12404 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
| 12405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12406 | if (cfg2 & (1 << 17)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12407 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12408 | |
| 12409 | /* serdes signal pre-emphasis in register 0x590 set by */ |
| 12410 | /* bootcode if bit 18 is set */ |
| 12411 | if (cfg2 & (1 << 18)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12412 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12413 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12414 | if (((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 12415 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) && |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12416 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12417 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12418 | |
Matt Carlson | 8c69b1e | 2010-08-02 11:26:00 +0000 | [diff] [blame] | 12419 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && |
| 12420 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
| 12421 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12422 | u32 cfg3; |
| 12423 | |
| 12424 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); |
| 12425 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) |
| 12426 | tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND; |
| 12427 | } |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12428 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 12429 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
| 12430 | tp->tg3_flags3 |= TG3_FLG3_RGMII_INBAND_DISABLE; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12431 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
| 12432 | tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_RX_EN; |
| 12433 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
| 12434 | tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_TX_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12435 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12436 | done: |
| 12437 | device_init_wakeup(&tp->pdev->dev, tp->tg3_flags & TG3_FLAG_WOL_CAP); |
| 12438 | device_set_wakeup_enable(&tp->pdev->dev, |
| 12439 | tp->tg3_flags & TG3_FLAG_WOL_ENABLE); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12440 | } |
| 12441 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 12442 | static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
| 12443 | { |
| 12444 | int i; |
| 12445 | u32 val; |
| 12446 | |
| 12447 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); |
| 12448 | tw32(OTP_CTRL, cmd); |
| 12449 | |
| 12450 | /* Wait for up to 1 ms for command to execute. */ |
| 12451 | for (i = 0; i < 100; i++) { |
| 12452 | val = tr32(OTP_STATUS); |
| 12453 | if (val & OTP_STATUS_CMD_DONE) |
| 12454 | break; |
| 12455 | udelay(10); |
| 12456 | } |
| 12457 | |
| 12458 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; |
| 12459 | } |
| 12460 | |
| 12461 | /* Read the gphy configuration from the OTP region of the chip. The gphy |
| 12462 | * configuration is a 32-bit value that straddles the alignment boundary. |
| 12463 | * We do two 32-bit reads and then shift and merge the results. |
| 12464 | */ |
| 12465 | static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp) |
| 12466 | { |
| 12467 | u32 bhalf_otp, thalf_otp; |
| 12468 | |
| 12469 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); |
| 12470 | |
| 12471 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) |
| 12472 | return 0; |
| 12473 | |
| 12474 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); |
| 12475 | |
| 12476 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 12477 | return 0; |
| 12478 | |
| 12479 | thalf_otp = tr32(OTP_READ_DATA); |
| 12480 | |
| 12481 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); |
| 12482 | |
| 12483 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 12484 | return 0; |
| 12485 | |
| 12486 | bhalf_otp = tr32(OTP_READ_DATA); |
| 12487 | |
| 12488 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); |
| 12489 | } |
| 12490 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12491 | static int __devinit tg3_phy_probe(struct tg3 *tp) |
| 12492 | { |
| 12493 | u32 hw_phy_id_1, hw_phy_id_2; |
| 12494 | u32 hw_phy_id, hw_phy_id_masked; |
| 12495 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12496 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12497 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) |
| 12498 | return tg3_phy_init(tp); |
| 12499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12500 | /* Reading the PHY ID register can conflict with ASF |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 12501 | * firmware access to the PHY hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12502 | */ |
| 12503 | err = 0; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 12504 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
| 12505 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12506 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12507 | } else { |
| 12508 | /* Now read the physical PHY_ID from the chip and verify |
| 12509 | * that it is sane. If it doesn't look good, we fall back |
| 12510 | * to either the hard-coded table based PHY_ID and failing |
| 12511 | * that the value found in the eeprom area. |
| 12512 | */ |
| 12513 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); |
| 12514 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); |
| 12515 | |
| 12516 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; |
| 12517 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; |
| 12518 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; |
| 12519 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12520 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12521 | } |
| 12522 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12523 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12524 | tp->phy_id = hw_phy_id; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12525 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12526 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Michael Chan | da6b2d0 | 2005-08-19 12:54:29 -0700 | [diff] [blame] | 12527 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12528 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12529 | } else { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12530 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12531 | /* Do nothing, phy ID already set up in |
| 12532 | * tg3_get_eeprom_hw_cfg(). |
| 12533 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12534 | } else { |
| 12535 | struct subsys_tbl_ent *p; |
| 12536 | |
| 12537 | /* No eeprom signature? Try the hardcoded |
| 12538 | * subsys device table. |
| 12539 | */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12540 | p = tg3_lookup_by_subsys(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12541 | if (!p) |
| 12542 | return -ENODEV; |
| 12543 | |
| 12544 | tp->phy_id = p->phy_id; |
| 12545 | if (!tp->phy_id || |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12546 | tp->phy_id == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12547 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12548 | } |
| 12549 | } |
| 12550 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 12551 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 12552 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 12553 | tp->pci_chip_rev_id != CHIPREV_ID_57765_A0)) |
| 12554 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 12555 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12556 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 12557 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12558 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 12559 | u32 bmsr, adv_reg, tg3_ctrl, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12560 | |
| 12561 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 12562 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 12563 | (bmsr & BMSR_LSTATUS)) |
| 12564 | goto skip_phy_reset; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12566 | err = tg3_phy_reset(tp); |
| 12567 | if (err) |
| 12568 | return err; |
| 12569 | |
| 12570 | adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 12571 | ADVERTISE_100HALF | ADVERTISE_100FULL | |
| 12572 | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); |
| 12573 | tg3_ctrl = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12574 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12575 | tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF | |
| 12576 | MII_TG3_CTRL_ADV_1000_FULL); |
| 12577 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 12578 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) |
| 12579 | tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER | |
| 12580 | MII_TG3_CTRL_ENABLE_AS_MASTER); |
| 12581 | } |
| 12582 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 12583 | mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 12584 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 12585 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full); |
| 12586 | if (!tg3_copper_is_advertising_all(tp, mask)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12587 | tg3_writephy(tp, MII_ADVERTISE, adv_reg); |
| 12588 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12589 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12590 | tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl); |
| 12591 | |
| 12592 | tg3_writephy(tp, MII_BMCR, |
| 12593 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 12594 | } |
| 12595 | tg3_phy_set_wirespeed(tp); |
| 12596 | |
| 12597 | tg3_writephy(tp, MII_ADVERTISE, adv_reg); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12598 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12599 | tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl); |
| 12600 | } |
| 12601 | |
| 12602 | skip_phy_reset: |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12603 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12604 | err = tg3_init_5401phy_dsp(tp); |
| 12605 | if (err) |
| 12606 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12608 | err = tg3_init_5401phy_dsp(tp); |
| 12609 | } |
| 12610 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12611 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12612 | tp->link_config.advertising = |
| 12613 | (ADVERTISED_1000baseT_Half | |
| 12614 | ADVERTISED_1000baseT_Full | |
| 12615 | ADVERTISED_Autoneg | |
| 12616 | ADVERTISED_FIBRE); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12617 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12618 | tp->link_config.advertising &= |
| 12619 | ~(ADVERTISED_1000baseT_Half | |
| 12620 | ADVERTISED_1000baseT_Full); |
| 12621 | |
| 12622 | return err; |
| 12623 | } |
| 12624 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 12625 | static void __devinit tg3_read_vpd(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12626 | { |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 12627 | u8 *vpd_data; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12628 | unsigned int block_end, rosize, len; |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 12629 | int j, i = 0; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12630 | u32 magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12631 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 12632 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
| 12633 | tg3_nvram_read(tp, 0x0, &magic)) |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 12634 | goto out_no_vpd; |
| 12635 | |
| 12636 | vpd_data = kmalloc(TG3_NVM_VPD_LEN, GFP_KERNEL); |
| 12637 | if (!vpd_data) |
| 12638 | goto out_no_vpd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12639 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12640 | if (magic == TG3_EEPROM_MAGIC) { |
Matt Carlson | 141518c | 2009-12-03 08:36:22 +0000 | [diff] [blame] | 12641 | for (i = 0; i < TG3_NVM_VPD_LEN; i += 4) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12642 | u32 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12643 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12644 | /* The data is in little-endian format in NVRAM. |
| 12645 | * Use the big-endian read routines to preserve |
| 12646 | * the byte order as it exists in NVRAM. |
| 12647 | */ |
Matt Carlson | 141518c | 2009-12-03 08:36:22 +0000 | [diff] [blame] | 12648 | if (tg3_nvram_read_be32(tp, TG3_NVM_VPD_OFF + i, &tmp)) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12649 | goto out_not_found; |
| 12650 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12651 | memcpy(&vpd_data[i], &tmp, sizeof(tmp)); |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12652 | } |
| 12653 | } else { |
Matt Carlson | 94c982b | 2009-12-03 08:36:23 +0000 | [diff] [blame] | 12654 | ssize_t cnt; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12655 | unsigned int pos = 0; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12656 | |
Matt Carlson | 94c982b | 2009-12-03 08:36:23 +0000 | [diff] [blame] | 12657 | for (; pos < TG3_NVM_VPD_LEN && i < 3; i++, pos += cnt) { |
| 12658 | cnt = pci_read_vpd(tp->pdev, pos, |
| 12659 | TG3_NVM_VPD_LEN - pos, |
| 12660 | &vpd_data[pos]); |
| 12661 | if (cnt == -ETIMEDOUT || -EINTR) |
| 12662 | cnt = 0; |
| 12663 | else if (cnt < 0) |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12664 | goto out_not_found; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12665 | } |
Matt Carlson | 94c982b | 2009-12-03 08:36:23 +0000 | [diff] [blame] | 12666 | if (pos != TG3_NVM_VPD_LEN) |
| 12667 | goto out_not_found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12668 | } |
| 12669 | |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12670 | i = pci_vpd_find_tag(vpd_data, 0, TG3_NVM_VPD_LEN, |
| 12671 | PCI_VPD_LRDT_RO_DATA); |
| 12672 | if (i < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12673 | goto out_not_found; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12674 | |
| 12675 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
| 12676 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; |
| 12677 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 12678 | |
| 12679 | if (block_end > TG3_NVM_VPD_LEN) |
| 12680 | goto out_not_found; |
| 12681 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 12682 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 12683 | PCI_VPD_RO_KEYWORD_MFR_ID); |
| 12684 | if (j > 0) { |
| 12685 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 12686 | |
| 12687 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 12688 | if (j + len > block_end || len != 4 || |
| 12689 | memcmp(&vpd_data[j], "1028", 4)) |
| 12690 | goto partno; |
| 12691 | |
| 12692 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 12693 | PCI_VPD_RO_KEYWORD_VENDOR0); |
| 12694 | if (j < 0) |
| 12695 | goto partno; |
| 12696 | |
| 12697 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 12698 | |
| 12699 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 12700 | if (j + len > block_end) |
| 12701 | goto partno; |
| 12702 | |
| 12703 | memcpy(tp->fw_ver, &vpd_data[j], len); |
| 12704 | strncat(tp->fw_ver, " bc ", TG3_NVM_VPD_LEN - len - 1); |
| 12705 | } |
| 12706 | |
| 12707 | partno: |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12708 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 12709 | PCI_VPD_RO_KEYWORD_PARTNO); |
| 12710 | if (i < 0) |
| 12711 | goto out_not_found; |
| 12712 | |
| 12713 | len = pci_vpd_info_field_size(&vpd_data[i]); |
| 12714 | |
| 12715 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 12716 | if (len > TG3_BPN_SIZE || |
| 12717 | (len + i) > TG3_NVM_VPD_LEN) |
| 12718 | goto out_not_found; |
| 12719 | |
| 12720 | memcpy(tp->board_part_number, &vpd_data[i], len); |
| 12721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12722 | out_not_found: |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 12723 | kfree(vpd_data); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 12724 | if (tp->board_part_number[0]) |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 12725 | return; |
| 12726 | |
| 12727 | out_no_vpd: |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 12728 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 12729 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717) |
| 12730 | strcpy(tp->board_part_number, "BCM5717"); |
| 12731 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) |
| 12732 | strcpy(tp->board_part_number, "BCM5718"); |
| 12733 | else |
| 12734 | goto nomatch; |
| 12735 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 12736 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
| 12737 | strcpy(tp->board_part_number, "BCM57780"); |
| 12738 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) |
| 12739 | strcpy(tp->board_part_number, "BCM57760"); |
| 12740 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) |
| 12741 | strcpy(tp->board_part_number, "BCM57790"); |
| 12742 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) |
| 12743 | strcpy(tp->board_part_number, "BCM57788"); |
| 12744 | else |
| 12745 | goto nomatch; |
| 12746 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
| 12747 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
| 12748 | strcpy(tp->board_part_number, "BCM57761"); |
| 12749 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) |
| 12750 | strcpy(tp->board_part_number, "BCM57765"); |
| 12751 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) |
| 12752 | strcpy(tp->board_part_number, "BCM57781"); |
| 12753 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) |
| 12754 | strcpy(tp->board_part_number, "BCM57785"); |
| 12755 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) |
| 12756 | strcpy(tp->board_part_number, "BCM57791"); |
| 12757 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 12758 | strcpy(tp->board_part_number, "BCM57795"); |
| 12759 | else |
| 12760 | goto nomatch; |
| 12761 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12762 | strcpy(tp->board_part_number, "BCM95906"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 12763 | } else { |
| 12764 | nomatch: |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12765 | strcpy(tp->board_part_number, "none"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 12766 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12767 | } |
| 12768 | |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12769 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
| 12770 | { |
| 12771 | u32 val; |
| 12772 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12773 | if (tg3_nvram_read(tp, offset, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12774 | (val & 0xfc000000) != 0x0c000000 || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12775 | tg3_nvram_read(tp, offset + 4, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12776 | val != 0) |
| 12777 | return 0; |
| 12778 | |
| 12779 | return 1; |
| 12780 | } |
| 12781 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12782 | static void __devinit tg3_read_bc_ver(struct tg3 *tp) |
| 12783 | { |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12784 | u32 val, offset, start, ver_offset; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12785 | int i, dst_off; |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12786 | bool newver = false; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12787 | |
| 12788 | if (tg3_nvram_read(tp, 0xc, &offset) || |
| 12789 | tg3_nvram_read(tp, 0x4, &start)) |
| 12790 | return; |
| 12791 | |
| 12792 | offset = tg3_nvram_logical_addr(tp, offset); |
| 12793 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12794 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12795 | return; |
| 12796 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12797 | if ((val & 0xfc000000) == 0x0c000000) { |
| 12798 | if (tg3_nvram_read(tp, offset + 4, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12799 | return; |
| 12800 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12801 | if (val == 0) |
| 12802 | newver = true; |
| 12803 | } |
| 12804 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12805 | dst_off = strlen(tp->fw_ver); |
| 12806 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12807 | if (newver) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12808 | if (TG3_VER_SIZE - dst_off < 16 || |
| 12809 | tg3_nvram_read(tp, offset + 8, &ver_offset)) |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12810 | return; |
| 12811 | |
| 12812 | offset = offset + ver_offset - start; |
| 12813 | for (i = 0; i < 16; i += 4) { |
| 12814 | __be32 v; |
| 12815 | if (tg3_nvram_read_be32(tp, offset + i, &v)) |
| 12816 | return; |
| 12817 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12818 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12819 | } |
| 12820 | } else { |
| 12821 | u32 major, minor; |
| 12822 | |
| 12823 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) |
| 12824 | return; |
| 12825 | |
| 12826 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> |
| 12827 | TG3_NVM_BCVER_MAJSFT; |
| 12828 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12829 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
| 12830 | "v%d.%02d", major, minor); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12831 | } |
| 12832 | } |
| 12833 | |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 12834 | static void __devinit tg3_read_hwsb_ver(struct tg3 *tp) |
| 12835 | { |
| 12836 | u32 val, major, minor; |
| 12837 | |
| 12838 | /* Use native endian representation */ |
| 12839 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) |
| 12840 | return; |
| 12841 | |
| 12842 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> |
| 12843 | TG3_NVM_HWSB_CFG1_MAJSFT; |
| 12844 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> |
| 12845 | TG3_NVM_HWSB_CFG1_MINSFT; |
| 12846 | |
| 12847 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); |
| 12848 | } |
| 12849 | |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12850 | static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val) |
| 12851 | { |
| 12852 | u32 offset, major, minor, build; |
| 12853 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12854 | 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] | 12855 | |
| 12856 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) |
| 12857 | return; |
| 12858 | |
| 12859 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { |
| 12860 | case TG3_EEPROM_SB_REVISION_0: |
| 12861 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; |
| 12862 | break; |
| 12863 | case TG3_EEPROM_SB_REVISION_2: |
| 12864 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; |
| 12865 | break; |
| 12866 | case TG3_EEPROM_SB_REVISION_3: |
| 12867 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; |
| 12868 | break; |
Matt Carlson | a4153d4 | 2010-02-17 15:16:56 +0000 | [diff] [blame] | 12869 | case TG3_EEPROM_SB_REVISION_4: |
| 12870 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; |
| 12871 | break; |
| 12872 | case TG3_EEPROM_SB_REVISION_5: |
| 12873 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; |
| 12874 | break; |
Matt Carlson | bba226a | 2010-10-14 10:37:38 +0000 | [diff] [blame] | 12875 | case TG3_EEPROM_SB_REVISION_6: |
| 12876 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; |
| 12877 | break; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12878 | default: |
| 12879 | return; |
| 12880 | } |
| 12881 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12882 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12883 | return; |
| 12884 | |
| 12885 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> |
| 12886 | TG3_EEPROM_SB_EDH_BLD_SHFT; |
| 12887 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> |
| 12888 | TG3_EEPROM_SB_EDH_MAJ_SHFT; |
| 12889 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; |
| 12890 | |
| 12891 | if (minor > 99 || build > 26) |
| 12892 | return; |
| 12893 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12894 | offset = strlen(tp->fw_ver); |
| 12895 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, |
| 12896 | " v%d.%02d", major, minor); |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12897 | |
| 12898 | if (build > 0) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12899 | offset = strlen(tp->fw_ver); |
| 12900 | if (offset < TG3_VER_SIZE - 1) |
| 12901 | tp->fw_ver[offset] = 'a' + build - 1; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12902 | } |
| 12903 | } |
| 12904 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12905 | static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp) |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 12906 | { |
| 12907 | u32 val, offset, start; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12908 | int i, vlen; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12909 | |
| 12910 | for (offset = TG3_NVM_DIR_START; |
| 12911 | offset < TG3_NVM_DIR_END; |
| 12912 | offset += TG3_NVM_DIRENT_SIZE) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12913 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12914 | return; |
| 12915 | |
| 12916 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
| 12917 | break; |
| 12918 | } |
| 12919 | |
| 12920 | if (offset == TG3_NVM_DIR_END) |
| 12921 | return; |
| 12922 | |
| 12923 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 12924 | start = 0x08000000; |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12925 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12926 | return; |
| 12927 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12928 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12929 | !tg3_fw_img_is_valid(tp, offset) || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12930 | tg3_nvram_read(tp, offset + 8, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12931 | return; |
| 12932 | |
| 12933 | offset += val - start; |
| 12934 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12935 | vlen = strlen(tp->fw_ver); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12936 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12937 | tp->fw_ver[vlen++] = ','; |
| 12938 | tp->fw_ver[vlen++] = ' '; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12939 | |
| 12940 | for (i = 0; i < 4; i++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12941 | __be32 v; |
| 12942 | if (tg3_nvram_read_be32(tp, offset, &v)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12943 | return; |
| 12944 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12945 | offset += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12946 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12947 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
| 12948 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12949 | break; |
| 12950 | } |
| 12951 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12952 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
| 12953 | vlen += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12954 | } |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12955 | } |
| 12956 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 12957 | static void __devinit tg3_read_dash_ver(struct tg3 *tp) |
| 12958 | { |
| 12959 | int vlen; |
| 12960 | u32 apedata; |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 12961 | char *fwtype; |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 12962 | |
| 12963 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) || |
| 12964 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 12965 | return; |
| 12966 | |
| 12967 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 12968 | if (apedata != APE_SEG_SIG_MAGIC) |
| 12969 | return; |
| 12970 | |
| 12971 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 12972 | if (!(apedata & APE_FW_STATUS_READY)) |
| 12973 | return; |
| 12974 | |
| 12975 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
| 12976 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 12977 | if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) { |
| 12978 | tp->tg3_flags3 |= TG3_FLG3_APE_HAS_NCSI; |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 12979 | fwtype = "NCSI"; |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 12980 | } else { |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 12981 | fwtype = "DASH"; |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 12982 | } |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 12983 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 12984 | vlen = strlen(tp->fw_ver); |
| 12985 | |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 12986 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
| 12987 | fwtype, |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 12988 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
| 12989 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, |
| 12990 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, |
| 12991 | (apedata & APE_FW_VERSION_BLDMSK)); |
| 12992 | } |
| 12993 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12994 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
| 12995 | { |
| 12996 | u32 val; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12997 | bool vpd_vers = false; |
| 12998 | |
| 12999 | if (tp->fw_ver[0] != 0) |
| 13000 | vpd_vers = true; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13001 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 13002 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13003 | strcat(tp->fw_ver, "sb"); |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 13004 | return; |
| 13005 | } |
| 13006 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13007 | if (tg3_nvram_read(tp, 0, &val)) |
| 13008 | return; |
| 13009 | |
| 13010 | if (val == TG3_EEPROM_MAGIC) |
| 13011 | tg3_read_bc_ver(tp); |
| 13012 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) |
| 13013 | tg3_read_sb_ver(tp, val); |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 13014 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 13015 | tg3_read_hwsb_ver(tp); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13016 | else |
| 13017 | return; |
| 13018 | |
| 13019 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13020 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) || vpd_vers) |
| 13021 | goto done; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13022 | |
| 13023 | tg3_read_mgmtfw_ver(tp); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13024 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13025 | done: |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13026 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13027 | } |
| 13028 | |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13029 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *); |
| 13030 | |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 13031 | static void inline vlan_features_add(struct net_device *dev, unsigned long flags) |
| 13032 | { |
| 13033 | #if TG3_VLAN_TAG_USED |
| 13034 | dev->vlan_features |= flags; |
| 13035 | #endif |
| 13036 | } |
| 13037 | |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13038 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
| 13039 | { |
| 13040 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13041 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 13042 | return 4096; |
| 13043 | else if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && |
| 13044 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
| 13045 | return 1024; |
| 13046 | else |
| 13047 | return 512; |
| 13048 | } |
| 13049 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13050 | static int __devinit tg3_get_invariants(struct tg3 *tp) |
| 13051 | { |
| 13052 | static struct pci_device_id write_reorder_chipsets[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13053 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 13054 | PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
John W. Linville | c165b00 | 2006-07-08 13:28:53 -0700 | [diff] [blame] | 13055 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 13056 | PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 13057 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, |
| 13058 | PCI_DEVICE_ID_VIA_8385_0) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13059 | { }, |
| 13060 | }; |
| 13061 | u32 misc_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13062 | u32 pci_state_reg, grc_misc_cfg; |
| 13063 | u32 val; |
| 13064 | u16 pci_cmd; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13065 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13067 | /* Force memory write invalidate off. If we leave it on, |
| 13068 | * then on 5700_BX chips we have to enable a workaround. |
| 13069 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary |
| 13070 | * to match the cacheline size. The Broadcom driver have this |
| 13071 | * workaround but turns MWI off all the times so never uses |
| 13072 | * it. This seems to suggest that the workaround is insufficient. |
| 13073 | */ |
| 13074 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13075 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; |
| 13076 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13077 | |
| 13078 | /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL |
| 13079 | * has the register indirect write enable bit set before |
| 13080 | * we try to access any of the MMIO registers. It is also |
| 13081 | * critical that the PCI-X hw workaround situation is decided |
| 13082 | * before that as well. |
| 13083 | */ |
| 13084 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 13085 | &misc_ctrl_reg); |
| 13086 | |
| 13087 | tp->pci_chip_rev_id = (misc_ctrl_reg >> |
| 13088 | MISC_HOST_CTRL_CHIPREV_SHIFT); |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 13089 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
| 13090 | u32 prod_id_asic_rev; |
| 13091 | |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 13092 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 13093 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13094 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13095 | pci_read_config_dword(tp->pdev, |
| 13096 | TG3PCI_GEN2_PRODID_ASICREV, |
| 13097 | &prod_id_asic_rev); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13098 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
| 13099 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || |
| 13100 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || |
| 13101 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || |
| 13102 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 13103 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 13104 | pci_read_config_dword(tp->pdev, |
| 13105 | TG3PCI_GEN15_PRODID_ASICREV, |
| 13106 | &prod_id_asic_rev); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13107 | else |
| 13108 | pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV, |
| 13109 | &prod_id_asic_rev); |
| 13110 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13111 | tp->pci_chip_rev_id = prod_id_asic_rev; |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 13112 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13113 | |
Michael Chan | ff645be | 2005-04-21 17:09:53 -0700 | [diff] [blame] | 13114 | /* Wrong chip ID in 5752 A0. This code can be removed later |
| 13115 | * as A0 is not in production. |
| 13116 | */ |
| 13117 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) |
| 13118 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
| 13119 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13120 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
| 13121 | * we need to disable memory and use config. cycles |
| 13122 | * only to access all registers. The 5702/03 chips |
| 13123 | * can mistakenly decode the special cycles from the |
| 13124 | * ICH chipsets as memory write cycles, causing corruption |
| 13125 | * of register and memory space. Only certain ICH bridges |
| 13126 | * will drive special cycles with non-zero data during the |
| 13127 | * address phase which can fall within the 5703's address |
| 13128 | * range. This is not an ICH bug as the PCI spec allows |
| 13129 | * non-zero address during special cycles. However, only |
| 13130 | * these ICH bridges are known to drive non-zero addresses |
| 13131 | * during special cycles. |
| 13132 | * |
| 13133 | * Since special cycles do not cross PCI bridges, we only |
| 13134 | * enable this workaround if the 5703 is on the secondary |
| 13135 | * bus of these ICH bridges. |
| 13136 | */ |
| 13137 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || |
| 13138 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { |
| 13139 | static struct tg3_dev_id { |
| 13140 | u32 vendor; |
| 13141 | u32 device; |
| 13142 | u32 rev; |
| 13143 | } ich_chipsets[] = { |
| 13144 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, |
| 13145 | PCI_ANY_ID }, |
| 13146 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, |
| 13147 | PCI_ANY_ID }, |
| 13148 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, |
| 13149 | 0xa }, |
| 13150 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, |
| 13151 | PCI_ANY_ID }, |
| 13152 | { }, |
| 13153 | }; |
| 13154 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; |
| 13155 | struct pci_dev *bridge = NULL; |
| 13156 | |
| 13157 | while (pci_id->vendor != 0) { |
| 13158 | bridge = pci_get_device(pci_id->vendor, pci_id->device, |
| 13159 | bridge); |
| 13160 | if (!bridge) { |
| 13161 | pci_id++; |
| 13162 | continue; |
| 13163 | } |
| 13164 | if (pci_id->rev != PCI_ANY_ID) { |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 13165 | if (bridge->revision > pci_id->rev) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13166 | continue; |
| 13167 | } |
| 13168 | if (bridge->subordinate && |
| 13169 | (bridge->subordinate->number == |
| 13170 | tp->pdev->bus->number)) { |
| 13171 | |
| 13172 | tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND; |
| 13173 | pci_dev_put(bridge); |
| 13174 | break; |
| 13175 | } |
| 13176 | } |
| 13177 | } |
| 13178 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 13179 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 13180 | static struct tg3_dev_id { |
| 13181 | u32 vendor; |
| 13182 | u32 device; |
| 13183 | } bridge_chipsets[] = { |
| 13184 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, |
| 13185 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, |
| 13186 | { }, |
| 13187 | }; |
| 13188 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; |
| 13189 | struct pci_dev *bridge = NULL; |
| 13190 | |
| 13191 | while (pci_id->vendor != 0) { |
| 13192 | bridge = pci_get_device(pci_id->vendor, |
| 13193 | pci_id->device, |
| 13194 | bridge); |
| 13195 | if (!bridge) { |
| 13196 | pci_id++; |
| 13197 | continue; |
| 13198 | } |
| 13199 | if (bridge->subordinate && |
| 13200 | (bridge->subordinate->number <= |
| 13201 | tp->pdev->bus->number) && |
| 13202 | (bridge->subordinate->subordinate >= |
| 13203 | tp->pdev->bus->number)) { |
| 13204 | tp->tg3_flags3 |= TG3_FLG3_5701_DMA_BUG; |
| 13205 | pci_dev_put(bridge); |
| 13206 | break; |
| 13207 | } |
| 13208 | } |
| 13209 | } |
| 13210 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13211 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
| 13212 | * DMA addresses > 40-bit. This bridge may have other additional |
| 13213 | * 57xx devices behind it in some 4-port NIC designs for example. |
| 13214 | * Any tg3 device found behind the bridge will also need the 40-bit |
| 13215 | * DMA workaround. |
| 13216 | */ |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13217 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
| 13218 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 13219 | tp->tg3_flags2 |= TG3_FLG2_5780_CLASS; |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13220 | tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG; |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 13221 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 13222 | } else { |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13223 | struct pci_dev *bridge = NULL; |
| 13224 | |
| 13225 | do { |
| 13226 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, |
| 13227 | PCI_DEVICE_ID_SERVERWORKS_EPB, |
| 13228 | bridge); |
| 13229 | if (bridge && bridge->subordinate && |
| 13230 | (bridge->subordinate->number <= |
| 13231 | tp->pdev->bus->number) && |
| 13232 | (bridge->subordinate->subordinate >= |
| 13233 | tp->pdev->bus->number)) { |
| 13234 | tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG; |
| 13235 | pci_dev_put(bridge); |
| 13236 | break; |
| 13237 | } |
| 13238 | } while (bridge); |
| 13239 | } |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 13240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13241 | /* Initialize misc host control in PCI block. */ |
| 13242 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
| 13243 | MISC_HOST_CTRL_CHIPREV); |
| 13244 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 13245 | tp->misc_host_ctrl); |
| 13246 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13247 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 13248 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || |
| 13249 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13250 | tp->pdev_peer = tg3_find_peer(tp); |
| 13251 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13252 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13253 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 13254 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 13255 | tp->tg3_flags3 |= TG3_FLG3_5717_PLUS; |
| 13256 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13257 | /* Intentionally exclude ASIC_REV_5906 */ |
| 13258 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 13259 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13260 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13261 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13262 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13263 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13264 | (tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13265 | tp->tg3_flags3 |= TG3_FLG3_5755_PLUS; |
| 13266 | |
| 13267 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 13268 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13269 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13270 | (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13271 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
John W. Linville | 6708e5c | 2005-04-21 17:00:52 -0700 | [diff] [blame] | 13272 | tp->tg3_flags2 |= TG3_FLG2_5750_PLUS; |
| 13273 | |
John W. Linville | 1b440c56 | 2005-04-21 17:03:18 -0700 | [diff] [blame] | 13274 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) || |
| 13275 | (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) |
| 13276 | tp->tg3_flags2 |= TG3_FLG2_5705_PLUS; |
| 13277 | |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13278 | /* 5700 B0 chips do not support checksumming correctly due |
| 13279 | * to hardware bugs. |
| 13280 | */ |
| 13281 | if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0) |
| 13282 | tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS; |
| 13283 | else { |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 13284 | unsigned long features = NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_GRO; |
| 13285 | |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13286 | tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13287 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 13288 | features |= NETIF_F_IPV6_CSUM; |
| 13289 | tp->dev->features |= features; |
| 13290 | vlan_features_add(tp->dev, features); |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13291 | } |
| 13292 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13293 | /* Determine TSO capabilities */ |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13294 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 13295 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_3; |
| 13296 | else if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
| 13297 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13298 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2; |
| 13299 | else if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
| 13300 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG; |
| 13301 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && |
| 13302 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) |
| 13303 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG; |
| 13304 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13305 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 13306 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
| 13307 | tp->tg3_flags2 |= TG3_FLG2_TSO_BUG; |
| 13308 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) |
| 13309 | tp->fw_needed = FIRMWARE_TG3TSO5; |
| 13310 | else |
| 13311 | tp->fw_needed = FIRMWARE_TG3TSO; |
| 13312 | } |
| 13313 | |
| 13314 | tp->irq_max = 1; |
| 13315 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 13316 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13317 | tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI; |
| 13318 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || |
| 13319 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || |
| 13320 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && |
| 13321 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && |
| 13322 | tp->pdev_peer == tp->pdev)) |
| 13323 | tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI; |
| 13324 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13325 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13326 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 13327 | tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 13328 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13329 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13330 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13331 | tp->tg3_flags |= TG3_FLAG_SUPPORT_MSIX; |
| 13332 | tp->irq_max = TG3_IRQ_MAX_VECS; |
| 13333 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13334 | } |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 13335 | |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 13336 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13337 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 13338 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 13339 | tp->tg3_flags3 |= TG3_FLG3_SHORT_DMA_BUG; |
| 13340 | else if (!(tp->tg3_flags3 & TG3_FLG3_5755_PLUS)) { |
| 13341 | tp->tg3_flags3 |= TG3_FLG3_4G_DMA_BNDRY_BUG; |
| 13342 | tp->tg3_flags3 |= TG3_FLG3_40BIT_DMA_LIMIT_BUG; |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 13343 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13344 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13345 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13346 | tp->tg3_flags3 |= TG3_FLG3_USE_JUMBO_BDFLAG; |
| 13347 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 13348 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 13349 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
| 13350 | (tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG)) |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 13351 | tp->tg3_flags |= TG3_FLAG_JUMBO_CAPABLE; |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 13352 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13353 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13354 | &pci_state_reg); |
| 13355 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13356 | tp->pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP); |
| 13357 | if (tp->pcie_cap != 0) { |
| 13358 | u16 lnkctl; |
| 13359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13360 | tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS; |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 13361 | |
| 13362 | pcie_set_readrq(tp->pdev, 4096); |
| 13363 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13364 | pci_read_config_word(tp->pdev, |
| 13365 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 13366 | &lnkctl); |
| 13367 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
| 13368 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 13369 | tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13370 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13371 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 9cf74eb | 2009-04-20 06:58:27 +0000 | [diff] [blame] | 13372 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
| 13373 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13374 | tp->tg3_flags3 |= TG3_FLG3_CLKREQ_BUG; |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 13375 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
| 13376 | tp->tg3_flags3 |= TG3_FLG3_L1PLLPD_EN; |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 13377 | } |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13378 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 13379 | tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS; |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13380 | } else if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
| 13381 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
| 13382 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
| 13383 | if (!tp->pcix_cap) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 13384 | dev_err(&tp->pdev->dev, |
| 13385 | "Cannot find PCI-X capability, aborting\n"); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13386 | return -EIO; |
| 13387 | } |
| 13388 | |
| 13389 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) |
| 13390 | tp->tg3_flags |= TG3_FLAG_PCIX_MODE; |
| 13391 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13392 | |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 13393 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
| 13394 | * reordering to the mailbox registers done by the host |
| 13395 | * controller can cause major troubles. We read back from |
| 13396 | * every mailbox register write to force the writes to be |
| 13397 | * posted to the chip in order. |
| 13398 | */ |
| 13399 | if (pci_dev_present(write_reorder_chipsets) && |
| 13400 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) |
| 13401 | tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER; |
| 13402 | |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 13403 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 13404 | &tp->pci_cacheline_sz); |
| 13405 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 13406 | &tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13407 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 13408 | tp->pci_lat_timer < 64) { |
| 13409 | tp->pci_lat_timer = 64; |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 13410 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 13411 | tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13412 | } |
| 13413 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13414 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
| 13415 | /* 5700 BX chips need to have their TX producer index |
| 13416 | * mailboxes written twice to workaround a bug. |
| 13417 | */ |
| 13418 | tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13419 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13420 | /* If we are in PCI-X mode, enable register write workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13421 | * |
| 13422 | * The workaround is to use indirect register accesses |
| 13423 | * for all chip writes not to mailbox registers. |
| 13424 | */ |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13425 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13426 | u32 pm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13427 | |
| 13428 | tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG; |
| 13429 | |
| 13430 | /* The chip can have it's power management PCI config |
| 13431 | * space registers clobbered due to this bug. |
| 13432 | * So explicitly force the chip into D0 here. |
| 13433 | */ |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13434 | pci_read_config_dword(tp->pdev, |
| 13435 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13436 | &pm_reg); |
| 13437 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; |
| 13438 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13439 | pci_write_config_dword(tp->pdev, |
| 13440 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13441 | pm_reg); |
| 13442 | |
| 13443 | /* Also, force SERR#/PERR# in PCI command. */ |
| 13444 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13445 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
| 13446 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13447 | } |
| 13448 | } |
| 13449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13450 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
| 13451 | tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED; |
| 13452 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
| 13453 | tp->tg3_flags |= TG3_FLAG_PCI_32BIT; |
| 13454 | |
| 13455 | /* Chip-specific fixup from Broadcom driver */ |
| 13456 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && |
| 13457 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
| 13458 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; |
| 13459 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); |
| 13460 | } |
| 13461 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13462 | /* Default fast path register access methods */ |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13463 | tp->read32 = tg3_read32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13464 | tp->write32 = tg3_write32; |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 13465 | tp->read32_mbox = tg3_read32; |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13466 | tp->write32_mbox = tg3_write32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13467 | tp->write32_tx_mbox = tg3_write32; |
| 13468 | tp->write32_rx_mbox = tg3_write32; |
| 13469 | |
| 13470 | /* Various workaround register access methods */ |
| 13471 | if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) |
| 13472 | tp->write32 = tg3_write_indirect_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 13473 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 || |
| 13474 | ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && |
| 13475 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { |
| 13476 | /* |
| 13477 | * Back to back register writes can cause problems on these |
| 13478 | * chips, the workaround is to read back all reg writes |
| 13479 | * except those to mailbox regs. |
| 13480 | * |
| 13481 | * See tg3_write_indirect_reg32(). |
| 13482 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13483 | tp->write32 = tg3_write_flush_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 13484 | } |
| 13485 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13486 | if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) || |
| 13487 | (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) { |
| 13488 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 13489 | if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) |
| 13490 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 13491 | } |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13492 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13493 | if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) { |
| 13494 | tp->read32 = tg3_read_indirect_reg32; |
| 13495 | tp->write32 = tg3_write_indirect_reg32; |
| 13496 | tp->read32_mbox = tg3_read_indirect_mbox; |
| 13497 | tp->write32_mbox = tg3_write_indirect_mbox; |
| 13498 | tp->write32_tx_mbox = tg3_write_indirect_mbox; |
| 13499 | tp->write32_rx_mbox = tg3_write_indirect_mbox; |
| 13500 | |
| 13501 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 13502 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13503 | |
| 13504 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13505 | pci_cmd &= ~PCI_COMMAND_MEMORY; |
| 13506 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13507 | } |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13508 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 13509 | tp->read32_mbox = tg3_read32_mbox_5906; |
| 13510 | tp->write32_mbox = tg3_write32_mbox_5906; |
| 13511 | tp->write32_tx_mbox = tg3_write32_mbox_5906; |
| 13512 | tp->write32_rx_mbox = tg3_write32_mbox_5906; |
| 13513 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13514 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 13515 | if (tp->write32 == tg3_write_indirect_reg32 || |
| 13516 | ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) && |
| 13517 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 13518 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 13519 | tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG; |
| 13520 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13521 | /* Get eeprom hw config before calling tg3_set_power_state(). |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13522 | * In particular, the TG3_FLG2_IS_NIC flag must be |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13523 | * determined before calling tg3_set_power_state() so that |
| 13524 | * we know whether or not to switch out of Vaux power. |
| 13525 | * When the flag is set, it means that GPIO1 is used for eeprom |
| 13526 | * write protect and also implies that it is a LOM where GPIOs |
| 13527 | * are not used to switch power. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13528 | */ |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13529 | tg3_get_eeprom_hw_cfg(tp); |
| 13530 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 13531 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
| 13532 | /* Allow reads and writes to the |
| 13533 | * APE register and memory space. |
| 13534 | */ |
| 13535 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 13536 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 13537 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 13538 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13539 | pci_state_reg); |
| 13540 | } |
| 13541 | |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13542 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13543 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13544 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13545 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13546 | (tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13547 | tp->tg3_flags |= TG3_FLAG_CPMU_PRESENT; |
| 13548 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 13549 | /* Set up tp->grc_local_ctrl before calling tg3_set_power_state(). |
| 13550 | * GPIO1 driven high will bring 5700's external PHY out of reset. |
| 13551 | * It is also used as eeprom write protect on LOMs. |
| 13552 | */ |
| 13553 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; |
| 13554 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || |
| 13555 | (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)) |
| 13556 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 13557 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 13558 | /* Unused GPIO3 must be driven as output on 5752 because there |
| 13559 | * are no pull-up resistors on unused GPIO pins. |
| 13560 | */ |
| 13561 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 13562 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 13563 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13564 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | cb4ed1f | 2010-01-20 16:58:09 +0000 | [diff] [blame] | 13565 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 13566 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 13567 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 13568 | |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 13569 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 13570 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 13571 | /* Turn off the debug UART. */ |
| 13572 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 13573 | if (tp->tg3_flags2 & TG3_FLG2_IS_NIC) |
| 13574 | /* Keep VMain power. */ |
| 13575 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 13576 | GRC_LCLCTRL_GPIO_OUTPUT0; |
| 13577 | } |
| 13578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13579 | /* Force the chip into D0. */ |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 13580 | err = tg3_set_power_state(tp, PCI_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13581 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 13582 | dev_err(&tp->pdev->dev, "Transition to D0 failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13583 | return err; |
| 13584 | } |
| 13585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13586 | /* Derive initial jumbo mode from MTU assigned in |
| 13587 | * ether_setup() via the alloc_etherdev() call |
| 13588 | */ |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 13589 | if (tp->dev->mtu > ETH_DATA_LEN && |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13590 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 13591 | tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13592 | |
| 13593 | /* Determine WakeOnLan speed to use. */ |
| 13594 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 13595 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 13596 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || |
| 13597 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { |
| 13598 | tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB); |
| 13599 | } else { |
| 13600 | tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB; |
| 13601 | } |
| 13602 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 13603 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13604 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 13605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13606 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
| 13607 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || |
| 13608 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
| 13609 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13610 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13611 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
| 13612 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 13613 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13614 | |
| 13615 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || |
| 13616 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13617 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13618 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13619 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13620 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13621 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13622 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13623 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13624 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13625 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 13626 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13627 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13628 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 13629 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
Michael Chan | d4011ad | 2007-02-13 12:17:25 -0800 | [diff] [blame] | 13630 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
| 13631 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13632 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 13633 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13634 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13635 | } else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13636 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 13637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13638 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 13639 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 13640 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 13641 | tp->phy_otp = tg3_read_otp_phycfg(tp); |
| 13642 | if (tp->phy_otp == 0) |
| 13643 | tp->phy_otp = TG3_OTP_DEFAULT; |
| 13644 | } |
| 13645 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 13646 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 13647 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
| 13648 | else |
| 13649 | tp->mi_mode = MAC_MI_MODE_BASE; |
| 13650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13651 | tp->coalesce_mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13652 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
| 13653 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) |
| 13654 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
| 13655 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13656 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 13657 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13658 | tp->tg3_flags3 |= TG3_FLG3_USE_PHYLIB; |
| 13659 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 13660 | err = tg3_mdio_init(tp); |
| 13661 | if (err) |
| 13662 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13663 | |
| 13664 | /* Initialize data/descriptor byte/word swapping. */ |
| 13665 | val = tr32(GRC_MODE); |
| 13666 | val &= GRC_MODE_HOST_STACKUP; |
| 13667 | tw32(GRC_MODE, val | tp->grc_mode); |
| 13668 | |
| 13669 | tg3_switch_clocks(tp); |
| 13670 | |
| 13671 | /* Clear this out for sanity. */ |
| 13672 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 13673 | |
| 13674 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13675 | &pci_state_reg); |
| 13676 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && |
| 13677 | (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) { |
| 13678 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); |
| 13679 | |
| 13680 | if (chiprevid == CHIPREV_ID_5701_A0 || |
| 13681 | chiprevid == CHIPREV_ID_5701_B0 || |
| 13682 | chiprevid == CHIPREV_ID_5701_B2 || |
| 13683 | chiprevid == CHIPREV_ID_5701_B5) { |
| 13684 | void __iomem *sram_base; |
| 13685 | |
| 13686 | /* Write some dummy words into the SRAM status block |
| 13687 | * area, see if it reads back correctly. If the return |
| 13688 | * value is bad, force enable the PCIX workaround. |
| 13689 | */ |
| 13690 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; |
| 13691 | |
| 13692 | writel(0x00000000, sram_base); |
| 13693 | writel(0x00000000, sram_base + 4); |
| 13694 | writel(0xffffffff, sram_base + 4); |
| 13695 | if (readl(sram_base) != 0x00000000) |
| 13696 | tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG; |
| 13697 | } |
| 13698 | } |
| 13699 | |
| 13700 | udelay(50); |
| 13701 | tg3_nvram_init(tp); |
| 13702 | |
| 13703 | grc_misc_cfg = tr32(GRC_MISC_CFG); |
| 13704 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; |
| 13705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13706 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 13707 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
| 13708 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) |
| 13709 | tp->tg3_flags2 |= TG3_FLG2_IS_5788; |
| 13710 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 13711 | if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) && |
| 13712 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)) |
| 13713 | tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS; |
| 13714 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) { |
| 13715 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
| 13716 | HOSTCC_MODE_CLRTICK_TXBD); |
| 13717 | |
| 13718 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; |
| 13719 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 13720 | tp->misc_host_ctrl); |
| 13721 | } |
| 13722 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 13723 | /* Preserve the APE MAC_MODE bits */ |
| 13724 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 13725 | tp->mac_mode = tr32(MAC_MODE) | |
| 13726 | MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
| 13727 | else |
| 13728 | tp->mac_mode = TG3_DEF_MAC_MODE; |
| 13729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13730 | /* these are limited to 10/100 only */ |
| 13731 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 13732 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || |
| 13733 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 13734 | tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 13735 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 || |
| 13736 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 || |
| 13737 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) || |
| 13738 | (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 13739 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F || |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 13740 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F || |
| 13741 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13742 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790 || |
Matt Carlson | d110114 | 2010-02-17 15:16:55 +0000 | [diff] [blame] | 13743 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 13744 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13745 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
| 13746 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13747 | |
| 13748 | err = tg3_phy_probe(tp); |
| 13749 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 13750 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13751 | /* ... but do not return immediately ... */ |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13752 | tg3_mdio_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13753 | } |
| 13754 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13755 | tg3_read_vpd(tp); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13756 | tg3_read_fw_ver(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13757 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13758 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 13759 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13760 | } else { |
| 13761 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13762 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13763 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13764 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13765 | } |
| 13766 | |
| 13767 | /* 5700 {AX,BX} chips have a broken status block link |
| 13768 | * change bit implementation, so we must use the |
| 13769 | * status register in those cases. |
| 13770 | */ |
| 13771 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
| 13772 | tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG; |
| 13773 | else |
| 13774 | tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG; |
| 13775 | |
| 13776 | /* The led_ctrl is set during tg3_phy_probe, here we might |
| 13777 | * have to force the link status polling mechanism based |
| 13778 | * upon subsystem IDs. |
| 13779 | */ |
| 13780 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
Michael Chan | 007a880d | 2007-05-31 14:49:51 -0700 | [diff] [blame] | 13781 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13782 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 13783 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
| 13784 | tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13785 | } |
| 13786 | |
| 13787 | /* For all SERDES we poll the MAC status register. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13788 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13789 | tp->tg3_flags |= TG3_FLAG_POLL_SERDES; |
| 13790 | else |
| 13791 | tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES; |
| 13792 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 13793 | tp->rx_offset = NET_IP_ALIGN + TG3_RX_HEADROOM; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 13794 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13795 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 13796 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) { |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 13797 | tp->rx_offset -= NET_IP_ALIGN; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 13798 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 13799 | tp->rx_copy_thresh = ~(u16)0; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 13800 | #endif |
| 13801 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13802 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 13803 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
| 13804 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13805 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
| 13806 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 13807 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 13808 | |
| 13809 | /* Increment the rx prod index on the rx std ring by at most |
| 13810 | * 8 for these chips to workaround hw errata. |
| 13811 | */ |
| 13812 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 13813 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 13814 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 13815 | tp->rx_std_max_post = 8; |
| 13816 | |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13817 | if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) |
| 13818 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
| 13819 | PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 13820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13821 | return err; |
| 13822 | } |
| 13823 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13824 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13825 | static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp) |
| 13826 | { |
| 13827 | struct net_device *dev = tp->dev; |
| 13828 | struct pci_dev *pdev = tp->pdev; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13829 | struct device_node *dp = pci_device_to_OF_node(pdev); |
David S. Miller | 374d4ca | 2007-03-29 01:57:57 -0700 | [diff] [blame] | 13830 | const unsigned char *addr; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13831 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13832 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13833 | addr = of_get_property(dp, "local-mac-address", &len); |
| 13834 | if (addr && len == 6) { |
| 13835 | memcpy(dev->dev_addr, addr, 6); |
| 13836 | memcpy(dev->perm_addr, dev->dev_addr, 6); |
| 13837 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13838 | } |
| 13839 | return -ENODEV; |
| 13840 | } |
| 13841 | |
| 13842 | static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp) |
| 13843 | { |
| 13844 | struct net_device *dev = tp->dev; |
| 13845 | |
| 13846 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 13847 | memcpy(dev->perm_addr, idprom->id_ethaddr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13848 | return 0; |
| 13849 | } |
| 13850 | #endif |
| 13851 | |
| 13852 | static int __devinit tg3_get_device_address(struct tg3 *tp) |
| 13853 | { |
| 13854 | struct net_device *dev = tp->dev; |
| 13855 | u32 hi, lo, mac_offset; |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 13856 | int addr_ok = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13857 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13858 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13859 | if (!tg3_get_macaddr_sparc(tp)) |
| 13860 | return 0; |
| 13861 | #endif |
| 13862 | |
| 13863 | mac_offset = 0x7c; |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 13864 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) || |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13865 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13866 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 13867 | mac_offset = 0xcc; |
| 13868 | if (tg3_nvram_lock(tp)) |
| 13869 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); |
| 13870 | else |
| 13871 | tg3_nvram_unlock(tp); |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13872 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13873 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
| 13874 | if (PCI_FUNC(tp->pdev->devfn) & 1) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13875 | mac_offset = 0xcc; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13876 | if (PCI_FUNC(tp->pdev->devfn) > 1) |
| 13877 | mac_offset += 0x18c; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13878 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13879 | mac_offset = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13880 | |
| 13881 | /* First try to get it from MAC address mailbox. */ |
| 13882 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); |
| 13883 | if ((hi >> 16) == 0x484b) { |
| 13884 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 13885 | dev->dev_addr[1] = (hi >> 0) & 0xff; |
| 13886 | |
| 13887 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); |
| 13888 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 13889 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 13890 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 13891 | dev->dev_addr[5] = (lo >> 0) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13892 | |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 13893 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
| 13894 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); |
| 13895 | } |
| 13896 | if (!addr_ok) { |
| 13897 | /* Next, try NVRAM. */ |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 13898 | if (!(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) && |
| 13899 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 13900 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 13901 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
| 13902 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 13903 | } |
| 13904 | /* Finally just fetch it out of the MAC control regs. */ |
| 13905 | else { |
| 13906 | hi = tr32(MAC_ADDR_0_HIGH); |
| 13907 | lo = tr32(MAC_ADDR_0_LOW); |
| 13908 | |
| 13909 | dev->dev_addr[5] = lo & 0xff; |
| 13910 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 13911 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 13912 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 13913 | dev->dev_addr[1] = hi & 0xff; |
| 13914 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 13915 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13916 | } |
| 13917 | |
| 13918 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { |
David S. Miller | 7582a33 | 2008-03-20 15:53:15 -0700 | [diff] [blame] | 13919 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13920 | if (!tg3_get_default_macaddr_sparc(tp)) |
| 13921 | return 0; |
| 13922 | #endif |
| 13923 | return -EINVAL; |
| 13924 | } |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 13925 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13926 | return 0; |
| 13927 | } |
| 13928 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 13929 | #define BOUNDARY_SINGLE_CACHELINE 1 |
| 13930 | #define BOUNDARY_MULTI_CACHELINE 2 |
| 13931 | |
| 13932 | static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
| 13933 | { |
| 13934 | int cacheline_size; |
| 13935 | u8 byte; |
| 13936 | int goal; |
| 13937 | |
| 13938 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); |
| 13939 | if (byte == 0) |
| 13940 | cacheline_size = 1024; |
| 13941 | else |
| 13942 | cacheline_size = (int) byte * 4; |
| 13943 | |
| 13944 | /* On 5703 and later chips, the boundary bits have no |
| 13945 | * effect. |
| 13946 | */ |
| 13947 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13948 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 13949 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) |
| 13950 | goto out; |
| 13951 | |
| 13952 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) |
| 13953 | goal = BOUNDARY_MULTI_CACHELINE; |
| 13954 | #else |
| 13955 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) |
| 13956 | goal = BOUNDARY_SINGLE_CACHELINE; |
| 13957 | #else |
| 13958 | goal = 0; |
| 13959 | #endif |
| 13960 | #endif |
| 13961 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13962 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 13963 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 13964 | goto out; |
| 13965 | } |
| 13966 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 13967 | if (!goal) |
| 13968 | goto out; |
| 13969 | |
| 13970 | /* PCI controllers on most RISC systems tend to disconnect |
| 13971 | * when a device tries to burst across a cache-line boundary. |
| 13972 | * Therefore, letting tg3 do so just wastes PCI bandwidth. |
| 13973 | * |
| 13974 | * Unfortunately, for PCI-E there are only limited |
| 13975 | * write-side controls for this, and thus for reads |
| 13976 | * we will still get the disconnects. We'll also waste |
| 13977 | * these PCI cycles for both read and write for chips |
| 13978 | * other than 5700 and 5701 which do not implement the |
| 13979 | * boundary bits. |
| 13980 | */ |
| 13981 | if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) && |
| 13982 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) { |
| 13983 | switch (cacheline_size) { |
| 13984 | case 16: |
| 13985 | case 32: |
| 13986 | case 64: |
| 13987 | case 128: |
| 13988 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 13989 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | |
| 13990 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); |
| 13991 | } else { |
| 13992 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 13993 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 13994 | } |
| 13995 | break; |
| 13996 | |
| 13997 | case 256: |
| 13998 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | |
| 13999 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); |
| 14000 | break; |
| 14001 | |
| 14002 | default: |
| 14003 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 14004 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 14005 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14006 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14007 | } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 14008 | switch (cacheline_size) { |
| 14009 | case 16: |
| 14010 | case 32: |
| 14011 | case 64: |
| 14012 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14013 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 14014 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; |
| 14015 | break; |
| 14016 | } |
| 14017 | /* fallthrough */ |
| 14018 | case 128: |
| 14019 | default: |
| 14020 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 14021 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; |
| 14022 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14023 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14024 | } else { |
| 14025 | switch (cacheline_size) { |
| 14026 | case 16: |
| 14027 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14028 | val |= (DMA_RWCTRL_READ_BNDRY_16 | |
| 14029 | DMA_RWCTRL_WRITE_BNDRY_16); |
| 14030 | break; |
| 14031 | } |
| 14032 | /* fallthrough */ |
| 14033 | case 32: |
| 14034 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14035 | val |= (DMA_RWCTRL_READ_BNDRY_32 | |
| 14036 | DMA_RWCTRL_WRITE_BNDRY_32); |
| 14037 | break; |
| 14038 | } |
| 14039 | /* fallthrough */ |
| 14040 | case 64: |
| 14041 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14042 | val |= (DMA_RWCTRL_READ_BNDRY_64 | |
| 14043 | DMA_RWCTRL_WRITE_BNDRY_64); |
| 14044 | break; |
| 14045 | } |
| 14046 | /* fallthrough */ |
| 14047 | case 128: |
| 14048 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14049 | val |= (DMA_RWCTRL_READ_BNDRY_128 | |
| 14050 | DMA_RWCTRL_WRITE_BNDRY_128); |
| 14051 | break; |
| 14052 | } |
| 14053 | /* fallthrough */ |
| 14054 | case 256: |
| 14055 | val |= (DMA_RWCTRL_READ_BNDRY_256 | |
| 14056 | DMA_RWCTRL_WRITE_BNDRY_256); |
| 14057 | break; |
| 14058 | case 512: |
| 14059 | val |= (DMA_RWCTRL_READ_BNDRY_512 | |
| 14060 | DMA_RWCTRL_WRITE_BNDRY_512); |
| 14061 | break; |
| 14062 | case 1024: |
| 14063 | default: |
| 14064 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | |
| 14065 | DMA_RWCTRL_WRITE_BNDRY_1024); |
| 14066 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14067 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14068 | } |
| 14069 | |
| 14070 | out: |
| 14071 | return val; |
| 14072 | } |
| 14073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14074 | static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) |
| 14075 | { |
| 14076 | struct tg3_internal_buffer_desc test_desc; |
| 14077 | u32 sram_dma_descs; |
| 14078 | int i, ret; |
| 14079 | |
| 14080 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; |
| 14081 | |
| 14082 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); |
| 14083 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); |
| 14084 | tw32(RDMAC_STATUS, 0); |
| 14085 | tw32(WDMAC_STATUS, 0); |
| 14086 | |
| 14087 | tw32(BUFMGR_MODE, 0); |
| 14088 | tw32(FTQ_RESET, 0); |
| 14089 | |
| 14090 | test_desc.addr_hi = ((u64) buf_dma) >> 32; |
| 14091 | test_desc.addr_lo = buf_dma & 0xffffffff; |
| 14092 | test_desc.nic_mbuf = 0x00002100; |
| 14093 | test_desc.len = size; |
| 14094 | |
| 14095 | /* |
| 14096 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz |
| 14097 | * the *second* time the tg3 driver was getting loaded after an |
| 14098 | * initial scan. |
| 14099 | * |
| 14100 | * Broadcom tells me: |
| 14101 | * ...the DMA engine is connected to the GRC block and a DMA |
| 14102 | * reset may affect the GRC block in some unpredictable way... |
| 14103 | * The behavior of resets to individual blocks has not been tested. |
| 14104 | * |
| 14105 | * Broadcom noted the GRC reset will also reset all sub-components. |
| 14106 | */ |
| 14107 | if (to_device) { |
| 14108 | test_desc.cqid_sqid = (13 << 8) | 2; |
| 14109 | |
| 14110 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); |
| 14111 | udelay(40); |
| 14112 | } else { |
| 14113 | test_desc.cqid_sqid = (16 << 8) | 7; |
| 14114 | |
| 14115 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); |
| 14116 | udelay(40); |
| 14117 | } |
| 14118 | test_desc.flags = 0x00000005; |
| 14119 | |
| 14120 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { |
| 14121 | u32 val; |
| 14122 | |
| 14123 | val = *(((u32 *)&test_desc) + i); |
| 14124 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, |
| 14125 | sram_dma_descs + (i * sizeof(u32))); |
| 14126 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 14127 | } |
| 14128 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 14129 | |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14130 | if (to_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14131 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14132 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14133 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14134 | |
| 14135 | ret = -ENODEV; |
| 14136 | for (i = 0; i < 40; i++) { |
| 14137 | u32 val; |
| 14138 | |
| 14139 | if (to_device) |
| 14140 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); |
| 14141 | else |
| 14142 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); |
| 14143 | if ((val & 0xffff) == sram_dma_descs) { |
| 14144 | ret = 0; |
| 14145 | break; |
| 14146 | } |
| 14147 | |
| 14148 | udelay(100); |
| 14149 | } |
| 14150 | |
| 14151 | return ret; |
| 14152 | } |
| 14153 | |
David S. Miller | ded7340 | 2005-05-23 13:59:47 -0700 | [diff] [blame] | 14154 | #define TEST_BUFFER_SIZE 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14155 | |
| 14156 | static int __devinit tg3_test_dma(struct tg3 *tp) |
| 14157 | { |
| 14158 | dma_addr_t buf_dma; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14159 | u32 *buf, saved_dma_rwctrl; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14160 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14161 | |
| 14162 | buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma); |
| 14163 | if (!buf) { |
| 14164 | ret = -ENOMEM; |
| 14165 | goto out_nofree; |
| 14166 | } |
| 14167 | |
| 14168 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | |
| 14169 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); |
| 14170 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14171 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14172 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 14173 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14174 | goto out; |
| 14175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14176 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 14177 | /* DMA read watermark not used on PCIE */ |
| 14178 | tp->dma_rwctrl |= 0x00180000; |
| 14179 | } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) { |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 14180 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 14181 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14182 | tp->dma_rwctrl |= 0x003f0000; |
| 14183 | else |
| 14184 | tp->dma_rwctrl |= 0x003f000f; |
| 14185 | } else { |
| 14186 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 14187 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 14188 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14189 | u32 read_water = 0x7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14190 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14191 | /* If the 5704 is behind the EPB bridge, we can |
| 14192 | * do the less restrictive ONE_DMA workaround for |
| 14193 | * better performance. |
| 14194 | */ |
| 14195 | if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) && |
| 14196 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 14197 | tp->dma_rwctrl |= 0x8000; |
| 14198 | else if (ccval == 0x6 || ccval == 0x7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14199 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 14200 | |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14201 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
| 14202 | read_water = 4; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14203 | /* Set bit 23 to enable PCIX hw bug fix */ |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14204 | tp->dma_rwctrl |= |
| 14205 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | |
| 14206 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | |
| 14207 | (1 << 23); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 14208 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
| 14209 | /* 5780 always in PCIX mode */ |
| 14210 | tp->dma_rwctrl |= 0x00144000; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 14211 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 14212 | /* 5714 always in PCIX mode */ |
| 14213 | tp->dma_rwctrl |= 0x00148000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14214 | } else { |
| 14215 | tp->dma_rwctrl |= 0x001b000f; |
| 14216 | } |
| 14217 | } |
| 14218 | |
| 14219 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 14220 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 14221 | tp->dma_rwctrl &= 0xfffffff0; |
| 14222 | |
| 14223 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 14224 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 14225 | /* Remove this if it causes problems for some boards. */ |
| 14226 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; |
| 14227 | |
| 14228 | /* On 5700/5701 chips, we need to set this bit. |
| 14229 | * Otherwise the chip will issue cacheline transactions |
| 14230 | * to streamable DMA memory with not all the byte |
| 14231 | * enables turned on. This is an error on several |
| 14232 | * RISC PCI controllers, in particular sparc64. |
| 14233 | * |
| 14234 | * On 5703/5704 chips, this bit has been reassigned |
| 14235 | * a different meaning. In particular, it is used |
| 14236 | * on those chips to enable a PCI-X workaround. |
| 14237 | */ |
| 14238 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; |
| 14239 | } |
| 14240 | |
| 14241 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14242 | |
| 14243 | #if 0 |
| 14244 | /* Unneeded, already done by tg3_get_invariants. */ |
| 14245 | tg3_switch_clocks(tp); |
| 14246 | #endif |
| 14247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14248 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14249 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 14250 | goto out; |
| 14251 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14252 | /* It is best to perform DMA test with maximum write burst size |
| 14253 | * to expose the 5700/5701 write DMA bug. |
| 14254 | */ |
| 14255 | saved_dma_rwctrl = tp->dma_rwctrl; |
| 14256 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 14257 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14259 | while (1) { |
| 14260 | u32 *p = buf, i; |
| 14261 | |
| 14262 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) |
| 14263 | p[i] = i; |
| 14264 | |
| 14265 | /* Send the buffer to the chip. */ |
| 14266 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); |
| 14267 | if (ret) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14268 | dev_err(&tp->pdev->dev, |
| 14269 | "%s: Buffer write failed. err = %d\n", |
| 14270 | __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14271 | break; |
| 14272 | } |
| 14273 | |
| 14274 | #if 0 |
| 14275 | /* validate data reached card RAM correctly. */ |
| 14276 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 14277 | u32 val; |
| 14278 | tg3_read_mem(tp, 0x2100 + (i*4), &val); |
| 14279 | if (le32_to_cpu(val) != p[i]) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14280 | dev_err(&tp->pdev->dev, |
| 14281 | "%s: Buffer corrupted on device! " |
| 14282 | "(%d != %d)\n", __func__, val, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14283 | /* ret = -ENODEV here? */ |
| 14284 | } |
| 14285 | p[i] = 0; |
| 14286 | } |
| 14287 | #endif |
| 14288 | /* Now read it back. */ |
| 14289 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); |
| 14290 | if (ret) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 14291 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
| 14292 | "err = %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14293 | break; |
| 14294 | } |
| 14295 | |
| 14296 | /* Verify it. */ |
| 14297 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 14298 | if (p[i] == i) |
| 14299 | continue; |
| 14300 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14301 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 14302 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 14303 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14304 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 14305 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14306 | break; |
| 14307 | } else { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14308 | dev_err(&tp->pdev->dev, |
| 14309 | "%s: Buffer corrupted on read back! " |
| 14310 | "(%d != %d)\n", __func__, p[i], i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14311 | ret = -ENODEV; |
| 14312 | goto out; |
| 14313 | } |
| 14314 | } |
| 14315 | |
| 14316 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { |
| 14317 | /* Success. */ |
| 14318 | ret = 0; |
| 14319 | break; |
| 14320 | } |
| 14321 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14322 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 14323 | DMA_RWCTRL_WRITE_BNDRY_16) { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14324 | static struct pci_device_id dma_wait_state_chipsets[] = { |
| 14325 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, |
| 14326 | PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
| 14327 | { }, |
| 14328 | }; |
| 14329 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14330 | /* DMA test passed without adjusting DMA boundary, |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14331 | * now look for chipsets that are known to expose the |
| 14332 | * DMA bug without failing the test. |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14333 | */ |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14334 | if (pci_dev_present(dma_wait_state_chipsets)) { |
| 14335 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 14336 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14337 | } else { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14338 | /* Safe to use the calculated DMA boundary. */ |
| 14339 | tp->dma_rwctrl = saved_dma_rwctrl; |
Matt Carlson | 859a588 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14340 | } |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14341 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14342 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14344 | |
| 14345 | out: |
| 14346 | pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma); |
| 14347 | out_nofree: |
| 14348 | return ret; |
| 14349 | } |
| 14350 | |
| 14351 | static void __devinit tg3_init_link_config(struct tg3 *tp) |
| 14352 | { |
| 14353 | tp->link_config.advertising = |
| 14354 | (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 14355 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 14356 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full | |
| 14357 | ADVERTISED_Autoneg | ADVERTISED_MII); |
| 14358 | tp->link_config.speed = SPEED_INVALID; |
| 14359 | tp->link_config.duplex = DUPLEX_INVALID; |
| 14360 | tp->link_config.autoneg = AUTONEG_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14361 | tp->link_config.active_speed = SPEED_INVALID; |
| 14362 | tp->link_config.active_duplex = DUPLEX_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14363 | tp->link_config.orig_speed = SPEED_INVALID; |
| 14364 | tp->link_config.orig_duplex = DUPLEX_INVALID; |
| 14365 | tp->link_config.orig_autoneg = AUTONEG_INVALID; |
| 14366 | } |
| 14367 | |
| 14368 | static void __devinit tg3_init_bufmgr_config(struct tg3 *tp) |
| 14369 | { |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 14370 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 14371 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14372 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14373 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14374 | DEFAULT_MB_MACRX_LOW_WATER_57765; |
| 14375 | tp->bufmgr_config.mbuf_high_water = |
| 14376 | DEFAULT_MB_HIGH_WATER_57765; |
| 14377 | |
| 14378 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14379 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14380 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14381 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; |
| 14382 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14383 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; |
| 14384 | } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
Michael Chan | fdfec17 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14385 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14386 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14387 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14388 | DEFAULT_MB_MACRX_LOW_WATER_5705; |
| 14389 | tp->bufmgr_config.mbuf_high_water = |
| 14390 | DEFAULT_MB_HIGH_WATER_5705; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14391 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 14392 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14393 | DEFAULT_MB_MACRX_LOW_WATER_5906; |
| 14394 | tp->bufmgr_config.mbuf_high_water = |
| 14395 | DEFAULT_MB_HIGH_WATER_5906; |
| 14396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14397 | |
Michael Chan | fdfec17 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14398 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14399 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; |
| 14400 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14401 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; |
| 14402 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14403 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; |
| 14404 | } else { |
| 14405 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14406 | DEFAULT_MB_RDMA_LOW_WATER; |
| 14407 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14408 | DEFAULT_MB_MACRX_LOW_WATER; |
| 14409 | tp->bufmgr_config.mbuf_high_water = |
| 14410 | DEFAULT_MB_HIGH_WATER; |
| 14411 | |
| 14412 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14413 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; |
| 14414 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14415 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; |
| 14416 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14417 | DEFAULT_MB_HIGH_WATER_JUMBO; |
| 14418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14419 | |
| 14420 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; |
| 14421 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; |
| 14422 | } |
| 14423 | |
| 14424 | static char * __devinit tg3_phy_string(struct tg3 *tp) |
| 14425 | { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14426 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
| 14427 | case TG3_PHY_ID_BCM5400: return "5400"; |
| 14428 | case TG3_PHY_ID_BCM5401: return "5401"; |
| 14429 | case TG3_PHY_ID_BCM5411: return "5411"; |
| 14430 | case TG3_PHY_ID_BCM5701: return "5701"; |
| 14431 | case TG3_PHY_ID_BCM5703: return "5703"; |
| 14432 | case TG3_PHY_ID_BCM5704: return "5704"; |
| 14433 | case TG3_PHY_ID_BCM5705: return "5705"; |
| 14434 | case TG3_PHY_ID_BCM5750: return "5750"; |
| 14435 | case TG3_PHY_ID_BCM5752: return "5752"; |
| 14436 | case TG3_PHY_ID_BCM5714: return "5714"; |
| 14437 | case TG3_PHY_ID_BCM5780: return "5780"; |
| 14438 | case TG3_PHY_ID_BCM5755: return "5755"; |
| 14439 | case TG3_PHY_ID_BCM5787: return "5787"; |
| 14440 | case TG3_PHY_ID_BCM5784: return "5784"; |
| 14441 | case TG3_PHY_ID_BCM5756: return "5722/5756"; |
| 14442 | case TG3_PHY_ID_BCM5906: return "5906"; |
| 14443 | case TG3_PHY_ID_BCM5761: return "5761"; |
| 14444 | case TG3_PHY_ID_BCM5718C: return "5718C"; |
| 14445 | case TG3_PHY_ID_BCM5718S: return "5718S"; |
| 14446 | case TG3_PHY_ID_BCM57765: return "57765"; |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 14447 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14448 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14449 | case 0: return "serdes"; |
| 14450 | default: return "unknown"; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14452 | } |
| 14453 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14454 | static char * __devinit tg3_bus_string(struct tg3 *tp, char *str) |
| 14455 | { |
| 14456 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 14457 | strcpy(str, "PCI Express"); |
| 14458 | return str; |
| 14459 | } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
| 14460 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
| 14461 | |
| 14462 | strcpy(str, "PCIX:"); |
| 14463 | |
| 14464 | if ((clock_ctrl == 7) || |
| 14465 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == |
| 14466 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) |
| 14467 | strcat(str, "133MHz"); |
| 14468 | else if (clock_ctrl == 0) |
| 14469 | strcat(str, "33MHz"); |
| 14470 | else if (clock_ctrl == 2) |
| 14471 | strcat(str, "50MHz"); |
| 14472 | else if (clock_ctrl == 4) |
| 14473 | strcat(str, "66MHz"); |
| 14474 | else if (clock_ctrl == 6) |
| 14475 | strcat(str, "100MHz"); |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14476 | } else { |
| 14477 | strcpy(str, "PCI:"); |
| 14478 | if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED) |
| 14479 | strcat(str, "66MHz"); |
| 14480 | else |
| 14481 | strcat(str, "33MHz"); |
| 14482 | } |
| 14483 | if (tp->tg3_flags & TG3_FLAG_PCI_32BIT) |
| 14484 | strcat(str, ":32-bit"); |
| 14485 | else |
| 14486 | strcat(str, ":64-bit"); |
| 14487 | return str; |
| 14488 | } |
| 14489 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 14490 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14491 | { |
| 14492 | struct pci_dev *peer; |
| 14493 | unsigned int func, devnr = tp->pdev->devfn & ~7; |
| 14494 | |
| 14495 | for (func = 0; func < 8; func++) { |
| 14496 | peer = pci_get_slot(tp->pdev->bus, devnr | func); |
| 14497 | if (peer && peer != tp->pdev) |
| 14498 | break; |
| 14499 | pci_dev_put(peer); |
| 14500 | } |
Michael Chan | 16fe9d7 | 2005-12-13 21:09:54 -0800 | [diff] [blame] | 14501 | /* 5704 can be configured in single-port mode, set peer to |
| 14502 | * tp->pdev in that case. |
| 14503 | */ |
| 14504 | if (!peer) { |
| 14505 | peer = tp->pdev; |
| 14506 | return peer; |
| 14507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14508 | |
| 14509 | /* |
| 14510 | * We don't need to keep the refcount elevated; there's no way |
| 14511 | * to remove one half of this device without removing the other |
| 14512 | */ |
| 14513 | pci_dev_put(peer); |
| 14514 | |
| 14515 | return peer; |
| 14516 | } |
| 14517 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 14518 | static void __devinit tg3_init_coal(struct tg3 *tp) |
| 14519 | { |
| 14520 | struct ethtool_coalesce *ec = &tp->coal; |
| 14521 | |
| 14522 | memset(ec, 0, sizeof(*ec)); |
| 14523 | ec->cmd = ETHTOOL_GCOALESCE; |
| 14524 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; |
| 14525 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; |
| 14526 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; |
| 14527 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; |
| 14528 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; |
| 14529 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; |
| 14530 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; |
| 14531 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; |
| 14532 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; |
| 14533 | |
| 14534 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | |
| 14535 | HOSTCC_MODE_CLRTICK_TXBD)) { |
| 14536 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; |
| 14537 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; |
| 14538 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; |
| 14539 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; |
| 14540 | } |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 14541 | |
| 14542 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 14543 | ec->rx_coalesce_usecs_irq = 0; |
| 14544 | ec->tx_coalesce_usecs_irq = 0; |
| 14545 | ec->stats_block_coalesce_usecs = 0; |
| 14546 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 14547 | } |
| 14548 | |
Stephen Hemminger | 7c7d64b | 2008-11-19 22:25:36 -0800 | [diff] [blame] | 14549 | static const struct net_device_ops tg3_netdev_ops = { |
| 14550 | .ndo_open = tg3_open, |
| 14551 | .ndo_stop = tg3_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14552 | .ndo_start_xmit = tg3_start_xmit, |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 14553 | .ndo_get_stats64 = tg3_get_stats64, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14554 | .ndo_validate_addr = eth_validate_addr, |
| 14555 | .ndo_set_multicast_list = tg3_set_rx_mode, |
| 14556 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 14557 | .ndo_do_ioctl = tg3_ioctl, |
| 14558 | .ndo_tx_timeout = tg3_tx_timeout, |
| 14559 | .ndo_change_mtu = tg3_change_mtu, |
| 14560 | #if TG3_VLAN_TAG_USED |
| 14561 | .ndo_vlan_rx_register = tg3_vlan_rx_register, |
| 14562 | #endif |
| 14563 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 14564 | .ndo_poll_controller = tg3_poll_controller, |
| 14565 | #endif |
| 14566 | }; |
| 14567 | |
| 14568 | static const struct net_device_ops tg3_netdev_ops_dma_bug = { |
| 14569 | .ndo_open = tg3_open, |
| 14570 | .ndo_stop = tg3_close, |
| 14571 | .ndo_start_xmit = tg3_start_xmit_dma_bug, |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 14572 | .ndo_get_stats64 = tg3_get_stats64, |
Stephen Hemminger | 7c7d64b | 2008-11-19 22:25:36 -0800 | [diff] [blame] | 14573 | .ndo_validate_addr = eth_validate_addr, |
| 14574 | .ndo_set_multicast_list = tg3_set_rx_mode, |
| 14575 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 14576 | .ndo_do_ioctl = tg3_ioctl, |
| 14577 | .ndo_tx_timeout = tg3_tx_timeout, |
| 14578 | .ndo_change_mtu = tg3_change_mtu, |
| 14579 | #if TG3_VLAN_TAG_USED |
| 14580 | .ndo_vlan_rx_register = tg3_vlan_rx_register, |
| 14581 | #endif |
| 14582 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 14583 | .ndo_poll_controller = tg3_poll_controller, |
| 14584 | #endif |
| 14585 | }; |
| 14586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14587 | static int __devinit tg3_init_one(struct pci_dev *pdev, |
| 14588 | const struct pci_device_id *ent) |
| 14589 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14590 | struct net_device *dev; |
| 14591 | struct tg3 *tp; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 14592 | int i, err, pm_cap; |
| 14593 | u32 sndmbx, rcvmbx, intmbx; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14594 | char str[40]; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14595 | u64 dma_mask, persist_dma_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14596 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14597 | printk_once(KERN_INFO "%s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14598 | |
| 14599 | err = pci_enable_device(pdev); |
| 14600 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14601 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14602 | return err; |
| 14603 | } |
| 14604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14605 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 14606 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14607 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14608 | goto err_out_disable_pdev; |
| 14609 | } |
| 14610 | |
| 14611 | pci_set_master(pdev); |
| 14612 | |
| 14613 | /* Find power-management capability. */ |
| 14614 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 14615 | if (pm_cap == 0) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14616 | dev_err(&pdev->dev, |
| 14617 | "Cannot find Power Management capability, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14618 | err = -EIO; |
| 14619 | goto err_out_free_res; |
| 14620 | } |
| 14621 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 14622 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14623 | if (!dev) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14624 | dev_err(&pdev->dev, "Etherdev alloc failed, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14625 | err = -ENOMEM; |
| 14626 | goto err_out_free_res; |
| 14627 | } |
| 14628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14629 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 14630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14631 | #if TG3_VLAN_TAG_USED |
| 14632 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14633 | #endif |
| 14634 | |
| 14635 | tp = netdev_priv(dev); |
| 14636 | tp->pdev = pdev; |
| 14637 | tp->dev = dev; |
| 14638 | tp->pm_cap = pm_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14639 | tp->rx_mode = TG3_DEF_RX_MODE; |
| 14640 | tp->tx_mode = TG3_DEF_TX_MODE; |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 14641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14642 | if (tg3_debug > 0) |
| 14643 | tp->msg_enable = tg3_debug; |
| 14644 | else |
| 14645 | tp->msg_enable = TG3_DEF_MSG_ENABLE; |
| 14646 | |
| 14647 | /* The word/byte swap controls here control register access byte |
| 14648 | * swapping. DMA data byte swapping is controlled in the GRC_MODE |
| 14649 | * setting below. |
| 14650 | */ |
| 14651 | tp->misc_host_ctrl = |
| 14652 | MISC_HOST_CTRL_MASK_PCI_INT | |
| 14653 | MISC_HOST_CTRL_WORD_SWAP | |
| 14654 | MISC_HOST_CTRL_INDIR_ACCESS | |
| 14655 | MISC_HOST_CTRL_PCISTATE_RW; |
| 14656 | |
| 14657 | /* The NONFRM (non-frame) byte/word swap controls take effect |
| 14658 | * on descriptor entries, anything which isn't packet data. |
| 14659 | * |
| 14660 | * The StrongARM chips on the board (one for tx, one for rx) |
| 14661 | * are running in big-endian mode. |
| 14662 | */ |
| 14663 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | |
| 14664 | GRC_MODE_WSWAP_NONFRM_DATA); |
| 14665 | #ifdef __BIG_ENDIAN |
| 14666 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; |
| 14667 | #endif |
| 14668 | spin_lock_init(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14669 | spin_lock_init(&tp->indirect_lock); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 14670 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14671 | |
Matt Carlson | d5fe488 | 2008-11-21 17:20:32 -0800 | [diff] [blame] | 14672 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 14673 | if (!tp->regs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14674 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14675 | err = -ENOMEM; |
| 14676 | goto err_out_free_dev; |
| 14677 | } |
| 14678 | |
| 14679 | tg3_init_link_config(tp); |
| 14680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14681 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
| 14682 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14684 | dev->ethtool_ops = &tg3_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14685 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14686 | dev->irq = pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14687 | |
| 14688 | err = tg3_get_invariants(tp); |
| 14689 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14690 | dev_err(&pdev->dev, |
| 14691 | "Problem fetching invariants of chip, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14692 | goto err_out_iounmap; |
| 14693 | } |
| 14694 | |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 14695 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) && |
Matt Carlson | 2e9f7a7 | 2010-09-15 08:59:56 +0000 | [diff] [blame] | 14696 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 14697 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5719) |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14698 | dev->netdev_ops = &tg3_netdev_ops; |
| 14699 | else |
| 14700 | dev->netdev_ops = &tg3_netdev_ops_dma_bug; |
| 14701 | |
| 14702 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14703 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
| 14704 | * device behind the EPB cannot support DMA addresses > 40-bit. |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14705 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
| 14706 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and |
| 14707 | * do DMA address check in tg3_start_xmit(). |
| 14708 | */ |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14709 | if (tp->tg3_flags2 & TG3_FLG2_IS_5788) |
Yang Hongyang | 284901a9 | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 14710 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14711 | else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) { |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 14712 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14713 | #ifdef CONFIG_HIGHMEM |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 14714 | dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14715 | #endif |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14716 | } else |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 14717 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14718 | |
| 14719 | /* Configure DMA attributes. */ |
Yang Hongyang | 284901a9 | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 14720 | if (dma_mask > DMA_BIT_MASK(32)) { |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14721 | err = pci_set_dma_mask(pdev, dma_mask); |
| 14722 | if (!err) { |
| 14723 | dev->features |= NETIF_F_HIGHDMA; |
| 14724 | err = pci_set_consistent_dma_mask(pdev, |
| 14725 | persist_dma_mask); |
| 14726 | if (err < 0) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14727 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
| 14728 | "DMA for consistent allocations\n"); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14729 | goto err_out_iounmap; |
| 14730 | } |
| 14731 | } |
| 14732 | } |
Yang Hongyang | 284901a9 | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 14733 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
| 14734 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14735 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14736 | dev_err(&pdev->dev, |
| 14737 | "No usable DMA configuration, aborting\n"); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14738 | goto err_out_iounmap; |
| 14739 | } |
| 14740 | } |
| 14741 | |
Michael Chan | fdfec17 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14742 | tg3_init_bufmgr_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14743 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14744 | /* Selectively allow TSO based on operating conditions */ |
| 14745 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) || |
| 14746 | (tp->fw_needed && !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) |
| 14747 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
| 14748 | else { |
| 14749 | tp->tg3_flags2 &= ~(TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG); |
| 14750 | tp->fw_needed = NULL; |
| 14751 | } |
| 14752 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 14753 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 14754 | tp->fw_needed = FIRMWARE_TG3; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 14755 | |
Michael Chan | 4e3a7aa | 2006-03-20 17:47:44 -0800 | [diff] [blame] | 14756 | /* TSO is on by default on chips that support hardware TSO. |
| 14757 | * Firmware TSO on older chips gives lower performance, so it |
| 14758 | * is off by default, but can be enabled using ethtool. |
| 14759 | */ |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14760 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) && |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14761 | (dev->features & NETIF_F_IP_CSUM)) { |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14762 | dev->features |= NETIF_F_TSO; |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14763 | vlan_features_add(dev, NETIF_F_TSO); |
| 14764 | } |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14765 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) || |
| 14766 | (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3)) { |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14767 | if (dev->features & NETIF_F_IPV6_CSUM) { |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 14768 | dev->features |= NETIF_F_TSO6; |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14769 | vlan_features_add(dev, NETIF_F_TSO6); |
| 14770 | } |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14771 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
| 14772 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 14773 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 14774 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14775 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14776 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 14777 | dev->features |= NETIF_F_TSO_ECN; |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14778 | vlan_features_add(dev, NETIF_F_TSO_ECN); |
| 14779 | } |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 14780 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14782 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
| 14783 | !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) && |
| 14784 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
| 14785 | tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64; |
| 14786 | tp->rx_pending = 63; |
| 14787 | } |
| 14788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14789 | err = tg3_get_device_address(tp); |
| 14790 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14791 | dev_err(&pdev->dev, |
| 14792 | "Could not obtain valid ethernet address, aborting\n"); |
Matt Carlson | 026a6c2 | 2009-12-03 08:36:24 +0000 | [diff] [blame] | 14793 | goto err_out_iounmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14794 | } |
| 14795 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14796 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 14797 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 14798 | if (!tp->aperegs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14799 | dev_err(&pdev->dev, |
| 14800 | "Cannot map APE registers, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14801 | err = -ENOMEM; |
Matt Carlson | 026a6c2 | 2009-12-03 08:36:24 +0000 | [diff] [blame] | 14802 | goto err_out_iounmap; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14803 | } |
| 14804 | |
| 14805 | tg3_ape_lock_init(tp); |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14806 | |
| 14807 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) |
| 14808 | tg3_read_dash_ver(tp); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14809 | } |
| 14810 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14811 | /* |
| 14812 | * Reset chip in case UNDI or EFI driver did not shutdown |
| 14813 | * DMA self test will enable WDMAC and we'll see (spurious) |
| 14814 | * pending DMA on the PCI bus at that point. |
| 14815 | */ |
| 14816 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
| 14817 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 14818 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
| 14819 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 14820 | } |
| 14821 | |
| 14822 | err = tg3_test_dma(tp); |
| 14823 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14824 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14825 | goto err_out_apeunmap; |
| 14826 | } |
| 14827 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14828 | /* flow control autonegotiation is default behavior */ |
| 14829 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 14830 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14831 | |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14832 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
| 14833 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; |
| 14834 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 14835 | for (i = 0; i < tp->irq_max; i++) { |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14836 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 14837 | |
| 14838 | tnapi->tp = tp; |
| 14839 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; |
| 14840 | |
| 14841 | tnapi->int_mbox = intmbx; |
| 14842 | if (i < 4) |
| 14843 | intmbx += 0x8; |
| 14844 | else |
| 14845 | intmbx += 0x4; |
| 14846 | |
| 14847 | tnapi->consmbox = rcvmbx; |
| 14848 | tnapi->prodmbox = sndmbx; |
| 14849 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 14850 | if (i) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14851 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 14852 | else |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14853 | tnapi->coal_now = HOSTCC_MODE_NOW; |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14854 | |
| 14855 | if (!(tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX)) |
| 14856 | break; |
| 14857 | |
| 14858 | /* |
| 14859 | * If we support MSIX, we'll be using RSS. If we're using |
| 14860 | * RSS, the first vector only handles link interrupts and the |
| 14861 | * remaining vectors handle rx and tx interrupts. Reuse the |
| 14862 | * mailbox values for the next iteration. The values we setup |
| 14863 | * above are still useful for the single vectored mode. |
| 14864 | */ |
| 14865 | if (!i) |
| 14866 | continue; |
| 14867 | |
| 14868 | rcvmbx += 0x8; |
| 14869 | |
| 14870 | if (sndmbx & 0x4) |
| 14871 | sndmbx -= 0x4; |
| 14872 | else |
| 14873 | sndmbx += 0xc; |
| 14874 | } |
| 14875 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14876 | tg3_init_coal(tp); |
| 14877 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 14878 | pci_set_drvdata(pdev, dev); |
| 14879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14880 | err = register_netdev(dev); |
| 14881 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14882 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14883 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14884 | } |
| 14885 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14886 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
| 14887 | tp->board_part_number, |
| 14888 | tp->pci_chip_rev_id, |
| 14889 | tg3_bus_string(tp, str), |
| 14890 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14891 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14892 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 14893 | struct phy_device *phydev; |
| 14894 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 14895 | netdev_info(dev, |
| 14896 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14897 | phydev->drv->name, dev_name(&phydev->dev)); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14898 | } else { |
| 14899 | char *ethtype; |
| 14900 | |
| 14901 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 14902 | ethtype = "10/100Base-TX"; |
| 14903 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 14904 | ethtype = "1000Base-SX"; |
| 14905 | else |
| 14906 | ethtype = "10/100/1000Base-T"; |
| 14907 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 14908 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14909 | "(WireSpeed[%d])\n", tg3_phy_string(tp), ethtype, |
| 14910 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0); |
| 14911 | } |
Matt Carlson | df59c94 | 2008-11-03 16:52:56 -0800 | [diff] [blame] | 14912 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14913 | netdev_info(dev, "RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n", |
| 14914 | (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0, |
| 14915 | (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0, |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14916 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14917 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0, |
| 14918 | (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0); |
| 14919 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
| 14920 | tp->dma_rwctrl, |
| 14921 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : |
| 14922 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14923 | |
| 14924 | return 0; |
| 14925 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14926 | err_out_apeunmap: |
| 14927 | if (tp->aperegs) { |
| 14928 | iounmap(tp->aperegs); |
| 14929 | tp->aperegs = NULL; |
| 14930 | } |
| 14931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14932 | err_out_iounmap: |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14933 | if (tp->regs) { |
| 14934 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 14935 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14936 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14937 | |
| 14938 | err_out_free_dev: |
| 14939 | free_netdev(dev); |
| 14940 | |
| 14941 | err_out_free_res: |
| 14942 | pci_release_regions(pdev); |
| 14943 | |
| 14944 | err_out_disable_pdev: |
| 14945 | pci_disable_device(pdev); |
| 14946 | pci_set_drvdata(pdev, NULL); |
| 14947 | return err; |
| 14948 | } |
| 14949 | |
| 14950 | static void __devexit tg3_remove_one(struct pci_dev *pdev) |
| 14951 | { |
| 14952 | struct net_device *dev = pci_get_drvdata(pdev); |
| 14953 | |
| 14954 | if (dev) { |
| 14955 | struct tg3 *tp = netdev_priv(dev); |
| 14956 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 14957 | if (tp->fw) |
| 14958 | release_firmware(tp->fw); |
| 14959 | |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 14960 | flush_scheduled_work(); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 14961 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14962 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
| 14963 | tg3_phy_fini(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 14964 | tg3_mdio_fini(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14965 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 14966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14967 | unregister_netdev(dev); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14968 | if (tp->aperegs) { |
| 14969 | iounmap(tp->aperegs); |
| 14970 | tp->aperegs = NULL; |
| 14971 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14972 | if (tp->regs) { |
| 14973 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 14974 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14975 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14976 | free_netdev(dev); |
| 14977 | pci_release_regions(pdev); |
| 14978 | pci_disable_device(pdev); |
| 14979 | pci_set_drvdata(pdev, NULL); |
| 14980 | } |
| 14981 | } |
| 14982 | |
| 14983 | static int tg3_suspend(struct pci_dev *pdev, pm_message_t state) |
| 14984 | { |
| 14985 | struct net_device *dev = pci_get_drvdata(pdev); |
| 14986 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 14987 | pci_power_t target_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14988 | int err; |
| 14989 | |
Michael Chan | 3e0c95f | 2007-08-03 20:56:54 -0700 | [diff] [blame] | 14990 | /* PCI register 4 needs to be saved whether netif_running() or not. |
| 14991 | * MSI address and data need to be saved if using MSI and |
| 14992 | * netif_running(). |
| 14993 | */ |
| 14994 | pci_save_state(pdev); |
| 14995 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14996 | if (!netif_running(dev)) |
| 14997 | return 0; |
| 14998 | |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 14999 | flush_scheduled_work(); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15000 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15001 | tg3_netif_stop(tp); |
| 15002 | |
| 15003 | del_timer_sync(&tp->timer); |
| 15004 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15005 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15006 | tg3_disable_ints(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15007 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15008 | |
| 15009 | netif_device_detach(dev); |
| 15010 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15011 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 15012 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 6a9eba1 | 2005-12-13 21:08:58 -0800 | [diff] [blame] | 15013 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15014 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15015 | |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 15016 | target_state = pdev->pm_cap ? pci_target_state(pdev) : PCI_D3hot; |
| 15017 | |
| 15018 | err = tg3_set_power_state(tp, target_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15019 | if (err) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15020 | int err2; |
| 15021 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15022 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15023 | |
Michael Chan | 6a9eba1 | 2005-12-13 21:08:58 -0800 | [diff] [blame] | 15024 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15025 | err2 = tg3_restart_hw(tp, 1); |
| 15026 | if (err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15027 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15028 | |
| 15029 | tp->timer.expires = jiffies + tp->timer_offset; |
| 15030 | add_timer(&tp->timer); |
| 15031 | |
| 15032 | netif_device_attach(dev); |
| 15033 | tg3_netif_start(tp); |
| 15034 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15035 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15036 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15037 | |
| 15038 | if (!err2) |
| 15039 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15040 | } |
| 15041 | |
| 15042 | return err; |
| 15043 | } |
| 15044 | |
| 15045 | static int tg3_resume(struct pci_dev *pdev) |
| 15046 | { |
| 15047 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15048 | struct tg3 *tp = netdev_priv(dev); |
| 15049 | int err; |
| 15050 | |
Michael Chan | 3e0c95f | 2007-08-03 20:56:54 -0700 | [diff] [blame] | 15051 | pci_restore_state(tp->pdev); |
| 15052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15053 | if (!netif_running(dev)) |
| 15054 | return 0; |
| 15055 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 15056 | err = tg3_set_power_state(tp, PCI_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15057 | if (err) |
| 15058 | return err; |
| 15059 | |
| 15060 | netif_device_attach(dev); |
| 15061 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15062 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15063 | |
Michael Chan | 6a9eba1 | 2005-12-13 21:08:58 -0800 | [diff] [blame] | 15064 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15065 | err = tg3_restart_hw(tp, 1); |
| 15066 | if (err) |
| 15067 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15068 | |
| 15069 | tp->timer.expires = jiffies + tp->timer_offset; |
| 15070 | add_timer(&tp->timer); |
| 15071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15072 | tg3_netif_start(tp); |
| 15073 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15074 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15075 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15076 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15077 | if (!err) |
| 15078 | tg3_phy_start(tp); |
| 15079 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15080 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15081 | } |
| 15082 | |
| 15083 | static struct pci_driver tg3_driver = { |
| 15084 | .name = DRV_MODULE_NAME, |
| 15085 | .id_table = tg3_pci_tbl, |
| 15086 | .probe = tg3_init_one, |
| 15087 | .remove = __devexit_p(tg3_remove_one), |
| 15088 | .suspend = tg3_suspend, |
| 15089 | .resume = tg3_resume |
| 15090 | }; |
| 15091 | |
| 15092 | static int __init tg3_init(void) |
| 15093 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 15094 | return pci_register_driver(&tg3_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15095 | } |
| 15096 | |
| 15097 | static void __exit tg3_cleanup(void) |
| 15098 | { |
| 15099 | pci_unregister_driver(&tg3_driver); |
| 15100 | } |
| 15101 | |
| 15102 | module_init(tg3_init); |
| 15103 | module_exit(tg3_cleanup); |