Commit 769ea6d8 authored by Steve Glendinning's avatar Steve Glendinning Committed by David S. Miller

smsc95xx: check return code from control messages

This patch adds additional checks of the values returned by
smsc95xx_(read|write)_reg, and wraps their common patterns
in macros.
Signed-off-by: default avatarSteve Glendinning <steve.glendinning@shawell.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4436761b
...@@ -47,6 +47,15 @@ ...@@ -47,6 +47,15 @@
#define SMSC95XX_TX_OVERHEAD (8) #define SMSC95XX_TX_OVERHEAD (8)
#define SMSC95XX_TX_OVERHEAD_CSUM (12) #define SMSC95XX_TX_OVERHEAD_CSUM (12)
#define check_warn(ret, fmt, args...) \
({ if (ret < 0) netdev_warn(dev->net, fmt, ##args); })
#define check_warn_return(ret, fmt, args...) \
({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); return ret; } })
#define check_warn_goto_done(ret, fmt, args...) \
({ if (ret < 0) { netdev_warn(dev->net, fmt, ##args); goto done; } })
struct smsc95xx_priv { struct smsc95xx_priv {
u32 mac_cr; u32 mac_cr;
u32 hash_hi; u32 hash_hi;
...@@ -63,7 +72,8 @@ static bool turbo_mode = true; ...@@ -63,7 +72,8 @@ static bool turbo_mode = true;
module_param(turbo_mode, bool, 0644); module_param(turbo_mode, bool, 0644);
MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction"); MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
static int smsc95xx_read_reg(struct usbnet *dev, u32 index, u32 *data) static int __must_check smsc95xx_read_reg(struct usbnet *dev, u32 index,
u32 *data)
{ {
u32 *buf = kmalloc(4, GFP_KERNEL); u32 *buf = kmalloc(4, GFP_KERNEL);
int ret; int ret;
...@@ -88,7 +98,8 @@ static int smsc95xx_read_reg(struct usbnet *dev, u32 index, u32 *data) ...@@ -88,7 +98,8 @@ static int smsc95xx_read_reg(struct usbnet *dev, u32 index, u32 *data)
return ret; return ret;
} }
static int smsc95xx_write_reg(struct usbnet *dev, u32 index, u32 data) static int __must_check smsc95xx_write_reg(struct usbnet *dev, u32 index,
u32 data)
{ {
u32 *buf = kmalloc(4, GFP_KERNEL); u32 *buf = kmalloc(4, GFP_KERNEL);
int ret; int ret;
...@@ -116,13 +127,15 @@ static int smsc95xx_write_reg(struct usbnet *dev, u32 index, u32 data) ...@@ -116,13 +127,15 @@ static int smsc95xx_write_reg(struct usbnet *dev, u32 index, u32 data)
/* Loop until the read is completed with timeout /* Loop until the read is completed with timeout
* called with phy_mutex held */ * called with phy_mutex held */
static int smsc95xx_phy_wait_not_busy(struct usbnet *dev) static int __must_check smsc95xx_phy_wait_not_busy(struct usbnet *dev)
{ {
unsigned long start_time = jiffies; unsigned long start_time = jiffies;
u32 val; u32 val;
int ret;
do { do {
smsc95xx_read_reg(dev, MII_ADDR, &val); ret = smsc95xx_read_reg(dev, MII_ADDR, &val);
check_warn_return(ret, "Error reading MII_ACCESS");
if (!(val & MII_BUSY_)) if (!(val & MII_BUSY_))
return 0; return 0;
} while (!time_after(jiffies, start_time + HZ)); } while (!time_after(jiffies, start_time + HZ));
...@@ -134,33 +147,32 @@ static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx) ...@@ -134,33 +147,32 @@ static int smsc95xx_mdio_read(struct net_device *netdev, int phy_id, int idx)
{ {
struct usbnet *dev = netdev_priv(netdev); struct usbnet *dev = netdev_priv(netdev);
u32 val, addr; u32 val, addr;
int ret;
mutex_lock(&dev->phy_mutex); mutex_lock(&dev->phy_mutex);
/* confirm MII not busy */ /* confirm MII not busy */
if (smsc95xx_phy_wait_not_busy(dev)) { ret = smsc95xx_phy_wait_not_busy(dev);
netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_read\n"); check_warn_goto_done(ret, "MII is busy in smsc95xx_mdio_read");
mutex_unlock(&dev->phy_mutex);
return -EIO;
}
/* set the address, index & direction (read from PHY) */ /* set the address, index & direction (read from PHY) */
phy_id &= dev->mii.phy_id_mask; phy_id &= dev->mii.phy_id_mask;
idx &= dev->mii.reg_num_mask; idx &= dev->mii.reg_num_mask;
addr = (phy_id << 11) | (idx << 6) | MII_READ_; addr = (phy_id << 11) | (idx << 6) | MII_READ_;
smsc95xx_write_reg(dev, MII_ADDR, addr); ret = smsc95xx_write_reg(dev, MII_ADDR, addr);
check_warn_goto_done(ret, "Error writing MII_ADDR");
if (smsc95xx_phy_wait_not_busy(dev)) { ret = smsc95xx_phy_wait_not_busy(dev);
netdev_warn(dev->net, "Timed out reading MII reg %02X\n", idx); check_warn_goto_done(ret, "Timed out reading MII reg %02X", idx);
mutex_unlock(&dev->phy_mutex);
return -EIO;
}
smsc95xx_read_reg(dev, MII_DATA, &val); ret = smsc95xx_read_reg(dev, MII_DATA, &val);
check_warn_goto_done(ret, "Error reading MII_DATA");
mutex_unlock(&dev->phy_mutex); ret = (u16)(val & 0xFFFF);
return (u16)(val & 0xFFFF); done:
mutex_unlock(&dev->phy_mutex);
return ret;
} }
static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx, static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
...@@ -168,38 +180,41 @@ static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx, ...@@ -168,38 +180,41 @@ static void smsc95xx_mdio_write(struct net_device *netdev, int phy_id, int idx,
{ {
struct usbnet *dev = netdev_priv(netdev); struct usbnet *dev = netdev_priv(netdev);
u32 val, addr; u32 val, addr;
int ret;
mutex_lock(&dev->phy_mutex); mutex_lock(&dev->phy_mutex);
/* confirm MII not busy */ /* confirm MII not busy */
if (smsc95xx_phy_wait_not_busy(dev)) { ret = smsc95xx_phy_wait_not_busy(dev);
netdev_warn(dev->net, "MII is busy in smsc95xx_mdio_write\n"); check_warn_goto_done(ret, "MII is busy in smsc95xx_mdio_write");
mutex_unlock(&dev->phy_mutex);
return;
}
val = regval; val = regval;
smsc95xx_write_reg(dev, MII_DATA, val); ret = smsc95xx_write_reg(dev, MII_DATA, val);
check_warn_goto_done(ret, "Error writing MII_DATA");
/* set the address, index & direction (write to PHY) */ /* set the address, index & direction (write to PHY) */
phy_id &= dev->mii.phy_id_mask; phy_id &= dev->mii.phy_id_mask;
idx &= dev->mii.reg_num_mask; idx &= dev->mii.reg_num_mask;
addr = (phy_id << 11) | (idx << 6) | MII_WRITE_; addr = (phy_id << 11) | (idx << 6) | MII_WRITE_;
smsc95xx_write_reg(dev, MII_ADDR, addr); ret = smsc95xx_write_reg(dev, MII_ADDR, addr);
check_warn_goto_done(ret, "Error writing MII_ADDR");
if (smsc95xx_phy_wait_not_busy(dev)) ret = smsc95xx_phy_wait_not_busy(dev);
netdev_warn(dev->net, "Timed out writing MII reg %02X\n", idx); check_warn_goto_done(ret, "Timed out writing MII reg %02X", idx);
done:
mutex_unlock(&dev->phy_mutex); mutex_unlock(&dev->phy_mutex);
} }
static int smsc95xx_wait_eeprom(struct usbnet *dev) static int __must_check smsc95xx_wait_eeprom(struct usbnet *dev)
{ {
unsigned long start_time = jiffies; unsigned long start_time = jiffies;
u32 val; u32 val;
int ret;
do { do {
smsc95xx_read_reg(dev, E2P_CMD, &val); ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
check_warn_return(ret, "Error reading E2P_CMD");
if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_)) if (!(val & E2P_CMD_BUSY_) || (val & E2P_CMD_TIMEOUT_))
break; break;
udelay(40); udelay(40);
...@@ -213,13 +228,15 @@ static int smsc95xx_wait_eeprom(struct usbnet *dev) ...@@ -213,13 +228,15 @@ static int smsc95xx_wait_eeprom(struct usbnet *dev)
return 0; return 0;
} }
static int smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev) static int __must_check smsc95xx_eeprom_confirm_not_busy(struct usbnet *dev)
{ {
unsigned long start_time = jiffies; unsigned long start_time = jiffies;
u32 val; u32 val;
int ret;
do { do {
smsc95xx_read_reg(dev, E2P_CMD, &val); ret = smsc95xx_read_reg(dev, E2P_CMD, &val);
check_warn_return(ret, "Error reading E2P_CMD");
if (!(val & E2P_CMD_BUSY_)) if (!(val & E2P_CMD_BUSY_))
return 0; return 0;
...@@ -246,13 +263,15 @@ static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length, ...@@ -246,13 +263,15 @@ static int smsc95xx_read_eeprom(struct usbnet *dev, u32 offset, u32 length,
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_); val = E2P_CMD_BUSY_ | E2P_CMD_READ_ | (offset & E2P_CMD_ADDR_);
smsc95xx_write_reg(dev, E2P_CMD, val); ret = smsc95xx_write_reg(dev, E2P_CMD, val);
check_warn_return(ret, "Error writing E2P_CMD");
ret = smsc95xx_wait_eeprom(dev); ret = smsc95xx_wait_eeprom(dev);
if (ret < 0) if (ret < 0)
return ret; return ret;
smsc95xx_read_reg(dev, E2P_DATA, &val); ret = smsc95xx_read_reg(dev, E2P_DATA, &val);
check_warn_return(ret, "Error reading E2P_DATA");
data[i] = val & 0xFF; data[i] = val & 0xFF;
offset++; offset++;
...@@ -276,7 +295,8 @@ static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, ...@@ -276,7 +295,8 @@ static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
/* Issue write/erase enable command */ /* Issue write/erase enable command */
val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_; val = E2P_CMD_BUSY_ | E2P_CMD_EWEN_;
smsc95xx_write_reg(dev, E2P_CMD, val); ret = smsc95xx_write_reg(dev, E2P_CMD, val);
check_warn_return(ret, "Error writing E2P_DATA");
ret = smsc95xx_wait_eeprom(dev); ret = smsc95xx_wait_eeprom(dev);
if (ret < 0) if (ret < 0)
...@@ -286,11 +306,13 @@ static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length, ...@@ -286,11 +306,13 @@ static int smsc95xx_write_eeprom(struct usbnet *dev, u32 offset, u32 length,
/* Fill data register */ /* Fill data register */
val = data[i]; val = data[i];
smsc95xx_write_reg(dev, E2P_DATA, val); ret = smsc95xx_write_reg(dev, E2P_DATA, val);
check_warn_return(ret, "Error writing E2P_DATA");
/* Send "write" command */ /* Send "write" command */
val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_); val = E2P_CMD_BUSY_ | E2P_CMD_WRITE_ | (offset & E2P_CMD_ADDR_);
smsc95xx_write_reg(dev, E2P_CMD, val); ret = smsc95xx_write_reg(dev, E2P_CMD, val);
check_warn_return(ret, "Error writing E2P_CMD");
ret = smsc95xx_wait_eeprom(dev); ret = smsc95xx_wait_eeprom(dev);
if (ret < 0) if (ret < 0)
...@@ -308,14 +330,14 @@ static void smsc95xx_async_cmd_callback(struct urb *urb) ...@@ -308,14 +330,14 @@ static void smsc95xx_async_cmd_callback(struct urb *urb)
struct usbnet *dev = usb_context->dev; struct usbnet *dev = usb_context->dev;
int status = urb->status; int status = urb->status;
if (status < 0) check_warn(status, "async callback failed with %d\n", status);
netdev_warn(dev->net, "async callback failed with %d\n", status);
kfree(usb_context); kfree(usb_context);
usb_free_urb(urb); usb_free_urb(urb);
} }
static int smsc95xx_write_reg_async(struct usbnet *dev, u16 index, u32 *data) static int __must_check smsc95xx_write_reg_async(struct usbnet *dev, u16 index,
u32 *data)
{ {
struct usb_context *usb_context; struct usb_context *usb_context;
int status; int status;
...@@ -371,6 +393,7 @@ static void smsc95xx_set_multicast(struct net_device *netdev) ...@@ -371,6 +393,7 @@ static void smsc95xx_set_multicast(struct net_device *netdev)
struct usbnet *dev = netdev_priv(netdev); struct usbnet *dev = netdev_priv(netdev);
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
unsigned long flags; unsigned long flags;
int ret;
pdata->hash_hi = 0; pdata->hash_hi = 0;
pdata->hash_lo = 0; pdata->hash_lo = 0;
...@@ -411,21 +434,23 @@ static void smsc95xx_set_multicast(struct net_device *netdev) ...@@ -411,21 +434,23 @@ static void smsc95xx_set_multicast(struct net_device *netdev)
spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
/* Initiate async writes, as we can't wait for completion here */ /* Initiate async writes, as we can't wait for completion here */
smsc95xx_write_reg_async(dev, HASHH, &pdata->hash_hi); ret = smsc95xx_write_reg_async(dev, HASHH, &pdata->hash_hi);
smsc95xx_write_reg_async(dev, HASHL, &pdata->hash_lo); check_warn(ret, "failed to initiate async write to HASHH");
smsc95xx_write_reg_async(dev, MAC_CR, &pdata->mac_cr);
ret = smsc95xx_write_reg_async(dev, HASHL, &pdata->hash_lo);
check_warn(ret, "failed to initiate async write to HASHL");
ret = smsc95xx_write_reg_async(dev, MAC_CR, &pdata->mac_cr);
check_warn(ret, "failed to initiate async write to MAC_CR");
} }
static void smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex, static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,
u16 lcladv, u16 rmtadv) u16 lcladv, u16 rmtadv)
{ {
u32 flow, afc_cfg = 0; u32 flow, afc_cfg = 0;
int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg); int ret = smsc95xx_read_reg(dev, AFC_CFG, &afc_cfg);
if (ret < 0) { check_warn_return(ret, "Error reading AFC_CFG");
netdev_warn(dev->net, "error reading AFC_CFG\n");
return;
}
if (duplex == DUPLEX_FULL) { if (duplex == DUPLEX_FULL) {
u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv); u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
...@@ -449,8 +474,13 @@ static void smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex, ...@@ -449,8 +474,13 @@ static void smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,
afc_cfg |= 0xF; afc_cfg |= 0xF;
} }
smsc95xx_write_reg(dev, FLOW, flow); ret = smsc95xx_write_reg(dev, FLOW, flow);
smsc95xx_write_reg(dev, AFC_CFG, afc_cfg); check_warn_return(ret, "Error writing FLOW");
ret = smsc95xx_write_reg(dev, AFC_CFG, afc_cfg);
check_warn_return(ret, "Error writing AFC_CFG");
return 0;
} }
static int smsc95xx_link_reset(struct usbnet *dev) static int smsc95xx_link_reset(struct usbnet *dev)
...@@ -460,10 +490,14 @@ static int smsc95xx_link_reset(struct usbnet *dev) ...@@ -460,10 +490,14 @@ static int smsc95xx_link_reset(struct usbnet *dev)
struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
unsigned long flags; unsigned long flags;
u16 lcladv, rmtadv; u16 lcladv, rmtadv;
int ret;
/* clear interrupt status */ /* clear interrupt status */
smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC); ret = smsc95xx_mdio_read(dev->net, mii->phy_id, PHY_INT_SRC);
smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); check_warn_return(ret, "Error reading PHY_INT_SRC");
ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
check_warn_return(ret, "Error writing INT_STS");
mii_check_media(mii, 1, 1); mii_check_media(mii, 1, 1);
mii_ethtool_gset(&dev->mii, &ecmd); mii_ethtool_gset(&dev->mii, &ecmd);
...@@ -484,9 +518,11 @@ static int smsc95xx_link_reset(struct usbnet *dev) ...@@ -484,9 +518,11 @@ static int smsc95xx_link_reset(struct usbnet *dev)
} }
spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
check_warn_return(ret, "Error writing MAC_CR");
smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv); ret = smsc95xx_phy_update_flowcontrol(dev, ecmd.duplex, lcladv, rmtadv);
check_warn_return(ret, "Error updating PHY flow control");
return 0; return 0;
} }
...@@ -522,10 +558,7 @@ static int smsc95xx_set_features(struct net_device *netdev, ...@@ -522,10 +558,7 @@ static int smsc95xx_set_features(struct net_device *netdev,
int ret; int ret;
ret = smsc95xx_read_reg(dev, COE_CR, &read_buf); ret = smsc95xx_read_reg(dev, COE_CR, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read COE_CR: %d\n", ret);
netdev_warn(dev->net, "Failed to read COE_CR: %d\n", ret);
return ret;
}
if (features & NETIF_F_HW_CSUM) if (features & NETIF_F_HW_CSUM)
read_buf |= Tx_COE_EN_; read_buf |= Tx_COE_EN_;
...@@ -538,10 +571,7 @@ static int smsc95xx_set_features(struct net_device *netdev, ...@@ -538,10 +571,7 @@ static int smsc95xx_set_features(struct net_device *netdev,
read_buf &= ~Rx_COE_EN_; read_buf &= ~Rx_COE_EN_;
ret = smsc95xx_write_reg(dev, COE_CR, read_buf); ret = smsc95xx_write_reg(dev, COE_CR, read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to write COE_CR: %d\n", ret);
netdev_warn(dev->net, "Failed to write COE_CR: %d\n", ret);
return ret;
}
netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf); netif_dbg(dev, hw, dev->net, "COE_CR = 0x%08x\n", read_buf);
return 0; return 0;
...@@ -656,53 +686,56 @@ static int smsc95xx_set_mac_address(struct usbnet *dev) ...@@ -656,53 +686,56 @@ static int smsc95xx_set_mac_address(struct usbnet *dev)
int ret; int ret;
ret = smsc95xx_write_reg(dev, ADDRL, addr_lo); ret = smsc95xx_write_reg(dev, ADDRL, addr_lo);
if (ret < 0) { check_warn_return(ret, "Failed to write ADDRL: %d\n", ret);
netdev_warn(dev->net, "Failed to write ADDRL: %d\n", ret);
return ret;
}
ret = smsc95xx_write_reg(dev, ADDRH, addr_hi); ret = smsc95xx_write_reg(dev, ADDRH, addr_hi);
if (ret < 0) { check_warn_return(ret, "Failed to write ADDRH: %d\n", ret);
netdev_warn(dev->net, "Failed to write ADDRH: %d\n", ret);
return ret;
}
return 0; return 0;
} }
/* starts the TX path */ /* starts the TX path */
static void smsc95xx_start_tx_path(struct usbnet *dev) static int smsc95xx_start_tx_path(struct usbnet *dev)
{ {
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
unsigned long flags; unsigned long flags;
int ret;
/* Enable Tx at MAC */ /* Enable Tx at MAC */
spin_lock_irqsave(&pdata->mac_cr_lock, flags); spin_lock_irqsave(&pdata->mac_cr_lock, flags);
pdata->mac_cr |= MAC_CR_TXEN_; pdata->mac_cr |= MAC_CR_TXEN_;
spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret);
/* Enable Tx at SCSRs */ /* Enable Tx at SCSRs */
smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_); ret = smsc95xx_write_reg(dev, TX_CFG, TX_CFG_ON_);
check_warn_return(ret, "Failed to write TX_CFG: %d\n", ret);
return 0;
} }
/* Starts the Receive path */ /* Starts the Receive path */
static void smsc95xx_start_rx_path(struct usbnet *dev) static int smsc95xx_start_rx_path(struct usbnet *dev)
{ {
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]); struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
unsigned long flags; unsigned long flags;
int ret;
spin_lock_irqsave(&pdata->mac_cr_lock, flags); spin_lock_irqsave(&pdata->mac_cr_lock, flags);
pdata->mac_cr |= MAC_CR_RXEN_; pdata->mac_cr |= MAC_CR_RXEN_;
spin_unlock_irqrestore(&pdata->mac_cr_lock, flags); spin_unlock_irqrestore(&pdata->mac_cr_lock, flags);
smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr); ret = smsc95xx_write_reg(dev, MAC_CR, pdata->mac_cr);
check_warn_return(ret, "Failed to write MAC_CR: %d\n", ret);
return 0;
} }
static int smsc95xx_phy_initialize(struct usbnet *dev) static int smsc95xx_phy_initialize(struct usbnet *dev)
{ {
int bmcr, timeout = 0; int bmcr, ret, timeout = 0;
/* Initialize MII structure */ /* Initialize MII structure */
dev->mii.dev = dev->net; dev->mii.dev = dev->net;
...@@ -731,7 +764,8 @@ static int smsc95xx_phy_initialize(struct usbnet *dev) ...@@ -731,7 +764,8 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)
ADVERTISE_PAUSE_ASYM); ADVERTISE_PAUSE_ASYM);
/* read to clear */ /* read to clear */
smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC); ret = smsc95xx_mdio_read(dev->net, dev->mii.phy_id, PHY_INT_SRC);
check_warn_return(ret, "Failed to read PHY_INT_SRC during init");
smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK, smsc95xx_mdio_write(dev->net, dev->mii.phy_id, PHY_INT_MASK,
PHY_INT_MASK_DEFAULT_); PHY_INT_MASK_DEFAULT_);
...@@ -750,20 +784,13 @@ static int smsc95xx_reset(struct usbnet *dev) ...@@ -750,20 +784,13 @@ static int smsc95xx_reset(struct usbnet *dev)
netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n"); netif_dbg(dev, ifup, dev->net, "entering smsc95xx_reset\n");
ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_); ret = smsc95xx_write_reg(dev, HW_CFG, HW_CFG_LRST_);
if (ret < 0) { check_warn_return(ret, "Failed to write HW_CFG_LRST_ bit in HW_CFG\n");
netdev_warn(dev->net, "Failed to write HW_CFG_LRST_ bit in HW_CFG register, ret = %d\n",
ret);
return ret;
}
timeout = 0; timeout = 0;
do { do {
msleep(10); msleep(10);
ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
return ret;
}
timeout++; timeout++;
} while ((read_buf & HW_CFG_LRST_) && (timeout < 100)); } while ((read_buf & HW_CFG_LRST_) && (timeout < 100));
...@@ -773,19 +800,13 @@ static int smsc95xx_reset(struct usbnet *dev) ...@@ -773,19 +800,13 @@ static int smsc95xx_reset(struct usbnet *dev)
} }
ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_); ret = smsc95xx_write_reg(dev, PM_CTRL, PM_CTL_PHY_RST_);
if (ret < 0) { check_warn_return(ret, "Failed to write PM_CTRL: %d\n", ret);
netdev_warn(dev->net, "Failed to write PM_CTRL: %d\n", ret);
return ret;
}
timeout = 0; timeout = 0;
do { do {
msleep(10); msleep(10);
ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf); ret = smsc95xx_read_reg(dev, PM_CTRL, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read PM_CTRL: %d\n", ret);
netdev_warn(dev->net, "Failed to read PM_CTRL: %d\n", ret);
return ret;
}
timeout++; timeout++;
} while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100)); } while ((read_buf & PM_CTL_PHY_RST_) && (timeout < 100));
...@@ -802,10 +823,7 @@ static int smsc95xx_reset(struct usbnet *dev) ...@@ -802,10 +823,7 @@ static int smsc95xx_reset(struct usbnet *dev)
"MAC Address: %pM\n", dev->net->dev_addr); "MAC Address: %pM\n", dev->net->dev_addr);
ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
return ret;
}
netif_dbg(dev, ifup, dev->net, netif_dbg(dev, ifup, dev->net,
"Read Value from HW_CFG : 0x%08x\n", read_buf); "Read Value from HW_CFG : 0x%08x\n", read_buf);
...@@ -813,17 +831,10 @@ static int smsc95xx_reset(struct usbnet *dev) ...@@ -813,17 +831,10 @@ static int smsc95xx_reset(struct usbnet *dev)
read_buf |= HW_CFG_BIR_; read_buf |= HW_CFG_BIR_;
ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to write HW_CFG_BIR_ bit in HW_CFG\n");
netdev_warn(dev->net, "Failed to write HW_CFG_BIR_ bit in HW_CFG register, ret = %d\n",
ret);
return ret;
}
ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
return ret;
}
netif_dbg(dev, ifup, dev->net, netif_dbg(dev, ifup, dev->net,
"Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n", "Read Value from HW_CFG after writing HW_CFG_BIR_: 0x%08x\n",
read_buf); read_buf);
...@@ -843,40 +854,28 @@ static int smsc95xx_reset(struct usbnet *dev) ...@@ -843,40 +854,28 @@ static int smsc95xx_reset(struct usbnet *dev)
"rx_urb_size=%ld\n", (ulong)dev->rx_urb_size); "rx_urb_size=%ld\n", (ulong)dev->rx_urb_size);
ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap); ret = smsc95xx_write_reg(dev, BURST_CAP, burst_cap);
if (ret < 0) { check_warn_return(ret, "Failed to write BURST_CAP: %d\n", ret);
netdev_warn(dev->net, "Failed to write BURST_CAP: %d\n", ret);
return ret;
}
ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf); ret = smsc95xx_read_reg(dev, BURST_CAP, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read BURST_CAP: %d\n", ret);
netdev_warn(dev->net, "Failed to read BURST_CAP: %d\n", ret);
return ret;
}
netif_dbg(dev, ifup, dev->net, netif_dbg(dev, ifup, dev->net,
"Read Value from BURST_CAP after writing: 0x%08x\n", "Read Value from BURST_CAP after writing: 0x%08x\n",
read_buf); read_buf);
ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY); ret = smsc95xx_write_reg(dev, BULK_IN_DLY, DEFAULT_BULK_IN_DELAY);
if (ret < 0) { check_warn_return(ret, "Failed to write BULK_IN_DLY: %d\n", ret);
netdev_warn(dev->net, "ret = %d\n", ret);
return ret;
}
ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf); ret = smsc95xx_read_reg(dev, BULK_IN_DLY, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read BULK_IN_DLY: %d\n", ret);
netdev_warn(dev->net, "Failed to read BULK_IN_DLY: %d\n", ret);
return ret;
}
netif_dbg(dev, ifup, dev->net, netif_dbg(dev, ifup, dev->net,
"Read Value from BULK_IN_DLY after writing: 0x%08x\n", "Read Value from BULK_IN_DLY after writing: 0x%08x\n",
read_buf); read_buf);
ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
return ret;
}
netif_dbg(dev, ifup, dev->net, netif_dbg(dev, ifup, dev->net,
"Read Value from HW_CFG: 0x%08x\n", read_buf); "Read Value from HW_CFG: 0x%08x\n", read_buf);
...@@ -889,97 +888,66 @@ static int smsc95xx_reset(struct usbnet *dev) ...@@ -889,97 +888,66 @@ static int smsc95xx_reset(struct usbnet *dev)
read_buf |= NET_IP_ALIGN << 9; read_buf |= NET_IP_ALIGN << 9;
ret = smsc95xx_write_reg(dev, HW_CFG, read_buf); ret = smsc95xx_write_reg(dev, HW_CFG, read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to write HW_CFG: %d\n", ret);
netdev_warn(dev->net, "Failed to write HW_CFG register, ret=%d\n",
ret);
return ret;
}
ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf); ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read HW_CFG: %d\n", ret);
netdev_warn(dev->net, "Failed to read HW_CFG: %d\n", ret);
return ret;
}
netif_dbg(dev, ifup, dev->net, netif_dbg(dev, ifup, dev->net,
"Read Value from HW_CFG after writing: 0x%08x\n", read_buf); "Read Value from HW_CFG after writing: 0x%08x\n", read_buf);
ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_); ret = smsc95xx_write_reg(dev, INT_STS, INT_STS_CLEAR_ALL_);
if (ret < 0) { check_warn_return(ret, "Failed to write INT_STS: %d\n", ret);
netdev_warn(dev->net, "Failed to write INT_STS register, ret=%d\n",
ret);
return ret;
}
ret = smsc95xx_read_reg(dev, ID_REV, &read_buf); ret = smsc95xx_read_reg(dev, ID_REV, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read ID_REV: %d\n", ret);
netdev_warn(dev->net, "Failed to read ID_REV: %d\n", ret);
return ret;
}
netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf); netif_dbg(dev, ifup, dev->net, "ID_REV = 0x%08x\n", read_buf);
/* Configure GPIO pins as LED outputs */ /* Configure GPIO pins as LED outputs */
write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED | write_buf = LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED |
LED_GPIO_CFG_FDX_LED; LED_GPIO_CFG_FDX_LED;
ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf); ret = smsc95xx_write_reg(dev, LED_GPIO_CFG, write_buf);
if (ret < 0) { check_warn_return(ret, "Failed to write LED_GPIO_CFG: %d\n", ret);
netdev_warn(dev->net, "Failed to write LED_GPIO_CFG register, ret=%d\n",
ret);
return ret;
}
/* Init Tx */ /* Init Tx */
ret = smsc95xx_write_reg(dev, FLOW, 0); ret = smsc95xx_write_reg(dev, FLOW, 0);
if (ret < 0) { check_warn_return(ret, "Failed to write FLOW: %d\n", ret);
netdev_warn(dev->net, "Failed to write FLOW: %d\n", ret);
return ret;
}
ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT); ret = smsc95xx_write_reg(dev, AFC_CFG, AFC_CFG_DEFAULT);
if (ret < 0) { check_warn_return(ret, "Failed to write AFC_CFG: %d\n", ret);
netdev_warn(dev->net, "Failed to write AFC_CFG: %d\n", ret);
return ret;
}
/* Don't need mac_cr_lock during initialisation */ /* Don't need mac_cr_lock during initialisation */
ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr); ret = smsc95xx_read_reg(dev, MAC_CR, &pdata->mac_cr);
if (ret < 0) { check_warn_return(ret, "Failed to read MAC_CR: %d\n", ret);
netdev_warn(dev->net, "Failed to read MAC_CR: %d\n", ret);
return ret;
}
/* Init Rx */ /* Init Rx */
/* Set Vlan */ /* Set Vlan */
ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q); ret = smsc95xx_write_reg(dev, VLAN1, (u32)ETH_P_8021Q);
if (ret < 0) { check_warn_return(ret, "Failed to write VLAN1: %d\n", ret);
netdev_warn(dev->net, "Failed to write VAN1: %d\n", ret);
return ret;
}
/* Enable or disable checksum offload engines */ /* Enable or disable checksum offload engines */
smsc95xx_set_features(dev->net, dev->net->features); ret = smsc95xx_set_features(dev->net, dev->net->features);
check_warn_return(ret, "Failed to set checksum offload features");
smsc95xx_set_multicast(dev->net); smsc95xx_set_multicast(dev->net);
if (smsc95xx_phy_initialize(dev) < 0) ret = smsc95xx_phy_initialize(dev);
return -EIO; check_warn_return(ret, "Failed to init PHY");
ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf); ret = smsc95xx_read_reg(dev, INT_EP_CTL, &read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to read INT_EP_CTL: %d\n", ret);
netdev_warn(dev->net, "Failed to read INT_EP_CTL: %d\n", ret);
return ret;
}
/* enable PHY interrupts */ /* enable PHY interrupts */
read_buf |= INT_EP_CTL_PHY_INT_; read_buf |= INT_EP_CTL_PHY_INT_;
ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf); ret = smsc95xx_write_reg(dev, INT_EP_CTL, read_buf);
if (ret < 0) { check_warn_return(ret, "Failed to write INT_EP_CTL: %d\n", ret);
netdev_warn(dev->net, "Failed to write INT_EP_CTL: %d\n", ret);
return ret;
}
smsc95xx_start_tx_path(dev); ret = smsc95xx_start_tx_path(dev);
smsc95xx_start_rx_path(dev); check_warn_return(ret, "Failed to start TX path");
ret = smsc95xx_start_rx_path(dev);
check_warn_return(ret, "Failed to start RX path");
netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n"); netif_dbg(dev, ifup, dev->net, "smsc95xx_reset, return 0\n");
return 0; return 0;
...@@ -1006,10 +974,7 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf) ...@@ -1006,10 +974,7 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n"); printk(KERN_INFO SMSC_CHIPNAME " v" SMSC_DRIVER_VERSION "\n");
ret = usbnet_get_endpoints(dev, intf); ret = usbnet_get_endpoints(dev, intf);
if (ret < 0) { check_warn_return(ret, "usbnet_get_endpoints failed: %d\n", ret);
netdev_warn(dev->net, "usbnet_get_endpoints failed: %d\n", ret);
return ret;
}
dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv), dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv),
GFP_KERNEL); GFP_KERNEL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment