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 | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 437 | int falcon_spi_cmd(struct efx_nic *efx, const struct efx_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 |
| 494 | falcon_spi_write_limit(const struct efx_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 |
| 501 | efx_spi_munge_command(const struct efx_spi_device *spi, |
| 502 | const u8 command, const unsigned int address) |
| 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 |
| 509 | falcon_spi_wait_write(struct efx_nic *efx, const struct efx_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 | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 533 | int falcon_spi_read(struct efx_nic *efx, const struct efx_spi_device *spi, |
| 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 | |
| 543 | command = efx_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 |
| 564 | falcon_spi_write(struct efx_nic *efx, const struct efx_spi_device *spi, |
| 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)); |
| 579 | command = efx_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 | |
| 589 | command = efx_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, |
| 767 | FRF_AB_XM_ACPT_ALL_UCAST, efx->promiscuous, |
| 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 | |
| 867 | falcon_reconfigure_xgxs_core(efx); |
| 868 | falcon_reconfigure_xmac_core(efx); |
| 869 | |
| 870 | falcon_reconfigure_mac_wrapper(efx); |
| 871 | |
| 872 | nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 5); |
| 873 | falcon_ack_status_intr(efx); |
| 874 | |
| 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | static void falcon_update_stats_xmac(struct efx_nic *efx) |
| 879 | { |
| 880 | struct efx_mac_stats *mac_stats = &efx->mac_stats; |
| 881 | |
| 882 | /* Update MAC stats from DMAed values */ |
| 883 | FALCON_STAT(efx, XgRxOctets, rx_bytes); |
| 884 | FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes); |
| 885 | FALCON_STAT(efx, XgRxPkts, rx_packets); |
| 886 | FALCON_STAT(efx, XgRxPktsOK, rx_good); |
| 887 | FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast); |
| 888 | FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast); |
| 889 | FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast); |
| 890 | FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64); |
| 891 | FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo); |
| 892 | FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo); |
| 893 | FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64); |
| 894 | FALCON_STAT(efx, XgRxDropEvents, rx_overflow); |
| 895 | FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad); |
| 896 | FALCON_STAT(efx, XgRxAlignError, rx_align_error); |
| 897 | FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error); |
| 898 | FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error); |
| 899 | FALCON_STAT(efx, XgRxControlPkts, rx_control); |
| 900 | FALCON_STAT(efx, XgRxPausePkts, rx_pause); |
| 901 | FALCON_STAT(efx, XgRxPkts64Octets, rx_64); |
| 902 | FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127); |
| 903 | FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255); |
| 904 | FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511); |
| 905 | FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023); |
| 906 | FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx); |
| 907 | FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo); |
| 908 | FALCON_STAT(efx, XgRxLengthError, rx_length_error); |
| 909 | FALCON_STAT(efx, XgTxPkts, tx_packets); |
| 910 | FALCON_STAT(efx, XgTxOctets, tx_bytes); |
| 911 | FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast); |
| 912 | FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast); |
| 913 | FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast); |
| 914 | FALCON_STAT(efx, XgTxControlPkts, tx_control); |
| 915 | FALCON_STAT(efx, XgTxPausePkts, tx_pause); |
| 916 | FALCON_STAT(efx, XgTxPkts64Octets, tx_64); |
| 917 | FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127); |
| 918 | FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255); |
| 919 | FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511); |
| 920 | FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023); |
| 921 | FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx); |
| 922 | FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo); |
| 923 | FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64); |
| 924 | FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo); |
| 925 | FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp); |
| 926 | FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error); |
| 927 | FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error); |
| 928 | |
| 929 | /* Update derived statistics */ |
| 930 | efx_update_diff_stat(&mac_stats->tx_good_bytes, |
| 931 | mac_stats->tx_bytes - mac_stats->tx_bad_bytes - |
| 932 | mac_stats->tx_control * 64); |
| 933 | efx_update_diff_stat(&mac_stats->rx_bad_bytes, |
| 934 | mac_stats->rx_bytes - mac_stats->rx_good_bytes - |
| 935 | mac_stats->rx_control * 64); |
| 936 | } |
| 937 | |
| 938 | static void falcon_poll_xmac(struct efx_nic *efx) |
| 939 | { |
| 940 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 941 | |
Ben Hutchings | ab3b825 | 2012-10-05 19:31:02 +0100 | [diff] [blame] | 942 | /* We expect xgmii faults if the wireside link is down */ |
| 943 | if (!efx->link_state.up || !nic_data->xmac_poll_required) |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 944 | return; |
| 945 | |
| 946 | nic_data->xmac_poll_required = !falcon_xmac_link_ok_retry(efx, 1); |
| 947 | falcon_ack_status_intr(efx); |
| 948 | } |
| 949 | |
| 950 | /************************************************************************** |
| 951 | * |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 952 | * MAC wrapper |
| 953 | * |
| 954 | ************************************************************************** |
| 955 | */ |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 956 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 957 | static void falcon_push_multicast_hash(struct efx_nic *efx) |
| 958 | { |
| 959 | union efx_multicast_hash *mc_hash = &efx->multicast_hash; |
| 960 | |
| 961 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
| 962 | |
| 963 | efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0); |
| 964 | efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1); |
| 965 | } |
| 966 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 967 | static void falcon_reset_macs(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 968 | { |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 969 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 970 | efx_oword_t reg, mac_ctrl; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 971 | int count; |
| 972 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 973 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) { |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 974 | /* It's not safe to use GLB_CTL_REG to reset the |
| 975 | * macs, so instead use the internal MAC resets |
| 976 | */ |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 977 | EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1); |
| 978 | efx_writeo(efx, ®, FR_AB_XM_GLB_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 979 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 980 | for (count = 0; count < 10000; count++) { |
| 981 | efx_reado(efx, ®, FR_AB_XM_GLB_CFG); |
| 982 | if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) == |
| 983 | 0) |
| 984 | return; |
| 985 | udelay(10); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 986 | } |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 987 | |
| 988 | netif_err(efx, hw, efx->net_dev, |
| 989 | "timed out waiting for XMAC core reset\n"); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 990 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 991 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 992 | /* Mac stats will fail whist the TX fifo is draining */ |
| 993 | WARN_ON(nic_data->stats_disable_count == 0); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 994 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 995 | efx_reado(efx, &mac_ctrl, FR_AB_MAC_CTRL); |
| 996 | EFX_SET_OWORD_FIELD(mac_ctrl, FRF_BB_TXFIFO_DRAIN_EN, 1); |
| 997 | efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 998 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 999 | efx_reado(efx, ®, FR_AB_GLB_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1000 | EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1); |
| 1001 | EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1); |
| 1002 | EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1003 | efx_writeo(efx, ®, FR_AB_GLB_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1004 | |
| 1005 | count = 0; |
| 1006 | while (1) { |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1007 | efx_reado(efx, ®, FR_AB_GLB_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1008 | if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) && |
| 1009 | !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) && |
| 1010 | !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1011 | netif_dbg(efx, hw, efx->net_dev, |
| 1012 | "Completed MAC reset after %d loops\n", |
| 1013 | count); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1014 | break; |
| 1015 | } |
| 1016 | if (count > 20) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1017 | netif_err(efx, hw, efx->net_dev, "MAC reset failed\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1018 | break; |
| 1019 | } |
| 1020 | count++; |
| 1021 | udelay(10); |
| 1022 | } |
| 1023 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1024 | /* Ensure the correct MAC is selected before statistics |
| 1025 | * are re-enabled by the caller */ |
| 1026 | efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL); |
Steve Hodgson | b7b40ee | 2010-04-28 09:28:10 +0000 | [diff] [blame] | 1027 | |
Steve Hodgson | b7b40ee | 2010-04-28 09:28:10 +0000 | [diff] [blame] | 1028 | falcon_setup_xaui(efx); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
Ben Hutchings | 9dd3a13 | 2012-09-13 01:11:25 +0100 | [diff] [blame] | 1031 | static void falcon_drain_tx_fifo(struct efx_nic *efx) |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1032 | { |
| 1033 | efx_oword_t reg; |
| 1034 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1035 | if ((efx_nic_rev(efx) < EFX_REV_FALCON_B0) || |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1036 | (efx->loopback_mode != LOOPBACK_NONE)) |
| 1037 | return; |
| 1038 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1039 | efx_reado(efx, ®, FR_AB_MAC_CTRL); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1040 | /* There is no point in draining more than once */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1041 | if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN)) |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1042 | return; |
| 1043 | |
| 1044 | falcon_reset_macs(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1047 | static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1048 | { |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1049 | efx_oword_t reg; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1050 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1051 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1052 | return; |
| 1053 | |
| 1054 | /* Isolate the MAC -> RX */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1055 | efx_reado(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1056 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1057 | efx_writeo(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1058 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1059 | /* Isolate TX -> MAC */ |
| 1060 | falcon_drain_tx_fifo(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
Ben Hutchings | ab0115f | 2012-09-13 01:11:31 +0100 | [diff] [blame] | 1063 | static void falcon_reconfigure_mac_wrapper(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1064 | { |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 1065 | struct efx_link_state *link_state = &efx->link_state; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1066 | efx_oword_t reg; |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 1067 | int link_speed, isolate; |
| 1068 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 1069 | isolate = !!ACCESS_ONCE(efx->reset_pending); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1070 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 1071 | switch (link_state->speed) { |
Ben Hutchings | f31a45d | 2008-12-12 21:43:33 -0800 | [diff] [blame] | 1072 | case 10000: link_speed = 3; break; |
| 1073 | case 1000: link_speed = 2; break; |
| 1074 | case 100: link_speed = 1; break; |
| 1075 | default: link_speed = 0; break; |
| 1076 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1077 | /* MAC_LINK_STATUS controls MAC backpressure but doesn't work |
| 1078 | * as advertised. Disable to ensure packets are not |
| 1079 | * indefinitely held and TX queue can be flushed at any point |
| 1080 | * while the link is down. */ |
| 1081 | EFX_POPULATE_OWORD_5(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1082 | FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */, |
| 1083 | FRF_AB_MAC_BCAD_ACPT, 1, |
| 1084 | FRF_AB_MAC_UC_PROM, efx->promiscuous, |
| 1085 | FRF_AB_MAC_LINK_STATUS, 1, /* always set */ |
| 1086 | FRF_AB_MAC_SPEED, link_speed); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1087 | /* On B0, MAC backpressure can be disabled and packets get |
| 1088 | * discarded. */ |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1089 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) { |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1090 | EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN, |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 1091 | !link_state->up || isolate); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1092 | } |
| 1093 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1094 | efx_writeo(efx, ®, FR_AB_MAC_CTRL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1095 | |
| 1096 | /* Restore the multicast hash registers. */ |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 1097 | falcon_push_multicast_hash(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1098 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1099 | efx_reado(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 4b0d29d | 2009-11-29 03:42:18 +0000 | [diff] [blame] | 1100 | /* Enable XOFF signal from RX FIFO (we enabled it during NIC |
| 1101 | * initialisation but it may read back as 0) */ |
| 1102 | EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1103 | /* Unisolate the MAC -> RX */ |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1104 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 1105 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, !isolate); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1106 | efx_writeo(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1107 | } |
| 1108 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1109 | static void falcon_stats_request(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1110 | { |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1111 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1112 | efx_oword_t reg; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1113 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1114 | WARN_ON(nic_data->stats_pending); |
| 1115 | WARN_ON(nic_data->stats_disable_count); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1116 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1117 | if (nic_data->stats_dma_done == NULL) |
| 1118 | return; /* no mac selected */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1119 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1120 | *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE; |
| 1121 | nic_data->stats_pending = true; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1122 | wmb(); /* ensure done flag is clear */ |
| 1123 | |
| 1124 | /* Initiate DMA transfer of stats */ |
| 1125 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1126 | FRF_AB_MAC_STAT_DMA_CMD, 1, |
| 1127 | FRF_AB_MAC_STAT_DMA_ADR, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1128 | efx->stats_buffer.dma_addr); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1129 | efx_writeo(efx, ®, FR_AB_MAC_STAT_DMA); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1130 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1131 | mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2)); |
| 1132 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1133 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1134 | static void falcon_stats_complete(struct efx_nic *efx) |
| 1135 | { |
| 1136 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1137 | |
| 1138 | if (!nic_data->stats_pending) |
| 1139 | return; |
| 1140 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 1141 | nic_data->stats_pending = false; |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1142 | if (*nic_data->stats_dma_done == FALCON_STATS_DONE) { |
| 1143 | rmb(); /* read the done flag before the stats */ |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1144 | falcon_update_stats_xmac(efx); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1145 | } else { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1146 | netif_err(efx, hw, efx->net_dev, |
| 1147 | "timed out waiting for statistics\n"); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | static void falcon_stats_timer_func(unsigned long context) |
| 1152 | { |
| 1153 | struct efx_nic *efx = (struct efx_nic *)context; |
| 1154 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1155 | |
| 1156 | spin_lock(&efx->stats_lock); |
| 1157 | |
| 1158 | falcon_stats_complete(efx); |
| 1159 | if (nic_data->stats_disable_count == 0) |
| 1160 | falcon_stats_request(efx); |
| 1161 | |
| 1162 | spin_unlock(&efx->stats_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1163 | } |
| 1164 | |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1165 | static bool falcon_loopback_link_poll(struct efx_nic *efx) |
| 1166 | { |
| 1167 | struct efx_link_state old_state = efx->link_state; |
| 1168 | |
| 1169 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
| 1170 | WARN_ON(!LOOPBACK_INTERNAL(efx)); |
| 1171 | |
| 1172 | efx->link_state.fd = true; |
| 1173 | efx->link_state.fc = efx->wanted_fc; |
| 1174 | efx->link_state.up = true; |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1175 | efx->link_state.speed = 10000; |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1176 | |
| 1177 | return !efx_link_state_equal(&efx->link_state, &old_state); |
| 1178 | } |
| 1179 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1180 | static int falcon_reconfigure_port(struct efx_nic *efx) |
| 1181 | { |
| 1182 | int rc; |
| 1183 | |
| 1184 | WARN_ON(efx_nic_rev(efx) > EFX_REV_FALCON_B0); |
| 1185 | |
| 1186 | /* Poll the PHY link state *before* reconfiguring it. This means we |
| 1187 | * will pick up the correct speed (in loopback) to select the correct |
| 1188 | * MAC. |
| 1189 | */ |
| 1190 | if (LOOPBACK_INTERNAL(efx)) |
| 1191 | falcon_loopback_link_poll(efx); |
| 1192 | else |
| 1193 | efx->phy_op->poll(efx); |
| 1194 | |
| 1195 | falcon_stop_nic_stats(efx); |
| 1196 | falcon_deconfigure_mac_wrapper(efx); |
| 1197 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1198 | falcon_reset_macs(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1199 | |
| 1200 | efx->phy_op->reconfigure(efx); |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1201 | rc = falcon_reconfigure_xmac(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1202 | BUG_ON(rc); |
| 1203 | |
| 1204 | falcon_start_nic_stats(efx); |
| 1205 | |
| 1206 | /* Synchronise efx->link_state with the kernel */ |
| 1207 | efx_link_status_changed(efx); |
| 1208 | |
| 1209 | return 0; |
| 1210 | } |
| 1211 | |
Ben Hutchings | 9dd3a13 | 2012-09-13 01:11:25 +0100 | [diff] [blame] | 1212 | /* TX flow control may automatically turn itself off if the link |
| 1213 | * partner (intermittently) stops responding to pause frames. There |
| 1214 | * isn't any indication that this has happened, so the best we do is |
| 1215 | * leave it up to the user to spot this and fix it by cycling transmit |
| 1216 | * flow control on this end. |
| 1217 | */ |
| 1218 | |
| 1219 | static void falcon_a1_prepare_enable_fc_tx(struct efx_nic *efx) |
| 1220 | { |
| 1221 | /* Schedule a reset to recover */ |
| 1222 | efx_schedule_reset(efx, RESET_TYPE_INVISIBLE); |
| 1223 | } |
| 1224 | |
| 1225 | static void falcon_b0_prepare_enable_fc_tx(struct efx_nic *efx) |
| 1226 | { |
| 1227 | /* Recover by resetting the EM block */ |
| 1228 | falcon_stop_nic_stats(efx); |
| 1229 | falcon_drain_tx_fifo(efx); |
| 1230 | falcon_reconfigure_xmac(efx); |
| 1231 | falcon_start_nic_stats(efx); |
| 1232 | } |
| 1233 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1234 | /************************************************************************** |
| 1235 | * |
| 1236 | * PHY access via GMII |
| 1237 | * |
| 1238 | ************************************************************************** |
| 1239 | */ |
| 1240 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1241 | /* Wait for GMII access to complete */ |
| 1242 | static int falcon_gmii_wait(struct efx_nic *efx) |
| 1243 | { |
Ben Hutchings | 80cb9a0 | 2009-11-25 16:08:41 +0000 | [diff] [blame] | 1244 | efx_oword_t md_stat; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1245 | int count; |
| 1246 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1247 | /* wait up to 50ms - taken max from datasheet */ |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1248 | for (count = 0; count < 5000; count++) { |
Ben Hutchings | 80cb9a0 | 2009-11-25 16:08:41 +0000 | [diff] [blame] | 1249 | efx_reado(efx, &md_stat, FR_AB_MD_STAT); |
| 1250 | if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) { |
| 1251 | if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 || |
| 1252 | EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1253 | netif_err(efx, hw, efx->net_dev, |
| 1254 | "error from GMII access " |
| 1255 | EFX_OWORD_FMT"\n", |
| 1256 | EFX_OWORD_VAL(md_stat)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1257 | return -EIO; |
| 1258 | } |
| 1259 | return 0; |
| 1260 | } |
| 1261 | udelay(10); |
| 1262 | } |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1263 | 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] | 1264 | return -ETIMEDOUT; |
| 1265 | } |
| 1266 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1267 | /* Write an MDIO register of a PHY connected to Falcon. */ |
| 1268 | static int falcon_mdio_write(struct net_device *net_dev, |
| 1269 | int prtad, int devad, u16 addr, u16 value) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1270 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1271 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1272 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1273 | efx_oword_t reg; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1274 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1275 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1276 | netif_vdbg(efx, hw, efx->net_dev, |
| 1277 | "writing MDIO %d register %d.%d with 0x%04x\n", |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1278 | prtad, devad, addr, value); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1279 | |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1280 | mutex_lock(&nic_data->mdio_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1281 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1282 | /* Check MDIO not currently being accessed */ |
| 1283 | rc = falcon_gmii_wait(efx); |
| 1284 | if (rc) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1285 | goto out; |
| 1286 | |
| 1287 | /* Write the address/ID register */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1288 | EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1289 | efx_writeo(efx, ®, FR_AB_MD_PHY_ADR); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1290 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1291 | EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad, |
| 1292 | FRF_AB_MD_DEV_ADR, devad); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1293 | efx_writeo(efx, ®, FR_AB_MD_ID); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1294 | |
| 1295 | /* Write data */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1296 | EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1297 | efx_writeo(efx, ®, FR_AB_MD_TXD); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1298 | |
| 1299 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1300 | FRF_AB_MD_WRC, 1, |
| 1301 | FRF_AB_MD_GC, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1302 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1303 | |
| 1304 | /* Wait for data to be written */ |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1305 | rc = falcon_gmii_wait(efx); |
| 1306 | if (rc) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1307 | /* Abort the write operation */ |
| 1308 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1309 | FRF_AB_MD_WRC, 0, |
| 1310 | FRF_AB_MD_GC, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1311 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1312 | udelay(10); |
| 1313 | } |
| 1314 | |
Steve Hodgson | ab86746 | 2009-11-28 05:34:44 +0000 | [diff] [blame] | 1315 | out: |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1316 | mutex_unlock(&nic_data->mdio_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1317 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1318 | } |
| 1319 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1320 | /* Read an MDIO register of a PHY connected to Falcon. */ |
| 1321 | static int falcon_mdio_read(struct net_device *net_dev, |
| 1322 | int prtad, int devad, u16 addr) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1323 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 1324 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1325 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1326 | efx_oword_t reg; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1327 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1328 | |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1329 | mutex_lock(&nic_data->mdio_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1330 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1331 | /* Check MDIO not currently being accessed */ |
| 1332 | rc = falcon_gmii_wait(efx); |
| 1333 | if (rc) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1334 | goto out; |
| 1335 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1336 | EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1337 | efx_writeo(efx, ®, FR_AB_MD_PHY_ADR); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1338 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1339 | EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad, |
| 1340 | FRF_AB_MD_DEV_ADR, devad); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1341 | efx_writeo(efx, ®, FR_AB_MD_ID); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1342 | |
| 1343 | /* Request data to be read */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1344 | 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] | 1345 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1346 | |
| 1347 | /* Wait for data to become available */ |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1348 | rc = falcon_gmii_wait(efx); |
| 1349 | if (rc == 0) { |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1350 | efx_reado(efx, ®, FR_AB_MD_RXD); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1351 | rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1352 | netif_vdbg(efx, hw, efx->net_dev, |
| 1353 | "read from MDIO %d register %d.%d, got %04x\n", |
| 1354 | prtad, devad, addr, rc); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1355 | } else { |
| 1356 | /* Abort the read operation */ |
| 1357 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1358 | FRF_AB_MD_RIC, 0, |
| 1359 | FRF_AB_MD_GC, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1360 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1361 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1362 | netif_dbg(efx, hw, efx->net_dev, |
| 1363 | "read from MDIO %d register %d.%d, got error %d\n", |
| 1364 | prtad, devad, addr, rc); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1365 | } |
| 1366 | |
Steve Hodgson | ab86746 | 2009-11-28 05:34:44 +0000 | [diff] [blame] | 1367 | out: |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1368 | mutex_unlock(&nic_data->mdio_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1369 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1370 | } |
| 1371 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1372 | /* This call is responsible for hooking in the MAC and PHY operations */ |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1373 | static int falcon_probe_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1374 | { |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1375 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1376 | int rc; |
| 1377 | |
Ben Hutchings | 96c45726 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 1378 | switch (efx->phy_type) { |
| 1379 | case PHY_TYPE_SFX7101: |
| 1380 | efx->phy_op = &falcon_sfx7101_phy_ops; |
| 1381 | break; |
Ben Hutchings | 96c45726 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 1382 | case PHY_TYPE_QT2022C2: |
| 1383 | case PHY_TYPE_QT2025C: |
Ben Hutchings | b37b62f | 2009-10-23 08:33:42 +0000 | [diff] [blame] | 1384 | efx->phy_op = &falcon_qt202x_phy_ops; |
Ben Hutchings | 96c45726 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 1385 | break; |
Ben Hutchings | 7e51b43 | 2010-09-22 10:00:47 +0000 | [diff] [blame] | 1386 | case PHY_TYPE_TXC43128: |
| 1387 | efx->phy_op = &falcon_txc_phy_ops; |
| 1388 | break; |
Ben Hutchings | 96c45726 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 1389 | default: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1390 | netif_err(efx, probe, efx->net_dev, "Unknown PHY type %d\n", |
| 1391 | efx->phy_type); |
Ben Hutchings | 96c45726 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 1392 | return -ENODEV; |
| 1393 | } |
| 1394 | |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 1395 | /* Fill out MDIO structure and loopback modes */ |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 1396 | mutex_init(&nic_data->mdio_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 1397 | efx->mdio.mdio_read = falcon_mdio_read; |
| 1398 | efx->mdio.mdio_write = falcon_mdio_write; |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 1399 | rc = efx->phy_op->probe(efx); |
| 1400 | if (rc != 0) |
| 1401 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1402 | |
Steve Hodgson | b895d73 | 2009-11-28 05:35:00 +0000 | [diff] [blame] | 1403 | /* Initial assumption */ |
| 1404 | efx->link_state.speed = 10000; |
| 1405 | efx->link_state.fd = true; |
| 1406 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1407 | /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */ |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1408 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 1409 | efx->wanted_fc = EFX_FC_RX | EFX_FC_TX; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1410 | else |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 1411 | efx->wanted_fc = EFX_FC_RX; |
Steve Hodgson | 7a6b8f6 | 2010-02-03 09:30:38 +0000 | [diff] [blame] | 1412 | if (efx->mdio.mmds & MDIO_DEVS_AN) |
| 1413 | efx->wanted_fc |= EFX_FC_AUTO; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1414 | |
| 1415 | /* Allocate buffer for stats */ |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1416 | rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer, |
Ben Hutchings | 0d19a54 | 2012-09-18 21:59:52 +0100 | [diff] [blame] | 1417 | FALCON_MAC_STATS_SIZE, GFP_KERNEL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1418 | if (rc) |
| 1419 | return rc; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1420 | netif_dbg(efx, probe, efx->net_dev, |
| 1421 | "stats buffer at %llx (virt %p phys %llx)\n", |
| 1422 | (u64)efx->stats_buffer.dma_addr, |
| 1423 | efx->stats_buffer.addr, |
| 1424 | (u64)virt_to_phys(efx->stats_buffer.addr)); |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1425 | nic_data->stats_dma_done = efx->stats_buffer.addr + XgDmaDone_offset; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1426 | |
| 1427 | return 0; |
| 1428 | } |
| 1429 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1430 | static void falcon_remove_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1431 | { |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 1432 | efx->phy_op->remove(efx); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1433 | efx_nic_free_buffer(efx, &efx->stats_buffer); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1434 | } |
| 1435 | |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 1436 | /* Global events are basically PHY events */ |
| 1437 | static bool |
| 1438 | falcon_handle_global_event(struct efx_channel *channel, efx_qword_t *event) |
| 1439 | { |
| 1440 | struct efx_nic *efx = channel->efx; |
Ben Hutchings | cef68bd | 2010-12-02 13:47:51 +0000 | [diff] [blame] | 1441 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 1442 | |
| 1443 | if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) || |
| 1444 | EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) || |
| 1445 | EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR)) |
| 1446 | /* Ignored */ |
| 1447 | return true; |
| 1448 | |
| 1449 | if ((efx_nic_rev(efx) == EFX_REV_FALCON_B0) && |
| 1450 | EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) { |
Ben Hutchings | cef68bd | 2010-12-02 13:47:51 +0000 | [diff] [blame] | 1451 | nic_data->xmac_poll_required = true; |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 1452 | return true; |
| 1453 | } |
| 1454 | |
| 1455 | if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ? |
| 1456 | EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) : |
| 1457 | EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) { |
| 1458 | netif_err(efx, rx_err, efx->net_dev, |
| 1459 | "channel %d seen global RX_RESET event. Resetting.\n", |
| 1460 | channel->channel); |
| 1461 | |
| 1462 | atomic_inc(&efx->rx_reset); |
| 1463 | efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ? |
| 1464 | RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE); |
| 1465 | return true; |
| 1466 | } |
| 1467 | |
| 1468 | return false; |
| 1469 | } |
| 1470 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1471 | /************************************************************************** |
| 1472 | * |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1473 | * Falcon test code |
| 1474 | * |
| 1475 | **************************************************************************/ |
| 1476 | |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 1477 | static int |
| 1478 | falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out) |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1479 | { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1480 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1481 | struct falcon_nvconfig *nvconfig; |
| 1482 | struct efx_spi_device *spi; |
| 1483 | void *region; |
| 1484 | int rc, magic_num, struct_ver; |
| 1485 | __le16 *word, *limit; |
| 1486 | u32 csum; |
| 1487 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1488 | if (efx_spi_present(&nic_data->spi_flash)) |
| 1489 | spi = &nic_data->spi_flash; |
| 1490 | else if (efx_spi_present(&nic_data->spi_eeprom)) |
| 1491 | spi = &nic_data->spi_eeprom; |
| 1492 | else |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1493 | return -EINVAL; |
| 1494 | |
Ben Hutchings | 0a95f56 | 2008-11-04 20:33:11 +0000 | [diff] [blame] | 1495 | region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1496 | if (!region) |
| 1497 | return -ENOMEM; |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1498 | nvconfig = region + FALCON_NVCONFIG_OFFSET; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1499 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1500 | mutex_lock(&nic_data->spi_lock); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 1501 | rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region); |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1502 | mutex_unlock(&nic_data->spi_lock); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1503 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1504 | netif_err(efx, hw, efx->net_dev, "Failed to read %s\n", |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1505 | efx_spi_present(&nic_data->spi_flash) ? |
| 1506 | "flash" : "EEPROM"); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1507 | rc = -EIO; |
| 1508 | goto out; |
| 1509 | } |
| 1510 | |
| 1511 | magic_num = le16_to_cpu(nvconfig->board_magic_num); |
| 1512 | struct_ver = le16_to_cpu(nvconfig->board_struct_ver); |
| 1513 | |
| 1514 | rc = -EINVAL; |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1515 | if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1516 | netif_err(efx, hw, efx->net_dev, |
| 1517 | "NVRAM bad magic 0x%x\n", magic_num); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1518 | goto out; |
| 1519 | } |
| 1520 | if (struct_ver < 2) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1521 | netif_err(efx, hw, efx->net_dev, |
| 1522 | "NVRAM has ancient version 0x%x\n", struct_ver); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1523 | goto out; |
| 1524 | } else if (struct_ver < 4) { |
| 1525 | word = &nvconfig->board_magic_num; |
| 1526 | limit = (__le16 *) (nvconfig + 1); |
| 1527 | } else { |
| 1528 | word = region; |
Ben Hutchings | 0a95f56 | 2008-11-04 20:33:11 +0000 | [diff] [blame] | 1529 | limit = region + FALCON_NVCONFIG_END; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1530 | } |
| 1531 | for (csum = 0; word < limit; ++word) |
| 1532 | csum += le16_to_cpu(*word); |
| 1533 | |
| 1534 | if (~csum & 0xffff) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1535 | netif_err(efx, hw, efx->net_dev, |
| 1536 | "NVRAM has incorrect checksum\n"); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1537 | goto out; |
| 1538 | } |
| 1539 | |
| 1540 | rc = 0; |
| 1541 | if (nvconfig_out) |
| 1542 | memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig)); |
| 1543 | |
| 1544 | out: |
| 1545 | kfree(region); |
| 1546 | return rc; |
| 1547 | } |
| 1548 | |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 1549 | static int falcon_test_nvram(struct efx_nic *efx) |
| 1550 | { |
| 1551 | return falcon_read_nvram(efx, NULL); |
| 1552 | } |
| 1553 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 1554 | static const struct efx_farch_register_test falcon_b0_register_tests[] = { |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1555 | { FR_AZ_ADR_REGION, |
Steve Hodgson | 4cddca5 | 2010-02-03 09:31:40 +0000 | [diff] [blame] | 1556 | EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1557 | { FR_AZ_RX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1558 | EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1559 | { FR_AZ_TX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1560 | EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1561 | { FR_AZ_TX_RESERVED, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1562 | EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1563 | { FR_AB_MAC_CTRL, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1564 | EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1565 | { FR_AZ_SRM_TX_DC_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1566 | EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1567 | { FR_AZ_RX_DC_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1568 | EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1569 | { FR_AZ_RX_DC_PF_WM, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1570 | EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1571 | { FR_BZ_DP_CTRL, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1572 | EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1573 | { FR_AB_GM_CFG2, |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1574 | EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1575 | { FR_AB_GMF_CFG0, |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1576 | EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1577 | { FR_AB_XM_GLB_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1578 | EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1579 | { FR_AB_XM_TX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1580 | EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1581 | { FR_AB_XM_RX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1582 | EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1583 | { FR_AB_XM_RX_PARAM, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1584 | EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1585 | { FR_AB_XM_FC, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1586 | EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1587 | { FR_AB_XM_ADR_LO, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1588 | EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1589 | { FR_AB_XX_SD_CTL, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1590 | EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) }, |
| 1591 | }; |
| 1592 | |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 1593 | static int |
| 1594 | 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] | 1595 | { |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 1596 | enum reset_type reset_method = RESET_TYPE_INVISIBLE; |
| 1597 | int rc, rc2; |
| 1598 | |
| 1599 | mutex_lock(&efx->mac_lock); |
| 1600 | if (efx->loopback_modes) { |
| 1601 | /* We need the 312 clock from the PHY to test the XMAC |
| 1602 | * registers, so move into XGMII loopback if available */ |
| 1603 | if (efx->loopback_modes & (1 << LOOPBACK_XGMII)) |
| 1604 | efx->loopback_mode = LOOPBACK_XGMII; |
| 1605 | else |
| 1606 | efx->loopback_mode = __ffs(efx->loopback_modes); |
| 1607 | } |
| 1608 | __efx_reconfigure_port(efx); |
| 1609 | mutex_unlock(&efx->mac_lock); |
| 1610 | |
| 1611 | efx_reset_down(efx, reset_method); |
| 1612 | |
| 1613 | tests->registers = |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 1614 | efx_farch_test_registers(efx, falcon_b0_register_tests, |
| 1615 | ARRAY_SIZE(falcon_b0_register_tests)) |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 1616 | ? -1 : 1; |
| 1617 | |
| 1618 | rc = falcon_reset_hw(efx, reset_method); |
| 1619 | rc2 = efx_reset_up(efx, reset_method, rc == 0); |
| 1620 | return rc ? rc : rc2; |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1623 | /************************************************************************** |
| 1624 | * |
| 1625 | * Device reset |
| 1626 | * |
| 1627 | ************************************************************************** |
| 1628 | */ |
| 1629 | |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 1630 | static enum reset_type falcon_map_reset_reason(enum reset_type reason) |
| 1631 | { |
| 1632 | switch (reason) { |
| 1633 | case RESET_TYPE_RX_RECOVERY: |
| 1634 | case RESET_TYPE_RX_DESC_FETCH: |
| 1635 | case RESET_TYPE_TX_DESC_FETCH: |
| 1636 | case RESET_TYPE_TX_SKIP: |
| 1637 | /* These can occasionally occur due to hardware bugs. |
| 1638 | * We try to reset without disrupting the link. |
| 1639 | */ |
| 1640 | return RESET_TYPE_INVISIBLE; |
| 1641 | default: |
| 1642 | return RESET_TYPE_ALL; |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | static int falcon_map_reset_flags(u32 *flags) |
| 1647 | { |
| 1648 | enum { |
| 1649 | FALCON_RESET_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER | |
| 1650 | ETH_RESET_OFFLOAD | ETH_RESET_MAC), |
| 1651 | FALCON_RESET_ALL = FALCON_RESET_INVISIBLE | ETH_RESET_PHY, |
| 1652 | FALCON_RESET_WORLD = FALCON_RESET_ALL | ETH_RESET_IRQ, |
| 1653 | }; |
| 1654 | |
| 1655 | if ((*flags & FALCON_RESET_WORLD) == FALCON_RESET_WORLD) { |
| 1656 | *flags &= ~FALCON_RESET_WORLD; |
| 1657 | return RESET_TYPE_WORLD; |
| 1658 | } |
| 1659 | |
| 1660 | if ((*flags & FALCON_RESET_ALL) == FALCON_RESET_ALL) { |
| 1661 | *flags &= ~FALCON_RESET_ALL; |
| 1662 | return RESET_TYPE_ALL; |
| 1663 | } |
| 1664 | |
| 1665 | if ((*flags & FALCON_RESET_INVISIBLE) == FALCON_RESET_INVISIBLE) { |
| 1666 | *flags &= ~FALCON_RESET_INVISIBLE; |
| 1667 | return RESET_TYPE_INVISIBLE; |
| 1668 | } |
| 1669 | |
| 1670 | return -EINVAL; |
| 1671 | } |
| 1672 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1673 | /* Resets NIC to known state. This routine must be called in process |
| 1674 | * context and is allowed to sleep. */ |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1675 | 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] | 1676 | { |
| 1677 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1678 | efx_oword_t glb_ctl_reg_ker; |
| 1679 | int rc; |
| 1680 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1681 | netif_dbg(efx, hw, efx->net_dev, "performing %s hardware reset\n", |
| 1682 | RESET_TYPE(method)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1683 | |
| 1684 | /* Initiate device reset */ |
| 1685 | if (method == RESET_TYPE_WORLD) { |
| 1686 | rc = pci_save_state(efx->pci_dev); |
| 1687 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1688 | netif_err(efx, drv, efx->net_dev, |
| 1689 | "failed to backup PCI state of primary " |
| 1690 | "function prior to hardware reset\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1691 | goto fail1; |
| 1692 | } |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1693 | if (efx_nic_is_dual_func(efx)) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1694 | rc = pci_save_state(nic_data->pci_dev2); |
| 1695 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1696 | netif_err(efx, drv, efx->net_dev, |
| 1697 | "failed to backup PCI state of " |
| 1698 | "secondary function prior to " |
| 1699 | "hardware reset\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1700 | goto fail2; |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | EFX_POPULATE_OWORD_2(glb_ctl_reg_ker, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1705 | FRF_AB_EXT_PHY_RST_DUR, |
| 1706 | FFE_AB_EXT_PHY_RST_DUR_10240US, |
| 1707 | FRF_AB_SWRST, 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1708 | } else { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1709 | EFX_POPULATE_OWORD_7(glb_ctl_reg_ker, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1710 | /* exclude PHY from "invisible" reset */ |
| 1711 | FRF_AB_EXT_PHY_RST_CTL, |
| 1712 | method == RESET_TYPE_INVISIBLE, |
| 1713 | /* exclude EEPROM/flash and PCIe */ |
| 1714 | FRF_AB_PCIE_CORE_RST_CTL, 1, |
| 1715 | FRF_AB_PCIE_NSTKY_RST_CTL, 1, |
| 1716 | FRF_AB_PCIE_SD_RST_CTL, 1, |
| 1717 | FRF_AB_EE_RST_CTL, 1, |
| 1718 | FRF_AB_EXT_PHY_RST_DUR, |
| 1719 | FFE_AB_EXT_PHY_RST_DUR_10240US, |
| 1720 | FRF_AB_SWRST, 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1721 | } |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1722 | efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1723 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1724 | netif_dbg(efx, hw, efx->net_dev, "waiting for hardware reset\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1725 | schedule_timeout_uninterruptible(HZ / 20); |
| 1726 | |
| 1727 | /* Restore PCI configuration if needed */ |
| 1728 | if (method == RESET_TYPE_WORLD) { |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 1729 | if (efx_nic_is_dual_func(efx)) |
| 1730 | pci_restore_state(nic_data->pci_dev2); |
| 1731 | pci_restore_state(efx->pci_dev); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1732 | netif_dbg(efx, drv, efx->net_dev, |
| 1733 | "successfully restored PCI config\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | /* Assert that reset complete */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1737 | efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1738 | if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1739 | rc = -ETIMEDOUT; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1740 | netif_err(efx, hw, efx->net_dev, |
| 1741 | "timed out waiting for hardware reset\n"); |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 1742 | goto fail3; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1743 | } |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1744 | netif_dbg(efx, hw, efx->net_dev, "hardware reset complete\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1745 | |
| 1746 | return 0; |
| 1747 | |
| 1748 | /* pci_save_state() and pci_restore_state() MUST be called in pairs */ |
| 1749 | fail2: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1750 | pci_restore_state(efx->pci_dev); |
| 1751 | fail1: |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 1752 | fail3: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1753 | return rc; |
| 1754 | } |
| 1755 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1756 | static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method) |
| 1757 | { |
| 1758 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1759 | int rc; |
| 1760 | |
| 1761 | mutex_lock(&nic_data->spi_lock); |
| 1762 | rc = __falcon_reset_hw(efx, method); |
| 1763 | mutex_unlock(&nic_data->spi_lock); |
| 1764 | |
| 1765 | return rc; |
| 1766 | } |
| 1767 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1768 | static void falcon_monitor(struct efx_nic *efx) |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1769 | { |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1770 | bool link_changed; |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1771 | int rc; |
| 1772 | |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1773 | BUG_ON(!mutex_is_locked(&efx->mac_lock)); |
| 1774 | |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1775 | rc = falcon_board(efx)->type->monitor(efx); |
| 1776 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1777 | netif_err(efx, hw, efx->net_dev, |
| 1778 | "Board sensor %s; shutting down PHY\n", |
| 1779 | (rc == -ERANGE) ? "reported fault" : "failed"); |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1780 | efx->phy_mode |= PHY_MODE_LOW_POWER; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1781 | rc = __efx_reconfigure_port(efx); |
| 1782 | WARN_ON(rc); |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1783 | } |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1784 | |
| 1785 | if (LOOPBACK_INTERNAL(efx)) |
| 1786 | link_changed = falcon_loopback_link_poll(efx); |
| 1787 | else |
| 1788 | link_changed = efx->phy_op->poll(efx); |
| 1789 | |
| 1790 | if (link_changed) { |
| 1791 | falcon_stop_nic_stats(efx); |
| 1792 | falcon_deconfigure_mac_wrapper(efx); |
| 1793 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1794 | falcon_reset_macs(efx); |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1795 | rc = falcon_reconfigure_xmac(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1796 | BUG_ON(rc); |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1797 | |
| 1798 | falcon_start_nic_stats(efx); |
| 1799 | |
| 1800 | efx_link_status_changed(efx); |
| 1801 | } |
| 1802 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1803 | falcon_poll_xmac(efx); |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1806 | /* Zeroes out the SRAM contents. This routine must be called in |
| 1807 | * process context and is allowed to sleep. |
| 1808 | */ |
| 1809 | static int falcon_reset_sram(struct efx_nic *efx) |
| 1810 | { |
| 1811 | efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker; |
| 1812 | int count; |
| 1813 | |
| 1814 | /* Set the SRAM wake/sleep GPIO appropriately. */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1815 | efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1816 | EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1); |
| 1817 | 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] | 1818 | efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1819 | |
| 1820 | /* Initiate SRAM reset */ |
| 1821 | EFX_POPULATE_OWORD_2(srm_cfg_reg_ker, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1822 | FRF_AZ_SRM_INIT_EN, 1, |
| 1823 | FRF_AZ_SRM_NB_SZ, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1824 | efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1825 | |
| 1826 | /* Wait for SRAM reset to complete */ |
| 1827 | count = 0; |
| 1828 | do { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1829 | netif_dbg(efx, hw, efx->net_dev, |
| 1830 | "waiting for SRAM reset (attempt %d)...\n", count); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1831 | |
| 1832 | /* SRAM reset is slow; expect around 16ms */ |
| 1833 | schedule_timeout_uninterruptible(HZ / 50); |
| 1834 | |
| 1835 | /* Check for reset complete */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1836 | efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1837 | 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] | 1838 | netif_dbg(efx, hw, efx->net_dev, |
| 1839 | "SRAM reset complete\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1840 | |
| 1841 | return 0; |
| 1842 | } |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1843 | } while (++count < 20); /* wait up to 0.4 sec */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1844 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1845 | 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] | 1846 | return -ETIMEDOUT; |
| 1847 | } |
| 1848 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1849 | static void falcon_spi_device_init(struct efx_nic *efx, |
| 1850 | struct efx_spi_device *spi_device, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1851 | unsigned int device_id, u32 device_type) |
| 1852 | { |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1853 | if (device_type != 0) { |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1854 | spi_device->device_id = device_id; |
| 1855 | spi_device->size = |
| 1856 | 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE); |
| 1857 | spi_device->addr_len = |
| 1858 | SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN); |
| 1859 | spi_device->munge_address = (spi_device->size == 1 << 9 && |
| 1860 | spi_device->addr_len == 1); |
Ben Hutchings | f415072 | 2008-11-04 20:34:28 +0000 | [diff] [blame] | 1861 | spi_device->erase_command = |
| 1862 | SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD); |
| 1863 | spi_device->erase_size = |
| 1864 | 1 << SPI_DEV_TYPE_FIELD(device_type, |
| 1865 | SPI_DEV_TYPE_ERASE_SIZE); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1866 | spi_device->block_size = |
| 1867 | 1 << SPI_DEV_TYPE_FIELD(device_type, |
| 1868 | SPI_DEV_TYPE_BLOCK_SIZE); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1869 | } else { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1870 | spi_device->size = 0; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1871 | } |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1872 | } |
| 1873 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1874 | /* Extract non-volatile configuration */ |
| 1875 | static int falcon_probe_nvconfig(struct efx_nic *efx) |
| 1876 | { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1877 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1878 | struct falcon_nvconfig *nvconfig; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1879 | int rc; |
| 1880 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1881 | nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1882 | if (!nvconfig) |
| 1883 | return -ENOMEM; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1884 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1885 | rc = falcon_read_nvram(efx, nvconfig); |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1886 | if (rc) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1887 | goto out; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1888 | |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1889 | efx->phy_type = nvconfig->board_v2.port0_phy_type; |
| 1890 | efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1891 | |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1892 | if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1893 | falcon_spi_device_init( |
| 1894 | efx, &nic_data->spi_flash, FFE_AB_SPI_DEVICE_FLASH, |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1895 | le32_to_cpu(nvconfig->board_v3 |
| 1896 | .spi_device_type[FFE_AB_SPI_DEVICE_FLASH])); |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1897 | falcon_spi_device_init( |
| 1898 | efx, &nic_data->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM, |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1899 | le32_to_cpu(nvconfig->board_v3 |
| 1900 | .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM])); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1901 | } |
| 1902 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1903 | /* Read the MAC addresses */ |
Ben Hutchings | 7e300bc | 2010-12-02 13:48:28 +0000 | [diff] [blame] | 1904 | memcpy(efx->net_dev->perm_addr, nvconfig->mac_address[0], ETH_ALEN); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1905 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1906 | netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n", |
| 1907 | efx->phy_type, efx->mdio.prtad); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1908 | |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1909 | rc = falcon_probe_board(efx, |
| 1910 | le16_to_cpu(nvconfig->board_v2.board_revision)); |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1911 | out: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1912 | kfree(nvconfig); |
| 1913 | return rc; |
| 1914 | } |
| 1915 | |
Ben Hutchings | 28e47c4 | 2012-02-15 01:58:49 +0000 | [diff] [blame] | 1916 | static void falcon_dimension_resources(struct efx_nic *efx) |
| 1917 | { |
| 1918 | efx->rx_dc_base = 0x20000; |
| 1919 | efx->tx_dc_base = 0x26000; |
| 1920 | } |
| 1921 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1922 | /* Probe all SPI devices on the NIC */ |
| 1923 | static void falcon_probe_spi_devices(struct efx_nic *efx) |
| 1924 | { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1925 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1926 | efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg; |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1927 | int boot_dev; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1928 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1929 | efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL); |
| 1930 | efx_reado(efx, &nic_stat, FR_AB_NIC_STAT); |
| 1931 | efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1932 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1933 | if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) { |
| 1934 | boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ? |
| 1935 | FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1936 | netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n", |
| 1937 | boot_dev == FFE_AB_SPI_DEVICE_FLASH ? |
| 1938 | "flash" : "EEPROM"); |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1939 | } else { |
| 1940 | /* Disable VPD and set clock dividers to safe |
| 1941 | * values for initial programming. */ |
| 1942 | boot_dev = -1; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1943 | netif_dbg(efx, probe, efx->net_dev, |
| 1944 | "Booted from internal ASIC settings;" |
| 1945 | " setting SPI config\n"); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1946 | 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] | 1947 | /* 125 MHz / 7 ~= 20 MHz */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1948 | FRF_AB_EE_SF_CLOCK_DIV, 7, |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1949 | /* 125 MHz / 63 ~= 2 MHz */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1950 | FRF_AB_EE_EE_CLOCK_DIV, 63); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1951 | efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1952 | } |
| 1953 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1954 | mutex_init(&nic_data->spi_lock); |
| 1955 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1956 | if (boot_dev == FFE_AB_SPI_DEVICE_FLASH) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1957 | falcon_spi_device_init(efx, &nic_data->spi_flash, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1958 | FFE_AB_SPI_DEVICE_FLASH, |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1959 | default_flash_type); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1960 | if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1961 | falcon_spi_device_init(efx, &nic_data->spi_eeprom, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1962 | FFE_AB_SPI_DEVICE_EEPROM, |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1963 | large_eeprom_type); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1964 | } |
| 1965 | |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 1966 | static unsigned int falcon_a1_mem_map_size(struct efx_nic *efx) |
| 1967 | { |
| 1968 | return 0x20000; |
| 1969 | } |
| 1970 | |
| 1971 | static unsigned int falcon_b0_mem_map_size(struct efx_nic *efx) |
| 1972 | { |
| 1973 | /* Map everything up to and including the RSS indirection table. |
| 1974 | * The PCI core takes care of mapping the MSI-X tables. |
| 1975 | */ |
| 1976 | return FR_BZ_RX_INDIRECTION_TBL + |
| 1977 | FR_BZ_RX_INDIRECTION_TBL_STEP * FR_BZ_RX_INDIRECTION_TBL_ROWS; |
| 1978 | } |
| 1979 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1980 | static int falcon_probe_nic(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1981 | { |
| 1982 | struct falcon_nic_data *nic_data; |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 1983 | struct falcon_board *board; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1984 | int rc; |
| 1985 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1986 | /* Allocate storage for hardware specific data */ |
| 1987 | nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); |
Ben Hutchings | 88c5942 | 2008-09-03 15:07:50 +0100 | [diff] [blame] | 1988 | if (!nic_data) |
| 1989 | return -ENOMEM; |
Ben Hutchings | 5daab96 | 2008-05-16 21:19:43 +0100 | [diff] [blame] | 1990 | efx->nic_data = nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1991 | |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 1992 | rc = -ENODEV; |
| 1993 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 1994 | if (efx_farch_fpga_ver(efx) != 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1995 | netif_err(efx, probe, efx->net_dev, |
| 1996 | "Falcon FPGA not supported\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1997 | goto fail1; |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 1998 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1999 | |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2000 | if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) { |
| 2001 | efx_oword_t nic_stat; |
| 2002 | struct pci_dev *dev; |
| 2003 | u8 pci_rev = efx->pci_dev->revision; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2004 | |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2005 | if ((pci_rev == 0xff) || (pci_rev == 0)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2006 | netif_err(efx, probe, efx->net_dev, |
| 2007 | "Falcon rev A0 not supported\n"); |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2008 | goto fail1; |
| 2009 | } |
| 2010 | efx_reado(efx, &nic_stat, FR_AB_NIC_STAT); |
| 2011 | if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2012 | netif_err(efx, probe, efx->net_dev, |
| 2013 | "Falcon rev A1 1G not supported\n"); |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2014 | goto fail1; |
| 2015 | } |
| 2016 | if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2017 | netif_err(efx, probe, efx->net_dev, |
| 2018 | "Falcon rev A1 PCI-X not supported\n"); |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 2019 | goto fail1; |
| 2020 | } |
| 2021 | |
| 2022 | dev = pci_dev_get(efx->pci_dev); |
Linus Torvalds | 0e59e7e7 | 2011-10-28 14:20:44 -0700 | [diff] [blame] | 2023 | while ((dev = pci_get_device(PCI_VENDOR_ID_SOLARFLARE, |
| 2024 | PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2025 | dev))) { |
| 2026 | if (dev->bus == efx->pci_dev->bus && |
| 2027 | dev->devfn == efx->pci_dev->devfn + 1) { |
| 2028 | nic_data->pci_dev2 = dev; |
| 2029 | break; |
| 2030 | } |
| 2031 | } |
| 2032 | if (!nic_data->pci_dev2) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2033 | netif_err(efx, probe, efx->net_dev, |
| 2034 | "failed to find secondary function\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2035 | rc = -ENODEV; |
| 2036 | goto fail2; |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | /* Now we can reset the NIC */ |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 2041 | rc = __falcon_reset_hw(efx, RESET_TYPE_ALL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2042 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2043 | netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2044 | goto fail3; |
| 2045 | } |
| 2046 | |
| 2047 | /* Allocate memory for INT_KER */ |
Ben Hutchings | 0d19a54 | 2012-09-18 21:59:52 +0100 | [diff] [blame] | 2048 | rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t), |
| 2049 | GFP_KERNEL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2050 | if (rc) |
| 2051 | goto fail4; |
| 2052 | BUG_ON(efx->irq_status.dma_addr & 0x0f); |
| 2053 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2054 | netif_dbg(efx, probe, efx->net_dev, |
| 2055 | "INT_KER at %llx (virt %p phys %llx)\n", |
| 2056 | (u64)efx->irq_status.dma_addr, |
| 2057 | efx->irq_status.addr, |
| 2058 | (u64)virt_to_phys(efx->irq_status.addr)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2059 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 2060 | falcon_probe_spi_devices(efx); |
| 2061 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2062 | /* Read in the non-volatile configuration */ |
| 2063 | rc = falcon_probe_nvconfig(efx); |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 2064 | if (rc) { |
| 2065 | if (rc == -EINVAL) |
| 2066 | netif_err(efx, probe, efx->net_dev, "NVRAM is invalid\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2067 | goto fail5; |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 2068 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2069 | |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 2070 | efx->max_channels = (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ? 4 : |
| 2071 | EFX_MAX_CHANNELS); |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 2072 | efx->timer_quantum_ns = 4968; /* 621 cycles */ |
| 2073 | |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 2074 | /* Initialise I2C adapter */ |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 2075 | board = falcon_board(efx); |
| 2076 | board->i2c_adap.owner = THIS_MODULE; |
| 2077 | board->i2c_data = falcon_i2c_bit_operations; |
| 2078 | board->i2c_data.data = efx; |
| 2079 | board->i2c_adap.algo_data = &board->i2c_data; |
| 2080 | board->i2c_adap.dev.parent = &efx->pci_dev->dev; |
| 2081 | strlcpy(board->i2c_adap.name, "SFC4000 GPIO", |
| 2082 | sizeof(board->i2c_adap.name)); |
| 2083 | rc = i2c_bit_add_bus(&board->i2c_adap); |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 2084 | if (rc) |
| 2085 | goto fail5; |
| 2086 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 2087 | rc = falcon_board(efx)->type->init(efx); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2088 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 2089 | netif_err(efx, probe, efx->net_dev, |
| 2090 | "failed to initialise board\n"); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2091 | goto fail6; |
| 2092 | } |
| 2093 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2094 | nic_data->stats_disable_count = 1; |
| 2095 | setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func, |
| 2096 | (unsigned long)efx); |
| 2097 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2098 | return 0; |
| 2099 | |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2100 | fail6: |
Lars-Peter Clausen | bf51a8c | 2013-03-09 08:16:46 +0000 | [diff] [blame] | 2101 | i2c_del_adapter(&board->i2c_adap); |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 2102 | memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2103 | fail5: |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2104 | efx_nic_free_buffer(efx, &efx->irq_status); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2105 | fail4: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2106 | fail3: |
| 2107 | if (nic_data->pci_dev2) { |
| 2108 | pci_dev_put(nic_data->pci_dev2); |
| 2109 | nic_data->pci_dev2 = NULL; |
| 2110 | } |
| 2111 | fail2: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2112 | fail1: |
| 2113 | kfree(efx->nic_data); |
| 2114 | return rc; |
| 2115 | } |
| 2116 | |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2117 | static void falcon_init_rx_cfg(struct efx_nic *efx) |
| 2118 | { |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2119 | /* RX control FIFO thresholds (32 entries) */ |
| 2120 | const unsigned ctrl_xon_thr = 20; |
| 2121 | const unsigned ctrl_xoff_thr = 25; |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2122 | efx_oword_t reg; |
| 2123 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2124 | efx_reado(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 2125 | if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) { |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 2126 | /* Data FIFO size is 5.5K. The RX DMA engine only |
| 2127 | * supports scattering for user-mode queues, but will |
| 2128 | * split DMA writes at intervals of RX_USR_BUF_SIZE |
| 2129 | * (32-byte units) even for kernel-mode queues. We |
| 2130 | * set it to be so large that that never happens. |
| 2131 | */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2132 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0); |
| 2133 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE, |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 2134 | (3 * 4096) >> 5); |
Ben Hutchings | 5fb6b06 | 2011-02-24 19:30:41 +0000 | [diff] [blame] | 2135 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, 512 >> 8); |
| 2136 | 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] | 2137 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr); |
| 2138 | 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] | 2139 | } else { |
Ben Hutchings | 625b451 | 2009-10-23 08:30:17 +0000 | [diff] [blame] | 2140 | /* Data FIFO size is 80K; register fields moved */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2141 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0); |
| 2142 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE, |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 2143 | EFX_RX_USR_BUF_SIZE >> 5); |
Ben Hutchings | 5fb6b06 | 2011-02-24 19:30:41 +0000 | [diff] [blame] | 2144 | /* Send XON and XOFF at ~3 * max MTU away from empty/full */ |
| 2145 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, 27648 >> 8); |
| 2146 | 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] | 2147 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr); |
| 2148 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr); |
| 2149 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1); |
Ben Hutchings | 477e54e | 2010-06-25 07:05:56 +0000 | [diff] [blame] | 2150 | |
| 2151 | /* Enable hash insertion. This is broken for the |
| 2152 | * 'Falcon' hash so also select Toeplitz TCP/IPv4 and |
| 2153 | * IPv4 hashes. */ |
| 2154 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1); |
| 2155 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1); |
| 2156 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1); |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2157 | } |
Ben Hutchings | 4b0d29d | 2009-11-29 03:42:18 +0000 | [diff] [blame] | 2158 | /* Always enable XOFF signal from RX FIFO. We enable |
| 2159 | * or disable transmission of pause frames at the MAC. */ |
| 2160 | EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2161 | efx_writeo(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2164 | /* This call performs hardware-specific global initialisation, such as |
| 2165 | * defining the descriptor cache sizes and number of RSS channels. |
| 2166 | * It does not set up any buffers, descriptor rings or event queues. |
| 2167 | */ |
| 2168 | static int falcon_init_nic(struct efx_nic *efx) |
| 2169 | { |
| 2170 | efx_oword_t temp; |
| 2171 | int rc; |
| 2172 | |
| 2173 | /* Use on-chip SRAM */ |
| 2174 | efx_reado(efx, &temp, FR_AB_NIC_STAT); |
| 2175 | EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1); |
| 2176 | efx_writeo(efx, &temp, FR_AB_NIC_STAT); |
| 2177 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2178 | rc = falcon_reset_sram(efx); |
| 2179 | if (rc) |
| 2180 | return rc; |
| 2181 | |
| 2182 | /* Clear the parity enables on the TX data fifos as |
| 2183 | * they produce false parity errors because of timing issues |
| 2184 | */ |
| 2185 | if (EFX_WORKAROUND_5129(efx)) { |
| 2186 | efx_reado(efx, &temp, FR_AZ_CSR_SPARE); |
| 2187 | EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0); |
| 2188 | efx_writeo(efx, &temp, FR_AZ_CSR_SPARE); |
| 2189 | } |
| 2190 | |
| 2191 | if (EFX_WORKAROUND_7244(efx)) { |
| 2192 | efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL); |
| 2193 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8); |
| 2194 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8); |
| 2195 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8); |
| 2196 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8); |
| 2197 | efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL); |
| 2198 | } |
| 2199 | |
| 2200 | /* XXX This is documented only for Falcon A0/A1 */ |
| 2201 | /* Setup RX. Wait for descriptor is broken and must |
| 2202 | * be disabled. RXDP recovery shouldn't be needed, but is. |
| 2203 | */ |
| 2204 | efx_reado(efx, &temp, FR_AA_RX_SELF_RST); |
| 2205 | EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1); |
| 2206 | EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1); |
| 2207 | if (EFX_WORKAROUND_5583(efx)) |
| 2208 | EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1); |
| 2209 | efx_writeo(efx, &temp, FR_AA_RX_SELF_RST); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2210 | |
| 2211 | /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16 |
| 2212 | * descriptors (which is bad). |
| 2213 | */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2214 | efx_reado(efx, &temp, FR_AZ_TX_CFG); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2215 | 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] | 2216 | efx_writeo(efx, &temp, FR_AZ_TX_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2217 | |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 2218 | falcon_init_rx_cfg(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2219 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 2220 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) { |
Ben Hutchings | 477e54e | 2010-06-25 07:05:56 +0000 | [diff] [blame] | 2221 | /* Set hash key for IPv4 */ |
| 2222 | memcpy(&temp, efx->rx_hash_key, sizeof(temp)); |
| 2223 | efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY); |
| 2224 | |
| 2225 | /* Set destination of both TX and RX Flush events */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2226 | EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2227 | efx_writeo(efx, &temp, FR_BZ_DP_CTRL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2228 | } |
| 2229 | |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 2230 | efx_farch_init_common(efx); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2231 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2232 | return 0; |
| 2233 | } |
| 2234 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2235 | static void falcon_remove_nic(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2236 | { |
| 2237 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 2238 | struct falcon_board *board = falcon_board(efx); |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 2239 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 2240 | board->type->fini(efx); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 2241 | |
Ben Hutchings | 8c87037 | 2009-03-04 09:53:02 +0000 | [diff] [blame] | 2242 | /* Remove I2C adapter and clear it in preparation for a retry */ |
Lars-Peter Clausen | bf51a8c | 2013-03-09 08:16:46 +0000 | [diff] [blame] | 2243 | i2c_del_adapter(&board->i2c_adap); |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 2244 | memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2245 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 2246 | efx_nic_free_buffer(efx, &efx->irq_status); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2247 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 2248 | __falcon_reset_hw(efx, RESET_TYPE_ALL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2249 | |
| 2250 | /* Release the second function after the reset */ |
| 2251 | if (nic_data->pci_dev2) { |
| 2252 | pci_dev_put(nic_data->pci_dev2); |
| 2253 | nic_data->pci_dev2 = NULL; |
| 2254 | } |
| 2255 | |
| 2256 | /* Tear down the private nic state */ |
| 2257 | kfree(efx->nic_data); |
| 2258 | efx->nic_data = NULL; |
| 2259 | } |
| 2260 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2261 | static void falcon_update_nic_stats(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2262 | { |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2263 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2264 | efx_oword_t cnt; |
| 2265 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2266 | if (nic_data->stats_disable_count) |
| 2267 | return; |
| 2268 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 2269 | efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2270 | efx->n_rx_nodesc_drop_cnt += |
| 2271 | EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2272 | |
| 2273 | if (nic_data->stats_pending && |
| 2274 | *nic_data->stats_dma_done == FALCON_STATS_DONE) { |
| 2275 | nic_data->stats_pending = false; |
| 2276 | rmb(); /* read the done flag before the stats */ |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 2277 | falcon_update_stats_xmac(efx); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | void falcon_start_nic_stats(struct efx_nic *efx) |
| 2282 | { |
| 2283 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 2284 | |
| 2285 | spin_lock_bh(&efx->stats_lock); |
| 2286 | if (--nic_data->stats_disable_count == 0) |
| 2287 | falcon_stats_request(efx); |
| 2288 | spin_unlock_bh(&efx->stats_lock); |
| 2289 | } |
| 2290 | |
| 2291 | void falcon_stop_nic_stats(struct efx_nic *efx) |
| 2292 | { |
| 2293 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 2294 | int i; |
| 2295 | |
| 2296 | might_sleep(); |
| 2297 | |
| 2298 | spin_lock_bh(&efx->stats_lock); |
| 2299 | ++nic_data->stats_disable_count; |
| 2300 | spin_unlock_bh(&efx->stats_lock); |
| 2301 | |
| 2302 | del_timer_sync(&nic_data->stats_timer); |
| 2303 | |
| 2304 | /* Wait enough time for the most recent transfer to |
| 2305 | * complete. */ |
| 2306 | for (i = 0; i < 4 && nic_data->stats_pending; i++) { |
| 2307 | if (*nic_data->stats_dma_done == FALCON_STATS_DONE) |
| 2308 | break; |
| 2309 | msleep(1); |
| 2310 | } |
| 2311 | |
| 2312 | spin_lock_bh(&efx->stats_lock); |
| 2313 | falcon_stats_complete(efx); |
| 2314 | spin_unlock_bh(&efx->stats_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2315 | } |
| 2316 | |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 2317 | static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode) |
| 2318 | { |
| 2319 | falcon_board(efx)->type->set_id_led(efx, mode); |
| 2320 | } |
| 2321 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2322 | /************************************************************************** |
| 2323 | * |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2324 | * Wake on LAN |
| 2325 | * |
| 2326 | ************************************************************************** |
| 2327 | */ |
| 2328 | |
| 2329 | static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol) |
| 2330 | { |
| 2331 | wol->supported = 0; |
| 2332 | wol->wolopts = 0; |
| 2333 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 2334 | } |
| 2335 | |
| 2336 | static int falcon_set_wol(struct efx_nic *efx, u32 type) |
| 2337 | { |
| 2338 | if (type != 0) |
| 2339 | return -EINVAL; |
| 2340 | return 0; |
| 2341 | } |
| 2342 | |
| 2343 | /************************************************************************** |
| 2344 | * |
Ben Hutchings | 754c653 | 2010-02-03 09:31:57 +0000 | [diff] [blame] | 2345 | * Revision-dependent attributes used by efx.c and nic.c |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2346 | * |
| 2347 | ************************************************************************** |
| 2348 | */ |
| 2349 | |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 2350 | const struct efx_nic_type falcon_a1_nic_type = { |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 2351 | .mem_map_size = falcon_a1_mem_map_size, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2352 | .probe = falcon_probe_nic, |
| 2353 | .remove = falcon_remove_nic, |
| 2354 | .init = falcon_init_nic, |
Ben Hutchings | 28e47c4 | 2012-02-15 01:58:49 +0000 | [diff] [blame] | 2355 | .dimension_resources = falcon_dimension_resources, |
Ben Hutchings | 1840667 | 2013-01-03 23:36:57 +0000 | [diff] [blame] | 2356 | .fini = falcon_irq_ack_a1, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2357 | .monitor = falcon_monitor, |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 2358 | .map_reset_reason = falcon_map_reset_reason, |
| 2359 | .map_reset_flags = falcon_map_reset_flags, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2360 | .reset = falcon_reset_hw, |
| 2361 | .probe_port = falcon_probe_port, |
| 2362 | .remove_port = falcon_remove_port, |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 2363 | .handle_global_event = falcon_handle_global_event, |
Ben Hutchings | e42c3d8 | 2013-05-27 16:52:54 +0100 | [diff] [blame] | 2364 | .fini_dmaq = efx_farch_fini_dmaq, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2365 | .prepare_flush = falcon_prepare_flush, |
Ben Hutchings | d5e8cc6 | 2012-09-06 16:52:31 +0100 | [diff] [blame] | 2366 | .finish_flush = efx_port_dummy_op_void, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2367 | .update_stats = falcon_update_nic_stats, |
| 2368 | .start_stats = falcon_start_nic_stats, |
| 2369 | .stop_stats = falcon_stop_nic_stats, |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 2370 | .set_id_led = falcon_set_id_led, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2371 | .push_irq_moderation = falcon_push_irq_moderation, |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2372 | .reconfigure_port = falcon_reconfigure_port, |
Ben Hutchings | 9dd3a13 | 2012-09-13 01:11:25 +0100 | [diff] [blame] | 2373 | .prepare_enable_fc_tx = falcon_a1_prepare_enable_fc_tx, |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 2374 | .reconfigure_mac = falcon_reconfigure_xmac, |
| 2375 | .check_mac_fault = falcon_xmac_check_fault, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2376 | .get_wol = falcon_get_wol, |
| 2377 | .set_wol = falcon_set_wol, |
| 2378 | .resume_wol = efx_port_dummy_op_void, |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 2379 | .test_nvram = falcon_test_nvram, |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 2380 | .irq_enable_master = efx_farch_irq_enable_master, |
| 2381 | .irq_test_generate = efx_farch_irq_test_generate, |
| 2382 | .irq_disable_non_ev = efx_farch_irq_disable_master, |
| 2383 | .irq_handle_msi = efx_farch_msi_interrupt, |
| 2384 | .irq_handle_legacy = falcon_legacy_interrupt_a1, |
| 2385 | .tx_probe = efx_farch_tx_probe, |
| 2386 | .tx_init = efx_farch_tx_init, |
| 2387 | .tx_remove = efx_farch_tx_remove, |
| 2388 | .tx_write = efx_farch_tx_write, |
| 2389 | .rx_push_indir_table = efx_farch_rx_push_indir_table, |
| 2390 | .rx_probe = efx_farch_rx_probe, |
| 2391 | .rx_init = efx_farch_rx_init, |
| 2392 | .rx_remove = efx_farch_rx_remove, |
| 2393 | .rx_write = efx_farch_rx_write, |
| 2394 | .rx_defer_refill = efx_farch_rx_defer_refill, |
| 2395 | .ev_probe = efx_farch_ev_probe, |
| 2396 | .ev_init = efx_farch_ev_init, |
| 2397 | .ev_fini = efx_farch_ev_fini, |
| 2398 | .ev_remove = efx_farch_ev_remove, |
| 2399 | .ev_process = efx_farch_ev_process, |
| 2400 | .ev_read_ack = efx_farch_ev_read_ack, |
| 2401 | .ev_test_generate = efx_farch_ev_test_generate, |
Steve Hodgson | b895d73 | 2009-11-28 05:35:00 +0000 | [diff] [blame] | 2402 | |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame^] | 2403 | /* We don't expose the filter table on Falcon A1 as it is not |
| 2404 | * mapped into function 0, but these implementations still |
| 2405 | * work with a degenerate case of all tables set to size 0. |
| 2406 | */ |
| 2407 | .filter_table_probe = efx_farch_filter_table_probe, |
| 2408 | .filter_table_restore = efx_farch_filter_table_restore, |
| 2409 | .filter_table_remove = efx_farch_filter_table_remove, |
| 2410 | .filter_insert = efx_farch_filter_insert, |
| 2411 | .filter_remove_safe = efx_farch_filter_remove_safe, |
| 2412 | .filter_get_safe = efx_farch_filter_get_safe, |
| 2413 | .filter_clear_rx = efx_farch_filter_clear_rx, |
| 2414 | .filter_count_rx_used = efx_farch_filter_count_rx_used, |
| 2415 | .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit, |
| 2416 | .filter_get_rx_ids = efx_farch_filter_get_rx_ids, |
| 2417 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 2418 | .revision = EFX_REV_FALCON_A1, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2419 | .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER, |
| 2420 | .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER, |
| 2421 | .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER, |
| 2422 | .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER, |
| 2423 | .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER, |
Ben Hutchings | 6d51d30 | 2009-10-23 08:31:07 +0000 | [diff] [blame] | 2424 | .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] | 2425 | .rx_buffer_padding = 0x24, |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 2426 | .can_rx_scatter = false, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2427 | .max_interrupt_mode = EFX_INT_MODE_MSI, |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 2428 | .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH, |
Ben Hutchings | c383b53 | 2009-11-29 15:11:02 +0000 | [diff] [blame] | 2429 | .offload_features = NETIF_F_IP_CSUM, |
Ben Hutchings | df2cd8a | 2012-09-19 00:56:18 +0100 | [diff] [blame] | 2430 | .mcdi_max_ver = -1, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2431 | }; |
| 2432 | |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 2433 | const struct efx_nic_type falcon_b0_nic_type = { |
Ben Hutchings | b105798 | 2012-09-19 00:56:47 +0100 | [diff] [blame] | 2434 | .mem_map_size = falcon_b0_mem_map_size, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2435 | .probe = falcon_probe_nic, |
| 2436 | .remove = falcon_remove_nic, |
| 2437 | .init = falcon_init_nic, |
Ben Hutchings | 28e47c4 | 2012-02-15 01:58:49 +0000 | [diff] [blame] | 2438 | .dimension_resources = falcon_dimension_resources, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2439 | .fini = efx_port_dummy_op_void, |
| 2440 | .monitor = falcon_monitor, |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 2441 | .map_reset_reason = falcon_map_reset_reason, |
| 2442 | .map_reset_flags = falcon_map_reset_flags, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2443 | .reset = falcon_reset_hw, |
| 2444 | .probe_port = falcon_probe_port, |
| 2445 | .remove_port = falcon_remove_port, |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 2446 | .handle_global_event = falcon_handle_global_event, |
Ben Hutchings | e42c3d8 | 2013-05-27 16:52:54 +0100 | [diff] [blame] | 2447 | .fini_dmaq = efx_farch_fini_dmaq, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2448 | .prepare_flush = falcon_prepare_flush, |
Ben Hutchings | d5e8cc6 | 2012-09-06 16:52:31 +0100 | [diff] [blame] | 2449 | .finish_flush = efx_port_dummy_op_void, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2450 | .update_stats = falcon_update_nic_stats, |
| 2451 | .start_stats = falcon_start_nic_stats, |
| 2452 | .stop_stats = falcon_stop_nic_stats, |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 2453 | .set_id_led = falcon_set_id_led, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 2454 | .push_irq_moderation = falcon_push_irq_moderation, |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 2455 | .reconfigure_port = falcon_reconfigure_port, |
Ben Hutchings | 9dd3a13 | 2012-09-13 01:11:25 +0100 | [diff] [blame] | 2456 | .prepare_enable_fc_tx = falcon_b0_prepare_enable_fc_tx, |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 2457 | .reconfigure_mac = falcon_reconfigure_xmac, |
| 2458 | .check_mac_fault = falcon_xmac_check_fault, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 2459 | .get_wol = falcon_get_wol, |
| 2460 | .set_wol = falcon_set_wol, |
| 2461 | .resume_wol = efx_port_dummy_op_void, |
Ben Hutchings | d4f2cec | 2012-07-04 03:58:33 +0100 | [diff] [blame] | 2462 | .test_chip = falcon_b0_test_chip, |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 2463 | .test_nvram = falcon_test_nvram, |
Ben Hutchings | 86094f7 | 2013-08-21 19:51:04 +0100 | [diff] [blame] | 2464 | .irq_enable_master = efx_farch_irq_enable_master, |
| 2465 | .irq_test_generate = efx_farch_irq_test_generate, |
| 2466 | .irq_disable_non_ev = efx_farch_irq_disable_master, |
| 2467 | .irq_handle_msi = efx_farch_msi_interrupt, |
| 2468 | .irq_handle_legacy = efx_farch_legacy_interrupt, |
| 2469 | .tx_probe = efx_farch_tx_probe, |
| 2470 | .tx_init = efx_farch_tx_init, |
| 2471 | .tx_remove = efx_farch_tx_remove, |
| 2472 | .tx_write = efx_farch_tx_write, |
| 2473 | .rx_push_indir_table = efx_farch_rx_push_indir_table, |
| 2474 | .rx_probe = efx_farch_rx_probe, |
| 2475 | .rx_init = efx_farch_rx_init, |
| 2476 | .rx_remove = efx_farch_rx_remove, |
| 2477 | .rx_write = efx_farch_rx_write, |
| 2478 | .rx_defer_refill = efx_farch_rx_defer_refill, |
| 2479 | .ev_probe = efx_farch_ev_probe, |
| 2480 | .ev_init = efx_farch_ev_init, |
| 2481 | .ev_fini = efx_farch_ev_fini, |
| 2482 | .ev_remove = efx_farch_ev_remove, |
| 2483 | .ev_process = efx_farch_ev_process, |
| 2484 | .ev_read_ack = efx_farch_ev_read_ack, |
| 2485 | .ev_test_generate = efx_farch_ev_test_generate, |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame^] | 2486 | .filter_table_probe = efx_farch_filter_table_probe, |
| 2487 | .filter_table_restore = efx_farch_filter_table_restore, |
| 2488 | .filter_table_remove = efx_farch_filter_table_remove, |
| 2489 | .filter_update_rx_scatter = efx_farch_filter_update_rx_scatter, |
| 2490 | .filter_insert = efx_farch_filter_insert, |
| 2491 | .filter_remove_safe = efx_farch_filter_remove_safe, |
| 2492 | .filter_get_safe = efx_farch_filter_get_safe, |
| 2493 | .filter_clear_rx = efx_farch_filter_clear_rx, |
| 2494 | .filter_count_rx_used = efx_farch_filter_count_rx_used, |
| 2495 | .filter_get_rx_id_limit = efx_farch_filter_get_rx_id_limit, |
| 2496 | .filter_get_rx_ids = efx_farch_filter_get_rx_ids, |
| 2497 | #ifdef CONFIG_RFS_ACCEL |
| 2498 | .filter_rfs_insert = efx_farch_filter_rfs_insert, |
| 2499 | .filter_rfs_expire_one = efx_farch_filter_rfs_expire_one, |
| 2500 | #endif |
Steve Hodgson | b895d73 | 2009-11-28 05:35:00 +0000 | [diff] [blame] | 2501 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 2502 | .revision = EFX_REV_FALCON_B0, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 2503 | .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL, |
| 2504 | .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL, |
| 2505 | .buf_tbl_base = FR_BZ_BUF_FULL_TBL, |
| 2506 | .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL, |
| 2507 | .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR, |
Ben Hutchings | 6d51d30 | 2009-10-23 08:31:07 +0000 | [diff] [blame] | 2508 | .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] | 2509 | .rx_buffer_hash_size = 0x10, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2510 | .rx_buffer_padding = 0, |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 2511 | .can_rx_scatter = true, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2512 | .max_interrupt_mode = EFX_INT_MODE_MSIX, |
Ben Hutchings | cc180b6 | 2011-12-08 19:51:47 +0000 | [diff] [blame] | 2513 | .timer_period_max = 1 << FRF_AB_TC_TIMER_VAL_WIDTH, |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 2514 | .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH | NETIF_F_NTUPLE, |
Ben Hutchings | df2cd8a | 2012-09-19 00:56:18 +0100 | [diff] [blame] | 2515 | .mcdi_max_ver = -1, |
Ben Hutchings | add7247 | 2012-11-08 01:46:53 +0000 | [diff] [blame^] | 2516 | .max_rx_ip_filters = FR_BZ_RX_FILTER_TBL0_ROWS, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 2517 | }; |
| 2518 | |