net/sfc: get RxQ pending descriptors count
[dpdk.git] / drivers / net / sfc / sfc_ethdev.c
index aa02f73..ad6f813 100644 (file)
@@ -67,6 +67,11 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        /* By default packets are dropped if no descriptors are available */
        dev_info->default_rxconf.rx_drop_en = 1;
 
+       dev_info->rx_offload_capa =
+               DEV_RX_OFFLOAD_IPV4_CKSUM |
+               DEV_RX_OFFLOAD_UDP_CKSUM |
+               DEV_RX_OFFLOAD_TCP_CKSUM;
+
        dev_info->tx_offload_capa =
                DEV_TX_OFFLOAD_IPV4_CKSUM |
                DEV_TX_OFFLOAD_UDP_CKSUM |
@@ -91,6 +96,24 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        dev_info->tx_desc_lim.nb_align = EFX_TXQ_MINNDESCS;
 }
 
+static const uint32_t *
+sfc_dev_supported_ptypes_get(struct rte_eth_dev *dev)
+{
+       static const uint32_t ptypes[] = {
+               RTE_PTYPE_L2_ETHER,
+               RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
+               RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
+               RTE_PTYPE_L4_TCP,
+               RTE_PTYPE_L4_UDP,
+               RTE_PTYPE_UNKNOWN
+       };
+
+       if (dev->rx_pkt_burst == sfc_recv_pkts)
+               return ptypes;
+
+       return NULL;
+}
+
 static int
 sfc_dev_configure(struct rte_eth_dev *dev)
 {
@@ -705,6 +728,131 @@ fail_inval:
        SFC_ASSERT(rc > 0);
        return -rc;
 }
+static void
+sfc_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+       const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
+       int rc;
+
+       sfc_adapter_lock(sa);
+
+       if (sa->state != SFC_ADAPTER_STARTED) {
+               sfc_info(sa, "the port is not started");
+               sfc_info(sa, "the new MAC address will be set on port start");
+
+               goto unlock;
+       }
+
+       if (encp->enc_allow_set_mac_with_installed_filters) {
+               rc = efx_mac_addr_set(sa->nic, mac_addr->addr_bytes);
+               if (rc != 0) {
+                       sfc_err(sa, "cannot set MAC address (rc = %u)", rc);
+                       goto unlock;
+               }
+
+               /*
+                * Changing the MAC address by means of MCDI request
+                * has no effect on received traffic, therefore
+                * we also need to update unicast filters
+                */
+               rc = sfc_set_rx_mode(sa);
+               if (rc != 0)
+                       sfc_err(sa, "cannot set filter (rc = %u)", rc);
+       } else {
+               sfc_warn(sa, "cannot set MAC address with filters installed");
+               sfc_warn(sa, "adapter will be restarted to pick the new MAC");
+               sfc_warn(sa, "(some traffic may be dropped)");
+
+               /*
+                * Since setting MAC address with filters installed is not
+                * allowed on the adapter, one needs to simply restart adapter
+                * so that the new MAC address will be taken from an outer
+                * storage and set flawlessly by means of sfc_start() call
+                */
+               sfc_stop(sa);
+               rc = sfc_start(sa);
+               if (rc != 0)
+                       sfc_err(sa, "cannot restart adapter (rc = %u)", rc);
+       }
+
+unlock:
+       sfc_adapter_unlock(sa);
+}
+
+
+static int
+sfc_set_mc_addr_list(struct rte_eth_dev *dev, struct ether_addr *mc_addr_set,
+                    uint32_t nb_mc_addr)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+       uint8_t *mc_addrs_p;
+       uint8_t *mc_addrs;
+       int rc;
+       unsigned int i;
+
+       if (nb_mc_addr > EFX_MAC_MULTICAST_LIST_MAX) {
+               sfc_err(sa, "too many multicast addresses: %u > %u",
+                        nb_mc_addr, EFX_MAC_MULTICAST_LIST_MAX);
+               return -EINVAL;
+       }
+
+       mc_addrs_p = rte_calloc("mc-addrs", nb_mc_addr, EFX_MAC_ADDR_LEN, 0);
+       if (mc_addrs_p == NULL)
+               return -ENOMEM;
+
+       mc_addrs = mc_addrs_p;
+
+       for (i = 0; i < nb_mc_addr; ++i) {
+               (void)rte_memcpy(mc_addrs, mc_addr_set[i].addr_bytes,
+                                EFX_MAC_ADDR_LEN);
+               mc_addrs += EFX_MAC_ADDR_LEN;
+       }
+
+       rc = efx_mac_multicast_list_set(sa->nic, mc_addrs_p, nb_mc_addr);
+
+       rte_free(mc_addrs_p);
+
+       if (rc != 0)
+               sfc_err(sa, "cannot set multicast address list (rc = %u)", rc);
+
+       SFC_ASSERT(rc > 0);
+       return -rc;
+}
+
+static void
+sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
+                     struct rte_eth_rxq_info *qinfo)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_rxq_info *rxq_info;
+       struct sfc_rxq *rxq;
+
+       sfc_adapter_lock(sa);
+
+       SFC_ASSERT(rx_queue_id < sa->rxq_count);
+
+       rxq_info = &sa->rxq_info[rx_queue_id];
+       rxq = rxq_info->rxq;
+       SFC_ASSERT(rxq != NULL);
+
+       qinfo->mp = rxq->refill_mb_pool;
+       qinfo->conf.rx_free_thresh = rxq->refill_threshold;
+       qinfo->conf.rx_drop_en = 1;
+       qinfo->nb_desc = rxq_info->entries;
+
+       sfc_adapter_unlock(sa);
+}
+
+static uint32_t
+sfc_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+
+       sfc_log_init(sa, "RxQ=%u", rx_queue_id);
+
+       return sfc_rx_qdesc_npending(sa, rx_queue_id);
+}
 
 static const struct eth_dev_ops sfc_eth_dev_ops = {
        .dev_configure                  = sfc_dev_configure,
@@ -722,13 +870,18 @@ static const struct eth_dev_ops sfc_eth_dev_ops = {
        .xstats_get                     = sfc_xstats_get,
        .xstats_get_names               = sfc_xstats_get_names,
        .dev_infos_get                  = sfc_dev_infos_get,
+       .dev_supported_ptypes_get       = sfc_dev_supported_ptypes_get,
        .mtu_set                        = sfc_dev_set_mtu,
        .rx_queue_setup                 = sfc_rx_queue_setup,
        .rx_queue_release               = sfc_rx_queue_release,
+       .rx_queue_count                 = sfc_rx_queue_count,
        .tx_queue_setup                 = sfc_tx_queue_setup,
        .tx_queue_release               = sfc_tx_queue_release,
        .flow_ctrl_get                  = sfc_flow_ctrl_get,
        .flow_ctrl_set                  = sfc_flow_ctrl_set,
+       .mac_addr_set                   = sfc_mac_addr_set,
+       .set_mc_addr_list               = sfc_set_mc_addr_list,
+       .rxq_info_get                   = sfc_rx_queue_info_get,
 };
 
 static int