You've already forked linux-rockchip
mirror of
https://github.com/armbian/linux-rockchip.git
synced 2026-01-06 11:08:10 -08:00
bus: mhi: core: Add support for data transfer
Add support for transferring data between external modem and host processor using MHI protocol. This is based on the patch submitted by Sujeev Dias: https://lkml.org/lkml/2018/7/9/988 Signed-off-by: Sujeev Dias <sdias@codeaurora.org> Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org> [mani: splitted the data transfer patch and cleaned up for upstream] Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Reviewed-by: Jeffrey Hugo <jhugo@codeaurora.org> Tested-by: Jeffrey Hugo <jhugo@codeaurora.org> Link: https://lore.kernel.org/r/20200220095854.4804-12-manivannan.sadhasivam@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
1d3173a3ba
commit
189ff97cca
@@ -491,6 +491,73 @@ int mhi_init_mmio(struct mhi_controller *mhi_cntrl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mhi_deinit_chan_ctxt(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_chan *mhi_chan)
|
||||
{
|
||||
struct mhi_ring *buf_ring;
|
||||
struct mhi_ring *tre_ring;
|
||||
struct mhi_chan_ctxt *chan_ctxt;
|
||||
|
||||
buf_ring = &mhi_chan->buf_ring;
|
||||
tre_ring = &mhi_chan->tre_ring;
|
||||
chan_ctxt = &mhi_cntrl->mhi_ctxt->chan_ctxt[mhi_chan->chan];
|
||||
|
||||
mhi_free_coherent(mhi_cntrl, tre_ring->alloc_size,
|
||||
tre_ring->pre_aligned, tre_ring->dma_handle);
|
||||
vfree(buf_ring->base);
|
||||
|
||||
buf_ring->base = tre_ring->base = NULL;
|
||||
chan_ctxt->rbase = 0;
|
||||
}
|
||||
|
||||
int mhi_init_chan_ctxt(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_chan *mhi_chan)
|
||||
{
|
||||
struct mhi_ring *buf_ring;
|
||||
struct mhi_ring *tre_ring;
|
||||
struct mhi_chan_ctxt *chan_ctxt;
|
||||
u32 tmp;
|
||||
int ret;
|
||||
|
||||
buf_ring = &mhi_chan->buf_ring;
|
||||
tre_ring = &mhi_chan->tre_ring;
|
||||
tre_ring->el_size = sizeof(struct mhi_tre);
|
||||
tre_ring->len = tre_ring->el_size * tre_ring->elements;
|
||||
chan_ctxt = &mhi_cntrl->mhi_ctxt->chan_ctxt[mhi_chan->chan];
|
||||
ret = mhi_alloc_aligned_ring(mhi_cntrl, tre_ring, tre_ring->len);
|
||||
if (ret)
|
||||
return -ENOMEM;
|
||||
|
||||
buf_ring->el_size = sizeof(struct mhi_buf_info);
|
||||
buf_ring->len = buf_ring->el_size * buf_ring->elements;
|
||||
buf_ring->base = vzalloc(buf_ring->len);
|
||||
|
||||
if (!buf_ring->base) {
|
||||
mhi_free_coherent(mhi_cntrl, tre_ring->alloc_size,
|
||||
tre_ring->pre_aligned, tre_ring->dma_handle);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
tmp = chan_ctxt->chcfg;
|
||||
tmp &= ~CHAN_CTX_CHSTATE_MASK;
|
||||
tmp |= (MHI_CH_STATE_ENABLED << CHAN_CTX_CHSTATE_SHIFT);
|
||||
chan_ctxt->chcfg = tmp;
|
||||
|
||||
chan_ctxt->rbase = tre_ring->iommu_base;
|
||||
chan_ctxt->rp = chan_ctxt->wp = chan_ctxt->rbase;
|
||||
chan_ctxt->rlen = tre_ring->len;
|
||||
tre_ring->ctxt_wp = &chan_ctxt->wp;
|
||||
|
||||
tre_ring->rp = tre_ring->wp = tre_ring->base;
|
||||
buf_ring->rp = buf_ring->wp = buf_ring->base;
|
||||
mhi_chan->db_cfg.db_mode = 1;
|
||||
|
||||
/* Update to all cores */
|
||||
smp_wmb();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_ev_cfg(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_controller_config *config)
|
||||
{
|
||||
@@ -799,6 +866,14 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl,
|
||||
rwlock_init(&mhi_chan->lock);
|
||||
}
|
||||
|
||||
if (mhi_cntrl->bounce_buf) {
|
||||
mhi_cntrl->map_single = mhi_map_single_use_bb;
|
||||
mhi_cntrl->unmap_single = mhi_unmap_single_use_bb;
|
||||
} else {
|
||||
mhi_cntrl->map_single = mhi_map_single_no_bb;
|
||||
mhi_cntrl->unmap_single = mhi_unmap_single_no_bb;
|
||||
}
|
||||
|
||||
/* Register controller with MHI bus */
|
||||
mhi_dev = mhi_alloc_device(mhi_cntrl);
|
||||
if (IS_ERR(mhi_dev)) {
|
||||
@@ -969,6 +1044,14 @@ static int mhi_driver_probe(struct device *dev)
|
||||
struct mhi_event *mhi_event;
|
||||
struct mhi_chan *ul_chan = mhi_dev->ul_chan;
|
||||
struct mhi_chan *dl_chan = mhi_dev->dl_chan;
|
||||
int ret;
|
||||
|
||||
/* Bring device out of LPM */
|
||||
ret = mhi_device_get_sync(mhi_dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = -EINVAL;
|
||||
|
||||
if (ul_chan) {
|
||||
/*
|
||||
@@ -976,13 +1059,18 @@ static int mhi_driver_probe(struct device *dev)
|
||||
* be provided
|
||||
*/
|
||||
if (ul_chan->lpm_notify && !mhi_drv->status_cb)
|
||||
return -EINVAL;
|
||||
goto exit_probe;
|
||||
|
||||
/* For non-offload channels then xfer_cb should be provided */
|
||||
if (!ul_chan->offload_ch && !mhi_drv->ul_xfer_cb)
|
||||
return -EINVAL;
|
||||
goto exit_probe;
|
||||
|
||||
ul_chan->xfer_cb = mhi_drv->ul_xfer_cb;
|
||||
if (ul_chan->auto_start) {
|
||||
ret = mhi_prepare_channel(mhi_cntrl, ul_chan);
|
||||
if (ret)
|
||||
goto exit_probe;
|
||||
}
|
||||
}
|
||||
|
||||
if (dl_chan) {
|
||||
@@ -991,11 +1079,11 @@ static int mhi_driver_probe(struct device *dev)
|
||||
* be provided
|
||||
*/
|
||||
if (dl_chan->lpm_notify && !mhi_drv->status_cb)
|
||||
return -EINVAL;
|
||||
goto exit_probe;
|
||||
|
||||
/* For non-offload channels then xfer_cb should be provided */
|
||||
if (!dl_chan->offload_ch && !mhi_drv->dl_xfer_cb)
|
||||
return -EINVAL;
|
||||
goto exit_probe;
|
||||
|
||||
mhi_event = &mhi_cntrl->mhi_event[dl_chan->er_index];
|
||||
|
||||
@@ -1005,19 +1093,36 @@ static int mhi_driver_probe(struct device *dev)
|
||||
* notify pending data
|
||||
*/
|
||||
if (mhi_event->cl_manage && !mhi_drv->status_cb)
|
||||
return -EINVAL;
|
||||
goto exit_probe;
|
||||
|
||||
dl_chan->xfer_cb = mhi_drv->dl_xfer_cb;
|
||||
}
|
||||
|
||||
/* Call the user provided probe function */
|
||||
return mhi_drv->probe(mhi_dev, mhi_dev->id);
|
||||
ret = mhi_drv->probe(mhi_dev, mhi_dev->id);
|
||||
if (ret)
|
||||
goto exit_probe;
|
||||
|
||||
if (dl_chan && dl_chan->auto_start)
|
||||
mhi_prepare_channel(mhi_cntrl, dl_chan);
|
||||
|
||||
mhi_device_put(mhi_dev);
|
||||
|
||||
return ret;
|
||||
|
||||
exit_probe:
|
||||
mhi_unprepare_from_transfer(mhi_dev);
|
||||
|
||||
mhi_device_put(mhi_dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mhi_driver_remove(struct device *dev)
|
||||
{
|
||||
struct mhi_device *mhi_dev = to_mhi_device(dev);
|
||||
struct mhi_driver *mhi_drv = to_mhi_driver(dev->driver);
|
||||
struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
|
||||
struct mhi_chan *mhi_chan;
|
||||
enum mhi_ch_state ch_state[] = {
|
||||
MHI_CH_STATE_DISABLED,
|
||||
@@ -1049,6 +1154,10 @@ static int mhi_driver_remove(struct device *dev)
|
||||
mhi_chan->ch_state = MHI_CH_STATE_SUSPENDED;
|
||||
write_unlock_irq(&mhi_chan->lock);
|
||||
|
||||
/* Reset the non-offload channel */
|
||||
if (!mhi_chan->offload_ch)
|
||||
mhi_reset_chan(mhi_cntrl, mhi_chan);
|
||||
|
||||
mutex_unlock(&mhi_chan->mutex);
|
||||
}
|
||||
|
||||
@@ -1063,11 +1172,20 @@ static int mhi_driver_remove(struct device *dev)
|
||||
|
||||
mutex_lock(&mhi_chan->mutex);
|
||||
|
||||
if (ch_state[dir] == MHI_CH_STATE_ENABLED &&
|
||||
!mhi_chan->offload_ch)
|
||||
mhi_deinit_chan_ctxt(mhi_cntrl, mhi_chan);
|
||||
|
||||
mhi_chan->ch_state = MHI_CH_STATE_DISABLED;
|
||||
|
||||
mutex_unlock(&mhi_chan->mutex);
|
||||
}
|
||||
|
||||
read_lock_bh(&mhi_cntrl->pm_lock);
|
||||
while (mhi_dev->dev_wake)
|
||||
mhi_device_put(mhi_dev);
|
||||
read_unlock_bh(&mhi_cntrl->pm_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -587,6 +587,8 @@ int mhi_pm_m0_transition(struct mhi_controller *mhi_cntrl);
|
||||
void mhi_pm_m1_transition(struct mhi_controller *mhi_cntrl);
|
||||
int mhi_pm_m3_transition(struct mhi_controller *mhi_cntrl);
|
||||
int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl);
|
||||
int mhi_send_cmd(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
|
||||
enum mhi_cmd_type cmd);
|
||||
|
||||
/* Register access methods */
|
||||
void mhi_db_brstmode(struct mhi_controller *mhi_cntrl, struct db_cfg *db_cfg,
|
||||
@@ -618,6 +620,14 @@ int mhi_init_irq_setup(struct mhi_controller *mhi_cntrl);
|
||||
void mhi_deinit_free_irq(struct mhi_controller *mhi_cntrl);
|
||||
void mhi_rddm_prepare(struct mhi_controller *mhi_cntrl,
|
||||
struct image_info *img_info);
|
||||
int mhi_prepare_channel(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_chan *mhi_chan);
|
||||
int mhi_init_chan_ctxt(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_chan *mhi_chan);
|
||||
void mhi_deinit_chan_ctxt(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_chan *mhi_chan);
|
||||
void mhi_reset_chan(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_chan *mhi_chan);
|
||||
|
||||
/* Memory allocation methods */
|
||||
static inline void *mhi_alloc_coherent(struct mhi_controller *mhi_cntrl,
|
||||
@@ -652,4 +662,16 @@ irqreturn_t mhi_irq_handler(int irq_number, void *dev);
|
||||
irqreturn_t mhi_intvec_threaded_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,
|
||||
void *buf, void *cb, size_t buf_len, enum mhi_flags flags);
|
||||
|
||||
int mhi_map_single_no_bb(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_buf_info *buf_info);
|
||||
int mhi_map_single_use_bb(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_buf_info *buf_info);
|
||||
void mhi_unmap_single_no_bb(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_buf_info *buf_info);
|
||||
void mhi_unmap_single_use_bb(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_buf_info *buf_info);
|
||||
|
||||
#endif /* _MHI_INT_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -927,3 +927,43 @@ int mhi_force_rddm_mode(struct mhi_controller *mhi_cntrl)
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mhi_force_rddm_mode);
|
||||
|
||||
void mhi_device_get(struct mhi_device *mhi_dev)
|
||||
{
|
||||
struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
|
||||
|
||||
mhi_dev->dev_wake++;
|
||||
read_lock_bh(&mhi_cntrl->pm_lock);
|
||||
mhi_cntrl->wake_get(mhi_cntrl, true);
|
||||
read_unlock_bh(&mhi_cntrl->pm_lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mhi_device_get);
|
||||
|
||||
int mhi_device_get_sync(struct mhi_device *mhi_dev)
|
||||
{
|
||||
struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
|
||||
int ret;
|
||||
|
||||
ret = __mhi_device_get_sync(mhi_cntrl);
|
||||
if (!ret)
|
||||
mhi_dev->dev_wake++;
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mhi_device_get_sync);
|
||||
|
||||
void mhi_device_put(struct mhi_device *mhi_dev)
|
||||
{
|
||||
struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
|
||||
|
||||
mhi_dev->dev_wake--;
|
||||
read_lock_bh(&mhi_cntrl->pm_lock);
|
||||
if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
|
||||
mhi_cntrl->runtime_get(mhi_cntrl);
|
||||
mhi_cntrl->runtime_put(mhi_cntrl);
|
||||
}
|
||||
|
||||
mhi_cntrl->wake_put(mhi_cntrl, false);
|
||||
read_unlock_bh(&mhi_cntrl->pm_lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mhi_device_put);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <linux/dma-direction.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/rwlock_types.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/spinlock_types.h>
|
||||
#include <linux/wait.h>
|
||||
@@ -336,6 +337,8 @@ struct mhi_controller_config {
|
||||
* @wake_toggle: CB function to assert and de-assert device wake (optional)
|
||||
* @runtime_get: CB function to controller runtime resume (required)
|
||||
* @runtimet_put: CB function to decrement pm usage (required)
|
||||
* @map_single: CB function to create TRE buffer
|
||||
* @unmap_single: CB function to destroy TRE buffer
|
||||
* @buffer_len: Bounce buffer length
|
||||
* @bounce_buf: Use of bounce buffer
|
||||
* @fbc_download: MHI host needs to do complete image transfer (optional)
|
||||
@@ -403,6 +406,10 @@ struct mhi_controller {
|
||||
void (*wake_toggle)(struct mhi_controller *mhi_cntrl);
|
||||
int (*runtime_get)(struct mhi_controller *mhi_cntrl);
|
||||
void (*runtime_put)(struct mhi_controller *mhi_cntrl);
|
||||
int (*map_single)(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_buf_info *buf);
|
||||
void (*unmap_single)(struct mhi_controller *mhi_cntrl,
|
||||
struct mhi_buf_info *buf);
|
||||
|
||||
size_t buffer_len;
|
||||
bool bounce_buf;
|
||||
@@ -583,4 +590,77 @@ int mhi_force_rddm_mode(struct mhi_controller *mhi_cntrl);
|
||||
*/
|
||||
enum mhi_state mhi_get_mhi_state(struct mhi_controller *mhi_cntrl);
|
||||
|
||||
/**
|
||||
* mhi_device_get - Disable device low power mode
|
||||
* @mhi_dev: Device associated with the channel
|
||||
*/
|
||||
void mhi_device_get(struct mhi_device *mhi_dev);
|
||||
|
||||
/**
|
||||
* mhi_device_get_sync - Disable device low power mode. Synchronously
|
||||
* take the controller out of suspended state
|
||||
* @mhi_dev: Device associated with the channel
|
||||
*/
|
||||
int mhi_device_get_sync(struct mhi_device *mhi_dev);
|
||||
|
||||
/**
|
||||
* mhi_device_put - Re-enable device low power mode
|
||||
* @mhi_dev: Device associated with the channel
|
||||
*/
|
||||
void mhi_device_put(struct mhi_device *mhi_dev);
|
||||
|
||||
/**
|
||||
* mhi_prepare_for_transfer - Setup channel for data transfer
|
||||
* @mhi_dev: Device associated with the channels
|
||||
*/
|
||||
int mhi_prepare_for_transfer(struct mhi_device *mhi_dev);
|
||||
|
||||
/**
|
||||
* mhi_unprepare_from_transfer - Unprepare the channels
|
||||
* @mhi_dev: Device associated with the channels
|
||||
*/
|
||||
void mhi_unprepare_from_transfer(struct mhi_device *mhi_dev);
|
||||
|
||||
/**
|
||||
* mhi_poll - Poll for any available data in DL direction
|
||||
* @mhi_dev: Device associated with the channels
|
||||
* @budget: # of events to process
|
||||
*/
|
||||
int mhi_poll(struct mhi_device *mhi_dev, u32 budget);
|
||||
|
||||
/**
|
||||
* mhi_queue_dma - Send or receive DMA mapped buffers from client device
|
||||
* over MHI channel
|
||||
* @mhi_dev: Device associated with the channels
|
||||
* @dir: DMA direction for the channel
|
||||
* @mhi_buf: Buffer for holding the DMA mapped data
|
||||
* @len: Buffer length
|
||||
* @mflags: MHI transfer flags used for the transfer
|
||||
*/
|
||||
int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
|
||||
struct mhi_buf *mhi_buf, size_t len, enum mhi_flags mflags);
|
||||
|
||||
/**
|
||||
* mhi_queue_buf - Send or receive raw buffers from client device over MHI
|
||||
* channel
|
||||
* @mhi_dev: Device associated with the channels
|
||||
* @dir: DMA direction for the channel
|
||||
* @buf: Buffer for holding the data
|
||||
* @len: Buffer length
|
||||
* @mflags: MHI transfer flags used for the transfer
|
||||
*/
|
||||
int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,
|
||||
void *buf, size_t len, enum mhi_flags mflags);
|
||||
|
||||
/**
|
||||
* mhi_queue_skb - Send or receive SKBs from client device over MHI channel
|
||||
* @mhi_dev: Device associated with the channels
|
||||
* @dir: DMA direction for the channel
|
||||
* @skb: Buffer for holding SKBs
|
||||
* @len: Buffer length
|
||||
* @mflags: MHI transfer flags used for the transfer
|
||||
*/
|
||||
int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
|
||||
struct sk_buff *skb, size_t len, enum mhi_flags mflags);
|
||||
|
||||
#endif /* _MHI_H_ */
|
||||
|
||||
Reference in New Issue
Block a user