Commit 05c6a8d7a7d778f26d8eb821556988993b766092

Authored by Ajit Khaparde
Committed by David S. Miller
1 parent 451f144398

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.

Signed-off-by: Ajit Khaparde <ajitk@serverengines.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 2 changed files with 30 additions and 0 deletions Side-by-side Diff

include/linux/ethtool.h
... ... @@ -362,6 +362,18 @@
362 362 __u32 rule_locs[0];
363 363 };
364 364  
  365 +#define ETHTOOL_FLASH_MAX_FILENAME 128
  366 +enum ethtool_flash_op_type {
  367 + ETHTOOL_FLASH_ALL_REGIONS = 0,
  368 +};
  369 +
  370 +/* for passing firmware flashing related parameters */
  371 +struct ethtool_flash {
  372 + __u32 cmd;
  373 + __u32 region;
  374 + char data[ETHTOOL_FLASH_MAX_FILENAME];
  375 +};
  376 +
365 377 #ifdef __KERNEL__
366 378  
367 379 struct net_device;
... ... @@ -489,6 +501,7 @@
489 501 int (*get_stats_count)(struct net_device *);/* use get_sset_count */
490 502 int (*get_rxnfc)(struct net_device *, struct ethtool_rxnfc *, void *);
491 503 int (*set_rxnfc)(struct net_device *, struct ethtool_rxnfc *);
  504 + int (*flash_device)(struct net_device *, struct ethtool_flash *);
492 505 };
493 506 #endif /* __KERNEL__ */
494 507  
... ... @@ -545,6 +558,7 @@
545 558 #define ETHTOOL_GRXCLSRLALL 0x00000030 /* Get all RX classification rule */
546 559 #define ETHTOOL_SRXCLSRLDEL 0x00000031 /* Delete RX classification rule */
547 560 #define ETHTOOL_SRXCLSRLINS 0x00000032 /* Insert RX classification rule */
  561 +#define ETHTOOL_FLASHDEV 0x00000033 /* Flash firmware to device */
548 562  
549 563 /* compatibility with older code */
550 564 #define SPARC_ETH_GSET ETHTOOL_GSET
... ... @@ -898,6 +898,19 @@
898 898 return actor(dev, edata.data);
899 899 }
900 900  
  901 +static int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
  902 +{
  903 + struct ethtool_flash efl;
  904 +
  905 + if (copy_from_user(&efl, useraddr, sizeof(efl)))
  906 + return -EFAULT;
  907 +
  908 + if (!dev->ethtool_ops->flash_device)
  909 + return -EOPNOTSUPP;
  910 +
  911 + return dev->ethtool_ops->flash_device(dev, &efl);
  912 +}
  913 +
901 914 /* The main entry point in this file. Called from net/core/dev.c */
902 915  
903 916 int dev_ethtool(struct net *net, struct ifreq *ifr)
... ... @@ -1110,6 +1123,9 @@
1110 1123 break;
1111 1124 case ETHTOOL_SGRO:
1112 1125 rc = ethtool_set_gro(dev, useraddr);
  1126 + break;
  1127 + case ETHTOOL_FLASHDEV:
  1128 + rc = ethtool_flash_device(dev, useraddr);
1113 1129 break;
1114 1130 default:
1115 1131 rc = -EOPNOTSUPP;