Skip to contentSkip to conversation

net/ethtool: Add support to the ethtool feature to flash firmware image from a specified file.

PATCH In review Ajit Khaparde 2 participants 2 messages Aug 14, 2009

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

PATCH 1/1 net/ethtool: Add support to 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 this image using the request_firmware() path.

---
 include/linux/ethtool.h |    8 ++++++++
 net/core/ethtool.c      |   17 +++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
include/linux/ethtool.h +8 -0
index 90c4a36..243cdce 100644
@@ -362,6 +362,12 @@ struct ethtool_rxnfc {
 	__u32				rule_locs[0];
 };
 
+/* for passing firmware flashing related parameters */
+struct ethtool_flash {
+	__u32	cmd;
+	__u8	*data;
+};
+
 #ifdef __KERNEL__
 
 struct net_device;
@@ -489,6 +495,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 *, u8 *);
 };
 #endif /* __KERNEL__ */
 
@@ -545,6 +552,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 +17 -0
index 44e5711..bb94b3d 100644
@@ -898,6 +898,20 @@ 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)
+{
+	int err;
+	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.data);
+}
+
 /* The main entry point in this file.  Called from net/core/dev.c */
 
 int dev_ethtool(struct net *net, struct ifreq *ifr)
@@ -1111,6 +1125,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
#1 lore raw
Quoted 15 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 this image using the request_firmware() path.

---
 include/linux/ethtool.h |    8 ++++++++
 net/core/ethtool.c      |   17 +++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
include/linux/ethtool.h +0 -0
index 90c4a36..243cdce 100644

include/linux/ethtool.h struct ethtool_rxnfc { · line 368

Quoted 7 lines
include/linux/ethtool.h +4 -0
@@ -362,6 +362,12 @@ struct ethtool_rxnfc {
 	__u32				rule_locs[0];
 };
 
+/* for passing firmware flashing related parameters */
+struct ethtool_flash {
+	__u32	cmd;
+	__u8	*data;

There also needs to be some sort of identifier to distinguish different flash regions.

[...]

net/core/ethtool.c static int ethtool_set_value(struct net_device *dev, char __user *useraddr, · line 907

Quoted 13 lines
net/core/ethtool.c +7 -0
@@ -898,6 +898,20 @@ 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)
+{
+	int err;
+	struct ethtool_flash efl;
+
+	if (copy_from_user(&efl, useraddr, sizeof(efl)))
+		return -EFAULT;

[...]

This leaves efl.data as a user-space pointer, not a kernel-space pointer. The string will then also need to be copied. It's simpler to embed the string in the structure, though that means putting a limit on the string length.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.