Skip to content

Commit

Permalink
raw/cnxk_bphy: extend link state capabilities
Browse files Browse the repository at this point in the history
Update the driver to leverage the firmware capabilities of setting
link state by adding two extra parameters i.e. timeout and flag
disabling auto enable of rx/tx during linkup.

Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
  • Loading branch information
Tomasz Duszynski authored and jerinjacobk committed Jan 22, 2024
1 parent 019c31d commit 7d3daa3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
11 changes: 8 additions & 3 deletions drivers/common/cnxk/roc_bphy_cgx.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ roc_bphy_cgx_stop_rxtx(struct roc_bphy_cgx *roc_cgx, unsigned int lmac)

int
roc_bphy_cgx_set_link_state(struct roc_bphy_cgx *roc_cgx, unsigned int lmac,
bool state)
struct roc_bphy_cgx_link_state *state)
{
uint64_t scr1, scr0;

Expand All @@ -321,8 +321,13 @@ roc_bphy_cgx_set_link_state(struct roc_bphy_cgx *roc_cgx, unsigned int lmac,
if (!roc_bphy_cgx_lmac_exists(roc_cgx, lmac))
return -ENODEV;

scr1 = state ? FIELD_PREP(SCR1_ETH_CMD_ID, ETH_CMD_LINK_BRING_UP) :
FIELD_PREP(SCR1_ETH_CMD_ID, ETH_CMD_LINK_BRING_DOWN);
if (!state)
return -EINVAL;

scr1 = (state->state ? FIELD_PREP(SCR1_ETH_CMD_ID, ETH_CMD_LINK_BRING_UP) :
FIELD_PREP(SCR1_ETH_CMD_ID, ETH_CMD_LINK_BRING_DOWN)) |
FIELD_PREP(SCR1_CGX_LINK_BRINGUP_ARGS_TIMEOUT, state->timeout) |
FIELD_PREP(SCR1_CGX_LINK_BRINGUP_ARGS_RX_TX_DIS, state->rx_tx_dis);

return roc_bphy_cgx_intf_req(roc_cgx, lmac, scr1, &scr0);
}
Expand Down
8 changes: 7 additions & 1 deletion drivers/common/cnxk/roc_bphy_cgx.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ struct roc_bphy_cgx_cpri_mode_misc {
int flags;
};

struct roc_bphy_cgx_link_state {
bool state;
int timeout;
bool rx_tx_dis;
};

__roc_api int roc_bphy_cgx_dev_init(struct roc_bphy_cgx *roc_cgx);
__roc_api int roc_bphy_cgx_dev_fini(struct roc_bphy_cgx *roc_cgx);

Expand All @@ -152,7 +158,7 @@ __roc_api int roc_bphy_cgx_start_rxtx(struct roc_bphy_cgx *roc_cgx,
__roc_api int roc_bphy_cgx_stop_rxtx(struct roc_bphy_cgx *roc_cgx,
unsigned int lmac);
__roc_api int roc_bphy_cgx_set_link_state(struct roc_bphy_cgx *roc_cgx,
unsigned int lmac, bool state);
unsigned int lmac, struct roc_bphy_cgx_link_state *state);
__roc_api int roc_bphy_cgx_get_linkinfo(struct roc_bphy_cgx *roc_cgx,
unsigned int lmac,
struct roc_bphy_cgx_link_info *info);
Expand Down
4 changes: 4 additions & 0 deletions drivers/common/cnxk/roc_bphy_cgx_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ enum eth_cmd_own {
#define SCR1_CPRI_MODE_MISC_ARGS_LANE_IDX GENMASK_ULL(15, 12)
#define SCR1_CPRI_MODE_MISC_ARGS_FLAGS GENMASK_ULL(17, 16)

/* struct cgx_link_bringup_args */
#define SCR1_CGX_LINK_BRINGUP_ARGS_TIMEOUT GENMASK_ULL(21, 8)
#define SCR1_CGX_LINK_BRINGUP_ARGS_RX_TX_DIS BIT_ULL(22)

#define SCR1_OWN_STATUS GENMASK_ULL(1, 0)

#endif /* _ROC_BPHY_CGX_PRIV_H_ */
7 changes: 5 additions & 2 deletions drivers/raw/cnxk_bphy/cnxk_bphy_cgx.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ cnxk_bphy_cgx_process_buf(struct cnxk_bphy_cgx *cgx, unsigned int queue,
struct roc_bphy_cgx_cpri_mode_change rcpri_mode;
struct roc_bphy_cgx_cpri_mode_misc rmode_misc;
struct roc_bphy_cgx_cpri_mode_tx_ctrl rtx_ctrl;
struct roc_bphy_cgx_link_state rlink_state;
struct roc_bphy_cgx_link_info rlink_info;
struct roc_bphy_cgx_link_mode rlink_mode;
enum roc_bphy_cgx_eth_link_fec *fec;
Expand Down Expand Up @@ -135,8 +136,10 @@ cnxk_bphy_cgx_process_buf(struct cnxk_bphy_cgx *cgx, unsigned int queue,
break;
case CNXK_BPHY_CGX_MSG_TYPE_SET_LINK_STATE:
link_state = msg->data;
ret = roc_bphy_cgx_set_link_state(cgx->rcgx, lmac,
link_state->state);
rlink_state.state = link_state->state;
rlink_state.timeout = link_state->timeout;
rlink_state.rx_tx_dis = link_state->rx_tx_dis;
ret = roc_bphy_cgx_set_link_state(cgx->rcgx, lmac, &rlink_state);
break;
case CNXK_BPHY_CGX_MSG_TYPE_START_RXTX:
ret = roc_bphy_cgx_start_rxtx(cgx->rcgx, lmac);
Expand Down
9 changes: 7 additions & 2 deletions drivers/raw/cnxk_bphy/cnxk_bphy_cgx_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ cnxk_bphy_cgx_link_cond(uint16_t dev_id, unsigned int queue, int cond)
int
cnxk_bphy_cgx_dev_selftest(uint16_t dev_id)
{
struct cnxk_bphy_cgx_msg_set_link_state link_state = { };
unsigned int queues, i;
int ret;

Expand Down Expand Up @@ -75,7 +76,8 @@ cnxk_bphy_cgx_dev_selftest(uint16_t dev_id)
break;
}

ret = rte_pmd_bphy_cgx_set_link_state(dev_id, i, false);
link_state.state = false;
ret = rte_pmd_bphy_cgx_set_link_state(dev_id, i, &link_state);
if (ret) {
BPHY_CGX_LOG(ERR, "Failed to set link down");
break;
Expand All @@ -85,7 +87,10 @@ cnxk_bphy_cgx_dev_selftest(uint16_t dev_id)
if (ret != 0)
BPHY_CGX_LOG(ERR, "Timed out waiting for a link down");

ret = rte_pmd_bphy_cgx_set_link_state(dev_id, i, true);
link_state.state = true;
link_state.timeout = 1500;
link_state.rx_tx_dis = true;
ret = rte_pmd_bphy_cgx_set_link_state(dev_id, i, &link_state);
if (ret) {
BPHY_CGX_LOG(ERR, "Failed to set link up");
break;
Expand Down
14 changes: 8 additions & 6 deletions drivers/raw/cnxk_bphy/rte_pmd_bphy.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ struct cnxk_bphy_cgx_msg_link_info {
struct cnxk_bphy_cgx_msg_set_link_state {
/** Defines link state result */
bool state; /* up or down */
/** Timeout in ms */
int timeout;
/** Set if Rx/Tx should not be enabled during link up config */
bool rx_tx_dis;
};

struct cnxk_bphy_cgx_msg_cpri_mode_change {
Expand Down Expand Up @@ -676,21 +680,19 @@ rte_pmd_bphy_cgx_set_link_mode(uint16_t dev_id, uint16_t lmac,
* The identifier of the device
* @param lmac
* LMAC number for operation
* @param up
* @param state
* Link state to set
*
* @return
* Returns 0 on success, negative error code otherwise
*/
static __rte_always_inline int
rte_pmd_bphy_cgx_set_link_state(uint16_t dev_id, uint16_t lmac, bool up)
rte_pmd_bphy_cgx_set_link_state(uint16_t dev_id, uint16_t lmac,
struct cnxk_bphy_cgx_msg_set_link_state *state)
{
struct cnxk_bphy_cgx_msg_set_link_state state = {
.state = up,
};
struct cnxk_bphy_cgx_msg msg = {
.type = CNXK_BPHY_CGX_MSG_TYPE_SET_LINK_STATE,
.data = &state,
.data = state,
};

return __rte_pmd_bphy_enq_deq(dev_id, lmac, &msg, NULL, 0);
Expand Down

0 comments on commit 7d3daa3

Please sign in to comment.