net/thunderx: support link up and down
authorHarman Kalra <hkalra@marvell.com>
Wed, 5 Feb 2020 09:26:33 +0000 (14:56 +0530)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 18 Mar 2020 09:21:41 +0000 (10:21 +0100)
Add support for .set_link_up/down() eth ops to bring
link up and down.

Signed-off-by: Harman Kalra <hkalra@marvell.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
drivers/net/thunderx/base/nicvf_mbox.c
drivers/net/thunderx/base/nicvf_mbox.h
drivers/net/thunderx/nicvf_ethdev.c

index 8f83d41..5b3ab93 100644 (file)
@@ -413,6 +413,16 @@ nicvf_mbox_reset_stat_counters(struct nicvf *nic, uint16_t rx_stat_mask,
        return nicvf_mbox_send_msg_to_pf(nic, &mbx);
 }
 
+int
+nicvf_mbox_set_link_up_down(struct nicvf *nic, bool enable)
+{
+       struct nic_mbx mbx = { .msg = { 0 } };
+
+       mbx.lbk.msg = NIC_MBOX_MSG_SET_LINK;
+       mbx.lbk.vf_id = nic->vf_id;
+       mbx.lbk.enable = enable;
+       return nicvf_mbox_send_msg_to_pf(nic, &mbx);
+}
 void
 nicvf_mbox_shutdown(struct nicvf *nic)
 {
index 81f1f40..d0b2943 100644 (file)
@@ -40,6 +40,7 @@
 #define        NIC_MBOX_MSG_ALLOC_SQS          0x12    /* Allocate secondary Qset */
 #define        NIC_MBOX_MSG_LOOPBACK           0x16    /* Set interface in loopback */
 #define        NIC_MBOX_MSG_RESET_STAT_COUNTER 0x17    /* Reset statistics counters */
+#define        NIC_MBOX_MSG_SET_LINK           0x21    /* Set link up/down */
 #define        NIC_MBOX_MSG_CFG_DONE           0xF0    /* VF configuration done */
 #define        NIC_MBOX_MSG_SHUTDOWN           0xF1    /* VF is being shutdown */
 #define        NIC_MBOX_MSG_MAX                0x100   /* Maximum number of messages */
@@ -169,6 +170,13 @@ struct reset_stat_cfg {
        uint16_t   sq_stat_mask;
 };
 
+/* Set link up/down */
+struct set_link_state {
+       uint8_t    msg;
+       uint8_t    vf_id;
+       bool       enable;
+};
+
 struct nic_mbx {
 /* 128 bit shared memory between PF and each VF */
 union {
@@ -186,6 +194,7 @@ union {
        struct sqs_alloc        sqs_alloc;
        struct set_loopback     lbk;
        struct reset_stat_cfg   reset_stat;
+       struct set_link_state   set_link;
 };
 };
 
@@ -210,6 +219,7 @@ int nicvf_mbox_rq_sync(struct nicvf *nic);
 int nicvf_mbox_loopback_config(struct nicvf *nic, bool enable);
 int nicvf_mbox_reset_stat_counters(struct nicvf *nic, uint16_t rx_stat_mask,
        uint8_t tx_stat_mask, uint16_t rq_stat_mask, uint16_t sq_stat_mask);
+int nicvf_mbox_set_link_up_down(struct nicvf *nic, bool enable);
 void nicvf_mbox_shutdown(struct nicvf *nic);
 void nicvf_mbox_cfg_done(struct nicvf *nic);
 
index 2cf0ffe..6f43541 100644 (file)
@@ -1988,6 +1988,37 @@ nicvf_dev_configure(struct rte_eth_dev *dev)
        return 0;
 }
 
+static int
+nicvf_dev_set_link_up(struct rte_eth_dev *dev)
+{
+       struct nicvf *nic = nicvf_pmd_priv(dev);
+       int rc, i;
+
+       rc = nicvf_mbox_set_link_up_down(nic, true);
+       if (rc)
+               goto done;
+
+       /* Start tx queues  */
+       for (i = 0; i < dev->data->nb_tx_queues; i++)
+               nicvf_dev_tx_queue_start(dev, i);
+
+done:
+       return rc;
+}
+
+static int
+nicvf_dev_set_link_down(struct rte_eth_dev *dev)
+{
+       struct nicvf *nic = nicvf_pmd_priv(dev);
+       int i;
+
+       /* Stop tx queues  */
+       for (i = 0; i < dev->data->nb_tx_queues; i++)
+               nicvf_dev_tx_queue_stop(dev, i);
+
+       return nicvf_mbox_set_link_up_down(nic, false);
+}
+
 /* Initialize and register driver with DPDK Application */
 static const struct eth_dev_ops nicvf_eth_dev_ops = {
        .dev_configure            = nicvf_dev_configure,
@@ -2015,6 +2046,8 @@ static const struct eth_dev_ops nicvf_eth_dev_ops = {
        .rx_queue_count           = nicvf_dev_rx_queue_count,
        .tx_queue_setup           = nicvf_dev_tx_queue_setup,
        .tx_queue_release         = nicvf_dev_tx_queue_release,
+       .dev_set_link_up          = nicvf_dev_set_link_up,
+       .dev_set_link_down        = nicvf_dev_set_link_down,
        .get_reg                  = nicvf_dev_get_regs,
 };