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