net/liquidio: add APIs to allocate and free soft command
authorShijith Thotton <shijith.thotton@caviumnetworks.com>
Sat, 25 Mar 2017 06:24:27 +0000 (11:54 +0530)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 4 Apr 2017 16:59:48 +0000 (18:59 +0200)
Get buffers from SC buffer pool and create soft command. Buffers are
freed to the pool once the command reaches device.

Signed-off-by: Shijith Thotton <shijith.thotton@caviumnetworks.com>
Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
Signed-off-by: Derek Chickles <derek.chickles@caviumnetworks.com>
Signed-off-by: Venkat Koppula <venkat.koppula@caviumnetworks.com>
Signed-off-by: Srisivasubramanian S <ssrinivasan@caviumnetworks.com>
Signed-off-by: Mallesham Jatharakonda <mjatharakonda@oneconvergence.com>
drivers/net/liquidio/lio_rxtx.c
drivers/net/liquidio/lio_rxtx.h
drivers/net/liquidio/lio_struct.h

index 1c6ce59..cfec96d 100644 (file)
@@ -227,3 +227,69 @@ lio_free_sc_buffer_pool(struct lio_device *lio_dev)
 {
        rte_mempool_free(lio_dev->sc_buf_pool);
 }
+
+struct lio_soft_command *
+lio_alloc_soft_command(struct lio_device *lio_dev, uint32_t datasize,
+                      uint32_t rdatasize, uint32_t ctxsize)
+{
+       uint32_t offset = sizeof(struct lio_soft_command);
+       struct lio_soft_command *sc;
+       struct rte_mbuf *m;
+       uint64_t dma_addr;
+
+       RTE_ASSERT((offset + datasize + rdatasize + ctxsize) <=
+                  LIO_SOFT_COMMAND_BUFFER_SIZE);
+
+       m = rte_pktmbuf_alloc(lio_dev->sc_buf_pool);
+       if (m == NULL) {
+               lio_dev_err(lio_dev, "Cannot allocate mbuf for sc\n");
+               return NULL;
+       }
+
+       /* set rte_mbuf data size and there is only 1 segment */
+       m->pkt_len = LIO_SOFT_COMMAND_BUFFER_SIZE;
+       m->data_len = LIO_SOFT_COMMAND_BUFFER_SIZE;
+
+       /* use rte_mbuf buffer for soft command */
+       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->mbuf = m;
+
+       dma_addr = sc->dma_addr;
+
+       if (ctxsize) {
+               sc->ctxptr = (uint8_t *)sc + offset;
+               sc->ctxsize = ctxsize;
+       }
+
+       /* Start data at 128 byte boundary */
+       offset = (offset + ctxsize + 127) & 0xffffff80;
+
+       if (datasize) {
+               sc->virtdptr = (uint8_t *)sc + offset;
+               sc->dmadptr = dma_addr + offset;
+               sc->datasize = datasize;
+       }
+
+       /* Start rdata at 128 byte boundary */
+       offset = (offset + datasize + 127) & 0xffffff80;
+
+       if (rdatasize) {
+               RTE_ASSERT(rdatasize >= 16);
+               sc->virtrptr = (uint8_t *)sc + offset;
+               sc->dmarptr = dma_addr + offset;
+               sc->rdatasize = rdatasize;
+               sc->status_word = (uint64_t *)((uint8_t *)(sc->virtrptr) +
+                                              rdatasize - 8);
+       }
+
+       return sc;
+}
+
+void
+lio_free_soft_command(struct lio_soft_command *sc)
+{
+       rte_pktmbuf_free(sc->mbuf);
+}
index b308211..284cb18 100644 (file)
@@ -53,9 +53,47 @@ struct lio_request_list {
 /** Maximum number of buffers to allocate into soft command buffer pool */
 #define LIO_MAX_SOFT_COMMAND_BUFFERS   255
 
+struct lio_soft_command {
+       /** Soft command buffer info. */
+       struct lio_stailq_node node;
+       uint64_t dma_addr;
+       uint32_t size;
+
+#define LIO_COMPLETION_WORD_INIT       0xffffffffffffffffULL
+       uint64_t *status_word;
+
+       /** Data buffer info */
+       void *virtdptr;
+       uint64_t dmadptr;
+       uint32_t datasize;
+
+       /** Return buffer info */
+       void *virtrptr;
+       uint64_t dmarptr;
+       uint32_t rdatasize;
+
+       /** Context buffer info */
+       void *ctxptr;
+       uint32_t ctxsize;
+
+       /** Time out and callback */
+       size_t wait_time;
+       size_t timeout;
+       uint32_t iq_no;
+       void (*callback)(uint32_t, void *);
+       void *callback_arg;
+       struct rte_mbuf *mbuf;
+};
+
 int lio_setup_sc_buffer_pool(struct lio_device *lio_dev);
 void lio_free_sc_buffer_pool(struct lio_device *lio_dev);
 
+struct lio_soft_command *
+lio_alloc_soft_command(struct lio_device *lio_dev,
+                      uint32_t datasize, uint32_t rdatasize,
+                      uint32_t ctxsize);
+void lio_free_soft_command(struct lio_soft_command *sc);
+
 /** Setup instruction queue zero for the device
  *  @param lio_dev which lio device to setup
  *
index 992ad39..45f9ac9 100644 (file)
 
 #include "lio_hw_defs.h"
 
+struct lio_stailq_node {
+       STAILQ_ENTRY(lio_stailq_node) entries;
+};
+
+STAILQ_HEAD(lio_stailq_head, lio_stailq_node);
+
 struct lio_version {
        uint16_t major;
        uint16_t minor;