Skip to content

Commit 7a141e6

Browse files
oleremdavem330
authored andcommitted
net: usb: asix: ax88772: move embedded PHY detection as early as possible
Some HW revisions need additional MAC configuration before the embedded PHY can be enabled. If this is not done, we won't be able to get response from the internal PHY. This issue was detected on chipcode == AX_AX88772_CHIPCODE variant, where ax88772_hw_reset() was executed with missing embd_phy flag. Fixes: e532a09 ("net: usb: asix: ax88772: add phylib support") Reported-by: Jarkko Nikula <[email protected]> Tested-by: Jarkko Nikula <[email protected]> Signed-off-by: Oleksij Rempel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 359f4cd commit 7a141e6

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

drivers/net/usb/asix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ struct asix_common_private {
184184
struct phy_device *phydev;
185185
u16 phy_addr;
186186
char phy_name[20];
187+
bool embd_phy;
187188
};
188189

189190
extern const struct driver_info ax88172a_info;

drivers/net/usb/asix_devices.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -354,24 +354,23 @@ static int ax88772_reset(struct usbnet *dev)
354354
static int ax88772_hw_reset(struct usbnet *dev, int in_pm)
355355
{
356356
struct asix_data *data = (struct asix_data *)&dev->data;
357-
int ret, embd_phy;
357+
struct asix_common_private *priv = dev->driver_priv;
358358
u16 rx_ctl;
359+
int ret;
359360

360361
ret = asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_2 |
361362
AX_GPIO_GPO2EN, 5, in_pm);
362363
if (ret < 0)
363364
goto out;
364365

365-
embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
366-
367-
ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy,
366+
ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, priv->embd_phy,
368367
0, 0, NULL, in_pm);
369368
if (ret < 0) {
370369
netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
371370
goto out;
372371
}
373372

374-
if (embd_phy) {
373+
if (priv->embd_phy) {
375374
ret = asix_sw_reset(dev, AX_SWRESET_IPPD, in_pm);
376375
if (ret < 0)
377376
goto out;
@@ -449,17 +448,16 @@ static int ax88772_hw_reset(struct usbnet *dev, int in_pm)
449448
static int ax88772a_hw_reset(struct usbnet *dev, int in_pm)
450449
{
451450
struct asix_data *data = (struct asix_data *)&dev->data;
452-
int ret, embd_phy;
451+
struct asix_common_private *priv = dev->driver_priv;
453452
u16 rx_ctl, phy14h, phy15h, phy16h;
454453
u8 chipcode = 0;
454+
int ret;
455455

456456
ret = asix_write_gpio(dev, AX_GPIO_RSE, 5, in_pm);
457457
if (ret < 0)
458458
goto out;
459459

460-
embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
461-
462-
ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy |
460+
ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, priv->embd_phy |
463461
AX_PHYSEL_SSEN, 0, 0, NULL, in_pm);
464462
if (ret < 0) {
465463
netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
@@ -683,12 +681,6 @@ static int ax88772_init_phy(struct usbnet *dev)
683681
struct asix_common_private *priv = dev->driver_priv;
684682
int ret;
685683

686-
ret = asix_read_phy_addr(dev, true);
687-
if (ret < 0)
688-
return ret;
689-
690-
priv->phy_addr = ret;
691-
692684
snprintf(priv->phy_name, sizeof(priv->phy_name), PHY_ID_FMT,
693685
priv->mdio->id, priv->phy_addr);
694686

@@ -716,6 +708,12 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
716708
int ret, i;
717709
u32 phyid;
718710

711+
priv = devm_kzalloc(&dev->udev->dev, sizeof(*priv), GFP_KERNEL);
712+
if (!priv)
713+
return -ENOMEM;
714+
715+
dev->driver_priv = priv;
716+
719717
usbnet_get_endpoints(dev, intf);
720718

721719
/* Maybe the boot loader passed the MAC address via device tree */
@@ -751,6 +749,13 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
751749
dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
752750
dev->net->needed_tailroom = 4; /* cf asix_tx_fixup() */
753751

752+
ret = asix_read_phy_addr(dev, true);
753+
if (ret < 0)
754+
return ret;
755+
756+
priv->phy_addr = ret;
757+
priv->embd_phy = ((priv->phy_addr & 0x1f) == 0x10 ? true : false);
758+
754759
asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0, 0, 1, &chipcode, 0);
755760
chipcode &= AX_CHIPCODE_MASK;
756761

@@ -773,12 +778,6 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
773778
dev->rx_urb_size = 2048;
774779
}
775780

776-
priv = devm_kzalloc(&dev->udev->dev, sizeof(*priv), GFP_KERNEL);
777-
if (!priv)
778-
return -ENOMEM;
779-
780-
dev->driver_priv = priv;
781-
782781
priv->presvd_phy_bmcr = 0;
783782
priv->presvd_phy_advertise = 0;
784783
if (chipcode == AX_AX88772_CHIPCODE) {

0 commit comments

Comments
 (0)