51
51
#include "nfp_cpp.h"
52
52
#include "nfp_nsp.h"
53
53
54
+ #define NFP_NSP_TIMEOUT_DEFAULT 30
55
+ #define NFP_NSP_TIMEOUT_BOOT 30
56
+
54
57
/* Offsets relative to the CSR base */
55
58
#define NSP_STATUS 0x00
56
59
#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48)
@@ -93,6 +96,7 @@ enum nfp_nsp_cmd {
93
96
SPCODE_FW_LOAD = 6 , /* Load fw from buffer, len in option */
94
97
SPCODE_ETH_RESCAN = 7 , /* Rescan ETHs, write ETH_TABLE to buf */
95
98
SPCODE_ETH_CONTROL = 8 , /* Update media config from buffer */
99
+ SPCODE_NSP_WRITE_FLASH = 11 , /* Load and flash image from buffer */
96
100
SPCODE_NSP_SENSORS = 12 , /* Read NSP sensor(s) */
97
101
SPCODE_NSP_IDENTIFY = 13 , /* Read NSP version */
98
102
};
@@ -260,10 +264,10 @@ u16 nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state)
260
264
}
261
265
262
266
static int
263
- nfp_nsp_wait_reg (struct nfp_cpp * cpp , u64 * reg ,
264
- u32 nsp_cpp , u64 addr , u64 mask , u64 val )
267
+ nfp_nsp_wait_reg (struct nfp_cpp * cpp , u64 * reg , u32 nsp_cpp , u64 addr ,
268
+ u64 mask , u64 val , u32 timeout_sec )
265
269
{
266
- const unsigned long wait_until = jiffies + 30 * HZ ;
270
+ const unsigned long wait_until = jiffies + timeout_sec * HZ ;
267
271
int err ;
268
272
269
273
for (;;) {
@@ -285,12 +289,13 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, u64 *reg,
285
289
}
286
290
287
291
/**
288
- * nfp_nsp_command () - Execute a command on the NFP Service Processor
292
+ * __nfp_nsp_command () - Execute a command on the NFP Service Processor
289
293
* @state: NFP SP state
290
294
* @code: NFP SP Command Code
291
295
* @option: NFP SP Command Argument
292
296
* @buff_cpp: NFP SP Buffer CPP Address info
293
297
* @buff_addr: NFP SP Buffer Host address
298
+ * @timeout_sec:Timeout value to wait for completion in seconds
294
299
*
295
300
* Return: 0 for success with no result
296
301
*
@@ -300,10 +305,11 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, u64 *reg,
300
305
* -ENODEV if the NSP is not a supported model
301
306
* -EBUSY if the NSP is stuck
302
307
* -EINTR if interrupted while waiting for completion
303
- * -ETIMEDOUT if the NSP took longer than 30 seconds to complete
308
+ * -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete
304
309
*/
305
- static int nfp_nsp_command (struct nfp_nsp * state , u16 code , u32 option ,
306
- u32 buff_cpp , u64 buff_addr )
310
+ static int
311
+ __nfp_nsp_command (struct nfp_nsp * state , u16 code , u32 option , u32 buff_cpp ,
312
+ u64 buff_addr , u32 timeout_sec )
307
313
{
308
314
u64 reg , ret_val , nsp_base , nsp_buffer , nsp_status , nsp_command ;
309
315
struct nfp_cpp * cpp = state -> cpp ;
@@ -341,17 +347,17 @@ static int nfp_nsp_command(struct nfp_nsp *state, u16 code, u32 option,
341
347
return err ;
342
348
343
349
/* Wait for NSP_COMMAND_START to go to 0 */
344
- err = nfp_nsp_wait_reg (cpp , & reg ,
345
- nsp_cpp , nsp_command , NSP_COMMAND_START , 0 );
350
+ err = nfp_nsp_wait_reg (cpp , & reg , nsp_cpp , nsp_command ,
351
+ NSP_COMMAND_START , 0 , NFP_NSP_TIMEOUT_DEFAULT );
346
352
if (err ) {
347
353
nfp_err (cpp , "Error %d waiting for code 0x%04x to start\n" ,
348
354
err , code );
349
355
return err ;
350
356
}
351
357
352
358
/* Wait for NSP_STATUS_BUSY to go to 0 */
353
- err = nfp_nsp_wait_reg (cpp , & reg ,
354
- nsp_cpp , nsp_status , NSP_STATUS_BUSY , 0 );
359
+ err = nfp_nsp_wait_reg (cpp , & reg , nsp_cpp , nsp_status , NSP_STATUS_BUSY ,
360
+ 0 , timeout_sec );
355
361
if (err ) {
356
362
nfp_err (cpp , "Error %d waiting for code 0x%04x to complete\n" ,
357
363
err , code );
@@ -374,9 +380,18 @@ static int nfp_nsp_command(struct nfp_nsp *state, u16 code, u32 option,
374
380
return ret_val ;
375
381
}
376
382
377
- static int nfp_nsp_command_buf (struct nfp_nsp * nsp , u16 code , u32 option ,
378
- const void * in_buf , unsigned int in_size ,
379
- void * out_buf , unsigned int out_size )
383
+ static int
384
+ nfp_nsp_command (struct nfp_nsp * state , u16 code , u32 option , u32 buff_cpp ,
385
+ u64 buff_addr )
386
+ {
387
+ return __nfp_nsp_command (state , code , option , buff_cpp , buff_addr ,
388
+ NFP_NSP_TIMEOUT_DEFAULT );
389
+ }
390
+
391
+ static int
392
+ __nfp_nsp_command_buf (struct nfp_nsp * nsp , u16 code , u32 option ,
393
+ const void * in_buf , unsigned int in_size , void * out_buf ,
394
+ unsigned int out_size , u32 timeout_sec )
380
395
{
381
396
struct nfp_cpp * cpp = nsp -> cpp ;
382
397
unsigned int max_size ;
@@ -429,7 +444,8 @@ static int nfp_nsp_command_buf(struct nfp_nsp *nsp, u16 code, u32 option,
429
444
return err ;
430
445
}
431
446
432
- ret = nfp_nsp_command (nsp , code , option , cpp_id , cpp_buf );
447
+ ret = __nfp_nsp_command (nsp , code , option , cpp_id , cpp_buf ,
448
+ timeout_sec );
433
449
if (ret < 0 )
434
450
return ret ;
435
451
@@ -442,12 +458,23 @@ static int nfp_nsp_command_buf(struct nfp_nsp *nsp, u16 code, u32 option,
442
458
return ret ;
443
459
}
444
460
461
+ static int
462
+ nfp_nsp_command_buf (struct nfp_nsp * nsp , u16 code , u32 option ,
463
+ const void * in_buf , unsigned int in_size , void * out_buf ,
464
+ unsigned int out_size )
465
+ {
466
+ return __nfp_nsp_command_buf (nsp , code , option , in_buf , in_size ,
467
+ out_buf , out_size ,
468
+ NFP_NSP_TIMEOUT_DEFAULT );
469
+ }
470
+
445
471
int nfp_nsp_wait (struct nfp_nsp * state )
446
472
{
447
- const unsigned long wait_until = jiffies + 30 * HZ ;
473
+ const unsigned long wait_until = jiffies + NFP_NSP_TIMEOUT_BOOT * HZ ;
448
474
int err ;
449
475
450
- nfp_dbg (state -> cpp , "Waiting for NSP to respond (30 sec max).\n" );
476
+ nfp_dbg (state -> cpp , "Waiting for NSP to respond (%u sec max).\n" ,
477
+ NFP_NSP_TIMEOUT_BOOT );
451
478
452
479
for (;;) {
453
480
const unsigned long start_time = jiffies ;
@@ -488,6 +515,17 @@ int nfp_nsp_load_fw(struct nfp_nsp *state, const struct firmware *fw)
488
515
fw -> size , NULL , 0 );
489
516
}
490
517
518
+ int nfp_nsp_write_flash (struct nfp_nsp * state , const struct firmware * fw )
519
+ {
520
+ /* The flash time is specified to take a maximum of 70s so we add an
521
+ * additional factor to this spec time.
522
+ */
523
+ u32 timeout_sec = 2.5 * 70 ;
524
+
525
+ return __nfp_nsp_command_buf (state , SPCODE_NSP_WRITE_FLASH , fw -> size ,
526
+ fw -> data , fw -> size , NULL , 0 , timeout_sec );
527
+ }
528
+
491
529
int nfp_nsp_read_eth_table (struct nfp_nsp * state , void * buf , unsigned int size )
492
530
{
493
531
return nfp_nsp_command_buf (state , SPCODE_ETH_RESCAN , size , NULL , 0 ,
0 commit comments