17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/capability.h>
22 #include <linux/slab.h>
23 #include <linux/types.h>
24 #include <linux/string.h>
25 #include <linux/errno.h>
28 #include <linux/netdevice.h>
29 #include <linux/hdlc.h>
36 static const char*
version =
"Moxa C101 driver version: 1.15";
37 static const char* devname =
"C101";
42 #define C101_PAGE 0x1D00
43 #define C101_DTR 0x1E00
44 #define C101_SCA 0x1F00
45 #define C101_WINDOW_SIZE 0x2000
46 #define C101_MAPPED_RAM_SIZE 0x4000
48 #define RAM_SIZE (256 * 1024)
49 #define TX_RING_BUFFERS 10
50 #define RX_RING_BUFFERS ((RAM_SIZE - C101_WINDOW_SIZE) / \
51 (sizeof(pkt_desc) + HDLC_MAX_MRU) - TX_RING_BUFFERS)
53 #define CLOCK_BASE 9830400
54 #define PAGE0_ALWAYS_MAPPED
84 static card_t **new_card = &first_card;
87 #define sca_in(reg, card) readb((card)->win0base + C101_SCA + (reg))
88 #define sca_out(value, reg, card) writeb(value, (card)->win0base + C101_SCA + (reg))
89 #define sca_inw(reg, card) readw((card)->win0base + C101_SCA + (reg))
92 #define sca_outw(value, reg, card) do { \
93 writeb(value & 0xFF, (card)->win0base + C101_SCA + (reg)); \
94 writeb((value >> 8 ) & 0xFF, (card)->win0base + C101_SCA + (reg + 1));\
97 #define port_to_card(port) (port)
98 #define log_node(port) (0)
99 #define phy_node(port) (0)
100 #define winsize(card) (C101_WINDOW_SIZE)
101 #define win0base(card) ((card)->win0base)
102 #define winbase(card) ((card)->win0base + 0x2000)
103 #define get_port(card, port) (card)
131 static void sca_msci_intr(
port_t *port)
153 static void c101_set_iface(
port_t *port)
209 c101_set_iface(port);
247 switch(ifr->ifr_settings.type) {
250 if (ifr->ifr_settings.size < size) {
251 ifr->ifr_settings.size =
size;
274 memcpy(&port->settings, &new_line, size);
275 c101_set_iface(port);
292 if (card->win0base) {
303 .ndo_open = c101_open,
304 .ndo_stop = c101_close,
307 .ndo_do_ioctl = c101_ioctl,
310 static int __init c101_run(
unsigned long irq,
unsigned long winbase)
317 if (irq<3 || irq>15 || irq == 6) {
318 pr_err(
"invalid IRQ value\n");
322 if (winbase < 0xC0000 || winbase > 0xDFFFF || (winbase & 0x3FFF) !=0) {
323 pr_err(
"invalid RAM value\n");
333 pr_err(
"unable to allocate memory\n");
338 if (
request_irq(irq, sca_intr, 0, devname, card)) {
339 pr_err(
"could not allocate IRQ\n");
340 c101_destroy_card(card);
346 pr_err(
"could not request RAM window\n");
347 c101_destroy_card(card);
352 if (!card->win0base) {
353 pr_err(
"could not map I/O address\n");
354 c101_destroy_card(card);
370 hdlc = dev_to_hdlc(dev);
378 hdlc->
attach = sca_attach;
379 hdlc->
xmit = sca_xmit;
384 pr_warn(
"unable to register hdlc device\n");
385 c101_destroy_card(card);
392 netdev_info(dev,
"Moxa C101 on IRQ%u, using %u TX + %u RX packets rings\n",
393 card->
irq, card->tx_ring_buffers, card->rx_ring_buffers);
396 new_card = &card->next_card;
402 static int __init c101_init(
void)
406 pr_info(
"no card initialized\n");
414 unsigned long irq, ram;
422 if (*
hw ==
':' || *
hw ==
'\x0')
426 return first_card ? 0 : -
EINVAL;
427 }
while(*
hw++ ==
':');
429 pr_err(
"invalid hardware parameters\n");
430 return first_card ? 0 : -
EINVAL;
434 static void __exit c101_cleanup(
void)
436 card_t *card = first_card;
440 card = card->next_card;
442 c101_destroy_card(ptr);