aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/sfc/falcon.c
diff options
context:
space:
mode:
authorBen Hutchings <bhutchings@solarflare.com>2010-12-02 08:47:29 -0500
committerDavid S. Miller <davem@davemloft.net>2010-12-03 12:08:07 -0500
commit4de92180258ac661bbce0f0065c9c81633ac862b (patch)
treebb58aecb8e7e52dd2f95daa53ab263ccd98b9374 /drivers/net/sfc/falcon.c
parent90b7a4ee610bf1d14120f5e0618ae2a3568394a5 (diff)
sfc: Move SPI state to struct falcon_nic_data
We only have direct access to SPI on Falcon, so move all this state out of struct efx_nic. Signed-off-by: Ben Hutchings <bhutchings@solarflare.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/sfc/falcon.c')
-rw-r--r--drivers/net/sfc/falcon.c91
1 files changed, 40 insertions, 51 deletions
diff --git a/drivers/net/sfc/falcon.c b/drivers/net/sfc/falcon.c
index fe150842d82b..ca59f7e02df4 100644
--- a/drivers/net/sfc/falcon.c
+++ b/drivers/net/sfc/falcon.c
@@ -254,7 +254,6 @@ int falcon_spi_cmd(struct efx_nic *efx, const struct efx_spi_device *spi,
254 /* Input validation */ 254 /* Input validation */
255 if (len > FALCON_SPI_MAX_LEN) 255 if (len > FALCON_SPI_MAX_LEN)
256 return -EINVAL; 256 return -EINVAL;
257 BUG_ON(!mutex_is_locked(&efx->spi_lock));
258 257
259 /* Check that previous command is not still running */ 258 /* Check that previous command is not still running */
260 rc = falcon_spi_poll(efx); 259 rc = falcon_spi_poll(efx);
@@ -888,6 +887,7 @@ static void falcon_remove_port(struct efx_nic *efx)
888static int 887static int
889falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out) 888falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
890{ 889{
890 struct falcon_nic_data *nic_data = efx->nic_data;
891 struct falcon_nvconfig *nvconfig; 891 struct falcon_nvconfig *nvconfig;
892 struct efx_spi_device *spi; 892 struct efx_spi_device *spi;
893 void *region; 893 void *region;
@@ -895,8 +895,11 @@ falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
895 __le16 *word, *limit; 895 __le16 *word, *limit;
896 u32 csum; 896 u32 csum;
897 897
898 spi = efx->spi_flash ? efx->spi_flash : efx->spi_eeprom; 898 if (efx_spi_present(&nic_data->spi_flash))
899 if (!spi) 899 spi = &nic_data->spi_flash;
900 else if (efx_spi_present(&nic_data->spi_eeprom))
901 spi = &nic_data->spi_eeprom;
902 else
900 return -EINVAL; 903 return -EINVAL;
901 904
902 region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL); 905 region = kmalloc(FALCON_NVCONFIG_END, GFP_KERNEL);
@@ -904,12 +907,13 @@ falcon_read_nvram(struct efx_nic *efx, struct falcon_nvconfig *nvconfig_out)
904 return -ENOMEM; 907 return -ENOMEM;
905 nvconfig = region + FALCON_NVCONFIG_OFFSET; 908 nvconfig = region + FALCON_NVCONFIG_OFFSET;
906 909
907 mutex_lock(&efx->spi_lock); 910 mutex_lock(&nic_data->spi_lock);
908 rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region); 911 rc = falcon_spi_read(efx, spi, 0, FALCON_NVCONFIG_END, NULL, region);
909 mutex_unlock(&efx->spi_lock); 912 mutex_unlock(&nic_data->spi_lock);
910 if (rc) { 913 if (rc) {
911 netif_err(efx, hw, efx->net_dev, "Failed to read %s\n", 914 netif_err(efx, hw, efx->net_dev, "Failed to read %s\n",
912 efx->spi_flash ? "flash" : "EEPROM"); 915 efx_spi_present(&nic_data->spi_flash) ?
916 "flash" : "EEPROM");
913 rc = -EIO; 917 rc = -EIO;
914 goto out; 918 goto out;
915 } 919 }
@@ -1011,7 +1015,7 @@ static int falcon_b0_test_registers(struct efx_nic *efx)
1011 1015
1012/* Resets NIC to known state. This routine must be called in process 1016/* Resets NIC to known state. This routine must be called in process
1013 * context and is allowed to sleep. */ 1017 * context and is allowed to sleep. */
1014static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method) 1018static int __falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
1015{ 1019{
1016 struct falcon_nic_data *nic_data = efx->nic_data; 1020 struct falcon_nic_data *nic_data = efx->nic_data;
1017 efx_oword_t glb_ctl_reg_ker; 1021 efx_oword_t glb_ctl_reg_ker;
@@ -1107,6 +1111,18 @@ fail5:
1107 return rc; 1111 return rc;
1108} 1112}
1109 1113
1114static int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
1115{
1116 struct falcon_nic_data *nic_data = efx->nic_data;
1117 int rc;
1118
1119 mutex_lock(&nic_data->spi_lock);
1120 rc = __falcon_reset_hw(efx, method);
1121 mutex_unlock(&nic_data->spi_lock);
1122
1123 return rc;
1124}
1125
1110static void falcon_monitor(struct efx_nic *efx) 1126static void falcon_monitor(struct efx_nic *efx)
1111{ 1127{
1112 bool link_changed; 1128 bool link_changed;
@@ -1188,16 +1204,11 @@ static int falcon_reset_sram(struct efx_nic *efx)
1188 return -ETIMEDOUT; 1204 return -ETIMEDOUT;
1189} 1205}
1190 1206
1191static int falcon_spi_device_init(struct efx_nic *efx, 1207static void falcon_spi_device_init(struct efx_nic *efx,
1192 struct efx_spi_device **spi_device_ret, 1208 struct efx_spi_device *spi_device,
1193 unsigned int device_id, u32 device_type) 1209 unsigned int device_id, u32 device_type)
1194{ 1210{
1195 struct efx_spi_device *spi_device;
1196
1197 if (device_type != 0) { 1211 if (device_type != 0) {
1198 spi_device = kzalloc(sizeof(*spi_device), GFP_KERNEL);
1199 if (!spi_device)
1200 return -ENOMEM;
1201 spi_device->device_id = device_id; 1212 spi_device->device_id = device_id;
1202 spi_device->size = 1213 spi_device->size =
1203 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE); 1214 1 << SPI_DEV_TYPE_FIELD(device_type, SPI_DEV_TYPE_SIZE);
@@ -1214,25 +1225,14 @@ static int falcon_spi_device_init(struct efx_nic *efx,
1214 1 << SPI_DEV_TYPE_FIELD(device_type, 1225 1 << SPI_DEV_TYPE_FIELD(device_type,
1215 SPI_DEV_TYPE_BLOCK_SIZE); 1226 SPI_DEV_TYPE_BLOCK_SIZE);
1216 } else { 1227 } else {
1217 spi_device = NULL; 1228 spi_device->size = 0;
1218 } 1229 }
1219
1220 kfree(*spi_device_ret);
1221 *spi_device_ret = spi_device;
1222 return 0;
1223}
1224
1225static void falcon_remove_spi_devices(struct efx_nic *efx)
1226{
1227 kfree(efx->spi_eeprom);
1228 efx->spi_eeprom = NULL;
1229 kfree(efx->spi_flash);
1230 efx->spi_flash = NULL;
1231} 1230}
1232 1231
1233/* Extract non-volatile configuration */ 1232/* Extract non-volatile configuration */
1234static int falcon_probe_nvconfig(struct efx_nic *efx) 1233static int falcon_probe_nvconfig(struct efx_nic *efx)
1235{ 1234{
1235 struct falcon_nic_data *nic_data = efx->nic_data;
1236 struct falcon_nvconfig *nvconfig; 1236 struct falcon_nvconfig *nvconfig;
1237 int rc; 1237 int rc;
1238 1238
@@ -1242,24 +1242,20 @@ static int falcon_probe_nvconfig(struct efx_nic *efx)
1242 1242
1243 rc = falcon_read_nvram(efx, nvconfig); 1243 rc = falcon_read_nvram(efx, nvconfig);
1244 if (rc) 1244 if (rc)
1245 goto fail1; 1245 goto out;
1246 1246
1247 efx->phy_type = nvconfig->board_v2.port0_phy_type; 1247 efx->phy_type = nvconfig->board_v2.port0_phy_type;
1248 efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr; 1248 efx->mdio.prtad = nvconfig->board_v2.port0_phy_addr;
1249 1249
1250 if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) { 1250 if (le16_to_cpu(nvconfig->board_struct_ver) >= 3) {
1251 rc = falcon_spi_device_init( 1251 falcon_spi_device_init(
1252 efx, &efx->spi_flash, FFE_AB_SPI_DEVICE_FLASH, 1252 efx, &nic_data->spi_flash, FFE_AB_SPI_DEVICE_FLASH,
1253 le32_to_cpu(nvconfig->board_v3 1253 le32_to_cpu(nvconfig->board_v3
1254 .spi_device_type[FFE_AB_SPI_DEVICE_FLASH])); 1254 .spi_device_type[FFE_AB_SPI_DEVICE_FLASH]));
1255 if (rc) 1255 falcon_spi_device_init(
1256 goto fail2; 1256 efx, &nic_data->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
1257 rc = falcon_spi_device_init(
1258 efx, &efx->spi_eeprom, FFE_AB_SPI_DEVICE_EEPROM,
1259 le32_to_cpu(nvconfig->board_v3 1257 le32_to_cpu(nvconfig->board_v3
1260 .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM])); 1258 .spi_device_type[FFE_AB_SPI_DEVICE_EEPROM]));
1261 if (rc)
1262 goto fail2;
1263 } 1259 }
1264 1260
1265 /* Read the MAC addresses */ 1261 /* Read the MAC addresses */
@@ -1270,15 +1266,7 @@ static int falcon_probe_nvconfig(struct efx_nic *efx)
1270 1266
1271 rc = falcon_probe_board(efx, 1267 rc = falcon_probe_board(efx,
1272 le16_to_cpu(nvconfig->board_v2.board_revision)); 1268 le16_to_cpu(nvconfig->board_v2.board_revision));
1273 if (rc) 1269out:
1274 goto fail2;
1275
1276 kfree(nvconfig);
1277 return 0;
1278
1279 fail2:
1280 falcon_remove_spi_devices(efx);
1281 fail1:
1282 kfree(nvconfig); 1270 kfree(nvconfig);
1283 return rc; 1271 return rc;
1284} 1272}
@@ -1286,6 +1274,7 @@ static int falcon_probe_nvconfig(struct efx_nic *efx)
1286/* Probe all SPI devices on the NIC */ 1274/* Probe all SPI devices on the NIC */
1287static void falcon_probe_spi_devices(struct efx_nic *efx) 1275static void falcon_probe_spi_devices(struct efx_nic *efx)
1288{ 1276{
1277 struct falcon_nic_data *nic_data = efx->nic_data;
1289 efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg; 1278 efx_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
1290 int boot_dev; 1279 int boot_dev;
1291 1280
@@ -1314,12 +1303,14 @@ static void falcon_probe_spi_devices(struct efx_nic *efx)
1314 efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0); 1303 efx_writeo(efx, &ee_vpd_cfg, FR_AB_EE_VPD_CFG0);
1315 } 1304 }
1316 1305
1306 mutex_init(&nic_data->spi_lock);
1307
1317 if (boot_dev == FFE_AB_SPI_DEVICE_FLASH) 1308 if (boot_dev == FFE_AB_SPI_DEVICE_FLASH)
1318 falcon_spi_device_init(efx, &efx->spi_flash, 1309 falcon_spi_device_init(efx, &nic_data->spi_flash,
1319 FFE_AB_SPI_DEVICE_FLASH, 1310 FFE_AB_SPI_DEVICE_FLASH,
1320 default_flash_type); 1311 default_flash_type);
1321 if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM) 1312 if (boot_dev == FFE_AB_SPI_DEVICE_EEPROM)
1322 falcon_spi_device_init(efx, &efx->spi_eeprom, 1313 falcon_spi_device_init(efx, &nic_data->spi_eeprom,
1323 FFE_AB_SPI_DEVICE_EEPROM, 1314 FFE_AB_SPI_DEVICE_EEPROM,
1324 large_eeprom_type); 1315 large_eeprom_type);
1325} 1316}
@@ -1384,7 +1375,7 @@ static int falcon_probe_nic(struct efx_nic *efx)
1384 } 1375 }
1385 1376
1386 /* Now we can reset the NIC */ 1377 /* Now we can reset the NIC */
1387 rc = falcon_reset_hw(efx, RESET_TYPE_ALL); 1378 rc = __falcon_reset_hw(efx, RESET_TYPE_ALL);
1388 if (rc) { 1379 if (rc) {
1389 netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n"); 1380 netif_err(efx, probe, efx->net_dev, "failed to reset NIC\n");
1390 goto fail3; 1381 goto fail3;
@@ -1442,7 +1433,6 @@ static int falcon_probe_nic(struct efx_nic *efx)
1442 BUG_ON(i2c_del_adapter(&board->i2c_adap)); 1433 BUG_ON(i2c_del_adapter(&board->i2c_adap));
1443 memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); 1434 memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
1444 fail5: 1435 fail5:
1445 falcon_remove_spi_devices(efx);
1446 efx_nic_free_buffer(efx, &efx->irq_status); 1436 efx_nic_free_buffer(efx, &efx->irq_status);
1447 fail4: 1437 fail4:
1448 fail3: 1438 fail3:
@@ -1596,10 +1586,9 @@ static void falcon_remove_nic(struct efx_nic *efx)
1596 BUG_ON(rc); 1586 BUG_ON(rc);
1597 memset(&board->i2c_adap, 0, sizeof(board->i2c_adap)); 1587 memset(&board->i2c_adap, 0, sizeof(board->i2c_adap));
1598 1588
1599 falcon_remove_spi_devices(efx);
1600 efx_nic_free_buffer(efx, &efx->irq_status); 1589 efx_nic_free_buffer(efx, &efx->irq_status);
1601 1590
1602 falcon_reset_hw(efx, RESET_TYPE_ALL); 1591 __falcon_reset_hw(efx, RESET_TYPE_ALL);
1603 1592
1604 /* Release the second function after the reset */ 1593 /* Release the second function after the reset */
1605 if (nic_data->pci_dev2) { 1594 if (nic_data->pci_dev2) {