Commit df13121f authored by David S. Miller's avatar David S. Miller

Merge davem@nuts.ninka.net:/home/davem/src/BK/net-2.5

into kernel.bkbits.net:/home/davem/net-2.5
parents ecdb3063 eb30a973
......@@ -1115,6 +1115,7 @@ static int __devinit vortex_probe1(struct device *gendev,
goto out;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, gendev);
vp = dev->priv;
option = global_options;
......
......@@ -1801,6 +1801,8 @@ static int __devinit cp_init_one (struct pci_dev *pdev,
if (!dev)
return -ENOMEM;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
cp = dev->priv;
cp->pdev = pdev;
cp->board_type = board_type;
......
......@@ -768,6 +768,8 @@ static int __devinit rtl8139_init_board (struct pci_dev *pdev,
return -ENOMEM;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
tp = dev->priv;
tp->pci_dev = pdev;
......
......@@ -131,26 +131,20 @@ static int __init probe_list(struct net_device *dev, struct devprobe *plist)
{
struct devprobe *p = plist;
unsigned long base_addr = dev->base_addr;
#ifdef CONFIG_NET_DIVERT
int ret;
#endif /* CONFIG_NET_DIVERT */
while (p->probe != NULL) {
if (base_addr && p->probe(dev) == 0) { /* probe given addr */
#ifdef CONFIG_NET_DIVERT
ret = alloc_divert_blk(dev);
if (ret)
return ret;
#endif /* CONFIG_NET_DIVERT */
return 0;
} else if (p->status == 0) { /* has autoprobe failed yet? */
p->status = p->probe(dev); /* no, try autoprobe */
if (p->status == 0) {
#ifdef CONFIG_NET_DIVERT
ret = alloc_divert_blk(dev);
if (ret)
return ret;
#endif /* CONFIG_NET_DIVERT */
return 0;
}
}
......
......@@ -188,6 +188,9 @@ MODULE_DEVICE_TABLE(pci, acenic_pci_tbl);
#define ACE_MOD_DEC_USE_COUNT do{} while(0)
#endif
#ifndef SET_NETDEV_DEV
#define SET_NETDEV_DEV(net, pdev) do{} while(0)
#endif
#if LINUX_VERSION_CODE >= 0x2051c
#define ace_sync_irq(irq) synchronize_irq(irq)
......@@ -651,6 +654,7 @@ int __devinit acenic_probe (ACE_PROBE_ARG)
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (!dev->priv)
dev->priv = kmalloc(sizeof(*ap), GFP_KERNEL);
......@@ -2428,7 +2432,7 @@ static inline void ace_tx_int(struct net_device *dev,
}
static void ace_interrupt(int irq, void *dev_id, struct pt_regs *ptregs)
static irqreturn_t ace_interrupt(int irq, void *dev_id, struct pt_regs *ptregs)
{
struct ace_private *ap;
struct ace_regs *regs;
......@@ -2446,7 +2450,7 @@ static void ace_interrupt(int irq, void *dev_id, struct pt_regs *ptregs)
* spending any time in here.
*/
if (!(readl(&regs->HostCtrl) & IN_INT))
return;
return IRQ_NONE;
/*
* ACK intr now. Otherwise we will lose updates to rx_ret_prd,
......@@ -2552,6 +2556,8 @@ static void ace_interrupt(int irq, void *dev_id, struct pt_regs *ptregs)
tasklet_schedule(&ap->ace_tasklet);
}
}
return IRQ_HANDLED;
}
......
......@@ -781,7 +781,7 @@ static int ace_init(struct net_device *dev);
static void ace_load_std_rx_ring(struct ace_private *ap, int nr_bufs);
static void ace_load_mini_rx_ring(struct ace_private *ap, int nr_bufs);
static void ace_load_jumbo_rx_ring(struct ace_private *ap, int nr_bufs);
static void ace_interrupt(int irq, void *dev_id, struct pt_regs *regs);
static irqreturn_t ace_interrupt(int irq, void *dev_id, struct pt_regs *regs);
static int ace_load_firmware(struct net_device *dev);
static int ace_open(struct net_device *dev);
static int ace_start_xmit(struct sk_buff *skb, struct net_device *dev);
......
......@@ -1542,6 +1542,7 @@ static int __devinit amd8111e_probe_one(struct pci_dev *pdev,
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
#if AMD8111E_VLAN_TAG_USED
dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX ;
......
......@@ -443,6 +443,7 @@ static int __devinit dfx_init_one_pci_or_eisa(struct pci_dev *pdev, long ioaddr)
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
bp = dev->priv;
......
......@@ -154,6 +154,7 @@ rio_probe1 (struct pci_dev *pdev, const struct pci_device_id *ent)
goto err_out_res;
}
SET_MODULE_OWNER (dev);
SET_NETDEV_DEV(dev, &pdev->dev);
#ifdef MEM_MAPPING
ioaddr = pci_resource_start (pdev, 1);
......
......@@ -591,6 +591,7 @@ e100_found1(struct pci_dev *pcid, const struct pci_device_id *ent)
bdp->device = dev;
pci_set_drvdata(pcid, dev);
SET_NETDEV_DEV(dev, &pcid->dev);
if ((rc = e100_alloc_space(bdp)) != 0) {
goto err_dev;
......
......@@ -391,6 +391,7 @@ e1000_probe(struct pci_dev *pdev,
goto err_alloc_etherdev;
SET_MODULE_OWNER(netdev);
SET_NETDEV_DEV(netdev, &pdev->dev);
pci_set_drvdata(pdev, netdev);
adapter = netdev->priv;
......
......@@ -678,6 +678,7 @@ static int __devinit speedo_found1(struct pci_dev *pdev,
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (dev->mem_start > 0)
option = dev->mem_start;
......@@ -829,6 +830,7 @@ static int __devinit speedo_found1(struct pci_dev *pdev,
pci_set_power_state(pdev, acpi_idle_state);
pci_set_drvdata (pdev, dev);
SET_NETDEV_DEV(dev, &pdev->dev);
dev->irq = pdev->irq;
......
......@@ -409,6 +409,7 @@ static int __devinit epic_init_one (struct pci_dev *pdev,
return -ENOMEM;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (pci_request_regions(pdev, DRV_NAME))
goto err_out_free_netdev;
......
......@@ -539,6 +539,7 @@ static int __devinit fealnx_init_one(struct pci_dev *pdev,
goto err_out_unmap;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
/* read ethernet id */
for (i = 0; i < 6; ++i)
......
......@@ -613,6 +613,7 @@ static int __init hamachi_init_one (struct pci_dev *pdev,
goto err_out_iounmap;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
#ifdef TX_CHECKSUM
printk("check that skbcopy in ip_queue_xmit isn't happening\n");
......
......@@ -776,6 +776,7 @@ static int __init hp100_probe1(struct net_device *dev, int ioaddr,
hp100_clear_stats(lp, ioaddr);
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pci_dev->dev);
ether_setup(dev);
/* If busmaster mode is wanted, a dma-capable memory area is needed for
......
......@@ -1532,6 +1532,8 @@ static int __devinit ioc3_probe(struct pci_dev *pdev,
goto out_free;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
ip = dev->priv;
ip->dev = dev;
......
......@@ -333,6 +333,7 @@ ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
}
SET_MODULE_OWNER(netdev);
SET_NETDEV_DEV(netdev, &pdev->dev);
pci_set_drvdata(pdev, netdev);
adapter = netdev->priv;
......
......@@ -762,6 +762,7 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
if (!dev)
return -ENOMEM;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
i = pci_request_regions(pdev, dev->name);
if (i) {
......
......@@ -265,6 +265,7 @@ static int __devinit ne2k_pci_init_one (struct pci_dev *pdev,
goto err_out_free_res;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
/* Reset card. Who knows what dain-bramaged state it was left in. */
{
......
......@@ -1586,6 +1586,7 @@ static void ns83820_run_bist(struct ns83820 *dev, const char *name, u32 enable,
dprintk("%s: done %s in %d loops\n", dev->net_dev.name, name, loops);
}
#ifdef PHY_CODE_IS_FINISHED
static void ns83820_mii_write_bit(struct ns83820 *dev, int bit)
{
/* drive MDC low */
......@@ -1758,6 +1759,7 @@ static void ns83820_probe_phy(struct ns83820 *dev)
dprintk("version: 0x%04x 0x%04x\n", a, b);
}
}
#endif
static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_device_id *id)
{
......@@ -1788,7 +1790,8 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
dev->ee.cache = &dev->MEAR_cache;
dev->ee.lock = &dev->misc_lock;
dev->net_dev.owner = THIS_MODULE;
SET_MODULE_OWNER(dev->net_dev);
SET_NETDEV_DEV(&dev->net_dev, &pci_dev->dev);
dev->net_dev.priv = dev;
INIT_WORK(&dev->tq_refill, queue_refill, dev);
......
......@@ -610,6 +610,7 @@ static int __devinit netdrv_init_board (struct pci_dev *pdev,
return -ENOMEM;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
tp = dev->priv;
/* enable device (incl. PCI PM wakeup), and bus-mastering */
......
......@@ -638,6 +638,7 @@ pcnet32_probe1(unsigned long ioaddr, unsigned int irq_line, int shared,
release_region(ioaddr, PCNET32_TOTAL_SIZE);
return -ENOMEM;
}
SET_NETDEV_DEV(dev, &pdev->dev);
printk(KERN_INFO PFX "%s at %#3lx,", chipname, ioaddr);
......@@ -718,6 +719,7 @@ pcnet32_probe1(unsigned long ioaddr, unsigned int irq_line, int shared,
spin_lock_init(&lp->lock);
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
dev->priv = lp;
lp->name = chipname;
lp->shared_irq = shared;
......
......@@ -373,6 +373,7 @@ rtl8169_init_board(struct pci_dev *pdev, struct net_device **dev_out,
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
tp = dev->priv;
// enable device (incl. PCI PM wakeup and hotplug setup)
......
......@@ -179,6 +179,7 @@ rcpci45_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
goto err_out;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
error = pci_enable_device (pdev);
if (error) {
......
......@@ -114,6 +114,7 @@ static int __devinit rr_init_one(struct pci_dev *pdev,
rrpriv = (struct rr_private *)dev->priv;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (pci_request_regions(pdev, "rrunner")) {
ret = -EIO;
......
......@@ -190,6 +190,7 @@ sb1000_probe_one(struct pnp_dev *pdev, const struct pnp_device_id *id)
dev->flags = IFF_POINTOPOINT|IFF_NOARP;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (sb1000_debug > 0)
printk(KERN_NOTICE "%s", version);
......
......@@ -397,6 +397,7 @@ static int __devinit sis900_probe (struct pci_dev *pci_dev, const struct pci_dev
if (!net_dev)
return -ENOMEM;
SET_MODULE_OWNER(net_dev);
SET_NETDEV_DEV(net_dev, &pci_dev->dev);
/* We do a request_region() to register /proc/ioports info. */
ioaddr = pci_resource_start(pci_dev, 0);
......
......@@ -460,6 +460,7 @@ static int __init skge_probe (void)
dev->irq = pdev->irq;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
dev->open = &SkGeOpen;
dev->stop = &SkGeClose;
dev->hard_start_xmit = &SkGeXmit;
......
......@@ -207,6 +207,7 @@ int __init ultramca_probe(struct device *gen_dev)
return -ENODEV;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, gen_dev);
if((i = register_netdev(dev)) != 0)
return i;
......
......@@ -876,6 +876,7 @@ static int __devinit starfire_init_one(struct pci_dev *pdev,
return -ENOMEM;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
irq = pdev->irq;
......
......@@ -548,6 +548,7 @@ static int __devinit sundance_probe1 (struct pci_dev *pdev,
if (!dev)
return -ENOMEM;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (pci_request_regions(pdev, DRV_NAME))
goto err_out_netdev;
......
......@@ -2703,6 +2703,7 @@ static int __devinit gem_init_one(struct pci_dev *pdev,
return -ENOMEM;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
gp = dev->priv;
......
......@@ -3025,6 +3025,7 @@ static int __init happy_meal_pci_init(struct pci_dev *pdev)
if (!dev)
goto err_out;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (hme_version_printed++ == 0)
printk(KERN_INFO "%s", version);
......
......@@ -6764,6 +6764,7 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (pci_using_dac)
dev->features |= NETIF_F_HIGHDMA;
......
......@@ -521,6 +521,7 @@ static int __devinit TLan_probe1(struct pci_dev *pdev,
return -ENOMEM;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
priv = dev->priv;
......
......@@ -2006,6 +2006,7 @@ static int __init de_init_one (struct pci_dev *pdev,
return -ENOMEM;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
dev->open = de_open;
dev->stop = de_close;
dev->set_multicast_list = de_set_rx_mode;
......
......@@ -1350,6 +1350,7 @@ de4x5_hw_init(struct net_device *dev, u_long iobase, struct pci_dev *pdev)
/* The DE4X5-specific entries in the device structure. */
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
dev->open = &de4x5_open;
dev->hard_start_xmit = &de4x5_queue_pkt;
dev->stop = &de4x5_close;
......
......@@ -348,6 +348,7 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
if (dev == NULL)
return -ENOMEM;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (pci_set_dma_mask(pdev, 0xffffffff)) {
printk(KERN_WARNING DRV_NAME ": 32-bit PCI DMA not available.\n");
......
......@@ -1360,6 +1360,7 @@ static int __devinit tulip_init_one (struct pci_dev *pdev,
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (pci_resource_len (pdev, 0) < tulip_tbl[chip_idx].io_size) {
printk (KERN_ERR PFX "%s: I/O region (0x%lx@0x%lx) too small, "
"aborting\n", pdev->slot_name,
......
......@@ -423,6 +423,7 @@ static int __devinit w840_probe1 (struct pci_dev *pdev,
if (!dev)
return -ENOMEM;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (pci_request_regions(pdev, DRV_NAME))
goto err_out_netdev;
......
......@@ -276,6 +276,7 @@ static int __devinit xircom_probe(struct pci_dev *pdev, const struct pci_device_
return -ENODEV;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
printk(KERN_INFO "%s: Xircom cardbus revision %i at irq %i \n", dev->name, chip_rev, pdev->irq);
private->dev = dev;
......
......@@ -560,6 +560,7 @@ static int __devinit xircom_init_one(struct pci_dev *pdev, const struct pci_devi
return -ENOMEM;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
dev->base_addr = ioaddr;
dev->irq = pdev->irq;
......
......@@ -2266,6 +2266,7 @@ typhoon_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
goto error_out;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
err = pci_enable_device(pdev);
if(err < 0) {
......
......@@ -660,6 +660,7 @@ static int __devinit via_rhine_init_one (struct pci_dev *pdev,
goto err_out;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
if (pci_request_regions(pdev, shortname))
goto err_out_free_netdev;
......
......@@ -13,6 +13,10 @@
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
* ============================================================================
* Please look at the bitkeeper changelog (or any other scm tool that ends up
* importing bitkeeper changelog or that replaces bitkeeper in the future as
* main tool for linux development).
*
* 2001/05/09 acme Fix MODULE_DESC for debug, .bss nitpicks,
* some cleanups
* 2000/07/13 acme remove useless #ifdef MODULE and crap
......@@ -46,11 +50,8 @@
#include <linux/ioport.h> /* request_region(), release_region() */
#include <linux/wanrouter.h> /* WAN router definitions */
#include <linux/cyclomx.h> /* cyclomx common user API definitions */
#include <asm/uaccess.h> /* kernel <-> user copy */
#include <linux/init.h> /* __init (when not using as a module) */
/* Debug */
unsigned int cycx_debug;
MODULE_AUTHOR("Arnaldo Carvalho de Melo");
......@@ -61,18 +62,17 @@ MODULE_PARM_DESC(cycx_debug, "cyclomx debug level");
/* Defines & Macros */
#define DRV_VERSION 0 /* version number */
#define DRV_RELEASE 10 /* release (minor version) number */
#define MAX_CARDS 1 /* max number of adapters */
#define CYCX_DRV_VERSION 0 /* version number */
#define CYCX_DRV_RELEASE 11 /* release (minor version) number */
#define CYCX_MAX_CARDS 1 /* max number of adapters */
#define CONFIG_CYCLOMX_CARDS 1
#define CONFIG_CYCX_CARDS 1
/* Function Prototypes */
/* WAN link driver entry points */
static int setup(struct wan_device *wandev, wandev_conf_t *conf);
static int shutdown(struct wan_device *wandev);
static int ioctl(struct wan_device *wandev, unsigned cmd, unsigned long arg);
static int cycx_wan_setup(struct wan_device *wandev, wandev_conf_t *conf);
static int cycx_wan_shutdown(struct wan_device *wandev);
/* Miscellaneous functions */
static irqreturn_t cycx_isr(int irq, void *dev_id, struct pt_regs *regs);
......@@ -82,12 +82,12 @@ static irqreturn_t cycx_isr(int irq, void *dev_id, struct pt_regs *regs);
*/
/* private data */
static char drvname[] = "cyclomx";
static char fullname[] = "CYCLOM 2X(tm) Sync Card Driver";
static char copyright[] = "(c) 1998-2001 Arnaldo Carvalho de Melo "
static char cycx_drvname[] = "cyclomx";
static char cycx_fullname[] = "CYCLOM 2X(tm) Sync Card Driver";
static char cycx_copyright[] = "(c) 1998-2003 Arnaldo Carvalho de Melo "
"<acme@conectiva.com.br>";
static int ncards = CONFIG_CYCLOMX_CARDS;
static struct cycx_device *card_array; /* adapter data space */
static int cycx_ncards = CONFIG_CYCX_CARDS;
static struct cycx_device *cycx_card_array; /* adapter data space */
/* Kernel Loadable Module Entry Points */
......@@ -103,51 +103,52 @@ static struct cycx_device *card_array; /* adapter data space */
* < 0 error.
* Context: process
*/
int __init cyclomx_init(void)
int __init cycx_init(void)
{
int cnt, err = -ENOMEM;
printk(KERN_INFO "%s v%u.%u %s\n",
fullname, DRV_VERSION, DRV_RELEASE, copyright);
cycx_fullname, CYCX_DRV_VERSION, CYCX_DRV_RELEASE,
cycx_copyright);
/* Verify number of cards and allocate adapter data space */
ncards = min_t(int, ncards, MAX_CARDS);
ncards = max_t(int, ncards, 1);
card_array = kmalloc(sizeof(struct cycx_device) * ncards, GFP_KERNEL);
if (!card_array)
cycx_ncards = min_t(int, cycx_ncards, CYCX_MAX_CARDS);
cycx_ncards = max_t(int, cycx_ncards, 1);
cycx_card_array = kmalloc(sizeof(struct cycx_device) * cycx_ncards,
GFP_KERNEL);
if (!cycx_card_array)
goto out;
memset(card_array, 0, sizeof(struct cycx_device) * ncards);
memset(cycx_card_array, 0, sizeof(struct cycx_device) * cycx_ncards);
/* Register adapters with WAN router */
for (cnt = 0; cnt < ncards; ++cnt) {
struct cycx_device *card = &card_array[cnt];
for (cnt = 0; cnt < cycx_ncards; ++cnt) {
struct cycx_device *card = &cycx_card_array[cnt];
struct wan_device *wandev = &card->wandev;
sprintf(card->devname, "%s%d", drvname, cnt + 1);
sprintf(card->devname, "%s%d", cycx_drvname, cnt + 1);
wandev->magic = ROUTER_MAGIC;
wandev->name = card->devname;
wandev->private = card;
wandev->setup = setup;
wandev->shutdown = shutdown;
wandev->ioctl = ioctl;
wandev->setup = cycx_wan_setup;
wandev->shutdown = cycx_wan_shutdown;
err = register_wan_device(wandev);
if (err) {
printk(KERN_ERR "%s: %s registration failed with "
"error %d!\n",
drvname, card->devname, err);
cycx_drvname, card->devname, err);
break;
}
}
err = -ENODEV;
if (!cnt) {
kfree(card_array);
kfree(cycx_card_array);
goto out;
}
err = 0;
ncards = cnt; /* adjust actual number of cards */
cycx_ncards = cnt; /* adjust actual number of cards */
out: return err;
}
......@@ -156,16 +157,16 @@ out: return err;
* o unregister all adapters from the WAN router
* o release all remaining system resources
*/
static void __exit cyclomx_cleanup(void)
static void __exit cycx_exit(void)
{
int i = 0;
for (; i < ncards; ++i) {
struct cycx_device *card = &card_array[i];
for (; i < cycx_ncards; ++i) {
struct cycx_device *card = &cycx_card_array[i];
unregister_wan_device(card->devname);
}
kfree(card_array);
kfree(cycx_card_array);
}
/* WAN Device Driver Entry Points */
......@@ -181,9 +182,9 @@ static void __exit cyclomx_cleanup(void)
* configuration structure is in kernel memory (including extended data, if
* any).
*/
static int setup(struct wan_device *wandev, wandev_conf_t *conf)
static int cycx_wan_setup(struct wan_device *wandev, wandev_conf_t *conf)
{
int err = -EFAULT;
int rc = -EFAULT;
struct cycx_device *card;
int irq;
......@@ -193,11 +194,11 @@ static int setup(struct wan_device *wandev, wandev_conf_t *conf)
goto out;
card = wandev->private;
err = -EBUSY;
rc = -EBUSY;
if (wandev->state != WAN_UNCONFIGURED)
goto out;
err = -EINVAL;
rc = -EINVAL;
if (!conf->data_size || !conf->data) {
printk(KERN_ERR "%s: firmware not found in configuration "
"data!\n", wandev->name);
......@@ -228,8 +229,8 @@ static int setup(struct wan_device *wandev, wandev_conf_t *conf)
card->lock = SPIN_LOCK_UNLOCKED;
init_waitqueue_head(&card->wait_stats);
err = cycx_setup(&card->hw, conf->data, conf->data_size);
if (err)
rc = cycx_setup(&card->hw, conf->data, conf->data_size);
if (rc)
goto out_irq;
/* Initialize WAN device data space */
......@@ -244,22 +245,23 @@ static int setup(struct wan_device *wandev, wandev_conf_t *conf)
switch (card->hw.fwid) {
#ifdef CONFIG_CYCLOMX_X25
case CFID_X25_2X:
err = cyx_init(card, conf);
rc = cycx_x25_wan_init(card, conf);
break;
#endif
default:
printk(KERN_ERR "%s: this firmware is not supported!\n",
wandev->name);
err = -EINVAL;
rc = -EINVAL;
}
if (err) {
if (rc) {
cycx_down(&card->hw);
goto out_irq;
}
err = 0;
out: return err;
rc = 0;
out:
return rc;
out_irq:
free_irq(irq, card);
goto out;
......@@ -273,7 +275,7 @@ out: return err;
* This function is called by the router when device is being unregistered or
* when it handles ROUTER_DOWN IOCTL.
*/
static int shutdown(struct wan_device *wandev)
static int cycx_wan_shutdown(struct wan_device *wandev)
{
int ret = -EFAULT;
struct cycx_device *card;
......@@ -295,21 +297,6 @@ static int shutdown(struct wan_device *wandev)
out: return ret;
}
/*
* Driver I/O control.
* o verify arguments
* o perform requested action
*
* This function is called when router handles one of the reserved user
* IOCTLs. Note that 'arg' still points to user address space.
*
* no reserved ioctls for the cyclom 2x up to now
*/
static int ioctl(struct wan_device *wandev, unsigned cmd, unsigned long arg)
{
return -EINVAL;
}
/* Miscellaneous */
/*
* Cyclom 2X Interrupt Service Routine.
......@@ -332,11 +319,12 @@ static irqreturn_t cycx_isr(int irq, void *dev_id, struct pt_regs *regs)
if (card->isr)
card->isr(card);
return IRQ_HANDLED;
out: return IRQ_NONE;
out:
return IRQ_NONE;
}
/* Set WAN device state. */
void cyclomx_set_state(struct cycx_device *card, int state)
void cycx_set_state(struct cycx_device *card, int state)
{
unsigned long flags;
char *string_state = NULL;
......@@ -360,5 +348,5 @@ void cyclomx_set_state(struct cycx_device *card, int state)
spin_unlock_irqrestore(&card->lock, flags);
}
module_init(cyclomx_init);
module_exit(cyclomx_cleanup);
module_init(cycx_init);
module_exit(cycx_exit);
This diff is collapsed.
......@@ -444,6 +444,7 @@ static int __devinit yellowfin_init_one(struct pci_dev *pdev,
return -ENOMEM;
}
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
np = dev->priv;
......
......@@ -2597,7 +2597,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
return status;
}
dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
SET_NETDEV_DEV(&dev->net, &dev->udev->dev);
register_netdev (&dev->net);
devinfo (dev, "register usbnet at usb-%s-%s, %s",
xdev->bus->bus_name, xdev->devpath,
......
......@@ -71,10 +71,10 @@ struct cycx_device {
};
/* Public Functions */
void cyclomx_set_state(struct cycx_device *card, int state);
void cycx_set_state(struct cycx_device *card, int state);
#ifdef CONFIG_CYCLOMX_X25
int cyx_init(struct cycx_device *card, wandev_conf_t *conf);
int cycx_x25_wan_init(struct cycx_device *card, wandev_conf_t *conf);
#endif
#endif /* __KERNEL__ */
#endif /* _CYCLOMX_H */
......@@ -107,11 +107,24 @@ struct divert_cf
/* diverter functions */
#include <linux/skbuff.h>
#ifdef CONFIG_NET_DIVERT
int alloc_divert_blk(struct net_device *);
void free_divert_blk(struct net_device *);
int divert_ioctl(unsigned int cmd, struct divert_cf *arg);
void divert_frame(struct sk_buff *skb);
static inline void handle_diverter(struct sk_buff *skb)
{
/* if diversion is supported on device, then divert */
if (skb->dev->divert && skb->dev->divert->divert)
divert_frame(skb);
}
#else
# define alloc_divert_blk(dev) (0)
# define free_divert_blk(dev) do {} while (0)
# define divert_ioctl(cmd, arg) (-ENOPKG)
# define handle_diverter(skb) do {} while (0)
#endif
#endif
#endif /* _LINUX_DIVERT_H */
......@@ -28,7 +28,7 @@
#include <linux/if.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <linux/kobject.h>
#include <linux/device.h>
#include <asm/atomic.h>
#include <asm/cache.h>
......@@ -441,11 +441,22 @@ struct net_device
struct divert_blk *divert;
#endif /* CONFIG_NET_DIVERT */
/* generic object representation */
struct kobject kobj;
/* generic device structure used in constructing class */
struct device *dev;
/* class/net/name entry */
struct class_device class_dev;
/* statistics sub-directory */
struct kobject stats_kobj;
};
#define SET_MODULE_OWNER(dev) do { } while (0)
/* Set the sysfs physical device reference for the network logical device
* if set prior to registration will cause a symlink during initialization.
*/
#define SET_NETDEV_DEV(net, pdev) ((net)->dev = (pdev))
struct packet_type
{
......@@ -561,12 +572,12 @@ static inline void netif_stop_queue(struct net_device *dev)
set_bit(__LINK_STATE_XOFF, &dev->state);
}
static inline int netif_queue_stopped(struct net_device *dev)
static inline int netif_queue_stopped(const struct net_device *dev)
{
return test_bit(__LINK_STATE_XOFF, &dev->state);
}
static inline int netif_running(struct net_device *dev)
static inline int netif_running(const struct net_device *dev)
{
return test_bit(__LINK_STATE_START, &dev->state);
}
......@@ -606,7 +617,9 @@ extern int netif_rx(struct sk_buff *skb);
#define HAVE_NETIF_RECEIVE_SKB 1
extern int netif_receive_skb(struct sk_buff *skb);
extern int dev_ioctl(unsigned int cmd, void *);
extern unsigned dev_get_flags(const struct net_device *);
extern int dev_change_flags(struct net_device *, unsigned);
extern int dev_set_mtu(struct net_device *, int);
extern void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
extern void dev_init(void);
......@@ -642,7 +655,7 @@ static inline void dev_put(struct net_device *dev)
extern void linkwatch_fire_event(struct net_device *dev);
static inline int netif_carrier_ok(struct net_device *dev)
static inline int netif_carrier_ok(const struct net_device *dev)
{
return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
}
......
......@@ -75,7 +75,7 @@ static void add_stats(char *buf,const char *aal,
}
static void dev_info(const struct atm_dev *dev,char *buf)
static void atm_dev_info(const struct atm_dev *dev,char *buf)
{
int off,i;
......@@ -319,7 +319,7 @@ static int atm_devices_info(loff_t pos,char *buf)
list_for_each(p, &atm_devs) {
dev = list_entry(p, struct atm_dev, dev_list);
if (left-- == 0) {
dev_info(dev,buf);
atm_dev_info(dev,buf);
spin_unlock(&atm_dev_lock);
return strlen(buf);
}
......
......@@ -620,13 +620,11 @@ static struct nf_hook_ops br_nf_ops[] = {
.priority = NF_IP_PRI_FIRST, },
};
#define NUMHOOKS (sizeof(br_nf_ops)/sizeof(br_nf_ops[0]))
int br_netfilter_init(void)
{
int i;
for (i = 0; i < NUMHOOKS; i++) {
for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
int ret;
if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
......@@ -647,6 +645,6 @@ void br_netfilter_fini(void)
{
int i;
for (i = NUMHOOKS - 1; i >= 0; i--)
for (i = ARRAY_SIZE(br_nf_ops) - 1; i >= 0; i--)
nf_unregister_hook(&br_nf_ops[i]);
}
......@@ -98,7 +98,7 @@ static int __init init(void)
ret = ebt_register_table(&frame_filter);
if (ret < 0)
return ret;
for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
for (i = 0; i < ARRAY_SIZE(ebt_ops_filter); i++)
if ((ret = nf_register_hook(&ebt_ops_filter[i])) < 0)
goto cleanup;
return ret;
......@@ -113,7 +113,7 @@ static void __exit fini(void)
{
int i;
for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
for (i = 0; i < ARRAY_SIZE(ebt_ops_filter); i++)
nf_unregister_hook(&ebt_ops_filter[i]);
ebt_unregister_table(&frame_filter);
}
......
......@@ -10,6 +10,7 @@
#include <linux/netfilter_bridge/ebtables.h>
#include <linux/module.h>
#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
(1 << NF_BR_POST_ROUTING))
......@@ -104,7 +105,7 @@ static int __init init(void)
ret = ebt_register_table(&frame_nat);
if (ret < 0)
return ret;
for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
for (i = 0; i < ARRAY_SIZE(ebt_ops_nat); i++)
if ((ret = nf_register_hook(&ebt_ops_nat[i])) < 0)
goto cleanup;
return ret;
......@@ -119,7 +120,7 @@ static void __exit fini(void)
{
int i;
for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
for (i = 0; i < ARRAY_SIZE(ebt_ops_nat); i++)
nf_unregister_hook(&ebt_ops_nat[i]);
ebt_unregister_table(&frame_nat);
}
......
......@@ -10,7 +10,8 @@ obj-y += sysctl_net_core.o
endif
endif
obj-$(CONFIG_NET) += flow.o dev.o dev_mcast.o dst.o neighbour.o rtnetlink.o utils.o link_watch.o filter.o
obj-$(CONFIG_NET) += flow.o dev.o net-sysfs.o dev_mcast.o dst.o neighbour.o \
rtnetlink.o utils.o link_watch.o filter.o
obj-$(CONFIG_NETFILTER) += netfilter.o
obj-$(CONFIG_NET_DIVERT) += dv.o
......
......@@ -131,16 +131,6 @@ extern int plip_init(void);
NET_PROFILE_DEFINE(dev_queue_xmit)
NET_PROFILE_DEFINE(softnet_process)
const char *if_port_text[] = {
"unknown",
"BNC",
"10baseT",
"AUI",
"100baseT",
"100baseTX",
"100baseFX"
};
/*
* The list of packet types we will receive (as opposed to discard)
* and the routines to invoke.
......@@ -203,7 +193,9 @@ int netdev_fastroute;
int netdev_fastroute_obstacles;
#endif
static struct subsystem net_subsys;
extern int netdev_sysfs_init(void);
extern int netdev_register_sysfs(struct net_device *);
extern void netdev_unregister_sysfs(struct net_device *);
/*******************************************************************************
......@@ -1465,15 +1457,6 @@ static __inline__ int handle_bridge(struct sk_buff *skb,
#endif
static inline void handle_diverter(struct sk_buff *skb)
{
#ifdef CONFIG_NET_DIVERT
/* if diversion is supported on device, then divert */
if (skb->dev->divert && skb->dev->divert->divert)
divert_frame(skb);
#endif
}
static inline int __handle_bridge(struct sk_buff *skb,
struct packet_type **pt_prev, int *ret)
{
......@@ -2084,6 +2067,22 @@ void dev_set_allmulti(struct net_device *dev, int inc)
dev_mc_upload(dev);
}
unsigned dev_get_flags(const struct net_device *dev)
{
unsigned flags;
flags = (dev->flags & ~(IFF_PROMISC |
IFF_ALLMULTI |
IFF_RUNNING)) |
(dev->gflags & (IFF_PROMISC |
IFF_ALLMULTI));
if (netif_running(dev) && netif_carrier_ok(dev))
flags |= IFF_RUNNING;
return flags;
}
int dev_change_flags(struct net_device *dev, unsigned flags)
{
int ret;
......@@ -2146,6 +2145,32 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
return ret;
}
int dev_set_mtu(struct net_device *dev, int new_mtu)
{
int err;
if (new_mtu == dev->mtu)
return 0;
/* MTU must be positive. */
if (new_mtu < 0)
return -EINVAL;
if (!netif_device_present(dev))
return -ENODEV;
err = 0;
if (dev->change_mtu)
err = dev->change_mtu(dev, new_mtu);
else
dev->mtu = new_mtu;
if (!err && dev->flags & IFF_UP)
notifier_call_chain(&netdev_chain,
NETDEV_CHANGEMTU, dev);
return err;
}
/*
* Perform the SIOCxIFxxx calls.
*/
......@@ -2159,13 +2184,7 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
switch (cmd) {
case SIOCGIFFLAGS: /* Get interface flags */
ifr->ifr_flags = (dev->flags & ~(IFF_PROMISC |
IFF_ALLMULTI |
IFF_RUNNING)) |
(dev->gflags & (IFF_PROMISC |
IFF_ALLMULTI));
if (netif_running(dev) && netif_carrier_ok(dev))
ifr->ifr_flags |= IFF_RUNNING;
ifr->ifr_flags = dev_get_flags(dev);
return 0;
case SIOCSIFFLAGS: /* Set interface flags */
......@@ -2185,27 +2204,7 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
return 0;
case SIOCSIFMTU: /* Set the MTU of a device */
if (ifr->ifr_mtu == dev->mtu)
return 0;
/*
* MTU must be positive.
*/
if (ifr->ifr_mtu < 0)
return -EINVAL;
if (!netif_device_present(dev))
return -ENODEV;
err = 0;
if (dev->change_mtu)
err = dev->change_mtu(dev, ifr->ifr_mtu);
else
dev->mtu = ifr->ifr_mtu;
if (!err && dev->flags & IFF_UP)
notifier_call_chain(&netdev_chain,
NETDEV_CHANGEMTU, dev);
return err;
return dev_set_mtu(dev, ifr->ifr_mtu);
case SIOCGIFHWADDR:
memcpy(ifr->ifr_hwaddr.sa_data, dev->dev_addr,
......@@ -2293,6 +2292,7 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
return -EEXIST;
memcpy(dev->name, ifr->ifr_newname, IFNAMSIZ);
dev->name[IFNAMSIZ - 1] = 0;
snprintf(dev->class_dev.class_id, BUS_ID_SIZE, dev->name);
notifier_call_chain(&netdev_chain,
NETDEV_CHANGENAME, dev);
return 0;
......@@ -2568,11 +2568,9 @@ int register_netdevice(struct net_device *dev)
dev->fastpath_lock = RW_LOCK_UNLOCKED;
#endif
#ifdef CONFIG_NET_DIVERT
ret = alloc_divert_blk(dev);
if (ret)
goto out;
#endif /* CONFIG_NET_DIVERT */
dev->iflink = -1;
......@@ -2591,11 +2589,10 @@ int register_netdevice(struct net_device *dev)
if (d == dev || !strcmp(d->name, dev->name))
goto out_err;
}
snprintf(dev->kobj.name,KOBJ_NAME_LEN,dev->name);
kobj_set_kset_s(dev,net_subsys);
if ((ret = kobject_register(&dev->kobj)))
goto out_err;
if ((ret = netdev_register_sysfs(dev)))
goto out_err;
/* Fix illegal SG+CSUM combinations. */
if ((dev->features & NETIF_F_SG) &&
!(dev->features & (NETIF_F_IP_CSUM |
......@@ -2638,9 +2635,7 @@ int register_netdevice(struct net_device *dev)
out:
return ret;
out_err:
#ifdef CONFIG_NET_DIVERT
free_divert_blk(dev);
#endif
goto out;
}
......@@ -2845,11 +2840,9 @@ int unregister_netdevice(struct net_device *dev)
/* Notifier chain MUST detach us from master device. */
BUG_TRAP(!dev->master);
#ifdef CONFIG_NET_DIVERT
free_divert_blk(dev);
#endif
kobject_unregister(&dev->kobj);
netdev_unregister_sysfs(dev);
spin_lock(&unregister_todo_lock);
dev->next = unregister_todo;
......@@ -2874,8 +2867,6 @@ extern void ip_auto_config(void);
extern void dv_init(void);
#endif /* CONFIG_NET_DIVERT */
static decl_subsys(net,NULL,NULL);
/*
* This is called single threaded during boot, so no need
......@@ -2891,7 +2882,8 @@ static int __init net_dev_init(void)
if (dev_proc_init())
goto out;
subsystem_register(&net_subsys);
if (netdev_sysfs_init())
goto out;
INIT_LIST_HEAD(&ptype_all);
for (i = 0; i < 16; i++)
......@@ -2965,7 +2957,8 @@ static int __init net_dev_init(void)
*/
netdev_boot_setup_check(dev);
if (dev->init && dev->init(dev)) {
if ( (dev->init && dev->init(dev)) ||
netdev_register_sysfs(dev) ) {
/*
* It failed to come up. It will be unhooked later.
* dev_alloc_name can now advance to next suitable
......
/*
* net-sysfs.c - network device class and attributes
*
* Copyright (c) 2003 Stephen Hemminber <shemminger@osdl.org>
*
*
* TODO:
* last_tx
* last_rx
*/
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <net/sock.h>
#include <linux/rtnetlink.h>
const char *if_port_text[] = {
[IF_PORT_UNKNOWN] = "unknown",
[IF_PORT_10BASE2] = "BNC",
[IF_PORT_10BASET] = "10baseT",
[IF_PORT_AUI] = "AUI",
[IF_PORT_100BASET] = "100baseT",
[IF_PORT_100BASETX] = "100baseTX",
[IF_PORT_100BASEFX] = "100baseFX"
};
#define to_net_dev(class) container_of((class), struct net_device, class_dev)
/* generate a show function for simple field */
#define NETDEVICE_SHOW(field, format_string) \
static ssize_t show_##field(struct class_device *dev, char *buf) \
{ \
return sprintf(buf, format_string, to_net_dev(dev)->field); \
}
/* generate a store function for a field with locking */
#define NETDEVICE_STORE(field) \
static ssize_t \
store_##field(struct class_device *dev, const char *buf, size_t len) \
{ \
char *endp; \
long new = simple_strtol(buf, &endp, 16); \
\
if (endp == buf || new < 0) \
return -EINVAL; \
\
if (!capable(CAP_NET_ADMIN)) \
return -EPERM; \
\
rtnl_lock(); \
to_net_dev(dev)->field = new; \
rtnl_unlock(); \
return len; \
}
/* generate a read-only network device class attribute */
#define NETDEVICE_ATTR(field, format_string) \
NETDEVICE_SHOW(field, format_string) \
static CLASS_DEVICE_ATTR(field, S_IRUGO, show_##field, NULL) \
NETDEVICE_ATTR(addr_len, "%d\n");
NETDEVICE_ATTR(iflink, "%d\n");
NETDEVICE_ATTR(ifindex, "%d\n");
NETDEVICE_ATTR(features, "%#x\n");
NETDEVICE_ATTR(type, "%d\n");
/* TODO: only a few devices set this now should fix others. */
static ssize_t show_port(struct class_device *dev, char *buf)
{
unsigned char port = to_net_dev(dev)->if_port;
char *cp = buf;
cp += sprintf(cp, "%d", port);
if (port < ARRAY_SIZE(if_port_text))
cp += sprintf(cp, " (%s)", if_port_text[port]);
*cp++ ='\n';
return cp - buf;
}
static CLASS_DEVICE_ATTR(if_port, S_IRUGO, show_port, NULL);
static ssize_t format_addr(char *buf, const unsigned char *addr, int len)
{
int i;
char *cp = buf;
read_lock(&dev_base_lock);
for (i = 0; i < len; i++)
cp += sprintf(cp, "%02x%c", addr[i],
i == (len - 1) ? '\n' : ':');
read_unlock(&dev_base_lock);
return cp - buf;
}
static ssize_t show_address(struct class_device *dev, char *buf)
{
struct net_device *net = to_net_dev(dev);
return format_addr(buf, net->dev_addr, net->addr_len);
}
static ssize_t show_broadcast(struct class_device *dev, char *buf)
{
struct net_device *net = to_net_dev(dev);
return format_addr(buf, net->broadcast, net->addr_len);
}
static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
static CLASS_DEVICE_ATTR(broadcast, S_IRUGO, show_broadcast, NULL);
/* read-write attributes */
NETDEVICE_SHOW(mtu, "%d\n");
static ssize_t store_mtu(struct class_device *dev, const char *buf, size_t len)
{
char *endp;
int new_mtu;
int err;
new_mtu = simple_strtoul(buf, &endp, 10);
if (endp == buf)
return -EINVAL;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
rtnl_lock();
err = dev_set_mtu(to_net_dev(dev), new_mtu);
rtnl_unlock();
return err == 0 ? len : err;
}
static CLASS_DEVICE_ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu);
NETDEVICE_SHOW(flags, "%#x\n");
static ssize_t store_flags(struct class_device *dev, const char *buf, size_t len)
{
unsigned long new_flags;
char *endp;
int err = 0;
new_flags = simple_strtoul(buf, &endp, 16);
if (endp == buf)
return -EINVAL;
if (!capable(CAP_NET_ADMIN))
return -EPERM;
rtnl_lock();
err = dev_change_flags(to_net_dev(dev), new_flags);
rtnl_unlock();
return err ? err : len;
}
static CLASS_DEVICE_ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags);
NETDEVICE_SHOW(tx_queue_len, "%lu\n");
NETDEVICE_STORE(tx_queue_len);
static CLASS_DEVICE_ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
store_tx_queue_len);
static struct class net_class = {
.name = "net",
};
static struct class_device_attribute *net_class_attributes[] = {
&class_device_attr_ifindex,
&class_device_attr_iflink,
&class_device_attr_addr_len,
&class_device_attr_tx_queue_len,
&class_device_attr_features,
&class_device_attr_mtu,
&class_device_attr_flags,
&class_device_attr_if_port,
&class_device_attr_type,
&class_device_attr_address,
&class_device_attr_broadcast,
NULL
};
struct netstat_fs_entry {
struct attribute attr;
ssize_t (*show)(const struct net_device_stats *, char *);
ssize_t (*store)(struct net_device_stats *, const char *, size_t);
};
static ssize_t net_device_stat_show(unsigned long var, char *buf)
{
return sprintf(buf, "%ld\n", var);
}
/* generate a read-only statistics attribute */
#define NETDEVICE_STAT(_NAME) \
static ssize_t show_stat_##_NAME(const struct net_device_stats *stats, \
char *buf) \
{ \
return net_device_stat_show(stats->_NAME, buf); \
} \
static struct netstat_fs_entry net_stat_##_NAME = { \
.attr = {.name = __stringify(_NAME), .mode = S_IRUGO }, \
.show = show_stat_##_NAME, \
}
NETDEVICE_STAT(rx_packets);
NETDEVICE_STAT(tx_packets);
NETDEVICE_STAT(rx_bytes);
NETDEVICE_STAT(tx_bytes);
NETDEVICE_STAT(rx_errors);
NETDEVICE_STAT(tx_errors);
NETDEVICE_STAT(rx_dropped);
NETDEVICE_STAT(tx_dropped);
NETDEVICE_STAT(multicast);
NETDEVICE_STAT(collisions);
NETDEVICE_STAT(rx_length_errors);
NETDEVICE_STAT(rx_over_errors);
NETDEVICE_STAT(rx_crc_errors);
NETDEVICE_STAT(rx_frame_errors);
NETDEVICE_STAT(rx_fifo_errors);
NETDEVICE_STAT(rx_missed_errors);
NETDEVICE_STAT(tx_aborted_errors);
NETDEVICE_STAT(tx_carrier_errors);
NETDEVICE_STAT(tx_fifo_errors);
NETDEVICE_STAT(tx_heartbeat_errors);
NETDEVICE_STAT(tx_window_errors);
NETDEVICE_STAT(rx_compressed);
NETDEVICE_STAT(tx_compressed);
static struct attribute *default_attrs[] = {
&net_stat_rx_packets.attr,
&net_stat_tx_packets.attr,
&net_stat_rx_bytes.attr,
&net_stat_tx_bytes.attr,
&net_stat_rx_errors.attr,
&net_stat_tx_errors.attr,
&net_stat_rx_dropped.attr,
&net_stat_tx_dropped.attr,
&net_stat_multicast.attr,
&net_stat_collisions.attr,
&net_stat_rx_length_errors.attr,
&net_stat_rx_over_errors.attr,
&net_stat_rx_crc_errors.attr,
&net_stat_rx_frame_errors.attr,
&net_stat_rx_fifo_errors.attr,
&net_stat_rx_missed_errors.attr,
&net_stat_tx_aborted_errors.attr,
&net_stat_tx_carrier_errors.attr,
&net_stat_tx_fifo_errors.attr,
&net_stat_tx_heartbeat_errors.attr,
&net_stat_tx_window_errors.attr,
&net_stat_rx_compressed.attr,
&net_stat_tx_compressed.attr,
NULL
};
static ssize_t
netstat_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
{
struct netstat_fs_entry *entry
= container_of(attr, struct netstat_fs_entry, attr);
struct class_device *class_dev
= container_of(kobj->parent, struct class_device, kobj);
struct net_device *dev
= to_net_dev(class_dev);
struct net_device_stats *stats
= dev->get_stats ? dev->get_stats(dev) : NULL;
if (stats && entry->show)
return entry->show(stats, buf);
return -EINVAL;
}
static struct sysfs_ops netstat_sysfs_ops = {
.show = netstat_attr_show,
};
static struct kobj_type netstat_ktype = {
.sysfs_ops = &netstat_sysfs_ops,
.default_attrs = default_attrs,
};
/* Create sysfs entries for network device. */
int netdev_register_sysfs(struct net_device *net)
{
struct class_device *class_dev = &(net->class_dev);
int i;
struct class_device_attribute *attr;
int ret;
memset(class_dev, 0, sizeof(struct class_device));
class_dev->class = &net_class;
class_dev->dev = net->dev;
class_dev->class_data = net;
snprintf(class_dev->class_id, BUS_ID_SIZE, net->name);
if ((ret = class_device_register(class_dev)))
goto out;
for (i = 0; (attr = net_class_attributes[i]); i++) {
if ((ret = class_device_create_file(class_dev, attr)))
goto out_unreg;
}
if (net->get_stats) {
struct kobject *k = &net->stats_kobj;
memset(k, 0, sizeof(*k));
k->parent = kobject_get(&class_dev->kobj);
if (!k->parent) {
ret = -EBUSY;
goto out_unreg;
}
snprintf(k->name, KOBJ_NAME_LEN, "%s", "statistics");
k->ktype = &netstat_ktype;
if((ret = kobject_register(k)))
goto out_unreg;
}
out:
return ret;
out_unreg:
printk(KERN_WARNING "%s: sysfs attribute registration failed %d\n",
net->name, ret);
class_device_unregister(class_dev);
goto out;
}
void netdev_unregister_sysfs(struct net_device *net)
{
if (net->get_stats)
kobject_del(&net->stats_kobj);
class_device_unregister(&net->class_dev);
}
int netdev_sysfs_init(void)
{
return class_register(&net_class);
}
......@@ -273,7 +273,7 @@ static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *
memcpy(t, &dn_dev_sysctl, sizeof(*t));
for(i = 0; i < (sizeof(t->dn_dev_vars)/sizeof(t->dn_dev_vars[0]) - 1); i++) {
for(i = 0; i < ARRAY_SIZE(t->dn_dev_vars) - 1; i++) {
long offset = (long)t->dn_dev_vars[i].data;
t->dn_dev_vars[i].data = ((char *)parms) + offset;
t->dn_dev_vars[i].de = NULL;
......
......@@ -1302,9 +1302,7 @@ static void devinet_sysctl_register(struct in_device *in_dev,
if (!t)
return;
memcpy(t, &devinet_sysctl, sizeof(*t));
for (i = 0;
i < sizeof(t->devinet_vars) / sizeof(t->devinet_vars[0]) - 1;
i++) {
for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
t->devinet_vars[i].de = NULL;
}
......
......@@ -301,7 +301,7 @@ static int help(struct sk_buff *skb,
array[2] = (ntohl(ct->tuplehash[dir].tuple.src.ip) >> 8) & 0xFF;
array[3] = ntohl(ct->tuplehash[dir].tuple.src.ip) & 0xFF;
for (i = 0; i < sizeof(search) / sizeof(search[0]); i++) {
for (i = 0; i < ARRAY_SIZE(search); i++) {
if (search[i].dir != dir) continue;
found = find_pattern(ftp_buffer, skb->len - dataoff,
......
......@@ -958,12 +958,15 @@ void ip_rt_redirect(u32 old_gw, u32 daddr, u32 new_gw,
INIT_RCU_HEAD(&rt->u.dst.rcu_head);
rt->u.dst.__use = 1;
atomic_set(&rt->u.dst.__refcnt, 1);
rt->u.dst.child = NULL;
if (rt->u.dst.dev)
dev_hold(rt->u.dst.dev);
rt->u.dst.obsolete = 0;
rt->u.dst.lastuse = jiffies;
rt->u.dst.path = &rt->u.dst;
rt->u.dst.neighbour = NULL;
rt->u.dst.hh = NULL;
rt->u.dst.obsolete = 0;
rt->u.dst.xfrm = NULL;
rt->rt_flags |= RTCF_REDIRECTED;
......@@ -1150,7 +1153,7 @@ static __inline__ unsigned short guess_mtu(unsigned short old_mtu)
{
int i;
for (i = 0; i < sizeof(mtu_plateau) / sizeof(mtu_plateau[0]); i++)
for (i = 0; i < ARRAY_SIZE(mtu_plateau); i++)
if (old_mtu > mtu_plateau[i])
return mtu_plateau[i];
return 68;
......
......@@ -17,6 +17,7 @@
#include <linux/tcp.h>
#include <linux/slab.h>
#include <linux/random.h>
#include <linux/kernel.h>
#include <net/tcp.h>
extern int sysctl_tcp_syncookies;
......@@ -38,7 +39,7 @@ static __u16 const msstab[] = {
(__u16)-1
};
/* The number doesn't include the -1 terminator */
#define NUM_MSS (sizeof(msstab)/sizeof(msstab[0]) - 1)
#define NUM_MSS (ARRAY_SIZE(msstab) - 1)
/*
* Generate a syncookie. mssp points to the mss, which is returned
......
......@@ -613,7 +613,7 @@ static inline void tcpdiag_rcv_skb(struct sk_buff *skb)
if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
return;
err = tcpdiag_rcv_msg(skb, nlh);
if (err)
if (err || nlh->nlmsg_flags & NLM_F_ACK)
netlink_ack(skb, nlh, err);
}
}
......
......@@ -53,8 +53,6 @@ static struct irda_entry dir[] = {
{"irias", irias_proc_read},
};
#define IRDA_ENTRIES_NUM (sizeof(dir)/sizeof(dir[0]))
/*
* Function irda_proc_register (void)
*
......@@ -70,7 +68,7 @@ void __init irda_proc_register(void)
return;
proc_irda->owner = THIS_MODULE;
for (i=0;i<IRDA_ENTRIES_NUM;i++)
for (i=0; i<ARRAY_SIZE(dir); i++)
create_proc_info_entry(dir[i].name,0,proc_irda,dir[i].fn);
}
......@@ -85,7 +83,7 @@ void __exit irda_proc_unregister(void)
int i;
if (proc_irda) {
for (i=0;i<IRDA_ENTRIES_NUM;i++)
for (i=0; i<ARRAY_SIZE(dir); i++)
remove_proc_entry(dir[i].name, proc_irda);
remove_proc_entry("net/irda", NULL);
......
......@@ -232,7 +232,7 @@ int __init init_netlink(void)
devfs_mk_dir("netlink");
/* Someone tell me the official names for the uppercase ones */
for (i = 0; i < sizeof(entries)/sizeof(entries[0]); i++) {
for (i = 0; i < ARRAY_SIZE(entries); i++) {
devfs_mk_cdev(MKDEV(NETLINK_MAJOR, entries[i].minor),
S_IFCHR|S_IRUSR|S_IWUSR, "netlink/%s", entries[i].name);
}
......@@ -259,7 +259,7 @@ void cleanup_module(void)
{
int i;
for (i = 0; i < sizeof(entries)/sizeof(entries[0]); i++)
for (i = 0; i < ARRAY_SIZE(entries); i++)
devfs_remove("netlink/%s", entries[i].name);
for (i = 0; i < 16; i++)
devfs_remove("netlink/tap%d", i);
......
......@@ -38,6 +38,7 @@
* be incorporated into the next SCTP release.
*/
#include <linux/kernel.h>
#include <net/sctp/sctp.h>
/*
......@@ -88,7 +89,7 @@ static int sctp_dbg_objcnt_read(char *buffer, char **start, off_t offset,
char temp[128];
/* How many entries? */
entries = sizeof(sctp_dbg_objcnt)/sizeof(sctp_dbg_objcnt[0]);
entries = ARRAY_SIZE(sctp_dbg_objcnt);
/* Walk the entries and print out the debug information
* for proc fs.
......
......@@ -821,11 +821,7 @@ static int sock_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
case SIOCGIFDIVERT:
case SIOCSIFDIVERT:
/* Convert this to call through a hook */
#ifdef CONFIG_NET_DIVERT
err = divert_ioctl(cmd, (struct divert_cf *)arg);
#else
err = -ENOPKG;
#endif /* CONFIG_NET_DIVERT */
break;
case SIOCADDDLCI:
case SIOCDELDLCI:
......
......@@ -288,7 +288,7 @@ static struct rpc_stat pmap_stats;
struct rpc_program pmap_program = {
.name = "portmap",
.number = RPC_PMAP_PROGRAM,
.nrvers = sizeof(pmap_version)/sizeof(pmap_version[0]),
.nrvers = ARRAY_SIZE(pmap_version),
.version = pmap_version,
.stats = &pmap_stats,
};
......@@ -251,17 +251,17 @@ static struct xfrm_algo_desc calg_list[] = {
static inline int aalg_entries(void)
{
return sizeof(aalg_list) / sizeof(aalg_list[0]);
return ARRAY_SIZE(aalg_list);
}
static inline int ealg_entries(void)
{
return sizeof(ealg_list) / sizeof(ealg_list[0]);
return ARRAY_SIZE(ealg_list);
}
static inline int calg_entries(void)
{
return sizeof(calg_list) / sizeof(calg_list[0]);
return ARRAY_SIZE(calg_list);
}
/* Todo: generic iterators */
......
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