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> |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 35 | #include <linux/mdio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/mii.h> |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 37 | #include <linux/phy.h> |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 38 | #include <linux/brcmphy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/if_vlan.h> |
| 40 | #include <linux/ip.h> |
| 41 | #include <linux/tcp.h> |
| 42 | #include <linux/workqueue.h> |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 43 | #include <linux/prefetch.h> |
Tobias Klauser | f9a5f7d | 2005-10-29 15:09:26 +0200 | [diff] [blame] | 44 | #include <linux/dma-mapping.h> |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 45 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #include <net/checksum.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 48 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #include <asm/system.h> |
| 51 | #include <asm/io.h> |
| 52 | #include <asm/byteorder.h> |
| 53 | #include <asm/uaccess.h> |
| 54 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 55 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <asm/idprom.h> |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 57 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #endif |
| 59 | |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 60 | #define BAR_0 0 |
| 61 | #define BAR_2 2 |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
| 64 | #define TG3_VLAN_TAG_USED 1 |
| 65 | #else |
| 66 | #define TG3_VLAN_TAG_USED 0 |
| 67 | #endif |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #include "tg3.h" |
| 70 | |
| 71 | #define DRV_MODULE_NAME "tg3" |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 72 | #define TG3_MAJ_NUM 3 |
Matt Carlson | 7c1a96a | 2010-10-14 10:37:45 +0000 | [diff] [blame] | 73 | #define TG3_MIN_NUM 115 |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 74 | #define DRV_MODULE_VERSION \ |
| 75 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) |
Matt Carlson | 7c1a96a | 2010-10-14 10:37:45 +0000 | [diff] [blame] | 76 | #define DRV_MODULE_RELDATE "October 14, 2010" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | #define TG3_DEF_MAC_MODE 0 |
| 79 | #define TG3_DEF_RX_MODE 0 |
| 80 | #define TG3_DEF_TX_MODE 0 |
| 81 | #define TG3_DEF_MSG_ENABLE \ |
| 82 | (NETIF_MSG_DRV | \ |
| 83 | NETIF_MSG_PROBE | \ |
| 84 | NETIF_MSG_LINK | \ |
| 85 | NETIF_MSG_TIMER | \ |
| 86 | NETIF_MSG_IFDOWN | \ |
| 87 | NETIF_MSG_IFUP | \ |
| 88 | NETIF_MSG_RX_ERR | \ |
| 89 | NETIF_MSG_TX_ERR) |
| 90 | |
| 91 | /* length of time before we decide the hardware is borked, |
| 92 | * and dev->tx_timeout() should be called to fix the problem |
| 93 | */ |
| 94 | #define TG3_TX_TIMEOUT (5 * HZ) |
| 95 | |
| 96 | /* hardware minimum and maximum for a single frame's data payload */ |
| 97 | #define TG3_MIN_MTU 60 |
| 98 | #define TG3_MAX_MTU(tp) \ |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 99 | ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) ? 9000 : 1500) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | /* These numbers seem to be hard coded in the NIC firmware somehow. |
| 102 | * You can't change the ring sizes, but you can change where you place |
| 103 | * them in the NIC onboard memory. |
| 104 | */ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 105 | #define TG3_RX_STD_RING_SIZE(tp) \ |
| 106 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || \ |
| 107 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) ? \ |
| 108 | RX_STD_MAX_SIZE_5717 : 512) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | #define TG3_DEF_RX_RING_PENDING 200 |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 110 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
| 111 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || \ |
| 112 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) ? \ |
| 113 | 1024 : 256) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 115 | #define TG3_RSS_INDIR_TBL_SIZE 128 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | /* Do not place this n-ring entries value into the tp struct itself, |
| 118 | * we really want to expose these constants to GCC so that modulo et |
| 119 | * al. operations are done with shifts and masks instead of with |
| 120 | * hw multiply/modulo instructions. Another solution would be to |
| 121 | * replace things like '% foo' with '& (foo - 1)'. |
| 122 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | #define TG3_TX_RING_SIZE 512 |
| 125 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) |
| 126 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 127 | #define TG3_RX_STD_RING_BYTES(tp) \ |
| 128 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) |
| 129 | #define TG3_RX_JMB_RING_BYTES(tp) \ |
| 130 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) |
| 131 | #define TG3_RX_RCB_RING_BYTES(tp) \ |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 132 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
| 134 | TG3_TX_RING_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
| 136 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 137 | #define TG3_RX_DMA_ALIGN 16 |
| 138 | #define TG3_RX_HEADROOM ALIGN(VLAN_HLEN, TG3_RX_DMA_ALIGN) |
| 139 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 140 | #define TG3_DMA_BYTE_ENAB 64 |
| 141 | |
| 142 | #define TG3_RX_STD_DMA_SZ 1536 |
| 143 | #define TG3_RX_JMB_DMA_SZ 9046 |
| 144 | |
| 145 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) |
| 146 | |
| 147 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) |
| 148 | #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] | 149 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 150 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
| 151 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 152 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 153 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
| 154 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 155 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 156 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
| 157 | * that are at least dword aligned when used in PCIX mode. The driver |
| 158 | * works around this bug by double copying the packet. This workaround |
| 159 | * is built into the normal double copy length check for efficiency. |
| 160 | * |
| 161 | * However, the double copy is only necessary on those architectures |
| 162 | * where unaligned memory accesses are inefficient. For those architectures |
| 163 | * where unaligned memory accesses incur little penalty, we can reintegrate |
| 164 | * the 5701 in the normal rx path. Doing so saves a device structure |
| 165 | * dereference by hardcoding the double copy threshold in place. |
| 166 | */ |
| 167 | #define TG3_RX_COPY_THRESHOLD 256 |
| 168 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 169 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD |
| 170 | #else |
| 171 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) |
| 172 | #endif |
| 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | /* minimum number of free TX descriptors required to wake up TX process */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 175 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 177 | #define TG3_RAW_IP_ALIGN 2 |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* number of ETHTOOL_GSTATS u64's */ |
| 180 | #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64)) |
| 181 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 182 | #define TG3_NUM_TEST 6 |
| 183 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 184 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
| 185 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 186 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
| 187 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
| 188 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | static char version[] __devinitdata = |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 191 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); |
| 194 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); |
| 195 | MODULE_LICENSE("GPL"); |
| 196 | MODULE_VERSION(DRV_MODULE_VERSION); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 197 | MODULE_FIRMWARE(FIRMWARE_TG3); |
| 198 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); |
| 199 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); |
| 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
| 202 | module_param(tg3_debug, int, 0); |
| 203 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); |
| 204 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 205 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 206 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
| 207 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, |
| 208 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, |
| 209 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, |
| 210 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, |
| 211 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, |
| 212 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, |
| 213 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, |
| 214 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, |
| 215 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, |
| 216 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, |
| 217 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, |
| 218 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, |
| 219 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, |
| 220 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, |
| 221 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, |
| 222 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, |
| 223 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, |
| 224 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)}, |
| 225 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)}, |
| 226 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, |
| 227 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 228 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 229 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 230 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 231 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
| 232 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)}, |
| 233 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
| 234 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, |
| 235 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, |
| 236 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, |
| 237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)}, |
| 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
| 239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, |
| 240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, |
| 241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
| 244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, |
| 245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
| 248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, |
| 249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, |
| 250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, |
| 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, |
| 252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, |
| 253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
| 255 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 256 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
| 257 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
Matt Carlson | 6c7af27 | 2007-10-21 16:12:02 -0700 | [diff] [blame] | 258 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 259 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
| 260 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
Matt Carlson | c88e668 | 2008-11-03 16:49:18 -0800 | [diff] [blame] | 261 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
| 262 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, |
Matt Carlson | 2befdce | 2009-08-28 12:28:45 +0000 | [diff] [blame] | 263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
| 264 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 265 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
| 266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, |
| 267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790)}, |
Matt Carlson | 5e7ccf2 | 2009-08-25 10:08:42 +0000 | [diff] [blame] | 268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
| 270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
Matt Carlson | b0f7522 | 2010-01-20 16:58:11 +0000 | [diff] [blame] | 271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
| 272 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, |
| 273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, |
| 274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, |
| 275 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791)}, |
| 276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)}, |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 277 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 278 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
| 279 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, |
| 280 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, |
| 281 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, |
| 282 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, |
| 283 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, |
| 284 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, |
| 285 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); |
| 289 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 290 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | const char string[ETH_GSTRING_LEN]; |
| 292 | } ethtool_stats_keys[TG3_NUM_STATS] = { |
| 293 | { "rx_octets" }, |
| 294 | { "rx_fragments" }, |
| 295 | { "rx_ucast_packets" }, |
| 296 | { "rx_mcast_packets" }, |
| 297 | { "rx_bcast_packets" }, |
| 298 | { "rx_fcs_errors" }, |
| 299 | { "rx_align_errors" }, |
| 300 | { "rx_xon_pause_rcvd" }, |
| 301 | { "rx_xoff_pause_rcvd" }, |
| 302 | { "rx_mac_ctrl_rcvd" }, |
| 303 | { "rx_xoff_entered" }, |
| 304 | { "rx_frame_too_long_errors" }, |
| 305 | { "rx_jabbers" }, |
| 306 | { "rx_undersize_packets" }, |
| 307 | { "rx_in_length_errors" }, |
| 308 | { "rx_out_length_errors" }, |
| 309 | { "rx_64_or_less_octet_packets" }, |
| 310 | { "rx_65_to_127_octet_packets" }, |
| 311 | { "rx_128_to_255_octet_packets" }, |
| 312 | { "rx_256_to_511_octet_packets" }, |
| 313 | { "rx_512_to_1023_octet_packets" }, |
| 314 | { "rx_1024_to_1522_octet_packets" }, |
| 315 | { "rx_1523_to_2047_octet_packets" }, |
| 316 | { "rx_2048_to_4095_octet_packets" }, |
| 317 | { "rx_4096_to_8191_octet_packets" }, |
| 318 | { "rx_8192_to_9022_octet_packets" }, |
| 319 | |
| 320 | { "tx_octets" }, |
| 321 | { "tx_collisions" }, |
| 322 | |
| 323 | { "tx_xon_sent" }, |
| 324 | { "tx_xoff_sent" }, |
| 325 | { "tx_flow_control" }, |
| 326 | { "tx_mac_errors" }, |
| 327 | { "tx_single_collisions" }, |
| 328 | { "tx_mult_collisions" }, |
| 329 | { "tx_deferred" }, |
| 330 | { "tx_excessive_collisions" }, |
| 331 | { "tx_late_collisions" }, |
| 332 | { "tx_collide_2times" }, |
| 333 | { "tx_collide_3times" }, |
| 334 | { "tx_collide_4times" }, |
| 335 | { "tx_collide_5times" }, |
| 336 | { "tx_collide_6times" }, |
| 337 | { "tx_collide_7times" }, |
| 338 | { "tx_collide_8times" }, |
| 339 | { "tx_collide_9times" }, |
| 340 | { "tx_collide_10times" }, |
| 341 | { "tx_collide_11times" }, |
| 342 | { "tx_collide_12times" }, |
| 343 | { "tx_collide_13times" }, |
| 344 | { "tx_collide_14times" }, |
| 345 | { "tx_collide_15times" }, |
| 346 | { "tx_ucast_packets" }, |
| 347 | { "tx_mcast_packets" }, |
| 348 | { "tx_bcast_packets" }, |
| 349 | { "tx_carrier_sense_errors" }, |
| 350 | { "tx_discards" }, |
| 351 | { "tx_errors" }, |
| 352 | |
| 353 | { "dma_writeq_full" }, |
| 354 | { "dma_write_prioq_full" }, |
| 355 | { "rxbds_empty" }, |
| 356 | { "rx_discards" }, |
| 357 | { "rx_errors" }, |
| 358 | { "rx_threshold_hit" }, |
| 359 | |
| 360 | { "dma_readq_full" }, |
| 361 | { "dma_read_prioq_full" }, |
| 362 | { "tx_comp_queue_full" }, |
| 363 | |
| 364 | { "ring_set_send_prod_index" }, |
| 365 | { "ring_status_update" }, |
| 366 | { "nic_irqs" }, |
| 367 | { "nic_avoided_irqs" }, |
| 368 | { "nic_tx_threshold_hit" } |
| 369 | }; |
| 370 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 371 | static const struct { |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 372 | const char string[ETH_GSTRING_LEN]; |
| 373 | } ethtool_test_keys[TG3_NUM_TEST] = { |
| 374 | { "nvram test (online) " }, |
| 375 | { "link test (online) " }, |
| 376 | { "register test (offline)" }, |
| 377 | { "memory test (offline)" }, |
| 378 | { "loopback test (offline)" }, |
| 379 | { "interrupt test (offline)" }, |
| 380 | }; |
| 381 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 382 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
| 383 | { |
| 384 | writel(val, tp->regs + off); |
| 385 | } |
| 386 | |
| 387 | static u32 tg3_read32(struct tg3 *tp, u32 off) |
| 388 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 389 | return readl(tp->regs + off); |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 392 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
| 393 | { |
| 394 | writel(val, tp->aperegs + off); |
| 395 | } |
| 396 | |
| 397 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) |
| 398 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 399 | return readl(tp->aperegs + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
| 403 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 404 | unsigned long flags; |
| 405 | |
| 406 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 407 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 408 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 409 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) |
| 413 | { |
| 414 | writel(val, tp->regs + off); |
| 415 | readl(tp->regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 418 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
| 419 | { |
| 420 | unsigned long flags; |
| 421 | u32 val; |
| 422 | |
| 423 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 424 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 425 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 426 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 427 | return val; |
| 428 | } |
| 429 | |
| 430 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) |
| 431 | { |
| 432 | unsigned long flags; |
| 433 | |
| 434 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { |
| 435 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + |
| 436 | TG3_64BIT_REG_LOW, val); |
| 437 | return; |
| 438 | } |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 439 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 440 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
| 441 | TG3_64BIT_REG_LOW, val); |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 446 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 447 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 448 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 449 | |
| 450 | /* In indirect mode when disabling interrupts, we also need |
| 451 | * to clear the interrupt bit in the GRC local ctrl register. |
| 452 | */ |
| 453 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && |
| 454 | (val == 0x1)) { |
| 455 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, |
| 456 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) |
| 461 | { |
| 462 | unsigned long flags; |
| 463 | u32 val; |
| 464 | |
| 465 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 466 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 467 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 468 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 469 | return val; |
| 470 | } |
| 471 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 472 | /* usec_wait specifies the wait time in usec when writing to certain registers |
| 473 | * where it is unsafe to read back the register without some delay. |
| 474 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. |
| 475 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. |
| 476 | */ |
| 477 | 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] | 478 | { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 479 | if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) || |
| 480 | (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND)) |
| 481 | /* Non-posted methods */ |
| 482 | tp->write32(tp, off, val); |
| 483 | else { |
| 484 | /* Posted method */ |
| 485 | tg3_write32(tp, off, val); |
| 486 | if (usec_wait) |
| 487 | udelay(usec_wait); |
| 488 | tp->read32(tp, off); |
| 489 | } |
| 490 | /* Wait again after the read for the posted method to guarantee that |
| 491 | * the wait time is met. |
| 492 | */ |
| 493 | if (usec_wait) |
| 494 | udelay(usec_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 497 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
| 498 | { |
| 499 | tp->write32_mbox(tp, off, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 500 | if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) && |
| 501 | !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND)) |
| 502 | tp->read32_mbox(tp, off); |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 505 | 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] | 506 | { |
| 507 | void __iomem *mbox = tp->regs + off; |
| 508 | writel(val, mbox); |
| 509 | if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) |
| 510 | writel(val, mbox); |
| 511 | if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) |
| 512 | readl(mbox); |
| 513 | } |
| 514 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 515 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
| 516 | { |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 517 | return readl(tp->regs + off + GRCMBOX_BASE); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) |
| 521 | { |
| 522 | writel(val, tp->regs + off + GRCMBOX_BASE); |
| 523 | } |
| 524 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 525 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 526 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 527 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
| 528 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) |
| 529 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 530 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 531 | #define tw32(reg, val) tp->write32(tp, reg, val) |
| 532 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) |
| 533 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) |
| 534 | #define tr32(reg) tp->read32(tp, reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
| 536 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) |
| 537 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 538 | unsigned long flags; |
| 539 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 540 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
| 541 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
| 542 | return; |
| 543 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 544 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 545 | if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) { |
| 546 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 547 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 549 | /* Always leave this as zero. */ |
| 550 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 551 | } else { |
| 552 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 553 | tw32_f(TG3PCI_MEM_WIN_DATA, val); |
| 554 | |
| 555 | /* Always leave this as zero. */ |
| 556 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 557 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 558 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
| 562 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 563 | unsigned long flags; |
| 564 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 565 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
| 566 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
| 567 | *val = 0; |
| 568 | return; |
| 569 | } |
| 570 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 571 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 572 | if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) { |
| 573 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 574 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 576 | /* Always leave this as zero. */ |
| 577 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 578 | } else { |
| 579 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 580 | *val = tr32(TG3PCI_MEM_WIN_DATA); |
| 581 | |
| 582 | /* Always leave this as zero. */ |
| 583 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 584 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 585 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 588 | static void tg3_ape_lock_init(struct tg3 *tp) |
| 589 | { |
| 590 | int i; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 591 | u32 regbase; |
| 592 | |
| 593 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 594 | regbase = TG3_APE_LOCK_GRANT; |
| 595 | else |
| 596 | regbase = TG3_APE_PER_LOCK_GRANT; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 597 | |
| 598 | /* Make sure the driver hasn't any stale locks. */ |
| 599 | for (i = 0; i < 8; i++) |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 600 | tg3_ape_write32(tp, regbase + 4 * i, APE_LOCK_GRANT_DRIVER); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static int tg3_ape_lock(struct tg3 *tp, int locknum) |
| 604 | { |
| 605 | int i, off; |
| 606 | int ret = 0; |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 607 | u32 status, req, gnt; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 608 | |
| 609 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) |
| 610 | return 0; |
| 611 | |
| 612 | switch (locknum) { |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 613 | case TG3_APE_LOCK_GRC: |
| 614 | case TG3_APE_LOCK_MEM: |
| 615 | break; |
| 616 | default: |
| 617 | return -EINVAL; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 620 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
| 621 | req = TG3_APE_LOCK_REQ; |
| 622 | gnt = TG3_APE_LOCK_GRANT; |
| 623 | } else { |
| 624 | req = TG3_APE_PER_LOCK_REQ; |
| 625 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 626 | } |
| 627 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 628 | off = 4 * locknum; |
| 629 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 630 | tg3_ape_write32(tp, req + off, APE_LOCK_REQ_DRIVER); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 631 | |
| 632 | /* Wait for up to 1 millisecond to acquire lock. */ |
| 633 | for (i = 0; i < 100; i++) { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 634 | status = tg3_ape_read32(tp, gnt + off); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 635 | if (status == APE_LOCK_GRANT_DRIVER) |
| 636 | break; |
| 637 | udelay(10); |
| 638 | } |
| 639 | |
| 640 | if (status != APE_LOCK_GRANT_DRIVER) { |
| 641 | /* Revoke the lock request. */ |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 642 | tg3_ape_write32(tp, gnt + off, |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 643 | APE_LOCK_GRANT_DRIVER); |
| 644 | |
| 645 | ret = -EBUSY; |
| 646 | } |
| 647 | |
| 648 | return ret; |
| 649 | } |
| 650 | |
| 651 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) |
| 652 | { |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 653 | u32 gnt; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 654 | |
| 655 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) |
| 656 | return; |
| 657 | |
| 658 | switch (locknum) { |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 659 | case TG3_APE_LOCK_GRC: |
| 660 | case TG3_APE_LOCK_MEM: |
| 661 | break; |
| 662 | default: |
| 663 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 666 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 667 | gnt = TG3_APE_LOCK_GRANT; |
| 668 | else |
| 669 | gnt = TG3_APE_PER_LOCK_GRANT; |
| 670 | |
| 671 | tg3_ape_write32(tp, gnt + 4 * locknum, APE_LOCK_GRANT_DRIVER); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | static void tg3_disable_ints(struct tg3 *tp) |
| 675 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 676 | int i; |
| 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 679 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 680 | for (i = 0; i < tp->irq_max; i++) |
| 681 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | static void tg3_enable_ints(struct tg3 *tp) |
| 685 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 686 | int i; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 687 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 688 | tp->irq_sync = 0; |
| 689 | wmb(); |
| 690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 692 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 693 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 694 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 695 | for (i = 0; i < tp->irq_cnt; i++) { |
| 696 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 697 | |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 698 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 699 | if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) |
| 700 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 701 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 702 | tp->coal_now |= tnapi->coal_now; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 703 | } |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 704 | |
| 705 | /* Force an initial interrupt */ |
| 706 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) && |
| 707 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
| 708 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 709 | else |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 710 | tw32(HOSTCC_MODE, tp->coal_now); |
| 711 | |
| 712 | 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] | 713 | } |
| 714 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 715 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 716 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 717 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 718 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 719 | unsigned int work_exists = 0; |
| 720 | |
| 721 | /* check for phy events */ |
| 722 | if (!(tp->tg3_flags & |
| 723 | (TG3_FLAG_USE_LINKCHG_REG | |
| 724 | TG3_FLAG_POLL_SERDES))) { |
| 725 | if (sblk->status & SD_STATUS_LINK_CHG) |
| 726 | work_exists = 1; |
| 727 | } |
| 728 | /* check for RX/TX work to do */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 729 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons || |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 730 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 731 | work_exists = 1; |
| 732 | |
| 733 | return work_exists; |
| 734 | } |
| 735 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 736 | /* tg3_int_reenable |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 737 | * similar to tg3_enable_ints, but it accurately determines whether there |
| 738 | * is new work pending and can return without flushing the PIO write |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 739 | * which reenables interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 741 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 743 | struct tg3 *tp = tnapi->tp; |
| 744 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 745 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | mmiowb(); |
| 747 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 748 | /* When doing tagged status, this work check is unnecessary. |
| 749 | * The last_tag we write above tells the chip which piece of |
| 750 | * work we've completed. |
| 751 | */ |
| 752 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) && |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 753 | tg3_has_work(tnapi)) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 754 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 755 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | static void tg3_switch_clocks(struct tg3 *tp) |
| 759 | { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 760 | u32 clock_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | u32 orig_clock_ctrl; |
| 762 | |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 763 | if ((tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) || |
| 764 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 765 | return; |
| 766 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 767 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
| 768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | orig_clock_ctrl = clock_ctrl; |
| 770 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | |
| 771 | CLOCK_CTRL_CLKRUN_OENABLE | |
| 772 | 0x1f); |
| 773 | tp->pci_clock_ctrl = clock_ctrl; |
| 774 | |
| 775 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 776 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 777 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 778 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
| 780 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 781 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 782 | clock_ctrl | |
| 783 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), |
| 784 | 40); |
| 785 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 786 | clock_ctrl | (CLOCK_CTRL_ALTCLK), |
| 787 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 789 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | #define PHY_BUSY_LOOPS 5000 |
| 793 | |
| 794 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
| 795 | { |
| 796 | u32 frame_val; |
| 797 | unsigned int loops; |
| 798 | int ret; |
| 799 | |
| 800 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 801 | tw32_f(MAC_MI_MODE, |
| 802 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 803 | udelay(80); |
| 804 | } |
| 805 | |
| 806 | *val = 0x0; |
| 807 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 808 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | MI_COM_PHY_ADDR_MASK); |
| 810 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 811 | MI_COM_REG_ADDR_MASK); |
| 812 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | tw32_f(MAC_MI_COM, frame_val); |
| 815 | |
| 816 | loops = PHY_BUSY_LOOPS; |
| 817 | while (loops != 0) { |
| 818 | udelay(10); |
| 819 | frame_val = tr32(MAC_MI_COM); |
| 820 | |
| 821 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 822 | udelay(5); |
| 823 | frame_val = tr32(MAC_MI_COM); |
| 824 | break; |
| 825 | } |
| 826 | loops -= 1; |
| 827 | } |
| 828 | |
| 829 | ret = -EBUSY; |
| 830 | if (loops != 0) { |
| 831 | *val = frame_val & MI_COM_DATA_MASK; |
| 832 | ret = 0; |
| 833 | } |
| 834 | |
| 835 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 836 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 837 | udelay(80); |
| 838 | } |
| 839 | |
| 840 | return ret; |
| 841 | } |
| 842 | |
| 843 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
| 844 | { |
| 845 | u32 frame_val; |
| 846 | unsigned int loops; |
| 847 | int ret; |
| 848 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 849 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 850 | (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL)) |
| 851 | return 0; |
| 852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 854 | tw32_f(MAC_MI_MODE, |
| 855 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 856 | udelay(80); |
| 857 | } |
| 858 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 859 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | MI_COM_PHY_ADDR_MASK); |
| 861 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 862 | MI_COM_REG_ADDR_MASK); |
| 863 | frame_val |= (val & MI_COM_DATA_MASK); |
| 864 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | tw32_f(MAC_MI_COM, frame_val); |
| 867 | |
| 868 | loops = PHY_BUSY_LOOPS; |
| 869 | while (loops != 0) { |
| 870 | udelay(10); |
| 871 | frame_val = tr32(MAC_MI_COM); |
| 872 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 873 | udelay(5); |
| 874 | frame_val = tr32(MAC_MI_COM); |
| 875 | break; |
| 876 | } |
| 877 | loops -= 1; |
| 878 | } |
| 879 | |
| 880 | ret = -EBUSY; |
| 881 | if (loops != 0) |
| 882 | ret = 0; |
| 883 | |
| 884 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 885 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 886 | udelay(80); |
| 887 | } |
| 888 | |
| 889 | return ret; |
| 890 | } |
| 891 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 892 | static int tg3_bmcr_reset(struct tg3 *tp) |
| 893 | { |
| 894 | u32 phy_control; |
| 895 | int limit, err; |
| 896 | |
| 897 | /* OK, reset it, and poll the BMCR_RESET bit until it |
| 898 | * clears or we time out. |
| 899 | */ |
| 900 | phy_control = BMCR_RESET; |
| 901 | err = tg3_writephy(tp, MII_BMCR, phy_control); |
| 902 | if (err != 0) |
| 903 | return -EBUSY; |
| 904 | |
| 905 | limit = 5000; |
| 906 | while (limit--) { |
| 907 | err = tg3_readphy(tp, MII_BMCR, &phy_control); |
| 908 | if (err != 0) |
| 909 | return -EBUSY; |
| 910 | |
| 911 | if ((phy_control & BMCR_RESET) == 0) { |
| 912 | udelay(40); |
| 913 | break; |
| 914 | } |
| 915 | udelay(10); |
| 916 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 917 | if (limit < 0) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 918 | return -EBUSY; |
| 919 | |
| 920 | return 0; |
| 921 | } |
| 922 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 923 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
| 924 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 925 | struct tg3 *tp = bp->priv; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 926 | u32 val; |
| 927 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 928 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 929 | |
| 930 | if (tg3_readphy(tp, reg, &val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 931 | val = -EIO; |
| 932 | |
| 933 | spin_unlock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 934 | |
| 935 | return val; |
| 936 | } |
| 937 | |
| 938 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) |
| 939 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 940 | struct tg3 *tp = bp->priv; |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 941 | u32 ret = 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 942 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 943 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 944 | |
| 945 | if (tg3_writephy(tp, reg, val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 946 | ret = -EIO; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 947 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 948 | spin_unlock_bh(&tp->lock); |
| 949 | |
| 950 | return ret; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | static int tg3_mdio_reset(struct mii_bus *bp) |
| 954 | { |
| 955 | return 0; |
| 956 | } |
| 957 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 958 | static void tg3_mdio_config_5785(struct tg3 *tp) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 959 | { |
| 960 | u32 val; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 961 | struct phy_device *phydev; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 962 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 963 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 964 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 965 | case PHY_ID_BCM50610: |
| 966 | case PHY_ID_BCM50610M: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 967 | val = MAC_PHYCFG2_50610_LED_MODES; |
| 968 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 969 | case PHY_ID_BCMAC131: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 970 | val = MAC_PHYCFG2_AC131_LED_MODES; |
| 971 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 972 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 973 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
| 974 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 975 | case PHY_ID_RTL8201E: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 976 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
| 977 | break; |
| 978 | default: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 979 | return; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { |
| 983 | tw32(MAC_PHYCFG2, val); |
| 984 | |
| 985 | val = tr32(MAC_PHYCFG1); |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 986 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
| 987 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); |
| 988 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 989 | tw32(MAC_PHYCFG1, val); |
| 990 | |
| 991 | return; |
| 992 | } |
| 993 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 994 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 995 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
| 996 | MAC_PHYCFG2_FMODE_MASK_MASK | |
| 997 | MAC_PHYCFG2_GMODE_MASK_MASK | |
| 998 | MAC_PHYCFG2_ACT_MASK_MASK | |
| 999 | MAC_PHYCFG2_QUAL_MASK_MASK | |
| 1000 | MAC_PHYCFG2_INBAND_ENABLE; |
| 1001 | |
| 1002 | tw32(MAC_PHYCFG2, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1003 | |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1004 | val = tr32(MAC_PHYCFG1); |
| 1005 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | |
| 1006 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 1007 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) { |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1008 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
| 1009 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
| 1010 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) |
| 1011 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
| 1012 | } |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1013 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
| 1014 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; |
| 1015 | tw32(MAC_PHYCFG1, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1016 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1017 | val = tr32(MAC_EXT_RGMII_MODE); |
| 1018 | val &= ~(MAC_RGMII_MODE_RX_INT_B | |
| 1019 | MAC_RGMII_MODE_RX_QUALITY | |
| 1020 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1021 | MAC_RGMII_MODE_RX_ENG_DET | |
| 1022 | MAC_RGMII_MODE_TX_ENABLE | |
| 1023 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1024 | MAC_RGMII_MODE_TX_RESET); |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 1025 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) { |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1026 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
| 1027 | val |= MAC_RGMII_MODE_RX_INT_B | |
| 1028 | MAC_RGMII_MODE_RX_QUALITY | |
| 1029 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1030 | MAC_RGMII_MODE_RX_ENG_DET; |
| 1031 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) |
| 1032 | val |= MAC_RGMII_MODE_TX_ENABLE | |
| 1033 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1034 | MAC_RGMII_MODE_TX_RESET; |
| 1035 | } |
| 1036 | tw32(MAC_EXT_RGMII_MODE, val); |
| 1037 | } |
| 1038 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1039 | static void tg3_mdio_start(struct tg3 *tp) |
| 1040 | { |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1041 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
| 1042 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1043 | udelay(80); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1044 | |
Matt Carlson | 9ea4818 | 2010-02-17 15:17:01 +0000 | [diff] [blame] | 1045 | if ((tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) && |
| 1046 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1047 | tg3_mdio_config_5785(tp); |
| 1048 | } |
| 1049 | |
| 1050 | static int tg3_mdio_init(struct tg3 *tp) |
| 1051 | { |
| 1052 | int i; |
| 1053 | u32 reg; |
| 1054 | struct phy_device *phydev; |
| 1055 | |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 1056 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 1057 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1058 | u32 is_serdes; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1059 | |
Matt Carlson | 9c7df91 | 2010-06-05 17:24:36 +0000 | [diff] [blame] | 1060 | tp->phy_addr = PCI_FUNC(tp->pdev->devfn) + 1; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1061 | |
Matt Carlson | d1ec96a | 2010-01-12 10:11:38 +0000 | [diff] [blame] | 1062 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
| 1063 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
| 1064 | else |
| 1065 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & |
| 1066 | TG3_CPMU_PHY_STRAP_IS_SERDES; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1067 | if (is_serdes) |
| 1068 | tp->phy_addr += 7; |
| 1069 | } else |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1070 | tp->phy_addr = TG3_PHY_MII_ADDR; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1071 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1072 | tg3_mdio_start(tp); |
| 1073 | |
| 1074 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) || |
| 1075 | (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED)) |
| 1076 | return 0; |
| 1077 | |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1078 | tp->mdio_bus = mdiobus_alloc(); |
| 1079 | if (tp->mdio_bus == NULL) |
| 1080 | return -ENOMEM; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1081 | |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1082 | tp->mdio_bus->name = "tg3 mdio bus"; |
| 1083 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1084 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1085 | tp->mdio_bus->priv = tp; |
| 1086 | tp->mdio_bus->parent = &tp->pdev->dev; |
| 1087 | tp->mdio_bus->read = &tg3_mdio_read; |
| 1088 | tp->mdio_bus->write = &tg3_mdio_write; |
| 1089 | tp->mdio_bus->reset = &tg3_mdio_reset; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1090 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1091 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1092 | |
| 1093 | for (i = 0; i < PHY_MAX_ADDR; i++) |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1094 | tp->mdio_bus->irq[i] = PHY_POLL; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1095 | |
| 1096 | /* The bus registration will look for all the PHYs on the mdio bus. |
| 1097 | * Unfortunately, it does not ensure the PHY is powered up before |
| 1098 | * accessing the PHY ID registers. A chip reset is the |
| 1099 | * quickest way to bring the device back to an operational state.. |
| 1100 | */ |
| 1101 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
| 1102 | tg3_bmcr_reset(tp); |
| 1103 | |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1104 | i = mdiobus_register(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1105 | if (i) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1106 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1107 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1108 | return i; |
| 1109 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1110 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1111 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1112 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1113 | if (!phydev || !phydev->drv) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1114 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1115 | mdiobus_unregister(tp->mdio_bus); |
| 1116 | mdiobus_free(tp->mdio_bus); |
| 1117 | return -ENODEV; |
| 1118 | } |
| 1119 | |
| 1120 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1121 | case PHY_ID_BCM57780: |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1122 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1123 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1124 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1125 | case PHY_ID_BCM50610: |
| 1126 | case PHY_ID_BCM50610M: |
Matt Carlson | 32e5a8d | 2009-11-02 14:31:39 +0000 | [diff] [blame] | 1127 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1128 | PHY_BRCM_RX_REFCLK_UNUSED | |
Matt Carlson | 52fae08 | 2009-11-02 14:32:38 +0000 | [diff] [blame] | 1129 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1130 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 1131 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1132 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
| 1133 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
| 1134 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
| 1135 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) |
| 1136 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1137 | /* fallthru */ |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1138 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1139 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1140 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1141 | case PHY_ID_RTL8201E: |
| 1142 | case PHY_ID_BCMAC131: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1143 | phydev->interface = PHY_INTERFACE_MODE_MII; |
Matt Carlson | cdd4e09d | 2009-11-02 14:31:11 +0000 | [diff] [blame] | 1144 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1145 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1146 | break; |
| 1147 | } |
| 1148 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1149 | tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_INITED; |
| 1150 | |
| 1151 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1152 | tg3_mdio_config_5785(tp); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1153 | |
| 1154 | return 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | static void tg3_mdio_fini(struct tg3 *tp) |
| 1158 | { |
| 1159 | if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { |
| 1160 | tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_INITED; |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1161 | mdiobus_unregister(tp->mdio_bus); |
| 1162 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | |
Matt Carlson | ddfc87b | 2010-10-14 10:37:40 +0000 | [diff] [blame] | 1166 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
| 1167 | { |
| 1168 | int err; |
| 1169 | |
| 1170 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1171 | if (err) |
| 1172 | goto done; |
| 1173 | |
| 1174 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1175 | if (err) |
| 1176 | goto done; |
| 1177 | |
| 1178 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1179 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1180 | if (err) |
| 1181 | goto done; |
| 1182 | |
| 1183 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1184 | |
| 1185 | done: |
| 1186 | return err; |
| 1187 | } |
| 1188 | |
| 1189 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) |
| 1190 | { |
| 1191 | int err; |
| 1192 | |
| 1193 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1194 | if (err) |
| 1195 | goto done; |
| 1196 | |
| 1197 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1198 | if (err) |
| 1199 | goto done; |
| 1200 | |
| 1201 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1202 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1203 | if (err) |
| 1204 | goto done; |
| 1205 | |
| 1206 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1207 | |
| 1208 | done: |
| 1209 | return err; |
| 1210 | } |
| 1211 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1212 | /* tp->lock is held. */ |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1213 | static inline void tg3_generate_fw_event(struct tg3 *tp) |
| 1214 | { |
| 1215 | u32 val; |
| 1216 | |
| 1217 | val = tr32(GRC_RX_CPU_EVENT); |
| 1218 | val |= GRC_RX_CPU_DRIVER_EVENT; |
| 1219 | tw32_f(GRC_RX_CPU_EVENT, val); |
| 1220 | |
| 1221 | tp->last_event_jiffies = jiffies; |
| 1222 | } |
| 1223 | |
| 1224 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 |
| 1225 | |
| 1226 | /* tp->lock is held. */ |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1227 | static void tg3_wait_for_event_ack(struct tg3 *tp) |
| 1228 | { |
| 1229 | int i; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1230 | unsigned int delay_cnt; |
| 1231 | long time_remain; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1232 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1233 | /* If enough time has passed, no wait is necessary. */ |
| 1234 | time_remain = (long)(tp->last_event_jiffies + 1 + |
| 1235 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - |
| 1236 | (long)jiffies; |
| 1237 | if (time_remain < 0) |
| 1238 | return; |
| 1239 | |
| 1240 | /* Check if we can shorten the wait time. */ |
| 1241 | delay_cnt = jiffies_to_usecs(time_remain); |
| 1242 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) |
| 1243 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; |
| 1244 | delay_cnt = (delay_cnt >> 3) + 1; |
| 1245 | |
| 1246 | for (i = 0; i < delay_cnt; i++) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1247 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
| 1248 | break; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1249 | udelay(8); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | /* tp->lock is held. */ |
| 1254 | static void tg3_ump_link_report(struct tg3 *tp) |
| 1255 | { |
| 1256 | u32 reg; |
| 1257 | u32 val; |
| 1258 | |
| 1259 | if (!(tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
| 1260 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 1261 | return; |
| 1262 | |
| 1263 | tg3_wait_for_event_ack(tp); |
| 1264 | |
| 1265 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); |
| 1266 | |
| 1267 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); |
| 1268 | |
| 1269 | val = 0; |
| 1270 | if (!tg3_readphy(tp, MII_BMCR, ®)) |
| 1271 | val = reg << 16; |
| 1272 | if (!tg3_readphy(tp, MII_BMSR, ®)) |
| 1273 | val |= (reg & 0xffff); |
| 1274 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, val); |
| 1275 | |
| 1276 | val = 0; |
| 1277 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) |
| 1278 | val = reg << 16; |
| 1279 | if (!tg3_readphy(tp, MII_LPA, ®)) |
| 1280 | val |= (reg & 0xffff); |
| 1281 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 4, val); |
| 1282 | |
| 1283 | val = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1284 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1285 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
| 1286 | val = reg << 16; |
| 1287 | if (!tg3_readphy(tp, MII_STAT1000, ®)) |
| 1288 | val |= (reg & 0xffff); |
| 1289 | } |
| 1290 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 8, val); |
| 1291 | |
| 1292 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) |
| 1293 | val = reg << 16; |
| 1294 | else |
| 1295 | val = 0; |
| 1296 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val); |
| 1297 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1298 | tg3_generate_fw_event(tp); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | static void tg3_link_report(struct tg3 *tp) |
| 1302 | { |
| 1303 | if (!netif_carrier_ok(tp->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1304 | netif_info(tp, link, tp->dev, "Link is down\n"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1305 | tg3_ump_link_report(tp); |
| 1306 | } else if (netif_msg_link(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1307 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
| 1308 | (tp->link_config.active_speed == SPEED_1000 ? |
| 1309 | 1000 : |
| 1310 | (tp->link_config.active_speed == SPEED_100 ? |
| 1311 | 100 : 10)), |
| 1312 | (tp->link_config.active_duplex == DUPLEX_FULL ? |
| 1313 | "full" : "half")); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1314 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 1315 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", |
| 1316 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? |
| 1317 | "on" : "off", |
| 1318 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? |
| 1319 | "on" : "off"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1320 | tg3_ump_link_report(tp); |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl) |
| 1325 | { |
| 1326 | u16 miireg; |
| 1327 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1328 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1329 | miireg = ADVERTISE_PAUSE_CAP; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1330 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1331 | miireg = ADVERTISE_PAUSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1332 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1333 | miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1334 | else |
| 1335 | miireg = 0; |
| 1336 | |
| 1337 | return miireg; |
| 1338 | } |
| 1339 | |
| 1340 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
| 1341 | { |
| 1342 | u16 miireg; |
| 1343 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1344 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1345 | miireg = ADVERTISE_1000XPAUSE; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1346 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1347 | miireg = ADVERTISE_1000XPSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1348 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1349 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
| 1350 | else |
| 1351 | miireg = 0; |
| 1352 | |
| 1353 | return miireg; |
| 1354 | } |
| 1355 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1356 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
| 1357 | { |
| 1358 | u8 cap = 0; |
| 1359 | |
| 1360 | if (lcladv & ADVERTISE_1000XPAUSE) { |
| 1361 | if (lcladv & ADVERTISE_1000XPSE_ASYM) { |
| 1362 | if (rmtadv & LPA_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1363 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1364 | else if (rmtadv & LPA_1000XPAUSE_ASYM) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1365 | cap = FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1366 | } else { |
| 1367 | if (rmtadv & LPA_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1368 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1369 | } |
| 1370 | } else if (lcladv & ADVERTISE_1000XPSE_ASYM) { |
| 1371 | if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM)) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1372 | cap = FLOW_CTRL_TX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | return cap; |
| 1376 | } |
| 1377 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1378 | 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] | 1379 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1380 | u8 autoneg; |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1381 | u8 flowctrl = 0; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1382 | u32 old_rx_mode = tp->rx_mode; |
| 1383 | u32 old_tx_mode = tp->tx_mode; |
| 1384 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1385 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1386 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1387 | else |
| 1388 | autoneg = tp->link_config.autoneg; |
| 1389 | |
| 1390 | if (autoneg == AUTONEG_ENABLE && |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1391 | (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1392 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1393 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1394 | else |
Steve Glendinning | bc02ff9 | 2008-12-16 02:00:48 -0800 | [diff] [blame] | 1395 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1396 | } else |
| 1397 | flowctrl = tp->link_config.flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1398 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1399 | tp->link_config.active_flowctrl = flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1400 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1401 | if (flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1402 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
| 1403 | else |
| 1404 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; |
| 1405 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1406 | if (old_rx_mode != tp->rx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1407 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1408 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1409 | if (flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1410 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
| 1411 | else |
| 1412 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; |
| 1413 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1414 | if (old_tx_mode != tp->tx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1415 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1418 | static void tg3_adjust_link(struct net_device *dev) |
| 1419 | { |
| 1420 | u8 oldflowctrl, linkmesg = 0; |
| 1421 | u32 mac_mode, lcl_adv, rmt_adv; |
| 1422 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1423 | 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] | 1424 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1425 | spin_lock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1426 | |
| 1427 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | |
| 1428 | MAC_MODE_HALF_DUPLEX); |
| 1429 | |
| 1430 | oldflowctrl = tp->link_config.active_flowctrl; |
| 1431 | |
| 1432 | if (phydev->link) { |
| 1433 | lcl_adv = 0; |
| 1434 | rmt_adv = 0; |
| 1435 | |
| 1436 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) |
| 1437 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1438 | else if (phydev->speed == SPEED_1000 || |
| 1439 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1440 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1441 | else |
| 1442 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1443 | |
| 1444 | if (phydev->duplex == DUPLEX_HALF) |
| 1445 | mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 1446 | else { |
| 1447 | lcl_adv = tg3_advert_flowctrl_1000T( |
| 1448 | tp->link_config.flowctrl); |
| 1449 | |
| 1450 | if (phydev->pause) |
| 1451 | rmt_adv = LPA_PAUSE_CAP; |
| 1452 | if (phydev->asym_pause) |
| 1453 | rmt_adv |= LPA_PAUSE_ASYM; |
| 1454 | } |
| 1455 | |
| 1456 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 1457 | } else |
| 1458 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 1459 | |
| 1460 | if (mac_mode != tp->mac_mode) { |
| 1461 | tp->mac_mode = mac_mode; |
| 1462 | tw32_f(MAC_MODE, tp->mac_mode); |
| 1463 | udelay(40); |
| 1464 | } |
| 1465 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1466 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
| 1467 | if (phydev->speed == SPEED_10) |
| 1468 | tw32(MAC_MI_STAT, |
| 1469 | MAC_MI_STAT_10MBPS_MODE | |
| 1470 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1471 | else |
| 1472 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1473 | } |
| 1474 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1475 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
| 1476 | tw32(MAC_TX_LENGTHS, |
| 1477 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1478 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1479 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1480 | else |
| 1481 | tw32(MAC_TX_LENGTHS, |
| 1482 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1483 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1484 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1485 | |
| 1486 | if ((phydev->link && tp->link_config.active_speed == SPEED_INVALID) || |
| 1487 | (!phydev->link && tp->link_config.active_speed != SPEED_INVALID) || |
| 1488 | phydev->speed != tp->link_config.active_speed || |
| 1489 | phydev->duplex != tp->link_config.active_duplex || |
| 1490 | oldflowctrl != tp->link_config.active_flowctrl) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 1491 | linkmesg = 1; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1492 | |
| 1493 | tp->link_config.active_speed = phydev->speed; |
| 1494 | tp->link_config.active_duplex = phydev->duplex; |
| 1495 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1496 | spin_unlock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1497 | |
| 1498 | if (linkmesg) |
| 1499 | tg3_link_report(tp); |
| 1500 | } |
| 1501 | |
| 1502 | static int tg3_phy_init(struct tg3 *tp) |
| 1503 | { |
| 1504 | struct phy_device *phydev; |
| 1505 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1506 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1507 | return 0; |
| 1508 | |
| 1509 | /* Bring the PHY back to a known state. */ |
| 1510 | tg3_bmcr_reset(tp); |
| 1511 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1512 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1513 | |
| 1514 | /* Attach the MAC to the PHY. */ |
Kay Sievers | fb28ad3 | 2008-11-10 13:55:14 -0800 | [diff] [blame] | 1515 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link, |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1516 | phydev->dev_flags, phydev->interface); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1517 | if (IS_ERR(phydev)) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 1518 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1519 | return PTR_ERR(phydev); |
| 1520 | } |
| 1521 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1522 | /* Mask with MAC supported features. */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1523 | switch (phydev->interface) { |
| 1524 | case PHY_INTERFACE_MODE_GMII: |
| 1525 | case PHY_INTERFACE_MODE_RGMII: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1526 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1527 | phydev->supported &= (PHY_GBIT_FEATURES | |
| 1528 | SUPPORTED_Pause | |
| 1529 | SUPPORTED_Asym_Pause); |
| 1530 | break; |
| 1531 | } |
| 1532 | /* fallthru */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1533 | case PHY_INTERFACE_MODE_MII: |
| 1534 | phydev->supported &= (PHY_BASIC_FEATURES | |
| 1535 | SUPPORTED_Pause | |
| 1536 | SUPPORTED_Asym_Pause); |
| 1537 | break; |
| 1538 | default: |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1539 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1540 | return -EINVAL; |
| 1541 | } |
| 1542 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1543 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1544 | |
| 1545 | phydev->advertising = phydev->supported; |
| 1546 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1547 | return 0; |
| 1548 | } |
| 1549 | |
| 1550 | static void tg3_phy_start(struct tg3 *tp) |
| 1551 | { |
| 1552 | struct phy_device *phydev; |
| 1553 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1554 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1555 | return; |
| 1556 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1557 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1558 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 1559 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 1560 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1561 | phydev->speed = tp->link_config.orig_speed; |
| 1562 | phydev->duplex = tp->link_config.orig_duplex; |
| 1563 | phydev->autoneg = tp->link_config.orig_autoneg; |
| 1564 | phydev->advertising = tp->link_config.orig_advertising; |
| 1565 | } |
| 1566 | |
| 1567 | phy_start(phydev); |
| 1568 | |
| 1569 | phy_start_aneg(phydev); |
| 1570 | } |
| 1571 | |
| 1572 | static void tg3_phy_stop(struct tg3 *tp) |
| 1573 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1574 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1575 | return; |
| 1576 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1577 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | static void tg3_phy_fini(struct tg3 *tp) |
| 1581 | { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1582 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1583 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1584 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1585 | } |
| 1586 | } |
| 1587 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 1588 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) |
| 1589 | { |
| 1590 | int err; |
| 1591 | |
| 1592 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1593 | if (!err) |
| 1594 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1595 | |
| 1596 | return err; |
| 1597 | } |
| 1598 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 1599 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1600 | { |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 1601 | int err; |
| 1602 | |
| 1603 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1604 | if (!err) |
| 1605 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1606 | |
| 1607 | return err; |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1610 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
| 1611 | { |
| 1612 | u32 phytest; |
| 1613 | |
| 1614 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 1615 | u32 phy; |
| 1616 | |
| 1617 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 1618 | phytest | MII_TG3_FET_SHADOW_EN); |
| 1619 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { |
| 1620 | if (enable) |
| 1621 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1622 | else |
| 1623 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1624 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); |
| 1625 | } |
| 1626 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 1627 | } |
| 1628 | } |
| 1629 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1630 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
| 1631 | { |
| 1632 | u32 reg; |
| 1633 | |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 1634 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 1635 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 1636 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1637 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1638 | return; |
| 1639 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1640 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1641 | tg3_phy_fet_toggle_apd(tp, enable); |
| 1642 | return; |
| 1643 | } |
| 1644 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1645 | reg = MII_TG3_MISC_SHDW_WREN | |
| 1646 | MII_TG3_MISC_SHDW_SCR5_SEL | |
| 1647 | MII_TG3_MISC_SHDW_SCR5_LPED | |
| 1648 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | |
| 1649 | MII_TG3_MISC_SHDW_SCR5_SDTL | |
| 1650 | MII_TG3_MISC_SHDW_SCR5_C125OE; |
| 1651 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) |
| 1652 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
| 1653 | |
| 1654 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 1655 | |
| 1656 | |
| 1657 | reg = MII_TG3_MISC_SHDW_WREN | |
| 1658 | MII_TG3_MISC_SHDW_APD_SEL | |
| 1659 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; |
| 1660 | if (enable) |
| 1661 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; |
| 1662 | |
| 1663 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 1664 | } |
| 1665 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1666 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
| 1667 | { |
| 1668 | u32 phy; |
| 1669 | |
| 1670 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1671 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1672 | return; |
| 1673 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1674 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1675 | u32 ephy; |
| 1676 | |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1677 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
| 1678 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; |
| 1679 | |
| 1680 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 1681 | ephy | MII_TG3_FET_SHADOW_EN); |
| 1682 | if (!tg3_readphy(tp, reg, &phy)) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1683 | if (enable) |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1684 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1685 | else |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1686 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 1687 | tg3_writephy(tp, reg, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1688 | } |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1689 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1690 | } |
| 1691 | } else { |
| 1692 | phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC | |
| 1693 | MII_TG3_AUXCTL_SHDWSEL_MISC; |
| 1694 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) && |
| 1695 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) { |
| 1696 | if (enable) |
| 1697 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 1698 | else |
| 1699 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 1700 | phy |= MII_TG3_AUXCTL_MISC_WREN; |
| 1701 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); |
| 1702 | } |
| 1703 | } |
| 1704 | } |
| 1705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
| 1707 | { |
| 1708 | u32 val; |
| 1709 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 1710 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | return; |
| 1712 | |
| 1713 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) && |
| 1714 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val)) |
| 1715 | tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 1716 | (val | (1 << 15) | (1 << 4))); |
| 1717 | } |
| 1718 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1719 | static void tg3_phy_apply_otp(struct tg3 *tp) |
| 1720 | { |
| 1721 | u32 otp, phy; |
| 1722 | |
| 1723 | if (!tp->phy_otp) |
| 1724 | return; |
| 1725 | |
| 1726 | otp = tp->phy_otp; |
| 1727 | |
| 1728 | /* Enable SM_DSP clock and tx 6dB coding. */ |
| 1729 | phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | |
| 1730 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | |
| 1731 | MII_TG3_AUXCTL_ACTL_TX_6DB; |
| 1732 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); |
| 1733 | |
| 1734 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); |
| 1735 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; |
| 1736 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); |
| 1737 | |
| 1738 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | |
| 1739 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); |
| 1740 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); |
| 1741 | |
| 1742 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); |
| 1743 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; |
| 1744 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); |
| 1745 | |
| 1746 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); |
| 1747 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); |
| 1748 | |
| 1749 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); |
| 1750 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); |
| 1751 | |
| 1752 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | |
| 1753 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); |
| 1754 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); |
| 1755 | |
| 1756 | /* Turn off SM_DSP clock. */ |
| 1757 | phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | |
| 1758 | MII_TG3_AUXCTL_ACTL_TX_6DB; |
| 1759 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); |
| 1760 | } |
| 1761 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 1762 | static void tg3_phy_eee_adjust(struct tg3 *tp, u32 current_link_up) |
| 1763 | { |
| 1764 | u32 val; |
| 1765 | |
| 1766 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 1767 | return; |
| 1768 | |
| 1769 | tp->setlpicnt = 0; |
| 1770 | |
| 1771 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 1772 | current_link_up == 1 && |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame^] | 1773 | tp->link_config.active_duplex == DUPLEX_FULL && |
| 1774 | (tp->link_config.active_speed == SPEED_100 || |
| 1775 | tp->link_config.active_speed == SPEED_1000)) { |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 1776 | u32 eeectl; |
| 1777 | |
| 1778 | if (tp->link_config.active_speed == SPEED_1000) |
| 1779 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; |
| 1780 | else |
| 1781 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; |
| 1782 | |
| 1783 | tw32(TG3_CPMU_EEE_CTRL, eeectl); |
| 1784 | |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 1785 | tg3_phy_cl45_read(tp, MDIO_MMD_AN, |
| 1786 | TG3_CL45_D7_EEERES_STAT, &val); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 1787 | |
| 1788 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
| 1789 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) |
| 1790 | tp->setlpicnt = 2; |
| 1791 | } |
| 1792 | |
| 1793 | if (!tp->setlpicnt) { |
| 1794 | val = tr32(TG3_CPMU_EEE_MODE); |
| 1795 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 1796 | } |
| 1797 | } |
| 1798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | static int tg3_wait_macro_done(struct tg3 *tp) |
| 1800 | { |
| 1801 | int limit = 100; |
| 1802 | |
| 1803 | while (limit--) { |
| 1804 | u32 tmp32; |
| 1805 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1806 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | if ((tmp32 & 0x1000) == 0) |
| 1808 | break; |
| 1809 | } |
| 1810 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 1811 | if (limit < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | return -EBUSY; |
| 1813 | |
| 1814 | return 0; |
| 1815 | } |
| 1816 | |
| 1817 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) |
| 1818 | { |
| 1819 | static const u32 test_pat[4][6] = { |
| 1820 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, |
| 1821 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, |
| 1822 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, |
| 1823 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } |
| 1824 | }; |
| 1825 | int chan; |
| 1826 | |
| 1827 | for (chan = 0; chan < 4; chan++) { |
| 1828 | int i; |
| 1829 | |
| 1830 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1831 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1832 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | |
| 1834 | for (i = 0; i < 6; i++) |
| 1835 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, |
| 1836 | test_pat[chan][i]); |
| 1837 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1838 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | if (tg3_wait_macro_done(tp)) { |
| 1840 | *resetp = 1; |
| 1841 | return -EBUSY; |
| 1842 | } |
| 1843 | |
| 1844 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1845 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1846 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | if (tg3_wait_macro_done(tp)) { |
| 1848 | *resetp = 1; |
| 1849 | return -EBUSY; |
| 1850 | } |
| 1851 | |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1852 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | if (tg3_wait_macro_done(tp)) { |
| 1854 | *resetp = 1; |
| 1855 | return -EBUSY; |
| 1856 | } |
| 1857 | |
| 1858 | for (i = 0; i < 6; i += 2) { |
| 1859 | u32 low, high; |
| 1860 | |
| 1861 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || |
| 1862 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || |
| 1863 | tg3_wait_macro_done(tp)) { |
| 1864 | *resetp = 1; |
| 1865 | return -EBUSY; |
| 1866 | } |
| 1867 | low &= 0x7fff; |
| 1868 | high &= 0x000f; |
| 1869 | if (low != test_pat[chan][i] || |
| 1870 | high != test_pat[chan][i+1]) { |
| 1871 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); |
| 1872 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); |
| 1873 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); |
| 1874 | |
| 1875 | return -EBUSY; |
| 1876 | } |
| 1877 | } |
| 1878 | } |
| 1879 | |
| 1880 | return 0; |
| 1881 | } |
| 1882 | |
| 1883 | static int tg3_phy_reset_chanpat(struct tg3 *tp) |
| 1884 | { |
| 1885 | int chan; |
| 1886 | |
| 1887 | for (chan = 0; chan < 4; chan++) { |
| 1888 | int i; |
| 1889 | |
| 1890 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1891 | (chan * 0x2000) | 0x0200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1892 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | for (i = 0; i < 6; i++) |
| 1894 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1895 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | if (tg3_wait_macro_done(tp)) |
| 1897 | return -EBUSY; |
| 1898 | } |
| 1899 | |
| 1900 | return 0; |
| 1901 | } |
| 1902 | |
| 1903 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) |
| 1904 | { |
| 1905 | u32 reg32, phy9_orig; |
| 1906 | int retries, do_phy_reset, err; |
| 1907 | |
| 1908 | retries = 10; |
| 1909 | do_phy_reset = 1; |
| 1910 | do { |
| 1911 | if (do_phy_reset) { |
| 1912 | err = tg3_bmcr_reset(tp); |
| 1913 | if (err) |
| 1914 | return err; |
| 1915 | do_phy_reset = 0; |
| 1916 | } |
| 1917 | |
| 1918 | /* Disable transmitter and interrupt. */ |
| 1919 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) |
| 1920 | continue; |
| 1921 | |
| 1922 | reg32 |= 0x3000; |
| 1923 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 1924 | |
| 1925 | /* Set full-duplex, 1000 mbps. */ |
| 1926 | tg3_writephy(tp, MII_BMCR, |
| 1927 | BMCR_FULLDPLX | TG3_BMCR_SPEED1000); |
| 1928 | |
| 1929 | /* Set to master mode. */ |
| 1930 | if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig)) |
| 1931 | continue; |
| 1932 | |
| 1933 | tg3_writephy(tp, MII_TG3_CTRL, |
| 1934 | (MII_TG3_CTRL_AS_MASTER | |
| 1935 | MII_TG3_CTRL_ENABLE_AS_MASTER)); |
| 1936 | |
| 1937 | /* Enable SM_DSP_CLOCK and 6dB. */ |
| 1938 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
| 1939 | |
| 1940 | /* Block the PHY control access. */ |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 1941 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | |
| 1943 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); |
| 1944 | if (!err) |
| 1945 | break; |
| 1946 | } while (--retries); |
| 1947 | |
| 1948 | err = tg3_phy_reset_chanpat(tp); |
| 1949 | if (err) |
| 1950 | return err; |
| 1951 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 1952 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | |
| 1954 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 1955 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | |
| 1957 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 1958 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 1959 | /* Set Extended packet length bit for jumbo frames */ |
| 1960 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 1961 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
| 1963 | } |
| 1964 | |
| 1965 | tg3_writephy(tp, MII_TG3_CTRL, phy9_orig); |
| 1966 | |
| 1967 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { |
| 1968 | reg32 &= ~0x3000; |
| 1969 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 1970 | } else if (!err) |
| 1971 | err = -EBUSY; |
| 1972 | |
| 1973 | return err; |
| 1974 | } |
| 1975 | |
| 1976 | /* This will reset the tigon3 PHY if there is no valid |
| 1977 | * link unless the FORCE argument is non-zero. |
| 1978 | */ |
| 1979 | static int tg3_phy_reset(struct tg3 *tp) |
| 1980 | { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 1981 | u32 val, cpmuctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | int err; |
| 1983 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 1984 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 1985 | val = tr32(GRC_MISC_CFG); |
| 1986 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); |
| 1987 | udelay(40); |
| 1988 | } |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 1989 | err = tg3_readphy(tp, MII_BMSR, &val); |
| 1990 | err |= tg3_readphy(tp, MII_BMSR, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | if (err != 0) |
| 1992 | return -EBUSY; |
| 1993 | |
Michael Chan | c8e1e82 | 2006-04-29 18:55:17 -0700 | [diff] [blame] | 1994 | if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) { |
| 1995 | netif_carrier_off(tp->dev); |
| 1996 | tg3_link_report(tp); |
| 1997 | } |
| 1998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 2000 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2001 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 2002 | err = tg3_phy_reset_5703_4_5(tp); |
| 2003 | if (err) |
| 2004 | return err; |
| 2005 | goto out; |
| 2006 | } |
| 2007 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2008 | cpmuctrl = 0; |
| 2009 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 2010 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 2011 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
| 2012 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) |
| 2013 | tw32(TG3_CPMU_CTRL, |
| 2014 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); |
| 2015 | } |
| 2016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | err = tg3_bmcr_reset(tp); |
| 2018 | if (err) |
| 2019 | return err; |
| 2020 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2021 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2022 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
| 2023 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2024 | |
| 2025 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 2026 | } |
| 2027 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2028 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2029 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2030 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2031 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == |
| 2032 | CPMU_LSPD_1000MB_MACCLK_12_5) { |
| 2033 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2034 | udelay(40); |
| 2035 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2036 | } |
| 2037 | } |
| 2038 | |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 2039 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 2040 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2041 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 2042 | return 0; |
| 2043 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 2044 | tg3_phy_apply_otp(tp); |
| 2045 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2046 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 2047 | tg3_phy_toggle_apd(tp, true); |
| 2048 | else |
| 2049 | tg3_phy_toggle_apd(tp, false); |
| 2050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | out: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2052 | if (tp->phy_flags & TG3_PHYFLG_ADC_BUG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2054 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
| 2055 | tg3_phydsp_write(tp, 0x000a, 0x0323); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
| 2057 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2058 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 2059 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 2060 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2062 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 2064 | tg3_phydsp_write(tp, 0x000a, 0x310b); |
| 2065 | tg3_phydsp_write(tp, 0x201f, 0x9506); |
| 2066 | tg3_phydsp_write(tp, 0x401f, 0x14e2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2068 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 2069 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
| 2070 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2071 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 2072 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
| 2073 | tg3_writephy(tp, MII_TG3_TEST1, |
| 2074 | MII_TG3_TEST1_TRIM_EN | 0x4); |
| 2075 | } else |
| 2076 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 2077 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
| 2078 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | /* Set Extended packet length bit (bit 14) on all chips that */ |
| 2080 | /* support jumbo frames */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2081 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | /* Cannot do read-modify-write on 5401 */ |
| 2083 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20); |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 2084 | } else if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | /* Set bit 14 with read-modify-write to preserve other bits */ |
| 2086 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) && |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2087 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val)) |
| 2088 | tg3_writephy(tp, MII_TG3_AUX_CTRL, val | 0x4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support |
| 2092 | * jumbo frames transmission. |
| 2093 | */ |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 2094 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2095 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 2096 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 2097 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2100 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2101 | /* adjust output voltage */ |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2102 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2105 | tg3_phy_toggle_automdix(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | tg3_phy_set_wirespeed(tp); |
| 2107 | return 0; |
| 2108 | } |
| 2109 | |
| 2110 | static void tg3_frob_aux_power(struct tg3 *tp) |
| 2111 | { |
| 2112 | struct tg3 *tp_peer = tp; |
| 2113 | |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2114 | /* The GPIOs do something completely different on 57765. */ |
| 2115 | if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0 || |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 2116 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2117 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | return; |
| 2119 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 2120 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2121 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || |
| 2122 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2123 | struct net_device *dev_peer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2125 | dev_peer = pci_get_drvdata(tp->pdev_peer); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2126 | /* remove_one() may have been run on the peer. */ |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2127 | if (!dev_peer) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2128 | tp_peer = tp; |
| 2129 | else |
| 2130 | tp_peer = netdev_priv(dev_peer); |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2131 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | |
| 2133 | if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 || |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2134 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 || |
| 2135 | (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 || |
| 2136 | (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2138 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2139 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2140 | (GRC_LCLCTRL_GPIO_OE0 | |
| 2141 | GRC_LCLCTRL_GPIO_OE1 | |
| 2142 | GRC_LCLCTRL_GPIO_OE2 | |
| 2143 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2144 | GRC_LCLCTRL_GPIO_OUTPUT1), |
| 2145 | 100); |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 2146 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 2147 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 2148 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
| 2149 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | |
| 2150 | GRC_LCLCTRL_GPIO_OE1 | |
| 2151 | GRC_LCLCTRL_GPIO_OE2 | |
| 2152 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2153 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2154 | tp->grc_local_ctrl; |
| 2155 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
| 2156 | |
| 2157 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2158 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
| 2159 | |
| 2160 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2161 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | } else { |
| 2163 | u32 no_gpio2; |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2164 | u32 grc_local_ctrl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | |
| 2166 | if (tp_peer != tp && |
| 2167 | (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0) |
| 2168 | return; |
| 2169 | |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2170 | /* Workaround to prevent overdrawing Amps. */ |
| 2171 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 2172 | ASIC_REV_5714) { |
| 2173 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2174 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2175 | grc_local_ctrl, 100); |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2176 | } |
| 2177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | /* On 5753 and variants, GPIO2 cannot be used. */ |
| 2179 | no_gpio2 = tp->nic_sram_data_cfg & |
| 2180 | NIC_SRAM_DATA_CFG_NO_GPIO2; |
| 2181 | |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2182 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | GRC_LCLCTRL_GPIO_OE1 | |
| 2184 | GRC_LCLCTRL_GPIO_OE2 | |
| 2185 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2186 | GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2187 | if (no_gpio2) { |
| 2188 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | |
| 2189 | GRC_LCLCTRL_GPIO_OUTPUT2); |
| 2190 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2191 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2192 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | |
| 2194 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2195 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2196 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2197 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | |
| 2199 | if (!no_gpio2) { |
| 2200 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2201 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2202 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | } |
| 2204 | } |
| 2205 | } else { |
| 2206 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 2207 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
| 2208 | if (tp_peer != tp && |
| 2209 | (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0) |
| 2210 | return; |
| 2211 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2212 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2213 | (GRC_LCLCTRL_GPIO_OE1 | |
| 2214 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2216 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2217 | GRC_LCLCTRL_GPIO_OE1, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2219 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2220 | (GRC_LCLCTRL_GPIO_OE1 | |
| 2221 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2226 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
| 2227 | { |
| 2228 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) |
| 2229 | return 1; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2230 | 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] | 2231 | if (speed != SPEED_10) |
| 2232 | return 1; |
| 2233 | } else if (speed == SPEED_10) |
| 2234 | return 1; |
| 2235 | |
| 2236 | return 0; |
| 2237 | } |
| 2238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | static int tg3_setup_phy(struct tg3 *, int); |
| 2240 | |
| 2241 | #define RESET_KIND_SHUTDOWN 0 |
| 2242 | #define RESET_KIND_INIT 1 |
| 2243 | #define RESET_KIND_SUSPEND 2 |
| 2244 | |
| 2245 | static void tg3_write_sig_post_reset(struct tg3 *, int); |
| 2246 | static int tg3_halt_cpu(struct tg3 *, u32); |
| 2247 | |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2248 | 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] | 2249 | { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2250 | u32 val; |
| 2251 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2252 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2253 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2254 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 2255 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); |
| 2256 | |
| 2257 | sg_dig_ctrl |= |
| 2258 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; |
| 2259 | tw32(SG_DIG_CTRL, sg_dig_ctrl); |
| 2260 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); |
| 2261 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2262 | return; |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2263 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2264 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2265 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2266 | tg3_bmcr_reset(tp); |
| 2267 | val = tr32(GRC_MISC_CFG); |
| 2268 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); |
| 2269 | udelay(40); |
| 2270 | return; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2271 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 0e5f784 | 2009-11-02 14:26:38 +0000 | [diff] [blame] | 2272 | u32 phytest; |
| 2273 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2274 | u32 phy; |
| 2275 | |
| 2276 | tg3_writephy(tp, MII_ADVERTISE, 0); |
| 2277 | tg3_writephy(tp, MII_BMCR, |
| 2278 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 2279 | |
| 2280 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2281 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2282 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { |
| 2283 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; |
| 2284 | tg3_writephy(tp, |
| 2285 | MII_TG3_FET_SHDW_AUXMODE4, |
| 2286 | phy); |
| 2287 | } |
| 2288 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2289 | } |
| 2290 | return; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2291 | } else if (do_low_power) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2292 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 2293 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2294 | |
| 2295 | tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 2296 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL | |
| 2297 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 2298 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | |
| 2299 | MII_TG3_AUXCTL_PCTL_VREG_11V); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2300 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2301 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2302 | /* The PHY should not be powered down on some chips because |
| 2303 | * of bugs. |
| 2304 | */ |
| 2305 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2306 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2307 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2308 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2309 | return; |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2310 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2311 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2312 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2313 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2314 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2315 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; |
| 2316 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2317 | } |
| 2318 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2319 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 2320 | } |
| 2321 | |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2322 | /* tp->lock is held. */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2323 | static int tg3_nvram_lock(struct tg3 *tp) |
| 2324 | { |
| 2325 | if (tp->tg3_flags & TG3_FLAG_NVRAM) { |
| 2326 | int i; |
| 2327 | |
| 2328 | if (tp->nvram_lock_cnt == 0) { |
| 2329 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); |
| 2330 | for (i = 0; i < 8000; i++) { |
| 2331 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) |
| 2332 | break; |
| 2333 | udelay(20); |
| 2334 | } |
| 2335 | if (i == 8000) { |
| 2336 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2337 | return -ENODEV; |
| 2338 | } |
| 2339 | } |
| 2340 | tp->nvram_lock_cnt++; |
| 2341 | } |
| 2342 | return 0; |
| 2343 | } |
| 2344 | |
| 2345 | /* tp->lock is held. */ |
| 2346 | static void tg3_nvram_unlock(struct tg3 *tp) |
| 2347 | { |
| 2348 | if (tp->tg3_flags & TG3_FLAG_NVRAM) { |
| 2349 | if (tp->nvram_lock_cnt > 0) |
| 2350 | tp->nvram_lock_cnt--; |
| 2351 | if (tp->nvram_lock_cnt == 0) |
| 2352 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | /* tp->lock is held. */ |
| 2357 | static void tg3_enable_nvram_access(struct tg3 *tp) |
| 2358 | { |
| 2359 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 2360 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2361 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2362 | |
| 2363 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); |
| 2364 | } |
| 2365 | } |
| 2366 | |
| 2367 | /* tp->lock is held. */ |
| 2368 | static void tg3_disable_nvram_access(struct tg3 *tp) |
| 2369 | { |
| 2370 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 2371 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2372 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2373 | |
| 2374 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, |
| 2379 | u32 offset, u32 *val) |
| 2380 | { |
| 2381 | u32 tmp; |
| 2382 | int i; |
| 2383 | |
| 2384 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) |
| 2385 | return -EINVAL; |
| 2386 | |
| 2387 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | |
| 2388 | EEPROM_ADDR_DEVID_MASK | |
| 2389 | EEPROM_ADDR_READ); |
| 2390 | tw32(GRC_EEPROM_ADDR, |
| 2391 | tmp | |
| 2392 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 2393 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & |
| 2394 | EEPROM_ADDR_ADDR_MASK) | |
| 2395 | EEPROM_ADDR_READ | EEPROM_ADDR_START); |
| 2396 | |
| 2397 | for (i = 0; i < 1000; i++) { |
| 2398 | tmp = tr32(GRC_EEPROM_ADDR); |
| 2399 | |
| 2400 | if (tmp & EEPROM_ADDR_COMPLETE) |
| 2401 | break; |
| 2402 | msleep(1); |
| 2403 | } |
| 2404 | if (!(tmp & EEPROM_ADDR_COMPLETE)) |
| 2405 | return -EBUSY; |
| 2406 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 2407 | tmp = tr32(GRC_EEPROM_DATA); |
| 2408 | |
| 2409 | /* |
| 2410 | * The data will always be opposite the native endian |
| 2411 | * format. Perform a blind byteswap to compensate. |
| 2412 | */ |
| 2413 | *val = swab32(tmp); |
| 2414 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2415 | return 0; |
| 2416 | } |
| 2417 | |
| 2418 | #define NVRAM_CMD_TIMEOUT 10000 |
| 2419 | |
| 2420 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) |
| 2421 | { |
| 2422 | int i; |
| 2423 | |
| 2424 | tw32(NVRAM_CMD, nvram_cmd); |
| 2425 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { |
| 2426 | udelay(10); |
| 2427 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { |
| 2428 | udelay(10); |
| 2429 | break; |
| 2430 | } |
| 2431 | } |
| 2432 | |
| 2433 | if (i == NVRAM_CMD_TIMEOUT) |
| 2434 | return -EBUSY; |
| 2435 | |
| 2436 | return 0; |
| 2437 | } |
| 2438 | |
| 2439 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) |
| 2440 | { |
| 2441 | if ((tp->tg3_flags & TG3_FLAG_NVRAM) && |
| 2442 | (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) && |
| 2443 | (tp->tg3_flags2 & TG3_FLG2_FLASH) && |
| 2444 | !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) && |
| 2445 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2446 | |
| 2447 | addr = ((addr / tp->nvram_pagesize) << |
| 2448 | ATMEL_AT45DB0X1B_PAGE_POS) + |
| 2449 | (addr % tp->nvram_pagesize); |
| 2450 | |
| 2451 | return addr; |
| 2452 | } |
| 2453 | |
| 2454 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) |
| 2455 | { |
| 2456 | if ((tp->tg3_flags & TG3_FLAG_NVRAM) && |
| 2457 | (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) && |
| 2458 | (tp->tg3_flags2 & TG3_FLG2_FLASH) && |
| 2459 | !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) && |
| 2460 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2461 | |
| 2462 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * |
| 2463 | tp->nvram_pagesize) + |
| 2464 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); |
| 2465 | |
| 2466 | return addr; |
| 2467 | } |
| 2468 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2469 | /* NOTE: Data read in from NVRAM is byteswapped according to |
| 2470 | * the byteswapping settings for all other register accesses. |
| 2471 | * tg3 devices are BE devices, so on a BE machine, the data |
| 2472 | * returned will be exactly as it is seen in NVRAM. On a LE |
| 2473 | * machine, the 32-bit value will be byteswapped. |
| 2474 | */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2475 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
| 2476 | { |
| 2477 | int ret; |
| 2478 | |
| 2479 | if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) |
| 2480 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
| 2481 | |
| 2482 | offset = tg3_nvram_phys_addr(tp, offset); |
| 2483 | |
| 2484 | if (offset > NVRAM_ADDR_MSK) |
| 2485 | return -EINVAL; |
| 2486 | |
| 2487 | ret = tg3_nvram_lock(tp); |
| 2488 | if (ret) |
| 2489 | return ret; |
| 2490 | |
| 2491 | tg3_enable_nvram_access(tp); |
| 2492 | |
| 2493 | tw32(NVRAM_ADDR, offset); |
| 2494 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | |
| 2495 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); |
| 2496 | |
| 2497 | if (ret == 0) |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2498 | *val = tr32(NVRAM_RDDATA); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2499 | |
| 2500 | tg3_disable_nvram_access(tp); |
| 2501 | |
| 2502 | tg3_nvram_unlock(tp); |
| 2503 | |
| 2504 | return ret; |
| 2505 | } |
| 2506 | |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2507 | /* Ensures NVRAM data is in bytestream format. */ |
| 2508 | 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] | 2509 | { |
| 2510 | u32 v; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2511 | int res = tg3_nvram_read(tp, offset, &v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2512 | if (!res) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2513 | *val = cpu_to_be32(v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2514 | return res; |
| 2515 | } |
| 2516 | |
| 2517 | /* tp->lock is held. */ |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2518 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) |
| 2519 | { |
| 2520 | u32 addr_high, addr_low; |
| 2521 | int i; |
| 2522 | |
| 2523 | addr_high = ((tp->dev->dev_addr[0] << 8) | |
| 2524 | tp->dev->dev_addr[1]); |
| 2525 | addr_low = ((tp->dev->dev_addr[2] << 24) | |
| 2526 | (tp->dev->dev_addr[3] << 16) | |
| 2527 | (tp->dev->dev_addr[4] << 8) | |
| 2528 | (tp->dev->dev_addr[5] << 0)); |
| 2529 | for (i = 0; i < 4; i++) { |
| 2530 | if (i == 1 && skip_mac_1) |
| 2531 | continue; |
| 2532 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); |
| 2533 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); |
| 2534 | } |
| 2535 | |
| 2536 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 2537 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2538 | for (i = 0; i < 12; i++) { |
| 2539 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); |
| 2540 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); |
| 2541 | } |
| 2542 | } |
| 2543 | |
| 2544 | addr_high = (tp->dev->dev_addr[0] + |
| 2545 | tp->dev->dev_addr[1] + |
| 2546 | tp->dev->dev_addr[2] + |
| 2547 | tp->dev->dev_addr[3] + |
| 2548 | tp->dev->dev_addr[4] + |
| 2549 | tp->dev->dev_addr[5]) & |
| 2550 | TX_BACKOFF_SEED_MASK; |
| 2551 | tw32(MAC_TX_BACKOFF_SEED, addr_high); |
| 2552 | } |
| 2553 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2554 | 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] | 2555 | { |
| 2556 | u32 misc_host_ctrl; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2557 | bool device_should_wake, do_low_power; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | |
| 2559 | /* Make sure register accesses (indirect or otherwise) |
| 2560 | * will function correctly. |
| 2561 | */ |
| 2562 | pci_write_config_dword(tp->pdev, |
| 2563 | TG3PCI_MISC_HOST_CTRL, |
| 2564 | tp->misc_host_ctrl); |
| 2565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | switch (state) { |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2567 | case PCI_D0: |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 2568 | pci_enable_wake(tp->pdev, state, false); |
| 2569 | pci_set_power_state(tp->pdev, PCI_D0); |
Michael Chan | 8c6bda1 | 2005-04-21 17:09:08 -0700 | [diff] [blame] | 2570 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 2571 | /* Switch out of Vaux if it is a NIC */ |
| 2572 | if (tp->tg3_flags2 & TG3_FLG2_IS_NIC) |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2573 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | |
| 2575 | return 0; |
| 2576 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2577 | case PCI_D1: |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2578 | case PCI_D2: |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2579 | case PCI_D3hot: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | break; |
| 2581 | |
| 2582 | default: |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 2583 | netdev_err(tp->dev, "Invalid power state (D%d) requested\n", |
| 2584 | state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 2586 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 2587 | |
| 2588 | /* Restore the CLKREQ setting. */ |
| 2589 | if (tp->tg3_flags3 & TG3_FLG3_CLKREQ_BUG) { |
| 2590 | u16 lnkctl; |
| 2591 | |
| 2592 | pci_read_config_word(tp->pdev, |
| 2593 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 2594 | &lnkctl); |
| 2595 | lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 2596 | pci_write_config_word(tp->pdev, |
| 2597 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 2598 | lnkctl); |
| 2599 | } |
| 2600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 2602 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 2603 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); |
| 2604 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2605 | device_should_wake = pci_pme_capable(tp->pdev, state) && |
| 2606 | device_may_wakeup(&tp->pdev->dev) && |
| 2607 | (tp->tg3_flags & TG3_FLAG_WOL_ENABLE); |
| 2608 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2609 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2610 | do_low_power = false; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2611 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2612 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2613 | struct phy_device *phydev; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2614 | u32 phyid, advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2615 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2616 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2617 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2618 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2619 | |
| 2620 | tp->link_config.orig_speed = phydev->speed; |
| 2621 | tp->link_config.orig_duplex = phydev->duplex; |
| 2622 | tp->link_config.orig_autoneg = phydev->autoneg; |
| 2623 | tp->link_config.orig_advertising = phydev->advertising; |
| 2624 | |
| 2625 | advertising = ADVERTISED_TP | |
| 2626 | ADVERTISED_Pause | |
| 2627 | ADVERTISED_Autoneg | |
| 2628 | ADVERTISED_10baseT_Half; |
| 2629 | |
| 2630 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2631 | device_should_wake) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2632 | if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) |
| 2633 | advertising |= |
| 2634 | ADVERTISED_100baseT_Half | |
| 2635 | ADVERTISED_100baseT_Full | |
| 2636 | ADVERTISED_10baseT_Full; |
| 2637 | else |
| 2638 | advertising |= ADVERTISED_10baseT_Full; |
| 2639 | } |
| 2640 | |
| 2641 | phydev->advertising = advertising; |
| 2642 | |
| 2643 | phy_start_aneg(phydev); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2644 | |
| 2645 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 2646 | if (phyid != PHY_ID_BCMAC131) { |
| 2647 | phyid &= PHY_BCM_OUI_MASK; |
| 2648 | if (phyid == PHY_BCM_OUI_1 || |
| 2649 | phyid == PHY_BCM_OUI_2 || |
| 2650 | phyid == PHY_BCM_OUI_3) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2651 | do_low_power = true; |
| 2652 | } |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2653 | } |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2654 | } else { |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 2655 | do_low_power = true; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2656 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 2657 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 2658 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2659 | tp->link_config.orig_speed = tp->link_config.speed; |
| 2660 | tp->link_config.orig_duplex = tp->link_config.duplex; |
| 2661 | tp->link_config.orig_autoneg = tp->link_config.autoneg; |
| 2662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2664 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2665 | tp->link_config.speed = SPEED_10; |
| 2666 | tp->link_config.duplex = DUPLEX_HALF; |
| 2667 | tp->link_config.autoneg = AUTONEG_ENABLE; |
| 2668 | tg3_setup_phy(tp, 0); |
| 2669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 2672 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 2673 | u32 val; |
| 2674 | |
| 2675 | val = tr32(GRC_VCPU_EXT_CTRL); |
| 2676 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); |
| 2677 | } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2678 | int i; |
| 2679 | u32 val; |
| 2680 | |
| 2681 | for (i = 0; i < 200; i++) { |
| 2682 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); |
| 2683 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 2684 | break; |
| 2685 | msleep(1); |
| 2686 | } |
| 2687 | } |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 2688 | if (tp->tg3_flags & TG3_FLAG_WOL_CAP) |
| 2689 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
| 2690 | WOL_DRV_STATE_SHUTDOWN | |
| 2691 | WOL_DRV_WOL | |
| 2692 | WOL_SET_MAGIC_PKT); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2693 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2694 | if (device_should_wake) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | u32 mac_mode; |
| 2696 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2697 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2698 | if (do_low_power) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2699 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a); |
| 2700 | udelay(40); |
| 2701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 2703 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2704 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 2705 | else |
| 2706 | mac_mode = MAC_MODE_PORT_MODE_MII; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2708 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
| 2709 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 2710 | ASIC_REV_5700) { |
| 2711 | u32 speed = (tp->tg3_flags & |
| 2712 | TG3_FLAG_WOL_SPEED_100MB) ? |
| 2713 | SPEED_100 : SPEED_10; |
| 2714 | if (tg3_5700_link_polarity(tp, speed)) |
| 2715 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 2716 | else |
| 2717 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 2718 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | } else { |
| 2720 | mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 2721 | } |
| 2722 | |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 2723 | if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 2725 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2726 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
| 2727 | if (((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
| 2728 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) && |
| 2729 | ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
| 2730 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))) |
| 2731 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 2733 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 2734 | mac_mode |= MAC_MODE_APE_TX_EN | |
| 2735 | MAC_MODE_APE_RX_EN | |
| 2736 | MAC_MODE_TDE_ENABLE; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 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) { |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame^] | 2972 | u32 val; |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 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 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame^] | 2989 | val = 0; |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2990 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 2991 | /* Advertise 100-BaseTX EEE ability */ |
| 2992 | if (tp->link_config.advertising & |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 2993 | ADVERTISED_100baseT_Full) |
| 2994 | val |= MDIO_AN_EEE_ADV_100TX; |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2995 | /* Advertise 1000-BaseT EEE ability */ |
| 2996 | if (tp->link_config.advertising & |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 2997 | ADVERTISED_1000baseT_Full) |
| 2998 | val |= MDIO_AN_EEE_ADV_1000T; |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 2999 | } |
Matt Carlson | 3110f5f5 | 2010-12-06 08:28:50 +0000 | [diff] [blame] | 3000 | tg3_phy_cl45_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, val); |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3001 | |
| 3002 | /* Turn off SM_DSP clock. */ |
| 3003 | val = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | |
| 3004 | MII_TG3_AUXCTL_ACTL_TX_6DB; |
| 3005 | tg3_writephy(tp, MII_TG3_AUX_CTRL, val); |
| 3006 | } |
| 3007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | if (tp->link_config.autoneg == AUTONEG_DISABLE && |
| 3009 | tp->link_config.speed != SPEED_INVALID) { |
| 3010 | u32 bmcr, orig_bmcr; |
| 3011 | |
| 3012 | tp->link_config.active_speed = tp->link_config.speed; |
| 3013 | tp->link_config.active_duplex = tp->link_config.duplex; |
| 3014 | |
| 3015 | bmcr = 0; |
| 3016 | switch (tp->link_config.speed) { |
| 3017 | default: |
| 3018 | case SPEED_10: |
| 3019 | break; |
| 3020 | |
| 3021 | case SPEED_100: |
| 3022 | bmcr |= BMCR_SPEED100; |
| 3023 | break; |
| 3024 | |
| 3025 | case SPEED_1000: |
| 3026 | bmcr |= TG3_BMCR_SPEED1000; |
| 3027 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | |
| 3030 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 3031 | bmcr |= BMCR_FULLDPLX; |
| 3032 | |
| 3033 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && |
| 3034 | (bmcr != orig_bmcr)) { |
| 3035 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); |
| 3036 | for (i = 0; i < 1500; i++) { |
| 3037 | u32 tmp; |
| 3038 | |
| 3039 | udelay(10); |
| 3040 | if (tg3_readphy(tp, MII_BMSR, &tmp) || |
| 3041 | tg3_readphy(tp, MII_BMSR, &tmp)) |
| 3042 | continue; |
| 3043 | if (!(tmp & BMSR_LSTATUS)) { |
| 3044 | udelay(40); |
| 3045 | break; |
| 3046 | } |
| 3047 | } |
| 3048 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 3049 | udelay(40); |
| 3050 | } |
| 3051 | } else { |
| 3052 | tg3_writephy(tp, MII_BMCR, |
| 3053 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | static int tg3_init_5401phy_dsp(struct tg3 *tp) |
| 3058 | { |
| 3059 | int err; |
| 3060 | |
| 3061 | /* Turn off tap power management. */ |
| 3062 | /* Set Extended packet length bit */ |
| 3063 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20); |
| 3064 | |
Matt Carlson | 6ee7c0a | 2010-08-02 11:26:04 +0000 | [diff] [blame] | 3065 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
| 3066 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); |
| 3067 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); |
| 3068 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); |
| 3069 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | |
| 3071 | udelay(40); |
| 3072 | |
| 3073 | return err; |
| 3074 | } |
| 3075 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 3076 | static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | { |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 3078 | u32 adv_reg, all_mask = 0; |
| 3079 | |
| 3080 | if (mask & ADVERTISED_10baseT_Half) |
| 3081 | all_mask |= ADVERTISE_10HALF; |
| 3082 | if (mask & ADVERTISED_10baseT_Full) |
| 3083 | all_mask |= ADVERTISE_10FULL; |
| 3084 | if (mask & ADVERTISED_100baseT_Half) |
| 3085 | all_mask |= ADVERTISE_100HALF; |
| 3086 | if (mask & ADVERTISED_100baseT_Full) |
| 3087 | all_mask |= ADVERTISE_100FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | |
| 3089 | if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg)) |
| 3090 | return 0; |
| 3091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | if ((adv_reg & all_mask) != all_mask) |
| 3093 | return 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3094 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | u32 tg3_ctrl; |
| 3096 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 3097 | all_mask = 0; |
| 3098 | if (mask & ADVERTISED_1000baseT_Half) |
| 3099 | all_mask |= ADVERTISE_1000HALF; |
| 3100 | if (mask & ADVERTISED_1000baseT_Full) |
| 3101 | all_mask |= ADVERTISE_1000FULL; |
| 3102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl)) |
| 3104 | return 0; |
| 3105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | if ((tg3_ctrl & all_mask) != all_mask) |
| 3107 | return 0; |
| 3108 | } |
| 3109 | return 1; |
| 3110 | } |
| 3111 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3112 | static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv) |
| 3113 | { |
| 3114 | u32 curadv, reqadv; |
| 3115 | |
| 3116 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
| 3117 | return 1; |
| 3118 | |
| 3119 | curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
| 3120 | reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); |
| 3121 | |
| 3122 | if (tp->link_config.active_duplex == DUPLEX_FULL) { |
| 3123 | if (curadv != reqadv) |
| 3124 | return 0; |
| 3125 | |
| 3126 | if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) |
| 3127 | tg3_readphy(tp, MII_LPA, rmtadv); |
| 3128 | } else { |
| 3129 | /* Reprogram the advertisement register, even if it |
| 3130 | * does not affect the current link. If the link |
| 3131 | * gets renegotiated in the future, we can save an |
| 3132 | * additional renegotiation cycle by advertising |
| 3133 | * it correctly in the first place. |
| 3134 | */ |
| 3135 | if (curadv != reqadv) { |
| 3136 | *lcladv &= ~(ADVERTISE_PAUSE_CAP | |
| 3137 | ADVERTISE_PAUSE_ASYM); |
| 3138 | tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv); |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | return 1; |
| 3143 | } |
| 3144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
| 3146 | { |
| 3147 | int current_link_up; |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 3148 | u32 bmsr, val; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3149 | u32 lcl_adv, rmt_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | u16 current_speed; |
| 3151 | u8 current_duplex; |
| 3152 | int i, err; |
| 3153 | |
| 3154 | tw32(MAC_EVENT, 0); |
| 3155 | |
| 3156 | tw32_f(MAC_STATUS, |
| 3157 | (MAC_STATUS_SYNC_CHANGED | |
| 3158 | MAC_STATUS_CFG_CHANGED | |
| 3159 | MAC_STATUS_MI_COMPLETION | |
| 3160 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 3161 | udelay(40); |
| 3162 | |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 3163 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 3164 | tw32_f(MAC_MI_MODE, |
| 3165 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 3166 | udelay(80); |
| 3167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | |
| 3169 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02); |
| 3170 | |
| 3171 | /* Some third-party PHYs need to be reset on link going |
| 3172 | * down. |
| 3173 | */ |
| 3174 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 3175 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 3176 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
| 3177 | netif_carrier_ok(tp->dev)) { |
| 3178 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3179 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3180 | !(bmsr & BMSR_LSTATUS)) |
| 3181 | force_reset = 1; |
| 3182 | } |
| 3183 | if (force_reset) |
| 3184 | tg3_phy_reset(tp); |
| 3185 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3186 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3188 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || |
| 3189 | !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) |
| 3190 | bmsr = 0; |
| 3191 | |
| 3192 | if (!(bmsr & BMSR_LSTATUS)) { |
| 3193 | err = tg3_init_5401phy_dsp(tp); |
| 3194 | if (err) |
| 3195 | return err; |
| 3196 | |
| 3197 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3198 | for (i = 0; i < 1000; i++) { |
| 3199 | udelay(10); |
| 3200 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3201 | (bmsr & BMSR_LSTATUS)) { |
| 3202 | udelay(40); |
| 3203 | break; |
| 3204 | } |
| 3205 | } |
| 3206 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3207 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
| 3208 | TG3_PHY_REV_BCM5401_B0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | !(bmsr & BMSR_LSTATUS) && |
| 3210 | tp->link_config.active_speed == SPEED_1000) { |
| 3211 | err = tg3_phy_reset(tp); |
| 3212 | if (!err) |
| 3213 | err = tg3_init_5401phy_dsp(tp); |
| 3214 | if (err) |
| 3215 | return err; |
| 3216 | } |
| 3217 | } |
| 3218 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 3219 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { |
| 3220 | /* 5701 {A0,B0} CRC bug workaround */ |
| 3221 | tg3_writephy(tp, 0x15, 0x0a75); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 3222 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
| 3223 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 3224 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | /* Clear pending interrupts... */ |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 3228 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
| 3229 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3231 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3233 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
| 3235 | |
| 3236 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3237 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3238 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
| 3239 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 3240 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 3241 | else |
| 3242 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); |
| 3243 | } |
| 3244 | |
| 3245 | current_link_up = 0; |
| 3246 | current_speed = SPEED_INVALID; |
| 3247 | current_duplex = DUPLEX_INVALID; |
| 3248 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3249 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007); |
| 3251 | tg3_readphy(tp, MII_TG3_AUX_CTRL, &val); |
| 3252 | if (!(val & (1 << 10))) { |
| 3253 | val |= (1 << 10); |
| 3254 | tg3_writephy(tp, MII_TG3_AUX_CTRL, val); |
| 3255 | goto relink; |
| 3256 | } |
| 3257 | } |
| 3258 | |
| 3259 | bmsr = 0; |
| 3260 | for (i = 0; i < 100; i++) { |
| 3261 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3262 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3263 | (bmsr & BMSR_LSTATUS)) |
| 3264 | break; |
| 3265 | udelay(40); |
| 3266 | } |
| 3267 | |
| 3268 | if (bmsr & BMSR_LSTATUS) { |
| 3269 | u32 aux_stat, bmcr; |
| 3270 | |
| 3271 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); |
| 3272 | for (i = 0; i < 2000; i++) { |
| 3273 | udelay(10); |
| 3274 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && |
| 3275 | aux_stat) |
| 3276 | break; |
| 3277 | } |
| 3278 | |
| 3279 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, |
| 3280 | ¤t_speed, |
| 3281 | ¤t_duplex); |
| 3282 | |
| 3283 | bmcr = 0; |
| 3284 | for (i = 0; i < 200; i++) { |
| 3285 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 3286 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) |
| 3287 | continue; |
| 3288 | if (bmcr && bmcr != 0x7fff) |
| 3289 | break; |
| 3290 | udelay(10); |
| 3291 | } |
| 3292 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3293 | lcl_adv = 0; |
| 3294 | rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3296 | tp->link_config.active_speed = current_speed; |
| 3297 | tp->link_config.active_duplex = current_duplex; |
| 3298 | |
| 3299 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 3300 | if ((bmcr & BMCR_ANENABLE) && |
| 3301 | tg3_copper_is_advertising_all(tp, |
| 3302 | tp->link_config.advertising)) { |
| 3303 | if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv, |
| 3304 | &rmt_adv)) |
| 3305 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | } |
| 3307 | } else { |
| 3308 | if (!(bmcr & BMCR_ANENABLE) && |
| 3309 | tp->link_config.speed == current_speed && |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3310 | tp->link_config.duplex == current_duplex && |
| 3311 | tp->link_config.flowctrl == |
| 3312 | tp->link_config.active_flowctrl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | } |
| 3315 | } |
| 3316 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3317 | if (current_link_up == 1 && |
| 3318 | tp->link_config.active_duplex == DUPLEX_FULL) |
| 3319 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | relink: |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 3323 | 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] | 3324 | tg3_phy_copper_begin(tp); |
| 3325 | |
Matt Carlson | f833c4c | 2010-09-15 09:00:01 +0000 | [diff] [blame] | 3326 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3327 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3328 | (bmsr & BMSR_LSTATUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | current_link_up = 1; |
| 3330 | } |
| 3331 | |
| 3332 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 3333 | if (current_link_up == 1) { |
| 3334 | if (tp->link_config.active_speed == SPEED_100 || |
| 3335 | tp->link_config.active_speed == SPEED_10) |
| 3336 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 3337 | else |
| 3338 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3339 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 3340 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 3341 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 3343 | |
| 3344 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 3345 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 3346 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 3347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3349 | if (current_link_up == 1 && |
| 3350 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3352 | else |
| 3353 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | /* ??? Without this setting Netgear GA302T PHY does not |
| 3357 | * ??? send/receive packets... |
| 3358 | */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3359 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
| 3361 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
| 3362 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 3363 | udelay(80); |
| 3364 | } |
| 3365 | |
| 3366 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3367 | udelay(40); |
| 3368 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 3369 | tg3_phy_eee_adjust(tp, current_link_up); |
| 3370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) { |
| 3372 | /* Polled via timer. */ |
| 3373 | tw32_f(MAC_EVENT, 0); |
| 3374 | } else { |
| 3375 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 3376 | } |
| 3377 | udelay(40); |
| 3378 | |
| 3379 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && |
| 3380 | current_link_up == 1 && |
| 3381 | tp->link_config.active_speed == SPEED_1000 && |
| 3382 | ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) || |
| 3383 | (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) { |
| 3384 | udelay(120); |
| 3385 | tw32_f(MAC_STATUS, |
| 3386 | (MAC_STATUS_SYNC_CHANGED | |
| 3387 | MAC_STATUS_CFG_CHANGED)); |
| 3388 | udelay(40); |
| 3389 | tg3_write_mem(tp, |
| 3390 | NIC_SRAM_FIRMWARE_MBOX, |
| 3391 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); |
| 3392 | } |
| 3393 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3394 | /* Prevent send BD corruption. */ |
| 3395 | if (tp->tg3_flags3 & TG3_FLG3_CLKREQ_BUG) { |
| 3396 | u16 oldlnkctl, newlnkctl; |
| 3397 | |
| 3398 | pci_read_config_word(tp->pdev, |
| 3399 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 3400 | &oldlnkctl); |
| 3401 | if (tp->link_config.active_speed == SPEED_100 || |
| 3402 | tp->link_config.active_speed == SPEED_10) |
| 3403 | newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3404 | else |
| 3405 | newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3406 | if (newlnkctl != oldlnkctl) |
| 3407 | pci_write_config_word(tp->pdev, |
| 3408 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 3409 | newlnkctl); |
| 3410 | } |
| 3411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 3413 | if (current_link_up) |
| 3414 | netif_carrier_on(tp->dev); |
| 3415 | else |
| 3416 | netif_carrier_off(tp->dev); |
| 3417 | tg3_link_report(tp); |
| 3418 | } |
| 3419 | |
| 3420 | return 0; |
| 3421 | } |
| 3422 | |
| 3423 | struct tg3_fiber_aneginfo { |
| 3424 | int state; |
| 3425 | #define ANEG_STATE_UNKNOWN 0 |
| 3426 | #define ANEG_STATE_AN_ENABLE 1 |
| 3427 | #define ANEG_STATE_RESTART_INIT 2 |
| 3428 | #define ANEG_STATE_RESTART 3 |
| 3429 | #define ANEG_STATE_DISABLE_LINK_OK 4 |
| 3430 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 |
| 3431 | #define ANEG_STATE_ABILITY_DETECT 6 |
| 3432 | #define ANEG_STATE_ACK_DETECT_INIT 7 |
| 3433 | #define ANEG_STATE_ACK_DETECT 8 |
| 3434 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 |
| 3435 | #define ANEG_STATE_COMPLETE_ACK 10 |
| 3436 | #define ANEG_STATE_IDLE_DETECT_INIT 11 |
| 3437 | #define ANEG_STATE_IDLE_DETECT 12 |
| 3438 | #define ANEG_STATE_LINK_OK 13 |
| 3439 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 |
| 3440 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 |
| 3441 | |
| 3442 | u32 flags; |
| 3443 | #define MR_AN_ENABLE 0x00000001 |
| 3444 | #define MR_RESTART_AN 0x00000002 |
| 3445 | #define MR_AN_COMPLETE 0x00000004 |
| 3446 | #define MR_PAGE_RX 0x00000008 |
| 3447 | #define MR_NP_LOADED 0x00000010 |
| 3448 | #define MR_TOGGLE_TX 0x00000020 |
| 3449 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 |
| 3450 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 |
| 3451 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 |
| 3452 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 |
| 3453 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 |
| 3454 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 |
| 3455 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 |
| 3456 | #define MR_TOGGLE_RX 0x00002000 |
| 3457 | #define MR_NP_RX 0x00004000 |
| 3458 | |
| 3459 | #define MR_LINK_OK 0x80000000 |
| 3460 | |
| 3461 | unsigned long link_time, cur_time; |
| 3462 | |
| 3463 | u32 ability_match_cfg; |
| 3464 | int ability_match_count; |
| 3465 | |
| 3466 | char ability_match, idle_match, ack_match; |
| 3467 | |
| 3468 | u32 txconfig, rxconfig; |
| 3469 | #define ANEG_CFG_NP 0x00000080 |
| 3470 | #define ANEG_CFG_ACK 0x00000040 |
| 3471 | #define ANEG_CFG_RF2 0x00000020 |
| 3472 | #define ANEG_CFG_RF1 0x00000010 |
| 3473 | #define ANEG_CFG_PS2 0x00000001 |
| 3474 | #define ANEG_CFG_PS1 0x00008000 |
| 3475 | #define ANEG_CFG_HD 0x00004000 |
| 3476 | #define ANEG_CFG_FD 0x00002000 |
| 3477 | #define ANEG_CFG_INVAL 0x00001f06 |
| 3478 | |
| 3479 | }; |
| 3480 | #define ANEG_OK 0 |
| 3481 | #define ANEG_DONE 1 |
| 3482 | #define ANEG_TIMER_ENAB 2 |
| 3483 | #define ANEG_FAILED -1 |
| 3484 | |
| 3485 | #define ANEG_STATE_SETTLE_TIME 10000 |
| 3486 | |
| 3487 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, |
| 3488 | struct tg3_fiber_aneginfo *ap) |
| 3489 | { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3490 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | unsigned long delta; |
| 3492 | u32 rx_cfg_reg; |
| 3493 | int ret; |
| 3494 | |
| 3495 | if (ap->state == ANEG_STATE_UNKNOWN) { |
| 3496 | ap->rxconfig = 0; |
| 3497 | ap->link_time = 0; |
| 3498 | ap->cur_time = 0; |
| 3499 | ap->ability_match_cfg = 0; |
| 3500 | ap->ability_match_count = 0; |
| 3501 | ap->ability_match = 0; |
| 3502 | ap->idle_match = 0; |
| 3503 | ap->ack_match = 0; |
| 3504 | } |
| 3505 | ap->cur_time++; |
| 3506 | |
| 3507 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { |
| 3508 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); |
| 3509 | |
| 3510 | if (rx_cfg_reg != ap->ability_match_cfg) { |
| 3511 | ap->ability_match_cfg = rx_cfg_reg; |
| 3512 | ap->ability_match = 0; |
| 3513 | ap->ability_match_count = 0; |
| 3514 | } else { |
| 3515 | if (++ap->ability_match_count > 1) { |
| 3516 | ap->ability_match = 1; |
| 3517 | ap->ability_match_cfg = rx_cfg_reg; |
| 3518 | } |
| 3519 | } |
| 3520 | if (rx_cfg_reg & ANEG_CFG_ACK) |
| 3521 | ap->ack_match = 1; |
| 3522 | else |
| 3523 | ap->ack_match = 0; |
| 3524 | |
| 3525 | ap->idle_match = 0; |
| 3526 | } else { |
| 3527 | ap->idle_match = 1; |
| 3528 | ap->ability_match_cfg = 0; |
| 3529 | ap->ability_match_count = 0; |
| 3530 | ap->ability_match = 0; |
| 3531 | ap->ack_match = 0; |
| 3532 | |
| 3533 | rx_cfg_reg = 0; |
| 3534 | } |
| 3535 | |
| 3536 | ap->rxconfig = rx_cfg_reg; |
| 3537 | ret = ANEG_OK; |
| 3538 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 3539 | switch (ap->state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | case ANEG_STATE_UNKNOWN: |
| 3541 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) |
| 3542 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3543 | |
| 3544 | /* fallthru */ |
| 3545 | case ANEG_STATE_AN_ENABLE: |
| 3546 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); |
| 3547 | if (ap->flags & MR_AN_ENABLE) { |
| 3548 | ap->link_time = 0; |
| 3549 | ap->cur_time = 0; |
| 3550 | ap->ability_match_cfg = 0; |
| 3551 | ap->ability_match_count = 0; |
| 3552 | ap->ability_match = 0; |
| 3553 | ap->idle_match = 0; |
| 3554 | ap->ack_match = 0; |
| 3555 | |
| 3556 | ap->state = ANEG_STATE_RESTART_INIT; |
| 3557 | } else { |
| 3558 | ap->state = ANEG_STATE_DISABLE_LINK_OK; |
| 3559 | } |
| 3560 | break; |
| 3561 | |
| 3562 | case ANEG_STATE_RESTART_INIT: |
| 3563 | ap->link_time = ap->cur_time; |
| 3564 | ap->flags &= ~(MR_NP_LOADED); |
| 3565 | ap->txconfig = 0; |
| 3566 | tw32(MAC_TX_AUTO_NEG, 0); |
| 3567 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3568 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3569 | udelay(40); |
| 3570 | |
| 3571 | ret = ANEG_TIMER_ENAB; |
| 3572 | ap->state = ANEG_STATE_RESTART; |
| 3573 | |
| 3574 | /* fallthru */ |
| 3575 | case ANEG_STATE_RESTART: |
| 3576 | delta = ap->cur_time - ap->link_time; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 3577 | if (delta > ANEG_STATE_SETTLE_TIME) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 3579 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | ret = ANEG_TIMER_ENAB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | break; |
| 3582 | |
| 3583 | case ANEG_STATE_DISABLE_LINK_OK: |
| 3584 | ret = ANEG_DONE; |
| 3585 | break; |
| 3586 | |
| 3587 | case ANEG_STATE_ABILITY_DETECT_INIT: |
| 3588 | ap->flags &= ~(MR_TOGGLE_TX); |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3589 | ap->txconfig = ANEG_CFG_FD; |
| 3590 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 3591 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 3592 | ap->txconfig |= ANEG_CFG_PS1; |
| 3593 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 3594 | ap->txconfig |= ANEG_CFG_PS2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 3596 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3597 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3598 | udelay(40); |
| 3599 | |
| 3600 | ap->state = ANEG_STATE_ABILITY_DETECT; |
| 3601 | break; |
| 3602 | |
| 3603 | case ANEG_STATE_ABILITY_DETECT: |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 3604 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | break; |
| 3607 | |
| 3608 | case ANEG_STATE_ACK_DETECT_INIT: |
| 3609 | ap->txconfig |= ANEG_CFG_ACK; |
| 3610 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 3611 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3612 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3613 | udelay(40); |
| 3614 | |
| 3615 | ap->state = ANEG_STATE_ACK_DETECT; |
| 3616 | |
| 3617 | /* fallthru */ |
| 3618 | case ANEG_STATE_ACK_DETECT: |
| 3619 | if (ap->ack_match != 0) { |
| 3620 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == |
| 3621 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { |
| 3622 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; |
| 3623 | } else { |
| 3624 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3625 | } |
| 3626 | } else if (ap->ability_match != 0 && |
| 3627 | ap->rxconfig == 0) { |
| 3628 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3629 | } |
| 3630 | break; |
| 3631 | |
| 3632 | case ANEG_STATE_COMPLETE_ACK_INIT: |
| 3633 | if (ap->rxconfig & ANEG_CFG_INVAL) { |
| 3634 | ret = ANEG_FAILED; |
| 3635 | break; |
| 3636 | } |
| 3637 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | |
| 3638 | MR_LP_ADV_HALF_DUPLEX | |
| 3639 | MR_LP_ADV_SYM_PAUSE | |
| 3640 | MR_LP_ADV_ASYM_PAUSE | |
| 3641 | MR_LP_ADV_REMOTE_FAULT1 | |
| 3642 | MR_LP_ADV_REMOTE_FAULT2 | |
| 3643 | MR_LP_ADV_NEXT_PAGE | |
| 3644 | MR_TOGGLE_RX | |
| 3645 | MR_NP_RX); |
| 3646 | if (ap->rxconfig & ANEG_CFG_FD) |
| 3647 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; |
| 3648 | if (ap->rxconfig & ANEG_CFG_HD) |
| 3649 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; |
| 3650 | if (ap->rxconfig & ANEG_CFG_PS1) |
| 3651 | ap->flags |= MR_LP_ADV_SYM_PAUSE; |
| 3652 | if (ap->rxconfig & ANEG_CFG_PS2) |
| 3653 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; |
| 3654 | if (ap->rxconfig & ANEG_CFG_RF1) |
| 3655 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; |
| 3656 | if (ap->rxconfig & ANEG_CFG_RF2) |
| 3657 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; |
| 3658 | if (ap->rxconfig & ANEG_CFG_NP) |
| 3659 | ap->flags |= MR_LP_ADV_NEXT_PAGE; |
| 3660 | |
| 3661 | ap->link_time = ap->cur_time; |
| 3662 | |
| 3663 | ap->flags ^= (MR_TOGGLE_TX); |
| 3664 | if (ap->rxconfig & 0x0008) |
| 3665 | ap->flags |= MR_TOGGLE_RX; |
| 3666 | if (ap->rxconfig & ANEG_CFG_NP) |
| 3667 | ap->flags |= MR_NP_RX; |
| 3668 | ap->flags |= MR_PAGE_RX; |
| 3669 | |
| 3670 | ap->state = ANEG_STATE_COMPLETE_ACK; |
| 3671 | ret = ANEG_TIMER_ENAB; |
| 3672 | break; |
| 3673 | |
| 3674 | case ANEG_STATE_COMPLETE_ACK: |
| 3675 | if (ap->ability_match != 0 && |
| 3676 | ap->rxconfig == 0) { |
| 3677 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3678 | break; |
| 3679 | } |
| 3680 | delta = ap->cur_time - ap->link_time; |
| 3681 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 3682 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { |
| 3683 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 3684 | } else { |
| 3685 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && |
| 3686 | !(ap->flags & MR_NP_RX)) { |
| 3687 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 3688 | } else { |
| 3689 | ret = ANEG_FAILED; |
| 3690 | } |
| 3691 | } |
| 3692 | } |
| 3693 | break; |
| 3694 | |
| 3695 | case ANEG_STATE_IDLE_DETECT_INIT: |
| 3696 | ap->link_time = ap->cur_time; |
| 3697 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 3698 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3699 | udelay(40); |
| 3700 | |
| 3701 | ap->state = ANEG_STATE_IDLE_DETECT; |
| 3702 | ret = ANEG_TIMER_ENAB; |
| 3703 | break; |
| 3704 | |
| 3705 | case ANEG_STATE_IDLE_DETECT: |
| 3706 | if (ap->ability_match != 0 && |
| 3707 | ap->rxconfig == 0) { |
| 3708 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3709 | break; |
| 3710 | } |
| 3711 | delta = ap->cur_time - ap->link_time; |
| 3712 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 3713 | /* XXX another gem from the Broadcom driver :( */ |
| 3714 | ap->state = ANEG_STATE_LINK_OK; |
| 3715 | } |
| 3716 | break; |
| 3717 | |
| 3718 | case ANEG_STATE_LINK_OK: |
| 3719 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); |
| 3720 | ret = ANEG_DONE; |
| 3721 | break; |
| 3722 | |
| 3723 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: |
| 3724 | /* ??? unimplemented */ |
| 3725 | break; |
| 3726 | |
| 3727 | case ANEG_STATE_NEXT_PAGE_WAIT: |
| 3728 | /* ??? unimplemented */ |
| 3729 | break; |
| 3730 | |
| 3731 | default: |
| 3732 | ret = ANEG_FAILED; |
| 3733 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3734 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | |
| 3736 | return ret; |
| 3737 | } |
| 3738 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3739 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | { |
| 3741 | int res = 0; |
| 3742 | struct tg3_fiber_aneginfo aninfo; |
| 3743 | int status = ANEG_FAILED; |
| 3744 | unsigned int tick; |
| 3745 | u32 tmp; |
| 3746 | |
| 3747 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 3748 | |
| 3749 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
| 3750 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); |
| 3751 | udelay(40); |
| 3752 | |
| 3753 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); |
| 3754 | udelay(40); |
| 3755 | |
| 3756 | memset(&aninfo, 0, sizeof(aninfo)); |
| 3757 | aninfo.flags |= MR_AN_ENABLE; |
| 3758 | aninfo.state = ANEG_STATE_UNKNOWN; |
| 3759 | aninfo.cur_time = 0; |
| 3760 | tick = 0; |
| 3761 | while (++tick < 195000) { |
| 3762 | status = tg3_fiber_aneg_smachine(tp, &aninfo); |
| 3763 | if (status == ANEG_DONE || status == ANEG_FAILED) |
| 3764 | break; |
| 3765 | |
| 3766 | udelay(1); |
| 3767 | } |
| 3768 | |
| 3769 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 3770 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3771 | udelay(40); |
| 3772 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3773 | *txflags = aninfo.txconfig; |
| 3774 | *rxflags = aninfo.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | |
| 3776 | if (status == ANEG_DONE && |
| 3777 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | |
| 3778 | MR_LP_ADV_FULL_DUPLEX))) |
| 3779 | res = 1; |
| 3780 | |
| 3781 | return res; |
| 3782 | } |
| 3783 | |
| 3784 | static void tg3_init_bcm8002(struct tg3 *tp) |
| 3785 | { |
| 3786 | u32 mac_status = tr32(MAC_STATUS); |
| 3787 | int i; |
| 3788 | |
| 3789 | /* Reset when initting first time or we have a link. */ |
| 3790 | if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) && |
| 3791 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 3792 | return; |
| 3793 | |
| 3794 | /* Set PLL lock range. */ |
| 3795 | tg3_writephy(tp, 0x16, 0x8007); |
| 3796 | |
| 3797 | /* SW reset */ |
| 3798 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); |
| 3799 | |
| 3800 | /* Wait for reset to complete. */ |
| 3801 | /* XXX schedule_timeout() ... */ |
| 3802 | for (i = 0; i < 500; i++) |
| 3803 | udelay(10); |
| 3804 | |
| 3805 | /* Config mode; select PMA/Ch 1 regs. */ |
| 3806 | tg3_writephy(tp, 0x10, 0x8411); |
| 3807 | |
| 3808 | /* Enable auto-lock and comdet, select txclk for tx. */ |
| 3809 | tg3_writephy(tp, 0x11, 0x0a10); |
| 3810 | |
| 3811 | tg3_writephy(tp, 0x18, 0x00a0); |
| 3812 | tg3_writephy(tp, 0x16, 0x41ff); |
| 3813 | |
| 3814 | /* Assert and deassert POR. */ |
| 3815 | tg3_writephy(tp, 0x13, 0x0400); |
| 3816 | udelay(40); |
| 3817 | tg3_writephy(tp, 0x13, 0x0000); |
| 3818 | |
| 3819 | tg3_writephy(tp, 0x11, 0x0a50); |
| 3820 | udelay(40); |
| 3821 | tg3_writephy(tp, 0x11, 0x0a10); |
| 3822 | |
| 3823 | /* Wait for signal to stabilize */ |
| 3824 | /* XXX schedule_timeout() ... */ |
| 3825 | for (i = 0; i < 15000; i++) |
| 3826 | udelay(10); |
| 3827 | |
| 3828 | /* Deselect the channel register so we can read the PHYID |
| 3829 | * later. |
| 3830 | */ |
| 3831 | tg3_writephy(tp, 0x10, 0x8011); |
| 3832 | } |
| 3833 | |
| 3834 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
| 3835 | { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3836 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | u32 sg_dig_ctrl, sg_dig_status; |
| 3838 | u32 serdes_cfg, expected_sg_dig_ctrl; |
| 3839 | int workaround, port_a; |
| 3840 | int current_link_up; |
| 3841 | |
| 3842 | serdes_cfg = 0; |
| 3843 | expected_sg_dig_ctrl = 0; |
| 3844 | workaround = 0; |
| 3845 | port_a = 1; |
| 3846 | current_link_up = 0; |
| 3847 | |
| 3848 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && |
| 3849 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { |
| 3850 | workaround = 1; |
| 3851 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 3852 | port_a = 0; |
| 3853 | |
| 3854 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ |
| 3855 | /* preserve bits 20-23 for voltage regulator */ |
| 3856 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; |
| 3857 | } |
| 3858 | |
| 3859 | sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 3860 | |
| 3861 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3862 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | if (workaround) { |
| 3864 | u32 val = serdes_cfg; |
| 3865 | |
| 3866 | if (port_a) |
| 3867 | val |= 0xc010000; |
| 3868 | else |
| 3869 | val |= 0x4010000; |
| 3870 | tw32_f(MAC_SERDES_CFG, val); |
| 3871 | } |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3872 | |
| 3873 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | } |
| 3875 | if (mac_status & MAC_STATUS_PCS_SYNCED) { |
| 3876 | tg3_setup_flow_control(tp, 0, 0); |
| 3877 | current_link_up = 1; |
| 3878 | } |
| 3879 | goto out; |
| 3880 | } |
| 3881 | |
| 3882 | /* Want auto-negotiation. */ |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3883 | 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] | 3884 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3885 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 3886 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 3887 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; |
| 3888 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 3889 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | |
| 3891 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3892 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3893 | tp->serdes_counter && |
| 3894 | ((mac_status & (MAC_STATUS_PCS_SYNCED | |
| 3895 | MAC_STATUS_RCVD_CFG)) == |
| 3896 | MAC_STATUS_PCS_SYNCED)) { |
| 3897 | tp->serdes_counter--; |
| 3898 | current_link_up = 1; |
| 3899 | goto out; |
| 3900 | } |
| 3901 | restart_autoneg: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | if (workaround) |
| 3903 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3904 | 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] | 3905 | udelay(5); |
| 3906 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); |
| 3907 | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3908 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3909 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
| 3911 | MAC_STATUS_SIGNAL_DET)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3912 | sg_dig_status = tr32(SG_DIG_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | mac_status = tr32(MAC_STATUS); |
| 3914 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3915 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3917 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3919 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) |
| 3920 | local_adv |= ADVERTISE_1000XPAUSE; |
| 3921 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) |
| 3922 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 3923 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3924 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3925 | remote_adv |= LPA_1000XPAUSE; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3926 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3927 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | |
| 3929 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 3930 | current_link_up = 1; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3931 | tp->serdes_counter = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3932 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3933 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3934 | if (tp->serdes_counter) |
| 3935 | tp->serdes_counter--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | else { |
| 3937 | if (workaround) { |
| 3938 | u32 val = serdes_cfg; |
| 3939 | |
| 3940 | if (port_a) |
| 3941 | val |= 0xc010000; |
| 3942 | else |
| 3943 | val |= 0x4010000; |
| 3944 | |
| 3945 | tw32_f(MAC_SERDES_CFG, val); |
| 3946 | } |
| 3947 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3948 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | udelay(40); |
| 3950 | |
| 3951 | /* Link parallel detection - link is up */ |
| 3952 | /* only if we have PCS_SYNC and not */ |
| 3953 | /* receiving config code words */ |
| 3954 | mac_status = tr32(MAC_STATUS); |
| 3955 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && |
| 3956 | !(mac_status & MAC_STATUS_RCVD_CFG)) { |
| 3957 | tg3_setup_flow_control(tp, 0, 0); |
| 3958 | current_link_up = 1; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3959 | tp->phy_flags |= |
| 3960 | TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3961 | tp->serdes_counter = |
| 3962 | SERDES_PARALLEL_DET_TIMEOUT; |
| 3963 | } else |
| 3964 | goto restart_autoneg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 | } |
| 3966 | } |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3967 | } else { |
| 3968 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 3969 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | out: |
| 3973 | return current_link_up; |
| 3974 | } |
| 3975 | |
| 3976 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
| 3977 | { |
| 3978 | int current_link_up = 0; |
| 3979 | |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 3980 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | |
| 3983 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3984 | u32 txflags, rxflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3986 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3987 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
| 3988 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3990 | if (txflags & ANEG_CFG_PS1) |
| 3991 | local_adv |= ADVERTISE_1000XPAUSE; |
| 3992 | if (txflags & ANEG_CFG_PS2) |
| 3993 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 3994 | |
| 3995 | if (rxflags & MR_LP_ADV_SYM_PAUSE) |
| 3996 | remote_adv |= LPA_1000XPAUSE; |
| 3997 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) |
| 3998 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | |
| 4000 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | current_link_up = 1; |
| 4003 | } |
| 4004 | for (i = 0; i < 30; i++) { |
| 4005 | udelay(20); |
| 4006 | tw32_f(MAC_STATUS, |
| 4007 | (MAC_STATUS_SYNC_CHANGED | |
| 4008 | MAC_STATUS_CFG_CHANGED)); |
| 4009 | udelay(40); |
| 4010 | if ((tr32(MAC_STATUS) & |
| 4011 | (MAC_STATUS_SYNC_CHANGED | |
| 4012 | MAC_STATUS_CFG_CHANGED)) == 0) |
| 4013 | break; |
| 4014 | } |
| 4015 | |
| 4016 | mac_status = tr32(MAC_STATUS); |
| 4017 | if (current_link_up == 0 && |
| 4018 | (mac_status & MAC_STATUS_PCS_SYNCED) && |
| 4019 | !(mac_status & MAC_STATUS_RCVD_CFG)) |
| 4020 | current_link_up = 1; |
| 4021 | } else { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 4022 | tg3_setup_flow_control(tp, 0, 0); |
| 4023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | /* Forcing 1000FD link up. */ |
| 4025 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | |
| 4027 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); |
| 4028 | udelay(40); |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 4029 | |
| 4030 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4031 | udelay(40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | out: |
| 4035 | return current_link_up; |
| 4036 | } |
| 4037 | |
| 4038 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) |
| 4039 | { |
| 4040 | u32 orig_pause_cfg; |
| 4041 | u16 orig_active_speed; |
| 4042 | u8 orig_active_duplex; |
| 4043 | u32 mac_status; |
| 4044 | int current_link_up; |
| 4045 | int i; |
| 4046 | |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 4047 | orig_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | orig_active_speed = tp->link_config.active_speed; |
| 4049 | orig_active_duplex = tp->link_config.active_duplex; |
| 4050 | |
| 4051 | if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) && |
| 4052 | netif_carrier_ok(tp->dev) && |
| 4053 | (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) { |
| 4054 | mac_status = tr32(MAC_STATUS); |
| 4055 | mac_status &= (MAC_STATUS_PCS_SYNCED | |
| 4056 | MAC_STATUS_SIGNAL_DET | |
| 4057 | MAC_STATUS_CFG_CHANGED | |
| 4058 | MAC_STATUS_RCVD_CFG); |
| 4059 | if (mac_status == (MAC_STATUS_PCS_SYNCED | |
| 4060 | MAC_STATUS_SIGNAL_DET)) { |
| 4061 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 4062 | MAC_STATUS_CFG_CHANGED)); |
| 4063 | return 0; |
| 4064 | } |
| 4065 | } |
| 4066 | |
| 4067 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 4068 | |
| 4069 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 4070 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 4071 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4072 | udelay(40); |
| 4073 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 4074 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | tg3_init_bcm8002(tp); |
| 4076 | |
| 4077 | /* Enable link change event even when serdes polling. */ |
| 4078 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4079 | udelay(40); |
| 4080 | |
| 4081 | current_link_up = 0; |
| 4082 | mac_status = tr32(MAC_STATUS); |
| 4083 | |
| 4084 | if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) |
| 4085 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
| 4086 | else |
| 4087 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); |
| 4088 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 4089 | tp->napi[0].hw_status->status = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | (SD_STATUS_UPDATED | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 4091 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | |
| 4093 | for (i = 0; i < 100; i++) { |
| 4094 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 4095 | MAC_STATUS_CFG_CHANGED)); |
| 4096 | udelay(5); |
| 4097 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4098 | MAC_STATUS_CFG_CHANGED | |
| 4099 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | break; |
| 4101 | } |
| 4102 | |
| 4103 | mac_status = tr32(MAC_STATUS); |
| 4104 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { |
| 4105 | current_link_up = 0; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4106 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 4107 | tp->serdes_counter == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | tw32_f(MAC_MODE, (tp->mac_mode | |
| 4109 | MAC_MODE_SEND_CONFIGS)); |
| 4110 | udelay(1); |
| 4111 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4112 | } |
| 4113 | } |
| 4114 | |
| 4115 | if (current_link_up == 1) { |
| 4116 | tp->link_config.active_speed = SPEED_1000; |
| 4117 | tp->link_config.active_duplex = DUPLEX_FULL; |
| 4118 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 4119 | LED_CTRL_LNKLED_OVERRIDE | |
| 4120 | LED_CTRL_1000MBPS_ON)); |
| 4121 | } else { |
| 4122 | tp->link_config.active_speed = SPEED_INVALID; |
| 4123 | tp->link_config.active_duplex = DUPLEX_INVALID; |
| 4124 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 4125 | LED_CTRL_LNKLED_OVERRIDE | |
| 4126 | LED_CTRL_TRAFFIC_OVERRIDE)); |
| 4127 | } |
| 4128 | |
| 4129 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 4130 | if (current_link_up) |
| 4131 | netif_carrier_on(tp->dev); |
| 4132 | else |
| 4133 | netif_carrier_off(tp->dev); |
| 4134 | tg3_link_report(tp); |
| 4135 | } else { |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 4136 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | if (orig_pause_cfg != now_pause_cfg || |
| 4138 | orig_active_speed != tp->link_config.active_speed || |
| 4139 | orig_active_duplex != tp->link_config.active_duplex) |
| 4140 | tg3_link_report(tp); |
| 4141 | } |
| 4142 | |
| 4143 | return 0; |
| 4144 | } |
| 4145 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4146 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
| 4147 | { |
| 4148 | int current_link_up, err = 0; |
| 4149 | u32 bmsr, bmcr; |
| 4150 | u16 current_speed; |
| 4151 | u8 current_duplex; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4152 | u32 local_adv, remote_adv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4153 | |
| 4154 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4155 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4156 | udelay(40); |
| 4157 | |
| 4158 | tw32(MAC_EVENT, 0); |
| 4159 | |
| 4160 | tw32_f(MAC_STATUS, |
| 4161 | (MAC_STATUS_SYNC_CHANGED | |
| 4162 | MAC_STATUS_CFG_CHANGED | |
| 4163 | MAC_STATUS_MI_COMPLETION | |
| 4164 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4165 | udelay(40); |
| 4166 | |
| 4167 | if (force_reset) |
| 4168 | tg3_phy_reset(tp); |
| 4169 | |
| 4170 | current_link_up = 0; |
| 4171 | current_speed = SPEED_INVALID; |
| 4172 | current_duplex = DUPLEX_INVALID; |
| 4173 | |
| 4174 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4175 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 4176 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 4177 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 4178 | bmsr |= BMSR_LSTATUS; |
| 4179 | else |
| 4180 | bmsr &= ~BMSR_LSTATUS; |
| 4181 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4182 | |
| 4183 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4184 | |
| 4185 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4186 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4187 | /* do nothing, just check for link up at the end */ |
| 4188 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 4189 | u32 adv, new_adv; |
| 4190 | |
| 4191 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 4192 | new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
| 4193 | ADVERTISE_1000XPAUSE | |
| 4194 | ADVERTISE_1000XPSE_ASYM | |
| 4195 | ADVERTISE_SLCT); |
| 4196 | |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4197 | new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4198 | |
| 4199 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) |
| 4200 | new_adv |= ADVERTISE_1000XHALF; |
| 4201 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) |
| 4202 | new_adv |= ADVERTISE_1000XFULL; |
| 4203 | |
| 4204 | if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) { |
| 4205 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 4206 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 4207 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 4208 | |
| 4209 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4210 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4211 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4212 | |
| 4213 | return err; |
| 4214 | } |
| 4215 | } else { |
| 4216 | u32 new_bmcr; |
| 4217 | |
| 4218 | bmcr &= ~BMCR_SPEED1000; |
| 4219 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4220 | |
| 4221 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 4222 | new_bmcr |= BMCR_FULLDPLX; |
| 4223 | |
| 4224 | if (new_bmcr != bmcr) { |
| 4225 | /* BMCR_SPEED1000 is a reserved bit that needs |
| 4226 | * to be set on write. |
| 4227 | */ |
| 4228 | new_bmcr |= BMCR_SPEED1000; |
| 4229 | |
| 4230 | /* Force a linkdown */ |
| 4231 | if (netif_carrier_ok(tp->dev)) { |
| 4232 | u32 adv; |
| 4233 | |
| 4234 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 4235 | adv &= ~(ADVERTISE_1000XFULL | |
| 4236 | ADVERTISE_1000XHALF | |
| 4237 | ADVERTISE_SLCT); |
| 4238 | tg3_writephy(tp, MII_ADVERTISE, adv); |
| 4239 | tg3_writephy(tp, MII_BMCR, bmcr | |
| 4240 | BMCR_ANRESTART | |
| 4241 | BMCR_ANENABLE); |
| 4242 | udelay(10); |
| 4243 | netif_carrier_off(tp->dev); |
| 4244 | } |
| 4245 | tg3_writephy(tp, MII_BMCR, new_bmcr); |
| 4246 | bmcr = new_bmcr; |
| 4247 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4248 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 4249 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 4250 | ASIC_REV_5714) { |
| 4251 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 4252 | bmsr |= BMSR_LSTATUS; |
| 4253 | else |
| 4254 | bmsr &= ~BMSR_LSTATUS; |
| 4255 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4256 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4257 | } |
| 4258 | } |
| 4259 | |
| 4260 | if (bmsr & BMSR_LSTATUS) { |
| 4261 | current_speed = SPEED_1000; |
| 4262 | current_link_up = 1; |
| 4263 | if (bmcr & BMCR_FULLDPLX) |
| 4264 | current_duplex = DUPLEX_FULL; |
| 4265 | else |
| 4266 | current_duplex = DUPLEX_HALF; |
| 4267 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4268 | local_adv = 0; |
| 4269 | remote_adv = 0; |
| 4270 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4271 | if (bmcr & BMCR_ANENABLE) { |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4272 | u32 common; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4273 | |
| 4274 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); |
| 4275 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); |
| 4276 | common = local_adv & remote_adv; |
| 4277 | if (common & (ADVERTISE_1000XHALF | |
| 4278 | ADVERTISE_1000XFULL)) { |
| 4279 | if (common & ADVERTISE_1000XFULL) |
| 4280 | current_duplex = DUPLEX_FULL; |
| 4281 | else |
| 4282 | current_duplex = DUPLEX_HALF; |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 4283 | } else if (!(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
| 4284 | /* Link is up via parallel detect */ |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4285 | } else { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4286 | current_link_up = 0; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4287 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4288 | } |
| 4289 | } |
| 4290 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4291 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
| 4292 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4293 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4294 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 4295 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 4296 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 4297 | |
| 4298 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4299 | udelay(40); |
| 4300 | |
| 4301 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4302 | |
| 4303 | tp->link_config.active_speed = current_speed; |
| 4304 | tp->link_config.active_duplex = current_duplex; |
| 4305 | |
| 4306 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 4307 | if (current_link_up) |
| 4308 | netif_carrier_on(tp->dev); |
| 4309 | else { |
| 4310 | netif_carrier_off(tp->dev); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4311 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4312 | } |
| 4313 | tg3_link_report(tp); |
| 4314 | } |
| 4315 | return err; |
| 4316 | } |
| 4317 | |
| 4318 | static void tg3_serdes_parallel_detect(struct tg3 *tp) |
| 4319 | { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4320 | if (tp->serdes_counter) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4321 | /* Give autoneg time to complete. */ |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4322 | tp->serdes_counter--; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4323 | return; |
| 4324 | } |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 4325 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4326 | if (!netif_carrier_ok(tp->dev) && |
| 4327 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { |
| 4328 | u32 bmcr; |
| 4329 | |
| 4330 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4331 | if (bmcr & BMCR_ANENABLE) { |
| 4332 | u32 phy1, phy2; |
| 4333 | |
| 4334 | /* Select shadow register 0x1f */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4335 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
| 4336 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4337 | |
| 4338 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4339 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 4340 | MII_TG3_DSP_EXP1_INT_STAT); |
| 4341 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 4342 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4343 | |
| 4344 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { |
| 4345 | /* We have signal detect and not receiving |
| 4346 | * config code words, link is up by parallel |
| 4347 | * detection. |
| 4348 | */ |
| 4349 | |
| 4350 | bmcr &= ~BMCR_ANENABLE; |
| 4351 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; |
| 4352 | tg3_writephy(tp, MII_BMCR, bmcr); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4353 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4354 | } |
| 4355 | } |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4356 | } else if (netif_carrier_ok(tp->dev) && |
| 4357 | (tp->link_config.autoneg == AUTONEG_ENABLE) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4358 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4359 | u32 phy2; |
| 4360 | |
| 4361 | /* Select expansion interrupt status register */ |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 4362 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 4363 | MII_TG3_DSP_EXP1_INT_STAT); |
| 4364 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4365 | if (phy2 & 0x20) { |
| 4366 | u32 bmcr; |
| 4367 | |
| 4368 | /* Config code words received, turn on autoneg. */ |
| 4369 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4370 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); |
| 4371 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4372 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4373 | |
| 4374 | } |
| 4375 | } |
| 4376 | } |
| 4377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
| 4379 | { |
| 4380 | int err; |
| 4381 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4382 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | err = tg3_setup_fiber_phy(tp, force_reset); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 4384 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4385 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 4386 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | err = tg3_setup_copper_phy(tp, force_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 4389 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | aa6c91f | 2007-11-12 21:18:04 -0800 | [diff] [blame] | 4390 | u32 val, scale; |
| 4391 | |
| 4392 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; |
| 4393 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) |
| 4394 | scale = 65; |
| 4395 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) |
| 4396 | scale = 6; |
| 4397 | else |
| 4398 | scale = 12; |
| 4399 | |
| 4400 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; |
| 4401 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 4402 | tw32(GRC_MISC_CFG, val); |
| 4403 | } |
| 4404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | if (tp->link_config.active_speed == SPEED_1000 && |
| 4406 | tp->link_config.active_duplex == DUPLEX_HALF) |
| 4407 | tw32(MAC_TX_LENGTHS, |
| 4408 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 4409 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 4410 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 4411 | else |
| 4412 | tw32(MAC_TX_LENGTHS, |
| 4413 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 4414 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 4415 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 4416 | |
| 4417 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 4418 | if (netif_carrier_ok(tp->dev)) { |
| 4419 | tw32(HOSTCC_STAT_COAL_TICKS, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 4420 | tp->coal.stats_block_coalesce_usecs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | } else { |
| 4422 | tw32(HOSTCC_STAT_COAL_TICKS, 0); |
| 4423 | } |
| 4424 | } |
| 4425 | |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 4426 | if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) { |
| 4427 | u32 val = tr32(PCIE_PWR_MGMT_THRESH); |
| 4428 | if (!netif_carrier_ok(tp->dev)) |
| 4429 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
| 4430 | tp->pwrmgmt_thresh; |
| 4431 | else |
| 4432 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 4433 | tw32(PCIE_PWR_MGMT_THRESH, val); |
| 4434 | } |
| 4435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | return err; |
| 4437 | } |
| 4438 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 4439 | static inline int tg3_irq_sync(struct tg3 *tp) |
| 4440 | { |
| 4441 | return tp->irq_sync; |
| 4442 | } |
| 4443 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4444 | /* This is called whenever we suspect that the system chipset is re- |
| 4445 | * ordering the sequence of MMIO to the tx send mailbox. The symptom |
| 4446 | * is bogus tx completions. We try to recover by setting the |
| 4447 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later |
| 4448 | * in the workqueue. |
| 4449 | */ |
| 4450 | static void tg3_tx_recover(struct tg3 *tp) |
| 4451 | { |
| 4452 | BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) || |
| 4453 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
| 4454 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 4455 | netdev_warn(tp->dev, |
| 4456 | "The system may be re-ordering memory-mapped I/O " |
| 4457 | "cycles to the network device, attempting to recover. " |
| 4458 | "Please report the problem to the driver maintainer " |
| 4459 | "and include system chipset information.\n"); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4460 | |
| 4461 | spin_lock(&tp->lock); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4462 | tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4463 | spin_unlock(&tp->lock); |
| 4464 | } |
| 4465 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4466 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4467 | { |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 4468 | /* Tell compiler to fetch tx indices from memory. */ |
| 4469 | barrier(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4470 | return tnapi->tx_pending - |
| 4471 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4472 | } |
| 4473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | /* Tigon3 never reports partial packet sends. So we do not |
| 4475 | * need special logic to handle SKBs that have not had all |
| 4476 | * of their frags sent yet, like SunGEM does. |
| 4477 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4478 | static void tg3_tx(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4480 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 4481 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4482 | u32 sw_idx = tnapi->tx_cons; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4483 | struct netdev_queue *txq; |
| 4484 | int index = tnapi - tp->napi; |
| 4485 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 4486 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4487 | index--; |
| 4488 | |
| 4489 | txq = netdev_get_tx_queue(tp->dev, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | |
| 4491 | while (sw_idx != hw_idx) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4492 | struct ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | struct sk_buff *skb = ri->skb; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4494 | int i, tx_bug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4496 | if (unlikely(skb == NULL)) { |
| 4497 | tg3_tx_recover(tp); |
| 4498 | return; |
| 4499 | } |
| 4500 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4501 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4502 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4503 | skb_headlen(skb), |
| 4504 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | |
| 4506 | ri->skb = NULL; |
| 4507 | |
| 4508 | sw_idx = NEXT_TX(sw_idx); |
| 4509 | |
| 4510 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4511 | ri = &tnapi->tx_buffers[sw_idx]; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4512 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
| 4513 | tx_bug = 1; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4514 | |
| 4515 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4516 | dma_unmap_addr(ri, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4517 | skb_shinfo(skb)->frags[i].size, |
| 4518 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | sw_idx = NEXT_TX(sw_idx); |
| 4520 | } |
| 4521 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 4522 | dev_kfree_skb(skb); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4523 | |
| 4524 | if (unlikely(tx_bug)) { |
| 4525 | tg3_tx_recover(tp); |
| 4526 | return; |
| 4527 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4528 | } |
| 4529 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4530 | tnapi->tx_cons = sw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4532 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
| 4533 | * before checking for netif_queue_stopped(). Without the |
| 4534 | * memory barrier, there is a small possibility that tg3_start_xmit() |
| 4535 | * will miss it and cause the queue to be stopped forever. |
| 4536 | */ |
| 4537 | smp_mb(); |
| 4538 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4539 | if (unlikely(netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4540 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4541 | __netif_tx_lock(txq, smp_processor_id()); |
| 4542 | if (netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4543 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4544 | netif_tx_wake_queue(txq); |
| 4545 | __netif_tx_unlock(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 4546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | } |
| 4548 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 4549 | static void tg3_rx_skb_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
| 4550 | { |
| 4551 | if (!ri->skb) |
| 4552 | return; |
| 4553 | |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4554 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 4555 | map_sz, PCI_DMA_FROMDEVICE); |
| 4556 | dev_kfree_skb_any(ri->skb); |
| 4557 | ri->skb = NULL; |
| 4558 | } |
| 4559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | /* Returns size of skb allocated or < 0 on error. |
| 4561 | * |
| 4562 | * We only need to fill in the address because the other members |
| 4563 | * of the RX descriptor are invariant, see tg3_init_rings. |
| 4564 | * |
| 4565 | * Note the purposeful assymetry of cpu vs. chip accesses. For |
| 4566 | * posting buffers we only dirty the first cache line of the RX |
| 4567 | * descriptor (containing the address). Whereas for the RX status |
| 4568 | * buffers the cpu only reads the last cacheline of the RX descriptor |
| 4569 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). |
| 4570 | */ |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 4571 | 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] | 4572 | u32 opaque_key, u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | { |
| 4574 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | f94e290 | 2010-10-14 10:37:42 +0000 | [diff] [blame] | 4575 | struct ring_info *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | struct sk_buff *skb; |
| 4577 | dma_addr_t mapping; |
| 4578 | int skb_size, dest_idx; |
| 4579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | switch (opaque_key) { |
| 4581 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4582 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4583 | desc = &tpr->rx_std[dest_idx]; |
| 4584 | map = &tpr->rx_std_buffers[dest_idx]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4585 | skb_size = tp->rx_pkt_map_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | break; |
| 4587 | |
| 4588 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4589 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 4590 | desc = &tpr->rx_jmb[dest_idx].std; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4591 | map = &tpr->rx_jmb_buffers[dest_idx]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4592 | skb_size = TG3_RX_JMB_MAP_SZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | break; |
| 4594 | |
| 4595 | default: |
| 4596 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4597 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | |
| 4599 | /* Do not overwrite any of the map or rp information |
| 4600 | * until we are sure we can commit to a new buffer. |
| 4601 | * |
| 4602 | * Callers depend upon this behavior and assume that |
| 4603 | * we leave everything unchanged if we fail. |
| 4604 | */ |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4605 | skb = netdev_alloc_skb(tp->dev, skb_size + tp->rx_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | if (skb == NULL) |
| 4607 | return -ENOMEM; |
| 4608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | skb_reserve(skb, tp->rx_offset); |
| 4610 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4611 | mapping = pci_map_single(tp->pdev, skb->data, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | PCI_DMA_FROMDEVICE); |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 4613 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
| 4614 | dev_kfree_skb(skb); |
| 4615 | return -EIO; |
| 4616 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | |
| 4618 | map->skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4619 | dma_unmap_addr_set(map, mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | desc->addr_hi = ((u64)mapping >> 32); |
| 4622 | desc->addr_lo = ((u64)mapping & 0xffffffff); |
| 4623 | |
| 4624 | return skb_size; |
| 4625 | } |
| 4626 | |
| 4627 | /* We only need to move over in the address because the other |
| 4628 | * members of the RX descriptor are invariant. See notes above |
| 4629 | * tg3_alloc_rx_skb for full details. |
| 4630 | */ |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4631 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
| 4632 | struct tg3_rx_prodring_set *dpr, |
| 4633 | u32 opaque_key, int src_idx, |
| 4634 | u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4636 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
| 4638 | struct ring_info *src_map, *dest_map; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4639 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 4640 | int dest_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | |
| 4642 | switch (opaque_key) { |
| 4643 | case RXD_OPAQUE_RING_STD: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4644 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4645 | dest_desc = &dpr->rx_std[dest_idx]; |
| 4646 | dest_map = &dpr->rx_std_buffers[dest_idx]; |
| 4647 | src_desc = &spr->rx_std[src_idx]; |
| 4648 | src_map = &spr->rx_std_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | break; |
| 4650 | |
| 4651 | case RXD_OPAQUE_RING_JUMBO: |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4652 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4653 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
| 4654 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; |
| 4655 | src_desc = &spr->rx_jmb[src_idx].std; |
| 4656 | src_map = &spr->rx_jmb_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | break; |
| 4658 | |
| 4659 | default: |
| 4660 | return; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4661 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4662 | |
| 4663 | dest_map->skb = src_map->skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4664 | dma_unmap_addr_set(dest_map, mapping, |
| 4665 | dma_unmap_addr(src_map, mapping)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | dest_desc->addr_hi = src_desc->addr_hi; |
| 4667 | dest_desc->addr_lo = src_desc->addr_lo; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4668 | |
| 4669 | /* Ensure that the update to the skb happens after the physical |
| 4670 | * addresses have been transferred to the new BD location. |
| 4671 | */ |
| 4672 | smp_wmb(); |
| 4673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4674 | src_map->skb = NULL; |
| 4675 | } |
| 4676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | /* The RX ring scheme is composed of multiple rings which post fresh |
| 4678 | * buffers to the chip, and one special ring the chip uses to report |
| 4679 | * status back to the host. |
| 4680 | * |
| 4681 | * The special ring reports the status of received packets to the |
| 4682 | * host. The chip does not write into the original descriptor the |
| 4683 | * RX buffer was obtained from. The chip simply takes the original |
| 4684 | * descriptor as provided by the host, updates the status and length |
| 4685 | * field, then writes this into the next status ring entry. |
| 4686 | * |
| 4687 | * Each ring the host uses to post buffers to the chip is described |
| 4688 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, |
| 4689 | * it is first placed into the on-chip ram. When the packet's length |
| 4690 | * is known, it walks down the TG3_BDINFO entries to select the ring. |
| 4691 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO |
| 4692 | * which is within the range of the new packet's length is chosen. |
| 4693 | * |
| 4694 | * The "separate ring for rx status" scheme may sound queer, but it makes |
| 4695 | * sense from a cache coherency perspective. If only the host writes |
| 4696 | * to the buffer post rings, and only the chip writes to the rx status |
| 4697 | * rings, then cache lines never move beyond shared-modified state. |
| 4698 | * If both the host and chip were to write into the same ring, cache line |
| 4699 | * eviction could occur since both entities want it in an exclusive state. |
| 4700 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4701 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4702 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4703 | struct tg3 *tp = tnapi->tp; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4704 | u32 work_mask, rx_std_posted = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4705 | u32 std_prod_idx, jmb_prod_idx; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4706 | u32 sw_idx = tnapi->rx_rcb_ptr; |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 4707 | u16 hw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | int received; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4709 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 4711 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | /* |
| 4713 | * We need to order the read of hw_idx and the read of |
| 4714 | * the opaque cookie. |
| 4715 | */ |
| 4716 | rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4717 | work_mask = 0; |
| 4718 | received = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4719 | std_prod_idx = tpr->rx_std_prod_idx; |
| 4720 | jmb_prod_idx = tpr->rx_jmb_prod_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | while (sw_idx != hw_idx && budget > 0) { |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 4722 | struct ring_info *ri; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4723 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | unsigned int len; |
| 4725 | struct sk_buff *skb; |
| 4726 | dma_addr_t dma_addr; |
| 4727 | u32 opaque_key, desc_idx, *post_ptr; |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4728 | bool hw_vlan __maybe_unused = false; |
| 4729 | u16 vtag __maybe_unused = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | |
| 4731 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 4732 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 4733 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4734 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4735 | dma_addr = dma_unmap_addr(ri, mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4736 | skb = ri->skb; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4737 | post_ptr = &std_prod_idx; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4738 | rx_std_posted++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 4740 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 4741 | dma_addr = dma_unmap_addr(ri, mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4742 | skb = ri->skb; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4743 | post_ptr = &jmb_prod_idx; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4744 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | goto next_pkt_nopost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4746 | |
| 4747 | work_mask |= opaque_key; |
| 4748 | |
| 4749 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 4750 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { |
| 4751 | drop_it: |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4752 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | desc_idx, *post_ptr); |
| 4754 | drop_it_no_recycle: |
| 4755 | /* Other statistics kept track of by card. */ |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 4756 | tp->rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | goto next_pkt; |
| 4758 | } |
| 4759 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 4760 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
| 4761 | ETH_FCS_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 4763 | if (len > TG3_RX_COPY_THRESH(tp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | int skb_size; |
| 4765 | |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 4766 | skb_size = tg3_alloc_rx_skb(tp, tpr, opaque_key, |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 4767 | *post_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | if (skb_size < 0) |
| 4769 | goto drop_it; |
| 4770 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4771 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4772 | PCI_DMA_FROMDEVICE); |
| 4773 | |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 4774 | /* Ensure that the update to the skb happens |
| 4775 | * after the usage of the old DMA mapping. |
| 4776 | */ |
| 4777 | smp_wmb(); |
| 4778 | |
| 4779 | ri->skb = NULL; |
| 4780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | skb_put(skb, len); |
| 4782 | } else { |
| 4783 | struct sk_buff *copy_skb; |
| 4784 | |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4785 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | desc_idx, *post_ptr); |
| 4787 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4788 | copy_skb = netdev_alloc_skb(tp->dev, len + VLAN_HLEN + |
| 4789 | TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | if (copy_skb == NULL) |
| 4791 | goto drop_it_no_recycle; |
| 4792 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4793 | skb_reserve(copy_skb, TG3_RAW_IP_ALIGN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | skb_put(copy_skb, len); |
| 4795 | 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] | 4796 | skb_copy_from_linear_data(skb, copy_skb->data, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
| 4798 | |
| 4799 | /* We'll reuse the original ring buffer. */ |
| 4800 | skb = copy_skb; |
| 4801 | } |
| 4802 | |
| 4803 | if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) && |
| 4804 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 4805 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 4806 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) |
| 4807 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 4808 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 4809 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | |
| 4811 | skb->protocol = eth_type_trans(skb, tp->dev); |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 4812 | |
| 4813 | if (len > (tp->dev->mtu + ETH_HLEN) && |
| 4814 | skb->protocol != htons(ETH_P_8021Q)) { |
| 4815 | dev_kfree_skb(skb); |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 4816 | goto drop_it_no_recycle; |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 4817 | } |
| 4818 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4819 | if (desc->type_flags & RXD_FLAG_VLAN && |
| 4820 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) { |
| 4821 | vtag = desc->err_vlan & RXD_VLAN_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | #if TG3_VLAN_TAG_USED |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 4823 | if (tp->vlgrp) |
| 4824 | hw_vlan = true; |
| 4825 | else |
| 4826 | #endif |
| 4827 | { |
| 4828 | struct vlan_ethhdr *ve = (struct vlan_ethhdr *) |
| 4829 | __skb_push(skb, VLAN_HLEN); |
| 4830 | |
| 4831 | memmove(ve, skb->data + VLAN_HLEN, |
| 4832 | ETH_ALEN * 2); |
| 4833 | ve->h_vlan_proto = htons(ETH_P_8021Q); |
| 4834 | ve->h_vlan_TCI = htons(vtag); |
| 4835 | } |
| 4836 | } |
| 4837 | |
| 4838 | #if TG3_VLAN_TAG_USED |
| 4839 | if (hw_vlan) |
| 4840 | vlan_gro_receive(&tnapi->napi, tp->vlgrp, vtag, skb); |
| 4841 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | #endif |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4843 | napi_gro_receive(&tnapi->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | received++; |
| 4846 | budget--; |
| 4847 | |
| 4848 | next_pkt: |
| 4849 | (*post_ptr)++; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4850 | |
| 4851 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4852 | tpr->rx_std_prod_idx = std_prod_idx & |
| 4853 | tp->rx_std_ring_mask; |
Matt Carlson | 86cfe4f | 2010-01-12 10:11:37 +0000 | [diff] [blame] | 4854 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 4855 | tpr->rx_std_prod_idx); |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4856 | work_mask &= ~RXD_OPAQUE_RING_STD; |
| 4857 | rx_std_posted = 0; |
| 4858 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | next_pkt_nopost: |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 4860 | sw_idx++; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 4861 | sw_idx &= tp->rx_ret_ring_mask; |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 4862 | |
| 4863 | /* Refresh hw_idx to see if there is new work */ |
| 4864 | if (sw_idx == hw_idx) { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 4865 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 4866 | rmb(); |
| 4867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | /* ACK the status ring. */ |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4871 | tnapi->rx_rcb_ptr = sw_idx; |
| 4872 | tw32_rx_mbox(tnapi->consmbox, sw_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | |
| 4874 | /* Refill RX ring(s). */ |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4875 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4876 | if (work_mask & RXD_OPAQUE_RING_STD) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4877 | tpr->rx_std_prod_idx = std_prod_idx & |
| 4878 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4879 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 4880 | tpr->rx_std_prod_idx); |
| 4881 | } |
| 4882 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4883 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
| 4884 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4885 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 4886 | tpr->rx_jmb_prod_idx); |
| 4887 | } |
| 4888 | mmiowb(); |
| 4889 | } else if (work_mask) { |
| 4890 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be |
| 4891 | * updated before the producer indices can be updated. |
| 4892 | */ |
| 4893 | smp_wmb(); |
| 4894 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4895 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
| 4896 | 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] | 4897 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4898 | if (tnapi != &tp->napi[1]) |
| 4899 | napi_schedule(&tp->napi[1].napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4900 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | |
| 4902 | return received; |
| 4903 | } |
| 4904 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4905 | static void tg3_poll_link(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | /* handle link change and other phy events */ |
| 4908 | if (!(tp->tg3_flags & |
| 4909 | (TG3_FLAG_USE_LINKCHG_REG | |
| 4910 | TG3_FLAG_POLL_SERDES))) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4911 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
| 4912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | if (sblk->status & SD_STATUS_LINK_CHG) { |
| 4914 | sblk->status = SD_STATUS_UPDATED | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4915 | (sblk->status & ~SD_STATUS_LINK_CHG); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 4916 | spin_lock(&tp->lock); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 4917 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
| 4918 | tw32_f(MAC_STATUS, |
| 4919 | (MAC_STATUS_SYNC_CHANGED | |
| 4920 | MAC_STATUS_CFG_CHANGED | |
| 4921 | MAC_STATUS_MI_COMPLETION | |
| 4922 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4923 | udelay(40); |
| 4924 | } else |
| 4925 | tg3_setup_phy(tp, 0); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 4926 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | } |
| 4928 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4929 | } |
| 4930 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4931 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
| 4932 | struct tg3_rx_prodring_set *dpr, |
| 4933 | struct tg3_rx_prodring_set *spr) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4934 | { |
| 4935 | u32 si, di, cpycnt, src_prod_idx; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4936 | int i, err = 0; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4937 | |
| 4938 | while (1) { |
| 4939 | src_prod_idx = spr->rx_std_prod_idx; |
| 4940 | |
| 4941 | /* Make sure updates to the rx_std_buffers[] entries and the |
| 4942 | * standard producer index are seen in the correct order. |
| 4943 | */ |
| 4944 | smp_rmb(); |
| 4945 | |
| 4946 | if (spr->rx_std_cons_idx == src_prod_idx) |
| 4947 | break; |
| 4948 | |
| 4949 | if (spr->rx_std_cons_idx < src_prod_idx) |
| 4950 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; |
| 4951 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4952 | cpycnt = tp->rx_std_ring_mask + 1 - |
| 4953 | spr->rx_std_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4954 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4955 | cpycnt = min(cpycnt, |
| 4956 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4957 | |
| 4958 | si = spr->rx_std_cons_idx; |
| 4959 | di = dpr->rx_std_prod_idx; |
| 4960 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4961 | for (i = di; i < di + cpycnt; i++) { |
| 4962 | if (dpr->rx_std_buffers[i].skb) { |
| 4963 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4964 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4965 | break; |
| 4966 | } |
| 4967 | } |
| 4968 | |
| 4969 | if (!cpycnt) |
| 4970 | break; |
| 4971 | |
| 4972 | /* Ensure that updates to the rx_std_buffers ring and the |
| 4973 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 4974 | * ordered correctly WRT the skb check above. |
| 4975 | */ |
| 4976 | smp_rmb(); |
| 4977 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4978 | memcpy(&dpr->rx_std_buffers[di], |
| 4979 | &spr->rx_std_buffers[si], |
| 4980 | cpycnt * sizeof(struct ring_info)); |
| 4981 | |
| 4982 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 4983 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 4984 | sbd = &spr->rx_std[si]; |
| 4985 | dbd = &dpr->rx_std[di]; |
| 4986 | dbd->addr_hi = sbd->addr_hi; |
| 4987 | dbd->addr_lo = sbd->addr_lo; |
| 4988 | } |
| 4989 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 4990 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
| 4991 | tp->rx_std_ring_mask; |
| 4992 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & |
| 4993 | tp->rx_std_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | while (1) { |
| 4997 | src_prod_idx = spr->rx_jmb_prod_idx; |
| 4998 | |
| 4999 | /* Make sure updates to the rx_jmb_buffers[] entries and |
| 5000 | * the jumbo producer index are seen in the correct order. |
| 5001 | */ |
| 5002 | smp_rmb(); |
| 5003 | |
| 5004 | if (spr->rx_jmb_cons_idx == src_prod_idx) |
| 5005 | break; |
| 5006 | |
| 5007 | if (spr->rx_jmb_cons_idx < src_prod_idx) |
| 5008 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; |
| 5009 | else |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5010 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
| 5011 | spr->rx_jmb_cons_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5012 | |
| 5013 | cpycnt = min(cpycnt, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5014 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5015 | |
| 5016 | si = spr->rx_jmb_cons_idx; |
| 5017 | di = dpr->rx_jmb_prod_idx; |
| 5018 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5019 | for (i = di; i < di + cpycnt; i++) { |
| 5020 | if (dpr->rx_jmb_buffers[i].skb) { |
| 5021 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5022 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 5023 | break; |
| 5024 | } |
| 5025 | } |
| 5026 | |
| 5027 | if (!cpycnt) |
| 5028 | break; |
| 5029 | |
| 5030 | /* Ensure that updates to the rx_jmb_buffers ring and the |
| 5031 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 5032 | * ordered correctly WRT the skb check above. |
| 5033 | */ |
| 5034 | smp_rmb(); |
| 5035 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5036 | memcpy(&dpr->rx_jmb_buffers[di], |
| 5037 | &spr->rx_jmb_buffers[si], |
| 5038 | cpycnt * sizeof(struct ring_info)); |
| 5039 | |
| 5040 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 5041 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 5042 | sbd = &spr->rx_jmb[si].std; |
| 5043 | dbd = &dpr->rx_jmb[di].std; |
| 5044 | dbd->addr_hi = sbd->addr_hi; |
| 5045 | dbd->addr_lo = sbd->addr_lo; |
| 5046 | } |
| 5047 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 5048 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
| 5049 | tp->rx_jmb_ring_mask; |
| 5050 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & |
| 5051 | tp->rx_jmb_ring_mask; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5052 | } |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5053 | |
| 5054 | return err; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5055 | } |
| 5056 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5057 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
| 5058 | { |
| 5059 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5060 | |
| 5061 | /* run TX completion thread */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5062 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5063 | tg3_tx(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5064 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5065 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5066 | } |
| 5067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5068 | /* run RX thread, within the bounds set by NAPI. |
| 5069 | * All RX "locking" is done by ensuring outside |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5070 | * code synchronizes with tg3->napi.poll() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | */ |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 5072 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5073 | work_done += tg3_rx(tnapi, budget - work_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5075 | if ((tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) && tnapi == &tp->napi[1]) { |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5076 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5077 | int i, err = 0; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5078 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
| 5079 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5080 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5081 | for (i = 1; i < tp->irq_cnt; i++) |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5082 | err |= tg3_rx_prodring_xfer(tp, dpr, |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 5083 | &tp->napi[i].prodring); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5084 | |
| 5085 | wmb(); |
| 5086 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5087 | if (std_prod_idx != dpr->rx_std_prod_idx) |
| 5088 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 5089 | dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5090 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 5091 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
| 5092 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 5093 | dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5094 | |
| 5095 | mmiowb(); |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 5096 | |
| 5097 | if (err) |
| 5098 | tw32_f(HOSTCC_MODE, tp->coal_now); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5099 | } |
| 5100 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5101 | return work_done; |
| 5102 | } |
David S. Miller | f7383c2 | 2005-05-18 22:50:53 -0700 | [diff] [blame] | 5103 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5104 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
| 5105 | { |
| 5106 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 5107 | struct tg3 *tp = tnapi->tp; |
| 5108 | int work_done = 0; |
| 5109 | struct tg3_hw_status *sblk = tnapi->hw_status; |
| 5110 | |
| 5111 | while (1) { |
| 5112 | work_done = tg3_poll_work(tnapi, work_done, budget); |
| 5113 | |
| 5114 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) |
| 5115 | goto tx_recovery; |
| 5116 | |
| 5117 | if (unlikely(work_done >= budget)) |
| 5118 | break; |
| 5119 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 5120 | /* tp->last_tag is used in tg3_int_reenable() below |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5121 | * to tell the hw how much work has been processed, |
| 5122 | * so we must read it before checking for more work. |
| 5123 | */ |
| 5124 | tnapi->last_tag = sblk->status_tag; |
| 5125 | tnapi->last_irq_tag = tnapi->last_tag; |
| 5126 | rmb(); |
| 5127 | |
| 5128 | /* check for RX/TX work to do */ |
Matt Carlson | 6d40db7 | 2010-04-05 10:19:20 +0000 | [diff] [blame] | 5129 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
| 5130 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5131 | napi_complete(napi); |
| 5132 | /* Reenable interrupts. */ |
| 5133 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
| 5134 | mmiowb(); |
| 5135 | break; |
| 5136 | } |
| 5137 | } |
| 5138 | |
| 5139 | return work_done; |
| 5140 | |
| 5141 | tx_recovery: |
| 5142 | /* work_done is guaranteed to be less than budget. */ |
| 5143 | napi_complete(napi); |
| 5144 | schedule_work(&tp->reset_task); |
| 5145 | return work_done; |
| 5146 | } |
| 5147 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5148 | static int tg3_poll(struct napi_struct *napi, int budget) |
| 5149 | { |
Matt Carlson | 8ef0442 | 2009-08-28 14:01:37 +0000 | [diff] [blame] | 5150 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 5151 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5152 | int work_done = 0; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5153 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5154 | |
| 5155 | while (1) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5156 | tg3_poll_link(tp); |
| 5157 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5158 | work_done = tg3_poll_work(tnapi, work_done, budget); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5159 | |
| 5160 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) |
| 5161 | goto tx_recovery; |
| 5162 | |
| 5163 | if (unlikely(work_done >= budget)) |
| 5164 | break; |
| 5165 | |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5166 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5167 | /* tp->last_tag is used in tg3_int_reenable() below |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5168 | * to tell the hw how much work has been processed, |
| 5169 | * so we must read it before checking for more work. |
| 5170 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5171 | tnapi->last_tag = sblk->status_tag; |
| 5172 | tnapi->last_irq_tag = tnapi->last_tag; |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5173 | rmb(); |
| 5174 | } else |
| 5175 | sblk->status &= ~SD_STATUS_UPDATED; |
| 5176 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5177 | if (likely(!tg3_has_work(tnapi))) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5178 | napi_complete(napi); |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5179 | tg3_int_reenable(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5180 | break; |
| 5181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | } |
| 5183 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5184 | return work_done; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5185 | |
| 5186 | tx_recovery: |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5187 | /* work_done is guaranteed to be less than budget. */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5188 | napi_complete(napi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5189 | schedule_work(&tp->reset_task); |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5190 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5191 | } |
| 5192 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 5193 | static void tg3_napi_disable(struct tg3 *tp) |
| 5194 | { |
| 5195 | int i; |
| 5196 | |
| 5197 | for (i = tp->irq_cnt - 1; i >= 0; i--) |
| 5198 | napi_disable(&tp->napi[i].napi); |
| 5199 | } |
| 5200 | |
| 5201 | static void tg3_napi_enable(struct tg3 *tp) |
| 5202 | { |
| 5203 | int i; |
| 5204 | |
| 5205 | for (i = 0; i < tp->irq_cnt; i++) |
| 5206 | napi_enable(&tp->napi[i].napi); |
| 5207 | } |
| 5208 | |
| 5209 | static void tg3_napi_init(struct tg3 *tp) |
| 5210 | { |
| 5211 | int i; |
| 5212 | |
| 5213 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); |
| 5214 | for (i = 1; i < tp->irq_cnt; i++) |
| 5215 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); |
| 5216 | } |
| 5217 | |
| 5218 | static void tg3_napi_fini(struct tg3 *tp) |
| 5219 | { |
| 5220 | int i; |
| 5221 | |
| 5222 | for (i = 0; i < tp->irq_cnt; i++) |
| 5223 | netif_napi_del(&tp->napi[i].napi); |
| 5224 | } |
| 5225 | |
| 5226 | static inline void tg3_netif_stop(struct tg3 *tp) |
| 5227 | { |
| 5228 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 5229 | tg3_napi_disable(tp); |
| 5230 | netif_tx_disable(tp->dev); |
| 5231 | } |
| 5232 | |
| 5233 | static inline void tg3_netif_start(struct tg3 *tp) |
| 5234 | { |
| 5235 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
| 5236 | * appropriate so long as all callers are assured to |
| 5237 | * have free tx slots (such as after tg3_init_hw) |
| 5238 | */ |
| 5239 | netif_tx_wake_all_queues(tp->dev); |
| 5240 | |
| 5241 | tg3_napi_enable(tp); |
| 5242 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; |
| 5243 | tg3_enable_ints(tp); |
| 5244 | } |
| 5245 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5246 | static void tg3_irq_quiesce(struct tg3 *tp) |
| 5247 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5248 | int i; |
| 5249 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5250 | BUG_ON(tp->irq_sync); |
| 5251 | |
| 5252 | tp->irq_sync = 1; |
| 5253 | smp_mb(); |
| 5254 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5255 | for (i = 0; i < tp->irq_cnt; i++) |
| 5256 | synchronize_irq(tp->napi[i].irq_vec); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5257 | } |
| 5258 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5259 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
| 5260 | * If irq_sync is non-zero, then the IRQ handler must be synchronized |
| 5261 | * with as well. Most of the time, this is not necessary except when |
| 5262 | * shutting down the device. |
| 5263 | */ |
| 5264 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) |
| 5265 | { |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 5266 | spin_lock_bh(&tp->lock); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5267 | if (irq_sync) |
| 5268 | tg3_irq_quiesce(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | static inline void tg3_full_unlock(struct tg3 *tp) |
| 5272 | { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5273 | spin_unlock_bh(&tp->lock); |
| 5274 | } |
| 5275 | |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5276 | /* One-shot MSI handler - Chip automatically disables interrupt |
| 5277 | * after sending MSI so driver doesn't have to do it. |
| 5278 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5279 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5280 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5281 | struct tg3_napi *tnapi = dev_id; |
| 5282 | struct tg3 *tp = tnapi->tp; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5283 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5284 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 5285 | if (tnapi->rx_rcb) |
| 5286 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5287 | |
| 5288 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5289 | napi_schedule(&tnapi->napi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5290 | |
| 5291 | return IRQ_HANDLED; |
| 5292 | } |
| 5293 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5294 | /* MSI ISR - No need to check for interrupt sharing and no need to |
| 5295 | * flush status block and interrupt mailbox. PCI ordering rules |
| 5296 | * guarantee that MSI will arrive after the status block. |
| 5297 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5298 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5299 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5300 | struct tg3_napi *tnapi = dev_id; |
| 5301 | struct tg3 *tp = tnapi->tp; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5302 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5303 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 5304 | if (tnapi->rx_rcb) |
| 5305 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5306 | /* |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5307 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5308 | * chip-internal interrupt pending events. |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5309 | * Writing non-zero to intr-mbox-0 additional tells the |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5310 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5311 | * event coalescing. |
| 5312 | */ |
| 5313 | tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 5314 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5315 | napi_schedule(&tnapi->napi); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 5316 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5317 | return IRQ_RETVAL(1); |
| 5318 | } |
| 5319 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5320 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5322 | struct tg3_napi *tnapi = dev_id; |
| 5323 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5324 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | unsigned int handled = 1; |
| 5326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 5328 | * the CPU before the status block posted prior to the interrupt. |
| 5329 | * Reading the PCI State register will confirm whether the |
| 5330 | * interrupt is ours and will flush the status block. |
| 5331 | */ |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5332 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
| 5333 | if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) || |
| 5334 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 5335 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5336 | goto out; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5337 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | /* |
| 5341 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
| 5342 | * chip-internal interrupt pending events. |
| 5343 | * Writing non-zero to intr-mbox-0 additional tells the |
| 5344 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5345 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5346 | * |
| 5347 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 5348 | * spurious interrupts. The flush impacts performance but |
| 5349 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5350 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5351 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5352 | if (tg3_irq_sync(tp)) |
| 5353 | goto out; |
| 5354 | sblk->status &= ~SD_STATUS_UPDATED; |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5355 | if (likely(tg3_has_work(tnapi))) { |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5356 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5357 | napi_schedule(&tnapi->napi); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5358 | } else { |
| 5359 | /* No work, shared interrupt perhaps? re-enable |
| 5360 | * interrupts, and flush that PCI write |
| 5361 | */ |
| 5362 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, |
| 5363 | 0x00000000); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5364 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5365 | out: |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5366 | return IRQ_RETVAL(handled); |
| 5367 | } |
| 5368 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5369 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5370 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5371 | struct tg3_napi *tnapi = dev_id; |
| 5372 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5373 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5374 | unsigned int handled = 1; |
| 5375 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5376 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 5377 | * the CPU before the status block posted prior to the interrupt. |
| 5378 | * Reading the PCI State register will confirm whether the |
| 5379 | * interrupt is ours and will flush the status block. |
| 5380 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5381 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5382 | if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) || |
| 5383 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 5384 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5385 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | /* |
| 5390 | * writing any value to intr-mbox-0 clears PCI INTA# and |
| 5391 | * chip-internal interrupt pending events. |
| 5392 | * writing non-zero to intr-mbox-0 additional tells the |
| 5393 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5394 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5395 | * |
| 5396 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 5397 | * spurious interrupts. The flush impacts performance but |
| 5398 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5399 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5400 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5401 | |
| 5402 | /* |
| 5403 | * In a shared interrupt configuration, sometimes other devices' |
| 5404 | * interrupts will scream. We record the current status tag here |
| 5405 | * so that the above check can report that the screaming interrupts |
| 5406 | * are unhandled. Eventually they will be silenced. |
| 5407 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5408 | tnapi->last_irq_tag = sblk->status_tag; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5409 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5410 | if (tg3_irq_sync(tp)) |
| 5411 | goto out; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5412 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5413 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5414 | |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5415 | napi_schedule(&tnapi->napi); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5416 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5417 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5418 | return IRQ_RETVAL(handled); |
| 5419 | } |
| 5420 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5421 | /* ISR for interrupt test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5422 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5423 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5424 | struct tg3_napi *tnapi = dev_id; |
| 5425 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5426 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5427 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 5428 | if ((sblk->status & SD_STATUS_UPDATED) || |
| 5429 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 5430 | tg3_disable_ints(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5431 | return IRQ_RETVAL(1); |
| 5432 | } |
| 5433 | return IRQ_RETVAL(0); |
| 5434 | } |
| 5435 | |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 5436 | static int tg3_init_hw(struct tg3 *, int); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 5437 | static int tg3_halt(struct tg3 *, int, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5438 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5439 | /* Restart hardware after configuration changes, self-test, etc. |
| 5440 | * Invoked with tp->lock held. |
| 5441 | */ |
| 5442 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) |
Eric Dumazet | 78c6146 | 2008-04-24 23:33:06 -0700 | [diff] [blame] | 5443 | __releases(tp->lock) |
| 5444 | __acquires(tp->lock) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5445 | { |
| 5446 | int err; |
| 5447 | |
| 5448 | err = tg3_init_hw(tp, reset_phy); |
| 5449 | if (err) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5450 | netdev_err(tp->dev, |
| 5451 | "Failed to re-initialize device, aborting\n"); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5452 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 5453 | tg3_full_unlock(tp); |
| 5454 | del_timer_sync(&tp->timer); |
| 5455 | tp->irq_sync = 0; |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 5456 | tg3_napi_enable(tp); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5457 | dev_close(tp->dev); |
| 5458 | tg3_full_lock(tp, 0); |
| 5459 | } |
| 5460 | return err; |
| 5461 | } |
| 5462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5463 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5464 | static void tg3_poll_controller(struct net_device *dev) |
| 5465 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5466 | int i; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5467 | struct tg3 *tp = netdev_priv(dev); |
| 5468 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5469 | for (i = 0; i < tp->irq_cnt; i++) |
Louis Rilling | fe234f0 | 2010-03-09 06:14:41 +0000 | [diff] [blame] | 5470 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5471 | } |
| 5472 | #endif |
| 5473 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5474 | static void tg3_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5476 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5477 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5478 | unsigned int restart_timer; |
| 5479 | |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5480 | tg3_full_lock(tp, 0); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5481 | |
| 5482 | if (!netif_running(tp->dev)) { |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5483 | tg3_full_unlock(tp); |
| 5484 | return; |
| 5485 | } |
| 5486 | |
| 5487 | tg3_full_unlock(tp); |
| 5488 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5489 | tg3_phy_stop(tp); |
| 5490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | tg3_netif_stop(tp); |
| 5492 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5493 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | |
| 5495 | restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER; |
| 5496 | tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER; |
| 5497 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5498 | if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) { |
| 5499 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 5500 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 5501 | tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER; |
| 5502 | tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING; |
| 5503 | } |
| 5504 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 5505 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5506 | err = tg3_init_hw(tp, 1); |
| 5507 | if (err) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5508 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | |
| 5510 | tg3_netif_start(tp); |
| 5511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | if (restart_timer) |
| 5513 | mod_timer(&tp->timer, jiffies + 1); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5514 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5515 | out: |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5516 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5517 | |
| 5518 | if (!err) |
| 5519 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | } |
| 5521 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5522 | static void tg3_dump_short_state(struct tg3 *tp) |
| 5523 | { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 5524 | netdev_err(tp->dev, "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n", |
| 5525 | tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS)); |
| 5526 | netdev_err(tp->dev, "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n", |
| 5527 | tr32(RDMAC_STATUS), tr32(WDMAC_STATUS)); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5528 | } |
| 5529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5530 | static void tg3_tx_timeout(struct net_device *dev) |
| 5531 | { |
| 5532 | struct tg3 *tp = netdev_priv(dev); |
| 5533 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5534 | if (netif_msg_tx_err(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 5535 | netdev_err(dev, "transmit timed out, resetting\n"); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5536 | tg3_dump_short_state(tp); |
| 5537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | |
| 5539 | schedule_work(&tp->reset_task); |
| 5540 | } |
| 5541 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5542 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
| 5543 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) |
| 5544 | { |
| 5545 | u32 base = (u32) mapping & 0xffffffff; |
| 5546 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 5547 | return (base > 0xffffdcc0) && (base + len + 8 < base); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5548 | } |
| 5549 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5550 | /* Test for DMA addresses > 40-bit */ |
| 5551 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 5552 | int len) |
| 5553 | { |
| 5554 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) |
Michael Chan | 6728a8e | 2006-03-27 23:16:49 -0800 | [diff] [blame] | 5555 | if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 5556 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5557 | return 0; |
| 5558 | #else |
| 5559 | return 0; |
| 5560 | #endif |
| 5561 | } |
| 5562 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5563 | 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] | 5564 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5565 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5566 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
| 5567 | struct sk_buff *skb, u32 last_plus_one, |
| 5568 | u32 *start, u32 base_flags, u32 mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5569 | { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5570 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 5571 | struct sk_buff *new_skb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5572 | dma_addr_t new_addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | u32 entry = *start; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5574 | int i, ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5575 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 5576 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 5577 | new_skb = skb_copy(skb, GFP_ATOMIC); |
| 5578 | else { |
| 5579 | int more_headroom = 4 - ((unsigned long)skb->data & 3); |
| 5580 | |
| 5581 | new_skb = skb_copy_expand(skb, |
| 5582 | skb_headroom(skb) + more_headroom, |
| 5583 | skb_tailroom(skb), GFP_ATOMIC); |
| 5584 | } |
| 5585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5586 | if (!new_skb) { |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5587 | ret = -1; |
| 5588 | } else { |
| 5589 | /* New SKB is guaranteed to be linear. */ |
| 5590 | entry = *start; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5591 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
| 5592 | PCI_DMA_TODEVICE); |
| 5593 | /* Make sure the mapping succeeded */ |
| 5594 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { |
| 5595 | ret = -1; |
| 5596 | dev_kfree_skb(new_skb); |
| 5597 | new_skb = NULL; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5598 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5599 | /* Make sure new skb does not cross any 4G boundaries. |
| 5600 | * Drop the packet if it does. |
| 5601 | */ |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5602 | } else if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
| 5603 | tg3_4g_overflow_test(new_addr, new_skb->len)) { |
| 5604 | pci_unmap_single(tp->pdev, new_addr, new_skb->len, |
| 5605 | PCI_DMA_TODEVICE); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5606 | ret = -1; |
| 5607 | dev_kfree_skb(new_skb); |
| 5608 | new_skb = NULL; |
| 5609 | } else { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5610 | tg3_set_txd(tnapi, entry, new_addr, new_skb->len, |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5611 | base_flags, 1 | (mss << 1)); |
| 5612 | *start = NEXT_TX(entry); |
| 5613 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | } |
| 5615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | /* Now clean up the sw ring entries. */ |
| 5617 | i = 0; |
| 5618 | while (entry != last_plus_one) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5619 | int len; |
| 5620 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5621 | if (i == 0) |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5622 | len = skb_headlen(skb); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5623 | else |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5624 | len = skb_shinfo(skb)->frags[i-1].size; |
| 5625 | |
| 5626 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5627 | dma_unmap_addr(&tnapi->tx_buffers[entry], |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5628 | mapping), |
| 5629 | len, PCI_DMA_TODEVICE); |
| 5630 | if (i == 0) { |
| 5631 | tnapi->tx_buffers[entry].skb = new_skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5632 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5633 | new_addr); |
| 5634 | } else { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5635 | tnapi->tx_buffers[entry].skb = NULL; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5636 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5637 | entry = NEXT_TX(entry); |
| 5638 | i++; |
| 5639 | } |
| 5640 | |
| 5641 | dev_kfree_skb(skb); |
| 5642 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5643 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | } |
| 5645 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5646 | static void tg3_set_txd(struct tg3_napi *tnapi, int entry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5647 | dma_addr_t mapping, int len, u32 flags, |
| 5648 | u32 mss_and_is_end) |
| 5649 | { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5650 | struct tg3_tx_buffer_desc *txd = &tnapi->tx_ring[entry]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 | int is_end = (mss_and_is_end & 0x1); |
| 5652 | u32 mss = (mss_and_is_end >> 1); |
| 5653 | u32 vlan_tag = 0; |
| 5654 | |
| 5655 | if (is_end) |
| 5656 | flags |= TXD_FLAG_END; |
| 5657 | if (flags & TXD_FLAG_VLAN) { |
| 5658 | vlan_tag = flags >> 16; |
| 5659 | flags &= 0xffff; |
| 5660 | } |
| 5661 | vlan_tag |= (mss << TXD_MSS_SHIFT); |
| 5662 | |
| 5663 | txd->addr_hi = ((u64) mapping >> 32); |
| 5664 | txd->addr_lo = ((u64) mapping & 0xffffffff); |
| 5665 | txd->len_flags = (len << TXD_LEN_SHIFT) | flags; |
| 5666 | txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT; |
| 5667 | } |
| 5668 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5669 | /* hard_start_xmit for devices that don't have any bugs and |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 5670 | * 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] | 5671 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5672 | static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, |
| 5673 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5674 | { |
| 5675 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5676 | u32 len, entry, base_flags, mss; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5677 | dma_addr_t mapping; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5678 | struct tg3_napi *tnapi; |
| 5679 | struct netdev_queue *txq; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5680 | unsigned int i, last; |
| 5681 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5682 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 5683 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 5684 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5685 | tnapi++; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5686 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 5687 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5688 | * and TX reclaim runs via tp->napi.poll inside of a software |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5689 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 5690 | * no IRQ context deadlocks to worry about either. Rejoice! |
| 5691 | */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5692 | if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5693 | if (!netif_tx_queue_stopped(txq)) { |
| 5694 | netif_tx_stop_queue(txq); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5695 | |
| 5696 | /* This is a hard error, log it. */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5697 | netdev_err(dev, |
| 5698 | "BUG! Tx Ring full when queue awake!\n"); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5699 | } |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5700 | return NETDEV_TX_BUSY; |
| 5701 | } |
| 5702 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5703 | entry = tnapi->tx_prod; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5704 | base_flags = 0; |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 5705 | mss = skb_shinfo(skb)->gso_size; |
| 5706 | if (mss) { |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5707 | int tcp_opt_len, ip_tcp_len; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5708 | u32 hdrlen; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5709 | |
| 5710 | if (skb_header_cloned(skb) && |
| 5711 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { |
| 5712 | dev_kfree_skb(skb); |
| 5713 | goto out_unlock; |
| 5714 | } |
| 5715 | |
Matt Carlson | 02e9608 | 2010-09-15 08:59:59 +0000 | [diff] [blame] | 5716 | if (skb_is_gso_v6(skb)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5717 | hdrlen = skb_headlen(skb) - ETH_HLEN; |
Matt Carlson | 02e9608 | 2010-09-15 08:59:59 +0000 | [diff] [blame] | 5718 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5719 | struct iphdr *iph = ip_hdr(skb); |
| 5720 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 5721 | tcp_opt_len = tcp_optlen(skb); |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 5722 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 5723 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5724 | iph->check = 0; |
| 5725 | iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5726 | hdrlen = ip_tcp_len + tcp_opt_len; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 5727 | } |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5728 | |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 5729 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5730 | mss |= (hdrlen & 0xc) << 12; |
| 5731 | if (hdrlen & 0x10) |
| 5732 | base_flags |= 0x00000010; |
| 5733 | base_flags |= (hdrlen & 0x3e0) << 5; |
| 5734 | } else |
| 5735 | mss |= hdrlen << 9; |
| 5736 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5737 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 5738 | TXD_FLAG_CPU_POST_DMA); |
| 5739 | |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5740 | tcp_hdr(skb)->check = 0; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5741 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5742 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5743 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 5744 | } |
| 5745 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5746 | #if TG3_VLAN_TAG_USED |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 5747 | if (vlan_tx_tag_present(skb)) |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5748 | base_flags |= (TXD_FLAG_VLAN | |
| 5749 | (vlan_tx_tag_get(skb) << 16)); |
| 5750 | #endif |
| 5751 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5752 | len = skb_headlen(skb); |
| 5753 | |
| 5754 | /* Queue skb data, a.k.a. the main skb fragment. */ |
| 5755 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
| 5756 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5757 | dev_kfree_skb(skb); |
| 5758 | goto out_unlock; |
| 5759 | } |
| 5760 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5761 | tnapi->tx_buffers[entry].skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5762 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5763 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 5764 | if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) && |
Matt Carlson | 8fc2f99 | 2010-12-06 08:28:49 +0000 | [diff] [blame] | 5765 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5766 | base_flags |= TXD_FLAG_JMB_PKT; |
| 5767 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5768 | tg3_set_txd(tnapi, entry, mapping, len, base_flags, |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5769 | (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); |
| 5770 | |
| 5771 | entry = NEXT_TX(entry); |
| 5772 | |
| 5773 | /* Now loop through additional data fragments, and queue them. */ |
| 5774 | if (skb_shinfo(skb)->nr_frags > 0) { |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5775 | last = skb_shinfo(skb)->nr_frags - 1; |
| 5776 | for (i = 0; i <= last; i++) { |
| 5777 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 5778 | |
| 5779 | len = frag->size; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5780 | mapping = pci_map_page(tp->pdev, |
| 5781 | frag->page, |
| 5782 | frag->page_offset, |
| 5783 | len, PCI_DMA_TODEVICE); |
| 5784 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 5785 | goto dma_error; |
| 5786 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5787 | tnapi->tx_buffers[entry].skb = NULL; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5788 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5789 | mapping); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5790 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5791 | tg3_set_txd(tnapi, entry, mapping, len, |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5792 | base_flags, (i == last) | (mss << 1)); |
| 5793 | |
| 5794 | entry = NEXT_TX(entry); |
| 5795 | } |
| 5796 | } |
| 5797 | |
| 5798 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5799 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5800 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5801 | tnapi->tx_prod = entry; |
| 5802 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5803 | netif_tx_stop_queue(txq); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 5804 | |
| 5805 | /* netif_tx_stop_queue() must be done before checking |
| 5806 | * checking tx index in tg3_tx_avail() below, because in |
| 5807 | * tg3_tx(), we update tx index before checking for |
| 5808 | * netif_tx_queue_stopped(). |
| 5809 | */ |
| 5810 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5811 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5812 | netif_tx_wake_queue(txq); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5813 | } |
| 5814 | |
| 5815 | out_unlock: |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 5816 | mmiowb(); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5817 | |
| 5818 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5819 | |
| 5820 | dma_error: |
| 5821 | last = i; |
| 5822 | entry = tnapi->tx_prod; |
| 5823 | tnapi->tx_buffers[entry].skb = NULL; |
| 5824 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5825 | dma_unmap_addr(&tnapi->tx_buffers[entry], mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5826 | skb_headlen(skb), |
| 5827 | PCI_DMA_TODEVICE); |
| 5828 | for (i = 0; i <= last; i++) { |
| 5829 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 5830 | entry = NEXT_TX(entry); |
| 5831 | |
| 5832 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 5833 | dma_unmap_addr(&tnapi->tx_buffers[entry], |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5834 | mapping), |
| 5835 | frag->size, PCI_DMA_TODEVICE); |
| 5836 | } |
| 5837 | |
| 5838 | dev_kfree_skb(skb); |
| 5839 | return NETDEV_TX_OK; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5840 | } |
| 5841 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5842 | static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *, |
| 5843 | struct net_device *); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5844 | |
| 5845 | /* Use GSO to workaround a rare TSO bug that may be triggered when the |
| 5846 | * TSO header is greater than 80 bytes. |
| 5847 | */ |
| 5848 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) |
| 5849 | { |
| 5850 | struct sk_buff *segs, *nskb; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5851 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5852 | |
| 5853 | /* Estimate the number of fragments in the worst case */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5854 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5855 | netif_stop_queue(tp->dev); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 5856 | |
| 5857 | /* netif_tx_stop_queue() must be done before checking |
| 5858 | * checking tx index in tg3_tx_avail() below, because in |
| 5859 | * tg3_tx(), we update tx index before checking for |
| 5860 | * netif_tx_queue_stopped(). |
| 5861 | */ |
| 5862 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5863 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 5864 | return NETDEV_TX_BUSY; |
| 5865 | |
| 5866 | netif_wake_queue(tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame] | 5870 | if (IS_ERR(segs)) |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5871 | goto tg3_tso_bug_end; |
| 5872 | |
| 5873 | do { |
| 5874 | nskb = segs; |
| 5875 | segs = segs->next; |
| 5876 | nskb->next = NULL; |
| 5877 | tg3_start_xmit_dma_bug(nskb, tp->dev); |
| 5878 | } while (segs); |
| 5879 | |
| 5880 | tg3_tso_bug_end: |
| 5881 | dev_kfree_skb(skb); |
| 5882 | |
| 5883 | return NETDEV_TX_OK; |
| 5884 | } |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5885 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5886 | /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and |
| 5887 | * support TG3_FLG2_HW_TSO_1 or firmware TSO only. |
| 5888 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5889 | static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *skb, |
| 5890 | struct net_device *dev) |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5891 | { |
| 5892 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5893 | u32 len, entry, base_flags, mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5894 | int would_hit_hwbug; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5895 | dma_addr_t mapping; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5896 | struct tg3_napi *tnapi; |
| 5897 | struct netdev_queue *txq; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5898 | unsigned int i, last; |
| 5899 | |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5900 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 5901 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 5902 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5903 | tnapi++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5904 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 5905 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5906 | * 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] | 5907 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 5908 | * no IRQ context deadlocks to worry about either. Rejoice! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5909 | */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5910 | if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5911 | if (!netif_tx_queue_stopped(txq)) { |
| 5912 | netif_tx_stop_queue(txq); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 5913 | |
| 5914 | /* This is a hard error, log it. */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 5915 | netdev_err(dev, |
| 5916 | "BUG! Tx Ring full when queue awake!\n"); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 5917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5918 | return NETDEV_TX_BUSY; |
| 5919 | } |
| 5920 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5921 | entry = tnapi->tx_prod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5922 | base_flags = 0; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 5923 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5924 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5925 | |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 5926 | mss = skb_shinfo(skb)->gso_size; |
| 5927 | if (mss) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5928 | struct iphdr *iph; |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 5929 | u32 tcp_opt_len, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5930 | |
| 5931 | if (skb_header_cloned(skb) && |
| 5932 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { |
| 5933 | dev_kfree_skb(skb); |
| 5934 | goto out_unlock; |
| 5935 | } |
| 5936 | |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 5937 | iph = ip_hdr(skb); |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 5938 | tcp_opt_len = tcp_optlen(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | |
Matt Carlson | 02e9608 | 2010-09-15 08:59:59 +0000 | [diff] [blame] | 5940 | if (skb_is_gso_v6(skb)) { |
Matt Carlson | 34195c3 | 2010-07-11 09:31:42 +0000 | [diff] [blame] | 5941 | hdr_len = skb_headlen(skb) - ETH_HLEN; |
| 5942 | } else { |
| 5943 | u32 ip_tcp_len; |
| 5944 | |
| 5945 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); |
| 5946 | hdr_len = ip_tcp_len + tcp_opt_len; |
| 5947 | |
| 5948 | iph->check = 0; |
| 5949 | iph->tot_len = htons(mss + hdr_len); |
| 5950 | } |
| 5951 | |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5952 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 5953 | (tp->tg3_flags2 & TG3_FLG2_TSO_BUG)) |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 5954 | return tg3_tso_bug(tp, skb); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5956 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 5957 | TXD_FLAG_CPU_POST_DMA); |
| 5958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5959 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) { |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5960 | tcp_hdr(skb)->check = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5961 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5962 | } else |
| 5963 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 5964 | iph->daddr, 0, |
| 5965 | IPPROTO_TCP, |
| 5966 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5967 | |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 5968 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) { |
| 5969 | mss |= (hdr_len & 0xc) << 12; |
| 5970 | if (hdr_len & 0x10) |
| 5971 | base_flags |= 0x00000010; |
| 5972 | base_flags |= (hdr_len & 0x3e0) << 5; |
| 5973 | } else if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 5974 | mss |= hdr_len << 9; |
| 5975 | else if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_1) || |
| 5976 | 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] | 5977 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5978 | int tsflags; |
| 5979 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5980 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5981 | mss |= (tsflags << 11); |
| 5982 | } |
| 5983 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5984 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5985 | int tsflags; |
| 5986 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5987 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5988 | base_flags |= tsflags << 12; |
| 5989 | } |
| 5990 | } |
| 5991 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5992 | #if TG3_VLAN_TAG_USED |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 5993 | if (vlan_tx_tag_present(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5994 | base_flags |= (TXD_FLAG_VLAN | |
| 5995 | (vlan_tx_tag_get(skb) << 16)); |
| 5996 | #endif |
| 5997 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 5998 | if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) && |
Matt Carlson | 8fc2f99 | 2010-12-06 08:28:49 +0000 | [diff] [blame] | 5999 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 6000 | base_flags |= TXD_FLAG_JMB_PKT; |
| 6001 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6002 | len = skb_headlen(skb); |
| 6003 | |
| 6004 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
| 6005 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 6006 | dev_kfree_skb(skb); |
| 6007 | goto out_unlock; |
| 6008 | } |
| 6009 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6010 | tnapi->tx_buffers[entry].skb = skb; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6011 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6012 | |
| 6013 | would_hit_hwbug = 0; |
| 6014 | |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 6015 | if ((tp->tg3_flags3 & TG3_FLG3_SHORT_DMA_BUG) && len <= 8) |
| 6016 | would_hit_hwbug = 1; |
| 6017 | |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6018 | if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
| 6019 | tg3_4g_overflow_test(mapping, len)) |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 6020 | would_hit_hwbug = 1; |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6021 | |
| 6022 | if ((tp->tg3_flags3 & TG3_FLG3_40BIT_DMA_LIMIT_BUG) && |
| 6023 | tg3_40bit_overflow_test(tp, mapping, len)) |
| 6024 | would_hit_hwbug = 1; |
| 6025 | |
| 6026 | if (tp->tg3_flags3 & TG3_FLG3_5701_DMA_BUG) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6027 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6028 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6029 | tg3_set_txd(tnapi, entry, mapping, len, base_flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6030 | (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); |
| 6031 | |
| 6032 | entry = NEXT_TX(entry); |
| 6033 | |
| 6034 | /* Now loop through additional data fragments, and queue them. */ |
| 6035 | if (skb_shinfo(skb)->nr_frags > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6036 | last = skb_shinfo(skb)->nr_frags - 1; |
| 6037 | for (i = 0; i <= last; i++) { |
| 6038 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 6039 | |
| 6040 | len = frag->size; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6041 | mapping = pci_map_page(tp->pdev, |
| 6042 | frag->page, |
| 6043 | frag->page_offset, |
| 6044 | len, PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6045 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6046 | tnapi->tx_buffers[entry].skb = NULL; |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6047 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6048 | mapping); |
| 6049 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 6050 | goto dma_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6051 | |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 6052 | if ((tp->tg3_flags3 & TG3_FLG3_SHORT_DMA_BUG) && |
| 6053 | len <= 8) |
| 6054 | would_hit_hwbug = 1; |
| 6055 | |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6056 | if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
| 6057 | tg3_4g_overflow_test(mapping, len)) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6058 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6059 | |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 6060 | if ((tp->tg3_flags3 & TG3_FLG3_40BIT_DMA_LIMIT_BUG) && |
| 6061 | tg3_40bit_overflow_test(tp, mapping, len)) |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 6062 | would_hit_hwbug = 1; |
| 6063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6064 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6065 | tg3_set_txd(tnapi, entry, mapping, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6066 | base_flags, (i == last)|(mss << 1)); |
| 6067 | else |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6068 | tg3_set_txd(tnapi, entry, mapping, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6069 | base_flags, (i == last)); |
| 6070 | |
| 6071 | entry = NEXT_TX(entry); |
| 6072 | } |
| 6073 | } |
| 6074 | |
| 6075 | if (would_hit_hwbug) { |
| 6076 | u32 last_plus_one = entry; |
| 6077 | u32 start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6078 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6079 | start = entry - 1 - skb_shinfo(skb)->nr_frags; |
| 6080 | start &= (TG3_TX_RING_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6081 | |
| 6082 | /* If the workaround fails due to memory/mapping |
| 6083 | * failure, silently drop this packet. |
| 6084 | */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6085 | if (tigon3_dma_hwbug_workaround(tnapi, skb, last_plus_one, |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 6086 | &start, base_flags, mss)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | goto out_unlock; |
| 6088 | |
| 6089 | entry = start; |
| 6090 | } |
| 6091 | |
| 6092 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6093 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6094 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6095 | tnapi->tx_prod = entry; |
| 6096 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6097 | netif_tx_stop_queue(txq); |
Matt Carlson | f65aac1 | 2010-08-02 11:26:03 +0000 | [diff] [blame] | 6098 | |
| 6099 | /* netif_tx_stop_queue() must be done before checking |
| 6100 | * checking tx index in tg3_tx_avail() below, because in |
| 6101 | * tg3_tx(), we update tx index before checking for |
| 6102 | * netif_tx_queue_stopped(). |
| 6103 | */ |
| 6104 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 6105 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 6106 | netif_tx_wake_queue(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 6107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6108 | |
| 6109 | out_unlock: |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 6110 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6111 | |
| 6112 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6113 | |
| 6114 | dma_error: |
| 6115 | last = i; |
| 6116 | entry = tnapi->tx_prod; |
| 6117 | tnapi->tx_buffers[entry].skb = NULL; |
| 6118 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6119 | dma_unmap_addr(&tnapi->tx_buffers[entry], mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6120 | skb_headlen(skb), |
| 6121 | PCI_DMA_TODEVICE); |
| 6122 | for (i = 0; i <= last; i++) { |
| 6123 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 6124 | entry = NEXT_TX(entry); |
| 6125 | |
| 6126 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6127 | dma_unmap_addr(&tnapi->tx_buffers[entry], |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6128 | mapping), |
| 6129 | frag->size, PCI_DMA_TODEVICE); |
| 6130 | } |
| 6131 | |
| 6132 | dev_kfree_skb(skb); |
| 6133 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
| 6137 | int new_mtu) |
| 6138 | { |
| 6139 | dev->mtu = new_mtu; |
| 6140 | |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6141 | if (new_mtu > ETH_DATA_LEN) { |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 6142 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) { |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6143 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE; |
| 6144 | ethtool_op_set_tso(dev, 0); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 6145 | } else { |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6146 | tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 6147 | } |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6148 | } else { |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 6149 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6150 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 6151 | tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE; |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 6152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) |
| 6156 | { |
| 6157 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6158 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6159 | |
| 6160 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) |
| 6161 | return -EINVAL; |
| 6162 | |
| 6163 | if (!netif_running(dev)) { |
| 6164 | /* We'll just catch it later when the |
| 6165 | * device is up'd. |
| 6166 | */ |
| 6167 | tg3_set_mtu(dev, tp, new_mtu); |
| 6168 | return 0; |
| 6169 | } |
| 6170 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 6171 | tg3_phy_stop(tp); |
| 6172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6173 | tg3_netif_stop(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6174 | |
| 6175 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6176 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 6177 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6178 | |
| 6179 | tg3_set_mtu(dev, tp, new_mtu); |
| 6180 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6181 | err = tg3_restart_hw(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6182 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6183 | if (!err) |
| 6184 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6185 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 6186 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6187 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 6188 | if (!err) |
| 6189 | tg3_phy_start(tp); |
| 6190 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 6191 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6192 | } |
| 6193 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6194 | static void tg3_rx_prodring_free(struct tg3 *tp, |
| 6195 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6196 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6197 | int i; |
| 6198 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6199 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6200 | 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] | 6201 | i = (i + 1) & tp->rx_std_ring_mask) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6202 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
| 6203 | tp->rx_pkt_map_sz); |
| 6204 | |
| 6205 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
| 6206 | for (i = tpr->rx_jmb_cons_idx; |
| 6207 | i != tpr->rx_jmb_prod_idx; |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6208 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6209 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
| 6210 | TG3_RX_JMB_MAP_SZ); |
| 6211 | } |
| 6212 | } |
| 6213 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6214 | return; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6216 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6217 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6218 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
| 6219 | tp->rx_pkt_map_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6220 | |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 6221 | if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && |
| 6222 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6223 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6224 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
| 6225 | TG3_RX_JMB_MAP_SZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6226 | } |
| 6227 | } |
| 6228 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 6229 | /* Initialize rx rings for packet processing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6230 | * |
| 6231 | * The chip has been shut down and the driver detached from |
| 6232 | * the networking, so no interrupts or new tx packets will |
| 6233 | * end up in the driver. tp->{tx,}lock are held and thus |
| 6234 | * we may not sleep. |
| 6235 | */ |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6236 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
| 6237 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6238 | { |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6239 | u32 i, rx_pkt_dma_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6240 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6241 | tpr->rx_std_cons_idx = 0; |
| 6242 | tpr->rx_std_prod_idx = 0; |
| 6243 | tpr->rx_jmb_cons_idx = 0; |
| 6244 | tpr->rx_jmb_prod_idx = 0; |
| 6245 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6246 | if (tpr != &tp->napi[0].prodring) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6247 | memset(&tpr->rx_std_buffers[0], 0, |
| 6248 | TG3_RX_STD_BUFF_RING_SIZE(tp)); |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 6249 | if (tpr->rx_jmb_buffers) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6250 | memset(&tpr->rx_jmb_buffers[0], 0, |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6251 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6252 | goto done; |
| 6253 | } |
| 6254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6255 | /* Zero out all descriptors. */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6256 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6257 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6258 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 6259 | if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) && |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6260 | tp->dev->mtu > ETH_DATA_LEN) |
| 6261 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; |
| 6262 | 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] | 6263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6264 | /* Initialize invariants of the rings, we only set this |
| 6265 | * stuff once. This works because the card does not |
| 6266 | * write into the rx buffer posting rings. |
| 6267 | */ |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6268 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | struct tg3_rx_buffer_desc *rxd; |
| 6270 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6271 | rxd = &tpr->rx_std[i]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6272 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6273 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
| 6274 | rxd->opaque = (RXD_OPAQUE_RING_STD | |
| 6275 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 6276 | } |
| 6277 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6278 | /* Now allocate fresh SKBs for each rx ring. */ |
| 6279 | for (i = 0; i < tp->rx_pending; i++) { |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 6280 | 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] | 6281 | netdev_warn(tp->dev, |
| 6282 | "Using a smaller RX standard ring. Only " |
| 6283 | "%d out of %d buffers were allocated " |
| 6284 | "successfully\n", i, tp->rx_pending); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6285 | if (i == 0) |
| 6286 | goto initfail; |
| 6287 | tp->rx_pending = i; |
| 6288 | break; |
| 6289 | } |
| 6290 | } |
| 6291 | |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 6292 | if (!(tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) || |
| 6293 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6294 | goto done; |
| 6295 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6296 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6297 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6298 | if (!(tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)) |
| 6299 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6300 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6301 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6302 | struct tg3_rx_buffer_desc *rxd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6303 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6304 | rxd = &tpr->rx_jmb[i].std; |
| 6305 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; |
| 6306 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | |
| 6307 | RXD_FLAG_JUMBO; |
| 6308 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | |
| 6309 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 6310 | } |
| 6311 | |
| 6312 | for (i = 0; i < tp->rx_jumbo_pending; i++) { |
| 6313 | 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] | 6314 | netdev_warn(tp->dev, |
| 6315 | "Using a smaller RX jumbo ring. Only %d " |
| 6316 | "out of %d buffers were allocated " |
| 6317 | "successfully\n", i, tp->rx_jumbo_pending); |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6318 | if (i == 0) |
| 6319 | goto initfail; |
| 6320 | tp->rx_jumbo_pending = i; |
| 6321 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | } |
| 6323 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6324 | |
| 6325 | done: |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 6326 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6327 | |
| 6328 | initfail: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6329 | tg3_rx_prodring_free(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6330 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6331 | } |
| 6332 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6333 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
| 6334 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6335 | { |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6336 | kfree(tpr->rx_std_buffers); |
| 6337 | tpr->rx_std_buffers = NULL; |
| 6338 | kfree(tpr->rx_jmb_buffers); |
| 6339 | tpr->rx_jmb_buffers = NULL; |
| 6340 | if (tpr->rx_std) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6341 | dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
| 6342 | tpr->rx_std, tpr->rx_std_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6343 | tpr->rx_std = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6344 | } |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6345 | if (tpr->rx_jmb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6346 | dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
| 6347 | tpr->rx_jmb, tpr->rx_jmb_mapping); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6348 | tpr->rx_jmb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6349 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6350 | } |
| 6351 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6352 | static int tg3_rx_prodring_init(struct tg3 *tp, |
| 6353 | struct tg3_rx_prodring_set *tpr) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6354 | { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6355 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
| 6356 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6357 | if (!tpr->rx_std_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6358 | return -ENOMEM; |
| 6359 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6360 | tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
| 6361 | TG3_RX_STD_RING_BYTES(tp), |
| 6362 | &tpr->rx_std_mapping, |
| 6363 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6364 | if (!tpr->rx_std) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6365 | goto err_out; |
| 6366 | |
Matt Carlson | 4803572 | 2010-10-14 10:37:43 +0000 | [diff] [blame] | 6367 | if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && |
| 6368 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 6369 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6370 | GFP_KERNEL); |
| 6371 | if (!tpr->rx_jmb_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6372 | goto err_out; |
| 6373 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6374 | tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
| 6375 | TG3_RX_JMB_RING_BYTES(tp), |
| 6376 | &tpr->rx_jmb_mapping, |
| 6377 | GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6378 | if (!tpr->rx_jmb) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6379 | goto err_out; |
| 6380 | } |
| 6381 | |
| 6382 | return 0; |
| 6383 | |
| 6384 | err_out: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6385 | tg3_rx_prodring_fini(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6386 | return -ENOMEM; |
| 6387 | } |
| 6388 | |
| 6389 | /* Free up pending packets in all rx/tx rings. |
| 6390 | * |
| 6391 | * The chip has been shut down and the driver detached from |
| 6392 | * the networking, so no interrupts or new tx packets will |
| 6393 | * end up in the driver. tp->{tx,}lock is not held and we are not |
| 6394 | * in an interrupt context and thus may sleep. |
| 6395 | */ |
| 6396 | static void tg3_free_rings(struct tg3 *tp) |
| 6397 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6398 | int i, j; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6399 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6400 | for (j = 0; j < tp->irq_cnt; j++) { |
| 6401 | struct tg3_napi *tnapi = &tp->napi[j]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6402 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6403 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
Matt Carlson | b28f642 | 2010-06-05 17:24:32 +0000 | [diff] [blame] | 6404 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6405 | if (!tnapi->tx_buffers) |
| 6406 | continue; |
| 6407 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6408 | for (i = 0; i < TG3_TX_RING_SIZE; ) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6409 | struct ring_info *txp; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6410 | struct sk_buff *skb; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6411 | unsigned int k; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6412 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6413 | txp = &tnapi->tx_buffers[i]; |
| 6414 | skb = txp->skb; |
| 6415 | |
| 6416 | if (skb == NULL) { |
| 6417 | i++; |
| 6418 | continue; |
| 6419 | } |
| 6420 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6421 | pci_unmap_single(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6422 | dma_unmap_addr(txp, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6423 | skb_headlen(skb), |
| 6424 | PCI_DMA_TODEVICE); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6425 | txp->skb = NULL; |
| 6426 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6427 | i++; |
| 6428 | |
| 6429 | for (k = 0; k < skb_shinfo(skb)->nr_frags; k++) { |
| 6430 | txp = &tnapi->tx_buffers[i & (TG3_TX_RING_SIZE - 1)]; |
| 6431 | pci_unmap_page(tp->pdev, |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 6432 | dma_unmap_addr(txp, mapping), |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6433 | skb_shinfo(skb)->frags[k].size, |
| 6434 | PCI_DMA_TODEVICE); |
| 6435 | i++; |
| 6436 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6437 | |
| 6438 | dev_kfree_skb_any(skb); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6439 | } |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6440 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6441 | } |
| 6442 | |
| 6443 | /* Initialize tx/rx rings for packet processing. |
| 6444 | * |
| 6445 | * The chip has been shut down and the driver detached from |
| 6446 | * the networking, so no interrupts or new tx packets will |
| 6447 | * end up in the driver. tp->{tx,}lock are held and thus |
| 6448 | * we may not sleep. |
| 6449 | */ |
| 6450 | static int tg3_init_rings(struct tg3 *tp) |
| 6451 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6452 | int i; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6453 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6454 | /* Free up all the SKBs. */ |
| 6455 | tg3_free_rings(tp); |
| 6456 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6457 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6458 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6459 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6460 | tnapi->last_tag = 0; |
| 6461 | tnapi->last_irq_tag = 0; |
| 6462 | tnapi->hw_status->status = 0; |
| 6463 | tnapi->hw_status->status_tag = 0; |
| 6464 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 6465 | |
| 6466 | tnapi->tx_prod = 0; |
| 6467 | tnapi->tx_cons = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6468 | if (tnapi->tx_ring) |
| 6469 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6470 | |
| 6471 | tnapi->rx_rcb_ptr = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6472 | if (tnapi->rx_rcb) |
| 6473 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6474 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6475 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6476 | tg3_free_rings(tp); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6477 | return -ENOMEM; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6478 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6479 | } |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6480 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6481 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6482 | } |
| 6483 | |
| 6484 | /* |
| 6485 | * Must not be invoked with interrupt sources disabled and |
| 6486 | * the hardware shutdown down. |
| 6487 | */ |
| 6488 | static void tg3_free_consistent(struct tg3 *tp) |
| 6489 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6490 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6491 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6492 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6493 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 6494 | |
| 6495 | if (tnapi->tx_ring) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6496 | dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6497 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
| 6498 | tnapi->tx_ring = NULL; |
| 6499 | } |
| 6500 | |
| 6501 | kfree(tnapi->tx_buffers); |
| 6502 | tnapi->tx_buffers = NULL; |
| 6503 | |
| 6504 | if (tnapi->rx_rcb) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6505 | dma_free_coherent(&tp->pdev->dev, |
| 6506 | TG3_RX_RCB_RING_BYTES(tp), |
| 6507 | tnapi->rx_rcb, |
| 6508 | tnapi->rx_rcb_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6509 | tnapi->rx_rcb = NULL; |
| 6510 | } |
| 6511 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6512 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
| 6513 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6514 | if (tnapi->hw_status) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6515 | dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
| 6516 | tnapi->hw_status, |
| 6517 | tnapi->status_mapping); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6518 | tnapi->hw_status = NULL; |
| 6519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6520 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6522 | if (tp->hw_stats) { |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6523 | dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
| 6524 | tp->hw_stats, tp->stats_mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6525 | tp->hw_stats = NULL; |
| 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | /* |
| 6530 | * Must not be invoked with interrupt sources disabled and |
| 6531 | * the hardware shutdown down. Can sleep. |
| 6532 | */ |
| 6533 | static int tg3_alloc_consistent(struct tg3 *tp) |
| 6534 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6535 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6536 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6537 | tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
| 6538 | sizeof(struct tg3_hw_stats), |
| 6539 | &tp->stats_mapping, |
| 6540 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6541 | if (!tp->hw_stats) |
| 6542 | goto err_out; |
| 6543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6544 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 6545 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6546 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6547 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6548 | struct tg3_hw_status *sblk; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6549 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6550 | tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
| 6551 | TG3_HW_STATUS_SIZE, |
| 6552 | &tnapi->status_mapping, |
| 6553 | GFP_KERNEL); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6554 | if (!tnapi->hw_status) |
| 6555 | goto err_out; |
| 6556 | |
| 6557 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6558 | sblk = tnapi->hw_status; |
| 6559 | |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 6560 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
| 6561 | goto err_out; |
| 6562 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 6563 | /* If multivector TSS is enabled, vector 0 does not handle |
| 6564 | * tx interrupts. Don't allocate any resources for it. |
| 6565 | */ |
| 6566 | if ((!i && !(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) || |
| 6567 | (i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS))) { |
| 6568 | tnapi->tx_buffers = kzalloc(sizeof(struct ring_info) * |
| 6569 | TG3_TX_RING_SIZE, |
| 6570 | GFP_KERNEL); |
| 6571 | if (!tnapi->tx_buffers) |
| 6572 | goto err_out; |
| 6573 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6574 | tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, |
| 6575 | TG3_TX_RING_BYTES, |
| 6576 | &tnapi->tx_desc_mapping, |
| 6577 | GFP_KERNEL); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 6578 | if (!tnapi->tx_ring) |
| 6579 | goto err_out; |
| 6580 | } |
| 6581 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6582 | /* |
| 6583 | * When RSS is enabled, the status block format changes |
| 6584 | * slightly. The "rx_jumbo_consumer", "reserved", |
| 6585 | * and "rx_mini_consumer" members get mapped to the |
| 6586 | * other three rx return ring producer indexes. |
| 6587 | */ |
| 6588 | switch (i) { |
| 6589 | default: |
| 6590 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
| 6591 | break; |
| 6592 | case 2: |
| 6593 | tnapi->rx_rcb_prod_idx = &sblk->rx_jumbo_consumer; |
| 6594 | break; |
| 6595 | case 3: |
| 6596 | tnapi->rx_rcb_prod_idx = &sblk->reserved; |
| 6597 | break; |
| 6598 | case 4: |
| 6599 | tnapi->rx_rcb_prod_idx = &sblk->rx_mini_consumer; |
| 6600 | break; |
| 6601 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6602 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6603 | /* |
| 6604 | * If multivector RSS is enabled, vector 0 does not handle |
| 6605 | * rx or tx interrupts. Don't allocate any resources for it. |
| 6606 | */ |
| 6607 | if (!i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) |
| 6608 | continue; |
| 6609 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 6610 | tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, |
| 6611 | TG3_RX_RCB_RING_BYTES(tp), |
| 6612 | &tnapi->rx_rcb_mapping, |
| 6613 | GFP_KERNEL); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6614 | if (!tnapi->rx_rcb) |
| 6615 | goto err_out; |
| 6616 | |
| 6617 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6618 | } |
| 6619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6620 | return 0; |
| 6621 | |
| 6622 | err_out: |
| 6623 | tg3_free_consistent(tp); |
| 6624 | return -ENOMEM; |
| 6625 | } |
| 6626 | |
| 6627 | #define MAX_WAIT_CNT 1000 |
| 6628 | |
| 6629 | /* To stop a block, clear the enable bit and poll till it |
| 6630 | * clears. tp->lock is held. |
| 6631 | */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6632 | 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] | 6633 | { |
| 6634 | unsigned int i; |
| 6635 | u32 val; |
| 6636 | |
| 6637 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 6638 | switch (ofs) { |
| 6639 | case RCVLSC_MODE: |
| 6640 | case DMAC_MODE: |
| 6641 | case MBFREE_MODE: |
| 6642 | case BUFMGR_MODE: |
| 6643 | case MEMARB_MODE: |
| 6644 | /* We can't enable/disable these bits of the |
| 6645 | * 5705/5750, just say success. |
| 6646 | */ |
| 6647 | return 0; |
| 6648 | |
| 6649 | default: |
| 6650 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6652 | } |
| 6653 | |
| 6654 | val = tr32(ofs); |
| 6655 | val &= ~enable_bit; |
| 6656 | tw32_f(ofs, val); |
| 6657 | |
| 6658 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 6659 | udelay(100); |
| 6660 | val = tr32(ofs); |
| 6661 | if ((val & enable_bit) == 0) |
| 6662 | break; |
| 6663 | } |
| 6664 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6665 | if (i == MAX_WAIT_CNT && !silent) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 6666 | dev_err(&tp->pdev->dev, |
| 6667 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", |
| 6668 | ofs, enable_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6669 | return -ENODEV; |
| 6670 | } |
| 6671 | |
| 6672 | return 0; |
| 6673 | } |
| 6674 | |
| 6675 | /* tp->lock is held. */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6676 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6677 | { |
| 6678 | int i, err; |
| 6679 | |
| 6680 | tg3_disable_ints(tp); |
| 6681 | |
| 6682 | tp->rx_mode &= ~RX_MODE_ENABLE; |
| 6683 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 6684 | udelay(10); |
| 6685 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6686 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
| 6687 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); |
| 6688 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); |
| 6689 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); |
| 6690 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); |
| 6691 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6692 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6693 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); |
| 6694 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); |
| 6695 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); |
| 6696 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); |
| 6697 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); |
| 6698 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); |
| 6699 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6700 | |
| 6701 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 6702 | tw32_f(MAC_MODE, tp->mac_mode); |
| 6703 | udelay(40); |
| 6704 | |
| 6705 | tp->tx_mode &= ~TX_MODE_ENABLE; |
| 6706 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 6707 | |
| 6708 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 6709 | udelay(100); |
| 6710 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) |
| 6711 | break; |
| 6712 | } |
| 6713 | if (i >= MAX_WAIT_CNT) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 6714 | dev_err(&tp->pdev->dev, |
| 6715 | "%s timed out, TX_MODE_ENABLE will not clear " |
| 6716 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 6717 | err |= -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6718 | } |
| 6719 | |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 6720 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6721 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
| 6722 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6723 | |
| 6724 | tw32(FTQ_RESET, 0xffffffff); |
| 6725 | tw32(FTQ_RESET, 0x00000000); |
| 6726 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6727 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
| 6728 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6729 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6730 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6731 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 6732 | if (tnapi->hw_status) |
| 6733 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 6734 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6735 | if (tp->hw_stats) |
| 6736 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 6737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6738 | return err; |
| 6739 | } |
| 6740 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6741 | static void tg3_ape_send_event(struct tg3 *tp, u32 event) |
| 6742 | { |
| 6743 | int i; |
| 6744 | u32 apedata; |
| 6745 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6746 | /* NCSI does not support APE events */ |
| 6747 | if (tp->tg3_flags3 & TG3_FLG3_APE_HAS_NCSI) |
| 6748 | return; |
| 6749 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6750 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 6751 | if (apedata != APE_SEG_SIG_MAGIC) |
| 6752 | return; |
| 6753 | |
| 6754 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
Matt Carlson | 731fd79 | 2008-08-15 14:07:51 -0700 | [diff] [blame] | 6755 | if (!(apedata & APE_FW_STATUS_READY)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6756 | return; |
| 6757 | |
| 6758 | /* Wait for up to 1 millisecond for APE to service previous event. */ |
| 6759 | for (i = 0; i < 10; i++) { |
| 6760 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) |
| 6761 | return; |
| 6762 | |
| 6763 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 6764 | |
| 6765 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6766 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
| 6767 | event | APE_EVENT_STATUS_EVENT_PENDING); |
| 6768 | |
| 6769 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 6770 | |
| 6771 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6772 | break; |
| 6773 | |
| 6774 | udelay(100); |
| 6775 | } |
| 6776 | |
| 6777 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6778 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 6779 | } |
| 6780 | |
| 6781 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
| 6782 | { |
| 6783 | u32 event; |
| 6784 | u32 apedata; |
| 6785 | |
| 6786 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) |
| 6787 | return; |
| 6788 | |
| 6789 | switch (kind) { |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6790 | case RESET_KIND_INIT: |
| 6791 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, |
| 6792 | APE_HOST_SEG_SIG_MAGIC); |
| 6793 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, |
| 6794 | APE_HOST_SEG_LEN_MAGIC); |
| 6795 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); |
| 6796 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); |
| 6797 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, |
Matt Carlson | 6867c84 | 2010-07-11 09:31:44 +0000 | [diff] [blame] | 6798 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6799 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
| 6800 | APE_HOST_BEHAV_NO_PHYLOCK); |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6801 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, |
| 6802 | TG3_APE_HOST_DRVR_STATE_START); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6803 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6804 | event = APE_EVENT_STATUS_STATE_START; |
| 6805 | break; |
| 6806 | case RESET_KIND_SHUTDOWN: |
| 6807 | /* With the interface we are currently using, |
| 6808 | * APE does not track driver state. Wiping |
| 6809 | * out the HOST SEGMENT SIGNATURE forces |
| 6810 | * the APE to assume OS absent status. |
| 6811 | */ |
| 6812 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); |
Matt Carlson | b2aee15 | 2008-11-03 16:51:11 -0800 | [diff] [blame] | 6813 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 6814 | if (device_may_wakeup(&tp->pdev->dev) && |
| 6815 | (tp->tg3_flags & TG3_FLAG_WOL_ENABLE)) { |
| 6816 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, |
| 6817 | TG3_APE_HOST_WOL_SPEED_AUTO); |
| 6818 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; |
| 6819 | } else |
| 6820 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; |
| 6821 | |
| 6822 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); |
| 6823 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 6824 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
| 6825 | break; |
| 6826 | case RESET_KIND_SUSPEND: |
| 6827 | event = APE_EVENT_STATUS_STATE_SUSPEND; |
| 6828 | break; |
| 6829 | default: |
| 6830 | return; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6831 | } |
| 6832 | |
| 6833 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; |
| 6834 | |
| 6835 | tg3_ape_send_event(tp, event); |
| 6836 | } |
| 6837 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 6838 | /* tp->lock is held. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6839 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) |
| 6840 | { |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 6841 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
| 6842 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6843 | |
| 6844 | if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) { |
| 6845 | switch (kind) { |
| 6846 | case RESET_KIND_INIT: |
| 6847 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6848 | DRV_STATE_START); |
| 6849 | break; |
| 6850 | |
| 6851 | case RESET_KIND_SHUTDOWN: |
| 6852 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6853 | DRV_STATE_UNLOAD); |
| 6854 | break; |
| 6855 | |
| 6856 | case RESET_KIND_SUSPEND: |
| 6857 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6858 | DRV_STATE_SUSPEND); |
| 6859 | break; |
| 6860 | |
| 6861 | default: |
| 6862 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6863 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6864 | } |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6865 | |
| 6866 | if (kind == RESET_KIND_INIT || |
| 6867 | kind == RESET_KIND_SUSPEND) |
| 6868 | tg3_ape_driver_state_change(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6869 | } |
| 6870 | |
| 6871 | /* tp->lock is held. */ |
| 6872 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) |
| 6873 | { |
| 6874 | if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) { |
| 6875 | switch (kind) { |
| 6876 | case RESET_KIND_INIT: |
| 6877 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6878 | DRV_STATE_START_DONE); |
| 6879 | break; |
| 6880 | |
| 6881 | case RESET_KIND_SHUTDOWN: |
| 6882 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6883 | DRV_STATE_UNLOAD_DONE); |
| 6884 | break; |
| 6885 | |
| 6886 | default: |
| 6887 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6888 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6889 | } |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6890 | |
| 6891 | if (kind == RESET_KIND_SHUTDOWN) |
| 6892 | tg3_ape_driver_state_change(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6893 | } |
| 6894 | |
| 6895 | /* tp->lock is held. */ |
| 6896 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) |
| 6897 | { |
| 6898 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { |
| 6899 | switch (kind) { |
| 6900 | case RESET_KIND_INIT: |
| 6901 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6902 | DRV_STATE_START); |
| 6903 | break; |
| 6904 | |
| 6905 | case RESET_KIND_SHUTDOWN: |
| 6906 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6907 | DRV_STATE_UNLOAD); |
| 6908 | break; |
| 6909 | |
| 6910 | case RESET_KIND_SUSPEND: |
| 6911 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6912 | DRV_STATE_SUSPEND); |
| 6913 | break; |
| 6914 | |
| 6915 | default: |
| 6916 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6918 | } |
| 6919 | } |
| 6920 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6921 | static int tg3_poll_fw(struct tg3 *tp) |
| 6922 | { |
| 6923 | int i; |
| 6924 | u32 val; |
| 6925 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6926 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Gary Zambrano | 0ccead1 | 2006-11-14 16:34:00 -0800 | [diff] [blame] | 6927 | /* Wait up to 20ms for init done. */ |
| 6928 | for (i = 0; i < 200; i++) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6929 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
| 6930 | return 0; |
Gary Zambrano | 0ccead1 | 2006-11-14 16:34:00 -0800 | [diff] [blame] | 6931 | udelay(100); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6932 | } |
| 6933 | return -ENODEV; |
| 6934 | } |
| 6935 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6936 | /* Wait for firmware initialization to complete. */ |
| 6937 | for (i = 0; i < 100000; i++) { |
| 6938 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); |
| 6939 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 6940 | break; |
| 6941 | udelay(10); |
| 6942 | } |
| 6943 | |
| 6944 | /* Chip might not be fitted with firmware. Some Sun onboard |
| 6945 | * parts are configured like that. So don't signal the timeout |
| 6946 | * of the above loop as an error, but do report the lack of |
| 6947 | * running firmware once. |
| 6948 | */ |
| 6949 | if (i >= 100000 && |
| 6950 | !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) { |
| 6951 | tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED; |
| 6952 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 6953 | netdev_info(tp->dev, "No firmware running\n"); |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6954 | } |
| 6955 | |
Matt Carlson | 6b10c16 | 2010-02-12 14:47:08 +0000 | [diff] [blame] | 6956 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 6957 | /* The 57765 A0 needs a little more |
| 6958 | * time to do some important work. |
| 6959 | */ |
| 6960 | mdelay(10); |
| 6961 | } |
| 6962 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6963 | return 0; |
| 6964 | } |
| 6965 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6966 | /* Save PCI command register before chip reset */ |
| 6967 | static void tg3_save_pci_state(struct tg3 *tp) |
| 6968 | { |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 6969 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6970 | } |
| 6971 | |
| 6972 | /* Restore PCI state after chip reset */ |
| 6973 | static void tg3_restore_pci_state(struct tg3 *tp) |
| 6974 | { |
| 6975 | u32 val; |
| 6976 | |
| 6977 | /* Re-enable indirect register accesses. */ |
| 6978 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 6979 | tp->misc_host_ctrl); |
| 6980 | |
| 6981 | /* Set MAX PCI retry to zero. */ |
| 6982 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); |
| 6983 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
| 6984 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) |
| 6985 | val |= PCISTATE_RETRY_SAME_DMA; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6986 | /* Allow reads and writes to the APE register and memory space. */ |
| 6987 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 6988 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 6989 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 6990 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6991 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
| 6992 | |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 6993 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6994 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 6995 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) { |
| 6996 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) |
Matt Carlson | cf79003 | 2010-11-24 08:31:48 +0000 | [diff] [blame] | 6997 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 6998 | else { |
| 6999 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 7000 | tp->pci_cacheline_sz); |
| 7001 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 7002 | tp->pci_lat_timer); |
| 7003 | } |
Michael Chan | 114342f | 2007-10-15 02:12:26 -0700 | [diff] [blame] | 7004 | } |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 7005 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7006 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 7007 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 7008 | u16 pcix_cmd; |
| 7009 | |
| 7010 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 7011 | &pcix_cmd); |
| 7012 | pcix_cmd &= ~PCI_X_CMD_ERO; |
| 7013 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 7014 | pcix_cmd); |
| 7015 | } |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7016 | |
| 7017 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7018 | |
| 7019 | /* Chip reset on 5780 will reset MSI enable bit, |
| 7020 | * so need to restore it. |
| 7021 | */ |
| 7022 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { |
| 7023 | u16 ctrl; |
| 7024 | |
| 7025 | pci_read_config_word(tp->pdev, |
| 7026 | tp->msi_cap + PCI_MSI_FLAGS, |
| 7027 | &ctrl); |
| 7028 | pci_write_config_word(tp->pdev, |
| 7029 | tp->msi_cap + PCI_MSI_FLAGS, |
| 7030 | ctrl | PCI_MSI_FLAGS_ENABLE); |
| 7031 | val = tr32(MSGINT_MODE); |
| 7032 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); |
| 7033 | } |
| 7034 | } |
| 7035 | } |
| 7036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7037 | static void tg3_stop_fw(struct tg3 *); |
| 7038 | |
| 7039 | /* tp->lock is held. */ |
| 7040 | static int tg3_chip_reset(struct tg3 *tp) |
| 7041 | { |
| 7042 | u32 val; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7043 | void (*write_op)(struct tg3 *, u32, u32); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7044 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7045 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 7046 | tg3_nvram_lock(tp); |
| 7047 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 7048 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
| 7049 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 7050 | /* No matching tg3_nvram_unlock() after this because |
| 7051 | * chip reset below will undo the nvram lock. |
| 7052 | */ |
| 7053 | tp->nvram_lock_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7054 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7055 | /* GRC_MISC_CFG core clock reset will clear the memory |
| 7056 | * enable bit in PCI register 4 and the MSI enable bit |
| 7057 | * on some chips, so we save relevant registers here. |
| 7058 | */ |
| 7059 | tg3_save_pci_state(tp); |
| 7060 | |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 7061 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 7062 | (tp->tg3_flags3 & TG3_FLG3_5755_PLUS)) |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 7063 | tw32(GRC_FASTBOOT_PC, 0); |
| 7064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7065 | /* |
| 7066 | * We must avoid the readl() that normally takes place. |
| 7067 | * It locks machines, causes machine checks, and other |
| 7068 | * fun things. So, temporarily disable the 5701 |
| 7069 | * hardware workaround, while we do the reset. |
| 7070 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7071 | write_op = tp->write32; |
| 7072 | if (write_op == tg3_write_flush_reg32) |
| 7073 | tp->write32 = tg3_write32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7074 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7075 | /* Prevent the irq handler from reading or writing PCI registers |
| 7076 | * during chip reset when the memory enable bit in the PCI command |
| 7077 | * register may be cleared. The chip does not generate interrupt |
| 7078 | * at this time, but the irq handler may still be called due to irq |
| 7079 | * sharing or irqpoll. |
| 7080 | */ |
| 7081 | tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7082 | for (i = 0; i < tp->irq_cnt; i++) { |
| 7083 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 7084 | if (tnapi->hw_status) { |
| 7085 | tnapi->hw_status->status = 0; |
| 7086 | tnapi->hw_status->status_tag = 0; |
| 7087 | } |
| 7088 | tnapi->last_tag = 0; |
| 7089 | tnapi->last_irq_tag = 0; |
Michael Chan | b8fa2f3 | 2007-04-06 17:35:37 -0700 | [diff] [blame] | 7090 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7091 | smp_mb(); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 7092 | |
| 7093 | for (i = 0; i < tp->irq_cnt; i++) |
| 7094 | synchronize_irq(tp->napi[i].irq_vec); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7095 | |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 7096 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 7097 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 7098 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 7099 | } |
| 7100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7101 | /* do the reset */ |
| 7102 | val = GRC_MISC_CFG_CORECLK_RESET; |
| 7103 | |
| 7104 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
Matt Carlson | 88075d9 | 2010-08-02 11:25:58 +0000 | [diff] [blame] | 7105 | /* Force PCIe 1.0a mode */ |
| 7106 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
| 7107 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
| 7108 | tr32(TG3_PCIE_PHY_TSTCTL) == |
| 7109 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) |
| 7110 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); |
| 7111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7112 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
| 7113 | tw32(GRC_MISC_CFG, (1 << 29)); |
| 7114 | val |= (1 << 29); |
| 7115 | } |
| 7116 | } |
| 7117 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 7118 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 7119 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
| 7120 | tw32(GRC_VCPU_EXT_CTRL, |
| 7121 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 7122 | } |
| 7123 | |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 7124 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
| 7125 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
| 7126 | !(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7127 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
Matt Carlson | f37500d | 2010-08-02 11:25:59 +0000 | [diff] [blame] | 7128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7129 | tw32(GRC_MISC_CFG, val); |
| 7130 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 7131 | /* restore 5701 hardware bug workaround write method */ |
| 7132 | tp->write32 = write_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7133 | |
| 7134 | /* Unfortunately, we have to delay before the PCI read back. |
| 7135 | * Some 575X chips even will not respond to a PCI cfg access |
| 7136 | * when the reset command is given to the chip. |
| 7137 | * |
| 7138 | * How do these hardware designers expect things to work |
| 7139 | * properly if the PCI write is posted for a long period |
| 7140 | * of time? It is always necessary to have some method by |
| 7141 | * which a register read back can occur to push the write |
| 7142 | * out which does the reset. |
| 7143 | * |
| 7144 | * For most tg3 variants the trick below was working. |
| 7145 | * Ho hum... |
| 7146 | */ |
| 7147 | udelay(120); |
| 7148 | |
| 7149 | /* Flush PCI posted writes. The normal MMIO registers |
| 7150 | * are inaccessible at this time so this is the only |
| 7151 | * way to make this reliably (actually, this is no longer |
| 7152 | * the case, see above). I tried to use indirect |
| 7153 | * register read/write but this upset some 5701 variants. |
| 7154 | */ |
| 7155 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); |
| 7156 | |
| 7157 | udelay(120); |
| 7158 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7159 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && tp->pcie_cap) { |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7160 | u16 val16; |
| 7161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7162 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
| 7163 | int i; |
| 7164 | u32 cfg_val; |
| 7165 | |
| 7166 | /* Wait for link training to complete. */ |
| 7167 | for (i = 0; i < 5000; i++) |
| 7168 | udelay(100); |
| 7169 | |
| 7170 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); |
| 7171 | pci_write_config_dword(tp->pdev, 0xc4, |
| 7172 | cfg_val | (1 << 15)); |
| 7173 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7174 | |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7175 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
| 7176 | pci_read_config_word(tp->pdev, |
| 7177 | tp->pcie_cap + PCI_EXP_DEVCTL, |
| 7178 | &val16); |
| 7179 | val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN | |
| 7180 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 7181 | /* |
| 7182 | * Older PCIe devices only support the 128 byte |
| 7183 | * MPS setting. Enforce the restriction. |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7184 | */ |
Matt Carlson | 6de34cb | 2010-08-02 11:25:55 +0000 | [diff] [blame] | 7185 | if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7186 | val16 &= ~PCI_EXP_DEVCTL_PAYLOAD; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7187 | pci_write_config_word(tp->pdev, |
| 7188 | tp->pcie_cap + PCI_EXP_DEVCTL, |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 7189 | val16); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7190 | |
Matt Carlson | cf79003 | 2010-11-24 08:31:48 +0000 | [diff] [blame] | 7191 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 7192 | |
| 7193 | /* Clear error status */ |
| 7194 | pci_write_config_word(tp->pdev, |
| 7195 | tp->pcie_cap + PCI_EXP_DEVSTA, |
| 7196 | PCI_EXP_DEVSTA_CED | |
| 7197 | PCI_EXP_DEVSTA_NFED | |
| 7198 | PCI_EXP_DEVSTA_FED | |
| 7199 | PCI_EXP_DEVSTA_URD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7200 | } |
| 7201 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7202 | tg3_restore_pci_state(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7203 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 7204 | tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING; |
| 7205 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7206 | val = 0; |
| 7207 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 7208 | val = tr32(MEMARB_MODE); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 7209 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7210 | |
| 7211 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { |
| 7212 | tg3_stop_fw(tp); |
| 7213 | tw32(0x5000, 0x400); |
| 7214 | } |
| 7215 | |
| 7216 | tw32(GRC_MODE, tp->grc_mode); |
| 7217 | |
| 7218 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 7219 | val = tr32(0xc4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7220 | |
| 7221 | tw32(0xc4, val | (1 << 15)); |
| 7222 | } |
| 7223 | |
| 7224 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && |
| 7225 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 7226 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
| 7227 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) |
| 7228 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
| 7229 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 7230 | } |
| 7231 | |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 7232 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 7233 | tp->mac_mode = MAC_MODE_APE_TX_EN | |
| 7234 | MAC_MODE_APE_RX_EN | |
| 7235 | MAC_MODE_TDE_ENABLE; |
| 7236 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 7237 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 7238 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 7239 | val = tp->mac_mode; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 7240 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 7241 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 7242 | val = tp->mac_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7243 | } else |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 7244 | val = 0; |
| 7245 | |
| 7246 | tw32_f(MAC_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7247 | udelay(40); |
| 7248 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 7249 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
| 7250 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 7251 | err = tg3_poll_fw(tp); |
| 7252 | if (err) |
| 7253 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7254 | |
Matt Carlson | 0a9140c | 2009-08-28 12:27:50 +0000 | [diff] [blame] | 7255 | tg3_mdio_start(tp); |
| 7256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7257 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 7258 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 7259 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 7260 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 7261 | val = tr32(0x7c00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7262 | |
| 7263 | tw32(0x7c00, val | (1 << 25)); |
| 7264 | } |
| 7265 | |
| 7266 | /* Reprobe ASF enable state. */ |
| 7267 | tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF; |
| 7268 | tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE; |
| 7269 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 7270 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 7271 | u32 nic_cfg; |
| 7272 | |
| 7273 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 7274 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
| 7275 | tp->tg3_flags |= TG3_FLAG_ENABLE_ASF; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 7276 | tp->last_event_jiffies = jiffies; |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 7277 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7278 | tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE; |
| 7279 | } |
| 7280 | } |
| 7281 | |
| 7282 | return 0; |
| 7283 | } |
| 7284 | |
| 7285 | /* tp->lock is held. */ |
| 7286 | static void tg3_stop_fw(struct tg3 *tp) |
| 7287 | { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7288 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) && |
| 7289 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 7290 | /* Wait for RX cpu to ACK the previous event. */ |
| 7291 | tg3_wait_for_event_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7292 | |
| 7293 | 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] | 7294 | |
| 7295 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7296 | |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 7297 | /* Wait for RX cpu to ACK this event. */ |
| 7298 | tg3_wait_for_event_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7299 | } |
| 7300 | } |
| 7301 | |
| 7302 | /* tp->lock is held. */ |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7303 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7304 | { |
| 7305 | int err; |
| 7306 | |
| 7307 | tg3_stop_fw(tp); |
| 7308 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7309 | tg3_write_sig_pre_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7310 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7311 | tg3_abort_hw(tp, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7312 | err = tg3_chip_reset(tp); |
| 7313 | |
Matt Carlson | daba2a6 | 2009-04-20 06:58:52 +0000 | [diff] [blame] | 7314 | __tg3_set_mac_addr(tp, 0); |
| 7315 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7316 | tg3_write_sig_legacy(tp, kind); |
| 7317 | tg3_write_sig_post_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7318 | |
| 7319 | if (err) |
| 7320 | return err; |
| 7321 | |
| 7322 | return 0; |
| 7323 | } |
| 7324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7325 | #define RX_CPU_SCRATCH_BASE 0x30000 |
| 7326 | #define RX_CPU_SCRATCH_SIZE 0x04000 |
| 7327 | #define TX_CPU_SCRATCH_BASE 0x34000 |
| 7328 | #define TX_CPU_SCRATCH_SIZE 0x04000 |
| 7329 | |
| 7330 | /* tp->lock is held. */ |
| 7331 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) |
| 7332 | { |
| 7333 | int i; |
| 7334 | |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 7335 | BUG_ON(offset == TX_CPU_BASE && |
| 7336 | (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7337 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 7338 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 7339 | u32 val = tr32(GRC_VCPU_EXT_CTRL); |
| 7340 | |
| 7341 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 7342 | return 0; |
| 7343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7344 | if (offset == RX_CPU_BASE) { |
| 7345 | for (i = 0; i < 10000; i++) { |
| 7346 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7347 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 7348 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 7349 | break; |
| 7350 | } |
| 7351 | |
| 7352 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7353 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); |
| 7354 | udelay(10); |
| 7355 | } else { |
| 7356 | for (i = 0; i < 10000; i++) { |
| 7357 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7358 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 7359 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 7360 | break; |
| 7361 | } |
| 7362 | } |
| 7363 | |
| 7364 | if (i >= 10000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7365 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
| 7366 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7367 | return -ENODEV; |
| 7368 | } |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7369 | |
| 7370 | /* Clear firmware's nvram arbitration. */ |
| 7371 | if (tp->tg3_flags & TG3_FLAG_NVRAM) |
| 7372 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7373 | return 0; |
| 7374 | } |
| 7375 | |
| 7376 | struct fw_info { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7377 | unsigned int fw_base; |
| 7378 | unsigned int fw_len; |
| 7379 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7380 | }; |
| 7381 | |
| 7382 | /* tp->lock is held. */ |
| 7383 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base, |
| 7384 | int cpu_scratch_size, struct fw_info *info) |
| 7385 | { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7386 | int err, lock_err, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7387 | void (*write_op)(struct tg3 *, u32, u32); |
| 7388 | |
| 7389 | if (cpu_base == TX_CPU_BASE && |
| 7390 | (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7391 | netdev_err(tp->dev, |
| 7392 | "%s: Trying to load TX cpu firmware which is 5705\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7393 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7394 | return -EINVAL; |
| 7395 | } |
| 7396 | |
| 7397 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
| 7398 | write_op = tg3_write_mem; |
| 7399 | else |
| 7400 | write_op = tg3_write_indirect_reg32; |
| 7401 | |
Michael Chan | 1b62815 | 2005-05-29 14:59:49 -0700 | [diff] [blame] | 7402 | /* It is possible that bootcode is still loading at this point. |
| 7403 | * Get the nvram lock first before halting the cpu. |
| 7404 | */ |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7405 | lock_err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7406 | err = tg3_halt_cpu(tp, cpu_base); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7407 | if (!lock_err) |
| 7408 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7409 | if (err) |
| 7410 | goto out; |
| 7411 | |
| 7412 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
| 7413 | write_op(tp, cpu_scratch_base + i, 0); |
| 7414 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7415 | 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] | 7416 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7417 | write_op(tp, (cpu_scratch_base + |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7418 | (info->fw_base & 0xffff) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7419 | (i * sizeof(u32))), |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7420 | be32_to_cpu(info->fw_data[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7421 | |
| 7422 | err = 0; |
| 7423 | |
| 7424 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7425 | return err; |
| 7426 | } |
| 7427 | |
| 7428 | /* tp->lock is held. */ |
| 7429 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) |
| 7430 | { |
| 7431 | struct fw_info info; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7432 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7433 | int err, i; |
| 7434 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7435 | fw_data = (void *)tp->fw->data; |
| 7436 | |
| 7437 | /* Firmware blob starts with version numbers, followed by |
| 7438 | start address and length. We are setting complete length. |
| 7439 | length = end_address_of_bss - start_address_of_text. |
| 7440 | Remainder is the blob to be loaded contiguously |
| 7441 | from start address. */ |
| 7442 | |
| 7443 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 7444 | info.fw_len = tp->fw->size - 12; |
| 7445 | info.fw_data = &fw_data[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7446 | |
| 7447 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
| 7448 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, |
| 7449 | &info); |
| 7450 | if (err) |
| 7451 | return err; |
| 7452 | |
| 7453 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, |
| 7454 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, |
| 7455 | &info); |
| 7456 | if (err) |
| 7457 | return err; |
| 7458 | |
| 7459 | /* Now startup only the RX cpu. */ |
| 7460 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7461 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7462 | |
| 7463 | for (i = 0; i < 5; i++) { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7464 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7465 | break; |
| 7466 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 7467 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7468 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7469 | udelay(1000); |
| 7470 | } |
| 7471 | if (i >= 5) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7472 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
| 7473 | "should be %08x\n", __func__, |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7474 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7475 | return -ENODEV; |
| 7476 | } |
| 7477 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 7478 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); |
| 7479 | |
| 7480 | return 0; |
| 7481 | } |
| 7482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7483 | /* 5705 needs a special version of the TSO firmware. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7484 | |
| 7485 | /* tp->lock is held. */ |
| 7486 | static int tg3_load_tso_firmware(struct tg3 *tp) |
| 7487 | { |
| 7488 | struct fw_info info; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7489 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7490 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
| 7491 | int err, i; |
| 7492 | |
| 7493 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
| 7494 | return 0; |
| 7495 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7496 | fw_data = (void *)tp->fw->data; |
| 7497 | |
| 7498 | /* Firmware blob starts with version numbers, followed by |
| 7499 | start address and length. We are setting complete length. |
| 7500 | length = end_address_of_bss - start_address_of_text. |
| 7501 | Remainder is the blob to be loaded contiguously |
| 7502 | from start address. */ |
| 7503 | |
| 7504 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 7505 | cpu_scratch_size = tp->fw_len; |
| 7506 | info.fw_len = tp->fw->size - 12; |
| 7507 | info.fw_data = &fw_data[3]; |
| 7508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7509 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7510 | cpu_base = RX_CPU_BASE; |
| 7511 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7512 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7513 | cpu_base = TX_CPU_BASE; |
| 7514 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; |
| 7515 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; |
| 7516 | } |
| 7517 | |
| 7518 | err = tg3_load_firmware_cpu(tp, cpu_base, |
| 7519 | cpu_scratch_base, cpu_scratch_size, |
| 7520 | &info); |
| 7521 | if (err) |
| 7522 | return err; |
| 7523 | |
| 7524 | /* Now startup the cpu. */ |
| 7525 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7526 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7527 | |
| 7528 | for (i = 0; i < 5; i++) { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7529 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7530 | break; |
| 7531 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7532 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7533 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7534 | udelay(1000); |
| 7535 | } |
| 7536 | if (i >= 5) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 7537 | netdev_err(tp->dev, |
| 7538 | "%s fails to set CPU PC, is %08x should be %08x\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 7539 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7540 | return -ENODEV; |
| 7541 | } |
| 7542 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7543 | tw32_f(cpu_base + CPU_MODE, 0x00000000); |
| 7544 | return 0; |
| 7545 | } |
| 7546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7548 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
| 7549 | { |
| 7550 | struct tg3 *tp = netdev_priv(dev); |
| 7551 | struct sockaddr *addr = p; |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7552 | int err = 0, skip_mac_1 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7553 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 7554 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7555 | return -EINVAL; |
| 7556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7557 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 7558 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 7559 | if (!netif_running(dev)) |
| 7560 | return 0; |
| 7561 | |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7562 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7563 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7564 | |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7565 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
| 7566 | addr0_low = tr32(MAC_ADDR_0_LOW); |
| 7567 | addr1_high = tr32(MAC_ADDR_1_HIGH); |
| 7568 | addr1_low = tr32(MAC_ADDR_1_LOW); |
| 7569 | |
| 7570 | /* Skip MAC addr 1 if ASF is using it. */ |
| 7571 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && |
| 7572 | !(addr1_high == 0 && addr1_low == 0)) |
| 7573 | skip_mac_1 = 1; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7574 | } |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7575 | spin_lock_bh(&tp->lock); |
| 7576 | __tg3_set_mac_addr(tp, skip_mac_1); |
| 7577 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7578 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 7579 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7580 | } |
| 7581 | |
| 7582 | /* tp->lock is held. */ |
| 7583 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, |
| 7584 | dma_addr_t mapping, u32 maxlen_flags, |
| 7585 | u32 nic_addr) |
| 7586 | { |
| 7587 | tg3_write_mem(tp, |
| 7588 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 7589 | ((u64) mapping >> 32)); |
| 7590 | tg3_write_mem(tp, |
| 7591 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), |
| 7592 | ((u64) mapping & 0xffffffff)); |
| 7593 | tg3_write_mem(tp, |
| 7594 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), |
| 7595 | maxlen_flags); |
| 7596 | |
| 7597 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 7598 | tg3_write_mem(tp, |
| 7599 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), |
| 7600 | nic_addr); |
| 7601 | } |
| 7602 | |
| 7603 | static void __tg3_set_rx_mode(struct net_device *); |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 7604 | 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] | 7605 | { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7606 | int i; |
| 7607 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7608 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7609 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
| 7610 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); |
| 7611 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7612 | } else { |
| 7613 | tw32(HOSTCC_TXCOL_TICKS, 0); |
| 7614 | tw32(HOSTCC_TXMAX_FRAMES, 0); |
| 7615 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7616 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7617 | |
Matt Carlson | 20d7375 | 2010-07-11 09:31:41 +0000 | [diff] [blame] | 7618 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) { |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7619 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
| 7620 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); |
| 7621 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); |
| 7622 | } else { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7623 | tw32(HOSTCC_RXCOL_TICKS, 0); |
| 7624 | tw32(HOSTCC_RXMAX_FRAMES, 0); |
| 7625 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7626 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7627 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7628 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 7629 | u32 val = ec->stats_block_coalesce_usecs; |
| 7630 | |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7631 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
| 7632 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); |
| 7633 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7634 | if (!netif_carrier_ok(tp->dev)) |
| 7635 | val = 0; |
| 7636 | |
| 7637 | tw32(HOSTCC_STAT_COAL_TICKS, val); |
| 7638 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7639 | |
| 7640 | for (i = 0; i < tp->irq_cnt - 1; i++) { |
| 7641 | u32 reg; |
| 7642 | |
| 7643 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; |
| 7644 | tw32(reg, ec->rx_coalesce_usecs); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7645 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
| 7646 | tw32(reg, ec->rx_max_coalesced_frames); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7647 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 7648 | tw32(reg, ec->rx_max_coalesced_frames_irq); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7649 | |
| 7650 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) { |
| 7651 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
| 7652 | tw32(reg, ec->tx_coalesce_usecs); |
| 7653 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; |
| 7654 | tw32(reg, ec->tx_max_coalesced_frames); |
| 7655 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 7656 | tw32(reg, ec->tx_max_coalesced_frames_irq); |
| 7657 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7658 | } |
| 7659 | |
| 7660 | for (; i < tp->irq_max - 1; i++) { |
| 7661 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7662 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7663 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7664 | |
| 7665 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) { |
| 7666 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 7667 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 7668 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 7669 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7670 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7672 | |
| 7673 | /* tp->lock is held. */ |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7674 | static void tg3_rings_reset(struct tg3 *tp) |
| 7675 | { |
| 7676 | int i; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7677 | u32 stblk, txrcb, rxrcb, limit; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7678 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 7679 | |
| 7680 | /* Disable all transmit rings but the first. */ |
| 7681 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 7682 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | 3d37728 | 2010-10-14 10:37:39 +0000 | [diff] [blame] | 7683 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 7684 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 7685 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7686 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 7687 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7688 | else |
| 7689 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 7690 | |
| 7691 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 7692 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) |
| 7693 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 7694 | BDINFO_FLAGS_DISABLED); |
| 7695 | |
| 7696 | |
| 7697 | /* Disable all receive return rings but the first. */ |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 7698 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 7699 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 7700 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
| 7701 | else if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7702 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7703 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 7704 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7705 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
| 7706 | else |
| 7707 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 7708 | |
| 7709 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 7710 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) |
| 7711 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 7712 | BDINFO_FLAGS_DISABLED); |
| 7713 | |
| 7714 | /* Disable interrupts */ |
| 7715 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); |
| 7716 | |
| 7717 | /* Zero mailbox registers. */ |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7718 | if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX) { |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 7719 | for (i = 1; i < tp->irq_max; i++) { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7720 | tp->napi[i].tx_prod = 0; |
| 7721 | tp->napi[i].tx_cons = 0; |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 7722 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
| 7723 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7724 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
| 7725 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); |
| 7726 | } |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 7727 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) |
| 7728 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7729 | } else { |
| 7730 | tp->napi[0].tx_prod = 0; |
| 7731 | tp->napi[0].tx_cons = 0; |
| 7732 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 7733 | tw32_rx_mbox(tp->napi[0].consmbox, 0); |
| 7734 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7735 | |
| 7736 | /* Make sure the NIC-based send BD rings are disabled. */ |
| 7737 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 7738 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 7739 | for (i = 0; i < 16; i++) |
| 7740 | tw32_tx_mbox(mbox + i * 8, 0); |
| 7741 | } |
| 7742 | |
| 7743 | txrcb = NIC_SRAM_SEND_RCB; |
| 7744 | rxrcb = NIC_SRAM_RCV_RET_RCB; |
| 7745 | |
| 7746 | /* Clear status block in ram. */ |
| 7747 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7748 | |
| 7749 | /* Set status block DMA address */ |
| 7750 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 7751 | ((u64) tnapi->status_mapping >> 32)); |
| 7752 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 7753 | ((u64) tnapi->status_mapping & 0xffffffff)); |
| 7754 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7755 | if (tnapi->tx_ring) { |
| 7756 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 7757 | (TG3_TX_RING_SIZE << |
| 7758 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 7759 | NIC_SRAM_TX_BUFFER_DESC); |
| 7760 | txrcb += TG3_BDINFO_SIZE; |
| 7761 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7762 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7763 | if (tnapi->rx_rcb) { |
| 7764 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 7765 | (tp->rx_ret_ring_mask + 1) << |
| 7766 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7767 | rxrcb += TG3_BDINFO_SIZE; |
| 7768 | } |
| 7769 | |
| 7770 | stblk = HOSTCC_STATBLCK_RING1; |
| 7771 | |
| 7772 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
| 7773 | u64 mapping = (u64)tnapi->status_mapping; |
| 7774 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); |
| 7775 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); |
| 7776 | |
| 7777 | /* Clear status block in ram. */ |
| 7778 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7779 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7780 | if (tnapi->tx_ring) { |
| 7781 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 7782 | (TG3_TX_RING_SIZE << |
| 7783 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 7784 | NIC_SRAM_TX_BUFFER_DESC); |
| 7785 | txrcb += TG3_BDINFO_SIZE; |
| 7786 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7787 | |
| 7788 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 7789 | ((tp->rx_ret_ring_mask + 1) << |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7790 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
| 7791 | |
| 7792 | stblk += 8; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7793 | rxrcb += TG3_BDINFO_SIZE; |
| 7794 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7795 | } |
| 7796 | |
| 7797 | /* tp->lock is held. */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 7798 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7799 | { |
| 7800 | u32 val, rdmac_mode; |
| 7801 | int i, err, limit; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 7802 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7803 | |
| 7804 | tg3_disable_ints(tp); |
| 7805 | |
| 7806 | tg3_stop_fw(tp); |
| 7807 | |
| 7808 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); |
| 7809 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 7810 | if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 7811 | tg3_abort_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7812 | |
Matt Carlson | 699c019 | 2010-12-06 08:28:51 +0000 | [diff] [blame] | 7813 | /* Enable MAC control of LPI */ |
| 7814 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { |
| 7815 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, |
| 7816 | TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | |
| 7817 | TG3_CPMU_EEE_LNKIDL_UART_IDL); |
| 7818 | |
| 7819 | tw32_f(TG3_CPMU_EEE_CTRL, |
| 7820 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); |
| 7821 | |
| 7822 | tw32_f(TG3_CPMU_EEE_MODE, |
| 7823 | TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
| 7824 | TG3_CPMU_EEEMD_LPI_IN_TX | |
| 7825 | TG3_CPMU_EEEMD_LPI_IN_RX | |
| 7826 | TG3_CPMU_EEEMD_EEE_ENABLE); |
| 7827 | } |
| 7828 | |
Matt Carlson | 603f117 | 2010-02-12 14:47:10 +0000 | [diff] [blame] | 7829 | if (reset_phy) |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 7830 | tg3_phy_reset(tp); |
| 7831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7832 | err = tg3_chip_reset(tp); |
| 7833 | if (err) |
| 7834 | return err; |
| 7835 | |
| 7836 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); |
| 7837 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 7838 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7839 | val = tr32(TG3_CPMU_CTRL); |
| 7840 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); |
| 7841 | tw32(TG3_CPMU_CTRL, val); |
Matt Carlson | 9acb961 | 2007-11-12 21:10:06 -0800 | [diff] [blame] | 7842 | |
| 7843 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 7844 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 7845 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 7846 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 7847 | |
| 7848 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); |
| 7849 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; |
| 7850 | val |= CPMU_LNK_AWARE_MACCLK_6_25; |
| 7851 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); |
| 7852 | |
| 7853 | val = tr32(TG3_CPMU_HST_ACC); |
| 7854 | val &= ~CPMU_HST_ACC_MACCLK_MASK; |
| 7855 | val |= CPMU_HST_ACC_MACCLK_6_25; |
| 7856 | tw32(TG3_CPMU_HST_ACC, val); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7857 | } |
| 7858 | |
Matt Carlson | 33466d9 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 7859 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 7860 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 7861 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | |
| 7862 | PCIE_PWR_MGMT_L1_THRESH_4MS; |
| 7863 | tw32(PCIE_PWR_MGMT_THRESH, val); |
Matt Carlson | 521e6b9 | 2009-08-25 10:06:01 +0000 | [diff] [blame] | 7864 | |
| 7865 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; |
| 7866 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); |
| 7867 | |
| 7868 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); |
Matt Carlson | 33466d9 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 7869 | |
Matt Carlson | f40386c | 2009-11-02 14:24:02 +0000 | [diff] [blame] | 7870 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 7871 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 7872 | } |
| 7873 | |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 7874 | if (tp->tg3_flags3 & TG3_FLG3_L1PLLPD_EN) { |
| 7875 | u32 grc_mode = tr32(GRC_MODE); |
| 7876 | |
| 7877 | /* Access the lower 1K of PL PCIE block registers. */ |
| 7878 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 7879 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 7880 | |
| 7881 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); |
| 7882 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, |
| 7883 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); |
| 7884 | |
| 7885 | tw32(GRC_MODE, grc_mode); |
| 7886 | } |
| 7887 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 7888 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
| 7889 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 7890 | u32 grc_mode = tr32(GRC_MODE); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 7891 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 7892 | /* Access the lower 1K of PL PCIE block registers. */ |
| 7893 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 7894 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 7895 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 7896 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 7897 | TG3_PCIE_PL_LO_PHYCTL5); |
| 7898 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, |
| 7899 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 7900 | |
Matt Carlson | 5093eed | 2010-11-24 08:31:45 +0000 | [diff] [blame] | 7901 | tw32(GRC_MODE, grc_mode); |
| 7902 | } |
Matt Carlson | a977dbe | 2010-04-12 06:58:26 +0000 | [diff] [blame] | 7903 | |
| 7904 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 7905 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 7906 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 7907 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
Matt Carlson | cea4646 | 2010-04-12 06:58:24 +0000 | [diff] [blame] | 7908 | } |
| 7909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7910 | /* This works around an issue with Athlon chipsets on |
| 7911 | * B3 tigon3 silicon. This bit has no effect on any |
| 7912 | * other revision. But do not set this on PCI Express |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 7913 | * 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] | 7914 | */ |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 7915 | if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) { |
| 7916 | if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) |
| 7917 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
| 7918 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 7919 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7920 | |
| 7921 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
| 7922 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) { |
| 7923 | val = tr32(TG3PCI_PCISTATE); |
| 7924 | val |= PCISTATE_RETRY_SAME_DMA; |
| 7925 | tw32(TG3PCI_PCISTATE, val); |
| 7926 | } |
| 7927 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7928 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
| 7929 | /* Allow reads and writes to the |
| 7930 | * APE register and memory space. |
| 7931 | */ |
| 7932 | val = tr32(TG3PCI_PCISTATE); |
| 7933 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 7934 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 7935 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7936 | tw32(TG3PCI_PCISTATE, val); |
| 7937 | } |
| 7938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7939 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
| 7940 | /* Enable some hw fixes. */ |
| 7941 | val = tr32(TG3PCI_MSI_DATA); |
| 7942 | val |= (1 << 26) | (1 << 28) | (1 << 29); |
| 7943 | tw32(TG3PCI_MSI_DATA, val); |
| 7944 | } |
| 7945 | |
| 7946 | /* Descriptor ring init may make accesses to the |
| 7947 | * NIC SRAM area to setup the TX descriptors, so we |
| 7948 | * can only do this after the hardware has been |
| 7949 | * successfully reset. |
| 7950 | */ |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 7951 | err = tg3_init_rings(tp); |
| 7952 | if (err) |
| 7953 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7954 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 7955 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 7956 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
| 7957 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
Matt Carlson | 1a31902 | 2010-04-12 06:58:25 +0000 | [diff] [blame] | 7958 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
| 7959 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 7960 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
| 7961 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && |
| 7962 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7963 | /* This value is determined during the probe time DMA |
| 7964 | * engine test, tg3_test_dma. |
| 7965 | */ |
| 7966 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 7967 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7968 | |
| 7969 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | |
| 7970 | GRC_MODE_4X_NIC_SEND_RINGS | |
| 7971 | GRC_MODE_NO_TX_PHDR_CSUM | |
| 7972 | GRC_MODE_NO_RX_PHDR_CSUM); |
| 7973 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; |
Michael Chan | d2d746f | 2006-04-06 21:45:39 -0700 | [diff] [blame] | 7974 | |
| 7975 | /* Pseudo-header checksum is done by hardware logic and not |
| 7976 | * the offload processers, so make the chip do the pseudo- |
| 7977 | * header checksums on receive. For transmit it is more |
| 7978 | * convenient to do the pseudo-header checksum in software |
| 7979 | * as Linux does that on transmit for us in all cases. |
| 7980 | */ |
| 7981 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7982 | |
| 7983 | tw32(GRC_MODE, |
| 7984 | tp->grc_mode | |
| 7985 | (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP)); |
| 7986 | |
| 7987 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ |
| 7988 | val = tr32(GRC_MISC_CFG); |
| 7989 | val &= ~0xff; |
| 7990 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 7991 | tw32(GRC_MISC_CFG, val); |
| 7992 | |
| 7993 | /* Initialize MBUF/DESC pool. */ |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 7994 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7995 | /* Do nothing. */ |
| 7996 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { |
| 7997 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
| 7998 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 7999 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
| 8000 | else |
| 8001 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); |
| 8002 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); |
| 8003 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 8004 | } else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8005 | int fw_len; |
| 8006 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 8007 | fw_len = tp->fw_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8008 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
| 8009 | tw32(BUFMGR_MB_POOL_ADDR, |
| 8010 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); |
| 8011 | tw32(BUFMGR_MB_POOL_SIZE, |
| 8012 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); |
| 8013 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8014 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 8015 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8016 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8017 | tp->bufmgr_config.mbuf_read_dma_low_water); |
| 8018 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 8019 | tp->bufmgr_config.mbuf_mac_rx_low_water); |
| 8020 | tw32(BUFMGR_MB_HIGH_WATER, |
| 8021 | tp->bufmgr_config.mbuf_high_water); |
| 8022 | } else { |
| 8023 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 8024 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); |
| 8025 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 8026 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); |
| 8027 | tw32(BUFMGR_MB_HIGH_WATER, |
| 8028 | tp->bufmgr_config.mbuf_high_water_jumbo); |
| 8029 | } |
| 8030 | tw32(BUFMGR_DMA_LOW_WATER, |
| 8031 | tp->bufmgr_config.dma_low_water); |
| 8032 | tw32(BUFMGR_DMA_HIGH_WATER, |
| 8033 | tp->bufmgr_config.dma_high_water); |
| 8034 | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8035 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
| 8036 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 8037 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; |
| 8038 | tw32(BUFMGR_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8039 | for (i = 0; i < 2000; i++) { |
| 8040 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) |
| 8041 | break; |
| 8042 | udelay(10); |
| 8043 | } |
| 8044 | if (i >= 2000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 8045 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8046 | return -ENODEV; |
| 8047 | } |
| 8048 | |
| 8049 | /* Setup replenish threshold. */ |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 8050 | val = tp->rx_pending / 8; |
| 8051 | if (val == 0) |
| 8052 | val = 1; |
| 8053 | else if (val > tp->rx_std_max_post) |
| 8054 | val = tp->rx_std_max_post; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 8055 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 8056 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) |
| 8057 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
| 8058 | |
| 8059 | if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2)) |
| 8060 | val = TG3_RX_INTERNAL_RING_SZ_5906 / 2; |
| 8061 | } |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 8062 | |
| 8063 | tw32(RCVBDI_STD_THRESH, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8064 | |
| 8065 | /* Initialize TG3_BDINFO's at: |
| 8066 | * RCVDBDI_STD_BD: standard eth size rx ring |
| 8067 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring |
| 8068 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) |
| 8069 | * |
| 8070 | * like so: |
| 8071 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring |
| 8072 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | |
| 8073 | * ring attribute flags |
| 8074 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM |
| 8075 | * |
| 8076 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. |
| 8077 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. |
| 8078 | * |
| 8079 | * The size of each ring is fixed in the firmware, but the location is |
| 8080 | * configurable. |
| 8081 | */ |
| 8082 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8083 | ((u64) tpr->rx_std_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8084 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8085 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 8086 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 8087 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5719) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 8088 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
| 8089 | NIC_SRAM_RX_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8090 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8091 | /* Disable the mini ring */ |
| 8092 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8093 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 8094 | BDINFO_FLAGS_DISABLED); |
| 8095 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8096 | /* Program the jumbo buffer descriptor ring control |
| 8097 | * blocks on those devices that have them. |
| 8098 | */ |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 8099 | if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8100 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8101 | /* Setup replenish threshold. */ |
| 8102 | tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8); |
| 8103 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 8104 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8105 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8106 | ((u64) tpr->rx_jmb_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8107 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 8108 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8109 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 8110 | (RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT) | |
| 8111 | BDINFO_FLAGS_USE_EXT_RECV); |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 8112 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) || |
| 8113 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 8114 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
| 8115 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8116 | } else { |
| 8117 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 8118 | BDINFO_FLAGS_DISABLED); |
| 8119 | } |
| 8120 | |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8121 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
| 8122 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 8123 | val = RX_STD_MAX_SIZE_5705; |
| 8124 | else |
| 8125 | val = RX_STD_MAX_SIZE_5717; |
| 8126 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
| 8127 | val |= (TG3_RX_STD_DMA_SZ << 2); |
| 8128 | } else |
Matt Carlson | 04380d4 | 2010-04-12 06:58:29 +0000 | [diff] [blame] | 8129 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 8130 | } else |
| 8131 | val = RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT; |
| 8132 | |
| 8133 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8134 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 8135 | tpr->rx_std_prod_idx = tp->rx_pending; |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 8136 | 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] | 8137 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 8138 | 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] | 8139 | tp->rx_jumbo_pending : 0; |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 8140 | 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] | 8141 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 8142 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8143 | tw32(STD_REPLENISH_LWM, 32); |
| 8144 | tw32(JMB_REPLENISH_LWM, 16); |
| 8145 | } |
| 8146 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8147 | tg3_rings_reset(tp); |
| 8148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8149 | /* Initialize MAC address and backoff seed. */ |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 8150 | __tg3_set_mac_addr(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8151 | |
| 8152 | /* MTU + ethernet header + FCS + optional VLAN tag */ |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 8153 | tw32(MAC_RX_MTU_SIZE, |
| 8154 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8155 | |
| 8156 | /* The slot time is changed by tg3_setup_phy if we |
| 8157 | * run at gigabit with half duplex. |
| 8158 | */ |
| 8159 | tw32(MAC_TX_LENGTHS, |
| 8160 | (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 8161 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 8162 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); |
| 8163 | |
| 8164 | /* Receive rules. */ |
| 8165 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); |
| 8166 | tw32(RCVLPC_CONFIG, 0x0181); |
| 8167 | |
| 8168 | /* Calculate RDMAC_MODE setting early, we need it to determine |
| 8169 | * the RCVLPC_STATE_ENABLE mask. |
| 8170 | */ |
| 8171 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | |
| 8172 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | |
| 8173 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | |
| 8174 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | |
| 8175 | RDMAC_MODE_LNGREAD_ENAB); |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8176 | |
Matt Carlson | deabaac | 2010-11-24 08:31:50 +0000 | [diff] [blame] | 8177 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
Matt Carlson | 0339e4e | 2010-02-12 14:47:09 +0000 | [diff] [blame] | 8178 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
| 8179 | |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 8180 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8181 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 8182 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 8183 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
| 8184 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | |
| 8185 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; |
| 8186 | |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8187 | /* If statement applies to 5705 and 5750 PCI devices only */ |
| 8188 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 8189 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) || |
| 8190 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8191 | if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE && |
Matt Carlson | c13e371 | 2007-05-05 11:50:04 -0700 | [diff] [blame] | 8192 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8193 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
| 8194 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
| 8195 | !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) { |
| 8196 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 8197 | } |
| 8198 | } |
| 8199 | |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8200 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) |
| 8201 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 8202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8203 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 8204 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
| 8205 | |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 8206 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
| 8207 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 8208 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
| 8209 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8210 | |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8211 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
| 8212 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 8213 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 8214 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 8215 | (tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { |
| 8216 | val = tr32(TG3_RDMA_RSRVCTRL_REG); |
Matt Carlson | b75cc0e | 2010-11-24 08:31:46 +0000 | [diff] [blame] | 8217 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
| 8218 | val &= ~TG3_RDMA_RSRVCTRL_TXMRGN_MASK; |
| 8219 | val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B; |
| 8220 | } |
Matt Carlson | 41a8a7e | 2010-09-15 08:59:53 +0000 | [diff] [blame] | 8221 | tw32(TG3_RDMA_RSRVCTRL_REG, |
| 8222 | val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); |
| 8223 | } |
| 8224 | |
Matt Carlson | d309a46 | 2010-09-30 10:34:31 +0000 | [diff] [blame] | 8225 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
| 8226 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 8227 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val | |
| 8228 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | |
| 8229 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); |
| 8230 | } |
| 8231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8232 | /* Receive/send statistics. */ |
Michael Chan | 1661394 | 2006-06-29 20:15:13 -0700 | [diff] [blame] | 8233 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
| 8234 | val = tr32(RCVLPC_STATS_ENABLE); |
| 8235 | val &= ~RCVLPC_STATSENAB_DACK_FIX; |
| 8236 | tw32(RCVLPC_STATS_ENABLE, val); |
| 8237 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && |
| 8238 | (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8239 | val = tr32(RCVLPC_STATS_ENABLE); |
| 8240 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; |
| 8241 | tw32(RCVLPC_STATS_ENABLE, val); |
| 8242 | } else { |
| 8243 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); |
| 8244 | } |
| 8245 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); |
| 8246 | tw32(SNDDATAI_STATSENAB, 0xffffff); |
| 8247 | tw32(SNDDATAI_STATSCTRL, |
| 8248 | (SNDDATAI_SCTRL_ENABLE | |
| 8249 | SNDDATAI_SCTRL_FASTUPD)); |
| 8250 | |
| 8251 | /* Setup host coalescing engine. */ |
| 8252 | tw32(HOSTCC_MODE, 0); |
| 8253 | for (i = 0; i < 2000; i++) { |
| 8254 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) |
| 8255 | break; |
| 8256 | udelay(10); |
| 8257 | } |
| 8258 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 8259 | __tg3_set_coalesce(tp, &tp->coal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8261 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 8262 | /* Status/statistics block address. See tg3_timer, |
| 8263 | * the tg3_periodic_fetch_stats call there, and |
| 8264 | * tg3_get_stats to see how this works for 5705/5750 chips. |
| 8265 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8266 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 8267 | ((u64) tp->stats_mapping >> 32)); |
| 8268 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 8269 | ((u64) tp->stats_mapping & 0xffffffff)); |
| 8270 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8272 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 8273 | |
| 8274 | /* Clear statistics and status block memory areas */ |
| 8275 | for (i = NIC_SRAM_STATS_BLK; |
| 8276 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; |
| 8277 | i += sizeof(u32)) { |
| 8278 | tg3_write_mem(tp, i, 0); |
| 8279 | udelay(40); |
| 8280 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8281 | } |
| 8282 | |
| 8283 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); |
| 8284 | |
| 8285 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); |
| 8286 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); |
| 8287 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 8288 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
| 8289 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8290 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
| 8291 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 8292 | /* reset to prevent losing 1st rx packet intermittently */ |
| 8293 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 8294 | udelay(10); |
| 8295 | } |
| 8296 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 8297 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 8298 | tp->mac_mode = MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 8299 | else |
| 8300 | tp->mac_mode = 0; |
| 8301 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8302 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 8303 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8304 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 8305 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
| 8306 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8307 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
| 8308 | udelay(40); |
| 8309 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8310 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8311 | * If TG3_FLG2_IS_NIC is zero, we should read the |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8312 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
| 8313 | * whether used as inputs or outputs, are set by boot code after |
| 8314 | * reset. |
| 8315 | */ |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8316 | if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8317 | u32 gpio_mask; |
| 8318 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8319 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
| 8320 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 8321 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 8322 | |
| 8323 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 8324 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
| 8325 | GRC_LCLCTRL_GPIO_OUTPUT3; |
| 8326 | |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 8327 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 8328 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 8329 | |
Gary Zambrano | aaf8446 | 2007-05-05 11:51:45 -0700 | [diff] [blame] | 8330 | tp->grc_local_ctrl &= ~gpio_mask; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8331 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
| 8332 | |
| 8333 | /* GPIO1 must be driven high for eeprom write protect */ |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8334 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) |
| 8335 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 8336 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8338 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 8339 | udelay(100); |
| 8340 | |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8341 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) { |
| 8342 | val = tr32(MSGINT_MODE); |
| 8343 | val |= MSGINT_MODE_MULTIVEC_EN | MSGINT_MODE_ENABLE; |
| 8344 | tw32(MSGINT_MODE, val); |
| 8345 | } |
| 8346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8347 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 8348 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
| 8349 | udelay(40); |
| 8350 | } |
| 8351 | |
| 8352 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | |
| 8353 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | |
| 8354 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | |
| 8355 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | |
| 8356 | WDMAC_MODE_LNGREAD_ENAB); |
| 8357 | |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8358 | /* If statement applies to 5705 and 5750 PCI devices only */ |
| 8359 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 8360 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) || |
| 8361 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) { |
Matt Carlson | 29ea095 | 2009-08-25 10:07:54 +0000 | [diff] [blame] | 8362 | if ((tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8363 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
| 8364 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { |
| 8365 | /* nothing */ |
| 8366 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
| 8367 | !(tp->tg3_flags2 & TG3_FLG2_IS_5788) && |
| 8368 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) { |
| 8369 | val |= WDMAC_MODE_RX_ACCEL; |
| 8370 | } |
| 8371 | } |
| 8372 | |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8373 | /* Enable host coalescing bug fix */ |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8374 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 8375 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8376 | |
Matt Carlson | 788a035 | 2009-11-02 14:26:03 +0000 | [diff] [blame] | 8377 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 8378 | val |= WDMAC_MODE_BURST_ALL_DATA; |
| 8379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8380 | tw32_f(WDMAC_MODE, val); |
| 8381 | udelay(40); |
| 8382 | |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8383 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
| 8384 | u16 pcix_cmd; |
| 8385 | |
| 8386 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8387 | &pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8388 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8389 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
| 8390 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8391 | } 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] | 8392 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
| 8393 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8394 | } |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8395 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8396 | pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8397 | } |
| 8398 | |
| 8399 | tw32_f(RDMAC_MODE, rdmac_mode); |
| 8400 | udelay(40); |
| 8401 | |
| 8402 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
| 8403 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 8404 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 8405 | |
| 8406 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 8407 | tw32(SNDDATAC_MODE, |
| 8408 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); |
| 8409 | else |
| 8410 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); |
| 8411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8412 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
| 8413 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 8414 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
| 8415 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 8416 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 8417 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
| 8418 | tw32(RCVDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8419 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8420 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
| 8421 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8422 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8423 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8424 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
| 8425 | tw32(SNDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8426 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
| 8427 | |
| 8428 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 8429 | err = tg3_load_5701_a0_firmware_fix(tp); |
| 8430 | if (err) |
| 8431 | return err; |
| 8432 | } |
| 8433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8434 | if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) { |
| 8435 | err = tg3_load_tso_firmware(tp); |
| 8436 | if (err) |
| 8437 | return err; |
| 8438 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8439 | |
| 8440 | tp->tx_mode = TX_MODE_ENABLE; |
Matt Carlson | b1d0521 | 2010-06-05 17:24:31 +0000 | [diff] [blame] | 8441 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
| 8442 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 8443 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8444 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 8445 | udelay(100); |
| 8446 | |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8447 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) { |
| 8448 | u32 reg = MAC_RSS_INDIR_TBL_0; |
| 8449 | u8 *ent = (u8 *)&val; |
| 8450 | |
| 8451 | /* Setup the indirection table */ |
| 8452 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { |
| 8453 | int idx = i % sizeof(val); |
| 8454 | |
Matt Carlson | 5efeeea | 2010-07-11 09:31:40 +0000 | [diff] [blame] | 8455 | ent[idx] = i % (tp->irq_cnt - 1); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8456 | if (idx == sizeof(val) - 1) { |
| 8457 | tw32(reg, val); |
| 8458 | reg += 4; |
| 8459 | } |
| 8460 | } |
| 8461 | |
| 8462 | /* Setup the "secret" hash key. */ |
| 8463 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); |
| 8464 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); |
| 8465 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); |
| 8466 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); |
| 8467 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); |
| 8468 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); |
| 8469 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); |
| 8470 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); |
| 8471 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); |
| 8472 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); |
| 8473 | } |
| 8474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8475 | tp->rx_mode = RX_MODE_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8476 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 8477 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
| 8478 | |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8479 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) |
| 8480 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
| 8481 | RX_MODE_RSS_ITBL_HASH_BITS_7 | |
| 8482 | RX_MODE_RSS_IPV6_HASH_EN | |
| 8483 | RX_MODE_RSS_TCP_IPV6_HASH_EN | |
| 8484 | RX_MODE_RSS_IPV4_HASH_EN | |
| 8485 | RX_MODE_RSS_TCP_IPV4_HASH_EN; |
| 8486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8487 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8488 | udelay(10); |
| 8489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8490 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 8491 | |
| 8492 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8493 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8494 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 8495 | udelay(10); |
| 8496 | } |
| 8497 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8498 | udelay(10); |
| 8499 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8500 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8501 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8502 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8503 | /* Set drive transmission level to 1.2V */ |
| 8504 | /* only if the signal pre-emphasis bit is not set */ |
| 8505 | val = tr32(MAC_SERDES_CFG); |
| 8506 | val &= 0xfffff000; |
| 8507 | val |= 0x880; |
| 8508 | tw32(MAC_SERDES_CFG, val); |
| 8509 | } |
| 8510 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) |
| 8511 | tw32(MAC_SERDES_CFG, 0x616000); |
| 8512 | } |
| 8513 | |
| 8514 | /* Prevent chip from dropping frames when flow control |
| 8515 | * is enabled. |
| 8516 | */ |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 8517 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 8518 | val = 1; |
| 8519 | else |
| 8520 | val = 2; |
| 8521 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8522 | |
| 8523 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8524 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8525 | /* Use hardware link auto-negotiation */ |
| 8526 | tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG; |
| 8527 | } |
| 8528 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8529 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 8530 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) { |
| 8531 | u32 tmp; |
| 8532 | |
| 8533 | tmp = tr32(SERDES_RX_CTRL); |
| 8534 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); |
| 8535 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; |
| 8536 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; |
| 8537 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 8538 | } |
| 8539 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8540 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)) { |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 8541 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 8542 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8543 | tp->link_config.speed = tp->link_config.orig_speed; |
| 8544 | tp->link_config.duplex = tp->link_config.orig_duplex; |
| 8545 | tp->link_config.autoneg = tp->link_config.orig_autoneg; |
| 8546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8547 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8548 | err = tg3_setup_phy(tp, 0); |
| 8549 | if (err) |
| 8550 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8551 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8552 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 8553 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8554 | u32 tmp; |
| 8555 | |
| 8556 | /* Clear CRC stats. */ |
| 8557 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { |
| 8558 | tg3_writephy(tp, MII_TG3_TEST1, |
| 8559 | tmp | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 8560 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8561 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8562 | } |
| 8563 | } |
| 8564 | |
| 8565 | __tg3_set_rx_mode(tp->dev); |
| 8566 | |
| 8567 | /* Initialize receive rules. */ |
| 8568 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); |
| 8569 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 8570 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); |
| 8571 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 8572 | |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 8573 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 8574 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8575 | limit = 8; |
| 8576 | else |
| 8577 | limit = 16; |
| 8578 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) |
| 8579 | limit -= 4; |
| 8580 | switch (limit) { |
| 8581 | case 16: |
| 8582 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); |
| 8583 | case 15: |
| 8584 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); |
| 8585 | case 14: |
| 8586 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); |
| 8587 | case 13: |
| 8588 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); |
| 8589 | case 12: |
| 8590 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); |
| 8591 | case 11: |
| 8592 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); |
| 8593 | case 10: |
| 8594 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); |
| 8595 | case 9: |
| 8596 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); |
| 8597 | case 8: |
| 8598 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); |
| 8599 | case 7: |
| 8600 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); |
| 8601 | case 6: |
| 8602 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); |
| 8603 | case 5: |
| 8604 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); |
| 8605 | case 4: |
| 8606 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ |
| 8607 | case 3: |
| 8608 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ |
| 8609 | case 2: |
| 8610 | case 1: |
| 8611 | |
| 8612 | default: |
| 8613 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 8614 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8615 | |
Matt Carlson | 9ce768e | 2007-10-11 19:49:11 -0700 | [diff] [blame] | 8616 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 8617 | /* Write our heartbeat update interval to APE. */ |
| 8618 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, |
| 8619 | APE_HOST_HEARTBEAT_INT_DISABLE); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8621 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
| 8622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8623 | return 0; |
| 8624 | } |
| 8625 | |
| 8626 | /* Called at device open time to get the chip ready for |
| 8627 | * packet processing. Invoked with tp->lock held. |
| 8628 | */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8629 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8630 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8631 | tg3_switch_clocks(tp); |
| 8632 | |
| 8633 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 8634 | |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 8635 | return tg3_reset_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8636 | } |
| 8637 | |
| 8638 | #define TG3_STAT_ADD32(PSTAT, REG) \ |
| 8639 | do { u32 __val = tr32(REG); \ |
| 8640 | (PSTAT)->low += __val; \ |
| 8641 | if ((PSTAT)->low < __val) \ |
| 8642 | (PSTAT)->high += 1; \ |
| 8643 | } while (0) |
| 8644 | |
| 8645 | static void tg3_periodic_fetch_stats(struct tg3 *tp) |
| 8646 | { |
| 8647 | struct tg3_hw_stats *sp = tp->hw_stats; |
| 8648 | |
| 8649 | if (!netif_carrier_ok(tp->dev)) |
| 8650 | return; |
| 8651 | |
| 8652 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); |
| 8653 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); |
| 8654 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); |
| 8655 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); |
| 8656 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); |
| 8657 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); |
| 8658 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); |
| 8659 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); |
| 8660 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); |
| 8661 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); |
| 8662 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); |
| 8663 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); |
| 8664 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); |
| 8665 | |
| 8666 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); |
| 8667 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); |
| 8668 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); |
| 8669 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); |
| 8670 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); |
| 8671 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); |
| 8672 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); |
| 8673 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); |
| 8674 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); |
| 8675 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); |
| 8676 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); |
| 8677 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); |
| 8678 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); |
| 8679 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 8680 | |
| 8681 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); |
| 8682 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
| 8683 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8684 | } |
| 8685 | |
| 8686 | static void tg3_timer(unsigned long __opaque) |
| 8687 | { |
| 8688 | struct tg3 *tp = (struct tg3 *) __opaque; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8689 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 8690 | if (tp->irq_sync) |
| 8691 | goto restart_timer; |
| 8692 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8693 | spin_lock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8694 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8695 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) { |
| 8696 | /* All of this garbage is because when using non-tagged |
| 8697 | * IRQ status the mailbox/status_block protocol the chip |
| 8698 | * uses with the cpu is race prone. |
| 8699 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8700 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8701 | tw32(GRC_LOCAL_CTRL, |
| 8702 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 8703 | } else { |
| 8704 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 8705 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8706 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8707 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8708 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 8709 | tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8710 | spin_unlock(&tp->lock); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8711 | schedule_work(&tp->reset_task); |
| 8712 | return; |
| 8713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8714 | } |
| 8715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8716 | /* This part only runs once per second. */ |
| 8717 | if (!--tp->timer_counter) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8718 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
| 8719 | tg3_periodic_fetch_stats(tp); |
| 8720 | |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 8721 | if (tp->setlpicnt && !--tp->setlpicnt) { |
| 8722 | u32 val = tr32(TG3_CPMU_EEE_MODE); |
| 8723 | tw32(TG3_CPMU_EEE_MODE, |
| 8724 | val | TG3_CPMU_EEEMD_LPI_ENABLE); |
| 8725 | } |
| 8726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8727 | if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) { |
| 8728 | u32 mac_stat; |
| 8729 | int phy_event; |
| 8730 | |
| 8731 | mac_stat = tr32(MAC_STATUS); |
| 8732 | |
| 8733 | phy_event = 0; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8734 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8735 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
| 8736 | phy_event = 1; |
| 8737 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) |
| 8738 | phy_event = 1; |
| 8739 | |
| 8740 | if (phy_event) |
| 8741 | tg3_setup_phy(tp, 0); |
| 8742 | } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) { |
| 8743 | u32 mac_stat = tr32(MAC_STATUS); |
| 8744 | int need_setup = 0; |
| 8745 | |
| 8746 | if (netif_carrier_ok(tp->dev) && |
| 8747 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
| 8748 | need_setup = 1; |
| 8749 | } |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 8750 | if (!netif_carrier_ok(tp->dev) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8751 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
| 8752 | MAC_STATUS_SIGNAL_DET))) { |
| 8753 | need_setup = 1; |
| 8754 | } |
| 8755 | if (need_setup) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 8756 | if (!tp->serdes_counter) { |
| 8757 | tw32_f(MAC_MODE, |
| 8758 | (tp->mac_mode & |
| 8759 | ~MAC_MODE_PORT_MODE_MASK)); |
| 8760 | udelay(40); |
| 8761 | tw32_f(MAC_MODE, tp->mac_mode); |
| 8762 | udelay(40); |
| 8763 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8764 | tg3_setup_phy(tp, 0); |
| 8765 | } |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 8766 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
Matt Carlson | 2138c00 | 2010-07-11 09:31:43 +0000 | [diff] [blame] | 8767 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 8768 | tg3_serdes_parallel_detect(tp); |
Matt Carlson | 57d8b88 | 2010-06-05 17:24:35 +0000 | [diff] [blame] | 8769 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8770 | |
| 8771 | tp->timer_counter = tp->timer_multiplier; |
| 8772 | } |
| 8773 | |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 8774 | /* Heartbeat is only sent once every 2 seconds. |
| 8775 | * |
| 8776 | * The heartbeat is to tell the ASF firmware that the host |
| 8777 | * driver is still alive. In the event that the OS crashes, |
| 8778 | * ASF needs to reset the hardware to free up the FIFO space |
| 8779 | * that may be filled with rx packets destined for the host. |
| 8780 | * If the FIFO is full, ASF will no longer function properly. |
| 8781 | * |
| 8782 | * Unintended resets have been reported on real time kernels |
| 8783 | * where the timer doesn't run on time. Netpoll will also have |
| 8784 | * same problem. |
| 8785 | * |
| 8786 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware |
| 8787 | * to check the ring condition when the heartbeat is expiring |
| 8788 | * before doing the reset. This will prevent most unintended |
| 8789 | * resets. |
| 8790 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8791 | if (!--tp->asf_counter) { |
Matt Carlson | bc7959b | 2008-08-15 14:08:55 -0700 | [diff] [blame] | 8792 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) && |
| 8793 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 8794 | tg3_wait_for_event_ack(tp); |
| 8795 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 8796 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 8797 | FWCMD_NICDRV_ALIVE3); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 8798 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 8799 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
| 8800 | TG3_FW_UPDATE_TIMEOUT_SEC); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 8801 | |
| 8802 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8803 | } |
| 8804 | tp->asf_counter = tp->asf_multiplier; |
| 8805 | } |
| 8806 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8807 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8808 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 8809 | restart_timer: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8810 | tp->timer.expires = jiffies + tp->timer_offset; |
| 8811 | add_timer(&tp->timer); |
| 8812 | } |
| 8813 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8814 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8815 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 8816 | irq_handler_t fn; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8817 | unsigned long flags; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8818 | char *name; |
| 8819 | struct tg3_napi *tnapi = &tp->napi[irq_num]; |
| 8820 | |
| 8821 | if (tp->irq_cnt == 1) |
| 8822 | name = tp->dev->name; |
| 8823 | else { |
| 8824 | name = &tnapi->irq_lbl[0]; |
| 8825 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); |
| 8826 | name[IFNAMSIZ-1] = 0; |
| 8827 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8828 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8829 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI_OR_MSIX) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8830 | fn = tg3_msi; |
| 8831 | if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) |
| 8832 | fn = tg3_msi_1shot; |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 8833 | flags = IRQF_SAMPLE_RANDOM; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8834 | } else { |
| 8835 | fn = tg3_interrupt; |
| 8836 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) |
| 8837 | fn = tg3_interrupt_tagged; |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 8838 | flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8839 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8840 | |
| 8841 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8842 | } |
| 8843 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8844 | static int tg3_test_interrupt(struct tg3 *tp) |
| 8845 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8846 | struct tg3_napi *tnapi = &tp->napi[0]; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8847 | struct net_device *dev = tp->dev; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8848 | int err, i, intr_ok = 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8849 | u32 val; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8850 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 8851 | if (!netif_running(dev)) |
| 8852 | return -ENODEV; |
| 8853 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8854 | tg3_disable_ints(tp); |
| 8855 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8856 | free_irq(tnapi->irq_vec, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8857 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8858 | /* |
| 8859 | * Turn off MSI one shot mode. Otherwise this test has no |
| 8860 | * observable way to know whether the interrupt was delivered. |
| 8861 | */ |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 8862 | if ((tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8863 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { |
| 8864 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
| 8865 | tw32(MSGINT_MODE, val); |
| 8866 | } |
| 8867 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8868 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8869 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8870 | if (err) |
| 8871 | return err; |
| 8872 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8873 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8874 | tg3_enable_ints(tp); |
| 8875 | |
| 8876 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 8877 | tnapi->coal_now); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8878 | |
| 8879 | for (i = 0; i < 5; i++) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8880 | u32 int_mbox, misc_host_ctrl; |
| 8881 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8882 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8883 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 8884 | |
| 8885 | if ((int_mbox != 0) || |
| 8886 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { |
| 8887 | intr_ok = 1; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8888 | break; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8889 | } |
| 8890 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8891 | msleep(10); |
| 8892 | } |
| 8893 | |
| 8894 | tg3_disable_ints(tp); |
| 8895 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8896 | free_irq(tnapi->irq_vec, tnapi); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 8897 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8898 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8899 | |
| 8900 | if (err) |
| 8901 | return err; |
| 8902 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8903 | if (intr_ok) { |
| 8904 | /* Reenable MSI one shot mode. */ |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 8905 | if ((tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8906 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { |
| 8907 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
| 8908 | tw32(MSGINT_MODE, val); |
| 8909 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8910 | return 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8911 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8912 | |
| 8913 | return -EIO; |
| 8914 | } |
| 8915 | |
| 8916 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is |
| 8917 | * successfully restored |
| 8918 | */ |
| 8919 | static int tg3_test_msi(struct tg3 *tp) |
| 8920 | { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8921 | int err; |
| 8922 | u16 pci_cmd; |
| 8923 | |
| 8924 | if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI)) |
| 8925 | return 0; |
| 8926 | |
| 8927 | /* Turn off SERR reporting in case MSI terminates with Master |
| 8928 | * Abort. |
| 8929 | */ |
| 8930 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 8931 | pci_write_config_word(tp->pdev, PCI_COMMAND, |
| 8932 | pci_cmd & ~PCI_COMMAND_SERR); |
| 8933 | |
| 8934 | err = tg3_test_interrupt(tp); |
| 8935 | |
| 8936 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 8937 | |
| 8938 | if (!err) |
| 8939 | return 0; |
| 8940 | |
| 8941 | /* other failures */ |
| 8942 | if (err != -EIO) |
| 8943 | return err; |
| 8944 | |
| 8945 | /* MSI test failed, go back to INTx mode */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 8946 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
| 8947 | "to INTx mode. Please report this failure to the PCI " |
| 8948 | "maintainer and include system chipset information\n"); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8949 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8950 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8951 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8952 | pci_disable_msi(tp->pdev); |
| 8953 | |
| 8954 | tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI; |
Andre Detsch | dc8bf1b | 2010-04-26 07:27:07 +0000 | [diff] [blame] | 8955 | tp->napi[0].irq_vec = tp->pdev->irq; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8956 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8957 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8958 | if (err) |
| 8959 | return err; |
| 8960 | |
| 8961 | /* Need to reset the chip because the MSI cycle may have terminated |
| 8962 | * with Master Abort. |
| 8963 | */ |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8964 | tg3_full_lock(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8965 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8966 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8967 | err = tg3_init_hw(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8968 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8969 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8970 | |
| 8971 | if (err) |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8972 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8973 | |
| 8974 | return err; |
| 8975 | } |
| 8976 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8977 | static int tg3_request_firmware(struct tg3 *tp) |
| 8978 | { |
| 8979 | const __be32 *fw_data; |
| 8980 | |
| 8981 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 8982 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
| 8983 | tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8984 | return -ENOENT; |
| 8985 | } |
| 8986 | |
| 8987 | fw_data = (void *)tp->fw->data; |
| 8988 | |
| 8989 | /* Firmware blob starts with version numbers, followed by |
| 8990 | * start address and _full_ length including BSS sections |
| 8991 | * (which must be longer than the actual data, of course |
| 8992 | */ |
| 8993 | |
| 8994 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ |
| 8995 | if (tp->fw_len < (tp->fw->size - 12)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 8996 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
| 8997 | tp->fw_len, tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8998 | release_firmware(tp->fw); |
| 8999 | tp->fw = NULL; |
| 9000 | return -EINVAL; |
| 9001 | } |
| 9002 | |
| 9003 | /* We no longer need firmware; we have it. */ |
| 9004 | tp->fw_needed = NULL; |
| 9005 | return 0; |
| 9006 | } |
| 9007 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9008 | static bool tg3_enable_msix(struct tg3 *tp) |
| 9009 | { |
| 9010 | int i, rc, cpus = num_online_cpus(); |
| 9011 | struct msix_entry msix_ent[tp->irq_max]; |
| 9012 | |
| 9013 | if (cpus == 1) |
| 9014 | /* Just fallback to the simpler MSI mode. */ |
| 9015 | return false; |
| 9016 | |
| 9017 | /* |
| 9018 | * We want as many rx rings enabled as there are cpus. |
| 9019 | * The first MSIX vector only deals with link interrupts, etc, |
| 9020 | * so we add one to the number of vectors we are requesting. |
| 9021 | */ |
| 9022 | tp->irq_cnt = min_t(unsigned, cpus + 1, tp->irq_max); |
| 9023 | |
| 9024 | for (i = 0; i < tp->irq_max; i++) { |
| 9025 | msix_ent[i].entry = i; |
| 9026 | msix_ent[i].vector = 0; |
| 9027 | } |
| 9028 | |
| 9029 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9030 | if (rc < 0) { |
| 9031 | return false; |
| 9032 | } else if (rc != 0) { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9033 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
| 9034 | return false; |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9035 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
| 9036 | tp->irq_cnt, rc); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9037 | tp->irq_cnt = rc; |
| 9038 | } |
| 9039 | |
| 9040 | for (i = 0; i < tp->irq_max; i++) |
| 9041 | tp->napi[i].irq_vec = msix_ent[i].vector; |
| 9042 | |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 9043 | netif_set_real_num_tx_queues(tp->dev, 1); |
| 9044 | rc = tp->irq_cnt > 1 ? tp->irq_cnt - 1 : 1; |
| 9045 | if (netif_set_real_num_rx_queues(tp->dev, rc)) { |
| 9046 | pci_disable_msix(tp->pdev); |
| 9047 | return false; |
| 9048 | } |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 9049 | |
| 9050 | if (tp->irq_cnt > 1) { |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9051 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_RSS; |
Matt Carlson | b92b904 | 2010-11-24 08:31:51 +0000 | [diff] [blame] | 9052 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
| 9053 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_TSS; |
| 9054 | netif_set_real_num_tx_queues(tp->dev, tp->irq_cnt - 1); |
| 9055 | } |
| 9056 | } |
Matt Carlson | 2430b03 | 2010-06-05 17:24:34 +0000 | [diff] [blame] | 9057 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9058 | return true; |
| 9059 | } |
| 9060 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9061 | static void tg3_ints_init(struct tg3 *tp) |
| 9062 | { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9063 | if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSI_OR_MSIX) && |
| 9064 | !(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) { |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9065 | /* All MSI supporting chips should support tagged |
| 9066 | * status. Assert that this is the case. |
| 9067 | */ |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 9068 | netdev_warn(tp->dev, |
| 9069 | "MSI without TAGGED_STATUS? Not using MSI\n"); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9070 | goto defcfg; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9071 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9072 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9073 | if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX) && tg3_enable_msix(tp)) |
| 9074 | tp->tg3_flags2 |= TG3_FLG2_USING_MSIX; |
| 9075 | else if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) && |
| 9076 | pci_enable_msi(tp->pdev) == 0) |
| 9077 | tp->tg3_flags2 |= TG3_FLG2_USING_MSI; |
| 9078 | |
| 9079 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI_OR_MSIX) { |
| 9080 | u32 msi_mode = tr32(MSGINT_MODE); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 9081 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) |
| 9082 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9083 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
| 9084 | } |
| 9085 | defcfg: |
| 9086 | if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSIX)) { |
| 9087 | tp->irq_cnt = 1; |
| 9088 | tp->napi[0].irq_vec = tp->pdev->irq; |
Ben Hutchings | 2ddaad3 | 2010-09-27 22:11:51 -0700 | [diff] [blame] | 9089 | netif_set_real_num_tx_queues(tp->dev, 1); |
Matt Carlson | 8540788 | 2010-10-06 13:40:58 -0700 | [diff] [blame] | 9090 | netif_set_real_num_rx_queues(tp->dev, 1); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9091 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9092 | } |
| 9093 | |
| 9094 | static void tg3_ints_fini(struct tg3 *tp) |
| 9095 | { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9096 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) |
| 9097 | pci_disable_msix(tp->pdev); |
| 9098 | else if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) |
| 9099 | pci_disable_msi(tp->pdev); |
| 9100 | tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI_OR_MSIX; |
Matt Carlson | 774ee75 | 2010-08-02 11:25:56 +0000 | [diff] [blame] | 9101 | tp->tg3_flags3 &= ~(TG3_FLG3_ENABLE_RSS | TG3_FLG3_ENABLE_TSS); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9102 | } |
| 9103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9104 | static int tg3_open(struct net_device *dev) |
| 9105 | { |
| 9106 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9107 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9108 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9109 | if (tp->fw_needed) { |
| 9110 | err = tg3_request_firmware(tp); |
| 9111 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 9112 | if (err) |
| 9113 | return err; |
| 9114 | } else if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9115 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9116 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE; |
| 9117 | } else if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 9118 | netdev_notice(tp->dev, "TSO capability restored\n"); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 9119 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
| 9120 | } |
| 9121 | } |
| 9122 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 9123 | netif_carrier_off(tp->dev); |
| 9124 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9125 | err = tg3_set_power_state(tp, PCI_D0); |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 9126 | if (err) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9127 | return err; |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 9128 | |
| 9129 | tg3_full_lock(tp, 0); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9131 | tg3_disable_ints(tp); |
| 9132 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
| 9133 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9134 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9135 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9136 | /* |
| 9137 | * Setup interrupts first so we know how |
| 9138 | * many NAPI resources to allocate |
| 9139 | */ |
| 9140 | tg3_ints_init(tp); |
| 9141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9142 | /* The placement of this call is tied |
| 9143 | * to the setup and use of Host TX descriptors. |
| 9144 | */ |
| 9145 | err = tg3_alloc_consistent(tp); |
| 9146 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9147 | goto err_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9148 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 9149 | tg3_napi_init(tp); |
| 9150 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 9151 | tg3_napi_enable(tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 9152 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9153 | for (i = 0; i < tp->irq_cnt; i++) { |
| 9154 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9155 | err = tg3_request_irq(tp, i); |
| 9156 | if (err) { |
| 9157 | for (i--; i >= 0; i--) |
| 9158 | free_irq(tnapi->irq_vec, tnapi); |
| 9159 | break; |
| 9160 | } |
| 9161 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9162 | |
| 9163 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9164 | goto err_out2; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9165 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9166 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9167 | |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 9168 | err = tg3_init_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9169 | if (err) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9170 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9171 | tg3_free_rings(tp); |
| 9172 | } else { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9173 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) |
| 9174 | tp->timer_offset = HZ; |
| 9175 | else |
| 9176 | tp->timer_offset = HZ / 10; |
| 9177 | |
| 9178 | BUG_ON(tp->timer_offset > HZ); |
| 9179 | tp->timer_counter = tp->timer_multiplier = |
| 9180 | (HZ / tp->timer_offset); |
| 9181 | tp->asf_counter = tp->asf_multiplier = |
Michael Chan | 28fbef7 | 2005-10-26 15:48:35 -0700 | [diff] [blame] | 9182 | ((HZ / tp->timer_offset) * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9183 | |
| 9184 | init_timer(&tp->timer); |
| 9185 | tp->timer.expires = jiffies + tp->timer_offset; |
| 9186 | tp->timer.data = (unsigned long) tp; |
| 9187 | tp->timer.function = tg3_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9188 | } |
| 9189 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9190 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9191 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9192 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9193 | goto err_out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9194 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9195 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { |
| 9196 | err = tg3_test_msi(tp); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 9197 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9198 | if (err) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9199 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9200 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9201 | tg3_free_rings(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9202 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9203 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9204 | goto err_out2; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9205 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9206 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 9207 | if (!(tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
| 9208 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9209 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9210 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 9211 | tw32(PCIE_TRANSACTION_CFG, |
| 9212 | val | PCIE_TRANS_CFG_1SHOT_MSI); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 9213 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9214 | } |
| 9215 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9216 | tg3_phy_start(tp); |
| 9217 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9218 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9219 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 9220 | add_timer(&tp->timer); |
| 9221 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9222 | tg3_enable_ints(tp); |
| 9223 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9224 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9225 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 9226 | netif_tx_start_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9227 | |
| 9228 | return 0; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9229 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9230 | err_out3: |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9231 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 9232 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9233 | free_irq(tnapi->irq_vec, tnapi); |
| 9234 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9235 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9236 | err_out2: |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 9237 | tg3_napi_disable(tp); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 9238 | tg3_napi_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9239 | tg3_free_consistent(tp); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 9240 | |
| 9241 | err_out1: |
| 9242 | tg3_ints_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9243 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9244 | } |
| 9245 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9246 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *, |
| 9247 | struct rtnl_link_stats64 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9248 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *); |
| 9249 | |
| 9250 | static int tg3_close(struct net_device *dev) |
| 9251 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9252 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9253 | struct tg3 *tp = netdev_priv(dev); |
| 9254 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 9255 | tg3_napi_disable(tp); |
Oleg Nesterov | 28e53bd | 2007-05-09 02:34:22 -0700 | [diff] [blame] | 9256 | cancel_work_sync(&tp->reset_task); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 9257 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 9258 | netif_tx_stop_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9259 | |
| 9260 | del_timer_sync(&tp->timer); |
| 9261 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 9262 | tg3_phy_stop(tp); |
| 9263 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9264 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9265 | |
| 9266 | tg3_disable_ints(tp); |
| 9267 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 9268 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9269 | tg3_free_rings(tp); |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 9270 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9271 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9272 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9273 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9274 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 9275 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9276 | free_irq(tnapi->irq_vec, tnapi); |
| 9277 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9278 | |
| 9279 | tg3_ints_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9280 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9281 | tg3_get_stats64(tp->dev, &tp->net_stats_prev); |
| 9282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9283 | memcpy(&tp->estats_prev, tg3_get_estats(tp), |
| 9284 | sizeof(tp->estats_prev)); |
| 9285 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 9286 | tg3_napi_fini(tp); |
| 9287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9288 | tg3_free_consistent(tp); |
| 9289 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9290 | tg3_set_power_state(tp, PCI_D3hot); |
| 9291 | |
| 9292 | netif_carrier_off(tp->dev); |
| 9293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9294 | return 0; |
| 9295 | } |
| 9296 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9297 | static inline u64 get_stat64(tg3_stat64_t *val) |
Stefan Buehler | 816f8b8 | 2008-08-15 14:10:54 -0700 | [diff] [blame] | 9298 | { |
| 9299 | return ((u64)val->high << 32) | ((u64)val->low); |
| 9300 | } |
| 9301 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9302 | static u64 calc_crc_errors(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9303 | { |
| 9304 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9305 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9306 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9307 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 9308 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9309 | u32 val; |
| 9310 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9311 | spin_lock_bh(&tp->lock); |
Michael Chan | 569a5df | 2007-02-13 12:18:15 -0800 | [diff] [blame] | 9312 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
| 9313 | tg3_writephy(tp, MII_TG3_TEST1, |
| 9314 | val | MII_TG3_TEST1_CRC_EN); |
Matt Carlson | f08aa1a | 2010-08-02 11:26:05 +0000 | [diff] [blame] | 9315 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9316 | } else |
| 9317 | val = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9318 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9319 | |
| 9320 | tp->phy_crc_errors += val; |
| 9321 | |
| 9322 | return tp->phy_crc_errors; |
| 9323 | } |
| 9324 | |
| 9325 | return get_stat64(&hw_stats->rx_fcs_errors); |
| 9326 | } |
| 9327 | |
| 9328 | #define ESTAT_ADD(member) \ |
| 9329 | estats->member = old_estats->member + \ |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9330 | get_stat64(&hw_stats->member) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9331 | |
| 9332 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp) |
| 9333 | { |
| 9334 | struct tg3_ethtool_stats *estats = &tp->estats; |
| 9335 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
| 9336 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9337 | |
| 9338 | if (!hw_stats) |
| 9339 | return old_estats; |
| 9340 | |
| 9341 | ESTAT_ADD(rx_octets); |
| 9342 | ESTAT_ADD(rx_fragments); |
| 9343 | ESTAT_ADD(rx_ucast_packets); |
| 9344 | ESTAT_ADD(rx_mcast_packets); |
| 9345 | ESTAT_ADD(rx_bcast_packets); |
| 9346 | ESTAT_ADD(rx_fcs_errors); |
| 9347 | ESTAT_ADD(rx_align_errors); |
| 9348 | ESTAT_ADD(rx_xon_pause_rcvd); |
| 9349 | ESTAT_ADD(rx_xoff_pause_rcvd); |
| 9350 | ESTAT_ADD(rx_mac_ctrl_rcvd); |
| 9351 | ESTAT_ADD(rx_xoff_entered); |
| 9352 | ESTAT_ADD(rx_frame_too_long_errors); |
| 9353 | ESTAT_ADD(rx_jabbers); |
| 9354 | ESTAT_ADD(rx_undersize_packets); |
| 9355 | ESTAT_ADD(rx_in_length_errors); |
| 9356 | ESTAT_ADD(rx_out_length_errors); |
| 9357 | ESTAT_ADD(rx_64_or_less_octet_packets); |
| 9358 | ESTAT_ADD(rx_65_to_127_octet_packets); |
| 9359 | ESTAT_ADD(rx_128_to_255_octet_packets); |
| 9360 | ESTAT_ADD(rx_256_to_511_octet_packets); |
| 9361 | ESTAT_ADD(rx_512_to_1023_octet_packets); |
| 9362 | ESTAT_ADD(rx_1024_to_1522_octet_packets); |
| 9363 | ESTAT_ADD(rx_1523_to_2047_octet_packets); |
| 9364 | ESTAT_ADD(rx_2048_to_4095_octet_packets); |
| 9365 | ESTAT_ADD(rx_4096_to_8191_octet_packets); |
| 9366 | ESTAT_ADD(rx_8192_to_9022_octet_packets); |
| 9367 | |
| 9368 | ESTAT_ADD(tx_octets); |
| 9369 | ESTAT_ADD(tx_collisions); |
| 9370 | ESTAT_ADD(tx_xon_sent); |
| 9371 | ESTAT_ADD(tx_xoff_sent); |
| 9372 | ESTAT_ADD(tx_flow_control); |
| 9373 | ESTAT_ADD(tx_mac_errors); |
| 9374 | ESTAT_ADD(tx_single_collisions); |
| 9375 | ESTAT_ADD(tx_mult_collisions); |
| 9376 | ESTAT_ADD(tx_deferred); |
| 9377 | ESTAT_ADD(tx_excessive_collisions); |
| 9378 | ESTAT_ADD(tx_late_collisions); |
| 9379 | ESTAT_ADD(tx_collide_2times); |
| 9380 | ESTAT_ADD(tx_collide_3times); |
| 9381 | ESTAT_ADD(tx_collide_4times); |
| 9382 | ESTAT_ADD(tx_collide_5times); |
| 9383 | ESTAT_ADD(tx_collide_6times); |
| 9384 | ESTAT_ADD(tx_collide_7times); |
| 9385 | ESTAT_ADD(tx_collide_8times); |
| 9386 | ESTAT_ADD(tx_collide_9times); |
| 9387 | ESTAT_ADD(tx_collide_10times); |
| 9388 | ESTAT_ADD(tx_collide_11times); |
| 9389 | ESTAT_ADD(tx_collide_12times); |
| 9390 | ESTAT_ADD(tx_collide_13times); |
| 9391 | ESTAT_ADD(tx_collide_14times); |
| 9392 | ESTAT_ADD(tx_collide_15times); |
| 9393 | ESTAT_ADD(tx_ucast_packets); |
| 9394 | ESTAT_ADD(tx_mcast_packets); |
| 9395 | ESTAT_ADD(tx_bcast_packets); |
| 9396 | ESTAT_ADD(tx_carrier_sense_errors); |
| 9397 | ESTAT_ADD(tx_discards); |
| 9398 | ESTAT_ADD(tx_errors); |
| 9399 | |
| 9400 | ESTAT_ADD(dma_writeq_full); |
| 9401 | ESTAT_ADD(dma_write_prioq_full); |
| 9402 | ESTAT_ADD(rxbds_empty); |
| 9403 | ESTAT_ADD(rx_discards); |
| 9404 | ESTAT_ADD(rx_errors); |
| 9405 | ESTAT_ADD(rx_threshold_hit); |
| 9406 | |
| 9407 | ESTAT_ADD(dma_readq_full); |
| 9408 | ESTAT_ADD(dma_read_prioq_full); |
| 9409 | ESTAT_ADD(tx_comp_queue_full); |
| 9410 | |
| 9411 | ESTAT_ADD(ring_set_send_prod_index); |
| 9412 | ESTAT_ADD(ring_status_update); |
| 9413 | ESTAT_ADD(nic_irqs); |
| 9414 | ESTAT_ADD(nic_avoided_irqs); |
| 9415 | ESTAT_ADD(nic_tx_threshold_hit); |
| 9416 | |
| 9417 | return estats; |
| 9418 | } |
| 9419 | |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9420 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
| 9421 | struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9422 | { |
| 9423 | struct tg3 *tp = netdev_priv(dev); |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 9424 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9425 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9426 | |
| 9427 | if (!hw_stats) |
| 9428 | return old_stats; |
| 9429 | |
| 9430 | stats->rx_packets = old_stats->rx_packets + |
| 9431 | get_stat64(&hw_stats->rx_ucast_packets) + |
| 9432 | get_stat64(&hw_stats->rx_mcast_packets) + |
| 9433 | get_stat64(&hw_stats->rx_bcast_packets); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9435 | stats->tx_packets = old_stats->tx_packets + |
| 9436 | get_stat64(&hw_stats->tx_ucast_packets) + |
| 9437 | get_stat64(&hw_stats->tx_mcast_packets) + |
| 9438 | get_stat64(&hw_stats->tx_bcast_packets); |
| 9439 | |
| 9440 | stats->rx_bytes = old_stats->rx_bytes + |
| 9441 | get_stat64(&hw_stats->rx_octets); |
| 9442 | stats->tx_bytes = old_stats->tx_bytes + |
| 9443 | get_stat64(&hw_stats->tx_octets); |
| 9444 | |
| 9445 | stats->rx_errors = old_stats->rx_errors + |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 9446 | get_stat64(&hw_stats->rx_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9447 | stats->tx_errors = old_stats->tx_errors + |
| 9448 | get_stat64(&hw_stats->tx_errors) + |
| 9449 | get_stat64(&hw_stats->tx_mac_errors) + |
| 9450 | get_stat64(&hw_stats->tx_carrier_sense_errors) + |
| 9451 | get_stat64(&hw_stats->tx_discards); |
| 9452 | |
| 9453 | stats->multicast = old_stats->multicast + |
| 9454 | get_stat64(&hw_stats->rx_mcast_packets); |
| 9455 | stats->collisions = old_stats->collisions + |
| 9456 | get_stat64(&hw_stats->tx_collisions); |
| 9457 | |
| 9458 | stats->rx_length_errors = old_stats->rx_length_errors + |
| 9459 | get_stat64(&hw_stats->rx_frame_too_long_errors) + |
| 9460 | get_stat64(&hw_stats->rx_undersize_packets); |
| 9461 | |
| 9462 | stats->rx_over_errors = old_stats->rx_over_errors + |
| 9463 | get_stat64(&hw_stats->rxbds_empty); |
| 9464 | stats->rx_frame_errors = old_stats->rx_frame_errors + |
| 9465 | get_stat64(&hw_stats->rx_align_errors); |
| 9466 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + |
| 9467 | get_stat64(&hw_stats->tx_discards); |
| 9468 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + |
| 9469 | get_stat64(&hw_stats->tx_carrier_sense_errors); |
| 9470 | |
| 9471 | stats->rx_crc_errors = old_stats->rx_crc_errors + |
| 9472 | calc_crc_errors(tp); |
| 9473 | |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 9474 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
| 9475 | get_stat64(&hw_stats->rx_discards); |
| 9476 | |
Eric Dumazet | b0057c5 | 2010-10-10 19:55:52 +0000 | [diff] [blame] | 9477 | stats->rx_dropped = tp->rx_dropped; |
| 9478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9479 | return stats; |
| 9480 | } |
| 9481 | |
| 9482 | static inline u32 calc_crc(unsigned char *buf, int len) |
| 9483 | { |
| 9484 | u32 reg; |
| 9485 | u32 tmp; |
| 9486 | int j, k; |
| 9487 | |
| 9488 | reg = 0xffffffff; |
| 9489 | |
| 9490 | for (j = 0; j < len; j++) { |
| 9491 | reg ^= buf[j]; |
| 9492 | |
| 9493 | for (k = 0; k < 8; k++) { |
| 9494 | tmp = reg & 0x01; |
| 9495 | |
| 9496 | reg >>= 1; |
| 9497 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 9498 | if (tmp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9499 | reg ^= 0xedb88320; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9500 | } |
| 9501 | } |
| 9502 | |
| 9503 | return ~reg; |
| 9504 | } |
| 9505 | |
| 9506 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) |
| 9507 | { |
| 9508 | /* accept or reject all multicast frames */ |
| 9509 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); |
| 9510 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); |
| 9511 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); |
| 9512 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); |
| 9513 | } |
| 9514 | |
| 9515 | static void __tg3_set_rx_mode(struct net_device *dev) |
| 9516 | { |
| 9517 | struct tg3 *tp = netdev_priv(dev); |
| 9518 | u32 rx_mode; |
| 9519 | |
| 9520 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
| 9521 | RX_MODE_KEEP_VLAN_TAG); |
| 9522 | |
| 9523 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
| 9524 | * flag clear. |
| 9525 | */ |
| 9526 | #if TG3_VLAN_TAG_USED |
| 9527 | if (!tp->vlgrp && |
| 9528 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 9529 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 9530 | #else |
| 9531 | /* By definition, VLAN is disabled always in this |
| 9532 | * case. |
| 9533 | */ |
| 9534 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 9535 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 9536 | #endif |
| 9537 | |
| 9538 | if (dev->flags & IFF_PROMISC) { |
| 9539 | /* Promiscuous mode. */ |
| 9540 | rx_mode |= RX_MODE_PROMISC; |
| 9541 | } else if (dev->flags & IFF_ALLMULTI) { |
| 9542 | /* Accept all multicast. */ |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 9543 | tg3_set_multi(tp, 1); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 9544 | } else if (netdev_mc_empty(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9545 | /* Reject all multicast. */ |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 9546 | tg3_set_multi(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9547 | } else { |
| 9548 | /* Accept one or more multicast(s). */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 9549 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9550 | u32 mc_filter[4] = { 0, }; |
| 9551 | u32 regidx; |
| 9552 | u32 bit; |
| 9553 | u32 crc; |
| 9554 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 9555 | netdev_for_each_mc_addr(ha, dev) { |
| 9556 | crc = calc_crc(ha->addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9557 | bit = ~crc & 0x7f; |
| 9558 | regidx = (bit & 0x60) >> 5; |
| 9559 | bit &= 0x1f; |
| 9560 | mc_filter[regidx] |= (1 << bit); |
| 9561 | } |
| 9562 | |
| 9563 | tw32(MAC_HASH_REG_0, mc_filter[0]); |
| 9564 | tw32(MAC_HASH_REG_1, mc_filter[1]); |
| 9565 | tw32(MAC_HASH_REG_2, mc_filter[2]); |
| 9566 | tw32(MAC_HASH_REG_3, mc_filter[3]); |
| 9567 | } |
| 9568 | |
| 9569 | if (rx_mode != tp->rx_mode) { |
| 9570 | tp->rx_mode = rx_mode; |
| 9571 | tw32_f(MAC_RX_MODE, rx_mode); |
| 9572 | udelay(10); |
| 9573 | } |
| 9574 | } |
| 9575 | |
| 9576 | static void tg3_set_rx_mode(struct net_device *dev) |
| 9577 | { |
| 9578 | struct tg3 *tp = netdev_priv(dev); |
| 9579 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 9580 | if (!netif_running(dev)) |
| 9581 | return; |
| 9582 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9583 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9584 | __tg3_set_rx_mode(dev); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9585 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9586 | } |
| 9587 | |
| 9588 | #define TG3_REGDUMP_LEN (32 * 1024) |
| 9589 | |
| 9590 | static int tg3_get_regs_len(struct net_device *dev) |
| 9591 | { |
| 9592 | return TG3_REGDUMP_LEN; |
| 9593 | } |
| 9594 | |
| 9595 | static void tg3_get_regs(struct net_device *dev, |
| 9596 | struct ethtool_regs *regs, void *_p) |
| 9597 | { |
| 9598 | u32 *p = _p; |
| 9599 | struct tg3 *tp = netdev_priv(dev); |
| 9600 | u8 *orig_p = _p; |
| 9601 | int i; |
| 9602 | |
| 9603 | regs->version = 0; |
| 9604 | |
| 9605 | memset(p, 0, TG3_REGDUMP_LEN); |
| 9606 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9607 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9608 | return; |
| 9609 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9610 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9611 | |
| 9612 | #define __GET_REG32(reg) (*(p)++ = tr32(reg)) |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 9613 | #define GET_REG32_LOOP(base, len) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9614 | do { p = (u32 *)(orig_p + (base)); \ |
| 9615 | for (i = 0; i < len; i += 4) \ |
| 9616 | __GET_REG32((base) + i); \ |
| 9617 | } while (0) |
| 9618 | #define GET_REG32_1(reg) \ |
| 9619 | do { p = (u32 *)(orig_p + (reg)); \ |
| 9620 | __GET_REG32((reg)); \ |
| 9621 | } while (0) |
| 9622 | |
| 9623 | GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0); |
| 9624 | GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200); |
| 9625 | GET_REG32_LOOP(MAC_MODE, 0x4f0); |
| 9626 | GET_REG32_LOOP(SNDDATAI_MODE, 0xe0); |
| 9627 | GET_REG32_1(SNDDATAC_MODE); |
| 9628 | GET_REG32_LOOP(SNDBDS_MODE, 0x80); |
| 9629 | GET_REG32_LOOP(SNDBDI_MODE, 0x48); |
| 9630 | GET_REG32_1(SNDBDC_MODE); |
| 9631 | GET_REG32_LOOP(RCVLPC_MODE, 0x20); |
| 9632 | GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c); |
| 9633 | GET_REG32_LOOP(RCVDBDI_MODE, 0x0c); |
| 9634 | GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c); |
| 9635 | GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44); |
| 9636 | GET_REG32_1(RCVDCC_MODE); |
| 9637 | GET_REG32_LOOP(RCVBDI_MODE, 0x20); |
| 9638 | GET_REG32_LOOP(RCVCC_MODE, 0x14); |
| 9639 | GET_REG32_LOOP(RCVLSC_MODE, 0x08); |
| 9640 | GET_REG32_1(MBFREE_MODE); |
| 9641 | GET_REG32_LOOP(HOSTCC_MODE, 0x100); |
| 9642 | GET_REG32_LOOP(MEMARB_MODE, 0x10); |
| 9643 | GET_REG32_LOOP(BUFMGR_MODE, 0x58); |
| 9644 | GET_REG32_LOOP(RDMAC_MODE, 0x08); |
| 9645 | GET_REG32_LOOP(WDMAC_MODE, 0x08); |
Chris Elmquist | 091465d | 2005-12-20 13:25:19 -0800 | [diff] [blame] | 9646 | GET_REG32_1(RX_CPU_MODE); |
| 9647 | GET_REG32_1(RX_CPU_STATE); |
| 9648 | GET_REG32_1(RX_CPU_PGMCTR); |
| 9649 | GET_REG32_1(RX_CPU_HWBKPT); |
| 9650 | GET_REG32_1(TX_CPU_MODE); |
| 9651 | GET_REG32_1(TX_CPU_STATE); |
| 9652 | GET_REG32_1(TX_CPU_PGMCTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9653 | GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110); |
| 9654 | GET_REG32_LOOP(FTQ_RESET, 0x120); |
| 9655 | GET_REG32_LOOP(MSGINT_MODE, 0x0c); |
| 9656 | GET_REG32_1(DMAC_MODE); |
| 9657 | GET_REG32_LOOP(GRC_MODE, 0x4c); |
| 9658 | if (tp->tg3_flags & TG3_FLAG_NVRAM) |
| 9659 | GET_REG32_LOOP(NVRAM_CMD, 0x24); |
| 9660 | |
| 9661 | #undef __GET_REG32 |
| 9662 | #undef GET_REG32_LOOP |
| 9663 | #undef GET_REG32_1 |
| 9664 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9665 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9666 | } |
| 9667 | |
| 9668 | static int tg3_get_eeprom_len(struct net_device *dev) |
| 9669 | { |
| 9670 | struct tg3 *tp = netdev_priv(dev); |
| 9671 | |
| 9672 | return tp->nvram_size; |
| 9673 | } |
| 9674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9675 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 9676 | { |
| 9677 | struct tg3 *tp = netdev_priv(dev); |
| 9678 | int ret; |
| 9679 | u8 *pd; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9680 | u32 i, offset, len, b_offset, b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9681 | __be32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9682 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 9683 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) |
| 9684 | return -EINVAL; |
| 9685 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9686 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9687 | return -EAGAIN; |
| 9688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9689 | offset = eeprom->offset; |
| 9690 | len = eeprom->len; |
| 9691 | eeprom->len = 0; |
| 9692 | |
| 9693 | eeprom->magic = TG3_EEPROM_MAGIC; |
| 9694 | |
| 9695 | if (offset & 3) { |
| 9696 | /* adjustments to start on required 4 byte boundary */ |
| 9697 | b_offset = offset & 3; |
| 9698 | b_count = 4 - b_offset; |
| 9699 | if (b_count > len) { |
| 9700 | /* i.e. offset=1 len=2 */ |
| 9701 | b_count = len; |
| 9702 | } |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9703 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9704 | if (ret) |
| 9705 | return ret; |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 9706 | memcpy(data, ((char *)&val) + b_offset, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9707 | len -= b_count; |
| 9708 | offset += b_count; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 9709 | eeprom->len += b_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9710 | } |
| 9711 | |
| 9712 | /* read bytes upto the last 4 byte boundary */ |
| 9713 | pd = &data[eeprom->len]; |
| 9714 | for (i = 0; i < (len - (len & 3)); i += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9715 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9716 | if (ret) { |
| 9717 | eeprom->len += i; |
| 9718 | return ret; |
| 9719 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9720 | memcpy(pd + i, &val, 4); |
| 9721 | } |
| 9722 | eeprom->len += i; |
| 9723 | |
| 9724 | if (len & 3) { |
| 9725 | /* read last bytes not ending on 4 byte boundary */ |
| 9726 | pd = &data[eeprom->len]; |
| 9727 | b_count = len & 3; |
| 9728 | b_offset = offset + len - b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9729 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9730 | if (ret) |
| 9731 | return ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9732 | memcpy(pd, &val, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9733 | eeprom->len += b_count; |
| 9734 | } |
| 9735 | return 0; |
| 9736 | } |
| 9737 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9738 | 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] | 9739 | |
| 9740 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 9741 | { |
| 9742 | struct tg3 *tp = netdev_priv(dev); |
| 9743 | int ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9744 | u32 offset, len, b_offset, odd_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9745 | u8 *buf; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9746 | __be32 start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9747 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 9748 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9749 | return -EAGAIN; |
| 9750 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 9751 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
| 9752 | eeprom->magic != TG3_EEPROM_MAGIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9753 | return -EINVAL; |
| 9754 | |
| 9755 | offset = eeprom->offset; |
| 9756 | len = eeprom->len; |
| 9757 | |
| 9758 | if ((b_offset = (offset & 3))) { |
| 9759 | /* adjustments to start on required 4 byte boundary */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9760 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9761 | if (ret) |
| 9762 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9763 | len += b_offset; |
| 9764 | offset &= ~3; |
Michael Chan | 1c8594b | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 9765 | if (len < 4) |
| 9766 | len = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9767 | } |
| 9768 | |
| 9769 | odd_len = 0; |
Michael Chan | 1c8594b | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 9770 | if (len & 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9771 | /* adjustments to end on required 4 byte boundary */ |
| 9772 | odd_len = 1; |
| 9773 | len = (len + 3) & ~3; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9774 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9775 | if (ret) |
| 9776 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9777 | } |
| 9778 | |
| 9779 | buf = data; |
| 9780 | if (b_offset || odd_len) { |
| 9781 | buf = kmalloc(len, GFP_KERNEL); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 9782 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9783 | return -ENOMEM; |
| 9784 | if (b_offset) |
| 9785 | memcpy(buf, &start, 4); |
| 9786 | if (odd_len) |
| 9787 | memcpy(buf+len-4, &end, 4); |
| 9788 | memcpy(buf + b_offset, data, eeprom->len); |
| 9789 | } |
| 9790 | |
| 9791 | ret = tg3_nvram_write_block(tp, offset, len, buf); |
| 9792 | |
| 9793 | if (buf != data) |
| 9794 | kfree(buf); |
| 9795 | |
| 9796 | return ret; |
| 9797 | } |
| 9798 | |
| 9799 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 9800 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9801 | struct tg3 *tp = netdev_priv(dev); |
| 9802 | |
| 9803 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9804 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9805 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9806 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9807 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 9808 | return phy_ethtool_gset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9809 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9811 | cmd->supported = (SUPPORTED_Autoneg); |
| 9812 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9813 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9814 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
| 9815 | SUPPORTED_1000baseT_Full); |
| 9816 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9817 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9818 | cmd->supported |= (SUPPORTED_100baseT_Half | |
| 9819 | SUPPORTED_100baseT_Full | |
| 9820 | SUPPORTED_10baseT_Half | |
| 9821 | SUPPORTED_10baseT_Full | |
Matt Carlson | 3bebab5 | 2007-11-12 21:22:40 -0800 | [diff] [blame] | 9822 | SUPPORTED_TP); |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 9823 | cmd->port = PORT_TP; |
| 9824 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9825 | cmd->supported |= SUPPORTED_FIBRE; |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 9826 | cmd->port = PORT_FIBRE; |
| 9827 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9829 | cmd->advertising = tp->link_config.advertising; |
| 9830 | if (netif_running(dev)) { |
| 9831 | cmd->speed = tp->link_config.active_speed; |
| 9832 | cmd->duplex = tp->link_config.active_duplex; |
Matt Carlson | 64c2218 | 2010-10-14 10:37:44 +0000 | [diff] [blame] | 9833 | } else { |
| 9834 | cmd->speed = SPEED_INVALID; |
| 9835 | cmd->duplex = DUPLEX_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9836 | } |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 9837 | cmd->phy_address = tp->phy_addr; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9838 | cmd->transceiver = XCVR_INTERNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9839 | cmd->autoneg = tp->link_config.autoneg; |
| 9840 | cmd->maxtxpkt = 0; |
| 9841 | cmd->maxrxpkt = 0; |
| 9842 | return 0; |
| 9843 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9845 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 9846 | { |
| 9847 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9848 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9849 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9850 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9851 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9852 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9853 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 9854 | return phy_ethtool_sset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9855 | } |
| 9856 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9857 | if (cmd->autoneg != AUTONEG_ENABLE && |
| 9858 | cmd->autoneg != AUTONEG_DISABLE) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 9859 | return -EINVAL; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9860 | |
| 9861 | if (cmd->autoneg == AUTONEG_DISABLE && |
| 9862 | cmd->duplex != DUPLEX_FULL && |
| 9863 | cmd->duplex != DUPLEX_HALF) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 9864 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9865 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9866 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 9867 | u32 mask = ADVERTISED_Autoneg | |
| 9868 | ADVERTISED_Pause | |
| 9869 | ADVERTISED_Asym_Pause; |
| 9870 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9871 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9872 | mask |= ADVERTISED_1000baseT_Half | |
| 9873 | ADVERTISED_1000baseT_Full; |
| 9874 | |
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 | mask |= ADVERTISED_100baseT_Half | |
| 9877 | ADVERTISED_100baseT_Full | |
| 9878 | ADVERTISED_10baseT_Half | |
| 9879 | ADVERTISED_10baseT_Full | |
| 9880 | ADVERTISED_TP; |
| 9881 | else |
| 9882 | mask |= ADVERTISED_FIBRE; |
| 9883 | |
| 9884 | if (cmd->advertising & ~mask) |
| 9885 | return -EINVAL; |
| 9886 | |
| 9887 | mask &= (ADVERTISED_1000baseT_Half | |
| 9888 | ADVERTISED_1000baseT_Full | |
| 9889 | ADVERTISED_100baseT_Half | |
| 9890 | ADVERTISED_100baseT_Full | |
| 9891 | ADVERTISED_10baseT_Half | |
| 9892 | ADVERTISED_10baseT_Full); |
| 9893 | |
| 9894 | cmd->advertising &= mask; |
| 9895 | } else { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 9896 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9897 | if (cmd->speed != SPEED_1000) |
| 9898 | return -EINVAL; |
| 9899 | |
| 9900 | if (cmd->duplex != DUPLEX_FULL) |
| 9901 | return -EINVAL; |
| 9902 | } else { |
| 9903 | if (cmd->speed != SPEED_100 && |
| 9904 | cmd->speed != SPEED_10) |
| 9905 | return -EINVAL; |
| 9906 | } |
| 9907 | } |
| 9908 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9909 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9910 | |
| 9911 | tp->link_config.autoneg = cmd->autoneg; |
| 9912 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Andy Gospodarek | 405d8e5 | 2007-10-08 01:08:47 -0700 | [diff] [blame] | 9913 | tp->link_config.advertising = (cmd->advertising | |
| 9914 | ADVERTISED_Autoneg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9915 | tp->link_config.speed = SPEED_INVALID; |
| 9916 | tp->link_config.duplex = DUPLEX_INVALID; |
| 9917 | } else { |
| 9918 | tp->link_config.advertising = 0; |
| 9919 | tp->link_config.speed = cmd->speed; |
| 9920 | tp->link_config.duplex = cmd->duplex; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9921 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9922 | |
Michael Chan | 24fcad6 | 2006-12-17 17:06:46 -0800 | [diff] [blame] | 9923 | tp->link_config.orig_speed = tp->link_config.speed; |
| 9924 | tp->link_config.orig_duplex = tp->link_config.duplex; |
| 9925 | tp->link_config.orig_autoneg = tp->link_config.autoneg; |
| 9926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9927 | if (netif_running(dev)) |
| 9928 | tg3_setup_phy(tp, 1); |
| 9929 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9930 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9932 | return 0; |
| 9933 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9935 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 9936 | { |
| 9937 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9939 | strcpy(info->driver, DRV_MODULE_NAME); |
| 9940 | strcpy(info->version, DRV_MODULE_VERSION); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 9941 | strcpy(info->fw_version, tp->fw_ver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9942 | strcpy(info->bus_info, pci_name(tp->pdev)); |
| 9943 | } |
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 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 9946 | { |
| 9947 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9948 | |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9949 | if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) && |
| 9950 | device_can_wakeup(&tp->pdev->dev)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 9951 | wol->supported = WAKE_MAGIC; |
| 9952 | else |
| 9953 | wol->supported = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9954 | wol->wolopts = 0; |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 9955 | if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) && |
| 9956 | device_can_wakeup(&tp->pdev->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9957 | wol->wolopts = WAKE_MAGIC; |
| 9958 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 9959 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9961 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 9962 | { |
| 9963 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9964 | struct device *dp = &tp->pdev->dev; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9966 | if (wol->wolopts & ~WAKE_MAGIC) |
| 9967 | return -EINVAL; |
| 9968 | if ((wol->wolopts & WAKE_MAGIC) && |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9969 | !((tp->tg3_flags & TG3_FLAG_WOL_CAP) && device_can_wakeup(dp))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9970 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9971 | |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 9972 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
| 9973 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9974 | spin_lock_bh(&tp->lock); |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 9975 | if (device_may_wakeup(dp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9976 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 9977 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9978 | tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9979 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9980 | |
Rafael J. Wysocki | f2dc0d1 | 2010-10-25 13:01:55 +0000 | [diff] [blame] | 9981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9982 | return 0; |
| 9983 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9985 | static u32 tg3_get_msglevel(struct net_device *dev) |
| 9986 | { |
| 9987 | struct tg3 *tp = netdev_priv(dev); |
| 9988 | return tp->msg_enable; |
| 9989 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9991 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
| 9992 | { |
| 9993 | struct tg3 *tp = netdev_priv(dev); |
| 9994 | tp->msg_enable = value; |
| 9995 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9997 | static int tg3_set_tso(struct net_device *dev, u32 value) |
| 9998 | { |
| 9999 | struct tg3 *tp = netdev_priv(dev); |
| 10000 | |
| 10001 | if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { |
| 10002 | if (value) |
| 10003 | return -EINVAL; |
| 10004 | return 0; |
| 10005 | } |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 10006 | if ((dev->features & NETIF_F_IPV6_CSUM) && |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 10007 | ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) || |
| 10008 | (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3))) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 10009 | if (value) { |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 10010 | dev->features |= NETIF_F_TSO6; |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 10011 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
| 10012 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 10013 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 10014 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10015 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 10016 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 10017 | dev->features |= NETIF_F_TSO_ECN; |
| 10018 | } else |
| 10019 | dev->features &= ~(NETIF_F_TSO6 | NETIF_F_TSO_ECN); |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 10020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10021 | return ethtool_op_set_tso(dev, value); |
| 10022 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10024 | static int tg3_nway_reset(struct net_device *dev) |
| 10025 | { |
| 10026 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10027 | int r; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10029 | if (!netif_running(dev)) |
| 10030 | return -EAGAIN; |
| 10031 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10032 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10033 | return -EINVAL; |
| 10034 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10035 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10036 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10037 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 10038 | 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] | 10039 | } else { |
| 10040 | u32 bmcr; |
| 10041 | |
| 10042 | spin_lock_bh(&tp->lock); |
| 10043 | r = -EINVAL; |
| 10044 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 10045 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && |
| 10046 | ((bmcr & BMCR_ANENABLE) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10047 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10048 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
| 10049 | BMCR_ANENABLE); |
| 10050 | r = 0; |
| 10051 | } |
| 10052 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10053 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10055 | return r; |
| 10056 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10058 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 10059 | { |
| 10060 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10061 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10062 | ering->rx_max_pending = tp->rx_std_ring_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10063 | ering->rx_mini_max_pending = 0; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10064 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10065 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10066 | else |
| 10067 | ering->rx_jumbo_max_pending = 0; |
| 10068 | |
| 10069 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10070 | |
| 10071 | ering->rx_pending = tp->rx_pending; |
| 10072 | ering->rx_mini_pending = 0; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 10073 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) |
| 10074 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
| 10075 | else |
| 10076 | ering->rx_jumbo_pending = 0; |
| 10077 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10078 | ering->tx_pending = tp->napi[0].tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10079 | } |
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 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 10082 | { |
| 10083 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10084 | int i, irq_sync = 0, err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10085 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 10086 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
| 10087 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10088 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
| 10089 | (ering->tx_pending <= MAX_SKB_FRAGS) || |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 10090 | ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) && |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10091 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10092 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10093 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10094 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10095 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10096 | tg3_netif_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10097 | irq_sync = 1; |
| 10098 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10099 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10100 | tg3_full_lock(tp, irq_sync); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10102 | tp->rx_pending = ering->rx_pending; |
| 10103 | |
| 10104 | if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) && |
| 10105 | tp->rx_pending > 63) |
| 10106 | tp->rx_pending = 63; |
| 10107 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10108 | |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 10109 | for (i = 0; i < tp->irq_max; i++) |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10110 | tp->napi[i].tx_pending = ering->tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10111 | |
| 10112 | if (netif_running(dev)) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10113 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10114 | err = tg3_restart_hw(tp, 1); |
| 10115 | if (!err) |
| 10116 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10117 | } |
| 10118 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10119 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10120 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10121 | if (irq_sync && !err) |
| 10122 | tg3_phy_start(tp); |
| 10123 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10124 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10125 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10127 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10128 | { |
| 10129 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10131 | epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0; |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10132 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10133 | if (tp->link_config.active_flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10134 | epause->rx_pause = 1; |
| 10135 | else |
| 10136 | epause->rx_pause = 0; |
| 10137 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10138 | if (tp->link_config.active_flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10139 | epause->tx_pause = 1; |
| 10140 | else |
| 10141 | epause->tx_pause = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10142 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10144 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10145 | { |
| 10146 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10147 | int err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10148 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10149 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10150 | u32 newadv; |
| 10151 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10152 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10153 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
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 (!(phydev->supported & SUPPORTED_Pause) || |
| 10156 | (!(phydev->supported & SUPPORTED_Asym_Pause) && |
Nicolas Kaiser | 2259dca | 2010-10-07 23:29:27 +0000 | [diff] [blame] | 10157 | (epause->rx_pause != epause->tx_pause))) |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10158 | return -EINVAL; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10159 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10160 | tp->link_config.flowctrl = 0; |
| 10161 | if (epause->rx_pause) { |
| 10162 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10163 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10164 | if (epause->tx_pause) { |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10165 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10166 | newadv = ADVERTISED_Pause; |
| 10167 | } else |
| 10168 | newadv = ADVERTISED_Pause | |
| 10169 | ADVERTISED_Asym_Pause; |
| 10170 | } else if (epause->tx_pause) { |
| 10171 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 10172 | newadv = ADVERTISED_Asym_Pause; |
| 10173 | } else |
| 10174 | newadv = 0; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10175 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10176 | if (epause->autoneg) |
| 10177 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; |
| 10178 | else |
| 10179 | tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG; |
| 10180 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10181 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10182 | u32 oldadv = phydev->advertising & |
| 10183 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 10184 | if (oldadv != newadv) { |
| 10185 | phydev->advertising &= |
| 10186 | ~(ADVERTISED_Pause | |
| 10187 | ADVERTISED_Asym_Pause); |
| 10188 | phydev->advertising |= newadv; |
| 10189 | if (phydev->autoneg) { |
| 10190 | /* |
| 10191 | * Always renegotiate the link to |
| 10192 | * inform our link partner of our |
| 10193 | * flow control settings, even if the |
| 10194 | * flow control is forced. Let |
| 10195 | * tg3_adjust_link() do the final |
| 10196 | * flow control setup. |
| 10197 | */ |
| 10198 | return phy_start_aneg(phydev); |
| 10199 | } |
| 10200 | } |
| 10201 | |
| 10202 | if (!epause->autoneg) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10203 | tg3_setup_flow_control(tp, 0, 0); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10204 | } else { |
| 10205 | tp->link_config.orig_advertising &= |
| 10206 | ~(ADVERTISED_Pause | |
| 10207 | ADVERTISED_Asym_Pause); |
| 10208 | tp->link_config.orig_advertising |= newadv; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10209 | } |
| 10210 | } else { |
| 10211 | int irq_sync = 0; |
| 10212 | |
| 10213 | if (netif_running(dev)) { |
| 10214 | tg3_netif_stop(tp); |
| 10215 | irq_sync = 1; |
| 10216 | } |
| 10217 | |
| 10218 | tg3_full_lock(tp, irq_sync); |
| 10219 | |
| 10220 | if (epause->autoneg) |
| 10221 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; |
| 10222 | else |
| 10223 | tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG; |
| 10224 | if (epause->rx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10225 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10226 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10227 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10228 | if (epause->tx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10229 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10230 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10231 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10232 | |
| 10233 | if (netif_running(dev)) { |
| 10234 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 10235 | err = tg3_restart_hw(tp, 1); |
| 10236 | if (!err) |
| 10237 | tg3_netif_start(tp); |
| 10238 | } |
| 10239 | |
| 10240 | tg3_full_unlock(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10242 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10243 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10244 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10246 | static u32 tg3_get_rx_csum(struct net_device *dev) |
| 10247 | { |
| 10248 | struct tg3 *tp = netdev_priv(dev); |
| 10249 | return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0; |
| 10250 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10252 | static int tg3_set_rx_csum(struct net_device *dev, u32 data) |
| 10253 | { |
| 10254 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10256 | if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) { |
| 10257 | if (data != 0) |
| 10258 | return -EINVAL; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10259 | return 0; |
| 10260 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10261 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10262 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10263 | if (data) |
| 10264 | tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; |
| 10265 | else |
| 10266 | tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10267 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10269 | return 0; |
| 10270 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10272 | static int tg3_set_tx_csum(struct net_device *dev, u32 data) |
| 10273 | { |
| 10274 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10276 | if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) { |
| 10277 | if (data != 0) |
| 10278 | return -EINVAL; |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10279 | return 0; |
| 10280 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10281 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10282 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Michael Chan | 6460d94 | 2007-07-14 19:07:52 -0700 | [diff] [blame] | 10283 | ethtool_op_set_tx_ipv6_csum(dev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10284 | else |
Michael Chan | 9c27dbd | 2006-03-20 22:28:27 -0800 | [diff] [blame] | 10285 | ethtool_op_set_tx_csum(dev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10286 | |
| 10287 | return 0; |
| 10288 | } |
| 10289 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10290 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10291 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 10292 | switch (sset) { |
| 10293 | case ETH_SS_TEST: |
| 10294 | return TG3_NUM_TEST; |
| 10295 | case ETH_SS_STATS: |
| 10296 | return TG3_NUM_STATS; |
| 10297 | default: |
| 10298 | return -EOPNOTSUPP; |
| 10299 | } |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10300 | } |
| 10301 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10302 | 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] | 10303 | { |
| 10304 | switch (stringset) { |
| 10305 | case ETH_SS_STATS: |
| 10306 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 10307 | break; |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10308 | case ETH_SS_TEST: |
| 10309 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); |
| 10310 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10311 | default: |
| 10312 | WARN_ON(1); /* we need a WARN() */ |
| 10313 | break; |
| 10314 | } |
| 10315 | } |
| 10316 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10317 | static int tg3_phys_id(struct net_device *dev, u32 data) |
| 10318 | { |
| 10319 | struct tg3 *tp = netdev_priv(dev); |
| 10320 | int i; |
| 10321 | |
| 10322 | if (!netif_running(tp->dev)) |
| 10323 | return -EAGAIN; |
| 10324 | |
| 10325 | if (data == 0) |
Stephen Hemminger | 759afc3 | 2008-02-23 19:51:59 -0800 | [diff] [blame] | 10326 | data = UINT_MAX / 2; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10327 | |
| 10328 | for (i = 0; i < (data * 2); i++) { |
| 10329 | if ((i % 2) == 0) |
| 10330 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 10331 | LED_CTRL_1000MBPS_ON | |
| 10332 | LED_CTRL_100MBPS_ON | |
| 10333 | LED_CTRL_10MBPS_ON | |
| 10334 | LED_CTRL_TRAFFIC_OVERRIDE | |
| 10335 | LED_CTRL_TRAFFIC_BLINK | |
| 10336 | LED_CTRL_TRAFFIC_LED); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10337 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10338 | else |
| 10339 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 10340 | LED_CTRL_TRAFFIC_OVERRIDE); |
| 10341 | |
| 10342 | if (msleep_interruptible(500)) |
| 10343 | break; |
| 10344 | } |
| 10345 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 10346 | return 0; |
| 10347 | } |
| 10348 | |
Matt Carlson | de6f31e | 2010-04-12 06:58:30 +0000 | [diff] [blame] | 10349 | static void tg3_get_ethtool_stats(struct net_device *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10350 | struct ethtool_stats *estats, u64 *tmp_stats) |
| 10351 | { |
| 10352 | struct tg3 *tp = netdev_priv(dev); |
| 10353 | memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats)); |
| 10354 | } |
| 10355 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10356 | #define NVRAM_TEST_SIZE 0x100 |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10357 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
| 10358 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 |
| 10359 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10360 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
| 10361 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10362 | |
| 10363 | static int tg3_test_nvram(struct tg3 *tp) |
| 10364 | { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10365 | u32 csum, magic; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10366 | __be32 *buf; |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 10367 | int i, j, k, err = 0, size; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10368 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 10369 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) |
| 10370 | return 0; |
| 10371 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 10372 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10373 | return -EIO; |
| 10374 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10375 | if (magic == TG3_EEPROM_MAGIC) |
| 10376 | size = NVRAM_TEST_SIZE; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10377 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10378 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
| 10379 | TG3_EEPROM_SB_FORMAT_1) { |
| 10380 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { |
| 10381 | case TG3_EEPROM_SB_REVISION_0: |
| 10382 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; |
| 10383 | break; |
| 10384 | case TG3_EEPROM_SB_REVISION_2: |
| 10385 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; |
| 10386 | break; |
| 10387 | case TG3_EEPROM_SB_REVISION_3: |
| 10388 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; |
| 10389 | break; |
| 10390 | default: |
| 10391 | return 0; |
| 10392 | } |
| 10393 | } else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10394 | return 0; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10395 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 10396 | size = NVRAM_SELFBOOT_HW_SIZE; |
| 10397 | else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10398 | return -EIO; |
| 10399 | |
| 10400 | buf = kmalloc(size, GFP_KERNEL); |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10401 | if (buf == NULL) |
| 10402 | return -ENOMEM; |
| 10403 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10404 | err = -EIO; |
| 10405 | for (i = 0, j = 0; i < size; i += 4, j++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10406 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
| 10407 | if (err) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10408 | break; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10409 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10410 | if (i < size) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10411 | goto out; |
| 10412 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10413 | /* Selfboot format */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10414 | magic = be32_to_cpu(buf[0]); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10415 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10416 | TG3_EEPROM_MAGIC_FW) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10417 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
| 10418 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10419 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10420 | TG3_EEPROM_SB_REVISION_2) { |
| 10421 | /* For rev 2, the csum doesn't include the MBA. */ |
| 10422 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) |
| 10423 | csum8 += buf8[i]; |
| 10424 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) |
| 10425 | csum8 += buf8[i]; |
| 10426 | } else { |
| 10427 | for (i = 0; i < size; i++) |
| 10428 | csum8 += buf8[i]; |
| 10429 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10430 | |
Adrian Bunk | ad96b48 | 2006-04-05 22:21:04 -0700 | [diff] [blame] | 10431 | if (csum8 == 0) { |
| 10432 | err = 0; |
| 10433 | goto out; |
| 10434 | } |
| 10435 | |
| 10436 | err = -EIO; |
| 10437 | goto out; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10438 | } |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10439 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10440 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10441 | TG3_EEPROM_MAGIC_HW) { |
| 10442 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10443 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10444 | u8 *buf8 = (u8 *) buf; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10445 | |
| 10446 | /* Separate the parity bits and the data bytes. */ |
| 10447 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { |
| 10448 | if ((i == 0) || (i == 8)) { |
| 10449 | int l; |
| 10450 | u8 msk; |
| 10451 | |
| 10452 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) |
| 10453 | parity[k++] = buf8[i] & msk; |
| 10454 | i++; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 10455 | } else if (i == 16) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10456 | int l; |
| 10457 | u8 msk; |
| 10458 | |
| 10459 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) |
| 10460 | parity[k++] = buf8[i] & msk; |
| 10461 | i++; |
| 10462 | |
| 10463 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) |
| 10464 | parity[k++] = buf8[i] & msk; |
| 10465 | i++; |
| 10466 | } |
| 10467 | data[j++] = buf8[i]; |
| 10468 | } |
| 10469 | |
| 10470 | err = -EIO; |
| 10471 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { |
| 10472 | u8 hw8 = hweight8(data[i]); |
| 10473 | |
| 10474 | if ((hw8 & 0x1) && parity[i]) |
| 10475 | goto out; |
| 10476 | else if (!(hw8 & 0x1) && !parity[i]) |
| 10477 | goto out; |
| 10478 | } |
| 10479 | err = 0; |
| 10480 | goto out; |
| 10481 | } |
| 10482 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10483 | /* Bootstrap checksum at offset 0x10 */ |
| 10484 | csum = calc_crc((unsigned char *) buf, 0x10); |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10485 | if (csum != be32_to_cpu(buf[0x10/4])) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10486 | goto out; |
| 10487 | |
| 10488 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ |
| 10489 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10490 | if (csum != be32_to_cpu(buf[0xfc/4])) |
| 10491 | goto out; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10492 | |
| 10493 | err = 0; |
| 10494 | |
| 10495 | out: |
| 10496 | kfree(buf); |
| 10497 | return err; |
| 10498 | } |
| 10499 | |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 10500 | #define TG3_SERDES_TIMEOUT_SEC 2 |
| 10501 | #define TG3_COPPER_TIMEOUT_SEC 6 |
| 10502 | |
| 10503 | static int tg3_test_link(struct tg3 *tp) |
| 10504 | { |
| 10505 | int i, max; |
| 10506 | |
| 10507 | if (!netif_running(tp->dev)) |
| 10508 | return -ENODEV; |
| 10509 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10510 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 10511 | max = TG3_SERDES_TIMEOUT_SEC; |
| 10512 | else |
| 10513 | max = TG3_COPPER_TIMEOUT_SEC; |
| 10514 | |
| 10515 | for (i = 0; i < max; i++) { |
| 10516 | if (netif_carrier_ok(tp->dev)) |
| 10517 | return 0; |
| 10518 | |
| 10519 | if (msleep_interruptible(1000)) |
| 10520 | break; |
| 10521 | } |
| 10522 | |
| 10523 | return -EIO; |
| 10524 | } |
| 10525 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10526 | /* Only test the commonly used registers */ |
David S. Miller | 30ca3e3 | 2006-03-20 23:02:36 -0800 | [diff] [blame] | 10527 | static int tg3_test_registers(struct tg3 *tp) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10528 | { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10529 | int i, is_5705, is_5750; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10530 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
| 10531 | static struct { |
| 10532 | u16 offset; |
| 10533 | u16 flags; |
| 10534 | #define TG3_FL_5705 0x1 |
| 10535 | #define TG3_FL_NOT_5705 0x2 |
| 10536 | #define TG3_FL_NOT_5788 0x4 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10537 | #define TG3_FL_NOT_5750 0x8 |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10538 | u32 read_mask; |
| 10539 | u32 write_mask; |
| 10540 | } reg_tbl[] = { |
| 10541 | /* MAC Control Registers */ |
| 10542 | { MAC_MODE, TG3_FL_NOT_5705, |
| 10543 | 0x00000000, 0x00ef6f8c }, |
| 10544 | { MAC_MODE, TG3_FL_5705, |
| 10545 | 0x00000000, 0x01ef6b8c }, |
| 10546 | { MAC_STATUS, TG3_FL_NOT_5705, |
| 10547 | 0x03800107, 0x00000000 }, |
| 10548 | { MAC_STATUS, TG3_FL_5705, |
| 10549 | 0x03800100, 0x00000000 }, |
| 10550 | { MAC_ADDR_0_HIGH, 0x0000, |
| 10551 | 0x00000000, 0x0000ffff }, |
| 10552 | { MAC_ADDR_0_LOW, 0x0000, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 10553 | 0x00000000, 0xffffffff }, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10554 | { MAC_RX_MTU_SIZE, 0x0000, |
| 10555 | 0x00000000, 0x0000ffff }, |
| 10556 | { MAC_TX_MODE, 0x0000, |
| 10557 | 0x00000000, 0x00000070 }, |
| 10558 | { MAC_TX_LENGTHS, 0x0000, |
| 10559 | 0x00000000, 0x00003fff }, |
| 10560 | { MAC_RX_MODE, TG3_FL_NOT_5705, |
| 10561 | 0x00000000, 0x000007fc }, |
| 10562 | { MAC_RX_MODE, TG3_FL_5705, |
| 10563 | 0x00000000, 0x000007dc }, |
| 10564 | { MAC_HASH_REG_0, 0x0000, |
| 10565 | 0x00000000, 0xffffffff }, |
| 10566 | { MAC_HASH_REG_1, 0x0000, |
| 10567 | 0x00000000, 0xffffffff }, |
| 10568 | { MAC_HASH_REG_2, 0x0000, |
| 10569 | 0x00000000, 0xffffffff }, |
| 10570 | { MAC_HASH_REG_3, 0x0000, |
| 10571 | 0x00000000, 0xffffffff }, |
| 10572 | |
| 10573 | /* Receive Data and Receive BD Initiator Control Registers. */ |
| 10574 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, |
| 10575 | 0x00000000, 0xffffffff }, |
| 10576 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, |
| 10577 | 0x00000000, 0xffffffff }, |
| 10578 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, |
| 10579 | 0x00000000, 0x00000003 }, |
| 10580 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, |
| 10581 | 0x00000000, 0xffffffff }, |
| 10582 | { RCVDBDI_STD_BD+0, 0x0000, |
| 10583 | 0x00000000, 0xffffffff }, |
| 10584 | { RCVDBDI_STD_BD+4, 0x0000, |
| 10585 | 0x00000000, 0xffffffff }, |
| 10586 | { RCVDBDI_STD_BD+8, 0x0000, |
| 10587 | 0x00000000, 0xffff0002 }, |
| 10588 | { RCVDBDI_STD_BD+0xc, 0x0000, |
| 10589 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10590 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10591 | /* Receive BD Initiator Control Registers. */ |
| 10592 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, |
| 10593 | 0x00000000, 0xffffffff }, |
| 10594 | { RCVBDI_STD_THRESH, TG3_FL_5705, |
| 10595 | 0x00000000, 0x000003ff }, |
| 10596 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, |
| 10597 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10598 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10599 | /* Host Coalescing Control Registers. */ |
| 10600 | { HOSTCC_MODE, TG3_FL_NOT_5705, |
| 10601 | 0x00000000, 0x00000004 }, |
| 10602 | { HOSTCC_MODE, TG3_FL_5705, |
| 10603 | 0x00000000, 0x000000f6 }, |
| 10604 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, |
| 10605 | 0x00000000, 0xffffffff }, |
| 10606 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, |
| 10607 | 0x00000000, 0x000003ff }, |
| 10608 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, |
| 10609 | 0x00000000, 0xffffffff }, |
| 10610 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, |
| 10611 | 0x00000000, 0x000003ff }, |
| 10612 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, |
| 10613 | 0x00000000, 0xffffffff }, |
| 10614 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10615 | 0x00000000, 0x000000ff }, |
| 10616 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, |
| 10617 | 0x00000000, 0xffffffff }, |
| 10618 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10619 | 0x00000000, 0x000000ff }, |
| 10620 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 10621 | 0x00000000, 0xffffffff }, |
| 10622 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 10623 | 0x00000000, 0xffffffff }, |
| 10624 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 10625 | 0x00000000, 0xffffffff }, |
| 10626 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10627 | 0x00000000, 0x000000ff }, |
| 10628 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 10629 | 0x00000000, 0xffffffff }, |
| 10630 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10631 | 0x00000000, 0x000000ff }, |
| 10632 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, |
| 10633 | 0x00000000, 0xffffffff }, |
| 10634 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, |
| 10635 | 0x00000000, 0xffffffff }, |
| 10636 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, |
| 10637 | 0x00000000, 0xffffffff }, |
| 10638 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, |
| 10639 | 0x00000000, 0xffffffff }, |
| 10640 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, |
| 10641 | 0x00000000, 0xffffffff }, |
| 10642 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, |
| 10643 | 0xffffffff, 0x00000000 }, |
| 10644 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, |
| 10645 | 0xffffffff, 0x00000000 }, |
| 10646 | |
| 10647 | /* Buffer Manager Control Registers. */ |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10648 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10649 | 0x00000000, 0x007fff80 }, |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10650 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10651 | 0x00000000, 0x007fffff }, |
| 10652 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, |
| 10653 | 0x00000000, 0x0000003f }, |
| 10654 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, |
| 10655 | 0x00000000, 0x000001ff }, |
| 10656 | { BUFMGR_MB_HIGH_WATER, 0x0000, |
| 10657 | 0x00000000, 0x000001ff }, |
| 10658 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, |
| 10659 | 0xffffffff, 0x00000000 }, |
| 10660 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, |
| 10661 | 0xffffffff, 0x00000000 }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10662 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10663 | /* Mailbox Registers */ |
| 10664 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, |
| 10665 | 0x00000000, 0x000001ff }, |
| 10666 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, |
| 10667 | 0x00000000, 0x000001ff }, |
| 10668 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, |
| 10669 | 0x00000000, 0x000007ff }, |
| 10670 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, |
| 10671 | 0x00000000, 0x000001ff }, |
| 10672 | |
| 10673 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, |
| 10674 | }; |
| 10675 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10676 | is_5705 = is_5750 = 0; |
| 10677 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10678 | is_5705 = 1; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10679 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
| 10680 | is_5750 = 1; |
| 10681 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10682 | |
| 10683 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { |
| 10684 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) |
| 10685 | continue; |
| 10686 | |
| 10687 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) |
| 10688 | continue; |
| 10689 | |
| 10690 | if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) && |
| 10691 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
| 10692 | continue; |
| 10693 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10694 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
| 10695 | continue; |
| 10696 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10697 | offset = (u32) reg_tbl[i].offset; |
| 10698 | read_mask = reg_tbl[i].read_mask; |
| 10699 | write_mask = reg_tbl[i].write_mask; |
| 10700 | |
| 10701 | /* Save the original register content */ |
| 10702 | save_val = tr32(offset); |
| 10703 | |
| 10704 | /* Determine the read-only value. */ |
| 10705 | read_val = save_val & read_mask; |
| 10706 | |
| 10707 | /* Write zero to the register, then make sure the read-only bits |
| 10708 | * are not changed and the read/write bits are all zeros. |
| 10709 | */ |
| 10710 | tw32(offset, 0); |
| 10711 | |
| 10712 | val = tr32(offset); |
| 10713 | |
| 10714 | /* Test the read-only and read/write bits. */ |
| 10715 | if (((val & read_mask) != read_val) || (val & write_mask)) |
| 10716 | goto out; |
| 10717 | |
| 10718 | /* Write ones to all the bits defined by RdMask and WrMask, then |
| 10719 | * make sure the read-only bits are not changed and the |
| 10720 | * read/write bits are all ones. |
| 10721 | */ |
| 10722 | tw32(offset, read_mask | write_mask); |
| 10723 | |
| 10724 | val = tr32(offset); |
| 10725 | |
| 10726 | /* Test the read-only bits. */ |
| 10727 | if ((val & read_mask) != read_val) |
| 10728 | goto out; |
| 10729 | |
| 10730 | /* Test the read/write bits. */ |
| 10731 | if ((val & write_mask) != write_mask) |
| 10732 | goto out; |
| 10733 | |
| 10734 | tw32(offset, save_val); |
| 10735 | } |
| 10736 | |
| 10737 | return 0; |
| 10738 | |
| 10739 | out: |
Michael Chan | 9f88f29 | 2006-12-07 00:22:54 -0800 | [diff] [blame] | 10740 | if (netif_msg_hw(tp)) |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 10741 | netdev_err(tp->dev, |
| 10742 | "Register test failed at offset %x\n", offset); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10743 | tw32(offset, save_val); |
| 10744 | return -EIO; |
| 10745 | } |
| 10746 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10747 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
| 10748 | { |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 10749 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10750 | int i; |
| 10751 | u32 j; |
| 10752 | |
Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 10753 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10754 | for (j = 0; j < len; j += 4) { |
| 10755 | u32 val; |
| 10756 | |
| 10757 | tg3_write_mem(tp, offset + j, test_pattern[i]); |
| 10758 | tg3_read_mem(tp, offset + j, &val); |
| 10759 | if (val != test_pattern[i]) |
| 10760 | return -EIO; |
| 10761 | } |
| 10762 | } |
| 10763 | return 0; |
| 10764 | } |
| 10765 | |
| 10766 | static int tg3_test_memory(struct tg3 *tp) |
| 10767 | { |
| 10768 | static struct mem_entry { |
| 10769 | u32 offset; |
| 10770 | u32 len; |
| 10771 | } mem_tbl_570x[] = { |
Michael Chan | 3869019 | 2005-12-19 16:27:28 -0800 | [diff] [blame] | 10772 | { 0x00000000, 0x00b50}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10773 | { 0x00002000, 0x1c000}, |
| 10774 | { 0xffffffff, 0x00000} |
| 10775 | }, mem_tbl_5705[] = { |
| 10776 | { 0x00000100, 0x0000c}, |
| 10777 | { 0x00000200, 0x00008}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10778 | { 0x00004000, 0x00800}, |
| 10779 | { 0x00006000, 0x01000}, |
| 10780 | { 0x00008000, 0x02000}, |
| 10781 | { 0x00010000, 0x0e000}, |
| 10782 | { 0xffffffff, 0x00000} |
Michael Chan | 79f4d13 | 2006-03-20 22:28:57 -0800 | [diff] [blame] | 10783 | }, mem_tbl_5755[] = { |
| 10784 | { 0x00000200, 0x00008}, |
| 10785 | { 0x00004000, 0x00800}, |
| 10786 | { 0x00006000, 0x00800}, |
| 10787 | { 0x00008000, 0x02000}, |
| 10788 | { 0x00010000, 0x0c000}, |
| 10789 | { 0xffffffff, 0x00000} |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10790 | }, mem_tbl_5906[] = { |
| 10791 | { 0x00000200, 0x00008}, |
| 10792 | { 0x00004000, 0x00400}, |
| 10793 | { 0x00006000, 0x00400}, |
| 10794 | { 0x00008000, 0x01000}, |
| 10795 | { 0x00010000, 0x01000}, |
| 10796 | { 0xffffffff, 0x00000} |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 10797 | }, mem_tbl_5717[] = { |
| 10798 | { 0x00000200, 0x00008}, |
| 10799 | { 0x00010000, 0x0a000}, |
| 10800 | { 0x00020000, 0x13c00}, |
| 10801 | { 0xffffffff, 0x00000} |
| 10802 | }, mem_tbl_57765[] = { |
| 10803 | { 0x00000200, 0x00008}, |
| 10804 | { 0x00004000, 0x00800}, |
| 10805 | { 0x00006000, 0x09800}, |
| 10806 | { 0x00010000, 0x0a000}, |
| 10807 | { 0xffffffff, 0x00000} |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10808 | }; |
| 10809 | struct mem_entry *mem_tbl; |
| 10810 | int err = 0; |
| 10811 | int i; |
| 10812 | |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 10813 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 10814 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 10815 | mem_tbl = mem_tbl_5717; |
| 10816 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 10817 | mem_tbl = mem_tbl_57765; |
| 10818 | else if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10819 | mem_tbl = mem_tbl_5755; |
| 10820 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 10821 | mem_tbl = mem_tbl_5906; |
| 10822 | else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
| 10823 | mem_tbl = mem_tbl_5705; |
| 10824 | else |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10825 | mem_tbl = mem_tbl_570x; |
| 10826 | |
| 10827 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { |
Matt Carlson | be98da6 | 2010-07-11 09:31:46 +0000 | [diff] [blame] | 10828 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
| 10829 | if (err) |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10830 | break; |
| 10831 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10832 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10833 | return err; |
| 10834 | } |
| 10835 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10836 | #define TG3_MAC_LOOPBACK 0 |
| 10837 | #define TG3_PHY_LOOPBACK 1 |
| 10838 | |
| 10839 | static int tg3_run_loopback(struct tg3 *tp, int loopback_mode) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10840 | { |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10841 | u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key; |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10842 | u32 desc_idx, coal_now; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10843 | struct sk_buff *skb, *rx_skb; |
| 10844 | u8 *tx_data; |
| 10845 | dma_addr_t map; |
| 10846 | int num_pkts, tx_len, rx_len, i, err; |
| 10847 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10848 | struct tg3_napi *tnapi, *rnapi; |
Matt Carlson | 8fea32b | 2010-09-15 08:59:58 +0000 | [diff] [blame] | 10849 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10850 | |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 10851 | tnapi = &tp->napi[0]; |
| 10852 | rnapi = &tp->napi[0]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 10853 | if (tp->irq_cnt > 1) { |
Matt Carlson | 1da85aa | 2010-09-30 10:34:34 +0000 | [diff] [blame] | 10854 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) |
| 10855 | rnapi = &tp->napi[1]; |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 10856 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
| 10857 | tnapi = &tp->napi[1]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 10858 | } |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10859 | coal_now = tnapi->coal_now | rnapi->coal_now; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10860 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10861 | if (loopback_mode == TG3_MAC_LOOPBACK) { |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10862 | /* HW errata - mac loopback fails in some cases on 5780. |
| 10863 | * Normal traffic and PHY loopback are not affected by |
| 10864 | * errata. |
| 10865 | */ |
| 10866 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) |
| 10867 | return 0; |
| 10868 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10869 | mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10870 | MAC_MODE_PORT_INT_LPBACK; |
| 10871 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 10872 | mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10873 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10874 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 10875 | else |
| 10876 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10877 | tw32(MAC_MODE, mac_mode); |
| 10878 | } else if (loopback_mode == TG3_PHY_LOOPBACK) { |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10879 | u32 val; |
| 10880 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10881 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 10882 | tg3_phy_fet_toggle_apd(tp, false); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 10883 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100; |
| 10884 | } else |
| 10885 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000; |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10886 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 10887 | tg3_phy_toggle_automdix(tp, 0); |
| 10888 | |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10889 | tg3_writephy(tp, MII_BMCR, val); |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10890 | udelay(40); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 10891 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10892 | mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10893 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
Matt Carlson | 1061b7c | 2010-02-12 14:47:12 +0000 | [diff] [blame] | 10894 | tg3_writephy(tp, MII_TG3_FET_PTEST, |
| 10895 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
| 10896 | MII_TG3_FET_PTEST_FRC_TX_LOCK); |
| 10897 | /* The write needs to be flushed for the AC131 */ |
| 10898 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 10899 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 10900 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 10901 | } else |
| 10902 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10903 | |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10904 | /* reset to prevent losing 1st rx packet intermittently */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 10905 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10906 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 10907 | udelay(10); |
| 10908 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 10909 | } |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10910 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 10911 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
| 10912 | if (masked_phy_id == TG3_PHY_ID_BCM5401) |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10913 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 10914 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10915 | mac_mode |= MAC_MODE_LINK_POLARITY; |
Michael Chan | ff18ff0 | 2006-03-27 23:17:27 -0800 | [diff] [blame] | 10916 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 10917 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 10918 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10919 | tw32(MAC_MODE, mac_mode); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 10920 | } else { |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10921 | return -EINVAL; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 10922 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10923 | |
| 10924 | err = -EIO; |
| 10925 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10926 | tx_len = 1514; |
David S. Miller | a20e9c6 | 2006-07-31 22:38:16 -0700 | [diff] [blame] | 10927 | skb = netdev_alloc_skb(tp->dev, tx_len); |
Jesper Juhl | a50bb7b | 2006-05-09 23:14:35 -0700 | [diff] [blame] | 10928 | if (!skb) |
| 10929 | return -ENOMEM; |
| 10930 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10931 | tx_data = skb_put(skb, tx_len); |
| 10932 | memcpy(tx_data, tp->dev->dev_addr, 6); |
| 10933 | memset(tx_data + 6, 0x0, 8); |
| 10934 | |
| 10935 | tw32(MAC_RX_MTU_SIZE, tx_len + 4); |
| 10936 | |
| 10937 | for (i = 14; i < tx_len; i++) |
| 10938 | tx_data[i] = (u8) (i & 0xff); |
| 10939 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 10940 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
| 10941 | if (pci_dma_mapping_error(tp->pdev, map)) { |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 10942 | dev_kfree_skb(skb); |
| 10943 | return -EIO; |
| 10944 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10945 | |
| 10946 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10947 | rnapi->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 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10952 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10953 | num_pkts = 0; |
| 10954 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 10955 | tg3_set_txd(tnapi, tnapi->tx_prod, map, tx_len, 0, 1); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10956 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10957 | tnapi->tx_prod++; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10958 | num_pkts++; |
| 10959 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10960 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 10961 | tr32_mailbox(tnapi->prodmbox); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10962 | |
| 10963 | udelay(10); |
| 10964 | |
Matt Carlson | 303fc92 | 2009-11-02 14:27:34 +0000 | [diff] [blame] | 10965 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
| 10966 | for (i = 0; i < 35; i++) { |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10967 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10968 | coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10969 | |
| 10970 | udelay(10); |
| 10971 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10972 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 10973 | rx_idx = rnapi->hw_status->idx[0].rx_producer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10974 | if ((tx_idx == tnapi->tx_prod) && |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10975 | (rx_idx == (rx_start_idx + num_pkts))) |
| 10976 | break; |
| 10977 | } |
| 10978 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 10979 | pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10980 | dev_kfree_skb(skb); |
| 10981 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10982 | if (tx_idx != tnapi->tx_prod) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10983 | goto out; |
| 10984 | |
| 10985 | if (rx_idx != rx_start_idx + num_pkts) |
| 10986 | goto out; |
| 10987 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 10988 | desc = &rnapi->rx_rcb[rx_start_idx]; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10989 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 10990 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 10991 | if (opaque_key != RXD_OPAQUE_RING_STD) |
| 10992 | goto out; |
| 10993 | |
| 10994 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 10995 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) |
| 10996 | goto out; |
| 10997 | |
| 10998 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; |
| 10999 | if (rx_len != tx_len) |
| 11000 | goto out; |
| 11001 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 11002 | rx_skb = tpr->rx_std_buffers[desc_idx].skb; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11003 | |
FUJITA Tomonori | 4e5e4f0 | 2010-04-12 14:32:09 +0000 | [diff] [blame] | 11004 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], mapping); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11005 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE); |
| 11006 | |
| 11007 | for (i = 14; i < tx_len; i++) { |
| 11008 | if (*(rx_skb->data + i) != (u8) (i & 0xff)) |
| 11009 | goto out; |
| 11010 | } |
| 11011 | err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11012 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11013 | /* tg3_free_rings will unmap and free the rx_skb */ |
| 11014 | out: |
| 11015 | return err; |
| 11016 | } |
| 11017 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11018 | #define TG3_MAC_LOOPBACK_FAILED 1 |
| 11019 | #define TG3_PHY_LOOPBACK_FAILED 2 |
| 11020 | #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \ |
| 11021 | TG3_PHY_LOOPBACK_FAILED) |
| 11022 | |
| 11023 | static int tg3_test_loopback(struct tg3 *tp) |
| 11024 | { |
| 11025 | int err = 0; |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11026 | u32 cpmuctrl = 0; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11027 | |
| 11028 | if (!netif_running(tp->dev)) |
| 11029 | return TG3_LOOPBACK_FAILED; |
| 11030 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11031 | err = tg3_reset_hw(tp, 1); |
| 11032 | if (err) |
| 11033 | return TG3_LOOPBACK_FAILED; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11034 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11035 | /* Turn off gphy autopowerdown. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11036 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11037 | tg3_phy_toggle_apd(tp, false); |
| 11038 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11039 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11040 | int i; |
| 11041 | u32 status; |
| 11042 | |
| 11043 | tw32(TG3_CPMU_MUTEX_REQ, CPMU_MUTEX_REQ_DRIVER); |
| 11044 | |
| 11045 | /* Wait for up to 40 microseconds to acquire lock. */ |
| 11046 | for (i = 0; i < 4; i++) { |
| 11047 | status = tr32(TG3_CPMU_MUTEX_GNT); |
| 11048 | if (status == CPMU_MUTEX_GNT_DRIVER) |
| 11049 | break; |
| 11050 | udelay(10); |
| 11051 | } |
| 11052 | |
| 11053 | if (status != CPMU_MUTEX_GNT_DRIVER) |
| 11054 | return TG3_LOOPBACK_FAILED; |
| 11055 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 11056 | /* Turn off link-based power management. */ |
Matt Carlson | e875093 | 2007-11-12 21:11:51 -0800 | [diff] [blame] | 11057 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
Matt Carlson | 109115e | 2008-05-02 16:48:59 -0700 | [diff] [blame] | 11058 | tw32(TG3_CPMU_CTRL, |
| 11059 | cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE | |
| 11060 | CPMU_CTRL_LINK_AWARE_MODE)); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11061 | } |
| 11062 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11063 | if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK)) |
| 11064 | err |= TG3_MAC_LOOPBACK_FAILED; |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11065 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11066 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 11067 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 11068 | |
| 11069 | /* Release the mutex */ |
| 11070 | tw32(TG3_CPMU_MUTEX_GNT, CPMU_MUTEX_GNT_DRIVER); |
| 11071 | } |
| 11072 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11073 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 11074 | !(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)) { |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11075 | if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK)) |
| 11076 | err |= TG3_PHY_LOOPBACK_FAILED; |
| 11077 | } |
| 11078 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11079 | /* Re-enable gphy autopowerdown. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11080 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 11081 | tg3_phy_toggle_apd(tp, true); |
| 11082 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11083 | return err; |
| 11084 | } |
| 11085 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11086 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
| 11087 | u64 *data) |
| 11088 | { |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11089 | struct tg3 *tp = netdev_priv(dev); |
| 11090 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11091 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11092 | tg3_set_power_state(tp, PCI_D0); |
| 11093 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11094 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
| 11095 | |
| 11096 | if (tg3_test_nvram(tp) != 0) { |
| 11097 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11098 | data[0] = 1; |
| 11099 | } |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11100 | if (tg3_test_link(tp) != 0) { |
| 11101 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11102 | data[1] = 1; |
| 11103 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11104 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11105 | int err, err2 = 0, irq_sync = 0; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11106 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11107 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11108 | tg3_phy_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11109 | tg3_netif_stop(tp); |
| 11110 | irq_sync = 1; |
| 11111 | } |
| 11112 | |
| 11113 | tg3_full_lock(tp, irq_sync); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11114 | |
| 11115 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11116 | err = tg3_nvram_lock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11117 | tg3_halt_cpu(tp, RX_CPU_BASE); |
| 11118 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 11119 | tg3_halt_cpu(tp, TX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11120 | if (!err) |
| 11121 | tg3_nvram_unlock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11122 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11123 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 11124 | tg3_phy_reset(tp); |
| 11125 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11126 | if (tg3_test_registers(tp) != 0) { |
| 11127 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11128 | data[2] = 1; |
| 11129 | } |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11130 | if (tg3_test_memory(tp) != 0) { |
| 11131 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11132 | data[3] = 1; |
| 11133 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11134 | if ((data[4] = tg3_test_loopback(tp)) != 0) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11135 | etest->flags |= ETH_TEST_FL_FAILED; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11136 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11137 | tg3_full_unlock(tp); |
| 11138 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 11139 | if (tg3_test_interrupt(tp) != 0) { |
| 11140 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11141 | data[5] = 1; |
| 11142 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11143 | |
| 11144 | tg3_full_lock(tp, 0); |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 11145 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11146 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11147 | if (netif_running(dev)) { |
| 11148 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11149 | err2 = tg3_restart_hw(tp, 1); |
| 11150 | if (!err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11151 | tg3_netif_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11152 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11153 | |
| 11154 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11155 | |
| 11156 | if (irq_sync && !err2) |
| 11157 | tg3_phy_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11158 | } |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11159 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11160 | tg3_set_power_state(tp, PCI_D3hot); |
| 11161 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11162 | } |
| 11163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11164 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 11165 | { |
| 11166 | struct mii_ioctl_data *data = if_mii(ifr); |
| 11167 | struct tg3 *tp = netdev_priv(dev); |
| 11168 | int err; |
| 11169 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11170 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11171 | struct phy_device *phydev; |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11172 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11173 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11174 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 11175 | return phy_mii_ioctl(phydev, ifr, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11176 | } |
| 11177 | |
Matt Carlson | 33f401a | 2010-04-05 10:19:27 +0000 | [diff] [blame] | 11178 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11179 | case SIOCGMIIPHY: |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 11180 | data->phy_id = tp->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11181 | |
| 11182 | /* fallthru */ |
| 11183 | case SIOCGMIIREG: { |
| 11184 | u32 mii_regval; |
| 11185 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11186 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11187 | break; /* We have no PHY */ |
| 11188 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11189 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11190 | return -EAGAIN; |
| 11191 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11192 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11193 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11194 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11195 | |
| 11196 | data->val_out = mii_regval; |
| 11197 | |
| 11198 | return err; |
| 11199 | } |
| 11200 | |
| 11201 | case SIOCSMIIREG: |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 11202 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11203 | break; /* We have no PHY */ |
| 11204 | |
Matt Carlson | 80096068 | 2010-08-02 11:26:06 +0000 | [diff] [blame] | 11205 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11206 | return -EAGAIN; |
| 11207 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11208 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11209 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11210 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11211 | |
| 11212 | return err; |
| 11213 | |
| 11214 | default: |
| 11215 | /* do nothing */ |
| 11216 | break; |
| 11217 | } |
| 11218 | return -EOPNOTSUPP; |
| 11219 | } |
| 11220 | |
| 11221 | #if TG3_VLAN_TAG_USED |
| 11222 | static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) |
| 11223 | { |
| 11224 | struct tg3 *tp = netdev_priv(dev); |
| 11225 | |
Matt Carlson | 844b3ee | 2009-02-25 14:23:56 +0000 | [diff] [blame] | 11226 | if (!netif_running(dev)) { |
| 11227 | tp->vlgrp = grp; |
| 11228 | return; |
| 11229 | } |
| 11230 | |
| 11231 | tg3_netif_stop(tp); |
Michael Chan | 29315e8 | 2006-06-29 20:12:30 -0700 | [diff] [blame] | 11232 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11233 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11234 | |
| 11235 | tp->vlgrp = grp; |
| 11236 | |
| 11237 | /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */ |
| 11238 | __tg3_set_rx_mode(dev); |
| 11239 | |
Matt Carlson | 844b3ee | 2009-02-25 14:23:56 +0000 | [diff] [blame] | 11240 | tg3_netif_start(tp); |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 11241 | |
| 11242 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11244 | #endif |
| 11245 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 11246 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 11247 | { |
| 11248 | struct tg3 *tp = netdev_priv(dev); |
| 11249 | |
| 11250 | memcpy(ec, &tp->coal, sizeof(*ec)); |
| 11251 | return 0; |
| 11252 | } |
| 11253 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 11254 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 11255 | { |
| 11256 | struct tg3 *tp = netdev_priv(dev); |
| 11257 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; |
| 11258 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; |
| 11259 | |
| 11260 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 11261 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
| 11262 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; |
| 11263 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; |
| 11264 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; |
| 11265 | } |
| 11266 | |
| 11267 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || |
| 11268 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || |
| 11269 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || |
| 11270 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || |
| 11271 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || |
| 11272 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || |
| 11273 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || |
| 11274 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || |
| 11275 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || |
| 11276 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) |
| 11277 | return -EINVAL; |
| 11278 | |
| 11279 | /* No rx interrupts will be generated if both are zero */ |
| 11280 | if ((ec->rx_coalesce_usecs == 0) && |
| 11281 | (ec->rx_max_coalesced_frames == 0)) |
| 11282 | return -EINVAL; |
| 11283 | |
| 11284 | /* No tx interrupts will be generated if both are zero */ |
| 11285 | if ((ec->tx_coalesce_usecs == 0) && |
| 11286 | (ec->tx_max_coalesced_frames == 0)) |
| 11287 | return -EINVAL; |
| 11288 | |
| 11289 | /* Only copy relevant parameters, ignore all others. */ |
| 11290 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; |
| 11291 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; |
| 11292 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; |
| 11293 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; |
| 11294 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; |
| 11295 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; |
| 11296 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; |
| 11297 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; |
| 11298 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; |
| 11299 | |
| 11300 | if (netif_running(dev)) { |
| 11301 | tg3_full_lock(tp, 0); |
| 11302 | __tg3_set_coalesce(tp, &tp->coal); |
| 11303 | tg3_full_unlock(tp); |
| 11304 | } |
| 11305 | return 0; |
| 11306 | } |
| 11307 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 11308 | static const struct ethtool_ops tg3_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11309 | .get_settings = tg3_get_settings, |
| 11310 | .set_settings = tg3_set_settings, |
| 11311 | .get_drvinfo = tg3_get_drvinfo, |
| 11312 | .get_regs_len = tg3_get_regs_len, |
| 11313 | .get_regs = tg3_get_regs, |
| 11314 | .get_wol = tg3_get_wol, |
| 11315 | .set_wol = tg3_set_wol, |
| 11316 | .get_msglevel = tg3_get_msglevel, |
| 11317 | .set_msglevel = tg3_set_msglevel, |
| 11318 | .nway_reset = tg3_nway_reset, |
| 11319 | .get_link = ethtool_op_get_link, |
| 11320 | .get_eeprom_len = tg3_get_eeprom_len, |
| 11321 | .get_eeprom = tg3_get_eeprom, |
| 11322 | .set_eeprom = tg3_set_eeprom, |
| 11323 | .get_ringparam = tg3_get_ringparam, |
| 11324 | .set_ringparam = tg3_set_ringparam, |
| 11325 | .get_pauseparam = tg3_get_pauseparam, |
| 11326 | .set_pauseparam = tg3_set_pauseparam, |
| 11327 | .get_rx_csum = tg3_get_rx_csum, |
| 11328 | .set_rx_csum = tg3_set_rx_csum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11329 | .set_tx_csum = tg3_set_tx_csum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11330 | .set_sg = ethtool_op_set_sg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11331 | .set_tso = tg3_set_tso, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11332 | .self_test = tg3_self_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11333 | .get_strings = tg3_get_strings, |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11334 | .phys_id = tg3_phys_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11335 | .get_ethtool_stats = tg3_get_ethtool_stats, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 11336 | .get_coalesce = tg3_get_coalesce, |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 11337 | .set_coalesce = tg3_set_coalesce, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 11338 | .get_sset_count = tg3_get_sset_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11339 | }; |
| 11340 | |
| 11341 | static void __devinit tg3_get_eeprom_size(struct tg3 *tp) |
| 11342 | { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11343 | u32 cursize, val, magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11344 | |
| 11345 | tp->nvram_size = EEPROM_CHIP_SIZE; |
| 11346 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11347 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11348 | return; |
| 11349 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11350 | if ((magic != TG3_EEPROM_MAGIC) && |
| 11351 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && |
| 11352 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11353 | return; |
| 11354 | |
| 11355 | /* |
| 11356 | * Size the chip by reading offsets at increasing powers of two. |
| 11357 | * When we encounter our validation signature, we know the addressing |
| 11358 | * has wrapped around, and thus have our chip size. |
| 11359 | */ |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11360 | cursize = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11361 | |
| 11362 | while (cursize < tp->nvram_size) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11363 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11364 | return; |
| 11365 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 11366 | if (val == magic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11367 | break; |
| 11368 | |
| 11369 | cursize <<= 1; |
| 11370 | } |
| 11371 | |
| 11372 | tp->nvram_size = cursize; |
| 11373 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11375 | static void __devinit tg3_get_nvram_size(struct tg3 *tp) |
| 11376 | { |
| 11377 | u32 val; |
| 11378 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11379 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
| 11380 | tg3_nvram_read(tp, 0, &val) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11381 | return; |
| 11382 | |
| 11383 | /* Selfboot format */ |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 11384 | if (val != TG3_EEPROM_MAGIC) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11385 | tg3_get_eeprom_size(tp); |
| 11386 | return; |
| 11387 | } |
| 11388 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 11389 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11390 | if (val != 0) { |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 11391 | /* This is confusing. We want to operate on the |
| 11392 | * 16-bit value at offset 0xf2. The tg3_nvram_read() |
| 11393 | * call will read from NVRAM and byteswap the data |
| 11394 | * according to the byteswapping settings for all |
| 11395 | * other register accesses. This ensures the data we |
| 11396 | * want will always reside in the lower 16-bits. |
| 11397 | * However, the data in NVRAM is in LE format, which |
| 11398 | * means the data from the NVRAM read will always be |
| 11399 | * opposite the endianness of the CPU. The 16-bit |
| 11400 | * byteswap then brings the data to CPU endianness. |
| 11401 | */ |
| 11402 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11403 | return; |
| 11404 | } |
| 11405 | } |
Matt Carlson | fd1122a | 2008-05-02 16:48:36 -0700 | [diff] [blame] | 11406 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11407 | } |
| 11408 | |
| 11409 | static void __devinit tg3_get_nvram_info(struct tg3 *tp) |
| 11410 | { |
| 11411 | u32 nvcfg1; |
| 11412 | |
| 11413 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11414 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { |
| 11415 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11416 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11417 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11418 | tw32(NVRAM_CFG1, nvcfg1); |
| 11419 | } |
| 11420 | |
Michael Chan | 4c98748 | 2005-09-05 17:52:38 -0700 | [diff] [blame] | 11421 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) || |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 11422 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11423 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11424 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
| 11425 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11426 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
| 11427 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11428 | break; |
| 11429 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: |
| 11430 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11431 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; |
| 11432 | break; |
| 11433 | case FLASH_VENDOR_ATMEL_EEPROM: |
| 11434 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11435 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11436 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11437 | break; |
| 11438 | case FLASH_VENDOR_ST: |
| 11439 | tp->nvram_jedecnum = JEDEC_ST; |
| 11440 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; |
| 11441 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11442 | break; |
| 11443 | case FLASH_VENDOR_SAIFUN: |
| 11444 | tp->nvram_jedecnum = JEDEC_SAIFUN; |
| 11445 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; |
| 11446 | break; |
| 11447 | case FLASH_VENDOR_SST_SMALL: |
| 11448 | case FLASH_VENDOR_SST_LARGE: |
| 11449 | tp->nvram_jedecnum = JEDEC_SST; |
| 11450 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; |
| 11451 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11452 | } |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11453 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11454 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11455 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
| 11456 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11457 | } |
| 11458 | } |
| 11459 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11460 | static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
| 11461 | { |
| 11462 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { |
| 11463 | case FLASH_5752PAGE_SIZE_256: |
| 11464 | tp->nvram_pagesize = 256; |
| 11465 | break; |
| 11466 | case FLASH_5752PAGE_SIZE_512: |
| 11467 | tp->nvram_pagesize = 512; |
| 11468 | break; |
| 11469 | case FLASH_5752PAGE_SIZE_1K: |
| 11470 | tp->nvram_pagesize = 1024; |
| 11471 | break; |
| 11472 | case FLASH_5752PAGE_SIZE_2K: |
| 11473 | tp->nvram_pagesize = 2048; |
| 11474 | break; |
| 11475 | case FLASH_5752PAGE_SIZE_4K: |
| 11476 | tp->nvram_pagesize = 4096; |
| 11477 | break; |
| 11478 | case FLASH_5752PAGE_SIZE_264: |
| 11479 | tp->nvram_pagesize = 264; |
| 11480 | break; |
| 11481 | case FLASH_5752PAGE_SIZE_528: |
| 11482 | tp->nvram_pagesize = 528; |
| 11483 | break; |
| 11484 | } |
| 11485 | } |
| 11486 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11487 | static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp) |
| 11488 | { |
| 11489 | u32 nvcfg1; |
| 11490 | |
| 11491 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11492 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11493 | /* NVRAM protection for TPM */ |
| 11494 | if (nvcfg1 & (1 << 27)) |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 11495 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11496 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11497 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11498 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
| 11499 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: |
| 11500 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11501 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11502 | break; |
| 11503 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11504 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11505 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11506 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11507 | break; |
| 11508 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11509 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11510 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11511 | tp->nvram_jedecnum = JEDEC_ST; |
| 11512 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11513 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11514 | break; |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11515 | } |
| 11516 | |
| 11517 | if (tp->tg3_flags2 & TG3_FLG2_FLASH) { |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11518 | tg3_nvram_get_pagesize(tp, nvcfg1); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11519 | } else { |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11520 | /* For eeprom, set pagesize to maximum eeprom size */ |
| 11521 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11522 | |
| 11523 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11524 | tw32(NVRAM_CFG1, nvcfg1); |
| 11525 | } |
| 11526 | } |
| 11527 | |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11528 | static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp) |
| 11529 | { |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11530 | u32 nvcfg1, protect = 0; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11531 | |
| 11532 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11533 | |
| 11534 | /* NVRAM protection for TPM */ |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11535 | if (nvcfg1 & (1 << 27)) { |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 11536 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11537 | protect = 1; |
| 11538 | } |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11539 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11540 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 11541 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11542 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 11543 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 11544 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 11545 | case FLASH_5755VENDOR_ATMEL_FLASH_5: |
| 11546 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11547 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11548 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11549 | tp->nvram_pagesize = 264; |
| 11550 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || |
| 11551 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) |
| 11552 | tp->nvram_size = (protect ? 0x3e200 : |
| 11553 | TG3_NVRAM_SIZE_512KB); |
| 11554 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) |
| 11555 | tp->nvram_size = (protect ? 0x1f200 : |
| 11556 | TG3_NVRAM_SIZE_256KB); |
| 11557 | else |
| 11558 | tp->nvram_size = (protect ? 0x1f200 : |
| 11559 | TG3_NVRAM_SIZE_128KB); |
| 11560 | break; |
| 11561 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11562 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11563 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11564 | tp->nvram_jedecnum = JEDEC_ST; |
| 11565 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11566 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11567 | tp->nvram_pagesize = 256; |
| 11568 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) |
| 11569 | tp->nvram_size = (protect ? |
| 11570 | TG3_NVRAM_SIZE_64KB : |
| 11571 | TG3_NVRAM_SIZE_128KB); |
| 11572 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) |
| 11573 | tp->nvram_size = (protect ? |
| 11574 | TG3_NVRAM_SIZE_64KB : |
| 11575 | TG3_NVRAM_SIZE_256KB); |
| 11576 | else |
| 11577 | tp->nvram_size = (protect ? |
| 11578 | TG3_NVRAM_SIZE_128KB : |
| 11579 | TG3_NVRAM_SIZE_512KB); |
| 11580 | break; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11581 | } |
| 11582 | } |
| 11583 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11584 | static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) |
| 11585 | { |
| 11586 | u32 nvcfg1; |
| 11587 | |
| 11588 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11589 | |
| 11590 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11591 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
| 11592 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 11593 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: |
| 11594 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 11595 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11596 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11597 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11598 | |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11599 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11600 | tw32(NVRAM_CFG1, nvcfg1); |
| 11601 | break; |
| 11602 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11603 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 11604 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 11605 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 11606 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11607 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11608 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11609 | tp->nvram_pagesize = 264; |
| 11610 | break; |
| 11611 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11612 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11613 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11614 | tp->nvram_jedecnum = JEDEC_ST; |
| 11615 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11616 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11617 | tp->nvram_pagesize = 256; |
| 11618 | break; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11619 | } |
| 11620 | } |
| 11621 | |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11622 | static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp) |
| 11623 | { |
| 11624 | u32 nvcfg1, protect = 0; |
| 11625 | |
| 11626 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11627 | |
| 11628 | /* NVRAM protection for TPM */ |
| 11629 | if (nvcfg1 & (1 << 27)) { |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 11630 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11631 | protect = 1; |
| 11632 | } |
| 11633 | |
| 11634 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 11635 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11636 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 11637 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 11638 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 11639 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 11640 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 11641 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 11642 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 11643 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 11644 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11645 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11646 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11647 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; |
| 11648 | tp->nvram_pagesize = 256; |
| 11649 | break; |
| 11650 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 11651 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 11652 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 11653 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 11654 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 11655 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 11656 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 11657 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 11658 | tp->nvram_jedecnum = JEDEC_ST; |
| 11659 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11660 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11661 | tp->nvram_pagesize = 256; |
| 11662 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11663 | } |
| 11664 | |
| 11665 | if (protect) { |
| 11666 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); |
| 11667 | } else { |
| 11668 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11669 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 11670 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 11671 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 11672 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 11673 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; |
| 11674 | break; |
| 11675 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 11676 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 11677 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 11678 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 11679 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 11680 | break; |
| 11681 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 11682 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 11683 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 11684 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 11685 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11686 | break; |
| 11687 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 11688 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 11689 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 11690 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 11691 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11692 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11693 | } |
| 11694 | } |
| 11695 | } |
| 11696 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 11697 | static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp) |
| 11698 | { |
| 11699 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11700 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11701 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11702 | } |
| 11703 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11704 | static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp) |
| 11705 | { |
| 11706 | u32 nvcfg1; |
| 11707 | |
| 11708 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11709 | |
| 11710 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11711 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 11712 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 11713 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11714 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11715 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11716 | |
| 11717 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11718 | tw32(NVRAM_CFG1, nvcfg1); |
| 11719 | return; |
| 11720 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11721 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 11722 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 11723 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 11724 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 11725 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 11726 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 11727 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11728 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11729 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11730 | |
| 11731 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11732 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11733 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 11734 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 11735 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11736 | break; |
| 11737 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 11738 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 11739 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11740 | break; |
| 11741 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 11742 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 11743 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11744 | break; |
| 11745 | } |
| 11746 | break; |
| 11747 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11748 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11749 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11750 | tp->nvram_jedecnum = JEDEC_ST; |
| 11751 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11752 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11753 | |
| 11754 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11755 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11756 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11757 | break; |
| 11758 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11759 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11760 | break; |
| 11761 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11762 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11763 | break; |
| 11764 | } |
| 11765 | break; |
| 11766 | default: |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11767 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11768 | return; |
| 11769 | } |
| 11770 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11771 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 11772 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11773 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11774 | } |
| 11775 | |
| 11776 | |
| 11777 | static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp) |
| 11778 | { |
| 11779 | u32 nvcfg1; |
| 11780 | |
| 11781 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11782 | |
| 11783 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11784 | case FLASH_5717VENDOR_ATMEL_EEPROM: |
| 11785 | case FLASH_5717VENDOR_MICRO_EEPROM: |
| 11786 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11787 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11788 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11789 | |
| 11790 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11791 | tw32(NVRAM_CFG1, nvcfg1); |
| 11792 | return; |
| 11793 | case FLASH_5717VENDOR_ATMEL_MDB011D: |
| 11794 | case FLASH_5717VENDOR_ATMEL_ADB011B: |
| 11795 | case FLASH_5717VENDOR_ATMEL_ADB011D: |
| 11796 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 11797 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 11798 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 11799 | case FLASH_5717VENDOR_ATMEL_45USPT: |
| 11800 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11801 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11802 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11803 | |
| 11804 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11805 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 11806 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 11807 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 11808 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11809 | break; |
| 11810 | default: |
| 11811 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11812 | break; |
| 11813 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11814 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11815 | case FLASH_5717VENDOR_ST_M_M25PE10: |
| 11816 | case FLASH_5717VENDOR_ST_A_M25PE10: |
| 11817 | case FLASH_5717VENDOR_ST_M_M45PE10: |
| 11818 | case FLASH_5717VENDOR_ST_A_M45PE10: |
| 11819 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 11820 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 11821 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 11822 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 11823 | case FLASH_5717VENDOR_ST_25USPT: |
| 11824 | case FLASH_5717VENDOR_ST_45USPT: |
| 11825 | tp->nvram_jedecnum = JEDEC_ST; |
| 11826 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11827 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11828 | |
| 11829 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11830 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 11831 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 11832 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 11833 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 11834 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11835 | break; |
| 11836 | default: |
| 11837 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11838 | break; |
| 11839 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11840 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11841 | default: |
| 11842 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM; |
| 11843 | return; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11844 | } |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11845 | |
| 11846 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 11847 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
| 11848 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11849 | } |
| 11850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11851 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
| 11852 | static void __devinit tg3_nvram_init(struct tg3 *tp) |
| 11853 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11854 | tw32_f(GRC_EEPROM_ADDR, |
| 11855 | (EEPROM_ADDR_FSM_RESET | |
| 11856 | (EEPROM_DEFAULT_CLOCK_PERIOD << |
| 11857 | EEPROM_ADDR_CLKPERD_SHIFT))); |
| 11858 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 11859 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11860 | |
| 11861 | /* Enable seeprom accesses. */ |
| 11862 | tw32_f(GRC_LOCAL_CTRL, |
| 11863 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); |
| 11864 | udelay(100); |
| 11865 | |
| 11866 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 11867 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
| 11868 | tp->tg3_flags |= TG3_FLAG_NVRAM; |
| 11869 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11870 | if (tg3_nvram_lock(tp)) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 11871 | netdev_warn(tp->dev, |
| 11872 | "Cannot get nvram lock, %s failed\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 11873 | __func__); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11874 | return; |
| 11875 | } |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11876 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11877 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11878 | tp->nvram_size = 0; |
| 11879 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11880 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 11881 | tg3_get_5752_nvram_info(tp); |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11882 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 11883 | tg3_get_5755_nvram_info(tp); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 11884 | 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] | 11885 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 11886 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11887 | tg3_get_5787_nvram_info(tp); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11888 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 11889 | tg3_get_5761_nvram_info(tp); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 11890 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 11891 | tg3_get_5906_nvram_info(tp); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 11892 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 11893 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11894 | tg3_get_57780_nvram_info(tp); |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 11895 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 11896 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11897 | tg3_get_5717_nvram_info(tp); |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11898 | else |
| 11899 | tg3_get_nvram_info(tp); |
| 11900 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11901 | if (tp->nvram_size == 0) |
| 11902 | tg3_get_nvram_size(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11903 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11904 | tg3_disable_nvram_access(tp); |
Michael Chan | 381291b | 2005-12-13 21:08:21 -0800 | [diff] [blame] | 11905 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11906 | |
| 11907 | } else { |
| 11908 | tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED); |
| 11909 | |
| 11910 | tg3_get_eeprom_size(tp); |
| 11911 | } |
| 11912 | } |
| 11913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11914 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
| 11915 | u32 offset, u32 len, u8 *buf) |
| 11916 | { |
| 11917 | int i, j, rc = 0; |
| 11918 | u32 val; |
| 11919 | |
| 11920 | for (i = 0; i < len; i += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11921 | u32 addr; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11922 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11923 | |
| 11924 | addr = offset + i; |
| 11925 | |
| 11926 | memcpy(&data, buf + i, 4); |
| 11927 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 11928 | /* |
| 11929 | * The SEEPROM interface expects the data to always be opposite |
| 11930 | * the native endian format. We accomplish this by reversing |
| 11931 | * all the operations that would have been performed on the |
| 11932 | * data from a call to tg3_nvram_read_be32(). |
| 11933 | */ |
| 11934 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11935 | |
| 11936 | val = tr32(GRC_EEPROM_ADDR); |
| 11937 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); |
| 11938 | |
| 11939 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | |
| 11940 | EEPROM_ADDR_READ); |
| 11941 | tw32(GRC_EEPROM_ADDR, val | |
| 11942 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 11943 | (addr & EEPROM_ADDR_ADDR_MASK) | |
| 11944 | EEPROM_ADDR_START | |
| 11945 | EEPROM_ADDR_WRITE); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11946 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 11947 | for (j = 0; j < 1000; j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11948 | val = tr32(GRC_EEPROM_ADDR); |
| 11949 | |
| 11950 | if (val & EEPROM_ADDR_COMPLETE) |
| 11951 | break; |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 11952 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11953 | } |
| 11954 | if (!(val & EEPROM_ADDR_COMPLETE)) { |
| 11955 | rc = -EBUSY; |
| 11956 | break; |
| 11957 | } |
| 11958 | } |
| 11959 | |
| 11960 | return rc; |
| 11961 | } |
| 11962 | |
| 11963 | /* offset and length are dword aligned */ |
| 11964 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, |
| 11965 | u8 *buf) |
| 11966 | { |
| 11967 | int ret = 0; |
| 11968 | u32 pagesize = tp->nvram_pagesize; |
| 11969 | u32 pagemask = pagesize - 1; |
| 11970 | u32 nvram_cmd; |
| 11971 | u8 *tmp; |
| 11972 | |
| 11973 | tmp = kmalloc(pagesize, GFP_KERNEL); |
| 11974 | if (tmp == NULL) |
| 11975 | return -ENOMEM; |
| 11976 | |
| 11977 | while (len) { |
| 11978 | int j; |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11979 | u32 phy_addr, page_off, size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11980 | |
| 11981 | phy_addr = offset & ~pagemask; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11983 | for (j = 0; j < pagesize; j += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11984 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
| 11985 | (__be32 *) (tmp + j)); |
| 11986 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11987 | break; |
| 11988 | } |
| 11989 | if (ret) |
| 11990 | break; |
| 11991 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 11992 | page_off = offset & pagemask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11993 | size = pagesize; |
| 11994 | if (len < size) |
| 11995 | size = len; |
| 11996 | |
| 11997 | len -= size; |
| 11998 | |
| 11999 | memcpy(tmp + page_off, buf, size); |
| 12000 | |
| 12001 | offset = offset + (pagesize - page_off); |
| 12002 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12003 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12004 | |
| 12005 | /* |
| 12006 | * Before we can erase the flash page, we need |
| 12007 | * to issue a special "write enable" command. |
| 12008 | */ |
| 12009 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 12010 | |
| 12011 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 12012 | break; |
| 12013 | |
| 12014 | /* Erase the target page */ |
| 12015 | tw32(NVRAM_ADDR, phy_addr); |
| 12016 | |
| 12017 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | |
| 12018 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; |
| 12019 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12020 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12021 | break; |
| 12022 | |
| 12023 | /* Issue another write enable to start the write. */ |
| 12024 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 12025 | |
| 12026 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 12027 | break; |
| 12028 | |
| 12029 | for (j = 0; j < pagesize; j += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12030 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12031 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12032 | data = *((__be32 *) (tmp + j)); |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12033 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12034 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12035 | |
| 12036 | tw32(NVRAM_ADDR, phy_addr + j); |
| 12037 | |
| 12038 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | |
| 12039 | NVRAM_CMD_WR; |
| 12040 | |
| 12041 | if (j == 0) |
| 12042 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 12043 | else if (j == (pagesize - 4)) |
| 12044 | nvram_cmd |= NVRAM_CMD_LAST; |
| 12045 | |
| 12046 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) |
| 12047 | break; |
| 12048 | } |
| 12049 | if (ret) |
| 12050 | break; |
| 12051 | } |
| 12052 | |
| 12053 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 12054 | tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 12055 | |
| 12056 | kfree(tmp); |
| 12057 | |
| 12058 | return ret; |
| 12059 | } |
| 12060 | |
| 12061 | /* offset and length are dword aligned */ |
| 12062 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, |
| 12063 | u8 *buf) |
| 12064 | { |
| 12065 | int i, ret = 0; |
| 12066 | |
| 12067 | for (i = 0; i < len; i += 4, offset += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12068 | u32 page_off, phy_addr, nvram_cmd; |
| 12069 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12070 | |
| 12071 | memcpy(&data, buf + i, 4); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12072 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12073 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12074 | page_off = offset % tp->nvram_pagesize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12075 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12076 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12077 | |
| 12078 | tw32(NVRAM_ADDR, phy_addr); |
| 12079 | |
| 12080 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
| 12081 | |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 12082 | if (page_off == 0 || i == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12083 | nvram_cmd |= NVRAM_CMD_FIRST; |
Michael Chan | f6d9a25 | 2006-04-29 19:00:24 -0700 | [diff] [blame] | 12084 | if (page_off == (tp->nvram_pagesize - 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12085 | nvram_cmd |= NVRAM_CMD_LAST; |
| 12086 | |
| 12087 | if (i == (len - 4)) |
| 12088 | nvram_cmd |= NVRAM_CMD_LAST; |
| 12089 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12090 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
| 12091 | !(tp->tg3_flags3 & TG3_FLG3_5755_PLUS) && |
Michael Chan | 4c98748 | 2005-09-05 17:52:38 -0700 | [diff] [blame] | 12092 | (tp->nvram_jedecnum == JEDEC_ST) && |
| 12093 | (nvram_cmd & NVRAM_CMD_FIRST)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12094 | |
| 12095 | if ((ret = tg3_nvram_exec_cmd(tp, |
| 12096 | NVRAM_CMD_WREN | NVRAM_CMD_GO | |
| 12097 | NVRAM_CMD_DONE))) |
| 12098 | |
| 12099 | break; |
| 12100 | } |
| 12101 | if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) { |
| 12102 | /* We always do complete word writes to eeprom. */ |
| 12103 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); |
| 12104 | } |
| 12105 | |
| 12106 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) |
| 12107 | break; |
| 12108 | } |
| 12109 | return ret; |
| 12110 | } |
| 12111 | |
| 12112 | /* offset and length are dword aligned */ |
| 12113 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) |
| 12114 | { |
| 12115 | int ret; |
| 12116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12117 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 12118 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
| 12119 | ~GRC_LCLCTRL_GPIO_OUTPUT1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12120 | udelay(40); |
| 12121 | } |
| 12122 | |
| 12123 | if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) { |
| 12124 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 12125 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12126 | u32 grc_mode; |
| 12127 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12128 | ret = tg3_nvram_lock(tp); |
| 12129 | if (ret) |
| 12130 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12131 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12132 | tg3_enable_nvram_access(tp); |
| 12133 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 12134 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12135 | tw32(NVRAM_WRITE1, 0x406); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12136 | |
| 12137 | grc_mode = tr32(GRC_MODE); |
| 12138 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); |
| 12139 | |
| 12140 | if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) || |
| 12141 | !(tp->tg3_flags2 & TG3_FLG2_FLASH)) { |
| 12142 | |
| 12143 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
| 12144 | buf); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 12145 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12146 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
| 12147 | buf); |
| 12148 | } |
| 12149 | |
| 12150 | grc_mode = tr32(GRC_MODE); |
| 12151 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); |
| 12152 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12153 | tg3_disable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12154 | tg3_nvram_unlock(tp); |
| 12155 | } |
| 12156 | |
| 12157 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 12158 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12159 | udelay(40); |
| 12160 | } |
| 12161 | |
| 12162 | return ret; |
| 12163 | } |
| 12164 | |
| 12165 | struct subsys_tbl_ent { |
| 12166 | u16 subsys_vendor, subsys_devid; |
| 12167 | u32 phy_id; |
| 12168 | }; |
| 12169 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12170 | static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12171 | /* Broadcom boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12172 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12173 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12174 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12175 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12176 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12177 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12178 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 12179 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, |
| 12180 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12181 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12182 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12183 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12184 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 12185 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, |
| 12186 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12187 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12188 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12189 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12190 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12191 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12192 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12193 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12194 | |
| 12195 | /* 3com boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12196 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12197 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12198 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12199 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12200 | { TG3PCI_SUBVENDOR_ID_3COM, |
| 12201 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, |
| 12202 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12203 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12204 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12205 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12206 | |
| 12207 | /* DELL boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12208 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12209 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12210 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12211 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12212 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12213 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12214 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12215 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12216 | |
| 12217 | /* Compaq boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12218 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12219 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12220 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12221 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12222 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 12223 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, |
| 12224 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12225 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12226 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12227 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12228 | |
| 12229 | /* IBM boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12230 | { TG3PCI_SUBVENDOR_ID_IBM, |
| 12231 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12232 | }; |
| 12233 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12234 | 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] | 12235 | { |
| 12236 | int i; |
| 12237 | |
| 12238 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { |
| 12239 | if ((subsys_id_to_phy_id[i].subsys_vendor == |
| 12240 | tp->pdev->subsystem_vendor) && |
| 12241 | (subsys_id_to_phy_id[i].subsys_devid == |
| 12242 | tp->pdev->subsystem_device)) |
| 12243 | return &subsys_id_to_phy_id[i]; |
| 12244 | } |
| 12245 | return NULL; |
| 12246 | } |
| 12247 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12248 | static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12249 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12250 | u32 val; |
Michael Chan | caf636c7 | 2006-03-22 01:05:31 -0800 | [diff] [blame] | 12251 | u16 pmcsr; |
| 12252 | |
| 12253 | /* On some early chips the SRAM cannot be accessed in D3hot state, |
| 12254 | * so need make sure we're in D0. |
| 12255 | */ |
| 12256 | pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr); |
| 12257 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
| 12258 | pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr); |
| 12259 | msleep(1); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12260 | |
| 12261 | /* Make sure register accesses (indirect or otherwise) |
| 12262 | * will function correctly. |
| 12263 | */ |
| 12264 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 12265 | tp->misc_host_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12266 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12267 | /* The memory arbiter has to be enabled in order for SRAM accesses |
| 12268 | * to succeed. Normally on powerup the tg3 chip firmware will make |
| 12269 | * sure it is enabled, but other entities such as system netboot |
| 12270 | * code might disable it. |
| 12271 | */ |
| 12272 | val = tr32(MEMARB_MODE); |
| 12273 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 12274 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12275 | tp->phy_id = TG3_PHY_ID_INVALID; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12276 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12277 | |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 12278 | /* Assume an onboard device and WOL capable by default. */ |
| 12279 | 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] | 12280 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12281 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12282 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12283 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12284 | tp->tg3_flags2 |= TG3_FLG2_IS_NIC; |
| 12285 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12286 | val = tr32(VCPU_CFGSHDW); |
| 12287 | if (val & VCPU_CFGSHDW_ASPM_DBNC) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12288 | tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND; |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12289 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 12290 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12291 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12292 | goto done; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12293 | } |
| 12294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12295 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 12296 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 12297 | u32 nic_cfg, led_cfg; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12298 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12299 | int eeprom_phy_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12300 | |
| 12301 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 12302 | tp->nic_sram_data_cfg = nic_cfg; |
| 12303 | |
| 12304 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); |
| 12305 | ver >>= NIC_SRAM_DATA_VER_SHIFT; |
| 12306 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) && |
| 12307 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) && |
| 12308 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) && |
| 12309 | (ver > 0) && (ver < 0x100)) |
| 12310 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); |
| 12311 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12312 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 12313 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
| 12314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12315 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
| 12316 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) |
| 12317 | eeprom_phy_serdes = 1; |
| 12318 | |
| 12319 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); |
| 12320 | if (nic_phy_id != 0) { |
| 12321 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; |
| 12322 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; |
| 12323 | |
| 12324 | eeprom_phy_id = (id1 >> 16) << 10; |
| 12325 | eeprom_phy_id |= (id2 & 0xfc00) << 16; |
| 12326 | eeprom_phy_id |= (id2 & 0x03ff) << 0; |
| 12327 | } else |
| 12328 | eeprom_phy_id = 0; |
| 12329 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12330 | tp->phy_id = eeprom_phy_id; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 12331 | if (eeprom_phy_serdes) { |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 12332 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12333 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 12334 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12335 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 12336 | } |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12337 | |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 12338 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12339 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
| 12340 | SHASTA_EXT_LED_MODE_MASK); |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 12341 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12342 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
| 12343 | |
| 12344 | switch (led_cfg) { |
| 12345 | default: |
| 12346 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: |
| 12347 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12348 | break; |
| 12349 | |
| 12350 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: |
| 12351 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 12352 | break; |
| 12353 | |
| 12354 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: |
| 12355 | tp->led_ctrl = LED_CTRL_MODE_MAC; |
Michael Chan | 9ba2779 | 2005-06-06 15:16:20 -0700 | [diff] [blame] | 12356 | |
| 12357 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is |
| 12358 | * read on some older 5700/5701 bootcode. |
| 12359 | */ |
| 12360 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 12361 | ASIC_REV_5700 || |
| 12362 | GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 12363 | ASIC_REV_5701) |
| 12364 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12366 | break; |
| 12367 | |
| 12368 | case SHASTA_EXT_LED_SHARED: |
| 12369 | tp->led_ctrl = LED_CTRL_MODE_SHARED; |
| 12370 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 12371 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) |
| 12372 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 12373 | LED_CTRL_MODE_PHY_2); |
| 12374 | break; |
| 12375 | |
| 12376 | case SHASTA_EXT_LED_MAC: |
| 12377 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; |
| 12378 | break; |
| 12379 | |
| 12380 | case SHASTA_EXT_LED_COMBO: |
| 12381 | tp->led_ctrl = LED_CTRL_MODE_COMBO; |
| 12382 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) |
| 12383 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 12384 | LED_CTRL_MODE_PHY_2); |
| 12385 | break; |
| 12386 | |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 12387 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12388 | |
| 12389 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 12390 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && |
| 12391 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
| 12392 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 12393 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 12394 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
| 12395 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
Matt Carlson | 5f60891 | 2007-11-12 21:17:07 -0800 | [diff] [blame] | 12396 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12397 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12398 | tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT; |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12399 | if ((tp->pdev->subsystem_vendor == |
| 12400 | PCI_VENDOR_ID_ARIMA) && |
| 12401 | (tp->pdev->subsystem_device == 0x205a || |
| 12402 | tp->pdev->subsystem_device == 0x2063)) |
| 12403 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
| 12404 | } else { |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12405 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12406 | tp->tg3_flags2 |= TG3_FLG2_IS_NIC; |
| 12407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12408 | |
| 12409 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
| 12410 | tp->tg3_flags |= TG3_FLAG_ENABLE_ASF; |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 12411 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12412 | tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE; |
| 12413 | } |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 12414 | |
| 12415 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && |
| 12416 | (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 12417 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_APE; |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 12418 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12419 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 12420 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
| 12421 | tp->tg3_flags &= ~TG3_FLAG_WOL_CAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12422 | |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 12423 | if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) && |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12424 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12425 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
| 12426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12427 | if (cfg2 & (1 << 17)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12428 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12429 | |
| 12430 | /* serdes signal pre-emphasis in register 0x590 set by */ |
| 12431 | /* bootcode if bit 18 is set */ |
| 12432 | if (cfg2 & (1 << 18)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12433 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12434 | |
Matt Carlson | 2e1e329 | 2010-11-24 08:31:53 +0000 | [diff] [blame] | 12435 | if (((tp->tg3_flags3 & TG3_FLG3_5717_PLUS) || |
| 12436 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 12437 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX))) && |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12438 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12439 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12440 | |
Matt Carlson | 8c69b1e | 2010-08-02 11:26:00 +0000 | [diff] [blame] | 12441 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && |
| 12442 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
| 12443 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12444 | u32 cfg3; |
| 12445 | |
| 12446 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); |
| 12447 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) |
| 12448 | tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND; |
| 12449 | } |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12450 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 12451 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
| 12452 | tp->tg3_flags3 |= TG3_FLG3_RGMII_INBAND_DISABLE; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12453 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
| 12454 | tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_RX_EN; |
| 12455 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
| 12456 | tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_TX_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12457 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12458 | done: |
| 12459 | device_init_wakeup(&tp->pdev->dev, tp->tg3_flags & TG3_FLAG_WOL_CAP); |
| 12460 | device_set_wakeup_enable(&tp->pdev->dev, |
| 12461 | tp->tg3_flags & TG3_FLAG_WOL_ENABLE); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12462 | } |
| 12463 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 12464 | static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
| 12465 | { |
| 12466 | int i; |
| 12467 | u32 val; |
| 12468 | |
| 12469 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); |
| 12470 | tw32(OTP_CTRL, cmd); |
| 12471 | |
| 12472 | /* Wait for up to 1 ms for command to execute. */ |
| 12473 | for (i = 0; i < 100; i++) { |
| 12474 | val = tr32(OTP_STATUS); |
| 12475 | if (val & OTP_STATUS_CMD_DONE) |
| 12476 | break; |
| 12477 | udelay(10); |
| 12478 | } |
| 12479 | |
| 12480 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; |
| 12481 | } |
| 12482 | |
| 12483 | /* Read the gphy configuration from the OTP region of the chip. The gphy |
| 12484 | * configuration is a 32-bit value that straddles the alignment boundary. |
| 12485 | * We do two 32-bit reads and then shift and merge the results. |
| 12486 | */ |
| 12487 | static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp) |
| 12488 | { |
| 12489 | u32 bhalf_otp, thalf_otp; |
| 12490 | |
| 12491 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); |
| 12492 | |
| 12493 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) |
| 12494 | return 0; |
| 12495 | |
| 12496 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); |
| 12497 | |
| 12498 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 12499 | return 0; |
| 12500 | |
| 12501 | thalf_otp = tr32(OTP_READ_DATA); |
| 12502 | |
| 12503 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); |
| 12504 | |
| 12505 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 12506 | return 0; |
| 12507 | |
| 12508 | bhalf_otp = tr32(OTP_READ_DATA); |
| 12509 | |
| 12510 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); |
| 12511 | } |
| 12512 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12513 | static int __devinit tg3_phy_probe(struct tg3 *tp) |
| 12514 | { |
| 12515 | u32 hw_phy_id_1, hw_phy_id_2; |
| 12516 | u32 hw_phy_id, hw_phy_id_masked; |
| 12517 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12518 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12519 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) |
| 12520 | return tg3_phy_init(tp); |
| 12521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12522 | /* Reading the PHY ID register can conflict with ASF |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 12523 | * firmware access to the PHY hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12524 | */ |
| 12525 | err = 0; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 12526 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
| 12527 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12528 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12529 | } else { |
| 12530 | /* Now read the physical PHY_ID from the chip and verify |
| 12531 | * that it is sane. If it doesn't look good, we fall back |
| 12532 | * to either the hard-coded table based PHY_ID and failing |
| 12533 | * that the value found in the eeprom area. |
| 12534 | */ |
| 12535 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); |
| 12536 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); |
| 12537 | |
| 12538 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; |
| 12539 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; |
| 12540 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; |
| 12541 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12542 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12543 | } |
| 12544 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12545 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12546 | tp->phy_id = hw_phy_id; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12547 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12548 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Michael Chan | da6b2d0 | 2005-08-19 12:54:29 -0700 | [diff] [blame] | 12549 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12550 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12551 | } else { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12552 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12553 | /* Do nothing, phy ID already set up in |
| 12554 | * tg3_get_eeprom_hw_cfg(). |
| 12555 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12556 | } else { |
| 12557 | struct subsys_tbl_ent *p; |
| 12558 | |
| 12559 | /* No eeprom signature? Try the hardcoded |
| 12560 | * subsys device table. |
| 12561 | */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12562 | p = tg3_lookup_by_subsys(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12563 | if (!p) |
| 12564 | return -ENODEV; |
| 12565 | |
| 12566 | tp->phy_id = p->phy_id; |
| 12567 | if (!tp->phy_id || |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12568 | tp->phy_id == TG3_PHY_ID_BCM8002) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12569 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12570 | } |
| 12571 | } |
| 12572 | |
Matt Carlson | a6b68da | 2010-12-06 08:28:52 +0000 | [diff] [blame^] | 12573 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
| 12574 | ((tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 && |
| 12575 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) || |
| 12576 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 12577 | tp->pci_chip_rev_id != CHIPREV_ID_57765_A0))) |
Matt Carlson | 52b02d0 | 2010-10-14 10:37:41 +0000 | [diff] [blame] | 12578 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 12579 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12580 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 12581 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12582 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 12583 | u32 bmsr, adv_reg, tg3_ctrl, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12584 | |
| 12585 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 12586 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 12587 | (bmsr & BMSR_LSTATUS)) |
| 12588 | goto skip_phy_reset; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12590 | err = tg3_phy_reset(tp); |
| 12591 | if (err) |
| 12592 | return err; |
| 12593 | |
| 12594 | adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 12595 | ADVERTISE_100HALF | ADVERTISE_100FULL | |
| 12596 | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); |
| 12597 | tg3_ctrl = 0; |
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_ctrl = (MII_TG3_CTRL_ADV_1000_HALF | |
| 12600 | MII_TG3_CTRL_ADV_1000_FULL); |
| 12601 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 12602 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) |
| 12603 | tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER | |
| 12604 | MII_TG3_CTRL_ENABLE_AS_MASTER); |
| 12605 | } |
| 12606 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 12607 | mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 12608 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 12609 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full); |
| 12610 | if (!tg3_copper_is_advertising_all(tp, mask)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12611 | tg3_writephy(tp, MII_ADVERTISE, adv_reg); |
| 12612 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12613 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12614 | tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl); |
| 12615 | |
| 12616 | tg3_writephy(tp, MII_BMCR, |
| 12617 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 12618 | } |
| 12619 | tg3_phy_set_wirespeed(tp); |
| 12620 | |
| 12621 | tg3_writephy(tp, MII_ADVERTISE, adv_reg); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12622 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12623 | tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl); |
| 12624 | } |
| 12625 | |
| 12626 | skip_phy_reset: |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12627 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12628 | err = tg3_init_5401phy_dsp(tp); |
| 12629 | if (err) |
| 12630 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12632 | err = tg3_init_5401phy_dsp(tp); |
| 12633 | } |
| 12634 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12635 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12636 | tp->link_config.advertising = |
| 12637 | (ADVERTISED_1000baseT_Half | |
| 12638 | ADVERTISED_1000baseT_Full | |
| 12639 | ADVERTISED_Autoneg | |
| 12640 | ADVERTISED_FIBRE); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 12641 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12642 | tp->link_config.advertising &= |
| 12643 | ~(ADVERTISED_1000baseT_Half | |
| 12644 | ADVERTISED_1000baseT_Full); |
| 12645 | |
| 12646 | return err; |
| 12647 | } |
| 12648 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 12649 | static void __devinit tg3_read_vpd(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12650 | { |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 12651 | u8 *vpd_data; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12652 | unsigned int block_end, rosize, len; |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 12653 | int j, i = 0; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12654 | u32 magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12655 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 12656 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
| 12657 | tg3_nvram_read(tp, 0x0, &magic)) |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 12658 | goto out_no_vpd; |
| 12659 | |
| 12660 | vpd_data = kmalloc(TG3_NVM_VPD_LEN, GFP_KERNEL); |
| 12661 | if (!vpd_data) |
| 12662 | goto out_no_vpd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12663 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12664 | if (magic == TG3_EEPROM_MAGIC) { |
Matt Carlson | 141518c | 2009-12-03 08:36:22 +0000 | [diff] [blame] | 12665 | for (i = 0; i < TG3_NVM_VPD_LEN; i += 4) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12666 | u32 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12667 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12668 | /* The data is in little-endian format in NVRAM. |
| 12669 | * Use the big-endian read routines to preserve |
| 12670 | * the byte order as it exists in NVRAM. |
| 12671 | */ |
Matt Carlson | 141518c | 2009-12-03 08:36:22 +0000 | [diff] [blame] | 12672 | if (tg3_nvram_read_be32(tp, TG3_NVM_VPD_OFF + i, &tmp)) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12673 | goto out_not_found; |
| 12674 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12675 | memcpy(&vpd_data[i], &tmp, sizeof(tmp)); |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12676 | } |
| 12677 | } else { |
Matt Carlson | 94c982b | 2009-12-03 08:36:23 +0000 | [diff] [blame] | 12678 | ssize_t cnt; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12679 | unsigned int pos = 0; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12680 | |
Matt Carlson | 94c982b | 2009-12-03 08:36:23 +0000 | [diff] [blame] | 12681 | for (; pos < TG3_NVM_VPD_LEN && i < 3; i++, pos += cnt) { |
| 12682 | cnt = pci_read_vpd(tp->pdev, pos, |
| 12683 | TG3_NVM_VPD_LEN - pos, |
| 12684 | &vpd_data[pos]); |
| 12685 | if (cnt == -ETIMEDOUT || -EINTR) |
| 12686 | cnt = 0; |
| 12687 | else if (cnt < 0) |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12688 | goto out_not_found; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12689 | } |
Matt Carlson | 94c982b | 2009-12-03 08:36:23 +0000 | [diff] [blame] | 12690 | if (pos != TG3_NVM_VPD_LEN) |
| 12691 | goto out_not_found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12692 | } |
| 12693 | |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12694 | i = pci_vpd_find_tag(vpd_data, 0, TG3_NVM_VPD_LEN, |
| 12695 | PCI_VPD_LRDT_RO_DATA); |
| 12696 | if (i < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12697 | goto out_not_found; |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12698 | |
| 12699 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
| 12700 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; |
| 12701 | i += PCI_VPD_LRDT_TAG_SIZE; |
| 12702 | |
| 12703 | if (block_end > TG3_NVM_VPD_LEN) |
| 12704 | goto out_not_found; |
| 12705 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 12706 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 12707 | PCI_VPD_RO_KEYWORD_MFR_ID); |
| 12708 | if (j > 0) { |
| 12709 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 12710 | |
| 12711 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 12712 | if (j + len > block_end || len != 4 || |
| 12713 | memcmp(&vpd_data[j], "1028", 4)) |
| 12714 | goto partno; |
| 12715 | |
| 12716 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 12717 | PCI_VPD_RO_KEYWORD_VENDOR0); |
| 12718 | if (j < 0) |
| 12719 | goto partno; |
| 12720 | |
| 12721 | len = pci_vpd_info_field_size(&vpd_data[j]); |
| 12722 | |
| 12723 | j += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 12724 | if (j + len > block_end) |
| 12725 | goto partno; |
| 12726 | |
| 12727 | memcpy(tp->fw_ver, &vpd_data[j], len); |
| 12728 | strncat(tp->fw_ver, " bc ", TG3_NVM_VPD_LEN - len - 1); |
| 12729 | } |
| 12730 | |
| 12731 | partno: |
Matt Carlson | 4181b2c | 2010-02-26 14:04:45 +0000 | [diff] [blame] | 12732 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
| 12733 | PCI_VPD_RO_KEYWORD_PARTNO); |
| 12734 | if (i < 0) |
| 12735 | goto out_not_found; |
| 12736 | |
| 12737 | len = pci_vpd_info_field_size(&vpd_data[i]); |
| 12738 | |
| 12739 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
| 12740 | if (len > TG3_BPN_SIZE || |
| 12741 | (len + i) > TG3_NVM_VPD_LEN) |
| 12742 | goto out_not_found; |
| 12743 | |
| 12744 | memcpy(tp->board_part_number, &vpd_data[i], len); |
| 12745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12746 | out_not_found: |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 12747 | kfree(vpd_data); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 12748 | if (tp->board_part_number[0]) |
Matt Carlson | a4a8bb1 | 2010-09-15 09:00:00 +0000 | [diff] [blame] | 12749 | return; |
| 12750 | |
| 12751 | out_no_vpd: |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 12752 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 12753 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717) |
| 12754 | strcpy(tp->board_part_number, "BCM5717"); |
| 12755 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) |
| 12756 | strcpy(tp->board_part_number, "BCM5718"); |
| 12757 | else |
| 12758 | goto nomatch; |
| 12759 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 12760 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
| 12761 | strcpy(tp->board_part_number, "BCM57780"); |
| 12762 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) |
| 12763 | strcpy(tp->board_part_number, "BCM57760"); |
| 12764 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) |
| 12765 | strcpy(tp->board_part_number, "BCM57790"); |
| 12766 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) |
| 12767 | strcpy(tp->board_part_number, "BCM57788"); |
| 12768 | else |
| 12769 | goto nomatch; |
| 12770 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
| 12771 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
| 12772 | strcpy(tp->board_part_number, "BCM57761"); |
| 12773 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) |
| 12774 | strcpy(tp->board_part_number, "BCM57765"); |
| 12775 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) |
| 12776 | strcpy(tp->board_part_number, "BCM57781"); |
| 12777 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) |
| 12778 | strcpy(tp->board_part_number, "BCM57785"); |
| 12779 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) |
| 12780 | strcpy(tp->board_part_number, "BCM57791"); |
| 12781 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 12782 | strcpy(tp->board_part_number, "BCM57795"); |
| 12783 | else |
| 12784 | goto nomatch; |
| 12785 | } 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] | 12786 | strcpy(tp->board_part_number, "BCM95906"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 12787 | } else { |
| 12788 | nomatch: |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12789 | strcpy(tp->board_part_number, "none"); |
Matt Carlson | 37a949c | 2010-09-30 10:34:33 +0000 | [diff] [blame] | 12790 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12791 | } |
| 12792 | |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12793 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
| 12794 | { |
| 12795 | u32 val; |
| 12796 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12797 | if (tg3_nvram_read(tp, offset, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12798 | (val & 0xfc000000) != 0x0c000000 || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12799 | tg3_nvram_read(tp, offset + 4, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12800 | val != 0) |
| 12801 | return 0; |
| 12802 | |
| 12803 | return 1; |
| 12804 | } |
| 12805 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12806 | static void __devinit tg3_read_bc_ver(struct tg3 *tp) |
| 12807 | { |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12808 | u32 val, offset, start, ver_offset; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12809 | int i, dst_off; |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12810 | bool newver = false; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12811 | |
| 12812 | if (tg3_nvram_read(tp, 0xc, &offset) || |
| 12813 | tg3_nvram_read(tp, 0x4, &start)) |
| 12814 | return; |
| 12815 | |
| 12816 | offset = tg3_nvram_logical_addr(tp, offset); |
| 12817 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12818 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12819 | return; |
| 12820 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12821 | if ((val & 0xfc000000) == 0x0c000000) { |
| 12822 | if (tg3_nvram_read(tp, offset + 4, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12823 | return; |
| 12824 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12825 | if (val == 0) |
| 12826 | newver = true; |
| 12827 | } |
| 12828 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12829 | dst_off = strlen(tp->fw_ver); |
| 12830 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12831 | if (newver) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12832 | if (TG3_VER_SIZE - dst_off < 16 || |
| 12833 | tg3_nvram_read(tp, offset + 8, &ver_offset)) |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12834 | return; |
| 12835 | |
| 12836 | offset = offset + ver_offset - start; |
| 12837 | for (i = 0; i < 16; i += 4) { |
| 12838 | __be32 v; |
| 12839 | if (tg3_nvram_read_be32(tp, offset + i, &v)) |
| 12840 | return; |
| 12841 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12842 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12843 | } |
| 12844 | } else { |
| 12845 | u32 major, minor; |
| 12846 | |
| 12847 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) |
| 12848 | return; |
| 12849 | |
| 12850 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> |
| 12851 | TG3_NVM_BCVER_MAJSFT; |
| 12852 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12853 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
| 12854 | "v%d.%02d", major, minor); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12855 | } |
| 12856 | } |
| 12857 | |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 12858 | static void __devinit tg3_read_hwsb_ver(struct tg3 *tp) |
| 12859 | { |
| 12860 | u32 val, major, minor; |
| 12861 | |
| 12862 | /* Use native endian representation */ |
| 12863 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) |
| 12864 | return; |
| 12865 | |
| 12866 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> |
| 12867 | TG3_NVM_HWSB_CFG1_MAJSFT; |
| 12868 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> |
| 12869 | TG3_NVM_HWSB_CFG1_MINSFT; |
| 12870 | |
| 12871 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); |
| 12872 | } |
| 12873 | |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12874 | static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val) |
| 12875 | { |
| 12876 | u32 offset, major, minor, build; |
| 12877 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12878 | 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] | 12879 | |
| 12880 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) |
| 12881 | return; |
| 12882 | |
| 12883 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { |
| 12884 | case TG3_EEPROM_SB_REVISION_0: |
| 12885 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; |
| 12886 | break; |
| 12887 | case TG3_EEPROM_SB_REVISION_2: |
| 12888 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; |
| 12889 | break; |
| 12890 | case TG3_EEPROM_SB_REVISION_3: |
| 12891 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; |
| 12892 | break; |
Matt Carlson | a4153d4 | 2010-02-17 15:16:56 +0000 | [diff] [blame] | 12893 | case TG3_EEPROM_SB_REVISION_4: |
| 12894 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; |
| 12895 | break; |
| 12896 | case TG3_EEPROM_SB_REVISION_5: |
| 12897 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; |
| 12898 | break; |
Matt Carlson | bba226a | 2010-10-14 10:37:38 +0000 | [diff] [blame] | 12899 | case TG3_EEPROM_SB_REVISION_6: |
| 12900 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; |
| 12901 | break; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12902 | default: |
| 12903 | return; |
| 12904 | } |
| 12905 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12906 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12907 | return; |
| 12908 | |
| 12909 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> |
| 12910 | TG3_EEPROM_SB_EDH_BLD_SHFT; |
| 12911 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> |
| 12912 | TG3_EEPROM_SB_EDH_MAJ_SHFT; |
| 12913 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; |
| 12914 | |
| 12915 | if (minor > 99 || build > 26) |
| 12916 | return; |
| 12917 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12918 | offset = strlen(tp->fw_ver); |
| 12919 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, |
| 12920 | " v%d.%02d", major, minor); |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12921 | |
| 12922 | if (build > 0) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 12923 | offset = strlen(tp->fw_ver); |
| 12924 | if (offset < TG3_VER_SIZE - 1) |
| 12925 | tp->fw_ver[offset] = 'a' + build - 1; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12926 | } |
| 12927 | } |
| 12928 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12929 | static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp) |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 12930 | { |
| 12931 | u32 val, offset, start; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12932 | int i, vlen; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12933 | |
| 12934 | for (offset = TG3_NVM_DIR_START; |
| 12935 | offset < TG3_NVM_DIR_END; |
| 12936 | offset += TG3_NVM_DIRENT_SIZE) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12937 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12938 | return; |
| 12939 | |
| 12940 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
| 12941 | break; |
| 12942 | } |
| 12943 | |
| 12944 | if (offset == TG3_NVM_DIR_END) |
| 12945 | return; |
| 12946 | |
| 12947 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 12948 | start = 0x08000000; |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12949 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12950 | return; |
| 12951 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12952 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12953 | !tg3_fw_img_is_valid(tp, offset) || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12954 | tg3_nvram_read(tp, offset + 8, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12955 | return; |
| 12956 | |
| 12957 | offset += val - start; |
| 12958 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12959 | vlen = strlen(tp->fw_ver); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12960 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12961 | tp->fw_ver[vlen++] = ','; |
| 12962 | tp->fw_ver[vlen++] = ' '; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12963 | |
| 12964 | for (i = 0; i < 4; i++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12965 | __be32 v; |
| 12966 | if (tg3_nvram_read_be32(tp, offset, &v)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12967 | return; |
| 12968 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12969 | offset += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12970 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12971 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
| 12972 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12973 | break; |
| 12974 | } |
| 12975 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12976 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
| 12977 | vlen += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12978 | } |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12979 | } |
| 12980 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 12981 | static void __devinit tg3_read_dash_ver(struct tg3 *tp) |
| 12982 | { |
| 12983 | int vlen; |
| 12984 | u32 apedata; |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 12985 | char *fwtype; |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 12986 | |
| 12987 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) || |
| 12988 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 12989 | return; |
| 12990 | |
| 12991 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 12992 | if (apedata != APE_SEG_SIG_MAGIC) |
| 12993 | return; |
| 12994 | |
| 12995 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 12996 | if (!(apedata & APE_FW_STATUS_READY)) |
| 12997 | return; |
| 12998 | |
| 12999 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
| 13000 | |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13001 | if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) { |
| 13002 | tp->tg3_flags3 |= TG3_FLG3_APE_HAS_NCSI; |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13003 | fwtype = "NCSI"; |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13004 | } else { |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13005 | fwtype = "DASH"; |
Matt Carlson | dc6d074 | 2010-09-15 08:59:55 +0000 | [diff] [blame] | 13006 | } |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13007 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13008 | vlen = strlen(tp->fw_ver); |
| 13009 | |
Matt Carlson | ecc7964 | 2010-08-02 11:26:01 +0000 | [diff] [blame] | 13010 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
| 13011 | fwtype, |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 13012 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
| 13013 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, |
| 13014 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, |
| 13015 | (apedata & APE_FW_VERSION_BLDMSK)); |
| 13016 | } |
| 13017 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13018 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
| 13019 | { |
| 13020 | u32 val; |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13021 | bool vpd_vers = false; |
| 13022 | |
| 13023 | if (tp->fw_ver[0] != 0) |
| 13024 | vpd_vers = true; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13025 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 13026 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) { |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13027 | strcat(tp->fw_ver, "sb"); |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 13028 | return; |
| 13029 | } |
| 13030 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13031 | if (tg3_nvram_read(tp, 0, &val)) |
| 13032 | return; |
| 13033 | |
| 13034 | if (val == TG3_EEPROM_MAGIC) |
| 13035 | tg3_read_bc_ver(tp); |
| 13036 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) |
| 13037 | tg3_read_sb_ver(tp, val); |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 13038 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 13039 | tg3_read_hwsb_ver(tp); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13040 | else |
| 13041 | return; |
| 13042 | |
| 13043 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13044 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) || vpd_vers) |
| 13045 | goto done; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 13046 | |
| 13047 | tg3_read_mgmtfw_ver(tp); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13048 | |
Matt Carlson | 75f9936 | 2010-04-05 10:19:24 +0000 | [diff] [blame] | 13049 | done: |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 13050 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13051 | } |
| 13052 | |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13053 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *); |
| 13054 | |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 13055 | static void inline vlan_features_add(struct net_device *dev, unsigned long flags) |
| 13056 | { |
| 13057 | #if TG3_VLAN_TAG_USED |
| 13058 | dev->vlan_features |= flags; |
| 13059 | #endif |
| 13060 | } |
| 13061 | |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13062 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
| 13063 | { |
| 13064 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13065 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
| 13066 | return 4096; |
| 13067 | else if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && |
| 13068 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
| 13069 | return 1024; |
| 13070 | else |
| 13071 | return 512; |
| 13072 | } |
| 13073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13074 | static int __devinit tg3_get_invariants(struct tg3 *tp) |
| 13075 | { |
| 13076 | static struct pci_device_id write_reorder_chipsets[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13077 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 13078 | PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
John W. Linville | c165b00 | 2006-07-08 13:28:53 -0700 | [diff] [blame] | 13079 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 13080 | PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 13081 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, |
| 13082 | PCI_DEVICE_ID_VIA_8385_0) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13083 | { }, |
| 13084 | }; |
| 13085 | u32 misc_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13086 | u32 pci_state_reg, grc_misc_cfg; |
| 13087 | u32 val; |
| 13088 | u16 pci_cmd; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13089 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13091 | /* Force memory write invalidate off. If we leave it on, |
| 13092 | * then on 5700_BX chips we have to enable a workaround. |
| 13093 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary |
| 13094 | * to match the cacheline size. The Broadcom driver have this |
| 13095 | * workaround but turns MWI off all the times so never uses |
| 13096 | * it. This seems to suggest that the workaround is insufficient. |
| 13097 | */ |
| 13098 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13099 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; |
| 13100 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13101 | |
| 13102 | /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL |
| 13103 | * has the register indirect write enable bit set before |
| 13104 | * we try to access any of the MMIO registers. It is also |
| 13105 | * critical that the PCI-X hw workaround situation is decided |
| 13106 | * before that as well. |
| 13107 | */ |
| 13108 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 13109 | &misc_ctrl_reg); |
| 13110 | |
| 13111 | tp->pci_chip_rev_id = (misc_ctrl_reg >> |
| 13112 | MISC_HOST_CTRL_CHIPREV_SHIFT); |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 13113 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
| 13114 | u32 prod_id_asic_rev; |
| 13115 | |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 13116 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 13117 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13118 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13119 | pci_read_config_dword(tp->pdev, |
| 13120 | TG3PCI_GEN2_PRODID_ASICREV, |
| 13121 | &prod_id_asic_rev); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13122 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
| 13123 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || |
| 13124 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || |
| 13125 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || |
| 13126 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 13127 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 13128 | pci_read_config_dword(tp->pdev, |
| 13129 | TG3PCI_GEN15_PRODID_ASICREV, |
| 13130 | &prod_id_asic_rev); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13131 | else |
| 13132 | pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV, |
| 13133 | &prod_id_asic_rev); |
| 13134 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13135 | tp->pci_chip_rev_id = prod_id_asic_rev; |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 13136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13137 | |
Michael Chan | ff645be | 2005-04-21 17:09:53 -0700 | [diff] [blame] | 13138 | /* Wrong chip ID in 5752 A0. This code can be removed later |
| 13139 | * as A0 is not in production. |
| 13140 | */ |
| 13141 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) |
| 13142 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
| 13143 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13144 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
| 13145 | * we need to disable memory and use config. cycles |
| 13146 | * only to access all registers. The 5702/03 chips |
| 13147 | * can mistakenly decode the special cycles from the |
| 13148 | * ICH chipsets as memory write cycles, causing corruption |
| 13149 | * of register and memory space. Only certain ICH bridges |
| 13150 | * will drive special cycles with non-zero data during the |
| 13151 | * address phase which can fall within the 5703's address |
| 13152 | * range. This is not an ICH bug as the PCI spec allows |
| 13153 | * non-zero address during special cycles. However, only |
| 13154 | * these ICH bridges are known to drive non-zero addresses |
| 13155 | * during special cycles. |
| 13156 | * |
| 13157 | * Since special cycles do not cross PCI bridges, we only |
| 13158 | * enable this workaround if the 5703 is on the secondary |
| 13159 | * bus of these ICH bridges. |
| 13160 | */ |
| 13161 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || |
| 13162 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { |
| 13163 | static struct tg3_dev_id { |
| 13164 | u32 vendor; |
| 13165 | u32 device; |
| 13166 | u32 rev; |
| 13167 | } ich_chipsets[] = { |
| 13168 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, |
| 13169 | PCI_ANY_ID }, |
| 13170 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, |
| 13171 | PCI_ANY_ID }, |
| 13172 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, |
| 13173 | 0xa }, |
| 13174 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, |
| 13175 | PCI_ANY_ID }, |
| 13176 | { }, |
| 13177 | }; |
| 13178 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; |
| 13179 | struct pci_dev *bridge = NULL; |
| 13180 | |
| 13181 | while (pci_id->vendor != 0) { |
| 13182 | bridge = pci_get_device(pci_id->vendor, pci_id->device, |
| 13183 | bridge); |
| 13184 | if (!bridge) { |
| 13185 | pci_id++; |
| 13186 | continue; |
| 13187 | } |
| 13188 | if (pci_id->rev != PCI_ANY_ID) { |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 13189 | if (bridge->revision > pci_id->rev) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13190 | continue; |
| 13191 | } |
| 13192 | if (bridge->subordinate && |
| 13193 | (bridge->subordinate->number == |
| 13194 | tp->pdev->bus->number)) { |
| 13195 | |
| 13196 | tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND; |
| 13197 | pci_dev_put(bridge); |
| 13198 | break; |
| 13199 | } |
| 13200 | } |
| 13201 | } |
| 13202 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 13203 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 13204 | static struct tg3_dev_id { |
| 13205 | u32 vendor; |
| 13206 | u32 device; |
| 13207 | } bridge_chipsets[] = { |
| 13208 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, |
| 13209 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, |
| 13210 | { }, |
| 13211 | }; |
| 13212 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; |
| 13213 | struct pci_dev *bridge = NULL; |
| 13214 | |
| 13215 | while (pci_id->vendor != 0) { |
| 13216 | bridge = pci_get_device(pci_id->vendor, |
| 13217 | pci_id->device, |
| 13218 | bridge); |
| 13219 | if (!bridge) { |
| 13220 | pci_id++; |
| 13221 | continue; |
| 13222 | } |
| 13223 | if (bridge->subordinate && |
| 13224 | (bridge->subordinate->number <= |
| 13225 | tp->pdev->bus->number) && |
| 13226 | (bridge->subordinate->subordinate >= |
| 13227 | tp->pdev->bus->number)) { |
| 13228 | tp->tg3_flags3 |= TG3_FLG3_5701_DMA_BUG; |
| 13229 | pci_dev_put(bridge); |
| 13230 | break; |
| 13231 | } |
| 13232 | } |
| 13233 | } |
| 13234 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13235 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
| 13236 | * DMA addresses > 40-bit. This bridge may have other additional |
| 13237 | * 57xx devices behind it in some 4-port NIC designs for example. |
| 13238 | * Any tg3 device found behind the bridge will also need the 40-bit |
| 13239 | * DMA workaround. |
| 13240 | */ |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13241 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
| 13242 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 13243 | tp->tg3_flags2 |= TG3_FLG2_5780_CLASS; |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13244 | tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG; |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 13245 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 13246 | } else { |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13247 | struct pci_dev *bridge = NULL; |
| 13248 | |
| 13249 | do { |
| 13250 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, |
| 13251 | PCI_DEVICE_ID_SERVERWORKS_EPB, |
| 13252 | bridge); |
| 13253 | if (bridge && bridge->subordinate && |
| 13254 | (bridge->subordinate->number <= |
| 13255 | tp->pdev->bus->number) && |
| 13256 | (bridge->subordinate->subordinate >= |
| 13257 | tp->pdev->bus->number)) { |
| 13258 | tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG; |
| 13259 | pci_dev_put(bridge); |
| 13260 | break; |
| 13261 | } |
| 13262 | } while (bridge); |
| 13263 | } |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 13264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13265 | /* Initialize misc host control in PCI block. */ |
| 13266 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
| 13267 | MISC_HOST_CTRL_CHIPREV); |
| 13268 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 13269 | tp->misc_host_ctrl); |
| 13270 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13271 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 13272 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || |
| 13273 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13274 | tp->pdev_peer = tg3_find_peer(tp); |
| 13275 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13276 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13277 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
| 13278 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 13279 | tp->tg3_flags3 |= TG3_FLG3_5717_PLUS; |
| 13280 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13281 | /* Intentionally exclude ASIC_REV_5906 */ |
| 13282 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 13283 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13284 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13285 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13286 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13287 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13288 | (tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13289 | tp->tg3_flags3 |= TG3_FLG3_5755_PLUS; |
| 13290 | |
| 13291 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 13292 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13293 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13294 | (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13295 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
John W. Linville | 6708e5c | 2005-04-21 17:00:52 -0700 | [diff] [blame] | 13296 | tp->tg3_flags2 |= TG3_FLG2_5750_PLUS; |
| 13297 | |
John W. Linville | 1b440c56 | 2005-04-21 17:03:18 -0700 | [diff] [blame] | 13298 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) || |
| 13299 | (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) |
| 13300 | tp->tg3_flags2 |= TG3_FLG2_5705_PLUS; |
| 13301 | |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13302 | /* 5700 B0 chips do not support checksumming correctly due |
| 13303 | * to hardware bugs. |
| 13304 | */ |
| 13305 | if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0) |
| 13306 | tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS; |
| 13307 | else { |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 13308 | unsigned long features = NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_GRO; |
| 13309 | |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13310 | tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13311 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 13312 | features |= NETIF_F_IPV6_CSUM; |
| 13313 | tp->dev->features |= features; |
| 13314 | vlan_features_add(tp->dev, features); |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13315 | } |
| 13316 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13317 | /* Determine TSO capabilities */ |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13318 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 13319 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_3; |
| 13320 | else if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
| 13321 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13322 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2; |
| 13323 | else if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
| 13324 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG; |
| 13325 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && |
| 13326 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) |
| 13327 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG; |
| 13328 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13329 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 13330 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
| 13331 | tp->tg3_flags2 |= TG3_FLG2_TSO_BUG; |
| 13332 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) |
| 13333 | tp->fw_needed = FIRMWARE_TG3TSO5; |
| 13334 | else |
| 13335 | tp->fw_needed = FIRMWARE_TG3TSO; |
| 13336 | } |
| 13337 | |
| 13338 | tp->irq_max = 1; |
| 13339 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 13340 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13341 | tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI; |
| 13342 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || |
| 13343 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || |
| 13344 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && |
| 13345 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && |
| 13346 | tp->pdev_peer == tp->pdev)) |
| 13347 | tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI; |
| 13348 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13349 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13350 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 13351 | tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 13352 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13353 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13354 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13355 | tp->tg3_flags |= TG3_FLAG_SUPPORT_MSIX; |
| 13356 | tp->irq_max = TG3_IRQ_MAX_VECS; |
| 13357 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13358 | } |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 13359 | |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 13360 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13361 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 13362 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 13363 | tp->tg3_flags3 |= TG3_FLG3_SHORT_DMA_BUG; |
| 13364 | else if (!(tp->tg3_flags3 & TG3_FLG3_5755_PLUS)) { |
| 13365 | tp->tg3_flags3 |= TG3_FLG3_4G_DMA_BNDRY_BUG; |
| 13366 | tp->tg3_flags3 |= TG3_FLG3_40BIT_DMA_LIMIT_BUG; |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 13367 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13368 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13369 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13370 | tp->tg3_flags3 |= TG3_FLG3_USE_JUMBO_BDFLAG; |
| 13371 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 13372 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
Matt Carlson | c6cdf43 | 2010-04-05 10:19:26 +0000 | [diff] [blame] | 13373 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
| 13374 | (tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG)) |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 13375 | tp->tg3_flags |= TG3_FLAG_JUMBO_CAPABLE; |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 13376 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13377 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13378 | &pci_state_reg); |
| 13379 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13380 | tp->pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP); |
| 13381 | if (tp->pcie_cap != 0) { |
| 13382 | u16 lnkctl; |
| 13383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13384 | tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS; |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 13385 | |
Matt Carlson | cf79003 | 2010-11-24 08:31:48 +0000 | [diff] [blame] | 13386 | tp->pcie_readrq = 4096; |
| 13387 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
| 13388 | u16 word; |
| 13389 | |
| 13390 | pci_read_config_word(tp->pdev, |
| 13391 | tp->pcie_cap + PCI_EXP_LNKSTA, |
| 13392 | &word); |
| 13393 | switch (word & PCI_EXP_LNKSTA_CLS) { |
| 13394 | case PCI_EXP_LNKSTA_CLS_2_5GB: |
| 13395 | word &= PCI_EXP_LNKSTA_NLW; |
| 13396 | word >>= PCI_EXP_LNKSTA_NLW_SHIFT; |
| 13397 | switch (word) { |
| 13398 | case 2: |
| 13399 | tp->pcie_readrq = 2048; |
| 13400 | break; |
| 13401 | case 4: |
| 13402 | tp->pcie_readrq = 1024; |
| 13403 | break; |
| 13404 | } |
| 13405 | break; |
| 13406 | |
| 13407 | case PCI_EXP_LNKSTA_CLS_5_0GB: |
| 13408 | word &= PCI_EXP_LNKSTA_NLW; |
| 13409 | word >>= PCI_EXP_LNKSTA_NLW_SHIFT; |
| 13410 | switch (word) { |
| 13411 | case 1: |
| 13412 | tp->pcie_readrq = 2048; |
| 13413 | break; |
| 13414 | case 2: |
| 13415 | tp->pcie_readrq = 1024; |
| 13416 | break; |
| 13417 | case 4: |
| 13418 | tp->pcie_readrq = 512; |
| 13419 | break; |
| 13420 | } |
| 13421 | } |
| 13422 | } |
| 13423 | |
| 13424 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 13425 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13426 | pci_read_config_word(tp->pdev, |
| 13427 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 13428 | &lnkctl); |
| 13429 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
| 13430 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 13431 | tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13432 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13433 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 9cf74eb | 2009-04-20 06:58:27 +0000 | [diff] [blame] | 13434 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
| 13435 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13436 | tp->tg3_flags3 |= TG3_FLG3_CLKREQ_BUG; |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 13437 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
| 13438 | tp->tg3_flags3 |= TG3_FLG3_L1PLLPD_EN; |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 13439 | } |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13440 | } 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] | 13441 | tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS; |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13442 | } else if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
| 13443 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
| 13444 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
| 13445 | if (!tp->pcix_cap) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 13446 | dev_err(&tp->pdev->dev, |
| 13447 | "Cannot find PCI-X capability, aborting\n"); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13448 | return -EIO; |
| 13449 | } |
| 13450 | |
| 13451 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) |
| 13452 | tp->tg3_flags |= TG3_FLAG_PCIX_MODE; |
| 13453 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13454 | |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 13455 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
| 13456 | * reordering to the mailbox registers done by the host |
| 13457 | * controller can cause major troubles. We read back from |
| 13458 | * every mailbox register write to force the writes to be |
| 13459 | * posted to the chip in order. |
| 13460 | */ |
| 13461 | if (pci_dev_present(write_reorder_chipsets) && |
| 13462 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) |
| 13463 | tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER; |
| 13464 | |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 13465 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 13466 | &tp->pci_cacheline_sz); |
| 13467 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 13468 | &tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13469 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 13470 | tp->pci_lat_timer < 64) { |
| 13471 | tp->pci_lat_timer = 64; |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 13472 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 13473 | tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13474 | } |
| 13475 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13476 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
| 13477 | /* 5700 BX chips need to have their TX producer index |
| 13478 | * mailboxes written twice to workaround a bug. |
| 13479 | */ |
| 13480 | tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13481 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13482 | /* If we are in PCI-X mode, enable register write workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13483 | * |
| 13484 | * The workaround is to use indirect register accesses |
| 13485 | * for all chip writes not to mailbox registers. |
| 13486 | */ |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13487 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13488 | u32 pm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13489 | |
| 13490 | tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG; |
| 13491 | |
| 13492 | /* The chip can have it's power management PCI config |
| 13493 | * space registers clobbered due to this bug. |
| 13494 | * So explicitly force the chip into D0 here. |
| 13495 | */ |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13496 | pci_read_config_dword(tp->pdev, |
| 13497 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13498 | &pm_reg); |
| 13499 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; |
| 13500 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13501 | pci_write_config_dword(tp->pdev, |
| 13502 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13503 | pm_reg); |
| 13504 | |
| 13505 | /* Also, force SERR#/PERR# in PCI command. */ |
| 13506 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13507 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
| 13508 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13509 | } |
| 13510 | } |
| 13511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13512 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
| 13513 | tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED; |
| 13514 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
| 13515 | tp->tg3_flags |= TG3_FLAG_PCI_32BIT; |
| 13516 | |
| 13517 | /* Chip-specific fixup from Broadcom driver */ |
| 13518 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && |
| 13519 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
| 13520 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; |
| 13521 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); |
| 13522 | } |
| 13523 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13524 | /* Default fast path register access methods */ |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13525 | tp->read32 = tg3_read32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13526 | tp->write32 = tg3_write32; |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 13527 | tp->read32_mbox = tg3_read32; |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13528 | tp->write32_mbox = tg3_write32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13529 | tp->write32_tx_mbox = tg3_write32; |
| 13530 | tp->write32_rx_mbox = tg3_write32; |
| 13531 | |
| 13532 | /* Various workaround register access methods */ |
| 13533 | if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) |
| 13534 | tp->write32 = tg3_write_indirect_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 13535 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 || |
| 13536 | ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && |
| 13537 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { |
| 13538 | /* |
| 13539 | * Back to back register writes can cause problems on these |
| 13540 | * chips, the workaround is to read back all reg writes |
| 13541 | * except those to mailbox regs. |
| 13542 | * |
| 13543 | * See tg3_write_indirect_reg32(). |
| 13544 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13545 | tp->write32 = tg3_write_flush_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 13546 | } |
| 13547 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13548 | if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) || |
| 13549 | (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) { |
| 13550 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 13551 | if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) |
| 13552 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 13553 | } |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13554 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13555 | if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) { |
| 13556 | tp->read32 = tg3_read_indirect_reg32; |
| 13557 | tp->write32 = tg3_write_indirect_reg32; |
| 13558 | tp->read32_mbox = tg3_read_indirect_mbox; |
| 13559 | tp->write32_mbox = tg3_write_indirect_mbox; |
| 13560 | tp->write32_tx_mbox = tg3_write_indirect_mbox; |
| 13561 | tp->write32_rx_mbox = tg3_write_indirect_mbox; |
| 13562 | |
| 13563 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 13564 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13565 | |
| 13566 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13567 | pci_cmd &= ~PCI_COMMAND_MEMORY; |
| 13568 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13569 | } |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13570 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 13571 | tp->read32_mbox = tg3_read32_mbox_5906; |
| 13572 | tp->write32_mbox = tg3_write32_mbox_5906; |
| 13573 | tp->write32_tx_mbox = tg3_write32_mbox_5906; |
| 13574 | tp->write32_rx_mbox = tg3_write32_mbox_5906; |
| 13575 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13576 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 13577 | if (tp->write32 == tg3_write_indirect_reg32 || |
| 13578 | ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) && |
| 13579 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 13580 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 13581 | tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG; |
| 13582 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13583 | /* Get eeprom hw config before calling tg3_set_power_state(). |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13584 | * In particular, the TG3_FLG2_IS_NIC flag must be |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13585 | * determined before calling tg3_set_power_state() so that |
| 13586 | * we know whether or not to switch out of Vaux power. |
| 13587 | * When the flag is set, it means that GPIO1 is used for eeprom |
| 13588 | * write protect and also implies that it is a LOM where GPIOs |
| 13589 | * are not used to switch power. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13590 | */ |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13591 | tg3_get_eeprom_hw_cfg(tp); |
| 13592 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 13593 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
| 13594 | /* Allow reads and writes to the |
| 13595 | * APE register and memory space. |
| 13596 | */ |
| 13597 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
Matt Carlson | f92d9dc1 | 2010-06-05 17:24:30 +0000 | [diff] [blame] | 13598 | PCISTATE_ALLOW_APE_SHMEM_WR | |
| 13599 | PCISTATE_ALLOW_APE_PSPACE_WR; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 13600 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13601 | pci_state_reg); |
| 13602 | } |
| 13603 | |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13604 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13605 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13606 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13607 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13608 | (tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13609 | tp->tg3_flags |= TG3_FLAG_CPMU_PRESENT; |
| 13610 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 13611 | /* Set up tp->grc_local_ctrl before calling tg3_set_power_state(). |
| 13612 | * GPIO1 driven high will bring 5700's external PHY out of reset. |
| 13613 | * It is also used as eeprom write protect on LOMs. |
| 13614 | */ |
| 13615 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; |
| 13616 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || |
| 13617 | (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)) |
| 13618 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 13619 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 13620 | /* Unused GPIO3 must be driven as output on 5752 because there |
| 13621 | * are no pull-up resistors on unused GPIO pins. |
| 13622 | */ |
| 13623 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 13624 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 13625 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13626 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | cb4ed1f | 2010-01-20 16:58:09 +0000 | [diff] [blame] | 13627 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 13628 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 13629 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 13630 | |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 13631 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 13632 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 13633 | /* Turn off the debug UART. */ |
| 13634 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 13635 | if (tp->tg3_flags2 & TG3_FLG2_IS_NIC) |
| 13636 | /* Keep VMain power. */ |
| 13637 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 13638 | GRC_LCLCTRL_GPIO_OUTPUT0; |
| 13639 | } |
| 13640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13641 | /* Force the chip into D0. */ |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 13642 | err = tg3_set_power_state(tp, PCI_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13643 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 13644 | dev_err(&tp->pdev->dev, "Transition to D0 failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13645 | return err; |
| 13646 | } |
| 13647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13648 | /* Derive initial jumbo mode from MTU assigned in |
| 13649 | * ether_setup() via the alloc_etherdev() call |
| 13650 | */ |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 13651 | if (tp->dev->mtu > ETH_DATA_LEN && |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13652 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 13653 | tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13654 | |
| 13655 | /* Determine WakeOnLan speed to use. */ |
| 13656 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 13657 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 13658 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || |
| 13659 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { |
| 13660 | tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB); |
| 13661 | } else { |
| 13662 | tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB; |
| 13663 | } |
| 13664 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 13665 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13666 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 13667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13668 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
| 13669 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || |
| 13670 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
| 13671 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13672 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13673 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
| 13674 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 13675 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13676 | |
| 13677 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || |
| 13678 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13679 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13680 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13681 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13682 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13683 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13684 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13685 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13686 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 13687 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 13688 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13689 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13690 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 13691 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
Michael Chan | d4011ad | 2007-02-13 12:17:25 -0800 | [diff] [blame] | 13692 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
| 13693 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13694 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 13695 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13696 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13697 | } else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13698 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 13699 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13700 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 13701 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 13702 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 13703 | tp->phy_otp = tg3_read_otp_phycfg(tp); |
| 13704 | if (tp->phy_otp == 0) |
| 13705 | tp->phy_otp = TG3_OTP_DEFAULT; |
| 13706 | } |
| 13707 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 13708 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 13709 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
| 13710 | else |
| 13711 | tp->mi_mode = MAC_MI_MODE_BASE; |
| 13712 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13713 | tp->coalesce_mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13714 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
| 13715 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) |
| 13716 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
| 13717 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13718 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 13719 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13720 | tp->tg3_flags3 |= TG3_FLG3_USE_PHYLIB; |
| 13721 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 13722 | err = tg3_mdio_init(tp); |
| 13723 | if (err) |
| 13724 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13725 | |
| 13726 | /* Initialize data/descriptor byte/word swapping. */ |
| 13727 | val = tr32(GRC_MODE); |
| 13728 | val &= GRC_MODE_HOST_STACKUP; |
| 13729 | tw32(GRC_MODE, val | tp->grc_mode); |
| 13730 | |
| 13731 | tg3_switch_clocks(tp); |
| 13732 | |
| 13733 | /* Clear this out for sanity. */ |
| 13734 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 13735 | |
| 13736 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13737 | &pci_state_reg); |
| 13738 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && |
| 13739 | (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) { |
| 13740 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); |
| 13741 | |
| 13742 | if (chiprevid == CHIPREV_ID_5701_A0 || |
| 13743 | chiprevid == CHIPREV_ID_5701_B0 || |
| 13744 | chiprevid == CHIPREV_ID_5701_B2 || |
| 13745 | chiprevid == CHIPREV_ID_5701_B5) { |
| 13746 | void __iomem *sram_base; |
| 13747 | |
| 13748 | /* Write some dummy words into the SRAM status block |
| 13749 | * area, see if it reads back correctly. If the return |
| 13750 | * value is bad, force enable the PCIX workaround. |
| 13751 | */ |
| 13752 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; |
| 13753 | |
| 13754 | writel(0x00000000, sram_base); |
| 13755 | writel(0x00000000, sram_base + 4); |
| 13756 | writel(0xffffffff, sram_base + 4); |
| 13757 | if (readl(sram_base) != 0x00000000) |
| 13758 | tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG; |
| 13759 | } |
| 13760 | } |
| 13761 | |
| 13762 | udelay(50); |
| 13763 | tg3_nvram_init(tp); |
| 13764 | |
| 13765 | grc_misc_cfg = tr32(GRC_MISC_CFG); |
| 13766 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; |
| 13767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13768 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 13769 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
| 13770 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) |
| 13771 | tp->tg3_flags2 |= TG3_FLG2_IS_5788; |
| 13772 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 13773 | if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) && |
| 13774 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)) |
| 13775 | tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS; |
| 13776 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) { |
| 13777 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
| 13778 | HOSTCC_MODE_CLRTICK_TXBD); |
| 13779 | |
| 13780 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; |
| 13781 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 13782 | tp->misc_host_ctrl); |
| 13783 | } |
| 13784 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 13785 | /* Preserve the APE MAC_MODE bits */ |
| 13786 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
Matt Carlson | d2394e6b | 2010-11-24 08:31:47 +0000 | [diff] [blame] | 13787 | tp->mac_mode = MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 13788 | else |
| 13789 | tp->mac_mode = TG3_DEF_MAC_MODE; |
| 13790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13791 | /* these are limited to 10/100 only */ |
| 13792 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 13793 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || |
| 13794 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 13795 | tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 13796 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 || |
| 13797 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 || |
| 13798 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) || |
| 13799 | (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 13800 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F || |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 13801 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F || |
| 13802 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13803 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790 || |
Matt Carlson | d110114 | 2010-02-17 15:16:55 +0000 | [diff] [blame] | 13804 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 13805 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13806 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
| 13807 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13808 | |
| 13809 | err = tg3_phy_probe(tp); |
| 13810 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 13811 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13812 | /* ... but do not return immediately ... */ |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13813 | tg3_mdio_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13814 | } |
| 13815 | |
Matt Carlson | 184b890 | 2010-04-05 10:19:25 +0000 | [diff] [blame] | 13816 | tg3_read_vpd(tp); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13817 | tg3_read_fw_ver(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13818 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13819 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 13820 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13821 | } else { |
| 13822 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13823 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13824 | else |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13825 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13826 | } |
| 13827 | |
| 13828 | /* 5700 {AX,BX} chips have a broken status block link |
| 13829 | * change bit implementation, so we must use the |
| 13830 | * status register in those cases. |
| 13831 | */ |
| 13832 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
| 13833 | tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG; |
| 13834 | else |
| 13835 | tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG; |
| 13836 | |
| 13837 | /* The led_ctrl is set during tg3_phy_probe, here we might |
| 13838 | * have to force the link status polling mechanism based |
| 13839 | * upon subsystem IDs. |
| 13840 | */ |
| 13841 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
Michael Chan | 007a880d | 2007-05-31 14:49:51 -0700 | [diff] [blame] | 13842 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13843 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 13844 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
| 13845 | tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13846 | } |
| 13847 | |
| 13848 | /* For all SERDES we poll the MAC status register. */ |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 13849 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13850 | tp->tg3_flags |= TG3_FLAG_POLL_SERDES; |
| 13851 | else |
| 13852 | tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES; |
| 13853 | |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 13854 | tp->rx_offset = NET_IP_ALIGN + TG3_RX_HEADROOM; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 13855 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13856 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 13857 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) { |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 13858 | tp->rx_offset -= NET_IP_ALIGN; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 13859 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
Matt Carlson | 9dc7a11 | 2010-04-12 06:58:28 +0000 | [diff] [blame] | 13860 | tp->rx_copy_thresh = ~(u16)0; |
Matt Carlson | d2757fc | 2010-04-12 06:58:27 +0000 | [diff] [blame] | 13861 | #endif |
| 13862 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13863 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 13864 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
| 13865 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; |
Matt Carlson | 7cb32cf | 2010-09-30 10:34:36 +0000 | [diff] [blame] | 13866 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
| 13867 | |
Matt Carlson | 2c49a44 | 2010-09-30 10:34:35 +0000 | [diff] [blame] | 13868 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 13869 | |
| 13870 | /* Increment the rx prod index on the rx std ring by at most |
| 13871 | * 8 for these chips to workaround hw errata. |
| 13872 | */ |
| 13873 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 13874 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 13875 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 13876 | tp->rx_std_max_post = 8; |
| 13877 | |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13878 | if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) |
| 13879 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
| 13880 | PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 13881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13882 | return err; |
| 13883 | } |
| 13884 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13885 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13886 | static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp) |
| 13887 | { |
| 13888 | struct net_device *dev = tp->dev; |
| 13889 | struct pci_dev *pdev = tp->pdev; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13890 | struct device_node *dp = pci_device_to_OF_node(pdev); |
David S. Miller | 374d4ca | 2007-03-29 01:57:57 -0700 | [diff] [blame] | 13891 | const unsigned char *addr; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13892 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13893 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13894 | addr = of_get_property(dp, "local-mac-address", &len); |
| 13895 | if (addr && len == 6) { |
| 13896 | memcpy(dev->dev_addr, addr, 6); |
| 13897 | memcpy(dev->perm_addr, dev->dev_addr, 6); |
| 13898 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13899 | } |
| 13900 | return -ENODEV; |
| 13901 | } |
| 13902 | |
| 13903 | static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp) |
| 13904 | { |
| 13905 | struct net_device *dev = tp->dev; |
| 13906 | |
| 13907 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 13908 | memcpy(dev->perm_addr, idprom->id_ethaddr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13909 | return 0; |
| 13910 | } |
| 13911 | #endif |
| 13912 | |
| 13913 | static int __devinit tg3_get_device_address(struct tg3 *tp) |
| 13914 | { |
| 13915 | struct net_device *dev = tp->dev; |
| 13916 | u32 hi, lo, mac_offset; |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 13917 | int addr_ok = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13918 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13919 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13920 | if (!tg3_get_macaddr_sparc(tp)) |
| 13921 | return 0; |
| 13922 | #endif |
| 13923 | |
| 13924 | mac_offset = 0x7c; |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 13925 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) || |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13926 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13927 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 13928 | mac_offset = 0xcc; |
| 13929 | if (tg3_nvram_lock(tp)) |
| 13930 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); |
| 13931 | else |
| 13932 | tg3_nvram_unlock(tp); |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13933 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13934 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { |
| 13935 | if (PCI_FUNC(tp->pdev->devfn) & 1) |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13936 | mac_offset = 0xcc; |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 13937 | if (PCI_FUNC(tp->pdev->devfn) > 1) |
| 13938 | mac_offset += 0x18c; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13939 | } 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] | 13940 | mac_offset = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13941 | |
| 13942 | /* First try to get it from MAC address mailbox. */ |
| 13943 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); |
| 13944 | if ((hi >> 16) == 0x484b) { |
| 13945 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 13946 | dev->dev_addr[1] = (hi >> 0) & 0xff; |
| 13947 | |
| 13948 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); |
| 13949 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 13950 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 13951 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 13952 | dev->dev_addr[5] = (lo >> 0) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13953 | |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 13954 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
| 13955 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); |
| 13956 | } |
| 13957 | if (!addr_ok) { |
| 13958 | /* Next, try NVRAM. */ |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 13959 | if (!(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) && |
| 13960 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 13961 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 13962 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
| 13963 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 13964 | } |
| 13965 | /* Finally just fetch it out of the MAC control regs. */ |
| 13966 | else { |
| 13967 | hi = tr32(MAC_ADDR_0_HIGH); |
| 13968 | lo = tr32(MAC_ADDR_0_LOW); |
| 13969 | |
| 13970 | dev->dev_addr[5] = lo & 0xff; |
| 13971 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 13972 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 13973 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 13974 | dev->dev_addr[1] = hi & 0xff; |
| 13975 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 13976 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13977 | } |
| 13978 | |
| 13979 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { |
David S. Miller | 7582a33 | 2008-03-20 15:53:15 -0700 | [diff] [blame] | 13980 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13981 | if (!tg3_get_default_macaddr_sparc(tp)) |
| 13982 | return 0; |
| 13983 | #endif |
| 13984 | return -EINVAL; |
| 13985 | } |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 13986 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13987 | return 0; |
| 13988 | } |
| 13989 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 13990 | #define BOUNDARY_SINGLE_CACHELINE 1 |
| 13991 | #define BOUNDARY_MULTI_CACHELINE 2 |
| 13992 | |
| 13993 | static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
| 13994 | { |
| 13995 | int cacheline_size; |
| 13996 | u8 byte; |
| 13997 | int goal; |
| 13998 | |
| 13999 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); |
| 14000 | if (byte == 0) |
| 14001 | cacheline_size = 1024; |
| 14002 | else |
| 14003 | cacheline_size = (int) byte * 4; |
| 14004 | |
| 14005 | /* On 5703 and later chips, the boundary bits have no |
| 14006 | * effect. |
| 14007 | */ |
| 14008 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14009 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 14010 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) |
| 14011 | goto out; |
| 14012 | |
| 14013 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) |
| 14014 | goal = BOUNDARY_MULTI_CACHELINE; |
| 14015 | #else |
| 14016 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) |
| 14017 | goal = BOUNDARY_SINGLE_CACHELINE; |
| 14018 | #else |
| 14019 | goal = 0; |
| 14020 | #endif |
| 14021 | #endif |
| 14022 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 14023 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14024 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 14025 | goto out; |
| 14026 | } |
| 14027 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14028 | if (!goal) |
| 14029 | goto out; |
| 14030 | |
| 14031 | /* PCI controllers on most RISC systems tend to disconnect |
| 14032 | * when a device tries to burst across a cache-line boundary. |
| 14033 | * Therefore, letting tg3 do so just wastes PCI bandwidth. |
| 14034 | * |
| 14035 | * Unfortunately, for PCI-E there are only limited |
| 14036 | * write-side controls for this, and thus for reads |
| 14037 | * we will still get the disconnects. We'll also waste |
| 14038 | * these PCI cycles for both read and write for chips |
| 14039 | * other than 5700 and 5701 which do not implement the |
| 14040 | * boundary bits. |
| 14041 | */ |
| 14042 | if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) && |
| 14043 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) { |
| 14044 | switch (cacheline_size) { |
| 14045 | case 16: |
| 14046 | case 32: |
| 14047 | case 64: |
| 14048 | case 128: |
| 14049 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14050 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | |
| 14051 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); |
| 14052 | } else { |
| 14053 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 14054 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 14055 | } |
| 14056 | break; |
| 14057 | |
| 14058 | case 256: |
| 14059 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | |
| 14060 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); |
| 14061 | break; |
| 14062 | |
| 14063 | default: |
| 14064 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 14065 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 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 | } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 14069 | switch (cacheline_size) { |
| 14070 | case 16: |
| 14071 | case 32: |
| 14072 | case 64: |
| 14073 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14074 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 14075 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; |
| 14076 | break; |
| 14077 | } |
| 14078 | /* fallthrough */ |
| 14079 | case 128: |
| 14080 | default: |
| 14081 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 14082 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; |
| 14083 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14084 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14085 | } else { |
| 14086 | switch (cacheline_size) { |
| 14087 | case 16: |
| 14088 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14089 | val |= (DMA_RWCTRL_READ_BNDRY_16 | |
| 14090 | DMA_RWCTRL_WRITE_BNDRY_16); |
| 14091 | break; |
| 14092 | } |
| 14093 | /* fallthrough */ |
| 14094 | case 32: |
| 14095 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14096 | val |= (DMA_RWCTRL_READ_BNDRY_32 | |
| 14097 | DMA_RWCTRL_WRITE_BNDRY_32); |
| 14098 | break; |
| 14099 | } |
| 14100 | /* fallthrough */ |
| 14101 | case 64: |
| 14102 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14103 | val |= (DMA_RWCTRL_READ_BNDRY_64 | |
| 14104 | DMA_RWCTRL_WRITE_BNDRY_64); |
| 14105 | break; |
| 14106 | } |
| 14107 | /* fallthrough */ |
| 14108 | case 128: |
| 14109 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 14110 | val |= (DMA_RWCTRL_READ_BNDRY_128 | |
| 14111 | DMA_RWCTRL_WRITE_BNDRY_128); |
| 14112 | break; |
| 14113 | } |
| 14114 | /* fallthrough */ |
| 14115 | case 256: |
| 14116 | val |= (DMA_RWCTRL_READ_BNDRY_256 | |
| 14117 | DMA_RWCTRL_WRITE_BNDRY_256); |
| 14118 | break; |
| 14119 | case 512: |
| 14120 | val |= (DMA_RWCTRL_READ_BNDRY_512 | |
| 14121 | DMA_RWCTRL_WRITE_BNDRY_512); |
| 14122 | break; |
| 14123 | case 1024: |
| 14124 | default: |
| 14125 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | |
| 14126 | DMA_RWCTRL_WRITE_BNDRY_1024); |
| 14127 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14128 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14129 | } |
| 14130 | |
| 14131 | out: |
| 14132 | return val; |
| 14133 | } |
| 14134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14135 | static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) |
| 14136 | { |
| 14137 | struct tg3_internal_buffer_desc test_desc; |
| 14138 | u32 sram_dma_descs; |
| 14139 | int i, ret; |
| 14140 | |
| 14141 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; |
| 14142 | |
| 14143 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); |
| 14144 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); |
| 14145 | tw32(RDMAC_STATUS, 0); |
| 14146 | tw32(WDMAC_STATUS, 0); |
| 14147 | |
| 14148 | tw32(BUFMGR_MODE, 0); |
| 14149 | tw32(FTQ_RESET, 0); |
| 14150 | |
| 14151 | test_desc.addr_hi = ((u64) buf_dma) >> 32; |
| 14152 | test_desc.addr_lo = buf_dma & 0xffffffff; |
| 14153 | test_desc.nic_mbuf = 0x00002100; |
| 14154 | test_desc.len = size; |
| 14155 | |
| 14156 | /* |
| 14157 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz |
| 14158 | * the *second* time the tg3 driver was getting loaded after an |
| 14159 | * initial scan. |
| 14160 | * |
| 14161 | * Broadcom tells me: |
| 14162 | * ...the DMA engine is connected to the GRC block and a DMA |
| 14163 | * reset may affect the GRC block in some unpredictable way... |
| 14164 | * The behavior of resets to individual blocks has not been tested. |
| 14165 | * |
| 14166 | * Broadcom noted the GRC reset will also reset all sub-components. |
| 14167 | */ |
| 14168 | if (to_device) { |
| 14169 | test_desc.cqid_sqid = (13 << 8) | 2; |
| 14170 | |
| 14171 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); |
| 14172 | udelay(40); |
| 14173 | } else { |
| 14174 | test_desc.cqid_sqid = (16 << 8) | 7; |
| 14175 | |
| 14176 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); |
| 14177 | udelay(40); |
| 14178 | } |
| 14179 | test_desc.flags = 0x00000005; |
| 14180 | |
| 14181 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { |
| 14182 | u32 val; |
| 14183 | |
| 14184 | val = *(((u32 *)&test_desc) + i); |
| 14185 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, |
| 14186 | sram_dma_descs + (i * sizeof(u32))); |
| 14187 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 14188 | } |
| 14189 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 14190 | |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14191 | if (to_device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14192 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14193 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14194 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14195 | |
| 14196 | ret = -ENODEV; |
| 14197 | for (i = 0; i < 40; i++) { |
| 14198 | u32 val; |
| 14199 | |
| 14200 | if (to_device) |
| 14201 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); |
| 14202 | else |
| 14203 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); |
| 14204 | if ((val & 0xffff) == sram_dma_descs) { |
| 14205 | ret = 0; |
| 14206 | break; |
| 14207 | } |
| 14208 | |
| 14209 | udelay(100); |
| 14210 | } |
| 14211 | |
| 14212 | return ret; |
| 14213 | } |
| 14214 | |
David S. Miller | ded7340 | 2005-05-23 13:59:47 -0700 | [diff] [blame] | 14215 | #define TEST_BUFFER_SIZE 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14216 | |
| 14217 | static int __devinit tg3_test_dma(struct tg3 *tp) |
| 14218 | { |
| 14219 | dma_addr_t buf_dma; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14220 | u32 *buf, saved_dma_rwctrl; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14221 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14222 | |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 14223 | buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
| 14224 | &buf_dma, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14225 | if (!buf) { |
| 14226 | ret = -ENOMEM; |
| 14227 | goto out_nofree; |
| 14228 | } |
| 14229 | |
| 14230 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | |
| 14231 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); |
| 14232 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14233 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14234 | |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 14235 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14236 | goto out; |
| 14237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14238 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 14239 | /* DMA read watermark not used on PCIE */ |
| 14240 | tp->dma_rwctrl |= 0x00180000; |
| 14241 | } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) { |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 14242 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 14243 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14244 | tp->dma_rwctrl |= 0x003f0000; |
| 14245 | else |
| 14246 | tp->dma_rwctrl |= 0x003f000f; |
| 14247 | } else { |
| 14248 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 14249 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 14250 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14251 | u32 read_water = 0x7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14252 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14253 | /* If the 5704 is behind the EPB bridge, we can |
| 14254 | * do the less restrictive ONE_DMA workaround for |
| 14255 | * better performance. |
| 14256 | */ |
| 14257 | if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) && |
| 14258 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 14259 | tp->dma_rwctrl |= 0x8000; |
| 14260 | else if (ccval == 0x6 || ccval == 0x7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14261 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 14262 | |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14263 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
| 14264 | read_water = 4; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14265 | /* Set bit 23 to enable PCIX hw bug fix */ |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14266 | tp->dma_rwctrl |= |
| 14267 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | |
| 14268 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | |
| 14269 | (1 << 23); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 14270 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
| 14271 | /* 5780 always in PCIX mode */ |
| 14272 | tp->dma_rwctrl |= 0x00144000; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 14273 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 14274 | /* 5714 always in PCIX mode */ |
| 14275 | tp->dma_rwctrl |= 0x00148000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14276 | } else { |
| 14277 | tp->dma_rwctrl |= 0x001b000f; |
| 14278 | } |
| 14279 | } |
| 14280 | |
| 14281 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 14282 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 14283 | tp->dma_rwctrl &= 0xfffffff0; |
| 14284 | |
| 14285 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 14286 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 14287 | /* Remove this if it causes problems for some boards. */ |
| 14288 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; |
| 14289 | |
| 14290 | /* On 5700/5701 chips, we need to set this bit. |
| 14291 | * Otherwise the chip will issue cacheline transactions |
| 14292 | * to streamable DMA memory with not all the byte |
| 14293 | * enables turned on. This is an error on several |
| 14294 | * RISC PCI controllers, in particular sparc64. |
| 14295 | * |
| 14296 | * On 5703/5704 chips, this bit has been reassigned |
| 14297 | * a different meaning. In particular, it is used |
| 14298 | * on those chips to enable a PCI-X workaround. |
| 14299 | */ |
| 14300 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; |
| 14301 | } |
| 14302 | |
| 14303 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14304 | |
| 14305 | #if 0 |
| 14306 | /* Unneeded, already done by tg3_get_invariants. */ |
| 14307 | tg3_switch_clocks(tp); |
| 14308 | #endif |
| 14309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14310 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14311 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 14312 | goto out; |
| 14313 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14314 | /* It is best to perform DMA test with maximum write burst size |
| 14315 | * to expose the 5700/5701 write DMA bug. |
| 14316 | */ |
| 14317 | saved_dma_rwctrl = tp->dma_rwctrl; |
| 14318 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 14319 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14321 | while (1) { |
| 14322 | u32 *p = buf, i; |
| 14323 | |
| 14324 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) |
| 14325 | p[i] = i; |
| 14326 | |
| 14327 | /* Send the buffer to the chip. */ |
| 14328 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); |
| 14329 | if (ret) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14330 | dev_err(&tp->pdev->dev, |
| 14331 | "%s: Buffer write failed. err = %d\n", |
| 14332 | __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14333 | break; |
| 14334 | } |
| 14335 | |
| 14336 | #if 0 |
| 14337 | /* validate data reached card RAM correctly. */ |
| 14338 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 14339 | u32 val; |
| 14340 | tg3_read_mem(tp, 0x2100 + (i*4), &val); |
| 14341 | if (le32_to_cpu(val) != p[i]) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14342 | dev_err(&tp->pdev->dev, |
| 14343 | "%s: Buffer corrupted on device! " |
| 14344 | "(%d != %d)\n", __func__, val, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14345 | /* ret = -ENODEV here? */ |
| 14346 | } |
| 14347 | p[i] = 0; |
| 14348 | } |
| 14349 | #endif |
| 14350 | /* Now read it back. */ |
| 14351 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); |
| 14352 | if (ret) { |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 14353 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
| 14354 | "err = %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14355 | break; |
| 14356 | } |
| 14357 | |
| 14358 | /* Verify it. */ |
| 14359 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 14360 | if (p[i] == i) |
| 14361 | continue; |
| 14362 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14363 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 14364 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 14365 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14366 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 14367 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14368 | break; |
| 14369 | } else { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14370 | dev_err(&tp->pdev->dev, |
| 14371 | "%s: Buffer corrupted on read back! " |
| 14372 | "(%d != %d)\n", __func__, p[i], i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14373 | ret = -ENODEV; |
| 14374 | goto out; |
| 14375 | } |
| 14376 | } |
| 14377 | |
| 14378 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { |
| 14379 | /* Success. */ |
| 14380 | ret = 0; |
| 14381 | break; |
| 14382 | } |
| 14383 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14384 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 14385 | DMA_RWCTRL_WRITE_BNDRY_16) { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14386 | static struct pci_device_id dma_wait_state_chipsets[] = { |
| 14387 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, |
| 14388 | PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
| 14389 | { }, |
| 14390 | }; |
| 14391 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14392 | /* DMA test passed without adjusting DMA boundary, |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14393 | * now look for chipsets that are known to expose the |
| 14394 | * DMA bug without failing the test. |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14395 | */ |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14396 | if (pci_dev_present(dma_wait_state_chipsets)) { |
| 14397 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 14398 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14399 | } else { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14400 | /* Safe to use the calculated DMA boundary. */ |
| 14401 | tp->dma_rwctrl = saved_dma_rwctrl; |
Matt Carlson | 859a58879 | 2010-04-05 10:19:28 +0000 | [diff] [blame] | 14402 | } |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14403 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14404 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14405 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14406 | |
| 14407 | out: |
Matt Carlson | 4bae65c | 2010-11-24 08:31:52 +0000 | [diff] [blame] | 14408 | dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14409 | out_nofree: |
| 14410 | return ret; |
| 14411 | } |
| 14412 | |
| 14413 | static void __devinit tg3_init_link_config(struct tg3 *tp) |
| 14414 | { |
| 14415 | tp->link_config.advertising = |
| 14416 | (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 14417 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 14418 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full | |
| 14419 | ADVERTISED_Autoneg | ADVERTISED_MII); |
| 14420 | tp->link_config.speed = SPEED_INVALID; |
| 14421 | tp->link_config.duplex = DUPLEX_INVALID; |
| 14422 | tp->link_config.autoneg = AUTONEG_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14423 | tp->link_config.active_speed = SPEED_INVALID; |
| 14424 | tp->link_config.active_duplex = DUPLEX_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14425 | tp->link_config.orig_speed = SPEED_INVALID; |
| 14426 | tp->link_config.orig_duplex = DUPLEX_INVALID; |
| 14427 | tp->link_config.orig_autoneg = AUTONEG_INVALID; |
| 14428 | } |
| 14429 | |
| 14430 | static void __devinit tg3_init_bufmgr_config(struct tg3 *tp) |
| 14431 | { |
Matt Carlson | c885e82 | 2010-08-02 11:25:57 +0000 | [diff] [blame] | 14432 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 14433 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14434 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14435 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14436 | DEFAULT_MB_MACRX_LOW_WATER_57765; |
| 14437 | tp->bufmgr_config.mbuf_high_water = |
| 14438 | DEFAULT_MB_HIGH_WATER_57765; |
| 14439 | |
| 14440 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14441 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14442 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14443 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; |
| 14444 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14445 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; |
| 14446 | } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14447 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14448 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14449 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14450 | DEFAULT_MB_MACRX_LOW_WATER_5705; |
| 14451 | tp->bufmgr_config.mbuf_high_water = |
| 14452 | DEFAULT_MB_HIGH_WATER_5705; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14453 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 14454 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14455 | DEFAULT_MB_MACRX_LOW_WATER_5906; |
| 14456 | tp->bufmgr_config.mbuf_high_water = |
| 14457 | DEFAULT_MB_HIGH_WATER_5906; |
| 14458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14459 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14460 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14461 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; |
| 14462 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14463 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; |
| 14464 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14465 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; |
| 14466 | } else { |
| 14467 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14468 | DEFAULT_MB_RDMA_LOW_WATER; |
| 14469 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14470 | DEFAULT_MB_MACRX_LOW_WATER; |
| 14471 | tp->bufmgr_config.mbuf_high_water = |
| 14472 | DEFAULT_MB_HIGH_WATER; |
| 14473 | |
| 14474 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14475 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; |
| 14476 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14477 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; |
| 14478 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14479 | DEFAULT_MB_HIGH_WATER_JUMBO; |
| 14480 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14481 | |
| 14482 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; |
| 14483 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; |
| 14484 | } |
| 14485 | |
| 14486 | static char * __devinit tg3_phy_string(struct tg3 *tp) |
| 14487 | { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14488 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
| 14489 | case TG3_PHY_ID_BCM5400: return "5400"; |
| 14490 | case TG3_PHY_ID_BCM5401: return "5401"; |
| 14491 | case TG3_PHY_ID_BCM5411: return "5411"; |
| 14492 | case TG3_PHY_ID_BCM5701: return "5701"; |
| 14493 | case TG3_PHY_ID_BCM5703: return "5703"; |
| 14494 | case TG3_PHY_ID_BCM5704: return "5704"; |
| 14495 | case TG3_PHY_ID_BCM5705: return "5705"; |
| 14496 | case TG3_PHY_ID_BCM5750: return "5750"; |
| 14497 | case TG3_PHY_ID_BCM5752: return "5752"; |
| 14498 | case TG3_PHY_ID_BCM5714: return "5714"; |
| 14499 | case TG3_PHY_ID_BCM5780: return "5780"; |
| 14500 | case TG3_PHY_ID_BCM5755: return "5755"; |
| 14501 | case TG3_PHY_ID_BCM5787: return "5787"; |
| 14502 | case TG3_PHY_ID_BCM5784: return "5784"; |
| 14503 | case TG3_PHY_ID_BCM5756: return "5722/5756"; |
| 14504 | case TG3_PHY_ID_BCM5906: return "5906"; |
| 14505 | case TG3_PHY_ID_BCM5761: return "5761"; |
| 14506 | case TG3_PHY_ID_BCM5718C: return "5718C"; |
| 14507 | case TG3_PHY_ID_BCM5718S: return "5718S"; |
| 14508 | case TG3_PHY_ID_BCM57765: return "57765"; |
Matt Carlson | 302b500 | 2010-06-05 17:24:38 +0000 | [diff] [blame] | 14509 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14510 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14511 | case 0: return "serdes"; |
| 14512 | default: return "unknown"; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14513 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14514 | } |
| 14515 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14516 | static char * __devinit tg3_bus_string(struct tg3 *tp, char *str) |
| 14517 | { |
| 14518 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 14519 | strcpy(str, "PCI Express"); |
| 14520 | return str; |
| 14521 | } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
| 14522 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
| 14523 | |
| 14524 | strcpy(str, "PCIX:"); |
| 14525 | |
| 14526 | if ((clock_ctrl == 7) || |
| 14527 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == |
| 14528 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) |
| 14529 | strcat(str, "133MHz"); |
| 14530 | else if (clock_ctrl == 0) |
| 14531 | strcat(str, "33MHz"); |
| 14532 | else if (clock_ctrl == 2) |
| 14533 | strcat(str, "50MHz"); |
| 14534 | else if (clock_ctrl == 4) |
| 14535 | strcat(str, "66MHz"); |
| 14536 | else if (clock_ctrl == 6) |
| 14537 | strcat(str, "100MHz"); |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14538 | } else { |
| 14539 | strcpy(str, "PCI:"); |
| 14540 | if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED) |
| 14541 | strcat(str, "66MHz"); |
| 14542 | else |
| 14543 | strcat(str, "33MHz"); |
| 14544 | } |
| 14545 | if (tp->tg3_flags & TG3_FLAG_PCI_32BIT) |
| 14546 | strcat(str, ":32-bit"); |
| 14547 | else |
| 14548 | strcat(str, ":64-bit"); |
| 14549 | return str; |
| 14550 | } |
| 14551 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 14552 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14553 | { |
| 14554 | struct pci_dev *peer; |
| 14555 | unsigned int func, devnr = tp->pdev->devfn & ~7; |
| 14556 | |
| 14557 | for (func = 0; func < 8; func++) { |
| 14558 | peer = pci_get_slot(tp->pdev->bus, devnr | func); |
| 14559 | if (peer && peer != tp->pdev) |
| 14560 | break; |
| 14561 | pci_dev_put(peer); |
| 14562 | } |
Michael Chan | 16fe9d7 | 2005-12-13 21:09:54 -0800 | [diff] [blame] | 14563 | /* 5704 can be configured in single-port mode, set peer to |
| 14564 | * tp->pdev in that case. |
| 14565 | */ |
| 14566 | if (!peer) { |
| 14567 | peer = tp->pdev; |
| 14568 | return peer; |
| 14569 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14570 | |
| 14571 | /* |
| 14572 | * We don't need to keep the refcount elevated; there's no way |
| 14573 | * to remove one half of this device without removing the other |
| 14574 | */ |
| 14575 | pci_dev_put(peer); |
| 14576 | |
| 14577 | return peer; |
| 14578 | } |
| 14579 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 14580 | static void __devinit tg3_init_coal(struct tg3 *tp) |
| 14581 | { |
| 14582 | struct ethtool_coalesce *ec = &tp->coal; |
| 14583 | |
| 14584 | memset(ec, 0, sizeof(*ec)); |
| 14585 | ec->cmd = ETHTOOL_GCOALESCE; |
| 14586 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; |
| 14587 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; |
| 14588 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; |
| 14589 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; |
| 14590 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; |
| 14591 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; |
| 14592 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; |
| 14593 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; |
| 14594 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; |
| 14595 | |
| 14596 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | |
| 14597 | HOSTCC_MODE_CLRTICK_TXBD)) { |
| 14598 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; |
| 14599 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; |
| 14600 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; |
| 14601 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; |
| 14602 | } |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 14603 | |
| 14604 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 14605 | ec->rx_coalesce_usecs_irq = 0; |
| 14606 | ec->tx_coalesce_usecs_irq = 0; |
| 14607 | ec->stats_block_coalesce_usecs = 0; |
| 14608 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 14609 | } |
| 14610 | |
Stephen Hemminger | 7c7d64b | 2008-11-19 22:25:36 -0800 | [diff] [blame] | 14611 | static const struct net_device_ops tg3_netdev_ops = { |
| 14612 | .ndo_open = tg3_open, |
| 14613 | .ndo_stop = tg3_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14614 | .ndo_start_xmit = tg3_start_xmit, |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 14615 | .ndo_get_stats64 = tg3_get_stats64, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14616 | .ndo_validate_addr = eth_validate_addr, |
| 14617 | .ndo_set_multicast_list = tg3_set_rx_mode, |
| 14618 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 14619 | .ndo_do_ioctl = tg3_ioctl, |
| 14620 | .ndo_tx_timeout = tg3_tx_timeout, |
| 14621 | .ndo_change_mtu = tg3_change_mtu, |
| 14622 | #if TG3_VLAN_TAG_USED |
| 14623 | .ndo_vlan_rx_register = tg3_vlan_rx_register, |
| 14624 | #endif |
| 14625 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 14626 | .ndo_poll_controller = tg3_poll_controller, |
| 14627 | #endif |
| 14628 | }; |
| 14629 | |
| 14630 | static const struct net_device_ops tg3_netdev_ops_dma_bug = { |
| 14631 | .ndo_open = tg3_open, |
| 14632 | .ndo_stop = tg3_close, |
| 14633 | .ndo_start_xmit = tg3_start_xmit_dma_bug, |
Eric Dumazet | 511d222 | 2010-07-07 20:44:24 +0000 | [diff] [blame] | 14634 | .ndo_get_stats64 = tg3_get_stats64, |
Stephen Hemminger | 7c7d64b | 2008-11-19 22:25:36 -0800 | [diff] [blame] | 14635 | .ndo_validate_addr = eth_validate_addr, |
| 14636 | .ndo_set_multicast_list = tg3_set_rx_mode, |
| 14637 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 14638 | .ndo_do_ioctl = tg3_ioctl, |
| 14639 | .ndo_tx_timeout = tg3_tx_timeout, |
| 14640 | .ndo_change_mtu = tg3_change_mtu, |
| 14641 | #if TG3_VLAN_TAG_USED |
| 14642 | .ndo_vlan_rx_register = tg3_vlan_rx_register, |
| 14643 | #endif |
| 14644 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 14645 | .ndo_poll_controller = tg3_poll_controller, |
| 14646 | #endif |
| 14647 | }; |
| 14648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14649 | static int __devinit tg3_init_one(struct pci_dev *pdev, |
| 14650 | const struct pci_device_id *ent) |
| 14651 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14652 | struct net_device *dev; |
| 14653 | struct tg3 *tp; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 14654 | int i, err, pm_cap; |
| 14655 | u32 sndmbx, rcvmbx, intmbx; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14656 | char str[40]; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14657 | u64 dma_mask, persist_dma_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14658 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14659 | printk_once(KERN_INFO "%s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14660 | |
| 14661 | err = pci_enable_device(pdev); |
| 14662 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14663 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14664 | return err; |
| 14665 | } |
| 14666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14667 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 14668 | if (err) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14669 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14670 | goto err_out_disable_pdev; |
| 14671 | } |
| 14672 | |
| 14673 | pci_set_master(pdev); |
| 14674 | |
| 14675 | /* Find power-management capability. */ |
| 14676 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 14677 | if (pm_cap == 0) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14678 | dev_err(&pdev->dev, |
| 14679 | "Cannot find Power Management capability, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14680 | err = -EIO; |
| 14681 | goto err_out_free_res; |
| 14682 | } |
| 14683 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 14684 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14685 | if (!dev) { |
Matt Carlson | 2445e46 | 2010-04-05 10:19:21 +0000 | [diff] [blame] | 14686 | dev_err(&pdev->dev, "Etherdev alloc failed, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14687 | err = -ENOMEM; |
| 14688 | goto err_out_free_res; |
| 14689 | } |
| 14690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14691 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 14692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14693 | #if TG3_VLAN_TAG_USED |
| 14694 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14695 | #endif |
| 14696 | |
| 14697 | tp = netdev_priv(dev); |
| 14698 | tp->pdev = pdev; |
| 14699 | tp->dev = dev; |
| 14700 | tp->pm_cap = pm_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14701 | tp->rx_mode = TG3_DEF_RX_MODE; |
| 14702 | tp->tx_mode = TG3_DEF_TX_MODE; |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 14703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14704 | if (tg3_debug > 0) |
| 14705 | tp->msg_enable = tg3_debug; |
| 14706 | else |
| 14707 | tp->msg_enable = TG3_DEF_MSG_ENABLE; |
| 14708 | |
| 14709 | /* The word/byte swap controls here control register access byte |
| 14710 | * swapping. DMA data byte swapping is controlled in the GRC_MODE |
| 14711 | * setting below. |
| 14712 | */ |
| 14713 | tp->misc_host_ctrl = |
| 14714 | MISC_HOST_CTRL_MASK_PCI_INT | |
| 14715 | MISC_HOST_CTRL_WORD_SWAP | |
| 14716 | MISC_HOST_CTRL_INDIR_ACCESS | |
| 14717 | MISC_HOST_CTRL_PCISTATE_RW; |
| 14718 | |
| 14719 | /* The NONFRM (non-frame) byte/word swap controls take effect |
| 14720 | * on descriptor entries, anything which isn't packet data. |
| 14721 | * |
| 14722 | * The StrongARM chips on the board (one for tx, one for rx) |
| 14723 | * are running in big-endian mode. |
| 14724 | */ |
| 14725 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | |
| 14726 | GRC_MODE_WSWAP_NONFRM_DATA); |
| 14727 | #ifdef __BIG_ENDIAN |
| 14728 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; |
| 14729 | #endif |
| 14730 | spin_lock_init(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14731 | spin_lock_init(&tp->indirect_lock); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 14732 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14733 | |
Matt Carlson | d5fe488 | 2008-11-21 17:20:32 -0800 | [diff] [blame] | 14734 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 14735 | if (!tp->regs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14736 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14737 | err = -ENOMEM; |
| 14738 | goto err_out_free_dev; |
| 14739 | } |
| 14740 | |
| 14741 | tg3_init_link_config(tp); |
| 14742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14743 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
| 14744 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14746 | dev->ethtool_ops = &tg3_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14747 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14748 | dev->irq = pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14749 | |
| 14750 | err = tg3_get_invariants(tp); |
| 14751 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14752 | dev_err(&pdev->dev, |
| 14753 | "Problem fetching invariants of chip, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14754 | goto err_out_iounmap; |
| 14755 | } |
| 14756 | |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 14757 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) && |
Matt Carlson | 2e9f7a7 | 2010-09-15 08:59:56 +0000 | [diff] [blame] | 14758 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
Matt Carlson | a50d079 | 2010-06-05 17:24:37 +0000 | [diff] [blame] | 14759 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5719) |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14760 | dev->netdev_ops = &tg3_netdev_ops; |
| 14761 | else |
| 14762 | dev->netdev_ops = &tg3_netdev_ops_dma_bug; |
| 14763 | |
| 14764 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14765 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
| 14766 | * device behind the EPB cannot support DMA addresses > 40-bit. |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14767 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
| 14768 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and |
| 14769 | * do DMA address check in tg3_start_xmit(). |
| 14770 | */ |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14771 | if (tp->tg3_flags2 & TG3_FLG2_IS_5788) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 14772 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14773 | else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) { |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 14774 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14775 | #ifdef CONFIG_HIGHMEM |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 14776 | dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14777 | #endif |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14778 | } else |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 14779 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14780 | |
| 14781 | /* Configure DMA attributes. */ |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 14782 | if (dma_mask > DMA_BIT_MASK(32)) { |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14783 | err = pci_set_dma_mask(pdev, dma_mask); |
| 14784 | if (!err) { |
| 14785 | dev->features |= NETIF_F_HIGHDMA; |
| 14786 | err = pci_set_consistent_dma_mask(pdev, |
| 14787 | persist_dma_mask); |
| 14788 | if (err < 0) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14789 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
| 14790 | "DMA for consistent allocations\n"); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14791 | goto err_out_iounmap; |
| 14792 | } |
| 14793 | } |
| 14794 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 14795 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
| 14796 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14797 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14798 | dev_err(&pdev->dev, |
| 14799 | "No usable DMA configuration, aborting\n"); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14800 | goto err_out_iounmap; |
| 14801 | } |
| 14802 | } |
| 14803 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14804 | tg3_init_bufmgr_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14805 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14806 | /* Selectively allow TSO based on operating conditions */ |
| 14807 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) || |
| 14808 | (tp->fw_needed && !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) |
| 14809 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
| 14810 | else { |
| 14811 | tp->tg3_flags2 &= ~(TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG); |
| 14812 | tp->fw_needed = NULL; |
| 14813 | } |
| 14814 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 14815 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 14816 | tp->fw_needed = FIRMWARE_TG3; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 14817 | |
Michael Chan | 4e3a7aa | 2006-03-20 17:47:44 -0800 | [diff] [blame] | 14818 | /* TSO is on by default on chips that support hardware TSO. |
| 14819 | * Firmware TSO on older chips gives lower performance, so it |
| 14820 | * is off by default, but can be enabled using ethtool. |
| 14821 | */ |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14822 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) && |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14823 | (dev->features & NETIF_F_IP_CSUM)) { |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14824 | dev->features |= NETIF_F_TSO; |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14825 | vlan_features_add(dev, NETIF_F_TSO); |
| 14826 | } |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14827 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) || |
| 14828 | (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3)) { |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14829 | if (dev->features & NETIF_F_IPV6_CSUM) { |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 14830 | dev->features |= NETIF_F_TSO6; |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14831 | vlan_features_add(dev, NETIF_F_TSO6); |
| 14832 | } |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14833 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
| 14834 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 14835 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 14836 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14837 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14838 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 14839 | dev->features |= NETIF_F_TSO_ECN; |
Eric Dumazet | 7fe876a | 2010-07-08 06:14:55 +0000 | [diff] [blame] | 14840 | vlan_features_add(dev, NETIF_F_TSO_ECN); |
| 14841 | } |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 14842 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14844 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
| 14845 | !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) && |
| 14846 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
| 14847 | tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64; |
| 14848 | tp->rx_pending = 63; |
| 14849 | } |
| 14850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14851 | err = tg3_get_device_address(tp); |
| 14852 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14853 | dev_err(&pdev->dev, |
| 14854 | "Could not obtain valid ethernet address, aborting\n"); |
Matt Carlson | 026a6c2 | 2009-12-03 08:36:24 +0000 | [diff] [blame] | 14855 | goto err_out_iounmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14856 | } |
| 14857 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14858 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 14859 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 14860 | if (!tp->aperegs) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14861 | dev_err(&pdev->dev, |
| 14862 | "Cannot map APE registers, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14863 | err = -ENOMEM; |
Matt Carlson | 026a6c2 | 2009-12-03 08:36:24 +0000 | [diff] [blame] | 14864 | goto err_out_iounmap; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14865 | } |
| 14866 | |
| 14867 | tg3_ape_lock_init(tp); |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14868 | |
| 14869 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) |
| 14870 | tg3_read_dash_ver(tp); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14871 | } |
| 14872 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14873 | /* |
| 14874 | * Reset chip in case UNDI or EFI driver did not shutdown |
| 14875 | * DMA self test will enable WDMAC and we'll see (spurious) |
| 14876 | * pending DMA on the PCI bus at that point. |
| 14877 | */ |
| 14878 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
| 14879 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 14880 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
| 14881 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 14882 | } |
| 14883 | |
| 14884 | err = tg3_test_dma(tp); |
| 14885 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14886 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14887 | goto err_out_apeunmap; |
| 14888 | } |
| 14889 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14890 | /* flow control autonegotiation is default behavior */ |
| 14891 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 14892 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14893 | |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14894 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
| 14895 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; |
| 14896 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
Matt Carlson | 6fd45cb | 2010-09-15 08:59:57 +0000 | [diff] [blame] | 14897 | for (i = 0; i < tp->irq_max; i++) { |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14898 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 14899 | |
| 14900 | tnapi->tp = tp; |
| 14901 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; |
| 14902 | |
| 14903 | tnapi->int_mbox = intmbx; |
| 14904 | if (i < 4) |
| 14905 | intmbx += 0x8; |
| 14906 | else |
| 14907 | intmbx += 0x4; |
| 14908 | |
| 14909 | tnapi->consmbox = rcvmbx; |
| 14910 | tnapi->prodmbox = sndmbx; |
| 14911 | |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 14912 | if (i) |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14913 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
Matt Carlson | 66cfd1b | 2010-09-30 10:34:30 +0000 | [diff] [blame] | 14914 | else |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14915 | tnapi->coal_now = HOSTCC_MODE_NOW; |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14916 | |
| 14917 | if (!(tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX)) |
| 14918 | break; |
| 14919 | |
| 14920 | /* |
| 14921 | * If we support MSIX, we'll be using RSS. If we're using |
| 14922 | * RSS, the first vector only handles link interrupts and the |
| 14923 | * remaining vectors handle rx and tx interrupts. Reuse the |
| 14924 | * mailbox values for the next iteration. The values we setup |
| 14925 | * above are still useful for the single vectored mode. |
| 14926 | */ |
| 14927 | if (!i) |
| 14928 | continue; |
| 14929 | |
| 14930 | rcvmbx += 0x8; |
| 14931 | |
| 14932 | if (sndmbx & 0x4) |
| 14933 | sndmbx -= 0x4; |
| 14934 | else |
| 14935 | sndmbx += 0xc; |
| 14936 | } |
| 14937 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14938 | tg3_init_coal(tp); |
| 14939 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 14940 | pci_set_drvdata(pdev, dev); |
| 14941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14942 | err = register_netdev(dev); |
| 14943 | if (err) { |
Matt Carlson | ab96b24 | 2010-04-05 10:19:22 +0000 | [diff] [blame] | 14944 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14945 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14946 | } |
| 14947 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14948 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
| 14949 | tp->board_part_number, |
| 14950 | tp->pci_chip_rev_id, |
| 14951 | tg3_bus_string(tp, str), |
| 14952 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14953 | |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14954 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 14955 | struct phy_device *phydev; |
| 14956 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 14957 | netdev_info(dev, |
| 14958 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14959 | phydev->drv->name, dev_name(&phydev->dev)); |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14960 | } else { |
| 14961 | char *ethtype; |
| 14962 | |
| 14963 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 14964 | ethtype = "10/100Base-TX"; |
| 14965 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 14966 | ethtype = "1000Base-SX"; |
| 14967 | else |
| 14968 | ethtype = "10/100/1000Base-T"; |
| 14969 | |
Matt Carlson | 5129c3a | 2010-04-05 10:19:23 +0000 | [diff] [blame] | 14970 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14971 | "(WireSpeed[%d])\n", tg3_phy_string(tp), ethtype, |
| 14972 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0); |
| 14973 | } |
Matt Carlson | df59c94 | 2008-11-03 16:52:56 -0800 | [diff] [blame] | 14974 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14975 | netdev_info(dev, "RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n", |
| 14976 | (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0, |
| 14977 | (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0, |
Matt Carlson | f07e9af | 2010-08-02 11:26:07 +0000 | [diff] [blame] | 14978 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame] | 14979 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0, |
| 14980 | (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0); |
| 14981 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
| 14982 | tp->dma_rwctrl, |
| 14983 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : |
| 14984 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14985 | |
| 14986 | return 0; |
| 14987 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14988 | err_out_apeunmap: |
| 14989 | if (tp->aperegs) { |
| 14990 | iounmap(tp->aperegs); |
| 14991 | tp->aperegs = NULL; |
| 14992 | } |
| 14993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14994 | err_out_iounmap: |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14995 | if (tp->regs) { |
| 14996 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 14997 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14998 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14999 | |
| 15000 | err_out_free_dev: |
| 15001 | free_netdev(dev); |
| 15002 | |
| 15003 | err_out_free_res: |
| 15004 | pci_release_regions(pdev); |
| 15005 | |
| 15006 | err_out_disable_pdev: |
| 15007 | pci_disable_device(pdev); |
| 15008 | pci_set_drvdata(pdev, NULL); |
| 15009 | return err; |
| 15010 | } |
| 15011 | |
| 15012 | static void __devexit tg3_remove_one(struct pci_dev *pdev) |
| 15013 | { |
| 15014 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15015 | |
| 15016 | if (dev) { |
| 15017 | struct tg3 *tp = netdev_priv(dev); |
| 15018 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 15019 | if (tp->fw) |
| 15020 | release_firmware(tp->fw); |
| 15021 | |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 15022 | flush_scheduled_work(); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15023 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15024 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
| 15025 | tg3_phy_fini(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15026 | tg3_mdio_fini(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15027 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 15028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15029 | unregister_netdev(dev); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 15030 | if (tp->aperegs) { |
| 15031 | iounmap(tp->aperegs); |
| 15032 | tp->aperegs = NULL; |
| 15033 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15034 | if (tp->regs) { |
| 15035 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 15036 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 15037 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15038 | free_netdev(dev); |
| 15039 | pci_release_regions(pdev); |
| 15040 | pci_disable_device(pdev); |
| 15041 | pci_set_drvdata(pdev, NULL); |
| 15042 | } |
| 15043 | } |
| 15044 | |
| 15045 | static int tg3_suspend(struct pci_dev *pdev, pm_message_t state) |
| 15046 | { |
| 15047 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15048 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 15049 | pci_power_t target_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15050 | int err; |
| 15051 | |
Michael Chan | 3e0c95f | 2007-08-03 20:56:54 -0700 | [diff] [blame] | 15052 | /* PCI register 4 needs to be saved whether netif_running() or not. |
| 15053 | * MSI address and data need to be saved if using MSI and |
| 15054 | * netif_running(). |
| 15055 | */ |
| 15056 | pci_save_state(pdev); |
| 15057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15058 | if (!netif_running(dev)) |
| 15059 | return 0; |
| 15060 | |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 15061 | flush_scheduled_work(); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15062 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15063 | tg3_netif_stop(tp); |
| 15064 | |
| 15065 | del_timer_sync(&tp->timer); |
| 15066 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15067 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15068 | tg3_disable_ints(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15069 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15070 | |
| 15071 | netif_device_detach(dev); |
| 15072 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15073 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 15074 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 6a9eba1 | 2005-12-13 21:08:58 -0800 | [diff] [blame] | 15075 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15076 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15077 | |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 15078 | target_state = pdev->pm_cap ? pci_target_state(pdev) : PCI_D3hot; |
| 15079 | |
| 15080 | err = tg3_set_power_state(tp, target_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15081 | if (err) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15082 | int err2; |
| 15083 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15084 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15085 | |
Michael Chan | 6a9eba1 | 2005-12-13 21:08:58 -0800 | [diff] [blame] | 15086 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15087 | err2 = tg3_restart_hw(tp, 1); |
| 15088 | if (err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15089 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15090 | |
| 15091 | tp->timer.expires = jiffies + tp->timer_offset; |
| 15092 | add_timer(&tp->timer); |
| 15093 | |
| 15094 | netif_device_attach(dev); |
| 15095 | tg3_netif_start(tp); |
| 15096 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15097 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15098 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15099 | |
| 15100 | if (!err2) |
| 15101 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15102 | } |
| 15103 | |
| 15104 | return err; |
| 15105 | } |
| 15106 | |
| 15107 | static int tg3_resume(struct pci_dev *pdev) |
| 15108 | { |
| 15109 | struct net_device *dev = pci_get_drvdata(pdev); |
| 15110 | struct tg3 *tp = netdev_priv(dev); |
| 15111 | int err; |
| 15112 | |
Michael Chan | 3e0c95f | 2007-08-03 20:56:54 -0700 | [diff] [blame] | 15113 | pci_restore_state(tp->pdev); |
| 15114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15115 | if (!netif_running(dev)) |
| 15116 | return 0; |
| 15117 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 15118 | err = tg3_set_power_state(tp, PCI_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15119 | if (err) |
| 15120 | return err; |
| 15121 | |
| 15122 | netif_device_attach(dev); |
| 15123 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15124 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15125 | |
Michael Chan | 6a9eba1 | 2005-12-13 21:08:58 -0800 | [diff] [blame] | 15126 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15127 | err = tg3_restart_hw(tp, 1); |
| 15128 | if (err) |
| 15129 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15130 | |
| 15131 | tp->timer.expires = jiffies + tp->timer_offset; |
| 15132 | add_timer(&tp->timer); |
| 15133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15134 | tg3_netif_start(tp); |
| 15135 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15136 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 15137 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15138 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 15139 | if (!err) |
| 15140 | tg3_phy_start(tp); |
| 15141 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 15142 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15143 | } |
| 15144 | |
| 15145 | static struct pci_driver tg3_driver = { |
| 15146 | .name = DRV_MODULE_NAME, |
| 15147 | .id_table = tg3_pci_tbl, |
| 15148 | .probe = tg3_init_one, |
| 15149 | .remove = __devexit_p(tg3_remove_one), |
| 15150 | .suspend = tg3_suspend, |
| 15151 | .resume = tg3_resume |
| 15152 | }; |
| 15153 | |
| 15154 | static int __init tg3_init(void) |
| 15155 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 15156 | return pci_register_driver(&tg3_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15157 | } |
| 15158 | |
| 15159 | static void __exit tg3_cleanup(void) |
| 15160 | { |
| 15161 | pci_unregister_driver(&tg3_driver); |
| 15162 | } |
| 15163 | |
| 15164 | module_init(tg3_init); |
| 15165 | module_exit(tg3_cleanup); |