11 #include <linux/bitops.h>
13 #include <linux/pci.h>
14 #include <linux/module.h>
16 #include <linux/i2c.h>
17 #include <linux/mii.h>
18 #include <linux/slab.h>
34 static const unsigned int
56 static void falcon_setsda(
void *
data,
int state)
66 static void falcon_setscl(
void *
data,
int state)
76 static int falcon_getsda(
void *
data)
85 static int falcon_getscl(
void *
data)
95 .setsda = falcon_setsda,
96 .setscl = falcon_setscl,
97 .getsda = falcon_getsda,
98 .getscl = falcon_getscl,
112 FRF_AB_TC_TIMER_MODE,
118 FRF_AB_TC_TIMER_MODE,
120 FRF_AB_TC_TIMER_VAL, 0);
127 static void falcon_deconfigure_mac_wrapper(
struct efx_nic *efx);
129 static void falcon_prepare_flush(
struct efx_nic *efx)
131 falcon_deconfigure_mac_wrapper(efx);
171 "IRQ %d on CPU %d not for me\n", irq,
195 efx_schedule_channel_irq(efx_get_channel(efx, 0));
197 efx_schedule_channel_irq(efx_get_channel(efx, 1));
207 #define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
209 static int falcon_spi_poll(
struct efx_nic *efx)
217 static int falcon_spi_wait(
struct efx_nic *efx)
226 for (i = 0; i < 10; i++) {
227 if (!falcon_spi_poll(efx))
233 if (!falcon_spi_poll(efx))
237 "timed out waiting for SPI\n");
246 const void *
in,
void *
out,
size_t len)
248 bool addressed = (address >= 0);
258 rc = falcon_spi_poll(efx);
276 FRF_AB_EE_SPI_HCMD_CMD_EN, 1,
277 FRF_AB_EE_SPI_HCMD_SF_SEL, spi->
device_id,
278 FRF_AB_EE_SPI_HCMD_DABCNT, len,
279 FRF_AB_EE_SPI_HCMD_READ, reading,
280 FRF_AB_EE_SPI_HCMD_DUBCNT, 0,
281 FRF_AB_EE_SPI_HCMD_ADBCNT,
283 FRF_AB_EE_SPI_HCMD_ENC, command);
287 rc = falcon_spi_wait(efx);
311 return command | (((address >> 8) & spi->
munge_address) << 3);
324 &status,
sizeof(status));
331 "SPI write timeout on device %d"
332 " last status=0x%02x\n",
341 loff_t start,
size_t len,
size_t *retlen,
u8 *
buffer)
343 size_t block_len,
pos = 0;
350 command = efx_spi_munge_command(spi,
SPI_READ, start + pos);
352 buffer + pos, block_len);
372 loff_t start,
size_t len,
size_t *retlen,
const u8 *
buffer)
375 size_t block_len,
pos = 0;
384 block_len =
min(len - pos,
385 falcon_spi_write_limit(spi, start + pos));
386 command = efx_spi_munge_command(spi,
SPI_WRITE, start + pos);
388 buffer + pos,
NULL, block_len);
396 command = efx_spi_munge_command(spi,
SPI_READ, start + pos);
398 NULL, verify_buffer, block_len);
399 if (
memcmp(verify_buffer, buffer + pos, block_len)) {
426 static void falcon_push_multicast_hash(
struct efx_nic *efx)
436 static void falcon_reset_macs(
struct efx_nic *efx)
449 for (count = 0; count < 10000; count++) {
458 "timed out waiting for XMAC core reset\n");
481 "Completed MAC reset after %d loops\n",
513 falcon_reset_macs(efx);
516 static void falcon_deconfigure_mac_wrapper(
struct efx_nic *efx)
540 switch (link_state->
speed) {
541 case 10000: link_speed = 3;
break;
542 case 1000: link_speed = 2;
break;
543 case 100: link_speed = 1;
break;
544 default: link_speed = 0;
break;
551 FRF_AB_MAC_XOFF_VAL, 0xffff ,
552 FRF_AB_MAC_BCAD_ACPT, 1,
554 FRF_AB_MAC_LINK_STATUS, 1,
555 FRF_AB_MAC_SPEED, link_speed);
560 !link_state->
up || isolate);
566 falcon_push_multicast_hash(efx);
578 static void falcon_stats_request(
struct efx_nic *efx)
595 FRF_AB_MAC_STAT_DMA_CMD, 1,
596 FRF_AB_MAC_STAT_DMA_ADR,
603 static void falcon_stats_complete(
struct efx_nic *efx)
616 "timed out waiting for statistics\n");
620 static void falcon_stats_timer_func(
unsigned long context)
627 falcon_stats_complete(efx);
629 falcon_stats_request(efx);
634 static bool falcon_loopback_link_poll(
struct efx_nic *efx)
646 return !efx_link_state_equal(&efx->
link_state, &old_state);
649 static int falcon_reconfigure_port(
struct efx_nic *efx)
660 falcon_loopback_link_poll(efx);
665 falcon_deconfigure_mac_wrapper(efx);
667 falcon_reset_macs(efx);
669 efx->
phy_op->reconfigure(efx);
689 static int falcon_gmii_wait(
struct efx_nic *efx)
695 for (count = 0; count < 5000; count++) {
701 "error from GMII access "
715 static int falcon_mdio_write(
struct net_device *net_dev,
718 struct efx_nic *efx = netdev_priv(net_dev);
724 "writing MDIO %d register %d.%d with 0x%04x\n",
725 prtad, devad, addr, value);
730 rc = falcon_gmii_wait(efx);
739 FRF_AB_MD_DEV_ADR, devad);
752 rc = falcon_gmii_wait(efx);
768 static int falcon_mdio_read(
struct net_device *net_dev,
769 int prtad,
int devad,
u16 addr)
771 struct efx_nic *efx = netdev_priv(net_dev);
779 rc = falcon_gmii_wait(efx);
787 FRF_AB_MD_DEV_ADR, devad);
795 rc = falcon_gmii_wait(efx);
800 "read from MDIO %d register %d.%d, got %04x\n",
801 prtad, devad, addr, rc);
810 "read from MDIO %d register %d.%d, got error %d\n",
811 prtad, devad, addr, rc);
820 static int falcon_probe_port(
struct efx_nic *efx)
844 efx->
mdio.mdio_read = falcon_mdio_read;
845 efx->
mdio.mdio_write = falcon_mdio_write;
846 rc = efx->
phy_op->probe(efx);
868 "stats buffer at %llx (virt %p phys %llx)\n",
877 static void falcon_remove_port(
struct efx_nic *efx)
906 "channel %d seen global RX_RESET event. Resetting.\n",
931 int rc, magic_num, struct_ver;
935 if (efx_spi_present(&nic_data->
spi_flash))
937 else if (efx_spi_present(&nic_data->
spi_eeprom))
964 "NVRAM bad magic 0x%x\n", magic_num);
967 if (struct_ver < 2) {
969 "NVRAM has ancient version 0x%x\n", struct_ver);
971 }
else if (struct_ver < 4) {
973 limit = (
__le16 *) (nvconfig + 1);
981 if (~csum & 0xffff) {
983 "NVRAM has incorrect checksum\n");
989 memcpy(nvconfig_out, nvconfig,
sizeof(*nvconfig));
996 static int falcon_test_nvram(
struct efx_nic *efx)
998 return falcon_read_nvram(efx,
NULL);
1003 EFX_OWORD32(0x0003FFFF, 0x0003FFFF, 0x0003FFFF, 0x0003FFFF) },
1005 EFX_OWORD32(0xFFFFFFFE, 0x00017FFF, 0x00000000, 0x00000000) },
1007 EFX_OWORD32(0x7FFF0037, 0x00000000, 0x00000000, 0x00000000) },
1009 EFX_OWORD32(0xFFFEFE80, 0x1FFFFFFF, 0x020000FE, 0x007FFFFF) },
1011 EFX_OWORD32(0xFFFF0000, 0x00000000, 0x00000000, 0x00000000) },
1013 EFX_OWORD32(0x001FFFFF, 0x00000000, 0x00000000, 0x00000000) },
1015 EFX_OWORD32(0x0000000F, 0x00000000, 0x00000000, 0x00000000) },
1017 EFX_OWORD32(0x000003FF, 0x00000000, 0x00000000, 0x00000000) },
1019 EFX_OWORD32(0x00000FFF, 0x00000000, 0x00000000, 0x00000000) },
1021 EFX_OWORD32(0x00007337, 0x00000000, 0x00000000, 0x00000000) },
1023 EFX_OWORD32(0x00001F1F, 0x00000000, 0x00000000, 0x00000000) },
1025 EFX_OWORD32(0x00000C68, 0x00000000, 0x00000000, 0x00000000) },
1027 EFX_OWORD32(0x00080164, 0x00000000, 0x00000000, 0x00000000) },
1029 EFX_OWORD32(0x07100A0C, 0x00000000, 0x00000000, 0x00000000) },
1031 EFX_OWORD32(0x00001FF8, 0x00000000, 0x00000000, 0x00000000) },
1033 EFX_OWORD32(0xFFFF0001, 0x00000000, 0x00000000, 0x00000000) },
1035 EFX_OWORD32(0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000) },
1037 EFX_OWORD32(0x0003FF0F, 0x00000000, 0x00000000, 0x00000000) },
1065 rc = falcon_reset_hw(efx, reset_method);
1067 return rc ? rc : rc2;
1093 static int falcon_map_reset_flags(
u32 *
flags)
1102 if ((*flags & FALCON_RESET_WORLD) == FALCON_RESET_WORLD) {
1103 *flags &= ~FALCON_RESET_WORLD;
1107 if ((*flags & FALCON_RESET_ALL) == FALCON_RESET_ALL) {
1108 *flags &= ~FALCON_RESET_ALL;
1112 if ((*flags & FALCON_RESET_INVISIBLE) == FALCON_RESET_INVISIBLE) {
1113 *flags &= ~FALCON_RESET_INVISIBLE;
1136 "failed to backup PCI state of primary "
1137 "function prior to hardware reset\n");
1140 if (efx_nic_is_dual_func(efx)) {
1144 "failed to backup PCI state of "
1145 "secondary function prior to "
1146 "hardware reset\n");
1152 FRF_AB_EXT_PHY_RST_DUR,
1158 FRF_AB_EXT_PHY_RST_CTL,
1161 FRF_AB_PCIE_CORE_RST_CTL, 1,
1162 FRF_AB_PCIE_NSTKY_RST_CTL, 1,
1163 FRF_AB_PCIE_SD_RST_CTL, 1,
1164 FRF_AB_EE_RST_CTL, 1,
1165 FRF_AB_EXT_PHY_RST_DUR,
1176 if (efx_nic_is_dual_func(efx))
1180 "successfully restored PCI config\n");
1188 "timed out waiting for hardware reset\n");
1209 rc = __falcon_reset_hw(efx, method);
1215 static void falcon_monitor(
struct efx_nic *efx)
1225 "Board sensor %s; shutting down PHY\n",
1226 (rc == -
ERANGE) ?
"reported fault" :
"failed");
1233 link_changed = falcon_loopback_link_poll(efx);
1235 link_changed = efx->
phy_op->poll(efx);
1239 falcon_deconfigure_mac_wrapper(efx);
1241 falcon_reset_macs(efx);
1256 static int falcon_reset_sram(
struct efx_nic *efx)
1269 FRF_AZ_SRM_INIT_EN, 1,
1270 FRF_AZ_SRM_NB_SZ, 0);
1277 "waiting for SRAM reset (attempt %d)...\n", count);
1286 "SRAM reset complete\n");
1290 }
while (++count < 20);
1296 static void falcon_spi_device_init(
struct efx_nic *efx,
1300 if (device_type != 0) {
1312 SPI_DEV_TYPE_ERASE_SIZE);
1315 SPI_DEV_TYPE_BLOCK_SIZE);
1317 spi_device->
size = 0;
1322 static int falcon_probe_nvconfig(
struct efx_nic *efx)
1332 rc = falcon_read_nvram(efx, nvconfig);
1340 falcon_spi_device_init(
1344 falcon_spi_device_init(
1363 static void falcon_dimension_resources(
struct efx_nic *efx)
1370 static void falcon_probe_spi_devices(
struct efx_nic *efx)
1385 "flash" :
"EEPROM");
1391 "Booted from internal ASIC settings;"
1392 " setting SPI config\n");
1395 FRF_AB_EE_SF_CLOCK_DIV, 7,
1397 FRF_AB_EE_EE_CLOCK_DIV, 63);
1404 falcon_spi_device_init(efx, &nic_data->
spi_flash,
1406 default_flash_type);
1408 falcon_spi_device_init(efx, &nic_data->
spi_eeprom,
1413 static int falcon_probe_nic(
struct efx_nic *efx)
1420 nic_data = kzalloc(
sizeof(*nic_data),
GFP_KERNEL);
1429 "Falcon FPGA not supported\n");
1438 if ((pci_rev == 0xff) || (pci_rev == 0)) {
1440 "Falcon rev A0 not supported\n");
1446 "Falcon rev A1 1G not supported\n");
1451 "Falcon rev A1 PCI-X not supported\n");
1467 "failed to find secondary function\n");
1487 "INT_KER at %llx (virt %p phys %llx)\n",
1492 falcon_probe_spi_devices(efx);
1495 rc = falcon_probe_nvconfig(efx);
1507 board->
i2c_data = falcon_i2c_bit_operations;
1520 "failed to initialise board\n");
1526 (
unsigned long)efx);
1547 static void falcon_init_rx_cfg(
struct efx_nic *efx)
1552 const unsigned huge_buf_size = (3 * 4096) >> 5;
1554 const unsigned ctrl_xon_thr = 20;
1555 const unsigned ctrl_xoff_thr = 25;
1597 static int falcon_init_nic(
struct efx_nic *efx)
1607 rc = falcon_reset_sram(efx);
1647 falcon_init_rx_cfg(efx);
1664 static void falcon_remove_nic(
struct efx_nic *efx)
1670 board->
type->fini(efx);
1692 static void falcon_update_nic_stats(
struct efx_nic *efx)
1718 falcon_stats_request(efx);
1744 falcon_stats_complete(efx);
1782 .probe = falcon_probe_nic,
1783 .remove = falcon_remove_nic,
1784 .init = falcon_init_nic,
1785 .dimension_resources = falcon_dimension_resources,
1787 .monitor = falcon_monitor,
1788 .map_reset_reason = falcon_map_reset_reason,
1789 .map_reset_flags = falcon_map_reset_flags,
1790 .reset = falcon_reset_hw,
1791 .probe_port = falcon_probe_port,
1792 .remove_port = falcon_remove_port,
1793 .handle_global_event = falcon_handle_global_event,
1794 .prepare_flush = falcon_prepare_flush,
1795 .update_stats = falcon_update_nic_stats,
1798 .set_id_led = falcon_set_id_led,
1799 .push_irq_moderation = falcon_push_irq_moderation,
1800 .reconfigure_port = falcon_reconfigure_port,
1803 .get_wol = falcon_get_wol,
1804 .set_wol = falcon_set_wol,
1806 .test_nvram = falcon_test_nvram,
1809 .mem_map_size = 0x20000,
1816 .rx_buffer_padding = 0x24,
1818 .phys_addr_channels = 4,
1824 .probe = falcon_probe_nic,
1825 .remove = falcon_remove_nic,
1826 .init = falcon_init_nic,
1827 .dimension_resources = falcon_dimension_resources,
1829 .monitor = falcon_monitor,
1830 .map_reset_reason = falcon_map_reset_reason,
1831 .map_reset_flags = falcon_map_reset_flags,
1832 .reset = falcon_reset_hw,
1833 .probe_port = falcon_probe_port,
1834 .remove_port = falcon_remove_port,
1835 .handle_global_event = falcon_handle_global_event,
1836 .prepare_flush = falcon_prepare_flush,
1837 .update_stats = falcon_update_nic_stats,
1840 .set_id_led = falcon_set_id_led,
1841 .push_irq_moderation = falcon_push_irq_moderation,
1842 .reconfigure_port = falcon_reconfigure_port,
1845 .get_wol = falcon_get_wol,
1846 .set_wol = falcon_set_wol,
1848 .test_chip = falcon_b0_test_chip,
1849 .test_nvram = falcon_test_nvram,
1864 .rx_buffer_hash_size = 0x10,
1865 .rx_buffer_padding = 0,
1867 .phys_addr_channels = 32,