net/atlantic: enable broadcast traffic
[dpdk.git] / drivers / raw / ifpga_rawdev / base / ifpga_fme.c
index 95e022e..2b447fd 100644 (file)
@@ -12,7 +12,7 @@
 
 int fme_get_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop)
 {
-       struct feature *feature;
+       struct ifpga_feature *feature;
 
        if (!fme)
                return -ENOENT;
@@ -27,7 +27,7 @@ int fme_get_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop)
 
 int fme_set_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop)
 {
-       struct feature *feature;
+       struct ifpga_feature *feature;
 
        if (!fme)
                return -ENOENT;
@@ -42,7 +42,7 @@ int fme_set_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop)
 
 int fme_set_irq(struct ifpga_fme_hw *fme, u32 feature_id, void *irq_set)
 {
-       struct feature *feature;
+       struct ifpga_feature *feature;
 
        if (!fme)
                return -ENOENT;
@@ -56,7 +56,7 @@ int fme_set_irq(struct ifpga_fme_hw *fme, u32 feature_id, void *irq_set)
 }
 
 /* fme private feature head */
-static int fme_hdr_init(struct feature *feature)
+static int fme_hdr_init(struct ifpga_feature *feature)
 {
        struct feature_fme_header *fme_hdr;
 
@@ -69,7 +69,7 @@ static int fme_hdr_init(struct feature *feature)
        return 0;
 }
 
-static void fme_hdr_uinit(struct feature *feature)
+static void fme_hdr_uinit(struct ifpga_feature *feature)
 {
        UNUSED(feature);
 
@@ -159,7 +159,7 @@ static int fme_hdr_get_bitstream_metadata(struct ifpga_fme_hw *fme,
 }
 
 static int
-fme_hdr_get_prop(struct feature *feature, struct feature_prop *prop)
+fme_hdr_get_prop(struct ifpga_feature *feature, struct feature_prop *prop)
 {
        struct ifpga_fme_hw *fme = feature->parent;
 
@@ -183,7 +183,7 @@ fme_hdr_get_prop(struct feature *feature, struct feature_prop *prop)
        return -ENOENT;
 }
 
-struct feature_ops fme_hdr_ops = {
+struct ifpga_feature_ops fme_hdr_ops = {
        .init = fme_hdr_init,
        .uinit = fme_hdr_uinit,
        .get_prop = fme_hdr_get_prop,
@@ -404,7 +404,7 @@ static int fme_thermal_get_revision(struct ifpga_fme_hw *fme, u64 *revision)
 
 #define FME_THERMAL_CAP_NO_TMP_THRESHOLD       0x1
 
-static int fme_thermal_mgmt_init(struct feature *feature)
+static int fme_thermal_mgmt_init(struct ifpga_feature *feature)
 {
        struct feature_fme_thermal *fme_thermal;
        struct feature_fme_tmp_threshold_cap thermal_cap;
@@ -425,7 +425,7 @@ static int fme_thermal_mgmt_init(struct feature *feature)
        return 0;
 }
 
-static void fme_thermal_mgmt_uinit(struct feature *feature)
+static void fme_thermal_mgmt_uinit(struct ifpga_feature *feature)
 {
        UNUSED(feature);
 
@@ -433,7 +433,7 @@ static void fme_thermal_mgmt_uinit(struct feature *feature)
 }
 
 static int
-fme_thermal_set_prop(struct feature *feature, struct feature_prop *prop)
+fme_thermal_set_prop(struct ifpga_feature *feature, struct feature_prop *prop)
 {
        struct ifpga_fme_hw *fme = feature->parent;
 
@@ -453,7 +453,7 @@ fme_thermal_set_prop(struct feature *feature, struct feature_prop *prop)
 }
 
 static int
-fme_thermal_get_prop(struct feature *feature, struct feature_prop *prop)
+fme_thermal_get_prop(struct ifpga_feature *feature, struct feature_prop *prop)
 {
        struct ifpga_fme_hw *fme = feature->parent;
 
@@ -484,7 +484,7 @@ fme_thermal_get_prop(struct feature *feature, struct feature_prop *prop)
        return -ENOENT;
 }
 
-struct feature_ops fme_thermal_mgmt_ops = {
+struct ifpga_feature_ops fme_thermal_mgmt_ops = {
        .init = fme_thermal_mgmt_init,
        .uinit = fme_thermal_mgmt_uinit,
        .get_prop = fme_thermal_get_prop,
@@ -670,7 +670,7 @@ static int fme_pwr_get_revision(struct ifpga_fme_hw *fme, u64 *revision)
        return 0;
 }
 
-static int fme_power_mgmt_init(struct feature *feature)
+static int fme_power_mgmt_init(struct ifpga_feature *feature)
 {
        UNUSED(feature);
 
@@ -679,14 +679,14 @@ static int fme_power_mgmt_init(struct feature *feature)
        return 0;
 }
 
-static void fme_power_mgmt_uinit(struct feature *feature)
+static void fme_power_mgmt_uinit(struct ifpga_feature *feature)
 {
        UNUSED(feature);
 
        dev_info(NULL, "FME power mgmt UInit.\n");
 }
 
-static int fme_power_mgmt_get_prop(struct feature *feature,
+static int fme_power_mgmt_get_prop(struct ifpga_feature *feature,
                                   struct feature_prop *prop)
 {
        struct ifpga_fme_hw *fme = feature->parent;
@@ -715,7 +715,7 @@ static int fme_power_mgmt_get_prop(struct feature *feature,
        return -ENOENT;
 }
 
-static int fme_power_mgmt_set_prop(struct feature *feature,
+static int fme_power_mgmt_set_prop(struct ifpga_feature *feature,
                                   struct feature_prop *prop)
 {
        struct ifpga_fme_hw *fme = feature->parent;
@@ -730,45 +730,129 @@ static int fme_power_mgmt_set_prop(struct feature *feature,
        return -ENOENT;
 }
 
-struct feature_ops fme_power_mgmt_ops = {
+struct ifpga_feature_ops fme_power_mgmt_ops = {
        .init = fme_power_mgmt_init,
        .uinit = fme_power_mgmt_uinit,
        .get_prop = fme_power_mgmt_get_prop,
        .set_prop = fme_power_mgmt_set_prop,
 };
 
-static int fme_hssi_eth_init(struct feature *feature)
+static int fme_hssi_eth_init(struct ifpga_feature *feature)
 {
        UNUSED(feature);
        return 0;
 }
 
-static void fme_hssi_eth_uinit(struct feature *feature)
+static void fme_hssi_eth_uinit(struct ifpga_feature *feature)
 {
        UNUSED(feature);
 }
 
-struct feature_ops fme_hssi_eth_ops = {
+struct ifpga_feature_ops fme_hssi_eth_ops = {
        .init = fme_hssi_eth_init,
        .uinit = fme_hssi_eth_uinit,
 };
 
-static int fme_emif_init(struct feature *feature)
+static int fme_emif_init(struct ifpga_feature *feature)
 {
        UNUSED(feature);
        return 0;
 }
 
-static void fme_emif_uinit(struct feature *feature)
+static void fme_emif_uinit(struct ifpga_feature *feature)
 {
        UNUSED(feature);
 }
 
-struct feature_ops fme_emif_ops = {
+struct ifpga_feature_ops fme_emif_ops = {
        .init = fme_emif_init,
        .uinit = fme_emif_uinit,
 };
 
+static const char *board_type_to_string(u32 type)
+{
+       switch (type) {
+       case VC_8_10G:
+               return "VC_8x10G";
+       case VC_4_25G:
+               return "VC_4x25G";
+       case VC_2_1_25:
+               return "VC_2x1x25G";
+       case VC_4_25G_2_25G:
+               return "VC_4x25G+2x25G";
+       case VC_2_2_25G:
+               return "VC_2x2x25G";
+       }
+
+       return "unknown";
+}
+
+static int board_type_to_info(u32 type,
+               struct ifpga_fme_board_info *info)
+{
+       switch (type) {
+       case VC_8_10G:
+               info->nums_of_retimer = 2;
+               info->ports_per_retimer = 4;
+               info->nums_of_fvl = 2;
+               info->ports_per_fvl = 4;
+               break;
+       case VC_4_25G:
+               info->nums_of_retimer = 1;
+               info->ports_per_retimer = 4;
+               info->nums_of_fvl = 2;
+               info->ports_per_fvl = 2;
+               break;
+       case VC_2_1_25:
+               info->nums_of_retimer = 2;
+               info->ports_per_retimer = 1;
+               info->nums_of_fvl = 1;
+               info->ports_per_fvl = 2;
+               break;
+       case VC_2_2_25G:
+               info->nums_of_retimer = 2;
+               info->ports_per_retimer = 2;
+               info->nums_of_fvl = 2;
+               info->ports_per_fvl = 2;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int fme_get_board_interface(struct ifpga_fme_hw *fme)
+{
+       struct fme_bitstream_id id;
+
+       if (fme_hdr_get_bitstream_id(fme, &id.id))
+               return -EINVAL;
+
+       fme->board_info.type = id.interface;
+       fme->board_info.build_hash = id.hash;
+       fme->board_info.debug_version = id.debug;
+       fme->board_info.major_version = id.major;
+       fme->board_info.minor_version = id.minor;
+
+       dev_info(fme, "board type: %s major_version:%u minor_version:%u build_hash:%u\n",
+                       board_type_to_string(fme->board_info.type),
+                       fme->board_info.major_version,
+                       fme->board_info.minor_version,
+                       fme->board_info.build_hash);
+
+       if (board_type_to_info(fme->board_info.type, &fme->board_info))
+               return -EINVAL;
+
+       dev_info(fme, "get board info: nums_retimers %d ports_per_retimer %d nums_fvl %d ports_per_fvl %d\n",
+                       fme->board_info.nums_of_retimer,
+                       fme->board_info.ports_per_retimer,
+                       fme->board_info.nums_of_fvl,
+                       fme->board_info.ports_per_fvl);
+
+       return 0;
+}
+
 static int spi_self_checking(void)
 {
        u32 val;
@@ -788,7 +872,7 @@ static int spi_self_checking(void)
        return 0;
 }
 
-static int fme_spi_init(struct feature *feature)
+static int fme_spi_init(struct ifpga_feature *feature)
 {
        struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;
        struct altera_spi_device *spi_master;
@@ -831,7 +915,7 @@ spi_fail:
        return ret;
 }
 
-static void fme_spi_uinit(struct feature *feature)
+static void fme_spi_uinit(struct ifpga_feature *feature)
 {
        struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;
 
@@ -839,7 +923,7 @@ static void fme_spi_uinit(struct feature *feature)
                intel_max10_device_remove(fme->max10_dev);
 }
 
-struct feature_ops fme_spi_master_ops = {
+struct ifpga_feature_ops fme_spi_master_ops = {
        .init = fme_spi_init,
        .uinit = fme_spi_uinit,
 };
@@ -891,7 +975,7 @@ static int nios_spi_check_error(struct altera_spi_device *dev)
        return 0;
 }
 
-static int fme_nios_spi_init(struct feature *feature)
+static int fme_nios_spi_init(struct ifpga_feature *feature)
 {
        struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;
        struct altera_spi_device *spi_master;
@@ -935,6 +1019,8 @@ static int fme_nios_spi_init(struct feature *feature)
                goto release_dev;
        }
 
+       fme_get_board_interface(fme);
+
        fme->max10_dev = max10;
 
        /* SPI self test */
@@ -950,7 +1036,7 @@ release_dev:
        return -ENODEV;
 }
 
-static void fme_nios_spi_uinit(struct feature *feature)
+static void fme_nios_spi_uinit(struct ifpga_feature *feature)
 {
        struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;
 
@@ -958,7 +1044,7 @@ static void fme_nios_spi_uinit(struct feature *feature)
                intel_max10_device_remove(fme->max10_dev);
 }
 
-struct feature_ops fme_nios_spi_master_ops = {
+struct ifpga_feature_ops fme_nios_spi_master_ops = {
        .init = fme_nios_spi_init,
        .uinit = fme_nios_spi_uinit,
 };
@@ -996,7 +1082,7 @@ static int i2c_mac_rom_test(struct altera_i2c_dev *dev)
        return 0;
 }
 
-static int fme_i2c_init(struct feature *feature)
+static int fme_i2c_init(struct ifpga_feature *feature)
 {
        struct feature_fme_i2c *i2c;
        struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;
@@ -1015,18 +1101,57 @@ static int fme_i2c_init(struct feature *feature)
        return 0;
 }
 
-static void fme_i2c_uninit(struct feature *feature)
+static void fme_i2c_uninit(struct ifpga_feature *feature)
 {
        struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;
 
        altera_i2c_remove(fme->i2c_master);
 }
 
-struct feature_ops fme_i2c_master_ops = {
+struct ifpga_feature_ops fme_i2c_master_ops = {
        .init = fme_i2c_init,
        .uinit = fme_i2c_uninit,
 };
 
+static int fme_eth_group_init(struct ifpga_feature *feature)
+{
+       struct ifpga_fme_hw *fme = (struct ifpga_fme_hw *)feature->parent;
+       struct eth_group_device *dev;
+
+       dev = (struct eth_group_device *)eth_group_probe(feature->addr);
+       if (!dev)
+               return -ENODEV;
+
+       fme->eth_dev[dev->group_id] = dev;
+
+       fme->eth_group_region[dev->group_id].addr =
+               feature->addr;
+       fme->eth_group_region[dev->group_id].phys_addr =
+               feature->phys_addr;
+       fme->eth_group_region[dev->group_id].len =
+               feature->size;
+
+       fme->nums_eth_dev++;
+
+       dev_info(NULL, "FME PHY Group %d Init.\n", dev->group_id);
+       dev_info(NULL, "found %d eth group, addr %p phys_addr 0x%llx len %u\n",
+                       dev->group_id, feature->addr,
+                       (unsigned long long)feature->phys_addr,
+                       feature->size);
+
+       return 0;
+}
+
+static void fme_eth_group_uinit(struct ifpga_feature *feature)
+{
+       UNUSED(feature);
+}
+
+struct ifpga_feature_ops fme_eth_group_ops = {
+       .init = fme_eth_group_init,
+       .uinit = fme_eth_group_uinit,
+};
+
 int fme_mgr_read_mac_rom(struct ifpga_fme_hw *fme, int offset,
                void *buf, int size)
 {
@@ -1050,3 +1175,128 @@ int fme_mgr_write_mac_rom(struct ifpga_fme_hw *fme, int offset,
 
        return at24_eeprom_write(dev, AT24512_SLAVE_ADDR, offset, buf, size);
 }
+
+static struct eth_group_device *get_eth_group_dev(struct ifpga_fme_hw *fme,
+               u8 group_id)
+{
+       struct eth_group_device *dev;
+
+       if (group_id > (MAX_ETH_GROUP_DEVICES - 1))
+               return NULL;
+
+       dev = (struct eth_group_device *)fme->eth_dev[group_id];
+       if (!dev)
+               return NULL;
+
+       if (dev->status != ETH_GROUP_DEV_ATTACHED)
+               return NULL;
+
+       return dev;
+}
+
+int fme_mgr_get_eth_group_nums(struct ifpga_fme_hw *fme)
+{
+       return fme->nums_eth_dev;
+}
+
+int fme_mgr_get_eth_group_info(struct ifpga_fme_hw *fme,
+               u8 group_id, struct opae_eth_group_info *info)
+{
+       struct eth_group_device *dev;
+
+       dev = get_eth_group_dev(fme, group_id);
+       if (!dev)
+               return -ENODEV;
+
+       info->group_id = group_id;
+       info->speed = dev->speed;
+       info->nums_of_mac = dev->mac_num;
+       info->nums_of_phy = dev->phy_num;
+
+       return 0;
+}
+
+int fme_mgr_eth_group_read_reg(struct ifpga_fme_hw *fme, u8 group_id,
+               u8 type, u8 index, u16 addr, u32 *data)
+{
+       struct eth_group_device *dev;
+
+       dev = get_eth_group_dev(fme, group_id);
+       if (!dev)
+               return -ENODEV;
+
+       return eth_group_read_reg(dev, type, index, addr, data);
+}
+
+int fme_mgr_eth_group_write_reg(struct ifpga_fme_hw *fme, u8 group_id,
+               u8 type, u8 index, u16 addr, u32 data)
+{
+       struct eth_group_device *dev;
+
+       dev = get_eth_group_dev(fme, group_id);
+       if (!dev)
+               return -ENODEV;
+
+       return eth_group_write_reg(dev, type, index, addr, data);
+}
+
+static int fme_get_eth_group_speed(struct ifpga_fme_hw *fme,
+               u8 group_id)
+{
+       struct eth_group_device *dev;
+
+       dev = get_eth_group_dev(fme, group_id);
+       if (!dev)
+               return -ENODEV;
+
+       return dev->speed;
+}
+
+int fme_mgr_get_retimer_info(struct ifpga_fme_hw *fme,
+               struct opae_retimer_info *info)
+{
+       struct intel_max10_device *dev;
+
+       dev = (struct intel_max10_device *)fme->max10_dev;
+       if (!dev)
+               return -ENODEV;
+
+       info->nums_retimer = fme->board_info.nums_of_retimer;
+       info->ports_per_retimer = fme->board_info.ports_per_retimer;
+       info->nums_fvl = fme->board_info.nums_of_fvl;
+       info->ports_per_fvl = fme->board_info.ports_per_fvl;
+
+       /* The speed of PKVL is identical the eth group's speed */
+       info->support_speed = fme_get_eth_group_speed(fme,
+                       LINE_SIDE_GROUP_ID);
+
+       return 0;
+}
+
+int fme_mgr_get_retimer_status(struct ifpga_fme_hw *fme,
+               struct opae_retimer_status *status)
+{
+       struct intel_max10_device *dev;
+       unsigned int val;
+
+       dev = (struct intel_max10_device *)fme->max10_dev;
+       if (!dev)
+               return -ENODEV;
+
+       if (max10_reg_read(PKVL_LINK_STATUS, &val)) {
+               dev_err(dev, "%s: read pkvl status fail\n", __func__);
+               return -EINVAL;
+       }
+
+       /* The speed of PKVL is identical the eth group's speed */
+       status->speed = fme_get_eth_group_speed(fme,
+                       LINE_SIDE_GROUP_ID);
+
+       status->line_link_bitmap = val;
+
+       dev_debug(dev, "get retimer status: speed:%d. line_link_bitmap:0x%x\n",
+                       status->speed,
+                       status->line_link_bitmap);
+
+       return 0;
+}