net/sfc/base: simplify NVRAM type to partition mappings
authorAndy Moreton <amoreton@solarflare.com>
Thu, 16 Nov 2017 08:03:56 +0000 (08:03 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 16 Jan 2018 17:47:49 +0000 (18:47 +0100)
Signed-off-by: Andy Moreton <amoreton@solarflare.com>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
drivers/net/sfc/base/ef10_nvram.c

index 0d742ab..fdd7646 100644 (file)
@@ -2106,83 +2106,47 @@ fail1:
 
 typedef struct ef10_parttbl_entry_s {
        unsigned int            partn;
-       unsigned int            port;
+       unsigned int            port_mask;
        efx_nvram_type_t        nvtype;
 } ef10_parttbl_entry_t;
 
+/* Port mask values */
+#define        PORT_1          (1u << 1)
+#define        PORT_2          (1u << 2)
+#define        PORT_3          (1u << 3)
+#define        PORT_4          (1u << 4)
+#define        PORT_ALL        (0xffffffffu)
+
+#define        PARTN_MAP_ENTRY(partn, port_mask, nvtype)       \
+{ (NVRAM_PARTITION_TYPE_##partn), (PORT_##port_mask), (EFX_NVRAM_##nvtype) }
+
 /* Translate EFX NVRAM types to firmware partition types */
 static ef10_parttbl_entry_t hunt_parttbl[] = {
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE,         1, EFX_NVRAM_MC_FIRMWARE},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE,         2, EFX_NVRAM_MC_FIRMWARE},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE,         3, EFX_NVRAM_MC_FIRMWARE},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE,         4, EFX_NVRAM_MC_FIRMWARE},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP,  1, EFX_NVRAM_MC_GOLDEN},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP,  2, EFX_NVRAM_MC_GOLDEN},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP,  3, EFX_NVRAM_MC_GOLDEN},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP,  4, EFX_NVRAM_MC_GOLDEN},
-       {NVRAM_PARTITION_TYPE_EXPANSION_ROM,       1, EFX_NVRAM_BOOTROM},
-       {NVRAM_PARTITION_TYPE_EXPANSION_ROM,       2, EFX_NVRAM_BOOTROM},
-       {NVRAM_PARTITION_TYPE_EXPANSION_ROM,       3, EFX_NVRAM_BOOTROM},
-       {NVRAM_PARTITION_TYPE_EXPANSION_ROM,       4, EFX_NVRAM_BOOTROM},
-       {NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 1, EFX_NVRAM_BOOTROM_CFG},
-       {NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 2, EFX_NVRAM_BOOTROM_CFG},
-       {NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 3, EFX_NVRAM_BOOTROM_CFG},
-       {NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 4, EFX_NVRAM_BOOTROM_CFG},
-       {NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,      1, EFX_NVRAM_DYNAMIC_CFG},
-       {NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,      2, EFX_NVRAM_DYNAMIC_CFG},
-       {NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,      3, EFX_NVRAM_DYNAMIC_CFG},
-       {NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,      4, EFX_NVRAM_DYNAMIC_CFG},
-       {NVRAM_PARTITION_TYPE_FPGA,                1, EFX_NVRAM_FPGA},
-       {NVRAM_PARTITION_TYPE_FPGA,                2, EFX_NVRAM_FPGA},
-       {NVRAM_PARTITION_TYPE_FPGA,                3, EFX_NVRAM_FPGA},
-       {NVRAM_PARTITION_TYPE_FPGA,                4, EFX_NVRAM_FPGA},
-       {NVRAM_PARTITION_TYPE_FPGA_BACKUP,         1, EFX_NVRAM_FPGA_BACKUP},
-       {NVRAM_PARTITION_TYPE_FPGA_BACKUP,         2, EFX_NVRAM_FPGA_BACKUP},
-       {NVRAM_PARTITION_TYPE_FPGA_BACKUP,         3, EFX_NVRAM_FPGA_BACKUP},
-       {NVRAM_PARTITION_TYPE_FPGA_BACKUP,         4, EFX_NVRAM_FPGA_BACKUP},
-       {NVRAM_PARTITION_TYPE_LICENSE,             1, EFX_NVRAM_LICENSE},
-       {NVRAM_PARTITION_TYPE_LICENSE,             2, EFX_NVRAM_LICENSE},
-       {NVRAM_PARTITION_TYPE_LICENSE,             3, EFX_NVRAM_LICENSE},
-       {NVRAM_PARTITION_TYPE_LICENSE,             4, EFX_NVRAM_LICENSE}
+       /*              partn                   ports   nvtype */
+       PARTN_MAP_ENTRY(MC_FIRMWARE,            ALL,    MC_FIRMWARE),
+       PARTN_MAP_ENTRY(MC_FIRMWARE_BACKUP,     ALL,    MC_GOLDEN),
+       PARTN_MAP_ENTRY(EXPANSION_ROM,          ALL,    BOOTROM),
+       PARTN_MAP_ENTRY(EXPROM_CONFIG_PORT0,    1,      BOOTROM_CFG),
+       PARTN_MAP_ENTRY(EXPROM_CONFIG_PORT1,    2,      BOOTROM_CFG),
+       PARTN_MAP_ENTRY(EXPROM_CONFIG_PORT2,    3,      BOOTROM_CFG),
+       PARTN_MAP_ENTRY(EXPROM_CONFIG_PORT3,    4,      BOOTROM_CFG),
+       PARTN_MAP_ENTRY(DYNAMIC_CONFIG,         ALL,    DYNAMIC_CFG),
+       PARTN_MAP_ENTRY(FPGA,                   ALL,    FPGA),
+       PARTN_MAP_ENTRY(FPGA_BACKUP,            ALL,    FPGA_BACKUP),
+       PARTN_MAP_ENTRY(LICENSE,                ALL,    LICENSE),
 };
 
 static ef10_parttbl_entry_t medford_parttbl[] = {
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE,         1, EFX_NVRAM_MC_FIRMWARE},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE,         2, EFX_NVRAM_MC_FIRMWARE},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE,         3, EFX_NVRAM_MC_FIRMWARE},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE,         4, EFX_NVRAM_MC_FIRMWARE},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP,  1, EFX_NVRAM_MC_GOLDEN},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP,  2, EFX_NVRAM_MC_GOLDEN},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP,  3, EFX_NVRAM_MC_GOLDEN},
-       {NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP,  4, EFX_NVRAM_MC_GOLDEN},
-       {NVRAM_PARTITION_TYPE_EXPANSION_ROM,       1, EFX_NVRAM_BOOTROM},
-       {NVRAM_PARTITION_TYPE_EXPANSION_ROM,       2, EFX_NVRAM_BOOTROM},
-       {NVRAM_PARTITION_TYPE_EXPANSION_ROM,       3, EFX_NVRAM_BOOTROM},
-       {NVRAM_PARTITION_TYPE_EXPANSION_ROM,       4, EFX_NVRAM_BOOTROM},
-       {NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 1, EFX_NVRAM_BOOTROM_CFG},
-       {NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 2, EFX_NVRAM_BOOTROM_CFG},
-       {NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 3, EFX_NVRAM_BOOTROM_CFG},
-       {NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 4, EFX_NVRAM_BOOTROM_CFG},
-       {NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,      1, EFX_NVRAM_DYNAMIC_CFG},
-       {NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,      2, EFX_NVRAM_DYNAMIC_CFG},
-       {NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,      3, EFX_NVRAM_DYNAMIC_CFG},
-       {NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG,      4, EFX_NVRAM_DYNAMIC_CFG},
-       {NVRAM_PARTITION_TYPE_FPGA,                1, EFX_NVRAM_FPGA},
-       {NVRAM_PARTITION_TYPE_FPGA,                2, EFX_NVRAM_FPGA},
-       {NVRAM_PARTITION_TYPE_FPGA,                3, EFX_NVRAM_FPGA},
-       {NVRAM_PARTITION_TYPE_FPGA,                4, EFX_NVRAM_FPGA},
-       {NVRAM_PARTITION_TYPE_FPGA_BACKUP,         1, EFX_NVRAM_FPGA_BACKUP},
-       {NVRAM_PARTITION_TYPE_FPGA_BACKUP,         2, EFX_NVRAM_FPGA_BACKUP},
-       {NVRAM_PARTITION_TYPE_FPGA_BACKUP,         3, EFX_NVRAM_FPGA_BACKUP},
-       {NVRAM_PARTITION_TYPE_FPGA_BACKUP,         4, EFX_NVRAM_FPGA_BACKUP},
-       {NVRAM_PARTITION_TYPE_LICENSE,             1, EFX_NVRAM_LICENSE},
-       {NVRAM_PARTITION_TYPE_LICENSE,             2, EFX_NVRAM_LICENSE},
-       {NVRAM_PARTITION_TYPE_LICENSE,             3, EFX_NVRAM_LICENSE},
-       {NVRAM_PARTITION_TYPE_LICENSE,             4, EFX_NVRAM_LICENSE},
-       {NVRAM_PARTITION_TYPE_EXPANSION_UEFI,      1, EFX_NVRAM_UEFIROM},
-       {NVRAM_PARTITION_TYPE_EXPANSION_UEFI,      2, EFX_NVRAM_UEFIROM},
-       {NVRAM_PARTITION_TYPE_EXPANSION_UEFI,      3, EFX_NVRAM_UEFIROM},
-       {NVRAM_PARTITION_TYPE_EXPANSION_UEFI,      4, EFX_NVRAM_UEFIROM}
+       /*              partn                   ports   nvtype */
+       PARTN_MAP_ENTRY(MC_FIRMWARE,            ALL,    MC_FIRMWARE),
+       PARTN_MAP_ENTRY(MC_FIRMWARE_BACKUP,     ALL,    MC_GOLDEN),
+       PARTN_MAP_ENTRY(EXPANSION_ROM,          ALL,    BOOTROM),
+       PARTN_MAP_ENTRY(EXPROM_CONFIG,          ALL,    BOOTROM_CFG),
+       PARTN_MAP_ENTRY(DYNAMIC_CONFIG,         ALL,    DYNAMIC_CFG),
+       PARTN_MAP_ENTRY(FPGA,                   ALL,    FPGA),
+       PARTN_MAP_ENTRY(FPGA_BACKUP,            ALL,    FPGA_BACKUP),
+       PARTN_MAP_ENTRY(LICENSE,                ALL,    LICENSE),
+       PARTN_MAP_ENTRY(EXPANSION_UEFI,         ALL,    UEFIROM),
 };
 
 static __checkReturn           efx_rc_t
@@ -2227,8 +2191,8 @@ ef10_nvram_type_to_partn(
                for (i = 0; i < parttbl_rows; i++) {
                        ef10_parttbl_entry_t *entry = &parttbl[i];
 
-                       if (entry->nvtype == type &&
-                           entry->port == emip->emi_port) {
+                       if ((entry->nvtype == type) &&
+                           (entry->port_mask & (1u << emip->emi_port))) {
                                *partnp = entry->partn;
                                return (0);
                        }
@@ -2257,8 +2221,8 @@ ef10_nvram_partn_to_type(
                for (i = 0; i < parttbl_rows; i++) {
                        ef10_parttbl_entry_t *entry = &parttbl[i];
 
-                       if (entry->partn == partn &&
-                           entry->port == emip->emi_port) {
+                       if ((entry->partn == partn) &&
+                           (entry->port_mask & (1u << emip->emi_port))) {
                                *typep = entry->nvtype;
                                return (0);
                        }