Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
| 3 | * Copyright 2005-2006 Fen Systems Ltd. |
Ben Hutchings | 0a6f40c | 2011-02-25 00:01:34 +0000 | [diff] [blame] | 4 | * Copyright 2006-2010 Solarflare Communications Inc. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published |
| 8 | * by the Free Software Foundation, incorporated herein by reference. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/bitops.h> |
| 12 | #include <linux/delay.h> |
| 13 | #include <linux/pci.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/seq_file.h> |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 16 | #include <linux/i2c.h> |
Ben Hutchings | f31a45d | 2008-12-12 21:43:33 -0800 | [diff] [blame] | 17 | #include <linux/mii.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 19 | #include "net_driver.h" |
| 20 | #include "bitfield.h" |
| 21 | #include "efx.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 22 | #include "spi.h" |
Ben Hutchings | 744093c | 2009-11-29 15:12:08 +0000 | [diff] [blame] | 23 | #include "nic.h" |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 24 | #include "regs.h" |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 25 | #include "io.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 26 | #include "phy.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 27 | #include "workarounds.h" |
| 28 | |
Ben Hutchings | 8986352 | 2009-11-25 16:09:04 +0000 | [diff] [blame] | 29 | /* Hardware control for SFC4000 (aka Falcon). */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 30 | |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 31 | static const unsigned int |
| 32 | /* "Large" EEPROM device: Atmel AT25640 or similar |
| 33 | * 8 KB, 16-bit address, 32 B write block */ |
| 34 | large_eeprom_type = ((13 << SPI_DEV_TYPE_SIZE_LBN) |
| 35 | | (2 << SPI_DEV_TYPE_ADDR_LEN_LBN) |
| 36 | | (5 << SPI_DEV_TYPE_BLOCK_SIZE_LBN)), |
| 37 | /* Default flash device: Atmel AT25F1024 |
| 38 | * 128 KB, 24-bit address, 32 KB erase block, 256 B write block */ |
| 39 | default_flash_type = ((17 << SPI_DEV_TYPE_SIZE_LBN) |
| 40 | | (3 << SPI_DEV_TYPE_ADDR_LEN_LBN) |
| 41 | | (0x52 << SPI_DEV_TYPE_ERASE_CMD_LBN) |
| 42 | | (15 << SPI_DEV_TYPE_ERASE_SIZE_LBN) |
| 43 | | (8 << SPI_DEV_TYPE_BLOCK_SIZE_LBN)); |
| 44 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 45 | /************************************************************************** |
| 46 | * |
| 47 | * I2C bus - this is a bit-bashing interface using GPIO pins |
| 48 | * Note that it uses the output enables to tristate the outputs |
| 49 | * SDA is the data pin and SCL is the clock |
| 50 | * |
| 51 | ************************************************************************** |
| 52 | */ |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 53 | static void falcon_setsda(void *data, int state) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 54 | { |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 55 | struct efx_nic *efx = (struct efx_nic *)data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 56 | efx_oword_t reg; |
| 57 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 58 | efx_reado(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 59 | EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN, !state); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 60 | efx_writeo(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 63 | static void falcon_setscl(void *data, int state) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 64 | { |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 65 | struct efx_nic *efx = (struct efx_nic *)data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 66 | efx_oword_t reg; |
| 67 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 68 | efx_reado(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 69 | EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO0_OEN, !state); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 70 | efx_writeo(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static int falcon_getsda(void *data) |
| 74 | { |
| 75 | struct efx_nic *efx = (struct efx_nic *)data; |
| 76 | efx_oword_t reg; |
| 77 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 78 | efx_reado(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 79 | return EFX_OWORD_FIELD(reg, FRF_AB_GPIO3_IN); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 82 | static int falcon_getscl(void *data) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 83 | { |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 84 | struct efx_nic *efx = (struct efx_nic *)data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 85 | efx_oword_t reg; |
| 86 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 87 | efx_reado(efx, ®, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 88 | return EFX_OWORD_FIELD(reg, FRF_AB_GPIO0_IN); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Ben Hutchings | 18e83e4 | 2012-01-05 19:05:20 +0000 | [diff] [blame] | 91 | static const struct i2c_algo_bit_data falcon_i2c_bit_operations = { |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 92 | .setsda = falcon_setsda, |
| 93 | .setscl = falcon_setscl, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 94 | .getsda = falcon_getsda, |
| 95 | .getscl = falcon_getscl, |
Ben Hutchings | 62c7832 | 2008-05-30 22:27:46 +0100 | [diff] [blame] | 96 | .udelay = 5, |
Ben Hutchings | 9dadae6 | 2008-07-18 18:59:12 +0100 | [diff] [blame] | 97 | /* Wait up to 50 ms for slave to let us pull SCL high */ |
| 98 | .timeout = DIV_ROUND_UP(HZ, 20), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 99 | }; |
| 100 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 101 | static void falcon_push_irq_moderation(struct efx_channel *channel) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 102 | { |
| 103 | efx_dword_t timer_cmd; |
| 104 | struct efx_nic *efx = channel->efx; |
| 105 | |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 106 | BUILD_BUG_ON(EFX_IRQ_MOD_MAX > (1 << FRF_AB_TC_TIMER_VAL_WIDTH)); |
| 107 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 108 | /* Set timer register */ |
| 109 | if (channel->irq_moderation) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 110 | EFX_POPULATE_DWORD_2(timer_cmd, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 111 | FRF_AB_TC_TIMER_MODE, |
| 112 | FFE_BB_TIMER_MODE_INT_HLDOFF, |
| 113 | FRF_AB_TC_TIMER_VAL, |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 114 | channel->irq_moderation - 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 115 | } else { |
| 116 | EFX_POPULATE_DWORD_2(timer_cmd, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 117 | FRF_AB_TC_TIMER_MODE, |
| 118 | FFE_BB_TIMER_MODE_DIS, |
| 119 | FRF_AB_TC_TIMER_VAL, 0); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 120 | } |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 121 | 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] | 122 | efx_writed_page_locked(efx, &timer_cmd, FR_BZ_TIMER_COMMAND_P0, |
| 123 | channel->channel); |
Ben Hutchings | 127e6e1 | 2009-11-25 16:09:55 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 126 | static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx); |
| 127 | |
Ben Hutchings | 127e6e1 | 2009-11-25 16:09:55 +0000 | [diff] [blame] | 128 | static void falcon_prepare_flush(struct efx_nic *efx) |
| 129 | { |
| 130 | falcon_deconfigure_mac_wrapper(efx); |
| 131 | |
| 132 | /* Wait for the tx and rx fifo's to get to the next packet boundary |
| 133 | * (~1ms without back-pressure), then to drain the remainder of the |
| 134 | * fifo's at data path speeds (negligible), with a healthy margin. */ |
| 135 | msleep(10); |
Ben Hutchings | 6bc5d3a | 2008-09-01 12:49:37 +0100 | [diff] [blame] | 136 | } |
| 137 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 138 | /* Acknowledge a legacy interrupt from Falcon |
| 139 | * |
| 140 | * This acknowledges a legacy (not MSI) interrupt via INT_ACK_KER_REG. |
| 141 | * |
| 142 | * Due to SFC bug 3706 (silicon revision <=A1) reads can be duplicated in the |
| 143 | * BIU. Interrupt acknowledge is read sensitive so must write instead |
| 144 | * (then read to ensure the BIU collector is flushed) |
| 145 | * |
| 146 | * NB most hardware supports MSI interrupts |
| 147 | */ |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 148 | inline void falcon_irq_ack_a1(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 149 | { |
| 150 | efx_dword_t reg; |
| 151 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 152 | EFX_POPULATE_DWORD_1(reg, FRF_AA_INT_ACK_KER_FIELD, 0xb7eb7e); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 153 | efx_writed(efx, ®, FR_AA_INT_ACK_KER); |
| 154 | efx_readd(efx, ®, FR_AA_WORK_AROUND_BROKEN_PCI_READS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 155 | } |
| 156 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 157 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 158 | irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 159 | { |
Ben Hutchings | d3208b5 | 2008-05-16 21:20:00 +0100 | [diff] [blame] | 160 | struct efx_nic *efx = dev_id; |
| 161 | efx_oword_t *int_ker = efx->irq_status.addr; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 162 | int syserr; |
| 163 | int queues; |
| 164 | |
| 165 | /* Check to see if this is our interrupt. If it isn't, we |
| 166 | * exit without having touched the hardware. |
| 167 | */ |
| 168 | if (unlikely(EFX_OWORD_IS_ZERO(*int_ker))) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 169 | netif_vdbg(efx, intr, efx->net_dev, |
| 170 | "IRQ %d on CPU %d not for me\n", irq, |
| 171 | raw_smp_processor_id()); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 172 | return IRQ_NONE; |
| 173 | } |
| 174 | efx->last_irq_cpu = raw_smp_processor_id(); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 175 | netif_vdbg(efx, intr, efx->net_dev, |
| 176 | "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n", |
| 177 | irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 178 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 179 | /* Determine interrupting queues, clear interrupt status |
| 180 | * register and acknowledge the device interrupt. |
| 181 | */ |
Ben Hutchings | 674979d | 2009-11-29 03:42:10 +0000 | [diff] [blame] | 182 | BUILD_BUG_ON(FSF_AZ_NET_IVEC_INT_Q_WIDTH > EFX_MAX_CHANNELS); |
| 183 | queues = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_INT_Q); |
Steve Hodgson | 6369545 | 2010-04-28 09:27:36 +0000 | [diff] [blame] | 184 | |
| 185 | /* Check to see if we have a serious error condition */ |
| 186 | if (queues & (1U << efx->fatal_irq_level)) { |
| 187 | syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT); |
| 188 | if (unlikely(syserr)) |
| 189 | return efx_nic_fatal_interrupt(efx); |
| 190 | } |
| 191 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 192 | EFX_ZERO_OWORD(*int_ker); |
| 193 | wmb(); /* Ensure the vector is cleared before interrupt ack */ |
| 194 | falcon_irq_ack_a1(efx); |
| 195 | |
Ben Hutchings | 8313aca | 2010-09-10 06:41:57 +0000 | [diff] [blame] | 196 | if (queues & 1) |
| 197 | efx_schedule_channel(efx_get_channel(efx, 0)); |
| 198 | if (queues & 2) |
| 199 | efx_schedule_channel(efx_get_channel(efx, 1)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 200 | return IRQ_HANDLED; |
| 201 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 202 | /************************************************************************** |
| 203 | * |
| 204 | * EEPROM/flash |
| 205 | * |
| 206 | ************************************************************************** |
| 207 | */ |
| 208 | |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 209 | #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 210 | |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 211 | static int falcon_spi_poll(struct efx_nic *efx) |
| 212 | { |
| 213 | efx_oword_t reg; |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 214 | efx_reado(efx, ®, FR_AB_EE_SPI_HCMD); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 215 | 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] | 216 | } |
| 217 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 218 | /* Wait for SPI command completion */ |
| 219 | static int falcon_spi_wait(struct efx_nic *efx) |
| 220 | { |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 221 | /* Most commands will finish quickly, so we start polling at |
| 222 | * very short intervals. Sometimes the command may have to |
| 223 | * wait for VPD or expansion ROM access outside of our |
| 224 | * control, so we allow up to 100 ms. */ |
| 225 | unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 10); |
| 226 | int i; |
| 227 | |
| 228 | for (i = 0; i < 10; i++) { |
| 229 | if (!falcon_spi_poll(efx)) |
| 230 | return 0; |
| 231 | udelay(10); |
| 232 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 233 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 234 | for (;;) { |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 235 | if (!falcon_spi_poll(efx)) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 236 | return 0; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 237 | if (time_after_eq(jiffies, timeout)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 238 | netif_err(efx, hw, efx->net_dev, |
| 239 | "timed out waiting for SPI\n"); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 240 | return -ETIMEDOUT; |
| 241 | } |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 242 | schedule_timeout_uninterruptible(1); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 243 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 244 | } |
| 245 | |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 246 | int falcon_spi_cmd(struct efx_nic *efx, const struct efx_spi_device *spi, |
Ben Hutchings | f415072 | 2008-11-04 20:34:28 +0000 | [diff] [blame] | 247 | unsigned int command, int address, |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 248 | const void *in, void *out, size_t len) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 249 | { |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 250 | bool addressed = (address >= 0); |
| 251 | bool reading = (out != NULL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 252 | efx_oword_t reg; |
| 253 | int rc; |
| 254 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 255 | /* Input validation */ |
| 256 | if (len > FALCON_SPI_MAX_LEN) |
| 257 | return -EINVAL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 258 | |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 259 | /* Check that previous command is not still running */ |
| 260 | rc = falcon_spi_poll(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 261 | if (rc) |
| 262 | return rc; |
| 263 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 264 | /* Program address register, if we have an address */ |
| 265 | if (addressed) { |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 266 | EFX_POPULATE_OWORD_1(reg, FRF_AB_EE_SPI_HADR_ADR, address); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 267 | efx_writeo(efx, ®, FR_AB_EE_SPI_HADR); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 268 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 269 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 270 | /* Program data register, if we have data */ |
| 271 | if (in != NULL) { |
| 272 | memcpy(®, in, len); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 273 | efx_writeo(efx, ®, FR_AB_EE_SPI_HDATA); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /* Issue read/write command */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 277 | EFX_POPULATE_OWORD_7(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 278 | FRF_AB_EE_SPI_HCMD_CMD_EN, 1, |
| 279 | FRF_AB_EE_SPI_HCMD_SF_SEL, spi->device_id, |
| 280 | FRF_AB_EE_SPI_HCMD_DABCNT, len, |
| 281 | FRF_AB_EE_SPI_HCMD_READ, reading, |
| 282 | FRF_AB_EE_SPI_HCMD_DUBCNT, 0, |
| 283 | FRF_AB_EE_SPI_HCMD_ADBCNT, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 284 | (addressed ? spi->addr_len : 0), |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 285 | FRF_AB_EE_SPI_HCMD_ENC, command); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 286 | efx_writeo(efx, ®, FR_AB_EE_SPI_HCMD); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 287 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 288 | /* Wait for read/write to complete */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 289 | rc = falcon_spi_wait(efx); |
| 290 | if (rc) |
| 291 | return rc; |
| 292 | |
| 293 | /* Read data */ |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 294 | if (out != NULL) { |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 295 | efx_reado(efx, ®, FR_AB_EE_SPI_HDATA); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 296 | memcpy(out, ®, len); |
| 297 | } |
| 298 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 302 | static size_t |
| 303 | falcon_spi_write_limit(const struct efx_spi_device *spi, size_t start) |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 304 | { |
| 305 | return min(FALCON_SPI_MAX_LEN, |
| 306 | (spi->block_size - (start & (spi->block_size - 1)))); |
| 307 | } |
| 308 | |
| 309 | static inline u8 |
| 310 | efx_spi_munge_command(const struct efx_spi_device *spi, |
| 311 | const u8 command, const unsigned int address) |
| 312 | { |
| 313 | return command | (((address >> 8) & spi->munge_address) << 3); |
| 314 | } |
| 315 | |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 316 | /* Wait up to 10 ms for buffered write completion */ |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 317 | int |
| 318 | falcon_spi_wait_write(struct efx_nic *efx, const struct efx_spi_device *spi) |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 319 | { |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 320 | unsigned long timeout = jiffies + 1 + DIV_ROUND_UP(HZ, 100); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 321 | u8 status; |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 322 | int rc; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 323 | |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 324 | for (;;) { |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 325 | rc = falcon_spi_cmd(efx, spi, SPI_RDSR, -1, NULL, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 326 | &status, sizeof(status)); |
| 327 | if (rc) |
| 328 | return rc; |
| 329 | if (!(status & SPI_STATUS_NRDY)) |
| 330 | return 0; |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 331 | if (time_after_eq(jiffies, timeout)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 332 | netif_err(efx, hw, efx->net_dev, |
| 333 | "SPI write timeout on device %d" |
| 334 | " last status=0x%02x\n", |
| 335 | spi->device_id, status); |
Ben Hutchings | be4ea89 | 2008-12-12 21:33:50 -0800 | [diff] [blame] | 336 | return -ETIMEDOUT; |
| 337 | } |
| 338 | schedule_timeout_uninterruptible(1); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 339 | } |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 342 | int falcon_spi_read(struct efx_nic *efx, const struct efx_spi_device *spi, |
| 343 | loff_t start, size_t len, size_t *retlen, u8 *buffer) |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 344 | { |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 345 | size_t block_len, pos = 0; |
| 346 | unsigned int command; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 347 | int rc = 0; |
| 348 | |
| 349 | while (pos < len) { |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 350 | block_len = min(len - pos, FALCON_SPI_MAX_LEN); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 351 | |
| 352 | command = efx_spi_munge_command(spi, SPI_READ, start + pos); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 353 | rc = falcon_spi_cmd(efx, spi, command, start + pos, NULL, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 354 | buffer + pos, block_len); |
| 355 | if (rc) |
| 356 | break; |
| 357 | pos += block_len; |
| 358 | |
| 359 | /* Avoid locking up the system */ |
| 360 | cond_resched(); |
| 361 | if (signal_pending(current)) { |
| 362 | rc = -EINTR; |
| 363 | break; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if (retlen) |
| 368 | *retlen = pos; |
| 369 | return rc; |
| 370 | } |
| 371 | |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 372 | int |
| 373 | falcon_spi_write(struct efx_nic *efx, const struct efx_spi_device *spi, |
| 374 | loff_t start, size_t len, size_t *retlen, const u8 *buffer) |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 375 | { |
| 376 | u8 verify_buffer[FALCON_SPI_MAX_LEN]; |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 377 | size_t block_len, pos = 0; |
| 378 | unsigned int command; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 379 | int rc = 0; |
| 380 | |
| 381 | while (pos < len) { |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 382 | rc = falcon_spi_cmd(efx, spi, SPI_WREN, -1, NULL, NULL, 0); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 383 | if (rc) |
| 384 | break; |
| 385 | |
Ben Hutchings | 23d30f0 | 2008-12-12 21:56:11 -0800 | [diff] [blame] | 386 | block_len = min(len - pos, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 387 | falcon_spi_write_limit(spi, start + pos)); |
| 388 | command = efx_spi_munge_command(spi, SPI_WRITE, start + pos); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 389 | rc = falcon_spi_cmd(efx, spi, command, start + pos, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 390 | buffer + pos, NULL, block_len); |
| 391 | if (rc) |
| 392 | break; |
| 393 | |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 394 | rc = falcon_spi_wait_write(efx, spi); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 395 | if (rc) |
| 396 | break; |
| 397 | |
| 398 | command = efx_spi_munge_command(spi, SPI_READ, start + pos); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 399 | rc = falcon_spi_cmd(efx, spi, command, start + pos, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 400 | NULL, verify_buffer, block_len); |
| 401 | if (memcmp(verify_buffer, buffer + pos, block_len)) { |
| 402 | rc = -EIO; |
| 403 | break; |
| 404 | } |
| 405 | |
| 406 | pos += block_len; |
| 407 | |
| 408 | /* Avoid locking up the system */ |
| 409 | cond_resched(); |
| 410 | if (signal_pending(current)) { |
| 411 | rc = -EINTR; |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | if (retlen) |
| 417 | *retlen = pos; |
| 418 | return rc; |
| 419 | } |
| 420 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 421 | /************************************************************************** |
| 422 | * |
| 423 | * MAC wrapper |
| 424 | * |
| 425 | ************************************************************************** |
| 426 | */ |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 427 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 428 | static void falcon_push_multicast_hash(struct efx_nic *efx) |
| 429 | { |
| 430 | union efx_multicast_hash *mc_hash = &efx->multicast_hash; |
| 431 | |
| 432 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
| 433 | |
| 434 | efx_writeo(efx, &mc_hash->oword[0], FR_AB_MAC_MC_HASH_REG0); |
| 435 | efx_writeo(efx, &mc_hash->oword[1], FR_AB_MAC_MC_HASH_REG1); |
| 436 | } |
| 437 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 438 | static void falcon_reset_macs(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 439 | { |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 440 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 441 | efx_oword_t reg, mac_ctrl; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 442 | int count; |
| 443 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 444 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) { |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 445 | /* It's not safe to use GLB_CTL_REG to reset the |
| 446 | * macs, so instead use the internal MAC resets |
| 447 | */ |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 448 | EFX_POPULATE_OWORD_1(reg, FRF_AB_XM_CORE_RST, 1); |
| 449 | efx_writeo(efx, ®, FR_AB_XM_GLB_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 450 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 451 | for (count = 0; count < 10000; count++) { |
| 452 | efx_reado(efx, ®, FR_AB_XM_GLB_CFG); |
| 453 | if (EFX_OWORD_FIELD(reg, FRF_AB_XM_CORE_RST) == |
| 454 | 0) |
| 455 | return; |
| 456 | udelay(10); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 457 | } |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 458 | |
| 459 | netif_err(efx, hw, efx->net_dev, |
| 460 | "timed out waiting for XMAC core reset\n"); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 461 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 462 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 463 | /* Mac stats will fail whist the TX fifo is draining */ |
| 464 | WARN_ON(nic_data->stats_disable_count == 0); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 465 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 466 | efx_reado(efx, &mac_ctrl, FR_AB_MAC_CTRL); |
| 467 | EFX_SET_OWORD_FIELD(mac_ctrl, FRF_BB_TXFIFO_DRAIN_EN, 1); |
| 468 | efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 469 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 470 | efx_reado(efx, ®, FR_AB_GLB_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 471 | EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGTX, 1); |
| 472 | EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_XGRX, 1); |
| 473 | EFX_SET_OWORD_FIELD(reg, FRF_AB_RST_EM, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 474 | efx_writeo(efx, ®, FR_AB_GLB_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 475 | |
| 476 | count = 0; |
| 477 | while (1) { |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 478 | efx_reado(efx, ®, FR_AB_GLB_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 479 | if (!EFX_OWORD_FIELD(reg, FRF_AB_RST_XGTX) && |
| 480 | !EFX_OWORD_FIELD(reg, FRF_AB_RST_XGRX) && |
| 481 | !EFX_OWORD_FIELD(reg, FRF_AB_RST_EM)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 482 | netif_dbg(efx, hw, efx->net_dev, |
| 483 | "Completed MAC reset after %d loops\n", |
| 484 | count); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 485 | break; |
| 486 | } |
| 487 | if (count > 20) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 488 | netif_err(efx, hw, efx->net_dev, "MAC reset failed\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 489 | break; |
| 490 | } |
| 491 | count++; |
| 492 | udelay(10); |
| 493 | } |
| 494 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 495 | /* Ensure the correct MAC is selected before statistics |
| 496 | * are re-enabled by the caller */ |
| 497 | efx_writeo(efx, &mac_ctrl, FR_AB_MAC_CTRL); |
Steve Hodgson | b7b40ee | 2010-04-28 09:28:10 +0000 | [diff] [blame] | 498 | |
Steve Hodgson | b7b40ee | 2010-04-28 09:28:10 +0000 | [diff] [blame] | 499 | falcon_setup_xaui(efx); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | void falcon_drain_tx_fifo(struct efx_nic *efx) |
| 503 | { |
| 504 | efx_oword_t reg; |
| 505 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 506 | if ((efx_nic_rev(efx) < EFX_REV_FALCON_B0) || |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 507 | (efx->loopback_mode != LOOPBACK_NONE)) |
| 508 | return; |
| 509 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 510 | efx_reado(efx, ®, FR_AB_MAC_CTRL); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 511 | /* There is no point in draining more than once */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 512 | if (EFX_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN)) |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 513 | return; |
| 514 | |
| 515 | falcon_reset_macs(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 518 | static void falcon_deconfigure_mac_wrapper(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 519 | { |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 520 | efx_oword_t reg; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 521 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 522 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 523 | return; |
| 524 | |
| 525 | /* Isolate the MAC -> RX */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 526 | efx_reado(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 527 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 528 | efx_writeo(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 529 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 530 | /* Isolate TX -> MAC */ |
| 531 | falcon_drain_tx_fifo(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | void falcon_reconfigure_mac_wrapper(struct efx_nic *efx) |
| 535 | { |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 536 | struct efx_link_state *link_state = &efx->link_state; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 537 | efx_oword_t reg; |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 538 | int link_speed, isolate; |
| 539 | |
Ben Hutchings | a7d529a | 2011-06-24 20:46:31 +0100 | [diff] [blame] | 540 | isolate = !!ACCESS_ONCE(efx->reset_pending); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 541 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 542 | switch (link_state->speed) { |
Ben Hutchings | f31a45d | 2008-12-12 21:43:33 -0800 | [diff] [blame] | 543 | case 10000: link_speed = 3; break; |
| 544 | case 1000: link_speed = 2; break; |
| 545 | case 100: link_speed = 1; break; |
| 546 | default: link_speed = 0; break; |
| 547 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 548 | /* MAC_LINK_STATUS controls MAC backpressure but doesn't work |
| 549 | * as advertised. Disable to ensure packets are not |
| 550 | * indefinitely held and TX queue can be flushed at any point |
| 551 | * while the link is down. */ |
| 552 | EFX_POPULATE_OWORD_5(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 553 | FRF_AB_MAC_XOFF_VAL, 0xffff /* max pause time */, |
| 554 | FRF_AB_MAC_BCAD_ACPT, 1, |
| 555 | FRF_AB_MAC_UC_PROM, efx->promiscuous, |
| 556 | FRF_AB_MAC_LINK_STATUS, 1, /* always set */ |
| 557 | FRF_AB_MAC_SPEED, link_speed); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 558 | /* On B0, MAC backpressure can be disabled and packets get |
| 559 | * discarded. */ |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 560 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) { |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 561 | EFX_SET_OWORD_FIELD(reg, FRF_BB_TXFIFO_DRAIN_EN, |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 562 | !link_state->up || isolate); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 563 | } |
| 564 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 565 | efx_writeo(efx, ®, FR_AB_MAC_CTRL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 566 | |
| 567 | /* Restore the multicast hash registers. */ |
Ben Hutchings | 8be4f3e | 2009-11-25 16:12:16 +0000 | [diff] [blame] | 568 | falcon_push_multicast_hash(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 569 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 570 | efx_reado(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 4b0d29d | 2009-11-29 03:42:18 +0000 | [diff] [blame] | 571 | /* Enable XOFF signal from RX FIFO (we enabled it during NIC |
| 572 | * initialisation but it may read back as 0) */ |
| 573 | EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 574 | /* Unisolate the MAC -> RX */ |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 575 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) |
Steve Hodgson | fd371e3 | 2010-06-01 11:17:51 +0000 | [diff] [blame] | 576 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, !isolate); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 577 | efx_writeo(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 578 | } |
| 579 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 580 | static void falcon_stats_request(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 581 | { |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 582 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 583 | efx_oword_t reg; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 584 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 585 | WARN_ON(nic_data->stats_pending); |
| 586 | WARN_ON(nic_data->stats_disable_count); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 587 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 588 | if (nic_data->stats_dma_done == NULL) |
| 589 | return; /* no mac selected */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 590 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 591 | *nic_data->stats_dma_done = FALCON_STATS_NOT_DONE; |
| 592 | nic_data->stats_pending = true; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 593 | wmb(); /* ensure done flag is clear */ |
| 594 | |
| 595 | /* Initiate DMA transfer of stats */ |
| 596 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 597 | FRF_AB_MAC_STAT_DMA_CMD, 1, |
| 598 | FRF_AB_MAC_STAT_DMA_ADR, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 599 | efx->stats_buffer.dma_addr); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 600 | efx_writeo(efx, ®, FR_AB_MAC_STAT_DMA); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 601 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 602 | mod_timer(&nic_data->stats_timer, round_jiffies_up(jiffies + HZ / 2)); |
| 603 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 604 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 605 | static void falcon_stats_complete(struct efx_nic *efx) |
| 606 | { |
| 607 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 608 | |
| 609 | if (!nic_data->stats_pending) |
| 610 | return; |
| 611 | |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 612 | nic_data->stats_pending = false; |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 613 | if (*nic_data->stats_dma_done == FALCON_STATS_DONE) { |
| 614 | rmb(); /* read the done flag before the stats */ |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 615 | falcon_update_stats_xmac(efx); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 616 | } else { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 617 | netif_err(efx, hw, efx->net_dev, |
| 618 | "timed out waiting for statistics\n"); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | |
| 622 | static void falcon_stats_timer_func(unsigned long context) |
| 623 | { |
| 624 | struct efx_nic *efx = (struct efx_nic *)context; |
| 625 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 626 | |
| 627 | spin_lock(&efx->stats_lock); |
| 628 | |
| 629 | falcon_stats_complete(efx); |
| 630 | if (nic_data->stats_disable_count == 0) |
| 631 | falcon_stats_request(efx); |
| 632 | |
| 633 | spin_unlock(&efx->stats_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 634 | } |
| 635 | |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 636 | static bool falcon_loopback_link_poll(struct efx_nic *efx) |
| 637 | { |
| 638 | struct efx_link_state old_state = efx->link_state; |
| 639 | |
| 640 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); |
| 641 | WARN_ON(!LOOPBACK_INTERNAL(efx)); |
| 642 | |
| 643 | efx->link_state.fd = true; |
| 644 | efx->link_state.fc = efx->wanted_fc; |
| 645 | efx->link_state.up = true; |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 646 | efx->link_state.speed = 10000; |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 647 | |
| 648 | return !efx_link_state_equal(&efx->link_state, &old_state); |
| 649 | } |
| 650 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 651 | static int falcon_reconfigure_port(struct efx_nic *efx) |
| 652 | { |
| 653 | int rc; |
| 654 | |
| 655 | WARN_ON(efx_nic_rev(efx) > EFX_REV_FALCON_B0); |
| 656 | |
| 657 | /* Poll the PHY link state *before* reconfiguring it. This means we |
| 658 | * will pick up the correct speed (in loopback) to select the correct |
| 659 | * MAC. |
| 660 | */ |
| 661 | if (LOOPBACK_INTERNAL(efx)) |
| 662 | falcon_loopback_link_poll(efx); |
| 663 | else |
| 664 | efx->phy_op->poll(efx); |
| 665 | |
| 666 | falcon_stop_nic_stats(efx); |
| 667 | falcon_deconfigure_mac_wrapper(efx); |
| 668 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 669 | falcon_reset_macs(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 670 | |
| 671 | efx->phy_op->reconfigure(efx); |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 672 | rc = falcon_reconfigure_xmac(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 673 | BUG_ON(rc); |
| 674 | |
| 675 | falcon_start_nic_stats(efx); |
| 676 | |
| 677 | /* Synchronise efx->link_state with the kernel */ |
| 678 | efx_link_status_changed(efx); |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 683 | /************************************************************************** |
| 684 | * |
| 685 | * PHY access via GMII |
| 686 | * |
| 687 | ************************************************************************** |
| 688 | */ |
| 689 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 690 | /* Wait for GMII access to complete */ |
| 691 | static int falcon_gmii_wait(struct efx_nic *efx) |
| 692 | { |
Ben Hutchings | 80cb9a0 | 2009-11-25 16:08:41 +0000 | [diff] [blame] | 693 | efx_oword_t md_stat; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 694 | int count; |
| 695 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 696 | /* wait up to 50ms - taken max from datasheet */ |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 697 | for (count = 0; count < 5000; count++) { |
Ben Hutchings | 80cb9a0 | 2009-11-25 16:08:41 +0000 | [diff] [blame] | 698 | efx_reado(efx, &md_stat, FR_AB_MD_STAT); |
| 699 | if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSY) == 0) { |
| 700 | if (EFX_OWORD_FIELD(md_stat, FRF_AB_MD_LNFL) != 0 || |
| 701 | EFX_OWORD_FIELD(md_stat, FRF_AB_MD_BSERR) != 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 702 | netif_err(efx, hw, efx->net_dev, |
| 703 | "error from GMII access " |
| 704 | EFX_OWORD_FMT"\n", |
| 705 | EFX_OWORD_VAL(md_stat)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 706 | return -EIO; |
| 707 | } |
| 708 | return 0; |
| 709 | } |
| 710 | udelay(10); |
| 711 | } |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 712 | 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] | 713 | return -ETIMEDOUT; |
| 714 | } |
| 715 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 716 | /* Write an MDIO register of a PHY connected to Falcon. */ |
| 717 | static int falcon_mdio_write(struct net_device *net_dev, |
| 718 | int prtad, int devad, u16 addr, u16 value) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 719 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 720 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 721 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 722 | efx_oword_t reg; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 723 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 724 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 725 | netif_vdbg(efx, hw, efx->net_dev, |
| 726 | "writing MDIO %d register %d.%d with 0x%04x\n", |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 727 | prtad, devad, addr, value); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 728 | |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 729 | mutex_lock(&nic_data->mdio_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 730 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 731 | /* Check MDIO not currently being accessed */ |
| 732 | rc = falcon_gmii_wait(efx); |
| 733 | if (rc) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 734 | goto out; |
| 735 | |
| 736 | /* Write the address/ID register */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 737 | EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 738 | efx_writeo(efx, ®, FR_AB_MD_PHY_ADR); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 739 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 740 | EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad, |
| 741 | FRF_AB_MD_DEV_ADR, devad); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 742 | efx_writeo(efx, ®, FR_AB_MD_ID); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 743 | |
| 744 | /* Write data */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 745 | EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_TXD, value); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 746 | efx_writeo(efx, ®, FR_AB_MD_TXD); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 747 | |
| 748 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 749 | FRF_AB_MD_WRC, 1, |
| 750 | FRF_AB_MD_GC, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 751 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 752 | |
| 753 | /* Wait for data to be written */ |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 754 | rc = falcon_gmii_wait(efx); |
| 755 | if (rc) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 756 | /* Abort the write operation */ |
| 757 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 758 | FRF_AB_MD_WRC, 0, |
| 759 | FRF_AB_MD_GC, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 760 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 761 | udelay(10); |
| 762 | } |
| 763 | |
Steve Hodgson | ab86746 | 2009-11-28 05:34:44 +0000 | [diff] [blame] | 764 | out: |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 765 | mutex_unlock(&nic_data->mdio_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 766 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 767 | } |
| 768 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 769 | /* Read an MDIO register of a PHY connected to Falcon. */ |
| 770 | static int falcon_mdio_read(struct net_device *net_dev, |
| 771 | int prtad, int devad, u16 addr) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 772 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 773 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 774 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 775 | efx_oword_t reg; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 776 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 777 | |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 778 | mutex_lock(&nic_data->mdio_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 779 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 780 | /* Check MDIO not currently being accessed */ |
| 781 | rc = falcon_gmii_wait(efx); |
| 782 | if (rc) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 783 | goto out; |
| 784 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 785 | EFX_POPULATE_OWORD_1(reg, FRF_AB_MD_PHY_ADR, addr); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 786 | efx_writeo(efx, ®, FR_AB_MD_PHY_ADR); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 787 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 788 | EFX_POPULATE_OWORD_2(reg, FRF_AB_MD_PRT_ADR, prtad, |
| 789 | FRF_AB_MD_DEV_ADR, devad); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 790 | efx_writeo(efx, ®, FR_AB_MD_ID); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 791 | |
| 792 | /* Request data to be read */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 793 | 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] | 794 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 795 | |
| 796 | /* Wait for data to become available */ |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 797 | rc = falcon_gmii_wait(efx); |
| 798 | if (rc == 0) { |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 799 | efx_reado(efx, ®, FR_AB_MD_RXD); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 800 | rc = EFX_OWORD_FIELD(reg, FRF_AB_MD_RXD); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 801 | netif_vdbg(efx, hw, efx->net_dev, |
| 802 | "read from MDIO %d register %d.%d, got %04x\n", |
| 803 | prtad, devad, addr, rc); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 804 | } else { |
| 805 | /* Abort the read operation */ |
| 806 | EFX_POPULATE_OWORD_2(reg, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 807 | FRF_AB_MD_RIC, 0, |
| 808 | FRF_AB_MD_GC, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 809 | efx_writeo(efx, ®, FR_AB_MD_CS); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 810 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 811 | netif_dbg(efx, hw, efx->net_dev, |
| 812 | "read from MDIO %d register %d.%d, got error %d\n", |
| 813 | prtad, devad, addr, rc); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 814 | } |
| 815 | |
Steve Hodgson | ab86746 | 2009-11-28 05:34:44 +0000 | [diff] [blame] | 816 | out: |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 817 | mutex_unlock(&nic_data->mdio_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 818 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 819 | } |
| 820 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 821 | /* This call is responsible for hooking in the MAC and PHY operations */ |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 822 | static int falcon_probe_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 823 | { |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 824 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 825 | int rc; |
| 826 | |
Ben Hutchings | 96c4572 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 827 | switch (efx->phy_type) { |
| 828 | case PHY_TYPE_SFX7101: |
| 829 | efx->phy_op = &falcon_sfx7101_phy_ops; |
| 830 | break; |
Ben Hutchings | 96c4572 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 831 | case PHY_TYPE_QT2022C2: |
| 832 | case PHY_TYPE_QT2025C: |
Ben Hutchings | b37b62f | 2009-10-23 08:33:42 +0000 | [diff] [blame] | 833 | efx->phy_op = &falcon_qt202x_phy_ops; |
Ben Hutchings | 96c4572 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 834 | break; |
Ben Hutchings | 7e51b43 | 2010-09-22 10:00:47 +0000 | [diff] [blame] | 835 | case PHY_TYPE_TXC43128: |
| 836 | efx->phy_op = &falcon_txc_phy_ops; |
| 837 | break; |
Ben Hutchings | 96c4572 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 838 | default: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 839 | netif_err(efx, probe, efx->net_dev, "Unknown PHY type %d\n", |
| 840 | efx->phy_type); |
Ben Hutchings | 96c4572 | 2009-10-23 08:32:42 +0000 | [diff] [blame] | 841 | return -ENODEV; |
| 842 | } |
| 843 | |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 844 | /* Fill out MDIO structure and loopback modes */ |
Ben Hutchings | 4833f02 | 2010-12-02 13:47:35 +0000 | [diff] [blame] | 845 | mutex_init(&nic_data->mdio_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 846 | efx->mdio.mdio_read = falcon_mdio_read; |
| 847 | efx->mdio.mdio_write = falcon_mdio_write; |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 848 | rc = efx->phy_op->probe(efx); |
| 849 | if (rc != 0) |
| 850 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 851 | |
Steve Hodgson | b895d73 | 2009-11-28 05:35:00 +0000 | [diff] [blame] | 852 | /* Initial assumption */ |
| 853 | efx->link_state.speed = 10000; |
| 854 | efx->link_state.fd = true; |
| 855 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 856 | /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */ |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 857 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 858 | efx->wanted_fc = EFX_FC_RX | EFX_FC_TX; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 859 | else |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 860 | efx->wanted_fc = EFX_FC_RX; |
Steve Hodgson | 7a6b8f6 | 2010-02-03 09:30:38 +0000 | [diff] [blame] | 861 | if (efx->mdio.mmds & MDIO_DEVS_AN) |
| 862 | efx->wanted_fc |= EFX_FC_AUTO; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 863 | |
| 864 | /* Allocate buffer for stats */ |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 865 | rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer, |
| 866 | FALCON_MAC_STATS_SIZE); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 867 | if (rc) |
| 868 | return rc; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 869 | netif_dbg(efx, probe, efx->net_dev, |
| 870 | "stats buffer at %llx (virt %p phys %llx)\n", |
| 871 | (u64)efx->stats_buffer.dma_addr, |
| 872 | efx->stats_buffer.addr, |
| 873 | (u64)virt_to_phys(efx->stats_buffer.addr)); |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 874 | nic_data->stats_dma_done = efx->stats_buffer.addr + XgDmaDone_offset; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 875 | |
| 876 | return 0; |
| 877 | } |
| 878 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 879 | static void falcon_remove_port(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 880 | { |
Steve Hodgson | ff3b00a | 2009-12-23 13:46:36 +0000 | [diff] [blame] | 881 | efx->phy_op->remove(efx); |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 882 | efx_nic_free_buffer(efx, &efx->stats_buffer); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 883 | } |
| 884 | |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 885 | /* Global events are basically PHY events */ |
| 886 | static bool |
| 887 | falcon_handle_global_event(struct efx_channel *channel, efx_qword_t *event) |
| 888 | { |
| 889 | struct efx_nic *efx = channel->efx; |
Ben Hutchings | cef68bd | 2010-12-02 13:47:51 +0000 | [diff] [blame] | 890 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 891 | |
| 892 | if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) || |
| 893 | EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) || |
| 894 | EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR)) |
| 895 | /* Ignored */ |
| 896 | return true; |
| 897 | |
| 898 | if ((efx_nic_rev(efx) == EFX_REV_FALCON_B0) && |
| 899 | EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) { |
Ben Hutchings | cef68bd | 2010-12-02 13:47:51 +0000 | [diff] [blame] | 900 | nic_data->xmac_poll_required = true; |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 901 | return true; |
| 902 | } |
| 903 | |
| 904 | if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ? |
| 905 | EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) : |
| 906 | EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) { |
| 907 | netif_err(efx, rx_err, efx->net_dev, |
| 908 | "channel %d seen global RX_RESET event. Resetting.\n", |
| 909 | channel->channel); |
| 910 | |
| 911 | atomic_inc(&efx->rx_reset); |
| 912 | efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ? |
| 913 | RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE); |
| 914 | return true; |
| 915 | } |
| 916 | |
| 917 | return false; |
| 918 | } |
| 919 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 920 | /************************************************************************** |
| 921 | * |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 922 | * Falcon test code |
| 923 | * |
| 924 | **************************************************************************/ |
| 925 | |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 926 | static int |
| 927 | falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out) |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 928 | { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 929 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 930 | struct falcon_nvconfig *nvconfig; |
| 931 | struct efx_spi_device *spi; |
| 932 | void *region; |
| 933 | int rc, magic_num, struct_ver; |
| 934 | __le16 *word, *limit; |
| 935 | u32 csum; |
| 936 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 937 | if (efx_spi_present(&nic_data->spi_flash)) |
| 938 | spi = &nic_data->spi_flash; |
| 939 | else if (efx_spi_present(&nic_data->spi_eeprom)) |
| 940 | spi = &nic_data->spi_eeprom; |
| 941 | else |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 942 | return -EINVAL; |
| 943 | |
Ben Hutchings | 0a95f56 | 2008-11-04 20:33:11 +0000 | [diff] [blame] | 944 | region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 945 | if (!region) |
| 946 | return -ENOMEM; |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 947 | nvconfig = region + FALCON_NVCONFIG_OFFSET; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 948 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 949 | mutex_lock(&nic_data->spi_lock); |
Ben Hutchings | 7688483 | 2009-11-29 15:10:44 +0000 | [diff] [blame] | 950 | rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region); |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 951 | mutex_unlock(&nic_data->spi_lock); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 952 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 953 | netif_err(efx, hw, efx->net_dev, "Failed to read %s\n", |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 954 | efx_spi_present(&nic_data->spi_flash) ? |
| 955 | "flash" : "EEPROM"); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 956 | rc = -EIO; |
| 957 | goto out; |
| 958 | } |
| 959 | |
| 960 | magic_num = le16_to_cpu(nvconfig->board_magic_num); |
| 961 | struct_ver = le16_to_cpu(nvconfig->board_struct_ver); |
| 962 | |
| 963 | rc = -EINVAL; |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 964 | if (magic_num != FALCON_NVCONFIG_BOARD_MAGIC_NUM) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 965 | netif_err(efx, hw, efx->net_dev, |
| 966 | "NVRAM bad magic 0x%x\n", magic_num); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 967 | goto out; |
| 968 | } |
| 969 | if (struct_ver < 2) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 970 | netif_err(efx, hw, efx->net_dev, |
| 971 | "NVRAM has ancient version 0x%x\n", struct_ver); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 972 | goto out; |
| 973 | } else if (struct_ver < 4) { |
| 974 | word = &nvconfig->board_magic_num; |
| 975 | limit = (__le16 *) (nvconfig + 1); |
| 976 | } else { |
| 977 | word = region; |
Ben Hutchings | 0a95f56 | 2008-11-04 20:33:11 +0000 | [diff] [blame] | 978 | limit = region + FALCON_NVCONFIG_END; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 979 | } |
| 980 | for (csum = 0; word < limit; ++word) |
| 981 | csum += le16_to_cpu(*word); |
| 982 | |
| 983 | if (~csum & 0xffff) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 984 | netif_err(efx, hw, efx->net_dev, |
| 985 | "NVRAM has incorrect checksum\n"); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 986 | goto out; |
| 987 | } |
| 988 | |
| 989 | rc = 0; |
| 990 | if (nvconfig_out) |
| 991 | memcpy(nvconfig_out, nvconfig, sizeof(*nvconfig)); |
| 992 | |
| 993 | out: |
| 994 | kfree(region); |
| 995 | return rc; |
| 996 | } |
| 997 | |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 998 | static int falcon_test_nvram(struct efx_nic *efx) |
| 999 | { |
| 1000 | return falcon_read_nvram(efx, NULL); |
| 1001 | } |
| 1002 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1003 | static const struct efx_nic_register_test falcon_b0_register_tests[] = { |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1004 | { FR_AZ_ADR_REGION, |
Steve Hodgson | 4cddca5 | 2010-02-03 09:31:40 +0000 | [diff] [blame] | 1005 | EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1006 | { FR_AZ_RX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1007 | EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1008 | { FR_AZ_TX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1009 | EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1010 | { FR_AZ_TX_RESERVED, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1011 | EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1012 | { FR_AB_MAC_CTRL, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1013 | EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1014 | { FR_AZ_SRM_TX_DC_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1015 | EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1016 | { FR_AZ_RX_DC_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1017 | EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1018 | { FR_AZ_RX_DC_PF_WM, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1019 | EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1020 | { FR_BZ_DP_CTRL, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1021 | EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1022 | { FR_AB_GM_CFG2, |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1023 | EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1024 | { FR_AB_GMF_CFG0, |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 1025 | EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1026 | { FR_AB_XM_GLB_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1027 | EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1028 | { FR_AB_XM_TX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1029 | EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1030 | { FR_AB_XM_RX_CFG, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1031 | EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1032 | { FR_AB_XM_RX_PARAM, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1033 | EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1034 | { FR_AB_XM_FC, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1035 | EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1036 | { FR_AB_XM_ADR_LO, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1037 | EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) }, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1038 | { FR_AB_XX_SD_CTL, |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1039 | EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) }, |
| 1040 | }; |
| 1041 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1042 | static int falcon_b0_test_registers(struct efx_nic *efx) |
| 1043 | { |
| 1044 | return efx_nic_test_registers(efx, falcon_b0_register_tests, |
| 1045 | ARRAY_SIZE(falcon_b0_register_tests)); |
| 1046 | } |
| 1047 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1048 | /************************************************************************** |
| 1049 | * |
| 1050 | * Device reset |
| 1051 | * |
| 1052 | ************************************************************************** |
| 1053 | */ |
| 1054 | |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 1055 | static enum reset_type falcon_map_reset_reason(enum reset_type reason) |
| 1056 | { |
| 1057 | switch (reason) { |
| 1058 | case RESET_TYPE_RX_RECOVERY: |
| 1059 | case RESET_TYPE_RX_DESC_FETCH: |
| 1060 | case RESET_TYPE_TX_DESC_FETCH: |
| 1061 | case RESET_TYPE_TX_SKIP: |
| 1062 | /* These can occasionally occur due to hardware bugs. |
| 1063 | * We try to reset without disrupting the link. |
| 1064 | */ |
| 1065 | return RESET_TYPE_INVISIBLE; |
| 1066 | default: |
| 1067 | return RESET_TYPE_ALL; |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | static int falcon_map_reset_flags(u32 *flags) |
| 1072 | { |
| 1073 | enum { |
| 1074 | FALCON_RESET_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER | |
| 1075 | ETH_RESET_OFFLOAD | ETH_RESET_MAC), |
| 1076 | FALCON_RESET_ALL = FALCON_RESET_INVISIBLE | ETH_RESET_PHY, |
| 1077 | FALCON_RESET_WORLD = FALCON_RESET_ALL | ETH_RESET_IRQ, |
| 1078 | }; |
| 1079 | |
| 1080 | if ((*flags & FALCON_RESET_WORLD) == FALCON_RESET_WORLD) { |
| 1081 | *flags &= ~FALCON_RESET_WORLD; |
| 1082 | return RESET_TYPE_WORLD; |
| 1083 | } |
| 1084 | |
| 1085 | if ((*flags & FALCON_RESET_ALL) == FALCON_RESET_ALL) { |
| 1086 | *flags &= ~FALCON_RESET_ALL; |
| 1087 | return RESET_TYPE_ALL; |
| 1088 | } |
| 1089 | |
| 1090 | if ((*flags & FALCON_RESET_INVISIBLE) == FALCON_RESET_INVISIBLE) { |
| 1091 | *flags &= ~FALCON_RESET_INVISIBLE; |
| 1092 | return RESET_TYPE_INVISIBLE; |
| 1093 | } |
| 1094 | |
| 1095 | return -EINVAL; |
| 1096 | } |
| 1097 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1098 | /* Resets NIC to known state. This routine must be called in process |
| 1099 | * context and is allowed to sleep. */ |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1100 | 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] | 1101 | { |
| 1102 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1103 | efx_oword_t glb_ctl_reg_ker; |
| 1104 | int rc; |
| 1105 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1106 | netif_dbg(efx, hw, efx->net_dev, "performing %s hardware reset\n", |
| 1107 | RESET_TYPE(method)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1108 | |
| 1109 | /* Initiate device reset */ |
| 1110 | if (method == RESET_TYPE_WORLD) { |
| 1111 | rc = pci_save_state(efx->pci_dev); |
| 1112 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1113 | netif_err(efx, drv, efx->net_dev, |
| 1114 | "failed to backup PCI state of primary " |
| 1115 | "function prior to hardware reset\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1116 | goto fail1; |
| 1117 | } |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1118 | if (efx_nic_is_dual_func(efx)) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1119 | rc = pci_save_state(nic_data->pci_dev2); |
| 1120 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1121 | netif_err(efx, drv, efx->net_dev, |
| 1122 | "failed to backup PCI state of " |
| 1123 | "secondary function prior to " |
| 1124 | "hardware reset\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1125 | goto fail2; |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | EFX_POPULATE_OWORD_2(glb_ctl_reg_ker, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1130 | FRF_AB_EXT_PHY_RST_DUR, |
| 1131 | FFE_AB_EXT_PHY_RST_DUR_10240US, |
| 1132 | FRF_AB_SWRST, 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1133 | } else { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1134 | EFX_POPULATE_OWORD_7(glb_ctl_reg_ker, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1135 | /* exclude PHY from "invisible" reset */ |
| 1136 | FRF_AB_EXT_PHY_RST_CTL, |
| 1137 | method == RESET_TYPE_INVISIBLE, |
| 1138 | /* exclude EEPROM/flash and PCIe */ |
| 1139 | FRF_AB_PCIE_CORE_RST_CTL, 1, |
| 1140 | FRF_AB_PCIE_NSTKY_RST_CTL, 1, |
| 1141 | FRF_AB_PCIE_SD_RST_CTL, 1, |
| 1142 | FRF_AB_EE_RST_CTL, 1, |
| 1143 | FRF_AB_EXT_PHY_RST_DUR, |
| 1144 | FFE_AB_EXT_PHY_RST_DUR_10240US, |
| 1145 | FRF_AB_SWRST, 1); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1146 | } |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1147 | efx_writeo(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1148 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1149 | netif_dbg(efx, hw, efx->net_dev, "waiting for hardware reset\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1150 | schedule_timeout_uninterruptible(HZ / 20); |
| 1151 | |
| 1152 | /* Restore PCI configuration if needed */ |
| 1153 | if (method == RESET_TYPE_WORLD) { |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 1154 | if (efx_nic_is_dual_func(efx)) |
| 1155 | pci_restore_state(nic_data->pci_dev2); |
| 1156 | pci_restore_state(efx->pci_dev); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1157 | netif_dbg(efx, drv, efx->net_dev, |
| 1158 | "successfully restored PCI config\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /* Assert that reset complete */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1162 | efx_reado(efx, &glb_ctl_reg_ker, FR_AB_GLB_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1163 | if (EFX_OWORD_FIELD(glb_ctl_reg_ker, FRF_AB_SWRST) != 0) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1164 | rc = -ETIMEDOUT; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1165 | netif_err(efx, hw, efx->net_dev, |
| 1166 | "timed out waiting for hardware reset\n"); |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 1167 | goto fail3; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1168 | } |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1169 | netif_dbg(efx, hw, efx->net_dev, "hardware reset complete\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1170 | |
| 1171 | return 0; |
| 1172 | |
| 1173 | /* pci_save_state() and pci_restore_state() MUST be called in pairs */ |
| 1174 | fail2: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1175 | pci_restore_state(efx->pci_dev); |
| 1176 | fail1: |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 1177 | fail3: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1178 | return rc; |
| 1179 | } |
| 1180 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1181 | static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method) |
| 1182 | { |
| 1183 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1184 | int rc; |
| 1185 | |
| 1186 | mutex_lock(&nic_data->spi_lock); |
| 1187 | rc = __falcon_reset_hw(efx, method); |
| 1188 | mutex_unlock(&nic_data->spi_lock); |
| 1189 | |
| 1190 | return rc; |
| 1191 | } |
| 1192 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1193 | static void falcon_monitor(struct efx_nic *efx) |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1194 | { |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1195 | bool link_changed; |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1196 | int rc; |
| 1197 | |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1198 | BUG_ON(!mutex_is_locked(&efx->mac_lock)); |
| 1199 | |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1200 | rc = falcon_board(efx)->type->monitor(efx); |
| 1201 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1202 | netif_err(efx, hw, efx->net_dev, |
| 1203 | "Board sensor %s; shutting down PHY\n", |
| 1204 | (rc == -ERANGE) ? "reported fault" : "failed"); |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1205 | efx->phy_mode |= PHY_MODE_LOW_POWER; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1206 | rc = __efx_reconfigure_port(efx); |
| 1207 | WARN_ON(rc); |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1208 | } |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1209 | |
| 1210 | if (LOOPBACK_INTERNAL(efx)) |
| 1211 | link_changed = falcon_loopback_link_poll(efx); |
| 1212 | else |
| 1213 | link_changed = efx->phy_op->poll(efx); |
| 1214 | |
| 1215 | if (link_changed) { |
| 1216 | falcon_stop_nic_stats(efx); |
| 1217 | falcon_deconfigure_mac_wrapper(efx); |
| 1218 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1219 | falcon_reset_macs(efx); |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1220 | rc = falcon_reconfigure_xmac(efx); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1221 | BUG_ON(rc); |
Steve Hodgson | fdaa9ae | 2009-11-28 05:34:05 +0000 | [diff] [blame] | 1222 | |
| 1223 | falcon_start_nic_stats(efx); |
| 1224 | |
| 1225 | efx_link_status_changed(efx); |
| 1226 | } |
| 1227 | |
Ben Hutchings | 8fbca79 | 2010-09-22 10:00:11 +0000 | [diff] [blame] | 1228 | falcon_poll_xmac(efx); |
Ben Hutchings | fe75820 | 2009-11-25 16:11:45 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1231 | /* Zeroes out the SRAM contents. This routine must be called in |
| 1232 | * process context and is allowed to sleep. |
| 1233 | */ |
| 1234 | static int falcon_reset_sram(struct efx_nic *efx) |
| 1235 | { |
| 1236 | efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker; |
| 1237 | int count; |
| 1238 | |
| 1239 | /* Set the SRAM wake/sleep GPIO appropriately. */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1240 | efx_reado(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1241 | EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, FRF_AB_GPIO1_OEN, 1); |
| 1242 | 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] | 1243 | efx_writeo(efx, &gpio_cfg_reg_ker, FR_AB_GPIO_CTL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1244 | |
| 1245 | /* Initiate SRAM reset */ |
| 1246 | EFX_POPULATE_OWORD_2(srm_cfg_reg_ker, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1247 | FRF_AZ_SRM_INIT_EN, 1, |
| 1248 | FRF_AZ_SRM_NB_SZ, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1249 | efx_writeo(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1250 | |
| 1251 | /* Wait for SRAM reset to complete */ |
| 1252 | count = 0; |
| 1253 | do { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1254 | netif_dbg(efx, hw, efx->net_dev, |
| 1255 | "waiting for SRAM reset (attempt %d)...\n", count); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1256 | |
| 1257 | /* SRAM reset is slow; expect around 16ms */ |
| 1258 | schedule_timeout_uninterruptible(HZ / 50); |
| 1259 | |
| 1260 | /* Check for reset complete */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1261 | efx_reado(efx, &srm_cfg_reg_ker, FR_AZ_SRM_CFG); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1262 | 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] | 1263 | netif_dbg(efx, hw, efx->net_dev, |
| 1264 | "SRAM reset complete\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1265 | |
| 1266 | return 0; |
| 1267 | } |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1268 | } while (++count < 20); /* wait up to 0.4 sec */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1269 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1270 | 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] | 1271 | return -ETIMEDOUT; |
| 1272 | } |
| 1273 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1274 | static void falcon_spi_device_init(struct efx_nic *efx, |
| 1275 | struct efx_spi_device *spi_device, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1276 | unsigned int device_id, u32 device_type) |
| 1277 | { |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1278 | if (device_type != 0) { |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1279 | spi_device->device_id = device_id; |
| 1280 | spi_device->size = |
| 1281 | 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE); |
| 1282 | spi_device->addr_len = |
| 1283 | SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ADDR_LEN); |
| 1284 | spi_device->munge_address = (spi_device->size == 1 << 9 && |
| 1285 | spi_device->addr_len == 1); |
Ben Hutchings | f415072 | 2008-11-04 20:34:28 +0000 | [diff] [blame] | 1286 | spi_device->erase_command = |
| 1287 | SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_ERASE_CMD); |
| 1288 | spi_device->erase_size = |
| 1289 | 1 << SPI_DEV_TYPE_FIELD(device_type, |
| 1290 | SPI_DEV_TYPE_ERASE_SIZE); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1291 | spi_device->block_size = |
| 1292 | 1 << SPI_DEV_TYPE_FIELD(device_type, |
| 1293 | SPI_DEV_TYPE_BLOCK_SIZE); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1294 | } else { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1295 | spi_device->size = 0; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1296 | } |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1297 | } |
| 1298 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1299 | /* Extract non-volatile configuration */ |
| 1300 | static int falcon_probe_nvconfig(struct efx_nic *efx) |
| 1301 | { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1302 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1303 | struct falcon_nvconfig *nvconfig; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1304 | int rc; |
| 1305 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1306 | nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1307 | if (!nvconfig) |
| 1308 | return -ENOMEM; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1309 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1310 | rc = falcon_read_nvram(efx, nvconfig); |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1311 | if (rc) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1312 | goto out; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1313 | |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1314 | efx->phy_type = nvconfig->board_v2.port0_phy_type; |
| 1315 | efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1316 | |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1317 | if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1318 | falcon_spi_device_init( |
| 1319 | efx, &nic_data->spi_flash, FFE_AB_SPI_DEVICE_FLASH, |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1320 | le32_to_cpu(nvconfig->board_v3 |
| 1321 | .spi_device_type[FFE_AB_SPI_DEVICE_FLASH])); |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1322 | falcon_spi_device_init( |
| 1323 | efx, &nic_data->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM, |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1324 | le32_to_cpu(nvconfig->board_v3 |
| 1325 | .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM])); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1326 | } |
| 1327 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1328 | /* Read the MAC addresses */ |
Ben Hutchings | 7e300bc | 2010-12-02 13:48:28 +0000 | [diff] [blame] | 1329 | memcpy(efx->net_dev->perm_addr, nvconfig->mac_address[0], ETH_ALEN); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 1330 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1331 | netif_dbg(efx, probe, efx->net_dev, "PHY is %d phy_id %d\n", |
| 1332 | efx->phy_type, efx->mdio.prtad); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1333 | |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1334 | rc = falcon_probe_board(efx, |
| 1335 | le16_to_cpu(nvconfig->board_v2.board_revision)); |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1336 | out: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1337 | kfree(nvconfig); |
| 1338 | return rc; |
| 1339 | } |
| 1340 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1341 | /* Probe all SPI devices on the NIC */ |
| 1342 | static void falcon_probe_spi_devices(struct efx_nic *efx) |
| 1343 | { |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1344 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1345 | efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg; |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1346 | int boot_dev; |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1347 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1348 | efx_reado(efx, &gpio_ctl, FR_AB_GPIO_CTL); |
| 1349 | efx_reado(efx, &nic_stat, FR_AB_NIC_STAT); |
| 1350 | efx_reado(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1351 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1352 | if (EFX_OWORD_FIELD(gpio_ctl, FRF_AB_GPIO3_PWRUP_VALUE)) { |
| 1353 | boot_dev = (EFX_OWORD_FIELD(nic_stat, FRF_AB_SF_PRST) ? |
| 1354 | FFE_AB_SPI_DEVICE_FLASH : FFE_AB_SPI_DEVICE_EEPROM); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1355 | netif_dbg(efx, probe, efx->net_dev, "Booted from %s\n", |
| 1356 | boot_dev == FFE_AB_SPI_DEVICE_FLASH ? |
| 1357 | "flash" : "EEPROM"); |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1358 | } else { |
| 1359 | /* Disable VPD and set clock dividers to safe |
| 1360 | * values for initial programming. */ |
| 1361 | boot_dev = -1; |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1362 | netif_dbg(efx, probe, efx->net_dev, |
| 1363 | "Booted from internal ASIC settings;" |
| 1364 | " setting SPI config\n"); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1365 | 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] | 1366 | /* 125 MHz / 7 ~= 20 MHz */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1367 | FRF_AB_EE_SF_CLOCK_DIV, 7, |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1368 | /* 125 MHz / 63 ~= 2 MHz */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1369 | FRF_AB_EE_EE_CLOCK_DIV, 63); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1370 | efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1371 | } |
| 1372 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1373 | mutex_init(&nic_data->spi_lock); |
| 1374 | |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1375 | if (boot_dev == FFE_AB_SPI_DEVICE_FLASH) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1376 | falcon_spi_device_init(efx, &nic_data->spi_flash, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1377 | FFE_AB_SPI_DEVICE_FLASH, |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1378 | default_flash_type); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1379 | if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM) |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1380 | falcon_spi_device_init(efx, &nic_data->spi_eeprom, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1381 | FFE_AB_SPI_DEVICE_EEPROM, |
Ben Hutchings | 2f7f573 | 2008-12-12 21:34:25 -0800 | [diff] [blame] | 1382 | large_eeprom_type); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1383 | } |
| 1384 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1385 | static int falcon_probe_nic(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1386 | { |
| 1387 | struct falcon_nic_data *nic_data; |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 1388 | struct falcon_board *board; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1389 | int rc; |
| 1390 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1391 | /* Allocate storage for hardware specific data */ |
| 1392 | nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); |
Ben Hutchings | 88c5942 | 2008-09-03 15:07:50 +0100 | [diff] [blame] | 1393 | if (!nic_data) |
| 1394 | return -ENOMEM; |
Ben Hutchings | 5daab96 | 2008-05-16 21:19:43 +0100 | [diff] [blame] | 1395 | efx->nic_data = nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1396 | |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 1397 | rc = -ENODEV; |
| 1398 | |
| 1399 | if (efx_nic_fpga_ver(efx) != 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1400 | netif_err(efx, probe, efx->net_dev, |
| 1401 | "Falcon FPGA not supported\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1402 | goto fail1; |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 1403 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1404 | |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 1405 | if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) { |
| 1406 | efx_oword_t nic_stat; |
| 1407 | struct pci_dev *dev; |
| 1408 | u8 pci_rev = efx->pci_dev->revision; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1409 | |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 1410 | if ((pci_rev == 0xff) || (pci_rev == 0)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1411 | netif_err(efx, probe, efx->net_dev, |
| 1412 | "Falcon rev A0 not supported\n"); |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 1413 | goto fail1; |
| 1414 | } |
| 1415 | efx_reado(efx, &nic_stat, FR_AB_NIC_STAT); |
| 1416 | if (EFX_OWORD_FIELD(nic_stat, FRF_AB_STRAP_10G) == 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1417 | netif_err(efx, probe, efx->net_dev, |
| 1418 | "Falcon rev A1 1G not supported\n"); |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 1419 | goto fail1; |
| 1420 | } |
| 1421 | if (EFX_OWORD_FIELD(nic_stat, FRF_AA_STRAP_PCIE) == 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1422 | netif_err(efx, probe, efx->net_dev, |
| 1423 | "Falcon rev A1 PCI-X not supported\n"); |
Ben Hutchings | 5784946 | 2009-11-29 15:08:21 +0000 | [diff] [blame] | 1424 | goto fail1; |
| 1425 | } |
| 1426 | |
| 1427 | dev = pci_dev_get(efx->pci_dev); |
Linus Torvalds | 0e59e7e | 2011-10-28 14:20:44 -0700 | [diff] [blame] | 1428 | while ((dev = pci_get_device(PCI_VENDOR_ID_SOLARFLARE, |
| 1429 | PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1430 | dev))) { |
| 1431 | if (dev->bus == efx->pci_dev->bus && |
| 1432 | dev->devfn == efx->pci_dev->devfn + 1) { |
| 1433 | nic_data->pci_dev2 = dev; |
| 1434 | break; |
| 1435 | } |
| 1436 | } |
| 1437 | if (!nic_data->pci_dev2) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1438 | netif_err(efx, probe, efx->net_dev, |
| 1439 | "failed to find secondary function\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1440 | rc = -ENODEV; |
| 1441 | goto fail2; |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | /* Now we can reset the NIC */ |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1446 | rc = __falcon_reset_hw(efx, RESET_TYPE_ALL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1447 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1448 | netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1449 | goto fail3; |
| 1450 | } |
| 1451 | |
| 1452 | /* Allocate memory for INT_KER */ |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1453 | rc = efx_nic_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1454 | if (rc) |
| 1455 | goto fail4; |
| 1456 | BUG_ON(efx->irq_status.dma_addr & 0x0f); |
| 1457 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1458 | netif_dbg(efx, probe, efx->net_dev, |
| 1459 | "INT_KER at %llx (virt %p phys %llx)\n", |
| 1460 | (u64)efx->irq_status.dma_addr, |
| 1461 | efx->irq_status.addr, |
| 1462 | (u64)virt_to_phys(efx->irq_status.addr)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1463 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 1464 | falcon_probe_spi_devices(efx); |
| 1465 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1466 | /* Read in the non-volatile configuration */ |
| 1467 | rc = falcon_probe_nvconfig(efx); |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1468 | if (rc) { |
| 1469 | if (rc == -EINVAL) |
| 1470 | netif_err(efx, probe, efx->net_dev, "NVRAM is invalid\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1471 | goto fail5; |
Ben Hutchings | 6c88b0b | 2010-12-02 13:47:01 +0000 | [diff] [blame] | 1472 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1473 | |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 1474 | /* Initialise I2C adapter */ |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 1475 | board = falcon_board(efx); |
| 1476 | board->i2c_adap.owner = THIS_MODULE; |
| 1477 | board->i2c_data = falcon_i2c_bit_operations; |
| 1478 | board->i2c_data.data = efx; |
| 1479 | board->i2c_adap.algo_data = &board->i2c_data; |
| 1480 | board->i2c_adap.dev.parent = &efx->pci_dev->dev; |
| 1481 | strlcpy(board->i2c_adap.name, "SFC4000 GPIO", |
| 1482 | sizeof(board->i2c_adap.name)); |
| 1483 | rc = i2c_bit_add_bus(&board->i2c_adap); |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 1484 | if (rc) |
| 1485 | goto fail5; |
| 1486 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 1487 | rc = falcon_board(efx)->type->init(efx); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 1488 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1489 | netif_err(efx, probe, efx->net_dev, |
| 1490 | "failed to initialise board\n"); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 1491 | goto fail6; |
| 1492 | } |
| 1493 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1494 | nic_data->stats_disable_count = 1; |
| 1495 | setup_timer(&nic_data->stats_timer, &falcon_stats_timer_func, |
| 1496 | (unsigned long)efx); |
| 1497 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1498 | return 0; |
| 1499 | |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 1500 | fail6: |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 1501 | BUG_ON(i2c_del_adapter(&board->i2c_adap)); |
| 1502 | memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1503 | fail5: |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1504 | efx_nic_free_buffer(efx, &efx->irq_status); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1505 | fail4: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1506 | fail3: |
| 1507 | if (nic_data->pci_dev2) { |
| 1508 | pci_dev_put(nic_data->pci_dev2); |
| 1509 | nic_data->pci_dev2 = NULL; |
| 1510 | } |
| 1511 | fail2: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1512 | fail1: |
| 1513 | kfree(efx->nic_data); |
| 1514 | return rc; |
| 1515 | } |
| 1516 | |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 1517 | static void falcon_init_rx_cfg(struct efx_nic *efx) |
| 1518 | { |
| 1519 | /* Prior to Siena the RX DMA engine will split each frame at |
| 1520 | * intervals of RX_USR_BUF_SIZE (32-byte units). We set it to |
| 1521 | * be so large that that never happens. */ |
| 1522 | const unsigned huge_buf_size = (3 * 4096) >> 5; |
| 1523 | /* RX control FIFO thresholds (32 entries) */ |
| 1524 | const unsigned ctrl_xon_thr = 20; |
| 1525 | const unsigned ctrl_xoff_thr = 25; |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 1526 | efx_oword_t reg; |
| 1527 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1528 | efx_reado(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1529 | if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1) { |
Ben Hutchings | 625b451 | 2009-10-23 08:30:17 +0000 | [diff] [blame] | 1530 | /* Data FIFO size is 5.5K */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1531 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_DESC_PUSH_EN, 0); |
| 1532 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_USR_BUF_SIZE, |
| 1533 | huge_buf_size); |
Ben Hutchings | 5fb6b06 | 2011-02-24 19:30:41 +0000 | [diff] [blame] | 1534 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_MAC_TH, 512 >> 8); |
| 1535 | 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] | 1536 | EFX_SET_OWORD_FIELD(reg, FRF_AA_RX_XON_TX_TH, ctrl_xon_thr); |
| 1537 | 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] | 1538 | } else { |
Ben Hutchings | 625b451 | 2009-10-23 08:30:17 +0000 | [diff] [blame] | 1539 | /* Data FIFO size is 80K; register fields moved */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1540 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_DESC_PUSH_EN, 0); |
| 1541 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_USR_BUF_SIZE, |
| 1542 | huge_buf_size); |
Ben Hutchings | 5fb6b06 | 2011-02-24 19:30:41 +0000 | [diff] [blame] | 1543 | /* Send XON and XOFF at ~3 * max MTU away from empty/full */ |
| 1544 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_MAC_TH, 27648 >> 8); |
| 1545 | 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] | 1546 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XON_TX_TH, ctrl_xon_thr); |
| 1547 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_XOFF_TX_TH, ctrl_xoff_thr); |
| 1548 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_INGR_EN, 1); |
Ben Hutchings | 477e54e | 2010-06-25 07:05:56 +0000 | [diff] [blame] | 1549 | |
| 1550 | /* Enable hash insertion. This is broken for the |
| 1551 | * 'Falcon' hash so also select Toeplitz TCP/IPv4 and |
| 1552 | * IPv4 hashes. */ |
| 1553 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_INSRT_HDR, 1); |
| 1554 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_HASH_ALG, 1); |
| 1555 | EFX_SET_OWORD_FIELD(reg, FRF_BZ_RX_IP_HASH, 1); |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 1556 | } |
Ben Hutchings | 4b0d29d | 2009-11-29 03:42:18 +0000 | [diff] [blame] | 1557 | /* Always enable XOFF signal from RX FIFO. We enable |
| 1558 | * or disable transmission of pause frames at the MAC. */ |
| 1559 | EFX_SET_OWORD_FIELD(reg, FRF_AZ_RX_XOFF_MAC_EN, 1); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1560 | efx_writeo(efx, ®, FR_AZ_RX_CFG); |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1563 | /* This call performs hardware-specific global initialisation, such as |
| 1564 | * defining the descriptor cache sizes and number of RSS channels. |
| 1565 | * It does not set up any buffers, descriptor rings or event queues. |
| 1566 | */ |
| 1567 | static int falcon_init_nic(struct efx_nic *efx) |
| 1568 | { |
| 1569 | efx_oword_t temp; |
| 1570 | int rc; |
| 1571 | |
| 1572 | /* Use on-chip SRAM */ |
| 1573 | efx_reado(efx, &temp, FR_AB_NIC_STAT); |
| 1574 | EFX_SET_OWORD_FIELD(temp, FRF_AB_ONCHIP_SRAM, 1); |
| 1575 | efx_writeo(efx, &temp, FR_AB_NIC_STAT); |
| 1576 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1577 | rc = falcon_reset_sram(efx); |
| 1578 | if (rc) |
| 1579 | return rc; |
| 1580 | |
| 1581 | /* Clear the parity enables on the TX data fifos as |
| 1582 | * they produce false parity errors because of timing issues |
| 1583 | */ |
| 1584 | if (EFX_WORKAROUND_5129(efx)) { |
| 1585 | efx_reado(efx, &temp, FR_AZ_CSR_SPARE); |
| 1586 | EFX_SET_OWORD_FIELD(temp, FRF_AB_MEM_PERR_EN_TX_DATA, 0); |
| 1587 | efx_writeo(efx, &temp, FR_AZ_CSR_SPARE); |
| 1588 | } |
| 1589 | |
| 1590 | if (EFX_WORKAROUND_7244(efx)) { |
| 1591 | efx_reado(efx, &temp, FR_BZ_RX_FILTER_CTL); |
| 1592 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_FULL_SRCH_LIMIT, 8); |
| 1593 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_UDP_WILD_SRCH_LIMIT, 8); |
| 1594 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_FULL_SRCH_LIMIT, 8); |
| 1595 | EFX_SET_OWORD_FIELD(temp, FRF_BZ_TCP_WILD_SRCH_LIMIT, 8); |
| 1596 | efx_writeo(efx, &temp, FR_BZ_RX_FILTER_CTL); |
| 1597 | } |
| 1598 | |
| 1599 | /* XXX This is documented only for Falcon A0/A1 */ |
| 1600 | /* Setup RX. Wait for descriptor is broken and must |
| 1601 | * be disabled. RXDP recovery shouldn't be needed, but is. |
| 1602 | */ |
| 1603 | efx_reado(efx, &temp, FR_AA_RX_SELF_RST); |
| 1604 | EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_NODESC_WAIT_DIS, 1); |
| 1605 | EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_SELF_RST_EN, 1); |
| 1606 | if (EFX_WORKAROUND_5583(efx)) |
| 1607 | EFX_SET_OWORD_FIELD(temp, FRF_AA_RX_ISCSI_DIS, 1); |
| 1608 | efx_writeo(efx, &temp, FR_AA_RX_SELF_RST); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1609 | |
| 1610 | /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16 |
| 1611 | * descriptors (which is bad). |
| 1612 | */ |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1613 | efx_reado(efx, &temp, FR_AZ_TX_CFG); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1614 | 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] | 1615 | efx_writeo(efx, &temp, FR_AZ_TX_CFG); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1616 | |
Ben Hutchings | 56241ce | 2009-10-23 08:30:06 +0000 | [diff] [blame] | 1617 | falcon_init_rx_cfg(efx); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1618 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1619 | if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) { |
Ben Hutchings | 477e54e | 2010-06-25 07:05:56 +0000 | [diff] [blame] | 1620 | /* Set hash key for IPv4 */ |
| 1621 | memcpy(&temp, efx->rx_hash_key, sizeof(temp)); |
| 1622 | efx_writeo(efx, &temp, FR_BZ_RX_RSS_TKEY); |
| 1623 | |
| 1624 | /* Set destination of both TX and RX Flush events */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1625 | EFX_POPULATE_OWORD_1(temp, FRF_BZ_FLS_EVQ_ID, 0); |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1626 | efx_writeo(efx, &temp, FR_BZ_DP_CTRL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1627 | } |
| 1628 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1629 | efx_nic_init_common(efx); |
| 1630 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1631 | return 0; |
| 1632 | } |
| 1633 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1634 | static void falcon_remove_nic(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1635 | { |
| 1636 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 1637 | struct falcon_board *board = falcon_board(efx); |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 1638 | int rc; |
| 1639 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 1640 | board->type->fini(efx); |
Ben Hutchings | 278c062 | 2009-11-23 16:05:12 +0000 | [diff] [blame] | 1641 | |
Ben Hutchings | 8c87037 | 2009-03-04 09:53:02 +0000 | [diff] [blame] | 1642 | /* Remove I2C adapter and clear it in preparation for a retry */ |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 1643 | rc = i2c_del_adapter(&board->i2c_adap); |
Ben Hutchings | 37b5a60 | 2008-05-30 22:27:04 +0100 | [diff] [blame] | 1644 | BUG_ON(rc); |
Ben Hutchings | e775fb9 | 2009-11-23 16:06:02 +0000 | [diff] [blame] | 1645 | memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1646 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 1647 | efx_nic_free_buffer(efx, &efx->irq_status); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1648 | |
Ben Hutchings | 4de9218 | 2010-12-02 13:47:29 +0000 | [diff] [blame] | 1649 | __falcon_reset_hw(efx, RESET_TYPE_ALL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1650 | |
| 1651 | /* Release the second function after the reset */ |
| 1652 | if (nic_data->pci_dev2) { |
| 1653 | pci_dev_put(nic_data->pci_dev2); |
| 1654 | nic_data->pci_dev2 = NULL; |
| 1655 | } |
| 1656 | |
| 1657 | /* Tear down the private nic state */ |
| 1658 | kfree(efx->nic_data); |
| 1659 | efx->nic_data = NULL; |
| 1660 | } |
| 1661 | |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1662 | static void falcon_update_nic_stats(struct efx_nic *efx) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1663 | { |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1664 | struct falcon_nic_data *nic_data = efx->nic_data; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1665 | efx_oword_t cnt; |
| 1666 | |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1667 | if (nic_data->stats_disable_count) |
| 1668 | return; |
| 1669 | |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 1670 | efx_reado(efx, &cnt, FR_AZ_RX_NODESC_DROP); |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1671 | efx->n_rx_nodesc_drop_cnt += |
| 1672 | EFX_OWORD_FIELD(cnt, FRF_AB_RX_NODESC_DROP_CNT); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1673 | |
| 1674 | if (nic_data->stats_pending && |
| 1675 | *nic_data->stats_dma_done == FALCON_STATS_DONE) { |
| 1676 | nic_data->stats_pending = false; |
| 1677 | rmb(); /* read the done flag before the stats */ |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1678 | falcon_update_stats_xmac(efx); |
Ben Hutchings | 55edc6e | 2009-11-25 16:11:35 +0000 | [diff] [blame] | 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | void falcon_start_nic_stats(struct efx_nic *efx) |
| 1683 | { |
| 1684 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1685 | |
| 1686 | spin_lock_bh(&efx->stats_lock); |
| 1687 | if (--nic_data->stats_disable_count == 0) |
| 1688 | falcon_stats_request(efx); |
| 1689 | spin_unlock_bh(&efx->stats_lock); |
| 1690 | } |
| 1691 | |
| 1692 | void falcon_stop_nic_stats(struct efx_nic *efx) |
| 1693 | { |
| 1694 | struct falcon_nic_data *nic_data = efx->nic_data; |
| 1695 | int i; |
| 1696 | |
| 1697 | might_sleep(); |
| 1698 | |
| 1699 | spin_lock_bh(&efx->stats_lock); |
| 1700 | ++nic_data->stats_disable_count; |
| 1701 | spin_unlock_bh(&efx->stats_lock); |
| 1702 | |
| 1703 | del_timer_sync(&nic_data->stats_timer); |
| 1704 | |
| 1705 | /* Wait enough time for the most recent transfer to |
| 1706 | * complete. */ |
| 1707 | for (i = 0; i < 4 && nic_data->stats_pending; i++) { |
| 1708 | if (*nic_data->stats_dma_done == FALCON_STATS_DONE) |
| 1709 | break; |
| 1710 | msleep(1); |
| 1711 | } |
| 1712 | |
| 1713 | spin_lock_bh(&efx->stats_lock); |
| 1714 | falcon_stats_complete(efx); |
| 1715 | spin_unlock_bh(&efx->stats_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1716 | } |
| 1717 | |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 1718 | static void falcon_set_id_led(struct efx_nic *efx, enum efx_led_mode mode) |
| 1719 | { |
| 1720 | falcon_board(efx)->type->set_id_led(efx, mode); |
| 1721 | } |
| 1722 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1723 | /************************************************************************** |
| 1724 | * |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 1725 | * Wake on LAN |
| 1726 | * |
| 1727 | ************************************************************************** |
| 1728 | */ |
| 1729 | |
| 1730 | static void falcon_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol) |
| 1731 | { |
| 1732 | wol->supported = 0; |
| 1733 | wol->wolopts = 0; |
| 1734 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 1735 | } |
| 1736 | |
| 1737 | static int falcon_set_wol(struct efx_nic *efx, u32 type) |
| 1738 | { |
| 1739 | if (type != 0) |
| 1740 | return -EINVAL; |
| 1741 | return 0; |
| 1742 | } |
| 1743 | |
| 1744 | /************************************************************************** |
| 1745 | * |
Ben Hutchings | 754c653 | 2010-02-03 09:31:57 +0000 | [diff] [blame] | 1746 | * Revision-dependent attributes used by efx.c and nic.c |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1747 | * |
| 1748 | ************************************************************************** |
| 1749 | */ |
| 1750 | |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 1751 | const struct efx_nic_type falcon_a1_nic_type = { |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1752 | .probe = falcon_probe_nic, |
| 1753 | .remove = falcon_remove_nic, |
| 1754 | .init = falcon_init_nic, |
| 1755 | .fini = efx_port_dummy_op_void, |
| 1756 | .monitor = falcon_monitor, |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 1757 | .map_reset_reason = falcon_map_reset_reason, |
| 1758 | .map_reset_flags = falcon_map_reset_flags, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1759 | .reset = falcon_reset_hw, |
| 1760 | .probe_port = falcon_probe_port, |
| 1761 | .remove_port = falcon_remove_port, |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 1762 | .handle_global_event = falcon_handle_global_event, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1763 | .prepare_flush = falcon_prepare_flush, |
| 1764 | .update_stats = falcon_update_nic_stats, |
| 1765 | .start_stats = falcon_start_nic_stats, |
| 1766 | .stop_stats = falcon_stop_nic_stats, |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 1767 | .set_id_led = falcon_set_id_led, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1768 | .push_irq_moderation = falcon_push_irq_moderation, |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1769 | .reconfigure_port = falcon_reconfigure_port, |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1770 | .reconfigure_mac = falcon_reconfigure_xmac, |
| 1771 | .check_mac_fault = falcon_xmac_check_fault, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 1772 | .get_wol = falcon_get_wol, |
| 1773 | .set_wol = falcon_set_wol, |
| 1774 | .resume_wol = efx_port_dummy_op_void, |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 1775 | .test_nvram = falcon_test_nvram, |
Steve Hodgson | b895d73 | 2009-11-28 05:35:00 +0000 | [diff] [blame] | 1776 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1777 | .revision = EFX_REV_FALCON_A1, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1778 | .mem_map_size = 0x20000, |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1779 | .txd_ptr_tbl_base = FR_AA_TX_DESC_PTR_TBL_KER, |
| 1780 | .rxd_ptr_tbl_base = FR_AA_RX_DESC_PTR_TBL_KER, |
| 1781 | .buf_tbl_base = FR_AA_BUF_FULL_TBL_KER, |
| 1782 | .evq_ptr_tbl_base = FR_AA_EVQ_PTR_TBL_KER, |
| 1783 | .evq_rptr_tbl_base = FR_AA_EVQ_RPTR_KER, |
Ben Hutchings | 6d51d30 | 2009-10-23 08:31:07 +0000 | [diff] [blame] | 1784 | .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] | 1785 | .rx_buffer_padding = 0x24, |
| 1786 | .max_interrupt_mode = EFX_INT_MODE_MSI, |
| 1787 | .phys_addr_channels = 4, |
Ben Hutchings | 0228f5cdb0 | 2009-11-28 05:36:12 +0000 | [diff] [blame] | 1788 | .tx_dc_base = 0x130000, |
| 1789 | .rx_dc_base = 0x100000, |
Ben Hutchings | c383b53 | 2009-11-29 15:11:02 +0000 | [diff] [blame] | 1790 | .offload_features = NETIF_F_IP_CSUM, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1791 | }; |
| 1792 | |
stephen hemminger | 6c8c251 | 2011-04-14 05:50:12 +0000 | [diff] [blame] | 1793 | const struct efx_nic_type falcon_b0_nic_type = { |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1794 | .probe = falcon_probe_nic, |
| 1795 | .remove = falcon_remove_nic, |
| 1796 | .init = falcon_init_nic, |
| 1797 | .fini = efx_port_dummy_op_void, |
| 1798 | .monitor = falcon_monitor, |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 1799 | .map_reset_reason = falcon_map_reset_reason, |
| 1800 | .map_reset_flags = falcon_map_reset_flags, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1801 | .reset = falcon_reset_hw, |
| 1802 | .probe_port = falcon_probe_port, |
| 1803 | .remove_port = falcon_remove_port, |
Ben Hutchings | 40641ed | 2010-12-02 13:47:45 +0000 | [diff] [blame] | 1804 | .handle_global_event = falcon_handle_global_event, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1805 | .prepare_flush = falcon_prepare_flush, |
| 1806 | .update_stats = falcon_update_nic_stats, |
| 1807 | .start_stats = falcon_start_nic_stats, |
| 1808 | .stop_stats = falcon_stop_nic_stats, |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 1809 | .set_id_led = falcon_set_id_led, |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 1810 | .push_irq_moderation = falcon_push_irq_moderation, |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 1811 | .reconfigure_port = falcon_reconfigure_port, |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 1812 | .reconfigure_mac = falcon_reconfigure_xmac, |
| 1813 | .check_mac_fault = falcon_xmac_check_fault, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 1814 | .get_wol = falcon_get_wol, |
| 1815 | .set_wol = falcon_set_wol, |
| 1816 | .resume_wol = efx_port_dummy_op_void, |
Ben Hutchings | 9bfc4bb | 2009-11-29 03:43:23 +0000 | [diff] [blame] | 1817 | .test_registers = falcon_b0_test_registers, |
Ben Hutchings | 0aa3fba | 2009-11-29 03:43:33 +0000 | [diff] [blame] | 1818 | .test_nvram = falcon_test_nvram, |
Steve Hodgson | b895d73 | 2009-11-28 05:35:00 +0000 | [diff] [blame] | 1819 | |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 1820 | .revision = EFX_REV_FALCON_B0, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1821 | /* Map everything up to and including the RSS indirection |
| 1822 | * table. Don't map MSI-X table, MSI-X PBA since Linux |
| 1823 | * requires that they not be mapped. */ |
Ben Hutchings | 3e6c453 | 2009-10-23 08:30:36 +0000 | [diff] [blame] | 1824 | .mem_map_size = (FR_BZ_RX_INDIRECTION_TBL + |
| 1825 | FR_BZ_RX_INDIRECTION_TBL_STEP * |
| 1826 | FR_BZ_RX_INDIRECTION_TBL_ROWS), |
| 1827 | .txd_ptr_tbl_base = FR_BZ_TX_DESC_PTR_TBL, |
| 1828 | .rxd_ptr_tbl_base = FR_BZ_RX_DESC_PTR_TBL, |
| 1829 | .buf_tbl_base = FR_BZ_BUF_FULL_TBL, |
| 1830 | .evq_ptr_tbl_base = FR_BZ_EVQ_PTR_TBL, |
| 1831 | .evq_rptr_tbl_base = FR_BZ_EVQ_RPTR, |
Ben Hutchings | 6d51d30 | 2009-10-23 08:31:07 +0000 | [diff] [blame] | 1832 | .max_dma_mask = DMA_BIT_MASK(FSF_AZ_TX_KER_BUF_ADDR_WIDTH), |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 1833 | .rx_buffer_hash_size = 0x10, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1834 | .rx_buffer_padding = 0, |
| 1835 | .max_interrupt_mode = EFX_INT_MODE_MSIX, |
| 1836 | .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy |
| 1837 | * interrupt handler only supports 32 |
| 1838 | * channels */ |
Ben Hutchings | 0228f5cdb0 | 2009-11-28 05:36:12 +0000 | [diff] [blame] | 1839 | .tx_dc_base = 0x130000, |
| 1840 | .rx_dc_base = 0x100000, |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1841 | .offload_features = NETIF_F_IP_CSUM | NETIF_F_RXHASH | NETIF_F_NTUPLE, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1842 | }; |
| 1843 | |