+
+ if (enable) {
+ /* If vlanid is already set, just return */
+ if (hinic_find_vlan_filter(nic_dev, vlan_id)) {
+ PMD_DRV_LOG(INFO, "Vlan %u has been added, device: %s",
+ vlan_id, nic_dev->proc_dev_name);
+ return 0;
+ }
+
+ err = hinic_add_remove_vlan(nic_dev->hwdev, vlan_id,
+ func_id, TRUE);
+ } else {
+ /* If vlanid can't be found, just return */
+ if (!hinic_find_vlan_filter(nic_dev, vlan_id)) {
+ PMD_DRV_LOG(INFO, "Vlan %u is not in the vlan filter list, device: %s",
+ vlan_id, nic_dev->proc_dev_name);
+ return 0;
+ }
+
+ err = hinic_add_remove_vlan(nic_dev->hwdev, vlan_id,
+ func_id, FALSE);
+ }
+
+ if (err) {
+ PMD_DRV_LOG(ERR, "%s vlan failed, func_id: %d, vlan_id: %d, err: %d",
+ enable ? "Add" : "Remove", func_id, vlan_id, err);
+ return err;
+ }
+
+ hinic_store_vlan_filter(nic_dev, vlan_id, enable);
+
+ PMD_DRV_LOG(INFO, "%s vlan %u succeed, device: %s",
+ enable ? "Add" : "Remove", vlan_id, nic_dev->proc_dev_name);
+ return 0;
+}
+
+/**
+ * DPDK callback to enable or disable vlan offload.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param mask
+ * Definitions used for VLAN setting
+ */
+static int hinic_vlan_offload_set(struct rte_eth_dev *dev, int mask)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
+ bool on;
+ int err;
+
+ /* Enable or disable VLAN filter */
+ if (mask & ETH_VLAN_FILTER_MASK) {
+ on = (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER) ?
+ TRUE : FALSE;
+ err = hinic_config_vlan_filter(nic_dev->hwdev, on);
+ if (err == HINIC_MGMT_CMD_UNSUPPORTED) {
+ PMD_DRV_LOG(WARNING,
+ "Current matching version does not support vlan filter configuration, device: %s, port_id: %d",
+ nic_dev->proc_dev_name, dev->data->port_id);
+ } else if (err) {
+ PMD_DRV_LOG(ERR, "Failed to %s vlan filter, device: %s, port_id: %d, err: %d",
+ on ? "enable" : "disable",
+ nic_dev->proc_dev_name,
+ dev->data->port_id, err);
+ return err;
+ }
+
+ PMD_DRV_LOG(INFO, "%s vlan filter succeed, device: %s, port_id: %d",
+ on ? "Enable" : "Disable",
+ nic_dev->proc_dev_name, dev->data->port_id);
+ }
+
+ /* Enable or disable VLAN stripping */
+ if (mask & ETH_VLAN_STRIP_MASK) {
+ on = (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) ?
+ TRUE : FALSE;
+ err = hinic_set_rx_vlan_offload(nic_dev->hwdev, on);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Failed to %s vlan strip, device: %s, port_id: %d, err: %d",
+ on ? "enable" : "disable",
+ nic_dev->proc_dev_name,
+ dev->data->port_id, err);
+ return err;
+ }
+
+ PMD_DRV_LOG(INFO, "%s vlan strip succeed, device: %s, port_id: %d",
+ on ? "Enable" : "Disable",
+ nic_dev->proc_dev_name, dev->data->port_id);
+ }
+
+ if (mask & ETH_VLAN_EXTEND_MASK) {
+ PMD_DRV_LOG(ERR, "Don't support vlan qinq, device: %s, port_id: %d",
+ nic_dev->proc_dev_name, dev->data->port_id);
+ return -ENOTSUP;
+ }
+
+ return 0;
+}
+
+static void hinic_remove_all_vlanid(struct rte_eth_dev *eth_dev)
+{
+ struct hinic_nic_dev *nic_dev =
+ HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(eth_dev);
+ u16 func_id;
+ int i;
+
+ func_id = hinic_global_func_id(nic_dev->hwdev);
+ for (i = 0; i <= RTE_ETHER_MAX_VLAN_ID; i++) {
+ /* If can't find it, continue */
+ if (!hinic_find_vlan_filter(nic_dev, i))
+ continue;
+
+ (void)hinic_add_remove_vlan(nic_dev->hwdev, i, func_id, FALSE);
+ hinic_store_vlan_filter(nic_dev, i, false);
+ }
+}
+
+static int hinic_set_dev_allmulticast(struct hinic_nic_dev *nic_dev,
+ bool enable)
+{
+ u32 rx_mode_ctrl = nic_dev->rx_mode_status;
+
+ if (enable)
+ rx_mode_ctrl |= HINIC_RX_MODE_MC_ALL;
+ else
+ rx_mode_ctrl &= (~HINIC_RX_MODE_MC_ALL);
+
+ return hinic_config_rx_mode(nic_dev, rx_mode_ctrl);
+}
+
+/**
+ * DPDK callback to enable allmulticast mode.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return
+ * 0 on success,
+ * negative error value otherwise.
+ */
+static int hinic_dev_allmulticast_enable(struct rte_eth_dev *dev)
+{
+ int ret = HINIC_OK;
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+
+ ret = hinic_set_dev_allmulticast(nic_dev, true);
+ if (ret) {
+ PMD_DRV_LOG(ERR, "Enable allmulticast failed, error: %d", ret);
+ return ret;
+ }
+
+ PMD_DRV_LOG(INFO, "Enable allmulticast succeed, nic_dev: %s, port_id: %d",
+ nic_dev->proc_dev_name, dev->data->port_id);
+ return 0;
+}
+
+/**
+ * DPDK callback to disable allmulticast mode.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return
+ * 0 on success,
+ * negative error value otherwise.
+ */
+static int hinic_dev_allmulticast_disable(struct rte_eth_dev *dev)
+{
+ int ret = HINIC_OK;
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+
+ ret = hinic_set_dev_allmulticast(nic_dev, false);
+ if (ret) {
+ PMD_DRV_LOG(ERR, "Disable allmulticast failed, error: %d", ret);
+ return ret;
+ }
+
+ PMD_DRV_LOG(INFO, "Disable allmulticast succeed, nic_dev: %s, port_id: %d",
+ nic_dev->proc_dev_name, dev->data->port_id);
+ return 0;