i40e: fix 32bit FW gtime wrapping issue
Subsystems (2)
PATCH v2 1/1 i40e: fix 32bit FW gtime wrapping issue
Before the i40e_nvm code didn't take into account that 32bit FW gtime wraps ~70minutes, timeout was calculated as 64bit gtime + NVM_TIMEOUT , so when gtime was ~70minutes, then gtime could not become greater than 64bit timeout value and the semaphore to be considered as expired.
Decrease hw_semaphore_timeout size down to 32bits, because FW I40E_GLVFGEN_TIMER register is 32bits only anyway, but having both variables same u32 size simplifies code.
Fix FW write semaphore expiration condition, taking into account that I40E_GLVFGEN_TIMER wraps, by checking the sign of subtraction of two 32 bit vaues.
---v1->v2 in commit message: add 'Fixes' tag, fix a typo
---
--- drivers/net/ethernet/intel/i40e/i40e_nvm.c | 8 ++++---- drivers/net/ethernet/intel/i40e/i40e_type.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_nvm.c +4 -4
@@ -55,7 +55,7 @@ int i40e_init_nvm(struct i40e_hw *hw)int i40e_acquire_nvm (struct i40e_hw *hw,enum i40e_aq_resource_access_type access) { -u64 gtime, timeout; +u32 gtime, timeout;u64 time_left =0 ;int ret_code =0 ;
@@ -78,7 +78,7 @@ int i40e_acquire_nvm(struct i40e_hw *hw,if (ret_code && time_left) {/* Poll until the current NVM owner timeouts */ timeout =I40E_MS_TO_GTIME (I40E_MAX_NVM_TIMEOUT ) + gtime; -while ((gtime < timeout) && time_left) { +while ((s32)(gtime - timeout) <0 && time_left) {usleep_range (10000 ,20000 ); gtime =rd32 (hw,I40E_GLVFGEN_TIMER ); ret_code = i40e_aq_request_resource(hw,
@@ -1192,9 +1192,9 @@ static int i40e_nvmupd_state_writing(struct i40e_hw *hw,u32 gtime; gtime =rd32 (hw,I40E_GLVFGEN_TIMER ); -if (gtime >= hw->nvm.hw_semaphore_timeout) { +if ((s32)(gtime - hw->nvm.hw_semaphore_timeout) >=0 ) {i40e_debug (hw,I40E_DEBUG_ALL , -"NVMUPD: write semaphore expired (%d >= %lld), retrying\n" , +"NVMUPD: write semaphore expired (%d >= %d), retrying\n" , gtime, hw->nvm.hw_semaphore_timeout);i40e_release_nvm (hw); status =i40e_acquire_nvm (hw,I40E_RESOURCE_WRITE );
drivers/net/ethernet/intel/i40e/i40e_type.h +1 -1
@@ -328,7 +328,7 @@ enum i40e_aq_resource_access_type { };struct i40e_nvm_info { -u64 hw_semaphore_timeout;/* usec global time (GTIME resolution) */ +u32 hw_semaphore_timeout;/* usec global time (GTIME resolution) */ u32 timeout;/* [ms] */ u16 sr_size;/* Shadow RAM size in words */ bool blank_nvm_mode;/* is NVM empty (no FW present)*/
Signature · 6 lines
2.25.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
Tony Nguyen
maintainerQuoted 11 lines · Aleksandr Loktionov
Before the
i40e_nvmcode didn't take into account that 32bit FW gtime wraps ~70minutes, timeout was calculated as 64bit gtime +NVM_TIMEOUT, so when gtime was ~70minutes, then gtime could not become greater than 64bit timeout value and the semaphore to be considered as expired.Decrease
hw_semaphore_timeoutsize down to 32bits, because FWI40E_GLVFGEN_TIMERregister is 32bits only anyway, but having both variables same u32 size simplifies code.
Fix FW write semaphore expiration condition, taking into account thatI40E_GLVFGEN_TIMERwraps, by checking the sign of subtraction of two 32 bit vaues.
Can you address and/or respond to all the comments on v1?
https://lore.kernel.org/intel-wired-lan/[email protected]/
Thanks,
Tony
Quoted 49 lines
Fixes 56a62fc86895 ("i40e: init code and hardware support")Signed-off-by Aleksandr Loktionov <[email protected]>---
v1->v2in commit message: add 'Fixes' tag, fix a typo
------ drivers/net/ethernet/intel/i40e/i40e_nvm.c | 8 ++++---- drivers/net/ethernet/intel/i40e/i40e_type.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/i40e/i40e_nvm.c +4
-4@@ -55,7 +55,7 @@ int i40e_init_nvm(struct i40e_hw *hw)int i40e_acquire_nvm (struct i40e_hw *hw,enum i40e_aq_resource_access_type access) { -u64 gtime, timeout; +u32 gtime, timeout;u64 time_left =0 ;int ret_code =0 ;@@ -78,7 +78,7 @@ int i40e_acquire_nvm(struct i40e_hw *hw,if (ret_code && time_left) {/* Poll until the current NVM owner timeouts */ timeout =I40E_MS_TO_GTIME (I40E_MAX_NVM_TIMEOUT ) + gtime; -while ((gtime < timeout) && time_left) { +while ((s32)(gtime - timeout) <0 && time_left) {usleep_range (10000 ,20000 ); gtime =rd32 (hw,I40E_GLVFGEN_TIMER ); ret_code = i40e_aq_request_resource(hw,@@ -1192,9 +1192,9 @@ static int i40e_nvmupd_state_writing(struct i40e_hw *hw,u32 gtime; gtime =rd32 (hw,I40E_GLVFGEN_TIMER ); -if (gtime >= hw->nvm.hw_semaphore_timeout) { +if ((s32)(gtime - hw->nvm.hw_semaphore_timeout) >=0 ) {i40e_debug (hw,I40E_DEBUG_ALL , -"NVMUPD: write semaphore expired (%d >= %lld), retrying\n" , +"NVMUPD: write semaphore expired (%d >= %d), retrying\n" , gtime, hw->nvm.hw_semaphore_timeout);i40e_release_nvm (hw); status =i40e_acquire_nvm (hw,I40E_RESOURCE_WRITE );drivers/net/ethernet/intel/i40e/i40e_type.h +0
-0
drivers/net/ethernet/intel/i40e/i40e_type.h enum i40e_aq_resource_access_type { · line 334
Quoted 8 lines
drivers/net/ethernet/intel/i40e/i40e_type.h +1
-1@@ -328,7 +328,7 @@ enum i40e_aq_resource_access_type { };struct i40e_nvm_info { -u64 hw_semaphore_timeout;/* usec global time (GTIME resolution) */ +u32 hw_semaphore_timeout;/* usec global time (GTIME resolution) */ u32 timeout;/* [ms] */ u16 sr_size;/* Shadow RAM size in words */ bool blank_nvm_mode;/* is NVM empty (no FW present)*/
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan