| 1 |
/* |
| 2 |
* tg3.c: Broadcom Tigon3 ethernet driver. |
| 3 |
* |
| 4 |
* Copyright (C) 2001, 2002, 2003, 2004 David S. Miller ([email protected]) |
| 5 |
* Copyright (C) 2001, 2002, 2003 Jeff Garzik ([email protected]) |
| 6 |
* Copyright (C) 2004 Sun Microsystems Inc. |
| 7 |
* Copyright (C) 2005-2016 Broadcom Corporation. |
| 8 |
* Copyright (C) 2016-2017 Broadcom Limited. |
| 9 |
* Copyright (C) 2018 Broadcom. All Rights Reserved. The term "Broadcom" |
| 10 |
* refers to Broadcom Inc. and/or its subsidiaries. |
| 11 |
* |
| 12 |
* Firmware is: |
| 13 |
* Derived from proprietary unpublished source code, |
| 14 |
* Copyright (C) 2000-2016 Broadcom Corporation. |
| 15 |
* Copyright (C) 2016-2017 Broadcom Ltd. |
| 16 |
* Copyright (C) 2018 Broadcom. All Rights Reserved. The term "Broadcom" |
| 17 |
* refers to Broadcom Inc. and/or its subsidiaries. |
| 18 |
* |
| 19 |
* Permission is hereby granted for the distribution of this firmware |
| 20 |
* data in hexadecimal or equivalent format, provided this copyright |
| 21 |
* notice is accompanying it. |
| 22 |
*/ |
| 23 |
|
| 24 |
|
| 25 |
#include <linux/module.h> |
| 26 |
#include <linux/moduleparam.h> |
| 27 |
#include <linux/stringify.h> |
| 28 |
#include <linux/kernel.h> |
| 29 |
#include <linux/sched/signal.h> |
| 30 |
#include <linux/types.h> |
| 31 |
#include <linux/compiler.h> |
| 32 |
#include <linux/slab.h> |
| 33 |
#include <linux/delay.h> |
| 34 |
#include <linux/in.h> |
| 35 |
#include <linux/interrupt.h> |
| 36 |
#include <linux/ioport.h> |
| 37 |
#include <linux/pci.h> |
| 38 |
#include <linux/netdevice.h> |
| 39 |
#include <linux/etherdevice.h> |
| 40 |
#include <linux/skbuff.h> |
| 41 |
#include <linux/ethtool.h> |
| 42 |
#include <linux/mdio.h> |
| 43 |
#include <linux/mii.h> |
| 44 |
#include <linux/phy.h> |
| 45 |
#include <linux/brcmphy.h> |
| 46 |
#include <linux/if.h> |
| 47 |
#include <linux/if_vlan.h> |
| 48 |
#include <linux/ip.h> |
| 49 |
#include <linux/tcp.h> |
| 50 |
#include <linux/workqueue.h> |
| 51 |
#include <linux/prefetch.h> |
| 52 |
#include <linux/dma-mapping.h> |
| 53 |
#include <linux/firmware.h> |
| 54 |
#include <linux/ssb/ssb_driver_gige.h> |
| 55 |
#include <linux/hwmon.h> |
| 56 |
#include <linux/hwmon-sysfs.h> |
| 57 |
#include <linux/crc32.h> |
| 58 |
#include <linux/dmi.h> |
| 59 |
|
| 60 |
#include <net/checksum.h> |
| 61 |
#include <net/gso.h> |
| 62 |
#include <net/ip.h> |
| 63 |
|
| 64 |
#include <linux/io.h> |
| 65 |
#include <asm/byteorder.h> |
| 66 |
#include <linux/uaccess.h> |
| 67 |
|
| 68 |
#include <uapi/linux/net_tstamp.h> |
| 69 |
#include <linux/ptp_clock_kernel.h> |
| 70 |
|
| 71 |
#define BAR_0 0 |
| 72 |
#define BAR_2 2 |
| 73 |
|
| 74 |
#include "tg3.h" |
| 75 |
|
| 76 |
/* Functions & macros to verify TG3_FLAGS types */ |
| 77 |
|
| 78 |
static inline int _tg3_flag(enum TG3_FLAGS flag, unsigned long *bits) |
| 79 |
{ |
| 80 |
return test_bit(flag, bits); |
| 81 |
} |
| 82 |
|
| 83 |
static inline void _tg3_flag_set(enum TG3_FLAGS flag, unsigned long *bits) |
| 84 |
{ |
| 85 |
set_bit(flag, bits); |
| 86 |
} |
| 87 |
|
| 88 |
static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits) |
| 89 |
{ |
| 90 |
clear_bit(flag, bits); |
| 91 |
} |
| 92 |
|
| 93 |
#define tg3_flag(tp, flag) \ |
| 94 |
_tg3_flag(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 95 |
#define tg3_flag_set(tp, flag) \ |
| 96 |
_tg3_flag_set(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 97 |
#define tg3_flag_clear(tp, flag) \ |
| 98 |
_tg3_flag_clear(TG3_FLAG_##flag, (tp)->tg3_flags) |
| 99 |
|
| 100 |
#define DRV_MODULE_NAME "tg3" |
| 101 |
/* DO NOT UPDATE TG3_*_NUM defines */ |
| 102 |
#define TG3_MAJ_NUM 3 |
| 103 |
#define TG3_MIN_NUM 137 |
| 104 |
|
| 105 |
#define RESET_KIND_SHUTDOWN 0 |
| 106 |
#define RESET_KIND_INIT 1 |
| 107 |
#define RESET_KIND_SUSPEND 2 |
| 108 |
|
| 109 |
#define TG3_DEF_RX_MODE 0 |
| 110 |
#define TG3_DEF_TX_MODE 0 |
| 111 |
#define TG3_DEF_MSG_ENABLE \ |
| 112 |
(NETIF_MSG_DRV | \ |
| 113 |
NETIF_MSG_PROBE | \ |
| 114 |
NETIF_MSG_LINK | \ |
| 115 |
NETIF_MSG_TIMER | \ |
| 116 |
NETIF_MSG_IFDOWN | \ |
| 117 |
NETIF_MSG_IFUP | \ |
| 118 |
NETIF_MSG_RX_ERR | \ |
| 119 |
NETIF_MSG_TX_ERR) |
| 120 |
|
| 121 |
#define TG3_GRC_LCLCTL_PWRSW_DELAY 100 |
| 122 |
|
| 123 |
/* length of time before we decide the hardware is borked, |
| 124 |
* and dev->tx_timeout() should be called to fix the problem |
| 125 |
*/ |
| 126 |
|
| 127 |
#define TG3_TX_TIMEOUT (5 * HZ) |
| 128 |
|
| 129 |
/* hardware minimum and maximum for a single frame's data payload */ |
| 130 |
#define TG3_MIN_MTU ETH_ZLEN |
| 131 |
#define TG3_MAX_MTU(tp) \ |
| 132 |
(tg3_flag(tp, JUMBO_CAPABLE) ? 9000 : 1500) |
| 133 |
|
| 134 |
/* These numbers seem to be hard coded in the NIC firmware somehow. |
| 135 |
* You can't change the ring sizes, but you can change where you place |
| 136 |
* them in the NIC onboard memory. |
| 137 |
*/ |
| 138 |
#define TG3_RX_STD_RING_SIZE(tp) \ |
| 139 |
(tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
| 140 |
TG3_RX_STD_MAX_SIZE_5717 : TG3_RX_STD_MAX_SIZE_5700) |
| 141 |
#define TG3_DEF_RX_RING_PENDING 200 |
| 142 |
#define TG3_RX_JMB_RING_SIZE(tp) \ |
| 143 |
(tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
| 144 |
TG3_RX_JMB_MAX_SIZE_5717 : TG3_RX_JMB_MAX_SIZE_5700) |
| 145 |
#define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
| 146 |
|
| 147 |
/* Do not place this n-ring entries value into the tp struct itself, |
| 148 |
* we really want to expose these constants to GCC so that modulo et |
| 149 |
* al. operations are done with shifts and masks instead of with |
| 150 |
* hw multiply/modulo instructions. Another solution would be to |
| 151 |
* replace things like '% foo' with '& (foo - 1)'. |
| 152 |
*/ |
| 153 |
|
| 154 |
#define TG3_TX_RING_SIZE 512 |
| 155 |
#define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) |
| 156 |
|
| 157 |
#define TG3_RX_STD_RING_BYTES(tp) \ |
| 158 |
(sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) |
| 159 |
#define TG3_RX_JMB_RING_BYTES(tp) \ |
| 160 |
(sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) |
| 161 |
#define TG3_RX_RCB_RING_BYTES(tp) \ |
| 162 |
(sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
| 163 |
#define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
| 164 |
TG3_TX_RING_SIZE) |
| 165 |
#define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
| 166 |
|
| 167 |
#define TG3_DMA_BYTE_ENAB 64 |
| 168 |
|
| 169 |
#define TG3_RX_STD_DMA_SZ 1536 |
| 170 |
#define TG3_RX_JMB_DMA_SZ 9046 |
| 171 |
|
| 172 |
#define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) |
| 173 |
|
| 174 |
#define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) |
| 175 |
#define TG3_RX_JMB_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_JMB_DMA_SZ) |
| 176 |
|
| 177 |
#define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
| 178 |
(sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) |
| 179 |
|
| 180 |
#define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
| 181 |
(sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) |
| 182 |
|
| 183 |
/* Due to a hardware bug, the 5701 can only DMA to memory addresses |
| 184 |
* that are at least dword aligned when used in PCIX mode. The driver |
| 185 |
* works around this bug by double copying the packet. This workaround |
| 186 |
* is built into the normal double copy length check for efficiency. |
| 187 |
* |
| 188 |
* However, the double copy is only necessary on those architectures |
| 189 |
* where unaligned memory accesses are inefficient. For those architectures |
| 190 |
* where unaligned memory accesses incur little penalty, we can reintegrate |
| 191 |
* the 5701 in the normal rx path. Doing so saves a device structure |
| 192 |
* dereference by hardcoding the double copy threshold in place. |
| 193 |
*/ |
| 194 |
#define TG3_RX_COPY_THRESHOLD 256 |
| 195 |
#if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) |
| 196 |
#define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD |
| 197 |
#else |
| 198 |
#define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) |
| 199 |
#endif |
| 200 |
|
| 201 |
#if (NET_IP_ALIGN != 0) |
| 202 |
#define TG3_RX_OFFSET(tp) ((tp)->rx_offset) |
| 203 |
#else |
| 204 |
#define TG3_RX_OFFSET(tp) (NET_SKB_PAD) |
| 205 |
#endif |
| 206 |
|
| 207 |
/* minimum number of free TX descriptors required to wake up TX process */ |
| 208 |
#define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
| 209 |
#define TG3_TX_BD_DMA_MAX_2K 2048 |
| 210 |
#define TG3_TX_BD_DMA_MAX_4K 4096 |
| 211 |
|
| 212 |
#define TG3_RAW_IP_ALIGN 2 |
| 213 |
|
| 214 |
#define TG3_MAX_UCAST_ADDR(tp) (tg3_flag((tp), ENABLE_ASF) ? 2 : 3) |
| 215 |
#define TG3_UCAST_ADDR_IDX(tp) (tg3_flag((tp), ENABLE_ASF) ? 2 : 1) |
| 216 |
|
| 217 |
#define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
| 218 |
#define TG3_FW_UPDATE_FREQ_SEC (TG3_FW_UPDATE_TIMEOUT_SEC / 2) |
| 219 |
|
| 220 |
#define FIRMWARE_TG3 "tigon/tg3.bin" |
| 221 |
#define FIRMWARE_TG357766 "tigon/tg357766.bin" |
| 222 |
#define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
| 223 |
#define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" |
| 224 |
|
| 225 |
MODULE_AUTHOR("David S. Miller <[email protected]> and Jeff Garzik <[email protected]>"); |
| 226 |
MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); |
| 227 |
MODULE_LICENSE("GPL"); |
| 228 |
MODULE_FIRMWARE(FIRMWARE_TG3); |
| 229 |
MODULE_FIRMWARE(FIRMWARE_TG357766); |
| 230 |
MODULE_FIRMWARE(FIRMWARE_TG3TSO); |
| 231 |
MODULE_FIRMWARE(FIRMWARE_TG3TSO5); |
| 232 |
|
| 233 |
static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
| 234 |
module_param(tg3_debug, int, 0); |
| 235 |
MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); |
| 236 |
|
| 237 |
#define TG3_DRV_DATA_FLAG_10_100_ONLY 0x0001 |
| 238 |
#define TG3_DRV_DATA_FLAG_5705_10_100 0x0002 |
| 239 |
|
| 240 |
static const struct pci_device_id tg3_pci_tbl[] = { |
| 241 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
| 242 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, |
| 243 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, |
| 244 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, |
| 245 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, |
| 246 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, |
| 247 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, |
| 248 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, |
| 249 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, |
| 250 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, |
| 251 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, |
| 252 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, |
| 253 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, |
| 254 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, |
| 255 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, |
| 256 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, |
| 257 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, |
| 258 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, |
| 259 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901), |
| 260 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 261 |
TG3_DRV_DATA_FLAG_5705_10_100}, |
| 262 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2), |
| 263 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 264 |
TG3_DRV_DATA_FLAG_5705_10_100}, |
| 265 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, |
| 266 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F), |
| 267 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | |
| 268 |
TG3_DRV_DATA_FLAG_5705_10_100}, |
| 269 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
| 270 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
| 271 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)}, |
| 272 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
| 273 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
| 274 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F), |
| 275 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 276 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
| 277 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, |
| 278 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, |
| 279 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, |
| 280 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F), |
| 281 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 282 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
| 283 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, |
| 284 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, |
| 285 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, |
| 286 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
| 287 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
| 288 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, |
| 289 |
{PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5787M, |
| 290 |
PCI_VENDOR_ID_LENOVO, |
| 291 |
TG3PCI_SUBDEVICE_ID_LENOVO_5787M), |
| 292 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 293 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, |
| 294 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F), |
| 295 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 296 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
| 297 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, |
| 298 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, |
| 299 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, |
| 300 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, |
| 301 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, |
| 302 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, |
| 303 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
| 304 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, |
| 305 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
| 306 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, |
| 307 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
| 308 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
| 309 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, |
| 310 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
| 311 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, |
| 312 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
| 313 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, |
| 314 |
{PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780, |
| 315 |
PCI_VENDOR_ID_AI, TG3PCI_SUBDEVICE_ID_ACER_57780_A), |
| 316 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 317 |
{PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780, |
| 318 |
PCI_VENDOR_ID_AI, TG3PCI_SUBDEVICE_ID_ACER_57780_B), |
| 319 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 320 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
| 321 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, |
| 322 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790), |
| 323 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 324 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
| 325 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
| 326 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717_C)}, |
| 327 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
| 328 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
| 329 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, |
| 330 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, |
| 331 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, |
| 332 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791), |
| 333 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 334 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795), |
| 335 |
.driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, |
| 336 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
| 337 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, |
| 338 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57762)}, |
| 339 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57766)}, |
| 340 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5762)}, |
| 341 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5725)}, |
| 342 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5727)}, |
| 343 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57764)}, |
| 344 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57767)}, |
| 345 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57787)}, |
| 346 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57782)}, |
| 347 |
{PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57786)}, |
| 348 |
{PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
| 349 |
{PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, |
| 350 |
{PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, |
| 351 |
{PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, |
| 352 |
{PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, |
| 353 |
{PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, |
| 354 |
{PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, |
| 355 |
{PCI_DEVICE(0x10cf, 0x11a2)}, /* Fujitsu 1000base-SX with BCM5703SKHB */ |
| 356 |
{} |
| 357 |
}; |
| 358 |
|
| 359 |
MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); |
| 360 |
|
| 361 |
static const struct { |
| 362 |
const char string[ETH_GSTRING_LEN]; |
| 363 |
} ethtool_stats_keys[] = { |
| 364 |
{ "rx_octets" }, |
| 365 |
{ "rx_fragments" }, |
| 366 |
{ "rx_ucast_packets" }, |
| 367 |
{ "rx_mcast_packets" }, |
| 368 |
{ "rx_bcast_packets" }, |
| 369 |
{ "rx_fcs_errors" }, |
| 370 |
{ "rx_align_errors" }, |
| 371 |
{ "rx_xon_pause_rcvd" }, |
| 372 |
{ "rx_xoff_pause_rcvd" }, |
| 373 |
{ "rx_mac_ctrl_rcvd" }, |
| 374 |
{ "rx_xoff_entered" }, |
| 375 |
{ "rx_frame_too_long_errors" }, |
| 376 |
{ "rx_jabbers" }, |
| 377 |
{ "rx_undersize_packets" }, |
| 378 |
{ "rx_in_length_errors" }, |
| 379 |
{ "rx_out_length_errors" }, |
| 380 |
{ "rx_64_or_less_octet_packets" }, |
| 381 |
{ "rx_65_to_127_octet_packets" }, |
| 382 |
{ "rx_128_to_255_octet_packets" }, |
| 383 |
{ "rx_256_to_511_octet_packets" }, |
| 384 |
{ "rx_512_to_1023_octet_packets" }, |
| 385 |
{ "rx_1024_to_1522_octet_packets" }, |
| 386 |
{ "rx_1523_to_2047_octet_packets" }, |
| 387 |
{ "rx_2048_to_4095_octet_packets" }, |
| 388 |
{ "rx_4096_to_8191_octet_packets" }, |
| 389 |
{ "rx_8192_to_9022_octet_packets" }, |
| 390 |
|
| 391 |
{ "tx_octets" }, |
| 392 |
{ "tx_collisions" }, |
| 393 |
|
| 394 |
{ "tx_xon_sent" }, |
| 395 |
{ "tx_xoff_sent" }, |
| 396 |
{ "tx_flow_control" }, |
| 397 |
{ "tx_mac_errors" }, |
| 398 |
{ "tx_single_collisions" }, |
| 399 |
{ "tx_mult_collisions" }, |
| 400 |
{ "tx_deferred" }, |
| 401 |
{ "tx_excessive_collisions" }, |
| 402 |
{ "tx_late_collisions" }, |
| 403 |
{ "tx_collide_2times" }, |
| 404 |
{ "tx_collide_3times" }, |
| 405 |
{ "tx_collide_4times" }, |
| 406 |
{ "tx_collide_5times" }, |
| 407 |
{ "tx_collide_6times" }, |
| 408 |
{ "tx_collide_7times" }, |
| 409 |
{ "tx_collide_8times" }, |
| 410 |
{ "tx_collide_9times" }, |
| 411 |
{ "tx_collide_10times" }, |
| 412 |
{ "tx_collide_11times" }, |
| 413 |
{ "tx_collide_12times" }, |
| 414 |
{ "tx_collide_13times" }, |
| 415 |
{ "tx_collide_14times" }, |
| 416 |
{ "tx_collide_15times" }, |
| 417 |
{ "tx_ucast_packets" }, |
| 418 |
{ "tx_mcast_packets" }, |
| 419 |
{ "tx_bcast_packets" }, |
| 420 |
{ "tx_carrier_sense_errors" }, |
| 421 |
{ "tx_discards" }, |
| 422 |
{ "tx_errors" }, |
| 423 |
|
| 424 |
{ "dma_writeq_full" }, |
| 425 |
{ "dma_write_prioq_full" }, |
| 426 |
{ "rxbds_empty" }, |
| 427 |
{ "rx_discards" }, |
| 428 |
{ "rx_errors" }, |
| 429 |
{ "rx_threshold_hit" }, |
| 430 |
|
| 431 |
{ "dma_readq_full" }, |
| 432 |
{ "dma_read_prioq_full" }, |
| 433 |
{ "tx_comp_queue_full" }, |
| 434 |
|
| 435 |
{ "ring_set_send_prod_index" }, |
| 436 |
{ "ring_status_update" }, |
| 437 |
{ "nic_irqs" }, |
| 438 |
{ "nic_avoided_irqs" }, |
| 439 |
{ "nic_tx_threshold_hit" }, |
| 440 |
|
| 441 |
{ "mbuf_lwm_thresh_hit" }, |
| 442 |
}; |
| 443 |
|
| 444 |
#define TG3_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) |
| 445 |
#define TG3_NVRAM_TEST 0 |
| 446 |
#define TG3_LINK_TEST 1 |
| 447 |
#define TG3_REGISTER_TEST 2 |
| 448 |
#define TG3_MEMORY_TEST 3 |
| 449 |
#define TG3_MAC_LOOPB_TEST 4 |
| 450 |
#define TG3_PHY_LOOPB_TEST 5 |
| 451 |
#define TG3_EXT_LOOPB_TEST 6 |
| 452 |
#define TG3_INTERRUPT_TEST 7 |
| 453 |
|
| 454 |
|
| 455 |
static const struct { |
| 456 |
const char string[ETH_GSTRING_LEN]; |
| 457 |
} ethtool_test_keys[] = { |
| 458 |
[TG3_NVRAM_TEST] = { "nvram test (online) " }, |
| 459 |
[TG3_LINK_TEST] = { "link test (online) " }, |
| 460 |
[TG3_REGISTER_TEST] = { "register test (offline)" }, |
| 461 |
[TG3_MEMORY_TEST] = { "memory test (offline)" }, |
| 462 |
[TG3_MAC_LOOPB_TEST] = { "mac loopback test (offline)" }, |
| 463 |
[TG3_PHY_LOOPB_TEST] = { "phy loopback test (offline)" }, |
| 464 |
[TG3_EXT_LOOPB_TEST] = { "ext loopback test (offline)" }, |
| 465 |
[TG3_INTERRUPT_TEST] = { "interrupt test (offline)" }, |
| 466 |
}; |
| 467 |
|
| 468 |
#define TG3_NUM_TEST ARRAY_SIZE(ethtool_test_keys) |
| 469 |
|
| 470 |
|
| 471 |
static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
| 472 |
{ |
| 473 |
writel(val, tp->regs + off); |
| 474 |
} |
| 475 |
|
| 476 |
static u32 tg3_read32(struct tg3 *tp, u32 off) |
| 477 |
{ |
| 478 |
return readl(tp->regs + off); |
| 479 |
} |
| 480 |
|
| 481 |
static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
| 482 |
{ |
| 483 |
writel(val, tp->aperegs + off); |
| 484 |
} |
| 485 |
|
| 486 |
static u32 tg3_ape_read32(struct tg3 *tp, u32 off) |
| 487 |
{ |
| 488 |
return readl(tp->aperegs + off); |
| 489 |
} |
| 490 |
|
| 491 |
static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
| 492 |
{ |
| 493 |
unsigned long flags; |
| 494 |
|
| 495 |
spin_lock_irqsave(&tp->indirect_lock, flags); |
| 496 |
pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 497 |
pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 498 |
spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 499 |
} |
| 500 |
|
| 501 |
static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) |
| 502 |
{ |
| 503 |
writel(val, tp->regs + off); |
| 504 |
readl(tp->regs + off); |
| 505 |
} |
| 506 |
|
| 507 |
static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
| 508 |
{ |
| 509 |
unsigned long flags; |
| 510 |
u32 val; |
| 511 |
|
| 512 |
spin_lock_irqsave(&tp->indirect_lock, flags); |
| 513 |
pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
| 514 |
pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 515 |
spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 516 |
return val; |
| 517 |
} |
| 518 |
|
| 519 |
static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) |
| 520 |
{ |
| 521 |
unsigned long flags; |
| 522 |
|
| 523 |
if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { |
| 524 |
pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + |
| 525 |
TG3_64BIT_REG_LOW, val); |
| 526 |
return; |
| 527 |
} |
| 528 |
if (off == TG3_RX_STD_PROD_IDX_REG) { |
| 529 |
pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
| 530 |
TG3_64BIT_REG_LOW, val); |
| 531 |
return; |
| 532 |
} |
| 533 |
|
| 534 |
spin_lock_irqsave(&tp->indirect_lock, flags); |
| 535 |
pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 536 |
pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); |
| 537 |
spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 538 |
|
| 539 |
/* In indirect mode when disabling interrupts, we also need |
| 540 |
* to clear the interrupt bit in the GRC local ctrl register. |
| 541 |
*/ |
| 542 |
if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && |
| 543 |
(val == 0x1)) { |
| 544 |
pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, |
| 545 |
tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); |
| 546 |
} |
| 547 |
} |
| 548 |
|
| 549 |
static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) |
| 550 |
{ |
| 551 |
unsigned long flags; |
| 552 |
u32 val; |
| 553 |
|
| 554 |
spin_lock_irqsave(&tp->indirect_lock, flags); |
| 555 |
pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); |
| 556 |
pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); |
| 557 |
spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 558 |
return val; |
| 559 |
} |
| 560 |
|
| 561 |
/* usec_wait specifies the wait time in usec when writing to certain registers |
| 562 |
* where it is unsafe to read back the register without some delay. |
| 563 |
* GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. |
| 564 |
* TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. |
| 565 |
*/ |
| 566 |
static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait) |
| 567 |
{ |
| 568 |
if (tg3_flag(tp, PCIX_TARGET_HWBUG) || tg3_flag(tp, ICH_WORKAROUND)) |
| 569 |
/* Non-posted methods */ |
| 570 |
tp->write32(tp, off, val); |
| 571 |
else { |
| 572 |
/* Posted method */ |
| 573 |
tg3_write32(tp, off, val); |
| 574 |
if (usec_wait) |
| 575 |
udelay(usec_wait); |
| 576 |
tp->read32(tp, off); |
| 577 |
} |
| 578 |
/* Wait again after the read for the posted method to guarantee that |
| 579 |
* the wait time is met. |
| 580 |
*/ |
| 581 |
if (usec_wait) |
| 582 |
udelay(usec_wait); |
| 583 |
} |
| 584 |
|
| 585 |
static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
| 586 |
{ |
| 587 |
tp->write32_mbox(tp, off, val); |
| 588 |
if (tg3_flag(tp, FLUSH_POSTED_WRITES) || |
| 589 |
(!tg3_flag(tp, MBOX_WRITE_REORDER) && |
| 590 |
!tg3_flag(tp, ICH_WORKAROUND))) |
| 591 |
tp->read32_mbox(tp, off); |
| 592 |
} |
| 593 |
|
| 594 |
static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val) |
| 595 |
{ |
| 596 |
void __iomem *mbox = tp->regs + off; |
| 597 |
writel(val, mbox); |
| 598 |
if (tg3_flag(tp, TXD_MBOX_HWBUG)) |
| 599 |
writel(val, mbox); |
| 600 |
if (tg3_flag(tp, MBOX_WRITE_REORDER) || |
| 601 |
tg3_flag(tp, FLUSH_POSTED_WRITES)) |
| 602 |
readl(mbox); |
| 603 |
} |
| 604 |
|
| 605 |
static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
| 606 |
{ |
| 607 |
return readl(tp->regs + off + GRCMBOX_BASE); |
| 608 |
} |
| 609 |
|
| 610 |
static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) |
| 611 |
{ |
| 612 |
writel(val, tp->regs + off + GRCMBOX_BASE); |
| 613 |
} |
| 614 |
|
| 615 |
#define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
| 616 |
#define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
| 617 |
#define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
| 618 |
#define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) |
| 619 |
#define tr32_mailbox(reg) tp->read32_mbox(tp, reg) |
| 620 |
|
| 621 |
#define tw32(reg, val) tp->write32(tp, reg, val) |
| 622 |
#define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) |
| 623 |
#define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) |
| 624 |
#define tr32(reg) tp->read32(tp, reg) |
| 625 |
|
| 626 |
static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) |
| 627 |
{ |
| 628 |
unsigned long flags; |
| 629 |
|
| 630 |
if (tg3_asic_rev(tp) == ASIC_REV_5906 && |
| 631 |
(off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
| 632 |
return; |
| 633 |
|
| 634 |
spin_lock_irqsave(&tp->indirect_lock, flags); |
| 635 |
if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
| 636 |
pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 637 |
pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 638 |
|
| 639 |
/* Always leave this as zero. */ |
| 640 |
pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 641 |
} else { |
| 642 |
tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 643 |
tw32_f(TG3PCI_MEM_WIN_DATA, val); |
| 644 |
|
| 645 |
/* Always leave this as zero. */ |
| 646 |
tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 647 |
} |
| 648 |
spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 649 |
} |
| 650 |
|
| 651 |
static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
| 652 |
{ |
| 653 |
unsigned long flags; |
| 654 |
|
| 655 |
if (tg3_asic_rev(tp) == ASIC_REV_5906 && |
| 656 |
(off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
| 657 |
*val = 0; |
| 658 |
return; |
| 659 |
} |
| 660 |
|
| 661 |
spin_lock_irqsave(&tp->indirect_lock, flags); |
| 662 |
if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
| 663 |
pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 664 |
pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 665 |
|
| 666 |
/* Always leave this as zero. */ |
| 667 |
pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 668 |
} else { |
| 669 |
tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); |
| 670 |
*val = tr32(TG3PCI_MEM_WIN_DATA); |
| 671 |
|
| 672 |
/* Always leave this as zero. */ |
| 673 |
tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 674 |
} |
| 675 |
spin_unlock_irqrestore(&tp->indirect_lock, flags); |
| 676 |
} |
| 677 |
|
| 678 |
static void tg3_ape_lock_init(struct tg3 *tp) |
| 679 |
{ |
| 680 |
int i; |
| 681 |
u32 regbase, bit; |
| 682 |
|
| 683 |
if (tg3_asic_rev(tp) == ASIC_REV_5761) |
| 684 |
regbase = TG3_APE_LOCK_GRANT; |
| 685 |
else |
| 686 |
regbase = TG3_APE_PER_LOCK_GRANT; |
| 687 |
|
| 688 |
/* Make sure the driver hasn't any stale locks. */ |
| 689 |
for (i = TG3_APE_LOCK_PHY0; i <= TG3_APE_LOCK_GPIO; i++) { |
| 690 |
switch (i) { |
| 691 |
case TG3_APE_LOCK_PHY0: |
| 692 |
case TG3_APE_LOCK_PHY1: |
| 693 |
case TG3_APE_LOCK_PHY2: |
| 694 |
case TG3_APE_LOCK_PHY3: |
| 695 |
bit = APE_LOCK_GRANT_DRIVER; |
| 696 |
break; |
| 697 |
default: |
| 698 |
if (!tp->pci_fn) |
| 699 |
bit = APE_LOCK_GRANT_DRIVER; |
| 700 |
else |
| 701 |
bit = 1 << tp->pci_fn; |
| 702 |
} |
| 703 |
tg3_ape_write32(tp, regbase + 4 * i, bit); |
| 704 |
} |
| 705 |
|
| 706 |
} |
| 707 |
|
| 708 |
static int tg3_ape_lock(struct tg3 *tp, int locknum) |
| 709 |
{ |
| 710 |
int i, off; |
| 711 |
int ret = 0; |
| 712 |
u32 status, req, gnt, bit; |
| 713 |
|
| 714 |
if (!tg3_flag(tp, ENABLE_APE)) |
| 715 |
return 0; |
| 716 |
|
| 717 |
switch (locknum) { |
| 718 |
case TG3_APE_LOCK_GPIO: |
| 719 |
if (tg3_asic_rev(tp) == ASIC_REV_5761) |
| 720 |
return 0; |
| 721 |
fallthrough; |
| 722 |
case TG3_APE_LOCK_GRC: |
| 723 |
case TG3_APE_LOCK_MEM: |
| 724 |
if (!tp->pci_fn) |
| 725 |
bit = APE_LOCK_REQ_DRIVER; |
| 726 |
else |
| 727 |
bit = 1 << tp->pci_fn; |
| 728 |
break; |
| 729 |
case TG3_APE_LOCK_PHY0: |
| 730 |
case TG3_APE_LOCK_PHY1: |
| 731 |
case TG3_APE_LOCK_PHY2: |
| 732 |
case TG3_APE_LOCK_PHY3: |
| 733 |
bit = APE_LOCK_REQ_DRIVER; |
| 734 |
break; |
| 735 |
default: |
| 736 |
return -EINVAL; |
| 737 |
} |
| 738 |
|
| 739 |
if (tg3_asic_rev(tp) == ASIC_REV_5761) { |
| 740 |
req = TG3_APE_LOCK_REQ; |
| 741 |
gnt = TG3_APE_LOCK_GRANT; |
| 742 |
} else { |
| 743 |
req = TG3_APE_PER_LOCK_REQ; |
| 744 |
gnt = TG3_APE_PER_LOCK_GRANT; |
| 745 |
} |
| 746 |
|
| 747 |
off = 4 * locknum; |
| 748 |
|
| 749 |
tg3_ape_write32(tp, req + off, bit); |
| 750 |
|
| 751 |
/* Wait for up to 1 millisecond to acquire lock. */ |
| 752 |
for (i = 0; i < 100; i++) { |
| 753 |
status = tg3_ape_read32(tp, gnt + off); |
| 754 |
if (status == bit) |
| 755 |
break; |
| 756 |
if (pci_channel_offline(tp->pdev)) |
| 757 |
break; |
| 758 |
|
| 759 |
udelay(10); |
| 760 |
} |
| 761 |
|
| 762 |
if (status != bit) { |
| 763 |
/* Revoke the lock request. */ |
| 764 |
tg3_ape_write32(tp, gnt + off, bit); |
| 765 |
ret = -EBUSY; |
| 766 |
} |
| 767 |
|
| 768 |
return ret; |
| 769 |
} |
| 770 |
|
| 771 |
static void tg3_ape_unlock(struct tg3 *tp, int locknum) |
| 772 |
{ |
| 773 |
u32 gnt, bit; |
| 774 |
|
| 775 |
if (!tg3_flag(tp, ENABLE_APE)) |
| 776 |
return; |
| 777 |
|
| 778 |
switch (locknum) { |
| 779 |
case TG3_APE_LOCK_GPIO: |
| 780 |
if (tg3_asic_rev(tp) == ASIC_REV_5761) |
| 781 |
return; |
| 782 |
fallthrough; |
| 783 |
case TG3_APE_LOCK_GRC: |
| 784 |
case TG3_APE_LOCK_MEM: |
| 785 |
if (!tp->pci_fn) |
| 786 |
bit = APE_LOCK_GRANT_DRIVER; |
| 787 |
else |
| 788 |
bit = 1 << tp->pci_fn; |
| 789 |
break; |
| 790 |
case TG3_APE_LOCK_PHY0: |
| 791 |
case TG3_APE_LOCK_PHY1: |
| 792 |
case TG3_APE_LOCK_PHY2: |
| 793 |
case TG3_APE_LOCK_PHY3: |
| 794 |
bit = APE_LOCK_GRANT_DRIVER; |
| 795 |
break; |
| 796 |
default: |
| 797 |
return; |
| 798 |
} |
| 799 |
|
| 800 |
if (tg3_asic_rev(tp) == ASIC_REV_5761) |
| 801 |
gnt = TG3_APE_LOCK_GRANT; |
| 802 |
else |
| 803 |
gnt = TG3_APE_PER_LOCK_GRANT; |
| 804 |
|
| 805 |
tg3_ape_write32(tp, gnt + 4 * locknum, bit); |
| 806 |
} |
| 807 |
|
| 808 |
static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us) |
| 809 |
{ |
| 810 |
u32 apedata; |
| 811 |
|
| 812 |
while (timeout_us) { |
| 813 |
if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) |
| 814 |
return -EBUSY; |
| 815 |
|
| 816 |
apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 817 |
if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 818 |
break; |
| 819 |
|
| 820 |
tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 821 |
|
| 822 |
udelay(10); |
| 823 |
timeout_us -= (timeout_us > 10) ? 10 : timeout_us; |
| 824 |
} |
| 825 |
|
| 826 |
return timeout_us ? 0 : -EBUSY; |
| 827 |
} |
| 828 |
|
| 829 |
#ifdef CONFIG_TIGON3_HWMON |
| 830 |
static int tg3_ape_wait_for_event(struct tg3 *tp, u32 timeout_us) |
| 831 |
{ |
| 832 |
u32 i, apedata; |
| 833 |
|
| 834 |
for (i = 0; i < timeout_us / 10; i++) { |
| 835 |
apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); |
| 836 |
|
| 837 |
if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) |
| 838 |
break; |
| 839 |
|
| 840 |
udelay(10); |
| 841 |
} |
| 842 |
|
| 843 |
return i == timeout_us / 10; |
| 844 |
} |
| 845 |
|
| 846 |
static int tg3_ape_scratchpad_read(struct tg3 *tp, u32 *data, u32 base_off, |
| 847 |
u32 len) |
| 848 |
{ |
| 849 |
int err; |
| 850 |
u32 i, bufoff, msgoff, maxlen, apedata; |
| 851 |
|
| 852 |
if (!tg3_flag(tp, APE_HAS_NCSI)) |
| 853 |
return 0; |
| 854 |
|
| 855 |
apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 856 |
if (apedata != APE_SEG_SIG_MAGIC) |
| 857 |
return -ENODEV; |
| 858 |
|
| 859 |
apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 860 |
if (!(apedata & APE_FW_STATUS_READY)) |
| 861 |
return -EAGAIN; |
| 862 |
|
| 863 |
bufoff = tg3_ape_read32(tp, TG3_APE_SEG_MSG_BUF_OFF) + |
| 864 |
TG3_APE_SHMEM_BASE; |
| 865 |
msgoff = bufoff + 2 * sizeof(u32); |
| 866 |
maxlen = tg3_ape_read32(tp, TG3_APE_SEG_MSG_BUF_LEN); |
| 867 |
|
| 868 |
while (len) { |
| 869 |
u32 length; |
| 870 |
|
| 871 |
/* Cap xfer sizes to scratchpad limits. */ |
| 872 |
length = (len > maxlen) ? maxlen : len; |
| 873 |
len -= length; |
| 874 |
|
| 875 |
apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 876 |
if (!(apedata & APE_FW_STATUS_READY)) |
| 877 |
return -EAGAIN; |
| 878 |
|
| 879 |
/* Wait for up to 1 msec for APE to service previous event. */ |
| 880 |
err = tg3_ape_event_lock(tp, 1000); |
| 881 |
if (err) |
| 882 |
return err; |
| 883 |
|
| 884 |
apedata = APE_EVENT_STATUS_DRIVER_EVNT | |
| 885 |
APE_EVENT_STATUS_SCRTCHPD_READ | |
| 886 |
APE_EVENT_STATUS_EVENT_PENDING; |
| 887 |
tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, apedata); |
| 888 |
|
| 889 |
tg3_ape_write32(tp, bufoff, base_off); |
| 890 |
tg3_ape_write32(tp, bufoff + sizeof(u32), length); |
| 891 |
|
| 892 |
tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 893 |
tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 894 |
|
| 895 |
base_off += length; |
| 896 |
|
| 897 |
if (tg3_ape_wait_for_event(tp, 30000)) |
| 898 |
return -EAGAIN; |
| 899 |
|
| 900 |
for (i = 0; length; i += 4, length -= 4) { |
| 901 |
u32 val = tg3_ape_read32(tp, msgoff + i); |
| 902 |
memcpy(data, &val, sizeof(u32)); |
| 903 |
data++; |
| 904 |
} |
| 905 |
} |
| 906 |
|
| 907 |
return 0; |
| 908 |
} |
| 909 |
#endif |
| 910 |
|
| 911 |
static int tg3_ape_send_event(struct tg3 *tp, u32 event) |
| 912 |
{ |
| 913 |
int err; |
| 914 |
u32 apedata; |
| 915 |
|
| 916 |
apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 917 |
if (apedata != APE_SEG_SIG_MAGIC) |
| 918 |
return -EAGAIN; |
| 919 |
|
| 920 |
apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 921 |
if (!(apedata & APE_FW_STATUS_READY)) |
| 922 |
return -EAGAIN; |
| 923 |
|
| 924 |
/* Wait for up to 20 millisecond for APE to service previous event. */ |
| 925 |
err = tg3_ape_event_lock(tp, 20000); |
| 926 |
if (err) |
| 927 |
return err; |
| 928 |
|
| 929 |
tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
| 930 |
event | APE_EVENT_STATUS_EVENT_PENDING); |
| 931 |
|
| 932 |
tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
| 933 |
tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); |
| 934 |
|
| 935 |
return 0; |
| 936 |
} |
| 937 |
|
| 938 |
static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
| 939 |
{ |
| 940 |
u32 event; |
| 941 |
u32 apedata; |
| 942 |
|
| 943 |
if (!tg3_flag(tp, ENABLE_APE)) |
| 944 |
return; |
| 945 |
|
| 946 |
switch (kind) { |
| 947 |
case RESET_KIND_INIT: |
| 948 |
tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_COUNT, tp->ape_hb++); |
| 949 |
tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, |
| 950 |
APE_HOST_SEG_SIG_MAGIC); |
| 951 |
tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, |
| 952 |
APE_HOST_SEG_LEN_MAGIC); |
| 953 |
apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); |
| 954 |
tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); |
| 955 |
tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, |
| 956 |
APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
| 957 |
tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
| 958 |
APE_HOST_BEHAV_NO_PHYLOCK); |
| 959 |
tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, |
| 960 |
TG3_APE_HOST_DRVR_STATE_START); |
| 961 |
|
| 962 |
event = APE_EVENT_STATUS_STATE_START; |
| 963 |
break; |
| 964 |
case RESET_KIND_SHUTDOWN: |
| 965 |
if (device_may_wakeup(&tp->pdev->dev) && |
| 966 |
tg3_flag(tp, WOL_ENABLE)) { |
| 967 |
tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, |
| 968 |
TG3_APE_HOST_WOL_SPEED_AUTO); |
| 969 |
apedata = TG3_APE_HOST_DRVR_STATE_WOL; |
| 970 |
} else |
| 971 |
apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; |
| 972 |
|
| 973 |
tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); |
| 974 |
|
| 975 |
event = APE_EVENT_STATUS_STATE_UNLOAD; |
| 976 |
break; |
| 977 |
default: |
| 978 |
return; |
| 979 |
} |
| 980 |
|
| 981 |
event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; |
| 982 |
|
| 983 |
tg3_ape_send_event(tp, event); |
| 984 |
} |
| 985 |
|
| 986 |
static void tg3_send_ape_heartbeat(struct tg3 *tp, |
| 987 |
unsigned long interval) |
| 988 |
{ |
| 989 |
/* Check if hb interval has exceeded */ |
| 990 |
if (!tg3_flag(tp, ENABLE_APE) || |
| 991 |
time_before(jiffies, tp->ape_hb_jiffies + interval)) |
| 992 |
return; |
| 993 |
|
| 994 |
tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_COUNT, tp->ape_hb++); |
| 995 |
tp->ape_hb_jiffies = jiffies; |
| 996 |
} |
| 997 |
|
| 998 |
static void tg3_disable_ints(struct tg3 *tp) |
| 999 |
{ |
| 1000 |
int i; |
| 1001 |
|
| 1002 |
tw32(TG3PCI_MISC_HOST_CTRL, |
| 1003 |
(tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); |
| 1004 |
for (i = 0; i < tp->irq_max; i++) |
| 1005 |
tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); |
| 1006 |
} |
| 1007 |
|
| 1008 |
static void tg3_enable_ints(struct tg3 *tp) |
| 1009 |
{ |
| 1010 |
int i; |
| 1011 |
|
| 1012 |
tp->irq_sync = 0; |
| 1013 |
wmb(); |
| 1014 |
|
| 1015 |
tw32(TG3PCI_MISC_HOST_CTRL, |
| 1016 |
(tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); |
| 1017 |
|
| 1018 |
tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
| 1019 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 1020 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 1021 |
|
| 1022 |
tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 1023 |
if (tg3_flag(tp, 1SHOT_MSI)) |
| 1024 |
tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 1025 |
|
| 1026 |
tp->coal_now |= tnapi->coal_now; |
| 1027 |
} |
| 1028 |
|
| 1029 |
/* Force an initial interrupt */ |
| 1030 |
if (!tg3_flag(tp, TAGGED_STATUS) && |
| 1031 |
(tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
| 1032 |
tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 1033 |
else |
| 1034 |
tw32(HOSTCC_MODE, tp->coal_now); |
| 1035 |
|
| 1036 |
tp->coal_now &= ~(tp->napi[0].coal_now | tp->napi[1].coal_now); |
| 1037 |
} |
| 1038 |
|
| 1039 |
static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
| 1040 |
{ |
| 1041 |
struct tg3 *tp = tnapi->tp; |
| 1042 |
struct tg3_hw_status *sblk = tnapi->hw_status; |
| 1043 |
unsigned int work_exists = 0; |
| 1044 |
|
| 1045 |
/* check for phy events */ |
| 1046 |
if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
| 1047 |
if (sblk->status & SD_STATUS_LINK_CHG) |
| 1048 |
work_exists = 1; |
| 1049 |
} |
| 1050 |
|
| 1051 |
/* check for TX work to do */ |
| 1052 |
if (sblk->idx[0].tx_consumer != tnapi->tx_cons) |
| 1053 |
work_exists = 1; |
| 1054 |
|
| 1055 |
/* check for RX work to do */ |
| 1056 |
if (tnapi->rx_rcb_prod_idx && |
| 1057 |
*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
| 1058 |
work_exists = 1; |
| 1059 |
|
| 1060 |
return work_exists; |
| 1061 |
} |
| 1062 |
|
| 1063 |
/* tg3_int_reenable |
| 1064 |
* similar to tg3_enable_ints, but it accurately determines whether there |
| 1065 |
* is new work pending and can return without flushing the PIO write |
| 1066 |
* which reenables interrupts |
| 1067 |
*/ |
| 1068 |
static void tg3_int_reenable(struct tg3_napi *tnapi) |
| 1069 |
{ |
| 1070 |
struct tg3 *tp = tnapi->tp; |
| 1071 |
|
| 1072 |
tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
| 1073 |
|
| 1074 |
/* When doing tagged status, this work check is unnecessary. |
| 1075 |
* The last_tag we write above tells the chip which piece of |
| 1076 |
* work we've completed. |
| 1077 |
*/ |
| 1078 |
if (!tg3_flag(tp, TAGGED_STATUS) && tg3_has_work(tnapi)) |
| 1079 |
tw32(HOSTCC_MODE, tp->coalesce_mode | |
| 1080 |
HOSTCC_MODE_ENABLE | tnapi->coal_now); |
| 1081 |
} |
| 1082 |
|
| 1083 |
static void tg3_switch_clocks(struct tg3 *tp) |
| 1084 |
{ |
| 1085 |
u32 clock_ctrl; |
| 1086 |
u32 orig_clock_ctrl; |
| 1087 |
|
| 1088 |
if (tg3_flag(tp, CPMU_PRESENT) || tg3_flag(tp, 5780_CLASS)) |
| 1089 |
return; |
| 1090 |
|
| 1091 |
clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
| 1092 |
|
| 1093 |
orig_clock_ctrl = clock_ctrl; |
| 1094 |
clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | |
| 1095 |
CLOCK_CTRL_CLKRUN_OENABLE | |
| 1096 |
0x1f); |
| 1097 |
tp->pci_clock_ctrl = clock_ctrl; |
| 1098 |
|
| 1099 |
if (tg3_flag(tp, 5705_PLUS)) { |
| 1100 |
if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
| 1101 |
tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1102 |
clock_ctrl | CLOCK_CTRL_625_CORE, 40); |
| 1103 |
} |
| 1104 |
} else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { |
| 1105 |
tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1106 |
clock_ctrl | |
| 1107 |
(CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), |
| 1108 |
40); |
| 1109 |
tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 1110 |
clock_ctrl | (CLOCK_CTRL_ALTCLK), |
| 1111 |
40); |
| 1112 |
} |
| 1113 |
tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
| 1114 |
} |
| 1115 |
|
| 1116 |
#define PHY_BUSY_LOOPS 5000 |
| 1117 |
|
| 1118 |
static int __tg3_readphy(struct tg3 *tp, unsigned int phy_addr, int reg, |
| 1119 |
u32 *val) |
| 1120 |
{ |
| 1121 |
u32 frame_val; |
| 1122 |
unsigned int loops; |
| 1123 |
int ret; |
| 1124 |
|
| 1125 |
if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1126 |
tw32_f(MAC_MI_MODE, |
| 1127 |
(tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 1128 |
udelay(80); |
| 1129 |
} |
| 1130 |
|
| 1131 |
tg3_ape_lock(tp, tp->phy_ape_lock); |
| 1132 |
|
| 1133 |
*val = 0x0; |
| 1134 |
|
| 1135 |
frame_val = ((phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
| 1136 |
MI_COM_PHY_ADDR_MASK); |
| 1137 |
frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 1138 |
MI_COM_REG_ADDR_MASK); |
| 1139 |
frame_val |= (MI_COM_CMD_READ | MI_COM_START); |
| 1140 |
|
| 1141 |
tw32_f(MAC_MI_COM, frame_val); |
| 1142 |
|
| 1143 |
loops = PHY_BUSY_LOOPS; |
| 1144 |
while (loops != 0) { |
| 1145 |
udelay(10); |
| 1146 |
frame_val = tr32(MAC_MI_COM); |
| 1147 |
|
| 1148 |
if ((frame_val & MI_COM_BUSY) == 0) { |
| 1149 |
udelay(5); |
| 1150 |
frame_val = tr32(MAC_MI_COM); |
| 1151 |
break; |
| 1152 |
} |
| 1153 |
loops -= 1; |
| 1154 |
} |
| 1155 |
|
| 1156 |
ret = -EBUSY; |
| 1157 |
if (loops != 0) { |
| 1158 |
*val = frame_val & MI_COM_DATA_MASK; |
| 1159 |
ret = 0; |
| 1160 |
} |
| 1161 |
|
| 1162 |
if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1163 |
tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1164 |
udelay(80); |
| 1165 |
} |
| 1166 |
|
| 1167 |
tg3_ape_unlock(tp, tp->phy_ape_lock); |
| 1168 |
|
| 1169 |
return ret; |
| 1170 |
} |
| 1171 |
|
| 1172 |
static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
| 1173 |
{ |
| 1174 |
return __tg3_readphy(tp, tp->phy_addr, reg, val); |
| 1175 |
} |
| 1176 |
|
| 1177 |
static int __tg3_writephy(struct tg3 *tp, unsigned int phy_addr, int reg, |
| 1178 |
u32 val) |
| 1179 |
{ |
| 1180 |
u32 frame_val; |
| 1181 |
unsigned int loops; |
| 1182 |
int ret; |
| 1183 |
|
| 1184 |
if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
| 1185 |
(reg == MII_CTRL1000 || reg == MII_TG3_AUX_CTRL)) |
| 1186 |
return 0; |
| 1187 |
|
| 1188 |
if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1189 |
tw32_f(MAC_MI_MODE, |
| 1190 |
(tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 1191 |
udelay(80); |
| 1192 |
} |
| 1193 |
|
| 1194 |
tg3_ape_lock(tp, tp->phy_ape_lock); |
| 1195 |
|
| 1196 |
frame_val = ((phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
| 1197 |
MI_COM_PHY_ADDR_MASK); |
| 1198 |
frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & |
| 1199 |
MI_COM_REG_ADDR_MASK); |
| 1200 |
frame_val |= (val & MI_COM_DATA_MASK); |
| 1201 |
frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); |
| 1202 |
|
| 1203 |
tw32_f(MAC_MI_COM, frame_val); |
| 1204 |
|
| 1205 |
loops = PHY_BUSY_LOOPS; |
| 1206 |
while (loops != 0) { |
| 1207 |
udelay(10); |
| 1208 |
frame_val = tr32(MAC_MI_COM); |
| 1209 |
if ((frame_val & MI_COM_BUSY) == 0) { |
| 1210 |
udelay(5); |
| 1211 |
frame_val = tr32(MAC_MI_COM); |
| 1212 |
break; |
| 1213 |
} |
| 1214 |
loops -= 1; |
| 1215 |
} |
| 1216 |
|
| 1217 |
ret = -EBUSY; |
| 1218 |
if (loops != 0) |
| 1219 |
ret = 0; |
| 1220 |
|
| 1221 |
if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 1222 |
tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1223 |
udelay(80); |
| 1224 |
} |
| 1225 |
|
| 1226 |
tg3_ape_unlock(tp, tp->phy_ape_lock); |
| 1227 |
|
| 1228 |
return ret; |
| 1229 |
} |
| 1230 |
|
| 1231 |
static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
| 1232 |
{ |
| 1233 |
return __tg3_writephy(tp, tp->phy_addr, reg, val); |
| 1234 |
} |
| 1235 |
|
| 1236 |
static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
| 1237 |
{ |
| 1238 |
int err; |
| 1239 |
|
| 1240 |
err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1241 |
if (err) |
| 1242 |
goto done; |
| 1243 |
|
| 1244 |
err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1245 |
if (err) |
| 1246 |
goto done; |
| 1247 |
|
| 1248 |
err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1249 |
MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1250 |
if (err) |
| 1251 |
goto done; |
| 1252 |
|
| 1253 |
err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1254 |
|
| 1255 |
done: |
| 1256 |
return err; |
| 1257 |
} |
| 1258 |
|
| 1259 |
static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) |
| 1260 |
{ |
| 1261 |
int err; |
| 1262 |
|
| 1263 |
err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); |
| 1264 |
if (err) |
| 1265 |
goto done; |
| 1266 |
|
| 1267 |
err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); |
| 1268 |
if (err) |
| 1269 |
goto done; |
| 1270 |
|
| 1271 |
err = tg3_writephy(tp, MII_TG3_MMD_CTRL, |
| 1272 |
MII_TG3_MMD_CTRL_DATA_NOINC | devad); |
| 1273 |
if (err) |
| 1274 |
goto done; |
| 1275 |
|
| 1276 |
err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); |
| 1277 |
|
| 1278 |
done: |
| 1279 |
return err; |
| 1280 |
} |
| 1281 |
|
| 1282 |
static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) |
| 1283 |
{ |
| 1284 |
int err; |
| 1285 |
|
| 1286 |
err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1287 |
if (!err) |
| 1288 |
err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1289 |
|
| 1290 |
return err; |
| 1291 |
} |
| 1292 |
|
| 1293 |
static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
| 1294 |
{ |
| 1295 |
int err; |
| 1296 |
|
| 1297 |
err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); |
| 1298 |
if (!err) |
| 1299 |
err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); |
| 1300 |
|
| 1301 |
return err; |
| 1302 |
} |
| 1303 |
|
| 1304 |
static int tg3_phy_auxctl_read(struct tg3 *tp, int reg, u32 *val) |
| 1305 |
{ |
| 1306 |
int err; |
| 1307 |
|
| 1308 |
err = tg3_writephy(tp, MII_TG3_AUX_CTRL, |
| 1309 |
(reg << MII_TG3_AUXCTL_MISC_RDSEL_SHIFT) | |
| 1310 |
MII_TG3_AUXCTL_SHDWSEL_MISC); |
| 1311 |
if (!err) |
| 1312 |
err = tg3_readphy(tp, MII_TG3_AUX_CTRL, val); |
| 1313 |
|
| 1314 |
return err; |
| 1315 |
} |
| 1316 |
|
| 1317 |
static int tg3_phy_auxctl_write(struct tg3 *tp, int reg, u32 set) |
| 1318 |
{ |
| 1319 |
if (reg == MII_TG3_AUXCTL_SHDWSEL_MISC) |
| 1320 |
set |= MII_TG3_AUXCTL_MISC_WREN; |
| 1321 |
|
| 1322 |
return tg3_writephy(tp, MII_TG3_AUX_CTRL, set | reg); |
| 1323 |
} |
| 1324 |
|
| 1325 |
static int tg3_phy_toggle_auxctl_smdsp(struct tg3 *tp, bool enable) |
| 1326 |
{ |
| 1327 |
u32 val; |
| 1328 |
int err; |
| 1329 |
|
| 1330 |
err = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 1331 |
|
| 1332 |
if (err) |
| 1333 |
return err; |
| 1334 |
|
| 1335 |
if (enable) |
| 1336 |
val |= MII_TG3_AUXCTL_ACTL_SMDSP_ENA; |
| 1337 |
else |
| 1338 |
val &= ~MII_TG3_AUXCTL_ACTL_SMDSP_ENA; |
| 1339 |
|
| 1340 |
err = tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 1341 |
val | MII_TG3_AUXCTL_ACTL_TX_6DB); |
| 1342 |
|
| 1343 |
return err; |
| 1344 |
} |
| 1345 |
|
| 1346 |
static int tg3_phy_shdw_write(struct tg3 *tp, int reg, u32 val) |
| 1347 |
{ |
| 1348 |
return tg3_writephy(tp, MII_TG3_MISC_SHDW, |
| 1349 |
reg | val | MII_TG3_MISC_SHDW_WREN); |
| 1350 |
} |
| 1351 |
|
| 1352 |
static int tg3_bmcr_reset(struct tg3 *tp) |
| 1353 |
{ |
| 1354 |
u32 phy_control; |
| 1355 |
int limit, err; |
| 1356 |
|
| 1357 |
/* OK, reset it, and poll the BMCR_RESET bit until it |
| 1358 |
* clears or we time out. |
| 1359 |
*/ |
| 1360 |
phy_control = BMCR_RESET; |
| 1361 |
err = tg3_writephy(tp, MII_BMCR, phy_control); |
| 1362 |
if (err != 0) |
| 1363 |
return -EBUSY; |
| 1364 |
|
| 1365 |
limit = 5000; |
| 1366 |
while (limit--) { |
| 1367 |
err = tg3_readphy(tp, MII_BMCR, &phy_control); |
| 1368 |
if (err != 0) |
| 1369 |
return -EBUSY; |
| 1370 |
|
| 1371 |
if ((phy_control & BMCR_RESET) == 0) { |
| 1372 |
udelay(40); |
| 1373 |
break; |
| 1374 |
} |
| 1375 |
udelay(10); |
| 1376 |
} |
| 1377 |
if (limit < 0) |
| 1378 |
return -EBUSY; |
| 1379 |
|
| 1380 |
return 0; |
| 1381 |
} |
| 1382 |
|
| 1383 |
static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
| 1384 |
{ |
| 1385 |
struct tg3 *tp = bp->priv; |
| 1386 |
u32 val; |
| 1387 |
|
| 1388 |
spin_lock_bh(&tp->lock); |
| 1389 |
|
| 1390 |
if (__tg3_readphy(tp, mii_id, reg, &val)) |
| 1391 |
val = -EIO; |
| 1392 |
|
| 1393 |
spin_unlock_bh(&tp->lock); |
| 1394 |
|
| 1395 |
return val; |
| 1396 |
} |
| 1397 |
|
| 1398 |
static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) |
| 1399 |
{ |
| 1400 |
struct tg3 *tp = bp->priv; |
| 1401 |
u32 ret = 0; |
| 1402 |
|
| 1403 |
spin_lock_bh(&tp->lock); |
| 1404 |
|
| 1405 |
if (__tg3_writephy(tp, mii_id, reg, val)) |
| 1406 |
ret = -EIO; |
| 1407 |
|
| 1408 |
spin_unlock_bh(&tp->lock); |
| 1409 |
|
| 1410 |
return ret; |
| 1411 |
} |
| 1412 |
|
| 1413 |
static void tg3_mdio_config_5785(struct tg3 *tp) |
| 1414 |
{ |
| 1415 |
u32 val; |
| 1416 |
struct phy_device *phydev; |
| 1417 |
|
| 1418 |
phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr); |
| 1419 |
switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
| 1420 |
case PHY_ID_BCM50610: |
| 1421 |
case PHY_ID_BCM50610M: |
| 1422 |
val = MAC_PHYCFG2_50610_LED_MODES; |
| 1423 |
break; |
| 1424 |
case PHY_ID_BCMAC131: |
| 1425 |
val = MAC_PHYCFG2_AC131_LED_MODES; |
| 1426 |
break; |
| 1427 |
case PHY_ID_RTL8211C: |
| 1428 |
val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
| 1429 |
break; |
| 1430 |
case PHY_ID_RTL8201E: |
| 1431 |
val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
| 1432 |
break; |
| 1433 |
default: |
| 1434 |
return; |
| 1435 |
} |
| 1436 |
|
| 1437 |
if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { |
| 1438 |
tw32(MAC_PHYCFG2, val); |
| 1439 |
|
| 1440 |
val = tr32(MAC_PHYCFG1); |
| 1441 |
val &= ~(MAC_PHYCFG1_RGMII_INT | |
| 1442 |
MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); |
| 1443 |
val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; |
| 1444 |
tw32(MAC_PHYCFG1, val); |
| 1445 |
|
| 1446 |
return; |
| 1447 |
} |
| 1448 |
|
| 1449 |
if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) |
| 1450 |
val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
| 1451 |
MAC_PHYCFG2_FMODE_MASK_MASK | |
| 1452 |
MAC_PHYCFG2_GMODE_MASK_MASK | |
| 1453 |
MAC_PHYCFG2_ACT_MASK_MASK | |
| 1454 |
MAC_PHYCFG2_QUAL_MASK_MASK | |
| 1455 |
MAC_PHYCFG2_INBAND_ENABLE; |
| 1456 |
|
| 1457 |
tw32(MAC_PHYCFG2, val); |
| 1458 |
|
| 1459 |
val = tr32(MAC_PHYCFG1); |
| 1460 |
val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | |
| 1461 |
MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); |
| 1462 |
if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1463 |
if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
| 1464 |
val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
| 1465 |
if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
| 1466 |
val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
| 1467 |
} |
| 1468 |
val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
| 1469 |
MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; |
| 1470 |
tw32(MAC_PHYCFG1, val); |
| 1471 |
|
| 1472 |
val = tr32(MAC_EXT_RGMII_MODE); |
| 1473 |
val &= ~(MAC_RGMII_MODE_RX_INT_B | |
| 1474 |
MAC_RGMII_MODE_RX_QUALITY | |
| 1475 |
MAC_RGMII_MODE_RX_ACTIVITY | |
| 1476 |
MAC_RGMII_MODE_RX_ENG_DET | |
| 1477 |
MAC_RGMII_MODE_TX_ENABLE | |
| 1478 |
MAC_RGMII_MODE_TX_LOWPWR | |
| 1479 |
MAC_RGMII_MODE_TX_RESET); |
| 1480 |
if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
| 1481 |
if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
| 1482 |
val |= MAC_RGMII_MODE_RX_INT_B | |
| 1483 |
MAC_RGMII_MODE_RX_QUALITY | |
| 1484 |
MAC_RGMII_MODE_RX_ACTIVITY | |
| 1485 |
MAC_RGMII_MODE_RX_ENG_DET; |
| 1486 |
if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
| 1487 |
val |= MAC_RGMII_MODE_TX_ENABLE | |
| 1488 |
MAC_RGMII_MODE_TX_LOWPWR | |
| 1489 |
MAC_RGMII_MODE_TX_RESET; |
| 1490 |
} |
| 1491 |
tw32(MAC_EXT_RGMII_MODE, val); |
| 1492 |
} |
| 1493 |
|
| 1494 |
static void tg3_mdio_start(struct tg3 *tp) |
| 1495 |
{ |
| 1496 |
tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
| 1497 |
tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 1498 |
udelay(80); |
| 1499 |
|
| 1500 |
if (tg3_flag(tp, MDIOBUS_INITED) && |
| 1501 |
tg3_asic_rev(tp) == ASIC_REV_5785) |
| 1502 |
tg3_mdio_config_5785(tp); |
| 1503 |
} |
| 1504 |
|
| 1505 |
static int tg3_mdio_init(struct tg3 *tp) |
| 1506 |
{ |
| 1507 |
int i; |
| 1508 |
u32 reg; |
| 1509 |
struct phy_device *phydev; |
| 1510 |
|
| 1511 |
if (tg3_flag(tp, 5717_PLUS)) { |
| 1512 |
u32 is_serdes; |
| 1513 |
|
| 1514 |
tp->phy_addr = tp->pci_fn + 1; |
| 1515 |
|
| 1516 |
if (tg3_chip_rev_id(tp) != CHIPREV_ID_5717_A0) |
| 1517 |
is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
| 1518 |
else |
| 1519 |
is_serdes = tr32(TG3_CPMU_PHY_STRAP) & |
| 1520 |
TG3_CPMU_PHY_STRAP_IS_SERDES; |
| 1521 |
if (is_serdes) |
| 1522 |
tp->phy_addr += 7; |
| 1523 |
} else if (tg3_flag(tp, IS_SSB_CORE) && tg3_flag(tp, ROBOSWITCH)) { |
| 1524 |
int addr; |
| 1525 |
|
| 1526 |
addr = ssb_gige_get_phyaddr(tp->pdev); |
| 1527 |
if (addr < 0) |
| 1528 |
return addr; |
| 1529 |
tp->phy_addr = addr; |
| 1530 |
} else |
| 1531 |
tp->phy_addr = TG3_PHY_MII_ADDR; |
| 1532 |
|
| 1533 |
tg3_mdio_start(tp); |
| 1534 |
|
| 1535 |
if (!tg3_flag(tp, USE_PHYLIB) || tg3_flag(tp, MDIOBUS_INITED)) |
| 1536 |
return 0; |
| 1537 |
|
| 1538 |
tp->mdio_bus = mdiobus_alloc(); |
| 1539 |
if (tp->mdio_bus == NULL) |
| 1540 |
return -ENOMEM; |
| 1541 |
|
| 1542 |
tp->mdio_bus->name = "tg3 mdio bus"; |
| 1543 |
snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", pci_dev_id(tp->pdev)); |
| 1544 |
tp->mdio_bus->priv = tp; |
| 1545 |
tp->mdio_bus->parent = &tp->pdev->dev; |
| 1546 |
tp->mdio_bus->read = &tg3_mdio_read; |
| 1547 |
tp->mdio_bus->write = &tg3_mdio_write; |
| 1548 |
tp->mdio_bus->phy_mask = ~(1 << tp->phy_addr); |
| 1549 |
|
| 1550 |
/* The bus registration will look for all the PHYs on the mdio bus. |
| 1551 |
* Unfortunately, it does not ensure the PHY is powered up before |
| 1552 |
* accessing the PHY ID registers. A chip reset is the |
| 1553 |
* quickest way to bring the device back to an operational state.. |
| 1554 |
*/ |
| 1555 |
if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) |
| 1556 |
tg3_bmcr_reset(tp); |
| 1557 |
|
| 1558 |
i = mdiobus_register(tp->mdio_bus); |
| 1559 |
if (i) { |
| 1560 |
dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
| 1561 |
mdiobus_free(tp->mdio_bus); |
| 1562 |
return i; |
| 1563 |
} |
| 1564 |
|
| 1565 |
phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr); |
| 1566 |
|
| 1567 |
if (!phydev || !phydev->drv) { |
| 1568 |
dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
| 1569 |
mdiobus_unregister(tp->mdio_bus); |
| 1570 |
mdiobus_free(tp->mdio_bus); |
| 1571 |
return -ENODEV; |
| 1572 |
} |
| 1573 |
|
| 1574 |
switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
| 1575 |
case PHY_ID_BCM57780: |
| 1576 |
phydev->interface = PHY_INTERFACE_MODE_GMII; |
| 1577 |
phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
| 1578 |
break; |
| 1579 |
case PHY_ID_BCM50610: |
| 1580 |
case PHY_ID_BCM50610M: |
| 1581 |
phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
| 1582 |
PHY_BRCM_RX_REFCLK_UNUSED | |
| 1583 |
PHY_BRCM_DIS_TXCRXC_NOENRGY | |
| 1584 |
PHY_BRCM_AUTO_PWRDWN_ENABLE; |
| 1585 |
fallthrough; |
| 1586 |
case PHY_ID_RTL8211C: |
| 1587 |
phydev->interface = PHY_INTERFACE_MODE_RGMII; |
| 1588 |
break; |
| 1589 |
case PHY_ID_RTL8201E: |
| 1590 |
case PHY_ID_BCMAC131: |
| 1591 |
phydev->interface = PHY_INTERFACE_MODE_MII; |
| 1592 |
phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
| 1593 |
tp->phy_flags |= TG3_PHYFLG_IS_FET; |
| 1594 |
break; |
| 1595 |
} |
| 1596 |
|
| 1597 |
tg3_flag_set(tp, MDIOBUS_INITED); |
| 1598 |
|
| 1599 |
if (tg3_asic_rev(tp) == ASIC_REV_5785) |
| 1600 |
tg3_mdio_config_5785(tp); |
| 1601 |
|
| 1602 |
return 0; |
| 1603 |
} |
| 1604 |
|
| 1605 |
static void tg3_mdio_fini(struct tg3 *tp) |
| 1606 |
{ |
| 1607 |
if (tg3_flag(tp, MDIOBUS_INITED)) { |
| 1608 |
tg3_flag_clear(tp, MDIOBUS_INITED); |
| 1609 |
mdiobus_unregister(tp->mdio_bus); |
| 1610 |
mdiobus_free(tp->mdio_bus); |
| 1611 |
} |
| 1612 |
} |
| 1613 |
|
| 1614 |
/* tp->lock is held. */ |
| 1615 |
static inline void tg3_generate_fw_event(struct tg3 *tp) |
| 1616 |
{ |
| 1617 |
u32 val; |
| 1618 |
|
| 1619 |
val = tr32(GRC_RX_CPU_EVENT); |
| 1620 |
val |= GRC_RX_CPU_DRIVER_EVENT; |
| 1621 |
tw32_f(GRC_RX_CPU_EVENT, val); |
| 1622 |
|
| 1623 |
tp->last_event_jiffies = jiffies; |
| 1624 |
} |
| 1625 |
|
| 1626 |
#define TG3_FW_EVENT_TIMEOUT_USEC 2500 |
| 1627 |
|
| 1628 |
/* tp->lock is held. */ |
| 1629 |
static void tg3_wait_for_event_ack(struct tg3 *tp) |
| 1630 |
{ |
| 1631 |
int i; |
| 1632 |
unsigned int delay_cnt; |
| 1633 |
long time_remain; |
| 1634 |
|
| 1635 |
/* If enough time has passed, no wait is necessary. */ |
| 1636 |
time_remain = (long)(tp->last_event_jiffies + 1 + |
| 1637 |
usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - |
| 1638 |
(long)jiffies; |
| 1639 |
if (time_remain < 0) |
| 1640 |
return; |
| 1641 |
|
| 1642 |
/* Check if we can shorten the wait time. */ |
| 1643 |
delay_cnt = jiffies_to_usecs(time_remain); |
| 1644 |
if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) |
| 1645 |
delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; |
| 1646 |
delay_cnt = (delay_cnt >> 3) + 1; |
| 1647 |
|
| 1648 |
for (i = 0; i < delay_cnt; i++) { |
| 1649 |
if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
| 1650 |
break; |
| 1651 |
if (pci_channel_offline(tp->pdev)) |
| 1652 |
break; |
| 1653 |
|
| 1654 |
udelay(8); |
| 1655 |
} |
| 1656 |
} |
| 1657 |
|
| 1658 |
/* tp->lock is held. */ |
| 1659 |
static void tg3_phy_gather_ump_data(struct tg3 *tp, u32 *data) |
| 1660 |
{ |
| 1661 |
u32 reg, val; |
| 1662 |
|
| 1663 |
val = 0; |
| 1664 |
if (!tg3_readphy(tp, MII_BMCR, ®)) |
| 1665 |
val = reg << 16; |
| 1666 |
if (!tg3_readphy(tp, MII_BMSR, ®)) |
| 1667 |
val |= (reg & 0xffff); |
| 1668 |
*data++ = val; |
| 1669 |
|
| 1670 |
val = 0; |
| 1671 |
if (!tg3_readphy(tp, MII_ADVERTISE, ®)) |
| 1672 |
val = reg << 16; |
| 1673 |
if (!tg3_readphy(tp, MII_LPA, ®)) |
| 1674 |
val |= (reg & 0xffff); |
| 1675 |
*data++ = val; |
| 1676 |
|
| 1677 |
val = 0; |
| 1678 |
if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
| 1679 |
if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
| 1680 |
val = reg << 16; |
| 1681 |
if (!tg3_readphy(tp, MII_STAT1000, ®)) |
| 1682 |
val |= (reg & 0xffff); |
| 1683 |
} |
| 1684 |
*data++ = val; |
| 1685 |
|
| 1686 |
if (!tg3_readphy(tp, MII_PHYADDR, ®)) |
| 1687 |
val = reg << 16; |
| 1688 |
else |
| 1689 |
val = 0; |
| 1690 |
*data++ = val; |
| 1691 |
} |
| 1692 |
|
| 1693 |
/* tp->lock is held. */ |
| 1694 |
static void tg3_ump_link_report(struct tg3 *tp) |
| 1695 |
{ |
| 1696 |
u32 data[4]; |
| 1697 |
|
| 1698 |
if (!tg3_flag(tp, 5780_CLASS) || !tg3_flag(tp, ENABLE_ASF)) |
| 1699 |
return; |
| 1700 |
|
| 1701 |
tg3_phy_gather_ump_data(tp, data); |
| 1702 |
|
| 1703 |
tg3_wait_for_event_ack(tp); |
| 1704 |
|
| 1705 |
tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); |
| 1706 |
tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); |
| 1707 |
tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x0, data[0]); |
| 1708 |
tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x4, data[1]); |
| 1709 |
tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x8, data[2]); |
| 1710 |
tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0xc, data[3]); |
| 1711 |
|
| 1712 |
tg3_generate_fw_event(tp); |
| 1713 |
} |
| 1714 |
|
| 1715 |
/* tp->lock is held. */ |
| 1716 |
static void tg3_stop_fw(struct tg3 *tp) |
| 1717 |
{ |
| 1718 |
if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
| 1719 |
/* Wait for RX cpu to ACK the previous event. */ |
| 1720 |
tg3_wait_for_event_ack(tp); |
| 1721 |
|
| 1722 |
tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); |
| 1723 |
|
| 1724 |
tg3_generate_fw_event(tp); |
| 1725 |
|
| 1726 |
/* Wait for RX cpu to ACK this event. */ |
| 1727 |
tg3_wait_for_event_ack(tp); |
| 1728 |
} |
| 1729 |
} |
| 1730 |
|
| 1731 |
/* tp->lock is held. */ |
| 1732 |
static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) |
| 1733 |
{ |
| 1734 |
tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
| 1735 |
NIC_SRAM_FIRMWARE_MBOX_MAGIC1); |
| 1736 |
|
| 1737 |
if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1738 |
switch (kind) { |
| 1739 |
case RESET_KIND_INIT: |
| 1740 |
tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1741 |
DRV_STATE_START); |
| 1742 |
break; |
| 1743 |
|
| 1744 |
case RESET_KIND_SHUTDOWN: |
| 1745 |
tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1746 |
DRV_STATE_UNLOAD); |
| 1747 |
break; |
| 1748 |
|
| 1749 |
case RESET_KIND_SUSPEND: |
| 1750 |
tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1751 |
DRV_STATE_SUSPEND); |
| 1752 |
break; |
| 1753 |
|
| 1754 |
default: |
| 1755 |
break; |
| 1756 |
} |
| 1757 |
} |
| 1758 |
} |
| 1759 |
|
| 1760 |
/* tp->lock is held. */ |
| 1761 |
static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) |
| 1762 |
{ |
| 1763 |
if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
| 1764 |
switch (kind) { |
| 1765 |
case RESET_KIND_INIT: |
| 1766 |
tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1767 |
DRV_STATE_START_DONE); |
| 1768 |
break; |
| 1769 |
|
| 1770 |
case RESET_KIND_SHUTDOWN: |
| 1771 |
tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1772 |
DRV_STATE_UNLOAD_DONE); |
| 1773 |
break; |
| 1774 |
|
| 1775 |
default: |
| 1776 |
break; |
| 1777 |
} |
| 1778 |
} |
| 1779 |
} |
| 1780 |
|
| 1781 |
/* tp->lock is held. */ |
| 1782 |
static void tg3_write_sig_legacy(struct tg3 *tp, int kind) |
| 1783 |
{ |
| 1784 |
if (tg3_flag(tp, ENABLE_ASF)) { |
| 1785 |
switch (kind) { |
| 1786 |
case RESET_KIND_INIT: |
| 1787 |
tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1788 |
DRV_STATE_START); |
| 1789 |
break; |
| 1790 |
|
| 1791 |
case RESET_KIND_SHUTDOWN: |
| 1792 |
tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1793 |
DRV_STATE_UNLOAD); |
| 1794 |
break; |
| 1795 |
|
| 1796 |
case RESET_KIND_SUSPEND: |
| 1797 |
tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, |
| 1798 |
DRV_STATE_SUSPEND); |
| 1799 |
break; |
| 1800 |
|
| 1801 |
default: |
| 1802 |
break; |
| 1803 |
} |
| 1804 |
} |
| 1805 |
} |
| 1806 |
|
| 1807 |
static int tg3_poll_fw(struct tg3 *tp) |
| 1808 |
{ |
| 1809 |
int i; |
| 1810 |
u32 val; |
| 1811 |
|
| 1812 |
if (tg3_flag(tp, NO_FWARE_REPORTED)) |
| 1813 |
return 0; |
| 1814 |
|
| 1815 |
if (tg3_flag(tp, IS_SSB_CORE)) { |
| 1816 |
/* We don't use firmware. */ |
| 1817 |
return 0; |
| 1818 |
} |
| 1819 |
|
| 1820 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 1821 |
/* Wait up to 20ms for init done. */ |
| 1822 |
for (i = 0; i < 200; i++) { |
| 1823 |
if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
| 1824 |
return 0; |
| 1825 |
if (pci_channel_offline(tp->pdev)) |
| 1826 |
return -ENODEV; |
| 1827 |
|
| 1828 |
udelay(100); |
| 1829 |
} |
| 1830 |
return -ENODEV; |
| 1831 |
} |
| 1832 |
|
| 1833 |
/* Wait for firmware initialization to complete. */ |
| 1834 |
for (i = 0; i < 100000; i++) { |
| 1835 |
tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); |
| 1836 |
if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 1837 |
break; |
| 1838 |
if (pci_channel_offline(tp->pdev)) { |
| 1839 |
if (!tg3_flag(tp, NO_FWARE_REPORTED)) { |
| 1840 |
tg3_flag_set(tp, NO_FWARE_REPORTED); |
| 1841 |
netdev_info(tp->dev, "No firmware running\n"); |
| 1842 |
} |
| 1843 |
|
| 1844 |
break; |
| 1845 |
} |
| 1846 |
|
| 1847 |
udelay(10); |
| 1848 |
} |
| 1849 |
|
| 1850 |
/* Chip might not be fitted with firmware. Some Sun onboard |
| 1851 |
* parts are configured like that. So don't signal the timeout |
| 1852 |
* of the above loop as an error, but do report the lack of |
| 1853 |
* running firmware once. |
| 1854 |
*/ |
| 1855 |
if (i >= 100000 && !tg3_flag(tp, NO_FWARE_REPORTED)) { |
| 1856 |
tg3_flag_set(tp, NO_FWARE_REPORTED); |
| 1857 |
|
| 1858 |
netdev_info(tp->dev, "No firmware running\n"); |
| 1859 |
} |
| 1860 |
|
| 1861 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) { |
| 1862 |
/* The 57765 A0 needs a little more |
| 1863 |
* time to do some important work. |
| 1864 |
*/ |
| 1865 |
mdelay(10); |
| 1866 |
} |
| 1867 |
|
| 1868 |
return 0; |
| 1869 |
} |
| 1870 |
|
| 1871 |
static void tg3_link_report(struct tg3 *tp) |
| 1872 |
{ |
| 1873 |
if (!netif_carrier_ok(tp->dev)) { |
| 1874 |
netif_info(tp, link, tp->dev, "Link is down\n"); |
| 1875 |
tg3_ump_link_report(tp); |
| 1876 |
} else if (netif_msg_link(tp)) { |
| 1877 |
netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
| 1878 |
(tp->link_config.active_speed == SPEED_1000 ? |
| 1879 |
1000 : |
| 1880 |
(tp->link_config.active_speed == SPEED_100 ? |
| 1881 |
100 : 10)), |
| 1882 |
(tp->link_config.active_duplex == DUPLEX_FULL ? |
| 1883 |
"full" : "half")); |
| 1884 |
|
| 1885 |
netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", |
| 1886 |
(tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? |
| 1887 |
"on" : "off", |
| 1888 |
(tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? |
| 1889 |
"on" : "off"); |
| 1890 |
|
| 1891 |
if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) |
| 1892 |
netdev_info(tp->dev, "EEE is %s\n", |
| 1893 |
tp->setlpicnt ? "enabled" : "disabled"); |
| 1894 |
|
| 1895 |
tg3_ump_link_report(tp); |
| 1896 |
} |
| 1897 |
|
| 1898 |
tp->link_up = netif_carrier_ok(tp->dev); |
| 1899 |
} |
| 1900 |
|
| 1901 |
static u32 tg3_decode_flowctrl_1000T(u32 adv) |
| 1902 |
{ |
| 1903 |
u32 flowctrl = 0; |
| 1904 |
|
| 1905 |
if (adv & ADVERTISE_PAUSE_CAP) { |
| 1906 |
flowctrl |= FLOW_CTRL_RX; |
| 1907 |
if (!(adv & ADVERTISE_PAUSE_ASYM)) |
| 1908 |
flowctrl |= FLOW_CTRL_TX; |
| 1909 |
} else if (adv & ADVERTISE_PAUSE_ASYM) |
| 1910 |
flowctrl |= FLOW_CTRL_TX; |
| 1911 |
|
| 1912 |
return flowctrl; |
| 1913 |
} |
| 1914 |
|
| 1915 |
static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
| 1916 |
{ |
| 1917 |
u16 miireg; |
| 1918 |
|
| 1919 |
if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
| 1920 |
miireg = ADVERTISE_1000XPAUSE; |
| 1921 |
else if (flow_ctrl & FLOW_CTRL_TX) |
| 1922 |
miireg = ADVERTISE_1000XPSE_ASYM; |
| 1923 |
else if (flow_ctrl & FLOW_CTRL_RX) |
| 1924 |
miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
| 1925 |
else |
| 1926 |
miireg = 0; |
| 1927 |
|
| 1928 |
return miireg; |
| 1929 |
} |
| 1930 |
|
| 1931 |
static u32 tg3_decode_flowctrl_1000X(u32 adv) |
| 1932 |
{ |
| 1933 |
u32 flowctrl = 0; |
| 1934 |
|
| 1935 |
if (adv & ADVERTISE_1000XPAUSE) { |
| 1936 |
flowctrl |= FLOW_CTRL_RX; |
| 1937 |
if (!(adv & ADVERTISE_1000XPSE_ASYM)) |
| 1938 |
flowctrl |= FLOW_CTRL_TX; |
| 1939 |
} else if (adv & ADVERTISE_1000XPSE_ASYM) |
| 1940 |
flowctrl |= FLOW_CTRL_TX; |
| 1941 |
|
| 1942 |
return flowctrl; |
| 1943 |
} |
| 1944 |
|
| 1945 |
static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
| 1946 |
{ |
| 1947 |
u8 cap = 0; |
| 1948 |
|
| 1949 |
if (lcladv & rmtadv & ADVERTISE_1000XPAUSE) { |
| 1950 |
cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 1951 |
} else if (lcladv & rmtadv & ADVERTISE_1000XPSE_ASYM) { |
| 1952 |
if (lcladv & ADVERTISE_1000XPAUSE) |
| 1953 |
cap = FLOW_CTRL_RX; |
| 1954 |
if (rmtadv & ADVERTISE_1000XPAUSE) |
| 1955 |
cap = FLOW_CTRL_TX; |
| 1956 |
} |
| 1957 |
|
| 1958 |
return cap; |
| 1959 |
} |
| 1960 |
|
| 1961 |
static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv) |
| 1962 |
{ |
| 1963 |
u8 autoneg; |
| 1964 |
u8 flowctrl = 0; |
| 1965 |
u32 old_rx_mode = tp->rx_mode; |
| 1966 |
u32 old_tx_mode = tp->tx_mode; |
| 1967 |
|
| 1968 |
if (tg3_flag(tp, USE_PHYLIB)) |
| 1969 |
autoneg = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr)->autoneg; |
| 1970 |
else |
| 1971 |
autoneg = tp->link_config.autoneg; |
| 1972 |
|
| 1973 |
if (autoneg == AUTONEG_ENABLE && tg3_flag(tp, PAUSE_AUTONEG)) { |
| 1974 |
if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 1975 |
flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
| 1976 |
else |
| 1977 |
flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
| 1978 |
} else |
| 1979 |
flowctrl = tp->link_config.flowctrl; |
| 1980 |
|
| 1981 |
tp->link_config.active_flowctrl = flowctrl; |
| 1982 |
|
| 1983 |
if (flowctrl & FLOW_CTRL_RX) |
| 1984 |
tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
| 1985 |
else |
| 1986 |
tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; |
| 1987 |
|
| 1988 |
if (old_rx_mode != tp->rx_mode) |
| 1989 |
tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 1990 |
|
| 1991 |
if (flowctrl & FLOW_CTRL_TX) |
| 1992 |
tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
| 1993 |
else |
| 1994 |
tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; |
| 1995 |
|
| 1996 |
if (old_tx_mode != tp->tx_mode) |
| 1997 |
tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 1998 |
} |
| 1999 |
|
| 2000 |
static void tg3_adjust_link(struct net_device *dev) |
| 2001 |
{ |
| 2002 |
u8 oldflowctrl, linkmesg = 0; |
| 2003 |
u32 mac_mode, lcl_adv, rmt_adv; |
| 2004 |
struct tg3 *tp = netdev_priv(dev); |
| 2005 |
struct phy_device *phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr); |
| 2006 |
|
| 2007 |
spin_lock_bh(&tp->lock); |
| 2008 |
|
| 2009 |
mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | |
| 2010 |
MAC_MODE_HALF_DUPLEX); |
| 2011 |
|
| 2012 |
oldflowctrl = tp->link_config.active_flowctrl; |
| 2013 |
|
| 2014 |
if (phydev->link) { |
| 2015 |
lcl_adv = 0; |
| 2016 |
rmt_adv = 0; |
| 2017 |
|
| 2018 |
if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) |
| 2019 |
mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 2020 |
else if (phydev->speed == SPEED_1000 || |
| 2021 |
tg3_asic_rev(tp) != ASIC_REV_5785) |
| 2022 |
mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 2023 |
else |
| 2024 |
mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 2025 |
|
| 2026 |
if (phydev->duplex == DUPLEX_HALF) |
| 2027 |
mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 2028 |
else { |
| 2029 |
lcl_adv = mii_advertise_flowctrl( |
| 2030 |
tp->link_config.flowctrl); |
| 2031 |
|
| 2032 |
if (phydev->pause) |
| 2033 |
rmt_adv = LPA_PAUSE_CAP; |
| 2034 |
if (phydev->asym_pause) |
| 2035 |
rmt_adv |= LPA_PAUSE_ASYM; |
| 2036 |
} |
| 2037 |
|
| 2038 |
tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 2039 |
} else |
| 2040 |
mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 2041 |
|
| 2042 |
if (mac_mode != tp->mac_mode) { |
| 2043 |
tp->mac_mode = mac_mode; |
| 2044 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 2045 |
udelay(40); |
| 2046 |
} |
| 2047 |
|
| 2048 |
if (tg3_asic_rev(tp) == ASIC_REV_5785) { |
| 2049 |
if (phydev->speed == SPEED_10) |
| 2050 |
tw32(MAC_MI_STAT, |
| 2051 |
MAC_MI_STAT_10MBPS_MODE | |
| 2052 |
MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 2053 |
else |
| 2054 |
tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 2055 |
} |
| 2056 |
|
| 2057 |
if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
| 2058 |
tw32(MAC_TX_LENGTHS, |
| 2059 |
((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 2060 |
(6 << TX_LENGTHS_IPG_SHIFT) | |
| 2061 |
(0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 2062 |
else |
| 2063 |
tw32(MAC_TX_LENGTHS, |
| 2064 |
((2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 2065 |
(6 << TX_LENGTHS_IPG_SHIFT) | |
| 2066 |
(32 << TX_LENGTHS_SLOT_TIME_SHIFT))); |
| 2067 |
|
| 2068 |
if (phydev->link != tp->old_link || |
| 2069 |
phydev->speed != tp->link_config.active_speed || |
| 2070 |
phydev->duplex != tp->link_config.active_duplex || |
| 2071 |
oldflowctrl != tp->link_config.active_flowctrl) |
| 2072 |
linkmesg = 1; |
| 2073 |
|
| 2074 |
tp->old_link = phydev->link; |
| 2075 |
tp->link_config.active_speed = phydev->speed; |
| 2076 |
tp->link_config.active_duplex = phydev->duplex; |
| 2077 |
|
| 2078 |
spin_unlock_bh(&tp->lock); |
| 2079 |
|
| 2080 |
if (linkmesg) |
| 2081 |
tg3_link_report(tp); |
| 2082 |
} |
| 2083 |
|
| 2084 |
static int tg3_phy_init(struct tg3 *tp) |
| 2085 |
{ |
| 2086 |
struct phy_device *phydev; |
| 2087 |
|
| 2088 |
if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
| 2089 |
return 0; |
| 2090 |
|
| 2091 |
/* Bring the PHY back to a known state. */ |
| 2092 |
tg3_bmcr_reset(tp); |
| 2093 |
|
| 2094 |
phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr); |
| 2095 |
|
| 2096 |
/* Attach the MAC to the PHY. */ |
| 2097 |
phydev = phy_connect(tp->dev, phydev_name(phydev), |
| 2098 |
tg3_adjust_link, phydev->interface); |
| 2099 |
if (IS_ERR(phydev)) { |
| 2100 |
dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
| 2101 |
return PTR_ERR(phydev); |
| 2102 |
} |
| 2103 |
|
| 2104 |
/* Mask with MAC supported features. */ |
| 2105 |
switch (phydev->interface) { |
| 2106 |
case PHY_INTERFACE_MODE_GMII: |
| 2107 |
case PHY_INTERFACE_MODE_RGMII: |
| 2108 |
if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 2109 |
phy_set_max_speed(phydev, SPEED_1000); |
| 2110 |
phy_support_asym_pause(phydev); |
| 2111 |
break; |
| 2112 |
} |
| 2113 |
fallthrough; |
| 2114 |
case PHY_INTERFACE_MODE_MII: |
| 2115 |
phy_set_max_speed(phydev, SPEED_100); |
| 2116 |
phy_support_asym_pause(phydev); |
| 2117 |
break; |
| 2118 |
default: |
| 2119 |
phy_disconnect(mdiobus_get_phy(tp->mdio_bus, tp->phy_addr)); |
| 2120 |
return -EINVAL; |
| 2121 |
} |
| 2122 |
|
| 2123 |
tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
| 2124 |
|
| 2125 |
phy_attached_info(phydev); |
| 2126 |
|
| 2127 |
return 0; |
| 2128 |
} |
| 2129 |
|
| 2130 |
static void tg3_phy_start(struct tg3 *tp) |
| 2131 |
{ |
| 2132 |
struct phy_device *phydev; |
| 2133 |
|
| 2134 |
if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
| 2135 |
return; |
| 2136 |
|
| 2137 |
phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr); |
| 2138 |
|
| 2139 |
if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 2140 |
tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
| 2141 |
phydev->speed = tp->link_config.speed; |
| 2142 |
phydev->duplex = tp->link_config.duplex; |
| 2143 |
phydev->autoneg = tp->link_config.autoneg; |
| 2144 |
ethtool_convert_legacy_u32_to_link_mode( |
| 2145 |
phydev->advertising, tp->link_config.advertising); |
| 2146 |
} |
| 2147 |
|
| 2148 |
phy_start(phydev); |
| 2149 |
|
| 2150 |
phy_start_aneg(phydev); |
| 2151 |
} |
| 2152 |
|
| 2153 |
static void tg3_phy_stop(struct tg3 *tp) |
| 2154 |
{ |
| 2155 |
if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
| 2156 |
return; |
| 2157 |
|
| 2158 |
phy_stop(mdiobus_get_phy(tp->mdio_bus, tp->phy_addr)); |
| 2159 |
} |
| 2160 |
|
| 2161 |
static void tg3_phy_fini(struct tg3 *tp) |
| 2162 |
{ |
| 2163 |
if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
| 2164 |
phy_disconnect(mdiobus_get_phy(tp->mdio_bus, tp->phy_addr)); |
| 2165 |
tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
| 2166 |
} |
| 2167 |
} |
| 2168 |
|
| 2169 |
static int tg3_phy_set_extloopbk(struct tg3 *tp) |
| 2170 |
{ |
| 2171 |
int err; |
| 2172 |
u32 val; |
| 2173 |
|
| 2174 |
if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 2175 |
return 0; |
| 2176 |
|
| 2177 |
if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
| 2178 |
/* Cannot do read-modify-write on 5401 */ |
| 2179 |
err = tg3_phy_auxctl_write(tp, |
| 2180 |
MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2181 |
MII_TG3_AUXCTL_ACTL_EXTLOOPBK | |
| 2182 |
0x4c20); |
| 2183 |
goto done; |
| 2184 |
} |
| 2185 |
|
| 2186 |
err = tg3_phy_auxctl_read(tp, |
| 2187 |
MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2188 |
if (err) |
| 2189 |
return err; |
| 2190 |
|
| 2191 |
val |= MII_TG3_AUXCTL_ACTL_EXTLOOPBK; |
| 2192 |
err = tg3_phy_auxctl_write(tp, |
| 2193 |
MII_TG3_AUXCTL_SHDWSEL_AUXCTL, val); |
| 2194 |
|
| 2195 |
done: |
| 2196 |
return err; |
| 2197 |
} |
| 2198 |
|
| 2199 |
static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
| 2200 |
{ |
| 2201 |
u32 phytest; |
| 2202 |
|
| 2203 |
if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 2204 |
u32 phy; |
| 2205 |
|
| 2206 |
tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2207 |
phytest | MII_TG3_FET_SHADOW_EN); |
| 2208 |
if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { |
| 2209 |
if (enable) |
| 2210 |
phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 2211 |
else |
| 2212 |
phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; |
| 2213 |
tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); |
| 2214 |
} |
| 2215 |
tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 2216 |
} |
| 2217 |
} |
| 2218 |
|
| 2219 |
static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
| 2220 |
{ |
| 2221 |
u32 reg; |
| 2222 |
|
| 2223 |
if (!tg3_flag(tp, 5705_PLUS) || |
| 2224 |
(tg3_flag(tp, 5717_PLUS) && |
| 2225 |
(tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
| 2226 |
return; |
| 2227 |
|
| 2228 |
if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 2229 |
tg3_phy_fet_toggle_apd(tp, enable); |
| 2230 |
return; |
| 2231 |
} |
| 2232 |
|
| 2233 |
reg = MII_TG3_MISC_SHDW_SCR5_LPED | |
| 2234 |
MII_TG3_MISC_SHDW_SCR5_DLPTLM | |
| 2235 |
MII_TG3_MISC_SHDW_SCR5_SDTL | |
| 2236 |
MII_TG3_MISC_SHDW_SCR5_C125OE; |
| 2237 |
if (tg3_asic_rev(tp) != ASIC_REV_5784 || !enable) |
| 2238 |
reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
| 2239 |
|
| 2240 |
tg3_phy_shdw_write(tp, MII_TG3_MISC_SHDW_SCR5_SEL, reg); |
| 2241 |
|
| 2242 |
|
| 2243 |
reg = MII_TG3_MISC_SHDW_APD_WKTM_84MS; |
| 2244 |
if (enable) |
| 2245 |
reg |= MII_TG3_MISC_SHDW_APD_ENABLE; |
| 2246 |
|
| 2247 |
tg3_phy_shdw_write(tp, MII_TG3_MISC_SHDW_APD_SEL, reg); |
| 2248 |
} |
| 2249 |
|
| 2250 |
static void tg3_phy_toggle_automdix(struct tg3 *tp, bool enable) |
| 2251 |
{ |
| 2252 |
u32 phy; |
| 2253 |
|
| 2254 |
if (!tg3_flag(tp, 5705_PLUS) || |
| 2255 |
(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 2256 |
return; |
| 2257 |
|
| 2258 |
if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 2259 |
u32 ephy; |
| 2260 |
|
| 2261 |
if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
| 2262 |
u32 reg = MII_TG3_FET_SHDW_MISCCTRL; |
| 2263 |
|
| 2264 |
tg3_writephy(tp, MII_TG3_FET_TEST, |
| 2265 |
ephy | MII_TG3_FET_SHADOW_EN); |
| 2266 |
if (!tg3_readphy(tp, reg, &phy)) { |
| 2267 |
if (enable) |
| 2268 |
phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 2269 |
else |
| 2270 |
phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
| 2271 |
tg3_writephy(tp, reg, phy); |
| 2272 |
} |
| 2273 |
tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
| 2274 |
} |
| 2275 |
} else { |
| 2276 |
int ret; |
| 2277 |
|
| 2278 |
ret = tg3_phy_auxctl_read(tp, |
| 2279 |
MII_TG3_AUXCTL_SHDWSEL_MISC, &phy); |
| 2280 |
if (!ret) { |
| 2281 |
if (enable) |
| 2282 |
phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 2283 |
else |
| 2284 |
phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; |
| 2285 |
tg3_phy_auxctl_write(tp, |
| 2286 |
MII_TG3_AUXCTL_SHDWSEL_MISC, phy); |
| 2287 |
} |
| 2288 |
} |
| 2289 |
} |
| 2290 |
|
| 2291 |
static void tg3_phy_set_wirespeed(struct tg3 *tp) |
| 2292 |
{ |
| 2293 |
int ret; |
| 2294 |
u32 val; |
| 2295 |
|
| 2296 |
if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
| 2297 |
return; |
| 2298 |
|
| 2299 |
ret = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, &val); |
| 2300 |
if (!ret) |
| 2301 |
tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, |
| 2302 |
val | MII_TG3_AUXCTL_MISC_WIRESPD_EN); |
| 2303 |
} |
| 2304 |
|
| 2305 |
static void tg3_phy_apply_otp(struct tg3 *tp) |
| 2306 |
{ |
| 2307 |
u32 otp, phy; |
| 2308 |
|
| 2309 |
if (!tp->phy_otp) |
| 2310 |
return; |
| 2311 |
|
| 2312 |
otp = tp->phy_otp; |
| 2313 |
|
| 2314 |
if (tg3_phy_toggle_auxctl_smdsp(tp, true)) |
| 2315 |
return; |
| 2316 |
|
| 2317 |
phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); |
| 2318 |
phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; |
| 2319 |
tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); |
| 2320 |
|
| 2321 |
phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | |
| 2322 |
((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); |
| 2323 |
tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); |
| 2324 |
|
| 2325 |
phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); |
| 2326 |
phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; |
| 2327 |
tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); |
| 2328 |
|
| 2329 |
phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); |
| 2330 |
tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); |
| 2331 |
|
| 2332 |
phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); |
| 2333 |
tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); |
| 2334 |
|
| 2335 |
phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | |
| 2336 |
((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); |
| 2337 |
tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); |
| 2338 |
|
| 2339 |
tg3_phy_toggle_auxctl_smdsp(tp, false); |
| 2340 |
} |
| 2341 |
|
| 2342 |
static void tg3_eee_pull_config(struct tg3 *tp, struct ethtool_keee *eee) |
| 2343 |
{ |
| 2344 |
u32 val; |
| 2345 |
struct ethtool_keee *dest = &tp->eee; |
| 2346 |
|
| 2347 |
if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 2348 |
return; |
| 2349 |
|
| 2350 |
if (eee) |
| 2351 |
dest = eee; |
| 2352 |
|
| 2353 |
if (tg3_phy_cl45_read(tp, MDIO_MMD_AN, TG3_CL45_D7_EEERES_STAT, &val)) |
| 2354 |
return; |
| 2355 |
|
| 2356 |
/* Pull eee_active */ |
| 2357 |
if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
| 2358 |
val == TG3_CL45_D7_EEERES_STAT_LP_100TX) { |
| 2359 |
dest->eee_active = 1; |
| 2360 |
} else |
| 2361 |
dest->eee_active = 0; |
| 2362 |
|
| 2363 |
/* Pull lp advertised settings */ |
| 2364 |
if (tg3_phy_cl45_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_LPABLE, &val)) |
| 2365 |
return; |
| 2366 |
mii_eee_cap1_mod_linkmode_t(dest->lp_advertised, val); |
| 2367 |
|
| 2368 |
/* Pull advertised and eee_enabled settings */ |
| 2369 |
if (tg3_phy_cl45_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, &val)) |
| 2370 |
return; |
| 2371 |
dest->eee_enabled = !!val; |
| 2372 |
mii_eee_cap1_mod_linkmode_t(dest->advertised, val); |
| 2373 |
|
| 2374 |
/* Pull tx_lpi_enabled */ |
| 2375 |
val = tr32(TG3_CPMU_EEE_MODE); |
| 2376 |
dest->tx_lpi_enabled = !!(val & TG3_CPMU_EEEMD_LPI_IN_TX); |
| 2377 |
|
| 2378 |
/* Pull lpi timer value */ |
| 2379 |
dest->tx_lpi_timer = tr32(TG3_CPMU_EEE_DBTMR1) & 0xffff; |
| 2380 |
} |
| 2381 |
|
| 2382 |
static void tg3_phy_eee_adjust(struct tg3 *tp, bool current_link_up) |
| 2383 |
{ |
| 2384 |
u32 val; |
| 2385 |
|
| 2386 |
if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 2387 |
return; |
| 2388 |
|
| 2389 |
tp->setlpicnt = 0; |
| 2390 |
|
| 2391 |
if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 2392 |
current_link_up && |
| 2393 |
tp->link_config.active_duplex == DUPLEX_FULL && |
| 2394 |
(tp->link_config.active_speed == SPEED_100 || |
| 2395 |
tp->link_config.active_speed == SPEED_1000)) { |
| 2396 |
u32 eeectl; |
| 2397 |
|
| 2398 |
if (tp->link_config.active_speed == SPEED_1000) |
| 2399 |
eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; |
| 2400 |
else |
| 2401 |
eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; |
| 2402 |
|
| 2403 |
tw32(TG3_CPMU_EEE_CTRL, eeectl); |
| 2404 |
|
| 2405 |
tg3_eee_pull_config(tp, NULL); |
| 2406 |
if (tp->eee.eee_active) |
| 2407 |
tp->setlpicnt = 2; |
| 2408 |
} |
| 2409 |
|
| 2410 |
if (!tp->setlpicnt) { |
| 2411 |
if (current_link_up && |
| 2412 |
!tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
| 2413 |
tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, 0x0000); |
| 2414 |
tg3_phy_toggle_auxctl_smdsp(tp, false); |
| 2415 |
} |
| 2416 |
|
| 2417 |
val = tr32(TG3_CPMU_EEE_MODE); |
| 2418 |
tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2419 |
} |
| 2420 |
} |
| 2421 |
|
| 2422 |
static void tg3_phy_eee_enable(struct tg3 *tp) |
| 2423 |
{ |
| 2424 |
u32 val; |
| 2425 |
|
| 2426 |
if (tp->link_config.active_speed == SPEED_1000 && |
| 2427 |
(tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 2428 |
tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 2429 |
tg3_flag(tp, 57765_CLASS)) && |
| 2430 |
!tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
| 2431 |
val = MII_TG3_DSP_TAP26_ALNOKO | |
| 2432 |
MII_TG3_DSP_TAP26_RMRXSTO; |
| 2433 |
tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
| 2434 |
tg3_phy_toggle_auxctl_smdsp(tp, false); |
| 2435 |
} |
| 2436 |
|
| 2437 |
val = tr32(TG3_CPMU_EEE_MODE); |
| 2438 |
tw32(TG3_CPMU_EEE_MODE, val | TG3_CPMU_EEEMD_LPI_ENABLE); |
| 2439 |
} |
| 2440 |
|
| 2441 |
static int tg3_wait_macro_done(struct tg3 *tp) |
| 2442 |
{ |
| 2443 |
int limit = 100; |
| 2444 |
|
| 2445 |
while (limit--) { |
| 2446 |
u32 tmp32; |
| 2447 |
|
| 2448 |
if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
| 2449 |
if ((tmp32 & 0x1000) == 0) |
| 2450 |
break; |
| 2451 |
} |
| 2452 |
} |
| 2453 |
if (limit < 0) |
| 2454 |
return -EBUSY; |
| 2455 |
|
| 2456 |
return 0; |
| 2457 |
} |
| 2458 |
|
| 2459 |
static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) |
| 2460 |
{ |
| 2461 |
static const u32 test_pat[4][6] = { |
| 2462 |
{ 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, |
| 2463 |
{ 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, |
| 2464 |
{ 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, |
| 2465 |
{ 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } |
| 2466 |
}; |
| 2467 |
int chan; |
| 2468 |
|
| 2469 |
for (chan = 0; chan < 4; chan++) { |
| 2470 |
int i; |
| 2471 |
|
| 2472 |
tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2473 |
(chan * 0x2000) | 0x0200); |
| 2474 |
tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
| 2475 |
|
| 2476 |
for (i = 0; i < 6; i++) |
| 2477 |
tg3_writephy(tp, MII_TG3_DSP_RW_PORT, |
| 2478 |
test_pat[chan][i]); |
| 2479 |
|
| 2480 |
tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
| 2481 |
if (tg3_wait_macro_done(tp)) { |
| 2482 |
*resetp = 1; |
| 2483 |
return -EBUSY; |
| 2484 |
} |
| 2485 |
|
| 2486 |
tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2487 |
(chan * 0x2000) | 0x0200); |
| 2488 |
tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
| 2489 |
if (tg3_wait_macro_done(tp)) { |
| 2490 |
*resetp = 1; |
| 2491 |
return -EBUSY; |
| 2492 |
} |
| 2493 |
|
| 2494 |
tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
| 2495 |
if (tg3_wait_macro_done(tp)) { |
| 2496 |
*resetp = 1; |
| 2497 |
return -EBUSY; |
| 2498 |
} |
| 2499 |
|
| 2500 |
for (i = 0; i < 6; i += 2) { |
| 2501 |
u32 low, high; |
| 2502 |
|
| 2503 |
if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || |
| 2504 |
tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || |
| 2505 |
tg3_wait_macro_done(tp)) { |
| 2506 |
*resetp = 1; |
| 2507 |
return -EBUSY; |
| 2508 |
} |
| 2509 |
low &= 0x7fff; |
| 2510 |
high &= 0x000f; |
| 2511 |
if (low != test_pat[chan][i] || |
| 2512 |
high != test_pat[chan][i+1]) { |
| 2513 |
tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); |
| 2514 |
tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); |
| 2515 |
tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); |
| 2516 |
|
| 2517 |
return -EBUSY; |
| 2518 |
} |
| 2519 |
} |
| 2520 |
} |
| 2521 |
|
| 2522 |
return 0; |
| 2523 |
} |
| 2524 |
|
| 2525 |
static int tg3_phy_reset_chanpat(struct tg3 *tp) |
| 2526 |
{ |
| 2527 |
int chan; |
| 2528 |
|
| 2529 |
for (chan = 0; chan < 4; chan++) { |
| 2530 |
int i; |
| 2531 |
|
| 2532 |
tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 2533 |
(chan * 0x2000) | 0x0200); |
| 2534 |
tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
| 2535 |
for (i = 0; i < 6; i++) |
| 2536 |
tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); |
| 2537 |
tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
| 2538 |
if (tg3_wait_macro_done(tp)) |
| 2539 |
return -EBUSY; |
| 2540 |
} |
| 2541 |
|
| 2542 |
return 0; |
| 2543 |
} |
| 2544 |
|
| 2545 |
static int tg3_phy_reset_5703_4_5(struct tg3 *tp) |
| 2546 |
{ |
| 2547 |
u32 reg32, phy9_orig; |
| 2548 |
int retries, do_phy_reset, err; |
| 2549 |
|
| 2550 |
retries = 10; |
| 2551 |
do_phy_reset = 1; |
| 2552 |
do { |
| 2553 |
if (do_phy_reset) { |
| 2554 |
err = tg3_bmcr_reset(tp); |
| 2555 |
if (err) |
| 2556 |
return err; |
| 2557 |
do_phy_reset = 0; |
| 2558 |
} |
| 2559 |
|
| 2560 |
/* Disable transmitter and interrupt. */ |
| 2561 |
if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) |
| 2562 |
continue; |
| 2563 |
|
| 2564 |
reg32 |= 0x3000; |
| 2565 |
tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2566 |
|
| 2567 |
/* Set full-duplex, 1000 mbps. */ |
| 2568 |
tg3_writephy(tp, MII_BMCR, |
| 2569 |
BMCR_FULLDPLX | BMCR_SPEED1000); |
| 2570 |
|
| 2571 |
/* Set to master mode. */ |
| 2572 |
if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig)) |
| 2573 |
continue; |
| 2574 |
|
| 2575 |
tg3_writephy(tp, MII_CTRL1000, |
| 2576 |
CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
| 2577 |
|
| 2578 |
err = tg3_phy_toggle_auxctl_smdsp(tp, true); |
| 2579 |
if (err) |
| 2580 |
return err; |
| 2581 |
|
| 2582 |
/* Block the PHY control access. */ |
| 2583 |
tg3_phydsp_write(tp, 0x8005, 0x0800); |
| 2584 |
|
| 2585 |
err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); |
| 2586 |
if (!err) |
| 2587 |
break; |
| 2588 |
} while (--retries); |
| 2589 |
|
| 2590 |
err = tg3_phy_reset_chanpat(tp); |
| 2591 |
if (err) |
| 2592 |
return err; |
| 2593 |
|
| 2594 |
tg3_phydsp_write(tp, 0x8005, 0x0000); |
| 2595 |
|
| 2596 |
tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); |
| 2597 |
tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
| 2598 |
|
| 2599 |
tg3_phy_toggle_auxctl_smdsp(tp, false); |
| 2600 |
|
| 2601 |
tg3_writephy(tp, MII_CTRL1000, phy9_orig); |
| 2602 |
|
| 2603 |
err = tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32); |
| 2604 |
if (err) |
| 2605 |
return err; |
| 2606 |
|
| 2607 |
reg32 &= ~0x3000; |
| 2608 |
tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); |
| 2609 |
|
| 2610 |
return 0; |
| 2611 |
} |
| 2612 |
|
| 2613 |
static void tg3_carrier_off(struct tg3 *tp) |
| 2614 |
{ |
| 2615 |
netif_carrier_off(tp->dev); |
| 2616 |
tp->link_up = false; |
| 2617 |
} |
| 2618 |
|
| 2619 |
static void tg3_warn_mgmt_link_flap(struct tg3 *tp) |
| 2620 |
{ |
| 2621 |
if (tg3_flag(tp, ENABLE_ASF)) |
| 2622 |
netdev_warn(tp->dev, |
| 2623 |
"Management side-band traffic will be interrupted during phy settings change\n"); |
| 2624 |
} |
| 2625 |
|
| 2626 |
/* This will reset the tigon3 PHY if there is no valid |
| 2627 |
* link unless the FORCE argument is non-zero. |
| 2628 |
*/ |
| 2629 |
static int tg3_phy_reset(struct tg3 *tp) |
| 2630 |
{ |
| 2631 |
u32 val, cpmuctrl; |
| 2632 |
int err; |
| 2633 |
|
| 2634 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 2635 |
val = tr32(GRC_MISC_CFG); |
| 2636 |
tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); |
| 2637 |
udelay(40); |
| 2638 |
} |
| 2639 |
err = tg3_readphy(tp, MII_BMSR, &val); |
| 2640 |
err |= tg3_readphy(tp, MII_BMSR, &val); |
| 2641 |
if (err != 0) |
| 2642 |
return -EBUSY; |
| 2643 |
|
| 2644 |
if (netif_running(tp->dev) && tp->link_up) { |
| 2645 |
netif_carrier_off(tp->dev); |
| 2646 |
tg3_link_report(tp); |
| 2647 |
} |
| 2648 |
|
| 2649 |
if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
| 2650 |
tg3_asic_rev(tp) == ASIC_REV_5704 || |
| 2651 |
tg3_asic_rev(tp) == ASIC_REV_5705) { |
| 2652 |
err = tg3_phy_reset_5703_4_5(tp); |
| 2653 |
if (err) |
| 2654 |
return err; |
| 2655 |
goto out; |
| 2656 |
} |
| 2657 |
|
| 2658 |
cpmuctrl = 0; |
| 2659 |
if (tg3_asic_rev(tp) == ASIC_REV_5784 && |
| 2660 |
tg3_chip_rev(tp) != CHIPREV_5784_AX) { |
| 2661 |
cpmuctrl = tr32(TG3_CPMU_CTRL); |
| 2662 |
if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) |
| 2663 |
tw32(TG3_CPMU_CTRL, |
| 2664 |
cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); |
| 2665 |
} |
| 2666 |
|
| 2667 |
err = tg3_bmcr_reset(tp); |
| 2668 |
if (err) |
| 2669 |
return err; |
| 2670 |
|
| 2671 |
if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
| 2672 |
val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
| 2673 |
tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); |
| 2674 |
|
| 2675 |
tw32(TG3_CPMU_CTRL, cpmuctrl); |
| 2676 |
} |
| 2677 |
|
| 2678 |
if (tg3_chip_rev(tp) == CHIPREV_5784_AX || |
| 2679 |
tg3_chip_rev(tp) == CHIPREV_5761_AX) { |
| 2680 |
val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 2681 |
if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == |
| 2682 |
CPMU_LSPD_1000MB_MACCLK_12_5) { |
| 2683 |
val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 2684 |
udelay(40); |
| 2685 |
tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 2686 |
} |
| 2687 |
} |
| 2688 |
|
| 2689 |
if (tg3_flag(tp, 5717_PLUS) && |
| 2690 |
(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
| 2691 |
return 0; |
| 2692 |
|
| 2693 |
tg3_phy_apply_otp(tp); |
| 2694 |
|
| 2695 |
if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
| 2696 |
tg3_phy_toggle_apd(tp, true); |
| 2697 |
else |
| 2698 |
tg3_phy_toggle_apd(tp, false); |
| 2699 |
|
| 2700 |
out: |
| 2701 |
if ((tp->phy_flags & TG3_PHYFLG_ADC_BUG) && |
| 2702 |
!tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
| 2703 |
tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
| 2704 |
tg3_phydsp_write(tp, 0x000a, 0x0323); |
| 2705 |
tg3_phy_toggle_auxctl_smdsp(tp, false); |
| 2706 |
} |
| 2707 |
|
| 2708 |
if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
| 2709 |
tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 2710 |
tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 2711 |
} |
| 2712 |
|
| 2713 |
if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
| 2714 |
if (!tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
| 2715 |
tg3_phydsp_write(tp, 0x000a, 0x310b); |
| 2716 |
tg3_phydsp_write(tp, 0x201f, 0x9506); |
| 2717 |
tg3_phydsp_write(tp, 0x401f, 0x14e2); |
| 2718 |
tg3_phy_toggle_auxctl_smdsp(tp, false); |
| 2719 |
} |
| 2720 |
} else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
| 2721 |
if (!tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
| 2722 |
tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
| 2723 |
if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { |
| 2724 |
tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
| 2725 |
tg3_writephy(tp, MII_TG3_TEST1, |
| 2726 |
MII_TG3_TEST1_TRIM_EN | 0x4); |
| 2727 |
} else |
| 2728 |
tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); |
| 2729 |
|
| 2730 |
tg3_phy_toggle_auxctl_smdsp(tp, false); |
| 2731 |
} |
| 2732 |
} |
| 2733 |
|
| 2734 |
/* Set Extended packet length bit (bit 14) on all chips that */ |
| 2735 |
/* support jumbo frames */ |
| 2736 |
if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
| 2737 |
/* Cannot do read-modify-write on 5401 */ |
| 2738 |
tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
| 2739 |
} else if (tg3_flag(tp, JUMBO_CAPABLE)) { |
| 2740 |
/* Set bit 14 with read-modify-write to preserve other bits */ |
| 2741 |
err = tg3_phy_auxctl_read(tp, |
| 2742 |
MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
| 2743 |
if (!err) |
| 2744 |
tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
| 2745 |
val | MII_TG3_AUXCTL_ACTL_EXTPKTLEN); |
| 2746 |
} |
| 2747 |
|
| 2748 |
/* Set phy register 0x10 bit 0 to high fifo elasticity to support |
| 2749 |
* jumbo frames transmission. |
| 2750 |
*/ |
| 2751 |
if (tg3_flag(tp, JUMBO_CAPABLE)) { |
| 2752 |
if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
| 2753 |
tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 2754 |
val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
| 2755 |
} |
| 2756 |
|
| 2757 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 2758 |
/* adjust output voltage */ |
| 2759 |
tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
| 2760 |
} |
| 2761 |
|
| 2762 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5762_A0) |
| 2763 |
tg3_phydsp_write(tp, 0xffb, 0x4000); |
| 2764 |
|
| 2765 |
tg3_phy_toggle_automdix(tp, true); |
| 2766 |
tg3_phy_set_wirespeed(tp); |
| 2767 |
return 0; |
| 2768 |
} |
| 2769 |
|
| 2770 |
#define TG3_GPIO_MSG_DRVR_PRES 0x00000001 |
| 2771 |
#define TG3_GPIO_MSG_NEED_VAUX 0x00000002 |
| 2772 |
#define TG3_GPIO_MSG_MASK (TG3_GPIO_MSG_DRVR_PRES | \ |
| 2773 |
TG3_GPIO_MSG_NEED_VAUX) |
| 2774 |
#define TG3_GPIO_MSG_ALL_DRVR_PRES_MASK \ |
| 2775 |
((TG3_GPIO_MSG_DRVR_PRES << 0) | \ |
| 2776 |
(TG3_GPIO_MSG_DRVR_PRES << 4) | \ |
| 2777 |
(TG3_GPIO_MSG_DRVR_PRES << 8) | \ |
| 2778 |
(TG3_GPIO_MSG_DRVR_PRES << 12)) |
| 2779 |
|
| 2780 |
#define TG3_GPIO_MSG_ALL_NEED_VAUX_MASK \ |
| 2781 |
((TG3_GPIO_MSG_NEED_VAUX << 0) | \ |
| 2782 |
(TG3_GPIO_MSG_NEED_VAUX << 4) | \ |
| 2783 |
(TG3_GPIO_MSG_NEED_VAUX << 8) | \ |
| 2784 |
(TG3_GPIO_MSG_NEED_VAUX << 12)) |
| 2785 |
|
| 2786 |
static inline u32 tg3_set_function_status(struct tg3 *tp, u32 newstat) |
| 2787 |
{ |
| 2788 |
u32 status, shift; |
| 2789 |
|
| 2790 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 2791 |
tg3_asic_rev(tp) == ASIC_REV_5719) |
| 2792 |
status = tg3_ape_read32(tp, TG3_APE_GPIO_MSG); |
| 2793 |
else |
| 2794 |
status = tr32(TG3_CPMU_DRV_STATUS); |
| 2795 |
|
| 2796 |
shift = TG3_APE_GPIO_MSG_SHIFT + 4 * tp->pci_fn; |
| 2797 |
status &= ~(TG3_GPIO_MSG_MASK << shift); |
| 2798 |
status |= (newstat << shift); |
| 2799 |
|
| 2800 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 2801 |
tg3_asic_rev(tp) == ASIC_REV_5719) |
| 2802 |
tg3_ape_write32(tp, TG3_APE_GPIO_MSG, status); |
| 2803 |
else |
| 2804 |
tw32(TG3_CPMU_DRV_STATUS, status); |
| 2805 |
|
| 2806 |
return status >> TG3_APE_GPIO_MSG_SHIFT; |
| 2807 |
} |
| 2808 |
|
| 2809 |
static inline int tg3_pwrsrc_switch_to_vmain(struct tg3 *tp) |
| 2810 |
{ |
| 2811 |
if (!tg3_flag(tp, IS_NIC)) |
| 2812 |
return 0; |
| 2813 |
|
| 2814 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 2815 |
tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 2816 |
tg3_asic_rev(tp) == ASIC_REV_5720) { |
| 2817 |
if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2818 |
return -EIO; |
| 2819 |
|
| 2820 |
tg3_set_function_status(tp, TG3_GPIO_MSG_DRVR_PRES); |
| 2821 |
|
| 2822 |
tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2823 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2824 |
|
| 2825 |
tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
| 2826 |
} else { |
| 2827 |
tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, |
| 2828 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2829 |
} |
| 2830 |
|
| 2831 |
return 0; |
| 2832 |
} |
| 2833 |
|
| 2834 |
static void tg3_pwrsrc_die_with_vmain(struct tg3 *tp) |
| 2835 |
{ |
| 2836 |
u32 grc_local_ctrl; |
| 2837 |
|
| 2838 |
if (!tg3_flag(tp, IS_NIC) || |
| 2839 |
tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 2840 |
tg3_asic_rev(tp) == ASIC_REV_5701) |
| 2841 |
return; |
| 2842 |
|
| 2843 |
grc_local_ctrl = tp->grc_local_ctrl | GRC_LCLCTRL_GPIO_OE1; |
| 2844 |
|
| 2845 |
tw32_wait_f(GRC_LOCAL_CTRL, |
| 2846 |
grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2847 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2848 |
|
| 2849 |
tw32_wait_f(GRC_LOCAL_CTRL, |
| 2850 |
grc_local_ctrl, |
| 2851 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2852 |
|
| 2853 |
tw32_wait_f(GRC_LOCAL_CTRL, |
| 2854 |
grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, |
| 2855 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2856 |
} |
| 2857 |
|
| 2858 |
static void tg3_pwrsrc_switch_to_vaux(struct tg3 *tp) |
| 2859 |
{ |
| 2860 |
if (!tg3_flag(tp, IS_NIC)) |
| 2861 |
return; |
| 2862 |
|
| 2863 |
if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 2864 |
tg3_asic_rev(tp) == ASIC_REV_5701) { |
| 2865 |
tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2866 |
(GRC_LCLCTRL_GPIO_OE0 | |
| 2867 |
GRC_LCLCTRL_GPIO_OE1 | |
| 2868 |
GRC_LCLCTRL_GPIO_OE2 | |
| 2869 |
GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2870 |
GRC_LCLCTRL_GPIO_OUTPUT1), |
| 2871 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2872 |
} else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 2873 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
| 2874 |
/* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
| 2875 |
u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | |
| 2876 |
GRC_LCLCTRL_GPIO_OE1 | |
| 2877 |
GRC_LCLCTRL_GPIO_OE2 | |
| 2878 |
GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 2879 |
GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2880 |
tp->grc_local_ctrl; |
| 2881 |
tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2882 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2883 |
|
| 2884 |
grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2885 |
tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2886 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2887 |
|
| 2888 |
grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2889 |
tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, |
| 2890 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2891 |
} else { |
| 2892 |
u32 no_gpio2; |
| 2893 |
u32 grc_local_ctrl = 0; |
| 2894 |
|
| 2895 |
/* Workaround to prevent overdrawing Amps. */ |
| 2896 |
if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
| 2897 |
grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
| 2898 |
tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
| 2899 |
grc_local_ctrl, |
| 2900 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2901 |
} |
| 2902 |
|
| 2903 |
/* On 5753 and variants, GPIO2 cannot be used. */ |
| 2904 |
no_gpio2 = tp->nic_sram_data_cfg & |
| 2905 |
NIC_SRAM_DATA_CFG_NO_GPIO2; |
| 2906 |
|
| 2907 |
grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 2908 |
GRC_LCLCTRL_GPIO_OE1 | |
| 2909 |
GRC_LCLCTRL_GPIO_OE2 | |
| 2910 |
GRC_LCLCTRL_GPIO_OUTPUT1 | |
| 2911 |
GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2912 |
if (no_gpio2) { |
| 2913 |
grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | |
| 2914 |
GRC_LCLCTRL_GPIO_OUTPUT2); |
| 2915 |
} |
| 2916 |
tw32_wait_f(GRC_LOCAL_CTRL, |
| 2917 |
tp->grc_local_ctrl | grc_local_ctrl, |
| 2918 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2919 |
|
| 2920 |
grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; |
| 2921 |
|
| 2922 |
tw32_wait_f(GRC_LOCAL_CTRL, |
| 2923 |
tp->grc_local_ctrl | grc_local_ctrl, |
| 2924 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2925 |
|
| 2926 |
if (!no_gpio2) { |
| 2927 |
grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; |
| 2928 |
tw32_wait_f(GRC_LOCAL_CTRL, |
| 2929 |
tp->grc_local_ctrl | grc_local_ctrl, |
| 2930 |
TG3_GRC_LCLCTL_PWRSW_DELAY); |
| 2931 |
} |
| 2932 |
} |
| 2933 |
} |
| 2934 |
|
| 2935 |
static void tg3_frob_aux_power_5717(struct tg3 *tp, bool wol_enable) |
| 2936 |
{ |
| 2937 |
u32 msg = 0; |
| 2938 |
|
| 2939 |
/* Serialize power state transitions */ |
| 2940 |
if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
| 2941 |
return; |
| 2942 |
|
| 2943 |
if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE) || wol_enable) |
| 2944 |
msg = TG3_GPIO_MSG_NEED_VAUX; |
| 2945 |
|
| 2946 |
msg = tg3_set_function_status(tp, msg); |
| 2947 |
|
| 2948 |
if (msg & TG3_GPIO_MSG_ALL_DRVR_PRES_MASK) |
| 2949 |
goto done; |
| 2950 |
|
| 2951 |
if (msg & TG3_GPIO_MSG_ALL_NEED_VAUX_MASK) |
| 2952 |
tg3_pwrsrc_switch_to_vaux(tp); |
| 2953 |
else |
| 2954 |
tg3_pwrsrc_die_with_vmain(tp); |
| 2955 |
|
| 2956 |
done: |
| 2957 |
tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
| 2958 |
} |
| 2959 |
|
| 2960 |
static void tg3_frob_aux_power(struct tg3 *tp, bool include_wol) |
| 2961 |
{ |
| 2962 |
bool need_vaux = false; |
| 2963 |
|
| 2964 |
/* The GPIOs do something completely different on 57765. */ |
| 2965 |
if (!tg3_flag(tp, IS_NIC) || tg3_flag(tp, 57765_CLASS)) |
| 2966 |
return; |
| 2967 |
|
| 2968 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 2969 |
tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 2970 |
tg3_asic_rev(tp) == ASIC_REV_5720) { |
| 2971 |
tg3_frob_aux_power_5717(tp, include_wol ? |
| 2972 |
tg3_flag(tp, WOL_ENABLE) != 0 : 0); |
| 2973 |
return; |
| 2974 |
} |
| 2975 |
|
| 2976 |
if (tp->pdev_peer && tp->pdev_peer != tp->pdev) { |
| 2977 |
struct net_device *dev_peer; |
| 2978 |
|
| 2979 |
dev_peer = pci_get_drvdata(tp->pdev_peer); |
| 2980 |
|
| 2981 |
/* remove_one() may have been run on the peer. */ |
| 2982 |
if (dev_peer) { |
| 2983 |
struct tg3 *tp_peer = netdev_priv(dev_peer); |
| 2984 |
|
| 2985 |
if (tg3_flag(tp_peer, INIT_COMPLETE)) |
| 2986 |
return; |
| 2987 |
|
| 2988 |
if ((include_wol && tg3_flag(tp_peer, WOL_ENABLE)) || |
| 2989 |
tg3_flag(tp_peer, ENABLE_ASF)) |
| 2990 |
need_vaux = true; |
| 2991 |
} |
| 2992 |
} |
| 2993 |
|
| 2994 |
if ((include_wol && tg3_flag(tp, WOL_ENABLE)) || |
| 2995 |
tg3_flag(tp, ENABLE_ASF)) |
| 2996 |
need_vaux = true; |
| 2997 |
|
| 2998 |
if (need_vaux) |
| 2999 |
tg3_pwrsrc_switch_to_vaux(tp); |
| 3000 |
else |
| 3001 |
tg3_pwrsrc_die_with_vmain(tp); |
| 3002 |
} |
| 3003 |
|
| 3004 |
static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
| 3005 |
{ |
| 3006 |
if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) |
| 3007 |
return 1; |
| 3008 |
else if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411) { |
| 3009 |
if (speed != SPEED_10) |
| 3010 |
return 1; |
| 3011 |
} else if (speed == SPEED_10) |
| 3012 |
return 1; |
| 3013 |
|
| 3014 |
return 0; |
| 3015 |
} |
| 3016 |
|
| 3017 |
static bool tg3_phy_power_bug(struct tg3 *tp) |
| 3018 |
{ |
| 3019 |
switch (tg3_asic_rev(tp)) { |
| 3020 |
case ASIC_REV_5700: |
| 3021 |
case ASIC_REV_5704: |
| 3022 |
return true; |
| 3023 |
case ASIC_REV_5780: |
| 3024 |
if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
| 3025 |
return true; |
| 3026 |
return false; |
| 3027 |
case ASIC_REV_5717: |
| 3028 |
if (!tp->pci_fn) |
| 3029 |
return true; |
| 3030 |
return false; |
| 3031 |
case ASIC_REV_5719: |
| 3032 |
case ASIC_REV_5720: |
| 3033 |
if ((tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 3034 |
!tp->pci_fn) |
| 3035 |
return true; |
| 3036 |
return false; |
| 3037 |
} |
| 3038 |
|
| 3039 |
return false; |
| 3040 |
} |
| 3041 |
|
| 3042 |
static bool tg3_phy_led_bug(struct tg3 *tp) |
| 3043 |
{ |
| 3044 |
switch (tg3_asic_rev(tp)) { |
| 3045 |
case ASIC_REV_5719: |
| 3046 |
case ASIC_REV_5720: |
| 3047 |
if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
| 3048 |
!tp->pci_fn) |
| 3049 |
return true; |
| 3050 |
return false; |
| 3051 |
} |
| 3052 |
|
| 3053 |
return false; |
| 3054 |
} |
| 3055 |
|
| 3056 |
static void tg3_power_down_phy(struct tg3 *tp, bool do_low_power) |
| 3057 |
{ |
| 3058 |
u32 val; |
| 3059 |
|
| 3060 |
if (tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) |
| 3061 |
return; |
| 3062 |
|
| 3063 |
if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 3064 |
if (tg3_asic_rev(tp) == ASIC_REV_5704) { |
| 3065 |
u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 3066 |
u32 serdes_cfg = tr32(MAC_SERDES_CFG); |
| 3067 |
|
| 3068 |
sg_dig_ctrl |= |
| 3069 |
SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; |
| 3070 |
tw32(SG_DIG_CTRL, sg_dig_ctrl); |
| 3071 |
tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); |
| 3072 |
} |
| 3073 |
return; |
| 3074 |
} |
| 3075 |
|
| 3076 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 3077 |
tg3_bmcr_reset(tp); |
| 3078 |
val = tr32(GRC_MISC_CFG); |
| 3079 |
tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); |
| 3080 |
udelay(40); |
| 3081 |
return; |
| 3082 |
} else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 3083 |
u32 phytest; |
| 3084 |
if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { |
| 3085 |
u32 phy; |
| 3086 |
|
| 3087 |
tg3_writephy(tp, MII_ADVERTISE, 0); |
| 3088 |
tg3_writephy(tp, MII_BMCR, |
| 3089 |
BMCR_ANENABLE | BMCR_ANRESTART); |
| 3090 |
|
| 3091 |
tg3_writephy(tp, MII_TG3_FET_TEST, |
| 3092 |
phytest | MII_TG3_FET_SHADOW_EN); |
| 3093 |
if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { |
| 3094 |
phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; |
| 3095 |
tg3_writephy(tp, |
| 3096 |
MII_TG3_FET_SHDW_AUXMODE4, |
| 3097 |
phy); |
| 3098 |
} |
| 3099 |
tg3_writephy(tp, MII_TG3_FET_TEST, phytest); |
| 3100 |
} |
| 3101 |
return; |
| 3102 |
} else if (do_low_power) { |
| 3103 |
if (!tg3_phy_led_bug(tp)) |
| 3104 |
tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 3105 |
MII_TG3_EXT_CTRL_FORCE_LED_OFF); |
| 3106 |
|
| 3107 |
val = MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 3108 |
MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | |
| 3109 |
MII_TG3_AUXCTL_PCTL_VREG_11V; |
| 3110 |
tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, val); |
| 3111 |
} |
| 3112 |
|
| 3113 |
/* The PHY should not be powered down on some chips because |
| 3114 |
* of bugs. |
| 3115 |
*/ |
| 3116 |
if (tg3_phy_power_bug(tp)) |
| 3117 |
return; |
| 3118 |
|
| 3119 |
if (tg3_chip_rev(tp) == CHIPREV_5784_AX || |
| 3120 |
tg3_chip_rev(tp) == CHIPREV_5761_AX) { |
| 3121 |
val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
| 3122 |
val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; |
| 3123 |
val |= CPMU_LSPD_1000MB_MACCLK_12_5; |
| 3124 |
tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); |
| 3125 |
} |
| 3126 |
|
| 3127 |
tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 3128 |
} |
| 3129 |
|
| 3130 |
/* tp->lock is held. */ |
| 3131 |
static int tg3_nvram_lock(struct tg3 *tp) |
| 3132 |
{ |
| 3133 |
if (tg3_flag(tp, NVRAM)) { |
| 3134 |
int i; |
| 3135 |
|
| 3136 |
if (tp->nvram_lock_cnt == 0) { |
| 3137 |
tw32(NVRAM_SWARB, SWARB_REQ_SET1); |
| 3138 |
for (i = 0; i < 8000; i++) { |
| 3139 |
if (tr32(NVRAM_SWARB) & SWARB_GNT1) |
| 3140 |
break; |
| 3141 |
udelay(20); |
| 3142 |
} |
| 3143 |
if (i == 8000) { |
| 3144 |
tw32(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 3145 |
return -ENODEV; |
| 3146 |
} |
| 3147 |
} |
| 3148 |
tp->nvram_lock_cnt++; |
| 3149 |
} |
| 3150 |
return 0; |
| 3151 |
} |
| 3152 |
|
| 3153 |
/* tp->lock is held. */ |
| 3154 |
static void tg3_nvram_unlock(struct tg3 *tp) |
| 3155 |
{ |
| 3156 |
if (tg3_flag(tp, NVRAM)) { |
| 3157 |
if (tp->nvram_lock_cnt > 0) |
| 3158 |
tp->nvram_lock_cnt--; |
| 3159 |
if (tp->nvram_lock_cnt == 0) |
| 3160 |
tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); |
| 3161 |
} |
| 3162 |
} |
| 3163 |
|
| 3164 |
/* tp->lock is held. */ |
| 3165 |
static void tg3_enable_nvram_access(struct tg3 *tp) |
| 3166 |
{ |
| 3167 |
if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
| 3168 |
u32 nvaccess = tr32(NVRAM_ACCESS); |
| 3169 |
|
| 3170 |
tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); |
| 3171 |
} |
| 3172 |
} |
| 3173 |
|
| 3174 |
/* tp->lock is held. */ |
| 3175 |
static void tg3_disable_nvram_access(struct tg3 *tp) |
| 3176 |
{ |
| 3177 |
if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
| 3178 |
u32 nvaccess = tr32(NVRAM_ACCESS); |
| 3179 |
|
| 3180 |
tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); |
| 3181 |
} |
| 3182 |
} |
| 3183 |
|
| 3184 |
static int tg3_nvram_read_using_eeprom(struct tg3 *tp, |
| 3185 |
u32 offset, u32 *val) |
| 3186 |
{ |
| 3187 |
u32 tmp; |
| 3188 |
int i; |
| 3189 |
|
| 3190 |
if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) |
| 3191 |
return -EINVAL; |
| 3192 |
|
| 3193 |
tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | |
| 3194 |
EEPROM_ADDR_DEVID_MASK | |
| 3195 |
EEPROM_ADDR_READ); |
| 3196 |
tw32(GRC_EEPROM_ADDR, |
| 3197 |
tmp | |
| 3198 |
(0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 3199 |
((offset << EEPROM_ADDR_ADDR_SHIFT) & |
| 3200 |
EEPROM_ADDR_ADDR_MASK) | |
| 3201 |
EEPROM_ADDR_READ | EEPROM_ADDR_START); |
| 3202 |
|
| 3203 |
for (i = 0; i < 1000; i++) { |
| 3204 |
tmp = tr32(GRC_EEPROM_ADDR); |
| 3205 |
|
| 3206 |
if (tmp & EEPROM_ADDR_COMPLETE) |
| 3207 |
break; |
| 3208 |
msleep(1); |
| 3209 |
} |
| 3210 |
if (!(tmp & EEPROM_ADDR_COMPLETE)) |
| 3211 |
return -EBUSY; |
| 3212 |
|
| 3213 |
tmp = tr32(GRC_EEPROM_DATA); |
| 3214 |
|
| 3215 |
/* |
| 3216 |
* The data will always be opposite the native endian |
| 3217 |
* format. Perform a blind byteswap to compensate. |
| 3218 |
*/ |
| 3219 |
*val = swab32(tmp); |
| 3220 |
|
| 3221 |
return 0; |
| 3222 |
} |
| 3223 |
|
| 3224 |
#define NVRAM_CMD_TIMEOUT 10000 |
| 3225 |
|
| 3226 |
static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) |
| 3227 |
{ |
| 3228 |
int i; |
| 3229 |
|
| 3230 |
tw32(NVRAM_CMD, nvram_cmd); |
| 3231 |
for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { |
| 3232 |
usleep_range(10, 40); |
| 3233 |
if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { |
| 3234 |
udelay(10); |
| 3235 |
break; |
| 3236 |
} |
| 3237 |
} |
| 3238 |
|
| 3239 |
if (i == NVRAM_CMD_TIMEOUT) |
| 3240 |
return -EBUSY; |
| 3241 |
|
| 3242 |
return 0; |
| 3243 |
} |
| 3244 |
|
| 3245 |
static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) |
| 3246 |
{ |
| 3247 |
if (tg3_flag(tp, NVRAM) && |
| 3248 |
tg3_flag(tp, NVRAM_BUFFERED) && |
| 3249 |
tg3_flag(tp, FLASH) && |
| 3250 |
!tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
| 3251 |
(tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 3252 |
|
| 3253 |
addr = ((addr / tp->nvram_pagesize) << |
| 3254 |
ATMEL_AT45DB0X1B_PAGE_POS) + |
| 3255 |
(addr % tp->nvram_pagesize); |
| 3256 |
|
| 3257 |
return addr; |
| 3258 |
} |
| 3259 |
|
| 3260 |
static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) |
| 3261 |
{ |
| 3262 |
if (tg3_flag(tp, NVRAM) && |
| 3263 |
tg3_flag(tp, NVRAM_BUFFERED) && |
| 3264 |
tg3_flag(tp, FLASH) && |
| 3265 |
!tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && |
| 3266 |
(tp->nvram_jedecnum == JEDEC_ATMEL)) |
| 3267 |
|
| 3268 |
addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * |
| 3269 |
tp->nvram_pagesize) + |
| 3270 |
(addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); |
| 3271 |
|
| 3272 |
return addr; |
| 3273 |
} |
| 3274 |
|
| 3275 |
/* NOTE: Data read in from NVRAM is byteswapped according to |
| 3276 |
* the byteswapping settings for all other register accesses. |
| 3277 |
* tg3 devices are BE devices, so on a BE machine, the data |
| 3278 |
* returned will be exactly as it is seen in NVRAM. On a LE |
| 3279 |
* machine, the 32-bit value will be byteswapped. |
| 3280 |
*/ |
| 3281 |
static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
| 3282 |
{ |
| 3283 |
int ret; |
| 3284 |
|
| 3285 |
if (!tg3_flag(tp, NVRAM)) |
| 3286 |
return tg3_nvram_read_using_eeprom(tp, offset, val); |
| 3287 |
|
| 3288 |
offset = tg3_nvram_phys_addr(tp, offset); |
| 3289 |
|
| 3290 |
if (offset > NVRAM_ADDR_MSK) |
| 3291 |
return -EINVAL; |
| 3292 |
|
| 3293 |
ret = tg3_nvram_lock(tp); |
| 3294 |
if (ret) |
| 3295 |
return ret; |
| 3296 |
|
| 3297 |
tg3_enable_nvram_access(tp); |
| 3298 |
|
| 3299 |
tw32(NVRAM_ADDR, offset); |
| 3300 |
ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | |
| 3301 |
NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); |
| 3302 |
|
| 3303 |
if (ret == 0) |
| 3304 |
*val = tr32(NVRAM_RDDATA); |
| 3305 |
|
| 3306 |
tg3_disable_nvram_access(tp); |
| 3307 |
|
| 3308 |
tg3_nvram_unlock(tp); |
| 3309 |
|
| 3310 |
return ret; |
| 3311 |
} |
| 3312 |
|
| 3313 |
/* Ensures NVRAM data is in bytestream format. */ |
| 3314 |
static int tg3_nvram_read_be32(struct tg3 *tp, u32 offset, __be32 *val) |
| 3315 |
{ |
| 3316 |
u32 v; |
| 3317 |
int res = tg3_nvram_read(tp, offset, &v); |
| 3318 |
if (!res) |
| 3319 |
*val = cpu_to_be32(v); |
| 3320 |
return res; |
| 3321 |
} |
| 3322 |
|
| 3323 |
static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
| 3324 |
u32 offset, u32 len, u8 *buf) |
| 3325 |
{ |
| 3326 |
int i, j, rc = 0; |
| 3327 |
u32 val; |
| 3328 |
|
| 3329 |
for (i = 0; i < len; i += 4) { |
| 3330 |
u32 addr; |
| 3331 |
__be32 data; |
| 3332 |
|
| 3333 |
addr = offset + i; |
| 3334 |
|
| 3335 |
memcpy(&data, buf + i, 4); |
| 3336 |
|
| 3337 |
/* |
| 3338 |
* The SEEPROM interface expects the data to always be opposite |
| 3339 |
* the native endian format. We accomplish this by reversing |
| 3340 |
* all the operations that would have been performed on the |
| 3341 |
* data from a call to tg3_nvram_read_be32(). |
| 3342 |
*/ |
| 3343 |
tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); |
| 3344 |
|
| 3345 |
val = tr32(GRC_EEPROM_ADDR); |
| 3346 |
tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); |
| 3347 |
|
| 3348 |
val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | |
| 3349 |
EEPROM_ADDR_READ); |
| 3350 |
tw32(GRC_EEPROM_ADDR, val | |
| 3351 |
(0 << EEPROM_ADDR_DEVID_SHIFT) | |
| 3352 |
(addr & EEPROM_ADDR_ADDR_MASK) | |
| 3353 |
EEPROM_ADDR_START | |
| 3354 |
EEPROM_ADDR_WRITE); |
| 3355 |
|
| 3356 |
for (j = 0; j < 1000; j++) { |
| 3357 |
val = tr32(GRC_EEPROM_ADDR); |
| 3358 |
|
| 3359 |
if (val & EEPROM_ADDR_COMPLETE) |
| 3360 |
break; |
| 3361 |
msleep(1); |
| 3362 |
} |
| 3363 |
if (!(val & EEPROM_ADDR_COMPLETE)) { |
| 3364 |
rc = -EBUSY; |
| 3365 |
break; |
| 3366 |
} |
| 3367 |
} |
| 3368 |
|
| 3369 |
return rc; |
| 3370 |
} |
| 3371 |
|
| 3372 |
/* offset and length are dword aligned */ |
| 3373 |
static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, |
| 3374 |
u8 *buf) |
| 3375 |
{ |
| 3376 |
int ret = 0; |
| 3377 |
u32 pagesize = tp->nvram_pagesize; |
| 3378 |
u32 pagemask = pagesize - 1; |
| 3379 |
u32 nvram_cmd; |
| 3380 |
u8 *tmp; |
| 3381 |
|
| 3382 |
tmp = kmalloc(pagesize, GFP_KERNEL); |
| 3383 |
if (tmp == NULL) |
| 3384 |
return -ENOMEM; |
| 3385 |
|
| 3386 |
while (len) { |
| 3387 |
int j; |
| 3388 |
u32 phy_addr, page_off, size; |
| 3389 |
|
| 3390 |
phy_addr = offset & ~pagemask; |
| 3391 |
|
| 3392 |
for (j = 0; j < pagesize; j += 4) { |
| 3393 |
ret = tg3_nvram_read_be32(tp, phy_addr + j, |
| 3394 |
(__be32 *) (tmp + j)); |
| 3395 |
if (ret) |
| 3396 |
break; |
| 3397 |
} |
| 3398 |
if (ret) |
| 3399 |
break; |
| 3400 |
|
| 3401 |
page_off = offset & pagemask; |
| 3402 |
size = pagesize; |
| 3403 |
if (len < size) |
| 3404 |
size = len; |
| 3405 |
|
| 3406 |
len -= size; |
| 3407 |
|
| 3408 |
memcpy(tmp + page_off, buf, size); |
| 3409 |
|
| 3410 |
offset = offset + (pagesize - page_off); |
| 3411 |
|
| 3412 |
tg3_enable_nvram_access(tp); |
| 3413 |
|
| 3414 |
/* |
| 3415 |
* Before we can erase the flash page, we need |
| 3416 |
* to issue a special "write enable" command. |
| 3417 |
*/ |
| 3418 |
nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3419 |
|
| 3420 |
if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3421 |
break; |
| 3422 |
|
| 3423 |
/* Erase the target page */ |
| 3424 |
tw32(NVRAM_ADDR, phy_addr); |
| 3425 |
|
| 3426 |
nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | |
| 3427 |
NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; |
| 3428 |
|
| 3429 |
if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3430 |
break; |
| 3431 |
|
| 3432 |
/* Issue another write enable to start the write. */ |
| 3433 |
nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3434 |
|
| 3435 |
if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
| 3436 |
break; |
| 3437 |
|
| 3438 |
for (j = 0; j < pagesize; j += 4) { |
| 3439 |
__be32 data; |
| 3440 |
|
| 3441 |
data = *((__be32 *) (tmp + j)); |
| 3442 |
|
| 3443 |
tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3444 |
|
| 3445 |
tw32(NVRAM_ADDR, phy_addr + j); |
| 3446 |
|
| 3447 |
nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | |
| 3448 |
NVRAM_CMD_WR; |
| 3449 |
|
| 3450 |
if (j == 0) |
| 3451 |
nvram_cmd |= NVRAM_CMD_FIRST; |
| 3452 |
else if (j == (pagesize - 4)) |
| 3453 |
nvram_cmd |= NVRAM_CMD_LAST; |
| 3454 |
|
| 3455 |
ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3456 |
if (ret) |
| 3457 |
break; |
| 3458 |
} |
| 3459 |
if (ret) |
| 3460 |
break; |
| 3461 |
} |
| 3462 |
|
| 3463 |
nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3464 |
tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3465 |
|
| 3466 |
kfree(tmp); |
| 3467 |
|
| 3468 |
return ret; |
| 3469 |
} |
| 3470 |
|
| 3471 |
/* offset and length are dword aligned */ |
| 3472 |
static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, |
| 3473 |
u8 *buf) |
| 3474 |
{ |
| 3475 |
int i, ret = 0; |
| 3476 |
|
| 3477 |
for (i = 0; i < len; i += 4, offset += 4) { |
| 3478 |
u32 page_off, phy_addr, nvram_cmd; |
| 3479 |
__be32 data; |
| 3480 |
|
| 3481 |
memcpy(&data, buf + i, 4); |
| 3482 |
tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
| 3483 |
|
| 3484 |
page_off = offset % tp->nvram_pagesize; |
| 3485 |
|
| 3486 |
phy_addr = tg3_nvram_phys_addr(tp, offset); |
| 3487 |
|
| 3488 |
nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
| 3489 |
|
| 3490 |
if (page_off == 0 || i == 0) |
| 3491 |
nvram_cmd |= NVRAM_CMD_FIRST; |
| 3492 |
if (page_off == (tp->nvram_pagesize - 4)) |
| 3493 |
nvram_cmd |= NVRAM_CMD_LAST; |
| 3494 |
|
| 3495 |
if (i == (len - 4)) |
| 3496 |
nvram_cmd |= NVRAM_CMD_LAST; |
| 3497 |
|
| 3498 |
if ((nvram_cmd & NVRAM_CMD_FIRST) || |
| 3499 |
!tg3_flag(tp, FLASH) || |
| 3500 |
!tg3_flag(tp, 57765_PLUS)) |
| 3501 |
tw32(NVRAM_ADDR, phy_addr); |
| 3502 |
|
| 3503 |
if (tg3_asic_rev(tp) != ASIC_REV_5752 && |
| 3504 |
!tg3_flag(tp, 5755_PLUS) && |
| 3505 |
(tp->nvram_jedecnum == JEDEC_ST) && |
| 3506 |
(nvram_cmd & NVRAM_CMD_FIRST)) { |
| 3507 |
u32 cmd; |
| 3508 |
|
| 3509 |
cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; |
| 3510 |
ret = tg3_nvram_exec_cmd(tp, cmd); |
| 3511 |
if (ret) |
| 3512 |
break; |
| 3513 |
} |
| 3514 |
if (!tg3_flag(tp, FLASH)) { |
| 3515 |
/* We always do complete word writes to eeprom. */ |
| 3516 |
nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); |
| 3517 |
} |
| 3518 |
|
| 3519 |
ret = tg3_nvram_exec_cmd(tp, nvram_cmd); |
| 3520 |
if (ret) |
| 3521 |
break; |
| 3522 |
} |
| 3523 |
return ret; |
| 3524 |
} |
| 3525 |
|
| 3526 |
/* offset and length are dword aligned */ |
| 3527 |
static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) |
| 3528 |
{ |
| 3529 |
int ret; |
| 3530 |
|
| 3531 |
if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3532 |
tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
| 3533 |
~GRC_LCLCTRL_GPIO_OUTPUT1); |
| 3534 |
udelay(40); |
| 3535 |
} |
| 3536 |
|
| 3537 |
if (!tg3_flag(tp, NVRAM)) { |
| 3538 |
ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
| 3539 |
} else { |
| 3540 |
u32 grc_mode; |
| 3541 |
|
| 3542 |
ret = tg3_nvram_lock(tp); |
| 3543 |
if (ret) |
| 3544 |
return ret; |
| 3545 |
|
| 3546 |
tg3_enable_nvram_access(tp); |
| 3547 |
if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) |
| 3548 |
tw32(NVRAM_WRITE1, 0x406); |
| 3549 |
|
| 3550 |
grc_mode = tr32(GRC_MODE); |
| 3551 |
tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); |
| 3552 |
|
| 3553 |
if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) { |
| 3554 |
ret = tg3_nvram_write_block_buffered(tp, offset, len, |
| 3555 |
buf); |
| 3556 |
} else { |
| 3557 |
ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
| 3558 |
buf); |
| 3559 |
} |
| 3560 |
|
| 3561 |
grc_mode = tr32(GRC_MODE); |
| 3562 |
tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); |
| 3563 |
|
| 3564 |
tg3_disable_nvram_access(tp); |
| 3565 |
tg3_nvram_unlock(tp); |
| 3566 |
} |
| 3567 |
|
| 3568 |
if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
| 3569 |
tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 3570 |
udelay(40); |
| 3571 |
} |
| 3572 |
|
| 3573 |
return ret; |
| 3574 |
} |
| 3575 |
|
| 3576 |
#define RX_CPU_SCRATCH_BASE 0x30000 |
| 3577 |
#define RX_CPU_SCRATCH_SIZE 0x04000 |
| 3578 |
#define TX_CPU_SCRATCH_BASE 0x34000 |
| 3579 |
#define TX_CPU_SCRATCH_SIZE 0x04000 |
| 3580 |
|
| 3581 |
/* tp->lock is held. */ |
| 3582 |
static int tg3_pause_cpu(struct tg3 *tp, u32 cpu_base) |
| 3583 |
{ |
| 3584 |
int i; |
| 3585 |
const int iters = 10000; |
| 3586 |
|
| 3587 |
for (i = 0; i < iters; i++) { |
| 3588 |
tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3589 |
tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
| 3590 |
if (tr32(cpu_base + CPU_MODE) & CPU_MODE_HALT) |
| 3591 |
break; |
| 3592 |
if (pci_channel_offline(tp->pdev)) |
| 3593 |
return -EBUSY; |
| 3594 |
} |
| 3595 |
|
| 3596 |
return (i == iters) ? -EBUSY : 0; |
| 3597 |
} |
| 3598 |
|
| 3599 |
/* tp->lock is held. */ |
| 3600 |
static int tg3_rxcpu_pause(struct tg3 *tp) |
| 3601 |
{ |
| 3602 |
int rc = tg3_pause_cpu(tp, RX_CPU_BASE); |
| 3603 |
|
| 3604 |
tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); |
| 3605 |
tw32_f(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); |
| 3606 |
udelay(10); |
| 3607 |
|
| 3608 |
return rc; |
| 3609 |
} |
| 3610 |
|
| 3611 |
/* tp->lock is held. */ |
| 3612 |
static int tg3_txcpu_pause(struct tg3 *tp) |
| 3613 |
{ |
| 3614 |
return tg3_pause_cpu(tp, TX_CPU_BASE); |
| 3615 |
} |
| 3616 |
|
| 3617 |
/* tp->lock is held. */ |
| 3618 |
static void tg3_resume_cpu(struct tg3 *tp, u32 cpu_base) |
| 3619 |
{ |
| 3620 |
tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3621 |
tw32_f(cpu_base + CPU_MODE, 0x00000000); |
| 3622 |
} |
| 3623 |
|
| 3624 |
/* tp->lock is held. */ |
| 3625 |
static void tg3_rxcpu_resume(struct tg3 *tp) |
| 3626 |
{ |
| 3627 |
tg3_resume_cpu(tp, RX_CPU_BASE); |
| 3628 |
} |
| 3629 |
|
| 3630 |
/* tp->lock is held. */ |
| 3631 |
static int tg3_halt_cpu(struct tg3 *tp, u32 cpu_base) |
| 3632 |
{ |
| 3633 |
int rc; |
| 3634 |
|
| 3635 |
BUG_ON(cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)); |
| 3636 |
|
| 3637 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 3638 |
u32 val = tr32(GRC_VCPU_EXT_CTRL); |
| 3639 |
|
| 3640 |
tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 3641 |
return 0; |
| 3642 |
} |
| 3643 |
if (cpu_base == RX_CPU_BASE) { |
| 3644 |
rc = tg3_rxcpu_pause(tp); |
| 3645 |
} else { |
| 3646 |
/* |
| 3647 |
* There is only an Rx CPU for the 5750 derivative in the |
| 3648 |
* BCM4785. |
| 3649 |
*/ |
| 3650 |
if (tg3_flag(tp, IS_SSB_CORE)) |
| 3651 |
return 0; |
| 3652 |
|
| 3653 |
rc = tg3_txcpu_pause(tp); |
| 3654 |
} |
| 3655 |
|
| 3656 |
if (rc) { |
| 3657 |
netdev_err(tp->dev, "%s timed out, %s CPU\n", |
| 3658 |
__func__, cpu_base == RX_CPU_BASE ? "RX" : "TX"); |
| 3659 |
return -ENODEV; |
| 3660 |
} |
| 3661 |
|
| 3662 |
/* Clear firmware's nvram arbitration. */ |
| 3663 |
if (tg3_flag(tp, NVRAM)) |
| 3664 |
tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
| 3665 |
return 0; |
| 3666 |
} |
| 3667 |
|
| 3668 |
static int tg3_fw_data_len(struct tg3 *tp, |
| 3669 |
const struct tg3_firmware_hdr *fw_hdr) |
| 3670 |
{ |
| 3671 |
int fw_len; |
| 3672 |
|
| 3673 |
/* Non fragmented firmware have one firmware header followed by a |
| 3674 |
* contiguous chunk of data to be written. The length field in that |
| 3675 |
* header is not the length of data to be written but the complete |
| 3676 |
* length of the bss. The data length is determined based on |
| 3677 |
* tp->fw->size minus headers. |
| 3678 |
* |
| 3679 |
* Fragmented firmware have a main header followed by multiple |
| 3680 |
* fragments. Each fragment is identical to non fragmented firmware |
| 3681 |
* with a firmware header followed by a contiguous chunk of data. In |
| 3682 |
* the main header, the length field is unused and set to 0xffffffff. |
| 3683 |
* In each fragment header the length is the entire size of that |
| 3684 |
* fragment i.e. fragment data + header length. Data length is |
| 3685 |
* therefore length field in the header minus TG3_FW_HDR_LEN. |
| 3686 |
*/ |
| 3687 |
if (tp->fw_len == 0xffffffff) |
| 3688 |
fw_len = be32_to_cpu(fw_hdr->len); |
| 3689 |
else |
| 3690 |
fw_len = tp->fw->size; |
| 3691 |
|
| 3692 |
return (fw_len - TG3_FW_HDR_LEN) / sizeof(u32); |
| 3693 |
} |
| 3694 |
|
| 3695 |
/* tp->lock is held. */ |
| 3696 |
static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, |
| 3697 |
u32 cpu_scratch_base, int cpu_scratch_size, |
| 3698 |
const struct tg3_firmware_hdr *fw_hdr) |
| 3699 |
{ |
| 3700 |
int err, i; |
| 3701 |
void (*write_op)(struct tg3 *, u32, u32); |
| 3702 |
int total_len = tp->fw->size; |
| 3703 |
|
| 3704 |
if (cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)) { |
| 3705 |
netdev_err(tp->dev, |
| 3706 |
"%s: Trying to load TX cpu firmware which is 5705\n", |
| 3707 |
__func__); |
| 3708 |
return -EINVAL; |
| 3709 |
} |
| 3710 |
|
| 3711 |
if (tg3_flag(tp, 5705_PLUS) && tg3_asic_rev(tp) != ASIC_REV_57766) |
| 3712 |
write_op = tg3_write_mem; |
| 3713 |
else |
| 3714 |
write_op = tg3_write_indirect_reg32; |
| 3715 |
|
| 3716 |
if (tg3_asic_rev(tp) != ASIC_REV_57766) { |
| 3717 |
/* It is possible that bootcode is still loading at this point. |
| 3718 |
* Get the nvram lock first before halting the cpu. |
| 3719 |
*/ |
| 3720 |
int lock_err = tg3_nvram_lock(tp); |
| 3721 |
err = tg3_halt_cpu(tp, cpu_base); |
| 3722 |
if (!lock_err) |
| 3723 |
tg3_nvram_unlock(tp); |
| 3724 |
if (err) |
| 3725 |
goto out; |
| 3726 |
|
| 3727 |
for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
| 3728 |
write_op(tp, cpu_scratch_base + i, 0); |
| 3729 |
tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3730 |
tw32(cpu_base + CPU_MODE, |
| 3731 |
tr32(cpu_base + CPU_MODE) | CPU_MODE_HALT); |
| 3732 |
} else { |
| 3733 |
/* Subtract additional main header for fragmented firmware and |
| 3734 |
* advance to the first fragment |
| 3735 |
*/ |
| 3736 |
total_len -= TG3_FW_HDR_LEN; |
| 3737 |
fw_hdr++; |
| 3738 |
} |
| 3739 |
|
| 3740 |
do { |
| 3741 |
__be32 *fw_data = (__be32 *)(fw_hdr + 1); |
| 3742 |
for (i = 0; i < tg3_fw_data_len(tp, fw_hdr); i++) |
| 3743 |
write_op(tp, cpu_scratch_base + |
| 3744 |
(be32_to_cpu(fw_hdr->base_addr) & 0xffff) + |
| 3745 |
(i * sizeof(u32)), |
| 3746 |
be32_to_cpu(fw_data[i])); |
| 3747 |
|
| 3748 |
total_len -= be32_to_cpu(fw_hdr->len); |
| 3749 |
|
| 3750 |
/* Advance to next fragment */ |
| 3751 |
fw_hdr = (struct tg3_firmware_hdr *) |
| 3752 |
((void *)fw_hdr + be32_to_cpu(fw_hdr->len)); |
| 3753 |
} while (total_len > 0); |
| 3754 |
|
| 3755 |
err = 0; |
| 3756 |
|
| 3757 |
out: |
| 3758 |
return err; |
| 3759 |
} |
| 3760 |
|
| 3761 |
/* tp->lock is held. */ |
| 3762 |
static int tg3_pause_cpu_and_set_pc(struct tg3 *tp, u32 cpu_base, u32 pc) |
| 3763 |
{ |
| 3764 |
int i; |
| 3765 |
const int iters = 5; |
| 3766 |
|
| 3767 |
tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3768 |
tw32_f(cpu_base + CPU_PC, pc); |
| 3769 |
|
| 3770 |
for (i = 0; i < iters; i++) { |
| 3771 |
if (tr32(cpu_base + CPU_PC) == pc) |
| 3772 |
break; |
| 3773 |
tw32(cpu_base + CPU_STATE, 0xffffffff); |
| 3774 |
tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); |
| 3775 |
tw32_f(cpu_base + CPU_PC, pc); |
| 3776 |
udelay(1000); |
| 3777 |
} |
| 3778 |
|
| 3779 |
return (i == iters) ? -EBUSY : 0; |
| 3780 |
} |
| 3781 |
|
| 3782 |
/* tp->lock is held. */ |
| 3783 |
static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) |
| 3784 |
{ |
| 3785 |
const struct tg3_firmware_hdr *fw_hdr; |
| 3786 |
int err; |
| 3787 |
|
| 3788 |
fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
| 3789 |
|
| 3790 |
/* Firmware blob starts with version numbers, followed by |
| 3791 |
start address and length. We are setting complete length. |
| 3792 |
length = end_address_of_bss - start_address_of_text. |
| 3793 |
Remainder is the blob to be loaded contiguously |
| 3794 |
from start address. */ |
| 3795 |
|
| 3796 |
err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
| 3797 |
RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, |
| 3798 |
fw_hdr); |
| 3799 |
if (err) |
| 3800 |
return err; |
| 3801 |
|
| 3802 |
err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, |
| 3803 |
TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, |
| 3804 |
fw_hdr); |
| 3805 |
if (err) |
| 3806 |
return err; |
| 3807 |
|
| 3808 |
/* Now startup only the RX cpu. */ |
| 3809 |
err = tg3_pause_cpu_and_set_pc(tp, RX_CPU_BASE, |
| 3810 |
be32_to_cpu(fw_hdr->base_addr)); |
| 3811 |
if (err) { |
| 3812 |
netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
| 3813 |
"should be %08x\n", __func__, |
| 3814 |
tr32(RX_CPU_BASE + CPU_PC), |
| 3815 |
be32_to_cpu(fw_hdr->base_addr)); |
| 3816 |
return -ENODEV; |
| 3817 |
} |
| 3818 |
|
| 3819 |
tg3_rxcpu_resume(tp); |
| 3820 |
|
| 3821 |
return 0; |
| 3822 |
} |
| 3823 |
|
| 3824 |
static int tg3_validate_rxcpu_state(struct tg3 *tp) |
| 3825 |
{ |
| 3826 |
const int iters = 1000; |
| 3827 |
int i; |
| 3828 |
u32 val; |
| 3829 |
|
| 3830 |
/* Wait for boot code to complete initialization and enter service |
| 3831 |
* loop. It is then safe to download service patches |
| 3832 |
*/ |
| 3833 |
for (i = 0; i < iters; i++) { |
| 3834 |
if (tr32(RX_CPU_HWBKPT) == TG3_SBROM_IN_SERVICE_LOOP) |
| 3835 |
break; |
| 3836 |
|
| 3837 |
udelay(10); |
| 3838 |
} |
| 3839 |
|
| 3840 |
if (i == iters) { |
| 3841 |
netdev_err(tp->dev, "Boot code not ready for service patches\n"); |
| 3842 |
return -EBUSY; |
| 3843 |
} |
| 3844 |
|
| 3845 |
val = tg3_read_indirect_reg32(tp, TG3_57766_FW_HANDSHAKE); |
| 3846 |
if (val & 0xff) { |
| 3847 |
netdev_warn(tp->dev, |
| 3848 |
"Other patches exist. Not downloading EEE patch\n"); |
| 3849 |
return -EEXIST; |
| 3850 |
} |
| 3851 |
|
| 3852 |
return 0; |
| 3853 |
} |
| 3854 |
|
| 3855 |
/* tp->lock is held. */ |
| 3856 |
static void tg3_load_57766_firmware(struct tg3 *tp) |
| 3857 |
{ |
| 3858 |
struct tg3_firmware_hdr *fw_hdr; |
| 3859 |
|
| 3860 |
if (!tg3_flag(tp, NO_NVRAM)) |
| 3861 |
return; |
| 3862 |
|
| 3863 |
if (tg3_validate_rxcpu_state(tp)) |
| 3864 |
return; |
| 3865 |
|
| 3866 |
if (!tp->fw) |
| 3867 |
return; |
| 3868 |
|
| 3869 |
/* This firmware blob has a different format than older firmware |
| 3870 |
* releases as given below. The main difference is we have fragmented |
| 3871 |
* data to be written to non-contiguous locations. |
| 3872 |
* |
| 3873 |
* In the beginning we have a firmware header identical to other |
| 3874 |
* firmware which consists of version, base addr and length. The length |
| 3875 |
* here is unused and set to 0xffffffff. |
| 3876 |
* |
| 3877 |
* This is followed by a series of firmware fragments which are |
| 3878 |
* individually identical to previous firmware. i.e. they have the |
| 3879 |
* firmware header and followed by data for that fragment. The version |
| 3880 |
* field of the individual fragment header is unused. |
| 3881 |
*/ |
| 3882 |
|
| 3883 |
fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
| 3884 |
if (be32_to_cpu(fw_hdr->base_addr) != TG3_57766_FW_BASE_ADDR) |
| 3885 |
return; |
| 3886 |
|
| 3887 |
if (tg3_rxcpu_pause(tp)) |
| 3888 |
return; |
| 3889 |
|
| 3890 |
/* tg3_load_firmware_cpu() will always succeed for the 57766 */ |
| 3891 |
tg3_load_firmware_cpu(tp, 0, TG3_57766_FW_BASE_ADDR, 0, fw_hdr); |
| 3892 |
|
| 3893 |
tg3_rxcpu_resume(tp); |
| 3894 |
} |
| 3895 |
|
| 3896 |
/* tp->lock is held. */ |
| 3897 |
static int tg3_load_tso_firmware(struct tg3 *tp) |
| 3898 |
{ |
| 3899 |
const struct tg3_firmware_hdr *fw_hdr; |
| 3900 |
unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
| 3901 |
int err; |
| 3902 |
|
| 3903 |
if (!tg3_flag(tp, FW_TSO)) |
| 3904 |
return 0; |
| 3905 |
|
| 3906 |
fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
| 3907 |
|
| 3908 |
/* Firmware blob starts with version numbers, followed by |
| 3909 |
start address and length. We are setting complete length. |
| 3910 |
length = end_address_of_bss - start_address_of_text. |
| 3911 |
Remainder is the blob to be loaded contiguously |
| 3912 |
from start address. */ |
| 3913 |
|
| 3914 |
cpu_scratch_size = tp->fw_len; |
| 3915 |
|
| 3916 |
if (tg3_asic_rev(tp) == ASIC_REV_5705) { |
| 3917 |
cpu_base = RX_CPU_BASE; |
| 3918 |
cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; |
| 3919 |
} else { |
| 3920 |
cpu_base = TX_CPU_BASE; |
| 3921 |
cpu_scratch_base = TX_CPU_SCRATCH_BASE; |
| 3922 |
cpu_scratch_size = TX_CPU_SCRATCH_SIZE; |
| 3923 |
} |
| 3924 |
|
| 3925 |
err = tg3_load_firmware_cpu(tp, cpu_base, |
| 3926 |
cpu_scratch_base, cpu_scratch_size, |
| 3927 |
fw_hdr); |
| 3928 |
if (err) |
| 3929 |
return err; |
| 3930 |
|
| 3931 |
/* Now startup the cpu. */ |
| 3932 |
err = tg3_pause_cpu_and_set_pc(tp, cpu_base, |
| 3933 |
be32_to_cpu(fw_hdr->base_addr)); |
| 3934 |
if (err) { |
| 3935 |
netdev_err(tp->dev, |
| 3936 |
"%s fails to set CPU PC, is %08x should be %08x\n", |
| 3937 |
__func__, tr32(cpu_base + CPU_PC), |
| 3938 |
be32_to_cpu(fw_hdr->base_addr)); |
| 3939 |
return -ENODEV; |
| 3940 |
} |
| 3941 |
|
| 3942 |
tg3_resume_cpu(tp, cpu_base); |
| 3943 |
return 0; |
| 3944 |
} |
| 3945 |
|
| 3946 |
/* tp->lock is held. */ |
| 3947 |
static void __tg3_set_one_mac_addr(struct tg3 *tp, const u8 *mac_addr, |
| 3948 |
int index) |
| 3949 |
{ |
| 3950 |
u32 addr_high, addr_low; |
| 3951 |
|
| 3952 |
addr_high = ((mac_addr[0] << 8) | mac_addr[1]); |
| 3953 |
addr_low = ((mac_addr[2] << 24) | (mac_addr[3] << 16) | |
| 3954 |
(mac_addr[4] << 8) | mac_addr[5]); |
| 3955 |
|
| 3956 |
if (index < 4) { |
| 3957 |
tw32(MAC_ADDR_0_HIGH + (index * 8), addr_high); |
| 3958 |
tw32(MAC_ADDR_0_LOW + (index * 8), addr_low); |
| 3959 |
} else { |
| 3960 |
index -= 4; |
| 3961 |
tw32(MAC_EXTADDR_0_HIGH + (index * 8), addr_high); |
| 3962 |
tw32(MAC_EXTADDR_0_LOW + (index * 8), addr_low); |
| 3963 |
} |
| 3964 |
} |
| 3965 |
|
| 3966 |
/* tp->lock is held. */ |
| 3967 |
static void __tg3_set_mac_addr(struct tg3 *tp, bool skip_mac_1) |
| 3968 |
{ |
| 3969 |
u32 addr_high; |
| 3970 |
int i; |
| 3971 |
|
| 3972 |
for (i = 0; i < 4; i++) { |
| 3973 |
if (i == 1 && skip_mac_1) |
| 3974 |
continue; |
| 3975 |
__tg3_set_one_mac_addr(tp, tp->dev->dev_addr, i); |
| 3976 |
} |
| 3977 |
|
| 3978 |
if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
| 3979 |
tg3_asic_rev(tp) == ASIC_REV_5704) { |
| 3980 |
for (i = 4; i < 16; i++) |
| 3981 |
__tg3_set_one_mac_addr(tp, tp->dev->dev_addr, i); |
| 3982 |
} |
| 3983 |
|
| 3984 |
addr_high = (tp->dev->dev_addr[0] + |
| 3985 |
tp->dev->dev_addr[1] + |
| 3986 |
tp->dev->dev_addr[2] + |
| 3987 |
tp->dev->dev_addr[3] + |
| 3988 |
tp->dev->dev_addr[4] + |
| 3989 |
tp->dev->dev_addr[5]) & |
| 3990 |
TX_BACKOFF_SEED_MASK; |
| 3991 |
tw32(MAC_TX_BACKOFF_SEED, addr_high); |
| 3992 |
} |
| 3993 |
|
| 3994 |
static void tg3_enable_register_access(struct tg3 *tp) |
| 3995 |
{ |
| 3996 |
/* |
| 3997 |
* Make sure register accesses (indirect or otherwise) will function |
| 3998 |
* correctly. |
| 3999 |
*/ |
| 4000 |
pci_write_config_dword(tp->pdev, |
| 4001 |
TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl); |
| 4002 |
} |
| 4003 |
|
| 4004 |
static int tg3_power_up(struct tg3 *tp) |
| 4005 |
{ |
| 4006 |
int err; |
| 4007 |
|
| 4008 |
tg3_enable_register_access(tp); |
| 4009 |
|
| 4010 |
err = pci_set_power_state(tp->pdev, PCI_D0); |
| 4011 |
if (!err) { |
| 4012 |
/* Switch out of Vaux if it is a NIC */ |
| 4013 |
tg3_pwrsrc_switch_to_vmain(tp); |
| 4014 |
} else { |
| 4015 |
netdev_err(tp->dev, "Transition to D0 failed\n"); |
| 4016 |
} |
| 4017 |
|
| 4018 |
return err; |
| 4019 |
} |
| 4020 |
|
| 4021 |
static int tg3_setup_phy(struct tg3 *, bool); |
| 4022 |
|
| 4023 |
static void tg3_power_down_prepare(struct tg3 *tp) |
| 4024 |
{ |
| 4025 |
u32 misc_host_ctrl; |
| 4026 |
bool device_should_wake, do_low_power; |
| 4027 |
|
| 4028 |
tg3_enable_register_access(tp); |
| 4029 |
|
| 4030 |
/* Restore the CLKREQ setting. */ |
| 4031 |
if (tg3_flag(tp, CLKREQ_BUG)) |
| 4032 |
pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL, |
| 4033 |
PCI_EXP_LNKCTL_CLKREQ_EN); |
| 4034 |
|
| 4035 |
misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 4036 |
tw32(TG3PCI_MISC_HOST_CTRL, |
| 4037 |
misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); |
| 4038 |
|
| 4039 |
device_should_wake = device_may_wakeup(&tp->pdev->dev) && |
| 4040 |
tg3_flag(tp, WOL_ENABLE); |
| 4041 |
|
| 4042 |
if (tg3_flag(tp, USE_PHYLIB)) { |
| 4043 |
do_low_power = false; |
| 4044 |
if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
| 4045 |
!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 4046 |
__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising) = { 0, }; |
| 4047 |
struct phy_device *phydev; |
| 4048 |
u32 phyid; |
| 4049 |
|
| 4050 |
phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr); |
| 4051 |
|
| 4052 |
tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
| 4053 |
|
| 4054 |
tp->link_config.speed = phydev->speed; |
| 4055 |
tp->link_config.duplex = phydev->duplex; |
| 4056 |
tp->link_config.autoneg = phydev->autoneg; |
| 4057 |
ethtool_convert_link_mode_to_legacy_u32( |
| 4058 |
&tp->link_config.advertising, |
| 4059 |
phydev->advertising); |
| 4060 |
|
| 4061 |
linkmode_set_bit(ETHTOOL_LINK_MODE_TP_BIT, advertising); |
| 4062 |
linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, |
| 4063 |
advertising); |
| 4064 |
linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, |
| 4065 |
advertising); |
| 4066 |
linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, |
| 4067 |
advertising); |
| 4068 |
|
| 4069 |
if (tg3_flag(tp, ENABLE_ASF) || device_should_wake) { |
| 4070 |
if (tg3_flag(tp, WOL_SPEED_100MB)) { |
| 4071 |
linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, |
| 4072 |
advertising); |
| 4073 |
linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, |
| 4074 |
advertising); |
| 4075 |
linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, |
| 4076 |
advertising); |
| 4077 |
} else { |
| 4078 |
linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, |
| 4079 |
advertising); |
| 4080 |
} |
| 4081 |
} |
| 4082 |
|
| 4083 |
linkmode_copy(phydev->advertising, advertising); |
| 4084 |
phy_start_aneg(phydev); |
| 4085 |
|
| 4086 |
phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; |
| 4087 |
if (phyid != PHY_ID_BCMAC131) { |
| 4088 |
phyid &= PHY_BCM_OUI_MASK; |
| 4089 |
if (phyid == PHY_BCM_OUI_1 || |
| 4090 |
phyid == PHY_BCM_OUI_2 || |
| 4091 |
phyid == PHY_BCM_OUI_3) |
| 4092 |
do_low_power = true; |
| 4093 |
} |
| 4094 |
} |
| 4095 |
} else { |
| 4096 |
do_low_power = true; |
| 4097 |
|
| 4098 |
if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) |
| 4099 |
tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
| 4100 |
|
| 4101 |
if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 4102 |
tg3_setup_phy(tp, false); |
| 4103 |
} |
| 4104 |
|
| 4105 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 4106 |
u32 val; |
| 4107 |
|
| 4108 |
val = tr32(GRC_VCPU_EXT_CTRL); |
| 4109 |
tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); |
| 4110 |
} else if (!tg3_flag(tp, ENABLE_ASF)) { |
| 4111 |
int i; |
| 4112 |
u32 val; |
| 4113 |
|
| 4114 |
for (i = 0; i < 200; i++) { |
| 4115 |
tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); |
| 4116 |
if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) |
| 4117 |
break; |
| 4118 |
msleep(1); |
| 4119 |
} |
| 4120 |
} |
| 4121 |
if (tg3_flag(tp, WOL_CAP)) |
| 4122 |
tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
| 4123 |
WOL_DRV_STATE_SHUTDOWN | |
| 4124 |
WOL_DRV_WOL | |
| 4125 |
WOL_SET_MAGIC_PKT); |
| 4126 |
|
| 4127 |
if (device_should_wake) { |
| 4128 |
u32 mac_mode; |
| 4129 |
|
| 4130 |
if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 4131 |
if (do_low_power && |
| 4132 |
!(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 4133 |
tg3_phy_auxctl_write(tp, |
| 4134 |
MII_TG3_AUXCTL_SHDWSEL_PWRCTL, |
| 4135 |
MII_TG3_AUXCTL_PCTL_WOL_EN | |
| 4136 |
MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
| 4137 |
MII_TG3_AUXCTL_PCTL_CL_AB_TXDAC); |
| 4138 |
udelay(40); |
| 4139 |
} |
| 4140 |
|
| 4141 |
if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
| 4142 |
mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 4143 |
else if (tp->phy_flags & |
| 4144 |
TG3_PHYFLG_KEEP_LINK_ON_PWRDN) { |
| 4145 |
if (tp->link_config.active_speed == SPEED_1000) |
| 4146 |
mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 4147 |
else |
| 4148 |
mac_mode = MAC_MODE_PORT_MODE_MII; |
| 4149 |
} else |
| 4150 |
mac_mode = MAC_MODE_PORT_MODE_MII; |
| 4151 |
|
| 4152 |
mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
| 4153 |
if (tg3_asic_rev(tp) == ASIC_REV_5700) { |
| 4154 |
u32 speed = tg3_flag(tp, WOL_SPEED_100MB) ? |
| 4155 |
SPEED_100 : SPEED_10; |
| 4156 |
if (tg3_5700_link_polarity(tp, speed)) |
| 4157 |
mac_mode |= MAC_MODE_LINK_POLARITY; |
| 4158 |
else |
| 4159 |
mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 4160 |
} |
| 4161 |
} else { |
| 4162 |
mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 4163 |
} |
| 4164 |
|
| 4165 |
if (!tg3_flag(tp, 5750_PLUS)) |
| 4166 |
tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 4167 |
|
| 4168 |
mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
| 4169 |
if ((tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) && |
| 4170 |
(tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE))) |
| 4171 |
mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
| 4172 |
|
| 4173 |
if (tg3_flag(tp, ENABLE_APE)) |
| 4174 |
mac_mode |= MAC_MODE_APE_TX_EN | |
| 4175 |
MAC_MODE_APE_RX_EN | |
| 4176 |
MAC_MODE_TDE_ENABLE; |
| 4177 |
|
| 4178 |
tw32_f(MAC_MODE, mac_mode); |
| 4179 |
udelay(100); |
| 4180 |
|
| 4181 |
tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); |
| 4182 |
udelay(10); |
| 4183 |
} |
| 4184 |
|
| 4185 |
if (!tg3_flag(tp, WOL_SPEED_100MB) && |
| 4186 |
(tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 4187 |
tg3_asic_rev(tp) == ASIC_REV_5701)) { |
| 4188 |
u32 base_val; |
| 4189 |
|
| 4190 |
base_val = tp->pci_clock_ctrl; |
| 4191 |
base_val |= (CLOCK_CTRL_RXCLK_DISABLE | |
| 4192 |
CLOCK_CTRL_TXCLK_DISABLE); |
| 4193 |
|
| 4194 |
tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
| 4195 |
CLOCK_CTRL_PWRDOWN_PLL133, 40); |
| 4196 |
} else if (tg3_flag(tp, 5780_CLASS) || |
| 4197 |
tg3_flag(tp, CPMU_PRESENT) || |
| 4198 |
tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 4199 |
/* do nothing */ |
| 4200 |
} else if (!(tg3_flag(tp, 5750_PLUS) && tg3_flag(tp, ENABLE_ASF))) { |
| 4201 |
u32 newbits1, newbits2; |
| 4202 |
|
| 4203 |
if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 4204 |
tg3_asic_rev(tp) == ASIC_REV_5701) { |
| 4205 |
newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 4206 |
CLOCK_CTRL_TXCLK_DISABLE | |
| 4207 |
CLOCK_CTRL_ALTCLK); |
| 4208 |
newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 4209 |
} else if (tg3_flag(tp, 5705_PLUS)) { |
| 4210 |
newbits1 = CLOCK_CTRL_625_CORE; |
| 4211 |
newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; |
| 4212 |
} else { |
| 4213 |
newbits1 = CLOCK_CTRL_ALTCLK; |
| 4214 |
newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; |
| 4215 |
} |
| 4216 |
|
| 4217 |
tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
| 4218 |
40); |
| 4219 |
|
| 4220 |
tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
| 4221 |
40); |
| 4222 |
|
| 4223 |
if (!tg3_flag(tp, 5705_PLUS)) { |
| 4224 |
u32 newbits3; |
| 4225 |
|
| 4226 |
if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 4227 |
tg3_asic_rev(tp) == ASIC_REV_5701) { |
| 4228 |
newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | |
| 4229 |
CLOCK_CTRL_TXCLK_DISABLE | |
| 4230 |
CLOCK_CTRL_44MHZ_CORE); |
| 4231 |
} else { |
| 4232 |
newbits3 = CLOCK_CTRL_44MHZ_CORE; |
| 4233 |
} |
| 4234 |
|
| 4235 |
tw32_wait_f(TG3PCI_CLOCK_CTRL, |
| 4236 |
tp->pci_clock_ctrl | newbits3, 40); |
| 4237 |
} |
| 4238 |
} |
| 4239 |
|
| 4240 |
if (!(device_should_wake) && !tg3_flag(tp, ENABLE_ASF)) |
| 4241 |
tg3_power_down_phy(tp, do_low_power); |
| 4242 |
|
| 4243 |
tg3_frob_aux_power(tp, true); |
| 4244 |
|
| 4245 |
/* Workaround for unstable PLL clock */ |
| 4246 |
if ((!tg3_flag(tp, IS_SSB_CORE)) && |
| 4247 |
((tg3_chip_rev(tp) == CHIPREV_5750_AX) || |
| 4248 |
(tg3_chip_rev(tp) == CHIPREV_5750_BX))) { |
| 4249 |
u32 val = tr32(0x7d00); |
| 4250 |
|
| 4251 |
val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); |
| 4252 |
tw32(0x7d00, val); |
| 4253 |
if (!tg3_flag(tp, ENABLE_ASF)) { |
| 4254 |
int err; |
| 4255 |
|
| 4256 |
err = tg3_nvram_lock(tp); |
| 4257 |
tg3_halt_cpu(tp, RX_CPU_BASE); |
| 4258 |
if (!err) |
| 4259 |
tg3_nvram_unlock(tp); |
| 4260 |
} |
| 4261 |
} |
| 4262 |
|
| 4263 |
tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
| 4264 |
|
| 4265 |
tg3_ape_driver_state_change(tp, RESET_KIND_SHUTDOWN); |
| 4266 |
|
| 4267 |
return; |
| 4268 |
} |
| 4269 |
|
| 4270 |
static void tg3_power_down(struct tg3 *tp) |
| 4271 |
{ |
| 4272 |
pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE)); |
| 4273 |
pci_set_power_state(tp->pdev, PCI_D3hot); |
| 4274 |
} |
| 4275 |
|
| 4276 |
static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u32 *speed, u8 *duplex) |
| 4277 |
{ |
| 4278 |
switch (val & MII_TG3_AUX_STAT_SPDMASK) { |
| 4279 |
case MII_TG3_AUX_STAT_10HALF: |
| 4280 |
*speed = SPEED_10; |
| 4281 |
*duplex = DUPLEX_HALF; |
| 4282 |
break; |
| 4283 |
|
| 4284 |
case MII_TG3_AUX_STAT_10FULL: |
| 4285 |
*speed = SPEED_10; |
| 4286 |
*duplex = DUPLEX_FULL; |
| 4287 |
break; |
| 4288 |
|
| 4289 |
case MII_TG3_AUX_STAT_100HALF: |
| 4290 |
*speed = SPEED_100; |
| 4291 |
*duplex = DUPLEX_HALF; |
| 4292 |
break; |
| 4293 |
|
| 4294 |
case MII_TG3_AUX_STAT_100FULL: |
| 4295 |
*speed = SPEED_100; |
| 4296 |
*duplex = DUPLEX_FULL; |
| 4297 |
break; |
| 4298 |
|
| 4299 |
case MII_TG3_AUX_STAT_1000HALF: |
| 4300 |
*speed = SPEED_1000; |
| 4301 |
*duplex = DUPLEX_HALF; |
| 4302 |
break; |
| 4303 |
|
| 4304 |
case MII_TG3_AUX_STAT_1000FULL: |
| 4305 |
*speed = SPEED_1000; |
| 4306 |
*duplex = DUPLEX_FULL; |
| 4307 |
break; |
| 4308 |
|
| 4309 |
default: |
| 4310 |
if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 4311 |
*speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
| 4312 |
SPEED_10; |
| 4313 |
*duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : |
| 4314 |
DUPLEX_HALF; |
| 4315 |
break; |
| 4316 |
} |
| 4317 |
*speed = SPEED_UNKNOWN; |
| 4318 |
*duplex = DUPLEX_UNKNOWN; |
| 4319 |
break; |
| 4320 |
} |
| 4321 |
} |
| 4322 |
|
| 4323 |
static int tg3_phy_autoneg_cfg(struct tg3 *tp, u32 advertise, u32 flowctrl) |
| 4324 |
{ |
| 4325 |
int err = 0; |
| 4326 |
u32 val, new_adv; |
| 4327 |
|
| 4328 |
new_adv = ADVERTISE_CSMA; |
| 4329 |
new_adv |= ethtool_adv_to_mii_adv_t(advertise) & ADVERTISE_ALL; |
| 4330 |
new_adv |= mii_advertise_flowctrl(flowctrl); |
| 4331 |
|
| 4332 |
err = tg3_writephy(tp, MII_ADVERTISE, new_adv); |
| 4333 |
if (err) |
| 4334 |
goto done; |
| 4335 |
|
| 4336 |
if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4337 |
new_adv = ethtool_adv_to_mii_ctrl1000_t(advertise); |
| 4338 |
|
| 4339 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
| 4340 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0) |
| 4341 |
new_adv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
| 4342 |
|
| 4343 |
err = tg3_writephy(tp, MII_CTRL1000, new_adv); |
| 4344 |
if (err) |
| 4345 |
goto done; |
| 4346 |
} |
| 4347 |
|
| 4348 |
if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 4349 |
goto done; |
| 4350 |
|
| 4351 |
tw32(TG3_CPMU_EEE_MODE, |
| 4352 |
tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); |
| 4353 |
|
| 4354 |
err = tg3_phy_toggle_auxctl_smdsp(tp, true); |
| 4355 |
if (!err) { |
| 4356 |
u32 err2; |
| 4357 |
|
| 4358 |
if (!tp->eee.eee_enabled) |
| 4359 |
val = 0; |
| 4360 |
else |
| 4361 |
val = ethtool_adv_to_mmd_eee_adv_t(advertise); |
| 4362 |
|
| 4363 |
mii_eee_cap1_mod_linkmode_t(tp->eee.advertised, val); |
| 4364 |
err = tg3_phy_cl45_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, val); |
| 4365 |
if (err) |
| 4366 |
val = 0; |
| 4367 |
|
| 4368 |
switch (tg3_asic_rev(tp)) { |
| 4369 |
case ASIC_REV_5717: |
| 4370 |
case ASIC_REV_57765: |
| 4371 |
case ASIC_REV_57766: |
| 4372 |
case ASIC_REV_5719: |
| 4373 |
/* If we advertised any eee advertisements above... */ |
| 4374 |
if (val) |
| 4375 |
val = MII_TG3_DSP_TAP26_ALNOKO | |
| 4376 |
MII_TG3_DSP_TAP26_RMRXSTO | |
| 4377 |
MII_TG3_DSP_TAP26_OPCSINPT; |
| 4378 |
tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
| 4379 |
fallthrough; |
| 4380 |
case ASIC_REV_5720: |
| 4381 |
case ASIC_REV_5762: |
| 4382 |
if (!tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) |
| 4383 |
tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, val | |
| 4384 |
MII_TG3_DSP_CH34TP2_HIBW01); |
| 4385 |
} |
| 4386 |
|
| 4387 |
err2 = tg3_phy_toggle_auxctl_smdsp(tp, false); |
| 4388 |
if (!err) |
| 4389 |
err = err2; |
| 4390 |
} |
| 4391 |
|
| 4392 |
done: |
| 4393 |
return err; |
| 4394 |
} |
| 4395 |
|
| 4396 |
static void tg3_phy_copper_begin(struct tg3 *tp) |
| 4397 |
{ |
| 4398 |
if (tp->link_config.autoneg == AUTONEG_ENABLE || |
| 4399 |
(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 4400 |
u32 adv, fc; |
| 4401 |
|
| 4402 |
if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
| 4403 |
!(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN)) { |
| 4404 |
adv = ADVERTISED_10baseT_Half | |
| 4405 |
ADVERTISED_10baseT_Full; |
| 4406 |
if (tg3_flag(tp, WOL_SPEED_100MB)) |
| 4407 |
adv |= ADVERTISED_100baseT_Half | |
| 4408 |
ADVERTISED_100baseT_Full; |
| 4409 |
if (tp->phy_flags & TG3_PHYFLG_1G_ON_VAUX_OK) { |
| 4410 |
if (!(tp->phy_flags & |
| 4411 |
TG3_PHYFLG_DISABLE_1G_HD_ADV)) |
| 4412 |
adv |= ADVERTISED_1000baseT_Half; |
| 4413 |
adv |= ADVERTISED_1000baseT_Full; |
| 4414 |
} |
| 4415 |
|
| 4416 |
fc = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 4417 |
} else { |
| 4418 |
adv = tp->link_config.advertising; |
| 4419 |
if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 4420 |
adv &= ~(ADVERTISED_1000baseT_Half | |
| 4421 |
ADVERTISED_1000baseT_Full); |
| 4422 |
|
| 4423 |
fc = tp->link_config.flowctrl; |
| 4424 |
} |
| 4425 |
|
| 4426 |
tg3_phy_autoneg_cfg(tp, adv, fc); |
| 4427 |
|
| 4428 |
if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
| 4429 |
(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN)) { |
| 4430 |
/* Normally during power down we want to autonegotiate |
| 4431 |
* the lowest possible speed for WOL. However, to avoid |
| 4432 |
* link flap, we leave it untouched. |
| 4433 |
*/ |
| 4434 |
return; |
| 4435 |
} |
| 4436 |
|
| 4437 |
tg3_writephy(tp, MII_BMCR, |
| 4438 |
BMCR_ANENABLE | BMCR_ANRESTART); |
| 4439 |
} else { |
| 4440 |
int i; |
| 4441 |
u32 bmcr, orig_bmcr; |
| 4442 |
|
| 4443 |
tp->link_config.active_speed = tp->link_config.speed; |
| 4444 |
tp->link_config.active_duplex = tp->link_config.duplex; |
| 4445 |
|
| 4446 |
if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
| 4447 |
/* With autoneg disabled, 5715 only links up when the |
| 4448 |
* advertisement register has the configured speed |
| 4449 |
* enabled. |
| 4450 |
*/ |
| 4451 |
tg3_writephy(tp, MII_ADVERTISE, ADVERTISE_ALL); |
| 4452 |
} |
| 4453 |
|
| 4454 |
bmcr = 0; |
| 4455 |
switch (tp->link_config.speed) { |
| 4456 |
default: |
| 4457 |
case SPEED_10: |
| 4458 |
break; |
| 4459 |
|
| 4460 |
case SPEED_100: |
| 4461 |
bmcr |= BMCR_SPEED100; |
| 4462 |
break; |
| 4463 |
|
| 4464 |
case SPEED_1000: |
| 4465 |
bmcr |= BMCR_SPEED1000; |
| 4466 |
break; |
| 4467 |
} |
| 4468 |
|
| 4469 |
if (tp->link_config.duplex == DUPLEX_FULL) |
| 4470 |
bmcr |= BMCR_FULLDPLX; |
| 4471 |
|
| 4472 |
if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && |
| 4473 |
(bmcr != orig_bmcr)) { |
| 4474 |
tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); |
| 4475 |
for (i = 0; i < 1500; i++) { |
| 4476 |
u32 tmp; |
| 4477 |
|
| 4478 |
udelay(10); |
| 4479 |
if (tg3_readphy(tp, MII_BMSR, &tmp) || |
| 4480 |
tg3_readphy(tp, MII_BMSR, &tmp)) |
| 4481 |
continue; |
| 4482 |
if (!(tmp & BMSR_LSTATUS)) { |
| 4483 |
udelay(40); |
| 4484 |
break; |
| 4485 |
} |
| 4486 |
} |
| 4487 |
tg3_writephy(tp, MII_BMCR, bmcr); |
| 4488 |
udelay(40); |
| 4489 |
} |
| 4490 |
} |
| 4491 |
} |
| 4492 |
|
| 4493 |
static int tg3_phy_pull_config(struct tg3 *tp) |
| 4494 |
{ |
| 4495 |
int err; |
| 4496 |
u32 val; |
| 4497 |
|
| 4498 |
err = tg3_readphy(tp, MII_BMCR, &val); |
| 4499 |
if (err) |
| 4500 |
goto done; |
| 4501 |
|
| 4502 |
if (!(val & BMCR_ANENABLE)) { |
| 4503 |
tp->link_config.autoneg = AUTONEG_DISABLE; |
| 4504 |
tp->link_config.advertising = 0; |
| 4505 |
tg3_flag_clear(tp, PAUSE_AUTONEG); |
| 4506 |
|
| 4507 |
err = -EIO; |
| 4508 |
|
| 4509 |
switch (val & (BMCR_SPEED1000 | BMCR_SPEED100)) { |
| 4510 |
case 0: |
| 4511 |
if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 4512 |
goto done; |
| 4513 |
|
| 4514 |
tp->link_config.speed = SPEED_10; |
| 4515 |
break; |
| 4516 |
case BMCR_SPEED100: |
| 4517 |
if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 4518 |
goto done; |
| 4519 |
|
| 4520 |
tp->link_config.speed = SPEED_100; |
| 4521 |
break; |
| 4522 |
case BMCR_SPEED1000: |
| 4523 |
if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4524 |
tp->link_config.speed = SPEED_1000; |
| 4525 |
break; |
| 4526 |
} |
| 4527 |
fallthrough; |
| 4528 |
default: |
| 4529 |
goto done; |
| 4530 |
} |
| 4531 |
|
| 4532 |
if (val & BMCR_FULLDPLX) |
| 4533 |
tp->link_config.duplex = DUPLEX_FULL; |
| 4534 |
else |
| 4535 |
tp->link_config.duplex = DUPLEX_HALF; |
| 4536 |
|
| 4537 |
tp->link_config.flowctrl = FLOW_CTRL_RX | FLOW_CTRL_TX; |
| 4538 |
|
| 4539 |
err = 0; |
| 4540 |
goto done; |
| 4541 |
} |
| 4542 |
|
| 4543 |
tp->link_config.autoneg = AUTONEG_ENABLE; |
| 4544 |
tp->link_config.advertising = ADVERTISED_Autoneg; |
| 4545 |
tg3_flag_set(tp, PAUSE_AUTONEG); |
| 4546 |
|
| 4547 |
if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 4548 |
u32 adv; |
| 4549 |
|
| 4550 |
err = tg3_readphy(tp, MII_ADVERTISE, &val); |
| 4551 |
if (err) |
| 4552 |
goto done; |
| 4553 |
|
| 4554 |
adv = mii_adv_to_ethtool_adv_t(val & ADVERTISE_ALL); |
| 4555 |
tp->link_config.advertising |= adv | ADVERTISED_TP; |
| 4556 |
|
| 4557 |
tp->link_config.flowctrl = tg3_decode_flowctrl_1000T(val); |
| 4558 |
} else { |
| 4559 |
tp->link_config.advertising |= ADVERTISED_FIBRE; |
| 4560 |
} |
| 4561 |
|
| 4562 |
if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4563 |
u32 adv; |
| 4564 |
|
| 4565 |
if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 4566 |
err = tg3_readphy(tp, MII_CTRL1000, &val); |
| 4567 |
if (err) |
| 4568 |
goto done; |
| 4569 |
|
| 4570 |
adv = mii_ctrl1000_to_ethtool_adv_t(val); |
| 4571 |
} else { |
| 4572 |
err = tg3_readphy(tp, MII_ADVERTISE, &val); |
| 4573 |
if (err) |
| 4574 |
goto done; |
| 4575 |
|
| 4576 |
adv = tg3_decode_flowctrl_1000X(val); |
| 4577 |
tp->link_config.flowctrl = adv; |
| 4578 |
|
| 4579 |
val &= (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL); |
| 4580 |
adv = mii_adv_to_ethtool_adv_x(val); |
| 4581 |
} |
| 4582 |
|
| 4583 |
tp->link_config.advertising |= adv; |
| 4584 |
} |
| 4585 |
|
| 4586 |
done: |
| 4587 |
return err; |
| 4588 |
} |
| 4589 |
|
| 4590 |
static int tg3_init_5401phy_dsp(struct tg3 *tp) |
| 4591 |
{ |
| 4592 |
int err; |
| 4593 |
|
| 4594 |
/* Turn off tap power management. */ |
| 4595 |
/* Set Extended packet length bit */ |
| 4596 |
err = tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
| 4597 |
|
| 4598 |
err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
| 4599 |
err |= tg3_phydsp_write(tp, 0x0013, 0x1204); |
| 4600 |
err |= tg3_phydsp_write(tp, 0x8006, 0x0132); |
| 4601 |
err |= tg3_phydsp_write(tp, 0x8006, 0x0232); |
| 4602 |
err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); |
| 4603 |
|
| 4604 |
udelay(40); |
| 4605 |
|
| 4606 |
return err; |
| 4607 |
} |
| 4608 |
|
| 4609 |
static bool tg3_phy_eee_config_ok(struct tg3 *tp) |
| 4610 |
{ |
| 4611 |
struct ethtool_keee eee = {}; |
| 4612 |
|
| 4613 |
if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
| 4614 |
return true; |
| 4615 |
|
| 4616 |
tg3_eee_pull_config(tp, &eee); |
| 4617 |
|
| 4618 |
if (tp->eee.eee_enabled) { |
| 4619 |
if (!linkmode_equal(tp->eee.advertised, eee.advertised) || |
| 4620 |
tp->eee.tx_lpi_timer != eee.tx_lpi_timer || |
| 4621 |
tp->eee.tx_lpi_enabled != eee.tx_lpi_enabled) |
| 4622 |
return false; |
| 4623 |
} else { |
| 4624 |
/* EEE is disabled but we're advertising */ |
| 4625 |
if (!linkmode_empty(eee.advertised)) |
| 4626 |
return false; |
| 4627 |
} |
| 4628 |
|
| 4629 |
return true; |
| 4630 |
} |
| 4631 |
|
| 4632 |
static bool tg3_phy_copper_an_config_ok(struct tg3 *tp, u32 *lcladv) |
| 4633 |
{ |
| 4634 |
u32 advmsk, tgtadv, advertising; |
| 4635 |
|
| 4636 |
advertising = tp->link_config.advertising; |
| 4637 |
tgtadv = ethtool_adv_to_mii_adv_t(advertising) & ADVERTISE_ALL; |
| 4638 |
|
| 4639 |
advmsk = ADVERTISE_ALL; |
| 4640 |
if (tp->link_config.active_duplex == DUPLEX_FULL) { |
| 4641 |
tgtadv |= mii_advertise_flowctrl(tp->link_config.flowctrl); |
| 4642 |
advmsk |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 4643 |
} |
| 4644 |
|
| 4645 |
if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
| 4646 |
return false; |
| 4647 |
|
| 4648 |
if ((*lcladv & advmsk) != tgtadv) |
| 4649 |
return false; |
| 4650 |
|
| 4651 |
if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4652 |
u32 tg3_ctrl; |
| 4653 |
|
| 4654 |
tgtadv = ethtool_adv_to_mii_ctrl1000_t(advertising); |
| 4655 |
|
| 4656 |
if (tg3_readphy(tp, MII_CTRL1000, &tg3_ctrl)) |
| 4657 |
return false; |
| 4658 |
|
| 4659 |
if (tgtadv && |
| 4660 |
(tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
| 4661 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0)) { |
| 4662 |
tgtadv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
| 4663 |
tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL | |
| 4664 |
CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); |
| 4665 |
} else { |
| 4666 |
tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL); |
| 4667 |
} |
| 4668 |
|
| 4669 |
if (tg3_ctrl != tgtadv) |
| 4670 |
return false; |
| 4671 |
} |
| 4672 |
|
| 4673 |
return true; |
| 4674 |
} |
| 4675 |
|
| 4676 |
static bool tg3_phy_copper_fetch_rmtadv(struct tg3 *tp, u32 *rmtadv) |
| 4677 |
{ |
| 4678 |
u32 lpeth = 0; |
| 4679 |
|
| 4680 |
if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 4681 |
u32 val; |
| 4682 |
|
| 4683 |
if (tg3_readphy(tp, MII_STAT1000, &val)) |
| 4684 |
return false; |
| 4685 |
|
| 4686 |
lpeth = mii_stat1000_to_ethtool_lpa_t(val); |
| 4687 |
} |
| 4688 |
|
| 4689 |
if (tg3_readphy(tp, MII_LPA, rmtadv)) |
| 4690 |
return false; |
| 4691 |
|
| 4692 |
lpeth |= mii_lpa_to_ethtool_lpa_t(*rmtadv); |
| 4693 |
tp->link_config.rmt_adv = lpeth; |
| 4694 |
|
| 4695 |
return true; |
| 4696 |
} |
| 4697 |
|
| 4698 |
static bool tg3_test_and_report_link_chg(struct tg3 *tp, bool curr_link_up) |
| 4699 |
{ |
| 4700 |
if (curr_link_up != tp->link_up) { |
| 4701 |
if (curr_link_up) { |
| 4702 |
netif_carrier_on(tp->dev); |
| 4703 |
} else { |
| 4704 |
netif_carrier_off(tp->dev); |
| 4705 |
if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
| 4706 |
tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 4707 |
} |
| 4708 |
|
| 4709 |
tg3_link_report(tp); |
| 4710 |
return true; |
| 4711 |
} |
| 4712 |
|
| 4713 |
return false; |
| 4714 |
} |
| 4715 |
|
| 4716 |
static void tg3_clear_mac_status(struct tg3 *tp) |
| 4717 |
{ |
| 4718 |
tw32(MAC_EVENT, 0); |
| 4719 |
|
| 4720 |
tw32_f(MAC_STATUS, |
| 4721 |
MAC_STATUS_SYNC_CHANGED | |
| 4722 |
MAC_STATUS_CFG_CHANGED | |
| 4723 |
MAC_STATUS_MI_COMPLETION | |
| 4724 |
MAC_STATUS_LNKSTATE_CHANGED); |
| 4725 |
udelay(40); |
| 4726 |
} |
| 4727 |
|
| 4728 |
static void tg3_setup_eee(struct tg3 *tp) |
| 4729 |
{ |
| 4730 |
u32 val; |
| 4731 |
|
| 4732 |
val = TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | |
| 4733 |
TG3_CPMU_EEE_LNKIDL_UART_IDL; |
| 4734 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) |
| 4735 |
val |= TG3_CPMU_EEE_LNKIDL_APE_TX_MT; |
| 4736 |
|
| 4737 |
tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, val); |
| 4738 |
|
| 4739 |
tw32_f(TG3_CPMU_EEE_CTRL, |
| 4740 |
TG3_CPMU_EEE_CTRL_EXIT_20_1_US); |
| 4741 |
|
| 4742 |
val = TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
| 4743 |
(tp->eee.tx_lpi_enabled ? TG3_CPMU_EEEMD_LPI_IN_TX : 0) | |
| 4744 |
TG3_CPMU_EEEMD_LPI_IN_RX | |
| 4745 |
TG3_CPMU_EEEMD_EEE_ENABLE; |
| 4746 |
|
| 4747 |
if (tg3_asic_rev(tp) != ASIC_REV_5717) |
| 4748 |
val |= TG3_CPMU_EEEMD_SND_IDX_DET_EN; |
| 4749 |
|
| 4750 |
if (tg3_flag(tp, ENABLE_APE)) |
| 4751 |
val |= TG3_CPMU_EEEMD_APE_TX_DET_EN; |
| 4752 |
|
| 4753 |
tw32_f(TG3_CPMU_EEE_MODE, tp->eee.eee_enabled ? val : 0); |
| 4754 |
|
| 4755 |
tw32_f(TG3_CPMU_EEE_DBTMR1, |
| 4756 |
TG3_CPMU_DBTMR1_PCIEXIT_2047US | |
| 4757 |
(tp->eee.tx_lpi_timer & 0xffff)); |
| 4758 |
|
| 4759 |
tw32_f(TG3_CPMU_EEE_DBTMR2, |
| 4760 |
TG3_CPMU_DBTMR2_APE_TX_2047US | |
| 4761 |
TG3_CPMU_DBTMR2_TXIDXEQ_2047US); |
| 4762 |
} |
| 4763 |
|
| 4764 |
static int tg3_setup_copper_phy(struct tg3 *tp, bool force_reset) |
| 4765 |
{ |
| 4766 |
bool current_link_up; |
| 4767 |
u32 bmsr, val; |
| 4768 |
u32 lcl_adv, rmt_adv; |
| 4769 |
u32 current_speed; |
| 4770 |
u8 current_duplex; |
| 4771 |
int i, err; |
| 4772 |
|
| 4773 |
tg3_clear_mac_status(tp); |
| 4774 |
|
| 4775 |
if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
| 4776 |
tw32_f(MAC_MI_MODE, |
| 4777 |
(tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); |
| 4778 |
udelay(80); |
| 4779 |
} |
| 4780 |
|
| 4781 |
tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, 0); |
| 4782 |
|
| 4783 |
/* Some third-party PHYs need to be reset on link going |
| 4784 |
* down. |
| 4785 |
*/ |
| 4786 |
if ((tg3_asic_rev(tp) == ASIC_REV_5703 || |
| 4787 |
tg3_asic_rev(tp) == ASIC_REV_5704 || |
| 4788 |
tg3_asic_rev(tp) == ASIC_REV_5705) && |
| 4789 |
tp->link_up) { |
| 4790 |
tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4791 |
if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4792 |
!(bmsr & BMSR_LSTATUS)) |
| 4793 |
force_reset = true; |
| 4794 |
} |
| 4795 |
if (force_reset) |
| 4796 |
tg3_phy_reset(tp); |
| 4797 |
|
| 4798 |
if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
| 4799 |
tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4800 |
if (tg3_readphy(tp, MII_BMSR, &bmsr) || |
| 4801 |
!tg3_flag(tp, INIT_COMPLETE)) |
| 4802 |
bmsr = 0; |
| 4803 |
|
| 4804 |
if (!(bmsr & BMSR_LSTATUS)) { |
| 4805 |
err = tg3_init_5401phy_dsp(tp); |
| 4806 |
if (err) |
| 4807 |
return err; |
| 4808 |
|
| 4809 |
tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4810 |
for (i = 0; i < 1000; i++) { |
| 4811 |
udelay(10); |
| 4812 |
if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4813 |
(bmsr & BMSR_LSTATUS)) { |
| 4814 |
udelay(40); |
| 4815 |
break; |
| 4816 |
} |
| 4817 |
} |
| 4818 |
|
| 4819 |
if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
| 4820 |
TG3_PHY_REV_BCM5401_B0 && |
| 4821 |
!(bmsr & BMSR_LSTATUS) && |
| 4822 |
tp->link_config.active_speed == SPEED_1000) { |
| 4823 |
err = tg3_phy_reset(tp); |
| 4824 |
if (!err) |
| 4825 |
err = tg3_init_5401phy_dsp(tp); |
| 4826 |
if (err) |
| 4827 |
return err; |
| 4828 |
} |
| 4829 |
} |
| 4830 |
} else if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
| 4831 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0) { |
| 4832 |
/* 5701 {A0,B0} CRC bug workaround */ |
| 4833 |
tg3_writephy(tp, 0x15, 0x0a75); |
| 4834 |
tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
| 4835 |
tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
| 4836 |
tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
| 4837 |
} |
| 4838 |
|
| 4839 |
/* Clear pending interrupts... */ |
| 4840 |
tg3_readphy(tp, MII_TG3_ISTAT, &val); |
| 4841 |
tg3_readphy(tp, MII_TG3_ISTAT, &val); |
| 4842 |
|
| 4843 |
if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
| 4844 |
tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
| 4845 |
else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
| 4846 |
tg3_writephy(tp, MII_TG3_IMASK, ~0); |
| 4847 |
|
| 4848 |
if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 4849 |
tg3_asic_rev(tp) == ASIC_REV_5701) { |
| 4850 |
if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
| 4851 |
tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 4852 |
MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 4853 |
else |
| 4854 |
tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); |
| 4855 |
} |
| 4856 |
|
| 4857 |
current_link_up = false; |
| 4858 |
current_speed = SPEED_UNKNOWN; |
| 4859 |
current_duplex = DUPLEX_UNKNOWN; |
| 4860 |
tp->phy_flags &= ~TG3_PHYFLG_MDIX_STATE; |
| 4861 |
tp->link_config.rmt_adv = 0; |
| 4862 |
|
| 4863 |
if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
| 4864 |
err = tg3_phy_auxctl_read(tp, |
| 4865 |
MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4866 |
&val); |
| 4867 |
if (!err && !(val & (1 << 10))) { |
| 4868 |
tg3_phy_auxctl_write(tp, |
| 4869 |
MII_TG3_AUXCTL_SHDWSEL_MISCTEST, |
| 4870 |
val | (1 << 10)); |
| 4871 |
goto relink; |
| 4872 |
} |
| 4873 |
} |
| 4874 |
|
| 4875 |
bmsr = 0; |
| 4876 |
for (i = 0; i < 100; i++) { |
| 4877 |
tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4878 |
if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 4879 |
(bmsr & BMSR_LSTATUS)) |
| 4880 |
break; |
| 4881 |
udelay(40); |
| 4882 |
} |
| 4883 |
|
| 4884 |
if (bmsr & BMSR_LSTATUS) { |
| 4885 |
u32 aux_stat, bmcr; |
| 4886 |
|
| 4887 |
tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); |
| 4888 |
for (i = 0; i < 2000; i++) { |
| 4889 |
udelay(10); |
| 4890 |
if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && |
| 4891 |
aux_stat) |
| 4892 |
break; |
| 4893 |
} |
| 4894 |
|
| 4895 |
tg3_aux_stat_to_speed_duplex(tp, aux_stat, |
| 4896 |
¤t_speed, |
| 4897 |
¤t_duplex); |
| 4898 |
|
| 4899 |
bmcr = 0; |
| 4900 |
for (i = 0; i < 200; i++) { |
| 4901 |
tg3_readphy(tp, MII_BMCR, &bmcr); |
| 4902 |
if (tg3_readphy(tp, MII_BMCR, &bmcr)) |
| 4903 |
continue; |
| 4904 |
if (bmcr && bmcr != 0x7fff) |
| 4905 |
break; |
| 4906 |
udelay(10); |
| 4907 |
} |
| 4908 |
|
| 4909 |
lcl_adv = 0; |
| 4910 |
rmt_adv = 0; |
| 4911 |
|
| 4912 |
tp->link_config.active_speed = current_speed; |
| 4913 |
tp->link_config.active_duplex = current_duplex; |
| 4914 |
|
| 4915 |
if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 4916 |
bool eee_config_ok = tg3_phy_eee_config_ok(tp); |
| 4917 |
|
| 4918 |
if ((bmcr & BMCR_ANENABLE) && |
| 4919 |
eee_config_ok && |
| 4920 |
tg3_phy_copper_an_config_ok(tp, &lcl_adv) && |
| 4921 |
tg3_phy_copper_fetch_rmtadv(tp, &rmt_adv)) |
| 4922 |
current_link_up = true; |
| 4923 |
|
| 4924 |
/* EEE settings changes take effect only after a phy |
| 4925 |
* reset. If we have skipped a reset due to Link Flap |
| 4926 |
* Avoidance being enabled, do it now. |
| 4927 |
*/ |
| 4928 |
if (!eee_config_ok && |
| 4929 |
(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) && |
| 4930 |
!force_reset) { |
| 4931 |
tg3_setup_eee(tp); |
| 4932 |
tg3_phy_reset(tp); |
| 4933 |
} |
| 4934 |
} else { |
| 4935 |
if (!(bmcr & BMCR_ANENABLE) && |
| 4936 |
tp->link_config.speed == current_speed && |
| 4937 |
tp->link_config.duplex == current_duplex) { |
| 4938 |
current_link_up = true; |
| 4939 |
} |
| 4940 |
} |
| 4941 |
|
| 4942 |
if (current_link_up && |
| 4943 |
tp->link_config.active_duplex == DUPLEX_FULL) { |
| 4944 |
u32 reg, bit; |
| 4945 |
|
| 4946 |
if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 4947 |
reg = MII_TG3_FET_GEN_STAT; |
| 4948 |
bit = MII_TG3_FET_GEN_STAT_MDIXSTAT; |
| 4949 |
} else { |
| 4950 |
reg = MII_TG3_EXT_STAT; |
| 4951 |
bit = MII_TG3_EXT_STAT_MDIX; |
| 4952 |
} |
| 4953 |
|
| 4954 |
if (!tg3_readphy(tp, reg, &val) && (val & bit)) |
| 4955 |
tp->phy_flags |= TG3_PHYFLG_MDIX_STATE; |
| 4956 |
|
| 4957 |
tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
| 4958 |
} |
| 4959 |
} |
| 4960 |
|
| 4961 |
relink: |
| 4962 |
if (!current_link_up || (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
| 4963 |
tg3_phy_copper_begin(tp); |
| 4964 |
|
| 4965 |
if (tg3_flag(tp, ROBOSWITCH)) { |
| 4966 |
current_link_up = true; |
| 4967 |
/* FIXME: when BCM5325 switch is used use 100 MBit/s */ |
| 4968 |
current_speed = SPEED_1000; |
| 4969 |
current_duplex = DUPLEX_FULL; |
| 4970 |
tp->link_config.active_speed = current_speed; |
| 4971 |
tp->link_config.active_duplex = current_duplex; |
| 4972 |
} |
| 4973 |
|
| 4974 |
tg3_readphy(tp, MII_BMSR, &bmsr); |
| 4975 |
if ((!tg3_readphy(tp, MII_BMSR, &bmsr) && (bmsr & BMSR_LSTATUS)) || |
| 4976 |
(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
| 4977 |
current_link_up = true; |
| 4978 |
} |
| 4979 |
|
| 4980 |
tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 4981 |
if (current_link_up) { |
| 4982 |
if (tp->link_config.active_speed == SPEED_100 || |
| 4983 |
tp->link_config.active_speed == SPEED_10) |
| 4984 |
tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4985 |
else |
| 4986 |
tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4987 |
} else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 4988 |
tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 4989 |
else |
| 4990 |
tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 4991 |
|
| 4992 |
/* In order for the 5750 core in BCM4785 chip to work properly |
| 4993 |
* in RGMII mode, the Led Control Register must be set up. |
| 4994 |
*/ |
| 4995 |
if (tg3_flag(tp, RGMII_MODE)) { |
| 4996 |
u32 led_ctrl = tr32(MAC_LED_CTRL); |
| 4997 |
led_ctrl &= ~(LED_CTRL_1000MBPS_ON | LED_CTRL_100MBPS_ON); |
| 4998 |
|
| 4999 |
if (tp->link_config.active_speed == SPEED_10) |
| 5000 |
led_ctrl |= LED_CTRL_LNKLED_OVERRIDE; |
| 5001 |
else if (tp->link_config.active_speed == SPEED_100) |
| 5002 |
led_ctrl |= (LED_CTRL_LNKLED_OVERRIDE | |
| 5003 |
LED_CTRL_100MBPS_ON); |
| 5004 |
else if (tp->link_config.active_speed == SPEED_1000) |
| 5005 |
led_ctrl |= (LED_CTRL_LNKLED_OVERRIDE | |
| 5006 |
LED_CTRL_1000MBPS_ON); |
| 5007 |
|
| 5008 |
tw32(MAC_LED_CTRL, led_ctrl); |
| 5009 |
udelay(40); |
| 5010 |
} |
| 5011 |
|
| 5012 |
tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 5013 |
if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 5014 |
tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 5015 |
|
| 5016 |
if (tg3_asic_rev(tp) == ASIC_REV_5700) { |
| 5017 |
if (current_link_up && |
| 5018 |
tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
| 5019 |
tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
| 5020 |
else |
| 5021 |
tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 5022 |
} |
| 5023 |
|
| 5024 |
/* ??? Without this setting Netgear GA302T PHY does not |
| 5025 |
* ??? send/receive packets... |
| 5026 |
*/ |
| 5027 |
if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
| 5028 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5700_ALTIMA) { |
| 5029 |
tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
| 5030 |
tw32_f(MAC_MI_MODE, tp->mi_mode); |
| 5031 |
udelay(80); |
| 5032 |
} |
| 5033 |
|
| 5034 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5035 |
udelay(40); |
| 5036 |
|
| 5037 |
tg3_phy_eee_adjust(tp, current_link_up); |
| 5038 |
|
| 5039 |
if (tg3_flag(tp, USE_LINKCHG_REG)) { |
| 5040 |
/* Polled via timer. */ |
| 5041 |
tw32_f(MAC_EVENT, 0); |
| 5042 |
} else { |
| 5043 |
tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5044 |
} |
| 5045 |
udelay(40); |
| 5046 |
|
| 5047 |
if (tg3_asic_rev(tp) == ASIC_REV_5700 && |
| 5048 |
current_link_up && |
| 5049 |
tp->link_config.active_speed == SPEED_1000 && |
| 5050 |
(tg3_flag(tp, PCIX_MODE) || tg3_flag(tp, PCI_HIGH_SPEED))) { |
| 5051 |
udelay(120); |
| 5052 |
tw32_f(MAC_STATUS, |
| 5053 |
(MAC_STATUS_SYNC_CHANGED | |
| 5054 |
MAC_STATUS_CFG_CHANGED)); |
| 5055 |
udelay(40); |
| 5056 |
tg3_write_mem(tp, |
| 5057 |
NIC_SRAM_FIRMWARE_MBOX, |
| 5058 |
NIC_SRAM_FIRMWARE_MBOX_MAGIC2); |
| 5059 |
} |
| 5060 |
|
| 5061 |
/* Prevent send BD corruption. */ |
| 5062 |
if (tg3_flag(tp, CLKREQ_BUG)) { |
| 5063 |
if (tp->link_config.active_speed == SPEED_100 || |
| 5064 |
tp->link_config.active_speed == SPEED_10) |
| 5065 |
pcie_capability_clear_word(tp->pdev, PCI_EXP_LNKCTL, |
| 5066 |
PCI_EXP_LNKCTL_CLKREQ_EN); |
| 5067 |
else |
| 5068 |
pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL, |
| 5069 |
PCI_EXP_LNKCTL_CLKREQ_EN); |
| 5070 |
} |
| 5071 |
|
| 5072 |
tg3_test_and_report_link_chg(tp, current_link_up); |
| 5073 |
|
| 5074 |
return 0; |
| 5075 |
} |
| 5076 |
|
| 5077 |
struct tg3_fiber_aneginfo { |
| 5078 |
int state; |
| 5079 |
#define ANEG_STATE_UNKNOWN 0 |
| 5080 |
#define ANEG_STATE_AN_ENABLE 1 |
| 5081 |
#define ANEG_STATE_RESTART_INIT 2 |
| 5082 |
#define ANEG_STATE_RESTART 3 |
| 5083 |
#define ANEG_STATE_DISABLE_LINK_OK 4 |
| 5084 |
#define ANEG_STATE_ABILITY_DETECT_INIT 5 |
| 5085 |
#define ANEG_STATE_ABILITY_DETECT 6 |
| 5086 |
#define ANEG_STATE_ACK_DETECT_INIT 7 |
| 5087 |
#define ANEG_STATE_ACK_DETECT 8 |
| 5088 |
#define ANEG_STATE_COMPLETE_ACK_INIT 9 |
| 5089 |
#define ANEG_STATE_COMPLETE_ACK 10 |
| 5090 |
#define ANEG_STATE_IDLE_DETECT_INIT 11 |
| 5091 |
#define ANEG_STATE_IDLE_DETECT 12 |
| 5092 |
#define ANEG_STATE_LINK_OK 13 |
| 5093 |
#define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 |
| 5094 |
#define ANEG_STATE_NEXT_PAGE_WAIT 15 |
| 5095 |
|
| 5096 |
u32 flags; |
| 5097 |
#define MR_AN_ENABLE 0x00000001 |
| 5098 |
#define MR_RESTART_AN 0x00000002 |
| 5099 |
#define MR_AN_COMPLETE 0x00000004 |
| 5100 |
#define MR_PAGE_RX 0x00000008 |
| 5101 |
#define MR_NP_LOADED 0x00000010 |
| 5102 |
#define MR_TOGGLE_TX 0x00000020 |
| 5103 |
#define MR_LP_ADV_FULL_DUPLEX 0x00000040 |
| 5104 |
#define MR_LP_ADV_HALF_DUPLEX 0x00000080 |
| 5105 |
#define MR_LP_ADV_SYM_PAUSE 0x00000100 |
| 5106 |
#define MR_LP_ADV_ASYM_PAUSE 0x00000200 |
| 5107 |
#define MR_LP_ADV_REMOTE_FAULT1 0x00000400 |
| 5108 |
#define MR_LP_ADV_REMOTE_FAULT2 0x00000800 |
| 5109 |
#define MR_LP_ADV_NEXT_PAGE 0x00001000 |
| 5110 |
#define MR_TOGGLE_RX 0x00002000 |
| 5111 |
#define MR_NP_RX 0x00004000 |
| 5112 |
|
| 5113 |
#define MR_LINK_OK 0x80000000 |
| 5114 |
|
| 5115 |
unsigned long link_time, cur_time; |
| 5116 |
|
| 5117 |
u32 ability_match_cfg; |
| 5118 |
int ability_match_count; |
| 5119 |
|
| 5120 |
char ability_match, idle_match, ack_match; |
| 5121 |
|
| 5122 |
u32 txconfig, rxconfig; |
| 5123 |
#define ANEG_CFG_NP 0x00000080 |
| 5124 |
#define ANEG_CFG_ACK 0x00000040 |
| 5125 |
#define ANEG_CFG_RF2 0x00000020 |
| 5126 |
#define ANEG_CFG_RF1 0x00000010 |
| 5127 |
#define ANEG_CFG_PS2 0x00000001 |
| 5128 |
#define ANEG_CFG_PS1 0x00008000 |
| 5129 |
#define ANEG_CFG_HD 0x00004000 |
| 5130 |
#define ANEG_CFG_FD 0x00002000 |
| 5131 |
#define ANEG_CFG_INVAL 0x00001f06 |
| 5132 |
|
| 5133 |
}; |
| 5134 |
#define ANEG_OK 0 |
| 5135 |
#define ANEG_DONE 1 |
| 5136 |
#define ANEG_TIMER_ENAB 2 |
| 5137 |
#define ANEG_FAILED -1 |
| 5138 |
|
| 5139 |
#define ANEG_STATE_SETTLE_TIME 10000 |
| 5140 |
|
| 5141 |
static int tg3_fiber_aneg_smachine(struct tg3 *tp, |
| 5142 |
struct tg3_fiber_aneginfo *ap) |
| 5143 |
{ |
| 5144 |
u16 flowctrl; |
| 5145 |
unsigned long delta; |
| 5146 |
u32 rx_cfg_reg; |
| 5147 |
int ret; |
| 5148 |
|
| 5149 |
if (ap->state == ANEG_STATE_UNKNOWN) { |
| 5150 |
ap->rxconfig = 0; |
| 5151 |
ap->link_time = 0; |
| 5152 |
ap->cur_time = 0; |
| 5153 |
ap->ability_match_cfg = 0; |
| 5154 |
ap->ability_match_count = 0; |
| 5155 |
ap->ability_match = 0; |
| 5156 |
ap->idle_match = 0; |
| 5157 |
ap->ack_match = 0; |
| 5158 |
} |
| 5159 |
ap->cur_time++; |
| 5160 |
|
| 5161 |
if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { |
| 5162 |
rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); |
| 5163 |
|
| 5164 |
if (rx_cfg_reg != ap->ability_match_cfg) { |
| 5165 |
ap->ability_match_cfg = rx_cfg_reg; |
| 5166 |
ap->ability_match = 0; |
| 5167 |
ap->ability_match_count = 0; |
| 5168 |
} else { |
| 5169 |
if (++ap->ability_match_count > 1) { |
| 5170 |
ap->ability_match = 1; |
| 5171 |
ap->ability_match_cfg = rx_cfg_reg; |
| 5172 |
} |
| 5173 |
} |
| 5174 |
if (rx_cfg_reg & ANEG_CFG_ACK) |
| 5175 |
ap->ack_match = 1; |
| 5176 |
else |
| 5177 |
ap->ack_match = 0; |
| 5178 |
|
| 5179 |
ap->idle_match = 0; |
| 5180 |
} else { |
| 5181 |
ap->idle_match = 1; |
| 5182 |
ap->ability_match_cfg = 0; |
| 5183 |
ap->ability_match_count = 0; |
| 5184 |
ap->ability_match = 0; |
| 5185 |
ap->ack_match = 0; |
| 5186 |
|
| 5187 |
rx_cfg_reg = 0; |
| 5188 |
} |
| 5189 |
|
| 5190 |
ap->rxconfig = rx_cfg_reg; |
| 5191 |
ret = ANEG_OK; |
| 5192 |
|
| 5193 |
switch (ap->state) { |
| 5194 |
case ANEG_STATE_UNKNOWN: |
| 5195 |
if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) |
| 5196 |
ap->state = ANEG_STATE_AN_ENABLE; |
| 5197 |
|
| 5198 |
fallthrough; |
| 5199 |
case ANEG_STATE_AN_ENABLE: |
| 5200 |
ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); |
| 5201 |
if (ap->flags & MR_AN_ENABLE) { |
| 5202 |
ap->link_time = 0; |
| 5203 |
ap->cur_time = 0; |
| 5204 |
ap->ability_match_cfg = 0; |
| 5205 |
ap->ability_match_count = 0; |
| 5206 |
ap->ability_match = 0; |
| 5207 |
ap->idle_match = 0; |
| 5208 |
ap->ack_match = 0; |
| 5209 |
|
| 5210 |
ap->state = ANEG_STATE_RESTART_INIT; |
| 5211 |
} else { |
| 5212 |
ap->state = ANEG_STATE_DISABLE_LINK_OK; |
| 5213 |
} |
| 5214 |
break; |
| 5215 |
|
| 5216 |
case ANEG_STATE_RESTART_INIT: |
| 5217 |
ap->link_time = ap->cur_time; |
| 5218 |
ap->flags &= ~(MR_NP_LOADED); |
| 5219 |
ap->txconfig = 0; |
| 5220 |
tw32(MAC_TX_AUTO_NEG, 0); |
| 5221 |
tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 5222 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5223 |
udelay(40); |
| 5224 |
|
| 5225 |
ret = ANEG_TIMER_ENAB; |
| 5226 |
ap->state = ANEG_STATE_RESTART; |
| 5227 |
|
| 5228 |
fallthrough; |
| 5229 |
case ANEG_STATE_RESTART: |
| 5230 |
delta = ap->cur_time - ap->link_time; |
| 5231 |
if (delta > ANEG_STATE_SETTLE_TIME) |
| 5232 |
ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
| 5233 |
else |
| 5234 |
ret = ANEG_TIMER_ENAB; |
| 5235 |
break; |
| 5236 |
|
| 5237 |
case ANEG_STATE_DISABLE_LINK_OK: |
| 5238 |
ret = ANEG_DONE; |
| 5239 |
break; |
| 5240 |
|
| 5241 |
case ANEG_STATE_ABILITY_DETECT_INIT: |
| 5242 |
ap->flags &= ~(MR_TOGGLE_TX); |
| 5243 |
ap->txconfig = ANEG_CFG_FD; |
| 5244 |
flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 5245 |
if (flowctrl & ADVERTISE_1000XPAUSE) |
| 5246 |
ap->txconfig |= ANEG_CFG_PS1; |
| 5247 |
if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 5248 |
ap->txconfig |= ANEG_CFG_PS2; |
| 5249 |
tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 5250 |
tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 5251 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5252 |
udelay(40); |
| 5253 |
|
| 5254 |
ap->state = ANEG_STATE_ABILITY_DETECT; |
| 5255 |
break; |
| 5256 |
|
| 5257 |
case ANEG_STATE_ABILITY_DETECT: |
| 5258 |
if (ap->ability_match != 0 && ap->rxconfig != 0) |
| 5259 |
ap->state = ANEG_STATE_ACK_DETECT_INIT; |
| 5260 |
break; |
| 5261 |
|
| 5262 |
case ANEG_STATE_ACK_DETECT_INIT: |
| 5263 |
ap->txconfig |= ANEG_CFG_ACK; |
| 5264 |
tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
| 5265 |
tp->mac_mode |= MAC_MODE_SEND_CONFIGS; |
| 5266 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5267 |
udelay(40); |
| 5268 |
|
| 5269 |
ap->state = ANEG_STATE_ACK_DETECT; |
| 5270 |
|
| 5271 |
fallthrough; |
| 5272 |
case ANEG_STATE_ACK_DETECT: |
| 5273 |
if (ap->ack_match != 0) { |
| 5274 |
if ((ap->rxconfig & ~ANEG_CFG_ACK) == |
| 5275 |
(ap->ability_match_cfg & ~ANEG_CFG_ACK)) { |
| 5276 |
ap->state = ANEG_STATE_COMPLETE_ACK_INIT; |
| 5277 |
} else { |
| 5278 |
ap->state = ANEG_STATE_AN_ENABLE; |
| 5279 |
} |
| 5280 |
} else if (ap->ability_match != 0 && |
| 5281 |
ap->rxconfig == 0) { |
| 5282 |
ap->state = ANEG_STATE_AN_ENABLE; |
| 5283 |
} |
| 5284 |
break; |
| 5285 |
|
| 5286 |
case ANEG_STATE_COMPLETE_ACK_INIT: |
| 5287 |
if (ap->rxconfig & ANEG_CFG_INVAL) { |
| 5288 |
ret = ANEG_FAILED; |
| 5289 |
break; |
| 5290 |
} |
| 5291 |
ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | |
| 5292 |
MR_LP_ADV_HALF_DUPLEX | |
| 5293 |
MR_LP_ADV_SYM_PAUSE | |
| 5294 |
MR_LP_ADV_ASYM_PAUSE | |
| 5295 |
MR_LP_ADV_REMOTE_FAULT1 | |
| 5296 |
MR_LP_ADV_REMOTE_FAULT2 | |
| 5297 |
MR_LP_ADV_NEXT_PAGE | |
| 5298 |
MR_TOGGLE_RX | |
| 5299 |
MR_NP_RX); |
| 5300 |
if (ap->rxconfig & ANEG_CFG_FD) |
| 5301 |
ap->flags |= MR_LP_ADV_FULL_DUPLEX; |
| 5302 |
if (ap->rxconfig & ANEG_CFG_HD) |
| 5303 |
ap->flags |= MR_LP_ADV_HALF_DUPLEX; |
| 5304 |
if (ap->rxconfig & ANEG_CFG_PS1) |
| 5305 |
ap->flags |= MR_LP_ADV_SYM_PAUSE; |
| 5306 |
if (ap->rxconfig & ANEG_CFG_PS2) |
| 5307 |
ap->flags |= MR_LP_ADV_ASYM_PAUSE; |
| 5308 |
if (ap->rxconfig & ANEG_CFG_RF1) |
| 5309 |
ap->flags |= MR_LP_ADV_REMOTE_FAULT1; |
| 5310 |
if (ap->rxconfig & ANEG_CFG_RF2) |
| 5311 |
ap->flags |= MR_LP_ADV_REMOTE_FAULT2; |
| 5312 |
if (ap->rxconfig & ANEG_CFG_NP) |
| 5313 |
ap->flags |= MR_LP_ADV_NEXT_PAGE; |
| 5314 |
|
| 5315 |
ap->link_time = ap->cur_time; |
| 5316 |
|
| 5317 |
ap->flags ^= (MR_TOGGLE_TX); |
| 5318 |
if (ap->rxconfig & 0x0008) |
| 5319 |
ap->flags |= MR_TOGGLE_RX; |
| 5320 |
if (ap->rxconfig & ANEG_CFG_NP) |
| 5321 |
ap->flags |= MR_NP_RX; |
| 5322 |
ap->flags |= MR_PAGE_RX; |
| 5323 |
|
| 5324 |
ap->state = ANEG_STATE_COMPLETE_ACK; |
| 5325 |
ret = ANEG_TIMER_ENAB; |
| 5326 |
break; |
| 5327 |
|
| 5328 |
case ANEG_STATE_COMPLETE_ACK: |
| 5329 |
if (ap->ability_match != 0 && |
| 5330 |
ap->rxconfig == 0) { |
| 5331 |
ap->state = ANEG_STATE_AN_ENABLE; |
| 5332 |
break; |
| 5333 |
} |
| 5334 |
delta = ap->cur_time - ap->link_time; |
| 5335 |
if (delta > ANEG_STATE_SETTLE_TIME) { |
| 5336 |
if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { |
| 5337 |
ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 5338 |
} else { |
| 5339 |
if ((ap->txconfig & ANEG_CFG_NP) == 0 && |
| 5340 |
!(ap->flags & MR_NP_RX)) { |
| 5341 |
ap->state = ANEG_STATE_IDLE_DETECT_INIT; |
| 5342 |
} else { |
| 5343 |
ret = ANEG_FAILED; |
| 5344 |
} |
| 5345 |
} |
| 5346 |
} |
| 5347 |
break; |
| 5348 |
|
| 5349 |
case ANEG_STATE_IDLE_DETECT_INIT: |
| 5350 |
ap->link_time = ap->cur_time; |
| 5351 |
tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 5352 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5353 |
udelay(40); |
| 5354 |
|
| 5355 |
ap->state = ANEG_STATE_IDLE_DETECT; |
| 5356 |
ret = ANEG_TIMER_ENAB; |
| 5357 |
break; |
| 5358 |
|
| 5359 |
case ANEG_STATE_IDLE_DETECT: |
| 5360 |
if (ap->ability_match != 0 && |
| 5361 |
ap->rxconfig == 0) { |
| 5362 |
ap->state = ANEG_STATE_AN_ENABLE; |
| 5363 |
break; |
| 5364 |
} |
| 5365 |
delta = ap->cur_time - ap->link_time; |
| 5366 |
if (delta > ANEG_STATE_SETTLE_TIME) { |
| 5367 |
/* XXX another gem from the Broadcom driver :( */ |
| 5368 |
ap->state = ANEG_STATE_LINK_OK; |
| 5369 |
} |
| 5370 |
break; |
| 5371 |
|
| 5372 |
case ANEG_STATE_LINK_OK: |
| 5373 |
ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); |
| 5374 |
ret = ANEG_DONE; |
| 5375 |
break; |
| 5376 |
|
| 5377 |
case ANEG_STATE_NEXT_PAGE_WAIT_INIT: |
| 5378 |
/* ??? unimplemented */ |
| 5379 |
break; |
| 5380 |
|
| 5381 |
case ANEG_STATE_NEXT_PAGE_WAIT: |
| 5382 |
/* ??? unimplemented */ |
| 5383 |
break; |
| 5384 |
|
| 5385 |
default: |
| 5386 |
ret = ANEG_FAILED; |
| 5387 |
break; |
| 5388 |
} |
| 5389 |
|
| 5390 |
return ret; |
| 5391 |
} |
| 5392 |
|
| 5393 |
static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
| 5394 |
{ |
| 5395 |
int res = 0; |
| 5396 |
struct tg3_fiber_aneginfo aninfo; |
| 5397 |
int status = ANEG_FAILED; |
| 5398 |
unsigned int tick; |
| 5399 |
u32 tmp; |
| 5400 |
|
| 5401 |
tw32_f(MAC_TX_AUTO_NEG, 0); |
| 5402 |
|
| 5403 |
tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
| 5404 |
tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); |
| 5405 |
udelay(40); |
| 5406 |
|
| 5407 |
tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); |
| 5408 |
udelay(40); |
| 5409 |
|
| 5410 |
memset(&aninfo, 0, sizeof(aninfo)); |
| 5411 |
aninfo.flags |= MR_AN_ENABLE; |
| 5412 |
aninfo.state = ANEG_STATE_UNKNOWN; |
| 5413 |
aninfo.cur_time = 0; |
| 5414 |
tick = 0; |
| 5415 |
while (++tick < 195000) { |
| 5416 |
status = tg3_fiber_aneg_smachine(tp, &aninfo); |
| 5417 |
if (status == ANEG_DONE || status == ANEG_FAILED) |
| 5418 |
break; |
| 5419 |
|
| 5420 |
udelay(1); |
| 5421 |
} |
| 5422 |
|
| 5423 |
tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; |
| 5424 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5425 |
udelay(40); |
| 5426 |
|
| 5427 |
*txflags = aninfo.txconfig; |
| 5428 |
*rxflags = aninfo.flags; |
| 5429 |
|
| 5430 |
if (status == ANEG_DONE && |
| 5431 |
(aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | |
| 5432 |
MR_LP_ADV_FULL_DUPLEX))) |
| 5433 |
res = 1; |
| 5434 |
|
| 5435 |
return res; |
| 5436 |
} |
| 5437 |
|
| 5438 |
static void tg3_init_bcm8002(struct tg3 *tp) |
| 5439 |
{ |
| 5440 |
u32 mac_status = tr32(MAC_STATUS); |
| 5441 |
int i; |
| 5442 |
|
| 5443 |
/* Reset when initting first time or we have a link. */ |
| 5444 |
if (tg3_flag(tp, INIT_COMPLETE) && |
| 5445 |
!(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 5446 |
return; |
| 5447 |
|
| 5448 |
/* Set PLL lock range. */ |
| 5449 |
tg3_writephy(tp, 0x16, 0x8007); |
| 5450 |
|
| 5451 |
/* SW reset */ |
| 5452 |
tg3_writephy(tp, MII_BMCR, BMCR_RESET); |
| 5453 |
|
| 5454 |
/* Wait for reset to complete. */ |
| 5455 |
/* XXX schedule_timeout() ... */ |
| 5456 |
for (i = 0; i < 500; i++) |
| 5457 |
udelay(10); |
| 5458 |
|
| 5459 |
/* Config mode; select PMA/Ch 1 regs. */ |
| 5460 |
tg3_writephy(tp, 0x10, 0x8411); |
| 5461 |
|
| 5462 |
/* Enable auto-lock and comdet, select txclk for tx. */ |
| 5463 |
tg3_writephy(tp, 0x11, 0x0a10); |
| 5464 |
|
| 5465 |
tg3_writephy(tp, 0x18, 0x00a0); |
| 5466 |
tg3_writephy(tp, 0x16, 0x41ff); |
| 5467 |
|
| 5468 |
/* Assert and deassert POR. */ |
| 5469 |
tg3_writephy(tp, 0x13, 0x0400); |
| 5470 |
udelay(40); |
| 5471 |
tg3_writephy(tp, 0x13, 0x0000); |
| 5472 |
|
| 5473 |
tg3_writephy(tp, 0x11, 0x0a50); |
| 5474 |
udelay(40); |
| 5475 |
tg3_writephy(tp, 0x11, 0x0a10); |
| 5476 |
|
| 5477 |
/* Wait for signal to stabilize */ |
| 5478 |
/* XXX schedule_timeout() ... */ |
| 5479 |
for (i = 0; i < 15000; i++) |
| 5480 |
udelay(10); |
| 5481 |
|
| 5482 |
/* Deselect the channel register so we can read the PHYID |
| 5483 |
* later. |
| 5484 |
*/ |
| 5485 |
tg3_writephy(tp, 0x10, 0x8011); |
| 5486 |
} |
| 5487 |
|
| 5488 |
static bool tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
| 5489 |
{ |
| 5490 |
u16 flowctrl; |
| 5491 |
bool current_link_up; |
| 5492 |
u32 sg_dig_ctrl, sg_dig_status; |
| 5493 |
u32 serdes_cfg, expected_sg_dig_ctrl; |
| 5494 |
int workaround, port_a; |
| 5495 |
|
| 5496 |
serdes_cfg = 0; |
| 5497 |
workaround = 0; |
| 5498 |
port_a = 1; |
| 5499 |
current_link_up = false; |
| 5500 |
|
| 5501 |
if (tg3_chip_rev_id(tp) != CHIPREV_ID_5704_A0 && |
| 5502 |
tg3_chip_rev_id(tp) != CHIPREV_ID_5704_A1) { |
| 5503 |
workaround = 1; |
| 5504 |
if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 5505 |
port_a = 0; |
| 5506 |
|
| 5507 |
/* preserve bits 0-11,13,14 for signal pre-emphasis */ |
| 5508 |
/* preserve bits 20-23 for voltage regulator */ |
| 5509 |
serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; |
| 5510 |
} |
| 5511 |
|
| 5512 |
sg_dig_ctrl = tr32(SG_DIG_CTRL); |
| 5513 |
|
| 5514 |
if (tp->link_config.autoneg != AUTONEG_ENABLE) { |
| 5515 |
if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
| 5516 |
if (workaround) { |
| 5517 |
u32 val = serdes_cfg; |
| 5518 |
|
| 5519 |
if (port_a) |
| 5520 |
val |= 0xc010000; |
| 5521 |
else |
| 5522 |
val |= 0x4010000; |
| 5523 |
tw32_f(MAC_SERDES_CFG, val); |
| 5524 |
} |
| 5525 |
|
| 5526 |
tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
| 5527 |
} |
| 5528 |
if (mac_status & MAC_STATUS_PCS_SYNCED) { |
| 5529 |
tg3_setup_flow_control(tp, 0, 0); |
| 5530 |
current_link_up = true; |
| 5531 |
} |
| 5532 |
goto out; |
| 5533 |
} |
| 5534 |
|
| 5535 |
/* Want auto-negotiation. */ |
| 5536 |
expected_sg_dig_ctrl = SG_DIG_USING_HW_AUTONEG | SG_DIG_COMMON_SETUP; |
| 5537 |
|
| 5538 |
flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 5539 |
if (flowctrl & ADVERTISE_1000XPAUSE) |
| 5540 |
expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; |
| 5541 |
if (flowctrl & ADVERTISE_1000XPSE_ASYM) |
| 5542 |
expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; |
| 5543 |
|
| 5544 |
if (sg_dig_ctrl != expected_sg_dig_ctrl) { |
| 5545 |
if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
| 5546 |
tp->serdes_counter && |
| 5547 |
((mac_status & (MAC_STATUS_PCS_SYNCED | |
| 5548 |
MAC_STATUS_RCVD_CFG)) == |
| 5549 |
MAC_STATUS_PCS_SYNCED)) { |
| 5550 |
tp->serdes_counter--; |
| 5551 |
current_link_up = true; |
| 5552 |
goto out; |
| 5553 |
} |
| 5554 |
restart_autoneg: |
| 5555 |
if (workaround) |
| 5556 |
tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); |
| 5557 |
tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | SG_DIG_SOFT_RESET); |
| 5558 |
udelay(5); |
| 5559 |
tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); |
| 5560 |
|
| 5561 |
tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
| 5562 |
tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 5563 |
} else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
| 5564 |
MAC_STATUS_SIGNAL_DET)) { |
| 5565 |
sg_dig_status = tr32(SG_DIG_STATUS); |
| 5566 |
mac_status = tr32(MAC_STATUS); |
| 5567 |
|
| 5568 |
if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
| 5569 |
(mac_status & MAC_STATUS_PCS_SYNCED)) { |
| 5570 |
u32 local_adv = 0, remote_adv = 0; |
| 5571 |
|
| 5572 |
if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) |
| 5573 |
local_adv |= ADVERTISE_1000XPAUSE; |
| 5574 |
if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) |
| 5575 |
local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 5576 |
|
| 5577 |
if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
| 5578 |
remote_adv |= LPA_1000XPAUSE; |
| 5579 |
if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
| 5580 |
remote_adv |= LPA_1000XPAUSE_ASYM; |
| 5581 |
|
| 5582 |
tp->link_config.rmt_adv = |
| 5583 |
mii_adv_to_ethtool_adv_x(remote_adv); |
| 5584 |
|
| 5585 |
tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5586 |
current_link_up = true; |
| 5587 |
tp->serdes_counter = 0; |
| 5588 |
tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 5589 |
} else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
| 5590 |
if (tp->serdes_counter) |
| 5591 |
tp->serdes_counter--; |
| 5592 |
else { |
| 5593 |
if (workaround) { |
| 5594 |
u32 val = serdes_cfg; |
| 5595 |
|
| 5596 |
if (port_a) |
| 5597 |
val |= 0xc010000; |
| 5598 |
else |
| 5599 |
val |= 0x4010000; |
| 5600 |
|
| 5601 |
tw32_f(MAC_SERDES_CFG, val); |
| 5602 |
} |
| 5603 |
|
| 5604 |
tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
| 5605 |
udelay(40); |
| 5606 |
|
| 5607 |
/* Link parallel detection - link is up */ |
| 5608 |
/* only if we have PCS_SYNC and not */ |
| 5609 |
/* receiving config code words */ |
| 5610 |
mac_status = tr32(MAC_STATUS); |
| 5611 |
if ((mac_status & MAC_STATUS_PCS_SYNCED) && |
| 5612 |
!(mac_status & MAC_STATUS_RCVD_CFG)) { |
| 5613 |
tg3_setup_flow_control(tp, 0, 0); |
| 5614 |
current_link_up = true; |
| 5615 |
tp->phy_flags |= |
| 5616 |
TG3_PHYFLG_PARALLEL_DETECT; |
| 5617 |
tp->serdes_counter = |
| 5618 |
SERDES_PARALLEL_DET_TIMEOUT; |
| 5619 |
} else |
| 5620 |
goto restart_autoneg; |
| 5621 |
} |
| 5622 |
} |
| 5623 |
} else { |
| 5624 |
tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
| 5625 |
tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 5626 |
} |
| 5627 |
|
| 5628 |
out: |
| 5629 |
return current_link_up; |
| 5630 |
} |
| 5631 |
|
| 5632 |
static bool tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
| 5633 |
{ |
| 5634 |
bool current_link_up = false; |
| 5635 |
|
| 5636 |
if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
| 5637 |
goto out; |
| 5638 |
|
| 5639 |
if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 5640 |
u32 txflags, rxflags; |
| 5641 |
int i; |
| 5642 |
|
| 5643 |
if (fiber_autoneg(tp, &txflags, &rxflags)) { |
| 5644 |
u32 local_adv = 0, remote_adv = 0; |
| 5645 |
|
| 5646 |
if (txflags & ANEG_CFG_PS1) |
| 5647 |
local_adv |= ADVERTISE_1000XPAUSE; |
| 5648 |
if (txflags & ANEG_CFG_PS2) |
| 5649 |
local_adv |= ADVERTISE_1000XPSE_ASYM; |
| 5650 |
|
| 5651 |
if (rxflags & MR_LP_ADV_SYM_PAUSE) |
| 5652 |
remote_adv |= LPA_1000XPAUSE; |
| 5653 |
if (rxflags & MR_LP_ADV_ASYM_PAUSE) |
| 5654 |
remote_adv |= LPA_1000XPAUSE_ASYM; |
| 5655 |
|
| 5656 |
tp->link_config.rmt_adv = |
| 5657 |
mii_adv_to_ethtool_adv_x(remote_adv); |
| 5658 |
|
| 5659 |
tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5660 |
|
| 5661 |
current_link_up = true; |
| 5662 |
} |
| 5663 |
for (i = 0; i < 30; i++) { |
| 5664 |
udelay(20); |
| 5665 |
tw32_f(MAC_STATUS, |
| 5666 |
(MAC_STATUS_SYNC_CHANGED | |
| 5667 |
MAC_STATUS_CFG_CHANGED)); |
| 5668 |
udelay(40); |
| 5669 |
if ((tr32(MAC_STATUS) & |
| 5670 |
(MAC_STATUS_SYNC_CHANGED | |
| 5671 |
MAC_STATUS_CFG_CHANGED)) == 0) |
| 5672 |
break; |
| 5673 |
} |
| 5674 |
|
| 5675 |
mac_status = tr32(MAC_STATUS); |
| 5676 |
if (!current_link_up && |
| 5677 |
(mac_status & MAC_STATUS_PCS_SYNCED) && |
| 5678 |
!(mac_status & MAC_STATUS_RCVD_CFG)) |
| 5679 |
current_link_up = true; |
| 5680 |
} else { |
| 5681 |
tg3_setup_flow_control(tp, 0, 0); |
| 5682 |
|
| 5683 |
/* Forcing 1000FD link up. */ |
| 5684 |
current_link_up = true; |
| 5685 |
|
| 5686 |
tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); |
| 5687 |
udelay(40); |
| 5688 |
|
| 5689 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5690 |
udelay(40); |
| 5691 |
} |
| 5692 |
|
| 5693 |
out: |
| 5694 |
return current_link_up; |
| 5695 |
} |
| 5696 |
|
| 5697 |
static int tg3_setup_fiber_phy(struct tg3 *tp, bool force_reset) |
| 5698 |
{ |
| 5699 |
u32 orig_pause_cfg; |
| 5700 |
u32 orig_active_speed; |
| 5701 |
u8 orig_active_duplex; |
| 5702 |
u32 mac_status; |
| 5703 |
bool current_link_up; |
| 5704 |
int i; |
| 5705 |
|
| 5706 |
orig_pause_cfg = tp->link_config.active_flowctrl; |
| 5707 |
orig_active_speed = tp->link_config.active_speed; |
| 5708 |
orig_active_duplex = tp->link_config.active_duplex; |
| 5709 |
|
| 5710 |
if (!tg3_flag(tp, HW_AUTONEG) && |
| 5711 |
tp->link_up && |
| 5712 |
tg3_flag(tp, INIT_COMPLETE)) { |
| 5713 |
mac_status = tr32(MAC_STATUS); |
| 5714 |
mac_status &= (MAC_STATUS_PCS_SYNCED | |
| 5715 |
MAC_STATUS_SIGNAL_DET | |
| 5716 |
MAC_STATUS_CFG_CHANGED | |
| 5717 |
MAC_STATUS_RCVD_CFG); |
| 5718 |
if (mac_status == (MAC_STATUS_PCS_SYNCED | |
| 5719 |
MAC_STATUS_SIGNAL_DET)) { |
| 5720 |
tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5721 |
MAC_STATUS_CFG_CHANGED)); |
| 5722 |
return 0; |
| 5723 |
} |
| 5724 |
} |
| 5725 |
|
| 5726 |
tw32_f(MAC_TX_AUTO_NEG, 0); |
| 5727 |
|
| 5728 |
tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 5729 |
tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
| 5730 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5731 |
udelay(40); |
| 5732 |
|
| 5733 |
if (tp->phy_id == TG3_PHY_ID_BCM8002) |
| 5734 |
tg3_init_bcm8002(tp); |
| 5735 |
|
| 5736 |
/* Enable link change event even when serdes polling. */ |
| 5737 |
tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5738 |
udelay(40); |
| 5739 |
|
| 5740 |
tp->link_config.rmt_adv = 0; |
| 5741 |
mac_status = tr32(MAC_STATUS); |
| 5742 |
|
| 5743 |
if (tg3_flag(tp, HW_AUTONEG)) |
| 5744 |
current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
| 5745 |
else |
| 5746 |
current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); |
| 5747 |
|
| 5748 |
tp->napi[0].hw_status->status = |
| 5749 |
(SD_STATUS_UPDATED | |
| 5750 |
(tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
| 5751 |
|
| 5752 |
for (i = 0; i < 100; i++) { |
| 5753 |
tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | |
| 5754 |
MAC_STATUS_CFG_CHANGED)); |
| 5755 |
udelay(5); |
| 5756 |
if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | |
| 5757 |
MAC_STATUS_CFG_CHANGED | |
| 5758 |
MAC_STATUS_LNKSTATE_CHANGED)) == 0) |
| 5759 |
break; |
| 5760 |
} |
| 5761 |
|
| 5762 |
mac_status = tr32(MAC_STATUS); |
| 5763 |
if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { |
| 5764 |
current_link_up = false; |
| 5765 |
if (tp->link_config.autoneg == AUTONEG_ENABLE && |
| 5766 |
tp->serdes_counter == 0) { |
| 5767 |
tw32_f(MAC_MODE, (tp->mac_mode | |
| 5768 |
MAC_MODE_SEND_CONFIGS)); |
| 5769 |
udelay(1); |
| 5770 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5771 |
} |
| 5772 |
} |
| 5773 |
|
| 5774 |
if (current_link_up) { |
| 5775 |
tp->link_config.active_speed = SPEED_1000; |
| 5776 |
tp->link_config.active_duplex = DUPLEX_FULL; |
| 5777 |
tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5778 |
LED_CTRL_LNKLED_OVERRIDE | |
| 5779 |
LED_CTRL_1000MBPS_ON)); |
| 5780 |
} else { |
| 5781 |
tp->link_config.active_speed = SPEED_UNKNOWN; |
| 5782 |
tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
| 5783 |
tw32(MAC_LED_CTRL, (tp->led_ctrl | |
| 5784 |
LED_CTRL_LNKLED_OVERRIDE | |
| 5785 |
LED_CTRL_TRAFFIC_OVERRIDE)); |
| 5786 |
} |
| 5787 |
|
| 5788 |
if (!tg3_test_and_report_link_chg(tp, current_link_up)) { |
| 5789 |
u32 now_pause_cfg = tp->link_config.active_flowctrl; |
| 5790 |
if (orig_pause_cfg != now_pause_cfg || |
| 5791 |
orig_active_speed != tp->link_config.active_speed || |
| 5792 |
orig_active_duplex != tp->link_config.active_duplex) |
| 5793 |
tg3_link_report(tp); |
| 5794 |
} |
| 5795 |
|
| 5796 |
return 0; |
| 5797 |
} |
| 5798 |
|
| 5799 |
static int tg3_setup_fiber_mii_phy(struct tg3 *tp, bool force_reset) |
| 5800 |
{ |
| 5801 |
int err = 0; |
| 5802 |
u32 bmsr, bmcr; |
| 5803 |
u32 current_speed = SPEED_UNKNOWN; |
| 5804 |
u8 current_duplex = DUPLEX_UNKNOWN; |
| 5805 |
bool current_link_up = false; |
| 5806 |
u32 local_adv = 0, remote_adv = 0, sgsr; |
| 5807 |
|
| 5808 |
if ((tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 5809 |
tg3_asic_rev(tp) == ASIC_REV_5720) && |
| 5810 |
!tg3_readphy(tp, SERDES_TG3_1000X_STATUS, &sgsr) && |
| 5811 |
(sgsr & SERDES_TG3_SGMII_MODE)) { |
| 5812 |
|
| 5813 |
if (force_reset) |
| 5814 |
tg3_phy_reset(tp); |
| 5815 |
|
| 5816 |
tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; |
| 5817 |
|
| 5818 |
if (!(sgsr & SERDES_TG3_LINK_UP)) { |
| 5819 |
tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 5820 |
} else { |
| 5821 |
current_link_up = true; |
| 5822 |
if (sgsr & SERDES_TG3_SPEED_1000) { |
| 5823 |
current_speed = SPEED_1000; |
| 5824 |
tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 5825 |
} else if (sgsr & SERDES_TG3_SPEED_100) { |
| 5826 |
current_speed = SPEED_100; |
| 5827 |
tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 5828 |
} else { |
| 5829 |
current_speed = SPEED_10; |
| 5830 |
tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 5831 |
} |
| 5832 |
|
| 5833 |
if (sgsr & SERDES_TG3_FULL_DUPLEX) |
| 5834 |
current_duplex = DUPLEX_FULL; |
| 5835 |
else |
| 5836 |
current_duplex = DUPLEX_HALF; |
| 5837 |
} |
| 5838 |
|
| 5839 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5840 |
udelay(40); |
| 5841 |
|
| 5842 |
tg3_clear_mac_status(tp); |
| 5843 |
|
| 5844 |
goto fiber_setup_done; |
| 5845 |
} |
| 5846 |
|
| 5847 |
tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 5848 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5849 |
udelay(40); |
| 5850 |
|
| 5851 |
tg3_clear_mac_status(tp); |
| 5852 |
|
| 5853 |
if (force_reset) |
| 5854 |
tg3_phy_reset(tp); |
| 5855 |
|
| 5856 |
tp->link_config.rmt_adv = 0; |
| 5857 |
|
| 5858 |
err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5859 |
err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5860 |
if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
| 5861 |
if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5862 |
bmsr |= BMSR_LSTATUS; |
| 5863 |
else |
| 5864 |
bmsr &= ~BMSR_LSTATUS; |
| 5865 |
} |
| 5866 |
|
| 5867 |
err |= tg3_readphy(tp, MII_BMCR, &bmcr); |
| 5868 |
|
| 5869 |
if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && |
| 5870 |
(tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
| 5871 |
/* do nothing, just check for link up at the end */ |
| 5872 |
} else if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
| 5873 |
u32 adv, newadv; |
| 5874 |
|
| 5875 |
err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 5876 |
newadv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
| 5877 |
ADVERTISE_1000XPAUSE | |
| 5878 |
ADVERTISE_1000XPSE_ASYM | |
| 5879 |
ADVERTISE_SLCT); |
| 5880 |
|
| 5881 |
newadv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
| 5882 |
newadv |= ethtool_adv_to_mii_adv_x(tp->link_config.advertising); |
| 5883 |
|
| 5884 |
if ((newadv != adv) || !(bmcr & BMCR_ANENABLE)) { |
| 5885 |
tg3_writephy(tp, MII_ADVERTISE, newadv); |
| 5886 |
bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
| 5887 |
tg3_writephy(tp, MII_BMCR, bmcr); |
| 5888 |
|
| 5889 |
tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5890 |
tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
| 5891 |
tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 5892 |
|
| 5893 |
return err; |
| 5894 |
} |
| 5895 |
} else { |
| 5896 |
u32 new_bmcr; |
| 5897 |
|
| 5898 |
bmcr &= ~BMCR_SPEED1000; |
| 5899 |
new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); |
| 5900 |
|
| 5901 |
if (tp->link_config.duplex == DUPLEX_FULL) |
| 5902 |
new_bmcr |= BMCR_FULLDPLX; |
| 5903 |
|
| 5904 |
if (new_bmcr != bmcr) { |
| 5905 |
/* BMCR_SPEED1000 is a reserved bit that needs |
| 5906 |
* to be set on write. |
| 5907 |
*/ |
| 5908 |
new_bmcr |= BMCR_SPEED1000; |
| 5909 |
|
| 5910 |
/* Force a linkdown */ |
| 5911 |
if (tp->link_up) { |
| 5912 |
u32 adv; |
| 5913 |
|
| 5914 |
err |= tg3_readphy(tp, MII_ADVERTISE, &adv); |
| 5915 |
adv &= ~(ADVERTISE_1000XFULL | |
| 5916 |
ADVERTISE_1000XHALF | |
| 5917 |
ADVERTISE_SLCT); |
| 5918 |
tg3_writephy(tp, MII_ADVERTISE, adv); |
| 5919 |
tg3_writephy(tp, MII_BMCR, bmcr | |
| 5920 |
BMCR_ANRESTART | |
| 5921 |
BMCR_ANENABLE); |
| 5922 |
udelay(10); |
| 5923 |
tg3_carrier_off(tp); |
| 5924 |
} |
| 5925 |
tg3_writephy(tp, MII_BMCR, new_bmcr); |
| 5926 |
bmcr = new_bmcr; |
| 5927 |
err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5928 |
err |= tg3_readphy(tp, MII_BMSR, &bmsr); |
| 5929 |
if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
| 5930 |
if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 5931 |
bmsr |= BMSR_LSTATUS; |
| 5932 |
else |
| 5933 |
bmsr &= ~BMSR_LSTATUS; |
| 5934 |
} |
| 5935 |
tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 5936 |
} |
| 5937 |
} |
| 5938 |
|
| 5939 |
if (bmsr & BMSR_LSTATUS) { |
| 5940 |
current_speed = SPEED_1000; |
| 5941 |
current_link_up = true; |
| 5942 |
if (bmcr & BMCR_FULLDPLX) |
| 5943 |
current_duplex = DUPLEX_FULL; |
| 5944 |
else |
| 5945 |
current_duplex = DUPLEX_HALF; |
| 5946 |
|
| 5947 |
if (bmcr & BMCR_ANENABLE) { |
| 5948 |
u32 common; |
| 5949 |
|
| 5950 |
err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); |
| 5951 |
err |= tg3_readphy(tp, MII_LPA, &remote_adv); |
| 5952 |
common = local_adv & remote_adv; |
| 5953 |
if (common & (ADVERTISE_1000XHALF | |
| 5954 |
ADVERTISE_1000XFULL)) { |
| 5955 |
if (common & ADVERTISE_1000XFULL) |
| 5956 |
current_duplex = DUPLEX_FULL; |
| 5957 |
else |
| 5958 |
current_duplex = DUPLEX_HALF; |
| 5959 |
|
| 5960 |
tp->link_config.rmt_adv = |
| 5961 |
mii_adv_to_ethtool_adv_x(remote_adv); |
| 5962 |
} else if (!tg3_flag(tp, 5780_CLASS)) { |
| 5963 |
/* Link is up via parallel detect */ |
| 5964 |
} else { |
| 5965 |
current_link_up = false; |
| 5966 |
} |
| 5967 |
} |
| 5968 |
} |
| 5969 |
|
| 5970 |
fiber_setup_done: |
| 5971 |
if (current_link_up && current_duplex == DUPLEX_FULL) |
| 5972 |
tg3_setup_flow_control(tp, local_adv, remote_adv); |
| 5973 |
|
| 5974 |
tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
| 5975 |
if (tp->link_config.active_duplex == DUPLEX_HALF) |
| 5976 |
tp->mac_mode |= MAC_MODE_HALF_DUPLEX; |
| 5977 |
|
| 5978 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 5979 |
udelay(40); |
| 5980 |
|
| 5981 |
tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); |
| 5982 |
|
| 5983 |
tp->link_config.active_speed = current_speed; |
| 5984 |
tp->link_config.active_duplex = current_duplex; |
| 5985 |
|
| 5986 |
tg3_test_and_report_link_chg(tp, current_link_up); |
| 5987 |
return err; |
| 5988 |
} |
| 5989 |
|
| 5990 |
static void tg3_serdes_parallel_detect(struct tg3 *tp) |
| 5991 |
{ |
| 5992 |
if (tp->serdes_counter) { |
| 5993 |
/* Give autoneg time to complete. */ |
| 5994 |
tp->serdes_counter--; |
| 5995 |
return; |
| 5996 |
} |
| 5997 |
|
| 5998 |
if (!tp->link_up && |
| 5999 |
(tp->link_config.autoneg == AUTONEG_ENABLE)) { |
| 6000 |
u32 bmcr; |
| 6001 |
|
| 6002 |
tg3_readphy(tp, MII_BMCR, &bmcr); |
| 6003 |
if (bmcr & BMCR_ANENABLE) { |
| 6004 |
u32 phy1, phy2; |
| 6005 |
|
| 6006 |
/* Select shadow register 0x1f */ |
| 6007 |
tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
| 6008 |
tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); |
| 6009 |
|
| 6010 |
/* Select expansion interrupt status register */ |
| 6011 |
tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 6012 |
MII_TG3_DSP_EXP1_INT_STAT); |
| 6013 |
tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 6014 |
tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 6015 |
|
| 6016 |
if ((phy1 & 0x10) && !(phy2 & 0x20)) { |
| 6017 |
/* We have signal detect and not receiving |
| 6018 |
* config code words, link is up by parallel |
| 6019 |
* detection. |
| 6020 |
*/ |
| 6021 |
|
| 6022 |
bmcr &= ~BMCR_ANENABLE; |
| 6023 |
bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; |
| 6024 |
tg3_writephy(tp, MII_BMCR, bmcr); |
| 6025 |
tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
| 6026 |
} |
| 6027 |
} |
| 6028 |
} else if (tp->link_up && |
| 6029 |
(tp->link_config.autoneg == AUTONEG_ENABLE) && |
| 6030 |
(tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
| 6031 |
u32 phy2; |
| 6032 |
|
| 6033 |
/* Select expansion interrupt status register */ |
| 6034 |
tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
| 6035 |
MII_TG3_DSP_EXP1_INT_STAT); |
| 6036 |
tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); |
| 6037 |
if (phy2 & 0x20) { |
| 6038 |
u32 bmcr; |
| 6039 |
|
| 6040 |
/* Config code words received, turn on autoneg. */ |
| 6041 |
tg3_readphy(tp, MII_BMCR, &bmcr); |
| 6042 |
tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); |
| 6043 |
|
| 6044 |
tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 6045 |
|
| 6046 |
} |
| 6047 |
} |
| 6048 |
} |
| 6049 |
|
| 6050 |
static int tg3_setup_phy(struct tg3 *tp, bool force_reset) |
| 6051 |
{ |
| 6052 |
u32 val; |
| 6053 |
int err; |
| 6054 |
|
| 6055 |
if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
| 6056 |
err = tg3_setup_fiber_phy(tp, force_reset); |
| 6057 |
else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
| 6058 |
err = tg3_setup_fiber_mii_phy(tp, force_reset); |
| 6059 |
else |
| 6060 |
err = tg3_setup_copper_phy(tp, force_reset); |
| 6061 |
|
| 6062 |
if (tg3_chip_rev(tp) == CHIPREV_5784_AX) { |
| 6063 |
u32 scale; |
| 6064 |
|
| 6065 |
val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; |
| 6066 |
if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) |
| 6067 |
scale = 65; |
| 6068 |
else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) |
| 6069 |
scale = 6; |
| 6070 |
else |
| 6071 |
scale = 12; |
| 6072 |
|
| 6073 |
val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; |
| 6074 |
val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 6075 |
tw32(GRC_MISC_CFG, val); |
| 6076 |
} |
| 6077 |
|
| 6078 |
val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 6079 |
(6 << TX_LENGTHS_IPG_SHIFT); |
| 6080 |
if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 6081 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 6082 |
val |= tr32(MAC_TX_LENGTHS) & |
| 6083 |
(TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 6084 |
TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 6085 |
|
| 6086 |
if (tp->link_config.active_speed == SPEED_1000 && |
| 6087 |
tp->link_config.active_duplex == DUPLEX_HALF) |
| 6088 |
tw32(MAC_TX_LENGTHS, val | |
| 6089 |
(0xff << TX_LENGTHS_SLOT_TIME_SHIFT)); |
| 6090 |
else |
| 6091 |
tw32(MAC_TX_LENGTHS, val | |
| 6092 |
(32 << TX_LENGTHS_SLOT_TIME_SHIFT)); |
| 6093 |
|
| 6094 |
if (!tg3_flag(tp, 5705_PLUS)) { |
| 6095 |
if (tp->link_up) { |
| 6096 |
tw32(HOSTCC_STAT_COAL_TICKS, |
| 6097 |
tp->coal.stats_block_coalesce_usecs); |
| 6098 |
} else { |
| 6099 |
tw32(HOSTCC_STAT_COAL_TICKS, 0); |
| 6100 |
} |
| 6101 |
} |
| 6102 |
|
| 6103 |
if (tg3_flag(tp, ASPM_WORKAROUND)) { |
| 6104 |
val = tr32(PCIE_PWR_MGMT_THRESH); |
| 6105 |
if (!tp->link_up) |
| 6106 |
val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
| 6107 |
tp->pwrmgmt_thresh; |
| 6108 |
else |
| 6109 |
val |= PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 6110 |
tw32(PCIE_PWR_MGMT_THRESH, val); |
| 6111 |
} |
| 6112 |
|
| 6113 |
return err; |
| 6114 |
} |
| 6115 |
|
| 6116 |
/* tp->lock must be held */ |
| 6117 |
static u64 tg3_refclk_read(struct tg3 *tp, struct ptp_system_timestamp *sts) |
| 6118 |
{ |
| 6119 |
u64 stamp; |
| 6120 |
|
| 6121 |
ptp_read_system_prets(sts); |
| 6122 |
stamp = tr32(TG3_EAV_REF_CLCK_LSB); |
| 6123 |
ptp_read_system_postts(sts); |
| 6124 |
stamp |= (u64)tr32(TG3_EAV_REF_CLCK_MSB) << 32; |
| 6125 |
|
| 6126 |
return stamp; |
| 6127 |
} |
| 6128 |
|
| 6129 |
/* tp->lock must be held */ |
| 6130 |
static void tg3_refclk_write(struct tg3 *tp, u64 newval) |
| 6131 |
{ |
| 6132 |
u32 clock_ctl = tr32(TG3_EAV_REF_CLCK_CTL); |
| 6133 |
|
| 6134 |
tw32(TG3_EAV_REF_CLCK_CTL, clock_ctl | TG3_EAV_REF_CLCK_CTL_STOP); |
| 6135 |
tw32(TG3_EAV_REF_CLCK_LSB, newval & 0xffffffff); |
| 6136 |
tw32(TG3_EAV_REF_CLCK_MSB, newval >> 32); |
| 6137 |
tw32_f(TG3_EAV_REF_CLCK_CTL, clock_ctl | TG3_EAV_REF_CLCK_CTL_RESUME); |
| 6138 |
} |
| 6139 |
|
| 6140 |
static inline void tg3_full_lock(struct tg3 *tp, int irq_sync); |
| 6141 |
static inline void tg3_full_unlock(struct tg3 *tp); |
| 6142 |
static int tg3_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info) |
| 6143 |
{ |
| 6144 |
struct tg3 *tp = netdev_priv(dev); |
| 6145 |
|
| 6146 |
info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE; |
| 6147 |
|
| 6148 |
if (tg3_flag(tp, PTP_CAPABLE)) { |
| 6149 |
info->so_timestamping |= SOF_TIMESTAMPING_TX_HARDWARE | |
| 6150 |
SOF_TIMESTAMPING_RX_HARDWARE | |
| 6151 |
SOF_TIMESTAMPING_RAW_HARDWARE; |
| 6152 |
} |
| 6153 |
|
| 6154 |
if (tp->ptp_clock) |
| 6155 |
info->phc_index = ptp_clock_index(tp->ptp_clock); |
| 6156 |
|
| 6157 |
info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); |
| 6158 |
|
| 6159 |
info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | |
| 6160 |
(1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) | |
| 6161 |
(1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | |
| 6162 |
(1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT); |
| 6163 |
return 0; |
| 6164 |
} |
| 6165 |
|
| 6166 |
static int tg3_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) |
| 6167 |
{ |
| 6168 |
struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 6169 |
u64 correction; |
| 6170 |
bool neg_adj; |
| 6171 |
|
| 6172 |
/* Frequency adjustment is performed using hardware with a 24 bit |
| 6173 |
* accumulator and a programmable correction value. On each clk, the |
| 6174 |
* correction value gets added to the accumulator and when it |
| 6175 |
* overflows, the time counter is incremented/decremented. |
| 6176 |
*/ |
| 6177 |
neg_adj = diff_by_scaled_ppm(1 << 24, scaled_ppm, &correction); |
| 6178 |
|
| 6179 |
tg3_full_lock(tp, 0); |
| 6180 |
|
| 6181 |
if (correction) |
| 6182 |
tw32(TG3_EAV_REF_CLK_CORRECT_CTL, |
| 6183 |
TG3_EAV_REF_CLK_CORRECT_EN | |
| 6184 |
(neg_adj ? TG3_EAV_REF_CLK_CORRECT_NEG : 0) | |
| 6185 |
((u32)correction & TG3_EAV_REF_CLK_CORRECT_MASK)); |
| 6186 |
else |
| 6187 |
tw32(TG3_EAV_REF_CLK_CORRECT_CTL, 0); |
| 6188 |
|
| 6189 |
tg3_full_unlock(tp); |
| 6190 |
|
| 6191 |
return 0; |
| 6192 |
} |
| 6193 |
|
| 6194 |
static int tg3_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) |
| 6195 |
{ |
| 6196 |
struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 6197 |
|
| 6198 |
tg3_full_lock(tp, 0); |
| 6199 |
tp->ptp_adjust += delta; |
| 6200 |
tg3_full_unlock(tp); |
| 6201 |
|
| 6202 |
return 0; |
| 6203 |
} |
| 6204 |
|
| 6205 |
static int tg3_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts, |
| 6206 |
struct ptp_system_timestamp *sts) |
| 6207 |
{ |
| 6208 |
u64 ns; |
| 6209 |
struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 6210 |
|
| 6211 |
tg3_full_lock(tp, 0); |
| 6212 |
ns = tg3_refclk_read(tp, sts); |
| 6213 |
ns += tp->ptp_adjust; |
| 6214 |
tg3_full_unlock(tp); |
| 6215 |
|
| 6216 |
*ts = ns_to_timespec64(ns); |
| 6217 |
|
| 6218 |
return 0; |
| 6219 |
} |
| 6220 |
|
| 6221 |
static int tg3_ptp_settime(struct ptp_clock_info *ptp, |
| 6222 |
const struct timespec64 *ts) |
| 6223 |
{ |
| 6224 |
u64 ns; |
| 6225 |
struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 6226 |
|
| 6227 |
ns = timespec64_to_ns(ts); |
| 6228 |
|
| 6229 |
tg3_full_lock(tp, 0); |
| 6230 |
tg3_refclk_write(tp, ns); |
| 6231 |
tp->ptp_adjust = 0; |
| 6232 |
tg3_full_unlock(tp); |
| 6233 |
|
| 6234 |
return 0; |
| 6235 |
} |
| 6236 |
|
| 6237 |
static int tg3_ptp_enable(struct ptp_clock_info *ptp, |
| 6238 |
struct ptp_clock_request *rq, int on) |
| 6239 |
{ |
| 6240 |
struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 6241 |
u32 clock_ctl; |
| 6242 |
int rval = 0; |
| 6243 |
|
| 6244 |
switch (rq->type) { |
| 6245 |
case PTP_CLK_REQ_PEROUT: |
| 6246 |
/* Reject requests with unsupported flags */ |
| 6247 |
if (rq->perout.flags) |
| 6248 |
return -EOPNOTSUPP; |
| 6249 |
|
| 6250 |
if (rq->perout.index != 0) |
| 6251 |
return -EINVAL; |
| 6252 |
|
| 6253 |
tg3_full_lock(tp, 0); |
| 6254 |
clock_ctl = tr32(TG3_EAV_REF_CLCK_CTL); |
| 6255 |
clock_ctl &= ~TG3_EAV_CTL_TSYNC_GPIO_MASK; |
| 6256 |
|
| 6257 |
if (on) { |
| 6258 |
u64 nsec; |
| 6259 |
|
| 6260 |
nsec = rq->perout.start.sec * 1000000000ULL + |
| 6261 |
rq->perout.start.nsec; |
| 6262 |
|
| 6263 |
if (rq->perout.period.sec || rq->perout.period.nsec) { |
| 6264 |
netdev_warn(tp->dev, |
| 6265 |
"Device supports only a one-shot timesync output, period must be 0\n"); |
| 6266 |
rval = -EINVAL; |
| 6267 |
goto err_out; |
| 6268 |
} |
| 6269 |
|
| 6270 |
if (nsec & (1ULL << 63)) { |
| 6271 |
netdev_warn(tp->dev, |
| 6272 |
"Start value (nsec) is over limit. Maximum size of start is only 63 bits\n"); |
| 6273 |
rval = -EINVAL; |
| 6274 |
goto err_out; |
| 6275 |
} |
| 6276 |
|
| 6277 |
tw32(TG3_EAV_WATCHDOG0_LSB, (nsec & 0xffffffff)); |
| 6278 |
tw32(TG3_EAV_WATCHDOG0_MSB, |
| 6279 |
TG3_EAV_WATCHDOG0_EN | |
| 6280 |
((nsec >> 32) & TG3_EAV_WATCHDOG_MSB_MASK)); |
| 6281 |
|
| 6282 |
tw32(TG3_EAV_REF_CLCK_CTL, |
| 6283 |
clock_ctl | TG3_EAV_CTL_TSYNC_WDOG0); |
| 6284 |
} else { |
| 6285 |
tw32(TG3_EAV_WATCHDOG0_MSB, 0); |
| 6286 |
tw32(TG3_EAV_REF_CLCK_CTL, clock_ctl); |
| 6287 |
} |
| 6288 |
|
| 6289 |
err_out: |
| 6290 |
tg3_full_unlock(tp); |
| 6291 |
return rval; |
| 6292 |
|
| 6293 |
default: |
| 6294 |
break; |
| 6295 |
} |
| 6296 |
|
| 6297 |
return -EOPNOTSUPP; |
| 6298 |
} |
| 6299 |
|
| 6300 |
static void tg3_hwclock_to_timestamp(struct tg3 *tp, u64 hwclock, |
| 6301 |
struct skb_shared_hwtstamps *timestamp) |
| 6302 |
{ |
| 6303 |
memset(timestamp, 0, sizeof(struct skb_shared_hwtstamps)); |
| 6304 |
timestamp->hwtstamp = ns_to_ktime((hwclock & TG3_TSTAMP_MASK) + |
| 6305 |
tp->ptp_adjust); |
| 6306 |
} |
| 6307 |
|
| 6308 |
static void tg3_read_tx_tstamp(struct tg3 *tp, u64 *hwclock) |
| 6309 |
{ |
| 6310 |
*hwclock = tr32(TG3_TX_TSTAMP_LSB); |
| 6311 |
*hwclock |= (u64)tr32(TG3_TX_TSTAMP_MSB) << 32; |
| 6312 |
} |
| 6313 |
|
| 6314 |
static long tg3_ptp_ts_aux_work(struct ptp_clock_info *ptp) |
| 6315 |
{ |
| 6316 |
struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); |
| 6317 |
struct skb_shared_hwtstamps timestamp; |
| 6318 |
u64 hwclock; |
| 6319 |
|
| 6320 |
if (tp->ptp_txts_retrycnt > 2) |
| 6321 |
goto done; |
| 6322 |
|
| 6323 |
tg3_read_tx_tstamp(tp, &hwclock); |
| 6324 |
|
| 6325 |
if (hwclock != tp->pre_tx_ts) { |
| 6326 |
tg3_hwclock_to_timestamp(tp, hwclock, ×tamp); |
| 6327 |
skb_tstamp_tx(tp->tx_tstamp_skb, ×tamp); |
| 6328 |
goto done; |
| 6329 |
} |
| 6330 |
tp->ptp_txts_retrycnt++; |
| 6331 |
return HZ / 10; |
| 6332 |
done: |
| 6333 |
dev_consume_skb_any(tp->tx_tstamp_skb); |
| 6334 |
tp->tx_tstamp_skb = NULL; |
| 6335 |
tp->ptp_txts_retrycnt = 0; |
| 6336 |
tp->pre_tx_ts = 0; |
| 6337 |
return -1; |
| 6338 |
} |
| 6339 |
|
| 6340 |
static const struct ptp_clock_info tg3_ptp_caps = { |
| 6341 |
.owner = THIS_MODULE, |
| 6342 |
.name = "tg3 clock", |
| 6343 |
.max_adj = 250000000, |
| 6344 |
.n_alarm = 0, |
| 6345 |
.n_ext_ts = 0, |
| 6346 |
.n_per_out = 1, |
| 6347 |
.n_pins = 0, |
| 6348 |
.pps = 0, |
| 6349 |
.adjfine = tg3_ptp_adjfine, |
| 6350 |
.adjtime = tg3_ptp_adjtime, |
| 6351 |
.do_aux_work = tg3_ptp_ts_aux_work, |
| 6352 |
.gettimex64 = tg3_ptp_gettimex, |
| 6353 |
.settime64 = tg3_ptp_settime, |
| 6354 |
.enable = tg3_ptp_enable, |
| 6355 |
}; |
| 6356 |
|
| 6357 |
/* tp->lock must be held */ |
| 6358 |
static void tg3_ptp_init(struct tg3 *tp) |
| 6359 |
{ |
| 6360 |
if (!tg3_flag(tp, PTP_CAPABLE)) |
| 6361 |
return; |
| 6362 |
|
| 6363 |
/* Initialize the hardware clock to the system time. */ |
| 6364 |
tg3_refclk_write(tp, ktime_to_ns(ktime_get_real())); |
| 6365 |
tp->ptp_adjust = 0; |
| 6366 |
tp->ptp_info = tg3_ptp_caps; |
| 6367 |
} |
| 6368 |
|
| 6369 |
/* tp->lock must be held */ |
| 6370 |
static void tg3_ptp_resume(struct tg3 *tp) |
| 6371 |
{ |
| 6372 |
if (!tg3_flag(tp, PTP_CAPABLE)) |
| 6373 |
return; |
| 6374 |
|
| 6375 |
tg3_refclk_write(tp, ktime_to_ns(ktime_get_real()) + tp->ptp_adjust); |
| 6376 |
tp->ptp_adjust = 0; |
| 6377 |
} |
| 6378 |
|
| 6379 |
static void tg3_ptp_fini(struct tg3 *tp) |
| 6380 |
{ |
| 6381 |
if (!tg3_flag(tp, PTP_CAPABLE) || !tp->ptp_clock) |
| 6382 |
return; |
| 6383 |
|
| 6384 |
ptp_clock_unregister(tp->ptp_clock); |
| 6385 |
tp->ptp_clock = NULL; |
| 6386 |
tp->ptp_adjust = 0; |
| 6387 |
dev_consume_skb_any(tp->tx_tstamp_skb); |
| 6388 |
tp->tx_tstamp_skb = NULL; |
| 6389 |
} |
| 6390 |
|
| 6391 |
static inline int tg3_irq_sync(struct tg3 *tp) |
| 6392 |
{ |
| 6393 |
return tp->irq_sync; |
| 6394 |
} |
| 6395 |
|
| 6396 |
static inline void tg3_rd32_loop(struct tg3 *tp, u32 *dst, u32 off, u32 len) |
| 6397 |
{ |
| 6398 |
int i; |
| 6399 |
|
| 6400 |
dst = (u32 *)((u8 *)dst + off); |
| 6401 |
for (i = 0; i < len; i += sizeof(u32)) |
| 6402 |
*dst++ = tr32(off + i); |
| 6403 |
} |
| 6404 |
|
| 6405 |
static void tg3_dump_legacy_regs(struct tg3 *tp, u32 *regs) |
| 6406 |
{ |
| 6407 |
tg3_rd32_loop(tp, regs, TG3PCI_VENDOR, 0xb0); |
| 6408 |
tg3_rd32_loop(tp, regs, MAILBOX_INTERRUPT_0, 0x200); |
| 6409 |
tg3_rd32_loop(tp, regs, MAC_MODE, 0x4f0); |
| 6410 |
tg3_rd32_loop(tp, regs, SNDDATAI_MODE, 0xe0); |
| 6411 |
tg3_rd32_loop(tp, regs, SNDDATAC_MODE, 0x04); |
| 6412 |
tg3_rd32_loop(tp, regs, SNDBDS_MODE, 0x80); |
| 6413 |
tg3_rd32_loop(tp, regs, SNDBDI_MODE, 0x48); |
| 6414 |
tg3_rd32_loop(tp, regs, SNDBDC_MODE, 0x04); |
| 6415 |
tg3_rd32_loop(tp, regs, RCVLPC_MODE, 0x20); |
| 6416 |
tg3_rd32_loop(tp, regs, RCVLPC_SELLST_BASE, 0x15c); |
| 6417 |
tg3_rd32_loop(tp, regs, RCVDBDI_MODE, 0x0c); |
| 6418 |
tg3_rd32_loop(tp, regs, RCVDBDI_JUMBO_BD, 0x3c); |
| 6419 |
tg3_rd32_loop(tp, regs, RCVDBDI_BD_PROD_IDX_0, 0x44); |
| 6420 |
tg3_rd32_loop(tp, regs, RCVDCC_MODE, 0x04); |
| 6421 |
tg3_rd32_loop(tp, regs, RCVBDI_MODE, 0x20); |
| 6422 |
tg3_rd32_loop(tp, regs, RCVCC_MODE, 0x14); |
| 6423 |
tg3_rd32_loop(tp, regs, RCVLSC_MODE, 0x08); |
| 6424 |
tg3_rd32_loop(tp, regs, MBFREE_MODE, 0x08); |
| 6425 |
tg3_rd32_loop(tp, regs, HOSTCC_MODE, 0x100); |
| 6426 |
|
| 6427 |
if (tg3_flag(tp, SUPPORT_MSIX)) |
| 6428 |
tg3_rd32_loop(tp, regs, HOSTCC_RXCOL_TICKS_VEC1, 0x180); |
| 6429 |
|
| 6430 |
tg3_rd32_loop(tp, regs, MEMARB_MODE, 0x10); |
| 6431 |
tg3_rd32_loop(tp, regs, BUFMGR_MODE, 0x58); |
| 6432 |
tg3_rd32_loop(tp, regs, RDMAC_MODE, 0x08); |
| 6433 |
tg3_rd32_loop(tp, regs, WDMAC_MODE, 0x08); |
| 6434 |
tg3_rd32_loop(tp, regs, RX_CPU_MODE, 0x04); |
| 6435 |
tg3_rd32_loop(tp, regs, RX_CPU_STATE, 0x04); |
| 6436 |
tg3_rd32_loop(tp, regs, RX_CPU_PGMCTR, 0x04); |
| 6437 |
tg3_rd32_loop(tp, regs, RX_CPU_HWBKPT, 0x04); |
| 6438 |
|
| 6439 |
if (!tg3_flag(tp, 5705_PLUS)) { |
| 6440 |
tg3_rd32_loop(tp, regs, TX_CPU_MODE, 0x04); |
| 6441 |
tg3_rd32_loop(tp, regs, TX_CPU_STATE, 0x04); |
| 6442 |
tg3_rd32_loop(tp, regs, TX_CPU_PGMCTR, 0x04); |
| 6443 |
} |
| 6444 |
|
| 6445 |
tg3_rd32_loop(tp, regs, GRCMBOX_INTERRUPT_0, 0x110); |
| 6446 |
tg3_rd32_loop(tp, regs, FTQ_RESET, 0x120); |
| 6447 |
tg3_rd32_loop(tp, regs, MSGINT_MODE, 0x0c); |
| 6448 |
tg3_rd32_loop(tp, regs, DMAC_MODE, 0x04); |
| 6449 |
tg3_rd32_loop(tp, regs, GRC_MODE, 0x4c); |
| 6450 |
|
| 6451 |
if (tg3_flag(tp, NVRAM)) |
| 6452 |
tg3_rd32_loop(tp, regs, NVRAM_CMD, 0x24); |
| 6453 |
} |
| 6454 |
|
| 6455 |
static void tg3_dump_state(struct tg3 *tp) |
| 6456 |
{ |
| 6457 |
int i; |
| 6458 |
u32 *regs; |
| 6459 |
|
| 6460 |
/* If it is a PCI error, all registers will be 0xffff, |
| 6461 |
* we don't dump them out, just report the error and return |
| 6462 |
*/ |
| 6463 |
if (tp->pdev->error_state != pci_channel_io_normal) { |
| 6464 |
netdev_err(tp->dev, "PCI channel ERROR!\n"); |
| 6465 |
return; |
| 6466 |
} |
| 6467 |
|
| 6468 |
regs = kzalloc(TG3_REG_BLK_SIZE, GFP_ATOMIC); |
| 6469 |
if (!regs) |
| 6470 |
return; |
| 6471 |
|
| 6472 |
if (tg3_flag(tp, PCI_EXPRESS)) { |
| 6473 |
/* Read up to but not including private PCI registers */ |
| 6474 |
for (i = 0; i < TG3_PCIE_TLDLPL_PORT; i += sizeof(u32)) |
| 6475 |
regs[i / sizeof(u32)] = tr32(i); |
| 6476 |
} else |
| 6477 |
tg3_dump_legacy_regs(tp, regs); |
| 6478 |
|
| 6479 |
for (i = 0; i < TG3_REG_BLK_SIZE / sizeof(u32); i += 4) { |
| 6480 |
if (!regs[i + 0] && !regs[i + 1] && |
| 6481 |
!regs[i + 2] && !regs[i + 3]) |
| 6482 |
continue; |
| 6483 |
|
| 6484 |
netdev_err(tp->dev, "0x%08x: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", |
| 6485 |
i * 4, |
| 6486 |
regs[i + 0], regs[i + 1], regs[i + 2], regs[i + 3]); |
| 6487 |
} |
| 6488 |
|
| 6489 |
kfree(regs); |
| 6490 |
|
| 6491 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 6492 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 6493 |
|
| 6494 |
/* SW status block */ |
| 6495 |
netdev_err(tp->dev, |
| 6496 |
"%d: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", |
| 6497 |
i, |
| 6498 |
tnapi->hw_status->status, |
| 6499 |
tnapi->hw_status->status_tag, |
| 6500 |
tnapi->hw_status->rx_jumbo_consumer, |
| 6501 |
tnapi->hw_status->rx_consumer, |
| 6502 |
tnapi->hw_status->rx_mini_consumer, |
| 6503 |
tnapi->hw_status->idx[0].rx_producer, |
| 6504 |
tnapi->hw_status->idx[0].tx_consumer); |
| 6505 |
|
| 6506 |
netdev_err(tp->dev, |
| 6507 |
"%d: NAPI info [%08x:%08x:(%04x:%04x:%04x):%04x:(%04x:%04x:%04x:%04x)]\n", |
| 6508 |
i, |
| 6509 |
tnapi->last_tag, tnapi->last_irq_tag, |
| 6510 |
tnapi->tx_prod, tnapi->tx_cons, tnapi->tx_pending, |
| 6511 |
tnapi->rx_rcb_ptr, |
| 6512 |
tnapi->prodring.rx_std_prod_idx, |
| 6513 |
tnapi->prodring.rx_std_cons_idx, |
| 6514 |
tnapi->prodring.rx_jmb_prod_idx, |
| 6515 |
tnapi->prodring.rx_jmb_cons_idx); |
| 6516 |
} |
| 6517 |
} |
| 6518 |
|
| 6519 |
/* This is called whenever we suspect that the system chipset is re- |
| 6520 |
* ordering the sequence of MMIO to the tx send mailbox. The symptom |
| 6521 |
* is bogus tx completions. We try to recover by setting the |
| 6522 |
* TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later |
| 6523 |
* in the workqueue. |
| 6524 |
*/ |
| 6525 |
static void tg3_tx_recover(struct tg3 *tp) |
| 6526 |
{ |
| 6527 |
BUG_ON(tg3_flag(tp, MBOX_WRITE_REORDER) || |
| 6528 |
tp->write32_tx_mbox == tg3_write_indirect_mbox); |
| 6529 |
|
| 6530 |
netdev_warn(tp->dev, |
| 6531 |
"The system may be re-ordering memory-mapped I/O " |
| 6532 |
"cycles to the network device, attempting to recover. " |
| 6533 |
"Please report the problem to the driver maintainer " |
| 6534 |
"and include system chipset information.\n"); |
| 6535 |
|
| 6536 |
tg3_flag_set(tp, TX_RECOVERY_PENDING); |
| 6537 |
} |
| 6538 |
|
| 6539 |
static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
| 6540 |
{ |
| 6541 |
/* Tell compiler to fetch tx indices from memory. */ |
| 6542 |
barrier(); |
| 6543 |
return tnapi->tx_pending - |
| 6544 |
((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); |
| 6545 |
} |
| 6546 |
|
| 6547 |
/* Tigon3 never reports partial packet sends. So we do not |
| 6548 |
* need special logic to handle SKBs that have not had all |
| 6549 |
* of their frags sent yet, like SunGEM does. |
| 6550 |
*/ |
| 6551 |
static void tg3_tx(struct tg3_napi *tnapi) |
| 6552 |
{ |
| 6553 |
struct tg3 *tp = tnapi->tp; |
| 6554 |
u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 6555 |
u32 sw_idx = tnapi->tx_cons; |
| 6556 |
struct netdev_queue *txq; |
| 6557 |
int index = tnapi - tp->napi; |
| 6558 |
unsigned int pkts_compl = 0, bytes_compl = 0; |
| 6559 |
|
| 6560 |
if (tg3_flag(tp, ENABLE_TSS)) |
| 6561 |
index--; |
| 6562 |
|
| 6563 |
txq = netdev_get_tx_queue(tp->dev, index); |
| 6564 |
|
| 6565 |
while (sw_idx != hw_idx) { |
| 6566 |
struct tg3_tx_ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
| 6567 |
bool complete_skb_later = false; |
| 6568 |
struct sk_buff *skb = ri->skb; |
| 6569 |
int i, tx_bug = 0; |
| 6570 |
|
| 6571 |
if (unlikely(skb == NULL)) { |
| 6572 |
tg3_tx_recover(tp); |
| 6573 |
return; |
| 6574 |
} |
| 6575 |
|
| 6576 |
if (tnapi->tx_ring[sw_idx].len_flags & TXD_FLAG_HWTSTAMP) { |
| 6577 |
struct skb_shared_hwtstamps timestamp; |
| 6578 |
u64 hwclock; |
| 6579 |
|
| 6580 |
tg3_read_tx_tstamp(tp, &hwclock); |
| 6581 |
if (hwclock != tp->pre_tx_ts) { |
| 6582 |
tg3_hwclock_to_timestamp(tp, hwclock, ×tamp); |
| 6583 |
skb_tstamp_tx(skb, ×tamp); |
| 6584 |
tp->pre_tx_ts = 0; |
| 6585 |
} else { |
| 6586 |
tp->tx_tstamp_skb = skb; |
| 6587 |
complete_skb_later = true; |
| 6588 |
} |
| 6589 |
} |
| 6590 |
|
| 6591 |
dma_unmap_single(&tp->pdev->dev, dma_unmap_addr(ri, mapping), |
| 6592 |
skb_headlen(skb), DMA_TO_DEVICE); |
| 6593 |
|
| 6594 |
ri->skb = NULL; |
| 6595 |
|
| 6596 |
while (ri->fragmented) { |
| 6597 |
ri->fragmented = false; |
| 6598 |
sw_idx = NEXT_TX(sw_idx); |
| 6599 |
ri = &tnapi->tx_buffers[sw_idx]; |
| 6600 |
} |
| 6601 |
|
| 6602 |
sw_idx = NEXT_TX(sw_idx); |
| 6603 |
|
| 6604 |
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 6605 |
ri = &tnapi->tx_buffers[sw_idx]; |
| 6606 |
if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
| 6607 |
tx_bug = 1; |
| 6608 |
|
| 6609 |
dma_unmap_page(&tp->pdev->dev, |
| 6610 |
dma_unmap_addr(ri, mapping), |
| 6611 |
skb_frag_size(&skb_shinfo(skb)->frags[i]), |
| 6612 |
DMA_TO_DEVICE); |
| 6613 |
|
| 6614 |
while (ri->fragmented) { |
| 6615 |
ri->fragmented = false; |
| 6616 |
sw_idx = NEXT_TX(sw_idx); |
| 6617 |
ri = &tnapi->tx_buffers[sw_idx]; |
| 6618 |
} |
| 6619 |
|
| 6620 |
sw_idx = NEXT_TX(sw_idx); |
| 6621 |
} |
| 6622 |
|
| 6623 |
pkts_compl++; |
| 6624 |
bytes_compl += skb->len; |
| 6625 |
|
| 6626 |
if (!complete_skb_later) |
| 6627 |
dev_consume_skb_any(skb); |
| 6628 |
else |
| 6629 |
ptp_schedule_worker(tp->ptp_clock, 0); |
| 6630 |
|
| 6631 |
if (unlikely(tx_bug)) { |
| 6632 |
tg3_tx_recover(tp); |
| 6633 |
return; |
| 6634 |
} |
| 6635 |
} |
| 6636 |
|
| 6637 |
netdev_tx_completed_queue(txq, pkts_compl, bytes_compl); |
| 6638 |
|
| 6639 |
tnapi->tx_cons = sw_idx; |
| 6640 |
|
| 6641 |
/* Need to make the tx_cons update visible to __tg3_start_xmit() |
| 6642 |
* before checking for netif_queue_stopped(). Without the |
| 6643 |
* memory barrier, there is a small possibility that __tg3_start_xmit() |
| 6644 |
* will miss it and cause the queue to be stopped forever. |
| 6645 |
*/ |
| 6646 |
smp_mb(); |
| 6647 |
|
| 6648 |
if (unlikely(netif_tx_queue_stopped(txq) && |
| 6649 |
(tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
| 6650 |
__netif_tx_lock(txq, smp_processor_id()); |
| 6651 |
if (netif_tx_queue_stopped(txq) && |
| 6652 |
(tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
| 6653 |
netif_tx_wake_queue(txq); |
| 6654 |
__netif_tx_unlock(txq); |
| 6655 |
} |
| 6656 |
} |
| 6657 |
|
| 6658 |
static void tg3_frag_free(bool is_frag, void *data) |
| 6659 |
{ |
| 6660 |
if (is_frag) |
| 6661 |
skb_free_frag(data); |
| 6662 |
else |
| 6663 |
kfree(data); |
| 6664 |
} |
| 6665 |
|
| 6666 |
static void tg3_rx_data_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
| 6667 |
{ |
| 6668 |
unsigned int skb_size = SKB_DATA_ALIGN(map_sz + TG3_RX_OFFSET(tp)) + |
| 6669 |
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 6670 |
|
| 6671 |
if (!ri->data) |
| 6672 |
return; |
| 6673 |
|
| 6674 |
dma_unmap_single(&tp->pdev->dev, dma_unmap_addr(ri, mapping), map_sz, |
| 6675 |
DMA_FROM_DEVICE); |
| 6676 |
tg3_frag_free(skb_size <= PAGE_SIZE, ri->data); |
| 6677 |
ri->data = NULL; |
| 6678 |
} |
| 6679 |
|
| 6680 |
|
| 6681 |
/* Returns size of skb allocated or < 0 on error. |
| 6682 |
* |
| 6683 |
* We only need to fill in the address because the other members |
| 6684 |
* of the RX descriptor are invariant, see tg3_init_rings. |
| 6685 |
* |
| 6686 |
* Note the purposeful asymmetry of cpu vs. chip accesses. For |
| 6687 |
* posting buffers we only dirty the first cache line of the RX |
| 6688 |
* descriptor (containing the address). Whereas for the RX status |
| 6689 |
* buffers the cpu only reads the last cacheline of the RX descriptor |
| 6690 |
* (to fetch the error flags, vlan tag, checksum, and opaque cookie). |
| 6691 |
*/ |
| 6692 |
static int tg3_alloc_rx_data(struct tg3 *tp, struct tg3_rx_prodring_set *tpr, |
| 6693 |
u32 opaque_key, u32 dest_idx_unmasked, |
| 6694 |
unsigned int *frag_size) |
| 6695 |
{ |
| 6696 |
struct tg3_rx_buffer_desc *desc; |
| 6697 |
struct ring_info *map; |
| 6698 |
u8 *data; |
| 6699 |
dma_addr_t mapping; |
| 6700 |
int skb_size, data_size, dest_idx; |
| 6701 |
|
| 6702 |
switch (opaque_key) { |
| 6703 |
case RXD_OPAQUE_RING_STD: |
| 6704 |
dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
| 6705 |
desc = &tpr->rx_std[dest_idx]; |
| 6706 |
map = &tpr->rx_std_buffers[dest_idx]; |
| 6707 |
data_size = tp->rx_pkt_map_sz; |
| 6708 |
break; |
| 6709 |
|
| 6710 |
case RXD_OPAQUE_RING_JUMBO: |
| 6711 |
dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
| 6712 |
desc = &tpr->rx_jmb[dest_idx].std; |
| 6713 |
map = &tpr->rx_jmb_buffers[dest_idx]; |
| 6714 |
data_size = TG3_RX_JMB_MAP_SZ; |
| 6715 |
break; |
| 6716 |
|
| 6717 |
default: |
| 6718 |
return -EINVAL; |
| 6719 |
} |
| 6720 |
|
| 6721 |
/* Do not overwrite any of the map or rp information |
| 6722 |
* until we are sure we can commit to a new buffer. |
| 6723 |
* |
| 6724 |
* Callers depend upon this behavior and assume that |
| 6725 |
* we leave everything unchanged if we fail. |
| 6726 |
*/ |
| 6727 |
skb_size = SKB_DATA_ALIGN(data_size + TG3_RX_OFFSET(tp)) + |
| 6728 |
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 6729 |
if (skb_size <= PAGE_SIZE) { |
| 6730 |
data = napi_alloc_frag(skb_size); |
| 6731 |
*frag_size = skb_size; |
| 6732 |
} else { |
| 6733 |
data = kmalloc(skb_size, GFP_ATOMIC); |
| 6734 |
*frag_size = 0; |
| 6735 |
} |
| 6736 |
if (!data) |
| 6737 |
return -ENOMEM; |
| 6738 |
|
| 6739 |
mapping = dma_map_single(&tp->pdev->dev, data + TG3_RX_OFFSET(tp), |
| 6740 |
data_size, DMA_FROM_DEVICE); |
| 6741 |
if (unlikely(dma_mapping_error(&tp->pdev->dev, mapping))) { |
| 6742 |
tg3_frag_free(skb_size <= PAGE_SIZE, data); |
| 6743 |
return -EIO; |
| 6744 |
} |
| 6745 |
|
| 6746 |
map->data = data; |
| 6747 |
dma_unmap_addr_set(map, mapping, mapping); |
| 6748 |
|
| 6749 |
desc->addr_hi = ((u64)mapping >> 32); |
| 6750 |
desc->addr_lo = ((u64)mapping & 0xffffffff); |
| 6751 |
|
| 6752 |
return data_size; |
| 6753 |
} |
| 6754 |
|
| 6755 |
/* We only need to move over in the address because the other |
| 6756 |
* members of the RX descriptor are invariant. See notes above |
| 6757 |
* tg3_alloc_rx_data for full details. |
| 6758 |
*/ |
| 6759 |
static void tg3_recycle_rx(struct tg3_napi *tnapi, |
| 6760 |
struct tg3_rx_prodring_set *dpr, |
| 6761 |
u32 opaque_key, int src_idx, |
| 6762 |
u32 dest_idx_unmasked) |
| 6763 |
{ |
| 6764 |
struct tg3 *tp = tnapi->tp; |
| 6765 |
struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
| 6766 |
struct ring_info *src_map, *dest_map; |
| 6767 |
struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
| 6768 |
int dest_idx; |
| 6769 |
|
| 6770 |
switch (opaque_key) { |
| 6771 |
case RXD_OPAQUE_RING_STD: |
| 6772 |
dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
| 6773 |
dest_desc = &dpr->rx_std[dest_idx]; |
| 6774 |
dest_map = &dpr->rx_std_buffers[dest_idx]; |
| 6775 |
src_desc = &spr->rx_std[src_idx]; |
| 6776 |
src_map = &spr->rx_std_buffers[src_idx]; |
| 6777 |
break; |
| 6778 |
|
| 6779 |
case RXD_OPAQUE_RING_JUMBO: |
| 6780 |
dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
| 6781 |
dest_desc = &dpr->rx_jmb[dest_idx].std; |
| 6782 |
dest_map = &dpr->rx_jmb_buffers[dest_idx]; |
| 6783 |
src_desc = &spr->rx_jmb[src_idx].std; |
| 6784 |
src_map = &spr->rx_jmb_buffers[src_idx]; |
| 6785 |
break; |
| 6786 |
|
| 6787 |
default: |
| 6788 |
return; |
| 6789 |
} |
| 6790 |
|
| 6791 |
dest_map->data = src_map->data; |
| 6792 |
dma_unmap_addr_set(dest_map, mapping, |
| 6793 |
dma_unmap_addr(src_map, mapping)); |
| 6794 |
dest_desc->addr_hi = src_desc->addr_hi; |
| 6795 |
dest_desc->addr_lo = src_desc->addr_lo; |
| 6796 |
|
| 6797 |
/* Ensure that the update to the skb happens after the physical |
| 6798 |
* addresses have been transferred to the new BD location. |
| 6799 |
*/ |
| 6800 |
smp_wmb(); |
| 6801 |
|
| 6802 |
src_map->data = NULL; |
| 6803 |
} |
| 6804 |
|
| 6805 |
/* The RX ring scheme is composed of multiple rings which post fresh |
| 6806 |
* buffers to the chip, and one special ring the chip uses to report |
| 6807 |
* status back to the host. |
| 6808 |
* |
| 6809 |
* The special ring reports the status of received packets to the |
| 6810 |
* host. The chip does not write into the original descriptor the |
| 6811 |
* RX buffer was obtained from. The chip simply takes the original |
| 6812 |
* descriptor as provided by the host, updates the status and length |
| 6813 |
* field, then writes this into the next status ring entry. |
| 6814 |
* |
| 6815 |
* Each ring the host uses to post buffers to the chip is described |
| 6816 |
* by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, |
| 6817 |
* it is first placed into the on-chip ram. When the packet's length |
| 6818 |
* is known, it walks down the TG3_BDINFO entries to select the ring. |
| 6819 |
* Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO |
| 6820 |
* which is within the range of the new packet's length is chosen. |
| 6821 |
* |
| 6822 |
* The "separate ring for rx status" scheme may sound queer, but it makes |
| 6823 |
* sense from a cache coherency perspective. If only the host writes |
| 6824 |
* to the buffer post rings, and only the chip writes to the rx status |
| 6825 |
* rings, then cache lines never move beyond shared-modified state. |
| 6826 |
* If both the host and chip were to write into the same ring, cache line |
| 6827 |
* eviction could occur since both entities want it in an exclusive state. |
| 6828 |
*/ |
| 6829 |
static int tg3_rx(struct tg3_napi *tnapi, int budget) |
| 6830 |
{ |
| 6831 |
struct tg3 *tp = tnapi->tp; |
| 6832 |
u32 work_mask, rx_std_posted = 0; |
| 6833 |
u32 std_prod_idx, jmb_prod_idx; |
| 6834 |
u32 sw_idx = tnapi->rx_rcb_ptr; |
| 6835 |
u16 hw_idx; |
| 6836 |
int received; |
| 6837 |
struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
| 6838 |
|
| 6839 |
hw_idx = *(tnapi->rx_rcb_prod_idx); |
| 6840 |
/* |
| 6841 |
* We need to order the read of hw_idx and the read of |
| 6842 |
* the opaque cookie. |
| 6843 |
*/ |
| 6844 |
rmb(); |
| 6845 |
work_mask = 0; |
| 6846 |
received = 0; |
| 6847 |
std_prod_idx = tpr->rx_std_prod_idx; |
| 6848 |
jmb_prod_idx = tpr->rx_jmb_prod_idx; |
| 6849 |
while (sw_idx != hw_idx && budget > 0) { |
| 6850 |
struct ring_info *ri; |
| 6851 |
struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
| 6852 |
unsigned int len; |
| 6853 |
struct sk_buff *skb; |
| 6854 |
dma_addr_t dma_addr; |
| 6855 |
u32 opaque_key, desc_idx, *post_ptr; |
| 6856 |
u8 *data; |
| 6857 |
u64 tstamp = 0; |
| 6858 |
|
| 6859 |
desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 6860 |
opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 6861 |
if (opaque_key == RXD_OPAQUE_RING_STD) { |
| 6862 |
ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
| 6863 |
dma_addr = dma_unmap_addr(ri, mapping); |
| 6864 |
data = ri->data; |
| 6865 |
post_ptr = &std_prod_idx; |
| 6866 |
rx_std_posted++; |
| 6867 |
} else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
| 6868 |
ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
| 6869 |
dma_addr = dma_unmap_addr(ri, mapping); |
| 6870 |
data = ri->data; |
| 6871 |
post_ptr = &jmb_prod_idx; |
| 6872 |
} else |
| 6873 |
goto next_pkt_nopost; |
| 6874 |
|
| 6875 |
work_mask |= opaque_key; |
| 6876 |
|
| 6877 |
if (desc->err_vlan & RXD_ERR_MASK) { |
| 6878 |
drop_it: |
| 6879 |
tg3_recycle_rx(tnapi, tpr, opaque_key, |
| 6880 |
desc_idx, *post_ptr); |
| 6881 |
drop_it_no_recycle: |
| 6882 |
/* Other statistics kept track of by card. */ |
| 6883 |
tnapi->rx_dropped++; |
| 6884 |
goto next_pkt; |
| 6885 |
} |
| 6886 |
|
| 6887 |
prefetch(data + TG3_RX_OFFSET(tp)); |
| 6888 |
len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
| 6889 |
ETH_FCS_LEN; |
| 6890 |
|
| 6891 |
if ((desc->type_flags & RXD_FLAG_PTPSTAT_MASK) == |
| 6892 |
RXD_FLAG_PTPSTAT_PTPV1 || |
| 6893 |
(desc->type_flags & RXD_FLAG_PTPSTAT_MASK) == |
| 6894 |
RXD_FLAG_PTPSTAT_PTPV2) { |
| 6895 |
tstamp = tr32(TG3_RX_TSTAMP_LSB); |
| 6896 |
tstamp |= (u64)tr32(TG3_RX_TSTAMP_MSB) << 32; |
| 6897 |
} |
| 6898 |
|
| 6899 |
if (len > TG3_RX_COPY_THRESH(tp)) { |
| 6900 |
int skb_size; |
| 6901 |
unsigned int frag_size; |
| 6902 |
|
| 6903 |
skb_size = tg3_alloc_rx_data(tp, tpr, opaque_key, |
| 6904 |
*post_ptr, &frag_size); |
| 6905 |
if (skb_size < 0) |
| 6906 |
goto drop_it; |
| 6907 |
|
| 6908 |
dma_unmap_single(&tp->pdev->dev, dma_addr, skb_size, |
| 6909 |
DMA_FROM_DEVICE); |
| 6910 |
|
| 6911 |
/* Ensure that the update to the data happens |
| 6912 |
* after the usage of the old DMA mapping. |
| 6913 |
*/ |
| 6914 |
smp_wmb(); |
| 6915 |
|
| 6916 |
ri->data = NULL; |
| 6917 |
|
| 6918 |
if (frag_size) |
| 6919 |
skb = build_skb(data, frag_size); |
| 6920 |
else |
| 6921 |
skb = slab_build_skb(data); |
| 6922 |
if (!skb) { |
| 6923 |
tg3_frag_free(frag_size != 0, data); |
| 6924 |
goto drop_it_no_recycle; |
| 6925 |
} |
| 6926 |
skb_reserve(skb, TG3_RX_OFFSET(tp)); |
| 6927 |
} else { |
| 6928 |
tg3_recycle_rx(tnapi, tpr, opaque_key, |
| 6929 |
desc_idx, *post_ptr); |
| 6930 |
|
| 6931 |
skb = netdev_alloc_skb(tp->dev, |
| 6932 |
len + TG3_RAW_IP_ALIGN); |
| 6933 |
if (skb == NULL) |
| 6934 |
goto drop_it_no_recycle; |
| 6935 |
|
| 6936 |
skb_reserve(skb, TG3_RAW_IP_ALIGN); |
| 6937 |
dma_sync_single_for_cpu(&tp->pdev->dev, dma_addr, len, |
| 6938 |
DMA_FROM_DEVICE); |
| 6939 |
memcpy(skb->data, |
| 6940 |
data + TG3_RX_OFFSET(tp), |
| 6941 |
len); |
| 6942 |
dma_sync_single_for_device(&tp->pdev->dev, dma_addr, |
| 6943 |
len, DMA_FROM_DEVICE); |
| 6944 |
} |
| 6945 |
|
| 6946 |
skb_put(skb, len); |
| 6947 |
if (tstamp) |
| 6948 |
tg3_hwclock_to_timestamp(tp, tstamp, |
| 6949 |
skb_hwtstamps(skb)); |
| 6950 |
|
| 6951 |
if ((tp->dev->features & NETIF_F_RXCSUM) && |
| 6952 |
(desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 6953 |
(((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 6954 |
>> RXD_TCPCSUM_SHIFT) == 0xffff)) |
| 6955 |
skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6956 |
else |
| 6957 |
skb_checksum_none_assert(skb); |
| 6958 |
|
| 6959 |
skb->protocol = eth_type_trans(skb, tp->dev); |
| 6960 |
|
| 6961 |
if (len > (tp->dev->mtu + ETH_HLEN) && |
| 6962 |
skb->protocol != htons(ETH_P_8021Q) && |
| 6963 |
skb->protocol != htons(ETH_P_8021AD)) { |
| 6964 |
dev_kfree_skb_any(skb); |
| 6965 |
goto drop_it_no_recycle; |
| 6966 |
} |
| 6967 |
|
| 6968 |
if (desc->type_flags & RXD_FLAG_VLAN && |
| 6969 |
!(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
| 6970 |
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
| 6971 |
desc->err_vlan & RXD_VLAN_MASK); |
| 6972 |
|
| 6973 |
napi_gro_receive(&tnapi->napi, skb); |
| 6974 |
|
| 6975 |
received++; |
| 6976 |
budget--; |
| 6977 |
|
| 6978 |
next_pkt: |
| 6979 |
(*post_ptr)++; |
| 6980 |
|
| 6981 |
if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { |
| 6982 |
tpr->rx_std_prod_idx = std_prod_idx & |
| 6983 |
tp->rx_std_ring_mask; |
| 6984 |
tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 6985 |
tpr->rx_std_prod_idx); |
| 6986 |
work_mask &= ~RXD_OPAQUE_RING_STD; |
| 6987 |
rx_std_posted = 0; |
| 6988 |
} |
| 6989 |
next_pkt_nopost: |
| 6990 |
sw_idx++; |
| 6991 |
sw_idx &= tp->rx_ret_ring_mask; |
| 6992 |
|
| 6993 |
/* Refresh hw_idx to see if there is new work */ |
| 6994 |
if (sw_idx == hw_idx) { |
| 6995 |
hw_idx = *(tnapi->rx_rcb_prod_idx); |
| 6996 |
rmb(); |
| 6997 |
} |
| 6998 |
} |
| 6999 |
|
| 7000 |
/* ACK the status ring. */ |
| 7001 |
tnapi->rx_rcb_ptr = sw_idx; |
| 7002 |
tw32_rx_mbox(tnapi->consmbox, sw_idx); |
| 7003 |
|
| 7004 |
/* Refill RX ring(s). */ |
| 7005 |
if (!tg3_flag(tp, ENABLE_RSS)) { |
| 7006 |
/* Sync BD data before updating mailbox */ |
| 7007 |
wmb(); |
| 7008 |
|
| 7009 |
if (work_mask & RXD_OPAQUE_RING_STD) { |
| 7010 |
tpr->rx_std_prod_idx = std_prod_idx & |
| 7011 |
tp->rx_std_ring_mask; |
| 7012 |
tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 7013 |
tpr->rx_std_prod_idx); |
| 7014 |
} |
| 7015 |
if (work_mask & RXD_OPAQUE_RING_JUMBO) { |
| 7016 |
tpr->rx_jmb_prod_idx = jmb_prod_idx & |
| 7017 |
tp->rx_jmb_ring_mask; |
| 7018 |
tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 7019 |
tpr->rx_jmb_prod_idx); |
| 7020 |
} |
| 7021 |
} else if (work_mask) { |
| 7022 |
/* rx_std_buffers[] and rx_jmb_buffers[] entries must be |
| 7023 |
* updated before the producer indices can be updated. |
| 7024 |
*/ |
| 7025 |
smp_wmb(); |
| 7026 |
|
| 7027 |
tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
| 7028 |
tpr->rx_jmb_prod_idx = jmb_prod_idx & tp->rx_jmb_ring_mask; |
| 7029 |
|
| 7030 |
if (tnapi != &tp->napi[1]) { |
| 7031 |
tp->rx_refill = true; |
| 7032 |
napi_schedule(&tp->napi[1].napi); |
| 7033 |
} |
| 7034 |
} |
| 7035 |
|
| 7036 |
return received; |
| 7037 |
} |
| 7038 |
|
| 7039 |
static void tg3_poll_link(struct tg3 *tp) |
| 7040 |
{ |
| 7041 |
/* handle link change and other phy events */ |
| 7042 |
if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
| 7043 |
struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
| 7044 |
|
| 7045 |
if (sblk->status & SD_STATUS_LINK_CHG) { |
| 7046 |
sblk->status = SD_STATUS_UPDATED | |
| 7047 |
(sblk->status & ~SD_STATUS_LINK_CHG); |
| 7048 |
spin_lock(&tp->lock); |
| 7049 |
if (tg3_flag(tp, USE_PHYLIB)) { |
| 7050 |
tw32_f(MAC_STATUS, |
| 7051 |
(MAC_STATUS_SYNC_CHANGED | |
| 7052 |
MAC_STATUS_CFG_CHANGED | |
| 7053 |
MAC_STATUS_MI_COMPLETION | |
| 7054 |
MAC_STATUS_LNKSTATE_CHANGED)); |
| 7055 |
udelay(40); |
| 7056 |
} else |
| 7057 |
tg3_setup_phy(tp, false); |
| 7058 |
spin_unlock(&tp->lock); |
| 7059 |
} |
| 7060 |
} |
| 7061 |
} |
| 7062 |
|
| 7063 |
static int tg3_rx_prodring_xfer(struct tg3 *tp, |
| 7064 |
struct tg3_rx_prodring_set *dpr, |
| 7065 |
struct tg3_rx_prodring_set *spr) |
| 7066 |
{ |
| 7067 |
u32 si, di, cpycnt, src_prod_idx; |
| 7068 |
int i, err = 0; |
| 7069 |
|
| 7070 |
while (1) { |
| 7071 |
src_prod_idx = spr->rx_std_prod_idx; |
| 7072 |
|
| 7073 |
/* Make sure updates to the rx_std_buffers[] entries and the |
| 7074 |
* standard producer index are seen in the correct order. |
| 7075 |
*/ |
| 7076 |
smp_rmb(); |
| 7077 |
|
| 7078 |
if (spr->rx_std_cons_idx == src_prod_idx) |
| 7079 |
break; |
| 7080 |
|
| 7081 |
if (spr->rx_std_cons_idx < src_prod_idx) |
| 7082 |
cpycnt = src_prod_idx - spr->rx_std_cons_idx; |
| 7083 |
else |
| 7084 |
cpycnt = tp->rx_std_ring_mask + 1 - |
| 7085 |
spr->rx_std_cons_idx; |
| 7086 |
|
| 7087 |
cpycnt = min(cpycnt, |
| 7088 |
tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); |
| 7089 |
|
| 7090 |
si = spr->rx_std_cons_idx; |
| 7091 |
di = dpr->rx_std_prod_idx; |
| 7092 |
|
| 7093 |
for (i = di; i < di + cpycnt; i++) { |
| 7094 |
if (dpr->rx_std_buffers[i].data) { |
| 7095 |
cpycnt = i - di; |
| 7096 |
err = -ENOSPC; |
| 7097 |
break; |
| 7098 |
} |
| 7099 |
} |
| 7100 |
|
| 7101 |
if (!cpycnt) |
| 7102 |
break; |
| 7103 |
|
| 7104 |
/* Ensure that updates to the rx_std_buffers ring and the |
| 7105 |
* shadowed hardware producer ring from tg3_recycle_skb() are |
| 7106 |
* ordered correctly WRT the skb check above. |
| 7107 |
*/ |
| 7108 |
smp_rmb(); |
| 7109 |
|
| 7110 |
memcpy(&dpr->rx_std_buffers[di], |
| 7111 |
&spr->rx_std_buffers[si], |
| 7112 |
cpycnt * sizeof(struct ring_info)); |
| 7113 |
|
| 7114 |
for (i = 0; i < cpycnt; i++, di++, si++) { |
| 7115 |
struct tg3_rx_buffer_desc *sbd, *dbd; |
| 7116 |
sbd = &spr->rx_std[si]; |
| 7117 |
dbd = &dpr->rx_std[di]; |
| 7118 |
dbd->addr_hi = sbd->addr_hi; |
| 7119 |
dbd->addr_lo = sbd->addr_lo; |
| 7120 |
} |
| 7121 |
|
| 7122 |
spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
| 7123 |
tp->rx_std_ring_mask; |
| 7124 |
dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & |
| 7125 |
tp->rx_std_ring_mask; |
| 7126 |
} |
| 7127 |
|
| 7128 |
while (1) { |
| 7129 |
src_prod_idx = spr->rx_jmb_prod_idx; |
| 7130 |
|
| 7131 |
/* Make sure updates to the rx_jmb_buffers[] entries and |
| 7132 |
* the jumbo producer index are seen in the correct order. |
| 7133 |
*/ |
| 7134 |
smp_rmb(); |
| 7135 |
|
| 7136 |
if (spr->rx_jmb_cons_idx == src_prod_idx) |
| 7137 |
break; |
| 7138 |
|
| 7139 |
if (spr->rx_jmb_cons_idx < src_prod_idx) |
| 7140 |
cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; |
| 7141 |
else |
| 7142 |
cpycnt = tp->rx_jmb_ring_mask + 1 - |
| 7143 |
spr->rx_jmb_cons_idx; |
| 7144 |
|
| 7145 |
cpycnt = min(cpycnt, |
| 7146 |
tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
| 7147 |
|
| 7148 |
si = spr->rx_jmb_cons_idx; |
| 7149 |
di = dpr->rx_jmb_prod_idx; |
| 7150 |
|
| 7151 |
for (i = di; i < di + cpycnt; i++) { |
| 7152 |
if (dpr->rx_jmb_buffers[i].data) { |
| 7153 |
cpycnt = i - di; |
| 7154 |
err = -ENOSPC; |
| 7155 |
break; |
| 7156 |
} |
| 7157 |
} |
| 7158 |
|
| 7159 |
if (!cpycnt) |
| 7160 |
break; |
| 7161 |
|
| 7162 |
/* Ensure that updates to the rx_jmb_buffers ring and the |
| 7163 |
* shadowed hardware producer ring from tg3_recycle_skb() are |
| 7164 |
* ordered correctly WRT the skb check above. |
| 7165 |
*/ |
| 7166 |
smp_rmb(); |
| 7167 |
|
| 7168 |
memcpy(&dpr->rx_jmb_buffers[di], |
| 7169 |
&spr->rx_jmb_buffers[si], |
| 7170 |
cpycnt * sizeof(struct ring_info)); |
| 7171 |
|
| 7172 |
for (i = 0; i < cpycnt; i++, di++, si++) { |
| 7173 |
struct tg3_rx_buffer_desc *sbd, *dbd; |
| 7174 |
sbd = &spr->rx_jmb[si].std; |
| 7175 |
dbd = &dpr->rx_jmb[di].std; |
| 7176 |
dbd->addr_hi = sbd->addr_hi; |
| 7177 |
dbd->addr_lo = sbd->addr_lo; |
| 7178 |
} |
| 7179 |
|
| 7180 |
spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
| 7181 |
tp->rx_jmb_ring_mask; |
| 7182 |
dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & |
| 7183 |
tp->rx_jmb_ring_mask; |
| 7184 |
} |
| 7185 |
|
| 7186 |
return err; |
| 7187 |
} |
| 7188 |
|
| 7189 |
static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
| 7190 |
{ |
| 7191 |
struct tg3 *tp = tnapi->tp; |
| 7192 |
|
| 7193 |
/* run TX completion thread */ |
| 7194 |
if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
| 7195 |
tg3_tx(tnapi); |
| 7196 |
if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
| 7197 |
return work_done; |
| 7198 |
} |
| 7199 |
|
| 7200 |
if (!tnapi->rx_rcb_prod_idx) |
| 7201 |
return work_done; |
| 7202 |
|
| 7203 |
/* run RX thread, within the bounds set by NAPI. |
| 7204 |
* All RX "locking" is done by ensuring outside |
| 7205 |
* code synchronizes with tg3->napi.poll() |
| 7206 |
*/ |
| 7207 |
if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
| 7208 |
work_done += tg3_rx(tnapi, budget - work_done); |
| 7209 |
|
| 7210 |
if (tg3_flag(tp, ENABLE_RSS) && tnapi == &tp->napi[1]) { |
| 7211 |
struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
| 7212 |
int i, err = 0; |
| 7213 |
u32 std_prod_idx = dpr->rx_std_prod_idx; |
| 7214 |
u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; |
| 7215 |
|
| 7216 |
tp->rx_refill = false; |
| 7217 |
for (i = 1; i <= tp->rxq_cnt; i++) |
| 7218 |
err |= tg3_rx_prodring_xfer(tp, dpr, |
| 7219 |
&tp->napi[i].prodring); |
| 7220 |
|
| 7221 |
wmb(); |
| 7222 |
|
| 7223 |
if (std_prod_idx != dpr->rx_std_prod_idx) |
| 7224 |
tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
| 7225 |
dpr->rx_std_prod_idx); |
| 7226 |
|
| 7227 |
if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
| 7228 |
tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
| 7229 |
dpr->rx_jmb_prod_idx); |
| 7230 |
|
| 7231 |
if (err) |
| 7232 |
tw32_f(HOSTCC_MODE, tp->coal_now); |
| 7233 |
} |
| 7234 |
|
| 7235 |
return work_done; |
| 7236 |
} |
| 7237 |
|
| 7238 |
static inline void tg3_reset_task_schedule(struct tg3 *tp) |
| 7239 |
{ |
| 7240 |
if (!test_and_set_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags)) |
| 7241 |
schedule_work(&tp->reset_task); |
| 7242 |
} |
| 7243 |
|
| 7244 |
static inline void tg3_reset_task_cancel(struct tg3 *tp) |
| 7245 |
{ |
| 7246 |
if (test_and_clear_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags)) |
| 7247 |
cancel_work_sync(&tp->reset_task); |
| 7248 |
tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
| 7249 |
} |
| 7250 |
|
| 7251 |
static int tg3_poll_msix(struct napi_struct *napi, int budget) |
| 7252 |
{ |
| 7253 |
struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 7254 |
struct tg3 *tp = tnapi->tp; |
| 7255 |
int work_done = 0; |
| 7256 |
struct tg3_hw_status *sblk = tnapi->hw_status; |
| 7257 |
|
| 7258 |
while (1) { |
| 7259 |
work_done = tg3_poll_work(tnapi, work_done, budget); |
| 7260 |
|
| 7261 |
if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
| 7262 |
goto tx_recovery; |
| 7263 |
|
| 7264 |
if (unlikely(work_done >= budget)) |
| 7265 |
break; |
| 7266 |
|
| 7267 |
/* tp->last_tag is used in tg3_int_reenable() below |
| 7268 |
* to tell the hw how much work has been processed, |
| 7269 |
* so we must read it before checking for more work. |
| 7270 |
*/ |
| 7271 |
tnapi->last_tag = sblk->status_tag; |
| 7272 |
tnapi->last_irq_tag = tnapi->last_tag; |
| 7273 |
rmb(); |
| 7274 |
|
| 7275 |
/* check for RX/TX work to do */ |
| 7276 |
if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
| 7277 |
*(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { |
| 7278 |
|
| 7279 |
/* This test here is not race free, but will reduce |
| 7280 |
* the number of interrupts by looping again. |
| 7281 |
*/ |
| 7282 |
if (tnapi == &tp->napi[1] && tp->rx_refill) |
| 7283 |
continue; |
| 7284 |
|
| 7285 |
napi_complete_done(napi, work_done); |
| 7286 |
/* Reenable interrupts. */ |
| 7287 |
tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
| 7288 |
|
| 7289 |
/* This test here is synchronized by napi_schedule() |
| 7290 |
* and napi_complete() to close the race condition. |
| 7291 |
*/ |
| 7292 |
if (unlikely(tnapi == &tp->napi[1] && tp->rx_refill)) { |
| 7293 |
tw32(HOSTCC_MODE, tp->coalesce_mode | |
| 7294 |
HOSTCC_MODE_ENABLE | |
| 7295 |
tnapi->coal_now); |
| 7296 |
} |
| 7297 |
break; |
| 7298 |
} |
| 7299 |
} |
| 7300 |
|
| 7301 |
tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL << 1); |
| 7302 |
return work_done; |
| 7303 |
|
| 7304 |
tx_recovery: |
| 7305 |
/* work_done is guaranteed to be less than budget. */ |
| 7306 |
napi_complete(napi); |
| 7307 |
tg3_reset_task_schedule(tp); |
| 7308 |
return work_done; |
| 7309 |
} |
| 7310 |
|
| 7311 |
static void tg3_process_error(struct tg3 *tp) |
| 7312 |
{ |
| 7313 |
u32 val; |
| 7314 |
bool real_error = false; |
| 7315 |
|
| 7316 |
if (tg3_flag(tp, ERROR_PROCESSED)) |
| 7317 |
return; |
| 7318 |
|
| 7319 |
/* Check Flow Attention register */ |
| 7320 |
val = tr32(HOSTCC_FLOW_ATTN); |
| 7321 |
if (val & ~HOSTCC_FLOW_ATTN_MBUF_LWM) { |
| 7322 |
netdev_err(tp->dev, "FLOW Attention error. Resetting chip.\n"); |
| 7323 |
real_error = true; |
| 7324 |
} |
| 7325 |
|
| 7326 |
if (tr32(MSGINT_STATUS) & ~MSGINT_STATUS_MSI_REQ) { |
| 7327 |
netdev_err(tp->dev, "MSI Status error. Resetting chip.\n"); |
| 7328 |
real_error = true; |
| 7329 |
} |
| 7330 |
|
| 7331 |
if (tr32(RDMAC_STATUS) || tr32(WDMAC_STATUS)) { |
| 7332 |
netdev_err(tp->dev, "DMA Status error. Resetting chip.\n"); |
| 7333 |
real_error = true; |
| 7334 |
} |
| 7335 |
|
| 7336 |
if (!real_error) |
| 7337 |
return; |
| 7338 |
|
| 7339 |
tg3_dump_state(tp); |
| 7340 |
|
| 7341 |
tg3_flag_set(tp, ERROR_PROCESSED); |
| 7342 |
tg3_reset_task_schedule(tp); |
| 7343 |
} |
| 7344 |
|
| 7345 |
static int tg3_poll(struct napi_struct *napi, int budget) |
| 7346 |
{ |
| 7347 |
struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
| 7348 |
struct tg3 *tp = tnapi->tp; |
| 7349 |
int work_done = 0; |
| 7350 |
struct tg3_hw_status *sblk = tnapi->hw_status; |
| 7351 |
|
| 7352 |
while (1) { |
| 7353 |
if (sblk->status & SD_STATUS_ERROR) |
| 7354 |
tg3_process_error(tp); |
| 7355 |
|
| 7356 |
tg3_poll_link(tp); |
| 7357 |
|
| 7358 |
work_done = tg3_poll_work(tnapi, work_done, budget); |
| 7359 |
|
| 7360 |
if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
| 7361 |
goto tx_recovery; |
| 7362 |
|
| 7363 |
if (unlikely(work_done >= budget)) |
| 7364 |
break; |
| 7365 |
|
| 7366 |
if (tg3_flag(tp, TAGGED_STATUS)) { |
| 7367 |
/* tp->last_tag is used in tg3_int_reenable() below |
| 7368 |
* to tell the hw how much work has been processed, |
| 7369 |
* so we must read it before checking for more work. |
| 7370 |
*/ |
| 7371 |
tnapi->last_tag = sblk->status_tag; |
| 7372 |
tnapi->last_irq_tag = tnapi->last_tag; |
| 7373 |
rmb(); |
| 7374 |
} else |
| 7375 |
sblk->status &= ~SD_STATUS_UPDATED; |
| 7376 |
|
| 7377 |
if (likely(!tg3_has_work(tnapi))) { |
| 7378 |
napi_complete_done(napi, work_done); |
| 7379 |
tg3_int_reenable(tnapi); |
| 7380 |
break; |
| 7381 |
} |
| 7382 |
} |
| 7383 |
|
| 7384 |
tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL << 1); |
| 7385 |
return work_done; |
| 7386 |
|
| 7387 |
tx_recovery: |
| 7388 |
/* work_done is guaranteed to be less than budget. */ |
| 7389 |
napi_complete(napi); |
| 7390 |
tg3_reset_task_schedule(tp); |
| 7391 |
return work_done; |
| 7392 |
} |
| 7393 |
|
| 7394 |
static void tg3_napi_disable(struct tg3 *tp) |
| 7395 |
{ |
| 7396 |
int txq_idx = tp->txq_cnt - 1; |
| 7397 |
int rxq_idx = tp->rxq_cnt - 1; |
| 7398 |
struct tg3_napi *tnapi; |
| 7399 |
int i; |
| 7400 |
|
| 7401 |
for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 7402 |
tnapi = &tp->napi[i]; |
| 7403 |
if (tnapi->tx_buffers) { |
| 7404 |
netif_queue_set_napi(tp->dev, txq_idx, |
| 7405 |
NETDEV_QUEUE_TYPE_TX, NULL); |
| 7406 |
txq_idx--; |
| 7407 |
} |
| 7408 |
if (tnapi->rx_rcb) { |
| 7409 |
netif_queue_set_napi(tp->dev, rxq_idx, |
| 7410 |
NETDEV_QUEUE_TYPE_RX, NULL); |
| 7411 |
rxq_idx--; |
| 7412 |
} |
| 7413 |
napi_disable(&tnapi->napi); |
| 7414 |
} |
| 7415 |
} |
| 7416 |
|
| 7417 |
static void tg3_napi_enable(struct tg3 *tp) |
| 7418 |
{ |
| 7419 |
int txq_idx = 0, rxq_idx = 0; |
| 7420 |
struct tg3_napi *tnapi; |
| 7421 |
int i; |
| 7422 |
|
| 7423 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 7424 |
tnapi = &tp->napi[i]; |
| 7425 |
napi_enable_locked(&tnapi->napi); |
| 7426 |
if (tnapi->tx_buffers) { |
| 7427 |
netif_queue_set_napi(tp->dev, txq_idx, |
| 7428 |
NETDEV_QUEUE_TYPE_TX, |
| 7429 |
&tnapi->napi); |
| 7430 |
txq_idx++; |
| 7431 |
} |
| 7432 |
if (tnapi->rx_rcb) { |
| 7433 |
netif_queue_set_napi(tp->dev, rxq_idx, |
| 7434 |
NETDEV_QUEUE_TYPE_RX, |
| 7435 |
&tnapi->napi); |
| 7436 |
rxq_idx++; |
| 7437 |
} |
| 7438 |
} |
| 7439 |
} |
| 7440 |
|
| 7441 |
static void tg3_napi_init(struct tg3 *tp) |
| 7442 |
{ |
| 7443 |
int i; |
| 7444 |
|
| 7445 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 7446 |
netif_napi_add_locked(tp->dev, &tp->napi[i].napi, |
| 7447 |
i ? tg3_poll_msix : tg3_poll); |
| 7448 |
netif_napi_set_irq_locked(&tp->napi[i].napi, |
| 7449 |
tp->napi[i].irq_vec); |
| 7450 |
} |
| 7451 |
} |
| 7452 |
|
| 7453 |
static void tg3_napi_fini(struct tg3 *tp) |
| 7454 |
{ |
| 7455 |
int i; |
| 7456 |
|
| 7457 |
for (i = 0; i < tp->irq_cnt; i++) |
| 7458 |
netif_napi_del(&tp->napi[i].napi); |
| 7459 |
} |
| 7460 |
|
| 7461 |
static inline void tg3_netif_stop(struct tg3 *tp) |
| 7462 |
{ |
| 7463 |
netif_trans_update(tp->dev); /* prevent tx timeout */ |
| 7464 |
tg3_napi_disable(tp); |
| 7465 |
netif_carrier_off(tp->dev); |
| 7466 |
netif_tx_disable(tp->dev); |
| 7467 |
} |
| 7468 |
|
| 7469 |
/* tp->lock must be held */ |
| 7470 |
static inline void tg3_netif_start(struct tg3 *tp) |
| 7471 |
{ |
| 7472 |
tg3_ptp_resume(tp); |
| 7473 |
|
| 7474 |
/* NOTE: unconditional netif_tx_wake_all_queues is only |
| 7475 |
* appropriate so long as all callers are assured to |
| 7476 |
* have free tx slots (such as after tg3_init_hw) |
| 7477 |
*/ |
| 7478 |
netif_tx_wake_all_queues(tp->dev); |
| 7479 |
|
| 7480 |
if (tp->link_up) |
| 7481 |
netif_carrier_on(tp->dev); |
| 7482 |
|
| 7483 |
tg3_napi_enable(tp); |
| 7484 |
tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; |
| 7485 |
tg3_enable_ints(tp); |
| 7486 |
} |
| 7487 |
|
| 7488 |
static void tg3_irq_quiesce(struct tg3 *tp) |
| 7489 |
__releases(tp->lock) |
| 7490 |
__acquires(tp->lock) |
| 7491 |
{ |
| 7492 |
int i; |
| 7493 |
|
| 7494 |
BUG_ON(tp->irq_sync); |
| 7495 |
|
| 7496 |
tp->irq_sync = 1; |
| 7497 |
smp_mb(); |
| 7498 |
|
| 7499 |
spin_unlock_bh(&tp->lock); |
| 7500 |
|
| 7501 |
for (i = 0; i < tp->irq_cnt; i++) |
| 7502 |
synchronize_irq(tp->napi[i].irq_vec); |
| 7503 |
|
| 7504 |
spin_lock_bh(&tp->lock); |
| 7505 |
} |
| 7506 |
|
| 7507 |
/* Fully shutdown all tg3 driver activity elsewhere in the system. |
| 7508 |
* If irq_sync is non-zero, then the IRQ handler must be synchronized |
| 7509 |
* with as well. Most of the time, this is not necessary except when |
| 7510 |
* shutting down the device. |
| 7511 |
*/ |
| 7512 |
static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) |
| 7513 |
{ |
| 7514 |
spin_lock_bh(&tp->lock); |
| 7515 |
if (irq_sync) |
| 7516 |
tg3_irq_quiesce(tp); |
| 7517 |
} |
| 7518 |
|
| 7519 |
static inline void tg3_full_unlock(struct tg3 *tp) |
| 7520 |
{ |
| 7521 |
spin_unlock_bh(&tp->lock); |
| 7522 |
} |
| 7523 |
|
| 7524 |
/* One-shot MSI handler - Chip automatically disables interrupt |
| 7525 |
* after sending MSI so driver doesn't have to do it. |
| 7526 |
*/ |
| 7527 |
static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
| 7528 |
{ |
| 7529 |
struct tg3_napi *tnapi = dev_id; |
| 7530 |
struct tg3 *tp = tnapi->tp; |
| 7531 |
|
| 7532 |
prefetch(tnapi->hw_status); |
| 7533 |
if (tnapi->rx_rcb) |
| 7534 |
prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
| 7535 |
|
| 7536 |
if (likely(!tg3_irq_sync(tp))) |
| 7537 |
napi_schedule(&tnapi->napi); |
| 7538 |
|
| 7539 |
return IRQ_HANDLED; |
| 7540 |
} |
| 7541 |
|
| 7542 |
/* MSI ISR - No need to check for interrupt sharing and no need to |
| 7543 |
* flush status block and interrupt mailbox. PCI ordering rules |
| 7544 |
* guarantee that MSI will arrive after the status block. |
| 7545 |
*/ |
| 7546 |
static irqreturn_t tg3_msi(int irq, void *dev_id) |
| 7547 |
{ |
| 7548 |
struct tg3_napi *tnapi = dev_id; |
| 7549 |
struct tg3 *tp = tnapi->tp; |
| 7550 |
|
| 7551 |
prefetch(tnapi->hw_status); |
| 7552 |
if (tnapi->rx_rcb) |
| 7553 |
prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
| 7554 |
/* |
| 7555 |
* Writing any value to intr-mbox-0 clears PCI INTA# and |
| 7556 |
* chip-internal interrupt pending events. |
| 7557 |
* Writing non-zero to intr-mbox-0 additional tells the |
| 7558 |
* NIC to stop sending us irqs, engaging "in-intr-handler" |
| 7559 |
* event coalescing. |
| 7560 |
*/ |
| 7561 |
tw32_mailbox(tnapi->int_mbox, 0x00000001); |
| 7562 |
if (likely(!tg3_irq_sync(tp))) |
| 7563 |
napi_schedule(&tnapi->napi); |
| 7564 |
|
| 7565 |
return IRQ_RETVAL(1); |
| 7566 |
} |
| 7567 |
|
| 7568 |
static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
| 7569 |
{ |
| 7570 |
struct tg3_napi *tnapi = dev_id; |
| 7571 |
struct tg3 *tp = tnapi->tp; |
| 7572 |
struct tg3_hw_status *sblk = tnapi->hw_status; |
| 7573 |
unsigned int handled = 1; |
| 7574 |
|
| 7575 |
/* In INTx mode, it is possible for the interrupt to arrive at |
| 7576 |
* the CPU before the status block posted prior to the interrupt. |
| 7577 |
* Reading the PCI State register will confirm whether the |
| 7578 |
* interrupt is ours and will flush the status block. |
| 7579 |
*/ |
| 7580 |
if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
| 7581 |
if (tg3_flag(tp, CHIP_RESETTING) || |
| 7582 |
(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 7583 |
handled = 0; |
| 7584 |
goto out; |
| 7585 |
} |
| 7586 |
} |
| 7587 |
|
| 7588 |
/* |
| 7589 |
* Writing any value to intr-mbox-0 clears PCI INTA# and |
| 7590 |
* chip-internal interrupt pending events. |
| 7591 |
* Writing non-zero to intr-mbox-0 additional tells the |
| 7592 |
* NIC to stop sending us irqs, engaging "in-intr-handler" |
| 7593 |
* event coalescing. |
| 7594 |
* |
| 7595 |
* Flush the mailbox to de-assert the IRQ immediately to prevent |
| 7596 |
* spurious interrupts. The flush impacts performance but |
| 7597 |
* excessive spurious interrupts can be worse in some cases. |
| 7598 |
*/ |
| 7599 |
tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
| 7600 |
if (tg3_irq_sync(tp)) |
| 7601 |
goto out; |
| 7602 |
sblk->status &= ~SD_STATUS_UPDATED; |
| 7603 |
if (likely(tg3_has_work(tnapi))) { |
| 7604 |
prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
| 7605 |
napi_schedule(&tnapi->napi); |
| 7606 |
} else { |
| 7607 |
/* No work, shared interrupt perhaps? re-enable |
| 7608 |
* interrupts, and flush that PCI write |
| 7609 |
*/ |
| 7610 |
tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, |
| 7611 |
0x00000000); |
| 7612 |
} |
| 7613 |
out: |
| 7614 |
return IRQ_RETVAL(handled); |
| 7615 |
} |
| 7616 |
|
| 7617 |
static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
| 7618 |
{ |
| 7619 |
struct tg3_napi *tnapi = dev_id; |
| 7620 |
struct tg3 *tp = tnapi->tp; |
| 7621 |
struct tg3_hw_status *sblk = tnapi->hw_status; |
| 7622 |
unsigned int handled = 1; |
| 7623 |
|
| 7624 |
/* In INTx mode, it is possible for the interrupt to arrive at |
| 7625 |
* the CPU before the status block posted prior to the interrupt. |
| 7626 |
* Reading the PCI State register will confirm whether the |
| 7627 |
* interrupt is ours and will flush the status block. |
| 7628 |
*/ |
| 7629 |
if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
| 7630 |
if (tg3_flag(tp, CHIP_RESETTING) || |
| 7631 |
(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 7632 |
handled = 0; |
| 7633 |
goto out; |
| 7634 |
} |
| 7635 |
} |
| 7636 |
|
| 7637 |
/* |
| 7638 |
* writing any value to intr-mbox-0 clears PCI INTA# and |
| 7639 |
* chip-internal interrupt pending events. |
| 7640 |
* writing non-zero to intr-mbox-0 additional tells the |
| 7641 |
* NIC to stop sending us irqs, engaging "in-intr-handler" |
| 7642 |
* event coalescing. |
| 7643 |
* |
| 7644 |
* Flush the mailbox to de-assert the IRQ immediately to prevent |
| 7645 |
* spurious interrupts. The flush impacts performance but |
| 7646 |
* excessive spurious interrupts can be worse in some cases. |
| 7647 |
*/ |
| 7648 |
tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
| 7649 |
|
| 7650 |
/* |
| 7651 |
* In a shared interrupt configuration, sometimes other devices' |
| 7652 |
* interrupts will scream. We record the current status tag here |
| 7653 |
* so that the above check can report that the screaming interrupts |
| 7654 |
* are unhandled. Eventually they will be silenced. |
| 7655 |
*/ |
| 7656 |
tnapi->last_irq_tag = sblk->status_tag; |
| 7657 |
|
| 7658 |
if (tg3_irq_sync(tp)) |
| 7659 |
goto out; |
| 7660 |
|
| 7661 |
prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
| 7662 |
|
| 7663 |
napi_schedule(&tnapi->napi); |
| 7664 |
|
| 7665 |
out: |
| 7666 |
return IRQ_RETVAL(handled); |
| 7667 |
} |
| 7668 |
|
| 7669 |
/* ISR for interrupt test */ |
| 7670 |
static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
| 7671 |
{ |
| 7672 |
struct tg3_napi *tnapi = dev_id; |
| 7673 |
struct tg3 *tp = tnapi->tp; |
| 7674 |
struct tg3_hw_status *sblk = tnapi->hw_status; |
| 7675 |
|
| 7676 |
if ((sblk->status & SD_STATUS_UPDATED) || |
| 7677 |
!(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
| 7678 |
tg3_disable_ints(tp); |
| 7679 |
return IRQ_RETVAL(1); |
| 7680 |
} |
| 7681 |
return IRQ_RETVAL(0); |
| 7682 |
} |
| 7683 |
|
| 7684 |
#ifdef CONFIG_NET_POLL_CONTROLLER |
| 7685 |
static void tg3_poll_controller(struct net_device *dev) |
| 7686 |
{ |
| 7687 |
int i; |
| 7688 |
struct tg3 *tp = netdev_priv(dev); |
| 7689 |
|
| 7690 |
if (tg3_irq_sync(tp)) |
| 7691 |
return; |
| 7692 |
|
| 7693 |
for (i = 0; i < tp->irq_cnt; i++) |
| 7694 |
tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
| 7695 |
} |
| 7696 |
#endif |
| 7697 |
|
| 7698 |
static void tg3_tx_timeout(struct net_device *dev, unsigned int txqueue) |
| 7699 |
{ |
| 7700 |
struct tg3 *tp = netdev_priv(dev); |
| 7701 |
|
| 7702 |
if (netif_msg_tx_err(tp)) { |
| 7703 |
netdev_err(dev, "transmit timed out, resetting\n"); |
| 7704 |
tg3_dump_state(tp); |
| 7705 |
} |
| 7706 |
|
| 7707 |
tg3_reset_task_schedule(tp); |
| 7708 |
} |
| 7709 |
|
| 7710 |
/* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
| 7711 |
static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) |
| 7712 |
{ |
| 7713 |
u32 base = (u32) mapping & 0xffffffff; |
| 7714 |
|
| 7715 |
return base + len + 8 < base; |
| 7716 |
} |
| 7717 |
|
| 7718 |
/* Test for TSO DMA buffers that cross into regions which are within MSS bytes |
| 7719 |
* of any 4GB boundaries: 4G, 8G, etc |
| 7720 |
*/ |
| 7721 |
static inline int tg3_4g_tso_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 7722 |
u32 len, u32 mss) |
| 7723 |
{ |
| 7724 |
if (tg3_asic_rev(tp) == ASIC_REV_5762 && mss) { |
| 7725 |
u32 base = (u32) mapping & 0xffffffff; |
| 7726 |
|
| 7727 |
return ((base + len + (mss & 0x3fff)) < base); |
| 7728 |
} |
| 7729 |
return 0; |
| 7730 |
} |
| 7731 |
|
| 7732 |
/* Test for DMA addresses > 40-bit */ |
| 7733 |
static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, |
| 7734 |
int len) |
| 7735 |
{ |
| 7736 |
#if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) |
| 7737 |
if (tg3_flag(tp, 40BIT_DMA_BUG)) |
| 7738 |
return ((u64) mapping + len) > DMA_BIT_MASK(40); |
| 7739 |
return 0; |
| 7740 |
#else |
| 7741 |
return 0; |
| 7742 |
#endif |
| 7743 |
} |
| 7744 |
|
| 7745 |
static inline void tg3_tx_set_bd(struct tg3_tx_buffer_desc *txbd, |
| 7746 |
dma_addr_t mapping, u32 len, u32 flags, |
| 7747 |
u32 mss, u32 vlan) |
| 7748 |
{ |
| 7749 |
txbd->addr_hi = ((u64) mapping >> 32); |
| 7750 |
txbd->addr_lo = ((u64) mapping & 0xffffffff); |
| 7751 |
txbd->len_flags = (len << TXD_LEN_SHIFT) | (flags & 0x0000ffff); |
| 7752 |
txbd->vlan_tag = (mss << TXD_MSS_SHIFT) | (vlan << TXD_VLAN_TAG_SHIFT); |
| 7753 |
} |
| 7754 |
|
| 7755 |
static bool tg3_tx_frag_set(struct tg3_napi *tnapi, u32 *entry, u32 *budget, |
| 7756 |
dma_addr_t map, u32 len, u32 flags, |
| 7757 |
u32 mss, u32 vlan) |
| 7758 |
{ |
| 7759 |
struct tg3 *tp = tnapi->tp; |
| 7760 |
bool hwbug = false; |
| 7761 |
|
| 7762 |
if (tg3_flag(tp, SHORT_DMA_BUG) && len <= 8) |
| 7763 |
hwbug = true; |
| 7764 |
|
| 7765 |
if (tg3_4g_overflow_test(map, len)) |
| 7766 |
hwbug = true; |
| 7767 |
|
| 7768 |
if (tg3_4g_tso_overflow_test(tp, map, len, mss)) |
| 7769 |
hwbug = true; |
| 7770 |
|
| 7771 |
if (tg3_40bit_overflow_test(tp, map, len)) |
| 7772 |
hwbug = true; |
| 7773 |
|
| 7774 |
if (tp->dma_limit) { |
| 7775 |
u32 prvidx = *entry; |
| 7776 |
u32 tmp_flag = flags & ~TXD_FLAG_END; |
| 7777 |
while (len > tp->dma_limit && *budget) { |
| 7778 |
u32 frag_len = tp->dma_limit; |
| 7779 |
len -= tp->dma_limit; |
| 7780 |
|
| 7781 |
/* Avoid the 8byte DMA problem */ |
| 7782 |
if (len <= 8) { |
| 7783 |
len += tp->dma_limit / 2; |
| 7784 |
frag_len = tp->dma_limit / 2; |
| 7785 |
} |
| 7786 |
|
| 7787 |
tnapi->tx_buffers[*entry].fragmented = true; |
| 7788 |
|
| 7789 |
tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 7790 |
frag_len, tmp_flag, mss, vlan); |
| 7791 |
*budget -= 1; |
| 7792 |
prvidx = *entry; |
| 7793 |
*entry = NEXT_TX(*entry); |
| 7794 |
|
| 7795 |
map += frag_len; |
| 7796 |
} |
| 7797 |
|
| 7798 |
if (len) { |
| 7799 |
if (*budget) { |
| 7800 |
tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 7801 |
len, flags, mss, vlan); |
| 7802 |
*budget -= 1; |
| 7803 |
*entry = NEXT_TX(*entry); |
| 7804 |
} else { |
| 7805 |
hwbug = true; |
| 7806 |
tnapi->tx_buffers[prvidx].fragmented = false; |
| 7807 |
} |
| 7808 |
} |
| 7809 |
} else { |
| 7810 |
tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
| 7811 |
len, flags, mss, vlan); |
| 7812 |
*entry = NEXT_TX(*entry); |
| 7813 |
} |
| 7814 |
|
| 7815 |
return hwbug; |
| 7816 |
} |
| 7817 |
|
| 7818 |
static void tg3_tx_skb_unmap(struct tg3_napi *tnapi, u32 entry, int last) |
| 7819 |
{ |
| 7820 |
int i; |
| 7821 |
struct sk_buff *skb; |
| 7822 |
struct tg3_tx_ring_info *txb = &tnapi->tx_buffers[entry]; |
| 7823 |
|
| 7824 |
skb = txb->skb; |
| 7825 |
txb->skb = NULL; |
| 7826 |
|
| 7827 |
dma_unmap_single(&tnapi->tp->pdev->dev, dma_unmap_addr(txb, mapping), |
| 7828 |
skb_headlen(skb), DMA_TO_DEVICE); |
| 7829 |
|
| 7830 |
while (txb->fragmented) { |
| 7831 |
txb->fragmented = false; |
| 7832 |
entry = NEXT_TX(entry); |
| 7833 |
txb = &tnapi->tx_buffers[entry]; |
| 7834 |
} |
| 7835 |
|
| 7836 |
for (i = 0; i <= last; i++) { |
| 7837 |
const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 7838 |
|
| 7839 |
entry = NEXT_TX(entry); |
| 7840 |
txb = &tnapi->tx_buffers[entry]; |
| 7841 |
|
| 7842 |
dma_unmap_page(&tnapi->tp->pdev->dev, |
| 7843 |
dma_unmap_addr(txb, mapping), |
| 7844 |
skb_frag_size(frag), DMA_TO_DEVICE); |
| 7845 |
|
| 7846 |
while (txb->fragmented) { |
| 7847 |
txb->fragmented = false; |
| 7848 |
entry = NEXT_TX(entry); |
| 7849 |
txb = &tnapi->tx_buffers[entry]; |
| 7850 |
} |
| 7851 |
} |
| 7852 |
} |
| 7853 |
|
| 7854 |
/* Workaround 4GB and 40-bit hardware DMA bugs. */ |
| 7855 |
static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
| 7856 |
struct sk_buff **pskb, |
| 7857 |
u32 *entry, u32 *budget, |
| 7858 |
u32 base_flags, u32 mss, u32 vlan) |
| 7859 |
{ |
| 7860 |
struct tg3 *tp = tnapi->tp; |
| 7861 |
struct sk_buff *new_skb, *skb = *pskb; |
| 7862 |
dma_addr_t new_addr = 0; |
| 7863 |
int ret = 0; |
| 7864 |
|
| 7865 |
if (tg3_asic_rev(tp) != ASIC_REV_5701) |
| 7866 |
new_skb = skb_copy(skb, GFP_ATOMIC); |
| 7867 |
else { |
| 7868 |
int more_headroom = 4 - ((unsigned long)skb->data & 3); |
| 7869 |
|
| 7870 |
new_skb = skb_copy_expand(skb, |
| 7871 |
skb_headroom(skb) + more_headroom, |
| 7872 |
skb_tailroom(skb), GFP_ATOMIC); |
| 7873 |
} |
| 7874 |
|
| 7875 |
if (!new_skb) { |
| 7876 |
ret = -1; |
| 7877 |
} else { |
| 7878 |
/* New SKB is guaranteed to be linear. */ |
| 7879 |
new_addr = dma_map_single(&tp->pdev->dev, new_skb->data, |
| 7880 |
new_skb->len, DMA_TO_DEVICE); |
| 7881 |
/* Make sure the mapping succeeded */ |
| 7882 |
if (dma_mapping_error(&tp->pdev->dev, new_addr)) { |
| 7883 |
dev_kfree_skb_any(new_skb); |
| 7884 |
ret = -1; |
| 7885 |
} else { |
| 7886 |
u32 save_entry = *entry; |
| 7887 |
|
| 7888 |
base_flags |= TXD_FLAG_END; |
| 7889 |
|
| 7890 |
tnapi->tx_buffers[*entry].skb = new_skb; |
| 7891 |
dma_unmap_addr_set(&tnapi->tx_buffers[*entry], |
| 7892 |
mapping, new_addr); |
| 7893 |
|
| 7894 |
if (tg3_tx_frag_set(tnapi, entry, budget, new_addr, |
| 7895 |
new_skb->len, base_flags, |
| 7896 |
mss, vlan)) { |
| 7897 |
tg3_tx_skb_unmap(tnapi, save_entry, -1); |
| 7898 |
dev_kfree_skb_any(new_skb); |
| 7899 |
ret = -1; |
| 7900 |
} |
| 7901 |
} |
| 7902 |
} |
| 7903 |
|
| 7904 |
dev_consume_skb_any(skb); |
| 7905 |
*pskb = new_skb; |
| 7906 |
return ret; |
| 7907 |
} |
| 7908 |
|
| 7909 |
static bool tg3_tso_bug_gso_check(struct tg3_napi *tnapi, struct sk_buff *skb) |
| 7910 |
{ |
| 7911 |
/* Check if we will never have enough descriptors, |
| 7912 |
* as gso_segs can be more than current ring size |
| 7913 |
*/ |
| 7914 |
return skb_shinfo(skb)->gso_segs < tnapi->tx_pending / 3; |
| 7915 |
} |
| 7916 |
|
| 7917 |
static netdev_tx_t __tg3_start_xmit(struct sk_buff *, struct net_device *); |
| 7918 |
|
| 7919 |
/* Use GSO to workaround all TSO packets that meet HW bug conditions |
| 7920 |
* indicated in tg3_tx_frag_set() |
| 7921 |
*/ |
| 7922 |
static int tg3_tso_bug(struct tg3 *tp, struct tg3_napi *tnapi, |
| 7923 |
struct netdev_queue *txq, struct sk_buff *skb) |
| 7924 |
{ |
| 7925 |
u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
| 7926 |
struct sk_buff *segs, *seg, *next; |
| 7927 |
|
| 7928 |
/* Estimate the number of fragments in the worst case */ |
| 7929 |
if (unlikely(tg3_tx_avail(tnapi) <= frag_cnt_est)) { |
| 7930 |
netif_tx_stop_queue(txq); |
| 7931 |
|
| 7932 |
/* netif_tx_stop_queue() must be done before checking |
| 7933 |
* checking tx index in tg3_tx_avail() below, because in |
| 7934 |
* tg3_tx(), we update tx index before checking for |
| 7935 |
* netif_tx_queue_stopped(). |
| 7936 |
*/ |
| 7937 |
smp_mb(); |
| 7938 |
if (tg3_tx_avail(tnapi) <= frag_cnt_est) |
| 7939 |
return NETDEV_TX_BUSY; |
| 7940 |
|
| 7941 |
netif_tx_wake_queue(txq); |
| 7942 |
} |
| 7943 |
|
| 7944 |
segs = skb_gso_segment(skb, tp->dev->features & |
| 7945 |
~(NETIF_F_TSO | NETIF_F_TSO6)); |
| 7946 |
if (IS_ERR(segs) || !segs) { |
| 7947 |
tnapi->tx_dropped++; |
| 7948 |
goto tg3_tso_bug_end; |
| 7949 |
} |
| 7950 |
|
| 7951 |
skb_list_walk_safe(segs, seg, next) { |
| 7952 |
skb_mark_not_on_list(seg); |
| 7953 |
__tg3_start_xmit(seg, tp->dev); |
| 7954 |
} |
| 7955 |
|
| 7956 |
tg3_tso_bug_end: |
| 7957 |
dev_consume_skb_any(skb); |
| 7958 |
|
| 7959 |
return NETDEV_TX_OK; |
| 7960 |
} |
| 7961 |
|
| 7962 |
/* hard_start_xmit for all devices */ |
| 7963 |
static netdev_tx_t __tg3_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 7964 |
{ |
| 7965 |
struct tg3 *tp = netdev_priv(dev); |
| 7966 |
u32 len, entry, base_flags, mss, vlan = 0; |
| 7967 |
u32 budget; |
| 7968 |
int i = -1, would_hit_hwbug; |
| 7969 |
dma_addr_t mapping; |
| 7970 |
struct tg3_napi *tnapi; |
| 7971 |
struct netdev_queue *txq; |
| 7972 |
unsigned int last; |
| 7973 |
struct iphdr *iph = NULL; |
| 7974 |
struct tcphdr *tcph = NULL; |
| 7975 |
__sum16 tcp_csum = 0, ip_csum = 0; |
| 7976 |
__be16 ip_tot_len = 0; |
| 7977 |
|
| 7978 |
txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
| 7979 |
tnapi = &tp->napi[skb_get_queue_mapping(skb)]; |
| 7980 |
if (tg3_flag(tp, ENABLE_TSS)) |
| 7981 |
tnapi++; |
| 7982 |
|
| 7983 |
budget = tg3_tx_avail(tnapi); |
| 7984 |
|
| 7985 |
/* We are running in BH disabled context with netif_tx_lock |
| 7986 |
* and TX reclaim runs via tp->napi.poll inside of a software |
| 7987 |
* interrupt. Furthermore, IRQ processing runs lockless so we have |
| 7988 |
* no IRQ context deadlocks to worry about either. Rejoice! |
| 7989 |
*/ |
| 7990 |
if (unlikely(budget <= (skb_shinfo(skb)->nr_frags + 1))) { |
| 7991 |
if (!netif_tx_queue_stopped(txq)) { |
| 7992 |
netif_tx_stop_queue(txq); |
| 7993 |
|
| 7994 |
/* This is a hard error, log it. */ |
| 7995 |
netdev_err(dev, |
| 7996 |
"BUG! Tx Ring full when queue awake!\n"); |
| 7997 |
} |
| 7998 |
return NETDEV_TX_BUSY; |
| 7999 |
} |
| 8000 |
|
| 8001 |
entry = tnapi->tx_prod; |
| 8002 |
base_flags = 0; |
| 8003 |
|
| 8004 |
mss = skb_shinfo(skb)->gso_size; |
| 8005 |
if (mss) { |
| 8006 |
u32 tcp_opt_len, hdr_len; |
| 8007 |
|
| 8008 |
if (skb_cow_head(skb, 0)) |
| 8009 |
goto drop; |
| 8010 |
|
| 8011 |
iph = ip_hdr(skb); |
| 8012 |
tcp_opt_len = tcp_optlen(skb); |
| 8013 |
|
| 8014 |
hdr_len = skb_tcp_all_headers(skb) - ETH_HLEN; |
| 8015 |
|
| 8016 |
/* HW/FW can not correctly segment packets that have been |
| 8017 |
* vlan encapsulated. |
| 8018 |
*/ |
| 8019 |
if (skb->protocol == htons(ETH_P_8021Q) || |
| 8020 |
skb->protocol == htons(ETH_P_8021AD)) { |
| 8021 |
if (tg3_tso_bug_gso_check(tnapi, skb)) |
| 8022 |
return tg3_tso_bug(tp, tnapi, txq, skb); |
| 8023 |
goto drop; |
| 8024 |
} |
| 8025 |
|
| 8026 |
if (!skb_is_gso_v6(skb)) { |
| 8027 |
if (unlikely((ETH_HLEN + hdr_len) > 80) && |
| 8028 |
tg3_flag(tp, TSO_BUG)) { |
| 8029 |
if (tg3_tso_bug_gso_check(tnapi, skb)) |
| 8030 |
return tg3_tso_bug(tp, tnapi, txq, skb); |
| 8031 |
goto drop; |
| 8032 |
} |
| 8033 |
ip_csum = iph->check; |
| 8034 |
ip_tot_len = iph->tot_len; |
| 8035 |
iph->check = 0; |
| 8036 |
iph->tot_len = htons(mss + hdr_len); |
| 8037 |
} |
| 8038 |
|
| 8039 |
base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
| 8040 |
TXD_FLAG_CPU_POST_DMA); |
| 8041 |
|
| 8042 |
tcph = tcp_hdr(skb); |
| 8043 |
tcp_csum = tcph->check; |
| 8044 |
|
| 8045 |
if (tg3_flag(tp, HW_TSO_1) || |
| 8046 |
tg3_flag(tp, HW_TSO_2) || |
| 8047 |
tg3_flag(tp, HW_TSO_3)) { |
| 8048 |
tcph->check = 0; |
| 8049 |
base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
| 8050 |
} else { |
| 8051 |
tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
| 8052 |
0, IPPROTO_TCP, 0); |
| 8053 |
} |
| 8054 |
|
| 8055 |
if (tg3_flag(tp, HW_TSO_3)) { |
| 8056 |
mss |= (hdr_len & 0xc) << 12; |
| 8057 |
if (hdr_len & 0x10) |
| 8058 |
base_flags |= 0x00000010; |
| 8059 |
base_flags |= (hdr_len & 0x3e0) << 5; |
| 8060 |
} else if (tg3_flag(tp, HW_TSO_2)) |
| 8061 |
mss |= hdr_len << 9; |
| 8062 |
else if (tg3_flag(tp, HW_TSO_1) || |
| 8063 |
tg3_asic_rev(tp) == ASIC_REV_5705) { |
| 8064 |
if (tcp_opt_len || iph->ihl > 5) { |
| 8065 |
int tsflags; |
| 8066 |
|
| 8067 |
tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
| 8068 |
mss |= (tsflags << 11); |
| 8069 |
} |
| 8070 |
} else { |
| 8071 |
if (tcp_opt_len || iph->ihl > 5) { |
| 8072 |
int tsflags; |
| 8073 |
|
| 8074 |
tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
| 8075 |
base_flags |= tsflags << 12; |
| 8076 |
} |
| 8077 |
} |
| 8078 |
} else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 8079 |
/* HW/FW can not correctly checksum packets that have been |
| 8080 |
* vlan encapsulated. |
| 8081 |
*/ |
| 8082 |
if (skb->protocol == htons(ETH_P_8021Q) || |
| 8083 |
skb->protocol == htons(ETH_P_8021AD)) { |
| 8084 |
if (skb_checksum_help(skb)) |
| 8085 |
goto drop; |
| 8086 |
} else { |
| 8087 |
base_flags |= TXD_FLAG_TCPUDP_CSUM; |
| 8088 |
} |
| 8089 |
} |
| 8090 |
|
| 8091 |
if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 8092 |
!mss && skb->len > VLAN_ETH_FRAME_LEN) |
| 8093 |
base_flags |= TXD_FLAG_JMB_PKT; |
| 8094 |
|
| 8095 |
if (skb_vlan_tag_present(skb)) { |
| 8096 |
base_flags |= TXD_FLAG_VLAN; |
| 8097 |
vlan = skb_vlan_tag_get(skb); |
| 8098 |
} |
| 8099 |
|
| 8100 |
if ((unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) && |
| 8101 |
tg3_flag(tp, TX_TSTAMP_EN)) { |
| 8102 |
tg3_full_lock(tp, 0); |
| 8103 |
if (!tp->pre_tx_ts) { |
| 8104 |
skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 8105 |
base_flags |= TXD_FLAG_HWTSTAMP; |
| 8106 |
tg3_read_tx_tstamp(tp, &tp->pre_tx_ts); |
| 8107 |
} |
| 8108 |
tg3_full_unlock(tp); |
| 8109 |
} |
| 8110 |
|
| 8111 |
len = skb_headlen(skb); |
| 8112 |
|
| 8113 |
mapping = dma_map_single(&tp->pdev->dev, skb->data, len, |
| 8114 |
DMA_TO_DEVICE); |
| 8115 |
if (dma_mapping_error(&tp->pdev->dev, mapping)) |
| 8116 |
goto drop; |
| 8117 |
|
| 8118 |
|
| 8119 |
tnapi->tx_buffers[entry].skb = skb; |
| 8120 |
dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
| 8121 |
|
| 8122 |
would_hit_hwbug = 0; |
| 8123 |
|
| 8124 |
if (tg3_flag(tp, 5701_DMA_BUG)) |
| 8125 |
would_hit_hwbug = 1; |
| 8126 |
|
| 8127 |
if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, len, base_flags | |
| 8128 |
((skb_shinfo(skb)->nr_frags == 0) ? TXD_FLAG_END : 0), |
| 8129 |
mss, vlan)) { |
| 8130 |
would_hit_hwbug = 1; |
| 8131 |
} else if (skb_shinfo(skb)->nr_frags > 0) { |
| 8132 |
u32 tmp_mss = mss; |
| 8133 |
|
| 8134 |
if (!tg3_flag(tp, HW_TSO_1) && |
| 8135 |
!tg3_flag(tp, HW_TSO_2) && |
| 8136 |
!tg3_flag(tp, HW_TSO_3)) |
| 8137 |
tmp_mss = 0; |
| 8138 |
|
| 8139 |
/* Now loop through additional data |
| 8140 |
* fragments, and queue them. |
| 8141 |
*/ |
| 8142 |
last = skb_shinfo(skb)->nr_frags - 1; |
| 8143 |
for (i = 0; i <= last; i++) { |
| 8144 |
skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 8145 |
|
| 8146 |
len = skb_frag_size(frag); |
| 8147 |
mapping = skb_frag_dma_map(&tp->pdev->dev, frag, 0, |
| 8148 |
len, DMA_TO_DEVICE); |
| 8149 |
|
| 8150 |
tnapi->tx_buffers[entry].skb = NULL; |
| 8151 |
dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
| 8152 |
mapping); |
| 8153 |
if (dma_mapping_error(&tp->pdev->dev, mapping)) |
| 8154 |
goto dma_error; |
| 8155 |
|
| 8156 |
if (!budget || |
| 8157 |
tg3_tx_frag_set(tnapi, &entry, &budget, mapping, |
| 8158 |
len, base_flags | |
| 8159 |
((i == last) ? TXD_FLAG_END : 0), |
| 8160 |
tmp_mss, vlan)) { |
| 8161 |
would_hit_hwbug = 1; |
| 8162 |
break; |
| 8163 |
} |
| 8164 |
} |
| 8165 |
} |
| 8166 |
|
| 8167 |
if (would_hit_hwbug) { |
| 8168 |
tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, i); |
| 8169 |
|
| 8170 |
if (mss && tg3_tso_bug_gso_check(tnapi, skb)) { |
| 8171 |
/* If it's a TSO packet, do GSO instead of |
| 8172 |
* allocating and copying to a large linear SKB |
| 8173 |
*/ |
| 8174 |
if (ip_tot_len) { |
| 8175 |
iph->check = ip_csum; |
| 8176 |
iph->tot_len = ip_tot_len; |
| 8177 |
} |
| 8178 |
tcph->check = tcp_csum; |
| 8179 |
return tg3_tso_bug(tp, tnapi, txq, skb); |
| 8180 |
} |
| 8181 |
|
| 8182 |
/* If the workaround fails due to memory/mapping |
| 8183 |
* failure, silently drop this packet. |
| 8184 |
*/ |
| 8185 |
entry = tnapi->tx_prod; |
| 8186 |
budget = tg3_tx_avail(tnapi); |
| 8187 |
if (tigon3_dma_hwbug_workaround(tnapi, &skb, &entry, &budget, |
| 8188 |
base_flags, mss, vlan)) |
| 8189 |
goto drop_nofree; |
| 8190 |
} |
| 8191 |
|
| 8192 |
skb_tx_timestamp(skb); |
| 8193 |
netdev_tx_sent_queue(txq, skb->len); |
| 8194 |
|
| 8195 |
/* Sync BD data before updating mailbox */ |
| 8196 |
wmb(); |
| 8197 |
|
| 8198 |
tnapi->tx_prod = entry; |
| 8199 |
if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { |
| 8200 |
netif_tx_stop_queue(txq); |
| 8201 |
|
| 8202 |
/* netif_tx_stop_queue() must be done before checking |
| 8203 |
* checking tx index in tg3_tx_avail() below, because in |
| 8204 |
* tg3_tx(), we update tx index before checking for |
| 8205 |
* netif_tx_queue_stopped(). |
| 8206 |
*/ |
| 8207 |
smp_mb(); |
| 8208 |
if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
| 8209 |
netif_tx_wake_queue(txq); |
| 8210 |
} |
| 8211 |
|
| 8212 |
return NETDEV_TX_OK; |
| 8213 |
|
| 8214 |
dma_error: |
| 8215 |
tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, --i); |
| 8216 |
tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; |
| 8217 |
drop: |
| 8218 |
dev_kfree_skb_any(skb); |
| 8219 |
drop_nofree: |
| 8220 |
tnapi->tx_dropped++; |
| 8221 |
return NETDEV_TX_OK; |
| 8222 |
} |
| 8223 |
|
| 8224 |
static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 8225 |
{ |
| 8226 |
struct netdev_queue *txq; |
| 8227 |
u16 skb_queue_mapping; |
| 8228 |
netdev_tx_t ret; |
| 8229 |
|
| 8230 |
skb_queue_mapping = skb_get_queue_mapping(skb); |
| 8231 |
txq = netdev_get_tx_queue(dev, skb_queue_mapping); |
| 8232 |
|
| 8233 |
ret = __tg3_start_xmit(skb, dev); |
| 8234 |
|
| 8235 |
/* Notify the hardware that packets are ready by updating the TX ring |
| 8236 |
* tail pointer. We respect netdev_xmit_more() thus avoiding poking |
| 8237 |
* the hardware for every packet. To guarantee forward progress the TX |
| 8238 |
* ring must be drained when it is full as indicated by |
| 8239 |
* netif_xmit_stopped(). This needs to happen even when the current |
| 8240 |
* skb was dropped or rejected with NETDEV_TX_BUSY. Otherwise packets |
| 8241 |
* queued by previous __tg3_start_xmit() calls might get stuck in |
| 8242 |
* the queue forever. |
| 8243 |
*/ |
| 8244 |
if (!netdev_xmit_more() || netif_xmit_stopped(txq)) { |
| 8245 |
struct tg3_napi *tnapi; |
| 8246 |
struct tg3 *tp; |
| 8247 |
|
| 8248 |
tp = netdev_priv(dev); |
| 8249 |
tnapi = &tp->napi[skb_queue_mapping]; |
| 8250 |
|
| 8251 |
if (tg3_flag(tp, ENABLE_TSS)) |
| 8252 |
tnapi++; |
| 8253 |
|
| 8254 |
tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 8255 |
} |
| 8256 |
|
| 8257 |
return ret; |
| 8258 |
} |
| 8259 |
|
| 8260 |
static void tg3_mac_loopback(struct tg3 *tp, bool enable) |
| 8261 |
{ |
| 8262 |
if (enable) { |
| 8263 |
tp->mac_mode &= ~(MAC_MODE_HALF_DUPLEX | |
| 8264 |
MAC_MODE_PORT_MODE_MASK); |
| 8265 |
|
| 8266 |
tp->mac_mode |= MAC_MODE_PORT_INT_LPBACK; |
| 8267 |
|
| 8268 |
if (!tg3_flag(tp, 5705_PLUS)) |
| 8269 |
tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
| 8270 |
|
| 8271 |
if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 8272 |
tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 8273 |
else |
| 8274 |
tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 8275 |
} else { |
| 8276 |
tp->mac_mode &= ~MAC_MODE_PORT_INT_LPBACK; |
| 8277 |
|
| 8278 |
if (tg3_flag(tp, 5705_PLUS) || |
| 8279 |
(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) || |
| 8280 |
tg3_asic_rev(tp) == ASIC_REV_5700) |
| 8281 |
tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 8282 |
} |
| 8283 |
|
| 8284 |
tw32(MAC_MODE, tp->mac_mode); |
| 8285 |
udelay(40); |
| 8286 |
} |
| 8287 |
|
| 8288 |
static int tg3_phy_lpbk_set(struct tg3 *tp, u32 speed, bool extlpbk) |
| 8289 |
{ |
| 8290 |
u32 val, bmcr, mac_mode, ptest = 0; |
| 8291 |
|
| 8292 |
tg3_phy_toggle_apd(tp, false); |
| 8293 |
tg3_phy_toggle_automdix(tp, false); |
| 8294 |
|
| 8295 |
if (extlpbk && tg3_phy_set_extloopbk(tp)) |
| 8296 |
return -EIO; |
| 8297 |
|
| 8298 |
bmcr = BMCR_FULLDPLX; |
| 8299 |
switch (speed) { |
| 8300 |
case SPEED_10: |
| 8301 |
break; |
| 8302 |
case SPEED_100: |
| 8303 |
bmcr |= BMCR_SPEED100; |
| 8304 |
break; |
| 8305 |
case SPEED_1000: |
| 8306 |
default: |
| 8307 |
if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
| 8308 |
speed = SPEED_100; |
| 8309 |
bmcr |= BMCR_SPEED100; |
| 8310 |
} else { |
| 8311 |
speed = SPEED_1000; |
| 8312 |
bmcr |= BMCR_SPEED1000; |
| 8313 |
} |
| 8314 |
} |
| 8315 |
|
| 8316 |
if (extlpbk) { |
| 8317 |
if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 8318 |
tg3_readphy(tp, MII_CTRL1000, &val); |
| 8319 |
val |= CTL1000_AS_MASTER | |
| 8320 |
CTL1000_ENABLE_MASTER; |
| 8321 |
tg3_writephy(tp, MII_CTRL1000, val); |
| 8322 |
} else { |
| 8323 |
ptest = MII_TG3_FET_PTEST_TRIM_SEL | |
| 8324 |
MII_TG3_FET_PTEST_TRIM_2; |
| 8325 |
tg3_writephy(tp, MII_TG3_FET_PTEST, ptest); |
| 8326 |
} |
| 8327 |
} else |
| 8328 |
bmcr |= BMCR_LOOPBACK; |
| 8329 |
|
| 8330 |
tg3_writephy(tp, MII_BMCR, bmcr); |
| 8331 |
|
| 8332 |
/* The write needs to be flushed for the FETs */ |
| 8333 |
if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
| 8334 |
tg3_readphy(tp, MII_BMCR, &bmcr); |
| 8335 |
|
| 8336 |
udelay(40); |
| 8337 |
|
| 8338 |
if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
| 8339 |
tg3_asic_rev(tp) == ASIC_REV_5785) { |
| 8340 |
tg3_writephy(tp, MII_TG3_FET_PTEST, ptest | |
| 8341 |
MII_TG3_FET_PTEST_FRC_TX_LINK | |
| 8342 |
MII_TG3_FET_PTEST_FRC_TX_LOCK); |
| 8343 |
|
| 8344 |
/* The write needs to be flushed for the AC131 */ |
| 8345 |
tg3_readphy(tp, MII_TG3_FET_PTEST, &val); |
| 8346 |
} |
| 8347 |
|
| 8348 |
/* Reset to prevent losing 1st rx packet intermittently */ |
| 8349 |
if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
| 8350 |
tg3_flag(tp, 5780_CLASS)) { |
| 8351 |
tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 8352 |
udelay(10); |
| 8353 |
tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8354 |
} |
| 8355 |
|
| 8356 |
mac_mode = tp->mac_mode & |
| 8357 |
~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); |
| 8358 |
if (speed == SPEED_1000) |
| 8359 |
mac_mode |= MAC_MODE_PORT_MODE_GMII; |
| 8360 |
else |
| 8361 |
mac_mode |= MAC_MODE_PORT_MODE_MII; |
| 8362 |
|
| 8363 |
if (tg3_asic_rev(tp) == ASIC_REV_5700) { |
| 8364 |
u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
| 8365 |
|
| 8366 |
if (masked_phy_id == TG3_PHY_ID_BCM5401) |
| 8367 |
mac_mode &= ~MAC_MODE_LINK_POLARITY; |
| 8368 |
else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
| 8369 |
mac_mode |= MAC_MODE_LINK_POLARITY; |
| 8370 |
|
| 8371 |
tg3_writephy(tp, MII_TG3_EXT_CTRL, |
| 8372 |
MII_TG3_EXT_CTRL_LNK3_LED_MODE); |
| 8373 |
} |
| 8374 |
|
| 8375 |
tw32(MAC_MODE, mac_mode); |
| 8376 |
udelay(40); |
| 8377 |
|
| 8378 |
return 0; |
| 8379 |
} |
| 8380 |
|
| 8381 |
static void tg3_set_loopback(struct net_device *dev, netdev_features_t features) |
| 8382 |
{ |
| 8383 |
struct tg3 *tp = netdev_priv(dev); |
| 8384 |
|
| 8385 |
if (features & NETIF_F_LOOPBACK) { |
| 8386 |
if (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK) |
| 8387 |
return; |
| 8388 |
|
| 8389 |
spin_lock_bh(&tp->lock); |
| 8390 |
tg3_mac_loopback(tp, true); |
| 8391 |
netif_carrier_on(tp->dev); |
| 8392 |
spin_unlock_bh(&tp->lock); |
| 8393 |
netdev_info(dev, "Internal MAC loopback mode enabled.\n"); |
| 8394 |
} else { |
| 8395 |
if (!(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) |
| 8396 |
return; |
| 8397 |
|
| 8398 |
spin_lock_bh(&tp->lock); |
| 8399 |
tg3_mac_loopback(tp, false); |
| 8400 |
/* Force link status check */ |
| 8401 |
tg3_setup_phy(tp, true); |
| 8402 |
spin_unlock_bh(&tp->lock); |
| 8403 |
netdev_info(dev, "Internal MAC loopback mode disabled.\n"); |
| 8404 |
} |
| 8405 |
} |
| 8406 |
|
| 8407 |
static netdev_features_t tg3_fix_features(struct net_device *dev, |
| 8408 |
netdev_features_t features) |
| 8409 |
{ |
| 8410 |
struct tg3 *tp = netdev_priv(dev); |
| 8411 |
|
| 8412 |
if (dev->mtu > ETH_DATA_LEN && tg3_flag(tp, 5780_CLASS)) |
| 8413 |
features &= ~NETIF_F_ALL_TSO; |
| 8414 |
|
| 8415 |
return features; |
| 8416 |
} |
| 8417 |
|
| 8418 |
static int tg3_set_features(struct net_device *dev, netdev_features_t features) |
| 8419 |
{ |
| 8420 |
netdev_features_t changed = dev->features ^ features; |
| 8421 |
|
| 8422 |
if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) |
| 8423 |
tg3_set_loopback(dev, features); |
| 8424 |
|
| 8425 |
return 0; |
| 8426 |
} |
| 8427 |
|
| 8428 |
static void tg3_rx_prodring_free(struct tg3 *tp, |
| 8429 |
struct tg3_rx_prodring_set *tpr) |
| 8430 |
{ |
| 8431 |
int i; |
| 8432 |
|
| 8433 |
if (tpr != &tp->napi[0].prodring) { |
| 8434 |
for (i = tpr->rx_std_cons_idx; i != tpr->rx_std_prod_idx; |
| 8435 |
i = (i + 1) & tp->rx_std_ring_mask) |
| 8436 |
tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
| 8437 |
tp->rx_pkt_map_sz); |
| 8438 |
|
| 8439 |
if (tg3_flag(tp, JUMBO_CAPABLE)) { |
| 8440 |
for (i = tpr->rx_jmb_cons_idx; |
| 8441 |
i != tpr->rx_jmb_prod_idx; |
| 8442 |
i = (i + 1) & tp->rx_jmb_ring_mask) { |
| 8443 |
tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
| 8444 |
TG3_RX_JMB_MAP_SZ); |
| 8445 |
} |
| 8446 |
} |
| 8447 |
|
| 8448 |
return; |
| 8449 |
} |
| 8450 |
|
| 8451 |
for (i = 0; i <= tp->rx_std_ring_mask; i++) |
| 8452 |
tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
| 8453 |
tp->rx_pkt_map_sz); |
| 8454 |
|
| 8455 |
if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
| 8456 |
for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
| 8457 |
tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
| 8458 |
TG3_RX_JMB_MAP_SZ); |
| 8459 |
} |
| 8460 |
} |
| 8461 |
|
| 8462 |
/* Initialize rx rings for packet processing. |
| 8463 |
* |
| 8464 |
* The chip has been shut down and the driver detached from |
| 8465 |
* the networking, so no interrupts or new tx packets will |
| 8466 |
* end up in the driver. tp->{tx,}lock are held and thus |
| 8467 |
* we may not sleep. |
| 8468 |
*/ |
| 8469 |
static int tg3_rx_prodring_alloc(struct tg3 *tp, |
| 8470 |
struct tg3_rx_prodring_set *tpr) |
| 8471 |
{ |
| 8472 |
u32 i, rx_pkt_dma_sz; |
| 8473 |
|
| 8474 |
tpr->rx_std_cons_idx = 0; |
| 8475 |
tpr->rx_std_prod_idx = 0; |
| 8476 |
tpr->rx_jmb_cons_idx = 0; |
| 8477 |
tpr->rx_jmb_prod_idx = 0; |
| 8478 |
|
| 8479 |
if (tpr != &tp->napi[0].prodring) { |
| 8480 |
memset(&tpr->rx_std_buffers[0], 0, |
| 8481 |
TG3_RX_STD_BUFF_RING_SIZE(tp)); |
| 8482 |
if (tpr->rx_jmb_buffers) |
| 8483 |
memset(&tpr->rx_jmb_buffers[0], 0, |
| 8484 |
TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
| 8485 |
goto done; |
| 8486 |
} |
| 8487 |
|
| 8488 |
/* Zero out all descriptors. */ |
| 8489 |
memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
| 8490 |
|
| 8491 |
rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
| 8492 |
if (tg3_flag(tp, 5780_CLASS) && |
| 8493 |
tp->dev->mtu > ETH_DATA_LEN) |
| 8494 |
rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; |
| 8495 |
tp->rx_pkt_map_sz = TG3_RX_DMA_TO_MAP_SZ(rx_pkt_dma_sz); |
| 8496 |
|
| 8497 |
/* Initialize invariants of the rings, we only set this |
| 8498 |
* stuff once. This works because the card does not |
| 8499 |
* write into the rx buffer posting rings. |
| 8500 |
*/ |
| 8501 |
for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
| 8502 |
struct tg3_rx_buffer_desc *rxd; |
| 8503 |
|
| 8504 |
rxd = &tpr->rx_std[i]; |
| 8505 |
rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
| 8506 |
rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
| 8507 |
rxd->opaque = (RXD_OPAQUE_RING_STD | |
| 8508 |
(i << RXD_OPAQUE_INDEX_SHIFT)); |
| 8509 |
} |
| 8510 |
|
| 8511 |
/* Now allocate fresh SKBs for each rx ring. */ |
| 8512 |
for (i = 0; i < tp->rx_pending; i++) { |
| 8513 |
unsigned int frag_size; |
| 8514 |
|
| 8515 |
if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_STD, i, |
| 8516 |
&frag_size) < 0) { |
| 8517 |
netdev_warn(tp->dev, |
| 8518 |
"Using a smaller RX standard ring. Only " |
| 8519 |
"%d out of %d buffers were allocated " |
| 8520 |
"successfully\n", i, tp->rx_pending); |
| 8521 |
if (i == 0) |
| 8522 |
goto initfail; |
| 8523 |
tp->rx_pending = i; |
| 8524 |
break; |
| 8525 |
} |
| 8526 |
} |
| 8527 |
|
| 8528 |
if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
| 8529 |
goto done; |
| 8530 |
|
| 8531 |
memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
| 8532 |
|
| 8533 |
if (!tg3_flag(tp, JUMBO_RING_ENABLE)) |
| 8534 |
goto done; |
| 8535 |
|
| 8536 |
for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
| 8537 |
struct tg3_rx_buffer_desc *rxd; |
| 8538 |
|
| 8539 |
rxd = &tpr->rx_jmb[i].std; |
| 8540 |
rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; |
| 8541 |
rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | |
| 8542 |
RXD_FLAG_JUMBO; |
| 8543 |
rxd->opaque = (RXD_OPAQUE_RING_JUMBO | |
| 8544 |
(i << RXD_OPAQUE_INDEX_SHIFT)); |
| 8545 |
} |
| 8546 |
|
| 8547 |
for (i = 0; i < tp->rx_jumbo_pending; i++) { |
| 8548 |
unsigned int frag_size; |
| 8549 |
|
| 8550 |
if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_JUMBO, i, |
| 8551 |
&frag_size) < 0) { |
| 8552 |
netdev_warn(tp->dev, |
| 8553 |
"Using a smaller RX jumbo ring. Only %d " |
| 8554 |
"out of %d buffers were allocated " |
| 8555 |
"successfully\n", i, tp->rx_jumbo_pending); |
| 8556 |
if (i == 0) |
| 8557 |
goto initfail; |
| 8558 |
tp->rx_jumbo_pending = i; |
| 8559 |
break; |
| 8560 |
} |
| 8561 |
} |
| 8562 |
|
| 8563 |
done: |
| 8564 |
return 0; |
| 8565 |
|
| 8566 |
initfail: |
| 8567 |
tg3_rx_prodring_free(tp, tpr); |
| 8568 |
return -ENOMEM; |
| 8569 |
} |
| 8570 |
|
| 8571 |
static void tg3_rx_prodring_fini(struct tg3 *tp, |
| 8572 |
struct tg3_rx_prodring_set *tpr) |
| 8573 |
{ |
| 8574 |
kfree(tpr->rx_std_buffers); |
| 8575 |
tpr->rx_std_buffers = NULL; |
| 8576 |
kfree(tpr->rx_jmb_buffers); |
| 8577 |
tpr->rx_jmb_buffers = NULL; |
| 8578 |
if (tpr->rx_std) { |
| 8579 |
dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
| 8580 |
tpr->rx_std, tpr->rx_std_mapping); |
| 8581 |
tpr->rx_std = NULL; |
| 8582 |
} |
| 8583 |
if (tpr->rx_jmb) { |
| 8584 |
dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
| 8585 |
tpr->rx_jmb, tpr->rx_jmb_mapping); |
| 8586 |
tpr->rx_jmb = NULL; |
| 8587 |
} |
| 8588 |
} |
| 8589 |
|
| 8590 |
static int tg3_rx_prodring_init(struct tg3 *tp, |
| 8591 |
struct tg3_rx_prodring_set *tpr) |
| 8592 |
{ |
| 8593 |
tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
| 8594 |
GFP_KERNEL); |
| 8595 |
if (!tpr->rx_std_buffers) |
| 8596 |
return -ENOMEM; |
| 8597 |
|
| 8598 |
tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
| 8599 |
TG3_RX_STD_RING_BYTES(tp), |
| 8600 |
&tpr->rx_std_mapping, |
| 8601 |
GFP_KERNEL); |
| 8602 |
if (!tpr->rx_std) |
| 8603 |
goto err_out; |
| 8604 |
|
| 8605 |
if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
| 8606 |
tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
| 8607 |
GFP_KERNEL); |
| 8608 |
if (!tpr->rx_jmb_buffers) |
| 8609 |
goto err_out; |
| 8610 |
|
| 8611 |
tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
| 8612 |
TG3_RX_JMB_RING_BYTES(tp), |
| 8613 |
&tpr->rx_jmb_mapping, |
| 8614 |
GFP_KERNEL); |
| 8615 |
if (!tpr->rx_jmb) |
| 8616 |
goto err_out; |
| 8617 |
} |
| 8618 |
|
| 8619 |
return 0; |
| 8620 |
|
| 8621 |
err_out: |
| 8622 |
tg3_rx_prodring_fini(tp, tpr); |
| 8623 |
return -ENOMEM; |
| 8624 |
} |
| 8625 |
|
| 8626 |
/* Free up pending packets in all rx/tx rings. |
| 8627 |
* |
| 8628 |
* The chip has been shut down and the driver detached from |
| 8629 |
* the networking, so no interrupts or new tx packets will |
| 8630 |
* end up in the driver. tp->{tx,}lock is not held and we are not |
| 8631 |
* in an interrupt context and thus may sleep. |
| 8632 |
*/ |
| 8633 |
static void tg3_free_rings(struct tg3 *tp) |
| 8634 |
{ |
| 8635 |
int i, j; |
| 8636 |
|
| 8637 |
for (j = 0; j < tp->irq_cnt; j++) { |
| 8638 |
struct tg3_napi *tnapi = &tp->napi[j]; |
| 8639 |
|
| 8640 |
tg3_rx_prodring_free(tp, &tnapi->prodring); |
| 8641 |
|
| 8642 |
if (!tnapi->tx_buffers) |
| 8643 |
continue; |
| 8644 |
|
| 8645 |
for (i = 0; i < TG3_TX_RING_SIZE; i++) { |
| 8646 |
struct sk_buff *skb = tnapi->tx_buffers[i].skb; |
| 8647 |
|
| 8648 |
if (!skb) |
| 8649 |
continue; |
| 8650 |
|
| 8651 |
tg3_tx_skb_unmap(tnapi, i, |
| 8652 |
skb_shinfo(skb)->nr_frags - 1); |
| 8653 |
|
| 8654 |
dev_consume_skb_any(skb); |
| 8655 |
} |
| 8656 |
netdev_tx_reset_queue(netdev_get_tx_queue(tp->dev, j)); |
| 8657 |
} |
| 8658 |
} |
| 8659 |
|
| 8660 |
/* Initialize tx/rx rings for packet processing. |
| 8661 |
* |
| 8662 |
* The chip has been shut down and the driver detached from |
| 8663 |
* the networking, so no interrupts or new tx packets will |
| 8664 |
* end up in the driver. tp->{tx,}lock are held and thus |
| 8665 |
* we may not sleep. |
| 8666 |
*/ |
| 8667 |
static int tg3_init_rings(struct tg3 *tp) |
| 8668 |
{ |
| 8669 |
int i; |
| 8670 |
|
| 8671 |
/* Free up all the SKBs. */ |
| 8672 |
tg3_free_rings(tp); |
| 8673 |
|
| 8674 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 8675 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 8676 |
|
| 8677 |
tnapi->last_tag = 0; |
| 8678 |
tnapi->last_irq_tag = 0; |
| 8679 |
tnapi->hw_status->status = 0; |
| 8680 |
tnapi->hw_status->status_tag = 0; |
| 8681 |
memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 8682 |
|
| 8683 |
tnapi->tx_prod = 0; |
| 8684 |
tnapi->tx_cons = 0; |
| 8685 |
if (tnapi->tx_ring) |
| 8686 |
memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); |
| 8687 |
|
| 8688 |
tnapi->rx_rcb_ptr = 0; |
| 8689 |
if (tnapi->rx_rcb) |
| 8690 |
memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
| 8691 |
|
| 8692 |
if (tnapi->prodring.rx_std && |
| 8693 |
tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
| 8694 |
tg3_free_rings(tp); |
| 8695 |
return -ENOMEM; |
| 8696 |
} |
| 8697 |
} |
| 8698 |
|
| 8699 |
return 0; |
| 8700 |
} |
| 8701 |
|
| 8702 |
static void tg3_mem_tx_release(struct tg3 *tp) |
| 8703 |
{ |
| 8704 |
int i; |
| 8705 |
|
| 8706 |
for (i = 0; i < tp->irq_max; i++) { |
| 8707 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 8708 |
|
| 8709 |
if (tnapi->tx_ring) { |
| 8710 |
dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
| 8711 |
tnapi->tx_ring, tnapi->tx_desc_mapping); |
| 8712 |
tnapi->tx_ring = NULL; |
| 8713 |
} |
| 8714 |
|
| 8715 |
kfree(tnapi->tx_buffers); |
| 8716 |
tnapi->tx_buffers = NULL; |
| 8717 |
} |
| 8718 |
} |
| 8719 |
|
| 8720 |
static int tg3_mem_tx_acquire(struct tg3 *tp) |
| 8721 |
{ |
| 8722 |
int i; |
| 8723 |
struct tg3_napi *tnapi = &tp->napi[0]; |
| 8724 |
|
| 8725 |
/* If multivector TSS is enabled, vector 0 does not handle |
| 8726 |
* tx interrupts. Don't allocate any resources for it. |
| 8727 |
*/ |
| 8728 |
if (tg3_flag(tp, ENABLE_TSS)) |
| 8729 |
tnapi++; |
| 8730 |
|
| 8731 |
for (i = 0; i < tp->txq_cnt; i++, tnapi++) { |
| 8732 |
tnapi->tx_buffers = kzalloc_objs(struct tg3_tx_ring_info, |
| 8733 |
TG3_TX_RING_SIZE); |
| 8734 |
if (!tnapi->tx_buffers) |
| 8735 |
goto err_out; |
| 8736 |
|
| 8737 |
tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, |
| 8738 |
TG3_TX_RING_BYTES, |
| 8739 |
&tnapi->tx_desc_mapping, |
| 8740 |
GFP_KERNEL); |
| 8741 |
if (!tnapi->tx_ring) |
| 8742 |
goto err_out; |
| 8743 |
} |
| 8744 |
|
| 8745 |
return 0; |
| 8746 |
|
| 8747 |
err_out: |
| 8748 |
tg3_mem_tx_release(tp); |
| 8749 |
return -ENOMEM; |
| 8750 |
} |
| 8751 |
|
| 8752 |
static void tg3_mem_rx_release(struct tg3 *tp) |
| 8753 |
{ |
| 8754 |
int i; |
| 8755 |
|
| 8756 |
for (i = 0; i < tp->irq_max; i++) { |
| 8757 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 8758 |
|
| 8759 |
tg3_rx_prodring_fini(tp, &tnapi->prodring); |
| 8760 |
|
| 8761 |
if (!tnapi->rx_rcb) |
| 8762 |
continue; |
| 8763 |
|
| 8764 |
dma_free_coherent(&tp->pdev->dev, |
| 8765 |
TG3_RX_RCB_RING_BYTES(tp), |
| 8766 |
tnapi->rx_rcb, |
| 8767 |
tnapi->rx_rcb_mapping); |
| 8768 |
tnapi->rx_rcb = NULL; |
| 8769 |
} |
| 8770 |
} |
| 8771 |
|
| 8772 |
static int tg3_mem_rx_acquire(struct tg3 *tp) |
| 8773 |
{ |
| 8774 |
unsigned int i, limit; |
| 8775 |
|
| 8776 |
limit = tp->rxq_cnt; |
| 8777 |
|
| 8778 |
/* If RSS is enabled, we need a (dummy) producer ring |
| 8779 |
* set on vector zero. This is the true hw prodring. |
| 8780 |
*/ |
| 8781 |
if (tg3_flag(tp, ENABLE_RSS)) |
| 8782 |
limit++; |
| 8783 |
|
| 8784 |
for (i = 0; i < limit; i++) { |
| 8785 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 8786 |
|
| 8787 |
if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
| 8788 |
goto err_out; |
| 8789 |
|
| 8790 |
/* If multivector RSS is enabled, vector 0 |
| 8791 |
* does not handle rx or tx interrupts. |
| 8792 |
* Don't allocate any resources for it. |
| 8793 |
*/ |
| 8794 |
if (!i && tg3_flag(tp, ENABLE_RSS)) |
| 8795 |
continue; |
| 8796 |
|
| 8797 |
tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, |
| 8798 |
TG3_RX_RCB_RING_BYTES(tp), |
| 8799 |
&tnapi->rx_rcb_mapping, |
| 8800 |
GFP_KERNEL); |
| 8801 |
if (!tnapi->rx_rcb) |
| 8802 |
goto err_out; |
| 8803 |
} |
| 8804 |
|
| 8805 |
return 0; |
| 8806 |
|
| 8807 |
err_out: |
| 8808 |
tg3_mem_rx_release(tp); |
| 8809 |
return -ENOMEM; |
| 8810 |
} |
| 8811 |
|
| 8812 |
/* |
| 8813 |
* Must not be invoked with interrupt sources disabled and |
| 8814 |
* the hardware shutdown down. |
| 8815 |
*/ |
| 8816 |
static void tg3_free_consistent(struct tg3 *tp) |
| 8817 |
{ |
| 8818 |
int i; |
| 8819 |
|
| 8820 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 8821 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 8822 |
|
| 8823 |
if (tnapi->hw_status) { |
| 8824 |
dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
| 8825 |
tnapi->hw_status, |
| 8826 |
tnapi->status_mapping); |
| 8827 |
tnapi->hw_status = NULL; |
| 8828 |
} |
| 8829 |
} |
| 8830 |
|
| 8831 |
tg3_mem_rx_release(tp); |
| 8832 |
tg3_mem_tx_release(tp); |
| 8833 |
|
| 8834 |
/* tp->hw_stats can be referenced safely: |
| 8835 |
* 1. under rtnl_lock |
| 8836 |
* 2. or under tp->lock if TG3_FLAG_INIT_COMPLETE is set. |
| 8837 |
*/ |
| 8838 |
if (tp->hw_stats) { |
| 8839 |
dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
| 8840 |
tp->hw_stats, tp->stats_mapping); |
| 8841 |
tp->hw_stats = NULL; |
| 8842 |
} |
| 8843 |
} |
| 8844 |
|
| 8845 |
/* |
| 8846 |
* Must not be invoked with interrupt sources disabled and |
| 8847 |
* the hardware shutdown down. Can sleep. |
| 8848 |
*/ |
| 8849 |
static int tg3_alloc_consistent(struct tg3 *tp) |
| 8850 |
{ |
| 8851 |
int i; |
| 8852 |
|
| 8853 |
tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
| 8854 |
sizeof(struct tg3_hw_stats), |
| 8855 |
&tp->stats_mapping, GFP_KERNEL); |
| 8856 |
if (!tp->hw_stats) |
| 8857 |
goto err_out; |
| 8858 |
|
| 8859 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 8860 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 8861 |
struct tg3_hw_status *sblk; |
| 8862 |
|
| 8863 |
tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
| 8864 |
TG3_HW_STATUS_SIZE, |
| 8865 |
&tnapi->status_mapping, |
| 8866 |
GFP_KERNEL); |
| 8867 |
if (!tnapi->hw_status) |
| 8868 |
goto err_out; |
| 8869 |
|
| 8870 |
sblk = tnapi->hw_status; |
| 8871 |
|
| 8872 |
if (tg3_flag(tp, ENABLE_RSS)) { |
| 8873 |
u16 *prodptr = NULL; |
| 8874 |
|
| 8875 |
/* |
| 8876 |
* When RSS is enabled, the status block format changes |
| 8877 |
* slightly. The "rx_jumbo_consumer", "reserved", |
| 8878 |
* and "rx_mini_consumer" members get mapped to the |
| 8879 |
* other three rx return ring producer indexes. |
| 8880 |
*/ |
| 8881 |
switch (i) { |
| 8882 |
case 1: |
| 8883 |
prodptr = &sblk->idx[0].rx_producer; |
| 8884 |
break; |
| 8885 |
case 2: |
| 8886 |
prodptr = &sblk->rx_jumbo_consumer; |
| 8887 |
break; |
| 8888 |
case 3: |
| 8889 |
prodptr = &sblk->reserved; |
| 8890 |
break; |
| 8891 |
case 4: |
| 8892 |
prodptr = &sblk->rx_mini_consumer; |
| 8893 |
break; |
| 8894 |
} |
| 8895 |
tnapi->rx_rcb_prod_idx = prodptr; |
| 8896 |
} else { |
| 8897 |
tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
| 8898 |
} |
| 8899 |
} |
| 8900 |
|
| 8901 |
if (tg3_mem_tx_acquire(tp) || tg3_mem_rx_acquire(tp)) |
| 8902 |
goto err_out; |
| 8903 |
|
| 8904 |
return 0; |
| 8905 |
|
| 8906 |
err_out: |
| 8907 |
tg3_free_consistent(tp); |
| 8908 |
return -ENOMEM; |
| 8909 |
} |
| 8910 |
|
| 8911 |
#define MAX_WAIT_CNT 1000 |
| 8912 |
|
| 8913 |
/* To stop a block, clear the enable bit and poll till it |
| 8914 |
* clears. tp->lock is held. |
| 8915 |
*/ |
| 8916 |
static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, bool silent) |
| 8917 |
{ |
| 8918 |
unsigned int i; |
| 8919 |
u32 val; |
| 8920 |
|
| 8921 |
if (tg3_flag(tp, 5705_PLUS)) { |
| 8922 |
switch (ofs) { |
| 8923 |
case RCVLSC_MODE: |
| 8924 |
case DMAC_MODE: |
| 8925 |
case MBFREE_MODE: |
| 8926 |
case BUFMGR_MODE: |
| 8927 |
case MEMARB_MODE: |
| 8928 |
/* We can't enable/disable these bits of the |
| 8929 |
* 5705/5750, just say success. |
| 8930 |
*/ |
| 8931 |
return 0; |
| 8932 |
|
| 8933 |
default: |
| 8934 |
break; |
| 8935 |
} |
| 8936 |
} |
| 8937 |
|
| 8938 |
val = tr32(ofs); |
| 8939 |
val &= ~enable_bit; |
| 8940 |
tw32_f(ofs, val); |
| 8941 |
|
| 8942 |
for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 8943 |
if (pci_channel_offline(tp->pdev)) { |
| 8944 |
dev_err(&tp->pdev->dev, |
| 8945 |
"tg3_stop_block device offline, " |
| 8946 |
"ofs=%lx enable_bit=%x\n", |
| 8947 |
ofs, enable_bit); |
| 8948 |
return -ENODEV; |
| 8949 |
} |
| 8950 |
|
| 8951 |
udelay(100); |
| 8952 |
val = tr32(ofs); |
| 8953 |
if ((val & enable_bit) == 0) |
| 8954 |
break; |
| 8955 |
} |
| 8956 |
|
| 8957 |
if (i == MAX_WAIT_CNT && !silent) { |
| 8958 |
dev_err(&tp->pdev->dev, |
| 8959 |
"tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", |
| 8960 |
ofs, enable_bit); |
| 8961 |
return -ENODEV; |
| 8962 |
} |
| 8963 |
|
| 8964 |
return 0; |
| 8965 |
} |
| 8966 |
|
| 8967 |
/* tp->lock is held. */ |
| 8968 |
static int tg3_abort_hw(struct tg3 *tp, bool silent) |
| 8969 |
{ |
| 8970 |
int i, err; |
| 8971 |
|
| 8972 |
tg3_disable_ints(tp); |
| 8973 |
|
| 8974 |
if (pci_channel_offline(tp->pdev)) { |
| 8975 |
tp->rx_mode &= ~(RX_MODE_ENABLE | TX_MODE_ENABLE); |
| 8976 |
tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 8977 |
err = -ENODEV; |
| 8978 |
goto err_no_dev; |
| 8979 |
} |
| 8980 |
|
| 8981 |
tp->rx_mode &= ~RX_MODE_ENABLE; |
| 8982 |
tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 8983 |
udelay(10); |
| 8984 |
|
| 8985 |
err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
| 8986 |
err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); |
| 8987 |
err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); |
| 8988 |
err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); |
| 8989 |
err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); |
| 8990 |
err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); |
| 8991 |
|
| 8992 |
err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); |
| 8993 |
err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); |
| 8994 |
err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); |
| 8995 |
err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); |
| 8996 |
err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); |
| 8997 |
err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); |
| 8998 |
err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); |
| 8999 |
|
| 9000 |
tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; |
| 9001 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 9002 |
udelay(40); |
| 9003 |
|
| 9004 |
tp->tx_mode &= ~TX_MODE_ENABLE; |
| 9005 |
tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 9006 |
|
| 9007 |
for (i = 0; i < MAX_WAIT_CNT; i++) { |
| 9008 |
udelay(100); |
| 9009 |
if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) |
| 9010 |
break; |
| 9011 |
} |
| 9012 |
if (i >= MAX_WAIT_CNT) { |
| 9013 |
dev_err(&tp->pdev->dev, |
| 9014 |
"%s timed out, TX_MODE_ENABLE will not clear " |
| 9015 |
"MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); |
| 9016 |
err |= -ENODEV; |
| 9017 |
} |
| 9018 |
|
| 9019 |
err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
| 9020 |
err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
| 9021 |
err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); |
| 9022 |
|
| 9023 |
tw32(FTQ_RESET, 0xffffffff); |
| 9024 |
tw32(FTQ_RESET, 0x00000000); |
| 9025 |
|
| 9026 |
err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
| 9027 |
err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); |
| 9028 |
|
| 9029 |
err_no_dev: |
| 9030 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 9031 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 9032 |
if (tnapi->hw_status) |
| 9033 |
memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 9034 |
} |
| 9035 |
|
| 9036 |
return err; |
| 9037 |
} |
| 9038 |
|
| 9039 |
/* Save PCI command register before chip reset */ |
| 9040 |
static void tg3_save_pci_state(struct tg3 *tp) |
| 9041 |
{ |
| 9042 |
pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
| 9043 |
} |
| 9044 |
|
| 9045 |
/* Restore PCI state after chip reset */ |
| 9046 |
static void tg3_restore_pci_state(struct tg3 *tp) |
| 9047 |
{ |
| 9048 |
u32 val; |
| 9049 |
|
| 9050 |
/* Re-enable indirect register accesses. */ |
| 9051 |
pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 9052 |
tp->misc_host_ctrl); |
| 9053 |
|
| 9054 |
/* Set MAX PCI retry to zero. */ |
| 9055 |
val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); |
| 9056 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0 && |
| 9057 |
tg3_flag(tp, PCIX_MODE)) |
| 9058 |
val |= PCISTATE_RETRY_SAME_DMA; |
| 9059 |
/* Allow reads and writes to the APE register and memory space. */ |
| 9060 |
if (tg3_flag(tp, ENABLE_APE)) |
| 9061 |
val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
| 9062 |
PCISTATE_ALLOW_APE_SHMEM_WR | |
| 9063 |
PCISTATE_ALLOW_APE_PSPACE_WR; |
| 9064 |
pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
| 9065 |
|
| 9066 |
pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
| 9067 |
|
| 9068 |
if (!tg3_flag(tp, PCI_EXPRESS)) { |
| 9069 |
pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 9070 |
tp->pci_cacheline_sz); |
| 9071 |
pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 9072 |
tp->pci_lat_timer); |
| 9073 |
} |
| 9074 |
|
| 9075 |
/* Make sure PCI-X relaxed ordering bit is clear. */ |
| 9076 |
if (tg3_flag(tp, PCIX_MODE)) { |
| 9077 |
u16 pcix_cmd; |
| 9078 |
|
| 9079 |
pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 9080 |
&pcix_cmd); |
| 9081 |
pcix_cmd &= ~PCI_X_CMD_ERO; |
| 9082 |
pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 9083 |
pcix_cmd); |
| 9084 |
} |
| 9085 |
|
| 9086 |
if (tg3_flag(tp, 5780_CLASS)) { |
| 9087 |
|
| 9088 |
/* Chip reset on 5780 will reset MSI enable bit, |
| 9089 |
* so need to restore it. |
| 9090 |
*/ |
| 9091 |
if (tg3_flag(tp, USING_MSI)) { |
| 9092 |
u16 ctrl; |
| 9093 |
|
| 9094 |
pci_read_config_word(tp->pdev, |
| 9095 |
tp->msi_cap + PCI_MSI_FLAGS, |
| 9096 |
&ctrl); |
| 9097 |
pci_write_config_word(tp->pdev, |
| 9098 |
tp->msi_cap + PCI_MSI_FLAGS, |
| 9099 |
ctrl | PCI_MSI_FLAGS_ENABLE); |
| 9100 |
val = tr32(MSGINT_MODE); |
| 9101 |
tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); |
| 9102 |
} |
| 9103 |
} |
| 9104 |
} |
| 9105 |
|
| 9106 |
static void tg3_override_clk(struct tg3 *tp) |
| 9107 |
{ |
| 9108 |
u32 val; |
| 9109 |
|
| 9110 |
switch (tg3_asic_rev(tp)) { |
| 9111 |
case ASIC_REV_5717: |
| 9112 |
val = tr32(TG3_CPMU_CLCK_ORIDE_ENABLE); |
| 9113 |
tw32(TG3_CPMU_CLCK_ORIDE_ENABLE, val | |
| 9114 |
TG3_CPMU_MAC_ORIDE_ENABLE); |
| 9115 |
break; |
| 9116 |
|
| 9117 |
case ASIC_REV_5719: |
| 9118 |
case ASIC_REV_5720: |
| 9119 |
tw32(TG3_CPMU_CLCK_ORIDE, CPMU_CLCK_ORIDE_MAC_ORIDE_EN); |
| 9120 |
break; |
| 9121 |
|
| 9122 |
default: |
| 9123 |
return; |
| 9124 |
} |
| 9125 |
} |
| 9126 |
|
| 9127 |
static void tg3_restore_clk(struct tg3 *tp) |
| 9128 |
{ |
| 9129 |
u32 val; |
| 9130 |
|
| 9131 |
switch (tg3_asic_rev(tp)) { |
| 9132 |
case ASIC_REV_5717: |
| 9133 |
val = tr32(TG3_CPMU_CLCK_ORIDE_ENABLE); |
| 9134 |
tw32(TG3_CPMU_CLCK_ORIDE_ENABLE, |
| 9135 |
val & ~TG3_CPMU_MAC_ORIDE_ENABLE); |
| 9136 |
break; |
| 9137 |
|
| 9138 |
case ASIC_REV_5719: |
| 9139 |
case ASIC_REV_5720: |
| 9140 |
val = tr32(TG3_CPMU_CLCK_ORIDE); |
| 9141 |
tw32(TG3_CPMU_CLCK_ORIDE, val & ~CPMU_CLCK_ORIDE_MAC_ORIDE_EN); |
| 9142 |
break; |
| 9143 |
|
| 9144 |
default: |
| 9145 |
return; |
| 9146 |
} |
| 9147 |
} |
| 9148 |
|
| 9149 |
/* tp->lock is held. */ |
| 9150 |
static int tg3_chip_reset(struct tg3 *tp) |
| 9151 |
__releases(tp->lock) |
| 9152 |
__acquires(tp->lock) |
| 9153 |
{ |
| 9154 |
u32 val; |
| 9155 |
void (*write_op)(struct tg3 *, u32, u32); |
| 9156 |
int i, err; |
| 9157 |
|
| 9158 |
if (!pci_device_is_present(tp->pdev)) |
| 9159 |
return -ENODEV; |
| 9160 |
|
| 9161 |
tg3_nvram_lock(tp); |
| 9162 |
|
| 9163 |
tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
| 9164 |
|
| 9165 |
/* No matching tg3_nvram_unlock() after this because |
| 9166 |
* chip reset below will undo the nvram lock. |
| 9167 |
*/ |
| 9168 |
tp->nvram_lock_cnt = 0; |
| 9169 |
|
| 9170 |
/* GRC_MISC_CFG core clock reset will clear the memory |
| 9171 |
* enable bit in PCI register 4 and the MSI enable bit |
| 9172 |
* on some chips, so we save relevant registers here. |
| 9173 |
*/ |
| 9174 |
tg3_save_pci_state(tp); |
| 9175 |
|
| 9176 |
if (tg3_asic_rev(tp) == ASIC_REV_5752 || |
| 9177 |
tg3_flag(tp, 5755_PLUS)) |
| 9178 |
tw32(GRC_FASTBOOT_PC, 0); |
| 9179 |
|
| 9180 |
/* |
| 9181 |
* We must avoid the readl() that normally takes place. |
| 9182 |
* It locks machines, causes machine checks, and other |
| 9183 |
* fun things. So, temporarily disable the 5701 |
| 9184 |
* hardware workaround, while we do the reset. |
| 9185 |
*/ |
| 9186 |
write_op = tp->write32; |
| 9187 |
if (write_op == tg3_write_flush_reg32) |
| 9188 |
tp->write32 = tg3_write32; |
| 9189 |
|
| 9190 |
/* Prevent the irq handler from reading or writing PCI registers |
| 9191 |
* during chip reset when the memory enable bit in the PCI command |
| 9192 |
* register may be cleared. The chip does not generate interrupt |
| 9193 |
* at this time, but the irq handler may still be called due to irq |
| 9194 |
* sharing or irqpoll. |
| 9195 |
*/ |
| 9196 |
tg3_flag_set(tp, CHIP_RESETTING); |
| 9197 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 9198 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 9199 |
if (tnapi->hw_status) { |
| 9200 |
tnapi->hw_status->status = 0; |
| 9201 |
tnapi->hw_status->status_tag = 0; |
| 9202 |
} |
| 9203 |
tnapi->last_tag = 0; |
| 9204 |
tnapi->last_irq_tag = 0; |
| 9205 |
} |
| 9206 |
smp_mb(); |
| 9207 |
|
| 9208 |
tg3_full_unlock(tp); |
| 9209 |
|
| 9210 |
for (i = 0; i < tp->irq_cnt; i++) |
| 9211 |
synchronize_irq(tp->napi[i].irq_vec); |
| 9212 |
|
| 9213 |
tg3_full_lock(tp, 0); |
| 9214 |
|
| 9215 |
if (tg3_asic_rev(tp) == ASIC_REV_57780) { |
| 9216 |
val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 9217 |
tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 9218 |
} |
| 9219 |
|
| 9220 |
/* do the reset */ |
| 9221 |
val = GRC_MISC_CFG_CORECLK_RESET; |
| 9222 |
|
| 9223 |
if (tg3_flag(tp, PCI_EXPRESS)) { |
| 9224 |
/* Force PCIe 1.0a mode */ |
| 9225 |
if (tg3_asic_rev(tp) != ASIC_REV_5785 && |
| 9226 |
!tg3_flag(tp, 57765_PLUS) && |
| 9227 |
tr32(TG3_PCIE_PHY_TSTCTL) == |
| 9228 |
(TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) |
| 9229 |
tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); |
| 9230 |
|
| 9231 |
if (tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0) { |
| 9232 |
tw32(GRC_MISC_CFG, (1 << 29)); |
| 9233 |
val |= (1 << 29); |
| 9234 |
} |
| 9235 |
} |
| 9236 |
|
| 9237 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 9238 |
tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
| 9239 |
tw32(GRC_VCPU_EXT_CTRL, |
| 9240 |
tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); |
| 9241 |
} |
| 9242 |
|
| 9243 |
/* Set the clock to the highest frequency to avoid timeouts. With link |
| 9244 |
* aware mode, the clock speed could be slow and bootcode does not |
| 9245 |
* complete within the expected time. Override the clock to allow the |
| 9246 |
* bootcode to finish sooner and then restore it. |
| 9247 |
*/ |
| 9248 |
tg3_override_clk(tp); |
| 9249 |
|
| 9250 |
/* Manage gphy power for all CPMU absent PCIe devices. */ |
| 9251 |
if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, CPMU_PRESENT)) |
| 9252 |
val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
| 9253 |
|
| 9254 |
tw32(GRC_MISC_CFG, val); |
| 9255 |
|
| 9256 |
/* restore 5701 hardware bug workaround write method */ |
| 9257 |
tp->write32 = write_op; |
| 9258 |
|
| 9259 |
/* Unfortunately, we have to delay before the PCI read back. |
| 9260 |
* Some 575X chips even will not respond to a PCI cfg access |
| 9261 |
* when the reset command is given to the chip. |
| 9262 |
* |
| 9263 |
* How do these hardware designers expect things to work |
| 9264 |
* properly if the PCI write is posted for a long period |
| 9265 |
* of time? It is always necessary to have some method by |
| 9266 |
* which a register read back can occur to push the write |
| 9267 |
* out which does the reset. |
| 9268 |
* |
| 9269 |
* For most tg3 variants the trick below was working. |
| 9270 |
* Ho hum... |
| 9271 |
*/ |
| 9272 |
udelay(120); |
| 9273 |
|
| 9274 |
/* Flush PCI posted writes. The normal MMIO registers |
| 9275 |
* are inaccessible at this time so this is the only |
| 9276 |
* way to make this reliably (actually, this is no longer |
| 9277 |
* the case, see above). I tried to use indirect |
| 9278 |
* register read/write but this upset some 5701 variants. |
| 9279 |
*/ |
| 9280 |
pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); |
| 9281 |
|
| 9282 |
udelay(120); |
| 9283 |
|
| 9284 |
if (tg3_flag(tp, PCI_EXPRESS) && pci_is_pcie(tp->pdev)) { |
| 9285 |
u16 val16; |
| 9286 |
|
| 9287 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5750_A0) { |
| 9288 |
int j; |
| 9289 |
u32 cfg_val; |
| 9290 |
|
| 9291 |
/* Wait for link training to complete. */ |
| 9292 |
for (j = 0; j < 5000; j++) |
| 9293 |
udelay(100); |
| 9294 |
|
| 9295 |
pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); |
| 9296 |
pci_write_config_dword(tp->pdev, 0xc4, |
| 9297 |
cfg_val | (1 << 15)); |
| 9298 |
} |
| 9299 |
|
| 9300 |
/* Clear the "no snoop" and "relaxed ordering" bits. */ |
| 9301 |
val16 = PCI_EXP_DEVCTL_RELAX_EN | PCI_EXP_DEVCTL_NOSNOOP_EN; |
| 9302 |
/* |
| 9303 |
* Older PCIe devices only support the 128 byte |
| 9304 |
* MPS setting. Enforce the restriction. |
| 9305 |
*/ |
| 9306 |
if (!tg3_flag(tp, CPMU_PRESENT)) |
| 9307 |
val16 |= PCI_EXP_DEVCTL_PAYLOAD; |
| 9308 |
pcie_capability_clear_word(tp->pdev, PCI_EXP_DEVCTL, val16); |
| 9309 |
|
| 9310 |
/* Clear error status */ |
| 9311 |
pcie_capability_write_word(tp->pdev, PCI_EXP_DEVSTA, |
| 9312 |
PCI_EXP_DEVSTA_CED | |
| 9313 |
PCI_EXP_DEVSTA_NFED | |
| 9314 |
PCI_EXP_DEVSTA_FED | |
| 9315 |
PCI_EXP_DEVSTA_URD); |
| 9316 |
} |
| 9317 |
|
| 9318 |
tg3_restore_pci_state(tp); |
| 9319 |
|
| 9320 |
tg3_flag_clear(tp, CHIP_RESETTING); |
| 9321 |
tg3_flag_clear(tp, ERROR_PROCESSED); |
| 9322 |
|
| 9323 |
val = 0; |
| 9324 |
if (tg3_flag(tp, 5780_CLASS)) |
| 9325 |
val = tr32(MEMARB_MODE); |
| 9326 |
tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 9327 |
|
| 9328 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5750_A3) { |
| 9329 |
tg3_stop_fw(tp); |
| 9330 |
tw32(0x5000, 0x400); |
| 9331 |
} |
| 9332 |
|
| 9333 |
if (tg3_flag(tp, IS_SSB_CORE)) { |
| 9334 |
/* |
| 9335 |
* BCM4785: In order to avoid repercussions from using |
| 9336 |
* potentially defective internal ROM, stop the Rx RISC CPU, |
| 9337 |
* which is not required. |
| 9338 |
*/ |
| 9339 |
tg3_stop_fw(tp); |
| 9340 |
tg3_halt_cpu(tp, RX_CPU_BASE); |
| 9341 |
} |
| 9342 |
|
| 9343 |
err = tg3_poll_fw(tp); |
| 9344 |
if (err) |
| 9345 |
return err; |
| 9346 |
|
| 9347 |
tw32(GRC_MODE, tp->grc_mode); |
| 9348 |
|
| 9349 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A0) { |
| 9350 |
val = tr32(0xc4); |
| 9351 |
|
| 9352 |
tw32(0xc4, val | (1 << 15)); |
| 9353 |
} |
| 9354 |
|
| 9355 |
if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && |
| 9356 |
tg3_asic_rev(tp) == ASIC_REV_5705) { |
| 9357 |
tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
| 9358 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A0) |
| 9359 |
tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
| 9360 |
tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 9361 |
} |
| 9362 |
|
| 9363 |
if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 9364 |
tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
| 9365 |
val = tp->mac_mode; |
| 9366 |
} else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
| 9367 |
tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
| 9368 |
val = tp->mac_mode; |
| 9369 |
} else |
| 9370 |
val = 0; |
| 9371 |
|
| 9372 |
tw32_f(MAC_MODE, val); |
| 9373 |
udelay(40); |
| 9374 |
|
| 9375 |
tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
| 9376 |
|
| 9377 |
tg3_mdio_start(tp); |
| 9378 |
|
| 9379 |
if (tg3_flag(tp, PCI_EXPRESS) && |
| 9380 |
tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0 && |
| 9381 |
tg3_asic_rev(tp) != ASIC_REV_5785 && |
| 9382 |
!tg3_flag(tp, 57765_PLUS)) { |
| 9383 |
val = tr32(0x7c00); |
| 9384 |
|
| 9385 |
tw32(0x7c00, val | (1 << 25)); |
| 9386 |
} |
| 9387 |
|
| 9388 |
tg3_restore_clk(tp); |
| 9389 |
|
| 9390 |
/* Increase the core clock speed to fix tx timeout issue for 5762 |
| 9391 |
* with 100Mbps link speed. |
| 9392 |
*/ |
| 9393 |
if (tg3_asic_rev(tp) == ASIC_REV_5762) { |
| 9394 |
val = tr32(TG3_CPMU_CLCK_ORIDE_ENABLE); |
| 9395 |
tw32(TG3_CPMU_CLCK_ORIDE_ENABLE, val | |
| 9396 |
TG3_CPMU_MAC_ORIDE_ENABLE); |
| 9397 |
} |
| 9398 |
|
| 9399 |
/* Reprobe ASF enable state. */ |
| 9400 |
tg3_flag_clear(tp, ENABLE_ASF); |
| 9401 |
tp->phy_flags &= ~(TG3_PHYFLG_1G_ON_VAUX_OK | |
| 9402 |
TG3_PHYFLG_KEEP_LINK_ON_PWRDN); |
| 9403 |
|
| 9404 |
tg3_flag_clear(tp, ASF_NEW_HANDSHAKE); |
| 9405 |
tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 9406 |
if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 9407 |
u32 nic_cfg; |
| 9408 |
|
| 9409 |
tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 9410 |
if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
| 9411 |
tg3_flag_set(tp, ENABLE_ASF); |
| 9412 |
tp->last_event_jiffies = jiffies; |
| 9413 |
if (tg3_flag(tp, 5750_PLUS)) |
| 9414 |
tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
| 9415 |
|
| 9416 |
tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &nic_cfg); |
| 9417 |
if (nic_cfg & NIC_SRAM_1G_ON_VAUX_OK) |
| 9418 |
tp->phy_flags |= TG3_PHYFLG_1G_ON_VAUX_OK; |
| 9419 |
if (nic_cfg & NIC_SRAM_LNK_FLAP_AVOID) |
| 9420 |
tp->phy_flags |= TG3_PHYFLG_KEEP_LINK_ON_PWRDN; |
| 9421 |
} |
| 9422 |
} |
| 9423 |
|
| 9424 |
return 0; |
| 9425 |
} |
| 9426 |
|
| 9427 |
static void tg3_get_nstats(struct tg3 *, struct rtnl_link_stats64 *); |
| 9428 |
static void tg3_get_estats(struct tg3 *, struct tg3_ethtool_stats *); |
| 9429 |
static void __tg3_set_rx_mode(struct net_device *); |
| 9430 |
|
| 9431 |
/* tp->lock is held. */ |
| 9432 |
static int tg3_halt(struct tg3 *tp, int kind, bool silent) |
| 9433 |
{ |
| 9434 |
int err, i; |
| 9435 |
|
| 9436 |
tg3_stop_fw(tp); |
| 9437 |
|
| 9438 |
tg3_write_sig_pre_reset(tp, kind); |
| 9439 |
|
| 9440 |
tg3_abort_hw(tp, silent); |
| 9441 |
err = tg3_chip_reset(tp); |
| 9442 |
|
| 9443 |
__tg3_set_mac_addr(tp, false); |
| 9444 |
|
| 9445 |
tg3_write_sig_legacy(tp, kind); |
| 9446 |
tg3_write_sig_post_reset(tp, kind); |
| 9447 |
|
| 9448 |
if (tp->hw_stats) { |
| 9449 |
/* Save the stats across chip resets... */ |
| 9450 |
tg3_get_nstats(tp, &tp->net_stats_prev); |
| 9451 |
tg3_get_estats(tp, &tp->estats_prev); |
| 9452 |
|
| 9453 |
/* And make sure the next sample is new data */ |
| 9454 |
memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
| 9455 |
|
| 9456 |
for (i = 0; i < TG3_IRQ_MAX_VECS; ++i) { |
| 9457 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 9458 |
|
| 9459 |
tnapi->rx_dropped = 0; |
| 9460 |
tnapi->tx_dropped = 0; |
| 9461 |
} |
| 9462 |
} |
| 9463 |
|
| 9464 |
return err; |
| 9465 |
} |
| 9466 |
|
| 9467 |
static int tg3_set_mac_addr(struct net_device *dev, void *p) |
| 9468 |
{ |
| 9469 |
struct tg3 *tp = netdev_priv(dev); |
| 9470 |
struct sockaddr *addr = p; |
| 9471 |
int err = 0; |
| 9472 |
bool skip_mac_1 = false; |
| 9473 |
|
| 9474 |
if (!is_valid_ether_addr(addr->sa_data)) |
| 9475 |
return -EADDRNOTAVAIL; |
| 9476 |
|
| 9477 |
eth_hw_addr_set(dev, addr->sa_data); |
| 9478 |
|
| 9479 |
if (!netif_running(dev)) |
| 9480 |
return 0; |
| 9481 |
|
| 9482 |
if (tg3_flag(tp, ENABLE_ASF)) { |
| 9483 |
u32 addr0_high, addr0_low, addr1_high, addr1_low; |
| 9484 |
|
| 9485 |
addr0_high = tr32(MAC_ADDR_0_HIGH); |
| 9486 |
addr0_low = tr32(MAC_ADDR_0_LOW); |
| 9487 |
addr1_high = tr32(MAC_ADDR_1_HIGH); |
| 9488 |
addr1_low = tr32(MAC_ADDR_1_LOW); |
| 9489 |
|
| 9490 |
/* Skip MAC addr 1 if ASF is using it. */ |
| 9491 |
if ((addr0_high != addr1_high || addr0_low != addr1_low) && |
| 9492 |
!(addr1_high == 0 && addr1_low == 0)) |
| 9493 |
skip_mac_1 = true; |
| 9494 |
} |
| 9495 |
spin_lock_bh(&tp->lock); |
| 9496 |
__tg3_set_mac_addr(tp, skip_mac_1); |
| 9497 |
__tg3_set_rx_mode(dev); |
| 9498 |
spin_unlock_bh(&tp->lock); |
| 9499 |
|
| 9500 |
return err; |
| 9501 |
} |
| 9502 |
|
| 9503 |
/* tp->lock is held. */ |
| 9504 |
static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, |
| 9505 |
dma_addr_t mapping, u32 maxlen_flags, |
| 9506 |
u32 nic_addr) |
| 9507 |
{ |
| 9508 |
tg3_write_mem(tp, |
| 9509 |
(bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), |
| 9510 |
((u64) mapping >> 32)); |
| 9511 |
tg3_write_mem(tp, |
| 9512 |
(bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), |
| 9513 |
((u64) mapping & 0xffffffff)); |
| 9514 |
tg3_write_mem(tp, |
| 9515 |
(bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), |
| 9516 |
maxlen_flags); |
| 9517 |
|
| 9518 |
if (!tg3_flag(tp, 5705_PLUS)) |
| 9519 |
tg3_write_mem(tp, |
| 9520 |
(bdinfo_addr + TG3_BDINFO_NIC_ADDR), |
| 9521 |
nic_addr); |
| 9522 |
} |
| 9523 |
|
| 9524 |
|
| 9525 |
static void tg3_coal_tx_init(struct tg3 *tp, struct ethtool_coalesce *ec) |
| 9526 |
{ |
| 9527 |
int i = 0; |
| 9528 |
|
| 9529 |
if (!tg3_flag(tp, ENABLE_TSS)) { |
| 9530 |
tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
| 9531 |
tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); |
| 9532 |
tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); |
| 9533 |
} else { |
| 9534 |
tw32(HOSTCC_TXCOL_TICKS, 0); |
| 9535 |
tw32(HOSTCC_TXMAX_FRAMES, 0); |
| 9536 |
tw32(HOSTCC_TXCOAL_MAXF_INT, 0); |
| 9537 |
|
| 9538 |
for (; i < tp->txq_cnt; i++) { |
| 9539 |
u32 reg; |
| 9540 |
|
| 9541 |
reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
| 9542 |
tw32(reg, ec->tx_coalesce_usecs); |
| 9543 |
reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; |
| 9544 |
tw32(reg, ec->tx_max_coalesced_frames); |
| 9545 |
reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 9546 |
tw32(reg, ec->tx_max_coalesced_frames_irq); |
| 9547 |
} |
| 9548 |
} |
| 9549 |
|
| 9550 |
for (; i < tp->irq_max - 1; i++) { |
| 9551 |
tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 9552 |
tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 9553 |
tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 9554 |
} |
| 9555 |
} |
| 9556 |
|
| 9557 |
static void tg3_coal_rx_init(struct tg3 *tp, struct ethtool_coalesce *ec) |
| 9558 |
{ |
| 9559 |
int i = 0; |
| 9560 |
u32 limit = tp->rxq_cnt; |
| 9561 |
|
| 9562 |
if (!tg3_flag(tp, ENABLE_RSS)) { |
| 9563 |
tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
| 9564 |
tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); |
| 9565 |
tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); |
| 9566 |
limit--; |
| 9567 |
} else { |
| 9568 |
tw32(HOSTCC_RXCOL_TICKS, 0); |
| 9569 |
tw32(HOSTCC_RXMAX_FRAMES, 0); |
| 9570 |
tw32(HOSTCC_RXCOAL_MAXF_INT, 0); |
| 9571 |
} |
| 9572 |
|
| 9573 |
for (; i < limit; i++) { |
| 9574 |
u32 reg; |
| 9575 |
|
| 9576 |
reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; |
| 9577 |
tw32(reg, ec->rx_coalesce_usecs); |
| 9578 |
reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
| 9579 |
tw32(reg, ec->rx_max_coalesced_frames); |
| 9580 |
reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
| 9581 |
tw32(reg, ec->rx_max_coalesced_frames_irq); |
| 9582 |
} |
| 9583 |
|
| 9584 |
for (; i < tp->irq_max - 1; i++) { |
| 9585 |
tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); |
| 9586 |
tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
| 9587 |
tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
| 9588 |
} |
| 9589 |
} |
| 9590 |
|
| 9591 |
static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) |
| 9592 |
{ |
| 9593 |
tg3_coal_tx_init(tp, ec); |
| 9594 |
tg3_coal_rx_init(tp, ec); |
| 9595 |
|
| 9596 |
if (!tg3_flag(tp, 5705_PLUS)) { |
| 9597 |
u32 val = ec->stats_block_coalesce_usecs; |
| 9598 |
|
| 9599 |
tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
| 9600 |
tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); |
| 9601 |
|
| 9602 |
if (!tp->link_up) |
| 9603 |
val = 0; |
| 9604 |
|
| 9605 |
tw32(HOSTCC_STAT_COAL_TICKS, val); |
| 9606 |
} |
| 9607 |
} |
| 9608 |
|
| 9609 |
/* tp->lock is held. */ |
| 9610 |
static void tg3_tx_rcbs_disable(struct tg3 *tp) |
| 9611 |
{ |
| 9612 |
u32 txrcb, limit; |
| 9613 |
|
| 9614 |
/* Disable all transmit rings but the first. */ |
| 9615 |
if (!tg3_flag(tp, 5705_PLUS)) |
| 9616 |
limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
| 9617 |
else if (tg3_flag(tp, 5717_PLUS)) |
| 9618 |
limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
| 9619 |
else if (tg3_flag(tp, 57765_CLASS) || |
| 9620 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 9621 |
limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
| 9622 |
else |
| 9623 |
limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 9624 |
|
| 9625 |
for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; |
| 9626 |
txrcb < limit; txrcb += TG3_BDINFO_SIZE) |
| 9627 |
tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 9628 |
BDINFO_FLAGS_DISABLED); |
| 9629 |
} |
| 9630 |
|
| 9631 |
/* tp->lock is held. */ |
| 9632 |
static void tg3_tx_rcbs_init(struct tg3 *tp) |
| 9633 |
{ |
| 9634 |
int i = 0; |
| 9635 |
u32 txrcb = NIC_SRAM_SEND_RCB; |
| 9636 |
|
| 9637 |
if (tg3_flag(tp, ENABLE_TSS)) |
| 9638 |
i++; |
| 9639 |
|
| 9640 |
for (; i < tp->irq_max; i++, txrcb += TG3_BDINFO_SIZE) { |
| 9641 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 9642 |
|
| 9643 |
if (!tnapi->tx_ring) |
| 9644 |
continue; |
| 9645 |
|
| 9646 |
tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, |
| 9647 |
(TG3_TX_RING_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT), |
| 9648 |
NIC_SRAM_TX_BUFFER_DESC); |
| 9649 |
} |
| 9650 |
} |
| 9651 |
|
| 9652 |
/* tp->lock is held. */ |
| 9653 |
static void tg3_rx_ret_rcbs_disable(struct tg3 *tp) |
| 9654 |
{ |
| 9655 |
u32 rxrcb, limit; |
| 9656 |
|
| 9657 |
/* Disable all receive return rings but the first. */ |
| 9658 |
if (tg3_flag(tp, 5717_PLUS)) |
| 9659 |
limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
| 9660 |
else if (!tg3_flag(tp, 5705_PLUS)) |
| 9661 |
limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
| 9662 |
else if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
| 9663 |
tg3_asic_rev(tp) == ASIC_REV_5762 || |
| 9664 |
tg3_flag(tp, 57765_CLASS)) |
| 9665 |
limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
| 9666 |
else |
| 9667 |
limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 9668 |
|
| 9669 |
for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; |
| 9670 |
rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) |
| 9671 |
tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, |
| 9672 |
BDINFO_FLAGS_DISABLED); |
| 9673 |
} |
| 9674 |
|
| 9675 |
/* tp->lock is held. */ |
| 9676 |
static void tg3_rx_ret_rcbs_init(struct tg3 *tp) |
| 9677 |
{ |
| 9678 |
int i = 0; |
| 9679 |
u32 rxrcb = NIC_SRAM_RCV_RET_RCB; |
| 9680 |
|
| 9681 |
if (tg3_flag(tp, ENABLE_RSS)) |
| 9682 |
i++; |
| 9683 |
|
| 9684 |
for (; i < tp->irq_max; i++, rxrcb += TG3_BDINFO_SIZE) { |
| 9685 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 9686 |
|
| 9687 |
if (!tnapi->rx_rcb) |
| 9688 |
continue; |
| 9689 |
|
| 9690 |
tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, |
| 9691 |
(tp->rx_ret_ring_mask + 1) << |
| 9692 |
BDINFO_FLAGS_MAXLEN_SHIFT, 0); |
| 9693 |
} |
| 9694 |
} |
| 9695 |
|
| 9696 |
/* tp->lock is held. */ |
| 9697 |
static void tg3_rings_reset(struct tg3 *tp) |
| 9698 |
{ |
| 9699 |
int i; |
| 9700 |
u32 stblk; |
| 9701 |
struct tg3_napi *tnapi = &tp->napi[0]; |
| 9702 |
|
| 9703 |
tg3_tx_rcbs_disable(tp); |
| 9704 |
|
| 9705 |
tg3_rx_ret_rcbs_disable(tp); |
| 9706 |
|
| 9707 |
/* Disable interrupts */ |
| 9708 |
tw32_mailbox_f(tp->napi[0].int_mbox, 1); |
| 9709 |
tp->napi[0].chk_msi_cnt = 0; |
| 9710 |
tp->napi[0].last_rx_cons = 0; |
| 9711 |
tp->napi[0].last_tx_cons = 0; |
| 9712 |
|
| 9713 |
/* Zero mailbox registers. */ |
| 9714 |
if (tg3_flag(tp, SUPPORT_MSIX)) { |
| 9715 |
for (i = 1; i < tp->irq_max; i++) { |
| 9716 |
tp->napi[i].tx_prod = 0; |
| 9717 |
tp->napi[i].tx_cons = 0; |
| 9718 |
if (tg3_flag(tp, ENABLE_TSS)) |
| 9719 |
tw32_mailbox(tp->napi[i].prodmbox, 0); |
| 9720 |
tw32_rx_mbox(tp->napi[i].consmbox, 0); |
| 9721 |
tw32_mailbox_f(tp->napi[i].int_mbox, 1); |
| 9722 |
tp->napi[i].chk_msi_cnt = 0; |
| 9723 |
tp->napi[i].last_rx_cons = 0; |
| 9724 |
tp->napi[i].last_tx_cons = 0; |
| 9725 |
} |
| 9726 |
if (!tg3_flag(tp, ENABLE_TSS)) |
| 9727 |
tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 9728 |
} else { |
| 9729 |
tp->napi[0].tx_prod = 0; |
| 9730 |
tp->napi[0].tx_cons = 0; |
| 9731 |
tw32_mailbox(tp->napi[0].prodmbox, 0); |
| 9732 |
tw32_rx_mbox(tp->napi[0].consmbox, 0); |
| 9733 |
} |
| 9734 |
|
| 9735 |
/* Make sure the NIC-based send BD rings are disabled. */ |
| 9736 |
if (!tg3_flag(tp, 5705_PLUS)) { |
| 9737 |
u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 9738 |
for (i = 0; i < 16; i++) |
| 9739 |
tw32_tx_mbox(mbox + i * 8, 0); |
| 9740 |
} |
| 9741 |
|
| 9742 |
/* Clear status block in ram. */ |
| 9743 |
memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 9744 |
|
| 9745 |
/* Set status block DMA address */ |
| 9746 |
tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 9747 |
((u64) tnapi->status_mapping >> 32)); |
| 9748 |
tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 9749 |
((u64) tnapi->status_mapping & 0xffffffff)); |
| 9750 |
|
| 9751 |
stblk = HOSTCC_STATBLCK_RING1; |
| 9752 |
|
| 9753 |
for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
| 9754 |
u64 mapping = (u64)tnapi->status_mapping; |
| 9755 |
tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); |
| 9756 |
tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); |
| 9757 |
stblk += 8; |
| 9758 |
|
| 9759 |
/* Clear status block in ram. */ |
| 9760 |
memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
| 9761 |
} |
| 9762 |
|
| 9763 |
tg3_tx_rcbs_init(tp); |
| 9764 |
tg3_rx_ret_rcbs_init(tp); |
| 9765 |
} |
| 9766 |
|
| 9767 |
static void tg3_setup_rxbd_thresholds(struct tg3 *tp) |
| 9768 |
{ |
| 9769 |
u32 val, bdcache_maxcnt, host_rep_thresh, nic_rep_thresh; |
| 9770 |
|
| 9771 |
if (!tg3_flag(tp, 5750_PLUS) || |
| 9772 |
tg3_flag(tp, 5780_CLASS) || |
| 9773 |
tg3_asic_rev(tp) == ASIC_REV_5750 || |
| 9774 |
tg3_asic_rev(tp) == ASIC_REV_5752 || |
| 9775 |
tg3_flag(tp, 57765_PLUS)) |
| 9776 |
bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5700; |
| 9777 |
else if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
| 9778 |
tg3_asic_rev(tp) == ASIC_REV_5787) |
| 9779 |
bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5755; |
| 9780 |
else |
| 9781 |
bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5906; |
| 9782 |
|
| 9783 |
nic_rep_thresh = min(bdcache_maxcnt / 2, tp->rx_std_max_post); |
| 9784 |
host_rep_thresh = max_t(u32, tp->rx_pending / 8, 1); |
| 9785 |
|
| 9786 |
val = min(nic_rep_thresh, host_rep_thresh); |
| 9787 |
tw32(RCVBDI_STD_THRESH, val); |
| 9788 |
|
| 9789 |
if (tg3_flag(tp, 57765_PLUS)) |
| 9790 |
tw32(STD_REPLENISH_LWM, bdcache_maxcnt); |
| 9791 |
|
| 9792 |
if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
| 9793 |
return; |
| 9794 |
|
| 9795 |
bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5700; |
| 9796 |
|
| 9797 |
host_rep_thresh = max_t(u32, tp->rx_jumbo_pending / 8, 1); |
| 9798 |
|
| 9799 |
val = min(bdcache_maxcnt / 2, host_rep_thresh); |
| 9800 |
tw32(RCVBDI_JUMBO_THRESH, val); |
| 9801 |
|
| 9802 |
if (tg3_flag(tp, 57765_PLUS)) |
| 9803 |
tw32(JMB_REPLENISH_LWM, bdcache_maxcnt); |
| 9804 |
} |
| 9805 |
|
| 9806 |
static inline u32 calc_crc(unsigned char *buf, int len) |
| 9807 |
{ |
| 9808 |
return ~crc32(~0, buf, len); |
| 9809 |
} |
| 9810 |
|
| 9811 |
static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) |
| 9812 |
{ |
| 9813 |
/* accept or reject all multicast frames */ |
| 9814 |
tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); |
| 9815 |
tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); |
| 9816 |
tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); |
| 9817 |
tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); |
| 9818 |
} |
| 9819 |
|
| 9820 |
static void __tg3_set_rx_mode(struct net_device *dev) |
| 9821 |
{ |
| 9822 |
struct tg3 *tp = netdev_priv(dev); |
| 9823 |
u32 rx_mode; |
| 9824 |
|
| 9825 |
rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | |
| 9826 |
RX_MODE_KEEP_VLAN_TAG); |
| 9827 |
|
| 9828 |
#if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) |
| 9829 |
/* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
| 9830 |
* flag clear. |
| 9831 |
*/ |
| 9832 |
if (!tg3_flag(tp, ENABLE_ASF)) |
| 9833 |
rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
| 9834 |
#endif |
| 9835 |
|
| 9836 |
if (dev->flags & IFF_PROMISC) { |
| 9837 |
/* Promiscuous mode. */ |
| 9838 |
rx_mode |= RX_MODE_PROMISC; |
| 9839 |
} else if (dev->flags & IFF_ALLMULTI) { |
| 9840 |
/* Accept all multicast. */ |
| 9841 |
tg3_set_multi(tp, 1); |
| 9842 |
} else if (netdev_mc_empty(dev)) { |
| 9843 |
/* Reject all multicast. */ |
| 9844 |
tg3_set_multi(tp, 0); |
| 9845 |
} else { |
| 9846 |
/* Accept one or more multicast(s). */ |
| 9847 |
struct netdev_hw_addr *ha; |
| 9848 |
u32 mc_filter[4] = { 0, }; |
| 9849 |
u32 regidx; |
| 9850 |
u32 bit; |
| 9851 |
u32 crc; |
| 9852 |
|
| 9853 |
netdev_for_each_mc_addr(ha, dev) { |
| 9854 |
crc = calc_crc(ha->addr, ETH_ALEN); |
| 9855 |
bit = ~crc & 0x7f; |
| 9856 |
regidx = (bit & 0x60) >> 5; |
| 9857 |
bit &= 0x1f; |
| 9858 |
mc_filter[regidx] |= (1 << bit); |
| 9859 |
} |
| 9860 |
|
| 9861 |
tw32(MAC_HASH_REG_0, mc_filter[0]); |
| 9862 |
tw32(MAC_HASH_REG_1, mc_filter[1]); |
| 9863 |
tw32(MAC_HASH_REG_2, mc_filter[2]); |
| 9864 |
tw32(MAC_HASH_REG_3, mc_filter[3]); |
| 9865 |
} |
| 9866 |
|
| 9867 |
if (netdev_uc_count(dev) > TG3_MAX_UCAST_ADDR(tp)) { |
| 9868 |
rx_mode |= RX_MODE_PROMISC; |
| 9869 |
} else if (!(dev->flags & IFF_PROMISC)) { |
| 9870 |
/* Add all entries into to the mac addr filter list */ |
| 9871 |
int i = 0; |
| 9872 |
struct netdev_hw_addr *ha; |
| 9873 |
|
| 9874 |
netdev_for_each_uc_addr(ha, dev) { |
| 9875 |
__tg3_set_one_mac_addr(tp, ha->addr, |
| 9876 |
i + TG3_UCAST_ADDR_IDX(tp)); |
| 9877 |
i++; |
| 9878 |
} |
| 9879 |
} |
| 9880 |
|
| 9881 |
if (rx_mode != tp->rx_mode) { |
| 9882 |
tp->rx_mode = rx_mode; |
| 9883 |
tw32_f(MAC_RX_MODE, rx_mode); |
| 9884 |
udelay(10); |
| 9885 |
} |
| 9886 |
} |
| 9887 |
|
| 9888 |
static void tg3_rss_init_dflt_indir_tbl(struct tg3 *tp, u32 qcnt) |
| 9889 |
{ |
| 9890 |
int i; |
| 9891 |
|
| 9892 |
for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 9893 |
tp->rss_ind_tbl[i] = ethtool_rxfh_indir_default(i, qcnt); |
| 9894 |
} |
| 9895 |
|
| 9896 |
static void tg3_rss_check_indir_tbl(struct tg3 *tp) |
| 9897 |
{ |
| 9898 |
int i; |
| 9899 |
|
| 9900 |
if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 9901 |
return; |
| 9902 |
|
| 9903 |
if (tp->rxq_cnt == 1) { |
| 9904 |
memset(&tp->rss_ind_tbl[0], 0, sizeof(tp->rss_ind_tbl)); |
| 9905 |
return; |
| 9906 |
} |
| 9907 |
|
| 9908 |
/* Validate table against current IRQ count */ |
| 9909 |
for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { |
| 9910 |
if (tp->rss_ind_tbl[i] >= tp->rxq_cnt) |
| 9911 |
break; |
| 9912 |
} |
| 9913 |
|
| 9914 |
if (i != TG3_RSS_INDIR_TBL_SIZE) |
| 9915 |
tg3_rss_init_dflt_indir_tbl(tp, tp->rxq_cnt); |
| 9916 |
} |
| 9917 |
|
| 9918 |
static void tg3_rss_write_indir_tbl(struct tg3 *tp) |
| 9919 |
{ |
| 9920 |
int i = 0; |
| 9921 |
u32 reg = MAC_RSS_INDIR_TBL_0; |
| 9922 |
|
| 9923 |
while (i < TG3_RSS_INDIR_TBL_SIZE) { |
| 9924 |
u32 val = tp->rss_ind_tbl[i]; |
| 9925 |
i++; |
| 9926 |
for (; i % 8; i++) { |
| 9927 |
val <<= 4; |
| 9928 |
val |= tp->rss_ind_tbl[i]; |
| 9929 |
} |
| 9930 |
tw32(reg, val); |
| 9931 |
reg += 4; |
| 9932 |
} |
| 9933 |
} |
| 9934 |
|
| 9935 |
static inline u32 tg3_lso_rd_dma_workaround_bit(struct tg3 *tp) |
| 9936 |
{ |
| 9937 |
if (tg3_asic_rev(tp) == ASIC_REV_5719) |
| 9938 |
return TG3_LSO_RD_DMA_TX_LENGTH_WA_5719; |
| 9939 |
else |
| 9940 |
return TG3_LSO_RD_DMA_TX_LENGTH_WA_5720; |
| 9941 |
} |
| 9942 |
|
| 9943 |
/* tp->lock is held. */ |
| 9944 |
static int tg3_reset_hw(struct tg3 *tp, bool reset_phy) |
| 9945 |
{ |
| 9946 |
u32 val, rdmac_mode; |
| 9947 |
int i, err, limit; |
| 9948 |
struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
| 9949 |
|
| 9950 |
tg3_disable_ints(tp); |
| 9951 |
|
| 9952 |
tg3_stop_fw(tp); |
| 9953 |
|
| 9954 |
tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); |
| 9955 |
|
| 9956 |
if (tg3_flag(tp, INIT_COMPLETE)) |
| 9957 |
tg3_abort_hw(tp, 1); |
| 9958 |
|
| 9959 |
if ((tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) && |
| 9960 |
!(tp->phy_flags & TG3_PHYFLG_USER_CONFIGURED)) { |
| 9961 |
tg3_phy_pull_config(tp); |
| 9962 |
tg3_eee_pull_config(tp, NULL); |
| 9963 |
tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; |
| 9964 |
} |
| 9965 |
|
| 9966 |
/* Enable MAC control of LPI */ |
| 9967 |
if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) |
| 9968 |
tg3_setup_eee(tp); |
| 9969 |
|
| 9970 |
if (reset_phy) |
| 9971 |
tg3_phy_reset(tp); |
| 9972 |
|
| 9973 |
err = tg3_chip_reset(tp); |
| 9974 |
if (err) |
| 9975 |
return err; |
| 9976 |
|
| 9977 |
tg3_write_sig_legacy(tp, RESET_KIND_INIT); |
| 9978 |
|
| 9979 |
if (tg3_chip_rev(tp) == CHIPREV_5784_AX) { |
| 9980 |
val = tr32(TG3_CPMU_CTRL); |
| 9981 |
val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); |
| 9982 |
tw32(TG3_CPMU_CTRL, val); |
| 9983 |
|
| 9984 |
val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 9985 |
val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 9986 |
val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 9987 |
tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 9988 |
|
| 9989 |
val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); |
| 9990 |
val &= ~CPMU_LNK_AWARE_MACCLK_MASK; |
| 9991 |
val |= CPMU_LNK_AWARE_MACCLK_6_25; |
| 9992 |
tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); |
| 9993 |
|
| 9994 |
val = tr32(TG3_CPMU_HST_ACC); |
| 9995 |
val &= ~CPMU_HST_ACC_MACCLK_MASK; |
| 9996 |
val |= CPMU_HST_ACC_MACCLK_6_25; |
| 9997 |
tw32(TG3_CPMU_HST_ACC, val); |
| 9998 |
} |
| 9999 |
|
| 10000 |
if (tg3_asic_rev(tp) == ASIC_REV_57780) { |
| 10001 |
val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 10002 |
val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | |
| 10003 |
PCIE_PWR_MGMT_L1_THRESH_4MS; |
| 10004 |
tw32(PCIE_PWR_MGMT_THRESH, val); |
| 10005 |
|
| 10006 |
val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; |
| 10007 |
tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); |
| 10008 |
|
| 10009 |
tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); |
| 10010 |
|
| 10011 |
val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
| 10012 |
tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); |
| 10013 |
} |
| 10014 |
|
| 10015 |
if (tg3_flag(tp, L1PLLPD_EN)) { |
| 10016 |
u32 grc_mode = tr32(GRC_MODE); |
| 10017 |
|
| 10018 |
/* Access the lower 1K of PL PCIE block registers. */ |
| 10019 |
val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 10020 |
tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 10021 |
|
| 10022 |
val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); |
| 10023 |
tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, |
| 10024 |
val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); |
| 10025 |
|
| 10026 |
tw32(GRC_MODE, grc_mode); |
| 10027 |
} |
| 10028 |
|
| 10029 |
if (tg3_flag(tp, 57765_CLASS)) { |
| 10030 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) { |
| 10031 |
u32 grc_mode = tr32(GRC_MODE); |
| 10032 |
|
| 10033 |
/* Access the lower 1K of PL PCIE block registers. */ |
| 10034 |
val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 10035 |
tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); |
| 10036 |
|
| 10037 |
val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 10038 |
TG3_PCIE_PL_LO_PHYCTL5); |
| 10039 |
tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, |
| 10040 |
val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); |
| 10041 |
|
| 10042 |
tw32(GRC_MODE, grc_mode); |
| 10043 |
} |
| 10044 |
|
| 10045 |
if (tg3_chip_rev(tp) != CHIPREV_57765_AX) { |
| 10046 |
u32 grc_mode; |
| 10047 |
|
| 10048 |
/* Fix transmit hangs */ |
| 10049 |
val = tr32(TG3_CPMU_PADRNG_CTL); |
| 10050 |
val |= TG3_CPMU_PADRNG_CTL_RDIV2; |
| 10051 |
tw32(TG3_CPMU_PADRNG_CTL, val); |
| 10052 |
|
| 10053 |
grc_mode = tr32(GRC_MODE); |
| 10054 |
|
| 10055 |
/* Access the lower 1K of DL PCIE block registers. */ |
| 10056 |
val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; |
| 10057 |
tw32(GRC_MODE, val | GRC_MODE_PCIE_DL_SEL); |
| 10058 |
|
| 10059 |
val = tr32(TG3_PCIE_TLDLPL_PORT + |
| 10060 |
TG3_PCIE_DL_LO_FTSMAX); |
| 10061 |
val &= ~TG3_PCIE_DL_LO_FTSMAX_MSK; |
| 10062 |
tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_DL_LO_FTSMAX, |
| 10063 |
val | TG3_PCIE_DL_LO_FTSMAX_VAL); |
| 10064 |
|
| 10065 |
tw32(GRC_MODE, grc_mode); |
| 10066 |
} |
| 10067 |
|
| 10068 |
val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
| 10069 |
val &= ~CPMU_LSPD_10MB_MACCLK_MASK; |
| 10070 |
val |= CPMU_LSPD_10MB_MACCLK_6_25; |
| 10071 |
tw32(TG3_CPMU_LSPD_10MB_CLK, val); |
| 10072 |
} |
| 10073 |
|
| 10074 |
/* This works around an issue with Athlon chipsets on |
| 10075 |
* B3 tigon3 silicon. This bit has no effect on any |
| 10076 |
* other revision. But do not set this on PCI Express |
| 10077 |
* chips and don't even touch the clocks if the CPMU is present. |
| 10078 |
*/ |
| 10079 |
if (!tg3_flag(tp, CPMU_PRESENT)) { |
| 10080 |
if (!tg3_flag(tp, PCI_EXPRESS)) |
| 10081 |
tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
| 10082 |
tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); |
| 10083 |
} |
| 10084 |
|
| 10085 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0 && |
| 10086 |
tg3_flag(tp, PCIX_MODE)) { |
| 10087 |
val = tr32(TG3PCI_PCISTATE); |
| 10088 |
val |= PCISTATE_RETRY_SAME_DMA; |
| 10089 |
tw32(TG3PCI_PCISTATE, val); |
| 10090 |
} |
| 10091 |
|
| 10092 |
if (tg3_flag(tp, ENABLE_APE)) { |
| 10093 |
/* Allow reads and writes to the |
| 10094 |
* APE register and memory space. |
| 10095 |
*/ |
| 10096 |
val = tr32(TG3PCI_PCISTATE); |
| 10097 |
val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
| 10098 |
PCISTATE_ALLOW_APE_SHMEM_WR | |
| 10099 |
PCISTATE_ALLOW_APE_PSPACE_WR; |
| 10100 |
tw32(TG3PCI_PCISTATE, val); |
| 10101 |
} |
| 10102 |
|
| 10103 |
if (tg3_chip_rev(tp) == CHIPREV_5704_BX) { |
| 10104 |
/* Enable some hw fixes. */ |
| 10105 |
val = tr32(TG3PCI_MSI_DATA); |
| 10106 |
val |= (1 << 26) | (1 << 28) | (1 << 29); |
| 10107 |
tw32(TG3PCI_MSI_DATA, val); |
| 10108 |
} |
| 10109 |
|
| 10110 |
/* Descriptor ring init may make accesses to the |
| 10111 |
* NIC SRAM area to setup the TX descriptors, so we |
| 10112 |
* can only do this after the hardware has been |
| 10113 |
* successfully reset. |
| 10114 |
*/ |
| 10115 |
err = tg3_init_rings(tp); |
| 10116 |
if (err) |
| 10117 |
return err; |
| 10118 |
|
| 10119 |
if (tg3_flag(tp, 57765_PLUS)) { |
| 10120 |
val = tr32(TG3PCI_DMA_RW_CTRL) & |
| 10121 |
~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 10122 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) |
| 10123 |
val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; |
| 10124 |
if (!tg3_flag(tp, 57765_CLASS) && |
| 10125 |
tg3_asic_rev(tp) != ASIC_REV_5717 && |
| 10126 |
tg3_asic_rev(tp) != ASIC_REV_5762) |
| 10127 |
val |= DMA_RWCTRL_TAGGED_STAT_WA; |
| 10128 |
tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
| 10129 |
} else if (tg3_asic_rev(tp) != ASIC_REV_5784 && |
| 10130 |
tg3_asic_rev(tp) != ASIC_REV_5761) { |
| 10131 |
/* This value is determined during the probe time DMA |
| 10132 |
* engine test, tg3_test_dma. |
| 10133 |
*/ |
| 10134 |
tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 10135 |
} |
| 10136 |
|
| 10137 |
tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | |
| 10138 |
GRC_MODE_4X_NIC_SEND_RINGS | |
| 10139 |
GRC_MODE_NO_TX_PHDR_CSUM | |
| 10140 |
GRC_MODE_NO_RX_PHDR_CSUM); |
| 10141 |
tp->grc_mode |= GRC_MODE_HOST_SENDBDS; |
| 10142 |
|
| 10143 |
/* Pseudo-header checksum is done by hardware logic and not |
| 10144 |
* the offload processors, so make the chip do the pseudo- |
| 10145 |
* header checksums on receive. For transmit it is more |
| 10146 |
* convenient to do the pseudo-header checksum in software |
| 10147 |
* as Linux does that on transmit for us in all cases. |
| 10148 |
*/ |
| 10149 |
tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; |
| 10150 |
|
| 10151 |
val = GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP; |
| 10152 |
if (tp->rxptpctl) |
| 10153 |
tw32(TG3_RX_PTP_CTL, |
| 10154 |
tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK); |
| 10155 |
|
| 10156 |
if (tg3_flag(tp, PTP_CAPABLE)) |
| 10157 |
val |= GRC_MODE_TIME_SYNC_ENABLE; |
| 10158 |
|
| 10159 |
tw32(GRC_MODE, tp->grc_mode | val); |
| 10160 |
|
| 10161 |
/* On one of the AMD platform, MRRS is restricted to 4000 because of |
| 10162 |
* south bridge limitation. As a workaround, Driver is setting MRRS |
| 10163 |
* to 2048 instead of default 4096. |
| 10164 |
*/ |
| 10165 |
if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
| 10166 |
tp->pdev->subsystem_device == TG3PCI_SUBDEVICE_ID_DELL_5762) { |
| 10167 |
val = tr32(TG3PCI_DEV_STATUS_CTRL) & ~MAX_READ_REQ_MASK; |
| 10168 |
tw32(TG3PCI_DEV_STATUS_CTRL, val | MAX_READ_REQ_SIZE_2048); |
| 10169 |
} |
| 10170 |
|
| 10171 |
/* Setup the timer prescalar register. Clock is always 66Mhz. */ |
| 10172 |
val = tr32(GRC_MISC_CFG); |
| 10173 |
val &= ~0xff; |
| 10174 |
val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); |
| 10175 |
tw32(GRC_MISC_CFG, val); |
| 10176 |
|
| 10177 |
/* Initialize MBUF/DESC pool. */ |
| 10178 |
if (tg3_flag(tp, 5750_PLUS)) { |
| 10179 |
/* Do nothing. */ |
| 10180 |
} else if (tg3_asic_rev(tp) != ASIC_REV_5705) { |
| 10181 |
tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
| 10182 |
if (tg3_asic_rev(tp) == ASIC_REV_5704) |
| 10183 |
tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
| 10184 |
else |
| 10185 |
tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); |
| 10186 |
tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); |
| 10187 |
tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); |
| 10188 |
} else if (tg3_flag(tp, TSO_CAPABLE)) { |
| 10189 |
int fw_len; |
| 10190 |
|
| 10191 |
fw_len = tp->fw_len; |
| 10192 |
fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
| 10193 |
tw32(BUFMGR_MB_POOL_ADDR, |
| 10194 |
NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); |
| 10195 |
tw32(BUFMGR_MB_POOL_SIZE, |
| 10196 |
NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); |
| 10197 |
} |
| 10198 |
|
| 10199 |
if (tp->dev->mtu <= ETH_DATA_LEN) { |
| 10200 |
tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 10201 |
tp->bufmgr_config.mbuf_read_dma_low_water); |
| 10202 |
tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 10203 |
tp->bufmgr_config.mbuf_mac_rx_low_water); |
| 10204 |
tw32(BUFMGR_MB_HIGH_WATER, |
| 10205 |
tp->bufmgr_config.mbuf_high_water); |
| 10206 |
} else { |
| 10207 |
tw32(BUFMGR_MB_RDMA_LOW_WATER, |
| 10208 |
tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); |
| 10209 |
tw32(BUFMGR_MB_MACRX_LOW_WATER, |
| 10210 |
tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); |
| 10211 |
tw32(BUFMGR_MB_HIGH_WATER, |
| 10212 |
tp->bufmgr_config.mbuf_high_water_jumbo); |
| 10213 |
} |
| 10214 |
tw32(BUFMGR_DMA_LOW_WATER, |
| 10215 |
tp->bufmgr_config.dma_low_water); |
| 10216 |
tw32(BUFMGR_DMA_HIGH_WATER, |
| 10217 |
tp->bufmgr_config.dma_high_water); |
| 10218 |
|
| 10219 |
val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
| 10220 |
if (tg3_asic_rev(tp) == ASIC_REV_5719) |
| 10221 |
val |= BUFMGR_MODE_NO_TX_UNDERRUN; |
| 10222 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 10223 |
tg3_asic_rev(tp) == ASIC_REV_5762 || |
| 10224 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || |
| 10225 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5720_A0) |
| 10226 |
val |= BUFMGR_MODE_MBLOW_ATTN_ENAB; |
| 10227 |
tw32(BUFMGR_MODE, val); |
| 10228 |
for (i = 0; i < 2000; i++) { |
| 10229 |
if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) |
| 10230 |
break; |
| 10231 |
udelay(10); |
| 10232 |
} |
| 10233 |
if (i >= 2000) { |
| 10234 |
netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
| 10235 |
return -ENODEV; |
| 10236 |
} |
| 10237 |
|
| 10238 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5906_A1) |
| 10239 |
tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
| 10240 |
|
| 10241 |
tg3_setup_rxbd_thresholds(tp); |
| 10242 |
|
| 10243 |
/* Initialize TG3_BDINFO's at: |
| 10244 |
* RCVDBDI_STD_BD: standard eth size rx ring |
| 10245 |
* RCVDBDI_JUMBO_BD: jumbo frame rx ring |
| 10246 |
* RCVDBDI_MINI_BD: small frame rx ring (??? does not work) |
| 10247 |
* |
| 10248 |
* like so: |
| 10249 |
* TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring |
| 10250 |
* TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | |
| 10251 |
* ring attribute flags |
| 10252 |
* TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM |
| 10253 |
* |
| 10254 |
* Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. |
| 10255 |
* Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. |
| 10256 |
* |
| 10257 |
* The size of each ring is fixed in the firmware, but the location is |
| 10258 |
* configurable. |
| 10259 |
*/ |
| 10260 |
tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 10261 |
((u64) tpr->rx_std_mapping >> 32)); |
| 10262 |
tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 10263 |
((u64) tpr->rx_std_mapping & 0xffffffff)); |
| 10264 |
if (!tg3_flag(tp, 5717_PLUS)) |
| 10265 |
tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
| 10266 |
NIC_SRAM_RX_BUFFER_DESC); |
| 10267 |
|
| 10268 |
/* Disable the mini ring */ |
| 10269 |
if (!tg3_flag(tp, 5705_PLUS)) |
| 10270 |
tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 10271 |
BDINFO_FLAGS_DISABLED); |
| 10272 |
|
| 10273 |
/* Program the jumbo buffer descriptor ring control |
| 10274 |
* blocks on those devices that have them. |
| 10275 |
*/ |
| 10276 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || |
| 10277 |
(tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS))) { |
| 10278 |
|
| 10279 |
if (tg3_flag(tp, JUMBO_RING_ENABLE)) { |
| 10280 |
tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 10281 |
((u64) tpr->rx_jmb_mapping >> 32)); |
| 10282 |
tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 10283 |
((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
| 10284 |
val = TG3_RX_JMB_RING_SIZE(tp) << |
| 10285 |
BDINFO_FLAGS_MAXLEN_SHIFT; |
| 10286 |
tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 10287 |
val | BDINFO_FLAGS_USE_EXT_RECV); |
| 10288 |
if (!tg3_flag(tp, USE_JUMBO_BDFLAG) || |
| 10289 |
tg3_flag(tp, 57765_CLASS) || |
| 10290 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 10291 |
tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
| 10292 |
NIC_SRAM_RX_JUMBO_BUFFER_DESC); |
| 10293 |
} else { |
| 10294 |
tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
| 10295 |
BDINFO_FLAGS_DISABLED); |
| 10296 |
} |
| 10297 |
|
| 10298 |
if (tg3_flag(tp, 57765_PLUS)) { |
| 10299 |
val = TG3_RX_STD_RING_SIZE(tp); |
| 10300 |
val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
| 10301 |
val |= (TG3_RX_STD_DMA_SZ << 2); |
| 10302 |
} else |
| 10303 |
val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
| 10304 |
} else |
| 10305 |
val = TG3_RX_STD_MAX_SIZE_5700 << BDINFO_FLAGS_MAXLEN_SHIFT; |
| 10306 |
|
| 10307 |
tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); |
| 10308 |
|
| 10309 |
tpr->rx_std_prod_idx = tp->rx_pending; |
| 10310 |
tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, tpr->rx_std_prod_idx); |
| 10311 |
|
| 10312 |
tpr->rx_jmb_prod_idx = |
| 10313 |
tg3_flag(tp, JUMBO_RING_ENABLE) ? tp->rx_jumbo_pending : 0; |
| 10314 |
tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, tpr->rx_jmb_prod_idx); |
| 10315 |
|
| 10316 |
tg3_rings_reset(tp); |
| 10317 |
|
| 10318 |
/* Initialize MAC address and backoff seed. */ |
| 10319 |
__tg3_set_mac_addr(tp, false); |
| 10320 |
|
| 10321 |
/* MTU + ethernet header + FCS + optional VLAN tag */ |
| 10322 |
tw32(MAC_RX_MTU_SIZE, |
| 10323 |
tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); |
| 10324 |
|
| 10325 |
/* The slot time is changed by tg3_setup_phy if we |
| 10326 |
* run at gigabit with half duplex. |
| 10327 |
*/ |
| 10328 |
val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
| 10329 |
(6 << TX_LENGTHS_IPG_SHIFT) | |
| 10330 |
(32 << TX_LENGTHS_SLOT_TIME_SHIFT); |
| 10331 |
|
| 10332 |
if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 10333 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 10334 |
val |= tr32(MAC_TX_LENGTHS) & |
| 10335 |
(TX_LENGTHS_JMB_FRM_LEN_MSK | |
| 10336 |
TX_LENGTHS_CNT_DWN_VAL_MSK); |
| 10337 |
|
| 10338 |
tw32(MAC_TX_LENGTHS, val); |
| 10339 |
|
| 10340 |
/* Receive rules. */ |
| 10341 |
tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); |
| 10342 |
tw32(RCVLPC_CONFIG, 0x0181); |
| 10343 |
|
| 10344 |
/* Calculate RDMAC_MODE setting early, we need it to determine |
| 10345 |
* the RCVLPC_STATE_ENABLE mask. |
| 10346 |
*/ |
| 10347 |
rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | |
| 10348 |
RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | |
| 10349 |
RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | |
| 10350 |
RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | |
| 10351 |
RDMAC_MODE_LNGREAD_ENAB); |
| 10352 |
|
| 10353 |
if (tg3_asic_rev(tp) == ASIC_REV_5717) |
| 10354 |
rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
| 10355 |
|
| 10356 |
if (tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 10357 |
tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 10358 |
tg3_asic_rev(tp) == ASIC_REV_57780) |
| 10359 |
rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
| 10360 |
RDMAC_MODE_MBUF_RBD_CRPT_ENAB | |
| 10361 |
RDMAC_MODE_MBUF_SBD_CRPT_ENAB; |
| 10362 |
|
| 10363 |
if (tg3_asic_rev(tp) == ASIC_REV_5705 && |
| 10364 |
tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) { |
| 10365 |
if (tg3_flag(tp, TSO_CAPABLE)) { |
| 10366 |
rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
| 10367 |
} else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
| 10368 |
!tg3_flag(tp, IS_5788)) { |
| 10369 |
rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 10370 |
} |
| 10371 |
} |
| 10372 |
|
| 10373 |
if (tg3_flag(tp, PCI_EXPRESS)) |
| 10374 |
rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
| 10375 |
|
| 10376 |
if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
| 10377 |
tp->dma_limit = 0; |
| 10378 |
if (tp->dev->mtu <= ETH_DATA_LEN) { |
| 10379 |
rdmac_mode |= RDMAC_MODE_JMB_2K_MMRR; |
| 10380 |
tp->dma_limit = TG3_TX_BD_DMA_MAX_2K; |
| 10381 |
} |
| 10382 |
} |
| 10383 |
|
| 10384 |
if (tg3_flag(tp, HW_TSO_1) || |
| 10385 |
tg3_flag(tp, HW_TSO_2) || |
| 10386 |
tg3_flag(tp, HW_TSO_3)) |
| 10387 |
rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
| 10388 |
|
| 10389 |
if (tg3_flag(tp, 57765_PLUS) || |
| 10390 |
tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 10391 |
tg3_asic_rev(tp) == ASIC_REV_57780) |
| 10392 |
rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
| 10393 |
|
| 10394 |
if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 10395 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 10396 |
rdmac_mode |= tr32(RDMAC_MODE) & RDMAC_MODE_H2BNC_VLAN_DET; |
| 10397 |
|
| 10398 |
if (tg3_asic_rev(tp) == ASIC_REV_5761 || |
| 10399 |
tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 10400 |
tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 10401 |
tg3_asic_rev(tp) == ASIC_REV_57780 || |
| 10402 |
tg3_flag(tp, 57765_PLUS)) { |
| 10403 |
u32 tgtreg; |
| 10404 |
|
| 10405 |
if (tg3_asic_rev(tp) == ASIC_REV_5762) |
| 10406 |
tgtreg = TG3_RDMA_RSRVCTRL_REG2; |
| 10407 |
else |
| 10408 |
tgtreg = TG3_RDMA_RSRVCTRL_REG; |
| 10409 |
|
| 10410 |
val = tr32(tgtreg); |
| 10411 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || |
| 10412 |
tg3_asic_rev(tp) == ASIC_REV_5762) { |
| 10413 |
val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | |
| 10414 |
TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | |
| 10415 |
TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); |
| 10416 |
val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B | |
| 10417 |
TG3_RDMA_RSRVCTRL_FIFO_LWM_1_5K | |
| 10418 |
TG3_RDMA_RSRVCTRL_FIFO_HWM_1_5K; |
| 10419 |
} |
| 10420 |
tw32(tgtreg, val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); |
| 10421 |
} |
| 10422 |
|
| 10423 |
if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 10424 |
tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 10425 |
tg3_asic_rev(tp) == ASIC_REV_5762) { |
| 10426 |
u32 tgtreg; |
| 10427 |
|
| 10428 |
if (tg3_asic_rev(tp) == ASIC_REV_5762) |
| 10429 |
tgtreg = TG3_LSO_RD_DMA_CRPTEN_CTRL2; |
| 10430 |
else |
| 10431 |
tgtreg = TG3_LSO_RD_DMA_CRPTEN_CTRL; |
| 10432 |
|
| 10433 |
val = tr32(tgtreg); |
| 10434 |
tw32(tgtreg, val | |
| 10435 |
TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | |
| 10436 |
TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); |
| 10437 |
} |
| 10438 |
|
| 10439 |
/* Receive/send statistics. */ |
| 10440 |
if (tg3_flag(tp, 5750_PLUS)) { |
| 10441 |
val = tr32(RCVLPC_STATS_ENABLE); |
| 10442 |
val &= ~RCVLPC_STATSENAB_DACK_FIX; |
| 10443 |
tw32(RCVLPC_STATS_ENABLE, val); |
| 10444 |
} else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && |
| 10445 |
tg3_flag(tp, TSO_CAPABLE)) { |
| 10446 |
val = tr32(RCVLPC_STATS_ENABLE); |
| 10447 |
val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; |
| 10448 |
tw32(RCVLPC_STATS_ENABLE, val); |
| 10449 |
} else { |
| 10450 |
tw32(RCVLPC_STATS_ENABLE, 0xffffff); |
| 10451 |
} |
| 10452 |
tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); |
| 10453 |
tw32(SNDDATAI_STATSENAB, 0xffffff); |
| 10454 |
tw32(SNDDATAI_STATSCTRL, |
| 10455 |
(SNDDATAI_SCTRL_ENABLE | |
| 10456 |
SNDDATAI_SCTRL_FASTUPD)); |
| 10457 |
|
| 10458 |
/* Setup host coalescing engine. */ |
| 10459 |
tw32(HOSTCC_MODE, 0); |
| 10460 |
for (i = 0; i < 2000; i++) { |
| 10461 |
if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) |
| 10462 |
break; |
| 10463 |
udelay(10); |
| 10464 |
} |
| 10465 |
|
| 10466 |
__tg3_set_coalesce(tp, &tp->coal); |
| 10467 |
|
| 10468 |
if (!tg3_flag(tp, 5705_PLUS)) { |
| 10469 |
/* Status/statistics block address. See tg3_timer, |
| 10470 |
* the tg3_periodic_fetch_stats call there, and |
| 10471 |
* tg3_get_stats to see how this works for 5705/5750 chips. |
| 10472 |
*/ |
| 10473 |
tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
| 10474 |
((u64) tp->stats_mapping >> 32)); |
| 10475 |
tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, |
| 10476 |
((u64) tp->stats_mapping & 0xffffffff)); |
| 10477 |
tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); |
| 10478 |
|
| 10479 |
tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
| 10480 |
|
| 10481 |
/* Clear statistics and status block memory areas */ |
| 10482 |
for (i = NIC_SRAM_STATS_BLK; |
| 10483 |
i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; |
| 10484 |
i += sizeof(u32)) { |
| 10485 |
tg3_write_mem(tp, i, 0); |
| 10486 |
udelay(40); |
| 10487 |
} |
| 10488 |
} |
| 10489 |
|
| 10490 |
tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); |
| 10491 |
|
| 10492 |
tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); |
| 10493 |
tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); |
| 10494 |
if (!tg3_flag(tp, 5705_PLUS)) |
| 10495 |
tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
| 10496 |
|
| 10497 |
if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
| 10498 |
tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
| 10499 |
/* reset to prevent losing 1st rx packet intermittently */ |
| 10500 |
tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 10501 |
udelay(10); |
| 10502 |
} |
| 10503 |
|
| 10504 |
tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
| 10505 |
MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | |
| 10506 |
MAC_MODE_FHDE_ENABLE; |
| 10507 |
if (tg3_flag(tp, ENABLE_APE)) |
| 10508 |
tp->mac_mode |= MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
| 10509 |
if (!tg3_flag(tp, 5705_PLUS) && |
| 10510 |
!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 10511 |
tg3_asic_rev(tp) != ASIC_REV_5700) |
| 10512 |
tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
| 10513 |
tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
| 10514 |
udelay(40); |
| 10515 |
|
| 10516 |
/* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
| 10517 |
* If TG3_FLAG_IS_NIC is zero, we should read the |
| 10518 |
* register to preserve the GPIO settings for LOMs. The GPIOs, |
| 10519 |
* whether used as inputs or outputs, are set by boot code after |
| 10520 |
* reset. |
| 10521 |
*/ |
| 10522 |
if (!tg3_flag(tp, IS_NIC)) { |
| 10523 |
u32 gpio_mask; |
| 10524 |
|
| 10525 |
gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
| 10526 |
GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | |
| 10527 |
GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; |
| 10528 |
|
| 10529 |
if (tg3_asic_rev(tp) == ASIC_REV_5752) |
| 10530 |
gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
| 10531 |
GRC_LCLCTRL_GPIO_OUTPUT3; |
| 10532 |
|
| 10533 |
if (tg3_asic_rev(tp) == ASIC_REV_5755) |
| 10534 |
gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 10535 |
|
| 10536 |
tp->grc_local_ctrl &= ~gpio_mask; |
| 10537 |
tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
| 10538 |
|
| 10539 |
/* GPIO1 must be driven high for eeprom write protect */ |
| 10540 |
if (tg3_flag(tp, EEPROM_WRITE_PROT)) |
| 10541 |
tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 10542 |
GRC_LCLCTRL_GPIO_OUTPUT1); |
| 10543 |
} |
| 10544 |
tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 10545 |
udelay(100); |
| 10546 |
|
| 10547 |
if (tg3_flag(tp, USING_MSIX)) { |
| 10548 |
val = tr32(MSGINT_MODE); |
| 10549 |
val |= MSGINT_MODE_ENABLE; |
| 10550 |
if (tp->irq_cnt > 1) |
| 10551 |
val |= MSGINT_MODE_MULTIVEC_EN; |
| 10552 |
if (!tg3_flag(tp, 1SHOT_MSI)) |
| 10553 |
val |= MSGINT_MODE_ONE_SHOT_DISABLE; |
| 10554 |
tw32(MSGINT_MODE, val); |
| 10555 |
} |
| 10556 |
|
| 10557 |
if (!tg3_flag(tp, 5705_PLUS)) { |
| 10558 |
tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
| 10559 |
udelay(40); |
| 10560 |
} |
| 10561 |
|
| 10562 |
val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | |
| 10563 |
WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | |
| 10564 |
WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | |
| 10565 |
WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | |
| 10566 |
WDMAC_MODE_LNGREAD_ENAB); |
| 10567 |
|
| 10568 |
if (tg3_asic_rev(tp) == ASIC_REV_5705 && |
| 10569 |
tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) { |
| 10570 |
if (tg3_flag(tp, TSO_CAPABLE) && |
| 10571 |
(tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A1 || |
| 10572 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A2)) { |
| 10573 |
/* nothing */ |
| 10574 |
} else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && |
| 10575 |
!tg3_flag(tp, IS_5788)) { |
| 10576 |
val |= WDMAC_MODE_RX_ACCEL; |
| 10577 |
} |
| 10578 |
} |
| 10579 |
|
| 10580 |
/* Enable host coalescing bug fix */ |
| 10581 |
if (tg3_flag(tp, 5755_PLUS)) |
| 10582 |
val |= WDMAC_MODE_STATUS_TAG_FIX; |
| 10583 |
|
| 10584 |
if (tg3_asic_rev(tp) == ASIC_REV_5785) |
| 10585 |
val |= WDMAC_MODE_BURST_ALL_DATA; |
| 10586 |
|
| 10587 |
tw32_f(WDMAC_MODE, val); |
| 10588 |
udelay(40); |
| 10589 |
|
| 10590 |
if (tg3_flag(tp, PCIX_MODE)) { |
| 10591 |
u16 pcix_cmd; |
| 10592 |
|
| 10593 |
pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 10594 |
&pcix_cmd); |
| 10595 |
if (tg3_asic_rev(tp) == ASIC_REV_5703) { |
| 10596 |
pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
| 10597 |
pcix_cmd |= PCI_X_CMD_READ_2K; |
| 10598 |
} else if (tg3_asic_rev(tp) == ASIC_REV_5704) { |
| 10599 |
pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
| 10600 |
pcix_cmd |= PCI_X_CMD_READ_2K; |
| 10601 |
} |
| 10602 |
pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
| 10603 |
pcix_cmd); |
| 10604 |
} |
| 10605 |
|
| 10606 |
tw32_f(RDMAC_MODE, rdmac_mode); |
| 10607 |
udelay(40); |
| 10608 |
|
| 10609 |
if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 10610 |
tg3_asic_rev(tp) == ASIC_REV_5720) { |
| 10611 |
for (i = 0; i < TG3_NUM_RDMA_CHANNELS; i++) { |
| 10612 |
if (tr32(TG3_RDMA_LENGTH + (i << 2)) > TG3_MAX_MTU(tp)) |
| 10613 |
break; |
| 10614 |
} |
| 10615 |
if (i < TG3_NUM_RDMA_CHANNELS) { |
| 10616 |
val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 10617 |
val |= tg3_lso_rd_dma_workaround_bit(tp); |
| 10618 |
tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val); |
| 10619 |
tg3_flag_set(tp, 5719_5720_RDMA_BUG); |
| 10620 |
} |
| 10621 |
} |
| 10622 |
|
| 10623 |
tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
| 10624 |
if (!tg3_flag(tp, 5705_PLUS)) |
| 10625 |
tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
| 10626 |
|
| 10627 |
if (tg3_asic_rev(tp) == ASIC_REV_5761) |
| 10628 |
tw32(SNDDATAC_MODE, |
| 10629 |
SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); |
| 10630 |
else |
| 10631 |
tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); |
| 10632 |
|
| 10633 |
tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
| 10634 |
tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); |
| 10635 |
val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
| 10636 |
if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
| 10637 |
val |= RCVDBDI_MODE_LRG_RING_SZ; |
| 10638 |
tw32(RCVDBDI_MODE, val); |
| 10639 |
tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
| 10640 |
if (tg3_flag(tp, HW_TSO_1) || |
| 10641 |
tg3_flag(tp, HW_TSO_2) || |
| 10642 |
tg3_flag(tp, HW_TSO_3)) |
| 10643 |
tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
| 10644 |
val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
| 10645 |
if (tg3_flag(tp, ENABLE_TSS)) |
| 10646 |
val |= SNDBDI_MODE_MULTI_TXQ_EN; |
| 10647 |
tw32(SNDBDI_MODE, val); |
| 10648 |
tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
| 10649 |
|
| 10650 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0) { |
| 10651 |
err = tg3_load_5701_a0_firmware_fix(tp); |
| 10652 |
if (err) |
| 10653 |
return err; |
| 10654 |
} |
| 10655 |
|
| 10656 |
if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
| 10657 |
/* Ignore any errors for the firmware download. If download |
| 10658 |
* fails, the device will operate with EEE disabled |
| 10659 |
*/ |
| 10660 |
tg3_load_57766_firmware(tp); |
| 10661 |
} |
| 10662 |
|
| 10663 |
if (tg3_flag(tp, TSO_CAPABLE)) { |
| 10664 |
err = tg3_load_tso_firmware(tp); |
| 10665 |
if (err) |
| 10666 |
return err; |
| 10667 |
} |
| 10668 |
|
| 10669 |
tp->tx_mode = TX_MODE_ENABLE; |
| 10670 |
|
| 10671 |
if (tg3_flag(tp, 5755_PLUS) || |
| 10672 |
tg3_asic_rev(tp) == ASIC_REV_5906) |
| 10673 |
tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; |
| 10674 |
|
| 10675 |
if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 10676 |
tg3_asic_rev(tp) == ASIC_REV_5762) { |
| 10677 |
val = TX_MODE_JMB_FRM_LEN | TX_MODE_CNT_DN_MODE; |
| 10678 |
tp->tx_mode &= ~val; |
| 10679 |
tp->tx_mode |= tr32(MAC_TX_MODE) & val; |
| 10680 |
} |
| 10681 |
|
| 10682 |
tw32_f(MAC_TX_MODE, tp->tx_mode); |
| 10683 |
udelay(100); |
| 10684 |
|
| 10685 |
if (tg3_flag(tp, ENABLE_RSS)) { |
| 10686 |
u32 rss_key[10]; |
| 10687 |
|
| 10688 |
tg3_rss_write_indir_tbl(tp); |
| 10689 |
|
| 10690 |
netdev_rss_key_fill(rss_key, 10 * sizeof(u32)); |
| 10691 |
|
| 10692 |
for (i = 0; i < 10 ; i++) |
| 10693 |
tw32(MAC_RSS_HASH_KEY_0 + i*4, rss_key[i]); |
| 10694 |
} |
| 10695 |
|
| 10696 |
tp->rx_mode = RX_MODE_ENABLE; |
| 10697 |
if (tg3_flag(tp, 5755_PLUS)) |
| 10698 |
tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
| 10699 |
|
| 10700 |
if (tg3_asic_rev(tp) == ASIC_REV_5762) |
| 10701 |
tp->rx_mode |= RX_MODE_IPV4_FRAG_FIX; |
| 10702 |
|
| 10703 |
if (tg3_flag(tp, ENABLE_RSS)) |
| 10704 |
tp->rx_mode |= RX_MODE_RSS_ENABLE | |
| 10705 |
RX_MODE_RSS_ITBL_HASH_BITS_7 | |
| 10706 |
RX_MODE_RSS_IPV6_HASH_EN | |
| 10707 |
RX_MODE_RSS_TCP_IPV6_HASH_EN | |
| 10708 |
RX_MODE_RSS_IPV4_HASH_EN | |
| 10709 |
RX_MODE_RSS_TCP_IPV4_HASH_EN; |
| 10710 |
|
| 10711 |
tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 10712 |
udelay(10); |
| 10713 |
|
| 10714 |
tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 10715 |
|
| 10716 |
tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); |
| 10717 |
if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 10718 |
tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
| 10719 |
udelay(10); |
| 10720 |
} |
| 10721 |
tw32_f(MAC_RX_MODE, tp->rx_mode); |
| 10722 |
udelay(10); |
| 10723 |
|
| 10724 |
if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 10725 |
if ((tg3_asic_rev(tp) == ASIC_REV_5704) && |
| 10726 |
!(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
| 10727 |
/* Set drive transmission level to 1.2V */ |
| 10728 |
/* only if the signal pre-emphasis bit is not set */ |
| 10729 |
val = tr32(MAC_SERDES_CFG); |
| 10730 |
val &= 0xfffff000; |
| 10731 |
val |= 0x880; |
| 10732 |
tw32(MAC_SERDES_CFG, val); |
| 10733 |
} |
| 10734 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5703_A1) |
| 10735 |
tw32(MAC_SERDES_CFG, 0x616000); |
| 10736 |
} |
| 10737 |
|
| 10738 |
/* Prevent chip from dropping frames when flow control |
| 10739 |
* is enabled. |
| 10740 |
*/ |
| 10741 |
if (tg3_flag(tp, 57765_CLASS)) |
| 10742 |
val = 1; |
| 10743 |
else |
| 10744 |
val = 2; |
| 10745 |
tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); |
| 10746 |
|
| 10747 |
if (tg3_asic_rev(tp) == ASIC_REV_5704 && |
| 10748 |
(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 10749 |
/* Use hardware link auto-negotiation */ |
| 10750 |
tg3_flag_set(tp, HW_AUTONEG); |
| 10751 |
} |
| 10752 |
|
| 10753 |
if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
| 10754 |
tg3_asic_rev(tp) == ASIC_REV_5714) { |
| 10755 |
u32 tmp; |
| 10756 |
|
| 10757 |
tmp = tr32(SERDES_RX_CTRL); |
| 10758 |
tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); |
| 10759 |
tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; |
| 10760 |
tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; |
| 10761 |
tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
| 10762 |
} |
| 10763 |
|
| 10764 |
if (!tg3_flag(tp, USE_PHYLIB)) { |
| 10765 |
if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
| 10766 |
tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
| 10767 |
|
| 10768 |
err = tg3_setup_phy(tp, false); |
| 10769 |
if (err) |
| 10770 |
return err; |
| 10771 |
|
| 10772 |
if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 10773 |
!(tp->phy_flags & TG3_PHYFLG_IS_FET)) { |
| 10774 |
u32 tmp; |
| 10775 |
|
| 10776 |
/* Clear CRC stats. */ |
| 10777 |
if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { |
| 10778 |
tg3_writephy(tp, MII_TG3_TEST1, |
| 10779 |
tmp | MII_TG3_TEST1_CRC_EN); |
| 10780 |
tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
| 10781 |
} |
| 10782 |
} |
| 10783 |
} |
| 10784 |
|
| 10785 |
__tg3_set_rx_mode(tp->dev); |
| 10786 |
|
| 10787 |
/* Initialize receive rules. */ |
| 10788 |
tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); |
| 10789 |
tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 10790 |
tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); |
| 10791 |
tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); |
| 10792 |
|
| 10793 |
if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) |
| 10794 |
limit = 8; |
| 10795 |
else |
| 10796 |
limit = 16; |
| 10797 |
if (tg3_flag(tp, ENABLE_ASF)) |
| 10798 |
limit -= 4; |
| 10799 |
switch (limit) { |
| 10800 |
case 16: |
| 10801 |
tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); |
| 10802 |
fallthrough; |
| 10803 |
case 15: |
| 10804 |
tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); |
| 10805 |
fallthrough; |
| 10806 |
case 14: |
| 10807 |
tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); |
| 10808 |
fallthrough; |
| 10809 |
case 13: |
| 10810 |
tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); |
| 10811 |
fallthrough; |
| 10812 |
case 12: |
| 10813 |
tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); |
| 10814 |
fallthrough; |
| 10815 |
case 11: |
| 10816 |
tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); |
| 10817 |
fallthrough; |
| 10818 |
case 10: |
| 10819 |
tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); |
| 10820 |
fallthrough; |
| 10821 |
case 9: |
| 10822 |
tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); |
| 10823 |
fallthrough; |
| 10824 |
case 8: |
| 10825 |
tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); |
| 10826 |
fallthrough; |
| 10827 |
case 7: |
| 10828 |
tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); |
| 10829 |
fallthrough; |
| 10830 |
case 6: |
| 10831 |
tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); |
| 10832 |
fallthrough; |
| 10833 |
case 5: |
| 10834 |
tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); |
| 10835 |
fallthrough; |
| 10836 |
case 4: |
| 10837 |
/* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ |
| 10838 |
case 3: |
| 10839 |
/* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ |
| 10840 |
case 2: |
| 10841 |
case 1: |
| 10842 |
|
| 10843 |
default: |
| 10844 |
break; |
| 10845 |
} |
| 10846 |
|
| 10847 |
if (tg3_flag(tp, ENABLE_APE)) |
| 10848 |
/* Write our heartbeat update interval to APE. */ |
| 10849 |
tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, |
| 10850 |
APE_HOST_HEARTBEAT_INT_5SEC); |
| 10851 |
|
| 10852 |
tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
| 10853 |
|
| 10854 |
return 0; |
| 10855 |
} |
| 10856 |
|
| 10857 |
/* Called at device open time to get the chip ready for |
| 10858 |
* packet processing. Invoked with tp->lock held. |
| 10859 |
*/ |
| 10860 |
static int tg3_init_hw(struct tg3 *tp, bool reset_phy) |
| 10861 |
{ |
| 10862 |
/* Chip may have been just powered on. If so, the boot code may still |
| 10863 |
* be running initialization. Wait for it to finish to avoid races in |
| 10864 |
* accessing the hardware. |
| 10865 |
*/ |
| 10866 |
tg3_enable_register_access(tp); |
| 10867 |
tg3_poll_fw(tp); |
| 10868 |
|
| 10869 |
tg3_switch_clocks(tp); |
| 10870 |
|
| 10871 |
tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 10872 |
|
| 10873 |
return tg3_reset_hw(tp, reset_phy); |
| 10874 |
} |
| 10875 |
|
| 10876 |
#ifdef CONFIG_TIGON3_HWMON |
| 10877 |
static void tg3_sd_scan_scratchpad(struct tg3 *tp, struct tg3_ocir *ocir) |
| 10878 |
{ |
| 10879 |
u32 off, len = TG3_OCIR_LEN; |
| 10880 |
int i; |
| 10881 |
|
| 10882 |
for (i = 0, off = 0; i < TG3_SD_NUM_RECS; i++, ocir++, off += len) { |
| 10883 |
tg3_ape_scratchpad_read(tp, (u32 *) ocir, off, len); |
| 10884 |
|
| 10885 |
if (ocir->signature != TG3_OCIR_SIG_MAGIC || |
| 10886 |
!(ocir->version_flags & TG3_OCIR_FLAG_ACTIVE)) |
| 10887 |
memset(ocir, 0, len); |
| 10888 |
} |
| 10889 |
} |
| 10890 |
|
| 10891 |
/* sysfs attributes for hwmon */ |
| 10892 |
static ssize_t tg3_show_temp(struct device *dev, |
| 10893 |
struct device_attribute *devattr, char *buf) |
| 10894 |
{ |
| 10895 |
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 10896 |
struct tg3 *tp = dev_get_drvdata(dev); |
| 10897 |
u32 temperature; |
| 10898 |
|
| 10899 |
spin_lock_bh(&tp->lock); |
| 10900 |
tg3_ape_scratchpad_read(tp, &temperature, attr->index, |
| 10901 |
sizeof(temperature)); |
| 10902 |
spin_unlock_bh(&tp->lock); |
| 10903 |
return sprintf(buf, "%u\n", temperature * 1000); |
| 10904 |
} |
| 10905 |
|
| 10906 |
|
| 10907 |
static SENSOR_DEVICE_ATTR(temp1_input, 0444, tg3_show_temp, NULL, |
| 10908 |
TG3_TEMP_SENSOR_OFFSET); |
| 10909 |
static SENSOR_DEVICE_ATTR(temp1_crit, 0444, tg3_show_temp, NULL, |
| 10910 |
TG3_TEMP_CAUTION_OFFSET); |
| 10911 |
static SENSOR_DEVICE_ATTR(temp1_max, 0444, tg3_show_temp, NULL, |
| 10912 |
TG3_TEMP_MAX_OFFSET); |
| 10913 |
|
| 10914 |
static struct attribute *tg3_attrs[] = { |
| 10915 |
&sensor_dev_attr_temp1_input.dev_attr.attr, |
| 10916 |
&sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 10917 |
&sensor_dev_attr_temp1_max.dev_attr.attr, |
| 10918 |
NULL |
| 10919 |
}; |
| 10920 |
ATTRIBUTE_GROUPS(tg3); |
| 10921 |
|
| 10922 |
static void tg3_hwmon_close(struct tg3 *tp) |
| 10923 |
{ |
| 10924 |
if (tp->hwmon_dev) { |
| 10925 |
hwmon_device_unregister(tp->hwmon_dev); |
| 10926 |
tp->hwmon_dev = NULL; |
| 10927 |
} |
| 10928 |
} |
| 10929 |
|
| 10930 |
static void tg3_hwmon_open(struct tg3 *tp) |
| 10931 |
{ |
| 10932 |
int i; |
| 10933 |
u32 size = 0; |
| 10934 |
struct pci_dev *pdev = tp->pdev; |
| 10935 |
struct tg3_ocir ocirs[TG3_SD_NUM_RECS]; |
| 10936 |
|
| 10937 |
tg3_sd_scan_scratchpad(tp, ocirs); |
| 10938 |
|
| 10939 |
for (i = 0; i < TG3_SD_NUM_RECS; i++) { |
| 10940 |
if (!ocirs[i].src_data_length) |
| 10941 |
continue; |
| 10942 |
|
| 10943 |
size += ocirs[i].src_hdr_length; |
| 10944 |
size += ocirs[i].src_data_length; |
| 10945 |
} |
| 10946 |
|
| 10947 |
if (!size) |
| 10948 |
return; |
| 10949 |
|
| 10950 |
tp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev, "tg3", |
| 10951 |
tp, tg3_groups); |
| 10952 |
if (IS_ERR(tp->hwmon_dev)) { |
| 10953 |
tp->hwmon_dev = NULL; |
| 10954 |
dev_err(&pdev->dev, "Cannot register hwmon device, aborting\n"); |
| 10955 |
} |
| 10956 |
} |
| 10957 |
#else |
| 10958 |
static inline void tg3_hwmon_close(struct tg3 *tp) { } |
| 10959 |
static inline void tg3_hwmon_open(struct tg3 *tp) { } |
| 10960 |
#endif /* CONFIG_TIGON3_HWMON */ |
| 10961 |
|
| 10962 |
|
| 10963 |
#define TG3_STAT_ADD32(PSTAT, REG) \ |
| 10964 |
do { u32 __val = tr32(REG); \ |
| 10965 |
(PSTAT)->low += __val; \ |
| 10966 |
if ((PSTAT)->low < __val) \ |
| 10967 |
(PSTAT)->high += 1; \ |
| 10968 |
} while (0) |
| 10969 |
|
| 10970 |
static void tg3_periodic_fetch_stats(struct tg3 *tp) |
| 10971 |
{ |
| 10972 |
struct tg3_hw_stats *sp = tp->hw_stats; |
| 10973 |
|
| 10974 |
if (!tp->link_up) |
| 10975 |
return; |
| 10976 |
|
| 10977 |
TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); |
| 10978 |
TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); |
| 10979 |
TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); |
| 10980 |
TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); |
| 10981 |
TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); |
| 10982 |
TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); |
| 10983 |
TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); |
| 10984 |
TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); |
| 10985 |
TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); |
| 10986 |
TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); |
| 10987 |
TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); |
| 10988 |
TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); |
| 10989 |
TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); |
| 10990 |
if (unlikely(tg3_flag(tp, 5719_5720_RDMA_BUG) && |
| 10991 |
(sp->tx_ucast_packets.low + sp->tx_mcast_packets.low + |
| 10992 |
sp->tx_bcast_packets.low) > TG3_NUM_RDMA_CHANNELS)) { |
| 10993 |
u32 val; |
| 10994 |
|
| 10995 |
val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
| 10996 |
val &= ~tg3_lso_rd_dma_workaround_bit(tp); |
| 10997 |
tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val); |
| 10998 |
tg3_flag_clear(tp, 5719_5720_RDMA_BUG); |
| 10999 |
} |
| 11000 |
|
| 11001 |
TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); |
| 11002 |
TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); |
| 11003 |
TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); |
| 11004 |
TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); |
| 11005 |
TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); |
| 11006 |
TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); |
| 11007 |
TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); |
| 11008 |
TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); |
| 11009 |
TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); |
| 11010 |
TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); |
| 11011 |
TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); |
| 11012 |
TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); |
| 11013 |
TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); |
| 11014 |
TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); |
| 11015 |
|
| 11016 |
TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); |
| 11017 |
if (tg3_asic_rev(tp) != ASIC_REV_5717 && |
| 11018 |
tg3_asic_rev(tp) != ASIC_REV_5762 && |
| 11019 |
tg3_chip_rev_id(tp) != CHIPREV_ID_5719_A0 && |
| 11020 |
tg3_chip_rev_id(tp) != CHIPREV_ID_5720_A0) { |
| 11021 |
TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
| 11022 |
} else { |
| 11023 |
u32 val = tr32(HOSTCC_FLOW_ATTN); |
| 11024 |
val = (val & HOSTCC_FLOW_ATTN_MBUF_LWM) ? 1 : 0; |
| 11025 |
if (val) { |
| 11026 |
tw32(HOSTCC_FLOW_ATTN, HOSTCC_FLOW_ATTN_MBUF_LWM); |
| 11027 |
sp->rx_discards.low += val; |
| 11028 |
if (sp->rx_discards.low < val) |
| 11029 |
sp->rx_discards.high += 1; |
| 11030 |
} |
| 11031 |
sp->mbuf_lwm_thresh_hit = sp->rx_discards; |
| 11032 |
} |
| 11033 |
TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
| 11034 |
} |
| 11035 |
|
| 11036 |
static void tg3_chk_missed_msi(struct tg3 *tp) |
| 11037 |
{ |
| 11038 |
u32 i; |
| 11039 |
|
| 11040 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 11041 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 11042 |
|
| 11043 |
if (tg3_has_work(tnapi)) { |
| 11044 |
if (tnapi->last_rx_cons == tnapi->rx_rcb_ptr && |
| 11045 |
tnapi->last_tx_cons == tnapi->tx_cons) { |
| 11046 |
if (tnapi->chk_msi_cnt < 1) { |
| 11047 |
tnapi->chk_msi_cnt++; |
| 11048 |
return; |
| 11049 |
} |
| 11050 |
tg3_msi(0, tnapi); |
| 11051 |
} |
| 11052 |
} |
| 11053 |
tnapi->chk_msi_cnt = 0; |
| 11054 |
tnapi->last_rx_cons = tnapi->rx_rcb_ptr; |
| 11055 |
tnapi->last_tx_cons = tnapi->tx_cons; |
| 11056 |
} |
| 11057 |
} |
| 11058 |
|
| 11059 |
static void tg3_timer(struct timer_list *t) |
| 11060 |
{ |
| 11061 |
struct tg3 *tp = timer_container_of(tp, t, timer); |
| 11062 |
|
| 11063 |
spin_lock(&tp->lock); |
| 11064 |
|
| 11065 |
if (tp->irq_sync || tg3_flag(tp, RESET_TASK_PENDING)) { |
| 11066 |
spin_unlock(&tp->lock); |
| 11067 |
goto restart_timer; |
| 11068 |
} |
| 11069 |
|
| 11070 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 11071 |
tg3_flag(tp, 57765_CLASS)) |
| 11072 |
tg3_chk_missed_msi(tp); |
| 11073 |
|
| 11074 |
if (tg3_flag(tp, FLUSH_POSTED_WRITES)) { |
| 11075 |
/* BCM4785: Flush posted writes from GbE to host memory. */ |
| 11076 |
tr32(HOSTCC_MODE); |
| 11077 |
} |
| 11078 |
|
| 11079 |
if (!tg3_flag(tp, TAGGED_STATUS)) { |
| 11080 |
/* All of this garbage is because when using non-tagged |
| 11081 |
* IRQ status the mailbox/status_block protocol the chip |
| 11082 |
* uses with the cpu is race prone. |
| 11083 |
*/ |
| 11084 |
if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
| 11085 |
tw32(GRC_LOCAL_CTRL, |
| 11086 |
tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); |
| 11087 |
} else { |
| 11088 |
tw32(HOSTCC_MODE, tp->coalesce_mode | |
| 11089 |
HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
| 11090 |
} |
| 11091 |
|
| 11092 |
if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 11093 |
spin_unlock(&tp->lock); |
| 11094 |
tg3_reset_task_schedule(tp); |
| 11095 |
goto restart_timer; |
| 11096 |
} |
| 11097 |
} |
| 11098 |
|
| 11099 |
/* This part only runs once per second. */ |
| 11100 |
if (!--tp->timer_counter) { |
| 11101 |
if (tg3_flag(tp, 5705_PLUS)) |
| 11102 |
tg3_periodic_fetch_stats(tp); |
| 11103 |
|
| 11104 |
if (tp->setlpicnt && !--tp->setlpicnt) |
| 11105 |
tg3_phy_eee_enable(tp); |
| 11106 |
|
| 11107 |
if (tg3_flag(tp, USE_LINKCHG_REG)) { |
| 11108 |
u32 mac_stat; |
| 11109 |
int phy_event; |
| 11110 |
|
| 11111 |
mac_stat = tr32(MAC_STATUS); |
| 11112 |
|
| 11113 |
phy_event = 0; |
| 11114 |
if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
| 11115 |
if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
| 11116 |
phy_event = 1; |
| 11117 |
} else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) |
| 11118 |
phy_event = 1; |
| 11119 |
|
| 11120 |
if (phy_event) |
| 11121 |
tg3_setup_phy(tp, false); |
| 11122 |
} else if (tg3_flag(tp, POLL_SERDES)) { |
| 11123 |
u32 mac_stat = tr32(MAC_STATUS); |
| 11124 |
int need_setup = 0; |
| 11125 |
|
| 11126 |
if (tp->link_up && |
| 11127 |
(mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
| 11128 |
need_setup = 1; |
| 11129 |
} |
| 11130 |
if (!tp->link_up && |
| 11131 |
(mac_stat & (MAC_STATUS_PCS_SYNCED | |
| 11132 |
MAC_STATUS_SIGNAL_DET))) { |
| 11133 |
need_setup = 1; |
| 11134 |
} |
| 11135 |
if (need_setup) { |
| 11136 |
if (!tp->serdes_counter) { |
| 11137 |
tw32_f(MAC_MODE, |
| 11138 |
(tp->mac_mode & |
| 11139 |
~MAC_MODE_PORT_MODE_MASK)); |
| 11140 |
udelay(40); |
| 11141 |
tw32_f(MAC_MODE, tp->mac_mode); |
| 11142 |
udelay(40); |
| 11143 |
} |
| 11144 |
tg3_setup_phy(tp, false); |
| 11145 |
} |
| 11146 |
} else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
| 11147 |
tg3_flag(tp, 5780_CLASS)) { |
| 11148 |
tg3_serdes_parallel_detect(tp); |
| 11149 |
} else if (tg3_flag(tp, POLL_CPMU_LINK)) { |
| 11150 |
u32 cpmu = tr32(TG3_CPMU_STATUS); |
| 11151 |
bool link_up = !((cpmu & TG3_CPMU_STATUS_LINK_MASK) == |
| 11152 |
TG3_CPMU_STATUS_LINK_MASK); |
| 11153 |
|
| 11154 |
if (link_up != tp->link_up) |
| 11155 |
tg3_setup_phy(tp, false); |
| 11156 |
} |
| 11157 |
|
| 11158 |
tp->timer_counter = tp->timer_multiplier; |
| 11159 |
} |
| 11160 |
|
| 11161 |
/* Heartbeat is only sent once every 2 seconds. |
| 11162 |
* |
| 11163 |
* The heartbeat is to tell the ASF firmware that the host |
| 11164 |
* driver is still alive. In the event that the OS crashes, |
| 11165 |
* ASF needs to reset the hardware to free up the FIFO space |
| 11166 |
* that may be filled with rx packets destined for the host. |
| 11167 |
* If the FIFO is full, ASF will no longer function properly. |
| 11168 |
* |
| 11169 |
* Unintended resets have been reported on real time kernels |
| 11170 |
* where the timer doesn't run on time. Netpoll will also have |
| 11171 |
* same problem. |
| 11172 |
* |
| 11173 |
* The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware |
| 11174 |
* to check the ring condition when the heartbeat is expiring |
| 11175 |
* before doing the reset. This will prevent most unintended |
| 11176 |
* resets. |
| 11177 |
*/ |
| 11178 |
if (!--tp->asf_counter) { |
| 11179 |
if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
| 11180 |
tg3_wait_for_event_ack(tp); |
| 11181 |
|
| 11182 |
tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
| 11183 |
FWCMD_NICDRV_ALIVE3); |
| 11184 |
tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
| 11185 |
tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
| 11186 |
TG3_FW_UPDATE_TIMEOUT_SEC); |
| 11187 |
|
| 11188 |
tg3_generate_fw_event(tp); |
| 11189 |
} |
| 11190 |
tp->asf_counter = tp->asf_multiplier; |
| 11191 |
} |
| 11192 |
|
| 11193 |
/* Update the APE heartbeat every 5 seconds.*/ |
| 11194 |
tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL); |
| 11195 |
|
| 11196 |
spin_unlock(&tp->lock); |
| 11197 |
|
| 11198 |
restart_timer: |
| 11199 |
tp->timer.expires = jiffies + tp->timer_offset; |
| 11200 |
add_timer(&tp->timer); |
| 11201 |
} |
| 11202 |
|
| 11203 |
static void tg3_timer_init(struct tg3 *tp) |
| 11204 |
{ |
| 11205 |
if (tg3_flag(tp, TAGGED_STATUS) && |
| 11206 |
tg3_asic_rev(tp) != ASIC_REV_5717 && |
| 11207 |
!tg3_flag(tp, 57765_CLASS)) |
| 11208 |
tp->timer_offset = HZ; |
| 11209 |
else |
| 11210 |
tp->timer_offset = HZ / 10; |
| 11211 |
|
| 11212 |
BUG_ON(tp->timer_offset > HZ); |
| 11213 |
|
| 11214 |
tp->timer_multiplier = (HZ / tp->timer_offset); |
| 11215 |
tp->asf_multiplier = (HZ / tp->timer_offset) * |
| 11216 |
TG3_FW_UPDATE_FREQ_SEC; |
| 11217 |
|
| 11218 |
timer_setup(&tp->timer, tg3_timer, 0); |
| 11219 |
} |
| 11220 |
|
| 11221 |
static void tg3_timer_start(struct tg3 *tp) |
| 11222 |
{ |
| 11223 |
tp->asf_counter = tp->asf_multiplier; |
| 11224 |
tp->timer_counter = tp->timer_multiplier; |
| 11225 |
|
| 11226 |
tp->timer.expires = jiffies + tp->timer_offset; |
| 11227 |
add_timer(&tp->timer); |
| 11228 |
} |
| 11229 |
|
| 11230 |
static void tg3_timer_stop(struct tg3 *tp) |
| 11231 |
{ |
| 11232 |
timer_delete_sync(&tp->timer); |
| 11233 |
} |
| 11234 |
|
| 11235 |
/* Restart hardware after configuration changes, self-test, etc. |
| 11236 |
* Invoked with tp->lock held. |
| 11237 |
*/ |
| 11238 |
static int tg3_restart_hw(struct tg3 *tp, bool reset_phy) |
| 11239 |
__releases(tp->lock) |
| 11240 |
__acquires(tp->lock) |
| 11241 |
__releases(tp->dev->lock) |
| 11242 |
__acquires(tp->dev->lock) |
| 11243 |
{ |
| 11244 |
int err; |
| 11245 |
|
| 11246 |
err = tg3_init_hw(tp, reset_phy); |
| 11247 |
if (err) { |
| 11248 |
netdev_err(tp->dev, |
| 11249 |
"Failed to re-initialize device, aborting\n"); |
| 11250 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11251 |
tg3_full_unlock(tp); |
| 11252 |
tg3_timer_stop(tp); |
| 11253 |
tp->irq_sync = 0; |
| 11254 |
tg3_napi_enable(tp); |
| 11255 |
netdev_unlock(tp->dev); |
| 11256 |
dev_close(tp->dev); |
| 11257 |
netdev_lock(tp->dev); |
| 11258 |
tg3_full_lock(tp, 0); |
| 11259 |
} |
| 11260 |
return err; |
| 11261 |
} |
| 11262 |
|
| 11263 |
static void tg3_reset_task(struct work_struct *work) |
| 11264 |
{ |
| 11265 |
struct tg3 *tp = container_of(work, struct tg3, reset_task); |
| 11266 |
int err; |
| 11267 |
|
| 11268 |
rtnl_lock(); |
| 11269 |
tg3_full_lock(tp, 0); |
| 11270 |
|
| 11271 |
if (tp->pcierr_recovery || !netif_running(tp->dev) || |
| 11272 |
tp->pdev->error_state != pci_channel_io_normal) { |
| 11273 |
tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 11274 |
tg3_full_unlock(tp); |
| 11275 |
rtnl_unlock(); |
| 11276 |
return; |
| 11277 |
} |
| 11278 |
|
| 11279 |
tg3_full_unlock(tp); |
| 11280 |
|
| 11281 |
tg3_phy_stop(tp); |
| 11282 |
|
| 11283 |
tg3_netif_stop(tp); |
| 11284 |
|
| 11285 |
netdev_lock(tp->dev); |
| 11286 |
tg3_full_lock(tp, 1); |
| 11287 |
|
| 11288 |
if (tg3_flag(tp, TX_RECOVERY_PENDING)) { |
| 11289 |
tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 11290 |
tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 11291 |
tg3_flag_set(tp, MBOX_WRITE_REORDER); |
| 11292 |
tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
| 11293 |
} |
| 11294 |
|
| 11295 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 11296 |
err = tg3_init_hw(tp, true); |
| 11297 |
if (err) { |
| 11298 |
tg3_full_unlock(tp); |
| 11299 |
tp->irq_sync = 0; |
| 11300 |
tg3_napi_enable(tp); |
| 11301 |
/* Clear this flag so that tg3_reset_task_cancel() will not |
| 11302 |
* call cancel_work_sync() and wait forever. |
| 11303 |
*/ |
| 11304 |
tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 11305 |
netdev_unlock(tp->dev); |
| 11306 |
dev_close(tp->dev); |
| 11307 |
goto out; |
| 11308 |
} |
| 11309 |
|
| 11310 |
tg3_netif_start(tp); |
| 11311 |
tg3_full_unlock(tp); |
| 11312 |
netdev_unlock(tp->dev); |
| 11313 |
tg3_phy_start(tp); |
| 11314 |
tg3_flag_clear(tp, RESET_TASK_PENDING); |
| 11315 |
out: |
| 11316 |
rtnl_unlock(); |
| 11317 |
} |
| 11318 |
|
| 11319 |
static int tg3_request_irq(struct tg3 *tp, int irq_num) |
| 11320 |
{ |
| 11321 |
irq_handler_t fn; |
| 11322 |
unsigned long flags; |
| 11323 |
char *name; |
| 11324 |
struct tg3_napi *tnapi = &tp->napi[irq_num]; |
| 11325 |
|
| 11326 |
if (tp->irq_cnt == 1) |
| 11327 |
name = tp->dev->name; |
| 11328 |
else { |
| 11329 |
name = &tnapi->irq_lbl[0]; |
| 11330 |
if (tnapi->tx_buffers && tnapi->rx_rcb) |
| 11331 |
snprintf(name, sizeof(tnapi->irq_lbl), |
| 11332 |
"%s-txrx-%d", tp->dev->name, irq_num); |
| 11333 |
else if (tnapi->tx_buffers) |
| 11334 |
snprintf(name, sizeof(tnapi->irq_lbl), |
| 11335 |
"%s-tx-%d", tp->dev->name, irq_num); |
| 11336 |
else if (tnapi->rx_rcb) |
| 11337 |
snprintf(name, sizeof(tnapi->irq_lbl), |
| 11338 |
"%s-rx-%d", tp->dev->name, irq_num); |
| 11339 |
else |
| 11340 |
snprintf(name, sizeof(tnapi->irq_lbl), |
| 11341 |
"%s-%d", tp->dev->name, irq_num); |
| 11342 |
} |
| 11343 |
|
| 11344 |
if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
| 11345 |
fn = tg3_msi; |
| 11346 |
if (tg3_flag(tp, 1SHOT_MSI)) |
| 11347 |
fn = tg3_msi_1shot; |
| 11348 |
flags = 0; |
| 11349 |
} else { |
| 11350 |
fn = tg3_interrupt; |
| 11351 |
if (tg3_flag(tp, TAGGED_STATUS)) |
| 11352 |
fn = tg3_interrupt_tagged; |
| 11353 |
flags = IRQF_SHARED; |
| 11354 |
} |
| 11355 |
|
| 11356 |
return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); |
| 11357 |
} |
| 11358 |
|
| 11359 |
static int tg3_test_interrupt(struct tg3 *tp) |
| 11360 |
{ |
| 11361 |
struct tg3_napi *tnapi = &tp->napi[0]; |
| 11362 |
struct net_device *dev = tp->dev; |
| 11363 |
int err, i, intr_ok = 0; |
| 11364 |
u32 val; |
| 11365 |
|
| 11366 |
if (!netif_running(dev)) |
| 11367 |
return -ENODEV; |
| 11368 |
|
| 11369 |
tg3_disable_ints(tp); |
| 11370 |
|
| 11371 |
free_irq(tnapi->irq_vec, tnapi); |
| 11372 |
|
| 11373 |
/* |
| 11374 |
* Turn off MSI one shot mode. Otherwise this test has no |
| 11375 |
* observable way to know whether the interrupt was delivered. |
| 11376 |
*/ |
| 11377 |
if (tg3_flag(tp, 57765_PLUS)) { |
| 11378 |
val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
| 11379 |
tw32(MSGINT_MODE, val); |
| 11380 |
} |
| 11381 |
|
| 11382 |
err = request_irq(tnapi->irq_vec, tg3_test_isr, |
| 11383 |
IRQF_SHARED, dev->name, tnapi); |
| 11384 |
if (err) |
| 11385 |
return err; |
| 11386 |
|
| 11387 |
tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
| 11388 |
tg3_enable_ints(tp); |
| 11389 |
|
| 11390 |
tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
| 11391 |
tnapi->coal_now); |
| 11392 |
|
| 11393 |
for (i = 0; i < 5; i++) { |
| 11394 |
u32 int_mbox, misc_host_ctrl; |
| 11395 |
|
| 11396 |
int_mbox = tr32_mailbox(tnapi->int_mbox); |
| 11397 |
misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
| 11398 |
|
| 11399 |
if ((int_mbox != 0) || |
| 11400 |
(misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { |
| 11401 |
intr_ok = 1; |
| 11402 |
break; |
| 11403 |
} |
| 11404 |
|
| 11405 |
if (tg3_flag(tp, 57765_PLUS) && |
| 11406 |
tnapi->hw_status->status_tag != tnapi->last_tag) |
| 11407 |
tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
| 11408 |
|
| 11409 |
msleep(10); |
| 11410 |
} |
| 11411 |
|
| 11412 |
tg3_disable_ints(tp); |
| 11413 |
|
| 11414 |
free_irq(tnapi->irq_vec, tnapi); |
| 11415 |
|
| 11416 |
err = tg3_request_irq(tp, 0); |
| 11417 |
|
| 11418 |
if (err) |
| 11419 |
return err; |
| 11420 |
|
| 11421 |
if (intr_ok) { |
| 11422 |
/* Reenable MSI one shot mode. */ |
| 11423 |
if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, 1SHOT_MSI)) { |
| 11424 |
val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
| 11425 |
tw32(MSGINT_MODE, val); |
| 11426 |
} |
| 11427 |
return 0; |
| 11428 |
} |
| 11429 |
|
| 11430 |
return -EIO; |
| 11431 |
} |
| 11432 |
|
| 11433 |
/* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is |
| 11434 |
* successfully restored |
| 11435 |
*/ |
| 11436 |
static int tg3_test_msi(struct tg3 *tp) |
| 11437 |
{ |
| 11438 |
int err; |
| 11439 |
u16 pci_cmd; |
| 11440 |
|
| 11441 |
if (!tg3_flag(tp, USING_MSI)) |
| 11442 |
return 0; |
| 11443 |
|
| 11444 |
/* Turn off SERR reporting in case MSI terminates with Master |
| 11445 |
* Abort. |
| 11446 |
*/ |
| 11447 |
pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 11448 |
pci_write_config_word(tp->pdev, PCI_COMMAND, |
| 11449 |
pci_cmd & ~PCI_COMMAND_SERR); |
| 11450 |
|
| 11451 |
err = tg3_test_interrupt(tp); |
| 11452 |
|
| 11453 |
pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 11454 |
|
| 11455 |
if (!err) |
| 11456 |
return 0; |
| 11457 |
|
| 11458 |
/* other failures */ |
| 11459 |
if (err != -EIO) |
| 11460 |
return err; |
| 11461 |
|
| 11462 |
/* MSI test failed, go back to INTx mode */ |
| 11463 |
netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
| 11464 |
"to INTx mode. Please report this failure to the PCI " |
| 11465 |
"maintainer and include system chipset information\n"); |
| 11466 |
|
| 11467 |
free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
| 11468 |
|
| 11469 |
pci_disable_msi(tp->pdev); |
| 11470 |
|
| 11471 |
tg3_flag_clear(tp, USING_MSI); |
| 11472 |
tp->napi[0].irq_vec = tp->pdev->irq; |
| 11473 |
|
| 11474 |
err = tg3_request_irq(tp, 0); |
| 11475 |
if (err) |
| 11476 |
return err; |
| 11477 |
|
| 11478 |
/* Need to reset the chip because the MSI cycle may have terminated |
| 11479 |
* with Master Abort. |
| 11480 |
*/ |
| 11481 |
tg3_full_lock(tp, 1); |
| 11482 |
|
| 11483 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11484 |
err = tg3_init_hw(tp, true); |
| 11485 |
|
| 11486 |
tg3_full_unlock(tp); |
| 11487 |
|
| 11488 |
if (err) |
| 11489 |
free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
| 11490 |
|
| 11491 |
return err; |
| 11492 |
} |
| 11493 |
|
| 11494 |
static int tg3_request_firmware(struct tg3 *tp) |
| 11495 |
{ |
| 11496 |
const struct tg3_firmware_hdr *fw_hdr; |
| 11497 |
|
| 11498 |
if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { |
| 11499 |
netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
| 11500 |
tp->fw_needed); |
| 11501 |
return -ENOENT; |
| 11502 |
} |
| 11503 |
|
| 11504 |
fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
| 11505 |
|
| 11506 |
/* Firmware blob starts with version numbers, followed by |
| 11507 |
* start address and _full_ length including BSS sections |
| 11508 |
* (which must be longer than the actual data, of course |
| 11509 |
*/ |
| 11510 |
|
| 11511 |
tp->fw_len = be32_to_cpu(fw_hdr->len); /* includes bss */ |
| 11512 |
if (tp->fw_len < (tp->fw->size - TG3_FW_HDR_LEN)) { |
| 11513 |
netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
| 11514 |
tp->fw_len, tp->fw_needed); |
| 11515 |
release_firmware(tp->fw); |
| 11516 |
tp->fw = NULL; |
| 11517 |
return -EINVAL; |
| 11518 |
} |
| 11519 |
|
| 11520 |
/* We no longer need firmware; we have it. */ |
| 11521 |
tp->fw_needed = NULL; |
| 11522 |
return 0; |
| 11523 |
} |
| 11524 |
|
| 11525 |
static u32 tg3_irq_count(struct tg3 *tp) |
| 11526 |
{ |
| 11527 |
u32 irq_cnt = max(tp->rxq_cnt, tp->txq_cnt); |
| 11528 |
|
| 11529 |
if (irq_cnt > 1) { |
| 11530 |
/* We want as many rx rings enabled as there are cpus. |
| 11531 |
* In multiqueue MSI-X mode, the first MSI-X vector |
| 11532 |
* only deals with link interrupts, etc, so we add |
| 11533 |
* one to the number of vectors we are requesting. |
| 11534 |
*/ |
| 11535 |
irq_cnt = min_t(unsigned, irq_cnt + 1, tp->irq_max); |
| 11536 |
} |
| 11537 |
|
| 11538 |
return irq_cnt; |
| 11539 |
} |
| 11540 |
|
| 11541 |
static bool tg3_enable_msix(struct tg3 *tp) |
| 11542 |
{ |
| 11543 |
int i, rc; |
| 11544 |
struct msix_entry msix_ent[TG3_IRQ_MAX_VECS]; |
| 11545 |
|
| 11546 |
tp->txq_cnt = tp->txq_req; |
| 11547 |
tp->rxq_cnt = tp->rxq_req; |
| 11548 |
if (!tp->rxq_cnt) |
| 11549 |
tp->rxq_cnt = netif_get_num_default_rss_queues(); |
| 11550 |
if (tp->rxq_cnt > tp->rxq_max) |
| 11551 |
tp->rxq_cnt = tp->rxq_max; |
| 11552 |
|
| 11553 |
/* Disable multiple TX rings by default. Simple round-robin hardware |
| 11554 |
* scheduling of the TX rings can cause starvation of rings with |
| 11555 |
* small packets when other rings have TSO or jumbo packets. |
| 11556 |
*/ |
| 11557 |
if (!tp->txq_req) |
| 11558 |
tp->txq_cnt = 1; |
| 11559 |
|
| 11560 |
tp->irq_cnt = tg3_irq_count(tp); |
| 11561 |
|
| 11562 |
for (i = 0; i < tp->irq_max; i++) { |
| 11563 |
msix_ent[i].entry = i; |
| 11564 |
msix_ent[i].vector = 0; |
| 11565 |
} |
| 11566 |
|
| 11567 |
rc = pci_enable_msix_range(tp->pdev, msix_ent, 1, tp->irq_cnt); |
| 11568 |
if (rc < 0) { |
| 11569 |
return false; |
| 11570 |
} else if (rc < tp->irq_cnt) { |
| 11571 |
netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
| 11572 |
tp->irq_cnt, rc); |
| 11573 |
tp->irq_cnt = rc; |
| 11574 |
tp->rxq_cnt = max(rc - 1, 1); |
| 11575 |
if (tp->txq_cnt) |
| 11576 |
tp->txq_cnt = min(tp->rxq_cnt, tp->txq_max); |
| 11577 |
} |
| 11578 |
|
| 11579 |
for (i = 0; i < tp->irq_max; i++) |
| 11580 |
tp->napi[i].irq_vec = msix_ent[i].vector; |
| 11581 |
|
| 11582 |
if (netif_set_real_num_rx_queues(tp->dev, tp->rxq_cnt)) { |
| 11583 |
pci_disable_msix(tp->pdev); |
| 11584 |
return false; |
| 11585 |
} |
| 11586 |
|
| 11587 |
if (tp->irq_cnt == 1) |
| 11588 |
return true; |
| 11589 |
|
| 11590 |
tg3_flag_set(tp, ENABLE_RSS); |
| 11591 |
|
| 11592 |
if (tp->txq_cnt > 1) |
| 11593 |
tg3_flag_set(tp, ENABLE_TSS); |
| 11594 |
|
| 11595 |
netif_set_real_num_tx_queues(tp->dev, tp->txq_cnt); |
| 11596 |
|
| 11597 |
return true; |
| 11598 |
} |
| 11599 |
|
| 11600 |
static void tg3_ints_init(struct tg3 *tp) |
| 11601 |
{ |
| 11602 |
if ((tg3_flag(tp, SUPPORT_MSI) || tg3_flag(tp, SUPPORT_MSIX)) && |
| 11603 |
!tg3_flag(tp, TAGGED_STATUS)) { |
| 11604 |
/* All MSI supporting chips should support tagged |
| 11605 |
* status. Assert that this is the case. |
| 11606 |
*/ |
| 11607 |
netdev_warn(tp->dev, |
| 11608 |
"MSI without TAGGED_STATUS? Not using MSI\n"); |
| 11609 |
goto defcfg; |
| 11610 |
} |
| 11611 |
|
| 11612 |
if (tg3_flag(tp, SUPPORT_MSIX) && tg3_enable_msix(tp)) |
| 11613 |
tg3_flag_set(tp, USING_MSIX); |
| 11614 |
else if (tg3_flag(tp, SUPPORT_MSI) && pci_enable_msi(tp->pdev) == 0) |
| 11615 |
tg3_flag_set(tp, USING_MSI); |
| 11616 |
|
| 11617 |
if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
| 11618 |
u32 msi_mode = tr32(MSGINT_MODE); |
| 11619 |
if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) |
| 11620 |
msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
| 11621 |
if (!tg3_flag(tp, 1SHOT_MSI)) |
| 11622 |
msi_mode |= MSGINT_MODE_ONE_SHOT_DISABLE; |
| 11623 |
tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
| 11624 |
} |
| 11625 |
defcfg: |
| 11626 |
if (!tg3_flag(tp, USING_MSIX)) { |
| 11627 |
tp->irq_cnt = 1; |
| 11628 |
tp->napi[0].irq_vec = tp->pdev->irq; |
| 11629 |
} |
| 11630 |
|
| 11631 |
if (tp->irq_cnt == 1) { |
| 11632 |
tp->txq_cnt = 1; |
| 11633 |
tp->rxq_cnt = 1; |
| 11634 |
netif_set_real_num_tx_queues(tp->dev, 1); |
| 11635 |
netif_set_real_num_rx_queues(tp->dev, 1); |
| 11636 |
} |
| 11637 |
} |
| 11638 |
|
| 11639 |
static void tg3_ints_fini(struct tg3 *tp) |
| 11640 |
{ |
| 11641 |
if (tg3_flag(tp, USING_MSIX)) |
| 11642 |
pci_disable_msix(tp->pdev); |
| 11643 |
else if (tg3_flag(tp, USING_MSI)) |
| 11644 |
pci_disable_msi(tp->pdev); |
| 11645 |
tg3_flag_clear(tp, USING_MSI); |
| 11646 |
tg3_flag_clear(tp, USING_MSIX); |
| 11647 |
tg3_flag_clear(tp, ENABLE_RSS); |
| 11648 |
tg3_flag_clear(tp, ENABLE_TSS); |
| 11649 |
} |
| 11650 |
|
| 11651 |
static int tg3_start(struct tg3 *tp, bool reset_phy, bool test_irq, |
| 11652 |
bool init) |
| 11653 |
{ |
| 11654 |
struct net_device *dev = tp->dev; |
| 11655 |
int i, err; |
| 11656 |
|
| 11657 |
/* |
| 11658 |
* Setup interrupts first so we know how |
| 11659 |
* many NAPI resources to allocate |
| 11660 |
*/ |
| 11661 |
tg3_ints_init(tp); |
| 11662 |
|
| 11663 |
tg3_rss_check_indir_tbl(tp); |
| 11664 |
|
| 11665 |
/* The placement of this call is tied |
| 11666 |
* to the setup and use of Host TX descriptors. |
| 11667 |
*/ |
| 11668 |
err = tg3_alloc_consistent(tp); |
| 11669 |
if (err) |
| 11670 |
goto out_ints_fini; |
| 11671 |
|
| 11672 |
netdev_lock(dev); |
| 11673 |
tg3_napi_init(tp); |
| 11674 |
|
| 11675 |
tg3_napi_enable(tp); |
| 11676 |
netdev_unlock(dev); |
| 11677 |
|
| 11678 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 11679 |
err = tg3_request_irq(tp, i); |
| 11680 |
if (err) { |
| 11681 |
for (i--; i >= 0; i--) { |
| 11682 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 11683 |
|
| 11684 |
free_irq(tnapi->irq_vec, tnapi); |
| 11685 |
} |
| 11686 |
goto out_napi_fini; |
| 11687 |
} |
| 11688 |
} |
| 11689 |
|
| 11690 |
tg3_full_lock(tp, 0); |
| 11691 |
|
| 11692 |
if (init) |
| 11693 |
tg3_ape_driver_state_change(tp, RESET_KIND_INIT); |
| 11694 |
|
| 11695 |
err = tg3_init_hw(tp, reset_phy); |
| 11696 |
if (err) { |
| 11697 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11698 |
tg3_free_rings(tp); |
| 11699 |
} |
| 11700 |
|
| 11701 |
tg3_full_unlock(tp); |
| 11702 |
|
| 11703 |
if (err) |
| 11704 |
goto out_free_irq; |
| 11705 |
|
| 11706 |
if (test_irq && tg3_flag(tp, USING_MSI)) { |
| 11707 |
err = tg3_test_msi(tp); |
| 11708 |
|
| 11709 |
if (err) { |
| 11710 |
tg3_full_lock(tp, 0); |
| 11711 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11712 |
tg3_free_rings(tp); |
| 11713 |
tg3_full_unlock(tp); |
| 11714 |
|
| 11715 |
goto out_napi_fini; |
| 11716 |
} |
| 11717 |
|
| 11718 |
if (!tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
| 11719 |
u32 val = tr32(PCIE_TRANSACTION_CFG); |
| 11720 |
|
| 11721 |
tw32(PCIE_TRANSACTION_CFG, |
| 11722 |
val | PCIE_TRANS_CFG_1SHOT_MSI); |
| 11723 |
} |
| 11724 |
} |
| 11725 |
|
| 11726 |
tg3_phy_start(tp); |
| 11727 |
|
| 11728 |
tg3_hwmon_open(tp); |
| 11729 |
|
| 11730 |
tg3_full_lock(tp, 0); |
| 11731 |
|
| 11732 |
tg3_timer_start(tp); |
| 11733 |
tg3_flag_set(tp, INIT_COMPLETE); |
| 11734 |
tg3_enable_ints(tp); |
| 11735 |
|
| 11736 |
tg3_ptp_resume(tp); |
| 11737 |
|
| 11738 |
tg3_full_unlock(tp); |
| 11739 |
|
| 11740 |
netif_tx_start_all_queues(dev); |
| 11741 |
|
| 11742 |
/* |
| 11743 |
* Reset loopback feature if it was turned on while the device was down |
| 11744 |
* make sure that it's installed properly now. |
| 11745 |
*/ |
| 11746 |
if (dev->features & NETIF_F_LOOPBACK) |
| 11747 |
tg3_set_loopback(dev, dev->features); |
| 11748 |
|
| 11749 |
return 0; |
| 11750 |
|
| 11751 |
out_free_irq: |
| 11752 |
for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 11753 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 11754 |
free_irq(tnapi->irq_vec, tnapi); |
| 11755 |
} |
| 11756 |
|
| 11757 |
out_napi_fini: |
| 11758 |
tg3_napi_disable(tp); |
| 11759 |
tg3_napi_fini(tp); |
| 11760 |
tg3_free_consistent(tp); |
| 11761 |
|
| 11762 |
out_ints_fini: |
| 11763 |
tg3_ints_fini(tp); |
| 11764 |
|
| 11765 |
return err; |
| 11766 |
} |
| 11767 |
|
| 11768 |
static void tg3_stop(struct tg3 *tp) |
| 11769 |
{ |
| 11770 |
int i; |
| 11771 |
|
| 11772 |
tg3_reset_task_cancel(tp); |
| 11773 |
tg3_netif_stop(tp); |
| 11774 |
|
| 11775 |
tg3_timer_stop(tp); |
| 11776 |
|
| 11777 |
tg3_hwmon_close(tp); |
| 11778 |
|
| 11779 |
tg3_phy_stop(tp); |
| 11780 |
|
| 11781 |
tg3_full_lock(tp, 1); |
| 11782 |
|
| 11783 |
tg3_disable_ints(tp); |
| 11784 |
|
| 11785 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 11786 |
tg3_free_rings(tp); |
| 11787 |
tg3_flag_clear(tp, INIT_COMPLETE); |
| 11788 |
|
| 11789 |
tg3_full_unlock(tp); |
| 11790 |
|
| 11791 |
for (i = tp->irq_cnt - 1; i >= 0; i--) { |
| 11792 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 11793 |
free_irq(tnapi->irq_vec, tnapi); |
| 11794 |
} |
| 11795 |
|
| 11796 |
tg3_ints_fini(tp); |
| 11797 |
|
| 11798 |
tg3_napi_fini(tp); |
| 11799 |
|
| 11800 |
tg3_free_consistent(tp); |
| 11801 |
} |
| 11802 |
|
| 11803 |
static int tg3_open(struct net_device *dev) |
| 11804 |
{ |
| 11805 |
struct tg3 *tp = netdev_priv(dev); |
| 11806 |
int err; |
| 11807 |
|
| 11808 |
if (tp->pcierr_recovery) { |
| 11809 |
netdev_err(dev, "Failed to open device. PCI error recovery " |
| 11810 |
"in progress\n"); |
| 11811 |
return -EAGAIN; |
| 11812 |
} |
| 11813 |
|
| 11814 |
if (tp->fw_needed) { |
| 11815 |
err = tg3_request_firmware(tp); |
| 11816 |
if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
| 11817 |
if (err) { |
| 11818 |
netdev_warn(tp->dev, "EEE capability disabled\n"); |
| 11819 |
tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; |
| 11820 |
} else if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) { |
| 11821 |
netdev_warn(tp->dev, "EEE capability restored\n"); |
| 11822 |
tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 11823 |
} |
| 11824 |
} else if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0) { |
| 11825 |
if (err) |
| 11826 |
return err; |
| 11827 |
} else if (err) { |
| 11828 |
netdev_warn(tp->dev, "TSO capability disabled\n"); |
| 11829 |
tg3_flag_clear(tp, TSO_CAPABLE); |
| 11830 |
} else if (!tg3_flag(tp, TSO_CAPABLE)) { |
| 11831 |
netdev_notice(tp->dev, "TSO capability restored\n"); |
| 11832 |
tg3_flag_set(tp, TSO_CAPABLE); |
| 11833 |
} |
| 11834 |
} |
| 11835 |
|
| 11836 |
tg3_carrier_off(tp); |
| 11837 |
|
| 11838 |
err = tg3_power_up(tp); |
| 11839 |
if (err) |
| 11840 |
return err; |
| 11841 |
|
| 11842 |
tg3_full_lock(tp, 0); |
| 11843 |
|
| 11844 |
tg3_disable_ints(tp); |
| 11845 |
tg3_flag_clear(tp, INIT_COMPLETE); |
| 11846 |
|
| 11847 |
tg3_full_unlock(tp); |
| 11848 |
|
| 11849 |
err = tg3_start(tp, |
| 11850 |
!(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN), |
| 11851 |
true, true); |
| 11852 |
if (err) { |
| 11853 |
tg3_frob_aux_power(tp, false); |
| 11854 |
pci_set_power_state(tp->pdev, PCI_D3hot); |
| 11855 |
} |
| 11856 |
|
| 11857 |
return err; |
| 11858 |
} |
| 11859 |
|
| 11860 |
static int tg3_close(struct net_device *dev) |
| 11861 |
{ |
| 11862 |
struct tg3 *tp = netdev_priv(dev); |
| 11863 |
|
| 11864 |
if (tp->pcierr_recovery) { |
| 11865 |
netdev_err(dev, "Failed to close device. PCI error recovery " |
| 11866 |
"in progress\n"); |
| 11867 |
return -EAGAIN; |
| 11868 |
} |
| 11869 |
|
| 11870 |
tg3_stop(tp); |
| 11871 |
|
| 11872 |
if (pci_device_is_present(tp->pdev)) { |
| 11873 |
tg3_power_down_prepare(tp); |
| 11874 |
|
| 11875 |
tg3_carrier_off(tp); |
| 11876 |
} |
| 11877 |
return 0; |
| 11878 |
} |
| 11879 |
|
| 11880 |
static inline u64 get_stat64(tg3_stat64_t *val) |
| 11881 |
{ |
| 11882 |
return ((u64)val->high << 32) | ((u64)val->low); |
| 11883 |
} |
| 11884 |
|
| 11885 |
static u64 tg3_calc_crc_errors(struct tg3 *tp) |
| 11886 |
{ |
| 11887 |
struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 11888 |
|
| 11889 |
if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 11890 |
(tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 11891 |
tg3_asic_rev(tp) == ASIC_REV_5701)) { |
| 11892 |
u32 val; |
| 11893 |
|
| 11894 |
if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
| 11895 |
tg3_writephy(tp, MII_TG3_TEST1, |
| 11896 |
val | MII_TG3_TEST1_CRC_EN); |
| 11897 |
tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
| 11898 |
} else |
| 11899 |
val = 0; |
| 11900 |
|
| 11901 |
tp->phy_crc_errors += val; |
| 11902 |
|
| 11903 |
return tp->phy_crc_errors; |
| 11904 |
} |
| 11905 |
|
| 11906 |
return get_stat64(&hw_stats->rx_fcs_errors); |
| 11907 |
} |
| 11908 |
|
| 11909 |
#define ESTAT_ADD(member) \ |
| 11910 |
estats->member = old_estats->member + \ |
| 11911 |
get_stat64(&hw_stats->member) |
| 11912 |
|
| 11913 |
static void tg3_get_estats(struct tg3 *tp, struct tg3_ethtool_stats *estats) |
| 11914 |
{ |
| 11915 |
struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
| 11916 |
struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 11917 |
|
| 11918 |
ESTAT_ADD(rx_octets); |
| 11919 |
ESTAT_ADD(rx_fragments); |
| 11920 |
ESTAT_ADD(rx_ucast_packets); |
| 11921 |
ESTAT_ADD(rx_mcast_packets); |
| 11922 |
ESTAT_ADD(rx_bcast_packets); |
| 11923 |
ESTAT_ADD(rx_fcs_errors); |
| 11924 |
ESTAT_ADD(rx_align_errors); |
| 11925 |
ESTAT_ADD(rx_xon_pause_rcvd); |
| 11926 |
ESTAT_ADD(rx_xoff_pause_rcvd); |
| 11927 |
ESTAT_ADD(rx_mac_ctrl_rcvd); |
| 11928 |
ESTAT_ADD(rx_xoff_entered); |
| 11929 |
ESTAT_ADD(rx_frame_too_long_errors); |
| 11930 |
ESTAT_ADD(rx_jabbers); |
| 11931 |
ESTAT_ADD(rx_undersize_packets); |
| 11932 |
ESTAT_ADD(rx_in_length_errors); |
| 11933 |
ESTAT_ADD(rx_out_length_errors); |
| 11934 |
ESTAT_ADD(rx_64_or_less_octet_packets); |
| 11935 |
ESTAT_ADD(rx_65_to_127_octet_packets); |
| 11936 |
ESTAT_ADD(rx_128_to_255_octet_packets); |
| 11937 |
ESTAT_ADD(rx_256_to_511_octet_packets); |
| 11938 |
ESTAT_ADD(rx_512_to_1023_octet_packets); |
| 11939 |
ESTAT_ADD(rx_1024_to_1522_octet_packets); |
| 11940 |
ESTAT_ADD(rx_1523_to_2047_octet_packets); |
| 11941 |
ESTAT_ADD(rx_2048_to_4095_octet_packets); |
| 11942 |
ESTAT_ADD(rx_4096_to_8191_octet_packets); |
| 11943 |
ESTAT_ADD(rx_8192_to_9022_octet_packets); |
| 11944 |
|
| 11945 |
ESTAT_ADD(tx_octets); |
| 11946 |
ESTAT_ADD(tx_collisions); |
| 11947 |
ESTAT_ADD(tx_xon_sent); |
| 11948 |
ESTAT_ADD(tx_xoff_sent); |
| 11949 |
ESTAT_ADD(tx_flow_control); |
| 11950 |
ESTAT_ADD(tx_mac_errors); |
| 11951 |
ESTAT_ADD(tx_single_collisions); |
| 11952 |
ESTAT_ADD(tx_mult_collisions); |
| 11953 |
ESTAT_ADD(tx_deferred); |
| 11954 |
ESTAT_ADD(tx_excessive_collisions); |
| 11955 |
ESTAT_ADD(tx_late_collisions); |
| 11956 |
ESTAT_ADD(tx_collide_2times); |
| 11957 |
ESTAT_ADD(tx_collide_3times); |
| 11958 |
ESTAT_ADD(tx_collide_4times); |
| 11959 |
ESTAT_ADD(tx_collide_5times); |
| 11960 |
ESTAT_ADD(tx_collide_6times); |
| 11961 |
ESTAT_ADD(tx_collide_7times); |
| 11962 |
ESTAT_ADD(tx_collide_8times); |
| 11963 |
ESTAT_ADD(tx_collide_9times); |
| 11964 |
ESTAT_ADD(tx_collide_10times); |
| 11965 |
ESTAT_ADD(tx_collide_11times); |
| 11966 |
ESTAT_ADD(tx_collide_12times); |
| 11967 |
ESTAT_ADD(tx_collide_13times); |
| 11968 |
ESTAT_ADD(tx_collide_14times); |
| 11969 |
ESTAT_ADD(tx_collide_15times); |
| 11970 |
ESTAT_ADD(tx_ucast_packets); |
| 11971 |
ESTAT_ADD(tx_mcast_packets); |
| 11972 |
ESTAT_ADD(tx_bcast_packets); |
| 11973 |
ESTAT_ADD(tx_carrier_sense_errors); |
| 11974 |
ESTAT_ADD(tx_discards); |
| 11975 |
ESTAT_ADD(tx_errors); |
| 11976 |
|
| 11977 |
ESTAT_ADD(dma_writeq_full); |
| 11978 |
ESTAT_ADD(dma_write_prioq_full); |
| 11979 |
ESTAT_ADD(rxbds_empty); |
| 11980 |
ESTAT_ADD(rx_discards); |
| 11981 |
ESTAT_ADD(rx_errors); |
| 11982 |
ESTAT_ADD(rx_threshold_hit); |
| 11983 |
|
| 11984 |
ESTAT_ADD(dma_readq_full); |
| 11985 |
ESTAT_ADD(dma_read_prioq_full); |
| 11986 |
ESTAT_ADD(tx_comp_queue_full); |
| 11987 |
|
| 11988 |
ESTAT_ADD(ring_set_send_prod_index); |
| 11989 |
ESTAT_ADD(ring_status_update); |
| 11990 |
ESTAT_ADD(nic_irqs); |
| 11991 |
ESTAT_ADD(nic_avoided_irqs); |
| 11992 |
ESTAT_ADD(nic_tx_threshold_hit); |
| 11993 |
|
| 11994 |
ESTAT_ADD(mbuf_lwm_thresh_hit); |
| 11995 |
} |
| 11996 |
|
| 11997 |
static void tg3_get_nstats(struct tg3 *tp, struct rtnl_link_stats64 *stats) |
| 11998 |
{ |
| 11999 |
struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
| 12000 |
struct tg3_hw_stats *hw_stats = tp->hw_stats; |
| 12001 |
unsigned long rx_dropped; |
| 12002 |
unsigned long tx_dropped; |
| 12003 |
int i; |
| 12004 |
|
| 12005 |
stats->rx_packets = old_stats->rx_packets + |
| 12006 |
get_stat64(&hw_stats->rx_ucast_packets) + |
| 12007 |
get_stat64(&hw_stats->rx_mcast_packets) + |
| 12008 |
get_stat64(&hw_stats->rx_bcast_packets); |
| 12009 |
|
| 12010 |
stats->tx_packets = old_stats->tx_packets + |
| 12011 |
get_stat64(&hw_stats->tx_ucast_packets) + |
| 12012 |
get_stat64(&hw_stats->tx_mcast_packets) + |
| 12013 |
get_stat64(&hw_stats->tx_bcast_packets); |
| 12014 |
|
| 12015 |
stats->rx_bytes = old_stats->rx_bytes + |
| 12016 |
get_stat64(&hw_stats->rx_octets); |
| 12017 |
stats->tx_bytes = old_stats->tx_bytes + |
| 12018 |
get_stat64(&hw_stats->tx_octets); |
| 12019 |
|
| 12020 |
stats->rx_errors = old_stats->rx_errors + |
| 12021 |
get_stat64(&hw_stats->rx_errors); |
| 12022 |
stats->tx_errors = old_stats->tx_errors + |
| 12023 |
get_stat64(&hw_stats->tx_errors) + |
| 12024 |
get_stat64(&hw_stats->tx_mac_errors) + |
| 12025 |
get_stat64(&hw_stats->tx_carrier_sense_errors) + |
| 12026 |
get_stat64(&hw_stats->tx_discards); |
| 12027 |
|
| 12028 |
stats->multicast = old_stats->multicast + |
| 12029 |
get_stat64(&hw_stats->rx_mcast_packets); |
| 12030 |
stats->collisions = old_stats->collisions + |
| 12031 |
get_stat64(&hw_stats->tx_collisions); |
| 12032 |
|
| 12033 |
stats->rx_length_errors = old_stats->rx_length_errors + |
| 12034 |
get_stat64(&hw_stats->rx_frame_too_long_errors) + |
| 12035 |
get_stat64(&hw_stats->rx_undersize_packets); |
| 12036 |
|
| 12037 |
stats->rx_frame_errors = old_stats->rx_frame_errors + |
| 12038 |
get_stat64(&hw_stats->rx_align_errors); |
| 12039 |
stats->tx_aborted_errors = old_stats->tx_aborted_errors + |
| 12040 |
get_stat64(&hw_stats->tx_discards); |
| 12041 |
stats->tx_carrier_errors = old_stats->tx_carrier_errors + |
| 12042 |
get_stat64(&hw_stats->tx_carrier_sense_errors); |
| 12043 |
|
| 12044 |
stats->rx_crc_errors = old_stats->rx_crc_errors + |
| 12045 |
tg3_calc_crc_errors(tp); |
| 12046 |
|
| 12047 |
stats->rx_missed_errors = old_stats->rx_missed_errors + |
| 12048 |
get_stat64(&hw_stats->rx_discards); |
| 12049 |
|
| 12050 |
/* Aggregate per-queue counters. The per-queue counters are updated |
| 12051 |
* by a single writer, race-free. The result computed by this loop |
| 12052 |
* might not be 100% accurate (counters can be updated in the middle of |
| 12053 |
* the loop) but the next tg3_get_nstats() will recompute the current |
| 12054 |
* value so it is acceptable. |
| 12055 |
* |
| 12056 |
* Note that these counters wrap around at 4G on 32bit machines. |
| 12057 |
*/ |
| 12058 |
rx_dropped = (unsigned long)(old_stats->rx_dropped); |
| 12059 |
tx_dropped = (unsigned long)(old_stats->tx_dropped); |
| 12060 |
|
| 12061 |
for (i = 0; i < tp->irq_cnt; i++) { |
| 12062 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 12063 |
|
| 12064 |
rx_dropped += tnapi->rx_dropped; |
| 12065 |
tx_dropped += tnapi->tx_dropped; |
| 12066 |
} |
| 12067 |
|
| 12068 |
stats->rx_dropped = rx_dropped; |
| 12069 |
stats->tx_dropped = tx_dropped; |
| 12070 |
} |
| 12071 |
|
| 12072 |
static int tg3_get_regs_len(struct net_device *dev) |
| 12073 |
{ |
| 12074 |
return TG3_REG_BLK_SIZE; |
| 12075 |
} |
| 12076 |
|
| 12077 |
static void tg3_get_regs(struct net_device *dev, |
| 12078 |
struct ethtool_regs *regs, void *_p) |
| 12079 |
{ |
| 12080 |
struct tg3 *tp = netdev_priv(dev); |
| 12081 |
|
| 12082 |
regs->version = 0; |
| 12083 |
|
| 12084 |
memset(_p, 0, TG3_REG_BLK_SIZE); |
| 12085 |
|
| 12086 |
if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
| 12087 |
return; |
| 12088 |
|
| 12089 |
tg3_full_lock(tp, 0); |
| 12090 |
|
| 12091 |
tg3_dump_legacy_regs(tp, (u32 *)_p); |
| 12092 |
|
| 12093 |
tg3_full_unlock(tp); |
| 12094 |
} |
| 12095 |
|
| 12096 |
static int tg3_get_eeprom_len(struct net_device *dev) |
| 12097 |
{ |
| 12098 |
struct tg3 *tp = netdev_priv(dev); |
| 12099 |
|
| 12100 |
return tp->nvram_size; |
| 12101 |
} |
| 12102 |
|
| 12103 |
static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 12104 |
{ |
| 12105 |
struct tg3 *tp = netdev_priv(dev); |
| 12106 |
int ret, cpmu_restore = 0; |
| 12107 |
u8 *pd; |
| 12108 |
u32 i, offset, len, b_offset, b_count, cpmu_val = 0; |
| 12109 |
__be32 val; |
| 12110 |
|
| 12111 |
if (tg3_flag(tp, NO_NVRAM)) |
| 12112 |
return -EINVAL; |
| 12113 |
|
| 12114 |
offset = eeprom->offset; |
| 12115 |
len = eeprom->len; |
| 12116 |
eeprom->len = 0; |
| 12117 |
|
| 12118 |
eeprom->magic = TG3_EEPROM_MAGIC; |
| 12119 |
|
| 12120 |
/* Override clock, link aware and link idle modes */ |
| 12121 |
if (tg3_flag(tp, CPMU_PRESENT)) { |
| 12122 |
cpmu_val = tr32(TG3_CPMU_CTRL); |
| 12123 |
if (cpmu_val & (CPMU_CTRL_LINK_AWARE_MODE | |
| 12124 |
CPMU_CTRL_LINK_IDLE_MODE)) { |
| 12125 |
tw32(TG3_CPMU_CTRL, cpmu_val & |
| 12126 |
~(CPMU_CTRL_LINK_AWARE_MODE | |
| 12127 |
CPMU_CTRL_LINK_IDLE_MODE)); |
| 12128 |
cpmu_restore = 1; |
| 12129 |
} |
| 12130 |
} |
| 12131 |
tg3_override_clk(tp); |
| 12132 |
|
| 12133 |
if (offset & 3) { |
| 12134 |
/* adjustments to start on required 4 byte boundary */ |
| 12135 |
b_offset = offset & 3; |
| 12136 |
b_count = 4 - b_offset; |
| 12137 |
if (b_count > len) { |
| 12138 |
/* i.e. offset=1 len=2 */ |
| 12139 |
b_count = len; |
| 12140 |
} |
| 12141 |
ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
| 12142 |
if (ret) |
| 12143 |
goto eeprom_done; |
| 12144 |
memcpy(data, ((char *)&val) + b_offset, b_count); |
| 12145 |
len -= b_count; |
| 12146 |
offset += b_count; |
| 12147 |
eeprom->len += b_count; |
| 12148 |
} |
| 12149 |
|
| 12150 |
/* read bytes up to the last 4 byte boundary */ |
| 12151 |
pd = &data[eeprom->len]; |
| 12152 |
for (i = 0; i < (len - (len & 3)); i += 4) { |
| 12153 |
ret = tg3_nvram_read_be32(tp, offset + i, &val); |
| 12154 |
if (ret) { |
| 12155 |
if (i) |
| 12156 |
i -= 4; |
| 12157 |
eeprom->len += i; |
| 12158 |
goto eeprom_done; |
| 12159 |
} |
| 12160 |
memcpy(pd + i, &val, 4); |
| 12161 |
if (need_resched()) { |
| 12162 |
if (signal_pending(current)) { |
| 12163 |
eeprom->len += i; |
| 12164 |
ret = -EINTR; |
| 12165 |
goto eeprom_done; |
| 12166 |
} |
| 12167 |
cond_resched(); |
| 12168 |
} |
| 12169 |
} |
| 12170 |
eeprom->len += i; |
| 12171 |
|
| 12172 |
if (len & 3) { |
| 12173 |
/* read last bytes not ending on 4 byte boundary */ |
| 12174 |
pd = &data[eeprom->len]; |
| 12175 |
b_count = len & 3; |
| 12176 |
b_offset = offset + len - b_count; |
| 12177 |
ret = tg3_nvram_read_be32(tp, b_offset, &val); |
| 12178 |
if (ret) |
| 12179 |
goto eeprom_done; |
| 12180 |
memcpy(pd, &val, b_count); |
| 12181 |
eeprom->len += b_count; |
| 12182 |
} |
| 12183 |
ret = 0; |
| 12184 |
|
| 12185 |
eeprom_done: |
| 12186 |
/* Restore clock, link aware and link idle modes */ |
| 12187 |
tg3_restore_clk(tp); |
| 12188 |
if (cpmu_restore) |
| 12189 |
tw32(TG3_CPMU_CTRL, cpmu_val); |
| 12190 |
|
| 12191 |
return ret; |
| 12192 |
} |
| 12193 |
|
| 12194 |
static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
| 12195 |
{ |
| 12196 |
struct tg3 *tp = netdev_priv(dev); |
| 12197 |
int ret; |
| 12198 |
u32 offset, len, b_offset, odd_len; |
| 12199 |
u8 *buf; |
| 12200 |
__be32 start = 0, end; |
| 12201 |
|
| 12202 |
if (tg3_flag(tp, NO_NVRAM) || |
| 12203 |
eeprom->magic != TG3_EEPROM_MAGIC) |
| 12204 |
return -EINVAL; |
| 12205 |
|
| 12206 |
offset = eeprom->offset; |
| 12207 |
len = eeprom->len; |
| 12208 |
|
| 12209 |
if ((b_offset = (offset & 3))) { |
| 12210 |
/* adjustments to start on required 4 byte boundary */ |
| 12211 |
ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
| 12212 |
if (ret) |
| 12213 |
return ret; |
| 12214 |
len += b_offset; |
| 12215 |
offset &= ~3; |
| 12216 |
if (len < 4) |
| 12217 |
len = 4; |
| 12218 |
} |
| 12219 |
|
| 12220 |
odd_len = 0; |
| 12221 |
if (len & 3) { |
| 12222 |
/* adjustments to end on required 4 byte boundary */ |
| 12223 |
odd_len = 1; |
| 12224 |
len = (len + 3) & ~3; |
| 12225 |
ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
| 12226 |
if (ret) |
| 12227 |
return ret; |
| 12228 |
} |
| 12229 |
|
| 12230 |
buf = data; |
| 12231 |
if (b_offset || odd_len) { |
| 12232 |
buf = kmalloc(len, GFP_KERNEL); |
| 12233 |
if (!buf) |
| 12234 |
return -ENOMEM; |
| 12235 |
if (b_offset) |
| 12236 |
memcpy(buf, &start, 4); |
| 12237 |
if (odd_len) |
| 12238 |
memcpy(buf+len-4, &end, 4); |
| 12239 |
memcpy(buf + b_offset, data, eeprom->len); |
| 12240 |
} |
| 12241 |
|
| 12242 |
ret = tg3_nvram_write_block(tp, offset, len, buf); |
| 12243 |
|
| 12244 |
if (buf != data) |
| 12245 |
kfree(buf); |
| 12246 |
|
| 12247 |
return ret; |
| 12248 |
} |
| 12249 |
|
| 12250 |
static int tg3_get_link_ksettings(struct net_device *dev, |
| 12251 |
struct ethtool_link_ksettings *cmd) |
| 12252 |
{ |
| 12253 |
struct tg3 *tp = netdev_priv(dev); |
| 12254 |
u32 supported, advertising; |
| 12255 |
|
| 12256 |
if (tg3_flag(tp, USE_PHYLIB)) { |
| 12257 |
struct phy_device *phydev; |
| 12258 |
if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
| 12259 |
return -EAGAIN; |
| 12260 |
phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr); |
| 12261 |
phy_ethtool_ksettings_get(phydev, cmd); |
| 12262 |
|
| 12263 |
return 0; |
| 12264 |
} |
| 12265 |
|
| 12266 |
supported = (SUPPORTED_Autoneg); |
| 12267 |
|
| 12268 |
if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
| 12269 |
supported |= (SUPPORTED_1000baseT_Half | |
| 12270 |
SUPPORTED_1000baseT_Full); |
| 12271 |
|
| 12272 |
if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 12273 |
supported |= (SUPPORTED_100baseT_Half | |
| 12274 |
SUPPORTED_100baseT_Full | |
| 12275 |
SUPPORTED_10baseT_Half | |
| 12276 |
SUPPORTED_10baseT_Full | |
| 12277 |
SUPPORTED_TP); |
| 12278 |
cmd->base.port = PORT_TP; |
| 12279 |
} else { |
| 12280 |
supported |= SUPPORTED_FIBRE; |
| 12281 |
cmd->base.port = PORT_FIBRE; |
| 12282 |
} |
| 12283 |
ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 12284 |
supported); |
| 12285 |
|
| 12286 |
advertising = tp->link_config.advertising; |
| 12287 |
if (tg3_flag(tp, PAUSE_AUTONEG)) { |
| 12288 |
if (tp->link_config.flowctrl & FLOW_CTRL_RX) { |
| 12289 |
if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 12290 |
advertising |= ADVERTISED_Pause; |
| 12291 |
} else { |
| 12292 |
advertising |= ADVERTISED_Pause | |
| 12293 |
ADVERTISED_Asym_Pause; |
| 12294 |
} |
| 12295 |
} else if (tp->link_config.flowctrl & FLOW_CTRL_TX) { |
| 12296 |
advertising |= ADVERTISED_Asym_Pause; |
| 12297 |
} |
| 12298 |
} |
| 12299 |
ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 12300 |
advertising); |
| 12301 |
|
| 12302 |
if (netif_running(dev) && netif_carrier_ok(dev)) { |
| 12303 |
cmd->base.speed = tp->link_config.active_speed; |
| 12304 |
cmd->base.duplex = tp->link_config.active_duplex; |
| 12305 |
ethtool_convert_legacy_u32_to_link_mode( |
| 12306 |
cmd->link_modes.lp_advertising, |
| 12307 |
tp->link_config.rmt_adv); |
| 12308 |
|
| 12309 |
if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
| 12310 |
if (tp->phy_flags & TG3_PHYFLG_MDIX_STATE) |
| 12311 |
cmd->base.eth_tp_mdix = ETH_TP_MDI_X; |
| 12312 |
else |
| 12313 |
cmd->base.eth_tp_mdix = ETH_TP_MDI; |
| 12314 |
} |
| 12315 |
} else { |
| 12316 |
cmd->base.speed = SPEED_UNKNOWN; |
| 12317 |
cmd->base.duplex = DUPLEX_UNKNOWN; |
| 12318 |
cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID; |
| 12319 |
} |
| 12320 |
cmd->base.phy_address = tp->phy_addr; |
| 12321 |
cmd->base.autoneg = tp->link_config.autoneg; |
| 12322 |
return 0; |
| 12323 |
} |
| 12324 |
|
| 12325 |
static int tg3_set_link_ksettings(struct net_device *dev, |
| 12326 |
const struct ethtool_link_ksettings *cmd) |
| 12327 |
{ |
| 12328 |
struct tg3 *tp = netdev_priv(dev); |
| 12329 |
u32 speed = cmd->base.speed; |
| 12330 |
u32 advertising; |
| 12331 |
|
| 12332 |
if (tg3_flag(tp, USE_PHYLIB)) { |
| 12333 |
struct phy_device *phydev; |
| 12334 |
if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
| 12335 |
return -EAGAIN; |
| 12336 |
phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr); |
| 12337 |
return phy_ethtool_ksettings_set(phydev, cmd); |
| 12338 |
} |
| 12339 |
|
| 12340 |
if (cmd->base.autoneg != AUTONEG_ENABLE && |
| 12341 |
cmd->base.autoneg != AUTONEG_DISABLE) |
| 12342 |
return -EINVAL; |
| 12343 |
|
| 12344 |
if (cmd->base.autoneg == AUTONEG_DISABLE && |
| 12345 |
cmd->base.duplex != DUPLEX_FULL && |
| 12346 |
cmd->base.duplex != DUPLEX_HALF) |
| 12347 |
return -EINVAL; |
| 12348 |
|
| 12349 |
ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 12350 |
cmd->link_modes.advertising); |
| 12351 |
|
| 12352 |
if (cmd->base.autoneg == AUTONEG_ENABLE) { |
| 12353 |
u32 mask = ADVERTISED_Autoneg | |
| 12354 |
ADVERTISED_Pause | |
| 12355 |
ADVERTISED_Asym_Pause; |
| 12356 |
|
| 12357 |
if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
| 12358 |
mask |= ADVERTISED_1000baseT_Half | |
| 12359 |
ADVERTISED_1000baseT_Full; |
| 12360 |
|
| 12361 |
if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 12362 |
mask |= ADVERTISED_100baseT_Half | |
| 12363 |
ADVERTISED_100baseT_Full | |
| 12364 |
ADVERTISED_10baseT_Half | |
| 12365 |
ADVERTISED_10baseT_Full | |
| 12366 |
ADVERTISED_TP; |
| 12367 |
else |
| 12368 |
mask |= ADVERTISED_FIBRE; |
| 12369 |
|
| 12370 |
if (advertising & ~mask) |
| 12371 |
return -EINVAL; |
| 12372 |
|
| 12373 |
mask &= (ADVERTISED_1000baseT_Half | |
| 12374 |
ADVERTISED_1000baseT_Full | |
| 12375 |
ADVERTISED_100baseT_Half | |
| 12376 |
ADVERTISED_100baseT_Full | |
| 12377 |
ADVERTISED_10baseT_Half | |
| 12378 |
ADVERTISED_10baseT_Full); |
| 12379 |
|
| 12380 |
advertising &= mask; |
| 12381 |
} else { |
| 12382 |
if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
| 12383 |
if (speed != SPEED_1000) |
| 12384 |
return -EINVAL; |
| 12385 |
|
| 12386 |
if (cmd->base.duplex != DUPLEX_FULL) |
| 12387 |
return -EINVAL; |
| 12388 |
} else { |
| 12389 |
if (speed != SPEED_100 && |
| 12390 |
speed != SPEED_10) |
| 12391 |
return -EINVAL; |
| 12392 |
} |
| 12393 |
} |
| 12394 |
|
| 12395 |
tg3_full_lock(tp, 0); |
| 12396 |
|
| 12397 |
tp->link_config.autoneg = cmd->base.autoneg; |
| 12398 |
if (cmd->base.autoneg == AUTONEG_ENABLE) { |
| 12399 |
tp->link_config.advertising = (advertising | |
| 12400 |
ADVERTISED_Autoneg); |
| 12401 |
tp->link_config.speed = SPEED_UNKNOWN; |
| 12402 |
tp->link_config.duplex = DUPLEX_UNKNOWN; |
| 12403 |
} else { |
| 12404 |
tp->link_config.advertising = 0; |
| 12405 |
tp->link_config.speed = speed; |
| 12406 |
tp->link_config.duplex = cmd->base.duplex; |
| 12407 |
} |
| 12408 |
|
| 12409 |
tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; |
| 12410 |
|
| 12411 |
tg3_warn_mgmt_link_flap(tp); |
| 12412 |
|
| 12413 |
if (netif_running(dev)) |
| 12414 |
tg3_setup_phy(tp, true); |
| 12415 |
|
| 12416 |
tg3_full_unlock(tp); |
| 12417 |
|
| 12418 |
return 0; |
| 12419 |
} |
| 12420 |
|
| 12421 |
static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 12422 |
{ |
| 12423 |
struct tg3 *tp = netdev_priv(dev); |
| 12424 |
|
| 12425 |
strscpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); |
| 12426 |
strscpy(info->fw_version, tp->fw_ver, sizeof(info->fw_version)); |
| 12427 |
strscpy(info->bus_info, pci_name(tp->pdev), sizeof(info->bus_info)); |
| 12428 |
} |
| 12429 |
|
| 12430 |
static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 12431 |
{ |
| 12432 |
struct tg3 *tp = netdev_priv(dev); |
| 12433 |
|
| 12434 |
if (tg3_flag(tp, WOL_CAP) && device_can_wakeup(&tp->pdev->dev)) |
| 12435 |
wol->supported = WAKE_MAGIC; |
| 12436 |
else |
| 12437 |
wol->supported = 0; |
| 12438 |
wol->wolopts = 0; |
| 12439 |
if (tg3_flag(tp, WOL_ENABLE) && device_can_wakeup(&tp->pdev->dev)) |
| 12440 |
wol->wolopts = WAKE_MAGIC; |
| 12441 |
memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 12442 |
} |
| 12443 |
|
| 12444 |
static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 12445 |
{ |
| 12446 |
struct tg3 *tp = netdev_priv(dev); |
| 12447 |
struct device *dp = &tp->pdev->dev; |
| 12448 |
|
| 12449 |
if (wol->wolopts & ~WAKE_MAGIC) |
| 12450 |
return -EINVAL; |
| 12451 |
if ((wol->wolopts & WAKE_MAGIC) && |
| 12452 |
!(tg3_flag(tp, WOL_CAP) && device_can_wakeup(dp))) |
| 12453 |
return -EINVAL; |
| 12454 |
|
| 12455 |
device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
| 12456 |
|
| 12457 |
if (device_may_wakeup(dp)) |
| 12458 |
tg3_flag_set(tp, WOL_ENABLE); |
| 12459 |
else |
| 12460 |
tg3_flag_clear(tp, WOL_ENABLE); |
| 12461 |
|
| 12462 |
return 0; |
| 12463 |
} |
| 12464 |
|
| 12465 |
static u32 tg3_get_msglevel(struct net_device *dev) |
| 12466 |
{ |
| 12467 |
struct tg3 *tp = netdev_priv(dev); |
| 12468 |
return tp->msg_enable; |
| 12469 |
} |
| 12470 |
|
| 12471 |
static void tg3_set_msglevel(struct net_device *dev, u32 value) |
| 12472 |
{ |
| 12473 |
struct tg3 *tp = netdev_priv(dev); |
| 12474 |
tp->msg_enable = value; |
| 12475 |
} |
| 12476 |
|
| 12477 |
static int tg3_nway_reset(struct net_device *dev) |
| 12478 |
{ |
| 12479 |
struct tg3 *tp = netdev_priv(dev); |
| 12480 |
int r; |
| 12481 |
|
| 12482 |
if (!netif_running(dev)) |
| 12483 |
return -EAGAIN; |
| 12484 |
|
| 12485 |
if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
| 12486 |
return -EINVAL; |
| 12487 |
|
| 12488 |
tg3_warn_mgmt_link_flap(tp); |
| 12489 |
|
| 12490 |
if (tg3_flag(tp, USE_PHYLIB)) { |
| 12491 |
if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
| 12492 |
return -EAGAIN; |
| 12493 |
r = phy_start_aneg(mdiobus_get_phy(tp->mdio_bus, tp->phy_addr)); |
| 12494 |
} else { |
| 12495 |
u32 bmcr; |
| 12496 |
|
| 12497 |
spin_lock_bh(&tp->lock); |
| 12498 |
r = -EINVAL; |
| 12499 |
tg3_readphy(tp, MII_BMCR, &bmcr); |
| 12500 |
if (!tg3_readphy(tp, MII_BMCR, &bmcr) && |
| 12501 |
((bmcr & BMCR_ANENABLE) || |
| 12502 |
(tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
| 12503 |
tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
| 12504 |
BMCR_ANENABLE); |
| 12505 |
r = 0; |
| 12506 |
} |
| 12507 |
spin_unlock_bh(&tp->lock); |
| 12508 |
} |
| 12509 |
|
| 12510 |
return r; |
| 12511 |
} |
| 12512 |
|
| 12513 |
static void tg3_get_ringparam(struct net_device *dev, |
| 12514 |
struct ethtool_ringparam *ering, |
| 12515 |
struct kernel_ethtool_ringparam *kernel_ering, |
| 12516 |
struct netlink_ext_ack *extack) |
| 12517 |
{ |
| 12518 |
struct tg3 *tp = netdev_priv(dev); |
| 12519 |
|
| 12520 |
ering->rx_max_pending = tp->rx_std_ring_mask; |
| 12521 |
if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
| 12522 |
ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
| 12523 |
else |
| 12524 |
ering->rx_jumbo_max_pending = 0; |
| 12525 |
|
| 12526 |
ering->tx_max_pending = TG3_TX_RING_SIZE - 1; |
| 12527 |
|
| 12528 |
ering->rx_pending = tp->rx_pending; |
| 12529 |
if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
| 12530 |
ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
| 12531 |
else |
| 12532 |
ering->rx_jumbo_pending = 0; |
| 12533 |
|
| 12534 |
ering->tx_pending = tp->napi[0].tx_pending; |
| 12535 |
} |
| 12536 |
|
| 12537 |
static int tg3_set_ringparam(struct net_device *dev, |
| 12538 |
struct ethtool_ringparam *ering, |
| 12539 |
struct kernel_ethtool_ringparam *kernel_ering, |
| 12540 |
struct netlink_ext_ack *extack) |
| 12541 |
{ |
| 12542 |
struct tg3 *tp = netdev_priv(dev); |
| 12543 |
int i, irq_sync = 0, err = 0; |
| 12544 |
bool reset_phy = false; |
| 12545 |
|
| 12546 |
if ((ering->rx_pending > tp->rx_std_ring_mask) || |
| 12547 |
(ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || |
| 12548 |
(ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
| 12549 |
(ering->tx_pending <= MAX_SKB_FRAGS) || |
| 12550 |
(tg3_flag(tp, TSO_BUG) && |
| 12551 |
(ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
| 12552 |
return -EINVAL; |
| 12553 |
|
| 12554 |
if (netif_running(dev)) { |
| 12555 |
tg3_phy_stop(tp); |
| 12556 |
tg3_netif_stop(tp); |
| 12557 |
irq_sync = 1; |
| 12558 |
} |
| 12559 |
|
| 12560 |
netdev_lock(dev); |
| 12561 |
tg3_full_lock(tp, irq_sync); |
| 12562 |
|
| 12563 |
tp->rx_pending = ering->rx_pending; |
| 12564 |
|
| 12565 |
if (tg3_flag(tp, MAX_RXPEND_64) && |
| 12566 |
tp->rx_pending > 63) |
| 12567 |
tp->rx_pending = 63; |
| 12568 |
|
| 12569 |
if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
| 12570 |
tp->rx_jumbo_pending = ering->rx_jumbo_pending; |
| 12571 |
|
| 12572 |
for (i = 0; i < tp->irq_max; i++) |
| 12573 |
tp->napi[i].tx_pending = ering->tx_pending; |
| 12574 |
|
| 12575 |
if (netif_running(dev)) { |
| 12576 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 12577 |
/* Reset PHY to avoid PHY lock up */ |
| 12578 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 12579 |
tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 12580 |
tg3_asic_rev(tp) == ASIC_REV_5720) |
| 12581 |
reset_phy = true; |
| 12582 |
|
| 12583 |
err = tg3_restart_hw(tp, reset_phy); |
| 12584 |
if (!err) |
| 12585 |
tg3_netif_start(tp); |
| 12586 |
} |
| 12587 |
|
| 12588 |
tg3_full_unlock(tp); |
| 12589 |
netdev_unlock(dev); |
| 12590 |
|
| 12591 |
if (irq_sync && !err) |
| 12592 |
tg3_phy_start(tp); |
| 12593 |
|
| 12594 |
return err; |
| 12595 |
} |
| 12596 |
|
| 12597 |
static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 12598 |
{ |
| 12599 |
struct tg3 *tp = netdev_priv(dev); |
| 12600 |
|
| 12601 |
epause->autoneg = !!tg3_flag(tp, PAUSE_AUTONEG); |
| 12602 |
|
| 12603 |
if (tp->link_config.flowctrl & FLOW_CTRL_RX) |
| 12604 |
epause->rx_pause = 1; |
| 12605 |
else |
| 12606 |
epause->rx_pause = 0; |
| 12607 |
|
| 12608 |
if (tp->link_config.flowctrl & FLOW_CTRL_TX) |
| 12609 |
epause->tx_pause = 1; |
| 12610 |
else |
| 12611 |
epause->tx_pause = 0; |
| 12612 |
} |
| 12613 |
|
| 12614 |
static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
| 12615 |
{ |
| 12616 |
struct tg3 *tp = netdev_priv(dev); |
| 12617 |
int err = 0; |
| 12618 |
bool reset_phy = false; |
| 12619 |
|
| 12620 |
if (tp->link_config.autoneg == AUTONEG_ENABLE) |
| 12621 |
tg3_warn_mgmt_link_flap(tp); |
| 12622 |
|
| 12623 |
if (tg3_flag(tp, USE_PHYLIB)) { |
| 12624 |
struct phy_device *phydev; |
| 12625 |
|
| 12626 |
phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr); |
| 12627 |
|
| 12628 |
if (!phy_validate_pause(phydev, epause)) |
| 12629 |
return -EINVAL; |
| 12630 |
|
| 12631 |
tp->link_config.flowctrl = 0; |
| 12632 |
phy_set_asym_pause(phydev, epause->rx_pause, epause->tx_pause); |
| 12633 |
if (epause->rx_pause) { |
| 12634 |
tp->link_config.flowctrl |= FLOW_CTRL_RX; |
| 12635 |
|
| 12636 |
if (epause->tx_pause) { |
| 12637 |
tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 12638 |
} |
| 12639 |
} else if (epause->tx_pause) { |
| 12640 |
tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 12641 |
} |
| 12642 |
|
| 12643 |
if (epause->autoneg) |
| 12644 |
tg3_flag_set(tp, PAUSE_AUTONEG); |
| 12645 |
else |
| 12646 |
tg3_flag_clear(tp, PAUSE_AUTONEG); |
| 12647 |
|
| 12648 |
if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
| 12649 |
if (phydev->autoneg) { |
| 12650 |
/* phy_set_asym_pause() will |
| 12651 |
* renegotiate the link to inform our |
| 12652 |
* link partner of our flow control |
| 12653 |
* settings, even if the flow control |
| 12654 |
* is forced. Let tg3_adjust_link() |
| 12655 |
* do the final flow control setup. |
| 12656 |
*/ |
| 12657 |
return 0; |
| 12658 |
} |
| 12659 |
|
| 12660 |
if (!epause->autoneg) |
| 12661 |
tg3_setup_flow_control(tp, 0, 0); |
| 12662 |
} |
| 12663 |
} else { |
| 12664 |
int irq_sync = 0; |
| 12665 |
|
| 12666 |
if (netif_running(dev)) { |
| 12667 |
tg3_netif_stop(tp); |
| 12668 |
irq_sync = 1; |
| 12669 |
} |
| 12670 |
|
| 12671 |
netdev_lock(dev); |
| 12672 |
tg3_full_lock(tp, irq_sync); |
| 12673 |
|
| 12674 |
if (epause->autoneg) |
| 12675 |
tg3_flag_set(tp, PAUSE_AUTONEG); |
| 12676 |
else |
| 12677 |
tg3_flag_clear(tp, PAUSE_AUTONEG); |
| 12678 |
if (epause->rx_pause) |
| 12679 |
tp->link_config.flowctrl |= FLOW_CTRL_RX; |
| 12680 |
else |
| 12681 |
tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
| 12682 |
if (epause->tx_pause) |
| 12683 |
tp->link_config.flowctrl |= FLOW_CTRL_TX; |
| 12684 |
else |
| 12685 |
tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
| 12686 |
|
| 12687 |
if (netif_running(dev)) { |
| 12688 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 12689 |
/* Reset PHY to avoid PHY lock up */ |
| 12690 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 12691 |
tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 12692 |
tg3_asic_rev(tp) == ASIC_REV_5720) |
| 12693 |
reset_phy = true; |
| 12694 |
|
| 12695 |
err = tg3_restart_hw(tp, reset_phy); |
| 12696 |
if (!err) |
| 12697 |
tg3_netif_start(tp); |
| 12698 |
} |
| 12699 |
|
| 12700 |
tg3_full_unlock(tp); |
| 12701 |
netdev_unlock(dev); |
| 12702 |
} |
| 12703 |
|
| 12704 |
tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; |
| 12705 |
|
| 12706 |
return err; |
| 12707 |
} |
| 12708 |
|
| 12709 |
static int tg3_get_sset_count(struct net_device *dev, int sset) |
| 12710 |
{ |
| 12711 |
switch (sset) { |
| 12712 |
case ETH_SS_TEST: |
| 12713 |
return TG3_NUM_TEST; |
| 12714 |
case ETH_SS_STATS: |
| 12715 |
return TG3_NUM_STATS; |
| 12716 |
default: |
| 12717 |
return -EOPNOTSUPP; |
| 12718 |
} |
| 12719 |
} |
| 12720 |
|
| 12721 |
static u32 tg3_get_rx_ring_count(struct net_device *dev) |
| 12722 |
{ |
| 12723 |
struct tg3 *tp = netdev_priv(dev); |
| 12724 |
|
| 12725 |
if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 12726 |
return 1; |
| 12727 |
|
| 12728 |
if (netif_running(tp->dev)) |
| 12729 |
return tp->rxq_cnt; |
| 12730 |
|
| 12731 |
return min_t(u32, netif_get_num_default_rss_queues(), tp->rxq_max); |
| 12732 |
} |
| 12733 |
|
| 12734 |
static u32 tg3_get_rxfh_indir_size(struct net_device *dev) |
| 12735 |
{ |
| 12736 |
u32 size = 0; |
| 12737 |
struct tg3 *tp = netdev_priv(dev); |
| 12738 |
|
| 12739 |
if (tg3_flag(tp, SUPPORT_MSIX)) |
| 12740 |
size = TG3_RSS_INDIR_TBL_SIZE; |
| 12741 |
|
| 12742 |
return size; |
| 12743 |
} |
| 12744 |
|
| 12745 |
static int tg3_get_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh) |
| 12746 |
{ |
| 12747 |
struct tg3 *tp = netdev_priv(dev); |
| 12748 |
int i; |
| 12749 |
|
| 12750 |
rxfh->hfunc = ETH_RSS_HASH_TOP; |
| 12751 |
if (!rxfh->indir) |
| 12752 |
return 0; |
| 12753 |
|
| 12754 |
for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 12755 |
rxfh->indir[i] = tp->rss_ind_tbl[i]; |
| 12756 |
|
| 12757 |
return 0; |
| 12758 |
} |
| 12759 |
|
| 12760 |
static int tg3_set_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh, |
| 12761 |
struct netlink_ext_ack *extack) |
| 12762 |
{ |
| 12763 |
struct tg3 *tp = netdev_priv(dev); |
| 12764 |
size_t i; |
| 12765 |
|
| 12766 |
/* We require at least one supported parameter to be changed and no |
| 12767 |
* change in any of the unsupported parameters |
| 12768 |
*/ |
| 12769 |
if (rxfh->key || |
| 12770 |
(rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && |
| 12771 |
rxfh->hfunc != ETH_RSS_HASH_TOP)) |
| 12772 |
return -EOPNOTSUPP; |
| 12773 |
|
| 12774 |
if (!rxfh->indir) |
| 12775 |
return 0; |
| 12776 |
|
| 12777 |
for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) |
| 12778 |
tp->rss_ind_tbl[i] = rxfh->indir[i]; |
| 12779 |
|
| 12780 |
if (!netif_running(dev) || !tg3_flag(tp, ENABLE_RSS)) |
| 12781 |
return 0; |
| 12782 |
|
| 12783 |
/* It is legal to write the indirection |
| 12784 |
* table while the device is running. |
| 12785 |
*/ |
| 12786 |
tg3_full_lock(tp, 0); |
| 12787 |
tg3_rss_write_indir_tbl(tp); |
| 12788 |
tg3_full_unlock(tp); |
| 12789 |
|
| 12790 |
return 0; |
| 12791 |
} |
| 12792 |
|
| 12793 |
static void tg3_get_channels(struct net_device *dev, |
| 12794 |
struct ethtool_channels *channel) |
| 12795 |
{ |
| 12796 |
struct tg3 *tp = netdev_priv(dev); |
| 12797 |
u32 deflt_qs = netif_get_num_default_rss_queues(); |
| 12798 |
|
| 12799 |
channel->max_rx = tp->rxq_max; |
| 12800 |
channel->max_tx = tp->txq_max; |
| 12801 |
|
| 12802 |
if (netif_running(dev)) { |
| 12803 |
channel->rx_count = tp->rxq_cnt; |
| 12804 |
channel->tx_count = tp->txq_cnt; |
| 12805 |
} else { |
| 12806 |
if (tp->rxq_req) |
| 12807 |
channel->rx_count = tp->rxq_req; |
| 12808 |
else |
| 12809 |
channel->rx_count = min(deflt_qs, tp->rxq_max); |
| 12810 |
|
| 12811 |
if (tp->txq_req) |
| 12812 |
channel->tx_count = tp->txq_req; |
| 12813 |
else |
| 12814 |
channel->tx_count = min(deflt_qs, tp->txq_max); |
| 12815 |
} |
| 12816 |
} |
| 12817 |
|
| 12818 |
static int tg3_set_channels(struct net_device *dev, |
| 12819 |
struct ethtool_channels *channel) |
| 12820 |
{ |
| 12821 |
struct tg3 *tp = netdev_priv(dev); |
| 12822 |
|
| 12823 |
if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 12824 |
return -EOPNOTSUPP; |
| 12825 |
|
| 12826 |
if (channel->rx_count > tp->rxq_max || |
| 12827 |
channel->tx_count > tp->txq_max) |
| 12828 |
return -EINVAL; |
| 12829 |
|
| 12830 |
tp->rxq_req = channel->rx_count; |
| 12831 |
tp->txq_req = channel->tx_count; |
| 12832 |
|
| 12833 |
if (!netif_running(dev)) |
| 12834 |
return 0; |
| 12835 |
|
| 12836 |
tg3_stop(tp); |
| 12837 |
|
| 12838 |
tg3_carrier_off(tp); |
| 12839 |
|
| 12840 |
tg3_start(tp, true, false, false); |
| 12841 |
|
| 12842 |
return 0; |
| 12843 |
} |
| 12844 |
|
| 12845 |
static void tg3_get_strings(struct net_device *dev, u32 stringset, u8 *buf) |
| 12846 |
{ |
| 12847 |
switch (stringset) { |
| 12848 |
case ETH_SS_STATS: |
| 12849 |
memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 12850 |
break; |
| 12851 |
case ETH_SS_TEST: |
| 12852 |
memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); |
| 12853 |
break; |
| 12854 |
default: |
| 12855 |
WARN_ON(1); /* we need a WARN() */ |
| 12856 |
break; |
| 12857 |
} |
| 12858 |
} |
| 12859 |
|
| 12860 |
static int tg3_set_phys_id(struct net_device *dev, |
| 12861 |
enum ethtool_phys_id_state state) |
| 12862 |
{ |
| 12863 |
struct tg3 *tp = netdev_priv(dev); |
| 12864 |
|
| 12865 |
switch (state) { |
| 12866 |
case ETHTOOL_ID_ACTIVE: |
| 12867 |
return 1; /* cycle on/off once per second */ |
| 12868 |
|
| 12869 |
case ETHTOOL_ID_ON: |
| 12870 |
tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 12871 |
LED_CTRL_1000MBPS_ON | |
| 12872 |
LED_CTRL_100MBPS_ON | |
| 12873 |
LED_CTRL_10MBPS_ON | |
| 12874 |
LED_CTRL_TRAFFIC_OVERRIDE | |
| 12875 |
LED_CTRL_TRAFFIC_BLINK | |
| 12876 |
LED_CTRL_TRAFFIC_LED); |
| 12877 |
break; |
| 12878 |
|
| 12879 |
case ETHTOOL_ID_OFF: |
| 12880 |
tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | |
| 12881 |
LED_CTRL_TRAFFIC_OVERRIDE); |
| 12882 |
break; |
| 12883 |
|
| 12884 |
case ETHTOOL_ID_INACTIVE: |
| 12885 |
tw32(MAC_LED_CTRL, tp->led_ctrl); |
| 12886 |
break; |
| 12887 |
} |
| 12888 |
|
| 12889 |
return 0; |
| 12890 |
} |
| 12891 |
|
| 12892 |
static void tg3_get_ethtool_stats(struct net_device *dev, |
| 12893 |
struct ethtool_stats *estats, u64 *tmp_stats) |
| 12894 |
{ |
| 12895 |
struct tg3 *tp = netdev_priv(dev); |
| 12896 |
|
| 12897 |
if (tp->hw_stats) |
| 12898 |
tg3_get_estats(tp, (struct tg3_ethtool_stats *)tmp_stats); |
| 12899 |
else |
| 12900 |
memset(tmp_stats, 0, sizeof(struct tg3_ethtool_stats)); |
| 12901 |
} |
| 12902 |
|
| 12903 |
static __be32 *tg3_vpd_readblock(struct tg3 *tp, unsigned int *vpdlen) |
| 12904 |
{ |
| 12905 |
int i; |
| 12906 |
__be32 *buf; |
| 12907 |
u32 offset = 0, len = 0; |
| 12908 |
u32 magic, val; |
| 12909 |
|
| 12910 |
if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &magic)) |
| 12911 |
return NULL; |
| 12912 |
|
| 12913 |
if (magic == TG3_EEPROM_MAGIC) { |
| 12914 |
for (offset = TG3_NVM_DIR_START; |
| 12915 |
offset < TG3_NVM_DIR_END; |
| 12916 |
offset += TG3_NVM_DIRENT_SIZE) { |
| 12917 |
if (tg3_nvram_read(tp, offset, &val)) |
| 12918 |
return NULL; |
| 12919 |
|
| 12920 |
if ((val >> TG3_NVM_DIRTYPE_SHIFT) == |
| 12921 |
TG3_NVM_DIRTYPE_EXTVPD) |
| 12922 |
break; |
| 12923 |
} |
| 12924 |
|
| 12925 |
if (offset != TG3_NVM_DIR_END) { |
| 12926 |
len = (val & TG3_NVM_DIRTYPE_LENMSK) * 4; |
| 12927 |
if (tg3_nvram_read(tp, offset + 4, &offset)) |
| 12928 |
return NULL; |
| 12929 |
|
| 12930 |
offset = tg3_nvram_logical_addr(tp, offset); |
| 12931 |
} |
| 12932 |
|
| 12933 |
if (!offset || !len) { |
| 12934 |
offset = TG3_NVM_VPD_OFF; |
| 12935 |
len = TG3_NVM_VPD_LEN; |
| 12936 |
} |
| 12937 |
|
| 12938 |
buf = kmalloc(len, GFP_KERNEL); |
| 12939 |
if (!buf) |
| 12940 |
return NULL; |
| 12941 |
|
| 12942 |
for (i = 0; i < len; i += 4) { |
| 12943 |
/* The data is in little-endian format in NVRAM. |
| 12944 |
* Use the big-endian read routines to preserve |
| 12945 |
* the byte order as it exists in NVRAM. |
| 12946 |
*/ |
| 12947 |
if (tg3_nvram_read_be32(tp, offset + i, &buf[i/4])) |
| 12948 |
goto error; |
| 12949 |
} |
| 12950 |
*vpdlen = len; |
| 12951 |
} else { |
| 12952 |
buf = pci_vpd_alloc(tp->pdev, vpdlen); |
| 12953 |
if (IS_ERR(buf)) |
| 12954 |
return NULL; |
| 12955 |
} |
| 12956 |
|
| 12957 |
return buf; |
| 12958 |
|
| 12959 |
error: |
| 12960 |
kfree(buf); |
| 12961 |
return NULL; |
| 12962 |
} |
| 12963 |
|
| 12964 |
#define NVRAM_TEST_SIZE 0x100 |
| 12965 |
#define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
| 12966 |
#define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 |
| 12967 |
#define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c |
| 12968 |
#define NVRAM_SELFBOOT_FORMAT1_4_SIZE 0x20 |
| 12969 |
#define NVRAM_SELFBOOT_FORMAT1_5_SIZE 0x24 |
| 12970 |
#define NVRAM_SELFBOOT_FORMAT1_6_SIZE 0x50 |
| 12971 |
#define NVRAM_SELFBOOT_HW_SIZE 0x20 |
| 12972 |
#define NVRAM_SELFBOOT_DATA_SIZE 0x1c |
| 12973 |
|
| 12974 |
static int tg3_test_nvram(struct tg3 *tp) |
| 12975 |
{ |
| 12976 |
u32 csum, magic; |
| 12977 |
__be32 *buf; |
| 12978 |
int i, j, k, err = 0, size; |
| 12979 |
unsigned int len; |
| 12980 |
|
| 12981 |
if (tg3_flag(tp, NO_NVRAM)) |
| 12982 |
return 0; |
| 12983 |
|
| 12984 |
if (tg3_nvram_read(tp, 0, &magic) != 0) |
| 12985 |
return -EIO; |
| 12986 |
|
| 12987 |
if (magic == TG3_EEPROM_MAGIC) |
| 12988 |
size = NVRAM_TEST_SIZE; |
| 12989 |
else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
| 12990 |
if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
| 12991 |
TG3_EEPROM_SB_FORMAT_1) { |
| 12992 |
switch (magic & TG3_EEPROM_SB_REVISION_MASK) { |
| 12993 |
case TG3_EEPROM_SB_REVISION_0: |
| 12994 |
size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; |
| 12995 |
break; |
| 12996 |
case TG3_EEPROM_SB_REVISION_2: |
| 12997 |
size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; |
| 12998 |
break; |
| 12999 |
case TG3_EEPROM_SB_REVISION_3: |
| 13000 |
size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; |
| 13001 |
break; |
| 13002 |
case TG3_EEPROM_SB_REVISION_4: |
| 13003 |
size = NVRAM_SELFBOOT_FORMAT1_4_SIZE; |
| 13004 |
break; |
| 13005 |
case TG3_EEPROM_SB_REVISION_5: |
| 13006 |
size = NVRAM_SELFBOOT_FORMAT1_5_SIZE; |
| 13007 |
break; |
| 13008 |
case TG3_EEPROM_SB_REVISION_6: |
| 13009 |
size = NVRAM_SELFBOOT_FORMAT1_6_SIZE; |
| 13010 |
break; |
| 13011 |
default: |
| 13012 |
return -EIO; |
| 13013 |
} |
| 13014 |
} else |
| 13015 |
return 0; |
| 13016 |
} else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 13017 |
size = NVRAM_SELFBOOT_HW_SIZE; |
| 13018 |
else |
| 13019 |
return -EIO; |
| 13020 |
|
| 13021 |
buf = kmalloc(size, GFP_KERNEL); |
| 13022 |
if (buf == NULL) |
| 13023 |
return -ENOMEM; |
| 13024 |
|
| 13025 |
err = -EIO; |
| 13026 |
for (i = 0, j = 0; i < size; i += 4, j++) { |
| 13027 |
err = tg3_nvram_read_be32(tp, i, &buf[j]); |
| 13028 |
if (err) |
| 13029 |
break; |
| 13030 |
} |
| 13031 |
if (i < size) |
| 13032 |
goto out; |
| 13033 |
|
| 13034 |
/* Selfboot format */ |
| 13035 |
magic = be32_to_cpu(buf[0]); |
| 13036 |
if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
| 13037 |
TG3_EEPROM_MAGIC_FW) { |
| 13038 |
u8 *buf8 = (u8 *) buf, csum8 = 0; |
| 13039 |
|
| 13040 |
if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
| 13041 |
TG3_EEPROM_SB_REVISION_2) { |
| 13042 |
/* For rev 2, the csum doesn't include the MBA. */ |
| 13043 |
for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) |
| 13044 |
csum8 += buf8[i]; |
| 13045 |
for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) |
| 13046 |
csum8 += buf8[i]; |
| 13047 |
} else { |
| 13048 |
for (i = 0; i < size; i++) |
| 13049 |
csum8 += buf8[i]; |
| 13050 |
} |
| 13051 |
|
| 13052 |
if (csum8 == 0) { |
| 13053 |
err = 0; |
| 13054 |
goto out; |
| 13055 |
} |
| 13056 |
|
| 13057 |
err = -EIO; |
| 13058 |
goto out; |
| 13059 |
} |
| 13060 |
|
| 13061 |
if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
| 13062 |
TG3_EEPROM_MAGIC_HW) { |
| 13063 |
u8 data[NVRAM_SELFBOOT_DATA_SIZE]; |
| 13064 |
u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
| 13065 |
u8 *buf8 = (u8 *) buf; |
| 13066 |
|
| 13067 |
/* Separate the parity bits and the data bytes. */ |
| 13068 |
for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { |
| 13069 |
if ((i == 0) || (i == 8)) { |
| 13070 |
int l; |
| 13071 |
u8 msk; |
| 13072 |
|
| 13073 |
for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) |
| 13074 |
parity[k++] = buf8[i] & msk; |
| 13075 |
i++; |
| 13076 |
} else if (i == 16) { |
| 13077 |
int l; |
| 13078 |
u8 msk; |
| 13079 |
|
| 13080 |
for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) |
| 13081 |
parity[k++] = buf8[i] & msk; |
| 13082 |
i++; |
| 13083 |
|
| 13084 |
for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) |
| 13085 |
parity[k++] = buf8[i] & msk; |
| 13086 |
i++; |
| 13087 |
} |
| 13088 |
data[j++] = buf8[i]; |
| 13089 |
} |
| 13090 |
|
| 13091 |
err = -EIO; |
| 13092 |
for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { |
| 13093 |
u8 hw8 = hweight8(data[i]); |
| 13094 |
|
| 13095 |
if ((hw8 & 0x1) && parity[i]) |
| 13096 |
goto out; |
| 13097 |
else if (!(hw8 & 0x1) && !parity[i]) |
| 13098 |
goto out; |
| 13099 |
} |
| 13100 |
err = 0; |
| 13101 |
goto out; |
| 13102 |
} |
| 13103 |
|
| 13104 |
err = -EIO; |
| 13105 |
|
| 13106 |
/* Bootstrap checksum at offset 0x10 */ |
| 13107 |
csum = calc_crc((unsigned char *) buf, 0x10); |
| 13108 |
|
| 13109 |
/* The type of buf is __be32 *, but this value is __le32 */ |
| 13110 |
if (csum != le32_to_cpu((__force __le32)buf[0x10 / 4])) |
| 13111 |
goto out; |
| 13112 |
|
| 13113 |
/* Manufacturing block starts at offset 0x74, checksum at 0xfc */ |
| 13114 |
csum = calc_crc((unsigned char *)&buf[0x74 / 4], 0x88); |
| 13115 |
|
| 13116 |
/* The type of buf is __be32 *, but this value is __le32 */ |
| 13117 |
if (csum != le32_to_cpu((__force __le32)buf[0xfc / 4])) |
| 13118 |
goto out; |
| 13119 |
|
| 13120 |
kfree(buf); |
| 13121 |
|
| 13122 |
buf = tg3_vpd_readblock(tp, &len); |
| 13123 |
if (!buf) |
| 13124 |
return -ENOMEM; |
| 13125 |
|
| 13126 |
err = pci_vpd_check_csum(buf, len); |
| 13127 |
/* go on if no checksum found */ |
| 13128 |
if (err == 1) |
| 13129 |
err = 0; |
| 13130 |
out: |
| 13131 |
kfree(buf); |
| 13132 |
return err; |
| 13133 |
} |
| 13134 |
|
| 13135 |
#define TG3_SERDES_TIMEOUT_SEC 2 |
| 13136 |
#define TG3_COPPER_TIMEOUT_SEC 6 |
| 13137 |
|
| 13138 |
static int tg3_test_link(struct tg3 *tp) |
| 13139 |
{ |
| 13140 |
int i, max; |
| 13141 |
|
| 13142 |
if (!netif_running(tp->dev)) |
| 13143 |
return -ENODEV; |
| 13144 |
|
| 13145 |
if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 13146 |
max = TG3_SERDES_TIMEOUT_SEC; |
| 13147 |
else |
| 13148 |
max = TG3_COPPER_TIMEOUT_SEC; |
| 13149 |
|
| 13150 |
for (i = 0; i < max; i++) { |
| 13151 |
if (tp->link_up) |
| 13152 |
return 0; |
| 13153 |
|
| 13154 |
if (msleep_interruptible(1000)) |
| 13155 |
break; |
| 13156 |
} |
| 13157 |
|
| 13158 |
return -EIO; |
| 13159 |
} |
| 13160 |
|
| 13161 |
/* Only test the commonly used registers */ |
| 13162 |
static int tg3_test_registers(struct tg3 *tp) |
| 13163 |
{ |
| 13164 |
int i, is_5705, is_5750; |
| 13165 |
u32 offset, read_mask, write_mask, val, save_val, read_val; |
| 13166 |
static struct { |
| 13167 |
u16 offset; |
| 13168 |
u16 flags; |
| 13169 |
#define TG3_FL_5705 0x1 |
| 13170 |
#define TG3_FL_NOT_5705 0x2 |
| 13171 |
#define TG3_FL_NOT_5788 0x4 |
| 13172 |
#define TG3_FL_NOT_5750 0x8 |
| 13173 |
u32 read_mask; |
| 13174 |
u32 write_mask; |
| 13175 |
} reg_tbl[] = { |
| 13176 |
/* MAC Control Registers */ |
| 13177 |
{ MAC_MODE, TG3_FL_NOT_5705, |
| 13178 |
0x00000000, 0x00ef6f8c }, |
| 13179 |
{ MAC_MODE, TG3_FL_5705, |
| 13180 |
0x00000000, 0x01ef6b8c }, |
| 13181 |
{ MAC_STATUS, TG3_FL_NOT_5705, |
| 13182 |
0x03800107, 0x00000000 }, |
| 13183 |
{ MAC_STATUS, TG3_FL_5705, |
| 13184 |
0x03800100, 0x00000000 }, |
| 13185 |
{ MAC_ADDR_0_HIGH, 0x0000, |
| 13186 |
0x00000000, 0x0000ffff }, |
| 13187 |
{ MAC_ADDR_0_LOW, 0x0000, |
| 13188 |
0x00000000, 0xffffffff }, |
| 13189 |
{ MAC_RX_MTU_SIZE, 0x0000, |
| 13190 |
0x00000000, 0x0000ffff }, |
| 13191 |
{ MAC_TX_MODE, 0x0000, |
| 13192 |
0x00000000, 0x00000070 }, |
| 13193 |
{ MAC_TX_LENGTHS, 0x0000, |
| 13194 |
0x00000000, 0x00003fff }, |
| 13195 |
{ MAC_RX_MODE, TG3_FL_NOT_5705, |
| 13196 |
0x00000000, 0x000007fc }, |
| 13197 |
{ MAC_RX_MODE, TG3_FL_5705, |
| 13198 |
0x00000000, 0x000007dc }, |
| 13199 |
{ MAC_HASH_REG_0, 0x0000, |
| 13200 |
0x00000000, 0xffffffff }, |
| 13201 |
{ MAC_HASH_REG_1, 0x0000, |
| 13202 |
0x00000000, 0xffffffff }, |
| 13203 |
{ MAC_HASH_REG_2, 0x0000, |
| 13204 |
0x00000000, 0xffffffff }, |
| 13205 |
{ MAC_HASH_REG_3, 0x0000, |
| 13206 |
0x00000000, 0xffffffff }, |
| 13207 |
|
| 13208 |
/* Receive Data and Receive BD Initiator Control Registers. */ |
| 13209 |
{ RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, |
| 13210 |
0x00000000, 0xffffffff }, |
| 13211 |
{ RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, |
| 13212 |
0x00000000, 0xffffffff }, |
| 13213 |
{ RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, |
| 13214 |
0x00000000, 0x00000003 }, |
| 13215 |
{ RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, |
| 13216 |
0x00000000, 0xffffffff }, |
| 13217 |
{ RCVDBDI_STD_BD+0, 0x0000, |
| 13218 |
0x00000000, 0xffffffff }, |
| 13219 |
{ RCVDBDI_STD_BD+4, 0x0000, |
| 13220 |
0x00000000, 0xffffffff }, |
| 13221 |
{ RCVDBDI_STD_BD+8, 0x0000, |
| 13222 |
0x00000000, 0xffff0002 }, |
| 13223 |
{ RCVDBDI_STD_BD+0xc, 0x0000, |
| 13224 |
0x00000000, 0xffffffff }, |
| 13225 |
|
| 13226 |
/* Receive BD Initiator Control Registers. */ |
| 13227 |
{ RCVBDI_STD_THRESH, TG3_FL_NOT_5705, |
| 13228 |
0x00000000, 0xffffffff }, |
| 13229 |
{ RCVBDI_STD_THRESH, TG3_FL_5705, |
| 13230 |
0x00000000, 0x000003ff }, |
| 13231 |
{ RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, |
| 13232 |
0x00000000, 0xffffffff }, |
| 13233 |
|
| 13234 |
/* Host Coalescing Control Registers. */ |
| 13235 |
{ HOSTCC_MODE, TG3_FL_NOT_5705, |
| 13236 |
0x00000000, 0x00000004 }, |
| 13237 |
{ HOSTCC_MODE, TG3_FL_5705, |
| 13238 |
0x00000000, 0x000000f6 }, |
| 13239 |
{ HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, |
| 13240 |
0x00000000, 0xffffffff }, |
| 13241 |
{ HOSTCC_RXCOL_TICKS, TG3_FL_5705, |
| 13242 |
0x00000000, 0x000003ff }, |
| 13243 |
{ HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, |
| 13244 |
0x00000000, 0xffffffff }, |
| 13245 |
{ HOSTCC_TXCOL_TICKS, TG3_FL_5705, |
| 13246 |
0x00000000, 0x000003ff }, |
| 13247 |
{ HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, |
| 13248 |
0x00000000, 0xffffffff }, |
| 13249 |
{ HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 13250 |
0x00000000, 0x000000ff }, |
| 13251 |
{ HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, |
| 13252 |
0x00000000, 0xffffffff }, |
| 13253 |
{ HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 13254 |
0x00000000, 0x000000ff }, |
| 13255 |
{ HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 13256 |
0x00000000, 0xffffffff }, |
| 13257 |
{ HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, |
| 13258 |
0x00000000, 0xffffffff }, |
| 13259 |
{ HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 13260 |
0x00000000, 0xffffffff }, |
| 13261 |
{ HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 13262 |
0x00000000, 0x000000ff }, |
| 13263 |
{ HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, |
| 13264 |
0x00000000, 0xffffffff }, |
| 13265 |
{ HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, |
| 13266 |
0x00000000, 0x000000ff }, |
| 13267 |
{ HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, |
| 13268 |
0x00000000, 0xffffffff }, |
| 13269 |
{ HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, |
| 13270 |
0x00000000, 0xffffffff }, |
| 13271 |
{ HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, |
| 13272 |
0x00000000, 0xffffffff }, |
| 13273 |
{ HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, |
| 13274 |
0x00000000, 0xffffffff }, |
| 13275 |
{ HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, |
| 13276 |
0x00000000, 0xffffffff }, |
| 13277 |
{ HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, |
| 13278 |
0xffffffff, 0x00000000 }, |
| 13279 |
{ HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, |
| 13280 |
0xffffffff, 0x00000000 }, |
| 13281 |
|
| 13282 |
/* Buffer Manager Control Registers. */ |
| 13283 |
{ BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
| 13284 |
0x00000000, 0x007fff80 }, |
| 13285 |
{ BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
| 13286 |
0x00000000, 0x007fffff }, |
| 13287 |
{ BUFMGR_MB_RDMA_LOW_WATER, 0x0000, |
| 13288 |
0x00000000, 0x0000003f }, |
| 13289 |
{ BUFMGR_MB_MACRX_LOW_WATER, 0x0000, |
| 13290 |
0x00000000, 0x000001ff }, |
| 13291 |
{ BUFMGR_MB_HIGH_WATER, 0x0000, |
| 13292 |
0x00000000, 0x000001ff }, |
| 13293 |
{ BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, |
| 13294 |
0xffffffff, 0x00000000 }, |
| 13295 |
{ BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, |
| 13296 |
0xffffffff, 0x00000000 }, |
| 13297 |
|
| 13298 |
/* Mailbox Registers */ |
| 13299 |
{ GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, |
| 13300 |
0x00000000, 0x000001ff }, |
| 13301 |
{ GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, |
| 13302 |
0x00000000, 0x000001ff }, |
| 13303 |
{ GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, |
| 13304 |
0x00000000, 0x000007ff }, |
| 13305 |
{ GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, |
| 13306 |
0x00000000, 0x000001ff }, |
| 13307 |
|
| 13308 |
{ 0xffff, 0x0000, 0x00000000, 0x00000000 }, |
| 13309 |
}; |
| 13310 |
|
| 13311 |
is_5705 = is_5750 = 0; |
| 13312 |
if (tg3_flag(tp, 5705_PLUS)) { |
| 13313 |
is_5705 = 1; |
| 13314 |
if (tg3_flag(tp, 5750_PLUS)) |
| 13315 |
is_5750 = 1; |
| 13316 |
} |
| 13317 |
|
| 13318 |
for (i = 0; reg_tbl[i].offset != 0xffff; i++) { |
| 13319 |
if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) |
| 13320 |
continue; |
| 13321 |
|
| 13322 |
if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) |
| 13323 |
continue; |
| 13324 |
|
| 13325 |
if (tg3_flag(tp, IS_5788) && |
| 13326 |
(reg_tbl[i].flags & TG3_FL_NOT_5788)) |
| 13327 |
continue; |
| 13328 |
|
| 13329 |
if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
| 13330 |
continue; |
| 13331 |
|
| 13332 |
offset = (u32) reg_tbl[i].offset; |
| 13333 |
read_mask = reg_tbl[i].read_mask; |
| 13334 |
write_mask = reg_tbl[i].write_mask; |
| 13335 |
|
| 13336 |
/* Save the original register content */ |
| 13337 |
save_val = tr32(offset); |
| 13338 |
|
| 13339 |
/* Determine the read-only value. */ |
| 13340 |
read_val = save_val & read_mask; |
| 13341 |
|
| 13342 |
/* Write zero to the register, then make sure the read-only bits |
| 13343 |
* are not changed and the read/write bits are all zeros. |
| 13344 |
*/ |
| 13345 |
tw32(offset, 0); |
| 13346 |
|
| 13347 |
val = tr32(offset); |
| 13348 |
|
| 13349 |
/* Test the read-only and read/write bits. */ |
| 13350 |
if (((val & read_mask) != read_val) || (val & write_mask)) |
| 13351 |
goto out; |
| 13352 |
|
| 13353 |
/* Write ones to all the bits defined by RdMask and WrMask, then |
| 13354 |
* make sure the read-only bits are not changed and the |
| 13355 |
* read/write bits are all ones. |
| 13356 |
*/ |
| 13357 |
tw32(offset, read_mask | write_mask); |
| 13358 |
|
| 13359 |
val = tr32(offset); |
| 13360 |
|
| 13361 |
/* Test the read-only bits. */ |
| 13362 |
if ((val & read_mask) != read_val) |
| 13363 |
goto out; |
| 13364 |
|
| 13365 |
/* Test the read/write bits. */ |
| 13366 |
if ((val & write_mask) != write_mask) |
| 13367 |
goto out; |
| 13368 |
|
| 13369 |
tw32(offset, save_val); |
| 13370 |
} |
| 13371 |
|
| 13372 |
return 0; |
| 13373 |
|
| 13374 |
out: |
| 13375 |
if (netif_msg_hw(tp)) |
| 13376 |
netdev_err(tp->dev, |
| 13377 |
"Register test failed at offset %x\n", offset); |
| 13378 |
tw32(offset, save_val); |
| 13379 |
return -EIO; |
| 13380 |
} |
| 13381 |
|
| 13382 |
static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
| 13383 |
{ |
| 13384 |
static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
| 13385 |
int i; |
| 13386 |
u32 j; |
| 13387 |
|
| 13388 |
for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
| 13389 |
for (j = 0; j < len; j += 4) { |
| 13390 |
u32 val; |
| 13391 |
|
| 13392 |
tg3_write_mem(tp, offset + j, test_pattern[i]); |
| 13393 |
tg3_read_mem(tp, offset + j, &val); |
| 13394 |
if (val != test_pattern[i]) |
| 13395 |
return -EIO; |
| 13396 |
} |
| 13397 |
} |
| 13398 |
return 0; |
| 13399 |
} |
| 13400 |
|
| 13401 |
static int tg3_test_memory(struct tg3 *tp) |
| 13402 |
{ |
| 13403 |
static struct mem_entry { |
| 13404 |
u32 offset; |
| 13405 |
u32 len; |
| 13406 |
} mem_tbl_570x[] = { |
| 13407 |
{ 0x00000000, 0x00b50}, |
| 13408 |
{ 0x00002000, 0x1c000}, |
| 13409 |
{ 0xffffffff, 0x00000} |
| 13410 |
}, mem_tbl_5705[] = { |
| 13411 |
{ 0x00000100, 0x0000c}, |
| 13412 |
{ 0x00000200, 0x00008}, |
| 13413 |
{ 0x00004000, 0x00800}, |
| 13414 |
{ 0x00006000, 0x01000}, |
| 13415 |
{ 0x00008000, 0x02000}, |
| 13416 |
{ 0x00010000, 0x0e000}, |
| 13417 |
{ 0xffffffff, 0x00000} |
| 13418 |
}, mem_tbl_5755[] = { |
| 13419 |
{ 0x00000200, 0x00008}, |
| 13420 |
{ 0x00004000, 0x00800}, |
| 13421 |
{ 0x00006000, 0x00800}, |
| 13422 |
{ 0x00008000, 0x02000}, |
| 13423 |
{ 0x00010000, 0x0c000}, |
| 13424 |
{ 0xffffffff, 0x00000} |
| 13425 |
}, mem_tbl_5906[] = { |
| 13426 |
{ 0x00000200, 0x00008}, |
| 13427 |
{ 0x00004000, 0x00400}, |
| 13428 |
{ 0x00006000, 0x00400}, |
| 13429 |
{ 0x00008000, 0x01000}, |
| 13430 |
{ 0x00010000, 0x01000}, |
| 13431 |
{ 0xffffffff, 0x00000} |
| 13432 |
}, mem_tbl_5717[] = { |
| 13433 |
{ 0x00000200, 0x00008}, |
| 13434 |
{ 0x00010000, 0x0a000}, |
| 13435 |
{ 0x00020000, 0x13c00}, |
| 13436 |
{ 0xffffffff, 0x00000} |
| 13437 |
}, mem_tbl_57765[] = { |
| 13438 |
{ 0x00000200, 0x00008}, |
| 13439 |
{ 0x00004000, 0x00800}, |
| 13440 |
{ 0x00006000, 0x09800}, |
| 13441 |
{ 0x00010000, 0x0a000}, |
| 13442 |
{ 0xffffffff, 0x00000} |
| 13443 |
}; |
| 13444 |
struct mem_entry *mem_tbl; |
| 13445 |
int err = 0; |
| 13446 |
int i; |
| 13447 |
|
| 13448 |
if (tg3_flag(tp, 5717_PLUS)) |
| 13449 |
mem_tbl = mem_tbl_5717; |
| 13450 |
else if (tg3_flag(tp, 57765_CLASS) || |
| 13451 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 13452 |
mem_tbl = mem_tbl_57765; |
| 13453 |
else if (tg3_flag(tp, 5755_PLUS)) |
| 13454 |
mem_tbl = mem_tbl_5755; |
| 13455 |
else if (tg3_asic_rev(tp) == ASIC_REV_5906) |
| 13456 |
mem_tbl = mem_tbl_5906; |
| 13457 |
else if (tg3_flag(tp, 5705_PLUS)) |
| 13458 |
mem_tbl = mem_tbl_5705; |
| 13459 |
else |
| 13460 |
mem_tbl = mem_tbl_570x; |
| 13461 |
|
| 13462 |
for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { |
| 13463 |
err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
| 13464 |
if (err) |
| 13465 |
break; |
| 13466 |
} |
| 13467 |
|
| 13468 |
return err; |
| 13469 |
} |
| 13470 |
|
| 13471 |
#define TG3_TSO_MSS 500 |
| 13472 |
|
| 13473 |
#define TG3_TSO_IP_HDR_LEN 20 |
| 13474 |
#define TG3_TSO_TCP_HDR_LEN 20 |
| 13475 |
#define TG3_TSO_TCP_OPT_LEN 12 |
| 13476 |
|
| 13477 |
static const u8 tg3_tso_header[] = { |
| 13478 |
0x08, 0x00, |
| 13479 |
0x45, 0x00, 0x00, 0x00, |
| 13480 |
0x00, 0x00, 0x40, 0x00, |
| 13481 |
0x40, 0x06, 0x00, 0x00, |
| 13482 |
0x0a, 0x00, 0x00, 0x01, |
| 13483 |
0x0a, 0x00, 0x00, 0x02, |
| 13484 |
0x0d, 0x00, 0xe0, 0x00, |
| 13485 |
0x00, 0x00, 0x01, 0x00, |
| 13486 |
0x00, 0x00, 0x02, 0x00, |
| 13487 |
0x80, 0x10, 0x10, 0x00, |
| 13488 |
0x14, 0x09, 0x00, 0x00, |
| 13489 |
0x01, 0x01, 0x08, 0x0a, |
| 13490 |
0x11, 0x11, 0x11, 0x11, |
| 13491 |
0x11, 0x11, 0x11, 0x11, |
| 13492 |
}; |
| 13493 |
|
| 13494 |
static int tg3_run_loopback(struct tg3 *tp, u32 pktsz, bool tso_loopback) |
| 13495 |
{ |
| 13496 |
u32 rx_start_idx, rx_idx, tx_idx, opaque_key; |
| 13497 |
u32 base_flags = 0, mss = 0, desc_idx, coal_now, data_off, val; |
| 13498 |
u32 budget; |
| 13499 |
struct sk_buff *skb; |
| 13500 |
u8 *tx_data, *rx_data; |
| 13501 |
dma_addr_t map; |
| 13502 |
int num_pkts, tx_len, rx_len, i, err; |
| 13503 |
struct tg3_rx_buffer_desc *desc; |
| 13504 |
struct tg3_napi *tnapi, *rnapi; |
| 13505 |
struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
| 13506 |
|
| 13507 |
tnapi = &tp->napi[0]; |
| 13508 |
rnapi = &tp->napi[0]; |
| 13509 |
if (tp->irq_cnt > 1) { |
| 13510 |
if (tg3_flag(tp, ENABLE_RSS)) |
| 13511 |
rnapi = &tp->napi[1]; |
| 13512 |
if (tg3_flag(tp, ENABLE_TSS)) |
| 13513 |
tnapi = &tp->napi[1]; |
| 13514 |
} |
| 13515 |
coal_now = tnapi->coal_now | rnapi->coal_now; |
| 13516 |
|
| 13517 |
err = -EIO; |
| 13518 |
|
| 13519 |
tx_len = pktsz; |
| 13520 |
skb = netdev_alloc_skb(tp->dev, tx_len); |
| 13521 |
if (!skb) |
| 13522 |
return -ENOMEM; |
| 13523 |
|
| 13524 |
tx_data = skb_put(skb, tx_len); |
| 13525 |
memcpy(tx_data, tp->dev->dev_addr, ETH_ALEN); |
| 13526 |
memset(tx_data + ETH_ALEN, 0x0, 8); |
| 13527 |
|
| 13528 |
tw32(MAC_RX_MTU_SIZE, tx_len + ETH_FCS_LEN); |
| 13529 |
|
| 13530 |
if (tso_loopback) { |
| 13531 |
struct iphdr *iph = (struct iphdr *)&tx_data[ETH_HLEN]; |
| 13532 |
|
| 13533 |
u32 hdr_len = TG3_TSO_IP_HDR_LEN + TG3_TSO_TCP_HDR_LEN + |
| 13534 |
TG3_TSO_TCP_OPT_LEN; |
| 13535 |
|
| 13536 |
memcpy(tx_data + ETH_ALEN * 2, tg3_tso_header, |
| 13537 |
sizeof(tg3_tso_header)); |
| 13538 |
mss = TG3_TSO_MSS; |
| 13539 |
|
| 13540 |
val = tx_len - ETH_ALEN * 2 - sizeof(tg3_tso_header); |
| 13541 |
num_pkts = DIV_ROUND_UP(val, TG3_TSO_MSS); |
| 13542 |
|
| 13543 |
/* Set the total length field in the IP header */ |
| 13544 |
iph->tot_len = htons((u16)(mss + hdr_len)); |
| 13545 |
|
| 13546 |
base_flags = (TXD_FLAG_CPU_PRE_DMA | |
| 13547 |
TXD_FLAG_CPU_POST_DMA); |
| 13548 |
|
| 13549 |
if (tg3_flag(tp, HW_TSO_1) || |
| 13550 |
tg3_flag(tp, HW_TSO_2) || |
| 13551 |
tg3_flag(tp, HW_TSO_3)) { |
| 13552 |
struct tcphdr *th; |
| 13553 |
val = ETH_HLEN + TG3_TSO_IP_HDR_LEN; |
| 13554 |
th = (struct tcphdr *)&tx_data[val]; |
| 13555 |
th->check = 0; |
| 13556 |
} else |
| 13557 |
base_flags |= TXD_FLAG_TCPUDP_CSUM; |
| 13558 |
|
| 13559 |
if (tg3_flag(tp, HW_TSO_3)) { |
| 13560 |
mss |= (hdr_len & 0xc) << 12; |
| 13561 |
if (hdr_len & 0x10) |
| 13562 |
base_flags |= 0x00000010; |
| 13563 |
base_flags |= (hdr_len & 0x3e0) << 5; |
| 13564 |
} else if (tg3_flag(tp, HW_TSO_2)) |
| 13565 |
mss |= hdr_len << 9; |
| 13566 |
else if (tg3_flag(tp, HW_TSO_1) || |
| 13567 |
tg3_asic_rev(tp) == ASIC_REV_5705) { |
| 13568 |
mss |= (TG3_TSO_TCP_OPT_LEN << 9); |
| 13569 |
} else { |
| 13570 |
base_flags |= (TG3_TSO_TCP_OPT_LEN << 10); |
| 13571 |
} |
| 13572 |
|
| 13573 |
data_off = ETH_ALEN * 2 + sizeof(tg3_tso_header); |
| 13574 |
} else { |
| 13575 |
num_pkts = 1; |
| 13576 |
data_off = ETH_HLEN; |
| 13577 |
|
| 13578 |
if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
| 13579 |
tx_len > VLAN_ETH_FRAME_LEN) |
| 13580 |
base_flags |= TXD_FLAG_JMB_PKT; |
| 13581 |
} |
| 13582 |
|
| 13583 |
for (i = data_off; i < tx_len; i++) |
| 13584 |
tx_data[i] = (u8) (i & 0xff); |
| 13585 |
|
| 13586 |
map = dma_map_single(&tp->pdev->dev, skb->data, tx_len, DMA_TO_DEVICE); |
| 13587 |
if (dma_mapping_error(&tp->pdev->dev, map)) { |
| 13588 |
dev_kfree_skb(skb); |
| 13589 |
return -EIO; |
| 13590 |
} |
| 13591 |
|
| 13592 |
val = tnapi->tx_prod; |
| 13593 |
tnapi->tx_buffers[val].skb = skb; |
| 13594 |
dma_unmap_addr_set(&tnapi->tx_buffers[val], mapping, map); |
| 13595 |
|
| 13596 |
tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
| 13597 |
rnapi->coal_now); |
| 13598 |
|
| 13599 |
udelay(10); |
| 13600 |
|
| 13601 |
rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
| 13602 |
|
| 13603 |
budget = tg3_tx_avail(tnapi); |
| 13604 |
if (tg3_tx_frag_set(tnapi, &val, &budget, map, tx_len, |
| 13605 |
base_flags | TXD_FLAG_END, mss, 0)) { |
| 13606 |
tnapi->tx_buffers[val].skb = NULL; |
| 13607 |
dev_kfree_skb(skb); |
| 13608 |
return -EIO; |
| 13609 |
} |
| 13610 |
|
| 13611 |
tnapi->tx_prod++; |
| 13612 |
|
| 13613 |
/* Sync BD data before updating mailbox */ |
| 13614 |
wmb(); |
| 13615 |
|
| 13616 |
tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
| 13617 |
tr32_mailbox(tnapi->prodmbox); |
| 13618 |
|
| 13619 |
udelay(10); |
| 13620 |
|
| 13621 |
/* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
| 13622 |
for (i = 0; i < 35; i++) { |
| 13623 |
tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
| 13624 |
coal_now); |
| 13625 |
|
| 13626 |
udelay(10); |
| 13627 |
|
| 13628 |
tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
| 13629 |
rx_idx = rnapi->hw_status->idx[0].rx_producer; |
| 13630 |
if ((tx_idx == tnapi->tx_prod) && |
| 13631 |
(rx_idx == (rx_start_idx + num_pkts))) |
| 13632 |
break; |
| 13633 |
} |
| 13634 |
|
| 13635 |
tg3_tx_skb_unmap(tnapi, tnapi->tx_prod - 1, -1); |
| 13636 |
dev_kfree_skb(skb); |
| 13637 |
|
| 13638 |
if (tx_idx != tnapi->tx_prod) |
| 13639 |
goto out; |
| 13640 |
|
| 13641 |
if (rx_idx != rx_start_idx + num_pkts) |
| 13642 |
goto out; |
| 13643 |
|
| 13644 |
val = data_off; |
| 13645 |
while (rx_idx != rx_start_idx) { |
| 13646 |
desc = &rnapi->rx_rcb[rx_start_idx++]; |
| 13647 |
desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
| 13648 |
opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; |
| 13649 |
|
| 13650 |
if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
| 13651 |
(desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) |
| 13652 |
goto out; |
| 13653 |
|
| 13654 |
rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) |
| 13655 |
- ETH_FCS_LEN; |
| 13656 |
|
| 13657 |
if (!tso_loopback) { |
| 13658 |
if (rx_len != tx_len) |
| 13659 |
goto out; |
| 13660 |
|
| 13661 |
if (pktsz <= TG3_RX_STD_DMA_SZ - ETH_FCS_LEN) { |
| 13662 |
if (opaque_key != RXD_OPAQUE_RING_STD) |
| 13663 |
goto out; |
| 13664 |
} else { |
| 13665 |
if (opaque_key != RXD_OPAQUE_RING_JUMBO) |
| 13666 |
goto out; |
| 13667 |
} |
| 13668 |
} else if ((desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
| 13669 |
(desc->ip_tcp_csum & RXD_TCPCSUM_MASK) |
| 13670 |
>> RXD_TCPCSUM_SHIFT != 0xffff) { |
| 13671 |
goto out; |
| 13672 |
} |
| 13673 |
|
| 13674 |
if (opaque_key == RXD_OPAQUE_RING_STD) { |
| 13675 |
rx_data = tpr->rx_std_buffers[desc_idx].data; |
| 13676 |
map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], |
| 13677 |
mapping); |
| 13678 |
} else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
| 13679 |
rx_data = tpr->rx_jmb_buffers[desc_idx].data; |
| 13680 |
map = dma_unmap_addr(&tpr->rx_jmb_buffers[desc_idx], |
| 13681 |
mapping); |
| 13682 |
} else |
| 13683 |
goto out; |
| 13684 |
|
| 13685 |
dma_sync_single_for_cpu(&tp->pdev->dev, map, rx_len, |
| 13686 |
DMA_FROM_DEVICE); |
| 13687 |
|
| 13688 |
rx_data += TG3_RX_OFFSET(tp); |
| 13689 |
for (i = data_off; i < rx_len; i++, val++) { |
| 13690 |
if (*(rx_data + i) != (u8) (val & 0xff)) |
| 13691 |
goto out; |
| 13692 |
} |
| 13693 |
} |
| 13694 |
|
| 13695 |
err = 0; |
| 13696 |
|
| 13697 |
/* tg3_free_rings will unmap and free the rx_data */ |
| 13698 |
out: |
| 13699 |
return err; |
| 13700 |
} |
| 13701 |
|
| 13702 |
#define TG3_STD_LOOPBACK_FAILED 1 |
| 13703 |
#define TG3_JMB_LOOPBACK_FAILED 2 |
| 13704 |
#define TG3_TSO_LOOPBACK_FAILED 4 |
| 13705 |
#define TG3_LOOPBACK_FAILED \ |
| 13706 |
(TG3_STD_LOOPBACK_FAILED | \ |
| 13707 |
TG3_JMB_LOOPBACK_FAILED | \ |
| 13708 |
TG3_TSO_LOOPBACK_FAILED) |
| 13709 |
|
| 13710 |
static int tg3_test_loopback(struct tg3 *tp, u64 *data, bool do_extlpbk) |
| 13711 |
{ |
| 13712 |
int err = -EIO; |
| 13713 |
u32 eee_cap; |
| 13714 |
u32 jmb_pkt_sz = 9000; |
| 13715 |
|
| 13716 |
if (tp->dma_limit) |
| 13717 |
jmb_pkt_sz = tp->dma_limit - ETH_HLEN; |
| 13718 |
|
| 13719 |
eee_cap = tp->phy_flags & TG3_PHYFLG_EEE_CAP; |
| 13720 |
tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; |
| 13721 |
|
| 13722 |
if (!netif_running(tp->dev)) { |
| 13723 |
data[TG3_MAC_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 13724 |
data[TG3_PHY_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 13725 |
if (do_extlpbk) |
| 13726 |
data[TG3_EXT_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 13727 |
goto done; |
| 13728 |
} |
| 13729 |
|
| 13730 |
err = tg3_reset_hw(tp, true); |
| 13731 |
if (err) { |
| 13732 |
data[TG3_MAC_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 13733 |
data[TG3_PHY_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 13734 |
if (do_extlpbk) |
| 13735 |
data[TG3_EXT_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
| 13736 |
goto done; |
| 13737 |
} |
| 13738 |
|
| 13739 |
if (tg3_flag(tp, ENABLE_RSS)) { |
| 13740 |
int i; |
| 13741 |
|
| 13742 |
/* Reroute all rx packets to the 1st queue */ |
| 13743 |
for (i = MAC_RSS_INDIR_TBL_0; |
| 13744 |
i < MAC_RSS_INDIR_TBL_0 + TG3_RSS_INDIR_TBL_SIZE; i += 4) |
| 13745 |
tw32(i, 0x0); |
| 13746 |
} |
| 13747 |
|
| 13748 |
/* HW errata - mac loopback fails in some cases on 5780. |
| 13749 |
* Normal traffic and PHY loopback are not affected by |
| 13750 |
* errata. Also, the MAC loopback test is deprecated for |
| 13751 |
* all newer ASIC revisions. |
| 13752 |
*/ |
| 13753 |
if (tg3_asic_rev(tp) != ASIC_REV_5780 && |
| 13754 |
!tg3_flag(tp, CPMU_PRESENT)) { |
| 13755 |
tg3_mac_loopback(tp, true); |
| 13756 |
|
| 13757 |
if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
| 13758 |
data[TG3_MAC_LOOPB_TEST] |= TG3_STD_LOOPBACK_FAILED; |
| 13759 |
|
| 13760 |
if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
| 13761 |
tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
| 13762 |
data[TG3_MAC_LOOPB_TEST] |= TG3_JMB_LOOPBACK_FAILED; |
| 13763 |
|
| 13764 |
tg3_mac_loopback(tp, false); |
| 13765 |
} |
| 13766 |
|
| 13767 |
if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
| 13768 |
!tg3_flag(tp, USE_PHYLIB)) { |
| 13769 |
int i; |
| 13770 |
|
| 13771 |
tg3_phy_lpbk_set(tp, 0, false); |
| 13772 |
|
| 13773 |
/* Wait for link */ |
| 13774 |
for (i = 0; i < 100; i++) { |
| 13775 |
if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
| 13776 |
break; |
| 13777 |
mdelay(1); |
| 13778 |
} |
| 13779 |
|
| 13780 |
if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
| 13781 |
data[TG3_PHY_LOOPB_TEST] |= TG3_STD_LOOPBACK_FAILED; |
| 13782 |
if (tg3_flag(tp, TSO_CAPABLE) && |
| 13783 |
tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
| 13784 |
data[TG3_PHY_LOOPB_TEST] |= TG3_TSO_LOOPBACK_FAILED; |
| 13785 |
if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
| 13786 |
tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
| 13787 |
data[TG3_PHY_LOOPB_TEST] |= TG3_JMB_LOOPBACK_FAILED; |
| 13788 |
|
| 13789 |
if (do_extlpbk) { |
| 13790 |
tg3_phy_lpbk_set(tp, 0, true); |
| 13791 |
|
| 13792 |
/* All link indications report up, but the hardware |
| 13793 |
* isn't really ready for about 20 msec. Double it |
| 13794 |
* to be sure. |
| 13795 |
*/ |
| 13796 |
mdelay(40); |
| 13797 |
|
| 13798 |
if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
| 13799 |
data[TG3_EXT_LOOPB_TEST] |= |
| 13800 |
TG3_STD_LOOPBACK_FAILED; |
| 13801 |
if (tg3_flag(tp, TSO_CAPABLE) && |
| 13802 |
tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
| 13803 |
data[TG3_EXT_LOOPB_TEST] |= |
| 13804 |
TG3_TSO_LOOPBACK_FAILED; |
| 13805 |
if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
| 13806 |
tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
| 13807 |
data[TG3_EXT_LOOPB_TEST] |= |
| 13808 |
TG3_JMB_LOOPBACK_FAILED; |
| 13809 |
} |
| 13810 |
|
| 13811 |
/* Re-enable gphy autopowerdown. */ |
| 13812 |
if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
| 13813 |
tg3_phy_toggle_apd(tp, true); |
| 13814 |
} |
| 13815 |
|
| 13816 |
err = (data[TG3_MAC_LOOPB_TEST] | data[TG3_PHY_LOOPB_TEST] | |
| 13817 |
data[TG3_EXT_LOOPB_TEST]) ? -EIO : 0; |
| 13818 |
|
| 13819 |
done: |
| 13820 |
tp->phy_flags |= eee_cap; |
| 13821 |
|
| 13822 |
return err; |
| 13823 |
} |
| 13824 |
|
| 13825 |
static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
| 13826 |
u64 *data) |
| 13827 |
{ |
| 13828 |
struct tg3 *tp = netdev_priv(dev); |
| 13829 |
bool doextlpbk = etest->flags & ETH_TEST_FL_EXTERNAL_LB; |
| 13830 |
|
| 13831 |
if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
| 13832 |
if (tg3_power_up(tp)) { |
| 13833 |
etest->flags |= ETH_TEST_FL_FAILED; |
| 13834 |
memset(data, 1, sizeof(u64) * TG3_NUM_TEST); |
| 13835 |
return; |
| 13836 |
} |
| 13837 |
tg3_ape_driver_state_change(tp, RESET_KIND_INIT); |
| 13838 |
} |
| 13839 |
|
| 13840 |
memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
| 13841 |
|
| 13842 |
if (tg3_test_nvram(tp) != 0) { |
| 13843 |
etest->flags |= ETH_TEST_FL_FAILED; |
| 13844 |
data[TG3_NVRAM_TEST] = 1; |
| 13845 |
} |
| 13846 |
if (!doextlpbk && tg3_test_link(tp)) { |
| 13847 |
etest->flags |= ETH_TEST_FL_FAILED; |
| 13848 |
data[TG3_LINK_TEST] = 1; |
| 13849 |
} |
| 13850 |
if (etest->flags & ETH_TEST_FL_OFFLINE) { |
| 13851 |
int err, err2 = 0, irq_sync = 0; |
| 13852 |
|
| 13853 |
if (netif_running(dev)) { |
| 13854 |
tg3_phy_stop(tp); |
| 13855 |
tg3_netif_stop(tp); |
| 13856 |
irq_sync = 1; |
| 13857 |
} |
| 13858 |
|
| 13859 |
tg3_full_lock(tp, irq_sync); |
| 13860 |
tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
| 13861 |
err = tg3_nvram_lock(tp); |
| 13862 |
tg3_halt_cpu(tp, RX_CPU_BASE); |
| 13863 |
if (!tg3_flag(tp, 5705_PLUS)) |
| 13864 |
tg3_halt_cpu(tp, TX_CPU_BASE); |
| 13865 |
if (!err) |
| 13866 |
tg3_nvram_unlock(tp); |
| 13867 |
|
| 13868 |
if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
| 13869 |
tg3_phy_reset(tp); |
| 13870 |
|
| 13871 |
if (tg3_test_registers(tp) != 0) { |
| 13872 |
etest->flags |= ETH_TEST_FL_FAILED; |
| 13873 |
data[TG3_REGISTER_TEST] = 1; |
| 13874 |
} |
| 13875 |
|
| 13876 |
if (tg3_test_memory(tp) != 0) { |
| 13877 |
etest->flags |= ETH_TEST_FL_FAILED; |
| 13878 |
data[TG3_MEMORY_TEST] = 1; |
| 13879 |
} |
| 13880 |
|
| 13881 |
if (doextlpbk) |
| 13882 |
etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; |
| 13883 |
|
| 13884 |
if (tg3_test_loopback(tp, data, doextlpbk)) |
| 13885 |
etest->flags |= ETH_TEST_FL_FAILED; |
| 13886 |
|
| 13887 |
tg3_full_unlock(tp); |
| 13888 |
|
| 13889 |
if (tg3_test_interrupt(tp) != 0) { |
| 13890 |
etest->flags |= ETH_TEST_FL_FAILED; |
| 13891 |
data[TG3_INTERRUPT_TEST] = 1; |
| 13892 |
} |
| 13893 |
|
| 13894 |
netdev_lock(dev); |
| 13895 |
tg3_full_lock(tp, 0); |
| 13896 |
|
| 13897 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 13898 |
if (netif_running(dev)) { |
| 13899 |
tg3_flag_set(tp, INIT_COMPLETE); |
| 13900 |
err2 = tg3_restart_hw(tp, true); |
| 13901 |
if (!err2) |
| 13902 |
tg3_netif_start(tp); |
| 13903 |
} |
| 13904 |
|
| 13905 |
tg3_full_unlock(tp); |
| 13906 |
netdev_unlock(dev); |
| 13907 |
|
| 13908 |
if (irq_sync && !err2) |
| 13909 |
tg3_phy_start(tp); |
| 13910 |
} |
| 13911 |
if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
| 13912 |
tg3_power_down_prepare(tp); |
| 13913 |
|
| 13914 |
} |
| 13915 |
|
| 13916 |
static int tg3_hwtstamp_set(struct net_device *dev, |
| 13917 |
struct kernel_hwtstamp_config *stmpconf, |
| 13918 |
struct netlink_ext_ack *extack) |
| 13919 |
{ |
| 13920 |
struct tg3 *tp = netdev_priv(dev); |
| 13921 |
|
| 13922 |
if (!tg3_flag(tp, PTP_CAPABLE)) |
| 13923 |
return -EOPNOTSUPP; |
| 13924 |
|
| 13925 |
if (stmpconf->tx_type != HWTSTAMP_TX_ON && |
| 13926 |
stmpconf->tx_type != HWTSTAMP_TX_OFF) |
| 13927 |
return -ERANGE; |
| 13928 |
|
| 13929 |
switch (stmpconf->rx_filter) { |
| 13930 |
case HWTSTAMP_FILTER_NONE: |
| 13931 |
tp->rxptpctl = 0; |
| 13932 |
break; |
| 13933 |
case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 13934 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | |
| 13935 |
TG3_RX_PTP_CTL_ALL_V1_EVENTS; |
| 13936 |
break; |
| 13937 |
case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 13938 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | |
| 13939 |
TG3_RX_PTP_CTL_SYNC_EVNT; |
| 13940 |
break; |
| 13941 |
case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 13942 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | |
| 13943 |
TG3_RX_PTP_CTL_DELAY_REQ; |
| 13944 |
break; |
| 13945 |
case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 13946 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | |
| 13947 |
TG3_RX_PTP_CTL_ALL_V2_EVENTS; |
| 13948 |
break; |
| 13949 |
case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 13950 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | |
| 13951 |
TG3_RX_PTP_CTL_ALL_V2_EVENTS; |
| 13952 |
break; |
| 13953 |
case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 13954 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | |
| 13955 |
TG3_RX_PTP_CTL_ALL_V2_EVENTS; |
| 13956 |
break; |
| 13957 |
case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 13958 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | |
| 13959 |
TG3_RX_PTP_CTL_SYNC_EVNT; |
| 13960 |
break; |
| 13961 |
case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 13962 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | |
| 13963 |
TG3_RX_PTP_CTL_SYNC_EVNT; |
| 13964 |
break; |
| 13965 |
case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 13966 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | |
| 13967 |
TG3_RX_PTP_CTL_SYNC_EVNT; |
| 13968 |
break; |
| 13969 |
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 13970 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | |
| 13971 |
TG3_RX_PTP_CTL_DELAY_REQ; |
| 13972 |
break; |
| 13973 |
case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 13974 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | |
| 13975 |
TG3_RX_PTP_CTL_DELAY_REQ; |
| 13976 |
break; |
| 13977 |
case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 13978 |
tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | |
| 13979 |
TG3_RX_PTP_CTL_DELAY_REQ; |
| 13980 |
break; |
| 13981 |
default: |
| 13982 |
return -ERANGE; |
| 13983 |
} |
| 13984 |
|
| 13985 |
if (netif_running(dev) && tp->rxptpctl) |
| 13986 |
tw32(TG3_RX_PTP_CTL, |
| 13987 |
tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK); |
| 13988 |
|
| 13989 |
if (stmpconf->tx_type == HWTSTAMP_TX_ON) |
| 13990 |
tg3_flag_set(tp, TX_TSTAMP_EN); |
| 13991 |
else |
| 13992 |
tg3_flag_clear(tp, TX_TSTAMP_EN); |
| 13993 |
|
| 13994 |
return 0; |
| 13995 |
} |
| 13996 |
|
| 13997 |
static int tg3_hwtstamp_get(struct net_device *dev, |
| 13998 |
struct kernel_hwtstamp_config *stmpconf) |
| 13999 |
{ |
| 14000 |
struct tg3 *tp = netdev_priv(dev); |
| 14001 |
|
| 14002 |
if (!tg3_flag(tp, PTP_CAPABLE)) |
| 14003 |
return -EOPNOTSUPP; |
| 14004 |
|
| 14005 |
stmpconf->flags = 0; |
| 14006 |
stmpconf->tx_type = tg3_flag(tp, TX_TSTAMP_EN) ? |
| 14007 |
HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; |
| 14008 |
|
| 14009 |
switch (tp->rxptpctl) { |
| 14010 |
case 0: |
| 14011 |
stmpconf->rx_filter = HWTSTAMP_FILTER_NONE; |
| 14012 |
break; |
| 14013 |
case TG3_RX_PTP_CTL_RX_PTP_V1_EN | TG3_RX_PTP_CTL_ALL_V1_EVENTS: |
| 14014 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; |
| 14015 |
break; |
| 14016 |
case TG3_RX_PTP_CTL_RX_PTP_V1_EN | TG3_RX_PTP_CTL_SYNC_EVNT: |
| 14017 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC; |
| 14018 |
break; |
| 14019 |
case TG3_RX_PTP_CTL_RX_PTP_V1_EN | TG3_RX_PTP_CTL_DELAY_REQ: |
| 14020 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ; |
| 14021 |
break; |
| 14022 |
case TG3_RX_PTP_CTL_RX_PTP_V2_EN | TG3_RX_PTP_CTL_ALL_V2_EVENTS: |
| 14023 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 14024 |
break; |
| 14025 |
case TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | TG3_RX_PTP_CTL_ALL_V2_EVENTS: |
| 14026 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; |
| 14027 |
break; |
| 14028 |
case TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | TG3_RX_PTP_CTL_ALL_V2_EVENTS: |
| 14029 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT; |
| 14030 |
break; |
| 14031 |
case TG3_RX_PTP_CTL_RX_PTP_V2_EN | TG3_RX_PTP_CTL_SYNC_EVNT: |
| 14032 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC; |
| 14033 |
break; |
| 14034 |
case TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | TG3_RX_PTP_CTL_SYNC_EVNT: |
| 14035 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_SYNC; |
| 14036 |
break; |
| 14037 |
case TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | TG3_RX_PTP_CTL_SYNC_EVNT: |
| 14038 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_SYNC; |
| 14039 |
break; |
| 14040 |
case TG3_RX_PTP_CTL_RX_PTP_V2_EN | TG3_RX_PTP_CTL_DELAY_REQ: |
| 14041 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ; |
| 14042 |
break; |
| 14043 |
case TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | TG3_RX_PTP_CTL_DELAY_REQ: |
| 14044 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ; |
| 14045 |
break; |
| 14046 |
case TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | TG3_RX_PTP_CTL_DELAY_REQ: |
| 14047 |
stmpconf->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ; |
| 14048 |
break; |
| 14049 |
default: |
| 14050 |
WARN_ON_ONCE(1); |
| 14051 |
return -ERANGE; |
| 14052 |
} |
| 14053 |
|
| 14054 |
return 0; |
| 14055 |
} |
| 14056 |
|
| 14057 |
static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 14058 |
{ |
| 14059 |
struct mii_ioctl_data *data = if_mii(ifr); |
| 14060 |
struct tg3 *tp = netdev_priv(dev); |
| 14061 |
int err; |
| 14062 |
|
| 14063 |
if (tg3_flag(tp, USE_PHYLIB)) { |
| 14064 |
struct phy_device *phydev; |
| 14065 |
if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
| 14066 |
return -EAGAIN; |
| 14067 |
phydev = mdiobus_get_phy(tp->mdio_bus, tp->phy_addr); |
| 14068 |
return phy_mii_ioctl(phydev, ifr, cmd); |
| 14069 |
} |
| 14070 |
|
| 14071 |
switch (cmd) { |
| 14072 |
case SIOCGMIIPHY: |
| 14073 |
data->phy_id = tp->phy_addr; |
| 14074 |
|
| 14075 |
fallthrough; |
| 14076 |
case SIOCGMIIREG: { |
| 14077 |
u32 mii_regval; |
| 14078 |
|
| 14079 |
if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
| 14080 |
break; /* We have no PHY */ |
| 14081 |
|
| 14082 |
if (!netif_running(dev)) |
| 14083 |
return -EAGAIN; |
| 14084 |
|
| 14085 |
spin_lock_bh(&tp->lock); |
| 14086 |
err = __tg3_readphy(tp, data->phy_id & 0x1f, |
| 14087 |
data->reg_num & 0x1f, &mii_regval); |
| 14088 |
spin_unlock_bh(&tp->lock); |
| 14089 |
|
| 14090 |
data->val_out = mii_regval; |
| 14091 |
|
| 14092 |
return err; |
| 14093 |
} |
| 14094 |
|
| 14095 |
case SIOCSMIIREG: |
| 14096 |
if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
| 14097 |
break; /* We have no PHY */ |
| 14098 |
|
| 14099 |
if (!netif_running(dev)) |
| 14100 |
return -EAGAIN; |
| 14101 |
|
| 14102 |
spin_lock_bh(&tp->lock); |
| 14103 |
err = __tg3_writephy(tp, data->phy_id & 0x1f, |
| 14104 |
data->reg_num & 0x1f, data->val_in); |
| 14105 |
spin_unlock_bh(&tp->lock); |
| 14106 |
|
| 14107 |
return err; |
| 14108 |
|
| 14109 |
default: |
| 14110 |
/* do nothing */ |
| 14111 |
break; |
| 14112 |
} |
| 14113 |
return -EOPNOTSUPP; |
| 14114 |
} |
| 14115 |
|
| 14116 |
static int tg3_get_coalesce(struct net_device *dev, |
| 14117 |
struct ethtool_coalesce *ec, |
| 14118 |
struct kernel_ethtool_coalesce *kernel_coal, |
| 14119 |
struct netlink_ext_ack *extack) |
| 14120 |
{ |
| 14121 |
struct tg3 *tp = netdev_priv(dev); |
| 14122 |
|
| 14123 |
memcpy(ec, &tp->coal, sizeof(*ec)); |
| 14124 |
return 0; |
| 14125 |
} |
| 14126 |
|
| 14127 |
static int tg3_set_coalesce(struct net_device *dev, |
| 14128 |
struct ethtool_coalesce *ec, |
| 14129 |
struct kernel_ethtool_coalesce *kernel_coal, |
| 14130 |
struct netlink_ext_ack *extack) |
| 14131 |
{ |
| 14132 |
struct tg3 *tp = netdev_priv(dev); |
| 14133 |
u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; |
| 14134 |
u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; |
| 14135 |
|
| 14136 |
if (!tg3_flag(tp, 5705_PLUS)) { |
| 14137 |
max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
| 14138 |
max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; |
| 14139 |
max_stat_coal_ticks = MAX_STAT_COAL_TICKS; |
| 14140 |
min_stat_coal_ticks = MIN_STAT_COAL_TICKS; |
| 14141 |
} |
| 14142 |
|
| 14143 |
if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || |
| 14144 |
(!ec->rx_coalesce_usecs) || |
| 14145 |
(ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || |
| 14146 |
(!ec->tx_coalesce_usecs) || |
| 14147 |
(ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || |
| 14148 |
(ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || |
| 14149 |
(ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || |
| 14150 |
(ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || |
| 14151 |
(ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || |
| 14152 |
(ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || |
| 14153 |
(ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || |
| 14154 |
(ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) |
| 14155 |
return -EINVAL; |
| 14156 |
|
| 14157 |
/* Only copy relevant parameters, ignore all others. */ |
| 14158 |
tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; |
| 14159 |
tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; |
| 14160 |
tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; |
| 14161 |
tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; |
| 14162 |
tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; |
| 14163 |
tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; |
| 14164 |
tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; |
| 14165 |
tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; |
| 14166 |
tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; |
| 14167 |
|
| 14168 |
if (netif_running(dev)) { |
| 14169 |
tg3_full_lock(tp, 0); |
| 14170 |
__tg3_set_coalesce(tp, &tp->coal); |
| 14171 |
tg3_full_unlock(tp); |
| 14172 |
} |
| 14173 |
return 0; |
| 14174 |
} |
| 14175 |
|
| 14176 |
static int tg3_set_eee(struct net_device *dev, struct ethtool_keee *edata) |
| 14177 |
{ |
| 14178 |
struct tg3 *tp = netdev_priv(dev); |
| 14179 |
|
| 14180 |
if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) { |
| 14181 |
netdev_warn(tp->dev, "Board does not support EEE!\n"); |
| 14182 |
return -EOPNOTSUPP; |
| 14183 |
} |
| 14184 |
|
| 14185 |
if (!linkmode_equal(edata->advertised, tp->eee.advertised)) { |
| 14186 |
netdev_warn(tp->dev, |
| 14187 |
"Direct manipulation of EEE advertisement is not supported\n"); |
| 14188 |
return -EINVAL; |
| 14189 |
} |
| 14190 |
|
| 14191 |
if (edata->tx_lpi_timer > TG3_CPMU_DBTMR1_LNKIDLE_MAX) { |
| 14192 |
netdev_warn(tp->dev, |
| 14193 |
"Maximal Tx Lpi timer supported is %#x(u)\n", |
| 14194 |
TG3_CPMU_DBTMR1_LNKIDLE_MAX); |
| 14195 |
return -EINVAL; |
| 14196 |
} |
| 14197 |
|
| 14198 |
tp->eee.eee_enabled = edata->eee_enabled; |
| 14199 |
tp->eee.tx_lpi_enabled = edata->tx_lpi_enabled; |
| 14200 |
tp->eee.tx_lpi_timer = edata->tx_lpi_timer; |
| 14201 |
|
| 14202 |
tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; |
| 14203 |
tg3_warn_mgmt_link_flap(tp); |
| 14204 |
|
| 14205 |
if (netif_running(tp->dev)) { |
| 14206 |
tg3_full_lock(tp, 0); |
| 14207 |
tg3_setup_eee(tp); |
| 14208 |
tg3_phy_reset(tp); |
| 14209 |
tg3_full_unlock(tp); |
| 14210 |
} |
| 14211 |
|
| 14212 |
return 0; |
| 14213 |
} |
| 14214 |
|
| 14215 |
static int tg3_get_eee(struct net_device *dev, struct ethtool_keee *edata) |
| 14216 |
{ |
| 14217 |
struct tg3 *tp = netdev_priv(dev); |
| 14218 |
|
| 14219 |
if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) { |
| 14220 |
netdev_warn(tp->dev, |
| 14221 |
"Board does not support EEE!\n"); |
| 14222 |
return -EOPNOTSUPP; |
| 14223 |
} |
| 14224 |
|
| 14225 |
*edata = tp->eee; |
| 14226 |
return 0; |
| 14227 |
} |
| 14228 |
|
| 14229 |
static const struct ethtool_ops tg3_ethtool_ops = { |
| 14230 |
.supported_coalesce_params = ETHTOOL_COALESCE_USECS | |
| 14231 |
ETHTOOL_COALESCE_MAX_FRAMES | |
| 14232 |
ETHTOOL_COALESCE_USECS_IRQ | |
| 14233 |
ETHTOOL_COALESCE_MAX_FRAMES_IRQ | |
| 14234 |
ETHTOOL_COALESCE_STATS_BLOCK_USECS, |
| 14235 |
.get_drvinfo = tg3_get_drvinfo, |
| 14236 |
.get_regs_len = tg3_get_regs_len, |
| 14237 |
.get_regs = tg3_get_regs, |
| 14238 |
.get_wol = tg3_get_wol, |
| 14239 |
.set_wol = tg3_set_wol, |
| 14240 |
.get_msglevel = tg3_get_msglevel, |
| 14241 |
.set_msglevel = tg3_set_msglevel, |
| 14242 |
.nway_reset = tg3_nway_reset, |
| 14243 |
.get_link = ethtool_op_get_link, |
| 14244 |
.get_eeprom_len = tg3_get_eeprom_len, |
| 14245 |
.get_eeprom = tg3_get_eeprom, |
| 14246 |
.set_eeprom = tg3_set_eeprom, |
| 14247 |
.get_ringparam = tg3_get_ringparam, |
| 14248 |
.set_ringparam = tg3_set_ringparam, |
| 14249 |
.get_pauseparam = tg3_get_pauseparam, |
| 14250 |
.set_pauseparam = tg3_set_pauseparam, |
| 14251 |
.self_test = tg3_self_test, |
| 14252 |
.get_strings = tg3_get_strings, |
| 14253 |
.set_phys_id = tg3_set_phys_id, |
| 14254 |
.get_ethtool_stats = tg3_get_ethtool_stats, |
| 14255 |
.get_coalesce = tg3_get_coalesce, |
| 14256 |
.set_coalesce = tg3_set_coalesce, |
| 14257 |
.get_sset_count = tg3_get_sset_count, |
| 14258 |
.get_rx_ring_count = tg3_get_rx_ring_count, |
| 14259 |
.get_rxfh_indir_size = tg3_get_rxfh_indir_size, |
| 14260 |
.get_rxfh = tg3_get_rxfh, |
| 14261 |
.set_rxfh = tg3_set_rxfh, |
| 14262 |
.get_channels = tg3_get_channels, |
| 14263 |
.set_channels = tg3_set_channels, |
| 14264 |
.get_ts_info = tg3_get_ts_info, |
| 14265 |
.get_eee = tg3_get_eee, |
| 14266 |
.set_eee = tg3_set_eee, |
| 14267 |
.get_link_ksettings = tg3_get_link_ksettings, |
| 14268 |
.set_link_ksettings = tg3_set_link_ksettings, |
| 14269 |
}; |
| 14270 |
|
| 14271 |
static void tg3_get_stats64(struct net_device *dev, |
| 14272 |
struct rtnl_link_stats64 *stats) |
| 14273 |
{ |
| 14274 |
struct tg3 *tp = netdev_priv(dev); |
| 14275 |
|
| 14276 |
spin_lock_bh(&tp->lock); |
| 14277 |
if (!tp->hw_stats || !tg3_flag(tp, INIT_COMPLETE)) { |
| 14278 |
*stats = tp->net_stats_prev; |
| 14279 |
spin_unlock_bh(&tp->lock); |
| 14280 |
return; |
| 14281 |
} |
| 14282 |
|
| 14283 |
tg3_get_nstats(tp, stats); |
| 14284 |
spin_unlock_bh(&tp->lock); |
| 14285 |
} |
| 14286 |
|
| 14287 |
static void tg3_set_rx_mode(struct net_device *dev) |
| 14288 |
{ |
| 14289 |
struct tg3 *tp = netdev_priv(dev); |
| 14290 |
|
| 14291 |
if (!netif_running(dev)) |
| 14292 |
return; |
| 14293 |
|
| 14294 |
tg3_full_lock(tp, 0); |
| 14295 |
__tg3_set_rx_mode(dev); |
| 14296 |
tg3_full_unlock(tp); |
| 14297 |
} |
| 14298 |
|
| 14299 |
static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
| 14300 |
int new_mtu) |
| 14301 |
{ |
| 14302 |
WRITE_ONCE(dev->mtu, new_mtu); |
| 14303 |
|
| 14304 |
if (new_mtu > ETH_DATA_LEN) { |
| 14305 |
if (tg3_flag(tp, 5780_CLASS)) { |
| 14306 |
netdev_update_features(dev); |
| 14307 |
tg3_flag_clear(tp, TSO_CAPABLE); |
| 14308 |
} else { |
| 14309 |
tg3_flag_set(tp, JUMBO_RING_ENABLE); |
| 14310 |
} |
| 14311 |
} else { |
| 14312 |
if (tg3_flag(tp, 5780_CLASS)) { |
| 14313 |
tg3_flag_set(tp, TSO_CAPABLE); |
| 14314 |
netdev_update_features(dev); |
| 14315 |
} |
| 14316 |
tg3_flag_clear(tp, JUMBO_RING_ENABLE); |
| 14317 |
} |
| 14318 |
} |
| 14319 |
|
| 14320 |
static int tg3_change_mtu(struct net_device *dev, int new_mtu) |
| 14321 |
{ |
| 14322 |
struct tg3 *tp = netdev_priv(dev); |
| 14323 |
int err; |
| 14324 |
bool reset_phy = false; |
| 14325 |
|
| 14326 |
if (!netif_running(dev)) { |
| 14327 |
/* We'll just catch it later when the |
| 14328 |
* device is up'd. |
| 14329 |
*/ |
| 14330 |
tg3_set_mtu(dev, tp, new_mtu); |
| 14331 |
return 0; |
| 14332 |
} |
| 14333 |
|
| 14334 |
tg3_phy_stop(tp); |
| 14335 |
|
| 14336 |
tg3_netif_stop(tp); |
| 14337 |
|
| 14338 |
tg3_set_mtu(dev, tp, new_mtu); |
| 14339 |
|
| 14340 |
netdev_lock(dev); |
| 14341 |
tg3_full_lock(tp, 1); |
| 14342 |
|
| 14343 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 14344 |
|
| 14345 |
/* Reset PHY, otherwise the read DMA engine will be in a mode that |
| 14346 |
* breaks all requests to 256 bytes. |
| 14347 |
*/ |
| 14348 |
if (tg3_asic_rev(tp) == ASIC_REV_57766 || |
| 14349 |
tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 14350 |
tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 14351 |
tg3_asic_rev(tp) == ASIC_REV_5720) |
| 14352 |
reset_phy = true; |
| 14353 |
|
| 14354 |
err = tg3_restart_hw(tp, reset_phy); |
| 14355 |
|
| 14356 |
if (!err) |
| 14357 |
tg3_netif_start(tp); |
| 14358 |
|
| 14359 |
tg3_full_unlock(tp); |
| 14360 |
netdev_unlock(dev); |
| 14361 |
|
| 14362 |
if (!err) |
| 14363 |
tg3_phy_start(tp); |
| 14364 |
|
| 14365 |
return err; |
| 14366 |
} |
| 14367 |
|
| 14368 |
static const struct net_device_ops tg3_netdev_ops = { |
| 14369 |
.ndo_open = tg3_open, |
| 14370 |
.ndo_stop = tg3_close, |
| 14371 |
.ndo_start_xmit = tg3_start_xmit, |
| 14372 |
.ndo_get_stats64 = tg3_get_stats64, |
| 14373 |
.ndo_validate_addr = eth_validate_addr, |
| 14374 |
.ndo_set_rx_mode = tg3_set_rx_mode, |
| 14375 |
.ndo_set_mac_address = tg3_set_mac_addr, |
| 14376 |
.ndo_eth_ioctl = tg3_ioctl, |
| 14377 |
.ndo_tx_timeout = tg3_tx_timeout, |
| 14378 |
.ndo_change_mtu = tg3_change_mtu, |
| 14379 |
.ndo_fix_features = tg3_fix_features, |
| 14380 |
.ndo_set_features = tg3_set_features, |
| 14381 |
#ifdef CONFIG_NET_POLL_CONTROLLER |
| 14382 |
.ndo_poll_controller = tg3_poll_controller, |
| 14383 |
#endif |
| 14384 |
.ndo_hwtstamp_get = tg3_hwtstamp_get, |
| 14385 |
.ndo_hwtstamp_set = tg3_hwtstamp_set, |
| 14386 |
}; |
| 14387 |
|
| 14388 |
static void tg3_get_eeprom_size(struct tg3 *tp) |
| 14389 |
{ |
| 14390 |
u32 cursize, val, magic; |
| 14391 |
|
| 14392 |
tp->nvram_size = EEPROM_CHIP_SIZE; |
| 14393 |
|
| 14394 |
if (tg3_nvram_read(tp, 0, &magic) != 0) |
| 14395 |
return; |
| 14396 |
|
| 14397 |
if ((magic != TG3_EEPROM_MAGIC) && |
| 14398 |
((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && |
| 14399 |
((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) |
| 14400 |
return; |
| 14401 |
|
| 14402 |
/* |
| 14403 |
* Size the chip by reading offsets at increasing powers of two. |
| 14404 |
* When we encounter our validation signature, we know the addressing |
| 14405 |
* has wrapped around, and thus have our chip size. |
| 14406 |
*/ |
| 14407 |
cursize = 0x10; |
| 14408 |
|
| 14409 |
while (cursize < tp->nvram_size) { |
| 14410 |
if (tg3_nvram_read(tp, cursize, &val) != 0) |
| 14411 |
return; |
| 14412 |
|
| 14413 |
if (val == magic) |
| 14414 |
break; |
| 14415 |
|
| 14416 |
cursize <<= 1; |
| 14417 |
} |
| 14418 |
|
| 14419 |
tp->nvram_size = cursize; |
| 14420 |
} |
| 14421 |
|
| 14422 |
static void tg3_get_nvram_size(struct tg3 *tp) |
| 14423 |
{ |
| 14424 |
u32 val; |
| 14425 |
|
| 14426 |
if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &val) != 0) |
| 14427 |
return; |
| 14428 |
|
| 14429 |
/* Selfboot format */ |
| 14430 |
if (val != TG3_EEPROM_MAGIC) { |
| 14431 |
tg3_get_eeprom_size(tp); |
| 14432 |
return; |
| 14433 |
} |
| 14434 |
|
| 14435 |
if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
| 14436 |
if (val != 0) { |
| 14437 |
/* This is confusing. We want to operate on the |
| 14438 |
* 16-bit value at offset 0xf2. The tg3_nvram_read() |
| 14439 |
* call will read from NVRAM and byteswap the data |
| 14440 |
* according to the byteswapping settings for all |
| 14441 |
* other register accesses. This ensures the data we |
| 14442 |
* want will always reside in the lower 16-bits. |
| 14443 |
* However, the data in NVRAM is in LE format, which |
| 14444 |
* means the data from the NVRAM read will always be |
| 14445 |
* opposite the endianness of the CPU. The 16-bit |
| 14446 |
* byteswap then brings the data to CPU endianness. |
| 14447 |
*/ |
| 14448 |
tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; |
| 14449 |
return; |
| 14450 |
} |
| 14451 |
} |
| 14452 |
tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 14453 |
} |
| 14454 |
|
| 14455 |
static void tg3_get_nvram_info(struct tg3 *tp) |
| 14456 |
{ |
| 14457 |
u32 nvcfg1; |
| 14458 |
|
| 14459 |
nvcfg1 = tr32(NVRAM_CFG1); |
| 14460 |
if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { |
| 14461 |
tg3_flag_set(tp, FLASH); |
| 14462 |
} else { |
| 14463 |
nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14464 |
tw32(NVRAM_CFG1, nvcfg1); |
| 14465 |
} |
| 14466 |
|
| 14467 |
if (tg3_asic_rev(tp) == ASIC_REV_5750 || |
| 14468 |
tg3_flag(tp, 5780_CLASS)) { |
| 14469 |
switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
| 14470 |
case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
| 14471 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14472 |
tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
| 14473 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14474 |
break; |
| 14475 |
case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: |
| 14476 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14477 |
tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; |
| 14478 |
break; |
| 14479 |
case FLASH_VENDOR_ATMEL_EEPROM: |
| 14480 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14481 |
tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14482 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14483 |
break; |
| 14484 |
case FLASH_VENDOR_ST: |
| 14485 |
tp->nvram_jedecnum = JEDEC_ST; |
| 14486 |
tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; |
| 14487 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14488 |
break; |
| 14489 |
case FLASH_VENDOR_SAIFUN: |
| 14490 |
tp->nvram_jedecnum = JEDEC_SAIFUN; |
| 14491 |
tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; |
| 14492 |
break; |
| 14493 |
case FLASH_VENDOR_SST_SMALL: |
| 14494 |
case FLASH_VENDOR_SST_LARGE: |
| 14495 |
tp->nvram_jedecnum = JEDEC_SST; |
| 14496 |
tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; |
| 14497 |
break; |
| 14498 |
} |
| 14499 |
} else { |
| 14500 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14501 |
tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; |
| 14502 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14503 |
} |
| 14504 |
} |
| 14505 |
|
| 14506 |
static void tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
| 14507 |
{ |
| 14508 |
switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { |
| 14509 |
case FLASH_5752PAGE_SIZE_256: |
| 14510 |
tp->nvram_pagesize = 256; |
| 14511 |
break; |
| 14512 |
case FLASH_5752PAGE_SIZE_512: |
| 14513 |
tp->nvram_pagesize = 512; |
| 14514 |
break; |
| 14515 |
case FLASH_5752PAGE_SIZE_1K: |
| 14516 |
tp->nvram_pagesize = 1024; |
| 14517 |
break; |
| 14518 |
case FLASH_5752PAGE_SIZE_2K: |
| 14519 |
tp->nvram_pagesize = 2048; |
| 14520 |
break; |
| 14521 |
case FLASH_5752PAGE_SIZE_4K: |
| 14522 |
tp->nvram_pagesize = 4096; |
| 14523 |
break; |
| 14524 |
case FLASH_5752PAGE_SIZE_264: |
| 14525 |
tp->nvram_pagesize = 264; |
| 14526 |
break; |
| 14527 |
case FLASH_5752PAGE_SIZE_528: |
| 14528 |
tp->nvram_pagesize = 528; |
| 14529 |
break; |
| 14530 |
} |
| 14531 |
} |
| 14532 |
|
| 14533 |
static void tg3_get_5752_nvram_info(struct tg3 *tp) |
| 14534 |
{ |
| 14535 |
u32 nvcfg1; |
| 14536 |
|
| 14537 |
nvcfg1 = tr32(NVRAM_CFG1); |
| 14538 |
|
| 14539 |
/* NVRAM protection for TPM */ |
| 14540 |
if (nvcfg1 & (1 << 27)) |
| 14541 |
tg3_flag_set(tp, PROTECTED_NVRAM); |
| 14542 |
|
| 14543 |
switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14544 |
case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
| 14545 |
case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: |
| 14546 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14547 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14548 |
break; |
| 14549 |
case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 14550 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14551 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14552 |
tg3_flag_set(tp, FLASH); |
| 14553 |
break; |
| 14554 |
case FLASH_5752VENDOR_ST_M45PE10: |
| 14555 |
case FLASH_5752VENDOR_ST_M45PE20: |
| 14556 |
case FLASH_5752VENDOR_ST_M45PE40: |
| 14557 |
tp->nvram_jedecnum = JEDEC_ST; |
| 14558 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14559 |
tg3_flag_set(tp, FLASH); |
| 14560 |
break; |
| 14561 |
} |
| 14562 |
|
| 14563 |
if (tg3_flag(tp, FLASH)) { |
| 14564 |
tg3_nvram_get_pagesize(tp, nvcfg1); |
| 14565 |
} else { |
| 14566 |
/* For eeprom, set pagesize to maximum eeprom size */ |
| 14567 |
tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14568 |
|
| 14569 |
nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14570 |
tw32(NVRAM_CFG1, nvcfg1); |
| 14571 |
} |
| 14572 |
} |
| 14573 |
|
| 14574 |
static void tg3_get_5755_nvram_info(struct tg3 *tp) |
| 14575 |
{ |
| 14576 |
u32 nvcfg1, protect = 0; |
| 14577 |
|
| 14578 |
nvcfg1 = tr32(NVRAM_CFG1); |
| 14579 |
|
| 14580 |
/* NVRAM protection for TPM */ |
| 14581 |
if (nvcfg1 & (1 << 27)) { |
| 14582 |
tg3_flag_set(tp, PROTECTED_NVRAM); |
| 14583 |
protect = 1; |
| 14584 |
} |
| 14585 |
|
| 14586 |
nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 14587 |
switch (nvcfg1) { |
| 14588 |
case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 14589 |
case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 14590 |
case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 14591 |
case FLASH_5755VENDOR_ATMEL_FLASH_5: |
| 14592 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14593 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14594 |
tg3_flag_set(tp, FLASH); |
| 14595 |
tp->nvram_pagesize = 264; |
| 14596 |
if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || |
| 14597 |
nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) |
| 14598 |
tp->nvram_size = (protect ? 0x3e200 : |
| 14599 |
TG3_NVRAM_SIZE_512KB); |
| 14600 |
else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) |
| 14601 |
tp->nvram_size = (protect ? 0x1f200 : |
| 14602 |
TG3_NVRAM_SIZE_256KB); |
| 14603 |
else |
| 14604 |
tp->nvram_size = (protect ? 0x1f200 : |
| 14605 |
TG3_NVRAM_SIZE_128KB); |
| 14606 |
break; |
| 14607 |
case FLASH_5752VENDOR_ST_M45PE10: |
| 14608 |
case FLASH_5752VENDOR_ST_M45PE20: |
| 14609 |
case FLASH_5752VENDOR_ST_M45PE40: |
| 14610 |
tp->nvram_jedecnum = JEDEC_ST; |
| 14611 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14612 |
tg3_flag_set(tp, FLASH); |
| 14613 |
tp->nvram_pagesize = 256; |
| 14614 |
if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) |
| 14615 |
tp->nvram_size = (protect ? |
| 14616 |
TG3_NVRAM_SIZE_64KB : |
| 14617 |
TG3_NVRAM_SIZE_128KB); |
| 14618 |
else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) |
| 14619 |
tp->nvram_size = (protect ? |
| 14620 |
TG3_NVRAM_SIZE_64KB : |
| 14621 |
TG3_NVRAM_SIZE_256KB); |
| 14622 |
else |
| 14623 |
tp->nvram_size = (protect ? |
| 14624 |
TG3_NVRAM_SIZE_128KB : |
| 14625 |
TG3_NVRAM_SIZE_512KB); |
| 14626 |
break; |
| 14627 |
} |
| 14628 |
} |
| 14629 |
|
| 14630 |
static void tg3_get_5787_nvram_info(struct tg3 *tp) |
| 14631 |
{ |
| 14632 |
u32 nvcfg1; |
| 14633 |
|
| 14634 |
nvcfg1 = tr32(NVRAM_CFG1); |
| 14635 |
|
| 14636 |
switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14637 |
case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
| 14638 |
case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 14639 |
case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: |
| 14640 |
case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 14641 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14642 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14643 |
tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14644 |
|
| 14645 |
nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14646 |
tw32(NVRAM_CFG1, nvcfg1); |
| 14647 |
break; |
| 14648 |
case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 14649 |
case FLASH_5755VENDOR_ATMEL_FLASH_1: |
| 14650 |
case FLASH_5755VENDOR_ATMEL_FLASH_2: |
| 14651 |
case FLASH_5755VENDOR_ATMEL_FLASH_3: |
| 14652 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14653 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14654 |
tg3_flag_set(tp, FLASH); |
| 14655 |
tp->nvram_pagesize = 264; |
| 14656 |
break; |
| 14657 |
case FLASH_5752VENDOR_ST_M45PE10: |
| 14658 |
case FLASH_5752VENDOR_ST_M45PE20: |
| 14659 |
case FLASH_5752VENDOR_ST_M45PE40: |
| 14660 |
tp->nvram_jedecnum = JEDEC_ST; |
| 14661 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14662 |
tg3_flag_set(tp, FLASH); |
| 14663 |
tp->nvram_pagesize = 256; |
| 14664 |
break; |
| 14665 |
} |
| 14666 |
} |
| 14667 |
|
| 14668 |
static void tg3_get_5761_nvram_info(struct tg3 *tp) |
| 14669 |
{ |
| 14670 |
u32 nvcfg1, protect = 0; |
| 14671 |
|
| 14672 |
nvcfg1 = tr32(NVRAM_CFG1); |
| 14673 |
|
| 14674 |
/* NVRAM protection for TPM */ |
| 14675 |
if (nvcfg1 & (1 << 27)) { |
| 14676 |
tg3_flag_set(tp, PROTECTED_NVRAM); |
| 14677 |
protect = 1; |
| 14678 |
} |
| 14679 |
|
| 14680 |
nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
| 14681 |
switch (nvcfg1) { |
| 14682 |
case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 14683 |
case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 14684 |
case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 14685 |
case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 14686 |
case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 14687 |
case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 14688 |
case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 14689 |
case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 14690 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14691 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14692 |
tg3_flag_set(tp, FLASH); |
| 14693 |
tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
| 14694 |
tp->nvram_pagesize = 256; |
| 14695 |
break; |
| 14696 |
case FLASH_5761VENDOR_ST_A_M45PE20: |
| 14697 |
case FLASH_5761VENDOR_ST_A_M45PE40: |
| 14698 |
case FLASH_5761VENDOR_ST_A_M45PE80: |
| 14699 |
case FLASH_5761VENDOR_ST_A_M45PE16: |
| 14700 |
case FLASH_5761VENDOR_ST_M_M45PE20: |
| 14701 |
case FLASH_5761VENDOR_ST_M_M45PE40: |
| 14702 |
case FLASH_5761VENDOR_ST_M_M45PE80: |
| 14703 |
case FLASH_5761VENDOR_ST_M_M45PE16: |
| 14704 |
tp->nvram_jedecnum = JEDEC_ST; |
| 14705 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14706 |
tg3_flag_set(tp, FLASH); |
| 14707 |
tp->nvram_pagesize = 256; |
| 14708 |
break; |
| 14709 |
} |
| 14710 |
|
| 14711 |
if (protect) { |
| 14712 |
tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); |
| 14713 |
} else { |
| 14714 |
switch (nvcfg1) { |
| 14715 |
case FLASH_5761VENDOR_ATMEL_ADB161D: |
| 14716 |
case FLASH_5761VENDOR_ATMEL_MDB161D: |
| 14717 |
case FLASH_5761VENDOR_ST_A_M45PE16: |
| 14718 |
case FLASH_5761VENDOR_ST_M_M45PE16: |
| 14719 |
tp->nvram_size = TG3_NVRAM_SIZE_2MB; |
| 14720 |
break; |
| 14721 |
case FLASH_5761VENDOR_ATMEL_ADB081D: |
| 14722 |
case FLASH_5761VENDOR_ATMEL_MDB081D: |
| 14723 |
case FLASH_5761VENDOR_ST_A_M45PE80: |
| 14724 |
case FLASH_5761VENDOR_ST_M_M45PE80: |
| 14725 |
tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 14726 |
break; |
| 14727 |
case FLASH_5761VENDOR_ATMEL_ADB041D: |
| 14728 |
case FLASH_5761VENDOR_ATMEL_MDB041D: |
| 14729 |
case FLASH_5761VENDOR_ST_A_M45PE40: |
| 14730 |
case FLASH_5761VENDOR_ST_M_M45PE40: |
| 14731 |
tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 14732 |
break; |
| 14733 |
case FLASH_5761VENDOR_ATMEL_ADB021D: |
| 14734 |
case FLASH_5761VENDOR_ATMEL_MDB021D: |
| 14735 |
case FLASH_5761VENDOR_ST_A_M45PE20: |
| 14736 |
case FLASH_5761VENDOR_ST_M_M45PE20: |
| 14737 |
tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14738 |
break; |
| 14739 |
} |
| 14740 |
} |
| 14741 |
} |
| 14742 |
|
| 14743 |
static void tg3_get_5906_nvram_info(struct tg3 *tp) |
| 14744 |
{ |
| 14745 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14746 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14747 |
tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14748 |
} |
| 14749 |
|
| 14750 |
static void tg3_get_57780_nvram_info(struct tg3 *tp) |
| 14751 |
{ |
| 14752 |
u32 nvcfg1; |
| 14753 |
|
| 14754 |
nvcfg1 = tr32(NVRAM_CFG1); |
| 14755 |
|
| 14756 |
switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14757 |
case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: |
| 14758 |
case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: |
| 14759 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14760 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14761 |
tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14762 |
|
| 14763 |
nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14764 |
tw32(NVRAM_CFG1, nvcfg1); |
| 14765 |
return; |
| 14766 |
case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 14767 |
case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 14768 |
case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 14769 |
case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 14770 |
case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 14771 |
case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 14772 |
case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 14773 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14774 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14775 |
tg3_flag_set(tp, FLASH); |
| 14776 |
|
| 14777 |
switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14778 |
case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: |
| 14779 |
case FLASH_57780VENDOR_ATMEL_AT45DB011D: |
| 14780 |
case FLASH_57780VENDOR_ATMEL_AT45DB011B: |
| 14781 |
tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 14782 |
break; |
| 14783 |
case FLASH_57780VENDOR_ATMEL_AT45DB021D: |
| 14784 |
case FLASH_57780VENDOR_ATMEL_AT45DB021B: |
| 14785 |
tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14786 |
break; |
| 14787 |
case FLASH_57780VENDOR_ATMEL_AT45DB041D: |
| 14788 |
case FLASH_57780VENDOR_ATMEL_AT45DB041B: |
| 14789 |
tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 14790 |
break; |
| 14791 |
} |
| 14792 |
break; |
| 14793 |
case FLASH_5752VENDOR_ST_M45PE10: |
| 14794 |
case FLASH_5752VENDOR_ST_M45PE20: |
| 14795 |
case FLASH_5752VENDOR_ST_M45PE40: |
| 14796 |
tp->nvram_jedecnum = JEDEC_ST; |
| 14797 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14798 |
tg3_flag_set(tp, FLASH); |
| 14799 |
|
| 14800 |
switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14801 |
case FLASH_5752VENDOR_ST_M45PE10: |
| 14802 |
tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 14803 |
break; |
| 14804 |
case FLASH_5752VENDOR_ST_M45PE20: |
| 14805 |
tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14806 |
break; |
| 14807 |
case FLASH_5752VENDOR_ST_M45PE40: |
| 14808 |
tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 14809 |
break; |
| 14810 |
} |
| 14811 |
break; |
| 14812 |
default: |
| 14813 |
tg3_flag_set(tp, NO_NVRAM); |
| 14814 |
return; |
| 14815 |
} |
| 14816 |
|
| 14817 |
tg3_nvram_get_pagesize(tp, nvcfg1); |
| 14818 |
if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
| 14819 |
tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
| 14820 |
} |
| 14821 |
|
| 14822 |
|
| 14823 |
static void tg3_get_5717_nvram_info(struct tg3 *tp) |
| 14824 |
{ |
| 14825 |
u32 nvcfg1; |
| 14826 |
|
| 14827 |
nvcfg1 = tr32(NVRAM_CFG1); |
| 14828 |
|
| 14829 |
switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14830 |
case FLASH_5717VENDOR_ATMEL_EEPROM: |
| 14831 |
case FLASH_5717VENDOR_MICRO_EEPROM: |
| 14832 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14833 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14834 |
tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14835 |
|
| 14836 |
nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14837 |
tw32(NVRAM_CFG1, nvcfg1); |
| 14838 |
return; |
| 14839 |
case FLASH_5717VENDOR_ATMEL_MDB011D: |
| 14840 |
case FLASH_5717VENDOR_ATMEL_ADB011B: |
| 14841 |
case FLASH_5717VENDOR_ATMEL_ADB011D: |
| 14842 |
case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 14843 |
case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 14844 |
case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 14845 |
case FLASH_5717VENDOR_ATMEL_45USPT: |
| 14846 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14847 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14848 |
tg3_flag_set(tp, FLASH); |
| 14849 |
|
| 14850 |
switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14851 |
case FLASH_5717VENDOR_ATMEL_MDB021D: |
| 14852 |
/* Detect size with tg3_nvram_get_size() */ |
| 14853 |
break; |
| 14854 |
case FLASH_5717VENDOR_ATMEL_ADB021B: |
| 14855 |
case FLASH_5717VENDOR_ATMEL_ADB021D: |
| 14856 |
tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14857 |
break; |
| 14858 |
default: |
| 14859 |
tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 14860 |
break; |
| 14861 |
} |
| 14862 |
break; |
| 14863 |
case FLASH_5717VENDOR_ST_M_M25PE10: |
| 14864 |
case FLASH_5717VENDOR_ST_A_M25PE10: |
| 14865 |
case FLASH_5717VENDOR_ST_M_M45PE10: |
| 14866 |
case FLASH_5717VENDOR_ST_A_M45PE10: |
| 14867 |
case FLASH_5717VENDOR_ST_M_M25PE20: |
| 14868 |
case FLASH_5717VENDOR_ST_A_M25PE20: |
| 14869 |
case FLASH_5717VENDOR_ST_M_M45PE20: |
| 14870 |
case FLASH_5717VENDOR_ST_A_M45PE20: |
| 14871 |
case FLASH_5717VENDOR_ST_25USPT: |
| 14872 |
case FLASH_5717VENDOR_ST_45USPT: |
| 14873 |
tp->nvram_jedecnum = JEDEC_ST; |
| 14874 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14875 |
tg3_flag_set(tp, FLASH); |
| 14876 |
|
| 14877 |
switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
| 14878 |
case FLASH_5717VENDOR_ST_M_M25PE20: |
| 14879 |
case FLASH_5717VENDOR_ST_M_M45PE20: |
| 14880 |
/* Detect size with tg3_nvram_get_size() */ |
| 14881 |
break; |
| 14882 |
case FLASH_5717VENDOR_ST_A_M25PE20: |
| 14883 |
case FLASH_5717VENDOR_ST_A_M45PE20: |
| 14884 |
tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14885 |
break; |
| 14886 |
default: |
| 14887 |
tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 14888 |
break; |
| 14889 |
} |
| 14890 |
break; |
| 14891 |
default: |
| 14892 |
tg3_flag_set(tp, NO_NVRAM); |
| 14893 |
return; |
| 14894 |
} |
| 14895 |
|
| 14896 |
tg3_nvram_get_pagesize(tp, nvcfg1); |
| 14897 |
if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
| 14898 |
tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
| 14899 |
} |
| 14900 |
|
| 14901 |
static void tg3_get_5720_nvram_info(struct tg3 *tp) |
| 14902 |
{ |
| 14903 |
u32 nvcfg1, nvmpinstrp, nv_status; |
| 14904 |
|
| 14905 |
nvcfg1 = tr32(NVRAM_CFG1); |
| 14906 |
nvmpinstrp = nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK; |
| 14907 |
|
| 14908 |
if (tg3_asic_rev(tp) == ASIC_REV_5762) { |
| 14909 |
if (!(nvcfg1 & NVRAM_CFG1_5762VENDOR_MASK)) { |
| 14910 |
tg3_flag_set(tp, NO_NVRAM); |
| 14911 |
return; |
| 14912 |
} |
| 14913 |
|
| 14914 |
switch (nvmpinstrp) { |
| 14915 |
case FLASH_5762_MX25L_100: |
| 14916 |
case FLASH_5762_MX25L_200: |
| 14917 |
case FLASH_5762_MX25L_400: |
| 14918 |
case FLASH_5762_MX25L_800: |
| 14919 |
case FLASH_5762_MX25L_160_320: |
| 14920 |
tp->nvram_pagesize = 4096; |
| 14921 |
tp->nvram_jedecnum = JEDEC_MACRONIX; |
| 14922 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14923 |
tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
| 14924 |
tg3_flag_set(tp, FLASH); |
| 14925 |
nv_status = tr32(NVRAM_AUTOSENSE_STATUS); |
| 14926 |
tp->nvram_size = |
| 14927 |
(1 << (nv_status >> AUTOSENSE_DEVID & |
| 14928 |
AUTOSENSE_DEVID_MASK) |
| 14929 |
<< AUTOSENSE_SIZE_IN_MB); |
| 14930 |
return; |
| 14931 |
|
| 14932 |
case FLASH_5762_EEPROM_HD: |
| 14933 |
nvmpinstrp = FLASH_5720_EEPROM_HD; |
| 14934 |
break; |
| 14935 |
case FLASH_5762_EEPROM_LD: |
| 14936 |
nvmpinstrp = FLASH_5720_EEPROM_LD; |
| 14937 |
break; |
| 14938 |
case FLASH_5720VENDOR_M_ST_M45PE20: |
| 14939 |
/* This pinstrap supports multiple sizes, so force it |
| 14940 |
* to read the actual size from location 0xf0. |
| 14941 |
*/ |
| 14942 |
nvmpinstrp = FLASH_5720VENDOR_ST_45USPT; |
| 14943 |
break; |
| 14944 |
} |
| 14945 |
} |
| 14946 |
|
| 14947 |
switch (nvmpinstrp) { |
| 14948 |
case FLASH_5720_EEPROM_HD: |
| 14949 |
case FLASH_5720_EEPROM_LD: |
| 14950 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14951 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14952 |
|
| 14953 |
nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
| 14954 |
tw32(NVRAM_CFG1, nvcfg1); |
| 14955 |
if (nvmpinstrp == FLASH_5720_EEPROM_HD) |
| 14956 |
tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
| 14957 |
else |
| 14958 |
tp->nvram_pagesize = ATMEL_AT24C02_CHIP_SIZE; |
| 14959 |
return; |
| 14960 |
case FLASH_5720VENDOR_M_ATMEL_DB011D: |
| 14961 |
case FLASH_5720VENDOR_A_ATMEL_DB011B: |
| 14962 |
case FLASH_5720VENDOR_A_ATMEL_DB011D: |
| 14963 |
case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 14964 |
case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 14965 |
case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 14966 |
case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 14967 |
case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 14968 |
case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 14969 |
case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 14970 |
case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 14971 |
case FLASH_5720VENDOR_ATMEL_45USPT: |
| 14972 |
tp->nvram_jedecnum = JEDEC_ATMEL; |
| 14973 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 14974 |
tg3_flag_set(tp, FLASH); |
| 14975 |
|
| 14976 |
switch (nvmpinstrp) { |
| 14977 |
case FLASH_5720VENDOR_M_ATMEL_DB021D: |
| 14978 |
case FLASH_5720VENDOR_A_ATMEL_DB021B: |
| 14979 |
case FLASH_5720VENDOR_A_ATMEL_DB021D: |
| 14980 |
tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 14981 |
break; |
| 14982 |
case FLASH_5720VENDOR_M_ATMEL_DB041D: |
| 14983 |
case FLASH_5720VENDOR_A_ATMEL_DB041B: |
| 14984 |
case FLASH_5720VENDOR_A_ATMEL_DB041D: |
| 14985 |
tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 14986 |
break; |
| 14987 |
case FLASH_5720VENDOR_M_ATMEL_DB081D: |
| 14988 |
case FLASH_5720VENDOR_A_ATMEL_DB081D: |
| 14989 |
tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 14990 |
break; |
| 14991 |
default: |
| 14992 |
if (tg3_asic_rev(tp) != ASIC_REV_5762) |
| 14993 |
tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 14994 |
break; |
| 14995 |
} |
| 14996 |
break; |
| 14997 |
case FLASH_5720VENDOR_M_ST_M25PE10: |
| 14998 |
case FLASH_5720VENDOR_M_ST_M45PE10: |
| 14999 |
case FLASH_5720VENDOR_A_ST_M25PE10: |
| 15000 |
case FLASH_5720VENDOR_A_ST_M45PE10: |
| 15001 |
case FLASH_5720VENDOR_M_ST_M25PE20: |
| 15002 |
case FLASH_5720VENDOR_M_ST_M45PE20: |
| 15003 |
case FLASH_5720VENDOR_A_ST_M25PE20: |
| 15004 |
case FLASH_5720VENDOR_A_ST_M45PE20: |
| 15005 |
case FLASH_5720VENDOR_M_ST_M25PE40: |
| 15006 |
case FLASH_5720VENDOR_M_ST_M45PE40: |
| 15007 |
case FLASH_5720VENDOR_A_ST_M25PE40: |
| 15008 |
case FLASH_5720VENDOR_A_ST_M45PE40: |
| 15009 |
case FLASH_5720VENDOR_M_ST_M25PE80: |
| 15010 |
case FLASH_5720VENDOR_M_ST_M45PE80: |
| 15011 |
case FLASH_5720VENDOR_A_ST_M25PE80: |
| 15012 |
case FLASH_5720VENDOR_A_ST_M45PE80: |
| 15013 |
case FLASH_5720VENDOR_ST_25USPT: |
| 15014 |
case FLASH_5720VENDOR_ST_45USPT: |
| 15015 |
tp->nvram_jedecnum = JEDEC_ST; |
| 15016 |
tg3_flag_set(tp, NVRAM_BUFFERED); |
| 15017 |
tg3_flag_set(tp, FLASH); |
| 15018 |
|
| 15019 |
switch (nvmpinstrp) { |
| 15020 |
case FLASH_5720VENDOR_M_ST_M25PE20: |
| 15021 |
case FLASH_5720VENDOR_M_ST_M45PE20: |
| 15022 |
case FLASH_5720VENDOR_A_ST_M25PE20: |
| 15023 |
case FLASH_5720VENDOR_A_ST_M45PE20: |
| 15024 |
tp->nvram_size = TG3_NVRAM_SIZE_256KB; |
| 15025 |
break; |
| 15026 |
case FLASH_5720VENDOR_M_ST_M25PE40: |
| 15027 |
case FLASH_5720VENDOR_M_ST_M45PE40: |
| 15028 |
case FLASH_5720VENDOR_A_ST_M25PE40: |
| 15029 |
case FLASH_5720VENDOR_A_ST_M45PE40: |
| 15030 |
tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
| 15031 |
break; |
| 15032 |
case FLASH_5720VENDOR_M_ST_M25PE80: |
| 15033 |
case FLASH_5720VENDOR_M_ST_M45PE80: |
| 15034 |
case FLASH_5720VENDOR_A_ST_M25PE80: |
| 15035 |
case FLASH_5720VENDOR_A_ST_M45PE80: |
| 15036 |
tp->nvram_size = TG3_NVRAM_SIZE_1MB; |
| 15037 |
break; |
| 15038 |
default: |
| 15039 |
if (tg3_asic_rev(tp) != ASIC_REV_5762) |
| 15040 |
tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
| 15041 |
break; |
| 15042 |
} |
| 15043 |
break; |
| 15044 |
default: |
| 15045 |
tg3_flag_set(tp, NO_NVRAM); |
| 15046 |
return; |
| 15047 |
} |
| 15048 |
|
| 15049 |
tg3_nvram_get_pagesize(tp, nvcfg1); |
| 15050 |
if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) |
| 15051 |
tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
| 15052 |
|
| 15053 |
if (tg3_asic_rev(tp) == ASIC_REV_5762) { |
| 15054 |
u32 val; |
| 15055 |
|
| 15056 |
if (tg3_nvram_read(tp, 0, &val)) |
| 15057 |
return; |
| 15058 |
|
| 15059 |
if (val != TG3_EEPROM_MAGIC && |
| 15060 |
(val & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) |
| 15061 |
tg3_flag_set(tp, NO_NVRAM); |
| 15062 |
} |
| 15063 |
} |
| 15064 |
|
| 15065 |
/* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
| 15066 |
static void tg3_nvram_init(struct tg3 *tp) |
| 15067 |
{ |
| 15068 |
if (tg3_flag(tp, IS_SSB_CORE)) { |
| 15069 |
/* No NVRAM and EEPROM on the SSB Broadcom GigE core. */ |
| 15070 |
tg3_flag_clear(tp, NVRAM); |
| 15071 |
tg3_flag_clear(tp, NVRAM_BUFFERED); |
| 15072 |
tg3_flag_set(tp, NO_NVRAM); |
| 15073 |
return; |
| 15074 |
} |
| 15075 |
|
| 15076 |
tw32_f(GRC_EEPROM_ADDR, |
| 15077 |
(EEPROM_ADDR_FSM_RESET | |
| 15078 |
(EEPROM_DEFAULT_CLOCK_PERIOD << |
| 15079 |
EEPROM_ADDR_CLKPERD_SHIFT))); |
| 15080 |
|
| 15081 |
msleep(1); |
| 15082 |
|
| 15083 |
/* Enable seeprom accesses. */ |
| 15084 |
tw32_f(GRC_LOCAL_CTRL, |
| 15085 |
tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); |
| 15086 |
udelay(100); |
| 15087 |
|
| 15088 |
if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
| 15089 |
tg3_asic_rev(tp) != ASIC_REV_5701) { |
| 15090 |
tg3_flag_set(tp, NVRAM); |
| 15091 |
|
| 15092 |
if (tg3_nvram_lock(tp)) { |
| 15093 |
netdev_warn(tp->dev, |
| 15094 |
"Cannot get nvram lock, %s failed\n", |
| 15095 |
__func__); |
| 15096 |
return; |
| 15097 |
} |
| 15098 |
tg3_enable_nvram_access(tp); |
| 15099 |
|
| 15100 |
tp->nvram_size = 0; |
| 15101 |
|
| 15102 |
if (tg3_asic_rev(tp) == ASIC_REV_5752) |
| 15103 |
tg3_get_5752_nvram_info(tp); |
| 15104 |
else if (tg3_asic_rev(tp) == ASIC_REV_5755) |
| 15105 |
tg3_get_5755_nvram_info(tp); |
| 15106 |
else if (tg3_asic_rev(tp) == ASIC_REV_5787 || |
| 15107 |
tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 15108 |
tg3_asic_rev(tp) == ASIC_REV_5785) |
| 15109 |
tg3_get_5787_nvram_info(tp); |
| 15110 |
else if (tg3_asic_rev(tp) == ASIC_REV_5761) |
| 15111 |
tg3_get_5761_nvram_info(tp); |
| 15112 |
else if (tg3_asic_rev(tp) == ASIC_REV_5906) |
| 15113 |
tg3_get_5906_nvram_info(tp); |
| 15114 |
else if (tg3_asic_rev(tp) == ASIC_REV_57780 || |
| 15115 |
tg3_flag(tp, 57765_CLASS)) |
| 15116 |
tg3_get_57780_nvram_info(tp); |
| 15117 |
else if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 15118 |
tg3_asic_rev(tp) == ASIC_REV_5719) |
| 15119 |
tg3_get_5717_nvram_info(tp); |
| 15120 |
else if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 15121 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 15122 |
tg3_get_5720_nvram_info(tp); |
| 15123 |
else |
| 15124 |
tg3_get_nvram_info(tp); |
| 15125 |
|
| 15126 |
if (tp->nvram_size == 0) |
| 15127 |
tg3_get_nvram_size(tp); |
| 15128 |
|
| 15129 |
tg3_disable_nvram_access(tp); |
| 15130 |
tg3_nvram_unlock(tp); |
| 15131 |
|
| 15132 |
} else { |
| 15133 |
tg3_flag_clear(tp, NVRAM); |
| 15134 |
tg3_flag_clear(tp, NVRAM_BUFFERED); |
| 15135 |
|
| 15136 |
tg3_get_eeprom_size(tp); |
| 15137 |
} |
| 15138 |
} |
| 15139 |
|
| 15140 |
struct subsys_tbl_ent { |
| 15141 |
u16 subsys_vendor, subsys_devid; |
| 15142 |
u32 phy_id; |
| 15143 |
}; |
| 15144 |
|
| 15145 |
static struct subsys_tbl_ent subsys_id_to_phy_id[] = { |
| 15146 |
/* Broadcom boards. */ |
| 15147 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15148 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
| 15149 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15150 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
| 15151 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15152 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
| 15153 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15154 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, |
| 15155 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15156 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
| 15157 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15158 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
| 15159 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15160 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, |
| 15161 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15162 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
| 15163 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15164 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
| 15165 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15166 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
| 15167 |
{ TG3PCI_SUBVENDOR_ID_BROADCOM, |
| 15168 |
TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
| 15169 |
|
| 15170 |
/* 3com boards. */ |
| 15171 |
{ TG3PCI_SUBVENDOR_ID_3COM, |
| 15172 |
TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
| 15173 |
{ TG3PCI_SUBVENDOR_ID_3COM, |
| 15174 |
TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
| 15175 |
{ TG3PCI_SUBVENDOR_ID_3COM, |
| 15176 |
TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, |
| 15177 |
{ TG3PCI_SUBVENDOR_ID_3COM, |
| 15178 |
TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
| 15179 |
{ TG3PCI_SUBVENDOR_ID_3COM, |
| 15180 |
TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
| 15181 |
|
| 15182 |
/* DELL boards. */ |
| 15183 |
{ TG3PCI_SUBVENDOR_ID_DELL, |
| 15184 |
TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
| 15185 |
{ TG3PCI_SUBVENDOR_ID_DELL, |
| 15186 |
TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
| 15187 |
{ TG3PCI_SUBVENDOR_ID_DELL, |
| 15188 |
TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
| 15189 |
{ TG3PCI_SUBVENDOR_ID_DELL, |
| 15190 |
TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
| 15191 |
|
| 15192 |
/* Compaq boards. */ |
| 15193 |
{ TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 15194 |
TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
| 15195 |
{ TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 15196 |
TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
| 15197 |
{ TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 15198 |
TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, |
| 15199 |
{ TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 15200 |
TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
| 15201 |
{ TG3PCI_SUBVENDOR_ID_COMPAQ, |
| 15202 |
TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
| 15203 |
|
| 15204 |
/* IBM boards. */ |
| 15205 |
{ TG3PCI_SUBVENDOR_ID_IBM, |
| 15206 |
TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } |
| 15207 |
}; |
| 15208 |
|
| 15209 |
static struct subsys_tbl_ent *tg3_lookup_by_subsys(struct tg3 *tp) |
| 15210 |
{ |
| 15211 |
int i; |
| 15212 |
|
| 15213 |
for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { |
| 15214 |
if ((subsys_id_to_phy_id[i].subsys_vendor == |
| 15215 |
tp->pdev->subsystem_vendor) && |
| 15216 |
(subsys_id_to_phy_id[i].subsys_devid == |
| 15217 |
tp->pdev->subsystem_device)) |
| 15218 |
return &subsys_id_to_phy_id[i]; |
| 15219 |
} |
| 15220 |
return NULL; |
| 15221 |
} |
| 15222 |
|
| 15223 |
static void tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
| 15224 |
{ |
| 15225 |
u32 val; |
| 15226 |
|
| 15227 |
tp->phy_id = TG3_PHY_ID_INVALID; |
| 15228 |
tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 15229 |
|
| 15230 |
/* Assume an onboard device and WOL capable by default. */ |
| 15231 |
tg3_flag_set(tp, EEPROM_WRITE_PROT); |
| 15232 |
tg3_flag_set(tp, WOL_CAP); |
| 15233 |
|
| 15234 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 15235 |
if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
| 15236 |
tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 15237 |
tg3_flag_set(tp, IS_NIC); |
| 15238 |
} |
| 15239 |
val = tr32(VCPU_CFGSHDW); |
| 15240 |
if (val & VCPU_CFGSHDW_ASPM_DBNC) |
| 15241 |
tg3_flag_set(tp, ASPM_WORKAROUND); |
| 15242 |
if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
| 15243 |
(val & VCPU_CFGSHDW_WOL_MAGPKT)) { |
| 15244 |
tg3_flag_set(tp, WOL_ENABLE); |
| 15245 |
device_set_wakeup_enable(&tp->pdev->dev, true); |
| 15246 |
} |
| 15247 |
goto done; |
| 15248 |
} |
| 15249 |
|
| 15250 |
tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
| 15251 |
if (val == NIC_SRAM_DATA_SIG_MAGIC) { |
| 15252 |
u32 nic_cfg, led_cfg; |
| 15253 |
u32 cfg2 = 0, cfg4 = 0, cfg5 = 0; |
| 15254 |
u32 nic_phy_id, ver, eeprom_phy_id; |
| 15255 |
int eeprom_phy_serdes = 0; |
| 15256 |
|
| 15257 |
tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); |
| 15258 |
tp->nic_sram_data_cfg = nic_cfg; |
| 15259 |
|
| 15260 |
tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); |
| 15261 |
ver >>= NIC_SRAM_DATA_VER_SHIFT; |
| 15262 |
if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
| 15263 |
tg3_asic_rev(tp) != ASIC_REV_5701 && |
| 15264 |
tg3_asic_rev(tp) != ASIC_REV_5703 && |
| 15265 |
(ver > 0) && (ver < 0x100)) |
| 15266 |
tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); |
| 15267 |
|
| 15268 |
if (tg3_asic_rev(tp) == ASIC_REV_5785) |
| 15269 |
tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
| 15270 |
|
| 15271 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 15272 |
tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 15273 |
tg3_asic_rev(tp) == ASIC_REV_5720) |
| 15274 |
tg3_read_mem(tp, NIC_SRAM_DATA_CFG_5, &cfg5); |
| 15275 |
|
| 15276 |
if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
| 15277 |
NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) |
| 15278 |
eeprom_phy_serdes = 1; |
| 15279 |
|
| 15280 |
tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); |
| 15281 |
if (nic_phy_id != 0) { |
| 15282 |
u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; |
| 15283 |
u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; |
| 15284 |
|
| 15285 |
eeprom_phy_id = (id1 >> 16) << 10; |
| 15286 |
eeprom_phy_id |= (id2 & 0xfc00) << 16; |
| 15287 |
eeprom_phy_id |= (id2 & 0x03ff) << 0; |
| 15288 |
} else |
| 15289 |
eeprom_phy_id = 0; |
| 15290 |
|
| 15291 |
tp->phy_id = eeprom_phy_id; |
| 15292 |
if (eeprom_phy_serdes) { |
| 15293 |
if (!tg3_flag(tp, 5705_PLUS)) |
| 15294 |
tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
| 15295 |
else |
| 15296 |
tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
| 15297 |
} |
| 15298 |
|
| 15299 |
if (tg3_flag(tp, 5750_PLUS)) |
| 15300 |
led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
| 15301 |
SHASTA_EXT_LED_MODE_MASK); |
| 15302 |
else |
| 15303 |
led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
| 15304 |
|
| 15305 |
switch (led_cfg) { |
| 15306 |
default: |
| 15307 |
case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: |
| 15308 |
tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 15309 |
break; |
| 15310 |
|
| 15311 |
case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: |
| 15312 |
tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 15313 |
break; |
| 15314 |
|
| 15315 |
case NIC_SRAM_DATA_CFG_LED_MODE_MAC: |
| 15316 |
tp->led_ctrl = LED_CTRL_MODE_MAC; |
| 15317 |
|
| 15318 |
/* Default to PHY_1_MODE if 0 (MAC_MODE) is |
| 15319 |
* read on some older 5700/5701 bootcode. |
| 15320 |
*/ |
| 15321 |
if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 15322 |
tg3_asic_rev(tp) == ASIC_REV_5701) |
| 15323 |
tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 15324 |
|
| 15325 |
break; |
| 15326 |
|
| 15327 |
case SHASTA_EXT_LED_SHARED: |
| 15328 |
tp->led_ctrl = LED_CTRL_MODE_SHARED; |
| 15329 |
if (tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0 && |
| 15330 |
tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A1) |
| 15331 |
tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 15332 |
LED_CTRL_MODE_PHY_2); |
| 15333 |
|
| 15334 |
if (tg3_flag(tp, 5717_PLUS) || |
| 15335 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 15336 |
tp->led_ctrl |= LED_CTRL_BLINK_RATE_OVERRIDE | |
| 15337 |
LED_CTRL_BLINK_RATE_MASK; |
| 15338 |
|
| 15339 |
break; |
| 15340 |
|
| 15341 |
case SHASTA_EXT_LED_MAC: |
| 15342 |
tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; |
| 15343 |
break; |
| 15344 |
|
| 15345 |
case SHASTA_EXT_LED_COMBO: |
| 15346 |
tp->led_ctrl = LED_CTRL_MODE_COMBO; |
| 15347 |
if (tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0) |
| 15348 |
tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
| 15349 |
LED_CTRL_MODE_PHY_2); |
| 15350 |
break; |
| 15351 |
|
| 15352 |
} |
| 15353 |
|
| 15354 |
if ((tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 15355 |
tg3_asic_rev(tp) == ASIC_REV_5701) && |
| 15356 |
tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
| 15357 |
tp->led_ctrl = LED_CTRL_MODE_PHY_2; |
| 15358 |
|
| 15359 |
if (tg3_chip_rev(tp) == CHIPREV_5784_AX) |
| 15360 |
tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
| 15361 |
|
| 15362 |
if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
| 15363 |
tg3_flag_set(tp, EEPROM_WRITE_PROT); |
| 15364 |
if ((tp->pdev->subsystem_vendor == |
| 15365 |
PCI_VENDOR_ID_ARIMA) && |
| 15366 |
(tp->pdev->subsystem_device == 0x205a || |
| 15367 |
tp->pdev->subsystem_device == 0x2063)) |
| 15368 |
tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 15369 |
} else { |
| 15370 |
tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
| 15371 |
tg3_flag_set(tp, IS_NIC); |
| 15372 |
} |
| 15373 |
|
| 15374 |
if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { |
| 15375 |
tg3_flag_set(tp, ENABLE_ASF); |
| 15376 |
if (tg3_flag(tp, 5750_PLUS)) |
| 15377 |
tg3_flag_set(tp, ASF_NEW_HANDSHAKE); |
| 15378 |
} |
| 15379 |
|
| 15380 |
if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && |
| 15381 |
tg3_flag(tp, 5750_PLUS)) |
| 15382 |
tg3_flag_set(tp, ENABLE_APE); |
| 15383 |
|
| 15384 |
if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
| 15385 |
!(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
| 15386 |
tg3_flag_clear(tp, WOL_CAP); |
| 15387 |
|
| 15388 |
if (tg3_flag(tp, WOL_CAP) && |
| 15389 |
(nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) { |
| 15390 |
tg3_flag_set(tp, WOL_ENABLE); |
| 15391 |
device_set_wakeup_enable(&tp->pdev->dev, true); |
| 15392 |
} |
| 15393 |
|
| 15394 |
if (cfg2 & (1 << 17)) |
| 15395 |
tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
| 15396 |
|
| 15397 |
/* serdes signal pre-emphasis in register 0x590 set by */ |
| 15398 |
/* bootcode if bit 18 is set */ |
| 15399 |
if (cfg2 & (1 << 18)) |
| 15400 |
tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
| 15401 |
|
| 15402 |
if ((tg3_flag(tp, 57765_PLUS) || |
| 15403 |
(tg3_asic_rev(tp) == ASIC_REV_5784 && |
| 15404 |
tg3_chip_rev(tp) != CHIPREV_5784_AX)) && |
| 15405 |
(cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
| 15406 |
tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
| 15407 |
|
| 15408 |
if (tg3_flag(tp, PCI_EXPRESS)) { |
| 15409 |
u32 cfg3; |
| 15410 |
|
| 15411 |
tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); |
| 15412 |
if (tg3_asic_rev(tp) != ASIC_REV_5785 && |
| 15413 |
!tg3_flag(tp, 57765_PLUS) && |
| 15414 |
(cfg3 & NIC_SRAM_ASPM_DEBOUNCE)) |
| 15415 |
tg3_flag_set(tp, ASPM_WORKAROUND); |
| 15416 |
if (cfg3 & NIC_SRAM_LNK_FLAP_AVOID) |
| 15417 |
tp->phy_flags |= TG3_PHYFLG_KEEP_LINK_ON_PWRDN; |
| 15418 |
if (cfg3 & NIC_SRAM_1G_ON_VAUX_OK) |
| 15419 |
tp->phy_flags |= TG3_PHYFLG_1G_ON_VAUX_OK; |
| 15420 |
} |
| 15421 |
|
| 15422 |
if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
| 15423 |
tg3_flag_set(tp, RGMII_INBAND_DISABLE); |
| 15424 |
if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
| 15425 |
tg3_flag_set(tp, RGMII_EXT_IBND_RX_EN); |
| 15426 |
if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
| 15427 |
tg3_flag_set(tp, RGMII_EXT_IBND_TX_EN); |
| 15428 |
|
| 15429 |
if (cfg5 & NIC_SRAM_DISABLE_1G_HALF_ADV) |
| 15430 |
tp->phy_flags |= TG3_PHYFLG_DISABLE_1G_HD_ADV; |
| 15431 |
} |
| 15432 |
done: |
| 15433 |
if (tg3_flag(tp, WOL_CAP)) |
| 15434 |
device_set_wakeup_enable(&tp->pdev->dev, |
| 15435 |
tg3_flag(tp, WOL_ENABLE)); |
| 15436 |
else |
| 15437 |
device_set_wakeup_capable(&tp->pdev->dev, false); |
| 15438 |
} |
| 15439 |
|
| 15440 |
static int tg3_ape_otp_read(struct tg3 *tp, u32 offset, u32 *val) |
| 15441 |
{ |
| 15442 |
int i, err; |
| 15443 |
u32 val2, off = offset * 8; |
| 15444 |
|
| 15445 |
err = tg3_nvram_lock(tp); |
| 15446 |
if (err) |
| 15447 |
return err; |
| 15448 |
|
| 15449 |
tg3_ape_write32(tp, TG3_APE_OTP_ADDR, off | APE_OTP_ADDR_CPU_ENABLE); |
| 15450 |
tg3_ape_write32(tp, TG3_APE_OTP_CTRL, APE_OTP_CTRL_PROG_EN | |
| 15451 |
APE_OTP_CTRL_CMD_RD | APE_OTP_CTRL_START); |
| 15452 |
tg3_ape_read32(tp, TG3_APE_OTP_CTRL); |
| 15453 |
udelay(10); |
| 15454 |
|
| 15455 |
for (i = 0; i < 100; i++) { |
| 15456 |
val2 = tg3_ape_read32(tp, TG3_APE_OTP_STATUS); |
| 15457 |
if (val2 & APE_OTP_STATUS_CMD_DONE) { |
| 15458 |
*val = tg3_ape_read32(tp, TG3_APE_OTP_RD_DATA); |
| 15459 |
break; |
| 15460 |
} |
| 15461 |
udelay(10); |
| 15462 |
} |
| 15463 |
|
| 15464 |
tg3_ape_write32(tp, TG3_APE_OTP_CTRL, 0); |
| 15465 |
|
| 15466 |
tg3_nvram_unlock(tp); |
| 15467 |
if (val2 & APE_OTP_STATUS_CMD_DONE) |
| 15468 |
return 0; |
| 15469 |
|
| 15470 |
return -EBUSY; |
| 15471 |
} |
| 15472 |
|
| 15473 |
static int tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
| 15474 |
{ |
| 15475 |
int i; |
| 15476 |
u32 val; |
| 15477 |
|
| 15478 |
tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); |
| 15479 |
tw32(OTP_CTRL, cmd); |
| 15480 |
|
| 15481 |
/* Wait for up to 1 ms for command to execute. */ |
| 15482 |
for (i = 0; i < 100; i++) { |
| 15483 |
val = tr32(OTP_STATUS); |
| 15484 |
if (val & OTP_STATUS_CMD_DONE) |
| 15485 |
break; |
| 15486 |
udelay(10); |
| 15487 |
} |
| 15488 |
|
| 15489 |
return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; |
| 15490 |
} |
| 15491 |
|
| 15492 |
/* Read the gphy configuration from the OTP region of the chip. The gphy |
| 15493 |
* configuration is a 32-bit value that straddles the alignment boundary. |
| 15494 |
* We do two 32-bit reads and then shift and merge the results. |
| 15495 |
*/ |
| 15496 |
static u32 tg3_read_otp_phycfg(struct tg3 *tp) |
| 15497 |
{ |
| 15498 |
u32 bhalf_otp, thalf_otp; |
| 15499 |
|
| 15500 |
tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); |
| 15501 |
|
| 15502 |
if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) |
| 15503 |
return 0; |
| 15504 |
|
| 15505 |
tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); |
| 15506 |
|
| 15507 |
if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 15508 |
return 0; |
| 15509 |
|
| 15510 |
thalf_otp = tr32(OTP_READ_DATA); |
| 15511 |
|
| 15512 |
tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); |
| 15513 |
|
| 15514 |
if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) |
| 15515 |
return 0; |
| 15516 |
|
| 15517 |
bhalf_otp = tr32(OTP_READ_DATA); |
| 15518 |
|
| 15519 |
return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); |
| 15520 |
} |
| 15521 |
|
| 15522 |
static void tg3_phy_init_link_config(struct tg3 *tp) |
| 15523 |
{ |
| 15524 |
u32 adv = ADVERTISED_Autoneg; |
| 15525 |
|
| 15526 |
if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
| 15527 |
if (!(tp->phy_flags & TG3_PHYFLG_DISABLE_1G_HD_ADV)) |
| 15528 |
adv |= ADVERTISED_1000baseT_Half; |
| 15529 |
adv |= ADVERTISED_1000baseT_Full; |
| 15530 |
} |
| 15531 |
|
| 15532 |
if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 15533 |
adv |= ADVERTISED_100baseT_Half | |
| 15534 |
ADVERTISED_100baseT_Full | |
| 15535 |
ADVERTISED_10baseT_Half | |
| 15536 |
ADVERTISED_10baseT_Full | |
| 15537 |
ADVERTISED_TP; |
| 15538 |
else |
| 15539 |
adv |= ADVERTISED_FIBRE; |
| 15540 |
|
| 15541 |
tp->link_config.advertising = adv; |
| 15542 |
tp->link_config.speed = SPEED_UNKNOWN; |
| 15543 |
tp->link_config.duplex = DUPLEX_UNKNOWN; |
| 15544 |
tp->link_config.autoneg = AUTONEG_ENABLE; |
| 15545 |
tp->link_config.active_speed = SPEED_UNKNOWN; |
| 15546 |
tp->link_config.active_duplex = DUPLEX_UNKNOWN; |
| 15547 |
|
| 15548 |
tp->old_link = -1; |
| 15549 |
} |
| 15550 |
|
| 15551 |
static int tg3_phy_probe(struct tg3 *tp) |
| 15552 |
{ |
| 15553 |
u32 hw_phy_id_1, hw_phy_id_2; |
| 15554 |
u32 hw_phy_id, hw_phy_id_masked; |
| 15555 |
int err; |
| 15556 |
|
| 15557 |
/* flow control autonegotiation is default behavior */ |
| 15558 |
tg3_flag_set(tp, PAUSE_AUTONEG); |
| 15559 |
tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
| 15560 |
|
| 15561 |
if (tg3_flag(tp, ENABLE_APE)) { |
| 15562 |
switch (tp->pci_fn) { |
| 15563 |
case 0: |
| 15564 |
tp->phy_ape_lock = TG3_APE_LOCK_PHY0; |
| 15565 |
break; |
| 15566 |
case 1: |
| 15567 |
tp->phy_ape_lock = TG3_APE_LOCK_PHY1; |
| 15568 |
break; |
| 15569 |
case 2: |
| 15570 |
tp->phy_ape_lock = TG3_APE_LOCK_PHY2; |
| 15571 |
break; |
| 15572 |
case 3: |
| 15573 |
tp->phy_ape_lock = TG3_APE_LOCK_PHY3; |
| 15574 |
break; |
| 15575 |
} |
| 15576 |
} |
| 15577 |
|
| 15578 |
if (!tg3_flag(tp, ENABLE_ASF) && |
| 15579 |
!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
| 15580 |
!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
| 15581 |
tp->phy_flags &= ~(TG3_PHYFLG_1G_ON_VAUX_OK | |
| 15582 |
TG3_PHYFLG_KEEP_LINK_ON_PWRDN); |
| 15583 |
|
| 15584 |
if (tg3_flag(tp, USE_PHYLIB)) |
| 15585 |
return tg3_phy_init(tp); |
| 15586 |
|
| 15587 |
/* Reading the PHY ID register can conflict with ASF |
| 15588 |
* firmware access to the PHY hardware. |
| 15589 |
*/ |
| 15590 |
err = 0; |
| 15591 |
if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE)) { |
| 15592 |
hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
| 15593 |
} else { |
| 15594 |
/* Now read the physical PHY_ID from the chip and verify |
| 15595 |
* that it is sane. If it doesn't look good, we fall back |
| 15596 |
* to either the hard-coded table based PHY_ID and failing |
| 15597 |
* that the value found in the eeprom area. |
| 15598 |
*/ |
| 15599 |
err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); |
| 15600 |
err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); |
| 15601 |
|
| 15602 |
hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; |
| 15603 |
hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; |
| 15604 |
hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; |
| 15605 |
|
| 15606 |
hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
| 15607 |
} |
| 15608 |
|
| 15609 |
if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
| 15610 |
tp->phy_id = hw_phy_id; |
| 15611 |
if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
| 15612 |
tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
| 15613 |
else |
| 15614 |
tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
| 15615 |
} else { |
| 15616 |
if (tp->phy_id != TG3_PHY_ID_INVALID) { |
| 15617 |
/* Do nothing, phy ID already set up in |
| 15618 |
* tg3_get_eeprom_hw_cfg(). |
| 15619 |
*/ |
| 15620 |
} else { |
| 15621 |
struct subsys_tbl_ent *p; |
| 15622 |
|
| 15623 |
/* No eeprom signature? Try the hardcoded |
| 15624 |
* subsys device table. |
| 15625 |
*/ |
| 15626 |
p = tg3_lookup_by_subsys(tp); |
| 15627 |
if (p) { |
| 15628 |
tp->phy_id = p->phy_id; |
| 15629 |
} else if (!tg3_flag(tp, IS_SSB_CORE)) { |
| 15630 |
/* For now we saw the IDs 0xbc050cd0, |
| 15631 |
* 0xbc050f80 and 0xbc050c30 on devices |
| 15632 |
* connected to an BCM4785 and there are |
| 15633 |
* probably more. Just assume that the phy is |
| 15634 |
* supported when it is connected to a SSB core |
| 15635 |
* for now. |
| 15636 |
*/ |
| 15637 |
return -ENODEV; |
| 15638 |
} |
| 15639 |
|
| 15640 |
if (!tp->phy_id || |
| 15641 |
tp->phy_id == TG3_PHY_ID_BCM8002) |
| 15642 |
tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
| 15643 |
} |
| 15644 |
} |
| 15645 |
|
| 15646 |
if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
| 15647 |
(tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 15648 |
tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 15649 |
tg3_asic_rev(tp) == ASIC_REV_57766 || |
| 15650 |
tg3_asic_rev(tp) == ASIC_REV_5762 || |
| 15651 |
(tg3_asic_rev(tp) == ASIC_REV_5717 && |
| 15652 |
tg3_chip_rev_id(tp) != CHIPREV_ID_5717_A0) || |
| 15653 |
(tg3_asic_rev(tp) == ASIC_REV_57765 && |
| 15654 |
tg3_chip_rev_id(tp) != CHIPREV_ID_57765_A0))) { |
| 15655 |
tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
| 15656 |
|
| 15657 |
linkmode_zero(tp->eee.supported); |
| 15658 |
linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, |
| 15659 |
tp->eee.supported); |
| 15660 |
linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, |
| 15661 |
tp->eee.supported); |
| 15662 |
linkmode_copy(tp->eee.advertised, tp->eee.supported); |
| 15663 |
|
| 15664 |
tp->eee.eee_enabled = 1; |
| 15665 |
tp->eee.tx_lpi_enabled = 1; |
| 15666 |
tp->eee.tx_lpi_timer = TG3_CPMU_DBTMR1_LNKIDLE_2047US; |
| 15667 |
} |
| 15668 |
|
| 15669 |
tg3_phy_init_link_config(tp); |
| 15670 |
|
| 15671 |
if (!(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) && |
| 15672 |
!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
| 15673 |
!tg3_flag(tp, ENABLE_APE) && |
| 15674 |
!tg3_flag(tp, ENABLE_ASF)) { |
| 15675 |
u32 bmsr, dummy; |
| 15676 |
|
| 15677 |
tg3_readphy(tp, MII_BMSR, &bmsr); |
| 15678 |
if (!tg3_readphy(tp, MII_BMSR, &bmsr) && |
| 15679 |
(bmsr & BMSR_LSTATUS)) |
| 15680 |
goto skip_phy_reset; |
| 15681 |
|
| 15682 |
err = tg3_phy_reset(tp); |
| 15683 |
if (err) |
| 15684 |
return err; |
| 15685 |
|
| 15686 |
tg3_phy_set_wirespeed(tp); |
| 15687 |
|
| 15688 |
if (!tg3_phy_copper_an_config_ok(tp, &dummy)) { |
| 15689 |
tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, |
| 15690 |
tp->link_config.flowctrl); |
| 15691 |
|
| 15692 |
tg3_writephy(tp, MII_BMCR, |
| 15693 |
BMCR_ANENABLE | BMCR_ANRESTART); |
| 15694 |
} |
| 15695 |
} |
| 15696 |
|
| 15697 |
skip_phy_reset: |
| 15698 |
if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
| 15699 |
err = tg3_init_5401phy_dsp(tp); |
| 15700 |
if (err) |
| 15701 |
return err; |
| 15702 |
|
| 15703 |
err = tg3_init_5401phy_dsp(tp); |
| 15704 |
} |
| 15705 |
|
| 15706 |
return err; |
| 15707 |
} |
| 15708 |
|
| 15709 |
static void tg3_read_vpd(struct tg3 *tp) |
| 15710 |
{ |
| 15711 |
u8 *vpd_data; |
| 15712 |
unsigned int len, vpdlen; |
| 15713 |
int i; |
| 15714 |
|
| 15715 |
vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen); |
| 15716 |
if (!vpd_data) |
| 15717 |
goto out_no_vpd; |
| 15718 |
|
| 15719 |
i = pci_vpd_find_ro_info_keyword(vpd_data, vpdlen, |
| 15720 |
PCI_VPD_RO_KEYWORD_MFR_ID, &len); |
| 15721 |
if (i < 0) |
| 15722 |
goto partno; |
| 15723 |
|
| 15724 |
if (len != 4 || memcmp(vpd_data + i, "1028", 4)) |
| 15725 |
goto partno; |
| 15726 |
|
| 15727 |
i = pci_vpd_find_ro_info_keyword(vpd_data, vpdlen, |
| 15728 |
PCI_VPD_RO_KEYWORD_VENDOR0, &len); |
| 15729 |
if (i < 0) |
| 15730 |
goto partno; |
| 15731 |
|
| 15732 |
memset(tp->fw_ver, 0, sizeof(tp->fw_ver)); |
| 15733 |
snprintf(tp->fw_ver, sizeof(tp->fw_ver), "%.*s bc ", len, vpd_data + i); |
| 15734 |
|
| 15735 |
partno: |
| 15736 |
i = pci_vpd_find_ro_info_keyword(vpd_data, vpdlen, |
| 15737 |
PCI_VPD_RO_KEYWORD_PARTNO, &len); |
| 15738 |
if (i < 0) |
| 15739 |
goto out_not_found; |
| 15740 |
|
| 15741 |
if (len > TG3_BPN_SIZE) |
| 15742 |
goto out_not_found; |
| 15743 |
|
| 15744 |
memcpy(tp->board_part_number, &vpd_data[i], len); |
| 15745 |
|
| 15746 |
out_not_found: |
| 15747 |
kfree(vpd_data); |
| 15748 |
if (tp->board_part_number[0]) |
| 15749 |
return; |
| 15750 |
|
| 15751 |
out_no_vpd: |
| 15752 |
if (tg3_asic_rev(tp) == ASIC_REV_5717) { |
| 15753 |
if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 15754 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C) |
| 15755 |
strcpy(tp->board_part_number, "BCM5717"); |
| 15756 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) |
| 15757 |
strcpy(tp->board_part_number, "BCM5718"); |
| 15758 |
else |
| 15759 |
goto nomatch; |
| 15760 |
} else if (tg3_asic_rev(tp) == ASIC_REV_57780) { |
| 15761 |
if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
| 15762 |
strcpy(tp->board_part_number, "BCM57780"); |
| 15763 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) |
| 15764 |
strcpy(tp->board_part_number, "BCM57760"); |
| 15765 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) |
| 15766 |
strcpy(tp->board_part_number, "BCM57790"); |
| 15767 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) |
| 15768 |
strcpy(tp->board_part_number, "BCM57788"); |
| 15769 |
else |
| 15770 |
goto nomatch; |
| 15771 |
} else if (tg3_asic_rev(tp) == ASIC_REV_57765) { |
| 15772 |
if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
| 15773 |
strcpy(tp->board_part_number, "BCM57761"); |
| 15774 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) |
| 15775 |
strcpy(tp->board_part_number, "BCM57765"); |
| 15776 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) |
| 15777 |
strcpy(tp->board_part_number, "BCM57781"); |
| 15778 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) |
| 15779 |
strcpy(tp->board_part_number, "BCM57785"); |
| 15780 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) |
| 15781 |
strcpy(tp->board_part_number, "BCM57791"); |
| 15782 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) |
| 15783 |
strcpy(tp->board_part_number, "BCM57795"); |
| 15784 |
else |
| 15785 |
goto nomatch; |
| 15786 |
} else if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
| 15787 |
if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762) |
| 15788 |
strcpy(tp->board_part_number, "BCM57762"); |
| 15789 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766) |
| 15790 |
strcpy(tp->board_part_number, "BCM57766"); |
| 15791 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782) |
| 15792 |
strcpy(tp->board_part_number, "BCM57782"); |
| 15793 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 15794 |
strcpy(tp->board_part_number, "BCM57786"); |
| 15795 |
else |
| 15796 |
goto nomatch; |
| 15797 |
} else if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 15798 |
strcpy(tp->board_part_number, "BCM95906"); |
| 15799 |
} else { |
| 15800 |
nomatch: |
| 15801 |
strcpy(tp->board_part_number, "none"); |
| 15802 |
} |
| 15803 |
} |
| 15804 |
|
| 15805 |
static int tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
| 15806 |
{ |
| 15807 |
u32 val; |
| 15808 |
|
| 15809 |
if (tg3_nvram_read(tp, offset, &val) || |
| 15810 |
(val & 0xfc000000) != 0x0c000000 || |
| 15811 |
tg3_nvram_read(tp, offset + 4, &val) || |
| 15812 |
val != 0) |
| 15813 |
return 0; |
| 15814 |
|
| 15815 |
return 1; |
| 15816 |
} |
| 15817 |
|
| 15818 |
static void tg3_read_bc_ver(struct tg3 *tp) |
| 15819 |
{ |
| 15820 |
u32 val, offset, start, ver_offset; |
| 15821 |
int i, dst_off; |
| 15822 |
bool newver = false; |
| 15823 |
|
| 15824 |
if (tg3_nvram_read(tp, 0xc, &offset) || |
| 15825 |
tg3_nvram_read(tp, 0x4, &start)) |
| 15826 |
return; |
| 15827 |
|
| 15828 |
offset = tg3_nvram_logical_addr(tp, offset); |
| 15829 |
|
| 15830 |
if (tg3_nvram_read(tp, offset, &val)) |
| 15831 |
return; |
| 15832 |
|
| 15833 |
if ((val & 0xfc000000) == 0x0c000000) { |
| 15834 |
if (tg3_nvram_read(tp, offset + 4, &val)) |
| 15835 |
return; |
| 15836 |
|
| 15837 |
if (val == 0) |
| 15838 |
newver = true; |
| 15839 |
} |
| 15840 |
|
| 15841 |
dst_off = strlen(tp->fw_ver); |
| 15842 |
|
| 15843 |
if (newver) { |
| 15844 |
if (TG3_VER_SIZE - dst_off < 16 || |
| 15845 |
tg3_nvram_read(tp, offset + 8, &ver_offset)) |
| 15846 |
return; |
| 15847 |
|
| 15848 |
offset = offset + ver_offset - start; |
| 15849 |
for (i = 0; i < 16; i += 4) { |
| 15850 |
__be32 v; |
| 15851 |
if (tg3_nvram_read_be32(tp, offset + i, &v)) |
| 15852 |
return; |
| 15853 |
|
| 15854 |
memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
| 15855 |
} |
| 15856 |
} else { |
| 15857 |
u32 major, minor; |
| 15858 |
|
| 15859 |
if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) |
| 15860 |
return; |
| 15861 |
|
| 15862 |
major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> |
| 15863 |
TG3_NVM_BCVER_MAJSFT; |
| 15864 |
minor = ver_offset & TG3_NVM_BCVER_MINMSK; |
| 15865 |
snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
| 15866 |
"v%d.%02d", major, minor); |
| 15867 |
} |
| 15868 |
} |
| 15869 |
|
| 15870 |
static void tg3_read_hwsb_ver(struct tg3 *tp) |
| 15871 |
{ |
| 15872 |
u32 val, major, minor; |
| 15873 |
|
| 15874 |
/* Use native endian representation */ |
| 15875 |
if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) |
| 15876 |
return; |
| 15877 |
|
| 15878 |
major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> |
| 15879 |
TG3_NVM_HWSB_CFG1_MAJSFT; |
| 15880 |
minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> |
| 15881 |
TG3_NVM_HWSB_CFG1_MINSFT; |
| 15882 |
|
| 15883 |
snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); |
| 15884 |
} |
| 15885 |
|
| 15886 |
static void tg3_read_sb_ver(struct tg3 *tp, u32 val) |
| 15887 |
{ |
| 15888 |
u32 offset, major, minor, build; |
| 15889 |
|
| 15890 |
strncat(tp->fw_ver, "sb", TG3_VER_SIZE - strlen(tp->fw_ver) - 1); |
| 15891 |
|
| 15892 |
if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) |
| 15893 |
return; |
| 15894 |
|
| 15895 |
switch (val & TG3_EEPROM_SB_REVISION_MASK) { |
| 15896 |
case TG3_EEPROM_SB_REVISION_0: |
| 15897 |
offset = TG3_EEPROM_SB_F1R0_EDH_OFF; |
| 15898 |
break; |
| 15899 |
case TG3_EEPROM_SB_REVISION_2: |
| 15900 |
offset = TG3_EEPROM_SB_F1R2_EDH_OFF; |
| 15901 |
break; |
| 15902 |
case TG3_EEPROM_SB_REVISION_3: |
| 15903 |
offset = TG3_EEPROM_SB_F1R3_EDH_OFF; |
| 15904 |
break; |
| 15905 |
case TG3_EEPROM_SB_REVISION_4: |
| 15906 |
offset = TG3_EEPROM_SB_F1R4_EDH_OFF; |
| 15907 |
break; |
| 15908 |
case TG3_EEPROM_SB_REVISION_5: |
| 15909 |
offset = TG3_EEPROM_SB_F1R5_EDH_OFF; |
| 15910 |
break; |
| 15911 |
case TG3_EEPROM_SB_REVISION_6: |
| 15912 |
offset = TG3_EEPROM_SB_F1R6_EDH_OFF; |
| 15913 |
break; |
| 15914 |
default: |
| 15915 |
return; |
| 15916 |
} |
| 15917 |
|
| 15918 |
if (tg3_nvram_read(tp, offset, &val)) |
| 15919 |
return; |
| 15920 |
|
| 15921 |
build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> |
| 15922 |
TG3_EEPROM_SB_EDH_BLD_SHFT; |
| 15923 |
major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> |
| 15924 |
TG3_EEPROM_SB_EDH_MAJ_SHFT; |
| 15925 |
minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; |
| 15926 |
|
| 15927 |
if (minor > 99 || build > 26) |
| 15928 |
return; |
| 15929 |
|
| 15930 |
offset = strlen(tp->fw_ver); |
| 15931 |
snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, |
| 15932 |
" v%d.%02d", major, minor); |
| 15933 |
|
| 15934 |
if (build > 0) { |
| 15935 |
offset = strlen(tp->fw_ver); |
| 15936 |
if (offset < TG3_VER_SIZE - 1) |
| 15937 |
tp->fw_ver[offset] = 'a' + build - 1; |
| 15938 |
} |
| 15939 |
} |
| 15940 |
|
| 15941 |
static void tg3_read_mgmtfw_ver(struct tg3 *tp) |
| 15942 |
{ |
| 15943 |
u32 val, offset, start; |
| 15944 |
int i, vlen; |
| 15945 |
|
| 15946 |
for (offset = TG3_NVM_DIR_START; |
| 15947 |
offset < TG3_NVM_DIR_END; |
| 15948 |
offset += TG3_NVM_DIRENT_SIZE) { |
| 15949 |
if (tg3_nvram_read(tp, offset, &val)) |
| 15950 |
return; |
| 15951 |
|
| 15952 |
if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
| 15953 |
break; |
| 15954 |
} |
| 15955 |
|
| 15956 |
if (offset == TG3_NVM_DIR_END) |
| 15957 |
return; |
| 15958 |
|
| 15959 |
if (!tg3_flag(tp, 5705_PLUS)) |
| 15960 |
start = 0x08000000; |
| 15961 |
else if (tg3_nvram_read(tp, offset - 4, &start)) |
| 15962 |
return; |
| 15963 |
|
| 15964 |
if (tg3_nvram_read(tp, offset + 4, &offset) || |
| 15965 |
!tg3_fw_img_is_valid(tp, offset) || |
| 15966 |
tg3_nvram_read(tp, offset + 8, &val)) |
| 15967 |
return; |
| 15968 |
|
| 15969 |
offset += val - start; |
| 15970 |
|
| 15971 |
vlen = strlen(tp->fw_ver); |
| 15972 |
|
| 15973 |
tp->fw_ver[vlen++] = ','; |
| 15974 |
tp->fw_ver[vlen++] = ' '; |
| 15975 |
|
| 15976 |
for (i = 0; i < 4; i++) { |
| 15977 |
__be32 v; |
| 15978 |
if (tg3_nvram_read_be32(tp, offset, &v)) |
| 15979 |
return; |
| 15980 |
|
| 15981 |
offset += sizeof(v); |
| 15982 |
|
| 15983 |
if (vlen > TG3_VER_SIZE - sizeof(v)) { |
| 15984 |
memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); |
| 15985 |
break; |
| 15986 |
} |
| 15987 |
|
| 15988 |
memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
| 15989 |
vlen += sizeof(v); |
| 15990 |
} |
| 15991 |
} |
| 15992 |
|
| 15993 |
static void tg3_probe_ncsi(struct tg3 *tp) |
| 15994 |
{ |
| 15995 |
u32 apedata; |
| 15996 |
|
| 15997 |
apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
| 15998 |
if (apedata != APE_SEG_SIG_MAGIC) |
| 15999 |
return; |
| 16000 |
|
| 16001 |
apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); |
| 16002 |
if (!(apedata & APE_FW_STATUS_READY)) |
| 16003 |
return; |
| 16004 |
|
| 16005 |
if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) |
| 16006 |
tg3_flag_set(tp, APE_HAS_NCSI); |
| 16007 |
} |
| 16008 |
|
| 16009 |
static void tg3_read_dash_ver(struct tg3 *tp) |
| 16010 |
{ |
| 16011 |
int vlen; |
| 16012 |
u32 apedata; |
| 16013 |
char *fwtype; |
| 16014 |
|
| 16015 |
apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
| 16016 |
|
| 16017 |
if (tg3_flag(tp, APE_HAS_NCSI)) |
| 16018 |
fwtype = "NCSI"; |
| 16019 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725) |
| 16020 |
fwtype = "SMASH"; |
| 16021 |
else |
| 16022 |
fwtype = "DASH"; |
| 16023 |
|
| 16024 |
vlen = strlen(tp->fw_ver); |
| 16025 |
|
| 16026 |
snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
| 16027 |
fwtype, |
| 16028 |
(apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
| 16029 |
(apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, |
| 16030 |
(apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, |
| 16031 |
(apedata & APE_FW_VERSION_BLDMSK)); |
| 16032 |
} |
| 16033 |
|
| 16034 |
static void tg3_read_otp_ver(struct tg3 *tp) |
| 16035 |
{ |
| 16036 |
u32 val, val2; |
| 16037 |
|
| 16038 |
if (tg3_asic_rev(tp) != ASIC_REV_5762) |
| 16039 |
return; |
| 16040 |
|
| 16041 |
if (!tg3_ape_otp_read(tp, OTP_ADDRESS_MAGIC0, &val) && |
| 16042 |
!tg3_ape_otp_read(tp, OTP_ADDRESS_MAGIC0 + 4, &val2) && |
| 16043 |
TG3_OTP_MAGIC0_VALID(val)) { |
| 16044 |
u64 val64 = (u64) val << 32 | val2; |
| 16045 |
u32 ver = 0; |
| 16046 |
int i, vlen; |
| 16047 |
|
| 16048 |
for (i = 0; i < 7; i++) { |
| 16049 |
if ((val64 & 0xff) == 0) |
| 16050 |
break; |
| 16051 |
ver = val64 & 0xff; |
| 16052 |
val64 >>= 8; |
| 16053 |
} |
| 16054 |
vlen = strlen(tp->fw_ver); |
| 16055 |
snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " .%02d", ver); |
| 16056 |
} |
| 16057 |
} |
| 16058 |
|
| 16059 |
static void tg3_read_fw_ver(struct tg3 *tp) |
| 16060 |
{ |
| 16061 |
u32 val; |
| 16062 |
bool vpd_vers = false; |
| 16063 |
|
| 16064 |
if (tp->fw_ver[0] != 0) |
| 16065 |
vpd_vers = true; |
| 16066 |
|
| 16067 |
if (tg3_flag(tp, NO_NVRAM)) { |
| 16068 |
strcat(tp->fw_ver, "sb"); |
| 16069 |
tg3_read_otp_ver(tp); |
| 16070 |
return; |
| 16071 |
} |
| 16072 |
|
| 16073 |
if (tg3_nvram_read(tp, 0, &val)) |
| 16074 |
return; |
| 16075 |
|
| 16076 |
if (val == TG3_EEPROM_MAGIC) |
| 16077 |
tg3_read_bc_ver(tp); |
| 16078 |
else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) |
| 16079 |
tg3_read_sb_ver(tp, val); |
| 16080 |
else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
| 16081 |
tg3_read_hwsb_ver(tp); |
| 16082 |
|
| 16083 |
if (tg3_flag(tp, ENABLE_ASF)) { |
| 16084 |
if (tg3_flag(tp, ENABLE_APE)) { |
| 16085 |
tg3_probe_ncsi(tp); |
| 16086 |
if (!vpd_vers) |
| 16087 |
tg3_read_dash_ver(tp); |
| 16088 |
} else if (!vpd_vers) { |
| 16089 |
tg3_read_mgmtfw_ver(tp); |
| 16090 |
} |
| 16091 |
} |
| 16092 |
|
| 16093 |
tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
| 16094 |
} |
| 16095 |
|
| 16096 |
static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
| 16097 |
{ |
| 16098 |
if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
| 16099 |
return TG3_RX_RET_MAX_SIZE_5717; |
| 16100 |
else if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) |
| 16101 |
return TG3_RX_RET_MAX_SIZE_5700; |
| 16102 |
else |
| 16103 |
return TG3_RX_RET_MAX_SIZE_5705; |
| 16104 |
} |
| 16105 |
|
| 16106 |
static const struct pci_device_id tg3_write_reorder_chipsets[] = { |
| 16107 |
{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
| 16108 |
{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
| 16109 |
{ PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8385_0) }, |
| 16110 |
{ }, |
| 16111 |
}; |
| 16112 |
|
| 16113 |
static struct pci_dev *tg3_find_peer(struct tg3 *tp) |
| 16114 |
{ |
| 16115 |
struct pci_dev *peer; |
| 16116 |
unsigned int func, devnr = tp->pdev->devfn & ~7; |
| 16117 |
|
| 16118 |
for (func = 0; func < 8; func++) { |
| 16119 |
peer = pci_get_slot(tp->pdev->bus, devnr | func); |
| 16120 |
if (peer && peer != tp->pdev) |
| 16121 |
break; |
| 16122 |
pci_dev_put(peer); |
| 16123 |
} |
| 16124 |
/* 5704 can be configured in single-port mode, set peer to |
| 16125 |
* tp->pdev in that case. |
| 16126 |
*/ |
| 16127 |
if (!peer) { |
| 16128 |
peer = tp->pdev; |
| 16129 |
return peer; |
| 16130 |
} |
| 16131 |
|
| 16132 |
/* |
| 16133 |
* We don't need to keep the refcount elevated; there's no way |
| 16134 |
* to remove one half of this device without removing the other |
| 16135 |
*/ |
| 16136 |
pci_dev_put(peer); |
| 16137 |
|
| 16138 |
return peer; |
| 16139 |
} |
| 16140 |
|
| 16141 |
static void tg3_detect_asic_rev(struct tg3 *tp, u32 misc_ctrl_reg) |
| 16142 |
{ |
| 16143 |
tp->pci_chip_rev_id = misc_ctrl_reg >> MISC_HOST_CTRL_CHIPREV_SHIFT; |
| 16144 |
if (tg3_asic_rev(tp) == ASIC_REV_USE_PROD_ID_REG) { |
| 16145 |
u32 reg; |
| 16146 |
|
| 16147 |
/* All devices that use the alternate |
| 16148 |
* ASIC REV location have a CPMU. |
| 16149 |
*/ |
| 16150 |
tg3_flag_set(tp, CPMU_PRESENT); |
| 16151 |
|
| 16152 |
if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 16153 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C || |
| 16154 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 16155 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
| 16156 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720 || |
| 16157 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57767 || |
| 16158 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57764 || |
| 16159 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5762 || |
| 16160 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725 || |
| 16161 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5727 || |
| 16162 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57787) |
| 16163 |
reg = TG3PCI_GEN2_PRODID_ASICREV; |
| 16164 |
else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
| 16165 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || |
| 16166 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || |
| 16167 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || |
| 16168 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
| 16169 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || |
| 16170 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762 || |
| 16171 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766 || |
| 16172 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782 || |
| 16173 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) |
| 16174 |
reg = TG3PCI_GEN15_PRODID_ASICREV; |
| 16175 |
else |
| 16176 |
reg = TG3PCI_PRODID_ASICREV; |
| 16177 |
|
| 16178 |
pci_read_config_dword(tp->pdev, reg, &tp->pci_chip_rev_id); |
| 16179 |
} |
| 16180 |
|
| 16181 |
/* Wrong chip ID in 5752 A0. This code can be removed later |
| 16182 |
* as A0 is not in production. |
| 16183 |
*/ |
| 16184 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5752_A0_HW) |
| 16185 |
tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
| 16186 |
|
| 16187 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5717_C0) |
| 16188 |
tp->pci_chip_rev_id = CHIPREV_ID_5720_A0; |
| 16189 |
|
| 16190 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 16191 |
tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 16192 |
tg3_asic_rev(tp) == ASIC_REV_5720) |
| 16193 |
tg3_flag_set(tp, 5717_PLUS); |
| 16194 |
|
| 16195 |
if (tg3_asic_rev(tp) == ASIC_REV_57765 || |
| 16196 |
tg3_asic_rev(tp) == ASIC_REV_57766) |
| 16197 |
tg3_flag_set(tp, 57765_CLASS); |
| 16198 |
|
| 16199 |
if (tg3_flag(tp, 57765_CLASS) || tg3_flag(tp, 5717_PLUS) || |
| 16200 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 16201 |
tg3_flag_set(tp, 57765_PLUS); |
| 16202 |
|
| 16203 |
/* Intentionally exclude ASIC_REV_5906 */ |
| 16204 |
if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
| 16205 |
tg3_asic_rev(tp) == ASIC_REV_5787 || |
| 16206 |
tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 16207 |
tg3_asic_rev(tp) == ASIC_REV_5761 || |
| 16208 |
tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 16209 |
tg3_asic_rev(tp) == ASIC_REV_57780 || |
| 16210 |
tg3_flag(tp, 57765_PLUS)) |
| 16211 |
tg3_flag_set(tp, 5755_PLUS); |
| 16212 |
|
| 16213 |
if (tg3_asic_rev(tp) == ASIC_REV_5780 || |
| 16214 |
tg3_asic_rev(tp) == ASIC_REV_5714) |
| 16215 |
tg3_flag_set(tp, 5780_CLASS); |
| 16216 |
|
| 16217 |
if (tg3_asic_rev(tp) == ASIC_REV_5750 || |
| 16218 |
tg3_asic_rev(tp) == ASIC_REV_5752 || |
| 16219 |
tg3_asic_rev(tp) == ASIC_REV_5906 || |
| 16220 |
tg3_flag(tp, 5755_PLUS) || |
| 16221 |
tg3_flag(tp, 5780_CLASS)) |
| 16222 |
tg3_flag_set(tp, 5750_PLUS); |
| 16223 |
|
| 16224 |
if (tg3_asic_rev(tp) == ASIC_REV_5705 || |
| 16225 |
tg3_flag(tp, 5750_PLUS)) |
| 16226 |
tg3_flag_set(tp, 5705_PLUS); |
| 16227 |
} |
| 16228 |
|
| 16229 |
static bool tg3_10_100_only_device(struct tg3 *tp, |
| 16230 |
const struct pci_device_id *ent) |
| 16231 |
{ |
| 16232 |
u32 grc_misc_cfg = tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK; |
| 16233 |
|
| 16234 |
if ((tg3_asic_rev(tp) == ASIC_REV_5703 && |
| 16235 |
(grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || |
| 16236 |
(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
| 16237 |
return true; |
| 16238 |
|
| 16239 |
if (ent->driver_data & TG3_DRV_DATA_FLAG_10_100_ONLY) { |
| 16240 |
if (tg3_asic_rev(tp) == ASIC_REV_5705) { |
| 16241 |
if (ent->driver_data & TG3_DRV_DATA_FLAG_5705_10_100) |
| 16242 |
return true; |
| 16243 |
} else { |
| 16244 |
return true; |
| 16245 |
} |
| 16246 |
} |
| 16247 |
|
| 16248 |
return false; |
| 16249 |
} |
| 16250 |
|
| 16251 |
static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent) |
| 16252 |
{ |
| 16253 |
u32 misc_ctrl_reg; |
| 16254 |
u32 pci_state_reg, grc_misc_cfg; |
| 16255 |
u32 val; |
| 16256 |
u16 pci_cmd; |
| 16257 |
int err; |
| 16258 |
|
| 16259 |
/* Force memory write invalidate off. If we leave it on, |
| 16260 |
* then on 5700_BX chips we have to enable a workaround. |
| 16261 |
* The workaround is to set the TG3PCI_DMA_RW_CTRL boundary |
| 16262 |
* to match the cacheline size. The Broadcom driver have this |
| 16263 |
* workaround but turns MWI off all the times so never uses |
| 16264 |
* it. This seems to suggest that the workaround is insufficient. |
| 16265 |
*/ |
| 16266 |
pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 16267 |
pci_cmd &= ~PCI_COMMAND_INVALIDATE; |
| 16268 |
pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 16269 |
|
| 16270 |
/* Important! -- Make sure register accesses are byteswapped |
| 16271 |
* correctly. Also, for those chips that require it, make |
| 16272 |
* sure that indirect register accesses are enabled before |
| 16273 |
* the first operation. |
| 16274 |
*/ |
| 16275 |
pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 16276 |
&misc_ctrl_reg); |
| 16277 |
tp->misc_host_ctrl |= (misc_ctrl_reg & |
| 16278 |
MISC_HOST_CTRL_CHIPREV); |
| 16279 |
pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 16280 |
tp->misc_host_ctrl); |
| 16281 |
|
| 16282 |
tg3_detect_asic_rev(tp, misc_ctrl_reg); |
| 16283 |
|
| 16284 |
/* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
| 16285 |
* we need to disable memory and use config. cycles |
| 16286 |
* only to access all registers. The 5702/03 chips |
| 16287 |
* can mistakenly decode the special cycles from the |
| 16288 |
* ICH chipsets as memory write cycles, causing corruption |
| 16289 |
* of register and memory space. Only certain ICH bridges |
| 16290 |
* will drive special cycles with non-zero data during the |
| 16291 |
* address phase which can fall within the 5703's address |
| 16292 |
* range. This is not an ICH bug as the PCI spec allows |
| 16293 |
* non-zero address during special cycles. However, only |
| 16294 |
* these ICH bridges are known to drive non-zero addresses |
| 16295 |
* during special cycles. |
| 16296 |
* |
| 16297 |
* Since special cycles do not cross PCI bridges, we only |
| 16298 |
* enable this workaround if the 5703 is on the secondary |
| 16299 |
* bus of these ICH bridges. |
| 16300 |
*/ |
| 16301 |
if ((tg3_chip_rev_id(tp) == CHIPREV_ID_5703_A1) || |
| 16302 |
(tg3_chip_rev_id(tp) == CHIPREV_ID_5703_A2)) { |
| 16303 |
static struct tg3_dev_id { |
| 16304 |
u32 vendor; |
| 16305 |
u32 device; |
| 16306 |
u32 rev; |
| 16307 |
} ich_chipsets[] = { |
| 16308 |
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, |
| 16309 |
PCI_ANY_ID }, |
| 16310 |
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, |
| 16311 |
PCI_ANY_ID }, |
| 16312 |
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, |
| 16313 |
0xa }, |
| 16314 |
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, |
| 16315 |
PCI_ANY_ID }, |
| 16316 |
{ }, |
| 16317 |
}; |
| 16318 |
struct tg3_dev_id *pci_id = &ich_chipsets[0]; |
| 16319 |
struct pci_dev *bridge = NULL; |
| 16320 |
|
| 16321 |
while (pci_id->vendor != 0) { |
| 16322 |
bridge = pci_get_device(pci_id->vendor, pci_id->device, |
| 16323 |
bridge); |
| 16324 |
if (!bridge) { |
| 16325 |
pci_id++; |
| 16326 |
continue; |
| 16327 |
} |
| 16328 |
if (pci_id->rev != PCI_ANY_ID) { |
| 16329 |
if (bridge->revision > pci_id->rev) |
| 16330 |
continue; |
| 16331 |
} |
| 16332 |
if (bridge->subordinate && |
| 16333 |
(bridge->subordinate->number == |
| 16334 |
tp->pdev->bus->number)) { |
| 16335 |
tg3_flag_set(tp, ICH_WORKAROUND); |
| 16336 |
pci_dev_put(bridge); |
| 16337 |
break; |
| 16338 |
} |
| 16339 |
} |
| 16340 |
} |
| 16341 |
|
| 16342 |
if (tg3_asic_rev(tp) == ASIC_REV_5701) { |
| 16343 |
static struct tg3_dev_id { |
| 16344 |
u32 vendor; |
| 16345 |
u32 device; |
| 16346 |
} bridge_chipsets[] = { |
| 16347 |
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, |
| 16348 |
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, |
| 16349 |
{ }, |
| 16350 |
}; |
| 16351 |
struct tg3_dev_id *pci_id = &bridge_chipsets[0]; |
| 16352 |
struct pci_dev *bridge = NULL; |
| 16353 |
|
| 16354 |
while (pci_id->vendor != 0) { |
| 16355 |
bridge = pci_get_device(pci_id->vendor, |
| 16356 |
pci_id->device, |
| 16357 |
bridge); |
| 16358 |
if (!bridge) { |
| 16359 |
pci_id++; |
| 16360 |
continue; |
| 16361 |
} |
| 16362 |
if (bridge->subordinate && |
| 16363 |
(bridge->subordinate->number <= |
| 16364 |
tp->pdev->bus->number) && |
| 16365 |
(bridge->subordinate->busn_res.end >= |
| 16366 |
tp->pdev->bus->number)) { |
| 16367 |
tg3_flag_set(tp, 5701_DMA_BUG); |
| 16368 |
pci_dev_put(bridge); |
| 16369 |
break; |
| 16370 |
} |
| 16371 |
} |
| 16372 |
} |
| 16373 |
|
| 16374 |
/* The EPB bridge inside 5714, 5715, and 5780 cannot support |
| 16375 |
* DMA addresses > 40-bit. This bridge may have other additional |
| 16376 |
* 57xx devices behind it in some 4-port NIC designs for example. |
| 16377 |
* Any tg3 device found behind the bridge will also need the 40-bit |
| 16378 |
* DMA workaround. |
| 16379 |
*/ |
| 16380 |
if (tg3_flag(tp, 5780_CLASS)) { |
| 16381 |
tg3_flag_set(tp, 40BIT_DMA_BUG); |
| 16382 |
tp->msi_cap = tp->pdev->msi_cap; |
| 16383 |
} else { |
| 16384 |
struct pci_dev *bridge = NULL; |
| 16385 |
|
| 16386 |
do { |
| 16387 |
bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, |
| 16388 |
PCI_DEVICE_ID_SERVERWORKS_EPB, |
| 16389 |
bridge); |
| 16390 |
if (bridge && bridge->subordinate && |
| 16391 |
(bridge->subordinate->number <= |
| 16392 |
tp->pdev->bus->number) && |
| 16393 |
(bridge->subordinate->busn_res.end >= |
| 16394 |
tp->pdev->bus->number)) { |
| 16395 |
tg3_flag_set(tp, 40BIT_DMA_BUG); |
| 16396 |
pci_dev_put(bridge); |
| 16397 |
break; |
| 16398 |
} |
| 16399 |
} while (bridge); |
| 16400 |
} |
| 16401 |
|
| 16402 |
if (tg3_asic_rev(tp) == ASIC_REV_5704 || |
| 16403 |
tg3_asic_rev(tp) == ASIC_REV_5714) |
| 16404 |
tp->pdev_peer = tg3_find_peer(tp); |
| 16405 |
|
| 16406 |
/* Determine TSO capabilities */ |
| 16407 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0) |
| 16408 |
; /* Do nothing. HW bug. */ |
| 16409 |
else if (tg3_flag(tp, 57765_PLUS)) |
| 16410 |
tg3_flag_set(tp, HW_TSO_3); |
| 16411 |
else if (tg3_flag(tp, 5755_PLUS) || |
| 16412 |
tg3_asic_rev(tp) == ASIC_REV_5906) |
| 16413 |
tg3_flag_set(tp, HW_TSO_2); |
| 16414 |
else if (tg3_flag(tp, 5750_PLUS)) { |
| 16415 |
tg3_flag_set(tp, HW_TSO_1); |
| 16416 |
tg3_flag_set(tp, TSO_BUG); |
| 16417 |
if (tg3_asic_rev(tp) == ASIC_REV_5750 && |
| 16418 |
tg3_chip_rev_id(tp) >= CHIPREV_ID_5750_C2) |
| 16419 |
tg3_flag_clear(tp, TSO_BUG); |
| 16420 |
} else if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
| 16421 |
tg3_asic_rev(tp) != ASIC_REV_5701 && |
| 16422 |
tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) { |
| 16423 |
tg3_flag_set(tp, FW_TSO); |
| 16424 |
tg3_flag_set(tp, TSO_BUG); |
| 16425 |
if (tg3_asic_rev(tp) == ASIC_REV_5705) |
| 16426 |
tp->fw_needed = FIRMWARE_TG3TSO5; |
| 16427 |
else |
| 16428 |
tp->fw_needed = FIRMWARE_TG3TSO; |
| 16429 |
} |
| 16430 |
|
| 16431 |
/* Selectively allow TSO based on operating conditions */ |
| 16432 |
if (tg3_flag(tp, HW_TSO_1) || |
| 16433 |
tg3_flag(tp, HW_TSO_2) || |
| 16434 |
tg3_flag(tp, HW_TSO_3) || |
| 16435 |
tg3_flag(tp, FW_TSO)) { |
| 16436 |
/* For firmware TSO, assume ASF is disabled. |
| 16437 |
* We'll disable TSO later if we discover ASF |
| 16438 |
* is enabled in tg3_get_eeprom_hw_cfg(). |
| 16439 |
*/ |
| 16440 |
tg3_flag_set(tp, TSO_CAPABLE); |
| 16441 |
} else { |
| 16442 |
tg3_flag_clear(tp, TSO_CAPABLE); |
| 16443 |
tg3_flag_clear(tp, TSO_BUG); |
| 16444 |
tp->fw_needed = NULL; |
| 16445 |
} |
| 16446 |
|
| 16447 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0) |
| 16448 |
tp->fw_needed = FIRMWARE_TG3; |
| 16449 |
|
| 16450 |
if (tg3_asic_rev(tp) == ASIC_REV_57766) |
| 16451 |
tp->fw_needed = FIRMWARE_TG357766; |
| 16452 |
|
| 16453 |
tp->irq_max = 1; |
| 16454 |
|
| 16455 |
if (tg3_flag(tp, 5750_PLUS)) { |
| 16456 |
tg3_flag_set(tp, SUPPORT_MSI); |
| 16457 |
if (tg3_chip_rev(tp) == CHIPREV_5750_AX || |
| 16458 |
tg3_chip_rev(tp) == CHIPREV_5750_BX || |
| 16459 |
(tg3_asic_rev(tp) == ASIC_REV_5714 && |
| 16460 |
tg3_chip_rev_id(tp) <= CHIPREV_ID_5714_A2 && |
| 16461 |
tp->pdev_peer == tp->pdev)) |
| 16462 |
tg3_flag_clear(tp, SUPPORT_MSI); |
| 16463 |
|
| 16464 |
if (tg3_flag(tp, 5755_PLUS) || |
| 16465 |
tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 16466 |
tg3_flag_set(tp, 1SHOT_MSI); |
| 16467 |
} |
| 16468 |
|
| 16469 |
if (tg3_flag(tp, 57765_PLUS)) { |
| 16470 |
tg3_flag_set(tp, SUPPORT_MSIX); |
| 16471 |
tp->irq_max = TG3_IRQ_MAX_VECS; |
| 16472 |
} |
| 16473 |
} |
| 16474 |
|
| 16475 |
tp->txq_max = 1; |
| 16476 |
tp->rxq_max = 1; |
| 16477 |
if (tp->irq_max > 1) { |
| 16478 |
tp->rxq_max = TG3_RSS_MAX_NUM_QS; |
| 16479 |
tg3_rss_init_dflt_indir_tbl(tp, TG3_RSS_MAX_NUM_QS); |
| 16480 |
|
| 16481 |
if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 16482 |
tg3_asic_rev(tp) == ASIC_REV_5720) |
| 16483 |
tp->txq_max = tp->irq_max - 1; |
| 16484 |
} |
| 16485 |
|
| 16486 |
if (tg3_flag(tp, 5755_PLUS) || |
| 16487 |
tg3_asic_rev(tp) == ASIC_REV_5906) |
| 16488 |
tg3_flag_set(tp, SHORT_DMA_BUG); |
| 16489 |
|
| 16490 |
if (tg3_asic_rev(tp) == ASIC_REV_5719) |
| 16491 |
tp->dma_limit = TG3_TX_BD_DMA_MAX_4K; |
| 16492 |
|
| 16493 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 16494 |
tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 16495 |
tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 16496 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 16497 |
tg3_flag_set(tp, LRG_PROD_RING_CAP); |
| 16498 |
|
| 16499 |
if (tg3_flag(tp, 57765_PLUS) && |
| 16500 |
tg3_chip_rev_id(tp) != CHIPREV_ID_5719_A0) |
| 16501 |
tg3_flag_set(tp, USE_JUMBO_BDFLAG); |
| 16502 |
|
| 16503 |
if (!tg3_flag(tp, 5705_PLUS) || |
| 16504 |
tg3_flag(tp, 5780_CLASS) || |
| 16505 |
tg3_flag(tp, USE_JUMBO_BDFLAG)) |
| 16506 |
tg3_flag_set(tp, JUMBO_CAPABLE); |
| 16507 |
|
| 16508 |
pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 16509 |
&pci_state_reg); |
| 16510 |
|
| 16511 |
if (pci_is_pcie(tp->pdev)) { |
| 16512 |
u16 lnkctl; |
| 16513 |
|
| 16514 |
tg3_flag_set(tp, PCI_EXPRESS); |
| 16515 |
|
| 16516 |
pcie_capability_read_word(tp->pdev, PCI_EXP_LNKCTL, &lnkctl); |
| 16517 |
if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
| 16518 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 16519 |
tg3_flag_clear(tp, HW_TSO_2); |
| 16520 |
tg3_flag_clear(tp, TSO_CAPABLE); |
| 16521 |
} |
| 16522 |
if (tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 16523 |
tg3_asic_rev(tp) == ASIC_REV_5761 || |
| 16524 |
tg3_chip_rev_id(tp) == CHIPREV_ID_57780_A0 || |
| 16525 |
tg3_chip_rev_id(tp) == CHIPREV_ID_57780_A1) |
| 16526 |
tg3_flag_set(tp, CLKREQ_BUG); |
| 16527 |
} else if (tg3_chip_rev_id(tp) == CHIPREV_ID_5717_A0) { |
| 16528 |
tg3_flag_set(tp, L1PLLPD_EN); |
| 16529 |
} |
| 16530 |
} else if (tg3_asic_rev(tp) == ASIC_REV_5785) { |
| 16531 |
/* BCM5785 devices are effectively PCIe devices, and should |
| 16532 |
* follow PCIe codepaths, but do not have a PCIe capabilities |
| 16533 |
* section. |
| 16534 |
*/ |
| 16535 |
tg3_flag_set(tp, PCI_EXPRESS); |
| 16536 |
} else if (!tg3_flag(tp, 5705_PLUS) || |
| 16537 |
tg3_flag(tp, 5780_CLASS)) { |
| 16538 |
tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
| 16539 |
if (!tp->pcix_cap) { |
| 16540 |
dev_err(&tp->pdev->dev, |
| 16541 |
"Cannot find PCI-X capability, aborting\n"); |
| 16542 |
return -EIO; |
| 16543 |
} |
| 16544 |
|
| 16545 |
if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) |
| 16546 |
tg3_flag_set(tp, PCIX_MODE); |
| 16547 |
} |
| 16548 |
|
| 16549 |
/* If we have an AMD 762 or VIA K8T800 chipset, write |
| 16550 |
* reordering to the mailbox registers done by the host |
| 16551 |
* controller can cause major troubles. We read back from |
| 16552 |
* every mailbox register write to force the writes to be |
| 16553 |
* posted to the chip in order. |
| 16554 |
*/ |
| 16555 |
if (pci_dev_present(tg3_write_reorder_chipsets) && |
| 16556 |
!tg3_flag(tp, PCI_EXPRESS)) |
| 16557 |
tg3_flag_set(tp, MBOX_WRITE_REORDER); |
| 16558 |
|
| 16559 |
pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
| 16560 |
&tp->pci_cacheline_sz); |
| 16561 |
pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 16562 |
&tp->pci_lat_timer); |
| 16563 |
if (tg3_asic_rev(tp) == ASIC_REV_5703 && |
| 16564 |
tp->pci_lat_timer < 64) { |
| 16565 |
tp->pci_lat_timer = 64; |
| 16566 |
pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
| 16567 |
tp->pci_lat_timer); |
| 16568 |
} |
| 16569 |
|
| 16570 |
/* Important! -- It is critical that the PCI-X hw workaround |
| 16571 |
* situation is decided before the first MMIO register access. |
| 16572 |
*/ |
| 16573 |
if (tg3_chip_rev(tp) == CHIPREV_5700_BX) { |
| 16574 |
/* 5700 BX chips need to have their TX producer index |
| 16575 |
* mailboxes written twice to workaround a bug. |
| 16576 |
*/ |
| 16577 |
tg3_flag_set(tp, TXD_MBOX_HWBUG); |
| 16578 |
|
| 16579 |
/* If we are in PCI-X mode, enable register write workaround. |
| 16580 |
* |
| 16581 |
* The workaround is to use indirect register accesses |
| 16582 |
* for all chip writes not to mailbox registers. |
| 16583 |
*/ |
| 16584 |
if (tg3_flag(tp, PCIX_MODE)) { |
| 16585 |
u32 pm_reg; |
| 16586 |
|
| 16587 |
tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
| 16588 |
|
| 16589 |
/* The chip can have its power management PCI config |
| 16590 |
* space registers clobbered due to this bug. |
| 16591 |
* So explicitly force the chip into D0 here. |
| 16592 |
*/ |
| 16593 |
pci_read_config_dword(tp->pdev, |
| 16594 |
tp->pdev->pm_cap + PCI_PM_CTRL, |
| 16595 |
&pm_reg); |
| 16596 |
pm_reg &= ~PCI_PM_CTRL_STATE_MASK; |
| 16597 |
pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; |
| 16598 |
pci_write_config_dword(tp->pdev, |
| 16599 |
tp->pdev->pm_cap + PCI_PM_CTRL, |
| 16600 |
pm_reg); |
| 16601 |
|
| 16602 |
/* Also, force SERR#/PERR# in PCI command. */ |
| 16603 |
pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 16604 |
pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; |
| 16605 |
pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 16606 |
} |
| 16607 |
} |
| 16608 |
|
| 16609 |
if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
| 16610 |
tg3_flag_set(tp, PCI_HIGH_SPEED); |
| 16611 |
if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
| 16612 |
tg3_flag_set(tp, PCI_32BIT); |
| 16613 |
|
| 16614 |
/* Chip-specific fixup from Broadcom driver */ |
| 16615 |
if ((tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0) && |
| 16616 |
(!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
| 16617 |
pci_state_reg |= PCISTATE_RETRY_SAME_DMA; |
| 16618 |
pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); |
| 16619 |
} |
| 16620 |
|
| 16621 |
/* Default fast path register access methods */ |
| 16622 |
tp->read32 = tg3_read32; |
| 16623 |
tp->write32 = tg3_write32; |
| 16624 |
tp->read32_mbox = tg3_read32; |
| 16625 |
tp->write32_mbox = tg3_write32; |
| 16626 |
tp->write32_tx_mbox = tg3_write32; |
| 16627 |
tp->write32_rx_mbox = tg3_write32; |
| 16628 |
|
| 16629 |
/* Various workaround register access methods */ |
| 16630 |
if (tg3_flag(tp, PCIX_TARGET_HWBUG)) |
| 16631 |
tp->write32 = tg3_write_indirect_reg32; |
| 16632 |
else if (tg3_asic_rev(tp) == ASIC_REV_5701 || |
| 16633 |
(tg3_flag(tp, PCI_EXPRESS) && |
| 16634 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5750_A0)) { |
| 16635 |
/* |
| 16636 |
* Back to back register writes can cause problems on these |
| 16637 |
* chips, the workaround is to read back all reg writes |
| 16638 |
* except those to mailbox regs. |
| 16639 |
* |
| 16640 |
* See tg3_write_indirect_reg32(). |
| 16641 |
*/ |
| 16642 |
tp->write32 = tg3_write_flush_reg32; |
| 16643 |
} |
| 16644 |
|
| 16645 |
if (tg3_flag(tp, TXD_MBOX_HWBUG) || tg3_flag(tp, MBOX_WRITE_REORDER)) { |
| 16646 |
tp->write32_tx_mbox = tg3_write32_tx_mbox; |
| 16647 |
if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
| 16648 |
tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 16649 |
} |
| 16650 |
|
| 16651 |
if (tg3_flag(tp, ICH_WORKAROUND)) { |
| 16652 |
tp->read32 = tg3_read_indirect_reg32; |
| 16653 |
tp->write32 = tg3_write_indirect_reg32; |
| 16654 |
tp->read32_mbox = tg3_read_indirect_mbox; |
| 16655 |
tp->write32_mbox = tg3_write_indirect_mbox; |
| 16656 |
tp->write32_tx_mbox = tg3_write_indirect_mbox; |
| 16657 |
tp->write32_rx_mbox = tg3_write_indirect_mbox; |
| 16658 |
|
| 16659 |
iounmap(tp->regs); |
| 16660 |
tp->regs = NULL; |
| 16661 |
|
| 16662 |
pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); |
| 16663 |
pci_cmd &= ~PCI_COMMAND_MEMORY; |
| 16664 |
pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); |
| 16665 |
} |
| 16666 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 16667 |
tp->read32_mbox = tg3_read32_mbox_5906; |
| 16668 |
tp->write32_mbox = tg3_write32_mbox_5906; |
| 16669 |
tp->write32_tx_mbox = tg3_write32_mbox_5906; |
| 16670 |
tp->write32_rx_mbox = tg3_write32_mbox_5906; |
| 16671 |
} |
| 16672 |
|
| 16673 |
if (tp->write32 == tg3_write_indirect_reg32 || |
| 16674 |
(tg3_flag(tp, PCIX_MODE) && |
| 16675 |
(tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 16676 |
tg3_asic_rev(tp) == ASIC_REV_5701))) |
| 16677 |
tg3_flag_set(tp, SRAM_USE_CONFIG); |
| 16678 |
|
| 16679 |
/* The memory arbiter has to be enabled in order for SRAM accesses |
| 16680 |
* to succeed. Normally on powerup the tg3 chip firmware will make |
| 16681 |
* sure it is enabled, but other entities such as system netboot |
| 16682 |
* code might disable it. |
| 16683 |
*/ |
| 16684 |
val = tr32(MEMARB_MODE); |
| 16685 |
tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
| 16686 |
|
| 16687 |
tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3; |
| 16688 |
if (tg3_asic_rev(tp) == ASIC_REV_5704 || |
| 16689 |
tg3_flag(tp, 5780_CLASS)) { |
| 16690 |
if (tg3_flag(tp, PCIX_MODE)) { |
| 16691 |
pci_read_config_dword(tp->pdev, |
| 16692 |
tp->pcix_cap + PCI_X_STATUS, |
| 16693 |
&val); |
| 16694 |
tp->pci_fn = val & 0x7; |
| 16695 |
} |
| 16696 |
} else if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 16697 |
tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 16698 |
tg3_asic_rev(tp) == ASIC_REV_5720) { |
| 16699 |
tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val); |
| 16700 |
if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) != NIC_SRAM_CPMUSTAT_SIG) |
| 16701 |
val = tr32(TG3_CPMU_STATUS); |
| 16702 |
|
| 16703 |
if (tg3_asic_rev(tp) == ASIC_REV_5717) |
| 16704 |
tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5717) ? 1 : 0; |
| 16705 |
else |
| 16706 |
tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5719) >> |
| 16707 |
TG3_CPMU_STATUS_FSHFT_5719; |
| 16708 |
} |
| 16709 |
|
| 16710 |
if (tg3_flag(tp, FLUSH_POSTED_WRITES)) { |
| 16711 |
tp->write32_tx_mbox = tg3_write_flush_reg32; |
| 16712 |
tp->write32_rx_mbox = tg3_write_flush_reg32; |
| 16713 |
} |
| 16714 |
|
| 16715 |
/* Get eeprom hw config before calling tg3_set_power_state(). |
| 16716 |
* In particular, the TG3_FLAG_IS_NIC flag must be |
| 16717 |
* determined before calling tg3_set_power_state() so that |
| 16718 |
* we know whether or not to switch out of Vaux power. |
| 16719 |
* When the flag is set, it means that GPIO1 is used for eeprom |
| 16720 |
* write protect and also implies that it is a LOM where GPIOs |
| 16721 |
* are not used to switch power. |
| 16722 |
*/ |
| 16723 |
tg3_get_eeprom_hw_cfg(tp); |
| 16724 |
|
| 16725 |
if (tg3_flag(tp, FW_TSO) && tg3_flag(tp, ENABLE_ASF)) { |
| 16726 |
tg3_flag_clear(tp, TSO_CAPABLE); |
| 16727 |
tg3_flag_clear(tp, TSO_BUG); |
| 16728 |
tp->fw_needed = NULL; |
| 16729 |
} |
| 16730 |
|
| 16731 |
if (tg3_flag(tp, ENABLE_APE)) { |
| 16732 |
/* Allow reads and writes to the |
| 16733 |
* APE register and memory space. |
| 16734 |
*/ |
| 16735 |
pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
| 16736 |
PCISTATE_ALLOW_APE_SHMEM_WR | |
| 16737 |
PCISTATE_ALLOW_APE_PSPACE_WR; |
| 16738 |
pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 16739 |
pci_state_reg); |
| 16740 |
|
| 16741 |
tg3_ape_lock_init(tp); |
| 16742 |
tp->ape_hb_interval = |
| 16743 |
msecs_to_jiffies(APE_HOST_HEARTBEAT_INT_5SEC); |
| 16744 |
} |
| 16745 |
|
| 16746 |
/* Set up tp->grc_local_ctrl before calling |
| 16747 |
* tg3_pwrsrc_switch_to_vmain(). GPIO1 driven high |
| 16748 |
* will bring 5700's external PHY out of reset. |
| 16749 |
* It is also used as eeprom write protect on LOMs. |
| 16750 |
*/ |
| 16751 |
tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; |
| 16752 |
if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 16753 |
tg3_flag(tp, EEPROM_WRITE_PROT)) |
| 16754 |
tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
| 16755 |
GRC_LCLCTRL_GPIO_OUTPUT1); |
| 16756 |
/* Unused GPIO3 must be driven as output on 5752 because there |
| 16757 |
* are no pull-up resistors on unused GPIO pins. |
| 16758 |
*/ |
| 16759 |
else if (tg3_asic_rev(tp) == ASIC_REV_5752) |
| 16760 |
tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
| 16761 |
|
| 16762 |
if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
| 16763 |
tg3_asic_rev(tp) == ASIC_REV_57780 || |
| 16764 |
tg3_flag(tp, 57765_CLASS)) |
| 16765 |
tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 16766 |
|
| 16767 |
if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 16768 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { |
| 16769 |
/* Turn off the debug UART. */ |
| 16770 |
tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
| 16771 |
if (tg3_flag(tp, IS_NIC)) |
| 16772 |
/* Keep VMain power. */ |
| 16773 |
tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
| 16774 |
GRC_LCLCTRL_GPIO_OUTPUT0; |
| 16775 |
} |
| 16776 |
|
| 16777 |
if (tg3_asic_rev(tp) == ASIC_REV_5762) |
| 16778 |
tp->grc_local_ctrl |= |
| 16779 |
tr32(GRC_LOCAL_CTRL) & GRC_LCLCTRL_GPIO_UART_SEL; |
| 16780 |
|
| 16781 |
/* Switch out of Vaux if it is a NIC */ |
| 16782 |
tg3_pwrsrc_switch_to_vmain(tp); |
| 16783 |
|
| 16784 |
/* Derive initial jumbo mode from MTU assigned in |
| 16785 |
* ether_setup() via the alloc_etherdev() call |
| 16786 |
*/ |
| 16787 |
if (tp->dev->mtu > ETH_DATA_LEN && !tg3_flag(tp, 5780_CLASS)) |
| 16788 |
tg3_flag_set(tp, JUMBO_RING_ENABLE); |
| 16789 |
|
| 16790 |
/* Determine WakeOnLan speed to use. */ |
| 16791 |
if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 16792 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
| 16793 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0 || |
| 16794 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B2) { |
| 16795 |
tg3_flag_clear(tp, WOL_SPEED_100MB); |
| 16796 |
} else { |
| 16797 |
tg3_flag_set(tp, WOL_SPEED_100MB); |
| 16798 |
} |
| 16799 |
|
| 16800 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) |
| 16801 |
tp->phy_flags |= TG3_PHYFLG_IS_FET; |
| 16802 |
|
| 16803 |
/* A few boards don't want Ethernet@WireSpeed phy feature */ |
| 16804 |
if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 16805 |
(tg3_asic_rev(tp) == ASIC_REV_5705 && |
| 16806 |
(tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) && |
| 16807 |
(tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A1)) || |
| 16808 |
(tp->phy_flags & TG3_PHYFLG_IS_FET) || |
| 16809 |
(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
| 16810 |
tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; |
| 16811 |
|
| 16812 |
if (tg3_chip_rev(tp) == CHIPREV_5703_AX || |
| 16813 |
tg3_chip_rev(tp) == CHIPREV_5704_AX) |
| 16814 |
tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
| 16815 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0) |
| 16816 |
tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
| 16817 |
|
| 16818 |
if (tg3_flag(tp, 5705_PLUS) && |
| 16819 |
!(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
| 16820 |
tg3_asic_rev(tp) != ASIC_REV_5785 && |
| 16821 |
tg3_asic_rev(tp) != ASIC_REV_57780 && |
| 16822 |
!tg3_flag(tp, 57765_PLUS)) { |
| 16823 |
if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
| 16824 |
tg3_asic_rev(tp) == ASIC_REV_5787 || |
| 16825 |
tg3_asic_rev(tp) == ASIC_REV_5784 || |
| 16826 |
tg3_asic_rev(tp) == ASIC_REV_5761) { |
| 16827 |
if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
| 16828 |
tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) |
| 16829 |
tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
| 16830 |
if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
| 16831 |
tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
| 16832 |
} else |
| 16833 |
tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
| 16834 |
} |
| 16835 |
|
| 16836 |
if (tg3_asic_rev(tp) == ASIC_REV_5784 && |
| 16837 |
tg3_chip_rev(tp) != CHIPREV_5784_AX) { |
| 16838 |
tp->phy_otp = tg3_read_otp_phycfg(tp); |
| 16839 |
if (tp->phy_otp == 0) |
| 16840 |
tp->phy_otp = TG3_OTP_DEFAULT; |
| 16841 |
} |
| 16842 |
|
| 16843 |
if (tg3_flag(tp, CPMU_PRESENT)) |
| 16844 |
tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
| 16845 |
else |
| 16846 |
tp->mi_mode = MAC_MI_MODE_BASE; |
| 16847 |
|
| 16848 |
tp->coalesce_mode = 0; |
| 16849 |
if (tg3_chip_rev(tp) != CHIPREV_5700_AX && |
| 16850 |
tg3_chip_rev(tp) != CHIPREV_5700_BX) |
| 16851 |
tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
| 16852 |
|
| 16853 |
/* Set these bits to enable statistics workaround. */ |
| 16854 |
if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
| 16855 |
tg3_asic_rev(tp) == ASIC_REV_5762 || |
| 16856 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || |
| 16857 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5720_A0) { |
| 16858 |
tp->coalesce_mode |= HOSTCC_MODE_ATTN; |
| 16859 |
tp->grc_mode |= GRC_MODE_IRQ_ON_FLOW_ATTN; |
| 16860 |
} |
| 16861 |
|
| 16862 |
if (tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 16863 |
tg3_asic_rev(tp) == ASIC_REV_57780) |
| 16864 |
tg3_flag_set(tp, USE_PHYLIB); |
| 16865 |
|
| 16866 |
err = tg3_mdio_init(tp); |
| 16867 |
if (err) |
| 16868 |
return err; |
| 16869 |
|
| 16870 |
/* Initialize data/descriptor byte/word swapping. */ |
| 16871 |
val = tr32(GRC_MODE); |
| 16872 |
if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 16873 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 16874 |
val &= (GRC_MODE_BYTE_SWAP_B2HRX_DATA | |
| 16875 |
GRC_MODE_WORD_SWAP_B2HRX_DATA | |
| 16876 |
GRC_MODE_B2HRX_ENABLE | |
| 16877 |
GRC_MODE_HTX2B_ENABLE | |
| 16878 |
GRC_MODE_HOST_STACKUP); |
| 16879 |
else |
| 16880 |
val &= GRC_MODE_HOST_STACKUP; |
| 16881 |
|
| 16882 |
tw32(GRC_MODE, val | tp->grc_mode); |
| 16883 |
|
| 16884 |
tg3_switch_clocks(tp); |
| 16885 |
|
| 16886 |
/* Clear this out for sanity. */ |
| 16887 |
tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 16888 |
|
| 16889 |
/* Clear TG3PCI_REG_BASE_ADDR to prevent hangs. */ |
| 16890 |
tw32(TG3PCI_REG_BASE_ADDR, 0); |
| 16891 |
|
| 16892 |
pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
| 16893 |
&pci_state_reg); |
| 16894 |
if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && |
| 16895 |
!tg3_flag(tp, PCIX_TARGET_HWBUG)) { |
| 16896 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
| 16897 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0 || |
| 16898 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B2 || |
| 16899 |
tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B5) { |
| 16900 |
void __iomem *sram_base; |
| 16901 |
|
| 16902 |
/* Write some dummy words into the SRAM status block |
| 16903 |
* area, see if it reads back correctly. If the return |
| 16904 |
* value is bad, force enable the PCIX workaround. |
| 16905 |
*/ |
| 16906 |
sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; |
| 16907 |
|
| 16908 |
writel(0x00000000, sram_base); |
| 16909 |
writel(0x00000000, sram_base + 4); |
| 16910 |
writel(0xffffffff, sram_base + 4); |
| 16911 |
if (readl(sram_base) != 0x00000000) |
| 16912 |
tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
| 16913 |
} |
| 16914 |
} |
| 16915 |
|
| 16916 |
udelay(50); |
| 16917 |
tg3_nvram_init(tp); |
| 16918 |
|
| 16919 |
/* If the device has an NVRAM, no need to load patch firmware */ |
| 16920 |
if (tg3_asic_rev(tp) == ASIC_REV_57766 && |
| 16921 |
!tg3_flag(tp, NO_NVRAM)) |
| 16922 |
tp->fw_needed = NULL; |
| 16923 |
|
| 16924 |
grc_misc_cfg = tr32(GRC_MISC_CFG); |
| 16925 |
grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; |
| 16926 |
|
| 16927 |
if (tg3_asic_rev(tp) == ASIC_REV_5705 && |
| 16928 |
(grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
| 16929 |
grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) |
| 16930 |
tg3_flag_set(tp, IS_5788); |
| 16931 |
|
| 16932 |
if (!tg3_flag(tp, IS_5788) && |
| 16933 |
tg3_asic_rev(tp) != ASIC_REV_5700) |
| 16934 |
tg3_flag_set(tp, TAGGED_STATUS); |
| 16935 |
if (tg3_flag(tp, TAGGED_STATUS)) { |
| 16936 |
tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
| 16937 |
HOSTCC_MODE_CLRTICK_TXBD); |
| 16938 |
|
| 16939 |
tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; |
| 16940 |
pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, |
| 16941 |
tp->misc_host_ctrl); |
| 16942 |
} |
| 16943 |
|
| 16944 |
/* Preserve the APE MAC_MODE bits */ |
| 16945 |
if (tg3_flag(tp, ENABLE_APE)) |
| 16946 |
tp->mac_mode = MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
| 16947 |
else |
| 16948 |
tp->mac_mode = 0; |
| 16949 |
|
| 16950 |
if (tg3_10_100_only_device(tp, ent)) |
| 16951 |
tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; |
| 16952 |
|
| 16953 |
err = tg3_phy_probe(tp); |
| 16954 |
if (err) { |
| 16955 |
dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
| 16956 |
/* ... but do not return immediately ... */ |
| 16957 |
tg3_mdio_fini(tp); |
| 16958 |
} |
| 16959 |
|
| 16960 |
tg3_read_vpd(tp); |
| 16961 |
tg3_read_fw_ver(tp); |
| 16962 |
|
| 16963 |
if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
| 16964 |
tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
| 16965 |
} else { |
| 16966 |
if (tg3_asic_rev(tp) == ASIC_REV_5700) |
| 16967 |
tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
| 16968 |
else |
| 16969 |
tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
| 16970 |
} |
| 16971 |
|
| 16972 |
/* 5700 {AX,BX} chips have a broken status block link |
| 16973 |
* change bit implementation, so we must use the |
| 16974 |
* status register in those cases. |
| 16975 |
*/ |
| 16976 |
if (tg3_asic_rev(tp) == ASIC_REV_5700) |
| 16977 |
tg3_flag_set(tp, USE_LINKCHG_REG); |
| 16978 |
else |
| 16979 |
tg3_flag_clear(tp, USE_LINKCHG_REG); |
| 16980 |
|
| 16981 |
/* The led_ctrl is set during tg3_phy_probe, here we might |
| 16982 |
* have to force the link status polling mechanism based |
| 16983 |
* upon subsystem IDs. |
| 16984 |
*/ |
| 16985 |
if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && |
| 16986 |
tg3_asic_rev(tp) == ASIC_REV_5701 && |
| 16987 |
!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
| 16988 |
tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
| 16989 |
tg3_flag_set(tp, USE_LINKCHG_REG); |
| 16990 |
} |
| 16991 |
|
| 16992 |
/* For all SERDES we poll the MAC status register. */ |
| 16993 |
if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
| 16994 |
tg3_flag_set(tp, POLL_SERDES); |
| 16995 |
else |
| 16996 |
tg3_flag_clear(tp, POLL_SERDES); |
| 16997 |
|
| 16998 |
if (tg3_flag(tp, ENABLE_APE) && tg3_flag(tp, ENABLE_ASF)) |
| 16999 |
tg3_flag_set(tp, POLL_CPMU_LINK); |
| 17000 |
|
| 17001 |
tp->rx_offset = NET_SKB_PAD + NET_IP_ALIGN; |
| 17002 |
tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
| 17003 |
if (tg3_asic_rev(tp) == ASIC_REV_5701 && |
| 17004 |
tg3_flag(tp, PCIX_MODE)) { |
| 17005 |
tp->rx_offset = NET_SKB_PAD; |
| 17006 |
#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
| 17007 |
tp->rx_copy_thresh = ~(u16)0; |
| 17008 |
#endif |
| 17009 |
} |
| 17010 |
|
| 17011 |
tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
| 17012 |
tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; |
| 17013 |
tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
| 17014 |
|
| 17015 |
tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
| 17016 |
|
| 17017 |
/* Increment the rx prod index on the rx std ring by at most |
| 17018 |
* 8 for these chips to workaround hw errata. |
| 17019 |
*/ |
| 17020 |
if (tg3_asic_rev(tp) == ASIC_REV_5750 || |
| 17021 |
tg3_asic_rev(tp) == ASIC_REV_5752 || |
| 17022 |
tg3_asic_rev(tp) == ASIC_REV_5755) |
| 17023 |
tp->rx_std_max_post = 8; |
| 17024 |
|
| 17025 |
if (tg3_flag(tp, ASPM_WORKAROUND)) |
| 17026 |
tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
| 17027 |
PCIE_PWR_MGMT_L1_THRESH_MSK; |
| 17028 |
|
| 17029 |
return err; |
| 17030 |
} |
| 17031 |
|
| 17032 |
static int tg3_is_default_mac_address(u8 *addr) |
| 17033 |
{ |
| 17034 |
static const u8 default_mac_address[ETH_ALEN] = { 0x00, 0x10, 0x18, 0x00, 0x00, 0x00 }; |
| 17035 |
|
| 17036 |
return ether_addr_equal(default_mac_address, addr); |
| 17037 |
} |
| 17038 |
|
| 17039 |
static int tg3_get_device_address(struct tg3 *tp, u8 *addr) |
| 17040 |
{ |
| 17041 |
u32 hi, lo, mac_offset; |
| 17042 |
int addr_ok = 0; |
| 17043 |
int err; |
| 17044 |
|
| 17045 |
if (!eth_platform_get_mac_address(&tp->pdev->dev, addr)) |
| 17046 |
return 0; |
| 17047 |
|
| 17048 |
if (tg3_flag(tp, IS_SSB_CORE)) { |
| 17049 |
err = ssb_gige_get_macaddr(tp->pdev, addr); |
| 17050 |
if (!err && is_valid_ether_addr(addr)) |
| 17051 |
return 0; |
| 17052 |
} |
| 17053 |
|
| 17054 |
mac_offset = 0x7c; |
| 17055 |
if (tg3_asic_rev(tp) == ASIC_REV_5704 || |
| 17056 |
tg3_flag(tp, 5780_CLASS)) { |
| 17057 |
if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
| 17058 |
mac_offset = 0xcc; |
| 17059 |
if (tg3_nvram_lock(tp)) |
| 17060 |
tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); |
| 17061 |
else |
| 17062 |
tg3_nvram_unlock(tp); |
| 17063 |
} else if (tg3_flag(tp, 5717_PLUS)) { |
| 17064 |
if (tp->pci_fn & 1) |
| 17065 |
mac_offset = 0xcc; |
| 17066 |
if (tp->pci_fn > 1) |
| 17067 |
mac_offset += 0x18c; |
| 17068 |
} else if (tg3_asic_rev(tp) == ASIC_REV_5906) |
| 17069 |
mac_offset = 0x10; |
| 17070 |
|
| 17071 |
/* First try to get it from MAC address mailbox. */ |
| 17072 |
tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); |
| 17073 |
if ((hi >> 16) == 0x484b) { |
| 17074 |
addr[0] = (hi >> 8) & 0xff; |
| 17075 |
addr[1] = (hi >> 0) & 0xff; |
| 17076 |
|
| 17077 |
tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); |
| 17078 |
addr[2] = (lo >> 24) & 0xff; |
| 17079 |
addr[3] = (lo >> 16) & 0xff; |
| 17080 |
addr[4] = (lo >> 8) & 0xff; |
| 17081 |
addr[5] = (lo >> 0) & 0xff; |
| 17082 |
|
| 17083 |
/* Some old bootcode may report a 0 MAC address in SRAM */ |
| 17084 |
addr_ok = is_valid_ether_addr(addr); |
| 17085 |
} |
| 17086 |
if (!addr_ok) { |
| 17087 |
__be32 be_hi, be_lo; |
| 17088 |
|
| 17089 |
/* Next, try NVRAM. */ |
| 17090 |
if (!tg3_flag(tp, NO_NVRAM) && |
| 17091 |
!tg3_nvram_read_be32(tp, mac_offset + 0, &be_hi) && |
| 17092 |
!tg3_nvram_read_be32(tp, mac_offset + 4, &be_lo)) { |
| 17093 |
memcpy(&addr[0], ((char *)&be_hi) + 2, 2); |
| 17094 |
memcpy(&addr[2], (char *)&be_lo, sizeof(be_lo)); |
| 17095 |
} |
| 17096 |
/* Finally just fetch it out of the MAC control regs. */ |
| 17097 |
else { |
| 17098 |
hi = tr32(MAC_ADDR_0_HIGH); |
| 17099 |
lo = tr32(MAC_ADDR_0_LOW); |
| 17100 |
|
| 17101 |
addr[5] = lo & 0xff; |
| 17102 |
addr[4] = (lo >> 8) & 0xff; |
| 17103 |
addr[3] = (lo >> 16) & 0xff; |
| 17104 |
addr[2] = (lo >> 24) & 0xff; |
| 17105 |
addr[1] = hi & 0xff; |
| 17106 |
addr[0] = (hi >> 8) & 0xff; |
| 17107 |
} |
| 17108 |
} |
| 17109 |
|
| 17110 |
if (!is_valid_ether_addr(addr)) |
| 17111 |
return -EINVAL; |
| 17112 |
|
| 17113 |
if (tg3_is_default_mac_address(addr)) |
| 17114 |
return device_get_mac_address(&tp->pdev->dev, addr); |
| 17115 |
|
| 17116 |
return 0; |
| 17117 |
} |
| 17118 |
|
| 17119 |
#define BOUNDARY_SINGLE_CACHELINE 1 |
| 17120 |
#define BOUNDARY_MULTI_CACHELINE 2 |
| 17121 |
|
| 17122 |
static u32 tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
| 17123 |
{ |
| 17124 |
int cacheline_size; |
| 17125 |
u8 byte; |
| 17126 |
int goal; |
| 17127 |
|
| 17128 |
pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); |
| 17129 |
if (byte == 0) |
| 17130 |
cacheline_size = 1024; |
| 17131 |
else |
| 17132 |
cacheline_size = (int) byte * 4; |
| 17133 |
|
| 17134 |
/* On 5703 and later chips, the boundary bits have no |
| 17135 |
* effect. |
| 17136 |
*/ |
| 17137 |
if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
| 17138 |
tg3_asic_rev(tp) != ASIC_REV_5701 && |
| 17139 |
!tg3_flag(tp, PCI_EXPRESS)) |
| 17140 |
goto out; |
| 17141 |
|
| 17142 |
#if defined(CONFIG_PPC64) || defined(CONFIG_PARISC) |
| 17143 |
goal = BOUNDARY_MULTI_CACHELINE; |
| 17144 |
#else |
| 17145 |
#if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) |
| 17146 |
goal = BOUNDARY_SINGLE_CACHELINE; |
| 17147 |
#else |
| 17148 |
goal = 0; |
| 17149 |
#endif |
| 17150 |
#endif |
| 17151 |
|
| 17152 |
if (tg3_flag(tp, 57765_PLUS)) { |
| 17153 |
val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
| 17154 |
goto out; |
| 17155 |
} |
| 17156 |
|
| 17157 |
if (!goal) |
| 17158 |
goto out; |
| 17159 |
|
| 17160 |
/* PCI controllers on most RISC systems tend to disconnect |
| 17161 |
* when a device tries to burst across a cache-line boundary. |
| 17162 |
* Therefore, letting tg3 do so just wastes PCI bandwidth. |
| 17163 |
* |
| 17164 |
* Unfortunately, for PCI-E there are only limited |
| 17165 |
* write-side controls for this, and thus for reads |
| 17166 |
* we will still get the disconnects. We'll also waste |
| 17167 |
* these PCI cycles for both read and write for chips |
| 17168 |
* other than 5700 and 5701 which do not implement the |
| 17169 |
* boundary bits. |
| 17170 |
*/ |
| 17171 |
if (tg3_flag(tp, PCIX_MODE) && !tg3_flag(tp, PCI_EXPRESS)) { |
| 17172 |
switch (cacheline_size) { |
| 17173 |
case 16: |
| 17174 |
case 32: |
| 17175 |
case 64: |
| 17176 |
case 128: |
| 17177 |
if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 17178 |
val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | |
| 17179 |
DMA_RWCTRL_WRITE_BNDRY_128_PCIX); |
| 17180 |
} else { |
| 17181 |
val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 17182 |
DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 17183 |
} |
| 17184 |
break; |
| 17185 |
|
| 17186 |
case 256: |
| 17187 |
val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | |
| 17188 |
DMA_RWCTRL_WRITE_BNDRY_256_PCIX); |
| 17189 |
break; |
| 17190 |
|
| 17191 |
default: |
| 17192 |
val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | |
| 17193 |
DMA_RWCTRL_WRITE_BNDRY_384_PCIX); |
| 17194 |
break; |
| 17195 |
} |
| 17196 |
} else if (tg3_flag(tp, PCI_EXPRESS)) { |
| 17197 |
switch (cacheline_size) { |
| 17198 |
case 16: |
| 17199 |
case 32: |
| 17200 |
case 64: |
| 17201 |
if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 17202 |
val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 17203 |
val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; |
| 17204 |
break; |
| 17205 |
} |
| 17206 |
fallthrough; |
| 17207 |
case 128: |
| 17208 |
default: |
| 17209 |
val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; |
| 17210 |
val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; |
| 17211 |
break; |
| 17212 |
} |
| 17213 |
} else { |
| 17214 |
switch (cacheline_size) { |
| 17215 |
case 16: |
| 17216 |
if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 17217 |
val |= (DMA_RWCTRL_READ_BNDRY_16 | |
| 17218 |
DMA_RWCTRL_WRITE_BNDRY_16); |
| 17219 |
break; |
| 17220 |
} |
| 17221 |
fallthrough; |
| 17222 |
case 32: |
| 17223 |
if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 17224 |
val |= (DMA_RWCTRL_READ_BNDRY_32 | |
| 17225 |
DMA_RWCTRL_WRITE_BNDRY_32); |
| 17226 |
break; |
| 17227 |
} |
| 17228 |
fallthrough; |
| 17229 |
case 64: |
| 17230 |
if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 17231 |
val |= (DMA_RWCTRL_READ_BNDRY_64 | |
| 17232 |
DMA_RWCTRL_WRITE_BNDRY_64); |
| 17233 |
break; |
| 17234 |
} |
| 17235 |
fallthrough; |
| 17236 |
case 128: |
| 17237 |
if (goal == BOUNDARY_SINGLE_CACHELINE) { |
| 17238 |
val |= (DMA_RWCTRL_READ_BNDRY_128 | |
| 17239 |
DMA_RWCTRL_WRITE_BNDRY_128); |
| 17240 |
break; |
| 17241 |
} |
| 17242 |
fallthrough; |
| 17243 |
case 256: |
| 17244 |
val |= (DMA_RWCTRL_READ_BNDRY_256 | |
| 17245 |
DMA_RWCTRL_WRITE_BNDRY_256); |
| 17246 |
break; |
| 17247 |
case 512: |
| 17248 |
val |= (DMA_RWCTRL_READ_BNDRY_512 | |
| 17249 |
DMA_RWCTRL_WRITE_BNDRY_512); |
| 17250 |
break; |
| 17251 |
case 1024: |
| 17252 |
default: |
| 17253 |
val |= (DMA_RWCTRL_READ_BNDRY_1024 | |
| 17254 |
DMA_RWCTRL_WRITE_BNDRY_1024); |
| 17255 |
break; |
| 17256 |
} |
| 17257 |
} |
| 17258 |
|
| 17259 |
out: |
| 17260 |
return val; |
| 17261 |
} |
| 17262 |
|
| 17263 |
static int tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, |
| 17264 |
int size, bool to_device) |
| 17265 |
{ |
| 17266 |
struct tg3_internal_buffer_desc test_desc; |
| 17267 |
u32 sram_dma_descs; |
| 17268 |
int i, ret; |
| 17269 |
|
| 17270 |
sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; |
| 17271 |
|
| 17272 |
tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); |
| 17273 |
tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); |
| 17274 |
tw32(RDMAC_STATUS, 0); |
| 17275 |
tw32(WDMAC_STATUS, 0); |
| 17276 |
|
| 17277 |
tw32(BUFMGR_MODE, 0); |
| 17278 |
tw32(FTQ_RESET, 0); |
| 17279 |
|
| 17280 |
test_desc.addr_hi = ((u64) buf_dma) >> 32; |
| 17281 |
test_desc.addr_lo = buf_dma & 0xffffffff; |
| 17282 |
test_desc.nic_mbuf = 0x00002100; |
| 17283 |
test_desc.len = size; |
| 17284 |
|
| 17285 |
/* |
| 17286 |
* HP ZX1 was seeing test failures for 5701 cards running at 33Mhz |
| 17287 |
* the *second* time the tg3 driver was getting loaded after an |
| 17288 |
* initial scan. |
| 17289 |
* |
| 17290 |
* Broadcom tells me: |
| 17291 |
* ...the DMA engine is connected to the GRC block and a DMA |
| 17292 |
* reset may affect the GRC block in some unpredictable way... |
| 17293 |
* The behavior of resets to individual blocks has not been tested. |
| 17294 |
* |
| 17295 |
* Broadcom noted the GRC reset will also reset all sub-components. |
| 17296 |
*/ |
| 17297 |
if (to_device) { |
| 17298 |
test_desc.cqid_sqid = (13 << 8) | 2; |
| 17299 |
|
| 17300 |
tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); |
| 17301 |
udelay(40); |
| 17302 |
} else { |
| 17303 |
test_desc.cqid_sqid = (16 << 8) | 7; |
| 17304 |
|
| 17305 |
tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); |
| 17306 |
udelay(40); |
| 17307 |
} |
| 17308 |
test_desc.flags = 0x00000005; |
| 17309 |
|
| 17310 |
for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { |
| 17311 |
u32 val; |
| 17312 |
|
| 17313 |
val = *(((u32 *)&test_desc) + i); |
| 17314 |
pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, |
| 17315 |
sram_dma_descs + (i * sizeof(u32))); |
| 17316 |
pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); |
| 17317 |
} |
| 17318 |
pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); |
| 17319 |
|
| 17320 |
if (to_device) |
| 17321 |
tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
| 17322 |
else |
| 17323 |
tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
| 17324 |
|
| 17325 |
ret = -ENODEV; |
| 17326 |
for (i = 0; i < 40; i++) { |
| 17327 |
u32 val; |
| 17328 |
|
| 17329 |
if (to_device) |
| 17330 |
val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); |
| 17331 |
else |
| 17332 |
val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); |
| 17333 |
if ((val & 0xffff) == sram_dma_descs) { |
| 17334 |
ret = 0; |
| 17335 |
break; |
| 17336 |
} |
| 17337 |
|
| 17338 |
udelay(100); |
| 17339 |
} |
| 17340 |
|
| 17341 |
return ret; |
| 17342 |
} |
| 17343 |
|
| 17344 |
#define TEST_BUFFER_SIZE 0x2000 |
| 17345 |
|
| 17346 |
static const struct pci_device_id tg3_dma_wait_state_chipsets[] = { |
| 17347 |
{ PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
| 17348 |
{ }, |
| 17349 |
}; |
| 17350 |
|
| 17351 |
static int tg3_test_dma(struct tg3 *tp) |
| 17352 |
{ |
| 17353 |
dma_addr_t buf_dma; |
| 17354 |
u32 *buf, saved_dma_rwctrl; |
| 17355 |
int ret = 0; |
| 17356 |
|
| 17357 |
buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
| 17358 |
&buf_dma, GFP_KERNEL); |
| 17359 |
if (!buf) { |
| 17360 |
ret = -ENOMEM; |
| 17361 |
goto out_nofree; |
| 17362 |
} |
| 17363 |
|
| 17364 |
tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | |
| 17365 |
(0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); |
| 17366 |
|
| 17367 |
tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
| 17368 |
|
| 17369 |
if (tg3_flag(tp, 57765_PLUS)) |
| 17370 |
goto out; |
| 17371 |
|
| 17372 |
if (tg3_flag(tp, PCI_EXPRESS)) { |
| 17373 |
/* DMA read watermark not used on PCIE */ |
| 17374 |
tp->dma_rwctrl |= 0x00180000; |
| 17375 |
} else if (!tg3_flag(tp, PCIX_MODE)) { |
| 17376 |
if (tg3_asic_rev(tp) == ASIC_REV_5705 || |
| 17377 |
tg3_asic_rev(tp) == ASIC_REV_5750) |
| 17378 |
tp->dma_rwctrl |= 0x003f0000; |
| 17379 |
else |
| 17380 |
tp->dma_rwctrl |= 0x003f000f; |
| 17381 |
} else { |
| 17382 |
if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
| 17383 |
tg3_asic_rev(tp) == ASIC_REV_5704) { |
| 17384 |
u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
| 17385 |
u32 read_water = 0x7; |
| 17386 |
|
| 17387 |
/* If the 5704 is behind the EPB bridge, we can |
| 17388 |
* do the less restrictive ONE_DMA workaround for |
| 17389 |
* better performance. |
| 17390 |
*/ |
| 17391 |
if (tg3_flag(tp, 40BIT_DMA_BUG) && |
| 17392 |
tg3_asic_rev(tp) == ASIC_REV_5704) |
| 17393 |
tp->dma_rwctrl |= 0x8000; |
| 17394 |
else if (ccval == 0x6 || ccval == 0x7) |
| 17395 |
tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 17396 |
|
| 17397 |
if (tg3_asic_rev(tp) == ASIC_REV_5703) |
| 17398 |
read_water = 4; |
| 17399 |
/* Set bit 23 to enable PCIX hw bug fix */ |
| 17400 |
tp->dma_rwctrl |= |
| 17401 |
(read_water << DMA_RWCTRL_READ_WATER_SHIFT) | |
| 17402 |
(0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | |
| 17403 |
(1 << 23); |
| 17404 |
} else if (tg3_asic_rev(tp) == ASIC_REV_5780) { |
| 17405 |
/* 5780 always in PCIX mode */ |
| 17406 |
tp->dma_rwctrl |= 0x00144000; |
| 17407 |
} else if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
| 17408 |
/* 5714 always in PCIX mode */ |
| 17409 |
tp->dma_rwctrl |= 0x00148000; |
| 17410 |
} else { |
| 17411 |
tp->dma_rwctrl |= 0x001b000f; |
| 17412 |
} |
| 17413 |
} |
| 17414 |
if (tg3_flag(tp, ONE_DMA_AT_ONCE)) |
| 17415 |
tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
| 17416 |
|
| 17417 |
if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
| 17418 |
tg3_asic_rev(tp) == ASIC_REV_5704) |
| 17419 |
tp->dma_rwctrl &= 0xfffffff0; |
| 17420 |
|
| 17421 |
if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
| 17422 |
tg3_asic_rev(tp) == ASIC_REV_5701) { |
| 17423 |
/* Remove this if it causes problems for some boards. */ |
| 17424 |
tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; |
| 17425 |
|
| 17426 |
/* On 5700/5701 chips, we need to set this bit. |
| 17427 |
* Otherwise the chip will issue cacheline transactions |
| 17428 |
* to streamable DMA memory with not all the byte |
| 17429 |
* enables turned on. This is an error on several |
| 17430 |
* RISC PCI controllers, in particular sparc64. |
| 17431 |
* |
| 17432 |
* On 5703/5704 chips, this bit has been reassigned |
| 17433 |
* a different meaning. In particular, it is used |
| 17434 |
* on those chips to enable a PCI-X workaround. |
| 17435 |
*/ |
| 17436 |
tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; |
| 17437 |
} |
| 17438 |
|
| 17439 |
tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 17440 |
|
| 17441 |
|
| 17442 |
if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
| 17443 |
tg3_asic_rev(tp) != ASIC_REV_5701) |
| 17444 |
goto out; |
| 17445 |
|
| 17446 |
/* It is best to perform DMA test with maximum write burst size |
| 17447 |
* to expose the 5700/5701 write DMA bug. |
| 17448 |
*/ |
| 17449 |
saved_dma_rwctrl = tp->dma_rwctrl; |
| 17450 |
tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 17451 |
tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 17452 |
|
| 17453 |
while (1) { |
| 17454 |
u32 *p = buf, i; |
| 17455 |
|
| 17456 |
for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) |
| 17457 |
p[i] = i; |
| 17458 |
|
| 17459 |
/* Send the buffer to the chip. */ |
| 17460 |
ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, true); |
| 17461 |
if (ret) { |
| 17462 |
dev_err(&tp->pdev->dev, |
| 17463 |
"%s: Buffer write failed. err = %d\n", |
| 17464 |
__func__, ret); |
| 17465 |
break; |
| 17466 |
} |
| 17467 |
|
| 17468 |
/* Now read it back. */ |
| 17469 |
ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, false); |
| 17470 |
if (ret) { |
| 17471 |
dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
| 17472 |
"err = %d\n", __func__, ret); |
| 17473 |
break; |
| 17474 |
} |
| 17475 |
|
| 17476 |
/* Verify it. */ |
| 17477 |
for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { |
| 17478 |
if (p[i] == i) |
| 17479 |
continue; |
| 17480 |
|
| 17481 |
if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 17482 |
DMA_RWCTRL_WRITE_BNDRY_16) { |
| 17483 |
tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 17484 |
tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 17485 |
tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 17486 |
break; |
| 17487 |
} else { |
| 17488 |
dev_err(&tp->pdev->dev, |
| 17489 |
"%s: Buffer corrupted on read back! " |
| 17490 |
"(%d != %d)\n", __func__, p[i], i); |
| 17491 |
ret = -ENODEV; |
| 17492 |
goto out; |
| 17493 |
} |
| 17494 |
} |
| 17495 |
|
| 17496 |
if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { |
| 17497 |
/* Success. */ |
| 17498 |
ret = 0; |
| 17499 |
break; |
| 17500 |
} |
| 17501 |
} |
| 17502 |
if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
| 17503 |
DMA_RWCTRL_WRITE_BNDRY_16) { |
| 17504 |
/* DMA test passed without adjusting DMA boundary, |
| 17505 |
* now look for chipsets that are known to expose the |
| 17506 |
* DMA bug without failing the test. |
| 17507 |
*/ |
| 17508 |
if (pci_dev_present(tg3_dma_wait_state_chipsets)) { |
| 17509 |
tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
| 17510 |
tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
| 17511 |
} else { |
| 17512 |
/* Safe to use the calculated DMA boundary. */ |
| 17513 |
tp->dma_rwctrl = saved_dma_rwctrl; |
| 17514 |
} |
| 17515 |
|
| 17516 |
tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
| 17517 |
} |
| 17518 |
|
| 17519 |
out: |
| 17520 |
dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
| 17521 |
out_nofree: |
| 17522 |
return ret; |
| 17523 |
} |
| 17524 |
|
| 17525 |
static void tg3_init_bufmgr_config(struct tg3 *tp) |
| 17526 |
{ |
| 17527 |
if (tg3_flag(tp, 57765_PLUS)) { |
| 17528 |
tp->bufmgr_config.mbuf_read_dma_low_water = |
| 17529 |
DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 17530 |
tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 17531 |
DEFAULT_MB_MACRX_LOW_WATER_57765; |
| 17532 |
tp->bufmgr_config.mbuf_high_water = |
| 17533 |
DEFAULT_MB_HIGH_WATER_57765; |
| 17534 |
|
| 17535 |
tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 17536 |
DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 17537 |
tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 17538 |
DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; |
| 17539 |
tp->bufmgr_config.mbuf_high_water_jumbo = |
| 17540 |
DEFAULT_MB_HIGH_WATER_JUMBO_57765; |
| 17541 |
} else if (tg3_flag(tp, 5705_PLUS)) { |
| 17542 |
tp->bufmgr_config.mbuf_read_dma_low_water = |
| 17543 |
DEFAULT_MB_RDMA_LOW_WATER_5705; |
| 17544 |
tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 17545 |
DEFAULT_MB_MACRX_LOW_WATER_5705; |
| 17546 |
tp->bufmgr_config.mbuf_high_water = |
| 17547 |
DEFAULT_MB_HIGH_WATER_5705; |
| 17548 |
if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
| 17549 |
tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 17550 |
DEFAULT_MB_MACRX_LOW_WATER_5906; |
| 17551 |
tp->bufmgr_config.mbuf_high_water = |
| 17552 |
DEFAULT_MB_HIGH_WATER_5906; |
| 17553 |
} |
| 17554 |
|
| 17555 |
tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 17556 |
DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; |
| 17557 |
tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 17558 |
DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; |
| 17559 |
tp->bufmgr_config.mbuf_high_water_jumbo = |
| 17560 |
DEFAULT_MB_HIGH_WATER_JUMBO_5780; |
| 17561 |
} else { |
| 17562 |
tp->bufmgr_config.mbuf_read_dma_low_water = |
| 17563 |
DEFAULT_MB_RDMA_LOW_WATER; |
| 17564 |
tp->bufmgr_config.mbuf_mac_rx_low_water = |
| 17565 |
DEFAULT_MB_MACRX_LOW_WATER; |
| 17566 |
tp->bufmgr_config.mbuf_high_water = |
| 17567 |
DEFAULT_MB_HIGH_WATER; |
| 17568 |
|
| 17569 |
tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = |
| 17570 |
DEFAULT_MB_RDMA_LOW_WATER_JUMBO; |
| 17571 |
tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = |
| 17572 |
DEFAULT_MB_MACRX_LOW_WATER_JUMBO; |
| 17573 |
tp->bufmgr_config.mbuf_high_water_jumbo = |
| 17574 |
DEFAULT_MB_HIGH_WATER_JUMBO; |
| 17575 |
} |
| 17576 |
|
| 17577 |
tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; |
| 17578 |
tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; |
| 17579 |
} |
| 17580 |
|
| 17581 |
static char *tg3_phy_string(struct tg3 *tp) |
| 17582 |
{ |
| 17583 |
switch (tp->phy_id & TG3_PHY_ID_MASK) { |
| 17584 |
case TG3_PHY_ID_BCM5400: return "5400"; |
| 17585 |
case TG3_PHY_ID_BCM5401: return "5401"; |
| 17586 |
case TG3_PHY_ID_BCM5411: return "5411"; |
| 17587 |
case TG3_PHY_ID_BCM5701: return "5701"; |
| 17588 |
case TG3_PHY_ID_BCM5703: return "5703"; |
| 17589 |
case TG3_PHY_ID_BCM5704: return "5704"; |
| 17590 |
case TG3_PHY_ID_BCM5705: return "5705"; |
| 17591 |
case TG3_PHY_ID_BCM5750: return "5750"; |
| 17592 |
case TG3_PHY_ID_BCM5752: return "5752"; |
| 17593 |
case TG3_PHY_ID_BCM5714: return "5714"; |
| 17594 |
case TG3_PHY_ID_BCM5780: return "5780"; |
| 17595 |
case TG3_PHY_ID_BCM5755: return "5755"; |
| 17596 |
case TG3_PHY_ID_BCM5787: return "5787"; |
| 17597 |
case TG3_PHY_ID_BCM5784: return "5784"; |
| 17598 |
case TG3_PHY_ID_BCM5756: return "5722/5756"; |
| 17599 |
case TG3_PHY_ID_BCM5906: return "5906"; |
| 17600 |
case TG3_PHY_ID_BCM5761: return "5761"; |
| 17601 |
case TG3_PHY_ID_BCM5718C: return "5718C"; |
| 17602 |
case TG3_PHY_ID_BCM5718S: return "5718S"; |
| 17603 |
case TG3_PHY_ID_BCM57765: return "57765"; |
| 17604 |
case TG3_PHY_ID_BCM5719C: return "5719C"; |
| 17605 |
case TG3_PHY_ID_BCM5720C: return "5720C"; |
| 17606 |
case TG3_PHY_ID_BCM5762: return "5762C"; |
| 17607 |
case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
| 17608 |
case 0: return "serdes"; |
| 17609 |
default: return "unknown"; |
| 17610 |
} |
| 17611 |
} |
| 17612 |
|
| 17613 |
static char *tg3_bus_string(struct tg3 *tp, char *str) |
| 17614 |
{ |
| 17615 |
if (tg3_flag(tp, PCI_EXPRESS)) { |
| 17616 |
strcpy(str, "PCI Express"); |
| 17617 |
return str; |
| 17618 |
} else if (tg3_flag(tp, PCIX_MODE)) { |
| 17619 |
u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
| 17620 |
|
| 17621 |
strcpy(str, "PCIX:"); |
| 17622 |
|
| 17623 |
if ((clock_ctrl == 7) || |
| 17624 |
((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == |
| 17625 |
GRC_MISC_CFG_BOARD_ID_5704CIOBE)) |
| 17626 |
strcat(str, "133MHz"); |
| 17627 |
else if (clock_ctrl == 0) |
| 17628 |
strcat(str, "33MHz"); |
| 17629 |
else if (clock_ctrl == 2) |
| 17630 |
strcat(str, "50MHz"); |
| 17631 |
else if (clock_ctrl == 4) |
| 17632 |
strcat(str, "66MHz"); |
| 17633 |
else if (clock_ctrl == 6) |
| 17634 |
strcat(str, "100MHz"); |
| 17635 |
} else { |
| 17636 |
strcpy(str, "PCI:"); |
| 17637 |
if (tg3_flag(tp, PCI_HIGH_SPEED)) |
| 17638 |
strcat(str, "66MHz"); |
| 17639 |
else |
| 17640 |
strcat(str, "33MHz"); |
| 17641 |
} |
| 17642 |
if (tg3_flag(tp, PCI_32BIT)) |
| 17643 |
strcat(str, ":32-bit"); |
| 17644 |
else |
| 17645 |
strcat(str, ":64-bit"); |
| 17646 |
return str; |
| 17647 |
} |
| 17648 |
|
| 17649 |
static void tg3_init_coal(struct tg3 *tp) |
| 17650 |
{ |
| 17651 |
struct ethtool_coalesce *ec = &tp->coal; |
| 17652 |
|
| 17653 |
memset(ec, 0, sizeof(*ec)); |
| 17654 |
ec->cmd = ETHTOOL_GCOALESCE; |
| 17655 |
ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; |
| 17656 |
ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; |
| 17657 |
ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; |
| 17658 |
ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; |
| 17659 |
ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; |
| 17660 |
ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; |
| 17661 |
ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; |
| 17662 |
ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; |
| 17663 |
ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; |
| 17664 |
|
| 17665 |
if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | |
| 17666 |
HOSTCC_MODE_CLRTICK_TXBD)) { |
| 17667 |
ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; |
| 17668 |
ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; |
| 17669 |
ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; |
| 17670 |
ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; |
| 17671 |
} |
| 17672 |
|
| 17673 |
if (tg3_flag(tp, 5705_PLUS)) { |
| 17674 |
ec->rx_coalesce_usecs_irq = 0; |
| 17675 |
ec->tx_coalesce_usecs_irq = 0; |
| 17676 |
ec->stats_block_coalesce_usecs = 0; |
| 17677 |
} |
| 17678 |
} |
| 17679 |
|
| 17680 |
static int tg3_init_one(struct pci_dev *pdev, |
| 17681 |
const struct pci_device_id *ent) |
| 17682 |
{ |
| 17683 |
struct net_device *dev; |
| 17684 |
struct tg3 *tp; |
| 17685 |
int i, err; |
| 17686 |
u32 sndmbx, rcvmbx, intmbx; |
| 17687 |
char str[40]; |
| 17688 |
u64 dma_mask, persist_dma_mask; |
| 17689 |
netdev_features_t features = 0; |
| 17690 |
u8 addr[ETH_ALEN] __aligned(2); |
| 17691 |
|
| 17692 |
err = pci_enable_device(pdev); |
| 17693 |
if (err) { |
| 17694 |
dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
| 17695 |
return err; |
| 17696 |
} |
| 17697 |
|
| 17698 |
err = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 17699 |
if (err) { |
| 17700 |
dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
| 17701 |
goto err_out_disable_pdev; |
| 17702 |
} |
| 17703 |
|
| 17704 |
pci_set_master(pdev); |
| 17705 |
|
| 17706 |
dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
| 17707 |
if (!dev) { |
| 17708 |
err = -ENOMEM; |
| 17709 |
goto err_out_free_res; |
| 17710 |
} |
| 17711 |
|
| 17712 |
SET_NETDEV_DEV(dev, &pdev->dev); |
| 17713 |
|
| 17714 |
tp = netdev_priv(dev); |
| 17715 |
tp->pdev = pdev; |
| 17716 |
tp->dev = dev; |
| 17717 |
tp->rx_mode = TG3_DEF_RX_MODE; |
| 17718 |
tp->tx_mode = TG3_DEF_TX_MODE; |
| 17719 |
tp->irq_sync = 1; |
| 17720 |
tp->pcierr_recovery = false; |
| 17721 |
|
| 17722 |
if (tg3_debug > 0) |
| 17723 |
tp->msg_enable = tg3_debug; |
| 17724 |
else |
| 17725 |
tp->msg_enable = TG3_DEF_MSG_ENABLE; |
| 17726 |
|
| 17727 |
if (pdev_is_ssb_gige_core(pdev)) { |
| 17728 |
tg3_flag_set(tp, IS_SSB_CORE); |
| 17729 |
if (ssb_gige_must_flush_posted_writes(pdev)) |
| 17730 |
tg3_flag_set(tp, FLUSH_POSTED_WRITES); |
| 17731 |
if (ssb_gige_one_dma_at_once(pdev)) |
| 17732 |
tg3_flag_set(tp, ONE_DMA_AT_ONCE); |
| 17733 |
if (ssb_gige_have_roboswitch(pdev)) { |
| 17734 |
tg3_flag_set(tp, USE_PHYLIB); |
| 17735 |
tg3_flag_set(tp, ROBOSWITCH); |
| 17736 |
} |
| 17737 |
if (ssb_gige_is_rgmii(pdev)) |
| 17738 |
tg3_flag_set(tp, RGMII_MODE); |
| 17739 |
} |
| 17740 |
|
| 17741 |
/* The word/byte swap controls here control register access byte |
| 17742 |
* swapping. DMA data byte swapping is controlled in the GRC_MODE |
| 17743 |
* setting below. |
| 17744 |
*/ |
| 17745 |
tp->misc_host_ctrl = |
| 17746 |
MISC_HOST_CTRL_MASK_PCI_INT | |
| 17747 |
MISC_HOST_CTRL_WORD_SWAP | |
| 17748 |
MISC_HOST_CTRL_INDIR_ACCESS | |
| 17749 |
MISC_HOST_CTRL_PCISTATE_RW; |
| 17750 |
|
| 17751 |
/* The NONFRM (non-frame) byte/word swap controls take effect |
| 17752 |
* on descriptor entries, anything which isn't packet data. |
| 17753 |
* |
| 17754 |
* The StrongARM chips on the board (one for tx, one for rx) |
| 17755 |
* are running in big-endian mode. |
| 17756 |
*/ |
| 17757 |
tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | |
| 17758 |
GRC_MODE_WSWAP_NONFRM_DATA); |
| 17759 |
#ifdef __BIG_ENDIAN |
| 17760 |
tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; |
| 17761 |
#endif |
| 17762 |
spin_lock_init(&tp->lock); |
| 17763 |
spin_lock_init(&tp->indirect_lock); |
| 17764 |
INIT_WORK(&tp->reset_task, tg3_reset_task); |
| 17765 |
|
| 17766 |
tp->regs = pci_ioremap_bar(pdev, BAR_0); |
| 17767 |
if (!tp->regs) { |
| 17768 |
dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
| 17769 |
err = -ENOMEM; |
| 17770 |
goto err_out_free_dev; |
| 17771 |
} |
| 17772 |
|
| 17773 |
if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
| 17774 |
tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761E || |
| 17775 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S || |
| 17776 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761SE || |
| 17777 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
| 17778 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C || |
| 17779 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
| 17780 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
| 17781 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720 || |
| 17782 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57767 || |
| 17783 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57764 || |
| 17784 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5762 || |
| 17785 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725 || |
| 17786 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_5727 || |
| 17787 |
tp->pdev->device == TG3PCI_DEVICE_TIGON3_57787) { |
| 17788 |
tg3_flag_set(tp, ENABLE_APE); |
| 17789 |
tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
| 17790 |
if (!tp->aperegs) { |
| 17791 |
dev_err(&pdev->dev, |
| 17792 |
"Cannot map APE registers, aborting\n"); |
| 17793 |
err = -ENOMEM; |
| 17794 |
goto err_out_iounmap; |
| 17795 |
} |
| 17796 |
} |
| 17797 |
|
| 17798 |
tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
| 17799 |
tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; |
| 17800 |
|
| 17801 |
dev->ethtool_ops = &tg3_ethtool_ops; |
| 17802 |
dev->watchdog_timeo = TG3_TX_TIMEOUT; |
| 17803 |
dev->netdev_ops = &tg3_netdev_ops; |
| 17804 |
dev->irq = pdev->irq; |
| 17805 |
|
| 17806 |
err = tg3_get_invariants(tp, ent); |
| 17807 |
if (err) { |
| 17808 |
dev_err(&pdev->dev, |
| 17809 |
"Problem fetching invariants of chip, aborting\n"); |
| 17810 |
goto err_out_apeunmap; |
| 17811 |
} |
| 17812 |
|
| 17813 |
/* The EPB bridge inside 5714, 5715, and 5780 and any |
| 17814 |
* device behind the EPB cannot support DMA addresses > 40-bit. |
| 17815 |
* On 64-bit systems with IOMMU, use 40-bit dma_mask. |
| 17816 |
* On 64-bit systems without IOMMU, use 64-bit dma_mask and |
| 17817 |
* do DMA address check in __tg3_start_xmit(). |
| 17818 |
*/ |
| 17819 |
if (tg3_flag(tp, IS_5788)) |
| 17820 |
persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
| 17821 |
else if (tg3_flag(tp, 40BIT_DMA_BUG)) { |
| 17822 |
persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
| 17823 |
#ifdef CONFIG_HIGHMEM |
| 17824 |
dma_mask = DMA_BIT_MASK(64); |
| 17825 |
#endif |
| 17826 |
} else |
| 17827 |
persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
| 17828 |
|
| 17829 |
if (tg3_asic_rev(tp) == ASIC_REV_57766) |
| 17830 |
persist_dma_mask = DMA_BIT_MASK(31); |
| 17831 |
|
| 17832 |
/* Configure DMA attributes. */ |
| 17833 |
if (dma_mask > DMA_BIT_MASK(32)) { |
| 17834 |
err = dma_set_mask(&pdev->dev, dma_mask); |
| 17835 |
if (!err) { |
| 17836 |
features |= NETIF_F_HIGHDMA; |
| 17837 |
err = dma_set_coherent_mask(&pdev->dev, |
| 17838 |
persist_dma_mask); |
| 17839 |
if (err < 0) { |
| 17840 |
dev_err(&pdev->dev, "Unable to obtain 64 bit " |
| 17841 |
"DMA for consistent allocations\n"); |
| 17842 |
goto err_out_apeunmap; |
| 17843 |
} |
| 17844 |
} |
| 17845 |
} |
| 17846 |
if (err || dma_mask == DMA_BIT_MASK(32)) { |
| 17847 |
err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
| 17848 |
if (err) { |
| 17849 |
dev_err(&pdev->dev, |
| 17850 |
"No usable DMA configuration, aborting\n"); |
| 17851 |
goto err_out_apeunmap; |
| 17852 |
} |
| 17853 |
} |
| 17854 |
|
| 17855 |
tg3_init_bufmgr_config(tp); |
| 17856 |
|
| 17857 |
/* 5700 B0 chips do not support checksumming correctly due |
| 17858 |
* to hardware bugs. |
| 17859 |
*/ |
| 17860 |
if (tg3_chip_rev_id(tp) != CHIPREV_ID_5700_B0) { |
| 17861 |
features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
| 17862 |
|
| 17863 |
if (tg3_flag(tp, 5755_PLUS)) |
| 17864 |
features |= NETIF_F_IPV6_CSUM; |
| 17865 |
} |
| 17866 |
|
| 17867 |
/* TSO is on by default on chips that support hardware TSO. |
| 17868 |
* Firmware TSO on older chips gives lower performance, so it |
| 17869 |
* is off by default, but can be enabled using ethtool. |
| 17870 |
*/ |
| 17871 |
if ((tg3_flag(tp, HW_TSO_1) || |
| 17872 |
tg3_flag(tp, HW_TSO_2) || |
| 17873 |
tg3_flag(tp, HW_TSO_3)) && |
| 17874 |
(features & NETIF_F_IP_CSUM)) |
| 17875 |
features |= NETIF_F_TSO; |
| 17876 |
if (tg3_flag(tp, HW_TSO_2) || tg3_flag(tp, HW_TSO_3)) { |
| 17877 |
if (features & NETIF_F_IPV6_CSUM) |
| 17878 |
features |= NETIF_F_TSO6; |
| 17879 |
if (tg3_flag(tp, HW_TSO_3) || |
| 17880 |
tg3_asic_rev(tp) == ASIC_REV_5761 || |
| 17881 |
(tg3_asic_rev(tp) == ASIC_REV_5784 && |
| 17882 |
tg3_chip_rev(tp) != CHIPREV_5784_AX) || |
| 17883 |
tg3_asic_rev(tp) == ASIC_REV_5785 || |
| 17884 |
tg3_asic_rev(tp) == ASIC_REV_57780) |
| 17885 |
features |= NETIF_F_TSO_ECN; |
| 17886 |
} |
| 17887 |
|
| 17888 |
dev->features |= features | NETIF_F_HW_VLAN_CTAG_TX | |
| 17889 |
NETIF_F_HW_VLAN_CTAG_RX; |
| 17890 |
dev->vlan_features |= features; |
| 17891 |
|
| 17892 |
/* |
| 17893 |
* Add loopback capability only for a subset of devices that support |
| 17894 |
* MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY |
| 17895 |
* loopback for the remaining devices. |
| 17896 |
*/ |
| 17897 |
if (tg3_asic_rev(tp) != ASIC_REV_5780 && |
| 17898 |
!tg3_flag(tp, CPMU_PRESENT)) |
| 17899 |
/* Add the loopback capability */ |
| 17900 |
features |= NETIF_F_LOOPBACK; |
| 17901 |
|
| 17902 |
dev->hw_features |= features; |
| 17903 |
dev->priv_flags |= IFF_UNICAST_FLT; |
| 17904 |
|
| 17905 |
/* MTU range: 60 - 9000 or 1500, depending on hardware */ |
| 17906 |
dev->min_mtu = TG3_MIN_MTU; |
| 17907 |
dev->max_mtu = TG3_MAX_MTU(tp); |
| 17908 |
|
| 17909 |
if (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A1 && |
| 17910 |
!tg3_flag(tp, TSO_CAPABLE) && |
| 17911 |
!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
| 17912 |
tg3_flag_set(tp, MAX_RXPEND_64); |
| 17913 |
tp->rx_pending = 63; |
| 17914 |
} |
| 17915 |
|
| 17916 |
err = tg3_get_device_address(tp, addr); |
| 17917 |
if (err) { |
| 17918 |
dev_err(&pdev->dev, |
| 17919 |
"Could not obtain valid ethernet address, aborting\n"); |
| 17920 |
goto err_out_apeunmap; |
| 17921 |
} |
| 17922 |
eth_hw_addr_set(dev, addr); |
| 17923 |
|
| 17924 |
intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
| 17925 |
rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; |
| 17926 |
sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
| 17927 |
for (i = 0; i < tp->irq_max; i++) { |
| 17928 |
struct tg3_napi *tnapi = &tp->napi[i]; |
| 17929 |
|
| 17930 |
tnapi->tp = tp; |
| 17931 |
tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; |
| 17932 |
|
| 17933 |
tnapi->int_mbox = intmbx; |
| 17934 |
intmbx += 0x8; |
| 17935 |
|
| 17936 |
tnapi->consmbox = rcvmbx; |
| 17937 |
tnapi->prodmbox = sndmbx; |
| 17938 |
|
| 17939 |
if (i) |
| 17940 |
tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
| 17941 |
else |
| 17942 |
tnapi->coal_now = HOSTCC_MODE_NOW; |
| 17943 |
|
| 17944 |
if (!tg3_flag(tp, SUPPORT_MSIX)) |
| 17945 |
break; |
| 17946 |
|
| 17947 |
/* |
| 17948 |
* If we support MSIX, we'll be using RSS. If we're using |
| 17949 |
* RSS, the first vector only handles link interrupts and the |
| 17950 |
* remaining vectors handle rx and tx interrupts. Reuse the |
| 17951 |
* mailbox values for the next iteration. The values we setup |
| 17952 |
* above are still useful for the single vectored mode. |
| 17953 |
*/ |
| 17954 |
if (!i) |
| 17955 |
continue; |
| 17956 |
|
| 17957 |
rcvmbx += 0x8; |
| 17958 |
|
| 17959 |
if (sndmbx & 0x4) |
| 17960 |
sndmbx -= 0x4; |
| 17961 |
else |
| 17962 |
sndmbx += 0xc; |
| 17963 |
} |
| 17964 |
|
| 17965 |
/* |
| 17966 |
* Reset chip in case UNDI or EFI driver did not shutdown |
| 17967 |
* DMA self test will enable WDMAC and we'll see (spurious) |
| 17968 |
* pending DMA on the PCI bus at that point. |
| 17969 |
*/ |
| 17970 |
if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
| 17971 |
(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
| 17972 |
tg3_full_lock(tp, 0); |
| 17973 |
tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
| 17974 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 17975 |
tg3_full_unlock(tp); |
| 17976 |
} |
| 17977 |
|
| 17978 |
err = tg3_test_dma(tp); |
| 17979 |
if (err) { |
| 17980 |
dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
| 17981 |
goto err_out_apeunmap; |
| 17982 |
} |
| 17983 |
|
| 17984 |
tg3_init_coal(tp); |
| 17985 |
|
| 17986 |
pci_set_drvdata(pdev, dev); |
| 17987 |
|
| 17988 |
if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
| 17989 |
tg3_asic_rev(tp) == ASIC_REV_5720 || |
| 17990 |
tg3_asic_rev(tp) == ASIC_REV_5762) |
| 17991 |
tg3_flag_set(tp, PTP_CAPABLE); |
| 17992 |
|
| 17993 |
tg3_timer_init(tp); |
| 17994 |
|
| 17995 |
tg3_carrier_off(tp); |
| 17996 |
|
| 17997 |
err = register_netdev(dev); |
| 17998 |
if (err) { |
| 17999 |
dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
| 18000 |
goto err_out_apeunmap; |
| 18001 |
} |
| 18002 |
|
| 18003 |
if (tg3_flag(tp, PTP_CAPABLE)) { |
| 18004 |
tg3_ptp_init(tp); |
| 18005 |
tp->ptp_clock = ptp_clock_register(&tp->ptp_info, |
| 18006 |
&tp->pdev->dev); |
| 18007 |
if (IS_ERR(tp->ptp_clock)) |
| 18008 |
tp->ptp_clock = NULL; |
| 18009 |
} |
| 18010 |
|
| 18011 |
netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
| 18012 |
tp->board_part_number, |
| 18013 |
tg3_chip_rev_id(tp), |
| 18014 |
tg3_bus_string(tp, str), |
| 18015 |
dev->dev_addr); |
| 18016 |
|
| 18017 |
if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) { |
| 18018 |
char *ethtype; |
| 18019 |
|
| 18020 |
if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
| 18021 |
ethtype = "10/100Base-TX"; |
| 18022 |
else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
| 18023 |
ethtype = "1000Base-SX"; |
| 18024 |
else |
| 18025 |
ethtype = "10/100/1000Base-T"; |
| 18026 |
|
| 18027 |
netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
| 18028 |
"(WireSpeed[%d], EEE[%d])\n", |
| 18029 |
tg3_phy_string(tp), ethtype, |
| 18030 |
(tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0, |
| 18031 |
(tp->phy_flags & TG3_PHYFLG_EEE_CAP) != 0); |
| 18032 |
} |
| 18033 |
|
| 18034 |
netdev_info(dev, "RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n", |
| 18035 |
(dev->features & NETIF_F_RXCSUM) != 0, |
| 18036 |
tg3_flag(tp, USE_LINKCHG_REG) != 0, |
| 18037 |
(tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
| 18038 |
tg3_flag(tp, ENABLE_ASF) != 0, |
| 18039 |
tg3_flag(tp, TSO_CAPABLE) != 0); |
| 18040 |
netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
| 18041 |
tp->dma_rwctrl, |
| 18042 |
pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : |
| 18043 |
((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); |
| 18044 |
|
| 18045 |
pci_save_state(pdev); |
| 18046 |
|
| 18047 |
return 0; |
| 18048 |
|
| 18049 |
err_out_apeunmap: |
| 18050 |
if (tp->aperegs) { |
| 18051 |
iounmap(tp->aperegs); |
| 18052 |
tp->aperegs = NULL; |
| 18053 |
} |
| 18054 |
|
| 18055 |
err_out_iounmap: |
| 18056 |
if (tp->regs) { |
| 18057 |
iounmap(tp->regs); |
| 18058 |
tp->regs = NULL; |
| 18059 |
} |
| 18060 |
|
| 18061 |
err_out_free_dev: |
| 18062 |
free_netdev(dev); |
| 18063 |
|
| 18064 |
err_out_free_res: |
| 18065 |
pci_release_regions(pdev); |
| 18066 |
|
| 18067 |
err_out_disable_pdev: |
| 18068 |
if (pci_is_enabled(pdev)) |
| 18069 |
pci_disable_device(pdev); |
| 18070 |
return err; |
| 18071 |
} |
| 18072 |
|
| 18073 |
static void tg3_remove_one(struct pci_dev *pdev) |
| 18074 |
{ |
| 18075 |
struct net_device *dev = pci_get_drvdata(pdev); |
| 18076 |
|
| 18077 |
if (dev) { |
| 18078 |
struct tg3 *tp = netdev_priv(dev); |
| 18079 |
|
| 18080 |
tg3_ptp_fini(tp); |
| 18081 |
|
| 18082 |
release_firmware(tp->fw); |
| 18083 |
|
| 18084 |
tg3_reset_task_cancel(tp); |
| 18085 |
|
| 18086 |
if (tg3_flag(tp, USE_PHYLIB)) { |
| 18087 |
tg3_phy_fini(tp); |
| 18088 |
tg3_mdio_fini(tp); |
| 18089 |
} |
| 18090 |
|
| 18091 |
unregister_netdev(dev); |
| 18092 |
if (tp->aperegs) { |
| 18093 |
iounmap(tp->aperegs); |
| 18094 |
tp->aperegs = NULL; |
| 18095 |
} |
| 18096 |
if (tp->regs) { |
| 18097 |
iounmap(tp->regs); |
| 18098 |
tp->regs = NULL; |
| 18099 |
} |
| 18100 |
free_netdev(dev); |
| 18101 |
pci_release_regions(pdev); |
| 18102 |
pci_disable_device(pdev); |
| 18103 |
} |
| 18104 |
} |
| 18105 |
|
| 18106 |
#ifdef CONFIG_PM_SLEEP |
| 18107 |
static int tg3_suspend(struct device *device) |
| 18108 |
{ |
| 18109 |
struct net_device *dev = dev_get_drvdata(device); |
| 18110 |
struct tg3 *tp = netdev_priv(dev); |
| 18111 |
|
| 18112 |
rtnl_lock(); |
| 18113 |
|
| 18114 |
if (!netif_running(dev)) |
| 18115 |
goto unlock; |
| 18116 |
|
| 18117 |
tg3_reset_task_cancel(tp); |
| 18118 |
tg3_phy_stop(tp); |
| 18119 |
tg3_netif_stop(tp); |
| 18120 |
|
| 18121 |
tg3_timer_stop(tp); |
| 18122 |
|
| 18123 |
tg3_full_lock(tp, 1); |
| 18124 |
tg3_disable_ints(tp); |
| 18125 |
tg3_full_unlock(tp); |
| 18126 |
|
| 18127 |
netif_device_detach(dev); |
| 18128 |
|
| 18129 |
tg3_full_lock(tp, 0); |
| 18130 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
| 18131 |
tg3_flag_clear(tp, INIT_COMPLETE); |
| 18132 |
tg3_full_unlock(tp); |
| 18133 |
|
| 18134 |
tg3_power_down_prepare(tp); |
| 18135 |
|
| 18136 |
unlock: |
| 18137 |
rtnl_unlock(); |
| 18138 |
return 0; |
| 18139 |
} |
| 18140 |
|
| 18141 |
static int tg3_resume(struct device *device) |
| 18142 |
{ |
| 18143 |
struct net_device *dev = dev_get_drvdata(device); |
| 18144 |
struct tg3 *tp = netdev_priv(dev); |
| 18145 |
int err = 0; |
| 18146 |
|
| 18147 |
rtnl_lock(); |
| 18148 |
|
| 18149 |
if (!netif_running(dev)) |
| 18150 |
goto unlock; |
| 18151 |
|
| 18152 |
netif_device_attach(dev); |
| 18153 |
|
| 18154 |
netdev_lock(dev); |
| 18155 |
tg3_full_lock(tp, 0); |
| 18156 |
|
| 18157 |
tg3_ape_driver_state_change(tp, RESET_KIND_INIT); |
| 18158 |
|
| 18159 |
tg3_flag_set(tp, INIT_COMPLETE); |
| 18160 |
err = tg3_restart_hw(tp, |
| 18161 |
!(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN)); |
| 18162 |
if (err) |
| 18163 |
goto out; |
| 18164 |
|
| 18165 |
tg3_timer_start(tp); |
| 18166 |
|
| 18167 |
tg3_netif_start(tp); |
| 18168 |
|
| 18169 |
out: |
| 18170 |
tg3_full_unlock(tp); |
| 18171 |
netdev_unlock(dev); |
| 18172 |
|
| 18173 |
if (!err) |
| 18174 |
tg3_phy_start(tp); |
| 18175 |
|
| 18176 |
unlock: |
| 18177 |
rtnl_unlock(); |
| 18178 |
return err; |
| 18179 |
} |
| 18180 |
#endif /* CONFIG_PM_SLEEP */ |
| 18181 |
|
| 18182 |
static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); |
| 18183 |
|
| 18184 |
/* Systems where ACPI _PTS (Prepare To Sleep) S5 will result in a fatal |
| 18185 |
* PCIe AER event on the tg3 device if the tg3 device is not, or cannot |
| 18186 |
* be, powered down. |
| 18187 |
*/ |
| 18188 |
static const struct dmi_system_id tg3_restart_aer_quirk_table[] = { |
| 18189 |
{ |
| 18190 |
.matches = { |
| 18191 |
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 18192 |
DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R440"), |
| 18193 |
}, |
| 18194 |
}, |
| 18195 |
{ |
| 18196 |
.matches = { |
| 18197 |
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 18198 |
DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R540"), |
| 18199 |
}, |
| 18200 |
}, |
| 18201 |
{ |
| 18202 |
.matches = { |
| 18203 |
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 18204 |
DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R640"), |
| 18205 |
}, |
| 18206 |
}, |
| 18207 |
{ |
| 18208 |
.matches = { |
| 18209 |
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 18210 |
DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R650"), |
| 18211 |
}, |
| 18212 |
}, |
| 18213 |
{ |
| 18214 |
.matches = { |
| 18215 |
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 18216 |
DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R740"), |
| 18217 |
}, |
| 18218 |
}, |
| 18219 |
{ |
| 18220 |
.matches = { |
| 18221 |
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 18222 |
DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R750"), |
| 18223 |
}, |
| 18224 |
}, |
| 18225 |
{} |
| 18226 |
}; |
| 18227 |
|
| 18228 |
static void tg3_shutdown(struct pci_dev *pdev) |
| 18229 |
{ |
| 18230 |
struct net_device *dev = pci_get_drvdata(pdev); |
| 18231 |
struct tg3 *tp = netdev_priv(dev); |
| 18232 |
|
| 18233 |
tg3_reset_task_cancel(tp); |
| 18234 |
|
| 18235 |
rtnl_lock(); |
| 18236 |
|
| 18237 |
netif_device_detach(dev); |
| 18238 |
|
| 18239 |
if (netif_running(dev)) |
| 18240 |
dev_close(dev); |
| 18241 |
|
| 18242 |
if (system_state == SYSTEM_POWER_OFF) |
| 18243 |
tg3_power_down(tp); |
| 18244 |
else if (system_state == SYSTEM_RESTART && |
| 18245 |
dmi_first_match(tg3_restart_aer_quirk_table) && |
| 18246 |
pdev->current_state != PCI_D3cold && |
| 18247 |
pdev->current_state != PCI_UNKNOWN) { |
| 18248 |
/* Disable PCIe AER on the tg3 to avoid a fatal |
| 18249 |
* error during this system restart. |
| 18250 |
*/ |
| 18251 |
pcie_capability_clear_word(pdev, PCI_EXP_DEVCTL, |
| 18252 |
PCI_EXP_DEVCTL_CERE | |
| 18253 |
PCI_EXP_DEVCTL_NFERE | |
| 18254 |
PCI_EXP_DEVCTL_FERE | |
| 18255 |
PCI_EXP_DEVCTL_URRE); |
| 18256 |
} |
| 18257 |
|
| 18258 |
rtnl_unlock(); |
| 18259 |
|
| 18260 |
pci_disable_device(pdev); |
| 18261 |
} |
| 18262 |
|
| 18263 |
/** |
| 18264 |
* tg3_io_error_detected - called when PCI error is detected |
| 18265 |
* @pdev: Pointer to PCI device |
| 18266 |
* @state: The current pci connection state |
| 18267 |
* |
| 18268 |
* This function is called after a PCI bus error affecting |
| 18269 |
* this device has been detected. |
| 18270 |
*/ |
| 18271 |
static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, |
| 18272 |
pci_channel_state_t state) |
| 18273 |
{ |
| 18274 |
struct net_device *netdev = pci_get_drvdata(pdev); |
| 18275 |
struct tg3 *tp = netdev_priv(netdev); |
| 18276 |
pci_ers_result_t err = PCI_ERS_RESULT_NEED_RESET; |
| 18277 |
|
| 18278 |
netdev_info(netdev, "PCI I/O error detected\n"); |
| 18279 |
|
| 18280 |
/* Want to make sure that the reset task doesn't run */ |
| 18281 |
tg3_reset_task_cancel(tp); |
| 18282 |
|
| 18283 |
rtnl_lock(); |
| 18284 |
|
| 18285 |
/* Could be second call or maybe we don't have netdev yet */ |
| 18286 |
if (!netdev || tp->pcierr_recovery || !netif_running(netdev)) |
| 18287 |
goto done; |
| 18288 |
|
| 18289 |
/* We needn't recover from permanent error */ |
| 18290 |
if (state == pci_channel_io_frozen) |
| 18291 |
tp->pcierr_recovery = true; |
| 18292 |
|
| 18293 |
tg3_phy_stop(tp); |
| 18294 |
|
| 18295 |
tg3_netif_stop(tp); |
| 18296 |
|
| 18297 |
tg3_timer_stop(tp); |
| 18298 |
|
| 18299 |
netif_device_detach(netdev); |
| 18300 |
|
| 18301 |
/* Clean up software state, even if MMIO is blocked */ |
| 18302 |
tg3_full_lock(tp, 0); |
| 18303 |
tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
| 18304 |
tg3_full_unlock(tp); |
| 18305 |
|
| 18306 |
done: |
| 18307 |
if (state == pci_channel_io_perm_failure) { |
| 18308 |
if (netdev) { |
| 18309 |
netdev_lock(netdev); |
| 18310 |
tg3_napi_enable(tp); |
| 18311 |
netdev_unlock(netdev); |
| 18312 |
dev_close(netdev); |
| 18313 |
} |
| 18314 |
err = PCI_ERS_RESULT_DISCONNECT; |
| 18315 |
} else { |
| 18316 |
pci_disable_device(pdev); |
| 18317 |
} |
| 18318 |
|
| 18319 |
rtnl_unlock(); |
| 18320 |
|
| 18321 |
return err; |
| 18322 |
} |
| 18323 |
|
| 18324 |
/** |
| 18325 |
* tg3_io_slot_reset - called after the pci bus has been reset. |
| 18326 |
* @pdev: Pointer to PCI device |
| 18327 |
* |
| 18328 |
* Restart the card from scratch, as if from a cold-boot. |
| 18329 |
* At this point, the card has experienced a hard reset, |
| 18330 |
* followed by fixups by BIOS, and has its config space |
| 18331 |
* set up identically to what it was at cold boot. |
| 18332 |
*/ |
| 18333 |
static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev) |
| 18334 |
{ |
| 18335 |
struct net_device *netdev = pci_get_drvdata(pdev); |
| 18336 |
struct tg3 *tp = netdev_priv(netdev); |
| 18337 |
pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 18338 |
int err; |
| 18339 |
|
| 18340 |
rtnl_lock(); |
| 18341 |
|
| 18342 |
if (pci_enable_device(pdev)) { |
| 18343 |
dev_err(&pdev->dev, |
| 18344 |
"Cannot re-enable PCI device after reset.\n"); |
| 18345 |
goto done; |
| 18346 |
} |
| 18347 |
|
| 18348 |
pci_set_master(pdev); |
| 18349 |
pci_restore_state(pdev); |
| 18350 |
|
| 18351 |
if (!netdev || !netif_running(netdev)) { |
| 18352 |
rc = PCI_ERS_RESULT_RECOVERED; |
| 18353 |
goto done; |
| 18354 |
} |
| 18355 |
|
| 18356 |
err = tg3_power_up(tp); |
| 18357 |
if (err) |
| 18358 |
goto done; |
| 18359 |
|
| 18360 |
rc = PCI_ERS_RESULT_RECOVERED; |
| 18361 |
|
| 18362 |
done: |
| 18363 |
if (rc != PCI_ERS_RESULT_RECOVERED && netdev && netif_running(netdev)) { |
| 18364 |
netdev_lock(netdev); |
| 18365 |
tg3_napi_enable(tp); |
| 18366 |
netdev_unlock(netdev); |
| 18367 |
dev_close(netdev); |
| 18368 |
} |
| 18369 |
rtnl_unlock(); |
| 18370 |
|
| 18371 |
return rc; |
| 18372 |
} |
| 18373 |
|
| 18374 |
/** |
| 18375 |
* tg3_io_resume - called when traffic can start flowing again. |
| 18376 |
* @pdev: Pointer to PCI device |
| 18377 |
* |
| 18378 |
* This callback is called when the error recovery driver tells |
| 18379 |
* us that its OK to resume normal operation. |
| 18380 |
*/ |
| 18381 |
static void tg3_io_resume(struct pci_dev *pdev) |
| 18382 |
{ |
| 18383 |
struct net_device *netdev = pci_get_drvdata(pdev); |
| 18384 |
struct tg3 *tp = netdev_priv(netdev); |
| 18385 |
int err; |
| 18386 |
|
| 18387 |
rtnl_lock(); |
| 18388 |
|
| 18389 |
if (!netdev || !netif_running(netdev)) |
| 18390 |
goto done; |
| 18391 |
|
| 18392 |
netdev_lock(netdev); |
| 18393 |
tg3_full_lock(tp, 0); |
| 18394 |
tg3_ape_driver_state_change(tp, RESET_KIND_INIT); |
| 18395 |
tg3_flag_set(tp, INIT_COMPLETE); |
| 18396 |
err = tg3_restart_hw(tp, true); |
| 18397 |
if (err) { |
| 18398 |
tg3_full_unlock(tp); |
| 18399 |
netdev_unlock(netdev); |
| 18400 |
netdev_err(netdev, "Cannot restart hardware after reset.\n"); |
| 18401 |
goto done; |
| 18402 |
} |
| 18403 |
|
| 18404 |
netif_device_attach(netdev); |
| 18405 |
|
| 18406 |
tg3_timer_start(tp); |
| 18407 |
|
| 18408 |
tg3_netif_start(tp); |
| 18409 |
|
| 18410 |
tg3_full_unlock(tp); |
| 18411 |
netdev_unlock(netdev); |
| 18412 |
|
| 18413 |
tg3_phy_start(tp); |
| 18414 |
|
| 18415 |
done: |
| 18416 |
tp->pcierr_recovery = false; |
| 18417 |
rtnl_unlock(); |
| 18418 |
} |
| 18419 |
|
| 18420 |
static const struct pci_error_handlers tg3_err_handler = { |
| 18421 |
.error_detected = tg3_io_error_detected, |
| 18422 |
.slot_reset = tg3_io_slot_reset, |
| 18423 |
.resume = tg3_io_resume |
| 18424 |
}; |
| 18425 |
|
| 18426 |
static struct pci_driver tg3_driver = { |
| 18427 |
.name = DRV_MODULE_NAME, |
| 18428 |
.id_table = tg3_pci_tbl, |
| 18429 |
.probe = tg3_init_one, |
| 18430 |
.remove = tg3_remove_one, |
| 18431 |
.err_handler = &tg3_err_handler, |
| 18432 |
.driver.pm = &tg3_pm_ops, |
| 18433 |
.shutdown = tg3_shutdown, |
| 18434 |
}; |
| 18435 |
|
| 18436 |
module_pci_driver(tg3_driver); |