Skip to content

Commit

Permalink
staging: et131x: Use phy-device, mii_bus and ethtool_ops
Browse files Browse the repository at this point in the history
Adding some basic ethtool ops and supporting functionality using a phy device.

Signed-off-by: Mark Einon <mark.einon@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Mark Einon authored and Greg Kroah-Hartman committed Aug 29, 2011
1 parent fca7737 commit 0f18f76
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 30 deletions.
1 change: 1 addition & 0 deletions drivers/staging/et131x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ et131x-y := et1310_eeprom.o \
et1310_rx.o \
et1310_tx.o \
et131x_initpci.o \
et131x_ethtool.o \
et131x_isr.o \
et131x_netdev.o
45 changes: 38 additions & 7 deletions drivers/staging/et131x/et1310_phy.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Agere Systems Inc.
* 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
* 10/100/1000 Base-T Ethernet Driver for the ET1310 and ET131x series MACs
*
* Copyright * 2005 Agere Systems Inc.
* All rights reserved.
Expand Down Expand Up @@ -82,6 +82,7 @@
#include <linux/if_arp.h>
#include <linux/ioport.h>
#include <linux/random.h>
#include <linux/phy.h>

#include "et1310_phy.h"

Expand All @@ -93,6 +94,40 @@

#include "et131x.h"

int et131x_mdio_read(struct mii_bus *bus, int phy_addr, int reg)
{
struct net_device *netdev = bus->priv;
struct et131x_adapter *adapter = netdev_priv(netdev);
u16 value;
int ret;

ret = et131x_phy_mii_read(adapter, phy_addr, reg, &value);

if (ret < 0)
return ret;
else
return value;
}

int et131x_mdio_write(struct mii_bus *bus, int phy_addr, int reg, u16 value)
{
struct net_device *netdev = bus->priv;
struct et131x_adapter *adapter = netdev_priv(netdev);

/* mii_write always uses the same phy_addr, xcvr_addr */
return et131x_mii_write(adapter, reg, value);
}

int et131x_mdio_reset(struct mii_bus *bus)
{
struct net_device *netdev = bus->priv;
struct et131x_adapter *adapter = netdev_priv(netdev);

et1310_phy_reset(adapter);

return 0;
}

/**
* et131x_phy_mii_read - Read from the PHY through the MII Interface on the MAC
* @adapter: pointer to our private adapter structure
Expand All @@ -107,7 +142,7 @@ int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 xcvr_addr,
{
struct mac_regs __iomem *mac = &adapter->regs->mac;
int status = 0;
u32 delay;
u32 delay = 0;
u32 mii_addr;
u32 mii_cmd;
u32 mii_indicator;
Expand All @@ -124,9 +159,6 @@ int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 xcvr_addr,
/* Set up the register we need to read from on the correct PHY */
writel(MII_ADDR(xcvr_addr, xcvr_reg), &mac->mii_mgmt_addr);

/* Kick the read cycle off */
delay = 0;

writel(0x1, &mac->mii_mgmt_cmd);

do {
Expand Down Expand Up @@ -176,7 +208,7 @@ int et131x_mii_write(struct et131x_adapter *adapter, u8 xcvr_reg, u16 value)
struct mac_regs __iomem *mac = &adapter->regs->mac;
int status = 0;
u8 xcvr_addr = adapter->stats.xcvr_addr;
u32 delay;
u32 delay = 0;
u32 mii_addr;
u32 mii_cmd;
u32 mii_indicator;
Expand All @@ -195,7 +227,6 @@ int et131x_mii_write(struct et131x_adapter *adapter, u8 xcvr_reg, u16 value)

/* Add the value to write to the registers to the mac */
writel(value, &mac->mii_mgmt_ctrl);
delay = 0;

do {
udelay(50);
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/et131x/et1310_phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ struct mi_regs {
u8 imr; /* Interrupt Mask Reg(Reg 0x18) */
u8 isr; /* Interrupt Status Reg(Reg 0x19) */
u8 psr; /* PHY Status Reg(Reg 0x1A) */
u8 lcr1; /* LED Control 1 Reg(Reg 0x1B) */
u8 lcr2; /* LED Control 2 Reg(Reg 0x1C) */
u8 lcr1; /* LED Control 1 Reg(Reg 0x1B) */
u8 lcr2; /* LED Control 2 Reg(Reg 0x1C) */
u8 mi_res4[3]; /* Future use by MI working group(Reg 0x1D - 0x1F) */
};

Expand Down
6 changes: 6 additions & 0 deletions drivers/staging/et131x/et131x.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ int32_t et131x_mii_write(struct et131x_adapter *adapter,
void et131x_mii_check(struct et131x_adapter *pAdapter,
u16 bmsr, u16 bmsr_ints);

int et131x_mdio_read(struct mii_bus *bus, int phy_addr, int reg);
int et131x_mdio_write(struct mii_bus *bus, int phy_addr, int reg, u16 value);
int et131x_mdio_reset(struct mii_bus *bus);

/* et1310_rx.c */
int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter);
void et131x_rx_dma_memory_free(struct et131x_adapter *adapter);
Expand Down Expand Up @@ -145,3 +149,5 @@ void et131x_handle_send_interrupt(struct et131x_adapter *adapter);
void et131x_free_busy_send_packets(struct et131x_adapter *adapter);
int et131x_send_packets(struct sk_buff *skb, struct net_device *netdev);

/* et131x_ethtool.c */
void et131x_set_ethtool_ops(struct net_device *netdev);
3 changes: 2 additions & 1 deletion drivers/staging/et131x/et131x_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ struct ce_stats {
struct et131x_adapter {
struct net_device *netdev;
struct pci_dev *pdev;

struct mii_bus *mii_bus;
struct phy_device *phydev;
struct work_struct task;

/* Flags that indicate current state of the adapter */
Expand Down
71 changes: 71 additions & 0 deletions drivers/staging/et131x/et131x_ethtool.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2011 Mark Einon
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Mark Einon <mark.einon@gmail.com>
*/
#include "et131x_version.h"
#include "et131x_defs.h"

#include <linux/types.h>
#include <linux/interrupt.h>
#include <linux/netdevice.h>
#include <linux/ethtool.h>
#include <linux/phy.h>
#include <linux/pci.h>

#include "et131x_adapter.h"
#include "et131x.h"

static int et131x_get_settings(struct net_device *netdev,
struct ethtool_cmd *cmd)
{
struct et131x_adapter *adapter = netdev_priv(netdev);

return phy_ethtool_gset(adapter->phydev, cmd);
}

static int et131x_set_settings(struct net_device *netdev,
struct ethtool_cmd *cmd)
{
struct et131x_adapter *adapter = netdev_priv(netdev);

return phy_ethtool_sset(adapter->phydev, cmd);
}

#define ET131X_DRVINFO_LEN 32 /* value from ethtool.h */
static void et131x_get_drvinfo(struct net_device *netdev,
struct ethtool_drvinfo *info)
{
struct et131x_adapter *adapter = netdev_priv(netdev);

strncpy(info->driver, DRIVER_NAME, ET131X_DRVINFO_LEN);
strncpy(info->version, DRIVER_VERSION_STRING, ET131X_DRVINFO_LEN);
strncpy(info->bus_info, pci_name(adapter->pdev), ET131X_DRVINFO_LEN);
}

static struct ethtool_ops et131x_ethtool_ops = {
.get_settings = et131x_get_settings,
.set_settings = et131x_set_settings,
.get_drvinfo = et131x_get_drvinfo,
.get_link = ethtool_op_get_link,
};

void et131x_set_ethtool_ops(struct net_device *netdev)
{
SET_ETHTOOL_OPS(netdev, &et131x_ethtool_ops);
}

Loading

0 comments on commit 0f18f76

Please sign in to comment.