Skip to contentSkip to conversation

netdev_ops

PATCH In review Matthew Wilcox 5 participants 15 messages Jul 8, 2003 – Jul 14, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netdev_ops

After a conversation with acme, I realised that ethtool_ops is far too narrow scope. What we need are netdev_ops. This patch renames the ethtool_ops to netdev_ops and fixes some other minor flaws:

- add _len() ops for operations which previously had to kmalloc their own memory.
- move the netdev_ops from ethtool.h to netdevice.h
- makes some ops generic as requested by Jeff Garzik.

I think netdev_ops is still a little too ethtool-specific; something I'd like to do is convert the parameters to be a little less ethtool-related. For example, instead of ->get_drvinfo, I'd like to see ethtool_get_drvinfo() call several methods and fill in all the data that way.

But let's see what everyone thinks of this patch first ...

Index: include/linux/ethtool.h
===================================================================
RCS file: /var/cvs/linux-2.5/include/linux/ethtool.h,v retrieving revision 1.5

linux/ethtool.h +3 -2
diff -u -p -r1.5 ethtool.h
@@ -12,6 +12,7 @@
 #ifndef _LINUX_ETHTOOL_H
 #define _LINUX_ETHTOOL_H
 
+#include <linux/types.h>
 
 /* This should work for both 32 and 64 bit userland. */
 struct ethtool_cmd {
@@ -97,7 +98,7 @@ struct ethtool_coalesce {
 	u32	rx_max_coalesced_frames;
 
 	/* Same as above two parameters, except that these values
-	 * apply while an IRQ is being services by the host.  Not
+	 * apply while an IRQ is being serviced by the host.  Not
 	 * all cards support this feature and the values are ignored
 	 * in that case.
 	 */
@@ -119,7 +120,7 @@ struct ethtool_coalesce {
 	u32	tx_max_coalesced_frames;
 
 	/* Same as above two parameters, except that these values
-	 * apply while an IRQ is being services by the host.  Not
+	 * apply while an IRQ is being serviced by the host.  Not
 	 * all cards support this feature and the values are ignored
 	 * in that case.
 	 */

Index: include/linux/netdevice.h
===================================================================
RCS file: /var/cvs/linux-2.5/include/linux/netdevice.h,v retrieving revision 1.14

linux/netdevice.h +100 -0

124 lines not on this page · raw message

Index: net/socket.c
===================================================================
RCS file: /var/cvs/linux-2.5/net/socket.c,v
retrieving revision 1.21

socket.c +0 -4
diff -u -p -r1.21 socket.c
@@ -74,7 +74,6 @@
 #include <linux/poll.h>
 #include <linux/cache.h>
 #include <linux/module.h>
-#include <linux/highmem.h>
 #include <linux/divert.h>
 #include <linux/mount.h>
 #include <linux/security.h>
@@ -1916,10 +1915,7 @@ int sock_unregister(int family)
 
 
 extern void sk_init(void);
-
-#ifdef CONFIG_WAN_ROUTER
 extern void wanrouter_init(void);
-#endif
 
 void __init sock_init(void)
 {

Index: net/core/Makefile
===================================================================
RCS file: /var/cvs/linux-2.5/net/core/Makefile,v
retrieving revision 1.9

core/Makefile +2 -2
diff -u -p -r1.9 Makefile
@@ -10,8 +10,8 @@ obj-y += sysctl_net_core.o
 endif
 endif
 
-obj-$(CONFIG_NET) += flow.o dev.o net-sysfs.o dev_mcast.o dst.o neighbour.o \
-		     rtnetlink.o utils.o link_watch.o filter.o
+obj-$(CONFIG_NET) += flow.o dev.o ethtool.o net-sysfs.o dev_mcast.o dst.o \
+			neighbour.o rtnetlink.o utils.o link_watch.o filter.o
 
 obj-$(CONFIG_NETFILTER) += netfilter.o
 obj-$(CONFIG_NET_DIVERT) += dv.o

Index: net/core/dev.c
===================================================================
RCS file: /var/cvs/linux-2.5/net/core/dev.c,v
retrieving revision 1.22

core/dev.c +44 -2

70 lines not on this page · raw message

Index: net/core/ethtool.c
===================================================================
RCS file: net/core/ethtool.c

core/ethtool.c new file +546 -0

546 lines not on this page · raw message

Index: drivers/net/tg3.c
===================================================================
RCS file: /var/cvs/linux-2.5/drivers/net/tg3.c,v
retrieving revision 1.16

net/tg3.c +250 -342

670 lines not on this page · raw message

Signature · 3 lines
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
#1 lore raw
Quoted 15 lines · Matthew Wilcox

After a conversation with acme, I realised that ethtool_ops is far too narrow scope. What we need are netdev_ops. This patch renames the ethtool_ops to netdev_ops and fixes some other minor flaws:

- add _len() ops for operations which previously had to kmalloc their own memory.
- move the netdev_ops from ethtool.h to netdevice.h
- makes some ops generic as requested by Jeff Garzik.

I think netdev_ops is still a little too ethtool-specific; something I'd like to do is convert the parameters to be a little less ethtool-related. For example, instead of ->get_drvinfo, I'd like to see ethtool_get_drvinfo() call several methods and fill in all the data that way.

Quoted 4 lines

But let's see what everyone thinks of this patch first ...

+ * Each operation is passed a &struct net_device as its first parameter.

Some of these are missing their netdevice arg?

Quoted 7 lines
linux/netdevice.h +4 -0
+	int	(*get_regs_len)(struct ethtool_regs *);
 
+	int	(*self_test_len)(struct ethtool_test *);
 
+	int	(*get_strings_len)(struct ethtool_gstrings *);
 
+	int	(*get_stats_len)(struct ethtool_stats *);
Signature · 3 lines
Ben Greear <[email protected]>       <Ben_Greear AT excite.com>
President of Candela Technologies Inc      http://www.candelatech.com
ScryMUD:  http://scry.wanfear.com     http://scry.wanfear.com/~greear
#2 lore raw
Quoted 5 lines · Ben Greear

Some of these are missing their netdevice arg?

linux/netdevice.h struct packet_type · line 583

Quoted 4 lines
linux/netdevice.h +4 -0
+	int	(*get_regs_len)(struct ethtool_regs *);
+	int	(*self_test_len)(struct ethtool_test *);
+	int	(*get_strings_len)(struct ethtool_gstrings *);
+	int	(*get_stats_len)(struct ethtool_stats *);

Well, they don't actually need it -- these are more attributes of the underlying driver than they are of any individual network device. I suspect at least one of them isn't needed, and I'm sure the e1000 guys are about to tell me which one ;-)

Signature · 3 lines
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
#3 lore raw

From: Matthew Wilcox <[email protected]>
Date: Tue, 8 Jul 2003 22:25:51 +0100

   On Tue, Jul 08, 2003 at 01:44:32PM -0700, Ben Greear wrote:
   > Some of these are missing their netdevice arg?
   > >+	int	(*get_regs_len)(struct ethtool_regs *);
   > >+	int	(*self_test_len)(struct ethtool_test *);
   > >+	int	(*get_strings_len)(struct ethtool_gstrings *);
   > >+	int	(*get_stats_len)(struct ethtool_stats *);

Well, they don't actually need it -- these are more attributes of the underlying driver than they are of any individual network device.

Not true, at least for the regs len different variants of the same chip can have a different sized register set.

#4 lore raw

Changes since yesterday's patch:

- Make all methods take the struct net_device as suggested by Ben Greear.
- Rename self_test_len() and get_stats_len() to *_count() to reflect that they return a count of elements, not a byte length.
- Related bugfixes.
- Remove the get_strings_len() method; we now infer the length from either self_test_count() or get_stats_count().
- memset() the drvinfo struct so it doesn't leak information from the kernel stack (existing bug in tg3).
- Clamp regs.len in ethtool.c rather than in the driver.
- Pass the stringset value to get_strings() rather than a pointer to the whole ethtool_gstrings struct.

I have a question about the error return values in ethtool_get_strings(). Are -EOPNOTSUPP and -EINVAL the right ones to use in the case statement? Or should I perhaps be using -ENOSYS instead of EINVAL? I've noticed drepper tends to prefer this for unimplemented subops. Since this is an ioctl(), perhaps I should be using -ENOTTY instead ;-)

Anyway, further comments welcomed.

Index: include/linux/ethtool.h
===================================================================
RCS file: /var/cvs/linux-2.5/include/linux/ethtool.h,v retrieving revision 1.5

linux/ethtool.h +3 -2
diff -u -p -r1.5 ethtool.h
@@ -12,6 +12,7 @@
 #ifndef _LINUX_ETHTOOL_H
 #define _LINUX_ETHTOOL_H
 
+#include <linux/types.h>
 
 /* This should work for both 32 and 64 bit userland. */
 struct ethtool_cmd {
@@ -97,7 +98,7 @@ struct ethtool_coalesce {
 	u32	rx_max_coalesced_frames;
 
 	/* Same as above two parameters, except that these values
-	 * apply while an IRQ is being services by the host.  Not
+	 * apply while an IRQ is being serviced by the host.  Not
 	 * all cards support this feature and the values are ignored
 	 * in that case.
 	 */
@@ -119,7 +120,7 @@ struct ethtool_coalesce {
 	u32	tx_max_coalesced_frames;
 
 	/* Same as above two parameters, except that these values
-	 * apply while an IRQ is being services by the host.  Not
+	 * apply while an IRQ is being serviced by the host.  Not
 	 * all cards support this feature and the values are ignored
 	 * in that case.
 	 */

Index: include/linux/netdevice.h
===================================================================
RCS file: /var/cvs/linux-2.5/include/linux/netdevice.h,v retrieving revision 1.14

linux/netdevice.h +98 -0

122 lines not on this page · raw message

Index: net/socket.c
===================================================================
RCS file: /var/cvs/linux-2.5/net/socket.c,v
retrieving revision 1.21

socket.c +0 -4
diff -u -p -r1.21 socket.c
@@ -74,7 +74,6 @@
 #include <linux/poll.h>
 #include <linux/cache.h>
 #include <linux/module.h>
-#include <linux/highmem.h>
 #include <linux/divert.h>
 #include <linux/mount.h>
 #include <linux/security.h>
@@ -1916,10 +1915,7 @@ int sock_unregister(int family)
 
 
 extern void sk_init(void);
-
-#ifdef CONFIG_WAN_ROUTER
 extern void wanrouter_init(void);
-#endif
 
 void __init sock_init(void)
 {

Index: net/core/Makefile
===================================================================
RCS file: /var/cvs/linux-2.5/net/core/Makefile,v
retrieving revision 1.9

core/Makefile +2 -2
diff -u -p -r1.9 Makefile
@@ -10,8 +10,8 @@ obj-y += sysctl_net_core.o
 endif
 endif
 
-obj-$(CONFIG_NET) += flow.o dev.o net-sysfs.o dev_mcast.o dst.o neighbour.o \
-		     rtnetlink.o utils.o link_watch.o filter.o
+obj-$(CONFIG_NET) += flow.o dev.o ethtool.o net-sysfs.o dev_mcast.o dst.o \
+			neighbour.o rtnetlink.o utils.o link_watch.o filter.o
 
 obj-$(CONFIG_NETFILTER) += netfilter.o
 obj-$(CONFIG_NET_DIVERT) += dv.o

Index: net/core/dev.c
===================================================================
RCS file: /var/cvs/linux-2.5/net/core/dev.c,v
retrieving revision 1.22

core/dev.c +44 -2

70 lines not on this page · raw message

Index: net/core/ethtool.c
===================================================================
RCS file: net/core/ethtool.c

core/ethtool.c new file +585 -0

585 lines not on this page · raw message

Index: drivers/net/tg3.c
===================================================================
RCS file: /var/cvs/linux-2.5/drivers/net/tg3.c,v
retrieving revision 1.16

net/tg3.c +242 -342

662 lines not on this page · raw message

Signature · 3 lines
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
#5 lore raw
Quoted 14 lines · Matthew Wilcox

Changes since yesterday's patch:

- Make all methods take the struct net_device as suggested by Ben Greear.
- Rename self_test_len() and get_stats_len() to *_count() to reflect that they return a count of elements, not a byte length.
- Related bugfixes.
- Remove the get_strings_len() method; we now infer the length from either self_test_count() or get_stats_count().
- memset() the drvinfo struct so it doesn't leak information from the kernel stack (existing bug in tg3).
- Clamp regs.len in ethtool.c rather than in the driver.
- Pass the stringset value to get_strings() rather than a pointer to the whole ethtool_gstrings struct.

Quoted 5 lines

I have a question about the error return values in ethtool_get_strings(). Are -EOPNOTSUPP and -EINVAL the right ones to use in the case statement? Or should I perhaps be using -ENOSYS instead of EINVAL? I've noticed drepper tends to prefer this for unimplemented subops. Since this is an ioctl(), perhaps I should be using -ENOTTY instead ;-)

Considering any number of things may change in the future, what do you think of adding a global 'nettool-version' method. That could allow user-space code to take appropriate action if something ever changes in a non-compatible way....

Also, for the strings (labels) passed back to user space, is there any documentation for suggested values for these strings? Even though we can't be completely type-safe, if there were suggested values in a comment in the code, it could help a great deal for any code trying to parse them for multiple different drivers/nics.

Ben

Signature · 3 lines
Ben Greear <[email protected]>       <Ben_Greear AT excite.com>
President of Candela Technologies Inc      http://www.candelatech.com
ScryMUD:  http://scry.wanfear.com     http://scry.wanfear.com/~greear
#6 lore raw
Quoted 4 lines · Ben Greear

Considering any number of things may change in the future, what do you think of adding a global 'nettool-version' method. That could allow user-space code to take appropriate action if something ever changes in a non-compatible way....

This patch makes only user-invisible changes. I'm trying to establish a base for further cleanups (eg, acme wants to look at unifying the wireless ops and the existing net_device function pointers into netdev_ops). I don't really have a position on adding a nettool-version ioctl or whatever, but I'm not sure it would make sense to have that as a netdev method.

Quoted 5 lines

Also, for the strings (labels) passed back to user space, is there any documentation for suggested values for these strings? Even though we can't be completely type-safe, if there were suggested values in a comment in the code, it could help a great deal for any code trying to parse them for multiple different drivers/nics.

I didn't see any documentation; I just read the code. The only drivers I noticed supporting the GSTRINGS subcommand are 8139cp, 8139too, e100 and e1000.

Signature · 3 lines
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
#7 lore raw
In reply to Ben Greear
Quoted 5 lines · Ben Greear

Also, for the strings (labels) passed back to user space, is there any documentation for suggested values for these strings? Even though we can't be completely type-safe, if there were suggested values in a comment in the code, it could help a great deal for any code trying to parse them for multiple different drivers/nics.

The strings represent NIC-specific attributes.

Jeff

#8 lore raw
Quoted 10 lines · Jeff Garzik
Quoted 5 lines · Ben Greear

Also, for the strings (labels) passed back to user space, is there any documentation for suggested values for these strings? Even though we can't be completely type-safe, if there were suggested values in a comment in the code, it could help a great deal for any code trying to parse them for multiple different drivers/nics.

The strings represent NIC-specific attributes.

Yes, but surely there is some comonality? I'm not asking for something set in stone, but just some general guidelines. However, I don't feel too strongly about this, so if it is not worth the time/effort, then I'll still be happy :)

Ben

Quoted 4 lines

Jeff

Signature · 3 lines
Ben Greear <[email protected]>       <Ben_Greear AT excite.com>
President of Candela Technologies Inc      http://www.candelatech.com
ScryMUD:  http://scry.wanfear.com     http://scry.wanfear.com/~greear
#9 lore raw
In reply to Matthew Wilcox

Comments:

1) The _ops are either too limited in scope, or too wide in scope.

We have a bunch of function pointers in struct net_device. We are adding a bunch more func ptrs in a new struct foo_ops.

If it is called ethtool_ops, I can support the addition of

	struct ethtool_ops *etops;

to struct net_device.

However, if we call it netdev_ops, the structure's name no longer describes its purpose. If we call it netdev_ops, we should move ALL the function pointers in struct net_device into netdev_ops as well, and deal with the associated driver breakage.

So, either change the name back to ethtool_ops, or go all the way. The current name to me implies a job half-done.

Personally, I would prefer the more radical "move all funcptrs into netdev_ops". This is closer to other Linux kernel APIs.

2) Yes, we do want a feature macro for this.

David, I respectfully disagree with "no back compat" type arguments. Besides h/w vendors who want to support distros currently in the field (read: not the latest kernel), _I_ am personally impacted by API divergence. As I have said (and proven) many times, I personally spend time keeping the more popular ethernet drivers in sync, 2.4 <-> 2.5. Each time a 2.5-specific change is added that is not easily massaged by a back compat macro, it costs me time. Hand-applying patches is not fun.

2.a) There is established precedent: grep for HAVE_xxx in netdevice.h and look at the ton of hits you get.

2.b) If #1 is decided to be ethtool_ops, create HAVE_ETHTOOL_OPS macro

2.c) If #2 is decided to be netdev_ops, and all func ptrs are moved into netdev_ops struct, then create the macro
SET_NETDEV_OPS(dev, ops)

This allows full back compat, without ugliness in mainline tree.

3) The func ptrs _count() are totally bogus. We have an unconditional indirect reference to a function call which does nothing but return a driver constant.

I personally think that having ethtool_ops members manually calling the ->get_drvinfo hook is a _lot_ cleaner than 10,000 foo_count hooks.

3.a) Further, we will inevitably be adding more counts in the future. If we wanted to be truly expandable, and you really don't like the counts being in struct ethtool_gdrvinfo, then create a struct ethtool_counts that puts all the constants in one place.

4) I don't see why ethtool.h suddenly needs to include linux/types.h, when it hasn't needed it in all this time until now.

5) net/socket.c changes appear unrelated to this patch.

6) (low prio) Add documentation to Documentation/networking/netdevices.txt. Most importantly, this documents locking/context.

7) (low prio) All that similar code in net/core/ethtool.c can be template-ized with a macro, IMO. Something like DEF_ETHTOOL_GOP(get_coalesce, ETHTOOL_GCOALESCE, ethtool_coalesce); DEF_ETHTOOL_SOP(set_coalesce, ethtool_coalesce);
(and templates for the ops that use edata)

8) (security) get-eeprom op needs to check that offset+len is not invalid, and does not wrap.

9) phys_id op should return an error, for consistency if nothing else. It's simple for driver authors to unconditionally return 0 if their code has no failure cases, and it's a slow path so adding the return in the driver code is no big deal.

10) (low prio) since it's a slow path, what about replacing the switch statement in dev_ethtool() with a lookup table? All the ethtool commands are low numbers. If you do this, I would suggest using the gcc array initializer syntax:
[ETHTOOL_GCOALESCE, ethtool_get_coalesce]

All the ethtool ops have the same prototype, after all.

Comments?

#10 lore raw
Quoted 16 lines · Jeff Garzik

Comments:

1) The _ops are either too limited in scope, or too wide in scope.

We have a bunch of function pointers in struct net_device. We are adding a bunch more func ptrs in a new struct foo_ops.

If it is called ethtool_ops, I can support the addition of

	struct ethtool_ops *etops;

to struct net_device.

However, if we call it netdev_ops, the structure's name no longer describes its purpose. If we call it netdev_ops, we should move ALL the function pointers in struct net_device into netdev_ops as well, and deal with the associated driver breakage.

Quoted 5 lines

So, either change the name back to ethtool_ops, or go all the way. The current name to me implies a job half-done.

Personally, I would prefer the more radical "move all funcptrs into netdev_ops". This is closer to other Linux kernel APIs.

Either way, I'd vote for netdev_ops, because I want to add generic 'ioctls' that work on struct net_device, not necessarily just ethernet devices. However, it's a minor issue since the code will work regardless.

Quoted 11 lines

3) The func ptrs _count() are totally bogus. We have an unconditional indirect reference to a function call which does nothing but return a driver constant.

I personally think that having ethtool_ops members manually calling the ->get_drvinfo hook is a _lot_ cleaner than 10,000 foo_count hooks.

3.a) Further, we will inevitably be adding more counts in the future. If we wanted to be truly expandable, and you really don't like the counts being in struct ethtool_gdrvinfo, then create a struct ethtool_counts that puts all the constants in one place.

Suppose we do this, how will we make a user-space app that tries to read this be backwards/forwards compatible? This is one of the reasons I was hoping for some versioning information that could be probed at run-time from user-space. Could bump the version each time we change something that is difficult to detect in user-space. (ie, adding a new ethtool-cmd is easy to detect because we'll get EINVAL or something when it's not there, and a success when it is, but getting a different sized struct, or a struct who's members have changed their meaning, will be more difficult to detect I believe.)

Programs that do not wish to deal with the cruft of versioning can just ignore it, but ones that are designed to be very robust can do the extra work to deal with the different versions.

Quoted 4 lines

4) I don't see why ethtool.h suddenly needs to include linux/types.h, when it hasn't needed it in all this time until now.

If we're changing lots of stuff...it would be nice to change the u32 etc to something that user-space can easily handle, as ethtool.h is (for better or worse) being included from user-space. Minor issue again as it can be dealt with via type-defs etc.

Thanks,
Ben

Signature · 3 lines
Ben Greear <[email protected]>       <Ben_Greear AT excite.com>
President of Candela Technologies Inc      http://www.candelatech.com
ScryMUD:  http://scry.wanfear.com     http://scry.wanfear.com/~greear
#11 lore raw
Quoted 7 lines · Ben Greear
Quoted 7 lines

3) The func ptrs _count() are totally bogus. We have an unconditional indirect reference to a function call which does nothing but return a driver constant.

I personally think that having ethtool_ops members manually calling the ->get_drvinfo hook is a _lot_ cleaner than 10,000 foo_count hooks.

Quoted 7 lines
Quoted 4 lines

3.a) Further, we will inevitably be adding more counts in the future. If we wanted to be truly expandable, and you really don't like the counts being in struct ethtool_gdrvinfo, then create a struct ethtool_counts that puts all the constants in one place.

Suppose we do this, how will we make a user-space app that tries to read this be backwards/forwards compatible?

It's trivial to return the existing values in the gdrvinfo struct in addition to a new ethtool_count struct. Full ABI compat is maintained.

Quoted 7 lines
Quoted 2 lines

4) I don't see why ethtool.h suddenly needs to include linux/types.h, when it hasn't needed it in all this time until now.

If we're changing lots of stuff...it would be nice to change the u32 etc to something that user-space can easily handle, as ethtool.h is (for better or worse) being included from user-space. Minor issue again as it can be dealt with via type-defs etc.

ethtool.h isn't included in the "lots of stuff" that is changing :) As you see from Matthew's patch, all changes to ethtool.h are non-essential.

Regardless, addressing your point, I consider ethtool.h a kernel-internal header, that's why it uses internal kernel types. Anybody who copies it to userspace must deal with that. It is _not_ intended to be #included directly from userspace. ethtool (the userland program) purposefully does its own typedefs and stuff.

Jeff

#13 lore raw
In reply to Jeff Garzik
Quoted 1 line · Jeff Garzik

1) The _ops are either too limited in scope, or too wide in scope.

Couldn't agree more. I blame acme -- he wants me to push it to be much wider in scope. Let's push _all_ the function pointers into netdev_ops.

But this is a mere step 1. I don't have enough network-related clout to do everything in one fell swoop.

Quoted 5 lines

2.c) If #2 is decided to be netdev_ops, and all func ptrs are moved into netdev_ops struct, then create the macro
SET_NETDEV_OPS(dev, ops)

This allows full back compat, without ugliness in mainline tree.

Yes, that was my preferred approach.

Quoted 6 lines

3) The func ptrs _count() are totally bogus. We have an unconditional indirect reference to a function call which does nothing but return a driver constant.

I personally think that having ethtool_ops members manually calling the ->get_drvinfo hook is a _lot_ cleaner than 10,000 foo_count hooks.

Disagree. I'd like to completely get rid of the ->get_drvinfo hook and have each hook return one thing. DaveM claims that these things are not always constants, and I believe him -- it's entirely possible different revs of a chip (with the same driver) may have more or fewer registers to return, for example.

We might want to put these counts directly in the net_device itself and eliminate the function calls. That would make sense.

Quoted 2 lines

4) I don't see why ethtool.h suddenly needs to include linux/types.h, when it hasn't needed it in all this time until now.

Otherwise you have to include <linux/types.h> before you include <linux/ethtool.h> which sucks. No relying on other people to do your inclusions for you ;-)

Quoted 1 line

5) net/socket.c changes appear unrelated to this patch.

You're right, they just happen to be in that tree.

Quoted 3 lines

6) (low prio) Add documentation to Documentation/networking/netdevices.txt. Most importantly, this documents locking/context.

An excellent idea.

Quoted 5 lines

7) (low prio) All that similar code in net/core/ethtool.c can be template-ized with a macro, IMO. Something like DEF_ETHTOOL_GOP(get_coalesce, ETHTOOL_GCOALESCE, ethtool_coalesce); DEF_ETHTOOL_SOP(set_coalesce, ethtool_coalesce);
(and templates for the ops that use edata)

Maybe. I'm not a fan of templated ops as it makes it harder to grep.

Quoted 2 lines

8) (security) get-eeprom op needs to check that offset+len is not invalid, and does not wrap.

Good idea, I'll add that check now.

Quoted 4 lines

9) phys_id op should return an error, for consistency if nothing else. It's simple for driver authors to unconditionally return 0 if their code has no failure cases, and it's a slow path so adding the return in the driver code is no big deal.

OK, ditto.

Quoted 7 lines

10) (low prio) since it's a slow path, what about replacing the switch statement in dev_ethtool() with a lookup table? All the ethtool commands are low numbers. If you do this, I would suggest using the gcc array initializer syntax:
[ETHTOOL_GCOALESCE, ethtool_get_coalesce]

All the ethtool ops have the same prototype, after all.

Well, they don't have quite the same prototype ... that's part of the point -- get the type safety going as early as possible.

Signature · 3 lines
"It's not Hollywood.  War is real, war is primarily not about defeat or
victory, it is about death.  I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
#12 lore raw
In reply to Jeff Garzik
Quoted 5 lines · Jeff Garzik

Regardless, addressing your point, I consider ethtool.h a kernel-internal header, that's why it uses internal kernel types. Anybody who copies it to userspace must deal with that. It is _not_ intended to be #included directly from userspace. ethtool (the userland program) purposefully does its own typedefs and stuff.

Any particular reason to not include it directly? It seems no more likely to cause problems than to use some potentially out-of-date copy in user-space. (And it might make the compile slightly tougher if you are distributing primarily as source.)

Ben

Signature · 3 lines
Ben Greear <[email protected]>       <Ben_Greear AT excite.com>
President of Candela Technologies Inc      http://www.candelatech.com
ScryMUD:  http://scry.wanfear.com     http://scry.wanfear.com/~greear
#14 lore raw
In reply to Matthew Wilcox

Em Fri, Jul 11, 2003 at 09:04:23PM +0100, Matthew Wilcox escreveu:

Quoted 5 lines · Jeff Garzik
Quoted 1 line

1) The _ops are either too limited in scope, or too wide in scope.

Couldn't agree more. I blame acme -- he wants me to push it to be much wider in scope. Let's push _all_ the function pointers into netdev_ops.

Hey, it was just a brainstorm session ;) Anyway, I'm heavily backlogged as I'm on a business trip for several days already, I'll try to read all this thread when I'm back home 8)

- Arnaldo