Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: hamradio: remove support for DMA SCC devices

Another incarnation of Z8530, looks like? Again, no real changes
in the git history, and it needs VIRT_TO_BUS. Unlikely to have
users, let's spend less time refactoring dead code...

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
865e2eb0 bc6df26f

-1486
-1
MAINTAINERS
··· 8766 8766 HIGH-SPEED SCC DRIVER FOR AX.25 8767 8767 L: linux-hams@vger.kernel.org 8768 8768 S: Orphan 8769 - F: drivers/net/hamradio/dmascc.c 8770 8769 F: drivers/net/hamradio/scc.c 8771 8770 8772 8771 HIGHPOINT ROCKETRAID 3xxx RAID DRIVER
-34
drivers/net/hamradio/Kconfig
··· 45 45 useful if some other computer on your local network has a direct 46 46 amateur radio connection. 47 47 48 - config DMASCC 49 - tristate "High-speed (DMA) SCC driver for AX.25" 50 - depends on ISA && AX25 && BROKEN_ON_SMP && ISA_DMA_API 51 - depends on VIRT_TO_BUS 52 - help 53 - This is a driver for high-speed SCC boards, i.e. those supporting 54 - DMA on one port. You usually use those boards to connect your 55 - computer to an amateur radio modem (such as the WA4DSY 56kbps 56 - modem), in order to send and receive AX.25 packet radio network 57 - traffic. 58 - 59 - Currently, this driver supports Ottawa PI/PI2, Paccomm/Gracilis 60 - PackeTwin, and S5SCC/DMA boards. They are detected automatically. 61 - If you have one of these cards, say Y here and read the AX25-HOWTO, 62 - available from <http://www.tldp.org/docs.html#howto>. 63 - 64 - This driver can operate multiple boards simultaneously. If you 65 - compile it as a module (by saying M instead of Y), it will be called 66 - dmascc. If you don't pass any parameter to the driver, all 67 - possible I/O addresses are probed. This could irritate other devices 68 - that are currently not in use. You may specify the list of addresses 69 - to be probed by "dmascc.io=addr1,addr2,..." (when compiled into the 70 - kernel image) or "io=addr1,addr2,..." (when loaded as a module). The 71 - network interfaces will be called dmascc0 and dmascc1 for the board 72 - detected first, dmascc2 and dmascc3 for the second one, and so on. 73 - 74 - Before you configure each interface with ifconfig, you MUST set 75 - certain parameters, such as channel access timing, clock mode, and 76 - DMA channel. This is accomplished with a small utility program, 77 - dmascc_cfg, available at 78 - <http://www.linux-ax25.org/wiki/Ax25-tools>. Please be sure to 79 - get at least version 1.27 of dmascc_cfg, as older versions will not 80 - work with the current driver. 81 - 82 48 config SCC 83 49 tristate "Z8530 SCC driver" 84 50 depends on ISA && AX25 && ISA_DMA_API
-1
drivers/net/hamradio/Makefile
··· 11 11 # Christoph Hellwig <hch@infradead.org> 12 12 # 13 13 14 - obj-$(CONFIG_DMASCC) += dmascc.o 15 14 obj-$(CONFIG_SCC) += scc.o 16 15 obj-$(CONFIG_MKISS) += mkiss.o 17 16 obj-$(CONFIG_6PACK) += 6pack.o
-1450
drivers/net/hamradio/dmascc.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Driver for high-speed SCC boards (those with DMA support) 4 - * Copyright (C) 1997-2000 Klaus Kudielka 5 - * 6 - * S5SCC/DMA support by Janko Koleznik S52HI 7 - */ 8 - 9 - 10 - #include <linux/module.h> 11 - #include <linux/bitops.h> 12 - #include <linux/delay.h> 13 - #include <linux/errno.h> 14 - #include <linux/if_arp.h> 15 - #include <linux/in.h> 16 - #include <linux/init.h> 17 - #include <linux/interrupt.h> 18 - #include <linux/ioport.h> 19 - #include <linux/kernel.h> 20 - #include <linux/mm.h> 21 - #include <linux/netdevice.h> 22 - #include <linux/slab.h> 23 - #include <linux/rtnetlink.h> 24 - #include <linux/sockios.h> 25 - #include <linux/workqueue.h> 26 - #include <linux/atomic.h> 27 - #include <asm/dma.h> 28 - #include <asm/io.h> 29 - #include <asm/irq.h> 30 - #include <linux/uaccess.h> 31 - #include <linux/jiffies.h> 32 - #include <net/ax25.h> 33 - #include "z8530.h" 34 - 35 - 36 - /* Number of buffers per channel */ 37 - 38 - #define NUM_TX_BUF 2 /* NUM_TX_BUF >= 1 (min. 2 recommended) */ 39 - #define NUM_RX_BUF 6 /* NUM_RX_BUF >= 1 (min. 2 recommended) */ 40 - #define BUF_SIZE 1576 /* BUF_SIZE >= mtu + hard_header_len */ 41 - 42 - 43 - /* Cards supported */ 44 - 45 - #define HW_PI { "Ottawa PI", 0x300, 0x20, 0x10, 8, \ 46 - 0, 8, 1843200, 3686400 } 47 - #define HW_PI2 { "Ottawa PI2", 0x300, 0x20, 0x10, 8, \ 48 - 0, 8, 3686400, 7372800 } 49 - #define HW_TWIN { "Gracilis PackeTwin", 0x200, 0x10, 0x10, 32, \ 50 - 0, 4, 6144000, 6144000 } 51 - #define HW_S5 { "S5SCC/DMA", 0x200, 0x10, 0x10, 32, \ 52 - 0, 8, 4915200, 9830400 } 53 - 54 - #define HARDWARE { HW_PI, HW_PI2, HW_TWIN, HW_S5 } 55 - 56 - #define TMR_0_HZ 25600 /* Frequency of timer 0 */ 57 - 58 - #define TYPE_PI 0 59 - #define TYPE_PI2 1 60 - #define TYPE_TWIN 2 61 - #define TYPE_S5 3 62 - #define NUM_TYPES 4 63 - 64 - #define MAX_NUM_DEVS 32 65 - 66 - 67 - /* SCC chips supported */ 68 - 69 - #define Z8530 0 70 - #define Z85C30 1 71 - #define Z85230 2 72 - 73 - #define CHIPNAMES { "Z8530", "Z85C30", "Z85230" } 74 - 75 - 76 - /* I/O registers */ 77 - 78 - /* 8530 registers relative to card base */ 79 - #define SCCB_CMD 0x00 80 - #define SCCB_DATA 0x01 81 - #define SCCA_CMD 0x02 82 - #define SCCA_DATA 0x03 83 - 84 - /* 8253/8254 registers relative to card base */ 85 - #define TMR_CNT0 0x00 86 - #define TMR_CNT1 0x01 87 - #define TMR_CNT2 0x02 88 - #define TMR_CTRL 0x03 89 - 90 - /* Additional PI/PI2 registers relative to card base */ 91 - #define PI_DREQ_MASK 0x04 92 - 93 - /* Additional PackeTwin registers relative to card base */ 94 - #define TWIN_INT_REG 0x08 95 - #define TWIN_CLR_TMR1 0x09 96 - #define TWIN_CLR_TMR2 0x0a 97 - #define TWIN_SPARE_1 0x0b 98 - #define TWIN_DMA_CFG 0x08 99 - #define TWIN_SERIAL_CFG 0x09 100 - #define TWIN_DMA_CLR_FF 0x0a 101 - #define TWIN_SPARE_2 0x0b 102 - 103 - 104 - /* PackeTwin I/O register values */ 105 - 106 - /* INT_REG */ 107 - #define TWIN_SCC_MSK 0x01 108 - #define TWIN_TMR1_MSK 0x02 109 - #define TWIN_TMR2_MSK 0x04 110 - #define TWIN_INT_MSK 0x07 111 - 112 - /* SERIAL_CFG */ 113 - #define TWIN_DTRA_ON 0x01 114 - #define TWIN_DTRB_ON 0x02 115 - #define TWIN_EXTCLKA 0x04 116 - #define TWIN_EXTCLKB 0x08 117 - #define TWIN_LOOPA_ON 0x10 118 - #define TWIN_LOOPB_ON 0x20 119 - #define TWIN_EI 0x80 120 - 121 - /* DMA_CFG */ 122 - #define TWIN_DMA_HDX_T1 0x08 123 - #define TWIN_DMA_HDX_R1 0x0a 124 - #define TWIN_DMA_HDX_T3 0x14 125 - #define TWIN_DMA_HDX_R3 0x16 126 - #define TWIN_DMA_FDX_T3R1 0x1b 127 - #define TWIN_DMA_FDX_T1R3 0x1d 128 - 129 - 130 - /* Status values */ 131 - 132 - #define IDLE 0 133 - #define TX_HEAD 1 134 - #define TX_DATA 2 135 - #define TX_PAUSE 3 136 - #define TX_TAIL 4 137 - #define RTS_OFF 5 138 - #define WAIT 6 139 - #define DCD_ON 7 140 - #define RX_ON 8 141 - #define DCD_OFF 9 142 - 143 - 144 - /* Ioctls */ 145 - 146 - #define SIOCGSCCPARAM SIOCDEVPRIVATE 147 - #define SIOCSSCCPARAM (SIOCDEVPRIVATE+1) 148 - 149 - 150 - /* Data types */ 151 - 152 - struct scc_param { 153 - int pclk_hz; /* frequency of BRG input (don't change) */ 154 - int brg_tc; /* BRG terminal count; BRG disabled if < 0 */ 155 - int nrzi; /* 0 (nrz), 1 (nrzi) */ 156 - int clocks; /* see dmascc_cfg documentation */ 157 - int txdelay; /* [1/TMR_0_HZ] */ 158 - int txtimeout; /* [1/HZ] */ 159 - int txtail; /* [1/TMR_0_HZ] */ 160 - int waittime; /* [1/TMR_0_HZ] */ 161 - int slottime; /* [1/TMR_0_HZ] */ 162 - int persist; /* 1 ... 256 */ 163 - int dma; /* -1 (disable), 0, 1, 3 */ 164 - int txpause; /* [1/TMR_0_HZ] */ 165 - int rtsoff; /* [1/TMR_0_HZ] */ 166 - int dcdon; /* [1/TMR_0_HZ] */ 167 - int dcdoff; /* [1/TMR_0_HZ] */ 168 - }; 169 - 170 - struct scc_hardware { 171 - char *name; 172 - int io_region; 173 - int io_delta; 174 - int io_size; 175 - int num_devs; 176 - int scc_offset; 177 - int tmr_offset; 178 - int tmr_hz; 179 - int pclk_hz; 180 - }; 181 - 182 - struct scc_priv { 183 - int type; 184 - int chip; 185 - struct net_device *dev; 186 - struct scc_info *info; 187 - 188 - int channel; 189 - int card_base, scc_cmd, scc_data; 190 - int tmr_cnt, tmr_ctrl, tmr_mode; 191 - struct scc_param param; 192 - char rx_buf[NUM_RX_BUF][BUF_SIZE]; 193 - int rx_len[NUM_RX_BUF]; 194 - int rx_ptr; 195 - struct work_struct rx_work; 196 - int rx_head, rx_tail, rx_count; 197 - int rx_over; 198 - char tx_buf[NUM_TX_BUF][BUF_SIZE]; 199 - int tx_len[NUM_TX_BUF]; 200 - int tx_ptr; 201 - int tx_head, tx_tail, tx_count; 202 - int state; 203 - unsigned long tx_start; 204 - int rr0; 205 - spinlock_t *register_lock; /* Per scc_info */ 206 - spinlock_t ring_lock; 207 - }; 208 - 209 - struct scc_info { 210 - int irq_used; 211 - int twin_serial_cfg; 212 - struct net_device *dev[2]; 213 - struct scc_priv priv[2]; 214 - struct scc_info *next; 215 - spinlock_t register_lock; /* Per device register lock */ 216 - }; 217 - 218 - 219 - /* Function declarations */ 220 - static int setup_adapter(int card_base, int type, int n) __init; 221 - 222 - static void write_scc(struct scc_priv *priv, int reg, int val); 223 - static void write_scc_data(struct scc_priv *priv, int val, int fast); 224 - static int read_scc(struct scc_priv *priv, int reg); 225 - static int read_scc_data(struct scc_priv *priv); 226 - 227 - static int scc_open(struct net_device *dev); 228 - static int scc_close(struct net_device *dev); 229 - static int scc_siocdevprivate(struct net_device *dev, struct ifreq *ifr, 230 - void __user *data, int cmd); 231 - static int scc_send_packet(struct sk_buff *skb, struct net_device *dev); 232 - static int scc_set_mac_address(struct net_device *dev, void *sa); 233 - 234 - static inline void tx_on(struct scc_priv *priv); 235 - static inline void rx_on(struct scc_priv *priv); 236 - static inline void rx_off(struct scc_priv *priv); 237 - static void start_timer(struct scc_priv *priv, int t, int r15); 238 - static inline unsigned char random(void); 239 - 240 - static inline void z8530_isr(struct scc_info *info); 241 - static irqreturn_t scc_isr(int irq, void *dev_id); 242 - static void rx_isr(struct scc_priv *priv); 243 - static void special_condition(struct scc_priv *priv, int rc); 244 - static void rx_bh(struct work_struct *); 245 - static void tx_isr(struct scc_priv *priv); 246 - static void es_isr(struct scc_priv *priv); 247 - static void tm_isr(struct scc_priv *priv); 248 - 249 - 250 - /* Initialization variables */ 251 - 252 - static int io[MAX_NUM_DEVS] __initdata = { 0, }; 253 - 254 - /* Beware! hw[] is also used in dmascc_exit(). */ 255 - static struct scc_hardware hw[NUM_TYPES] = HARDWARE; 256 - 257 - 258 - /* Global variables */ 259 - 260 - static struct scc_info *first; 261 - static unsigned long rand; 262 - 263 - 264 - MODULE_AUTHOR("Klaus Kudielka"); 265 - MODULE_DESCRIPTION("Driver for high-speed SCC boards"); 266 - module_param_hw_array(io, int, ioport, NULL, 0); 267 - MODULE_LICENSE("GPL"); 268 - 269 - static void __exit dmascc_exit(void) 270 - { 271 - int i; 272 - struct scc_info *info; 273 - 274 - while (first) { 275 - info = first; 276 - 277 - /* Unregister devices */ 278 - for (i = 0; i < 2; i++) 279 - unregister_netdev(info->dev[i]); 280 - 281 - /* Reset board */ 282 - if (info->priv[0].type == TYPE_TWIN) 283 - outb(0, info->dev[0]->base_addr + TWIN_SERIAL_CFG); 284 - write_scc(&info->priv[0], R9, FHWRES); 285 - release_region(info->dev[0]->base_addr, 286 - hw[info->priv[0].type].io_size); 287 - 288 - for (i = 0; i < 2; i++) 289 - free_netdev(info->dev[i]); 290 - 291 - /* Free memory */ 292 - first = info->next; 293 - kfree(info); 294 - } 295 - } 296 - 297 - static int __init dmascc_init(void) 298 - { 299 - int h, i, j, n; 300 - int base[MAX_NUM_DEVS], tcmd[MAX_NUM_DEVS], t0[MAX_NUM_DEVS], 301 - t1[MAX_NUM_DEVS]; 302 - unsigned t_val; 303 - unsigned long time, start[MAX_NUM_DEVS], delay[MAX_NUM_DEVS], 304 - counting[MAX_NUM_DEVS]; 305 - 306 - /* Initialize random number generator */ 307 - rand = jiffies; 308 - /* Cards found = 0 */ 309 - n = 0; 310 - /* Warning message */ 311 - if (!io[0]) 312 - printk(KERN_INFO "dmascc: autoprobing (dangerous)\n"); 313 - 314 - /* Run autodetection for each card type */ 315 - for (h = 0; h < NUM_TYPES; h++) { 316 - 317 - if (io[0]) { 318 - /* User-specified I/O address regions */ 319 - for (i = 0; i < hw[h].num_devs; i++) 320 - base[i] = 0; 321 - for (i = 0; i < MAX_NUM_DEVS && io[i]; i++) { 322 - j = (io[i] - 323 - hw[h].io_region) / hw[h].io_delta; 324 - if (j >= 0 && j < hw[h].num_devs && 325 - hw[h].io_region + 326 - j * hw[h].io_delta == io[i]) { 327 - base[j] = io[i]; 328 - } 329 - } 330 - } else { 331 - /* Default I/O address regions */ 332 - for (i = 0; i < hw[h].num_devs; i++) { 333 - base[i] = 334 - hw[h].io_region + i * hw[h].io_delta; 335 - } 336 - } 337 - 338 - /* Check valid I/O address regions */ 339 - for (i = 0; i < hw[h].num_devs; i++) 340 - if (base[i]) { 341 - if (!request_region 342 - (base[i], hw[h].io_size, "dmascc")) 343 - base[i] = 0; 344 - else { 345 - tcmd[i] = 346 - base[i] + hw[h].tmr_offset + 347 - TMR_CTRL; 348 - t0[i] = 349 - base[i] + hw[h].tmr_offset + 350 - TMR_CNT0; 351 - t1[i] = 352 - base[i] + hw[h].tmr_offset + 353 - TMR_CNT1; 354 - } 355 - } 356 - 357 - /* Start timers */ 358 - for (i = 0; i < hw[h].num_devs; i++) 359 - if (base[i]) { 360 - /* Timer 0: LSB+MSB, Mode 3, TMR_0_HZ */ 361 - outb(0x36, tcmd[i]); 362 - outb((hw[h].tmr_hz / TMR_0_HZ) & 0xFF, 363 - t0[i]); 364 - outb((hw[h].tmr_hz / TMR_0_HZ) >> 8, 365 - t0[i]); 366 - /* Timer 1: LSB+MSB, Mode 0, HZ/10 */ 367 - outb(0x70, tcmd[i]); 368 - outb((TMR_0_HZ / HZ * 10) & 0xFF, t1[i]); 369 - outb((TMR_0_HZ / HZ * 10) >> 8, t1[i]); 370 - start[i] = jiffies; 371 - delay[i] = 0; 372 - counting[i] = 1; 373 - /* Timer 2: LSB+MSB, Mode 0 */ 374 - outb(0xb0, tcmd[i]); 375 - } 376 - time = jiffies; 377 - /* Wait until counter registers are loaded */ 378 - udelay(2000000 / TMR_0_HZ); 379 - 380 - /* Timing loop */ 381 - while (time_is_after_jiffies(time + 13)) { 382 - for (i = 0; i < hw[h].num_devs; i++) 383 - if (base[i] && counting[i]) { 384 - /* Read back Timer 1: latch; read LSB; read MSB */ 385 - outb(0x40, tcmd[i]); 386 - t_val = 387 - inb(t1[i]) + (inb(t1[i]) << 8); 388 - /* Also check whether counter did wrap */ 389 - if (t_val == 0 || 390 - t_val > TMR_0_HZ / HZ * 10) 391 - counting[i] = 0; 392 - delay[i] = jiffies - start[i]; 393 - } 394 - } 395 - 396 - /* Evaluate measurements */ 397 - for (i = 0; i < hw[h].num_devs; i++) 398 - if (base[i]) { 399 - if ((delay[i] >= 9 && delay[i] <= 11) && 400 - /* Ok, we have found an adapter */ 401 - (setup_adapter(base[i], h, n) == 0)) 402 - n++; 403 - else 404 - release_region(base[i], 405 - hw[h].io_size); 406 - } 407 - 408 - } /* NUM_TYPES */ 409 - 410 - /* If any adapter was successfully initialized, return ok */ 411 - if (n) 412 - return 0; 413 - 414 - /* If no adapter found, return error */ 415 - printk(KERN_INFO "dmascc: no adapters found\n"); 416 - return -EIO; 417 - } 418 - 419 - module_init(dmascc_init); 420 - module_exit(dmascc_exit); 421 - 422 - static void __init dev_setup(struct net_device *dev) 423 - { 424 - dev->type = ARPHRD_AX25; 425 - dev->hard_header_len = AX25_MAX_HEADER_LEN; 426 - dev->mtu = 1500; 427 - dev->addr_len = AX25_ADDR_LEN; 428 - dev->tx_queue_len = 64; 429 - memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN); 430 - dev_addr_set(dev, (u8 *)&ax25_defaddr); 431 - } 432 - 433 - static const struct net_device_ops scc_netdev_ops = { 434 - .ndo_open = scc_open, 435 - .ndo_stop = scc_close, 436 - .ndo_start_xmit = scc_send_packet, 437 - .ndo_siocdevprivate = scc_siocdevprivate, 438 - .ndo_set_mac_address = scc_set_mac_address, 439 - }; 440 - 441 - static int __init setup_adapter(int card_base, int type, int n) 442 - { 443 - int i, irq, chip, err; 444 - struct scc_info *info; 445 - struct net_device *dev; 446 - struct scc_priv *priv; 447 - unsigned long time; 448 - unsigned int irqs; 449 - int tmr_base = card_base + hw[type].tmr_offset; 450 - int scc_base = card_base + hw[type].scc_offset; 451 - char *chipnames[] = CHIPNAMES; 452 - 453 - /* Initialize what is necessary for write_scc and write_scc_data */ 454 - info = kzalloc(sizeof(struct scc_info), GFP_KERNEL | GFP_DMA); 455 - if (!info) { 456 - err = -ENOMEM; 457 - goto out; 458 - } 459 - 460 - info->dev[0] = alloc_netdev(0, "", NET_NAME_UNKNOWN, dev_setup); 461 - if (!info->dev[0]) { 462 - printk(KERN_ERR "dmascc: " 463 - "could not allocate memory for %s at %#3x\n", 464 - hw[type].name, card_base); 465 - err = -ENOMEM; 466 - goto out1; 467 - } 468 - 469 - info->dev[1] = alloc_netdev(0, "", NET_NAME_UNKNOWN, dev_setup); 470 - if (!info->dev[1]) { 471 - printk(KERN_ERR "dmascc: " 472 - "could not allocate memory for %s at %#3x\n", 473 - hw[type].name, card_base); 474 - err = -ENOMEM; 475 - goto out2; 476 - } 477 - spin_lock_init(&info->register_lock); 478 - 479 - priv = &info->priv[0]; 480 - priv->type = type; 481 - priv->card_base = card_base; 482 - priv->scc_cmd = scc_base + SCCA_CMD; 483 - priv->scc_data = scc_base + SCCA_DATA; 484 - priv->register_lock = &info->register_lock; 485 - 486 - /* Reset SCC */ 487 - write_scc(priv, R9, FHWRES | MIE | NV); 488 - 489 - /* Determine type of chip by enabling SDLC/HDLC enhancements */ 490 - write_scc(priv, R15, SHDLCE); 491 - if (!read_scc(priv, R15)) { 492 - /* WR7' not present. This is an ordinary Z8530 SCC. */ 493 - chip = Z8530; 494 - } else { 495 - /* Put one character in TX FIFO */ 496 - write_scc_data(priv, 0, 0); 497 - if (read_scc(priv, R0) & Tx_BUF_EMP) { 498 - /* TX FIFO not full. This is a Z85230 ESCC with a 4-byte FIFO. */ 499 - chip = Z85230; 500 - } else { 501 - /* TX FIFO full. This is a Z85C30 SCC with a 1-byte FIFO. */ 502 - chip = Z85C30; 503 - } 504 - } 505 - write_scc(priv, R15, 0); 506 - 507 - /* Start IRQ auto-detection */ 508 - irqs = probe_irq_on(); 509 - 510 - /* Enable interrupts */ 511 - if (type == TYPE_TWIN) { 512 - outb(0, card_base + TWIN_DMA_CFG); 513 - inb(card_base + TWIN_CLR_TMR1); 514 - inb(card_base + TWIN_CLR_TMR2); 515 - info->twin_serial_cfg = TWIN_EI; 516 - outb(info->twin_serial_cfg, card_base + TWIN_SERIAL_CFG); 517 - } else { 518 - write_scc(priv, R15, CTSIE); 519 - write_scc(priv, R0, RES_EXT_INT); 520 - write_scc(priv, R1, EXT_INT_ENAB); 521 - } 522 - 523 - /* Start timer */ 524 - outb(1, tmr_base + TMR_CNT1); 525 - outb(0, tmr_base + TMR_CNT1); 526 - 527 - /* Wait and detect IRQ */ 528 - time = jiffies; 529 - while (time_is_after_jiffies(time + 2 + HZ / TMR_0_HZ)); 530 - irq = probe_irq_off(irqs); 531 - 532 - /* Clear pending interrupt, disable interrupts */ 533 - if (type == TYPE_TWIN) { 534 - inb(card_base + TWIN_CLR_TMR1); 535 - } else { 536 - write_scc(priv, R1, 0); 537 - write_scc(priv, R15, 0); 538 - write_scc(priv, R0, RES_EXT_INT); 539 - } 540 - 541 - if (irq <= 0) { 542 - printk(KERN_ERR 543 - "dmascc: could not find irq of %s at %#3x (irq=%d)\n", 544 - hw[type].name, card_base, irq); 545 - err = -ENODEV; 546 - goto out3; 547 - } 548 - 549 - /* Set up data structures */ 550 - for (i = 0; i < 2; i++) { 551 - dev = info->dev[i]; 552 - priv = &info->priv[i]; 553 - priv->type = type; 554 - priv->chip = chip; 555 - priv->dev = dev; 556 - priv->info = info; 557 - priv->channel = i; 558 - spin_lock_init(&priv->ring_lock); 559 - priv->register_lock = &info->register_lock; 560 - priv->card_base = card_base; 561 - priv->scc_cmd = scc_base + (i ? SCCB_CMD : SCCA_CMD); 562 - priv->scc_data = scc_base + (i ? SCCB_DATA : SCCA_DATA); 563 - priv->tmr_cnt = tmr_base + (i ? TMR_CNT2 : TMR_CNT1); 564 - priv->tmr_ctrl = tmr_base + TMR_CTRL; 565 - priv->tmr_mode = i ? 0xb0 : 0x70; 566 - priv->param.pclk_hz = hw[type].pclk_hz; 567 - priv->param.brg_tc = -1; 568 - priv->param.clocks = TCTRxCP | RCRTxCP; 569 - priv->param.persist = 256; 570 - priv->param.dma = -1; 571 - INIT_WORK(&priv->rx_work, rx_bh); 572 - dev->ml_priv = priv; 573 - snprintf(dev->name, sizeof(dev->name), "dmascc%i", 2 * n + i); 574 - dev->base_addr = card_base; 575 - dev->irq = irq; 576 - dev->netdev_ops = &scc_netdev_ops; 577 - dev->header_ops = &ax25_header_ops; 578 - } 579 - if (register_netdev(info->dev[0])) { 580 - printk(KERN_ERR "dmascc: could not register %s\n", 581 - info->dev[0]->name); 582 - err = -ENODEV; 583 - goto out3; 584 - } 585 - if (register_netdev(info->dev[1])) { 586 - printk(KERN_ERR "dmascc: could not register %s\n", 587 - info->dev[1]->name); 588 - err = -ENODEV; 589 - goto out4; 590 - } 591 - 592 - 593 - info->next = first; 594 - first = info; 595 - printk(KERN_INFO "dmascc: found %s (%s) at %#3x, irq %d\n", 596 - hw[type].name, chipnames[chip], card_base, irq); 597 - return 0; 598 - 599 - out4: 600 - unregister_netdev(info->dev[0]); 601 - out3: 602 - if (info->priv[0].type == TYPE_TWIN) 603 - outb(0, info->dev[0]->base_addr + TWIN_SERIAL_CFG); 604 - write_scc(&info->priv[0], R9, FHWRES); 605 - free_netdev(info->dev[1]); 606 - out2: 607 - free_netdev(info->dev[0]); 608 - out1: 609 - kfree(info); 610 - out: 611 - return err; 612 - } 613 - 614 - 615 - /* Driver functions */ 616 - 617 - static void write_scc(struct scc_priv *priv, int reg, int val) 618 - { 619 - unsigned long flags; 620 - switch (priv->type) { 621 - case TYPE_S5: 622 - if (reg) 623 - outb(reg, priv->scc_cmd); 624 - outb(val, priv->scc_cmd); 625 - return; 626 - case TYPE_TWIN: 627 - if (reg) 628 - outb_p(reg, priv->scc_cmd); 629 - outb_p(val, priv->scc_cmd); 630 - return; 631 - default: 632 - spin_lock_irqsave(priv->register_lock, flags); 633 - outb_p(0, priv->card_base + PI_DREQ_MASK); 634 - if (reg) 635 - outb_p(reg, priv->scc_cmd); 636 - outb_p(val, priv->scc_cmd); 637 - outb(1, priv->card_base + PI_DREQ_MASK); 638 - spin_unlock_irqrestore(priv->register_lock, flags); 639 - return; 640 - } 641 - } 642 - 643 - 644 - static void write_scc_data(struct scc_priv *priv, int val, int fast) 645 - { 646 - unsigned long flags; 647 - switch (priv->type) { 648 - case TYPE_S5: 649 - outb(val, priv->scc_data); 650 - return; 651 - case TYPE_TWIN: 652 - outb_p(val, priv->scc_data); 653 - return; 654 - default: 655 - if (fast) 656 - outb_p(val, priv->scc_data); 657 - else { 658 - spin_lock_irqsave(priv->register_lock, flags); 659 - outb_p(0, priv->card_base + PI_DREQ_MASK); 660 - outb_p(val, priv->scc_data); 661 - outb(1, priv->card_base + PI_DREQ_MASK); 662 - spin_unlock_irqrestore(priv->register_lock, flags); 663 - } 664 - return; 665 - } 666 - } 667 - 668 - 669 - static int read_scc(struct scc_priv *priv, int reg) 670 - { 671 - int rc; 672 - unsigned long flags; 673 - switch (priv->type) { 674 - case TYPE_S5: 675 - if (reg) 676 - outb(reg, priv->scc_cmd); 677 - return inb(priv->scc_cmd); 678 - case TYPE_TWIN: 679 - if (reg) 680 - outb_p(reg, priv->scc_cmd); 681 - return inb_p(priv->scc_cmd); 682 - default: 683 - spin_lock_irqsave(priv->register_lock, flags); 684 - outb_p(0, priv->card_base + PI_DREQ_MASK); 685 - if (reg) 686 - outb_p(reg, priv->scc_cmd); 687 - rc = inb_p(priv->scc_cmd); 688 - outb(1, priv->card_base + PI_DREQ_MASK); 689 - spin_unlock_irqrestore(priv->register_lock, flags); 690 - return rc; 691 - } 692 - } 693 - 694 - 695 - static int read_scc_data(struct scc_priv *priv) 696 - { 697 - int rc; 698 - unsigned long flags; 699 - switch (priv->type) { 700 - case TYPE_S5: 701 - return inb(priv->scc_data); 702 - case TYPE_TWIN: 703 - return inb_p(priv->scc_data); 704 - default: 705 - spin_lock_irqsave(priv->register_lock, flags); 706 - outb_p(0, priv->card_base + PI_DREQ_MASK); 707 - rc = inb_p(priv->scc_data); 708 - outb(1, priv->card_base + PI_DREQ_MASK); 709 - spin_unlock_irqrestore(priv->register_lock, flags); 710 - return rc; 711 - } 712 - } 713 - 714 - 715 - static int scc_open(struct net_device *dev) 716 - { 717 - struct scc_priv *priv = dev->ml_priv; 718 - struct scc_info *info = priv->info; 719 - int card_base = priv->card_base; 720 - 721 - /* Request IRQ if not already used by other channel */ 722 - if (!info->irq_used) { 723 - if (request_irq(dev->irq, scc_isr, 0, "dmascc", info)) { 724 - return -EAGAIN; 725 - } 726 - } 727 - info->irq_used++; 728 - 729 - /* Request DMA if required */ 730 - if (priv->param.dma >= 0) { 731 - if (request_dma(priv->param.dma, "dmascc")) { 732 - if (--info->irq_used == 0) 733 - free_irq(dev->irq, info); 734 - return -EAGAIN; 735 - } else { 736 - unsigned long flags = claim_dma_lock(); 737 - clear_dma_ff(priv->param.dma); 738 - release_dma_lock(flags); 739 - } 740 - } 741 - 742 - /* Initialize local variables */ 743 - priv->rx_ptr = 0; 744 - priv->rx_over = 0; 745 - priv->rx_head = priv->rx_tail = priv->rx_count = 0; 746 - priv->state = IDLE; 747 - priv->tx_head = priv->tx_tail = priv->tx_count = 0; 748 - priv->tx_ptr = 0; 749 - 750 - /* Reset channel */ 751 - write_scc(priv, R9, (priv->channel ? CHRB : CHRA) | MIE | NV); 752 - /* X1 clock, SDLC mode */ 753 - write_scc(priv, R4, SDLC | X1CLK); 754 - /* DMA */ 755 - write_scc(priv, R1, EXT_INT_ENAB | WT_FN_RDYFN); 756 - /* 8 bit RX char, RX disable */ 757 - write_scc(priv, R3, Rx8); 758 - /* 8 bit TX char, TX disable */ 759 - write_scc(priv, R5, Tx8); 760 - /* SDLC address field */ 761 - write_scc(priv, R6, 0); 762 - /* SDLC flag */ 763 - write_scc(priv, R7, FLAG); 764 - switch (priv->chip) { 765 - case Z85C30: 766 - /* Select WR7' */ 767 - write_scc(priv, R15, SHDLCE); 768 - /* Auto EOM reset */ 769 - write_scc(priv, R7, AUTOEOM); 770 - write_scc(priv, R15, 0); 771 - break; 772 - case Z85230: 773 - /* Select WR7' */ 774 - write_scc(priv, R15, SHDLCE); 775 - /* The following bits are set (see 2.5.2.1): 776 - - Automatic EOM reset 777 - - Interrupt request if RX FIFO is half full 778 - This bit should be ignored in DMA mode (according to the 779 - documentation), but actually isn't. The receiver doesn't work if 780 - it is set. Thus, we have to clear it in DMA mode. 781 - - Interrupt/DMA request if TX FIFO is completely empty 782 - a) If set, the ESCC behaves as if it had no TX FIFO (Z85C30 783 - compatibility). 784 - b) If cleared, DMA requests may follow each other very quickly, 785 - filling up the TX FIFO. 786 - Advantage: TX works even in case of high bus latency. 787 - Disadvantage: Edge-triggered DMA request circuitry may miss 788 - a request. No more data is delivered, resulting 789 - in a TX FIFO underrun. 790 - Both PI2 and S5SCC/DMA seem to work fine with TXFIFOE cleared. 791 - The PackeTwin doesn't. I don't know about the PI, but let's 792 - assume it behaves like the PI2. 793 - */ 794 - if (priv->param.dma >= 0) { 795 - if (priv->type == TYPE_TWIN) 796 - write_scc(priv, R7, AUTOEOM | TXFIFOE); 797 - else 798 - write_scc(priv, R7, AUTOEOM); 799 - } else { 800 - write_scc(priv, R7, AUTOEOM | RXFIFOH); 801 - } 802 - write_scc(priv, R15, 0); 803 - break; 804 - } 805 - /* Preset CRC, NRZ(I) encoding */ 806 - write_scc(priv, R10, CRCPS | (priv->param.nrzi ? NRZI : NRZ)); 807 - 808 - /* Configure baud rate generator */ 809 - if (priv->param.brg_tc >= 0) { 810 - /* Program BR generator */ 811 - write_scc(priv, R12, priv->param.brg_tc & 0xFF); 812 - write_scc(priv, R13, (priv->param.brg_tc >> 8) & 0xFF); 813 - /* BRG source = SYS CLK; enable BRG; DTR REQ function (required by 814 - PackeTwin, not connected on the PI2); set DPLL source to BRG */ 815 - write_scc(priv, R14, SSBR | DTRREQ | BRSRC | BRENABL); 816 - /* Enable DPLL */ 817 - write_scc(priv, R14, SEARCH | DTRREQ | BRSRC | BRENABL); 818 - } else { 819 - /* Disable BR generator */ 820 - write_scc(priv, R14, DTRREQ | BRSRC); 821 - } 822 - 823 - /* Configure clocks */ 824 - if (priv->type == TYPE_TWIN) { 825 - /* Disable external TX clock receiver */ 826 - outb((info->twin_serial_cfg &= 827 - ~(priv->channel ? TWIN_EXTCLKB : TWIN_EXTCLKA)), 828 - card_base + TWIN_SERIAL_CFG); 829 - } 830 - write_scc(priv, R11, priv->param.clocks); 831 - if ((priv->type == TYPE_TWIN) && !(priv->param.clocks & TRxCOI)) { 832 - /* Enable external TX clock receiver */ 833 - outb((info->twin_serial_cfg |= 834 - (priv->channel ? TWIN_EXTCLKB : TWIN_EXTCLKA)), 835 - card_base + TWIN_SERIAL_CFG); 836 - } 837 - 838 - /* Configure PackeTwin */ 839 - if (priv->type == TYPE_TWIN) { 840 - /* Assert DTR, enable interrupts */ 841 - outb((info->twin_serial_cfg |= TWIN_EI | 842 - (priv->channel ? TWIN_DTRB_ON : TWIN_DTRA_ON)), 843 - card_base + TWIN_SERIAL_CFG); 844 - } 845 - 846 - /* Read current status */ 847 - priv->rr0 = read_scc(priv, R0); 848 - /* Enable DCD interrupt */ 849 - write_scc(priv, R15, DCDIE); 850 - 851 - netif_start_queue(dev); 852 - 853 - return 0; 854 - } 855 - 856 - 857 - static int scc_close(struct net_device *dev) 858 - { 859 - struct scc_priv *priv = dev->ml_priv; 860 - struct scc_info *info = priv->info; 861 - int card_base = priv->card_base; 862 - 863 - netif_stop_queue(dev); 864 - 865 - if (priv->type == TYPE_TWIN) { 866 - /* Drop DTR */ 867 - outb((info->twin_serial_cfg &= 868 - (priv->channel ? ~TWIN_DTRB_ON : ~TWIN_DTRA_ON)), 869 - card_base + TWIN_SERIAL_CFG); 870 - } 871 - 872 - /* Reset channel, free DMA and IRQ */ 873 - write_scc(priv, R9, (priv->channel ? CHRB : CHRA) | MIE | NV); 874 - if (priv->param.dma >= 0) { 875 - if (priv->type == TYPE_TWIN) 876 - outb(0, card_base + TWIN_DMA_CFG); 877 - free_dma(priv->param.dma); 878 - } 879 - if (--info->irq_used == 0) 880 - free_irq(dev->irq, info); 881 - 882 - return 0; 883 - } 884 - 885 - 886 - static int scc_siocdevprivate(struct net_device *dev, struct ifreq *ifr, void __user *data, int cmd) 887 - { 888 - struct scc_priv *priv = dev->ml_priv; 889 - 890 - switch (cmd) { 891 - case SIOCGSCCPARAM: 892 - if (copy_to_user(data, &priv->param, sizeof(struct scc_param))) 893 - return -EFAULT; 894 - return 0; 895 - case SIOCSSCCPARAM: 896 - if (!capable(CAP_NET_ADMIN)) 897 - return -EPERM; 898 - if (netif_running(dev)) 899 - return -EAGAIN; 900 - if (copy_from_user(&priv->param, data, 901 - sizeof(struct scc_param))) 902 - return -EFAULT; 903 - return 0; 904 - default: 905 - return -EOPNOTSUPP; 906 - } 907 - } 908 - 909 - 910 - static int scc_send_packet(struct sk_buff *skb, struct net_device *dev) 911 - { 912 - struct scc_priv *priv = dev->ml_priv; 913 - unsigned long flags; 914 - int i; 915 - 916 - if (skb->protocol == htons(ETH_P_IP)) 917 - return ax25_ip_xmit(skb); 918 - 919 - /* Temporarily stop the scheduler feeding us packets */ 920 - netif_stop_queue(dev); 921 - 922 - /* Transfer data to DMA buffer */ 923 - i = priv->tx_head; 924 - skb_copy_from_linear_data_offset(skb, 1, priv->tx_buf[i], skb->len - 1); 925 - priv->tx_len[i] = skb->len - 1; 926 - 927 - /* Clear interrupts while we touch our circular buffers */ 928 - 929 - spin_lock_irqsave(&priv->ring_lock, flags); 930 - /* Move the ring buffer's head */ 931 - priv->tx_head = (i + 1) % NUM_TX_BUF; 932 - priv->tx_count++; 933 - 934 - /* If we just filled up the last buffer, leave queue stopped. 935 - The higher layers must wait until we have a DMA buffer 936 - to accept the data. */ 937 - if (priv->tx_count < NUM_TX_BUF) 938 - netif_wake_queue(dev); 939 - 940 - /* Set new TX state */ 941 - if (priv->state == IDLE) { 942 - /* Assert RTS, start timer */ 943 - priv->state = TX_HEAD; 944 - priv->tx_start = jiffies; 945 - write_scc(priv, R5, TxCRC_ENAB | RTS | TxENAB | Tx8); 946 - write_scc(priv, R15, 0); 947 - start_timer(priv, priv->param.txdelay, 0); 948 - } 949 - 950 - /* Turn interrupts back on and free buffer */ 951 - spin_unlock_irqrestore(&priv->ring_lock, flags); 952 - dev_kfree_skb(skb); 953 - 954 - return NETDEV_TX_OK; 955 - } 956 - 957 - 958 - static int scc_set_mac_address(struct net_device *dev, void *sa) 959 - { 960 - dev_addr_set(dev, ((struct sockaddr *)sa)->sa_data); 961 - return 0; 962 - } 963 - 964 - 965 - static inline void tx_on(struct scc_priv *priv) 966 - { 967 - int i, n; 968 - unsigned long flags; 969 - 970 - if (priv->param.dma >= 0) { 971 - n = (priv->chip == Z85230) ? 3 : 1; 972 - /* Program DMA controller */ 973 - flags = claim_dma_lock(); 974 - set_dma_mode(priv->param.dma, DMA_MODE_WRITE); 975 - set_dma_addr(priv->param.dma, 976 - virt_to_bus(priv->tx_buf[priv->tx_tail]) + n); 977 - set_dma_count(priv->param.dma, 978 - priv->tx_len[priv->tx_tail] - n); 979 - release_dma_lock(flags); 980 - /* Enable TX underrun interrupt */ 981 - write_scc(priv, R15, TxUIE); 982 - /* Configure DREQ */ 983 - if (priv->type == TYPE_TWIN) 984 - outb((priv->param.dma == 985 - 1) ? TWIN_DMA_HDX_T1 : TWIN_DMA_HDX_T3, 986 - priv->card_base + TWIN_DMA_CFG); 987 - else 988 - write_scc(priv, R1, 989 - EXT_INT_ENAB | WT_FN_RDYFN | 990 - WT_RDY_ENAB); 991 - /* Write first byte(s) */ 992 - spin_lock_irqsave(priv->register_lock, flags); 993 - for (i = 0; i < n; i++) 994 - write_scc_data(priv, 995 - priv->tx_buf[priv->tx_tail][i], 1); 996 - enable_dma(priv->param.dma); 997 - spin_unlock_irqrestore(priv->register_lock, flags); 998 - } else { 999 - write_scc(priv, R15, TxUIE); 1000 - write_scc(priv, R1, 1001 - EXT_INT_ENAB | WT_FN_RDYFN | TxINT_ENAB); 1002 - tx_isr(priv); 1003 - } 1004 - /* Reset EOM latch if we do not have the AUTOEOM feature */ 1005 - if (priv->chip == Z8530) 1006 - write_scc(priv, R0, RES_EOM_L); 1007 - } 1008 - 1009 - 1010 - static inline void rx_on(struct scc_priv *priv) 1011 - { 1012 - unsigned long flags; 1013 - 1014 - /* Clear RX FIFO */ 1015 - while (read_scc(priv, R0) & Rx_CH_AV) 1016 - read_scc_data(priv); 1017 - priv->rx_over = 0; 1018 - if (priv->param.dma >= 0) { 1019 - /* Program DMA controller */ 1020 - flags = claim_dma_lock(); 1021 - set_dma_mode(priv->param.dma, DMA_MODE_READ); 1022 - set_dma_addr(priv->param.dma, 1023 - virt_to_bus(priv->rx_buf[priv->rx_head])); 1024 - set_dma_count(priv->param.dma, BUF_SIZE); 1025 - release_dma_lock(flags); 1026 - enable_dma(priv->param.dma); 1027 - /* Configure PackeTwin DMA */ 1028 - if (priv->type == TYPE_TWIN) { 1029 - outb((priv->param.dma == 1030 - 1) ? TWIN_DMA_HDX_R1 : TWIN_DMA_HDX_R3, 1031 - priv->card_base + TWIN_DMA_CFG); 1032 - } 1033 - /* Sp. cond. intr. only, ext int enable, RX DMA enable */ 1034 - write_scc(priv, R1, EXT_INT_ENAB | INT_ERR_Rx | 1035 - WT_RDY_RT | WT_FN_RDYFN | WT_RDY_ENAB); 1036 - } else { 1037 - /* Reset current frame */ 1038 - priv->rx_ptr = 0; 1039 - /* Intr. on all Rx characters and Sp. cond., ext int enable */ 1040 - write_scc(priv, R1, EXT_INT_ENAB | INT_ALL_Rx | WT_RDY_RT | 1041 - WT_FN_RDYFN); 1042 - } 1043 - write_scc(priv, R0, ERR_RES); 1044 - write_scc(priv, R3, RxENABLE | Rx8 | RxCRC_ENAB); 1045 - } 1046 - 1047 - 1048 - static inline void rx_off(struct scc_priv *priv) 1049 - { 1050 - /* Disable receiver */ 1051 - write_scc(priv, R3, Rx8); 1052 - /* Disable DREQ / RX interrupt */ 1053 - if (priv->param.dma >= 0 && priv->type == TYPE_TWIN) 1054 - outb(0, priv->card_base + TWIN_DMA_CFG); 1055 - else 1056 - write_scc(priv, R1, EXT_INT_ENAB | WT_FN_RDYFN); 1057 - /* Disable DMA */ 1058 - if (priv->param.dma >= 0) 1059 - disable_dma(priv->param.dma); 1060 - } 1061 - 1062 - 1063 - static void start_timer(struct scc_priv *priv, int t, int r15) 1064 - { 1065 - outb(priv->tmr_mode, priv->tmr_ctrl); 1066 - if (t == 0) { 1067 - tm_isr(priv); 1068 - } else if (t > 0) { 1069 - outb(t & 0xFF, priv->tmr_cnt); 1070 - outb((t >> 8) & 0xFF, priv->tmr_cnt); 1071 - if (priv->type != TYPE_TWIN) { 1072 - write_scc(priv, R15, r15 | CTSIE); 1073 - priv->rr0 |= CTS; 1074 - } 1075 - } 1076 - } 1077 - 1078 - 1079 - static inline unsigned char random(void) 1080 - { 1081 - /* See "Numerical Recipes in C", second edition, p. 284 */ 1082 - rand = rand * 1664525L + 1013904223L; 1083 - return (unsigned char) (rand >> 24); 1084 - } 1085 - 1086 - static inline void z8530_isr(struct scc_info *info) 1087 - { 1088 - int is, i = 100; 1089 - 1090 - while ((is = read_scc(&info->priv[0], R3)) && i--) { 1091 - if (is & CHARxIP) { 1092 - rx_isr(&info->priv[0]); 1093 - } else if (is & CHATxIP) { 1094 - tx_isr(&info->priv[0]); 1095 - } else if (is & CHAEXT) { 1096 - es_isr(&info->priv[0]); 1097 - } else if (is & CHBRxIP) { 1098 - rx_isr(&info->priv[1]); 1099 - } else if (is & CHBTxIP) { 1100 - tx_isr(&info->priv[1]); 1101 - } else { 1102 - es_isr(&info->priv[1]); 1103 - } 1104 - write_scc(&info->priv[0], R0, RES_H_IUS); 1105 - i++; 1106 - } 1107 - if (i < 0) { 1108 - printk(KERN_ERR "dmascc: stuck in ISR with RR3=0x%02x.\n", 1109 - is); 1110 - } 1111 - /* Ok, no interrupts pending from this 8530. The INT line should 1112 - be inactive now. */ 1113 - } 1114 - 1115 - 1116 - static irqreturn_t scc_isr(int irq, void *dev_id) 1117 - { 1118 - struct scc_info *info = dev_id; 1119 - 1120 - spin_lock(info->priv[0].register_lock); 1121 - /* At this point interrupts are enabled, and the interrupt under service 1122 - is already acknowledged, but masked off. 1123 - 1124 - Interrupt processing: We loop until we know that the IRQ line is 1125 - low. If another positive edge occurs afterwards during the ISR, 1126 - another interrupt will be triggered by the interrupt controller 1127 - as soon as the IRQ level is enabled again (see asm/irq.h). 1128 - 1129 - Bottom-half handlers will be processed after scc_isr(). This is 1130 - important, since we only have small ringbuffers and want new data 1131 - to be fetched/delivered immediately. */ 1132 - 1133 - if (info->priv[0].type == TYPE_TWIN) { 1134 - int is, card_base = info->priv[0].card_base; 1135 - while ((is = ~inb(card_base + TWIN_INT_REG)) & 1136 - TWIN_INT_MSK) { 1137 - if (is & TWIN_SCC_MSK) { 1138 - z8530_isr(info); 1139 - } else if (is & TWIN_TMR1_MSK) { 1140 - inb(card_base + TWIN_CLR_TMR1); 1141 - tm_isr(&info->priv[0]); 1142 - } else { 1143 - inb(card_base + TWIN_CLR_TMR2); 1144 - tm_isr(&info->priv[1]); 1145 - } 1146 - } 1147 - } else 1148 - z8530_isr(info); 1149 - spin_unlock(info->priv[0].register_lock); 1150 - return IRQ_HANDLED; 1151 - } 1152 - 1153 - 1154 - static void rx_isr(struct scc_priv *priv) 1155 - { 1156 - if (priv->param.dma >= 0) { 1157 - /* Check special condition and perform error reset. See 2.4.7.5. */ 1158 - special_condition(priv, read_scc(priv, R1)); 1159 - write_scc(priv, R0, ERR_RES); 1160 - } else { 1161 - /* Check special condition for each character. Error reset not necessary. 1162 - Same algorithm for SCC and ESCC. See 2.4.7.1 and 2.4.7.4. */ 1163 - int rc; 1164 - while (read_scc(priv, R0) & Rx_CH_AV) { 1165 - rc = read_scc(priv, R1); 1166 - if (priv->rx_ptr < BUF_SIZE) 1167 - priv->rx_buf[priv->rx_head][priv-> 1168 - rx_ptr++] = 1169 - read_scc_data(priv); 1170 - else { 1171 - priv->rx_over = 2; 1172 - read_scc_data(priv); 1173 - } 1174 - special_condition(priv, rc); 1175 - } 1176 - } 1177 - } 1178 - 1179 - 1180 - static void special_condition(struct scc_priv *priv, int rc) 1181 - { 1182 - int cb; 1183 - unsigned long flags; 1184 - 1185 - /* See Figure 2-15. Only overrun and EOF need to be checked. */ 1186 - 1187 - if (rc & Rx_OVR) { 1188 - /* Receiver overrun */ 1189 - priv->rx_over = 1; 1190 - if (priv->param.dma < 0) 1191 - write_scc(priv, R0, ERR_RES); 1192 - } else if (rc & END_FR) { 1193 - /* End of frame. Get byte count */ 1194 - if (priv->param.dma >= 0) { 1195 - flags = claim_dma_lock(); 1196 - cb = BUF_SIZE - get_dma_residue(priv->param.dma) - 1197 - 2; 1198 - release_dma_lock(flags); 1199 - } else { 1200 - cb = priv->rx_ptr - 2; 1201 - } 1202 - if (priv->rx_over) { 1203 - /* We had an overrun */ 1204 - priv->dev->stats.rx_errors++; 1205 - if (priv->rx_over == 2) 1206 - priv->dev->stats.rx_length_errors++; 1207 - else 1208 - priv->dev->stats.rx_fifo_errors++; 1209 - priv->rx_over = 0; 1210 - } else if (rc & CRC_ERR) { 1211 - /* Count invalid CRC only if packet length >= minimum */ 1212 - if (cb >= 15) { 1213 - priv->dev->stats.rx_errors++; 1214 - priv->dev->stats.rx_crc_errors++; 1215 - } 1216 - } else { 1217 - if (cb >= 15) { 1218 - if (priv->rx_count < NUM_RX_BUF - 1) { 1219 - /* Put good frame in FIFO */ 1220 - priv->rx_len[priv->rx_head] = cb; 1221 - priv->rx_head = 1222 - (priv->rx_head + 1223 - 1) % NUM_RX_BUF; 1224 - priv->rx_count++; 1225 - schedule_work(&priv->rx_work); 1226 - } else { 1227 - priv->dev->stats.rx_errors++; 1228 - priv->dev->stats.rx_over_errors++; 1229 - } 1230 - } 1231 - } 1232 - /* Get ready for new frame */ 1233 - if (priv->param.dma >= 0) { 1234 - flags = claim_dma_lock(); 1235 - set_dma_addr(priv->param.dma, 1236 - virt_to_bus(priv->rx_buf[priv->rx_head])); 1237 - set_dma_count(priv->param.dma, BUF_SIZE); 1238 - release_dma_lock(flags); 1239 - } else { 1240 - priv->rx_ptr = 0; 1241 - } 1242 - } 1243 - } 1244 - 1245 - 1246 - static void rx_bh(struct work_struct *ugli_api) 1247 - { 1248 - struct scc_priv *priv = container_of(ugli_api, struct scc_priv, rx_work); 1249 - int i = priv->rx_tail; 1250 - int cb; 1251 - unsigned long flags; 1252 - struct sk_buff *skb; 1253 - unsigned char *data; 1254 - 1255 - spin_lock_irqsave(&priv->ring_lock, flags); 1256 - while (priv->rx_count) { 1257 - spin_unlock_irqrestore(&priv->ring_lock, flags); 1258 - cb = priv->rx_len[i]; 1259 - /* Allocate buffer */ 1260 - skb = dev_alloc_skb(cb + 1); 1261 - if (skb == NULL) { 1262 - /* Drop packet */ 1263 - priv->dev->stats.rx_dropped++; 1264 - } else { 1265 - /* Fill buffer */ 1266 - data = skb_put(skb, cb + 1); 1267 - data[0] = 0; 1268 - memcpy(&data[1], priv->rx_buf[i], cb); 1269 - skb->protocol = ax25_type_trans(skb, priv->dev); 1270 - netif_rx(skb); 1271 - priv->dev->stats.rx_packets++; 1272 - priv->dev->stats.rx_bytes += cb; 1273 - } 1274 - spin_lock_irqsave(&priv->ring_lock, flags); 1275 - /* Move tail */ 1276 - priv->rx_tail = i = (i + 1) % NUM_RX_BUF; 1277 - priv->rx_count--; 1278 - } 1279 - spin_unlock_irqrestore(&priv->ring_lock, flags); 1280 - } 1281 - 1282 - 1283 - static void tx_isr(struct scc_priv *priv) 1284 - { 1285 - int i = priv->tx_tail, p = priv->tx_ptr; 1286 - 1287 - /* Suspend TX interrupts if we don't want to send anything. 1288 - See Figure 2-22. */ 1289 - if (p == priv->tx_len[i]) { 1290 - write_scc(priv, R0, RES_Tx_P); 1291 - return; 1292 - } 1293 - 1294 - /* Write characters */ 1295 - while ((read_scc(priv, R0) & Tx_BUF_EMP) && p < priv->tx_len[i]) { 1296 - write_scc_data(priv, priv->tx_buf[i][p++], 0); 1297 - } 1298 - 1299 - /* Reset EOM latch of Z8530 */ 1300 - if (!priv->tx_ptr && p && priv->chip == Z8530) 1301 - write_scc(priv, R0, RES_EOM_L); 1302 - 1303 - priv->tx_ptr = p; 1304 - } 1305 - 1306 - 1307 - static void es_isr(struct scc_priv *priv) 1308 - { 1309 - int i, rr0, drr0, res; 1310 - unsigned long flags; 1311 - 1312 - /* Read status, reset interrupt bit (open latches) */ 1313 - rr0 = read_scc(priv, R0); 1314 - write_scc(priv, R0, RES_EXT_INT); 1315 - drr0 = priv->rr0 ^ rr0; 1316 - priv->rr0 = rr0; 1317 - 1318 - /* Transmit underrun (2.4.9.6). We can't check the TxEOM flag, since 1319 - it might have already been cleared again by AUTOEOM. */ 1320 - if (priv->state == TX_DATA) { 1321 - /* Get remaining bytes */ 1322 - i = priv->tx_tail; 1323 - if (priv->param.dma >= 0) { 1324 - disable_dma(priv->param.dma); 1325 - flags = claim_dma_lock(); 1326 - res = get_dma_residue(priv->param.dma); 1327 - release_dma_lock(flags); 1328 - } else { 1329 - res = priv->tx_len[i] - priv->tx_ptr; 1330 - priv->tx_ptr = 0; 1331 - } 1332 - /* Disable DREQ / TX interrupt */ 1333 - if (priv->param.dma >= 0 && priv->type == TYPE_TWIN) 1334 - outb(0, priv->card_base + TWIN_DMA_CFG); 1335 - else 1336 - write_scc(priv, R1, EXT_INT_ENAB | WT_FN_RDYFN); 1337 - if (res) { 1338 - /* Update packet statistics */ 1339 - priv->dev->stats.tx_errors++; 1340 - priv->dev->stats.tx_fifo_errors++; 1341 - /* Other underrun interrupts may already be waiting */ 1342 - write_scc(priv, R0, RES_EXT_INT); 1343 - write_scc(priv, R0, RES_EXT_INT); 1344 - } else { 1345 - /* Update packet statistics */ 1346 - priv->dev->stats.tx_packets++; 1347 - priv->dev->stats.tx_bytes += priv->tx_len[i]; 1348 - /* Remove frame from FIFO */ 1349 - priv->tx_tail = (i + 1) % NUM_TX_BUF; 1350 - priv->tx_count--; 1351 - /* Inform upper layers */ 1352 - netif_wake_queue(priv->dev); 1353 - } 1354 - /* Switch state */ 1355 - write_scc(priv, R15, 0); 1356 - if (priv->tx_count && 1357 - time_is_after_jiffies(priv->tx_start + priv->param.txtimeout)) { 1358 - priv->state = TX_PAUSE; 1359 - start_timer(priv, priv->param.txpause, 0); 1360 - } else { 1361 - priv->state = TX_TAIL; 1362 - start_timer(priv, priv->param.txtail, 0); 1363 - } 1364 - } 1365 - 1366 - /* DCD transition */ 1367 - if (drr0 & DCD) { 1368 - if (rr0 & DCD) { 1369 - switch (priv->state) { 1370 - case IDLE: 1371 - case WAIT: 1372 - priv->state = DCD_ON; 1373 - write_scc(priv, R15, 0); 1374 - start_timer(priv, priv->param.dcdon, 0); 1375 - } 1376 - } else { 1377 - switch (priv->state) { 1378 - case RX_ON: 1379 - rx_off(priv); 1380 - priv->state = DCD_OFF; 1381 - write_scc(priv, R15, 0); 1382 - start_timer(priv, priv->param.dcdoff, 0); 1383 - } 1384 - } 1385 - } 1386 - 1387 - /* CTS transition */ 1388 - if ((drr0 & CTS) && (~rr0 & CTS) && priv->type != TYPE_TWIN) 1389 - tm_isr(priv); 1390 - 1391 - } 1392 - 1393 - 1394 - static void tm_isr(struct scc_priv *priv) 1395 - { 1396 - switch (priv->state) { 1397 - case TX_HEAD: 1398 - case TX_PAUSE: 1399 - tx_on(priv); 1400 - priv->state = TX_DATA; 1401 - break; 1402 - case TX_TAIL: 1403 - write_scc(priv, R5, TxCRC_ENAB | Tx8); 1404 - priv->state = RTS_OFF; 1405 - if (priv->type != TYPE_TWIN) 1406 - write_scc(priv, R15, 0); 1407 - start_timer(priv, priv->param.rtsoff, 0); 1408 - break; 1409 - case RTS_OFF: 1410 - write_scc(priv, R15, DCDIE); 1411 - priv->rr0 = read_scc(priv, R0); 1412 - if (priv->rr0 & DCD) { 1413 - priv->dev->stats.collisions++; 1414 - rx_on(priv); 1415 - priv->state = RX_ON; 1416 - } else { 1417 - priv->state = WAIT; 1418 - start_timer(priv, priv->param.waittime, DCDIE); 1419 - } 1420 - break; 1421 - case WAIT: 1422 - if (priv->tx_count) { 1423 - priv->state = TX_HEAD; 1424 - priv->tx_start = jiffies; 1425 - write_scc(priv, R5, 1426 - TxCRC_ENAB | RTS | TxENAB | Tx8); 1427 - write_scc(priv, R15, 0); 1428 - start_timer(priv, priv->param.txdelay, 0); 1429 - } else { 1430 - priv->state = IDLE; 1431 - if (priv->type != TYPE_TWIN) 1432 - write_scc(priv, R15, DCDIE); 1433 - } 1434 - break; 1435 - case DCD_ON: 1436 - case DCD_OFF: 1437 - write_scc(priv, R15, DCDIE); 1438 - priv->rr0 = read_scc(priv, R0); 1439 - if (priv->rr0 & DCD) { 1440 - rx_on(priv); 1441 - priv->state = RX_ON; 1442 - } else { 1443 - priv->state = WAIT; 1444 - start_timer(priv, 1445 - random() / priv->param.persist * 1446 - priv->param.slottime, DCDIE); 1447 - } 1448 - break; 1449 - } 1450 - }