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