Messages in this thread | | | From | Radhey Shyam Pandey <> | Subject | RE: [PATCH 05/14] net: axienet: Factor out TX descriptor chain cleanup | Date | Fri, 10 Jan 2020 18:04:57 +0000 |
| |
> -----Original Message----- > From: Andre Przywara <andre.przywara@arm.com> > Sent: Friday, January 10, 2020 5:24 PM > To: David S . Miller <davem@davemloft.net>; Radhey Shyam Pandey > <radheys@xilinx.com> > Cc: Michal Simek <michals@xilinx.com>; Robert Hancock > <hancock@sedsystems.ca>; netdev@vger.kernel.org; linux-arm- > kernel@lists.infradead.org; linux-kernel@vger.kernel.org > Subject: [PATCH 05/14] net: axienet: Factor out TX descriptor chain cleanup > > Factor out the code that cleans up a number of connected TX descriptors, > as we will need it to properly roll back a failed _xmit() call. > There are subtle differences between cleaning up a successfully sent > chain (unknown number of involved descriptors, total data size needed) > and a chain that was about to set up (number of descriptors known), so > cater for those variations with some extra parameters. > > Signed-off-by: Andre Przywara <andre.przywara@arm.com> > --- > .../net/ethernet/xilinx/xilinx_axienet_main.c | 75 ++++++++++++------- > 1 file changed, 50 insertions(+), 25 deletions(-) > > diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > index ec5d01adc1d5..82abe2b0f16a 100644 > --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c > @@ -543,33 +543,37 @@ static int axienet_device_reset(struct net_device > *ndev) > return 0; > } > > -/** > - * axienet_start_xmit_done - Invoked once a transmit is completed by the > - * Axi DMA Tx channel. > - * @ndev: Pointer to the net_device structure > - * > - * This function is invoked from the Axi DMA Tx isr to notify the completion > - * of transmit operation. It clears fields in the corresponding Tx BDs and > - * unmaps the corresponding buffer so that CPU can regain ownership of > the > - * buffer. It finally invokes "netif_wake_queue" to restart transmission if > - * required. > +/* Clean up a series of linked TX descriptors. Would either be called > + * after a successful transmit operation, or after there was an error > + * when setting up the chain. > + * Returns the number of descriptors handled. > */ > -static void axienet_start_xmit_done(struct net_device *ndev)
To be consistent we can add the doxygen function description. The rest looks good. Feel free to add: Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
> +static int axienet_free_tx_chain(struct net_device *ndev, u32 first_bd, > + int nr_bds, u32 *sizep) > { > - u32 size = 0; > - u32 packets = 0; > struct axienet_local *lp = netdev_priv(ndev); > + int max_bds = (nr_bds != -1) ? nr_bds : lp->tx_bd_num; > struct axidma_bd *cur_p; > - unsigned int status = 0; > + unsigned int status; > + int i; > + > + for (i = 0; i < max_bds; i++) { > + cur_p = &lp->tx_bd_v[(first_bd + i) % lp->tx_bd_num]; > + status = cur_p->status; > + > + /* If no number is given, clean up *all* descriptors that have > + * been completed by the MAC. > + */ > + if (nr_bds == -1 && !(status & > XAXIDMA_BD_STS_COMPLETE_MASK)) > + break; > > - cur_p = &lp->tx_bd_v[lp->tx_bd_ci]; > - status = cur_p->status; > - while (status & XAXIDMA_BD_STS_COMPLETE_MASK) { > dma_unmap_single(ndev->dev.parent, cur_p->phys, > (cur_p->cntrl & > XAXIDMA_BD_CTRL_LENGTH_MASK), > DMA_TO_DEVICE); > - if (cur_p->skb) > + > + if (cur_p->skb && (status & > XAXIDMA_BD_STS_COMPLETE_MASK)) > dev_consume_skb_irq(cur_p->skb); > + > cur_p->cntrl = 0; > cur_p->app0 = 0; > cur_p->app1 = 0; > @@ -578,15 +582,36 @@ static void axienet_start_xmit_done(struct > net_device *ndev) > cur_p->status = 0; > cur_p->skb = NULL; > > - size += status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK; > - packets++; > - > - if (++lp->tx_bd_ci >= lp->tx_bd_num) > - lp->tx_bd_ci = 0; > - cur_p = &lp->tx_bd_v[lp->tx_bd_ci]; > - status = cur_p->status; > + if (sizep) > + *sizep += status & > XAXIDMA_BD_STS_ACTUAL_LEN_MASK; > } > > + return i; > +} > + > +/** > + * axienet_start_xmit_done - Invoked once a transmit is completed by the > + * Axi DMA Tx channel. > + * @ndev: Pointer to the net_device structure > + * > + * This function is invoked from the Axi DMA Tx isr to notify the completion > + * of transmit operation. It clears fields in the corresponding Tx BDs and > + * unmaps the corresponding buffer so that CPU can regain ownership of > the > + * buffer. It finally invokes "netif_wake_queue" to restart transmission if > + * required. > + */ > +static void axienet_start_xmit_done(struct net_device *ndev) > +{ > + u32 size = 0; > + u32 packets = 0; > + struct axienet_local *lp = netdev_priv(ndev); > + > + packets = axienet_free_tx_chain(ndev, lp->tx_bd_ci, -1, &size); > + > + lp->tx_bd_ci += packets; > + if (lp->tx_bd_ci >= lp->tx_bd_num) > + lp->tx_bd_ci -= lp->tx_bd_num; > + > ndev->stats.tx_packets += packets; > ndev->stats.tx_bytes += size; > > -- > 2.17.1
| |