2020-04-28 01:01:33 +03:00
|
|
|
.. SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
=====================
|
|
|
|
Softnet Driver Issues
|
|
|
|
=====================
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
Transmit path guidelines:
|
|
|
|
|
2012-04-05 18:40:25 +04:00
|
|
|
1) The ndo_start_xmit method must not return NETDEV_TX_BUSY under
|
|
|
|
any normal circumstances. It is considered a hard error unless
|
2022-08-30 02:54:14 +03:00
|
|
|
there is no way your device can tell ahead of time when its
|
2005-04-17 02:20:36 +04:00
|
|
|
transmit function will become busy.
|
|
|
|
|
|
|
|
Instead it must maintain the queue properly. For example,
|
2020-04-28 01:01:33 +03:00
|
|
|
for a driver implementing scatter-gather this means::
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-04-05 18:40:25 +04:00
|
|
|
static netdev_tx_t drv_hard_start_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-12-08 12:14:16 +03:00
|
|
|
struct drv *dp = netdev_priv(dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
lock_tx(dp);
|
|
|
|
...
|
|
|
|
/* This is a hard error log it. */
|
|
|
|
if (TX_BUFFS_AVAIL(dp) <= (skb_shinfo(skb)->nr_frags + 1)) {
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
unlock_tx(dp);
|
|
|
|
printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
|
|
|
|
dev->name);
|
2012-04-05 18:40:25 +04:00
|
|
|
return NETDEV_TX_BUSY;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
... queue packet to card ...
|
|
|
|
... update tx consumer index ...
|
|
|
|
|
|
|
|
if (TX_BUFFS_AVAIL(dp) <= (MAX_SKB_FRAGS + 1))
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
...
|
|
|
|
unlock_tx(dp);
|
|
|
|
...
|
2012-04-05 18:40:25 +04:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2020-04-28 01:01:33 +03:00
|
|
|
And then at the end of your TX reclamation event handling::
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (netif_queue_stopped(dp->dev) &&
|
2020-04-28 01:01:33 +03:00
|
|
|
TX_BUFFS_AVAIL(dp) > (MAX_SKB_FRAGS + 1))
|
2005-04-17 02:20:36 +04:00
|
|
|
netif_wake_queue(dp->dev);
|
|
|
|
|
2020-04-28 01:01:33 +03:00
|
|
|
For a non-scatter-gather supporting card, the three tests simply become::
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* This is a hard error log it. */
|
|
|
|
if (TX_BUFFS_AVAIL(dp) <= 0)
|
|
|
|
|
2020-04-28 01:01:33 +03:00
|
|
|
and::
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (TX_BUFFS_AVAIL(dp) == 0)
|
|
|
|
|
2020-04-28 01:01:33 +03:00
|
|
|
and::
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (netif_queue_stopped(dp->dev) &&
|
2020-04-28 01:01:33 +03:00
|
|
|
TX_BUFFS_AVAIL(dp) > 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
netif_wake_queue(dp->dev);
|
|
|
|
|
2012-04-05 18:40:06 +04:00
|
|
|
2) An ndo_start_xmit method must not modify the shared parts of a
|
2008-01-15 17:25:27 +03:00
|
|
|
cloned SKB.
|
|
|
|
|
2012-04-05 18:40:25 +04:00
|
|
|
3) Do not forget that once you return NETDEV_TX_OK from your
|
|
|
|
ndo_start_xmit method, it is your driver's responsibility to free
|
|
|
|
up the SKB and in some finite amount of time.
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
For example, this means that it is not allowed for your TX
|
|
|
|
mitigation scheme to let TX packets "hang out" in the TX
|
|
|
|
ring unreclaimed forever if no new TX packets are sent.
|
|
|
|
This error can deadlock sockets waiting for send buffer room
|
|
|
|
to be freed up.
|
|
|
|
|
2012-04-05 18:40:25 +04:00
|
|
|
If you return NETDEV_TX_BUSY from the ndo_start_xmit method, you
|
|
|
|
must not keep any reference to that SKB and you must not attempt
|
|
|
|
to free it up.
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
Probing guidelines:
|
|
|
|
|
|
|
|
1) Any hardware layer address you obtain for your device should
|
|
|
|
be verified. For example, for ethernet check it with
|
|
|
|
linux/etherdevice.h:is_valid_ether_addr()
|
|
|
|
|
|
|
|
Close/stop guidelines:
|
|
|
|
|
2012-04-05 18:39:47 +04:00
|
|
|
1) After the ndo_stop routine has been called, the hardware must
|
2005-04-17 02:20:36 +04:00
|
|
|
not receive or transmit any data. All in flight packets must
|
2020-04-28 01:01:33 +03:00
|
|
|
be aborted. If necessary, poll or wait for completion of
|
2005-04-17 02:20:36 +04:00
|
|
|
any reset commands.
|
|
|
|
|
2012-04-05 18:39:47 +04:00
|
|
|
2) The ndo_stop routine will be called by unregister_netdevice
|
2005-04-17 02:20:36 +04:00
|
|
|
if device is still UP.
|