diff mbox

[U-Boot,16/18] net: Allow drivers to return -ENOSYS with the write_hwaddr() method

Message ID 1436222877-17548-17-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass July 6, 2015, 10:47 p.m. UTC
Some drivers may want to implement this method for some of their devices but
not for others. So it is not possible to just leave the operation out of
the table. Drivers could get around this by masquerading as two separate
drivers but that seems unpleasant.

Allow the driver to return an error when it does not want to process the
write_hwaddr() method.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/net.h | 4 +++-
 net/eth.c     | 6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

Simon Glass July 22, 2015, 11:41 p.m. UTC | #1
On 6 July 2015 at 16:47, Simon Glass <sjg@chromium.org> wrote:
> Some drivers may want to implement this method for some of their devices but
> not for others. So it is not possible to just leave the operation out of
> the table. Drivers could get around this by masquerading as two separate
> drivers but that seems unpleasant.
>
> Allow the driver to return an error when it does not want to process the
> write_hwaddr() method.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  include/net.h | 4 +++-
>  net/eth.c     | 6 ++++++
>  2 files changed, 9 insertions(+), 1 deletion(-)

Applied to u-boot-dm.
diff mbox

Patch

diff --git a/include/net.h b/include/net.h
index b9c13f2..d09bec9 100644
--- a/include/net.h
+++ b/include/net.h
@@ -119,7 +119,9 @@  enum eth_recv_flags {
  * mcast: Join or leave a multicast group (for TFTP) - optional
  * write_hwaddr: Write a MAC address to the hardware (used to pass it to Linux
  *		 on some platforms like ARM). This function expects the
- *		 eth_pdata::enetaddr field to be populated - optional
+ *		 eth_pdata::enetaddr field to be populated. The method can
+ *		 return -ENOSYS to indicate that this is not implemented for
+		 this hardware - optional.
  * read_rom_hwaddr: Some devices have a backup of the MAC address stored in a
  *		    ROM on the board. This is how the driver should expose it
  *		    to the network stack. This function should fill in the
diff --git a/net/eth.c b/net/eth.c
index 72ce91c..d3ec8d6 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -287,7 +287,13 @@  static int eth_write_hwaddr(struct udevice *dev)
 			return -EINVAL;
 		}
 
+		/*
+		 * Drivers are allowed to decide not to implement this at
+		 * run-time. E.g. Some devices may use it and some may not.
+		 */
 		ret = eth_get_ops(dev)->write_hwaddr(dev);
+		if (ret == -ENOSYS)
+			ret = 0;
 		if (ret)
 			printf("\nWarning: %s failed to set MAC address\n",
 			       dev->name);