yam.c-2.4.0-test12-patch-v1

From: Hans Grobler (terhi.victor@logonet.com)
Date: Thu Dec 14 2000 - 08:00:34 EET

  • Next message: Brent Corbin: "Re: soundmodem"

    yam.c-2.4.0-test12-patch-v1:
      - numerous cleanups (indentation,whitespace) as per Documentation/CodingStyle
      - add_mcs,yam_ioctl: changes GFP_ATOMIC to GFP_KERNEL as the kmalloc are
          on sleep safe codepaths (non-interrupt).
      - tagged all printk's with KERN_WARNING or KERN_ERR as appropriate
      - fixed comment about fpgaconf.h

    yam.c-2.4.0-test12-pre7-patch-v2:
      - yam_data,yam_init_driver: removed explicit data initialization as per
          linux2.4 style '.bss' clearing.
      - yam_drvinfo: tagged initialization data for later ejection.
      - yam_rx_flag,yam_rx_byte: fixed static inline definition order
      - yam_send_packet: removed unnecessary skb == NULL check. the
          network layer will never pass a NULL skbuff
      - yam_net_procfs_init,yam_net_procfs_remove: removed unnecessary
          conditional macros. the linux2.4 proc headers already handle this.

    patch version 1:
      - yam_init,init_module,cleanup_module: converted to use new linux2.4
          module definition format.
      - free_mcs: merged into yam_cleanup_driver (and get rid of conditional
          compile flag)
      - irqs array: removed unnecessary variable

    diff -u3Nr -X dontdiff linux-2.4.0-test12.orig/drivers/net/hamradio/yam.c linux-2.4.0-test12/drivers/net/hamradio/yam.c
    --- linux-2.4.0-test12.orig/drivers/net/hamradio/yam.c Thu May 4 20:31:21 2000
    +++ linux-2.4.0-test12/drivers/net/hamradio/yam.c Wed Dec 13 22:36:37 2000
    @@ -60,7 +60,7 @@
     #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
     /* prototypes for ax25_encapsulate and ax25_rebuild_header */
     #include <net/ax25.h>
    -#endif /* CONFIG_AX25 || CONFIG_AX25_MODULE */
    +#endif /* CONFIG_AX25 || CONFIG_AX25_MODULE */

     /* make genksyms happy */
     #include <linux/ip.h>
    @@ -81,33 +81,33 @@
     /* --------------------------------------------------------------------- */

     static const char yam_drvname[] = "yam";
    -static const char yam_drvinfo[] = KERN_INFO "YAM driver version 0.8 by F1OAT/F6FBB\n";
    +static const char yam_drvinfo[] __initdata = KERN_INFO "YAM driver version 0.8 by F1OAT/F6FBB\n";

     /* --------------------------------------------------------------------- */

     #define YAM_9600 1
     #define YAM_1200 2

    -#define NR_PORTS 4
    +#define NR_PORTS 4
     #define YAM_MAGIC 0xF10A7654

     /* Transmitter states */

    -#define TX_OFF 0
    +#define TX_OFF 0
     #define TX_HEAD 1
    -#define TX_DATA 2
    -#define TX_CRC1 3
    -#define TX_CRC2 4
    -#define TX_TAIL 5
    +#define TX_DATA 2
    +#define TX_CRC1 3
    +#define TX_CRC2 4
    +#define TX_TAIL 5

     #define YAM_MAX_FRAME 1024

    -#define DEFAULT_BITRATE 9600 /* bps */
    -#define DEFAULT_HOLDD 10 /* sec */
    -#define DEFAULT_TXD 300 /* ms */
    -#define DEFAULT_TXTAIL 10 /* ms */
    -#define DEFAULT_SLOT 100 /* ms */
    -#define DEFAULT_PERS 64 /* 0->255 */
    +#define DEFAULT_BITRATE 9600 /* bps */
    +#define DEFAULT_HOLDD 10 /* sec */
    +#define DEFAULT_TXD 300 /* ms */
    +#define DEFAULT_TXTAIL 10 /* ms */
    +#define DEFAULT_SLOT 100 /* ms */
    +#define DEFAULT_PERS 64 /* 0->255 */

     struct yam_port {
             int magic;
    @@ -128,11 +128,11 @@

             /* Parameters section */

    - int txd; /* tx delay */
    - int holdd; /* duplex ptt delay */
    - int txtail; /* txtail delay */
    - int slot; /* slottime */
    - int pers; /* persistence */
    + int txd; /* tx delay */
    + int holdd; /* duplex ptt delay */
    + int txtail; /* txtail delay */
    + int slot; /* slottime */
    + int pers; /* persistence */

             /* Tx section */

    @@ -160,104 +160,100 @@

     static struct yam_port yam_ports[NR_PORTS];

    -static struct yam_mcs *yam_data = NULL;
    -
    -static unsigned irqs[16];
    +static struct yam_mcs *yam_data;

    -static char ax25_bcast[7] =
    +static const char ax25_bcast[7] =
     {'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, '0' << 1};
    -static char ax25_test[7] =
    +static const char ax25_test[7] =
     {'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1};

     static struct timer_list yam_timer;

     /* --------------------------------------------------------------------- */

    -#define RBR(iobase) (iobase+0)
    -#define THR(iobase) (iobase+0)
    -#define IER(iobase) (iobase+1)
    -#define IIR(iobase) (iobase+2)
    -#define FCR(iobase) (iobase+2)
    -#define LCR(iobase) (iobase+3)
    -#define MCR(iobase) (iobase+4)
    -#define LSR(iobase) (iobase+5)
    -#define MSR(iobase) (iobase+6)
    -#define SCR(iobase) (iobase+7)
    -#define DLL(iobase) (iobase+0)
    -#define DLM(iobase) (iobase+1)
    +#define RBR(iobase) (iobase+0)
    +#define THR(iobase) (iobase+0)
    +#define IER(iobase) (iobase+1)
    +#define IIR(iobase) (iobase+2)
    +#define FCR(iobase) (iobase+2)
    +#define LCR(iobase) (iobase+3)
    +#define MCR(iobase) (iobase+4)
    +#define LSR(iobase) (iobase+5)
    +#define MSR(iobase) (iobase+6)
    +#define SCR(iobase) (iobase+7)
    +#define DLL(iobase) (iobase+0)
    +#define DLM(iobase) (iobase+1)

    -#define YAM_EXTENT 8
    +#define YAM_EXTENT 8

     /* Interrupt Identification Register Bit Masks */
    -#define IIR_NOPEND 1
    -#define IIR_MSR 0
    -#define IIR_TX 2
    -#define IIR_RX 4
    -#define IIR_LSR 6
    +#define IIR_NOPEND 1
    +#define IIR_MSR 0
    +#define IIR_TX 2
    +#define IIR_RX 4
    +#define IIR_LSR 6
     #define IIR_TIMEOUT 12 /* Fifo mode only */

     #define IIR_MASK 0x0F

     /* Interrupt Enable Register Bit Masks */
    -#define IER_RX 1 /* enable rx interrupt */
    -#define IER_TX 2 /* enable tx interrupt */
    -#define IER_LSR 4 /* enable line status interrupts */
    -#define IER_MSR 8 /* enable modem status interrupts */
    +#define IER_RX 1 /* enable rx interrupt */
    +#define IER_TX 2 /* enable tx interrupt */
    +#define IER_LSR 4 /* enable line status interrupts */
    +#define IER_MSR 8 /* enable modem status interrupts */

     /* Modem Control Register Bit Masks */
    -#define MCR_DTR 0x01 /* DTR output */
    -#define MCR_RTS 0x02 /* RTS output */
    -#define MCR_OUT1 0x04 /* OUT1 output (not accessible in RS232) */
    -#define MCR_OUT2 0x08 /* Master Interrupt enable (must be set on PCs) */
    -#define MCR_LOOP 0x10 /* Loopback enable */
    +#define MCR_DTR 0x01 /* DTR output */
    +#define MCR_RTS 0x02 /* RTS output */
    +#define MCR_OUT1 0x04 /* OUT1 output (not accessible in RS232) */
    +#define MCR_OUT2 0x08 /* Master Interrupt enable (must be set on PCs) */
    +#define MCR_LOOP 0x10 /* Loopback enable */

     /* Modem Status Register Bit Masks */
    -#define MSR_DCTS 0x01 /* Delta CTS input */
    -#define MSR_DDSR 0x02 /* Delta DSR */
    -#define MSR_DRIN 0x04 /* Delta RI */
    -#define MSR_DDCD 0x08 /* Delta DCD */
    -#define MSR_CTS 0x10 /* CTS input */
    -#define MSR_DSR 0x20 /* DSR input */
    -#define MSR_RING 0x40 /* RI input */
    -#define MSR_DCD 0x80 /* DCD input */
    +#define MSR_DCTS 0x01 /* Delta CTS input */
    +#define MSR_DDSR 0x02 /* Delta DSR */
    +#define MSR_DRIN 0x04 /* Delta RI */
    +#define MSR_DDCD 0x08 /* Delta DCD */
    +#define MSR_CTS 0x10 /* CTS input */
    +#define MSR_DSR 0x20 /* DSR input */
    +#define MSR_RING 0x40 /* RI input */
    +#define MSR_DCD 0x80 /* DCD input */

     /* line status register bit mask */
    -#define LSR_RXC 0x01
    -#define LSR_OE 0x02
    -#define LSR_PE 0x04
    -#define LSR_FE 0x08
    -#define LSR_BREAK 0x10
    -#define LSR_THRE 0x20
    -#define LSR_TSRE 0x40
    +#define LSR_RXC 0x01
    +#define LSR_OE 0x02
    +#define LSR_PE 0x04
    +#define LSR_FE 0x08
    +#define LSR_BREAK 0x10
    +#define LSR_THRE 0x20
    +#define LSR_TSRE 0x40

     /* Line Control Register Bit Masks */
    -#define LCR_DLAB 0x80
    -#define LCR_BREAK 0x40
    -#define LCR_PZERO 0x28
    -#define LCR_PEVEN 0x18
    -#define LCR_PODD 0x08
    -#define LCR_STOP1 0x00
    -#define LCR_STOP2 0x04
    -#define LCR_BIT5 0x00
    -#define LCR_BIT6 0x02
    -#define LCR_BIT7 0x01
    -#define LCR_BIT8 0x03
    +#define LCR_DLAB 0x80
    +#define LCR_BREAK 0x40
    +#define LCR_PZERO 0x28
    +#define LCR_PEVEN 0x18
    +#define LCR_PODD 0x08
    +#define LCR_STOP1 0x00
    +#define LCR_STOP2 0x04
    +#define LCR_BIT5 0x00
    +#define LCR_BIT6 0x02
    +#define LCR_BIT7 0x01
    +#define LCR_BIT8 0x03

     /* YAM Modem <-> UART Port mapping */

    -#define TX_RDY MSR_DCTS /* transmitter ready to send */
    -#define RX_DCD MSR_DCD /* carrier detect */
    -#define RX_FLAG MSR_RING /* hdlc flag received */
    -#define FPGA_DONE MSR_DSR /* FPGA is configured */
    -#define PTT_ON (MCR_RTS|MCR_OUT2) /* activate PTT */
    -#define PTT_OFF (MCR_DTR|MCR_OUT2) /* release PTT */
    -
    -#define ENABLE_RXINT IER_RX /* enable uart rx interrupt during rx */
    -#define ENABLE_TXINT IER_MSR /* enable uart ms interrupt during tx */
    -#define ENABLE_RTXINT (IER_RX|IER_MSR) /* full duplex operations */
    +#define TX_RDY MSR_DCTS /* transmitter ready to send */
    +#define RX_DCD MSR_DCD /* carrier detect */
    +#define RX_FLAG MSR_RING /* hdlc flag received */
    +#define FPGA_DONE MSR_DSR /* FPGA is configured */
    +#define PTT_ON (MCR_RTS|MCR_OUT2) /* activate PTT */
    +#define PTT_OFF (MCR_DTR|MCR_OUT2) /* release PTT */
    +
    +#define ENABLE_RXINT IER_RX /* enable uart rx interrupt during rx */
    +#define ENABLE_TXINT IER_MSR /* enable uart ms interrupt during tx */
    +#define ENABLE_RTXINT (IER_RX|IER_MSR) /* full duplex operations */

    -#define MIN(a, b) (((a) < (b)) ? (a) : (b))
    -#define MAX(a, b) (((a) > (b)) ? (a) : (b))

     /*************************************************************************
     * CRC Tables
    @@ -357,21 +353,7 @@
             return 0;
     }

    -#ifdef MODULE
    -static void free_mcs(void)
    -{
    - struct yam_mcs *p;
    -
    - while (yam_data) {
    - p = yam_data;
    - yam_data = yam_data->next;
    - kfree(p);
    - }
    -}
    -#endif
    -
    -static unsigned char *
    - add_mcs(unsigned char *bits, int bitrate)
    +static unsigned char *add_mcs(unsigned char *bits, int bitrate)
     {
             struct yam_mcs *p;

    @@ -386,8 +368,7 @@
             }

             /* Allocate a new mcs */
    - p = kmalloc(sizeof(struct yam_mcs), GFP_ATOMIC);
    - if (p == NULL) {
    + if ((p = kmalloc(sizeof(struct yam_mcs), GFP_KERNEL)) == NULL) {
                     printk(KERN_WARNING "YAM: no memory to allocate mcs\n");
                     return NULL;
             }
    @@ -421,7 +402,7 @@

     /*
      * download bitstream to FPGA
    - * data is contained in bits[] array in fpgaconf.h
    + * data is contained in bits[] array in yam1200.h resp. yam9600.h
      */

     static int fpga_download(int iobase, int bitrate)
    @@ -436,7 +417,7 @@
             fpga_reset(iobase);
             for (i = 0; i < YAM_FPGA_SIZE; i++) {
                     if (fpga_write(iobase, pbits[i])) {
    - printk("yam: error in write cycle\n");
    + printk(KERN_ERR "yam: error in write cycle\n");
                             return -1; /* write... */
                     }
             }
    @@ -523,8 +504,7 @@
     /******************************************************************************
     * Rx Section
     ******************************************************************************/
    -static void inline
    - yam_rx_flag(struct net_device *dev, struct yam_port *yp)
    +static inline void yam_rx_flag(struct net_device *dev, struct yam_port *yp)
     {
             if (yp->dcd && yp->rx_len >= 3 && yp->rx_len < YAM_MAX_FRAME) {
                     int pkt_len = yp->rx_len - 2 + 1; /* -CRC + kiss */
    @@ -534,7 +514,7 @@
                             /* Bad crc */
                     } else {
                             if (!(skb = dev_alloc_skb(pkt_len))) {
    - printk("%s: memory squeeze, dropping packet\n", dev->name);
    + printk(KERN_WARNING "%s: memory squeeze, dropping packet\n", dev->name);
                                     ++yp->stats.rx_dropped;
                             } else {
                                     unsigned char *cp;
    @@ -554,8 +534,7 @@
             yp->rx_crch = 0xf3;
     }

    -static void inline
    - yam_rx_byte(struct net_device *dev, struct yam_port *yp, unsigned char rxb)
    +static inline void yam_rx_byte(struct net_device *dev, struct yam_port *yp, unsigned char rxb)
     {
             if (yp->rx_len < YAM_MAX_FRAME) {
                     unsigned char c = yp->rx_crcl;
    @@ -583,9 +562,6 @@
     {
             struct yam_port *yp = dev->priv;

    - if (skb == NULL) {
    - return 0;
    - }
             skb_queue_tail(&yp->send_queue, skb);
             dev->trans_start = jiffies;
             return 0;
    @@ -761,7 +737,7 @@
                             yp->dcd = (msr & RX_DCD) ? 1 : 0;

                             if (--counter <= 0) {
    - printk("%s: too many irq iir=%d\n", dev->name, iir);
    + printk(KERN_ERR "%s: too many irq iir=%d\n", dev->name, iir);
                                     return;
                             }
                             if (msr & TX_RDY) {
    @@ -833,19 +809,6 @@
             return len;
     }

    -#ifdef CONFIG_INET
    -#ifdef CONFIG_PROC_FS
    -#define yam_net_procfs_init() proc_net_create("yam",0,yam_net_get_info)
    -#define yam_net_procfs_remove() proc_net_remove("yam")
    -#else
    -#define yam_net_procfs_init()
    -#define yam_net_procfs_remove()
    -#endif /* CONFIG_PROC_FS */
    -#else
    -#define yam_net_procfs_init()
    -#define yam_net_procfs_remove()
    -#endif /* CONFIG_INET */
    -
     /* --------------------------------------------------------------------- */

     static struct net_device_stats *yam_get_stats(struct net_device *dev)
    @@ -883,20 +846,20 @@
                     return -ENXIO;
             }
             if (check_region(dev->base_addr, YAM_EXTENT)) {
    - printk("%s: cannot 0x%lx busy\n", dev->name, dev->base_addr);
    + printk(KERN_ERR "%s: cannot 0x%lx busy\n", dev->name, dev->base_addr);
                     return -EACCES;
             }
             if ((u = yam_check_uart(dev->base_addr)) == c_uart_unknown) {
    - printk("%s: cannot find uart type\n", dev->name);
    + printk(KERN_ERR "%s: cannot find uart type\n", dev->name);
                     return -EIO;
             }
             if (fpga_download(dev->base_addr, yp->bitrate)) {
    - printk("%s: cannot init FPGA\n", dev->name);
    + printk(KERN_ERR "%s: cannot init FPGA\n", dev->name);
                     return -EIO;
             }
             outb(0, IER(dev->base_addr));
             if (request_irq(dev->irq, yam_interrupt, SA_INTERRUPT | SA_SHIRQ, dev->name, NULL)) {
    - printk("%s: irq %d busy\n", dev->name, dev->irq);
    + printk(KERN_ERR "%s: irq %d busy\n", dev->name, dev->irq);
                     return -EBUSY;
             }
             request_region(dev->base_addr, YAM_EXTENT, dev->name);
    @@ -975,7 +938,7 @@
             case SIOCYAMSMCS:
                     if (netif_running(dev))
                             return -EINVAL; /* Cannot change this parameter when up */
    - ym = kmalloc(sizeof(struct yamdrv_ioctl_mcs), GFP_ATOMIC);
    + ym = kmalloc(sizeof(struct yamdrv_ioctl_mcs), GFP_KERNEL);
                     if(ym==NULL)
                             return -ENOBUFS;
                     ym->bitrate = 9600;
    @@ -1135,17 +1098,13 @@

     /* --------------------------------------------------------------------- */

    -int __init yam_init(void)
    +static int __init yam_init_driver(void)
     {
             struct net_device *dev;
             int i;

             printk(yam_drvinfo);

    - /* Clears the IRQ table */
    - memset(irqs, 0, sizeof(irqs));
    - memset(yam_ports, 0, sizeof(yam_ports));
    -
             for (i = 0; i < NR_PORTS; i++) {
                     sprintf(yam_ports[i].dev.name, "yam%d", i);
                     yam_ports[i].magic = YAM_MAGIC;
    @@ -1169,7 +1128,7 @@
                     dev->if_port = 0;

                     if (register_netdev(dev)) {
    - printk(KERN_WARNING "yam: cannot register net device %s\n", dev->name);
    + printk(KERN_WARNING "yam: cannot register net device %s\n", dev->name);
                             return -ENXIO;
                     }
             }
    @@ -1178,33 +1137,15 @@
             yam_timer.expires = jiffies + HZ / 100;
             add_timer(&yam_timer);

    - yam_net_procfs_init();
    - return 1;
    -}
    -
    -/* --------------------------------------------------------------------- */
    -
    -#ifdef MODULE
    -
    -/*
    - * command line settable parameters
    - */
    -
    -
    -MODULE_AUTHOR("Frederic Rible F1OAT terhi.victor@logonet.com");
    -MODULE_DESCRIPTION("Yam amateur radio modem driver");
    -
    -int init_module(void)
    -{
    - int ret = yam_init();
    -
    - return (ret == 1) ? 0 : ret;
    + proc_net_create("yam", 0, yam_net_get_info);
    + return 0;
     }

     /* --------------------------------------------------------------------- */

    -void cleanup_module(void)
    +static void __exit yam_cleanup_driver(void)
     {
    + struct yam_mcs *p;
             int i;

             del_timer(&yam_timer);
    @@ -1216,9 +1157,23 @@
                             yam_close(dev);
                     unregister_netdev(dev);
             }
    - free_mcs();
    - yam_net_procfs_remove();
    +
    + while (yam_data) {
    + p = yam_data;
    + yam_data = yam_data->next;
    + kfree(p);
    + }
    +
    + proc_net_remove("yam");
     }

    -#endif /* MODULE */
     /* --------------------------------------------------------------------- */
    +
    +MODULE_AUTHOR("Frederic Rible F1OAT terhi.victor@logonet.com");
    +MODULE_DESCRIPTION("Yam amateur radio modem driver");
    +
    +module_init(yam_init_driver);
    +module_exit(yam_cleanup_driver);
    +
    +/* --------------------------------------------------------------------- */
    +

    -
    To unsubscribe from this list: send the line "unsubscribe linux-hams" in
    the body of a message to xqhoav.slyv@lsc.ufsc.br
    -
    To unsubscribe from this list: send the line "unsubscribe linux-hams" in
    the body of a message to terhi.victor@logonet.com



    This archive was generated by hypermail 2b30 : Thu Dec 14 2000 - 16:41:06 EET