Commit a4ca448e authored by Ioana Ciornei's avatar Ioana Ciornei Committed by David S. Miller

dpaa2-eth: work with an array of FDs

Up until now, the __dpaa2_eth_tx function used a single FD on the stack
to construct the structure to be enqueued. Since we are now preparing
the ground work to add support for TSO done in software at the driver
level, the same function needs to work with an array of FDs and enqueue
as many as the build_*_fd functions create.

Make the necessary adjustments in order to do this. These include:
keeping an array of FDs in a percpu structure, cleaning up the necessary
FDs before populating it and then, retrying the enqueue process up till
all the generated FDs were enqueued or until we reach the maximum number
retries.

This patch does not change the fact that only a single FD will result
from a __dpaa2_eth_tx call but rather just creates the necessary changes
for the next patch.
Signed-off-by: default avatarIoana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a4218aef
...@@ -878,6 +878,7 @@ static int dpaa2_eth_build_sg_fd(struct dpaa2_eth_priv *priv, ...@@ -878,6 +878,7 @@ static int dpaa2_eth_build_sg_fd(struct dpaa2_eth_priv *priv,
err = -ENOMEM; err = -ENOMEM;
goto dma_map_single_failed; goto dma_map_single_failed;
} }
memset(fd, 0, sizeof(struct dpaa2_fd));
dpaa2_fd_set_offset(fd, priv->tx_data_offset); dpaa2_fd_set_offset(fd, priv->tx_data_offset);
dpaa2_fd_set_format(fd, dpaa2_fd_sg); dpaa2_fd_set_format(fd, dpaa2_fd_sg);
dpaa2_fd_set_addr(fd, addr); dpaa2_fd_set_addr(fd, addr);
...@@ -946,6 +947,7 @@ static int dpaa2_eth_build_sg_fd_single_buf(struct dpaa2_eth_priv *priv, ...@@ -946,6 +947,7 @@ static int dpaa2_eth_build_sg_fd_single_buf(struct dpaa2_eth_priv *priv,
goto sgt_map_failed; goto sgt_map_failed;
} }
memset(fd, 0, sizeof(struct dpaa2_fd));
dpaa2_fd_set_offset(fd, priv->tx_data_offset); dpaa2_fd_set_offset(fd, priv->tx_data_offset);
dpaa2_fd_set_format(fd, dpaa2_fd_sg); dpaa2_fd_set_format(fd, dpaa2_fd_sg);
dpaa2_fd_set_addr(fd, sgt_addr); dpaa2_fd_set_addr(fd, sgt_addr);
...@@ -998,6 +1000,7 @@ static int dpaa2_eth_build_single_fd(struct dpaa2_eth_priv *priv, ...@@ -998,6 +1000,7 @@ static int dpaa2_eth_build_single_fd(struct dpaa2_eth_priv *priv,
if (unlikely(dma_mapping_error(dev, addr))) if (unlikely(dma_mapping_error(dev, addr)))
return -ENOMEM; return -ENOMEM;
memset(fd, 0, sizeof(struct dpaa2_fd));
dpaa2_fd_set_addr(fd, addr); dpaa2_fd_set_addr(fd, addr);
dpaa2_fd_set_offset(fd, (u16)(skb->data - buffer_start)); dpaa2_fd_set_offset(fd, (u16)(skb->data - buffer_start));
dpaa2_fd_set_len(fd, skb->len); dpaa2_fd_set_len(fd, skb->len);
...@@ -1111,12 +1114,14 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb, ...@@ -1111,12 +1114,14 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb,
struct net_device *net_dev) struct net_device *net_dev)
{ {
struct dpaa2_eth_priv *priv = netdev_priv(net_dev); struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
int total_enqueued = 0, retries = 0, enqueued;
struct dpaa2_eth_drv_stats *percpu_extras; struct dpaa2_eth_drv_stats *percpu_extras;
struct rtnl_link_stats64 *percpu_stats; struct rtnl_link_stats64 *percpu_stats;
unsigned int needed_headroom; unsigned int needed_headroom;
int num_fds = 1, max_retries;
struct dpaa2_eth_fq *fq; struct dpaa2_eth_fq *fq;
struct netdev_queue *nq; struct netdev_queue *nq;
struct dpaa2_fd fd; struct dpaa2_fd *fd;
u16 queue_mapping; u16 queue_mapping;
u8 prio = 0; u8 prio = 0;
int err, i; int err, i;
...@@ -1125,6 +1130,7 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb, ...@@ -1125,6 +1130,7 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb,
percpu_stats = this_cpu_ptr(priv->percpu_stats); percpu_stats = this_cpu_ptr(priv->percpu_stats);
percpu_extras = this_cpu_ptr(priv->percpu_extras); percpu_extras = this_cpu_ptr(priv->percpu_extras);
fd = (this_cpu_ptr(priv->fd))->array;
needed_headroom = dpaa2_eth_needed_headroom(skb); needed_headroom = dpaa2_eth_needed_headroom(skb);
...@@ -1139,20 +1145,22 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb, ...@@ -1139,20 +1145,22 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb,
} }
/* Setup the FD fields */ /* Setup the FD fields */
memset(&fd, 0, sizeof(fd));
if (skb_is_nonlinear(skb)) { if (skb_is_nonlinear(skb)) {
err = dpaa2_eth_build_sg_fd(priv, skb, &fd, &swa); err = dpaa2_eth_build_sg_fd(priv, skb, fd, &swa);
percpu_extras->tx_sg_frames++; percpu_extras->tx_sg_frames++;
percpu_extras->tx_sg_bytes += skb->len; percpu_extras->tx_sg_bytes += skb->len;
fd_len = dpaa2_fd_get_len(fd);
} else if (skb_headroom(skb) < needed_headroom) { } else if (skb_headroom(skb) < needed_headroom) {
err = dpaa2_eth_build_sg_fd_single_buf(priv, skb, &fd, &swa); err = dpaa2_eth_build_sg_fd_single_buf(priv, skb, fd, &swa);
percpu_extras->tx_sg_frames++; percpu_extras->tx_sg_frames++;
percpu_extras->tx_sg_bytes += skb->len; percpu_extras->tx_sg_bytes += skb->len;
percpu_extras->tx_converted_sg_frames++; percpu_extras->tx_converted_sg_frames++;
percpu_extras->tx_converted_sg_bytes += skb->len; percpu_extras->tx_converted_sg_bytes += skb->len;
fd_len = dpaa2_fd_get_len(fd);
} else { } else {
err = dpaa2_eth_build_single_fd(priv, skb, &fd, &swa); err = dpaa2_eth_build_single_fd(priv, skb, fd, &swa);
fd_len = dpaa2_fd_get_len(fd);
} }
if (unlikely(err)) { if (unlikely(err)) {
...@@ -1161,10 +1169,11 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb, ...@@ -1161,10 +1169,11 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb,
} }
if (skb->cb[0]) if (skb->cb[0])
dpaa2_eth_enable_tx_tstamp(priv, &fd, swa, skb); dpaa2_eth_enable_tx_tstamp(priv, fd, swa, skb);
/* Tracing point */ /* Tracing point */
trace_dpaa2_tx_fd(net_dev, &fd); for (i = 0; i < num_fds; i++)
trace_dpaa2_tx_fd(net_dev, &fd[i]);
/* TxConf FQ selection relies on queue id from the stack. /* TxConf FQ selection relies on queue id from the stack.
* In case of a forwarded frame from another DPNI interface, we choose * In case of a forwarded frame from another DPNI interface, we choose
...@@ -1184,27 +1193,32 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb, ...@@ -1184,27 +1193,32 @@ static netdev_tx_t __dpaa2_eth_tx(struct sk_buff *skb,
queue_mapping %= dpaa2_eth_queue_count(priv); queue_mapping %= dpaa2_eth_queue_count(priv);
} }
fq = &priv->fq[queue_mapping]; fq = &priv->fq[queue_mapping];
fd_len = dpaa2_fd_get_len(&fd);
nq = netdev_get_tx_queue(net_dev, queue_mapping); nq = netdev_get_tx_queue(net_dev, queue_mapping);
netdev_tx_sent_queue(nq, fd_len); netdev_tx_sent_queue(nq, fd_len);
/* Everything that happens after this enqueues might race with /* Everything that happens after this enqueues might race with
* the Tx confirmation callback for this frame * the Tx confirmation callback for this frame
*/ */
for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) { max_retries = num_fds * DPAA2_ETH_ENQUEUE_RETRIES;
err = priv->enqueue(priv, fq, &fd, prio, 1, NULL); while (total_enqueued < num_fds && retries < max_retries) {
if (err != -EBUSY) err = priv->enqueue(priv, fq, &fd[total_enqueued],
break; prio, num_fds - total_enqueued, &enqueued);
if (err == -EBUSY) {
retries++;
continue;
} }
percpu_extras->tx_portal_busy += i;
total_enqueued += enqueued;
}
percpu_extras->tx_portal_busy += retries;
if (unlikely(err < 0)) { if (unlikely(err < 0)) {
percpu_stats->tx_errors++; percpu_stats->tx_errors++;
/* Clean up everything, including freeing the skb */ /* Clean up everything, including freeing the skb */
dpaa2_eth_free_tx_fd(priv, fq, &fd, false); dpaa2_eth_free_tx_fd(priv, fq, fd, false);
netdev_tx_completed_queue(nq, 1, fd_len); netdev_tx_completed_queue(nq, 1, fd_len);
} else { } else {
percpu_stats->tx_packets++; percpu_stats->tx_packets += total_enqueued;
percpu_stats->tx_bytes += fd_len; percpu_stats->tx_bytes += fd_len;
} }
...@@ -4406,6 +4420,13 @@ static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev) ...@@ -4406,6 +4420,13 @@ static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev)
goto err_alloc_sgt_cache; goto err_alloc_sgt_cache;
} }
priv->fd = alloc_percpu(*priv->fd);
if (!priv->fd) {
dev_err(dev, "alloc_percpu(fds) failed\n");
err = -ENOMEM;
goto err_alloc_fds;
}
err = dpaa2_eth_netdev_init(net_dev); err = dpaa2_eth_netdev_init(net_dev);
if (err) if (err)
goto err_netdev_init; goto err_netdev_init;
...@@ -4493,6 +4514,8 @@ static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev) ...@@ -4493,6 +4514,8 @@ static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev)
err_alloc_rings: err_alloc_rings:
err_csum: err_csum:
err_netdev_init: err_netdev_init:
free_percpu(priv->fd);
err_alloc_fds:
free_percpu(priv->sgt_cache); free_percpu(priv->sgt_cache);
err_alloc_sgt_cache: err_alloc_sgt_cache:
free_percpu(priv->percpu_extras); free_percpu(priv->percpu_extras);
...@@ -4548,6 +4571,7 @@ static int dpaa2_eth_remove(struct fsl_mc_device *ls_dev) ...@@ -4548,6 +4571,7 @@ static int dpaa2_eth_remove(struct fsl_mc_device *ls_dev)
fsl_mc_free_irqs(ls_dev); fsl_mc_free_irqs(ls_dev);
dpaa2_eth_free_rings(priv); dpaa2_eth_free_rings(priv);
free_percpu(priv->fd);
free_percpu(priv->sgt_cache); free_percpu(priv->sgt_cache);
free_percpu(priv->percpu_stats); free_percpu(priv->percpu_stats);
free_percpu(priv->percpu_extras); free_percpu(priv->percpu_extras);
......
...@@ -497,6 +497,11 @@ struct dpaa2_eth_trap_data { ...@@ -497,6 +497,11 @@ struct dpaa2_eth_trap_data {
#define DPAA2_ETH_DEFAULT_COPYBREAK 512 #define DPAA2_ETH_DEFAULT_COPYBREAK 512
#define DPAA2_ETH_ENQUEUE_MAX_FDS 200
struct dpaa2_eth_fds {
struct dpaa2_fd array[DPAA2_ETH_ENQUEUE_MAX_FDS];
};
/* Driver private data */ /* Driver private data */
struct dpaa2_eth_priv { struct dpaa2_eth_priv {
struct net_device *net_dev; struct net_device *net_dev;
...@@ -579,6 +584,8 @@ struct dpaa2_eth_priv { ...@@ -579,6 +584,8 @@ struct dpaa2_eth_priv {
struct devlink_port devlink_port; struct devlink_port devlink_port;
u32 rx_copybreak; u32 rx_copybreak;
struct dpaa2_eth_fds __percpu *fd;
}; };
struct dpaa2_eth_devlink_priv { struct dpaa2_eth_devlink_priv {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment