19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/capability.h>
24 #include <linux/slab.h>
25 #include <linux/types.h>
26 #include <linux/fcntl.h>
28 #include <linux/string.h>
29 #include <linux/errno.h>
33 #include <linux/netdevice.h>
34 #include <linux/hdlc.h>
39 static const char*
version =
"SDL RISCom/N2 driver version: 1.15";
40 static const char* devname =
"RISCom/N2";
45 #define USE_WINDOWSIZE 16384
46 #define USE_BUS16BITS 1
47 #define CLOCK_BASE 9830400
49 #define MAX_RAM_SIZE 0x80000
50 #if MAX_RAM_SIZE > MAX_PAGES * USE_WINDOWSIZE
52 #define MAX_RAM_SIZE (MAX_PAGES * USE_WINDOWSIZE)
54 #define N2_IOPORTS 0x10
55 #define NEED_DETECT_RAM
56 #define NEED_SCA_MSCI_INTR
57 #define MAX_TX_BUFFERS 10
80 #define PSR_WINBITS 0x60
81 #define PSR_DMAEN 0x80
82 #define PSR_PAGEBITS 0x0F
87 #define CLOCK_OUT_PORT1 0x80
88 #define CLOCK_OUT_PORT0 0x40
89 #define TX422_PORT1 0x20
90 #define TX422_PORT0 0x10
91 #define DSR_PORT1 0x08
92 #define DSR_PORT0 0x04
93 #define DTR_PORT1 0x02
94 #define DTR_PORT0 0x01
131 static card_t *first_card;
132 static card_t **new_card = &first_card;
135 #define sca_reg(reg, card) (0x8000 | (card)->io | \
136 ((reg) & 0x0F) | (((reg) & 0xF0) << 6))
137 #define sca_in(reg, card) inb(sca_reg(reg, card))
138 #define sca_out(value, reg, card) outb(value, sca_reg(reg, card))
139 #define sca_inw(reg, card) inw(sca_reg(reg, card))
140 #define sca_outw(value, reg, card) outw(value, sca_reg(reg, card))
142 #define port_to_card(port) ((port)->card)
143 #define log_node(port) ((port)->log_node)
144 #define phy_node(port) ((port)->phy_node)
145 #define winsize(card) (USE_WINDOWSIZE)
146 #define winbase(card) ((card)->winbase)
147 #define get_port(card, port) ((card)->ports[port].valid ? \
148 &(card)->ports[port] : NULL)
214 int io = port->
card->io;
237 int io = port->
card->io;
265 switch(ifr->ifr_settings.type) {
268 if (ifr->ifr_settings.size < size) {
269 ifr->ifr_settings.size =
size;
292 memcpy(&port->settings, &new_line, size);
303 static void n2_destroy_card(
card_t *card)
307 for (cnt = 0; cnt < 2; cnt++)
332 .ndo_stop = n2_close,
335 .ndo_do_ioctl = n2_ioctl,
338 static int __init n2_run(
unsigned long io,
unsigned long irq,
339 unsigned long winbase,
long valid0,
long valid1)
346 pr_err(
"invalid I/O port value\n");
350 if (irq < 3 || irq > 15 || irq == 6) {
351 pr_err(
"invalid IRQ value\n");
355 if (winbase < 0xA0000 || winbase > 0xFFFFF || (winbase & 0xFFF) != 0) {
356 pr_err(
"invalid RAM value\n");
367 pr_err(
"unable to allocate memory\n");
368 n2_destroy_card(card);
373 pr_err(
"I/O port region in use\n");
374 n2_destroy_card(card);
379 if (
request_irq(irq, sca_intr, 0, devname, card)) {
380 pr_err(
"could not allocate IRQ\n");
381 n2_destroy_card(card);
387 pr_err(
"could not request RAM window\n");
388 n2_destroy_card(card);
393 if (!card->winbase) {
394 pr_err(
"ioremap() failed\n");
395 n2_destroy_card(card);
416 pr_err(
"invalid window size\n");
417 n2_destroy_card(card);
424 card->ram_size = sca_detect_ram(card, card->winbase,
MAX_RAM_SIZE);
427 i = card->ram_size / ((valid0 + valid1) * (
sizeof(
pkt_desc) +
431 card->rx_ring_buffers = i - card->tx_ring_buffers;
433 card->buff_offset = (valid0 + valid1) *
sizeof(
pkt_desc) *
434 (card->tx_ring_buffers + card->rx_ring_buffers);
436 pr_info(
"RISCom/N2 %u KB RAM, IRQ%u, using %u TX + %u RX packets rings\n",
437 card->ram_size / 1024, card->
irq,
438 card->tx_ring_buffers, card->rx_ring_buffers);
440 if (card->tx_ring_buffers < 1) {
441 pr_err(
"RAM test failed\n");
442 n2_destroy_card(card);
451 for (cnt = 0; cnt < 2; cnt++) {
456 if ((cnt == 0 && !valid0) || (cnt == 1 && !valid1))
459 port->phy_node =
cnt;
462 if ((cnt == 1) && valid0)
471 hdlc->
attach = sca_attach;
472 hdlc->
xmit = sca_xmit;
477 pr_warn(
"unable to register hdlc device\n");
479 n2_destroy_card(card);
484 netdev_info(dev,
"RISCom/N2 node %d\n", port->phy_node);
488 new_card = &card->next_card;
495 static int __init n2_init(
void)
499 pr_info(
"no card initialized\n");
507 unsigned long io,
irq, ram;
508 long valid[2] = { 0, 0 };
523 if (*
hw ==
'0' && !valid[0])
525 else if (*
hw ==
'1' && !valid[1])
532 if (!valid[0] && !valid[1])
535 if (*
hw ==
':' || *
hw ==
'\x0')
536 n2_run(io, irq, ram, valid[0], valid[1]);
539 return first_card ? 0 : -
EINVAL;
540 }
while(*
hw++ ==
':');
542 pr_err(
"invalid hardware parameters\n");
543 return first_card ? 0 : -
EINVAL;
547 static void __exit n2_cleanup(
void)
549 card_t *card = first_card;
553 card = card->next_card;
554 n2_destroy_card(ptr);