dma/odm: dev-to-mem support and zero-length validation
cover dma/odm: dev-to-mem support and zero-length validation
This series extends the Marvell ODM DMA driver with device memory bidirectional DMA transfers (dev-to-mem and mem-to-dev), and rejects zero-length operations early with -EINVAL to avoid queue disable.
Shijith Thotton (1):
dma/odm: avoid zero length DMA transfers
Vamsi Attunuru (1):
dma/odm: support dev to mem transfers
drivers/dma/odm/odm.c | 51 ++++++++++++++++++++++++++++++++++-- drivers/dma/odm/odm.h | 12 ++++++++- drivers/dma/odm/odm_dmadev.c | 27 ++++++++++++++----- drivers/dma/odm/odm_priv.h | 4 ++- 4 files changed, 84 insertions(+), 10 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 dma/odm: support dev to mem transfers
From: Vamsi Attunuru <[email protected]>
Adds support for dev to mem and mem to dev
DMA transfers.
--- drivers/dma/odm/odm.c | 51 ++++++++++++++++++++++++++++++++++-- drivers/dma/odm/odm.h | 12 ++++++++- drivers/dma/odm/odm_dmadev.c | 9 ++++--- drivers/dma/odm/odm_priv.h | 4 ++- 4 files changed, 69 insertions(+), 7 deletions(-)
drivers/dma/odm/odm.c +49 -2
@@ -125,13 +125,41 @@ odm_disable(struct odm_dev *odm)return 0 ; } +static int +odm_get_ext_port_type (const struct rte_dma_vchan_conf *conf,uint8_t *ext_port) +{ +uint8_t coreid; + +if (conf->src_port.port_type ==RTE_DMA_PORT_PCIE ) { + coreid = conf->src_port.pcie.coreid; + }else if (conf->dst_port.port_type ==RTE_DMA_PORT_PCIE ) { + coreid = conf->dst_port.pcie.coreid; + }else { + *ext_port =ODM_EXT_PORT_NCB ; +return 0 ; + } + +switch (coreid) { +case 0 : + *ext_port =ODM_EXT_PORT_PEM0 ; +return 0 ; +case 1 : + *ext_port =ODM_EXT_PORT_PEM1 ; +return 0 ; +default : +ODM_LOG (ERR ,"Unsupported PCIe coreid %u (only 0 and 1 are valid)" , coreid); +return -EINVAL ; + } +} +int -odm_vchan_setup (struct odm_dev *odm,int vchan,int nb_desc) +odm_vchan_setup (struct odm_dev *odm,int vchan,const struct rte_dma_vchan_conf *conf) {struct odm_queue *vq = &odm->vq[vchan];int isize, csize, max_nb_desc, rc =0 ;union odm_mbox_msg mbox_msg;const struct rte_memzone *mz; +uint8_t ext_port;char name[32 ];if (vq->iring_mz !=NULL )
@@ -140,10 +168,29 @@ odm_vchan_setup(struct odm_dev *odm, int vchan, int nb_desc) mbox_msg.u[0 ] =0 ; mbox_msg.u[1 ] =0 ; +switch (conf->direction) { +case RTE_DMA_DIR_DEV_TO_MEM : + vq->xtype =ODM_XTYPE_INBOUND ; +break ; +case RTE_DMA_DIR_MEM_TO_DEV : + vq->xtype =ODM_XTYPE_OUTBOUND ; +break ; +case RTE_DMA_DIR_MEM_TO_MEM : + vq->xtype =ODM_XTYPE_INTERNAL ; +break ; +default : +ODM_LOG (ERR ,"Unsupported DMA direction %d" , conf->direction); +return -EINVAL ; + } +/* ODM PF driver expects vfid starts from index 0 */ mbox_msg.q.vfid = odm->vfid; mbox_msg.q.cmd =ODM_QUEUE_OPEN ; mbox_msg.q.qidx = vchan; + rc =odm_get_ext_port_type (conf, &ext_port); +if (rc <0 ) +return rc; + mbox_msg.q.ext_port = ext_port; rc =send_mbox_to_pf (odm, &mbox_msg, &mbox_msg);if (rc <0 )return rc;
@@ -151,7 +198,7 @@ odm_vchan_setup(struct odm_dev *odm, int vchan, int nb_desc)/* Determine instruction & completion ring sizes. */ /* Create iring that can support nb_desc. Round up to a multiple of 1024. */ - isize =RTE_ALIGN_CEIL (nb_desc *ODM_IRING_ENTRY_SIZE_MAX *8 ,1024 ); + isize =RTE_ALIGN_CEIL (conf->nb_desc *ODM_IRING_ENTRY_SIZE_MAX *8 ,1024 ); isize =RTE_MIN (isize,ODM_IRING_MAX_SIZE );snprintf (name,sizeof (name),"vq%d_iring%d" , odm->vfid, vchan); mz =rte_memzone_reserve_aligned (name, isize,SOCKET_ID_ANY ,0 ,1024 );
drivers/dma/odm/odm.h +11 -1
@@ -9,6 +9,7 @@#include <rte_common.h> #include <rte_compat.h> +#include <rte_dmadev.h> #include <rte_io.h> #include <rte_log.h> #include <rte_memzone.h>
@@ -40,10 +41,17 @@* ODM Transfer Type Enumeration * Enumerates the pointer type in ODM_DMA_INSTR_HDR_S[XTYPE] */ +#define ODM_XTYPE_OUTBOUND 0 +#define ODM_XTYPE_INBOUND 1#define ODM_XTYPE_INTERNAL 2#define ODM_XTYPE_FILL0 4#define ODM_XTYPE_FILL1 5 +/* ODM external port type */ +#define ODM_EXT_PORT_PEM0 0x0 +#define ODM_EXT_PORT_PEM1 0x1 +#define ODM_EXT_PORT_NCB 0x2 +/* * ODM Header completion type enumeration * Enumerates the completion type in ODM_DMA_INSTR_HDR_S[CT]
@@ -168,6 +176,8 @@ struct odm_queue {uint16_t iring_max_words;/* Number of words in cring.*/ uint16_t cring_max_entry; +/* DMA transfer type.*/ +uint16_t xtype;/* Extra instruction size used per inflight instruction.*/ uint8_t *extra_ins_sz;struct vq_stats stats;
@@ -189,6 +199,6 @@ int odm_dev_fini(struct odm_dev *odm);int odm_configure (struct odm_dev *odm);int odm_enable (struct odm_dev *odm);int odm_disable (struct odm_dev *odm); -int odm_vchan_setup (struct odm_dev *odm,int vchan,int nb_desc); +int odm_vchan_setup (struct odm_dev *odm,int vchan,const struct rte_dma_vchan_conf *conf);#endif /* _ODM_H_ */
drivers/dma/odm/odm_dmadev.c +6 -3
@@ -30,7 +30,8 @@ odm_dmadev_info_get(const struct rte_dma_dev *dev, struct rte_dma_info *dev_info dev_info->max_vchans = odm->max_qs; dev_info->nb_vchans = odm->num_qs; dev_info->dev_capa = - (RTE_DMA_CAPA_MEM_TO_MEM |RTE_DMA_CAPA_OPS_COPY |RTE_DMA_CAPA_OPS_COPY_SG ); + (RTE_DMA_CAPA_MEM_TO_MEM |RTE_DMA_CAPA_OPS_COPY |RTE_DMA_CAPA_OPS_COPY_SG | +RTE_DMA_CAPA_MEM_TO_DEV |RTE_DMA_CAPA_DEV_TO_MEM ); dev_info->max_desc =ODM_IRING_MAX_ENTRY ; dev_info->min_desc =1 ; dev_info->max_sges =ODM_MAX_POINTER ;
@@ -58,7 +59,7 @@ odm_dmadev_vchan_setup(struct rte_dma_dev *dev, uint16_t vchan,struct odm_dev *odm = dev->fp_obj->dev_private;RTE_SET_USED (conf_sz); -return odm_vchan_setup (odm, vchan, conf->nb_desc); +return odm_vchan_setup (odm, vchan, conf); } static int
@@ -99,7 +100,7 @@ odm_dmadev_copy(void *dev_private, uint16_t vchan, rte_iova_t src, rte_iova_t dsstruct odm_queue *vq;uint64_t h; -const union odm_instr_hdr_s hdr = { +union odm_instr_hdr_s hdr = { .s.ct =ODM_HDR_CT_CW_NC , .s.xtype =ODM_XTYPE_INTERNAL , .s.nfst =1 ,
@@ -107,6 +108,7 @@ odm_dmadev_copy(void *dev_private, uint16_t vchan, rte_iova_t src, rte_iova_t ds }; vq = &odm->vq[vchan]; + hdr.s.xtype = vq->xtype; h = length; h |= ((uint64_t )length <<32 );
@@ -252,6 +254,7 @@ odm_dmadev_copy_sg(void *dev_private, uint16_t vchan, const struct rte_dma_sge * vq = &odm->vq[vchan];const uint16_t max_iring_words = vq->iring_max_words; + hdr.s.xtype = vq->xtype; iring_head_ptr = vq->iring_mz->addr; iring_head = vq->iring_head; iring_sz_available = vq->iring_sz_available;
drivers/dma/odm/odm_priv.h +3 -1
@@ -34,8 +34,10 @@ struct odm_mbox_queue_msg { uint64_t vfid : 8;/* Queue index in the VF */ uint64_t qidx : 8; +/* Port type for external DMA access */ + uint64_t ext_port : 8;/* Reserved */ - uint64_t rsvd_24_63 : 40; + uint64_t rsvd_32_63 : 32; };union odm_mbox_msg {
Signature · 1 line
2.25.1
PATCH 2/2 dma/odm: avoid zero length DMA transfers
In reply to Shijith ThottonAdd validation to reject zero-length DMA operations early with -EINVAL, preventing queue disable.
--- drivers/dma/odm/odm_dmadev.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/dma/odm/odm_dmadev.c +15 -3
@@ -110,6 +110,9 @@ odm_dmadev_copy(void *dev_private, uint16_t vchan, rte_iova_t src, rte_iova_t ds vq = &odm->vq[vchan]; hdr.s.xtype = vq->xtype; +if (unlikely (!length)) +return -EINVAL ; + h = length; h |= ((uint64_t )length <<32 );
@@ -262,14 +265,20 @@ odm_dmadev_copy_sg(void *dev_private, uint16_t vchan, const struct rte_dma_sge * pending_submit_len = vq->pending_submit_len; pending_submit_cnt = vq->pending_submit_cnt; -if (unlikely (nb_src >4 || nb_dst >4 )) +if (unlikely (!nb_src || nb_src >4 || !nb_dst || nb_dst >4 ))return -EINVAL ; -for (i =0 ; i < nb_src; i++) +for (i =0 ; i < nb_src; i++) { +if (unlikely (!src[i].length)) +return -EINVAL ; s_sz += src[i].length; + } -for (i =0 ; i < nb_dst; i++) +for (i =0 ; i < nb_dst; i++) { +if (unlikely (!dst[i].length)) +return -EINVAL ; d_sz += dst[i].length; + }if (s_sz != d_sz)return -EINVAL ;
@@ -342,6 +351,9 @@ odm_dmadev_fill(void *dev_private, uint16_t vchan, uint64_t pattern, rte_iova_t .s.nlst = 1, }; +if (unlikely (!length)) +return -EINVAL ; + h = (uint64_t )length;switch (pattern) {
Signature · 1 line
2.25.1
Re: [PATCH v1 2/2] dma/odm: avoid zero length DMA transfers
Quoted 5 lines · Shijith Thotton
Add validation to reject zero-length DMA operations early with
-EINVAL, preventing queue disable.Signed-off-by Shijith Thotton <[email protected]>
Added Fixes to 2/2 patch.
Series applied to dpdk-next-net-mrvl/for-main. Thanks
Quoted 55 lines
--- drivers/dma/odm/odm_dmadev.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)drivers/dma/odm/odm_dmadev.c +15
-4@@ -110,6 +110,9 @@ odm_dmadev_copy(void *dev_private, uint16_t vchan, rte_iova_t src, rte_iova_t ds vq = &odm->vq[vchan]; hdr.s.xtype = vq->xtype; +if (unlikely (!length)) +return -EINVAL ; + h = length; h |= ((uint64_t )length <<32 );@@ -262,14 +265,20 @@ odm_dmadev_copy_sg(void *dev_private, uint16_t vchan, const struct rte_dma_sge * pending_submit_len = vq->pending_submit_len; pending_submit_cnt = vq->pending_submit_cnt; -if (unlikely (nb_src >4 || nb_dst >4 )) +if (unlikely (!nb_src || nb_src >4 || !nb_dst || nb_dst >4 ))return -EINVAL ; -for (i =0 ; i < nb_src; i++) +for (i =0 ; i < nb_src; i++) { +if (unlikely (!src[i].length)) +return -EINVAL ; s_sz += src[i].length; + } -for (i =0 ; i < nb_dst; i++) +for (i =0 ; i < nb_dst; i++) { +if (unlikely (!dst[i].length)) +return -EINVAL ; d_sz += dst[i].length; + }if (s_sz != d_sz)return -EINVAL ;@@ -342,6 +351,9 @@ odm_dmadev_fill(void *dev_private, uint16_t vchan, uint64_t pattern, rte_iova_t .s.nlst = 1, }; +if (unlikely (!length)) +return -EINVAL ; + h = (uint64_t )length;switch (pattern) { --2.25.1