History

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

Manivannan Sadhasivam committed 6 years ago

Commit 189ff971 parent 1d3173a5 files · +979 −8Browse files

Unified · Split

5 files
  1. drivers/bus/mhi/core/init.c +124 −6
  2. drivers/bus/mhi/core/internal.h +22 −0
  3. drivers/bus/mhi/core/main.c +713 −2
  4. drivers/bus/mhi/core/pm.c +40 −0
  5. include/linux/mhi.h +80 −0
drivers/bus/mhi/core/init.c+124−6
@@ -491,6 +491,73 @@ int mhi_init_mmio(struct mhi_controller *mhi_cntrl) · 490 unmodified lines
491491 return 0;
492492 }
493493
494+void mhi_deinit_chan_ctxt(struct mhi_controller *mhi_cntrl,
495+ struct mhi_chan *mhi_chan)
496+{
497+ struct mhi_ring *buf_ring;
498+ struct mhi_ring *tre_ring;
499+ struct mhi_chan_ctxt *chan_ctxt;
500+
501+ buf_ring = &mhi_chan->buf_ring;
502+ tre_ring = &mhi_chan->tre_ring;
503+ chan_ctxt = &mhi_cntrl->mhi_ctxt->chan_ctxt[mhi_chan->chan];
504+
505+ mhi_free_coherent(mhi_cntrl, tre_ring->alloc_size,
506+ tre_ring->pre_aligned, tre_ring->dma_handle);
507+ vfree(buf_ring->base);
508+
509+ buf_ring->base = tre_ring->base = NULL;
510+ chan_ctxt->rbase = 0;
511+}
512+
513+int mhi_init_chan_ctxt(struct mhi_controller *mhi_cntrl,
514+ struct mhi_chan *mhi_chan)
515+{
516+ struct mhi_ring *buf_ring;
517+ struct mhi_ring *tre_ring;
518+ struct mhi_chan_ctxt *chan_ctxt;
519+ u32 tmp;
520+ int ret;
521+
522+ buf_ring = &mhi_chan->buf_ring;
523+ tre_ring = &mhi_chan->tre_ring;
524+ tre_ring->el_size = sizeof(struct mhi_tre);
525+ tre_ring->len = tre_ring->el_size * tre_ring->elements;
526+ chan_ctxt = &mhi_cntrl->mhi_ctxt->chan_ctxt[mhi_chan->chan];
527+ ret = mhi_alloc_aligned_ring(mhi_cntrl, tre_ring, tre_ring->len);
528+ if (ret)
529+ return -ENOMEM;
530+
531+ buf_ring->el_size = sizeof(struct mhi_buf_info);
532+ buf_ring->len = buf_ring->el_size * buf_ring->elements;
533+ buf_ring->base = vzalloc(buf_ring->len);
534+
535+ if (!buf_ring->base) {
536+ mhi_free_coherent(mhi_cntrl, tre_ring->alloc_size,
537+ tre_ring->pre_aligned, tre_ring->dma_handle);
538+ return -ENOMEM;
539+ }
540+
541+ tmp = chan_ctxt->chcfg;
542+ tmp &= ~CHAN_CTX_CHSTATE_MASK;
543+ tmp |= (MHI_CH_STATE_ENABLED << CHAN_CTX_CHSTATE_SHIFT);
544+ chan_ctxt->chcfg = tmp;
545+
546+ chan_ctxt->rbase = tre_ring->iommu_base;
547+ chan_ctxt->rp = chan_ctxt->wp = chan_ctxt->rbase;
548+ chan_ctxt->rlen = tre_ring->len;
549+ tre_ring->ctxt_wp = &chan_ctxt->wp;
550+
551+ tre_ring->rp = tre_ring->wp = tre_ring->base;
552+ buf_ring->rp = buf_ring->wp = buf_ring->base;
553+ mhi_chan->db_cfg.db_mode = 1;
554+
555+ /* Update to all cores */
556+ smp_wmb();
557+
558+ return 0;
559+}
560+
494561 static int parse_ev_cfg(struct mhi_controller *mhi_cntrl,
495562 struct mhi_controller_config *config)
496563 {
@@ -799,6 +866,14 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl, · 302 unmodified lines
799866 rwlock_init(&mhi_chan->lock);
800867 }
801868
869+ if (mhi_cntrl->bounce_buf) {
870+ mhi_cntrl->map_single = mhi_map_single_use_bb;
871+ mhi_cntrl->unmap_single = mhi_unmap_single_use_bb;
872+ } else {
873+ mhi_cntrl->map_single = mhi_map_single_no_bb;
874+ mhi_cntrl->unmap_single = mhi_unmap_single_no_bb;
875+ }
876+
802877 /* Register controller with MHI bus */
803878 mhi_dev = mhi_alloc_device(mhi_cntrl);
804879 if (IS_ERR(mhi_dev)) {
@@ -969,6 +1044,14 @@ static int mhi_driver_probe(struct device *dev) · 164 unmodified lines
9691044 struct mhi_event *mhi_event;
9701045 struct mhi_chan *ul_chan = mhi_dev->ul_chan;
9711046 struct mhi_chan *dl_chan = mhi_dev->dl_chan;
1047+ int ret;
1048+
1049+ /* Bring device out of LPM */
1050+ ret = mhi_device_get_sync(mhi_dev);
1051+ if (ret)
1052+ return ret;
1053+
1054+ ret = -EINVAL;
9721055
9731056 if (ul_chan) {
9741057 /*
@@ -976,13 +1059,18 @@ static int mhi_driver_probe(struct device *dev) · 1 unmodified line
9761059 * be provided
9771060 */
9781061 if (ul_chan->lpm_notify && !mhi_drv->status_cb)
979− return -EINVAL;
1062+ goto exit_probe;
9801063
9811064 /* For non-offload channels then xfer_cb should be provided */
9821065 if (!ul_chan->offload_ch && !mhi_drv->ul_xfer_cb)
983− return -EINVAL;
1066+ goto exit_probe;
9841067
9851068 ul_chan->xfer_cb = mhi_drv->ul_xfer_cb;
1069+ if (ul_chan->auto_start) {
1070+ ret = mhi_prepare_channel(mhi_cntrl, ul_chan);
1071+ if (ret)
1072+ goto exit_probe;
1073+ }
9861074 }
9871075
9881076 if (dl_chan) {
@@ -991,11 +1079,11 @@ static int mhi_driver_probe(struct device *dev) · 2 unmodified lines
9911079 * be provided
9921080 */
9931081 if (dl_chan->lpm_notify && !mhi_drv->status_cb)
994− return -EINVAL;
1082+ goto exit_probe;
9951083
9961084 /* For non-offload channels then xfer_cb should be provided */
9971085 if (!dl_chan->offload_ch && !mhi_drv->dl_xfer_cb)
998− return -EINVAL;
1086+ goto exit_probe;
9991087
10001088 mhi_event = &mhi_cntrl->mhi_event[dl_chan->er_index];
10011089
@@ -1005,19 +1093,36 @@ static int mhi_driver_probe(struct device *dev) · 3 unmodified lines
10051093 * notify pending data
10061094 */
10071095 if (mhi_event->cl_manage && !mhi_drv->status_cb)
1008− return -EINVAL;
1096+ goto exit_probe;
10091097
10101098 dl_chan->xfer_cb = mhi_drv->dl_xfer_cb;
10111099 }
10121100
10131101 /* Call the user provided probe function */
1014− return mhi_drv->probe(mhi_dev, mhi_dev->id);
1102+ ret = mhi_drv->probe(mhi_dev, mhi_dev->id);
1103+ if (ret)
1104+ goto exit_probe;
1105+
1106+ if (dl_chan && dl_chan->auto_start)
1107+ mhi_prepare_channel(mhi_cntrl, dl_chan);
1108+
1109+ mhi_device_put(mhi_dev);
1110+
1111+ return ret;
1112+
1113+exit_probe:
1114+ mhi_unprepare_from_transfer(mhi_dev);
1115+
1116+ mhi_device_put(mhi_dev);
1117+
1118+ return ret;
10151119 }
10161120
10171121 static int mhi_driver_remove(struct device *dev)
10181122 {
10191123 struct mhi_device *mhi_dev = to_mhi_device(dev);
10201124 struct mhi_driver *mhi_drv = to_mhi_driver(dev->driver);
1125+ struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
10211126 struct mhi_chan *mhi_chan;
10221127 enum mhi_ch_state ch_state[] = {
10231128 MHI_CH_STATE_DISABLED,
@@ -1049,6 +1154,10 @@ static int mhi_driver_remove(struct device *dev) · 25 unmodified lines
10491154 mhi_chan->ch_state = MHI_CH_STATE_SUSPENDED;
10501155 write_unlock_irq(&mhi_chan->lock);
10511156
1157+ /* Reset the non-offload channel */
1158+ if (!mhi_chan->offload_ch)
1159+ mhi_reset_chan(mhi_cntrl, mhi_chan);
1160+
10521161 mutex_unlock(&mhi_chan->mutex);
10531162 }
10541163
@@ -1063,11 +1172,20 @@ static int mhi_driver_remove(struct device *dev) · 8 unmodified lines
10631172
10641173 mutex_lock(&mhi_chan->mutex);
10651174
1175+ if (ch_state[dir] == MHI_CH_STATE_ENABLED &&
1176+ !mhi_chan->offload_ch)
1177+ mhi_deinit_chan_ctxt(mhi_cntrl, mhi_chan);
1178+
10661179 mhi_chan->ch_state = MHI_CH_STATE_DISABLED;
10671180
10681181 mutex_unlock(&mhi_chan->mutex);
10691182 }
10701183
1184+ read_lock_bh(&mhi_cntrl->pm_lock);
1185+ while (mhi_dev->dev_wake)
1186+ mhi_device_put(mhi_dev);
1187+ read_unlock_bh(&mhi_cntrl->pm_lock);
1188+
10711189 return 0;
10721190 }
10731191
drivers/bus/mhi/core/internal.h+22−0
@@ -587,6 +587,8 @@ int mhi_pm_m0_transition(struct mhi_controller *mhi_cntrl); · 586 unmodified lines
587587 void mhi_pm_m1_transition(struct mhi_controller *mhi_cntrl);
588588 int mhi_pm_m3_transition(struct mhi_controller *mhi_cntrl);
589589 int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl);
590+int mhi_send_cmd(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
591+ enum mhi_cmd_type cmd);
590592
591593 /* Register access methods */
592594 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); · 25 unmodified lines
618620 void mhi_deinit_free_irq(struct mhi_controller *mhi_cntrl);
619621 void mhi_rddm_prepare(struct mhi_controller *mhi_cntrl,
620622 struct image_info *img_info);
623+int mhi_prepare_channel(struct mhi_controller *mhi_cntrl,
624+ struct mhi_chan *mhi_chan);
625+int mhi_init_chan_ctxt(struct mhi_controller *mhi_cntrl,
626+ struct mhi_chan *mhi_chan);
627+void mhi_deinit_chan_ctxt(struct mhi_controller *mhi_cntrl,
628+ struct mhi_chan *mhi_chan);
629+void mhi_reset_chan(struct mhi_controller *mhi_cntrl,
630+ struct mhi_chan *mhi_chan);
621631
622632 /* Memory allocation methods */
623633 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); · 28 unmodified lines
652662 irqreturn_t mhi_intvec_threaded_handler(int irq_number, void *dev);
653663 irqreturn_t mhi_intvec_handler(int irq_number, void *dev);
654664
665+int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
666+ void *buf, void *cb, size_t buf_len, enum mhi_flags flags);
667+
668+int mhi_map_single_no_bb(struct mhi_controller *mhi_cntrl,
669+ struct mhi_buf_info *buf_info);
670+int mhi_map_single_use_bb(struct mhi_controller *mhi_cntrl,
671+ struct mhi_buf_info *buf_info);
672+void mhi_unmap_single_no_bb(struct mhi_controller *mhi_cntrl,
673+ struct mhi_buf_info *buf_info);
674+void mhi_unmap_single_use_bb(struct mhi_controller *mhi_cntrl,
675+ struct mhi_buf_info *buf_info);
676+
655677 #endif /* _MHI_INT_H */
drivers/bus/mhi/core/main.c+713−2
@@ -142,11 +142,83 @@ enum mhi_state mhi_get_mhi_state(struct mhi_controller *mhi_cntrl) · 141 unmodified lines
142142 return ret ? MHI_STATE_MAX : state;
143143 }
144144
145+int mhi_map_single_no_bb(struct mhi_controller *mhi_cntrl,
146+ struct mhi_buf_info *buf_info)
147+{
148+ buf_info->p_addr = dma_map_single(mhi_cntrl->cntrl_dev,
149+ buf_info->v_addr, buf_info->len,
150+ buf_info->dir);
151+ if (dma_mapping_error(mhi_cntrl->cntrl_dev, buf_info->p_addr))
152+ return -ENOMEM;
153+
154+ return 0;
155+}
156+
157+int mhi_map_single_use_bb(struct mhi_controller *mhi_cntrl,
158+ struct mhi_buf_info *buf_info)
159+{
160+ void *buf = mhi_alloc_coherent(mhi_cntrl, buf_info->len,
161+ &buf_info->p_addr, GFP_ATOMIC);
162+
163+ if (!buf)
164+ return -ENOMEM;
165+
166+ if (buf_info->dir == DMA_TO_DEVICE)
167+ memcpy(buf, buf_info->v_addr, buf_info->len);
168+
169+ buf_info->bb_addr = buf;
170+
171+ return 0;
172+}
173+
174+void mhi_unmap_single_no_bb(struct mhi_controller *mhi_cntrl,
175+ struct mhi_buf_info *buf_info)
176+{
177+ dma_unmap_single(mhi_cntrl->cntrl_dev, buf_info->p_addr, buf_info->len,
178+ buf_info->dir);
179+}
180+
181+void mhi_unmap_single_use_bb(struct mhi_controller *mhi_cntrl,
182+ struct mhi_buf_info *buf_info)
183+{
184+ if (buf_info->dir == DMA_FROM_DEVICE)
185+ memcpy(buf_info->v_addr, buf_info->bb_addr, buf_info->len);
186+
187+ mhi_free_coherent(mhi_cntrl, buf_info->len, buf_info->bb_addr,
188+ buf_info->p_addr);
189+}
190+
191+static int get_nr_avail_ring_elements(struct mhi_controller *mhi_cntrl,
192+ struct mhi_ring *ring)
193+{
194+ int nr_el;
195+
196+ if (ring->wp < ring->rp) {
197+ nr_el = ((ring->rp - ring->wp) / ring->el_size) - 1;
198+ } else {
199+ nr_el = (ring->rp - ring->base) / ring->el_size;
200+ nr_el += ((ring->base + ring->len - ring->wp) /
201+ ring->el_size) - 1;
202+ }
203+
204+ return nr_el;
205+}
206+
145207 static void *mhi_to_virtual(struct mhi_ring *ring, dma_addr_t addr)
146208 {
147209 return (addr - ring->iommu_base) + ring->base;
148210 }
149211
212+static void mhi_add_ring_element(struct mhi_controller *mhi_cntrl,
213+ struct mhi_ring *ring)
214+{
215+ ring->wp += ring->el_size;
216+ if (ring->wp >= (ring->base + ring->len))
217+ ring->wp = ring->base;
218+ /* smp update */
219+ smp_wmb();
220+}
221+
150222 static void mhi_del_ring_element(struct mhi_controller *mhi_cntrl,
151223 struct mhi_ring *ring)
152224 {
@@ -416,14 +488,12 @@ static int parse_xfer_event(struct mhi_controller *mhi_cntrl, · 263 unmodified lines
416488 /* Get the TRB this event points to */
417489 ev_tre = mhi_to_virtual(tre_ring, ptr);
418490
419− /* device rp after servicing the TREs */
420491 dev_rp = ev_tre + 1;
421492 if (dev_rp >= (tre_ring->base + tre_ring->len))
422493 dev_rp = tre_ring->base;
423494
424495 result.dir = mhi_chan->dir;
425496
426− /* local rp */
427497 local_rp = tre_ring->rp;
428498 while (local_rp != dev_rp) {
429499 buf_info = buf_ring->rp;
@@ -433,6 +503,10 @@ static int parse_xfer_event(struct mhi_controller *mhi_cntrl, · 3 unmodified lines
433503 else
434504 xfer_len = buf_info->len;
435505
506+ /* Unmap if it's not pre-mapped by client */
507+ if (likely(!buf_info->pre_mapped))
508+ mhi_cntrl->unmap_single(mhi_cntrl, buf_info);
509+
436510 result.buf_addr = buf_info->cb_buf;
437511 result.bytes_xferd = xfer_len;
438512 mhi_del_ring_element(mhi_cntrl, buf_ring);
@@ -444,6 +518,23 @@ static int parse_xfer_event(struct mhi_controller *mhi_cntrl, · 5 unmodified lines
444518
445519 if (mhi_chan->dir == DMA_TO_DEVICE)
446520 atomic_dec(&mhi_cntrl->pending_pkts);
521+
522+ /*
523+ * Recycle the buffer if buffer is pre-allocated,
524+ * if there is an error, not much we can do apart
525+ * from dropping the packet
526+ */
527+ if (mhi_chan->pre_alloc) {
528+ if (mhi_queue_buf(mhi_chan->mhi_dev,
529+ mhi_chan->dir,
530+ buf_info->cb_buf,
531+ buf_info->len, MHI_EOT)) {
532+ dev_err(dev,
533+ "Error recycling buffer for chan:%d\n",
534+ mhi_chan->chan);
535+ kfree(buf_info->cb_buf);
536+ }
537+ }
447538 }
448539 break;
449540 } /* CC_EOT */
@@ -803,3 +894,623 @@ void mhi_ctrl_ev_task(unsigned long data) · 353 unmodified lines
803894 schedule_work(&mhi_cntrl->syserr_worker);
804895 }
805896 }
897+
898+static bool mhi_is_ring_full(struct mhi_controller *mhi_cntrl,
899+ struct mhi_ring *ring)
900+{
901+ void *tmp = ring->wp + ring->el_size;
902+
903+ if (tmp >= (ring->base + ring->len))
904+ tmp = ring->base;
905+
906+ return (tmp == ring->rp);
907+}
908+
909+int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
910+ struct sk_buff *skb, size_t len, enum mhi_flags mflags)
911+{
912+ struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
913+ struct mhi_chan *mhi_chan = (dir == DMA_TO_DEVICE) ? mhi_dev->ul_chan :
914+ mhi_dev->dl_chan;
915+ struct mhi_ring *tre_ring = &mhi_chan->tre_ring;
916+ struct mhi_ring *buf_ring = &mhi_chan->buf_ring;
917+ struct mhi_buf_info *buf_info;
918+ struct mhi_tre *mhi_tre;
919+ int ret;
920+
921+ /* If MHI host pre-allocates buffers then client drivers cannot queue */
922+ if (mhi_chan->pre_alloc)
923+ return -EINVAL;
924+
925+ if (mhi_is_ring_full(mhi_cntrl, tre_ring))
926+ return -ENOMEM;
927+
928+ read_lock_bh(&mhi_cntrl->pm_lock);
929+ if (unlikely(MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state))) {
930+ read_unlock_bh(&mhi_cntrl->pm_lock);
931+ return -EIO;
932+ }
933+
934+ /* we're in M3 or transitioning to M3 */
935+ if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
936+ mhi_cntrl->runtime_get(mhi_cntrl);
937+ mhi_cntrl->runtime_put(mhi_cntrl);
938+ }
939+
940+ /* Toggle wake to exit out of M2 */
941+ mhi_cntrl->wake_toggle(mhi_cntrl);
942+
943+ /* Generate the TRE */
944+ buf_info = buf_ring->wp;
945+
946+ buf_info->v_addr = skb->data;
947+ buf_info->cb_buf = skb;
948+ buf_info->wp = tre_ring->wp;
949+ buf_info->dir = mhi_chan->dir;
950+ buf_info->len = len;
951+ ret = mhi_cntrl->map_single(mhi_cntrl, buf_info);
952+ if (ret)
953+ goto map_error;
954+
955+ mhi_tre = tre_ring->wp;
956+
957+ mhi_tre->ptr = MHI_TRE_DATA_PTR(buf_info->p_addr);
958+ mhi_tre->dword[0] = MHI_TRE_DATA_DWORD0(buf_info->len);
959+ mhi_tre->dword[1] = MHI_TRE_DATA_DWORD1(1, 1, 0, 0);
960+
961+ /* increment WP */
962+ mhi_add_ring_element(mhi_cntrl, tre_ring);
963+ mhi_add_ring_element(mhi_cntrl, buf_ring);
964+
965+ if (mhi_chan->dir == DMA_TO_DEVICE)
966+ atomic_inc(&mhi_cntrl->pending_pkts);
967+
968+ if (likely(MHI_DB_ACCESS_VALID(mhi_cntrl))) {
969+ read_lock_bh(&mhi_chan->lock);
970+ mhi_ring_chan_db(mhi_cntrl, mhi_chan);
971+ read_unlock_bh(&mhi_chan->lock);
972+ }
973+
974+ read_unlock_bh(&mhi_cntrl->pm_lock);
975+
976+ return 0;
977+
978+map_error:
979+ read_unlock_bh(&mhi_cntrl->pm_lock);
980+
981+ return ret;
982+}
983+EXPORT_SYMBOL_GPL(mhi_queue_skb);
984+
985+int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
986+ struct mhi_buf *mhi_buf, size_t len, enum mhi_flags mflags)
987+{
988+ struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
989+ struct mhi_chan *mhi_chan = (dir == DMA_TO_DEVICE) ? mhi_dev->ul_chan :
990+ mhi_dev->dl_chan;
991+ struct device *dev = &mhi_cntrl->mhi_dev->dev;
992+ struct mhi_ring *tre_ring = &mhi_chan->tre_ring;
993+ struct mhi_ring *buf_ring = &mhi_chan->buf_ring;
994+ struct mhi_buf_info *buf_info;
995+ struct mhi_tre *mhi_tre;
996+
997+ /* If MHI host pre-allocates buffers then client drivers cannot queue */
998+ if (mhi_chan->pre_alloc)
999+ return -EINVAL;
1000+
1001+ if (mhi_is_ring_full(mhi_cntrl, tre_ring))
1002+ return -ENOMEM;
1003+
1004+ read_lock_bh(&mhi_cntrl->pm_lock);
1005+ if (unlikely(MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state))) {
1006+ dev_err(dev, "MHI is not in activate state, PM state: %s\n",
1007+ to_mhi_pm_state_str(mhi_cntrl->pm_state));
1008+ read_unlock_bh(&mhi_cntrl->pm_lock);
1009+
1010+ return -EIO;
1011+ }
1012+
1013+ /* we're in M3 or transitioning to M3 */
1014+ if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
1015+ mhi_cntrl->runtime_get(mhi_cntrl);
1016+ mhi_cntrl->runtime_put(mhi_cntrl);
1017+ }
1018+
1019+ /* Toggle wake to exit out of M2 */
1020+ mhi_cntrl->wake_toggle(mhi_cntrl);
1021+
1022+ /* Generate the TRE */
1023+ buf_info = buf_ring->wp;
1024+ WARN_ON(buf_info->used);
1025+ buf_info->p_addr = mhi_buf->dma_addr;
1026+ buf_info->pre_mapped = true;
1027+ buf_info->cb_buf = mhi_buf;
1028+ buf_info->wp = tre_ring->wp;
1029+ buf_info->dir = mhi_chan->dir;
1030+ buf_info->len = len;
1031+
1032+ mhi_tre = tre_ring->wp;
1033+
1034+ mhi_tre->ptr = MHI_TRE_DATA_PTR(buf_info->p_addr);
1035+ mhi_tre->dword[0] = MHI_TRE_DATA_DWORD0(buf_info->len);
1036+ mhi_tre->dword[1] = MHI_TRE_DATA_DWORD1(1, 1, 0, 0);
1037+
1038+ /* increment WP */
1039+ mhi_add_ring_element(mhi_cntrl, tre_ring);
1040+ mhi_add_ring_element(mhi_cntrl, buf_ring);
1041+
1042+ if (mhi_chan->dir == DMA_TO_DEVICE)
1043+ atomic_inc(&mhi_cntrl->pending_pkts);
1044+
1045+ if (likely(MHI_DB_ACCESS_VALID(mhi_cntrl))) {
1046+ read_lock_bh(&mhi_chan->lock);
1047+ mhi_ring_chan_db(mhi_cntrl, mhi_chan);
1048+ read_unlock_bh(&mhi_chan->lock);
1049+ }
1050+
1051+ read_unlock_bh(&mhi_cntrl->pm_lock);
1052+
1053+ return 0;
1054+}
1055+EXPORT_SYMBOL_GPL(mhi_queue_dma);
1056+
1057+int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan,
1058+ void *buf, void *cb, size_t buf_len, enum mhi_flags flags)
1059+{
1060+ struct mhi_ring *buf_ring, *tre_ring;
1061+ struct mhi_tre *mhi_tre;
1062+ struct mhi_buf_info *buf_info;
1063+ int eot, eob, chain, bei;
1064+ int ret;
1065+
1066+ buf_ring = &mhi_chan->buf_ring;
1067+ tre_ring = &mhi_chan->tre_ring;
1068+
1069+ buf_info = buf_ring->wp;
1070+ buf_info->v_addr = buf;
1071+ buf_info->cb_buf = cb;
1072+ buf_info->wp = tre_ring->wp;
1073+ buf_info->dir = mhi_chan->dir;
1074+ buf_info->len = buf_len;
1075+
1076+ ret = mhi_cntrl->map_single(mhi_cntrl, buf_info);
1077+ if (ret)
1078+ return ret;
1079+
1080+ eob = !!(flags & MHI_EOB);
1081+ eot = !!(flags & MHI_EOT);
1082+ chain = !!(flags & MHI_CHAIN);
1083+ bei = !!(mhi_chan->intmod);
1084+
1085+ mhi_tre = tre_ring->wp;
1086+ mhi_tre->ptr = MHI_TRE_DATA_PTR(buf_info->p_addr);
1087+ mhi_tre->dword[0] = MHI_TRE_DATA_DWORD0(buf_len);
1088+ mhi_tre->dword[1] = MHI_TRE_DATA_DWORD1(bei, eot, eob, chain);
1089+
1090+ /* increment WP */
1091+ mhi_add_ring_element(mhi_cntrl, tre_ring);
1092+ mhi_add_ring_element(mhi_cntrl, buf_ring);
1093+
1094+ return 0;
1095+}
1096+
1097+int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,
1098+ void *buf, size_t len, enum mhi_flags mflags)
1099+{
1100+ struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
1101+ struct mhi_chan *mhi_chan = (dir == DMA_TO_DEVICE) ? mhi_dev->ul_chan :
1102+ mhi_dev->dl_chan;
1103+ struct mhi_ring *tre_ring;
1104+ unsigned long flags;
1105+ int ret;
1106+
1107+ /*
1108+ * this check here only as a guard, it's always
1109+ * possible mhi can enter error while executing rest of function,
1110+ * which is not fatal so we do not need to hold pm_lock
1111+ */
1112+ if (unlikely(MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)))
1113+ return -EIO;
1114+
1115+ tre_ring = &mhi_chan->tre_ring;
1116+ if (mhi_is_ring_full(mhi_cntrl, tre_ring))
1117+ return -ENOMEM;
1118+
1119+ ret = mhi_gen_tre(mhi_cntrl, mhi_chan, buf, buf, len, mflags);
1120+ if (unlikely(ret))
1121+ return ret;
1122+
1123+ read_lock_irqsave(&mhi_cntrl->pm_lock, flags);
1124+
1125+ /* we're in M3 or transitioning to M3 */
1126+ if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
1127+ mhi_cntrl->runtime_get(mhi_cntrl);
1128+ mhi_cntrl->runtime_put(mhi_cntrl);
1129+ }
1130+
1131+ /* Toggle wake to exit out of M2 */
1132+ mhi_cntrl->wake_toggle(mhi_cntrl);
1133+
1134+ if (mhi_chan->dir == DMA_TO_DEVICE)
1135+ atomic_inc(&mhi_cntrl->pending_pkts);
1136+
1137+ if (likely(MHI_DB_ACCESS_VALID(mhi_cntrl))) {
1138+ unsigned long flags;
1139+
1140+ read_lock_irqsave(&mhi_chan->lock, flags);
1141+ mhi_ring_chan_db(mhi_cntrl, mhi_chan);
1142+ read_unlock_irqrestore(&mhi_chan->lock, flags);
1143+ }
1144+
1145+ read_unlock_irqrestore(&mhi_cntrl->pm_lock, flags);
1146+
1147+ return 0;
1148+}
1149+EXPORT_SYMBOL_GPL(mhi_queue_buf);
1150+
1151+int mhi_send_cmd(struct mhi_controller *mhi_cntrl,
1152+ struct mhi_chan *mhi_chan,
1153+ enum mhi_cmd_type cmd)
1154+{
1155+ struct mhi_tre *cmd_tre = NULL;
1156+ struct mhi_cmd *mhi_cmd = &mhi_cntrl->mhi_cmd[PRIMARY_CMD_RING];
1157+ struct mhi_ring *ring = &mhi_cmd->ring;
1158+ struct device *dev = &mhi_cntrl->mhi_dev->dev;
1159+ int chan = 0;
1160+
1161+ if (mhi_chan)
1162+ chan = mhi_chan->chan;
1163+
1164+ spin_lock_bh(&mhi_cmd->lock);
1165+ if (!get_nr_avail_ring_elements(mhi_cntrl, ring)) {
1166+ spin_unlock_bh(&mhi_cmd->lock);
1167+ return -ENOMEM;
1168+ }
1169+
1170+ /* prepare the cmd tre */
1171+ cmd_tre = ring->wp;
1172+ switch (cmd) {
1173+ case MHI_CMD_RESET_CHAN:
1174+ cmd_tre->ptr = MHI_TRE_CMD_RESET_PTR;
1175+ cmd_tre->dword[0] = MHI_TRE_CMD_RESET_DWORD0;
1176+ cmd_tre->dword[1] = MHI_TRE_CMD_RESET_DWORD1(chan);
1177+ break;
1178+ case MHI_CMD_START_CHAN:
1179+ cmd_tre->ptr = MHI_TRE_CMD_START_PTR;
1180+ cmd_tre->dword[0] = MHI_TRE_CMD_START_DWORD0;
1181+ cmd_tre->dword[1] = MHI_TRE_CMD_START_DWORD1(chan);
1182+ break;
1183+ default:
1184+ dev_err(dev, "Command not supported\n");
1185+ break;
1186+ }
1187+
1188+ /* queue to hardware */
1189+ mhi_add_ring_element(mhi_cntrl, ring);
1190+ read_lock_bh(&mhi_cntrl->pm_lock);
1191+ if (likely(MHI_DB_ACCESS_VALID(mhi_cntrl)))
1192+ mhi_ring_cmd_db(mhi_cntrl, mhi_cmd);
1193+ read_unlock_bh(&mhi_cntrl->pm_lock);
1194+ spin_unlock_bh(&mhi_cmd->lock);
1195+
1196+ return 0;
1197+}
1198+
1199+static void __mhi_unprepare_channel(struct mhi_controller *mhi_cntrl,
1200+ struct mhi_chan *mhi_chan)
1201+{
1202+ int ret;
1203+ struct device *dev = &mhi_cntrl->mhi_dev->dev;
1204+
1205+ dev_dbg(dev, "Entered: unprepare channel:%d\n", mhi_chan->chan);
1206+
1207+ /* no more processing events for this channel */
1208+ mutex_lock(&mhi_chan->mutex);
1209+ write_lock_irq(&mhi_chan->lock);
1210+ if (mhi_chan->ch_state != MHI_CH_STATE_ENABLED) {
1211+ write_unlock_irq(&mhi_chan->lock);
1212+ mutex_unlock(&mhi_chan->mutex);
1213+ return;
1214+ }
1215+
1216+ mhi_chan->ch_state = MHI_CH_STATE_DISABLED;
1217+ write_unlock_irq(&mhi_chan->lock);
1218+
1219+ reinit_completion(&mhi_chan->completion);
1220+ read_lock_bh(&mhi_cntrl->pm_lock);
1221+ if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) {
1222+ read_unlock_bh(&mhi_cntrl->pm_lock);
1223+ goto error_invalid_state;
1224+ }
1225+
1226+ mhi_cntrl->wake_toggle(mhi_cntrl);
1227+ read_unlock_bh(&mhi_cntrl->pm_lock);
1228+
1229+ mhi_cntrl->runtime_get(mhi_cntrl);
1230+ mhi_cntrl->runtime_put(mhi_cntrl);
1231+ ret = mhi_send_cmd(mhi_cntrl, mhi_chan, MHI_CMD_RESET_CHAN);
1232+ if (ret)
1233+ goto error_invalid_state;
1234+
1235+ /* even if it fails we will still reset */
1236+ ret = wait_for_completion_timeout(&mhi_chan->completion,
1237+ msecs_to_jiffies(mhi_cntrl->timeout_ms));
1238+ if (!ret || mhi_chan->ccs != MHI_EV_CC_SUCCESS)
1239+ dev_err(dev,
1240+ "Failed to receive cmd completion, still resetting\n");
1241+
1242+error_invalid_state:
1243+ if (!mhi_chan->offload_ch) {
1244+ mhi_reset_chan(mhi_cntrl, mhi_chan);
1245+ mhi_deinit_chan_ctxt(mhi_cntrl, mhi_chan);
1246+ }
1247+ dev_dbg(dev, "chan:%d successfully resetted\n", mhi_chan->chan);
1248+ mutex_unlock(&mhi_chan->mutex);
1249+}
1250+
1251+int mhi_prepare_channel(struct mhi_controller *mhi_cntrl,
1252+ struct mhi_chan *mhi_chan)
1253+{
1254+ int ret = 0;
1255+ struct device *dev = &mhi_cntrl->mhi_dev->dev;
1256+
1257+ dev_dbg(dev, "Preparing channel: %d\n", mhi_chan->chan);
1258+
1259+ if (!(BIT(mhi_cntrl->ee) & mhi_chan->ee_mask)) {
1260+ dev_err(dev,
1261+ "Current EE: %s Required EE Mask: 0x%x for chan: %s\n",
1262+ TO_MHI_EXEC_STR(mhi_cntrl->ee), mhi_chan->ee_mask,
1263+ mhi_chan->name);
1264+ return -ENOTCONN;
1265+ }
1266+
1267+ mutex_lock(&mhi_chan->mutex);
1268+
1269+ /* If channel is not in disable state, do not allow it to start */
1270+ if (mhi_chan->ch_state != MHI_CH_STATE_DISABLED) {
1271+ ret = -EIO;
1272+ dev_dbg(dev, "channel: %d is not in disabled state\n",
1273+ mhi_chan->chan);
1274+ goto error_init_chan;
1275+ }
1276+
1277+ /* Check of client manages channel context for offload channels */
1278+ if (!mhi_chan->offload_ch) {
1279+ ret = mhi_init_chan_ctxt(mhi_cntrl, mhi_chan);
1280+ if (ret)
1281+ goto error_init_chan;
1282+ }
1283+
1284+ reinit_completion(&mhi_chan->completion);
1285+ read_lock_bh(&mhi_cntrl->pm_lock);
1286+ if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) {
1287+ read_unlock_bh(&mhi_cntrl->pm_lock);
1288+ ret = -EIO;
1289+ goto error_pm_state;
1290+ }
1291+
1292+ mhi_cntrl->wake_toggle(mhi_cntrl);
1293+ read_unlock_bh(&mhi_cntrl->pm_lock);
1294+ mhi_cntrl->runtime_get(mhi_cntrl);
1295+ mhi_cntrl->runtime_put(mhi_cntrl);
1296+
1297+ ret = mhi_send_cmd(mhi_cntrl, mhi_chan, MHI_CMD_START_CHAN);
1298+ if (ret)
1299+ goto error_pm_state;
1300+
1301+ ret = wait_for_completion_timeout(&mhi_chan->completion,
1302+ msecs_to_jiffies(mhi_cntrl->timeout_ms));
1303+ if (!ret || mhi_chan->ccs != MHI_EV_CC_SUCCESS) {
1304+ ret = -EIO;
1305+ goto error_pm_state;
1306+ }
1307+
1308+ write_lock_irq(&mhi_chan->lock);
1309+ mhi_chan->ch_state = MHI_CH_STATE_ENABLED;
1310+ write_unlock_irq(&mhi_chan->lock);
1311+
1312+ /* Pre-allocate buffer for xfer ring */
1313+ if (mhi_chan->pre_alloc) {
1314+ int nr_el = get_nr_avail_ring_elements(mhi_cntrl,
1315+ &mhi_chan->tre_ring);
1316+ size_t len = mhi_cntrl->buffer_len;
1317+
1318+ while (nr_el--) {
1319+ void *buf;
1320+
1321+ buf = kmalloc(len, GFP_KERNEL);
1322+ if (!buf) {
1323+ ret = -ENOMEM;
1324+ goto error_pre_alloc;
1325+ }
1326+
1327+ /* Prepare transfer descriptors */
1328+ ret = mhi_gen_tre(mhi_cntrl, mhi_chan, buf, buf,
1329+ len, MHI_EOT);
1330+ if (ret) {
1331+ kfree(buf);
1332+ goto error_pre_alloc;
1333+ }
1334+ }
1335+
1336+ read_lock_bh(&mhi_cntrl->pm_lock);
1337+ if (MHI_DB_ACCESS_VALID(mhi_cntrl)) {
1338+ read_lock_irq(&mhi_chan->lock);
1339+ mhi_ring_chan_db(mhi_cntrl, mhi_chan);
1340+ read_unlock_irq(&mhi_chan->lock);
1341+ }
1342+ read_unlock_bh(&mhi_cntrl->pm_lock);
1343+ }
1344+
1345+ mutex_unlock(&mhi_chan->mutex);
1346+
1347+ dev_dbg(dev, "Chan: %d successfully moved to start state\n",
1348+ mhi_chan->chan);
1349+
1350+ return 0;
1351+
1352+error_pm_state:
1353+ if (!mhi_chan->offload_ch)
1354+ mhi_deinit_chan_ctxt(mhi_cntrl, mhi_chan);
1355+
1356+error_init_chan:
1357+ mutex_unlock(&mhi_chan->mutex);
1358+
1359+ return ret;
1360+
1361+error_pre_alloc:
1362+ mutex_unlock(&mhi_chan->mutex);
1363+ __mhi_unprepare_channel(mhi_cntrl, mhi_chan);
1364+
1365+ return ret;
1366+}
1367+
1368+static void mhi_mark_stale_events(struct mhi_controller *mhi_cntrl,
1369+ struct mhi_event *mhi_event,
1370+ struct mhi_event_ctxt *er_ctxt,
1371+ int chan)
1372+
1373+{
1374+ struct mhi_tre *dev_rp, *local_rp;
1375+ struct mhi_ring *ev_ring;
1376+ struct device *dev = &mhi_cntrl->mhi_dev->dev;
1377+ unsigned long flags;
1378+
1379+ dev_dbg(dev, "Marking all events for chan: %d as stale\n", chan);
1380+
1381+ ev_ring = &mhi_event->ring;
1382+
1383+ /* mark all stale events related to channel as STALE event */
1384+ spin_lock_irqsave(&mhi_event->lock, flags);
1385+ dev_rp = mhi_to_virtual(ev_ring, er_ctxt->rp);
1386+
1387+ local_rp = ev_ring->rp;
1388+ while (dev_rp != local_rp) {
1389+ if (MHI_TRE_GET_EV_TYPE(local_rp) == MHI_PKT_TYPE_TX_EVENT &&
1390+ chan == MHI_TRE_GET_EV_CHID(local_rp))
1391+ local_rp->dword[1] = MHI_TRE_EV_DWORD1(chan,
1392+ MHI_PKT_TYPE_STALE_EVENT);
1393+ local_rp++;
1394+ if (local_rp == (ev_ring->base + ev_ring->len))
1395+ local_rp = ev_ring->base;
1396+ }
1397+
1398+ dev_dbg(dev, "Finished marking events as stale events\n");
1399+ spin_unlock_irqrestore(&mhi_event->lock, flags);
1400+}
1401+
1402+static void mhi_reset_data_chan(struct mhi_controller *mhi_cntrl,
1403+ struct mhi_chan *mhi_chan)
1404+{
1405+ struct mhi_ring *buf_ring, *tre_ring;
1406+ struct mhi_result result;
1407+
1408+ /* Reset any pending buffers */
1409+ buf_ring = &mhi_chan->buf_ring;
1410+ tre_ring = &mhi_chan->tre_ring;
1411+ result.transaction_status = -ENOTCONN;
1412+ result.bytes_xferd = 0;
1413+ while (tre_ring->rp != tre_ring->wp) {
1414+ struct mhi_buf_info *buf_info = buf_ring->rp;
1415+
1416+ if (mhi_chan->dir == DMA_TO_DEVICE)
1417+ atomic_dec(&mhi_cntrl->pending_pkts);
1418+
1419+ if (!buf_info->pre_mapped)
1420+ mhi_cntrl->unmap_single(mhi_cntrl, buf_info);
1421+
1422+ mhi_del_ring_element(mhi_cntrl, buf_ring);
1423+ mhi_del_ring_element(mhi_cntrl, tre_ring);
1424+
1425+ if (mhi_chan->pre_alloc) {
1426+ kfree(buf_info->cb_buf);
1427+ } else {
1428+ result.buf_addr = buf_info->cb_buf;
1429+ mhi_chan->xfer_cb(mhi_chan->mhi_dev, &result);
1430+ }
1431+ }
1432+}
1433+
1434+void mhi_reset_chan(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan)
1435+{
1436+ struct mhi_event *mhi_event;
1437+ struct mhi_event_ctxt *er_ctxt;
1438+ int chan = mhi_chan->chan;
1439+
1440+ /* Nothing to reset, client doesn't queue buffers */
1441+ if (mhi_chan->offload_ch)
1442+ return;
1443+
1444+ read_lock_bh(&mhi_cntrl->pm_lock);
1445+ mhi_event = &mhi_cntrl->mhi_event[mhi_chan->er_index];
1446+ er_ctxt = &mhi_cntrl->mhi_ctxt->er_ctxt[mhi_chan->er_index];
1447+
1448+ mhi_mark_stale_events(mhi_cntrl, mhi_event, er_ctxt, chan);
1449+
1450+ mhi_reset_data_chan(mhi_cntrl, mhi_chan);
1451+
1452+ read_unlock_bh(&mhi_cntrl->pm_lock);
1453+}
1454+
1455+/* Move channel to start state */
1456+int mhi_prepare_for_transfer(struct mhi_device *mhi_dev)
1457+{
1458+ int ret, dir;
1459+ struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
1460+ struct mhi_chan *mhi_chan;
1461+
1462+ for (dir = 0; dir < 2; dir++) {
1463+ mhi_chan = dir ? mhi_dev->dl_chan : mhi_dev->ul_chan;
1464+ if (!mhi_chan)
1465+ continue;
1466+
1467+ ret = mhi_prepare_channel(mhi_cntrl, mhi_chan);
1468+ if (ret)
1469+ goto error_open_chan;
1470+ }
1471+
1472+ return 0;
1473+
1474+error_open_chan:
1475+ for (--dir; dir >= 0; dir--) {
1476+ mhi_chan = dir ? mhi_dev->dl_chan : mhi_dev->ul_chan;
1477+ if (!mhi_chan)
1478+ continue;
1479+
1480+ __mhi_unprepare_channel(mhi_cntrl, mhi_chan);
1481+ }
1482+
1483+ return ret;
1484+}
1485+EXPORT_SYMBOL_GPL(mhi_prepare_for_transfer);
1486+
1487+void mhi_unprepare_from_transfer(struct mhi_device *mhi_dev)
1488+{
1489+ struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
1490+ struct mhi_chan *mhi_chan;
1491+ int dir;
1492+
1493+ for (dir = 0; dir < 2; dir++) {
1494+ mhi_chan = dir ? mhi_dev->ul_chan : mhi_dev->dl_chan;
1495+ if (!mhi_chan)
1496+ continue;
1497+
1498+ __mhi_unprepare_channel(mhi_cntrl, mhi_chan);
1499+ }
1500+}
1501+EXPORT_SYMBOL_GPL(mhi_unprepare_from_transfer);
1502+
1503+int mhi_poll(struct mhi_device *mhi_dev, u32 budget)
1504+{
1505+ struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
1506+ struct mhi_chan *mhi_chan = mhi_dev->dl_chan;
1507+ struct mhi_event *mhi_event = &mhi_cntrl->mhi_event[mhi_chan->er_index];
1508+ int ret;
1509+
1510+ spin_lock_bh(&mhi_event->lock);
1511+ ret = mhi_event->process_event(mhi_cntrl, mhi_event, budget);
1512+ spin_unlock_bh(&mhi_event->lock);
1513+
1514+ return ret;
1515+}
1516+EXPORT_SYMBOL_GPL(mhi_poll);
drivers/bus/mhi/core/pm.c+40−0
@@ -927,3 +927,43 @@ int mhi_force_rddm_mode(struct mhi_controller *mhi_cntrl) · 926 unmodified lines
927927 return ret;
928928 }
929929 EXPORT_SYMBOL_GPL(mhi_force_rddm_mode);
930+
931+void mhi_device_get(struct mhi_device *mhi_dev)
932+{
933+ struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
934+
935+ mhi_dev->dev_wake++;
936+ read_lock_bh(&mhi_cntrl->pm_lock);
937+ mhi_cntrl->wake_get(mhi_cntrl, true);
938+ read_unlock_bh(&mhi_cntrl->pm_lock);
939+}
940+EXPORT_SYMBOL_GPL(mhi_device_get);
941+
942+int mhi_device_get_sync(struct mhi_device *mhi_dev)
943+{
944+ struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
945+ int ret;
946+
947+ ret = __mhi_device_get_sync(mhi_cntrl);
948+ if (!ret)
949+ mhi_dev->dev_wake++;
950+
951+ return ret;
952+}
953+EXPORT_SYMBOL_GPL(mhi_device_get_sync);
954+
955+void mhi_device_put(struct mhi_device *mhi_dev)
956+{
957+ struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
958+
959+ mhi_dev->dev_wake--;
960+ read_lock_bh(&mhi_cntrl->pm_lock);
961+ if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) {
962+ mhi_cntrl->runtime_get(mhi_cntrl);
963+ mhi_cntrl->runtime_put(mhi_cntrl);
964+ }
965+
966+ mhi_cntrl->wake_put(mhi_cntrl, false);
967+ read_unlock_bh(&mhi_cntrl->pm_lock);
968+}
969+EXPORT_SYMBOL_GPL(mhi_device_put);
include/linux/mhi.h+80−0
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010 #include <linux/dma-direction.h>
1111 #include <linux/mutex.h>
1212 #include <linux/rwlock_types.h>
13+#include <linux/skbuff.h>
1314 #include <linux/slab.h>
1415 #include <linux/spinlock_types.h>
1516 #include <linux/wait.h>
@@ -336,6 +337,8 @@ struct mhi_controller_config { · 320 unmodified lines
336337 * @wake_toggle: CB function to assert and de-assert device wake (optional)
337338 * @runtime_get: CB function to controller runtime resume (required)
338339 * @runtimet_put: CB function to decrement pm usage (required)
340+ * @map_single: CB function to create TRE buffer
341+ * @unmap_single: CB function to destroy TRE buffer
339342 * @buffer_len: Bounce buffer length
340343 * @bounce_buf: Use of bounce buffer
341344 * @fbc_download: MHI host needs to do complete image transfer (optional)
@@ -403,6 +406,10 @@ struct mhi_controller { · 61 unmodified lines
403406 void (*wake_toggle)(struct mhi_controller *mhi_cntrl);
404407 int (*runtime_get)(struct mhi_controller *mhi_cntrl);
405408 void (*runtime_put)(struct mhi_controller *mhi_cntrl);
409+ int (*map_single)(struct mhi_controller *mhi_cntrl,
410+ struct mhi_buf_info *buf);
411+ void (*unmap_single)(struct mhi_controller *mhi_cntrl,
412+ struct mhi_buf_info *buf);
406413
407414 size_t buffer_len;
408415 bool bounce_buf;
@@ -583,4 +590,77 @@ int mhi_force_rddm_mode(struct mhi_controller *mhi_cntrl); · 174 unmodified lines
583590 */
584591 enum mhi_state mhi_get_mhi_state(struct mhi_controller *mhi_cntrl);
585592
593+/**
594+ * mhi_device_get - Disable device low power mode
595+ * @mhi_dev: Device associated with the channel
596+ */
597+void mhi_device_get(struct mhi_device *mhi_dev);
598+
599+/**
600+ * mhi_device_get_sync - Disable device low power mode. Synchronously
601+ * take the controller out of suspended state
602+ * @mhi_dev: Device associated with the channel
603+ */
604+int mhi_device_get_sync(struct mhi_device *mhi_dev);
605+
606+/**
607+ * mhi_device_put - Re-enable device low power mode
608+ * @mhi_dev: Device associated with the channel
609+ */
610+void mhi_device_put(struct mhi_device *mhi_dev);
611+
612+/**
613+ * mhi_prepare_for_transfer - Setup channel for data transfer
614+ * @mhi_dev: Device associated with the channels
615+ */
616+int mhi_prepare_for_transfer(struct mhi_device *mhi_dev);
617+
618+/**
619+ * mhi_unprepare_from_transfer - Unprepare the channels
620+ * @mhi_dev: Device associated with the channels
621+ */
622+void mhi_unprepare_from_transfer(struct mhi_device *mhi_dev);
623+
624+/**
625+ * mhi_poll - Poll for any available data in DL direction
626+ * @mhi_dev: Device associated with the channels
627+ * @budget: # of events to process
628+ */
629+int mhi_poll(struct mhi_device *mhi_dev, u32 budget);
630+
631+/**
632+ * mhi_queue_dma - Send or receive DMA mapped buffers from client device
633+ * over MHI channel
634+ * @mhi_dev: Device associated with the channels
635+ * @dir: DMA direction for the channel
636+ * @mhi_buf: Buffer for holding the DMA mapped data
637+ * @len: Buffer length
638+ * @mflags: MHI transfer flags used for the transfer
639+ */
640+int mhi_queue_dma(struct mhi_device *mhi_dev, enum dma_data_direction dir,
641+ struct mhi_buf *mhi_buf, size_t len, enum mhi_flags mflags);
642+
643+/**
644+ * mhi_queue_buf - Send or receive raw buffers from client device over MHI
645+ * channel
646+ * @mhi_dev: Device associated with the channels
647+ * @dir: DMA direction for the channel
648+ * @buf: Buffer for holding the data
649+ * @len: Buffer length
650+ * @mflags: MHI transfer flags used for the transfer
651+ */
652+int mhi_queue_buf(struct mhi_device *mhi_dev, enum dma_data_direction dir,
653+ void *buf, size_t len, enum mhi_flags mflags);
654+
655+/**
656+ * mhi_queue_skb - Send or receive SKBs from client device over MHI channel
657+ * @mhi_dev: Device associated with the channels
658+ * @dir: DMA direction for the channel
659+ * @skb: Buffer for holding SKBs
660+ * @len: Buffer length
661+ * @mflags: MHI transfer flags used for the transfer
662+ */
663+int mhi_queue_skb(struct mhi_device *mhi_dev, enum dma_data_direction dir,
664+ struct sk_buff *skb, size_t len, enum mhi_flags mflags);
665+
586666 #endif /* _MHI_H_ */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t