net/ethtool: Add support for the ethtool feature to flash firmware image from a specified file.
Subsystems (3)
PATCH 1/1 net/ethtool: Add support for the ethtool feature to flash firmware image from a specified file.
This patch adds support to flash a firmware image to a device using ethtool. The driver gets the filename of the firmware image and flashes the image using the request firmware path.
The region "on the chip" to be flashed can be specified by an option. It is upto the device driver to enumerate the region number passed by ethtool, to the region to be flashed.
The default behavior is to flash all the regions on the chip.
--- include/linux/ethtool.h | 14 ++++++++++++++ net/core/ethtool.c | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-)
include/linux/ethtool.h +14 -0
@@ -362,6 +362,18 @@ struct ethtool_rxnfc {__u32 rule_locs[0 ]; }; +#define ETHTOOL_FLASH_MAX_FILENAME 128 +enum ethtool_flash_op_type { +ETHTOOL_FLASH_ALL_REGIONS =0 , +}; + +/* for passing firmware flashing related parameters */ +struct ethtool_flash { +__u32 cmd; +__u32 region; +char data[ETHTOOL_FLASH_MAX_FILENAME ]; +}; +#ifdef __KERNEL__struct net_device ;
@@ -489,6 +501,7 @@ struct ethtool_ops {int (*get_stats_count)(struct net_device *);/* use get_sset_count */ int (*get_rxnfc)(struct net_device *,struct ethtool_rxnfc *,void *);int (*set_rxnfc)(struct net_device *,struct ethtool_rxnfc *); + int (*flash_device)(struct net_device *, struct ethtool_flash *); };#endif /* __KERNEL__ */
@@ -545,6 +558,7 @@ struct ethtool_ops {#define ETHTOOL_GRXCLSRLALL 0x00000030/* Get all RX classification rule */ #define ETHTOOL_SRXCLSRLDEL 0x00000031/* Delete RX classification rule */ #define ETHTOOL_SRXCLSRLINS 0x00000032/* Insert RX classification rule */ +#define ETHTOOL_FLASHDEV 0x00000033/* Flash firmware to device */ /* compatibility with older code */ #define SPARC_ETH_GSET ETHTOOL_GSET
net/core/ethtool.c +16 -0
@@ -898,6 +898,19 @@ static int ethtool_set_value(struct net_device *dev, char __user *useraddr,return actor (dev, edata.data); } +static int ethtool_flash_device (struct net_device *dev,char __user *useraddr) +{ +struct ethtool_flash efl; + +if (copy_from_user (&efl, useraddr,sizeof (efl))) +return -EFAULT ; + +if (!dev->ethtool_ops->flash_device) +return -EOPNOTSUPP ; + +return dev->ethtool_ops->flash_device (dev, &efl); +} +/* The main entry point in this file. Called from net/core/dev.c */ int dev_ethtool (struct net *net,struct ifreq *ifr)
@@ -1111,6 +1124,9 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)case ETHTOOL_SGRO : rc =ethtool_set_gro (dev, useraddr);break ; +case ETHTOOL_FLASHDEV : + rc =ethtool_flash_device (dev, useraddr); +break ;default : rc = -EOPNOTSUPP ; }
Signature · 1 line
1.6.0.4
Quoted 25 lines · Ajit Khaparde
This patch adds support to flash a firmware image to a device using ethtool. The driver gets the filename of the firmware image and flashes the image using the request firmware path.
The region "on the chip" to be flashed can be specified by an option. It is upto the device driver to enumerate the region number passed by ethtool, to the region to be flashed.
The default behavior is to flash all the regions on the chip.
Signed-off-by Ajit Khaparde<[email protected]>--- include/linux/ethtool.h | 14 ++++++++++++++ net/core/ethtool.c | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-)include/linux/ethtool.h +1
-0@@ -362,6 +362,18 @@ struct ethtool_rxnfc {__u32 rule_locs[0 ]; }; +#define ETHTOOL_FLASH_MAX_FILENAME 128
include/linux/ethtool.h struct ethtool_rxnfc { · line 375
Quoted 10 lines
include/linux/ethtool.h +10
-0+enum ethtool_flash_op_type { +ETHTOOL_FLASH_ALL_REGIONS =0 , +}; + +/* for passing firmware flashing related parameters */ +struct ethtool_flash { +__u32 cmd; +__u32 region; +char data[ETHTOOL_FLASH_MAX_FILENAME ]; +};
It passes a _filepath_ directly into the kernel? That seems quite wrong...
we fixed kernel drivers to _not_ think they could read directly from the userland filesystem many years ago.
Seems like passing in an mmap'd fd would be far preferable.
Jeff
David Miller
maintainerFrom: Jeff Garzik <[email protected]>
Date: Thu, 03 Sep 2009 01:33:01 -0400
Quoted 7 lines
It passes a _filepath_ directly into the kernel? That seems quite wrong...
we fixed kernel drivers to _not_ think they could read directly from the userland filesystem many years ago.
Seems like passing in an mmap'd fd would be far preferable.
Jeff, it's passing in something that's going to requested via the firmware loading infrastructure in the kernel.
It is the most appropriate way to do this.
Quoted 8 lines · Jeff Garzik
Quoted 8 lines
include/linux/ethtool.h +0
-0@@ -362,6 +362,18 @@ struct ethtool_rxnfc {__u32 rule_locs[0 ]; };
Quoted 13 lines
include/linux/ethtool.h struct ethtool_rxnfc { · line 375
Quoted 11 lines
include/linux/ethtool.h +11
-0+#define ETHTOOL_FLASH_MAX_FILENAME 128 +enum ethtool_flash_op_type { +ETHTOOL_FLASH_ALL_REGIONS =0 , +}; + +/* for passing firmware flashing related parameters */ +struct ethtool_flash { +__u32 cmd; +__u32 region; +char data[ETHTOOL_FLASH_MAX_FILENAME ]; +};It passes a _filepath_ directly into the kernel? That seems quite wrong...
doh, nevermind. Catching up...
Jeff
From: Ajit Khaparde <[email protected]>
Date: Thu, 3 Sep 2009 08:32:55 +0530
Quoted 11 lines
This patch adds support to flash a firmware image to a device using ethtool. The driver gets the filename of the firmware image and flashes the image using the request firmware path.
The region "on the chip" to be flashed can be specified by an option. It is upto the device driver to enumerate the region number passed by ethtool, to the region to be flashed.
The default behavior is to flash all the regions on the chip.
Signed-off-by Ajit Khaparde <[email protected]>
Applied to net-next-2.6, thanks.