Skip to content

Commit e24e23b

Browse files
tmon-nordicgithub-actions[bot]
authored andcommitted
[nrf fromtree] drivers: udc_dwc2: Fix multipart DMA OUT transfers
DMA transfers are supposed to write to buffer tail. Use the proper pointer to make multipart DMA transfers actually write the data to the intended location. The issue was observed on control write transfers where the OUT Data Stage was at least 128 bytes (because endpoint 0 transfer width is limited to 7 bits). The issue is unlikely to happen on non-control transfers because the transfer size width is at least 11 bits (at most 19 bits) and packet size counter is at least 4 bits (at most: 10 bits) which means that at least 2048 byte transfer spanning at least 15 packets (or at least 524288 byte spanning 1023 packets for 19 bits transfer size counter and 10 bits packet counter) is required to necessitate multipart DMA. Signed-off-by: Tomasz Moń <[email protected]> (cherry picked from commit 45ee2a0) (cherry picked from commit 3d948a5)
1 parent 0f0106c commit e24e23b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/usb/udc/udc_dwc2.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,17 +660,19 @@ static void dwc2_prep_rx(const struct device *dev, struct net_buf *buf,
660660
sys_write32(doeptsiz, doeptsiz_reg);
661661

662662
if (priv->bufferdma) {
663-
if (!dwc2_dma_buffer_ok_to_use(dev, buf->data, xfersize, cfg->mps)) {
663+
void *data = net_buf_tail(buf);
664+
665+
if (!dwc2_dma_buffer_ok_to_use(dev, data, xfersize, cfg->mps)) {
664666
/* Cannot continue unless buffer is bounced. Device will
665667
* cease to function. Is fatal error appropriate here?
666668
*/
667669
return;
668670
}
669671

670-
sys_write32((uint32_t)buf->data,
672+
sys_write32((uint32_t)data,
671673
(mem_addr_t)&base->out_ep[ep_idx].doepdma);
672674

673-
sys_cache_data_invd_range(buf->data, xfersize);
675+
sys_cache_data_invd_range(data, xfersize);
674676
}
675677

676678
sys_write32(doepctl, doepctl_reg);
@@ -2514,7 +2516,7 @@ static inline void dwc2_handle_out_xfercompl(const struct device *dev,
25142516
}
25152517

25162518
if (priv->bufferdma && bcnt) {
2517-
sys_cache_data_invd_range(buf->data, bcnt);
2519+
sys_cache_data_invd_range(net_buf_tail(buf), bcnt);
25182520
net_buf_add(buf, bcnt);
25192521
}
25202522

0 commit comments

Comments
 (0)