9
0
Fork 0

add a device_d to ethernet devices

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2009-06-11 15:32:06 +02:00
parent 56139274fd
commit 2f8df2a003
15 changed files with 66 additions and 63 deletions

View File

@ -265,7 +265,6 @@ static int at91rm9200_eth_init (struct device_d *dev)
edev = malloc(sizeof(struct eth_device));
dev->priv = edev;
edev->dev = dev;
edev->open = at91rm9200_eth_open;
edev->send = at91rm9200_eth_send;

View File

@ -450,7 +450,6 @@ static int cs8900_probe(struct device_d *dev)
edev = (struct eth_device *)malloc(sizeof(struct eth_device));
dev->type_data = edev;
edev->priv = priv;
edev->dev = dev;
edev->init = cs8900_dev_init;
edev->open = cs8900_open;

View File

@ -480,7 +480,6 @@ static int dm9000_probe(struct device_d *dev)
edev = xzalloc(sizeof(struct eth_device) + sizeof(struct dm9000_priv));
dev->type_data = edev;
edev->dev = dev;
edev->priv = (struct dm9000_priv *)(edev + 1);
if (!dev->platform_data) {

View File

@ -538,7 +538,6 @@ static int fec_probe(struct device_d *dev)
dev->type_data = edev;
fec = (struct fec_priv *)malloc(sizeof(*fec));
edev->priv = fec;
edev->dev = dev;
edev->open = fec_open,
edev->init = fec_init,
edev->send = fec_send,

View File

@ -676,7 +676,6 @@ int mpc5xxx_fec_probe(struct device_d *dev)
dev->type_data = edev;
fec = (mpc5xxx_fec_priv *)malloc(sizeof(*fec));
edev->priv = fec;
edev->dev = dev;
edev->open = mpc5xxx_fec_open,
edev->init = mpc5xxx_fec_init,
edev->send = mpc5xxx_fec_send,

View File

@ -421,7 +421,6 @@ static int macb_probe(struct device_d *dev)
edev = xzalloc(sizeof(struct eth_device) + sizeof(struct macb_device));
dev->type_data = edev;
edev->dev = dev;
edev->priv = (struct macb_device *)(edev + 1);
macb = edev->priv;

View File

@ -26,6 +26,7 @@
#include <miiphy.h>
#include <clock.h>
#include <net.h>
#include <malloc.h>
int miiphy_restart_aneg(struct miiphy_device *mdev)
{
@ -175,10 +176,8 @@ static struct file_operations miiphy_ops = {
static int miiphy_probe(struct device_d *dev)
{
struct miiphy_device *mdev = dev->priv;
char name[MAX_DRIVER_NAME];
get_free_deviceid(name, "phy");
mdev->cdev.name = strdup(name);
mdev->cdev.name = asprintf("phy%d", dev->id);
mdev->cdev.size = 32;
mdev->cdev.ops = &miiphy_ops;
mdev->cdev.priv = mdev;
@ -186,6 +185,20 @@ static int miiphy_probe(struct device_d *dev)
return 0;
}
static void miiphy_remove(struct device_d *dev)
{
struct miiphy_device *mdev = dev->priv;
free(mdev->cdev.name);
devfs_remove(&mdev->cdev);
}
static struct driver_d miiphy_drv = {
.name = "miiphy",
.probe = miiphy_probe,
.remove = miiphy_remove,
};
int miiphy_register(struct miiphy_device *mdev)
{
mdev->dev.priv = mdev;
@ -194,10 +207,10 @@ int miiphy_register(struct miiphy_device *mdev)
return register_device(&mdev->dev);
}
static struct driver_d miiphy_drv = {
.name = "miiphy",
.probe = miiphy_probe,
};
void miiphy_unregister(struct miiphy_device *mdev)
{
unregister_device(&mdev->dev);
}
static int miiphy_init(void)
{

View File

@ -246,7 +246,6 @@ static int netx_eth_probe(struct device_d *dev)
edev = xzalloc(sizeof(struct eth_device) + sizeof(struct netx_eth_priv));
dev->type_data = edev;
edev->dev = dev;
edev->priv = (struct netx_priv *)(edev + 1);
priv = edev->priv;

View File

@ -717,7 +717,6 @@ static int smc911x_probe(struct device_d *dev)
edev = xzalloc(sizeof(struct eth_device) +
sizeof(struct smc911x_priv));
dev->type_data = edev;
edev->dev = dev;
edev->priv = (struct smc911x_priv *)(edev + 1);
priv = edev->priv;

View File

@ -89,7 +89,6 @@ int tap_probe(struct device_d *dev)
edev = malloc(sizeof(struct eth_device));
dev->type_data = edev;
edev->dev = dev;
edev->priv = priv;
edev->init = tap_eth_open;

View File

@ -154,7 +154,7 @@ static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
void *buf;
int err = -ENOMEM;
dev_dbg(dev->edev.dev, "asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d",
dev_dbg(&dev->edev.dev, "asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d",
cmd, value, index, size);
buf = malloc(size);
@ -187,7 +187,7 @@ static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
void *buf = NULL;
int err = -ENOMEM;
dev_dbg(dev->edev.dev, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d",
dev_dbg(&dev->edev.dev, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d",
cmd, value, index, size);
if (data) {
@ -218,7 +218,7 @@ static inline int asix_set_sw_mii(struct usbnet *dev)
int ret;
ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
if (ret < 0)
dev_err(dev->edev.dev, "Failed to enable software MII access");
dev_err(&dev->edev.dev, "Failed to enable software MII access");
return ret;
}
@ -227,7 +227,7 @@ static inline int asix_set_hw_mii(struct usbnet *dev)
int ret;
ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
if (ret < 0)
dev_err(dev->edev.dev, "Failed to enable hardware MII access");
dev_err(&dev->edev.dev, "Failed to enable hardware MII access");
return ret;
}
@ -243,7 +243,7 @@ static int asix_mdio_read(struct miiphy_device *mdev, uint8_t phy_id,
(__u16)loc, 2, &res);
asix_set_hw_mii(dev);
dev_dbg(dev->edev.dev, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x",
dev_dbg(&dev->edev.dev, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x",
phy_id, loc, le16_to_cpu(res));
*val = le16_to_cpu(res);
@ -258,7 +258,7 @@ static int asix_mdio_write(struct miiphy_device *mdev, uint8_t phy_id,
struct usbnet *dev = eth->priv;
__le16 res = cpu_to_le16(val);
dev_dbg(dev->edev.dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x",
dev_dbg(&dev->edev.dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x",
phy_id, loc, val);
asix_set_sw_mii(dev);
@ -273,13 +273,13 @@ static inline int asix_get_phy_addr(struct usbnet *dev)
u8 buf[2];
int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
dev_dbg(dev->edev.dev, "asix_get_phy_addr()");
dev_dbg(&dev->edev.dev, "asix_get_phy_addr()");
if (ret < 0) {
dev_err(dev->edev.dev, "Error reading PHYID register: %02x", ret);
dev_err(&dev->edev.dev, "Error reading PHYID register: %02x", ret);
goto out;
}
dev_dbg(dev->edev.dev, "asix_get_phy_addr() returning 0x%04x", *((__le16 *)buf));
dev_dbg(&dev->edev.dev, "asix_get_phy_addr() returning 0x%04x", *((__le16 *)buf));
ret = buf[1];
out:
@ -292,7 +292,7 @@ static int asix_sw_reset(struct usbnet *dev, u8 flags)
ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
if (ret < 0)
dev_err(dev->edev.dev, "Failed to send software reset: %02x", ret);
dev_err(&dev->edev.dev, "Failed to send software reset: %02x", ret);
return ret;
}
@ -303,7 +303,7 @@ static u16 asix_read_rx_ctl(struct usbnet *dev)
int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, &v);
if (ret < 0) {
dev_err(dev->edev.dev, "Error reading RX_CTL register: %02x", ret);
dev_err(&dev->edev.dev, "Error reading RX_CTL register: %02x", ret);
goto out;
}
ret = le16_to_cpu(v);
@ -315,10 +315,10 @@ static int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
{
int ret;
dev_dbg(dev->edev.dev, "asix_write_rx_ctl() - mode = 0x%04x", mode);
dev_dbg(&dev->edev.dev, "asix_write_rx_ctl() - mode = 0x%04x", mode);
ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
if (ret < 0)
dev_err(dev->edev.dev, "Failed to write RX_CTL mode to 0x%04x: %02x",
dev_err(&dev->edev.dev, "Failed to write RX_CTL mode to 0x%04x: %02x",
mode, ret);
return ret;
@ -330,7 +330,7 @@ static u16 asix_read_medium_status(struct usbnet *dev)
int ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
if (ret < 0) {
dev_err(dev->edev.dev, "Error reading Medium Status register: %02x", ret);
dev_err(&dev->edev.dev, "Error reading Medium Status register: %02x", ret);
goto out;
}
ret = le16_to_cpu(v);
@ -342,10 +342,10 @@ static int asix_write_medium_mode(struct usbnet *dev, u16 mode)
{
int ret;
dev_dbg(dev->edev.dev, "asix_write_medium_mode() - mode = 0x%04x", mode);
dev_dbg(&dev->edev.dev, "asix_write_medium_mode() - mode = 0x%04x", mode);
ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
if (ret < 0)
dev_err(dev->edev.dev, "Failed to write Medium Mode mode to 0x%04x: %02x",
dev_err(&dev->edev.dev, "Failed to write Medium Mode mode to 0x%04x: %02x",
mode, ret);
return ret;
@ -355,10 +355,10 @@ static int asix_write_gpio(struct usbnet *dev, u16 value, int sleep)
{
int ret;
dev_dbg(dev->edev.dev,"asix_write_gpio() - value = 0x%04x", value);
dev_dbg(&dev->edev.dev,"asix_write_gpio() - value = 0x%04x", value);
ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL);
if (ret < 0)
dev_err(dev->edev.dev, "Failed to write GPIO value 0x%04x: %02x",
dev_err(&dev->edev.dev, "Failed to write GPIO value 0x%04x: %02x",
value, ret);
if (sleep)

View File

@ -112,7 +112,7 @@ static int usbnet_send(struct eth_device *edev, void *eth_data, int data_length)
tx_buffer[len++] = 0;
ret = usb_bulk_msg(dev->udev, dev->out, tx_buffer, len, &alen, 1000);
dev_dbg(edev->dev, "%s: ret: %d len: %d alen: %d\n", __func__, ret, len, alen);
dev_dbg(&edev->dev, "%s: ret: %d len: %d alen: %d\n", __func__, ret, len, alen);
return ret;
}
@ -125,7 +125,7 @@ static int usbnet_recv(struct eth_device *edev)
struct driver_info *info = dev->driver_info;
int len, ret, alen = 0;
dev_dbg(edev->dev, "%s\n",__func__);
dev_dbg(&edev->dev, "%s\n",__func__);
len = dev->rx_urb_size;
@ -149,14 +149,14 @@ static int usbnet_init(struct eth_device *edev)
struct driver_info *info = dev->driver_info;
int ret = 0;
dev_dbg(edev->dev, "%s\n",__func__);
dev_dbg(&edev->dev, "%s\n",__func__);
/* put into "known safe" state */
if (info->reset)
ret = info->reset(dev);
if (ret) {
dev_info (edev->dev, "open reset fail (%d)", ret);
dev_info(&edev->dev, "open reset fail (%d)", ret);
return ret;
}
@ -169,7 +169,7 @@ static int usbnet_open(struct eth_device *edev)
{
struct usbnet *dev = (struct usbnet*)edev->priv;
dev_dbg(edev->dev, "%s\n",__func__);
dev_dbg(&edev->dev, "%s\n",__func__);
if (miiphy_wait_aneg(&dev->miiphy))
return -1;
@ -181,7 +181,7 @@ static int usbnet_open(struct eth_device *edev)
static void usbnet_halt(struct eth_device *edev)
{
dev_dbg(edev->dev, "%s\n",__func__);
dev_dbg(&edev->dev, "%s\n",__func__);
}
int usbnet_probe(struct usb_device *usbdev, const struct usb_device_id *prod)
@ -191,7 +191,7 @@ int usbnet_probe(struct usb_device *usbdev, const struct usb_device_id *prod)
struct driver_info *info;
int status;
dev_dbg(edev->dev, "%s\n", __func__);
dev_dbg(&edev->dev, "%s\n", __func__);
undev = xzalloc(sizeof (*undev));
@ -206,10 +206,6 @@ int usbnet_probe(struct usb_device *usbdev, const struct usb_device_id *prod)
edev->recv = usbnet_recv,
edev->halt = usbnet_halt,
edev->priv = undev;
edev->dev = &undev->dev;
get_free_deviceid(edev->dev->id, "eth");
sprintf(edev->dev->name, "%s", "usbnet");
info = (struct driver_info *)prod->driver_info;
undev->driver_info = info;
@ -224,14 +220,11 @@ int usbnet_probe(struct usb_device *usbdev, const struct usb_device_id *prod)
undev->rx_urb_size = 1514; /* FIXME: What to put here? */
undev->maxpacket = usb_maxpacket(undev->udev, undev->out);
/* FIXME: eth layer should have the device and register it */
register_device(edev->dev);
eth_register(edev);
return 0;
out1:
dev_dbg(edev->dev, "err: %d\n", status);
dev_dbg(&edev->dev, "err: %d\n", status);
return status;
}
@ -242,7 +235,7 @@ void usbnet_disconnect(struct usb_device *usbdev)
struct driver_info *info;
eth_unregister(edev);
unregister_device(edev->dev);
unregister_device(&edev->dev);
info = undev->driver_info;
if (info->unbind)

View File

@ -12,6 +12,7 @@
#ifndef __NET_H__
#define __NET_H__
#include <driver.h>
#include <linux/types.h>
#include <param.h>
#include <asm/byteorder.h> /* for nton* / ntoh* stuff */
@ -75,7 +76,7 @@ struct eth_device {
struct param_d param_serverip;
struct param_d param_ethaddr;
struct device_d *dev;
struct device_d dev;
struct list_head list;
};

View File

@ -44,12 +44,14 @@ struct eth_device * eth_get_current(void)
return eth_current;
}
struct eth_device *eth_get_byname(char *name)
struct eth_device *eth_get_byname(char *ethname)
{
struct eth_device *edev;
char name[MAX_DRIVER_NAME];
list_for_each_entry(edev, &netdev_list, list) {
if (!strcmp(edev->dev->id, name))
sprintf(name, "%s%d", edev->dev.name, edev->dev.id);
if (!strcmp(ethname, name))
return edev;
}
return NULL;
@ -120,7 +122,7 @@ static int eth_set_ipaddr(struct device_d *dev, struct param_d *param, const cha
int eth_register(struct eth_device *edev)
{
struct device_d *dev = edev->dev;
struct device_d *dev = &edev->dev;
unsigned char ethaddr_str[20];
unsigned char ethaddr[6];
@ -129,6 +131,9 @@ int eth_register(struct eth_device *edev)
return -1;
}
strcpy(edev->dev.name, "eth");
register_device(&edev->dev);
dev->type_data = edev;
edev->param_ip.name = "ipaddr";
edev->param_ip.set = &eth_set_ipaddr;

View File

@ -258,7 +258,7 @@ NetLoop(proto_t protocol)
return -1;
}
ip = dev_get_param_ip(eth_current->dev, "ipaddr");
ip = dev_get_param_ip(&eth_current->dev, "ipaddr");
NetCopyIP(&NetOurIP, &ip);
/* XXX problem with bss workaround */
@ -291,16 +291,16 @@ NetLoop(proto_t protocol)
return -1;
restart:
string_to_ethaddr(dev_get_param(eth_get_current()->dev, "ethaddr"),
string_to_ethaddr(dev_get_param(&eth_get_current()->dev, "ethaddr"),
NetOurEther);
NetState = NETLOOP_CONTINUE;
NetOurGatewayIP = dev_get_param_ip(eth_current->dev, "gateway");
NetOurSubnetMask = dev_get_param_ip(eth_current->dev, "netmask");
NetOurGatewayIP = dev_get_param_ip(&eth_current->dev, "gateway");
NetOurSubnetMask = dev_get_param_ip(&eth_current->dev, "netmask");
NetOurVLAN = getenv_VLAN("vlan");
NetOurNativeVLAN = getenv_VLAN("nvlan");
NetServerIP = dev_get_param_ip(eth_current->dev, "serverip");
NetServerIP = dev_get_param_ip(&eth_current->dev, "serverip");
/*
* Start the ball rolling with the given start function. From
@ -894,7 +894,7 @@ NetReceive(uchar * inpkt, int len)
static int net_check_prereq (proto_t protocol)
{
char *ethid = eth_get_current()->dev->id;
struct eth_device *edev = eth_get_current();
switch (protocol) {
/* Fall through */
@ -920,13 +920,13 @@ static int net_check_prereq (proto_t protocol)
case NETCONS:
case TFTP:
if (NetServerIP == 0) {
printf("*** ERROR: `%s.serverip' not set\n", ethid);
printf("*** ERROR: `%s.serverip' not set\n", dev_id(&edev->dev));
return (1);
}
common:
if (NetOurIP == 0) {
printf("*** ERROR: `%s.ipaddr' not set\n", ethid);
printf("*** ERROR: `%s.ipaddr' not set\n", dev_id(&edev->dev));
return (1);
}
/* Fall through */
@ -935,7 +935,7 @@ static int net_check_prereq (proto_t protocol)
case RARP:
case BOOTP:
if (memcmp (NetOurEther, "\0\0\0\0\0\0", 6) == 0) {
printf("*** ERROR: `%s.ethaddr' not set\n", ethid);
printf("*** ERROR: `%s.ethaddr' not set\n", dev_id(&edev->dev));
return (1);
}
/* Fall through */