diff options
| author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2016-04-07 14:39:45 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2016-04-08 15:26:05 -0400 |
| commit | 30d2117191b7437b5b6ce2f09eddf86f203c7a37 (patch) | |
| tree | f437adb19c983ee21fbb22f42710ea5088c21c96 /drivers/net/ethernet | |
| parent | aba52df80b1a2d15fe1745dfe187e9823821f5c0 (diff) | |
nfp: propagate list buffer size in struct rx_ring
Free list buffer size needs to be propagated to few functions
as a parameter and added to struct nfp_net_rx_ring since soon
some of the functions will be reused to manage rings with
buffers of size different than nn->fl_bufsz.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet')
| -rw-r--r-- | drivers/net/ethernet/netronome/nfp/nfp_net.h | 3 | ||||
| -rw-r--r-- | drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 24 |
2 files changed, 19 insertions, 8 deletions
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net.h b/drivers/net/ethernet/netronome/nfp/nfp_net.h index fc005c982b7d..9ab8e3967dc9 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net.h +++ b/drivers/net/ethernet/netronome/nfp/nfp_net.h | |||
| @@ -298,6 +298,8 @@ struct nfp_net_rx_buf { | |||
| 298 | * @rxds: Virtual address of FL/RX ring in host memory | 298 | * @rxds: Virtual address of FL/RX ring in host memory |
| 299 | * @dma: DMA address of the FL/RX ring | 299 | * @dma: DMA address of the FL/RX ring |
| 300 | * @size: Size, in bytes, of the FL/RX ring (needed to free) | 300 | * @size: Size, in bytes, of the FL/RX ring (needed to free) |
| 301 | * @bufsz: Buffer allocation size for convenience of management routines | ||
| 302 | * (NOTE: this is in second cache line, do not use on fast path!) | ||
| 301 | */ | 303 | */ |
| 302 | struct nfp_net_rx_ring { | 304 | struct nfp_net_rx_ring { |
| 303 | struct nfp_net_r_vector *r_vec; | 305 | struct nfp_net_r_vector *r_vec; |
| @@ -319,6 +321,7 @@ struct nfp_net_rx_ring { | |||
| 319 | 321 | ||
| 320 | dma_addr_t dma; | 322 | dma_addr_t dma; |
| 321 | unsigned int size; | 323 | unsigned int size; |
| 324 | unsigned int bufsz; | ||
| 322 | } ____cacheline_aligned; | 325 | } ____cacheline_aligned; |
| 323 | 326 | ||
| 324 | /** | 327 | /** |
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index ed23b9d348c3..03c60f755de0 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c | |||
| @@ -957,25 +957,27 @@ static inline int nfp_net_rx_space(struct nfp_net_rx_ring *rx_ring) | |||
| 957 | * nfp_net_rx_alloc_one() - Allocate and map skb for RX | 957 | * nfp_net_rx_alloc_one() - Allocate and map skb for RX |
| 958 | * @rx_ring: RX ring structure of the skb | 958 | * @rx_ring: RX ring structure of the skb |
| 959 | * @dma_addr: Pointer to storage for DMA address (output param) | 959 | * @dma_addr: Pointer to storage for DMA address (output param) |
| 960 | * @fl_bufsz: size of freelist buffers | ||
| 960 | * | 961 | * |
| 961 | * This function will allcate a new skb, map it for DMA. | 962 | * This function will allcate a new skb, map it for DMA. |
| 962 | * | 963 | * |
| 963 | * Return: allocated skb or NULL on failure. | 964 | * Return: allocated skb or NULL on failure. |
| 964 | */ | 965 | */ |
| 965 | static struct sk_buff * | 966 | static struct sk_buff * |
| 966 | nfp_net_rx_alloc_one(struct nfp_net_rx_ring *rx_ring, dma_addr_t *dma_addr) | 967 | nfp_net_rx_alloc_one(struct nfp_net_rx_ring *rx_ring, dma_addr_t *dma_addr, |
| 968 | unsigned int fl_bufsz) | ||
| 967 | { | 969 | { |
| 968 | struct nfp_net *nn = rx_ring->r_vec->nfp_net; | 970 | struct nfp_net *nn = rx_ring->r_vec->nfp_net; |
| 969 | struct sk_buff *skb; | 971 | struct sk_buff *skb; |
| 970 | 972 | ||
| 971 | skb = netdev_alloc_skb(nn->netdev, nn->fl_bufsz); | 973 | skb = netdev_alloc_skb(nn->netdev, fl_bufsz); |
| 972 | if (!skb) { | 974 | if (!skb) { |
| 973 | nn_warn_ratelimit(nn, "Failed to alloc receive SKB\n"); | 975 | nn_warn_ratelimit(nn, "Failed to alloc receive SKB\n"); |
| 974 | return NULL; | 976 | return NULL; |
| 975 | } | 977 | } |
| 976 | 978 | ||
| 977 | *dma_addr = dma_map_single(&nn->pdev->dev, skb->data, | 979 | *dma_addr = dma_map_single(&nn->pdev->dev, skb->data, |
| 978 | nn->fl_bufsz, DMA_FROM_DEVICE); | 980 | fl_bufsz, DMA_FROM_DEVICE); |
| 979 | if (dma_mapping_error(&nn->pdev->dev, *dma_addr)) { | 981 | if (dma_mapping_error(&nn->pdev->dev, *dma_addr)) { |
| 980 | dev_kfree_skb_any(skb); | 982 | dev_kfree_skb_any(skb); |
| 981 | nn_warn_ratelimit(nn, "Failed to map DMA RX buffer\n"); | 983 | nn_warn_ratelimit(nn, "Failed to map DMA RX buffer\n"); |
| @@ -1068,7 +1070,7 @@ nfp_net_rx_ring_bufs_free(struct nfp_net *nn, struct nfp_net_rx_ring *rx_ring) | |||
| 1068 | continue; | 1070 | continue; |
| 1069 | 1071 | ||
| 1070 | dma_unmap_single(&pdev->dev, rx_ring->rxbufs[i].dma_addr, | 1072 | dma_unmap_single(&pdev->dev, rx_ring->rxbufs[i].dma_addr, |
| 1071 | nn->fl_bufsz, DMA_FROM_DEVICE); | 1073 | rx_ring->bufsz, DMA_FROM_DEVICE); |
| 1072 | dev_kfree_skb_any(rx_ring->rxbufs[i].skb); | 1074 | dev_kfree_skb_any(rx_ring->rxbufs[i].skb); |
| 1073 | rx_ring->rxbufs[i].dma_addr = 0; | 1075 | rx_ring->rxbufs[i].dma_addr = 0; |
| 1074 | rx_ring->rxbufs[i].skb = NULL; | 1076 | rx_ring->rxbufs[i].skb = NULL; |
| @@ -1090,7 +1092,8 @@ nfp_net_rx_ring_bufs_alloc(struct nfp_net *nn, struct nfp_net_rx_ring *rx_ring) | |||
| 1090 | 1092 | ||
| 1091 | for (i = 0; i < rx_ring->cnt - 1; i++) { | 1093 | for (i = 0; i < rx_ring->cnt - 1; i++) { |
| 1092 | rxbufs[i].skb = | 1094 | rxbufs[i].skb = |
| 1093 | nfp_net_rx_alloc_one(rx_ring, &rxbufs[i].dma_addr); | 1095 | nfp_net_rx_alloc_one(rx_ring, &rxbufs[i].dma_addr, |
| 1096 | rx_ring->bufsz); | ||
| 1094 | if (!rxbufs[i].skb) { | 1097 | if (!rxbufs[i].skb) { |
| 1095 | nfp_net_rx_ring_bufs_free(nn, rx_ring); | 1098 | nfp_net_rx_ring_bufs_free(nn, rx_ring); |
| 1096 | return -ENOMEM; | 1099 | return -ENOMEM; |
| @@ -1278,7 +1281,8 @@ static int nfp_net_rx(struct nfp_net_rx_ring *rx_ring, int budget) | |||
| 1278 | 1281 | ||
| 1279 | skb = rx_ring->rxbufs[idx].skb; | 1282 | skb = rx_ring->rxbufs[idx].skb; |
| 1280 | 1283 | ||
| 1281 | new_skb = nfp_net_rx_alloc_one(rx_ring, &new_dma_addr); | 1284 | new_skb = nfp_net_rx_alloc_one(rx_ring, &new_dma_addr, |
| 1285 | nn->fl_bufsz); | ||
| 1282 | if (!new_skb) { | 1286 | if (!new_skb) { |
| 1283 | nfp_net_rx_give_one(rx_ring, rx_ring->rxbufs[idx].skb, | 1287 | nfp_net_rx_give_one(rx_ring, rx_ring->rxbufs[idx].skb, |
| 1284 | rx_ring->rxbufs[idx].dma_addr); | 1288 | rx_ring->rxbufs[idx].dma_addr); |
| @@ -1465,10 +1469,12 @@ static void nfp_net_rx_ring_free(struct nfp_net_rx_ring *rx_ring) | |||
| 1465 | /** | 1469 | /** |
| 1466 | * nfp_net_rx_ring_alloc() - Allocate resource for a RX ring | 1470 | * nfp_net_rx_ring_alloc() - Allocate resource for a RX ring |
| 1467 | * @rx_ring: RX ring to allocate | 1471 | * @rx_ring: RX ring to allocate |
| 1472 | * @fl_bufsz: Size of buffers to allocate | ||
| 1468 | * | 1473 | * |
| 1469 | * Return: 0 on success, negative errno otherwise. | 1474 | * Return: 0 on success, negative errno otherwise. |
| 1470 | */ | 1475 | */ |
| 1471 | static int nfp_net_rx_ring_alloc(struct nfp_net_rx_ring *rx_ring) | 1476 | static int |
| 1477 | nfp_net_rx_ring_alloc(struct nfp_net_rx_ring *rx_ring, unsigned int fl_bufsz) | ||
| 1472 | { | 1478 | { |
| 1473 | struct nfp_net_r_vector *r_vec = rx_ring->r_vec; | 1479 | struct nfp_net_r_vector *r_vec = rx_ring->r_vec; |
| 1474 | struct nfp_net *nn = r_vec->nfp_net; | 1480 | struct nfp_net *nn = r_vec->nfp_net; |
| @@ -1476,6 +1482,7 @@ static int nfp_net_rx_ring_alloc(struct nfp_net_rx_ring *rx_ring) | |||
| 1476 | int sz; | 1482 | int sz; |
| 1477 | 1483 | ||
| 1478 | rx_ring->cnt = nn->rxd_cnt; | 1484 | rx_ring->cnt = nn->rxd_cnt; |
| 1485 | rx_ring->bufsz = fl_bufsz; | ||
| 1479 | 1486 | ||
| 1480 | rx_ring->size = sizeof(*rx_ring->rxds) * rx_ring->cnt; | 1487 | rx_ring->size = sizeof(*rx_ring->rxds) * rx_ring->cnt; |
| 1481 | rx_ring->rxds = dma_zalloc_coherent(&pdev->dev, rx_ring->size, | 1488 | rx_ring->rxds = dma_zalloc_coherent(&pdev->dev, rx_ring->size, |
| @@ -1817,7 +1824,8 @@ static int nfp_net_netdev_open(struct net_device *netdev) | |||
| 1817 | if (err) | 1824 | if (err) |
| 1818 | goto err_cleanup_vec_p; | 1825 | goto err_cleanup_vec_p; |
| 1819 | 1826 | ||
| 1820 | err = nfp_net_rx_ring_alloc(nn->r_vecs[r].rx_ring); | 1827 | err = nfp_net_rx_ring_alloc(nn->r_vecs[r].rx_ring, |
| 1828 | nn->fl_bufsz); | ||
| 1821 | if (err) | 1829 | if (err) |
| 1822 | goto err_free_tx_ring_p; | 1830 | goto err_free_tx_ring_p; |
| 1823 | 1831 | ||
