ethdev: move jumbo frame offload check to library
[dpdk.git] / drivers / net / cxgbe / cxgbe_ethdev.c
index 177eca3..cdecf6b 100644 (file)
@@ -310,22 +310,11 @@ int cxgbe_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
                return err;
 
        /* Must accommodate at least RTE_ETHER_MIN_MTU */
-       if (new_mtu < RTE_ETHER_MIN_MTU || new_mtu > dev_info.max_rx_pktlen)
+       if (mtu < RTE_ETHER_MIN_MTU || new_mtu > dev_info.max_rx_pktlen)
                return -EINVAL;
 
-       /* set to jumbo mode if needed */
-       if (new_mtu > CXGBE_ETH_MAX_LEN)
-               eth_dev->data->dev_conf.rxmode.offloads |=
-                       DEV_RX_OFFLOAD_JUMBO_FRAME;
-       else
-               eth_dev->data->dev_conf.rxmode.offloads &=
-                       ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
        err = t4_set_rxmode(adapter, adapter->mbox, pi->viid, new_mtu, -1, -1,
                            -1, -1, true);
-       if (!err)
-               eth_dev->data->dev_conf.rxmode.max_rx_pkt_len = new_mtu;
-
        return err;
 }
 
@@ -532,7 +521,7 @@ int cxgbe_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
 
        /*  Free up the existing queue  */
        if (eth_dev->data->tx_queues[queue_idx]) {
-               cxgbe_dev_tx_queue_release(eth_dev->data->tx_queues[queue_idx]);
+               cxgbe_dev_tx_queue_release(eth_dev, queue_idx);
                eth_dev->data->tx_queues[queue_idx] = NULL;
        }
 
@@ -565,9 +554,9 @@ int cxgbe_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
        return err;
 }
 
-void cxgbe_dev_tx_queue_release(void *q)
+void cxgbe_dev_tx_queue_release(struct rte_eth_dev *eth_dev, uint16_t qid)
 {
-       struct sge_eth_txq *txq = (struct sge_eth_txq *)q;
+       struct sge_eth_txq *txq = eth_dev->data->tx_queues[qid];
 
        if (txq) {
                struct port_info *pi = (struct port_info *)
@@ -623,7 +612,8 @@ int cxgbe_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
                             const struct rte_eth_rxconf *rx_conf __rte_unused,
                             struct rte_mempool *mp)
 {
-       unsigned int pkt_len = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
+       unsigned int pkt_len = eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
+               RTE_ETHER_CRC_LEN;
        struct port_info *pi = eth_dev->data->dev_private;
        struct adapter *adapter = pi->adapter;
        struct rte_eth_dev_info dev_info;
@@ -655,7 +645,7 @@ int cxgbe_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
 
        /*  Free up the existing queue  */
        if (eth_dev->data->rx_queues[queue_idx]) {
-               cxgbe_dev_rx_queue_release(eth_dev->data->rx_queues[queue_idx]);
+               cxgbe_dev_rx_queue_release(eth_dev, queue_idx);
                eth_dev->data->rx_queues[queue_idx] = NULL;
        }
 
@@ -679,11 +669,10 @@ int cxgbe_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
        }
 
        rxq->rspq.size = temp_nb_desc;
-       if ((&rxq->fl) != NULL)
-               rxq->fl.size = temp_nb_desc;
+       rxq->fl.size = temp_nb_desc;
 
        /* Set to jumbo mode if necessary */
-       if (pkt_len > CXGBE_ETH_MAX_LEN)
+       if (eth_dev->data->mtu > RTE_ETHER_MTU)
                eth_dev->data->dev_conf.rxmode.offloads |=
                        DEV_RX_OFFLOAD_JUMBO_FRAME;
        else
@@ -702,9 +691,9 @@ int cxgbe_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
        return err;
 }
 
-void cxgbe_dev_rx_queue_release(void *q)
+void cxgbe_dev_rx_queue_release(struct rte_eth_dev *eth_dev, uint16_t qid)
 {
-       struct sge_eth_rxq *rxq = (struct sge_eth_rxq *)q;
+       struct sge_eth_rxq *rxq = eth_dev->data->rx_queues[qid];
 
        if (rxq) {
                struct port_info *pi = (struct port_info *)
@@ -881,15 +870,37 @@ static const struct cxgbe_dev_xstats_name_off cxgbe_dev_port_stats_strings[] = {
        {"rx_bg3_truncated_packets", offsetof(struct port_stats, rx_trunc3)},
 };
 
+static const struct cxgbe_dev_xstats_name_off
+cxgbevf_dev_port_stats_strings[] = {
+       {"tx_bytes", offsetof(struct port_stats, tx_octets)},
+       {"tx_broadcast_packets", offsetof(struct port_stats, tx_bcast_frames)},
+       {"tx_multicast_packets", offsetof(struct port_stats, tx_mcast_frames)},
+       {"tx_unicast_packets", offsetof(struct port_stats, tx_ucast_frames)},
+       {"tx_drop_packets", offsetof(struct port_stats, tx_drop)},
+       {"rx_broadcast_packets", offsetof(struct port_stats, rx_bcast_frames)},
+       {"rx_multicast_packets", offsetof(struct port_stats, rx_mcast_frames)},
+       {"rx_unicast_packets", offsetof(struct port_stats, rx_ucast_frames)},
+       {"rx_length_error_packets", offsetof(struct port_stats, rx_len_err)},
+};
+
 #define CXGBE_NB_RXQ_STATS RTE_DIM(cxgbe_dev_rxq_stats_strings)
 #define CXGBE_NB_TXQ_STATS RTE_DIM(cxgbe_dev_txq_stats_strings)
 #define CXGBE_NB_PORT_STATS RTE_DIM(cxgbe_dev_port_stats_strings)
+#define CXGBEVF_NB_PORT_STATS RTE_DIM(cxgbevf_dev_port_stats_strings)
 
 static u16 cxgbe_dev_xstats_count(struct port_info *pi)
 {
-       return CXGBE_NB_PORT_STATS +
-              (pi->n_tx_qsets * CXGBE_NB_TXQ_STATS) +
-              (pi->n_rx_qsets * CXGBE_NB_RXQ_STATS);
+       u16 count;
+
+       count = (pi->n_tx_qsets * CXGBE_NB_TXQ_STATS) +
+               (pi->n_rx_qsets * CXGBE_NB_RXQ_STATS);
+
+       if (is_pf4(pi->adapter) != 0)
+               count += CXGBE_NB_PORT_STATS;
+       else
+               count += CXGBEVF_NB_PORT_STATS;
+
+       return count;
 }
 
 static int cxgbe_dev_xstats(struct rte_eth_dev *dev,
@@ -900,20 +911,28 @@ static int cxgbe_dev_xstats(struct rte_eth_dev *dev,
        struct port_info *pi = dev->data->dev_private;
        struct adapter *adap = pi->adapter;
        struct sge *s = &adap->sge;
+       u16 count, i, qid, nstats;
        struct port_stats ps;
-       u16 count, i, qid;
        u64 *stats_ptr;
 
        count = cxgbe_dev_xstats_count(pi);
        if (size < count)
                return count;
 
-       /* port stats */
-       cxgbe_stats_get(pi, &ps);
+       if (is_pf4(adap) != 0) {
+               /* port stats for PF*/
+               cxgbe_stats_get(pi, &ps);
+               xstats_str = cxgbe_dev_port_stats_strings;
+               nstats = CXGBE_NB_PORT_STATS;
+       } else {
+               /* port stats for VF*/
+               cxgbevf_stats_get(pi, &ps);
+               xstats_str = cxgbevf_dev_port_stats_strings;
+               nstats = CXGBEVF_NB_PORT_STATS;
+       }
 
        count = 0;
-       xstats_str = cxgbe_dev_port_stats_strings;
-       for (i = 0; i < CXGBE_NB_PORT_STATS; i++, count++) {
+       for (i = 0; i < nstats; i++, count++) {
                if (xstats_names != NULL)
                        snprintf(xstats_names[count].name,
                                 sizeof(xstats_names[count].name),
@@ -970,9 +989,9 @@ static int cxgbe_dev_xstats(struct rte_eth_dev *dev,
 }
 
 /* Get port extended statistics by ID. */
-static int cxgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev,
-                                     const uint64_t *ids, uint64_t *values,
-                                     unsigned int n)
+int cxgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev,
+                              const uint64_t *ids, uint64_t *values,
+                              unsigned int n)
 {
        struct port_info *pi = dev->data->dev_private;
        struct rte_eth_xstat *xstats_copy;
@@ -1005,9 +1024,10 @@ out_err:
 }
 
 /* Get names of port extended statistics by ID. */
-static int cxgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
+int cxgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
+                                           const uint64_t *ids,
                                            struct rte_eth_xstat_name *xnames,
-                                           const uint64_t *ids, unsigned int n)
+                                           unsigned int n)
 {
        struct port_info *pi = dev->data->dev_private;
        struct rte_eth_xstat_name *xnames_copy;
@@ -1041,16 +1061,16 @@ out_err:
 }
 
 /* Get port extended statistics. */
-static int cxgbe_dev_xstats_get(struct rte_eth_dev *dev,
-                               struct rte_eth_xstat *xstats, unsigned int n)
+int cxgbe_dev_xstats_get(struct rte_eth_dev *dev,
+                        struct rte_eth_xstat *xstats, unsigned int n)
 {
        return cxgbe_dev_xstats(dev, NULL, xstats, n);
 }
 
 /* Get names of port extended statistics. */
-static int cxgbe_dev_xstats_get_names(struct rte_eth_dev *dev,
-                                     struct rte_eth_xstat_name *xstats_names,
-                                     unsigned int n)
+int cxgbe_dev_xstats_get_names(struct rte_eth_dev *dev,
+                              struct rte_eth_xstat_name *xstats_names,
+                              unsigned int n)
 {
        return cxgbe_dev_xstats(dev, xstats_names, NULL, n);
 }
@@ -1590,6 +1610,31 @@ set_fec:
        return ret;
 }
 
+int cxgbe_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
+                        size_t fw_size)
+{
+       struct port_info *pi = dev->data->dev_private;
+       struct adapter *adapter = pi->adapter;
+       int ret;
+
+       if (adapter->params.fw_vers == 0)
+               return -EIO;
+
+       ret = snprintf(fw_version, fw_size, "%u.%u.%u.%u",
+                      G_FW_HDR_FW_VER_MAJOR(adapter->params.fw_vers),
+                      G_FW_HDR_FW_VER_MINOR(adapter->params.fw_vers),
+                      G_FW_HDR_FW_VER_MICRO(adapter->params.fw_vers),
+                      G_FW_HDR_FW_VER_BUILD(adapter->params.fw_vers));
+       if (ret < 0)
+               return -EINVAL;
+
+       ret += 1;
+       if (fw_size < (size_t)ret)
+               return ret;
+
+       return 0;
+}
+
 static const struct eth_dev_ops cxgbe_eth_dev_ops = {
        .dev_start              = cxgbe_dev_start,
        .dev_stop               = cxgbe_dev_stop,
@@ -1635,6 +1680,7 @@ static const struct eth_dev_ops cxgbe_eth_dev_ops = {
        .fec_get_capability     = cxgbe_fec_get_capability,
        .fec_get                = cxgbe_fec_get,
        .fec_set                = cxgbe_fec_set,
+       .fw_version_get         = cxgbe_fw_version_get,
 };
 
 /*