drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
Extension
.c
Size
12753 bytes
Lines
435
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (--times == 0) {
			MLXFW_ERR_MSG(mlxfw_dev, extack,
				      "Timeout reached on FSM state change", -ETIMEDOUT);
			return -ETIMEDOUT;
		}
		msleep(MLXFW_FSM_STATE_WAIT_CYCLE_MS);
		goto retry;
	}
	return 0;
}

static int
mlxfw_fsm_reactivate_err(struct mlxfw_dev *mlxfw_dev,
			 struct netlink_ext_ack *extack, u8 err)
{
	enum mlxfw_fsm_reactivate_status status;

#define MXFW_REACT_PRFX "Reactivate FSM: "
#define MLXFW_REACT_ERR(msg, err) \
	MLXFW_ERR_MSG(mlxfw_dev, extack, MXFW_REACT_PRFX msg, err)

	status = min_t(enum mlxfw_fsm_reactivate_status, err,
		       MLXFW_FSM_REACTIVATE_STATUS_MAX);

	switch (status) {
	case MLXFW_FSM_REACTIVATE_STATUS_BUSY:
		MLXFW_REACT_ERR("busy", err);
		break;
	case MLXFW_FSM_REACTIVATE_STATUS_PROHIBITED_FW_VER_ERR:
		MLXFW_REACT_ERR("prohibited fw ver", err);
		break;
	case MLXFW_FSM_REACTIVATE_STATUS_FIRST_PAGE_COPY_FAILED:
		MLXFW_REACT_ERR("first page copy failed", err);
		break;
	case MLXFW_FSM_REACTIVATE_STATUS_FIRST_PAGE_ERASE_FAILED:
		MLXFW_REACT_ERR("first page erase failed", err);
		break;
	case MLXFW_FSM_REACTIVATE_STATUS_FIRST_PAGE_RESTORE_FAILED:
		MLXFW_REACT_ERR("first page restore failed", err);
		break;
	case MLXFW_FSM_REACTIVATE_STATUS_CANDIDATE_FW_DEACTIVATION_FAILED:
		MLXFW_REACT_ERR("candidate fw deactivation failed", err);
		break;
	case MLXFW_FSM_REACTIVATE_STATUS_ERR_DEVICE_RESET_REQUIRED:
		MLXFW_REACT_ERR("device reset required", err);
		break;
	case MLXFW_FSM_REACTIVATE_STATUS_ERR_FW_PROGRAMMING_NEEDED:
		MLXFW_REACT_ERR("fw programming needed", err);
		break;
	case MLXFW_FSM_REACTIVATE_STATUS_FW_ALREADY_ACTIVATED:
		MLXFW_REACT_ERR("fw already activated", err);
		break;
	case MLXFW_FSM_REACTIVATE_STATUS_OK:
	case MLXFW_FSM_REACTIVATE_STATUS_MAX:
		MLXFW_REACT_ERR("unexpected error", err);
		break;
	}
	return -EREMOTEIO;
};

static int mlxfw_fsm_reactivate(struct mlxfw_dev *mlxfw_dev,
				struct netlink_ext_ack *extack,
				bool *supported)
{
	u8 status;
	int err;

	if (!mlxfw_dev->ops->fsm_reactivate)
		return 0;

	err = mlxfw_dev->ops->fsm_reactivate(mlxfw_dev, &status);
	if (err == -EOPNOTSUPP) {
		*supported = false;
		return 0;
	}

	if (err) {
		MLXFW_ERR_MSG(mlxfw_dev, extack,
			      "Could not reactivate firmware flash", err);
		return err;
	}

	if (status == MLXFW_FSM_REACTIVATE_STATUS_OK ||
	    status == MLXFW_FSM_REACTIVATE_STATUS_FW_ALREADY_ACTIVATED)
		return 0;

	return mlxfw_fsm_reactivate_err(mlxfw_dev, extack, status);
}

static void mlxfw_status_notify(struct mlxfw_dev *mlxfw_dev,

Annotation

Implementation Notes