Smsc75xx Change

Hey everyone!

For something I have been working on I wanted the ability to set a mac address so I can keep a static ip. I know you can do it from the device tree but I was having issues understanding and moving forward with that for all of my boards so I ported some of the code from the Microchip smsc7500 driver to let me set the mac address through a driver params option.

the patch is here and ill update it with a patch link before the end of day.

its easy to use just create
/etc/modprobe.d/smsc75xxmac.conf

then add this line to the file
options smsc75xx mac_addr_hi16=$WHATEVER_IP options smsc75xx mac_addr_lo32=2
(the 2 signifies the MAC as a locally administered address so just change it to what you need)

reboot then set your ip and that should get you a static ip!

example to set the ip:
nmcli connection add con-name eth0 ifname eth0 type ethernet ip4 $WHATEVER_IP/24

I HOPE THIS HELPS SOMEONE!!!

From b65f16df39ac81fdd2ded3ac93a9c51ebce0bf40 Mon Sep 17 00:00:00 2001
From: Jessie <jessie.pullaro@gmail.com>
Date: Fri, 16 Aug 2019 10:20:33 -0400
Subject: [PATCH] smsc75xx driver change to port setting mac address from
driver params. from the microchip driver

---
 drivers/net/usb/smsc75xx.c | 38 +++++++++++++++++++++++++++++++++++---
 drivers/net/usb/smsc75xx.h |  9 +++++++++
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index ec287c9741e8..04ffd70da1f2 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -18,6 +18,7 @@
  *****************************************************************************/
 
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/kmod.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
@@ -62,6 +63,22 @@
 #define SUSPEND_ALLMODES		(SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
 					 SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
 
+/****************************************************************************************/
+/***********************	Driver Parameters *********************************************/
+/****************************************************************************************/
+
+u32 mac_addr_hi16 = DUMMY_VALUE;
+module_param(mac_addr_hi16, uint, 0);
+MODULE_PARM_DESC(mac_addr_hi16,"Specifies the high 16 bits of the mac address");
+
+u32 mac_addr_lo32 = DUMMY_VALUE;
+module_param(mac_addr_lo32, uint, 0);
+MODULE_PARM_DESC(mac_addr_lo32,"Specifies the low 32 bits of the mac address");
+
+/****************************************************************************************/
+/********************Static Functions, Structure and Variables **************************/
+/****************************************************************************************/
+
 struct smsc75xx_priv {
 	struct usbnet *dev;
 	u32 rfe_ctl;
@@ -771,13 +788,28 @@ static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
 static void smsc75xx_init_mac_address(struct usbnet *dev)
 {
 	const u8 *mac_addr;
+	u32 dwAddrH, dwAddrL;
 
 	/* maybe the boot loader passed the MAC address in devicetree */
 	mac_addr = of_get_mac_address(dev->udev->dev.of_node);
 	if (mac_addr) {
-		memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN);
-		return;
-	}
+ 	 memcpy(dev->net->dev_addr, mac_addr, ETH_ALEN);
+ 	 return;
+  }
+
+  if(mac_addr_hi16 != DUMMY_VALUE || mac_addr_lo32 != DUMMY_VALUE){
+ 	 dwAddrH = mac_addr_hi16 & 0xFFFF;
+ 	 dwAddrL = mac_addr_lo32;
+
+ 	 dev->net->dev_addr[0]=LOBYTE(LOWORD(dwAddrL));
+ 	 dev->net->dev_addr[1]=HIBYTE(LOWORD(dwAddrL));
+ 	 dev->net->dev_addr[2]=LOBYTE(HIWORD(dwAddrL));
+ 	 dev->net->dev_addr[3]=HIBYTE(HIWORD(dwAddrL));
+ 	 dev->net->dev_addr[4]=LOBYTE(LOWORD(dwAddrH));
+ 	 dev->net->dev_addr[5]=HIBYTE(LOWORD(dwAddrH));
+
+ 	 return;
+  }
 
 	/* try reading mac address from EEPROM */
 	if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
diff --git a/drivers/net/usb/smsc75xx.h b/drivers/net/usb/smsc75xx.h
index 2c7ea8fd184f..64256ba06655 100644
--- a/drivers/net/usb/smsc75xx.h
+++ b/drivers/net/usb/smsc75xx.h
@@ -418,4 +418,13 @@
 #define INT_ENP_MAC_ERR_INT		((u32)BIT(15))
 #define INT_ENP_RX_FIFO_DATA_INT	((u32)BIT(12))
 
+/* Added for Driver parameter feature */
+
+#define HIBYTE(word)  		((BYTE)(((u16)(word))>>8))
+#define LOBYTE(word)  		((BYTE)(((u16)(word))&0x00FFU))
+#define HIWORD(dWord) 		((u16)(((u32)(dWord))>>16))
+#define LOWORD(dWord) 		((u16)(((u32)(dWord))&0x0000FFFFUL))
+typedef unsigned char BYTE;
+#define DUMMY_VALUE
+
 #endif /* _SMSC75XX_H */
-- 
2.17.1