net/sfc: add HW switch ID helpers
authorIvan Malov <ivan.malov@oktetlabs.ru>
Tue, 20 Oct 2020 09:13:22 +0000 (10:13 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 3 Nov 2020 22:24:25 +0000 (23:24 +0100)
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 <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
drivers/net/sfc/sfc.c
drivers/net/sfc/sfc.h

index 3b89649..a4fe495 100644 (file)
@@ -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;
+}
index 4b5d687..ed059e1 100644 (file)
@@ -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
 }