Skip to content

Commit df2d59a

Browse files
Dmitry Bezrukovdavem330
Dmitry Bezrukov
authored andcommitted
net: usb: aqc111: Add support for getting and setting of MAC address
Signed-off-by: Dmitry Bezrukov <[email protected]> Signed-off-by: Igor Russkikh <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7b8b065 commit df2d59a

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

drivers/net/usb/aqc111.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/netdevice.h>
1212
#include <linux/mii.h>
1313
#include <linux/usb.h>
14+
#include <linux/if_vlan.h>
1415
#include <linux/usb/cdc.h>
1516
#include <linux/usb/usbnet.h>
1617

@@ -204,11 +205,43 @@ static void aqc111_set_phy_speed(struct usbnet *dev, u8 autoneg, u16 speed)
204205
aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0, &aqc111_data->phy_cfg);
205206
}
206207

208+
static int aqc111_set_mac_addr(struct net_device *net, void *p)
209+
{
210+
struct usbnet *dev = netdev_priv(net);
211+
int ret = 0;
212+
213+
ret = eth_mac_addr(net, p);
214+
if (ret < 0)
215+
return ret;
216+
217+
/* Set the MAC address */
218+
return aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_NODE_ID, ETH_ALEN,
219+
ETH_ALEN, net->dev_addr);
220+
}
221+
207222
static const struct net_device_ops aqc111_netdev_ops = {
208223
.ndo_open = usbnet_open,
209224
.ndo_stop = usbnet_stop,
225+
.ndo_set_mac_address = aqc111_set_mac_addr,
226+
.ndo_validate_addr = eth_validate_addr,
210227
};
211228

229+
static int aqc111_read_perm_mac(struct usbnet *dev)
230+
{
231+
u8 buf[ETH_ALEN];
232+
int ret;
233+
234+
ret = aqc111_read_cmd(dev, AQ_FLASH_PARAMETERS, 0, 0, ETH_ALEN, buf);
235+
if (ret < 0)
236+
goto out;
237+
238+
ether_addr_copy(dev->net->perm_addr, buf);
239+
240+
return 0;
241+
out:
242+
return ret;
243+
}
244+
212245
static void aqc111_read_fw_version(struct usbnet *dev,
213246
struct aqc111_data *aqc111_data)
214247
{
@@ -251,6 +284,12 @@ static int aqc111_bind(struct usbnet *dev, struct usb_interface *intf)
251284
/* store aqc111_data pointer in device data field */
252285
dev->driver_priv = aqc111_data;
253286

287+
/* Init the MAC address */
288+
ret = aqc111_read_perm_mac(dev);
289+
if (ret)
290+
goto out;
291+
292+
ether_addr_copy(dev->net->dev_addr, dev->net->perm_addr);
254293
dev->net->netdev_ops = &aqc111_netdev_ops;
255294

256295
aqc111_read_fw_version(dev, aqc111_data);
@@ -259,6 +298,10 @@ static int aqc111_bind(struct usbnet *dev, struct usb_interface *intf)
259298
SPEED_5000 : SPEED_1000;
260299

261300
return 0;
301+
302+
out:
303+
kfree(aqc111_data);
304+
return ret;
262305
}
263306

264307
static void aqc111_unbind(struct usbnet *dev, struct usb_interface *intf)
@@ -467,6 +510,10 @@ static int aqc111_reset(struct usbnet *dev)
467510
aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0,
468511
&aqc111_data->phy_cfg);
469512

513+
/* Set the MAC address */
514+
aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_NODE_ID, ETH_ALEN,
515+
ETH_ALEN, dev->net->dev_addr);
516+
470517
reg8 = 0xFF;
471518
aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_BM_INT_MASK, 1, 1, &reg8);
472519

drivers/net/usb/aqc111.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define __LINUX_USBNET_AQC111_H
1212

1313
#define AQ_ACCESS_MAC 0x01
14+
#define AQ_FLASH_PARAMETERS 0x20
1415
#define AQ_PHY_POWER 0x31
1516
#define AQ_PHY_OPS 0x61
1617

0 commit comments

Comments
 (0)