Allow NICs to pass Frame Checksum up the stack.
Subsystems (3)
cover Allow NICs to pass Frame Checksum up the stack.
From: Ben Greear <[email protected]>
This series provides ethtool support to set and get the rx-checksum flag, and adds support to the e100 driver.
Assuming this series is acceptable, I would then propose a series of patches to allow receiving all frames, even ones with bad checksums, etc.
And if that is acceptable, a third series would allow user-space to generate packets with custom ethernet frame checksums (ie, bad ones if desired).
And finally, more drivers, such as e1000 and hopefully e100e can be supported.
Ben Greear (2):
net: Support getting/setting RX-FCS in drivers.
e100: Support receiving Ethernet FCS.
drivers/net/e100.c | 39 ++++++++++++++++++++++++++++++++++++--- include/linux/ethtool.h | 5 +++++ net/core/ethtool.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.3.4
RFC 1/2 net: Support getting/setting RX-FCS in drivers.
From: Ben Greear <[email protected]>
This will allow us to enable/disable having the Ethernet frame checksum appended to the skb. Enabling this is useful when sniffing packets.
In particular, this can be used to test logic that allows a NIC to receive all frames, even ones with bad checksums.
---
:100644 100644 439b173... e5e8747... M include/linux/ethtool.h
:100644 100644 fd14116... b36bac7... M net/core/ethtool.c
include/linux/ethtool.h | 5 +++++ net/core/ethtool.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 0 deletions(-)
include/linux/ethtool.h +5 -0
@@ -955,6 +955,8 @@ struct ethtool_ops {int (*get_dump_data)(struct net_device *,struct ethtool_dump *,void *);int (*set_dump)(struct net_device *,struct ethtool_dump *); +int (*set_save_fcs)(struct net_device *,u32 ); + int (*get_save_fcs)(struct net_device *, u32 *); };#endif /* __KERNEL__ */
@@ -1029,6 +1031,9 @@ struct ethtool_ops {#define ETHTOOL_SET_DUMP 0x0000003e/* Set dump settings */ #define ETHTOOL_GET_DUMP_FLAG 0x0000003f/* Get dump settings */ #define ETHTOOL_GET_DUMP_DATA 0x00000040/* Get dump data */ +#define ETHTOOL_GETRXFCS 0x00000041/* Get RX Save Frame Checksum */ +#define ETHTOOL_SETRXFCS 0x00000042/* Set RX Save Frame Checksum */ +/* compatibility with older code */ #define SPARC_ETH_GSET ETHTOOL_GSET
net/core/ethtool.c +38 -0
@@ -1927,6 +1927,38 @@ out:return ret; } +static int ethtool_get_rx_fcs (struct net_device *dev,void __user *useraddr) +{ +struct ethtool_value edata; +int rv =0 ; + +if (!dev->ethtool_ops->get_save_fcs) +return -EOPNOTSUPP ; + + rv = dev->ethtool_ops->get_save_fcs (dev, &edata.data); +if (rv <0 ) +return rv; + +if (copy_to_user (useraddr, &edata,sizeof (edata))) +return -EFAULT ; +return 0 ; +} + + +static int ethtool_set_rx_fcs (struct net_device *dev,void __user *useraddr) +{ +struct ethtool_value id; + +if (!dev->ethtool_ops->set_save_fcs) +return -EOPNOTSUPP ; + +if (copy_from_user (&id, useraddr,sizeof (id))) +return -EFAULT ; + +return dev->ethtool_ops->set_save_fcs (dev, id.data); +} + +/* The main entry point in this file. Called from net/core/dev.c */ int dev_ethtool (struct net *net,struct ifreq *ifr)
@@ -2152,6 +2184,12 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)case ETHTOOL_GET_DUMP_DATA : rc =ethtool_get_dump_data (dev, useraddr);break ; +case ETHTOOL_SETRXFCS : + rc =ethtool_set_rx_fcs (dev, useraddr); +break ; +case ETHTOOL_GETRXFCS : + rc =ethtool_get_rx_fcs (dev, useraddr); +break ;default : rc = -EOPNOTSUPP ; }
Signature · 1 line
1.7.3.4
RFC 2/2 e100: Support receiving Ethernet FCS.
In reply to [email protected]From: Ben Greear <[email protected]>
Helps when sniffing packets.
---
:100644 100644 e336c79... 80fcadf... M drivers/net/e100.c
drivers/net/e100.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 files changed, 36 insertions(+), 3 deletions(-)
drivers/net/e100.c +36 -3
@@ -587,6 +587,7 @@ struct nic { multicast_all = (1 <<2 ), wol_magic = (1 <<3 ), ich_10h_workaround = (1 <<4 ), + save_fcs = (1 <<5 ), } flags ____cacheline_aligned;enum mac mac;
@@ -1130,6 +1131,9 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb) config->promiscuous_mode =0x1 ;/* 1=on, 0=off */ } +if (nic->flags & save_fcs) + config->rx_crc_transfer =0x1 ;/* 1=save, 0=discard */ +if (nic->flags & multicast_all) config->multicast_all =0x1 ;/* 1=accept, 0=no */
@@ -1917,6 +1921,7 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,struct sk_buff *skb = rx->skb;struct rfd *rfd = (struct rfd *)skb->data;u16 rfd_status, actual_size; +u16 fcs_pad =0 ;if (unlikely (work_done && *work_done >= work_to_do))return -EAGAIN ;
@@ -1949,9 +1954,11 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx, }/* Get actual data size */ +if (nic->flags & save_fcs) + fcs_pad =4 ; actual_size =le16_to_cpu (rfd->actual_size) &0x3FFF ; -if (unlikely (actual_size >RFD_BUF_LEN -sizeof (struct rfd ))) - actual_size =RFD_BUF_LEN -sizeof (struct rfd ); +if (unlikely (actual_size >RFD_BUF_LEN + fcs_pad -sizeof (struct rfd ))) + actual_size =RFD_BUF_LEN + fcs_pad -sizeof (struct rfd );/* Get data */ pci_unmap_single(nic->pdev, rx->dma_addr,
@@ -1978,7 +1985,7 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,if (unlikely (!(rfd_status & cb_ok))) {/* Don't indicate if hardware indicates errors */ dev_kfree_skb_any (skb); - }else if (actual_size >ETH_DATA_LEN +VLAN_ETH_HLEN ) { + }else if (actual_size >ETH_DATA_LEN +VLAN_ETH_HLEN + fcs_pad) {/* Don't indicate oversized frames */ nic->rx_over_length_errors++;dev_kfree_skb_any (skb);
@@ -2370,6 +2377,30 @@ static int e100_set_settings(struct net_device *netdev, struct ethtool_cmd *cmd)return err; } +static int e100_set_save_fcs (struct net_device *netdev,u32 data) +{ +struct nic *nic =netdev_priv (netdev); +if (data) + nic->flags |= save_fcs; +else + nic->flags &= ~save_fcs; + +e100_exec_cb (nic,NULL , e100_configure); + +return 0 ; +} + +static int e100_get_save_fcs (struct net_device *netdev,u32 * data) +{ +struct nic *nic =netdev_priv (netdev); +if (nic->flags & save_fcs) + *data =1 ; +else + *data =0 ; + +return 0 ; +} +static void e100_get_drvinfo (struct net_device *netdev,struct ethtool_drvinfo *info) {
@@ -2689,6 +2720,8 @@ static const struct ethtool_ops e100_ethtool_ops = { .set_phys_id = e100_set_phys_id, .get_ethtool_stats = e100_get_ethtool_stats, .get_sset_count = e100_get_sset_count, + .set_save_fcs = e100_set_save_fcs, + .get_save_fcs = e100_get_save_fcs, };static int e100_do_ioctl (struct net_device *netdev,struct ifreq *ifr,int cmd)
Signature · 1 line
1.7.3.4
Re: [RFC 1/2] net: Support getting/setting RX-FCS in drivers.
In reply to [email protected]2011/6/17 <[email protected]>:
Quoted 8 lines
From: Ben Greear <[email protected]>
This will allow us to enable/disable having the Ethernet frame checksum appended to the skb. Enabling this is useful when sniffing packets.
In particular, this can be used to test logic that allows a NIC to receive all frames, even ones with bad checksums.
You want to silently run away from extending dev->features field? ;-)
Best Regards,
Michał Mirosław
Re: [RFC 1/2] net: Support getting/setting RX-FCS in drivers.
In reply to [email protected]Quoted 22 lines · On Thu, 2011-06-16 at 21:30 -0700, [email protected] wrote:
From: Ben Greear <[email protected]>
This will allow us to enable/disable having the Ethernet frame checksum appended to the skb. Enabling this is useful when sniffing packets.
In particular, this can be used to test logic that allows a NIC to receive all frames, even ones with bad checksums.
Signed-off-by Ben Greear <[email protected]>---
:100644 100644 439b173... e5e8747... Minclude/linux/ethtool.h
:100644 100644 fd14116... b36bac7... Mnet/core/ethtool.cinclude/linux/ethtool.h | 5 +++++ net/core/ethtool.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 0 deletions(-)include/linux/ethtool.h +0
-0
include/linux/ethtool.h struct ethtool_ops { · line 959
Quoted 5 lines
include/linux/ethtool.h +2
-0@@ -955,6 +955,8 @@ struct ethtool_ops {int (*get_dump_data)(struct net_device *,struct ethtool_dump *,void *);int (*set_dump)(struct net_device *,struct ethtool_dump *); +int (*set_save_fcs)(struct net_device *,u32 ); +int (*get_save_fcs)(struct net_device *,u32 *);
These need to be described in the kernel-doc.
Why do these function names use 'save_fcs' whereas the command names use 'RXFCS'?
Quoted 56 lines
include/linux/ethtool.h +3
-0};#endif /* __KERNEL__ */ @@ -1029,6 +1031,9 @@ struct ethtool_ops {#define ETHTOOL_SET_DUMP 0x0000003e/* Set dump settings */ #define ETHTOOL_GET_DUMP_FLAG 0x0000003f/* Get dump settings */ #define ETHTOOL_GET_DUMP_DATA 0x00000040/* Get dump data */ +#define ETHTOOL_GETRXFCS 0x00000041/* Get RX Save Frame Checksum */ +#define ETHTOOL_SETRXFCS 0x00000042/* Set RX Save Frame Checksum */ +/* compatibility with older code */ #define SPARC_ETH_GSET ETHTOOL_GSETnet/core/ethtool.c +32
-0@@ -1927,6 +1927,38 @@ out:return ret; } +static int ethtool_get_rx_fcs (struct net_device *dev,void __user *useraddr) +{ +struct ethtool_value edata; +int rv =0 ; + +if (!dev->ethtool_ops->get_save_fcs) +return -EOPNOTSUPP ; + + rv = dev->ethtool_ops->get_save_fcs (dev, &edata.data); +if (rv <0 ) +return rv; + +if (copy_to_user (useraddr, &edata,sizeof (edata))) +return -EFAULT ; +return 0 ; +} + + +static int ethtool_set_rx_fcs (struct net_device *dev,void __user *useraddr) +{ +struct ethtool_value id; + +if (!dev->ethtool_ops->set_save_fcs) +return -EOPNOTSUPP ; + +if (copy_from_user (&id, useraddr,sizeof (id))) +return -EFAULT ; + +return dev->ethtool_ops->set_save_fcs (dev, id.data); +} + +/* The main entry point in this file. Called from net/core/dev.c */ int dev_ethtool (struct net *net,struct ifreq *ifr)
net/core/ethtool.c int dev_ethtool(struct net *net, struct ifreq *ifr) · line 2192
Quoted 9 lines
net/core/ethtool.c +6
-0@@ -2152,6 +2184,12 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)case ETHTOOL_GET_DUMP_DATA : rc =ethtool_get_dump_data (dev, useraddr);break ; +case ETHTOOL_SETRXFCS : + rc =ethtool_set_rx_fcs (dev, useraddr); +break ; +case ETHTOOL_GETRXFCS : + rc =ethtool_get_rx_fcs (dev, useraddr); +break ;
You can use ethtool_{get,set}_value() rather than adding new trivial functions.
And as Michal says, this could reasonably be a feature not an entirely separate flag. I'm not sure it's that important to have debugging flags in features, but I also don't want to have 2 commands per flag...
Ben.
Quoted 3 lines
net/core/ethtool.c +0
-0default : rc = -EOPNOTSUPP ; }
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.
Re: [RFC 1/2] net: Support getting/setting RX-FCS in drivers.
Quoted 88 lines · Ben Hutchings
Quoted 22 lines · On Thu, 2011-06-16 at 21:30 -0700, [email protected] wrote:
From: Ben Greear<[email protected]>
This will allow us to enable/disable having the Ethernet frame checksum appended to the skb. Enabling this is useful when sniffing packets.
In particular, this can be used to test logic that allows a NIC to receive all frames, even ones with bad checksums.
Signed-off-by Ben Greear<[email protected]>---
:100644 100644 439b173... e5e8747... Minclude/linux/ethtool.h
:100644 100644 fd14116... b36bac7... Mnet/core/ethtool.cinclude/linux/ethtool.h | 5 +++++ net/core/ethtool.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 0 deletions(-)include/linux/ethtool.h +0
-0include/linux/ethtool.h struct ethtool_ops { · line 959
Quoted 5 lines
include/linux/ethtool.h +2
-0@@ -955,6 +955,8 @@ struct ethtool_ops {int (*get_dump_data)(struct net_device *,struct ethtool_dump *,void *);int (*set_dump)(struct net_device *,struct ethtool_dump *); +int (*set_save_fcs)(struct net_device *,u32 ); +int (*get_save_fcs)(struct net_device *,u32 *);These need to be described in the kernel-doc.
Why do these function names use '
save_fcs' whereas the command names use 'RXFCS'?Quoted 54 lines
include/linux/ethtool.h +3
-0};#endif /* __KERNEL__ */ @@ -1029,6 +1031,9 @@ struct ethtool_ops {#define ETHTOOL_SET_DUMP 0x0000003e/* Set dump settings */ #define ETHTOOL_GET_DUMP_FLAG 0x0000003f/* Get dump settings */ #define ETHTOOL_GET_DUMP_DATA 0x00000040/* Get dump data */ +#define ETHTOOL_GETRXFCS 0x00000041/* Get RX Save Frame Checksum */ +#define ETHTOOL_SETRXFCS 0x00000042/* Set RX Save Frame Checksum */ +/* compatibility with older code */ #define SPARC_ETH_GSET ETHTOOL_GSETnet/core/ethtool.c +32
-0@@ -1927,6 +1927,38 @@ out:return ret; } +static int ethtool_get_rx_fcs (struct net_device *dev,void __user *useraddr) +{ +struct ethtool_value edata; +int rv =0 ; + +if (!dev->ethtool_ops->get_save_fcs) +return -EOPNOTSUPP ; + + rv = dev->ethtool_ops->get_save_fcs (dev,&edata.data); +if (rv<0 ) +return rv; + +if (copy_to_user (useraddr,&edata,sizeof (edata))) +return -EFAULT ; +return 0 ; +} + + +static int ethtool_set_rx_fcs (struct net_device *dev,void __user *useraddr) +{ +struct ethtool_value id; + +if (!dev->ethtool_ops->set_save_fcs) +return -EOPNOTSUPP ; + +if (copy_from_user (&id, useraddr,sizeof (id))) +return -EFAULT ; + +return dev->ethtool_ops->set_save_fcs (dev, id.data); +} + +/* The main entry point in this file. Called from net/core/dev.c */
Quoted 14 lines
net/core/ethtool.c int dev_ethtool(struct net *net, struct ifreq *ifr) · line 2192
Quoted 11 lines
net/core/ethtool.c +6
-0int dev_ethtool (struct net *net,struct ifreq *ifr)@@ -2152,6 +2184,12 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)case ETHTOOL_GET_DUMP_DATA : rc =ethtool_get_dump_data (dev, useraddr);break ; +case ETHTOOL_SETRXFCS : + rc =ethtool_set_rx_fcs (dev, useraddr); +break ; +case ETHTOOL_GETRXFCS : + rc =ethtool_get_rx_fcs (dev, useraddr); +break ;You can use ethtool_{get,set}_value() rather than adding new trivial functions.
I'll look at that.
Quoted 4 lines
And as Michal says, this could reasonably be a feature not an entirely separate flag. I'm not sure it's that important to have debugging flags in features, but I also don't want to have 2 commands per flag...
I'm not sure it really counts as a feature, and I've no desire to tangle with the effort to extend features beyond 32 bits. Maybe we could have a new ethtool command that took a struct with two args, so we can "set flag-foo val" instead of 'enable-flag-foo' and 'disable-flag-foo'?
That should be only one additional method for the drivers to implement, and can be used for the other patches I have planned as well.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Re: [RFC 1/2] net: Support getting/setting RX-FCS in drivers.
Quoted 10 lines · Ben Greear
Quoted 9 lines · Ben Hutchings
Quoted 8 lines · On Thu, 2011-06-16 at 21:30 -0700, [email protected] wrote:
From: Ben Greear<[email protected]>
This will allow us to enable/disable having the Ethernet frame checksum appended to the skb. Enabling this is useful when sniffing packets.
In particular, this can be used to test logic that allows a NIC to receive all frames, even ones with bad checksums.
[...]
Quoted 6 lines
Quoted 3 lines
And as Michal says, this could reasonably be a feature not an entirely separate flag. I'm not sure it's that important to have debugging flags in features, but I also don't want to have 2 commands per flag...
I'm not sure it really counts as a feature, and I've no desire to tangle with the effort to extend features beyond 32 bits.
There are several people wanting to add new flags, so between you I'm sure you can manage it.
Quoted 6 lines
Maybe we could have a new
ethtool command that took a struct with two args, so we can "set flag-foo val" instead of 'enable-flag-foo' and 'disable-flag-foo'?That should be only one additional method for the drivers to implement, and can be used for the other patches I have planned as well.
Whereas implementing an extra feature toggle now requires zero extra methods.
Ben.
Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Not speaking for my employer; that's the marketing department's job. They asked us to note that Solarflare product names are trademarked.