|
@@ -18,9 +18,11 @@
|
18
|
18
|
|
19
|
19
|
#include "etherboot.h"
|
20
|
20
|
#include "nic.h"
|
|
21
|
+#include <errno.h>
|
21
|
22
|
#include <gpxe/pci.h>
|
22
|
23
|
#include <gpxe/bitbash.h>
|
23
|
24
|
#include <gpxe/i2c.h>
|
|
25
|
+#include <gpxe/nvs.h>
|
24
|
26
|
#include "timer.h"
|
25
|
27
|
#define dma_addr_t unsigned long
|
26
|
28
|
#include "etherfabric.h"
|
|
@@ -210,6 +212,9 @@ struct efab_nic {
|
210
|
212
|
struct i2c_bit_basher ef1002_i2c;
|
211
|
213
|
unsigned long ef1002_i2c_outputs;
|
212
|
214
|
struct i2c_device ef1002_eeprom;
|
|
215
|
+
|
|
216
|
+ /** NVS access */
|
|
217
|
+ struct nvs_device nvs;
|
213
|
218
|
};
|
214
|
219
|
|
215
|
220
|
/**************************************************************************
|
|
@@ -2206,10 +2211,13 @@ struct efab_spi_device {
|
2206
|
2211
|
unsigned int device_id;
|
2207
|
2212
|
/** Address length (in bytes) */
|
2208
|
2213
|
unsigned int addr_len;
|
2209
|
|
- /** Read command */
|
2210
|
|
- unsigned int read_command;
|
|
2214
|
+ /** Device size */
|
|
2215
|
+ unsigned int len;
|
2211
|
2216
|
};
|
2212
|
2217
|
|
|
2218
|
+#define SPI_WRITE_CMD 0x02
|
|
2219
|
+#define SPI_READ_CMD 0x03
|
|
2220
|
+
|
2213
|
2221
|
/**
|
2214
|
2222
|
* Wait for SPI command completion
|
2215
|
2223
|
*
|
|
@@ -2234,8 +2242,8 @@ static int falcon_spi_wait ( struct efab_nic *efab ) {
|
2234
|
2242
|
*
|
2235
|
2243
|
*/
|
2236
|
2244
|
static int falcon_spi_read ( struct efab_nic *efab,
|
2237
|
|
- struct efab_spi_device *spi,
|
2238
|
|
- int address, void *data, unsigned int len ) {
|
|
2245
|
+ struct efab_spi_device *spi, int address,
|
|
2246
|
+ void *data, unsigned int len ) {
|
2239
|
2247
|
efab_oword_t reg;
|
2240
|
2248
|
|
2241
|
2249
|
/* Program address register */
|
|
@@ -2250,7 +2258,7 @@ static int falcon_spi_read ( struct efab_nic *efab,
|
2250
|
2258
|
FCN_EE_SPI_HCMD_READ, FCN_EE_SPI_READ,
|
2251
|
2259
|
FCN_EE_SPI_HCMD_DUBCNT, 0,
|
2252
|
2260
|
FCN_EE_SPI_HCMD_ADBCNT, spi->addr_len,
|
2253
|
|
- FCN_EE_SPI_HCMD_ENC, spi->read_command );
|
|
2261
|
+ FCN_EE_SPI_HCMD_ENC, SPI_READ_CMD );
|
2254
|
2262
|
falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
|
2255
|
2263
|
|
2256
|
2264
|
/* Wait for read to complete */
|
|
@@ -2264,24 +2272,61 @@ static int falcon_spi_read ( struct efab_nic *efab,
|
2264
|
2272
|
return 1;
|
2265
|
2273
|
}
|
2266
|
2274
|
|
2267
|
|
-#define SPI_READ_CMD 0x03
|
|
2275
|
+/**
|
|
2276
|
+ * Perform SPI write
|
|
2277
|
+ *
|
|
2278
|
+ */
|
|
2279
|
+static int falcon_spi_write ( struct efab_nic *efab,
|
|
2280
|
+ struct efab_spi_device *spi, int address,
|
|
2281
|
+ const void *data, unsigned int len ) {
|
|
2282
|
+ efab_oword_t reg;
|
|
2283
|
+
|
|
2284
|
+ /* Program address register */
|
|
2285
|
+ EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
|
|
2286
|
+ falcon_write ( efab, ®, FCN_EE_SPI_HADR_REG_KER );
|
|
2287
|
+
|
|
2288
|
+ /* Program data register */
|
|
2289
|
+ memcpy ( ®, data, len );
|
|
2290
|
+ falcon_write ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
|
|
2291
|
+
|
|
2292
|
+ /* Issue write command */
|
|
2293
|
+ EFAB_POPULATE_OWORD_7 ( reg,
|
|
2294
|
+ FCN_EE_SPI_HCMD_CMD_EN, 1,
|
|
2295
|
+ FCN_EE_SPI_HCMD_SF_SEL, spi->device_id,
|
|
2296
|
+ FCN_EE_SPI_HCMD_DABCNT, len,
|
|
2297
|
+ FCN_EE_SPI_HCMD_READ, FCN_EE_SPI_WRITE,
|
|
2298
|
+ FCN_EE_SPI_HCMD_DUBCNT, 0,
|
|
2299
|
+ FCN_EE_SPI_HCMD_ADBCNT, spi->addr_len,
|
|
2300
|
+ FCN_EE_SPI_HCMD_ENC, SPI_WRITE_CMD );
|
|
2301
|
+ falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
|
|
2302
|
+
|
|
2303
|
+ /* Wait for read to complete */
|
|
2304
|
+ if ( ! falcon_spi_wait ( efab ) )
|
|
2305
|
+ return 0;
|
|
2306
|
+
|
|
2307
|
+ return 1;
|
|
2308
|
+}
|
|
2309
|
+
|
2268
|
2310
|
#define AT25F1024_ADDR_LEN 3
|
2269
|
|
-#define AT25F1024_READ_CMD SPI_READ_CMD
|
|
2311
|
+#define AT25040_ADDR_LEN 1
|
2270
|
2312
|
#define MC25XX640_ADDR_LEN 2
|
2271
|
|
-#define MC25XX640_READ_CMD SPI_READ_CMD
|
2272
|
2313
|
|
2273
|
2314
|
/** Falcon Flash SPI device */
|
2274
|
2315
|
static struct efab_spi_device falcon_spi_flash = {
|
2275
|
2316
|
.device_id = FCN_EE_SPI_FLASH,
|
2276
|
2317
|
.addr_len = AT25F1024_ADDR_LEN,
|
2277
|
|
- .read_command = AT25F1024_READ_CMD,
|
2278
|
2318
|
};
|
2279
|
2319
|
|
2280
|
2320
|
/** Falcon EEPROM SPI device */
|
2281
|
2321
|
static struct efab_spi_device falcon_spi_large_eeprom = {
|
2282
|
2322
|
.device_id = FCN_EE_SPI_EEPROM,
|
2283
|
2323
|
.addr_len = MC25XX640_ADDR_LEN,
|
2284
|
|
- .read_command = MC25XX640_READ_CMD,
|
|
2324
|
+};
|
|
2325
|
+
|
|
2326
|
+/** Falcon EEPROM SPI device */
|
|
2327
|
+static struct efab_spi_device falcon_spi_small_eeprom = {
|
|
2328
|
+ .device_id = FCN_EE_SPI_EEPROM,
|
|
2329
|
+ .addr_len = AT25040_ADDR_LEN,
|
2285
|
2330
|
};
|
2286
|
2331
|
|
2287
|
2332
|
/** Offset of MAC address within EEPROM or Flash */
|
|
@@ -2301,6 +2346,49 @@ static int falcon_read_eeprom ( struct efab_nic *efab ) {
|
2301
|
2346
|
efab->mac_addr, sizeof ( efab->mac_addr ) );
|
2302
|
2347
|
}
|
2303
|
2348
|
|
|
2349
|
+#define FALCON_NVS_OFFSET 0x000
|
|
2350
|
+
|
|
2351
|
+static int falcon_read_nvs ( struct nvs_device *nvs, unsigned int offset,
|
|
2352
|
+ void *data, size_t len ) {
|
|
2353
|
+ struct efab_nic *efab = container_of ( nvs, struct efab_nic, nvs );
|
|
2354
|
+ struct efab_spi_device *spi = &falcon_spi_small_eeprom;
|
|
2355
|
+
|
|
2356
|
+ while ( len ) {
|
|
2357
|
+ if ( ! falcon_spi_read ( efab, spi,
|
|
2358
|
+ ( offset + FALCON_NVS_OFFSET ),
|
|
2359
|
+ data, 16 ) ) {
|
|
2360
|
+ return -EIO;
|
|
2361
|
+ }
|
|
2362
|
+ data += 16;
|
|
2363
|
+ offset += 16;
|
|
2364
|
+ len -=16;
|
|
2365
|
+ }
|
|
2366
|
+ return 0;
|
|
2367
|
+}
|
|
2368
|
+
|
|
2369
|
+static int falcon_write_nvs ( struct nvs_device *nvs, unsigned int offset,
|
|
2370
|
+ const void *data, size_t len ) {
|
|
2371
|
+ struct efab_nic *efab = container_of ( nvs, struct efab_nic, nvs );
|
|
2372
|
+ struct efab_spi_device *spi = &falcon_spi_large_eeprom;
|
|
2373
|
+
|
|
2374
|
+ while ( len ) {
|
|
2375
|
+ if ( ! falcon_spi_write ( efab, spi,
|
|
2376
|
+ ( offset + FALCON_NVS_OFFSET ),
|
|
2377
|
+ data, 16 ) ) {
|
|
2378
|
+ return -EIO;
|
|
2379
|
+ }
|
|
2380
|
+ data += 16;
|
|
2381
|
+ offset += 16;
|
|
2382
|
+ len -=16;
|
|
2383
|
+ }
|
|
2384
|
+ return 0;
|
|
2385
|
+}
|
|
2386
|
+
|
|
2387
|
+static struct nvs_operations falcon_nvs_operations = {
|
|
2388
|
+ .read = falcon_read_nvs,
|
|
2389
|
+ .write = falcon_write_nvs,
|
|
2390
|
+};
|
|
2391
|
+
|
2304
|
2392
|
/** RX descriptor */
|
2305
|
2393
|
typedef efab_qword_t falcon_rx_desc_t;
|
2306
|
2394
|
|
|
@@ -2952,6 +3040,14 @@ static int falcon_init_nic ( struct efab_nic *efab ) {
|
2952
|
3040
|
falcon_write ( efab, ®, FCN_INT_ADR_REG_KER );
|
2953
|
3041
|
udelay ( 1000 );
|
2954
|
3042
|
|
|
3043
|
+ /* Register non-volatile storage */
|
|
3044
|
+ if ( efab->has_eeprom ) {
|
|
3045
|
+ efab->nvs.op = &falcon_nvs_operations;
|
|
3046
|
+ efab->nvs.len = 0x100;
|
|
3047
|
+ if ( nvs_register ( &efab->nvs ) != 0 )
|
|
3048
|
+ return 0;
|
|
3049
|
+ }
|
|
3050
|
+
|
2955
|
3051
|
return 1;
|
2956
|
3052
|
}
|
2957
|
3053
|
|
|
@@ -3303,7 +3399,7 @@ PROBE - Look for an adapter, this routine's visible to the outside
|
3303
|
3399
|
***************************************************************************/
|
3304
|
3400
|
static int etherfabric_probe ( struct nic *nic, struct pci_device *pci ) {
|
3305
|
3401
|
static struct efab_nic efab;
|
3306
|
|
- static int nic_port = 1;
|
|
3402
|
+ static int nic_port = 0;
|
3307
|
3403
|
struct efab_buffers *buffers;
|
3308
|
3404
|
int i;
|
3309
|
3405
|
|