diff options
71 files changed, 783 insertions, 357 deletions
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c index daa8a8273c04..6ac7c7c6418c 100644 --- a/drivers/net/3c59x.c +++ b/drivers/net/3c59x.c @@ -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; diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c index 8e671de34594..8a1c02d9a9b5 100644 --- a/drivers/net/8139cp.c +++ b/drivers/net/8139cp.c @@ -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; diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c index a730ebf418ab..b87d14cbf179 100644 --- a/drivers/net/8139too.c +++ b/drivers/net/8139too.c @@ -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; diff --git a/drivers/net/Space.c b/drivers/net/Space.c index b09a14ceae14..16b90c0ee242 100644 --- a/drivers/net/Space.c +++ b/drivers/net/Space.c @@ -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; } } diff --git a/drivers/net/acenic.c b/drivers/net/acenic.c index d606320424c8..adc1480a7d56 100644 --- a/drivers/net/acenic.c +++ b/drivers/net/acenic.c @@ -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(®s->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; } diff --git a/drivers/net/acenic.h b/drivers/net/acenic.h index 1fe5bcdbaab9..de273f7583e6 100644 --- a/drivers/net/acenic.h +++ b/drivers/net/acenic.h @@ -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); diff --git a/drivers/net/amd8111e.c b/drivers/net/amd8111e.c index b2d4ac676b9e..38b1e4814cc8 100755 --- a/drivers/net/amd8111e.c +++ b/drivers/net/amd8111e.c @@ -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 ; diff --git a/drivers/net/defxx.c b/drivers/net/defxx.c index caecb88097e5..4cec39502f08 100644 --- a/drivers/net/defxx.c +++ b/drivers/net/defxx.c @@ -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; diff --git a/drivers/net/dl2k.c b/drivers/net/dl2k.c index 015ab57e202b..1f8fbda3b21b 100644 --- a/drivers/net/dl2k.c +++ b/drivers/net/dl2k.c @@ -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); diff --git a/drivers/net/e100/e100_main.c b/drivers/net/e100/e100_main.c index bfad0a28c3df..070c9fb9f0f4 100644 --- a/drivers/net/e100/e100_main.c +++ b/drivers/net/e100/e100_main.c @@ -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; diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c index bb5d823e243e..86f15dbb0a21 100644 --- a/drivers/net/e1000/e1000_main.c +++ b/drivers/net/e1000/e1000_main.c @@ -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; diff --git a/drivers/net/eepro100.c b/drivers/net/eepro100.c index 076682df1638..35321d42666a 100644 --- a/drivers/net/eepro100.c +++ b/drivers/net/eepro100.c @@ -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; diff --git a/drivers/net/epic100.c b/drivers/net/epic100.c index 50982eca1dcb..9c4e6ac14a98 100644 --- a/drivers/net/epic100.c +++ b/drivers/net/epic100.c @@ -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; diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c index 824f1d48fe88..4c5d647a526f 100644 --- a/drivers/net/fealnx.c +++ b/drivers/net/fealnx.c @@ -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) diff --git a/drivers/net/hamachi.c b/drivers/net/hamachi.c index f9539782e679..93b6f7f4d4c6 100644 --- a/drivers/net/hamachi.c +++ b/drivers/net/hamachi.c @@ -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"); diff --git a/drivers/net/hp100.c b/drivers/net/hp100.c index a2f8d53a494f..0b98f0bfc1c8 100644 --- a/drivers/net/hp100.c +++ b/drivers/net/hp100.c @@ -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 diff --git a/drivers/net/ioc3-eth.c b/drivers/net/ioc3-eth.c index a6a32af6b38c..fc9c9f8433d2 100644 --- a/drivers/net/ioc3-eth.c +++ b/drivers/net/ioc3-eth.c @@ -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; diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c index 933fc5e7e553..89c85a2ecfad 100644 --- a/drivers/net/ixgb/ixgb_main.c +++ b/drivers/net/ixgb/ixgb_main.c @@ -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; diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c index df5ff08ac3b9..6ce21320d149 100644 --- a/drivers/net/natsemi.c +++ b/drivers/net/natsemi.c @@ -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) { diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c index cd3ae0c11daa..927b4b9a6e82 100644 --- a/drivers/net/ne2k-pci.c +++ b/drivers/net/ne2k-pci.c @@ -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. */ { diff --git a/drivers/net/ns83820.c b/drivers/net/ns83820.c index 47f1fc9791a4..f977a3164e6f 100644 --- a/drivers/net/ns83820.c +++ b/drivers/net/ns83820.c @@ -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); diff --git a/drivers/net/pci-skeleton.c b/drivers/net/pci-skeleton.c index ad8af585edd7..a092d4ae0c34 100644 --- a/drivers/net/pci-skeleton.c +++ b/drivers/net/pci-skeleton.c @@ -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 */ diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c index 30f741193b5b..f87cff0357a3 100644 --- a/drivers/net/pcnet32.c +++ b/drivers/net/pcnet32.c @@ -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; diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index 4c7dd2ee759b..bd37d330c02b 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c @@ -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) diff --git a/drivers/net/rcpci45.c b/drivers/net/rcpci45.c index 78ff9d5bfb4f..c984c37ef750 100644 --- a/drivers/net/rcpci45.c +++ b/drivers/net/rcpci45.c @@ -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) { diff --git a/drivers/net/rrunner.c b/drivers/net/rrunner.c index c603c316a200..c2d95cc61921 100644 --- a/drivers/net/rrunner.c +++ b/drivers/net/rrunner.c @@ -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; diff --git a/drivers/net/sb1000.c b/drivers/net/sb1000.c index dc6150d0c71a..8e6b6a2eb889 100644 --- a/drivers/net/sb1000.c +++ b/drivers/net/sb1000.c @@ -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); diff --git a/drivers/net/sis900.c b/drivers/net/sis900.c index 34c6792e6116..279bcb75a9a2 100644 --- a/drivers/net/sis900.c +++ b/drivers/net/sis900.c @@ -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); diff --git a/drivers/net/sk98lin/skge.c b/drivers/net/sk98lin/skge.c index e872584c8103..839bcdf0fc47 100644 --- a/drivers/net/sk98lin/skge.c +++ b/drivers/net/sk98lin/skge.c @@ -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; diff --git a/drivers/net/smc-mca.c b/drivers/net/smc-mca.c index 45e528061f4c..2884d4e51abe 100644 --- a/drivers/net/smc-mca.c +++ b/drivers/net/smc-mca.c @@ -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; diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c index 9aae78c646b3..52f861d4732a 100644 --- a/drivers/net/starfire.c +++ b/drivers/net/starfire.c @@ -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; diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c index 1328db356d33..3cdb10f7fc94 100644 --- a/drivers/net/sundance.c +++ b/drivers/net/sundance.c @@ -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; diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c index 0a64b04c695b..768856045c0d 100644 --- a/drivers/net/sungem.c +++ b/drivers/net/sungem.c @@ -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; diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c index 2119f01f5b9d..a031b0f152df 100644 --- a/drivers/net/sunhme.c +++ b/drivers/net/sunhme.c @@ -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); diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c index c2f81572da9d..6b5162f21f06 100644 --- a/drivers/net/tg3.c +++ b/drivers/net/tg3.c @@ -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; diff --git a/drivers/net/tlan.c b/drivers/net/tlan.c index 5f02c533f8f7..ad5646db78fd 100644 --- a/drivers/net/tlan.c +++ b/drivers/net/tlan.c @@ -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; diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c index 952d0d374914..fe457dfd8b0e 100644 --- a/drivers/net/tulip/de2104x.c +++ b/drivers/net/tulip/de2104x.c @@ -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; diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c index 98d78d98c542..9a534bb64557 100644 --- a/drivers/net/tulip/de4x5.c +++ b/drivers/net/tulip/de4x5.c @@ -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; diff --git a/drivers/net/tulip/dmfe.c b/drivers/net/tulip/dmfe.c index 845dd8cb8902..ccc16afb74ed 100644 --- a/drivers/net/tulip/dmfe.c +++ b/drivers/net/tulip/dmfe.c @@ -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"); diff --git a/drivers/net/tulip/tulip_core.c b/drivers/net/tulip/tulip_core.c index 058ed3e817c0..8ed05ed2da88 100644 --- a/drivers/net/tulip/tulip_core.c +++ b/drivers/net/tulip/tulip_core.c @@ -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, diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c index 060a376ebec3..27be3edb69d2 100644 --- a/drivers/net/tulip/winbond-840.c +++ b/drivers/net/tulip/winbond-840.c @@ -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; diff --git a/drivers/net/tulip/xircom_cb.c b/drivers/net/tulip/xircom_cb.c index 3acf64b11c62..6aed1c21e642 100644 --- a/drivers/net/tulip/xircom_cb.c +++ b/drivers/net/tulip/xircom_cb.c @@ -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; diff --git a/drivers/net/tulip/xircom_tulip_cb.c b/drivers/net/tulip/xircom_tulip_cb.c index 56a05a62940a..5c7ad26cb124 100644 --- a/drivers/net/tulip/xircom_tulip_cb.c +++ b/drivers/net/tulip/xircom_tulip_cb.c @@ -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; diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c index deed8d4b2342..809f5d1a7762 100644 --- a/drivers/net/typhoon.c +++ b/drivers/net/typhoon.c @@ -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) { diff --git a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c index 551bafadfe23..4226efcc5f0d 100644 --- a/drivers/net/via-rhine.c +++ b/drivers/net/via-rhine.c @@ -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; diff --git a/drivers/net/wan/cycx_main.c b/drivers/net/wan/cycx_main.c index 2addb21bcb92..f475a174070e 100644 --- a/drivers/net/wan/cycx_main.c +++ b/drivers/net/wan/cycx_main.c @@ -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_irq: * 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); diff --git a/drivers/net/wan/cycx_x25.c b/drivers/net/wan/cycx_x25.c index 2341ae5e3abc..94d5986262ca 100644 --- a/drivers/net/wan/cycx_x25.c +++ b/drivers/net/wan/cycx_x25.c @@ -94,8 +94,8 @@ #include <linux/cycx_x25.h> /* X.25 firmware API definitions */ /* Defines & Macros */ -#define MAX_CMD_RETRY 5 -#define X25_CHAN_MTU 2048 /* unfragmented logical channel MTU */ +#define CYCX_X25_MAX_CMD_RETRY 5 +#define CYCX_X25_CHAN_MTU 2048 /* unfragmented logical channel MTU */ /* Data Structures */ /* This is an extension of the 'struct net_device' we create for each network @@ -123,56 +123,65 @@ struct cycx_x25_channel { /* Function Prototypes */ /* WAN link driver entry points. These are called by the WAN router module. */ -static int update(struct wan_device *wandev), - new_if(struct wan_device *wandev, struct net_device *dev, - wanif_conf_t *conf), - del_if(struct wan_device *wandev, struct net_device *dev); +static int cycx_wan_update(struct wan_device *wandev), + cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev, + wanif_conf_t *conf), + cycx_wan_del_if(struct wan_device *wandev, struct net_device *dev); /* Network device interface */ -static int if_init(struct net_device *dev), - if_open(struct net_device *dev), - if_close(struct net_device *dev), - if_header(struct sk_buff *skb, struct net_device *dev, - u16 type, void *daddr, void *saddr, unsigned len), - if_rebuild_hdr(struct sk_buff *skb), - if_send(struct sk_buff *skb, struct net_device *dev); - -static struct net_device_stats *if_stats(struct net_device *dev); +static int cycx_netdevice_init(struct net_device *dev), + cycx_netdevice_open(struct net_device *dev), + cycx_netdevice_stop(struct net_device *dev), + cycx_netdevice_hard_header(struct sk_buff *skb, + struct net_device *dev, u16 type, + void *daddr, void *saddr, unsigned len), + cycx_netdevice_rebuild_header(struct sk_buff *skb), + cycx_netdevice_hard_start_xmit(struct sk_buff *skb, + struct net_device *dev); + +static struct net_device_stats * + cycx_netdevice_get_stats(struct net_device *dev); /* Interrupt handlers */ -static void cyx_isr(struct cycx_device *card), - tx_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd), - rx_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd), - log_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd), - stat_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd), - connect_confirm_intr(struct cycx_device *card, +static void cycx_x25_irq_handler(struct cycx_device *card), + cycx_x25_irq_tx(struct cycx_device *card, struct cycx_x25_cmd *cmd), + cycx_x25_irq_rx(struct cycx_device *card, struct cycx_x25_cmd *cmd), + cycx_x25_irq_log(struct cycx_device *card, + struct cycx_x25_cmd *cmd), + cycx_x25_irq_stat(struct cycx_device *card, + struct cycx_x25_cmd *cmd), + cycx_x25_irq_connect_confirm(struct cycx_device *card, + struct cycx_x25_cmd *cmd), + cycx_x25_irq_disconnect_confirm(struct cycx_device *card, + struct cycx_x25_cmd *cmd), + cycx_x25_irq_connect(struct cycx_device *card, struct cycx_x25_cmd *cmd), - disconnect_confirm_intr(struct cycx_device *card, + cycx_x25_irq_disconnect(struct cycx_device *card, struct cycx_x25_cmd *cmd), - connect_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd), - disconnect_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd), - spur_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd); + cycx_x25_irq_spurious(struct cycx_device *card, + struct cycx_x25_cmd *cmd); /* X.25 firmware interface functions */ -static int x25_configure(struct cycx_device *card, - struct cycx_x25_config *conf), - x25_get_stats(struct cycx_device *card), - x25_send(struct cycx_device *card, u8 link, u8 lcn, u8 bitm, int len, - void *buf), - x25_connect_response(struct cycx_device *card, +static int cycx_x25_configure(struct cycx_device *card, + struct cycx_x25_config *conf), + cycx_x25_get_stats(struct cycx_device *card), + cycx_x25_send(struct cycx_device *card, u8 link, u8 lcn, u8 bitm, + int len, void *buf), + cycx_x25_connect_response(struct cycx_device *card, struct cycx_x25_channel *chan), - x25_disconnect_response(struct cycx_device *card, u8 link, u8 lcn); + cycx_x25_disconnect_response(struct cycx_device *card, u8 link, + u8 lcn); /* channel functions */ -static int chan_connect(struct net_device *dev), - chan_send(struct net_device *dev, struct sk_buff *skb); +static int cycx_x25_chan_connect(struct net_device *dev), + cycx_x25_chan_send(struct net_device *dev, struct sk_buff *skb); -static void chan_disconnect(struct net_device *dev), - chan_x25_send_event(struct net_device *dev, u8 event); +static void cycx_x25_chan_disconnect(struct net_device *dev), + cycx_x25_chan_send_event(struct net_device *dev, u8 event); /* Miscellaneous functions */ -static void set_chan_state(struct net_device *dev, u8 state), - chan_timer(unsigned long d); +static void cycx_x25_set_chan_state(struct net_device *dev, u8 state), + cycx_x25_chan_timer(unsigned long d); static void nibble_to_byte(u8 *s, u8 *d, u8 len, u8 nibble), reset_timer(struct net_device *dev); @@ -182,20 +191,21 @@ static u8 log2(u32 n); static unsigned dec_to_uint(u8 *str, int len); -static struct net_device *get_dev_by_lcn(struct wan_device *wandev, s16 lcn); -static struct net_device *get_dev_by_dte_addr(struct wan_device *wandev, - char *dte); +static struct net_device *cycx_x25_get_dev_by_lcn(struct wan_device *wandev, + s16 lcn); +static struct net_device * + cycx_x25_get_dev_by_dte_addr(struct wan_device *wandev, char *dte); #ifdef CYCLOMX_X25_DEBUG static void hex_dump(char *msg, unsigned char *p, int len); -static void x25_dump_config(struct cycx_x25_config *conf); -static void x25_dump_stats(struct cycx_x25_stats *stats); -static void x25_dump_devs(struct wan_device *wandev); +static void cycx_x25_dump_config(struct cycx_x25_config *conf); +static void cycx_x25_dump_stats(struct cycx_x25_stats *stats); +static void cycx_x25_dump_devs(struct wan_device *wandev); #else #define hex_dump(msg, p, len) -#define x25_dump_config(conf) -#define x25_dump_stats(stats) -#define x25_dump_devs(wandev) +#define cycx_x25_dump_config(conf) +#define cycx_x25_dump_stats(stats) +#define cycx_x25_dump_devs(wandev) #endif /* Public Functions */ @@ -208,7 +218,7 @@ static void x25_dump_devs(struct wan_device *wandev); * * Return: 0 o.k. * < 0 failure. */ -int cyx_init(struct cycx_device *card, wandev_conf_t *conf) +int cycx_x25_wan_init(struct cycx_device *card, wandev_conf_t *conf) { struct cycx_x25_config cfg; @@ -306,7 +316,7 @@ int cyx_init(struct cycx_device *card, wandev_conf_t *conf) cfg.n2 = min_t(unsigned int, conf->u.x25.n2, 30); /* initialize adapter */ - if (x25_configure(card, &cfg)) + if (cycx_x25_configure(card, &cfg)) return -EIO; /* Initialize protocol-specific fields of adapter data space */ @@ -314,11 +324,11 @@ int cyx_init(struct cycx_device *card, wandev_conf_t *conf) card->wandev.interface = conf->interface; card->wandev.clocking = conf->clocking; card->wandev.station = conf->station; - card->isr = cyx_isr; + card->isr = cycx_x25_irq_handler; card->exec = NULL; - card->wandev.update = update; - card->wandev.new_if = new_if; - card->wandev.del_if = del_if; + card->wandev.update = cycx_wan_update; + card->wandev.new_if = cycx_wan_new_if; + card->wandev.del_if = cycx_wan_del_if; card->wandev.state = WAN_DISCONNECTED; return 0; @@ -326,7 +336,7 @@ int cyx_init(struct cycx_device *card, wandev_conf_t *conf) /* WAN Device Driver Entry Points */ /* Update device status & statistics. */ -static int update(struct wan_device *wandev) +static int cycx_wan_update(struct wan_device *wandev) { /* sanity checks */ if (!wandev || !wandev->private) @@ -335,7 +345,7 @@ static int update(struct wan_device *wandev) if (wandev->state == WAN_UNCONFIGURED) return -ENODEV; - x25_get_stats(wandev->private); + cycx_x25_get_stats(wandev->private); return 0; } @@ -350,8 +360,8 @@ static int update(struct wan_device *wandev) * * Return: 0 o.k. * < 0 failure (channel will not be created) */ -static int new_if(struct wan_device *wandev, struct net_device *dev, - wanif_conf_t *conf) +static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev, + wanif_conf_t *conf) { struct cycx_device *card = wandev->private; struct cycx_x25_channel *chan; @@ -402,8 +412,8 @@ static int new_if(struct wan_device *wandev, struct net_device *dev, chan->svc = 1; strncpy(chan->addr, &conf->addr[1], WAN_ADDRESS_SZ); init_timer(&chan->timer); - chan->timer.function = chan_timer; - chan->timer.data = (unsigned long)dev; + chan->timer.function = cycx_x25_chan_timer; + chan->timer.data = (unsigned long)dev; /* Set channel timeouts (default if not specified) */ chan->idle_tmout = conf->idle_timeout ? conf->idle_timeout : 90; @@ -434,14 +444,14 @@ static int new_if(struct wan_device *wandev, struct net_device *dev, /* prepare network device data space for registration */ strcpy(dev->name, chan->name); - dev->init = if_init; + dev->init = cycx_netdevice_init; dev->priv = chan; return 0; } /* Delete logical channel. */ -static int del_if(struct wan_device *wandev, struct net_device *dev) +static int cycx_wan_del_if(struct wan_device *wandev, struct net_device *dev) { if (dev->priv) { struct cycx_x25_channel *chan = dev->priv; @@ -467,43 +477,44 @@ static int del_if(struct wan_device *wandev, struct net_device *dev) * This routine is called only once for each interface, during Linux network * interface registration. Returning anything but zero will fail interface * registration. */ -static int if_init(struct net_device *dev) +static int cycx_netdevice_init(struct net_device *dev) { struct cycx_x25_channel *chan = dev->priv; struct cycx_device *card = chan->card; struct wan_device *wandev = &card->wandev; /* Initialize device driver entry points */ - dev->open = if_open; - dev->stop = if_close; - dev->hard_header = if_header; - dev->rebuild_header = if_rebuild_hdr; - dev->hard_start_xmit = if_send; - dev->get_stats = if_stats; + dev->open = cycx_netdevice_open; + dev->stop = cycx_netdevice_stop; + dev->hard_header = cycx_netdevice_hard_header; + dev->rebuild_header = cycx_netdevice_rebuild_header; + dev->hard_start_xmit = cycx_netdevice_hard_start_xmit; + dev->get_stats = cycx_netdevice_get_stats; /* Initialize media-specific parameters */ - dev->mtu = X25_CHAN_MTU; - dev->type = ARPHRD_HWX25; /* ARP h/w type */ - dev->hard_header_len = 0; /* media header length */ - dev->addr_len = 0; /* hardware address length */ + dev->mtu = CYCX_X25_CHAN_MTU; + dev->type = ARPHRD_HWX25; /* ARP h/w type */ + dev->hard_header_len = 0; /* media header length */ + dev->addr_len = 0; /* hardware address length */ if (!chan->svc) *(u16*)dev->dev_addr = htons(chan->lcn); /* Initialize hardware parameters (just for reference) */ - dev->irq = wandev->irq; - dev->dma = wandev->dma; - dev->base_addr = wandev->ioport; - dev->mem_start = (unsigned long)wandev->maddr; - dev->mem_end = (unsigned long)(wandev->maddr + wandev->msize - 1); - dev->flags |= IFF_NOARP; + dev->irq = wandev->irq; + dev->dma = wandev->dma; + dev->base_addr = wandev->ioport; + dev->mem_start = (unsigned long)wandev->maddr; + dev->mem_end = (unsigned long)(wandev->maddr + + wandev->msize - 1); + dev->flags |= IFF_NOARP; /* Set transmit buffer queue length */ - dev->tx_queue_len = 10; + dev->tx_queue_len = 10; SET_MODULE_OWNER(dev); /* Initialize socket buffers */ - set_chan_state(dev, WAN_DISCONNECTED); + cycx_x25_set_chan_state(dev, WAN_DISCONNECTED); return 0; } @@ -513,7 +524,7 @@ static int if_init(struct net_device *dev) * o if link is disconnected then initiate connection * * Return 0 if O.k. or errno. */ -static int if_open(struct net_device *dev) +static int cycx_netdevice_open(struct net_device *dev) { if (netif_running(dev)) return -EBUSY; /* only one open is allowed */ @@ -525,14 +536,14 @@ static int if_open(struct net_device *dev) /* Close network interface. * o reset flags. * o if there's no more open channels then disconnect physical link. */ -static int if_close(struct net_device *dev) +static int cycx_netdevice_stop(struct net_device *dev) { struct cycx_x25_channel *chan = dev->priv; netif_stop_queue(dev); if (chan->state == WAN_CONNECTED || chan->state == WAN_CONNECTING) - chan_disconnect(dev); + cycx_x25_chan_disconnect(dev); return 0; } @@ -545,8 +556,9 @@ static int if_close(struct net_device *dev) * set skb->protocol to 0 and discard packet later. * * Return: media header length. */ -static int if_header(struct sk_buff *skb, struct net_device *dev, - u16 type, void *daddr, void *saddr, unsigned len) +static int cycx_netdevice_hard_header(struct sk_buff *skb, + struct net_device *dev, u16 type, + void *daddr, void *saddr, unsigned len) { skb->protocol = type; @@ -556,7 +568,7 @@ static int if_header(struct sk_buff *skb, struct net_device *dev, /* * Re-build media header. * Return: 1 physical address resolved. * 0 physical address not resolved */ -static int if_rebuild_hdr(struct sk_buff *skb) +static int cycx_netdevice_rebuild_header(struct sk_buff *skb) { return 1; } @@ -576,7 +588,8 @@ static int if_rebuild_hdr(struct sk_buff *skb) * bottom half" (with interrupts enabled). * 2. Setting tbusy flag will inhibit further transmit requests from the * protocol stack and can be used for flow control with protocol layer. */ -static int if_send(struct sk_buff *skb, struct net_device *dev) +static int cycx_netdevice_hard_start_xmit(struct sk_buff *skb, + struct net_device *dev) { struct cycx_x25_channel *chan = dev->priv; struct cycx_device *card = chan->card; @@ -595,7 +608,7 @@ static int if_send(struct sk_buff *skb, struct net_device *dev) } else if (chan->protocol == ETH_P_IP) { switch (chan->state) { case WAN_DISCONNECTED: - if (chan_connect(dev)) { + if (cycx_x25_chan_connect(dev)) { netif_stop_queue(dev); return -EBUSY; } @@ -605,7 +618,7 @@ static int if_send(struct sk_buff *skb, struct net_device *dev) dev->trans_start = jiffies; netif_stop_queue(dev); - if (chan_send(dev, skb)) + if (cycx_x25_chan_send(dev, skb)) return -EBUSY; break; @@ -617,10 +630,10 @@ static int if_send(struct sk_buff *skb, struct net_device *dev) switch (skb->data[0]) { case 0: break; case 1: /* Connect request */ - chan_connect(dev); + cycx_x25_chan_connect(dev); goto free_packet; case 2: /* Disconnect request */ - chan_disconnect(dev); + cycx_x25_chan_disconnect(dev); goto free_packet; default: printk(KERN_INFO @@ -635,7 +648,7 @@ static int if_send(struct sk_buff *skb, struct net_device *dev) dev->trans_start = jiffies; netif_stop_queue(dev); - if (chan_send(dev, skb)) { + if (cycx_x25_chan_send(dev, skb)) { /* prepare for future retransmissions */ skb_push(skb, 1); return -EBUSY; @@ -650,7 +663,7 @@ free_packet: /* Get Ethernet-style interface statistics. * Return a pointer to struct net_device_stats */ -static struct net_device_stats *if_stats(struct net_device *dev) +static struct net_device_stats *cycx_netdevice_get_stats(struct net_device *dev) { struct cycx_x25_channel *chan = dev->priv; @@ -659,7 +672,7 @@ static struct net_device_stats *if_stats(struct net_device *dev) /* Interrupt Handlers */ /* X.25 Interrupt Service Routine. */ -static void cyx_isr(struct cycx_device *card) +static void cycx_x25_irq_handler(struct cycx_device *card) { struct cycx_x25_cmd cmd; u16 z = 0; @@ -670,37 +683,38 @@ static void cyx_isr(struct cycx_device *card) switch (cmd.command) { case X25_DATA_INDICATION: - rx_intr(card, &cmd); + cycx_x25_irq_rx(card, &cmd); break; case X25_ACK_FROM_VC: - tx_intr(card, &cmd); + cycx_x25_irq_tx(card, &cmd); break; case X25_LOG: - log_intr(card, &cmd); + cycx_x25_irq_log(card, &cmd); break; case X25_STATISTIC: - stat_intr(card, &cmd); + cycx_x25_irq_stat(card, &cmd); break; case X25_CONNECT_CONFIRM: - connect_confirm_intr(card, &cmd); + cycx_x25_irq_connect_confirm(card, &cmd); break; case X25_CONNECT_INDICATION: - connect_intr(card, &cmd); + cycx_x25_irq_connect(card, &cmd); break; case X25_DISCONNECT_INDICATION: - disconnect_intr(card, &cmd); + cycx_x25_irq_disconnect(card, &cmd); break; case X25_DISCONNECT_CONFIRM: - disconnect_confirm_intr(card, &cmd); + cycx_x25_irq_disconnect_confirm(card, &cmd); break; case X25_LINE_ON: - cyclomx_set_state(card, WAN_CONNECTED); + cycx_set_state(card, WAN_CONNECTED); break; case X25_LINE_OFF: - cyclomx_set_state(card, WAN_DISCONNECTED); + cycx_set_state(card, WAN_DISCONNECTED); break; default: - spur_intr(card, &cmd); /* unwanted interrupt */ + cycx_x25_irq_spurious(card, &cmd); + break; } cycx_poke(&card->hw, 0, &z, sizeof(z)); @@ -711,7 +725,7 @@ static void cyx_isr(struct cycx_device *card) /* Transmit interrupt handler. * o Release socket buffer * o Clear 'tbusy' flag */ -static void tx_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) +static void cycx_x25_irq_tx(struct cycx_device *card, struct cycx_x25_cmd *cmd) { struct net_device *dev; struct wan_device *wandev = &card->wandev; @@ -720,7 +734,8 @@ static void tx_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) cycx_peek(&card->hw, cmd->buf, &lcn, sizeof(lcn)); /* unbusy device and then dev_tint(); */ - if ((dev = get_dev_by_lcn(wandev, lcn)) != NULL) { + dev = cycx_x25_get_dev_by_lcn(wandev, lcn); + if (dev) { card->buff_int_mode_unbusy = 1; netif_wake_queue(dev); } else @@ -742,7 +757,7 @@ static void tx_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) * expected on this channel. * 2. If something goes wrong and X.25 packet has to be dropped (e.g. no * socket buffers available) the whole packet sequence must be discarded. */ -static void rx_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) +static void cycx_x25_irq_rx(struct cycx_device *card, struct cycx_x25_cmd *cmd) { struct wan_device *wandev = &card->wandev; struct net_device *dev; @@ -755,7 +770,8 @@ static void rx_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) cycx_peek(&card->hw, cmd->buf + 4, &bitm, sizeof(bitm)); bitm &= 0x10; - if ((dev = get_dev_by_lcn(wandev, lcn)) == NULL) { + dev = cycx_x25_get_dev_by_lcn(wandev, lcn); + if (!dev) { /* Invalid channel, discard packet */ printk(KERN_INFO "%s: receiving on orphaned LCN %d!\n", card->devname, lcn); @@ -826,7 +842,8 @@ static void rx_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) } /* Connect interrupt handler. */ -static void connect_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) +static void cycx_x25_irq_connect(struct cycx_device *card, + struct cycx_x25_cmd *cmd) { struct wan_device *wandev = &card->wandev; struct net_device *dev = NULL; @@ -851,10 +868,11 @@ static void connect_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) if (sizerem) nibble_to_byte(d + (sizeloc >> 1), rem, sizerem, sizeloc & 1); - dprintk(1, KERN_INFO "connect_intr:lcn=%d, local=%s, remote=%s\n", - lcn, loc, rem); + dprintk(1, KERN_INFO "%s:lcn=%d, local=%s, remote=%s\n", + __FUNCTION__, lcn, loc, rem); - if ((dev = get_dev_by_dte_addr(wandev, rem)) == NULL) { + dev = cycx_x25_get_dev_by_dte_addr(wandev, rem); + if (!dev) { /* Invalid channel, discard packet */ printk(KERN_INFO "%s: connect not expected: remote %s!\n", card->devname, rem); @@ -863,13 +881,13 @@ static void connect_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) chan = dev->priv; chan->lcn = lcn; - x25_connect_response(card, chan); - set_chan_state(dev, WAN_CONNECTED); + cycx_x25_connect_response(card, chan); + cycx_x25_set_chan_state(dev, WAN_CONNECTED); } /* Connect confirm interrupt handler. */ -static void connect_confirm_intr(struct cycx_device *card, - struct cycx_x25_cmd *cmd) +static void cycx_x25_irq_connect_confirm(struct cycx_device *card, + struct cycx_x25_cmd *cmd) { struct wan_device *wandev = &card->wandev; struct net_device *dev; @@ -878,10 +896,11 @@ static void connect_confirm_intr(struct cycx_device *card, cycx_peek(&card->hw, cmd->buf, &lcn, sizeof(lcn)); cycx_peek(&card->hw, cmd->buf + 1, &key, sizeof(key)); - dprintk(1, KERN_INFO "%s: connect_confirm_intr:lcn=%d, key=%d\n", - card->devname, lcn, key); + dprintk(1, KERN_INFO "%s: %s:lcn=%d, key=%d\n", + card->devname, __FUNCTION__, lcn, key); - if ((dev = get_dev_by_lcn(wandev, -key)) == NULL) { + dev = cycx_x25_get_dev_by_lcn(wandev, -key); + if (!dev) { /* Invalid channel, discard packet */ clear_bit(--key, (void*)&card->u.x.connection_keys); printk(KERN_INFO "%s: connect confirm not expected: lcn %d, " @@ -892,51 +911,54 @@ static void connect_confirm_intr(struct cycx_device *card, clear_bit(--key, (void*)&card->u.x.connection_keys); chan = dev->priv; chan->lcn = lcn; - set_chan_state(dev, WAN_CONNECTED); + cycx_x25_set_chan_state(dev, WAN_CONNECTED); } /* Disconnect confirm interrupt handler. */ -static void disconnect_confirm_intr(struct cycx_device *card, - struct cycx_x25_cmd *cmd) +static void cycx_x25_irq_disconnect_confirm(struct cycx_device *card, + struct cycx_x25_cmd *cmd) { struct wan_device *wandev = &card->wandev; struct net_device *dev; u8 lcn; cycx_peek(&card->hw, cmd->buf, &lcn, sizeof(lcn)); - dprintk(1, KERN_INFO "%s: disconnect_confirm_intr:lcn=%d\n", - card->devname, lcn); - if ((dev = get_dev_by_lcn(wandev, lcn)) == NULL) { + dprintk(1, KERN_INFO "%s: %s:lcn=%d\n", + card->devname, __FUNCTION__, lcn); + dev = cycx_x25_get_dev_by_lcn(wandev, lcn); + if (!dev) { /* Invalid channel, discard packet */ printk(KERN_INFO "%s:disconnect confirm not expected!:lcn %d\n", card->devname, lcn); return; } - set_chan_state(dev, WAN_DISCONNECTED); + cycx_x25_set_chan_state(dev, WAN_DISCONNECTED); } /* disconnect interrupt handler. */ -static void disconnect_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) +static void cycx_x25_irq_disconnect(struct cycx_device *card, + struct cycx_x25_cmd *cmd) { struct wan_device *wandev = &card->wandev; struct net_device *dev; u8 lcn; cycx_peek(&card->hw, cmd->buf, &lcn, sizeof(lcn)); - dprintk(1, KERN_INFO "disconnect_intr:lcn=%d\n", lcn); + dprintk(1, KERN_INFO "%s:lcn=%d\n", __FUNCTION__, lcn); - if ((dev = get_dev_by_lcn(wandev, lcn)) != NULL) { + dev = cycx_x25_get_dev_by_lcn(wandev, lcn); + if (dev) { struct cycx_x25_channel *chan = dev->priv; - x25_disconnect_response(card, chan->link, lcn); - set_chan_state(dev, WAN_DISCONNECTED); + cycx_x25_disconnect_response(card, chan->link, lcn); + cycx_x25_set_chan_state(dev, WAN_DISCONNECTED); } else - x25_disconnect_response(card, 0, lcn); + cycx_x25_disconnect_response(card, 0, lcn); } /* LOG interrupt handler. */ -static void log_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) +static void cycx_x25_irq_log(struct cycx_device *card, struct cycx_x25_cmd *cmd) { #if CYCLOMX_X25_DEBUG char bf[20]; @@ -952,7 +974,7 @@ static void log_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) cycx_peek(&card->hw, cmd->buf + 10 + toread, &code, 1); cycx_peek(&card->hw, cmd->buf + 10 + toread + 1, &routine, 1); - printk(KERN_INFO "cyx_isr: X25_LOG (0x4500) indic.:\n"); + printk(KERN_INFO "cycx_x25_irq_handler: X25_LOG (0x4500) indic.:\n"); printk(KERN_INFO "cmd->buf=0x%X\n", cmd->buf); printk(KERN_INFO "Log message code=0x%X\n", msg_code); printk(KERN_INFO "Link=%d\n", link); @@ -964,20 +986,22 @@ static void log_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) } /* STATISTIC interrupt handler. */ -static void stat_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) +static void cycx_x25_irq_stat(struct cycx_device *card, + struct cycx_x25_cmd *cmd) { cycx_peek(&card->hw, cmd->buf, &card->u.x.stats, sizeof(card->u.x.stats)); - hex_dump("stat_intr", (unsigned char*)&card->u.x.stats, + hex_dump("cycx_x25_irq_stat", (unsigned char*)&card->u.x.stats, sizeof(card->u.x.stats)); - x25_dump_stats(&card->u.x.stats); + cycx_x25_dump_stats(&card->u.x.stats); wake_up_interruptible(&card->wait_stats); } /* Spurious interrupt handler. * o print a warning * If number of spurious interrupts exceeded some limit, then ??? */ -static void spur_intr(struct cycx_device *card, struct cycx_x25_cmd *cmd) +static void cycx_x25_irq_spurious(struct cycx_device *card, + struct cycx_x25_cmd *cmd) { printk(KERN_INFO "%s: spurious interrupt (0x%X)!\n", card->devname, cmd->command); @@ -1008,7 +1032,7 @@ static int x25_exec(struct cycx_device *card, int command, int link, struct cycx_x25_cmd c; unsigned long flags; u32 addr = 0x1200 + 0x2E0 * link + 0x1E2; - u8 retry = MAX_CMD_RETRY; + u8 retry = CYCX_X25_MAX_CMD_RETRY; int err = 0; c.command = command; @@ -1050,7 +1074,8 @@ static int x25_exec(struct cycx_device *card, int command, int link, } /* Configure adapter. */ -static int x25_configure(struct cycx_device *card, struct cycx_x25_config *conf) +static int cycx_x25_configure(struct cycx_device *card, + struct cycx_x25_config *conf) { struct { u16 nlinks; @@ -1071,15 +1096,15 @@ static int x25_configure(struct cycx_device *card, struct cycx_x25_config *conf) x25_cmd_conf.conf[1].clock = 8; x25_cmd_conf.conf[1].flags = 0; /* default = RS232 */ - x25_dump_config(&x25_cmd_conf.conf[0]); - x25_dump_config(&x25_cmd_conf.conf[1]); + cycx_x25_dump_config(&x25_cmd_conf.conf[0]); + cycx_x25_dump_config(&x25_cmd_conf.conf[1]); return x25_exec(card, X25_CONFIG, 0, &x25_cmd_conf, sizeof(x25_cmd_conf), NULL, 0); } /* Get protocol statistics. */ -static int x25_get_stats(struct cycx_device *card) +static int cycx_x25_get_stats(struct cycx_device *card) { /* the firmware expects 20 in the size field!!! thanks to Daniela */ @@ -1107,7 +1132,7 @@ static int x25_get_stats(struct cycx_device *card) card->wandev.stats.collisions = 0; /* not available from fw */ card->wandev.stats.tx_errors = 0; /* not available from fw */ - x25_dump_devs(&card->wandev); + cycx_x25_dump_devs(&card->wandev); return 0; } @@ -1207,8 +1232,8 @@ static int x25_place_call(struct cycx_device *card, } /* Place X.25 CONNECT RESPONSE. */ -static int x25_connect_response(struct cycx_device *card, - struct cycx_x25_channel *chan) +static int cycx_x25_connect_response(struct cycx_device *card, + struct cycx_x25_channel *chan) { u8 d[8]; @@ -1222,7 +1247,8 @@ static int x25_connect_response(struct cycx_device *card, } /* Place X.25 DISCONNECT RESPONSE. */ -static int x25_disconnect_response(struct cycx_device *card, u8 link, u8 lcn) +static int cycx_x25_disconnect_response(struct cycx_device *card, u8 link, + u8 lcn) { char d[5]; @@ -1251,8 +1277,8 @@ static int x25_clear_call(struct cycx_device *card, u8 link, u8 lcn, u8 cause, } /* Send X.25 data packet. */ -static int x25_send(struct cycx_device *card, u8 link, u8 lcn, u8 bitm, int len, - void *buf) +static int cycx_x25_send(struct cycx_device *card, u8 link, u8 lcn, u8 bitm, + int len, void *buf) { u8 d[] = "?\xFF\x10??"; @@ -1264,7 +1290,8 @@ static int x25_send(struct cycx_device *card, u8 link, u8 lcn, u8 bitm, int len, /* Miscellaneous */ /* Find network device by its channel number. */ -static struct net_device *get_dev_by_lcn(struct wan_device *wandev, s16 lcn) +static struct net_device *cycx_x25_get_dev_by_lcn(struct wan_device *wandev, + s16 lcn) { struct net_device *dev = wandev->dev; struct cycx_x25_channel *chan; @@ -1280,8 +1307,8 @@ static struct net_device *get_dev_by_lcn(struct wan_device *wandev, s16 lcn) } /* Find network device by its remote dte address. */ -static struct net_device *get_dev_by_dte_addr(struct wan_device *wandev, - char *dte) +static struct net_device * + cycx_x25_get_dev_by_dte_addr(struct wan_device *wandev, char *dte) { struct net_device *dev = wandev->dev; struct cycx_x25_channel *chan; @@ -1303,7 +1330,7 @@ static struct net_device *get_dev_by_dte_addr(struct wan_device *wandev, * Return: 0 connected * >0 connection in progress * <0 failure */ -static int chan_connect(struct net_device *dev) +static int cycx_x25_chan_connect(struct net_device *dev) { struct cycx_x25_channel *chan = dev->priv; struct cycx_device *card = chan->card; @@ -1318,42 +1345,42 @@ static int chan_connect(struct net_device *dev) if (x25_place_call(card, chan)) return -EIO; - set_chan_state(dev, WAN_CONNECTING); + cycx_x25_set_chan_state(dev, WAN_CONNECTING); return 1; } else - set_chan_state(dev, WAN_CONNECTED); + cycx_x25_set_chan_state(dev, WAN_CONNECTED); return 0; } /* Disconnect logical channel. * o if SVC then clear X.25 call */ -static void chan_disconnect(struct net_device *dev) +static void cycx_x25_chan_disconnect(struct net_device *dev) { struct cycx_x25_channel *chan = dev->priv; if (chan->svc) { x25_clear_call(chan->card, chan->link, chan->lcn, 0, 0); - set_chan_state(dev, WAN_DISCONNECTING); + cycx_x25_set_chan_state(dev, WAN_DISCONNECTING); } else - set_chan_state(dev, WAN_DISCONNECTED); + cycx_x25_set_chan_state(dev, WAN_DISCONNECTED); } /* Called by kernel timer */ -static void chan_timer(unsigned long d) +static void cycx_x25_chan_timer(unsigned long d) { struct net_device *dev = (struct net_device *)d; struct cycx_x25_channel *chan = dev->priv; if (chan->state == WAN_CONNECTED) - chan_disconnect(dev); + cycx_x25_chan_disconnect(dev); else - printk(KERN_ERR "%s: chan_timer for svc (%s) not connected!\n", - chan->card->devname, dev->name); + printk(KERN_ERR "%s: %s for svc (%s) not connected!\n", + chan->card->devname, __FUNCTION__, dev->name); } /* Set logical channel state. */ -static void set_chan_state(struct net_device *dev, u8 state) +static void cycx_x25_set_chan_state(struct net_device *dev, u8 state) { struct cycx_x25_channel *chan = dev->priv; struct cycx_device *card = chan->card; @@ -1374,7 +1401,7 @@ static void set_chan_state(struct net_device *dev, u8 state) reset_timer(dev); if (chan->protocol == ETH_P_X25) - chan_x25_send_event(dev, 1); + cycx_x25_chan_send_event(dev, 1); break; case WAN_CONNECTING: @@ -1392,7 +1419,7 @@ static void set_chan_state(struct net_device *dev, u8 state) } if (chan->protocol == ETH_P_X25) - chan_x25_send_event(dev, 2); + cycx_x25_chan_send_event(dev, 2); netif_wake_queue(dev); break; @@ -1419,7 +1446,7 @@ static void set_chan_state(struct net_device *dev, u8 state) * the packet into 'complete sequence' using M-bit. * 2. When transmission is complete, an event notification should be issued * to the router. */ -static int chan_send(struct net_device *dev, struct sk_buff *skb) +static int cycx_x25_chan_send(struct net_device *dev, struct sk_buff *skb) { struct cycx_x25_channel *chan = dev->priv; struct cycx_device *card = chan->card; @@ -1431,7 +1458,7 @@ static int chan_send(struct net_device *dev, struct sk_buff *skb) bitm = 0x10; /* set M-bit (more data) */ } - if (x25_send(card, chan->link, chan->lcn, bitm, len, skb->data)) + if (cycx_x25_send(card, chan->link, chan->lcn, bitm, len, skb->data)) return 1; if (bitm) { @@ -1447,7 +1474,7 @@ static int chan_send(struct net_device *dev, struct sk_buff *skb) /* Send event (connection, disconnection, etc) to X.25 socket layer */ -static void chan_x25_send_event(struct net_device *dev, u8 event) +static void cycx_x25_chan_send_event(struct net_device *dev, u8 event) { struct sk_buff *skb; unsigned char *ptr; @@ -1525,7 +1552,7 @@ static void reset_timer(struct net_device *dev) mod_timer(&chan->timer, jiffies+chan->idle_tmout*HZ); } #ifdef CYCLOMX_X25_DEBUG -static void x25_dump_config(struct cycx_x25_config *conf) +static void cycx_x25_dump_config(struct cycx_x25_config *conf) { printk(KERN_INFO "X.25 configuration\n"); printk(KERN_INFO "-----------------\n"); @@ -1547,7 +1574,7 @@ static void x25_dump_config(struct cycx_x25_config *conf) printk(KERN_INFO "flags=0x%x\n", conf->flags); } -static void x25_dump_stats(struct cycx_x25_stats *stats) +static void cycx_x25_dump_stats(struct cycx_x25_stats *stats) { printk(KERN_INFO "X.25 statistics\n"); printk(KERN_INFO "--------------\n"); @@ -1563,7 +1590,7 @@ static void x25_dump_stats(struct cycx_x25_stats *stats) printk(KERN_INFO "rx_aborts=%d\n", stats->rx_aborts); } -static void x25_dump_devs(struct wan_device *wandev) +static void cycx_x25_dump_devs(struct wan_device *wandev) { struct net_device *dev = wandev->dev; diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c index c4d6785dfb56..1f17e03fab20 100644 --- a/drivers/net/yellowfin.c +++ b/drivers/net/yellowfin.c @@ -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; diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c index 0fda2ee135f8..e6cf5cb736c8 100644 --- a/drivers/usb/net/usbnet.c +++ b/drivers/usb/net/usbnet.c @@ -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, diff --git a/include/linux/cyclomx.h b/include/linux/cyclomx.h index c8f4173cc4d1..d84bc68e2af7 100644 --- a/include/linux/cyclomx.h +++ b/include/linux/cyclomx.h @@ -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 */ diff --git a/include/linux/divert.h b/include/linux/divert.h index 66e56ec15b66..38497a643657 100644 --- a/include/linux/divert.h +++ b/include/linux/divert.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 */ diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 94d077ef70be..7106c2eaf67e 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.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); } diff --git a/net/atm/proc.c b/net/atm/proc.c index 1efc0b7a0df2..eca265a87792 100644 --- a/net/atm/proc.c +++ b/net/atm/proc.c @@ -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); } diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c index ef876ca00b69..12c073e51b79 100644 --- a/net/bridge/br_netfilter.c +++ b/net/bridge/br_netfilter.c @@ -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]); } diff --git a/net/bridge/netfilter/ebtable_filter.c b/net/bridge/netfilter/ebtable_filter.c index ee9394bb5e01..c18666e0392b 100644 --- a/net/bridge/netfilter/ebtable_filter.c +++ b/net/bridge/netfilter/ebtable_filter.c @@ -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); } diff --git a/net/bridge/netfilter/ebtable_nat.c b/net/bridge/netfilter/ebtable_nat.c index ca39dac72f66..828cac2cc4a3 100644 --- a/net/bridge/netfilter/ebtable_nat.c +++ b/net/bridge/netfilter/ebtable_nat.c @@ -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); } diff --git a/net/core/Makefile b/net/core/Makefile index c30bc3bc7abd..dc05b5f08a5a 100644 --- a/net/core/Makefile +++ b/net/core/Makefile @@ -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 diff --git a/net/core/dev.c b/net/core/dev.c index db0273ba4a3a..d6d458ec7e4a 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -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 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c new file mode 100644 index 000000000000..e4f69ff53bf6 --- /dev/null +++ b/net/core/net-sysfs.c @@ -0,0 +1,344 @@ +/* + * 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); +} diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c index 4711ac69f3d1..63fdae09b071 100644 --- a/net/decnet/dn_dev.c +++ b/net/decnet/dn_dev.c @@ -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; diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index c66cf0b5950b..3ccb6c6c2978 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -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; } diff --git a/net/ipv4/netfilter/ip_conntrack_ftp.c b/net/ipv4/netfilter/ip_conntrack_ftp.c index dbcb4d1292c5..9a0fca610442 100644 --- a/net/ipv4/netfilter/ip_conntrack_ftp.c +++ b/net/ipv4/netfilter/ip_conntrack_ftp.c @@ -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, diff --git a/net/ipv4/route.c b/net/ipv4/route.c index d9e78a4e0650..d2989aaacf1b 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -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; diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 2047c3d31c9b..20b54ef6281d 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -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 diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c index f62883773c32..e61b52e1bed9 100644 --- a/net/ipv4/tcp_diag.c +++ b/net/ipv4/tcp_diag.c @@ -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); } } diff --git a/net/irda/irproc.c b/net/irda/irproc.c index c5f9cc1d00dd..aef346111238 100644 --- a/net/irda/irproc.c +++ b/net/irda/irproc.c @@ -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); diff --git a/net/netlink/netlink_dev.c b/net/netlink/netlink_dev.c index 94c99613890c..c38bdcb138d0 100644 --- a/net/netlink/netlink_dev.c +++ b/net/netlink/netlink_dev.c @@ -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); diff --git a/net/sctp/objcnt.c b/net/sctp/objcnt.c index 5d704fea933d..7e29bd6959a5 100644 --- a/net/sctp/objcnt.c +++ b/net/sctp/objcnt.c @@ -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. diff --git a/net/socket.c b/net/socket.c index 2f65bf513848..ba8e4fb345ab 100644 --- a/net/socket.c +++ b/net/socket.c @@ -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: diff --git a/net/sunrpc/pmap_clnt.c b/net/sunrpc/pmap_clnt.c index e934e2361880..ed627ea885e8 100644 --- a/net/sunrpc/pmap_clnt.c +++ b/net/sunrpc/pmap_clnt.c @@ -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, }; diff --git a/net/xfrm/xfrm_algo.c b/net/xfrm/xfrm_algo.c index b850f0285cf2..cd9327b9672c 100644 --- a/net/xfrm/xfrm_algo.c +++ b/net/xfrm/xfrm_algo.c @@ -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 */ |
