5151#include "nfp_cpp.h"
5252#include "nfp_nsp.h"
5353
54+ #define NFP_NSP_TIMEOUT_DEFAULT 30
55+ #define NFP_NSP_TIMEOUT_BOOT 30
56+
5457/* Offsets relative to the CSR base */
5558#define NSP_STATUS 0x00
5659#define NSP_STATUS_MAGIC GENMASK_ULL(63, 48)
@@ -260,10 +263,10 @@ u16 nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state)
260263}
261264
262265static int
263- nfp_nsp_wait_reg (struct nfp_cpp * cpp , u64 * reg ,
264- u32 nsp_cpp , u64 addr , u64 mask , u64 val )
266+ nfp_nsp_wait_reg (struct nfp_cpp * cpp , u64 * reg , u32 nsp_cpp , u64 addr ,
267+ u64 mask , u64 val , u32 timeout_sec )
265268{
266- const unsigned long wait_until = jiffies + 30 * HZ ;
269+ const unsigned long wait_until = jiffies + timeout_sec * HZ ;
267270 int err ;
268271
269272 for (;;) {
@@ -285,12 +288,13 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, u64 *reg,
285288}
286289
287290/**
288- * nfp_nsp_command () - Execute a command on the NFP Service Processor
291+ * __nfp_nsp_command () - Execute a command on the NFP Service Processor
289292 * @state: NFP SP state
290293 * @code: NFP SP Command Code
291294 * @option: NFP SP Command Argument
292295 * @buff_cpp: NFP SP Buffer CPP Address info
293296 * @buff_addr: NFP SP Buffer Host address
297+ * @timeout_sec:Timeout value to wait for completion in seconds
294298 *
295299 * Return: 0 for success with no result
296300 *
@@ -300,10 +304,11 @@ nfp_nsp_wait_reg(struct nfp_cpp *cpp, u64 *reg,
300304 * -ENODEV if the NSP is not a supported model
301305 * -EBUSY if the NSP is stuck
302306 * -EINTR if interrupted while waiting for completion
303- * -ETIMEDOUT if the NSP took longer than 30 seconds to complete
307+ * -ETIMEDOUT if the NSP took longer than @timeout_sec seconds to complete
304308 */
305- static int nfp_nsp_command (struct nfp_nsp * state , u16 code , u32 option ,
306- u32 buff_cpp , u64 buff_addr )
309+ static int
310+ __nfp_nsp_command (struct nfp_nsp * state , u16 code , u32 option , u32 buff_cpp ,
311+ u64 buff_addr , u32 timeout_sec )
307312{
308313 u64 reg , ret_val , nsp_base , nsp_buffer , nsp_status , nsp_command ;
309314 struct nfp_cpp * cpp = state -> cpp ;
@@ -341,17 +346,17 @@ static int nfp_nsp_command(struct nfp_nsp *state, u16 code, u32 option,
341346 return err ;
342347
343348 /* 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 );
349+ err = nfp_nsp_wait_reg (cpp , & reg , nsp_cpp , nsp_command ,
350+ NSP_COMMAND_START , 0 , NFP_NSP_TIMEOUT_DEFAULT );
346351 if (err ) {
347352 nfp_err (cpp , "Error %d waiting for code 0x%04x to start\n" ,
348353 err , code );
349354 return err ;
350355 }
351356
352357 /* 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 );
358+ err = nfp_nsp_wait_reg (cpp , & reg , nsp_cpp , nsp_status , NSP_STATUS_BUSY ,
359+ 0 , timeout_sec );
355360 if (err ) {
356361 nfp_err (cpp , "Error %d waiting for code 0x%04x to complete\n" ,
357362 err , code );
@@ -374,9 +379,18 @@ static int nfp_nsp_command(struct nfp_nsp *state, u16 code, u32 option,
374379 return ret_val ;
375380}
376381
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 )
382+ static int
383+ nfp_nsp_command (struct nfp_nsp * state , u16 code , u32 option , u32 buff_cpp ,
384+ u64 buff_addr )
385+ {
386+ return __nfp_nsp_command (state , code , option , buff_cpp , buff_addr ,
387+ NFP_NSP_TIMEOUT_DEFAULT );
388+ }
389+
390+ static int
391+ __nfp_nsp_command_buf (struct nfp_nsp * nsp , u16 code , u32 option ,
392+ const void * in_buf , unsigned int in_size , void * out_buf ,
393+ unsigned int out_size , u32 timeout_sec )
380394{
381395 struct nfp_cpp * cpp = nsp -> cpp ;
382396 unsigned int max_size ;
@@ -429,7 +443,8 @@ static int nfp_nsp_command_buf(struct nfp_nsp *nsp, u16 code, u32 option,
429443 return err ;
430444 }
431445
432- ret = nfp_nsp_command (nsp , code , option , cpp_id , cpp_buf );
446+ ret = __nfp_nsp_command (nsp , code , option , cpp_id , cpp_buf ,
447+ timeout_sec );
433448 if (ret < 0 )
434449 return ret ;
435450
@@ -442,12 +457,23 @@ static int nfp_nsp_command_buf(struct nfp_nsp *nsp, u16 code, u32 option,
442457 return ret ;
443458}
444459
460+ static int
461+ nfp_nsp_command_buf (struct nfp_nsp * nsp , u16 code , u32 option ,
462+ const void * in_buf , unsigned int in_size , void * out_buf ,
463+ unsigned int out_size )
464+ {
465+ return __nfp_nsp_command_buf (nsp , code , option , in_buf , in_size ,
466+ out_buf , out_size ,
467+ NFP_NSP_TIMEOUT_DEFAULT );
468+ }
469+
445470int nfp_nsp_wait (struct nfp_nsp * state )
446471{
447- const unsigned long wait_until = jiffies + 30 * HZ ;
472+ const unsigned long wait_until = jiffies + NFP_NSP_TIMEOUT_BOOT * HZ ;
448473 int err ;
449474
450- nfp_dbg (state -> cpp , "Waiting for NSP to respond (30 sec max).\n" );
475+ nfp_dbg (state -> cpp , "Waiting for NSP to respond (%u sec max).\n" ,
476+ NFP_NSP_TIMEOUT_BOOT );
451477
452478 for (;;) {
453479 const unsigned long start_time = jiffies ;
0 commit comments