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> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/compiler.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/delay.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 26 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/init.h> |
| 28 | #include <linux/ioport.h> |
| 29 | #include <linux/pci.h> |
| 30 | #include <linux/netdevice.h> |
| 31 | #include <linux/etherdevice.h> |
| 32 | #include <linux/skbuff.h> |
| 33 | #include <linux/ethtool.h> |
| 34 | #include <linux/mii.h> |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 35 | #include <linux/phy.h> |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 36 | #include <linux/brcmphy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/if_vlan.h> |
| 38 | #include <linux/ip.h> |
| 39 | #include <linux/tcp.h> |
| 40 | #include <linux/workqueue.h> |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 41 | #include <linux/prefetch.h> |
Tobias Klauser | f9a5f7d | 2005-10-29 15:09:26 +0200 | [diff] [blame] | 42 | #include <linux/dma-mapping.h> |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 43 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | #include <net/checksum.h> |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 46 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | #include <asm/system.h> |
| 49 | #include <asm/io.h> |
| 50 | #include <asm/byteorder.h> |
| 51 | #include <asm/uaccess.h> |
| 52 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 53 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <asm/idprom.h> |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 55 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #endif |
| 57 | |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 58 | #define BAR_0 0 |
| 59 | #define BAR_2 2 |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
| 62 | #define TG3_VLAN_TAG_USED 1 |
| 63 | #else |
| 64 | #define TG3_VLAN_TAG_USED 0 |
| 65 | #endif |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include "tg3.h" |
| 68 | |
| 69 | #define DRV_MODULE_NAME "tg3" |
Matt Carlson | be7ce53 | 2010-02-17 15:17:05 +0000 | [diff] [blame] | 70 | #define DRV_MODULE_VERSION "3.108" |
| 71 | #define DRV_MODULE_RELDATE "February 17, 2010" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | #define TG3_DEF_MAC_MODE 0 |
| 74 | #define TG3_DEF_RX_MODE 0 |
| 75 | #define TG3_DEF_TX_MODE 0 |
| 76 | #define TG3_DEF_MSG_ENABLE \ |
| 77 | (NETIF_MSG_DRV | \ |
| 78 | NETIF_MSG_PROBE | \ |
| 79 | NETIF_MSG_LINK | \ |
| 80 | NETIF_MSG_TIMER | \ |
| 81 | NETIF_MSG_IFDOWN | \ |
| 82 | NETIF_MSG_IFUP | \ |
| 83 | NETIF_MSG_RX_ERR | \ |
| 84 | NETIF_MSG_TX_ERR) |
| 85 | |
| 86 | /* length of time before we decide the hardware is borked, |
| 87 | * and dev->tx_timeout() should be called to fix the problem |
| 88 | */ |
| 89 | #define TG3_TX_TIMEOUT (5 * HZ) |
| 90 | |
| 91 | /* hardware minimum and maximum for a single frame's data payload */ |
| 92 | #define TG3_MIN_MTU 60 |
| 93 | #define TG3_MAX_MTU(tp) \ |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 94 | ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) ? 9000 : 1500) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* These numbers seem to be hard coded in the NIC firmware somehow. |
| 97 | * You can't change the ring sizes, but you can change where you place |
| 98 | * them in the NIC onboard memory. |
| 99 | */ |
| 100 | #define TG3_RX_RING_SIZE 512 |
| 101 | #define TG3_DEF_RX_RING_PENDING 200 |
| 102 | #define TG3_RX_JUMBO_RING_SIZE 256 |
| 103 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 104 | #define TG3_RSS_INDIR_TBL_SIZE 128 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* Do not place this n-ring entries value into the tp struct itself, |
| 107 | * we really want to expose these constants to GCC so that modulo et |
| 108 | * al. operations are done with shifts and masks instead of with |
| 109 | * hw multiply/modulo instructions. Another solution would be to |
| 110 | * replace things like '% foo' with '& (foo - 1)'. |
| 111 | */ |
| 112 | #define TG3_RX_RCB_RING_SIZE(tp) \ |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 113 | (((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && \ |
Matt Carlson | 5ea1c50 | 2009-09-11 16:50:16 -0700 | [diff] [blame] | 114 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) ? 1024 : 512) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | #define TG3_TX_RING_SIZE 512 |
| 117 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) |
| 118 | |
| 119 | #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \ |
| 120 | TG3_RX_RING_SIZE) |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 121 | #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_ext_rx_buffer_desc) * \ |
| 122 | TG3_RX_JUMBO_RING_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \ |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 124 | TG3_RX_RCB_RING_SIZE(tp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
| 126 | TG3_TX_RING_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
| 128 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 129 | #define TG3_DMA_BYTE_ENAB 64 |
| 130 | |
| 131 | #define TG3_RX_STD_DMA_SZ 1536 |
| 132 | #define TG3_RX_JMB_DMA_SZ 9046 |
| 133 | |
| 134 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) |
| 135 | |
| 136 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) |
| 137 | #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] | 138 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 139 | #define TG3_RX_STD_BUFF_RING_SIZE \ |
| 140 | (sizeof(struct ring_info) * TG3_RX_RING_SIZE) |
| 141 | |
| 142 | #define TG3_RX_JMB_BUFF_RING_SIZE \ |
| 143 | (sizeof(struct ring_info) * TG3_RX_JUMBO_RING_SIZE) |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | /* minimum number of free TX descriptors required to wake up TX process */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 146 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 148 | #define TG3_RAW_IP_ALIGN 2 |
| 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* number of ETHTOOL_GSTATS u64's */ |
| 151 | #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64)) |
| 152 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 153 | #define TG3_NUM_TEST 6 |
| 154 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 155 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
| 156 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
| 157 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | static char version[] __devinitdata = |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 160 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); |
| 163 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); |
| 164 | MODULE_LICENSE("GPL"); |
| 165 | MODULE_VERSION(DRV_MODULE_VERSION); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 166 | MODULE_FIRMWARE(FIRMWARE_TG3); |
| 167 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); |
| 168 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); |
| 169 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 170 | #define TG3_RSS_MIN_NUM_MSIX_VECS 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
| 173 | module_param(tg3_debug, int, 0); |
| 174 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); |
| 175 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 176 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 177 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
| 178 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, |
| 179 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, |
| 180 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, |
| 181 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, |
| 182 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, |
| 183 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, |
| 184 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, |
| 185 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, |
| 186 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, |
| 187 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, |
| 188 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, |
| 189 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, |
| 190 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, |
| 191 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, |
| 192 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, |
| 193 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, |
| 194 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, |
| 195 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)}, |
| 196 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)}, |
| 197 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, |
| 198 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)}, |
| 199 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5720)}, |
| 200 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 201 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 202 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)}, |
| 203 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
| 204 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750M)}, |
| 205 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
| 206 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)}, |
| 207 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
| 208 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, |
| 209 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, |
| 210 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, |
| 211 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)}, |
| 212 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
| 213 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, |
| 214 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, |
| 215 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, |
Michael Chan | 126a336 | 2006-09-27 16:03:07 -0700 | [diff] [blame] | 216 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 217 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
| 218 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, |
| 219 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 220 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 221 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
| 222 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, |
| 223 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, |
| 224 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, |
| 225 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, |
| 226 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, |
| 227 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 228 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
| 229 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 230 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
| 231 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
Matt Carlson | 6c7af27 | 2007-10-21 16:12:02 -0700 | [diff] [blame] | 232 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 233 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
| 234 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
Matt Carlson | c88e668 | 2008-11-03 16:49:18 -0800 | [diff] [blame] | 235 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
| 236 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, |
Matt Carlson | 2befdce | 2009-08-28 12:28:45 +0000 | [diff] [blame] | 237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
| 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
| 240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, |
| 241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790)}, |
Matt Carlson | 5e7ccf2 | 2009-08-25 10:08:42 +0000 | [diff] [blame] | 242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
| 244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
| 245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5724)}, |
Matt Carlson | b0f7522 | 2010-01-20 16:58:11 +0000 | [diff] [blame] | 246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
| 247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, |
| 248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, |
| 249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, |
| 250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791)}, |
| 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)}, |
Henrik Kretzschmar | 1318521 | 2006-08-22 00:28:33 -0700 | [diff] [blame] | 252 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
| 253 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, |
| 254 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, |
| 255 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, |
| 256 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, |
| 257 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, |
| 258 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, |
| 259 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); |
| 263 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 264 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | const char string[ETH_GSTRING_LEN]; |
| 266 | } ethtool_stats_keys[TG3_NUM_STATS] = { |
| 267 | { "rx_octets" }, |
| 268 | { "rx_fragments" }, |
| 269 | { "rx_ucast_packets" }, |
| 270 | { "rx_mcast_packets" }, |
| 271 | { "rx_bcast_packets" }, |
| 272 | { "rx_fcs_errors" }, |
| 273 | { "rx_align_errors" }, |
| 274 | { "rx_xon_pause_rcvd" }, |
| 275 | { "rx_xoff_pause_rcvd" }, |
| 276 | { "rx_mac_ctrl_rcvd" }, |
| 277 | { "rx_xoff_entered" }, |
| 278 | { "rx_frame_too_long_errors" }, |
| 279 | { "rx_jabbers" }, |
| 280 | { "rx_undersize_packets" }, |
| 281 | { "rx_in_length_errors" }, |
| 282 | { "rx_out_length_errors" }, |
| 283 | { "rx_64_or_less_octet_packets" }, |
| 284 | { "rx_65_to_127_octet_packets" }, |
| 285 | { "rx_128_to_255_octet_packets" }, |
| 286 | { "rx_256_to_511_octet_packets" }, |
| 287 | { "rx_512_to_1023_octet_packets" }, |
| 288 | { "rx_1024_to_1522_octet_packets" }, |
| 289 | { "rx_1523_to_2047_octet_packets" }, |
| 290 | { "rx_2048_to_4095_octet_packets" }, |
| 291 | { "rx_4096_to_8191_octet_packets" }, |
| 292 | { "rx_8192_to_9022_octet_packets" }, |
| 293 | |
| 294 | { "tx_octets" }, |
| 295 | { "tx_collisions" }, |
| 296 | |
| 297 | { "tx_xon_sent" }, |
| 298 | { "tx_xoff_sent" }, |
| 299 | { "tx_flow_control" }, |
| 300 | { "tx_mac_errors" }, |
| 301 | { "tx_single_collisions" }, |
| 302 | { "tx_mult_collisions" }, |
| 303 | { "tx_deferred" }, |
| 304 | { "tx_excessive_collisions" }, |
| 305 | { "tx_late_collisions" }, |
| 306 | { "tx_collide_2times" }, |
| 307 | { "tx_collide_3times" }, |
| 308 | { "tx_collide_4times" }, |
| 309 | { "tx_collide_5times" }, |
| 310 | { "tx_collide_6times" }, |
| 311 | { "tx_collide_7times" }, |
| 312 | { "tx_collide_8times" }, |
| 313 | { "tx_collide_9times" }, |
| 314 | { "tx_collide_10times" }, |
| 315 | { "tx_collide_11times" }, |
| 316 | { "tx_collide_12times" }, |
| 317 | { "tx_collide_13times" }, |
| 318 | { "tx_collide_14times" }, |
| 319 | { "tx_collide_15times" }, |
| 320 | { "tx_ucast_packets" }, |
| 321 | { "tx_mcast_packets" }, |
| 322 | { "tx_bcast_packets" }, |
| 323 | { "tx_carrier_sense_errors" }, |
| 324 | { "tx_discards" }, |
| 325 | { "tx_errors" }, |
| 326 | |
| 327 | { "dma_writeq_full" }, |
| 328 | { "dma_write_prioq_full" }, |
| 329 | { "rxbds_empty" }, |
| 330 | { "rx_discards" }, |
| 331 | { "rx_errors" }, |
| 332 | { "rx_threshold_hit" }, |
| 333 | |
| 334 | { "dma_readq_full" }, |
| 335 | { "dma_read_prioq_full" }, |
| 336 | { "tx_comp_queue_full" }, |
| 337 | |
| 338 | { "ring_set_send_prod_index" }, |
| 339 | { "ring_status_update" }, |
| 340 | { "nic_irqs" }, |
| 341 | { "nic_avoided_irqs" }, |
| 342 | { "nic_tx_threshold_hit" } |
| 343 | }; |
| 344 | |
Andreas Mohr | 50da859 | 2006-08-14 23:54:30 -0700 | [diff] [blame] | 345 | static const struct { |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 346 | const char string[ETH_GSTRING_LEN]; |
| 347 | } ethtool_test_keys[TG3_NUM_TEST] = { |
| 348 | { "nvram test (online) " }, |
| 349 | { "link test (online) " }, |
| 350 | { "register test (offline)" }, |
| 351 | { "memory test (offline)" }, |
| 352 | { "loopback test (offline)" }, |
| 353 | { "interrupt test (offline)" }, |
| 354 | }; |
| 355 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 356 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
| 357 | { |
| 358 | writel(val, tp->regs + off); |
| 359 | } |
| 360 | |
| 361 | static u32 tg3_read32(struct tg3 *tp, u32 off) |
| 362 | { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 363 | return (readl(tp->regs + off)); |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 364 | } |
| 365 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 366 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
| 367 | { |
| 368 | writel(val, tp->aperegs + off); |
| 369 | } |
| 370 | |
| 371 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) |
| 372 | { |
| 373 | return (readl(tp->aperegs + off)); |
| 374 | } |
| 375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
| 377 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 378 | unsigned long flags; |
| 379 | |
| 380 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 381 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 382 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 383 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) |
| 387 | { |
| 388 | writel(val, tp->regs + off); |
| 389 | readl(tp->regs + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 392 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
| 393 | { |
| 394 | unsigned long flags; |
| 395 | u32 val; |
| 396 | |
| 397 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 398 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 399 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 400 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 401 | return val; |
| 402 | } |
| 403 | |
| 404 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) |
| 405 | { |
| 406 | unsigned long flags; |
| 407 | |
| 408 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { |
| 409 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + |
| 410 | TG3_64BIT_REG_LOW, val); |
| 411 | return; |
| 412 | } |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 413 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 414 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
| 415 | TG3_64BIT_REG_LOW, val); |
| 416 | return; |
| 417 | } |
| 418 | |
| 419 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 420 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 421 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 422 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 423 | |
| 424 | /* In indirect mode when disabling interrupts, we also need |
| 425 | * to clear the interrupt bit in the GRC local ctrl register. |
| 426 | */ |
| 427 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && |
| 428 | (val == 0x1)) { |
| 429 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, |
| 430 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) |
| 435 | { |
| 436 | unsigned long flags; |
| 437 | u32 val; |
| 438 | |
| 439 | spin_lock_irqsave(&tp->indirect_lock, flags); |
| 440 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 441 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 442 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 443 | return val; |
| 444 | } |
| 445 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 446 | /* usec_wait specifies the wait time in usec when writing to certain registers |
| 447 | * where it is unsafe to read back the register without some delay. |
| 448 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. |
| 449 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. |
| 450 | */ |
| 451 | 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] | 452 | { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 453 | if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) || |
| 454 | (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND)) |
| 455 | /* Non-posted methods */ |
| 456 | tp->write32(tp, off, val); |
| 457 | else { |
| 458 | /* Posted method */ |
| 459 | tg3_write32(tp, off, val); |
| 460 | if (usec_wait) |
| 461 | udelay(usec_wait); |
| 462 | tp->read32(tp, off); |
| 463 | } |
| 464 | /* Wait again after the read for the posted method to guarantee that |
| 465 | * the wait time is met. |
| 466 | */ |
| 467 | if (usec_wait) |
| 468 | udelay(usec_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 471 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
| 472 | { |
| 473 | tp->write32_mbox(tp, off, val); |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 474 | if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) && |
| 475 | !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND)) |
| 476 | tp->read32_mbox(tp, off); |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 479 | 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] | 480 | { |
| 481 | void __iomem *mbox = tp->regs + off; |
| 482 | writel(val, mbox); |
| 483 | if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) |
| 484 | writel(val, mbox); |
| 485 | if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) |
| 486 | readl(mbox); |
| 487 | } |
| 488 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 489 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
| 490 | { |
| 491 | return (readl(tp->regs + off + GRCMBOX_BASE)); |
| 492 | } |
| 493 | |
| 494 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) |
| 495 | { |
| 496 | writel(val, tp->regs + off + GRCMBOX_BASE); |
| 497 | } |
| 498 | |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 499 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 500 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 501 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
| 502 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 503 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 504 | |
| 505 | #define tw32(reg,val) tp->write32(tp, reg, val) |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 506 | #define tw32_f(reg,val) _tw32_flush(tp,(reg),(val), 0) |
| 507 | #define tw32_wait_f(reg,val,us) _tw32_flush(tp,(reg),(val), (us)) |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 508 | #define tr32(reg) tp->read32(tp, reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) |
| 511 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 512 | unsigned long flags; |
| 513 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 514 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
| 515 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
| 516 | return; |
| 517 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 518 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 519 | if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) { |
| 520 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 521 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 523 | /* Always leave this as zero. */ |
| 524 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 525 | } else { |
| 526 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 527 | tw32_f(TG3PCI_MEM_WIN_DATA, val); |
| 528 | |
| 529 | /* Always leave this as zero. */ |
| 530 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 531 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 532 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
| 536 | { |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 537 | unsigned long flags; |
| 538 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 539 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
| 540 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
| 541 | *val = 0; |
| 542 | return; |
| 543 | } |
| 544 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 545 | spin_lock_irqsave(&tp->indirect_lock, flags); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 546 | if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) { |
| 547 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 548 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 550 | /* Always leave this as zero. */ |
| 551 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 552 | } else { |
| 553 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 554 | *val = tr32(TG3PCI_MEM_WIN_DATA); |
| 555 | |
| 556 | /* Always leave this as zero. */ |
| 557 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 558 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 559 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 562 | static void tg3_ape_lock_init(struct tg3 *tp) |
| 563 | { |
| 564 | int i; |
| 565 | |
| 566 | /* Make sure the driver hasn't any stale locks. */ |
| 567 | for (i = 0; i < 8; i++) |
| 568 | tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + 4 * i, |
| 569 | APE_LOCK_GRANT_DRIVER); |
| 570 | } |
| 571 | |
| 572 | static int tg3_ape_lock(struct tg3 *tp, int locknum) |
| 573 | { |
| 574 | int i, off; |
| 575 | int ret = 0; |
| 576 | u32 status; |
| 577 | |
| 578 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) |
| 579 | return 0; |
| 580 | |
| 581 | switch (locknum) { |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 582 | case TG3_APE_LOCK_GRC: |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 583 | case TG3_APE_LOCK_MEM: |
| 584 | break; |
| 585 | default: |
| 586 | return -EINVAL; |
| 587 | } |
| 588 | |
| 589 | off = 4 * locknum; |
| 590 | |
| 591 | tg3_ape_write32(tp, TG3_APE_LOCK_REQ + off, APE_LOCK_REQ_DRIVER); |
| 592 | |
| 593 | /* Wait for up to 1 millisecond to acquire lock. */ |
| 594 | for (i = 0; i < 100; i++) { |
| 595 | status = tg3_ape_read32(tp, TG3_APE_LOCK_GRANT + off); |
| 596 | if (status == APE_LOCK_GRANT_DRIVER) |
| 597 | break; |
| 598 | udelay(10); |
| 599 | } |
| 600 | |
| 601 | if (status != APE_LOCK_GRANT_DRIVER) { |
| 602 | /* Revoke the lock request. */ |
| 603 | tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + off, |
| 604 | APE_LOCK_GRANT_DRIVER); |
| 605 | |
| 606 | ret = -EBUSY; |
| 607 | } |
| 608 | |
| 609 | return ret; |
| 610 | } |
| 611 | |
| 612 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) |
| 613 | { |
| 614 | int off; |
| 615 | |
| 616 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) |
| 617 | return; |
| 618 | |
| 619 | switch (locknum) { |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 620 | case TG3_APE_LOCK_GRC: |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 621 | case TG3_APE_LOCK_MEM: |
| 622 | break; |
| 623 | default: |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | off = 4 * locknum; |
| 628 | tg3_ape_write32(tp, TG3_APE_LOCK_GRANT + off, APE_LOCK_GRANT_DRIVER); |
| 629 | } |
| 630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | static void tg3_disable_ints(struct tg3 *tp) |
| 632 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 633 | int i; |
| 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 636 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 637 | for (i = 0; i < tp->irq_max; i++) |
| 638 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | static void tg3_enable_ints(struct tg3 *tp) |
| 642 | { |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 643 | int i; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 644 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 645 | tp->irq_sync = 0; |
| 646 | wmb(); |
| 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 649 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 650 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 651 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 652 | for (i = 0; i < tp->irq_cnt; i++) { |
| 653 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 654 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 655 | if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) |
| 656 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 657 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 658 | tp->coal_now |= tnapi->coal_now; |
Matt Carlson | 89aeb3b | 2009-09-01 13:08:58 +0000 | [diff] [blame] | 659 | } |
Matt Carlson | f19af9c | 2009-09-01 12:47:49 +0000 | [diff] [blame] | 660 | |
| 661 | /* Force an initial interrupt */ |
| 662 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) && |
| 663 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
| 664 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 665 | else |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 666 | tw32(HOSTCC_MODE, tp->coal_now); |
| 667 | |
| 668 | 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] | 669 | } |
| 670 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 671 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 672 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 673 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 674 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 675 | unsigned int work_exists = 0; |
| 676 | |
| 677 | /* check for phy events */ |
| 678 | if (!(tp->tg3_flags & |
| 679 | (TG3_FLAG_USE_LINKCHG_REG | |
| 680 | TG3_FLAG_POLL_SERDES))) { |
| 681 | if (sblk->status & SD_STATUS_LINK_CHG) |
| 682 | work_exists = 1; |
| 683 | } |
| 684 | /* check for RX/TX work to do */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 685 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons || |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 686 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 687 | work_exists = 1; |
| 688 | |
| 689 | return work_exists; |
| 690 | } |
| 691 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 692 | /* tg3_int_reenable |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 693 | * similar to tg3_enable_ints, but it accurately determines whether there |
| 694 | * is new work pending and can return without flushing the PIO write |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 695 | * which reenables interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 697 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 699 | struct tg3 *tp = tnapi->tp; |
| 700 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 701 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | mmiowb(); |
| 703 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 704 | /* When doing tagged status, this work check is unnecessary. |
| 705 | * The last_tag we write above tells the chip which piece of |
| 706 | * work we've completed. |
| 707 | */ |
| 708 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) && |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 709 | tg3_has_work(tnapi)) |
Michael Chan | 04237dd | 2005-04-25 15:17:17 -0700 | [diff] [blame] | 710 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 711 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 714 | static void tg3_napi_disable(struct tg3 *tp) |
| 715 | { |
| 716 | int i; |
| 717 | |
| 718 | for (i = tp->irq_cnt - 1; i >= 0; i--) |
| 719 | napi_disable(&tp->napi[i].napi); |
| 720 | } |
| 721 | |
| 722 | static void tg3_napi_enable(struct tg3 *tp) |
| 723 | { |
| 724 | int i; |
| 725 | |
| 726 | for (i = 0; i < tp->irq_cnt; i++) |
| 727 | napi_enable(&tp->napi[i].napi); |
| 728 | } |
| 729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | static inline void tg3_netif_stop(struct tg3 *tp) |
| 731 | { |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 732 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 733 | tg3_napi_disable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | netif_tx_disable(tp->dev); |
| 735 | } |
| 736 | |
| 737 | static inline void tg3_netif_start(struct tg3 *tp) |
| 738 | { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 739 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
| 740 | * appropriate so long as all callers are assured to |
| 741 | * have free tx slots (such as after tg3_init_hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | */ |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 743 | netif_tx_wake_all_queues(tp->dev); |
| 744 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 745 | tg3_napi_enable(tp); |
| 746 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 747 | tg3_enable_ints(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | static void tg3_switch_clocks(struct tg3 *tp) |
| 751 | { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 752 | u32 clock_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | u32 orig_clock_ctrl; |
| 754 | |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 755 | if ((tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) || |
| 756 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 757 | return; |
| 758 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 759 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
| 760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | orig_clock_ctrl = clock_ctrl; |
| 762 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | |
| 763 | CLOCK_CTRL_CLKRUN_OENABLE | |
| 764 | 0x1f); |
| 765 | tp->pci_clock_ctrl = clock_ctrl; |
| 766 | |
| 767 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 768 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 769 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 770 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } |
| 772 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 773 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 774 | clock_ctrl | |
| 775 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), |
| 776 | 40); |
| 777 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 778 | clock_ctrl | (CLOCK_CTRL_ALTCLK), |
| 779 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 781 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | #define PHY_BUSY_LOOPS 5000 |
| 785 | |
| 786 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
| 787 | { |
| 788 | u32 frame_val; |
| 789 | unsigned int loops; |
| 790 | int ret; |
| 791 | |
| 792 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 793 | tw32_f(MAC_MI_MODE, |
| 794 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 795 | udelay(80); |
| 796 | } |
| 797 | |
| 798 | *val = 0x0; |
| 799 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 800 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | MI_COM_PHY_ADDR_MASK); |
| 802 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 803 | MI_COM_REG_ADDR_MASK); |
| 804 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | tw32_f(MAC_MI_COM, frame_val); |
| 807 | |
| 808 | loops = PHY_BUSY_LOOPS; |
| 809 | while (loops != 0) { |
| 810 | udelay(10); |
| 811 | frame_val = tr32(MAC_MI_COM); |
| 812 | |
| 813 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 814 | udelay(5); |
| 815 | frame_val = tr32(MAC_MI_COM); |
| 816 | break; |
| 817 | } |
| 818 | loops -= 1; |
| 819 | } |
| 820 | |
| 821 | ret = -EBUSY; |
| 822 | if (loops != 0) { |
| 823 | *val = frame_val & MI_COM_DATA_MASK; |
| 824 | ret = 0; |
| 825 | } |
| 826 | |
| 827 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 828 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 829 | udelay(80); |
| 830 | } |
| 831 | |
| 832 | return ret; |
| 833 | } |
| 834 | |
| 835 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
| 836 | { |
| 837 | u32 frame_val; |
| 838 | unsigned int loops; |
| 839 | int ret; |
| 840 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 841 | if ((tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) && |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 842 | (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL)) |
| 843 | return 0; |
| 844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 846 | tw32_f(MAC_MI_MODE, |
| 847 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 848 | udelay(80); |
| 849 | } |
| 850 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 851 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | MI_COM_PHY_ADDR_MASK); |
| 853 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 854 | MI_COM_REG_ADDR_MASK); |
| 855 | frame_val |= (val & MI_COM_DATA_MASK); |
| 856 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | tw32_f(MAC_MI_COM, frame_val); |
| 859 | |
| 860 | loops = PHY_BUSY_LOOPS; |
| 861 | while (loops != 0) { |
| 862 | udelay(10); |
| 863 | frame_val = tr32(MAC_MI_COM); |
| 864 | if ((frame_val & MI_COM_BUSY) == 0) { |
| 865 | udelay(5); |
| 866 | frame_val = tr32(MAC_MI_COM); |
| 867 | break; |
| 868 | } |
| 869 | loops -= 1; |
| 870 | } |
| 871 | |
| 872 | ret = -EBUSY; |
| 873 | if (loops != 0) |
| 874 | ret = 0; |
| 875 | |
| 876 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 877 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 878 | udelay(80); |
| 879 | } |
| 880 | |
| 881 | return ret; |
| 882 | } |
| 883 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 884 | static int tg3_bmcr_reset(struct tg3 *tp) |
| 885 | { |
| 886 | u32 phy_control; |
| 887 | int limit, err; |
| 888 | |
| 889 | /* OK, reset it, and poll the BMCR_RESET bit until it |
| 890 | * clears or we time out. |
| 891 | */ |
| 892 | phy_control = BMCR_RESET; |
| 893 | err = tg3_writephy(tp, MII_BMCR, phy_control); |
| 894 | if (err != 0) |
| 895 | return -EBUSY; |
| 896 | |
| 897 | limit = 5000; |
| 898 | while (limit--) { |
| 899 | err = tg3_readphy(tp, MII_BMCR, &phy_control); |
| 900 | if (err != 0) |
| 901 | return -EBUSY; |
| 902 | |
| 903 | if ((phy_control & BMCR_RESET) == 0) { |
| 904 | udelay(40); |
| 905 | break; |
| 906 | } |
| 907 | udelay(10); |
| 908 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 909 | if (limit < 0) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 910 | return -EBUSY; |
| 911 | |
| 912 | return 0; |
| 913 | } |
| 914 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 915 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
| 916 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 917 | struct tg3 *tp = bp->priv; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 918 | u32 val; |
| 919 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 920 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 921 | |
| 922 | if (tg3_readphy(tp, reg, &val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 923 | val = -EIO; |
| 924 | |
| 925 | spin_unlock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 926 | |
| 927 | return val; |
| 928 | } |
| 929 | |
| 930 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) |
| 931 | { |
Francois Romieu | 3d16543 | 2009-01-19 16:56:50 -0800 | [diff] [blame] | 932 | struct tg3 *tp = bp->priv; |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 933 | u32 ret = 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 934 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 935 | spin_lock_bh(&tp->lock); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 936 | |
| 937 | if (tg3_writephy(tp, reg, val)) |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 938 | ret = -EIO; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 939 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 940 | spin_unlock_bh(&tp->lock); |
| 941 | |
| 942 | return ret; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | static int tg3_mdio_reset(struct mii_bus *bp) |
| 946 | { |
| 947 | return 0; |
| 948 | } |
| 949 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 950 | static void tg3_mdio_config_5785(struct tg3 *tp) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 951 | { |
| 952 | u32 val; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 953 | struct phy_device *phydev; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 954 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 955 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 956 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 957 | case PHY_ID_BCM50610: |
| 958 | case PHY_ID_BCM50610M: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 959 | val = MAC_PHYCFG2_50610_LED_MODES; |
| 960 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 961 | case PHY_ID_BCMAC131: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 962 | val = MAC_PHYCFG2_AC131_LED_MODES; |
| 963 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 964 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 965 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
| 966 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 967 | case PHY_ID_RTL8201E: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 968 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
| 969 | break; |
| 970 | default: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 971 | return; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { |
| 975 | tw32(MAC_PHYCFG2, val); |
| 976 | |
| 977 | val = tr32(MAC_PHYCFG1); |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 978 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
| 979 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); |
| 980 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 981 | tw32(MAC_PHYCFG1, val); |
| 982 | |
| 983 | return; |
| 984 | } |
| 985 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 986 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 987 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
| 988 | MAC_PHYCFG2_FMODE_MASK_MASK | |
| 989 | MAC_PHYCFG2_GMODE_MASK_MASK | |
| 990 | MAC_PHYCFG2_ACT_MASK_MASK | |
| 991 | MAC_PHYCFG2_QUAL_MASK_MASK | |
| 992 | MAC_PHYCFG2_INBAND_ENABLE; |
| 993 | |
| 994 | tw32(MAC_PHYCFG2, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 995 | |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 996 | val = tr32(MAC_PHYCFG1); |
| 997 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | |
| 998 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 999 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) { |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1000 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
| 1001 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
| 1002 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) |
| 1003 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
| 1004 | } |
Matt Carlson | bb85fbb | 2009-08-25 10:09:07 +0000 | [diff] [blame] | 1005 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
| 1006 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; |
| 1007 | tw32(MAC_PHYCFG1, val); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1008 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1009 | val = tr32(MAC_EXT_RGMII_MODE); |
| 1010 | val &= ~(MAC_RGMII_MODE_RX_INT_B | |
| 1011 | MAC_RGMII_MODE_RX_QUALITY | |
| 1012 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1013 | MAC_RGMII_MODE_RX_ENG_DET | |
| 1014 | MAC_RGMII_MODE_TX_ENABLE | |
| 1015 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1016 | MAC_RGMII_MODE_TX_RESET); |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 1017 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) { |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1018 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
| 1019 | val |= MAC_RGMII_MODE_RX_INT_B | |
| 1020 | MAC_RGMII_MODE_RX_QUALITY | |
| 1021 | MAC_RGMII_MODE_RX_ACTIVITY | |
| 1022 | MAC_RGMII_MODE_RX_ENG_DET; |
| 1023 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) |
| 1024 | val |= MAC_RGMII_MODE_TX_ENABLE | |
| 1025 | MAC_RGMII_MODE_TX_LOWPWR | |
| 1026 | MAC_RGMII_MODE_TX_RESET; |
| 1027 | } |
| 1028 | tw32(MAC_EXT_RGMII_MODE, val); |
| 1029 | } |
| 1030 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1031 | static void tg3_mdio_start(struct tg3 *tp) |
| 1032 | { |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1033 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
| 1034 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1035 | udelay(80); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1036 | |
Matt Carlson | 9ea4818 | 2010-02-17 15:17:01 +0000 | [diff] [blame] | 1037 | if ((tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) && |
| 1038 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1039 | tg3_mdio_config_5785(tp); |
| 1040 | } |
| 1041 | |
| 1042 | static int tg3_mdio_init(struct tg3 *tp) |
| 1043 | { |
| 1044 | int i; |
| 1045 | u32 reg; |
| 1046 | struct phy_device *phydev; |
| 1047 | |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1048 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 1049 | u32 funcnum, is_serdes; |
| 1050 | |
| 1051 | funcnum = tr32(TG3_CPMU_STATUS) & TG3_CPMU_STATUS_PCIE_FUNC; |
| 1052 | if (funcnum) |
| 1053 | tp->phy_addr = 2; |
| 1054 | else |
| 1055 | tp->phy_addr = 1; |
| 1056 | |
Matt Carlson | d1ec96a | 2010-01-12 10:11:38 +0000 | [diff] [blame] | 1057 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
| 1058 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
| 1059 | else |
| 1060 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & |
| 1061 | TG3_CPMU_PHY_STRAP_IS_SERDES; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1062 | if (is_serdes) |
| 1063 | tp->phy_addr += 7; |
| 1064 | } else |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1065 | tp->phy_addr = TG3_PHY_MII_ADDR; |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 1066 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1067 | tg3_mdio_start(tp); |
| 1068 | |
| 1069 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) || |
| 1070 | (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED)) |
| 1071 | return 0; |
| 1072 | |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1073 | tp->mdio_bus = mdiobus_alloc(); |
| 1074 | if (tp->mdio_bus == NULL) |
| 1075 | return -ENOMEM; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1076 | |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1077 | tp->mdio_bus->name = "tg3 mdio bus"; |
| 1078 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1079 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1080 | tp->mdio_bus->priv = tp; |
| 1081 | tp->mdio_bus->parent = &tp->pdev->dev; |
| 1082 | tp->mdio_bus->read = &tg3_mdio_read; |
| 1083 | tp->mdio_bus->write = &tg3_mdio_write; |
| 1084 | tp->mdio_bus->reset = &tg3_mdio_reset; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1085 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1086 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1087 | |
| 1088 | for (i = 0; i < PHY_MAX_ADDR; i++) |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1089 | tp->mdio_bus->irq[i] = PHY_POLL; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1090 | |
| 1091 | /* The bus registration will look for all the PHYs on the mdio bus. |
| 1092 | * Unfortunately, it does not ensure the PHY is powered up before |
| 1093 | * accessing the PHY ID registers. A chip reset is the |
| 1094 | * quickest way to bring the device back to an operational state.. |
| 1095 | */ |
| 1096 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
| 1097 | tg3_bmcr_reset(tp); |
| 1098 | |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1099 | i = mdiobus_register(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1100 | if (i) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 1101 | netdev_warn(tp->dev, "mdiobus_reg failed (0x%x)\n", i); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1102 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1103 | return i; |
| 1104 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1105 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1106 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1107 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1108 | if (!phydev || !phydev->drv) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 1109 | netdev_warn(tp->dev, "No PHY devices\n"); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1110 | mdiobus_unregister(tp->mdio_bus); |
| 1111 | mdiobus_free(tp->mdio_bus); |
| 1112 | return -ENODEV; |
| 1113 | } |
| 1114 | |
| 1115 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1116 | case PHY_ID_BCM57780: |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1117 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1118 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1119 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1120 | case PHY_ID_BCM50610: |
| 1121 | case PHY_ID_BCM50610M: |
Matt Carlson | 32e5a8d | 2009-11-02 14:31:39 +0000 | [diff] [blame] | 1122 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1123 | PHY_BRCM_RX_REFCLK_UNUSED | |
Matt Carlson | 52fae08 | 2009-11-02 14:32:38 +0000 | [diff] [blame] | 1124 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
Matt Carlson | c704dc2 | 2009-11-02 14:32:12 +0000 | [diff] [blame] | 1125 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 1126 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE) |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1127 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
| 1128 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
| 1129 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
| 1130 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) |
| 1131 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1132 | /* fallthru */ |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1133 | case PHY_ID_RTL8211C: |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1134 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1135 | break; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 1136 | case PHY_ID_RTL8201E: |
| 1137 | case PHY_ID_BCMAC131: |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1138 | phydev->interface = PHY_INTERFACE_MODE_MII; |
Matt Carlson | cdd4e09d | 2009-11-02 14:31:11 +0000 | [diff] [blame] | 1139 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1140 | tp->tg3_flags3 |= TG3_FLG3_PHY_IS_FET; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1141 | break; |
| 1142 | } |
| 1143 | |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1144 | tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_INITED; |
| 1145 | |
| 1146 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 1147 | tg3_mdio_config_5785(tp); |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1148 | |
| 1149 | return 0; |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static void tg3_mdio_fini(struct tg3 *tp) |
| 1153 | { |
| 1154 | if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { |
| 1155 | tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_INITED; |
Lennert Buytenhek | 298cf9be | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1156 | mdiobus_unregister(tp->mdio_bus); |
| 1157 | mdiobus_free(tp->mdio_bus); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1161 | /* tp->lock is held. */ |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1162 | static inline void tg3_generate_fw_event(struct tg3 *tp) |
| 1163 | { |
| 1164 | u32 val; |
| 1165 | |
| 1166 | val = tr32(GRC_RX_CPU_EVENT); |
| 1167 | val |= GRC_RX_CPU_DRIVER_EVENT; |
| 1168 | tw32_f(GRC_RX_CPU_EVENT, val); |
| 1169 | |
| 1170 | tp->last_event_jiffies = jiffies; |
| 1171 | } |
| 1172 | |
| 1173 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 |
| 1174 | |
| 1175 | /* tp->lock is held. */ |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1176 | static void tg3_wait_for_event_ack(struct tg3 *tp) |
| 1177 | { |
| 1178 | int i; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1179 | unsigned int delay_cnt; |
| 1180 | long time_remain; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1181 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1182 | /* If enough time has passed, no wait is necessary. */ |
| 1183 | time_remain = (long)(tp->last_event_jiffies + 1 + |
| 1184 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - |
| 1185 | (long)jiffies; |
| 1186 | if (time_remain < 0) |
| 1187 | return; |
| 1188 | |
| 1189 | /* Check if we can shorten the wait time. */ |
| 1190 | delay_cnt = jiffies_to_usecs(time_remain); |
| 1191 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) |
| 1192 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; |
| 1193 | delay_cnt = (delay_cnt >> 3) + 1; |
| 1194 | |
| 1195 | for (i = 0; i < delay_cnt; i++) { |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1196 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
| 1197 | break; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1198 | udelay(8); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | /* tp->lock is held. */ |
| 1203 | static void tg3_ump_link_report(struct tg3 *tp) |
| 1204 | { |
| 1205 | u32 reg; |
| 1206 | u32 val; |
| 1207 | |
| 1208 | if (!(tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
| 1209 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 1210 | return; |
| 1211 | |
| 1212 | tg3_wait_for_event_ack(tp); |
| 1213 | |
| 1214 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); |
| 1215 | |
| 1216 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); |
| 1217 | |
| 1218 | val = 0; |
| 1219 | if (!tg3_readphy(tp, MII_BMCR, ®)) |
| 1220 | val = reg << 16; |
| 1221 | if (!tg3_readphy(tp, MII_BMSR, ®)) |
| 1222 | val |= (reg & 0xffff); |
| 1223 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, val); |
| 1224 | |
| 1225 | val = 0; |
| 1226 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) |
| 1227 | val = reg << 16; |
| 1228 | if (!tg3_readphy(tp, MII_LPA, ®)) |
| 1229 | val |= (reg & 0xffff); |
| 1230 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 4, val); |
| 1231 | |
| 1232 | val = 0; |
| 1233 | if (!(tp->tg3_flags2 & TG3_FLG2_MII_SERDES)) { |
| 1234 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
| 1235 | val = reg << 16; |
| 1236 | if (!tg3_readphy(tp, MII_STAT1000, ®)) |
| 1237 | val |= (reg & 0xffff); |
| 1238 | } |
| 1239 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 8, val); |
| 1240 | |
| 1241 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) |
| 1242 | val = reg << 16; |
| 1243 | else |
| 1244 | val = 0; |
| 1245 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val); |
| 1246 | |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 1247 | tg3_generate_fw_event(tp); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | static void tg3_link_report(struct tg3 *tp) |
| 1251 | { |
| 1252 | if (!netif_carrier_ok(tp->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 1253 | netif_info(tp, link, tp->dev, "Link is down\n"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1254 | tg3_ump_link_report(tp); |
| 1255 | } else if (netif_msg_link(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 1256 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
| 1257 | (tp->link_config.active_speed == SPEED_1000 ? |
| 1258 | 1000 : |
| 1259 | (tp->link_config.active_speed == SPEED_100 ? |
| 1260 | 100 : 10)), |
| 1261 | (tp->link_config.active_duplex == DUPLEX_FULL ? |
| 1262 | "full" : "half")); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1263 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 1264 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", |
| 1265 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? |
| 1266 | "on" : "off", |
| 1267 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? |
| 1268 | "on" : "off"); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1269 | tg3_ump_link_report(tp); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl) |
| 1274 | { |
| 1275 | u16 miireg; |
| 1276 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1277 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1278 | miireg = ADVERTISE_PAUSE_CAP; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1279 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1280 | miireg = ADVERTISE_PAUSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1281 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1282 | miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1283 | else |
| 1284 | miireg = 0; |
| 1285 | |
| 1286 | return miireg; |
| 1287 | } |
| 1288 | |
| 1289 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
| 1290 | { |
| 1291 | u16 miireg; |
| 1292 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1293 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1294 | miireg = ADVERTISE_1000XPAUSE; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1295 | else if (flow_ctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1296 | miireg = ADVERTISE_1000XPSE_ASYM; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1297 | else if (flow_ctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1298 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
| 1299 | else |
| 1300 | miireg = 0; |
| 1301 | |
| 1302 | return miireg; |
| 1303 | } |
| 1304 | |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1305 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
| 1306 | { |
| 1307 | u8 cap = 0; |
| 1308 | |
| 1309 | if (lcladv & ADVERTISE_1000XPAUSE) { |
| 1310 | if (lcladv & ADVERTISE_1000XPSE_ASYM) { |
| 1311 | if (rmtadv & LPA_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1312 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1313 | else if (rmtadv & LPA_1000XPAUSE_ASYM) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1314 | cap = FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1315 | } else { |
| 1316 | if (rmtadv & LPA_1000XPAUSE) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1317 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1318 | } |
| 1319 | } else if (lcladv & ADVERTISE_1000XPSE_ASYM) { |
| 1320 | if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM)) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1321 | cap = FLOW_CTRL_TX; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | return cap; |
| 1325 | } |
| 1326 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1327 | 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] | 1328 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1329 | u8 autoneg; |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1330 | u8 flowctrl = 0; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1331 | u32 old_rx_mode = tp->rx_mode; |
| 1332 | u32 old_tx_mode = tp->tx_mode; |
| 1333 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1334 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1335 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1336 | else |
| 1337 | autoneg = tp->link_config.autoneg; |
| 1338 | |
| 1339 | if (autoneg == AUTONEG_ENABLE && |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1340 | (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)) { |
| 1341 | if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1342 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1343 | else |
Steve Glendinning | bc02ff9 | 2008-12-16 02:00:48 -0800 | [diff] [blame] | 1344 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1345 | } else |
| 1346 | flowctrl = tp->link_config.flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1347 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1348 | tp->link_config.active_flowctrl = flowctrl; |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1349 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1350 | if (flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1351 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
| 1352 | else |
| 1353 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; |
| 1354 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1355 | if (old_rx_mode != tp->rx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1356 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1357 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 1358 | if (flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1359 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
| 1360 | else |
| 1361 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; |
| 1362 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 1363 | if (old_tx_mode != tp->tx_mode) |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1364 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
Matt Carlson | 95e2869 | 2008-05-25 23:44:14 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1367 | static void tg3_adjust_link(struct net_device *dev) |
| 1368 | { |
| 1369 | u8 oldflowctrl, linkmesg = 0; |
| 1370 | u32 mac_mode, lcl_adv, rmt_adv; |
| 1371 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1372 | 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] | 1373 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1374 | spin_lock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1375 | |
| 1376 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | |
| 1377 | MAC_MODE_HALF_DUPLEX); |
| 1378 | |
| 1379 | oldflowctrl = tp->link_config.active_flowctrl; |
| 1380 | |
| 1381 | if (phydev->link) { |
| 1382 | lcl_adv = 0; |
| 1383 | rmt_adv = 0; |
| 1384 | |
| 1385 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) |
| 1386 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1387 | else if (phydev->speed == SPEED_1000 || |
| 1388 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1389 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | c3df074 | 2009-11-02 14:27:02 +0000 | [diff] [blame] | 1390 | else |
| 1391 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1392 | |
| 1393 | if (phydev->duplex == DUPLEX_HALF) |
| 1394 | mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 1395 | else { |
| 1396 | lcl_adv = tg3_advert_flowctrl_1000T( |
| 1397 | tp->link_config.flowctrl); |
| 1398 | |
| 1399 | if (phydev->pause) |
| 1400 | rmt_adv = LPA_PAUSE_CAP; |
| 1401 | if (phydev->asym_pause) |
| 1402 | rmt_adv |= LPA_PAUSE_ASYM; |
| 1403 | } |
| 1404 | |
| 1405 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 1406 | } else |
| 1407 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 1408 | |
| 1409 | if (mac_mode != tp->mac_mode) { |
| 1410 | tp->mac_mode = mac_mode; |
| 1411 | tw32_f(MAC_MODE, tp->mac_mode); |
| 1412 | udelay(40); |
| 1413 | } |
| 1414 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 1415 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
| 1416 | if (phydev->speed == SPEED_10) |
| 1417 | tw32(MAC_MI_STAT, |
| 1418 | MAC_MI_STAT_10MBPS_MODE | |
| 1419 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1420 | else |
| 1421 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 1422 | } |
| 1423 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1424 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
| 1425 | tw32(MAC_TX_LENGTHS, |
| 1426 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1427 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1428 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1429 | else |
| 1430 | tw32(MAC_TX_LENGTHS, |
| 1431 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 1432 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 1433 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 1434 | |
| 1435 | if ((phydev->link && tp->link_config.active_speed == SPEED_INVALID) || |
| 1436 | (!phydev->link && tp->link_config.active_speed != SPEED_INVALID) || |
| 1437 | phydev->speed != tp->link_config.active_speed || |
| 1438 | phydev->duplex != tp->link_config.active_duplex || |
| 1439 | oldflowctrl != tp->link_config.active_flowctrl) |
| 1440 | linkmesg = 1; |
| 1441 | |
| 1442 | tp->link_config.active_speed = phydev->speed; |
| 1443 | tp->link_config.active_duplex = phydev->duplex; |
| 1444 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 1445 | spin_unlock_bh(&tp->lock); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1446 | |
| 1447 | if (linkmesg) |
| 1448 | tg3_link_report(tp); |
| 1449 | } |
| 1450 | |
| 1451 | static int tg3_phy_init(struct tg3 *tp) |
| 1452 | { |
| 1453 | struct phy_device *phydev; |
| 1454 | |
| 1455 | if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) |
| 1456 | return 0; |
| 1457 | |
| 1458 | /* Bring the PHY back to a known state. */ |
| 1459 | tg3_bmcr_reset(tp); |
| 1460 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1461 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1462 | |
| 1463 | /* Attach the MAC to the PHY. */ |
Kay Sievers | fb28ad3 | 2008-11-10 13:55:14 -0800 | [diff] [blame] | 1464 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link, |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 1465 | phydev->dev_flags, phydev->interface); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1466 | if (IS_ERR(phydev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 1467 | netdev_err(tp->dev, "Could not attach to PHY\n"); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1468 | return PTR_ERR(phydev); |
| 1469 | } |
| 1470 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1471 | /* Mask with MAC supported features. */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1472 | switch (phydev->interface) { |
| 1473 | case PHY_INTERFACE_MODE_GMII: |
| 1474 | case PHY_INTERFACE_MODE_RGMII: |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 1475 | if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) { |
| 1476 | phydev->supported &= (PHY_GBIT_FEATURES | |
| 1477 | SUPPORTED_Pause | |
| 1478 | SUPPORTED_Asym_Pause); |
| 1479 | break; |
| 1480 | } |
| 1481 | /* fallthru */ |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1482 | case PHY_INTERFACE_MODE_MII: |
| 1483 | phydev->supported &= (PHY_BASIC_FEATURES | |
| 1484 | SUPPORTED_Pause | |
| 1485 | SUPPORTED_Asym_Pause); |
| 1486 | break; |
| 1487 | default: |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1488 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | 9c61d6b | 2008-11-03 16:54:56 -0800 | [diff] [blame] | 1489 | return -EINVAL; |
| 1490 | } |
| 1491 | |
| 1492 | tp->tg3_flags3 |= TG3_FLG3_PHY_CONNECTED; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1493 | |
| 1494 | phydev->advertising = phydev->supported; |
| 1495 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1496 | return 0; |
| 1497 | } |
| 1498 | |
| 1499 | static void tg3_phy_start(struct tg3 *tp) |
| 1500 | { |
| 1501 | struct phy_device *phydev; |
| 1502 | |
| 1503 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
| 1504 | return; |
| 1505 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1506 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1507 | |
| 1508 | if (tp->link_config.phy_is_low_power) { |
| 1509 | tp->link_config.phy_is_low_power = 0; |
| 1510 | phydev->speed = tp->link_config.orig_speed; |
| 1511 | phydev->duplex = tp->link_config.orig_duplex; |
| 1512 | phydev->autoneg = tp->link_config.orig_autoneg; |
| 1513 | phydev->advertising = tp->link_config.orig_advertising; |
| 1514 | } |
| 1515 | |
| 1516 | phy_start(phydev); |
| 1517 | |
| 1518 | phy_start_aneg(phydev); |
| 1519 | } |
| 1520 | |
| 1521 | static void tg3_phy_stop(struct tg3 *tp) |
| 1522 | { |
| 1523 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
| 1524 | return; |
| 1525 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1526 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | static void tg3_phy_fini(struct tg3 *tp) |
| 1530 | { |
| 1531 | if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 1532 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 1533 | tp->tg3_flags3 &= ~TG3_FLG3_PHY_CONNECTED; |
| 1534 | } |
| 1535 | } |
| 1536 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1537 | static void tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
| 1538 | { |
| 1539 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1540 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1541 | } |
| 1542 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1543 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
| 1544 | { |
| 1545 | u32 phytest; |
| 1546 | |
| 1547 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 1548 | u32 phy; |
| 1549 | |
| 1550 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 1551 | phytest | MII_TG3_FET_SHADOW_EN); |
| 1552 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { |
| 1553 | if (enable) |
| 1554 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1555 | else |
| 1556 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 1557 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); |
| 1558 | } |
| 1559 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 1560 | } |
| 1561 | } |
| 1562 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1563 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
| 1564 | { |
| 1565 | u32 reg; |
| 1566 | |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 1567 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
| 1568 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 && |
| 1569 | (tp->tg3_flags2 & TG3_FLG2_MII_SERDES))) |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1570 | return; |
| 1571 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1572 | if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) { |
| 1573 | tg3_phy_fet_toggle_apd(tp, enable); |
| 1574 | return; |
| 1575 | } |
| 1576 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1577 | reg = MII_TG3_MISC_SHDW_WREN | |
| 1578 | MII_TG3_MISC_SHDW_SCR5_SEL | |
| 1579 | MII_TG3_MISC_SHDW_SCR5_LPED | |
| 1580 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | |
| 1581 | MII_TG3_MISC_SHDW_SCR5_SDTL | |
| 1582 | MII_TG3_MISC_SHDW_SCR5_C125OE; |
| 1583 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) |
| 1584 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
| 1585 | |
| 1586 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 1587 | |
| 1588 | |
| 1589 | reg = MII_TG3_MISC_SHDW_WREN | |
| 1590 | MII_TG3_MISC_SHDW_APD_SEL | |
| 1591 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; |
| 1592 | if (enable) |
| 1593 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; |
| 1594 | |
| 1595 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); |
| 1596 | } |
| 1597 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1598 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
| 1599 | { |
| 1600 | u32 phy; |
| 1601 | |
| 1602 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
| 1603 | (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) |
| 1604 | return; |
| 1605 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 1606 | if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1607 | u32 ephy; |
| 1608 | |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1609 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
| 1610 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; |
| 1611 | |
| 1612 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 1613 | ephy | MII_TG3_FET_SHADOW_EN); |
| 1614 | if (!tg3_readphy(tp, reg, &phy)) { |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1615 | if (enable) |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1616 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1617 | else |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1618 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 1619 | tg3_writephy(tp, reg, phy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1620 | } |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 1621 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 1622 | } |
| 1623 | } else { |
| 1624 | phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC | |
| 1625 | MII_TG3_AUXCTL_SHDWSEL_MISC; |
| 1626 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) && |
| 1627 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) { |
| 1628 | if (enable) |
| 1629 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 1630 | else |
| 1631 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 1632 | phy |= MII_TG3_AUXCTL_MISC_WREN; |
| 1633 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); |
| 1634 | } |
| 1635 | } |
| 1636 | } |
| 1637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
| 1639 | { |
| 1640 | u32 val; |
| 1641 | |
| 1642 | if (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) |
| 1643 | return; |
| 1644 | |
| 1645 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) && |
| 1646 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val)) |
| 1647 | tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 1648 | (val | (1 << 15) | (1 << 4))); |
| 1649 | } |
| 1650 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1651 | static void tg3_phy_apply_otp(struct tg3 *tp) |
| 1652 | { |
| 1653 | u32 otp, phy; |
| 1654 | |
| 1655 | if (!tp->phy_otp) |
| 1656 | return; |
| 1657 | |
| 1658 | otp = tp->phy_otp; |
| 1659 | |
| 1660 | /* Enable SM_DSP clock and tx 6dB coding. */ |
| 1661 | phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | |
| 1662 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | |
| 1663 | MII_TG3_AUXCTL_ACTL_TX_6DB; |
| 1664 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); |
| 1665 | |
| 1666 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); |
| 1667 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; |
| 1668 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); |
| 1669 | |
| 1670 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | |
| 1671 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); |
| 1672 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); |
| 1673 | |
| 1674 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); |
| 1675 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; |
| 1676 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); |
| 1677 | |
| 1678 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); |
| 1679 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); |
| 1680 | |
| 1681 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); |
| 1682 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); |
| 1683 | |
| 1684 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | |
| 1685 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); |
| 1686 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); |
| 1687 | |
| 1688 | /* Turn off SM_DSP clock. */ |
| 1689 | phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | |
| 1690 | MII_TG3_AUXCTL_ACTL_TX_6DB; |
| 1691 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); |
| 1692 | } |
| 1693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | static int tg3_wait_macro_done(struct tg3 *tp) |
| 1695 | { |
| 1696 | int limit = 100; |
| 1697 | |
| 1698 | while (limit--) { |
| 1699 | u32 tmp32; |
| 1700 | |
| 1701 | if (!tg3_readphy(tp, 0x16, &tmp32)) { |
| 1702 | if ((tmp32 & 0x1000) == 0) |
| 1703 | break; |
| 1704 | } |
| 1705 | } |
Roel Kluin | d4675b5 | 2009-02-12 16:33:27 -0800 | [diff] [blame] | 1706 | if (limit < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | return -EBUSY; |
| 1708 | |
| 1709 | return 0; |
| 1710 | } |
| 1711 | |
| 1712 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) |
| 1713 | { |
| 1714 | static const u32 test_pat[4][6] = { |
| 1715 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, |
| 1716 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, |
| 1717 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, |
| 1718 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } |
| 1719 | }; |
| 1720 | int chan; |
| 1721 | |
| 1722 | for (chan = 0; chan < 4; chan++) { |
| 1723 | int i; |
| 1724 | |
| 1725 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1726 | (chan * 0x2000) | 0x0200); |
| 1727 | tg3_writephy(tp, 0x16, 0x0002); |
| 1728 | |
| 1729 | for (i = 0; i < 6; i++) |
| 1730 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, |
| 1731 | test_pat[chan][i]); |
| 1732 | |
| 1733 | tg3_writephy(tp, 0x16, 0x0202); |
| 1734 | if (tg3_wait_macro_done(tp)) { |
| 1735 | *resetp = 1; |
| 1736 | return -EBUSY; |
| 1737 | } |
| 1738 | |
| 1739 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1740 | (chan * 0x2000) | 0x0200); |
| 1741 | tg3_writephy(tp, 0x16, 0x0082); |
| 1742 | if (tg3_wait_macro_done(tp)) { |
| 1743 | *resetp = 1; |
| 1744 | return -EBUSY; |
| 1745 | } |
| 1746 | |
| 1747 | tg3_writephy(tp, 0x16, 0x0802); |
| 1748 | if (tg3_wait_macro_done(tp)) { |
| 1749 | *resetp = 1; |
| 1750 | return -EBUSY; |
| 1751 | } |
| 1752 | |
| 1753 | for (i = 0; i < 6; i += 2) { |
| 1754 | u32 low, high; |
| 1755 | |
| 1756 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || |
| 1757 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || |
| 1758 | tg3_wait_macro_done(tp)) { |
| 1759 | *resetp = 1; |
| 1760 | return -EBUSY; |
| 1761 | } |
| 1762 | low &= 0x7fff; |
| 1763 | high &= 0x000f; |
| 1764 | if (low != test_pat[chan][i] || |
| 1765 | high != test_pat[chan][i+1]) { |
| 1766 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); |
| 1767 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); |
| 1768 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); |
| 1769 | |
| 1770 | return -EBUSY; |
| 1771 | } |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | return 0; |
| 1776 | } |
| 1777 | |
| 1778 | static int tg3_phy_reset_chanpat(struct tg3 *tp) |
| 1779 | { |
| 1780 | int chan; |
| 1781 | |
| 1782 | for (chan = 0; chan < 4; chan++) { |
| 1783 | int i; |
| 1784 | |
| 1785 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 1786 | (chan * 0x2000) | 0x0200); |
| 1787 | tg3_writephy(tp, 0x16, 0x0002); |
| 1788 | for (i = 0; i < 6; i++) |
| 1789 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); |
| 1790 | tg3_writephy(tp, 0x16, 0x0202); |
| 1791 | if (tg3_wait_macro_done(tp)) |
| 1792 | return -EBUSY; |
| 1793 | } |
| 1794 | |
| 1795 | return 0; |
| 1796 | } |
| 1797 | |
| 1798 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) |
| 1799 | { |
| 1800 | u32 reg32, phy9_orig; |
| 1801 | int retries, do_phy_reset, err; |
| 1802 | |
| 1803 | retries = 10; |
| 1804 | do_phy_reset = 1; |
| 1805 | do { |
| 1806 | if (do_phy_reset) { |
| 1807 | err = tg3_bmcr_reset(tp); |
| 1808 | if (err) |
| 1809 | return err; |
| 1810 | do_phy_reset = 0; |
| 1811 | } |
| 1812 | |
| 1813 | /* Disable transmitter and interrupt. */ |
| 1814 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) |
| 1815 | continue; |
| 1816 | |
| 1817 | reg32 |= 0x3000; |
| 1818 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 1819 | |
| 1820 | /* Set full-duplex, 1000 mbps. */ |
| 1821 | tg3_writephy(tp, MII_BMCR, |
| 1822 | BMCR_FULLDPLX | TG3_BMCR_SPEED1000); |
| 1823 | |
| 1824 | /* Set to master mode. */ |
| 1825 | if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig)) |
| 1826 | continue; |
| 1827 | |
| 1828 | tg3_writephy(tp, MII_TG3_CTRL, |
| 1829 | (MII_TG3_CTRL_AS_MASTER | |
| 1830 | MII_TG3_CTRL_ENABLE_AS_MASTER)); |
| 1831 | |
| 1832 | /* Enable SM_DSP_CLOCK and 6dB. */ |
| 1833 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
| 1834 | |
| 1835 | /* Block the PHY control access. */ |
| 1836 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005); |
| 1837 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0800); |
| 1838 | |
| 1839 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); |
| 1840 | if (!err) |
| 1841 | break; |
| 1842 | } while (--retries); |
| 1843 | |
| 1844 | err = tg3_phy_reset_chanpat(tp); |
| 1845 | if (err) |
| 1846 | return err; |
| 1847 | |
| 1848 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8005); |
| 1849 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0000); |
| 1850 | |
| 1851 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); |
| 1852 | tg3_writephy(tp, 0x16, 0x0000); |
| 1853 | |
| 1854 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 1855 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 1856 | /* Set Extended packet length bit for jumbo frames */ |
| 1857 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400); |
| 1858 | } |
| 1859 | else { |
| 1860 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
| 1861 | } |
| 1862 | |
| 1863 | tg3_writephy(tp, MII_TG3_CTRL, phy9_orig); |
| 1864 | |
| 1865 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { |
| 1866 | reg32 &= ~0x3000; |
| 1867 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 1868 | } else if (!err) |
| 1869 | err = -EBUSY; |
| 1870 | |
| 1871 | return err; |
| 1872 | } |
| 1873 | |
| 1874 | /* This will reset the tigon3 PHY if there is no valid |
| 1875 | * link unless the FORCE argument is non-zero. |
| 1876 | */ |
| 1877 | static int tg3_phy_reset(struct tg3 *tp) |
| 1878 | { |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1879 | u32 cpmuctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | u32 phy_status; |
| 1881 | int err; |
| 1882 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 1883 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 1884 | u32 val; |
| 1885 | |
| 1886 | val = tr32(GRC_MISC_CFG); |
| 1887 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); |
| 1888 | udelay(40); |
| 1889 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | err = tg3_readphy(tp, MII_BMSR, &phy_status); |
| 1891 | err |= tg3_readphy(tp, MII_BMSR, &phy_status); |
| 1892 | if (err != 0) |
| 1893 | return -EBUSY; |
| 1894 | |
Michael Chan | c8e1e82 | 2006-04-29 18:55:17 -0700 | [diff] [blame] | 1895 | if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) { |
| 1896 | netif_carrier_off(tp->dev); |
| 1897 | tg3_link_report(tp); |
| 1898 | } |
| 1899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 1901 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 1902 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 1903 | err = tg3_phy_reset_5703_4_5(tp); |
| 1904 | if (err) |
| 1905 | return err; |
| 1906 | goto out; |
| 1907 | } |
| 1908 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1909 | cpmuctrl = 0; |
| 1910 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 1911 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 1912 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
| 1913 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) |
| 1914 | tw32(TG3_CPMU_CTRL, |
| 1915 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); |
| 1916 | } |
| 1917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | err = tg3_bmcr_reset(tp); |
| 1919 | if (err) |
| 1920 | return err; |
| 1921 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1922 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
| 1923 | u32 phy; |
| 1924 | |
| 1925 | phy = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
| 1926 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, phy); |
| 1927 | |
| 1928 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 1929 | } |
| 1930 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 1931 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 1932 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 1933 | u32 val; |
| 1934 | |
| 1935 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 1936 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == |
| 1937 | CPMU_LSPD_1000MB_MACCLK_12_5) { |
| 1938 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 1939 | udelay(40); |
| 1940 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 1941 | } |
| 1942 | } |
| 1943 | |
Matt Carlson | ecf1410 | 2010-01-20 16:58:05 +0000 | [diff] [blame] | 1944 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 && |
| 1945 | (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)) |
| 1946 | return 0; |
| 1947 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 1948 | tg3_phy_apply_otp(tp); |
| 1949 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 1950 | if (tp->tg3_flags3 & TG3_FLG3_PHY_ENABLE_APD) |
| 1951 | tg3_phy_toggle_apd(tp, true); |
| 1952 | else |
| 1953 | tg3_phy_toggle_apd(tp, false); |
| 1954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | out: |
| 1956 | if (tp->tg3_flags2 & TG3_FLG2_PHY_ADC_BUG) { |
| 1957 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
| 1958 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f); |
| 1959 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x2aaa); |
| 1960 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
| 1961 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0323); |
| 1962 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
| 1963 | } |
| 1964 | if (tp->tg3_flags2 & TG3_FLG2_PHY_5704_A0_BUG) { |
| 1965 | tg3_writephy(tp, 0x1c, 0x8d68); |
| 1966 | tg3_writephy(tp, 0x1c, 0x8d68); |
| 1967 | } |
| 1968 | if (tp->tg3_flags2 & TG3_FLG2_PHY_BER_BUG) { |
| 1969 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
| 1970 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
| 1971 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x310b); |
| 1972 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f); |
| 1973 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x9506); |
| 1974 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x401f); |
| 1975 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x14e2); |
| 1976 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
| 1977 | } |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 1978 | else if (tp->tg3_flags2 & TG3_FLG2_PHY_JITTER_BUG) { |
| 1979 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
| 1980 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 1981 | if (tp->tg3_flags2 & TG3_FLG2_PHY_ADJUST_TRIM) { |
| 1982 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
| 1983 | tg3_writephy(tp, MII_TG3_TEST1, |
| 1984 | MII_TG3_TEST1_TRIM_EN | 0x4); |
| 1985 | } else |
| 1986 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 1987 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
| 1988 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | /* Set Extended packet length bit (bit 14) on all chips that */ |
| 1990 | /* support jumbo frames */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 1991 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | /* Cannot do read-modify-write on 5401 */ |
| 1993 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20); |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 1994 | } else if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | u32 phy_reg; |
| 1996 | |
| 1997 | /* Set bit 14 with read-modify-write to preserve other bits */ |
| 1998 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) && |
| 1999 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg)) |
| 2000 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000); |
| 2001 | } |
| 2002 | |
| 2003 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support |
| 2004 | * jumbo frames transmission. |
| 2005 | */ |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 2006 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | u32 phy_reg; |
| 2008 | |
| 2009 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg)) |
| 2010 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 2011 | phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
| 2012 | } |
| 2013 | |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2014 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2015 | /* adjust output voltage */ |
Matt Carlson | 535ef6e | 2009-08-25 10:09:36 +0000 | [diff] [blame] | 2016 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 2019 | tg3_phy_toggle_automdix(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | tg3_phy_set_wirespeed(tp); |
| 2021 | return 0; |
| 2022 | } |
| 2023 | |
| 2024 | static void tg3_frob_aux_power(struct tg3 *tp) |
| 2025 | { |
| 2026 | struct tg3 *tp_peer = tp; |
| 2027 | |
Matt Carlson | 334355a | 2010-01-20 16:58:10 +0000 | [diff] [blame] | 2028 | /* The GPIOs do something completely different on 57765. */ |
| 2029 | if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0 || |
| 2030 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | return; |
| 2032 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 2033 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2034 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || |
| 2035 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2036 | struct net_device *dev_peer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2038 | dev_peer = pci_get_drvdata(tp->pdev_peer); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2039 | /* remove_one() may have been run on the peer. */ |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2040 | if (!dev_peer) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2041 | tp_peer = tp; |
| 2042 | else |
| 2043 | tp_peer = netdev_priv(dev_peer); |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 2044 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | |
| 2046 | if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 || |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2047 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 || |
| 2048 | (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 || |
| 2049 | (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2051 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2052 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2053 | (GRC_LCLCTRL_GPIO_OE0 | |
| 2054 | GRC_LCLCTRL_GPIO_OE1 | |
| 2055 | GRC_LCLCTRL_GPIO_OE2 | |
| 2056 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2057 | GRC_LCLCTRL_GPIO_OUTPUT1), |
| 2058 | 100); |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 2059 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 2060 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 2061 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
| 2062 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | |
| 2063 | GRC_LCLCTRL_GPIO_OE1 | |
| 2064 | GRC_LCLCTRL_GPIO_OE2 | |
| 2065 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2066 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2067 | tp->grc_local_ctrl; |
| 2068 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
| 2069 | |
| 2070 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2071 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
| 2072 | |
| 2073 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2074 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | } else { |
| 2076 | u32 no_gpio2; |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2077 | u32 grc_local_ctrl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | |
| 2079 | if (tp_peer != tp && |
| 2080 | (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0) |
| 2081 | return; |
| 2082 | |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2083 | /* Workaround to prevent overdrawing Amps. */ |
| 2084 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 2085 | ASIC_REV_5714) { |
| 2086 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2087 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2088 | grc_local_ctrl, 100); |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2089 | } |
| 2090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | /* On 5753 and variants, GPIO2 cannot be used. */ |
| 2092 | no_gpio2 = tp->nic_sram_data_cfg & |
| 2093 | NIC_SRAM_DATA_CFG_NO_GPIO2; |
| 2094 | |
Michael Chan | dc56b7d | 2005-12-19 16:26:28 -0800 | [diff] [blame] | 2095 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | GRC_LCLCTRL_GPIO_OE1 | |
| 2097 | GRC_LCLCTRL_GPIO_OE2 | |
| 2098 | GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2099 | GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2100 | if (no_gpio2) { |
| 2101 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | |
| 2102 | GRC_LCLCTRL_GPIO_OUTPUT2); |
| 2103 | } |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2104 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2105 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | |
| 2107 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2108 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2109 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2110 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | |
| 2112 | if (!no_gpio2) { |
| 2113 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2114 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2115 | grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | } else { |
| 2119 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 2120 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
| 2121 | if (tp_peer != tp && |
| 2122 | (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0) |
| 2123 | return; |
| 2124 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2125 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2126 | (GRC_LCLCTRL_GPIO_OE1 | |
| 2127 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2129 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2130 | GRC_LCLCTRL_GPIO_OE1, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2132 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2133 | (GRC_LCLCTRL_GPIO_OE1 | |
| 2134 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | } |
| 2136 | } |
| 2137 | } |
| 2138 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2139 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
| 2140 | { |
| 2141 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) |
| 2142 | return 1; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 2143 | 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] | 2144 | if (speed != SPEED_10) |
| 2145 | return 1; |
| 2146 | } else if (speed == SPEED_10) |
| 2147 | return 1; |
| 2148 | |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | static int tg3_setup_phy(struct tg3 *, int); |
| 2153 | |
| 2154 | #define RESET_KIND_SHUTDOWN 0 |
| 2155 | #define RESET_KIND_INIT 1 |
| 2156 | #define RESET_KIND_SUSPEND 2 |
| 2157 | |
| 2158 | static void tg3_write_sig_post_reset(struct tg3 *, int); |
| 2159 | static int tg3_halt_cpu(struct tg3 *, u32); |
| 2160 | |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2161 | 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] | 2162 | { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2163 | u32 val; |
| 2164 | |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2165 | if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) { |
| 2166 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2167 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 2168 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); |
| 2169 | |
| 2170 | sg_dig_ctrl |= |
| 2171 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; |
| 2172 | tw32(SG_DIG_CTRL, sg_dig_ctrl); |
| 2173 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); |
| 2174 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2175 | return; |
Michael Chan | 5129724 | 2007-02-13 12:17:57 -0800 | [diff] [blame] | 2176 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2177 | |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2178 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 60189dd | 2006-12-17 17:08:07 -0800 | [diff] [blame] | 2179 | tg3_bmcr_reset(tp); |
| 2180 | val = tr32(GRC_MISC_CFG); |
| 2181 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); |
| 2182 | udelay(40); |
| 2183 | return; |
Matt Carlson | 0e5f784 | 2009-11-02 14:26:38 +0000 | [diff] [blame] | 2184 | } else if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) { |
| 2185 | u32 phytest; |
| 2186 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2187 | u32 phy; |
| 2188 | |
| 2189 | tg3_writephy(tp, MII_ADVERTISE, 0); |
| 2190 | tg3_writephy(tp, MII_BMCR, |
| 2191 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 2192 | |
| 2193 | tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2194 | phytest | MII_TG3_FET_SHADOW_EN); |
| 2195 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { |
| 2196 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; |
| 2197 | tg3_writephy(tp, |
| 2198 | MII_TG3_FET_SHDW_AUXMODE4, |
| 2199 | phy); |
| 2200 | } |
| 2201 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2202 | } |
| 2203 | return; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2204 | } else if (do_low_power) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2205 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 2206 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2207 | |
| 2208 | tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 2209 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL | |
| 2210 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 2211 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | |
| 2212 | MII_TG3_AUXCTL_PCTL_VREG_11V); |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2213 | } |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2214 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2215 | /* The PHY should not be powered down on some chips because |
| 2216 | * of bugs. |
| 2217 | */ |
| 2218 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2219 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 2220 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && |
| 2221 | (tp->tg3_flags2 & TG3_FLG2_MII_SERDES))) |
| 2222 | return; |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2223 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 2224 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
| 2225 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { |
Matt Carlson | ce057f0 | 2007-11-12 21:08:03 -0800 | [diff] [blame] | 2226 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2227 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2228 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; |
| 2229 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2230 | } |
| 2231 | |
Michael Chan | 15c3b69 | 2006-03-22 01:06:52 -0800 | [diff] [blame] | 2232 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 2233 | } |
| 2234 | |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2235 | /* tp->lock is held. */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2236 | static int tg3_nvram_lock(struct tg3 *tp) |
| 2237 | { |
| 2238 | if (tp->tg3_flags & TG3_FLAG_NVRAM) { |
| 2239 | int i; |
| 2240 | |
| 2241 | if (tp->nvram_lock_cnt == 0) { |
| 2242 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); |
| 2243 | for (i = 0; i < 8000; i++) { |
| 2244 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) |
| 2245 | break; |
| 2246 | udelay(20); |
| 2247 | } |
| 2248 | if (i == 8000) { |
| 2249 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2250 | return -ENODEV; |
| 2251 | } |
| 2252 | } |
| 2253 | tp->nvram_lock_cnt++; |
| 2254 | } |
| 2255 | return 0; |
| 2256 | } |
| 2257 | |
| 2258 | /* tp->lock is held. */ |
| 2259 | static void tg3_nvram_unlock(struct tg3 *tp) |
| 2260 | { |
| 2261 | if (tp->tg3_flags & TG3_FLAG_NVRAM) { |
| 2262 | if (tp->nvram_lock_cnt > 0) |
| 2263 | tp->nvram_lock_cnt--; |
| 2264 | if (tp->nvram_lock_cnt == 0) |
| 2265 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | /* tp->lock is held. */ |
| 2270 | static void tg3_enable_nvram_access(struct tg3 *tp) |
| 2271 | { |
| 2272 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 2273 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2274 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2275 | |
| 2276 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); |
| 2277 | } |
| 2278 | } |
| 2279 | |
| 2280 | /* tp->lock is held. */ |
| 2281 | static void tg3_disable_nvram_access(struct tg3 *tp) |
| 2282 | { |
| 2283 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 2284 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) { |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2285 | u32 nvaccess = tr32(NVRAM_ACCESS); |
| 2286 | |
| 2287 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); |
| 2288 | } |
| 2289 | } |
| 2290 | |
| 2291 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, |
| 2292 | u32 offset, u32 *val) |
| 2293 | { |
| 2294 | u32 tmp; |
| 2295 | int i; |
| 2296 | |
| 2297 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) |
| 2298 | return -EINVAL; |
| 2299 | |
| 2300 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | |
| 2301 | EEPROM_ADDR_DEVID_MASK | |
| 2302 | EEPROM_ADDR_READ); |
| 2303 | tw32(GRC_EEPROM_ADDR, |
| 2304 | tmp | |
| 2305 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 2306 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & |
| 2307 | EEPROM_ADDR_ADDR_MASK) | |
| 2308 | EEPROM_ADDR_READ | EEPROM_ADDR_START); |
| 2309 | |
| 2310 | for (i = 0; i < 1000; i++) { |
| 2311 | tmp = tr32(GRC_EEPROM_ADDR); |
| 2312 | |
| 2313 | if (tmp & EEPROM_ADDR_COMPLETE) |
| 2314 | break; |
| 2315 | msleep(1); |
| 2316 | } |
| 2317 | if (!(tmp & EEPROM_ADDR_COMPLETE)) |
| 2318 | return -EBUSY; |
| 2319 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 2320 | tmp = tr32(GRC_EEPROM_DATA); |
| 2321 | |
| 2322 | /* |
| 2323 | * The data will always be opposite the native endian |
| 2324 | * format. Perform a blind byteswap to compensate. |
| 2325 | */ |
| 2326 | *val = swab32(tmp); |
| 2327 | |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2328 | return 0; |
| 2329 | } |
| 2330 | |
| 2331 | #define NVRAM_CMD_TIMEOUT 10000 |
| 2332 | |
| 2333 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) |
| 2334 | { |
| 2335 | int i; |
| 2336 | |
| 2337 | tw32(NVRAM_CMD, nvram_cmd); |
| 2338 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { |
| 2339 | udelay(10); |
| 2340 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { |
| 2341 | udelay(10); |
| 2342 | break; |
| 2343 | } |
| 2344 | } |
| 2345 | |
| 2346 | if (i == NVRAM_CMD_TIMEOUT) |
| 2347 | return -EBUSY; |
| 2348 | |
| 2349 | return 0; |
| 2350 | } |
| 2351 | |
| 2352 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) |
| 2353 | { |
| 2354 | if ((tp->tg3_flags & TG3_FLAG_NVRAM) && |
| 2355 | (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) && |
| 2356 | (tp->tg3_flags2 & TG3_FLG2_FLASH) && |
| 2357 | !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) && |
| 2358 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2359 | |
| 2360 | addr = ((addr / tp->nvram_pagesize) << |
| 2361 | ATMEL_AT45DB0X1B_PAGE_POS) + |
| 2362 | (addr % tp->nvram_pagesize); |
| 2363 | |
| 2364 | return addr; |
| 2365 | } |
| 2366 | |
| 2367 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) |
| 2368 | { |
| 2369 | if ((tp->tg3_flags & TG3_FLAG_NVRAM) && |
| 2370 | (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) && |
| 2371 | (tp->tg3_flags2 & TG3_FLG2_FLASH) && |
| 2372 | !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) && |
| 2373 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 2374 | |
| 2375 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * |
| 2376 | tp->nvram_pagesize) + |
| 2377 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); |
| 2378 | |
| 2379 | return addr; |
| 2380 | } |
| 2381 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2382 | /* NOTE: Data read in from NVRAM is byteswapped according to |
| 2383 | * the byteswapping settings for all other register accesses. |
| 2384 | * tg3 devices are BE devices, so on a BE machine, the data |
| 2385 | * returned will be exactly as it is seen in NVRAM. On a LE |
| 2386 | * machine, the 32-bit value will be byteswapped. |
| 2387 | */ |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2388 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
| 2389 | { |
| 2390 | int ret; |
| 2391 | |
| 2392 | if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) |
| 2393 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
| 2394 | |
| 2395 | offset = tg3_nvram_phys_addr(tp, offset); |
| 2396 | |
| 2397 | if (offset > NVRAM_ADDR_MSK) |
| 2398 | return -EINVAL; |
| 2399 | |
| 2400 | ret = tg3_nvram_lock(tp); |
| 2401 | if (ret) |
| 2402 | return ret; |
| 2403 | |
| 2404 | tg3_enable_nvram_access(tp); |
| 2405 | |
| 2406 | tw32(NVRAM_ADDR, offset); |
| 2407 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | |
| 2408 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); |
| 2409 | |
| 2410 | if (ret == 0) |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 2411 | *val = tr32(NVRAM_RDDATA); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2412 | |
| 2413 | tg3_disable_nvram_access(tp); |
| 2414 | |
| 2415 | tg3_nvram_unlock(tp); |
| 2416 | |
| 2417 | return ret; |
| 2418 | } |
| 2419 | |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2420 | /* Ensures NVRAM data is in bytestream format. */ |
| 2421 | 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] | 2422 | { |
| 2423 | u32 v; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2424 | int res = tg3_nvram_read(tp, offset, &v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2425 | if (!res) |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 2426 | *val = cpu_to_be32(v); |
Matt Carlson | ffbcfed | 2009-02-25 14:24:28 +0000 | [diff] [blame] | 2427 | return res; |
| 2428 | } |
| 2429 | |
| 2430 | /* tp->lock is held. */ |
Matt Carlson | 3f00789 | 2008-11-03 16:51:36 -0800 | [diff] [blame] | 2431 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) |
| 2432 | { |
| 2433 | u32 addr_high, addr_low; |
| 2434 | int i; |
| 2435 | |
| 2436 | addr_high = ((tp->dev->dev_addr[0] << 8) | |
| 2437 | tp->dev->dev_addr[1]); |
| 2438 | addr_low = ((tp->dev->dev_addr[2] << 24) | |
| 2439 | (tp->dev->dev_addr[3] << 16) | |
| 2440 | (tp->dev->dev_addr[4] << 8) | |
| 2441 | (tp->dev->dev_addr[5] << 0)); |
| 2442 | for (i = 0; i < 4; i++) { |
| 2443 | if (i == 1 && skip_mac_1) |
| 2444 | continue; |
| 2445 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); |
| 2446 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); |
| 2447 | } |
| 2448 | |
| 2449 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 2450 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 2451 | for (i = 0; i < 12; i++) { |
| 2452 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); |
| 2453 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | addr_high = (tp->dev->dev_addr[0] + |
| 2458 | tp->dev->dev_addr[1] + |
| 2459 | tp->dev->dev_addr[2] + |
| 2460 | tp->dev->dev_addr[3] + |
| 2461 | tp->dev->dev_addr[4] + |
| 2462 | tp->dev->dev_addr[5]) & |
| 2463 | TX_BACKOFF_SEED_MASK; |
| 2464 | tw32(MAC_TX_BACKOFF_SEED, addr_high); |
| 2465 | } |
| 2466 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2467 | 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] | 2468 | { |
| 2469 | u32 misc_host_ctrl; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2470 | bool device_should_wake, do_low_power; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | |
| 2472 | /* Make sure register accesses (indirect or otherwise) |
| 2473 | * will function correctly. |
| 2474 | */ |
| 2475 | pci_write_config_dword(tp->pdev, |
| 2476 | TG3PCI_MISC_HOST_CTRL, |
| 2477 | tp->misc_host_ctrl); |
| 2478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | switch (state) { |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2480 | case PCI_D0: |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 2481 | pci_enable_wake(tp->pdev, state, false); |
| 2482 | pci_set_power_state(tp->pdev, PCI_D0); |
Michael Chan | 8c6bda1 | 2005-04-21 17:09:08 -0700 | [diff] [blame] | 2483 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 2484 | /* Switch out of Vaux if it is a NIC */ |
| 2485 | if (tp->tg3_flags2 & TG3_FLG2_IS_NIC) |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2486 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | |
| 2488 | return 0; |
| 2489 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2490 | case PCI_D1: |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2491 | case PCI_D2: |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 2492 | case PCI_D3hot: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | break; |
| 2494 | |
| 2495 | default: |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 2496 | netdev_err(tp->dev, "Invalid power state (D%d) requested\n", |
| 2497 | state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 2499 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 2500 | |
| 2501 | /* Restore the CLKREQ setting. */ |
| 2502 | if (tp->tg3_flags3 & TG3_FLG3_CLKREQ_BUG) { |
| 2503 | u16 lnkctl; |
| 2504 | |
| 2505 | pci_read_config_word(tp->pdev, |
| 2506 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 2507 | &lnkctl); |
| 2508 | lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 2509 | pci_write_config_word(tp->pdev, |
| 2510 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 2511 | lnkctl); |
| 2512 | } |
| 2513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 2515 | tw32(TG3PCI_MISC_HOST_CTRL, |
| 2516 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); |
| 2517 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2518 | device_should_wake = pci_pme_capable(tp->pdev, state) && |
| 2519 | device_may_wakeup(&tp->pdev->dev) && |
| 2520 | (tp->tg3_flags & TG3_FLAG_WOL_ENABLE); |
| 2521 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2522 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2523 | do_low_power = false; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2524 | if ((tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) && |
| 2525 | !tp->link_config.phy_is_low_power) { |
| 2526 | struct phy_device *phydev; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2527 | u32 phyid, advertising; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2528 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 2529 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2530 | |
| 2531 | tp->link_config.phy_is_low_power = 1; |
| 2532 | |
| 2533 | tp->link_config.orig_speed = phydev->speed; |
| 2534 | tp->link_config.orig_duplex = phydev->duplex; |
| 2535 | tp->link_config.orig_autoneg = phydev->autoneg; |
| 2536 | tp->link_config.orig_advertising = phydev->advertising; |
| 2537 | |
| 2538 | advertising = ADVERTISED_TP | |
| 2539 | ADVERTISED_Pause | |
| 2540 | ADVERTISED_Autoneg | |
| 2541 | ADVERTISED_10baseT_Half; |
| 2542 | |
| 2543 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2544 | device_should_wake) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2545 | if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) |
| 2546 | advertising |= |
| 2547 | ADVERTISED_100baseT_Half | |
| 2548 | ADVERTISED_100baseT_Full | |
| 2549 | ADVERTISED_10baseT_Full; |
| 2550 | else |
| 2551 | advertising |= ADVERTISED_10baseT_Full; |
| 2552 | } |
| 2553 | |
| 2554 | phydev->advertising = advertising; |
| 2555 | |
| 2556 | phy_start_aneg(phydev); |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2557 | |
| 2558 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; |
Matt Carlson | 6a443a0 | 2010-02-17 15:17:04 +0000 | [diff] [blame] | 2559 | if (phyid != PHY_ID_BCMAC131) { |
| 2560 | phyid &= PHY_BCM_OUI_MASK; |
| 2561 | if (phyid == PHY_BCM_OUI_1 || |
| 2562 | phyid == PHY_BCM_OUI_2 || |
| 2563 | phyid == PHY_BCM_OUI_3) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2564 | do_low_power = true; |
| 2565 | } |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 2566 | } |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2567 | } else { |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 2568 | do_low_power = true; |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2569 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2570 | if (tp->link_config.phy_is_low_power == 0) { |
| 2571 | tp->link_config.phy_is_low_power = 1; |
| 2572 | tp->link_config.orig_speed = tp->link_config.speed; |
| 2573 | tp->link_config.orig_duplex = tp->link_config.duplex; |
| 2574 | tp->link_config.orig_autoneg = tp->link_config.autoneg; |
| 2575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2577 | if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) { |
| 2578 | tp->link_config.speed = SPEED_10; |
| 2579 | tp->link_config.duplex = DUPLEX_HALF; |
| 2580 | tp->link_config.autoneg = AUTONEG_ENABLE; |
| 2581 | tg3_setup_phy(tp, 0); |
| 2582 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 2585 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 2586 | u32 val; |
| 2587 | |
| 2588 | val = tr32(GRC_VCPU_EXT_CTRL); |
| 2589 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); |
| 2590 | } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2591 | int i; |
| 2592 | u32 val; |
| 2593 | |
| 2594 | for (i = 0; i < 200; i++) { |
| 2595 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); |
| 2596 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 2597 | break; |
| 2598 | msleep(1); |
| 2599 | } |
| 2600 | } |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 2601 | if (tp->tg3_flags & TG3_FLAG_WOL_CAP) |
| 2602 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
| 2603 | WOL_DRV_STATE_SHUTDOWN | |
| 2604 | WOL_DRV_WOL | |
| 2605 | WOL_SET_MAGIC_PKT); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2606 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2607 | if (device_should_wake) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | u32 mac_mode; |
| 2609 | |
| 2610 | if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) { |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2611 | if (do_low_power) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 2612 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a); |
| 2613 | udelay(40); |
| 2614 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 2616 | if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) |
| 2617 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 2618 | else |
| 2619 | mac_mode = MAC_MODE_PORT_MODE_MII; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 2621 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
| 2622 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 2623 | ASIC_REV_5700) { |
| 2624 | u32 speed = (tp->tg3_flags & |
| 2625 | TG3_FLAG_WOL_SPEED_100MB) ? |
| 2626 | SPEED_100 : SPEED_10; |
| 2627 | if (tg3_5700_link_polarity(tp, speed)) |
| 2628 | mac_mode |= MAC_MODE_LINK_POLARITY; |
| 2629 | else |
| 2630 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 2631 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | } else { |
| 2633 | mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 2634 | } |
| 2635 | |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 2636 | if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 2638 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2639 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
| 2640 | if (((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
| 2641 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) && |
| 2642 | ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
| 2643 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))) |
| 2644 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 2646 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
| 2647 | mac_mode |= tp->mac_mode & |
| 2648 | (MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN); |
| 2649 | if (mac_mode & MAC_MODE_APE_TX_EN) |
| 2650 | mac_mode |= MAC_MODE_TDE_ENABLE; |
| 2651 | } |
| 2652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | tw32_f(MAC_MODE, mac_mode); |
| 2654 | udelay(100); |
| 2655 | |
| 2656 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); |
| 2657 | udelay(10); |
| 2658 | } |
| 2659 | |
| 2660 | if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) && |
| 2661 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2662 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 2663 | u32 base_val; |
| 2664 | |
| 2665 | base_val = tp->pci_clock_ctrl; |
| 2666 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | |
| 2667 | CLOCK_CTRL_TXCLK_DISABLE); |
| 2668 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2669 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
| 2670 | CLOCK_CTRL_PWRDOWN_PLL133, 40); |
Michael Chan | d7b0a85 | 2007-02-13 12:17:38 -0800 | [diff] [blame] | 2671 | } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 2672 | (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) || |
Michael Chan | d7b0a85 | 2007-02-13 12:17:38 -0800 | [diff] [blame] | 2673 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) { |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 2674 | /* do nothing */ |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 2675 | } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) { |
| 2677 | u32 newbits1, newbits2; |
| 2678 | |
| 2679 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2680 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 2681 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 2682 | CLOCK_CTRL_TXCLK_DISABLE | |
| 2683 | CLOCK_CTRL_ALTCLK); |
| 2684 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 2685 | } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 2686 | newbits1 = CLOCK_CTRL_625_CORE; |
| 2687 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; |
| 2688 | } else { |
| 2689 | newbits1 = CLOCK_CTRL_ALTCLK; |
| 2690 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 2691 | } |
| 2692 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2693 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
| 2694 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2696 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
| 2697 | 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | |
| 2699 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 2700 | u32 newbits3; |
| 2701 | |
| 2702 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 2703 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 2704 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 2705 | CLOCK_CTRL_TXCLK_DISABLE | |
| 2706 | CLOCK_CTRL_44MHZ_CORE); |
| 2707 | } else { |
| 2708 | newbits3 = CLOCK_CTRL_44MHZ_CORE; |
| 2709 | } |
| 2710 | |
Michael Chan | b401e9e | 2005-12-19 16:27:04 -0800 | [diff] [blame] | 2711 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 2712 | tp->pci_clock_ctrl | newbits3, 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | } |
| 2714 | } |
| 2715 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2716 | if (!(device_should_wake) && |
Matt Carlson | 2243584 | 2008-11-21 17:21:13 -0800 | [diff] [blame] | 2717 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
Matt Carlson | 0a459aa | 2008-11-03 16:54:15 -0800 | [diff] [blame] | 2718 | tg3_power_down_phy(tp, do_low_power); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | tg3_frob_aux_power(tp); |
| 2721 | |
| 2722 | /* Workaround for unstable PLL clock */ |
| 2723 | if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) || |
| 2724 | (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) { |
| 2725 | u32 val = tr32(0x7d00); |
| 2726 | |
| 2727 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); |
| 2728 | tw32(0x7d00, val); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2729 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 2730 | int err; |
| 2731 | |
| 2732 | err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | tg3_halt_cpu(tp, RX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 2734 | if (!err) |
| 2735 | tg3_nvram_unlock(tp); |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 2736 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 2739 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
| 2740 | |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 2741 | if (device_should_wake) |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 2742 | pci_enable_wake(tp->pdev, state, true); |
| 2743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | /* Finally, set the new power state. */ |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 2745 | pci_set_power_state(tp->pdev, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | return 0; |
| 2748 | } |
| 2749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
| 2751 | { |
| 2752 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { |
| 2753 | case MII_TG3_AUX_STAT_10HALF: |
| 2754 | *speed = SPEED_10; |
| 2755 | *duplex = DUPLEX_HALF; |
| 2756 | break; |
| 2757 | |
| 2758 | case MII_TG3_AUX_STAT_10FULL: |
| 2759 | *speed = SPEED_10; |
| 2760 | *duplex = DUPLEX_FULL; |
| 2761 | break; |
| 2762 | |
| 2763 | case MII_TG3_AUX_STAT_100HALF: |
| 2764 | *speed = SPEED_100; |
| 2765 | *duplex = DUPLEX_HALF; |
| 2766 | break; |
| 2767 | |
| 2768 | case MII_TG3_AUX_STAT_100FULL: |
| 2769 | *speed = SPEED_100; |
| 2770 | *duplex = DUPLEX_FULL; |
| 2771 | break; |
| 2772 | |
| 2773 | case MII_TG3_AUX_STAT_1000HALF: |
| 2774 | *speed = SPEED_1000; |
| 2775 | *duplex = DUPLEX_HALF; |
| 2776 | break; |
| 2777 | |
| 2778 | case MII_TG3_AUX_STAT_1000FULL: |
| 2779 | *speed = SPEED_1000; |
| 2780 | *duplex = DUPLEX_FULL; |
| 2781 | break; |
| 2782 | |
| 2783 | default: |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 2784 | if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) { |
Michael Chan | 715116a | 2006-09-27 16:09:25 -0700 | [diff] [blame] | 2785 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
| 2786 | SPEED_10; |
| 2787 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : |
| 2788 | DUPLEX_HALF; |
| 2789 | break; |
| 2790 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | *speed = SPEED_INVALID; |
| 2792 | *duplex = DUPLEX_INVALID; |
| 2793 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 2794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | static void tg3_phy_copper_begin(struct tg3 *tp) |
| 2798 | { |
| 2799 | u32 new_adv; |
| 2800 | int i; |
| 2801 | |
| 2802 | if (tp->link_config.phy_is_low_power) { |
| 2803 | /* Entering low power mode. Disable gigabit and |
| 2804 | * 100baseT advertisements. |
| 2805 | */ |
| 2806 | tg3_writephy(tp, MII_TG3_CTRL, 0); |
| 2807 | |
| 2808 | new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 2809 | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); |
| 2810 | if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) |
| 2811 | new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 2812 | |
| 2813 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 2814 | } else if (tp->link_config.speed == SPEED_INVALID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | if (tp->tg3_flags & TG3_FLAG_10_100_ONLY) |
| 2816 | tp->link_config.advertising &= |
| 2817 | ~(ADVERTISED_1000baseT_Half | |
| 2818 | ADVERTISED_1000baseT_Full); |
| 2819 | |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2820 | new_adv = ADVERTISE_CSMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | if (tp->link_config.advertising & ADVERTISED_10baseT_Half) |
| 2822 | new_adv |= ADVERTISE_10HALF; |
| 2823 | if (tp->link_config.advertising & ADVERTISED_10baseT_Full) |
| 2824 | new_adv |= ADVERTISE_10FULL; |
| 2825 | if (tp->link_config.advertising & ADVERTISED_100baseT_Half) |
| 2826 | new_adv |= ADVERTISE_100HALF; |
| 2827 | if (tp->link_config.advertising & ADVERTISED_100baseT_Full) |
| 2828 | new_adv |= ADVERTISE_100FULL; |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2829 | |
| 2830 | new_adv |= tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); |
| 2831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 2833 | |
| 2834 | if (tp->link_config.advertising & |
| 2835 | (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) { |
| 2836 | new_adv = 0; |
| 2837 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) |
| 2838 | new_adv |= MII_TG3_CTRL_ADV_1000_HALF; |
| 2839 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) |
| 2840 | new_adv |= MII_TG3_CTRL_ADV_1000_FULL; |
| 2841 | if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY) && |
| 2842 | (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 2843 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)) |
| 2844 | new_adv |= (MII_TG3_CTRL_AS_MASTER | |
| 2845 | MII_TG3_CTRL_ENABLE_AS_MASTER); |
| 2846 | tg3_writephy(tp, MII_TG3_CTRL, new_adv); |
| 2847 | } else { |
| 2848 | tg3_writephy(tp, MII_TG3_CTRL, 0); |
| 2849 | } |
| 2850 | } else { |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2851 | new_adv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); |
| 2852 | new_adv |= ADVERTISE_CSMA; |
| 2853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | /* Asking for a specific link mode. */ |
| 2855 | if (tp->link_config.speed == SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 2857 | |
| 2858 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 2859 | new_adv = MII_TG3_CTRL_ADV_1000_FULL; |
| 2860 | else |
| 2861 | new_adv = MII_TG3_CTRL_ADV_1000_HALF; |
| 2862 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 2863 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) |
| 2864 | new_adv |= (MII_TG3_CTRL_AS_MASTER | |
| 2865 | MII_TG3_CTRL_ENABLE_AS_MASTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | if (tp->link_config.speed == SPEED_100) { |
| 2868 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 2869 | new_adv |= ADVERTISE_100FULL; |
| 2870 | else |
| 2871 | new_adv |= ADVERTISE_100HALF; |
| 2872 | } else { |
| 2873 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 2874 | new_adv |= ADVERTISE_10FULL; |
| 2875 | else |
| 2876 | new_adv |= ADVERTISE_10HALF; |
| 2877 | } |
| 2878 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2879 | |
| 2880 | new_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2881 | } |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 2882 | |
| 2883 | tg3_writephy(tp, MII_TG3_CTRL, new_adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | if (tp->link_config.autoneg == AUTONEG_DISABLE && |
| 2887 | tp->link_config.speed != SPEED_INVALID) { |
| 2888 | u32 bmcr, orig_bmcr; |
| 2889 | |
| 2890 | tp->link_config.active_speed = tp->link_config.speed; |
| 2891 | tp->link_config.active_duplex = tp->link_config.duplex; |
| 2892 | |
| 2893 | bmcr = 0; |
| 2894 | switch (tp->link_config.speed) { |
| 2895 | default: |
| 2896 | case SPEED_10: |
| 2897 | break; |
| 2898 | |
| 2899 | case SPEED_100: |
| 2900 | bmcr |= BMCR_SPEED100; |
| 2901 | break; |
| 2902 | |
| 2903 | case SPEED_1000: |
| 2904 | bmcr |= TG3_BMCR_SPEED1000; |
| 2905 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 2906 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | |
| 2908 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 2909 | bmcr |= BMCR_FULLDPLX; |
| 2910 | |
| 2911 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && |
| 2912 | (bmcr != orig_bmcr)) { |
| 2913 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); |
| 2914 | for (i = 0; i < 1500; i++) { |
| 2915 | u32 tmp; |
| 2916 | |
| 2917 | udelay(10); |
| 2918 | if (tg3_readphy(tp, MII_BMSR, &tmp) || |
| 2919 | tg3_readphy(tp, MII_BMSR, &tmp)) |
| 2920 | continue; |
| 2921 | if (!(tmp & BMSR_LSTATUS)) { |
| 2922 | udelay(40); |
| 2923 | break; |
| 2924 | } |
| 2925 | } |
| 2926 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 2927 | udelay(40); |
| 2928 | } |
| 2929 | } else { |
| 2930 | tg3_writephy(tp, MII_BMCR, |
| 2931 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | static int tg3_init_5401phy_dsp(struct tg3 *tp) |
| 2936 | { |
| 2937 | int err; |
| 2938 | |
| 2939 | /* Turn off tap power management. */ |
| 2940 | /* Set Extended packet length bit */ |
| 2941 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20); |
| 2942 | |
| 2943 | err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0012); |
| 2944 | err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1804); |
| 2945 | |
| 2946 | err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x0013); |
| 2947 | err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x1204); |
| 2948 | |
| 2949 | err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006); |
| 2950 | err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0132); |
| 2951 | |
| 2952 | err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8006); |
| 2953 | err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0232); |
| 2954 | |
| 2955 | err |= tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x201f); |
| 2956 | err |= tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x0a20); |
| 2957 | |
| 2958 | udelay(40); |
| 2959 | |
| 2960 | return err; |
| 2961 | } |
| 2962 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 2963 | static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | { |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 2965 | u32 adv_reg, all_mask = 0; |
| 2966 | |
| 2967 | if (mask & ADVERTISED_10baseT_Half) |
| 2968 | all_mask |= ADVERTISE_10HALF; |
| 2969 | if (mask & ADVERTISED_10baseT_Full) |
| 2970 | all_mask |= ADVERTISE_10FULL; |
| 2971 | if (mask & ADVERTISED_100baseT_Half) |
| 2972 | all_mask |= ADVERTISE_100HALF; |
| 2973 | if (mask & ADVERTISED_100baseT_Full) |
| 2974 | all_mask |= ADVERTISE_100FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | |
| 2976 | if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg)) |
| 2977 | return 0; |
| 2978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | if ((adv_reg & all_mask) != all_mask) |
| 2980 | return 0; |
| 2981 | if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) { |
| 2982 | u32 tg3_ctrl; |
| 2983 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 2984 | all_mask = 0; |
| 2985 | if (mask & ADVERTISED_1000baseT_Half) |
| 2986 | all_mask |= ADVERTISE_1000HALF; |
| 2987 | if (mask & ADVERTISED_1000baseT_Full) |
| 2988 | all_mask |= ADVERTISE_1000FULL; |
| 2989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl)) |
| 2991 | return 0; |
| 2992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | if ((tg3_ctrl & all_mask) != all_mask) |
| 2994 | return 0; |
| 2995 | } |
| 2996 | return 1; |
| 2997 | } |
| 2998 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 2999 | static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv) |
| 3000 | { |
| 3001 | u32 curadv, reqadv; |
| 3002 | |
| 3003 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
| 3004 | return 1; |
| 3005 | |
| 3006 | curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
| 3007 | reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); |
| 3008 | |
| 3009 | if (tp->link_config.active_duplex == DUPLEX_FULL) { |
| 3010 | if (curadv != reqadv) |
| 3011 | return 0; |
| 3012 | |
| 3013 | if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) |
| 3014 | tg3_readphy(tp, MII_LPA, rmtadv); |
| 3015 | } else { |
| 3016 | /* Reprogram the advertisement register, even if it |
| 3017 | * does not affect the current link. If the link |
| 3018 | * gets renegotiated in the future, we can save an |
| 3019 | * additional renegotiation cycle by advertising |
| 3020 | * it correctly in the first place. |
| 3021 | */ |
| 3022 | if (curadv != reqadv) { |
| 3023 | *lcladv &= ~(ADVERTISE_PAUSE_CAP | |
| 3024 | ADVERTISE_PAUSE_ASYM); |
| 3025 | tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv); |
| 3026 | } |
| 3027 | } |
| 3028 | |
| 3029 | return 1; |
| 3030 | } |
| 3031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
| 3033 | { |
| 3034 | int current_link_up; |
| 3035 | u32 bmsr, dummy; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3036 | u32 lcl_adv, rmt_adv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | u16 current_speed; |
| 3038 | u8 current_duplex; |
| 3039 | int i, err; |
| 3040 | |
| 3041 | tw32(MAC_EVENT, 0); |
| 3042 | |
| 3043 | tw32_f(MAC_STATUS, |
| 3044 | (MAC_STATUS_SYNC_CHANGED | |
| 3045 | MAC_STATUS_CFG_CHANGED | |
| 3046 | MAC_STATUS_MI_COMPLETION | |
| 3047 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 3048 | udelay(40); |
| 3049 | |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 3050 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 3051 | tw32_f(MAC_MI_MODE, |
| 3052 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 3053 | udelay(80); |
| 3054 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | |
| 3056 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02); |
| 3057 | |
| 3058 | /* Some third-party PHYs need to be reset on link going |
| 3059 | * down. |
| 3060 | */ |
| 3061 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 3062 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 3063 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
| 3064 | netif_carrier_ok(tp->dev)) { |
| 3065 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3066 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3067 | !(bmsr & BMSR_LSTATUS)) |
| 3068 | force_reset = 1; |
| 3069 | } |
| 3070 | if (force_reset) |
| 3071 | tg3_phy_reset(tp); |
| 3072 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3073 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3075 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || |
| 3076 | !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) |
| 3077 | bmsr = 0; |
| 3078 | |
| 3079 | if (!(bmsr & BMSR_LSTATUS)) { |
| 3080 | err = tg3_init_5401phy_dsp(tp); |
| 3081 | if (err) |
| 3082 | return err; |
| 3083 | |
| 3084 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3085 | for (i = 0; i < 1000; i++) { |
| 3086 | udelay(10); |
| 3087 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3088 | (bmsr & BMSR_LSTATUS)) { |
| 3089 | udelay(40); |
| 3090 | break; |
| 3091 | } |
| 3092 | } |
| 3093 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3094 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
| 3095 | TG3_PHY_REV_BCM5401_B0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | !(bmsr & BMSR_LSTATUS) && |
| 3097 | tp->link_config.active_speed == SPEED_1000) { |
| 3098 | err = tg3_phy_reset(tp); |
| 3099 | if (!err) |
| 3100 | err = tg3_init_5401phy_dsp(tp); |
| 3101 | if (err) |
| 3102 | return err; |
| 3103 | } |
| 3104 | } |
| 3105 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 3106 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { |
| 3107 | /* 5701 {A0,B0} CRC bug workaround */ |
| 3108 | tg3_writephy(tp, 0x15, 0x0a75); |
| 3109 | tg3_writephy(tp, 0x1c, 0x8c68); |
| 3110 | tg3_writephy(tp, 0x1c, 0x8d68); |
| 3111 | tg3_writephy(tp, 0x1c, 0x8c68); |
| 3112 | } |
| 3113 | |
| 3114 | /* Clear pending interrupts... */ |
| 3115 | tg3_readphy(tp, MII_TG3_ISTAT, &dummy); |
| 3116 | tg3_readphy(tp, MII_TG3_ISTAT, &dummy); |
| 3117 | |
| 3118 | if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) |
| 3119 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 3120 | else if (!(tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
| 3122 | |
| 3123 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 3124 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 3125 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
| 3126 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 3127 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 3128 | else |
| 3129 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); |
| 3130 | } |
| 3131 | |
| 3132 | current_link_up = 0; |
| 3133 | current_speed = SPEED_INVALID; |
| 3134 | current_duplex = DUPLEX_INVALID; |
| 3135 | |
| 3136 | if (tp->tg3_flags2 & TG3_FLG2_CAPACITIVE_COUPLING) { |
| 3137 | u32 val; |
| 3138 | |
| 3139 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007); |
| 3140 | tg3_readphy(tp, MII_TG3_AUX_CTRL, &val); |
| 3141 | if (!(val & (1 << 10))) { |
| 3142 | val |= (1 << 10); |
| 3143 | tg3_writephy(tp, MII_TG3_AUX_CTRL, val); |
| 3144 | goto relink; |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | bmsr = 0; |
| 3149 | for (i = 0; i < 100; i++) { |
| 3150 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 3151 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 3152 | (bmsr & BMSR_LSTATUS)) |
| 3153 | break; |
| 3154 | udelay(40); |
| 3155 | } |
| 3156 | |
| 3157 | if (bmsr & BMSR_LSTATUS) { |
| 3158 | u32 aux_stat, bmcr; |
| 3159 | |
| 3160 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); |
| 3161 | for (i = 0; i < 2000; i++) { |
| 3162 | udelay(10); |
| 3163 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && |
| 3164 | aux_stat) |
| 3165 | break; |
| 3166 | } |
| 3167 | |
| 3168 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, |
| 3169 | ¤t_speed, |
| 3170 | ¤t_duplex); |
| 3171 | |
| 3172 | bmcr = 0; |
| 3173 | for (i = 0; i < 200; i++) { |
| 3174 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 3175 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) |
| 3176 | continue; |
| 3177 | if (bmcr && bmcr != 0x7fff) |
| 3178 | break; |
| 3179 | udelay(10); |
| 3180 | } |
| 3181 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3182 | lcl_adv = 0; |
| 3183 | rmt_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3185 | tp->link_config.active_speed = current_speed; |
| 3186 | tp->link_config.active_duplex = current_duplex; |
| 3187 | |
| 3188 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 3189 | if ((bmcr & BMCR_ANENABLE) && |
| 3190 | tg3_copper_is_advertising_all(tp, |
| 3191 | tp->link_config.advertising)) { |
| 3192 | if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv, |
| 3193 | &rmt_adv)) |
| 3194 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | } |
| 3196 | } else { |
| 3197 | if (!(bmcr & BMCR_ANENABLE) && |
| 3198 | tp->link_config.speed == current_speed && |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3199 | tp->link_config.duplex == current_duplex && |
| 3200 | tp->link_config.flowctrl == |
| 3201 | tp->link_config.active_flowctrl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | } |
| 3204 | } |
| 3205 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 3206 | if (current_link_up == 1 && |
| 3207 | tp->link_config.active_duplex == DUPLEX_FULL) |
| 3208 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | relink: |
Michael Chan | 6921d20 | 2005-12-13 21:15:53 -0800 | [diff] [blame] | 3212 | if (current_link_up == 0 || tp->link_config.phy_is_low_power) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | u32 tmp; |
| 3214 | |
| 3215 | tg3_phy_copper_begin(tp); |
| 3216 | |
| 3217 | tg3_readphy(tp, MII_BMSR, &tmp); |
| 3218 | if (!tg3_readphy(tp, MII_BMSR, &tmp) && |
| 3219 | (tmp & BMSR_LSTATUS)) |
| 3220 | current_link_up = 1; |
| 3221 | } |
| 3222 | |
| 3223 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 3224 | if (current_link_up == 1) { |
| 3225 | if (tp->link_config.active_speed == SPEED_100 || |
| 3226 | tp->link_config.active_speed == SPEED_10) |
| 3227 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 3228 | else |
| 3229 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 3230 | } else if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) |
| 3231 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 3232 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 3234 | |
| 3235 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 3236 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 3237 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 3238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3240 | if (current_link_up == 1 && |
| 3241 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3243 | else |
| 3244 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | /* ??? Without this setting Netgear GA302T PHY does not |
| 3248 | * ??? send/receive packets... |
| 3249 | */ |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3250 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
| 3252 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
| 3253 | tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 3254 | udelay(80); |
| 3255 | } |
| 3256 | |
| 3257 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3258 | udelay(40); |
| 3259 | |
| 3260 | if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) { |
| 3261 | /* Polled via timer. */ |
| 3262 | tw32_f(MAC_EVENT, 0); |
| 3263 | } else { |
| 3264 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 3265 | } |
| 3266 | udelay(40); |
| 3267 | |
| 3268 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && |
| 3269 | current_link_up == 1 && |
| 3270 | tp->link_config.active_speed == SPEED_1000 && |
| 3271 | ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) || |
| 3272 | (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) { |
| 3273 | udelay(120); |
| 3274 | tw32_f(MAC_STATUS, |
| 3275 | (MAC_STATUS_SYNC_CHANGED | |
| 3276 | MAC_STATUS_CFG_CHANGED)); |
| 3277 | udelay(40); |
| 3278 | tg3_write_mem(tp, |
| 3279 | NIC_SRAM_FIRMWARE_MBOX, |
| 3280 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); |
| 3281 | } |
| 3282 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 3283 | /* Prevent send BD corruption. */ |
| 3284 | if (tp->tg3_flags3 & TG3_FLG3_CLKREQ_BUG) { |
| 3285 | u16 oldlnkctl, newlnkctl; |
| 3286 | |
| 3287 | pci_read_config_word(tp->pdev, |
| 3288 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 3289 | &oldlnkctl); |
| 3290 | if (tp->link_config.active_speed == SPEED_100 || |
| 3291 | tp->link_config.active_speed == SPEED_10) |
| 3292 | newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3293 | else |
| 3294 | newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3295 | if (newlnkctl != oldlnkctl) |
| 3296 | pci_write_config_word(tp->pdev, |
| 3297 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 3298 | newlnkctl); |
| 3299 | } |
| 3300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 3302 | if (current_link_up) |
| 3303 | netif_carrier_on(tp->dev); |
| 3304 | else |
| 3305 | netif_carrier_off(tp->dev); |
| 3306 | tg3_link_report(tp); |
| 3307 | } |
| 3308 | |
| 3309 | return 0; |
| 3310 | } |
| 3311 | |
| 3312 | struct tg3_fiber_aneginfo { |
| 3313 | int state; |
| 3314 | #define ANEG_STATE_UNKNOWN 0 |
| 3315 | #define ANEG_STATE_AN_ENABLE 1 |
| 3316 | #define ANEG_STATE_RESTART_INIT 2 |
| 3317 | #define ANEG_STATE_RESTART 3 |
| 3318 | #define ANEG_STATE_DISABLE_LINK_OK 4 |
| 3319 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 |
| 3320 | #define ANEG_STATE_ABILITY_DETECT 6 |
| 3321 | #define ANEG_STATE_ACK_DETECT_INIT 7 |
| 3322 | #define ANEG_STATE_ACK_DETECT 8 |
| 3323 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 |
| 3324 | #define ANEG_STATE_COMPLETE_ACK 10 |
| 3325 | #define ANEG_STATE_IDLE_DETECT_INIT 11 |
| 3326 | #define ANEG_STATE_IDLE_DETECT 12 |
| 3327 | #define ANEG_STATE_LINK_OK 13 |
| 3328 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 |
| 3329 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 |
| 3330 | |
| 3331 | u32 flags; |
| 3332 | #define MR_AN_ENABLE 0x00000001 |
| 3333 | #define MR_RESTART_AN 0x00000002 |
| 3334 | #define MR_AN_COMPLETE 0x00000004 |
| 3335 | #define MR_PAGE_RX 0x00000008 |
| 3336 | #define MR_NP_LOADED 0x00000010 |
| 3337 | #define MR_TOGGLE_TX 0x00000020 |
| 3338 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 |
| 3339 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 |
| 3340 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 |
| 3341 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 |
| 3342 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 |
| 3343 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 |
| 3344 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 |
| 3345 | #define MR_TOGGLE_RX 0x00002000 |
| 3346 | #define MR_NP_RX 0x00004000 |
| 3347 | |
| 3348 | #define MR_LINK_OK 0x80000000 |
| 3349 | |
| 3350 | unsigned long link_time, cur_time; |
| 3351 | |
| 3352 | u32 ability_match_cfg; |
| 3353 | int ability_match_count; |
| 3354 | |
| 3355 | char ability_match, idle_match, ack_match; |
| 3356 | |
| 3357 | u32 txconfig, rxconfig; |
| 3358 | #define ANEG_CFG_NP 0x00000080 |
| 3359 | #define ANEG_CFG_ACK 0x00000040 |
| 3360 | #define ANEG_CFG_RF2 0x00000020 |
| 3361 | #define ANEG_CFG_RF1 0x00000010 |
| 3362 | #define ANEG_CFG_PS2 0x00000001 |
| 3363 | #define ANEG_CFG_PS1 0x00008000 |
| 3364 | #define ANEG_CFG_HD 0x00004000 |
| 3365 | #define ANEG_CFG_FD 0x00002000 |
| 3366 | #define ANEG_CFG_INVAL 0x00001f06 |
| 3367 | |
| 3368 | }; |
| 3369 | #define ANEG_OK 0 |
| 3370 | #define ANEG_DONE 1 |
| 3371 | #define ANEG_TIMER_ENAB 2 |
| 3372 | #define ANEG_FAILED -1 |
| 3373 | |
| 3374 | #define ANEG_STATE_SETTLE_TIME 10000 |
| 3375 | |
| 3376 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, |
| 3377 | struct tg3_fiber_aneginfo *ap) |
| 3378 | { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3379 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | unsigned long delta; |
| 3381 | u32 rx_cfg_reg; |
| 3382 | int ret; |
| 3383 | |
| 3384 | if (ap->state == ANEG_STATE_UNKNOWN) { |
| 3385 | ap->rxconfig = 0; |
| 3386 | ap->link_time = 0; |
| 3387 | ap->cur_time = 0; |
| 3388 | ap->ability_match_cfg = 0; |
| 3389 | ap->ability_match_count = 0; |
| 3390 | ap->ability_match = 0; |
| 3391 | ap->idle_match = 0; |
| 3392 | ap->ack_match = 0; |
| 3393 | } |
| 3394 | ap->cur_time++; |
| 3395 | |
| 3396 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { |
| 3397 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); |
| 3398 | |
| 3399 | if (rx_cfg_reg != ap->ability_match_cfg) { |
| 3400 | ap->ability_match_cfg = rx_cfg_reg; |
| 3401 | ap->ability_match = 0; |
| 3402 | ap->ability_match_count = 0; |
| 3403 | } else { |
| 3404 | if (++ap->ability_match_count > 1) { |
| 3405 | ap->ability_match = 1; |
| 3406 | ap->ability_match_cfg = rx_cfg_reg; |
| 3407 | } |
| 3408 | } |
| 3409 | if (rx_cfg_reg & ANEG_CFG_ACK) |
| 3410 | ap->ack_match = 1; |
| 3411 | else |
| 3412 | ap->ack_match = 0; |
| 3413 | |
| 3414 | ap->idle_match = 0; |
| 3415 | } else { |
| 3416 | ap->idle_match = 1; |
| 3417 | ap->ability_match_cfg = 0; |
| 3418 | ap->ability_match_count = 0; |
| 3419 | ap->ability_match = 0; |
| 3420 | ap->ack_match = 0; |
| 3421 | |
| 3422 | rx_cfg_reg = 0; |
| 3423 | } |
| 3424 | |
| 3425 | ap->rxconfig = rx_cfg_reg; |
| 3426 | ret = ANEG_OK; |
| 3427 | |
| 3428 | switch(ap->state) { |
| 3429 | case ANEG_STATE_UNKNOWN: |
| 3430 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) |
| 3431 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3432 | |
| 3433 | /* fallthru */ |
| 3434 | case ANEG_STATE_AN_ENABLE: |
| 3435 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); |
| 3436 | if (ap->flags & MR_AN_ENABLE) { |
| 3437 | ap->link_time = 0; |
| 3438 | ap->cur_time = 0; |
| 3439 | ap->ability_match_cfg = 0; |
| 3440 | ap->ability_match_count = 0; |
| 3441 | ap->ability_match = 0; |
| 3442 | ap->idle_match = 0; |
| 3443 | ap->ack_match = 0; |
| 3444 | |
| 3445 | ap->state = ANEG_STATE_RESTART_INIT; |
| 3446 | } else { |
| 3447 | ap->state = ANEG_STATE_DISABLE_LINK_OK; |
| 3448 | } |
| 3449 | break; |
| 3450 | |
| 3451 | case ANEG_STATE_RESTART_INIT: |
| 3452 | ap->link_time = ap->cur_time; |
| 3453 | ap->flags &= ~(MR_NP_LOADED); |
| 3454 | ap->txconfig = 0; |
| 3455 | tw32(MAC_TX_AUTO_NEG, 0); |
| 3456 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3457 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3458 | udelay(40); |
| 3459 | |
| 3460 | ret = ANEG_TIMER_ENAB; |
| 3461 | ap->state = ANEG_STATE_RESTART; |
| 3462 | |
| 3463 | /* fallthru */ |
| 3464 | case ANEG_STATE_RESTART: |
| 3465 | delta = ap->cur_time - ap->link_time; |
| 3466 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 3467 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
| 3468 | } else { |
| 3469 | ret = ANEG_TIMER_ENAB; |
| 3470 | } |
| 3471 | break; |
| 3472 | |
| 3473 | case ANEG_STATE_DISABLE_LINK_OK: |
| 3474 | ret = ANEG_DONE; |
| 3475 | break; |
| 3476 | |
| 3477 | case ANEG_STATE_ABILITY_DETECT_INIT: |
| 3478 | ap->flags &= ~(MR_TOGGLE_TX); |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3479 | ap->txconfig = ANEG_CFG_FD; |
| 3480 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 3481 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 3482 | ap->txconfig |= ANEG_CFG_PS1; |
| 3483 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 3484 | ap->txconfig |= ANEG_CFG_PS2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 3486 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3487 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3488 | udelay(40); |
| 3489 | |
| 3490 | ap->state = ANEG_STATE_ABILITY_DETECT; |
| 3491 | break; |
| 3492 | |
| 3493 | case ANEG_STATE_ABILITY_DETECT: |
| 3494 | if (ap->ability_match != 0 && ap->rxconfig != 0) { |
| 3495 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
| 3496 | } |
| 3497 | break; |
| 3498 | |
| 3499 | case ANEG_STATE_ACK_DETECT_INIT: |
| 3500 | ap->txconfig |= ANEG_CFG_ACK; |
| 3501 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 3502 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 3503 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3504 | udelay(40); |
| 3505 | |
| 3506 | ap->state = ANEG_STATE_ACK_DETECT; |
| 3507 | |
| 3508 | /* fallthru */ |
| 3509 | case ANEG_STATE_ACK_DETECT: |
| 3510 | if (ap->ack_match != 0) { |
| 3511 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == |
| 3512 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { |
| 3513 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; |
| 3514 | } else { |
| 3515 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3516 | } |
| 3517 | } else if (ap->ability_match != 0 && |
| 3518 | ap->rxconfig == 0) { |
| 3519 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3520 | } |
| 3521 | break; |
| 3522 | |
| 3523 | case ANEG_STATE_COMPLETE_ACK_INIT: |
| 3524 | if (ap->rxconfig & ANEG_CFG_INVAL) { |
| 3525 | ret = ANEG_FAILED; |
| 3526 | break; |
| 3527 | } |
| 3528 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | |
| 3529 | MR_LP_ADV_HALF_DUPLEX | |
| 3530 | MR_LP_ADV_SYM_PAUSE | |
| 3531 | MR_LP_ADV_ASYM_PAUSE | |
| 3532 | MR_LP_ADV_REMOTE_FAULT1 | |
| 3533 | MR_LP_ADV_REMOTE_FAULT2 | |
| 3534 | MR_LP_ADV_NEXT_PAGE | |
| 3535 | MR_TOGGLE_RX | |
| 3536 | MR_NP_RX); |
| 3537 | if (ap->rxconfig & ANEG_CFG_FD) |
| 3538 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; |
| 3539 | if (ap->rxconfig & ANEG_CFG_HD) |
| 3540 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; |
| 3541 | if (ap->rxconfig & ANEG_CFG_PS1) |
| 3542 | ap->flags |= MR_LP_ADV_SYM_PAUSE; |
| 3543 | if (ap->rxconfig & ANEG_CFG_PS2) |
| 3544 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; |
| 3545 | if (ap->rxconfig & ANEG_CFG_RF1) |
| 3546 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; |
| 3547 | if (ap->rxconfig & ANEG_CFG_RF2) |
| 3548 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; |
| 3549 | if (ap->rxconfig & ANEG_CFG_NP) |
| 3550 | ap->flags |= MR_LP_ADV_NEXT_PAGE; |
| 3551 | |
| 3552 | ap->link_time = ap->cur_time; |
| 3553 | |
| 3554 | ap->flags ^= (MR_TOGGLE_TX); |
| 3555 | if (ap->rxconfig & 0x0008) |
| 3556 | ap->flags |= MR_TOGGLE_RX; |
| 3557 | if (ap->rxconfig & ANEG_CFG_NP) |
| 3558 | ap->flags |= MR_NP_RX; |
| 3559 | ap->flags |= MR_PAGE_RX; |
| 3560 | |
| 3561 | ap->state = ANEG_STATE_COMPLETE_ACK; |
| 3562 | ret = ANEG_TIMER_ENAB; |
| 3563 | break; |
| 3564 | |
| 3565 | case ANEG_STATE_COMPLETE_ACK: |
| 3566 | if (ap->ability_match != 0 && |
| 3567 | ap->rxconfig == 0) { |
| 3568 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3569 | break; |
| 3570 | } |
| 3571 | delta = ap->cur_time - ap->link_time; |
| 3572 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 3573 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { |
| 3574 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 3575 | } else { |
| 3576 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && |
| 3577 | !(ap->flags & MR_NP_RX)) { |
| 3578 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 3579 | } else { |
| 3580 | ret = ANEG_FAILED; |
| 3581 | } |
| 3582 | } |
| 3583 | } |
| 3584 | break; |
| 3585 | |
| 3586 | case ANEG_STATE_IDLE_DETECT_INIT: |
| 3587 | ap->link_time = ap->cur_time; |
| 3588 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 3589 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3590 | udelay(40); |
| 3591 | |
| 3592 | ap->state = ANEG_STATE_IDLE_DETECT; |
| 3593 | ret = ANEG_TIMER_ENAB; |
| 3594 | break; |
| 3595 | |
| 3596 | case ANEG_STATE_IDLE_DETECT: |
| 3597 | if (ap->ability_match != 0 && |
| 3598 | ap->rxconfig == 0) { |
| 3599 | ap->state = ANEG_STATE_AN_ENABLE; |
| 3600 | break; |
| 3601 | } |
| 3602 | delta = ap->cur_time - ap->link_time; |
| 3603 | if (delta > ANEG_STATE_SETTLE_TIME) { |
| 3604 | /* XXX another gem from the Broadcom driver :( */ |
| 3605 | ap->state = ANEG_STATE_LINK_OK; |
| 3606 | } |
| 3607 | break; |
| 3608 | |
| 3609 | case ANEG_STATE_LINK_OK: |
| 3610 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); |
| 3611 | ret = ANEG_DONE; |
| 3612 | break; |
| 3613 | |
| 3614 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: |
| 3615 | /* ??? unimplemented */ |
| 3616 | break; |
| 3617 | |
| 3618 | case ANEG_STATE_NEXT_PAGE_WAIT: |
| 3619 | /* ??? unimplemented */ |
| 3620 | break; |
| 3621 | |
| 3622 | default: |
| 3623 | ret = ANEG_FAILED; |
| 3624 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 3625 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | |
| 3627 | return ret; |
| 3628 | } |
| 3629 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3630 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | { |
| 3632 | int res = 0; |
| 3633 | struct tg3_fiber_aneginfo aninfo; |
| 3634 | int status = ANEG_FAILED; |
| 3635 | unsigned int tick; |
| 3636 | u32 tmp; |
| 3637 | |
| 3638 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 3639 | |
| 3640 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
| 3641 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); |
| 3642 | udelay(40); |
| 3643 | |
| 3644 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); |
| 3645 | udelay(40); |
| 3646 | |
| 3647 | memset(&aninfo, 0, sizeof(aninfo)); |
| 3648 | aninfo.flags |= MR_AN_ENABLE; |
| 3649 | aninfo.state = ANEG_STATE_UNKNOWN; |
| 3650 | aninfo.cur_time = 0; |
| 3651 | tick = 0; |
| 3652 | while (++tick < 195000) { |
| 3653 | status = tg3_fiber_aneg_smachine(tp, &aninfo); |
| 3654 | if (status == ANEG_DONE || status == ANEG_FAILED) |
| 3655 | break; |
| 3656 | |
| 3657 | udelay(1); |
| 3658 | } |
| 3659 | |
| 3660 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 3661 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3662 | udelay(40); |
| 3663 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3664 | *txflags = aninfo.txconfig; |
| 3665 | *rxflags = aninfo.flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | |
| 3667 | if (status == ANEG_DONE && |
| 3668 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | |
| 3669 | MR_LP_ADV_FULL_DUPLEX))) |
| 3670 | res = 1; |
| 3671 | |
| 3672 | return res; |
| 3673 | } |
| 3674 | |
| 3675 | static void tg3_init_bcm8002(struct tg3 *tp) |
| 3676 | { |
| 3677 | u32 mac_status = tr32(MAC_STATUS); |
| 3678 | int i; |
| 3679 | |
| 3680 | /* Reset when initting first time or we have a link. */ |
| 3681 | if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) && |
| 3682 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 3683 | return; |
| 3684 | |
| 3685 | /* Set PLL lock range. */ |
| 3686 | tg3_writephy(tp, 0x16, 0x8007); |
| 3687 | |
| 3688 | /* SW reset */ |
| 3689 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); |
| 3690 | |
| 3691 | /* Wait for reset to complete. */ |
| 3692 | /* XXX schedule_timeout() ... */ |
| 3693 | for (i = 0; i < 500; i++) |
| 3694 | udelay(10); |
| 3695 | |
| 3696 | /* Config mode; select PMA/Ch 1 regs. */ |
| 3697 | tg3_writephy(tp, 0x10, 0x8411); |
| 3698 | |
| 3699 | /* Enable auto-lock and comdet, select txclk for tx. */ |
| 3700 | tg3_writephy(tp, 0x11, 0x0a10); |
| 3701 | |
| 3702 | tg3_writephy(tp, 0x18, 0x00a0); |
| 3703 | tg3_writephy(tp, 0x16, 0x41ff); |
| 3704 | |
| 3705 | /* Assert and deassert POR. */ |
| 3706 | tg3_writephy(tp, 0x13, 0x0400); |
| 3707 | udelay(40); |
| 3708 | tg3_writephy(tp, 0x13, 0x0000); |
| 3709 | |
| 3710 | tg3_writephy(tp, 0x11, 0x0a50); |
| 3711 | udelay(40); |
| 3712 | tg3_writephy(tp, 0x11, 0x0a10); |
| 3713 | |
| 3714 | /* Wait for signal to stabilize */ |
| 3715 | /* XXX schedule_timeout() ... */ |
| 3716 | for (i = 0; i < 15000; i++) |
| 3717 | udelay(10); |
| 3718 | |
| 3719 | /* Deselect the channel register so we can read the PHYID |
| 3720 | * later. |
| 3721 | */ |
| 3722 | tg3_writephy(tp, 0x10, 0x8011); |
| 3723 | } |
| 3724 | |
| 3725 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
| 3726 | { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3727 | u16 flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | u32 sg_dig_ctrl, sg_dig_status; |
| 3729 | u32 serdes_cfg, expected_sg_dig_ctrl; |
| 3730 | int workaround, port_a; |
| 3731 | int current_link_up; |
| 3732 | |
| 3733 | serdes_cfg = 0; |
| 3734 | expected_sg_dig_ctrl = 0; |
| 3735 | workaround = 0; |
| 3736 | port_a = 1; |
| 3737 | current_link_up = 0; |
| 3738 | |
| 3739 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && |
| 3740 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { |
| 3741 | workaround = 1; |
| 3742 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 3743 | port_a = 0; |
| 3744 | |
| 3745 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ |
| 3746 | /* preserve bits 20-23 for voltage regulator */ |
| 3747 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; |
| 3748 | } |
| 3749 | |
| 3750 | sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 3751 | |
| 3752 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3753 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | if (workaround) { |
| 3755 | u32 val = serdes_cfg; |
| 3756 | |
| 3757 | if (port_a) |
| 3758 | val |= 0xc010000; |
| 3759 | else |
| 3760 | val |= 0x4010000; |
| 3761 | tw32_f(MAC_SERDES_CFG, val); |
| 3762 | } |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3763 | |
| 3764 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | } |
| 3766 | if (mac_status & MAC_STATUS_PCS_SYNCED) { |
| 3767 | tg3_setup_flow_control(tp, 0, 0); |
| 3768 | current_link_up = 1; |
| 3769 | } |
| 3770 | goto out; |
| 3771 | } |
| 3772 | |
| 3773 | /* Want auto-negotiation. */ |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3774 | 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] | 3775 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3776 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 3777 | if (flowctrl & ADVERTISE_1000XPAUSE) |
| 3778 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; |
| 3779 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 3780 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | |
| 3782 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3783 | if ((tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT) && |
| 3784 | tp->serdes_counter && |
| 3785 | ((mac_status & (MAC_STATUS_PCS_SYNCED | |
| 3786 | MAC_STATUS_RCVD_CFG)) == |
| 3787 | MAC_STATUS_PCS_SYNCED)) { |
| 3788 | tp->serdes_counter--; |
| 3789 | current_link_up = 1; |
| 3790 | goto out; |
| 3791 | } |
| 3792 | restart_autoneg: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | if (workaround) |
| 3794 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3795 | 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] | 3796 | udelay(5); |
| 3797 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); |
| 3798 | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3799 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
| 3800 | tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
| 3802 | MAC_STATUS_SIGNAL_DET)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3803 | sg_dig_status = tr32(SG_DIG_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | mac_status = tr32(MAC_STATUS); |
| 3805 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3806 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3808 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3810 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) |
| 3811 | local_adv |= ADVERTISE_1000XPAUSE; |
| 3812 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) |
| 3813 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 3814 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3815 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3816 | remote_adv |= LPA_1000XPAUSE; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3817 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
Matt Carlson | 82cd3d1 | 2007-12-20 20:09:00 -0800 | [diff] [blame] | 3818 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | |
| 3820 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 3821 | current_link_up = 1; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3822 | tp->serdes_counter = 0; |
| 3823 | tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT; |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3824 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3825 | if (tp->serdes_counter) |
| 3826 | tp->serdes_counter--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | else { |
| 3828 | if (workaround) { |
| 3829 | u32 val = serdes_cfg; |
| 3830 | |
| 3831 | if (port_a) |
| 3832 | val |= 0xc010000; |
| 3833 | else |
| 3834 | val |= 0x4010000; |
| 3835 | |
| 3836 | tw32_f(MAC_SERDES_CFG, val); |
| 3837 | } |
| 3838 | |
Matt Carlson | c98f6e3 | 2007-12-20 20:08:32 -0800 | [diff] [blame] | 3839 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | udelay(40); |
| 3841 | |
| 3842 | /* Link parallel detection - link is up */ |
| 3843 | /* only if we have PCS_SYNC and not */ |
| 3844 | /* receiving config code words */ |
| 3845 | mac_status = tr32(MAC_STATUS); |
| 3846 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && |
| 3847 | !(mac_status & MAC_STATUS_RCVD_CFG)) { |
| 3848 | tg3_setup_flow_control(tp, 0, 0); |
| 3849 | current_link_up = 1; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3850 | tp->tg3_flags2 |= |
| 3851 | TG3_FLG2_PARALLEL_DETECT; |
| 3852 | tp->serdes_counter = |
| 3853 | SERDES_PARALLEL_DET_TIMEOUT; |
| 3854 | } else |
| 3855 | goto restart_autoneg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | } |
| 3857 | } |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3858 | } else { |
| 3859 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
| 3860 | tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | out: |
| 3864 | return current_link_up; |
| 3865 | } |
| 3866 | |
| 3867 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
| 3868 | { |
| 3869 | int current_link_up = 0; |
| 3870 | |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 3871 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | |
| 3874 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3875 | u32 txflags, rxflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3877 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3878 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
| 3879 | u32 local_adv = 0, remote_adv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3881 | if (txflags & ANEG_CFG_PS1) |
| 3882 | local_adv |= ADVERTISE_1000XPAUSE; |
| 3883 | if (txflags & ANEG_CFG_PS2) |
| 3884 | local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 3885 | |
| 3886 | if (rxflags & MR_LP_ADV_SYM_PAUSE) |
| 3887 | remote_adv |= LPA_1000XPAUSE; |
| 3888 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) |
| 3889 | remote_adv |= LPA_1000XPAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | |
| 3891 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 3892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | current_link_up = 1; |
| 3894 | } |
| 3895 | for (i = 0; i < 30; i++) { |
| 3896 | udelay(20); |
| 3897 | tw32_f(MAC_STATUS, |
| 3898 | (MAC_STATUS_SYNC_CHANGED | |
| 3899 | MAC_STATUS_CFG_CHANGED)); |
| 3900 | udelay(40); |
| 3901 | if ((tr32(MAC_STATUS) & |
| 3902 | (MAC_STATUS_SYNC_CHANGED | |
| 3903 | MAC_STATUS_CFG_CHANGED)) == 0) |
| 3904 | break; |
| 3905 | } |
| 3906 | |
| 3907 | mac_status = tr32(MAC_STATUS); |
| 3908 | if (current_link_up == 0 && |
| 3909 | (mac_status & MAC_STATUS_PCS_SYNCED) && |
| 3910 | !(mac_status & MAC_STATUS_RCVD_CFG)) |
| 3911 | current_link_up = 1; |
| 3912 | } else { |
Matt Carlson | 5be73b4 | 2007-12-20 20:09:29 -0800 | [diff] [blame] | 3913 | tg3_setup_flow_control(tp, 0, 0); |
| 3914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | /* Forcing 1000FD link up. */ |
| 3916 | current_link_up = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | |
| 3918 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); |
| 3919 | udelay(40); |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 3920 | |
| 3921 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3922 | udelay(40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | out: |
| 3926 | return current_link_up; |
| 3927 | } |
| 3928 | |
| 3929 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) |
| 3930 | { |
| 3931 | u32 orig_pause_cfg; |
| 3932 | u16 orig_active_speed; |
| 3933 | u8 orig_active_duplex; |
| 3934 | u32 mac_status; |
| 3935 | int current_link_up; |
| 3936 | int i; |
| 3937 | |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 3938 | orig_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | orig_active_speed = tp->link_config.active_speed; |
| 3940 | orig_active_duplex = tp->link_config.active_duplex; |
| 3941 | |
| 3942 | if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) && |
| 3943 | netif_carrier_ok(tp->dev) && |
| 3944 | (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) { |
| 3945 | mac_status = tr32(MAC_STATUS); |
| 3946 | mac_status &= (MAC_STATUS_PCS_SYNCED | |
| 3947 | MAC_STATUS_SIGNAL_DET | |
| 3948 | MAC_STATUS_CFG_CHANGED | |
| 3949 | MAC_STATUS_RCVD_CFG); |
| 3950 | if (mac_status == (MAC_STATUS_PCS_SYNCED | |
| 3951 | MAC_STATUS_SIGNAL_DET)) { |
| 3952 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 3953 | MAC_STATUS_CFG_CHANGED)); |
| 3954 | return 0; |
| 3955 | } |
| 3956 | } |
| 3957 | |
| 3958 | tw32_f(MAC_TX_AUTO_NEG, 0); |
| 3959 | |
| 3960 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 3961 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 3962 | tw32_f(MAC_MODE, tp->mac_mode); |
| 3963 | udelay(40); |
| 3964 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 3965 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | tg3_init_bcm8002(tp); |
| 3967 | |
| 3968 | /* Enable link change event even when serdes polling. */ |
| 3969 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 3970 | udelay(40); |
| 3971 | |
| 3972 | current_link_up = 0; |
| 3973 | mac_status = tr32(MAC_STATUS); |
| 3974 | |
| 3975 | if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) |
| 3976 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
| 3977 | else |
| 3978 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); |
| 3979 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 3980 | tp->napi[0].hw_status->status = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | (SD_STATUS_UPDATED | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 3982 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | |
| 3984 | for (i = 0; i < 100; i++) { |
| 3985 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 3986 | MAC_STATUS_CFG_CHANGED)); |
| 3987 | udelay(5); |
| 3988 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3989 | MAC_STATUS_CFG_CHANGED | |
| 3990 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | break; |
| 3992 | } |
| 3993 | |
| 3994 | mac_status = tr32(MAC_STATUS); |
| 3995 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { |
| 3996 | current_link_up = 0; |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 3997 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 3998 | tp->serdes_counter == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | tw32_f(MAC_MODE, (tp->mac_mode | |
| 4000 | MAC_MODE_SEND_CONFIGS)); |
| 4001 | udelay(1); |
| 4002 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4003 | } |
| 4004 | } |
| 4005 | |
| 4006 | if (current_link_up == 1) { |
| 4007 | tp->link_config.active_speed = SPEED_1000; |
| 4008 | tp->link_config.active_duplex = DUPLEX_FULL; |
| 4009 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 4010 | LED_CTRL_LNKLED_OVERRIDE | |
| 4011 | LED_CTRL_1000MBPS_ON)); |
| 4012 | } else { |
| 4013 | tp->link_config.active_speed = SPEED_INVALID; |
| 4014 | tp->link_config.active_duplex = DUPLEX_INVALID; |
| 4015 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 4016 | LED_CTRL_LNKLED_OVERRIDE | |
| 4017 | LED_CTRL_TRAFFIC_OVERRIDE)); |
| 4018 | } |
| 4019 | |
| 4020 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 4021 | if (current_link_up) |
| 4022 | netif_carrier_on(tp->dev); |
| 4023 | else |
| 4024 | netif_carrier_off(tp->dev); |
| 4025 | tg3_link_report(tp); |
| 4026 | } else { |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 4027 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | if (orig_pause_cfg != now_pause_cfg || |
| 4029 | orig_active_speed != tp->link_config.active_speed || |
| 4030 | orig_active_duplex != tp->link_config.active_duplex) |
| 4031 | tg3_link_report(tp); |
| 4032 | } |
| 4033 | |
| 4034 | return 0; |
| 4035 | } |
| 4036 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4037 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
| 4038 | { |
| 4039 | int current_link_up, err = 0; |
| 4040 | u32 bmsr, bmcr; |
| 4041 | u16 current_speed; |
| 4042 | u8 current_duplex; |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4043 | u32 local_adv, remote_adv; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4044 | |
| 4045 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4046 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4047 | udelay(40); |
| 4048 | |
| 4049 | tw32(MAC_EVENT, 0); |
| 4050 | |
| 4051 | tw32_f(MAC_STATUS, |
| 4052 | (MAC_STATUS_SYNC_CHANGED | |
| 4053 | MAC_STATUS_CFG_CHANGED | |
| 4054 | MAC_STATUS_MI_COMPLETION | |
| 4055 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4056 | udelay(40); |
| 4057 | |
| 4058 | if (force_reset) |
| 4059 | tg3_phy_reset(tp); |
| 4060 | |
| 4061 | current_link_up = 0; |
| 4062 | current_speed = SPEED_INVALID; |
| 4063 | current_duplex = DUPLEX_INVALID; |
| 4064 | |
| 4065 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4066 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 4067 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 4068 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 4069 | bmsr |= BMSR_LSTATUS; |
| 4070 | else |
| 4071 | bmsr &= ~BMSR_LSTATUS; |
| 4072 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4073 | |
| 4074 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4075 | |
| 4076 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && |
Matt Carlson | 2bd3ed0 | 2008-06-09 15:39:55 -0700 | [diff] [blame] | 4077 | (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4078 | /* do nothing, just check for link up at the end */ |
| 4079 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 4080 | u32 adv, new_adv; |
| 4081 | |
| 4082 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 4083 | new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
| 4084 | ADVERTISE_1000XPAUSE | |
| 4085 | ADVERTISE_1000XPSE_ASYM | |
| 4086 | ADVERTISE_SLCT); |
| 4087 | |
Matt Carlson | ba4d07a | 2007-12-20 20:08:00 -0800 | [diff] [blame] | 4088 | new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4089 | |
| 4090 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) |
| 4091 | new_adv |= ADVERTISE_1000XHALF; |
| 4092 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) |
| 4093 | new_adv |= ADVERTISE_1000XFULL; |
| 4094 | |
| 4095 | if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) { |
| 4096 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 4097 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 4098 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 4099 | |
| 4100 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4101 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4102 | tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT; |
| 4103 | |
| 4104 | return err; |
| 4105 | } |
| 4106 | } else { |
| 4107 | u32 new_bmcr; |
| 4108 | |
| 4109 | bmcr &= ~BMCR_SPEED1000; |
| 4110 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); |
| 4111 | |
| 4112 | if (tp->link_config.duplex == DUPLEX_FULL) |
| 4113 | new_bmcr |= BMCR_FULLDPLX; |
| 4114 | |
| 4115 | if (new_bmcr != bmcr) { |
| 4116 | /* BMCR_SPEED1000 is a reserved bit that needs |
| 4117 | * to be set on write. |
| 4118 | */ |
| 4119 | new_bmcr |= BMCR_SPEED1000; |
| 4120 | |
| 4121 | /* Force a linkdown */ |
| 4122 | if (netif_carrier_ok(tp->dev)) { |
| 4123 | u32 adv; |
| 4124 | |
| 4125 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 4126 | adv &= ~(ADVERTISE_1000XFULL | |
| 4127 | ADVERTISE_1000XHALF | |
| 4128 | ADVERTISE_SLCT); |
| 4129 | tg3_writephy(tp, MII_ADVERTISE, adv); |
| 4130 | tg3_writephy(tp, MII_BMCR, bmcr | |
| 4131 | BMCR_ANRESTART | |
| 4132 | BMCR_ANENABLE); |
| 4133 | udelay(10); |
| 4134 | netif_carrier_off(tp->dev); |
| 4135 | } |
| 4136 | tg3_writephy(tp, MII_BMCR, new_bmcr); |
| 4137 | bmcr = new_bmcr; |
| 4138 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4139 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 4140 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 4141 | ASIC_REV_5714) { |
| 4142 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 4143 | bmsr |= BMSR_LSTATUS; |
| 4144 | else |
| 4145 | bmsr &= ~BMSR_LSTATUS; |
| 4146 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4147 | tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT; |
| 4148 | } |
| 4149 | } |
| 4150 | |
| 4151 | if (bmsr & BMSR_LSTATUS) { |
| 4152 | current_speed = SPEED_1000; |
| 4153 | current_link_up = 1; |
| 4154 | if (bmcr & BMCR_FULLDPLX) |
| 4155 | current_duplex = DUPLEX_FULL; |
| 4156 | else |
| 4157 | current_duplex = DUPLEX_HALF; |
| 4158 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4159 | local_adv = 0; |
| 4160 | remote_adv = 0; |
| 4161 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4162 | if (bmcr & BMCR_ANENABLE) { |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4163 | u32 common; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4164 | |
| 4165 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); |
| 4166 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); |
| 4167 | common = local_adv & remote_adv; |
| 4168 | if (common & (ADVERTISE_1000XHALF | |
| 4169 | ADVERTISE_1000XFULL)) { |
| 4170 | if (common & ADVERTISE_1000XFULL) |
| 4171 | current_duplex = DUPLEX_FULL; |
| 4172 | else |
| 4173 | current_duplex = DUPLEX_HALF; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4174 | } |
| 4175 | else |
| 4176 | current_link_up = 0; |
| 4177 | } |
| 4178 | } |
| 4179 | |
Matt Carlson | ef167e2 | 2007-12-20 20:10:01 -0800 | [diff] [blame] | 4180 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
| 4181 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 4182 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4183 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 4184 | if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 4185 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 4186 | |
| 4187 | tw32_f(MAC_MODE, tp->mac_mode); |
| 4188 | udelay(40); |
| 4189 | |
| 4190 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 4191 | |
| 4192 | tp->link_config.active_speed = current_speed; |
| 4193 | tp->link_config.active_duplex = current_duplex; |
| 4194 | |
| 4195 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
| 4196 | if (current_link_up) |
| 4197 | netif_carrier_on(tp->dev); |
| 4198 | else { |
| 4199 | netif_carrier_off(tp->dev); |
| 4200 | tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT; |
| 4201 | } |
| 4202 | tg3_link_report(tp); |
| 4203 | } |
| 4204 | return err; |
| 4205 | } |
| 4206 | |
| 4207 | static void tg3_serdes_parallel_detect(struct tg3 *tp) |
| 4208 | { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4209 | if (tp->serdes_counter) { |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4210 | /* Give autoneg time to complete. */ |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 4211 | tp->serdes_counter--; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4212 | return; |
| 4213 | } |
| 4214 | if (!netif_carrier_ok(tp->dev) && |
| 4215 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { |
| 4216 | u32 bmcr; |
| 4217 | |
| 4218 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4219 | if (bmcr & BMCR_ANENABLE) { |
| 4220 | u32 phy1, phy2; |
| 4221 | |
| 4222 | /* Select shadow register 0x1f */ |
| 4223 | tg3_writephy(tp, 0x1c, 0x7c00); |
| 4224 | tg3_readphy(tp, 0x1c, &phy1); |
| 4225 | |
| 4226 | /* Select expansion interrupt status register */ |
| 4227 | tg3_writephy(tp, 0x17, 0x0f01); |
| 4228 | tg3_readphy(tp, 0x15, &phy2); |
| 4229 | tg3_readphy(tp, 0x15, &phy2); |
| 4230 | |
| 4231 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { |
| 4232 | /* We have signal detect and not receiving |
| 4233 | * config code words, link is up by parallel |
| 4234 | * detection. |
| 4235 | */ |
| 4236 | |
| 4237 | bmcr &= ~BMCR_ANENABLE; |
| 4238 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; |
| 4239 | tg3_writephy(tp, MII_BMCR, bmcr); |
| 4240 | tp->tg3_flags2 |= TG3_FLG2_PARALLEL_DETECT; |
| 4241 | } |
| 4242 | } |
| 4243 | } |
| 4244 | else if (netif_carrier_ok(tp->dev) && |
| 4245 | (tp->link_config.autoneg == AUTONEG_ENABLE) && |
| 4246 | (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT)) { |
| 4247 | u32 phy2; |
| 4248 | |
| 4249 | /* Select expansion interrupt status register */ |
| 4250 | tg3_writephy(tp, 0x17, 0x0f01); |
| 4251 | tg3_readphy(tp, 0x15, &phy2); |
| 4252 | if (phy2 & 0x20) { |
| 4253 | u32 bmcr; |
| 4254 | |
| 4255 | /* Config code words received, turn on autoneg. */ |
| 4256 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4257 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); |
| 4258 | |
| 4259 | tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT; |
| 4260 | |
| 4261 | } |
| 4262 | } |
| 4263 | } |
| 4264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
| 4266 | { |
| 4267 | int err; |
| 4268 | |
| 4269 | if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) { |
| 4270 | err = tg3_setup_fiber_phy(tp, force_reset); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 4271 | } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) { |
| 4272 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | } else { |
| 4274 | err = tg3_setup_copper_phy(tp, force_reset); |
| 4275 | } |
| 4276 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 4277 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | aa6c91f | 2007-11-12 21:18:04 -0800 | [diff] [blame] | 4278 | u32 val, scale; |
| 4279 | |
| 4280 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; |
| 4281 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) |
| 4282 | scale = 65; |
| 4283 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) |
| 4284 | scale = 6; |
| 4285 | else |
| 4286 | scale = 12; |
| 4287 | |
| 4288 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; |
| 4289 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 4290 | tw32(GRC_MISC_CFG, val); |
| 4291 | } |
| 4292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | if (tp->link_config.active_speed == SPEED_1000 && |
| 4294 | tp->link_config.active_duplex == DUPLEX_HALF) |
| 4295 | tw32(MAC_TX_LENGTHS, |
| 4296 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 4297 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 4298 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 4299 | else |
| 4300 | tw32(MAC_TX_LENGTHS, |
| 4301 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 4302 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 4303 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 4304 | |
| 4305 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 4306 | if (netif_carrier_ok(tp->dev)) { |
| 4307 | tw32(HOSTCC_STAT_COAL_TICKS, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 4308 | tp->coal.stats_block_coalesce_usecs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | } else { |
| 4310 | tw32(HOSTCC_STAT_COAL_TICKS, 0); |
| 4311 | } |
| 4312 | } |
| 4313 | |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 4314 | if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) { |
| 4315 | u32 val = tr32(PCIE_PWR_MGMT_THRESH); |
| 4316 | if (!netif_carrier_ok(tp->dev)) |
| 4317 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
| 4318 | tp->pwrmgmt_thresh; |
| 4319 | else |
| 4320 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 4321 | tw32(PCIE_PWR_MGMT_THRESH, val); |
| 4322 | } |
| 4323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | return err; |
| 4325 | } |
| 4326 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4327 | /* This is called whenever we suspect that the system chipset is re- |
| 4328 | * ordering the sequence of MMIO to the tx send mailbox. The symptom |
| 4329 | * is bogus tx completions. We try to recover by setting the |
| 4330 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later |
| 4331 | * in the workqueue. |
| 4332 | */ |
| 4333 | static void tg3_tx_recover(struct tg3 *tp) |
| 4334 | { |
| 4335 | BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) || |
| 4336 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
| 4337 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 4338 | netdev_warn(tp->dev, "The system may be re-ordering memory-mapped I/O cycles to the network device, attempting to recover\n" |
| 4339 | "Please report the problem to the driver maintainer and include system chipset information.\n"); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4340 | |
| 4341 | spin_lock(&tp->lock); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4342 | tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4343 | spin_unlock(&tp->lock); |
| 4344 | } |
| 4345 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4346 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4347 | { |
| 4348 | smp_mb(); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4349 | return tnapi->tx_pending - |
| 4350 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4351 | } |
| 4352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | /* Tigon3 never reports partial packet sends. So we do not |
| 4354 | * need special logic to handle SKBs that have not had all |
| 4355 | * of their frags sent yet, like SunGEM does. |
| 4356 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4357 | static void tg3_tx(struct tg3_napi *tnapi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4359 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 4360 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4361 | u32 sw_idx = tnapi->tx_cons; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4362 | struct netdev_queue *txq; |
| 4363 | int index = tnapi - tp->napi; |
| 4364 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 4365 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4366 | index--; |
| 4367 | |
| 4368 | txq = netdev_get_tx_queue(tp->dev, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | |
| 4370 | while (sw_idx != hw_idx) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4371 | struct ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4372 | struct sk_buff *skb = ri->skb; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4373 | int i, tx_bug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4375 | if (unlikely(skb == NULL)) { |
| 4376 | tg3_tx_recover(tp); |
| 4377 | return; |
| 4378 | } |
| 4379 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4380 | pci_unmap_single(tp->pdev, |
| 4381 | pci_unmap_addr(ri, mapping), |
| 4382 | skb_headlen(skb), |
| 4383 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | |
| 4385 | ri->skb = NULL; |
| 4386 | |
| 4387 | sw_idx = NEXT_TX(sw_idx); |
| 4388 | |
| 4389 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4390 | ri = &tnapi->tx_buffers[sw_idx]; |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4391 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
| 4392 | tx_bug = 1; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 4393 | |
| 4394 | pci_unmap_page(tp->pdev, |
| 4395 | pci_unmap_addr(ri, mapping), |
| 4396 | skb_shinfo(skb)->frags[i].size, |
| 4397 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | sw_idx = NEXT_TX(sw_idx); |
| 4399 | } |
| 4400 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 4401 | dev_kfree_skb(skb); |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 4402 | |
| 4403 | if (unlikely(tx_bug)) { |
| 4404 | tg3_tx_recover(tp); |
| 4405 | return; |
| 4406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | } |
| 4408 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4409 | tnapi->tx_cons = sw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | |
Michael Chan | 1b2a720 | 2006-08-07 21:46:02 -0700 | [diff] [blame] | 4411 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
| 4412 | * before checking for netif_queue_stopped(). Without the |
| 4413 | * memory barrier, there is a small possibility that tg3_start_xmit() |
| 4414 | * will miss it and cause the queue to be stopped forever. |
| 4415 | */ |
| 4416 | smp_mb(); |
| 4417 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4418 | if (unlikely(netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4419 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4420 | __netif_tx_lock(txq, smp_processor_id()); |
| 4421 | if (netif_tx_queue_stopped(txq) && |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4422 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 4423 | netif_tx_wake_queue(txq); |
| 4424 | __netif_tx_unlock(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 4425 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | } |
| 4427 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 4428 | static void tg3_rx_skb_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
| 4429 | { |
| 4430 | if (!ri->skb) |
| 4431 | return; |
| 4432 | |
| 4433 | pci_unmap_single(tp->pdev, pci_unmap_addr(ri, mapping), |
| 4434 | map_sz, PCI_DMA_FROMDEVICE); |
| 4435 | dev_kfree_skb_any(ri->skb); |
| 4436 | ri->skb = NULL; |
| 4437 | } |
| 4438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | /* Returns size of skb allocated or < 0 on error. |
| 4440 | * |
| 4441 | * We only need to fill in the address because the other members |
| 4442 | * of the RX descriptor are invariant, see tg3_init_rings. |
| 4443 | * |
| 4444 | * Note the purposeful assymetry of cpu vs. chip accesses. For |
| 4445 | * posting buffers we only dirty the first cache line of the RX |
| 4446 | * descriptor (containing the address). Whereas for the RX status |
| 4447 | * buffers the cpu only reads the last cacheline of the RX descriptor |
| 4448 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). |
| 4449 | */ |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 4450 | 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] | 4451 | u32 opaque_key, u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | { |
| 4453 | struct tg3_rx_buffer_desc *desc; |
| 4454 | struct ring_info *map, *src_map; |
| 4455 | struct sk_buff *skb; |
| 4456 | dma_addr_t mapping; |
| 4457 | int skb_size, dest_idx; |
| 4458 | |
| 4459 | src_map = NULL; |
| 4460 | switch (opaque_key) { |
| 4461 | case RXD_OPAQUE_RING_STD: |
| 4462 | dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4463 | desc = &tpr->rx_std[dest_idx]; |
| 4464 | map = &tpr->rx_std_buffers[dest_idx]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4465 | skb_size = tp->rx_pkt_map_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | break; |
| 4467 | |
| 4468 | case RXD_OPAQUE_RING_JUMBO: |
| 4469 | dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE; |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 4470 | desc = &tpr->rx_jmb[dest_idx].std; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4471 | map = &tpr->rx_jmb_buffers[dest_idx]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4472 | skb_size = TG3_RX_JMB_MAP_SZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | break; |
| 4474 | |
| 4475 | default: |
| 4476 | return -EINVAL; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4477 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | |
| 4479 | /* Do not overwrite any of the map or rp information |
| 4480 | * until we are sure we can commit to a new buffer. |
| 4481 | * |
| 4482 | * Callers depend upon this behavior and assume that |
| 4483 | * we leave everything unchanged if we fail. |
| 4484 | */ |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4485 | skb = netdev_alloc_skb(tp->dev, skb_size + tp->rx_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 | if (skb == NULL) |
| 4487 | return -ENOMEM; |
| 4488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | skb_reserve(skb, tp->rx_offset); |
| 4490 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4491 | mapping = pci_map_single(tp->pdev, skb->data, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | PCI_DMA_FROMDEVICE); |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 4493 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
| 4494 | dev_kfree_skb(skb); |
| 4495 | return -EIO; |
| 4496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | |
| 4498 | map->skb = skb; |
| 4499 | pci_unmap_addr_set(map, mapping, mapping); |
| 4500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | desc->addr_hi = ((u64)mapping >> 32); |
| 4502 | desc->addr_lo = ((u64)mapping & 0xffffffff); |
| 4503 | |
| 4504 | return skb_size; |
| 4505 | } |
| 4506 | |
| 4507 | /* We only need to move over in the address because the other |
| 4508 | * members of the RX descriptor are invariant. See notes above |
| 4509 | * tg3_alloc_rx_skb for full details. |
| 4510 | */ |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4511 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
| 4512 | struct tg3_rx_prodring_set *dpr, |
| 4513 | u32 opaque_key, int src_idx, |
| 4514 | u32 dest_idx_unmasked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4516 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
| 4518 | struct ring_info *src_map, *dest_map; |
| 4519 | int dest_idx; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4520 | struct tg3_rx_prodring_set *spr = &tp->prodring[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | |
| 4522 | switch (opaque_key) { |
| 4523 | case RXD_OPAQUE_RING_STD: |
| 4524 | dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4525 | dest_desc = &dpr->rx_std[dest_idx]; |
| 4526 | dest_map = &dpr->rx_std_buffers[dest_idx]; |
| 4527 | src_desc = &spr->rx_std[src_idx]; |
| 4528 | src_map = &spr->rx_std_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | break; |
| 4530 | |
| 4531 | case RXD_OPAQUE_RING_JUMBO: |
| 4532 | dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE; |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4533 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
| 4534 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; |
| 4535 | src_desc = &spr->rx_jmb[src_idx].std; |
| 4536 | src_map = &spr->rx_jmb_buffers[src_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | break; |
| 4538 | |
| 4539 | default: |
| 4540 | return; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 4541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | |
| 4543 | dest_map->skb = src_map->skb; |
| 4544 | pci_unmap_addr_set(dest_map, mapping, |
| 4545 | pci_unmap_addr(src_map, mapping)); |
| 4546 | dest_desc->addr_hi = src_desc->addr_hi; |
| 4547 | dest_desc->addr_lo = src_desc->addr_lo; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4548 | |
| 4549 | /* Ensure that the update to the skb happens after the physical |
| 4550 | * addresses have been transferred to the new BD location. |
| 4551 | */ |
| 4552 | smp_wmb(); |
| 4553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | src_map->skb = NULL; |
| 4555 | } |
| 4556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | /* The RX ring scheme is composed of multiple rings which post fresh |
| 4558 | * buffers to the chip, and one special ring the chip uses to report |
| 4559 | * status back to the host. |
| 4560 | * |
| 4561 | * The special ring reports the status of received packets to the |
| 4562 | * host. The chip does not write into the original descriptor the |
| 4563 | * RX buffer was obtained from. The chip simply takes the original |
| 4564 | * descriptor as provided by the host, updates the status and length |
| 4565 | * field, then writes this into the next status ring entry. |
| 4566 | * |
| 4567 | * Each ring the host uses to post buffers to the chip is described |
| 4568 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, |
| 4569 | * it is first placed into the on-chip ram. When the packet's length |
| 4570 | * is known, it walks down the TG3_BDINFO entries to select the ring. |
| 4571 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO |
| 4572 | * which is within the range of the new packet's length is chosen. |
| 4573 | * |
| 4574 | * The "separate ring for rx status" scheme may sound queer, but it makes |
| 4575 | * sense from a cache coherency perspective. If only the host writes |
| 4576 | * to the buffer post rings, and only the chip writes to the rx status |
| 4577 | * rings, then cache lines never move beyond shared-modified state. |
| 4578 | * If both the host and chip were to write into the same ring, cache line |
| 4579 | * eviction could occur since both entities want it in an exclusive state. |
| 4580 | */ |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4581 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4583 | struct tg3 *tp = tnapi->tp; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4584 | u32 work_mask, rx_std_posted = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4585 | u32 std_prod_idx, jmb_prod_idx; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4586 | u32 sw_idx = tnapi->rx_rcb_ptr; |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 4587 | u16 hw_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | int received; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4589 | struct tg3_rx_prodring_set *tpr = tnapi->prodring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 4591 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | /* |
| 4593 | * We need to order the read of hw_idx and the read of |
| 4594 | * the opaque cookie. |
| 4595 | */ |
| 4596 | rmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | work_mask = 0; |
| 4598 | received = 0; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4599 | std_prod_idx = tpr->rx_std_prod_idx; |
| 4600 | jmb_prod_idx = tpr->rx_jmb_prod_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | while (sw_idx != hw_idx && budget > 0) { |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 4602 | struct ring_info *ri; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4603 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4604 | unsigned int len; |
| 4605 | struct sk_buff *skb; |
| 4606 | dma_addr_t dma_addr; |
| 4607 | u32 opaque_key, desc_idx, *post_ptr; |
| 4608 | |
| 4609 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 4610 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 4611 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4612 | ri = &tp->prodring[0].rx_std_buffers[desc_idx]; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4613 | dma_addr = pci_unmap_addr(ri, mapping); |
| 4614 | skb = ri->skb; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4615 | post_ptr = &std_prod_idx; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4616 | rx_std_posted++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4618 | ri = &tp->prodring[0].rx_jmb_buffers[desc_idx]; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4619 | dma_addr = pci_unmap_addr(ri, mapping); |
| 4620 | skb = ri->skb; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4621 | post_ptr = &jmb_prod_idx; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 4622 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | goto next_pkt_nopost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | |
| 4625 | work_mask |= opaque_key; |
| 4626 | |
| 4627 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 4628 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { |
| 4629 | drop_it: |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4630 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | desc_idx, *post_ptr); |
| 4632 | drop_it_no_recycle: |
| 4633 | /* Other statistics kept track of by card. */ |
| 4634 | tp->net_stats.rx_dropped++; |
| 4635 | goto next_pkt; |
| 4636 | } |
| 4637 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 4638 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
| 4639 | ETH_FCS_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 4641 | if (len > RX_COPY_THRESHOLD && |
| 4642 | tp->rx_offset == NET_IP_ALIGN) { |
| 4643 | /* rx_offset will likely not equal NET_IP_ALIGN |
| 4644 | * if this is a 5701 card running in PCI-X mode |
| 4645 | * [see tg3_get_invariants()] |
| 4646 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | int skb_size; |
| 4648 | |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 4649 | skb_size = tg3_alloc_rx_skb(tp, tpr, opaque_key, |
Matt Carlson | afc081f | 2009-11-13 13:03:43 +0000 | [diff] [blame] | 4650 | *post_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | if (skb_size < 0) |
| 4652 | goto drop_it; |
| 4653 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 4654 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | PCI_DMA_FROMDEVICE); |
| 4656 | |
Matt Carlson | 61e800c | 2010-02-17 15:16:54 +0000 | [diff] [blame] | 4657 | /* Ensure that the update to the skb happens |
| 4658 | * after the usage of the old DMA mapping. |
| 4659 | */ |
| 4660 | smp_wmb(); |
| 4661 | |
| 4662 | ri->skb = NULL; |
| 4663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4664 | skb_put(skb, len); |
| 4665 | } else { |
| 4666 | struct sk_buff *copy_skb; |
| 4667 | |
Matt Carlson | a389616 | 2009-11-13 13:03:44 +0000 | [diff] [blame] | 4668 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | desc_idx, *post_ptr); |
| 4670 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 4671 | copy_skb = netdev_alloc_skb(tp->dev, |
| 4672 | len + TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | if (copy_skb == NULL) |
| 4674 | goto drop_it_no_recycle; |
| 4675 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 4676 | skb_reserve(copy_skb, TG3_RAW_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | skb_put(copy_skb, len); |
| 4678 | 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] | 4679 | skb_copy_from_linear_data(skb, copy_skb->data, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
| 4681 | |
| 4682 | /* We'll reuse the original ring buffer. */ |
| 4683 | skb = copy_skb; |
| 4684 | } |
| 4685 | |
| 4686 | if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) && |
| 4687 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 4688 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 4689 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) |
| 4690 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 4691 | else |
| 4692 | skb->ip_summed = CHECKSUM_NONE; |
| 4693 | |
| 4694 | skb->protocol = eth_type_trans(skb, tp->dev); |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 4695 | |
| 4696 | if (len > (tp->dev->mtu + ETH_HLEN) && |
| 4697 | skb->protocol != htons(ETH_P_8021Q)) { |
| 4698 | dev_kfree_skb(skb); |
| 4699 | goto next_pkt; |
| 4700 | } |
| 4701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4702 | #if TG3_VLAN_TAG_USED |
| 4703 | if (tp->vlgrp != NULL && |
| 4704 | desc->type_flags & RXD_FLAG_VLAN) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4705 | vlan_gro_receive(&tnapi->napi, tp->vlgrp, |
Matt Carlson | 8ef0442 | 2009-08-28 14:01:37 +0000 | [diff] [blame] | 4706 | desc->err_vlan & RXD_VLAN_MASK, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | } else |
| 4708 | #endif |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4709 | napi_gro_receive(&tnapi->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | received++; |
| 4712 | budget--; |
| 4713 | |
| 4714 | next_pkt: |
| 4715 | (*post_ptr)++; |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4716 | |
| 4717 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { |
Matt Carlson | 86cfe4f | 2010-01-12 10:11:37 +0000 | [diff] [blame] | 4718 | tpr->rx_std_prod_idx = std_prod_idx % TG3_RX_RING_SIZE; |
| 4719 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 4720 | tpr->rx_std_prod_idx); |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 4721 | work_mask &= ~RXD_OPAQUE_RING_STD; |
| 4722 | rx_std_posted = 0; |
| 4723 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | next_pkt_nopost: |
Michael Chan | 483ba50 | 2005-04-25 15:14:03 -0700 | [diff] [blame] | 4725 | sw_idx++; |
Eric Dumazet | 6b31a51 | 2007-02-06 13:29:21 -0800 | [diff] [blame] | 4726 | sw_idx &= (TG3_RX_RCB_RING_SIZE(tp) - 1); |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 4727 | |
| 4728 | /* Refresh hw_idx to see if there is new work */ |
| 4729 | if (sw_idx == hw_idx) { |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 4730 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
Michael Chan | 52f6d69 | 2005-04-25 15:14:32 -0700 | [diff] [blame] | 4731 | rmb(); |
| 4732 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | /* ACK the status ring. */ |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 4736 | tnapi->rx_rcb_ptr = sw_idx; |
| 4737 | tw32_rx_mbox(tnapi->consmbox, sw_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4738 | |
| 4739 | /* Refill RX ring(s). */ |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4740 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) { |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4741 | if (work_mask & RXD_OPAQUE_RING_STD) { |
| 4742 | tpr->rx_std_prod_idx = std_prod_idx % TG3_RX_RING_SIZE; |
| 4743 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 4744 | tpr->rx_std_prod_idx); |
| 4745 | } |
| 4746 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { |
| 4747 | tpr->rx_jmb_prod_idx = jmb_prod_idx % |
| 4748 | TG3_RX_JUMBO_RING_SIZE; |
| 4749 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 4750 | tpr->rx_jmb_prod_idx); |
| 4751 | } |
| 4752 | mmiowb(); |
| 4753 | } else if (work_mask) { |
| 4754 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be |
| 4755 | * updated before the producer indices can be updated. |
| 4756 | */ |
| 4757 | smp_wmb(); |
| 4758 | |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4759 | tpr->rx_std_prod_idx = std_prod_idx % TG3_RX_RING_SIZE; |
Matt Carlson | 4361935 | 2009-11-13 13:03:47 +0000 | [diff] [blame] | 4760 | tpr->rx_jmb_prod_idx = jmb_prod_idx % TG3_RX_JUMBO_RING_SIZE; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4761 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4762 | if (tnapi != &tp->napi[1]) |
| 4763 | napi_schedule(&tp->napi[1].napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | |
| 4766 | return received; |
| 4767 | } |
| 4768 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4769 | static void tg3_poll_link(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | /* handle link change and other phy events */ |
| 4772 | if (!(tp->tg3_flags & |
| 4773 | (TG3_FLAG_USE_LINKCHG_REG | |
| 4774 | TG3_FLAG_POLL_SERDES))) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4775 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
| 4776 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | if (sblk->status & SD_STATUS_LINK_CHG) { |
| 4778 | sblk->status = SD_STATUS_UPDATED | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4779 | (sblk->status & ~SD_STATUS_LINK_CHG); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 4780 | spin_lock(&tp->lock); |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 4781 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
| 4782 | tw32_f(MAC_STATUS, |
| 4783 | (MAC_STATUS_SYNC_CHANGED | |
| 4784 | MAC_STATUS_CFG_CHANGED | |
| 4785 | MAC_STATUS_MI_COMPLETION | |
| 4786 | MAC_STATUS_LNKSTATE_CHANGED)); |
| 4787 | udelay(40); |
| 4788 | } else |
| 4789 | tg3_setup_phy(tp, 0); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 4790 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | } |
| 4792 | } |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4793 | } |
| 4794 | |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4795 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
| 4796 | struct tg3_rx_prodring_set *dpr, |
| 4797 | struct tg3_rx_prodring_set *spr) |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4798 | { |
| 4799 | u32 si, di, cpycnt, src_prod_idx; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4800 | int i, err = 0; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4801 | |
| 4802 | while (1) { |
| 4803 | src_prod_idx = spr->rx_std_prod_idx; |
| 4804 | |
| 4805 | /* Make sure updates to the rx_std_buffers[] entries and the |
| 4806 | * standard producer index are seen in the correct order. |
| 4807 | */ |
| 4808 | smp_rmb(); |
| 4809 | |
| 4810 | if (spr->rx_std_cons_idx == src_prod_idx) |
| 4811 | break; |
| 4812 | |
| 4813 | if (spr->rx_std_cons_idx < src_prod_idx) |
| 4814 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; |
| 4815 | else |
| 4816 | cpycnt = TG3_RX_RING_SIZE - spr->rx_std_cons_idx; |
| 4817 | |
| 4818 | cpycnt = min(cpycnt, TG3_RX_RING_SIZE - dpr->rx_std_prod_idx); |
| 4819 | |
| 4820 | si = spr->rx_std_cons_idx; |
| 4821 | di = dpr->rx_std_prod_idx; |
| 4822 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4823 | for (i = di; i < di + cpycnt; i++) { |
| 4824 | if (dpr->rx_std_buffers[i].skb) { |
| 4825 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4826 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4827 | break; |
| 4828 | } |
| 4829 | } |
| 4830 | |
| 4831 | if (!cpycnt) |
| 4832 | break; |
| 4833 | |
| 4834 | /* Ensure that updates to the rx_std_buffers ring and the |
| 4835 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 4836 | * ordered correctly WRT the skb check above. |
| 4837 | */ |
| 4838 | smp_rmb(); |
| 4839 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4840 | memcpy(&dpr->rx_std_buffers[di], |
| 4841 | &spr->rx_std_buffers[si], |
| 4842 | cpycnt * sizeof(struct ring_info)); |
| 4843 | |
| 4844 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 4845 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 4846 | sbd = &spr->rx_std[si]; |
| 4847 | dbd = &dpr->rx_std[di]; |
| 4848 | dbd->addr_hi = sbd->addr_hi; |
| 4849 | dbd->addr_lo = sbd->addr_lo; |
| 4850 | } |
| 4851 | |
| 4852 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) % |
| 4853 | TG3_RX_RING_SIZE; |
| 4854 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) % |
| 4855 | TG3_RX_RING_SIZE; |
| 4856 | } |
| 4857 | |
| 4858 | while (1) { |
| 4859 | src_prod_idx = spr->rx_jmb_prod_idx; |
| 4860 | |
| 4861 | /* Make sure updates to the rx_jmb_buffers[] entries and |
| 4862 | * the jumbo producer index are seen in the correct order. |
| 4863 | */ |
| 4864 | smp_rmb(); |
| 4865 | |
| 4866 | if (spr->rx_jmb_cons_idx == src_prod_idx) |
| 4867 | break; |
| 4868 | |
| 4869 | if (spr->rx_jmb_cons_idx < src_prod_idx) |
| 4870 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; |
| 4871 | else |
| 4872 | cpycnt = TG3_RX_JUMBO_RING_SIZE - spr->rx_jmb_cons_idx; |
| 4873 | |
| 4874 | cpycnt = min(cpycnt, |
| 4875 | TG3_RX_JUMBO_RING_SIZE - dpr->rx_jmb_prod_idx); |
| 4876 | |
| 4877 | si = spr->rx_jmb_cons_idx; |
| 4878 | di = dpr->rx_jmb_prod_idx; |
| 4879 | |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4880 | for (i = di; i < di + cpycnt; i++) { |
| 4881 | if (dpr->rx_jmb_buffers[i].skb) { |
| 4882 | cpycnt = i - di; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4883 | err = -ENOSPC; |
Matt Carlson | e92967b | 2010-02-12 14:47:06 +0000 | [diff] [blame] | 4884 | break; |
| 4885 | } |
| 4886 | } |
| 4887 | |
| 4888 | if (!cpycnt) |
| 4889 | break; |
| 4890 | |
| 4891 | /* Ensure that updates to the rx_jmb_buffers ring and the |
| 4892 | * shadowed hardware producer ring from tg3_recycle_skb() are |
| 4893 | * ordered correctly WRT the skb check above. |
| 4894 | */ |
| 4895 | smp_rmb(); |
| 4896 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4897 | memcpy(&dpr->rx_jmb_buffers[di], |
| 4898 | &spr->rx_jmb_buffers[si], |
| 4899 | cpycnt * sizeof(struct ring_info)); |
| 4900 | |
| 4901 | for (i = 0; i < cpycnt; i++, di++, si++) { |
| 4902 | struct tg3_rx_buffer_desc *sbd, *dbd; |
| 4903 | sbd = &spr->rx_jmb[si].std; |
| 4904 | dbd = &dpr->rx_jmb[di].std; |
| 4905 | dbd->addr_hi = sbd->addr_hi; |
| 4906 | dbd->addr_lo = sbd->addr_lo; |
| 4907 | } |
| 4908 | |
| 4909 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) % |
| 4910 | TG3_RX_JUMBO_RING_SIZE; |
| 4911 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) % |
| 4912 | TG3_RX_JUMBO_RING_SIZE; |
| 4913 | } |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4914 | |
| 4915 | return err; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4918 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
| 4919 | { |
| 4920 | struct tg3 *tp = tnapi->tp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | |
| 4922 | /* run TX completion thread */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 4923 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4924 | tg3_tx(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 4925 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 4926 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | } |
| 4928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4929 | /* run RX thread, within the bounds set by NAPI. |
| 4930 | * All RX "locking" is done by ensuring outside |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4931 | * code synchronizes with tg3->napi.poll() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | */ |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 4933 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 4934 | work_done += tg3_rx(tnapi, budget - work_done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4935 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4936 | if ((tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) && tnapi == &tp->napi[1]) { |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4937 | struct tg3_rx_prodring_set *dpr = &tp->prodring[0]; |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4938 | int i, err = 0; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4939 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
| 4940 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4941 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4942 | for (i = 1; i < tp->irq_cnt; i++) |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4943 | err |= tg3_rx_prodring_xfer(tp, dpr, |
| 4944 | tp->napi[i].prodring); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4945 | |
| 4946 | wmb(); |
| 4947 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4948 | if (std_prod_idx != dpr->rx_std_prod_idx) |
| 4949 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 4950 | dpr->rx_std_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4951 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 4952 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
| 4953 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 4954 | dpr->rx_jmb_prod_idx); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4955 | |
| 4956 | mmiowb(); |
Matt Carlson | f89f38b | 2010-02-12 14:47:07 +0000 | [diff] [blame] | 4957 | |
| 4958 | if (err) |
| 4959 | tw32_f(HOSTCC_MODE, tp->coal_now); |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 4960 | } |
| 4961 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 4962 | return work_done; |
| 4963 | } |
David S. Miller | f7383c2 | 2005-05-18 22:50:53 -0700 | [diff] [blame] | 4964 | |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 4965 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
| 4966 | { |
| 4967 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 4968 | struct tg3 *tp = tnapi->tp; |
| 4969 | int work_done = 0; |
| 4970 | struct tg3_hw_status *sblk = tnapi->hw_status; |
| 4971 | |
| 4972 | while (1) { |
| 4973 | work_done = tg3_poll_work(tnapi, work_done, budget); |
| 4974 | |
| 4975 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) |
| 4976 | goto tx_recovery; |
| 4977 | |
| 4978 | if (unlikely(work_done >= budget)) |
| 4979 | break; |
| 4980 | |
| 4981 | /* tp->last_tag is used in tg3_restart_ints() below |
| 4982 | * to tell the hw how much work has been processed, |
| 4983 | * so we must read it before checking for more work. |
| 4984 | */ |
| 4985 | tnapi->last_tag = sblk->status_tag; |
| 4986 | tnapi->last_irq_tag = tnapi->last_tag; |
| 4987 | rmb(); |
| 4988 | |
| 4989 | /* check for RX/TX work to do */ |
| 4990 | if (sblk->idx[0].tx_consumer == tnapi->tx_cons && |
| 4991 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr) { |
| 4992 | napi_complete(napi); |
| 4993 | /* Reenable interrupts. */ |
| 4994 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
| 4995 | mmiowb(); |
| 4996 | break; |
| 4997 | } |
| 4998 | } |
| 4999 | |
| 5000 | return work_done; |
| 5001 | |
| 5002 | tx_recovery: |
| 5003 | /* work_done is guaranteed to be less than budget. */ |
| 5004 | napi_complete(napi); |
| 5005 | schedule_work(&tp->reset_task); |
| 5006 | return work_done; |
| 5007 | } |
| 5008 | |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5009 | static int tg3_poll(struct napi_struct *napi, int budget) |
| 5010 | { |
Matt Carlson | 8ef0442 | 2009-08-28 14:01:37 +0000 | [diff] [blame] | 5011 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 5012 | struct tg3 *tp = tnapi->tp; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5013 | int work_done = 0; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5014 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5015 | |
| 5016 | while (1) { |
Matt Carlson | 35f2d7d | 2009-11-13 13:03:41 +0000 | [diff] [blame] | 5017 | tg3_poll_link(tp); |
| 5018 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5019 | work_done = tg3_poll_work(tnapi, work_done, budget); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5020 | |
| 5021 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) |
| 5022 | goto tx_recovery; |
| 5023 | |
| 5024 | if (unlikely(work_done >= budget)) |
| 5025 | break; |
| 5026 | |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5027 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) { |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5028 | /* tp->last_tag is used in tg3_int_reenable() below |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5029 | * to tell the hw how much work has been processed, |
| 5030 | * so we must read it before checking for more work. |
| 5031 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5032 | tnapi->last_tag = sblk->status_tag; |
| 5033 | tnapi->last_irq_tag = tnapi->last_tag; |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5034 | rmb(); |
| 5035 | } else |
| 5036 | sblk->status &= ~SD_STATUS_UPDATED; |
| 5037 | |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5038 | if (likely(!tg3_has_work(tnapi))) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5039 | napi_complete(napi); |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5040 | tg3_int_reenable(tnapi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5041 | break; |
| 5042 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | } |
| 5044 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5045 | return work_done; |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5046 | |
| 5047 | tx_recovery: |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5048 | /* work_done is guaranteed to be less than budget. */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5049 | napi_complete(napi); |
David S. Miller | 6f53576 | 2007-10-11 18:08:29 -0700 | [diff] [blame] | 5050 | schedule_work(&tp->reset_task); |
Michael Chan | 4fd7ab5 | 2007-10-12 01:39:50 -0700 | [diff] [blame] | 5051 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5054 | static void tg3_irq_quiesce(struct tg3 *tp) |
| 5055 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5056 | int i; |
| 5057 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5058 | BUG_ON(tp->irq_sync); |
| 5059 | |
| 5060 | tp->irq_sync = 1; |
| 5061 | smp_mb(); |
| 5062 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5063 | for (i = 0; i < tp->irq_cnt; i++) |
| 5064 | synchronize_irq(tp->napi[i].irq_vec); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5065 | } |
| 5066 | |
| 5067 | static inline int tg3_irq_sync(struct tg3 *tp) |
| 5068 | { |
| 5069 | return tp->irq_sync; |
| 5070 | } |
| 5071 | |
| 5072 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
| 5073 | * If irq_sync is non-zero, then the IRQ handler must be synchronized |
| 5074 | * with as well. Most of the time, this is not necessary except when |
| 5075 | * shutting down the device. |
| 5076 | */ |
| 5077 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) |
| 5078 | { |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 5079 | spin_lock_bh(&tp->lock); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5080 | if (irq_sync) |
| 5081 | tg3_irq_quiesce(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5082 | } |
| 5083 | |
| 5084 | static inline void tg3_full_unlock(struct tg3 *tp) |
| 5085 | { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5086 | spin_unlock_bh(&tp->lock); |
| 5087 | } |
| 5088 | |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5089 | /* One-shot MSI handler - Chip automatically disables interrupt |
| 5090 | * after sending MSI so driver doesn't have to do it. |
| 5091 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5092 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5093 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5094 | struct tg3_napi *tnapi = dev_id; |
| 5095 | struct tg3 *tp = tnapi->tp; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5096 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5097 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 5098 | if (tnapi->rx_rcb) |
| 5099 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5100 | |
| 5101 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5102 | napi_schedule(&tnapi->napi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 5103 | |
| 5104 | return IRQ_HANDLED; |
| 5105 | } |
| 5106 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5107 | /* MSI ISR - No need to check for interrupt sharing and no need to |
| 5108 | * flush status block and interrupt mailbox. PCI ordering rules |
| 5109 | * guarantee that MSI will arrive after the status block. |
| 5110 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5111 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5112 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5113 | struct tg3_napi *tnapi = dev_id; |
| 5114 | struct tg3 *tp = tnapi->tp; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5115 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5116 | prefetch(tnapi->hw_status); |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 5117 | if (tnapi->rx_rcb) |
| 5118 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5119 | /* |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5120 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5121 | * chip-internal interrupt pending events. |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5122 | * Writing non-zero to intr-mbox-0 additional tells the |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5123 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5124 | * event coalescing. |
| 5125 | */ |
| 5126 | tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 5127 | if (likely(!tg3_irq_sync(tp))) |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5128 | napi_schedule(&tnapi->napi); |
Michael Chan | 6148748 | 2005-09-05 17:53:19 -0700 | [diff] [blame] | 5129 | |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5130 | return IRQ_RETVAL(1); |
| 5131 | } |
| 5132 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5133 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5134 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5135 | struct tg3_napi *tnapi = dev_id; |
| 5136 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5137 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 | unsigned int handled = 1; |
| 5139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5140 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 5141 | * the CPU before the status block posted prior to the interrupt. |
| 5142 | * Reading the PCI State register will confirm whether the |
| 5143 | * interrupt is ours and will flush the status block. |
| 5144 | */ |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5145 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
| 5146 | if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) || |
| 5147 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 5148 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5149 | goto out; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5150 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5151 | } |
| 5152 | |
| 5153 | /* |
| 5154 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
| 5155 | * chip-internal interrupt pending events. |
| 5156 | * Writing non-zero to intr-mbox-0 additional tells the |
| 5157 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5158 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5159 | * |
| 5160 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 5161 | * spurious interrupts. The flush impacts performance but |
| 5162 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5163 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5164 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5165 | if (tg3_irq_sync(tp)) |
| 5166 | goto out; |
| 5167 | sblk->status &= ~SD_STATUS_UPDATED; |
Matt Carlson | 17375d2 | 2009-08-28 14:02:18 +0000 | [diff] [blame] | 5168 | if (likely(tg3_has_work(tnapi))) { |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5169 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5170 | napi_schedule(&tnapi->napi); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5171 | } else { |
| 5172 | /* No work, shared interrupt perhaps? re-enable |
| 5173 | * interrupts, and flush that PCI write |
| 5174 | */ |
| 5175 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, |
| 5176 | 0x00000000); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5177 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5178 | out: |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5179 | return IRQ_RETVAL(handled); |
| 5180 | } |
| 5181 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5182 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5183 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5184 | struct tg3_napi *tnapi = dev_id; |
| 5185 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5186 | struct tg3_hw_status *sblk = tnapi->hw_status; |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5187 | unsigned int handled = 1; |
| 5188 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 5189 | /* In INTx mode, it is possible for the interrupt to arrive at |
| 5190 | * the CPU before the status block posted prior to the interrupt. |
| 5191 | * Reading the PCI State register will confirm whether the |
| 5192 | * interrupt is ours and will flush the status block. |
| 5193 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5194 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5195 | if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) || |
| 5196 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 5197 | handled = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5198 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | /* |
| 5203 | * writing any value to intr-mbox-0 clears PCI INTA# and |
| 5204 | * chip-internal interrupt pending events. |
| 5205 | * writing non-zero to intr-mbox-0 additional tells the |
| 5206 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
| 5207 | * event coalescing. |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5208 | * |
| 5209 | * Flush the mailbox to de-assert the IRQ immediately to prevent |
| 5210 | * spurious interrupts. The flush impacts performance but |
| 5211 | * excessive spurious interrupts can be worse in some cases. |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5212 | */ |
Michael Chan | c04cb34 | 2007-05-07 00:26:15 -0700 | [diff] [blame] | 5213 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5214 | |
| 5215 | /* |
| 5216 | * In a shared interrupt configuration, sometimes other devices' |
| 5217 | * interrupts will scream. We record the current status tag here |
| 5218 | * so that the above check can report that the screaming interrupts |
| 5219 | * are unhandled. Eventually they will be silenced. |
| 5220 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5221 | tnapi->last_irq_tag = sblk->status_tag; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5222 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 5223 | if (tg3_irq_sync(tp)) |
| 5224 | goto out; |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5225 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 5226 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5227 | |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5228 | napi_schedule(&tnapi->napi); |
Matt Carlson | 624f8e5 | 2009-04-20 06:55:01 +0000 | [diff] [blame] | 5229 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5230 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5231 | return IRQ_RETVAL(handled); |
| 5232 | } |
| 5233 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5234 | /* ISR for interrupt test */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5235 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5236 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 5237 | struct tg3_napi *tnapi = dev_id; |
| 5238 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 5239 | struct tg3_hw_status *sblk = tnapi->hw_status; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5240 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 5241 | if ((sblk->status & SD_STATUS_UPDATED) || |
| 5242 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 5243 | tg3_disable_ints(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 5244 | return IRQ_RETVAL(1); |
| 5245 | } |
| 5246 | return IRQ_RETVAL(0); |
| 5247 | } |
| 5248 | |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 5249 | static int tg3_init_hw(struct tg3 *, int); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 5250 | static int tg3_halt(struct tg3 *, int, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5251 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5252 | /* Restart hardware after configuration changes, self-test, etc. |
| 5253 | * Invoked with tp->lock held. |
| 5254 | */ |
| 5255 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) |
Eric Dumazet | 78c6146 | 2008-04-24 23:33:06 -0700 | [diff] [blame] | 5256 | __releases(tp->lock) |
| 5257 | __acquires(tp->lock) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5258 | { |
| 5259 | int err; |
| 5260 | |
| 5261 | err = tg3_init_hw(tp, reset_phy); |
| 5262 | if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 5263 | netdev_err(tp->dev, "Failed to re-initialize device, aborting\n"); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5264 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 5265 | tg3_full_unlock(tp); |
| 5266 | del_timer_sync(&tp->timer); |
| 5267 | tp->irq_sync = 0; |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 5268 | tg3_napi_enable(tp); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5269 | dev_close(tp->dev); |
| 5270 | tg3_full_lock(tp, 0); |
| 5271 | } |
| 5272 | return err; |
| 5273 | } |
| 5274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5275 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5276 | static void tg3_poll_controller(struct net_device *dev) |
| 5277 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5278 | int i; |
Michael Chan | 88b06bc2 | 2005-04-21 17:13:25 -0700 | [diff] [blame] | 5279 | struct tg3 *tp = netdev_priv(dev); |
| 5280 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 5281 | for (i = 0; i < tp->irq_cnt; i++) |
| 5282 | tg3_interrupt(tp->napi[i].irq_vec, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5283 | } |
| 5284 | #endif |
| 5285 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5286 | static void tg3_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5287 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5288 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5289 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5290 | unsigned int restart_timer; |
| 5291 | |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5292 | tg3_full_lock(tp, 0); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5293 | |
| 5294 | if (!netif_running(tp->dev)) { |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5295 | tg3_full_unlock(tp); |
| 5296 | return; |
| 5297 | } |
| 5298 | |
| 5299 | tg3_full_unlock(tp); |
| 5300 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5301 | tg3_phy_stop(tp); |
| 5302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5303 | tg3_netif_stop(tp); |
| 5304 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5305 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5306 | |
| 5307 | restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER; |
| 5308 | tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER; |
| 5309 | |
Michael Chan | df3e654 | 2006-05-26 17:48:07 -0700 | [diff] [blame] | 5310 | if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) { |
| 5311 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 5312 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 5313 | tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER; |
| 5314 | tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING; |
| 5315 | } |
| 5316 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 5317 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5318 | err = tg3_init_hw(tp, 1); |
| 5319 | if (err) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5320 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | |
| 5322 | tg3_netif_start(tp); |
| 5323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5324 | if (restart_timer) |
| 5325 | mod_timer(&tp->timer, jiffies + 1); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5326 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5327 | out: |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 5328 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5329 | |
| 5330 | if (!err) |
| 5331 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5332 | } |
| 5333 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5334 | static void tg3_dump_short_state(struct tg3 *tp) |
| 5335 | { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 5336 | netdev_err(tp->dev, "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n", |
| 5337 | tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS)); |
| 5338 | netdev_err(tp->dev, "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n", |
| 5339 | tr32(RDMAC_STATUS), tr32(WDMAC_STATUS)); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5340 | } |
| 5341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5342 | static void tg3_tx_timeout(struct net_device *dev) |
| 5343 | { |
| 5344 | struct tg3 *tp = netdev_priv(dev); |
| 5345 | |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5346 | if (netif_msg_tx_err(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 5347 | netdev_err(dev, "transmit timed out, resetting\n"); |
Michael Chan | b040875 | 2007-02-13 12:18:30 -0800 | [diff] [blame] | 5348 | tg3_dump_short_state(tp); |
| 5349 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5350 | |
| 5351 | schedule_work(&tp->reset_task); |
| 5352 | } |
| 5353 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5354 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
| 5355 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) |
| 5356 | { |
| 5357 | u32 base = (u32) mapping & 0xffffffff; |
| 5358 | |
| 5359 | return ((base > 0xffffdcc0) && |
| 5360 | (base + len + 8 < base)); |
| 5361 | } |
| 5362 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5363 | /* Test for DMA addresses > 40-bit */ |
| 5364 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 5365 | int len) |
| 5366 | { |
| 5367 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) |
Michael Chan | 6728a8e | 2006-03-27 23:16:49 -0800 | [diff] [blame] | 5368 | if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 5369 | return (((u64) mapping + len) > DMA_BIT_MASK(40)); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5370 | return 0; |
| 5371 | #else |
| 5372 | return 0; |
| 5373 | #endif |
| 5374 | } |
| 5375 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5376 | 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] | 5377 | |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5378 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5379 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
| 5380 | struct sk_buff *skb, u32 last_plus_one, |
| 5381 | u32 *start, u32 base_flags, u32 mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5382 | { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5383 | struct tg3 *tp = tnapi->tp; |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 5384 | struct sk_buff *new_skb; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5385 | dma_addr_t new_addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | u32 entry = *start; |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5387 | int i, ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5388 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 5389 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 5390 | new_skb = skb_copy(skb, GFP_ATOMIC); |
| 5391 | else { |
| 5392 | int more_headroom = 4 - ((unsigned long)skb->data & 3); |
| 5393 | |
| 5394 | new_skb = skb_copy_expand(skb, |
| 5395 | skb_headroom(skb) + more_headroom, |
| 5396 | skb_tailroom(skb), GFP_ATOMIC); |
| 5397 | } |
| 5398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5399 | if (!new_skb) { |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5400 | ret = -1; |
| 5401 | } else { |
| 5402 | /* New SKB is guaranteed to be linear. */ |
| 5403 | entry = *start; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5404 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
| 5405 | PCI_DMA_TODEVICE); |
| 5406 | /* Make sure the mapping succeeded */ |
| 5407 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { |
| 5408 | ret = -1; |
| 5409 | dev_kfree_skb(new_skb); |
| 5410 | new_skb = NULL; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5411 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5412 | /* Make sure new skb does not cross any 4G boundaries. |
| 5413 | * Drop the packet if it does. |
| 5414 | */ |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5415 | } else if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
| 5416 | tg3_4g_overflow_test(new_addr, new_skb->len)) { |
| 5417 | pci_unmap_single(tp->pdev, new_addr, new_skb->len, |
| 5418 | PCI_DMA_TODEVICE); |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5419 | ret = -1; |
| 5420 | dev_kfree_skb(new_skb); |
| 5421 | new_skb = NULL; |
| 5422 | } else { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5423 | tg3_set_txd(tnapi, entry, new_addr, new_skb->len, |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5424 | base_flags, 1 | (mss << 1)); |
| 5425 | *start = NEXT_TX(entry); |
| 5426 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | } |
| 5428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5429 | /* Now clean up the sw ring entries. */ |
| 5430 | i = 0; |
| 5431 | while (entry != last_plus_one) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5432 | int len; |
| 5433 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5434 | if (i == 0) |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5435 | len = skb_headlen(skb); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5436 | else |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5437 | len = skb_shinfo(skb)->frags[i-1].size; |
| 5438 | |
| 5439 | pci_unmap_single(tp->pdev, |
| 5440 | pci_unmap_addr(&tnapi->tx_buffers[entry], |
| 5441 | mapping), |
| 5442 | len, PCI_DMA_TODEVICE); |
| 5443 | if (i == 0) { |
| 5444 | tnapi->tx_buffers[entry].skb = new_skb; |
| 5445 | pci_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
| 5446 | new_addr); |
| 5447 | } else { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5448 | tnapi->tx_buffers[entry].skb = NULL; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5450 | entry = NEXT_TX(entry); |
| 5451 | i++; |
| 5452 | } |
| 5453 | |
| 5454 | dev_kfree_skb(skb); |
| 5455 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5456 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5457 | } |
| 5458 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5459 | static void tg3_set_txd(struct tg3_napi *tnapi, int entry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5460 | dma_addr_t mapping, int len, u32 flags, |
| 5461 | u32 mss_and_is_end) |
| 5462 | { |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5463 | struct tg3_tx_buffer_desc *txd = &tnapi->tx_ring[entry]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 | int is_end = (mss_and_is_end & 0x1); |
| 5465 | u32 mss = (mss_and_is_end >> 1); |
| 5466 | u32 vlan_tag = 0; |
| 5467 | |
| 5468 | if (is_end) |
| 5469 | flags |= TXD_FLAG_END; |
| 5470 | if (flags & TXD_FLAG_VLAN) { |
| 5471 | vlan_tag = flags >> 16; |
| 5472 | flags &= 0xffff; |
| 5473 | } |
| 5474 | vlan_tag |= (mss << TXD_MSS_SHIFT); |
| 5475 | |
| 5476 | txd->addr_hi = ((u64) mapping >> 32); |
| 5477 | txd->addr_lo = ((u64) mapping & 0xffffffff); |
| 5478 | txd->len_flags = (len << TXD_LEN_SHIFT) | flags; |
| 5479 | txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT; |
| 5480 | } |
| 5481 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5482 | /* hard_start_xmit for devices that don't have any bugs and |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 5483 | * 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] | 5484 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5485 | static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, |
| 5486 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | { |
| 5488 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5489 | u32 len, entry, base_flags, mss; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5490 | dma_addr_t mapping; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5491 | struct tg3_napi *tnapi; |
| 5492 | struct netdev_queue *txq; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5493 | unsigned int i, last; |
| 5494 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5495 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5496 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 5497 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 5498 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5499 | tnapi++; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5500 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 5501 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5502 | * and TX reclaim runs via tp->napi.poll inside of a software |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5503 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 5504 | * no IRQ context deadlocks to worry about either. Rejoice! |
| 5505 | */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5506 | if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5507 | if (!netif_tx_queue_stopped(txq)) { |
| 5508 | netif_tx_stop_queue(txq); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5509 | |
| 5510 | /* This is a hard error, log it. */ |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 5511 | netdev_err(dev, "BUG! Tx Ring full when queue awake!\n"); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5512 | } |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5513 | return NETDEV_TX_BUSY; |
| 5514 | } |
| 5515 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5516 | entry = tnapi->tx_prod; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5517 | base_flags = 0; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5518 | mss = 0; |
Matt Carlson | c13e371 | 2007-05-05 11:50:04 -0700 | [diff] [blame] | 5519 | if ((mss = skb_shinfo(skb)->gso_size) != 0) { |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5520 | int tcp_opt_len, ip_tcp_len; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5521 | u32 hdrlen; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5522 | |
| 5523 | if (skb_header_cloned(skb) && |
| 5524 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { |
| 5525 | dev_kfree_skb(skb); |
| 5526 | goto out_unlock; |
| 5527 | } |
| 5528 | |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 5529 | if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5530 | hdrlen = skb_headlen(skb) - ETH_HLEN; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 5531 | else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5532 | struct iphdr *iph = ip_hdr(skb); |
| 5533 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 5534 | tcp_opt_len = tcp_optlen(skb); |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 5535 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 5536 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5537 | iph->check = 0; |
| 5538 | iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5539 | hdrlen = ip_tcp_len + tcp_opt_len; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 5540 | } |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5541 | |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 5542 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5543 | mss |= (hdrlen & 0xc) << 12; |
| 5544 | if (hdrlen & 0x10) |
| 5545 | base_flags |= 0x00000010; |
| 5546 | base_flags |= (hdrlen & 0x3e0) << 5; |
| 5547 | } else |
| 5548 | mss |= hdrlen << 9; |
| 5549 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5550 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 5551 | TXD_FLAG_CPU_POST_DMA); |
| 5552 | |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5553 | tcp_hdr(skb)->check = 0; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5554 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5555 | } |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 5556 | else if (skb->ip_summed == CHECKSUM_PARTIAL) |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5557 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5558 | #if TG3_VLAN_TAG_USED |
| 5559 | if (tp->vlgrp != NULL && vlan_tx_tag_present(skb)) |
| 5560 | base_flags |= (TXD_FLAG_VLAN | |
| 5561 | (vlan_tx_tag_get(skb) << 16)); |
| 5562 | #endif |
| 5563 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5564 | len = skb_headlen(skb); |
| 5565 | |
| 5566 | /* Queue skb data, a.k.a. the main skb fragment. */ |
| 5567 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
| 5568 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5569 | dev_kfree_skb(skb); |
| 5570 | goto out_unlock; |
| 5571 | } |
| 5572 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5573 | tnapi->tx_buffers[entry].skb = skb; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5574 | pci_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5575 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 5576 | if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 5577 | !mss && skb->len > ETH_DATA_LEN) |
| 5578 | base_flags |= TXD_FLAG_JMB_PKT; |
| 5579 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5580 | tg3_set_txd(tnapi, entry, mapping, len, base_flags, |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5581 | (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); |
| 5582 | |
| 5583 | entry = NEXT_TX(entry); |
| 5584 | |
| 5585 | /* Now loop through additional data fragments, and queue them. */ |
| 5586 | if (skb_shinfo(skb)->nr_frags > 0) { |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5587 | last = skb_shinfo(skb)->nr_frags - 1; |
| 5588 | for (i = 0; i <= last; i++) { |
| 5589 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 5590 | |
| 5591 | len = frag->size; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5592 | mapping = pci_map_page(tp->pdev, |
| 5593 | frag->page, |
| 5594 | frag->page_offset, |
| 5595 | len, PCI_DMA_TODEVICE); |
| 5596 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 5597 | goto dma_error; |
| 5598 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5599 | tnapi->tx_buffers[entry].skb = NULL; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5600 | pci_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
| 5601 | mapping); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5602 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5603 | tg3_set_txd(tnapi, entry, mapping, len, |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5604 | base_flags, (i == last) | (mss << 1)); |
| 5605 | |
| 5606 | entry = NEXT_TX(entry); |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5611 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5612 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5613 | tnapi->tx_prod = entry; |
| 5614 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5615 | netif_tx_stop_queue(txq); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5616 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 5617 | netif_tx_wake_queue(txq); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | out_unlock: |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 5621 | mmiowb(); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5622 | |
| 5623 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5624 | |
| 5625 | dma_error: |
| 5626 | last = i; |
| 5627 | entry = tnapi->tx_prod; |
| 5628 | tnapi->tx_buffers[entry].skb = NULL; |
| 5629 | pci_unmap_single(tp->pdev, |
| 5630 | pci_unmap_addr(&tnapi->tx_buffers[entry], mapping), |
| 5631 | skb_headlen(skb), |
| 5632 | PCI_DMA_TODEVICE); |
| 5633 | for (i = 0; i <= last; i++) { |
| 5634 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 5635 | entry = NEXT_TX(entry); |
| 5636 | |
| 5637 | pci_unmap_page(tp->pdev, |
| 5638 | pci_unmap_addr(&tnapi->tx_buffers[entry], |
| 5639 | mapping), |
| 5640 | frag->size, PCI_DMA_TODEVICE); |
| 5641 | } |
| 5642 | |
| 5643 | dev_kfree_skb(skb); |
| 5644 | return NETDEV_TX_OK; |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5645 | } |
| 5646 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5647 | static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *, |
| 5648 | struct net_device *); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5649 | |
| 5650 | /* Use GSO to workaround a rare TSO bug that may be triggered when the |
| 5651 | * TSO header is greater than 80 bytes. |
| 5652 | */ |
| 5653 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) |
| 5654 | { |
| 5655 | struct sk_buff *segs, *nskb; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5656 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5657 | |
| 5658 | /* Estimate the number of fragments in the worst case */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5659 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5660 | netif_stop_queue(tp->dev); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5661 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 5662 | return NETDEV_TX_BUSY; |
| 5663 | |
| 5664 | netif_wake_queue(tp->dev); |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); |
Hirofumi Nakagawa | 801678c | 2008-04-29 01:03:09 -0700 | [diff] [blame] | 5668 | if (IS_ERR(segs)) |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5669 | goto tg3_tso_bug_end; |
| 5670 | |
| 5671 | do { |
| 5672 | nskb = segs; |
| 5673 | segs = segs->next; |
| 5674 | nskb->next = NULL; |
| 5675 | tg3_start_xmit_dma_bug(nskb, tp->dev); |
| 5676 | } while (segs); |
| 5677 | |
| 5678 | tg3_tso_bug_end: |
| 5679 | dev_kfree_skb(skb); |
| 5680 | |
| 5681 | return NETDEV_TX_OK; |
| 5682 | } |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5683 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5684 | /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and |
| 5685 | * support TG3_FLG2_HW_TSO_1 or firmware TSO only. |
| 5686 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5687 | static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *skb, |
| 5688 | struct net_device *dev) |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5689 | { |
| 5690 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 5691 | u32 len, entry, base_flags, mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | int would_hit_hwbug; |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5693 | dma_addr_t mapping; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5694 | struct tg3_napi *tnapi; |
| 5695 | struct netdev_queue *txq; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5696 | unsigned int i, last; |
| 5697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5698 | |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5699 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 5700 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 5701 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5702 | tnapi++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | |
Michael Chan | 00b7050 | 2006-06-17 21:58:45 -0700 | [diff] [blame] | 5704 | /* We are running in BH disabled context with netif_tx_lock |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5705 | * 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] | 5706 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
| 5707 | * no IRQ context deadlocks to worry about either. Rejoice! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5708 | */ |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5709 | if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5710 | if (!netif_tx_queue_stopped(txq)) { |
| 5711 | netif_tx_stop_queue(txq); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 5712 | |
| 5713 | /* This is a hard error, log it. */ |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 5714 | netdev_err(dev, "BUG! Tx Ring full when queue awake!\n"); |
Stephen Hemminger | 1f064a8 | 2005-12-06 17:36:44 -0800 | [diff] [blame] | 5715 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5716 | return NETDEV_TX_BUSY; |
| 5717 | } |
| 5718 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5719 | entry = tnapi->tx_prod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5720 | base_flags = 0; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 5721 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5722 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5723 | |
Matt Carlson | c13e371 | 2007-05-05 11:50:04 -0700 | [diff] [blame] | 5724 | if ((mss = skb_shinfo(skb)->gso_size) != 0) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5725 | struct iphdr *iph; |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 5726 | u32 tcp_opt_len, ip_tcp_len, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5727 | |
| 5728 | if (skb_header_cloned(skb) && |
| 5729 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { |
| 5730 | dev_kfree_skb(skb); |
| 5731 | goto out_unlock; |
| 5732 | } |
| 5733 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 5734 | tcp_opt_len = tcp_optlen(skb); |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 5735 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5736 | |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5737 | hdr_len = ip_tcp_len + tcp_opt_len; |
| 5738 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 5739 | (tp->tg3_flags2 & TG3_FLG2_TSO_BUG)) |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 5740 | return (tg3_tso_bug(tp, skb)); |
| 5741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 5743 | TXD_FLAG_CPU_POST_DMA); |
| 5744 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5745 | iph = ip_hdr(skb); |
| 5746 | iph->check = 0; |
| 5747 | iph->tot_len = htons(mss + hdr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5748 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) { |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5749 | tcp_hdr(skb)->check = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5750 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 5751 | } else |
| 5752 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 5753 | iph->daddr, 0, |
| 5754 | IPPROTO_TCP, |
| 5755 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5756 | |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 5757 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) { |
| 5758 | mss |= (hdr_len & 0xc) << 12; |
| 5759 | if (hdr_len & 0x10) |
| 5760 | base_flags |= 0x00000010; |
| 5761 | base_flags |= (hdr_len & 0x3e0) << 5; |
| 5762 | } else if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 5763 | mss |= hdr_len << 9; |
| 5764 | else if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_1) || |
| 5765 | 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] | 5766 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5767 | int tsflags; |
| 5768 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5769 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5770 | mss |= (tsflags << 11); |
| 5771 | } |
| 5772 | } else { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5773 | if (tcp_opt_len || iph->ihl > 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5774 | int tsflags; |
| 5775 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5776 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5777 | base_flags |= tsflags << 12; |
| 5778 | } |
| 5779 | } |
| 5780 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5781 | #if TG3_VLAN_TAG_USED |
| 5782 | if (tp->vlgrp != NULL && vlan_tx_tag_present(skb)) |
| 5783 | base_flags |= (TXD_FLAG_VLAN | |
| 5784 | (vlan_tx_tag_get(skb) << 16)); |
| 5785 | #endif |
| 5786 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 5787 | if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) && |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 5788 | !mss && skb->len > ETH_DATA_LEN) |
| 5789 | base_flags |= TXD_FLAG_JMB_PKT; |
| 5790 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5791 | len = skb_headlen(skb); |
| 5792 | |
| 5793 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); |
| 5794 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
David S. Miller | 90079ce | 2008-09-11 04:52:51 -0700 | [diff] [blame] | 5795 | dev_kfree_skb(skb); |
| 5796 | goto out_unlock; |
| 5797 | } |
| 5798 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5799 | tnapi->tx_buffers[entry].skb = skb; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5800 | pci_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5801 | |
| 5802 | would_hit_hwbug = 0; |
| 5803 | |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 5804 | if ((tp->tg3_flags3 & TG3_FLG3_SHORT_DMA_BUG) && len <= 8) |
| 5805 | would_hit_hwbug = 1; |
| 5806 | |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 5807 | if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
| 5808 | tg3_4g_overflow_test(mapping, len)) |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 5809 | would_hit_hwbug = 1; |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 5810 | |
| 5811 | if ((tp->tg3_flags3 & TG3_FLG3_40BIT_DMA_LIMIT_BUG) && |
| 5812 | tg3_40bit_overflow_test(tp, mapping, len)) |
| 5813 | would_hit_hwbug = 1; |
| 5814 | |
| 5815 | if (tp->tg3_flags3 & TG3_FLG3_5701_DMA_BUG) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5816 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5817 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5818 | tg3_set_txd(tnapi, entry, mapping, len, base_flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5819 | (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); |
| 5820 | |
| 5821 | entry = NEXT_TX(entry); |
| 5822 | |
| 5823 | /* Now loop through additional data fragments, and queue them. */ |
| 5824 | if (skb_shinfo(skb)->nr_frags > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5825 | last = skb_shinfo(skb)->nr_frags - 1; |
| 5826 | for (i = 0; i <= last; i++) { |
| 5827 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 5828 | |
| 5829 | len = frag->size; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5830 | mapping = pci_map_page(tp->pdev, |
| 5831 | frag->page, |
| 5832 | frag->page_offset, |
| 5833 | len, PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5834 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5835 | tnapi->tx_buffers[entry].skb = NULL; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5836 | pci_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
| 5837 | mapping); |
| 5838 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
| 5839 | goto dma_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5840 | |
Matt Carlson | 92c6b8d | 2009-11-02 14:23:27 +0000 | [diff] [blame] | 5841 | if ((tp->tg3_flags3 & TG3_FLG3_SHORT_DMA_BUG) && |
| 5842 | len <= 8) |
| 5843 | would_hit_hwbug = 1; |
| 5844 | |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 5845 | if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
| 5846 | tg3_4g_overflow_test(mapping, len)) |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5847 | would_hit_hwbug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5848 | |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 5849 | if ((tp->tg3_flags3 & TG3_FLG3_40BIT_DMA_LIMIT_BUG) && |
| 5850 | tg3_40bit_overflow_test(tp, mapping, len)) |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 5851 | would_hit_hwbug = 1; |
| 5852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5854 | tg3_set_txd(tnapi, entry, mapping, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5855 | base_flags, (i == last)|(mss << 1)); |
| 5856 | else |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5857 | tg3_set_txd(tnapi, entry, mapping, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5858 | base_flags, (i == last)); |
| 5859 | |
| 5860 | entry = NEXT_TX(entry); |
| 5861 | } |
| 5862 | } |
| 5863 | |
| 5864 | if (would_hit_hwbug) { |
| 5865 | u32 last_plus_one = entry; |
| 5866 | u32 start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5867 | |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5868 | start = entry - 1 - skb_shinfo(skb)->nr_frags; |
| 5869 | start &= (TG3_TX_RING_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5870 | |
| 5871 | /* If the workaround fails due to memory/mapping |
| 5872 | * failure, silently drop this packet. |
| 5873 | */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5874 | if (tigon3_dma_hwbug_workaround(tnapi, skb, last_plus_one, |
Michael Chan | c58ec93 | 2005-09-17 00:46:27 -0700 | [diff] [blame] | 5875 | &start, base_flags, mss)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5876 | goto out_unlock; |
| 5877 | |
| 5878 | entry = start; |
| 5879 | } |
| 5880 | |
| 5881 | /* Packets are ready, update Tx producer idx local and on card. */ |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5882 | tw32_tx_mbox(tnapi->prodmbox, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5883 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5884 | tnapi->tx_prod = entry; |
| 5885 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5886 | netif_tx_stop_queue(txq); |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 5887 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
Matt Carlson | 24f4efd | 2009-11-13 13:03:35 +0000 | [diff] [blame] | 5888 | netif_tx_wake_queue(txq); |
Michael Chan | 51b9146 | 2005-09-01 17:41:28 -0700 | [diff] [blame] | 5889 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5890 | |
| 5891 | out_unlock: |
Eric Dumazet | cdd0db0 | 2009-05-28 00:00:41 +0000 | [diff] [blame] | 5892 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5893 | |
| 5894 | return NETDEV_TX_OK; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 5895 | |
| 5896 | dma_error: |
| 5897 | last = i; |
| 5898 | entry = tnapi->tx_prod; |
| 5899 | tnapi->tx_buffers[entry].skb = NULL; |
| 5900 | pci_unmap_single(tp->pdev, |
| 5901 | pci_unmap_addr(&tnapi->tx_buffers[entry], mapping), |
| 5902 | skb_headlen(skb), |
| 5903 | PCI_DMA_TODEVICE); |
| 5904 | for (i = 0; i <= last; i++) { |
| 5905 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 5906 | entry = NEXT_TX(entry); |
| 5907 | |
| 5908 | pci_unmap_page(tp->pdev, |
| 5909 | pci_unmap_addr(&tnapi->tx_buffers[entry], |
| 5910 | mapping), |
| 5911 | frag->size, PCI_DMA_TODEVICE); |
| 5912 | } |
| 5913 | |
| 5914 | dev_kfree_skb(skb); |
| 5915 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5916 | } |
| 5917 | |
| 5918 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
| 5919 | int new_mtu) |
| 5920 | { |
| 5921 | dev->mtu = new_mtu; |
| 5922 | |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 5923 | if (new_mtu > ETH_DATA_LEN) { |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 5924 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) { |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 5925 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE; |
| 5926 | ethtool_op_set_tso(dev, 0); |
| 5927 | } |
| 5928 | else |
| 5929 | tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE; |
| 5930 | } else { |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 5931 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 5932 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 5933 | tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE; |
Michael Chan | ef7f5ec | 2005-07-25 12:32:25 -0700 | [diff] [blame] | 5934 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5935 | } |
| 5936 | |
| 5937 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) |
| 5938 | { |
| 5939 | struct tg3 *tp = netdev_priv(dev); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5940 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5941 | |
| 5942 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) |
| 5943 | return -EINVAL; |
| 5944 | |
| 5945 | if (!netif_running(dev)) { |
| 5946 | /* We'll just catch it later when the |
| 5947 | * device is up'd. |
| 5948 | */ |
| 5949 | tg3_set_mtu(dev, tp, new_mtu); |
| 5950 | return 0; |
| 5951 | } |
| 5952 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5953 | tg3_phy_stop(tp); |
| 5954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5955 | tg3_netif_stop(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5956 | |
| 5957 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5958 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 5959 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5960 | |
| 5961 | tg3_set_mtu(dev, tp, new_mtu); |
| 5962 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5963 | err = tg3_restart_hw(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5964 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5965 | if (!err) |
| 5966 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5967 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 5968 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5969 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 5970 | if (!err) |
| 5971 | tg3_phy_start(tp); |
| 5972 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 5973 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5974 | } |
| 5975 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 5976 | static void tg3_rx_prodring_free(struct tg3 *tp, |
| 5977 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5978 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5979 | int i; |
| 5980 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5981 | if (tpr != &tp->prodring[0]) { |
| 5982 | for (i = tpr->rx_std_cons_idx; i != tpr->rx_std_prod_idx; |
| 5983 | i = (i + 1) % TG3_RX_RING_SIZE) |
| 5984 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
| 5985 | tp->rx_pkt_map_sz); |
| 5986 | |
| 5987 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
| 5988 | for (i = tpr->rx_jmb_cons_idx; |
| 5989 | i != tpr->rx_jmb_prod_idx; |
| 5990 | i = (i + 1) % TG3_RX_JUMBO_RING_SIZE) { |
| 5991 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
| 5992 | TG3_RX_JMB_MAP_SZ); |
| 5993 | } |
| 5994 | } |
| 5995 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5996 | return; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 5997 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5998 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 5999 | for (i = 0; i < TG3_RX_RING_SIZE; i++) |
| 6000 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
| 6001 | tp->rx_pkt_map_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6002 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6003 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6004 | for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) |
| 6005 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
| 6006 | TG3_RX_JMB_MAP_SZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6007 | } |
| 6008 | } |
| 6009 | |
| 6010 | /* Initialize tx/rx rings for packet processing. |
| 6011 | * |
| 6012 | * The chip has been shut down and the driver detached from |
| 6013 | * the networking, so no interrupts or new tx packets will |
| 6014 | * end up in the driver. tp->{tx,}lock are held and thus |
| 6015 | * we may not sleep. |
| 6016 | */ |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6017 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
| 6018 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6019 | { |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6020 | u32 i, rx_pkt_dma_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6021 | |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6022 | tpr->rx_std_cons_idx = 0; |
| 6023 | tpr->rx_std_prod_idx = 0; |
| 6024 | tpr->rx_jmb_cons_idx = 0; |
| 6025 | tpr->rx_jmb_prod_idx = 0; |
| 6026 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6027 | if (tpr != &tp->prodring[0]) { |
| 6028 | memset(&tpr->rx_std_buffers[0], 0, TG3_RX_STD_BUFF_RING_SIZE); |
| 6029 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) |
| 6030 | memset(&tpr->rx_jmb_buffers[0], 0, |
| 6031 | TG3_RX_JMB_BUFF_RING_SIZE); |
| 6032 | goto done; |
| 6033 | } |
| 6034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6035 | /* Zero out all descriptors. */ |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6036 | memset(tpr->rx_std, 0, TG3_RX_RING_BYTES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6037 | |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6038 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 6039 | if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) && |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6040 | tp->dev->mtu > ETH_DATA_LEN) |
| 6041 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; |
| 6042 | 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] | 6043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6044 | /* Initialize invariants of the rings, we only set this |
| 6045 | * stuff once. This works because the card does not |
| 6046 | * write into the rx buffer posting rings. |
| 6047 | */ |
| 6048 | for (i = 0; i < TG3_RX_RING_SIZE; i++) { |
| 6049 | struct tg3_rx_buffer_desc *rxd; |
| 6050 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6051 | rxd = &tpr->rx_std[i]; |
Matt Carlson | 287be12 | 2009-08-28 13:58:46 +0000 | [diff] [blame] | 6052 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6053 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
| 6054 | rxd->opaque = (RXD_OPAQUE_RING_STD | |
| 6055 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 6056 | } |
| 6057 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6058 | /* Now allocate fresh SKBs for each rx ring. */ |
| 6059 | for (i = 0; i < tp->rx_pending; i++) { |
Matt Carlson | 86b21e5 | 2009-11-13 13:03:45 +0000 | [diff] [blame] | 6060 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_STD, i) < 0) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 6061 | netdev_warn(tp->dev, "Using a smaller RX standard ring, only %d out of %d buffers were allocated successfully\n", |
| 6062 | i, tp->rx_pending); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6063 | if (i == 0) |
| 6064 | goto initfail; |
| 6065 | tp->rx_pending = i; |
| 6066 | break; |
| 6067 | } |
| 6068 | } |
| 6069 | |
| 6070 | if (!(tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE)) |
| 6071 | goto done; |
| 6072 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6073 | memset(tpr->rx_jmb, 0, TG3_RX_JUMBO_RING_BYTES); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6074 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6075 | if (!(tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)) |
| 6076 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6077 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6078 | for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) { |
| 6079 | struct tg3_rx_buffer_desc *rxd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6080 | |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6081 | rxd = &tpr->rx_jmb[i].std; |
| 6082 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; |
| 6083 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | |
| 6084 | RXD_FLAG_JUMBO; |
| 6085 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | |
| 6086 | (i << RXD_OPAQUE_INDEX_SHIFT)); |
| 6087 | } |
| 6088 | |
| 6089 | for (i = 0; i < tp->rx_jumbo_pending; i++) { |
| 6090 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_JUMBO, i) < 0) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 6091 | netdev_warn(tp->dev, "Using a smaller RX jumbo ring, only %d out of %d buffers were allocated successfully\n", |
| 6092 | i, tp->rx_jumbo_pending); |
Matt Carlson | 0d86df8 | 2010-02-17 15:17:00 +0000 | [diff] [blame] | 6093 | if (i == 0) |
| 6094 | goto initfail; |
| 6095 | tp->rx_jumbo_pending = i; |
| 6096 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6097 | } |
| 6098 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6099 | |
| 6100 | done: |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 6101 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6102 | |
| 6103 | initfail: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6104 | tg3_rx_prodring_free(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6105 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6106 | } |
| 6107 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6108 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
| 6109 | struct tg3_rx_prodring_set *tpr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6110 | { |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6111 | kfree(tpr->rx_std_buffers); |
| 6112 | tpr->rx_std_buffers = NULL; |
| 6113 | kfree(tpr->rx_jmb_buffers); |
| 6114 | tpr->rx_jmb_buffers = NULL; |
| 6115 | if (tpr->rx_std) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6116 | pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6117 | tpr->rx_std, tpr->rx_std_mapping); |
| 6118 | tpr->rx_std = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6119 | } |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6120 | if (tpr->rx_jmb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6122 | tpr->rx_jmb, tpr->rx_jmb_mapping); |
| 6123 | tpr->rx_jmb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6124 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6125 | } |
| 6126 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6127 | static int tg3_rx_prodring_init(struct tg3 *tp, |
| 6128 | struct tg3_rx_prodring_set *tpr) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6129 | { |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6130 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE, GFP_KERNEL); |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6131 | if (!tpr->rx_std_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6132 | return -ENOMEM; |
| 6133 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6134 | tpr->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES, |
| 6135 | &tpr->rx_std_mapping); |
| 6136 | if (!tpr->rx_std) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6137 | goto err_out; |
| 6138 | |
| 6139 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6140 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6141 | GFP_KERNEL); |
| 6142 | if (!tpr->rx_jmb_buffers) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6143 | goto err_out; |
| 6144 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6145 | tpr->rx_jmb = pci_alloc_consistent(tp->pdev, |
| 6146 | TG3_RX_JUMBO_RING_BYTES, |
| 6147 | &tpr->rx_jmb_mapping); |
| 6148 | if (!tpr->rx_jmb) |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6149 | goto err_out; |
| 6150 | } |
| 6151 | |
| 6152 | return 0; |
| 6153 | |
| 6154 | err_out: |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 6155 | tg3_rx_prodring_fini(tp, tpr); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6156 | return -ENOMEM; |
| 6157 | } |
| 6158 | |
| 6159 | /* Free up pending packets in all rx/tx rings. |
| 6160 | * |
| 6161 | * The chip has been shut down and the driver detached from |
| 6162 | * the networking, so no interrupts or new tx packets will |
| 6163 | * end up in the driver. tp->{tx,}lock is not held and we are not |
| 6164 | * in an interrupt context and thus may sleep. |
| 6165 | */ |
| 6166 | static void tg3_free_rings(struct tg3 *tp) |
| 6167 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6168 | int i, j; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6169 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6170 | for (j = 0; j < tp->irq_cnt; j++) { |
| 6171 | struct tg3_napi *tnapi = &tp->napi[j]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6172 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6173 | if (!tnapi->tx_buffers) |
| 6174 | continue; |
| 6175 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6176 | for (i = 0; i < TG3_TX_RING_SIZE; ) { |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6177 | struct ring_info *txp; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6178 | struct sk_buff *skb; |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6179 | unsigned int k; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6180 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6181 | txp = &tnapi->tx_buffers[i]; |
| 6182 | skb = txp->skb; |
| 6183 | |
| 6184 | if (skb == NULL) { |
| 6185 | i++; |
| 6186 | continue; |
| 6187 | } |
| 6188 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6189 | pci_unmap_single(tp->pdev, |
| 6190 | pci_unmap_addr(txp, mapping), |
| 6191 | skb_headlen(skb), |
| 6192 | PCI_DMA_TODEVICE); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6193 | txp->skb = NULL; |
| 6194 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 6195 | i++; |
| 6196 | |
| 6197 | for (k = 0; k < skb_shinfo(skb)->nr_frags; k++) { |
| 6198 | txp = &tnapi->tx_buffers[i & (TG3_TX_RING_SIZE - 1)]; |
| 6199 | pci_unmap_page(tp->pdev, |
| 6200 | pci_unmap_addr(txp, mapping), |
| 6201 | skb_shinfo(skb)->frags[k].size, |
| 6202 | PCI_DMA_TODEVICE); |
| 6203 | i++; |
| 6204 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6205 | |
| 6206 | dev_kfree_skb_any(skb); |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6207 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6208 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6209 | tg3_rx_prodring_free(tp, &tp->prodring[j]); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6210 | } |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6211 | } |
| 6212 | |
| 6213 | /* Initialize tx/rx rings for packet processing. |
| 6214 | * |
| 6215 | * The chip has been shut down and the driver detached from |
| 6216 | * the networking, so no interrupts or new tx packets will |
| 6217 | * end up in the driver. tp->{tx,}lock are held and thus |
| 6218 | * we may not sleep. |
| 6219 | */ |
| 6220 | static int tg3_init_rings(struct tg3 *tp) |
| 6221 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6222 | int i; |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6223 | |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6224 | /* Free up all the SKBs. */ |
| 6225 | tg3_free_rings(tp); |
| 6226 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6227 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6228 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6229 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6230 | tnapi->last_tag = 0; |
| 6231 | tnapi->last_irq_tag = 0; |
| 6232 | tnapi->hw_status->status = 0; |
| 6233 | tnapi->hw_status->status_tag = 0; |
| 6234 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 6235 | |
| 6236 | tnapi->tx_prod = 0; |
| 6237 | tnapi->tx_cons = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6238 | if (tnapi->tx_ring) |
| 6239 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6240 | |
| 6241 | tnapi->rx_rcb_ptr = 0; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6242 | if (tnapi->rx_rcb) |
| 6243 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6244 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6245 | if (tg3_rx_prodring_alloc(tp, &tp->prodring[i])) { |
| 6246 | tg3_free_rings(tp); |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6247 | return -ENOMEM; |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6248 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6249 | } |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 6250 | |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6251 | return 0; |
Matt Carlson | cf7a729 | 2009-08-28 13:59:57 +0000 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | /* |
| 6255 | * Must not be invoked with interrupt sources disabled and |
| 6256 | * the hardware shutdown down. |
| 6257 | */ |
| 6258 | static void tg3_free_consistent(struct tg3 *tp) |
| 6259 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6260 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6261 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6262 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6263 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 6264 | |
| 6265 | if (tnapi->tx_ring) { |
| 6266 | pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES, |
| 6267 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
| 6268 | tnapi->tx_ring = NULL; |
| 6269 | } |
| 6270 | |
| 6271 | kfree(tnapi->tx_buffers); |
| 6272 | tnapi->tx_buffers = NULL; |
| 6273 | |
| 6274 | if (tnapi->rx_rcb) { |
| 6275 | pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp), |
| 6276 | tnapi->rx_rcb, |
| 6277 | tnapi->rx_rcb_mapping); |
| 6278 | tnapi->rx_rcb = NULL; |
| 6279 | } |
| 6280 | |
| 6281 | if (tnapi->hw_status) { |
| 6282 | pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE, |
| 6283 | tnapi->hw_status, |
| 6284 | tnapi->status_mapping); |
| 6285 | tnapi->hw_status = NULL; |
| 6286 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6287 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | if (tp->hw_stats) { |
| 6290 | pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats), |
| 6291 | tp->hw_stats, tp->stats_mapping); |
| 6292 | tp->hw_stats = NULL; |
| 6293 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6294 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6295 | for (i = 0; i < tp->irq_cnt; i++) |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6296 | tg3_rx_prodring_fini(tp, &tp->prodring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6297 | } |
| 6298 | |
| 6299 | /* |
| 6300 | * Must not be invoked with interrupt sources disabled and |
| 6301 | * the hardware shutdown down. Can sleep. |
| 6302 | */ |
| 6303 | static int tg3_alloc_consistent(struct tg3 *tp) |
| 6304 | { |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6305 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 6306 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6307 | for (i = 0; i < tp->irq_cnt; i++) { |
Matt Carlson | 2b2cdb6 | 2009-11-13 13:03:48 +0000 | [diff] [blame] | 6308 | if (tg3_rx_prodring_init(tp, &tp->prodring[i])) |
| 6309 | goto err_out; |
| 6310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6312 | tp->hw_stats = pci_alloc_consistent(tp->pdev, |
| 6313 | sizeof(struct tg3_hw_stats), |
| 6314 | &tp->stats_mapping); |
| 6315 | if (!tp->hw_stats) |
| 6316 | goto err_out; |
| 6317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6318 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 6319 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6320 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6321 | struct tg3_napi *tnapi = &tp->napi[i]; |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6322 | struct tg3_hw_status *sblk; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6323 | |
| 6324 | tnapi->hw_status = pci_alloc_consistent(tp->pdev, |
| 6325 | TG3_HW_STATUS_SIZE, |
| 6326 | &tnapi->status_mapping); |
| 6327 | if (!tnapi->hw_status) |
| 6328 | goto err_out; |
| 6329 | |
| 6330 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6331 | sblk = tnapi->hw_status; |
| 6332 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 6333 | /* If multivector TSS is enabled, vector 0 does not handle |
| 6334 | * tx interrupts. Don't allocate any resources for it. |
| 6335 | */ |
| 6336 | if ((!i && !(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) || |
| 6337 | (i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS))) { |
| 6338 | tnapi->tx_buffers = kzalloc(sizeof(struct ring_info) * |
| 6339 | TG3_TX_RING_SIZE, |
| 6340 | GFP_KERNEL); |
| 6341 | if (!tnapi->tx_buffers) |
| 6342 | goto err_out; |
| 6343 | |
| 6344 | tnapi->tx_ring = pci_alloc_consistent(tp->pdev, |
| 6345 | TG3_TX_RING_BYTES, |
| 6346 | &tnapi->tx_desc_mapping); |
| 6347 | if (!tnapi->tx_ring) |
| 6348 | goto err_out; |
| 6349 | } |
| 6350 | |
Matt Carlson | 8d9d7cf | 2009-09-01 13:19:05 +0000 | [diff] [blame] | 6351 | /* |
| 6352 | * When RSS is enabled, the status block format changes |
| 6353 | * slightly. The "rx_jumbo_consumer", "reserved", |
| 6354 | * and "rx_mini_consumer" members get mapped to the |
| 6355 | * other three rx return ring producer indexes. |
| 6356 | */ |
| 6357 | switch (i) { |
| 6358 | default: |
| 6359 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
| 6360 | break; |
| 6361 | case 2: |
| 6362 | tnapi->rx_rcb_prod_idx = &sblk->rx_jumbo_consumer; |
| 6363 | break; |
| 6364 | case 3: |
| 6365 | tnapi->rx_rcb_prod_idx = &sblk->reserved; |
| 6366 | break; |
| 6367 | case 4: |
| 6368 | tnapi->rx_rcb_prod_idx = &sblk->rx_mini_consumer; |
| 6369 | break; |
| 6370 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6371 | |
Matt Carlson | e4af1af | 2010-02-12 14:47:05 +0000 | [diff] [blame] | 6372 | tnapi->prodring = &tp->prodring[i]; |
Matt Carlson | b196c7e | 2009-11-13 13:03:50 +0000 | [diff] [blame] | 6373 | |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 6374 | /* |
| 6375 | * If multivector RSS is enabled, vector 0 does not handle |
| 6376 | * rx or tx interrupts. Don't allocate any resources for it. |
| 6377 | */ |
| 6378 | if (!i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) |
| 6379 | continue; |
| 6380 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6381 | tnapi->rx_rcb = pci_alloc_consistent(tp->pdev, |
| 6382 | TG3_RX_RCB_RING_BYTES(tp), |
| 6383 | &tnapi->rx_rcb_mapping); |
| 6384 | if (!tnapi->rx_rcb) |
| 6385 | goto err_out; |
| 6386 | |
| 6387 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6388 | } |
| 6389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6390 | return 0; |
| 6391 | |
| 6392 | err_out: |
| 6393 | tg3_free_consistent(tp); |
| 6394 | return -ENOMEM; |
| 6395 | } |
| 6396 | |
| 6397 | #define MAX_WAIT_CNT 1000 |
| 6398 | |
| 6399 | /* To stop a block, clear the enable bit and poll till it |
| 6400 | * clears. tp->lock is held. |
| 6401 | */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6402 | 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] | 6403 | { |
| 6404 | unsigned int i; |
| 6405 | u32 val; |
| 6406 | |
| 6407 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 6408 | switch (ofs) { |
| 6409 | case RCVLSC_MODE: |
| 6410 | case DMAC_MODE: |
| 6411 | case MBFREE_MODE: |
| 6412 | case BUFMGR_MODE: |
| 6413 | case MEMARB_MODE: |
| 6414 | /* We can't enable/disable these bits of the |
| 6415 | * 5705/5750, just say success. |
| 6416 | */ |
| 6417 | return 0; |
| 6418 | |
| 6419 | default: |
| 6420 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6422 | } |
| 6423 | |
| 6424 | val = tr32(ofs); |
| 6425 | val &= ~enable_bit; |
| 6426 | tw32_f(ofs, val); |
| 6427 | |
| 6428 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 6429 | udelay(100); |
| 6430 | val = tr32(ofs); |
| 6431 | if ((val & enable_bit) == 0) |
| 6432 | break; |
| 6433 | } |
| 6434 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6435 | if (i == MAX_WAIT_CNT && !silent) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 6436 | pr_err("tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6437 | ofs, enable_bit); |
| 6438 | return -ENODEV; |
| 6439 | } |
| 6440 | |
| 6441 | return 0; |
| 6442 | } |
| 6443 | |
| 6444 | /* tp->lock is held. */ |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6445 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6446 | { |
| 6447 | int i, err; |
| 6448 | |
| 6449 | tg3_disable_ints(tp); |
| 6450 | |
| 6451 | tp->rx_mode &= ~RX_MODE_ENABLE; |
| 6452 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 6453 | udelay(10); |
| 6454 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6455 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
| 6456 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); |
| 6457 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); |
| 6458 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); |
| 6459 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); |
| 6460 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6461 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6462 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); |
| 6463 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); |
| 6464 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); |
| 6465 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); |
| 6466 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); |
| 6467 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); |
| 6468 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6469 | |
| 6470 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 6471 | tw32_f(MAC_MODE, tp->mac_mode); |
| 6472 | udelay(40); |
| 6473 | |
| 6474 | tp->tx_mode &= ~TX_MODE_ENABLE; |
| 6475 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 6476 | |
| 6477 | for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 6478 | udelay(100); |
| 6479 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) |
| 6480 | break; |
| 6481 | } |
| 6482 | if (i >= MAX_WAIT_CNT) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 6483 | netdev_err(tp->dev, "%s timed out, TX_MODE_ENABLE will not clear MAC_TX_MODE=%08x\n", |
| 6484 | __func__, tr32(MAC_TX_MODE)); |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 6485 | err |= -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6486 | } |
| 6487 | |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 6488 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6489 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
| 6490 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6491 | |
| 6492 | tw32(FTQ_RESET, 0xffffffff); |
| 6493 | tw32(FTQ_RESET, 0x00000000); |
| 6494 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 6495 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
| 6496 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6497 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6498 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6499 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 6500 | if (tnapi->hw_status) |
| 6501 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 6502 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6503 | if (tp->hw_stats) |
| 6504 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 6505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6506 | return err; |
| 6507 | } |
| 6508 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6509 | static void tg3_ape_send_event(struct tg3 *tp, u32 event) |
| 6510 | { |
| 6511 | int i; |
| 6512 | u32 apedata; |
| 6513 | |
| 6514 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 6515 | if (apedata != APE_SEG_SIG_MAGIC) |
| 6516 | return; |
| 6517 | |
| 6518 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
Matt Carlson | 731fd79 | 2008-08-15 14:07:51 -0700 | [diff] [blame] | 6519 | if (!(apedata & APE_FW_STATUS_READY)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6520 | return; |
| 6521 | |
| 6522 | /* Wait for up to 1 millisecond for APE to service previous event. */ |
| 6523 | for (i = 0; i < 10; i++) { |
| 6524 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) |
| 6525 | return; |
| 6526 | |
| 6527 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 6528 | |
| 6529 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6530 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
| 6531 | event | APE_EVENT_STATUS_EVENT_PENDING); |
| 6532 | |
| 6533 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 6534 | |
| 6535 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6536 | break; |
| 6537 | |
| 6538 | udelay(100); |
| 6539 | } |
| 6540 | |
| 6541 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 6542 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 6543 | } |
| 6544 | |
| 6545 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
| 6546 | { |
| 6547 | u32 event; |
| 6548 | u32 apedata; |
| 6549 | |
| 6550 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) |
| 6551 | return; |
| 6552 | |
| 6553 | switch (kind) { |
| 6554 | case RESET_KIND_INIT: |
| 6555 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, |
| 6556 | APE_HOST_SEG_SIG_MAGIC); |
| 6557 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, |
| 6558 | APE_HOST_SEG_LEN_MAGIC); |
| 6559 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); |
| 6560 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); |
| 6561 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, |
| 6562 | APE_HOST_DRIVER_ID_MAGIC); |
| 6563 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
| 6564 | APE_HOST_BEHAV_NO_PHYLOCK); |
| 6565 | |
| 6566 | event = APE_EVENT_STATUS_STATE_START; |
| 6567 | break; |
| 6568 | case RESET_KIND_SHUTDOWN: |
Matt Carlson | b2aee15 | 2008-11-03 16:51:11 -0800 | [diff] [blame] | 6569 | /* With the interface we are currently using, |
| 6570 | * APE does not track driver state. Wiping |
| 6571 | * out the HOST SEGMENT SIGNATURE forces |
| 6572 | * the APE to assume OS absent status. |
| 6573 | */ |
| 6574 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); |
| 6575 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6576 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
| 6577 | break; |
| 6578 | case RESET_KIND_SUSPEND: |
| 6579 | event = APE_EVENT_STATUS_STATE_SUSPEND; |
| 6580 | break; |
| 6581 | default: |
| 6582 | return; |
| 6583 | } |
| 6584 | |
| 6585 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; |
| 6586 | |
| 6587 | tg3_ape_send_event(tp, event); |
| 6588 | } |
| 6589 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 6590 | /* tp->lock is held. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6591 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) |
| 6592 | { |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 6593 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
| 6594 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6595 | |
| 6596 | if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) { |
| 6597 | switch (kind) { |
| 6598 | case RESET_KIND_INIT: |
| 6599 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6600 | DRV_STATE_START); |
| 6601 | break; |
| 6602 | |
| 6603 | case RESET_KIND_SHUTDOWN: |
| 6604 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6605 | DRV_STATE_UNLOAD); |
| 6606 | break; |
| 6607 | |
| 6608 | case RESET_KIND_SUSPEND: |
| 6609 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6610 | DRV_STATE_SUSPEND); |
| 6611 | break; |
| 6612 | |
| 6613 | default: |
| 6614 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6615 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6616 | } |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6617 | |
| 6618 | if (kind == RESET_KIND_INIT || |
| 6619 | kind == RESET_KIND_SUSPEND) |
| 6620 | tg3_ape_driver_state_change(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6621 | } |
| 6622 | |
| 6623 | /* tp->lock is held. */ |
| 6624 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) |
| 6625 | { |
| 6626 | if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) { |
| 6627 | switch (kind) { |
| 6628 | case RESET_KIND_INIT: |
| 6629 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6630 | DRV_STATE_START_DONE); |
| 6631 | break; |
| 6632 | |
| 6633 | case RESET_KIND_SHUTDOWN: |
| 6634 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6635 | DRV_STATE_UNLOAD_DONE); |
| 6636 | break; |
| 6637 | |
| 6638 | default: |
| 6639 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6640 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6641 | } |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6642 | |
| 6643 | if (kind == RESET_KIND_SHUTDOWN) |
| 6644 | tg3_ape_driver_state_change(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6645 | } |
| 6646 | |
| 6647 | /* tp->lock is held. */ |
| 6648 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) |
| 6649 | { |
| 6650 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { |
| 6651 | switch (kind) { |
| 6652 | case RESET_KIND_INIT: |
| 6653 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6654 | DRV_STATE_START); |
| 6655 | break; |
| 6656 | |
| 6657 | case RESET_KIND_SHUTDOWN: |
| 6658 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6659 | DRV_STATE_UNLOAD); |
| 6660 | break; |
| 6661 | |
| 6662 | case RESET_KIND_SUSPEND: |
| 6663 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 6664 | DRV_STATE_SUSPEND); |
| 6665 | break; |
| 6666 | |
| 6667 | default: |
| 6668 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 6669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6670 | } |
| 6671 | } |
| 6672 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6673 | static int tg3_poll_fw(struct tg3 *tp) |
| 6674 | { |
| 6675 | int i; |
| 6676 | u32 val; |
| 6677 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6678 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Gary Zambrano | 0ccead1 | 2006-11-14 16:34:00 -0800 | [diff] [blame] | 6679 | /* Wait up to 20ms for init done. */ |
| 6680 | for (i = 0; i < 200; i++) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6681 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
| 6682 | return 0; |
Gary Zambrano | 0ccead1 | 2006-11-14 16:34:00 -0800 | [diff] [blame] | 6683 | udelay(100); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6684 | } |
| 6685 | return -ENODEV; |
| 6686 | } |
| 6687 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6688 | /* Wait for firmware initialization to complete. */ |
| 6689 | for (i = 0; i < 100000; i++) { |
| 6690 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); |
| 6691 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 6692 | break; |
| 6693 | udelay(10); |
| 6694 | } |
| 6695 | |
| 6696 | /* Chip might not be fitted with firmware. Some Sun onboard |
| 6697 | * parts are configured like that. So don't signal the timeout |
| 6698 | * of the above loop as an error, but do report the lack of |
| 6699 | * running firmware once. |
| 6700 | */ |
| 6701 | if (i >= 100000 && |
| 6702 | !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) { |
| 6703 | tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED; |
| 6704 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 6705 | netdev_info(tp->dev, "No firmware running\n"); |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6706 | } |
| 6707 | |
Matt Carlson | 6b10c16 | 2010-02-12 14:47:08 +0000 | [diff] [blame] | 6708 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
| 6709 | /* The 57765 A0 needs a little more |
| 6710 | * time to do some important work. |
| 6711 | */ |
| 6712 | mdelay(10); |
| 6713 | } |
| 6714 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6715 | return 0; |
| 6716 | } |
| 6717 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6718 | /* Save PCI command register before chip reset */ |
| 6719 | static void tg3_save_pci_state(struct tg3 *tp) |
| 6720 | { |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 6721 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6722 | } |
| 6723 | |
| 6724 | /* Restore PCI state after chip reset */ |
| 6725 | static void tg3_restore_pci_state(struct tg3 *tp) |
| 6726 | { |
| 6727 | u32 val; |
| 6728 | |
| 6729 | /* Re-enable indirect register accesses. */ |
| 6730 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 6731 | tp->misc_host_ctrl); |
| 6732 | |
| 6733 | /* Set MAX PCI retry to zero. */ |
| 6734 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); |
| 6735 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
| 6736 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) |
| 6737 | val |= PCISTATE_RETRY_SAME_DMA; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 6738 | /* Allow reads and writes to the APE register and memory space. */ |
| 6739 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 6740 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
| 6741 | PCISTATE_ALLOW_APE_SHMEM_WR; |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6742 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
| 6743 | |
Matt Carlson | 8a6eac9 | 2007-10-21 16:17:55 -0700 | [diff] [blame] | 6744 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6745 | |
Matt Carlson | fcb389d | 2008-11-03 16:55:44 -0800 | [diff] [blame] | 6746 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) { |
| 6747 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) |
| 6748 | pcie_set_readrq(tp->pdev, 4096); |
| 6749 | else { |
| 6750 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 6751 | tp->pci_cacheline_sz); |
| 6752 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 6753 | tp->pci_lat_timer); |
| 6754 | } |
Michael Chan | 114342f | 2007-10-15 02:12:26 -0700 | [diff] [blame] | 6755 | } |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 6756 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6757 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 6758 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 6759 | u16 pcix_cmd; |
| 6760 | |
| 6761 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 6762 | &pcix_cmd); |
| 6763 | pcix_cmd &= ~PCI_X_CMD_ERO; |
| 6764 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 6765 | pcix_cmd); |
| 6766 | } |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6767 | |
| 6768 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) { |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6769 | |
| 6770 | /* Chip reset on 5780 will reset MSI enable bit, |
| 6771 | * so need to restore it. |
| 6772 | */ |
| 6773 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { |
| 6774 | u16 ctrl; |
| 6775 | |
| 6776 | pci_read_config_word(tp->pdev, |
| 6777 | tp->msi_cap + PCI_MSI_FLAGS, |
| 6778 | &ctrl); |
| 6779 | pci_write_config_word(tp->pdev, |
| 6780 | tp->msi_cap + PCI_MSI_FLAGS, |
| 6781 | ctrl | PCI_MSI_FLAGS_ENABLE); |
| 6782 | val = tr32(MSGINT_MODE); |
| 6783 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); |
| 6784 | } |
| 6785 | } |
| 6786 | } |
| 6787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6788 | static void tg3_stop_fw(struct tg3 *); |
| 6789 | |
| 6790 | /* tp->lock is held. */ |
| 6791 | static int tg3_chip_reset(struct tg3 *tp) |
| 6792 | { |
| 6793 | u32 val; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 6794 | void (*write_op)(struct tg3 *, u32, u32); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6795 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6796 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 6797 | tg3_nvram_lock(tp); |
| 6798 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 6799 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
| 6800 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 6801 | /* No matching tg3_nvram_unlock() after this because |
| 6802 | * chip reset below will undo the nvram lock. |
| 6803 | */ |
| 6804 | tp->nvram_lock_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6805 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6806 | /* GRC_MISC_CFG core clock reset will clear the memory |
| 6807 | * enable bit in PCI register 4 and the MSI enable bit |
| 6808 | * on some chips, so we save relevant registers here. |
| 6809 | */ |
| 6810 | tg3_save_pci_state(tp); |
| 6811 | |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 6812 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 6813 | (tp->tg3_flags3 & TG3_FLG3_5755_PLUS)) |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 6814 | tw32(GRC_FASTBOOT_PC, 0); |
| 6815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6816 | /* |
| 6817 | * We must avoid the readl() that normally takes place. |
| 6818 | * It locks machines, causes machine checks, and other |
| 6819 | * fun things. So, temporarily disable the 5701 |
| 6820 | * hardware workaround, while we do the reset. |
| 6821 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 6822 | write_op = tp->write32; |
| 6823 | if (write_op == tg3_write_flush_reg32) |
| 6824 | tp->write32 = tg3_write32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6825 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6826 | /* Prevent the irq handler from reading or writing PCI registers |
| 6827 | * during chip reset when the memory enable bit in the PCI command |
| 6828 | * register may be cleared. The chip does not generate interrupt |
| 6829 | * at this time, but the irq handler may still be called due to irq |
| 6830 | * sharing or irqpoll. |
| 6831 | */ |
| 6832 | tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 6833 | for (i = 0; i < tp->irq_cnt; i++) { |
| 6834 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 6835 | if (tnapi->hw_status) { |
| 6836 | tnapi->hw_status->status = 0; |
| 6837 | tnapi->hw_status->status_tag = 0; |
| 6838 | } |
| 6839 | tnapi->last_tag = 0; |
| 6840 | tnapi->last_irq_tag = 0; |
Michael Chan | b8fa2f3 | 2007-04-06 17:35:37 -0700 | [diff] [blame] | 6841 | } |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6842 | smp_mb(); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 6843 | |
| 6844 | for (i = 0; i < tp->irq_cnt; i++) |
| 6845 | synchronize_irq(tp->napi[i].irq_vec); |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6846 | |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 6847 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 6848 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 6849 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 6850 | } |
| 6851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6852 | /* do the reset */ |
| 6853 | val = GRC_MISC_CFG_CORECLK_RESET; |
| 6854 | |
| 6855 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 6856 | if (tr32(0x7e2c) == 0x60) { |
| 6857 | tw32(0x7e2c, 0x20); |
| 6858 | } |
| 6859 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
| 6860 | tw32(GRC_MISC_CFG, (1 << 29)); |
| 6861 | val |= (1 << 29); |
| 6862 | } |
| 6863 | } |
| 6864 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 6865 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 6866 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
| 6867 | tw32(GRC_VCPU_EXT_CTRL, |
| 6868 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 6869 | } |
| 6870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6871 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
| 6872 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
| 6873 | tw32(GRC_MISC_CFG, val); |
| 6874 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 6875 | /* restore 5701 hardware bug workaround write method */ |
| 6876 | tp->write32 = write_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6877 | |
| 6878 | /* Unfortunately, we have to delay before the PCI read back. |
| 6879 | * Some 575X chips even will not respond to a PCI cfg access |
| 6880 | * when the reset command is given to the chip. |
| 6881 | * |
| 6882 | * How do these hardware designers expect things to work |
| 6883 | * properly if the PCI write is posted for a long period |
| 6884 | * of time? It is always necessary to have some method by |
| 6885 | * which a register read back can occur to push the write |
| 6886 | * out which does the reset. |
| 6887 | * |
| 6888 | * For most tg3 variants the trick below was working. |
| 6889 | * Ho hum... |
| 6890 | */ |
| 6891 | udelay(120); |
| 6892 | |
| 6893 | /* Flush PCI posted writes. The normal MMIO registers |
| 6894 | * are inaccessible at this time so this is the only |
| 6895 | * way to make this reliably (actually, this is no longer |
| 6896 | * the case, see above). I tried to use indirect |
| 6897 | * register read/write but this upset some 5701 variants. |
| 6898 | */ |
| 6899 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); |
| 6900 | |
| 6901 | udelay(120); |
| 6902 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 6903 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && tp->pcie_cap) { |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 6904 | u16 val16; |
| 6905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6906 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
| 6907 | int i; |
| 6908 | u32 cfg_val; |
| 6909 | |
| 6910 | /* Wait for link training to complete. */ |
| 6911 | for (i = 0; i < 5000; i++) |
| 6912 | udelay(100); |
| 6913 | |
| 6914 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); |
| 6915 | pci_write_config_dword(tp->pdev, 0xc4, |
| 6916 | cfg_val | (1 << 15)); |
| 6917 | } |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 6918 | |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 6919 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
| 6920 | pci_read_config_word(tp->pdev, |
| 6921 | tp->pcie_cap + PCI_EXP_DEVCTL, |
| 6922 | &val16); |
| 6923 | val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN | |
| 6924 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 6925 | /* |
| 6926 | * Older PCIe devices only support the 128 byte |
| 6927 | * MPS setting. Enforce the restriction. |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 6928 | */ |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 6929 | if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) || |
| 6930 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784)) |
| 6931 | val16 &= ~PCI_EXP_DEVCTL_PAYLOAD; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 6932 | pci_write_config_word(tp->pdev, |
| 6933 | tp->pcie_cap + PCI_EXP_DEVCTL, |
Matt Carlson | e712699 | 2009-08-25 10:08:16 +0000 | [diff] [blame] | 6934 | val16); |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 6935 | |
| 6936 | pcie_set_readrq(tp->pdev, 4096); |
| 6937 | |
| 6938 | /* Clear error status */ |
| 6939 | pci_write_config_word(tp->pdev, |
| 6940 | tp->pcie_cap + PCI_EXP_DEVSTA, |
| 6941 | PCI_EXP_DEVSTA_CED | |
| 6942 | PCI_EXP_DEVSTA_NFED | |
| 6943 | PCI_EXP_DEVSTA_FED | |
| 6944 | PCI_EXP_DEVSTA_URD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6945 | } |
| 6946 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6947 | tg3_restore_pci_state(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6948 | |
Michael Chan | d18edcb | 2007-03-24 20:57:11 -0700 | [diff] [blame] | 6949 | tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING; |
| 6950 | |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6951 | val = 0; |
| 6952 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 6953 | val = tr32(MEMARB_MODE); |
Michael Chan | ee6a99b | 2007-07-18 21:49:10 -0700 | [diff] [blame] | 6954 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6955 | |
| 6956 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { |
| 6957 | tg3_stop_fw(tp); |
| 6958 | tw32(0x5000, 0x400); |
| 6959 | } |
| 6960 | |
| 6961 | tw32(GRC_MODE, tp->grc_mode); |
| 6962 | |
| 6963 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 6964 | val = tr32(0xc4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6965 | |
| 6966 | tw32(0xc4, val | (1 << 15)); |
| 6967 | } |
| 6968 | |
| 6969 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && |
| 6970 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
| 6971 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
| 6972 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) |
| 6973 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
| 6974 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 6975 | } |
| 6976 | |
| 6977 | if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) { |
| 6978 | tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 6979 | tw32_f(MAC_MODE, tp->mac_mode); |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 6980 | } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) { |
| 6981 | tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 6982 | tw32_f(MAC_MODE, tp->mac_mode); |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 6983 | } else if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
| 6984 | tp->mac_mode &= (MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN); |
| 6985 | if (tp->mac_mode & MAC_MODE_APE_TX_EN) |
| 6986 | tp->mac_mode |= MAC_MODE_TDE_ENABLE; |
| 6987 | tw32_f(MAC_MODE, tp->mac_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6988 | } else |
| 6989 | tw32_f(MAC_MODE, 0); |
| 6990 | udelay(40); |
| 6991 | |
Matt Carlson | 77b483f | 2008-08-15 14:07:24 -0700 | [diff] [blame] | 6992 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
| 6993 | |
Michael Chan | 7a6f436 | 2006-09-27 16:03:31 -0700 | [diff] [blame] | 6994 | err = tg3_poll_fw(tp); |
| 6995 | if (err) |
| 6996 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6997 | |
Matt Carlson | 0a9140c | 2009-08-28 12:27:50 +0000 | [diff] [blame] | 6998 | tg3_mdio_start(tp); |
| 6999 | |
Matt Carlson | 52cdf85 | 2009-11-02 14:25:06 +0000 | [diff] [blame] | 7000 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 7001 | u8 phy_addr; |
| 7002 | |
| 7003 | phy_addr = tp->phy_addr; |
| 7004 | tp->phy_addr = TG3_PHY_PCIE_ADDR; |
| 7005 | |
| 7006 | tg3_writephy(tp, TG3_PCIEPHY_BLOCK_ADDR, |
| 7007 | TG3_PCIEPHY_TXB_BLK << TG3_PCIEPHY_BLOCK_SHIFT); |
| 7008 | val = TG3_PCIEPHY_TX0CTRL1_TXOCM | TG3_PCIEPHY_TX0CTRL1_RDCTL | |
| 7009 | TG3_PCIEPHY_TX0CTRL1_TXCMV | TG3_PCIEPHY_TX0CTRL1_TKSEL | |
| 7010 | TG3_PCIEPHY_TX0CTRL1_NB_EN; |
| 7011 | tg3_writephy(tp, TG3_PCIEPHY_TX0CTRL1, val); |
| 7012 | udelay(10); |
| 7013 | |
| 7014 | tg3_writephy(tp, TG3_PCIEPHY_BLOCK_ADDR, |
| 7015 | TG3_PCIEPHY_XGXS_BLK1 << TG3_PCIEPHY_BLOCK_SHIFT); |
| 7016 | val = TG3_PCIEPHY_PWRMGMT4_LOWPWR_EN | |
| 7017 | TG3_PCIEPHY_PWRMGMT4_L1PLLPD_EN; |
| 7018 | tg3_writephy(tp, TG3_PCIEPHY_PWRMGMT4, val); |
| 7019 | udelay(10); |
| 7020 | |
| 7021 | tp->phy_addr = phy_addr; |
| 7022 | } |
| 7023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7024 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 7025 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 7026 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7027 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 7028 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57765) { |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 7029 | val = tr32(0x7c00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7030 | |
| 7031 | tw32(0x7c00, val | (1 << 25)); |
| 7032 | } |
| 7033 | |
| 7034 | /* Reprobe ASF enable state. */ |
| 7035 | tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF; |
| 7036 | tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE; |
| 7037 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 7038 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 7039 | u32 nic_cfg; |
| 7040 | |
| 7041 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 7042 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
| 7043 | tp->tg3_flags |= TG3_FLAG_ENABLE_ASF; |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 7044 | tp->last_event_jiffies = jiffies; |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 7045 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7046 | tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE; |
| 7047 | } |
| 7048 | } |
| 7049 | |
| 7050 | return 0; |
| 7051 | } |
| 7052 | |
| 7053 | /* tp->lock is held. */ |
| 7054 | static void tg3_stop_fw(struct tg3 *tp) |
| 7055 | { |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7056 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) && |
| 7057 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 7058 | /* Wait for RX cpu to ACK the previous event. */ |
| 7059 | tg3_wait_for_event_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7060 | |
| 7061 | 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] | 7062 | |
| 7063 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7064 | |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 7065 | /* Wait for RX cpu to ACK this event. */ |
| 7066 | tg3_wait_for_event_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7067 | } |
| 7068 | } |
| 7069 | |
| 7070 | /* tp->lock is held. */ |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7071 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7072 | { |
| 7073 | int err; |
| 7074 | |
| 7075 | tg3_stop_fw(tp); |
| 7076 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7077 | tg3_write_sig_pre_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7078 | |
David S. Miller | b3b7d6b | 2005-05-05 14:40:20 -0700 | [diff] [blame] | 7079 | tg3_abort_hw(tp, silent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7080 | err = tg3_chip_reset(tp); |
| 7081 | |
Matt Carlson | daba2a6 | 2009-04-20 06:58:52 +0000 | [diff] [blame] | 7082 | __tg3_set_mac_addr(tp, 0); |
| 7083 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 7084 | tg3_write_sig_legacy(tp, kind); |
| 7085 | tg3_write_sig_post_reset(tp, kind); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7086 | |
| 7087 | if (err) |
| 7088 | return err; |
| 7089 | |
| 7090 | return 0; |
| 7091 | } |
| 7092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7093 | #define RX_CPU_SCRATCH_BASE 0x30000 |
| 7094 | #define RX_CPU_SCRATCH_SIZE 0x04000 |
| 7095 | #define TX_CPU_SCRATCH_BASE 0x34000 |
| 7096 | #define TX_CPU_SCRATCH_SIZE 0x04000 |
| 7097 | |
| 7098 | /* tp->lock is held. */ |
| 7099 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) |
| 7100 | { |
| 7101 | int i; |
| 7102 | |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 7103 | BUG_ON(offset == TX_CPU_BASE && |
| 7104 | (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7105 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 7106 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 7107 | u32 val = tr32(GRC_VCPU_EXT_CTRL); |
| 7108 | |
| 7109 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 7110 | return 0; |
| 7111 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7112 | if (offset == RX_CPU_BASE) { |
| 7113 | for (i = 0; i < 10000; i++) { |
| 7114 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7115 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 7116 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 7117 | break; |
| 7118 | } |
| 7119 | |
| 7120 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7121 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); |
| 7122 | udelay(10); |
| 7123 | } else { |
| 7124 | for (i = 0; i < 10000; i++) { |
| 7125 | tw32(offset + CPU_STATE, 0xffffffff); |
| 7126 | tw32(offset + CPU_MODE, CPU_MODE_HALT); |
| 7127 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) |
| 7128 | break; |
| 7129 | } |
| 7130 | } |
| 7131 | |
| 7132 | if (i >= 10000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 7133 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
| 7134 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7135 | return -ENODEV; |
| 7136 | } |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7137 | |
| 7138 | /* Clear firmware's nvram arbitration. */ |
| 7139 | if (tp->tg3_flags & TG3_FLAG_NVRAM) |
| 7140 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7141 | return 0; |
| 7142 | } |
| 7143 | |
| 7144 | struct fw_info { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7145 | unsigned int fw_base; |
| 7146 | unsigned int fw_len; |
| 7147 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7148 | }; |
| 7149 | |
| 7150 | /* tp->lock is held. */ |
| 7151 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base, |
| 7152 | int cpu_scratch_size, struct fw_info *info) |
| 7153 | { |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7154 | int err, lock_err, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7155 | void (*write_op)(struct tg3 *, u32, u32); |
| 7156 | |
| 7157 | if (cpu_base == TX_CPU_BASE && |
| 7158 | (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 7159 | netdev_err(tp->dev, "%s: Trying to load TX cpu firmware which is 5705\n", |
| 7160 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7161 | return -EINVAL; |
| 7162 | } |
| 7163 | |
| 7164 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
| 7165 | write_op = tg3_write_mem; |
| 7166 | else |
| 7167 | write_op = tg3_write_indirect_reg32; |
| 7168 | |
Michael Chan | 1b62815 | 2005-05-29 14:59:49 -0700 | [diff] [blame] | 7169 | /* It is possible that bootcode is still loading at this point. |
| 7170 | * Get the nvram lock first before halting the cpu. |
| 7171 | */ |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7172 | lock_err = tg3_nvram_lock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7173 | err = tg3_halt_cpu(tp, cpu_base); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 7174 | if (!lock_err) |
| 7175 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7176 | if (err) |
| 7177 | goto out; |
| 7178 | |
| 7179 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
| 7180 | write_op(tp, cpu_scratch_base + i, 0); |
| 7181 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7182 | 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] | 7183 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7184 | write_op(tp, (cpu_scratch_base + |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7185 | (info->fw_base & 0xffff) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7186 | (i * sizeof(u32))), |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7187 | be32_to_cpu(info->fw_data[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7188 | |
| 7189 | err = 0; |
| 7190 | |
| 7191 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7192 | return err; |
| 7193 | } |
| 7194 | |
| 7195 | /* tp->lock is held. */ |
| 7196 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) |
| 7197 | { |
| 7198 | struct fw_info info; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7199 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7200 | int err, i; |
| 7201 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7202 | fw_data = (void *)tp->fw->data; |
| 7203 | |
| 7204 | /* Firmware blob starts with version numbers, followed by |
| 7205 | start address and length. We are setting complete length. |
| 7206 | length = end_address_of_bss - start_address_of_text. |
| 7207 | Remainder is the blob to be loaded contiguously |
| 7208 | from start address. */ |
| 7209 | |
| 7210 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 7211 | info.fw_len = tp->fw->size - 12; |
| 7212 | info.fw_data = &fw_data[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7213 | |
| 7214 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
| 7215 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, |
| 7216 | &info); |
| 7217 | if (err) |
| 7218 | return err; |
| 7219 | |
| 7220 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, |
| 7221 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, |
| 7222 | &info); |
| 7223 | if (err) |
| 7224 | return err; |
| 7225 | |
| 7226 | /* Now startup only the RX cpu. */ |
| 7227 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7228 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7229 | |
| 7230 | for (i = 0; i < 5; i++) { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7231 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7232 | break; |
| 7233 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 7234 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7235 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7236 | udelay(1000); |
| 7237 | } |
| 7238 | if (i >= 5) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 7239 | netdev_err(tp->dev, "tg3_load_firmware fails to set RX CPU PC, is %08x should be %08x\n", |
| 7240 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7241 | return -ENODEV; |
| 7242 | } |
| 7243 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 7244 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); |
| 7245 | |
| 7246 | return 0; |
| 7247 | } |
| 7248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7249 | /* 5705 needs a special version of the TSO firmware. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7250 | |
| 7251 | /* tp->lock is held. */ |
| 7252 | static int tg3_load_tso_firmware(struct tg3 *tp) |
| 7253 | { |
| 7254 | struct fw_info info; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7255 | const __be32 *fw_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7256 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
| 7257 | int err, i; |
| 7258 | |
| 7259 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
| 7260 | return 0; |
| 7261 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7262 | fw_data = (void *)tp->fw->data; |
| 7263 | |
| 7264 | /* Firmware blob starts with version numbers, followed by |
| 7265 | start address and length. We are setting complete length. |
| 7266 | length = end_address_of_bss - start_address_of_text. |
| 7267 | Remainder is the blob to be loaded contiguously |
| 7268 | from start address. */ |
| 7269 | |
| 7270 | info.fw_base = be32_to_cpu(fw_data[1]); |
| 7271 | cpu_scratch_size = tp->fw_len; |
| 7272 | info.fw_len = tp->fw->size - 12; |
| 7273 | info.fw_data = &fw_data[3]; |
| 7274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7275 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7276 | cpu_base = RX_CPU_BASE; |
| 7277 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7278 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7279 | cpu_base = TX_CPU_BASE; |
| 7280 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; |
| 7281 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; |
| 7282 | } |
| 7283 | |
| 7284 | err = tg3_load_firmware_cpu(tp, cpu_base, |
| 7285 | cpu_scratch_base, cpu_scratch_size, |
| 7286 | &info); |
| 7287 | if (err) |
| 7288 | return err; |
| 7289 | |
| 7290 | /* Now startup the cpu. */ |
| 7291 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7292 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7293 | |
| 7294 | for (i = 0; i < 5; i++) { |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7295 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7296 | break; |
| 7297 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7298 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7299 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7300 | udelay(1000); |
| 7301 | } |
| 7302 | if (i >= 5) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 7303 | netdev_err(tp->dev, "%s fails to set CPU PC, is %08x should be %08x\n", |
| 7304 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7305 | return -ENODEV; |
| 7306 | } |
| 7307 | tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 7308 | tw32_f(cpu_base + CPU_MODE, 0x00000000); |
| 7309 | return 0; |
| 7310 | } |
| 7311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7313 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
| 7314 | { |
| 7315 | struct tg3 *tp = netdev_priv(dev); |
| 7316 | struct sockaddr *addr = p; |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7317 | int err = 0, skip_mac_1 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7318 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 7319 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7320 | return -EINVAL; |
| 7321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7322 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 7323 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 7324 | if (!netif_running(dev)) |
| 7325 | return 0; |
| 7326 | |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7327 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7328 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7329 | |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7330 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
| 7331 | addr0_low = tr32(MAC_ADDR_0_LOW); |
| 7332 | addr1_high = tr32(MAC_ADDR_1_HIGH); |
| 7333 | addr1_low = tr32(MAC_ADDR_1_LOW); |
| 7334 | |
| 7335 | /* Skip MAC addr 1 if ASF is using it. */ |
| 7336 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && |
| 7337 | !(addr1_high == 0 && addr1_low == 0)) |
| 7338 | skip_mac_1 = 1; |
Michael Chan | 58712ef | 2006-04-29 18:58:01 -0700 | [diff] [blame] | 7339 | } |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7340 | spin_lock_bh(&tp->lock); |
| 7341 | __tg3_set_mac_addr(tp, skip_mac_1); |
| 7342 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7343 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 7344 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7345 | } |
| 7346 | |
| 7347 | /* tp->lock is held. */ |
| 7348 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, |
| 7349 | dma_addr_t mapping, u32 maxlen_flags, |
| 7350 | u32 nic_addr) |
| 7351 | { |
| 7352 | tg3_write_mem(tp, |
| 7353 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 7354 | ((u64) mapping >> 32)); |
| 7355 | tg3_write_mem(tp, |
| 7356 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), |
| 7357 | ((u64) mapping & 0xffffffff)); |
| 7358 | tg3_write_mem(tp, |
| 7359 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), |
| 7360 | maxlen_flags); |
| 7361 | |
| 7362 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 7363 | tg3_write_mem(tp, |
| 7364 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), |
| 7365 | nic_addr); |
| 7366 | } |
| 7367 | |
| 7368 | static void __tg3_set_rx_mode(struct net_device *); |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 7369 | 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] | 7370 | { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7371 | int i; |
| 7372 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7373 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7374 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
| 7375 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); |
| 7376 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7377 | } else { |
| 7378 | tw32(HOSTCC_TXCOL_TICKS, 0); |
| 7379 | tw32(HOSTCC_TXMAX_FRAMES, 0); |
| 7380 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7381 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7382 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7383 | if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSIX)) { |
| 7384 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
| 7385 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); |
| 7386 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); |
| 7387 | } else { |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7388 | tw32(HOSTCC_RXCOL_TICKS, 0); |
| 7389 | tw32(HOSTCC_RXMAX_FRAMES, 0); |
| 7390 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7391 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7392 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7393 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 7394 | u32 val = ec->stats_block_coalesce_usecs; |
| 7395 | |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7396 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
| 7397 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); |
| 7398 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7399 | if (!netif_carrier_ok(tp->dev)) |
| 7400 | val = 0; |
| 7401 | |
| 7402 | tw32(HOSTCC_STAT_COAL_TICKS, val); |
| 7403 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7404 | |
| 7405 | for (i = 0; i < tp->irq_cnt - 1; i++) { |
| 7406 | u32 reg; |
| 7407 | |
| 7408 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; |
| 7409 | tw32(reg, ec->rx_coalesce_usecs); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7410 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
| 7411 | tw32(reg, ec->rx_max_coalesced_frames); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7412 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 7413 | tw32(reg, ec->rx_max_coalesced_frames_irq); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7414 | |
| 7415 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) { |
| 7416 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
| 7417 | tw32(reg, ec->tx_coalesce_usecs); |
| 7418 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; |
| 7419 | tw32(reg, ec->tx_max_coalesced_frames); |
| 7420 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 7421 | tw32(reg, ec->tx_max_coalesced_frames_irq); |
| 7422 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7423 | } |
| 7424 | |
| 7425 | for (; i < tp->irq_max - 1; i++) { |
| 7426 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7427 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7428 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7429 | |
| 7430 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) { |
| 7431 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 7432 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 7433 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 7434 | } |
Matt Carlson | b6080e1 | 2009-09-01 13:12:00 +0000 | [diff] [blame] | 7435 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 7436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7437 | |
| 7438 | /* tp->lock is held. */ |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7439 | static void tg3_rings_reset(struct tg3 *tp) |
| 7440 | { |
| 7441 | int i; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7442 | u32 stblk, txrcb, rxrcb, limit; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7443 | struct tg3_napi *tnapi = &tp->napi[0]; |
| 7444 | |
| 7445 | /* Disable all transmit rings but the first. */ |
| 7446 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 7447 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7448 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 7449 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7450 | else |
| 7451 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 7452 | |
| 7453 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 7454 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) |
| 7455 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 7456 | BDINFO_FLAGS_DISABLED); |
| 7457 | |
| 7458 | |
| 7459 | /* Disable all receive return rings but the first. */ |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 7460 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
| 7461 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
| 7462 | else if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7463 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7464 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
| 7465 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7466 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
| 7467 | else |
| 7468 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 7469 | |
| 7470 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 7471 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) |
| 7472 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 7473 | BDINFO_FLAGS_DISABLED); |
| 7474 | |
| 7475 | /* Disable interrupts */ |
| 7476 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); |
| 7477 | |
| 7478 | /* Zero mailbox registers. */ |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7479 | if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX) { |
| 7480 | for (i = 1; i < TG3_IRQ_MAX_VECS; i++) { |
| 7481 | tp->napi[i].tx_prod = 0; |
| 7482 | tp->napi[i].tx_cons = 0; |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 7483 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
| 7484 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7485 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
| 7486 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); |
| 7487 | } |
Matt Carlson | c2353a3 | 2010-01-20 16:58:08 +0000 | [diff] [blame] | 7488 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) |
| 7489 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7490 | } else { |
| 7491 | tp->napi[0].tx_prod = 0; |
| 7492 | tp->napi[0].tx_cons = 0; |
| 7493 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 7494 | tw32_rx_mbox(tp->napi[0].consmbox, 0); |
| 7495 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7496 | |
| 7497 | /* Make sure the NIC-based send BD rings are disabled. */ |
| 7498 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 7499 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 7500 | for (i = 0; i < 16; i++) |
| 7501 | tw32_tx_mbox(mbox + i * 8, 0); |
| 7502 | } |
| 7503 | |
| 7504 | txrcb = NIC_SRAM_SEND_RCB; |
| 7505 | rxrcb = NIC_SRAM_RCV_RET_RCB; |
| 7506 | |
| 7507 | /* Clear status block in ram. */ |
| 7508 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7509 | |
| 7510 | /* Set status block DMA address */ |
| 7511 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 7512 | ((u64) tnapi->status_mapping >> 32)); |
| 7513 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 7514 | ((u64) tnapi->status_mapping & 0xffffffff)); |
| 7515 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7516 | if (tnapi->tx_ring) { |
| 7517 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 7518 | (TG3_TX_RING_SIZE << |
| 7519 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 7520 | NIC_SRAM_TX_BUFFER_DESC); |
| 7521 | txrcb += TG3_BDINFO_SIZE; |
| 7522 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7523 | |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7524 | if (tnapi->rx_rcb) { |
| 7525 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
| 7526 | (TG3_RX_RCB_RING_SIZE(tp) << |
| 7527 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
| 7528 | rxrcb += TG3_BDINFO_SIZE; |
| 7529 | } |
| 7530 | |
| 7531 | stblk = HOSTCC_STATBLCK_RING1; |
| 7532 | |
| 7533 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
| 7534 | u64 mapping = (u64)tnapi->status_mapping; |
| 7535 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); |
| 7536 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); |
| 7537 | |
| 7538 | /* Clear status block in ram. */ |
| 7539 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 7540 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 7541 | if (tnapi->tx_ring) { |
| 7542 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 7543 | (TG3_TX_RING_SIZE << |
| 7544 | BDINFO_FLAGS_MAXLEN_SHIFT), |
| 7545 | NIC_SRAM_TX_BUFFER_DESC); |
| 7546 | txrcb += TG3_BDINFO_SIZE; |
| 7547 | } |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7548 | |
| 7549 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
| 7550 | (TG3_RX_RCB_RING_SIZE(tp) << |
| 7551 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
| 7552 | |
| 7553 | stblk += 8; |
Matt Carlson | f77a6a8 | 2009-09-01 13:04:37 +0000 | [diff] [blame] | 7554 | rxrcb += TG3_BDINFO_SIZE; |
| 7555 | } |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7556 | } |
| 7557 | |
| 7558 | /* tp->lock is held. */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 7559 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7560 | { |
| 7561 | u32 val, rdmac_mode; |
| 7562 | int i, err, limit; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7563 | struct tg3_rx_prodring_set *tpr = &tp->prodring[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7564 | |
| 7565 | tg3_disable_ints(tp); |
| 7566 | |
| 7567 | tg3_stop_fw(tp); |
| 7568 | |
| 7569 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); |
| 7570 | |
| 7571 | if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) { |
Michael Chan | e6de8ad | 2005-05-05 14:42:41 -0700 | [diff] [blame] | 7572 | tg3_abort_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7573 | } |
| 7574 | |
Matt Carlson | 603f117 | 2010-02-12 14:47:10 +0000 | [diff] [blame] | 7575 | if (reset_phy) |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 7576 | tg3_phy_reset(tp); |
| 7577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7578 | err = tg3_chip_reset(tp); |
| 7579 | if (err) |
| 7580 | return err; |
| 7581 | |
| 7582 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); |
| 7583 | |
Matt Carlson | bcb37f6 | 2008-11-03 16:52:09 -0800 | [diff] [blame] | 7584 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7585 | val = tr32(TG3_CPMU_CTRL); |
| 7586 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); |
| 7587 | tw32(TG3_CPMU_CTRL, val); |
Matt Carlson | 9acb961 | 2007-11-12 21:10:06 -0800 | [diff] [blame] | 7588 | |
| 7589 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 7590 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 7591 | val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 7592 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 7593 | |
| 7594 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); |
| 7595 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; |
| 7596 | val |= CPMU_LNK_AWARE_MACCLK_6_25; |
| 7597 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); |
| 7598 | |
| 7599 | val = tr32(TG3_CPMU_HST_ACC); |
| 7600 | val &= ~CPMU_HST_ACC_MACCLK_MASK; |
| 7601 | val |= CPMU_HST_ACC_MACCLK_6_25; |
| 7602 | tw32(TG3_CPMU_HST_ACC, val); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7603 | } |
| 7604 | |
Matt Carlson | 33466d9 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 7605 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
| 7606 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 7607 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | |
| 7608 | PCIE_PWR_MGMT_L1_THRESH_4MS; |
| 7609 | tw32(PCIE_PWR_MGMT_THRESH, val); |
Matt Carlson | 521e6b9 | 2009-08-25 10:06:01 +0000 | [diff] [blame] | 7610 | |
| 7611 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; |
| 7612 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); |
| 7613 | |
| 7614 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); |
Matt Carlson | 33466d9 | 2009-04-20 06:57:41 +0000 | [diff] [blame] | 7615 | |
Matt Carlson | f40386c | 2009-11-02 14:24:02 +0000 | [diff] [blame] | 7616 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 7617 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
Matt Carlson | 255ca31 | 2009-08-25 10:07:27 +0000 | [diff] [blame] | 7618 | } |
| 7619 | |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 7620 | if (tp->tg3_flags3 & TG3_FLG3_L1PLLPD_EN) { |
| 7621 | u32 grc_mode = tr32(GRC_MODE); |
| 7622 | |
| 7623 | /* Access the lower 1K of PL PCIE block registers. */ |
| 7624 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 7625 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 7626 | |
| 7627 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); |
| 7628 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, |
| 7629 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); |
| 7630 | |
| 7631 | tw32(GRC_MODE, grc_mode); |
| 7632 | } |
| 7633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7634 | /* This works around an issue with Athlon chipsets on |
| 7635 | * B3 tigon3 silicon. This bit has no effect on any |
| 7636 | * other revision. But do not set this on PCI Express |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 7637 | * 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] | 7638 | */ |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 7639 | if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) { |
| 7640 | if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) |
| 7641 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
| 7642 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 7643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7644 | |
| 7645 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && |
| 7646 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) { |
| 7647 | val = tr32(TG3PCI_PCISTATE); |
| 7648 | val |= PCISTATE_RETRY_SAME_DMA; |
| 7649 | tw32(TG3PCI_PCISTATE, val); |
| 7650 | } |
| 7651 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 7652 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
| 7653 | /* Allow reads and writes to the |
| 7654 | * APE register and memory space. |
| 7655 | */ |
| 7656 | val = tr32(TG3PCI_PCISTATE); |
| 7657 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
| 7658 | PCISTATE_ALLOW_APE_SHMEM_WR; |
| 7659 | tw32(TG3PCI_PCISTATE, val); |
| 7660 | } |
| 7661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7662 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
| 7663 | /* Enable some hw fixes. */ |
| 7664 | val = tr32(TG3PCI_MSI_DATA); |
| 7665 | val |= (1 << 26) | (1 << 28) | (1 << 29); |
| 7666 | tw32(TG3PCI_MSI_DATA, val); |
| 7667 | } |
| 7668 | |
| 7669 | /* Descriptor ring init may make accesses to the |
| 7670 | * NIC SRAM area to setup the TX descriptors, so we |
| 7671 | * can only do this after the hardware has been |
| 7672 | * successfully reset. |
| 7673 | */ |
Michael Chan | 32d8c57 | 2006-07-25 16:38:29 -0700 | [diff] [blame] | 7674 | err = tg3_init_rings(tp); |
| 7675 | if (err) |
| 7676 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7677 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7678 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 7679 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 7680 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
| 7681 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 7682 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
| 7683 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && |
| 7684 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7685 | /* This value is determined during the probe time DMA |
| 7686 | * engine test, tg3_test_dma. |
| 7687 | */ |
| 7688 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 7689 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7690 | |
| 7691 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | |
| 7692 | GRC_MODE_4X_NIC_SEND_RINGS | |
| 7693 | GRC_MODE_NO_TX_PHDR_CSUM | |
| 7694 | GRC_MODE_NO_RX_PHDR_CSUM); |
| 7695 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; |
Michael Chan | d2d746f | 2006-04-06 21:45:39 -0700 | [diff] [blame] | 7696 | |
| 7697 | /* Pseudo-header checksum is done by hardware logic and not |
| 7698 | * the offload processers, so make the chip do the pseudo- |
| 7699 | * header checksums on receive. For transmit it is more |
| 7700 | * convenient to do the pseudo-header checksum in software |
| 7701 | * as Linux does that on transmit for us in all cases. |
| 7702 | */ |
| 7703 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7704 | |
| 7705 | tw32(GRC_MODE, |
| 7706 | tp->grc_mode | |
| 7707 | (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP)); |
| 7708 | |
| 7709 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ |
| 7710 | val = tr32(GRC_MISC_CFG); |
| 7711 | val &= ~0xff; |
| 7712 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 7713 | tw32(GRC_MISC_CFG, val); |
| 7714 | |
| 7715 | /* Initialize MBUF/DESC pool. */ |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 7716 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7717 | /* Do nothing. */ |
| 7718 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { |
| 7719 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
| 7720 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 7721 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
| 7722 | else |
| 7723 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); |
| 7724 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); |
| 7725 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); |
| 7726 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7727 | else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) { |
| 7728 | int fw_len; |
| 7729 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 7730 | fw_len = tp->fw_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7731 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
| 7732 | tw32(BUFMGR_MB_POOL_ADDR, |
| 7733 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); |
| 7734 | tw32(BUFMGR_MB_POOL_SIZE, |
| 7735 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); |
| 7736 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7737 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 7738 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7739 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 7740 | tp->bufmgr_config.mbuf_read_dma_low_water); |
| 7741 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 7742 | tp->bufmgr_config.mbuf_mac_rx_low_water); |
| 7743 | tw32(BUFMGR_MB_HIGH_WATER, |
| 7744 | tp->bufmgr_config.mbuf_high_water); |
| 7745 | } else { |
| 7746 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 7747 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); |
| 7748 | tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 7749 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); |
| 7750 | tw32(BUFMGR_MB_HIGH_WATER, |
| 7751 | tp->bufmgr_config.mbuf_high_water_jumbo); |
| 7752 | } |
| 7753 | tw32(BUFMGR_DMA_LOW_WATER, |
| 7754 | tp->bufmgr_config.dma_low_water); |
| 7755 | tw32(BUFMGR_DMA_HIGH_WATER, |
| 7756 | tp->bufmgr_config.dma_high_water); |
| 7757 | |
| 7758 | tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE); |
| 7759 | for (i = 0; i < 2000; i++) { |
| 7760 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) |
| 7761 | break; |
| 7762 | udelay(10); |
| 7763 | } |
| 7764 | if (i >= 2000) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 7765 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7766 | return -ENODEV; |
| 7767 | } |
| 7768 | |
| 7769 | /* Setup replenish threshold. */ |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 7770 | val = tp->rx_pending / 8; |
| 7771 | if (val == 0) |
| 7772 | val = 1; |
| 7773 | else if (val > tp->rx_std_max_post) |
| 7774 | val = tp->rx_std_max_post; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 7775 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 7776 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) |
| 7777 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
| 7778 | |
| 7779 | if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2)) |
| 7780 | val = TG3_RX_INTERNAL_RING_SZ_5906 / 2; |
| 7781 | } |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 7782 | |
| 7783 | tw32(RCVBDI_STD_THRESH, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7784 | |
| 7785 | /* Initialize TG3_BDINFO's at: |
| 7786 | * RCVDBDI_STD_BD: standard eth size rx ring |
| 7787 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring |
| 7788 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) |
| 7789 | * |
| 7790 | * like so: |
| 7791 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring |
| 7792 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | |
| 7793 | * ring attribute flags |
| 7794 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM |
| 7795 | * |
| 7796 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. |
| 7797 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. |
| 7798 | * |
| 7799 | * The size of each ring is fixed in the firmware, but the location is |
| 7800 | * configurable. |
| 7801 | */ |
| 7802 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7803 | ((u64) tpr->rx_std_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7804 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7805 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
Matt Carlson | 13fa95b0 | 2010-01-12 10:11:36 +0000 | [diff] [blame] | 7806 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 7807 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
| 7808 | NIC_SRAM_RX_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7809 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 7810 | /* Disable the mini ring */ |
| 7811 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7812 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 7813 | BDINFO_FLAGS_DISABLED); |
| 7814 | |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 7815 | /* Program the jumbo buffer descriptor ring control |
| 7816 | * blocks on those devices that have them. |
| 7817 | */ |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 7818 | if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 7819 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7820 | /* Setup replenish threshold. */ |
| 7821 | tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8); |
| 7822 | |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 7823 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7824 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7825 | ((u64) tpr->rx_jmb_mapping >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7826 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 7827 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7828 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
Matt Carlson | 79ed5ac | 2009-08-28 14:00:55 +0000 | [diff] [blame] | 7829 | (RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT) | |
| 7830 | BDINFO_FLAGS_USE_EXT_RECV); |
Matt Carlson | 5fd68fb | 2010-01-20 16:58:07 +0000 | [diff] [blame] | 7831 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) |
Matt Carlson | 87668d3 | 2009-11-13 13:03:34 +0000 | [diff] [blame] | 7832 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
| 7833 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7834 | } else { |
| 7835 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 7836 | BDINFO_FLAGS_DISABLED); |
| 7837 | } |
| 7838 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7839 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 7840 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 7841 | val = (RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT) | |
| 7842 | (RX_STD_MAX_SIZE << 2); |
| 7843 | else |
| 7844 | val = RX_STD_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT; |
Matt Carlson | fdb72b3 | 2009-08-28 13:57:12 +0000 | [diff] [blame] | 7845 | } else |
| 7846 | val = RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT; |
| 7847 | |
| 7848 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7849 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 7850 | tpr->rx_std_prod_idx = tp->rx_pending; |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 7851 | 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] | 7852 | |
Matt Carlson | 411da64 | 2009-11-13 13:03:46 +0000 | [diff] [blame] | 7853 | 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] | 7854 | tp->rx_jumbo_pending : 0; |
Matt Carlson | 66711e6 | 2009-11-13 13:03:49 +0000 | [diff] [blame] | 7855 | 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] | 7856 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 7857 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 7858 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 7859 | tw32(STD_REPLENISH_LWM, 32); |
| 7860 | tw32(JMB_REPLENISH_LWM, 16); |
| 7861 | } |
| 7862 | |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7863 | tg3_rings_reset(tp); |
| 7864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7865 | /* Initialize MAC address and backoff seed. */ |
Michael Chan | 986e0ae | 2007-05-05 12:10:20 -0700 | [diff] [blame] | 7866 | __tg3_set_mac_addr(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7867 | |
| 7868 | /* MTU + ethernet header + FCS + optional VLAN tag */ |
Matt Carlson | f7b493e | 2009-02-25 14:21:52 +0000 | [diff] [blame] | 7869 | tw32(MAC_RX_MTU_SIZE, |
| 7870 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7871 | |
| 7872 | /* The slot time is changed by tg3_setup_phy if we |
| 7873 | * run at gigabit with half duplex. |
| 7874 | */ |
| 7875 | tw32(MAC_TX_LENGTHS, |
| 7876 | (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 7877 | (6 << TX_LENGTHS_IPG_SHIFT) | |
| 7878 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); |
| 7879 | |
| 7880 | /* Receive rules. */ |
| 7881 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); |
| 7882 | tw32(RCVLPC_CONFIG, 0x0181); |
| 7883 | |
| 7884 | /* Calculate RDMAC_MODE setting early, we need it to determine |
| 7885 | * the RCVLPC_STATE_ENABLE mask. |
| 7886 | */ |
| 7887 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | |
| 7888 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | |
| 7889 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | |
| 7890 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | |
| 7891 | RDMAC_MODE_LNGREAD_ENAB); |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 7892 | |
Matt Carlson | 0339e4e | 2010-02-12 14:47:09 +0000 | [diff] [blame] | 7893 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
| 7894 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
| 7895 | |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 7896 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 7897 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 7898 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 7899 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
| 7900 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | |
| 7901 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; |
| 7902 | |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 7903 | /* If statement applies to 5705 and 5750 PCI devices only */ |
| 7904 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 7905 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) || |
| 7906 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7907 | if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE && |
Matt Carlson | c13e371 | 2007-05-05 11:50:04 -0700 | [diff] [blame] | 7908 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7909 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
| 7910 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
| 7911 | !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) { |
| 7912 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 7913 | } |
| 7914 | } |
| 7915 | |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 7916 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) |
| 7917 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 7918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7919 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 7920 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
| 7921 | |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 7922 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
| 7923 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 7924 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
| 7925 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7926 | |
| 7927 | /* Receive/send statistics. */ |
Michael Chan | 1661394 | 2006-06-29 20:15:13 -0700 | [diff] [blame] | 7928 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
| 7929 | val = tr32(RCVLPC_STATS_ENABLE); |
| 7930 | val &= ~RCVLPC_STATSENAB_DACK_FIX; |
| 7931 | tw32(RCVLPC_STATS_ENABLE, val); |
| 7932 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && |
| 7933 | (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7934 | val = tr32(RCVLPC_STATS_ENABLE); |
| 7935 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; |
| 7936 | tw32(RCVLPC_STATS_ENABLE, val); |
| 7937 | } else { |
| 7938 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); |
| 7939 | } |
| 7940 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); |
| 7941 | tw32(SNDDATAI_STATSENAB, 0xffffff); |
| 7942 | tw32(SNDDATAI_STATSCTRL, |
| 7943 | (SNDDATAI_SCTRL_ENABLE | |
| 7944 | SNDDATAI_SCTRL_FASTUPD)); |
| 7945 | |
| 7946 | /* Setup host coalescing engine. */ |
| 7947 | tw32(HOSTCC_MODE, 0); |
| 7948 | for (i = 0; i < 2000; i++) { |
| 7949 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) |
| 7950 | break; |
| 7951 | udelay(10); |
| 7952 | } |
| 7953 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 7954 | __tg3_set_coalesce(tp, &tp->coal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7956 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 7957 | /* Status/statistics block address. See tg3_timer, |
| 7958 | * the tg3_periodic_fetch_stats call there, and |
| 7959 | * tg3_get_stats to see how this works for 5705/5750 chips. |
| 7960 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7961 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 7962 | ((u64) tp->stats_mapping >> 32)); |
| 7963 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 7964 | ((u64) tp->stats_mapping & 0xffffffff)); |
| 7965 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7967 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
Matt Carlson | 2d31eca | 2009-09-01 12:53:31 +0000 | [diff] [blame] | 7968 | |
| 7969 | /* Clear statistics and status block memory areas */ |
| 7970 | for (i = NIC_SRAM_STATS_BLK; |
| 7971 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; |
| 7972 | i += sizeof(u32)) { |
| 7973 | tg3_write_mem(tp, i, 0); |
| 7974 | udelay(40); |
| 7975 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7976 | } |
| 7977 | |
| 7978 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); |
| 7979 | |
| 7980 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); |
| 7981 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); |
| 7982 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 7983 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
| 7984 | |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 7985 | if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) { |
| 7986 | tp->tg3_flags2 &= ~TG3_FLG2_PARALLEL_DETECT; |
| 7987 | /* reset to prevent losing 1st rx packet intermittently */ |
| 7988 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 7989 | udelay(10); |
| 7990 | } |
| 7991 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 7992 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 7993 | tp->mac_mode &= MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
| 7994 | else |
| 7995 | tp->mac_mode = 0; |
| 7996 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7997 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE; |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 7998 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
| 7999 | !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) && |
| 8000 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
| 8001 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8002 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
| 8003 | udelay(40); |
| 8004 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8005 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8006 | * If TG3_FLG2_IS_NIC is zero, we should read the |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8007 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
| 8008 | * whether used as inputs or outputs, are set by boot code after |
| 8009 | * reset. |
| 8010 | */ |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8011 | if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8012 | u32 gpio_mask; |
| 8013 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8014 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
| 8015 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 8016 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 8017 | |
| 8018 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 8019 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
| 8020 | GRC_LCLCTRL_GPIO_OUTPUT3; |
| 8021 | |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 8022 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 8023 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 8024 | |
Gary Zambrano | aaf8446 | 2007-05-05 11:51:45 -0700 | [diff] [blame] | 8025 | tp->grc_local_ctrl &= ~gpio_mask; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8026 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
| 8027 | |
| 8028 | /* GPIO1 must be driven high for eeprom write protect */ |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 8029 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) |
| 8030 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 8031 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 8032 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8033 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 8034 | udelay(100); |
| 8035 | |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8036 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) { |
| 8037 | val = tr32(MSGINT_MODE); |
| 8038 | val |= MSGINT_MODE_MULTIVEC_EN | MSGINT_MODE_ENABLE; |
| 8039 | tw32(MSGINT_MODE, val); |
| 8040 | } |
| 8041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8042 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 8043 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
| 8044 | udelay(40); |
| 8045 | } |
| 8046 | |
| 8047 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | |
| 8048 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | |
| 8049 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | |
| 8050 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | |
| 8051 | WDMAC_MODE_LNGREAD_ENAB); |
| 8052 | |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 8053 | /* If statement applies to 5705 and 5750 PCI devices only */ |
| 8054 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 8055 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) || |
| 8056 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) { |
Matt Carlson | 29ea095 | 2009-08-25 10:07:54 +0000 | [diff] [blame] | 8057 | if ((tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8058 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
| 8059 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { |
| 8060 | /* nothing */ |
| 8061 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
| 8062 | !(tp->tg3_flags2 & TG3_FLG2_IS_5788) && |
| 8063 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) { |
| 8064 | val |= WDMAC_MODE_RX_ACCEL; |
| 8065 | } |
| 8066 | } |
| 8067 | |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8068 | /* Enable host coalescing bug fix */ |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8069 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 8070 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 8071 | |
Matt Carlson | 788a035 | 2009-11-02 14:26:03 +0000 | [diff] [blame] | 8072 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 8073 | val |= WDMAC_MODE_BURST_ALL_DATA; |
| 8074 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8075 | tw32_f(WDMAC_MODE, val); |
| 8076 | udelay(40); |
| 8077 | |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8078 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
| 8079 | u16 pcix_cmd; |
| 8080 | |
| 8081 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8082 | &pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8083 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8084 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
| 8085 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8086 | } 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] | 8087 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
| 8088 | pcix_cmd |= PCI_X_CMD_READ_2K; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8089 | } |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 8090 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 8091 | pcix_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8092 | } |
| 8093 | |
| 8094 | tw32_f(RDMAC_MODE, rdmac_mode); |
| 8095 | udelay(40); |
| 8096 | |
| 8097 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
| 8098 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 8099 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 8100 | |
| 8101 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 8102 | tw32(SNDDATAC_MODE, |
| 8103 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); |
| 8104 | else |
| 8105 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); |
| 8106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8107 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
| 8108 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); |
| 8109 | tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ); |
| 8110 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8111 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
| 8112 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8113 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8114 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8115 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
| 8116 | tw32(SNDBDI_MODE, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8117 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
| 8118 | |
| 8119 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 8120 | err = tg3_load_5701_a0_firmware_fix(tp); |
| 8121 | if (err) |
| 8122 | return err; |
| 8123 | } |
| 8124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8125 | if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) { |
| 8126 | err = tg3_load_tso_firmware(tp); |
| 8127 | if (err) |
| 8128 | return err; |
| 8129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8130 | |
| 8131 | tp->tx_mode = TX_MODE_ENABLE; |
| 8132 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 8133 | udelay(100); |
| 8134 | |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8135 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) { |
| 8136 | u32 reg = MAC_RSS_INDIR_TBL_0; |
| 8137 | u8 *ent = (u8 *)&val; |
| 8138 | |
| 8139 | /* Setup the indirection table */ |
| 8140 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { |
| 8141 | int idx = i % sizeof(val); |
| 8142 | |
| 8143 | ent[idx] = i % (tp->irq_cnt - 1); |
| 8144 | if (idx == sizeof(val) - 1) { |
| 8145 | tw32(reg, val); |
| 8146 | reg += 4; |
| 8147 | } |
| 8148 | } |
| 8149 | |
| 8150 | /* Setup the "secret" hash key. */ |
| 8151 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); |
| 8152 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); |
| 8153 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); |
| 8154 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); |
| 8155 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); |
| 8156 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); |
| 8157 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); |
| 8158 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); |
| 8159 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); |
| 8160 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); |
| 8161 | } |
| 8162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8163 | tp->rx_mode = RX_MODE_ENABLE; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 8164 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 8165 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
| 8166 | |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8167 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) |
| 8168 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
| 8169 | RX_MODE_RSS_ITBL_HASH_BITS_7 | |
| 8170 | RX_MODE_RSS_IPV6_HASH_EN | |
| 8171 | RX_MODE_RSS_TCP_IPV6_HASH_EN | |
| 8172 | RX_MODE_RSS_IPV4_HASH_EN | |
| 8173 | RX_MODE_RSS_TCP_IPV4_HASH_EN; |
| 8174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8175 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8176 | udelay(10); |
| 8177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8178 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 8179 | |
| 8180 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 8181 | if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8182 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 8183 | udelay(10); |
| 8184 | } |
| 8185 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8186 | udelay(10); |
| 8187 | |
| 8188 | if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) { |
| 8189 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
| 8190 | !(tp->tg3_flags2 & TG3_FLG2_SERDES_PREEMPHASIS)) { |
| 8191 | /* Set drive transmission level to 1.2V */ |
| 8192 | /* only if the signal pre-emphasis bit is not set */ |
| 8193 | val = tr32(MAC_SERDES_CFG); |
| 8194 | val &= 0xfffff000; |
| 8195 | val |= 0x880; |
| 8196 | tw32(MAC_SERDES_CFG, val); |
| 8197 | } |
| 8198 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) |
| 8199 | tw32(MAC_SERDES_CFG, 0x616000); |
| 8200 | } |
| 8201 | |
| 8202 | /* Prevent chip from dropping frames when flow control |
| 8203 | * is enabled. |
| 8204 | */ |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 8205 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 8206 | val = 1; |
| 8207 | else |
| 8208 | val = 2; |
| 8209 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8210 | |
| 8211 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && |
| 8212 | (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) { |
| 8213 | /* Use hardware link auto-negotiation */ |
| 8214 | tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG; |
| 8215 | } |
| 8216 | |
Michael Chan | d4d2c55 | 2006-03-20 17:47:20 -0800 | [diff] [blame] | 8217 | if ((tp->tg3_flags2 & TG3_FLG2_MII_SERDES) && |
| 8218 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) { |
| 8219 | u32 tmp; |
| 8220 | |
| 8221 | tmp = tr32(SERDES_RX_CTRL); |
| 8222 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); |
| 8223 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; |
| 8224 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; |
| 8225 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 8226 | } |
| 8227 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8228 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)) { |
| 8229 | if (tp->link_config.phy_is_low_power) { |
| 8230 | tp->link_config.phy_is_low_power = 0; |
| 8231 | tp->link_config.speed = tp->link_config.orig_speed; |
| 8232 | tp->link_config.duplex = tp->link_config.orig_duplex; |
| 8233 | tp->link_config.autoneg = tp->link_config.orig_autoneg; |
| 8234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8235 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8236 | err = tg3_setup_phy(tp, 0); |
| 8237 | if (err) |
| 8238 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8239 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8240 | if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) && |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 8241 | !(tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET)) { |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 8242 | u32 tmp; |
| 8243 | |
| 8244 | /* Clear CRC stats. */ |
| 8245 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { |
| 8246 | tg3_writephy(tp, MII_TG3_TEST1, |
| 8247 | tmp | MII_TG3_TEST1_CRC_EN); |
| 8248 | tg3_readphy(tp, 0x14, &tmp); |
| 8249 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8250 | } |
| 8251 | } |
| 8252 | |
| 8253 | __tg3_set_rx_mode(tp->dev); |
| 8254 | |
| 8255 | /* Initialize receive rules. */ |
| 8256 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); |
| 8257 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 8258 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); |
| 8259 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 8260 | |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 8261 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 8262 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8263 | limit = 8; |
| 8264 | else |
| 8265 | limit = 16; |
| 8266 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) |
| 8267 | limit -= 4; |
| 8268 | switch (limit) { |
| 8269 | case 16: |
| 8270 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); |
| 8271 | case 15: |
| 8272 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); |
| 8273 | case 14: |
| 8274 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); |
| 8275 | case 13: |
| 8276 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); |
| 8277 | case 12: |
| 8278 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); |
| 8279 | case 11: |
| 8280 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); |
| 8281 | case 10: |
| 8282 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); |
| 8283 | case 9: |
| 8284 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); |
| 8285 | case 8: |
| 8286 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); |
| 8287 | case 7: |
| 8288 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); |
| 8289 | case 6: |
| 8290 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); |
| 8291 | case 5: |
| 8292 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); |
| 8293 | case 4: |
| 8294 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ |
| 8295 | case 3: |
| 8296 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ |
| 8297 | case 2: |
| 8298 | case 1: |
| 8299 | |
| 8300 | default: |
| 8301 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 8302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8303 | |
Matt Carlson | 9ce768e | 2007-10-11 19:49:11 -0700 | [diff] [blame] | 8304 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 8305 | /* Write our heartbeat update interval to APE. */ |
| 8306 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, |
| 8307 | APE_HOST_HEARTBEAT_INT_DISABLE); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 8308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8309 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
| 8310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8311 | return 0; |
| 8312 | } |
| 8313 | |
| 8314 | /* Called at device open time to get the chip ready for |
| 8315 | * packet processing. Invoked with tp->lock held. |
| 8316 | */ |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8317 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8318 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8319 | tg3_switch_clocks(tp); |
| 8320 | |
| 8321 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 8322 | |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 8323 | return tg3_reset_hw(tp, reset_phy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8324 | } |
| 8325 | |
| 8326 | #define TG3_STAT_ADD32(PSTAT, REG) \ |
| 8327 | do { u32 __val = tr32(REG); \ |
| 8328 | (PSTAT)->low += __val; \ |
| 8329 | if ((PSTAT)->low < __val) \ |
| 8330 | (PSTAT)->high += 1; \ |
| 8331 | } while (0) |
| 8332 | |
| 8333 | static void tg3_periodic_fetch_stats(struct tg3 *tp) |
| 8334 | { |
| 8335 | struct tg3_hw_stats *sp = tp->hw_stats; |
| 8336 | |
| 8337 | if (!netif_carrier_ok(tp->dev)) |
| 8338 | return; |
| 8339 | |
| 8340 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); |
| 8341 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); |
| 8342 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); |
| 8343 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); |
| 8344 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); |
| 8345 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); |
| 8346 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); |
| 8347 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); |
| 8348 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); |
| 8349 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); |
| 8350 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); |
| 8351 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); |
| 8352 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); |
| 8353 | |
| 8354 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); |
| 8355 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); |
| 8356 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); |
| 8357 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); |
| 8358 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); |
| 8359 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); |
| 8360 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); |
| 8361 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); |
| 8362 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); |
| 8363 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); |
| 8364 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); |
| 8365 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); |
| 8366 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); |
| 8367 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); |
Michael Chan | 463d305 | 2006-05-22 16:36:27 -0700 | [diff] [blame] | 8368 | |
| 8369 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); |
| 8370 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
| 8371 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8372 | } |
| 8373 | |
| 8374 | static void tg3_timer(unsigned long __opaque) |
| 8375 | { |
| 8376 | struct tg3 *tp = (struct tg3 *) __opaque; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8377 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 8378 | if (tp->irq_sync) |
| 8379 | goto restart_timer; |
| 8380 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8381 | spin_lock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8382 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8383 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) { |
| 8384 | /* All of this garbage is because when using non-tagged |
| 8385 | * IRQ status the mailbox/status_block protocol the chip |
| 8386 | * uses with the cpu is race prone. |
| 8387 | */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8388 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8389 | tw32(GRC_LOCAL_CTRL, |
| 8390 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 8391 | } else { |
| 8392 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 8393 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8394 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8395 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8396 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 8397 | tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8398 | spin_unlock(&tp->lock); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8399 | schedule_work(&tp->reset_task); |
| 8400 | return; |
| 8401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8402 | } |
| 8403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8404 | /* This part only runs once per second. */ |
| 8405 | if (!--tp->timer_counter) { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8406 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
| 8407 | tg3_periodic_fetch_stats(tp); |
| 8408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8409 | if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) { |
| 8410 | u32 mac_stat; |
| 8411 | int phy_event; |
| 8412 | |
| 8413 | mac_stat = tr32(MAC_STATUS); |
| 8414 | |
| 8415 | phy_event = 0; |
| 8416 | if (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) { |
| 8417 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
| 8418 | phy_event = 1; |
| 8419 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) |
| 8420 | phy_event = 1; |
| 8421 | |
| 8422 | if (phy_event) |
| 8423 | tg3_setup_phy(tp, 0); |
| 8424 | } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) { |
| 8425 | u32 mac_stat = tr32(MAC_STATUS); |
| 8426 | int need_setup = 0; |
| 8427 | |
| 8428 | if (netif_carrier_ok(tp->dev) && |
| 8429 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
| 8430 | need_setup = 1; |
| 8431 | } |
| 8432 | if (! netif_carrier_ok(tp->dev) && |
| 8433 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
| 8434 | MAC_STATUS_SIGNAL_DET))) { |
| 8435 | need_setup = 1; |
| 8436 | } |
| 8437 | if (need_setup) { |
Michael Chan | 3d3ebe7 | 2006-09-27 15:59:15 -0700 | [diff] [blame] | 8438 | if (!tp->serdes_counter) { |
| 8439 | tw32_f(MAC_MODE, |
| 8440 | (tp->mac_mode & |
| 8441 | ~MAC_MODE_PORT_MODE_MASK)); |
| 8442 | udelay(40); |
| 8443 | tw32_f(MAC_MODE, tp->mac_mode); |
| 8444 | udelay(40); |
| 8445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8446 | tg3_setup_phy(tp, 0); |
| 8447 | } |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 8448 | } else if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) |
| 8449 | tg3_serdes_parallel_detect(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8450 | |
| 8451 | tp->timer_counter = tp->timer_multiplier; |
| 8452 | } |
| 8453 | |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 8454 | /* Heartbeat is only sent once every 2 seconds. |
| 8455 | * |
| 8456 | * The heartbeat is to tell the ASF firmware that the host |
| 8457 | * driver is still alive. In the event that the OS crashes, |
| 8458 | * ASF needs to reset the hardware to free up the FIFO space |
| 8459 | * that may be filled with rx packets destined for the host. |
| 8460 | * If the FIFO is full, ASF will no longer function properly. |
| 8461 | * |
| 8462 | * Unintended resets have been reported on real time kernels |
| 8463 | * where the timer doesn't run on time. Netpoll will also have |
| 8464 | * same problem. |
| 8465 | * |
| 8466 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware |
| 8467 | * to check the ring condition when the heartbeat is expiring |
| 8468 | * before doing the reset. This will prevent most unintended |
| 8469 | * resets. |
| 8470 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8471 | if (!--tp->asf_counter) { |
Matt Carlson | bc7959b | 2008-08-15 14:08:55 -0700 | [diff] [blame] | 8472 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) && |
| 8473 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { |
Matt Carlson | 7c5026a | 2008-05-02 16:49:29 -0700 | [diff] [blame] | 8474 | tg3_wait_for_event_ack(tp); |
| 8475 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 8476 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
Michael Chan | 130b8e4 | 2006-09-27 16:00:40 -0700 | [diff] [blame] | 8477 | FWCMD_NICDRV_ALIVE3); |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 8478 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
Michael Chan | 28fbef7 | 2005-10-26 15:48:35 -0700 | [diff] [blame] | 8479 | /* 5 seconds timeout */ |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 8480 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5); |
Matt Carlson | 4ba526c | 2008-08-15 14:10:04 -0700 | [diff] [blame] | 8481 | |
| 8482 | tg3_generate_fw_event(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8483 | } |
| 8484 | tp->asf_counter = tp->asf_multiplier; |
| 8485 | } |
| 8486 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8487 | spin_unlock(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8488 | |
Michael Chan | f475f16 | 2006-03-27 23:20:14 -0800 | [diff] [blame] | 8489 | restart_timer: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8490 | tp->timer.expires = jiffies + tp->timer_offset; |
| 8491 | add_timer(&tp->timer); |
| 8492 | } |
| 8493 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8494 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8495 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 8496 | irq_handler_t fn; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8497 | unsigned long flags; |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8498 | char *name; |
| 8499 | struct tg3_napi *tnapi = &tp->napi[irq_num]; |
| 8500 | |
| 8501 | if (tp->irq_cnt == 1) |
| 8502 | name = tp->dev->name; |
| 8503 | else { |
| 8504 | name = &tnapi->irq_lbl[0]; |
| 8505 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); |
| 8506 | name[IFNAMSIZ-1] = 0; |
| 8507 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8508 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8509 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI_OR_MSIX) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8510 | fn = tg3_msi; |
| 8511 | if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) |
| 8512 | fn = tg3_msi_1shot; |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 8513 | flags = IRQF_SAMPLE_RANDOM; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8514 | } else { |
| 8515 | fn = tg3_interrupt; |
| 8516 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) |
| 8517 | fn = tg3_interrupt_tagged; |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 8518 | flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM; |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8519 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8520 | |
| 8521 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8522 | } |
| 8523 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8524 | static int tg3_test_interrupt(struct tg3 *tp) |
| 8525 | { |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8526 | struct tg3_napi *tnapi = &tp->napi[0]; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8527 | struct net_device *dev = tp->dev; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8528 | int err, i, intr_ok = 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8529 | u32 val; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8530 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 8531 | if (!netif_running(dev)) |
| 8532 | return -ENODEV; |
| 8533 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8534 | tg3_disable_ints(tp); |
| 8535 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8536 | free_irq(tnapi->irq_vec, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8537 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8538 | /* |
| 8539 | * Turn off MSI one shot mode. Otherwise this test has no |
| 8540 | * observable way to know whether the interrupt was delivered. |
| 8541 | */ |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8542 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 8543 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8544 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { |
| 8545 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
| 8546 | tw32(MSGINT_MODE, val); |
| 8547 | } |
| 8548 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8549 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8550 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, tnapi); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8551 | if (err) |
| 8552 | return err; |
| 8553 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8554 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8555 | tg3_enable_ints(tp); |
| 8556 | |
| 8557 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 8558 | tnapi->coal_now); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8559 | |
| 8560 | for (i = 0; i < 5; i++) { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8561 | u32 int_mbox, misc_host_ctrl; |
| 8562 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8563 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8564 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 8565 | |
| 8566 | if ((int_mbox != 0) || |
| 8567 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { |
| 8568 | intr_ok = 1; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8569 | break; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 8570 | } |
| 8571 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8572 | msleep(10); |
| 8573 | } |
| 8574 | |
| 8575 | tg3_disable_ints(tp); |
| 8576 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8577 | free_irq(tnapi->irq_vec, tnapi); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 8578 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8579 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8580 | |
| 8581 | if (err) |
| 8582 | return err; |
| 8583 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8584 | if (intr_ok) { |
| 8585 | /* Reenable MSI one shot mode. */ |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8586 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 8587 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8588 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { |
| 8589 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
| 8590 | tw32(MSGINT_MODE, val); |
| 8591 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8592 | return 0; |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8593 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8594 | |
| 8595 | return -EIO; |
| 8596 | } |
| 8597 | |
| 8598 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is |
| 8599 | * successfully restored |
| 8600 | */ |
| 8601 | static int tg3_test_msi(struct tg3 *tp) |
| 8602 | { |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8603 | int err; |
| 8604 | u16 pci_cmd; |
| 8605 | |
| 8606 | if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI)) |
| 8607 | return 0; |
| 8608 | |
| 8609 | /* Turn off SERR reporting in case MSI terminates with Master |
| 8610 | * Abort. |
| 8611 | */ |
| 8612 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 8613 | pci_write_config_word(tp->pdev, PCI_COMMAND, |
| 8614 | pci_cmd & ~PCI_COMMAND_SERR); |
| 8615 | |
| 8616 | err = tg3_test_interrupt(tp); |
| 8617 | |
| 8618 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 8619 | |
| 8620 | if (!err) |
| 8621 | return 0; |
| 8622 | |
| 8623 | /* other failures */ |
| 8624 | if (err != -EIO) |
| 8625 | return err; |
| 8626 | |
| 8627 | /* MSI test failed, go back to INTx mode */ |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 8628 | netdev_warn(tp->dev, "No interrupt was generated using MSI, switching to INTx mode\n" |
| 8629 | "Please report this failure to the PCI maintainer and include system chipset information\n"); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8630 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8631 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Matt Carlson | 09943a1 | 2009-08-28 14:01:57 +0000 | [diff] [blame] | 8632 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8633 | pci_disable_msi(tp->pdev); |
| 8634 | |
| 8635 | tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI; |
| 8636 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8637 | err = tg3_request_irq(tp, 0); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8638 | if (err) |
| 8639 | return err; |
| 8640 | |
| 8641 | /* Need to reset the chip because the MSI cycle may have terminated |
| 8642 | * with Master Abort. |
| 8643 | */ |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8644 | tg3_full_lock(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8645 | |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8646 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8647 | err = tg3_init_hw(tp, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8648 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8649 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8650 | |
| 8651 | if (err) |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8652 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8653 | |
| 8654 | return err; |
| 8655 | } |
| 8656 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8657 | static int tg3_request_firmware(struct tg3 *tp) |
| 8658 | { |
| 8659 | const __be32 *fw_data; |
| 8660 | |
| 8661 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 8662 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
| 8663 | tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8664 | return -ENOENT; |
| 8665 | } |
| 8666 | |
| 8667 | fw_data = (void *)tp->fw->data; |
| 8668 | |
| 8669 | /* Firmware blob starts with version numbers, followed by |
| 8670 | * start address and _full_ length including BSS sections |
| 8671 | * (which must be longer than the actual data, of course |
| 8672 | */ |
| 8673 | |
| 8674 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ |
| 8675 | if (tp->fw_len < (tp->fw->size - 12)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 8676 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
| 8677 | tp->fw_len, tp->fw_needed); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8678 | release_firmware(tp->fw); |
| 8679 | tp->fw = NULL; |
| 8680 | return -EINVAL; |
| 8681 | } |
| 8682 | |
| 8683 | /* We no longer need firmware; we have it. */ |
| 8684 | tp->fw_needed = NULL; |
| 8685 | return 0; |
| 8686 | } |
| 8687 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8688 | static bool tg3_enable_msix(struct tg3 *tp) |
| 8689 | { |
| 8690 | int i, rc, cpus = num_online_cpus(); |
| 8691 | struct msix_entry msix_ent[tp->irq_max]; |
| 8692 | |
| 8693 | if (cpus == 1) |
| 8694 | /* Just fallback to the simpler MSI mode. */ |
| 8695 | return false; |
| 8696 | |
| 8697 | /* |
| 8698 | * We want as many rx rings enabled as there are cpus. |
| 8699 | * The first MSIX vector only deals with link interrupts, etc, |
| 8700 | * so we add one to the number of vectors we are requesting. |
| 8701 | */ |
| 8702 | tp->irq_cnt = min_t(unsigned, cpus + 1, tp->irq_max); |
| 8703 | |
| 8704 | for (i = 0; i < tp->irq_max; i++) { |
| 8705 | msix_ent[i].entry = i; |
| 8706 | msix_ent[i].vector = 0; |
| 8707 | } |
| 8708 | |
| 8709 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); |
| 8710 | if (rc != 0) { |
| 8711 | if (rc < TG3_RSS_MIN_NUM_MSIX_VECS) |
| 8712 | return false; |
| 8713 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
| 8714 | return false; |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 8715 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
| 8716 | tp->irq_cnt, rc); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8717 | tp->irq_cnt = rc; |
| 8718 | } |
| 8719 | |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8720 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_RSS; |
| 8721 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8722 | for (i = 0; i < tp->irq_max; i++) |
| 8723 | tp->napi[i].irq_vec = msix_ent[i].vector; |
| 8724 | |
Matt Carlson | 19cfaec | 2009-12-03 08:36:20 +0000 | [diff] [blame] | 8725 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 8726 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_TSS; |
| 8727 | tp->dev->real_num_tx_queues = tp->irq_cnt - 1; |
| 8728 | } else |
| 8729 | tp->dev->real_num_tx_queues = 1; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 8730 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8731 | return true; |
| 8732 | } |
| 8733 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8734 | static void tg3_ints_init(struct tg3 *tp) |
| 8735 | { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8736 | if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSI_OR_MSIX) && |
| 8737 | !(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) { |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8738 | /* All MSI supporting chips should support tagged |
| 8739 | * status. Assert that this is the case. |
| 8740 | */ |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 8741 | netdev_warn(tp->dev, "MSI without TAGGED? Not using MSI\n"); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8742 | goto defcfg; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8743 | } |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8744 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8745 | if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX) && tg3_enable_msix(tp)) |
| 8746 | tp->tg3_flags2 |= TG3_FLG2_USING_MSIX; |
| 8747 | else if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) && |
| 8748 | pci_enable_msi(tp->pdev) == 0) |
| 8749 | tp->tg3_flags2 |= TG3_FLG2_USING_MSI; |
| 8750 | |
| 8751 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI_OR_MSIX) { |
| 8752 | u32 msi_mode = tr32(MSGINT_MODE); |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8753 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) |
| 8754 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8755 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
| 8756 | } |
| 8757 | defcfg: |
| 8758 | if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSIX)) { |
| 8759 | tp->irq_cnt = 1; |
| 8760 | tp->napi[0].irq_vec = tp->pdev->irq; |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 8761 | tp->dev->real_num_tx_queues = 1; |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8762 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8763 | } |
| 8764 | |
| 8765 | static void tg3_ints_fini(struct tg3 *tp) |
| 8766 | { |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8767 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) |
| 8768 | pci_disable_msix(tp->pdev); |
| 8769 | else if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) |
| 8770 | pci_disable_msi(tp->pdev); |
| 8771 | tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI_OR_MSIX; |
Matt Carlson | baf8a94 | 2009-09-01 13:13:00 +0000 | [diff] [blame] | 8772 | tp->tg3_flags3 &= ~TG3_FLG3_ENABLE_RSS; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8773 | } |
| 8774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8775 | static int tg3_open(struct net_device *dev) |
| 8776 | { |
| 8777 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8778 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8779 | |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8780 | if (tp->fw_needed) { |
| 8781 | err = tg3_request_firmware(tp); |
| 8782 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { |
| 8783 | if (err) |
| 8784 | return err; |
| 8785 | } else if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 8786 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8787 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE; |
| 8788 | } else if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 8789 | netdev_notice(tp->dev, "TSO capability restored\n"); |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 8790 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
| 8791 | } |
| 8792 | } |
| 8793 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 8794 | netif_carrier_off(tp->dev); |
| 8795 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 8796 | err = tg3_set_power_state(tp, PCI_D0); |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 8797 | if (err) |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 8798 | return err; |
Matt Carlson | 2f751b6 | 2008-08-04 23:17:34 -0700 | [diff] [blame] | 8799 | |
| 8800 | tg3_full_lock(tp, 0); |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 8801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8802 | tg3_disable_ints(tp); |
| 8803 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
| 8804 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8805 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8806 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8807 | /* |
| 8808 | * Setup interrupts first so we know how |
| 8809 | * many NAPI resources to allocate |
| 8810 | */ |
| 8811 | tg3_ints_init(tp); |
| 8812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8813 | /* The placement of this call is tied |
| 8814 | * to the setup and use of Host TX descriptors. |
| 8815 | */ |
| 8816 | err = tg3_alloc_consistent(tp); |
| 8817 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8818 | goto err_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8819 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 8820 | tg3_napi_enable(tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 8821 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8822 | for (i = 0; i < tp->irq_cnt; i++) { |
| 8823 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8824 | err = tg3_request_irq(tp, i); |
| 8825 | if (err) { |
| 8826 | for (i--; i >= 0; i--) |
| 8827 | free_irq(tnapi->irq_vec, tnapi); |
| 8828 | break; |
| 8829 | } |
| 8830 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8831 | |
| 8832 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8833 | goto err_out2; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8834 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8835 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8836 | |
Gary Zambrano | 8e7a22e | 2006-04-29 18:59:13 -0700 | [diff] [blame] | 8837 | err = tg3_init_hw(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8838 | if (err) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8839 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8840 | tg3_free_rings(tp); |
| 8841 | } else { |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8842 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) |
| 8843 | tp->timer_offset = HZ; |
| 8844 | else |
| 8845 | tp->timer_offset = HZ / 10; |
| 8846 | |
| 8847 | BUG_ON(tp->timer_offset > HZ); |
| 8848 | tp->timer_counter = tp->timer_multiplier = |
| 8849 | (HZ / tp->timer_offset); |
| 8850 | tp->asf_counter = tp->asf_multiplier = |
Michael Chan | 28fbef7 | 2005-10-26 15:48:35 -0700 | [diff] [blame] | 8851 | ((HZ / tp->timer_offset) * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8852 | |
| 8853 | init_timer(&tp->timer); |
| 8854 | tp->timer.expires = jiffies + tp->timer_offset; |
| 8855 | tp->timer.data = (unsigned long) tp; |
| 8856 | tp->timer.function = tg3_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8857 | } |
| 8858 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8859 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8860 | |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8861 | if (err) |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8862 | goto err_out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8863 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8864 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { |
| 8865 | err = tg3_test_msi(tp); |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 8866 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8867 | if (err) { |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8868 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 8869 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8870 | tg3_free_rings(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8871 | tg3_full_unlock(tp); |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8872 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8873 | goto err_out2; |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8874 | } |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8875 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8876 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 8877 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57765 && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8878 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI) && |
| 8879 | (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)) { |
| 8880 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8881 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 8882 | tw32(PCIE_TRANSACTION_CFG, |
| 8883 | val | PCIE_TRANS_CFG_1SHOT_MSI); |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 8884 | } |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8885 | } |
| 8886 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 8887 | tg3_phy_start(tp); |
| 8888 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8889 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8890 | |
Michael Chan | 7938109 | 2005-04-21 17:13:59 -0700 | [diff] [blame] | 8891 | add_timer(&tp->timer); |
| 8892 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8893 | tg3_enable_ints(tp); |
| 8894 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 8895 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8896 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 8897 | netif_tx_start_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8898 | |
| 8899 | return 0; |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8900 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8901 | err_out3: |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 8902 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 8903 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 8904 | free_irq(tnapi->irq_vec, tnapi); |
| 8905 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8906 | |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8907 | err_out2: |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 8908 | tg3_napi_disable(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8909 | tg3_free_consistent(tp); |
Matt Carlson | 679563f | 2009-09-01 12:55:46 +0000 | [diff] [blame] | 8910 | |
| 8911 | err_out1: |
| 8912 | tg3_ints_fini(tp); |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 8913 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8914 | } |
| 8915 | |
| 8916 | #if 0 |
| 8917 | /*static*/ void tg3_dump_state(struct tg3 *tp) |
| 8918 | { |
| 8919 | u32 val32, val32_2, val32_3, val32_4, val32_5; |
| 8920 | u16 val16; |
| 8921 | int i; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 8922 | struct tg3_hw_status *sblk = tp->napi[0]->hw_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8923 | |
| 8924 | pci_read_config_word(tp->pdev, PCI_STATUS, &val16); |
| 8925 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, &val32); |
| 8926 | printk("DEBUG: PCI status [%04x] TG3PCI state[%08x]\n", |
| 8927 | val16, val32); |
| 8928 | |
| 8929 | /* MAC block */ |
| 8930 | printk("DEBUG: MAC_MODE[%08x] MAC_STATUS[%08x]\n", |
| 8931 | tr32(MAC_MODE), tr32(MAC_STATUS)); |
| 8932 | printk(" MAC_EVENT[%08x] MAC_LED_CTRL[%08x]\n", |
| 8933 | tr32(MAC_EVENT), tr32(MAC_LED_CTRL)); |
| 8934 | printk("DEBUG: MAC_TX_MODE[%08x] MAC_TX_STATUS[%08x]\n", |
| 8935 | tr32(MAC_TX_MODE), tr32(MAC_TX_STATUS)); |
| 8936 | printk(" MAC_RX_MODE[%08x] MAC_RX_STATUS[%08x]\n", |
| 8937 | tr32(MAC_RX_MODE), tr32(MAC_RX_STATUS)); |
| 8938 | |
| 8939 | /* Send data initiator control block */ |
| 8940 | printk("DEBUG: SNDDATAI_MODE[%08x] SNDDATAI_STATUS[%08x]\n", |
| 8941 | tr32(SNDDATAI_MODE), tr32(SNDDATAI_STATUS)); |
| 8942 | printk(" SNDDATAI_STATSCTRL[%08x]\n", |
| 8943 | tr32(SNDDATAI_STATSCTRL)); |
| 8944 | |
| 8945 | /* Send data completion control block */ |
| 8946 | printk("DEBUG: SNDDATAC_MODE[%08x]\n", tr32(SNDDATAC_MODE)); |
| 8947 | |
| 8948 | /* Send BD ring selector block */ |
| 8949 | printk("DEBUG: SNDBDS_MODE[%08x] SNDBDS_STATUS[%08x]\n", |
| 8950 | tr32(SNDBDS_MODE), tr32(SNDBDS_STATUS)); |
| 8951 | |
| 8952 | /* Send BD initiator control block */ |
| 8953 | printk("DEBUG: SNDBDI_MODE[%08x] SNDBDI_STATUS[%08x]\n", |
| 8954 | tr32(SNDBDI_MODE), tr32(SNDBDI_STATUS)); |
| 8955 | |
| 8956 | /* Send BD completion control block */ |
| 8957 | printk("DEBUG: SNDBDC_MODE[%08x]\n", tr32(SNDBDC_MODE)); |
| 8958 | |
| 8959 | /* Receive list placement control block */ |
| 8960 | printk("DEBUG: RCVLPC_MODE[%08x] RCVLPC_STATUS[%08x]\n", |
| 8961 | tr32(RCVLPC_MODE), tr32(RCVLPC_STATUS)); |
| 8962 | printk(" RCVLPC_STATSCTRL[%08x]\n", |
| 8963 | tr32(RCVLPC_STATSCTRL)); |
| 8964 | |
| 8965 | /* Receive data and receive BD initiator control block */ |
| 8966 | printk("DEBUG: RCVDBDI_MODE[%08x] RCVDBDI_STATUS[%08x]\n", |
| 8967 | tr32(RCVDBDI_MODE), tr32(RCVDBDI_STATUS)); |
| 8968 | |
| 8969 | /* Receive data completion control block */ |
| 8970 | printk("DEBUG: RCVDCC_MODE[%08x]\n", |
| 8971 | tr32(RCVDCC_MODE)); |
| 8972 | |
| 8973 | /* Receive BD initiator control block */ |
| 8974 | printk("DEBUG: RCVBDI_MODE[%08x] RCVBDI_STATUS[%08x]\n", |
| 8975 | tr32(RCVBDI_MODE), tr32(RCVBDI_STATUS)); |
| 8976 | |
| 8977 | /* Receive BD completion control block */ |
| 8978 | printk("DEBUG: RCVCC_MODE[%08x] RCVCC_STATUS[%08x]\n", |
| 8979 | tr32(RCVCC_MODE), tr32(RCVCC_STATUS)); |
| 8980 | |
| 8981 | /* Receive list selector control block */ |
| 8982 | printk("DEBUG: RCVLSC_MODE[%08x] RCVLSC_STATUS[%08x]\n", |
| 8983 | tr32(RCVLSC_MODE), tr32(RCVLSC_STATUS)); |
| 8984 | |
| 8985 | /* Mbuf cluster free block */ |
| 8986 | printk("DEBUG: MBFREE_MODE[%08x] MBFREE_STATUS[%08x]\n", |
| 8987 | tr32(MBFREE_MODE), tr32(MBFREE_STATUS)); |
| 8988 | |
| 8989 | /* Host coalescing control block */ |
| 8990 | printk("DEBUG: HOSTCC_MODE[%08x] HOSTCC_STATUS[%08x]\n", |
| 8991 | tr32(HOSTCC_MODE), tr32(HOSTCC_STATUS)); |
| 8992 | printk("DEBUG: HOSTCC_STATS_BLK_HOST_ADDR[%08x%08x]\n", |
| 8993 | tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 8994 | tr32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW)); |
| 8995 | printk("DEBUG: HOSTCC_STATUS_BLK_HOST_ADDR[%08x%08x]\n", |
| 8996 | tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 8997 | tr32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW)); |
| 8998 | printk("DEBUG: HOSTCC_STATS_BLK_NIC_ADDR[%08x]\n", |
| 8999 | tr32(HOSTCC_STATS_BLK_NIC_ADDR)); |
| 9000 | printk("DEBUG: HOSTCC_STATUS_BLK_NIC_ADDR[%08x]\n", |
| 9001 | tr32(HOSTCC_STATUS_BLK_NIC_ADDR)); |
| 9002 | |
| 9003 | /* Memory arbiter control block */ |
| 9004 | printk("DEBUG: MEMARB_MODE[%08x] MEMARB_STATUS[%08x]\n", |
| 9005 | tr32(MEMARB_MODE), tr32(MEMARB_STATUS)); |
| 9006 | |
| 9007 | /* Buffer manager control block */ |
| 9008 | printk("DEBUG: BUFMGR_MODE[%08x] BUFMGR_STATUS[%08x]\n", |
| 9009 | tr32(BUFMGR_MODE), tr32(BUFMGR_STATUS)); |
| 9010 | printk("DEBUG: BUFMGR_MB_POOL_ADDR[%08x] BUFMGR_MB_POOL_SIZE[%08x]\n", |
| 9011 | tr32(BUFMGR_MB_POOL_ADDR), tr32(BUFMGR_MB_POOL_SIZE)); |
| 9012 | printk("DEBUG: BUFMGR_DMA_DESC_POOL_ADDR[%08x] " |
| 9013 | "BUFMGR_DMA_DESC_POOL_SIZE[%08x]\n", |
| 9014 | tr32(BUFMGR_DMA_DESC_POOL_ADDR), |
| 9015 | tr32(BUFMGR_DMA_DESC_POOL_SIZE)); |
| 9016 | |
| 9017 | /* Read DMA control block */ |
| 9018 | printk("DEBUG: RDMAC_MODE[%08x] RDMAC_STATUS[%08x]\n", |
| 9019 | tr32(RDMAC_MODE), tr32(RDMAC_STATUS)); |
| 9020 | |
| 9021 | /* Write DMA control block */ |
| 9022 | printk("DEBUG: WDMAC_MODE[%08x] WDMAC_STATUS[%08x]\n", |
| 9023 | tr32(WDMAC_MODE), tr32(WDMAC_STATUS)); |
| 9024 | |
| 9025 | /* DMA completion block */ |
| 9026 | printk("DEBUG: DMAC_MODE[%08x]\n", |
| 9027 | tr32(DMAC_MODE)); |
| 9028 | |
| 9029 | /* GRC block */ |
| 9030 | printk("DEBUG: GRC_MODE[%08x] GRC_MISC_CFG[%08x]\n", |
| 9031 | tr32(GRC_MODE), tr32(GRC_MISC_CFG)); |
| 9032 | printk("DEBUG: GRC_LOCAL_CTRL[%08x]\n", |
| 9033 | tr32(GRC_LOCAL_CTRL)); |
| 9034 | |
| 9035 | /* TG3_BDINFOs */ |
| 9036 | printk("DEBUG: RCVDBDI_JUMBO_BD[%08x%08x:%08x:%08x]\n", |
| 9037 | tr32(RCVDBDI_JUMBO_BD + 0x0), |
| 9038 | tr32(RCVDBDI_JUMBO_BD + 0x4), |
| 9039 | tr32(RCVDBDI_JUMBO_BD + 0x8), |
| 9040 | tr32(RCVDBDI_JUMBO_BD + 0xc)); |
| 9041 | printk("DEBUG: RCVDBDI_STD_BD[%08x%08x:%08x:%08x]\n", |
| 9042 | tr32(RCVDBDI_STD_BD + 0x0), |
| 9043 | tr32(RCVDBDI_STD_BD + 0x4), |
| 9044 | tr32(RCVDBDI_STD_BD + 0x8), |
| 9045 | tr32(RCVDBDI_STD_BD + 0xc)); |
| 9046 | printk("DEBUG: RCVDBDI_MINI_BD[%08x%08x:%08x:%08x]\n", |
| 9047 | tr32(RCVDBDI_MINI_BD + 0x0), |
| 9048 | tr32(RCVDBDI_MINI_BD + 0x4), |
| 9049 | tr32(RCVDBDI_MINI_BD + 0x8), |
| 9050 | tr32(RCVDBDI_MINI_BD + 0xc)); |
| 9051 | |
| 9052 | tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x0, &val32); |
| 9053 | tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x4, &val32_2); |
| 9054 | tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0x8, &val32_3); |
| 9055 | tg3_read_mem(tp, NIC_SRAM_SEND_RCB + 0xc, &val32_4); |
| 9056 | printk("DEBUG: SRAM_SEND_RCB_0[%08x%08x:%08x:%08x]\n", |
| 9057 | val32, val32_2, val32_3, val32_4); |
| 9058 | |
| 9059 | tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x0, &val32); |
| 9060 | tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x4, &val32_2); |
| 9061 | tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0x8, &val32_3); |
| 9062 | tg3_read_mem(tp, NIC_SRAM_RCV_RET_RCB + 0xc, &val32_4); |
| 9063 | printk("DEBUG: SRAM_RCV_RET_RCB_0[%08x%08x:%08x:%08x]\n", |
| 9064 | val32, val32_2, val32_3, val32_4); |
| 9065 | |
| 9066 | tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x0, &val32); |
| 9067 | tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x4, &val32_2); |
| 9068 | tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x8, &val32_3); |
| 9069 | tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0xc, &val32_4); |
| 9070 | tg3_read_mem(tp, NIC_SRAM_STATUS_BLK + 0x10, &val32_5); |
| 9071 | printk("DEBUG: SRAM_STATUS_BLK[%08x:%08x:%08x:%08x:%08x]\n", |
| 9072 | val32, val32_2, val32_3, val32_4, val32_5); |
| 9073 | |
| 9074 | /* SW status block */ |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 9075 | printk(KERN_DEBUG |
| 9076 | "Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", |
| 9077 | sblk->status, |
| 9078 | sblk->status_tag, |
| 9079 | sblk->rx_jumbo_consumer, |
| 9080 | sblk->rx_consumer, |
| 9081 | sblk->rx_mini_consumer, |
| 9082 | sblk->idx[0].rx_producer, |
| 9083 | sblk->idx[0].tx_consumer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9084 | |
| 9085 | /* SW statistics block */ |
| 9086 | printk("DEBUG: Host statistics block [%08x:%08x:%08x:%08x]\n", |
| 9087 | ((u32 *)tp->hw_stats)[0], |
| 9088 | ((u32 *)tp->hw_stats)[1], |
| 9089 | ((u32 *)tp->hw_stats)[2], |
| 9090 | ((u32 *)tp->hw_stats)[3]); |
| 9091 | |
| 9092 | /* Mailboxes */ |
| 9093 | printk("DEBUG: SNDHOST_PROD[%08x%08x] SNDNIC_PROD[%08x%08x]\n", |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 9094 | tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x0), |
| 9095 | tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + 0x4), |
| 9096 | tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x0), |
| 9097 | tr32_mailbox(MAILBOX_SNDNIC_PROD_IDX_0 + 0x4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9098 | |
| 9099 | /* NIC side send descriptors. */ |
| 9100 | for (i = 0; i < 6; i++) { |
| 9101 | unsigned long txd; |
| 9102 | |
| 9103 | txd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_TX_BUFFER_DESC |
| 9104 | + (i * sizeof(struct tg3_tx_buffer_desc)); |
| 9105 | printk("DEBUG: NIC TXD(%d)[%08x:%08x:%08x:%08x]\n", |
| 9106 | i, |
| 9107 | readl(txd + 0x0), readl(txd + 0x4), |
| 9108 | readl(txd + 0x8), readl(txd + 0xc)); |
| 9109 | } |
| 9110 | |
| 9111 | /* NIC side RX descriptors. */ |
| 9112 | for (i = 0; i < 6; i++) { |
| 9113 | unsigned long rxd; |
| 9114 | |
| 9115 | rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_BUFFER_DESC |
| 9116 | + (i * sizeof(struct tg3_rx_buffer_desc)); |
| 9117 | printk("DEBUG: NIC RXD_STD(%d)[0][%08x:%08x:%08x:%08x]\n", |
| 9118 | i, |
| 9119 | readl(rxd + 0x0), readl(rxd + 0x4), |
| 9120 | readl(rxd + 0x8), readl(rxd + 0xc)); |
| 9121 | rxd += (4 * sizeof(u32)); |
| 9122 | printk("DEBUG: NIC RXD_STD(%d)[1][%08x:%08x:%08x:%08x]\n", |
| 9123 | i, |
| 9124 | readl(rxd + 0x0), readl(rxd + 0x4), |
| 9125 | readl(rxd + 0x8), readl(rxd + 0xc)); |
| 9126 | } |
| 9127 | |
| 9128 | for (i = 0; i < 6; i++) { |
| 9129 | unsigned long rxd; |
| 9130 | |
| 9131 | rxd = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_RX_JUMBO_BUFFER_DESC |
| 9132 | + (i * sizeof(struct tg3_rx_buffer_desc)); |
| 9133 | printk("DEBUG: NIC RXD_JUMBO(%d)[0][%08x:%08x:%08x:%08x]\n", |
| 9134 | i, |
| 9135 | readl(rxd + 0x0), readl(rxd + 0x4), |
| 9136 | readl(rxd + 0x8), readl(rxd + 0xc)); |
| 9137 | rxd += (4 * sizeof(u32)); |
| 9138 | printk("DEBUG: NIC RXD_JUMBO(%d)[1][%08x:%08x:%08x:%08x]\n", |
| 9139 | i, |
| 9140 | readl(rxd + 0x0), readl(rxd + 0x4), |
| 9141 | readl(rxd + 0x8), readl(rxd + 0xc)); |
| 9142 | } |
| 9143 | } |
| 9144 | #endif |
| 9145 | |
| 9146 | static struct net_device_stats *tg3_get_stats(struct net_device *); |
| 9147 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *); |
| 9148 | |
| 9149 | static int tg3_close(struct net_device *dev) |
| 9150 | { |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9151 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9152 | struct tg3 *tp = netdev_priv(dev); |
| 9153 | |
Matt Carlson | fed9781 | 2009-09-01 13:10:19 +0000 | [diff] [blame] | 9154 | tg3_napi_disable(tp); |
Oleg Nesterov | 28e53bd | 2007-05-09 02:34:22 -0700 | [diff] [blame] | 9155 | cancel_work_sync(&tp->reset_task); |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 9156 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 9157 | netif_tx_stop_all_queues(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9158 | |
| 9159 | del_timer_sync(&tp->timer); |
| 9160 | |
Matt Carlson | 24bb4fb | 2009-10-05 17:55:29 +0000 | [diff] [blame] | 9161 | tg3_phy_stop(tp); |
| 9162 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9163 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9164 | #if 0 |
| 9165 | tg3_dump_state(tp); |
| 9166 | #endif |
| 9167 | |
| 9168 | tg3_disable_ints(tp); |
| 9169 | |
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); |
Michael Chan | 5cf64b8a | 2007-05-05 12:11:21 -0700 | [diff] [blame] | 9172 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9173 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9174 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9175 | |
Matt Carlson | 4f125f4 | 2009-09-01 12:55:02 +0000 | [diff] [blame] | 9176 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 9177 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 9178 | free_irq(tnapi->irq_vec, tnapi); |
| 9179 | } |
Matt Carlson | 07b0173 | 2009-08-28 14:01:15 +0000 | [diff] [blame] | 9180 | |
| 9181 | tg3_ints_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9182 | |
| 9183 | memcpy(&tp->net_stats_prev, tg3_get_stats(tp->dev), |
| 9184 | sizeof(tp->net_stats_prev)); |
| 9185 | memcpy(&tp->estats_prev, tg3_get_estats(tp), |
| 9186 | sizeof(tp->estats_prev)); |
| 9187 | |
| 9188 | tg3_free_consistent(tp); |
| 9189 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9190 | tg3_set_power_state(tp, PCI_D3hot); |
| 9191 | |
| 9192 | netif_carrier_off(tp->dev); |
| 9193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9194 | return 0; |
| 9195 | } |
| 9196 | |
| 9197 | static inline unsigned long get_stat64(tg3_stat64_t *val) |
| 9198 | { |
| 9199 | unsigned long ret; |
| 9200 | |
| 9201 | #if (BITS_PER_LONG == 32) |
| 9202 | ret = val->low; |
| 9203 | #else |
| 9204 | ret = ((u64)val->high << 32) | ((u64)val->low); |
| 9205 | #endif |
| 9206 | return ret; |
| 9207 | } |
| 9208 | |
Stefan Buehler | 816f8b8 | 2008-08-15 14:10:54 -0700 | [diff] [blame] | 9209 | static inline u64 get_estat64(tg3_stat64_t *val) |
| 9210 | { |
| 9211 | return ((u64)val->high << 32) | ((u64)val->low); |
| 9212 | } |
| 9213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9214 | static unsigned long calc_crc_errors(struct tg3 *tp) |
| 9215 | { |
| 9216 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9217 | |
| 9218 | if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) && |
| 9219 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 9220 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9221 | u32 val; |
| 9222 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9223 | spin_lock_bh(&tp->lock); |
Michael Chan | 569a5df | 2007-02-13 12:18:15 -0800 | [diff] [blame] | 9224 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
| 9225 | tg3_writephy(tp, MII_TG3_TEST1, |
| 9226 | val | MII_TG3_TEST1_CRC_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9227 | tg3_readphy(tp, 0x14, &val); |
| 9228 | } else |
| 9229 | val = 0; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9230 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9231 | |
| 9232 | tp->phy_crc_errors += val; |
| 9233 | |
| 9234 | return tp->phy_crc_errors; |
| 9235 | } |
| 9236 | |
| 9237 | return get_stat64(&hw_stats->rx_fcs_errors); |
| 9238 | } |
| 9239 | |
| 9240 | #define ESTAT_ADD(member) \ |
| 9241 | estats->member = old_estats->member + \ |
Stefan Buehler | 816f8b8 | 2008-08-15 14:10:54 -0700 | [diff] [blame] | 9242 | get_estat64(&hw_stats->member) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9243 | |
| 9244 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp) |
| 9245 | { |
| 9246 | struct tg3_ethtool_stats *estats = &tp->estats; |
| 9247 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
| 9248 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9249 | |
| 9250 | if (!hw_stats) |
| 9251 | return old_estats; |
| 9252 | |
| 9253 | ESTAT_ADD(rx_octets); |
| 9254 | ESTAT_ADD(rx_fragments); |
| 9255 | ESTAT_ADD(rx_ucast_packets); |
| 9256 | ESTAT_ADD(rx_mcast_packets); |
| 9257 | ESTAT_ADD(rx_bcast_packets); |
| 9258 | ESTAT_ADD(rx_fcs_errors); |
| 9259 | ESTAT_ADD(rx_align_errors); |
| 9260 | ESTAT_ADD(rx_xon_pause_rcvd); |
| 9261 | ESTAT_ADD(rx_xoff_pause_rcvd); |
| 9262 | ESTAT_ADD(rx_mac_ctrl_rcvd); |
| 9263 | ESTAT_ADD(rx_xoff_entered); |
| 9264 | ESTAT_ADD(rx_frame_too_long_errors); |
| 9265 | ESTAT_ADD(rx_jabbers); |
| 9266 | ESTAT_ADD(rx_undersize_packets); |
| 9267 | ESTAT_ADD(rx_in_length_errors); |
| 9268 | ESTAT_ADD(rx_out_length_errors); |
| 9269 | ESTAT_ADD(rx_64_or_less_octet_packets); |
| 9270 | ESTAT_ADD(rx_65_to_127_octet_packets); |
| 9271 | ESTAT_ADD(rx_128_to_255_octet_packets); |
| 9272 | ESTAT_ADD(rx_256_to_511_octet_packets); |
| 9273 | ESTAT_ADD(rx_512_to_1023_octet_packets); |
| 9274 | ESTAT_ADD(rx_1024_to_1522_octet_packets); |
| 9275 | ESTAT_ADD(rx_1523_to_2047_octet_packets); |
| 9276 | ESTAT_ADD(rx_2048_to_4095_octet_packets); |
| 9277 | ESTAT_ADD(rx_4096_to_8191_octet_packets); |
| 9278 | ESTAT_ADD(rx_8192_to_9022_octet_packets); |
| 9279 | |
| 9280 | ESTAT_ADD(tx_octets); |
| 9281 | ESTAT_ADD(tx_collisions); |
| 9282 | ESTAT_ADD(tx_xon_sent); |
| 9283 | ESTAT_ADD(tx_xoff_sent); |
| 9284 | ESTAT_ADD(tx_flow_control); |
| 9285 | ESTAT_ADD(tx_mac_errors); |
| 9286 | ESTAT_ADD(tx_single_collisions); |
| 9287 | ESTAT_ADD(tx_mult_collisions); |
| 9288 | ESTAT_ADD(tx_deferred); |
| 9289 | ESTAT_ADD(tx_excessive_collisions); |
| 9290 | ESTAT_ADD(tx_late_collisions); |
| 9291 | ESTAT_ADD(tx_collide_2times); |
| 9292 | ESTAT_ADD(tx_collide_3times); |
| 9293 | ESTAT_ADD(tx_collide_4times); |
| 9294 | ESTAT_ADD(tx_collide_5times); |
| 9295 | ESTAT_ADD(tx_collide_6times); |
| 9296 | ESTAT_ADD(tx_collide_7times); |
| 9297 | ESTAT_ADD(tx_collide_8times); |
| 9298 | ESTAT_ADD(tx_collide_9times); |
| 9299 | ESTAT_ADD(tx_collide_10times); |
| 9300 | ESTAT_ADD(tx_collide_11times); |
| 9301 | ESTAT_ADD(tx_collide_12times); |
| 9302 | ESTAT_ADD(tx_collide_13times); |
| 9303 | ESTAT_ADD(tx_collide_14times); |
| 9304 | ESTAT_ADD(tx_collide_15times); |
| 9305 | ESTAT_ADD(tx_ucast_packets); |
| 9306 | ESTAT_ADD(tx_mcast_packets); |
| 9307 | ESTAT_ADD(tx_bcast_packets); |
| 9308 | ESTAT_ADD(tx_carrier_sense_errors); |
| 9309 | ESTAT_ADD(tx_discards); |
| 9310 | ESTAT_ADD(tx_errors); |
| 9311 | |
| 9312 | ESTAT_ADD(dma_writeq_full); |
| 9313 | ESTAT_ADD(dma_write_prioq_full); |
| 9314 | ESTAT_ADD(rxbds_empty); |
| 9315 | ESTAT_ADD(rx_discards); |
| 9316 | ESTAT_ADD(rx_errors); |
| 9317 | ESTAT_ADD(rx_threshold_hit); |
| 9318 | |
| 9319 | ESTAT_ADD(dma_readq_full); |
| 9320 | ESTAT_ADD(dma_read_prioq_full); |
| 9321 | ESTAT_ADD(tx_comp_queue_full); |
| 9322 | |
| 9323 | ESTAT_ADD(ring_set_send_prod_index); |
| 9324 | ESTAT_ADD(ring_status_update); |
| 9325 | ESTAT_ADD(nic_irqs); |
| 9326 | ESTAT_ADD(nic_avoided_irqs); |
| 9327 | ESTAT_ADD(nic_tx_threshold_hit); |
| 9328 | |
| 9329 | return estats; |
| 9330 | } |
| 9331 | |
| 9332 | static struct net_device_stats *tg3_get_stats(struct net_device *dev) |
| 9333 | { |
| 9334 | struct tg3 *tp = netdev_priv(dev); |
| 9335 | struct net_device_stats *stats = &tp->net_stats; |
| 9336 | struct net_device_stats *old_stats = &tp->net_stats_prev; |
| 9337 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 9338 | |
| 9339 | if (!hw_stats) |
| 9340 | return old_stats; |
| 9341 | |
| 9342 | stats->rx_packets = old_stats->rx_packets + |
| 9343 | get_stat64(&hw_stats->rx_ucast_packets) + |
| 9344 | get_stat64(&hw_stats->rx_mcast_packets) + |
| 9345 | get_stat64(&hw_stats->rx_bcast_packets); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9347 | stats->tx_packets = old_stats->tx_packets + |
| 9348 | get_stat64(&hw_stats->tx_ucast_packets) + |
| 9349 | get_stat64(&hw_stats->tx_mcast_packets) + |
| 9350 | get_stat64(&hw_stats->tx_bcast_packets); |
| 9351 | |
| 9352 | stats->rx_bytes = old_stats->rx_bytes + |
| 9353 | get_stat64(&hw_stats->rx_octets); |
| 9354 | stats->tx_bytes = old_stats->tx_bytes + |
| 9355 | get_stat64(&hw_stats->tx_octets); |
| 9356 | |
| 9357 | stats->rx_errors = old_stats->rx_errors + |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 9358 | get_stat64(&hw_stats->rx_errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9359 | stats->tx_errors = old_stats->tx_errors + |
| 9360 | get_stat64(&hw_stats->tx_errors) + |
| 9361 | get_stat64(&hw_stats->tx_mac_errors) + |
| 9362 | get_stat64(&hw_stats->tx_carrier_sense_errors) + |
| 9363 | get_stat64(&hw_stats->tx_discards); |
| 9364 | |
| 9365 | stats->multicast = old_stats->multicast + |
| 9366 | get_stat64(&hw_stats->rx_mcast_packets); |
| 9367 | stats->collisions = old_stats->collisions + |
| 9368 | get_stat64(&hw_stats->tx_collisions); |
| 9369 | |
| 9370 | stats->rx_length_errors = old_stats->rx_length_errors + |
| 9371 | get_stat64(&hw_stats->rx_frame_too_long_errors) + |
| 9372 | get_stat64(&hw_stats->rx_undersize_packets); |
| 9373 | |
| 9374 | stats->rx_over_errors = old_stats->rx_over_errors + |
| 9375 | get_stat64(&hw_stats->rxbds_empty); |
| 9376 | stats->rx_frame_errors = old_stats->rx_frame_errors + |
| 9377 | get_stat64(&hw_stats->rx_align_errors); |
| 9378 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + |
| 9379 | get_stat64(&hw_stats->tx_discards); |
| 9380 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + |
| 9381 | get_stat64(&hw_stats->tx_carrier_sense_errors); |
| 9382 | |
| 9383 | stats->rx_crc_errors = old_stats->rx_crc_errors + |
| 9384 | calc_crc_errors(tp); |
| 9385 | |
John W. Linville | 4f63b87 | 2005-09-12 14:43:18 -0700 | [diff] [blame] | 9386 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
| 9387 | get_stat64(&hw_stats->rx_discards); |
| 9388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9389 | return stats; |
| 9390 | } |
| 9391 | |
| 9392 | static inline u32 calc_crc(unsigned char *buf, int len) |
| 9393 | { |
| 9394 | u32 reg; |
| 9395 | u32 tmp; |
| 9396 | int j, k; |
| 9397 | |
| 9398 | reg = 0xffffffff; |
| 9399 | |
| 9400 | for (j = 0; j < len; j++) { |
| 9401 | reg ^= buf[j]; |
| 9402 | |
| 9403 | for (k = 0; k < 8; k++) { |
| 9404 | tmp = reg & 0x01; |
| 9405 | |
| 9406 | reg >>= 1; |
| 9407 | |
| 9408 | if (tmp) { |
| 9409 | reg ^= 0xedb88320; |
| 9410 | } |
| 9411 | } |
| 9412 | } |
| 9413 | |
| 9414 | return ~reg; |
| 9415 | } |
| 9416 | |
| 9417 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) |
| 9418 | { |
| 9419 | /* accept or reject all multicast frames */ |
| 9420 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); |
| 9421 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); |
| 9422 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); |
| 9423 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); |
| 9424 | } |
| 9425 | |
| 9426 | static void __tg3_set_rx_mode(struct net_device *dev) |
| 9427 | { |
| 9428 | struct tg3 *tp = netdev_priv(dev); |
| 9429 | u32 rx_mode; |
| 9430 | |
| 9431 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
| 9432 | RX_MODE_KEEP_VLAN_TAG); |
| 9433 | |
| 9434 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
| 9435 | * flag clear. |
| 9436 | */ |
| 9437 | #if TG3_VLAN_TAG_USED |
| 9438 | if (!tp->vlgrp && |
| 9439 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 9440 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 9441 | #else |
| 9442 | /* By definition, VLAN is disabled always in this |
| 9443 | * case. |
| 9444 | */ |
| 9445 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 9446 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 9447 | #endif |
| 9448 | |
| 9449 | if (dev->flags & IFF_PROMISC) { |
| 9450 | /* Promiscuous mode. */ |
| 9451 | rx_mode |= RX_MODE_PROMISC; |
| 9452 | } else if (dev->flags & IFF_ALLMULTI) { |
| 9453 | /* Accept all multicast. */ |
| 9454 | tg3_set_multi (tp, 1); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 9455 | } else if (netdev_mc_empty(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9456 | /* Reject all multicast. */ |
| 9457 | tg3_set_multi (tp, 0); |
| 9458 | } else { |
| 9459 | /* Accept one or more multicast(s). */ |
| 9460 | struct dev_mc_list *mclist; |
| 9461 | unsigned int i; |
| 9462 | u32 mc_filter[4] = { 0, }; |
| 9463 | u32 regidx; |
| 9464 | u32 bit; |
| 9465 | u32 crc; |
| 9466 | |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 9467 | for (i = 0, mclist = dev->mc_list; mclist && i < netdev_mc_count(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9468 | i++, mclist = mclist->next) { |
| 9469 | |
| 9470 | crc = calc_crc (mclist->dmi_addr, ETH_ALEN); |
| 9471 | bit = ~crc & 0x7f; |
| 9472 | regidx = (bit & 0x60) >> 5; |
| 9473 | bit &= 0x1f; |
| 9474 | mc_filter[regidx] |= (1 << bit); |
| 9475 | } |
| 9476 | |
| 9477 | tw32(MAC_HASH_REG_0, mc_filter[0]); |
| 9478 | tw32(MAC_HASH_REG_1, mc_filter[1]); |
| 9479 | tw32(MAC_HASH_REG_2, mc_filter[2]); |
| 9480 | tw32(MAC_HASH_REG_3, mc_filter[3]); |
| 9481 | } |
| 9482 | |
| 9483 | if (rx_mode != tp->rx_mode) { |
| 9484 | tp->rx_mode = rx_mode; |
| 9485 | tw32_f(MAC_RX_MODE, rx_mode); |
| 9486 | udelay(10); |
| 9487 | } |
| 9488 | } |
| 9489 | |
| 9490 | static void tg3_set_rx_mode(struct net_device *dev) |
| 9491 | { |
| 9492 | struct tg3 *tp = netdev_priv(dev); |
| 9493 | |
Michael Chan | e75f7c9 | 2006-03-20 21:33:26 -0800 | [diff] [blame] | 9494 | if (!netif_running(dev)) |
| 9495 | return; |
| 9496 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9497 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9498 | __tg3_set_rx_mode(dev); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9499 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9500 | } |
| 9501 | |
| 9502 | #define TG3_REGDUMP_LEN (32 * 1024) |
| 9503 | |
| 9504 | static int tg3_get_regs_len(struct net_device *dev) |
| 9505 | { |
| 9506 | return TG3_REGDUMP_LEN; |
| 9507 | } |
| 9508 | |
| 9509 | static void tg3_get_regs(struct net_device *dev, |
| 9510 | struct ethtool_regs *regs, void *_p) |
| 9511 | { |
| 9512 | u32 *p = _p; |
| 9513 | struct tg3 *tp = netdev_priv(dev); |
| 9514 | u8 *orig_p = _p; |
| 9515 | int i; |
| 9516 | |
| 9517 | regs->version = 0; |
| 9518 | |
| 9519 | memset(p, 0, TG3_REGDUMP_LEN); |
| 9520 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9521 | if (tp->link_config.phy_is_low_power) |
| 9522 | return; |
| 9523 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9524 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9525 | |
| 9526 | #define __GET_REG32(reg) (*(p)++ = tr32(reg)) |
| 9527 | #define GET_REG32_LOOP(base,len) \ |
| 9528 | do { p = (u32 *)(orig_p + (base)); \ |
| 9529 | for (i = 0; i < len; i += 4) \ |
| 9530 | __GET_REG32((base) + i); \ |
| 9531 | } while (0) |
| 9532 | #define GET_REG32_1(reg) \ |
| 9533 | do { p = (u32 *)(orig_p + (reg)); \ |
| 9534 | __GET_REG32((reg)); \ |
| 9535 | } while (0) |
| 9536 | |
| 9537 | GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0); |
| 9538 | GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200); |
| 9539 | GET_REG32_LOOP(MAC_MODE, 0x4f0); |
| 9540 | GET_REG32_LOOP(SNDDATAI_MODE, 0xe0); |
| 9541 | GET_REG32_1(SNDDATAC_MODE); |
| 9542 | GET_REG32_LOOP(SNDBDS_MODE, 0x80); |
| 9543 | GET_REG32_LOOP(SNDBDI_MODE, 0x48); |
| 9544 | GET_REG32_1(SNDBDC_MODE); |
| 9545 | GET_REG32_LOOP(RCVLPC_MODE, 0x20); |
| 9546 | GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c); |
| 9547 | GET_REG32_LOOP(RCVDBDI_MODE, 0x0c); |
| 9548 | GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c); |
| 9549 | GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44); |
| 9550 | GET_REG32_1(RCVDCC_MODE); |
| 9551 | GET_REG32_LOOP(RCVBDI_MODE, 0x20); |
| 9552 | GET_REG32_LOOP(RCVCC_MODE, 0x14); |
| 9553 | GET_REG32_LOOP(RCVLSC_MODE, 0x08); |
| 9554 | GET_REG32_1(MBFREE_MODE); |
| 9555 | GET_REG32_LOOP(HOSTCC_MODE, 0x100); |
| 9556 | GET_REG32_LOOP(MEMARB_MODE, 0x10); |
| 9557 | GET_REG32_LOOP(BUFMGR_MODE, 0x58); |
| 9558 | GET_REG32_LOOP(RDMAC_MODE, 0x08); |
| 9559 | GET_REG32_LOOP(WDMAC_MODE, 0x08); |
Chris Elmquist | 091465d | 2005-12-20 13:25:19 -0800 | [diff] [blame] | 9560 | GET_REG32_1(RX_CPU_MODE); |
| 9561 | GET_REG32_1(RX_CPU_STATE); |
| 9562 | GET_REG32_1(RX_CPU_PGMCTR); |
| 9563 | GET_REG32_1(RX_CPU_HWBKPT); |
| 9564 | GET_REG32_1(TX_CPU_MODE); |
| 9565 | GET_REG32_1(TX_CPU_STATE); |
| 9566 | GET_REG32_1(TX_CPU_PGMCTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9567 | GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110); |
| 9568 | GET_REG32_LOOP(FTQ_RESET, 0x120); |
| 9569 | GET_REG32_LOOP(MSGINT_MODE, 0x0c); |
| 9570 | GET_REG32_1(DMAC_MODE); |
| 9571 | GET_REG32_LOOP(GRC_MODE, 0x4c); |
| 9572 | if (tp->tg3_flags & TG3_FLAG_NVRAM) |
| 9573 | GET_REG32_LOOP(NVRAM_CMD, 0x24); |
| 9574 | |
| 9575 | #undef __GET_REG32 |
| 9576 | #undef GET_REG32_LOOP |
| 9577 | #undef GET_REG32_1 |
| 9578 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9579 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9580 | } |
| 9581 | |
| 9582 | static int tg3_get_eeprom_len(struct net_device *dev) |
| 9583 | { |
| 9584 | struct tg3 *tp = netdev_priv(dev); |
| 9585 | |
| 9586 | return tp->nvram_size; |
| 9587 | } |
| 9588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9589 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 9590 | { |
| 9591 | struct tg3 *tp = netdev_priv(dev); |
| 9592 | int ret; |
| 9593 | u8 *pd; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9594 | u32 i, offset, len, b_offset, b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9595 | __be32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9596 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 9597 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) |
| 9598 | return -EINVAL; |
| 9599 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9600 | if (tp->link_config.phy_is_low_power) |
| 9601 | return -EAGAIN; |
| 9602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9603 | offset = eeprom->offset; |
| 9604 | len = eeprom->len; |
| 9605 | eeprom->len = 0; |
| 9606 | |
| 9607 | eeprom->magic = TG3_EEPROM_MAGIC; |
| 9608 | |
| 9609 | if (offset & 3) { |
| 9610 | /* adjustments to start on required 4 byte boundary */ |
| 9611 | b_offset = offset & 3; |
| 9612 | b_count = 4 - b_offset; |
| 9613 | if (b_count > len) { |
| 9614 | /* i.e. offset=1 len=2 */ |
| 9615 | b_count = len; |
| 9616 | } |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9617 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9618 | if (ret) |
| 9619 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9620 | memcpy(data, ((char*)&val) + b_offset, b_count); |
| 9621 | len -= b_count; |
| 9622 | offset += b_count; |
| 9623 | eeprom->len += b_count; |
| 9624 | } |
| 9625 | |
| 9626 | /* read bytes upto the last 4 byte boundary */ |
| 9627 | pd = &data[eeprom->len]; |
| 9628 | for (i = 0; i < (len - (len & 3)); i += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9629 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9630 | if (ret) { |
| 9631 | eeprom->len += i; |
| 9632 | return ret; |
| 9633 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9634 | memcpy(pd + i, &val, 4); |
| 9635 | } |
| 9636 | eeprom->len += i; |
| 9637 | |
| 9638 | if (len & 3) { |
| 9639 | /* read last bytes not ending on 4 byte boundary */ |
| 9640 | pd = &data[eeprom->len]; |
| 9641 | b_count = len & 3; |
| 9642 | b_offset = offset + len - b_count; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9643 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9644 | if (ret) |
| 9645 | return ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9646 | memcpy(pd, &val, b_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9647 | eeprom->len += b_count; |
| 9648 | } |
| 9649 | return 0; |
| 9650 | } |
| 9651 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9652 | 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] | 9653 | |
| 9654 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 9655 | { |
| 9656 | struct tg3 *tp = netdev_priv(dev); |
| 9657 | int ret; |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 9658 | u32 offset, len, b_offset, odd_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9659 | u8 *buf; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9660 | __be32 start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9661 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 9662 | if (tp->link_config.phy_is_low_power) |
| 9663 | return -EAGAIN; |
| 9664 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 9665 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
| 9666 | eeprom->magic != TG3_EEPROM_MAGIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9667 | return -EINVAL; |
| 9668 | |
| 9669 | offset = eeprom->offset; |
| 9670 | len = eeprom->len; |
| 9671 | |
| 9672 | if ((b_offset = (offset & 3))) { |
| 9673 | /* adjustments to start on required 4 byte boundary */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9674 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9675 | if (ret) |
| 9676 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9677 | len += b_offset; |
| 9678 | offset &= ~3; |
Michael Chan | 1c8594b | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 9679 | if (len < 4) |
| 9680 | len = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9681 | } |
| 9682 | |
| 9683 | odd_len = 0; |
Michael Chan | 1c8594b | 2005-04-21 17:12:46 -0700 | [diff] [blame] | 9684 | if (len & 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9685 | /* adjustments to end on required 4 byte boundary */ |
| 9686 | odd_len = 1; |
| 9687 | len = (len + 3) & ~3; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 9688 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9689 | if (ret) |
| 9690 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9691 | } |
| 9692 | |
| 9693 | buf = data; |
| 9694 | if (b_offset || odd_len) { |
| 9695 | buf = kmalloc(len, GFP_KERNEL); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 9696 | if (!buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9697 | return -ENOMEM; |
| 9698 | if (b_offset) |
| 9699 | memcpy(buf, &start, 4); |
| 9700 | if (odd_len) |
| 9701 | memcpy(buf+len-4, &end, 4); |
| 9702 | memcpy(buf + b_offset, data, eeprom->len); |
| 9703 | } |
| 9704 | |
| 9705 | ret = tg3_nvram_write_block(tp, offset, len, buf); |
| 9706 | |
| 9707 | if (buf != data) |
| 9708 | kfree(buf); |
| 9709 | |
| 9710 | return ret; |
| 9711 | } |
| 9712 | |
| 9713 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 9714 | { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9715 | struct tg3 *tp = netdev_priv(dev); |
| 9716 | |
| 9717 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9718 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9719 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
| 9720 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9721 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 9722 | return phy_ethtool_gset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9723 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9725 | cmd->supported = (SUPPORTED_Autoneg); |
| 9726 | |
| 9727 | if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) |
| 9728 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
| 9729 | SUPPORTED_1000baseT_Full); |
| 9730 | |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 9731 | if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9732 | cmd->supported |= (SUPPORTED_100baseT_Half | |
| 9733 | SUPPORTED_100baseT_Full | |
| 9734 | SUPPORTED_10baseT_Half | |
| 9735 | SUPPORTED_10baseT_Full | |
Matt Carlson | 3bebab5 | 2007-11-12 21:22:40 -0800 | [diff] [blame] | 9736 | SUPPORTED_TP); |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 9737 | cmd->port = PORT_TP; |
| 9738 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9739 | cmd->supported |= SUPPORTED_FIBRE; |
Karsten Keil | ef34814 | 2006-05-12 12:49:08 -0700 | [diff] [blame] | 9740 | cmd->port = PORT_FIBRE; |
| 9741 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9743 | cmd->advertising = tp->link_config.advertising; |
| 9744 | if (netif_running(dev)) { |
| 9745 | cmd->speed = tp->link_config.active_speed; |
| 9746 | cmd->duplex = tp->link_config.active_duplex; |
| 9747 | } |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 9748 | cmd->phy_address = tp->phy_addr; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9749 | cmd->transceiver = XCVR_INTERNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9750 | cmd->autoneg = tp->link_config.autoneg; |
| 9751 | cmd->maxtxpkt = 0; |
| 9752 | cmd->maxrxpkt = 0; |
| 9753 | return 0; |
| 9754 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9756 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 9757 | { |
| 9758 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9759 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9760 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9761 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9762 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
| 9763 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9764 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 9765 | return phy_ethtool_sset(phydev, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9766 | } |
| 9767 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9768 | if (cmd->autoneg != AUTONEG_ENABLE && |
| 9769 | cmd->autoneg != AUTONEG_DISABLE) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 9770 | return -EINVAL; |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9771 | |
| 9772 | if (cmd->autoneg == AUTONEG_DISABLE && |
| 9773 | cmd->duplex != DUPLEX_FULL && |
| 9774 | cmd->duplex != DUPLEX_HALF) |
Michael Chan | 37ff238 | 2005-10-26 15:49:51 -0700 | [diff] [blame] | 9775 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9776 | |
Matt Carlson | 7e5856b | 2009-02-25 14:23:01 +0000 | [diff] [blame] | 9777 | if (cmd->autoneg == AUTONEG_ENABLE) { |
| 9778 | u32 mask = ADVERTISED_Autoneg | |
| 9779 | ADVERTISED_Pause | |
| 9780 | ADVERTISED_Asym_Pause; |
| 9781 | |
| 9782 | if (!(tp->tg3_flags2 & TG3_FLAG_10_100_ONLY)) |
| 9783 | mask |= ADVERTISED_1000baseT_Half | |
| 9784 | ADVERTISED_1000baseT_Full; |
| 9785 | |
| 9786 | if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) |
| 9787 | mask |= ADVERTISED_100baseT_Half | |
| 9788 | ADVERTISED_100baseT_Full | |
| 9789 | ADVERTISED_10baseT_Half | |
| 9790 | ADVERTISED_10baseT_Full | |
| 9791 | ADVERTISED_TP; |
| 9792 | else |
| 9793 | mask |= ADVERTISED_FIBRE; |
| 9794 | |
| 9795 | if (cmd->advertising & ~mask) |
| 9796 | return -EINVAL; |
| 9797 | |
| 9798 | mask &= (ADVERTISED_1000baseT_Half | |
| 9799 | ADVERTISED_1000baseT_Full | |
| 9800 | ADVERTISED_100baseT_Half | |
| 9801 | ADVERTISED_100baseT_Full | |
| 9802 | ADVERTISED_10baseT_Half | |
| 9803 | ADVERTISED_10baseT_Full); |
| 9804 | |
| 9805 | cmd->advertising &= mask; |
| 9806 | } else { |
| 9807 | if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) { |
| 9808 | if (cmd->speed != SPEED_1000) |
| 9809 | return -EINVAL; |
| 9810 | |
| 9811 | if (cmd->duplex != DUPLEX_FULL) |
| 9812 | return -EINVAL; |
| 9813 | } else { |
| 9814 | if (cmd->speed != SPEED_100 && |
| 9815 | cmd->speed != SPEED_10) |
| 9816 | return -EINVAL; |
| 9817 | } |
| 9818 | } |
| 9819 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9820 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9821 | |
| 9822 | tp->link_config.autoneg = cmd->autoneg; |
| 9823 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Andy Gospodarek | 405d8e5 | 2007-10-08 01:08:47 -0700 | [diff] [blame] | 9824 | tp->link_config.advertising = (cmd->advertising | |
| 9825 | ADVERTISED_Autoneg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9826 | tp->link_config.speed = SPEED_INVALID; |
| 9827 | tp->link_config.duplex = DUPLEX_INVALID; |
| 9828 | } else { |
| 9829 | tp->link_config.advertising = 0; |
| 9830 | tp->link_config.speed = cmd->speed; |
| 9831 | tp->link_config.duplex = cmd->duplex; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9832 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9833 | |
Michael Chan | 24fcad6 | 2006-12-17 17:06:46 -0800 | [diff] [blame] | 9834 | tp->link_config.orig_speed = tp->link_config.speed; |
| 9835 | tp->link_config.orig_duplex = tp->link_config.duplex; |
| 9836 | tp->link_config.orig_autoneg = tp->link_config.autoneg; |
| 9837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9838 | if (netif_running(dev)) |
| 9839 | tg3_setup_phy(tp, 1); |
| 9840 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9841 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9843 | return 0; |
| 9844 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9846 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 9847 | { |
| 9848 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9850 | strcpy(info->driver, DRV_MODULE_NAME); |
| 9851 | strcpy(info->version, DRV_MODULE_VERSION); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 9852 | strcpy(info->fw_version, tp->fw_ver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9853 | strcpy(info->bus_info, pci_name(tp->pdev)); |
| 9854 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9856 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 9857 | { |
| 9858 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9859 | |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9860 | if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) && |
| 9861 | device_can_wakeup(&tp->pdev->dev)) |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 9862 | wol->supported = WAKE_MAGIC; |
| 9863 | else |
| 9864 | wol->supported = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9865 | wol->wolopts = 0; |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 9866 | if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) && |
| 9867 | device_can_wakeup(&tp->pdev->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9868 | wol->wolopts = WAKE_MAGIC; |
| 9869 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 9870 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9872 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 9873 | { |
| 9874 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9875 | struct device *dp = &tp->pdev->dev; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9877 | if (wol->wolopts & ~WAKE_MAGIC) |
| 9878 | return -EINVAL; |
| 9879 | if ((wol->wolopts & WAKE_MAGIC) && |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9880 | !((tp->tg3_flags & TG3_FLAG_WOL_CAP) && device_can_wakeup(dp))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9881 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9882 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9883 | spin_lock_bh(&tp->lock); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9884 | if (wol->wolopts & WAKE_MAGIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9885 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9886 | device_set_wakeup_enable(dp, true); |
| 9887 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9888 | tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE; |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 9889 | device_set_wakeup_enable(dp, false); |
| 9890 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 9891 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9893 | return 0; |
| 9894 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9896 | static u32 tg3_get_msglevel(struct net_device *dev) |
| 9897 | { |
| 9898 | struct tg3 *tp = netdev_priv(dev); |
| 9899 | return tp->msg_enable; |
| 9900 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9902 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
| 9903 | { |
| 9904 | struct tg3 *tp = netdev_priv(dev); |
| 9905 | tp->msg_enable = value; |
| 9906 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9908 | static int tg3_set_tso(struct net_device *dev, u32 value) |
| 9909 | { |
| 9910 | struct tg3 *tp = netdev_priv(dev); |
| 9911 | |
| 9912 | if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { |
| 9913 | if (value) |
| 9914 | return -EINVAL; |
| 9915 | return 0; |
| 9916 | } |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 9917 | if ((dev->features & NETIF_F_IPV6_CSUM) && |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 9918 | ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) || |
| 9919 | (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3))) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 9920 | if (value) { |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 9921 | dev->features |= NETIF_F_TSO6; |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 9922 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
| 9923 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 9924 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 9925 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 9926 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 9927 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 9928 | dev->features |= NETIF_F_TSO_ECN; |
| 9929 | } else |
| 9930 | dev->features &= ~(NETIF_F_TSO6 | NETIF_F_TSO_ECN); |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 9931 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9932 | return ethtool_op_set_tso(dev, value); |
| 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 int tg3_nway_reset(struct net_device *dev) |
| 9936 | { |
| 9937 | struct tg3 *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9938 | int r; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9940 | if (!netif_running(dev)) |
| 9941 | return -EAGAIN; |
| 9942 | |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 9943 | if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) |
| 9944 | return -EINVAL; |
| 9945 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 9946 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
| 9947 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
| 9948 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 9949 | 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] | 9950 | } else { |
| 9951 | u32 bmcr; |
| 9952 | |
| 9953 | spin_lock_bh(&tp->lock); |
| 9954 | r = -EINVAL; |
| 9955 | tg3_readphy(tp, MII_BMCR, &bmcr); |
| 9956 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && |
| 9957 | ((bmcr & BMCR_ANENABLE) || |
| 9958 | (tp->tg3_flags2 & TG3_FLG2_PARALLEL_DETECT))) { |
| 9959 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
| 9960 | BMCR_ANENABLE); |
| 9961 | r = 0; |
| 9962 | } |
| 9963 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9964 | } |
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 | return r; |
| 9967 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9969 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 9970 | { |
| 9971 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9973 | ering->rx_max_pending = TG3_RX_RING_SIZE - 1; |
| 9974 | ering->rx_mini_max_pending = 0; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 9975 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) |
| 9976 | ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1; |
| 9977 | else |
| 9978 | ering->rx_jumbo_max_pending = 0; |
| 9979 | |
| 9980 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9981 | |
| 9982 | ering->rx_pending = tp->rx_pending; |
| 9983 | ering->rx_mini_pending = 0; |
Michael Chan | 4f81c32 | 2006-03-20 21:33:42 -0800 | [diff] [blame] | 9984 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) |
| 9985 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
| 9986 | else |
| 9987 | ering->rx_jumbo_pending = 0; |
| 9988 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 9989 | ering->tx_pending = tp->napi[0].tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9990 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9992 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
| 9993 | { |
| 9994 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 9995 | int i, irq_sync = 0, err = 0; |
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 | if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) || |
| 9998 | (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) || |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 9999 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
| 10000 | (ering->tx_pending <= MAX_SKB_FRAGS) || |
Michael Chan | 7f62ad5 | 2007-02-20 23:25:40 -0800 | [diff] [blame] | 10001 | ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) && |
Michael Chan | bc3a925 | 2006-10-18 20:55:18 -0700 | [diff] [blame] | 10002 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10003 | return -EINVAL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10004 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10005 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10006 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10007 | tg3_netif_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10008 | irq_sync = 1; |
| 10009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10010 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10011 | tg3_full_lock(tp, irq_sync); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10013 | tp->rx_pending = ering->rx_pending; |
| 10014 | |
| 10015 | if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) && |
| 10016 | tp->rx_pending > 63) |
| 10017 | tp->rx_pending = 63; |
| 10018 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 10019 | |
| 10020 | for (i = 0; i < TG3_IRQ_MAX_VECS; i++) |
| 10021 | tp->napi[i].tx_pending = ering->tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10022 | |
| 10023 | if (netif_running(dev)) { |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 10024 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10025 | err = tg3_restart_hw(tp, 1); |
| 10026 | if (!err) |
| 10027 | tg3_netif_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10028 | } |
| 10029 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10030 | tg3_full_unlock(tp); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10031 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10032 | if (irq_sync && !err) |
| 10033 | tg3_phy_start(tp); |
| 10034 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10035 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10036 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10037 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10038 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10039 | { |
| 10040 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10042 | epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0; |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10043 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10044 | if (tp->link_config.active_flowctrl & FLOW_CTRL_RX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10045 | epause->rx_pause = 1; |
| 10046 | else |
| 10047 | epause->rx_pause = 0; |
| 10048 | |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10049 | if (tp->link_config.active_flowctrl & FLOW_CTRL_TX) |
Matt Carlson | 8d01862 | 2007-12-20 20:05:44 -0800 | [diff] [blame] | 10050 | epause->tx_pause = 1; |
| 10051 | else |
| 10052 | epause->tx_pause = 0; |
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 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 10056 | { |
| 10057 | struct tg3 *tp = netdev_priv(dev); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10058 | int err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10059 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10060 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10061 | u32 newadv; |
| 10062 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10063 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10064 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10065 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10066 | if (!(phydev->supported & SUPPORTED_Pause) || |
| 10067 | (!(phydev->supported & SUPPORTED_Asym_Pause) && |
| 10068 | ((epause->rx_pause && !epause->tx_pause) || |
| 10069 | (!epause->rx_pause && epause->tx_pause)))) |
| 10070 | return -EINVAL; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10071 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10072 | tp->link_config.flowctrl = 0; |
| 10073 | if (epause->rx_pause) { |
| 10074 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10075 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10076 | if (epause->tx_pause) { |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10077 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10078 | newadv = ADVERTISED_Pause; |
| 10079 | } else |
| 10080 | newadv = ADVERTISED_Pause | |
| 10081 | ADVERTISED_Asym_Pause; |
| 10082 | } else if (epause->tx_pause) { |
| 10083 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 10084 | newadv = ADVERTISED_Asym_Pause; |
| 10085 | } else |
| 10086 | newadv = 0; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10087 | |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10088 | if (epause->autoneg) |
| 10089 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; |
| 10090 | else |
| 10091 | tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG; |
| 10092 | |
| 10093 | if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) { |
| 10094 | u32 oldadv = phydev->advertising & |
| 10095 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 10096 | if (oldadv != newadv) { |
| 10097 | phydev->advertising &= |
| 10098 | ~(ADVERTISED_Pause | |
| 10099 | ADVERTISED_Asym_Pause); |
| 10100 | phydev->advertising |= newadv; |
| 10101 | if (phydev->autoneg) { |
| 10102 | /* |
| 10103 | * Always renegotiate the link to |
| 10104 | * inform our link partner of our |
| 10105 | * flow control settings, even if the |
| 10106 | * flow control is forced. Let |
| 10107 | * tg3_adjust_link() do the final |
| 10108 | * flow control setup. |
| 10109 | */ |
| 10110 | return phy_start_aneg(phydev); |
| 10111 | } |
| 10112 | } |
| 10113 | |
| 10114 | if (!epause->autoneg) |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10115 | tg3_setup_flow_control(tp, 0, 0); |
Matt Carlson | 2712168 | 2010-02-17 15:16:57 +0000 | [diff] [blame] | 10116 | } else { |
| 10117 | tp->link_config.orig_advertising &= |
| 10118 | ~(ADVERTISED_Pause | |
| 10119 | ADVERTISED_Asym_Pause); |
| 10120 | tp->link_config.orig_advertising |= newadv; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10121 | } |
| 10122 | } else { |
| 10123 | int irq_sync = 0; |
| 10124 | |
| 10125 | if (netif_running(dev)) { |
| 10126 | tg3_netif_stop(tp); |
| 10127 | irq_sync = 1; |
| 10128 | } |
| 10129 | |
| 10130 | tg3_full_lock(tp, irq_sync); |
| 10131 | |
| 10132 | if (epause->autoneg) |
| 10133 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; |
| 10134 | else |
| 10135 | tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG; |
| 10136 | if (epause->rx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10137 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10138 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10139 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10140 | if (epause->tx_pause) |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10141 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10142 | else |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 10143 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 10144 | |
| 10145 | if (netif_running(dev)) { |
| 10146 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 10147 | err = tg3_restart_hw(tp, 1); |
| 10148 | if (!err) |
| 10149 | tg3_netif_start(tp); |
| 10150 | } |
| 10151 | |
| 10152 | tg3_full_unlock(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 10153 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10154 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10155 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10156 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10158 | static u32 tg3_get_rx_csum(struct net_device *dev) |
| 10159 | { |
| 10160 | struct tg3 *tp = netdev_priv(dev); |
| 10161 | return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0; |
| 10162 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10164 | static int tg3_set_rx_csum(struct net_device *dev, u32 data) |
| 10165 | { |
| 10166 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10168 | if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) { |
| 10169 | if (data != 0) |
| 10170 | return -EINVAL; |
| 10171 | return 0; |
| 10172 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10173 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10174 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10175 | if (data) |
| 10176 | tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; |
| 10177 | else |
| 10178 | tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 10179 | spin_unlock_bh(&tp->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10181 | return 0; |
| 10182 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10184 | static int tg3_set_tx_csum(struct net_device *dev, u32 data) |
| 10185 | { |
| 10186 | struct tg3 *tp = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10188 | if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) { |
| 10189 | if (data != 0) |
| 10190 | return -EINVAL; |
| 10191 | return 0; |
| 10192 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10193 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10194 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Michael Chan | 6460d94 | 2007-07-14 19:07:52 -0700 | [diff] [blame] | 10195 | ethtool_op_set_tx_ipv6_csum(dev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10196 | else |
Michael Chan | 9c27dbd | 2006-03-20 22:28:27 -0800 | [diff] [blame] | 10197 | ethtool_op_set_tx_csum(dev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10198 | |
| 10199 | return 0; |
| 10200 | } |
| 10201 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 10202 | static int tg3_get_sset_count (struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10203 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 10204 | switch (sset) { |
| 10205 | case ETH_SS_TEST: |
| 10206 | return TG3_NUM_TEST; |
| 10207 | case ETH_SS_STATS: |
| 10208 | return TG3_NUM_STATS; |
| 10209 | default: |
| 10210 | return -EOPNOTSUPP; |
| 10211 | } |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10212 | } |
| 10213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10214 | static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf) |
| 10215 | { |
| 10216 | switch (stringset) { |
| 10217 | case ETH_SS_STATS: |
| 10218 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 10219 | break; |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10220 | case ETH_SS_TEST: |
| 10221 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); |
| 10222 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10223 | default: |
| 10224 | WARN_ON(1); /* we need a WARN() */ |
| 10225 | break; |
| 10226 | } |
| 10227 | } |
| 10228 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10229 | static int tg3_phys_id(struct net_device *dev, u32 data) |
| 10230 | { |
| 10231 | struct tg3 *tp = netdev_priv(dev); |
| 10232 | int i; |
| 10233 | |
| 10234 | if (!netif_running(tp->dev)) |
| 10235 | return -EAGAIN; |
| 10236 | |
| 10237 | if (data == 0) |
Stephen Hemminger | 759afc3 | 2008-02-23 19:51:59 -0800 | [diff] [blame] | 10238 | data = UINT_MAX / 2; |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10239 | |
| 10240 | for (i = 0; i < (data * 2); i++) { |
| 10241 | if ((i % 2) == 0) |
| 10242 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 10243 | LED_CTRL_1000MBPS_ON | |
| 10244 | LED_CTRL_100MBPS_ON | |
| 10245 | LED_CTRL_10MBPS_ON | |
| 10246 | LED_CTRL_TRAFFIC_OVERRIDE | |
| 10247 | LED_CTRL_TRAFFIC_BLINK | |
| 10248 | LED_CTRL_TRAFFIC_LED); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10249 | |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 10250 | else |
| 10251 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 10252 | LED_CTRL_TRAFFIC_OVERRIDE); |
| 10253 | |
| 10254 | if (msleep_interruptible(500)) |
| 10255 | break; |
| 10256 | } |
| 10257 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 10258 | return 0; |
| 10259 | } |
| 10260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10261 | static void tg3_get_ethtool_stats (struct net_device *dev, |
| 10262 | struct ethtool_stats *estats, u64 *tmp_stats) |
| 10263 | { |
| 10264 | struct tg3 *tp = netdev_priv(dev); |
| 10265 | memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats)); |
| 10266 | } |
| 10267 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10268 | #define NVRAM_TEST_SIZE 0x100 |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10269 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
| 10270 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 |
| 10271 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10272 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
| 10273 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10274 | |
| 10275 | static int tg3_test_nvram(struct tg3 *tp) |
| 10276 | { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10277 | u32 csum, magic; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10278 | __be32 *buf; |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 10279 | int i, j, k, err = 0, size; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10280 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 10281 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) |
| 10282 | return 0; |
| 10283 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 10284 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10285 | return -EIO; |
| 10286 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10287 | if (magic == TG3_EEPROM_MAGIC) |
| 10288 | size = NVRAM_TEST_SIZE; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10289 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10290 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
| 10291 | TG3_EEPROM_SB_FORMAT_1) { |
| 10292 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { |
| 10293 | case TG3_EEPROM_SB_REVISION_0: |
| 10294 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; |
| 10295 | break; |
| 10296 | case TG3_EEPROM_SB_REVISION_2: |
| 10297 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; |
| 10298 | break; |
| 10299 | case TG3_EEPROM_SB_REVISION_3: |
| 10300 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; |
| 10301 | break; |
| 10302 | default: |
| 10303 | return 0; |
| 10304 | } |
| 10305 | } else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10306 | return 0; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10307 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 10308 | size = NVRAM_SELFBOOT_HW_SIZE; |
| 10309 | else |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10310 | return -EIO; |
| 10311 | |
| 10312 | buf = kmalloc(size, GFP_KERNEL); |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10313 | if (buf == NULL) |
| 10314 | return -ENOMEM; |
| 10315 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10316 | err = -EIO; |
| 10317 | for (i = 0, j = 0; i < size; i += 4, j++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10318 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
| 10319 | if (err) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10320 | break; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10321 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10322 | if (i < size) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10323 | goto out; |
| 10324 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10325 | /* Selfboot format */ |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10326 | magic = be32_to_cpu(buf[0]); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10327 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10328 | TG3_EEPROM_MAGIC_FW) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10329 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
| 10330 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10331 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
Matt Carlson | a5767de | 2007-11-12 21:10:58 -0800 | [diff] [blame] | 10332 | TG3_EEPROM_SB_REVISION_2) { |
| 10333 | /* For rev 2, the csum doesn't include the MBA. */ |
| 10334 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) |
| 10335 | csum8 += buf8[i]; |
| 10336 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) |
| 10337 | csum8 += buf8[i]; |
| 10338 | } else { |
| 10339 | for (i = 0; i < size; i++) |
| 10340 | csum8 += buf8[i]; |
| 10341 | } |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10342 | |
Adrian Bunk | ad96b48 | 2006-04-05 22:21:04 -0700 | [diff] [blame] | 10343 | if (csum8 == 0) { |
| 10344 | err = 0; |
| 10345 | goto out; |
| 10346 | } |
| 10347 | |
| 10348 | err = -EIO; |
| 10349 | goto out; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 10350 | } |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10351 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 10352 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10353 | TG3_EEPROM_MAGIC_HW) { |
| 10354 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10355 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10356 | u8 *buf8 = (u8 *) buf; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10357 | |
| 10358 | /* Separate the parity bits and the data bytes. */ |
| 10359 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { |
| 10360 | if ((i == 0) || (i == 8)) { |
| 10361 | int l; |
| 10362 | u8 msk; |
| 10363 | |
| 10364 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) |
| 10365 | parity[k++] = buf8[i] & msk; |
| 10366 | i++; |
| 10367 | } |
| 10368 | else if (i == 16) { |
| 10369 | int l; |
| 10370 | u8 msk; |
| 10371 | |
| 10372 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) |
| 10373 | parity[k++] = buf8[i] & msk; |
| 10374 | i++; |
| 10375 | |
| 10376 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) |
| 10377 | parity[k++] = buf8[i] & msk; |
| 10378 | i++; |
| 10379 | } |
| 10380 | data[j++] = buf8[i]; |
| 10381 | } |
| 10382 | |
| 10383 | err = -EIO; |
| 10384 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { |
| 10385 | u8 hw8 = hweight8(data[i]); |
| 10386 | |
| 10387 | if ((hw8 & 0x1) && parity[i]) |
| 10388 | goto out; |
| 10389 | else if (!(hw8 & 0x1) && !parity[i]) |
| 10390 | goto out; |
| 10391 | } |
| 10392 | err = 0; |
| 10393 | goto out; |
| 10394 | } |
| 10395 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10396 | /* Bootstrap checksum at offset 0x10 */ |
| 10397 | csum = calc_crc((unsigned char *) buf, 0x10); |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10398 | if (csum != be32_to_cpu(buf[0x10/4])) |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10399 | goto out; |
| 10400 | |
| 10401 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ |
| 10402 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 10403 | if (csum != be32_to_cpu(buf[0xfc/4])) |
| 10404 | goto out; |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10405 | |
| 10406 | err = 0; |
| 10407 | |
| 10408 | out: |
| 10409 | kfree(buf); |
| 10410 | return err; |
| 10411 | } |
| 10412 | |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 10413 | #define TG3_SERDES_TIMEOUT_SEC 2 |
| 10414 | #define TG3_COPPER_TIMEOUT_SEC 6 |
| 10415 | |
| 10416 | static int tg3_test_link(struct tg3 *tp) |
| 10417 | { |
| 10418 | int i, max; |
| 10419 | |
| 10420 | if (!netif_running(tp->dev)) |
| 10421 | return -ENODEV; |
| 10422 | |
Michael Chan | 4c98748 | 2005-09-05 17:52:38 -0700 | [diff] [blame] | 10423 | if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 10424 | max = TG3_SERDES_TIMEOUT_SEC; |
| 10425 | else |
| 10426 | max = TG3_COPPER_TIMEOUT_SEC; |
| 10427 | |
| 10428 | for (i = 0; i < max; i++) { |
| 10429 | if (netif_carrier_ok(tp->dev)) |
| 10430 | return 0; |
| 10431 | |
| 10432 | if (msleep_interruptible(1000)) |
| 10433 | break; |
| 10434 | } |
| 10435 | |
| 10436 | return -EIO; |
| 10437 | } |
| 10438 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10439 | /* Only test the commonly used registers */ |
David S. Miller | 30ca3e3 | 2006-03-20 23:02:36 -0800 | [diff] [blame] | 10440 | static int tg3_test_registers(struct tg3 *tp) |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10441 | { |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10442 | int i, is_5705, is_5750; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10443 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
| 10444 | static struct { |
| 10445 | u16 offset; |
| 10446 | u16 flags; |
| 10447 | #define TG3_FL_5705 0x1 |
| 10448 | #define TG3_FL_NOT_5705 0x2 |
| 10449 | #define TG3_FL_NOT_5788 0x4 |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10450 | #define TG3_FL_NOT_5750 0x8 |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10451 | u32 read_mask; |
| 10452 | u32 write_mask; |
| 10453 | } reg_tbl[] = { |
| 10454 | /* MAC Control Registers */ |
| 10455 | { MAC_MODE, TG3_FL_NOT_5705, |
| 10456 | 0x00000000, 0x00ef6f8c }, |
| 10457 | { MAC_MODE, TG3_FL_5705, |
| 10458 | 0x00000000, 0x01ef6b8c }, |
| 10459 | { MAC_STATUS, TG3_FL_NOT_5705, |
| 10460 | 0x03800107, 0x00000000 }, |
| 10461 | { MAC_STATUS, TG3_FL_5705, |
| 10462 | 0x03800100, 0x00000000 }, |
| 10463 | { MAC_ADDR_0_HIGH, 0x0000, |
| 10464 | 0x00000000, 0x0000ffff }, |
| 10465 | { MAC_ADDR_0_LOW, 0x0000, |
| 10466 | 0x00000000, 0xffffffff }, |
| 10467 | { MAC_RX_MTU_SIZE, 0x0000, |
| 10468 | 0x00000000, 0x0000ffff }, |
| 10469 | { MAC_TX_MODE, 0x0000, |
| 10470 | 0x00000000, 0x00000070 }, |
| 10471 | { MAC_TX_LENGTHS, 0x0000, |
| 10472 | 0x00000000, 0x00003fff }, |
| 10473 | { MAC_RX_MODE, TG3_FL_NOT_5705, |
| 10474 | 0x00000000, 0x000007fc }, |
| 10475 | { MAC_RX_MODE, TG3_FL_5705, |
| 10476 | 0x00000000, 0x000007dc }, |
| 10477 | { MAC_HASH_REG_0, 0x0000, |
| 10478 | 0x00000000, 0xffffffff }, |
| 10479 | { MAC_HASH_REG_1, 0x0000, |
| 10480 | 0x00000000, 0xffffffff }, |
| 10481 | { MAC_HASH_REG_2, 0x0000, |
| 10482 | 0x00000000, 0xffffffff }, |
| 10483 | { MAC_HASH_REG_3, 0x0000, |
| 10484 | 0x00000000, 0xffffffff }, |
| 10485 | |
| 10486 | /* Receive Data and Receive BD Initiator Control Registers. */ |
| 10487 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, |
| 10488 | 0x00000000, 0xffffffff }, |
| 10489 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, |
| 10490 | 0x00000000, 0xffffffff }, |
| 10491 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, |
| 10492 | 0x00000000, 0x00000003 }, |
| 10493 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, |
| 10494 | 0x00000000, 0xffffffff }, |
| 10495 | { RCVDBDI_STD_BD+0, 0x0000, |
| 10496 | 0x00000000, 0xffffffff }, |
| 10497 | { RCVDBDI_STD_BD+4, 0x0000, |
| 10498 | 0x00000000, 0xffffffff }, |
| 10499 | { RCVDBDI_STD_BD+8, 0x0000, |
| 10500 | 0x00000000, 0xffff0002 }, |
| 10501 | { RCVDBDI_STD_BD+0xc, 0x0000, |
| 10502 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10503 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10504 | /* Receive BD Initiator Control Registers. */ |
| 10505 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, |
| 10506 | 0x00000000, 0xffffffff }, |
| 10507 | { RCVBDI_STD_THRESH, TG3_FL_5705, |
| 10508 | 0x00000000, 0x000003ff }, |
| 10509 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, |
| 10510 | 0x00000000, 0xffffffff }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10511 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10512 | /* Host Coalescing Control Registers. */ |
| 10513 | { HOSTCC_MODE, TG3_FL_NOT_5705, |
| 10514 | 0x00000000, 0x00000004 }, |
| 10515 | { HOSTCC_MODE, TG3_FL_5705, |
| 10516 | 0x00000000, 0x000000f6 }, |
| 10517 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, |
| 10518 | 0x00000000, 0xffffffff }, |
| 10519 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, |
| 10520 | 0x00000000, 0x000003ff }, |
| 10521 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, |
| 10522 | 0x00000000, 0xffffffff }, |
| 10523 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, |
| 10524 | 0x00000000, 0x000003ff }, |
| 10525 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, |
| 10526 | 0x00000000, 0xffffffff }, |
| 10527 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10528 | 0x00000000, 0x000000ff }, |
| 10529 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, |
| 10530 | 0x00000000, 0xffffffff }, |
| 10531 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10532 | 0x00000000, 0x000000ff }, |
| 10533 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 10534 | 0x00000000, 0xffffffff }, |
| 10535 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 10536 | 0x00000000, 0xffffffff }, |
| 10537 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 10538 | 0x00000000, 0xffffffff }, |
| 10539 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10540 | 0x00000000, 0x000000ff }, |
| 10541 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 10542 | 0x00000000, 0xffffffff }, |
| 10543 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 10544 | 0x00000000, 0x000000ff }, |
| 10545 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, |
| 10546 | 0x00000000, 0xffffffff }, |
| 10547 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, |
| 10548 | 0x00000000, 0xffffffff }, |
| 10549 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, |
| 10550 | 0x00000000, 0xffffffff }, |
| 10551 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, |
| 10552 | 0x00000000, 0xffffffff }, |
| 10553 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, |
| 10554 | 0x00000000, 0xffffffff }, |
| 10555 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, |
| 10556 | 0xffffffff, 0x00000000 }, |
| 10557 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, |
| 10558 | 0xffffffff, 0x00000000 }, |
| 10559 | |
| 10560 | /* Buffer Manager Control Registers. */ |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10561 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10562 | 0x00000000, 0x007fff80 }, |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10563 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10564 | 0x00000000, 0x007fffff }, |
| 10565 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, |
| 10566 | 0x00000000, 0x0000003f }, |
| 10567 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, |
| 10568 | 0x00000000, 0x000001ff }, |
| 10569 | { BUFMGR_MB_HIGH_WATER, 0x0000, |
| 10570 | 0x00000000, 0x000001ff }, |
| 10571 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, |
| 10572 | 0xffffffff, 0x00000000 }, |
| 10573 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, |
| 10574 | 0xffffffff, 0x00000000 }, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10575 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10576 | /* Mailbox Registers */ |
| 10577 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, |
| 10578 | 0x00000000, 0x000001ff }, |
| 10579 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, |
| 10580 | 0x00000000, 0x000001ff }, |
| 10581 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, |
| 10582 | 0x00000000, 0x000007ff }, |
| 10583 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, |
| 10584 | 0x00000000, 0x000001ff }, |
| 10585 | |
| 10586 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, |
| 10587 | }; |
| 10588 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10589 | is_5705 = is_5750 = 0; |
| 10590 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10591 | is_5705 = 1; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10592 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
| 10593 | is_5750 = 1; |
| 10594 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10595 | |
| 10596 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { |
| 10597 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) |
| 10598 | continue; |
| 10599 | |
| 10600 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) |
| 10601 | continue; |
| 10602 | |
| 10603 | if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) && |
| 10604 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
| 10605 | continue; |
| 10606 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10607 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
| 10608 | continue; |
| 10609 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10610 | offset = (u32) reg_tbl[i].offset; |
| 10611 | read_mask = reg_tbl[i].read_mask; |
| 10612 | write_mask = reg_tbl[i].write_mask; |
| 10613 | |
| 10614 | /* Save the original register content */ |
| 10615 | save_val = tr32(offset); |
| 10616 | |
| 10617 | /* Determine the read-only value. */ |
| 10618 | read_val = save_val & read_mask; |
| 10619 | |
| 10620 | /* Write zero to the register, then make sure the read-only bits |
| 10621 | * are not changed and the read/write bits are all zeros. |
| 10622 | */ |
| 10623 | tw32(offset, 0); |
| 10624 | |
| 10625 | val = tr32(offset); |
| 10626 | |
| 10627 | /* Test the read-only and read/write bits. */ |
| 10628 | if (((val & read_mask) != read_val) || (val & write_mask)) |
| 10629 | goto out; |
| 10630 | |
| 10631 | /* Write ones to all the bits defined by RdMask and WrMask, then |
| 10632 | * make sure the read-only bits are not changed and the |
| 10633 | * read/write bits are all ones. |
| 10634 | */ |
| 10635 | tw32(offset, read_mask | write_mask); |
| 10636 | |
| 10637 | val = tr32(offset); |
| 10638 | |
| 10639 | /* Test the read-only bits. */ |
| 10640 | if ((val & read_mask) != read_val) |
| 10641 | goto out; |
| 10642 | |
| 10643 | /* Test the read/write bits. */ |
| 10644 | if ((val & write_mask) != write_mask) |
| 10645 | goto out; |
| 10646 | |
| 10647 | tw32(offset, save_val); |
| 10648 | } |
| 10649 | |
| 10650 | return 0; |
| 10651 | |
| 10652 | out: |
Michael Chan | 9f88f29 | 2006-12-07 00:22:54 -0800 | [diff] [blame] | 10653 | if (netif_msg_hw(tp)) |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 10654 | pr_err("Register test failed at offset %x\n", offset); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 10655 | tw32(offset, save_val); |
| 10656 | return -EIO; |
| 10657 | } |
| 10658 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10659 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
| 10660 | { |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 10661 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10662 | int i; |
| 10663 | u32 j; |
| 10664 | |
Alejandro Martinez Ruiz | e9edda6 | 2007-10-15 03:37:43 +0200 | [diff] [blame] | 10665 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10666 | for (j = 0; j < len; j += 4) { |
| 10667 | u32 val; |
| 10668 | |
| 10669 | tg3_write_mem(tp, offset + j, test_pattern[i]); |
| 10670 | tg3_read_mem(tp, offset + j, &val); |
| 10671 | if (val != test_pattern[i]) |
| 10672 | return -EIO; |
| 10673 | } |
| 10674 | } |
| 10675 | return 0; |
| 10676 | } |
| 10677 | |
| 10678 | static int tg3_test_memory(struct tg3 *tp) |
| 10679 | { |
| 10680 | static struct mem_entry { |
| 10681 | u32 offset; |
| 10682 | u32 len; |
| 10683 | } mem_tbl_570x[] = { |
Michael Chan | 3869019 | 2005-12-19 16:27:28 -0800 | [diff] [blame] | 10684 | { 0x00000000, 0x00b50}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10685 | { 0x00002000, 0x1c000}, |
| 10686 | { 0xffffffff, 0x00000} |
| 10687 | }, mem_tbl_5705[] = { |
| 10688 | { 0x00000100, 0x0000c}, |
| 10689 | { 0x00000200, 0x00008}, |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10690 | { 0x00004000, 0x00800}, |
| 10691 | { 0x00006000, 0x01000}, |
| 10692 | { 0x00008000, 0x02000}, |
| 10693 | { 0x00010000, 0x0e000}, |
| 10694 | { 0xffffffff, 0x00000} |
Michael Chan | 79f4d13 | 2006-03-20 22:28:57 -0800 | [diff] [blame] | 10695 | }, mem_tbl_5755[] = { |
| 10696 | { 0x00000200, 0x00008}, |
| 10697 | { 0x00004000, 0x00800}, |
| 10698 | { 0x00006000, 0x00800}, |
| 10699 | { 0x00008000, 0x02000}, |
| 10700 | { 0x00010000, 0x0c000}, |
| 10701 | { 0xffffffff, 0x00000} |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10702 | }, mem_tbl_5906[] = { |
| 10703 | { 0x00000200, 0x00008}, |
| 10704 | { 0x00004000, 0x00400}, |
| 10705 | { 0x00006000, 0x00400}, |
| 10706 | { 0x00008000, 0x01000}, |
| 10707 | { 0x00010000, 0x01000}, |
| 10708 | { 0xffffffff, 0x00000} |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 10709 | }, mem_tbl_5717[] = { |
| 10710 | { 0x00000200, 0x00008}, |
| 10711 | { 0x00010000, 0x0a000}, |
| 10712 | { 0x00020000, 0x13c00}, |
| 10713 | { 0xffffffff, 0x00000} |
| 10714 | }, mem_tbl_57765[] = { |
| 10715 | { 0x00000200, 0x00008}, |
| 10716 | { 0x00004000, 0x00800}, |
| 10717 | { 0x00006000, 0x09800}, |
| 10718 | { 0x00010000, 0x0a000}, |
| 10719 | { 0xffffffff, 0x00000} |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10720 | }; |
| 10721 | struct mem_entry *mem_tbl; |
| 10722 | int err = 0; |
| 10723 | int i; |
| 10724 | |
Matt Carlson | 8b5a6c4 | 2010-01-20 16:58:06 +0000 | [diff] [blame] | 10725 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
| 10726 | mem_tbl = mem_tbl_5717; |
| 10727 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 10728 | mem_tbl = mem_tbl_57765; |
| 10729 | else if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10730 | mem_tbl = mem_tbl_5755; |
| 10731 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 10732 | mem_tbl = mem_tbl_5906; |
| 10733 | else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
| 10734 | mem_tbl = mem_tbl_5705; |
| 10735 | else |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10736 | mem_tbl = mem_tbl_570x; |
| 10737 | |
| 10738 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { |
| 10739 | if ((err = tg3_do_mem_test(tp, mem_tbl[i].offset, |
| 10740 | mem_tbl[i].len)) != 0) |
| 10741 | break; |
| 10742 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10743 | |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 10744 | return err; |
| 10745 | } |
| 10746 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10747 | #define TG3_MAC_LOOPBACK 0 |
| 10748 | #define TG3_PHY_LOOPBACK 1 |
| 10749 | |
| 10750 | static int tg3_run_loopback(struct tg3 *tp, int loopback_mode) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10751 | { |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10752 | u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key; |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10753 | u32 desc_idx, coal_now; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10754 | struct sk_buff *skb, *rx_skb; |
| 10755 | u8 *tx_data; |
| 10756 | dma_addr_t map; |
| 10757 | int num_pkts, tx_len, rx_len, i, err; |
| 10758 | struct tg3_rx_buffer_desc *desc; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10759 | struct tg3_napi *tnapi, *rnapi; |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 10760 | struct tg3_rx_prodring_set *tpr = &tp->prodring[0]; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10761 | |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 10762 | tnapi = &tp->napi[0]; |
| 10763 | rnapi = &tp->napi[0]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 10764 | if (tp->irq_cnt > 1) { |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 10765 | rnapi = &tp->napi[1]; |
Matt Carlson | c887340 | 2010-02-12 14:47:11 +0000 | [diff] [blame] | 10766 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
| 10767 | tnapi = &tp->napi[1]; |
Matt Carlson | 0c1d0e2 | 2009-09-01 13:16:33 +0000 | [diff] [blame] | 10768 | } |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10769 | coal_now = tnapi->coal_now | rnapi->coal_now; |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10770 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10771 | if (loopback_mode == TG3_MAC_LOOPBACK) { |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10772 | /* HW errata - mac loopback fails in some cases on 5780. |
| 10773 | * Normal traffic and PHY loopback are not affected by |
| 10774 | * errata. |
| 10775 | */ |
| 10776 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) |
| 10777 | return 0; |
| 10778 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10779 | mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10780 | MAC_MODE_PORT_INT_LPBACK; |
| 10781 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 10782 | mac_mode |= MAC_MODE_LINK_POLARITY; |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10783 | if (tp->tg3_flags & TG3_FLAG_10_100_ONLY) |
| 10784 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 10785 | else |
| 10786 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10787 | tw32(MAC_MODE, mac_mode); |
| 10788 | } else if (loopback_mode == TG3_PHY_LOOPBACK) { |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10789 | u32 val; |
| 10790 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 10791 | if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) { |
| 10792 | tg3_phy_fet_toggle_apd(tp, false); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 10793 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100; |
| 10794 | } else |
| 10795 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000; |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10796 | |
Matt Carlson | 9ef8ca9 | 2007-07-11 19:48:29 -0700 | [diff] [blame] | 10797 | tg3_phy_toggle_automdix(tp, 0); |
| 10798 | |
Michael Chan | 3f7045c | 2006-09-27 16:02:29 -0700 | [diff] [blame] | 10799 | tg3_writephy(tp, MII_BMCR, val); |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10800 | udelay(40); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 10801 | |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10802 | mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 10803 | if (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) { |
Matt Carlson | 1061b7c | 2010-02-12 14:47:12 +0000 | [diff] [blame] | 10804 | tg3_writephy(tp, MII_TG3_FET_PTEST, |
| 10805 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
| 10806 | MII_TG3_FET_PTEST_FRC_TX_LOCK); |
| 10807 | /* The write needs to be flushed for the AC131 */ |
| 10808 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 10809 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); |
Michael Chan | 5d64ad3 | 2006-12-07 00:19:40 -0800 | [diff] [blame] | 10810 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 10811 | } else |
| 10812 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 10813 | |
Michael Chan | c94e394 | 2005-09-27 12:12:42 -0700 | [diff] [blame] | 10814 | /* reset to prevent losing 1st rx packet intermittently */ |
| 10815 | if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) { |
| 10816 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 10817 | udelay(10); |
| 10818 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 10819 | } |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10820 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 10821 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
| 10822 | if (masked_phy_id == TG3_PHY_ID_BCM5401) |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10823 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 10824 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
Matt Carlson | e8f3f6c | 2007-07-11 19:47:55 -0700 | [diff] [blame] | 10825 | mac_mode |= MAC_MODE_LINK_POLARITY; |
Michael Chan | ff18ff0 | 2006-03-27 23:17:27 -0800 | [diff] [blame] | 10826 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 10827 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 10828 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10829 | tw32(MAC_MODE, mac_mode); |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10830 | } |
| 10831 | else |
| 10832 | return -EINVAL; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10833 | |
| 10834 | err = -EIO; |
| 10835 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10836 | tx_len = 1514; |
David S. Miller | a20e9c6 | 2006-07-31 22:38:16 -0700 | [diff] [blame] | 10837 | skb = netdev_alloc_skb(tp->dev, tx_len); |
Jesper Juhl | a50bb7b | 2006-05-09 23:14:35 -0700 | [diff] [blame] | 10838 | if (!skb) |
| 10839 | return -ENOMEM; |
| 10840 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10841 | tx_data = skb_put(skb, tx_len); |
| 10842 | memcpy(tx_data, tp->dev->dev_addr, 6); |
| 10843 | memset(tx_data + 6, 0x0, 8); |
| 10844 | |
| 10845 | tw32(MAC_RX_MTU_SIZE, tx_len + 4); |
| 10846 | |
| 10847 | for (i = 14; i < tx_len; i++) |
| 10848 | tx_data[i] = (u8) (i & 0xff); |
| 10849 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 10850 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
| 10851 | if (pci_dma_mapping_error(tp->pdev, map)) { |
Matt Carlson | a21771d | 2009-11-02 14:25:31 +0000 | [diff] [blame] | 10852 | dev_kfree_skb(skb); |
| 10853 | return -EIO; |
| 10854 | } |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10855 | |
| 10856 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10857 | rnapi->coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10858 | |
| 10859 | udelay(10); |
| 10860 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10861 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10862 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10863 | num_pkts = 0; |
| 10864 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 10865 | tg3_set_txd(tnapi, tnapi->tx_prod, map, tx_len, 0, 1); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10866 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10867 | tnapi->tx_prod++; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10868 | num_pkts++; |
| 10869 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10870 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 10871 | tr32_mailbox(tnapi->prodmbox); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10872 | |
| 10873 | udelay(10); |
| 10874 | |
Matt Carlson | 303fc92 | 2009-11-02 14:27:34 +0000 | [diff] [blame] | 10875 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
| 10876 | for (i = 0; i < 35; i++) { |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10877 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
Matt Carlson | fd2ce37 | 2009-09-01 12:51:13 +0000 | [diff] [blame] | 10878 | coal_now); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10879 | |
| 10880 | udelay(10); |
| 10881 | |
Matt Carlson | 898a56f | 2009-08-28 14:02:40 +0000 | [diff] [blame] | 10882 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 10883 | rx_idx = rnapi->hw_status->idx[0].rx_producer; |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10884 | if ((tx_idx == tnapi->tx_prod) && |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10885 | (rx_idx == (rx_start_idx + num_pkts))) |
| 10886 | break; |
| 10887 | } |
| 10888 | |
Alexander Duyck | f4188d8 | 2009-12-02 16:48:38 +0000 | [diff] [blame] | 10889 | pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10890 | dev_kfree_skb(skb); |
| 10891 | |
Matt Carlson | f3f3f27 | 2009-08-28 14:03:21 +0000 | [diff] [blame] | 10892 | if (tx_idx != tnapi->tx_prod) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10893 | goto out; |
| 10894 | |
| 10895 | if (rx_idx != rx_start_idx + num_pkts) |
| 10896 | goto out; |
| 10897 | |
Matt Carlson | 7233448 | 2009-08-28 14:03:01 +0000 | [diff] [blame] | 10898 | desc = &rnapi->rx_rcb[rx_start_idx]; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10899 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 10900 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 10901 | if (opaque_key != RXD_OPAQUE_RING_STD) |
| 10902 | goto out; |
| 10903 | |
| 10904 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 10905 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) |
| 10906 | goto out; |
| 10907 | |
| 10908 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; |
| 10909 | if (rx_len != tx_len) |
| 10910 | goto out; |
| 10911 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 10912 | rx_skb = tpr->rx_std_buffers[desc_idx].skb; |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10913 | |
Matt Carlson | 21f581a | 2009-08-28 14:00:25 +0000 | [diff] [blame] | 10914 | map = pci_unmap_addr(&tpr->rx_std_buffers[desc_idx], mapping); |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10915 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE); |
| 10916 | |
| 10917 | for (i = 14; i < tx_len; i++) { |
| 10918 | if (*(rx_skb->data + i) != (u8) (i & 0xff)) |
| 10919 | goto out; |
| 10920 | } |
| 10921 | err = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 10922 | |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 10923 | /* tg3_free_rings will unmap and free the rx_skb */ |
| 10924 | out: |
| 10925 | return err; |
| 10926 | } |
| 10927 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10928 | #define TG3_MAC_LOOPBACK_FAILED 1 |
| 10929 | #define TG3_PHY_LOOPBACK_FAILED 2 |
| 10930 | #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \ |
| 10931 | TG3_PHY_LOOPBACK_FAILED) |
| 10932 | |
| 10933 | static int tg3_test_loopback(struct tg3 *tp) |
| 10934 | { |
| 10935 | int err = 0; |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 10936 | u32 cpmuctrl = 0; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10937 | |
| 10938 | if (!netif_running(tp->dev)) |
| 10939 | return TG3_LOOPBACK_FAILED; |
| 10940 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 10941 | err = tg3_reset_hw(tp, 1); |
| 10942 | if (err) |
| 10943 | return TG3_LOOPBACK_FAILED; |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10944 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 10945 | /* Turn off gphy autopowerdown. */ |
| 10946 | if (tp->tg3_flags3 & TG3_FLG3_PHY_ENABLE_APD) |
| 10947 | tg3_phy_toggle_apd(tp, false); |
| 10948 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10949 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 10950 | int i; |
| 10951 | u32 status; |
| 10952 | |
| 10953 | tw32(TG3_CPMU_MUTEX_REQ, CPMU_MUTEX_REQ_DRIVER); |
| 10954 | |
| 10955 | /* Wait for up to 40 microseconds to acquire lock. */ |
| 10956 | for (i = 0; i < 4; i++) { |
| 10957 | status = tr32(TG3_CPMU_MUTEX_GNT); |
| 10958 | if (status == CPMU_MUTEX_GNT_DRIVER) |
| 10959 | break; |
| 10960 | udelay(10); |
| 10961 | } |
| 10962 | |
| 10963 | if (status != CPMU_MUTEX_GNT_DRIVER) |
| 10964 | return TG3_LOOPBACK_FAILED; |
| 10965 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 10966 | /* Turn off link-based power management. */ |
Matt Carlson | e875093 | 2007-11-12 21:11:51 -0800 | [diff] [blame] | 10967 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
Matt Carlson | 109115e | 2008-05-02 16:48:59 -0700 | [diff] [blame] | 10968 | tw32(TG3_CPMU_CTRL, |
| 10969 | cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE | |
| 10970 | CPMU_CTRL_LINK_AWARE_MODE)); |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 10971 | } |
| 10972 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10973 | if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK)) |
| 10974 | err |= TG3_MAC_LOOPBACK_FAILED; |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 10975 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 10976 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) { |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 10977 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 10978 | |
| 10979 | /* Release the mutex */ |
| 10980 | tw32(TG3_CPMU_MUTEX_GNT, CPMU_MUTEX_GNT_DRIVER); |
| 10981 | } |
| 10982 | |
Matt Carlson | dd47700 | 2008-05-25 23:45:58 -0700 | [diff] [blame] | 10983 | if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) && |
| 10984 | !(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)) { |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10985 | if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK)) |
| 10986 | err |= TG3_PHY_LOOPBACK_FAILED; |
| 10987 | } |
| 10988 | |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 10989 | /* Re-enable gphy autopowerdown. */ |
| 10990 | if (tp->tg3_flags3 & TG3_FLG3_PHY_ENABLE_APD) |
| 10991 | tg3_phy_toggle_apd(tp, true); |
| 10992 | |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 10993 | return err; |
| 10994 | } |
| 10995 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 10996 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
| 10997 | u64 *data) |
| 10998 | { |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 10999 | struct tg3 *tp = netdev_priv(dev); |
| 11000 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11001 | if (tp->link_config.phy_is_low_power) |
| 11002 | tg3_set_power_state(tp, PCI_D0); |
| 11003 | |
Michael Chan | 566f86a | 2005-05-29 14:56:58 -0700 | [diff] [blame] | 11004 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
| 11005 | |
| 11006 | if (tg3_test_nvram(tp) != 0) { |
| 11007 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11008 | data[0] = 1; |
| 11009 | } |
Michael Chan | ca43007 | 2005-05-29 14:57:23 -0700 | [diff] [blame] | 11010 | if (tg3_test_link(tp) != 0) { |
| 11011 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11012 | data[1] = 1; |
| 11013 | } |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11014 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11015 | int err, err2 = 0, irq_sync = 0; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11016 | |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11017 | if (netif_running(dev)) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11018 | tg3_phy_stop(tp); |
Michael Chan | bbe832c | 2005-06-24 20:20:04 -0700 | [diff] [blame] | 11019 | tg3_netif_stop(tp); |
| 11020 | irq_sync = 1; |
| 11021 | } |
| 11022 | |
| 11023 | tg3_full_lock(tp, irq_sync); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11024 | |
| 11025 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11026 | err = tg3_nvram_lock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11027 | tg3_halt_cpu(tp, RX_CPU_BASE); |
| 11028 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 11029 | tg3_halt_cpu(tp, TX_CPU_BASE); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11030 | if (!err) |
| 11031 | tg3_nvram_unlock(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11032 | |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 11033 | if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) |
| 11034 | tg3_phy_reset(tp); |
| 11035 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11036 | if (tg3_test_registers(tp) != 0) { |
| 11037 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11038 | data[2] = 1; |
| 11039 | } |
Michael Chan | 7942e1d | 2005-05-29 14:58:36 -0700 | [diff] [blame] | 11040 | if (tg3_test_memory(tp) != 0) { |
| 11041 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11042 | data[3] = 1; |
| 11043 | } |
Michael Chan | 9f40dea | 2005-09-05 17:53:06 -0700 | [diff] [blame] | 11044 | if ((data[4] = tg3_test_loopback(tp)) != 0) |
Michael Chan | c76949a | 2005-05-29 14:58:59 -0700 | [diff] [blame] | 11045 | etest->flags |= ETH_TEST_FL_FAILED; |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11046 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11047 | tg3_full_unlock(tp); |
| 11048 | |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 11049 | if (tg3_test_interrupt(tp) != 0) { |
| 11050 | etest->flags |= ETH_TEST_FL_FAILED; |
| 11051 | data[5] = 1; |
| 11052 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11053 | |
| 11054 | tg3_full_lock(tp, 0); |
Michael Chan | d4bc392 | 2005-05-29 14:59:20 -0700 | [diff] [blame] | 11055 | |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11056 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11057 | if (netif_running(dev)) { |
| 11058 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11059 | err2 = tg3_restart_hw(tp, 1); |
| 11060 | if (!err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 11061 | tg3_netif_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11062 | } |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11063 | |
| 11064 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11065 | |
| 11066 | if (irq_sync && !err2) |
| 11067 | tg3_phy_start(tp); |
Michael Chan | a71116d | 2005-05-29 14:58:11 -0700 | [diff] [blame] | 11068 | } |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11069 | if (tp->link_config.phy_is_low_power) |
| 11070 | tg3_set_power_state(tp, PCI_D3hot); |
| 11071 | |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11072 | } |
| 11073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11074 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 11075 | { |
| 11076 | struct mii_ioctl_data *data = if_mii(ifr); |
| 11077 | struct tg3 *tp = netdev_priv(dev); |
| 11078 | int err; |
| 11079 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11080 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11081 | struct phy_device *phydev; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11082 | if (!(tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED)) |
| 11083 | return -EAGAIN; |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 11084 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
| 11085 | return phy_mii_ioctl(phydev, data, cmd); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 11086 | } |
| 11087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11088 | switch(cmd) { |
| 11089 | case SIOCGMIIPHY: |
Matt Carlson | 882e979 | 2009-09-01 13:21:36 +0000 | [diff] [blame] | 11090 | data->phy_id = tp->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11091 | |
| 11092 | /* fallthru */ |
| 11093 | case SIOCGMIIREG: { |
| 11094 | u32 mii_regval; |
| 11095 | |
| 11096 | if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) |
| 11097 | break; /* We have no PHY */ |
| 11098 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11099 | if (tp->link_config.phy_is_low_power) |
| 11100 | return -EAGAIN; |
| 11101 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11102 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11103 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11104 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11105 | |
| 11106 | data->val_out = mii_regval; |
| 11107 | |
| 11108 | return err; |
| 11109 | } |
| 11110 | |
| 11111 | case SIOCSMIIREG: |
| 11112 | if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) |
| 11113 | break; /* We have no PHY */ |
| 11114 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 11115 | if (tp->link_config.phy_is_low_power) |
| 11116 | return -EAGAIN; |
| 11117 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11118 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11119 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11120 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11121 | |
| 11122 | return err; |
| 11123 | |
| 11124 | default: |
| 11125 | /* do nothing */ |
| 11126 | break; |
| 11127 | } |
| 11128 | return -EOPNOTSUPP; |
| 11129 | } |
| 11130 | |
| 11131 | #if TG3_VLAN_TAG_USED |
| 11132 | static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) |
| 11133 | { |
| 11134 | struct tg3 *tp = netdev_priv(dev); |
| 11135 | |
Matt Carlson | 844b3ee | 2009-02-25 14:23:56 +0000 | [diff] [blame] | 11136 | if (!netif_running(dev)) { |
| 11137 | tp->vlgrp = grp; |
| 11138 | return; |
| 11139 | } |
| 11140 | |
| 11141 | tg3_netif_stop(tp); |
Michael Chan | 29315e8 | 2006-06-29 20:12:30 -0700 | [diff] [blame] | 11142 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 11143 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11144 | |
| 11145 | tp->vlgrp = grp; |
| 11146 | |
| 11147 | /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */ |
| 11148 | __tg3_set_rx_mode(dev); |
| 11149 | |
Matt Carlson | 844b3ee | 2009-02-25 14:23:56 +0000 | [diff] [blame] | 11150 | tg3_netif_start(tp); |
Michael Chan | 4696654 | 2007-07-11 19:47:19 -0700 | [diff] [blame] | 11151 | |
| 11152 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11153 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11154 | #endif |
| 11155 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 11156 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 11157 | { |
| 11158 | struct tg3 *tp = netdev_priv(dev); |
| 11159 | |
| 11160 | memcpy(ec, &tp->coal, sizeof(*ec)); |
| 11161 | return 0; |
| 11162 | } |
| 11163 | |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 11164 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 11165 | { |
| 11166 | struct tg3 *tp = netdev_priv(dev); |
| 11167 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; |
| 11168 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; |
| 11169 | |
| 11170 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
| 11171 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
| 11172 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; |
| 11173 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; |
| 11174 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; |
| 11175 | } |
| 11176 | |
| 11177 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || |
| 11178 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || |
| 11179 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || |
| 11180 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || |
| 11181 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || |
| 11182 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || |
| 11183 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || |
| 11184 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || |
| 11185 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || |
| 11186 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) |
| 11187 | return -EINVAL; |
| 11188 | |
| 11189 | /* No rx interrupts will be generated if both are zero */ |
| 11190 | if ((ec->rx_coalesce_usecs == 0) && |
| 11191 | (ec->rx_max_coalesced_frames == 0)) |
| 11192 | return -EINVAL; |
| 11193 | |
| 11194 | /* No tx interrupts will be generated if both are zero */ |
| 11195 | if ((ec->tx_coalesce_usecs == 0) && |
| 11196 | (ec->tx_max_coalesced_frames == 0)) |
| 11197 | return -EINVAL; |
| 11198 | |
| 11199 | /* Only copy relevant parameters, ignore all others. */ |
| 11200 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; |
| 11201 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; |
| 11202 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; |
| 11203 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; |
| 11204 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; |
| 11205 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; |
| 11206 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; |
| 11207 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; |
| 11208 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; |
| 11209 | |
| 11210 | if (netif_running(dev)) { |
| 11211 | tg3_full_lock(tp, 0); |
| 11212 | __tg3_set_coalesce(tp, &tp->coal); |
| 11213 | tg3_full_unlock(tp); |
| 11214 | } |
| 11215 | return 0; |
| 11216 | } |
| 11217 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 11218 | static const struct ethtool_ops tg3_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11219 | .get_settings = tg3_get_settings, |
| 11220 | .set_settings = tg3_set_settings, |
| 11221 | .get_drvinfo = tg3_get_drvinfo, |
| 11222 | .get_regs_len = tg3_get_regs_len, |
| 11223 | .get_regs = tg3_get_regs, |
| 11224 | .get_wol = tg3_get_wol, |
| 11225 | .set_wol = tg3_set_wol, |
| 11226 | .get_msglevel = tg3_get_msglevel, |
| 11227 | .set_msglevel = tg3_set_msglevel, |
| 11228 | .nway_reset = tg3_nway_reset, |
| 11229 | .get_link = ethtool_op_get_link, |
| 11230 | .get_eeprom_len = tg3_get_eeprom_len, |
| 11231 | .get_eeprom = tg3_get_eeprom, |
| 11232 | .set_eeprom = tg3_set_eeprom, |
| 11233 | .get_ringparam = tg3_get_ringparam, |
| 11234 | .set_ringparam = tg3_set_ringparam, |
| 11235 | .get_pauseparam = tg3_get_pauseparam, |
| 11236 | .set_pauseparam = tg3_set_pauseparam, |
| 11237 | .get_rx_csum = tg3_get_rx_csum, |
| 11238 | .set_rx_csum = tg3_set_rx_csum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11239 | .set_tx_csum = tg3_set_tx_csum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11240 | .set_sg = ethtool_op_set_sg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11241 | .set_tso = tg3_set_tso, |
Michael Chan | 4cafd3f | 2005-05-29 14:56:34 -0700 | [diff] [blame] | 11242 | .self_test = tg3_self_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11243 | .get_strings = tg3_get_strings, |
Michael Chan | 4009a93 | 2005-09-05 17:52:54 -0700 | [diff] [blame] | 11244 | .phys_id = tg3_phys_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11245 | .get_ethtool_stats = tg3_get_ethtool_stats, |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 11246 | .get_coalesce = tg3_get_coalesce, |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 11247 | .set_coalesce = tg3_set_coalesce, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 11248 | .get_sset_count = tg3_get_sset_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11249 | }; |
| 11250 | |
| 11251 | static void __devinit tg3_get_eeprom_size(struct tg3 *tp) |
| 11252 | { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11253 | u32 cursize, val, magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11254 | |
| 11255 | tp->nvram_size = EEPROM_CHIP_SIZE; |
| 11256 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11257 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11258 | return; |
| 11259 | |
Michael Chan | b16250e | 2006-09-27 16:10:14 -0700 | [diff] [blame] | 11260 | if ((magic != TG3_EEPROM_MAGIC) && |
| 11261 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && |
| 11262 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11263 | return; |
| 11264 | |
| 11265 | /* |
| 11266 | * Size the chip by reading offsets at increasing powers of two. |
| 11267 | * When we encounter our validation signature, we know the addressing |
| 11268 | * has wrapped around, and thus have our chip size. |
| 11269 | */ |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11270 | cursize = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11271 | |
| 11272 | while (cursize < tp->nvram_size) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 11273 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11274 | return; |
| 11275 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 11276 | if (val == magic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11277 | break; |
| 11278 | |
| 11279 | cursize <<= 1; |
| 11280 | } |
| 11281 | |
| 11282 | tp->nvram_size = cursize; |
| 11283 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11285 | static void __devinit tg3_get_nvram_size(struct tg3 *tp) |
| 11286 | { |
| 11287 | u32 val; |
| 11288 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11289 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
| 11290 | tg3_nvram_read(tp, 0, &val) != 0) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11291 | return; |
| 11292 | |
| 11293 | /* Selfboot format */ |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 11294 | if (val != TG3_EEPROM_MAGIC) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11295 | tg3_get_eeprom_size(tp); |
| 11296 | return; |
| 11297 | } |
| 11298 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 11299 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11300 | if (val != 0) { |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 11301 | /* This is confusing. We want to operate on the |
| 11302 | * 16-bit value at offset 0xf2. The tg3_nvram_read() |
| 11303 | * call will read from NVRAM and byteswap the data |
| 11304 | * according to the byteswapping settings for all |
| 11305 | * other register accesses. This ensures the data we |
| 11306 | * want will always reside in the lower 16-bits. |
| 11307 | * However, the data in NVRAM is in LE format, which |
| 11308 | * means the data from the NVRAM read will always be |
| 11309 | * opposite the endianness of the CPU. The 16-bit |
| 11310 | * byteswap then brings the data to CPU endianness. |
| 11311 | */ |
| 11312 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11313 | return; |
| 11314 | } |
| 11315 | } |
Matt Carlson | fd1122a | 2008-05-02 16:48:36 -0700 | [diff] [blame] | 11316 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11317 | } |
| 11318 | |
| 11319 | static void __devinit tg3_get_nvram_info(struct tg3 *tp) |
| 11320 | { |
| 11321 | u32 nvcfg1; |
| 11322 | |
| 11323 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11324 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { |
| 11325 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11326 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11327 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11328 | tw32(NVRAM_CFG1, nvcfg1); |
| 11329 | } |
| 11330 | |
Michael Chan | 4c98748 | 2005-09-05 17:52:38 -0700 | [diff] [blame] | 11331 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) || |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 11332 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11333 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11334 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
| 11335 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11336 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
| 11337 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11338 | break; |
| 11339 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: |
| 11340 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11341 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; |
| 11342 | break; |
| 11343 | case FLASH_VENDOR_ATMEL_EEPROM: |
| 11344 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11345 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11346 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11347 | break; |
| 11348 | case FLASH_VENDOR_ST: |
| 11349 | tp->nvram_jedecnum = JEDEC_ST; |
| 11350 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; |
| 11351 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11352 | break; |
| 11353 | case FLASH_VENDOR_SAIFUN: |
| 11354 | tp->nvram_jedecnum = JEDEC_SAIFUN; |
| 11355 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; |
| 11356 | break; |
| 11357 | case FLASH_VENDOR_SST_SMALL: |
| 11358 | case FLASH_VENDOR_SST_LARGE: |
| 11359 | tp->nvram_jedecnum = JEDEC_SST; |
| 11360 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; |
| 11361 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11362 | } |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11363 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11364 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11365 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
| 11366 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11367 | } |
| 11368 | } |
| 11369 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11370 | static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
| 11371 | { |
| 11372 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { |
| 11373 | case FLASH_5752PAGE_SIZE_256: |
| 11374 | tp->nvram_pagesize = 256; |
| 11375 | break; |
| 11376 | case FLASH_5752PAGE_SIZE_512: |
| 11377 | tp->nvram_pagesize = 512; |
| 11378 | break; |
| 11379 | case FLASH_5752PAGE_SIZE_1K: |
| 11380 | tp->nvram_pagesize = 1024; |
| 11381 | break; |
| 11382 | case FLASH_5752PAGE_SIZE_2K: |
| 11383 | tp->nvram_pagesize = 2048; |
| 11384 | break; |
| 11385 | case FLASH_5752PAGE_SIZE_4K: |
| 11386 | tp->nvram_pagesize = 4096; |
| 11387 | break; |
| 11388 | case FLASH_5752PAGE_SIZE_264: |
| 11389 | tp->nvram_pagesize = 264; |
| 11390 | break; |
| 11391 | case FLASH_5752PAGE_SIZE_528: |
| 11392 | tp->nvram_pagesize = 528; |
| 11393 | break; |
| 11394 | } |
| 11395 | } |
| 11396 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11397 | static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp) |
| 11398 | { |
| 11399 | u32 nvcfg1; |
| 11400 | |
| 11401 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11402 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11403 | /* NVRAM protection for TPM */ |
| 11404 | if (nvcfg1 & (1 << 27)) |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 11405 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11406 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11407 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11408 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
| 11409 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: |
| 11410 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11411 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11412 | break; |
| 11413 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11414 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11415 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11416 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11417 | break; |
| 11418 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11419 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11420 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11421 | tp->nvram_jedecnum = JEDEC_ST; |
| 11422 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11423 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11424 | break; |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11425 | } |
| 11426 | |
| 11427 | if (tp->tg3_flags2 & TG3_FLG2_FLASH) { |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11428 | tg3_nvram_get_pagesize(tp, nvcfg1); |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11429 | } else { |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11430 | /* For eeprom, set pagesize to maximum eeprom size */ |
| 11431 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11432 | |
| 11433 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11434 | tw32(NVRAM_CFG1, nvcfg1); |
| 11435 | } |
| 11436 | } |
| 11437 | |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11438 | static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp) |
| 11439 | { |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11440 | u32 nvcfg1, protect = 0; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11441 | |
| 11442 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11443 | |
| 11444 | /* NVRAM protection for TPM */ |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11445 | if (nvcfg1 & (1 << 27)) { |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 11446 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11447 | protect = 1; |
| 11448 | } |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11449 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11450 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 11451 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11452 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 11453 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 11454 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 11455 | case FLASH_5755VENDOR_ATMEL_FLASH_5: |
| 11456 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11457 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11458 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11459 | tp->nvram_pagesize = 264; |
| 11460 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || |
| 11461 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) |
| 11462 | tp->nvram_size = (protect ? 0x3e200 : |
| 11463 | TG3_NVRAM_SIZE_512KB); |
| 11464 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) |
| 11465 | tp->nvram_size = (protect ? 0x1f200 : |
| 11466 | TG3_NVRAM_SIZE_256KB); |
| 11467 | else |
| 11468 | tp->nvram_size = (protect ? 0x1f200 : |
| 11469 | TG3_NVRAM_SIZE_128KB); |
| 11470 | break; |
| 11471 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11472 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11473 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11474 | tp->nvram_jedecnum = JEDEC_ST; |
| 11475 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11476 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11477 | tp->nvram_pagesize = 256; |
| 11478 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) |
| 11479 | tp->nvram_size = (protect ? |
| 11480 | TG3_NVRAM_SIZE_64KB : |
| 11481 | TG3_NVRAM_SIZE_128KB); |
| 11482 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) |
| 11483 | tp->nvram_size = (protect ? |
| 11484 | TG3_NVRAM_SIZE_64KB : |
| 11485 | TG3_NVRAM_SIZE_256KB); |
| 11486 | else |
| 11487 | tp->nvram_size = (protect ? |
| 11488 | TG3_NVRAM_SIZE_128KB : |
| 11489 | TG3_NVRAM_SIZE_512KB); |
| 11490 | break; |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11491 | } |
| 11492 | } |
| 11493 | |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11494 | static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) |
| 11495 | { |
| 11496 | u32 nvcfg1; |
| 11497 | |
| 11498 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11499 | |
| 11500 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11501 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
| 11502 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 11503 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: |
| 11504 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 11505 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11506 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11507 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11508 | |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11509 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11510 | tw32(NVRAM_CFG1, nvcfg1); |
| 11511 | break; |
| 11512 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11513 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 11514 | case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 11515 | case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 11516 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11517 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11518 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11519 | tp->nvram_pagesize = 264; |
| 11520 | break; |
| 11521 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11522 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11523 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11524 | tp->nvram_jedecnum = JEDEC_ST; |
| 11525 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11526 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11527 | tp->nvram_pagesize = 256; |
| 11528 | break; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11529 | } |
| 11530 | } |
| 11531 | |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11532 | static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp) |
| 11533 | { |
| 11534 | u32 nvcfg1, protect = 0; |
| 11535 | |
| 11536 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11537 | |
| 11538 | /* NVRAM protection for TPM */ |
| 11539 | if (nvcfg1 & (1 << 27)) { |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 11540 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11541 | protect = 1; |
| 11542 | } |
| 11543 | |
| 11544 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 11545 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11546 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 11547 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 11548 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 11549 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 11550 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 11551 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 11552 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 11553 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 11554 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11555 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11556 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11557 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; |
| 11558 | tp->nvram_pagesize = 256; |
| 11559 | break; |
| 11560 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 11561 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 11562 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 11563 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 11564 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 11565 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 11566 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 11567 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 11568 | tp->nvram_jedecnum = JEDEC_ST; |
| 11569 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11570 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11571 | tp->nvram_pagesize = 256; |
| 11572 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11573 | } |
| 11574 | |
| 11575 | if (protect) { |
| 11576 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); |
| 11577 | } else { |
| 11578 | switch (nvcfg1) { |
Matt Carlson | 8590a60 | 2009-08-28 12:29:16 +0000 | [diff] [blame] | 11579 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 11580 | case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 11581 | case FLASH_5761VENDOR_ST_A_M45PE16: |
| 11582 | case FLASH_5761VENDOR_ST_M_M45PE16: |
| 11583 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; |
| 11584 | break; |
| 11585 | case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 11586 | case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 11587 | case FLASH_5761VENDOR_ST_A_M45PE80: |
| 11588 | case FLASH_5761VENDOR_ST_M_M45PE80: |
| 11589 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 11590 | break; |
| 11591 | case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 11592 | case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 11593 | case FLASH_5761VENDOR_ST_A_M45PE40: |
| 11594 | case FLASH_5761VENDOR_ST_M_M45PE40: |
| 11595 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11596 | break; |
| 11597 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 11598 | case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 11599 | case FLASH_5761VENDOR_ST_A_M45PE20: |
| 11600 | case FLASH_5761VENDOR_ST_M_M45PE20: |
| 11601 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11602 | break; |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11603 | } |
| 11604 | } |
| 11605 | } |
| 11606 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 11607 | static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp) |
| 11608 | { |
| 11609 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11610 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11611 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11612 | } |
| 11613 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11614 | static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp) |
| 11615 | { |
| 11616 | u32 nvcfg1; |
| 11617 | |
| 11618 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11619 | |
| 11620 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11621 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 11622 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 11623 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11624 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11625 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11626 | |
| 11627 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11628 | tw32(NVRAM_CFG1, nvcfg1); |
| 11629 | return; |
| 11630 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11631 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 11632 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 11633 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 11634 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 11635 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 11636 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 11637 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11638 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11639 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11640 | |
| 11641 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11642 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 11643 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 11644 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 11645 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11646 | break; |
| 11647 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 11648 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 11649 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11650 | break; |
| 11651 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 11652 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 11653 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11654 | break; |
| 11655 | } |
| 11656 | break; |
| 11657 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11658 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11659 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11660 | tp->nvram_jedecnum = JEDEC_ST; |
| 11661 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11662 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11663 | |
| 11664 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11665 | case FLASH_5752VENDOR_ST_M45PE10: |
| 11666 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11667 | break; |
| 11668 | case FLASH_5752VENDOR_ST_M45PE20: |
| 11669 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11670 | break; |
| 11671 | case FLASH_5752VENDOR_ST_M45PE40: |
| 11672 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 11673 | break; |
| 11674 | } |
| 11675 | break; |
| 11676 | default: |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 11677 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11678 | return; |
| 11679 | } |
| 11680 | |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11681 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 11682 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11683 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11684 | } |
| 11685 | |
| 11686 | |
| 11687 | static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp) |
| 11688 | { |
| 11689 | u32 nvcfg1; |
| 11690 | |
| 11691 | nvcfg1 = tr32(NVRAM_CFG1); |
| 11692 | |
| 11693 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11694 | case FLASH_5717VENDOR_ATMEL_EEPROM: |
| 11695 | case FLASH_5717VENDOR_MICRO_EEPROM: |
| 11696 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11697 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11698 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 11699 | |
| 11700 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 11701 | tw32(NVRAM_CFG1, nvcfg1); |
| 11702 | return; |
| 11703 | case FLASH_5717VENDOR_ATMEL_MDB011D: |
| 11704 | case FLASH_5717VENDOR_ATMEL_ADB011B: |
| 11705 | case FLASH_5717VENDOR_ATMEL_ADB011D: |
| 11706 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 11707 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 11708 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 11709 | case FLASH_5717VENDOR_ATMEL_45USPT: |
| 11710 | tp->nvram_jedecnum = JEDEC_ATMEL; |
| 11711 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11712 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11713 | |
| 11714 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11715 | case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 11716 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 11717 | case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 11718 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11719 | break; |
| 11720 | default: |
| 11721 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11722 | break; |
| 11723 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11724 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11725 | case FLASH_5717VENDOR_ST_M_M25PE10: |
| 11726 | case FLASH_5717VENDOR_ST_A_M25PE10: |
| 11727 | case FLASH_5717VENDOR_ST_M_M45PE10: |
| 11728 | case FLASH_5717VENDOR_ST_A_M45PE10: |
| 11729 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 11730 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 11731 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 11732 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 11733 | case FLASH_5717VENDOR_ST_25USPT: |
| 11734 | case FLASH_5717VENDOR_ST_45USPT: |
| 11735 | tp->nvram_jedecnum = JEDEC_ST; |
| 11736 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; |
| 11737 | tp->tg3_flags2 |= TG3_FLG2_FLASH; |
| 11738 | |
| 11739 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 11740 | case FLASH_5717VENDOR_ST_M_M25PE20: |
| 11741 | case FLASH_5717VENDOR_ST_A_M25PE20: |
| 11742 | case FLASH_5717VENDOR_ST_M_M45PE20: |
| 11743 | case FLASH_5717VENDOR_ST_A_M45PE20: |
| 11744 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 11745 | break; |
| 11746 | default: |
| 11747 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 11748 | break; |
| 11749 | } |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11750 | break; |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11751 | default: |
| 11752 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM; |
| 11753 | return; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11754 | } |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11755 | |
| 11756 | tg3_nvram_get_pagesize(tp, nvcfg1); |
| 11757 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
| 11758 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11759 | } |
| 11760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11761 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
| 11762 | static void __devinit tg3_nvram_init(struct tg3 *tp) |
| 11763 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11764 | tw32_f(GRC_EEPROM_ADDR, |
| 11765 | (EEPROM_ADDR_FSM_RESET | |
| 11766 | (EEPROM_DEFAULT_CLOCK_PERIOD << |
| 11767 | EEPROM_ADDR_CLKPERD_SHIFT))); |
| 11768 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 11769 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11770 | |
| 11771 | /* Enable seeprom accesses. */ |
| 11772 | tw32_f(GRC_LOCAL_CTRL, |
| 11773 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); |
| 11774 | udelay(100); |
| 11775 | |
| 11776 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 11777 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { |
| 11778 | tp->tg3_flags |= TG3_FLAG_NVRAM; |
| 11779 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11780 | if (tg3_nvram_lock(tp)) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 11781 | netdev_warn(tp->dev, "Cannot get nvram lock, %s failed\n", |
| 11782 | __func__); |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 11783 | return; |
| 11784 | } |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11785 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11786 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11787 | tp->nvram_size = 0; |
| 11788 | |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11789 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 11790 | tg3_get_5752_nvram_info(tp); |
Michael Chan | d3c7b88 | 2006-03-23 01:28:25 -0800 | [diff] [blame] | 11791 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 11792 | tg3_get_5755_nvram_info(tp); |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 11793 | 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] | 11794 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 11795 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 11796 | tg3_get_5787_nvram_info(tp); |
Matt Carlson | 6b91fa0 | 2007-10-10 18:01:09 -0700 | [diff] [blame] | 11797 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
| 11798 | tg3_get_5761_nvram_info(tp); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 11799 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 11800 | tg3_get_5906_nvram_info(tp); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 11801 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 11802 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11803 | tg3_get_57780_nvram_info(tp); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 11804 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
| 11805 | tg3_get_5717_nvram_info(tp); |
Michael Chan | 361b4ac | 2005-04-21 17:11:21 -0700 | [diff] [blame] | 11806 | else |
| 11807 | tg3_get_nvram_info(tp); |
| 11808 | |
Matt Carlson | 989a9d2 | 2007-05-05 11:51:05 -0700 | [diff] [blame] | 11809 | if (tp->nvram_size == 0) |
| 11810 | tg3_get_nvram_size(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11811 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11812 | tg3_disable_nvram_access(tp); |
Michael Chan | 381291b | 2005-12-13 21:08:21 -0800 | [diff] [blame] | 11813 | tg3_nvram_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11814 | |
| 11815 | } else { |
| 11816 | tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED); |
| 11817 | |
| 11818 | tg3_get_eeprom_size(tp); |
| 11819 | } |
| 11820 | } |
| 11821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11822 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
| 11823 | u32 offset, u32 len, u8 *buf) |
| 11824 | { |
| 11825 | int i, j, rc = 0; |
| 11826 | u32 val; |
| 11827 | |
| 11828 | for (i = 0; i < len; i += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11829 | u32 addr; |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11830 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11831 | |
| 11832 | addr = offset + i; |
| 11833 | |
| 11834 | memcpy(&data, buf + i, 4); |
| 11835 | |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 11836 | /* |
| 11837 | * The SEEPROM interface expects the data to always be opposite |
| 11838 | * the native endian format. We accomplish this by reversing |
| 11839 | * all the operations that would have been performed on the |
| 11840 | * data from a call to tg3_nvram_read_be32(). |
| 11841 | */ |
| 11842 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11843 | |
| 11844 | val = tr32(GRC_EEPROM_ADDR); |
| 11845 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); |
| 11846 | |
| 11847 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | |
| 11848 | EEPROM_ADDR_READ); |
| 11849 | tw32(GRC_EEPROM_ADDR, val | |
| 11850 | (0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 11851 | (addr & EEPROM_ADDR_ADDR_MASK) | |
| 11852 | EEPROM_ADDR_START | |
| 11853 | EEPROM_ADDR_WRITE); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11854 | |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 11855 | for (j = 0; j < 1000; j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11856 | val = tr32(GRC_EEPROM_ADDR); |
| 11857 | |
| 11858 | if (val & EEPROM_ADDR_COMPLETE) |
| 11859 | break; |
Michael Chan | 9d57f01 | 2006-12-07 00:23:25 -0800 | [diff] [blame] | 11860 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11861 | } |
| 11862 | if (!(val & EEPROM_ADDR_COMPLETE)) { |
| 11863 | rc = -EBUSY; |
| 11864 | break; |
| 11865 | } |
| 11866 | } |
| 11867 | |
| 11868 | return rc; |
| 11869 | } |
| 11870 | |
| 11871 | /* offset and length are dword aligned */ |
| 11872 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, |
| 11873 | u8 *buf) |
| 11874 | { |
| 11875 | int ret = 0; |
| 11876 | u32 pagesize = tp->nvram_pagesize; |
| 11877 | u32 pagemask = pagesize - 1; |
| 11878 | u32 nvram_cmd; |
| 11879 | u8 *tmp; |
| 11880 | |
| 11881 | tmp = kmalloc(pagesize, GFP_KERNEL); |
| 11882 | if (tmp == NULL) |
| 11883 | return -ENOMEM; |
| 11884 | |
| 11885 | while (len) { |
| 11886 | int j; |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11887 | u32 phy_addr, page_off, size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11888 | |
| 11889 | phy_addr = offset & ~pagemask; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 11890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11891 | for (j = 0; j < pagesize; j += 4) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11892 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
| 11893 | (__be32 *) (tmp + j)); |
| 11894 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11895 | break; |
| 11896 | } |
| 11897 | if (ret) |
| 11898 | break; |
| 11899 | |
| 11900 | page_off = offset & pagemask; |
| 11901 | size = pagesize; |
| 11902 | if (len < size) |
| 11903 | size = len; |
| 11904 | |
| 11905 | len -= size; |
| 11906 | |
| 11907 | memcpy(tmp + page_off, buf, size); |
| 11908 | |
| 11909 | offset = offset + (pagesize - page_off); |
| 11910 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 11911 | tg3_enable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11912 | |
| 11913 | /* |
| 11914 | * Before we can erase the flash page, we need |
| 11915 | * to issue a special "write enable" command. |
| 11916 | */ |
| 11917 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 11918 | |
| 11919 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 11920 | break; |
| 11921 | |
| 11922 | /* Erase the target page */ |
| 11923 | tw32(NVRAM_ADDR, phy_addr); |
| 11924 | |
| 11925 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | |
| 11926 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; |
| 11927 | |
| 11928 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 11929 | break; |
| 11930 | |
| 11931 | /* Issue another write enable to start the write. */ |
| 11932 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 11933 | |
| 11934 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 11935 | break; |
| 11936 | |
| 11937 | for (j = 0; j < pagesize; j += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11938 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11939 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11940 | data = *((__be32 *) (tmp + j)); |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 11941 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11942 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11943 | |
| 11944 | tw32(NVRAM_ADDR, phy_addr + j); |
| 11945 | |
| 11946 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | |
| 11947 | NVRAM_CMD_WR; |
| 11948 | |
| 11949 | if (j == 0) |
| 11950 | nvram_cmd |= NVRAM_CMD_FIRST; |
| 11951 | else if (j == (pagesize - 4)) |
| 11952 | nvram_cmd |= NVRAM_CMD_LAST; |
| 11953 | |
| 11954 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) |
| 11955 | break; |
| 11956 | } |
| 11957 | if (ret) |
| 11958 | break; |
| 11959 | } |
| 11960 | |
| 11961 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 11962 | tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 11963 | |
| 11964 | kfree(tmp); |
| 11965 | |
| 11966 | return ret; |
| 11967 | } |
| 11968 | |
| 11969 | /* offset and length are dword aligned */ |
| 11970 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, |
| 11971 | u8 *buf) |
| 11972 | { |
| 11973 | int i, ret = 0; |
| 11974 | |
| 11975 | for (i = 0; i < len; i += 4, offset += 4) { |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11976 | u32 page_off, phy_addr, nvram_cmd; |
| 11977 | __be32 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11978 | |
| 11979 | memcpy(&data, buf + i, 4); |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 11980 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11981 | |
| 11982 | page_off = offset % tp->nvram_pagesize; |
| 11983 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 11984 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11985 | |
| 11986 | tw32(NVRAM_ADDR, phy_addr); |
| 11987 | |
| 11988 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
| 11989 | |
| 11990 | if ((page_off == 0) || (i == 0)) |
| 11991 | nvram_cmd |= NVRAM_CMD_FIRST; |
Michael Chan | f6d9a25 | 2006-04-29 19:00:24 -0700 | [diff] [blame] | 11992 | if (page_off == (tp->nvram_pagesize - 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11993 | nvram_cmd |= NVRAM_CMD_LAST; |
| 11994 | |
| 11995 | if (i == (len - 4)) |
| 11996 | nvram_cmd |= NVRAM_CMD_LAST; |
| 11997 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 11998 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
| 11999 | !(tp->tg3_flags3 & TG3_FLG3_5755_PLUS) && |
Michael Chan | 4c98748 | 2005-09-05 17:52:38 -0700 | [diff] [blame] | 12000 | (tp->nvram_jedecnum == JEDEC_ST) && |
| 12001 | (nvram_cmd & NVRAM_CMD_FIRST)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12002 | |
| 12003 | if ((ret = tg3_nvram_exec_cmd(tp, |
| 12004 | NVRAM_CMD_WREN | NVRAM_CMD_GO | |
| 12005 | NVRAM_CMD_DONE))) |
| 12006 | |
| 12007 | break; |
| 12008 | } |
| 12009 | if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) { |
| 12010 | /* We always do complete word writes to eeprom. */ |
| 12011 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); |
| 12012 | } |
| 12013 | |
| 12014 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) |
| 12015 | break; |
| 12016 | } |
| 12017 | return ret; |
| 12018 | } |
| 12019 | |
| 12020 | /* offset and length are dword aligned */ |
| 12021 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) |
| 12022 | { |
| 12023 | int ret; |
| 12024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12025 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 12026 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
| 12027 | ~GRC_LCLCTRL_GPIO_OUTPUT1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12028 | udelay(40); |
| 12029 | } |
| 12030 | |
| 12031 | if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) { |
| 12032 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
| 12033 | } |
| 12034 | else { |
| 12035 | u32 grc_mode; |
| 12036 | |
Michael Chan | ec41c7d | 2006-01-17 02:40:55 -0800 | [diff] [blame] | 12037 | ret = tg3_nvram_lock(tp); |
| 12038 | if (ret) |
| 12039 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12040 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12041 | tg3_enable_nvram_access(tp); |
| 12042 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
Matt Carlson | f66a29b | 2009-11-13 13:03:36 +0000 | [diff] [blame] | 12043 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12044 | tw32(NVRAM_WRITE1, 0x406); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12045 | |
| 12046 | grc_mode = tr32(GRC_MODE); |
| 12047 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); |
| 12048 | |
| 12049 | if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) || |
| 12050 | !(tp->tg3_flags2 & TG3_FLG2_FLASH)) { |
| 12051 | |
| 12052 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
| 12053 | buf); |
| 12054 | } |
| 12055 | else { |
| 12056 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
| 12057 | buf); |
| 12058 | } |
| 12059 | |
| 12060 | grc_mode = tr32(GRC_MODE); |
| 12061 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); |
| 12062 | |
Michael Chan | e6af301 | 2005-04-21 17:12:05 -0700 | [diff] [blame] | 12063 | tg3_disable_nvram_access(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12064 | tg3_nvram_unlock(tp); |
| 12065 | } |
| 12066 | |
| 12067 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) { |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 12068 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12069 | udelay(40); |
| 12070 | } |
| 12071 | |
| 12072 | return ret; |
| 12073 | } |
| 12074 | |
| 12075 | struct subsys_tbl_ent { |
| 12076 | u16 subsys_vendor, subsys_devid; |
| 12077 | u32 phy_id; |
| 12078 | }; |
| 12079 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12080 | static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12081 | /* Broadcom boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12082 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12083 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12084 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12085 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12086 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12087 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12088 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 12089 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, |
| 12090 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12091 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12092 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12093 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12094 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 12095 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, |
| 12096 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12097 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12098 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12099 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12100 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12101 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12102 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12103 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12104 | |
| 12105 | /* 3com boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12106 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12107 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12108 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12109 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12110 | { TG3PCI_SUBVENDOR_ID_3COM, |
| 12111 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, |
| 12112 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12113 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12114 | { TG3PCI_SUBVENDOR_ID_3COM, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12115 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12116 | |
| 12117 | /* DELL boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12118 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12119 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12120 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12121 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12122 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12123 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12124 | { TG3PCI_SUBVENDOR_ID_DELL, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12125 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12126 | |
| 12127 | /* Compaq boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12128 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12129 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12130 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12131 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12132 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 12133 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, |
| 12134 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12135 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12136 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12137 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12138 | |
| 12139 | /* IBM boards. */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12140 | { TG3PCI_SUBVENDOR_ID_IBM, |
| 12141 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12142 | }; |
| 12143 | |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12144 | 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] | 12145 | { |
| 12146 | int i; |
| 12147 | |
| 12148 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { |
| 12149 | if ((subsys_id_to_phy_id[i].subsys_vendor == |
| 12150 | tp->pdev->subsystem_vendor) && |
| 12151 | (subsys_id_to_phy_id[i].subsys_devid == |
| 12152 | tp->pdev->subsystem_device)) |
| 12153 | return &subsys_id_to_phy_id[i]; |
| 12154 | } |
| 12155 | return NULL; |
| 12156 | } |
| 12157 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12158 | static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12159 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12160 | u32 val; |
Michael Chan | caf636c7 | 2006-03-22 01:05:31 -0800 | [diff] [blame] | 12161 | u16 pmcsr; |
| 12162 | |
| 12163 | /* On some early chips the SRAM cannot be accessed in D3hot state, |
| 12164 | * so need make sure we're in D0. |
| 12165 | */ |
| 12166 | pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr); |
| 12167 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
| 12168 | pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr); |
| 12169 | msleep(1); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12170 | |
| 12171 | /* Make sure register accesses (indirect or otherwise) |
| 12172 | * will function correctly. |
| 12173 | */ |
| 12174 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 12175 | tp->misc_host_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12176 | |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12177 | /* The memory arbiter has to be enabled in order for SRAM accesses |
| 12178 | * to succeed. Normally on powerup the tg3 chip firmware will make |
| 12179 | * sure it is enabled, but other entities such as system netboot |
| 12180 | * code might disable it. |
| 12181 | */ |
| 12182 | val = tr32(MEMARB_MODE); |
| 12183 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 12184 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12185 | tp->phy_id = TG3_PHY_ID_INVALID; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12186 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12187 | |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 12188 | /* Assume an onboard device and WOL capable by default. */ |
| 12189 | 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] | 12190 | |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12191 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12192 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12193 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12194 | tp->tg3_flags2 |= TG3_FLG2_IS_NIC; |
| 12195 | } |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12196 | val = tr32(VCPU_CFGSHDW); |
| 12197 | if (val & VCPU_CFGSHDW_ASPM_DBNC) |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12198 | tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND; |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12199 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
Matt Carlson | 2023276 | 2008-12-21 20:18:56 -0800 | [diff] [blame] | 12200 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12201 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12202 | goto done; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12203 | } |
| 12204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12205 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 12206 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 12207 | u32 nic_cfg, led_cfg; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12208 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12209 | int eeprom_phy_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12210 | |
| 12211 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 12212 | tp->nic_sram_data_cfg = nic_cfg; |
| 12213 | |
| 12214 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); |
| 12215 | ver >>= NIC_SRAM_DATA_VER_SHIFT; |
| 12216 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) && |
| 12217 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) && |
| 12218 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) && |
| 12219 | (ver > 0) && (ver < 0x100)) |
| 12220 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); |
| 12221 | |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12222 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
| 12223 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
| 12224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12225 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
| 12226 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) |
| 12227 | eeprom_phy_serdes = 1; |
| 12228 | |
| 12229 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); |
| 12230 | if (nic_phy_id != 0) { |
| 12231 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; |
| 12232 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; |
| 12233 | |
| 12234 | eeprom_phy_id = (id1 >> 16) << 10; |
| 12235 | eeprom_phy_id |= (id2 & 0xfc00) << 16; |
| 12236 | eeprom_phy_id |= (id2 & 0x03ff) << 0; |
| 12237 | } else |
| 12238 | eeprom_phy_id = 0; |
| 12239 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12240 | tp->phy_id = eeprom_phy_id; |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 12241 | if (eeprom_phy_serdes) { |
Matt Carlson | d1ec96a | 2010-01-12 10:11:38 +0000 | [diff] [blame] | 12242 | if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
| 12243 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 12244 | tp->tg3_flags2 |= TG3_FLG2_MII_SERDES; |
| 12245 | else |
| 12246 | tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES; |
| 12247 | } |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12248 | |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 12249 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12250 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
| 12251 | SHASTA_EXT_LED_MODE_MASK); |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 12252 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12253 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
| 12254 | |
| 12255 | switch (led_cfg) { |
| 12256 | default: |
| 12257 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: |
| 12258 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12259 | break; |
| 12260 | |
| 12261 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: |
| 12262 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 12263 | break; |
| 12264 | |
| 12265 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: |
| 12266 | tp->led_ctrl = LED_CTRL_MODE_MAC; |
Michael Chan | 9ba2779 | 2005-06-06 15:16:20 -0700 | [diff] [blame] | 12267 | |
| 12268 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is |
| 12269 | * read on some older 5700/5701 bootcode. |
| 12270 | */ |
| 12271 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 12272 | ASIC_REV_5700 || |
| 12273 | GET_ASIC_REV(tp->pci_chip_rev_id) == |
| 12274 | ASIC_REV_5701) |
| 12275 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 12276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12277 | break; |
| 12278 | |
| 12279 | case SHASTA_EXT_LED_SHARED: |
| 12280 | tp->led_ctrl = LED_CTRL_MODE_SHARED; |
| 12281 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
| 12282 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) |
| 12283 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 12284 | LED_CTRL_MODE_PHY_2); |
| 12285 | break; |
| 12286 | |
| 12287 | case SHASTA_EXT_LED_MAC: |
| 12288 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; |
| 12289 | break; |
| 12290 | |
| 12291 | case SHASTA_EXT_LED_COMBO: |
| 12292 | tp->led_ctrl = LED_CTRL_MODE_COMBO; |
| 12293 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) |
| 12294 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 12295 | LED_CTRL_MODE_PHY_2); |
| 12296 | break; |
| 12297 | |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 12298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12299 | |
| 12300 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 12301 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && |
| 12302 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
| 12303 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 12304 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 12305 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
| 12306 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
Matt Carlson | 5f60891 | 2007-11-12 21:17:07 -0800 | [diff] [blame] | 12307 | |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12308 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12309 | tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT; |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12310 | if ((tp->pdev->subsystem_vendor == |
| 12311 | PCI_VENDOR_ID_ARIMA) && |
| 12312 | (tp->pdev->subsystem_device == 0x205a || |
| 12313 | tp->pdev->subsystem_device == 0x2063)) |
| 12314 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
| 12315 | } else { |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12316 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 12317 | tp->tg3_flags2 |= TG3_FLG2_IS_NIC; |
| 12318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12319 | |
| 12320 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
| 12321 | tp->tg3_flags |= TG3_FLAG_ENABLE_ASF; |
John W. Linville | cbf4685 | 2005-04-21 17:01:29 -0700 | [diff] [blame] | 12322 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12323 | tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE; |
| 12324 | } |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 12325 | |
| 12326 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && |
| 12327 | (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 12328 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_APE; |
Matt Carlson | b2b98d4 | 2008-11-03 16:52:32 -0800 | [diff] [blame] | 12329 | |
Gary Zambrano | a85feb8 | 2007-05-05 11:52:19 -0700 | [diff] [blame] | 12330 | if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES && |
| 12331 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
| 12332 | tp->tg3_flags &= ~TG3_FLAG_WOL_CAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12333 | |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 12334 | if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) && |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12335 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) |
Matt Carlson | 0527ba3 | 2007-10-10 18:03:30 -0700 | [diff] [blame] | 12336 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
| 12337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12338 | if (cfg2 & (1 << 17)) |
| 12339 | tp->tg3_flags2 |= TG3_FLG2_CAPACITIVE_COUPLING; |
| 12340 | |
| 12341 | /* serdes signal pre-emphasis in register 0x590 set by */ |
| 12342 | /* bootcode if bit 18 is set */ |
| 12343 | if (cfg2 & (1 << 18)) |
| 12344 | tp->tg3_flags2 |= TG3_FLG2_SERDES_PREEMPHASIS; |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12345 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12346 | if (((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 12347 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) && |
Matt Carlson | 6833c04 | 2008-11-21 17:18:59 -0800 | [diff] [blame] | 12348 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
| 12349 | tp->tg3_flags3 |= TG3_FLG3_PHY_ENABLE_APD; |
| 12350 | |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 12351 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 12352 | u32 cfg3; |
| 12353 | |
| 12354 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); |
| 12355 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) |
| 12356 | tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND; |
| 12357 | } |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12358 | |
Matt Carlson | 1441706 | 2010-02-17 15:16:59 +0000 | [diff] [blame] | 12359 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
| 12360 | tp->tg3_flags3 |= TG3_FLG3_RGMII_INBAND_DISABLE; |
Matt Carlson | a9daf36 | 2008-05-25 23:49:44 -0700 | [diff] [blame] | 12361 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
| 12362 | tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_RX_EN; |
| 12363 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
| 12364 | tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_TX_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12365 | } |
Matt Carlson | 05ac4cb | 2008-11-03 16:53:46 -0800 | [diff] [blame] | 12366 | done: |
| 12367 | device_init_wakeup(&tp->pdev->dev, tp->tg3_flags & TG3_FLAG_WOL_CAP); |
| 12368 | device_set_wakeup_enable(&tp->pdev->dev, |
| 12369 | tp->tg3_flags & TG3_FLAG_WOL_ENABLE); |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12370 | } |
| 12371 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 12372 | static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
| 12373 | { |
| 12374 | int i; |
| 12375 | u32 val; |
| 12376 | |
| 12377 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); |
| 12378 | tw32(OTP_CTRL, cmd); |
| 12379 | |
| 12380 | /* Wait for up to 1 ms for command to execute. */ |
| 12381 | for (i = 0; i < 100; i++) { |
| 12382 | val = tr32(OTP_STATUS); |
| 12383 | if (val & OTP_STATUS_CMD_DONE) |
| 12384 | break; |
| 12385 | udelay(10); |
| 12386 | } |
| 12387 | |
| 12388 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; |
| 12389 | } |
| 12390 | |
| 12391 | /* Read the gphy configuration from the OTP region of the chip. The gphy |
| 12392 | * configuration is a 32-bit value that straddles the alignment boundary. |
| 12393 | * We do two 32-bit reads and then shift and merge the results. |
| 12394 | */ |
| 12395 | static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp) |
| 12396 | { |
| 12397 | u32 bhalf_otp, thalf_otp; |
| 12398 | |
| 12399 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); |
| 12400 | |
| 12401 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) |
| 12402 | return 0; |
| 12403 | |
| 12404 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); |
| 12405 | |
| 12406 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 12407 | return 0; |
| 12408 | |
| 12409 | thalf_otp = tr32(OTP_READ_DATA); |
| 12410 | |
| 12411 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); |
| 12412 | |
| 12413 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 12414 | return 0; |
| 12415 | |
| 12416 | bhalf_otp = tr32(OTP_READ_DATA); |
| 12417 | |
| 12418 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); |
| 12419 | } |
| 12420 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12421 | static int __devinit tg3_phy_probe(struct tg3 *tp) |
| 12422 | { |
| 12423 | u32 hw_phy_id_1, hw_phy_id_2; |
| 12424 | u32 hw_phy_id, hw_phy_id_masked; |
| 12425 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12426 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 12427 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) |
| 12428 | return tg3_phy_init(tp); |
| 12429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12430 | /* Reading the PHY ID register can conflict with ASF |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 12431 | * firmware access to the PHY hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12432 | */ |
| 12433 | err = 0; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 12434 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
| 12435 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12436 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12437 | } else { |
| 12438 | /* Now read the physical PHY_ID from the chip and verify |
| 12439 | * that it is sane. If it doesn't look good, we fall back |
| 12440 | * to either the hard-coded table based PHY_ID and failing |
| 12441 | * that the value found in the eeprom area. |
| 12442 | */ |
| 12443 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); |
| 12444 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); |
| 12445 | |
| 12446 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; |
| 12447 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; |
| 12448 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; |
| 12449 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12450 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12451 | } |
| 12452 | |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12453 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12454 | tp->phy_id = hw_phy_id; |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12455 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12456 | tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES; |
Michael Chan | da6b2d0 | 2005-08-19 12:54:29 -0700 | [diff] [blame] | 12457 | else |
| 12458 | tp->tg3_flags2 &= ~TG3_FLG2_PHY_SERDES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12459 | } else { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12460 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 12461 | /* Do nothing, phy ID already set up in |
| 12462 | * tg3_get_eeprom_hw_cfg(). |
| 12463 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12464 | } else { |
| 12465 | struct subsys_tbl_ent *p; |
| 12466 | |
| 12467 | /* No eeprom signature? Try the hardcoded |
| 12468 | * subsys device table. |
| 12469 | */ |
Matt Carlson | 24daf2b | 2010-02-17 15:17:02 +0000 | [diff] [blame] | 12470 | p = tg3_lookup_by_subsys(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12471 | if (!p) |
| 12472 | return -ENODEV; |
| 12473 | |
| 12474 | tp->phy_id = p->phy_id; |
| 12475 | if (!tp->phy_id || |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12476 | tp->phy_id == TG3_PHY_ID_BCM8002) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12477 | tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES; |
| 12478 | } |
| 12479 | } |
| 12480 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 12481 | if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) && |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 12482 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12483 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 12484 | u32 bmsr, adv_reg, tg3_ctrl, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12485 | |
| 12486 | tg3_readphy(tp, MII_BMSR, &bmsr); |
| 12487 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 12488 | (bmsr & BMSR_LSTATUS)) |
| 12489 | goto skip_phy_reset; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 12490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12491 | err = tg3_phy_reset(tp); |
| 12492 | if (err) |
| 12493 | return err; |
| 12494 | |
| 12495 | adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 12496 | ADVERTISE_100HALF | ADVERTISE_100FULL | |
| 12497 | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); |
| 12498 | tg3_ctrl = 0; |
| 12499 | if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) { |
| 12500 | tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF | |
| 12501 | MII_TG3_CTRL_ADV_1000_FULL); |
| 12502 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 12503 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) |
| 12504 | tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER | |
| 12505 | MII_TG3_CTRL_ENABLE_AS_MASTER); |
| 12506 | } |
| 12507 | |
Michael Chan | 3600d91 | 2006-12-07 00:21:48 -0800 | [diff] [blame] | 12508 | mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 12509 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 12510 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full); |
| 12511 | if (!tg3_copper_is_advertising_all(tp, mask)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12512 | tg3_writephy(tp, MII_ADVERTISE, adv_reg); |
| 12513 | |
| 12514 | if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) |
| 12515 | tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl); |
| 12516 | |
| 12517 | tg3_writephy(tp, MII_BMCR, |
| 12518 | BMCR_ANENABLE | BMCR_ANRESTART); |
| 12519 | } |
| 12520 | tg3_phy_set_wirespeed(tp); |
| 12521 | |
| 12522 | tg3_writephy(tp, MII_ADVERTISE, adv_reg); |
| 12523 | if (!(tp->tg3_flags & TG3_FLAG_10_100_ONLY)) |
| 12524 | tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl); |
| 12525 | } |
| 12526 | |
| 12527 | skip_phy_reset: |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 12528 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12529 | err = tg3_init_5401phy_dsp(tp); |
| 12530 | if (err) |
| 12531 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12533 | err = tg3_init_5401phy_dsp(tp); |
| 12534 | } |
| 12535 | |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 12536 | if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12537 | tp->link_config.advertising = |
| 12538 | (ADVERTISED_1000baseT_Half | |
| 12539 | ADVERTISED_1000baseT_Full | |
| 12540 | ADVERTISED_Autoneg | |
| 12541 | ADVERTISED_FIBRE); |
| 12542 | if (tp->tg3_flags & TG3_FLAG_10_100_ONLY) |
| 12543 | tp->link_config.advertising &= |
| 12544 | ~(ADVERTISED_1000baseT_Half | |
| 12545 | ADVERTISED_1000baseT_Full); |
| 12546 | |
| 12547 | return err; |
| 12548 | } |
| 12549 | |
| 12550 | static void __devinit tg3_read_partno(struct tg3 *tp) |
| 12551 | { |
Matt Carlson | 141518c | 2009-12-03 08:36:22 +0000 | [diff] [blame] | 12552 | unsigned char vpd_data[TG3_NVM_VPD_LEN]; /* in little-endian format */ |
Michael Chan | af2c6a4 | 2006-11-07 14:57:51 -0800 | [diff] [blame] | 12553 | unsigned int i; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12554 | u32 magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12555 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 12556 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
| 12557 | tg3_nvram_read(tp, 0x0, &magic)) |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12558 | goto out_not_found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12559 | |
Michael Chan | 1820180 | 2006-03-20 22:29:15 -0800 | [diff] [blame] | 12560 | if (magic == TG3_EEPROM_MAGIC) { |
Matt Carlson | 141518c | 2009-12-03 08:36:22 +0000 | [diff] [blame] | 12561 | for (i = 0; i < TG3_NVM_VPD_LEN; i += 4) { |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12562 | u32 tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12563 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12564 | /* The data is in little-endian format in NVRAM. |
| 12565 | * Use the big-endian read routines to preserve |
| 12566 | * the byte order as it exists in NVRAM. |
| 12567 | */ |
Matt Carlson | 141518c | 2009-12-03 08:36:22 +0000 | [diff] [blame] | 12568 | if (tg3_nvram_read_be32(tp, TG3_NVM_VPD_OFF + i, &tmp)) |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12569 | goto out_not_found; |
| 12570 | |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 12571 | memcpy(&vpd_data[i], &tmp, sizeof(tmp)); |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12572 | } |
| 12573 | } else { |
Matt Carlson | 94c982b | 2009-12-03 08:36:23 +0000 | [diff] [blame] | 12574 | ssize_t cnt; |
| 12575 | unsigned int pos = 0, i = 0; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12576 | |
Matt Carlson | 94c982b | 2009-12-03 08:36:23 +0000 | [diff] [blame] | 12577 | for (; pos < TG3_NVM_VPD_LEN && i < 3; i++, pos += cnt) { |
| 12578 | cnt = pci_read_vpd(tp->pdev, pos, |
| 12579 | TG3_NVM_VPD_LEN - pos, |
| 12580 | &vpd_data[pos]); |
| 12581 | if (cnt == -ETIMEDOUT || -EINTR) |
| 12582 | cnt = 0; |
| 12583 | else if (cnt < 0) |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 12584 | goto out_not_found; |
Michael Chan | 1b27777 | 2006-03-20 22:27:48 -0800 | [diff] [blame] | 12585 | } |
Matt Carlson | 94c982b | 2009-12-03 08:36:23 +0000 | [diff] [blame] | 12586 | if (pos != TG3_NVM_VPD_LEN) |
| 12587 | goto out_not_found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12588 | } |
| 12589 | |
| 12590 | /* Now parse and find the part number. */ |
Matt Carlson | 141518c | 2009-12-03 08:36:22 +0000 | [diff] [blame] | 12591 | for (i = 0; i < TG3_NVM_VPD_LEN - 2; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12592 | unsigned char val = vpd_data[i]; |
Michael Chan | af2c6a4 | 2006-11-07 14:57:51 -0800 | [diff] [blame] | 12593 | unsigned int block_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12594 | |
| 12595 | if (val == 0x82 || val == 0x91) { |
| 12596 | i = (i + 3 + |
| 12597 | (vpd_data[i + 1] + |
| 12598 | (vpd_data[i + 2] << 8))); |
| 12599 | continue; |
| 12600 | } |
| 12601 | |
| 12602 | if (val != 0x90) |
| 12603 | goto out_not_found; |
| 12604 | |
| 12605 | block_end = (i + 3 + |
| 12606 | (vpd_data[i + 1] + |
| 12607 | (vpd_data[i + 2] << 8))); |
| 12608 | i += 3; |
Michael Chan | af2c6a4 | 2006-11-07 14:57:51 -0800 | [diff] [blame] | 12609 | |
Matt Carlson | 141518c | 2009-12-03 08:36:22 +0000 | [diff] [blame] | 12610 | if (block_end > TG3_NVM_VPD_LEN) |
Michael Chan | af2c6a4 | 2006-11-07 14:57:51 -0800 | [diff] [blame] | 12611 | goto out_not_found; |
| 12612 | |
| 12613 | while (i < (block_end - 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12614 | if (vpd_data[i + 0] == 'P' && |
| 12615 | vpd_data[i + 1] == 'N') { |
| 12616 | int partno_len = vpd_data[i + 2]; |
| 12617 | |
Michael Chan | af2c6a4 | 2006-11-07 14:57:51 -0800 | [diff] [blame] | 12618 | i += 3; |
Matt Carlson | 141518c | 2009-12-03 08:36:22 +0000 | [diff] [blame] | 12619 | if (partno_len > TG3_BPN_SIZE || |
| 12620 | (partno_len + i) > TG3_NVM_VPD_LEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12621 | goto out_not_found; |
| 12622 | |
| 12623 | memcpy(tp->board_part_number, |
Michael Chan | af2c6a4 | 2006-11-07 14:57:51 -0800 | [diff] [blame] | 12624 | &vpd_data[i], partno_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12625 | |
| 12626 | /* Success. */ |
| 12627 | return; |
| 12628 | } |
Michael Chan | af2c6a4 | 2006-11-07 14:57:51 -0800 | [diff] [blame] | 12629 | i += 3 + vpd_data[i + 2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12630 | } |
| 12631 | |
| 12632 | /* Part number not found. */ |
| 12633 | goto out_not_found; |
| 12634 | } |
| 12635 | |
| 12636 | out_not_found: |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12637 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 12638 | strcpy(tp->board_part_number, "BCM95906"); |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 12639 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 && |
| 12640 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
| 12641 | strcpy(tp->board_part_number, "BCM57780"); |
| 12642 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 && |
| 12643 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) |
| 12644 | strcpy(tp->board_part_number, "BCM57760"); |
| 12645 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 && |
| 12646 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) |
| 12647 | strcpy(tp->board_part_number, "BCM57790"); |
Matt Carlson | 5e7ccf2 | 2009-08-25 10:08:42 +0000 | [diff] [blame] | 12648 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 && |
| 12649 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) |
| 12650 | strcpy(tp->board_part_number, "BCM57788"); |
Matt Carlson | b474eca | 2010-02-17 15:16:58 +0000 | [diff] [blame] | 12651 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 12652 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
| 12653 | strcpy(tp->board_part_number, "BCM57761"); |
| 12654 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 12655 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 12656 | strcpy(tp->board_part_number, "BCM57765"); |
Matt Carlson | b474eca | 2010-02-17 15:16:58 +0000 | [diff] [blame] | 12657 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 12658 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) |
| 12659 | strcpy(tp->board_part_number, "BCM57781"); |
| 12660 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 12661 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) |
| 12662 | strcpy(tp->board_part_number, "BCM57785"); |
| 12663 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 12664 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) |
| 12665 | strcpy(tp->board_part_number, "BCM57791"); |
| 12666 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
| 12667 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 12668 | strcpy(tp->board_part_number, "BCM57795"); |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 12669 | else |
| 12670 | strcpy(tp->board_part_number, "none"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12671 | } |
| 12672 | |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12673 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
| 12674 | { |
| 12675 | u32 val; |
| 12676 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12677 | if (tg3_nvram_read(tp, offset, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12678 | (val & 0xfc000000) != 0x0c000000 || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12679 | tg3_nvram_read(tp, offset + 4, &val) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12680 | val != 0) |
| 12681 | return 0; |
| 12682 | |
| 12683 | return 1; |
| 12684 | } |
| 12685 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12686 | static void __devinit tg3_read_bc_ver(struct tg3 *tp) |
| 12687 | { |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12688 | u32 val, offset, start, ver_offset; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12689 | int i; |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12690 | bool newver = false; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12691 | |
| 12692 | if (tg3_nvram_read(tp, 0xc, &offset) || |
| 12693 | tg3_nvram_read(tp, 0x4, &start)) |
| 12694 | return; |
| 12695 | |
| 12696 | offset = tg3_nvram_logical_addr(tp, offset); |
| 12697 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12698 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12699 | return; |
| 12700 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12701 | if ((val & 0xfc000000) == 0x0c000000) { |
| 12702 | if (tg3_nvram_read(tp, offset + 4, &val)) |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12703 | return; |
| 12704 | |
Matt Carlson | ff3a7cb | 2009-02-25 14:26:58 +0000 | [diff] [blame] | 12705 | if (val == 0) |
| 12706 | newver = true; |
| 12707 | } |
| 12708 | |
| 12709 | if (newver) { |
| 12710 | if (tg3_nvram_read(tp, offset + 8, &ver_offset)) |
| 12711 | return; |
| 12712 | |
| 12713 | offset = offset + ver_offset - start; |
| 12714 | for (i = 0; i < 16; i += 4) { |
| 12715 | __be32 v; |
| 12716 | if (tg3_nvram_read_be32(tp, offset + i, &v)) |
| 12717 | return; |
| 12718 | |
| 12719 | memcpy(tp->fw_ver + i, &v, sizeof(v)); |
| 12720 | } |
| 12721 | } else { |
| 12722 | u32 major, minor; |
| 12723 | |
| 12724 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) |
| 12725 | return; |
| 12726 | |
| 12727 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> |
| 12728 | TG3_NVM_BCVER_MAJSFT; |
| 12729 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; |
| 12730 | snprintf(&tp->fw_ver[0], 32, "v%d.%02d", major, minor); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12731 | } |
| 12732 | } |
| 12733 | |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 12734 | static void __devinit tg3_read_hwsb_ver(struct tg3 *tp) |
| 12735 | { |
| 12736 | u32 val, major, minor; |
| 12737 | |
| 12738 | /* Use native endian representation */ |
| 12739 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) |
| 12740 | return; |
| 12741 | |
| 12742 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> |
| 12743 | TG3_NVM_HWSB_CFG1_MAJSFT; |
| 12744 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> |
| 12745 | TG3_NVM_HWSB_CFG1_MINSFT; |
| 12746 | |
| 12747 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); |
| 12748 | } |
| 12749 | |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12750 | static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val) |
| 12751 | { |
| 12752 | u32 offset, major, minor, build; |
| 12753 | |
| 12754 | tp->fw_ver[0] = 's'; |
| 12755 | tp->fw_ver[1] = 'b'; |
| 12756 | tp->fw_ver[2] = '\0'; |
| 12757 | |
| 12758 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) |
| 12759 | return; |
| 12760 | |
| 12761 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { |
| 12762 | case TG3_EEPROM_SB_REVISION_0: |
| 12763 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; |
| 12764 | break; |
| 12765 | case TG3_EEPROM_SB_REVISION_2: |
| 12766 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; |
| 12767 | break; |
| 12768 | case TG3_EEPROM_SB_REVISION_3: |
| 12769 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; |
| 12770 | break; |
Matt Carlson | a4153d4 | 2010-02-17 15:16:56 +0000 | [diff] [blame] | 12771 | case TG3_EEPROM_SB_REVISION_4: |
| 12772 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; |
| 12773 | break; |
| 12774 | case TG3_EEPROM_SB_REVISION_5: |
| 12775 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; |
| 12776 | break; |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12777 | default: |
| 12778 | return; |
| 12779 | } |
| 12780 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12781 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | dfe00d7 | 2008-11-21 17:19:41 -0800 | [diff] [blame] | 12782 | return; |
| 12783 | |
| 12784 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> |
| 12785 | TG3_EEPROM_SB_EDH_BLD_SHFT; |
| 12786 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> |
| 12787 | TG3_EEPROM_SB_EDH_MAJ_SHFT; |
| 12788 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; |
| 12789 | |
| 12790 | if (minor > 99 || build > 26) |
| 12791 | return; |
| 12792 | |
| 12793 | snprintf(&tp->fw_ver[2], 30, " v%d.%02d", major, minor); |
| 12794 | |
| 12795 | if (build > 0) { |
| 12796 | tp->fw_ver[8] = 'a' + build - 1; |
| 12797 | tp->fw_ver[9] = '\0'; |
| 12798 | } |
| 12799 | } |
| 12800 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12801 | static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp) |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 12802 | { |
| 12803 | u32 val, offset, start; |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12804 | int i, vlen; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12805 | |
| 12806 | for (offset = TG3_NVM_DIR_START; |
| 12807 | offset < TG3_NVM_DIR_END; |
| 12808 | offset += TG3_NVM_DIRENT_SIZE) { |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12809 | if (tg3_nvram_read(tp, offset, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12810 | return; |
| 12811 | |
| 12812 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
| 12813 | break; |
| 12814 | } |
| 12815 | |
| 12816 | if (offset == TG3_NVM_DIR_END) |
| 12817 | return; |
| 12818 | |
| 12819 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
| 12820 | start = 0x08000000; |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12821 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12822 | return; |
| 12823 | |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12824 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12825 | !tg3_fw_img_is_valid(tp, offset) || |
Matt Carlson | e4f3411 | 2009-02-25 14:25:00 +0000 | [diff] [blame] | 12826 | tg3_nvram_read(tp, offset + 8, &val)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12827 | return; |
| 12828 | |
| 12829 | offset += val - start; |
| 12830 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12831 | vlen = strlen(tp->fw_ver); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12832 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12833 | tp->fw_ver[vlen++] = ','; |
| 12834 | tp->fw_ver[vlen++] = ' '; |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12835 | |
| 12836 | for (i = 0; i < 4; i++) { |
Matt Carlson | a9dc529 | 2009-02-25 14:25:30 +0000 | [diff] [blame] | 12837 | __be32 v; |
| 12838 | if (tg3_nvram_read_be32(tp, offset, &v)) |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12839 | return; |
| 12840 | |
Al Viro | b9fc7dc | 2007-12-17 22:59:57 -0800 | [diff] [blame] | 12841 | offset += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12842 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12843 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
| 12844 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12845 | break; |
| 12846 | } |
| 12847 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12848 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
| 12849 | vlen += sizeof(v); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12850 | } |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12851 | } |
| 12852 | |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 12853 | static void __devinit tg3_read_dash_ver(struct tg3 *tp) |
| 12854 | { |
| 12855 | int vlen; |
| 12856 | u32 apedata; |
| 12857 | |
| 12858 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) || |
| 12859 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
| 12860 | return; |
| 12861 | |
| 12862 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 12863 | if (apedata != APE_SEG_SIG_MAGIC) |
| 12864 | return; |
| 12865 | |
| 12866 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 12867 | if (!(apedata & APE_FW_STATUS_READY)) |
| 12868 | return; |
| 12869 | |
| 12870 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
| 12871 | |
| 12872 | vlen = strlen(tp->fw_ver); |
| 12873 | |
| 12874 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " DASH v%d.%d.%d.%d", |
| 12875 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
| 12876 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, |
| 12877 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, |
| 12878 | (apedata & APE_FW_VERSION_BLDMSK)); |
| 12879 | } |
| 12880 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12881 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
| 12882 | { |
| 12883 | u32 val; |
| 12884 | |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 12885 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) { |
| 12886 | tp->fw_ver[0] = 's'; |
| 12887 | tp->fw_ver[1] = 'b'; |
| 12888 | tp->fw_ver[2] = '\0'; |
| 12889 | |
| 12890 | return; |
| 12891 | } |
| 12892 | |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12893 | if (tg3_nvram_read(tp, 0, &val)) |
| 12894 | return; |
| 12895 | |
| 12896 | if (val == TG3_EEPROM_MAGIC) |
| 12897 | tg3_read_bc_ver(tp); |
| 12898 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) |
| 12899 | tg3_read_sb_ver(tp, val); |
Matt Carlson | a6f6cb1 | 2009-02-25 14:27:43 +0000 | [diff] [blame] | 12900 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 12901 | tg3_read_hwsb_ver(tp); |
Matt Carlson | acd9c11 | 2009-02-25 14:26:33 +0000 | [diff] [blame] | 12902 | else |
| 12903 | return; |
| 12904 | |
| 12905 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
| 12906 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) |
| 12907 | return; |
| 12908 | |
| 12909 | tg3_read_mgmtfw_ver(tp); |
Matt Carlson | 9c8a620 | 2007-10-21 16:16:08 -0700 | [diff] [blame] | 12910 | |
| 12911 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 12912 | } |
| 12913 | |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 12914 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *); |
| 12915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12916 | static int __devinit tg3_get_invariants(struct tg3 *tp) |
| 12917 | { |
| 12918 | static struct pci_device_id write_reorder_chipsets[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12919 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, |
| 12920 | PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
John W. Linville | c165b00 | 2006-07-08 13:28:53 -0700 | [diff] [blame] | 12921 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, |
| 12922 | PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 12923 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, |
| 12924 | PCI_DEVICE_ID_VIA_8385_0) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12925 | { }, |
| 12926 | }; |
| 12927 | u32 misc_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12928 | u32 pci_state_reg, grc_misc_cfg; |
| 12929 | u32 val; |
| 12930 | u16 pci_cmd; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 12931 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12933 | /* Force memory write invalidate off. If we leave it on, |
| 12934 | * then on 5700_BX chips we have to enable a workaround. |
| 12935 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary |
| 12936 | * to match the cacheline size. The Broadcom driver have this |
| 12937 | * workaround but turns MWI off all the times so never uses |
| 12938 | * it. This seems to suggest that the workaround is insufficient. |
| 12939 | */ |
| 12940 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 12941 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; |
| 12942 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 12943 | |
| 12944 | /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL |
| 12945 | * has the register indirect write enable bit set before |
| 12946 | * we try to access any of the MMIO registers. It is also |
| 12947 | * critical that the PCI-X hw workaround situation is decided |
| 12948 | * before that as well. |
| 12949 | */ |
| 12950 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 12951 | &misc_ctrl_reg); |
| 12952 | |
| 12953 | tp->pci_chip_rev_id = (misc_ctrl_reg >> |
| 12954 | MISC_HOST_CTRL_CHIPREV_SHIFT); |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 12955 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
| 12956 | u32 prod_id_asic_rev; |
| 12957 | |
Matt Carlson | 5001e2f | 2009-11-13 13:03:51 +0000 | [diff] [blame] | 12958 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 12959 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 12960 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5724) |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 12961 | pci_read_config_dword(tp->pdev, |
| 12962 | TG3PCI_GEN2_PRODID_ASICREV, |
| 12963 | &prod_id_asic_rev); |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 12964 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
| 12965 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || |
| 12966 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || |
| 12967 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || |
| 12968 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 12969 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 12970 | pci_read_config_dword(tp->pdev, |
| 12971 | TG3PCI_GEN15_PRODID_ASICREV, |
| 12972 | &prod_id_asic_rev); |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 12973 | else |
| 12974 | pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV, |
| 12975 | &prod_id_asic_rev); |
| 12976 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 12977 | tp->pci_chip_rev_id = prod_id_asic_rev; |
Matt Carlson | 795d01c | 2007-10-07 23:28:17 -0700 | [diff] [blame] | 12978 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12979 | |
Michael Chan | ff645be | 2005-04-21 17:09:53 -0700 | [diff] [blame] | 12980 | /* Wrong chip ID in 5752 A0. This code can be removed later |
| 12981 | * as A0 is not in production. |
| 12982 | */ |
| 12983 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) |
| 12984 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
| 12985 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 12986 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
| 12987 | * we need to disable memory and use config. cycles |
| 12988 | * only to access all registers. The 5702/03 chips |
| 12989 | * can mistakenly decode the special cycles from the |
| 12990 | * ICH chipsets as memory write cycles, causing corruption |
| 12991 | * of register and memory space. Only certain ICH bridges |
| 12992 | * will drive special cycles with non-zero data during the |
| 12993 | * address phase which can fall within the 5703's address |
| 12994 | * range. This is not an ICH bug as the PCI spec allows |
| 12995 | * non-zero address during special cycles. However, only |
| 12996 | * these ICH bridges are known to drive non-zero addresses |
| 12997 | * during special cycles. |
| 12998 | * |
| 12999 | * Since special cycles do not cross PCI bridges, we only |
| 13000 | * enable this workaround if the 5703 is on the secondary |
| 13001 | * bus of these ICH bridges. |
| 13002 | */ |
| 13003 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || |
| 13004 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { |
| 13005 | static struct tg3_dev_id { |
| 13006 | u32 vendor; |
| 13007 | u32 device; |
| 13008 | u32 rev; |
| 13009 | } ich_chipsets[] = { |
| 13010 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, |
| 13011 | PCI_ANY_ID }, |
| 13012 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, |
| 13013 | PCI_ANY_ID }, |
| 13014 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, |
| 13015 | 0xa }, |
| 13016 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, |
| 13017 | PCI_ANY_ID }, |
| 13018 | { }, |
| 13019 | }; |
| 13020 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; |
| 13021 | struct pci_dev *bridge = NULL; |
| 13022 | |
| 13023 | while (pci_id->vendor != 0) { |
| 13024 | bridge = pci_get_device(pci_id->vendor, pci_id->device, |
| 13025 | bridge); |
| 13026 | if (!bridge) { |
| 13027 | pci_id++; |
| 13028 | continue; |
| 13029 | } |
| 13030 | if (pci_id->rev != PCI_ANY_ID) { |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 13031 | if (bridge->revision > pci_id->rev) |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13032 | continue; |
| 13033 | } |
| 13034 | if (bridge->subordinate && |
| 13035 | (bridge->subordinate->number == |
| 13036 | tp->pdev->bus->number)) { |
| 13037 | |
| 13038 | tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND; |
| 13039 | pci_dev_put(bridge); |
| 13040 | break; |
| 13041 | } |
| 13042 | } |
| 13043 | } |
| 13044 | |
Matt Carlson | 41588ba | 2008-04-19 18:12:33 -0700 | [diff] [blame] | 13045 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
| 13046 | static struct tg3_dev_id { |
| 13047 | u32 vendor; |
| 13048 | u32 device; |
| 13049 | } bridge_chipsets[] = { |
| 13050 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, |
| 13051 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, |
| 13052 | { }, |
| 13053 | }; |
| 13054 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; |
| 13055 | struct pci_dev *bridge = NULL; |
| 13056 | |
| 13057 | while (pci_id->vendor != 0) { |
| 13058 | bridge = pci_get_device(pci_id->vendor, |
| 13059 | pci_id->device, |
| 13060 | bridge); |
| 13061 | if (!bridge) { |
| 13062 | pci_id++; |
| 13063 | continue; |
| 13064 | } |
| 13065 | if (bridge->subordinate && |
| 13066 | (bridge->subordinate->number <= |
| 13067 | tp->pdev->bus->number) && |
| 13068 | (bridge->subordinate->subordinate >= |
| 13069 | tp->pdev->bus->number)) { |
| 13070 | tp->tg3_flags3 |= TG3_FLG3_5701_DMA_BUG; |
| 13071 | pci_dev_put(bridge); |
| 13072 | break; |
| 13073 | } |
| 13074 | } |
| 13075 | } |
| 13076 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13077 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
| 13078 | * DMA addresses > 40-bit. This bridge may have other additional |
| 13079 | * 57xx devices behind it in some 4-port NIC designs for example. |
| 13080 | * Any tg3 device found behind the bridge will also need the 40-bit |
| 13081 | * DMA workaround. |
| 13082 | */ |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13083 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
| 13084 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 13085 | tp->tg3_flags2 |= TG3_FLG2_5780_CLASS; |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13086 | tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG; |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 13087 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13088 | } |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 13089 | else { |
| 13090 | struct pci_dev *bridge = NULL; |
| 13091 | |
| 13092 | do { |
| 13093 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, |
| 13094 | PCI_DEVICE_ID_SERVERWORKS_EPB, |
| 13095 | bridge); |
| 13096 | if (bridge && bridge->subordinate && |
| 13097 | (bridge->subordinate->number <= |
| 13098 | tp->pdev->bus->number) && |
| 13099 | (bridge->subordinate->subordinate >= |
| 13100 | tp->pdev->bus->number)) { |
| 13101 | tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG; |
| 13102 | pci_dev_put(bridge); |
| 13103 | break; |
| 13104 | } |
| 13105 | } while (bridge); |
| 13106 | } |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 13107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13108 | /* Initialize misc host control in PCI block. */ |
| 13109 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
| 13110 | MISC_HOST_CTRL_CHIPREV); |
| 13111 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 13112 | tp->misc_host_ctrl); |
| 13113 | |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13114 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
| 13115 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || |
| 13116 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13117 | tp->pdev_peer = tg3_find_peer(tp); |
| 13118 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13119 | /* Intentionally exclude ASIC_REV_5906 */ |
| 13120 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Michael Chan | d9ab5ad | 2006-03-20 22:27:35 -0800 | [diff] [blame] | 13121 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13122 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13123 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13124 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13125 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13126 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13127 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13128 | tp->tg3_flags3 |= TG3_FLG3_5755_PLUS; |
| 13129 | |
| 13130 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 13131 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13132 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13133 | (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13134 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
John W. Linville | 6708e5c | 2005-04-21 17:00:52 -0700 | [diff] [blame] | 13135 | tp->tg3_flags2 |= TG3_FLG2_5750_PLUS; |
| 13136 | |
John W. Linville | 1b440c56 | 2005-04-21 17:03:18 -0700 | [diff] [blame] | 13137 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) || |
| 13138 | (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) |
| 13139 | tp->tg3_flags2 |= TG3_FLG2_5705_PLUS; |
| 13140 | |
Matt Carlson | 027455a | 2008-12-21 20:19:30 -0800 | [diff] [blame] | 13141 | /* 5700 B0 chips do not support checksumming correctly due |
| 13142 | * to hardware bugs. |
| 13143 | */ |
| 13144 | if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0) |
| 13145 | tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS; |
| 13146 | else { |
| 13147 | tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; |
| 13148 | tp->dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG; |
| 13149 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
| 13150 | tp->dev->features |= NETIF_F_IPV6_CSUM; |
| 13151 | } |
| 13152 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13153 | /* Determine TSO capabilities */ |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13154 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13155 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 13156 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_3; |
| 13157 | else if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
| 13158 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13159 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2; |
| 13160 | else if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
| 13161 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG; |
| 13162 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && |
| 13163 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) |
| 13164 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG; |
| 13165 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13166 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 13167 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { |
| 13168 | tp->tg3_flags2 |= TG3_FLG2_TSO_BUG; |
| 13169 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) |
| 13170 | tp->fw_needed = FIRMWARE_TG3TSO5; |
| 13171 | else |
| 13172 | tp->fw_needed = FIRMWARE_TG3TSO; |
| 13173 | } |
| 13174 | |
| 13175 | tp->irq_max = 1; |
| 13176 | |
Michael Chan | 5a6f307 | 2006-03-20 22:28:05 -0800 | [diff] [blame] | 13177 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
Michael Chan | 7544b09 | 2007-05-05 13:08:32 -0700 | [diff] [blame] | 13178 | tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI; |
| 13179 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || |
| 13180 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || |
| 13181 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && |
| 13182 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && |
| 13183 | tp->pdev_peer == tp->pdev)) |
| 13184 | tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI; |
| 13185 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13186 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13187 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
Michael Chan | fcfa0a3 | 2006-03-20 22:28:41 -0800 | [diff] [blame] | 13188 | tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI; |
Michael Chan | 52c0fd8 | 2006-06-29 20:15:54 -0700 | [diff] [blame] | 13189 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13190 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13191 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13192 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 13193 | tp->tg3_flags |= TG3_FLAG_SUPPORT_MSIX; |
| 13194 | tp->irq_max = TG3_IRQ_MAX_VECS; |
| 13195 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13196 | } |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 13197 | |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 13198 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13199 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 13200 | tp->tg3_flags3 |= TG3_FLG3_SHORT_DMA_BUG; |
| 13201 | else if (!(tp->tg3_flags3 & TG3_FLG3_5755_PLUS)) { |
| 13202 | tp->tg3_flags3 |= TG3_FLG3_4G_DMA_BNDRY_BUG; |
| 13203 | tp->tg3_flags3 |= TG3_FLG3_40BIT_DMA_LIMIT_BUG; |
Matt Carlson | 0e1406d | 2009-11-02 12:33:33 +0000 | [diff] [blame] | 13204 | } |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13205 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13206 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13207 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
| 13208 | tp->tg3_flags3 |= TG3_FLG3_USE_JUMBO_BDFLAG; |
| 13209 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 13210 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13211 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13212 | (tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG)) |
Matt Carlson | 8f666b0 | 2009-08-28 13:58:24 +0000 | [diff] [blame] | 13213 | tp->tg3_flags |= TG3_FLAG_JUMBO_CAPABLE; |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 13214 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13215 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13216 | &pci_state_reg); |
| 13217 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13218 | tp->pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP); |
| 13219 | if (tp->pcie_cap != 0) { |
| 13220 | u16 lnkctl; |
| 13221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13222 | tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS; |
Matt Carlson | 5f5c51e | 2007-11-12 21:19:37 -0800 | [diff] [blame] | 13223 | |
| 13224 | pcie_set_readrq(tp->pdev, 4096); |
| 13225 | |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13226 | pci_read_config_word(tp->pdev, |
| 13227 | tp->pcie_cap + PCI_EXP_LNKCTL, |
| 13228 | &lnkctl); |
| 13229 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
| 13230 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 13231 | tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2; |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13232 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13233 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 9cf74eb | 2009-04-20 06:58:27 +0000 | [diff] [blame] | 13234 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
| 13235 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) |
Matt Carlson | 5e7dfd0 | 2008-11-21 17:18:16 -0800 | [diff] [blame] | 13236 | tp->tg3_flags3 |= TG3_FLG3_CLKREQ_BUG; |
Matt Carlson | 614b059 | 2010-01-20 16:58:02 +0000 | [diff] [blame] | 13237 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
| 13238 | tp->tg3_flags3 |= TG3_FLG3_L1PLLPD_EN; |
Michael Chan | c7835a7 | 2006-11-15 21:14:42 -0800 | [diff] [blame] | 13239 | } |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13240 | } 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] | 13241 | tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS; |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13242 | } else if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
| 13243 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
| 13244 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
| 13245 | if (!tp->pcix_cap) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 13246 | pr_err("Cannot find PCI-X capability, aborting\n"); |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13247 | return -EIO; |
| 13248 | } |
| 13249 | |
| 13250 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) |
| 13251 | tp->tg3_flags |= TG3_FLAG_PCIX_MODE; |
| 13252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13253 | |
Michael Chan | 399de50 | 2005-10-03 14:02:39 -0700 | [diff] [blame] | 13254 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
| 13255 | * reordering to the mailbox registers done by the host |
| 13256 | * controller can cause major troubles. We read back from |
| 13257 | * every mailbox register write to force the writes to be |
| 13258 | * posted to the chip in order. |
| 13259 | */ |
| 13260 | if (pci_dev_present(write_reorder_chipsets) && |
| 13261 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) |
| 13262 | tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER; |
| 13263 | |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 13264 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 13265 | &tp->pci_cacheline_sz); |
| 13266 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 13267 | &tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13268 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 13269 | tp->pci_lat_timer < 64) { |
| 13270 | tp->pci_lat_timer = 64; |
Matt Carlson | 69fc405 | 2008-12-21 20:19:57 -0800 | [diff] [blame] | 13271 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 13272 | tp->pci_lat_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13273 | } |
| 13274 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13275 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
| 13276 | /* 5700 BX chips need to have their TX producer index |
| 13277 | * mailboxes written twice to workaround a bug. |
| 13278 | */ |
| 13279 | tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13280 | |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13281 | /* If we are in PCI-X mode, enable register write workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13282 | * |
| 13283 | * The workaround is to use indirect register accesses |
| 13284 | * for all chip writes not to mailbox registers. |
| 13285 | */ |
Matt Carlson | 52f4490 | 2008-11-21 17:17:04 -0800 | [diff] [blame] | 13286 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13287 | u32 pm_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13288 | |
| 13289 | tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG; |
| 13290 | |
| 13291 | /* The chip can have it's power management PCI config |
| 13292 | * space registers clobbered due to this bug. |
| 13293 | * So explicitly force the chip into D0 here. |
| 13294 | */ |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13295 | pci_read_config_dword(tp->pdev, |
| 13296 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13297 | &pm_reg); |
| 13298 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; |
| 13299 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; |
Matt Carlson | 9974a35 | 2007-10-07 23:27:28 -0700 | [diff] [blame] | 13300 | pci_write_config_dword(tp->pdev, |
| 13301 | tp->pm_cap + PCI_PM_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13302 | pm_reg); |
| 13303 | |
| 13304 | /* Also, force SERR#/PERR# in PCI command. */ |
| 13305 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13306 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
| 13307 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13308 | } |
| 13309 | } |
| 13310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13311 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
| 13312 | tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED; |
| 13313 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
| 13314 | tp->tg3_flags |= TG3_FLAG_PCI_32BIT; |
| 13315 | |
| 13316 | /* Chip-specific fixup from Broadcom driver */ |
| 13317 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && |
| 13318 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
| 13319 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; |
| 13320 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); |
| 13321 | } |
| 13322 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13323 | /* Default fast path register access methods */ |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13324 | tp->read32 = tg3_read32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13325 | tp->write32 = tg3_write32; |
Michael Chan | 09ee929 | 2005-08-09 20:17:00 -0700 | [diff] [blame] | 13326 | tp->read32_mbox = tg3_read32; |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13327 | tp->write32_mbox = tg3_write32; |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13328 | tp->write32_tx_mbox = tg3_write32; |
| 13329 | tp->write32_rx_mbox = tg3_write32; |
| 13330 | |
| 13331 | /* Various workaround register access methods */ |
| 13332 | if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) |
| 13333 | tp->write32 = tg3_write_indirect_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 13334 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 || |
| 13335 | ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && |
| 13336 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { |
| 13337 | /* |
| 13338 | * Back to back register writes can cause problems on these |
| 13339 | * chips, the workaround is to read back all reg writes |
| 13340 | * except those to mailbox regs. |
| 13341 | * |
| 13342 | * See tg3_write_indirect_reg32(). |
| 13343 | */ |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13344 | tp->write32 = tg3_write_flush_reg32; |
Matt Carlson | 98efd8a | 2007-05-05 12:47:25 -0700 | [diff] [blame] | 13345 | } |
| 13346 | |
Michael Chan | 1ee582d | 2005-08-09 20:16:46 -0700 | [diff] [blame] | 13347 | if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) || |
| 13348 | (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) { |
| 13349 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 13350 | if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) |
| 13351 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 13352 | } |
Michael Chan | 2009493 | 2005-08-09 20:16:32 -0700 | [diff] [blame] | 13353 | |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13354 | if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) { |
| 13355 | tp->read32 = tg3_read_indirect_reg32; |
| 13356 | tp->write32 = tg3_write_indirect_reg32; |
| 13357 | tp->read32_mbox = tg3_read_indirect_mbox; |
| 13358 | tp->write32_mbox = tg3_write_indirect_mbox; |
| 13359 | tp->write32_tx_mbox = tg3_write_indirect_mbox; |
| 13360 | tp->write32_rx_mbox = tg3_write_indirect_mbox; |
| 13361 | |
| 13362 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 13363 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13364 | |
| 13365 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 13366 | pci_cmd &= ~PCI_COMMAND_MEMORY; |
| 13367 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 13368 | } |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 13369 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 13370 | tp->read32_mbox = tg3_read32_mbox_5906; |
| 13371 | tp->write32_mbox = tg3_write32_mbox_5906; |
| 13372 | tp->write32_tx_mbox = tg3_write32_mbox_5906; |
| 13373 | tp->write32_rx_mbox = tg3_write32_mbox_5906; |
| 13374 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 13375 | |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 13376 | if (tp->write32 == tg3_write_indirect_reg32 || |
| 13377 | ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) && |
| 13378 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 13379 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
Michael Chan | bbadf50 | 2006-04-06 21:46:34 -0700 | [diff] [blame] | 13380 | tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG; |
| 13381 | |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13382 | /* Get eeprom hw config before calling tg3_set_power_state(). |
Michael Chan | 9d26e21 | 2006-12-07 00:21:14 -0800 | [diff] [blame] | 13383 | * In particular, the TG3_FLG2_IS_NIC flag must be |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13384 | * determined before calling tg3_set_power_state() so that |
| 13385 | * we know whether or not to switch out of Vaux power. |
| 13386 | * When the flag is set, it means that GPIO1 is used for eeprom |
| 13387 | * write protect and also implies that it is a LOM where GPIOs |
| 13388 | * are not used to switch power. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13389 | */ |
Michael Chan | 7d0c41e | 2005-04-21 17:06:20 -0700 | [diff] [blame] | 13390 | tg3_get_eeprom_hw_cfg(tp); |
| 13391 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 13392 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
| 13393 | /* Allow reads and writes to the |
| 13394 | * APE register and memory space. |
| 13395 | */ |
| 13396 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
| 13397 | PCISTATE_ALLOW_APE_SHMEM_WR; |
| 13398 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13399 | pci_state_reg); |
| 13400 | } |
| 13401 | |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13402 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13403 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13404 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13405 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13406 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13407 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13408 | tp->tg3_flags |= TG3_FLAG_CPMU_PRESENT; |
| 13409 | |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 13410 | /* Set up tp->grc_local_ctrl before calling tg3_set_power_state(). |
| 13411 | * GPIO1 driven high will bring 5700's external PHY out of reset. |
| 13412 | * It is also used as eeprom write protect on LOMs. |
| 13413 | */ |
| 13414 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; |
| 13415 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || |
| 13416 | (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)) |
| 13417 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 13418 | GRC_LCLCTRL_GPIO_OUTPUT1); |
Michael Chan | 3e7d83b | 2005-04-21 17:10:36 -0700 | [diff] [blame] | 13419 | /* Unused GPIO3 must be driven as output on 5752 because there |
| 13420 | * are no pull-up resistors on unused GPIO pins. |
| 13421 | */ |
| 13422 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
| 13423 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
Michael Chan | 314fba3 | 2005-04-21 17:07:04 -0700 | [diff] [blame] | 13424 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13425 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | cb4ed1f | 2010-01-20 16:58:09 +0000 | [diff] [blame] | 13426 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
| 13427 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Michael Chan | af36e6b | 2006-03-23 01:28:06 -0800 | [diff] [blame] | 13428 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 13429 | |
Matt Carlson | 8d519ab | 2009-04-20 06:58:01 +0000 | [diff] [blame] | 13430 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 13431 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
Matt Carlson | 5f0c4a3 | 2008-06-09 15:41:12 -0700 | [diff] [blame] | 13432 | /* Turn off the debug UART. */ |
| 13433 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 13434 | if (tp->tg3_flags2 & TG3_FLG2_IS_NIC) |
| 13435 | /* Keep VMain power. */ |
| 13436 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 13437 | GRC_LCLCTRL_GPIO_OUTPUT0; |
| 13438 | } |
| 13439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13440 | /* Force the chip into D0. */ |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 13441 | err = tg3_set_power_state(tp, PCI_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13442 | if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 13443 | pr_err("(%s) transition to D0 failed\n", pci_name(tp->pdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13444 | return err; |
| 13445 | } |
| 13446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13447 | /* Derive initial jumbo mode from MTU assigned in |
| 13448 | * ether_setup() via the alloc_etherdev() call |
| 13449 | */ |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 13450 | if (tp->dev->mtu > ETH_DATA_LEN && |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13451 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
Michael Chan | 0f893dc | 2005-07-25 12:30:38 -0700 | [diff] [blame] | 13452 | tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13453 | |
| 13454 | /* Determine WakeOnLan speed to use. */ |
| 13455 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 13456 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
| 13457 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || |
| 13458 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { |
| 13459 | tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB); |
| 13460 | } else { |
| 13461 | tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB; |
| 13462 | } |
| 13463 | |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 13464 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
| 13465 | tp->tg3_flags3 |= TG3_FLG3_PHY_IS_FET; |
| 13466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13467 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
| 13468 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || |
| 13469 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && |
| 13470 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13471 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 13472 | (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) || |
Michael Chan | 747e8f8 | 2005-07-25 12:33:22 -0700 | [diff] [blame] | 13473 | (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13474 | tp->tg3_flags2 |= TG3_FLG2_NO_ETH_WIRE_SPEED; |
| 13475 | |
| 13476 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || |
| 13477 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) |
| 13478 | tp->tg3_flags2 |= TG3_FLG2_PHY_ADC_BUG; |
| 13479 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
| 13480 | tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG; |
| 13481 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13482 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 13483 | !(tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET) && |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13484 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
Matt Carlson | f6eb9b1 | 2009-09-01 13:19:53 +0000 | [diff] [blame] | 13485 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13486 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
| 13487 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57765) { |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 13488 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
Matt Carlson | d30cdd2 | 2007-10-07 23:28:35 -0700 | [diff] [blame] | 13489 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 13490 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
| 13491 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
Michael Chan | d4011ad | 2007-02-13 12:17:25 -0800 | [diff] [blame] | 13492 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
| 13493 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) |
| 13494 | tp->tg3_flags2 |= TG3_FLG2_PHY_JITTER_BUG; |
Michael Chan | c1d2a19 | 2007-01-08 19:57:20 -0800 | [diff] [blame] | 13495 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
| 13496 | tp->tg3_flags2 |= TG3_FLG2_PHY_ADJUST_TRIM; |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13497 | } else |
Michael Chan | c424cb2 | 2006-04-29 18:56:34 -0700 | [diff] [blame] | 13498 | tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG; |
| 13499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13500 | |
Matt Carlson | b2a5c19 | 2008-04-03 21:44:44 -0700 | [diff] [blame] | 13501 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 13502 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { |
| 13503 | tp->phy_otp = tg3_read_otp_phycfg(tp); |
| 13504 | if (tp->phy_otp == 0) |
| 13505 | tp->phy_otp = TG3_OTP_DEFAULT; |
| 13506 | } |
| 13507 | |
Matt Carlson | f51f356 | 2008-05-25 23:45:08 -0700 | [diff] [blame] | 13508 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 13509 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
| 13510 | else |
| 13511 | tp->mi_mode = MAC_MI_MODE_BASE; |
| 13512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13513 | tp->coalesce_mode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13514 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
| 13515 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) |
| 13516 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
| 13517 | |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13518 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
| 13519 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 13520 | tp->tg3_flags3 |= TG3_FLG3_USE_PHYLIB; |
| 13521 | |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 13522 | err = tg3_mdio_init(tp); |
| 13523 | if (err) |
| 13524 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13525 | |
Matt Carlson | 55dffe7 | 2010-01-12 10:11:39 +0000 | [diff] [blame] | 13526 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 && |
| 13527 | (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0 || |
| 13528 | (tp->tg3_flags2 & TG3_FLG2_MII_SERDES))) |
| 13529 | return -ENOTSUPP; |
| 13530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13531 | /* Initialize data/descriptor byte/word swapping. */ |
| 13532 | val = tr32(GRC_MODE); |
| 13533 | val &= GRC_MODE_HOST_STACKUP; |
| 13534 | tw32(GRC_MODE, val | tp->grc_mode); |
| 13535 | |
| 13536 | tg3_switch_clocks(tp); |
| 13537 | |
| 13538 | /* Clear this out for sanity. */ |
| 13539 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 13540 | |
| 13541 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 13542 | &pci_state_reg); |
| 13543 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && |
| 13544 | (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) { |
| 13545 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); |
| 13546 | |
| 13547 | if (chiprevid == CHIPREV_ID_5701_A0 || |
| 13548 | chiprevid == CHIPREV_ID_5701_B0 || |
| 13549 | chiprevid == CHIPREV_ID_5701_B2 || |
| 13550 | chiprevid == CHIPREV_ID_5701_B5) { |
| 13551 | void __iomem *sram_base; |
| 13552 | |
| 13553 | /* Write some dummy words into the SRAM status block |
| 13554 | * area, see if it reads back correctly. If the return |
| 13555 | * value is bad, force enable the PCIX workaround. |
| 13556 | */ |
| 13557 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; |
| 13558 | |
| 13559 | writel(0x00000000, sram_base); |
| 13560 | writel(0x00000000, sram_base + 4); |
| 13561 | writel(0xffffffff, sram_base + 4); |
| 13562 | if (readl(sram_base) != 0x00000000) |
| 13563 | tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG; |
| 13564 | } |
| 13565 | } |
| 13566 | |
| 13567 | udelay(50); |
| 13568 | tg3_nvram_init(tp); |
| 13569 | |
| 13570 | grc_misc_cfg = tr32(GRC_MISC_CFG); |
| 13571 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; |
| 13572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13573 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 13574 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
| 13575 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) |
| 13576 | tp->tg3_flags2 |= TG3_FLG2_IS_5788; |
| 13577 | |
David S. Miller | fac9b83 | 2005-05-18 22:46:34 -0700 | [diff] [blame] | 13578 | if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) && |
| 13579 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)) |
| 13580 | tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS; |
| 13581 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) { |
| 13582 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
| 13583 | HOSTCC_MODE_CLRTICK_TXBD); |
| 13584 | |
| 13585 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; |
| 13586 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 13587 | tp->misc_host_ctrl); |
| 13588 | } |
| 13589 | |
Matt Carlson | 3bda125 | 2008-08-15 14:08:22 -0700 | [diff] [blame] | 13590 | /* Preserve the APE MAC_MODE bits */ |
| 13591 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
| 13592 | tp->mac_mode = tr32(MAC_MODE) | |
| 13593 | MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
| 13594 | else |
| 13595 | tp->mac_mode = TG3_DEF_MAC_MODE; |
| 13596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13597 | /* these are limited to 10/100 only */ |
| 13598 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
| 13599 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || |
| 13600 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
| 13601 | tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 13602 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 || |
| 13603 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 || |
| 13604 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) || |
| 13605 | (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && |
| 13606 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F || |
Michael Chan | 676917d | 2006-12-07 00:20:22 -0800 | [diff] [blame] | 13607 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F || |
| 13608 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 13609 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790 || |
Matt Carlson | d110114 | 2010-02-17 15:16:55 +0000 | [diff] [blame] | 13610 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 13611 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
Matt Carlson | 7f97a4b | 2009-08-25 10:10:03 +0000 | [diff] [blame] | 13612 | (tp->tg3_flags3 & TG3_FLG3_PHY_IS_FET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13613 | tp->tg3_flags |= TG3_FLAG_10_100_ONLY; |
| 13614 | |
| 13615 | err = tg3_phy_probe(tp); |
| 13616 | if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 13617 | pr_err("(%s) phy probe failed, err %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13618 | pci_name(tp->pdev), err); |
| 13619 | /* ... but do not return immediately ... */ |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 13620 | tg3_mdio_fini(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13621 | } |
| 13622 | |
| 13623 | tg3_read_partno(tp); |
Michael Chan | c4e6575 | 2006-03-20 22:29:32 -0800 | [diff] [blame] | 13624 | tg3_read_fw_ver(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13625 | |
| 13626 | if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) { |
| 13627 | tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT; |
| 13628 | } else { |
| 13629 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
| 13630 | tp->tg3_flags |= TG3_FLAG_USE_MI_INTERRUPT; |
| 13631 | else |
| 13632 | tp->tg3_flags &= ~TG3_FLAG_USE_MI_INTERRUPT; |
| 13633 | } |
| 13634 | |
| 13635 | /* 5700 {AX,BX} chips have a broken status block link |
| 13636 | * change bit implementation, so we must use the |
| 13637 | * status register in those cases. |
| 13638 | */ |
| 13639 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) |
| 13640 | tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG; |
| 13641 | else |
| 13642 | tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG; |
| 13643 | |
| 13644 | /* The led_ctrl is set during tg3_phy_probe, here we might |
| 13645 | * have to force the link status polling mechanism based |
| 13646 | * upon subsystem IDs. |
| 13647 | */ |
| 13648 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
Michael Chan | 007a880d | 2007-05-31 14:49:51 -0700 | [diff] [blame] | 13649 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13650 | !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) { |
| 13651 | tp->tg3_flags |= (TG3_FLAG_USE_MI_INTERRUPT | |
| 13652 | TG3_FLAG_USE_LINKCHG_REG); |
| 13653 | } |
| 13654 | |
| 13655 | /* For all SERDES we poll the MAC status register. */ |
| 13656 | if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) |
| 13657 | tp->tg3_flags |= TG3_FLAG_POLL_SERDES; |
| 13658 | else |
| 13659 | tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES; |
| 13660 | |
Matt Carlson | ad82926 | 2008-11-21 17:16:16 -0800 | [diff] [blame] | 13661 | tp->rx_offset = NET_IP_ALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13662 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
| 13663 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) |
| 13664 | tp->rx_offset = 0; |
| 13665 | |
Michael Chan | f92905d | 2006-06-29 20:14:29 -0700 | [diff] [blame] | 13666 | tp->rx_std_max_post = TG3_RX_RING_SIZE; |
| 13667 | |
| 13668 | /* Increment the rx prod index on the rx std ring by at most |
| 13669 | * 8 for these chips to workaround hw errata. |
| 13670 | */ |
| 13671 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
| 13672 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
| 13673 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
| 13674 | tp->rx_std_max_post = 8; |
| 13675 | |
Matt Carlson | 8ed5d97 | 2007-05-07 00:25:49 -0700 | [diff] [blame] | 13676 | if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) |
| 13677 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
| 13678 | PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 13679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13680 | return err; |
| 13681 | } |
| 13682 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13683 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13684 | static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp) |
| 13685 | { |
| 13686 | struct net_device *dev = tp->dev; |
| 13687 | struct pci_dev *pdev = tp->pdev; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13688 | struct device_node *dp = pci_device_to_OF_node(pdev); |
David S. Miller | 374d4ca | 2007-03-29 01:57:57 -0700 | [diff] [blame] | 13689 | const unsigned char *addr; |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13690 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13691 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13692 | addr = of_get_property(dp, "local-mac-address", &len); |
| 13693 | if (addr && len == 6) { |
| 13694 | memcpy(dev->dev_addr, addr, 6); |
| 13695 | memcpy(dev->perm_addr, dev->dev_addr, 6); |
| 13696 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13697 | } |
| 13698 | return -ENODEV; |
| 13699 | } |
| 13700 | |
| 13701 | static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp) |
| 13702 | { |
| 13703 | struct net_device *dev = tp->dev; |
| 13704 | |
| 13705 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 13706 | memcpy(dev->perm_addr, idprom->id_ethaddr, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13707 | return 0; |
| 13708 | } |
| 13709 | #endif |
| 13710 | |
| 13711 | static int __devinit tg3_get_device_address(struct tg3 *tp) |
| 13712 | { |
| 13713 | struct net_device *dev = tp->dev; |
| 13714 | u32 hi, lo, mac_offset; |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 13715 | int addr_ok = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13716 | |
David S. Miller | 49b6e95f | 2007-03-29 01:38:42 -0700 | [diff] [blame] | 13717 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13718 | if (!tg3_get_macaddr_sparc(tp)) |
| 13719 | return 0; |
| 13720 | #endif |
| 13721 | |
| 13722 | mac_offset = 0x7c; |
David S. Miller | f49639e | 2006-06-09 11:58:36 -0700 | [diff] [blame] | 13723 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) || |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 13724 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13725 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 13726 | mac_offset = 0xcc; |
| 13727 | if (tg3_nvram_lock(tp)) |
| 13728 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); |
| 13729 | else |
| 13730 | tg3_nvram_unlock(tp); |
Matt Carlson | a1b950d | 2009-09-01 13:20:17 +0000 | [diff] [blame] | 13731 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
| 13732 | if (tr32(TG3_CPMU_STATUS) & TG3_CPMU_STATUS_PCIE_FUNC) |
| 13733 | mac_offset = 0xcc; |
| 13734 | } 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] | 13735 | mac_offset = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13736 | |
| 13737 | /* First try to get it from MAC address mailbox. */ |
| 13738 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); |
| 13739 | if ((hi >> 16) == 0x484b) { |
| 13740 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 13741 | dev->dev_addr[1] = (hi >> 0) & 0xff; |
| 13742 | |
| 13743 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); |
| 13744 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 13745 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 13746 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 13747 | dev->dev_addr[5] = (lo >> 0) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13748 | |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 13749 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
| 13750 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); |
| 13751 | } |
| 13752 | if (!addr_ok) { |
| 13753 | /* Next, try NVRAM. */ |
Matt Carlson | df259d8 | 2009-04-20 06:57:14 +0000 | [diff] [blame] | 13754 | if (!(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) && |
| 13755 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
Matt Carlson | 6d348f2 | 2009-02-25 14:25:52 +0000 | [diff] [blame] | 13756 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
Matt Carlson | 62cedd1 | 2009-04-20 14:52:29 -0700 | [diff] [blame] | 13757 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
| 13758 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); |
Michael Chan | 008652b | 2006-03-27 23:14:53 -0800 | [diff] [blame] | 13759 | } |
| 13760 | /* Finally just fetch it out of the MAC control regs. */ |
| 13761 | else { |
| 13762 | hi = tr32(MAC_ADDR_0_HIGH); |
| 13763 | lo = tr32(MAC_ADDR_0_LOW); |
| 13764 | |
| 13765 | dev->dev_addr[5] = lo & 0xff; |
| 13766 | dev->dev_addr[4] = (lo >> 8) & 0xff; |
| 13767 | dev->dev_addr[3] = (lo >> 16) & 0xff; |
| 13768 | dev->dev_addr[2] = (lo >> 24) & 0xff; |
| 13769 | dev->dev_addr[1] = hi & 0xff; |
| 13770 | dev->dev_addr[0] = (hi >> 8) & 0xff; |
| 13771 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13772 | } |
| 13773 | |
| 13774 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { |
David S. Miller | 7582a33 | 2008-03-20 15:53:15 -0700 | [diff] [blame] | 13775 | #ifdef CONFIG_SPARC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13776 | if (!tg3_get_default_macaddr_sparc(tp)) |
| 13777 | return 0; |
| 13778 | #endif |
| 13779 | return -EINVAL; |
| 13780 | } |
John W. Linville | 2ff4369 | 2005-09-12 14:44:20 -0700 | [diff] [blame] | 13781 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13782 | return 0; |
| 13783 | } |
| 13784 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 13785 | #define BOUNDARY_SINGLE_CACHELINE 1 |
| 13786 | #define BOUNDARY_MULTI_CACHELINE 2 |
| 13787 | |
| 13788 | static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
| 13789 | { |
| 13790 | int cacheline_size; |
| 13791 | u8 byte; |
| 13792 | int goal; |
| 13793 | |
| 13794 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); |
| 13795 | if (byte == 0) |
| 13796 | cacheline_size = 1024; |
| 13797 | else |
| 13798 | cacheline_size = (int) byte * 4; |
| 13799 | |
| 13800 | /* On 5703 and later chips, the boundary bits have no |
| 13801 | * effect. |
| 13802 | */ |
| 13803 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 13804 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && |
| 13805 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) |
| 13806 | goto out; |
| 13807 | |
| 13808 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) |
| 13809 | goal = BOUNDARY_MULTI_CACHELINE; |
| 13810 | #else |
| 13811 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) |
| 13812 | goal = BOUNDARY_SINGLE_CACHELINE; |
| 13813 | #else |
| 13814 | goal = 0; |
| 13815 | #endif |
| 13816 | #endif |
| 13817 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 13818 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 13819 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 13820 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 13821 | goto out; |
| 13822 | } |
| 13823 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 13824 | if (!goal) |
| 13825 | goto out; |
| 13826 | |
| 13827 | /* PCI controllers on most RISC systems tend to disconnect |
| 13828 | * when a device tries to burst across a cache-line boundary. |
| 13829 | * Therefore, letting tg3 do so just wastes PCI bandwidth. |
| 13830 | * |
| 13831 | * Unfortunately, for PCI-E there are only limited |
| 13832 | * write-side controls for this, and thus for reads |
| 13833 | * we will still get the disconnects. We'll also waste |
| 13834 | * these PCI cycles for both read and write for chips |
| 13835 | * other than 5700 and 5701 which do not implement the |
| 13836 | * boundary bits. |
| 13837 | */ |
| 13838 | if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) && |
| 13839 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) { |
| 13840 | switch (cacheline_size) { |
| 13841 | case 16: |
| 13842 | case 32: |
| 13843 | case 64: |
| 13844 | case 128: |
| 13845 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 13846 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | |
| 13847 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); |
| 13848 | } else { |
| 13849 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 13850 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 13851 | } |
| 13852 | break; |
| 13853 | |
| 13854 | case 256: |
| 13855 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | |
| 13856 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); |
| 13857 | break; |
| 13858 | |
| 13859 | default: |
| 13860 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 13861 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 13862 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 13863 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 13864 | } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 13865 | switch (cacheline_size) { |
| 13866 | case 16: |
| 13867 | case 32: |
| 13868 | case 64: |
| 13869 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 13870 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 13871 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; |
| 13872 | break; |
| 13873 | } |
| 13874 | /* fallthrough */ |
| 13875 | case 128: |
| 13876 | default: |
| 13877 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 13878 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; |
| 13879 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 13880 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 13881 | } else { |
| 13882 | switch (cacheline_size) { |
| 13883 | case 16: |
| 13884 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 13885 | val |= (DMA_RWCTRL_READ_BNDRY_16 | |
| 13886 | DMA_RWCTRL_WRITE_BNDRY_16); |
| 13887 | break; |
| 13888 | } |
| 13889 | /* fallthrough */ |
| 13890 | case 32: |
| 13891 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 13892 | val |= (DMA_RWCTRL_READ_BNDRY_32 | |
| 13893 | DMA_RWCTRL_WRITE_BNDRY_32); |
| 13894 | break; |
| 13895 | } |
| 13896 | /* fallthrough */ |
| 13897 | case 64: |
| 13898 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 13899 | val |= (DMA_RWCTRL_READ_BNDRY_64 | |
| 13900 | DMA_RWCTRL_WRITE_BNDRY_64); |
| 13901 | break; |
| 13902 | } |
| 13903 | /* fallthrough */ |
| 13904 | case 128: |
| 13905 | if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 13906 | val |= (DMA_RWCTRL_READ_BNDRY_128 | |
| 13907 | DMA_RWCTRL_WRITE_BNDRY_128); |
| 13908 | break; |
| 13909 | } |
| 13910 | /* fallthrough */ |
| 13911 | case 256: |
| 13912 | val |= (DMA_RWCTRL_READ_BNDRY_256 | |
| 13913 | DMA_RWCTRL_WRITE_BNDRY_256); |
| 13914 | break; |
| 13915 | case 512: |
| 13916 | val |= (DMA_RWCTRL_READ_BNDRY_512 | |
| 13917 | DMA_RWCTRL_WRITE_BNDRY_512); |
| 13918 | break; |
| 13919 | case 1024: |
| 13920 | default: |
| 13921 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | |
| 13922 | DMA_RWCTRL_WRITE_BNDRY_1024); |
| 13923 | break; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 13924 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 13925 | } |
| 13926 | |
| 13927 | out: |
| 13928 | return val; |
| 13929 | } |
| 13930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13931 | static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) |
| 13932 | { |
| 13933 | struct tg3_internal_buffer_desc test_desc; |
| 13934 | u32 sram_dma_descs; |
| 13935 | int i, ret; |
| 13936 | |
| 13937 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; |
| 13938 | |
| 13939 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); |
| 13940 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); |
| 13941 | tw32(RDMAC_STATUS, 0); |
| 13942 | tw32(WDMAC_STATUS, 0); |
| 13943 | |
| 13944 | tw32(BUFMGR_MODE, 0); |
| 13945 | tw32(FTQ_RESET, 0); |
| 13946 | |
| 13947 | test_desc.addr_hi = ((u64) buf_dma) >> 32; |
| 13948 | test_desc.addr_lo = buf_dma & 0xffffffff; |
| 13949 | test_desc.nic_mbuf = 0x00002100; |
| 13950 | test_desc.len = size; |
| 13951 | |
| 13952 | /* |
| 13953 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz |
| 13954 | * the *second* time the tg3 driver was getting loaded after an |
| 13955 | * initial scan. |
| 13956 | * |
| 13957 | * Broadcom tells me: |
| 13958 | * ...the DMA engine is connected to the GRC block and a DMA |
| 13959 | * reset may affect the GRC block in some unpredictable way... |
| 13960 | * The behavior of resets to individual blocks has not been tested. |
| 13961 | * |
| 13962 | * Broadcom noted the GRC reset will also reset all sub-components. |
| 13963 | */ |
| 13964 | if (to_device) { |
| 13965 | test_desc.cqid_sqid = (13 << 8) | 2; |
| 13966 | |
| 13967 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); |
| 13968 | udelay(40); |
| 13969 | } else { |
| 13970 | test_desc.cqid_sqid = (16 << 8) | 7; |
| 13971 | |
| 13972 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); |
| 13973 | udelay(40); |
| 13974 | } |
| 13975 | test_desc.flags = 0x00000005; |
| 13976 | |
| 13977 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { |
| 13978 | u32 val; |
| 13979 | |
| 13980 | val = *(((u32 *)&test_desc) + i); |
| 13981 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, |
| 13982 | sram_dma_descs + (i * sizeof(u32))); |
| 13983 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 13984 | } |
| 13985 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 13986 | |
| 13987 | if (to_device) { |
| 13988 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
| 13989 | } else { |
| 13990 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
| 13991 | } |
| 13992 | |
| 13993 | ret = -ENODEV; |
| 13994 | for (i = 0; i < 40; i++) { |
| 13995 | u32 val; |
| 13996 | |
| 13997 | if (to_device) |
| 13998 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); |
| 13999 | else |
| 14000 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); |
| 14001 | if ((val & 0xffff) == sram_dma_descs) { |
| 14002 | ret = 0; |
| 14003 | break; |
| 14004 | } |
| 14005 | |
| 14006 | udelay(100); |
| 14007 | } |
| 14008 | |
| 14009 | return ret; |
| 14010 | } |
| 14011 | |
David S. Miller | ded7340 | 2005-05-23 13:59:47 -0700 | [diff] [blame] | 14012 | #define TEST_BUFFER_SIZE 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14013 | |
| 14014 | static int __devinit tg3_test_dma(struct tg3 *tp) |
| 14015 | { |
| 14016 | dma_addr_t buf_dma; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14017 | u32 *buf, saved_dma_rwctrl; |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14018 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14019 | |
| 14020 | buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma); |
| 14021 | if (!buf) { |
| 14022 | ret = -ENOMEM; |
| 14023 | goto out_nofree; |
| 14024 | } |
| 14025 | |
| 14026 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | |
| 14027 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); |
| 14028 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14029 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14030 | |
Matt Carlson | b703df6 | 2009-12-03 08:36:21 +0000 | [diff] [blame] | 14031 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14032 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
Matt Carlson | cbf9ca6 | 2009-11-13 13:03:40 +0000 | [diff] [blame] | 14033 | goto out; |
| 14034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14035 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 14036 | /* DMA read watermark not used on PCIE */ |
| 14037 | tp->dma_rwctrl |= 0x00180000; |
| 14038 | } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) { |
Michael Chan | 85e94ce | 2005-04-21 17:05:28 -0700 | [diff] [blame] | 14039 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
| 14040 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14041 | tp->dma_rwctrl |= 0x003f0000; |
| 14042 | else |
| 14043 | tp->dma_rwctrl |= 0x003f000f; |
| 14044 | } else { |
| 14045 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 14046 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
| 14047 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14048 | u32 read_water = 0x7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14049 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14050 | /* If the 5704 is behind the EPB bridge, we can |
| 14051 | * do the less restrictive ONE_DMA workaround for |
| 14052 | * better performance. |
| 14053 | */ |
| 14054 | if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) && |
| 14055 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 14056 | tp->dma_rwctrl |= 0x8000; |
| 14057 | else if (ccval == 0x6 || ccval == 0x7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14058 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 14059 | |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14060 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
| 14061 | read_water = 4; |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14062 | /* Set bit 23 to enable PCIX hw bug fix */ |
Michael Chan | 49afdeb | 2007-02-13 12:17:03 -0800 | [diff] [blame] | 14063 | tp->dma_rwctrl |= |
| 14064 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | |
| 14065 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | |
| 14066 | (1 << 23); |
Michael Chan | 4cf78e4 | 2005-07-25 12:29:19 -0700 | [diff] [blame] | 14067 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
| 14068 | /* 5780 always in PCIX mode */ |
| 14069 | tp->dma_rwctrl |= 0x00144000; |
Michael Chan | a4e2b34 | 2005-10-26 15:46:52 -0700 | [diff] [blame] | 14070 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
| 14071 | /* 5714 always in PCIX mode */ |
| 14072 | tp->dma_rwctrl |= 0x00148000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14073 | } else { |
| 14074 | tp->dma_rwctrl |= 0x001b000f; |
| 14075 | } |
| 14076 | } |
| 14077 | |
| 14078 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
| 14079 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
| 14080 | tp->dma_rwctrl &= 0xfffffff0; |
| 14081 | |
| 14082 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
| 14083 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { |
| 14084 | /* Remove this if it causes problems for some boards. */ |
| 14085 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; |
| 14086 | |
| 14087 | /* On 5700/5701 chips, we need to set this bit. |
| 14088 | * Otherwise the chip will issue cacheline transactions |
| 14089 | * to streamable DMA memory with not all the byte |
| 14090 | * enables turned on. This is an error on several |
| 14091 | * RISC PCI controllers, in particular sparc64. |
| 14092 | * |
| 14093 | * On 5703/5704 chips, this bit has been reassigned |
| 14094 | * a different meaning. In particular, it is used |
| 14095 | * on those chips to enable a PCI-X workaround. |
| 14096 | */ |
| 14097 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; |
| 14098 | } |
| 14099 | |
| 14100 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14101 | |
| 14102 | #if 0 |
| 14103 | /* Unneeded, already done by tg3_get_invariants. */ |
| 14104 | tg3_switch_clocks(tp); |
| 14105 | #endif |
| 14106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14107 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
| 14108 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
| 14109 | goto out; |
| 14110 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14111 | /* It is best to perform DMA test with maximum write burst size |
| 14112 | * to expose the 5700/5701 write DMA bug. |
| 14113 | */ |
| 14114 | saved_dma_rwctrl = tp->dma_rwctrl; |
| 14115 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 14116 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14118 | while (1) { |
| 14119 | u32 *p = buf, i; |
| 14120 | |
| 14121 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) |
| 14122 | p[i] = i; |
| 14123 | |
| 14124 | /* Send the buffer to the chip. */ |
| 14125 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); |
| 14126 | if (ret) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14127 | pr_err("tg3_test_dma() Write the buffer failed %d\n", |
| 14128 | ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14129 | break; |
| 14130 | } |
| 14131 | |
| 14132 | #if 0 |
| 14133 | /* validate data reached card RAM correctly. */ |
| 14134 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 14135 | u32 val; |
| 14136 | tg3_read_mem(tp, 0x2100 + (i*4), &val); |
| 14137 | if (le32_to_cpu(val) != p[i]) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14138 | pr_err(" tg3_test_dma() Card buffer corrupted on write! (%d != %d)\n", |
| 14139 | val, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14140 | /* ret = -ENODEV here? */ |
| 14141 | } |
| 14142 | p[i] = 0; |
| 14143 | } |
| 14144 | #endif |
| 14145 | /* Now read it back. */ |
| 14146 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); |
| 14147 | if (ret) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14148 | pr_err("tg3_test_dma() Read the buffer failed %d\n", |
| 14149 | ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14150 | |
| 14151 | break; |
| 14152 | } |
| 14153 | |
| 14154 | /* Verify it. */ |
| 14155 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 14156 | if (p[i] == i) |
| 14157 | continue; |
| 14158 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14159 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 14160 | DMA_RWCTRL_WRITE_BNDRY_16) { |
| 14161 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14162 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 14163 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14164 | break; |
| 14165 | } else { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14166 | pr_err("tg3_test_dma() buffer corrupted on read back! (%d != %d)\n", |
| 14167 | p[i], i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14168 | ret = -ENODEV; |
| 14169 | goto out; |
| 14170 | } |
| 14171 | } |
| 14172 | |
| 14173 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { |
| 14174 | /* Success. */ |
| 14175 | ret = 0; |
| 14176 | break; |
| 14177 | } |
| 14178 | } |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14179 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 14180 | DMA_RWCTRL_WRITE_BNDRY_16) { |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14181 | static struct pci_device_id dma_wait_state_chipsets[] = { |
| 14182 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, |
| 14183 | PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
| 14184 | { }, |
| 14185 | }; |
| 14186 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14187 | /* DMA test passed without adjusting DMA boundary, |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14188 | * now look for chipsets that are known to expose the |
| 14189 | * DMA bug without failing the test. |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14190 | */ |
Michael Chan | 6d1cfba | 2005-06-08 14:13:14 -0700 | [diff] [blame] | 14191 | if (pci_dev_present(dma_wait_state_chipsets)) { |
| 14192 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 14193 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 14194 | } |
| 14195 | else |
| 14196 | /* Safe to use the calculated DMA boundary. */ |
| 14197 | tp->dma_rwctrl = saved_dma_rwctrl; |
| 14198 | |
David S. Miller | 59e6b43 | 2005-05-18 22:50:10 -0700 | [diff] [blame] | 14199 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 14200 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14201 | |
| 14202 | out: |
| 14203 | pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma); |
| 14204 | out_nofree: |
| 14205 | return ret; |
| 14206 | } |
| 14207 | |
| 14208 | static void __devinit tg3_init_link_config(struct tg3 *tp) |
| 14209 | { |
| 14210 | tp->link_config.advertising = |
| 14211 | (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 14212 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 14213 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full | |
| 14214 | ADVERTISED_Autoneg | ADVERTISED_MII); |
| 14215 | tp->link_config.speed = SPEED_INVALID; |
| 14216 | tp->link_config.duplex = DUPLEX_INVALID; |
| 14217 | tp->link_config.autoneg = AUTONEG_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14218 | tp->link_config.active_speed = SPEED_INVALID; |
| 14219 | tp->link_config.active_duplex = DUPLEX_INVALID; |
| 14220 | tp->link_config.phy_is_low_power = 0; |
| 14221 | tp->link_config.orig_speed = SPEED_INVALID; |
| 14222 | tp->link_config.orig_duplex = DUPLEX_INVALID; |
| 14223 | tp->link_config.orig_autoneg = AUTONEG_INVALID; |
| 14224 | } |
| 14225 | |
| 14226 | static void __devinit tg3_init_bufmgr_config(struct tg3 *tp) |
| 14227 | { |
Matt Carlson | 666bc83 | 2010-01-20 16:58:03 +0000 | [diff] [blame] | 14228 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
| 14229 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
| 14230 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14231 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14232 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14233 | DEFAULT_MB_MACRX_LOW_WATER_57765; |
| 14234 | tp->bufmgr_config.mbuf_high_water = |
| 14235 | DEFAULT_MB_HIGH_WATER_57765; |
| 14236 | |
| 14237 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14238 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14239 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14240 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; |
| 14241 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14242 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; |
| 14243 | } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14244 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14245 | DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 14246 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14247 | DEFAULT_MB_MACRX_LOW_WATER_5705; |
| 14248 | tp->bufmgr_config.mbuf_high_water = |
| 14249 | DEFAULT_MB_HIGH_WATER_5705; |
Michael Chan | b5d3772 | 2006-09-27 16:06:21 -0700 | [diff] [blame] | 14250 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
| 14251 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14252 | DEFAULT_MB_MACRX_LOW_WATER_5906; |
| 14253 | tp->bufmgr_config.mbuf_high_water = |
| 14254 | DEFAULT_MB_HIGH_WATER_5906; |
| 14255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14256 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14257 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14258 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; |
| 14259 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14260 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; |
| 14261 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14262 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; |
| 14263 | } else { |
| 14264 | tp->bufmgr_config.mbuf_read_dma_low_water = |
| 14265 | DEFAULT_MB_RDMA_LOW_WATER; |
| 14266 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 14267 | DEFAULT_MB_MACRX_LOW_WATER; |
| 14268 | tp->bufmgr_config.mbuf_high_water = |
| 14269 | DEFAULT_MB_HIGH_WATER; |
| 14270 | |
| 14271 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 14272 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; |
| 14273 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 14274 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; |
| 14275 | tp->bufmgr_config.mbuf_high_water_jumbo = |
| 14276 | DEFAULT_MB_HIGH_WATER_JUMBO; |
| 14277 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14278 | |
| 14279 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; |
| 14280 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; |
| 14281 | } |
| 14282 | |
| 14283 | static char * __devinit tg3_phy_string(struct tg3 *tp) |
| 14284 | { |
Matt Carlson | 79eb690 | 2010-02-17 15:17:03 +0000 | [diff] [blame] | 14285 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
| 14286 | case TG3_PHY_ID_BCM5400: return "5400"; |
| 14287 | case TG3_PHY_ID_BCM5401: return "5401"; |
| 14288 | case TG3_PHY_ID_BCM5411: return "5411"; |
| 14289 | case TG3_PHY_ID_BCM5701: return "5701"; |
| 14290 | case TG3_PHY_ID_BCM5703: return "5703"; |
| 14291 | case TG3_PHY_ID_BCM5704: return "5704"; |
| 14292 | case TG3_PHY_ID_BCM5705: return "5705"; |
| 14293 | case TG3_PHY_ID_BCM5750: return "5750"; |
| 14294 | case TG3_PHY_ID_BCM5752: return "5752"; |
| 14295 | case TG3_PHY_ID_BCM5714: return "5714"; |
| 14296 | case TG3_PHY_ID_BCM5780: return "5780"; |
| 14297 | case TG3_PHY_ID_BCM5755: return "5755"; |
| 14298 | case TG3_PHY_ID_BCM5787: return "5787"; |
| 14299 | case TG3_PHY_ID_BCM5784: return "5784"; |
| 14300 | case TG3_PHY_ID_BCM5756: return "5722/5756"; |
| 14301 | case TG3_PHY_ID_BCM5906: return "5906"; |
| 14302 | case TG3_PHY_ID_BCM5761: return "5761"; |
| 14303 | case TG3_PHY_ID_BCM5718C: return "5718C"; |
| 14304 | case TG3_PHY_ID_BCM5718S: return "5718S"; |
| 14305 | case TG3_PHY_ID_BCM57765: return "57765"; |
| 14306 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14307 | case 0: return "serdes"; |
| 14308 | default: return "unknown"; |
Stephen Hemminger | 855e111 | 2008-04-16 16:37:28 -0700 | [diff] [blame] | 14309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14310 | } |
| 14311 | |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14312 | static char * __devinit tg3_bus_string(struct tg3 *tp, char *str) |
| 14313 | { |
| 14314 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
| 14315 | strcpy(str, "PCI Express"); |
| 14316 | return str; |
| 14317 | } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
| 14318 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
| 14319 | |
| 14320 | strcpy(str, "PCIX:"); |
| 14321 | |
| 14322 | if ((clock_ctrl == 7) || |
| 14323 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == |
| 14324 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) |
| 14325 | strcat(str, "133MHz"); |
| 14326 | else if (clock_ctrl == 0) |
| 14327 | strcat(str, "33MHz"); |
| 14328 | else if (clock_ctrl == 2) |
| 14329 | strcat(str, "50MHz"); |
| 14330 | else if (clock_ctrl == 4) |
| 14331 | strcat(str, "66MHz"); |
| 14332 | else if (clock_ctrl == 6) |
| 14333 | strcat(str, "100MHz"); |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14334 | } else { |
| 14335 | strcpy(str, "PCI:"); |
| 14336 | if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED) |
| 14337 | strcat(str, "66MHz"); |
| 14338 | else |
| 14339 | strcat(str, "33MHz"); |
| 14340 | } |
| 14341 | if (tp->tg3_flags & TG3_FLAG_PCI_32BIT) |
| 14342 | strcat(str, ":32-bit"); |
| 14343 | else |
| 14344 | strcat(str, ":64-bit"); |
| 14345 | return str; |
| 14346 | } |
| 14347 | |
Michael Chan | 8c2dc7e | 2005-12-19 16:26:02 -0800 | [diff] [blame] | 14348 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14349 | { |
| 14350 | struct pci_dev *peer; |
| 14351 | unsigned int func, devnr = tp->pdev->devfn & ~7; |
| 14352 | |
| 14353 | for (func = 0; func < 8; func++) { |
| 14354 | peer = pci_get_slot(tp->pdev->bus, devnr | func); |
| 14355 | if (peer && peer != tp->pdev) |
| 14356 | break; |
| 14357 | pci_dev_put(peer); |
| 14358 | } |
Michael Chan | 16fe9d7 | 2005-12-13 21:09:54 -0800 | [diff] [blame] | 14359 | /* 5704 can be configured in single-port mode, set peer to |
| 14360 | * tp->pdev in that case. |
| 14361 | */ |
| 14362 | if (!peer) { |
| 14363 | peer = tp->pdev; |
| 14364 | return peer; |
| 14365 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14366 | |
| 14367 | /* |
| 14368 | * We don't need to keep the refcount elevated; there's no way |
| 14369 | * to remove one half of this device without removing the other |
| 14370 | */ |
| 14371 | pci_dev_put(peer); |
| 14372 | |
| 14373 | return peer; |
| 14374 | } |
| 14375 | |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 14376 | static void __devinit tg3_init_coal(struct tg3 *tp) |
| 14377 | { |
| 14378 | struct ethtool_coalesce *ec = &tp->coal; |
| 14379 | |
| 14380 | memset(ec, 0, sizeof(*ec)); |
| 14381 | ec->cmd = ETHTOOL_GCOALESCE; |
| 14382 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; |
| 14383 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; |
| 14384 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; |
| 14385 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; |
| 14386 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; |
| 14387 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; |
| 14388 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; |
| 14389 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; |
| 14390 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; |
| 14391 | |
| 14392 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | |
| 14393 | HOSTCC_MODE_CLRTICK_TXBD)) { |
| 14394 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; |
| 14395 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; |
| 14396 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; |
| 14397 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; |
| 14398 | } |
Michael Chan | d244c89 | 2005-07-05 14:42:33 -0700 | [diff] [blame] | 14399 | |
| 14400 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { |
| 14401 | ec->rx_coalesce_usecs_irq = 0; |
| 14402 | ec->tx_coalesce_usecs_irq = 0; |
| 14403 | ec->stats_block_coalesce_usecs = 0; |
| 14404 | } |
David S. Miller | 15f9850 | 2005-05-18 22:49:26 -0700 | [diff] [blame] | 14405 | } |
| 14406 | |
Stephen Hemminger | 7c7d64b | 2008-11-19 22:25:36 -0800 | [diff] [blame] | 14407 | static const struct net_device_ops tg3_netdev_ops = { |
| 14408 | .ndo_open = tg3_open, |
| 14409 | .ndo_stop = tg3_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14410 | .ndo_start_xmit = tg3_start_xmit, |
| 14411 | .ndo_get_stats = tg3_get_stats, |
| 14412 | .ndo_validate_addr = eth_validate_addr, |
| 14413 | .ndo_set_multicast_list = tg3_set_rx_mode, |
| 14414 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 14415 | .ndo_do_ioctl = tg3_ioctl, |
| 14416 | .ndo_tx_timeout = tg3_tx_timeout, |
| 14417 | .ndo_change_mtu = tg3_change_mtu, |
| 14418 | #if TG3_VLAN_TAG_USED |
| 14419 | .ndo_vlan_rx_register = tg3_vlan_rx_register, |
| 14420 | #endif |
| 14421 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 14422 | .ndo_poll_controller = tg3_poll_controller, |
| 14423 | #endif |
| 14424 | }; |
| 14425 | |
| 14426 | static const struct net_device_ops tg3_netdev_ops_dma_bug = { |
| 14427 | .ndo_open = tg3_open, |
| 14428 | .ndo_stop = tg3_close, |
| 14429 | .ndo_start_xmit = tg3_start_xmit_dma_bug, |
Stephen Hemminger | 7c7d64b | 2008-11-19 22:25:36 -0800 | [diff] [blame] | 14430 | .ndo_get_stats = tg3_get_stats, |
| 14431 | .ndo_validate_addr = eth_validate_addr, |
| 14432 | .ndo_set_multicast_list = tg3_set_rx_mode, |
| 14433 | .ndo_set_mac_address = tg3_set_mac_addr, |
| 14434 | .ndo_do_ioctl = tg3_ioctl, |
| 14435 | .ndo_tx_timeout = tg3_tx_timeout, |
| 14436 | .ndo_change_mtu = tg3_change_mtu, |
| 14437 | #if TG3_VLAN_TAG_USED |
| 14438 | .ndo_vlan_rx_register = tg3_vlan_rx_register, |
| 14439 | #endif |
| 14440 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 14441 | .ndo_poll_controller = tg3_poll_controller, |
| 14442 | #endif |
| 14443 | }; |
| 14444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14445 | static int __devinit tg3_init_one(struct pci_dev *pdev, |
| 14446 | const struct pci_device_id *ent) |
| 14447 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14448 | struct net_device *dev; |
| 14449 | struct tg3 *tp; |
Matt Carlson | 646c9ed | 2009-09-01 12:58:41 +0000 | [diff] [blame] | 14450 | int i, err, pm_cap; |
| 14451 | u32 sndmbx, rcvmbx, intmbx; |
Michael Chan | f9804dd | 2005-09-27 12:13:10 -0700 | [diff] [blame] | 14452 | char str[40]; |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14453 | u64 dma_mask, persist_dma_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14454 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14455 | printk_once(KERN_INFO "%s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14456 | |
| 14457 | err = pci_enable_device(pdev); |
| 14458 | if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14459 | pr_err("Cannot enable PCI device, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14460 | return err; |
| 14461 | } |
| 14462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14463 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 14464 | if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14465 | pr_err("Cannot obtain PCI resources, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14466 | goto err_out_disable_pdev; |
| 14467 | } |
| 14468 | |
| 14469 | pci_set_master(pdev); |
| 14470 | |
| 14471 | /* Find power-management capability. */ |
| 14472 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 14473 | if (pm_cap == 0) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14474 | pr_err("Cannot find PowerManagement capability, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14475 | err = -EIO; |
| 14476 | goto err_out_free_res; |
| 14477 | } |
| 14478 | |
Matt Carlson | fe5f578 | 2009-09-01 13:09:39 +0000 | [diff] [blame] | 14479 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14480 | if (!dev) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14481 | pr_err("Etherdev alloc failed, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14482 | err = -ENOMEM; |
| 14483 | goto err_out_free_res; |
| 14484 | } |
| 14485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14486 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 14487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14488 | #if TG3_VLAN_TAG_USED |
| 14489 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14490 | #endif |
| 14491 | |
| 14492 | tp = netdev_priv(dev); |
| 14493 | tp->pdev = pdev; |
| 14494 | tp->dev = dev; |
| 14495 | tp->pm_cap = pm_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14496 | tp->rx_mode = TG3_DEF_RX_MODE; |
| 14497 | tp->tx_mode = TG3_DEF_TX_MODE; |
Matt Carlson | 8ef2142 | 2008-05-02 16:47:53 -0700 | [diff] [blame] | 14498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14499 | if (tg3_debug > 0) |
| 14500 | tp->msg_enable = tg3_debug; |
| 14501 | else |
| 14502 | tp->msg_enable = TG3_DEF_MSG_ENABLE; |
| 14503 | |
| 14504 | /* The word/byte swap controls here control register access byte |
| 14505 | * swapping. DMA data byte swapping is controlled in the GRC_MODE |
| 14506 | * setting below. |
| 14507 | */ |
| 14508 | tp->misc_host_ctrl = |
| 14509 | MISC_HOST_CTRL_MASK_PCI_INT | |
| 14510 | MISC_HOST_CTRL_WORD_SWAP | |
| 14511 | MISC_HOST_CTRL_INDIR_ACCESS | |
| 14512 | MISC_HOST_CTRL_PCISTATE_RW; |
| 14513 | |
| 14514 | /* The NONFRM (non-frame) byte/word swap controls take effect |
| 14515 | * on descriptor entries, anything which isn't packet data. |
| 14516 | * |
| 14517 | * The StrongARM chips on the board (one for tx, one for rx) |
| 14518 | * are running in big-endian mode. |
| 14519 | */ |
| 14520 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | |
| 14521 | GRC_MODE_WSWAP_NONFRM_DATA); |
| 14522 | #ifdef __BIG_ENDIAN |
| 14523 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; |
| 14524 | #endif |
| 14525 | spin_lock_init(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14526 | spin_lock_init(&tp->indirect_lock); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 14527 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14528 | |
Matt Carlson | d5fe488 | 2008-11-21 17:20:32 -0800 | [diff] [blame] | 14529 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
Andy Gospodarek | ab0049b | 2007-09-06 20:42:14 +0100 | [diff] [blame] | 14530 | if (!tp->regs) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14531 | netdev_err(dev, "Cannot map device registers, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14532 | err = -ENOMEM; |
| 14533 | goto err_out_free_dev; |
| 14534 | } |
| 14535 | |
| 14536 | tg3_init_link_config(tp); |
| 14537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14538 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
| 14539 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14541 | dev->ethtool_ops = &tg3_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14542 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14543 | dev->irq = pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14544 | |
| 14545 | err = tg3_get_invariants(tp); |
| 14546 | if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14547 | netdev_err(dev, "Problem fetching invariants of chip, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14548 | goto err_out_iounmap; |
| 14549 | } |
| 14550 | |
Matt Carlson | 615774f | 2009-11-13 13:03:39 +0000 | [diff] [blame] | 14551 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) && |
| 14552 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 14553 | dev->netdev_ops = &tg3_netdev_ops; |
| 14554 | else |
| 14555 | dev->netdev_ops = &tg3_netdev_ops_dma_bug; |
| 14556 | |
| 14557 | |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14558 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
| 14559 | * device behind the EPB cannot support DMA addresses > 40-bit. |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14560 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
| 14561 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and |
| 14562 | * do DMA address check in tg3_start_xmit(). |
| 14563 | */ |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14564 | if (tp->tg3_flags2 & TG3_FLG2_IS_5788) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 14565 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14566 | else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) { |
Yang Hongyang | 50cf156 | 2009-04-06 19:01:14 -0700 | [diff] [blame] | 14567 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14568 | #ifdef CONFIG_HIGHMEM |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 14569 | dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14570 | #endif |
Michael Chan | 4a29cc2 | 2006-03-19 13:21:12 -0800 | [diff] [blame] | 14571 | } else |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 14572 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14573 | |
| 14574 | /* Configure DMA attributes. */ |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 14575 | if (dma_mask > DMA_BIT_MASK(32)) { |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14576 | err = pci_set_dma_mask(pdev, dma_mask); |
| 14577 | if (!err) { |
| 14578 | dev->features |= NETIF_F_HIGHDMA; |
| 14579 | err = pci_set_consistent_dma_mask(pdev, |
| 14580 | persist_dma_mask); |
| 14581 | if (err < 0) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14582 | netdev_err(dev, "Unable to obtain 64 bit DMA for consistent allocations\n"); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14583 | goto err_out_iounmap; |
| 14584 | } |
| 14585 | } |
| 14586 | } |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 14587 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
| 14588 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14589 | if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14590 | netdev_err(dev, "No usable DMA configuration, aborting\n"); |
Michael Chan | 72f2afb | 2006-03-06 19:28:35 -0800 | [diff] [blame] | 14591 | goto err_out_iounmap; |
| 14592 | } |
| 14593 | } |
| 14594 | |
Michael Chan | fdfec172 | 2005-07-25 12:31:48 -0700 | [diff] [blame] | 14595 | tg3_init_bufmgr_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14596 | |
Matt Carlson | 507399f | 2009-11-13 13:03:37 +0000 | [diff] [blame] | 14597 | /* Selectively allow TSO based on operating conditions */ |
| 14598 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) || |
| 14599 | (tp->fw_needed && !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) |
| 14600 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
| 14601 | else { |
| 14602 | tp->tg3_flags2 &= ~(TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG); |
| 14603 | tp->fw_needed = NULL; |
| 14604 | } |
| 14605 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 14606 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) |
Matt Carlson | 9e9fd12 | 2009-01-19 16:57:45 -0800 | [diff] [blame] | 14607 | tp->fw_needed = FIRMWARE_TG3; |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 14608 | |
Michael Chan | 4e3a7aa | 2006-03-20 17:47:44 -0800 | [diff] [blame] | 14609 | /* TSO is on by default on chips that support hardware TSO. |
| 14610 | * Firmware TSO on older chips gives lower performance, so it |
| 14611 | * is off by default, but can be enabled using ethtool. |
| 14612 | */ |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14613 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) && |
| 14614 | (dev->features & NETIF_F_IP_CSUM)) |
| 14615 | dev->features |= NETIF_F_TSO; |
| 14616 | |
| 14617 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) || |
| 14618 | (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3)) { |
| 14619 | if (dev->features & NETIF_F_IPV6_CSUM) |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 14620 | dev->features |= NETIF_F_TSO6; |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14621 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
| 14622 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
Matt Carlson | 57e6983 | 2008-05-25 23:48:31 -0700 | [diff] [blame] | 14623 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
| 14624 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || |
Matt Carlson | 321d32a | 2008-11-21 17:22:19 -0800 | [diff] [blame] | 14625 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
Matt Carlson | e849cdc | 2009-11-13 13:03:38 +0000 | [diff] [blame] | 14626 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
Matt Carlson | 9936bcf | 2007-10-10 18:03:07 -0700 | [diff] [blame] | 14627 | dev->features |= NETIF_F_TSO_ECN; |
Michael Chan | b002662 | 2006-07-03 19:42:14 -0700 | [diff] [blame] | 14628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14630 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
| 14631 | !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) && |
| 14632 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
| 14633 | tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64; |
| 14634 | tp->rx_pending = 63; |
| 14635 | } |
| 14636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14637 | err = tg3_get_device_address(tp); |
| 14638 | if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14639 | netdev_err(dev, "Could not obtain valid ethernet address, aborting\n"); |
Matt Carlson | 026a6c2 | 2009-12-03 08:36:24 +0000 | [diff] [blame] | 14640 | goto err_out_iounmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14641 | } |
| 14642 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14643 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
Matt Carlson | 6353239 | 2008-11-03 16:49:57 -0800 | [diff] [blame] | 14644 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 14645 | if (!tp->aperegs) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14646 | netdev_err(dev, "Cannot map APE registers, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14647 | err = -ENOMEM; |
Matt Carlson | 026a6c2 | 2009-12-03 08:36:24 +0000 | [diff] [blame] | 14648 | goto err_out_iounmap; |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14649 | } |
| 14650 | |
| 14651 | tg3_ape_lock_init(tp); |
Matt Carlson | 7fd7644 | 2009-02-25 14:27:20 +0000 | [diff] [blame] | 14652 | |
| 14653 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) |
| 14654 | tg3_read_dash_ver(tp); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14655 | } |
| 14656 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14657 | /* |
| 14658 | * Reset chip in case UNDI or EFI driver did not shutdown |
| 14659 | * DMA self test will enable WDMAC and we'll see (spurious) |
| 14660 | * pending DMA on the PCI bus at that point. |
| 14661 | */ |
| 14662 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
| 14663 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 14664 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
| 14665 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 14666 | } |
| 14667 | |
| 14668 | err = tg3_test_dma(tp); |
| 14669 | if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14670 | netdev_err(dev, "DMA engine test failed, aborting\n"); |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14671 | goto err_out_apeunmap; |
| 14672 | } |
| 14673 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14674 | /* flow control autonegotiation is default behavior */ |
| 14675 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; |
Steve Glendinning | e18ce34 | 2008-12-16 02:00:00 -0800 | [diff] [blame] | 14676 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14677 | |
Matt Carlson | 78f90dc | 2009-11-13 13:03:42 +0000 | [diff] [blame] | 14678 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
| 14679 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; |
| 14680 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 14681 | for (i = 0; i < TG3_IRQ_MAX_VECS; i++) { |
| 14682 | struct tg3_napi *tnapi = &tp->napi[i]; |
| 14683 | |
| 14684 | tnapi->tp = tp; |
| 14685 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; |
| 14686 | |
| 14687 | tnapi->int_mbox = intmbx; |
| 14688 | if (i < 4) |
| 14689 | intmbx += 0x8; |
| 14690 | else |
| 14691 | intmbx += 0x4; |
| 14692 | |
| 14693 | tnapi->consmbox = rcvmbx; |
| 14694 | tnapi->prodmbox = sndmbx; |
| 14695 | |
| 14696 | if (i) { |
| 14697 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
| 14698 | netif_napi_add(dev, &tnapi->napi, tg3_poll_msix, 64); |
| 14699 | } else { |
| 14700 | tnapi->coal_now = HOSTCC_MODE_NOW; |
| 14701 | netif_napi_add(dev, &tnapi->napi, tg3_poll, 64); |
| 14702 | } |
| 14703 | |
| 14704 | if (!(tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX)) |
| 14705 | break; |
| 14706 | |
| 14707 | /* |
| 14708 | * If we support MSIX, we'll be using RSS. If we're using |
| 14709 | * RSS, the first vector only handles link interrupts and the |
| 14710 | * remaining vectors handle rx and tx interrupts. Reuse the |
| 14711 | * mailbox values for the next iteration. The values we setup |
| 14712 | * above are still useful for the single vectored mode. |
| 14713 | */ |
| 14714 | if (!i) |
| 14715 | continue; |
| 14716 | |
| 14717 | rcvmbx += 0x8; |
| 14718 | |
| 14719 | if (sndmbx & 0x4) |
| 14720 | sndmbx -= 0x4; |
| 14721 | else |
| 14722 | sndmbx += 0xc; |
| 14723 | } |
| 14724 | |
Matt Carlson | c88864d | 2007-11-12 21:07:01 -0800 | [diff] [blame] | 14725 | tg3_init_coal(tp); |
| 14726 | |
Michael Chan | c49a156 | 2006-12-17 17:07:29 -0800 | [diff] [blame] | 14727 | pci_set_drvdata(pdev, dev); |
| 14728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14729 | err = register_netdev(dev); |
| 14730 | if (err) { |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14731 | netdev_err(dev, "Cannot register net device, aborting\n"); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14732 | goto err_out_apeunmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14733 | } |
| 14734 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14735 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
| 14736 | tp->board_part_number, |
| 14737 | tp->pci_chip_rev_id, |
| 14738 | tg3_bus_string(tp, str), |
| 14739 | dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14740 | |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 14741 | if (tp->tg3_flags3 & TG3_FLG3_PHY_CONNECTED) { |
| 14742 | struct phy_device *phydev; |
| 14743 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14744 | netdev_info(dev, "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", |
| 14745 | phydev->drv->name, dev_name(&phydev->dev)); |
Matt Carlson | 3f0e3ad | 2009-11-02 14:24:36 +0000 | [diff] [blame] | 14746 | } else |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14747 | netdev_info(dev, "attached PHY is %s (%s Ethernet) (WireSpeed[%d])\n", |
| 14748 | tg3_phy_string(tp), |
| 14749 | ((tp->tg3_flags & TG3_FLAG_10_100_ONLY) ? "10/100Base-TX" : |
| 14750 | ((tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) ? "1000Base-SX" : |
| 14751 | "10/100/1000Base-T")), |
| 14752 | (tp->tg3_flags2 & TG3_FLG2_NO_ETH_WIRE_SPEED) == 0); |
Matt Carlson | df59c94 | 2008-11-03 16:52:56 -0800 | [diff] [blame] | 14753 | |
Joe Perches | 05dbe00 | 2010-02-17 19:44:19 +0000 | [diff] [blame^] | 14754 | netdev_info(dev, "RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n", |
| 14755 | (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0, |
| 14756 | (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0, |
| 14757 | (tp->tg3_flags & TG3_FLAG_USE_MI_INTERRUPT) != 0, |
| 14758 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0, |
| 14759 | (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0); |
| 14760 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
| 14761 | tp->dma_rwctrl, |
| 14762 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : |
| 14763 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14764 | |
| 14765 | return 0; |
| 14766 | |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14767 | err_out_apeunmap: |
| 14768 | if (tp->aperegs) { |
| 14769 | iounmap(tp->aperegs); |
| 14770 | tp->aperegs = NULL; |
| 14771 | } |
| 14772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14773 | err_out_iounmap: |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14774 | if (tp->regs) { |
| 14775 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 14776 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14777 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14778 | |
| 14779 | err_out_free_dev: |
| 14780 | free_netdev(dev); |
| 14781 | |
| 14782 | err_out_free_res: |
| 14783 | pci_release_regions(pdev); |
| 14784 | |
| 14785 | err_out_disable_pdev: |
| 14786 | pci_disable_device(pdev); |
| 14787 | pci_set_drvdata(pdev, NULL); |
| 14788 | return err; |
| 14789 | } |
| 14790 | |
| 14791 | static void __devexit tg3_remove_one(struct pci_dev *pdev) |
| 14792 | { |
| 14793 | struct net_device *dev = pci_get_drvdata(pdev); |
| 14794 | |
| 14795 | if (dev) { |
| 14796 | struct tg3 *tp = netdev_priv(dev); |
| 14797 | |
Jaswinder Singh Rajput | 077f849 | 2009-01-04 16:11:25 -0800 | [diff] [blame] | 14798 | if (tp->fw) |
| 14799 | release_firmware(tp->fw); |
| 14800 | |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 14801 | flush_scheduled_work(); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 14802 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14803 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
| 14804 | tg3_phy_fini(tp); |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 14805 | tg3_mdio_fini(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14806 | } |
Matt Carlson | 158d7ab | 2008-05-29 01:37:54 -0700 | [diff] [blame] | 14807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14808 | unregister_netdev(dev); |
Matt Carlson | 0d3031d | 2007-10-10 18:02:43 -0700 | [diff] [blame] | 14809 | if (tp->aperegs) { |
| 14810 | iounmap(tp->aperegs); |
| 14811 | tp->aperegs = NULL; |
| 14812 | } |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14813 | if (tp->regs) { |
| 14814 | iounmap(tp->regs); |
Peter Hagervall | 22abe31 | 2005-09-16 17:01:03 -0700 | [diff] [blame] | 14815 | tp->regs = NULL; |
Michael Chan | 6892914 | 2005-08-09 20:17:14 -0700 | [diff] [blame] | 14816 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14817 | free_netdev(dev); |
| 14818 | pci_release_regions(pdev); |
| 14819 | pci_disable_device(pdev); |
| 14820 | pci_set_drvdata(pdev, NULL); |
| 14821 | } |
| 14822 | } |
| 14823 | |
| 14824 | static int tg3_suspend(struct pci_dev *pdev, pm_message_t state) |
| 14825 | { |
| 14826 | struct net_device *dev = pci_get_drvdata(pdev); |
| 14827 | struct tg3 *tp = netdev_priv(dev); |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 14828 | pci_power_t target_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14829 | int err; |
| 14830 | |
Michael Chan | 3e0c95f | 2007-08-03 20:56:54 -0700 | [diff] [blame] | 14831 | /* PCI register 4 needs to be saved whether netif_running() or not. |
| 14832 | * MSI address and data need to be saved if using MSI and |
| 14833 | * netif_running(). |
| 14834 | */ |
| 14835 | pci_save_state(pdev); |
| 14836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14837 | if (!netif_running(dev)) |
| 14838 | return 0; |
| 14839 | |
Michael Chan | 7faa006 | 2006-02-02 17:29:28 -0800 | [diff] [blame] | 14840 | flush_scheduled_work(); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14841 | tg3_phy_stop(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14842 | tg3_netif_stop(tp); |
| 14843 | |
| 14844 | del_timer_sync(&tp->timer); |
| 14845 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 14846 | tg3_full_lock(tp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14847 | tg3_disable_ints(tp); |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 14848 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14849 | |
| 14850 | netif_device_detach(dev); |
| 14851 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 14852 | tg3_full_lock(tp, 0); |
Michael Chan | 944d980 | 2005-05-29 14:57:48 -0700 | [diff] [blame] | 14853 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
Michael Chan | 6a9eba1 | 2005-12-13 21:08:58 -0800 | [diff] [blame] | 14854 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 14855 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14856 | |
Rafael J. Wysocki | 12dac07 | 2008-07-30 16:37:33 -0700 | [diff] [blame] | 14857 | target_state = pdev->pm_cap ? pci_target_state(pdev) : PCI_D3hot; |
| 14858 | |
| 14859 | err = tg3_set_power_state(tp, target_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14860 | if (err) { |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14861 | int err2; |
| 14862 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 14863 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14864 | |
Michael Chan | 6a9eba1 | 2005-12-13 21:08:58 -0800 | [diff] [blame] | 14865 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14866 | err2 = tg3_restart_hw(tp, 1); |
| 14867 | if (err2) |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 14868 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14869 | |
| 14870 | tp->timer.expires = jiffies + tp->timer_offset; |
| 14871 | add_timer(&tp->timer); |
| 14872 | |
| 14873 | netif_device_attach(dev); |
| 14874 | tg3_netif_start(tp); |
| 14875 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 14876 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 14877 | tg3_full_unlock(tp); |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14878 | |
| 14879 | if (!err2) |
| 14880 | tg3_phy_start(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14881 | } |
| 14882 | |
| 14883 | return err; |
| 14884 | } |
| 14885 | |
| 14886 | static int tg3_resume(struct pci_dev *pdev) |
| 14887 | { |
| 14888 | struct net_device *dev = pci_get_drvdata(pdev); |
| 14889 | struct tg3 *tp = netdev_priv(dev); |
| 14890 | int err; |
| 14891 | |
Michael Chan | 3e0c95f | 2007-08-03 20:56:54 -0700 | [diff] [blame] | 14892 | pci_restore_state(tp->pdev); |
| 14893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14894 | if (!netif_running(dev)) |
| 14895 | return 0; |
| 14896 | |
Michael Chan | bc1c756 | 2006-03-20 17:48:03 -0800 | [diff] [blame] | 14897 | err = tg3_set_power_state(tp, PCI_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14898 | if (err) |
| 14899 | return err; |
| 14900 | |
| 14901 | netif_device_attach(dev); |
| 14902 | |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 14903 | tg3_full_lock(tp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14904 | |
Michael Chan | 6a9eba1 | 2005-12-13 21:08:58 -0800 | [diff] [blame] | 14905 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 14906 | err = tg3_restart_hw(tp, 1); |
| 14907 | if (err) |
| 14908 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14909 | |
| 14910 | tp->timer.expires = jiffies + tp->timer_offset; |
| 14911 | add_timer(&tp->timer); |
| 14912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14913 | tg3_netif_start(tp); |
| 14914 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 14915 | out: |
David S. Miller | f47c11e | 2005-06-24 20:18:35 -0700 | [diff] [blame] | 14916 | tg3_full_unlock(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14917 | |
Matt Carlson | b02fd9e | 2008-05-25 23:47:41 -0700 | [diff] [blame] | 14918 | if (!err) |
| 14919 | tg3_phy_start(tp); |
| 14920 | |
Michael Chan | b9ec6c1 | 2006-07-25 16:37:27 -0700 | [diff] [blame] | 14921 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14922 | } |
| 14923 | |
| 14924 | static struct pci_driver tg3_driver = { |
| 14925 | .name = DRV_MODULE_NAME, |
| 14926 | .id_table = tg3_pci_tbl, |
| 14927 | .probe = tg3_init_one, |
| 14928 | .remove = __devexit_p(tg3_remove_one), |
| 14929 | .suspend = tg3_suspend, |
| 14930 | .resume = tg3_resume |
| 14931 | }; |
| 14932 | |
| 14933 | static int __init tg3_init(void) |
| 14934 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 14935 | return pci_register_driver(&tg3_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14936 | } |
| 14937 | |
| 14938 | static void __exit tg3_cleanup(void) |
| 14939 | { |
| 14940 | pci_unregister_driver(&tg3_driver); |
| 14941 | } |
| 14942 | |
| 14943 | module_init(tg3_init); |
| 14944 | module_exit(tg3_cleanup); |