Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f18f767 authored by Mark Einon's avatar Mark Einon Committed by Greg Kroah-Hartman
Browse files

staging: et131x: Use phy-device, mii_bus and ethtool_ops



Adding some basic ethtool ops and supporting functionality using a phy device.

Signed-off-by: default avatarMark Einon <mark.einon@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent fca7737f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
+38 −7
Original line number Diff line number Diff line
/*
 * 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.
@@ -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"

@@ -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
@@ -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;
@@ -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 {
@@ -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;
@@ -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);
+6 −0
Original line number Diff line number Diff line
@@ -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);
@@ -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);
+2 −1
Original line number Diff line number Diff line
@@ -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 */
+71 −0
Original line number Diff line number Diff line
/*
 *  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