mbuf: rename data address helpers to IOVA
[dpdk.git] / drivers / net / liquidio / lio_rxtx.c
index 470131c..efad4e7 100644 (file)
@@ -81,28 +81,6 @@ lio_droq_destroy_ring_buffers(struct lio_droq *droq)
        lio_droq_reset_indices(droq);
 }
 
-static void *
-lio_recv_buffer_alloc(struct lio_device *lio_dev, int q_no)
-{
-       struct lio_droq *droq = lio_dev->droq[q_no];
-       struct rte_mempool *mpool = droq->mpool;
-       struct rte_mbuf *m;
-
-       m = rte_pktmbuf_alloc(mpool);
-       if (m == NULL) {
-               lio_dev_err(lio_dev, "Cannot allocate\n");
-               return NULL;
-       }
-
-       rte_mbuf_refcnt_set(m, 1);
-       m->next = NULL;
-       m->data_off = RTE_PKTMBUF_HEADROOM;
-       m->nb_segs = 1;
-       m->pool = mpool;
-
-       return m;
-}
-
 static int
 lio_droq_setup_ring_buffers(struct lio_device *lio_dev,
                            struct lio_droq *droq)
@@ -112,7 +90,7 @@ lio_droq_setup_ring_buffers(struct lio_device *lio_dev,
        void *buf;
 
        for (i = 0; i < droq->max_count; i++) {
-               buf = lio_recv_buffer_alloc(lio_dev, droq->q_no);
+               buf = rte_pktmbuf_alloc(droq->mpool);
                if (buf == NULL) {
                        lio_dev_err(lio_dev, "buffer alloc failed\n");
                        droq->stats.rx_alloc_failure++;
@@ -194,7 +172,7 @@ lio_alloc_info_buffer(struct lio_device *lio_dev,
        if (droq->info_mz == NULL)
                return NULL;
 
-       droq->info_list_dma = droq->info_mz->phys_addr;
+       droq->info_list_dma = droq->info_mz->iova;
        droq->info_alloc_size = droq->info_mz->len;
        droq->info_base_addr = (size_t)droq->info_mz->addr;
 
@@ -244,7 +222,7 @@ lio_init_droq(struct lio_device *lio_dev, uint32_t q_no,
                return -1;
        }
 
-       droq->desc_ring_dma = droq->desc_ring_mz->phys_addr;
+       droq->desc_ring_dma = droq->desc_ring_mz->iova;
        droq->desc_ring = (struct lio_droq_desc *)droq->desc_ring_mz->addr;
 
        lio_dev_dbg(lio_dev, "droq[%d]: desc_ring: virt: 0x%p, dma: %lx\n",
@@ -378,7 +356,6 @@ lio_droq_refill_pullup_descs(struct lio_droq *droq,
 
 /* lio_droq_refill
  *
- * @param lio_dev      - pointer to the lio device structure
  * @param droq         - droq in which descriptors require new buffers.
  *
  * Description:
@@ -394,7 +371,7 @@ lio_droq_refill_pullup_descs(struct lio_droq *droq,
  * This routine is called with droq->lock held.
  */
 static uint32_t
-lio_droq_refill(struct lio_device *lio_dev, struct lio_droq *droq)
+lio_droq_refill(struct lio_droq *droq)
 {
        struct lio_droq_desc *desc_ring;
        uint32_t desc_refilled = 0;
@@ -407,7 +384,7 @@ lio_droq_refill(struct lio_device *lio_dev, struct lio_droq *droq)
                 * reuse the buffer, else allocate.
                 */
                if (droq->recv_buf_list[droq->refill_idx].buffer == NULL) {
-                       buf = lio_recv_buffer_alloc(lio_dev, droq->q_no);
+                       buf = rte_pktmbuf_alloc(droq->mpool);
                        /* If a buffer could not be allocated, no point in
                         * continuing
                         */
@@ -489,9 +466,6 @@ lio_droq_fast_process_packet(struct lio_device *lio_dev,
                        droq->refill_count++;
 
                        if (likely(nicbuf != NULL)) {
-                               nicbuf->data_off = RTE_PKTMBUF_HEADROOM;
-                               nicbuf->nb_segs = 1;
-                               nicbuf->next = NULL;
                                /* We don't have a way to pass flags yet */
                                nicbuf->ol_flags = 0;
                                if (rh->r_dh.has_hash) {
@@ -545,9 +519,6 @@ lio_droq_fast_process_packet(struct lio_device *lio_dev,
                                        if (!pkt_len)
                                                first_buf = nicbuf;
 
-                                       nicbuf->data_off = RTE_PKTMBUF_HEADROOM;
-                                       nicbuf->nb_segs = 1;
-                                       nicbuf->next = NULL;
                                        nicbuf->port = lio_dev->port_id;
                                        /* We don't have a way to pass
                                         * flags yet
@@ -617,7 +588,7 @@ lio_droq_fast_process_packet(struct lio_device *lio_dev,
        }
 
        if (droq->refill_count >= droq->refill_threshold) {
-               int desc_refilled = lio_droq_refill(lio_dev, droq);
+               int desc_refilled = lio_droq_refill(droq);
 
                /* Flush the droq descriptor data to memory to be sure
                 * that when we update the credits the data in memory is
@@ -763,7 +734,7 @@ lio_init_instr_queue(struct lio_device *lio_dev,
                return -1;
        }
 
-       iq->base_addr_dma = iq->iq_mz->phys_addr;
+       iq->base_addr_dma = iq->iq_mz->iova;
        iq->base_addr = (uint8_t *)iq->iq_mz->addr;
 
        iq->max_count = num_descs;
@@ -918,6 +889,40 @@ release_lio_iq:
        return -1;
 }
 
+int
+lio_wait_for_instr_fetch(struct lio_device *lio_dev)
+{
+       int pending, instr_cnt;
+       int i, retry = 1000;
+
+       do {
+               instr_cnt = 0;
+
+               for (i = 0; i < LIO_MAX_INSTR_QUEUES(lio_dev); i++) {
+                       if (!(lio_dev->io_qmask.iq & (1ULL << i)))
+                               continue;
+
+                       if (lio_dev->instr_queue[i] == NULL)
+                               break;
+
+                       pending = rte_atomic64_read(
+                           &lio_dev->instr_queue[i]->instr_pending);
+                       if (pending)
+                               lio_flush_iq(lio_dev, lio_dev->instr_queue[i]);
+
+                       instr_cnt += pending;
+               }
+
+               if (instr_cnt == 0)
+                       break;
+
+               rte_delay_ms(1);
+
+       } while (retry-- && instr_cnt);
+
+       return instr_cnt;
+}
+
 static inline void
 lio_ring_doorbell(struct lio_device *lio_dev,
                  struct lio_instr_queue *iq)
@@ -1293,7 +1298,7 @@ lio_alloc_soft_command(struct lio_device *lio_dev, uint32_t datasize,
        sc = rte_pktmbuf_mtod(m, struct lio_soft_command *);
        memset(sc, 0, LIO_SOFT_COMMAND_BUFFER_SIZE);
        sc->size = LIO_SOFT_COMMAND_BUFFER_SIZE;
-       sc->dma_addr = rte_mbuf_data_dma_addr(m);
+       sc->dma_addr = rte_mbuf_data_iova(m);
        sc->mbuf = m;
 
        dma_addr = sc->dma_addr;
@@ -1734,7 +1739,7 @@ lio_dev_xmit_pkts(void *tx_queue, struct rte_mbuf **pkts, uint16_t nb_pkts)
                        cmdsetup.s.u.datasize = pkt_len;
                        lio_prepare_pci_cmd(lio_dev, &ndata.cmd,
                                            &cmdsetup, tag);
-                       ndata.cmd.cmd3.dptr = rte_mbuf_data_dma_addr(m);
+                       ndata.cmd.cmd3.dptr = rte_mbuf_data_iova(m);
                        ndata.reqtype = LIO_REQTYPE_NORESP_NET;
                } else {
                        struct lio_buf_free_info *finfo;
@@ -1766,7 +1771,7 @@ lio_dev_xmit_pkts(void *tx_queue, struct rte_mbuf **pkts, uint16_t nb_pkts)
                                            &cmdsetup, tag);
 
                        memset(g->sg, 0, g->sg_size);
-                       g->sg[0].ptr[0] = rte_mbuf_data_dma_addr(m);
+                       g->sg[0].ptr[0] = rte_mbuf_data_iova(m);
                        lio_add_sg_size(&g->sg[0], m->data_len, 0);
                        pkt_len = m->data_len;
                        finfo->mbuf = m;
@@ -1777,7 +1782,7 @@ lio_dev_xmit_pkts(void *tx_queue, struct rte_mbuf **pkts, uint16_t nb_pkts)
                        m = m->next;
                        while (frags--) {
                                g->sg[(i >> 2)].ptr[(i & 3)] =
-                                               rte_mbuf_data_dma_addr(m);
+                                               rte_mbuf_data_iova(m);
                                lio_add_sg_size(&g->sg[(i >> 2)],
                                                m->data_len, (i & 3));
                                pkt_len += m->data_len;
@@ -1785,7 +1790,7 @@ lio_dev_xmit_pkts(void *tx_queue, struct rte_mbuf **pkts, uint16_t nb_pkts)
                                m = m->next;
                        }
 
-                       phyaddr = rte_mem_virt2phy(g->sg);
+                       phyaddr = rte_mem_virt2iova(g->sg);
                        if (phyaddr == RTE_BAD_PHYS_ADDR) {
                                PMD_TX_LOG(lio_dev, ERR, "bad phys addr\n");
                                goto xmit_failed;
@@ -1826,3 +1831,26 @@ xmit_failed:
        return processed;
 }
 
+void
+lio_dev_clear_queues(struct rte_eth_dev *eth_dev)
+{
+       struct lio_instr_queue *txq;
+       struct lio_droq *rxq;
+       uint16_t i;
+
+       for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
+               txq = eth_dev->data->tx_queues[i];
+               if (txq != NULL) {
+                       lio_dev_tx_queue_release(txq);
+                       eth_dev->data->tx_queues[i] = NULL;
+               }
+       }
+
+       for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
+               rxq = eth_dev->data->rx_queues[i];
+               if (rxq != NULL) {
+                       lio_dev_rx_queue_release(rxq);
+                       eth_dev->data->rx_queues[i] = NULL;
+               }
+       }
+}