Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
| 3 | * Copyright 2005-2006 Fen Systems Ltd. |
Ben Hutchings | 0a6f40c | 2011-02-25 00:01:34 +0000 | [diff] [blame] | 4 | * Copyright 2006-2010 Solarflare Communications Inc. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published |
| 8 | * by the Free Software Foundation, incorporated herein by reference. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/bitops.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <linux/pci.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/seq_file.h> |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 16 | #include <linux/i2c.h> |
Ben Hutchings | f31a45d | 2008-12-12 21:43:33 -0800 | [diff] [blame] | 17 | #include <linux/mii.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 19 | #include "net_driver.h" |
| 20 | #include "bitfield.h" |
| 21 | #include "efx.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 22 | #include "spi.h" |
Ben Hutchings | 744093c | 2009-11-29 15:12:08 +0000 | [diff] [blame] | 23 | #include "nic.h" |
Ben Hutchings | 8b8a95a | 2012-09-18 01:57:07 +0100 | [diff] [blame] | 24 | #include "farch_regs.h" |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 25 | #include "io.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 26 | #include "phy.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 27 | #include "workarounds.h" |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 28 | #include "selftest.h" |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 29 | #include "mdio_10g.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 30 | |
Ben Hutchings | 8986352 | 2009-11-25 16:09:04 +0000 | [diff] [blame] | 31 | /* Hardware control for SFC4000 (aka Falcon). */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 32 | |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 33 | /************************************************************************** |
| 34 | * |
| 35 | * MAC stats DMA format |
| 36 | * |
| 37 | ************************************************************************** |
| 38 | */ |
| 39 | |
| 40 | #define FALCON_MAC_STATS_SIZE 0x100 |
| 41 | |
| 42 | #define XgRxOctets_offset 0x0 |
| 43 | #define XgRxOctets_WIDTH 48 |
| 44 | #define XgRxOctetsOK_offset 0x8 |
| 45 | #define XgRxOctetsOK_WIDTH 48 |
| 46 | #define XgRxPkts_offset 0x10 |
| 47 | #define XgRxPkts_WIDTH 32 |
| 48 | #define XgRxPktsOK_offset 0x14 |
| 49 | #define XgRxPktsOK_WIDTH 32 |
| 50 | #define XgRxBroadcastPkts_offset 0x18 |
| 51 | #define XgRxBroadcastPkts_WIDTH 32 |
| 52 | #define XgRxMulticastPkts_offset 0x1C |
| 53 | #define XgRxMulticastPkts_WIDTH 32 |
| 54 | #define XgRxUnicastPkts_offset 0x20 |
| 55 | #define XgRxUnicastPkts_WIDTH 32 |
| 56 | #define XgRxUndersizePkts_offset 0x24 |
| 57 | #define XgRxUndersizePkts_WIDTH 32 |
| 58 | #define XgRxOversizePkts_offset 0x28 |
| 59 | #define XgRxOversizePkts_WIDTH 32 |
| 60 | #define XgRxJabberPkts_offset 0x2C |
| 61 | #define XgRxJabberPkts_WIDTH 32 |
| 62 | #define XgRxUndersizeFCSerrorPkts_offset 0x30 |
| 63 | #define XgRxUndersizeFCSerrorPkts_WIDTH 32 |
| 64 | #define XgRxDropEvents_offset 0x34 |
| 65 | #define XgRxDropEvents_WIDTH 32 |
| 66 | #define XgRxFCSerrorPkts_offset 0x38 |
| 67 | #define XgRxFCSerrorPkts_WIDTH 32 |
| 68 | #define XgRxAlignError_offset 0x3C |
| 69 | #define XgRxAlignError_WIDTH 32 |
| 70 | #define XgRxSymbolError_offset 0x40 |
| 71 | #define XgRxSymbolError_WIDTH 32 |
| 72 | #define XgRxInternalMACError_offset 0x44 |
| 73 | #define XgRxInternalMACError_WIDTH 32 |
| 74 | #define XgRxControlPkts_offset 0x48 |
| 75 | #define XgRxControlPkts_WIDTH 32 |
| 76 | #define XgRxPausePkts_offset 0x4C |
| 77 | #define XgRxPausePkts_WIDTH 32 |
| 78 | #define XgRxPkts64Octets_offset 0x50 |
| 79 | #define XgRxPkts64Octets_WIDTH 32 |
| 80 | #define XgRxPkts65to127Octets_offset 0x54 |
| 81 | #define XgRxPkts65to127Octets_WIDTH 32 |
| 82 | #define XgRxPkts128to255Octets_offset 0x58 |
| 83 | #define XgRxPkts128to255Octets_WIDTH 32 |
| 84 | #define XgRxPkts256to511Octets_offset 0x5C |
| 85 | #define XgRxPkts256to511Octets_WIDTH 32 |
| 86 | #define XgRxPkts512to1023Octets_offset 0x60 |
| 87 | #define XgRxPkts512to1023Octets_WIDTH 32 |
| 88 | #define XgRxPkts1024to15xxOctets_offset 0x64 |
| 89 | #define XgRxPkts1024to15xxOctets_WIDTH 32 |
| 90 | #define XgRxPkts15xxtoMaxOctets_offset 0x68 |
| 91 | #define XgRxPkts15xxtoMaxOctets_WIDTH 32 |
| 92 | #define XgRxLengthError_offset 0x6C |
| 93 | #define XgRxLengthError_WIDTH 32 |
| 94 | #define XgTxPkts_offset 0x80 |
| 95 | #define XgTxPkts_WIDTH 32 |
| 96 | #define XgTxOctets_offset 0x88 |
| 97 | #define XgTxOctets_WIDTH 48 |
| 98 | #define XgTxMulticastPkts_offset 0x90 |
| 99 | #define XgTxMulticastPkts_WIDTH 32 |
| 100 | #define XgTxBroadcastPkts_offset 0x94 |
| 101 | #define XgTxBroadcastPkts_WIDTH 32 |
| 102 | #define XgTxUnicastPkts_offset 0x98 |
| 103 | #define XgTxUnicastPkts_WIDTH 32 |
| 104 | #define XgTxControlPkts_offset 0x9C |
| 105 | #define XgTxControlPkts_WIDTH 32 |
| 106 | #define XgTxPausePkts_offset 0xA0 |
| 107 | #define XgTxPausePkts_WIDTH 32 |
| 108 | #define XgTxPkts64Octets_offset 0xA4 |
| 109 | #define XgTxPkts64Octets_WIDTH 32 |
| 110 | #define XgTxPkts65to127Octets_offset 0xA8 |
| 111 | #define XgTxPkts65to127Octets_WIDTH 32 |
| 112 | #define XgTxPkts128to255Octets_offset 0xAC |
| 113 | #define XgTxPkts128to255Octets_WIDTH 32 |
| 114 | #define XgTxPkts256to511Octets_offset 0xB0 |
| 115 | #define XgTxPkts256to511Octets_WIDTH 32 |
| 116 | #define XgTxPkts512to1023Octets_offset 0xB4 |
| 117 | #define XgTxPkts512to1023Octets_WIDTH 32 |
| 118 | #define XgTxPkts1024to15xxOctets_offset 0xB8 |
| 119 | #define XgTxPkts1024to15xxOctets_WIDTH 32 |
| 120 | #define XgTxPkts1519toMaxOctets_offset 0xBC |
| 121 | #define XgTxPkts1519toMaxOctets_WIDTH 32 |
| 122 | #define XgTxUndersizePkts_offset 0xC0 |
| 123 | #define XgTxUndersizePkts_WIDTH 32 |
| 124 | #define XgTxOversizePkts_offset 0xC4 |
| 125 | #define XgTxOversizePkts_WIDTH 32 |
| 126 | #define XgTxNonTcpUdpPkt_offset 0xC8 |
| 127 | #define XgTxNonTcpUdpPkt_WIDTH 16 |
| 128 | #define XgTxMacSrcErrPkt_offset 0xCC |
| 129 | #define XgTxMacSrcErrPkt_WIDTH 16 |
| 130 | #define XgTxIpSrcErrPkt_offset 0xD0 |
| 131 | #define XgTxIpSrcErrPkt_WIDTH 16 |
| 132 | #define XgDmaDone_offset 0xD4 |
| 133 | #define XgDmaDone_WIDTH 32 |
| 134 | |
| 135 | #define FALCON_STATS_NOT_DONE 0x00000000 |
| 136 | #define FALCON_STATS_DONE 0xffffffff |
| 137 | |
| 138 | #define FALCON_STAT_OFFSET(falcon_stat) EFX_VAL(falcon_stat, offset) |
| 139 | #define FALCON_STAT_WIDTH(falcon_stat) EFX_VAL(falcon_stat, WIDTH) |
| 140 | |
| 141 | /* Retrieve statistic from statistics block */ |
| 142 | #define FALCON_STAT(efx, falcon_stat, efx_stat) do { \ |
| 143 | if (FALCON_STAT_WIDTH(falcon_stat) == 16) \ |
| 144 | (efx)->mac_stats.efx_stat += le16_to_cpu( \ |
| 145 | *((__force __le16 *) \ |
| 146 | (efx->stats_buffer.addr + \ |
| 147 | FALCON_STAT_OFFSET(falcon_stat)))); \ |
| 148 | else if (FALCON_STAT_WIDTH(falcon_stat) == 32) \ |
| 149 | (efx)->mac_stats.efx_stat += le32_to_cpu( \ |
| 150 | *((__force __le32 *) \ |
| 151 | (efx->stats_buffer.addr + \ |
| 152 | FALCON_STAT_OFFSET(falcon_stat)))); \ |
| 153 | else \ |
| 154 | (efx)->mac_stats.efx_stat += le64_to_cpu( \ |
| 155 | *((__force __le64 *) \ |
| 156 | (efx->stats_buffer.addr + \ |
| 157 | FALCON_STAT_OFFSET(falcon_stat)))); \ |
| 158 | } while (0) |
| 159 | |
| 160 | /************************************************************************** |
| 161 | * |
| 162 | * Non-volatile configuration |
| 163 | * |
| 164 | ************************************************************************** |
| 165 | */ |
| 166 | |
| 167 | /* Board configuration v2 (v1 is obsolete; later versions are compatible) */ |
| 168 | struct falcon_nvconfig_board_v2 { |
| 169 | __le16 nports; |
| 170 | u8 port0_phy_addr; |
| 171 | u8 port0_phy_type; |
| 172 | u8 port1_phy_addr; |
| 173 | u8 port1_phy_type; |
| 174 | __le16 asic_sub_revision; |
| 175 | __le16 board_revision; |
| 176 | } __packed; |
| 177 | |
| 178 | /* Board configuration v3 extra information */ |
| 179 | struct falcon_nvconfig_board_v3 { |
| 180 | __le32 spi_device_type[2]; |
| 181 | } __packed; |
| 182 | |
| 183 | /* Bit numbers for spi_device_type */ |
| 184 | #define SPI_DEV_TYPE_SIZE_LBN 0 |
| 185 | #define SPI_DEV_TYPE_SIZE_WIDTH 5 |
| 186 | #define SPI_DEV_TYPE_ADDR_LEN_LBN 6 |
| 187 | #define SPI_DEV_TYPE_ADDR_LEN_WIDTH 2 |
| 188 | #define SPI_DEV_TYPE_ERASE_CMD_LBN 8 |
| 189 | #define SPI_DEV_TYPE_ERASE_CMD_WIDTH 8 |
| 190 | #define SPI_DEV_TYPE_ERASE_SIZE_LBN 16 |
| 191 | #define SPI_DEV_TYPE_ERASE_SIZE_WIDTH 5 |
| 192 | #define SPI_DEV_TYPE_BLOCK_SIZE_LBN 24 |
| 193 | #define SPI_DEV_TYPE_BLOCK_SIZE_WIDTH 5 |
| 194 | #define SPI_DEV_TYPE_FIELD(type, field) \ |
| 195 | (((type) >> EFX_LOW_BIT(field)) & EFX_MASK32(EFX_WIDTH(field))) |
| 196 | |
| 197 | #define FALCON_NVCONFIG_OFFSET 0x300 |
| 198 | |
| 199 | #define FALCON_NVCONFIG_BOARD_MAGIC_NUM 0xFA1C |
| 200 | struct falcon_nvconfig { |
| 201 | efx_oword_t ee_vpd_cfg_reg; /* 0x300 */ |
| 202 | u8 mac_address[2][8]; /* 0x310 */ |
| 203 | efx_oword_t pcie_sd_ctl0123_reg; /* 0x320 */ |
| 204 | efx_oword_t pcie_sd_ctl45_reg; /* 0x330 */ |
| 205 | efx_oword_t pcie_pcs_ctl_stat_reg; /* 0x340 */ |
| 206 | efx_oword_t hw_init_reg; /* 0x350 */ |
| 207 | efx_oword_t nic_stat_reg; /* 0x360 */ |
| 208 | efx_oword_t glb_ctl_reg; /* 0x370 */ |
| 209 | efx_oword_t srm_cfg_reg; /* 0x380 */ |
| 210 | efx_oword_t spare_reg; /* 0x390 */ |
| 211 | __le16 board_magic_num; /* 0x3A0 */ |
| 212 | __le16 board_struct_ver; |
| 213 | __le16 board_checksum; |
| 214 | struct falcon_nvconfig_board_v2 board_v2; |
| 215 | efx_oword_t ee_base_page_reg; /* 0x3B0 */ |
| 216 | struct falcon_nvconfig_board_v3 board_v3; /* 0x3C0 */ |
| 217 | } __packed; |
| 218 | |
| 219 | /*************************************************************************/ |
| 220 | |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 221 | static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method); |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 222 | static void falcon_reconfigure_mac_wrapper(struct efx_nic *efx); |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 223 | |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 224 | static const unsigned int |
| 225 | /* "Large" EEPROM device: Atmel AT25640 or similar |
| 226 | * 8 KB, 16-bit address, 32 B write block */ |
| 227 | large_eeprom_type = ((13 << SPI_DEV_TYPE_SIZE_LBN) |
| 228 | | (2 << SPI_DEV_TYPE_ADDR_LEN_LBN) |
| 229 | | (5 << SPI_DEV_TYPE_BLOCK_SIZE_LBN)), |
| 230 | /* Default flash device: Atmel AT25F1024 |
| 231 | * 128 KB, 24-bit address, 32 KB erase block, 256 B write block */ |
| 232 | default_flash_type = ((17 << SPI_DEV_TYPE_SIZE_LBN) |
| 233 | | (3 << SPI_DEV_TYPE_ADDR_LEN_LBN) |
| 234 | | (0x52 << SPI_DEV_TYPE_ERASE_CMD_LBN) |
| 235 | | (15 << SPI_DEV_TYPE_ERASE_SIZE_LBN) |
| 236 | | (8 << SPI_DEV_TYPE_BLOCK_SIZE_LBN)); |
| 237 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 238 | /************************************************************************** |
| 239 | * |
| 240 | * I2C bus - this is a bit-bashing interface using GPIO pins |
| 241 | * Note that it uses the output enables to tristate the outputs |
| 242 | * SDA is the data pin and SCL is the clock |
| 243 | * |
| 244 | ************************************************************************** |
| 245 | */ |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 246 | static void falcon_setsda(void *data, int state) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 247 | { |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 248 | struct efx_nic *efx = (struct efx_nic *)data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 249 | efx_oword_t reg; |
| 250 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 251 | efx_reado(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 252 | EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN, !state); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 253 | efx_writeo(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 254 | } |
| 255 | |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 256 | static void falcon_setscl(void *data, int state) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 257 | { |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 258 | struct efx_nic *efx = (struct efx_nic *)data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 259 | efx_oword_t reg; |
| 260 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 261 | efx_reado(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 262 | EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO0_OEN, !state); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 263 | efx_writeo(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static int falcon_getsda(void *data) |
| 267 | { |
| 268 | struct efx_nic *efx = (struct efx_nic *)data; |
| 269 | efx_oword_t reg; |
| 270 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 271 | efx_reado(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 272 | return EFX_OWORD_FIELD(reg, FRF_AB_GPIO3_IN); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 275 | static int falcon_getscl(void *data) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 276 | { |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 277 | struct efx_nic *efx = (struct efx_nic *)data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 278 | efx_oword_t reg; |
| 279 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 280 | efx_reado(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 281 | return EFX_OWORD_FIELD(reg, FRF_AB_GPIO0_IN); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 282 | } |
| 283 | |
Ben Hutchings | 18e83e4 | 2012-01-05 19:05:20 +0000 | [diff] [blame] | 284 | static const struct i2c_algo_bit_data falcon_i2c_bit_operations = { |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 285 | .setsda = falcon_setsda, |
| 286 | .setscl = falcon_setscl, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 287 | .getsda = falcon_getsda, |
| 288 | .getscl = falcon_getscl, |
Ben Hutchings | 62c7832 | 2008-05-30 22:27:46 +0100 | [diff] [blame] | 289 | .udelay = 5, |
Ben Hutchings | 9dadae6 | 2008-07-18 18:59:12 +0100 | [diff] [blame] | 290 | /* Wait up to 50 ms for slave to let us pull SCL high */ |
| 291 | .timeout = DIV_ROUND_UP(HZ, 20), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 292 | }; |
| 293 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 294 | static void falcon_push_irq_moderation(struct efx_channel *channel) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 295 | { |
| 296 | efx_dword_t timer_cmd; |
| 297 | struct efx_nic *efx = channel->efx; |
| 298 | |
| 299 | /* Set timer register */ |
| 300 | if (channel->irq_moderation) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 301 | EFX_POPULATE_DWORD_2(timer_cmd, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 302 | FRF_AB_TC_TIMER_MODE, |
| 303 | FFE_BB_TIMER_MODE_INT_HLDOFF, |
| 304 | FRF_AB_TC_TIMER_VAL, |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 305 | channel->irq_moderation - 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 306 | } else { |
| 307 | EFX_POPULATE_DWORD_2(timer_cmd, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 308 | FRF_AB_TC_TIMER_MODE, |
| 309 | FFE_BB_TIMER_MODE_DIS, |
| 310 | FRF_AB_TC_TIMER_VAL, 0); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 311 | } |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 312 | BUILD_BUG_ON(FR_AA_TIMER_COMMAND_KER != FR_BZ_TIMER_COMMAND_P0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 313 | efx_writed_page_locked(efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0, |
| 314 | channel->channel); |
Ben Hutchings | 127e6e1 | 2009-11-25 16:09:55 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 317 | static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx); |
| 318 | |
Ben Hutchings | 127e6e1 | 2009-11-25 16:09:55 +0000 | [diff] [blame] | 319 | static void falcon_prepare_flush(struct efx_nic *efx) |
| 320 | { |
| 321 | falcon_deconfigure_mac_wrapper(efx); |
| 322 | |
| 323 | /* Wait for the tx and rx fifo's to get to the next packet boundary |
| 324 | * (~1ms without back-pressure), then to drain the remainder of the |
| 325 | * fifo's at data path speeds (negligible), with a healthy margin. */ |
| 326 | msleep(10); |
Ben Hutchings | 6bc5d3a | 2008-09-01 12:49:37 +0100 | [diff] [blame] | 327 | } |
| 328 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 329 | /* Acknowledge a legacy interrupt from Falcon |
| 330 | * |
| 331 | * This acknowledges a legacy (not MSI) interrupt via INT_ACK_KER_REG. |
| 332 | * |
| 333 | * Due to SFC bug 3706 (silicon revision <=A1) reads can be duplicated in the |
| 334 | * BIU. Interrupt acknowledge is read sensitive so must write instead |
| 335 | * (then read to ensure the BIU collector is flushed) |
| 336 | * |
| 337 | * NB most hardware supports MSI interrupts |
| 338 | */ |
Ben Hutchings | 1840667 | 2013-01-03 23:36:57 +0000 | [diff] [blame] | 339 | static inline void falcon_irq_ack_a1(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 340 | { |
| 341 | efx_dword_t reg; |
| 342 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 343 | EFX_POPULATE_DWORD_1(reg, FRF_AA_INT_ACK_KER_FIELD, 0xb7eb7e); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 344 | efx_writed(efx, ®, FR_AA_INT_ACK_KER); |
| 345 | efx_readd(efx, ®, FR_AA_WORK_AROUND_BROKEN_PCI_READS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 346 | } |
| 347 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 348 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 349 | static irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 350 | { |
Ben Hutchings | d3208b5 | 2008-05-16 21:20:00 +0100 | [diff] [blame] | 351 | struct efx_nic *efx = dev_id; |
| 352 | efx_oword_t *int_ker = efx->irq_status.addr; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 353 | int syserr; |
| 354 | int queues; |
| 355 | |
| 356 | /* Check to see if this is our interrupt. If it isn't, we |
| 357 | * exit without having touched the hardware. |
| 358 | */ |
| 359 | if (unlikely(EFX_OWORD_IS_ZERO(*int_ker))) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 360 | netif_vdbg(efx, intr, efx->net_dev, |
| 361 | "IRQ %d on CPU %d not for me\n", irq, |
| 362 | raw_smp_processor_id()); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 363 | return IRQ_NONE; |
| 364 | } |
| 365 | efx->last_irq_cpu = raw_smp_processor_id(); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 366 | netif_vdbg(efx, intr, efx->net_dev, |
| 367 | "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n", |
| 368 | irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 369 | |
Ben Hutchings | d829118 | 2012-10-05 23:35:41 +0100 | [diff] [blame] | 370 | if (!likely(ACCESS_ONCE(efx->irq_soft_enabled))) |
| 371 | return IRQ_HANDLED; |
| 372 | |
Ben Hutchings | f70d184 | 2012-01-06 01:08:24 +0000 | [diff] [blame] | 373 | /* Check to see if we have a serious error condition */ |
| 374 | syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT); |
| 375 | if (unlikely(syserr)) |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 376 | return efx_farch_fatal_interrupt(efx); |
Ben Hutchings | f70d184 | 2012-01-06 01:08:24 +0000 | [diff] [blame] | 377 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 378 | /* Determine interrupting queues, clear interrupt status |
| 379 | * register and acknowledge the device interrupt. |
| 380 | */ |
Ben Hutchings | 674979d | 2009-11-29 03:42:10 +0000 | [diff] [blame] | 381 | BUILD_BUG_ON(FSF_AZ_NET_IVEC_INT_Q_WIDTH > EFX_MAX_CHANNELS); |
| 382 | queues = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_INT_Q); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 383 | EFX_ZERO_OWORD(*int_ker); |
| 384 | wmb(); /* Ensure the vector is cleared before interrupt ack */ |
| 385 | falcon_irq_ack_a1(efx); |
| 386 | |
Ben Hutchings | 8313aca | 2010-09-10 06:41:57 +0000 | [diff] [blame] | 387 | if (queues & 1) |
Ben Hutchings | 1646a6f3 | 2012-01-05 20:14:10 +0000 | [diff] [blame] | 388 | efx_schedule_channel_irq(efx_get_channel(efx, 0)); |
Ben Hutchings | 8313aca | 2010-09-10 06:41:57 +0000 | [diff] [blame] | 389 | if (queues & 2) |
Ben Hutchings | 1646a6f3 | 2012-01-05 20:14:10 +0000 | [diff] [blame] | 390 | efx_schedule_channel_irq(efx_get_channel(efx, 1)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 391 | return IRQ_HANDLED; |
| 392 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 393 | /************************************************************************** |
| 394 | * |
| 395 | * EEPROM/flash |
| 396 | * |
| 397 | ************************************************************************** |
| 398 | */ |
| 399 | |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 400 | #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 401 | |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 402 | static int falcon_spi_poll(struct efx_nic *efx) |
| 403 | { |
| 404 | efx_oword_t reg; |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 405 | efx_reado(efx, ®, FR_AB_EE_SPI_HCMD); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 406 | return EFX_OWORD_FIELD(reg, FRF_AB_EE_SPI_HCMD_CMD_EN) ? -EBUSY : 0; |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 409 | /* Wait for SPI command completion */ |
| 410 | static int falcon_spi_wait(struct efx_nic *efx) |
| 411 | { |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 412 | /* Most commands will finish quickly, so we start polling at |
| 413 | * very short intervals. Sometimes the command may have to |
| 414 | * wait for VPD or expansion ROM access outside of our |
| 415 | * control, so we allow up to 100 ms. */ |
| 416 | unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10); |
| 417 | int i; |
| 418 | |
| 419 | for (i = 0; i < 10; i++) { |
| 420 | if (!falcon_spi_poll(efx)) |
| 421 | return 0; |
| 422 | udelay(10); |
| 423 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 424 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 425 | for (;;) { |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 426 | if (!falcon_spi_poll(efx)) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 427 | return 0; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 428 | if (time_after_eq(jiffies, timeout)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 429 | netif_err(efx, hw, efx->net_dev, |
| 430 | "timed out waiting for SPI\n"); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 431 | return -ETIMEDOUT; |
| 432 | } |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 433 | schedule_timeout_uninterruptible(1); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 434 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 435 | } |
| 436 | |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 437 | int falcon_spi_cmd(struct efx_nic *efx, const struct falcon_spi_device *spi, |
Ben Hutchings | f415072 | 2008-11-04 20:34:28 +0000 | [diff] [blame] | 438 | unsigned int command, int address, |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 439 | const void *in, void *out, size_t len) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 440 | { |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 441 | bool addressed = (address >= 0); |
| 442 | bool reading = (out != NULL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 443 | efx_oword_t reg; |
| 444 | int rc; |
| 445 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 446 | /* Input validation */ |
| 447 | if (len > FALCON_SPI_MAX_LEN) |
| 448 | return -EINVAL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 449 | |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 450 | /* Check that previous command is not still running */ |
| 451 | rc = falcon_spi_poll(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 452 | if (rc) |
| 453 | return rc; |
| 454 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 455 | /* Program address register, if we have an address */ |
| 456 | if (addressed) { |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 457 | EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 458 | efx_writeo(efx, ®, FR_AB_EE_SPI_HADR); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 459 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 460 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 461 | /* Program data register, if we have data */ |
| 462 | if (in != NULL) { |
| 463 | memcpy(®, in, len); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 464 | efx_writeo(efx, ®, FR_AB_EE_SPI_HDATA); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /* Issue read/write command */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 468 | EFX_POPULATE_OWORD_7(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 469 | FRF_AB_EE_SPI_HCMD_CMD_EN, 1, |
| 470 | FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id, |
| 471 | FRF_AB_EE_SPI_HCMD_DABCNT, len, |
| 472 | FRF_AB_EE_SPI_HCMD_READ, reading, |
| 473 | FRF_AB_EE_SPI_HCMD_DUBCNT, 0, |
| 474 | FRF_AB_EE_SPI_HCMD_ADBCNT, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 475 | (addressed ? spi->addr_len : 0), |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 476 | FRF_AB_EE_SPI_HCMD_ENC, command); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 477 | efx_writeo(efx, ®, FR_AB_EE_SPI_HCMD); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 478 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 479 | /* Wait for read/write to complete */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 480 | rc = falcon_spi_wait(efx); |
| 481 | if (rc) |
| 482 | return rc; |
| 483 | |
| 484 | /* Read data */ |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 485 | if (out != NULL) { |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 486 | efx_reado(efx, ®, FR_AB_EE_SPI_HDATA); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 487 | memcpy(out, ®, len); |
| 488 | } |
| 489 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 490 | return 0; |
| 491 | } |
| 492 | |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 493 | static size_t |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 494 | falcon_spi_write_limit(const struct falcon_spi_device *spi, size_t start) |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 495 | { |
| 496 | return min(FALCON_SPI_MAX_LEN, |
| 497 | (spi->block_size - (start & (spi->block_size - 1)))); |
| 498 | } |
| 499 | |
| 500 | static inline u8 |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 501 | falcon_spi_munge_command(const struct falcon_spi_device *spi, |
| 502 | const u8 command, const unsigned int address) |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 503 | { |
| 504 | return command | (((address >> 8) & spi->munge_address) << 3); |
| 505 | } |
| 506 | |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 507 | /* Wait up to 10 ms for buffered write completion */ |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 508 | int |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 509 | falcon_spi_wait_write(struct efx_nic *efx, const struct falcon_spi_device *spi) |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 510 | { |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 511 | unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 512 | u8 status; |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 513 | int rc; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 514 | |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 515 | for (;;) { |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 516 | rc = falcon_spi_cmd(efx, spi, SPI_RDSR, -1, NULL, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 517 | &status, sizeof(status)); |
| 518 | if (rc) |
| 519 | return rc; |
| 520 | if (!(status & SPI_STATUS_NRDY)) |
| 521 | return 0; |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 522 | if (time_after_eq(jiffies, timeout)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 523 | netif_err(efx, hw, efx->net_dev, |
| 524 | "SPI write timeout on device %d" |
| 525 | " last status=0x%02x\n", |
| 526 | spi->device_id, status); |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 527 | return -ETIMEDOUT; |
| 528 | } |
| 529 | schedule_timeout_uninterruptible(1); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 530 | } |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 533 | int falcon_spi_read(struct efx_nic *efx, const struct falcon_spi_device *spi, |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 534 | loff_t start, size_t len, size_t *retlen, u8 *buffer) |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 535 | { |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 536 | size_t block_len, pos = 0; |
| 537 | unsigned int command; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 538 | int rc = 0; |
| 539 | |
| 540 | while (pos < len) { |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 541 | block_len = min(len - pos, FALCON_SPI_MAX_LEN); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 542 | |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 543 | command = falcon_spi_munge_command(spi, SPI_READ, start + pos); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 544 | rc = falcon_spi_cmd(efx, spi, command, start + pos, NULL, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 545 | buffer + pos, block_len); |
| 546 | if (rc) |
| 547 | break; |
| 548 | pos += block_len; |
| 549 | |
| 550 | /* Avoid locking up the system */ |
| 551 | cond_resched(); |
| 552 | if (signal_pending(current)) { |
| 553 | rc = -EINTR; |
| 554 | break; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | if (retlen) |
| 559 | *retlen = pos; |
| 560 | return rc; |
| 561 | } |
| 562 | |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 563 | int |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 564 | falcon_spi_write(struct efx_nic *efx, const struct falcon_spi_device *spi, |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 565 | loff_t start, size_t len, size_t *retlen, const u8 *buffer) |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 566 | { |
| 567 | u8 verify_buffer[FALCON_SPI_MAX_LEN]; |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 568 | size_t block_len, pos = 0; |
| 569 | unsigned int command; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 570 | int rc = 0; |
| 571 | |
| 572 | while (pos < len) { |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 573 | rc = falcon_spi_cmd(efx, spi, SPI_WREN, -1, NULL, NULL, 0); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 574 | if (rc) |
| 575 | break; |
| 576 | |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 577 | block_len = min(len - pos, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 578 | falcon_spi_write_limit(spi, start + pos)); |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 579 | command = falcon_spi_munge_command(spi, SPI_WRITE, start + pos); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 580 | rc = falcon_spi_cmd(efx, spi, command, start + pos, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 581 | buffer + pos, NULL, block_len); |
| 582 | if (rc) |
| 583 | break; |
| 584 | |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 585 | rc = falcon_spi_wait_write(efx, spi); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 586 | if (rc) |
| 587 | break; |
| 588 | |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 589 | command = falcon_spi_munge_command(spi, SPI_READ, start + pos); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 590 | rc = falcon_spi_cmd(efx, spi, command, start + pos, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 591 | NULL, verify_buffer, block_len); |
| 592 | if (memcmp(verify_buffer, buffer + pos, block_len)) { |
| 593 | rc = -EIO; |
| 594 | break; |
| 595 | } |
| 596 | |
| 597 | pos += block_len; |
| 598 | |
| 599 | /* Avoid locking up the system */ |
| 600 | cond_resched(); |
| 601 | if (signal_pending(current)) { |
| 602 | rc = -EINTR; |
| 603 | break; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | if (retlen) |
| 608 | *retlen = pos; |
| 609 | return rc; |
| 610 | } |
| 611 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 612 | /************************************************************************** |
| 613 | * |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 614 | * XMAC operations |
| 615 | * |
| 616 | ************************************************************************** |
| 617 | */ |
| 618 | |
| 619 | /* Configure the XAUI driver that is an output from Falcon */ |
| 620 | static void falcon_setup_xaui(struct efx_nic *efx) |
| 621 | { |
| 622 | efx_oword_t sdctl, txdrv; |
| 623 | |
| 624 | /* Move the XAUI into low power, unless there is no PHY, in |
| 625 | * which case the XAUI will have to drive a cable. */ |
| 626 | if (efx->phy_type == PHY_TYPE_NONE) |
| 627 | return; |
| 628 | |
| 629 | efx_reado(efx, &sdctl, FR_AB_XX_SD_CTL); |
| 630 | EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVD, FFE_AB_XX_SD_CTL_DRV_DEF); |
| 631 | EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVD, FFE_AB_XX_SD_CTL_DRV_DEF); |
| 632 | EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVC, FFE_AB_XX_SD_CTL_DRV_DEF); |
| 633 | EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVC, FFE_AB_XX_SD_CTL_DRV_DEF); |
| 634 | EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVB, FFE_AB_XX_SD_CTL_DRV_DEF); |
| 635 | EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVB, FFE_AB_XX_SD_CTL_DRV_DEF); |
| 636 | EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_HIDRVA, FFE_AB_XX_SD_CTL_DRV_DEF); |
| 637 | EFX_SET_OWORD_FIELD(sdctl, FRF_AB_XX_LODRVA, FFE_AB_XX_SD_CTL_DRV_DEF); |
| 638 | efx_writeo(efx, &sdctl, FR_AB_XX_SD_CTL); |
| 639 | |
| 640 | EFX_POPULATE_OWORD_8(txdrv, |
| 641 | FRF_AB_XX_DEQD, FFE_AB_XX_TXDRV_DEQ_DEF, |
| 642 | FRF_AB_XX_DEQC, FFE_AB_XX_TXDRV_DEQ_DEF, |
| 643 | FRF_AB_XX_DEQB, FFE_AB_XX_TXDRV_DEQ_DEF, |
| 644 | FRF_AB_XX_DEQA, FFE_AB_XX_TXDRV_DEQ_DEF, |
| 645 | FRF_AB_XX_DTXD, FFE_AB_XX_TXDRV_DTX_DEF, |
| 646 | FRF_AB_XX_DTXC, FFE_AB_XX_TXDRV_DTX_DEF, |
| 647 | FRF_AB_XX_DTXB, FFE_AB_XX_TXDRV_DTX_DEF, |
| 648 | FRF_AB_XX_DTXA, FFE_AB_XX_TXDRV_DTX_DEF); |
| 649 | efx_writeo(efx, &txdrv, FR_AB_XX_TXDRV_CTL); |
| 650 | } |
| 651 | |
| 652 | int falcon_reset_xaui(struct efx_nic *efx) |
| 653 | { |
| 654 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 655 | efx_oword_t reg; |
| 656 | int count; |
| 657 | |
| 658 | /* Don't fetch MAC statistics over an XMAC reset */ |
| 659 | WARN_ON(nic_data->stats_disable_count == 0); |
| 660 | |
| 661 | /* Start reset sequence */ |
| 662 | EFX_POPULATE_OWORD_1(reg, FRF_AB_XX_RST_XX_EN, 1); |
| 663 | efx_writeo(efx, ®, FR_AB_XX_PWR_RST); |
| 664 | |
| 665 | /* Wait up to 10 ms for completion, then reinitialise */ |
| 666 | for (count = 0; count < 1000; count++) { |
| 667 | efx_reado(efx, ®, FR_AB_XX_PWR_RST); |
| 668 | if (EFX_OWORD_FIELD(reg, FRF_AB_XX_RST_XX_EN) == 0 && |
| 669 | EFX_OWORD_FIELD(reg, FRF_AB_XX_SD_RST_ACT) == 0) { |
| 670 | falcon_setup_xaui(efx); |
| 671 | return 0; |
| 672 | } |
| 673 | udelay(10); |
| 674 | } |
| 675 | netif_err(efx, hw, efx->net_dev, |
| 676 | "timed out waiting for XAUI/XGXS reset\n"); |
| 677 | return -ETIMEDOUT; |
| 678 | } |
| 679 | |
| 680 | static void falcon_ack_status_intr(struct efx_nic *efx) |
| 681 | { |
| 682 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 683 | efx_oword_t reg; |
| 684 | |
| 685 | if ((efx_nic_rev(efx) != EFX_REV_FALCON_B0) || LOOPBACK_INTERNAL(efx)) |
| 686 | return; |
| 687 | |
| 688 | /* We expect xgmii faults if the wireside link is down */ |
Ben Hutchings | ab3b825 | 2012-10-05 19:31:02 +0100 | [diff] [blame] | 689 | if (!efx->link_state.up) |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 690 | return; |
| 691 | |
| 692 | /* We can only use this interrupt to signal the negative edge of |
| 693 | * xaui_align [we have to poll the positive edge]. */ |
| 694 | if (nic_data->xmac_poll_required) |
| 695 | return; |
| 696 | |
| 697 | efx_reado(efx, ®, FR_AB_XM_MGT_INT_MSK); |
| 698 | } |
| 699 | |
| 700 | static bool falcon_xgxs_link_ok(struct efx_nic *efx) |
| 701 | { |
| 702 | efx_oword_t reg; |
| 703 | bool align_done, link_ok = false; |
| 704 | int sync_status; |
| 705 | |
| 706 | /* Read link status */ |
| 707 | efx_reado(efx, ®, FR_AB_XX_CORE_STAT); |
| 708 | |
| 709 | align_done = EFX_OWORD_FIELD(reg, FRF_AB_XX_ALIGN_DONE); |
| 710 | sync_status = EFX_OWORD_FIELD(reg, FRF_AB_XX_SYNC_STAT); |
| 711 | if (align_done && (sync_status == FFE_AB_XX_STAT_ALL_LANES)) |
| 712 | link_ok = true; |
| 713 | |
| 714 | /* Clear link status ready for next read */ |
| 715 | EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_COMMA_DET, FFE_AB_XX_STAT_ALL_LANES); |
| 716 | EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_CHAR_ERR, FFE_AB_XX_STAT_ALL_LANES); |
| 717 | EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_DISPERR, FFE_AB_XX_STAT_ALL_LANES); |
| 718 | efx_writeo(efx, ®, FR_AB_XX_CORE_STAT); |
| 719 | |
| 720 | return link_ok; |
| 721 | } |
| 722 | |
| 723 | static bool falcon_xmac_link_ok(struct efx_nic *efx) |
| 724 | { |
| 725 | /* |
| 726 | * Check MAC's XGXS link status except when using XGMII loopback |
| 727 | * which bypasses the XGXS block. |
| 728 | * If possible, check PHY's XGXS link status except when using |
| 729 | * MAC loopback. |
| 730 | */ |
| 731 | return (efx->loopback_mode == LOOPBACK_XGMII || |
| 732 | falcon_xgxs_link_ok(efx)) && |
| 733 | (!(efx->mdio.mmds & (1 << MDIO_MMD_PHYXS)) || |
| 734 | LOOPBACK_INTERNAL(efx) || |
| 735 | efx_mdio_phyxgxs_lane_sync(efx)); |
| 736 | } |
| 737 | |
| 738 | static void falcon_reconfigure_xmac_core(struct efx_nic *efx) |
| 739 | { |
| 740 | unsigned int max_frame_len; |
| 741 | efx_oword_t reg; |
| 742 | bool rx_fc = !!(efx->link_state.fc & EFX_FC_RX); |
| 743 | bool tx_fc = !!(efx->link_state.fc & EFX_FC_TX); |
| 744 | |
| 745 | /* Configure MAC - cut-thru mode is hard wired on */ |
| 746 | EFX_POPULATE_OWORD_3(reg, |
| 747 | FRF_AB_XM_RX_JUMBO_MODE, 1, |
| 748 | FRF_AB_XM_TX_STAT_EN, 1, |
| 749 | FRF_AB_XM_RX_STAT_EN, 1); |
| 750 | efx_writeo(efx, ®, FR_AB_XM_GLB_CFG); |
| 751 | |
| 752 | /* Configure TX */ |
| 753 | EFX_POPULATE_OWORD_6(reg, |
| 754 | FRF_AB_XM_TXEN, 1, |
| 755 | FRF_AB_XM_TX_PRMBL, 1, |
| 756 | FRF_AB_XM_AUTO_PAD, 1, |
| 757 | FRF_AB_XM_TXCRC, 1, |
| 758 | FRF_AB_XM_FCNTL, tx_fc, |
| 759 | FRF_AB_XM_IPG, 0x3); |
| 760 | efx_writeo(efx, ®, FR_AB_XM_TX_CFG); |
| 761 | |
| 762 | /* Configure RX */ |
| 763 | EFX_POPULATE_OWORD_5(reg, |
| 764 | FRF_AB_XM_RXEN, 1, |
| 765 | FRF_AB_XM_AUTO_DEPAD, 0, |
| 766 | FRF_AB_XM_ACPT_ALL_MCAST, 1, |
Ben Hutchings | 964e613 | 2012-11-19 23:08:22 +0000 | [diff] [blame] | 767 | FRF_AB_XM_ACPT_ALL_UCAST, !efx->unicast_filter, |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 768 | FRF_AB_XM_PASS_CRC_ERR, 1); |
| 769 | efx_writeo(efx, ®, FR_AB_XM_RX_CFG); |
| 770 | |
| 771 | /* Set frame length */ |
| 772 | max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu); |
| 773 | EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_MAX_RX_FRM_SIZE, max_frame_len); |
| 774 | efx_writeo(efx, ®, FR_AB_XM_RX_PARAM); |
| 775 | EFX_POPULATE_OWORD_2(reg, |
| 776 | FRF_AB_XM_MAX_TX_FRM_SIZE, max_frame_len, |
| 777 | FRF_AB_XM_TX_JUMBO_MODE, 1); |
| 778 | efx_writeo(efx, ®, FR_AB_XM_TX_PARAM); |
| 779 | |
| 780 | EFX_POPULATE_OWORD_2(reg, |
| 781 | FRF_AB_XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */ |
| 782 | FRF_AB_XM_DIS_FCNTL, !rx_fc); |
| 783 | efx_writeo(efx, ®, FR_AB_XM_FC); |
| 784 | |
| 785 | /* Set MAC address */ |
| 786 | memcpy(®, &efx->net_dev->dev_addr[0], 4); |
| 787 | efx_writeo(efx, ®, FR_AB_XM_ADR_LO); |
| 788 | memcpy(®, &efx->net_dev->dev_addr[4], 2); |
| 789 | efx_writeo(efx, ®, FR_AB_XM_ADR_HI); |
| 790 | } |
| 791 | |
| 792 | static void falcon_reconfigure_xgxs_core(struct efx_nic *efx) |
| 793 | { |
| 794 | efx_oword_t reg; |
| 795 | bool xgxs_loopback = (efx->loopback_mode == LOOPBACK_XGXS); |
| 796 | bool xaui_loopback = (efx->loopback_mode == LOOPBACK_XAUI); |
| 797 | bool xgmii_loopback = (efx->loopback_mode == LOOPBACK_XGMII); |
Ben Hutchings | ab3b825 | 2012-10-05 19:31:02 +0100 | [diff] [blame] | 798 | bool old_xgmii_loopback, old_xgxs_loopback, old_xaui_loopback; |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 799 | |
| 800 | /* XGXS block is flaky and will need to be reset if moving |
| 801 | * into our out of XGMII, XGXS or XAUI loopbacks. */ |
Ben Hutchings | ab3b825 | 2012-10-05 19:31:02 +0100 | [diff] [blame] | 802 | efx_reado(efx, ®, FR_AB_XX_CORE_STAT); |
| 803 | old_xgxs_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_XGXS_LB_EN); |
| 804 | old_xgmii_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_XGMII_LB_EN); |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 805 | |
Ben Hutchings | ab3b825 | 2012-10-05 19:31:02 +0100 | [diff] [blame] | 806 | efx_reado(efx, ®, FR_AB_XX_SD_CTL); |
| 807 | old_xaui_loopback = EFX_OWORD_FIELD(reg, FRF_AB_XX_LPBKA); |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 808 | |
Ben Hutchings | ab3b825 | 2012-10-05 19:31:02 +0100 | [diff] [blame] | 809 | /* The PHY driver may have turned XAUI off */ |
| 810 | if ((xgxs_loopback != old_xgxs_loopback) || |
| 811 | (xaui_loopback != old_xaui_loopback) || |
| 812 | (xgmii_loopback != old_xgmii_loopback)) |
| 813 | falcon_reset_xaui(efx); |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 814 | |
| 815 | efx_reado(efx, ®, FR_AB_XX_CORE_STAT); |
| 816 | EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_FORCE_SIG, |
| 817 | (xgxs_loopback || xaui_loopback) ? |
| 818 | FFE_AB_XX_FORCE_SIG_ALL_LANES : 0); |
| 819 | EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_XGXS_LB_EN, xgxs_loopback); |
| 820 | EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_XGMII_LB_EN, xgmii_loopback); |
| 821 | efx_writeo(efx, ®, FR_AB_XX_CORE_STAT); |
| 822 | |
| 823 | efx_reado(efx, ®, FR_AB_XX_SD_CTL); |
| 824 | EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKD, xaui_loopback); |
| 825 | EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKC, xaui_loopback); |
| 826 | EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKB, xaui_loopback); |
| 827 | EFX_SET_OWORD_FIELD(reg, FRF_AB_XX_LPBKA, xaui_loopback); |
| 828 | efx_writeo(efx, ®, FR_AB_XX_SD_CTL); |
| 829 | } |
| 830 | |
| 831 | |
| 832 | /* Try to bring up the Falcon side of the Falcon-Phy XAUI link */ |
| 833 | static bool falcon_xmac_link_ok_retry(struct efx_nic *efx, int tries) |
| 834 | { |
| 835 | bool mac_up = falcon_xmac_link_ok(efx); |
| 836 | |
| 837 | if (LOOPBACK_MASK(efx) & LOOPBACKS_EXTERNAL(efx) & LOOPBACKS_WS || |
| 838 | efx_phy_mode_disabled(efx->phy_mode)) |
| 839 | /* XAUI link is expected to be down */ |
| 840 | return mac_up; |
| 841 | |
| 842 | falcon_stop_nic_stats(efx); |
| 843 | |
| 844 | while (!mac_up && tries) { |
| 845 | netif_dbg(efx, hw, efx->net_dev, "bashing xaui\n"); |
| 846 | falcon_reset_xaui(efx); |
| 847 | udelay(200); |
| 848 | |
| 849 | mac_up = falcon_xmac_link_ok(efx); |
| 850 | --tries; |
| 851 | } |
| 852 | |
| 853 | falcon_start_nic_stats(efx); |
| 854 | |
| 855 | return mac_up; |
| 856 | } |
| 857 | |
| 858 | static bool falcon_xmac_check_fault(struct efx_nic *efx) |
| 859 | { |
| 860 | return !falcon_xmac_link_ok_retry(efx, 5); |
| 861 | } |
| 862 | |
| 863 | static int falcon_reconfigure_xmac(struct efx_nic *efx) |
| 864 | { |
| 865 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 866 | |
Ben Hutchings | 964e613 | 2012-11-19 23:08:22 +0000 | [diff] [blame] | 867 | efx_farch_filter_sync_rx_mode(efx); |
| 868 | |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 869 | falcon_reconfigure_xgxs_core(efx); |
| 870 | falcon_reconfigure_xmac_core(efx); |
| 871 | |
| 872 | falcon_reconfigure_mac_wrapper(efx); |
| 873 | |
| 874 | nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 5); |
| 875 | falcon_ack_status_intr(efx); |
| 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | static void falcon_update_stats_xmac(struct efx_nic *efx) |
| 881 | { |
| 882 | struct efx_mac_stats *mac_stats = &efx->mac_stats; |
| 883 | |
| 884 | /* Update MAC stats from DMAed values */ |
| 885 | FALCON_STAT(efx, XgRxOctets, rx_bytes); |
| 886 | FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes); |
| 887 | FALCON_STAT(efx, XgRxPkts, rx_packets); |
| 888 | FALCON_STAT(efx, XgRxPktsOK, rx_good); |
| 889 | FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast); |
| 890 | FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast); |
| 891 | FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast); |
| 892 | FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64); |
| 893 | FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo); |
| 894 | FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo); |
| 895 | FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64); |
| 896 | FALCON_STAT(efx, XgRxDropEvents, rx_overflow); |
| 897 | FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad); |
| 898 | FALCON_STAT(efx, XgRxAlignError, rx_align_error); |
| 899 | FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error); |
| 900 | FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error); |
| 901 | FALCON_STAT(efx, XgRxControlPkts, rx_control); |
| 902 | FALCON_STAT(efx, XgRxPausePkts, rx_pause); |
| 903 | FALCON_STAT(efx, XgRxPkts64Octets, rx_64); |
| 904 | FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127); |
| 905 | FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255); |
| 906 | FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511); |
| 907 | FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023); |
| 908 | FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx); |
| 909 | FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo); |
| 910 | FALCON_STAT(efx, XgRxLengthError, rx_length_error); |
| 911 | FALCON_STAT(efx, XgTxPkts, tx_packets); |
| 912 | FALCON_STAT(efx, XgTxOctets, tx_bytes); |
| 913 | FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast); |
| 914 | FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast); |
| 915 | FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast); |
| 916 | FALCON_STAT(efx, XgTxControlPkts, tx_control); |
| 917 | FALCON_STAT(efx, XgTxPausePkts, tx_pause); |
| 918 | FALCON_STAT(efx, XgTxPkts64Octets, tx_64); |
| 919 | FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127); |
| 920 | FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255); |
| 921 | FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511); |
| 922 | FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023); |
| 923 | FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx); |
| 924 | FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo); |
| 925 | FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64); |
| 926 | FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo); |
| 927 | FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp); |
| 928 | FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error); |
| 929 | FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error); |
| 930 | |
| 931 | /* Update derived statistics */ |
| 932 | efx_update_diff_stat(&mac_stats->tx_good_bytes, |
| 933 | mac_stats->tx_bytes - mac_stats->tx_bad_bytes - |
| 934 | mac_stats->tx_control * 64); |
| 935 | efx_update_diff_stat(&mac_stats->rx_bad_bytes, |
| 936 | mac_stats->rx_bytes - mac_stats->rx_good_bytes - |
| 937 | mac_stats->rx_control * 64); |
| 938 | } |
| 939 | |
| 940 | static void falcon_poll_xmac(struct efx_nic *efx) |
| 941 | { |
| 942 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 943 | |
Ben Hutchings | ab3b825 | 2012-10-05 19:31:02 +0100 | [diff] [blame] | 944 | /* We expect xgmii faults if the wireside link is down */ |
| 945 | if (!efx->link_state.up || !nic_data->xmac_poll_required) |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 946 | return; |
| 947 | |
| 948 | nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 1); |
| 949 | falcon_ack_status_intr(efx); |
| 950 | } |
| 951 | |
| 952 | /************************************************************************** |
| 953 | * |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 954 | * MAC wrapper |
| 955 | * |
| 956 | ************************************************************************** |
| 957 | */ |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 958 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 959 | static void falcon_push_multicast_hash(struct efx_nic *efx) |
| 960 | { |
| 961 | union efx_multicast_hash *mc_hash = &efx->multicast_hash; |
| 962 | |
| 963 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
| 964 | |
| 965 | efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0); |
| 966 | efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1); |
| 967 | } |
| 968 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 969 | static void falcon_reset_macs(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 970 | { |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 971 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 972 | efx_oword_t reg, mac_ctrl; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 973 | int count; |
| 974 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 975 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) { |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 976 | /* It's not safe to use GLB_CTL_REG to reset the |
| 977 | * macs, so instead use the internal MAC resets |
| 978 | */ |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 979 | EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1); |
| 980 | efx_writeo(efx, ®, FR_AB_XM_GLB_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 981 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 982 | for (count = 0; count < 10000; count++) { |
| 983 | efx_reado(efx, ®, FR_AB_XM_GLB_CFG); |
| 984 | if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) == |
| 985 | 0) |
| 986 | return; |
| 987 | udelay(10); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 988 | } |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 989 | |
| 990 | netif_err(efx, hw, efx->net_dev, |
| 991 | "timed out waiting for XMAC core reset\n"); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 992 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 993 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 994 | /* Mac stats will fail whist the TX fifo is draining */ |
| 995 | WARN_ON(nic_data->stats_disable_count == 0); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 996 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 997 | efx_reado(efx, &mac_ctrl, FR_AB_MAC_CTRL); |
| 998 | EFX_SET_OWORD_FIELD(mac_ctrl, FRF_BB_TXFIFO_DRAIN_EN, 1); |
| 999 | efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1000 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1001 | efx_reado(efx, ®, FR_AB_GLB_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1002 | EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1); |
| 1003 | EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1); |
| 1004 | EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1005 | efx_writeo(efx, ®, FR_AB_GLB_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1006 | |
| 1007 | count = 0; |
| 1008 | while (1) { |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1009 | efx_reado(efx, ®, FR_AB_GLB_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1010 | if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) && |
| 1011 | !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) && |
| 1012 | !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1013 | netif_dbg(efx, hw, efx->net_dev, |
| 1014 | "Completed MAC reset after %d loops\n", |
| 1015 | count); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1016 | break; |
| 1017 | } |
| 1018 | if (count > 20) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1019 | netif_err(efx, hw, efx->net_dev, "MAC reset failed\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1020 | break; |
| 1021 | } |
| 1022 | count++; |
| 1023 | udelay(10); |
| 1024 | } |
| 1025 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1026 | /* Ensure the correct MAC is selected before statistics |
| 1027 | * are re-enabled by the caller */ |
| 1028 | efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL); |
Steve Hodgson | b7b40ee | 2010-04-28 09:28:10 +0000 | [diff] [blame] | 1029 | |
Steve Hodgson | b7b40ee | 2010-04-28 09:28:10 +0000 | [diff] [blame] | 1030 | falcon_setup_xaui(efx); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1031 | } |
| 1032 | |
Ben Hutchings | 9dd3a13 | 2012-09-13 01:11:25 +0100 | [diff] [blame] | 1033 | static void falcon_drain_tx_fifo(struct efx_nic *efx) |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1034 | { |
| 1035 | efx_oword_t reg; |
| 1036 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1037 | if ((efx_nic_rev(efx) < EFX_REV_FALCON_B0) || |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1038 | (efx->loopback_mode != LOOPBACK_NONE)) |
| 1039 | return; |
| 1040 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1041 | efx_reado(efx, ®, FR_AB_MAC_CTRL); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1042 | /* There is no point in draining more than once */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1043 | if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN)) |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1044 | return; |
| 1045 | |
| 1046 | falcon_reset_macs(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1047 | } |
| 1048 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1049 | static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1050 | { |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1051 | efx_oword_t reg; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1052 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1053 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1054 | return; |
| 1055 | |
| 1056 | /* Isolate the MAC -> RX */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1057 | efx_reado(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1058 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1059 | efx_writeo(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1060 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1061 | /* Isolate TX -> MAC */ |
| 1062 | falcon_drain_tx_fifo(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1063 | } |
| 1064 | |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 1065 | static void falcon_reconfigure_mac_wrapper(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1066 | { |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 1067 | struct efx_link_state *link_state = &efx->link_state; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1068 | efx_oword_t reg; |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 1069 | int link_speed, isolate; |
| 1070 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 1071 | isolate = !!ACCESS_ONCE(efx->reset_pending); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1072 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 1073 | switch (link_state->speed) { |
Ben Hutchings | f31a45d | 2008-12-12 21:43:33 -0800 | [diff] [blame] | 1074 | case 10000: link_speed = 3; break; |
| 1075 | case 1000: link_speed = 2; break; |
| 1076 | case 100: link_speed = 1; break; |
| 1077 | default: link_speed = 0; break; |
| 1078 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1079 | /* MAC_LINK_STATUS controls MAC backpressure but doesn't work |
| 1080 | * as advertised. Disable to ensure packets are not |
| 1081 | * indefinitely held and TX queue can be flushed at any point |
| 1082 | * while the link is down. */ |
| 1083 | EFX_POPULATE_OWORD_5(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1084 | FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */, |
| 1085 | FRF_AB_MAC_BCAD_ACPT, 1, |
Ben Hutchings | 964e613 | 2012-11-19 23:08:22 +0000 | [diff] [blame] | 1086 | FRF_AB_MAC_UC_PROM, !efx->unicast_filter, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1087 | FRF_AB_MAC_LINK_STATUS, 1, /* always set */ |
| 1088 | FRF_AB_MAC_SPEED, link_speed); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1089 | /* On B0, MAC backpressure can be disabled and packets get |
| 1090 | * discarded. */ |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1091 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) { |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1092 | EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN, |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 1093 | !link_state->up || isolate); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1094 | } |
| 1095 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1096 | efx_writeo(efx, ®, FR_AB_MAC_CTRL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1097 | |
| 1098 | /* Restore the multicast hash registers. */ |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1099 | falcon_push_multicast_hash(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1100 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1101 | efx_reado(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 4b0d29d | 2009-11-29 03:42:18 +0000 | [diff] [blame] | 1102 | /* Enable XOFF signal from RX FIFO (we enabled it during NIC |
| 1103 | * initialisation but it may read back as 0) */ |
| 1104 | EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1105 | /* Unisolate the MAC -> RX */ |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1106 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 1107 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, !isolate); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1108 | efx_writeo(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1109 | } |
| 1110 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1111 | static void falcon_stats_request(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1112 | { |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1113 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1114 | efx_oword_t reg; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1115 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1116 | WARN_ON(nic_data->stats_pending); |
| 1117 | WARN_ON(nic_data->stats_disable_count); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1118 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1119 | if (nic_data->stats_dma_done == NULL) |
| 1120 | return; /* no mac selected */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1121 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1122 | *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE; |
| 1123 | nic_data->stats_pending = true; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1124 | wmb(); /* ensure done flag is clear */ |
| 1125 | |
| 1126 | /* Initiate DMA transfer of stats */ |
| 1127 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1128 | FRF_AB_MAC_STAT_DMA_CMD, 1, |
| 1129 | FRF_AB_MAC_STAT_DMA_ADR, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1130 | efx->stats_buffer.dma_addr); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1131 | efx_writeo(efx, ®, FR_AB_MAC_STAT_DMA); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1132 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1133 | mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2)); |
| 1134 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1135 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1136 | static void falcon_stats_complete(struct efx_nic *efx) |
| 1137 | { |
| 1138 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1139 | |
| 1140 | if (!nic_data->stats_pending) |
| 1141 | return; |
| 1142 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1143 | nic_data->stats_pending = false; |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1144 | if (*nic_data->stats_dma_done == FALCON_STATS_DONE) { |
| 1145 | rmb(); /* read the done flag before the stats */ |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1146 | falcon_update_stats_xmac(efx); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1147 | } else { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1148 | netif_err(efx, hw, efx->net_dev, |
| 1149 | "timed out waiting for statistics\n"); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | static void falcon_stats_timer_func(unsigned long context) |
| 1154 | { |
| 1155 | struct efx_nic *efx = (struct efx_nic *)context; |
| 1156 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1157 | |
| 1158 | spin_lock(&efx->stats_lock); |
| 1159 | |
| 1160 | falcon_stats_complete(efx); |
| 1161 | if (nic_data->stats_disable_count == 0) |
| 1162 | falcon_stats_request(efx); |
| 1163 | |
| 1164 | spin_unlock(&efx->stats_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1165 | } |
| 1166 | |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1167 | static bool falcon_loopback_link_poll(struct efx_nic *efx) |
| 1168 | { |
| 1169 | struct efx_link_state old_state = efx->link_state; |
| 1170 | |
| 1171 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
| 1172 | WARN_ON(!LOOPBACK_INTERNAL(efx)); |
| 1173 | |
| 1174 | efx->link_state.fd = true; |
| 1175 | efx->link_state.fc = efx->wanted_fc; |
| 1176 | efx->link_state.up = true; |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1177 | efx->link_state.speed = 10000; |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1178 | |
| 1179 | return !efx_link_state_equal(&efx->link_state, &old_state); |
| 1180 | } |
| 1181 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1182 | static int falcon_reconfigure_port(struct efx_nic *efx) |
| 1183 | { |
| 1184 | int rc; |
| 1185 | |
| 1186 | WARN_ON(efx_nic_rev(efx) > EFX_REV_FALCON_B0); |
| 1187 | |
| 1188 | /* Poll the PHY link state *before* reconfiguring it. This means we |
| 1189 | * will pick up the correct speed (in loopback) to select the correct |
| 1190 | * MAC. |
| 1191 | */ |
| 1192 | if (LOOPBACK_INTERNAL(efx)) |
| 1193 | falcon_loopback_link_poll(efx); |
| 1194 | else |
| 1195 | efx->phy_op->poll(efx); |
| 1196 | |
| 1197 | falcon_stop_nic_stats(efx); |
| 1198 | falcon_deconfigure_mac_wrapper(efx); |
| 1199 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1200 | falcon_reset_macs(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1201 | |
| 1202 | efx->phy_op->reconfigure(efx); |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1203 | rc = falcon_reconfigure_xmac(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1204 | BUG_ON(rc); |
| 1205 | |
| 1206 | falcon_start_nic_stats(efx); |
| 1207 | |
| 1208 | /* Synchronise efx->link_state with the kernel */ |
| 1209 | efx_link_status_changed(efx); |
| 1210 | |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
Ben Hutchings | 9dd3a13 | 2012-09-13 01:11:25 +0100 | [diff] [blame] | 1214 | /* TX flow control may automatically turn itself off if the link |
| 1215 | * partner (intermittently) stops responding to pause frames. There |
| 1216 | * isn't any indication that this has happened, so the best we do is |
| 1217 | * leave it up to the user to spot this and fix it by cycling transmit |
| 1218 | * flow control on this end. |
| 1219 | */ |
| 1220 | |
| 1221 | static void falcon_a1_prepare_enable_fc_tx(struct efx_nic *efx) |
| 1222 | { |
| 1223 | /* Schedule a reset to recover */ |
| 1224 | efx_schedule_reset(efx, RESET_TYPE_INVISIBLE); |
| 1225 | } |
| 1226 | |
| 1227 | static void falcon_b0_prepare_enable_fc_tx(struct efx_nic *efx) |
| 1228 | { |
| 1229 | /* Recover by resetting the EM block */ |
| 1230 | falcon_stop_nic_stats(efx); |
| 1231 | falcon_drain_tx_fifo(efx); |
| 1232 | falcon_reconfigure_xmac(efx); |
| 1233 | falcon_start_nic_stats(efx); |
| 1234 | } |
| 1235 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1236 | /************************************************************************** |
| 1237 | * |
| 1238 | * PHY access via GMII |
| 1239 | * |
| 1240 | ************************************************************************** |
| 1241 | */ |
| 1242 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1243 | /* Wait for GMII access to complete */ |
| 1244 | static int falcon_gmii_wait(struct efx_nic *efx) |
| 1245 | { |
Ben Hutchings | 80cb9a0 | 2009-11-25 16:08:41 +0000 | [diff] [blame] | 1246 | efx_oword_t md_stat; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1247 | int count; |
| 1248 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1249 | /* wait up to 50ms - taken max from datasheet */ |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1250 | for (count = 0; count < 5000; count++) { |
Ben Hutchings | 80cb9a0 | 2009-11-25 16:08:41 +0000 | [diff] [blame] | 1251 | efx_reado(efx, &md_stat, FR_AB_MD_STAT); |
| 1252 | if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) { |
| 1253 | if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 || |
| 1254 | EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1255 | netif_err(efx, hw, efx->net_dev, |
| 1256 | "error from GMII access " |
| 1257 | EFX_OWORD_FMT"\n", |
| 1258 | EFX_OWORD_VAL(md_stat)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1259 | return -EIO; |
| 1260 | } |
| 1261 | return 0; |
| 1262 | } |
| 1263 | udelay(10); |
| 1264 | } |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1265 | netif_err(efx, hw, efx->net_dev, "timed out waiting for GMII\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1266 | return -ETIMEDOUT; |
| 1267 | } |
| 1268 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1269 | /* Write an MDIO register of a PHY connected to Falcon. */ |
| 1270 | static int falcon_mdio_write(struct net_device *net_dev, |
| 1271 | int prtad, int devad, u16 addr, u16 value) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1272 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1273 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1274 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1275 | efx_oword_t reg; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1276 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1277 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1278 | netif_vdbg(efx, hw, efx->net_dev, |
| 1279 | "writing MDIO %d register %d.%d with 0x%04x\n", |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1280 | prtad, devad, addr, value); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1281 | |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1282 | mutex_lock(&nic_data->mdio_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1283 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1284 | /* Check MDIO not currently being accessed */ |
| 1285 | rc = falcon_gmii_wait(efx); |
| 1286 | if (rc) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1287 | goto out; |
| 1288 | |
| 1289 | /* Write the address/ID register */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1290 | EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1291 | efx_writeo(efx, ®, FR_AB_MD_PHY_ADR); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1292 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1293 | EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad, |
| 1294 | FRF_AB_MD_DEV_ADR, devad); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1295 | efx_writeo(efx, ®, FR_AB_MD_ID); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1296 | |
| 1297 | /* Write data */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1298 | EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1299 | efx_writeo(efx, ®, FR_AB_MD_TXD); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1300 | |
| 1301 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1302 | FRF_AB_MD_WRC, 1, |
| 1303 | FRF_AB_MD_GC, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1304 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1305 | |
| 1306 | /* Wait for data to be written */ |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1307 | rc = falcon_gmii_wait(efx); |
| 1308 | if (rc) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1309 | /* Abort the write operation */ |
| 1310 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1311 | FRF_AB_MD_WRC, 0, |
| 1312 | FRF_AB_MD_GC, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1313 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1314 | udelay(10); |
| 1315 | } |
| 1316 | |
Steve Hodgson | ab86746 | 2009-11-28 05:34:44 +0000 | [diff] [blame] | 1317 | out: |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1318 | mutex_unlock(&nic_data->mdio_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1319 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1320 | } |
| 1321 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1322 | /* Read an MDIO register of a PHY connected to Falcon. */ |
| 1323 | static int falcon_mdio_read(struct net_device *net_dev, |
| 1324 | int prtad, int devad, u16 addr) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1325 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1326 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1327 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1328 | efx_oword_t reg; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1329 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1330 | |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1331 | mutex_lock(&nic_data->mdio_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1332 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1333 | /* Check MDIO not currently being accessed */ |
| 1334 | rc = falcon_gmii_wait(efx); |
| 1335 | if (rc) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1336 | goto out; |
| 1337 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1338 | EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1339 | efx_writeo(efx, ®, FR_AB_MD_PHY_ADR); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1340 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1341 | EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad, |
| 1342 | FRF_AB_MD_DEV_ADR, devad); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1343 | efx_writeo(efx, ®, FR_AB_MD_ID); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1344 | |
| 1345 | /* Request data to be read */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1346 | EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_RDC, 1, FRF_AB_MD_GC, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1347 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1348 | |
| 1349 | /* Wait for data to become available */ |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1350 | rc = falcon_gmii_wait(efx); |
| 1351 | if (rc == 0) { |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1352 | efx_reado(efx, ®, FR_AB_MD_RXD); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1353 | rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1354 | netif_vdbg(efx, hw, efx->net_dev, |
| 1355 | "read from MDIO %d register %d.%d, got %04x\n", |
| 1356 | prtad, devad, addr, rc); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1357 | } else { |
| 1358 | /* Abort the read operation */ |
| 1359 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1360 | FRF_AB_MD_RIC, 0, |
| 1361 | FRF_AB_MD_GC, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1362 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1363 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1364 | netif_dbg(efx, hw, efx->net_dev, |
| 1365 | "read from MDIO %d register %d.%d, got error %d\n", |
| 1366 | prtad, devad, addr, rc); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1367 | } |
| 1368 | |
Steve Hodgson | ab86746 | 2009-11-28 05:34:44 +0000 | [diff] [blame] | 1369 | out: |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1370 | mutex_unlock(&nic_data->mdio_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1371 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1372 | } |
| 1373 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1374 | /* This call is responsible for hooking in the MAC and PHY operations */ |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1375 | static int falcon_probe_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1376 | { |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1377 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1378 | int rc; |
| 1379 | |
Ben Hutchings | 96c45726 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 1380 | switch (efx->phy_type) { |
| 1381 | case PHY_TYPE_SFX7101: |
| 1382 | efx->phy_op = &falcon_sfx7101_phy_ops; |
| 1383 | break; |
Ben Hutchings | 96c45726 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 1384 | case PHY_TYPE_QT2022C2: |
| 1385 | case PHY_TYPE_QT2025C: |
Ben Hutchings | b37b62f | 2009-10-23 08:33:42 +0000 | [diff] [blame] | 1386 | efx->phy_op = &falcon_qt202x_phy_ops; |
Ben Hutchings | 96c45726 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 1387 | break; |
Ben Hutchings | 7e51b43 | 2010-09-22 10:00:47 +0000 | [diff] [blame] | 1388 | case PHY_TYPE_TXC43128: |
| 1389 | efx->phy_op = &falcon_txc_phy_ops; |
| 1390 | break; |
Ben Hutchings | 96c45726 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 1391 | default: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1392 | netif_err(efx, probe, efx->net_dev, "Unknown PHY type %d\n", |
| 1393 | efx->phy_type); |
Ben Hutchings | 96c45726 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 1394 | return -ENODEV; |
| 1395 | } |
| 1396 | |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 1397 | /* Fill out MDIO structure and loopback modes */ |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1398 | mutex_init(&nic_data->mdio_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1399 | efx->mdio.mdio_read = falcon_mdio_read; |
| 1400 | efx->mdio.mdio_write = falcon_mdio_write; |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 1401 | rc = efx->phy_op->probe(efx); |
| 1402 | if (rc != 0) |
| 1403 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1404 | |
Steve Hodgson | b895d73 | 2009-11-28 05:35:00 +0000 | [diff] [blame] | 1405 | /* Initial assumption */ |
| 1406 | efx->link_state.speed = 10000; |
| 1407 | efx->link_state.fd = true; |
| 1408 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1409 | /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */ |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1410 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 1411 | efx->wanted_fc = EFX_FC_RX | EFX_FC_TX; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1412 | else |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 1413 | efx->wanted_fc = EFX_FC_RX; |
Steve Hodgson | 7a6b8f6 | 2010-02-03 09:30:38 +0000 | [diff] [blame] | 1414 | if (efx->mdio.mmds & MDIO_DEVS_AN) |
| 1415 | efx->wanted_fc |= EFX_FC_AUTO; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1416 | |
| 1417 | /* Allocate buffer for stats */ |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1418 | rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer, |
Ben Hutchings | 0d19a54 | 2012-09-18 21:59:52 +0100 | [diff] [blame] | 1419 | FALCON_MAC_STATS_SIZE, GFP_KERNEL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1420 | if (rc) |
| 1421 | return rc; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1422 | netif_dbg(efx, probe, efx->net_dev, |
| 1423 | "stats buffer at %llx (virt %p phys %llx)\n", |
| 1424 | (u64)efx->stats_buffer.dma_addr, |
| 1425 | efx->stats_buffer.addr, |
| 1426 | (u64)virt_to_phys(efx->stats_buffer.addr)); |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1427 | nic_data->stats_dma_done = efx->stats_buffer.addr + XgDmaDone_offset; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1428 | |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1432 | static void falcon_remove_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1433 | { |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 1434 | efx->phy_op->remove(efx); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1435 | efx_nic_free_buffer(efx, &efx->stats_buffer); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1436 | } |
| 1437 | |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 1438 | /* Global events are basically PHY events */ |
| 1439 | static bool |
| 1440 | falcon_handle_global_event(struct efx_channel *channel, efx_qword_t *event) |
| 1441 | { |
| 1442 | struct efx_nic *efx = channel->efx; |
Ben Hutchings | cef68bd | 2010-12-02 13:47:51 +0000 | [diff] [blame] | 1443 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 1444 | |
| 1445 | if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) || |
| 1446 | EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) || |
| 1447 | EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR)) |
| 1448 | /* Ignored */ |
| 1449 | return true; |
| 1450 | |
| 1451 | if ((efx_nic_rev(efx) == EFX_REV_FALCON_B0) && |
| 1452 | EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) { |
Ben Hutchings | cef68bd | 2010-12-02 13:47:51 +0000 | [diff] [blame] | 1453 | nic_data->xmac_poll_required = true; |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 1454 | return true; |
| 1455 | } |
| 1456 | |
| 1457 | if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ? |
| 1458 | EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) : |
| 1459 | EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) { |
| 1460 | netif_err(efx, rx_err, efx->net_dev, |
| 1461 | "channel %d seen global RX_RESET event. Resetting.\n", |
| 1462 | channel->channel); |
| 1463 | |
| 1464 | atomic_inc(&efx->rx_reset); |
| 1465 | efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ? |
| 1466 | RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE); |
| 1467 | return true; |
| 1468 | } |
| 1469 | |
| 1470 | return false; |
| 1471 | } |
| 1472 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1473 | /************************************************************************** |
| 1474 | * |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1475 | * Falcon test code |
| 1476 | * |
| 1477 | **************************************************************************/ |
| 1478 | |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 1479 | static int |
| 1480 | falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out) |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1481 | { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1482 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1483 | struct falcon_nvconfig *nvconfig; |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 1484 | struct falcon_spi_device *spi; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1485 | void *region; |
| 1486 | int rc, magic_num, struct_ver; |
| 1487 | __le16 *word, *limit; |
| 1488 | u32 csum; |
| 1489 | |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 1490 | if (falcon_spi_present(&nic_data->spi_flash)) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1491 | spi = &nic_data->spi_flash; |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 1492 | else if (falcon_spi_present(&nic_data->spi_eeprom)) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1493 | spi = &nic_data->spi_eeprom; |
| 1494 | else |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1495 | return -EINVAL; |
| 1496 | |
Ben Hutchings | 0a95f56 | 2008-11-04 20:33:11 +0000 | [diff] [blame] | 1497 | region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1498 | if (!region) |
| 1499 | return -ENOMEM; |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1500 | nvconfig = region + FALCON_NVCONFIG_OFFSET; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1501 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1502 | mutex_lock(&nic_data->spi_lock); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 1503 | rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region); |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1504 | mutex_unlock(&nic_data->spi_lock); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1505 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1506 | netif_err(efx, hw, efx->net_dev, "Failed to read %s\n", |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 1507 | falcon_spi_present(&nic_data->spi_flash) ? |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1508 | "flash" : "EEPROM"); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1509 | rc = -EIO; |
| 1510 | goto out; |
| 1511 | } |
| 1512 | |
| 1513 | magic_num = le16_to_cpu(nvconfig->board_magic_num); |
| 1514 | struct_ver = le16_to_cpu(nvconfig->board_struct_ver); |
| 1515 | |
| 1516 | rc = -EINVAL; |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1517 | if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1518 | netif_err(efx, hw, efx->net_dev, |
| 1519 | "NVRAM bad magic 0x%x\n", magic_num); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1520 | goto out; |
| 1521 | } |
| 1522 | if (struct_ver < 2) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1523 | netif_err(efx, hw, efx->net_dev, |
| 1524 | "NVRAM has ancient version 0x%x\n", struct_ver); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1525 | goto out; |
| 1526 | } else if (struct_ver < 4) { |
| 1527 | word = &nvconfig->board_magic_num; |
| 1528 | limit = (__le16 *) (nvconfig + 1); |
| 1529 | } else { |
| 1530 | word = region; |
Ben Hutchings | 0a95f56 | 2008-11-04 20:33:11 +0000 | [diff] [blame] | 1531 | limit = region + FALCON_NVCONFIG_END; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1532 | } |
| 1533 | for (csum = 0; word < limit; ++word) |
| 1534 | csum += le16_to_cpu(*word); |
| 1535 | |
| 1536 | if (~csum & 0xffff) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1537 | netif_err(efx, hw, efx->net_dev, |
| 1538 | "NVRAM has incorrect checksum\n"); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1539 | goto out; |
| 1540 | } |
| 1541 | |
| 1542 | rc = 0; |
| 1543 | if (nvconfig_out) |
| 1544 | memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig)); |
| 1545 | |
| 1546 | out: |
| 1547 | kfree(region); |
| 1548 | return rc; |
| 1549 | } |
| 1550 | |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 1551 | static int falcon_test_nvram(struct efx_nic *efx) |
| 1552 | { |
| 1553 | return falcon_read_nvram(efx, NULL); |
| 1554 | } |
| 1555 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 1556 | static const struct efx_farch_register_test falcon_b0_register_tests[] = { |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1557 | { FR_AZ_ADR_REGION, |
Steve Hodgson | 4cddca5 | 2010-02-03 09:31:40 +0000 | [diff] [blame] | 1558 | EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1559 | { FR_AZ_RX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1560 | EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1561 | { FR_AZ_TX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1562 | EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1563 | { FR_AZ_TX_RESERVED, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1564 | EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1565 | { FR_AB_MAC_CTRL, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1566 | EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1567 | { FR_AZ_SRM_TX_DC_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1568 | EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1569 | { FR_AZ_RX_DC_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1570 | EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1571 | { FR_AZ_RX_DC_PF_WM, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1572 | EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1573 | { FR_BZ_DP_CTRL, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1574 | EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1575 | { FR_AB_GM_CFG2, |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1576 | EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1577 | { FR_AB_GMF_CFG0, |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1578 | EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1579 | { FR_AB_XM_GLB_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1580 | EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1581 | { FR_AB_XM_TX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1582 | EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1583 | { FR_AB_XM_RX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1584 | EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1585 | { FR_AB_XM_RX_PARAM, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1586 | EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1587 | { FR_AB_XM_FC, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1588 | EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1589 | { FR_AB_XM_ADR_LO, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1590 | EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1591 | { FR_AB_XX_SD_CTL, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1592 | EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) }, |
| 1593 | }; |
| 1594 | |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 1595 | static int |
| 1596 | falcon_b0_test_chip(struct efx_nic *efx, struct efx_self_tests *tests) |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1597 | { |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 1598 | enum reset_type reset_method = RESET_TYPE_INVISIBLE; |
| 1599 | int rc, rc2; |
| 1600 | |
| 1601 | mutex_lock(&efx->mac_lock); |
| 1602 | if (efx->loopback_modes) { |
| 1603 | /* We need the 312 clock from the PHY to test the XMAC |
| 1604 | * registers, so move into XGMII loopback if available */ |
| 1605 | if (efx->loopback_modes & (1 << LOOPBACK_XGMII)) |
| 1606 | efx->loopback_mode = LOOPBACK_XGMII; |
| 1607 | else |
| 1608 | efx->loopback_mode = __ffs(efx->loopback_modes); |
| 1609 | } |
| 1610 | __efx_reconfigure_port(efx); |
| 1611 | mutex_unlock(&efx->mac_lock); |
| 1612 | |
| 1613 | efx_reset_down(efx, reset_method); |
| 1614 | |
| 1615 | tests->registers = |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 1616 | efx_farch_test_registers(efx, falcon_b0_register_tests, |
| 1617 | ARRAY_SIZE(falcon_b0_register_tests)) |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 1618 | ? -1 : 1; |
| 1619 | |
| 1620 | rc = falcon_reset_hw(efx, reset_method); |
| 1621 | rc2 = efx_reset_up(efx, reset_method, rc == 0); |
| 1622 | return rc ? rc : rc2; |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1625 | /************************************************************************** |
| 1626 | * |
| 1627 | * Device reset |
| 1628 | * |
| 1629 | ************************************************************************** |
| 1630 | */ |
| 1631 | |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 1632 | static enum reset_type falcon_map_reset_reason(enum reset_type reason) |
| 1633 | { |
| 1634 | switch (reason) { |
| 1635 | case RESET_TYPE_RX_RECOVERY: |
| 1636 | case RESET_TYPE_RX_DESC_FETCH: |
| 1637 | case RESET_TYPE_TX_DESC_FETCH: |
| 1638 | case RESET_TYPE_TX_SKIP: |
| 1639 | /* These can occasionally occur due to hardware bugs. |
| 1640 | * We try to reset without disrupting the link. |
| 1641 | */ |
| 1642 | return RESET_TYPE_INVISIBLE; |
| 1643 | default: |
| 1644 | return RESET_TYPE_ALL; |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | static int falcon_map_reset_flags(u32 *flags) |
| 1649 | { |
| 1650 | enum { |
| 1651 | FALCON_RESET_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER | |
| 1652 | ETH_RESET_OFFLOAD | ETH_RESET_MAC), |
| 1653 | FALCON_RESET_ALL = FALCON_RESET_INVISIBLE | ETH_RESET_PHY, |
| 1654 | FALCON_RESET_WORLD = FALCON_RESET_ALL | ETH_RESET_IRQ, |
| 1655 | }; |
| 1656 | |
| 1657 | if ((*flags & FALCON_RESET_WORLD) == FALCON_RESET_WORLD) { |
| 1658 | *flags &= ~FALCON_RESET_WORLD; |
| 1659 | return RESET_TYPE_WORLD; |
| 1660 | } |
| 1661 | |
| 1662 | if ((*flags & FALCON_RESET_ALL) == FALCON_RESET_ALL) { |
| 1663 | *flags &= ~FALCON_RESET_ALL; |
| 1664 | return RESET_TYPE_ALL; |
| 1665 | } |
| 1666 | |
| 1667 | if ((*flags & FALCON_RESET_INVISIBLE) == FALCON_RESET_INVISIBLE) { |
| 1668 | *flags &= ~FALCON_RESET_INVISIBLE; |
| 1669 | return RESET_TYPE_INVISIBLE; |
| 1670 | } |
| 1671 | |
| 1672 | return -EINVAL; |
| 1673 | } |
| 1674 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1675 | /* Resets NIC to known state. This routine must be called in process |
| 1676 | * context and is allowed to sleep. */ |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1677 | static int __falcon_reset_hw(struct efx_nic *efx, enum reset_type method) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1678 | { |
| 1679 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1680 | efx_oword_t glb_ctl_reg_ker; |
| 1681 | int rc; |
| 1682 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1683 | netif_dbg(efx, hw, efx->net_dev, "performing %s hardware reset\n", |
| 1684 | RESET_TYPE(method)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1685 | |
| 1686 | /* Initiate device reset */ |
| 1687 | if (method == RESET_TYPE_WORLD) { |
| 1688 | rc = pci_save_state(efx->pci_dev); |
| 1689 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1690 | netif_err(efx, drv, efx->net_dev, |
| 1691 | "failed to backup PCI state of primary " |
| 1692 | "function prior to hardware reset\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1693 | goto fail1; |
| 1694 | } |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1695 | if (efx_nic_is_dual_func(efx)) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1696 | rc = pci_save_state(nic_data->pci_dev2); |
| 1697 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1698 | netif_err(efx, drv, efx->net_dev, |
| 1699 | "failed to backup PCI state of " |
| 1700 | "secondary function prior to " |
| 1701 | "hardware reset\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1702 | goto fail2; |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | EFX_POPULATE_OWORD_2(glb_ctl_reg_ker, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1707 | FRF_AB_EXT_PHY_RST_DUR, |
| 1708 | FFE_AB_EXT_PHY_RST_DUR_10240US, |
| 1709 | FRF_AB_SWRST, 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1710 | } else { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1711 | EFX_POPULATE_OWORD_7(glb_ctl_reg_ker, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1712 | /* exclude PHY from "invisible" reset */ |
| 1713 | FRF_AB_EXT_PHY_RST_CTL, |
| 1714 | method == RESET_TYPE_INVISIBLE, |
| 1715 | /* exclude EEPROM/flash and PCIe */ |
| 1716 | FRF_AB_PCIE_CORE_RST_CTL, 1, |
| 1717 | FRF_AB_PCIE_NSTKY_RST_CTL, 1, |
| 1718 | FRF_AB_PCIE_SD_RST_CTL, 1, |
| 1719 | FRF_AB_EE_RST_CTL, 1, |
| 1720 | FRF_AB_EXT_PHY_RST_DUR, |
| 1721 | FFE_AB_EXT_PHY_RST_DUR_10240US, |
| 1722 | FRF_AB_SWRST, 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1723 | } |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1724 | efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1725 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1726 | netif_dbg(efx, hw, efx->net_dev, "waiting for hardware reset\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1727 | schedule_timeout_uninterruptible(HZ / 20); |
| 1728 | |
| 1729 | /* Restore PCI configuration if needed */ |
| 1730 | if (method == RESET_TYPE_WORLD) { |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 1731 | if (efx_nic_is_dual_func(efx)) |
| 1732 | pci_restore_state(nic_data->pci_dev2); |
| 1733 | pci_restore_state(efx->pci_dev); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1734 | netif_dbg(efx, drv, efx->net_dev, |
| 1735 | "successfully restored PCI config\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | /* Assert that reset complete */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1739 | efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1740 | if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1741 | rc = -ETIMEDOUT; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1742 | netif_err(efx, hw, efx->net_dev, |
| 1743 | "timed out waiting for hardware reset\n"); |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 1744 | goto fail3; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1745 | } |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1746 | netif_dbg(efx, hw, efx->net_dev, "hardware reset complete\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1747 | |
| 1748 | return 0; |
| 1749 | |
| 1750 | /* pci_save_state() and pci_restore_state() MUST be called in pairs */ |
| 1751 | fail2: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1752 | pci_restore_state(efx->pci_dev); |
| 1753 | fail1: |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 1754 | fail3: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1755 | return rc; |
| 1756 | } |
| 1757 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1758 | static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method) |
| 1759 | { |
| 1760 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1761 | int rc; |
| 1762 | |
| 1763 | mutex_lock(&nic_data->spi_lock); |
| 1764 | rc = __falcon_reset_hw(efx, method); |
| 1765 | mutex_unlock(&nic_data->spi_lock); |
| 1766 | |
| 1767 | return rc; |
| 1768 | } |
| 1769 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1770 | static void falcon_monitor(struct efx_nic *efx) |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1771 | { |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1772 | bool link_changed; |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1773 | int rc; |
| 1774 | |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1775 | BUG_ON(!mutex_is_locked(&efx->mac_lock)); |
| 1776 | |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1777 | rc = falcon_board(efx)->type->monitor(efx); |
| 1778 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1779 | netif_err(efx, hw, efx->net_dev, |
| 1780 | "Board sensor %s; shutting down PHY\n", |
| 1781 | (rc == -ERANGE) ? "reported fault" : "failed"); |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1782 | efx->phy_mode |= PHY_MODE_LOW_POWER; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1783 | rc = __efx_reconfigure_port(efx); |
| 1784 | WARN_ON(rc); |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1785 | } |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1786 | |
| 1787 | if (LOOPBACK_INTERNAL(efx)) |
| 1788 | link_changed = falcon_loopback_link_poll(efx); |
| 1789 | else |
| 1790 | link_changed = efx->phy_op->poll(efx); |
| 1791 | |
| 1792 | if (link_changed) { |
| 1793 | falcon_stop_nic_stats(efx); |
| 1794 | falcon_deconfigure_mac_wrapper(efx); |
| 1795 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1796 | falcon_reset_macs(efx); |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1797 | rc = falcon_reconfigure_xmac(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1798 | BUG_ON(rc); |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1799 | |
| 1800 | falcon_start_nic_stats(efx); |
| 1801 | |
| 1802 | efx_link_status_changed(efx); |
| 1803 | } |
| 1804 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1805 | falcon_poll_xmac(efx); |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1808 | /* Zeroes out the SRAM contents. This routine must be called in |
| 1809 | * process context and is allowed to sleep. |
| 1810 | */ |
| 1811 | static int falcon_reset_sram(struct efx_nic *efx) |
| 1812 | { |
| 1813 | efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker; |
| 1814 | int count; |
| 1815 | |
| 1816 | /* Set the SRAM wake/sleep GPIO appropriately. */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1817 | efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1818 | EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1); |
| 1819 | EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OUT, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1820 | efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1821 | |
| 1822 | /* Initiate SRAM reset */ |
| 1823 | EFX_POPULATE_OWORD_2(srm_cfg_reg_ker, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1824 | FRF_AZ_SRM_INIT_EN, 1, |
| 1825 | FRF_AZ_SRM_NB_SZ, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1826 | efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1827 | |
| 1828 | /* Wait for SRAM reset to complete */ |
| 1829 | count = 0; |
| 1830 | do { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1831 | netif_dbg(efx, hw, efx->net_dev, |
| 1832 | "waiting for SRAM reset (attempt %d)...\n", count); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1833 | |
| 1834 | /* SRAM reset is slow; expect around 16ms */ |
| 1835 | schedule_timeout_uninterruptible(HZ / 50); |
| 1836 | |
| 1837 | /* Check for reset complete */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1838 | efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1839 | if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, FRF_AZ_SRM_INIT_EN)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1840 | netif_dbg(efx, hw, efx->net_dev, |
| 1841 | "SRAM reset complete\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1842 | |
| 1843 | return 0; |
| 1844 | } |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1845 | } while (++count < 20); /* wait up to 0.4 sec */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1846 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1847 | netif_err(efx, hw, efx->net_dev, "timed out waiting for SRAM reset\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1848 | return -ETIMEDOUT; |
| 1849 | } |
| 1850 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1851 | static void falcon_spi_device_init(struct efx_nic *efx, |
Ben Hutchings | ecd0a6f0 | 2012-11-28 04:12:41 +0000 | [diff] [blame] | 1852 | struct falcon_spi_device *spi_device, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1853 | unsigned int device_id, u32 device_type) |
| 1854 | { |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1855 | if (device_type != 0) { |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1856 | spi_device->device_id = device_id; |
| 1857 | spi_device->size = |
| 1858 | 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE); |
| 1859 | spi_device->addr_len = |
| 1860 | SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN); |
| 1861 | spi_device->munge_address = (spi_device->size == 1 << 9 && |
| 1862 | spi_device->addr_len == 1); |
Ben Hutchings | f415072 | 2008-11-04 20:34:28 +0000 | [diff] [blame] | 1863 | spi_device->erase_command = |
| 1864 | SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD); |
| 1865 | spi_device->erase_size = |
| 1866 | 1 << SPI_DEV_TYPE_FIELD(device_type, |
| 1867 | SPI_DEV_TYPE_ERASE_SIZE); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1868 | spi_device->block_size = |
| 1869 | 1 << SPI_DEV_TYPE_FIELD(device_type, |
| 1870 | SPI_DEV_TYPE_BLOCK_SIZE); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1871 | } else { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1872 | spi_device->size = 0; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1873 | } |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1874 | } |
| 1875 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1876 | /* Extract non-volatile configuration */ |
| 1877 | static int falcon_probe_nvconfig(struct efx_nic *efx) |
| 1878 | { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1879 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1880 | struct falcon_nvconfig *nvconfig; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1881 | int rc; |
| 1882 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1883 | nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1884 | if (!nvconfig) |
| 1885 | return -ENOMEM; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1886 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1887 | rc = falcon_read_nvram(efx, nvconfig); |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1888 | if (rc) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1889 | goto out; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1890 | |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1891 | efx->phy_type = nvconfig->board_v2.port0_phy_type; |
| 1892 | efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1893 | |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1894 | if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1895 | falcon_spi_device_init( |
| 1896 | efx, &nic_data->spi_flash, FFE_AB_SPI_DEVICE_FLASH, |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1897 | le32_to_cpu(nvconfig->board_v3 |
| 1898 | .spi_device_type[FFE_AB_SPI_DEVICE_FLASH])); |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1899 | falcon_spi_device_init( |
| 1900 | efx, &nic_data->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM, |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1901 | le32_to_cpu(nvconfig->board_v3 |
| 1902 | .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM])); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1903 | } |
| 1904 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1905 | /* Read the MAC addresses */ |
Ben Hutchings | 7e300bc | 2010-12-02 13:48:28 +0000 | [diff] [blame] | 1906 | memcpy(efx->net_dev->perm_addr, nvconfig->mac_address[0], ETH_ALEN); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1907 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1908 | netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n", |
| 1909 | efx->phy_type, efx->mdio.prtad); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1910 | |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1911 | rc = falcon_probe_board(efx, |
| 1912 | le16_to_cpu(nvconfig->board_v2.board_revision)); |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1913 | out: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1914 | kfree(nvconfig); |
| 1915 | return rc; |
| 1916 | } |
| 1917 | |
Ben Hutchings | 28e47c4 | 2012-02-15 01:58:49 +0000 | [diff] [blame] | 1918 | static void falcon_dimension_resources(struct efx_nic *efx) |
| 1919 | { |
| 1920 | efx->rx_dc_base = 0x20000; |
| 1921 | efx->tx_dc_base = 0x26000; |
| 1922 | } |
| 1923 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1924 | /* Probe all SPI devices on the NIC */ |
| 1925 | static void falcon_probe_spi_devices(struct efx_nic *efx) |
| 1926 | { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1927 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1928 | efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg; |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1929 | int boot_dev; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1930 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1931 | efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL); |
| 1932 | efx_reado(efx, &nic_stat, FR_AB_NIC_STAT); |
| 1933 | efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1934 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1935 | if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) { |
| 1936 | boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ? |
| 1937 | FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1938 | netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n", |
| 1939 | boot_dev == FFE_AB_SPI_DEVICE_FLASH ? |
| 1940 | "flash" : "EEPROM"); |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1941 | } else { |
| 1942 | /* Disable VPD and set clock dividers to safe |
| 1943 | * values for initial programming. */ |
| 1944 | boot_dev = -1; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1945 | netif_dbg(efx, probe, efx->net_dev, |
| 1946 | "Booted from internal ASIC settings;" |
| 1947 | " setting SPI config\n"); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1948 | EFX_POPULATE_OWORD_3(ee_vpd_cfg, FRF_AB_EE_VPD_EN, 0, |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1949 | /* 125 MHz / 7 ~= 20 MHz */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1950 | FRF_AB_EE_SF_CLOCK_DIV, 7, |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1951 | /* 125 MHz / 63 ~= 2 MHz */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1952 | FRF_AB_EE_EE_CLOCK_DIV, 63); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1953 | efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1954 | } |
| 1955 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1956 | mutex_init(&nic_data->spi_lock); |
| 1957 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1958 | if (boot_dev == FFE_AB_SPI_DEVICE_FLASH) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1959 | falcon_spi_device_init(efx, &nic_data->spi_flash, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1960 | FFE_AB_SPI_DEVICE_FLASH, |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1961 | default_flash_type); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1962 | if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1963 | falcon_spi_device_init(efx, &nic_data->spi_eeprom, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1964 | FFE_AB_SPI_DEVICE_EEPROM, |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1965 | large_eeprom_type); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1966 | } |
| 1967 | |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 1968 | static unsigned int falcon_a1_mem_map_size(struct efx_nic *efx) |
| 1969 | { |
| 1970 | return 0x20000; |
| 1971 | } |
| 1972 | |
| 1973 | static unsigned int falcon_b0_mem_map_size(struct efx_nic *efx) |
| 1974 | { |
| 1975 | /* Map everything up to and including the RSS indirection table. |
| 1976 | * The PCI core takes care of mapping the MSI-X tables. |
| 1977 | */ |
| 1978 | return FR_BZ_RX_INDIRECTION_TBL + |
| 1979 | FR_BZ_RX_INDIRECTION_TBL_STEP * FR_BZ_RX_INDIRECTION_TBL_ROWS; |
| 1980 | } |
| 1981 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1982 | static int falcon_probe_nic(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1983 | { |
| 1984 | struct falcon_nic_data *nic_data; |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 1985 | struct falcon_board *board; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1986 | int rc; |
| 1987 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1988 | /* Allocate storage for hardware specific data */ |
| 1989 | nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); |
Ben Hutchings | 88c5942 | 2008-09-03 15:07:50 +0100 | [diff] [blame] | 1990 | if (!nic_data) |
| 1991 | return -ENOMEM; |
Ben Hutchings | 5daab96 | 2008-05-16 21:19:43 +0100 | [diff] [blame] | 1992 | efx->nic_data = nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1993 | |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 1994 | rc = -ENODEV; |
| 1995 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 1996 | if (efx_farch_fpga_ver(efx) != 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1997 | netif_err(efx, probe, efx->net_dev, |
| 1998 | "Falcon FPGA not supported\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1999 | goto fail1; |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2000 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2001 | |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2002 | if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) { |
| 2003 | efx_oword_t nic_stat; |
| 2004 | struct pci_dev *dev; |
| 2005 | u8 pci_rev = efx->pci_dev->revision; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2006 | |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2007 | if ((pci_rev == 0xff) || (pci_rev == 0)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2008 | netif_err(efx, probe, efx->net_dev, |
| 2009 | "Falcon rev A0 not supported\n"); |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2010 | goto fail1; |
| 2011 | } |
| 2012 | efx_reado(efx, &nic_stat, FR_AB_NIC_STAT); |
| 2013 | if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2014 | netif_err(efx, probe, efx->net_dev, |
| 2015 | "Falcon rev A1 1G not supported\n"); |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2016 | goto fail1; |
| 2017 | } |
| 2018 | if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2019 | netif_err(efx, probe, efx->net_dev, |
| 2020 | "Falcon rev A1 PCI-X not supported\n"); |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2021 | goto fail1; |
| 2022 | } |
| 2023 | |
| 2024 | dev = pci_dev_get(efx->pci_dev); |
Linus Torvalds | 0e59e7e7 | 2011-10-28 14:20:44 -0700 | [diff] [blame] | 2025 | while ((dev = pci_get_device(PCI_VENDOR_ID_SOLARFLARE, |
| 2026 | PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2027 | dev))) { |
| 2028 | if (dev->bus == efx->pci_dev->bus && |
| 2029 | dev->devfn == efx->pci_dev->devfn + 1) { |
| 2030 | nic_data->pci_dev2 = dev; |
| 2031 | break; |
| 2032 | } |
| 2033 | } |
| 2034 | if (!nic_data->pci_dev2) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2035 | netif_err(efx, probe, efx->net_dev, |
| 2036 | "failed to find secondary function\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2037 | rc = -ENODEV; |
| 2038 | goto fail2; |
| 2039 | } |
| 2040 | } |
| 2041 | |
| 2042 | /* Now we can reset the NIC */ |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 2043 | rc = __falcon_reset_hw(efx, RESET_TYPE_ALL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2044 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2045 | netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2046 | goto fail3; |
| 2047 | } |
| 2048 | |
| 2049 | /* Allocate memory for INT_KER */ |
Ben Hutchings | 0d19a54 | 2012-09-18 21:59:52 +0100 | [diff] [blame] | 2050 | rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t), |
| 2051 | GFP_KERNEL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2052 | if (rc) |
| 2053 | goto fail4; |
| 2054 | BUG_ON(efx->irq_status.dma_addr & 0x0f); |
| 2055 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2056 | netif_dbg(efx, probe, efx->net_dev, |
| 2057 | "INT_KER at %llx (virt %p phys %llx)\n", |
| 2058 | (u64)efx->irq_status.dma_addr, |
| 2059 | efx->irq_status.addr, |
| 2060 | (u64)virt_to_phys(efx->irq_status.addr)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2061 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 2062 | falcon_probe_spi_devices(efx); |
| 2063 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2064 | /* Read in the non-volatile configuration */ |
| 2065 | rc = falcon_probe_nvconfig(efx); |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 2066 | if (rc) { |
| 2067 | if (rc == -EINVAL) |
| 2068 | netif_err(efx, probe, efx->net_dev, "NVRAM is invalid\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2069 | goto fail5; |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 2070 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2071 | |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 2072 | efx->max_channels = (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ? 4 : |
| 2073 | EFX_MAX_CHANNELS); |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 2074 | efx->timer_quantum_ns = 4968; /* 621 cycles */ |
| 2075 | |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 2076 | /* Initialise I2C adapter */ |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 2077 | board = falcon_board(efx); |
| 2078 | board->i2c_adap.owner = THIS_MODULE; |
| 2079 | board->i2c_data = falcon_i2c_bit_operations; |
| 2080 | board->i2c_data.data = efx; |
| 2081 | board->i2c_adap.algo_data = &board->i2c_data; |
| 2082 | board->i2c_adap.dev.parent = &efx->pci_dev->dev; |
| 2083 | strlcpy(board->i2c_adap.name, "SFC4000 GPIO", |
| 2084 | sizeof(board->i2c_adap.name)); |
| 2085 | rc = i2c_bit_add_bus(&board->i2c_adap); |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 2086 | if (rc) |
| 2087 | goto fail5; |
| 2088 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 2089 | rc = falcon_board(efx)->type->init(efx); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2090 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2091 | netif_err(efx, probe, efx->net_dev, |
| 2092 | "failed to initialise board\n"); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2093 | goto fail6; |
| 2094 | } |
| 2095 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2096 | nic_data->stats_disable_count = 1; |
| 2097 | setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func, |
| 2098 | (unsigned long)efx); |
| 2099 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2100 | return 0; |
| 2101 | |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2102 | fail6: |
Lars-Peter Clausen | bf51a8c | 2013-03-09 08:16:46 +0000 | [diff] [blame] | 2103 | i2c_del_adapter(&board->i2c_adap); |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 2104 | memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2105 | fail5: |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2106 | efx_nic_free_buffer(efx, &efx->irq_status); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2107 | fail4: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2108 | fail3: |
| 2109 | if (nic_data->pci_dev2) { |
| 2110 | pci_dev_put(nic_data->pci_dev2); |
| 2111 | nic_data->pci_dev2 = NULL; |
| 2112 | } |
| 2113 | fail2: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2114 | fail1: |
| 2115 | kfree(efx->nic_data); |
| 2116 | return rc; |
| 2117 | } |
| 2118 | |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2119 | static void falcon_init_rx_cfg(struct efx_nic *efx) |
| 2120 | { |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2121 | /* RX control FIFO thresholds (32 entries) */ |
| 2122 | const unsigned ctrl_xon_thr = 20; |
| 2123 | const unsigned ctrl_xoff_thr = 25; |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2124 | efx_oword_t reg; |
| 2125 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2126 | efx_reado(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 2127 | if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) { |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 2128 | /* Data FIFO size is 5.5K. The RX DMA engine only |
| 2129 | * supports scattering for user-mode queues, but will |
| 2130 | * split DMA writes at intervals of RX_USR_BUF_SIZE |
| 2131 | * (32-byte units) even for kernel-mode queues. We |
| 2132 | * set it to be so large that that never happens. |
| 2133 | */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2134 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0); |
| 2135 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE, |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 2136 | (3 * 4096) >> 5); |
Ben Hutchings | 5fb6b06 | 2011-02-24 19:30:41 +0000 | [diff] [blame] | 2137 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, 512 >> 8); |
| 2138 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_MAC_TH, 2048 >> 8); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2139 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr); |
| 2140 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XOFF_TX_TH, ctrl_xoff_thr); |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2141 | } else { |
Ben Hutchings | 625b451 | 2009-10-23 08:30:17 +0000 | [diff] [blame] | 2142 | /* Data FIFO size is 80K; register fields moved */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2143 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0); |
| 2144 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE, |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 2145 | EFX_RX_USR_BUF_SIZE >> 5); |
Ben Hutchings | 5fb6b06 | 2011-02-24 19:30:41 +0000 | [diff] [blame] | 2146 | /* Send XON and XOFF at ~3 * max MTU away from empty/full */ |
| 2147 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, 27648 >> 8); |
| 2148 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_MAC_TH, 54272 >> 8); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2149 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr); |
| 2150 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr); |
| 2151 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1); |
Ben Hutchings | 477e54e | 2010-06-25 07:05:56 +0000 | [diff] [blame] | 2152 | |
| 2153 | /* Enable hash insertion. This is broken for the |
| 2154 | * 'Falcon' hash so also select Toeplitz TCP/IPv4 and |
| 2155 | * IPv4 hashes. */ |
| 2156 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1); |
| 2157 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1); |
| 2158 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1); |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2159 | } |
Ben Hutchings | 4b0d29d | 2009-11-29 03:42:18 +0000 | [diff] [blame] | 2160 | /* Always enable XOFF signal from RX FIFO. We enable |
| 2161 | * or disable transmission of pause frames at the MAC. */ |
| 2162 | EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2163 | efx_writeo(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2166 | /* This call performs hardware-specific global initialisation, such as |
| 2167 | * defining the descriptor cache sizes and number of RSS channels. |
| 2168 | * It does not set up any buffers, descriptor rings or event queues. |
| 2169 | */ |
| 2170 | static int falcon_init_nic(struct efx_nic *efx) |
| 2171 | { |
| 2172 | efx_oword_t temp; |
| 2173 | int rc; |
| 2174 | |
| 2175 | /* Use on-chip SRAM */ |
| 2176 | efx_reado(efx, &temp, FR_AB_NIC_STAT); |
| 2177 | EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1); |
| 2178 | efx_writeo(efx, &temp, FR_AB_NIC_STAT); |
| 2179 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2180 | rc = falcon_reset_sram(efx); |
| 2181 | if (rc) |
| 2182 | return rc; |
| 2183 | |
| 2184 | /* Clear the parity enables on the TX data fifos as |
| 2185 | * they produce false parity errors because of timing issues |
| 2186 | */ |
| 2187 | if (EFX_WORKAROUND_5129(efx)) { |
| 2188 | efx_reado(efx, &temp, FR_AZ_CSR_SPARE); |
| 2189 | EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0); |
| 2190 | efx_writeo(efx, &temp, FR_AZ_CSR_SPARE); |
| 2191 | } |
| 2192 | |
| 2193 | if (EFX_WORKAROUND_7244(efx)) { |
| 2194 | efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL); |
| 2195 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8); |
| 2196 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8); |
| 2197 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8); |
| 2198 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8); |
| 2199 | efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL); |
| 2200 | } |
| 2201 | |
| 2202 | /* XXX This is documented only for Falcon A0/A1 */ |
| 2203 | /* Setup RX. Wait for descriptor is broken and must |
| 2204 | * be disabled. RXDP recovery shouldn't be needed, but is. |
| 2205 | */ |
| 2206 | efx_reado(efx, &temp, FR_AA_RX_SELF_RST); |
| 2207 | EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1); |
| 2208 | EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1); |
| 2209 | if (EFX_WORKAROUND_5583(efx)) |
| 2210 | EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1); |
| 2211 | efx_writeo(efx, &temp, FR_AA_RX_SELF_RST); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2212 | |
| 2213 | /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16 |
| 2214 | * descriptors (which is bad). |
| 2215 | */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2216 | efx_reado(efx, &temp, FR_AZ_TX_CFG); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2217 | EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_NO_EOP_DISC_EN, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2218 | efx_writeo(efx, &temp, FR_AZ_TX_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2219 | |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2220 | falcon_init_rx_cfg(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2221 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 2222 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) { |
Ben Hutchings | 477e54e | 2010-06-25 07:05:56 +0000 | [diff] [blame] | 2223 | /* Set hash key for IPv4 */ |
| 2224 | memcpy(&temp, efx->rx_hash_key, sizeof(temp)); |
| 2225 | efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY); |
| 2226 | |
| 2227 | /* Set destination of both TX and RX Flush events */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2228 | EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2229 | efx_writeo(efx, &temp, FR_BZ_DP_CTRL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2230 | } |
| 2231 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 2232 | efx_farch_init_common(efx); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2233 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2234 | return 0; |
| 2235 | } |
| 2236 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2237 | static void falcon_remove_nic(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2238 | { |
| 2239 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 2240 | struct falcon_board *board = falcon_board(efx); |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 2241 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 2242 | board->type->fini(efx); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2243 | |
Ben Hutchings | 8c87037 | 2009-03-04 09:53:02 +0000 | [diff] [blame] | 2244 | /* Remove I2C adapter and clear it in preparation for a retry */ |
Lars-Peter Clausen | bf51a8c | 2013-03-09 08:16:46 +0000 | [diff] [blame] | 2245 | i2c_del_adapter(&board->i2c_adap); |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 2246 | memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2247 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2248 | efx_nic_free_buffer(efx, &efx->irq_status); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2249 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 2250 | __falcon_reset_hw(efx, RESET_TYPE_ALL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2251 | |
| 2252 | /* Release the second function after the reset */ |
| 2253 | if (nic_data->pci_dev2) { |
| 2254 | pci_dev_put(nic_data->pci_dev2); |
| 2255 | nic_data->pci_dev2 = NULL; |
| 2256 | } |
| 2257 | |
| 2258 | /* Tear down the private nic state */ |
| 2259 | kfree(efx->nic_data); |
| 2260 | efx->nic_data = NULL; |
| 2261 | } |
| 2262 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2263 | static void falcon_update_nic_stats(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2264 | { |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2265 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2266 | efx_oword_t cnt; |
| 2267 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2268 | if (nic_data->stats_disable_count) |
| 2269 | return; |
| 2270 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2271 | efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2272 | efx->n_rx_nodesc_drop_cnt += |
| 2273 | EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2274 | |
| 2275 | if (nic_data->stats_pending && |
| 2276 | *nic_data->stats_dma_done == FALCON_STATS_DONE) { |
| 2277 | nic_data->stats_pending = false; |
| 2278 | rmb(); /* read the done flag before the stats */ |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 2279 | falcon_update_stats_xmac(efx); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | void falcon_start_nic_stats(struct efx_nic *efx) |
| 2284 | { |
| 2285 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 2286 | |
| 2287 | spin_lock_bh(&efx->stats_lock); |
| 2288 | if (--nic_data->stats_disable_count == 0) |
| 2289 | falcon_stats_request(efx); |
| 2290 | spin_unlock_bh(&efx->stats_lock); |
| 2291 | } |
| 2292 | |
| 2293 | void falcon_stop_nic_stats(struct efx_nic *efx) |
| 2294 | { |
| 2295 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 2296 | int i; |
| 2297 | |
| 2298 | might_sleep(); |
| 2299 | |
| 2300 | spin_lock_bh(&efx->stats_lock); |
| 2301 | ++nic_data->stats_disable_count; |
| 2302 | spin_unlock_bh(&efx->stats_lock); |
| 2303 | |
| 2304 | del_timer_sync(&nic_data->stats_timer); |
| 2305 | |
| 2306 | /* Wait enough time for the most recent transfer to |
| 2307 | * complete. */ |
| 2308 | for (i = 0; i < 4 && nic_data->stats_pending; i++) { |
| 2309 | if (*nic_data->stats_dma_done == FALCON_STATS_DONE) |
| 2310 | break; |
| 2311 | msleep(1); |
| 2312 | } |
| 2313 | |
| 2314 | spin_lock_bh(&efx->stats_lock); |
| 2315 | falcon_stats_complete(efx); |
| 2316 | spin_unlock_bh(&efx->stats_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2317 | } |
| 2318 | |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 2319 | static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode) |
| 2320 | { |
| 2321 | falcon_board(efx)->type->set_id_led(efx, mode); |
| 2322 | } |
| 2323 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2324 | /************************************************************************** |
| 2325 | * |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2326 | * Wake on LAN |
| 2327 | * |
| 2328 | ************************************************************************** |
| 2329 | */ |
| 2330 | |
| 2331 | static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol) |
| 2332 | { |
| 2333 | wol->supported = 0; |
| 2334 | wol->wolopts = 0; |
| 2335 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 2336 | } |
| 2337 | |
| 2338 | static int falcon_set_wol(struct efx_nic *efx, u32 type) |
| 2339 | { |
| 2340 | if (type != 0) |
| 2341 | return -EINVAL; |
| 2342 | return 0; |
| 2343 | } |
| 2344 | |
| 2345 | /************************************************************************** |
| 2346 | * |
Ben Hutchings | 754c653 | 2010-02-03 09:31:57 +0000 | [diff] [blame] | 2347 | * Revision-dependent attributes used by efx.c and nic.c |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2348 | * |
| 2349 | ************************************************************************** |
| 2350 | */ |
| 2351 | |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 2352 | const struct efx_nic_type falcon_a1_nic_type = { |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 2353 | .mem_map_size = falcon_a1_mem_map_size, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2354 | .probe = falcon_probe_nic, |
| 2355 | .remove = falcon_remove_nic, |
| 2356 | .init = falcon_init_nic, |
Ben Hutchings | 28e47c4 | 2012-02-15 01:58:49 +0000 | [diff] [blame] | 2357 | .dimension_resources = falcon_dimension_resources, |
Ben Hutchings | 1840667 | 2013-01-03 23:36:57 +0000 | [diff] [blame] | 2358 | .fini = falcon_irq_ack_a1, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2359 | .monitor = falcon_monitor, |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 2360 | .map_reset_reason = falcon_map_reset_reason, |
| 2361 | .map_reset_flags = falcon_map_reset_flags, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2362 | .reset = falcon_reset_hw, |
| 2363 | .probe_port = falcon_probe_port, |
| 2364 | .remove_port = falcon_remove_port, |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 2365 | .handle_global_event = falcon_handle_global_event, |
Ben Hutchings | e42c3d8 | 2013-05-27 16:52:54 +0100 | [diff] [blame] | 2366 | .fini_dmaq = efx_farch_fini_dmaq, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2367 | .prepare_flush = falcon_prepare_flush, |
Ben Hutchings | d5e8cc6 | 2012-09-06 16:52:31 +0100 | [diff] [blame] | 2368 | .finish_flush = efx_port_dummy_op_void, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2369 | .update_stats = falcon_update_nic_stats, |
| 2370 | .start_stats = falcon_start_nic_stats, |
| 2371 | .stop_stats = falcon_stop_nic_stats, |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 2372 | .set_id_led = falcon_set_id_led, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2373 | .push_irq_moderation = falcon_push_irq_moderation, |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2374 | .reconfigure_port = falcon_reconfigure_port, |
Ben Hutchings | 9dd3a13 | 2012-09-13 01:11:25 +0100 | [diff] [blame] | 2375 | .prepare_enable_fc_tx = falcon_a1_prepare_enable_fc_tx, |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 2376 | .reconfigure_mac = falcon_reconfigure_xmac, |
| 2377 | .check_mac_fault = falcon_xmac_check_fault, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2378 | .get_wol = falcon_get_wol, |
| 2379 | .set_wol = falcon_set_wol, |
| 2380 | .resume_wol = efx_port_dummy_op_void, |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 2381 | .test_nvram = falcon_test_nvram, |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 2382 | .irq_enable_master = efx_farch_irq_enable_master, |
| 2383 | .irq_test_generate = efx_farch_irq_test_generate, |
| 2384 | .irq_disable_non_ev = efx_farch_irq_disable_master, |
| 2385 | .irq_handle_msi = efx_farch_msi_interrupt, |
| 2386 | .irq_handle_legacy = falcon_legacy_interrupt_a1, |
| 2387 | .tx_probe = efx_farch_tx_probe, |
| 2388 | .tx_init = efx_farch_tx_init, |
| 2389 | .tx_remove = efx_farch_tx_remove, |
| 2390 | .tx_write = efx_farch_tx_write, |
| 2391 | .rx_push_indir_table = efx_farch_rx_push_indir_table, |
| 2392 | .rx_probe = efx_farch_rx_probe, |
| 2393 | .rx_init = efx_farch_rx_init, |
| 2394 | .rx_remove = efx_farch_rx_remove, |
| 2395 | .rx_write = efx_farch_rx_write, |
| 2396 | .rx_defer_refill = efx_farch_rx_defer_refill, |
| 2397 | .ev_probe = efx_farch_ev_probe, |
| 2398 | .ev_init = efx_farch_ev_init, |
| 2399 | .ev_fini = efx_farch_ev_fini, |
| 2400 | .ev_remove = efx_farch_ev_remove, |
| 2401 | .ev_process = efx_farch_ev_process, |
| 2402 | .ev_read_ack = efx_farch_ev_read_ack, |
| 2403 | .ev_test_generate = efx_farch_ev_test_generate, |
Steve Hodgson | b895d73 | 2009-11-28 05:35:00 +0000 | [diff] [blame] | 2404 | |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 2405 | /* We don't expose the filter table on Falcon A1 as it is not |
| 2406 | * mapped into function 0, but these implementations still |
| 2407 | * work with a degenerate case of all tables set to size 0. |
| 2408 | */ |
| 2409 | .filter_table_probe = efx_farch_filter_table_probe, |
| 2410 | .filter_table_restore = efx_farch_filter_table_restore, |
| 2411 | .filter_table_remove = efx_farch_filter_table_remove, |
| 2412 | .filter_insert = efx_farch_filter_insert, |
| 2413 | .filter_remove_safe = efx_farch_filter_remove_safe, |
| 2414 | .filter_get_safe = efx_farch_filter_get_safe, |
| 2415 | .filter_clear_rx = efx_farch_filter_clear_rx, |
| 2416 | .filter_count_rx_used = efx_farch_filter_count_rx_used, |
| 2417 | .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit, |
| 2418 | .filter_get_rx_ids = efx_farch_filter_get_rx_ids, |
| 2419 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 2420 | .revision = EFX_REV_FALCON_A1, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2421 | .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER, |
| 2422 | .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER, |
| 2423 | .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER, |
| 2424 | .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER, |
| 2425 | .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER, |
Ben Hutchings | 6d51d30 | 2009-10-23 08:31:07 +0000 | [diff] [blame] | 2426 | .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2427 | .rx_buffer_padding = 0x24, |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 2428 | .can_rx_scatter = false, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2429 | .max_interrupt_mode = EFX_INT_MODE_MSI, |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 2430 | .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH, |
Ben Hutchings | c383b53 | 2009-11-29 15:11:02 +0000 | [diff] [blame] | 2431 | .offload_features = NETIF_F_IP_CSUM, |
Ben Hutchings | df2cd8a | 2012-09-19 00:56:18 +0100 | [diff] [blame] | 2432 | .mcdi_max_ver = -1, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2433 | }; |
| 2434 | |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 2435 | const struct efx_nic_type falcon_b0_nic_type = { |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 2436 | .mem_map_size = falcon_b0_mem_map_size, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2437 | .probe = falcon_probe_nic, |
| 2438 | .remove = falcon_remove_nic, |
| 2439 | .init = falcon_init_nic, |
Ben Hutchings | 28e47c4 | 2012-02-15 01:58:49 +0000 | [diff] [blame] | 2440 | .dimension_resources = falcon_dimension_resources, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2441 | .fini = efx_port_dummy_op_void, |
| 2442 | .monitor = falcon_monitor, |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 2443 | .map_reset_reason = falcon_map_reset_reason, |
| 2444 | .map_reset_flags = falcon_map_reset_flags, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2445 | .reset = falcon_reset_hw, |
| 2446 | .probe_port = falcon_probe_port, |
| 2447 | .remove_port = falcon_remove_port, |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 2448 | .handle_global_event = falcon_handle_global_event, |
Ben Hutchings | e42c3d8 | 2013-05-27 16:52:54 +0100 | [diff] [blame] | 2449 | .fini_dmaq = efx_farch_fini_dmaq, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2450 | .prepare_flush = falcon_prepare_flush, |
Ben Hutchings | d5e8cc6 | 2012-09-06 16:52:31 +0100 | [diff] [blame] | 2451 | .finish_flush = efx_port_dummy_op_void, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2452 | .update_stats = falcon_update_nic_stats, |
| 2453 | .start_stats = falcon_start_nic_stats, |
| 2454 | .stop_stats = falcon_stop_nic_stats, |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 2455 | .set_id_led = falcon_set_id_led, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2456 | .push_irq_moderation = falcon_push_irq_moderation, |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2457 | .reconfigure_port = falcon_reconfigure_port, |
Ben Hutchings | 9dd3a13 | 2012-09-13 01:11:25 +0100 | [diff] [blame] | 2458 | .prepare_enable_fc_tx = falcon_b0_prepare_enable_fc_tx, |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 2459 | .reconfigure_mac = falcon_reconfigure_xmac, |
| 2460 | .check_mac_fault = falcon_xmac_check_fault, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2461 | .get_wol = falcon_get_wol, |
| 2462 | .set_wol = falcon_set_wol, |
| 2463 | .resume_wol = efx_port_dummy_op_void, |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 2464 | .test_chip = falcon_b0_test_chip, |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 2465 | .test_nvram = falcon_test_nvram, |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 2466 | .irq_enable_master = efx_farch_irq_enable_master, |
| 2467 | .irq_test_generate = efx_farch_irq_test_generate, |
| 2468 | .irq_disable_non_ev = efx_farch_irq_disable_master, |
| 2469 | .irq_handle_msi = efx_farch_msi_interrupt, |
| 2470 | .irq_handle_legacy = efx_farch_legacy_interrupt, |
| 2471 | .tx_probe = efx_farch_tx_probe, |
| 2472 | .tx_init = efx_farch_tx_init, |
| 2473 | .tx_remove = efx_farch_tx_remove, |
| 2474 | .tx_write = efx_farch_tx_write, |
| 2475 | .rx_push_indir_table = efx_farch_rx_push_indir_table, |
| 2476 | .rx_probe = efx_farch_rx_probe, |
| 2477 | .rx_init = efx_farch_rx_init, |
| 2478 | .rx_remove = efx_farch_rx_remove, |
| 2479 | .rx_write = efx_farch_rx_write, |
| 2480 | .rx_defer_refill = efx_farch_rx_defer_refill, |
| 2481 | .ev_probe = efx_farch_ev_probe, |
| 2482 | .ev_init = efx_farch_ev_init, |
| 2483 | .ev_fini = efx_farch_ev_fini, |
| 2484 | .ev_remove = efx_farch_ev_remove, |
| 2485 | .ev_process = efx_farch_ev_process, |
| 2486 | .ev_read_ack = efx_farch_ev_read_ack, |
| 2487 | .ev_test_generate = efx_farch_ev_test_generate, |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 2488 | .filter_table_probe = efx_farch_filter_table_probe, |
| 2489 | .filter_table_restore = efx_farch_filter_table_restore, |
| 2490 | .filter_table_remove = efx_farch_filter_table_remove, |
| 2491 | .filter_update_rx_scatter = efx_farch_filter_update_rx_scatter, |
| 2492 | .filter_insert = efx_farch_filter_insert, |
| 2493 | .filter_remove_safe = efx_farch_filter_remove_safe, |
| 2494 | .filter_get_safe = efx_farch_filter_get_safe, |
| 2495 | .filter_clear_rx = efx_farch_filter_clear_rx, |
| 2496 | .filter_count_rx_used = efx_farch_filter_count_rx_used, |
| 2497 | .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit, |
| 2498 | .filter_get_rx_ids = efx_farch_filter_get_rx_ids, |
| 2499 | #ifdef CONFIG_RFS_ACCEL |
| 2500 | .filter_rfs_insert = efx_farch_filter_rfs_insert, |
| 2501 | .filter_rfs_expire_one = efx_farch_filter_rfs_expire_one, |
| 2502 | #endif |
Steve Hodgson | b895d73 | 2009-11-28 05:35:00 +0000 | [diff] [blame] | 2503 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 2504 | .revision = EFX_REV_FALCON_B0, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2505 | .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL, |
| 2506 | .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL, |
| 2507 | .buf_tbl_base = FR_BZ_BUF_FULL_TBL, |
| 2508 | .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL, |
| 2509 | .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR, |
Ben Hutchings | 6d51d30 | 2009-10-23 08:31:07 +0000 | [diff] [blame] | 2510 | .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH), |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 2511 | .rx_buffer_hash_size = 0x10, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2512 | .rx_buffer_padding = 0, |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 2513 | .can_rx_scatter = true, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2514 | .max_interrupt_mode = EFX_INT_MODE_MSIX, |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 2515 | .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH, |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 2516 | .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH | NETIF_F_NTUPLE, |
Ben Hutchings | df2cd8a | 2012-09-19 00:56:18 +0100 | [diff] [blame] | 2517 | .mcdi_max_ver = -1, |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame] | 2518 | .max_rx_ip_filters = FR_BZ_RX_FILTER_TBL0_ROWS, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2519 | }; |
| 2520 | |