Skip to content

Commit

Permalink
linux/ena: Extend support to 256 reset reasons
Browse files Browse the repository at this point in the history
Currently we only use 4 bits in order to define the reset reason.
This allows us to define 16 reset reasons which have already been used
up. In order to allow for more reset reasons to be defined and detected,
this patch will extend the reset reason up to 8 bits which allows
256 reset reasons.

For backward compatibility reasons, bits 28-31 will represent the LSB
and bits 24-27 will represent the MSB in the relevant register.
This way when an old driver writes a reset reason it will be compatible
with the newer devices.

Also, in case the device does not support extended reset reasons, the
driver will identify it and fall back to GENERIC reset reason.
When using an old driver all reset reasons are mapped correctly
except of ENA_REGS_RESET_RX_DESCRIPTOR_MALFORMED since it was
already defined with index 16 before extending the reset
reasons support, in this case the device will interpret the
reset reason as ENA_REGS_RESET_NORMAL.

Signed-off-by: Osama Abboud <[email protected]>
  • Loading branch information
Osama Abboud committed Sep 4, 2023
1 parent 5d46360 commit 7975b2e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions kernel/linux/common/ena_com/ena_admin_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum ena_admin_aq_caps_id {
/* ENA SRD customer metrics */
ENA_ADMIN_ENA_SRD_INFO = 1,
ENA_ADMIN_CUSTOMER_METRICS = 2,
ENA_ADMIN_EXTENDED_RESET_REASONS = 3,
};

enum ena_admin_placement_policy_type {
Expand Down
25 changes: 23 additions & 2 deletions kernel/linux/common/ena_com/ena_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,7 @@ void ena_com_aenq_intr_handler(struct ena_com_dev *ena_dev, void *data)
int ena_com_dev_reset(struct ena_com_dev *ena_dev,
enum ena_regs_reset_reason_types reset_reason)
{
u32 reset_reason_msb, reset_reason_lsb;
u32 stat, timeout, cap, reset_val;
int rc;

Expand Down Expand Up @@ -2434,8 +2435,28 @@ int ena_com_dev_reset(struct ena_com_dev *ena_dev,

/* start reset */
reset_val = ENA_REGS_DEV_CTL_DEV_RESET_MASK;
reset_val |= (reset_reason << ENA_REGS_DEV_CTL_RESET_REASON_SHIFT) &
ENA_REGS_DEV_CTL_RESET_REASON_MASK;

/* For backward compatibility, device will interpret
* bits 24-27 as MSB, bits 28-31 as LSB
*/
reset_reason_lsb = ENA_FIELD_GET(reset_reason, ENA_RESET_REASON_LSB_MASK,
ENA_RESET_REASON_LSB_OFFSET);

reset_reason_msb = ENA_FIELD_GET(reset_reason, ENA_RESET_REASON_MSB_MASK,
ENA_RESET_REASON_MSB_OFFSET);

reset_val |= reset_reason_lsb << ENA_REGS_DEV_CTL_RESET_REASON_SHIFT;

if (ena_com_get_cap(ena_dev, ENA_ADMIN_EXTENDED_RESET_REASONS))
reset_val |= reset_reason_msb << ENA_REGS_DEV_CTL_RESET_REASON_EXT_SHIFT;
else if (reset_reason_msb) {
/* In case the device does not support intended
* extended reset reason fallback to generic
*/
reset_val = ENA_REGS_DEV_CTL_DEV_RESET_MASK;
reset_val |= (ENA_REGS_RESET_GENERIC << ENA_REGS_DEV_CTL_RESET_REASON_SHIFT) &
ENA_REGS_DEV_CTL_RESET_REASON_MASK;
}
writel(reset_val, ena_dev->reg_bar + ENA_REGS_DEV_CTL_OFF);

/* Write again the MMIO read request address */
Expand Down
8 changes: 8 additions & 0 deletions kernel/linux/common/ena_com/ena_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
#define ADMIN_CQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_acq_entry))
#define ADMIN_AENQ_SIZE(depth) ((depth) * sizeof(struct ena_admin_aenq_entry))

/* Macros used to extract LSB/MSB from the
* enums defining the reset reasons
*/
#define ENA_RESET_REASON_LSB_OFFSET 0
#define ENA_RESET_REASON_LSB_MASK 0xf
#define ENA_RESET_REASON_MSB_OFFSET 4
#define ENA_RESET_REASON_MSB_MASK 0xf0

#define ENA_CUSTOMER_METRICS_BUFFER_SIZE 512

/*****************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions kernel/linux/common/ena_com/ena_regs_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ enum ena_regs_reset_reason_types {
#define ENA_REGS_DEV_CTL_QUIESCENT_MASK 0x4
#define ENA_REGS_DEV_CTL_IO_RESUME_SHIFT 3
#define ENA_REGS_DEV_CTL_IO_RESUME_MASK 0x8
#define ENA_REGS_DEV_CTL_RESET_REASON_EXT_SHIFT 24
#define ENA_REGS_DEV_CTL_RESET_REASON_EXT_MASK 0xf000000
#define ENA_REGS_DEV_CTL_RESET_REASON_SHIFT 28
#define ENA_REGS_DEV_CTL_RESET_REASON_MASK 0xf0000000

Expand Down
7 changes: 7 additions & 0 deletions kernel/linux/ena/kcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,13 @@ static inline void ena_netif_napi_add(struct net_device *dev,
#define ENA_LARGE_LLQ_ETHTOOL
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
#include <linux/bitfield.h>
#define ENA_FIELD_GET(value, mask, offset) FIELD_GET(mask, value)
#else
#define ENA_FIELD_GET(value, mask, offset) ((typeof(mask))((value & mask) >> offset))
#endif

#if defined(ENA_DEVLINK_SUPPORT) && LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0)
#define devl_param_driverinit_value_get devlink_param_driverinit_value_get
#define devl_param_driverinit_value_set devlink_param_driverinit_value_set
Expand Down

0 comments on commit 7975b2e

Please sign in to comment.