diff options
Diffstat (limited to 'drivers/net/wan')
-rw-r--r-- | drivers/net/wan/Kconfig | 4 | ||||
-rw-r--r-- | drivers/net/wan/c101.c | 46 | ||||
-rw-r--r-- | drivers/net/wan/cosa.c | 493 | ||||
-rw-r--r-- | drivers/net/wan/farsync.c | 487 | ||||
-rw-r--r-- | drivers/net/wan/fsl_ucc_hdlc.c | 3 | ||||
-rw-r--r-- | drivers/net/wan/hd64570.c | 124 | ||||
-rw-r--r-- | drivers/net/wan/hd64572.c | 95 | ||||
-rw-r--r-- | drivers/net/wan/hdlc.c | 63 | ||||
-rw-r--r-- | drivers/net/wan/hdlc_cisco.c | 49 | ||||
-rw-r--r-- | drivers/net/wan/hdlc_fr.c | 101 | ||||
-rw-r--r-- | drivers/net/wan/hdlc_ppp.c | 38 | ||||
-rw-r--r-- | drivers/net/wan/hdlc_x25.c | 77 | ||||
-rw-r--r-- | drivers/net/wan/hostess_sv11.c | 113 | ||||
-rw-r--r-- | drivers/net/wan/ixp4xx_hss.c | 144 | ||||
-rw-r--r-- | drivers/net/wan/lapbether.c | 65 | ||||
-rw-r--r-- | drivers/net/wan/lmc/lmc.h | 2 | ||||
-rw-r--r-- | drivers/net/wan/n2.c | 56 | ||||
-rw-r--r-- | drivers/net/wan/pc300too.c | 52 | ||||
-rw-r--r-- | drivers/net/wan/pci200syn.c | 51 | ||||
-rw-r--r-- | drivers/net/wan/sealevel.c | 126 | ||||
-rw-r--r-- | drivers/net/wan/wanxl.c | 190 | ||||
-rw-r--r-- | drivers/net/wan/z85230.c | 995 |
22 files changed, 1487 insertions, 1887 deletions
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig index 83c9481995dd..473df2505c8e 100644 --- a/drivers/net/wan/Kconfig +++ b/drivers/net/wan/Kconfig @@ -49,7 +49,7 @@ config COSA network device. You will need user-space utilities COSA or SRP boards for downloading - the firmware to the cards and to set them up. Look at the + the firmware to the cards and to set them up. Look at the <http://www.fi.muni.cz/~kas/cosa/> for more information. You can also read the comment at the top of the <file:drivers/net/wan/cosa.c> for details about the cards and the driver itself. @@ -108,7 +108,7 @@ config HDLC Generic HDLC driver currently supports raw HDLC, Cisco HDLC, Frame Relay, synchronous Point-to-Point Protocol (PPP) and X.25. - To compile this driver as a module, choose M here: the + To compile this driver as a module, choose M here: the module will be called hdlc. If unsure, say N. diff --git a/drivers/net/wan/c101.c b/drivers/net/wan/c101.c index c354a5143e99..059c2f7133be 100644 --- a/drivers/net/wan/c101.c +++ b/drivers/net/wan/c101.c @@ -28,9 +28,8 @@ #include "hd64570.h" - -static const char* version = "Moxa C101 driver version: 1.15"; -static const char* devname = "C101"; +static const char *version = "Moxa C101 driver version: 1.15"; +static const char *devname = "C101"; #undef DEBUG_PKT #define DEBUG_RINGS @@ -51,7 +50,6 @@ static const char* devname = "C101"; static char *hw; /* pointer to hw=xxx command line string */ - typedef struct card_s { struct net_device *dev; spinlock_t lock; /* TX lock */ @@ -72,14 +70,13 @@ typedef struct card_s { u8 page; struct card_s *next_card; -}card_t; +} card_t; typedef card_t port_t; static card_t *first_card; static card_t **new_card = &first_card; - #define sca_in(reg, card) readb((card)->win0base + C101_SCA + (reg)) #define sca_out(value, reg, card) writeb(value, (card)->win0base + C101_SCA + (reg)) #define sca_inw(reg, card) readw((card)->win0base + C101_SCA + (reg)) @@ -87,19 +84,18 @@ static card_t **new_card = &first_card; /* EDA address register must be set in EDAL, EDAH order - 8 bit ISA bus */ #define sca_outw(value, reg, card) do { \ writeb(value & 0xFF, (card)->win0base + C101_SCA + (reg)); \ - writeb((value >> 8 ) & 0xFF, (card)->win0base + C101_SCA + (reg + 1));\ -} while(0) + writeb((value >> 8) & 0xFF, (card)->win0base + C101_SCA + (reg + 1));\ +} while (0) #define port_to_card(port) (port) #define log_node(port) (0) #define phy_node(port) (0) #define winsize(card) (C101_WINDOW_SIZE) #define win0base(card) ((card)->win0base) -#define winbase(card) ((card)->win0base + 0x2000) +#define winbase(card) ((card)->win0base + 0x2000) #define get_port(card, port) (card) static void sca_msci_intr(port_t *port); - static inline u8 sca_get_page(card_t *card) { return card->page; @@ -111,10 +107,8 @@ static inline void openwin(card_t *card, u8 page) writeb(page, card->win0base + C101_PAGE); } - #include "hd64570.c" - static inline void set_carrier(port_t *port) { if (!(sca_in(MSCI1_OFFSET + ST3, port) & ST3_DCD)) @@ -123,7 +117,6 @@ static inline void set_carrier(port_t *port) netif_carrier_off(port_to_dev(port)); } - static void sca_msci_intr(port_t *port) { u8 stat = sca_in(MSCI0_OFFSET + ST1, port); /* read MSCI ST1 status */ @@ -145,13 +138,12 @@ static void sca_msci_intr(port_t *port) set_carrier(port); } - static void c101_set_iface(port_t *port) { u8 rxs = port->rxs & CLK_BRG_MASK; u8 txs = port->txs & CLK_BRG_MASK; - switch(port->settings.clock_type) { + switch (port->settings.clock_type) { case CLOCK_INT: rxs |= CLK_BRG_RX; /* TX clock */ txs |= CLK_RXCLK_TX; /* BRG output */ @@ -179,7 +171,6 @@ static void c101_set_iface(port_t *port) sca_set_port(port); } - static int c101_open(struct net_device *dev) { port_t *port = dev_to_port(dev); @@ -206,7 +197,6 @@ static int c101_open(struct net_device *dev) return 0; } - static int c101_close(struct net_device *dev) { port_t *port = dev_to_port(dev); @@ -218,7 +208,6 @@ static int c101_close(struct net_device *dev) return 0; } - static int c101_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { const size_t size = sizeof(sync_serial_settings); @@ -240,7 +229,7 @@ static int c101_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) if (cmd != SIOCWANDEV) return hdlc_ioctl(dev, ifr, cmd); - switch(ifr->ifr_settings.type) { + switch (ifr->ifr_settings.type) { case IF_GET_IFACE: ifr->ifr_settings.type = IF_IFACE_SYNC_SERIAL; if (ifr->ifr_settings.size < size) { @@ -252,7 +241,7 @@ static int c101_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) return 0; case IF_IFACE_SYNC_SERIAL: - if(!capable(CAP_NET_ADMIN)) + if (!capable(CAP_NET_ADMIN)) return -EPERM; if (copy_from_user(&new_line, line, size)) @@ -276,8 +265,6 @@ static int c101_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) } } - - static void c101_destroy_card(card_t *card) { readb(card->win0base + C101_PAGE); /* Resets SCA? */ @@ -309,18 +296,18 @@ static int __init c101_run(unsigned long irq, unsigned long winbase) card_t *card; int result; - if (irq<3 || irq>15 || irq == 6) /* FIXME */ { + if (irq < 3 || irq > 15 || irq == 6) /* FIXME */ { pr_err("invalid IRQ value\n"); return -ENODEV; } - if (winbase < 0xC0000 || winbase > 0xDFFFF || (winbase & 0x3FFF) !=0) { + if (winbase < 0xC0000 || winbase > 0xDFFFF || (winbase & 0x3FFF) != 0) { pr_err("invalid RAM value\n"); return -ENODEV; } card = kzalloc(sizeof(card_t), GFP_KERNEL); - if (card == NULL) + if (!card) return -ENOBUFS; card->dev = alloc_hdlcdev(card); @@ -392,11 +379,9 @@ static int __init c101_run(unsigned long irq, unsigned long winbase) return 0; } - - static int __init c101_init(void) { - if (hw == NULL) { + if (!hw) { #ifdef MODULE pr_info("no card initialized\n"); #endif @@ -419,26 +404,25 @@ static int __init c101_init(void) if (*hw == '\x0') return first_card ? 0 : -EINVAL; - }while(*hw++ == ':'); + } while (*hw++ == ':'); pr_err("invalid hardware parameters\n"); return first_card ? 0 : -EINVAL; } - static void __exit c101_cleanup(void) { card_t *card = first_card; while (card) { card_t *ptr = card; + card = card->next_card; unregister_hdlc_device(port_to_dev(ptr)); c101_destroy_card(ptr); } } - module_init(c101_init); module_exit(c101_cleanup); diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c index 2369ca250cd6..43caab0b7dee 100644 --- a/drivers/net/wan/cosa.c +++ b/drivers/net/wan/cosa.c @@ -1,13 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* $Id: cosa.c,v 1.31 2000/03/08 17:47:16 kas Exp $ */ -/* - * Copyright (C) 1995-1997 Jan "Yenya" Kasprzak <kas@fi.muni.cz> +/* Copyright (C) 1995-1997 Jan "Yenya" Kasprzak <kas@fi.muni.cz> * Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl> */ -/* - * The driver for the SRP and COSA synchronous serial cards. +/* The driver for the SRP and COSA synchronous serial cards. * * HARDWARE INFO * @@ -90,7 +88,7 @@ #define COSA_MAX_ID_STRING 128 /* Maximum length of the channel name */ -#define COSA_MAX_NAME (sizeof("cosaXXXcXXX")+1) +#define COSA_MAX_NAME (sizeof("cosaXXXcXXX") + 1) /* Per-channel data structure */ @@ -124,9 +122,9 @@ struct channel_data { }; /* cosa->firmware_status bits */ -#define COSA_FW_RESET (1<<0) /* Is the ROM monitor active? */ -#define COSA_FW_DOWNLOAD (1<<1) /* Is the microcode downloaded? */ -#define COSA_FW_START (1<<2) /* Is the microcode running? */ +#define COSA_FW_RESET BIT(0) /* Is the ROM monitor active? */ +#define COSA_FW_DOWNLOAD BIT(1) /* Is the microcode downloaded? */ +#define COSA_FW_START BIT(2) /* Is the microcode running? */ struct cosa_data { int num; /* Card number */ @@ -152,28 +150,25 @@ struct cosa_data { char *type; /* card type */ }; -/* - * Define this if you want all the possible ports to be autoprobed. +/* Define this if you want all the possible ports to be autoprobed. * It is here but it probably is not a good idea to use this. */ -/* #define COSA_ISA_AUTOPROBE 1 */ +/* #define COSA_ISA_AUTOPROBE 1*/ -/* - * Character device major number. 117 was allocated for us. +/* Character device major number. 117 was allocated for us. * The value of 0 means to allocate a first free one. */ static DEFINE_MUTEX(cosa_chardev_mutex); static int cosa_major = 117; -/* - * Encoding of the minor numbers: +/* Encoding of the minor numbers: * The lowest CARD_MINOR_BITS bits means the channel on the single card, * the highest bits means the card number. */ #define CARD_MINOR_BITS 4 /* How many bits in minor number are reserved - * for the single card */ -/* - * The following depends on CARD_MINOR_BITS. Unfortunately, the "MODULE_STRING" + * for the single card + */ +/* The following depends on CARD_MINOR_BITS. Unfortunately, the "MODULE_STRING" * macro doesn't like anything other than the raw number as an argument :-( */ #define MAX_CARDS 16 @@ -184,8 +179,7 @@ static int cosa_major = 117; #define DRIVER_TXMAP_SHIFT 2 #define DRIVER_TXMAP_MASK 0x0c /* FIXME: 0xfc for 8-channel version */ -/* - * for cosa->rxtx - indicates whether either transmit or receive is +/* for cosa->rxtx - indicates whether either transmit or receive is * in progress. These values are mean number of the bit. */ #define TXBIT 0 @@ -198,22 +192,22 @@ static int cosa_major = 117; #undef DEBUG_IRQS //1 /* Print the message when the IRQ is received */ #undef DEBUG_IO //1 /* Dump the I/O traffic */ -#define TX_TIMEOUT (5*HZ) +#define TX_TIMEOUT (5 * HZ) /* Maybe the following should be allocated dynamically */ static struct cosa_data cosa_cards[MAX_CARDS]; static int nr_cards; #ifdef COSA_ISA_AUTOPROBE -static int io[MAX_CARDS+1] = { 0x220, 0x228, 0x210, 0x218, 0, }; +static int io[MAX_CARDS + 1] = {0x220, 0x228, 0x210, 0x218, 0,}; /* NOTE: DMA is not autoprobed!!! */ -static int dma[MAX_CARDS+1] = { 1, 7, 1, 7, 1, 7, 1, 7, 0, }; +static int dma[MAX_CARDS + 1] = {1, 7, 1, 7, 1, 7, 1, 7, 0,}; #else -static int io[MAX_CARDS+1]; -static int dma[MAX_CARDS+1]; +static int io[MAX_CARDS + 1]; +static int dma[MAX_CARDS + 1]; #endif /* IRQ can be safely autoprobed */ -static int irq[MAX_CARDS+1] = { -1, -1, -1, -1, -1, -1, 0, }; +static int irq[MAX_CARDS + 1] = {-1, -1, -1, -1, -1, -1, 0,}; /* for class stuff*/ static struct class *cosa_class; @@ -244,14 +238,14 @@ MODULE_LICENSE("GPL"); #define cosa_inw inw #endif -#define is_8bit(cosa) (!(cosa->datareg & 0x08)) +#define is_8bit(cosa) (!((cosa)->datareg & 0x08)) -#define cosa_getstatus(cosa) (cosa_inb(cosa->statusreg)) -#define cosa_putstatus(cosa, stat) (cosa_outb(stat, cosa->statusreg)) -#define cosa_getdata16(cosa) (cosa_inw(cosa->datareg)) -#define cosa_getdata8(cosa) (cosa_inb(cosa->datareg)) -#define cosa_putdata16(cosa, dt) (cosa_outw(dt, cosa->datareg)) -#define cosa_putdata8(cosa, dt) (cosa_outb(dt, cosa->datareg)) +#define cosa_getstatus(cosa) (cosa_inb((cosa)->statusreg)) +#define cosa_putstatus(cosa, stat) (cosa_outb(stat, (cosa)->statusreg)) +#define cosa_getdata16(cosa) (cosa_inw((cosa)->datareg)) +#define cosa_getdata8(cosa) (cosa_inb((cosa)->datareg)) +#define cosa_putdata16(cosa, dt) (cosa_outw(dt, (cosa)->datareg)) +#define cosa_putdata8(cosa, dt) (cosa_outb(dt, (cosa)->datareg)) /* Initialization stuff */ static int cosa_probe(int ioaddr, int irq, int dma); @@ -280,14 +274,14 @@ static char *chrdev_setup_rx(struct channel_data *channel, int size); static int chrdev_rx_done(struct channel_data *channel); static int chrdev_tx_done(struct channel_data *channel, int size); static ssize_t cosa_read(struct file *file, - char __user *buf, size_t count, loff_t *ppos); + char __user *buf, size_t count, loff_t *ppos); static ssize_t cosa_write(struct file *file, - const char __user *buf, size_t count, loff_t *ppos); + const char __user *buf, size_t count, loff_t *ppos); static unsigned int cosa_poll(struct file *file, poll_table *poll); static int cosa_open(struct inode *inode, struct file *file); static int cosa_release(struct inode *inode, struct file *file); static long cosa_chardev_ioctl(struct file *file, unsigned int cmd, - unsigned long arg); + unsigned long arg); #ifdef COSA_FASYNC_WORKING static int cosa_fasync(struct inode *inode, struct file *file, int on); #endif @@ -337,7 +331,7 @@ static void debug_status_in(struct cosa_data *cosa, int status); static void debug_status_out(struct cosa_data *cosa, int status); #endif -static inline struct channel_data* dev_to_chan(struct net_device *dev) +static inline struct channel_data *dev_to_chan(struct net_device *dev) { return (struct channel_data *)dev_to_hdlc(dev)->priv; } @@ -355,15 +349,16 @@ static int __init cosa_init(void) goto out; } } else { - if (!(cosa_major=register_chrdev(0, "cosa", &cosa_fops))) { + cosa_major = register_chrdev(0, "cosa", &cosa_fops); + if (!cosa_major) { pr_warn("unable to register chardev\n"); err = -EIO; goto out; } } - for (i=0; i<MAX_CARDS; i++) + for (i = 0; i < MAX_CARDS; i++) cosa_cards[i].num = -1; - for (i=0; io[i] != 0 && i < MAX_CARDS; i++) + for (i = 0; io[i] != 0 && i < MAX_CARDS; i++) cosa_probe(io[i], irq[i], dma[i]); if (!nr_cards) { pr_warn("no devices found\n"); @@ -426,7 +421,7 @@ static const struct net_device_ops cosa_ops = { static int cosa_probe(int base, int irq, int dma) { - struct cosa_data *cosa = cosa_cards+nr_cards; + struct cosa_data *cosa = cosa_cards + nr_cards; int i, err = 0; memset(cosa, 0, sizeof(struct cosa_data)); @@ -438,7 +433,8 @@ static int cosa_probe(int base, int irq, int dma) return -1; } /* I/O address should be between 0x100 and 0x3ff and should be - * multiple of 8. */ + * multiple of 8. + */ if (base < 0x100 || base > 0x3ff || base & 0x7) { pr_info("invalid I/O address 0x%x\n", base); return -1; @@ -448,8 +444,9 @@ static int cosa_probe(int base, int irq, int dma) pr_info("invalid DMA %d\n", dma); return -1; } - /* and finally, on 16-bit COSA DMA should be 4-7 and - * I/O base should not be multiple of 0x10 */ + /* and finally, on 16-bit COSA DMA should be 4-7 and + * I/O base should not be multiple of 0x10 + */ if (((base & 0x8) && dma < 4) || (!(base & 0x8) && dma > 3)) { pr_info("8/16 bit base and DMA mismatch (base=0x%x, dma=%d)\n", base, dma); @@ -458,12 +455,12 @@ static int cosa_probe(int base, int irq, int dma) cosa->dma = dma; cosa->datareg = base; - cosa->statusreg = is_8bit(cosa)?base+1:base+2; + cosa->statusreg = is_8bit(cosa) ? base + 1 : base + 2; spin_lock_init(&cosa->lock); - if (!request_region(base, is_8bit(cosa)?2:4,"cosa")) + if (!request_region(base, is_8bit(cosa) ? 2 : 4, "cosa")) return -1; - + if (cosa_reset_and_read_id(cosa, cosa->id_string) < 0) { printk(KERN_DEBUG "probe at 0x%x failed.\n", base); err = -1; @@ -471,11 +468,11 @@ static int cosa_probe(int base, int irq, int dma) } /* Test the validity of identification string */ - if (!strncmp(cosa->id_string, "SRP", 3)) + if (!strncmp(cosa->id_string, "SRP", 3)) { cosa->type = "srp"; - else if (!strncmp(cosa->id_string, "COSA", 4)) - cosa->type = is_8bit(cosa)? "cosa8": "cosa16"; - else { + } else if (!strncmp(cosa->id_string, "COSA", 4)) { + cosa->type = is_8bit(cosa) ? "cosa8" : "cosa16"; + } else { /* Print a warning only if we are not autoprobing */ #ifndef COSA_ISA_AUTOPROBE pr_info("valid signature not found at 0x%x\n", base); @@ -483,9 +480,9 @@ static int cosa_probe(int base, int irq, int dma) err = -1; goto err_out; } - /* Update the name of the region now we know the type of card */ - release_region(base, is_8bit(cosa)?2:4); - if (!request_region(base, is_8bit(cosa)?2:4, cosa->type)) { + /* Update the name of the region now we know the type of card */ + release_region(base, is_8bit(cosa) ? 2 : 4); + if (!request_region(base, is_8bit(cosa) ? 2 : 4, cosa->type)) { printk(KERN_DEBUG "changing name at 0x%x failed.\n", base); return -1; } @@ -495,8 +492,7 @@ static int cosa_probe(int base, int irq, int dma) unsigned long irqs; /* pr_info("IRQ autoprobe\n"); */ irqs = probe_irq_on(); - /* - * Enable interrupt on tx buffer empty (it sure is) + /* Enable interrupt on tx buffer empty (it sure is) * really sure ? * FIXME: When this code is not used as module, we should * probably call udelay() instead of the interruptible sleep. @@ -536,8 +532,8 @@ static int cosa_probe(int base, int irq, int dma) err = -1; goto err_out1; } - - cosa->bouncebuf = kmalloc(COSA_MTU, GFP_KERNEL|GFP_DMA); + + cosa->bouncebuf = kmalloc(COSA_MTU, GFP_KERNEL | GFP_DMA); if (!cosa->bouncebuf) { err = -ENOMEM; goto err_out2; @@ -563,7 +559,8 @@ static int cosa_probe(int base, int irq, int dma) sema_init(&chan->wsem, 1); /* Register the network interface */ - if (!(chan->netdev = alloc_hdlcdev(chan))) { + chan->netdev = alloc_hdlcdev(chan); + if (!chan->netdev) { pr_warn("%s: alloc_hdlcdev failed\n", chan->name); err = -ENOMEM; goto err_hdlcdev; @@ -603,12 +600,11 @@ err_out2: err_out1: free_irq(cosa->irq, cosa); err_out: - release_region(cosa->datareg,is_8bit(cosa)?2:4); + release_region(cosa->datareg, is_8bit(cosa) ? 2 : 4); pr_notice("cosa%d: allocating resources failed\n", cosa->num); return err; } - /*---------- network device ---------- */ static int cosa_net_attach(struct net_device *dev, unsigned short encoding, @@ -659,7 +655,7 @@ static int cosa_net_open(struct net_device *dev) } static netdev_tx_t cosa_net_tx(struct sk_buff *skb, - struct net_device *dev) + struct net_device *dev) { struct channel_data *chan = dev_to_chan(dev); @@ -714,13 +710,12 @@ static int cosa_net_close(struct net_device *dev) static char *cosa_net_setup_rx(struct channel_data *chan, int size) { - /* - * We can safely fall back to non-dma-able memory, because we have + /* We can safely fall back to non-dma-able memory, because we have * the cosa->bouncebuf pre-allocated. */ kfree_skb(chan->rx_skb); chan->rx_skb = dev_alloc_skb(size); - if (chan->rx_skb == NULL) { + if (!chan->rx_skb) { pr_notice("%s: Memory squeeze, dropping packet\n", chan->name); chan->netdev->stats.rx_dropped++; return NULL; @@ -767,7 +762,7 @@ static int cosa_net_tx_done(struct channel_data *chan, int size) /*---------- Character device ---------- */ static ssize_t cosa_read(struct file *file, - char __user *buf, size_t count, loff_t *ppos) + char __user *buf, size_t count, loff_t *ppos) { DECLARE_WAITQUEUE(wait, current); unsigned long flags; @@ -782,9 +777,9 @@ static ssize_t cosa_read(struct file *file, } if (mutex_lock_interruptible(&chan->rlock)) return -ERESTARTSYS; - - chan->rxdata = kmalloc(COSA_MTU, GFP_DMA|GFP_KERNEL); - if (chan->rxdata == NULL) { + + chan->rxdata = kmalloc(COSA_MTU, GFP_DMA | GFP_KERNEL); + if (!chan->rxdata) { mutex_unlock(&chan->rlock); return -ENOMEM; } @@ -840,9 +835,8 @@ static int chrdev_rx_done(struct channel_data *chan) return 1; } - static ssize_t cosa_write(struct file *file, - const char __user *buf, size_t count, loff_t *ppos) + const char __user *buf, size_t count, loff_t *ppos) { DECLARE_WAITQUEUE(wait, current); struct channel_data *chan = file->private_data; @@ -860,10 +854,10 @@ static ssize_t cosa_write(struct file *file, if (count > COSA_MTU) count = COSA_MTU; - + /* Allocate the buffer */ - kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA); - if (kbuf == NULL) { + kbuf = kmalloc(count, GFP_KERNEL | GFP_DMA); + if (!kbuf) { up(&chan->wsem); return -ENOMEM; } @@ -872,7 +866,7 @@ static ssize_t cosa_write(struct file *file, kfree(kbuf); return -EFAULT; } - chan->tx_status=0; + chan->tx_status = 0; cosa_start_tx(chan, kbuf, count); spin_lock_irqsave(&cosa->lock, flags); @@ -927,20 +921,20 @@ static int cosa_open(struct inode *inode, struct file *file) int ret = 0; mutex_lock(&cosa_chardev_mutex); - if ((n=iminor(file_inode(file))>>CARD_MINOR_BITS) - >= nr_cards) { + n = iminor(file_inode(file)) >> CARD_MINOR_BITS; + if (n >= nr_cards) { ret = -ENODEV; goto out; } - cosa = cosa_cards+n; + cosa = cosa_cards + n; - if ((n=iminor(file_inode(file)) - & ((1<<CARD_MINOR_BITS)-1)) >= cosa->nchannels) { + n = iminor(file_inode(file)) & ((1 << CARD_MINOR_BITS) - 1); + if (n >= cosa->nchannels) { ret = -ENODEV; goto out; } chan = cosa->chan + n; - + file->private_data = chan; spin_lock_irqsave(&cosa->lock, flags); @@ -982,26 +976,25 @@ static struct fasync_struct *fasync[256] = { NULL, }; /* To be done ... */ static int cosa_fasync(struct inode *inode, struct file *file, int on) { - int port = iminor(inode); + int port = iminor(inode); return fasync_helper(inode, file, on, &fasync[port]); } #endif - /* ---------- Ioctls ---------- */ -/* - * Ioctl subroutines can safely be made inline, because they are called +/* Ioctl subroutines can safely be made inline, because they are called * only from cosa_ioctl(). */ static inline int cosa_reset(struct cosa_data *cosa) { char idstring[COSA_MAX_ID_STRING]; + if (cosa->usage > 1) pr_info("cosa%d: WARNING: reset requested with cosa->usage > 1 (%d). Odd things may happen.\n", cosa->num, cosa->usage); - cosa->firmware_status &= ~(COSA_FW_RESET|COSA_FW_START); + cosa->firmware_status &= ~(COSA_FW_RESET | COSA_FW_START); if (cosa_reset_and_read_id(cosa, idstring) < 0) { pr_notice("cosa%d: reset failed\n", cosa->num); return -EIO; @@ -1025,7 +1018,7 @@ static inline int cosa_download(struct cosa_data *cosa, void __user *arg) cosa->name, cosa->firmware_status); return -EPERM; } - + if (copy_from_user(&d, arg, sizeof(d))) return -EFAULT; @@ -1034,9 +1027,8 @@ static inline int cosa_download(struct cosa_data *cosa, void __user *arg) if (d.len < 0 || d.len > COSA_MAX_FIRMWARE_SIZE) return -EINVAL; - /* If something fails, force the user to reset the card */ - cosa->firmware_status &= ~(COSA_FW_RESET|COSA_FW_DOWNLOAD); + cosa->firmware_status &= ~(COSA_FW_RESET | COSA_FW_DOWNLOAD); i = download(cosa, d.code, d.len, d.addr); if (i < 0) { @@ -1046,7 +1038,7 @@ static inline int cosa_download(struct cosa_data *cosa, void __user *arg) } pr_info("cosa%d: downloading microcode - 0x%04x bytes at 0x%04x\n", cosa->num, d.len, d.addr); - cosa->firmware_status |= COSA_FW_RESET|COSA_FW_DOWNLOAD; + cosa->firmware_status |= COSA_FW_RESET | COSA_FW_DOWNLOAD; return 0; } @@ -1091,14 +1083,15 @@ static inline int cosa_start(struct cosa_data *cosa, int address) pr_info("cosa%d: WARNING: start microcode requested with cosa->usage > 1 (%d). Odd things may happen.\n", cosa->num, cosa->usage); - if ((cosa->firmware_status & (COSA_FW_RESET|COSA_FW_DOWNLOAD)) - != (COSA_FW_RESET|COSA_FW_DOWNLOAD)) { + if ((cosa->firmware_status & (COSA_FW_RESET | COSA_FW_DOWNLOAD)) + != (COSA_FW_RESET | COSA_FW_DOWNLOAD)) { pr_notice("%s: download the microcode and/or reset the card first (status %d)\n", cosa->name, cosa->firmware_status); return -EPERM; } cosa->firmware_status &= ~COSA_FW_RESET; - if ((i=startmicrocode(cosa, address)) < 0) { + i = startmicrocode(cosa, address); + if (i < 0) { pr_notice("cosa%d: start microcode at 0x%04x failed: %d\n", cosa->num, address, i); return -EIO; @@ -1108,11 +1101,12 @@ static inline int cosa_start(struct cosa_data *cosa, int address) cosa->firmware_status |= COSA_FW_START; return 0; } - + /* Buffer of size at least COSA_MAX_ID_STRING is expected */ static inline int cosa_getidstr(struct cosa_data *cosa, char __user *string) { - int l = strlen(cosa->id_string)+1; + int l = strlen(cosa->id_string) + 1; + if (copy_to_user(string, cosa->id_string, l)) return -EFAULT; return l; @@ -1121,16 +1115,19 @@ static inline int cosa_getidstr(struct cosa_data *cosa, char __user *string) /* Buffer of size at least COSA_MAX_ID_STRING is expected */ static inline int cosa_gettype(struct cosa_data *cosa, char __user *string) { - int l = strlen(cosa->type)+1; + int l = strlen(cosa->type) + 1; + if (copy_to_user(string, cosa->type, l)) return -EFAULT; return l; } static int cosa_ioctl_common(struct cosa_data *cosa, - struct channel_data *channel, unsigned int cmd, unsigned long arg) + struct channel_data *channel, unsigned int cmd, + unsigned long arg) { void __user *argp = (void __user *)arg; + switch (cmd) { case COSAIORSET: /* Reset the device */ if (!capable(CAP_NET_ADMIN)) @@ -1143,7 +1140,7 @@ static int cosa_ioctl_common(struct cosa_data *cosa, case COSAIODOWNLD: /* Download the firmware */ if (!capable(CAP_SYS_RAWIO)) return -EACCES; - + return cosa_download(cosa, argp); case COSAIORMEM: if (!capable(CAP_SYS_RAWIO)) @@ -1176,6 +1173,7 @@ static int cosa_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { int rv; struct channel_data *chan = dev_to_chan(dev); + rv = cosa_ioctl_common(chan->cosa, chan, cmd, (unsigned long)ifr->ifr_data); if (rv != -ENOIOCTLCMD) @@ -1184,7 +1182,7 @@ static int cosa_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) } static long cosa_chardev_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) + unsigned long arg) { struct channel_data *channel = file->private_data; struct cosa_data *cosa; @@ -1197,11 +1195,9 @@ static long cosa_chardev_ioctl(struct file *file, unsigned int cmd, return ret; } - /*---------- HW layer interface ---------- */ -/* - * The higher layer can bind itself to the HW layer by setting the callbacks +/* The higher layer can bind itself to the HW layer by setting the callbacks * in the channel_data structure and by using these routines. */ static void cosa_enable_rx(struct channel_data *chan) @@ -1220,8 +1216,7 @@ static void cosa_disable_rx(struct channel_data *chan) put_driver_status(cosa); } -/* - * FIXME: This routine probably should check for cosa_start_tx() called when +/* FIXME: This routine probably should check for cosa_start_tx() called when * the previous transmit is still unfinished. In this case the non-zero * return value should indicate to the caller that the queuing(sp?) up * the transmit has failed. @@ -1235,7 +1230,7 @@ static int cosa_start_tx(struct channel_data *chan, char *buf, int len) pr_info("cosa%dc%d: starting tx(0x%x)", chan->cosa->num, chan->num, len); - for (i=0; i<len; i++) + for (i = 0; i < len; i++) pr_cont(" %02x", buf[i]&0xff); pr_cont("\n"); #endif @@ -1262,10 +1257,10 @@ static void put_driver_status(struct cosa_data *cosa) status = (cosa->rxbitmap ? DRIVER_RX_READY : 0) | (cosa->txbitmap ? DRIVER_TX_READY : 0) - | (cosa->txbitmap? ~(cosa->txbitmap<<DRIVER_TXMAP_SHIFT) - &DRIVER_TXMAP_MASK : 0); + | (cosa->txbitmap ? ~(cosa->txbitmap << DRIVER_TXMAP_SHIFT) + & DRIVER_TXMAP_MASK : 0); if (!cosa->rxtx) { - if (cosa->rxbitmap|cosa->txbitmap) { + if (cosa->rxbitmap | cosa->txbitmap) { if (!cosa->enabled) { cosa_putstatus(cosa, SR_RX_INT_ENA); #ifdef DEBUG_IO @@ -1294,10 +1289,10 @@ static void put_driver_status_nolock(struct cosa_data *cosa) status = (cosa->rxbitmap ? DRIVER_RX_READY : 0) | (cosa->txbitmap ? DRIVER_TX_READY : 0) - | (cosa->txbitmap? ~(cosa->txbitmap<<DRIVER_TXMAP_SHIFT) - &DRIVER_TXMAP_MASK : 0); + | (cosa->txbitmap ? ~(cosa->txbitmap << DRIVER_TXMAP_SHIFT) + & DRIVER_TXMAP_MASK : 0); - if (cosa->rxbitmap|cosa->txbitmap) { + if (cosa->rxbitmap | cosa->txbitmap) { cosa_putstatus(cosa, SR_RX_INT_ENA); #ifdef DEBUG_IO debug_status_out(cosa, SR_RX_INT_ENA); @@ -1316,8 +1311,7 @@ static void put_driver_status_nolock(struct cosa_data *cosa) #endif } -/* - * The "kickme" function: When the DMA times out, this is called to +/* The "kickme" function: When the DMA times out, this is called to * clean up the driver status. * FIXME: Preliminary support, the interface is probably wrong. */ @@ -1344,7 +1338,7 @@ static void cosa_kick(struct cosa_data *cosa) udelay(100); cosa_putstatus(cosa, 0); udelay(100); - (void) cosa_getdata8(cosa); + (void)cosa_getdata8(cosa); udelay(100); cosa_putdata8(cosa, 0); udelay(100); @@ -1352,8 +1346,7 @@ static void cosa_kick(struct cosa_data *cosa) spin_unlock_irqrestore(&cosa->lock, flags); } -/* - * Check if the whole buffer is DMA-able. It means it is below the 16M of +/* Check if the whole buffer is DMA-able. It means it is below the 16M of * physical memory and doesn't span the 64k boundary. For now it seems * SKB's never do this, but we'll check this anyway. */ @@ -1361,9 +1354,10 @@ static int cosa_dma_able(struct channel_data *chan, char *buf, int len) { static int count; unsigned long b = (unsigned long)buf; - if (b+len >= MAX_DMA_ADDRESS) + + if (b + len >= MAX_DMA_ADDRESS) return 0; - if ((b^ (b+len)) & 0x10000) { + if ((b ^ (b + len)) & 0x10000) { if (count++ < 5) pr_info("%s: packet spanning a 64k boundary\n", chan->name); @@ -1372,11 +1366,9 @@ static int cosa_dma_able(struct channel_data *chan, char *buf, int len) return 1; } - /* ---------- The SRP/COSA ROM monitor functions ---------- */ -/* - * Downloading SRP microcode: say "w" to SRP monitor, it answers by "w=", +/* Downloading SRP microcode: say "w" to SRP monitor, it answers by "w=", * drivers need to say 4-digit hex number meaning start address of the microcode * separated by a single space. Monitor replies by saying " =". Now driver * has to write 4-digit hex number meaning the last byte address ended @@ -1387,18 +1379,27 @@ static int download(struct cosa_data *cosa, const char __user *microcode, int le { int i; - if (put_wait_data(cosa, 'w') == -1) return -1; + if (put_wait_data(cosa, 'w') == -1) + return -1; if ((i=get_wait_data(cosa)) != 'w') { printk("dnld: 0x%04x\n",i); return -2;} - if (get_wait_data(cosa) != '=') return -3; - - if (puthexnumber(cosa, address) < 0) return -4; - if (put_wait_data(cosa, ' ') == -1) return -10; - if (get_wait_data(cosa) != ' ') return -11; - if (get_wait_data(cosa) != '=') return -12; - - if (puthexnumber(cosa, address+length-1) < 0) return -13; - if (put_wait_data(cosa, ' ') == -1) return -18; - if (get_wait_data(cosa) != ' ') return -19; + if (get_wait_data(cosa) != '=') + return -3; + + if (puthexnumber(cosa, address) < 0) + return -4; + if (put_wait_data(cosa, ' ') == -1) + return -10; + if (get_wait_data(cosa) != ' ') + return -11; + if (get_wait_data(cosa) != '=') + return -12; + + if (puthexnumber(cosa, address + length - 1) < 0) + return -13; + if (put_wait_data(cosa, ' ') == -1) + return -18; + if (get_wait_data(cosa) != ' ') + return -19; while (length--) { char c; @@ -1413,43 +1414,53 @@ static int download(struct cosa_data *cosa, const char __user *microcode, int le microcode++; } - if (get_wait_data(cosa) != '\r') return -21; - if (get_wait_data(cosa) != '\n') return -22; - if (get_wait_data(cosa) != '.') return -23; + if (get_wait_data(cosa) != '\r') + return -21; + if (get_wait_data(cosa) != '\n') + return -22; + if (get_wait_data(cosa) != '.') + return -23; #if 0 printk(KERN_DEBUG "cosa%d: download completed.\n", cosa->num); #endif return 0; } - -/* - * Starting microcode is done via the "g" command of the SRP monitor. +/* Starting microcode is done via the "g" command of the SRP monitor. * The chat should be the following: "g" "g=" "<addr><CR>" * "<CR><CR><LF><CR><LF>". */ static int startmicrocode(struct cosa_data *cosa, int address) { - if (put_wait_data(cosa, 'g') == -1) return -1; - if (get_wait_data(cosa) != 'g') return -2; - if (get_wait_data(cosa) != '=') return -3; - - if (puthexnumber(cosa, address) < 0) return -4; - if (put_wait_data(cosa, '\r') == -1) return -5; - - if (get_wait_data(cosa) != '\r') return -6; - if (get_wait_data(cosa) != '\r') return -7; - if (get_wait_data(cosa) != '\n') return -8; - if (get_wait_data(cosa) != '\r') return -9; - if (get_wait_data(cosa) != '\n') return -10; + if (put_wait_data(cosa, 'g') == -1) + return -1; + if (get_wait_data(cosa) != 'g') + return -2; + if (get_wait_data(cosa) != '=') + return -3; + + if (puthexnumber(cosa, address) < 0) + return -4; + if (put_wait_data(cosa, '\r') == -1) + return -5; + + if (get_wait_data(cosa) != '\r') + return -6; + if (get_wait_data(cosa) != '\r') + return -7; + if (get_wait_data(cosa) != '\n') + return -8; + if (get_wait_data(cosa) != '\r') + return -9; + if (get_wait_data(cosa) != '\n') + return -10; #if 0 printk(KERN_DEBUG "cosa%d: microcode started\n", cosa->num); #endif return 0; } -/* - * Reading memory is done via the "r" command of the SRP monitor. +/* Reading memory is done via the "r" command of the SRP monitor. * The chat is the following "r" "r=" "<addr> " " =" "<last_byte> " " " * Then driver can read the data and the conversation is finished * by SRP monitor sending "<CR><LF>." (dot at the end). @@ -1459,27 +1470,39 @@ static int startmicrocode(struct cosa_data *cosa, int address) */ static int readmem(struct cosa_data *cosa, char __user *microcode, int length, int address) { - if (put_wait_data(cosa, 'r') == -1) return -1; - if ((get_wait_data(cosa)) != 'r') return -2; - if ((get_wait_data(cosa)) != '=') return -3; - - if (puthexnumber(cosa, address) < 0) return -4; - if (put_wait_data(cosa, ' ') == -1) return -5; - if (get_wait_data(cosa) != ' ') return -6; - if (get_wait_data(cosa) != '=') return -7; - - if (puthexnumber(cosa, address+length-1) < 0) return -8; - if (put_wait_data(cosa, ' ') == -1) return -9; - if (get_wait_data(cosa) != ' ') return -10; + if (put_wait_data(cosa, 'r') == -1) + return -1; + if ((get_wait_data(cosa)) != 'r') + return -2; + if ((get_wait_data(cosa)) != '=') + return -3; + + if (puthexnumber(cosa, address) < 0) + return -4; + if (put_wait_data(cosa, ' ') == -1) + return -5; + if (get_wait_data(cosa) != ' ') + return -6; + if (get_wait_data(cosa) != '=') + return -7; + + if (puthexnumber(cosa, address + length - 1) < 0) + return -8; + if (put_wait_data(cosa, ' ') == -1) + return -9; + if (get_wait_data(cosa) != ' ') + return -10; while (length--) { char c; int i; - if ((i=get_wait_data(cosa)) == -1) { + + i = get_wait_data(cosa); + if (i == -1) { pr_info("0x%04x bytes remaining\n", length); return -11; } - c=i; + c = i; #if 1 if (put_user(c, microcode)) return -23; /* ??? */ @@ -1489,22 +1512,24 @@ static int readmem(struct cosa_data *cosa, char __user *microcode, int length, i microcode++; } - if (get_wait_data(cosa) != '\r') return -21; - if (get_wait_data(cosa) != '\n') return -22; - if (get_wait_data(cosa) != '.') return -23; + if (get_wait_data(cosa) != '\r') + return -21; + if (get_wait_data(cosa) != '\n') + return -22; + if (get_wait_data(cosa) != '.') + return -23; #if 0 printk(KERN_DEBUG "cosa%d: readmem completed.\n", cosa->num); #endif return 0; } -/* - * This function resets the device and reads the initial prompt +/* This function resets the device and reads the initial prompt * of the device's ROM monitor. */ static int cosa_reset_and_read_id(struct cosa_data *cosa, char *idstring) { - int i=0, id=0, prev=0, curr=0; + int i = 0, id = 0, prev = 0, curr = 0; /* Reset the card ... */ cosa_putstatus(cosa, 0); @@ -1514,18 +1539,18 @@ static int cosa_reset_and_read_id(struct cosa_data *cosa, char *idstring) /* Disable all IRQs from the card */ cosa_putstatus(cosa, 0); - /* - * Try to read the ID string. The card then prints out the + /* Try to read the ID string. The card then prints out the * identification string ended by the "\n\x2e". * * The following loop is indexed through i (instead of id) * to avoid looping forever when for any reason * the port returns '\r', '\n' or '\x2e' permanently. */ - for (i=0; i<COSA_MAX_ID_STRING-1; i++, prev=curr) { - if ((curr = get_wait_data(cosa)) == -1) { + for (i = 0; i < COSA_MAX_ID_STRING - 1; i++, prev = curr) { + curr = get_wait_data(cosa); + if (curr == -1) return -1; - } + curr &= 0xff; if (curr != '\r' && curr != '\n' && curr != 0x2e) idstring[id++] = curr; @@ -1537,11 +1562,9 @@ static int cosa_reset_and_read_id(struct cosa_data *cosa, char *idstring) return id; } - /* ---------- Auxiliary routines for COSA/SRP monitor ---------- */ -/* - * This routine gets the data byte from the card waiting for the SR_RX_RDY +/* This routine gets the data byte from the card waiting for the SR_RX_RDY * bit to be set in a loop. It should be used in the exceptional cases * only (for example when resetting the card or downloading the firmware. */ @@ -1553,10 +1576,11 @@ static int get_wait_data(struct cosa_data *cosa) /* read data and return them */ if (cosa_getstatus(cosa) & SR_RX_RDY) { short r; + r = cosa_getdata8(cosa); #if 0 pr_info("get_wait_data returning after %d retries\n", - 999-retries); + 999 - retries); #endif return r; } @@ -1568,20 +1592,20 @@ static int get_wait_data(struct cosa_data *cosa) return -1; } -/* - * This routine puts the data byte to the card waiting for the SR_TX_RDY +/* This routine puts the data byte to the card waiting for the SR_TX_RDY * bit to be set in a loop. It should be used in the exceptional cases * only (for example when resetting the card or downloading the firmware). */ static int put_wait_data(struct cosa_data *cosa, int data) { int retries = 1000; + while (--retries) { /* read data and return them */ if (cosa_getstatus(cosa) & SR_TX_RDY) { cosa_putdata8(cosa, data); #if 0 - pr_info("Putdata: %d retries\n", 999-retries); + pr_info("Putdata: %d retries\n", 999 - retries); #endif return 0; } @@ -1594,9 +1618,8 @@ static int put_wait_data(struct cosa_data *cosa, int data) cosa->num, cosa_getstatus(cosa)); return -1; } - -/* - * The following routine puts the hexadecimal number into the SRP monitor + +/* The following routine puts the hexadecimal number into the SRP monitor * and verifies the proper echo of the sent bytes. Returns 0 on success, * negative number on failure (-1,-3,-5,-7) means that put_wait_data() failed, * (-2,-4,-6,-8) means that reading echo failed. @@ -1608,26 +1631,24 @@ static int puthexnumber(struct cosa_data *cosa, int number) /* Well, I should probably replace this by something faster. */ sprintf(temp, "%04X", number); - for (i=0; i<4; i++) { + for (i = 0; i < 4; i++) { if (put_wait_data(cosa, temp[i]) == -1) { pr_notice("cosa%d: puthexnumber failed to write byte %d\n", cosa->num, i); - return -1-2*i; + return -1 - 2 * i; } if (get_wait_data(cosa) != temp[i]) { pr_notice("cosa%d: puthexhumber failed to read echo of byte %d\n", cosa->num, i); - return -2-2*i; + return -2 - 2 * i; } } return 0; } - /* ---------- Interrupt routines ---------- */ -/* - * There are three types of interrupt: +/* There are three types of interrupt: * At the beginning of transmit - this handled is in tx_interrupt(), * at the beginning of receive - it is in rx_interrupt() and * at the end of transmit/receive - it is the eot_interrupt() function. @@ -1635,14 +1656,13 @@ static int puthexnumber(struct cosa_data *cosa, int number) * COSA status byte. I have moved the rx/tx/eot interrupt handling into * separate functions to make it more readable. These functions are inline, * so there should be no overhead of function call. - * + * * In the COSA bus-master mode, we need to tell the card the address of a * buffer. Unfortunately, COSA may be too slow for us, so we must busy-wait. * It's time to use the bottom half :-( */ -/* - * Transmit interrupt routine - called when COSA is willing to obtain +/* Transmit interrupt routine - called when COSA is willing to obtain * data from the OS. The most tricky part of the routine is selection * of channel we (OS) want to send packet for. For SRP we should probably * use the round-robin approach. The newer COSA firmwares have a simple @@ -1667,7 +1687,8 @@ static inline void tx_interrupt(struct cosa_data *cosa, int status) set_bit(TXBIT, &cosa->rxtx); if (!test_bit(IRQBIT, &cosa->rxtx)) { /* flow control, see the comment above */ - int i=0; + int i = 0; + if (!cosa->txbitmap) { pr_warn("%s: No channel wants data in TX IRQ. Expect DMA timeout.\n", cosa->name); @@ -1681,9 +1702,10 @@ static inline void tx_interrupt(struct cosa_data *cosa, int status) i++; if (cosa->txchan >= cosa->nchannels) cosa->txchan = 0; - if (!(cosa->txbitmap & (1<<cosa->txchan))) + if (!(cosa->txbitmap & (1 << cosa->txchan))) continue; - if (~status & (1 << (cosa->txchan+DRIVER_TXMAP_SHIFT))) + if (~status & + (1 << (cosa->txchan + DRIVER_TXMAP_SHIFT))) break; /* in second pass, accept first ready-to-TX channel */ if (i > cosa->nchannels) { @@ -1698,12 +1720,13 @@ static inline void tx_interrupt(struct cosa_data *cosa, int status) } cosa->txsize = cosa->chan[cosa->txchan].txsize; - if (cosa_dma_able(cosa->chan+cosa->txchan, - cosa->chan[cosa->txchan].txbuf, cosa->txsize)) { + if (cosa_dma_able(cosa->chan + cosa->txchan, + cosa->chan[cosa->txchan].txbuf, + cosa->txsize)) { cosa->txbuf = cosa->chan[cosa->txchan].txbuf; } else { memcpy(cosa->bouncebuf, cosa->chan[cosa->txchan].txbuf, - cosa->txsize); + cosa->txsize); cosa->txbuf = cosa->bouncebuf; } } @@ -1711,12 +1734,12 @@ static inline void tx_interrupt(struct cosa_data *cosa, int status) if (is_8bit(cosa)) { if (!test_bit(IRQBIT, &cosa->rxtx)) { cosa_putstatus(cosa, SR_TX_INT_ENA); - cosa_putdata8(cosa, ((cosa->txchan << 5) & 0xe0)| + cosa_putdata8(cosa, ((cosa->txchan << 5) & 0xe0) | ((cosa->txsize >> 8) & 0x1f)); #ifdef DEBUG_IO debug_status_out(cosa, SR_TX_INT_ENA); - debug_data_out(cosa, ((cosa->txchan << 5) & 0xe0)| - ((cosa->txsize >> 8) & 0x1f)); + debug_data_out(cosa, ((cosa->txchan << 5) & 0xe0) | + ((cosa->txsize >> 8) & 0x1f)); debug_data_in(cosa, cosa_getdata8(cosa)); #else cosa_getdata8(cosa); @@ -1727,20 +1750,20 @@ static inline void tx_interrupt(struct cosa_data *cosa, int status) } else { clear_bit(IRQBIT, &cosa->rxtx); cosa_putstatus(cosa, 0); - cosa_putdata8(cosa, cosa->txsize&0xff); + cosa_putdata8(cosa, cosa->txsize & 0xff); #ifdef DEBUG_IO debug_status_out(cosa, 0); - debug_data_out(cosa, cosa->txsize&0xff); + debug_data_out(cosa, cosa->txsize & 0xff); #endif } } else { cosa_putstatus(cosa, SR_TX_INT_ENA); - cosa_putdata16(cosa, ((cosa->txchan<<13) & 0xe000) + cosa_putdata16(cosa, ((cosa->txchan << 13) & 0xe000) | (cosa->txsize & 0x1fff)); #ifdef DEBUG_IO debug_status_out(cosa, SR_TX_INT_ENA); - debug_data_out(cosa, ((cosa->txchan<<13) & 0xe000) - | (cosa->txsize & 0x1fff)); + debug_data_out(cosa, ((cosa->txchan << 13) & 0xe000) | + (cosa->txsize & 0x1fff)); debug_data_in(cosa, cosa_getdata8(cosa)); debug_status_out(cosa, 0); #else @@ -1751,25 +1774,28 @@ static inline void tx_interrupt(struct cosa_data *cosa, int status) if (cosa->busmaster) { unsigned long addr = virt_to_bus(cosa->txbuf); - int count=0; + int count = 0; + pr_info("busmaster IRQ\n"); - while (!(cosa_getstatus(cosa)&SR_TX_RDY)) { + while (!(cosa_getstatus(cosa) & SR_TX_RDY)) { count++; udelay(10); - if (count > 1000) break; + if (count > 1000) + break; } pr_info("status %x\n", cosa_getstatus(cosa)); pr_info("ready after %d loops\n", count); - cosa_putdata16(cosa, (addr >> 16)&0xffff); + cosa_putdata16(cosa, (addr >> 16) & 0xffff); count = 0; - while (!(cosa_getstatus(cosa)&SR_TX_RDY)) { + while (!(cosa_getstatus(cosa) & SR_TX_RDY)) { count++; - if (count > 1000) break; + if (count > 1000) + break; udelay(10); } pr_info("ready after %d loops\n", count); - cosa_putdata16(cosa, addr &0xffff); + cosa_putdata16(cosa, addr & 0xffff); flags1 = claim_dma_lock(); set_dma_mode(cosa->dma, DMA_MODE_CASCADE); enable_dma(cosa->dma); @@ -1785,9 +1811,9 @@ static inline void tx_interrupt(struct cosa_data *cosa, int status) enable_dma(cosa->dma); release_dma_lock(flags1); } - cosa_putstatus(cosa, SR_TX_DMA_ENA|SR_USR_INT_ENA); + cosa_putstatus(cosa, SR_TX_DMA_ENA | SR_USR_INT_ENA); #ifdef DEBUG_IO - debug_status_out(cosa, SR_TX_DMA_ENA|SR_USR_INT_ENA); + debug_status_out(cosa, SR_TX_DMA_ENA | SR_USR_INT_ENA); #endif spin_unlock_irqrestore(&cosa->lock, flags); } @@ -1806,7 +1832,7 @@ static inline void rx_interrupt(struct cosa_data *cosa, int status) if (!test_bit(IRQBIT, &cosa->rxtx)) { set_bit(IRQBIT, &cosa->rxtx); put_driver_status_nolock(cosa); - cosa->rxsize = cosa_getdata8(cosa) <<8; + cosa->rxsize = cosa_getdata8(cosa) << 8; #ifdef DEBUG_IO debug_data_in(cosa, cosa->rxsize >> 8); #endif @@ -1859,20 +1885,20 @@ reject: /* Reject the packet */ disable_dma(cosa->dma); clear_dma_ff(cosa->dma); set_dma_mode(cosa->dma, DMA_MODE_READ); - if (cosa_dma_able(cosa->rxchan, cosa->rxbuf, cosa->rxsize & 0x1fff)) { + if (cosa_dma_able(cosa->rxchan, cosa->rxbuf, cosa->rxsize & 0x1fff)) set_dma_addr(cosa->dma, virt_to_bus(cosa->rxbuf)); - } else { + else set_dma_addr(cosa->dma, virt_to_bus(cosa->bouncebuf)); - } - set_dma_count(cosa->dma, (cosa->rxsize&0x1fff)); + + set_dma_count(cosa->dma, (cosa->rxsize & 0x1fff)); enable_dma(cosa->dma); release_dma_lock(flags); spin_lock_irqsave(&cosa->lock, flags); - cosa_putstatus(cosa, SR_RX_DMA_ENA|SR_USR_INT_ENA); + cosa_putstatus(cosa, SR_RX_DMA_ENA | SR_USR_INT_ENA); if (!is_8bit(cosa) && (status & SR_TX_RDY)) cosa_putdata8(cosa, DRIVER_RX_READY); #ifdef DEBUG_IO - debug_status_out(cosa, SR_RX_DMA_ENA|SR_USR_INT_ENA); + debug_status_out(cosa, SR_RX_DMA_ENA | SR_USR_INT_ENA); if (!is_8bit(cosa) && (status & SR_TX_RDY)) debug_data_cmd(cosa, DRIVER_RX_READY); #endif @@ -1882,13 +1908,15 @@ reject: /* Reject the packet */ static inline void eot_interrupt(struct cosa_data *cosa, int status) { unsigned long flags, flags1; + spin_lock_irqsave(&cosa->lock, flags); flags1 = claim_dma_lock(); disable_dma(cosa->dma); clear_dma_ff(cosa->dma); release_dma_lock(flags1); if (test_bit(TXBIT, &cosa->rxtx)) { - struct channel_data *chan = cosa->chan+cosa->txchan; + struct channel_data *chan = cosa->chan + cosa->txchan; + if (chan->tx_done) if (chan->tx_done(chan, cosa->txsize)) clear_bit(chan->num, &cosa->txbitmap); @@ -1896,9 +1924,10 @@ static inline void eot_interrupt(struct cosa_data *cosa, int status) #ifdef DEBUG_DATA { int i; + pr_info("cosa%dc%d: done rx(0x%x)", cosa->num, cosa->rxchan->num, cosa->rxsize); - for (i=0; i<cosa->rxsize; i++) + for (i = 0; i < cosa->rxsize; i++) pr_cont(" %02x", cosa->rxbuf[i]&0xff); pr_cont("\n"); } @@ -1914,8 +1943,7 @@ static inline void eot_interrupt(struct cosa_data *cosa, int status) } else { pr_notice("cosa%d: unexpected EOT interrupt\n", cosa->num); } - /* - * Clear the RXBIT, TXBIT and IRQBIT (the latest should be + /* Clear the RXBIT, TXBIT and IRQBIT (the latest should be * cleared anyway). We should do it as soon as possible * so that we can tell the COSA we are done and to give it a time * for recovery. @@ -1968,10 +1996,8 @@ again: return IRQ_HANDLED; } - /* ---------- I/O debugging routines ---------- */ -/* - * These routines can be used to monitor COSA/SRP I/O and to printk() +/* These routines can be used to monitor COSA/SRP I/O and to printk() * the data being transferred on the data and status I/O port in a * readable way. */ @@ -1980,6 +2006,7 @@ again: static void debug_status_in(struct cosa_data *cosa, int status) { char *s; + switch (status & SR_CMD_FROM_SRP_MASK) { case SR_UP_REQUEST: s = "RX_REQ"; diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c index 5de71e44fc5a..b3466e084e84 100644 --- a/drivers/net/wan/farsync.c +++ b/drivers/net/wan/farsync.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -/* - * FarSync WAN driver for Linux (2.6.x kernel version) +/* FarSync WAN driver for Linux (2.6.x kernel version) * * Actually sync driver for X.21, V.35 and V.24 on FarSync T-series cards * @@ -30,8 +29,7 @@ #include "farsync.h" -/* - * Module info +/* Module info */ MODULE_AUTHOR("R.J.Dunlop <bob.dunlop@farsite.co.uk>"); MODULE_DESCRIPTION("FarSync T-Series WAN driver. FarSite Communications Ltd."); @@ -49,20 +47,23 @@ MODULE_LICENSE("GPL"); /* Default parameters for the link */ #define FST_TX_QUEUE_LEN 100 /* At 8Mbps a longer queue length is - * useful */ + * useful + */ #define FST_TXQ_DEPTH 16 /* This one is for the buffering * of frames on the way down to the card * so that we can keep the card busy * and maximise throughput */ #define FST_HIGH_WATER_MARK 12 /* Point at which we flow control - * network layer */ + * network layer + */ #define FST_LOW_WATER_MARK 8 /* Point at which we remove flow - * control from network layer */ + * control from network layer + */ #define FST_MAX_MTU 8000 /* Huge but possible */ #define FST_DEF_MTU 1500 /* Common sane value */ -#define FST_TX_TIMEOUT (2*HZ) +#define FST_TX_TIMEOUT (2 * HZ) #ifdef ARPHRD_RAWHDLC #define ARPHRD_MYTYPE ARPHRD_RAWHDLC /* Raw frames */ @@ -70,13 +71,12 @@ MODULE_LICENSE("GPL"); #define ARPHRD_MYTYPE ARPHRD_HDLC /* Cisco-HDLC (keepalives etc) */ #endif -/* - * Modules parameters and associated variables +/* Modules parameters and associated variables */ static int fst_txq_low = FST_LOW_WATER_MARK; static int fst_txq_high = FST_HIGH_WATER_MARK; static int fst_max_reads = 7; -static int fst_excluded_cards = 0; +static int fst_excluded_cards; static int fst_excluded_list[FST_MAX_CARDS]; module_param(fst_txq_low, int, 0); @@ -105,9 +105,11 @@ module_param_array(fst_excluded_list, int, NULL, 0); #define FST_MEMSIZE 0x100000 /* Size of card memory (1Mb) */ #define SMC_BASE 0x00002000L /* Base offset of the shared memory window main - * configuration structure */ + * configuration structure + */ #define BFM_BASE 0x00010000L /* Base offset of the shared memory window DMA - * buffers */ + * buffers + */ #define LEN_TX_BUFFER 8192 /* Size of packet buffers */ #define LEN_RX_BUFFER 8192 @@ -377,8 +379,7 @@ struct fst_shared { #define INTCSR_9054 0x68 /* Interrupt control/status register */ /* 9054 DMA Registers */ -/* - * Note that we will be using DMA Channel 0 for copying rx data +/* Note that we will be using DMA Channel 0 for copying rx data * and Channel 1 for copying tx data */ #define DMAMODE0 0x80 @@ -421,7 +422,7 @@ struct buf_window { /* Per port (line or channel) information */ struct fst_port_info { - struct net_device *dev; /* Device struct - must be first */ + struct net_device *dev; /* Device struct - must be first */ struct fst_card_info *card; /* Card we're associated with */ int index; /* Port index on the card */ int hwif; /* Line hardware (lineInterface copy) */ @@ -431,8 +432,7 @@ struct fst_port_info { int txpos; /* Next Tx buffer to use */ int txipos; /* Next Tx buffer to check for free */ int start; /* Indication of start/stop to network */ - /* - * A sixteen entry transmit queue + /* A sixteen entry transmit queue */ int txqs; /* index to get next buffer to tx */ int txqe; /* index to queue next packet */ @@ -479,9 +479,7 @@ struct fst_card_info { #define dev_to_port(D) (dev_to_hdlc(D)->priv) #define port_to_dev(P) ((P)->dev) - -/* - * Shared memory window access macros +/* Shared memory window access macros * * We have a nice memory based structure above, which could be directly * mapped on i386 but might not work on other architectures unless we use @@ -491,16 +489,15 @@ struct fst_card_info { */ #define WIN_OFFSET(X) ((long)&(((struct fst_shared *)SMC_BASE)->X)) -#define FST_RDB(C,E) readb ((C)->mem + WIN_OFFSET(E)) -#define FST_RDW(C,E) readw ((C)->mem + WIN_OFFSET(E)) -#define FST_RDL(C,E) readl ((C)->mem + WIN_OFFSET(E)) +#define FST_RDB(C, E) (readb((C)->mem + WIN_OFFSET(E))) +#define FST_RDW(C, E) (readw((C)->mem + WIN_OFFSET(E))) +#define FST_RDL(C, E) (readl((C)->mem + WIN_OFFSET(E))) -#define FST_WRB(C,E,B) writeb ((B), (C)->mem + WIN_OFFSET(E)) -#define FST_WRW(C,E,W) writew ((W), (C)->mem + WIN_OFFSET(E)) -#define FST_WRL(C,E,L) writel ((L), (C)->mem + WIN_OFFSET(E)) +#define FST_WRB(C, E, B) (writeb((B), (C)->mem + WIN_OFFSET(E))) +#define FST_WRW(C, E, W) (writew((W), (C)->mem + WIN_OFFSET(E))) +#define FST_WRL(C, E, L) (writel((L), (C)->mem + WIN_OFFSET(E))) -/* - * Debug support +/* Debug support */ #if FST_DEBUG @@ -524,43 +521,41 @@ do { \ } while (0) #endif -/* - * PCI ID lookup table +/* PCI ID lookup table */ static const struct pci_device_id fst_pci_dev_id[] = { - {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T2P, PCI_ANY_ID, + {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T2P, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FST_TYPE_T2P}, - {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T4P, PCI_ANY_ID, + {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T4P, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FST_TYPE_T4P}, - {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T1U, PCI_ANY_ID, + {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T1U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FST_TYPE_T1U}, - {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T2U, PCI_ANY_ID, + {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T2U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FST_TYPE_T2U}, - {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T4U, PCI_ANY_ID, + {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T4U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FST_TYPE_T4U}, - {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_TE1, PCI_ANY_ID, + {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_TE1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FST_TYPE_TE1}, - {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_TE1C, PCI_ANY_ID, + {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_TE1C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FST_TYPE_TE1}, {0,} /* End */ }; MODULE_DEVICE_TABLE(pci, fst_pci_dev_id); -/* - * Device Driver Work Queues +/* Device Driver Work Queues * - * So that we don't spend too much time processing events in the - * Interrupt Service routine, we will declare a work queue per Card + * So that we don't spend too much time processing events in the + * Interrupt Service routine, we will declare a work queue per Card * and make the ISR schedule a task in the queue for later execution. * In the 2.4 Kernel we used to use the immediate queue for BH's - * Now that they are gone, tasklets seem to be much better than work + * Now that they are gone, tasklets seem to be much better than work * queues. */ @@ -578,18 +573,16 @@ static u64 fst_work_txq; static u64 fst_work_intq; static void -fst_q_work_item(u64 * queue, int card_index) +fst_q_work_item(u64 *queue, int card_index) { unsigned long flags; u64 mask; - /* - * Grab the queue exclusively + /* Grab the queue exclusively */ spin_lock_irqsave(&fst_work_q_lock, flags); - /* - * Making an entry in the queue is simply a matter of setting + /* Making an entry in the queue is simply a matter of setting * a bit for the card indicating that there is work to do in the * bottom half for the card. Note the limitation of 64 cards. * That ought to be enough @@ -606,8 +599,7 @@ fst_process_tx_work_q(struct tasklet_struct *unused) u64 work_txq; int i; - /* - * Grab the queue exclusively + /* Grab the queue exclusively */ dbg(DBG_TX, "fst_process_tx_work_q\n"); spin_lock_irqsave(&fst_work_q_lock, flags); @@ -615,12 +607,11 @@ fst_process_tx_work_q(struct tasklet_struct *unused) fst_work_txq = 0; spin_unlock_irqrestore(&fst_work_q_lock, flags); - /* - * Call the bottom half for each card with work waiting + /* Call the bottom half for each card with work waiting */ for (i = 0; i < FST_MAX_CARDS; i++) { if (work_txq & 0x01) { - if (fst_card_array[i] != NULL) { + if (fst_card_array[i]) { dbg(DBG_TX, "Calling tx bh for card %d\n", i); do_bottom_half_tx(fst_card_array[i]); } @@ -636,8 +627,7 @@ fst_process_int_work_q(struct tasklet_struct *unused) u64 work_intq; int i; - /* - * Grab the queue exclusively + /* Grab the queue exclusively */ dbg(DBG_INTR, "fst_process_int_work_q\n"); spin_lock_irqsave(&fst_work_q_lock, flags); @@ -645,12 +635,11 @@ fst_process_int_work_q(struct tasklet_struct *unused) fst_work_intq = 0; spin_unlock_irqrestore(&fst_work_q_lock, flags); - /* - * Call the bottom half for each card with work waiting + /* Call the bottom half for each card with work waiting */ for (i = 0; i < FST_MAX_CARDS; i++) { if (work_intq & 0x01) { - if (fst_card_array[i] != NULL) { + if (fst_card_array[i]) { dbg(DBG_INTR, "Calling rx & tx bh for card %d\n", i); do_bottom_half_rx(fst_card_array[i]); @@ -683,19 +672,16 @@ fst_cpureset(struct fst_card_info *card) dbg(DBG_ASS, "Error in reading interrupt line register\n"); } - /* - * Assert PLX software reset and Am186 hardware reset + /* Assert PLX software reset and Am186 hardware reset * and then deassert the PLX software reset but 186 still in reset */ outw(0x440f, card->pci_conf + CNTRL_9054 + 2); outw(0x040f, card->pci_conf + CNTRL_9054 + 2); - /* - * We are delaying here to allow the 9054 to reset itself + /* We are delaying here to allow the 9054 to reset itself */ usleep_range(10, 20); outw(0x240f, card->pci_conf + CNTRL_9054 + 2); - /* - * We are delaying here to allow the 9054 to reload its eeprom + /* We are delaying here to allow the 9054 to reload its eeprom */ usleep_range(10, 20); outw(0x040f, card->pci_conf + CNTRL_9054 + 2); @@ -720,19 +706,17 @@ static inline void fst_cpurelease(struct fst_card_info *card) { if (card->family == FST_FAMILY_TXU) { - /* - * Force posted writes to complete + /* Force posted writes to complete */ - (void) readb(card->mem); + (void)readb(card->mem); - /* - * Release LRESET DO = 1 + /* Release LRESET DO = 1 * Then release Local Hold, DO = 1 */ outw(0x040e, card->pci_conf + CNTRL_9054 + 2); outw(0x040f, card->pci_conf + CNTRL_9054 + 2); } else { - (void) readb(card->ctlmem); + (void)readb(card->ctlmem); } } @@ -742,7 +726,7 @@ static inline void fst_clear_intr(struct fst_card_info *card) { if (card->family == FST_FAMILY_TXU) { - (void) readb(card->ctlmem); + (void)readb(card->ctlmem); } else { /* Poke the appropriate PLX chip register (same as enabling interrupts) */ @@ -755,11 +739,10 @@ fst_clear_intr(struct fst_card_info *card) static inline void fst_enable_intr(struct fst_card_info *card) { - if (card->family == FST_FAMILY_TXU) { + if (card->family == FST_FAMILY_TXU) outl(0x0f0c0900, card->pci_conf + INTCSR_9054); - } else { + else outw(0x0543, card->pci_conf + INTCSR_9052); - } } /* Disable card interrupts @@ -767,11 +750,10 @@ fst_enable_intr(struct fst_card_info *card) static inline void fst_disable_intr(struct fst_card_info *card) { - if (card->family == FST_FAMILY_TXU) { + if (card->family == FST_FAMILY_TXU) outl(0x00000000, card->pci_conf + INTCSR_9054); - } else { + else outw(0x0000, card->pci_conf + INTCSR_9052); - } } /* Process the result of trying to pass a received frame up the stack @@ -782,8 +764,7 @@ fst_process_rx_status(int rx_status, char *name) switch (rx_status) { case NET_RX_SUCCESS: { - /* - * Nothing to do here + /* Nothing to do here */ break; } @@ -800,11 +781,10 @@ fst_process_rx_status(int rx_status, char *name) static inline void fst_init_dma(struct fst_card_info *card) { - /* - * This is only required for the PLX 9054 + /* This is only required for the PLX 9054 */ if (card->family == FST_FAMILY_TXU) { - pci_set_master(card->device); + pci_set_master(card->device); outl(0x00020441, card->pci_conf + DMAMODE0); outl(0x00020441, card->pci_conf + DMAMODE1); outl(0x0, card->pci_conf + DMATHR); @@ -819,8 +799,7 @@ fst_tx_dma_complete(struct fst_card_info *card, struct fst_port_info *port, { struct net_device *dev = port_to_dev(port); - /* - * Everything is now set, just tell the card to go + /* Everything is now set, just tell the card to go */ dbg(DBG_TX, "fst_tx_dma_complete\n"); FST_WRB(card, txDescrRing[port->index][txpos].bits, @@ -830,8 +809,7 @@ fst_tx_dma_complete(struct fst_card_info *card, struct fst_port_info *port, netif_trans_update(dev); } -/* - * Mark it for our own raw sockets interface +/* Mark it for our own raw sockets interface */ static __be16 farsync_type_trans(struct sk_buff *skb, struct net_device *dev) { @@ -874,55 +852,47 @@ fst_rx_dma_complete(struct fst_card_info *card, struct fst_port_info *port, dev->stats.rx_dropped++; } -/* - * Receive a frame through the DMA +/* Receive a frame through the DMA */ static inline void fst_rx_dma(struct fst_card_info *card, dma_addr_t dma, u32 mem, int len) { - /* - * This routine will setup the DMA and start it + /* This routine will setup the DMA and start it */ dbg(DBG_RX, "In fst_rx_dma %x %x %d\n", (u32)dma, mem, len); - if (card->dmarx_in_progress) { + if (card->dmarx_in_progress) dbg(DBG_ASS, "In fst_rx_dma while dma in progress\n"); - } outl(dma, card->pci_conf + DMAPADR0); /* Copy to here */ outl(mem, card->pci_conf + DMALADR0); /* from here */ outl(len, card->pci_conf + DMASIZ0); /* for this length */ outl(0x00000000c, card->pci_conf + DMADPR0); /* In this direction */ - /* - * We use the dmarx_in_progress flag to flag the channel as busy + /* We use the dmarx_in_progress flag to flag the channel as busy */ card->dmarx_in_progress = 1; outb(0x03, card->pci_conf + DMACSR0); /* Start the transfer */ } -/* - * Send a frame through the DMA +/* Send a frame through the DMA */ static inline void fst_tx_dma(struct fst_card_info *card, dma_addr_t dma, u32 mem, int len) { - /* - * This routine will setup the DMA and start it. + /* This routine will setup the DMA and start it. */ dbg(DBG_TX, "In fst_tx_dma %x %x %d\n", (u32)dma, mem, len); - if (card->dmatx_in_progress) { + if (card->dmatx_in_progress) dbg(DBG_ASS, "In fst_tx_dma while dma in progress\n"); - } outl(dma, card->pci_conf + DMAPADR1); /* Copy from here */ outl(mem, card->pci_conf + DMALADR1); /* to here */ outl(len, card->pci_conf + DMASIZ1); /* for this length */ outl(0x000000004, card->pci_conf + DMADPR1); /* In this direction */ - /* - * We use the dmatx_in_progress to flag the channel as busy + /* We use the dmatx_in_progress to flag the channel as busy */ card->dmatx_in_progress = 1; outb(0x03, card->pci_conf + DMACSR1); /* Start the transfer */ @@ -958,12 +928,11 @@ fst_issue_cmd(struct fst_port_info *port, unsigned short cmd) mbval = FST_RDW(card, portMailbox[port->index][0]); } - if (safety > 0) { + if (safety > 0) dbg(DBG_CMD, "Mailbox clear after %d jiffies\n", safety); - } - if (mbval == NAK) { + + if (mbval == NAK) dbg(DBG_CMD, "issue_cmd: previous command was NAK'd\n"); - } FST_WRW(card, portMailbox[port->index][0], cmd); @@ -998,8 +967,7 @@ fst_op_lower(struct fst_port_info *port, unsigned int outputs) fst_issue_cmd(port, SETV24O); } -/* - * Setup port Rx buffers +/* Setup port Rx buffers */ static void fst_rx_config(struct fst_port_info *port) @@ -1016,8 +984,8 @@ fst_rx_config(struct fst_port_info *port) for (i = 0; i < NUM_RX_BUFFER; i++) { offset = BUF_OFFSET(rxBuffer[pi][i][0]); - FST_WRW(card, rxDescrRing[pi][i].ladr, (u16) offset); - FST_WRB(card, rxDescrRing[pi][i].hadr, (u8) (offset >> 16)); + FST_WRW(card, rxDescrRing[pi][i].ladr, (u16)offset); + FST_WRB(card, rxDescrRing[pi][i].hadr, (u8)(offset >> 16)); FST_WRW(card, rxDescrRing[pi][i].bcnt, cnv_bcnt(LEN_RX_BUFFER)); FST_WRW(card, rxDescrRing[pi][i].mcnt, LEN_RX_BUFFER); FST_WRB(card, rxDescrRing[pi][i].bits, DMA_OWN); @@ -1026,8 +994,7 @@ fst_rx_config(struct fst_port_info *port) spin_unlock_irqrestore(&card->card_lock, flags); } -/* - * Setup port Tx buffers +/* Setup port Tx buffers */ static void fst_tx_config(struct fst_port_info *port) @@ -1044,8 +1011,8 @@ fst_tx_config(struct fst_port_info *port) for (i = 0; i < NUM_TX_BUFFER; i++) { offset = BUF_OFFSET(txBuffer[pi][i][0]); - FST_WRW(card, txDescrRing[pi][i].ladr, (u16) offset); - FST_WRB(card, txDescrRing[pi][i].hadr, (u8) (offset >> 16)); + FST_WRW(card, txDescrRing[pi][i].ladr, (u16)offset); + FST_WRB(card, txDescrRing[pi][i].hadr, (u8)(offset >> 16)); FST_WRW(card, txDescrRing[pi][i].bcnt, 0); FST_WRB(card, txDescrRing[pi][i].bits, 0); } @@ -1069,16 +1036,14 @@ fst_intr_te1_alarm(struct fst_card_info *card, struct fst_port_info *port) ais = FST_RDB(card, suStatus.alarmIndicationSignal); if (los) { - /* - * Lost the link + /* Lost the link */ if (netif_carrier_ok(port_to_dev(port))) { dbg(DBG_INTR, "Net carrier off\n"); netif_carrier_off(port_to_dev(port)); } } else { - /* - * Link available + /* Link available */ if (!netif_carrier_ok(port_to_dev(port))) { dbg(DBG_INTR, "Net carrier on\n"); @@ -1110,7 +1075,7 @@ fst_intr_ctlchg(struct fst_card_info *card, struct fst_port_info *port) signals = FST_RDL(card, v24DebouncedSts[port->index]); - if (signals & (((port->hwif == X21) || (port->hwif == X21D)) + if (signals & ((port->hwif == X21 || port->hwif == X21D) ? IPSTS_INDICATE : IPSTS_DCD)) { if (!netif_carrier_ok(port_to_dev(port))) { dbg(DBG_INTR, "DCD active\n"); @@ -1132,8 +1097,7 @@ fst_log_rx_error(struct fst_card_info *card, struct fst_port_info *port, { struct net_device *dev = port_to_dev(port); - /* - * Increment the appropriate error counter + /* Increment the appropriate error counter */ dev->stats.rx_errors++; if (dmabits & RX_OFLO) { @@ -1168,15 +1132,14 @@ fst_recover_rx_error(struct fst_card_info *card, struct fst_port_info *port, int pi; pi = port->index; - /* - * Discard buffer descriptors until we see the start of the + /* Discard buffer descriptors until we see the start of the * next frame. Note that for long frames this could be in - * a subsequent interrupt. + * a subsequent interrupt. */ i = 0; while ((dmabits & (DMA_OWN | RX_STP)) == 0) { FST_WRB(card, rxDescrRing[pi][rxp].bits, DMA_OWN); - rxp = (rxp+1) % NUM_RX_BUFFER; + rxp = (rxp + 1) % NUM_RX_BUFFER; if (++i > NUM_RX_BUFFER) { dbg(DBG_ASS, "intr_rx: Discarding more bufs" " than we have\n"); @@ -1190,11 +1153,9 @@ fst_recover_rx_error(struct fst_card_info *card, struct fst_port_info *port, /* Discard the terminal buffer */ if (!(dmabits & DMA_OWN)) { FST_WRB(card, rxDescrRing[pi][rxp].bits, DMA_OWN); - rxp = (rxp+1) % NUM_RX_BUFFER; + rxp = (rxp + 1) % NUM_RX_BUFFER; } port->rxpos = rxp; - return; - } /* Rx complete interrupt @@ -1219,17 +1180,15 @@ fst_intr_rx(struct fst_card_info *card, struct fst_port_info *port) pi, rxp); return; } - if (card->dmarx_in_progress) { + if (card->dmarx_in_progress) return; - } /* Get buffer length */ len = FST_RDW(card, rxDescrRing[pi][rxp].mcnt); /* Discard the CRC */ len -= 2; if (len == 0) { - /* - * This seems to happen on the TE1 interface sometimes + /* This seems to happen on the TE1 interface sometimes * so throw the frame away and log the event. */ pr_err("Frame received with 0 length. Card %d Port %d\n", @@ -1237,7 +1196,7 @@ fst_intr_rx(struct fst_card_info *card, struct fst_port_info *port) /* Return descriptor to card */ FST_WRB(card, rxDescrRing[pi][rxp].bits, DMA_OWN); - rxp = (rxp+1) % NUM_RX_BUFFER; + rxp = (rxp + 1) % NUM_RX_BUFFER; port->rxpos = rxp; return; } @@ -1254,7 +1213,8 @@ fst_intr_rx(struct fst_card_info *card, struct fst_port_info *port) } /* Allocate SKB */ - if ((skb = dev_alloc_skb(len)) == NULL) { + skb = dev_alloc_skb(len); + if (!skb) { dbg(DBG_RX, "intr_rx: can't allocate buffer\n"); dev->stats.rx_dropped++; @@ -1262,18 +1222,17 @@ fst_intr_rx(struct fst_card_info *card, struct fst_port_info *port) /* Return descriptor to card */ FST_WRB(card, rxDescrRing[pi][rxp].bits, DMA_OWN); - rxp = (rxp+1) % NUM_RX_BUFFER; + rxp = (rxp + 1) % NUM_RX_BUFFER; port->rxpos = rxp; return; } - /* - * We know the length we need to receive, len. + /* We know the length we need to receive, len. * It's not worth using the DMA for reads of less than * FST_MIN_DMA_LEN */ - if ((len < FST_MIN_DMA_LEN) || (card->family == FST_FAMILY_TXP)) { + if (len < FST_MIN_DMA_LEN || card->family == FST_FAMILY_TXP) { memcpy_fromio(skb_put(skb, len), card->mem + BUF_OFFSET(rxBuffer[pi][rxp][0]), len); @@ -1307,12 +1266,11 @@ fst_intr_rx(struct fst_card_info *card, struct fst_port_info *port) dbg(DBG_ASS, "About to increment rxpos by more than 1\n"); dbg(DBG_ASS, "rxp = %d rxpos = %d\n", rxp, port->rxpos); } - rxp = (rxp+1) % NUM_RX_BUFFER; + rxp = (rxp + 1) % NUM_RX_BUFFER; port->rxpos = rxp; } -/* - * The bottom halfs to the ISR +/* The bottom half to the ISR * */ @@ -1326,8 +1284,7 @@ do_bottom_half_tx(struct fst_card_info *card) unsigned long flags; struct net_device *dev; - /* - * Find a free buffer for the transmit + /* Find a free buffer for the transmit * Step through each port on this card */ @@ -1340,39 +1297,36 @@ do_bottom_half_tx(struct fst_card_info *card) while (!(FST_RDB(card, txDescrRing[pi][port->txpos].bits) & DMA_OWN) && !(card->dmatx_in_progress)) { - /* - * There doesn't seem to be a txdone event per-se + /* There doesn't seem to be a txdone event per-se * We seem to have to deduce it, by checking the DMA_OWN * bit on the next buffer we think we can use */ spin_lock_irqsave(&card->card_lock, flags); - if ((txq_length = port->txqe - port->txqs) < 0) { - /* - * This is the case where one has wrapped and the + txq_length = port->txqe - port->txqs; + if (txq_length < 0) { + /* This is the case where one has wrapped and the * maths gives us a negative number */ txq_length = txq_length + FST_TXQ_DEPTH; } spin_unlock_irqrestore(&card->card_lock, flags); if (txq_length > 0) { - /* - * There is something to send + /* There is something to send */ spin_lock_irqsave(&card->card_lock, flags); skb = port->txq[port->txqs]; port->txqs++; - if (port->txqs == FST_TXQ_DEPTH) { + if (port->txqs == FST_TXQ_DEPTH) port->txqs = 0; - } + spin_unlock_irqrestore(&card->card_lock, flags); - /* - * copy the data and set the required indicators on the + /* copy the data and set the required indicators on the * card. */ FST_WRW(card, txDescrRing[pi][port->txpos].bcnt, cnv_bcnt(skb->len)); - if ((skb->len < FST_MIN_DMA_LEN) || - (card->family == FST_FAMILY_TXP)) { + if (skb->len < FST_MIN_DMA_LEN || + card->family == FST_FAMILY_TXP) { /* Enqueue the packet with normal io */ memcpy_toio(card->mem + BUF_OFFSET(txBuffer[pi] @@ -1401,8 +1355,7 @@ do_bottom_half_tx(struct fst_card_info *card) } if (++port->txpos >= NUM_TX_BUFFER) port->txpos = 0; - /* - * If we have flow control on, can we now release it? + /* If we have flow control on, can we now release it? */ if (port->start) { if (txq_length < fst_txq_low) { @@ -1413,8 +1366,7 @@ do_bottom_half_tx(struct fst_card_info *card) } dev_kfree_skb(skb); } else { - /* - * Nothing to send so break out of the while loop + /* Nothing to send so break out of the while loop */ break; } @@ -1438,8 +1390,7 @@ do_bottom_half_rx(struct fst_card_info *card) while (!(FST_RDB(card, rxDescrRing[pi][port->rxpos].bits) & DMA_OWN) && !(card->dmarx_in_progress)) { if (rx_count > fst_max_reads) { - /* - * Don't spend forever in receive processing + /* Don't spend forever in receive processing * Schedule another event */ fst_q_work_item(&fst_work_intq, card->card_no); @@ -1452,8 +1403,7 @@ do_bottom_half_rx(struct fst_card_info *card) } } -/* - * The interrupt service routine +/* The interrupt service routine * Dev_id is our fst_card_info pointer */ static irqreturn_t @@ -1468,8 +1418,7 @@ fst_intr(int dummy, void *dev_id) unsigned int do_card_interrupt; unsigned int int_retry_count; - /* - * Check to see if the interrupt was for this card + /* Check to see if the interrupt was for this card * return if not * Note that the call to clear the interrupt is important */ @@ -1478,10 +1427,9 @@ fst_intr(int dummy, void *dev_id) pr_err("Interrupt received for card %d in a non running state (%d)\n", card->card_no, card->state); - /* - * It is possible to really be running, i.e. we have re-loaded + /* It is possible to really be running, i.e. we have re-loaded * a running card - * Clear and reprime the interrupt source + * Clear and reprime the interrupt source */ fst_clear_intr(card); return IRQ_HANDLED; @@ -1490,8 +1438,7 @@ fst_intr(int dummy, void *dev_id) /* Clear and reprime the interrupt source */ fst_clear_intr(card); - /* - * Is the interrupt for this card (handshake == 1) + /* Is the interrupt for this card (handshake == 1) */ do_card_interrupt = 0; if (FST_RDB(card, interruptHandshake) == 1) { @@ -1500,13 +1447,11 @@ fst_intr(int dummy, void *dev_id) FST_WRB(card, interruptHandshake, 0xEE); } if (card->family == FST_FAMILY_TXU) { - /* - * Is it a DMA Interrupt + /* Is it a DMA Interrupt */ dma_intcsr = inl(card->pci_conf + INTCSR_9054); if (dma_intcsr & 0x00200000) { - /* - * DMA Channel 0 (Rx transfer complete) + /* DMA Channel 0 (Rx transfer complete) */ dbg(DBG_RX, "DMA Rx xfer complete\n"); outb(0x8, card->pci_conf + DMACSR0); @@ -1517,8 +1462,7 @@ fst_intr(int dummy, void *dev_id) do_card_interrupt += FST_RX_DMA_INT; } if (dma_intcsr & 0x00400000) { - /* - * DMA Channel 1 (Tx transfer complete) + /* DMA Channel 1 (Tx transfer complete) */ dbg(DBG_TX, "DMA Tx xfer complete\n"); outb(0x8, card->pci_conf + DMACSR1); @@ -1529,8 +1473,7 @@ fst_intr(int dummy, void *dev_id) } } - /* - * Have we been missing Interrupts + /* Have we been missing Interrupts */ int_retry_count = FST_RDL(card, interruptRetryCount); if (int_retry_count) { @@ -1539,9 +1482,8 @@ fst_intr(int dummy, void *dev_id) FST_WRL(card, interruptRetryCount, 0); } - if (!do_card_interrupt) { + if (!do_card_interrupt) return IRQ_HANDLED; - } /* Scehdule the bottom half of the ISR */ fst_q_work_item(&fst_work_intq, card->card_no); @@ -1611,7 +1553,7 @@ fst_intr(int dummy, void *dev_id) rdidx = 0; } FST_WRB(card, interruptEvent.rdindex, rdidx); - return IRQ_HANDLED; + return IRQ_HANDLED; } /* Check that the shared memory configuration is one that we can handle @@ -1635,7 +1577,8 @@ check_started_ok(struct fst_card_info *card) return; } /* Firmware status flag, 0x00 = initialising, 0x01 = OK, 0xFF = fail */ - if ((i = FST_RDB(card, taskStatus)) == 0x01) { + i = FST_RDB(card, taskStatus); + if (i == 0x01) { card->state = FST_RUNNING; } else if (i == 0xFF) { pr_err("Firmware initialisation failed. Card halted\n"); @@ -1665,8 +1608,8 @@ set_conf_from_info(struct fst_card_info *card, struct fst_port_info *port, int err; unsigned char my_framing; - /* Set things according to the user set valid flags - * Several of the old options have been invalidated/replaced by the + /* Set things according to the user set valid flags + * Several of the old options have been invalidated/replaced by the * generic hdlc package. */ err = 0; @@ -1740,9 +1683,8 @@ set_conf_from_info(struct fst_card_info *card, struct fst_port_info *port, #endif } #if FST_DEBUG - if (info->valid & FSTVAL_DEBUG) { + if (info->valid & FSTVAL_DEBUG) fst_debug_mask = info->debug; - } #endif return err; @@ -1754,7 +1696,7 @@ gather_conf_info(struct fst_card_info *card, struct fst_port_info *port, { int i; - memset(info, 0, sizeof (struct fstioc_info)); + memset(info, 0, sizeof(struct fstioc_info)); i = port->index; info->kernelVersion = LINUX_VERSION_CODE; @@ -1787,27 +1729,23 @@ gather_conf_info(struct fst_card_info *card, struct fst_port_info *port, info->cardMode = FST_RDW(card, cardMode); info->smcFirmwareVersion = FST_RDL(card, smcFirmwareVersion); - /* - * The T2U can report cable presence for both A or B - * in bits 0 and 1 of cableStatus. See which port we are and + /* The T2U can report cable presence for both A or B + * in bits 0 and 1 of cableStatus. See which port we are and * do the mapping. */ if (card->family == FST_FAMILY_TXU) { if (port->index == 0) { - /* - * Port A + /* Port A */ info->cableStatus = info->cableStatus & 1; } else { - /* - * Port B + /* Port B */ info->cableStatus = info->cableStatus >> 1; info->cableStatus = info->cableStatus & 1; } } - /* - * Some additional bits if we are TE1 + /* Some additional bits if we are TE1 */ if (card->type == FST_TYPE_TE1) { info->lineSpeed = FST_RDL(card, suConfig.dataRate); @@ -1851,14 +1789,12 @@ fst_set_iface(struct fst_card_info *card, struct fst_port_info *port, sync_serial_settings sync; int i; - if (ifr->ifr_settings.size != sizeof (sync)) { + if (ifr->ifr_settings.size != sizeof(sync)) return -ENOMEM; - } if (copy_from_user - (&sync, ifr->ifr_settings.ifs_ifsu.sync, sizeof (sync))) { + (&sync, ifr->ifr_settings.ifs_ifsu.sync, sizeof(sync))) return -EFAULT; - } if (sync.loopback) return -EINVAL; @@ -1951,12 +1887,11 @@ fst_get_iface(struct fst_card_info *card, struct fst_port_info *port, ifr->ifr_settings.type = IF_IFACE_X21; break; } - if (ifr->ifr_settings.size == 0) { + if (ifr->ifr_settings.size == 0) return 0; /* only type requested */ - } - if (ifr->ifr_settings.size < sizeof (sync)) { + + if (ifr->ifr_settings.size < sizeof(sync)) return -ENOMEM; - } i = port->index; memset(&sync, 0, sizeof(sync)); @@ -1966,11 +1901,10 @@ fst_get_iface(struct fst_card_info *card, struct fst_port_info *port, INTCLK ? CLOCK_INT : CLOCK_EXT; sync.loopback = 0; - if (copy_to_user(ifr->ifr_settings.ifs_ifsu.sync, &sync, sizeof (sync))) { + if (copy_to_user(ifr->ifr_settings.ifs_ifsu.sync, &sync, sizeof(sync))) return -EFAULT; - } - ifr->ifr_settings.size = sizeof (sync); + ifr->ifr_settings.size = sizeof(sync); return 0; } @@ -2008,21 +1942,19 @@ fst_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /* First copy in the header with the length and offset of data * to write */ - if (ifr->ifr_data == NULL) { + if (!ifr->ifr_data) return -EINVAL; - } + if (copy_from_user(&wrthdr, ifr->ifr_data, - sizeof (struct fstioc_write))) { + sizeof(struct fstioc_write))) return -EFAULT; - } /* Sanity check the parameters. We don't support partial writes * when going over the top */ if (wrthdr.size > FST_MEMSIZE || wrthdr.offset > FST_MEMSIZE || - wrthdr.size + wrthdr.offset > FST_MEMSIZE) { + wrthdr.size + wrthdr.offset > FST_MEMSIZE) return -ENXIO; - } /* Now copy the data to the card. */ @@ -2037,9 +1969,9 @@ fst_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /* Writes to the memory of a card in the reset state constitute * a download */ - if (card->state == FST_RESET) { + if (card->state == FST_RESET) card->state = FST_DOWNLOAD; - } + return 0; case FSTGETCONF: @@ -2059,21 +1991,18 @@ fst_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) } } - if (ifr->ifr_data == NULL) { + if (!ifr->ifr_data) return -EINVAL; - } gather_conf_info(card, port, &info); - if (copy_to_user(ifr->ifr_data, &info, sizeof (info))) { + if (copy_to_user(ifr->ifr_data, &info, sizeof(info))) return -EFAULT; - } + return 0; case FSTSETCONF: - - /* - * Most of the settings have been moved to the generic ioctls + /* Most of the settings have been moved to the generic ioctls * this just covers debug and board ident now */ @@ -2082,9 +2011,8 @@ fst_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) card->card_no, card->state); return -EIO; } - if (copy_from_user(&info, ifr->ifr_data, sizeof (info))) { + if (copy_from_user(&info, ifr->ifr_data, sizeof(info))) return -EFAULT; - } return set_conf_from_info(card, port, &info); @@ -2150,7 +2078,7 @@ fst_openport(struct fst_port_info *port) port->run = 1; signals = FST_RDL(port->card, v24DebouncedSts[port->index]); - if (signals & (((port->hwif == X21) || (port->hwif == X21D)) + if (signals & ((port->hwif == X21 || port->hwif == X21D) ? IPSTS_INDICATE : IPSTS_DCD)) netif_carrier_on(port_to_dev(port)); else @@ -2159,7 +2087,6 @@ fst_openport(struct fst_port_info *port) port->txqe = 0; port->txqs = 0; } - } static void @@ -2185,7 +2112,7 @@ fst_open(struct net_device *dev) port = dev_to_port(dev); if (!try_module_get(THIS_MODULE)) - return -EBUSY; + return -EBUSY; if (port->mode != FST_RAW) { err = hdlc_open(dev); @@ -2220,9 +2147,9 @@ fst_close(struct net_device *dev) netif_stop_queue(dev); fst_closeport(dev_to_port(dev)); - if (port->mode != FST_RAW) { + if (port->mode != FST_RAW) hdlc_close(dev); - } + module_put(THIS_MODULE); return 0; } @@ -2230,8 +2157,7 @@ fst_close(struct net_device *dev) static int fst_attach(struct net_device *dev, unsigned short encoding, unsigned short parity) { - /* - * Setting currently fixed in FarSync card so we check and forget + /* Setting currently fixed in FarSync card so we check and forget */ if (encoding != ENCODING_NRZ || parity != PARITY_CRC16_PR1_CCITT) return -EINVAL; @@ -2289,23 +2215,21 @@ fst_start_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } - /* - * We are always going to queue the packet + /* We are always going to queue the packet * so that the bottom half is the only place we tx from * Check there is room in the port txq */ spin_lock_irqsave(&card->card_lock, flags); - if ((txq_length = port->txqe - port->txqs) < 0) { - /* - * This is the case where the next free has wrapped but the + txq_length = port->txqe - port->txqs; + if (txq_length < 0) { + /* This is the case where the next free has wrapped but the * last used hasn't */ txq_length = txq_length + FST_TXQ_DEPTH; } spin_unlock_irqrestore(&card->card_lock, flags); if (txq_length > fst_txq_high) { - /* - * We have got enough buffers in the pipeline. Ask the network + /* We have got enough buffers in the pipeline. Ask the network * layer to stop sending frames down */ netif_stop_queue(dev); @@ -2313,8 +2237,7 @@ fst_start_xmit(struct sk_buff *skb, struct net_device *dev) } if (txq_length == FST_TXQ_DEPTH - 1) { - /* - * This shouldn't have happened but such is life + /* This shouldn't have happened but such is life */ dev_kfree_skb(skb); dev->stats.tx_errors++; @@ -2323,8 +2246,7 @@ fst_start_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } - /* - * queue the buffer + /* queue the buffer */ spin_lock_irqsave(&card->card_lock, flags); port->txq[port->txqe] = skb; @@ -2340,8 +2262,7 @@ fst_start_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } -/* - * Card setup having checked hardware resources. +/* Card setup having checked hardware resources. * Should be pretty bizarre if we get an error here (kernel memory * exhaustion is one possibility). If we do see a problem we report it * via a printk and leave the corresponding interface and all that follow @@ -2371,7 +2292,7 @@ fst_init_card(struct fst_card_info *card) err = register_hdlc_device(card->ports[i].dev); if (err < 0) { pr_err("Cannot register HDLC device for port %d (errno %d)\n", - i, -err); + i, -err); while (i--) unregister_hdlc_device(card->ports[i].dev); return err; @@ -2393,14 +2314,13 @@ static const struct net_device_ops fst_ops = { .ndo_tx_timeout = fst_tx_timeout, }; -/* - * Initialise card when detected. +/* Initialise card when detected. * Returns 0 to indicate success, or errno otherwise. */ static int fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent) { - static int no_of_cards_added = 0; + static int no_of_cards_added; struct fst_card_info *card; int err = 0; int i; @@ -2411,17 +2331,15 @@ fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent) #if FST_DEBUG dbg(DBG_ASS, "The value of debug mask is %x\n", fst_debug_mask); #endif - /* - * We are going to be clever and allow certain cards not to be + /* We are going to be clever and allow certain cards not to be * configured. An exclude list can be provided in /etc/modules.conf */ if (fst_excluded_cards != 0) { - /* - * There are cards to exclude + /* There are cards to exclude * */ for (i = 0; i < fst_excluded_cards; i++) { - if ((pdev->devfn) >> 3 == fst_excluded_list[i]) { + if (pdev->devfn >> 3 == fst_excluded_list[i]) { pr_info("FarSync PCI device %d not assigned\n", (pdev->devfn) >> 3); return -EBUSY; @@ -2431,16 +2349,18 @@ fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent) /* Allocate driver private data */ card = kzalloc(sizeof(struct fst_card_info), GFP_KERNEL); - if (card == NULL) + if (!card) return -ENOMEM; /* Try to enable the device */ - if ((err = pci_enable_device(pdev)) != 0) { + err = pci_enable_device(pdev); + if (err) { pr_err("Failed to enable card. Err %d\n", -err); goto enable_fail; } - if ((err = pci_request_regions(pdev, "FarSync")) !=0) { + err = pci_request_regions(pdev, "FarSync"); + if (err) { pr_err("Failed to allocate regions. Err %d\n", -err); goto regions_fail; } @@ -2449,12 +2369,14 @@ fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent) card->pci_conf = pci_resource_start(pdev, 1); card->phys_mem = pci_resource_start(pdev, 2); card->phys_ctlmem = pci_resource_start(pdev, 3); - if ((card->mem = ioremap(card->phys_mem, FST_MEMSIZE)) == NULL) { + card->mem = ioremap(card->phys_mem, FST_MEMSIZE); + if (!card->mem) { pr_err("Physical memory remap failed\n"); err = -ENODEV; goto ioremap_physmem_fail; } - if ((card->ctlmem = ioremap(card->phys_ctlmem, 0x10)) == NULL) { + card->ctlmem = ioremap(card->phys_ctlmem, 0x10); + if (!card->ctlmem) { pr_err("Control memory remap failed\n"); err = -ENODEV; goto ioremap_ctlmem_fail; @@ -2474,19 +2396,20 @@ fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent) card->family = ((ent->driver_data == FST_TYPE_T2P) || (ent->driver_data == FST_TYPE_T4P)) ? FST_FAMILY_TXP : FST_FAMILY_TXU; - if ((ent->driver_data == FST_TYPE_T1U) || - (ent->driver_data == FST_TYPE_TE1)) + if (ent->driver_data == FST_TYPE_T1U || + ent->driver_data == FST_TYPE_TE1) card->nports = 1; else card->nports = ((ent->driver_data == FST_TYPE_T2P) || (ent->driver_data == FST_TYPE_T2U)) ? 2 : 4; card->state = FST_UNINIT; - spin_lock_init ( &card->card_lock ); + spin_lock_init(&card->card_lock); - for ( i = 0 ; i < card->nports ; i++ ) { + for (i = 0; i < card->nports; i++) { struct net_device *dev = alloc_hdlcdev(&card->ports[i]); hdlc_device *hdlc; + if (!dev) { while (i--) free_netdev(card->ports[i].dev); @@ -2495,29 +2418,29 @@ fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent) goto hdlcdev_fail; } card->ports[i].dev = dev; - card->ports[i].card = card; - card->ports[i].index = i; - card->ports[i].run = 0; + card->ports[i].card = card; + card->ports[i].index = i; + card->ports[i].run = 0; hdlc = dev_to_hdlc(dev); - /* Fill in the net device info */ + /* Fill in the net device info */ /* Since this is a PCI setup this is purely * informational. Give them the buffer addresses * and basic card I/O. */ - dev->mem_start = card->phys_mem - + BUF_OFFSET ( txBuffer[i][0][0]); - dev->mem_end = card->phys_mem - + BUF_OFFSET ( txBuffer[i][NUM_TX_BUFFER - 1][LEN_RX_BUFFER - 1]); - dev->base_addr = card->pci_conf; - dev->irq = card->irq; + dev->mem_start = card->phys_mem + + BUF_OFFSET(txBuffer[i][0][0]); + dev->mem_end = card->phys_mem + + BUF_OFFSET(txBuffer[i][NUM_TX_BUFFER - 1][LEN_RX_BUFFER - 1]); + dev->base_addr = card->pci_conf; + dev->irq = card->irq; dev->netdev_ops = &fst_ops; dev->tx_queue_len = FST_TX_QUEUE_LEN; dev->watchdog_timeo = FST_TX_TIMEOUT; - hdlc->attach = fst_attach; - hdlc->xmit = fst_start_xmit; + hdlc->attach = fst_attach; + hdlc->xmit = fst_start_xmit; } card->device = pdev; @@ -2549,13 +2472,12 @@ fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (err) goto init_card_fail; if (card->family == FST_FAMILY_TXU) { - /* - * Allocate a dma buffer for transmit and receives + /* Allocate a dma buffer for transmit and receives */ card->rx_dma_handle_host = dma_alloc_coherent(&card->device->dev, FST_MAX_MTU, &card->rx_dma_handle_card, GFP_KERNEL); - if (card->rx_dma_handle_host == NULL) { + if (!card->rx_dma_handle_host) { pr_err("Could not allocate rx dma buffer\n"); err = -ENOMEM; goto rx_dma_fail; @@ -2563,7 +2485,7 @@ fst_add_one(struct pci_dev *pdev, const struct pci_device_id *ent) card->tx_dma_handle_host = dma_alloc_coherent(&card->device->dev, FST_MAX_MTU, &card->tx_dma_handle_card, GFP_KERNEL); - if (card->tx_dma_handle_host == NULL) { + if (!card->tx_dma_handle_host) { pr_err("Could not allocate tx dma buffer\n"); err = -ENOMEM; goto tx_dma_fail; @@ -2598,8 +2520,7 @@ enable_fail: return err; } -/* - * Cleanup and close down a card +/* Cleanup and close down a card */ static void fst_remove_one(struct pci_dev *pdev) @@ -2611,6 +2532,7 @@ fst_remove_one(struct pci_dev *pdev) for (i = 0; i < card->nports; i++) { struct net_device *dev = port_to_dev(&card->ports[i]); + unregister_hdlc_device(dev); } @@ -2621,8 +2543,7 @@ fst_remove_one(struct pci_dev *pdev) iounmap(card->mem); pci_release_regions(pdev); if (card->family == FST_FAMILY_TXU) { - /* - * Free dma buffers + /* Free dma buffers */ dma_free_coherent(&card->device->dev, FST_MAX_MTU, card->rx_dma_handle_host, diff --git a/drivers/net/wan/fsl_ucc_hdlc.c b/drivers/net/wan/fsl_ucc_hdlc.c index 7eac6a3e1cde..39f05fabbfa4 100644 --- a/drivers/net/wan/fsl_ucc_hdlc.c +++ b/drivers/net/wan/fsl_ucc_hdlc.c @@ -1171,9 +1171,8 @@ static int ucc_hdlc_probe(struct platform_device *pdev) ut_info->uf_info.irq = irq_of_parse_and_map(np, 0); uhdlc_priv = kzalloc(sizeof(*uhdlc_priv), GFP_KERNEL); - if (!uhdlc_priv) { + if (!uhdlc_priv) return -ENOMEM; - } dev_set_drvdata(&pdev->dev, uhdlc_priv); uhdlc_priv->dev = &pdev->dev; diff --git a/drivers/net/wan/hd64570.c b/drivers/net/wan/hd64570.c index 058e48182838..0d19e39fec86 100644 --- a/drivers/net/wan/hd64570.c +++ b/drivers/net/wan/hd64570.c @@ -47,7 +47,6 @@ #define SCA_INTR_DMAC_RX(node) (node ? 0x20 : 0x02) #define SCA_INTR_DMAC_TX(node) (node ? 0x40 : 0x04) - static inline struct net_device *port_to_dev(port_t *port) { return port->dev; @@ -59,12 +58,18 @@ static inline int sca_intr_status(card_t *card) u8 isr0 = sca_in(ISR0, card); u8 isr1 = sca_in(ISR1, card); - if (isr1 & 0x03) result |= SCA_INTR_DMAC_RX(0); - if (isr1 & 0x0C) result |= SCA_INTR_DMAC_TX(0); - if (isr1 & 0x30) result |= SCA_INTR_DMAC_RX(1); - if (isr1 & 0xC0) result |= SCA_INTR_DMAC_TX(1); - if (isr0 & 0x0F) result |= SCA_INTR_MSCI(0); - if (isr0 & 0xF0) result |= SCA_INTR_MSCI(1); + if (isr1 & 0x03) + result |= SCA_INTR_DMAC_RX(0); + if (isr1 & 0x0C) + result |= SCA_INTR_DMAC_TX(0); + if (isr1 & 0x30) + result |= SCA_INTR_DMAC_RX(1); + if (isr1 & 0xC0) + result |= SCA_INTR_DMAC_TX(1); + if (isr0 & 0x0F) + result |= SCA_INTR_MSCI(0); + if (isr0 & 0xF0) + result |= SCA_INTR_MSCI(1); if (!(result & SCA_INTR_DMAC_TX(0))) if (sca_in(DSR_TX(0), card) & DSR_EOM) @@ -76,7 +81,7 @@ static inline int sca_intr_status(card_t *card) return result; } -static inline port_t* dev_to_port(struct net_device *dev) +static inline port_t *dev_to_port(struct net_device *dev) { return dev_to_hdlc(dev)->priv; } @@ -87,7 +92,6 @@ static inline u16 next_desc(port_t *port, u16 desc, int transmit) : port_to_card(port)->rx_ring_buffers); } - static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit) { u16 rx_buffs = port_to_card(port)->rx_ring_buffers; @@ -98,14 +102,12 @@ static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit) transmit * rx_buffs + desc; } - static inline u16 desc_offset(port_t *port, u16 desc, int transmit) { /* Descriptor offset always fits in 16 bits */ return desc_abs_number(port, desc, transmit) * sizeof(pkt_desc); } - static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc, int transmit) { @@ -118,14 +120,12 @@ static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc, #endif } - static inline u32 buffer_offset(port_t *port, u16 desc, int transmit) { return port_to_card(port)->buff_offset + desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU; } - static inline void sca_set_carrier(port_t *port) { if (!(sca_in(get_msci(port) + ST3, port_to_card(port)) & ST3_DCD)) { @@ -143,7 +143,6 @@ static inline void sca_set_carrier(port_t *port) } } - static void sca_init_port(port_t *port) { card_t *card = port_to_card(port); @@ -213,13 +212,12 @@ static void sca_init_port(port_t *port) sca_set_carrier(port); } - #ifdef NEED_SCA_MSCI_INTR /* MSCI interrupt service */ static inline void sca_msci_intr(port_t *port) { u16 msci = get_msci(port); - card_t* card = port_to_card(port); + card_t *card = port_to_card(port); u8 stat = sca_in(msci + ST1, card); /* read MSCI ST1 status */ /* Reset MSCI TX underrun and CDCD status bit */ @@ -236,7 +234,6 @@ static inline void sca_msci_intr(port_t *port) } #endif - static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, u16 rxin) { @@ -265,8 +262,9 @@ static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, memcpy_fromio(skb->data, winbase(card) + buff, maxlen); openwin(card, page + 1); memcpy_fromio(skb->data + maxlen, winbase(card), len - maxlen); - } else + } else { memcpy_fromio(skb->data, winbase(card) + buff, len); + } #ifndef PAGE0_ALWAYS_MAPPED openwin(card, 0); /* select pkt_desc table page back */ @@ -282,7 +280,6 @@ static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, netif_rx(skb); } - /* Receive DMA interrupt service */ static inline void sca_rx_intr(port_t *port) { @@ -304,7 +301,7 @@ static inline void sca_rx_intr(port_t *port) pkt_desc __iomem *desc; u32 cda = sca_inw(dmac + CDAL, card); - if ((cda >= desc_off) && (cda < desc_off + sizeof(pkt_desc))) + if (cda >= desc_off && (cda < desc_off + sizeof(pkt_desc))) break; /* No frame received */ desc = desc_address(port, port->rxin, 0); @@ -322,8 +319,9 @@ static inline void sca_rx_intr(port_t *port) dev->stats.rx_crc_errors++; if (stat & ST_RX_EOM) port->rxpart = 0; /* received last fragment */ - } else + } else { sca_rx(card, port, desc, port->rxin); + } /* Set new error descriptor address */ sca_outw(desc_off, dmac + EDAL, card); @@ -334,13 +332,12 @@ static inline void sca_rx_intr(port_t *port) sca_out(DSR_DE, DSR_RX(phy_node(port)), card); } - /* Transmit DMA interrupt service */ static inline void sca_tx_intr(port_t *port) { struct net_device *dev = port_to_dev(port); u16 dmac = get_dmac_tx(port); - card_t* card = port_to_card(port); + card_t *card = port_to_card(port); u8 stat; spin_lock(&port->lock); @@ -356,7 +353,8 @@ static inline void sca_tx_intr(port_t *port) u32 desc_off = desc_offset(port, port->txlast, 1); u32 cda = sca_inw(dmac + CDAL, card); - if ((cda >= desc_off) && (cda < desc_off + sizeof(pkt_desc))) + + if (cda >= desc_off && (cda < desc_off + sizeof(pkt_desc))) break; /* Transmitter is/will_be sending this frame */ desc = desc_address(port, port->txlast, 1); @@ -370,8 +368,7 @@ static inline void sca_tx_intr(port_t *port) spin_unlock(&port->lock); } - -static irqreturn_t sca_intr(int irq, void* dev_id) +static irqreturn_t sca_intr(int irq, void *dev_id) { card_t *card = dev_id; int i; @@ -379,10 +376,11 @@ static irqreturn_t sca_intr(int irq, void* dev_id) int handled = 0; u8 page = sca_get_page(card); - while((stat = sca_intr_status(card)) != 0) { + while ((stat = sca_intr_status(card)) != 0) { handled = 1; for (i = 0; i < 2; i++) { port_t *port = get_port(card, i); + if (port) { if (stat & SCA_INTR_MSCI(i)) sca_msci_intr(port); @@ -400,15 +398,13 @@ static irqreturn_t sca_intr(int irq, void* dev_id) return IRQ_RETVAL(handled); } - static void sca_set_port(port_t *port) { - card_t* card = port_to_card(port); + card_t *card = port_to_card(port); u16 msci = get_msci(port); u8 md2 = sca_in(msci + MD2, card); unsigned int tmc, br = 10, brv = 1024; - if (port->settings.clock_rate > 0) { /* Try lower br for better accuracy*/ do { @@ -417,14 +413,15 @@ static void sca_set_port(port_t *port) /* Baud Rate = CLOCK_BASE / TMC / 2^BR */ tmc = CLOCK_BASE / brv / port->settings.clock_rate; - }while (br > 1 && tmc <= 128); + } while (br > 1 && tmc <= 128); if (tmc < 1) { tmc = 1; br = 0; /* For baud=CLOCK_BASE we use tmc=1 br=0 */ brv = 1; - } else if (tmc > 255) + } else if (tmc > 255) { tmc = 256; /* tmc=0 means 256 - low baud rates */ + } port->settings.clock_rate = CLOCK_BASE / brv / tmc; } else { @@ -450,34 +447,50 @@ static void sca_set_port(port_t *port) md2 &= ~MD2_LOOPBACK; sca_out(md2, msci + MD2, card); - } - static void sca_open(struct net_device *dev) { port_t *port = dev_to_port(dev); - card_t* card = port_to_card(port); + card_t *card = port_to_card(port); u16 msci = get_msci(port); u8 md0, md2; - switch(port->encoding) { - case ENCODING_NRZ: md2 = MD2_NRZ; break; - case ENCODING_NRZI: md2 = MD2_NRZI; break; - case ENCODING_FM_MARK: md2 = MD2_FM_MARK; break; - case ENCODING_FM_SPACE: md2 = MD2_FM_SPACE; break; - default: md2 = MD2_MANCHESTER; + switch (port->encoding) { + case ENCODING_NRZ: + md2 = MD2_NRZ; + break; + case ENCODING_NRZI: + md2 = MD2_NRZI; + break; + case ENCODING_FM_MARK: + md2 = MD2_FM_MARK; + break; + case ENCODING_FM_SPACE: + md2 = MD2_FM_SPACE; + break; + default: + md2 = MD2_MANCHESTER; } if (port->settings.loopback) md2 |= MD2_LOOPBACK; - switch(port->parity) { - case PARITY_CRC16_PR0: md0 = MD0_HDLC | MD0_CRC_16_0; break; - case PARITY_CRC16_PR1: md0 = MD0_HDLC | MD0_CRC_16; break; - case PARITY_CRC16_PR0_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU_0; break; - case PARITY_CRC16_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU; break; - default: md0 = MD0_HDLC | MD0_CRC_NONE; + switch (port->parity) { + case PARITY_CRC16_PR0: + md0 = MD0_HDLC | MD0_CRC_16_0; + break; + case PARITY_CRC16_PR1: + md0 = MD0_HDLC | MD0_CRC_16; + break; + case PARITY_CRC16_PR0_CCITT: + md0 = MD0_HDLC | MD0_CRC_ITU_0; + break; + case PARITY_CRC16_PR1_CCITT: + md0 = MD0_HDLC | MD0_CRC_ITU; + break; + default: + md0 = MD0_HDLC | MD0_CRC_NONE; } sca_out(CMD_RESET, msci + CMD, card); @@ -494,9 +507,9 @@ static void sca_open(struct net_device *dev) sca_out(0x14, msci + TRC1, card); /* +1=TXRDY/DMA deactiv condition */ /* We're using the following interrupts: - - TXINT (DMAC completed all transmisions, underrun or DCD change) - - all DMA interrupts -*/ + * - TXINT (DMAC completed all transmisions, underrun or DCD change) + * - all DMA interrupts + */ sca_set_carrier(port); /* MSCI TX INT and RX INT A IRQ enable */ @@ -517,11 +530,10 @@ static void sca_open(struct net_device *dev) netif_start_queue(dev); } - static void sca_close(struct net_device *dev) { port_t *port = dev_to_port(dev); - card_t* card = port_to_card(port); + card_t *card = port_to_card(port); /* reset channel */ sca_out(CMD_RESET, get_msci(port) + CMD, port_to_card(port)); @@ -535,7 +547,6 @@ static void sca_close(struct net_device *dev) netif_stop_queue(dev); } - static int sca_attach(struct net_device *dev, unsigned short encoding, unsigned short parity) { @@ -558,7 +569,6 @@ static int sca_attach(struct net_device *dev, unsigned short encoding, return 0; } - #ifdef DEBUG_RINGS static void sca_dump_rings(struct net_device *dev) { @@ -613,7 +623,6 @@ static void sca_dump_rings(struct net_device *dev) } #endif /* DEBUG_RINGS */ - static netdev_tx_t sca_xmit(struct sk_buff *skb, struct net_device *dev) { port_t *port = dev_to_port(dev); @@ -645,8 +654,9 @@ static netdev_tx_t sca_xmit(struct sk_buff *skb, struct net_device *dev) memcpy_toio(winbase(card) + buff, skb->data, maxlen); openwin(card, page + 1); memcpy_toio(winbase(card), skb->data + maxlen, len - maxlen); - } else + } else { memcpy_toio(winbase(card) + buff, skb->data, len); + } #ifndef PAGE0_ALWAYS_MAPPED openwin(card, 0); /* select pkt_desc table page back */ @@ -670,7 +680,6 @@ static netdev_tx_t sca_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } - #ifdef NEED_DETECT_RAM static u32 sca_detect_ram(card_t *card, u8 __iomem *rambase, u32 ramsize) { @@ -699,7 +708,6 @@ static u32 sca_detect_ram(card_t *card, u8 __iomem *rambase, u32 ramsize) } #endif /* NEED_DETECT_RAM */ - static void sca_init(card_t *card, int wait_states) { sca_out(wait_states, WCRL, card); /* Wait Control */ diff --git a/drivers/net/wan/hd64572.c b/drivers/net/wan/hd64572.c index 9f60e3969bf8..b89b03a6aba7 100644 --- a/drivers/net/wan/hd64572.c +++ b/drivers/net/wan/hd64572.c @@ -41,20 +41,20 @@ #define NAPI_WEIGHT 16 -#define get_msci(port) (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET) -#define get_dmac_rx(port) (port->chan ? DMAC1RX_OFFSET : DMAC0RX_OFFSET) -#define get_dmac_tx(port) (port->chan ? DMAC1TX_OFFSET : DMAC0TX_OFFSET) +#define get_msci(port) ((port)->chan ? MSCI1_OFFSET : MSCI0_OFFSET) +#define get_dmac_rx(port) ((port)->chan ? DMAC1RX_OFFSET : DMAC0RX_OFFSET) +#define get_dmac_tx(port) ((port)->chan ? DMAC1TX_OFFSET : DMAC0TX_OFFSET) -#define sca_in(reg, card) readb(card->scabase + (reg)) -#define sca_out(value, reg, card) writeb(value, card->scabase + (reg)) -#define sca_inw(reg, card) readw(card->scabase + (reg)) -#define sca_outw(value, reg, card) writew(value, card->scabase + (reg)) -#define sca_inl(reg, card) readl(card->scabase + (reg)) -#define sca_outl(value, reg, card) writel(value, card->scabase + (reg)) +#define sca_in(reg, card) readb((card)->scabase + (reg)) +#define sca_out(value, reg, card) writeb(value, (card)->scabase + (reg)) +#define sca_inw(reg, card) readw((card)->scabase + (reg)) +#define sca_outw(value, reg, card) writew(value, (card)->scabase + (reg)) +#define sca_inl(reg, card) readl((card)->scabase + (reg)) +#define sca_outl(value, reg, card) writel(value, (card)->scabase + (reg)) static int sca_poll(struct napi_struct *napi, int budget); -static inline port_t* dev_to_port(struct net_device *dev) +static inline port_t *dev_to_port(struct net_device *dev) { return dev_to_hdlc(dev)->priv; } @@ -81,14 +81,12 @@ static inline u16 desc_abs_number(port_t *port, u16 desc, int transmit) return port->chan * (rx_buffs + tx_buffs) + transmit * rx_buffs + desc; } - static inline u16 desc_offset(port_t *port, u16 desc, int transmit) { /* Descriptor offset always fits in 16 bits */ return desc_abs_number(port, desc, transmit) * sizeof(pkt_desc); } - static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc, int transmit) { @@ -96,14 +94,12 @@ static inline pkt_desc __iomem *desc_address(port_t *port, u16 desc, desc_offset(port, desc, transmit)); } - static inline u32 buffer_offset(port_t *port, u16 desc, int transmit) { return port->card->buff_offset + desc_abs_number(port, desc, transmit) * (u32)HDLC_MAX_MRU; } - static inline void sca_set_carrier(port_t *port) { if (!(sca_in(get_msci(port) + ST3, port->card) & ST3_DCD)) { @@ -121,7 +117,6 @@ static inline void sca_set_carrier(port_t *port) } } - static void sca_init_port(port_t *port) { card_t *card = port->card; @@ -181,12 +176,11 @@ static void sca_init_port(port_t *port) netif_napi_add(port->netdev, &port->napi, sca_poll, NAPI_WEIGHT); } - /* MSCI interrupt service */ static inline void sca_msci_intr(port_t *port) { u16 msci = get_msci(port); - card_t* card = port->card; + card_t *card = port->card; if (sca_in(msci + ST1, card) & ST1_CDCD) { /* Reset MSCI CDCD status bit */ @@ -195,7 +189,6 @@ static inline void sca_msci_intr(port_t *port) } } - static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, u16 rxin) { @@ -225,7 +218,6 @@ static inline void sca_rx(card_t *card, port_t *port, pkt_desc __iomem *desc, netif_receive_skb(skb); } - /* Receive DMA service */ static inline int sca_rx_done(port_t *port, int budget) { @@ -281,12 +273,11 @@ static inline int sca_rx_done(port_t *port, int budget) return received; } - /* Transmit DMA service */ static inline void sca_tx_done(port_t *port) { struct net_device *dev = port->netdev; - card_t* card = port->card; + card_t *card = port->card; u8 stat; unsigned count = 0; @@ -321,7 +312,6 @@ static inline void sca_tx_done(port_t *port) spin_unlock(&port->lock); } - static int sca_poll(struct napi_struct *napi, int budget) { port_t *port = container_of(napi, port_t, napi); @@ -363,15 +353,13 @@ static irqreturn_t sca_intr(int irq, void *dev_id) return IRQ_RETVAL(handled); } - static void sca_set_port(port_t *port) { - card_t* card = port->card; + card_t *card = port->card; u16 msci = get_msci(port); u8 md2 = sca_in(msci + MD2, card); unsigned int tmc, br = 10, brv = 1024; - if (port->settings.clock_rate > 0) { /* Try lower br for better accuracy*/ do { @@ -380,14 +368,15 @@ static void sca_set_port(port_t *port) /* Baud Rate = CLOCK_BASE / TMC / 2^BR */ tmc = CLOCK_BASE / brv / port->settings.clock_rate; - }while (br > 1 && tmc <= 128); + } while (br > 1 && tmc <= 128); if (tmc < 1) { tmc = 1; br = 0; /* For baud=CLOCK_BASE we use tmc=1 br=0 */ brv = 1; - } else if (tmc > 255) + } else if (tmc > 255) { tmc = 256; /* tmc=0 means 256 - low baud rates */ + } port->settings.clock_rate = CLOCK_BASE / brv / tmc; } else { @@ -414,34 +403,50 @@ static void sca_set_port(port_t *port) md2 &= ~MD2_LOOPBACK; sca_out(md2, msci + MD2, card); - } - static void sca_open(struct net_device *dev) { port_t *port = dev_to_port(dev); - card_t* card = port->card; + card_t *card = port->card; u16 msci = get_msci(port); u8 md0, md2; - switch(port->encoding) { - case ENCODING_NRZ: md2 = MD2_NRZ; break; - case ENCODING_NRZI: md2 = MD2_NRZI; break; - case ENCODING_FM_MARK: md2 = MD2_FM_MARK; break; - case ENCODING_FM_SPACE: md2 = MD2_FM_SPACE; break; - default: md2 = MD2_MANCHESTER; + switch (port->encoding) { + case ENCODING_NRZ: + md2 = MD2_NRZ; + break; + case ENCODING_NRZI: + md2 = MD2_NRZI; + break; + case ENCODING_FM_MARK: + md2 = MD2_FM_MARK; + break; + case ENCODING_FM_SPACE: + md2 = MD2_FM_SPACE; + break; + default: + md2 = MD2_MANCHESTER; } if (port->settings.loopback) md2 |= MD2_LOOPBACK; - switch(port->parity) { - case PARITY_CRC16_PR0: md0 = MD0_HDLC | MD0_CRC_16_0; break; - case PARITY_CRC16_PR1: md0 = MD0_HDLC | MD0_CRC_16; break; - case PARITY_CRC32_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU32; break; - case PARITY_CRC16_PR1_CCITT: md0 = MD0_HDLC | MD0_CRC_ITU; break; - default: md0 = MD0_HDLC | MD0_CRC_NONE; + switch (port->parity) { + case PARITY_CRC16_PR0: + md0 = MD0_HDLC | MD0_CRC_16_0; + break; + case PARITY_CRC16_PR1: + md0 = MD0_HDLC | MD0_CRC_16; + break; + case PARITY_CRC32_PR1_CCITT: + md0 = MD0_HDLC | MD0_CRC_ITU32; + break; + case PARITY_CRC16_PR1_CCITT: + md0 = MD0_HDLC | MD0_CRC_ITU; + break; + default: + md0 = MD0_HDLC | MD0_CRC_NONE; } sca_out(CMD_RESET, msci + CMD, card); @@ -476,7 +481,6 @@ static void sca_open(struct net_device *dev) netif_start_queue(dev); } - static void sca_close(struct net_device *dev) { port_t *port = dev_to_port(dev); @@ -488,7 +492,6 @@ static void sca_close(struct net_device *dev) netif_stop_queue(dev); } - static int sca_attach(struct net_device *dev, unsigned short encoding, unsigned short parity) { @@ -511,7 +514,6 @@ static int sca_attach(struct net_device *dev, unsigned short encoding, return 0; } - #ifdef DEBUG_RINGS static void sca_dump_rings(struct net_device *dev) { @@ -558,7 +560,6 @@ static void sca_dump_rings(struct net_device *dev) } #endif /* DEBUG_RINGS */ - static netdev_tx_t sca_xmit(struct sk_buff *skb, struct net_device *dev) { port_t *port = dev_to_port(dev); @@ -600,7 +601,6 @@ static netdev_tx_t sca_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } - static u32 sca_detect_ram(card_t *card, u8 __iomem *rambase, u32 ramsize) { /* Round RAM size to 32 bits, fill from end to start */ @@ -619,7 +619,6 @@ static u32 sca_detect_ram(card_t *card, u8 __iomem *rambase, u32 ramsize) return i; } - static void sca_init(card_t *card, int wait_states) { sca_out(wait_states, WCRL, card); /* Wait Control */ diff --git a/drivers/net/wan/hdlc.c b/drivers/net/wan/hdlc.c index 1bdd3df0867a..dd6312b69861 100644 --- a/drivers/net/wan/hdlc.c +++ b/drivers/net/wan/hdlc.c @@ -36,8 +36,7 @@ #include <linux/slab.h> #include <net/net_namespace.h> - -static const char* version = "HDLC support module revision 1.22"; +static const char *version = "HDLC support module revision 1.22"; #undef DEBUG_LINK @@ -74,25 +73,24 @@ netdev_tx_t hdlc_start_xmit(struct sk_buff *skb, struct net_device *dev) return hdlc->xmit(skb, dev); /* call hardware driver directly */ } +EXPORT_SYMBOL(hdlc_start_xmit); static inline void hdlc_proto_start(struct net_device *dev) { hdlc_device *hdlc = dev_to_hdlc(dev); + if (hdlc->proto->start) hdlc->proto->start(dev); } - - static inline void hdlc_proto_stop(struct net_device *dev) { hdlc_device *hdlc = dev_to_hdlc(dev); + if (hdlc->proto->stop) hdlc->proto->stop(dev); } - - static int hdlc_device_event(struct notifier_block *this, unsigned long event, void *ptr) { @@ -141,8 +139,6 @@ carrier_exit: return NOTIFY_DONE; } - - /* Must be called by hardware driver when HDLC device is being opened */ int hdlc_open(struct net_device *dev) { @@ -152,11 +148,12 @@ int hdlc_open(struct net_device *dev) hdlc->carrier, hdlc->open); #endif - if (hdlc->proto == NULL) + if (!hdlc->proto) return -ENOSYS; /* no protocol attached */ if (hdlc->proto->open) { int result = hdlc->proto->open(dev); + if (result) return result; } @@ -166,16 +163,16 @@ int hdlc_open(struct net_device *dev) if (hdlc->carrier) { netdev_info(dev, "Carrier detected\n"); hdlc_proto_start(dev); - } else + } else { netdev_info(dev, "No carrier\n"); + } hdlc->open = 1; spin_unlock_irq(&hdlc->state_lock); return 0; } - - +EXPORT_SYMBOL(hdlc_open); /* Must be called by hardware driver when HDLC device is being closed */ void hdlc_close(struct net_device *dev) @@ -197,8 +194,7 @@ void hdlc_close(struct net_device *dev) if (hdlc->proto->close) hdlc->proto->close(dev); } - - +EXPORT_SYMBOL(hdlc_close); int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { @@ -217,12 +213,14 @@ int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /* Not handled by currently attached protocol (if any) */ while (proto) { - if ((result = proto->ioctl(dev, ifr)) != -EINVAL) + result = proto->ioctl(dev, ifr); + if (result != -EINVAL) return result; proto = proto->next; } return -EINVAL; } +EXPORT_SYMBOL(hdlc_ioctl); static const struct header_ops hdlc_null_ops; @@ -256,12 +254,14 @@ static void hdlc_setup(struct net_device *dev) struct net_device *alloc_hdlcdev(void *priv) { struct net_device *dev; + dev = alloc_netdev(sizeof(struct hdlc_device), "hdlc%d", NET_NAME_UNKNOWN, hdlc_setup); if (dev) dev_to_hdlc(dev)->priv = priv; return dev; } +EXPORT_SYMBOL(alloc_hdlcdev); void unregister_hdlc_device(struct net_device *dev) { @@ -270,8 +270,7 @@ void unregister_hdlc_device(struct net_device *dev) unregister_netdevice(dev); rtnl_unlock(); } - - +EXPORT_SYMBOL(unregister_hdlc_device); int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto, size_t size) @@ -287,7 +286,7 @@ int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto, if (size) { dev_to_hdlc(dev)->state = kmalloc(size, GFP_KERNEL); - if (dev_to_hdlc(dev)->state == NULL) { + if (!dev_to_hdlc(dev)->state) { module_put(proto->module); return -ENOBUFS; } @@ -296,7 +295,7 @@ int attach_hdlc_protocol(struct net_device *dev, struct hdlc_proto *proto, return 0; } - +EXPORT_SYMBOL(attach_hdlc_protocol); int detach_hdlc_protocol(struct net_device *dev) { @@ -322,7 +321,7 @@ int detach_hdlc_protocol(struct net_device *dev) return 0; } - +EXPORT_SYMBOL(detach_hdlc_protocol); void register_hdlc_protocol(struct hdlc_proto *proto) { @@ -331,7 +330,7 @@ void register_hdlc_protocol(struct hdlc_proto *proto) first_proto = proto; rtnl_unlock(); } - +EXPORT_SYMBOL(register_hdlc_protocol); void unregister_hdlc_protocol(struct hdlc_proto *proto) { @@ -346,54 +345,38 @@ void unregister_hdlc_protocol(struct hdlc_proto *proto) *p = proto->next; rtnl_unlock(); } - - +EXPORT_SYMBOL(unregister_hdlc_protocol); MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>"); MODULE_DESCRIPTION("HDLC support module"); MODULE_LICENSE("GPL v2"); -EXPORT_SYMBOL(hdlc_start_xmit); -EXPORT_SYMBOL(hdlc_open); -EXPORT_SYMBOL(hdlc_close); -EXPORT_SYMBOL(hdlc_ioctl); -EXPORT_SYMBOL(alloc_hdlcdev); -EXPORT_SYMBOL(unregister_hdlc_device); -EXPORT_SYMBOL(register_hdlc_protocol); -EXPORT_SYMBOL(unregister_hdlc_protocol); -EXPORT_SYMBOL(attach_hdlc_protocol); -EXPORT_SYMBOL(detach_hdlc_protocol); - static struct packet_type hdlc_packet_type __read_mostly = { .type = cpu_to_be16(ETH_P_HDLC), .func = hdlc_rcv, }; - static struct notifier_block hdlc_notifier = { .notifier_call = hdlc_device_event, }; - static int __init hdlc_module_init(void) { int result; pr_info("%s\n", version); - if ((result = register_netdevice_notifier(&hdlc_notifier)) != 0) + result = register_netdevice_notifier(&hdlc_notifier); + if (result) return result; dev_add_pack(&hdlc_packet_type); return 0; } - - static void __exit hdlc_module_exit(void) { dev_remove_pack(&hdlc_packet_type); unregister_netdevice_notifier(&hdlc_notifier); } - module_init(hdlc_module_init); module_exit(hdlc_module_exit); diff --git a/drivers/net/wan/hdlc_cisco.c b/drivers/net/wan/hdlc_cisco.c index cb5898f7d68c..349ca18088e8 100644 --- a/drivers/net/wan/hdlc_cisco.c +++ b/drivers/net/wan/hdlc_cisco.c @@ -28,13 +28,11 @@ #define CISCO_ADDR_REPLY 1 /* Cisco address reply */ #define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */ - struct hdlc_header { u8 address; u8 control; __be16 protocol; -}__packed; - +} __packed; struct cisco_packet { __be32 type; /* code */ @@ -42,11 +40,10 @@ struct cisco_packet { __be32 par2; __be16 rel; /* reliability */ __be32 time; -}__packed; +} __packed; #define CISCO_PACKET_LEN 18 #define CISCO_BIG_PACKET_LEN 20 - struct cisco_state { cisco_proto settings; @@ -59,16 +56,13 @@ struct cisco_state { u32 rxseq; /* RX sequence number */ }; - static int cisco_ioctl(struct net_device *dev, struct ifreq *ifr); - -static inline struct cisco_state* state(hdlc_device *hdlc) +static inline struct cisco_state *state(hdlc_device *hdlc) { return (struct cisco_state *)hdlc->state; } - static int cisco_hard_header(struct sk_buff *skb, struct net_device *dev, u16 type, const void *daddr, const void *saddr, unsigned int len) @@ -79,7 +73,7 @@ static int cisco_hard_header(struct sk_buff *skb, struct net_device *dev, #endif skb_push(skb, sizeof(struct hdlc_header)); - data = (struct hdlc_header*)skb->data; + data = (struct hdlc_header *)skb->data; if (type == CISCO_KEEPALIVE) data->address = CISCO_MULTICAST; else @@ -90,8 +84,6 @@ static int cisco_hard_header(struct sk_buff *skb, struct net_device *dev, return sizeof(struct hdlc_header); } - - static void cisco_keepalive_send(struct net_device *dev, u32 type, __be32 par1, __be32 par2) { @@ -100,13 +92,12 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type, skb = dev_alloc_skb(sizeof(struct hdlc_header) + sizeof(struct cisco_packet)); - if (!skb) { - netdev_warn(dev, "Memory squeeze on %s()\n", __func__); + if (!skb) return; - } + skb_reserve(skb, 4); cisco_hard_header(skb, dev, CISCO_KEEPALIVE, NULL, NULL, 0); - data = (struct cisco_packet*)(skb->data + 4); + data = (struct cisco_packet *)(skb->data + 4); data->type = htonl(type); data->par1 = par1; @@ -124,11 +115,9 @@ static void cisco_keepalive_send(struct net_device *dev, u32 type, dev_queue_xmit(skb); } - - static __be16 cisco_type_trans(struct sk_buff *skb, struct net_device *dev) { - struct hdlc_header *data = (struct hdlc_header*)skb->data; + struct hdlc_header *data = (struct hdlc_header *)skb->data; if (skb->len < sizeof(struct hdlc_header)) return cpu_to_be16(ETH_P_HDLC); @@ -148,13 +137,12 @@ static __be16 cisco_type_trans(struct sk_buff *skb, struct net_device *dev) } } - static int cisco_rx(struct sk_buff *skb) { struct net_device *dev = skb->dev; hdlc_device *hdlc = dev_to_hdlc(dev); struct cisco_state *st = state(hdlc); - struct hdlc_header *data = (struct hdlc_header*)skb->data; + struct hdlc_header *data = (struct hdlc_header *)skb->data; struct cisco_packet *cisco_data; struct in_device *in_dev; __be32 addr, mask; @@ -183,10 +171,10 @@ static int cisco_rx(struct sk_buff *skb) goto rx_error; } - cisco_data = (struct cisco_packet*)(skb->data + sizeof + cisco_data = (struct cisco_packet *)(skb->data + sizeof (struct hdlc_header)); - switch (ntohl (cisco_data->type)) { + switch (ntohl(cisco_data->type)) { case CISCO_ADDR_REQ: /* Stolen from syncppp.c :-) */ rcu_read_lock(); in_dev = __in_dev_get_rcu(dev); @@ -226,6 +214,7 @@ static int cisco_rx(struct sk_buff *skb) st->last_poll = jiffies; if (!st->up) { u32 sec, min, hrs, days; + sec = ntohl(cisco_data->time) / 1000; min = sec / 60; sec -= min * 60; hrs = min / 60; min -= hrs * 60; @@ -253,8 +242,6 @@ rx_error: return NET_RX_DROP; } - - static void cisco_timer(struct timer_list *t) { struct cisco_state *st = from_timer(st, t, timer); @@ -276,8 +263,6 @@ static void cisco_timer(struct timer_list *t) add_timer(&st->timer); } - - static void cisco_start(struct net_device *dev) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -294,8 +279,6 @@ static void cisco_start(struct net_device *dev) add_timer(&st->timer); } - - static void cisco_stop(struct net_device *dev) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -310,7 +293,6 @@ static void cisco_stop(struct net_device *dev) spin_unlock_irqrestore(&st->lock, flags); } - static struct hdlc_proto proto = { .start = cisco_start, .stop = cisco_stop, @@ -359,7 +341,8 @@ static int cisco_ioctl(struct net_device *dev, struct ifreq *ifr) new_settings.timeout < 2) return -EINVAL; - result = hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT); + result = hdlc->attach(dev, ENCODING_NRZ, + PARITY_CRC16_PR1_CCITT); if (result) return result; @@ -381,21 +364,17 @@ static int cisco_ioctl(struct net_device *dev, struct ifreq *ifr) return -EINVAL; } - static int __init mod_init(void) { register_hdlc_protocol(&proto); return 0; } - - static void __exit mod_exit(void) { unregister_hdlc_protocol(&proto); } - module_init(mod_init); module_exit(mod_exit); diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c index 0720f5f92caa..72250fe0a1df 100644 --- a/drivers/net/wan/hdlc_fr.c +++ b/drivers/net/wan/hdlc_fr.c @@ -6,16 +6,16 @@ * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl> * - Theory of PVC state + Theory of PVC state DCE mode: (exist,new) -> 0,0 when "PVC create" or if "link unreliable" - 0,x -> 1,1 if "link reliable" when sending FULL STATUS - 1,1 -> 1,0 if received FULL STATUS ACK + 0,x -> 1,1 if "link reliable" when sending FULL STATUS + 1,1 -> 1,0 if received FULL STATUS ACK (active) -> 0 when "ifconfig PVC down" or "link unreliable" or "PVC create" - -> 1 when "PVC up" and (exist,new) = 1,0 + -> 1 when "PVC up" and (exist,new) = 1,0 DTE mode: (exist,new,active) = FULL STATUS if "link reliable" @@ -60,7 +60,6 @@ #define NLPID_CCITT_ANSI_LMI 0x08 #define NLPID_CISCO_LMI 0x09 - #define LMI_CCITT_ANSI_DLCI 0 /* LMI DLCI */ #define LMI_CISCO_DLCI 1023 @@ -86,7 +85,6 @@ #define LMI_CCITT_CISCO_LENGTH 13 /* LMI frame lengths */ #define LMI_ANSI_LENGTH 14 - struct fr_hdr { #if defined(__LITTLE_ENDIAN_BITFIELD) unsigned ea1: 1; @@ -111,7 +109,6 @@ struct fr_hdr { #endif } __packed; - struct pvc_device { struct net_device *frad; struct net_device *main; @@ -128,7 +125,7 @@ struct pvc_device { unsigned int fecn: 1; unsigned int becn: 1; unsigned int bandwidth; /* Cisco LMI reporting only */ - }state; + } state; }; struct frad_state { @@ -149,29 +146,24 @@ struct frad_state { u8 rxseq; /* RX sequence number */ }; - static int fr_ioctl(struct net_device *dev, struct ifreq *ifr); - static inline u16 q922_to_dlci(u8 *hdr) { return ((hdr[0] & 0xFC) << 2) | ((hdr[1] & 0xF0) >> 4); } - static inline void dlci_to_q922(u8 *hdr, u16 dlci) { hdr[0] = (dlci >> 2) & 0xFC; hdr[1] = ((dlci << 4) & 0xF0) | 0x01; } - -static inline struct frad_state* state(hdlc_device *hdlc) +static inline struct frad_state *state(hdlc_device *hdlc) { - return(struct frad_state *)(hdlc->state); + return (struct frad_state *)(hdlc->state); } - static inline struct pvc_device *find_pvc(hdlc_device *hdlc, u16 dlci) { struct pvc_device *pvc = state(hdlc)->first_pvc; @@ -187,7 +179,6 @@ static inline struct pvc_device *find_pvc(hdlc_device *hdlc, u16 dlci) return NULL; } - static struct pvc_device *add_pvc(struct net_device *dev, u16 dlci) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -215,13 +206,11 @@ static struct pvc_device *add_pvc(struct net_device *dev, u16 dlci) return pvc; } - static inline int pvc_is_used(struct pvc_device *pvc) { return pvc->main || pvc->ether; } - static inline void pvc_carrier(int on, struct pvc_device *pvc) { if (on) { @@ -241,7 +230,6 @@ static inline void pvc_carrier(int on, struct pvc_device *pvc) } } - static inline void delete_unused_pvcs(hdlc_device *hdlc) { struct pvc_device **pvc_p = &state(hdlc)->first_pvc; @@ -260,7 +248,6 @@ static inline void delete_unused_pvcs(hdlc_device *hdlc) } } - static inline struct net_device **get_dev_p(struct pvc_device *pvc, int type) { @@ -270,7 +257,6 @@ static inline struct net_device **get_dev_p(struct pvc_device *pvc, return &pvc->main; } - static int fr_hard_header(struct sk_buff *skb, u16 dlci) { if (!skb->dev) { /* Control packets */ @@ -334,8 +320,6 @@ static int fr_hard_header(struct sk_buff *skb, u16 dlci) return 0; } - - static int pvc_open(struct net_device *dev) { struct pvc_device *pvc = dev->ml_priv; @@ -345,6 +329,7 @@ static int pvc_open(struct net_device *dev) if (pvc->open_count++ == 0) { hdlc_device *hdlc = dev_to_hdlc(pvc->frad); + if (state(hdlc)->settings.lmi == LMI_NONE) pvc->state.active = netif_carrier_ok(pvc->frad); @@ -354,14 +339,13 @@ static int pvc_open(struct net_device *dev) return 0; } - - static int pvc_close(struct net_device *dev) { struct pvc_device *pvc = dev->ml_priv; if (--pvc->open_count == 0) { hdlc_device *hdlc = dev_to_hdlc(pvc->frad); + if (state(hdlc)->settings.lmi == LMI_NONE) pvc->state.active = 0; @@ -373,8 +357,6 @@ static int pvc_close(struct net_device *dev) return 0; } - - static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { struct pvc_device *pvc = dev->ml_priv; @@ -465,15 +447,12 @@ static inline void fr_log_dlci_active(struct pvc_device *pvc) pvc->state.active ? "active" : "inactive"); } - - static inline u8 fr_lmi_nextseq(u8 x) { x++; return x ? x : 1; } - static void fr_lmi_send(struct net_device *dev, int fullrep) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -495,17 +474,16 @@ static void fr_lmi_send(struct net_device *dev, int fullrep) } skb = dev_alloc_skb(len); - if (!skb) { - netdev_warn(dev, "Memory squeeze on fr_lmi_send()\n"); + if (!skb) return; - } + memset(skb->data, 0, len); skb_reserve(skb, 4); - if (lmi == LMI_CISCO) { + if (lmi == LMI_CISCO) fr_hard_header(skb, LMI_CISCO_DLCI); - } else { + else fr_hard_header(skb, LMI_CCITT_ANSI_DLCI); - } + data = skb_tail_pointer(skb); data[i++] = LMI_CALLREF; data[i++] = dce ? LMI_STATUS : LMI_STATUS_ENQUIRY; @@ -569,8 +547,6 @@ static void fr_lmi_send(struct net_device *dev, int fullrep) dev_queue_xmit(skb); } - - static void fr_set_link_state(int reliable, struct net_device *dev) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -603,7 +579,6 @@ static void fr_set_link_state(int reliable, struct net_device *dev) } } - static void fr_timer(struct timer_list *t) { struct frad_state *st = from_timer(st, t, timer); @@ -637,10 +612,10 @@ static void fr_timer(struct timer_list *t) fr_set_link_state(reliable, dev); } - if (state(hdlc)->settings.dce) + if (state(hdlc)->settings.dce) { state(hdlc)->timer.expires = jiffies + state(hdlc)->settings.t392 * HZ; - else { + } else { if (state(hdlc)->n391cnt) state(hdlc)->n391cnt--; @@ -655,7 +630,6 @@ static void fr_timer(struct timer_list *t) add_timer(&state(hdlc)->timer); } - static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -696,8 +670,9 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb) return 1; } i = 7; - } else + } else { i = 6; + } if (skb->data[i] != (lmi == LMI_CCITT ? LMI_CCITT_REPTYPE : LMI_ANSI_CISCO_REPTYPE)) { @@ -814,8 +789,8 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb) } i++; - new = !! (skb->data[i + 2] & 0x08); - active = !! (skb->data[i + 2] & 0x02); + new = !!(skb->data[i + 2] & 0x08); + active = !!(skb->data[i + 2] & 0x02); if (lmi == LMI_CISCO) { dlci = (skb->data[i] << 8) | skb->data[i + 1]; bw = (skb->data[i + 3] << 16) | @@ -962,8 +937,8 @@ static int fr_rx(struct sk_buff *skb) pvc->state.becn ^= 1; } - - if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) { + skb = skb_share_check(skb, GFP_ATOMIC); + if (!skb) { frad->stats.rx_dropped++; return NET_RX_DROP; } @@ -1018,8 +993,6 @@ rx_drop: return NET_RX_DROP; } - - static void fr_start(struct net_device *dev) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -1040,11 +1013,11 @@ static void fr_start(struct net_device *dev) /* First poll after 1 s */ state(hdlc)->timer.expires = jiffies + HZ; add_timer(&state(hdlc)->timer); - } else + } else { fr_set_link_state(1, dev); + } } - static void fr_stop(struct net_device *dev) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -1056,7 +1029,6 @@ static void fr_stop(struct net_device *dev) fr_set_link_state(0, dev); } - static void fr_close(struct net_device *dev) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -1071,7 +1043,6 @@ static void fr_close(struct net_device *dev) } } - static void pvc_setup(struct net_device *dev) { dev->type = ARPHRD_DLCI; @@ -1095,7 +1066,8 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type) struct net_device *dev; int used; - if ((pvc = add_pvc(frad, dlci)) == NULL) { + pvc = add_pvc(frad, dlci); + if (!pvc) { netdev_warn(frad, "Memory squeeze on fr_add_pvc()\n"); return -ENOBUFS; } @@ -1121,7 +1093,7 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type) dev->priv_flags &= ~IFF_TX_SKB_SHARING; eth_hw_addr_random(dev); } else { - *(__be16*)dev->dev_addr = htons(dlci); + *(__be16 *)dev->dev_addr = htons(dlci); dlci_to_q922(dev->broadcast, dlci); } dev->netdev_ops = &pvc_ops; @@ -1147,17 +1119,17 @@ static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type) return 0; } - - static int fr_del_pvc(hdlc_device *hdlc, unsigned int dlci, int type) { struct pvc_device *pvc; struct net_device *dev; - if ((pvc = find_pvc(hdlc, dlci)) == NULL) + pvc = find_pvc(hdlc, dlci); + if (!pvc) return -ENOENT; - if ((dev = *get_dev_p(pvc, type)) == NULL) + dev = *get_dev_p(pvc, type); + if (!dev) return -ENOENT; if (dev->flags & IFF_UP) @@ -1174,12 +1146,11 @@ static int fr_del_pvc(hdlc_device *hdlc, unsigned int dlci, int type) return 0; } - - static void fr_destroy(struct net_device *frad) { hdlc_device *hdlc = dev_to_hdlc(frad); struct pvc_device *pvc = state(hdlc)->first_pvc; + state(hdlc)->first_pvc = NULL; /* All PVCs destroyed */ state(hdlc)->dce_pvc_count = 0; state(hdlc)->dce_changed = 1; @@ -1198,7 +1169,6 @@ static void fr_destroy(struct net_device *frad) } } - static struct hdlc_proto proto = { .close = fr_close, .start = fr_start, @@ -1209,7 +1179,6 @@ static struct hdlc_proto proto = { .module = THIS_MODULE, }; - static int fr_ioctl(struct net_device *dev, struct ifreq *ifr) { fr_proto __user *fr_s = ifr->ifr_settings.ifs_ifsu.fr; @@ -1259,7 +1228,8 @@ static int fr_ioctl(struct net_device *dev, struct ifreq *ifr) new_settings.dce != 1)) return -EINVAL; - result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT); + result = hdlc->attach(dev, ENCODING_NRZ, + PARITY_CRC16_PR1_CCITT); if (result) return result; @@ -1309,20 +1279,17 @@ static int fr_ioctl(struct net_device *dev, struct ifreq *ifr) return -EINVAL; } - static int __init mod_init(void) { register_hdlc_protocol(&proto); return 0; } - static void __exit mod_exit(void) { unregister_hdlc_protocol(&proto); } - module_init(mod_init); module_exit(mod_exit); diff --git a/drivers/net/wan/hdlc_ppp.c b/drivers/net/wan/hdlc_ppp.c index 261b53fc8e04..834be2ae3e9e 100644 --- a/drivers/net/wan/hdlc_ppp.c +++ b/drivers/net/wan/hdlc_ppp.c @@ -41,6 +41,7 @@ static const char *const code_names[CP_CODES] = { "0", "ConfReq", "ConfAck", "ConfNak", "ConfRej", "TermReq", "TermAck", "CodeRej", "ProtoRej", "EchoReq", "EchoReply", "Discard" }; + static char debug_buffer[64 + 3 * DEBUG_CP]; #endif @@ -58,7 +59,6 @@ struct cp_header { __be16 len; }; - struct proto { struct net_device *dev; struct timer_list timer; @@ -91,6 +91,7 @@ static const char *const state_names[STATES] = { "Closed", "Stopped", "Stopping", "ReqSent", "AckRecv", "AckSent", "Opened" }; + static const char *const event_names[EVENTS] = { "Start", "Stop", "TO+", "TO-", "RCR+", "RCR-", "RCA", "RCN", "RTR", "RTA", "RUC", "RXJ+", "RXJ-" @@ -101,12 +102,12 @@ static struct sk_buff_head tx_queue; /* used when holding the spin lock */ static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr); -static inline struct ppp* get_ppp(struct net_device *dev) +static inline struct ppp *get_ppp(struct net_device *dev) { return (struct ppp *)dev_to_hdlc(dev)->state; } -static inline struct proto* get_proto(struct net_device *dev, u16 pid) +static inline struct proto *get_proto(struct net_device *dev, u16 pid) { struct ppp *ppp = get_ppp(dev); @@ -122,7 +123,7 @@ static inline struct proto* get_proto(struct net_device *dev, u16 pid) } } -static inline const char* proto_name(u16 pid) +static inline const char *proto_name(u16 pid) { switch (pid) { case PID_LCP: @@ -138,7 +139,7 @@ static inline const char* proto_name(u16 pid) static __be16 ppp_type_trans(struct sk_buff *skb, struct net_device *dev) { - struct hdlc_header *data = (struct hdlc_header*)skb->data; + struct hdlc_header *data = (struct hdlc_header *)skb->data; if (skb->len < sizeof(struct hdlc_header)) return htons(ETH_P_HDLC); @@ -160,7 +161,6 @@ static __be16 ppp_type_trans(struct sk_buff *skb, struct net_device *dev) } } - static int ppp_hard_header(struct sk_buff *skb, struct net_device *dev, u16 type, const void *daddr, const void *saddr, unsigned int len) @@ -171,7 +171,7 @@ static int ppp_hard_header(struct sk_buff *skb, struct net_device *dev, #endif skb_push(skb, sizeof(struct hdlc_header)); - data = (struct hdlc_header*)skb->data; + data = (struct hdlc_header *)skb->data; data->address = HDLC_ADDR_ALLSTATIONS; data->control = HDLC_CTRL_UI; @@ -193,10 +193,10 @@ static int ppp_hard_header(struct sk_buff *skb, struct net_device *dev, return sizeof(struct hdlc_header); } - static void ppp_tx_flush(void) { struct sk_buff *skb; + while ((skb = skb_dequeue(&tx_queue)) != NULL) dev_queue_xmit(skb); } @@ -219,10 +219,9 @@ static void ppp_tx_cp(struct net_device *dev, u16 pid, u8 code, skb = dev_alloc_skb(sizeof(struct hdlc_header) + sizeof(struct cp_header) + magic_len + len); - if (!skb) { - netdev_warn(dev, "out of memory in ppp_tx_cp()\n"); + if (!skb) return; - } + skb_reserve(skb, sizeof(struct hdlc_header)); cp = skb_put(skb, sizeof(struct cp_header)); @@ -256,7 +255,6 @@ static void ppp_tx_cp(struct net_device *dev, u16 pid, u8 code, skb_queue_tail(&tx_queue, skb); } - /* State transition table (compare STD-51) Events Actions TO+ = Timeout with counter > 0 irc = Initialize-Restart-Count @@ -294,7 +292,6 @@ static int cp_table[EVENTS][STATES] = { { 0 , 1 , 1 , 1 , 1 , 1 ,IRC|STR|2}, /* RXJ- */ }; - /* SCA: RCR+ must supply id, len and data SCN: RCR- must supply code, id, len and data STA: RTR must supply id @@ -369,7 +366,6 @@ static void ppp_cp_event(struct net_device *dev, u16 pid, u16 event, u8 code, #endif } - static void ppp_cp_parse_cr(struct net_device *dev, u16 pid, u8 id, unsigned int req_len, const u8 *data) { @@ -378,7 +374,8 @@ static void ppp_cp_parse_cr(struct net_device *dev, u16 pid, u8 id, u8 *out; unsigned int len = req_len, nak_len = 0, rej_len = 0; - if (!(out = kmalloc(len, GFP_ATOMIC))) { + out = kmalloc(len, GFP_ATOMIC); + if (!out) { dev->stats.rx_dropped++; return; /* out of memory, ignore CR packet */ } @@ -435,7 +432,7 @@ err_out: static int ppp_rx(struct sk_buff *skb) { - struct hdlc_header *hdr = (struct hdlc_header*)skb->data; + struct hdlc_header *hdr = (struct hdlc_header *)skb->data; struct net_device *dev = skb->dev; struct ppp *ppp = get_ppp(dev); struct proto *proto; @@ -493,7 +490,7 @@ static int ppp_rx(struct sk_buff *skb) if (pid == PID_LCP) switch (cp->code) { case LCP_PROTO_REJ: - pid = ntohs(*(__be16*)skb->data); + pid = ntohs(*(__be16 *)skb->data); if (pid == PID_LCP || pid == PID_IPCP || pid == PID_IPV6CP) ppp_cp_event(dev, pid, RXJ_BAD, 0, 0, @@ -615,7 +612,6 @@ static void ppp_timer(struct timer_list *t) ppp_tx_flush(); } - static void ppp_start(struct net_device *dev) { struct ppp *ppp = get_ppp(dev); @@ -623,6 +619,7 @@ static void ppp_start(struct net_device *dev) for (i = 0; i < IDX_COUNT; i++) { struct proto *proto = &ppp->protos[i]; + proto->dev = dev; timer_setup(&proto->timer, ppp_timer, 0); proto->state = CLOSED; @@ -680,7 +677,8 @@ static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr) /* no settable parameters */ - result = hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT); + result = hdlc->attach(dev, ENCODING_NRZ, + PARITY_CRC16_PR1_CCITT); if (result) return result; @@ -707,7 +705,6 @@ static int ppp_ioctl(struct net_device *dev, struct ifreq *ifr) return -EINVAL; } - static int __init mod_init(void) { skb_queue_head_init(&tx_queue); @@ -720,7 +717,6 @@ static void __exit mod_exit(void) unregister_hdlc_protocol(&proto); } - module_init(mod_init); module_exit(mod_exit); diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c index ba8c36c7ea91..d2bf72bf3bd7 100644 --- a/drivers/net/wan/hdlc_x25.c +++ b/drivers/net/wan/hdlc_x25.c @@ -56,10 +56,8 @@ static void x25_connect_disconnect(struct net_device *dev, int reason, int code) unsigned char *ptr; skb = __dev_alloc_skb(1, GFP_ATOMIC | __GFP_NOMEMALLOC); - if (!skb) { - netdev_err(dev, "out of memory\n"); + if (!skb) return; - } ptr = skb_put(skb, 1); *ptr = code; @@ -70,22 +68,16 @@ static void x25_connect_disconnect(struct net_device *dev, int reason, int code) tasklet_schedule(&x25st->rx_tasklet); } - - static void x25_connected(struct net_device *dev, int reason) { x25_connect_disconnect(dev, reason, X25_IFACE_CONNECT); } - - static void x25_disconnected(struct net_device *dev, int reason) { x25_connect_disconnect(dev, reason, X25_IFACE_DISCONNECT); } - - static int x25_data_indication(struct net_device *dev, struct sk_buff *skb) { struct x25_state *x25st = state(dev_to_hdlc(dev)); @@ -108,8 +100,6 @@ static int x25_data_indication(struct net_device *dev, struct sk_buff *skb) return NET_RX_SUCCESS; } - - static void x25_data_transmit(struct net_device *dev, struct sk_buff *skb) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -123,8 +113,6 @@ static void x25_data_transmit(struct net_device *dev, struct sk_buff *skb) hdlc->xmit(skb, dev); /* Ignore return value :-( */ } - - static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -149,13 +137,15 @@ static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev) switch (skb->data[0]) { case X25_IFACE_DATA: /* Data to be transmitted */ skb_pull(skb, 1); - if ((result = lapb_data_request(dev, skb)) != LAPB_OK) + result = lapb_data_request(dev, skb); + if (result != LAPB_OK) dev_kfree_skb(skb); spin_unlock_bh(&x25st->up_lock); return NETDEV_TX_OK; case X25_IFACE_CONNECT: - if ((result = lapb_connect_request(dev))!= LAPB_OK) { + result = lapb_connect_request(dev); + if (result != LAPB_OK) { if (result == LAPB_CONNECTED) /* Send connect confirm. msg to level 3 */ x25_connected(dev, 0); @@ -166,7 +156,8 @@ static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev) break; case X25_IFACE_DISCONNECT: - if ((result = lapb_disconnect_request(dev)) != LAPB_OK) { + result = lapb_disconnect_request(dev); + if (result != LAPB_OK) { if (result == LAPB_NOTCONNECTED) /* Send disconnect confirm. msg to level 3 */ x25_disconnected(dev, 0); @@ -185,8 +176,6 @@ static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } - - static int x25_open(struct net_device *dev) { static const struct lapb_register_struct cb = { @@ -232,8 +221,6 @@ static int x25_open(struct net_device *dev) return 0; } - - static void x25_close(struct net_device *dev) { hdlc_device *hdlc = dev_to_hdlc(dev); @@ -247,15 +234,14 @@ static void x25_close(struct net_device *dev) tasklet_kill(&x25st->rx_tasklet); } - - static int x25_rx(struct sk_buff *skb) { struct net_device *dev = skb->dev; hdlc_device *hdlc = dev_to_hdlc(dev); struct x25_state *x25st = state(hdlc); - if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) { + skb = skb_share_check(skb, GFP_ATOMIC); + if (!skb) { dev->stats.rx_dropped++; return NET_RX_DROP; } @@ -279,7 +265,6 @@ static int x25_rx(struct sk_buff *skb) return NET_RX_DROP; } - static struct hdlc_proto proto = { .open = x25_open, .close = x25_close, @@ -289,7 +274,6 @@ static struct hdlc_proto proto = { .module = THIS_MODULE, }; - static int x25_ioctl(struct net_device *dev, struct ifreq *ifr) { x25_hdlc_proto __user *x25_s = ifr->ifr_settings.ifs_ifsu.x25; @@ -326,35 +310,36 @@ static int x25_ioctl(struct net_device *dev, struct ifreq *ifr) new_settings.t1 = 3; new_settings.t2 = 1; new_settings.n2 = 10; - } - else { + } else { if (copy_from_user(&new_settings, x25_s, size)) return -EFAULT; if ((new_settings.dce != 0 && - new_settings.dce != 1) || - (new_settings.modulo != 8 && - new_settings.modulo != 128) || - new_settings.window < 1 || - (new_settings.modulo == 8 && - new_settings.window > 7) || - (new_settings.modulo == 128 && - new_settings.window > 127) || - new_settings.t1 < 1 || - new_settings.t1 > 255 || - new_settings.t2 < 1 || - new_settings.t2 > 255 || - new_settings.n2 < 1 || - new_settings.n2 > 255) + new_settings.dce != 1) || + (new_settings.modulo != 8 && + new_settings.modulo != 128) || + new_settings.window < 1 || + (new_settings.modulo == 8 && + new_settings.window > 7) || + (new_settings.modulo == 128 && + new_settings.window > 127) || + new_settings.t1 < 1 || + new_settings.t1 > 255 || + new_settings.t2 < 1 || + new_settings.t2 > 255 || + new_settings.n2 < 1 || + new_settings.n2 > 255) return -EINVAL; } - result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT); + result = hdlc->attach(dev, ENCODING_NRZ, + PARITY_CRC16_PR1_CCITT); if (result) return result; - if ((result = attach_hdlc_protocol(dev, &proto, - sizeof(struct x25_state)))) + result = attach_hdlc_protocol(dev, &proto, + sizeof(struct x25_state)); + if (result) return result; memcpy(&state(hdlc)->settings, &new_settings, size); @@ -380,21 +365,17 @@ static int x25_ioctl(struct net_device *dev, struct ifreq *ifr) return -EINVAL; } - static int __init mod_init(void) { register_hdlc_protocol(&proto); return 0; } - - static void __exit mod_exit(void) { unregister_hdlc_protocol(&proto); } - module_init(mod_init); module_exit(mod_exit); diff --git a/drivers/net/wan/hostess_sv11.c b/drivers/net/wan/hostess_sv11.c index 6c05c4c8914a..fd61a7cc4fdf 100644 --- a/drivers/net/wan/hostess_sv11.c +++ b/drivers/net/wan/hostess_sv11.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* - * Comtrol SV11 card driver +/* Comtrol SV11 card driver * * This is a slightly odd Z85230 synchronous driver. All you need to * know basically is @@ -9,7 +8,7 @@ * * It supports DMA using two DMA channels in SYNC mode. The driver doesn't * use these facilities - * + * * The control port is at io+1, the data at io+3 and turning off the DMA * is done by writing 0 to io+4 * @@ -44,17 +43,15 @@ static int dma; -/* - * Network driver support routines +/* Network driver support routines */ -static inline struct z8530_dev* dev_to_sv(struct net_device *dev) +static inline struct z8530_dev *dev_to_sv(struct net_device *dev) { return (struct z8530_dev *)dev_to_hdlc(dev)->priv; } -/* - * Frame receive. Simple for our card as we do HDLC and there +/* Frame receive. Simple for our card as we do HDLC and there * is no funny garbage involved */ @@ -65,15 +62,13 @@ static void hostess_input(struct z8530_channel *c, struct sk_buff *skb) skb->protocol = hdlc_type_trans(skb, c->netdevice); skb_reset_mac_header(skb); skb->dev = c->netdevice; - /* - * Send it to the PPP layer. We don't have time to process + /* Send it to the PPP layer. We don't have time to process * it right now. */ netif_rx(skb); } -/* - * We've been placed in the UP state +/* We've been placed in the UP state */ static int hostess_open(struct net_device *d) @@ -81,19 +76,18 @@ static int hostess_open(struct net_device *d) struct z8530_dev *sv11 = dev_to_sv(d); int err = -1; - /* - * Link layer up + /* Link layer up */ switch (dma) { - case 0: - err = z8530_sync_open(d, &sv11->chanA); - break; - case 1: - err = z8530_sync_dma_open(d, &sv11->chanA); - break; - case 2: - err = z8530_sync_txdma_open(d, &sv11->chanA); - break; + case 0: + err = z8530_sync_open(d, &sv11->chanA); + break; + case 1: + err = z8530_sync_dma_open(d, &sv11->chanA); + break; + case 2: + err = z8530_sync_txdma_open(d, &sv11->chanA); + break; } if (err) @@ -102,15 +96,15 @@ static int hostess_open(struct net_device *d) err = hdlc_open(d); if (err) { switch (dma) { - case 0: - z8530_sync_close(d, &sv11->chanA); - break; - case 1: - z8530_sync_dma_close(d, &sv11->chanA); - break; - case 2: - z8530_sync_txdma_close(d, &sv11->chanA); - break; + case 0: + z8530_sync_close(d, &sv11->chanA); + break; + case 1: + z8530_sync_dma_close(d, &sv11->chanA); + break; + case 2: + z8530_sync_txdma_close(d, &sv11->chanA); + break; } return err; } @@ -127,8 +121,7 @@ static int hostess_open(struct net_device *d) static int hostess_close(struct net_device *d) { struct z8530_dev *sv11 = dev_to_sv(d); - /* - * Discard new frames + /* Discard new frames */ sv11->chanA.rx_function = z8530_null_rx; @@ -136,32 +129,29 @@ static int hostess_close(struct net_device *d) netif_stop_queue(d); switch (dma) { - case 0: - z8530_sync_close(d, &sv11->chanA); - break; - case 1: - z8530_sync_dma_close(d, &sv11->chanA); - break; - case 2: - z8530_sync_txdma_close(d, &sv11->chanA); - break; + case 0: + z8530_sync_close(d, &sv11->chanA); + break; + case 1: + z8530_sync_dma_close(d, &sv11->chanA); + break; + case 2: + z8530_sync_txdma_close(d, &sv11->chanA); + break; } return 0; } static int hostess_ioctl(struct net_device *d, struct ifreq *ifr, int cmd) { - /* struct z8530_dev *sv11=dev_to_sv(d); - z8530_ioctl(d,&sv11->chanA,ifr,cmd) */ return hdlc_ioctl(d, ifr, cmd); } -/* - * Passed network frames, fire them downwind. +/* Passed network frames, fire them downwind. */ static netdev_tx_t hostess_queue_xmit(struct sk_buff *skb, - struct net_device *d) + struct net_device *d) { return z8530_queue_xmit(&dev_to_sv(d)->chanA, skb); } @@ -174,8 +164,7 @@ static int hostess_attach(struct net_device *dev, unsigned short encoding, return -EINVAL; } -/* - * Description block for a Comtrol Hostess SV11 card +/* Description block for a Comtrol Hostess SV11 card */ static const struct net_device_ops hostess_ops = { @@ -189,8 +178,7 @@ static struct z8530_dev *sv11_init(int iobase, int irq) { struct z8530_dev *sv; struct net_device *netdev; - /* - * Get the needed I/O space + /* Get the needed I/O space */ if (!request_region(iobase, 8, "Comtrol SV11")) { @@ -202,8 +190,7 @@ static struct z8530_dev *sv11_init(int iobase, int irq) if (!sv) goto err_kzalloc; - /* - * Stuff in the I/O addressing + /* Stuff in the I/O addressing */ sv->active = 0; @@ -218,7 +205,8 @@ static struct z8530_dev *sv11_init(int iobase, int irq) outb(0, iobase + 4); /* DMA off */ /* We want a fast IRQ for this device. Actually we'd like an even faster - IRQ ;) - This is one driver RtLinux is made for */ + * IRQ ;) - This is one driver RtLinux is made for + */ if (request_irq(irq, z8530_interrupt, 0, "Hostess SV11", sv) < 0) { @@ -232,8 +220,7 @@ static struct z8530_dev *sv11_init(int iobase, int irq) sv->chanB.dev = sv; if (dma) { - /* - * You can have DMA off or 1 and 3 thats the lot + /* You can have DMA off or 1 and 3 thats the lot * on the Comtrol. */ sv->chanA.txdma = 3; @@ -248,11 +235,11 @@ static struct z8530_dev *sv11_init(int iobase, int irq) } /* Kill our private IRQ line the hostess can end up chattering - until the configuration is set */ + * until the configuration is set + */ disable_irq(irq); - /* - * Begin normal initialise + /* Begin normal initialise */ if (z8530_init(sv)) { @@ -268,8 +255,7 @@ static struct z8530_dev *sv11_init(int iobase, int irq) enable_irq(irq); - /* - * Now we can take the IRQ + /* Now we can take the IRQ */ sv->chanA.netdevice = netdev = alloc_hdlcdev(sv); @@ -340,7 +326,8 @@ static struct z8530_dev *sv11_unit; int init_module(void) { - if ((sv11_unit = sv11_init(io, irq)) == NULL) + sv11_unit = sv11_init(io, irq); + if (!sv11_unit) return -ENODEV; return 0; } diff --git a/drivers/net/wan/ixp4xx_hss.c b/drivers/net/wan/ixp4xx_hss.c index ecea09fd21cb..e97521138f7e 100644 --- a/drivers/net/wan/ixp4xx_hss.c +++ b/drivers/net/wan/ixp4xx_hss.c @@ -83,7 +83,6 @@ #define PKT_HDLC_CRC_32 0x2 /* default = CRC-16 */ #define PKT_HDLC_MSB_ENDIAN 0x4 /* default = LE */ - /* hss_config, PCRs */ /* Frame sync sampling, default = active low */ #define PCR_FRM_SYNC_ACTIVE_HIGH 0x40000000 @@ -150,26 +149,24 @@ /* HSS number, default = 0 (first) */ #define CCR_SECOND_HSS 0x01000000 - /* hss_config, clkCR: main:10, num:10, denom:12 */ -#define CLK42X_SPEED_EXP ((0x3FF << 22) | ( 2 << 12) | 15) /*65 KHz*/ - -#define CLK42X_SPEED_512KHZ (( 130 << 22) | ( 2 << 12) | 15) -#define CLK42X_SPEED_1536KHZ (( 43 << 22) | ( 18 << 12) | 47) -#define CLK42X_SPEED_1544KHZ (( 43 << 22) | ( 33 << 12) | 192) -#define CLK42X_SPEED_2048KHZ (( 32 << 22) | ( 34 << 12) | 63) -#define CLK42X_SPEED_4096KHZ (( 16 << 22) | ( 34 << 12) | 127) -#define CLK42X_SPEED_8192KHZ (( 8 << 22) | ( 34 << 12) | 255) - -#define CLK46X_SPEED_512KHZ (( 130 << 22) | ( 24 << 12) | 127) -#define CLK46X_SPEED_1536KHZ (( 43 << 22) | (152 << 12) | 383) -#define CLK46X_SPEED_1544KHZ (( 43 << 22) | ( 66 << 12) | 385) -#define CLK46X_SPEED_2048KHZ (( 32 << 22) | (280 << 12) | 511) -#define CLK46X_SPEED_4096KHZ (( 16 << 22) | (280 << 12) | 1023) -#define CLK46X_SPEED_8192KHZ (( 8 << 22) | (280 << 12) | 2047) - -/* - * HSS_CONFIG_CLOCK_CR register consists of 3 parts: +#define CLK42X_SPEED_EXP ((0x3FF << 22) | (2 << 12) | 15) /*65 KHz*/ + +#define CLK42X_SPEED_512KHZ ((130 << 22) | (2 << 12) | 15) +#define CLK42X_SPEED_1536KHZ ((43 << 22) | (18 << 12) | 47) +#define CLK42X_SPEED_1544KHZ ((43 << 22) | (33 << 12) | 192) +#define CLK42X_SPEED_2048KHZ ((32 << 22) | (34 << 12) | 63) +#define CLK42X_SPEED_4096KHZ ((16 << 22) | (34 << 12) | 127) +#define CLK42X_SPEED_8192KHZ ((8 << 22) | (34 << 12) | 255) + +#define CLK46X_SPEED_512KHZ ((130 << 22) | (24 << 12) | 127) +#define CLK46X_SPEED_1536KHZ ((43 << 22) | (152 << 12) | 383) +#define CLK46X_SPEED_1544KHZ ((43 << 22) | (66 << 12) | 385) +#define CLK46X_SPEED_2048KHZ ((32 << 22) | (280 << 12) | 511) +#define CLK46X_SPEED_4096KHZ ((16 << 22) | (280 << 12) | 1023) +#define CLK46X_SPEED_8192KHZ ((8 << 22) | (280 << 12) | 2047) + +/* HSS_CONFIG_CLOCK_CR register consists of 3 parts: * A (10 bits), B (10 bits) and C (12 bits). * IXP42x HSS clock generator operation (verified with an oscilloscope): * Each clock bit takes 7.5 ns (1 / 133.xx MHz). @@ -208,7 +205,6 @@ #define HSS_CONFIG_TX_LUT 0x18 /* channel look-up tables */ #define HSS_CONFIG_RX_LUT 0x38 - /* NPE command codes */ /* writes the ConfigWord value to the location specified by offset */ #define PORT_CONFIG_WRITE 0x40 @@ -220,7 +216,8 @@ #define PORT_ERROR_READ 0x42 /* triggers the NPE to reset internal status and enable the HssPacketized - operation for the flow specified by pPipe */ + * operation for the flow specified by pPipe + */ #define PKT_PIPE_FLOW_ENABLE 0x50 #define PKT_PIPE_FLOW_DISABLE 0x51 #define PKT_NUM_PIPES_WRITE 0x52 @@ -235,12 +232,12 @@ #define ERR_HDLC_ALIGN 2 /* HDLC alignment error */ #define ERR_HDLC_FCS 3 /* HDLC Frame Check Sum error */ #define ERR_RXFREE_Q_EMPTY 4 /* RX-free queue became empty while receiving - this packet (if buf_len < pkt_len) */ + * this packet (if buf_len < pkt_len) + */ #define ERR_HDLC_TOO_LONG 5 /* HDLC frame size too long */ #define ERR_HDLC_ABORT 6 /* abort sequence received */ #define ERR_DISCONNECTING 7 /* disconnect is in progress */ - #ifdef __ARMEB__ typedef struct sk_buff buffer_t; #define free_buffer dev_kfree_skb @@ -308,7 +305,6 @@ struct desc { u32 __reserved1[4]; }; - #define rx_desc_phys(port, n) ((port)->desc_tab_phys + \ (n) * sizeof(struct desc)) #define rx_desc_ptr(port, n) (&(port)->desc_tab[n]) @@ -327,7 +323,7 @@ static DEFINE_SPINLOCK(npe_lock); static const struct { int tx, txdone, rx, rxfree; -}queue_ids[2] = {{HSS0_PKT_TX0_QUEUE, HSS0_PKT_TXDONE_QUEUE, HSS0_PKT_RX_QUEUE, +} queue_ids[2] = {{HSS0_PKT_TX0_QUEUE, HSS0_PKT_TXDONE_QUEUE, HSS0_PKT_RX_QUEUE, HSS0_PKT_RXFREE0_QUEUE}, {HSS1_PKT_TX0_QUEUE, HSS1_PKT_TXDONE_QUEUE, HSS1_PKT_RX_QUEUE, HSS1_PKT_RXFREE0_QUEUE}, @@ -337,7 +333,7 @@ static const struct { * utility functions ****************************************************************************/ -static inline struct port* dev_to_port(struct net_device *dev) +static inline struct port *dev_to_port(struct net_device *dev) { return dev_to_hdlc(dev)->priv; } @@ -346,6 +342,7 @@ static inline struct port* dev_to_port(struct net_device *dev) static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt) { int i; + for (i = 0; i < cnt; i++) dest[i] = swab32(src[i]); } @@ -355,9 +352,10 @@ static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt) * HSS access ****************************************************************************/ -static void hss_npe_send(struct port *port, struct msg *msg, const char* what) +static void hss_npe_send(struct port *port, struct msg *msg, const char *what) { - u32 *val = (u32*)msg; + u32 *val = (u32 *)msg; + if (npe_send_message(port->npe, msg, what)) { pr_crit("HSS-%i: unable to send command [%08X:%08X] to %s\n", port->id, val[0], val[1], npe_name(port->npe)); @@ -513,10 +511,12 @@ static int hss_load_firmware(struct port *port) if (port->initialized) return 0; - if (!npe_running(port->npe) && - (err = npe_load_firmware(port->npe, npe_name(port->npe), - port->dev))) - return err; + if (!npe_running(port->npe)) { + err = npe_load_firmware(port->npe, npe_name(port->npe), + port->dev); + if (err) + return err; + } /* HDLC mode configuration */ memset(&msg, 0, sizeof(msg)); @@ -567,7 +567,6 @@ static inline void debug_pkt(struct net_device *dev, const char *func, #endif } - static inline void debug_desc(u32 phys, struct desc *desc) { #if DEBUG_DESC @@ -583,7 +582,8 @@ static inline int queue_get_desc(unsigned int queue, struct port *port, u32 phys, tab_phys, n_desc; struct desc *tab; - if (!(phys = qmgr_get_entry(queue))) + phys = qmgr_get_entry(queue); + if (!phys) return -1; BUG_ON(phys & 0x1F); @@ -603,10 +603,10 @@ static inline void queue_put_desc(unsigned int queue, u32 phys, BUG_ON(phys & 0x1F); qmgr_put_entry(queue, phys); /* Don't check for queue overflow here, we've allocated sufficient - length and queues >= 32 don't support this check anyway. */ + * length and queues >= 32 don't support this check anyway. + */ } - static inline void dma_unmap_tx(struct port *port, struct desc *desc) { #ifdef __ARMEB__ @@ -619,7 +619,6 @@ static inline void dma_unmap_tx(struct port *port, struct desc *desc) #endif } - static void hss_hdlc_set_carrier(void *pdev, int carrier) { struct net_device *netdev = pdev; @@ -670,7 +669,8 @@ static int hss_hdlc_poll(struct napi_struct *napi, int budget) u32 phys; #endif - if ((n = queue_get_desc(rxq, port, 0)) < 0) { + n = queue_get_desc(rxq, port, 0); + if (n < 0) { #if DEBUG_RX printk(KERN_DEBUG "%s: hss_hdlc_poll" " napi_complete\n", dev->name); @@ -705,7 +705,8 @@ static int hss_hdlc_poll(struct napi_struct *napi, int budget) switch (desc->status) { case 0: #ifdef __ARMEB__ - if ((skb = netdev_alloc_skb(dev, RX_SIZE)) != NULL) { + skb = netdev_alloc_skb(dev, RX_SIZE); + if (skb) { phys = dma_map_single(&dev->dev, skb->data, RX_SIZE, DMA_FROM_DEVICE); @@ -784,7 +785,6 @@ static int hss_hdlc_poll(struct napi_struct *napi, int budget) return received; /* not all work done */ } - static void hss_hdlc_txdone_irq(void *pdev) { struct net_device *dev = pdev; @@ -854,7 +854,8 @@ static int hss_hdlc_xmit(struct sk_buff *skb, struct net_device *dev) #else offset = (int)skb->data & 3; /* keep 32-bit alignment */ bytes = ALIGN(offset + len, 4); - if (!(mem = kmalloc(bytes, GFP_ATOMIC))) { + mem = kmalloc(bytes, GFP_ATOMIC); + if (!mem) { dev_kfree_skb(skb); dev->stats.tx_dropped++; return NETDEV_TX_OK; @@ -910,7 +911,6 @@ static int hss_hdlc_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } - static int request_hdlc_queues(struct port *port) { int err; @@ -974,8 +974,9 @@ static int init_hdlc_queues(struct port *port) return -ENOMEM; } - if (!(port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL, - &port->desc_tab_phys))) + port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL, + &port->desc_tab_phys); + if (!port->desc_tab) return -ENOMEM; memset(port->desc_tab, 0, POOL_ALLOC_SIZE); memset(port->rx_buff_tab, 0, sizeof(port->rx_buff_tab)); /* tables */ @@ -987,11 +988,13 @@ static int init_hdlc_queues(struct port *port) buffer_t *buff; void *data; #ifdef __ARMEB__ - if (!(buff = netdev_alloc_skb(port->netdev, RX_SIZE))) + buff = netdev_alloc_skb(port->netdev, RX_SIZE); + if (!buff) return -ENOMEM; data = buff->data; #else - if (!(buff = kmalloc(RX_SIZE, GFP_KERNEL))) + buff = kmalloc(RX_SIZE, GFP_KERNEL); + if (!buff) return -ENOMEM; data = buff; #endif @@ -1016,6 +1019,7 @@ static void destroy_hdlc_queues(struct port *port) for (i = 0; i < RX_DESCS; i++) { struct desc *desc = rx_desc_ptr(port, i); buffer_t *buff = port->rx_buff_tab[i]; + if (buff) { dma_unmap_single(&port->netdev->dev, desc->data, RX_SIZE, @@ -1026,6 +1030,7 @@ static void destroy_hdlc_queues(struct port *port) for (i = 0; i < TX_DESCS; i++) { struct desc *desc = tx_desc_ptr(port, i); buffer_t *buff = port->tx_buff_tab[i]; + if (buff) { dma_unmap_tx(port, desc); free_buffer(buff); @@ -1047,23 +1052,29 @@ static int hss_hdlc_open(struct net_device *dev) unsigned long flags; int i, err = 0; - if ((err = hdlc_open(dev))) + err = hdlc_open(dev); + if (err) return err; - if ((err = hss_load_firmware(port))) + err = hss_load_firmware(port); + if (err) goto err_hdlc_close; - if ((err = request_hdlc_queues(port))) + err = request_hdlc_queues(port); + if (err) goto err_hdlc_close; - if ((err = init_hdlc_queues(port))) + err = init_hdlc_queues(port); + if (err) goto err_destroy_queues; spin_lock_irqsave(&npe_lock, flags); - if (port->plat->open) - if ((err = port->plat->open(port->id, dev, - hss_hdlc_set_carrier))) + if (port->plat->open) { + err = port->plat->open(port->id, dev, hss_hdlc_set_carrier); + if (err) goto err_unlock; + } + spin_unlock_irqrestore(&npe_lock, flags); /* Populate queues with buffers, no failure after this point */ @@ -1160,7 +1171,6 @@ static int hss_hdlc_close(struct net_device *dev) return 0; } - static int hss_hdlc_attach(struct net_device *dev, unsigned short encoding, unsigned short parity) { @@ -1169,7 +1179,7 @@ static int hss_hdlc_attach(struct net_device *dev, unsigned short encoding, if (encoding != ENCODING_NRZ) return -EINVAL; - switch(parity) { + switch (parity) { case PARITY_CRC16_PR1_CCITT: port->hdlc_cfg = 0; return 0; @@ -1224,6 +1234,7 @@ static void find_best_clock(u32 timer_freq, u32 rate, u32 *best, u32 *reg) for (b = 0; b < 0x400; b++) { u64 c = (b + 1) * (u64)rate; + do_div(c, timer_freq - rate * a); c--; if (c >= 0xFFF) { /* 12-bit - no need to check more 'b's */ @@ -1255,7 +1266,7 @@ static int hss_hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) if (cmd != SIOCWANDEV) return hdlc_ioctl(dev, ifr, cmd); - switch(ifr->ifr_settings.type) { + switch (ifr->ifr_settings.type) { case IF_GET_IFACE: ifr->ifr_settings.type = IF_IFACE_V35; if (ifr->ifr_settings.size < size) { @@ -1272,7 +1283,7 @@ static int hss_hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) case IF_IFACE_SYNC_SERIAL: case IF_IFACE_V35: - if(!capable(CAP_NET_ADMIN)) + if (!capable(CAP_NET_ADMIN)) return -EPERM; if (copy_from_user(&new_line, line, size)) return -EFAULT; @@ -1288,11 +1299,11 @@ static int hss_hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) return -EINVAL; port->clock_type = clk; /* Update settings */ - if (clk == CLOCK_INT) + if (clk == CLOCK_INT) { find_best_clock(port->plat->timer_freq, new_line.clock_rate, &port->clock_rate, &port->clock_reg); - else { + } else { port->clock_rate = 0; port->clock_reg = CLK42X_SPEED_2048KHZ; } @@ -1334,15 +1345,19 @@ static int hss_init_one(struct platform_device *pdev) hdlc_device *hdlc; int err; - if ((port = kzalloc(sizeof(*port), GFP_KERNEL)) == NULL) + port = kzalloc(sizeof(*port), GFP_KERNEL); + if (!port) return -ENOMEM; - if ((port->npe = npe_request(0)) == NULL) { + port->npe = npe_request(0); + if (!port->npe) { err = -ENODEV; goto err_free; } - if ((port->netdev = dev = alloc_hdlcdev(port)) == NULL) { + dev = alloc_hdlcdev(port); + port->netdev = alloc_hdlcdev(port); + if (!port->netdev) { err = -ENOMEM; goto err_plat; } @@ -1361,7 +1376,8 @@ static int hss_init_one(struct platform_device *pdev) port->plat = pdev->dev.platform_data; netif_napi_add(dev, &port->napi, hss_hdlc_poll, NAPI_WEIGHT); - if ((err = register_hdlc_device(dev))) + err = register_hdlc_device(dev); + if (err) goto err_free_netdev; platform_set_drvdata(pdev, port); diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c index 59646865a3a4..89d31adc3809 100644 --- a/drivers/net/wan/lapbether.c +++ b/drivers/net/wan/lapbether.c @@ -6,7 +6,7 @@ * * This is a "pseudo" network driver to allow LAPB over Ethernet. * - * This driver can use any ethernet destination address, and can be + * This driver can use any ethernet destination address, and can be * limited to accept frames from one dedicated ethernet card only. * * History @@ -44,7 +44,8 @@ static const u8 bcast_addr[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; /* If this number is made larger, check that the temporary string buffer - * in lapbeth_new_device is large enough to store the probe device name.*/ + * in lapbeth_new_device is large enough to store the probe device name. + */ #define MAXLAPBDEV 100 struct lapbethdev { @@ -64,15 +65,14 @@ static void lapbeth_disconnected(struct net_device *dev, int reason); /* ------------------------------------------------------------------------ */ -/* - * Get the LAPB device for the ethernet device +/* Get the LAPB device for the ethernet device */ static struct lapbethdev *lapbeth_get_x25_dev(struct net_device *dev) { struct lapbethdev *lapbeth; list_for_each_entry_rcu(lapbeth, &lapbeth_devices, node, lockdep_rtnl_is_held()) { - if (lapbeth->ethdev == dev) + if (lapbeth->ethdev == dev) return lapbeth; } return NULL; @@ -105,10 +105,10 @@ static int lapbeth_napi_poll(struct napi_struct *napi, int budget) return processed; } -/* - * Receive a LAPB frame via an ethernet interface. +/* Receive a LAPB frame via an ethernet interface. */ -static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *ptype, struct net_device *orig_dev) +static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev, + struct packet_type *ptype, struct net_device *orig_dev) { int len, err; struct lapbethdev *lapbeth; @@ -116,7 +116,8 @@ static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev, struct packe if (dev_net(dev) != &init_net) goto drop; - if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) + skb = skb_share_check(skb, GFP_ATOMIC); + if (!skb) return NET_RX_DROP; if (!pskb_may_pull(skb, 2)) @@ -137,7 +138,8 @@ static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev, struct packe skb_pull(skb, 2); /* Remove the length bytes */ skb_trim(skb, len); /* Set the length of the data */ - if ((err = lapb_data_received(lapbeth->axdev, skb)) != LAPB_OK) { + err = lapb_data_received(lapbeth->axdev, skb); + if (err != LAPB_OK) { printk(KERN_DEBUG "lapbether: lapb_data_received err - %d\n", err); goto drop_unlock; } @@ -177,11 +179,10 @@ static int lapbeth_data_indication(struct net_device *dev, struct sk_buff *skb) return NET_RX_SUCCESS; } -/* - * Send a LAPB frame via an ethernet interface +/* Send a LAPB frame via an ethernet interface */ static netdev_tx_t lapbeth_xmit(struct sk_buff *skb, - struct net_device *dev) + struct net_device *dev) { struct lapbethdev *lapbeth = netdev_priv(dev); int err; @@ -219,7 +220,8 @@ static netdev_tx_t lapbeth_xmit(struct sk_buff *skb, skb_pull(skb, 1); - if ((err = lapb_data_request(dev, skb)) != LAPB_OK) { + err = lapb_data_request(dev, skb); + if (err != LAPB_OK) { pr_err("lapb_data_request error - %d\n", err); goto drop; } @@ -263,10 +265,8 @@ static void lapbeth_connected(struct net_device *dev, int reason) unsigned char *ptr; struct sk_buff *skb = __dev_alloc_skb(1, GFP_ATOMIC | __GFP_NOMEMALLOC); - if (!skb) { - pr_err("out of memory\n"); + if (!skb) return; - } ptr = skb_put(skb, 1); *ptr = X25_IFACE_CONNECT; @@ -283,10 +283,8 @@ static void lapbeth_disconnected(struct net_device *dev, int reason) unsigned char *ptr; struct sk_buff *skb = __dev_alloc_skb(1, GFP_ATOMIC | __GFP_NOMEMALLOC); - if (!skb) { - pr_err("out of memory\n"); + if (!skb) return; - } ptr = skb_put(skb, 1); *ptr = X25_IFACE_DISCONNECT; @@ -297,17 +295,16 @@ static void lapbeth_disconnected(struct net_device *dev, int reason) napi_schedule(&lapbeth->napi); } -/* - * Set AX.25 callsign +/* Set AX.25 callsign */ static int lapbeth_set_mac_address(struct net_device *dev, void *addr) { struct sockaddr *sa = addr; + memcpy(dev->dev_addr, sa->sa_data, dev->addr_len); return 0; } - static const struct lapb_register_struct lapbeth_callbacks = { .connect_confirmation = lapbeth_connected, .connect_indication = lapbeth_connected, @@ -317,8 +314,7 @@ static const struct lapb_register_struct lapbeth_callbacks = { .data_transmit = lapbeth_data_transmit, }; -/* - * open/close a device +/* open/close a device */ static int lapbeth_open(struct net_device *dev) { @@ -327,7 +323,8 @@ static int lapbeth_open(struct net_device *dev) napi_enable(&lapbeth->napi); - if ((err = lapb_register(dev, &lapbeth_callbacks)) != LAPB_OK) { + err = lapb_register(dev, &lapbeth_callbacks); + if (err != LAPB_OK) { pr_err("lapb_register error: %d\n", err); return -ENODEV; } @@ -348,7 +345,8 @@ static int lapbeth_close(struct net_device *dev) lapbeth->up = false; spin_unlock_bh(&lapbeth->up_lock); - if ((err = lapb_unregister(dev)) != LAPB_OK) + err = lapb_unregister(dev); + if (err != LAPB_OK) pr_err("lapb_unregister error: %d\n", err); napi_disable(&lapbeth->napi); @@ -375,8 +373,7 @@ static void lapbeth_setup(struct net_device *dev) dev->addr_len = 0; } -/* - * Setup a new device. +/* Setup a new device. */ static int lapbeth_new_device(struct net_device *dev) { @@ -427,8 +424,7 @@ fail: goto out; } -/* - * Free a lapb network device. +/* Free a lapb network device. */ static void lapbeth_free_device(struct lapbethdev *lapbeth) { @@ -437,8 +433,7 @@ static void lapbeth_free_device(struct lapbethdev *lapbeth) unregister_netdevice(lapbeth->axdev); } -/* - * Handle device status changes. +/* Handle device status changes. * * Called from notifier with RTNL held. */ @@ -457,13 +452,13 @@ static int lapbeth_device_event(struct notifier_block *this, switch (event) { case NETDEV_UP: /* New ethernet device -> new LAPB interface */ - if (lapbeth_get_x25_dev(dev) == NULL) + if (!lapbeth_get_x25_dev(dev)) lapbeth_new_device(dev); break; case NETDEV_GOING_DOWN: /* ethernet device closes -> close LAPB interface */ lapbeth = lapbeth_get_x25_dev(dev); - if (lapbeth) + if (lapbeth) dev_close(lapbeth->axdev); break; case NETDEV_UNREGISTER: diff --git a/drivers/net/wan/lmc/lmc.h b/drivers/net/wan/lmc/lmc.h index 38961793adad..3bd541c868d5 100644 --- a/drivers/net/wan/lmc/lmc.h +++ b/drivers/net/wan/lmc/lmc.h @@ -9,7 +9,7 @@ */ int lmc_probe(struct net_device * dev); unsigned lmc_mii_readreg(lmc_softc_t * const sc, unsigned - devaddr, unsigned regno); + devaddr, unsigned regno); void lmc_mii_writereg(lmc_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data); void lmc_led_on(lmc_softc_t * const, u32); diff --git a/drivers/net/wan/n2.c b/drivers/net/wan/n2.c index 5bf4463873b1..bdb6dc2409bc 100644 --- a/drivers/net/wan/n2.c +++ b/drivers/net/wan/n2.c @@ -32,9 +32,8 @@ #include <asm/io.h> #include "hd64570.h" - -static const char* version = "SDL RISCom/N2 driver version: 1.15"; -static const char* devname = "RISCom/N2"; +static const char *version = "SDL RISCom/N2 driver version: 1.15"; +static const char *devname = "RISCom/N2"; #undef DEBUG_PKT #define DEBUG_RINGS @@ -64,11 +63,9 @@ static char *hw; /* pointer to hw=xxx command line string */ #define PCR_ENWIN 4 /* Open window */ #define PCR_BUS16 8 /* 16-bit bus */ - /* Memory Base Address Register */ #define N2_BAR 2 - /* Page Scan Register */ #define N2_PSR 4 #define WIN16K 0x00 @@ -78,7 +75,6 @@ static char *hw; /* pointer to hw=xxx command line string */ #define PSR_DMAEN 0x80 #define PSR_PAGEBITS 0x0F - /* Modem Control Reg */ #define N2_MCR 6 #define CLOCK_OUT_PORT1 0x80 @@ -90,7 +86,6 @@ static char *hw; /* pointer to hw=xxx command line string */ #define DTR_PORT1 0x02 #define DTR_PORT0 0x01 - typedef struct port_s { struct net_device *dev; struct card_s *card; @@ -106,9 +101,7 @@ typedef struct port_s { u8 rxs, txs, tmc; /* SCA registers */ u8 phy_node; /* physical port # - 0 or 1 */ u8 log_node; /* logical port # */ -}port_t; - - +} port_t; typedef struct card_s { u8 __iomem *winbase; /* ISA window base address */ @@ -122,13 +115,11 @@ typedef struct card_s { port_t ports[2]; struct card_s *next_card; -}card_t; - +} card_t; static card_t *first_card; static card_t **new_card = &first_card; - #define sca_reg(reg, card) (0x8000 | (card)->io | \ ((reg) & 0x0F) | (((reg) & 0xF0) << 6)) #define sca_in(reg, card) inb(sca_reg(reg, card)) @@ -144,23 +135,20 @@ static card_t **new_card = &first_card; #define get_port(card, port) ((card)->ports[port].valid ? \ &(card)->ports[port] : NULL) - static __inline__ u8 sca_get_page(card_t *card) { return inb(card->io + N2_PSR) & PSR_PAGEBITS; } - static __inline__ void openwin(card_t *card, u8 page) { u8 psr = inb(card->io + N2_PSR); + outb((psr & ~PSR_PAGEBITS) | page, card->io + N2_PSR); } - #include "hd64570.c" - static void n2_set_iface(port_t *port) { card_t *card = port->card; @@ -170,7 +158,7 @@ static void n2_set_iface(port_t *port) u8 rxs = port->rxs & CLK_BRG_MASK; u8 txs = port->txs & CLK_BRG_MASK; - switch(port->settings.clock_type) { + switch (port->settings.clock_type) { case CLOCK_INT: mcr |= port->phy_node ? CLOCK_OUT_PORT1 : CLOCK_OUT_PORT0; rxs |= CLK_BRG_RX; /* BRG output */ @@ -203,13 +191,12 @@ static void n2_set_iface(port_t *port) sca_set_port(port); } - - static int n2_open(struct net_device *dev) { port_t *port = dev_to_port(dev); int io = port->card->io; - u8 mcr = inb(io + N2_MCR) | (port->phy_node ? TX422_PORT1:TX422_PORT0); + u8 mcr = inb(io + N2_MCR) | + (port->phy_node ? TX422_PORT1 : TX422_PORT0); int result; result = hdlc_open(dev); @@ -226,13 +213,12 @@ static int n2_open(struct net_device *dev) return 0; } - - static int n2_close(struct net_device *dev) { port_t *port = dev_to_port(dev); int io = port->card->io; - u8 mcr = inb(io+N2_MCR) | (port->phy_node ? TX422_PORT1 : TX422_PORT0); + u8 mcr = inb(io + N2_MCR) | + (port->phy_node ? TX422_PORT1 : TX422_PORT0); sca_close(dev); mcr |= port->phy_node ? DTR_PORT1 : DTR_PORT0; /* set DTR OFF */ @@ -241,8 +227,6 @@ static int n2_close(struct net_device *dev) return 0; } - - static int n2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { const size_t size = sizeof(sync_serial_settings); @@ -259,7 +243,7 @@ static int n2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) if (cmd != SIOCWANDEV) return hdlc_ioctl(dev, ifr, cmd); - switch(ifr->ifr_settings.type) { + switch (ifr->ifr_settings.type) { case IF_GET_IFACE: ifr->ifr_settings.type = IF_IFACE_SYNC_SERIAL; if (ifr->ifr_settings.size < size) { @@ -271,7 +255,7 @@ static int n2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) return 0; case IF_IFACE_SYNC_SERIAL: - if(!capable(CAP_NET_ADMIN)) + if (!capable(CAP_NET_ADMIN)) return -EPERM; if (copy_from_user(&new_line, line, size)) @@ -295,8 +279,6 @@ static int n2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) } } - - static void n2_destroy_card(card_t *card) { int cnt; @@ -304,6 +286,7 @@ static void n2_destroy_card(card_t *card) for (cnt = 0; cnt < 2; cnt++) if (card->ports[cnt].card) { struct net_device *dev = port_to_dev(&card->ports[cnt]); + unregister_hdlc_device(dev); } @@ -354,7 +337,7 @@ static int __init n2_run(unsigned long io, unsigned long irq, } card = kzalloc(sizeof(card_t), GFP_KERNEL); - if (card == NULL) + if (!card) return -ENOBUFS; card->ports[0].dev = alloc_hdlcdev(&card->ports[0]); @@ -486,11 +469,9 @@ static int __init n2_run(unsigned long io, unsigned long irq, return 0; } - - static int __init n2_init(void) { - if (hw==NULL) { + if (!hw) { #ifdef MODULE pr_info("no card initialized\n"); #endif @@ -515,7 +496,7 @@ static int __init n2_init(void) if (*hw++ != ',') break; - while(1) { + while (1) { if (*hw == '0' && !valid[0]) valid[0] = 1; /* Port 0 enabled */ else if (*hw == '1' && !valid[1]) @@ -533,25 +514,24 @@ static int __init n2_init(void) if (*hw == '\x0') return first_card ? 0 : -EINVAL; - }while(*hw++ == ':'); + } while (*hw++ == ':'); pr_err("invalid hardware parameters\n"); return first_card ? 0 : -EINVAL; } - static void __exit n2_cleanup(void) { card_t *card = first_card; while (card) { card_t *ptr = card; + card = card->next_card; n2_destroy_card(ptr); } } - module_init(n2_init); module_exit(n2_cleanup); diff --git a/drivers/net/wan/pc300too.c b/drivers/net/wan/pc300too.c index 001fd378d417..7b123a771aa6 100644 --- a/drivers/net/wan/pc300too.c +++ b/drivers/net/wan/pc300too.c @@ -44,7 +44,7 @@ #define MAX_TX_BUFFERS 10 static int pci_clock_freq = 33000000; -static int use_crystal_clock = 0; +static int use_crystal_clock; static unsigned int CLOCK_BASE; /* Masks to access the init_ctrl PLX register */ @@ -52,11 +52,9 @@ static unsigned int CLOCK_BASE; #define PC300_CHMEDIA_MASK(port) (0x00000020UL << ((port) * 3)) #define PC300_CTYPE_MASK (0x00000800UL) - enum { PC300_RSV = 1, PC300_X21, PC300_TE }; /* card types */ -/* - * PLX PCI9050-1 local configuration and shared runtime registers. +/* PLX PCI9050-1 local configuration and shared runtime registers. * This structure can be used to access 9050 registers (memory mapped). */ typedef struct { @@ -69,9 +67,7 @@ typedef struct { u32 cs_base[4]; /* 3C-48h : Chip Select Base Addrs */ u32 intr_ctrl_stat; /* 4Ch : Interrupt Control/Status */ u32 init_ctrl; /* 50h : EEPROM ctrl, Init Ctrl, etc */ -}plx9050; - - +} plx9050; typedef struct port_s { struct napi_struct napi; @@ -88,9 +84,7 @@ typedef struct port_s { u16 txlast; u8 rxs, txs, tmc; /* SCA registers */ u8 chan; /* physical port # - 0 or 1 */ -}port_t; - - +} port_t; typedef struct card_s { int type; /* RSV, X21, etc. */ @@ -105,26 +99,24 @@ typedef struct card_s { u8 irq; /* interrupt request level */ port_t ports[2]; -}card_t; - +} card_t; #define get_port(card, port) ((port) < (card)->n_ports ? \ (&(card)->ports[port]) : (NULL)) #include "hd64572.c" - static void pc300_set_iface(port_t *port) { card_t *card = port->card; - u32 __iomem * init_ctrl = &card->plxbase->init_ctrl; + u32 __iomem *init_ctrl = &card->plxbase->init_ctrl; u16 msci = get_msci(port); u8 rxs = port->rxs & CLK_BRG_MASK; u8 txs = port->txs & CLK_BRG_MASK; sca_out(EXS_TES1, (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS, port->card); - switch(port->settings.clock_type) { + switch (port->settings.clock_type) { case CLOCK_INT: rxs |= CLK_BRG; /* BRG output */ txs |= CLK_PIN_OUT | CLK_TX_RXCLK; /* RX clock */ @@ -162,13 +154,11 @@ static void pc300_set_iface(port_t *port) } } - - static int pc300_open(struct net_device *dev) { port_t *port = dev_to_port(dev); - int result = hdlc_open(dev); + if (result) return result; @@ -177,8 +167,6 @@ static int pc300_open(struct net_device *dev) return 0; } - - static int pc300_close(struct net_device *dev) { sca_close(dev); @@ -186,8 +174,6 @@ static int pc300_close(struct net_device *dev) return 0; } - - static int pc300_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { const size_t size = sizeof(sync_serial_settings); @@ -214,7 +200,6 @@ static int pc300_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) if (copy_to_user(line, &port->settings, size)) return -EFAULT; return 0; - } if (port->card->type == PC300_X21 && @@ -255,8 +240,6 @@ static int pc300_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) return 0; } - - static void pc300_pci_remove_one(struct pci_dev *pdev) { int i; @@ -314,7 +297,7 @@ static int pc300_pci_init_one(struct pci_dev *pdev, } card = kzalloc(sizeof(card_t), GFP_KERNEL); - if (card == NULL) { + if (!card) { pci_release_regions(pdev); pci_disable_device(pdev); return -ENOBUFS; @@ -338,9 +321,7 @@ static int pc300_pci_init_one(struct pci_dev *pdev, ramphys = pci_resource_start(pdev, 3) & PCI_BASE_ADDRESS_MEM_MASK; card->rambase = pci_ioremap_bar(pdev, 3); - if (card->plxbase == NULL || - card->scabase == NULL || - card->rambase == NULL) { + if (!card->plxbase || !card->scabase || !card->rambase) { pr_err("ioremap() failed\n"); pc300_pci_remove_one(pdev); return -ENOMEM; @@ -365,12 +346,14 @@ static int pc300_pci_init_one(struct pci_dev *pdev, else card->n_ports = 2; - for (i = 0; i < card->n_ports; i++) - if (!(card->ports[i].netdev = alloc_hdlcdev(&card->ports[i]))) { + for (i = 0; i < card->n_ports; i++) { + card->ports[i].netdev = alloc_hdlcdev(&card->ports[i]); + if (!card->ports[i].netdev) { pr_err("unable to allocate memory\n"); pc300_pci_remove_one(pdev); return -ENOMEM; } + } /* Reset PLX */ p = &card->plxbase->init_ctrl; @@ -442,6 +425,7 @@ static int pc300_pci_init_one(struct pci_dev *pdev, port_t *port = &card->ports[i]; struct net_device *dev = port->netdev; hdlc_device *hdlc = dev_to_hdlc(dev); + port->chan = i; spin_lock_init(&port->lock); @@ -472,8 +456,6 @@ static int pc300_pci_init_one(struct pci_dev *pdev, return 0; } - - static const struct pci_device_id pc300_pci_tbl[] = { { PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_PC300_RX_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, @@ -486,7 +468,6 @@ static const struct pci_device_id pc300_pci_tbl[] = { { 0, } }; - static struct pci_driver pc300_pci_driver = { .name = "PC300", .id_table = pc300_pci_tbl, @@ -494,7 +475,6 @@ static struct pci_driver pc300_pci_driver = { .remove = pc300_pci_remove_one, }; - static int __init pc300_init_module(void) { if (pci_clock_freq < 1000000 || pci_clock_freq > 80000000) { @@ -511,8 +491,6 @@ static int __init pc300_init_module(void) return pci_register_driver(&pc300_pci_driver); } - - static void __exit pc300_cleanup_module(void) { pci_unregister_driver(&pc300_pci_driver); diff --git a/drivers/net/wan/pci200syn.c b/drivers/net/wan/pci200syn.c index ba5cc0c53833..dee9c4e15eca 100644 --- a/drivers/net/wan/pci200syn.c +++ b/drivers/net/wan/pci200syn.c @@ -42,8 +42,7 @@ static int pci_clock_freq = 33000000; #define CLOCK_BASE pci_clock_freq -/* - * PLX PCI9052 local configuration and shared runtime registers. +/* PLX PCI9052 local configuration and shared runtime registers. * This structure can be used to access 9052 registers (memory mapped). */ typedef struct { @@ -56,9 +55,7 @@ typedef struct { u32 cs_base[4]; /* 3C-48h : Chip Select Base Addrs */ u32 intr_ctrl_stat; /* 4Ch : Interrupt Control/Status */ u32 init_ctrl; /* 50h : EEPROM ctrl, Init Ctrl, etc */ -}plx9052; - - +} plx9052; typedef struct port_s { struct napi_struct napi; @@ -74,9 +71,7 @@ typedef struct port_s { u16 txlast; u8 rxs, txs, tmc; /* SCA registers */ u8 chan; /* physical port # - 0 or 1 */ -}port_t; - - +} port_t; typedef struct card_s { u8 __iomem *rambase; /* buffer memory base (virtual) */ @@ -88,15 +83,15 @@ typedef struct card_s { u8 irq; /* interrupt request level */ port_t ports[2]; -}card_t; - +} card_t; -#define get_port(card, port) (&card->ports[port]) +#define get_port(card, port) (&(card)->ports[port]) #define sca_flush(card) (sca_in(IER0, card)) static inline void new_memcpy_toio(char __iomem *dest, char *src, int length) { int len; + do { len = length > 256 ? 256 : length; memcpy_toio(dest, src, len); @@ -112,7 +107,6 @@ static inline void new_memcpy_toio(char __iomem *dest, char *src, int length) #include "hd64572.c" - static void pci200_set_iface(port_t *port) { card_t *card = port->card; @@ -122,7 +116,7 @@ static void pci200_set_iface(port_t *port) sca_out(EXS_TES1, (port->chan ? MSCI1_OFFSET : MSCI0_OFFSET) + EXS, port->card); - switch(port->settings.clock_type) { + switch (port->settings.clock_type) { case CLOCK_INT: rxs |= CLK_BRG; /* BRG output */ txs |= CLK_PIN_OUT | CLK_TX_RXCLK; /* RX clock */ @@ -151,13 +145,11 @@ static void pci200_set_iface(port_t *port) sca_set_port(port); } - - static int pci200_open(struct net_device *dev) { port_t *port = dev_to_port(dev); - int result = hdlc_open(dev); + if (result) return result; @@ -167,8 +159,6 @@ static int pci200_open(struct net_device *dev) return 0; } - - static int pci200_close(struct net_device *dev) { sca_close(dev); @@ -177,8 +167,6 @@ static int pci200_close(struct net_device *dev) return 0; } - - static int pci200_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { const size_t size = sizeof(sync_serial_settings); @@ -195,7 +183,7 @@ static int pci200_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) if (cmd != SIOCWANDEV) return hdlc_ioctl(dev, ifr, cmd); - switch(ifr->ifr_settings.type) { + switch (ifr->ifr_settings.type) { case IF_GET_IFACE: ifr->ifr_settings.type = IF_IFACE_V35; if (ifr->ifr_settings.size < size) { @@ -233,8 +221,6 @@ static int pci200_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) } } - - static void pci200_pci_remove_one(struct pci_dev *pdev) { int i; @@ -292,7 +278,7 @@ static int pci200_pci_init_one(struct pci_dev *pdev, } card = kzalloc(sizeof(card_t), GFP_KERNEL); - if (card == NULL) { + if (!card) { pci_release_regions(pdev); pci_disable_device(pdev); return -ENOBUFS; @@ -314,18 +300,16 @@ static int pci200_pci_init_one(struct pci_dev *pdev, return -EFAULT; } - plxphys = pci_resource_start(pdev,0) & PCI_BASE_ADDRESS_MEM_MASK; + plxphys = pci_resource_start(pdev, 0) & PCI_BASE_ADDRESS_MEM_MASK; card->plxbase = ioremap(plxphys, PCI200SYN_PLX_SIZE); - scaphys = pci_resource_start(pdev,2) & PCI_BASE_ADDRESS_MEM_MASK; + scaphys = pci_resource_start(pdev, 2) & PCI_BASE_ADDRESS_MEM_MASK; card->scabase = ioremap(scaphys, PCI200SYN_SCA_SIZE); - ramphys = pci_resource_start(pdev,3) & PCI_BASE_ADDRESS_MEM_MASK; + ramphys = pci_resource_start(pdev, 3) & PCI_BASE_ADDRESS_MEM_MASK; card->rambase = pci_ioremap_bar(pdev, 3); - if (card->plxbase == NULL || - card->scabase == NULL || - card->rambase == NULL) { + if (!card->plxbase || !card->scabase || !card->rambase) { pr_err("ioremap() failed\n"); pci200_pci_remove_one(pdev); return -EFAULT; @@ -380,6 +364,7 @@ static int pci200_pci_init_one(struct pci_dev *pdev, port_t *port = &card->ports[i]; struct net_device *dev = port->netdev; hdlc_device *hdlc = dev_to_hdlc(dev); + port->chan = i; spin_lock_init(&port->lock); @@ -407,15 +392,12 @@ static int pci200_pci_init_one(struct pci_dev *pdev, return 0; } - - static const struct pci_device_id pci200_pci_tbl[] = { { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_PCI200SYN, 0, 0, 0 }, { 0, } }; - static struct pci_driver pci200_pci_driver = { .name = "PCI200SYN", .id_table = pci200_pci_tbl, @@ -423,7 +405,6 @@ static struct pci_driver pci200_pci_driver = { .remove = pci200_pci_remove_one, }; - static int __init pci200_init_module(void) { if (pci_clock_freq < 1000000 || pci_clock_freq > 80000000) { @@ -433,8 +414,6 @@ static int __init pci200_init_module(void) return pci_register_driver(&pci200_pci_driver); } - - static void __exit pci200_cleanup_module(void) { pci_unregister_driver(&pci200_pci_driver); diff --git a/drivers/net/wan/sealevel.c b/drivers/net/wan/sealevel.c index 7dddc9dcbe23..4403e219ca03 100644 --- a/drivers/net/wan/sealevel.c +++ b/drivers/net/wan/sealevel.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -/* - * Sealevel Systems 4021 driver. +/* Sealevel Systems 4021 driver. * * (c) Copyright 1999, 2001 Alan Cox * (c) Copyright 2001 Red Hat Inc. @@ -29,32 +28,25 @@ #include <asm/byteorder.h> #include "z85230.h" - -struct slvl_device -{ +struct slvl_device { struct z8530_channel *chan; int channel; }; - -struct slvl_board -{ +struct slvl_board { struct slvl_device dev[2]; struct z8530_dev board; int iobase; }; -/* - * Network driver support routines - */ + /* Network driver support routines */ -static inline struct slvl_device* dev_to_chan(struct net_device *dev) +static inline struct slvl_device *dev_to_chan(struct net_device *dev) { return (struct slvl_device *)dev_to_hdlc(dev)->priv; } -/* - * Frame receive. Simple for our card as we do HDLC and there +/* Frame receive. Simple for our card as we do HDLC and there * is no funny garbage involved */ @@ -68,9 +60,7 @@ static void sealevel_input(struct z8530_channel *c, struct sk_buff *skb) netif_rx(skb); } -/* - * We've been placed in the UP state - */ + /* We've been placed in the UP state */ static int sealevel_open(struct net_device *d) { @@ -78,17 +68,15 @@ static int sealevel_open(struct net_device *d) int err = -1; int unit = slvl->channel; - /* - * Link layer up. - */ + /* Link layer up. */ switch (unit) { - case 0: - err = z8530_sync_dma_open(d, slvl->chan); - break; - case 1: - err = z8530_sync_open(d, slvl->chan); - break; + case 0: + err = z8530_sync_dma_open(d, slvl->chan); + break; + case 1: + err = z8530_sync_open(d, slvl->chan); + break; } if (err) @@ -97,21 +85,18 @@ static int sealevel_open(struct net_device *d) err = hdlc_open(d); if (err) { switch (unit) { - case 0: - z8530_sync_dma_close(d, slvl->chan); - break; - case 1: - z8530_sync_close(d, slvl->chan); - break; + case 0: + z8530_sync_dma_close(d, slvl->chan); + break; + case 1: + z8530_sync_close(d, slvl->chan); + break; } return err; } slvl->chan->rx_function = sealevel_input; - /* - * Go go go - */ netif_start_queue(d); return 0; } @@ -121,9 +106,7 @@ static int sealevel_close(struct net_device *d) struct slvl_device *slvl = dev_to_chan(d); int unit = slvl->channel; - /* - * Discard new frames - */ + /* Discard new frames */ slvl->chan->rx_function = z8530_null_rx; @@ -131,12 +114,12 @@ static int sealevel_close(struct net_device *d) netif_stop_queue(d); switch (unit) { - case 0: - z8530_sync_dma_close(d, slvl->chan); - break; - case 1: - z8530_sync_close(d, slvl->chan); - break; + case 0: + z8530_sync_dma_close(d, slvl->chan); + break; + case 1: + z8530_sync_close(d, slvl->chan); + break; } return 0; } @@ -144,16 +127,15 @@ static int sealevel_close(struct net_device *d) static int sealevel_ioctl(struct net_device *d, struct ifreq *ifr, int cmd) { /* struct slvl_device *slvl=dev_to_chan(d); - z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) */ + * z8530_ioctl(d,&slvl->sync.chanA,ifr,cmd) + */ return hdlc_ioctl(d, ifr, cmd); } -/* - * Passed network frames, fire them downwind. - */ +/* Passed network frames, fire them downwind. */ static netdev_tx_t sealevel_queue_xmit(struct sk_buff *skb, - struct net_device *d) + struct net_device *d) { return z8530_queue_xmit(dev_to_chan(d)->chan, skb); } @@ -176,6 +158,7 @@ static const struct net_device_ops sealevel_ops = { static int slvl_setup(struct slvl_device *sv, int iobase, int irq) { struct net_device *dev = alloc_hdlcdev(sv); + if (!dev) return -1; @@ -195,10 +178,7 @@ static int slvl_setup(struct slvl_device *sv, int iobase, int irq) return 0; } - -/* - * Allocate and setup Sealevel board. - */ +/* Allocate and setup Sealevel board. */ static __init struct slvl_board *slvl_init(int iobase, int irq, int txdma, int rxdma, int slow) @@ -206,9 +186,7 @@ static __init struct slvl_board *slvl_init(int iobase, int irq, struct z8530_dev *dev; struct slvl_board *b; - /* - * Get the needed I/O space - */ + /* Get the needed I/O space */ if (!request_region(iobase, 8, "Sealevel 4021")) { pr_warn("I/O 0x%X already in use\n", iobase); @@ -227,17 +205,13 @@ static __init struct slvl_board *slvl_init(int iobase, int irq, dev = &b->board; - /* - * Stuff in the I/O addressing - */ + /* Stuff in the I/O addressing */ dev->active = 0; b->iobase = iobase; - /* - * Select 8530 delays for the old board - */ + /* Select 8530 delays for the old board */ if (slow) iobase |= Z8530_PORT_SLEEP; @@ -250,15 +224,13 @@ static __init struct slvl_board *slvl_init(int iobase, int irq, dev->chanA.irqs = &z8530_nop; dev->chanB.irqs = &z8530_nop; - /* - * Assert DTR enable DMA - */ + /* Assert DTR enable DMA */ outb(3 | (1 << 7), b->iobase + 4); - /* We want a fast IRQ for this device. Actually we'd like an even faster - IRQ ;) - This is one driver RtLinux is made for */ + * IRQ ;) - This is one driver RtLinux is made for + */ if (request_irq(irq, z8530_interrupt, 0, "SeaLevel", dev) < 0) { @@ -282,9 +254,7 @@ static __init struct slvl_board *slvl_init(int iobase, int irq, disable_irq(irq); - /* - * Begin normal initialise - */ + /* Begin normal initialise */ if (z8530_init(dev) != 0) { pr_err("Z8530 series device not found\n"); @@ -299,9 +269,7 @@ static __init struct slvl_board *slvl_init(int iobase, int irq, z8530_channel_load(&dev->chanB, z8530_hdlc_kilostream_85230); } - /* - * Now we can take the IRQ - */ + /* Now we can take the IRQ */ enable_irq(irq); @@ -338,6 +306,7 @@ static void __exit slvl_shutdown(struct slvl_board *b) for (u = 0; u < 2; u++) { struct net_device *d = b->dev[u].chan->netdevice; + unregister_hdlc_device(d); free_netdev(d); } @@ -351,12 +320,11 @@ static void __exit slvl_shutdown(struct slvl_board *b) kfree(b); } - -static int io=0x238; -static int txdma=1; -static int rxdma=3; -static int irq=5; -static bool slow=false; +static int io = 0x238; +static int txdma = 1; +static int rxdma = 3; +static int irq = 5; +static bool slow; module_param_hw(io, int, ioport, 0); MODULE_PARM_DESC(io, "The I/O base of the Sealevel card"); diff --git a/drivers/net/wan/wanxl.c b/drivers/net/wan/wanxl.c index a83133388de9..f22e48415e6f 100644 --- a/drivers/net/wan/wanxl.c +++ b/drivers/net/wan/wanxl.c @@ -32,7 +32,7 @@ #include "wanxl.h" -static const char* version = "wanXL serial card driver version: 0.48"; +static const char *version = "wanXL serial card driver version: 0.48"; #define PLX_CTL_RESET 0x40000000 /* adapter reset */ @@ -50,24 +50,21 @@ static const char* version = "wanXL serial card driver version: 0.48"; /* MAILBOX #2 - DRAM SIZE */ #define MBX2_MEMSZ_MASK 0xFFFF0000 /* PUTS Memory Size Register mask */ - struct port { struct net_device *dev; struct card *card; spinlock_t lock; /* for wanxl_xmit */ - int node; /* physical port #0 - 3 */ + int node; /* physical port #0 - 3 */ unsigned int clock_type; int tx_in, tx_out; struct sk_buff *tx_skbs[TX_BUFFERS]; }; - struct card_status { desc_t rx_descs[RX_QUEUE_LENGTH]; port_status_t port_status[4]; }; - struct card { int n_ports; /* 1, 2 or 4 ports */ u8 irq; @@ -81,25 +78,22 @@ struct card { struct port ports[]; /* 1 - 4 port structures follow */ }; - - static inline struct port *dev_to_port(struct net_device *dev) { return (struct port *)dev_to_hdlc(dev)->priv; } - static inline port_status_t *get_status(struct port *port) { return &port->card->status->port_status[port->node]; } - #ifdef DEBUG_PCI static inline dma_addr_t pci_map_single_debug(struct pci_dev *pdev, void *ptr, size_t size, int direction) { dma_addr_t addr = dma_map_single(&pdev->dev, ptr, size, direction); + if (addr + size > 0x100000000LL) pr_crit("%s: pci_map_single() returned memory at 0x%llx!\n", pci_name(pdev), (unsigned long long)addr); @@ -110,7 +104,6 @@ static inline dma_addr_t pci_map_single_debug(struct pci_dev *pdev, void *ptr, #define pci_map_single pci_map_single_debug #endif - /* Cable and/or personality module change interrupt service */ static inline void wanxl_cable_intr(struct port *port) { @@ -118,22 +111,46 @@ static inline void wanxl_cable_intr(struct port *port) int valid = 1; const char *cable, *pm, *dte = "", *dsr = "", *dcd = ""; - switch(value & 0x7) { - case STATUS_CABLE_V35: cable = "V.35"; break; - case STATUS_CABLE_X21: cable = "X.21"; break; - case STATUS_CABLE_V24: cable = "V.24"; break; - case STATUS_CABLE_EIA530: cable = "EIA530"; break; - case STATUS_CABLE_NONE: cable = "no"; break; - default: cable = "invalid"; + switch (value & 0x7) { + case STATUS_CABLE_V35: + cable = "V.35"; + break; + case STATUS_CABLE_X21: + cable = "X.21"; + break; + case STATUS_CABLE_V24: + cable = "V.24"; + break; + case STATUS_CABLE_EIA530: + cable = "EIA530"; + break; + case STATUS_CABLE_NONE: + cable = "no"; + break; + default: + cable = "invalid"; } - switch((value >> STATUS_CABLE_PM_SHIFT) & 0x7) { - case STATUS_CABLE_V35: pm = "V.35"; break; - case STATUS_CABLE_X21: pm = "X.21"; break; - case STATUS_CABLE_V24: pm = "V.24"; break; - case STATUS_CABLE_EIA530: pm = "EIA530"; break; - case STATUS_CABLE_NONE: pm = "no personality"; valid = 0; break; - default: pm = "invalid personality"; valid = 0; + switch ((value >> STATUS_CABLE_PM_SHIFT) & 0x7) { + case STATUS_CABLE_V35: + pm = "V.35"; + break; + case STATUS_CABLE_X21: + pm = "X.21"; + break; + case STATUS_CABLE_V24: + pm = "V.24"; + break; + case STATUS_CABLE_EIA530: + pm = "EIA530"; + break; + case STATUS_CABLE_NONE: + pm = "no personality"; + valid = 0; + break; + default: + pm = "invalid personality"; + valid = 0; } if (valid) { @@ -154,14 +171,13 @@ static inline void wanxl_cable_intr(struct port *port) netif_carrier_off(port->dev); } - - /* Transmit complete interrupt service */ static inline void wanxl_tx_intr(struct port *port) { struct net_device *dev = port->dev; + while (1) { - desc_t *desc = &get_status(port)->tx_descs[port->tx_in]; + desc_t *desc = &get_status(port)->tx_descs[port->tx_in]; struct sk_buff *skb = port->tx_skbs[port->tx_in]; switch (desc->stat) { @@ -179,34 +195,33 @@ static inline void wanxl_tx_intr(struct port *port) dev->stats.tx_packets++; dev->stats.tx_bytes += skb->len; } - desc->stat = PACKET_EMPTY; /* Free descriptor */ + desc->stat = PACKET_EMPTY; /* Free descriptor */ dma_unmap_single(&port->card->pdev->dev, desc->address, skb->len, DMA_TO_DEVICE); dev_consume_skb_irq(skb); - port->tx_in = (port->tx_in + 1) % TX_BUFFERS; - } + port->tx_in = (port->tx_in + 1) % TX_BUFFERS; + } } - - /* Receive complete interrupt service */ static inline void wanxl_rx_intr(struct card *card) { desc_t *desc; + while (desc = &card->status->rx_descs[card->rx_in], desc->stat != PACKET_EMPTY) { - if ((desc->stat & PACKET_PORT_MASK) > card->n_ports) + if ((desc->stat & PACKET_PORT_MASK) > card->n_ports) { pr_crit("%s: received packet for nonexistent port\n", pci_name(card->pdev)); - else { + } else { struct sk_buff *skb = card->rx_skbs[card->rx_in]; struct port *port = &card->ports[desc->stat & PACKET_PORT_MASK]; struct net_device *dev = port->dev; - if (!skb) + if (!skb) { dev->stats.rx_dropped++; - else { + } else { dma_unmap_single(&card->pdev->dev, desc->address, BUFFER_LENGTH, DMA_FROM_DEVICE); @@ -239,21 +254,18 @@ static inline void wanxl_rx_intr(struct card *card) } } - - -static irqreturn_t wanxl_intr(int irq, void* dev_id) +static irqreturn_t wanxl_intr(int irq, void *dev_id) { struct card *card = dev_id; - int i; - u32 stat; - int handled = 0; - + int i; + u32 stat; + int handled = 0; - while((stat = readl(card->plx + PLX_DOORBELL_FROM_CARD)) != 0) { - handled = 1; + while ((stat = readl(card->plx + PLX_DOORBELL_FROM_CARD)) != 0) { + handled = 1; writel(stat, card->plx + PLX_DOORBELL_FROM_CARD); - for (i = 0; i < card->n_ports; i++) { + for (i = 0; i < card->n_ports; i++) { if (stat & (1 << (DOORBELL_FROM_CARD_TX_0 + i))) wanxl_tx_intr(&card->ports[i]); if (stat & (1 << (DOORBELL_FROM_CARD_CABLE_0 + i))) @@ -261,23 +273,21 @@ static irqreturn_t wanxl_intr(int irq, void* dev_id) } if (stat & (1 << DOORBELL_FROM_CARD_RX)) wanxl_rx_intr(card); - } + } - return IRQ_RETVAL(handled); + return IRQ_RETVAL(handled); } - - static netdev_tx_t wanxl_xmit(struct sk_buff *skb, struct net_device *dev) { struct port *port = dev_to_port(dev); desc_t *desc; - spin_lock(&port->lock); + spin_lock(&port->lock); desc = &get_status(port)->tx_descs[port->tx_out]; - if (desc->stat != PACKET_EMPTY) { - /* should never happen - previous xmit should stop queue */ + if (desc->stat != PACKET_EMPTY) { + /* should never happen - previous xmit should stop queue */ #ifdef DEBUG_PKT printk(KERN_DEBUG "%s: transmitter buffer full\n", dev->name); #endif @@ -312,8 +322,6 @@ static netdev_tx_t wanxl_xmit(struct sk_buff *skb, struct net_device *dev) return NETDEV_TX_OK; } - - static int wanxl_attach(struct net_device *dev, unsigned short encoding, unsigned short parity) { @@ -335,8 +343,6 @@ static int wanxl_attach(struct net_device *dev, unsigned short encoding, return 0; } - - static int wanxl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { const size_t size = sizeof(sync_serial_settings); @@ -384,11 +390,9 @@ static int wanxl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) default: return hdlc_ioctl(dev, ifr, cmd); - } + } } - - static int wanxl_open(struct net_device *dev) { struct port *port = dev_to_port(dev); @@ -400,7 +404,9 @@ static int wanxl_open(struct net_device *dev) netdev_err(dev, "port already open\n"); return -EIO; } - if ((i = hdlc_open(dev)) != 0) + + i = hdlc_open(dev); + if (i) return i; port->tx_in = port->tx_out = 0; @@ -423,8 +429,6 @@ static int wanxl_open(struct net_device *dev) return -EFAULT; } - - static int wanxl_close(struct net_device *dev) { struct port *port = dev_to_port(dev); @@ -461,8 +465,6 @@ static int wanxl_close(struct net_device *dev) return 0; } - - static struct net_device_stats *wanxl_get_stats(struct net_device *dev) { struct port *port = dev_to_port(dev); @@ -474,8 +476,6 @@ static struct net_device_stats *wanxl_get_stats(struct net_device *dev) return &dev->stats; } - - static int wanxl_puts_command(struct card *card, u32 cmd) { unsigned long timeout = jiffies + 5 * HZ; @@ -486,13 +486,11 @@ static int wanxl_puts_command(struct card *card, u32 cmd) return 0; schedule(); - }while (time_after(timeout, jiffies)); + } while (time_after(timeout, jiffies)); return -1; } - - static void wanxl_reset(struct card *card) { u32 old_value = readl(card->plx + PLX_CONTROL) & ~PLX_CTL_RESET; @@ -505,8 +503,6 @@ static void wanxl_reset(struct card *card) readl(card->plx + PLX_CONTROL); /* wait for posted write */ } - - static void wanxl_pci_remove_one(struct pci_dev *pdev) { struct card *card = pci_get_drvdata(pdev); @@ -543,7 +539,6 @@ static void wanxl_pci_remove_one(struct pci_dev *pdev) kfree(card); } - #include "wanxlfw.inc" static const struct net_device_ops wanxl_ops = { @@ -574,12 +569,14 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, return i; /* QUICC can only access first 256 MB of host RAM directly, - but PLX9060 DMA does 32-bits for actual packet data transfers */ + * but PLX9060 DMA does 32-bits for actual packet data transfers + */ /* FIXME when PCI/DMA subsystems are fixed. - We set both dma_mask and consistent_dma_mask to 28 bits - and pray pci_alloc_consistent() will use this info. It should - work on most platforms */ + * We set both dma_mask and consistent_dma_mask to 28 bits + * and pray pci_alloc_consistent() will use this info. It should + * work on most platforms + */ if (dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(28)) || dma_set_mask(&pdev->dev, DMA_BIT_MASK(28))) { pr_err("No usable DMA configuration\n"); @@ -594,13 +591,18 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, } switch (pdev->device) { - case PCI_DEVICE_ID_SBE_WANXL100: ports = 1; break; - case PCI_DEVICE_ID_SBE_WANXL200: ports = 2; break; - default: ports = 4; + case PCI_DEVICE_ID_SBE_WANXL100: + ports = 1; + break; + case PCI_DEVICE_ID_SBE_WANXL200: + ports = 2; + break; + default: + ports = 4; } card = kzalloc(struct_size(card, ports, ports), GFP_KERNEL); - if (card == NULL) { + if (!card) { pci_release_regions(pdev); pci_disable_device(pdev); return -ENOBUFS; @@ -612,7 +614,7 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, card->status = dma_alloc_coherent(&pdev->dev, sizeof(struct card_status), &card->status_address, GFP_KERNEL); - if (card->status == NULL) { + if (!card->status) { wanxl_pci_remove_one(pdev); return -ENOBUFS; } @@ -624,8 +626,9 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, #endif /* FIXME when PCI/DMA subsystems are fixed. - We set both dma_mask and consistent_dma_mask back to 32 bits - to indicate the card can do 32-bit DMA addressing */ + * We set both dma_mask and consistent_dma_mask back to 32 bits + * to indicate the card can do 32-bit DMA addressing + */ if (dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)) || dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) { pr_err("No usable DMA configuration\n"); @@ -639,7 +642,7 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, card->plx = ioremap(plx_phy, 0x70); if (!card->plx) { pr_err("ioremap() failed\n"); - wanxl_pci_remove_one(pdev); + wanxl_pci_remove_one(pdev); return -EFAULT; } @@ -656,7 +659,7 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, return -ENODEV; } - switch(stat & 0xC0) { + switch (stat & 0xC0) { case 0x00: /* hmm - PUTS completed with non-zero code? */ case 0x80: /* PUTS still testing the hardware */ break; @@ -677,7 +680,6 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, /* set up on-board RAM mapping */ mem_phy = pci_resource_start(pdev, 2); - /* sanity check the board's reported memory size */ if (ramsize < BUFFERS_ADDR + (TX_BUFFERS + RX_BUFFERS) * BUFFER_LENGTH * ports) { @@ -697,6 +699,7 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, for (i = 0; i < RX_QUEUE_LENGTH; i++) { struct sk_buff *skb = dev_alloc_skb(BUFFER_LENGTH); + card->rx_skbs[i] = skb; if (skb) card->status->rx_descs[i].address = @@ -707,12 +710,12 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, mem = ioremap(mem_phy, PDM_OFFSET + sizeof(firmware)); if (!mem) { pr_err("ioremap() failed\n"); - wanxl_pci_remove_one(pdev); + wanxl_pci_remove_one(pdev); return -EFAULT; } for (i = 0; i < sizeof(firmware); i += 4) - writel(ntohl(*(__be32*)(firmware + i)), mem + PDM_OFFSET + i); + writel(ntohl(*(__be32 *)(firmware + i)), mem + PDM_OFFSET + i); for (i = 0; i < ports; i++) writel(card->status_address + @@ -732,10 +735,11 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, timeout = jiffies + 5 * HZ; do { - if ((stat = readl(card->plx + PLX_MAILBOX_5)) != 0) + stat = readl(card->plx + PLX_MAILBOX_5); + if (stat) break; schedule(); - }while (time_after(timeout, jiffies)); + } while (time_after(timeout, jiffies)); if (!stat) { pr_warn("%s: timeout while initializing card firmware\n", @@ -764,6 +768,7 @@ static int wanxl_pci_init_one(struct pci_dev *pdev, hdlc_device *hdlc; struct port *port = &card->ports[i]; struct net_device *dev = alloc_hdlcdev(port); + if (!dev) { pr_err("%s: unable to allocate memory\n", pci_name(pdev)); @@ -813,7 +818,6 @@ static const struct pci_device_id wanxl_pci_tbl[] = { { 0, } }; - static struct pci_driver wanxl_pci_driver = { .name = "wanXL", .id_table = wanxl_pci_tbl, @@ -821,7 +825,6 @@ static struct pci_driver wanxl_pci_driver = { .remove = wanxl_pci_remove_one, }; - static int __init wanxl_init_module(void) { #ifdef MODULE @@ -835,7 +838,6 @@ static void __exit wanxl_cleanup_module(void) pci_unregister_driver(&wanxl_pci_driver); } - MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>"); MODULE_DESCRIPTION("SBE Inc. wanXL serial port driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c index 138930c66ad2..982a03488a00 100644 --- a/drivers/net/wan/z85230.c +++ b/drivers/net/wan/z85230.c @@ -1,7 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -/* - * - * (c) Copyright 1998 Alan Cox <alan@lxorguk.ukuu.org.uk> +/* (c) Copyright 1998 Alan Cox <alan@lxorguk.ukuu.org.uk> * (c) Copyright 2000, 2001 Red Hat Inc * * Development of this driver was funded by Equiinet Ltd @@ -12,7 +10,7 @@ * Asynchronous mode dropped for 2.2. For 2.5 we will attempt the * unification of all the Z85x30 asynchronous drivers for real. * - * DMA now uses get_free_page as kmalloc buffers may span a 64K + * DMA now uses get_free_page as kmalloc buffers may span a 64K * boundary. * * Modified for SMP safety and SMP locking by Alan Cox @@ -55,14 +53,13 @@ #include "z85230.h" - /** * z8530_read_port - Architecture specific interface function * @p: port to read * * Provided port access methods. The Comtrol SV11 requires no delays * between accesses and uses PC I/O. Some drivers may need a 5uS delay - * + * * In the longer term this should become an architecture specific * section so that this can become a generic driver interface for all * platforms. For now we only handle PC I/O ports with or without the @@ -74,8 +71,9 @@ static inline int z8530_read_port(unsigned long p) { - u8 r=inb(Z8530_PORT_OF(p)); - if(p&Z8530_PORT_SLEEP) /* gcc should figure this out efficiently ! */ + u8 r = inb(Z8530_PORT_OF(p)); + + if (p & Z8530_PORT_SLEEP) /* gcc should figure this out efficiently ! */ udelay(5); return r; } @@ -95,34 +93,30 @@ static inline int z8530_read_port(unsigned long p) * dread 5uS sanity delay. */ - static inline void z8530_write_port(unsigned long p, u8 d) { - outb(d,Z8530_PORT_OF(p)); - if(p&Z8530_PORT_SLEEP) + outb(d, Z8530_PORT_OF(p)); + if (p & Z8530_PORT_SLEEP) udelay(5); } - - static void z8530_rx_done(struct z8530_channel *c); static void z8530_tx_done(struct z8530_channel *c); - /** - * read_zsreg - Read a register from a Z85230 + * read_zsreg - Read a register from a Z85230 * @c: Z8530 channel to read from (2 per chip) * @reg: Register to read * FIXME: Use a spinlock. - * + * * Most of the Z8530 registers are indexed off the control registers. * A read is done by writing to the control register and reading the * register back. The caller must hold the lock */ - + static inline u8 read_zsreg(struct z8530_channel *c, u8 reg) { - if(reg) + if (reg) z8530_write_port(c->ctrlio, reg); return z8530_read_port(c->ctrlio); } @@ -138,7 +132,8 @@ static inline u8 read_zsreg(struct z8530_channel *c, u8 reg) static inline u8 read_zsdata(struct z8530_channel *c) { u8 r; - r=z8530_read_port(c->dataio); + + r = z8530_read_port(c->dataio); return r; } @@ -156,10 +151,9 @@ static inline u8 read_zsdata(struct z8530_channel *c) */ static inline void write_zsreg(struct z8530_channel *c, u8 reg, u8 val) { - if(reg) + if (reg) z8530_write_port(c->ctrlio, reg); z8530_write_port(c->ctrlio, val); - } /** @@ -182,108 +176,94 @@ static inline void write_zsctrl(struct z8530_channel *c, u8 val) * * Write directly to the data register on the Z8530 */ - - static inline void write_zsdata(struct z8530_channel *c, u8 val) { z8530_write_port(c->dataio, val); } -/* - * Register loading parameters for a dead port +/* Register loading parameters for a dead port */ - -u8 z8530_dead_port[]= -{ + +u8 z8530_dead_port[] = { 255 }; - EXPORT_SYMBOL(z8530_dead_port); -/* - * Register loading parameters for currently supported circuit types +/* Register loading parameters for currently supported circuit types */ - -/* - * Data clocked by telco end. This is the correct data for the UK +/* Data clocked by telco end. This is the correct data for the UK * "kilostream" service, and most other similar services. */ - -u8 z8530_hdlc_kilostream[]= -{ - 4, SYNC_ENAB|SDLC|X1CLK, + +u8 z8530_hdlc_kilostream[] = { + 4, SYNC_ENAB | SDLC | X1CLK, 2, 0, /* No vector */ 1, 0, - 3, ENT_HM|RxCRC_ENAB|Rx8, - 5, TxCRC_ENAB|RTS|TxENAB|Tx8|DTR, + 3, ENT_HM | RxCRC_ENAB | Rx8, + 5, TxCRC_ENAB | RTS | TxENAB | Tx8 | DTR, 9, 0, /* Disable interrupts */ 6, 0xFF, 7, FLAG, - 10, ABUNDER|NRZ|CRCPS,/*MARKIDLE ??*/ + 10, ABUNDER | NRZ | CRCPS,/*MARKIDLE ??*/ 11, TCTRxCP, 14, DISDPLL, - 15, DCDIE|SYNCIE|CTSIE|TxUIE|BRKIE, - 1, EXT_INT_ENAB|TxINT_ENAB|INT_ALL_Rx, - 9, NV|MIE|NORESET, + 15, DCDIE | SYNCIE | CTSIE | TxUIE | BRKIE, + 1, EXT_INT_ENAB | TxINT_ENAB | INT_ALL_Rx, + 9, NV | MIE | NORESET, 255 }; - EXPORT_SYMBOL(z8530_hdlc_kilostream); -/* - * As above but for enhanced chips. +/* As above but for enhanced chips. */ - -u8 z8530_hdlc_kilostream_85230[]= -{ - 4, SYNC_ENAB|SDLC|X1CLK, + +u8 z8530_hdlc_kilostream_85230[] = { + 4, SYNC_ENAB | SDLC | X1CLK, 2, 0, /* No vector */ 1, 0, - 3, ENT_HM|RxCRC_ENAB|Rx8, - 5, TxCRC_ENAB|RTS|TxENAB|Tx8|DTR, + 3, ENT_HM | RxCRC_ENAB | Rx8, + 5, TxCRC_ENAB | RTS | TxENAB | Tx8 | DTR, 9, 0, /* Disable interrupts */ 6, 0xFF, 7, FLAG, - 10, ABUNDER|NRZ|CRCPS, /* MARKIDLE?? */ + 10, ABUNDER | NRZ | CRCPS, /* MARKIDLE?? */ 11, TCTRxCP, 14, DISDPLL, - 15, DCDIE|SYNCIE|CTSIE|TxUIE|BRKIE, - 1, EXT_INT_ENAB|TxINT_ENAB|INT_ALL_Rx, - 9, NV|MIE|NORESET, + 15, DCDIE | SYNCIE | CTSIE | TxUIE | BRKIE, + 1, EXT_INT_ENAB | TxINT_ENAB | INT_ALL_Rx, + 9, NV | MIE | NORESET, 23, 3, /* Extended mode AUTO TX and EOM*/ - + 255 }; - EXPORT_SYMBOL(z8530_hdlc_kilostream_85230); /** * z8530_flush_fifo - Flush on chip RX FIFO * @c: Channel to flush * - * Flush the receive FIFO. There is no specific option for this, we + * Flush the receive FIFO. There is no specific option for this, we * blindly read bytes and discard them. Reading when there is no data * is harmless. The 8530 has a 4 byte FIFO, the 85230 has 8 bytes. - * + * * All locking is handled for the caller. On return data may still be * present if it arrived during the flush. */ - + static void z8530_flush_fifo(struct z8530_channel *c) { read_zsreg(c, R1); read_zsreg(c, R1); read_zsreg(c, R1); read_zsreg(c, R1); - if(c->dev->type==Z85230) - { + if (c->dev->type == Z85230) { read_zsreg(c, R1); read_zsreg(c, R1); read_zsreg(c, R1); read_zsreg(c, R1); } -} +} /** * z8530_rtsdtr - Control the outgoing DTS/RTS line @@ -309,7 +289,7 @@ static void z8530_rtsdtr(struct z8530_channel *c, int set) * z8530_rx - Handle a PIO receive event * @c: Z8530 channel to process * - * Receive handler for receiving in PIO mode. This is much like the + * Receive handler for receiving in PIO mode. This is much like the * async one but not quite the same or as complex * * Note: Its intended that this handler can easily be separated from @@ -322,77 +302,63 @@ static void z8530_rtsdtr(struct z8530_channel *c, int set) * other code - this is true in the RT case too. * * We only cover the sync cases for this. If you want 2Mbit async - * do it yourself but consider medical assistance first. This non DMA - * synchronous mode is portable code. The DMA mode assumes PCI like + * do it yourself but consider medical assistance first. This non DMA + * synchronous mode is portable code. The DMA mode assumes PCI like * ISA DMA * * Called with the device lock held */ - + static void z8530_rx(struct z8530_channel *c) { - u8 ch,stat; + u8 ch, stat; - while(1) - { + while (1) { /* FIFO empty ? */ - if(!(read_zsreg(c, R0)&1)) + if (!(read_zsreg(c, R0) & 1)) break; - ch=read_zsdata(c); - stat=read_zsreg(c, R1); - - /* - * Overrun ? + ch = read_zsdata(c); + stat = read_zsreg(c, R1); + + /* Overrun ? */ - if(c->count < c->max) - { - *c->dptr++=ch; + if (c->count < c->max) { + *c->dptr++ = ch; c->count++; } - if(stat&END_FR) - { - - /* - * Error ? + if (stat & END_FR) { + /* Error ? */ - if(stat&(Rx_OVR|CRC_ERR)) - { + if (stat & (Rx_OVR | CRC_ERR)) { /* Rewind the buffer and return */ - if(c->skb) - c->dptr=c->skb->data; - c->count=0; - if(stat&Rx_OVR) - { + if (c->skb) + c->dptr = c->skb->data; + c->count = 0; + if (stat & Rx_OVR) { pr_warn("%s: overrun\n", c->dev->name); c->rx_overrun++; } - if(stat&CRC_ERR) - { + if (stat & CRC_ERR) { c->rx_crc_err++; /* printk("crc error\n"); */ } /* Shove the frame upstream */ - } - else - { - /* - * Drop the lock for RX processing, or - * there are deadlocks - */ + } else { + /* Drop the lock for RX processing, or + * there are deadlocks + */ z8530_rx_done(c); write_zsctrl(c, RES_Rx_CRC); } } } - /* - * Clear irq + /* Clear irq */ write_zsctrl(c, ERR_RES); write_zsctrl(c, RES_H_IUS); } - /** * z8530_tx - Handle a PIO transmit event * @c: Z8530 channel to process @@ -402,35 +368,31 @@ static void z8530_rx(struct z8530_channel *c) * in as possible, its quite possible that we won't keep up with the * data rate otherwise. */ - + static void z8530_tx(struct z8530_channel *c) { - while(c->txcount) { + while (c->txcount) { /* FIFO full ? */ - if(!(read_zsreg(c, R0)&4)) + if (!(read_zsreg(c, R0) & 4)) return; c->txcount--; - /* - * Shovel out the byte + /* Shovel out the byte */ write_zsreg(c, R8, *c->tx_ptr++); write_zsctrl(c, RES_H_IUS); /* We are about to underflow */ - if(c->txcount==0) - { + if (c->txcount == 0) { write_zsctrl(c, RES_EOM_L); - write_zsreg(c, R10, c->regs[10]&~ABUNDER); + write_zsreg(c, R10, c->regs[10] & ~ABUNDER); } } - - /* - * End of frame TX - fire another one + /* End of frame TX - fire another one */ - + write_zsctrl(c, RES_Tx_P); - z8530_tx_done(c); + z8530_tx_done(c); write_zsctrl(c, RES_H_IUS); } @@ -460,8 +422,7 @@ static void z8530_status(struct z8530_channel *chan) z8530_tx_done(chan); } - if (altered & chan->dcdcheck) - { + if (altered & chan->dcdcheck) { if (status & chan->dcdcheck) { pr_info("%s: DCD raised\n", chan->dev->name); write_zsreg(chan, R3, chan->regs[3] | RxENABLE); @@ -474,7 +435,6 @@ static void z8530_status(struct z8530_channel *chan) if (chan->netdevice) netif_carrier_off(chan->netdevice); } - } write_zsctrl(chan, RES_EXT_INT); write_zsctrl(chan, RES_H_IUS); @@ -485,7 +445,6 @@ struct z8530_irqhandler z8530_sync = { .tx = z8530_tx, .status = z8530_status, }; - EXPORT_SYMBOL(z8530_sync); /** @@ -497,31 +456,27 @@ EXPORT_SYMBOL(z8530_sync); * events are handled by the DMA hardware. We get a kick here only if * a frame ended. */ - + static void z8530_dma_rx(struct z8530_channel *chan) { - if(chan->rxdma_on) - { + if (chan->rxdma_on) { /* Special condition check only */ u8 status; - + read_zsreg(chan, R7); read_zsreg(chan, R6); - - status=read_zsreg(chan, R1); - - if(status&END_FR) - { + + status = read_zsreg(chan, R1); + + if (status & END_FR) z8530_rx_done(chan); /* Fire up the next one */ - } + write_zsctrl(chan, ERR_RES); write_zsctrl(chan, RES_H_IUS); - } - else - { + } else { /* DMA is off right now, drain the slow way */ z8530_rx(chan); - } + } } /** @@ -531,11 +486,9 @@ static void z8530_dma_rx(struct z8530_channel *chan) * We have received an interrupt while doing DMA transmissions. It * shouldn't happen. Scream loudly if it does. */ - static void z8530_dma_tx(struct z8530_channel *chan) { - if(!chan->dma_tx) - { + if (!chan->dma_tx) { pr_warn("Hey who turned the DMA off?\n"); z8530_tx(chan); return; @@ -548,40 +501,35 @@ static void z8530_dma_tx(struct z8530_channel *chan) /** * z8530_dma_status - Handle a DMA status exception * @chan: Z8530 channel to process - * + * * A status event occurred on the Z8530. We receive these for two reasons * when in DMA mode. Firstly if we finished a packet transfer we get one * and kick the next packet out. Secondly we may see a DCD change. * */ - static void z8530_dma_status(struct z8530_channel *chan) { u8 status, altered; - status=read_zsreg(chan, R0); - altered=chan->status^status; - - chan->status=status; + status = read_zsreg(chan, R0); + altered = chan->status ^ status; + chan->status = status; - if(chan->dma_tx) - { - if(status&TxEOM) - { + if (chan->dma_tx) { + if (status & TxEOM) { unsigned long flags; - - flags=claim_dma_lock(); + + flags = claim_dma_lock(); disable_dma(chan->txdma); - clear_dma_ff(chan->txdma); - chan->txdma_on=0; + clear_dma_ff(chan->txdma); + chan->txdma_on = 0; release_dma_lock(flags); z8530_tx_done(chan); } } - if (altered & chan->dcdcheck) - { + if (altered & chan->dcdcheck) { if (status & chan->dcdcheck) { pr_info("%s: DCD raised\n", chan->dev->name); write_zsreg(chan, R3, chan->regs[3] | RxENABLE); @@ -621,21 +569,18 @@ static struct z8530_irqhandler z8530_txdma_sync = { * (eg the MacII) we must clear the interrupt cause or die. */ - static void z8530_rx_clear(struct z8530_channel *c) { - /* - * Data and status bytes + /* Data and status bytes */ u8 stat; read_zsdata(c); - stat=read_zsreg(c, R1); - - if(stat&END_FR) + stat = read_zsreg(c, R1); + + if (stat & END_FR) write_zsctrl(c, RES_Rx_CRC); - /* - * Clear irq + /* Clear irq */ write_zsctrl(c, ERR_RES); write_zsctrl(c, RES_H_IUS); @@ -667,8 +612,9 @@ static void z8530_tx_clear(struct z8530_channel *c) static void z8530_status_clear(struct z8530_channel *chan) { - u8 status=read_zsreg(chan, R0); - if(status&TxEOM) + u8 status = read_zsreg(chan, R0); + + if (status & TxEOM) write_zsctrl(chan, ERR_RES); write_zsctrl(chan, RES_EXT_INT); write_zsctrl(chan, RES_H_IUS); @@ -679,13 +625,11 @@ struct z8530_irqhandler z8530_nop = { .tx = z8530_tx_clear, .status = z8530_status_clear, }; - - EXPORT_SYMBOL(z8530_nop); /** * z8530_interrupt - Handle an interrupt from a Z8530 - * @irq: Interrupt number + * @irq: Interrupt number * @dev_id: The Z8530 device that is interrupting. * * A Z85[2]30 device has stuck its hand in the air for attention. @@ -701,78 +645,73 @@ EXPORT_SYMBOL(z8530_nop); irqreturn_t z8530_interrupt(int irq, void *dev_id) { - struct z8530_dev *dev=dev_id; + struct z8530_dev *dev = dev_id; u8 intr; static volatile int locker=0; - int work=0; + int work = 0; struct z8530_irqhandler *irqs; - - if(locker) - { + + if (locker) { pr_err("IRQ re-enter\n"); return IRQ_NONE; } - locker=1; + locker = 1; spin_lock(&dev->lock); - while(++work<5000) - { - + while (++work < 5000) { intr = read_zsreg(&dev->chanA, R3); - if(!(intr & (CHARxIP|CHATxIP|CHAEXT|CHBRxIP|CHBTxIP|CHBEXT))) + if (!(intr & + (CHARxIP | CHATxIP | CHAEXT | CHBRxIP | CHBTxIP | CHBEXT))) break; - - /* This holds the IRQ status. On the 8530 you must read it from chan - A even though it applies to the whole chip */ - + + /* This holds the IRQ status. On the 8530 you must read it + * from chan A even though it applies to the whole chip + */ + /* Now walk the chip and see what it is wanting - it may be - an IRQ for someone else remember */ - - irqs=dev->chanA.irqs; + * an IRQ for someone else remember + */ + + irqs = dev->chanA.irqs; - if(intr & (CHARxIP|CHATxIP|CHAEXT)) - { - if(intr&CHARxIP) + if (intr & (CHARxIP | CHATxIP | CHAEXT)) { + if (intr & CHARxIP) irqs->rx(&dev->chanA); - if(intr&CHATxIP) + if (intr & CHATxIP) irqs->tx(&dev->chanA); - if(intr&CHAEXT) + if (intr & CHAEXT) irqs->status(&dev->chanA); } - irqs=dev->chanB.irqs; + irqs = dev->chanB.irqs; - if(intr & (CHBRxIP|CHBTxIP|CHBEXT)) - { - if(intr&CHBRxIP) + if (intr & (CHBRxIP | CHBTxIP | CHBEXT)) { + if (intr & CHBRxIP) irqs->rx(&dev->chanB); - if(intr&CHBTxIP) + if (intr & CHBTxIP) irqs->tx(&dev->chanB); - if(intr&CHBEXT) + if (intr & CHBEXT) irqs->status(&dev->chanB); } } spin_unlock(&dev->lock); - if(work==5000) + if (work == 5000) pr_err("%s: interrupt jammed - abort(0x%X)!\n", dev->name, intr); /* Ok all done */ - locker=0; + locker = 0; return IRQ_HANDLED; } - EXPORT_SYMBOL(z8530_interrupt); -static const u8 reg_init[16]= -{ - 0,0,0,0, - 0,0,0,0, - 0,0,0,0, - 0x55,0,0,0 +static const u8 reg_init[16] = { + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0x55, 0, 0, 0 }; - /** * z8530_sync_open - Open a Z8530 channel for PIO * @dev: The network interface we are using @@ -781,7 +720,6 @@ static const u8 reg_init[16]= * Switch a Z8530 into synchronous mode without DMA assist. We * raise the RTS/DTR and commence network operation. */ - int z8530_sync_open(struct net_device *dev, struct z8530_channel *c) { unsigned long flags; @@ -789,7 +727,7 @@ int z8530_sync_open(struct net_device *dev, struct z8530_channel *c) spin_lock_irqsave(c->lock, flags); c->sync = 1; - c->mtu = dev->mtu+64; + c->mtu = dev->mtu + 64; c->count = 0; c->skb = NULL; c->skb2 = NULL; @@ -798,17 +736,15 @@ int z8530_sync_open(struct net_device *dev, struct z8530_channel *c) /* This loads the double buffer up */ z8530_rx_done(c); /* Load the frame ring */ z8530_rx_done(c); /* Load the backup frame */ - z8530_rtsdtr(c,1); + z8530_rtsdtr(c, 1); c->dma_tx = 0; - c->regs[R1]|=TxINT_ENAB; + c->regs[R1] |= TxINT_ENAB; write_zsreg(c, R1, c->regs[R1]); - write_zsreg(c, R3, c->regs[R3]|RxENABLE); + write_zsreg(c, R3, c->regs[R3] | RxENABLE); spin_unlock_irqrestore(c->lock, flags); return 0; } - - EXPORT_SYMBOL(z8530_sync_open); /** @@ -819,25 +755,23 @@ EXPORT_SYMBOL(z8530_sync_open); * Close down a Z8530 interface and switch its interrupt handlers * to discard future events. */ - int z8530_sync_close(struct net_device *dev, struct z8530_channel *c) { u8 chk; unsigned long flags; - + spin_lock_irqsave(c->lock, flags); c->irqs = &z8530_nop; c->max = 0; c->sync = 0; - - chk=read_zsreg(c,R0); + + chk = read_zsreg(c, R0); write_zsreg(c, R3, c->regs[R3]); - z8530_rtsdtr(c,0); + z8530_rtsdtr(c, 0); spin_unlock_irqrestore(c->lock, flags); return 0; } - EXPORT_SYMBOL(z8530_sync_close); /** @@ -849,91 +783,83 @@ EXPORT_SYMBOL(z8530_sync_close); * ISA DMA channels must be available for this to work. We assume ISA * DMA driven I/O and PC limits on access. */ - int z8530_sync_dma_open(struct net_device *dev, struct z8530_channel *c) { unsigned long cflags, dflags; - + c->sync = 1; - c->mtu = dev->mtu+64; + c->mtu = dev->mtu + 64; c->count = 0; c->skb = NULL; c->skb2 = NULL; - /* - * Load the DMA interfaces up + + /* Load the DMA interfaces up */ c->rxdma_on = 0; c->txdma_on = 0; - - /* - * Allocate the DMA flip buffers. Limit by page size. + + /* Allocate the DMA flip buffers. Limit by page size. * Everyone runs 1500 mtu or less on wan links so this * should be fine. */ - - if(c->mtu > PAGE_SIZE/2) + + if (c->mtu > PAGE_SIZE / 2) return -EMSGSIZE; - - c->rx_buf[0]=(void *)get_zeroed_page(GFP_KERNEL|GFP_DMA); - if(c->rx_buf[0]==NULL) + + c->rx_buf[0] = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); + if (!c->rx_buf[0]) return -ENOBUFS; - c->rx_buf[1]=c->rx_buf[0]+PAGE_SIZE/2; - - c->tx_dma_buf[0]=(void *)get_zeroed_page(GFP_KERNEL|GFP_DMA); - if(c->tx_dma_buf[0]==NULL) - { + c->rx_buf[1] = c->rx_buf[0] + PAGE_SIZE / 2; + + c->tx_dma_buf[0] = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); + if (!c->tx_dma_buf[0]) { free_page((unsigned long)c->rx_buf[0]); - c->rx_buf[0]=NULL; + c->rx_buf[0] = NULL; return -ENOBUFS; } - c->tx_dma_buf[1]=c->tx_dma_buf[0]+PAGE_SIZE/2; + c->tx_dma_buf[1] = c->tx_dma_buf[0] + PAGE_SIZE / 2; - c->tx_dma_used=0; + c->tx_dma_used = 0; c->dma_tx = 1; - c->dma_num=0; - c->dma_ready=1; - - /* - * Enable DMA control mode + c->dma_num = 0; + c->dma_ready = 1; + + /* Enable DMA control mode */ spin_lock_irqsave(c->lock, cflags); - - /* - * TX DMA via DIR/REQ + + /* TX DMA via DIR/REQ + */ + + c->regs[R14] |= DTRREQ; + write_zsreg(c, R14, c->regs[R14]); + + c->regs[R1] &= ~TxINT_ENAB; + write_zsreg(c, R1, c->regs[R1]); + + /* RX DMA via W/Req */ - - c->regs[R14]|= DTRREQ; - write_zsreg(c, R14, c->regs[R14]); - c->regs[R1]&= ~TxINT_ENAB; + c->regs[R1] |= WT_FN_RDYFN; + c->regs[R1] |= WT_RDY_RT; + c->regs[R1] |= INT_ERR_Rx; + c->regs[R1] &= ~TxINT_ENAB; write_zsreg(c, R1, c->regs[R1]); - - /* - * RX DMA via W/Req - */ - - c->regs[R1]|= WT_FN_RDYFN; - c->regs[R1]|= WT_RDY_RT; - c->regs[R1]|= INT_ERR_Rx; - c->regs[R1]&= ~TxINT_ENAB; + c->regs[R1] |= WT_RDY_ENAB; write_zsreg(c, R1, c->regs[R1]); - c->regs[R1]|= WT_RDY_ENAB; - write_zsreg(c, R1, c->regs[R1]); - - /* - * DMA interrupts + + /* DMA interrupts + */ + + /* Set up the DMA configuration */ - - /* - * Set up the DMA configuration - */ - - dflags=claim_dma_lock(); - + + dflags = claim_dma_lock(); + disable_dma(c->rxdma); clear_dma_ff(c->rxdma); - set_dma_mode(c->rxdma, DMA_MODE_READ|0x10); + set_dma_mode(c->rxdma, DMA_MODE_READ | 0x10); set_dma_addr(c->rxdma, virt_to_bus(c->rx_buf[0])); set_dma_count(c->rxdma, c->mtu); enable_dma(c->rxdma); @@ -942,26 +868,24 @@ int z8530_sync_dma_open(struct net_device *dev, struct z8530_channel *c) clear_dma_ff(c->txdma); set_dma_mode(c->txdma, DMA_MODE_WRITE); disable_dma(c->txdma); - + release_dma_lock(dflags); - - /* - * Select the DMA interrupt handlers + + /* Select the DMA interrupt handlers */ c->rxdma_on = 1; c->txdma_on = 1; c->tx_dma_used = 1; - + c->irqs = &z8530_dma_sync; - z8530_rtsdtr(c,1); - write_zsreg(c, R3, c->regs[R3]|RxENABLE); + z8530_rtsdtr(c, 1); + write_zsreg(c, R3, c->regs[R3] | RxENABLE); spin_unlock_irqrestore(c->lock, cflags); - + return 0; } - EXPORT_SYMBOL(z8530_sync_dma_open); /** @@ -972,66 +896,60 @@ EXPORT_SYMBOL(z8530_sync_dma_open); * Shut down a DMA mode synchronous interface. Halt the DMA, and * free the buffers. */ - int z8530_sync_dma_close(struct net_device *dev, struct z8530_channel *c) { u8 chk; unsigned long flags; - + c->irqs = &z8530_nop; c->max = 0; c->sync = 0; - - /* - * Disable the PC DMA channels + + /* Disable the PC DMA channels */ - - flags=claim_dma_lock(); + + flags = claim_dma_lock(); disable_dma(c->rxdma); clear_dma_ff(c->rxdma); - + c->rxdma_on = 0; - + disable_dma(c->txdma); clear_dma_ff(c->txdma); release_dma_lock(flags); - + c->txdma_on = 0; c->tx_dma_used = 0; spin_lock_irqsave(c->lock, flags); - /* - * Disable DMA control mode + /* Disable DMA control mode */ - - c->regs[R1]&= ~WT_RDY_ENAB; - write_zsreg(c, R1, c->regs[R1]); - c->regs[R1]&= ~(WT_RDY_RT|WT_FN_RDYFN|INT_ERR_Rx); - c->regs[R1]|= INT_ALL_Rx; + + c->regs[R1] &= ~WT_RDY_ENAB; write_zsreg(c, R1, c->regs[R1]); - c->regs[R14]&= ~DTRREQ; - write_zsreg(c, R14, c->regs[R14]); - - if(c->rx_buf[0]) - { + c->regs[R1] &= ~(WT_RDY_RT | WT_FN_RDYFN | INT_ERR_Rx); + c->regs[R1] |= INT_ALL_Rx; + write_zsreg(c, R1, c->regs[R1]); + c->regs[R14] &= ~DTRREQ; + write_zsreg(c, R14, c->regs[R14]); + + if (c->rx_buf[0]) { free_page((unsigned long)c->rx_buf[0]); - c->rx_buf[0]=NULL; + c->rx_buf[0] = NULL; } - if(c->tx_dma_buf[0]) - { + if (c->tx_dma_buf[0]) { free_page((unsigned long)c->tx_dma_buf[0]); - c->tx_dma_buf[0]=NULL; + c->tx_dma_buf[0] = NULL; } - chk=read_zsreg(c,R0); + chk = read_zsreg(c, R0); write_zsreg(c, R3, c->regs[R3]); - z8530_rtsdtr(c,0); + z8530_rtsdtr(c, 0); spin_unlock_irqrestore(c->lock, flags); return 0; } - EXPORT_SYMBOL(z8530_sync_dma_close); /** @@ -1050,65 +968,58 @@ int z8530_sync_txdma_open(struct net_device *dev, struct z8530_channel *c) printk("Opening sync interface for TX-DMA\n"); c->sync = 1; - c->mtu = dev->mtu+64; + c->mtu = dev->mtu + 64; c->count = 0; c->skb = NULL; c->skb2 = NULL; - - /* - * Allocate the DMA flip buffers. Limit by page size. + + /* Allocate the DMA flip buffers. Limit by page size. * Everyone runs 1500 mtu or less on wan links so this * should be fine. */ - - if(c->mtu > PAGE_SIZE/2) + + if (c->mtu > PAGE_SIZE / 2) return -EMSGSIZE; - - c->tx_dma_buf[0]=(void *)get_zeroed_page(GFP_KERNEL|GFP_DMA); - if(c->tx_dma_buf[0]==NULL) - return -ENOBUFS; - c->tx_dma_buf[1] = c->tx_dma_buf[0] + PAGE_SIZE/2; + c->tx_dma_buf[0] = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); + if (!c->tx_dma_buf[0]) + return -ENOBUFS; + c->tx_dma_buf[1] = c->tx_dma_buf[0] + PAGE_SIZE / 2; spin_lock_irqsave(c->lock, cflags); - /* - * Load the PIO receive ring + /* Load the PIO receive ring */ z8530_rx_done(c); z8530_rx_done(c); - /* - * Load the DMA interfaces up + /* Load the DMA interfaces up */ c->rxdma_on = 0; c->txdma_on = 0; - - c->tx_dma_used=0; - c->dma_num=0; - c->dma_ready=1; + + c->tx_dma_used = 0; + c->dma_num = 0; + c->dma_ready = 1; c->dma_tx = 1; - /* - * Enable DMA control mode + /* Enable DMA control mode */ - /* - * TX DMA via DIR/REQ - */ - c->regs[R14]|= DTRREQ; - write_zsreg(c, R14, c->regs[R14]); - - c->regs[R1]&= ~TxINT_ENAB; + /* TX DMA via DIR/REQ + */ + c->regs[R14] |= DTRREQ; + write_zsreg(c, R14, c->regs[R14]); + + c->regs[R1] &= ~TxINT_ENAB; write_zsreg(c, R1, c->regs[R1]); - - /* - * Set up the DMA configuration - */ - + + /* Set up the DMA configuration + */ + dflags = claim_dma_lock(); disable_dma(c->txdma); @@ -1117,23 +1028,21 @@ int z8530_sync_txdma_open(struct net_device *dev, struct z8530_channel *c) disable_dma(c->txdma); release_dma_lock(dflags); - - /* - * Select the DMA interrupt handlers + + /* Select the DMA interrupt handlers */ c->rxdma_on = 0; c->txdma_on = 1; c->tx_dma_used = 1; - + c->irqs = &z8530_txdma_sync; - z8530_rtsdtr(c,1); - write_zsreg(c, R3, c->regs[R3]|RxENABLE); + z8530_rtsdtr(c, 1); + write_zsreg(c, R3, c->regs[R3] | RxENABLE); spin_unlock_irqrestore(c->lock, cflags); - + return 0; } - EXPORT_SYMBOL(z8530_sync_txdma_open); /** @@ -1141,7 +1050,7 @@ EXPORT_SYMBOL(z8530_sync_txdma_open); * @dev: Network device to detach * @c: Z8530 channel to move into discard mode * - * Shut down a DMA/PIO split mode synchronous interface. Halt the DMA, + * Shut down a DMA/PIO split mode synchronous interface. Halt the DMA, * and free the buffers. */ @@ -1150,17 +1059,15 @@ int z8530_sync_txdma_close(struct net_device *dev, struct z8530_channel *c) unsigned long dflags, cflags; u8 chk; - spin_lock_irqsave(c->lock, cflags); - + c->irqs = &z8530_nop; c->max = 0; c->sync = 0; - - /* - * Disable the PC DMA channels + + /* Disable the PC DMA channels */ - + dflags = claim_dma_lock(); disable_dma(c->txdma); @@ -1170,41 +1077,34 @@ int z8530_sync_txdma_close(struct net_device *dev, struct z8530_channel *c) release_dma_lock(dflags); - /* - * Disable DMA control mode + /* Disable DMA control mode */ - - c->regs[R1]&= ~WT_RDY_ENAB; - write_zsreg(c, R1, c->regs[R1]); - c->regs[R1]&= ~(WT_RDY_RT|WT_FN_RDYFN|INT_ERR_Rx); - c->regs[R1]|= INT_ALL_Rx; + + c->regs[R1] &= ~WT_RDY_ENAB; + write_zsreg(c, R1, c->regs[R1]); + c->regs[R1] &= ~(WT_RDY_RT | WT_FN_RDYFN | INT_ERR_Rx); + c->regs[R1] |= INT_ALL_Rx; write_zsreg(c, R1, c->regs[R1]); - c->regs[R14]&= ~DTRREQ; - write_zsreg(c, R14, c->regs[R14]); - - if(c->tx_dma_buf[0]) - { + c->regs[R14] &= ~DTRREQ; + write_zsreg(c, R14, c->regs[R14]); + + if (c->tx_dma_buf[0]) { free_page((unsigned long)c->tx_dma_buf[0]); - c->tx_dma_buf[0]=NULL; + c->tx_dma_buf[0] = NULL; } - chk=read_zsreg(c,R0); + chk = read_zsreg(c, R0); write_zsreg(c, R3, c->regs[R3]); - z8530_rtsdtr(c,0); + z8530_rtsdtr(c, 0); spin_unlock_irqrestore(c->lock, cflags); return 0; } - - EXPORT_SYMBOL(z8530_sync_txdma_close); - -/* - * Name strings for Z8530 chips. SGI claim to have a 130, Zilog deny +/* Name strings for Z8530 chips. SGI claim to have a 130, Zilog deny * it exists... */ - -static const char *z8530_type_name[]={ +static const char * const z8530_type_name[] = { "Z8530", "Z85C30", "Z85230" @@ -1224,78 +1124,71 @@ static const char *z8530_type_name[]={ void z8530_describe(struct z8530_dev *dev, char *mapping, unsigned long io) { pr_info("%s: %s found at %s 0x%lX, IRQ %d\n", - dev->name, + dev->name, z8530_type_name[dev->type], mapping, Z8530_PORT_OF(io), dev->irq); } - EXPORT_SYMBOL(z8530_describe); -/* - * Locked operation part of the z8530 init code +/* Locked operation part of the z8530 init code */ - static inline int do_z8530_init(struct z8530_dev *dev) { /* NOP the interrupt handlers first - we might get a - floating IRQ transition when we reset the chip */ - dev->chanA.irqs=&z8530_nop; - dev->chanB.irqs=&z8530_nop; - dev->chanA.dcdcheck=DCD; - dev->chanB.dcdcheck=DCD; + * floating IRQ transition when we reset the chip + */ + dev->chanA.irqs = &z8530_nop; + dev->chanB.irqs = &z8530_nop; + dev->chanA.dcdcheck = DCD; + dev->chanB.dcdcheck = DCD; /* Reset the chip */ write_zsreg(&dev->chanA, R9, 0xC0); udelay(200); /* Now check its valid */ write_zsreg(&dev->chanA, R12, 0xAA); - if(read_zsreg(&dev->chanA, R12)!=0xAA) + if (read_zsreg(&dev->chanA, R12) != 0xAA) return -ENODEV; write_zsreg(&dev->chanA, R12, 0x55); - if(read_zsreg(&dev->chanA, R12)!=0x55) + if (read_zsreg(&dev->chanA, R12) != 0x55) return -ENODEV; - - dev->type=Z8530; - - /* - * See the application note. + + dev->type = Z8530; + + /* See the application note. */ - + write_zsreg(&dev->chanA, R15, 0x01); - - /* - * If we can set the low bit of R15 then + + /* If we can set the low bit of R15 then * the chip is enhanced. */ - - if(read_zsreg(&dev->chanA, R15)==0x01) - { + + if (read_zsreg(&dev->chanA, R15) == 0x01) { /* This C30 versus 230 detect is from Klaus Kudielka's dmascc */ /* Put a char in the fifo */ write_zsreg(&dev->chanA, R8, 0); - if(read_zsreg(&dev->chanA, R0)&Tx_BUF_EMP) + if (read_zsreg(&dev->chanA, R0) & Tx_BUF_EMP) dev->type = Z85230; /* Has a FIFO */ else dev->type = Z85C30; /* Z85C30, 1 byte FIFO */ } - - /* - * The code assumes R7' and friends are + + /* The code assumes R7' and friends are * off. Use write_zsext() for these and keep * this bit clear. */ - + write_zsreg(&dev->chanA, R15, 0); - - /* - * At this point it looks like the chip is behaving + + /* At this point it looks like the chip is behaving */ - + memcpy(dev->chanA.regs, reg_init, 16); - memcpy(dev->chanB.regs, reg_init ,16); - + memcpy(dev->chanB.regs, reg_init, 16); + return 0; } @@ -1332,36 +1225,32 @@ int z8530_init(struct z8530_dev *dev) return ret; } - - EXPORT_SYMBOL(z8530_init); /** * z8530_shutdown - Shutdown a Z8530 device * @dev: The Z8530 chip to shutdown * - * We set the interrupt handlers to silence any interrupts. We then + * We set the interrupt handlers to silence any interrupts. We then * reset the chip and wait 100uS to be sure the reset completed. Just * in case the caller then tries to do stuff. * * This is called without the lock held */ - int z8530_shutdown(struct z8530_dev *dev) { unsigned long flags; /* Reset the chip */ spin_lock_irqsave(&dev->lock, flags); - dev->chanA.irqs=&z8530_nop; - dev->chanB.irqs=&z8530_nop; + dev->chanA.irqs = &z8530_nop; + dev->chanB.irqs = &z8530_nop; write_zsreg(&dev->chanA, R9, 0xC0); /* We must lock the udelay, the chip is offlimits here */ udelay(100); spin_unlock_irqrestore(&dev->lock, flags); return 0; } - EXPORT_SYMBOL(z8530_shutdown); /** @@ -1370,7 +1259,7 @@ EXPORT_SYMBOL(z8530_shutdown); * @rtable: table of register, value pairs * FIXME: ioctl to allow user uploaded tables * - * Load a Z8530 channel up from the system data. We use +16 to + * Load a Z8530 channel up from the system data. We use +16 to * indicate the "prime" registers. The value 255 terminates the * table. */ @@ -1381,41 +1270,39 @@ int z8530_channel_load(struct z8530_channel *c, u8 *rtable) spin_lock_irqsave(c->lock, flags); - while(*rtable!=255) - { - int reg=*rtable++; - if(reg>0x0F) - write_zsreg(c, R15, c->regs[15]|1); - write_zsreg(c, reg&0x0F, *rtable); - if(reg>0x0F) - write_zsreg(c, R15, c->regs[15]&~1); - c->regs[reg]=*rtable++; + while (*rtable != 255) { + int reg = *rtable++; + + if (reg > 0x0F) + write_zsreg(c, R15, c->regs[15] | 1); + write_zsreg(c, reg & 0x0F, *rtable); + if (reg > 0x0F) + write_zsreg(c, R15, c->regs[15] & ~1); + c->regs[reg] = *rtable++; } - c->rx_function=z8530_null_rx; - c->skb=NULL; - c->tx_skb=NULL; - c->tx_next_skb=NULL; - c->mtu=1500; - c->max=0; - c->count=0; - c->status=read_zsreg(c, R0); - c->sync=1; - write_zsreg(c, R3, c->regs[R3]|RxENABLE); + c->rx_function = z8530_null_rx; + c->skb = NULL; + c->tx_skb = NULL; + c->tx_next_skb = NULL; + c->mtu = 1500; + c->max = 0; + c->count = 0; + c->status = read_zsreg(c, R0); + c->sync = 1; + write_zsreg(c, R3, c->regs[R3] | RxENABLE); spin_unlock_irqrestore(c->lock, flags); return 0; } - EXPORT_SYMBOL(z8530_channel_load); - /** * z8530_tx_begin - Begin packet transmission * @c: The Z8530 channel to kick * * This is the speed sensitive side of transmission. If we are called * and no buffer is being transmitted we commence the next buffer. If - * nothing is queued we idle the sync. + * nothing is queued we idle the sync. * * Note: We are handling this code path in the interrupt path, keep it * fast or bad things will happen. @@ -1426,85 +1313,68 @@ EXPORT_SYMBOL(z8530_channel_load); static void z8530_tx_begin(struct z8530_channel *c) { unsigned long flags; - if(c->tx_skb) + + if (c->tx_skb) return; - - c->tx_skb=c->tx_next_skb; - c->tx_next_skb=NULL; - c->tx_ptr=c->tx_next_ptr; - - if(c->tx_skb==NULL) - { + + c->tx_skb = c->tx_next_skb; + c->tx_next_skb = NULL; + c->tx_ptr = c->tx_next_ptr; + + if (!c->tx_skb) { /* Idle on */ - if(c->dma_tx) - { - flags=claim_dma_lock(); + if (c->dma_tx) { + flags = claim_dma_lock(); disable_dma(c->txdma); - /* - * Check if we crapped out. + /* Check if we crapped out. */ - if (get_dma_residue(c->txdma)) - { + if (get_dma_residue(c->txdma)) { c->netdevice->stats.tx_dropped++; c->netdevice->stats.tx_fifo_errors++; } release_dma_lock(flags); } - c->txcount=0; - } - else - { - c->txcount=c->tx_skb->len; - - - if(c->dma_tx) - { - /* - * FIXME. DMA is broken for the original 8530, + c->txcount = 0; + } else { + c->txcount = c->tx_skb->len; + + if (c->dma_tx) { + /* FIXME. DMA is broken for the original 8530, * on the older parts we need to set a flag and * wait for a further TX interrupt to fire this - * stage off + * stage off */ - - flags=claim_dma_lock(); + + flags = claim_dma_lock(); disable_dma(c->txdma); - /* - * These two are needed by the 8530/85C30 + /* These two are needed by the 8530/85C30 * and must be issued when idling. */ - - if(c->dev->type!=Z85230) - { + if (c->dev->type != Z85230) { write_zsctrl(c, RES_Tx_CRC); write_zsctrl(c, RES_EOM_L); - } - write_zsreg(c, R10, c->regs[10]&~ABUNDER); + } + write_zsreg(c, R10, c->regs[10] & ~ABUNDER); clear_dma_ff(c->txdma); set_dma_addr(c->txdma, virt_to_bus(c->tx_ptr)); set_dma_count(c->txdma, c->txcount); enable_dma(c->txdma); release_dma_lock(flags); write_zsctrl(c, RES_EOM_L); - write_zsreg(c, R5, c->regs[R5]|TxENAB); - } - else - { - + write_zsreg(c, R5, c->regs[R5] | TxENAB); + } else { /* ABUNDER off */ write_zsreg(c, R10, c->regs[10]); write_zsctrl(c, RES_Tx_CRC); - - while(c->txcount && (read_zsreg(c,R0)&Tx_BUF_EMP)) - { + + while (c->txcount && (read_zsreg(c, R0) & Tx_BUF_EMP)) { write_zsreg(c, R8, *c->tx_ptr++); c->txcount--; } - } } - /* - * Since we emptied tx_skb we can ask for more + /* Since we emptied tx_skb we can ask for more */ netif_wake_queue(c->netdevice); } @@ -1525,7 +1395,7 @@ static void z8530_tx_done(struct z8530_channel *c) struct sk_buff *skb; /* Actually this can happen.*/ - if (c->tx_skb == NULL) + if (!c->tx_skb) return; skb = c->tx_skb; @@ -1544,12 +1414,10 @@ static void z8530_tx_done(struct z8530_channel *c) * We point the receive handler at this function when idle. Instead * of processing the frames we get to throw them away. */ - void z8530_null_rx(struct z8530_channel *c, struct sk_buff *skb) { dev_kfree_skb_any(skb); } - EXPORT_SYMBOL(z8530_null_rx); /** @@ -1564,67 +1432,58 @@ EXPORT_SYMBOL(z8530_null_rx); * * Called with the lock held */ - static void z8530_rx_done(struct z8530_channel *c) { struct sk_buff *skb; int ct; - - /* - * Is our receive engine in DMA mode + + /* Is our receive engine in DMA mode */ - - if(c->rxdma_on) - { - /* - * Save the ready state and the buffer currently + if (c->rxdma_on) { + /* Save the ready state and the buffer currently * being used as the DMA target */ - - int ready=c->dma_ready; - unsigned char *rxb=c->rx_buf[c->dma_num]; + int ready = c->dma_ready; + unsigned char *rxb = c->rx_buf[c->dma_num]; unsigned long flags; - - /* - * Complete this DMA. Necessary to find the length - */ - - flags=claim_dma_lock(); - + + /* Complete this DMA. Necessary to find the length + */ + flags = claim_dma_lock(); + disable_dma(c->rxdma); clear_dma_ff(c->rxdma); - c->rxdma_on=0; - ct=c->mtu-get_dma_residue(c->rxdma); - if(ct<0) - ct=2; /* Shit happens.. */ - c->dma_ready=0; - - /* - * Normal case: the other slot is free, start the next DMA + c->rxdma_on = 0; + ct = c->mtu - get_dma_residue(c->rxdma); + if (ct < 0) + ct = 2; /* Shit happens.. */ + c->dma_ready = 0; + + /* Normal case: the other slot is free, start the next DMA * into it immediately. */ - - if(ready) - { - c->dma_num^=1; - set_dma_mode(c->rxdma, DMA_MODE_READ|0x10); + + if (ready) { + c->dma_num ^= 1; + set_dma_mode(c->rxdma, DMA_MODE_READ | 0x10); set_dma_addr(c->rxdma, virt_to_bus(c->rx_buf[c->dma_num])); set_dma_count(c->rxdma, c->mtu); c->rxdma_on = 1; enable_dma(c->rxdma); - /* Stop any frames that we missed the head of - from passing */ + /* Stop any frames that we missed the head of + * from passing + */ write_zsreg(c, R0, RES_Rx_CRC); - } - else + } else { /* Can't occur as we dont reenable the DMA irq until - after the flip is done */ + * after the flip is done + */ netdev_warn(c->netdevice, "DMA flip overrun!\n"); + } release_dma_lock(flags); - /* - * Shove the old buffer into an sk_buff. We can't DMA + /* Shove the old buffer into an sk_buff. We can't DMA * directly into one on a PC - it might be above the 16Mb * boundary. Optimisation - we could check to see if we * can avoid the copy. Optimisation 2 - make the memcpy @@ -1632,7 +1491,7 @@ static void z8530_rx_done(struct z8530_channel *c) */ skb = dev_alloc_skb(ct); - if (skb == NULL) { + if (!skb) { c->netdevice->stats.rx_dropped++; netdev_warn(c->netdevice, "Memory squeeze\n"); } else { @@ -1646,8 +1505,7 @@ static void z8530_rx_done(struct z8530_channel *c) RT_LOCK; skb = c->skb; - /* - * The game we play for non DMA is similar. We want to + /* The game we play for non DMA is similar. We want to * get the controller set up for the next packet as fast * as possible. We potentially only have one byte + the * fifo length for this. Thus we want to flip to the new @@ -1658,7 +1516,7 @@ static void z8530_rx_done(struct z8530_channel *c) * sync IRQ for the RT_LOCK area. * */ - ct=c->count; + ct = c->count; c->skb = c->skb2; c->count = 0; @@ -1673,15 +1531,13 @@ static void z8530_rx_done(struct z8530_channel *c) RT_UNLOCK; c->skb2 = dev_alloc_skb(c->mtu); - if (c->skb2 == NULL) - netdev_warn(c->netdevice, "memory squeeze\n"); - else + if (c->skb2) skb_put(c->skb2, c->mtu); + c->netdevice->stats.rx_packets++; c->netdevice->stats.rx_bytes += ct; } - /* - * If we received a frame we must now process it. + /* If we received a frame we must now process it. */ if (skb) { skb_trim(skb, ct); @@ -1702,9 +1558,10 @@ static void z8530_rx_done(struct z8530_channel *c) static inline int spans_boundary(struct sk_buff *skb) { - unsigned long a=(unsigned long)skb->data; - a^=(a+skb->len); - if(a&0x00010000) /* If the 64K bit is different.. */ + unsigned long a = (unsigned long)skb->data; + + a ^= (a + skb->len); + if (a & 0x00010000) /* If the 64K bit is different.. */ return 1; return 0; } @@ -1715,60 +1572,54 @@ static inline int spans_boundary(struct sk_buff *skb) * @skb: The packet to kick down the channel * * Queue a packet for transmission. Because we have rather - * hard to hit interrupt latencies for the Z85230 per packet + * hard to hit interrupt latencies for the Z85230 per packet * even in DMA mode we do the flip to DMA buffer if needed here * not in the IRQ. * - * Called from the network code. The lock is not held at this + * Called from the network code. The lock is not held at this * point. */ - netdev_tx_t z8530_queue_xmit(struct z8530_channel *c, struct sk_buff *skb) { unsigned long flags; - + netif_stop_queue(c->netdevice); - if(c->tx_next_skb) + if (c->tx_next_skb) return NETDEV_TX_BUSY; - /* PC SPECIFIC - DMA limits */ - - /* - * If we will DMA the transmit and its gone over the ISA bus + /* If we will DMA the transmit and its gone over the ISA bus * limit, then copy to the flip buffer */ - - if(c->dma_tx && ((unsigned long)(virt_to_bus(skb->data+skb->len))>=16*1024*1024 || spans_boundary(skb))) - { - /* - * Send the flip buffer, and flip the flippy bit. + + if (c->dma_tx && + ((unsigned long)(virt_to_bus(skb->data + skb->len)) >= + 16 * 1024 * 1024 || spans_boundary(skb))) { + /* Send the flip buffer, and flip the flippy bit. * We don't care which is used when just so long as * we never use the same buffer twice in a row. Since * only one buffer can be going out at a time the other * has to be safe. */ - c->tx_next_ptr=c->tx_dma_buf[c->tx_dma_used]; - c->tx_dma_used^=1; /* Flip temp buffer */ + c->tx_next_ptr = c->tx_dma_buf[c->tx_dma_used]; + c->tx_dma_used ^= 1; /* Flip temp buffer */ skb_copy_from_linear_data(skb, c->tx_next_ptr, skb->len); + } else { + c->tx_next_ptr = skb->data; } - else - c->tx_next_ptr=skb->data; RT_LOCK; - c->tx_next_skb=skb; + c->tx_next_skb = skb; RT_UNLOCK; - + spin_lock_irqsave(c->lock, flags); z8530_tx_begin(c); spin_unlock_irqrestore(c->lock, flags); - + return NETDEV_TX_OK; } - EXPORT_SYMBOL(z8530_queue_xmit); -/* - * Module support +/* Module support */ static const char banner[] __initconst = KERN_INFO "Generic Z85C30/Z85230 interface driver v0.02\n"; |