+/**
+ * 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);
+ }
+
+ 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;
+ int err;
+
+ err = hinic_mutex_lock(&nic_dev->rx_mode_mutex);
+ if (err)
+ return err;
+
+ 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);
+
+ err = hinic_config_rx_mode(nic_dev, rx_mode_ctrl);
+
+ (void)hinic_mutex_unlock(&nic_dev->rx_mode_mutex);
+
+ return err;
+}
+
+/**
+ * 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;
+}
+
+/**
+ * DPDK callback to enable promiscuous mode.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return
+ * 0 on success,
+ * negative error value otherwise.
+ */
+static int hinic_dev_promiscuous_enable(struct rte_eth_dev *dev)
+{
+ int rc = HINIC_OK;
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+
+ PMD_DRV_LOG(INFO, "Enable promiscuous, nic_dev: %s, port_id: %d, promisc: %d",
+ nic_dev->proc_dev_name, dev->data->port_id,
+ dev->data->promiscuous);
+
+ rc = hinic_set_dev_promiscuous(nic_dev, true);
+ if (rc)
+ PMD_DRV_LOG(ERR, "Enable promiscuous failed");
+
+ return rc;
+}
+
+/**
+ * DPDK callback to disable promiscuous mode.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ *
+ * @return
+ * 0 on success,
+ * negative error value otherwise.
+ */
+static int hinic_dev_promiscuous_disable(struct rte_eth_dev *dev)
+{
+ int rc = HINIC_OK;
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+
+ PMD_DRV_LOG(INFO, "Disable promiscuous, nic_dev: %s, port_id: %d, promisc: %d",
+ nic_dev->proc_dev_name, dev->data->port_id,
+ dev->data->promiscuous);
+
+ rc = hinic_set_dev_promiscuous(nic_dev, false);
+ if (rc)
+ PMD_DRV_LOG(ERR, "Disable promiscuous failed");
+
+ return rc;
+}
+
+static int hinic_flow_ctrl_get(struct rte_eth_dev *dev,
+ struct rte_eth_fc_conf *fc_conf)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ struct nic_pause_config nic_pause;
+ int err;
+
+ memset(&nic_pause, 0, sizeof(nic_pause));
+
+ err = hinic_get_pause_info(nic_dev->hwdev, &nic_pause);
+ if (err)
+ return err;
+
+ if (nic_dev->pause_set || !nic_pause.auto_neg) {
+ nic_pause.rx_pause = nic_dev->nic_pause.rx_pause;
+ nic_pause.tx_pause = nic_dev->nic_pause.tx_pause;
+ }
+
+ fc_conf->autoneg = nic_pause.auto_neg;
+
+ if (nic_pause.tx_pause && nic_pause.rx_pause)
+ fc_conf->mode = RTE_FC_FULL;
+ else if (nic_pause.tx_pause)
+ fc_conf->mode = RTE_FC_TX_PAUSE;
+ else if (nic_pause.rx_pause)
+ fc_conf->mode = RTE_FC_RX_PAUSE;
+ else
+ fc_conf->mode = RTE_FC_NONE;
+
+ return 0;
+}
+
+static int hinic_flow_ctrl_set(struct rte_eth_dev *dev,
+ struct rte_eth_fc_conf *fc_conf)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ struct nic_pause_config nic_pause;
+ int err;
+
+ nic_pause.auto_neg = fc_conf->autoneg;
+
+ if (((fc_conf->mode & RTE_FC_FULL) == RTE_FC_FULL) ||
+ (fc_conf->mode & RTE_FC_TX_PAUSE))
+ nic_pause.tx_pause = true;
+ else
+ nic_pause.tx_pause = false;
+
+ if (((fc_conf->mode & RTE_FC_FULL) == RTE_FC_FULL) ||
+ (fc_conf->mode & RTE_FC_RX_PAUSE))
+ nic_pause.rx_pause = true;
+ else
+ nic_pause.rx_pause = false;
+
+ err = hinic_set_pause_config(nic_dev->hwdev, nic_pause);
+ if (err)
+ return err;
+
+ nic_dev->pause_set = true;
+ nic_dev->nic_pause.auto_neg = nic_pause.auto_neg;
+ nic_dev->nic_pause.rx_pause = nic_pause.rx_pause;
+ nic_dev->nic_pause.tx_pause = nic_pause.tx_pause;
+
+ PMD_DRV_LOG(INFO, "Set pause options, tx: %s, rx: %s, auto: %s\n",
+ nic_pause.tx_pause ? "on" : "off",
+ nic_pause.rx_pause ? "on" : "off",
+ nic_pause.auto_neg ? "on" : "off");
+
+ return 0;
+}
+
+/**
+ * DPDK callback to update the RSS hash key and RSS hash type.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param rss_conf
+ * RSS configuration data.
+ *
+ * @return
+ * 0 on success, negative error value otherwise.
+ */
+static int hinic_rss_hash_update(struct rte_eth_dev *dev,
+ struct rte_eth_rss_conf *rss_conf)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ u8 tmpl_idx = nic_dev->rss_tmpl_idx;
+ u8 hashkey[HINIC_RSS_KEY_SIZE] = {0};
+ u8 prio_tc[HINIC_DCB_UP_MAX] = {0};
+ u64 rss_hf = rss_conf->rss_hf;
+ struct nic_rss_type rss_type = {0};
+ int err = 0;
+
+ if (!(nic_dev->flags & ETH_MQ_RX_RSS_FLAG)) {
+ PMD_DRV_LOG(WARNING, "RSS is not enabled");
+ return HINIC_OK;
+ }
+
+ if (rss_conf->rss_key_len > HINIC_RSS_KEY_SIZE) {
+ PMD_DRV_LOG(ERR, "Invalid rss key, rss_key_len: %d",
+ rss_conf->rss_key_len);
+ return HINIC_ERROR;
+ }
+
+ if (rss_conf->rss_key) {
+ memcpy(hashkey, rss_conf->rss_key, rss_conf->rss_key_len);
+ err = hinic_rss_set_template_tbl(nic_dev->hwdev, tmpl_idx,
+ hashkey);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Set rss template table failed");
+ goto disable_rss;
+ }
+ }
+
+ rss_type.ipv4 = (rss_hf & (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4)) ? 1 : 0;
+ rss_type.tcp_ipv4 = (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) ? 1 : 0;
+ rss_type.ipv6 = (rss_hf & (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6)) ? 1 : 0;
+ rss_type.ipv6_ext = (rss_hf & ETH_RSS_IPV6_EX) ? 1 : 0;
+ rss_type.tcp_ipv6 = (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) ? 1 : 0;
+ rss_type.tcp_ipv6_ext = (rss_hf & ETH_RSS_IPV6_TCP_EX) ? 1 : 0;
+ rss_type.udp_ipv4 = (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) ? 1 : 0;
+ rss_type.udp_ipv6 = (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP) ? 1 : 0;
+
+ err = hinic_set_rss_type(nic_dev->hwdev, tmpl_idx, rss_type);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Set rss type table failed");
+ goto disable_rss;
+ }
+
+ return 0;
+
+disable_rss:
+ memset(prio_tc, 0, sizeof(prio_tc));
+ (void)hinic_rss_cfg(nic_dev->hwdev, 0, tmpl_idx, 0, prio_tc);
+ return err;
+}
+
+/**
+ * DPDK callback to get the RSS hash configuration.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param rss_conf
+ * RSS configuration data.
+ *
+ * @return
+ * 0 on success, negative error value otherwise.
+ */
+static int hinic_rss_conf_get(struct rte_eth_dev *dev,
+ struct rte_eth_rss_conf *rss_conf)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ u8 tmpl_idx = nic_dev->rss_tmpl_idx;
+ u8 hashkey[HINIC_RSS_KEY_SIZE] = {0};
+ struct nic_rss_type rss_type = {0};
+ int err;
+
+ if (!(nic_dev->flags & ETH_MQ_RX_RSS_FLAG)) {
+ PMD_DRV_LOG(WARNING, "RSS is not enabled");
+ return HINIC_ERROR;
+ }
+
+ err = hinic_rss_get_template_tbl(nic_dev->hwdev, tmpl_idx, hashkey);
+ if (err)
+ return err;
+
+ if (rss_conf->rss_key &&
+ rss_conf->rss_key_len >= HINIC_RSS_KEY_SIZE) {
+ memcpy(rss_conf->rss_key, hashkey, sizeof(hashkey));
+ rss_conf->rss_key_len = sizeof(hashkey);
+ }
+
+ err = hinic_get_rss_type(nic_dev->hwdev, tmpl_idx, &rss_type);
+ if (err)
+ return err;
+
+ rss_conf->rss_hf = 0;
+ rss_conf->rss_hf |= rss_type.ipv4 ?
+ (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4) : 0;
+ rss_conf->rss_hf |= rss_type.tcp_ipv4 ? ETH_RSS_NONFRAG_IPV4_TCP : 0;
+ rss_conf->rss_hf |= rss_type.ipv6 ?
+ (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6) : 0;
+ rss_conf->rss_hf |= rss_type.ipv6_ext ? ETH_RSS_IPV6_EX : 0;
+ rss_conf->rss_hf |= rss_type.tcp_ipv6 ? ETH_RSS_NONFRAG_IPV6_TCP : 0;
+ rss_conf->rss_hf |= rss_type.tcp_ipv6_ext ? ETH_RSS_IPV6_TCP_EX : 0;
+ rss_conf->rss_hf |= rss_type.udp_ipv4 ? ETH_RSS_NONFRAG_IPV4_UDP : 0;
+ rss_conf->rss_hf |= rss_type.udp_ipv6 ? ETH_RSS_NONFRAG_IPV6_UDP : 0;
+
+ return HINIC_OK;
+}
+
+/**
+ * DPDK callback to update the RSS redirection table.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param reta_conf
+ * Pointer to RSS reta configuration data.
+ * @param reta_size
+ * Size of the RETA table.
+ *
+ * @return
+ * 0 on success, negative error value otherwise.
+ */
+static int hinic_rss_indirtbl_update(struct rte_eth_dev *dev,
+ struct rte_eth_rss_reta_entry64 *reta_conf,
+ uint16_t reta_size)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ u8 tmpl_idx = nic_dev->rss_tmpl_idx;
+ u8 prio_tc[HINIC_DCB_UP_MAX] = {0};
+ u32 indirtbl[NIC_RSS_INDIR_SIZE] = {0};
+ int err = 0;
+ u16 i = 0;
+ u16 idx, shift;
+
+ if (!(nic_dev->flags & ETH_MQ_RX_RSS_FLAG))
+ return HINIC_OK;
+
+ if (reta_size != NIC_RSS_INDIR_SIZE) {
+ PMD_DRV_LOG(ERR, "Invalid reta size, reta_size: %d", reta_size);
+ return HINIC_ERROR;
+ }
+
+ err = hinic_rss_get_indir_tbl(nic_dev->hwdev, tmpl_idx, indirtbl);
+ if (err)
+ return err;
+
+ /* update rss indir_tbl */
+ for (i = 0; i < reta_size; i++) {
+ idx = i / RTE_RETA_GROUP_SIZE;
+ shift = i % RTE_RETA_GROUP_SIZE;
+
+ if (reta_conf[idx].reta[shift] >= nic_dev->num_rq) {
+ PMD_DRV_LOG(ERR, "Invalid reta entry, indirtbl[%d]: %d "
+ "exceeds the maximum rxq num: %d", i,
+ reta_conf[idx].reta[shift], nic_dev->num_rq);
+ return -EINVAL;
+ }
+
+ if (reta_conf[idx].mask & (1ULL << shift))
+ indirtbl[i] = reta_conf[idx].reta[shift];
+ }
+
+ err = hinic_rss_set_indir_tbl(nic_dev->hwdev, tmpl_idx, indirtbl);
+ if (err)
+ goto disable_rss;
+
+ nic_dev->rss_indir_flag = true;
+
+ return 0;
+
+disable_rss:
+ memset(prio_tc, 0, sizeof(prio_tc));
+ (void)hinic_rss_cfg(nic_dev->hwdev, 0, tmpl_idx, 0, prio_tc);
+
+ return HINIC_ERROR;
+}
+
+/**
+ * DPDK callback to get the RSS indirection table.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param reta_conf
+ * Pointer to RSS reta configuration data.
+ * @param reta_size
+ * Size of the RETA table.
+ *
+ * @return
+ * 0 on success, negative error value otherwise.
+ */
+static int hinic_rss_indirtbl_query(struct rte_eth_dev *dev,
+ struct rte_eth_rss_reta_entry64 *reta_conf,
+ uint16_t reta_size)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ u8 tmpl_idx = nic_dev->rss_tmpl_idx;
+ int err = 0;
+ u32 indirtbl[NIC_RSS_INDIR_SIZE] = {0};
+ u16 idx, shift;
+ u16 i = 0;
+
+ if (reta_size != NIC_RSS_INDIR_SIZE) {
+ PMD_DRV_LOG(ERR, "Invalid reta size, reta_size: %d", reta_size);
+ return HINIC_ERROR;
+ }
+
+ err = hinic_rss_get_indir_tbl(nic_dev->hwdev, tmpl_idx, indirtbl);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Get rss indirect table failed, error: %d",
+ err);
+ return err;
+ }
+
+ for (i = 0; i < reta_size; i++) {
+ idx = i / RTE_RETA_GROUP_SIZE;
+ shift = i % RTE_RETA_GROUP_SIZE;
+ if (reta_conf[idx].mask & (1ULL << shift))
+ reta_conf[idx].reta[shift] = (uint16_t)indirtbl[i];
+ }
+
+ return HINIC_OK;
+}
+
+/**
+ * DPDK callback to get extended device statistics.
+ *
+ * @param dev
+ * Pointer to Ethernet device.
+ * @param xstats
+ * Pointer to rte extended stats table.
+ * @param n
+ * The size of the stats table.
+ *
+ * @return
+ * Number of extended stats on success and stats is filled,
+ * negative error value otherwise.
+ */
+static int hinic_dev_xstats_get(struct rte_eth_dev *dev,
+ struct rte_eth_xstat *xstats,
+ unsigned int n)
+{
+ u16 qid = 0;
+ u32 i;
+ int err, count;
+ struct hinic_nic_dev *nic_dev;
+ struct hinic_phy_port_stats port_stats;
+ struct hinic_vport_stats vport_stats;
+ struct hinic_rxq *rxq = NULL;
+ struct hinic_rxq_stats rxq_stats;
+ struct hinic_txq *txq = NULL;
+ struct hinic_txq_stats txq_stats;
+
+ nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ count = hinic_xstats_calc_num(nic_dev);
+ if ((int)n < count)
+ return count;
+
+ count = 0;
+
+ /* Get stats from hinic_rxq_stats */
+ for (qid = 0; qid < nic_dev->num_rq; qid++) {
+ rxq = nic_dev->rxqs[qid];
+ hinic_rxq_get_stats(rxq, &rxq_stats);
+
+ for (i = 0; i < HINIC_RXQ_XSTATS_NUM; i++) {
+ xstats[count].value =
+ *(uint64_t *)(((char *)&rxq_stats) +
+ hinic_rxq_stats_strings[i].offset);
+ xstats[count].id = count;
+ count++;
+ }
+ }
+
+ /* Get stats from hinic_txq_stats */
+ for (qid = 0; qid < nic_dev->num_sq; qid++) {
+ txq = nic_dev->txqs[qid];
+ hinic_txq_get_stats(txq, &txq_stats);
+
+ for (i = 0; i < HINIC_TXQ_XSTATS_NUM; i++) {
+ xstats[count].value =
+ *(uint64_t *)(((char *)&txq_stats) +
+ hinic_txq_stats_strings[i].offset);
+ xstats[count].id = count;
+ count++;
+ }
+ }
+
+ /* Get stats from hinic_vport_stats */
+ err = hinic_get_vport_stats(nic_dev->hwdev, &vport_stats);
+ if (err)
+ return err;
+
+ for (i = 0; i < HINIC_VPORT_XSTATS_NUM; i++) {
+ xstats[count].value =
+ *(uint64_t *)(((char *)&vport_stats) +
+ hinic_vport_stats_strings[i].offset);
+ xstats[count].id = count;
+ count++;
+ }
+
+ if (HINIC_IS_VF(nic_dev->hwdev))
+ return count;
+
+ /* Get stats from hinic_phy_port_stats */
+ err = hinic_get_phy_port_stats(nic_dev->hwdev, &port_stats);
+ if (err)
+ return err;
+
+ for (i = 0; i < HINIC_PHYPORT_XSTATS_NUM; i++) {
+ xstats[count].value = *(uint64_t *)(((char *)&port_stats) +
+ hinic_phyport_stats_strings[i].offset);
+ xstats[count].id = count;
+ count++;
+ }
+
+ return count;
+}
+
+static void hinic_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
+ struct rte_eth_rxq_info *qinfo)
+{
+ struct hinic_rxq *rxq = dev->data->rx_queues[queue_id];
+
+ qinfo->mp = rxq->mb_pool;
+ qinfo->nb_desc = rxq->q_depth;
+}
+
+static void hinic_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
+ struct rte_eth_txq_info *qinfo)
+{
+ struct hinic_txq *txq = dev->data->tx_queues[queue_id];
+
+ qinfo->nb_desc = txq->q_depth;
+}
+
+/**
+ * DPDK callback to retrieve names of extended device statistics
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param xstats_names
+ * Buffer to insert names into.
+ *
+ * @return
+ * Number of xstats names.
+ */
+static int hinic_dev_xstats_get_names(struct rte_eth_dev *dev,
+ struct rte_eth_xstat_name *xstats_names,
+ __rte_unused unsigned int limit)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ int count = 0;
+ u16 i = 0, q_num;
+
+ if (xstats_names == NULL)
+ return hinic_xstats_calc_num(nic_dev);
+
+ /* get pmd rxq stats */
+ for (q_num = 0; q_num < nic_dev->num_rq; q_num++) {
+ for (i = 0; i < HINIC_RXQ_XSTATS_NUM; i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name),
+ "rxq%d_%s_pmd",
+ q_num, hinic_rxq_stats_strings[i].name);
+ count++;
+ }
+ }
+
+ /* get pmd txq stats */
+ for (q_num = 0; q_num < nic_dev->num_sq; q_num++) {
+ for (i = 0; i < HINIC_TXQ_XSTATS_NUM; i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name),
+ "txq%d_%s_pmd",
+ q_num, hinic_txq_stats_strings[i].name);
+ count++;
+ }
+ }
+
+ /* get vport stats */
+ for (i = 0; i < HINIC_VPORT_XSTATS_NUM; i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name),
+ "%s", hinic_vport_stats_strings[i].name);
+ count++;
+ }
+
+ if (HINIC_IS_VF(nic_dev->hwdev))
+ return count;
+
+ /* get phy port stats */
+ for (i = 0; i < HINIC_PHYPORT_XSTATS_NUM; i++) {
+ snprintf(xstats_names[count].name,
+ sizeof(xstats_names[count].name),
+ "%s", hinic_phyport_stats_strings[i].name);
+ count++;
+ }
+
+ return count;
+}
+
+/**
+ * DPDK callback to set mac address
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param addr
+ * Pointer to mac address
+ * @return
+ * 0 on success, negative error value otherwise.
+ */
+static int hinic_set_mac_addr(struct rte_eth_dev *dev,
+ struct rte_ether_addr *addr)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ u16 func_id;
+ int err;
+
+ func_id = hinic_global_func_id(nic_dev->hwdev);
+ err = hinic_update_mac(nic_dev->hwdev, nic_dev->default_addr.addr_bytes,
+ addr->addr_bytes, 0, func_id);
+ if (err)
+ return err;
+
+ rte_ether_addr_copy(addr, &nic_dev->default_addr);
+
+ PMD_DRV_LOG(INFO, "Set new mac address %02x:%02x:%02x:%02x:%02x:%02x",
+ addr->addr_bytes[0], addr->addr_bytes[1],
+ addr->addr_bytes[2], addr->addr_bytes[3],
+ addr->addr_bytes[4], addr->addr_bytes[5]);
+
+ return 0;
+}
+
+/**
+ * DPDK callback to remove a MAC address.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param index
+ * MAC address index, should less than 128.
+ */
+static void hinic_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ u16 func_id;
+ int ret;
+
+ if (index >= HINIC_MAX_UC_MAC_ADDRS) {
+ PMD_DRV_LOG(INFO, "Remove mac index(%u) is out of range",
+ index);
+ return;
+ }
+
+ func_id = hinic_global_func_id(nic_dev->hwdev);
+ ret = hinic_del_mac(nic_dev->hwdev,
+ dev->data->mac_addrs[index].addr_bytes, 0, func_id);
+ if (ret)
+ return;
+
+ memset(&dev->data->mac_addrs[index], 0, sizeof(struct rte_ether_addr));
+}
+
+/**
+ * DPDK callback to add a MAC address.
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param mac_addr
+ * Pointer to MAC address
+ * @param index
+ * MAC address index, should less than 128.
+ * @param vmdq
+ * VMDq pool index(not used).
+ *
+ * @return
+ * 0 on success, negative error value otherwise.
+ */
+static int hinic_mac_addr_add(struct rte_eth_dev *dev,
+ struct rte_ether_addr *mac_addr, uint32_t index,
+ __rte_unused uint32_t vmdq)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ unsigned int i;
+ u16 func_id;
+ int ret;
+
+ if (index >= HINIC_MAX_UC_MAC_ADDRS) {
+ PMD_DRV_LOG(INFO, "Add mac index(%u) is out of range", index);
+ return -EINVAL;
+ }
+
+ /* First, make sure this address isn't already configured. */
+ for (i = 0; (i != HINIC_MAX_UC_MAC_ADDRS); ++i) {
+ /* Skip this index, it's going to be reconfigured. */
+ if (i == index)
+ continue;
+
+ if (memcmp(&dev->data->mac_addrs[i],
+ mac_addr, sizeof(*mac_addr)))
+ continue;
+
+ PMD_DRV_LOG(INFO, "MAC address already configured");
+ return -EADDRINUSE;
+ }
+
+ func_id = hinic_global_func_id(nic_dev->hwdev);
+ ret = hinic_set_mac(nic_dev->hwdev, mac_addr->addr_bytes, 0, func_id);
+ if (ret)
+ return ret;
+
+ dev->data->mac_addrs[index] = *mac_addr;
+ return 0;
+}
+
+/**
+ * DPDK callback to set multicast mac address
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param mc_addr_set
+ * Pointer to multicast mac address
+ * @param nb_mc_addr
+ * mc addr count
+ * @return
+ * 0 on success, negative error value otherwise.
+ */
+static int hinic_set_mc_addr_list(struct rte_eth_dev *dev,
+ struct rte_ether_addr *mc_addr_set,
+ uint32_t nb_mc_addr)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ u16 func_id;
+ int ret;
+ u32 i;
+
+ func_id = hinic_global_func_id(nic_dev->hwdev);
+
+ /* delete old multi_cast addrs firstly */
+ hinic_delete_mc_addr_list(nic_dev);
+
+ if (nb_mc_addr > HINIC_MAX_MC_MAC_ADDRS)
+ goto allmulti;
+
+ for (i = 0; i < nb_mc_addr; i++) {
+ ret = hinic_set_mac(nic_dev->hwdev, mc_addr_set[i].addr_bytes,
+ 0, func_id);
+ /* if add mc addr failed, set all multi_cast */
+ if (ret) {
+ hinic_delete_mc_addr_list(nic_dev);
+ goto allmulti;
+ }
+
+ rte_ether_addr_copy(&mc_addr_set[i], &nic_dev->mc_list[i]);
+ }
+
+ return 0;
+
+allmulti:
+ hinic_dev_allmulticast_enable(dev);
+
+ return 0;
+}
+
+/**
+ * DPDK callback to manage filter control operations
+ *
+ * @param dev
+ * Pointer to Ethernet device structure.
+ * @param filter_type
+ * Filter type, which just supports generic type.
+ * @param filter_op
+ * Filter operation to perform.
+ * @param arg
+ * Pointer to operation-specific structure.
+ *
+ * @return
+ * 0 on success, negative error value otherwise.
+ */
+static int hinic_dev_filter_ctrl(struct rte_eth_dev *dev,
+ enum rte_filter_type filter_type,
+ enum rte_filter_op filter_op,
+ void *arg)
+{
+ struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+ int func_id = hinic_global_func_id(nic_dev->hwdev);
+
+ switch (filter_type) {
+ case RTE_ETH_FILTER_GENERIC:
+ if (filter_op != RTE_ETH_FILTER_GET)
+ return -EINVAL;
+ *(const void **)arg = &hinic_flow_ops;
+ break;
+ default:
+ PMD_DRV_LOG(INFO, "Filter type (%d) not supported",
+ filter_type);
+ return -EINVAL;
+ }
+
+ PMD_DRV_LOG(INFO, "Set filter_ctrl succeed, func_id: 0x%x, filter_type: 0x%x,"
+ "filter_op: 0x%x.", func_id, filter_type, filter_op);
+ return 0;
+}
+
+static int hinic_set_default_pause_feature(struct hinic_nic_dev *nic_dev)
+{
+ struct nic_pause_config pause_config = {0};
+ int err;
+
+ pause_config.auto_neg = 0;
+ pause_config.rx_pause = HINIC_DEFAUT_PAUSE_CONFIG;
+ pause_config.tx_pause = HINIC_DEFAUT_PAUSE_CONFIG;
+
+ err = hinic_set_pause_config(nic_dev->hwdev, pause_config);
+ if (err)
+ return err;
+
+ nic_dev->pause_set = true;
+ nic_dev->nic_pause.auto_neg = pause_config.auto_neg;
+ nic_dev->nic_pause.rx_pause = pause_config.rx_pause;
+ nic_dev->nic_pause.tx_pause = pause_config.tx_pause;
+
+ return 0;
+}
+
+static int hinic_set_default_dcb_feature(struct hinic_nic_dev *nic_dev)
+{
+ u8 up_tc[HINIC_DCB_UP_MAX] = {0};
+ u8 up_pgid[HINIC_DCB_UP_MAX] = {0};
+ u8 up_bw[HINIC_DCB_UP_MAX] = {0};
+ u8 pg_bw[HINIC_DCB_UP_MAX] = {0};
+ u8 up_strict[HINIC_DCB_UP_MAX] = {0};
+ int i = 0;
+
+ pg_bw[0] = 100;
+ for (i = 0; i < HINIC_DCB_UP_MAX; i++)
+ up_bw[i] = 100;
+
+ return hinic_dcb_set_ets(nic_dev->hwdev, up_tc, pg_bw,
+ up_pgid, up_bw, up_strict);
+}
+
+static int hinic_pf_get_default_cos(struct hinic_hwdev *hwdev, u8 *cos_id)
+{
+ u8 default_cos = 0;
+ u8 valid_cos_bitmap;
+ u8 i;
+
+ valid_cos_bitmap = hwdev->cfg_mgmt->svc_cap.valid_cos_bitmap;
+ if (!valid_cos_bitmap) {
+ PMD_DRV_LOG(ERR, "PF has none cos to support\n");
+ return -EFAULT;
+ }
+
+ for (i = 0; i < NR_MAX_COS; i++) {
+ if (valid_cos_bitmap & BIT(i))
+ default_cos = i; /* Find max cos id as default cos */
+ }
+
+ *cos_id = default_cos;
+
+ return 0;
+}
+
+static int hinic_init_default_cos(struct hinic_nic_dev *nic_dev)
+{
+ u8 cos_id = 0;
+ int err;
+
+ if (!HINIC_IS_VF(nic_dev->hwdev)) {
+ err = hinic_pf_get_default_cos(nic_dev->hwdev, &cos_id);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Get PF default cos failed, err: %d",
+ err);
+ return HINIC_ERROR;
+ }
+ } else {
+ err = hinic_vf_get_default_cos(nic_dev->hwdev, &cos_id);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Get VF default cos failed, err: %d",
+ err);
+ return HINIC_ERROR;
+ }
+ }
+
+ nic_dev->default_cos = cos_id;
+
+ PMD_DRV_LOG(INFO, "Default cos %d", nic_dev->default_cos);
+
+ return 0;
+}
+
+static int hinic_set_default_hw_feature(struct hinic_nic_dev *nic_dev)
+{
+ int err;
+
+ err = hinic_init_default_cos(nic_dev);
+ if (err)
+ return err;
+
+ if (hinic_func_type(nic_dev->hwdev) == TYPE_VF)
+ return 0;
+
+ /* Restore DCB configure to default status */
+ err = hinic_set_default_dcb_feature(nic_dev);
+ if (err)
+ return err;
+
+ /* Set pause enable, and up will disable pfc. */
+ err = hinic_set_default_pause_feature(nic_dev);
+ if (err)
+ return err;
+
+ err = hinic_reset_port_link_cfg(nic_dev->hwdev);
+ if (err)
+ return err;
+
+ err = hinic_set_link_status_follow(nic_dev->hwdev,
+ HINIC_LINK_FOLLOW_PORT);
+ if (err == HINIC_MGMT_CMD_UNSUPPORTED)
+ PMD_DRV_LOG(WARNING, "Don't support to set link status follow phy port status");
+ else if (err)
+ return err;
+
+ return hinic_set_anti_attack(nic_dev->hwdev, true);
+}
+
+static int32_t hinic_card_workmode_check(struct hinic_nic_dev *nic_dev)