Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux ARCnet driver - COM20020 chipset support |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Written 1997 by David Woodhouse. |
| 5 | * Written 1994-1999 by Avery Pennarun. |
| 6 | * Written 1999 by Martin Mares <mj@ucw.cz>. |
| 7 | * Derived from skeleton.c by Donald Becker. |
| 8 | * |
| 9 | * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com) |
| 10 | * for sponsoring the further development of this driver. |
| 11 | * |
| 12 | * ********************** |
| 13 | * |
| 14 | * The original copyright of skeleton.c was as follows: |
| 15 | * |
| 16 | * skeleton.c Written 1993 by Donald Becker. |
| 17 | * Copyright 1993 United States Government as represented by the |
| 18 | * Director, National Security Agency. This software may only be used |
| 19 | * and distributed according to the terms of the GNU General Public License as |
| 20 | * modified by SRC, incorporated herein by reference. |
| 21 | * |
| 22 | * ********************** |
| 23 | * |
| 24 | * For more details, see drivers/net/arcnet.c |
| 25 | * |
| 26 | * ********************** |
| 27 | */ |
Joe Perches | 05a24b2 | 2015-05-05 10:05:56 -0700 | [diff] [blame] | 28 | |
| 29 | #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/module.h> |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/types.h> |
| 34 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/errno.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/netdevice.h> |
| 38 | #include <linux/init.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 39 | #include <linux/interrupt.h> |
Joe Perches | 5e7ef91 | 2015-05-05 10:05:51 -0700 | [diff] [blame] | 40 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Joe Perches | 26c6d28 | 2015-05-05 10:06:03 -0700 | [diff] [blame] | 42 | #include "arcdevice.h" |
| 43 | #include "com20020.h" |
| 44 | |
Joe Perches | 4e299b9 | 2015-05-05 10:06:04 -0700 | [diff] [blame] | 45 | static const char * const clockrates[] = { |
| 46 | "XXXXXXX", "XXXXXXXX", "XXXXXX", "2.5 Mb/s", |
| 47 | "1.25Mb/s", "625 Kb/s", "312.5 Kb/s", "156.25 Kb/s", |
| 48 | "Reserved", "Reserved", "Reserved" |
Joe Perches | 7f5e760 | 2015-05-05 10:05:49 -0700 | [diff] [blame] | 49 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | static void com20020_command(struct net_device *dev, int command); |
| 52 | static int com20020_status(struct net_device *dev); |
| 53 | static void com20020_setmask(struct net_device *dev, int mask); |
| 54 | static int com20020_reset(struct net_device *dev, int really_reset); |
| 55 | static void com20020_copy_to_card(struct net_device *dev, int bufnum, |
| 56 | int offset, void *buf, int count); |
| 57 | static void com20020_copy_from_card(struct net_device *dev, int bufnum, |
| 58 | int offset, void *buf, int count); |
| 59 | static void com20020_set_mc_list(struct net_device *dev); |
| 60 | static void com20020_close(struct net_device *); |
| 61 | |
| 62 | static void com20020_copy_from_card(struct net_device *dev, int bufnum, |
| 63 | int offset, void *buf, int count) |
| 64 | { |
| 65 | int ioaddr = dev->base_addr, ofs = 512 * bufnum + offset; |
| 66 | |
| 67 | /* set up the address register */ |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 68 | arcnet_outb((ofs >> 8) | RDDATAflag | AUTOINCflag, |
| 69 | ioaddr, COM20020_REG_W_ADDR_HI); |
| 70 | arcnet_outb(ofs & 0xff, ioaddr, COM20020_REG_W_ADDR_LO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | /* copy the data */ |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 73 | TIME(dev, "insb", count, |
| 74 | arcnet_insb(ioaddr, COM20020_REG_RW_MEMDATA, buf, count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | static void com20020_copy_to_card(struct net_device *dev, int bufnum, |
| 78 | int offset, void *buf, int count) |
| 79 | { |
| 80 | int ioaddr = dev->base_addr, ofs = 512 * bufnum + offset; |
| 81 | |
| 82 | /* set up the address register */ |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 83 | arcnet_outb((ofs >> 8) | AUTOINCflag, ioaddr, COM20020_REG_W_ADDR_HI); |
| 84 | arcnet_outb(ofs & 0xff, ioaddr, COM20020_REG_W_ADDR_LO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | /* copy the data */ |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 87 | TIME(dev, "outsb", count, |
| 88 | arcnet_outsb(ioaddr, COM20020_REG_RW_MEMDATA, buf, count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* Reset the card and check some basic stuff during the detection stage. */ |
| 92 | int com20020_check(struct net_device *dev) |
| 93 | { |
| 94 | int ioaddr = dev->base_addr, status; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 95 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Michael Grzeschik | 84286f1 | 2015-04-15 11:43:57 +0200 | [diff] [blame] | 97 | arcnet_outb(XTOcfg(3) | RESETcfg, ioaddr, COM20020_REG_W_CONFIG); |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 98 | udelay(5); |
Michael Grzeschik | 84286f1 | 2015-04-15 11:43:57 +0200 | [diff] [blame] | 99 | arcnet_outb(XTOcfg(3), ioaddr, COM20020_REG_W_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | mdelay(RESETtime); |
| 101 | |
| 102 | lp->setup = lp->clockm ? 0 : (lp->clockp << 1); |
| 103 | lp->setup2 = (lp->clockm << 4) | 8; |
| 104 | |
| 105 | /* CHECK: should we do this for SOHARD cards ? */ |
| 106 | /* Enable P1Mode for backplane mode */ |
| 107 | lp->setup = lp->setup | P1MODE; |
| 108 | |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 109 | com20020_set_subaddress(lp, ioaddr, SUB_SETUP1); |
| 110 | arcnet_outb(lp->setup, ioaddr, COM20020_REG_W_XREG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Joe Perches | 7f5e760 | 2015-05-05 10:05:49 -0700 | [diff] [blame] | 112 | if (lp->clockm != 0) { |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 113 | com20020_set_subaddress(lp, ioaddr, SUB_SETUP2); |
| 114 | arcnet_outb(lp->setup2, ioaddr, COM20020_REG_W_XREG); |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | /* must now write the magic "restart operation" command */ |
| 117 | mdelay(1); |
Michael Grzeschik | 84286f1 | 2015-04-15 11:43:57 +0200 | [diff] [blame] | 118 | arcnet_outb(STARTIOcmd, ioaddr, COM20020_REG_W_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Michael Grzeschik | 27daf6e | 2015-03-20 15:20:59 +0100 | [diff] [blame] | 121 | lp->config = (lp->timeout << 3) | (lp->backplane << 2) | SUB_NODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | /* set node ID to 0x42 (but transmitter is disabled, so it's okay) */ |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 123 | arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); |
| 124 | arcnet_outb(0x42, ioaddr, COM20020_REG_W_XREG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 126 | status = arcnet_inb(ioaddr, COM20020_REG_R_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | if ((status & 0x99) != (NORXflag | TXFREEflag | RESETflag)) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 129 | arc_printk(D_NORMAL, dev, "status invalid (%Xh).\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return -ENODEV; |
| 131 | } |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 132 | arc_printk(D_INIT_REASONS, dev, "status after reset: %X\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 134 | arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear, |
| 135 | ioaddr, COM20020_REG_W_COMMAND); |
| 136 | status = arcnet_inb(ioaddr, COM20020_REG_R_STATUS); |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 137 | arc_printk(D_INIT_REASONS, dev, "status after reset acknowledged: %X\n", |
| 138 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | /* Read first location of memory */ |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 141 | arcnet_outb(0 | RDDATAflag | AUTOINCflag, |
| 142 | ioaddr, COM20020_REG_W_ADDR_HI); |
| 143 | arcnet_outb(0, ioaddr, COM20020_REG_W_ADDR_LO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 145 | status = arcnet_inb(ioaddr, COM20020_REG_RW_MEMDATA); |
Joe Perches | 97464ed | 2015-05-05 10:05:59 -0700 | [diff] [blame] | 146 | if (status != TESTvalue) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 147 | arc_printk(D_NORMAL, dev, "Signature byte not found (%02Xh != D1h).\n", |
| 148 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | return -ENODEV; |
| 150 | } |
| 151 | return 0; |
| 152 | } |
| 153 | |
Michael Grzeschik | a0d2e51 | 2014-09-29 11:55:35 +0200 | [diff] [blame] | 154 | static int com20020_set_hwaddr(struct net_device *dev, void *addr) |
| 155 | { |
| 156 | int ioaddr = dev->base_addr; |
| 157 | struct arcnet_local *lp = netdev_priv(dev); |
| 158 | struct sockaddr *hwaddr = addr; |
| 159 | |
| 160 | memcpy(dev->dev_addr, hwaddr->sa_data, 1); |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 161 | com20020_set_subaddress(lp, ioaddr, SUB_NODE); |
| 162 | arcnet_outb(dev->dev_addr[0], ioaddr, COM20020_REG_W_XREG); |
Michael Grzeschik | a0d2e51 | 2014-09-29 11:55:35 +0200 | [diff] [blame] | 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
Michael Grzeschik | 27daf6e | 2015-03-20 15:20:59 +0100 | [diff] [blame] | 167 | static int com20020_netdev_open(struct net_device *dev) |
| 168 | { |
| 169 | int ioaddr = dev->base_addr; |
| 170 | struct arcnet_local *lp = netdev_priv(dev); |
| 171 | |
| 172 | lp->config |= TXENcfg; |
| 173 | arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); |
| 174 | |
| 175 | return arcnet_open(dev); |
| 176 | } |
| 177 | |
| 178 | static int com20020_netdev_close(struct net_device *dev) |
| 179 | { |
| 180 | int ioaddr = dev->base_addr; |
| 181 | struct arcnet_local *lp = netdev_priv(dev); |
| 182 | |
| 183 | arcnet_close(dev); |
| 184 | |
| 185 | /* disable transmitter */ |
| 186 | lp->config &= ~TXENcfg; |
| 187 | arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); |
| 188 | return 0; |
| 189 | } |
| 190 | |
Stephen Hemminger | a1799af | 2009-01-09 13:01:10 +0000 | [diff] [blame] | 191 | const struct net_device_ops com20020_netdev_ops = { |
Michael Grzeschik | 27daf6e | 2015-03-20 15:20:59 +0100 | [diff] [blame] | 192 | .ndo_open = com20020_netdev_open, |
| 193 | .ndo_stop = com20020_netdev_close, |
Stephen Hemminger | a1799af | 2009-01-09 13:01:10 +0000 | [diff] [blame] | 194 | .ndo_start_xmit = arcnet_send_packet, |
| 195 | .ndo_tx_timeout = arcnet_timeout, |
Michael Grzeschik | a0d2e51 | 2014-09-29 11:55:35 +0200 | [diff] [blame] | 196 | .ndo_set_mac_address = com20020_set_hwaddr, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 197 | .ndo_set_rx_mode = com20020_set_mc_list, |
Stephen Hemminger | a1799af | 2009-01-09 13:01:10 +0000 | [diff] [blame] | 198 | }; |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | /* Set up the struct net_device associated with this card. Called after |
| 201 | * probing succeeds. |
| 202 | */ |
| 203 | int com20020_found(struct net_device *dev, int shared) |
| 204 | { |
| 205 | struct arcnet_local *lp; |
| 206 | int ioaddr = dev->base_addr; |
| 207 | |
| 208 | /* Initialize the rest of the device structure. */ |
| 209 | |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 210 | lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | lp->hw.owner = THIS_MODULE; |
| 213 | lp->hw.command = com20020_command; |
| 214 | lp->hw.status = com20020_status; |
| 215 | lp->hw.intmask = com20020_setmask; |
| 216 | lp->hw.reset = com20020_reset; |
| 217 | lp->hw.copy_to_card = com20020_copy_to_card; |
| 218 | lp->hw.copy_from_card = com20020_copy_from_card; |
| 219 | lp->hw.close = com20020_close; |
| 220 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 221 | /* FIXME: do this some other way! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | if (!dev->dev_addr[0]) |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 223 | dev->dev_addr[0] = arcnet_inb(ioaddr, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 225 | com20020_set_subaddress(lp, ioaddr, SUB_SETUP1); |
| 226 | arcnet_outb(lp->setup, ioaddr, COM20020_REG_W_XREG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Joe Perches | 7f5e760 | 2015-05-05 10:05:49 -0700 | [diff] [blame] | 228 | if (lp->card_flags & ARC_CAN_10MBIT) { |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 229 | com20020_set_subaddress(lp, ioaddr, SUB_SETUP2); |
| 230 | arcnet_outb(lp->setup2, ioaddr, COM20020_REG_W_XREG); |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | /* must now write the magic "restart operation" command */ |
| 233 | mdelay(1); |
Michael Grzeschik | 84286f1 | 2015-04-15 11:43:57 +0200 | [diff] [blame] | 234 | arcnet_outb(STARTIOcmd, ioaddr, COM20020_REG_W_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Michael Grzeschik | 27daf6e | 2015-03-20 15:20:59 +0100 | [diff] [blame] | 237 | lp->config = (lp->timeout << 3) | (lp->backplane << 2) | SUB_NODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | /* Default 0x38 + register: Node ID */ |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 239 | arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); |
| 240 | arcnet_outb(dev->dev_addr[0], ioaddr, COM20020_REG_W_XREG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | /* reserve the irq */ |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 243 | if (request_irq(dev->irq, arcnet_interrupt, shared, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | "arcnet (COM20020)", dev)) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 245 | arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | return -ENODEV; |
| 247 | } |
| 248 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 249 | arc_printk(D_NORMAL, dev, "%s: station %02Xh found at %03lXh, IRQ %d.\n", |
| 250 | lp->card_name, dev->dev_addr[0], dev->base_addr, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | if (lp->backplane) |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 253 | arc_printk(D_NORMAL, dev, "Using backplane mode.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | if (lp->timeout != 3) |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 256 | arc_printk(D_NORMAL, dev, "Using extended timeout value of %d\n", |
| 257 | lp->timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 259 | arc_printk(D_NORMAL, dev, "Using CKP %d - data rate %s\n", |
| 260 | lp->setup >> 1, |
Joe Perches | 4e299b9 | 2015-05-05 10:06:04 -0700 | [diff] [blame] | 261 | clockrates[3 - |
| 262 | ((lp->setup2 & 0xF0) >> 4) + |
| 263 | ((lp->setup & 0x0F) >> 1)]); |
| 264 | /* The clockrates array index looks very fragile. |
| 265 | * It seems like it could have negative indexing. |
| 266 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | if (register_netdev(dev)) { |
| 269 | free_irq(dev->irq, dev); |
| 270 | return -EIO; |
| 271 | } |
| 272 | return 0; |
| 273 | } |
| 274 | |
Joe Perches | f2f0a16 | 2015-05-05 10:05:52 -0700 | [diff] [blame] | 275 | /* Do a hardware reset on the card, and set up necessary registers. |
Joe Perches | cb33464 | 2015-05-05 10:05:47 -0700 | [diff] [blame] | 276 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | * This should be called as little as possible, because it disrupts the |
| 278 | * token on the network (causes a RECON) and requires a significant delay. |
| 279 | * |
| 280 | * However, it does make sure the card is in a defined state. |
| 281 | */ |
| 282 | static int com20020_reset(struct net_device *dev, int really_reset) |
| 283 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 284 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | u_int ioaddr = dev->base_addr; |
| 286 | u_char inbyte; |
| 287 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 288 | arc_printk(D_DEBUG, dev, "%s: %d: %s: dev: %p, lp: %p, dev->name: %s\n", |
| 289 | __FILE__, __LINE__, __func__, dev, lp, dev->name); |
| 290 | arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n", |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 291 | dev->name, arcnet_inb(ioaddr, COM20020_REG_R_STATUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 293 | arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); |
Michael Grzeschik | 27daf6e | 2015-03-20 15:20:59 +0100 | [diff] [blame] | 294 | lp->config |= (lp->timeout << 3) | (lp->backplane << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | /* power-up defaults */ |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 296 | arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 297 | arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | if (really_reset) { |
| 300 | /* reset the card */ |
Michael Grzeschik | 84286f1 | 2015-04-15 11:43:57 +0200 | [diff] [blame] | 301 | arcnet_outb(lp->config | RESETcfg, ioaddr, COM20020_REG_W_CONFIG); |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 302 | udelay(5); |
| 303 | arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 304 | mdelay(RESETtime * 2); |
| 305 | /* COM20020 seems to be slower sometimes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | /* clear flags & end reset */ |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 308 | arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 309 | arcnet_outb(CFLAGScmd | RESETclear | CONFIGclear, |
| 310 | ioaddr, COM20020_REG_W_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | /* verify that the ARCnet signature byte is present */ |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 313 | arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | com20020_copy_from_card(dev, 0, 0, &inbyte, 1); |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 316 | arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (inbyte != TESTvalue) { |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 318 | arc_printk(D_DEBUG, dev, "%s: %d: %s\n", |
| 319 | __FILE__, __LINE__, __func__); |
| 320 | arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | return 1; |
| 322 | } |
| 323 | /* enable extended (512-byte) packets */ |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 324 | arcnet_outb(CONFIGcmd | EXTconf, ioaddr, COM20020_REG_W_COMMAND); |
| 325 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 326 | arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | /* done! return success. */ |
| 329 | return 0; |
| 330 | } |
| 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | static void com20020_setmask(struct net_device *dev, int mask) |
| 333 | { |
| 334 | u_int ioaddr = dev->base_addr; |
Joe Perches | 01a1d5a | 2015-05-05 10:05:48 -0700 | [diff] [blame] | 335 | |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 336 | arc_printk(D_DURING, dev, "Setting mask to %x at %x\n", mask, ioaddr); |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 337 | arcnet_outb(mask, ioaddr, COM20020_REG_W_INTMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | static void com20020_command(struct net_device *dev, int cmd) |
| 341 | { |
| 342 | u_int ioaddr = dev->base_addr; |
Joe Perches | 01a1d5a | 2015-05-05 10:05:48 -0700 | [diff] [blame] | 343 | |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 344 | arcnet_outb(cmd, ioaddr, COM20020_REG_W_COMMAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | static int com20020_status(struct net_device *dev) |
| 348 | { |
| 349 | u_int ioaddr = dev->base_addr; |
| 350 | |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 351 | return arcnet_inb(ioaddr, COM20020_REG_R_STATUS) + |
| 352 | (arcnet_inb(ioaddr, COM20020_REG_R_DIAGSTAT) << 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | static void com20020_close(struct net_device *dev) |
| 356 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 357 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | int ioaddr = dev->base_addr; |
| 359 | |
| 360 | /* disable transmitter */ |
| 361 | lp->config &= ~TXENcfg; |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 362 | arcnet_outb(lp->config, ioaddr, COM20020_REG_W_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /* Set or clear the multicast filter for this adaptor. |
| 366 | * num_addrs == -1 Promiscuous mode, receive all packets |
| 367 | * num_addrs == 0 Normal mode, clear multicast list |
| 368 | * num_addrs > 0 Multicast mode, receive normal and MC packets, and do |
| 369 | * best-effort filtering. |
| 370 | * FIXME - do multicast stuff, not just promiscuous. |
| 371 | */ |
| 372 | static void com20020_set_mc_list(struct net_device *dev) |
| 373 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 374 | struct arcnet_local *lp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | int ioaddr = dev->base_addr; |
| 376 | |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 377 | if ((dev->flags & IFF_PROMISC) && (dev->flags & IFF_UP)) { |
| 378 | /* Enable promiscuous mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | if (!(lp->setup & PROMISCset)) |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 380 | arc_printk(D_NORMAL, dev, "Setting promiscuous flag...\n"); |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 381 | com20020_set_subaddress(lp, ioaddr, SUB_SETUP1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | lp->setup |= PROMISCset; |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 383 | arcnet_outb(lp->setup, ioaddr, COM20020_REG_W_XREG); |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 384 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* Disable promiscuous mode, use normal mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | if ((lp->setup & PROMISCset)) |
Joe Perches | a34c093 | 2015-05-05 10:05:55 -0700 | [diff] [blame] | 387 | arc_printk(D_NORMAL, dev, "Resetting promiscuous flag...\n"); |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 388 | com20020_set_subaddress(lp, ioaddr, SUB_SETUP1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | lp->setup &= ~PROMISCset; |
Joe Perches | 0fec651 | 2015-05-05 10:06:06 -0700 | [diff] [blame] | 390 | arcnet_outb(lp->setup, ioaddr, COM20020_REG_W_XREG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
Randy Dunlap | ace48ff | 2006-11-08 19:51:03 -0800 | [diff] [blame] | 394 | #if defined(CONFIG_ARCNET_COM20020_PCI_MODULE) || \ |
Randy Dunlap | 2a10387 | 2007-02-12 00:52:22 -0800 | [diff] [blame] | 395 | defined(CONFIG_ARCNET_COM20020_ISA_MODULE) || \ |
| 396 | defined(CONFIG_ARCNET_COM20020_CS_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | EXPORT_SYMBOL(com20020_check); |
| 398 | EXPORT_SYMBOL(com20020_found); |
David S. Miller | dd0a251 | 2009-01-25 21:17:25 -0800 | [diff] [blame] | 399 | EXPORT_SYMBOL(com20020_netdev_ops); |
Randy Dunlap | ace48ff | 2006-11-08 19:51:03 -0800 | [diff] [blame] | 400 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | MODULE_LICENSE("GPL"); |
| 403 | |
Randy Dunlap | ace48ff | 2006-11-08 19:51:03 -0800 | [diff] [blame] | 404 | #ifdef MODULE |
| 405 | |
Jon Schindler | 0ebd1c1 | 2008-02-28 01:31:08 -0600 | [diff] [blame] | 406 | static int __init com20020_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { |
Joe Perches | 72aeea4 | 2015-05-05 10:05:54 -0700 | [diff] [blame] | 408 | if (BUGLVL(D_NORMAL)) |
Joe Perches | d6d7d3e | 2015-05-05 10:06:02 -0700 | [diff] [blame] | 409 | pr_info("%s\n", "COM20020 chipset support (by David Woodhouse et al.)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | return 0; |
| 411 | } |
| 412 | |
Jon Schindler | 0ebd1c1 | 2008-02-28 01:31:08 -0600 | [diff] [blame] | 413 | static void __exit com20020_module_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
| 415 | } |
Jon Schindler | 0ebd1c1 | 2008-02-28 01:31:08 -0600 | [diff] [blame] | 416 | module_init(com20020_module_init); |
| 417 | module_exit(com20020_module_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | #endif /* MODULE */ |