Commit cd116318 authored by Hemant Kumar's avatar Hemant Kumar Committed by Greg Kroah-Hartman

bus: mhi: core: Refactor mhi queue APIs

Move all the common code to generate TRE from mhi_queue_buf,
mhi_queue_dma and mhi_queue_skb to mhi_gen_tre. This helps
to centralize the TRE generation code which makes any future
bug fixing easier to manage in these APIs.
Suggested-by: default avatarJeffrey Hugo <jhugo@codeaurora.org>
Signed-off-by: default avatarHemant Kumar <hemantk@codeaurora.org>
Signed-off-by: default avatarBhaumik Bhatt <bbhatt@codeaurora.org>
Reviewed-by: default avatarJeffrey Hugo <jhugo@codeaurora.org>
Reviewed-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://lore.kernel.org/r/20200521170249.21795-2-manivannan.sadhasivam@linaro.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ddc0aef0
...@@ -670,8 +670,7 @@ irqreturn_t mhi_intvec_threaded_handler(int irq_number, void *dev); ...@@ -670,8 +670,7 @@ irqreturn_t mhi_intvec_threaded_handler(int irq_number, void *dev);
irqreturn_t mhi_intvec_handler(int irq_number, void *dev); irqreturn_t mhi_intvec_handler(int irq_number, void *dev);
int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan, int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
void *buf, void *cb, size_t buf_len, enum mhi_flags flags); struct mhi_buf_info *info, enum mhi_flags flags);
int mhi_map_single_no_bb(struct mhi_controller *mhi_cntrl, int mhi_map_single_no_bb(struct mhi_controller *mhi_cntrl,
struct mhi_buf_info *buf_info); struct mhi_buf_info *buf_info);
int mhi_map_single_use_bb(struct mhi_controller *mhi_cntrl, int mhi_map_single_use_bb(struct mhi_controller *mhi_cntrl,
......
...@@ -919,9 +919,7 @@ int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir, ...@@ -919,9 +919,7 @@ int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
struct mhi_chan *mhi_chan = (dir == DMA_TO_DEVICE) ? mhi_dev->ul_chan : struct mhi_chan *mhi_chan = (dir == DMA_TO_DEVICE) ? mhi_dev->ul_chan :
mhi_dev->dl_chan; mhi_dev->dl_chan;
struct mhi_ring *tre_ring = &mhi_chan->tre_ring; struct mhi_ring *tre_ring = &mhi_chan->tre_ring;
struct mhi_ring *buf_ring = &mhi_chan->buf_ring; struct mhi_buf_info buf_info = { };
struct mhi_buf_info *buf_info;
struct mhi_tre *mhi_tre;
int ret; int ret;
/* If MHI host pre-allocates buffers then client drivers cannot queue */ /* If MHI host pre-allocates buffers then client drivers cannot queue */
...@@ -946,27 +944,15 @@ int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir, ...@@ -946,27 +944,15 @@ int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
/* Toggle wake to exit out of M2 */ /* Toggle wake to exit out of M2 */
mhi_cntrl->wake_toggle(mhi_cntrl); mhi_cntrl->wake_toggle(mhi_cntrl);
/* Generate the TRE */ buf_info.v_addr = skb->data;
buf_info = buf_ring->wp; buf_info.cb_buf = skb;
buf_info.len = len;
buf_info->v_addr = skb->data;
buf_info->cb_buf = skb;
buf_info->wp = tre_ring->wp;
buf_info->dir = mhi_chan->dir;
buf_info->len = len;
ret = mhi_cntrl->map_single(mhi_cntrl, buf_info);
if (ret)
goto map_error;
mhi_tre = tre_ring->wp;
mhi_tre->ptr = MHI_TRE_DATA_PTR(buf_info->p_addr);
mhi_tre->dword[0] = MHI_TRE_DATA_DWORD0(buf_info->len);
mhi_tre->dword[1] = MHI_TRE_DATA_DWORD1(1, 1, 0, 0);
/* increment WP */ ret = mhi_gen_tre(mhi_cntrl, mhi_chan, &buf_info, mflags);
mhi_add_ring_element(mhi_cntrl, tre_ring); if (unlikely(ret)) {
mhi_add_ring_element(mhi_cntrl, buf_ring); read_unlock_bh(&mhi_cntrl->pm_lock);
return ret;
}
if (mhi_chan->dir == DMA_TO_DEVICE) if (mhi_chan->dir == DMA_TO_DEVICE)
atomic_inc(&mhi_cntrl->pending_pkts); atomic_inc(&mhi_cntrl->pending_pkts);
...@@ -980,11 +966,6 @@ int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir, ...@@ -980,11 +966,6 @@ int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
read_unlock_bh(&mhi_cntrl->pm_lock); read_unlock_bh(&mhi_cntrl->pm_lock);
return 0; return 0;
map_error:
read_unlock_bh(&mhi_cntrl->pm_lock);
return ret;
} }
EXPORT_SYMBOL_GPL(mhi_queue_skb); EXPORT_SYMBOL_GPL(mhi_queue_skb);
...@@ -996,9 +977,8 @@ int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir, ...@@ -996,9 +977,8 @@ int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
mhi_dev->dl_chan; mhi_dev->dl_chan;
struct device *dev = &mhi_cntrl->mhi_dev->dev; struct device *dev = &mhi_cntrl->mhi_dev->dev;
struct mhi_ring *tre_ring = &mhi_chan->tre_ring; struct mhi_ring *tre_ring = &mhi_chan->tre_ring;
struct mhi_ring *buf_ring = &mhi_chan->buf_ring; struct mhi_buf_info buf_info = { };
struct mhi_buf_info *buf_info; int ret;
struct mhi_tre *mhi_tre;
/* If MHI host pre-allocates buffers then client drivers cannot queue */ /* If MHI host pre-allocates buffers then client drivers cannot queue */
if (mhi_chan->pre_alloc) if (mhi_chan->pre_alloc)
...@@ -1025,25 +1005,16 @@ int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir, ...@@ -1025,25 +1005,16 @@ int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
/* Toggle wake to exit out of M2 */ /* Toggle wake to exit out of M2 */
mhi_cntrl->wake_toggle(mhi_cntrl); mhi_cntrl->wake_toggle(mhi_cntrl);
/* Generate the TRE */ buf_info.p_addr = mhi_buf->dma_addr;
buf_info = buf_ring->wp; buf_info.cb_buf = mhi_buf;
WARN_ON(buf_info->used); buf_info.pre_mapped = true;
buf_info->p_addr = mhi_buf->dma_addr; buf_info.len = len;
buf_info->pre_mapped = true;
buf_info->cb_buf = mhi_buf;
buf_info->wp = tre_ring->wp;
buf_info->dir = mhi_chan->dir;
buf_info->len = len;
mhi_tre = tre_ring->wp;
mhi_tre->ptr = MHI_TRE_DATA_PTR(buf_info->p_addr);
mhi_tre->dword[0] = MHI_TRE_DATA_DWORD0(buf_info->len);
mhi_tre->dword[1] = MHI_TRE_DATA_DWORD1(1, 1, 0, 0);
/* increment WP */ ret = mhi_gen_tre(mhi_cntrl, mhi_chan, &buf_info, mflags);
mhi_add_ring_element(mhi_cntrl, tre_ring); if (unlikely(ret)) {
mhi_add_ring_element(mhi_cntrl, buf_ring); read_unlock_bh(&mhi_cntrl->pm_lock);
return ret;
}
if (mhi_chan->dir == DMA_TO_DEVICE) if (mhi_chan->dir == DMA_TO_DEVICE)
atomic_inc(&mhi_cntrl->pending_pkts); atomic_inc(&mhi_cntrl->pending_pkts);
...@@ -1061,7 +1032,7 @@ int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir, ...@@ -1061,7 +1032,7 @@ int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
EXPORT_SYMBOL_GPL(mhi_queue_dma); EXPORT_SYMBOL_GPL(mhi_queue_dma);
int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan, int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
void *buf, void *cb, size_t buf_len, enum mhi_flags flags) struct mhi_buf_info *info, enum mhi_flags flags)
{ {
struct mhi_ring *buf_ring, *tre_ring; struct mhi_ring *buf_ring, *tre_ring;
struct mhi_tre *mhi_tre; struct mhi_tre *mhi_tre;
...@@ -1073,15 +1044,22 @@ int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan, ...@@ -1073,15 +1044,22 @@ int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
tre_ring = &mhi_chan->tre_ring; tre_ring = &mhi_chan->tre_ring;
buf_info = buf_ring->wp; buf_info = buf_ring->wp;
buf_info->v_addr = buf; WARN_ON(buf_info->used);
buf_info->cb_buf = cb; buf_info->pre_mapped = info->pre_mapped;
if (info->pre_mapped)
buf_info->p_addr = info->p_addr;
else
buf_info->v_addr = info->v_addr;
buf_info->cb_buf = info->cb_buf;
buf_info->wp = tre_ring->wp; buf_info->wp = tre_ring->wp;
buf_info->dir = mhi_chan->dir; buf_info->dir = mhi_chan->dir;
buf_info->len = buf_len; buf_info->len = info->len;
if (!info->pre_mapped) {
ret = mhi_cntrl->map_single(mhi_cntrl, buf_info); ret = mhi_cntrl->map_single(mhi_cntrl, buf_info);
if (ret) if (ret)
return ret; return ret;
}
eob = !!(flags & MHI_EOB); eob = !!(flags & MHI_EOB);
eot = !!(flags & MHI_EOT); eot = !!(flags & MHI_EOT);
...@@ -1090,7 +1068,7 @@ int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan, ...@@ -1090,7 +1068,7 @@ int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
mhi_tre = tre_ring->wp; mhi_tre = tre_ring->wp;
mhi_tre->ptr = MHI_TRE_DATA_PTR(buf_info->p_addr); mhi_tre->ptr = MHI_TRE_DATA_PTR(buf_info->p_addr);
mhi_tre->dword[0] = MHI_TRE_DATA_DWORD0(buf_len); mhi_tre->dword[0] = MHI_TRE_DATA_DWORD0(info->len);
mhi_tre->dword[1] = MHI_TRE_DATA_DWORD1(bei, eot, eob, chain); mhi_tre->dword[1] = MHI_TRE_DATA_DWORD1(bei, eot, eob, chain);
/* increment WP */ /* increment WP */
...@@ -1107,6 +1085,7 @@ int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir, ...@@ -1107,6 +1085,7 @@ int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,
struct mhi_chan *mhi_chan = (dir == DMA_TO_DEVICE) ? mhi_dev->ul_chan : struct mhi_chan *mhi_chan = (dir == DMA_TO_DEVICE) ? mhi_dev->ul_chan :
mhi_dev->dl_chan; mhi_dev->dl_chan;
struct mhi_ring *tre_ring; struct mhi_ring *tre_ring;
struct mhi_buf_info buf_info = { };
unsigned long flags; unsigned long flags;
int ret; int ret;
...@@ -1122,7 +1101,11 @@ int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir, ...@@ -1122,7 +1101,11 @@ int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,
if (mhi_is_ring_full(mhi_cntrl, tre_ring)) if (mhi_is_ring_full(mhi_cntrl, tre_ring))
return -ENOMEM; return -ENOMEM;
ret = mhi_gen_tre(mhi_cntrl, mhi_chan, buf, buf, len, mflags); buf_info.v_addr = buf;
buf_info.cb_buf = buf;
buf_info.len = len;
ret = mhi_gen_tre(mhi_cntrl, mhi_chan, &buf_info, mflags);
if (unlikely(ret)) if (unlikely(ret))
return ret; return ret;
...@@ -1323,7 +1306,7 @@ int mhi_prepare_channel(struct mhi_controller *mhi_cntrl, ...@@ -1323,7 +1306,7 @@ int mhi_prepare_channel(struct mhi_controller *mhi_cntrl,
while (nr_el--) { while (nr_el--) {
void *buf; void *buf;
struct mhi_buf_info info = { };
buf = kmalloc(len, GFP_KERNEL); buf = kmalloc(len, GFP_KERNEL);
if (!buf) { if (!buf) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -1331,8 +1314,10 @@ int mhi_prepare_channel(struct mhi_controller *mhi_cntrl, ...@@ -1331,8 +1314,10 @@ int mhi_prepare_channel(struct mhi_controller *mhi_cntrl,
} }
/* Prepare transfer descriptors */ /* Prepare transfer descriptors */
ret = mhi_gen_tre(mhi_cntrl, mhi_chan, buf, buf, info.v_addr = buf;
len, MHI_EOT); info.cb_buf = buf;
info.len = len;
ret = mhi_gen_tre(mhi_cntrl, mhi_chan, &info, MHI_EOT);
if (ret) { if (ret) {
kfree(buf); kfree(buf);
goto error_pre_alloc; goto error_pre_alloc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment