From: Vasanth Sadhasivan <vasanth.sadhasivan@xxxxxxxxxxx> DMA allocated buffers are a precious resource. If there is no need for DMA allocations, then it might be worth to use non-dma allocated buffers. After testing the gs_usb driver with and without DMA allocation, there does not seem to be a significant change in latency or cpu utilization either way. Therefore, DMA allocation is not necessary and removed. Co-developed-by: Rhett Aultman <rhett.aultman@xxxxxxxxxxx> Signed-off-by: Rhett Aultman <rhett.aultman@xxxxxxxxxxx> Signed-off-by: Vasanth Sadhasivan <vasanth.sadhasivan@xxxxxxxxxxx> --- drivers/net/can/usb/gs_usb.c | 38 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index baf749c8cda3..1bfc775c62c5 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -269,7 +269,6 @@ struct gs_can { struct usb_anchor tx_submitted; atomic_t active_tx_urbs; void *rxbuf[GS_MAX_RX_URBS]; - dma_addr_t rxbuf_dma[GS_MAX_RX_URBS]; }; /* usb interface struct */ @@ -587,9 +586,7 @@ static void gs_usb_xmit_callback(struct urb *urb) if (urb->status) netdev_info(netdev, "usb xmit fail %u\n", txc->echo_id); - - usb_free_coherent(urb->dev, urb->transfer_buffer_length, - urb->transfer_buffer, urb->transfer_dma); + devm_kfree(&urb->dev->dev, urb->transfer_buffer); } static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, @@ -618,8 +615,7 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, if (!urb) goto nomem_urb; - hf = usb_alloc_coherent(dev->udev, dev->hf_size_tx, GFP_ATOMIC, - &urb->transfer_dma); + hf = devm_kmalloc(&dev->udev->dev, dev->hf_size_tx, GFP_ATOMIC); if (!hf) { netdev_err(netdev, "No memory left for USB buffer\n"); goto nomem_hf; @@ -663,7 +659,6 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, hf, dev->hf_size_tx, gs_usb_xmit_callback, txc); - urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; usb_anchor_urb(urb, &dev->tx_submitted); can_put_echo_skb(skb, netdev, idx, 0); @@ -678,8 +673,7 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, gs_free_tx_context(txc); usb_unanchor_urb(urb); - usb_free_coherent(dev->udev, urb->transfer_buffer_length, - urb->transfer_buffer, urb->transfer_dma); + devm_kfree(&dev->udev->dev, hf); if (rc == -ENODEV) { netif_device_detach(netdev); @@ -699,8 +693,7 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, return NETDEV_TX_OK; badidx: - usb_free_coherent(dev->udev, urb->transfer_buffer_length, - urb->transfer_buffer, urb->transfer_dma); + devm_kfree(&dev->udev->dev, hf); nomem_hf: usb_free_urb(urb); @@ -744,7 +737,6 @@ static int gs_can_open(struct net_device *netdev) for (i = 0; i < GS_MAX_RX_URBS; i++) { struct urb *urb; u8 *buf; - dma_addr_t buf_dma; /* alloc rx urb */ urb = usb_alloc_urb(0, GFP_KERNEL); @@ -752,10 +744,9 @@ static int gs_can_open(struct net_device *netdev) return -ENOMEM; /* alloc rx buffer */ - buf = usb_alloc_coherent(dev->udev, - dev->parent->hf_size_rx, - GFP_KERNEL, - &buf_dma); + buf = devm_kmalloc(&dev->udev->dev, + dev->parent->hf_size_rx, + GFP_KERNEL); if (!buf) { netdev_err(netdev, "No memory left for USB buffer\n"); @@ -763,8 +754,6 @@ static int gs_can_open(struct net_device *netdev) return -ENOMEM; } - urb->transfer_dma = buf_dma; - /* fill, anchor, and submit rx urb */ usb_fill_bulk_urb(urb, dev->udev, @@ -773,7 +762,6 @@ static int gs_can_open(struct net_device *netdev) buf, dev->parent->hf_size_rx, gs_usb_receive_bulk_callback, parent); - urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; usb_anchor_urb(urb, &parent->rx_submitted); @@ -786,16 +774,12 @@ static int gs_can_open(struct net_device *netdev) "usb_submit failed (err=%d)\n", rc); usb_unanchor_urb(urb); - usb_free_coherent(dev->udev, - sizeof(struct gs_host_frame), - buf, - buf_dma); + devm_kfree(&dev->udev->dev, buf); usb_free_urb(urb); break; } dev->rxbuf[i] = buf; - dev->rxbuf_dma[i] = buf_dma; /* Drop reference, * USB core will take care of freeing it @@ -863,10 +847,8 @@ static int gs_can_close(struct net_device *netdev) if (!parent->active_channels) { usb_kill_anchored_urbs(&parent->rx_submitted); for (i = 0; i < GS_MAX_RX_URBS; i++) - usb_free_coherent(dev->udev, - sizeof(struct gs_host_frame), - dev->rxbuf[i], - dev->rxbuf_dma[i]); + devm_kfree(&dev->udev->dev, + dev->rxbuf[i]); } /* Stop sending URBs */ -- 2.25.1