^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Linux ARCnet driver - COM90xx chipset (IO-mapped buffers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Written 1997 by David Woodhouse.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written 1994-1999 by Avery Pennarun.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Derived from skeleton.c by Donald Becker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * for sponsoring the further development of this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * The original copyright of skeleton.c was as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * skeleton.c Written 1993 by Donald Becker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Copyright 1993 United States Government as represented by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Director, National Security Agency. This software may only be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * and distributed according to the terms of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * modified by SRC, incorporated herein by reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * For more details, see drivers/net/arcnet.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * **********************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "arcdevice.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include "com9026.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* Internal function declarations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static int com90io_found(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static void com90io_command(struct net_device *dev, int command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static int com90io_status(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static void com90io_setmask(struct net_device *dev, int mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int com90io_reset(struct net_device *dev, int really_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static void com90io_copy_to_card(struct net_device *dev, int bufnum, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) void *buf, int count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static void com90io_copy_from_card(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int offset, void *buf, int count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* Handy defines for ARCnet specific stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* The number of low I/O ports used by the card. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define ARCNET_TOTAL_SIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * IO-mapped operation routines *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #undef ONE_AT_A_TIME_TX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #undef ONE_AT_A_TIME_RX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static u_char get_buffer_byte(struct net_device *dev, unsigned offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) arcnet_outb(offset >> 8, ioaddr, COM9026_REG_W_ADDR_HI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #ifdef ONE_AT_A_TIME_TX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void put_buffer_byte(struct net_device *dev, unsigned offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) u_char datum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) arcnet_outb(offset >> 8, ioaddr, COM9026_REG_W_ADDR_HI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) arcnet_outb(datum, ioaddr, COM9026_REG_RW_MEMDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static void get_whole_buffer(struct net_device *dev, unsigned offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned length, char *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) arcnet_outb((offset >> 8) | AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) arcnet_outb(offset & 0xff, ioaddr, COM9026_REG_W_ADDR_LO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) while (length--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #ifdef ONE_AT_A_TIME_RX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *(dest++) = get_buffer_byte(dev, offset++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *(dest++) = arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static void put_whole_buffer(struct net_device *dev, unsigned offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) unsigned length, char *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) arcnet_outb((offset >> 8) | AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) arcnet_outb(offset & 0xff, ioaddr,COM9026_REG_W_ADDR_LO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) while (length--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #ifdef ONE_AT_A_TIME_TX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) put_buffer_byte(dev, offset++, *(dest++));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) arcnet_outb(*(dest++), ioaddr, COM9026_REG_RW_MEMDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* We cannot probe for an IO mapped card either, although we can check that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * it's where we were told it was, and even autoirq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int __init com90io_probe(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int ioaddr = dev->base_addr, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) unsigned long airqmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (BUGLVL(D_NORMAL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) pr_info("%s\n", "COM90xx IO-mapped mode support (by David Woodhouse et el.)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) pr_info("E-mail me if you actually test this driver, please!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (!ioaddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) arc_printk(D_NORMAL, dev, "No autoprobe for IO mapped cards; you must specify the base address!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "com90io probe")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) arc_printk(D_INIT_REASONS, dev, "IO request_region %x-%x failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (arcnet_inb(ioaddr, COM9026_REG_R_STATUS) == 0xFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) arc_printk(D_INIT_REASONS, dev, "IO address %x empty\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ioaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) arcnet_inb(ioaddr, COM9026_REG_R_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) mdelay(RESETtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if ((status & 0x9D) != (NORXflag | RECONflag | TXFREEflag | RESETflag)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) arc_printk(D_INIT_REASONS, dev, "Status invalid (%Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) arc_printk(D_INIT_REASONS, dev, "Status after reset: %X\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ioaddr, COM9026_REG_W_COMMAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) arc_printk(D_INIT_REASONS, dev, "Status after reset acknowledged: %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) status = arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (status & RESETflag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) arc_printk(D_INIT_REASONS, dev, "Eternal reset (status=%Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) arcnet_outb((0x16 | IOMAPflag) & ~ENABLE16flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ioaddr, COM9026_REG_RW_CONFIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Read first loc'n of memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) arcnet_outb(AUTOINCflag, ioaddr, COM9026_REG_W_ADDR_HI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) arcnet_outb(0, ioaddr, COM9026_REG_W_ADDR_LO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) status = arcnet_inb(ioaddr, COM9026_REG_RW_MEMDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (status != 0xd1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) arc_printk(D_INIT_REASONS, dev, "Signature byte not found (%Xh instead).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (!dev->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* if we do this, we're sure to get an IRQ since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * card has just reset and the NORXflag is on until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * we tell it to start receiving.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) airqmask = probe_irq_on();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) arcnet_outb(NORXflag, ioaddr, COM9026_REG_W_INTMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) arcnet_outb(0, ioaddr, COM9026_REG_W_INTMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) dev->irq = probe_irq_off(airqmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if ((int)dev->irq <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) release_region(ioaddr, ARCNET_TOTAL_SIZE); /* end of probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return com90io_found(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) release_region(ioaddr, ARCNET_TOTAL_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* Set up the struct net_device associated with this card. Called after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * probing succeeds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static int __init com90io_found(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct arcnet_local *lp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* Reserve the irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (request_irq(dev->irq, arcnet_interrupt, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) "arcnet (COM90xx-IO)", dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* Reserve the I/O region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (!request_region(dev->base_addr, ARCNET_TOTAL_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) "arcnet (COM90xx-IO)")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) free_irq(dev->irq, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) lp->card_name = "COM90xx I/O";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) lp->hw.command = com90io_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) lp->hw.status = com90io_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) lp->hw.intmask = com90io_setmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) lp->hw.reset = com90io_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) lp->hw.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) lp->hw.copy_to_card = com90io_copy_to_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) lp->hw.copy_from_card = com90io_copy_from_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) lp->config = (0x16 | IOMAPflag) & ~ENABLE16flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) arcnet_outb(lp->config, ioaddr, COM9026_REG_RW_CONFIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* get and check the station ID from offset 1 in shmem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) dev->dev_addr[0] = get_buffer_byte(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) err = register_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) & ~IOMAPflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) ioaddr, COM9026_REG_RW_CONFIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) free_irq(dev->irq, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) arc_printk(D_NORMAL, dev, "COM90IO: station %02Xh found at %03lXh, IRQ %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) dev->dev_addr[0], dev->base_addr, dev->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /* Do a hardware reset on the card, and set up necessary registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * This should be called as little as possible, because it disrupts the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * token on the network (causes a RECON) and requires a significant delay.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * However, it does make sure the card is in a defined state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static int com90io_reset(struct net_device *dev, int really_reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct arcnet_local *lp = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) short ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) dev->name, arcnet_inb(ioaddr, COM9026_REG_R_STATUS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (really_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /* reset the card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) arcnet_inb(ioaddr, COM9026_REG_R_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) mdelay(RESETtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* Set the thing to IO-mapped, 8-bit mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) lp->config = (0x1C | IOMAPflag) & ~ENABLE16flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) arcnet_outb(lp->config, ioaddr, COM9026_REG_RW_CONFIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) arcnet_outb(CFLAGScmd | RESETclear, ioaddr, COM9026_REG_W_COMMAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /* clear flags & end reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) arcnet_outb(CFLAGScmd | CONFIGclear, ioaddr, COM9026_REG_W_COMMAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* verify that the ARCnet signature byte is present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (get_buffer_byte(dev, 0) != TESTvalue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* enable extended (512-byte) packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) arcnet_outb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /* done! return success. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static void com90io_command(struct net_device *dev, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) short ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) arcnet_outb(cmd, ioaddr, COM9026_REG_W_COMMAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static int com90io_status(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) short ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return arcnet_inb(ioaddr, COM9026_REG_R_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static void com90io_setmask(struct net_device *dev, int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) short ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) arcnet_outb(mask, ioaddr, COM9026_REG_W_INTMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static void com90io_copy_to_card(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) int offset, void *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) TIME(dev, "put_whole_buffer", count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) put_whole_buffer(dev, bufnum * 512 + offset, count, buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static void com90io_copy_from_card(struct net_device *dev, int bufnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) int offset, void *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) TIME(dev, "get_whole_buffer", count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) get_whole_buffer(dev, bufnum * 512 + offset, count, buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static int io; /* use the insmod io= irq= shmem= options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static char device[9]; /* use eg. device=arc1 to change name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) module_param_hw(io, int, ioport, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) module_param_hw(irq, int, irq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) module_param_string(device, device, sizeof(device), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) #ifndef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static int __init com90io_setup(char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int ints[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) s = get_options(s, 4, ints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (!ints[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) switch (ints[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) default: /* ERROR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) pr_err("Too many arguments\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) case 2: /* IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) irq = ints[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) case 1: /* IO address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) io = ints[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (*s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) snprintf(device, sizeof(device), "%s", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) __setup("com90io=", com90io_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static struct net_device *my_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static int __init com90io_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) dev = alloc_arcdev(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) dev->base_addr = io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) dev->irq = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (dev->irq == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) dev->irq = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) err = com90io_probe(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) my_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static void __exit com90io_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct net_device *dev = my_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) int ioaddr = dev->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) unregister_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* In case the old driver is loaded later,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * set the thing back to MMAP mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) arcnet_outb(arcnet_inb(ioaddr, COM9026_REG_RW_CONFIG) & ~IOMAPflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) ioaddr, COM9026_REG_RW_CONFIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) free_irq(dev->irq, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) release_region(dev->base_addr, ARCNET_TOTAL_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) module_init(com90io_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) module_exit(com90io_exit)