Skip to content

Commit 5f54c54

Browse files
Vahram AharonyanFelipe Balbi
authored andcommitted
usb: dwc2: gadget: Add DDMA chain pointers to dwc2_hsotg_ep structure
Add DMA descriptor members to the dwc2_hsotg_ep structure. Signed-off-by: Vahram Aharonyan <vahrama@synopsys.com> Signed-off-by: John Youn <johnyoun@synopsys.com> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
1 parent cf77b5f commit 5f54c54

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

drivers/usb/dwc2/core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ struct dwc2_hsotg_req;
172172
* @periodic: Set if this is a periodic ep, such as Interrupt
173173
* @isochronous: Set if this is a isochronous ep
174174
* @send_zlp: Set if we need to send a zero-length packet.
175+
* @desc_list_dma: The DMA address of descriptor chain currently in use.
176+
* @desc_list: Pointer to descriptor DMA chain head currently in use.
177+
* @desc_count: Count of entries within the DMA descriptor chain of EP.
175178
* @total_data: The total number of data bytes done.
176179
* @fifo_size: The size of the FIFO (for periodic IN endpoints)
177180
* @fifo_load: The amount of data loaded into the FIFO (periodic IN)
@@ -219,6 +222,10 @@ struct dwc2_hsotg_ep {
219222
#define TARGET_FRAME_INITIAL 0xFFFFFFFF
220223
bool frame_overrun;
221224

225+
dma_addr_t desc_list_dma;
226+
struct dwc2_dma_desc *desc_list;
227+
u8 desc_count;
228+
222229
char name[10];
223230
};
224231

drivers/usb/dwc2/gadget.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,6 +3077,18 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
30773077
dev_dbg(hsotg->dev, "%s: read DxEPCTL=0x%08x from 0x%08x\n",
30783078
__func__, epctrl, epctrl_reg);
30793079

3080+
/* Allocate DMA descriptor chain for non-ctrl endpoints */
3081+
if (using_desc_dma(hsotg)) {
3082+
hs_ep->desc_list = dma_alloc_coherent(hsotg->dev,
3083+
MAX_DMA_DESC_NUM_GENERIC *
3084+
sizeof(struct dwc2_dma_desc),
3085+
&hs_ep->desc_list_dma, GFP_KERNEL);
3086+
if (!hs_ep->desc_list) {
3087+
ret = -ENOMEM;
3088+
goto error2;
3089+
}
3090+
}
3091+
30803092
spin_lock_irqsave(&hsotg->lock, flags);
30813093

30823094
epctrl &= ~(DXEPCTL_EPTYPE_MASK | DXEPCTL_MPS_MASK);
@@ -3160,7 +3172,7 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
31603172
dev_err(hsotg->dev,
31613173
"%s: No suitable fifo found\n", __func__);
31623174
ret = -ENOMEM;
3163-
goto error;
3175+
goto error1;
31643176
}
31653177
hsotg->fifo_map |= 1 << fifo_index;
31663178
epctrl |= DXEPCTL_TXFNUM(fifo_index);
@@ -3182,8 +3194,17 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
31823194
/* enable the endpoint interrupt */
31833195
dwc2_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
31843196

3185-
error:
3197+
error1:
31863198
spin_unlock_irqrestore(&hsotg->lock, flags);
3199+
3200+
error2:
3201+
if (ret && using_desc_dma(hsotg) && hs_ep->desc_list) {
3202+
dma_free_coherent(hsotg->dev, MAX_DMA_DESC_NUM_GENERIC *
3203+
sizeof(struct dwc2_dma_desc),
3204+
hs_ep->desc_list, hs_ep->desc_list_dma);
3205+
hs_ep->desc_list = NULL;
3206+
}
3207+
31873208
return ret;
31883209
}
31893210

@@ -3208,6 +3229,14 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep)
32083229
return -EINVAL;
32093230
}
32103231

3232+
/* Remove DMA memory allocated for non-control Endpoints */
3233+
if (using_desc_dma(hsotg)) {
3234+
dma_free_coherent(hsotg->dev, MAX_DMA_DESC_NUM_GENERIC *
3235+
sizeof(struct dwc2_dma_desc),
3236+
hs_ep->desc_list, hs_ep->desc_list_dma);
3237+
hs_ep->desc_list = NULL;
3238+
}
3239+
32113240
epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index);
32123241

32133242
spin_lock_irqsave(&hsotg->lock, flags);

0 commit comments

Comments
 (0)