Skip to content

Commit

Permalink
net/nfp: add LED support
Browse files Browse the repository at this point in the history
Implement the necessary functions to allow user to visually identify a
physical port associated with a netdev by blinking an LED on that port.

Signed-off-by: James Hershaw <[email protected]>
Signed-off-by: Chaoyong He <[email protected]>
  • Loading branch information
hechaoyong authored and ferruhy committed Nov 6, 2024
1 parent 6e3e1d0 commit 9982462
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/guides/nics/features/nfp.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Basic stats = Y
Stats per queue = Y
EEPROM dump = Y
Module EEPROM dump = Y
LED = Y
Linux = Y
Multiprocess aware = Y
x86-64 = Y
Expand Down
30 changes: 30 additions & 0 deletions drivers/net/nfp/flower/nfp_flower_representor.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ nfp_repr_get_module_eeprom(struct rte_eth_dev *dev,
return nfp_net_get_module_eeprom(dev, info);
}

static int
nfp_flower_repr_led_on(struct rte_eth_dev *dev)
{
struct nfp_flower_representor *repr;

repr = dev->data->dev_private;
if (!nfp_flower_repr_is_phy(repr))
return -EOPNOTSUPP;

return nfp_net_led_on(dev);
}

static int
nfp_flower_repr_led_off(struct rte_eth_dev *dev)
{
struct nfp_flower_representor *repr;

repr = dev->data->dev_private;
if (!nfp_flower_repr_is_phy(repr))
return -EOPNOTSUPP;

return nfp_net_led_off(dev);
}

static int
nfp_flower_repr_link_update(struct rte_eth_dev *dev,
__rte_unused int wait_to_complete)
Expand Down Expand Up @@ -623,6 +647,9 @@ static const struct eth_dev_ops nfp_flower_multiple_pf_repr_dev_ops = {
.set_eeprom = nfp_repr_set_eeprom,
.get_module_info = nfp_repr_get_module_info,
.get_module_eeprom = nfp_repr_get_module_eeprom,

.dev_led_on = nfp_flower_repr_led_on,
.dev_led_off = nfp_flower_repr_led_off,
};

static const struct eth_dev_ops nfp_flower_repr_dev_ops = {
Expand Down Expand Up @@ -661,6 +688,9 @@ static const struct eth_dev_ops nfp_flower_repr_dev_ops = {
.set_eeprom = nfp_repr_set_eeprom,
.get_module_info = nfp_repr_get_module_info,
.get_module_eeprom = nfp_repr_get_module_eeprom,

.dev_led_on = nfp_flower_repr_led_on,
.dev_led_off = nfp_flower_repr_led_off,
};

static uint32_t
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/nfp/nfp_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,8 @@ static const struct eth_dev_ops nfp_net_eth_dev_ops = {
.set_eeprom = nfp_net_set_eeprom,
.get_module_info = nfp_net_get_module_info,
.get_module_eeprom = nfp_net_get_module_eeprom,
.dev_led_on = nfp_net_led_on,
.dev_led_off = nfp_net_led_off,
};

static inline void
Expand Down
32 changes: 32 additions & 0 deletions drivers/net/nfp/nfp_net_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3181,3 +3181,35 @@ nfp_net_get_module_eeprom(struct rte_eth_dev *dev,
nfp_nsp_close(nsp);
return ret;
}

static int
nfp_net_led_control(struct rte_eth_dev *dev,
bool is_on)
{
int ret;
uint32_t nfp_idx;
struct nfp_net_hw_priv *hw_priv;

hw_priv = dev->process_private;
nfp_idx = nfp_net_get_nfp_index(dev);

ret = nfp_eth_set_idmode(hw_priv->pf_dev->cpp, nfp_idx, is_on);
if (ret < 0) {
PMD_DRV_LOG(ERR, "Set nfp idmode failed.");
return ret;
}

return 0;
}

int
nfp_net_led_on(struct rte_eth_dev *dev)
{
return nfp_net_led_control(dev, true);
}

int
nfp_net_led_off(struct rte_eth_dev *dev)
{
return nfp_net_led_control(dev, false);
}
2 changes: 2 additions & 0 deletions drivers/net/nfp/nfp_net_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ int nfp_net_get_eeprom(struct rte_eth_dev *dev, struct rte_dev_eeprom_info *eepr
int nfp_net_set_eeprom(struct rte_eth_dev *dev, struct rte_dev_eeprom_info *eeprom);
int nfp_net_get_module_info(struct rte_eth_dev *dev, struct rte_eth_dev_module_info *info);
int nfp_net_get_module_eeprom(struct rte_eth_dev *dev, struct rte_dev_eeprom_info *info);
int nfp_net_led_on(struct rte_eth_dev *dev);
int nfp_net_led_off(struct rte_eth_dev *dev);

#define NFP_PRIV_TO_APP_FW_NIC(app_fw_priv)\
((struct nfp_app_fw_nic *)app_fw_priv)
Expand Down
1 change: 1 addition & 0 deletions drivers/net/nfp/nfpcore/nfp_nsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ int nfp_eth_set_speed(struct nfp_nsp *nsp, uint32_t speed);
int nfp_eth_set_split(struct nfp_nsp *nsp, uint32_t lanes);
int nfp_eth_set_tx_pause(struct nfp_nsp *nsp, bool tx_pause);
int nfp_eth_set_rx_pause(struct nfp_nsp *nsp, bool rx_pause);
int nfp_eth_set_idmode(struct nfp_cpp *cpp, uint32_t idx, bool is_on);

/* NSP static information */
struct nfp_nsp_identify {
Expand Down
36 changes: 36 additions & 0 deletions drivers/net/nfp/nfpcore/nfp_nsp_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#define NSP_ETH_CTRL_SET_LANES RTE_BIT64(5)
#define NSP_ETH_CTRL_SET_ANEG RTE_BIT64(6)
#define NSP_ETH_CTRL_SET_FEC RTE_BIT64(7)
#define NSP_ETH_CTRL_SET_IDMODE RTE_BIT64(8)
#define NSP_ETH_CTRL_SET_TX_PAUSE RTE_BIT64(10)
#define NSP_ETH_CTRL_SET_RX_PAUSE RTE_BIT64(11)

Expand Down Expand Up @@ -736,3 +737,38 @@ nfp_eth_set_rx_pause(struct nfp_nsp *nsp,
return NFP_ETH_SET_BIT_CONFIG(nsp, NSP_ETH_RAW_STATE,
NSP_ETH_STATE_RX_PAUSE, rx_pause, NSP_ETH_CTRL_SET_RX_PAUSE);
}

int
nfp_eth_set_idmode(struct nfp_cpp *cpp,
uint32_t idx,
bool is_on)
{
uint64_t reg;
struct nfp_nsp *nsp;
union eth_table_entry *entries;

nsp = nfp_eth_config_start(cpp, idx);
if (nsp == NULL)
return -EIO;

/*
* Older ABI versions did support this feature, however this has only
* been reliable since ABI 32.
*/
if (nfp_nsp_get_abi_ver_minor(nsp) < 32) {
PMD_DRV_LOG(ERR, "Operation only supported on ABI 32 or newer.");
nfp_eth_config_cleanup_end(nsp);
return -ENOTSUP;
}

entries = nfp_nsp_config_entries(nsp);

reg = rte_le_to_cpu_64(entries[idx].control);
reg &= ~NSP_ETH_CTRL_SET_IDMODE;
reg |= FIELD_PREP(NSP_ETH_CTRL_SET_IDMODE, is_on);
entries[idx].control = rte_cpu_to_le_64(reg);

nfp_nsp_config_set_modified(nsp, 1);

return nfp_eth_config_commit_end(nsp);
}

0 comments on commit 9982462

Please sign in to comment.