net/ionic: improve link state handling
[dpdk.git] / drivers / net / ionic / ionic_lif.c
index 875c7e5..c1a95ca 100644 (file)
@@ -25,7 +25,6 @@ ionic_qcq_enable(struct ionic_qcq *qcq)
                .pending_work = true,
                .cmd.q_control = {
                        .opcode = IONIC_CMD_Q_CONTROL,
-                       .lif_index = lif->index,
                        .type = q->type,
                        .index = q->index,
                        .oper = IONIC_Q_ENABLE,
@@ -50,7 +49,6 @@ ionic_qcq_disable(struct ionic_qcq *qcq)
                .pending_work = true,
                .cmd.q_control = {
                        .opcode = IONIC_CMD_Q_CONTROL,
-                       .lif_index = lif->index,
                        .type = q->type,
                        .index = q->index,
                        .oper = IONIC_Q_DISABLE,
@@ -65,12 +63,12 @@ ionic_qcq_disable(struct ionic_qcq *qcq)
        return ionic_adminq_post_wait(lif, &ctx);
 }
 
-int
-ionic_lif_stop(struct ionic_lif *lif __rte_unused)
+void
+ionic_lif_stop(struct ionic_lif *lif)
 {
-       /* Carrier OFF here */
+       IONIC_PRINT_CALL();
 
-       return 0;
+       lif->state &= ~IONIC_LIF_F_UP;
 }
 
 void
@@ -81,7 +79,7 @@ ionic_lif_reset(struct ionic_lif *lif)
 
        IONIC_PRINT_CALL();
 
-       ionic_dev_cmd_lif_reset(idev, lif->index);
+       ionic_dev_cmd_lif_reset(idev);
        err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
        if (err)
                IONIC_PRINT(WARNING, "Failed to reset %s", lif->name);
@@ -438,7 +436,6 @@ ionic_lif_rx_mode(struct ionic_lif *lif, uint32_t rx_mode)
                .pending_work = true,
                .cmd.rx_mode_set = {
                        .opcode = IONIC_CMD_RX_MODE_SET,
-                       .lif_index = lif->index,
                        .rx_mode = rx_mode,
                },
        };
@@ -530,7 +527,6 @@ ionic_lif_change_mtu(struct ionic_lif *lif, int new_mtu)
                .pending_work = true,
                .cmd.lif_setattr = {
                        .opcode = IONIC_CMD_LIF_SETATTR,
-                       .index = lif->index,
                        .attr = IONIC_LIF_ATTR_MTU,
                        .mtu = new_mtu,
                },
@@ -824,7 +820,6 @@ ionic_lif_alloc(struct ionic_lif *lif)
 {
        struct ionic_adapter *adapter = lif->adapter;
        uint32_t socket_id = rte_socket_id();
-       int dbpage_num;
        int err;
 
        /*
@@ -840,9 +835,7 @@ ionic_lif_alloc(struct ionic_lif *lif)
        rte_spinlock_init(&lif->adminq_lock);
        rte_spinlock_init(&lif->adminq_service_lock);
 
-       dbpage_num = ionic_db_page_num(lif, 0);
-
-       lif->kern_dbpage = ionic_bus_map_dbpage(adapter, dbpage_num);
+       lif->kern_dbpage = ionic_bus_map_dbpage(adapter, 0);
        if (!lif->kern_dbpage) {
                IONIC_PRINT(ERR, "Cannot map dbpage, aborting");
                return -ENOMEM;
@@ -927,6 +920,21 @@ ionic_lif_free(struct ionic_lif *lif)
        }
 }
 
+void
+ionic_lif_free_queues(struct ionic_lif *lif)
+{
+       uint32_t i;
+
+       for (i = 0; i < lif->ntxqcqs; i++) {
+               ionic_dev_tx_queue_release(lif->eth_dev->data->tx_queues[i]);
+               lif->eth_dev->data->tx_queues[i] = NULL;
+       }
+       for (i = 0; i < lif->nrxqcqs; i++) {
+               ionic_dev_rx_queue_release(lif->eth_dev->data->rx_queues[i]);
+               lif->eth_dev->data->rx_queues[i] = NULL;
+       }
+}
+
 int
 ionic_lif_rss_config(struct ionic_lif *lif,
                const uint16_t types, const uint8_t *key, const uint32_t *indir)
@@ -1090,14 +1098,32 @@ ionic_link_status_check(struct ionic_lif *lif)
                return;
 
        if (link_up) {
-               IONIC_PRINT(DEBUG, "Link up - %d Gbps",
-                       lif->info->status.link_speed);
                adapter->link_speed = lif->info->status.link_speed;
+               IONIC_PRINT(DEBUG, "Link up - %d Gbps",
+                       adapter->link_speed);
        } else {
                IONIC_PRINT(DEBUG, "Link down");
        }
 
        adapter->link_up = link_up;
+       ionic_dev_link_update(lif->eth_dev, 0);
+}
+
+static void
+ionic_lif_handle_fw_down(struct ionic_lif *lif)
+{
+       if (lif->state & IONIC_LIF_F_FW_RESET)
+               return;
+
+       lif->state |= IONIC_LIF_F_FW_RESET;
+
+       if (lif->state & IONIC_LIF_F_UP) {
+               IONIC_PRINT(NOTICE,
+                       "Surprise FW stop, stopping %s\n", lif->name);
+               ionic_lif_stop(lif);
+       }
+
+       IONIC_PRINT(NOTICE, "FW down, %s stopped", lif->name);
 }
 
 static bool
@@ -1119,14 +1145,27 @@ ionic_notifyq_cb(struct ionic_cq *cq, uint32_t cq_desc_index, void *cb_arg)
        switch (cq_desc->event.ecode) {
        case IONIC_EVENT_LINK_CHANGE:
                IONIC_PRINT(DEBUG,
-                       "Notifyq IONIC_EVENT_LINK_CHANGE eid=%jd link_status=%d link_speed=%d",
+                       "Notifyq IONIC_EVENT_LINK_CHANGE %s "
+                       "eid=%jd link_status=%d link_speed=%d",
+                       lif->name,
                        cq_desc->event.eid,
                        cq_desc->link_change.link_status,
                        cq_desc->link_change.link_speed);
 
                lif->state |= IONIC_LIF_F_LINK_CHECK_NEEDED;
+               break;
 
+       case IONIC_EVENT_RESET:
+               IONIC_PRINT(NOTICE,
+                       "Notifyq IONIC_EVENT_RESET %s "
+                       "eid=%jd, reset_code=%d state=%d",
+                       lif->name,
+                       cq_desc->event.eid,
+                       cq_desc->reset.reset_code,
+                       cq_desc->reset.state);
+               ionic_lif_handle_fw_down(lif);
                break;
+
        default:
                IONIC_PRINT(WARNING, "Notifyq bad event ecode=%d eid=%jd",
                        cq_desc->event.ecode, cq_desc->event.eid);
@@ -1174,7 +1213,7 @@ ionic_lif_adminq_init(struct ionic_lif *lif)
        struct ionic_q_init_comp comp;
        int err;
 
-       ionic_dev_cmd_adminq_init(idev, qcq, lif->index, qcq->intr.index);
+       ionic_dev_cmd_adminq_init(idev, qcq, qcq->intr.index);
        err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
        if (err)
                return err;
@@ -1210,7 +1249,6 @@ ionic_lif_notifyq_init(struct ionic_lif *lif)
                .pending_work = true,
                .cmd.q_init = {
                        .opcode = IONIC_CMD_Q_INIT,
-                       .lif_index = lif->index,
                        .type = q->type,
                        .index = q->index,
                        .flags = (IONIC_QINIT_F_IRQ | IONIC_QINIT_F_ENA),
@@ -1256,7 +1294,6 @@ ionic_lif_set_features(struct ionic_lif *lif)
                .pending_work = true,
                .cmd.lif_setattr = {
                        .opcode = IONIC_CMD_LIF_SETATTR,
-                       .index = lif->index,
                        .attr = IONIC_LIF_ATTR_FEATURES,
                        .features = lif->features,
                },
@@ -1318,7 +1355,6 @@ ionic_lif_txq_init(struct ionic_qcq *qcq)
                .pending_work = true,
                .cmd.q_init = {
                        .opcode = IONIC_CMD_Q_INIT,
-                       .lif_index = lif->index,
                        .type = q->type,
                        .index = q->index,
                        .flags = IONIC_QINIT_F_SG,
@@ -1365,7 +1401,6 @@ ionic_lif_rxq_init(struct ionic_qcq *qcq)
                .pending_work = true,
                .cmd.q_init = {
                        .opcode = IONIC_CMD_Q_INIT,
-                       .lif_index = lif->index,
                        .type = q->type,
                        .index = q->index,
                        .flags = IONIC_QINIT_F_SG,
@@ -1409,7 +1444,6 @@ ionic_station_set(struct ionic_lif *lif)
                .pending_work = true,
                .cmd.lif_getattr = {
                        .opcode = IONIC_CMD_LIF_GETATTR,
-                       .index = lif->index,
                        .attr = IONIC_LIF_ATTR_MAC,
                },
        };
@@ -1449,7 +1483,6 @@ ionic_lif_set_name(struct ionic_lif *lif)
                .pending_work = true,
                .cmd.lif_setattr = {
                        .opcode = IONIC_CMD_LIF_SETATTR,
-                       .index = lif->index,
                        .attr = IONIC_LIF_ATTR_NAME,
                },
        };
@@ -1469,7 +1502,7 @@ ionic_lif_init(struct ionic_lif *lif)
 
        memset(&lif->stats_base, 0, sizeof(lif->stats_base));
 
-       ionic_dev_cmd_lif_init(idev, lif->index, lif->info_pa);
+       ionic_dev_cmd_lif_init(idev, lif->info_pa);
        err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
        ionic_dev_cmd_comp(idev, &comp);
        if (err)
@@ -1616,9 +1649,10 @@ ionic_lif_start(struct ionic_lif *lif)
                }
        }
 
-       ionic_link_status_check(lif);
-
        /* Carrier ON here */
+       lif->state |= IONIC_LIF_F_UP;
+
+       ionic_link_status_check(lif);
 
        return 0;
 }
@@ -1672,7 +1706,6 @@ int
 ionic_lifs_size(struct ionic_adapter *adapter)
 {
        struct ionic_identity *ident = &adapter->ident;
-       uint32_t nlifs = ident->dev.nlifs;
        uint32_t nintrs, dev_nintrs = ident->dev.nintrs;
 
        adapter->max_ntxqs_per_lif =
@@ -1680,7 +1713,7 @@ ionic_lifs_size(struct ionic_adapter *adapter)
        adapter->max_nrxqs_per_lif =
                ident->lif.eth.config.queue_count[IONIC_QTYPE_RXQ];
 
-       nintrs = nlifs * 1 /* notifyq */;
+       nintrs = 1 /* notifyq */;
 
        if (nintrs > dev_nintrs) {
                IONIC_PRINT(ERR,