net/enic: extract code for checking link status
[dpdk.git] / drivers / net / enic / enic_main.c
index d117f30..a0283ca 100644 (file)
@@ -123,6 +123,8 @@ static void enic_log_q_error(struct enic *enic)
        }
 
        for (i = 0; i < enic_vnic_rq_count(enic); i++) {
+               if (!enic->rq[i].in_use)
+                       continue;
                error_status = vnic_rq_error_status(&enic->rq[i]);
                if (error_status)
                        dev_err(enic, "RQ[%d] error_status %d\n", i,
@@ -172,7 +174,8 @@ void enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats)
         * which can make ibytes be slightly higher than it should be.
         */
        rx_packet_errors = rte_atomic64_read(&soft_stats->rx_packet_errors);
-       rx_truncated = rx_packet_errors - stats->rx.rx_errors;
+       rx_truncated = rx_packet_errors - stats->rx.rx_errors -
+               stats->rx.rx_no_bufs;
 
        r_stats->ipackets = stats->rx.rx_frames_ok - rx_truncated;
        r_stats->opackets = stats->tx.tx_frames_ok;
@@ -314,6 +317,7 @@ enic_alloc_rx_queue_mbufs(struct enic *enic, struct vnic_rq *rq)
                        return -ENOMEM;
                }
 
+               mb->data_off = RTE_PKTMBUF_HEADROOM;
                dma_addr = (dma_addr_t)(mb->buf_physaddr
                           + RTE_PKTMBUF_HEADROOM);
                rq_enet_desc_enc(rqd, dma_addr,
@@ -407,6 +411,21 @@ enic_free_consistent(void *priv,
        rte_free(mze);
 }
 
+int enic_link_update(struct enic *enic)
+{
+       struct rte_eth_dev *eth_dev = enic->rte_dev;
+       int ret;
+       int link_status = 0;
+
+       link_status = enic_get_link_status(enic);
+       ret = (link_status == enic->link_status);
+       enic->link_status = link_status;
+       eth_dev->data->dev_link.link_status = link_status;
+       eth_dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
+       eth_dev->data->dev_link.link_speed = vnic_dev_port_speed(enic->vdev);
+       return ret;
+}
+
 static void
 enic_intr_handler(__rte_unused struct rte_intr_handle *handle,
        void *arg)
@@ -426,7 +445,6 @@ int enic_enable(struct enic *enic)
 
        eth_dev->data->dev_link.link_speed = vnic_dev_port_speed(enic->vdev);
        eth_dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
-       vnic_dev_notify_set(enic->vdev, -1); /* No Intr for notify */
 
        if (enic_clsf_init(enic))
                dev_warning(enic, "Init of hash table for clsf failed."\
@@ -794,6 +812,10 @@ int enic_disable(struct enic *enic)
 
        vnic_intr_mask(&enic->intr);
        (void)vnic_intr_masked(&enic->intr); /* flush write */
+       rte_intr_disable(&enic->pdev->intr_handle);
+       rte_intr_callback_unregister(&enic->pdev->intr_handle,
+                                    enic_intr_handler,
+                                    (void *)enic->rte_dev);
 
        vnic_dev_disable(enic->vdev);
 
@@ -816,7 +838,6 @@ int enic_disable(struct enic *enic)
        }
 
        vnic_dev_set_reset_flag(enic->vdev, 1);
-       vnic_dev_notify_unset(enic->vdev);
 
        for (i = 0; i < enic->wq_count; i++)
                vnic_wq_clean(&enic->wq[i], enic_free_wq_buf);
@@ -1018,6 +1039,9 @@ static void enic_dev_deinit(struct enic *enic)
 {
        struct rte_eth_dev *eth_dev = enic->rte_dev;
 
+       /* stop link status checking */
+       vnic_dev_notify_unset(enic->vdev);
+
        rte_free(eth_dev->data->mac_addrs);
 }
 
@@ -1133,6 +1157,9 @@ static int enic_dev_init(struct enic *enic)
 
        vnic_dev_set_reset_flag(enic->vdev, 0);
 
+       /* set up link status checking */
+       vnic_dev_notify_set(enic->vdev, -1); /* No Intr for notify */
+
        return 0;
 
 }