This source file includes following definitions.
- sdla_read
- sdla_write
- sdla_clear
- sdla_byte
- sdla_stop
- sdla_start
- sdla_z80_poll
- sdla_cpuspeed
- sdla_errors
- sdla_cmd
- sdla_activate
- sdla_deactivate
- sdla_assoc
- sdla_deassoc
- sdla_dlci_conf
- sdla_transmit
- sdla_receive
- sdla_isr
- sdla_poll
- sdla_close
- sdla_open
- sdla_config
- sdla_xfer
- sdla_reconfig
- sdla_ioctl
- sdla_change_mtu
- sdla_set_config
- sdla_stats
- sdla_init
- sdla_setup
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 #include <linux/module.h>
33
34 #include <linux/kernel.h>
35 #include <linux/sched.h>
36 #include <linux/types.h>
37 #include <linux/fcntl.h>
38 #include <linux/interrupt.h>
39 #include <linux/ptrace.h>
40 #include <linux/ioport.h>
41 #include <linux/in.h>
42 #include <linux/malloc.h>
43 #include <linux/string.h>
44 #include <linux/timer.h>
45 #include <linux/errno.h>
46
47 #include <asm/system.h>
48 #include <asm/bitops.h>
49 #include <asm/io.h>
50 #include <asm/dma.h>
51
52 #include <linux/netdevice.h>
53 #include <linux/skbuff.h>
54 #include <linux/if_arp.h>
55 #include <linux/if_frad.h>
56
57 #include <linux/sdla.h>
58
59 static const char* version = "SDLA driver v0.20, 13 Apr 1996, mike.mclagan@linux.org";
60
61 static const char* devname = "sdla";
62
63 static unsigned int valid_port[] = { 0x250, 0x270, 0x280, 0x300, 0x350, 0x360, 0x380, 0x390};
64
65 static unsigned int valid_mem[] = {0xA0000, 0xA2000, 0xA4000, 0xA6000, 0xA8000, 0xAA000, 0xAC000, 0xAE000,
66 0xB0000, 0xB2000, 0xB4000, 0xB6000, 0xB8000, 0xBA000, 0xBC000, 0xBE000,
67 0xC0000, 0xC2000, 0xC4000, 0xC6000, 0xC8000, 0xCA000, 0xCC000, 0xCE000,
68 0xD0000, 0xD2000, 0xD4000, 0xD6000, 0xD8000, 0xDA000, 0xDC000, 0xDE000,
69 0xE0000, 0xE2000, 0xE4000, 0xE6000, 0xE8000, 0xEA000, 0xEC000, 0xEE000};
70
71
72
73
74
75
76
77 #define SDLA_WINDOW(dev,addr) outb((((addr) >> 13) & 0x1F), (dev)->base_addr + SDLA_REG_Z80_WINDOW)
78
79 static void sdla_read(struct device *dev, int addr, void *buf, short len)
80 {
81 unsigned long flags;
82 char *temp, *base;
83 int offset, bytes;
84
85 temp = buf;
86 while(len)
87 {
88 offset = addr & SDLA_ADDR_MASK;
89 bytes = offset + len > SDLA_WINDOW_SIZE ? SDLA_WINDOW_SIZE - offset : len;
90 base = (void *) (dev->mem_start + offset);
91
92 save_flags(flags);
93 cli();
94 SDLA_WINDOW(dev, addr);
95 memcpy(temp, base, bytes);
96 restore_flags(flags);
97
98 addr += bytes;
99 temp += bytes;
100 len -= bytes;
101 }
102 }
103
104 static void sdla_write(struct device *dev, int addr, void *buf, short len)
105 {
106 unsigned long flags;
107 char *temp, *base;
108 int offset, bytes;
109
110 temp = buf;
111 while(len)
112 {
113 offset = addr & SDLA_ADDR_MASK;
114 bytes = offset + len > SDLA_WINDOW_SIZE ? SDLA_WINDOW_SIZE - offset : len;
115 base = (void *) (dev->mem_start + offset);
116
117 save_flags(flags);
118 cli();
119 SDLA_WINDOW(dev, addr);
120 memcpy(base, temp, bytes);
121 restore_flags(flags);
122
123 addr += bytes;
124 temp += bytes;
125 len -= bytes;
126 }
127 }
128
129 static void sdla_clear(struct device *dev)
130 {
131 unsigned long flags;
132 char *base;
133 int len, addr, bytes;
134
135 len = 65536;
136 addr = 0;
137 bytes = SDLA_WINDOW_SIZE;
138 base = (void *) dev->mem_start;
139
140 save_flags(flags);
141 cli();
142 while(len)
143 {
144 SDLA_WINDOW(dev, addr);
145 memset(base, 0, bytes);
146
147 addr += bytes;
148 len -= bytes;
149 }
150 restore_flags(flags);
151 }
152
153 static char sdla_byte(struct device *dev, int addr)
154 {
155 unsigned long flags;
156 char byte, *temp;
157
158 temp = (void *) (dev->mem_start + (addr & SDLA_ADDR_MASK));
159
160 save_flags(flags);
161 cli();
162 SDLA_WINDOW(dev, addr);
163 byte = *temp;
164 restore_flags(flags);
165
166 return(byte);
167 }
168
169 void sdla_stop(struct device *dev)
170 {
171 struct frad_local *flp;
172
173 flp = dev->priv;
174 switch(flp->type)
175 {
176 case SDLA_S502A:
177 outb(SDLA_S502A_HALT, dev->base_addr + SDLA_REG_CONTROL);
178 flp->state = SDLA_HALT;
179 break;
180 case SDLA_S502E:
181 outb(SDLA_HALT, dev->base_addr + SDLA_REG_Z80_CONTROL);
182 outb(SDLA_S502E_ENABLE, dev->base_addr + SDLA_REG_CONTROL);
183 flp->state = SDLA_S502E_ENABLE;
184 break;
185 case SDLA_S507:
186 flp->state &= ~SDLA_CPUEN;
187 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
188 break;
189 case SDLA_S508:
190 flp->state &= ~SDLA_CPUEN;
191 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
192 break;
193 }
194 }
195
196 void sdla_start(struct device *dev)
197 {
198 struct frad_local *flp;
199
200 flp = dev->priv;
201 switch(flp->type)
202 {
203 case SDLA_S502A:
204 outb(SDLA_S502A_NMI, dev->base_addr + SDLA_REG_CONTROL);
205 outb(SDLA_S502A_START, dev->base_addr + SDLA_REG_CONTROL);
206 flp->state = SDLA_S502A_START;
207 break;
208 case SDLA_S502E:
209 outb(SDLA_S502E_CPUEN, dev->base_addr + SDLA_REG_Z80_CONTROL);
210 outb(0x00, dev->base_addr + SDLA_REG_CONTROL);
211 flp->state = 0;
212 break;
213 case SDLA_S507:
214 flp->state |= SDLA_CPUEN;
215 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
216 break;
217 case SDLA_S508:
218 flp->state |= SDLA_CPUEN;
219 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
220 break;
221 }
222 }
223
224
225
226
227
228
229
230
231
232
233
234 int sdla_z80_poll(struct device *dev, int z80_addr, int jiffs, char resp1, char resp2)
235 {
236 unsigned long start, done, now;
237 char resp, *temp;
238
239 start = now = jiffies;
240 done = jiffies + jiffs;
241
242 temp = (void *)dev->mem_start;
243 temp += z80_addr & SDLA_ADDR_MASK;
244
245 resp = ~resp1;
246 while ((jiffies < done) && (resp != resp1) && (!resp2 || (resp != resp2)))
247 {
248 if (jiffies != now)
249 {
250 SDLA_WINDOW(dev, z80_addr);
251 now = jiffies;
252 resp = *temp;
253 }
254 }
255 return(jiffies < done ? jiffies - start : -1);
256 }
257
258
259 #define Z80_READY '1'
260 #define LOADER_READY '2'
261 #define Z80_SCC_OK '3'
262 #define Z80_SCC_BAD '4'
263
264 static int sdla_cpuspeed(struct device *dev, struct ifreq *ifr)
265 {
266 int jiffs;
267 char data;
268
269 sdla_start(dev);
270 if (sdla_z80_poll(dev, 0, 3*HZ, Z80_READY, 0) < 0)
271 return(-EIO);
272
273 data = LOADER_READY;
274 sdla_write(dev, 0, &data, 1);
275
276 if ((jiffs = sdla_z80_poll(dev, 0, 8*HZ, Z80_SCC_OK, Z80_SCC_BAD)) < 0)
277 return(-EIO);
278
279 sdla_stop(dev);
280 sdla_read(dev, 0, &data, 1);
281
282 if (data == Z80_SCC_BAD)
283 return(-EIO);
284
285 if (data != Z80_SCC_OK)
286 return(-EINVAL);
287
288 if (jiffs < 165)
289 ifr->ifr_mtu = SDLA_CPU_16M;
290 else
291 if (jiffs < 220)
292 ifr->ifr_mtu = SDLA_CPU_10M;
293 else
294 if (jiffs < 258)
295 ifr->ifr_mtu = SDLA_CPU_8M;
296 else
297 if (jiffs < 357)
298 ifr->ifr_mtu = SDLA_CPU_7M;
299 else
300 if (jiffs < 467)
301 ifr->ifr_mtu = SDLA_CPU_5M;
302 else
303 ifr->ifr_mtu = SDLA_CPU_3M;
304
305 return(0);
306 }
307
308
309
310
311
312
313
314
315 struct _dlci_stat {
316 short dlci __attribute__((packed));
317 char flags __attribute__((packed));
318 };
319
320 struct _frad_stat {
321 char flags;
322 struct _dlci_stat dlcis[SDLA_MAX_DLCI];
323 };
324
325 static void sdla_errors(struct device *dev, int cmd, int dlci, int ret, int len, void *data)
326 {
327 struct _dlci_stat *pstatus;
328 short *pdlci;
329 int i;
330 char *state;
331
332 switch (ret)
333 {
334 case SDLA_RET_MODEM:
335 state = data;
336 if (*state & SDLA_MODEM_DCD_LOW)
337 printk(KERN_INFO "%s: Modem DCD unexpectedly low!\n", dev->name);
338 if (*state & SDLA_MODEM_CTS_LOW)
339 printk(KERN_INFO "%s: Modem CTS unexpectedly low!\n", dev->name);
340
341 break;
342
343 case SDLA_RET_CHANNEL_OFF:
344 printk(KERN_INFO "%s: Channel became inoperative!\n", dev->name);
345
346 break;
347
348 case SDLA_RET_CHANNEL_ON:
349 printk(KERN_INFO "%s: Channel became operative!\n", dev->name);
350
351 break;
352
353 case SDLA_RET_DLCI_STATUS:
354 printk(KERN_INFO "%s: Status change reported by Access Node.\n", dev->name);
355 len /= sizeof(struct _dlci_stat);
356 for(pstatus = data, i=0;i < len;i++,pstatus++)
357 {
358 if (pstatus->flags & SDLA_DLCI_NEW)
359 state = "new";
360 else
361 if (pstatus->flags & SDLA_DLCI_DELETED)
362 state = "deleted";
363 else
364 if (pstatus->flags & SDLA_DLCI_ACTIVE)
365 state = "active";
366 else
367 state = "unknown status";
368
369 printk(KERN_INFO "%s: DLCI %i: %s.\n", dev->name, pstatus->dlci, state);
370
371 }
372 break;
373
374 case SDLA_RET_DLCI_UNKNOWN:
375 printk(KERN_INFO "%s: Received unknown DLCIs:", dev->name);
376 len /= sizeof(short);
377 for(pdlci = data,i=0;i < len;i++,pdlci++)
378 printk(" %i", *pdlci);
379 printk("\n");
380 break;
381
382 case SDLA_RET_TIMEOUT:
383 printk(KERN_ERR "%s: Command timed out!\n", dev->name);
384 break;
385
386 case SDLA_RET_BUF_OVERSIZE:
387 printk(KERN_INFO "%s: Bc/CIR overflow, acceptable size is %i\n", dev->name, len);
388 break;
389
390 case SDLA_RET_BUF_TOO_BIG:
391 printk(KERN_INFO "%s: Buffer size over specified max of %i\n", dev->name, len);
392 break;
393
394 case SDLA_RET_CHANNEL_INACTIVE:
395 case SDLA_RET_DLCI_INACTIVE:
396 case SDLA_RET_CIR_OVERFLOW:
397 case SDLA_RET_NO_BUFS:
398 if (cmd == SDLA_INFORMATION_WRITE)
399 break;
400
401 default:
402 printk(KERN_DEBUG "%s: Cmd 0x%2.2X generated return code 0x%2.2X\n", dev->name, cmd, ret);
403
404 break;
405 }
406 }
407
408 static int sdla_cmd(struct device *dev, int cmd, short dlci, short flags,
409 void *inbuf, short inlen, void *outbuf, short *outlen)
410 {
411 static struct _frad_stat status;
412 struct frad_local *flp;
413 struct sdla_cmd *cmd_buf;
414 unsigned long pflags;
415 int jiffs, ret, waiting, len;
416 long window;
417
418 flp = dev->priv;
419
420 window = flp->type == SDLA_S508 ? SDLA_508_CMD_BUF : SDLA_502_CMD_BUF;
421 cmd_buf = (struct sdla_cmd *)(dev->mem_start + (window & SDLA_ADDR_MASK));
422 ret = 0;
423 jiffs = jiffies + HZ;
424 save_flags(pflags);
425 cli();
426 SDLA_WINDOW(dev, window);
427 cmd_buf->cmd = cmd;
428 cmd_buf->dlci = dlci;
429 cmd_buf->flags = flags;
430
431 if (inbuf)
432 memcpy(cmd_buf->data, inbuf, inlen);
433
434 cmd_buf->length = inlen;
435
436 cmd_buf->opp_flag = 1;
437 restore_flags(pflags);
438
439 waiting = 1;
440 len = 0;
441 while (waiting && (jiffies <= jiffs))
442 {
443 if (waiting++ % 3)
444 {
445 save_flags(pflags);
446 cli();
447 SDLA_WINDOW(dev, window);
448 waiting = ((volatile)(cmd_buf->opp_flag));
449 restore_flags(pflags);
450 }
451 }
452
453 if (!waiting)
454 {
455 save_flags(pflags);
456 cli();
457 SDLA_WINDOW(dev, window);
458 ret = cmd_buf->retval;
459 len = cmd_buf->length;
460 if (outbuf && outlen)
461 {
462 *outlen = *outlen >= len ? len : *outlen;
463
464 if (*outlen)
465 memcpy(outbuf, cmd_buf->data, *outlen);
466 }
467
468
469 if (ret)
470 memcpy(&status, cmd_buf->data, len > sizeof(status) ? sizeof(status) : len);
471
472 restore_flags(pflags);
473 }
474 else
475 ret = SDLA_RET_TIMEOUT;
476
477 if (ret != SDLA_RET_OK)
478 sdla_errors(dev, cmd, dlci, ret, len, &status);
479
480 return(ret);
481 }
482
483
484
485
486
487
488
489 static int sdla_reconfig(struct device *dev);
490
491 int sdla_activate(struct device *slave, struct device *master)
492 {
493 struct frad_local *flp;
494 int i;
495
496 flp = slave->priv;
497
498 for(i=0;i<CONFIG_DLCI_MAX;i++)
499 if (flp->master[i] == master)
500 break;
501
502 if (i == CONFIG_DLCI_MAX)
503 return(-ENODEV);
504
505 flp->dlci[i] = abs(flp->dlci[i]);
506
507 if (slave->start && (flp->config.station == FRAD_STATION_NODE))
508 sdla_cmd(slave, SDLA_ACTIVATE_DLCI, 0, 0, &flp->dlci[i], sizeof(short), NULL, NULL);
509
510 return(0);
511 }
512
513 int sdla_deactivate(struct device *slave, struct device *master)
514 {
515 struct frad_local *flp;
516 int i;
517
518 flp = slave->priv;
519
520 for(i=0;i<CONFIG_DLCI_MAX;i++)
521 if (flp->master[i] == master)
522 break;
523
524 if (i == CONFIG_DLCI_MAX)
525 return(-ENODEV);
526
527 flp->dlci[i] = -abs(flp->dlci[i]);
528
529 if (slave->start && (flp->config.station == FRAD_STATION_NODE))
530 sdla_cmd(slave, SDLA_DEACTIVATE_DLCI, 0, 0, &flp->dlci[i], sizeof(short), NULL, NULL);
531
532 return(0);
533 }
534
535 int sdla_assoc(struct device *slave, struct device *master)
536 {
537 struct frad_local *flp;
538 int i;
539
540 if (master->type != ARPHRD_DLCI)
541 return(-EINVAL);
542
543 flp = slave->priv;
544
545 for(i=0;i<CONFIG_DLCI_MAX;i++)
546 {
547 if (!flp->master[i])
548 break;
549 if (abs(flp->dlci[i]) == *(short *)(master->dev_addr))
550 return(-EADDRINUSE);
551 }
552
553 if (i == CONFIG_DLCI_MAX)
554 return(-EMLINK);
555
556 MOD_INC_USE_COUNT;
557
558 flp->master[i] = master;
559 flp->dlci[i] = -*(short *)(master->dev_addr);
560 master->mtu = slave->mtu;
561
562 if (slave->start)
563 if (flp->config.station == FRAD_STATION_CPE)
564 sdla_reconfig(slave);
565 else
566 sdla_cmd(slave, SDLA_ADD_DLCI, 0, 0, master->dev_addr, sizeof(short), NULL, NULL);
567
568 return(0);
569 }
570
571 int sdla_deassoc(struct device *slave, struct device *master)
572 {
573 struct frad_local *flp;
574 int i;
575
576 flp = slave->priv;
577
578 for(i=0;i<CONFIG_DLCI_MAX;i++)
579 if (flp->master[i] == master)
580 break;
581
582 if (i == CONFIG_DLCI_MAX)
583 return(-ENODEV);
584
585 flp->master[i] = NULL;
586 flp->dlci[i] = 0;
587
588 MOD_DEC_USE_COUNT;
589
590 if (slave->start)
591 if (flp->config.station == FRAD_STATION_CPE)
592 sdla_reconfig(slave);
593 else
594 sdla_cmd(slave, SDLA_DELETE_DLCI, 0, 0, master->dev_addr, sizeof(short), NULL, NULL);
595
596 return(0);
597 }
598
599 int sdla_dlci_conf(struct device *slave, struct device *master, int get)
600 {
601 struct frad_local *flp;
602 struct frad_local *dlp;
603 int i;
604 short len, ret;
605
606 flp = slave->priv;
607
608 for(i=0;i<CONFIG_DLCI_MAX;i++)
609 if (flp->master[i] == master)
610 break;
611
612 if (i == CONFIG_DLCI_MAX)
613 return(-ENODEV);
614
615 dlp = master->priv;
616
617 ret = SDLA_RET_OK;
618 len = sizeof(struct dlci_conf);
619 if (slave->start)
620 if (get)
621 ret = sdla_cmd(slave, SDLA_READ_DLCI_CONFIGURATION, abs(flp->dlci[i]), 0,
622 NULL, 0, &dlp->config, &len);
623 else
624 ret = sdla_cmd(slave, SDLA_SET_DLCI_CONFIGURATION, abs(flp->dlci[i]), 0,
625 &dlp->config, sizeof(struct dlci_conf) - 4 * sizeof(short), NULL, NULL);
626
627 return(ret == SDLA_RET_OK ? 0 : -EIO);
628 }
629
630
631
632
633
634
635
636
637 static int sdla_transmit(struct sk_buff *skb, struct device *dev)
638 {
639 struct frad_local *flp;
640 int ret, addr;
641 short size;
642 unsigned long flags;
643 struct buf_entry *pbuf;
644
645 flp = dev->priv;
646 ret = 0;
647
648 if (dev->tbusy)
649 return(1);
650
651 if (skb == NULL)
652 return(0);
653
654 if (set_bit(0, (void*)&dev->tbusy) != 0)
655 printk(KERN_WARNING "%s: transmitter access conflict.\n", dev->name);
656 else
657 {
658
659
660
661
662
663
664
665 switch (dev->type)
666 {
667 case ARPHRD_FRAD:
668 if (skb->dev->type != ARPHRD_DLCI)
669 {
670 printk(KERN_WARNING "%s: FRAD module accepts packets from DLCI ONLY!\n", dev->name);
671 dev_kfree_skb(skb, FREE_WRITE);
672 return(0);
673 }
674 break;
675
676 default:
677 printk(KERN_WARNING "%s: unknown firmware type 0x%4.4X\n", dev->name, dev->type);
678 dev_kfree_skb(skb, FREE_WRITE);
679 return(0);
680 }
681
682
683 switch (flp->type)
684 {
685 case SDLA_S502A:
686 case SDLA_S502E:
687 ret = sdla_cmd(dev, SDLA_INFORMATION_WRITE, *(short *)(skb->dev->dev_addr), 0, skb->data, skb->len, NULL, NULL);
688 break;
689
690 case SDLA_S508:
691 size = sizeof(addr);
692 ret = sdla_cmd(dev, SDLA_INFORMATION_WRITE, *(short *)(skb->dev->dev_addr), 0, NULL, skb->len, &addr, &size);
693 if (ret == SDLA_RET_OK)
694 {
695 save_flags(flags);
696 cli();
697 SDLA_WINDOW(dev, addr);
698 pbuf = (void *)(((int) dev->mem_start) + (addr & SDLA_ADDR_MASK));
699
700 sdla_write(dev, pbuf->buf_addr, skb->data, skb->len);
701
702 SDLA_WINDOW(dev, addr);
703 pbuf->opp_flag = 1;
704 restore_flags(flags);
705 }
706 break;
707 }
708
709 switch (ret)
710 {
711 case SDLA_RET_OK:
712 flp->stats.tx_packets++;
713 ret = DLCI_RET_OK;
714 break;
715
716 case SDLA_RET_CIR_OVERFLOW:
717 case SDLA_RET_BUF_OVERSIZE:
718 case SDLA_RET_NO_BUFS:
719 flp->stats.tx_dropped++;
720 ret = DLCI_RET_DROP;
721 break;
722
723 default:
724 flp->stats.tx_errors++;
725 ret = DLCI_RET_ERR;
726 break;
727 }
728 dev->tbusy = 0;
729 }
730 return(ret);
731 }
732
733 static void sdla_receive(struct device *dev)
734 {
735 struct device *master;
736 struct frad_local *flp;
737 struct dlci_local *dlp;
738 struct sk_buff *skb;
739
740 struct sdla_cmd *cmd;
741 struct buf_info *pbufi;
742 struct buf_entry *pbuf;
743
744 unsigned long flags;
745 int i, received, success, addr, buf_base, buf_top;
746 short dlci, len, len2, split;
747
748 flp = dev->priv;
749 success = 1;
750 received = addr = buf_top = buf_base = 0;
751 len = dlci = 0;
752 skb = NULL;
753 master = NULL;
754 cmd = NULL;
755 pbufi = NULL;
756 pbuf = NULL;
757
758 save_flags(flags);
759 cli();
760
761 switch (flp->type)
762 {
763 case SDLA_S502A:
764 case SDLA_S502E:
765 cmd = (void *) (dev->mem_start + (SDLA_502_RCV_BUF & SDLA_ADDR_MASK));
766 SDLA_WINDOW(dev, SDLA_502_RCV_BUF);
767 success = cmd->opp_flag;
768 if (!success)
769 break;
770
771 dlci = cmd->dlci;
772 len = cmd->length;
773 break;
774
775 case SDLA_S508:
776 pbufi = (void *) (dev->mem_start + (SDLA_508_RXBUF_INFO & SDLA_ADDR_MASK));
777 SDLA_WINDOW(dev, SDLA_508_RXBUF_INFO);
778 pbuf = (void *) (dev->mem_start + ((pbufi->rse_base + flp->buffer * sizeof(struct buf_entry)) & SDLA_ADDR_MASK));
779 success = pbuf->opp_flag;
780 if (!success)
781 break;
782
783 buf_top = pbufi->buf_top;
784 buf_base = pbufi->buf_base;
785 dlci = pbuf->dlci;
786 len = pbuf->length;
787 addr = pbuf->buf_addr;
788 break;
789 }
790
791
792 if (success)
793 {
794 for (i=0;i<CONFIG_DLCI_MAX;i++)
795 if (flp->dlci[i] == dlci)
796 break;
797
798 if (i == CONFIG_DLCI_MAX)
799 {
800 printk(KERN_NOTICE "%s: Received packet from invalid DLCI %i, ignoring.", dev->name, dlci);
801 flp->stats.rx_errors++;
802 success = 0;
803 }
804 }
805
806 if (success)
807 {
808 master = flp->master[i];
809 skb = dev_alloc_skb(len + sizeof(struct frhdr));
810 if (skb == NULL)
811 {
812 printk(KERN_NOTICE "%s: Memory squeeze, dropping packet.\n", dev->name);
813 flp->stats.rx_dropped++;
814 success = 0;
815 }
816 else
817 skb_reserve(skb, sizeof(struct frhdr));
818 }
819
820
821 switch (flp->type)
822 {
823 case SDLA_S502A:
824 case SDLA_S502E:
825 if (success)
826 sdla_read(dev, SDLA_502_RCV_BUF + SDLA_502_DATA_OFS, skb_put(skb,len), len);
827
828 SDLA_WINDOW(dev, SDLA_502_RCV_BUF);
829 cmd->opp_flag = 0;
830 break;
831
832 case SDLA_S508:
833 if (success)
834 {
835
836 split = addr + len > buf_top + 1 ? len - (buf_top - addr + 1) : 0;
837 len2 = len - split;
838
839 sdla_read(dev, addr, skb_put(skb, len2), len2);
840 if (split)
841 sdla_read(dev, buf_base, skb_put(skb, split), split);
842 }
843
844
845 SDLA_WINDOW(dev, SDLA_508_RXBUF_INFO);
846 flp->buffer = (flp->buffer + 1) % pbufi->rse_num;
847 pbuf->opp_flag = 0;
848 break;
849 }
850
851 if (success)
852 {
853 flp->stats.rx_packets++;
854 dlp = master->priv;
855 (*dlp->receive)(skb, master);
856 }
857
858 restore_flags(flags);
859 }
860
861 static void sdla_isr(int irq, void *dev_id, struct pt_regs * regs)
862 {
863 struct device *dev;
864 struct frad_local *flp;
865 char byte;
866
867 dev = irq2dev_map[irq];
868
869 if (dev == NULL)
870 {
871 printk(KERN_WARNING "sdla_isr(): irq %d for unknown device.\n", irq);
872 return;
873 }
874
875 flp = dev->priv;
876
877 if (!flp->initialized)
878 {
879 printk(KERN_WARNING "%s: irq %d for uninitialized device.\n", dev->name, irq);
880 return;
881 }
882
883 dev->interrupt = 1;
884 byte = sdla_byte(dev, flp->type == SDLA_S508 ? SDLA_508_IRQ_INTERFACE : SDLA_502_IRQ_INTERFACE);
885 switch (byte)
886 {
887 case SDLA_INTR_RX:
888 sdla_receive(dev);
889 break;
890
891
892 case SDLA_INTR_MODEM:
893 case SDLA_INTR_STATUS:
894 sdla_cmd(dev, SDLA_READ_DLC_STATUS, 0, 0, NULL, 0, NULL, NULL);
895 break;
896
897 case SDLA_INTR_TX:
898 case SDLA_INTR_COMPLETE:
899 case SDLA_INTR_TIMER:
900 printk(KERN_WARNING "%s: invalid irq flag 0x%02X.\n", dev->name, byte);
901 break;
902 }
903
904
905 if (flp->type == SDLA_S502E)
906 {
907 flp->state &= ~SDLA_S502E_INTACK;
908 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
909 flp->state |= SDLA_S502E_INTACK;
910 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
911 }
912
913
914 byte = 0;
915 sdla_write(dev, flp->type == SDLA_S508 ? SDLA_508_IRQ_INTERFACE : SDLA_502_IRQ_INTERFACE, &byte, sizeof(byte));
916 dev->interrupt = 0;
917 }
918
919 static void sdla_poll(unsigned long device)
920 {
921 struct device *dev;
922 struct frad_local *flp;
923
924 dev = (struct device *) device;
925 flp = dev->priv;
926
927 if (sdla_byte(dev, SDLA_502_RCV_BUF))
928 sdla_receive(dev);
929
930 flp->timer.expires = 1;
931 add_timer(&flp->timer);
932 }
933
934 static int sdla_close(struct device *dev)
935 {
936 struct frad_local *flp;
937 struct intr_info intr;
938 int len, i;
939 short dlcis[CONFIG_DLCI_MAX];
940
941 flp = dev->priv;
942
943 len = 0;
944 for(i=0;i<CONFIG_DLCI_MAX;i++)
945 if (flp->dlci[i])
946 dlcis[len++] = abs(flp->dlci[i]);
947 len *= 2;
948
949 if (flp->config.station == FRAD_STATION_NODE)
950 {
951 for(i=0;i<CONFIG_DLCI_MAX;i++)
952 if (flp->dlci[i] > 0)
953 sdla_cmd(dev, SDLA_DEACTIVATE_DLCI, 0, 0, dlcis, len, NULL, NULL);
954 sdla_cmd(dev, SDLA_DELETE_DLCI, 0, 0, &flp->dlci[i], sizeof(flp->dlci[i]), NULL, NULL);
955 }
956
957 memset(&intr, 0, sizeof(intr));
958
959 switch(flp->type)
960 {
961 case SDLA_S502A:
962 del_timer(&flp->timer);
963 break;
964
965 case SDLA_S502E:
966 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(char) + sizeof(short), NULL, NULL);
967 flp->state &= ~SDLA_S502E_INTACK;
968 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
969 break;
970
971 case SDLA_S507:
972 break;
973
974 case SDLA_S508:
975 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(struct intr_info), NULL, NULL);
976 flp->state &= ~SDLA_S508_INTEN;
977 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
978 break;
979 }
980
981 sdla_cmd(dev, SDLA_DISABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
982
983 dev->tbusy = 1;
984 dev->start = 0;
985
986 MOD_DEC_USE_COUNT;
987
988 return(0);
989 }
990
991 struct conf_data {
992 struct frad_conf config;
993 short dlci[CONFIG_DLCI_MAX];
994 };
995
996 static int sdla_open(struct device *dev)
997 {
998 struct frad_local *flp;
999 struct dlci_local *dlp;
1000 struct conf_data data;
1001 struct intr_info intr;
1002 int len, i;
1003 char byte;
1004
1005 flp = dev->priv;
1006
1007 if (!flp->initialized)
1008 return(-EPERM);
1009
1010 if (!flp->configured)
1011 return(-EPERM);
1012
1013
1014 len = 0;
1015 for(i=0;i<CONFIG_DLCI_MAX;i++)
1016 if (flp->dlci[i])
1017 data.dlci[len++] = abs(flp->dlci[i]);
1018 len *= 2;
1019
1020 memcpy(&data.config, &flp->config, sizeof(struct frad_conf));
1021 len += sizeof(struct frad_conf);
1022
1023 sdla_cmd(dev, SDLA_DISABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1024 sdla_cmd(dev, SDLA_SET_DLCI_CONFIGURATION, 0, 0, &data, len, NULL, NULL);
1025
1026 if (flp->type == SDLA_S508)
1027 flp->buffer = 0;
1028
1029 sdla_cmd(dev, SDLA_ENABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1030
1031
1032 memset(&intr, 0, sizeof(intr));
1033 switch(flp->type)
1034 {
1035 case SDLA_S502A:
1036 flp->timer.expires = 1;
1037 add_timer(&flp->timer);
1038 break;
1039
1040 case SDLA_S502E:
1041 flp->state |= SDLA_S502E_ENABLE;
1042 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
1043 flp->state |= SDLA_S502E_INTACK;
1044 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
1045 byte = 0;
1046 sdla_write(dev, SDLA_502_IRQ_INTERFACE, &byte, sizeof(byte));
1047 intr.flags = SDLA_INTR_RX | SDLA_INTR_STATUS | SDLA_INTR_MODEM;
1048 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(char) + sizeof(short), NULL, NULL);
1049 break;
1050
1051 case SDLA_S507:
1052 break;
1053
1054 case SDLA_S508:
1055 flp->state |= SDLA_S508_INTEN;
1056 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
1057 byte = 0;
1058 sdla_write(dev, SDLA_508_IRQ_INTERFACE, &byte, sizeof(byte));
1059 intr.flags = SDLA_INTR_RX | SDLA_INTR_STATUS | SDLA_INTR_MODEM;
1060 intr.irq = dev->irq;
1061 sdla_cmd(dev, SDLA_SET_IRQ_TRIGGER, 0, 0, &intr, sizeof(struct intr_info), NULL, NULL);
1062 break;
1063 }
1064
1065 if (flp->config.station == FRAD_STATION_CPE)
1066 {
1067 byte = SDLA_ICS_STATUS_ENQ;
1068 sdla_cmd(dev, SDLA_ISSUE_IN_CHANNEL_SIGNAL, 0, 0, &byte, sizeof(byte), NULL, NULL);
1069 }
1070 else
1071 {
1072 sdla_cmd(dev, SDLA_ADD_DLCI, 0, 0, data.dlci, len - sizeof(struct frad_conf), NULL, NULL);
1073 for(i=0;i<CONFIG_DLCI_MAX;i++)
1074 if (flp->dlci[i] > 0)
1075 sdla_cmd(dev, SDLA_ACTIVATE_DLCI, 0, 0, &flp->dlci[i], 2*sizeof(flp->dlci[i]), NULL, NULL);
1076 }
1077
1078
1079 for(i=0;i<CONFIG_DLCI_MAX;i++)
1080 if (flp->dlci[i])
1081 {
1082 dlp = flp->master[i]->priv;
1083 if (dlp->configured)
1084 sdla_cmd(dev, SDLA_SET_DLCI_CONFIGURATION, abs(flp->dlci[i]), 0, &dlp->config, sizeof(struct dlci_conf), NULL, NULL);
1085 }
1086
1087 dev->tbusy = 0;
1088 dev->interrupt = 0;
1089 dev->start = 1;
1090
1091 MOD_INC_USE_COUNT;
1092
1093 return(0);
1094 }
1095
1096 static int sdla_config(struct device *dev, struct frad_conf *conf, int get)
1097 {
1098 struct frad_local *flp;
1099 struct conf_data data;
1100 int i, err;
1101 short size;
1102
1103 if (dev->type == 0xFFFF)
1104 return(-EUNATCH);
1105
1106 flp = dev->priv;
1107
1108 if (!get)
1109 {
1110 if (dev->start)
1111 return(-EBUSY);
1112
1113 err = verify_area(VERIFY_READ, conf, sizeof(struct frad_conf));
1114 if (err)
1115 return(err);
1116
1117 memcpy_fromfs(&data.config, conf, sizeof(struct frad_conf));
1118
1119 if (data.config.station & ~FRAD_STATION_NODE)
1120 return(-EINVAL);
1121
1122 if (data.config.flags & ~FRAD_VALID_FLAGS)
1123 return(-EINVAL);
1124
1125 if ((data.config.kbaud < 0) ||
1126 ((data.config.kbaud > 128) && (flp->type != SDLA_S508)))
1127 return(-EINVAL);
1128
1129 if (data.config.clocking & ~(FRAD_CLOCK_INT | SDLA_S508_PORT_RS232))
1130 return(-EINVAL);
1131
1132 if ((data.config.mtu < 0) || (data.config.mtu > SDLA_MAX_MTU))
1133 return(-EINVAL);
1134
1135 if ((data.config.T391 < 5) || (data.config.T391 > 30))
1136 return(-EINVAL);
1137
1138 if ((data.config.T392 < 5) || (data.config.T392 > 30))
1139 return(-EINVAL);
1140
1141 if ((data.config.N391 < 1) || (data.config.N391 > 255))
1142 return(-EINVAL);
1143
1144 if ((data.config.N392 < 1) || (data.config.N392 > 10))
1145 return(-EINVAL);
1146
1147 if ((data.config.N393 < 1) || (data.config.N393 > 10))
1148 return(-EINVAL);
1149
1150 memcpy(&flp->config, &data.config, sizeof(struct frad_conf));
1151 flp->config.flags |= SDLA_DIRECT_RECV;
1152
1153 if (flp->type == SDLA_S508)
1154 flp->config.flags |= SDLA_TX70_RX30;
1155
1156 if (dev->mtu != flp->config.mtu)
1157 {
1158
1159 dev->mtu = flp->config.mtu;
1160 for(i=0;i<CONFIG_DLCI_MAX;i++)
1161 if (flp->master[i])
1162 flp->master[i]->mtu = flp->config.mtu;
1163 }
1164
1165 flp->config.mtu += sizeof(struct frhdr);
1166
1167
1168 if (!flp->configured)
1169 sdla_start(dev);
1170
1171 flp->configured = 1;
1172 }
1173 else
1174 {
1175 err = verify_area(VERIFY_WRITE, conf, sizeof(struct frad_conf));
1176 if (err)
1177 return(err);
1178
1179
1180 if (dev->start)
1181 {
1182 size = sizeof(data);
1183 if (sdla_cmd(dev, SDLA_READ_DLCI_CONFIGURATION, 0, 0, NULL, 0, &data, &size) != SDLA_RET_OK)
1184 return(-EIO);
1185 }
1186 else
1187 if (flp->configured)
1188 memcpy(&data.config, &flp->config, sizeof(struct frad_conf));
1189 else
1190 memset(&data.config, 0, sizeof(struct frad_conf));
1191
1192 memcpy(&flp->config, &data.config, sizeof(struct frad_conf));
1193 data.config.flags &= FRAD_VALID_FLAGS;
1194 data.config.mtu -= data.config.mtu > sizeof(struct frhdr) ? sizeof(struct frhdr) : data.config.mtu;
1195 memcpy_tofs(conf, &data.config, sizeof(struct frad_conf));
1196 }
1197
1198 return(0);
1199 }
1200
1201 static int sdla_xfer(struct device *dev, struct sdla_mem *info, int read)
1202 {
1203 struct sdla_mem mem;
1204 int err;
1205 char *temp;
1206
1207 err = verify_area(VERIFY_READ, info, sizeof(struct sdla_mem));
1208 if (err)
1209 return(err);
1210
1211 memcpy_fromfs(&mem, info, sizeof(mem));
1212 if (read)
1213 {
1214 err = verify_area(VERIFY_WRITE, mem.data, mem.len);
1215 if (err)
1216 return(err);
1217
1218 temp = kmalloc(mem.len, GFP_KERNEL);
1219 if (!temp)
1220 return(-ENOMEM);
1221 sdla_read(dev, mem.addr, temp, mem.len);
1222 memcpy_tofs(mem.data, temp, mem.len);
1223 kfree(temp);
1224 }
1225 else
1226 {
1227 err = verify_area(VERIFY_READ, mem.data, mem.len);
1228 if (err)
1229 return(err);
1230
1231 temp = kmalloc(mem.len, GFP_KERNEL);
1232 if (!temp)
1233 return(-ENOMEM);
1234 memcpy_fromfs(temp, mem.data, mem.len);
1235 sdla_write(dev, mem.addr, temp, mem.len);
1236 kfree(temp);
1237 }
1238 return(0);
1239 }
1240
1241 static int sdla_reconfig(struct device *dev)
1242 {
1243 struct frad_local *flp;
1244 struct conf_data data;
1245 int i, len;
1246
1247 flp = dev->priv;
1248
1249 len = 0;
1250 for(i=0;i<CONFIG_DLCI_MAX;i++)
1251 if (flp->dlci[i])
1252 data.dlci[len++] = flp->dlci[i];
1253 len *= 2;
1254
1255 memcpy(&data, &flp->config, sizeof(struct frad_conf));
1256 len += sizeof(struct frad_conf);
1257
1258 sdla_cmd(dev, SDLA_DISABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1259 sdla_cmd(dev, SDLA_SET_DLCI_CONFIGURATION, 0, 0, &data, len, NULL, NULL);
1260 sdla_cmd(dev, SDLA_ENABLE_COMMUNICATIONS, 0, 0, NULL, 0, NULL, NULL);
1261
1262 return(0);
1263 }
1264
1265 static int sdla_ioctl(struct device *dev, struct ifreq *ifr, int cmd)
1266 {
1267 struct frad_local *flp;
1268
1269 flp = dev->priv;
1270
1271 if (!flp->initialized)
1272 return(-EPERM);
1273
1274 switch (cmd)
1275 {
1276 case FRAD_GET_CONF:
1277 case FRAD_SET_CONF:
1278 return(sdla_config(dev, (struct frad_conf *)ifr->ifr_data, cmd == FRAD_GET_CONF));
1279
1280 case SDLA_IDENTIFY:
1281 ifr->ifr_flags = flp->type;
1282 break;
1283
1284 case SDLA_CPUSPEED:
1285 return(sdla_cpuspeed(dev, ifr));
1286
1287
1288
1289
1290
1291
1292
1293 case SDLA_PROTOCOL:
1294 if (flp->configured)
1295 return(-EALREADY);
1296
1297 switch (ifr->ifr_flags)
1298 {
1299 case ARPHRD_FRAD:
1300 dev->type = ifr->ifr_flags;
1301 dev->family = AF_UNSPEC;
1302 break;
1303
1304 default:
1305 return(-ENOPROTOOPT);
1306 }
1307 break;
1308
1309 case SDLA_CLEARMEM:
1310 sdla_clear(dev);
1311 break;
1312
1313 case SDLA_WRITEMEM:
1314 case SDLA_READMEM:
1315 return(sdla_xfer(dev, (struct sdla_mem *)ifr->ifr_data, cmd == SDLA_READMEM));
1316
1317 case SDLA_START:
1318 sdla_start(dev);
1319 break;
1320
1321 case SDLA_STOP:
1322 sdla_stop(dev);
1323 break;
1324
1325 default:
1326 return(-EOPNOTSUPP);
1327 }
1328 return(0);
1329 }
1330
1331 int sdla_change_mtu(struct device *dev, int new_mtu)
1332 {
1333 struct frad_local *flp;
1334
1335 flp = dev->priv;
1336
1337 if (dev->start)
1338 return(-EBUSY);
1339
1340
1341 return(-EACCES);
1342 }
1343
1344 int sdla_set_config(struct device *dev, struct ifmap *map)
1345 {
1346 struct frad_local *flp;
1347 int i;
1348 char byte;
1349
1350 flp = dev->priv;
1351
1352 if (flp->initialized)
1353 return(-EINVAL);
1354
1355 for(i=0;i < sizeof(valid_port) / sizeof (int) ; i++)
1356 if (valid_port[i] == map->base_addr)
1357 break;
1358
1359 if (i == sizeof(valid_port) / sizeof(int))
1360 return(-EINVAL);
1361
1362 dev->base_addr = map->base_addr;
1363 request_region(dev->base_addr, SDLA_IO_EXTENTS, dev->name);
1364
1365
1366
1367 flp->type = SDLA_UNKNOWN;
1368 flp->state = 0;
1369
1370 for(i=1;i<SDLA_IO_EXTENTS;i++)
1371 if (inb(dev->base_addr + i) != 0xFF)
1372 break;
1373
1374 if (i == SDLA_IO_EXTENTS)
1375 {
1376 outb(SDLA_HALT, dev->base_addr + SDLA_REG_Z80_CONTROL);
1377 if ((inb(dev->base_addr + SDLA_S502_STS) & 0x0F) == 0x08)
1378 {
1379 outb(SDLA_S502E_INTACK, dev->base_addr + SDLA_REG_CONTROL);
1380 if ((inb(dev->base_addr + SDLA_S502_STS) & 0x0F) == 0x0C)
1381 {
1382 outb(SDLA_HALT, dev->base_addr + SDLA_REG_CONTROL);
1383 flp->type = SDLA_S502E;
1384 }
1385 }
1386 }
1387
1388 if (flp->type == SDLA_UNKNOWN)
1389 {
1390 for(byte=inb(dev->base_addr),i=0;i<SDLA_IO_EXTENTS;i++)
1391 if (inb(dev->base_addr + i) != byte)
1392 break;
1393
1394 if (i == SDLA_IO_EXTENTS)
1395 {
1396 outb(SDLA_HALT, dev->base_addr + SDLA_REG_CONTROL);
1397 if ((inb(dev->base_addr + SDLA_S502_STS) & 0x7E) == 0x30)
1398 {
1399 outb(SDLA_S507_ENABLE, dev->base_addr + SDLA_REG_CONTROL);
1400 if ((inb(dev->base_addr + SDLA_S502_STS) & 0x7E) == 0x32)
1401 {
1402 outb(SDLA_HALT, dev->base_addr + SDLA_REG_CONTROL);
1403 flp->type = SDLA_S507;
1404 }
1405 }
1406 }
1407 }
1408
1409 if (flp->type == SDLA_UNKNOWN)
1410 {
1411 outb(SDLA_HALT, dev->base_addr + SDLA_REG_CONTROL);
1412 if ((inb(dev->base_addr + SDLA_S508_STS) & 0x3F) == 0x00)
1413 {
1414 outb(SDLA_S508_INTEN, dev->base_addr + SDLA_REG_CONTROL);
1415 if ((inb(dev->base_addr + SDLA_S508_STS) & 0x3F) == 0x10)
1416 {
1417 outb(SDLA_HALT, dev->base_addr + SDLA_REG_CONTROL);
1418 flp->type = SDLA_S508;
1419 }
1420 }
1421 }
1422
1423 if (flp->type == SDLA_UNKNOWN)
1424 {
1425 outb(SDLA_S502A_HALT, dev->base_addr + SDLA_REG_CONTROL);
1426 if (inb(dev->base_addr + SDLA_S502_STS) == 0x40)
1427 {
1428 outb(SDLA_S502A_START, dev->base_addr + SDLA_REG_CONTROL);
1429 if (inb(dev->base_addr + SDLA_S502_STS) == 0x40)
1430 {
1431 outb(SDLA_S502A_INTEN, dev->base_addr + SDLA_REG_CONTROL);
1432 if (inb(dev->base_addr + SDLA_S502_STS) == 0x44)
1433 {
1434 outb(SDLA_S502A_START, dev->base_addr + SDLA_REG_CONTROL);
1435 flp->type = SDLA_S502A;
1436 }
1437 }
1438 }
1439 }
1440
1441 if (flp->type == SDLA_UNKNOWN)
1442 {
1443 printk(KERN_NOTICE "%s: Unknown card type\n", dev->name);
1444 return(-ENODEV);
1445 }
1446
1447 switch(dev->base_addr)
1448 {
1449 case 0x270:
1450 case 0x280:
1451 case 0x380:
1452 case 0x390:
1453 if ((flp->type != SDLA_S508) && (flp->type != SDLA_S507))
1454 return(-EINVAL);
1455 }
1456
1457 switch (map->irq)
1458 {
1459 case 2:
1460 if (flp->type != SDLA_S502E)
1461 return(-EINVAL);
1462 break;
1463
1464 case 10:
1465 case 11:
1466 case 12:
1467 case 15:
1468 case 4:
1469 if ((flp->type != SDLA_S508) && (flp->type != SDLA_S507))
1470 return(-EINVAL);
1471
1472 case 3:
1473 case 5:
1474 case 7:
1475 if (flp->type == SDLA_S502A)
1476 return(-EINVAL);
1477 break;
1478
1479 default:
1480 return(-EINVAL);
1481 }
1482 dev->irq = map->irq;
1483
1484 if (request_irq(dev->irq, &sdla_isr, 0, dev->name, NULL))
1485 return(-EADDRINUSE);
1486
1487 irq2dev_map[dev->irq] = dev;
1488
1489 if (flp->type == SDLA_S507)
1490 {
1491 switch(dev->irq)
1492 {
1493 case 3:
1494 flp->state = SDLA_S507_IRQ3;
1495 break;
1496 case 4:
1497 flp->state = SDLA_S507_IRQ4;
1498 break;
1499 case 5:
1500 flp->state = SDLA_S507_IRQ5;
1501 break;
1502 case 7:
1503 flp->state = SDLA_S507_IRQ7;
1504 break;
1505 case 10:
1506 flp->state = SDLA_S507_IRQ10;
1507 break;
1508 case 11:
1509 flp->state = SDLA_S507_IRQ11;
1510 break;
1511 case 12:
1512 flp->state = SDLA_S507_IRQ12;
1513 break;
1514 case 15:
1515 flp->state = SDLA_S507_IRQ15;
1516 break;
1517 }
1518 }
1519
1520 for(i=0;i < sizeof(valid_mem) / sizeof (int) ; i++)
1521 if (valid_mem[i] == map->mem_start)
1522 break;
1523
1524 if (i == sizeof(valid_mem) / sizeof(int))
1525 return(-EINVAL);
1526
1527 if ((flp->type == SDLA_S502A) && (((map->mem_start & 0xF000) >> 12) == 0x0E))
1528 return(-EINVAL);
1529
1530 if ((flp->type != SDLA_S507) && ((map->mem_start >> 16) == 0x0B))
1531 return(-EINVAL);
1532
1533 if ((flp->type == SDLA_S507) && ((map->mem_start >> 16) == 0x0D))
1534 return(-EINVAL);
1535
1536 dev->mem_start = map->mem_start;
1537 dev->mem_end = dev->mem_start + 0x2000;
1538
1539 byte = flp->type != SDLA_S508 ? SDLA_8K_WINDOW : 0;
1540 byte |= (map->mem_start & 0xF000) >> (12 + (flp->type == SDLA_S508 ? 1 : 0));
1541 switch(flp->type)
1542 {
1543 case SDLA_S502A:
1544 case SDLA_S502E:
1545 switch (map->mem_start >> 16)
1546 {
1547 case 0x0A:
1548 byte |= SDLA_S502_SEG_A;
1549 break;
1550 case 0x0C:
1551 byte |= SDLA_S502_SEG_C;
1552 break;
1553 case 0x0D:
1554 byte |= SDLA_S502_SEG_D;
1555 break;
1556 case 0x0E:
1557 byte |= SDLA_S502_SEG_E;
1558 break;
1559 }
1560 break;
1561 case SDLA_S507:
1562 switch (map->mem_start >> 16)
1563 {
1564 case 0x0A:
1565 byte |= SDLA_S507_SEG_A;
1566 break;
1567 case 0x0B:
1568 byte |= SDLA_S507_SEG_B;
1569 break;
1570 case 0x0C:
1571 byte |= SDLA_S507_SEG_C;
1572 break;
1573 case 0x0E:
1574 byte |= SDLA_S507_SEG_E;
1575 break;
1576 }
1577 break;
1578 case SDLA_S508:
1579 switch (map->mem_start >> 16)
1580 {
1581 case 0x0A:
1582 byte |= SDLA_S508_SEG_A;
1583 break;
1584 case 0x0C:
1585 byte |= SDLA_S508_SEG_C;
1586 break;
1587 case 0x0D:
1588 byte |= SDLA_S508_SEG_D;
1589 break;
1590 case 0x0E:
1591 byte |= SDLA_S508_SEG_E;
1592 break;
1593 }
1594 break;
1595 }
1596
1597
1598 outb(byte, dev->base_addr + SDLA_REG_PC_WINDOW);
1599 switch(flp->type)
1600 {
1601 case SDLA_S502E:
1602 flp->state = SDLA_S502E_ENABLE;
1603 break;
1604 case SDLA_S507:
1605 flp->state |= SDLA_MEMEN;
1606 break;
1607 case SDLA_S508:
1608 flp->state = SDLA_MEMEN;
1609 break;
1610 }
1611 outb(flp->state, dev->base_addr + SDLA_REG_CONTROL);
1612
1613 flp->initialized = 1;
1614 return(0);
1615 }
1616
1617 static struct enet_statistics *sdla_stats(struct device *dev)
1618 {
1619 struct frad_local *flp;
1620
1621 flp = dev->priv;
1622
1623 return(&flp->stats);
1624 }
1625
1626 int sdla_init(struct device *dev)
1627 {
1628 struct frad_local *flp;
1629 int i;
1630
1631
1632 flp = kmalloc(sizeof(struct frad_local), GFP_KERNEL);
1633 if (!flp)
1634 return(-ENOMEM);
1635
1636 memset(flp, 0, sizeof(struct frad_local));
1637 dev->priv = flp;
1638
1639 dev->flags = 0;
1640 dev->open = sdla_open;
1641 dev->stop = sdla_close;
1642 dev->do_ioctl = sdla_ioctl;
1643 dev->set_config = sdla_set_config;
1644 dev->get_stats = sdla_stats;
1645 dev->hard_start_xmit = sdla_transmit;
1646 dev->change_mtu = sdla_change_mtu;
1647
1648 dev->type = 0xFFFF;
1649 dev->family = AF_UNSPEC;
1650 dev->pa_alen = 0;
1651 dev->pa_addr = 0;
1652 dev->pa_dstaddr = 0;
1653 dev->pa_brdaddr = 0;
1654 dev->pa_mask = 0;
1655 dev->hard_header_len = 0;
1656 dev->addr_len = 0;
1657 dev->mtu = SDLA_MAX_MTU;
1658
1659 for (i = 0; i < DEV_NUMBUFFS; i++)
1660 skb_queue_head_init(&dev->buffs[i]);
1661
1662 flp->activate = sdla_activate;
1663 flp->deactivate = sdla_deactivate;
1664 flp->assoc = sdla_assoc;
1665 flp->deassoc = sdla_deassoc;
1666 flp->dlci_conf = sdla_dlci_conf;
1667
1668 init_timer(&flp->timer);
1669 flp->timer.expires = 1;
1670 flp->timer.data = (unsigned long) dev;
1671 flp->timer.function = sdla_poll;
1672
1673 return(0);
1674 }
1675
1676 void sdla_setup(void)
1677 {
1678 printk("%s.\n", version);
1679 register_frad(devname);
1680 }
1681
1682 #ifdef MODULE
1683 static struct device sdla0 = {"sdla0", 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, sdla_init};
1684
1685 int init_module(void)
1686 {
1687 int result;
1688
1689 sdla_setup();
1690 if ((result = register_netdev(&sdla0)) != 0)
1691 return result;
1692
1693 return 0;
1694 }
1695
1696 void cleanup_module(void)
1697 {
1698 unregister_netdev(&sdla0);
1699 if (sdla0.priv)
1700 kfree(sdla0.priv);
1701 if (sdla0.irq)
1702 free_irq(sdla0.irq, NULL);
1703 }
1704 #endif