From e86b48aa46d4f0df25bb02789647d0ce61551a4d Mon Sep 17 00:00:00 2001 From: Ivan Malov Date: Tue, 20 Oct 2020 10:13:22 +0100 Subject: [PATCH] net/sfc: add HW switch ID helpers The driver will need a means to figure out relationship between RTE ethdev instances and underlying HW switch entities. For now, use board serial number string as a unique HW switch identifier. Signed-off-by: Ivan Malov Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- drivers/net/sfc/sfc.c | 44 +++++++++++++++++++++++++++++++++++++++++++ drivers/net/sfc/sfc.h | 8 ++++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c index 3b896490f7..a4fe495788 100644 --- a/drivers/net/sfc/sfc.c +++ b/drivers/net/sfc/sfc.c @@ -1259,3 +1259,47 @@ sfc_register_logtype(const struct rte_pci_addr *pci_addr, return ret; } + +struct sfc_hw_switch_id { + char board_sn[RTE_SIZEOF_FIELD(efx_nic_board_info_t, enbi_serial)]; +}; + +int +sfc_hw_switch_id_init(struct sfc_adapter *sa, + struct sfc_hw_switch_id **idp) +{ + efx_nic_board_info_t board_info; + struct sfc_hw_switch_id *id; + int rc; + + if (idp == NULL) + return EINVAL; + + id = rte_zmalloc("sfc_hw_switch_id", sizeof(*id), 0); + if (id == NULL) + return ENOMEM; + + rc = efx_nic_get_board_info(sa->nic, &board_info); + if (rc != 0) + return rc; + + memcpy(id->board_sn, board_info.enbi_serial, sizeof(id->board_sn)); + + *idp = id; + + return 0; +} + +void +sfc_hw_switch_id_fini(__rte_unused struct sfc_adapter *sa, + struct sfc_hw_switch_id *id) +{ + rte_free(id); +} + +bool +sfc_hw_switch_ids_equal(const struct sfc_hw_switch_id *left, + const struct sfc_hw_switch_id *right) +{ + return strcmp(left->board_sn, right->board_sn) == 0; +} diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index 4b5d687108..ed059e142f 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -403,6 +403,14 @@ int sfc_port_reset_mac_stats(struct sfc_adapter *sa); int sfc_set_rx_mode(struct sfc_adapter *sa); int sfc_set_rx_mode_unchecked(struct sfc_adapter *sa); +struct sfc_hw_switch_id; + +int sfc_hw_switch_id_init(struct sfc_adapter *sa, + struct sfc_hw_switch_id **idp); +void sfc_hw_switch_id_fini(struct sfc_adapter *sa, + struct sfc_hw_switch_id *idp); +bool sfc_hw_switch_ids_equal(const struct sfc_hw_switch_id *left, + const struct sfc_hw_switch_id *right); #ifdef __cplusplus } -- 2.20.1