1 /*****************************************************************************/
4 * istallion.c -- stallion intelligent multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/cdk.h>
37 #include <linux/comstats.h>
38 #include <linux/istallion.h>
39 #include <linux/ioport.h>
40 #include <linux/delay.h>
41 #include <linux/init.h>
42 #include <linux/devfs_fs_kernel.h>
43 #include <linux/device.h>
46 #include <asm/uaccess.h>
49 #include <linux/pci.h>
52 /*****************************************************************************/
55 * Define different board types. Not all of the following board types
56 * are supported by this driver. But I will use the standard "assigned"
57 * board numbers. Currently supported boards are abbreviated as:
58 * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
62 #define BRD_STALLION 1
64 #define BRD_ONBOARD2 3
67 #define BRD_BRUMBY16 6
68 #define BRD_ONBOARDE 7
69 #define BRD_ONBOARD32 9
70 #define BRD_ONBOARD2_32 10
71 #define BRD_ONBOARDRS 11
79 #define BRD_ECH64PCI 27
80 #define BRD_EASYIOPCI 28
83 #define BRD_BRUMBY BRD_BRUMBY4
86 * Define a configuration structure to hold the board configuration.
87 * Need to set this up in the code (for now) with the boards that are
88 * to be configured into the system. This is what needs to be modified
89 * when adding/removing/modifying boards. Each line entry in the
90 * stli_brdconf[] array is a board. Each line contains io/irq/memory
91 * ranges for that board (as well as what type of board it is).
93 * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
94 * This line will configure an EasyConnection 8/64 at io address 2a0,
95 * and shared memory address of cc000. Multiple EasyConnection 8/64
96 * boards can share the same shared memory address space. No interrupt
97 * is required for this board type.
99 * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
100 * This line will configure an EasyConnection 8/64 EISA in slot 5 and
101 * shared memory address of 0x80000000 (2 GByte). Multiple
102 * EasyConnection 8/64 EISA boards can share the same shared memory
103 * address space. No interrupt is required for this board type.
105 * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
106 * This line will configure an ONboard (ISA type) at io address 240,
107 * and shared memory address of d0000. Multiple ONboards can share
108 * the same shared memory address space. No interrupt required.
110 * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
111 * This line will configure a Brumby board (any number of ports!) at
112 * io address 360 and shared memory address of c8000. All Brumby boards
113 * configured into a system must have their own separate io and memory
114 * addresses. No interrupt is required.
116 * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
117 * This line will configure an original Stallion board at io address 330
118 * and shared memory address d0000 (this would only be valid for a "V4.0"
119 * or Rev.O Stallion board). All Stallion boards configured into the
120 * system must have their own separate io and memory addresses. No
121 * interrupt is required.
128 unsigned long memaddr;
133 static stlconf_t stli_brdconf[] = {
134 /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
137 static int stli_nrbrds = sizeof(stli_brdconf) / sizeof(stlconf_t);
140 * There is some experimental EISA board detection code in this driver.
141 * By default it is disabled, but for those that want to try it out,
142 * then set the define below to be 1.
144 #define STLI_EISAPROBE 0
146 /*****************************************************************************/
149 * Define some important driver characteristics. Device major numbers
150 * allocated as per Linux Device Registry.
152 #ifndef STL_SIOMEMMAJOR
153 #define STL_SIOMEMMAJOR 28
155 #ifndef STL_SERIALMAJOR
156 #define STL_SERIALMAJOR 24
158 #ifndef STL_CALLOUTMAJOR
159 #define STL_CALLOUTMAJOR 25
162 /*****************************************************************************/
165 * Define our local driver identity first. Set up stuff to deal with
166 * all the local structures required by a serial tty driver.
168 static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
169 static char *stli_drvname = "istallion";
170 static char *stli_drvversion = "5.6.0";
171 static char *stli_serialname = "ttyE";
173 static struct tty_driver *stli_serial;
176 * We will need to allocate a temporary write buffer for chars that
177 * come direct from user space. The problem is that a copy from user
178 * space might cause a page fault (typically on a system that is
179 * swapping!). All ports will share one buffer - since if the system
180 * is already swapping a shared buffer won't make things any worse.
182 static char *stli_tmpwritebuf;
183 static DECLARE_MUTEX(stli_tmpwritesem);
185 #define STLI_TXBUFSIZE 4096
188 * Use a fast local buffer for cooked characters. Typically a whole
189 * bunch of cooked characters come in for a port, 1 at a time. So we
190 * save those up into a local buffer, then write out the whole lot
191 * with a large memcpy. Just use 1 buffer for all ports, since its
192 * use it is only need for short periods of time by each port.
194 static char *stli_txcookbuf;
195 static int stli_txcooksize;
196 static int stli_txcookrealsize;
197 static struct tty_struct *stli_txcooktty;
200 * Define a local default termios struct. All ports will be created
201 * with this termios initially. Basically all it defines is a raw port
202 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
204 static struct termios stli_deftermios = {
205 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
210 * Define global stats structures. Not used often, and can be
211 * re-used for each stats call.
213 static comstats_t stli_comstats;
214 static combrd_t stli_brdstats;
215 static asystats_t stli_cdkstats;
216 static stlibrd_t stli_dummybrd;
217 static stliport_t stli_dummyport;
219 /*****************************************************************************/
221 static stlibrd_t *stli_brds[STL_MAXBRDS];
223 static int stli_shared;
226 * Per board state flags. Used with the state field of the board struct.
227 * Not really much here... All we need to do is keep track of whether
228 * the board has been detected, and whether it is actually running a slave
231 #define BST_FOUND 0x1
232 #define BST_STARTED 0x2
235 * Define the set of port state flags. These are marked for internal
236 * state purposes only, usually to do with the state of communications
237 * with the slave. Most of them need to be updated atomically, so always
238 * use the bit setting operations (unless protected by cli/sti).
240 #define ST_INITIALIZING 1
246 #define ST_DOFLUSHRX 7
247 #define ST_DOFLUSHTX 8
250 #define ST_GETSIGS 11
253 * Define an array of board names as printable strings. Handy for
254 * referencing boards when printing trace and stuff.
256 static char *stli_brdnames[] = {
289 /*****************************************************************************/
293 * Define some string labels for arguments passed from the module
294 * load line. These allow for easy board definitions, and easy
295 * modification of the io, memory and irq resoucres.
298 static char *board0[8];
299 static char *board1[8];
300 static char *board2[8];
301 static char *board3[8];
303 static char **stli_brdsp[] = {
311 * Define a set of common board names, and types. This is used to
312 * parse any module arguments.
315 typedef struct stlibrdtype {
320 static stlibrdtype_t stli_brdstr[] = {
321 { "stallion", BRD_STALLION },
322 { "1", BRD_STALLION },
323 { "brumby", BRD_BRUMBY },
324 { "brumby4", BRD_BRUMBY },
325 { "brumby/4", BRD_BRUMBY },
326 { "brumby-4", BRD_BRUMBY },
327 { "brumby8", BRD_BRUMBY },
328 { "brumby/8", BRD_BRUMBY },
329 { "brumby-8", BRD_BRUMBY },
330 { "brumby16", BRD_BRUMBY },
331 { "brumby/16", BRD_BRUMBY },
332 { "brumby-16", BRD_BRUMBY },
334 { "onboard2", BRD_ONBOARD2 },
335 { "onboard-2", BRD_ONBOARD2 },
336 { "onboard/2", BRD_ONBOARD2 },
337 { "onboard-mc", BRD_ONBOARD2 },
338 { "onboard/mc", BRD_ONBOARD2 },
339 { "onboard-mca", BRD_ONBOARD2 },
340 { "onboard/mca", BRD_ONBOARD2 },
341 { "3", BRD_ONBOARD2 },
342 { "onboard", BRD_ONBOARD },
343 { "onboardat", BRD_ONBOARD },
344 { "4", BRD_ONBOARD },
345 { "onboarde", BRD_ONBOARDE },
346 { "onboard-e", BRD_ONBOARDE },
347 { "onboard/e", BRD_ONBOARDE },
348 { "onboard-ei", BRD_ONBOARDE },
349 { "onboard/ei", BRD_ONBOARDE },
350 { "7", BRD_ONBOARDE },
352 { "ecpat", BRD_ECP },
353 { "ec8/64", BRD_ECP },
354 { "ec8/64-at", BRD_ECP },
355 { "ec8/64-isa", BRD_ECP },
357 { "ecpe", BRD_ECPE },
358 { "ecpei", BRD_ECPE },
359 { "ec8/64-e", BRD_ECPE },
360 { "ec8/64-ei", BRD_ECPE },
362 { "ecpmc", BRD_ECPMC },
363 { "ec8/64-mc", BRD_ECPMC },
364 { "ec8/64-mca", BRD_ECPMC },
366 { "ecppci", BRD_ECPPCI },
367 { "ec/ra", BRD_ECPPCI },
368 { "ec/ra-pc", BRD_ECPPCI },
369 { "ec/ra-pci", BRD_ECPPCI },
370 { "29", BRD_ECPPCI },
374 * Define the module agruments.
376 MODULE_AUTHOR("Greg Ungerer");
377 MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
378 MODULE_LICENSE("GPL");
381 MODULE_PARM(board0, "1-3s");
382 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
383 MODULE_PARM(board1, "1-3s");
384 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
385 MODULE_PARM(board2, "1-3s");
386 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
387 MODULE_PARM(board3, "1-3s");
388 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
393 * Set up a default memory address table for EISA board probing.
394 * The default addresses are all bellow 1Mbyte, which has to be the
395 * case anyway. They should be safe, since we only read values from
396 * them, and interrupts are disabled while we do it. If the higher
397 * memory support is compiled in then we also try probing around
398 * the 1Gb, 2Gb and 3Gb areas as well...
400 static unsigned long stli_eisamemprobeaddrs[] = {
401 0xc0000, 0xd0000, 0xe0000, 0xf0000,
402 0x80000000, 0x80010000, 0x80020000, 0x80030000,
403 0x40000000, 0x40010000, 0x40020000, 0x40030000,
404 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
405 0xff000000, 0xff010000, 0xff020000, 0xff030000,
408 static int stli_eisamempsize = sizeof(stli_eisamemprobeaddrs) / sizeof(unsigned long);
409 int stli_eisaprobe = STLI_EISAPROBE;
412 * Define the Stallion PCI vendor and device IDs.
415 #ifndef PCI_VENDOR_ID_STALLION
416 #define PCI_VENDOR_ID_STALLION 0x124d
418 #ifndef PCI_DEVICE_ID_ECRA
419 #define PCI_DEVICE_ID_ECRA 0x0004
422 static struct pci_device_id istallion_pci_tbl[] = {
423 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
426 MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
428 #endif /* CONFIG_PCI */
430 /*****************************************************************************/
433 * Hardware configuration info for ECP boards. These defines apply
434 * to the directly accessible io ports of the ECP. There is a set of
435 * defines for each ECP board type, ISA, EISA, MCA and PCI.
439 #define ECP_MEMSIZE (128 * 1024)
440 #define ECP_PCIMEMSIZE (256 * 1024)
442 #define ECP_ATPAGESIZE (4 * 1024)
443 #define ECP_MCPAGESIZE (4 * 1024)
444 #define ECP_EIPAGESIZE (64 * 1024)
445 #define ECP_PCIPAGESIZE (64 * 1024)
447 #define STL_EISAID 0x8c4e
450 * Important defines for the ISA class of ECP board.
453 #define ECP_ATCONFR 1
454 #define ECP_ATMEMAR 2
455 #define ECP_ATMEMPR 3
456 #define ECP_ATSTOP 0x1
457 #define ECP_ATINTENAB 0x10
458 #define ECP_ATENABLE 0x20
459 #define ECP_ATDISABLE 0x00
460 #define ECP_ATADDRMASK 0x3f000
461 #define ECP_ATADDRSHFT 12
464 * Important defines for the EISA class of ECP board.
467 #define ECP_EIMEMARL 1
468 #define ECP_EICONFR 2
469 #define ECP_EIMEMARH 3
470 #define ECP_EIENABLE 0x1
471 #define ECP_EIDISABLE 0x0
472 #define ECP_EISTOP 0x4
473 #define ECP_EIEDGE 0x00
474 #define ECP_EILEVEL 0x80
475 #define ECP_EIADDRMASKL 0x00ff0000
476 #define ECP_EIADDRSHFTL 16
477 #define ECP_EIADDRMASKH 0xff000000
478 #define ECP_EIADDRSHFTH 24
479 #define ECP_EIBRDENAB 0xc84
481 #define ECP_EISAID 0x4
484 * Important defines for the Micro-channel class of ECP board.
485 * (It has a lot in common with the ISA boards.)
488 #define ECP_MCCONFR 1
489 #define ECP_MCSTOP 0x20
490 #define ECP_MCENABLE 0x80
491 #define ECP_MCDISABLE 0x00
494 * Important defines for the PCI class of ECP board.
495 * (It has a lot in common with the other ECP boards.)
497 #define ECP_PCIIREG 0
498 #define ECP_PCICONFR 1
499 #define ECP_PCISTOP 0x01
502 * Hardware configuration info for ONboard and Brumby boards. These
503 * defines apply to the directly accessible io ports of these boards.
505 #define ONB_IOSIZE 16
506 #define ONB_MEMSIZE (64 * 1024)
507 #define ONB_ATPAGESIZE (64 * 1024)
508 #define ONB_MCPAGESIZE (64 * 1024)
509 #define ONB_EIMEMSIZE (128 * 1024)
510 #define ONB_EIPAGESIZE (64 * 1024)
513 * Important defines for the ISA class of ONboard board.
516 #define ONB_ATMEMAR 1
517 #define ONB_ATCONFR 2
518 #define ONB_ATSTOP 0x4
519 #define ONB_ATENABLE 0x01
520 #define ONB_ATDISABLE 0x00
521 #define ONB_ATADDRMASK 0xff0000
522 #define ONB_ATADDRSHFT 16
524 #define ONB_MEMENABLO 0
525 #define ONB_MEMENABHI 0x02
528 * Important defines for the EISA class of ONboard board.
531 #define ONB_EIMEMARL 1
532 #define ONB_EICONFR 2
533 #define ONB_EIMEMARH 3
534 #define ONB_EIENABLE 0x1
535 #define ONB_EIDISABLE 0x0
536 #define ONB_EISTOP 0x4
537 #define ONB_EIEDGE 0x00
538 #define ONB_EILEVEL 0x80
539 #define ONB_EIADDRMASKL 0x00ff0000
540 #define ONB_EIADDRSHFTL 16
541 #define ONB_EIADDRMASKH 0xff000000
542 #define ONB_EIADDRSHFTH 24
543 #define ONB_EIBRDENAB 0xc84
545 #define ONB_EISAID 0x1
548 * Important defines for the Brumby boards. They are pretty simple,
549 * there is not much that is programmably configurable.
551 #define BBY_IOSIZE 16
552 #define BBY_MEMSIZE (64 * 1024)
553 #define BBY_PAGESIZE (16 * 1024)
556 #define BBY_ATCONFR 1
557 #define BBY_ATSTOP 0x4
560 * Important defines for the Stallion boards. They are pretty simple,
561 * there is not much that is programmably configurable.
563 #define STAL_IOSIZE 16
564 #define STAL_MEMSIZE (64 * 1024)
565 #define STAL_PAGESIZE (64 * 1024)
568 * Define the set of status register values for EasyConnection panels.
569 * The signature will return with the status value for each panel. From
570 * this we can determine what is attached to the board - before we have
571 * actually down loaded any code to it.
573 #define ECH_PNLSTATUS 2
574 #define ECH_PNL16PORT 0x20
575 #define ECH_PNLIDMASK 0x07
576 #define ECH_PNLXPID 0x40
577 #define ECH_PNLINTRPEND 0x80
580 * Define some macros to do things to the board. Even those these boards
581 * are somewhat related there is often significantly different ways of
582 * doing some operation on it (like enable, paging, reset, etc). So each
583 * board class has a set of functions which do the commonly required
584 * operations. The macros below basically just call these functions,
585 * generally checking for a NULL function - which means that the board
586 * needs nothing done to it to achieve this operation!
588 #define EBRDINIT(brdp) \
589 if (brdp->init != NULL) \
592 #define EBRDENABLE(brdp) \
593 if (brdp->enable != NULL) \
594 (* brdp->enable)(brdp);
596 #define EBRDDISABLE(brdp) \
597 if (brdp->disable != NULL) \
598 (* brdp->disable)(brdp);
600 #define EBRDINTR(brdp) \
601 if (brdp->intr != NULL) \
602 (* brdp->intr)(brdp);
604 #define EBRDRESET(brdp) \
605 if (brdp->reset != NULL) \
606 (* brdp->reset)(brdp);
608 #define EBRDGETMEMPTR(brdp,offset) \
609 (* brdp->getmemptr)(brdp, offset, __LINE__)
612 * Define the maximal baud rate, and the default baud base for ports.
614 #define STL_MAXBAUD 460800
615 #define STL_BAUDBASE 115200
616 #define STL_CLOSEDELAY (5 * HZ / 10)
618 /*****************************************************************************/
621 * Define macros to extract a brd or port number from a minor number.
623 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
624 #define MINOR2PORT(min) ((min) & 0x3f)
627 * Define a baud rate table that converts termios baud rate selector
628 * into the actual baud rate value. All baud rate calculations are based
629 * on the actual baud rate required.
631 static unsigned int stli_baudrates[] = {
632 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
633 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
636 /*****************************************************************************/
639 * Define some handy local macros...
642 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
645 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
647 /*****************************************************************************/
650 * Prototype all functions in this driver!
654 static void stli_argbrds(void);
655 static int stli_parsebrd(stlconf_t *confp, char **argp);
657 static unsigned long stli_atol(char *str);
661 static int stli_open(struct tty_struct *tty, struct file *filp);
662 static void stli_close(struct tty_struct *tty, struct file *filp);
663 static int stli_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
664 static void stli_putchar(struct tty_struct *tty, unsigned char ch);
665 static void stli_flushchars(struct tty_struct *tty);
666 static int stli_writeroom(struct tty_struct *tty);
667 static int stli_charsinbuffer(struct tty_struct *tty);
668 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
669 static void stli_settermios(struct tty_struct *tty, struct termios *old);
670 static void stli_throttle(struct tty_struct *tty);
671 static void stli_unthrottle(struct tty_struct *tty);
672 static void stli_stop(struct tty_struct *tty);
673 static void stli_start(struct tty_struct *tty);
674 static void stli_flushbuffer(struct tty_struct *tty);
675 static void stli_breakctl(struct tty_struct *tty, int state);
676 static void stli_waituntilsent(struct tty_struct *tty, int timeout);
677 static void stli_sendxchar(struct tty_struct *tty, char ch);
678 static void stli_hangup(struct tty_struct *tty);
679 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
681 static int stli_brdinit(stlibrd_t *brdp);
682 static int stli_startbrd(stlibrd_t *brdp);
683 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
684 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
685 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
686 static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp);
687 static void stli_poll(unsigned long arg);
688 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
689 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
690 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
691 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
692 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
693 static void stli_dohangup(void *arg);
694 static void stli_delay(int len);
695 static int stli_setport(stliport_t *portp);
696 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
697 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
698 static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp);
699 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
700 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
701 static long stli_mktiocm(unsigned long sigvalue);
702 static void stli_read(stlibrd_t *brdp, stliport_t *portp);
703 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp);
704 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp);
705 static int stli_getbrdstats(combrd_t __user *bp);
706 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp);
707 static int stli_portcmdstats(stliport_t *portp);
708 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
709 static int stli_getportstruct(stliport_t __user *arg);
710 static int stli_getbrdstruct(stlibrd_t __user *arg);
711 static void *stli_memalloc(int len);
712 static stlibrd_t *stli_allocbrd(void);
714 static void stli_ecpinit(stlibrd_t *brdp);
715 static void stli_ecpenable(stlibrd_t *brdp);
716 static void stli_ecpdisable(stlibrd_t *brdp);
717 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
718 static void stli_ecpreset(stlibrd_t *brdp);
719 static void stli_ecpintr(stlibrd_t *brdp);
720 static void stli_ecpeiinit(stlibrd_t *brdp);
721 static void stli_ecpeienable(stlibrd_t *brdp);
722 static void stli_ecpeidisable(stlibrd_t *brdp);
723 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
724 static void stli_ecpeireset(stlibrd_t *brdp);
725 static void stli_ecpmcenable(stlibrd_t *brdp);
726 static void stli_ecpmcdisable(stlibrd_t *brdp);
727 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
728 static void stli_ecpmcreset(stlibrd_t *brdp);
729 static void stli_ecppciinit(stlibrd_t *brdp);
730 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
731 static void stli_ecppcireset(stlibrd_t *brdp);
733 static void stli_onbinit(stlibrd_t *brdp);
734 static void stli_onbenable(stlibrd_t *brdp);
735 static void stli_onbdisable(stlibrd_t *brdp);
736 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
737 static void stli_onbreset(stlibrd_t *brdp);
738 static void stli_onbeinit(stlibrd_t *brdp);
739 static void stli_onbeenable(stlibrd_t *brdp);
740 static void stli_onbedisable(stlibrd_t *brdp);
741 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
742 static void stli_onbereset(stlibrd_t *brdp);
743 static void stli_bbyinit(stlibrd_t *brdp);
744 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
745 static void stli_bbyreset(stlibrd_t *brdp);
746 static void stli_stalinit(stlibrd_t *brdp);
747 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
748 static void stli_stalreset(stlibrd_t *brdp);
750 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
752 static inline int stli_initbrds(void);
753 static inline int stli_initecp(stlibrd_t *brdp);
754 static inline int stli_initonb(stlibrd_t *brdp);
755 static inline int stli_findeisabrds(void);
756 static inline int stli_eisamemprobe(stlibrd_t *brdp);
757 static inline int stli_initports(stlibrd_t *brdp);
758 static inline int stli_getbrdnr(void);
761 static inline int stli_findpcibrds(void);
762 static inline int stli_initpcibrd(int brdtype, struct pci_dev *devp);
765 /*****************************************************************************/
768 * Define the driver info for a user level shared memory device. This
769 * device will work sort of like the /dev/kmem device - except that it
770 * will give access to the shared memory on the Stallion intelligent
771 * board. This is also a very useful debugging tool.
773 static struct file_operations stli_fsiomem = {
774 .owner = THIS_MODULE,
775 .read = stli_memread,
776 .write = stli_memwrite,
777 .ioctl = stli_memioctl,
780 /*****************************************************************************/
783 * Define a timer_list entry for our poll routine. The slave board
784 * is polled every so often to see if anything needs doing. This is
785 * much cheaper on host cpu than using interrupts. It turns out to
786 * not increase character latency by much either...
788 static struct timer_list stli_timerlist = TIMER_INITIALIZER(stli_poll, 0, 0);
790 static int stli_timeron;
793 * Define the calculation for the timeout routine.
795 #define STLI_TIMEOUT (jiffies + 1)
797 /*****************************************************************************/
799 static struct class_simple *istallion_class;
804 * Loadable module initialization stuff.
807 static int __init istallion_module_init(void)
812 printk("init_module()\n");
818 restore_flags(flags);
823 /*****************************************************************************/
825 static void __exit istallion_module_exit(void)
833 printk("cleanup_module()\n");
836 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
843 * Free up all allocated resources used by the ports. This includes
844 * memory and interrupts.
848 del_timer(&stli_timerlist);
851 i = tty_unregister_driver(stli_serial);
853 printk("STALLION: failed to un-register tty driver, "
855 restore_flags(flags);
858 put_tty_driver(stli_serial);
859 for (i = 0; i < 4; i++) {
860 devfs_remove("staliomem/%d", i);
861 class_simple_device_remove(MKDEV(STL_SIOMEMMAJOR, i));
863 devfs_remove("staliomem");
864 class_simple_destroy(istallion_class);
865 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
866 printk("STALLION: failed to un-register serial memory device, "
868 if (stli_tmpwritebuf != (char *) NULL)
869 kfree(stli_tmpwritebuf);
870 if (stli_txcookbuf != (char *) NULL)
871 kfree(stli_txcookbuf);
873 for (i = 0; (i < stli_nrbrds); i++) {
874 if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL)
876 for (j = 0; (j < STL_MAXPORTS); j++) {
877 portp = brdp->ports[j];
878 if (portp != (stliport_t *) NULL) {
879 if (portp->tty != (struct tty_struct *) NULL)
880 tty_hangup(portp->tty);
885 iounmap(brdp->membase);
886 if (brdp->iosize > 0)
887 release_region(brdp->iobase, brdp->iosize);
889 stli_brds[i] = (stlibrd_t *) NULL;
892 restore_flags(flags);
895 module_init(istallion_module_init);
896 module_exit(istallion_module_exit);
898 /*****************************************************************************/
901 * Check for any arguments passed in on the module load command line.
904 static void stli_argbrds(void)
911 printk("stli_argbrds()\n");
914 nrargs = sizeof(stli_brdsp) / sizeof(char **);
916 for (i = stli_nrbrds; (i < nrargs); i++) {
917 memset(&conf, 0, sizeof(conf));
918 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
920 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
924 brdp->brdtype = conf.brdtype;
925 brdp->iobase = conf.ioaddr1;
926 brdp->memaddr = conf.memaddr;
931 /*****************************************************************************/
934 * Convert an ascii string number into an unsigned long.
937 static unsigned long stli_atol(char *str)
945 if ((*sp == '0') && (*(sp+1) == 'x')) {
948 } else if (*sp == '0') {
955 for (; (*sp != 0); sp++) {
956 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
957 if ((c < 0) || (c >= base)) {
958 printk("STALLION: invalid argument %s\n", str);
962 val = (val * base) + c;
967 /*****************************************************************************/
970 * Parse the supplied argument string, into the board conf struct.
973 static int stli_parsebrd(stlconf_t *confp, char **argp)
979 printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
982 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
985 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
988 nrbrdnames = sizeof(stli_brdstr) / sizeof(stlibrdtype_t);
989 for (i = 0; (i < nrbrdnames); i++) {
990 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
993 if (i >= nrbrdnames) {
994 printk("STALLION: unknown board name, %s?\n", argp[0]);
998 confp->brdtype = stli_brdstr[i].type;
999 if ((argp[1] != (char *) NULL) && (*argp[1] != 0))
1000 confp->ioaddr1 = stli_atol(argp[1]);
1001 if ((argp[2] != (char *) NULL) && (*argp[2] != 0))
1002 confp->memaddr = stli_atol(argp[2]);
1008 /*****************************************************************************/
1011 * Local driver kernel malloc routine.
1014 static void *stli_memalloc(int len)
1016 return((void *) kmalloc(len, GFP_KERNEL));
1019 /*****************************************************************************/
1021 static int stli_open(struct tty_struct *tty, struct file *filp)
1025 unsigned int minordev;
1026 int brdnr, portnr, rc;
1029 printk("stli_open(tty=%x,filp=%x): device=%s\n", (int) tty,
1030 (int) filp, tty->name);
1033 minordev = tty->index;
1034 brdnr = MINOR2BRD(minordev);
1035 if (brdnr >= stli_nrbrds)
1037 brdp = stli_brds[brdnr];
1038 if (brdp == (stlibrd_t *) NULL)
1040 if ((brdp->state & BST_STARTED) == 0)
1042 portnr = MINOR2PORT(minordev);
1043 if ((portnr < 0) || (portnr > brdp->nrports))
1046 portp = brdp->ports[portnr];
1047 if (portp == (stliport_t *) NULL)
1049 if (portp->devnr < 1)
1054 * Check if this port is in the middle of closing. If so then wait
1055 * until it is closed then return error status based on flag settings.
1056 * The sleep here does not need interrupt protection since the wakeup
1057 * for it is done with the same context.
1059 if (portp->flags & ASYNC_CLOSING) {
1060 interruptible_sleep_on(&portp->close_wait);
1061 if (portp->flags & ASYNC_HUP_NOTIFY)
1063 return(-ERESTARTSYS);
1067 * On the first open of the device setup the port hardware, and
1068 * initialize the per port data structure. Since initializing the port
1069 * requires several commands to the board we will need to wait for any
1070 * other open that is already initializing the port.
1073 tty->driver_data = portp;
1076 while (test_bit(ST_INITIALIZING, &portp->state)) {
1077 if (signal_pending(current))
1078 return(-ERESTARTSYS);
1079 interruptible_sleep_on(&portp->raw_wait);
1082 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1083 set_bit(ST_INITIALIZING, &portp->state);
1084 if ((rc = stli_initopen(brdp, portp)) >= 0) {
1085 portp->flags |= ASYNC_INITIALIZED;
1086 clear_bit(TTY_IO_ERROR, &tty->flags);
1088 clear_bit(ST_INITIALIZING, &portp->state);
1089 wake_up_interruptible(&portp->raw_wait);
1095 * Check if this port is in the middle of closing. If so then wait
1096 * until it is closed then return error status, based on flag settings.
1097 * The sleep here does not need interrupt protection since the wakeup
1098 * for it is done with the same context.
1100 if (portp->flags & ASYNC_CLOSING) {
1101 interruptible_sleep_on(&portp->close_wait);
1102 if (portp->flags & ASYNC_HUP_NOTIFY)
1104 return(-ERESTARTSYS);
1108 * Based on type of open being done check if it can overlap with any
1109 * previous opens still in effect. If we are a normal serial device
1110 * then also we might have to wait for carrier.
1112 if (!(filp->f_flags & O_NONBLOCK)) {
1113 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
1116 portp->flags |= ASYNC_NORMAL_ACTIVE;
1120 /*****************************************************************************/
1122 static void stli_close(struct tty_struct *tty, struct file *filp)
1126 unsigned long flags;
1129 printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1132 portp = tty->driver_data;
1133 if (portp == (stliport_t *) NULL)
1138 if (tty_hung_up_p(filp)) {
1139 restore_flags(flags);
1142 if ((tty->count == 1) && (portp->refcount != 1))
1143 portp->refcount = 1;
1144 if (portp->refcount-- > 1) {
1145 restore_flags(flags);
1149 portp->flags |= ASYNC_CLOSING;
1152 * May want to wait for data to drain before closing. The BUSY flag
1153 * keeps track of whether we are still transmitting or not. It is
1154 * updated by messages from the slave - indicating when all chars
1155 * really have drained.
1157 if (tty == stli_txcooktty)
1158 stli_flushchars(tty);
1160 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1161 tty_wait_until_sent(tty, portp->closing_wait);
1163 portp->flags &= ~ASYNC_INITIALIZED;
1164 brdp = stli_brds[portp->brdnr];
1165 stli_rawclose(brdp, portp, 0, 0);
1166 if (tty->termios->c_cflag & HUPCL) {
1167 stli_mkasysigs(&portp->asig, 0, 0);
1168 if (test_bit(ST_CMDING, &portp->state))
1169 set_bit(ST_DOSIGS, &portp->state);
1171 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
1172 sizeof(asysigs_t), 0);
1174 clear_bit(ST_TXBUSY, &portp->state);
1175 clear_bit(ST_RXSTOP, &portp->state);
1176 set_bit(TTY_IO_ERROR, &tty->flags);
1177 if (tty->ldisc.flush_buffer)
1178 (tty->ldisc.flush_buffer)(tty);
1179 set_bit(ST_DOFLUSHRX, &portp->state);
1180 stli_flushbuffer(tty);
1183 portp->tty = (struct tty_struct *) NULL;
1185 if (portp->openwaitcnt) {
1186 if (portp->close_delay)
1187 stli_delay(portp->close_delay);
1188 wake_up_interruptible(&portp->open_wait);
1191 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1192 wake_up_interruptible(&portp->close_wait);
1193 restore_flags(flags);
1196 /*****************************************************************************/
1199 * Carry out first open operations on a port. This involves a number of
1200 * commands to be sent to the slave. We need to open the port, set the
1201 * notification events, set the initial port settings, get and set the
1202 * initial signal values. We sleep and wait in between each one. But
1203 * this still all happens pretty quickly.
1206 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1208 struct tty_struct *tty;
1214 printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
1217 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1220 memset(&nt, 0, sizeof(asynotify_t));
1221 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1223 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1224 sizeof(asynotify_t), 0)) < 0)
1228 if (tty == (struct tty_struct *) NULL)
1230 stli_mkasyport(portp, &aport, tty->termios);
1231 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1232 sizeof(asyport_t), 0)) < 0)
1235 set_bit(ST_GETSIGS, &portp->state);
1236 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1237 sizeof(asysigs_t), 1)) < 0)
1239 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1240 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1241 stli_mkasysigs(&portp->asig, 1, 1);
1242 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1243 sizeof(asysigs_t), 0)) < 0)
1249 /*****************************************************************************/
1252 * Send an open message to the slave. This will sleep waiting for the
1253 * acknowledgement, so must have user context. We need to co-ordinate
1254 * with close events here, since we don't want open and close events
1258 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1260 volatile cdkhdr_t *hdrp;
1261 volatile cdkctrl_t *cp;
1262 volatile unsigned char *bits;
1263 unsigned long flags;
1267 printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1268 (int) brdp, (int) portp, (int) arg, wait);
1272 * Send a message to the slave to open this port.
1278 * Slave is already closing this port. This can happen if a hangup
1279 * occurs on this port. So we must wait until it is complete. The
1280 * order of opens and closes may not be preserved across shared
1281 * memory, so we must wait until it is complete.
1283 while (test_bit(ST_CLOSING, &portp->state)) {
1284 if (signal_pending(current)) {
1285 restore_flags(flags);
1286 return(-ERESTARTSYS);
1288 interruptible_sleep_on(&portp->raw_wait);
1292 * Everything is ready now, so write the open message into shared
1293 * memory. Once the message is in set the service bits to say that
1294 * this port wants service.
1297 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1300 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1301 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1303 *bits |= portp->portbit;
1307 restore_flags(flags);
1312 * Slave is in action, so now we must wait for the open acknowledgment
1316 set_bit(ST_OPENING, &portp->state);
1317 while (test_bit(ST_OPENING, &portp->state)) {
1318 if (signal_pending(current)) {
1322 interruptible_sleep_on(&portp->raw_wait);
1324 restore_flags(flags);
1326 if ((rc == 0) && (portp->rc != 0))
1331 /*****************************************************************************/
1334 * Send a close message to the slave. Normally this will sleep waiting
1335 * for the acknowledgement, but if wait parameter is 0 it will not. If
1336 * wait is true then must have user context (to sleep).
1339 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1341 volatile cdkhdr_t *hdrp;
1342 volatile cdkctrl_t *cp;
1343 volatile unsigned char *bits;
1344 unsigned long flags;
1348 printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1349 (int) brdp, (int) portp, (int) arg, wait);
1356 * Slave is already closing this port. This can happen if a hangup
1357 * occurs on this port.
1360 while (test_bit(ST_CLOSING, &portp->state)) {
1361 if (signal_pending(current)) {
1362 restore_flags(flags);
1363 return(-ERESTARTSYS);
1365 interruptible_sleep_on(&portp->raw_wait);
1370 * Write the close command into shared memory.
1373 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1376 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1377 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1379 *bits |= portp->portbit;
1382 set_bit(ST_CLOSING, &portp->state);
1384 restore_flags(flags);
1389 * Slave is in action, so now we must wait for the open acknowledgment
1393 while (test_bit(ST_CLOSING, &portp->state)) {
1394 if (signal_pending(current)) {
1398 interruptible_sleep_on(&portp->raw_wait);
1400 restore_flags(flags);
1402 if ((rc == 0) && (portp->rc != 0))
1407 /*****************************************************************************/
1410 * Send a command to the slave and wait for the response. This must
1411 * have user context (it sleeps). This routine is generic in that it
1412 * can send any type of command. Its purpose is to wait for that command
1413 * to complete (as opposed to initiating the command then returning).
1416 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1418 unsigned long flags;
1421 printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
1422 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
1423 (int) arg, size, copyback);
1428 while (test_bit(ST_CMDING, &portp->state)) {
1429 if (signal_pending(current)) {
1430 restore_flags(flags);
1431 return(-ERESTARTSYS);
1433 interruptible_sleep_on(&portp->raw_wait);
1436 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1438 while (test_bit(ST_CMDING, &portp->state)) {
1439 if (signal_pending(current)) {
1440 restore_flags(flags);
1441 return(-ERESTARTSYS);
1443 interruptible_sleep_on(&portp->raw_wait);
1445 restore_flags(flags);
1452 /*****************************************************************************/
1455 * Send the termios settings for this port to the slave. This sleeps
1456 * waiting for the command to complete - so must have user context.
1459 static int stli_setport(stliport_t *portp)
1465 printk("stli_setport(portp=%x)\n", (int) portp);
1468 if (portp == (stliport_t *) NULL)
1470 if (portp->tty == (struct tty_struct *) NULL)
1472 if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds))
1474 brdp = stli_brds[portp->brdnr];
1475 if (brdp == (stlibrd_t *) NULL)
1478 stli_mkasyport(portp, &aport, portp->tty->termios);
1479 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1482 /*****************************************************************************/
1485 * Wait for a specified delay period, this is not a busy-loop. It will
1486 * give up the processor while waiting. Unfortunately this has some
1487 * rather intimate knowledge of the process management stuff.
1490 static void stli_delay(int len)
1493 printk("stli_delay(len=%d)\n", len);
1496 set_current_state(TASK_INTERRUPTIBLE);
1497 schedule_timeout(len);
1501 /*****************************************************************************/
1504 * Possibly need to wait for carrier (DCD signal) to come high. Say
1505 * maybe because if we are clocal then we don't need to wait...
1508 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1510 unsigned long flags;
1514 printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
1515 (int) brdp, (int) portp, (int) filp);
1521 if (portp->tty->termios->c_cflag & CLOCAL)
1526 portp->openwaitcnt++;
1527 if (! tty_hung_up_p(filp))
1531 stli_mkasysigs(&portp->asig, 1, 1);
1532 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1533 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1535 if (tty_hung_up_p(filp) ||
1536 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1537 if (portp->flags & ASYNC_HUP_NOTIFY)
1543 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1544 (doclocal || (portp->sigs & TIOCM_CD))) {
1547 if (signal_pending(current)) {
1551 interruptible_sleep_on(&portp->open_wait);
1554 if (! tty_hung_up_p(filp))
1556 portp->openwaitcnt--;
1557 restore_flags(flags);
1562 /*****************************************************************************/
1565 * Write routine. Take the data and put it in the shared memory ring
1566 * queue. If port is not already sending chars then need to mark the
1567 * service bits for this port.
1570 static int stli_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1572 volatile cdkasy_t *ap;
1573 volatile cdkhdr_t *hdrp;
1574 volatile unsigned char *bits;
1575 unsigned char *shbuf, *chbuf;
1578 unsigned int len, stlen, head, tail, size;
1579 unsigned long flags;
1582 printk("stli_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1583 (int) tty, from_user, (int) buf, count);
1586 if ((tty == (struct tty_struct *) NULL) ||
1587 (stli_tmpwritebuf == (char *) NULL))
1589 if (tty == stli_txcooktty)
1590 stli_flushchars(tty);
1591 portp = tty->driver_data;
1592 if (portp == (stliport_t *) NULL)
1594 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1596 brdp = stli_brds[portp->brdnr];
1597 if (brdp == (stlibrd_t *) NULL)
1599 chbuf = (unsigned char *) buf;
1602 * If copying direct from user space we need to be able to handle page
1603 * faults while we are copying. To do this copy as much as we can now
1604 * into a kernel buffer. From there we copy it into shared memory. The
1605 * big problem is that we do not want shared memory enabled when we are
1606 * sleeping (other boards may be serviced while asleep). Something else
1607 * to note here is the reading of the tail twice. Since the boards
1608 * shared memory can be on an 8-bit bus then we need to be very careful
1609 * reading 16 bit quantities - since both the board (slave) and host
1610 * could be writing and reading at the same time.
1616 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1617 head = (unsigned int) ap->txq.head;
1618 tail = (unsigned int) ap->txq.tail;
1619 if (tail != ((unsigned int) ap->txq.tail))
1620 tail = (unsigned int) ap->txq.tail;
1621 len = (head >= tail) ? (portp->txsize - (head - tail) - 1) :
1623 count = MIN(len, count);
1625 restore_flags(flags);
1627 down(&stli_tmpwritesem);
1628 if (copy_from_user(stli_tmpwritebuf, chbuf, count))
1630 chbuf = &stli_tmpwritebuf[0];
1634 * All data is now local, shove as much as possible into shared memory.
1639 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1640 head = (unsigned int) ap->txq.head;
1641 tail = (unsigned int) ap->txq.tail;
1642 if (tail != ((unsigned int) ap->txq.tail))
1643 tail = (unsigned int) ap->txq.tail;
1644 size = portp->txsize;
1646 len = size - (head - tail) - 1;
1647 stlen = size - head;
1649 len = tail - head - 1;
1653 len = MIN(len, count);
1655 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1658 stlen = MIN(len, stlen);
1659 memcpy((shbuf + head), chbuf, stlen);
1670 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1671 ap->txq.head = head;
1672 if (test_bit(ST_TXBUSY, &portp->state)) {
1673 if (ap->changed.data & DT_TXEMPTY)
1674 ap->changed.data &= ~DT_TXEMPTY;
1676 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1677 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1679 *bits |= portp->portbit;
1680 set_bit(ST_TXBUSY, &portp->state);
1684 up(&stli_tmpwritesem);
1685 restore_flags(flags);
1690 /*****************************************************************************/
1693 * Output a single character. We put it into a temporary local buffer
1694 * (for speed) then write out that buffer when the flushchars routine
1695 * is called. There is a safety catch here so that if some other port
1696 * writes chars before the current buffer has been, then we write them
1697 * first them do the new ports.
1700 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1703 printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1706 if (tty == (struct tty_struct *) NULL)
1708 if (tty != stli_txcooktty) {
1709 if (stli_txcooktty != (struct tty_struct *) NULL)
1710 stli_flushchars(stli_txcooktty);
1711 stli_txcooktty = tty;
1714 stli_txcookbuf[stli_txcooksize++] = ch;
1717 /*****************************************************************************/
1720 * Transfer characters from the local TX cooking buffer to the board.
1721 * We sort of ignore the tty that gets passed in here. We rely on the
1722 * info stored with the TX cook buffer to tell us which port to flush
1723 * the data on. In any case we clean out the TX cook buffer, for re-use
1727 static void stli_flushchars(struct tty_struct *tty)
1729 volatile cdkhdr_t *hdrp;
1730 volatile unsigned char *bits;
1731 volatile cdkasy_t *ap;
1732 struct tty_struct *cooktty;
1735 unsigned int len, stlen, head, tail, size, count, cooksize;
1736 unsigned char *buf, *shbuf;
1737 unsigned long flags;
1740 printk("stli_flushchars(tty=%x)\n", (int) tty);
1743 cooksize = stli_txcooksize;
1744 cooktty = stli_txcooktty;
1745 stli_txcooksize = 0;
1746 stli_txcookrealsize = 0;
1747 stli_txcooktty = (struct tty_struct *) NULL;
1749 if (tty == (struct tty_struct *) NULL)
1751 if (cooktty == (struct tty_struct *) NULL)
1758 portp = tty->driver_data;
1759 if (portp == (stliport_t *) NULL)
1761 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1763 brdp = stli_brds[portp->brdnr];
1764 if (brdp == (stlibrd_t *) NULL)
1771 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1772 head = (unsigned int) ap->txq.head;
1773 tail = (unsigned int) ap->txq.tail;
1774 if (tail != ((unsigned int) ap->txq.tail))
1775 tail = (unsigned int) ap->txq.tail;
1776 size = portp->txsize;
1778 len = size - (head - tail) - 1;
1779 stlen = size - head;
1781 len = tail - head - 1;
1785 len = MIN(len, cooksize);
1787 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1788 buf = stli_txcookbuf;
1791 stlen = MIN(len, stlen);
1792 memcpy((shbuf + head), buf, stlen);
1803 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1804 ap->txq.head = head;
1806 if (test_bit(ST_TXBUSY, &portp->state)) {
1807 if (ap->changed.data & DT_TXEMPTY)
1808 ap->changed.data &= ~DT_TXEMPTY;
1810 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1811 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1813 *bits |= portp->portbit;
1814 set_bit(ST_TXBUSY, &portp->state);
1817 restore_flags(flags);
1820 /*****************************************************************************/
1822 static int stli_writeroom(struct tty_struct *tty)
1824 volatile cdkasyrq_t *rp;
1827 unsigned int head, tail, len;
1828 unsigned long flags;
1831 printk("stli_writeroom(tty=%x)\n", (int) tty);
1834 if (tty == (struct tty_struct *) NULL)
1836 if (tty == stli_txcooktty) {
1837 if (stli_txcookrealsize != 0) {
1838 len = stli_txcookrealsize - stli_txcooksize;
1843 portp = tty->driver_data;
1844 if (portp == (stliport_t *) NULL)
1846 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1848 brdp = stli_brds[portp->brdnr];
1849 if (brdp == (stlibrd_t *) NULL)
1855 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1856 head = (unsigned int) rp->head;
1857 tail = (unsigned int) rp->tail;
1858 if (tail != ((unsigned int) rp->tail))
1859 tail = (unsigned int) rp->tail;
1860 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1863 restore_flags(flags);
1865 if (tty == stli_txcooktty) {
1866 stli_txcookrealsize = len;
1867 len -= stli_txcooksize;
1872 /*****************************************************************************/
1875 * Return the number of characters in the transmit buffer. Normally we
1876 * will return the number of chars in the shared memory ring queue.
1877 * We need to kludge around the case where the shared memory buffer is
1878 * empty but not all characters have drained yet, for this case just
1879 * return that there is 1 character in the buffer!
1882 static int stli_charsinbuffer(struct tty_struct *tty)
1884 volatile cdkasyrq_t *rp;
1887 unsigned int head, tail, len;
1888 unsigned long flags;
1891 printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
1894 if (tty == (struct tty_struct *) NULL)
1896 if (tty == stli_txcooktty)
1897 stli_flushchars(tty);
1898 portp = tty->driver_data;
1899 if (portp == (stliport_t *) NULL)
1901 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1903 brdp = stli_brds[portp->brdnr];
1904 if (brdp == (stlibrd_t *) NULL)
1910 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1911 head = (unsigned int) rp->head;
1912 tail = (unsigned int) rp->tail;
1913 if (tail != ((unsigned int) rp->tail))
1914 tail = (unsigned int) rp->tail;
1915 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1916 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1919 restore_flags(flags);
1924 /*****************************************************************************/
1927 * Generate the serial struct info.
1930 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1932 struct serial_struct sio;
1936 printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1939 memset(&sio, 0, sizeof(struct serial_struct));
1940 sio.type = PORT_UNKNOWN;
1941 sio.line = portp->portnr;
1943 sio.flags = portp->flags;
1944 sio.baud_base = portp->baud_base;
1945 sio.close_delay = portp->close_delay;
1946 sio.closing_wait = portp->closing_wait;
1947 sio.custom_divisor = portp->custom_divisor;
1948 sio.xmit_fifo_size = 0;
1951 brdp = stli_brds[portp->brdnr];
1952 if (brdp != (stlibrd_t *) NULL)
1953 sio.port = brdp->iobase;
1955 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
1959 /*****************************************************************************/
1962 * Set port according to the serial struct info.
1963 * At this point we do not do any auto-configure stuff, so we will
1964 * just quietly ignore any requests to change irq, etc.
1967 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1969 struct serial_struct sio;
1973 printk("stli_setserial(portp=%p,sp=%p)\n", portp, sp);
1976 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1978 if (!capable(CAP_SYS_ADMIN)) {
1979 if ((sio.baud_base != portp->baud_base) ||
1980 (sio.close_delay != portp->close_delay) ||
1981 ((sio.flags & ~ASYNC_USR_MASK) !=
1982 (portp->flags & ~ASYNC_USR_MASK)))
1986 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1987 (sio.flags & ASYNC_USR_MASK);
1988 portp->baud_base = sio.baud_base;
1989 portp->close_delay = sio.close_delay;
1990 portp->closing_wait = sio.closing_wait;
1991 portp->custom_divisor = sio.custom_divisor;
1993 if ((rc = stli_setport(portp)) < 0)
1998 /*****************************************************************************/
2000 static int stli_tiocmget(struct tty_struct *tty, struct file *file)
2002 stliport_t *portp = tty->driver_data;
2006 if (portp == (stliport_t *) NULL)
2008 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2010 brdp = stli_brds[portp->brdnr];
2011 if (brdp == (stlibrd_t *) NULL)
2013 if (tty->flags & (1 << TTY_IO_ERROR))
2016 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
2017 &portp->asig, sizeof(asysigs_t), 1)) < 0)
2020 return stli_mktiocm(portp->asig.sigvalue);
2023 static int stli_tiocmset(struct tty_struct *tty, struct file *file,
2024 unsigned int set, unsigned int clear)
2026 stliport_t *portp = tty->driver_data;
2028 int rts = -1, dtr = -1;
2030 if (portp == (stliport_t *) NULL)
2032 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2034 brdp = stli_brds[portp->brdnr];
2035 if (brdp == (stlibrd_t *) NULL)
2037 if (tty->flags & (1 << TTY_IO_ERROR))
2040 if (set & TIOCM_RTS)
2042 if (set & TIOCM_DTR)
2044 if (clear & TIOCM_RTS)
2046 if (clear & TIOCM_DTR)
2049 stli_mkasysigs(&portp->asig, dtr, rts);
2051 return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
2052 sizeof(asysigs_t), 0);
2055 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
2061 void __user *argp = (void __user *)arg;
2064 printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
2065 (int) tty, (int) file, cmd, (int) arg);
2068 if (tty == (struct tty_struct *) NULL)
2070 portp = tty->driver_data;
2071 if (portp == (stliport_t *) NULL)
2073 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2075 brdp = stli_brds[portp->brdnr];
2076 if (brdp == (stlibrd_t *) NULL)
2079 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
2080 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
2081 if (tty->flags & (1 << TTY_IO_ERROR))
2089 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
2090 (unsigned __user *) arg);
2093 if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
2094 tty->termios->c_cflag =
2095 (tty->termios->c_cflag & ~CLOCAL) |
2096 (ival ? CLOCAL : 0);
2099 rc = stli_getserial(portp, argp);
2102 rc = stli_setserial(portp, argp);
2105 rc = put_user(portp->pflag, (unsigned __user *)argp);
2108 if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
2109 stli_setport(portp);
2111 case COM_GETPORTSTATS:
2112 rc = stli_getportstats(portp, argp);
2114 case COM_CLRPORTSTATS:
2115 rc = stli_clrportstats(portp, argp);
2121 case TIOCSERGSTRUCT:
2122 case TIOCSERGETMULTI:
2123 case TIOCSERSETMULTI:
2132 /*****************************************************************************/
2135 * This routine assumes that we have user context and can sleep.
2136 * Looks like it is true for the current ttys implementation..!!
2139 static void stli_settermios(struct tty_struct *tty, struct termios *old)
2143 struct termios *tiosp;
2147 printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
2150 if (tty == (struct tty_struct *) NULL)
2152 portp = tty->driver_data;
2153 if (portp == (stliport_t *) NULL)
2155 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2157 brdp = stli_brds[portp->brdnr];
2158 if (brdp == (stlibrd_t *) NULL)
2161 tiosp = tty->termios;
2162 if ((tiosp->c_cflag == old->c_cflag) &&
2163 (tiosp->c_iflag == old->c_iflag))
2166 stli_mkasyport(portp, &aport, tiosp);
2167 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
2168 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
2169 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
2170 sizeof(asysigs_t), 0);
2171 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
2172 tty->hw_stopped = 0;
2173 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
2174 wake_up_interruptible(&portp->open_wait);
2177 /*****************************************************************************/
2180 * Attempt to flow control who ever is sending us data. We won't really
2181 * do any flow control action here. We can't directly, and even if we
2182 * wanted to we would have to send a command to the slave. The slave
2183 * knows how to flow control, and will do so when its buffers reach its
2184 * internal high water marks. So what we will do is set a local state
2185 * bit that will stop us sending any RX data up from the poll routine
2186 * (which is the place where RX data from the slave is handled).
2189 static void stli_throttle(struct tty_struct *tty)
2194 printk("stli_throttle(tty=%x)\n", (int) tty);
2197 if (tty == (struct tty_struct *) NULL)
2199 portp = tty->driver_data;
2200 if (portp == (stliport_t *) NULL)
2203 set_bit(ST_RXSTOP, &portp->state);
2206 /*****************************************************************************/
2209 * Unflow control the device sending us data... That means that all
2210 * we have to do is clear the RXSTOP state bit. The next poll call
2211 * will then be able to pass the RX data back up.
2214 static void stli_unthrottle(struct tty_struct *tty)
2219 printk("stli_unthrottle(tty=%x)\n", (int) tty);
2222 if (tty == (struct tty_struct *) NULL)
2224 portp = tty->driver_data;
2225 if (portp == (stliport_t *) NULL)
2228 clear_bit(ST_RXSTOP, &portp->state);
2231 /*****************************************************************************/
2234 * Stop the transmitter. Basically to do this we will just turn TX
2238 static void stli_stop(struct tty_struct *tty)
2245 printk("stli_stop(tty=%x)\n", (int) tty);
2248 if (tty == (struct tty_struct *) NULL)
2250 portp = tty->driver_data;
2251 if (portp == (stliport_t *) NULL)
2253 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2255 brdp = stli_brds[portp->brdnr];
2256 if (brdp == (stlibrd_t *) NULL)
2259 memset(&actrl, 0, sizeof(asyctrl_t));
2260 actrl.txctrl = CT_STOPFLOW;
2262 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2266 /*****************************************************************************/
2269 * Start the transmitter again. Just turn TX interrupts back on.
2272 static void stli_start(struct tty_struct *tty)
2279 printk("stli_start(tty=%x)\n", (int) tty);
2282 if (tty == (struct tty_struct *) NULL)
2284 portp = tty->driver_data;
2285 if (portp == (stliport_t *) NULL)
2287 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2289 brdp = stli_brds[portp->brdnr];
2290 if (brdp == (stlibrd_t *) NULL)
2293 memset(&actrl, 0, sizeof(asyctrl_t));
2294 actrl.txctrl = CT_STARTFLOW;
2296 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2300 /*****************************************************************************/
2303 * Scheduler called hang up routine. This is called from the scheduler,
2304 * not direct from the driver "poll" routine. We can't call it there
2305 * since the real local hangup code will enable/disable the board and
2306 * other things that we can't do while handling the poll. Much easier
2307 * to deal with it some time later (don't really care when, hangups
2308 * aren't that time critical).
2311 static void stli_dohangup(void *arg)
2316 printk(KERN_DEBUG "stli_dohangup(portp=%x)\n", (int) arg);
2320 * FIXME: There's a module removal race here: tty_hangup
2321 * calls schedule_work which will call into this
2324 portp = (stliport_t *) arg;
2325 if (portp != (stliport_t *) NULL) {
2326 if (portp->tty != (struct tty_struct *) NULL) {
2327 tty_hangup(portp->tty);
2332 /*****************************************************************************/
2335 * Hangup this port. This is pretty much like closing the port, only
2336 * a little more brutal. No waiting for data to drain. Shutdown the
2337 * port and maybe drop signals. This is rather tricky really. We want
2338 * to close the port as well.
2341 static void stli_hangup(struct tty_struct *tty)
2345 unsigned long flags;
2348 printk(KERN_DEBUG "stli_hangup(tty=%x)\n", (int) tty);
2351 if (tty == (struct tty_struct *) NULL)
2353 portp = tty->driver_data;
2354 if (portp == (stliport_t *) NULL)
2356 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2358 brdp = stli_brds[portp->brdnr];
2359 if (brdp == (stlibrd_t *) NULL)
2362 portp->flags &= ~ASYNC_INITIALIZED;
2366 if (! test_bit(ST_CLOSING, &portp->state))
2367 stli_rawclose(brdp, portp, 0, 0);
2368 if (tty->termios->c_cflag & HUPCL) {
2369 stli_mkasysigs(&portp->asig, 0, 0);
2370 if (test_bit(ST_CMDING, &portp->state)) {
2371 set_bit(ST_DOSIGS, &portp->state);
2372 set_bit(ST_DOFLUSHTX, &portp->state);
2373 set_bit(ST_DOFLUSHRX, &portp->state);
2375 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
2376 &portp->asig, sizeof(asysigs_t), 0);
2379 restore_flags(flags);
2381 clear_bit(ST_TXBUSY, &portp->state);
2382 clear_bit(ST_RXSTOP, &portp->state);
2383 set_bit(TTY_IO_ERROR, &tty->flags);
2384 portp->tty = (struct tty_struct *) NULL;
2385 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
2386 portp->refcount = 0;
2387 wake_up_interruptible(&portp->open_wait);
2390 /*****************************************************************************/
2393 * Flush characters from the lower buffer. We may not have user context
2394 * so we cannot sleep waiting for it to complete. Also we need to check
2395 * if there is chars for this port in the TX cook buffer, and flush them
2399 static void stli_flushbuffer(struct tty_struct *tty)
2403 unsigned long ftype, flags;
2406 printk(KERN_DEBUG "stli_flushbuffer(tty=%x)\n", (int) tty);
2409 if (tty == (struct tty_struct *) NULL)
2411 portp = tty->driver_data;
2412 if (portp == (stliport_t *) NULL)
2414 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2416 brdp = stli_brds[portp->brdnr];
2417 if (brdp == (stlibrd_t *) NULL)
2422 if (tty == stli_txcooktty) {
2423 stli_txcooktty = (struct tty_struct *) NULL;
2424 stli_txcooksize = 0;
2425 stli_txcookrealsize = 0;
2427 if (test_bit(ST_CMDING, &portp->state)) {
2428 set_bit(ST_DOFLUSHTX, &portp->state);
2431 if (test_bit(ST_DOFLUSHRX, &portp->state)) {
2433 clear_bit(ST_DOFLUSHRX, &portp->state);
2435 stli_sendcmd(brdp, portp, A_FLUSH, &ftype,
2436 sizeof(unsigned long), 0);
2438 restore_flags(flags);
2440 wake_up_interruptible(&tty->write_wait);
2441 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2442 tty->ldisc.write_wakeup)
2443 (tty->ldisc.write_wakeup)(tty);
2446 /*****************************************************************************/
2448 static void stli_breakctl(struct tty_struct *tty, int state)
2453 /* long savestate, savetime; */
2456 printk(KERN_DEBUG "stli_breakctl(tty=%x,state=%d)\n", (int) tty, state);
2459 if (tty == (struct tty_struct *) NULL)
2461 portp = tty->driver_data;
2462 if (portp == (stliport_t *) NULL)
2464 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2466 brdp = stli_brds[portp->brdnr];
2467 if (brdp == (stlibrd_t *) NULL)
2471 * Due to a bug in the tty send_break() code we need to preserve
2472 * the current process state and timeout...
2473 savetime = current->timeout;
2474 savestate = current->state;
2477 arg = (state == -1) ? BREAKON : BREAKOFF;
2478 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
2482 current->timeout = savetime;
2483 current->state = savestate;
2487 /*****************************************************************************/
2489 static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2495 printk(KERN_DEBUG "stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty, timeout);
2498 if (tty == (struct tty_struct *) NULL)
2500 portp = tty->driver_data;
2501 if (portp == (stliport_t *) NULL)
2506 tend = jiffies + timeout;
2508 while (test_bit(ST_TXBUSY, &portp->state)) {
2509 if (signal_pending(current))
2512 if (time_after_eq(jiffies, tend))
2517 /*****************************************************************************/
2519 static void stli_sendxchar(struct tty_struct *tty, char ch)
2526 printk(KERN_DEBUG "stli_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
2529 if (tty == (struct tty_struct *) NULL)
2531 portp = tty->driver_data;
2532 if (portp == (stliport_t *) NULL)
2534 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2536 brdp = stli_brds[portp->brdnr];
2537 if (brdp == (stlibrd_t *) NULL)
2540 memset(&actrl, 0, sizeof(asyctrl_t));
2541 if (ch == STOP_CHAR(tty)) {
2542 actrl.rxctrl = CT_STOPFLOW;
2543 } else if (ch == START_CHAR(tty)) {
2544 actrl.rxctrl = CT_STARTFLOW;
2546 actrl.txctrl = CT_SENDCHR;
2550 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2553 /*****************************************************************************/
2558 * Format info for a specified port. The line is deliberately limited
2559 * to 80 characters. (If it is too long it will be truncated, if too
2560 * short then padded with spaces).
2563 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
2568 rc = stli_portcmdstats(portp);
2571 if (brdp->state & BST_STARTED) {
2572 switch (stli_comstats.hwid) {
2573 case 0: uart = "2681"; break;
2574 case 1: uart = "SC26198"; break;
2575 default: uart = "CD1400"; break;
2580 sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
2582 if ((brdp->state & BST_STARTED) && (rc >= 0)) {
2583 sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
2584 (int) stli_comstats.rxtotal);
2586 if (stli_comstats.rxframing)
2587 sp += sprintf(sp, " fe:%d",
2588 (int) stli_comstats.rxframing);
2589 if (stli_comstats.rxparity)
2590 sp += sprintf(sp, " pe:%d",
2591 (int) stli_comstats.rxparity);
2592 if (stli_comstats.rxbreaks)
2593 sp += sprintf(sp, " brk:%d",
2594 (int) stli_comstats.rxbreaks);
2595 if (stli_comstats.rxoverrun)
2596 sp += sprintf(sp, " oe:%d",
2597 (int) stli_comstats.rxoverrun);
2599 cnt = sprintf(sp, "%s%s%s%s%s ",
2600 (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
2601 (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
2602 (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
2603 (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
2604 (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
2609 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
2612 pos[(MAXLINE - 2)] = '+';
2613 pos[(MAXLINE - 1)] = '\n';
2618 /*****************************************************************************/
2621 * Port info, read from the /proc file system.
2624 static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2628 int brdnr, portnr, totalport;
2633 printk(KERN_DEBUG "stli_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
2634 "data=%x\n", (int) page, (int) start, (int) off, count,
2635 (int) eof, (int) data);
2643 pos += sprintf(pos, "%s: version %s", stli_drvtitle,
2645 while (pos < (page + MAXLINE - 1))
2652 * We scan through for each board, panel and port. The offset is
2653 * calculated on the fly, and irrelevant ports are skipped.
2655 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2656 brdp = stli_brds[brdnr];
2657 if (brdp == (stlibrd_t *) NULL)
2659 if (brdp->state == 0)
2662 maxoff = curoff + (brdp->nrports * MAXLINE);
2663 if (off >= maxoff) {
2668 totalport = brdnr * STL_MAXPORTS;
2669 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2671 portp = brdp->ports[portnr];
2672 if (portp == (stliport_t *) NULL)
2674 if (off >= (curoff += MAXLINE))
2676 if ((pos - page + MAXLINE) > count)
2678 pos += stli_portinfo(brdp, portp, totalport, pos);
2689 /*****************************************************************************/
2692 * Generic send command routine. This will send a message to the slave,
2693 * of the specified type with the specified argument. Must be very
2694 * careful of data that will be copied out from shared memory -
2695 * containing command results. The command completion is all done from
2696 * a poll routine that does not have user context. Therefore you cannot
2697 * copy back directly into user space, or to the kernel stack of a
2698 * process. This routine does not sleep, so can be called from anywhere.
2701 static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2703 volatile cdkhdr_t *hdrp;
2704 volatile cdkctrl_t *cp;
2705 volatile unsigned char *bits;
2706 unsigned long flags;
2709 printk(KERN_DEBUG "stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
2710 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
2711 (int) arg, size, copyback);
2717 if (test_bit(ST_CMDING, &portp->state)) {
2718 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2720 restore_flags(flags);
2725 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2727 memcpy((void *) &(cp->args[0]), arg, size);
2730 portp->argsize = size;
2735 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2736 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
2738 *bits |= portp->portbit;
2739 set_bit(ST_CMDING, &portp->state);
2741 restore_flags(flags);
2744 /*****************************************************************************/
2747 * Read data from shared memory. This assumes that the shared memory
2748 * is enabled and that interrupts are off. Basically we just empty out
2749 * the shared memory buffer into the tty buffer. Must be careful to
2750 * handle the case where we fill up the tty buffer, but still have
2751 * more chars to unload.
2754 static inline void stli_read(stlibrd_t *brdp, stliport_t *portp)
2756 volatile cdkasyrq_t *rp;
2757 volatile char *shbuf;
2758 struct tty_struct *tty;
2759 unsigned int head, tail, size;
2760 unsigned int len, stlen;
2763 printk(KERN_DEBUG "stli_read(brdp=%x,portp=%d)\n",
2764 (int) brdp, (int) portp);
2767 if (test_bit(ST_RXSTOP, &portp->state))
2770 if (tty == (struct tty_struct *) NULL)
2773 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2774 head = (unsigned int) rp->head;
2775 if (head != ((unsigned int) rp->head))
2776 head = (unsigned int) rp->head;
2777 tail = (unsigned int) rp->tail;
2778 size = portp->rxsize;
2783 len = size - (tail - head);
2784 stlen = size - tail;
2787 len = MIN(len, (TTY_FLIPBUF_SIZE - tty->flip.count));
2788 shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2791 stlen = MIN(len, stlen);
2792 memcpy(tty->flip.char_buf_ptr, (char *) (shbuf + tail), stlen);
2793 memset(tty->flip.flag_buf_ptr, 0, stlen);
2794 tty->flip.char_buf_ptr += stlen;
2795 tty->flip.flag_buf_ptr += stlen;
2796 tty->flip.count += stlen;
2805 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2809 set_bit(ST_RXING, &portp->state);
2811 tty_schedule_flip(tty);
2814 /*****************************************************************************/
2817 * Set up and carry out any delayed commands. There is only a small set
2818 * of slave commands that can be done "off-level". So it is not too
2819 * difficult to deal with them here.
2822 static inline void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2826 if (test_bit(ST_DOSIGS, &portp->state)) {
2827 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2828 test_bit(ST_DOFLUSHRX, &portp->state))
2829 cmd = A_SETSIGNALSF;
2830 else if (test_bit(ST_DOFLUSHTX, &portp->state))
2831 cmd = A_SETSIGNALSFTX;
2832 else if (test_bit(ST_DOFLUSHRX, &portp->state))
2833 cmd = A_SETSIGNALSFRX;
2836 clear_bit(ST_DOFLUSHTX, &portp->state);
2837 clear_bit(ST_DOFLUSHRX, &portp->state);
2838 clear_bit(ST_DOSIGS, &portp->state);
2839 memcpy((void *) &(cp->args[0]), (void *) &portp->asig,
2843 set_bit(ST_CMDING, &portp->state);
2844 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2845 test_bit(ST_DOFLUSHRX, &portp->state)) {
2846 cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2847 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2848 clear_bit(ST_DOFLUSHTX, &portp->state);
2849 clear_bit(ST_DOFLUSHRX, &portp->state);
2850 memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2853 set_bit(ST_CMDING, &portp->state);
2857 /*****************************************************************************/
2860 * Host command service checking. This handles commands or messages
2861 * coming from the slave to the host. Must have board shared memory
2862 * enabled and interrupts off when called. Notice that by servicing the
2863 * read data last we don't need to change the shared memory pointer
2864 * during processing (which is a slow IO operation).
2865 * Return value indicates if this port is still awaiting actions from
2866 * the slave (like open, command, or even TX data being sent). If 0
2867 * then port is still busy, otherwise no longer busy.
2870 static inline int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2872 volatile cdkasy_t *ap;
2873 volatile cdkctrl_t *cp;
2874 struct tty_struct *tty;
2876 unsigned long oldsigs;
2880 printk(KERN_DEBUG "stli_hostcmd(brdp=%x,channr=%d)\n",
2881 (int) brdp, channr);
2884 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
2888 * Check if we are waiting for an open completion message.
2890 if (test_bit(ST_OPENING, &portp->state)) {
2891 rc = (int) cp->openarg;
2892 if ((cp->open == 0) && (rc != 0)) {
2897 clear_bit(ST_OPENING, &portp->state);
2898 wake_up_interruptible(&portp->raw_wait);
2903 * Check if we are waiting for a close completion message.
2905 if (test_bit(ST_CLOSING, &portp->state)) {
2906 rc = (int) cp->closearg;
2907 if ((cp->close == 0) && (rc != 0)) {
2912 clear_bit(ST_CLOSING, &portp->state);
2913 wake_up_interruptible(&portp->raw_wait);
2918 * Check if we are waiting for a command completion message. We may
2919 * need to copy out the command results associated with this command.
2921 if (test_bit(ST_CMDING, &portp->state)) {
2923 if ((cp->cmd == 0) && (rc != 0)) {
2926 if (portp->argp != (void *) NULL) {
2927 memcpy(portp->argp, (void *) &(cp->args[0]),
2929 portp->argp = (void *) NULL;
2933 clear_bit(ST_CMDING, &portp->state);
2934 stli_dodelaycmd(portp, cp);
2935 wake_up_interruptible(&portp->raw_wait);
2940 * Check for any notification messages ready. This includes lots of
2941 * different types of events - RX chars ready, RX break received,
2942 * TX data low or empty in the slave, modem signals changed state.
2951 if (nt.signal & SG_DCD) {
2952 oldsigs = portp->sigs;
2953 portp->sigs = stli_mktiocm(nt.sigvalue);
2954 clear_bit(ST_GETSIGS, &portp->state);
2955 if ((portp->sigs & TIOCM_CD) &&
2956 ((oldsigs & TIOCM_CD) == 0))
2957 wake_up_interruptible(&portp->open_wait);
2958 if ((oldsigs & TIOCM_CD) &&
2959 ((portp->sigs & TIOCM_CD) == 0)) {
2960 if (portp->flags & ASYNC_CHECK_CD) {
2962 schedule_work(&portp->tqhangup);
2967 if (nt.data & DT_TXEMPTY)
2968 clear_bit(ST_TXBUSY, &portp->state);
2969 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2970 if (tty != (struct tty_struct *) NULL) {
2971 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2972 tty->ldisc.write_wakeup) {
2973 (tty->ldisc.write_wakeup)(tty);
2976 wake_up_interruptible(&tty->write_wait);
2980 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2981 if (tty != (struct tty_struct *) NULL) {
2982 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
2984 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2985 *tty->flip.char_buf_ptr++ = 0;
2986 if (portp->flags & ASYNC_SAK) {
2990 tty_schedule_flip(tty);
2995 if (nt.data & DT_RXBUSY) {
2997 stli_read(brdp, portp);
3002 * It might seem odd that we are checking for more RX chars here.
3003 * But, we need to handle the case where the tty buffer was previously
3004 * filled, but we had more characters to pass up. The slave will not
3005 * send any more RX notify messages until the RX buffer has been emptied.
3006 * But it will leave the service bits on (since the buffer is not empty).
3007 * So from here we can try to process more RX chars.
3009 if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
3010 clear_bit(ST_RXING, &portp->state);
3011 stli_read(brdp, portp);
3014 return((test_bit(ST_OPENING, &portp->state) ||
3015 test_bit(ST_CLOSING, &portp->state) ||
3016 test_bit(ST_CMDING, &portp->state) ||
3017 test_bit(ST_TXBUSY, &portp->state) ||
3018 test_bit(ST_RXING, &portp->state)) ? 0 : 1);
3021 /*****************************************************************************/
3024 * Service all ports on a particular board. Assumes that the boards
3025 * shared memory is enabled, and that the page pointer is pointed
3026 * at the cdk header structure.
3029 static inline void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
3032 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
3033 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
3034 unsigned char *slavep;
3035 int bitpos, bitat, bitsize;
3036 int channr, nrdevs, slavebitchange;
3038 bitsize = brdp->bitsize;
3039 nrdevs = brdp->nrdevs;
3042 * Check if slave wants any service. Basically we try to do as
3043 * little work as possible here. There are 2 levels of service
3044 * bits. So if there is nothing to do we bail early. We check
3045 * 8 service bits at a time in the inner loop, so we can bypass
3046 * the lot if none of them want service.
3048 memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset),
3051 memset(&slavebits[0], 0, bitsize);
3054 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
3055 if (hostbits[bitpos] == 0)
3057 channr = bitpos * 8;
3058 for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
3059 if (hostbits[bitpos] & bitat) {
3060 portp = brdp->ports[(channr - 1)];
3061 if (stli_hostcmd(brdp, portp)) {
3063 slavebits[bitpos] |= bitat;
3070 * If any of the ports are no longer busy then update them in the
3071 * slave request bits. We need to do this after, since a host port
3072 * service may initiate more slave requests.
3074 if (slavebitchange) {
3075 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3076 slavep = ((unsigned char *) hdrp) + brdp->slaveoffset;
3077 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
3078 if (slavebits[bitpos])
3079 slavep[bitpos] &= ~slavebits[bitpos];
3084 /*****************************************************************************/
3087 * Driver poll routine. This routine polls the boards in use and passes
3088 * messages back up to host when necessary. This is actually very
3089 * CPU efficient, since we will always have the kernel poll clock, it
3090 * adds only a few cycles when idle (since board service can be
3091 * determined very easily), but when loaded generates no interrupts
3092 * (with their expensive associated context change).
3095 static void stli_poll(unsigned long arg)
3097 volatile cdkhdr_t *hdrp;
3101 stli_timerlist.expires = STLI_TIMEOUT;
3102 add_timer(&stli_timerlist);
3105 * Check each board and do any servicing required.
3107 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
3108 brdp = stli_brds[brdnr];
3109 if (brdp == (stlibrd_t *) NULL)
3111 if ((brdp->state & BST_STARTED) == 0)
3115 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3117 stli_brdpoll(brdp, hdrp);
3122 /*****************************************************************************/
3125 * Translate the termios settings into the port setting structure of
3129 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
3132 printk(KERN_DEBUG "stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
3133 (int) portp, (int) pp, (int) tiosp);
3136 memset(pp, 0, sizeof(asyport_t));
3139 * Start of by setting the baud, char size, parity and stop bit info.
3141 pp->baudout = tiosp->c_cflag & CBAUD;
3142 if (pp->baudout & CBAUDEX) {
3143 pp->baudout &= ~CBAUDEX;
3144 if ((pp->baudout < 1) || (pp->baudout > 4))
3145 tiosp->c_cflag &= ~CBAUDEX;
3149 pp->baudout = stli_baudrates[pp->baudout];
3150 if ((tiosp->c_cflag & CBAUD) == B38400) {
3151 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3152 pp->baudout = 57600;
3153 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3154 pp->baudout = 115200;
3155 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3156 pp->baudout = 230400;
3157 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3158 pp->baudout = 460800;
3159 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3160 pp->baudout = (portp->baud_base / portp->custom_divisor);
3162 if (pp->baudout > STL_MAXBAUD)
3163 pp->baudout = STL_MAXBAUD;
3164 pp->baudin = pp->baudout;
3166 switch (tiosp->c_cflag & CSIZE) {
3181 if (tiosp->c_cflag & CSTOPB)
3182 pp->stopbs = PT_STOP2;
3184 pp->stopbs = PT_STOP1;
3186 if (tiosp->c_cflag & PARENB) {
3187 if (tiosp->c_cflag & PARODD)
3188 pp->parity = PT_ODDPARITY;
3190 pp->parity = PT_EVENPARITY;
3192 pp->parity = PT_NOPARITY;
3196 * Set up any flow control options enabled.
3198 if (tiosp->c_iflag & IXON) {
3200 if (tiosp->c_iflag & IXANY)
3201 pp->flow |= F_IXANY;
3203 if (tiosp->c_cflag & CRTSCTS)
3204 pp->flow |= (F_RTSFLOW | F_CTSFLOW);
3206 pp->startin = tiosp->c_cc[VSTART];
3207 pp->stopin = tiosp->c_cc[VSTOP];
3208 pp->startout = tiosp->c_cc[VSTART];
3209 pp->stopout = tiosp->c_cc[VSTOP];
3212 * Set up the RX char marking mask with those RX error types we must
3213 * catch. We can get the slave to help us out a little here, it will
3214 * ignore parity errors and breaks for us, and mark parity errors in
3217 if (tiosp->c_iflag & IGNPAR)
3218 pp->iflag |= FI_IGNRXERRS;
3219 if (tiosp->c_iflag & IGNBRK)
3220 pp->iflag |= FI_IGNBREAK;
3222 portp->rxmarkmsk = 0;
3223 if (tiosp->c_iflag & (INPCK | PARMRK))
3224 pp->iflag |= FI_1MARKRXERRS;
3225 if (tiosp->c_iflag & BRKINT)
3226 portp->rxmarkmsk |= BRKINT;
3229 * Set up clocal processing as required.
3231 if (tiosp->c_cflag & CLOCAL)
3232 portp->flags &= ~ASYNC_CHECK_CD;
3234 portp->flags |= ASYNC_CHECK_CD;
3237 * Transfer any persistent flags into the asyport structure.
3239 pp->pflag = (portp->pflag & 0xffff);
3240 pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
3241 pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
3242 pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
3245 /*****************************************************************************/
3248 * Construct a slave signals structure for setting the DTR and RTS
3249 * signals as specified.
3252 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
3255 printk(KERN_DEBUG "stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n",
3256 (int) sp, dtr, rts);
3259 memset(sp, 0, sizeof(asysigs_t));
3261 sp->signal |= SG_DTR;
3262 sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
3265 sp->signal |= SG_RTS;
3266 sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
3270 /*****************************************************************************/
3273 * Convert the signals returned from the slave into a local TIOCM type
3274 * signals value. We keep them locally in TIOCM format.
3277 static long stli_mktiocm(unsigned long sigvalue)
3282 printk(KERN_DEBUG "stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
3286 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
3287 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
3288 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
3289 tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
3290 tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
3291 tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
3295 /*****************************************************************************/
3298 * All panels and ports actually attached have been worked out. All
3299 * we need to do here is set up the appropriate per port data structures.
3302 static inline int stli_initports(stlibrd_t *brdp)
3305 int i, panelnr, panelport;
3308 printk(KERN_DEBUG "stli_initports(brdp=%x)\n", (int) brdp);
3311 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
3312 portp = (stliport_t *) stli_memalloc(sizeof(stliport_t));
3313 if (portp == (stliport_t *) NULL) {
3314 printk("STALLION: failed to allocate port structure\n");
3318 memset(portp, 0, sizeof(stliport_t));
3319 portp->magic = STLI_PORTMAGIC;
3321 portp->brdnr = brdp->brdnr;
3322 portp->panelnr = panelnr;
3323 portp->baud_base = STL_BAUDBASE;
3324 portp->close_delay = STL_CLOSEDELAY;
3325 portp->closing_wait = 30 * HZ;
3326 INIT_WORK(&portp->tqhangup, stli_dohangup, portp);
3327 init_waitqueue_head(&portp->open_wait);
3328 init_waitqueue_head(&portp->close_wait);
3329 init_waitqueue_head(&portp->raw_wait);
3331 if (panelport >= brdp->panels[panelnr]) {
3335 brdp->ports[i] = portp;
3341 /*****************************************************************************/
3344 * All the following routines are board specific hardware operations.
3347 static void stli_ecpinit(stlibrd_t *brdp)
3349 unsigned long memconf;
3352 printk(KERN_DEBUG "stli_ecpinit(brdp=%d)\n", (int) brdp);
3355 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3357 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3360 memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
3361 outb(memconf, (brdp->iobase + ECP_ATMEMAR));
3364 /*****************************************************************************/
3366 static void stli_ecpenable(stlibrd_t *brdp)
3369 printk(KERN_DEBUG "stli_ecpenable(brdp=%x)\n", (int) brdp);
3371 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
3374 /*****************************************************************************/
3376 static void stli_ecpdisable(stlibrd_t *brdp)
3379 printk(KERN_DEBUG "stli_ecpdisable(brdp=%x)\n", (int) brdp);
3381 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3384 /*****************************************************************************/
3386 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3392 printk(KERN_DEBUG "stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3396 if (offset > brdp->memsize) {
3397 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3398 "range at line=%d(%d), brd=%d\n",
3399 (int) offset, line, __LINE__, brdp->brdnr);
3403 ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
3404 val = (unsigned char) (offset / ECP_ATPAGESIZE);
3406 outb(val, (brdp->iobase + ECP_ATMEMPR));
3410 /*****************************************************************************/
3412 static void stli_ecpreset(stlibrd_t *brdp)
3415 printk(KERN_DEBUG "stli_ecpreset(brdp=%x)\n", (int) brdp);
3418 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3420 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3424 /*****************************************************************************/
3426 static void stli_ecpintr(stlibrd_t *brdp)
3429 printk(KERN_DEBUG "stli_ecpintr(brdp=%x)\n", (int) brdp);
3431 outb(0x1, brdp->iobase);
3434 /*****************************************************************************/
3437 * The following set of functions act on ECP EISA boards.
3440 static void stli_ecpeiinit(stlibrd_t *brdp)
3442 unsigned long memconf;
3445 printk(KERN_DEBUG "stli_ecpeiinit(brdp=%x)\n", (int) brdp);
3448 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3449 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3451 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3454 memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
3455 outb(memconf, (brdp->iobase + ECP_EIMEMARL));
3456 memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
3457 outb(memconf, (brdp->iobase + ECP_EIMEMARH));
3460 /*****************************************************************************/
3462 static void stli_ecpeienable(stlibrd_t *brdp)
3464 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
3467 /*****************************************************************************/
3469 static void stli_ecpeidisable(stlibrd_t *brdp)
3471 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3474 /*****************************************************************************/
3476 static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3482 printk(KERN_DEBUG "stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3483 (int) brdp, (int) offset, line);
3486 if (offset > brdp->memsize) {
3487 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3488 "range at line=%d(%d), brd=%d\n",
3489 (int) offset, line, __LINE__, brdp->brdnr);
3493 ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
3494 if (offset < ECP_EIPAGESIZE)
3497 val = ECP_EIENABLE | 0x40;
3499 outb(val, (brdp->iobase + ECP_EICONFR));
3503 /*****************************************************************************/
3505 static void stli_ecpeireset(stlibrd_t *brdp)
3507 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3509 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3513 /*****************************************************************************/
3516 * The following set of functions act on ECP MCA boards.
3519 static void stli_ecpmcenable(stlibrd_t *brdp)
3521 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
3524 /*****************************************************************************/
3526 static void stli_ecpmcdisable(stlibrd_t *brdp)
3528 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3531 /*****************************************************************************/
3533 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3538 if (offset > brdp->memsize) {
3539 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3540 "range at line=%d(%d), brd=%d\n",
3541 (int) offset, line, __LINE__, brdp->brdnr);
3545 ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3546 val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3548 outb(val, (brdp->iobase + ECP_MCCONFR));
3552 /*****************************************************************************/
3554 static void stli_ecpmcreset(stlibrd_t *brdp)
3556 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3558 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3562 /*****************************************************************************/
3565 * The following set of functions act on ECP PCI boards.
3568 static void stli_ecppciinit(stlibrd_t *brdp)
3571 printk(KERN_DEBUG "stli_ecppciinit(brdp=%x)\n", (int) brdp);
3574 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3576 outb(0, (brdp->iobase + ECP_PCICONFR));
3580 /*****************************************************************************/
3582 static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3588 printk(KERN_DEBUG "stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3589 (int) brdp, (int) offset, line);
3592 if (offset > brdp->memsize) {
3593 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3594 "range at line=%d(%d), board=%d\n",
3595 (int) offset, line, __LINE__, brdp->brdnr);
3599 ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
3600 val = (offset / ECP_PCIPAGESIZE) << 1;
3602 outb(val, (brdp->iobase + ECP_PCICONFR));
3606 /*****************************************************************************/
3608 static void stli_ecppcireset(stlibrd_t *brdp)
3610 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3612 outb(0, (brdp->iobase + ECP_PCICONFR));
3616 /*****************************************************************************/
3619 * The following routines act on ONboards.
3622 static void stli_onbinit(stlibrd_t *brdp)
3624 unsigned long memconf;
3627 printk(KERN_DEBUG "stli_onbinit(brdp=%d)\n", (int) brdp);
3630 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3632 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3635 memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3636 outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3637 outb(0x1, brdp->iobase);
3641 /*****************************************************************************/
3643 static void stli_onbenable(stlibrd_t *brdp)
3646 printk(KERN_DEBUG "stli_onbenable(brdp=%x)\n", (int) brdp);
3648 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3651 /*****************************************************************************/
3653 static void stli_onbdisable(stlibrd_t *brdp)
3656 printk(KERN_DEBUG "stli_onbdisable(brdp=%x)\n", (int) brdp);
3658 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3661 /*****************************************************************************/
3663 static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3668 printk(KERN_DEBUG "stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3672 if (offset > brdp->memsize) {
3673 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3674 "range at line=%d(%d), brd=%d\n",
3675 (int) offset, line, __LINE__, brdp->brdnr);
3678 ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3683 /*****************************************************************************/
3685 static void stli_onbreset(stlibrd_t *brdp)
3689 printk(KERN_DEBUG "stli_onbreset(brdp=%x)\n", (int) brdp);
3692 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3694 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3698 /*****************************************************************************/
3701 * The following routines act on ONboard EISA.
3704 static void stli_onbeinit(stlibrd_t *brdp)
3706 unsigned long memconf;
3709 printk(KERN_DEBUG "stli_onbeinit(brdp=%d)\n", (int) brdp);
3712 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3713 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3715 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3718 memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3719 outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3720 memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3721 outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3722 outb(0x1, brdp->iobase);
3726 /*****************************************************************************/
3728 static void stli_onbeenable(stlibrd_t *brdp)
3731 printk(KERN_DEBUG "stli_onbeenable(brdp=%x)\n", (int) brdp);
3733 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3736 /*****************************************************************************/
3738 static void stli_onbedisable(stlibrd_t *brdp)
3741 printk(KERN_DEBUG "stli_onbedisable(brdp=%x)\n", (int) brdp);
3743 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3746 /*****************************************************************************/
3748 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3754 printk(KERN_DEBUG "stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
3755 (int) brdp, (int) offset, line);
3758 if (offset > brdp->memsize) {
3759 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3760 "range at line=%d(%d), brd=%d\n",
3761 (int) offset, line, __LINE__, brdp->brdnr);
3765 ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3766 if (offset < ONB_EIPAGESIZE)
3769 val = ONB_EIENABLE | 0x40;
3771 outb(val, (brdp->iobase + ONB_EICONFR));
3775 /*****************************************************************************/
3777 static void stli_onbereset(stlibrd_t *brdp)
3781 printk(KERN_ERR "stli_onbereset(brdp=%x)\n", (int) brdp);
3784 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3786 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3790 /*****************************************************************************/
3793 * The following routines act on Brumby boards.
3796 static void stli_bbyinit(stlibrd_t *brdp)
3800 printk(KERN_ERR "stli_bbyinit(brdp=%d)\n", (int) brdp);
3803 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3805 outb(0, (brdp->iobase + BBY_ATCONFR));
3807 outb(0x1, brdp->iobase);
3811 /*****************************************************************************/
3813 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3819 printk(KERN_ERR "stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3823 if (offset > brdp->memsize) {
3824 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3825 "range at line=%d(%d), brd=%d\n",
3826 (int) offset, line, __LINE__, brdp->brdnr);
3830 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3831 val = (unsigned char) (offset / BBY_PAGESIZE);
3833 outb(val, (brdp->iobase + BBY_ATCONFR));
3837 /*****************************************************************************/
3839 static void stli_bbyreset(stlibrd_t *brdp)
3843 printk(KERN_DEBUG "stli_bbyreset(brdp=%x)\n", (int) brdp);
3846 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3848 outb(0, (brdp->iobase + BBY_ATCONFR));
3852 /*****************************************************************************/
3855 * The following routines act on original old Stallion boards.
3858 static void stli_stalinit(stlibrd_t *brdp)
3862 printk(KERN_DEBUG "stli_stalinit(brdp=%d)\n", (int) brdp);
3865 outb(0x1, brdp->iobase);
3869 /*****************************************************************************/
3871 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3876 printk(KERN_DEBUG "stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3880 if (offset > brdp->memsize) {
3881 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3882 "range at line=%d(%d), brd=%d\n",
3883 (int) offset, line, __LINE__, brdp->brdnr);
3886 ptr = brdp->membase + (offset % STAL_PAGESIZE);
3891 /*****************************************************************************/
3893 static void stli_stalreset(stlibrd_t *brdp)
3895 volatile unsigned long *vecp;
3898 printk(KERN_DEBUG "stli_stalreset(brdp=%x)\n", (int) brdp);
3901 vecp = (volatile unsigned long *) (brdp->membase + 0x30);
3903 outb(0, brdp->iobase);
3907 /*****************************************************************************/
3910 * Try to find an ECP board and initialize it. This handles only ECP
3914 static inline int stli_initecp(stlibrd_t *brdp)
3918 unsigned int status, nxtid;
3920 int panelnr, nrports;
3923 printk(KERN_DEBUG "stli_initecp(brdp=%x)\n", (int) brdp);
3926 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3929 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3931 release_region(brdp->iobase, brdp->iosize);
3935 brdp->iosize = ECP_IOSIZE;
3938 * Based on the specific board type setup the common vars to access
3939 * and enable shared memory. Set all board specific information now
3942 switch (brdp->brdtype) {
3944 brdp->membase = (void *) brdp->memaddr;
3945 brdp->memsize = ECP_MEMSIZE;
3946 brdp->pagesize = ECP_ATPAGESIZE;
3947 brdp->init = stli_ecpinit;
3948 brdp->enable = stli_ecpenable;
3949 brdp->reenable = stli_ecpenable;
3950 brdp->disable = stli_ecpdisable;
3951 brdp->getmemptr = stli_ecpgetmemptr;
3952 brdp->intr = stli_ecpintr;
3953 brdp->reset = stli_ecpreset;
3954 name = "serial(EC8/64)";
3958 brdp->membase = (void *) brdp->memaddr;
3959 brdp->memsize = ECP_MEMSIZE;
3960 brdp->pagesize = ECP_EIPAGESIZE;
3961 brdp->init = stli_ecpeiinit;
3962 brdp->enable = stli_ecpeienable;
3963 brdp->reenable = stli_ecpeienable;
3964 brdp->disable = stli_ecpeidisable;
3965 brdp->getmemptr = stli_ecpeigetmemptr;
3966 brdp->intr = stli_ecpintr;
3967 brdp->reset = stli_ecpeireset;
3968 name = "serial(EC8/64-EI)";
3972 brdp->membase = (void *) brdp->memaddr;
3973 brdp->memsize = ECP_MEMSIZE;
3974 brdp->pagesize = ECP_MCPAGESIZE;
3976 brdp->enable = stli_ecpmcenable;
3977 brdp->reenable = stli_ecpmcenable;
3978 brdp->disable = stli_ecpmcdisable;
3979 brdp->getmemptr = stli_ecpmcgetmemptr;
3980 brdp->intr = stli_ecpintr;
3981 brdp->reset = stli_ecpmcreset;
3982 name = "serial(EC8/64-MCA)";
3986 brdp->membase = (void *) brdp->memaddr;
3987 brdp->memsize = ECP_PCIMEMSIZE;
3988 brdp->pagesize = ECP_PCIPAGESIZE;
3989 brdp->init = stli_ecppciinit;
3990 brdp->enable = NULL;
3991 brdp->reenable = NULL;
3992 brdp->disable = NULL;
3993 brdp->getmemptr = stli_ecppcigetmemptr;
3994 brdp->intr = stli_ecpintr;
3995 brdp->reset = stli_ecppcireset;
3996 name = "serial(EC/RA-PCI)";
4000 release_region(brdp->iobase, brdp->iosize);
4005 * The per-board operations structure is all set up, so now let's go
4006 * and get the board operational. Firstly initialize board configuration
4007 * registers. Set the memory mapping info so we can get at the boards
4012 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4013 if (brdp->membase == (void *) NULL)
4015 release_region(brdp->iobase, brdp->iosize);
4020 * Now that all specific code is set up, enable the shared memory and
4021 * look for the a signature area that will tell us exactly what board
4022 * this is, and what it is connected to it.
4025 sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
4026 memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
4030 printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
4031 __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
4032 (int) sig.panelid[1], (int) sig.panelid[2],
4033 (int) sig.panelid[3], (int) sig.panelid[4],
4034 (int) sig.panelid[5], (int) sig.panelid[6],
4035 (int) sig.panelid[7]);
4038 if (sig.magic != ECP_MAGIC)
4040 release_region(brdp->iobase, brdp->iosize);
4045 * Scan through the signature looking at the panels connected to the
4046 * board. Calculate the total number of ports as we go.
4048 for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
4049 status = sig.panelid[nxtid];
4050 if ((status & ECH_PNLIDMASK) != nxtid)
4053 brdp->panelids[panelnr] = status;
4054 nrports = (status & ECH_PNL16PORT) ? 16 : 8;
4055 if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
4057 brdp->panels[panelnr] = nrports;
4058 brdp->nrports += nrports;
4064 brdp->state |= BST_FOUND;
4068 /*****************************************************************************/
4071 * Try to find an ONboard, Brumby or Stallion board and initialize it.
4072 * This handles only these board types.
4075 static inline int stli_initonb(stlibrd_t *brdp)
4083 printk(KERN_DEBUG "stli_initonb(brdp=%x)\n", (int) brdp);
4087 * Do a basic sanity check on the IO and memory addresses.
4089 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
4092 brdp->iosize = ONB_IOSIZE;
4094 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
4098 * Based on the specific board type setup the common vars to access
4099 * and enable shared memory. Set all board specific information now
4102 switch (brdp->brdtype) {
4106 case BRD_ONBOARD2_32:
4108 brdp->membase = (void *) brdp->memaddr;
4109 brdp->memsize = ONB_MEMSIZE;
4110 brdp->pagesize = ONB_ATPAGESIZE;
4111 brdp->init = stli_onbinit;
4112 brdp->enable = stli_onbenable;
4113 brdp->reenable = stli_onbenable;
4114 brdp->disable = stli_onbdisable;
4115 brdp->getmemptr = stli_onbgetmemptr;
4116 brdp->intr = stli_ecpintr;
4117 brdp->reset = stli_onbreset;
4118 if (brdp->memaddr > 0x100000)
4119 brdp->enabval = ONB_MEMENABHI;
4121 brdp->enabval = ONB_MEMENABLO;
4122 name = "serial(ONBoard)";
4126 brdp->membase = (void *) brdp->memaddr;
4127 brdp->memsize = ONB_EIMEMSIZE;
4128 brdp->pagesize = ONB_EIPAGESIZE;
4129 brdp->init = stli_onbeinit;
4130 brdp->enable = stli_onbeenable;
4131 brdp->reenable = stli_onbeenable;
4132 brdp->disable = stli_onbedisable;
4133 brdp->getmemptr = stli_onbegetmemptr;
4134 brdp->intr = stli_ecpintr;
4135 brdp->reset = stli_onbereset;
4136 name = "serial(ONBoard/E)";
4142 brdp->membase = (void *) brdp->memaddr;
4143 brdp->memsize = BBY_MEMSIZE;
4144 brdp->pagesize = BBY_PAGESIZE;
4145 brdp->init = stli_bbyinit;
4146 brdp->enable = NULL;
4147 brdp->reenable = NULL;
4148 brdp->disable = NULL;
4149 brdp->getmemptr = stli_bbygetmemptr;
4150 brdp->intr = stli_ecpintr;
4151 brdp->reset = stli_bbyreset;
4152 name = "serial(Brumby)";
4156 brdp->membase = (void *) brdp->memaddr;
4157 brdp->memsize = STAL_MEMSIZE;
4158 brdp->pagesize = STAL_PAGESIZE;
4159 brdp->init = stli_stalinit;
4160 brdp->enable = NULL;
4161 brdp->reenable = NULL;
4162 brdp->disable = NULL;
4163 brdp->getmemptr = stli_stalgetmemptr;
4164 brdp->intr = stli_ecpintr;
4165 brdp->reset = stli_stalreset;
4166 name = "serial(Stallion)";
4170 release_region(brdp->iobase, brdp->iosize);
4175 * The per-board operations structure is all set up, so now let's go
4176 * and get the board operational. Firstly initialize board configuration
4177 * registers. Set the memory mapping info so we can get at the boards
4182 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4183 if (brdp->membase == (void *) NULL)
4185 release_region(brdp->iobase, brdp->iosize);
4190 * Now that all specific code is set up, enable the shared memory and
4191 * look for the a signature area that will tell us exactly what board
4192 * this is, and how many ports.
4195 sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
4196 memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
4200 printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
4201 __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
4202 sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
4205 if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
4206 (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
4208 release_region(brdp->iobase, brdp->iosize);
4213 * Scan through the signature alive mask and calculate how many ports
4214 * there are on this board.
4220 for (i = 0; (i < 16); i++) {
4221 if (((sig.amask0 << i) & 0x8000) == 0)
4226 brdp->panels[0] = brdp->nrports;
4229 brdp->state |= BST_FOUND;
4233 /*****************************************************************************/
4236 * Start up a running board. This routine is only called after the
4237 * code has been down loaded to the board and is operational. It will
4238 * read in the memory map, and get the show on the road...
4241 static int stli_startbrd(stlibrd_t *brdp)
4243 volatile cdkhdr_t *hdrp;
4244 volatile cdkmem_t *memp;
4245 volatile cdkasy_t *ap;
4246 unsigned long flags;
4248 int portnr, nrdevs, i, rc;
4251 printk(KERN_DEBUG "stli_startbrd(brdp=%x)\n", (int) brdp);
4259 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
4260 nrdevs = hdrp->nrdevs;
4263 printk("%s(%d): CDK version %d.%d.%d --> "
4264 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
4265 __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification,
4266 hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp,
4267 (int) hdrp->slavep);
4270 if (nrdevs < (brdp->nrports + 1)) {
4271 printk(KERN_ERR "STALLION: slave failed to allocate memory for "
4272 "all devices, devices=%d\n", nrdevs);
4273 brdp->nrports = nrdevs - 1;
4275 brdp->nrdevs = nrdevs;
4276 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
4277 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
4278 brdp->bitsize = (nrdevs + 7) / 8;
4279 memp = (volatile cdkmem_t *) hdrp->memp;
4280 if (((unsigned long) memp) > brdp->memsize) {
4281 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
4283 goto stli_donestartup;
4285 memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp);
4286 if (memp->dtype != TYP_ASYNCTRL) {
4287 printk(KERN_ERR "STALLION: no slave control device found\n");
4288 goto stli_donestartup;
4293 * Cycle through memory allocation of each port. We are guaranteed to
4294 * have all ports inside the first page of slave window, so no need to
4295 * change pages while reading memory map.
4297 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
4298 if (memp->dtype != TYP_ASYNC)
4300 portp = brdp->ports[portnr];
4301 if (portp == (stliport_t *) NULL)
4304 portp->addr = memp->offset;
4305 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
4306 portp->portidx = (unsigned char) (i / 8);
4307 portp->portbit = (unsigned char) (0x1 << (i % 8));
4310 hdrp->slavereq = 0xff;
4313 * For each port setup a local copy of the RX and TX buffer offsets
4314 * and sizes. We do this separate from the above, because we need to
4315 * move the shared memory page...
4317 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
4318 portp = brdp->ports[portnr];
4319 if (portp == (stliport_t *) NULL)
4321 if (portp->addr == 0)
4323 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
4324 if (ap != (volatile cdkasy_t *) NULL) {
4325 portp->rxsize = ap->rxq.size;
4326 portp->txsize = ap->txq.size;
4327 portp->rxoffset = ap->rxq.offset;
4328 portp->txoffset = ap->txq.offset;
4334 restore_flags(flags);
4337 brdp->state |= BST_STARTED;
4339 if (! stli_timeron) {
4341 stli_timerlist.expires = STLI_TIMEOUT;
4342 add_timer(&stli_timerlist);
4348 /*****************************************************************************/
4351 * Probe and initialize the specified board.
4354 static int __init stli_brdinit(stlibrd_t *brdp)
4357 printk(KERN_DEBUG "stli_brdinit(brdp=%x)\n", (int) brdp);
4360 stli_brds[brdp->brdnr] = brdp;
4362 switch (brdp->brdtype) {
4373 case BRD_ONBOARD2_32:
4385 printk(KERN_ERR "STALLION: %s board type not supported in "
4386 "this driver\n", stli_brdnames[brdp->brdtype]);
4389 printk(KERN_ERR "STALLION: board=%d is unknown board "
4390 "type=%d\n", brdp->brdnr, brdp->brdtype);
4394 if ((brdp->state & BST_FOUND) == 0) {
4395 printk(KERN_ERR "STALLION: %s board not found, board=%d "
4397 stli_brdnames[brdp->brdtype], brdp->brdnr,
4398 brdp->iobase, (int) brdp->memaddr);
4402 stli_initports(brdp);
4403 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
4404 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
4405 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
4406 brdp->nrpanels, brdp->nrports);
4410 /*****************************************************************************/
4413 * Probe around trying to find where the EISA boards shared memory
4414 * might be. This is a bit if hack, but it is the best we can do.
4417 static inline int stli_eisamemprobe(stlibrd_t *brdp)
4419 cdkecpsig_t ecpsig, *ecpsigp;
4420 cdkonbsig_t onbsig, *onbsigp;
4424 printk(KERN_DEBUG "stli_eisamemprobe(brdp=%x)\n", (int) brdp);
4428 * First up we reset the board, to get it into a known state. There
4429 * is only 2 board types here we need to worry about. Don;t use the
4430 * standard board init routine here, it programs up the shared
4431 * memory address, and we don't know it yet...
4433 if (brdp->brdtype == BRD_ECPE) {
4434 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
4435 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
4437 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
4439 stli_ecpeienable(brdp);
4440 } else if (brdp->brdtype == BRD_ONBOARDE) {
4441 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
4442 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
4444 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
4446 outb(0x1, brdp->iobase);
4448 stli_onbeenable(brdp);
4454 brdp->memsize = ECP_MEMSIZE;
4457 * Board shared memory is enabled, so now we have a poke around and
4458 * see if we can find it.
4460 for (i = 0; (i < stli_eisamempsize); i++) {
4461 brdp->memaddr = stli_eisamemprobeaddrs[i];
4462 brdp->membase = (void *) brdp->memaddr;
4463 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4464 if (brdp->membase == (void *) NULL)
4467 if (brdp->brdtype == BRD_ECPE) {
4468 ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp,
4469 CDK_SIGADDR, __LINE__);
4470 memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
4471 if (ecpsig.magic == ECP_MAGIC)
4474 onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp,
4475 CDK_SIGADDR, __LINE__);
4476 memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t));
4477 if ((onbsig.magic0 == ONB_MAGIC0) &&
4478 (onbsig.magic1 == ONB_MAGIC1) &&
4479 (onbsig.magic2 == ONB_MAGIC2) &&
4480 (onbsig.magic3 == ONB_MAGIC3))
4484 iounmap(brdp->membase);
4490 * Regardless of whether we found the shared memory or not we must
4491 * disable the region. After that return success or failure.
4493 if (brdp->brdtype == BRD_ECPE)
4494 stli_ecpeidisable(brdp);
4496 stli_onbedisable(brdp);
4500 brdp->membase = NULL;
4501 printk(KERN_ERR "STALLION: failed to probe shared memory "
4502 "region for %s in EISA slot=%d\n",
4503 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
4509 static inline int stli_getbrdnr(void)
4513 for (i = 0; i < STL_MAXBRDS; i++) {
4514 if (!stli_brds[i]) {
4515 if (i >= stli_nrbrds)
4516 stli_nrbrds = i + 1;
4523 /*****************************************************************************/
4526 * Probe around and try to find any EISA boards in system. The biggest
4527 * problem here is finding out what memory address is associated with
4528 * an EISA board after it is found. The registers of the ECPE and
4529 * ONboardE are not readable - so we can't read them from there. We
4530 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
4531 * actually have any way to find out the real value. The best we can
4532 * do is go probing around in the usual places hoping we can find it.
4535 static inline int stli_findeisabrds(void)
4538 unsigned int iobase, eid;
4542 printk(KERN_DEBUG "stli_findeisabrds()\n");
4546 * Firstly check if this is an EISA system. Do this by probing for
4547 * the system board EISA ID. If this is not an EISA system then
4548 * don't bother going any further!
4551 if (inb(0xc80) == 0xff)
4555 * Looks like an EISA system, so go searching for EISA boards.
4557 for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
4558 outb(0xff, (iobase + 0xc80));
4559 eid = inb(iobase + 0xc80);
4560 eid |= inb(iobase + 0xc81) << 8;
4561 if (eid != STL_EISAID)
4565 * We have found a board. Need to check if this board was
4566 * statically configured already (just in case!).
4568 for (i = 0; (i < STL_MAXBRDS); i++) {
4569 brdp = stli_brds[i];
4570 if (brdp == (stlibrd_t *) NULL)
4572 if (brdp->iobase == iobase)
4575 if (i < STL_MAXBRDS)
4579 * We have found a Stallion board and it is not configured already.
4580 * Allocate a board structure and initialize it.
4582 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4584 if ((brdp->brdnr = stli_getbrdnr()) < 0)
4586 eid = inb(iobase + 0xc82);
4587 if (eid == ECP_EISAID)
4588 brdp->brdtype = BRD_ECPE;
4589 else if (eid == ONB_EISAID)
4590 brdp->brdtype = BRD_ONBOARDE;
4592 brdp->brdtype = BRD_UNKNOWN;
4593 brdp->iobase = iobase;
4594 outb(0x1, (iobase + 0xc84));
4595 if (stli_eisamemprobe(brdp))
4596 outb(0, (iobase + 0xc84));
4603 /*****************************************************************************/
4606 * Find the next available board number that is free.
4609 /*****************************************************************************/
4614 * We have a Stallion board. Allocate a board structure and
4615 * initialize it. Read its IO and MEMORY resources from PCI
4616 * configuration space.
4619 static inline int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4624 printk(KERN_DEBUG "stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
4625 brdtype, dev->bus->number, dev->devfn);
4628 if (pci_enable_device(devp))
4630 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4632 if ((brdp->brdnr = stli_getbrdnr()) < 0) {
4633 printk(KERN_INFO "STALLION: too many boards found, "
4634 "maximum supported %d\n", STL_MAXBRDS);
4637 brdp->brdtype = brdtype;
4640 printk(KERN_DEBUG "%s(%d): BAR[]=%lx,%lx,%lx,%lx\n", __FILE__, __LINE__,
4641 pci_resource_start(devp, 0),
4642 pci_resource_start(devp, 1),
4643 pci_resource_start(devp, 2),
4644 pci_resource_start(devp, 3));
4648 * We have all resources from the board, so lets setup the actual
4649 * board structure now.
4651 brdp->iobase = pci_resource_start(devp, 3);
4652 brdp->memaddr = pci_resource_start(devp, 2);
4658 /*****************************************************************************/
4661 * Find all Stallion PCI boards that might be installed. Initialize each
4662 * one as it is found.
4665 static inline int stli_findpcibrds(void)
4667 struct pci_dev *dev = NULL;
4671 printk("stli_findpcibrds()\n");
4674 while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION,
4675 PCI_DEVICE_ID_ECRA, dev))) {
4676 if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
4685 /*****************************************************************************/
4688 * Allocate a new board structure. Fill out the basic info in it.
4691 static stlibrd_t *stli_allocbrd(void)
4695 brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
4696 if (brdp == (stlibrd_t *) NULL) {
4697 printk(KERN_ERR "STALLION: failed to allocate memory "
4698 "(size=%d)\n", sizeof(stlibrd_t));
4699 return((stlibrd_t *) NULL);
4702 memset(brdp, 0, sizeof(stlibrd_t));
4703 brdp->magic = STLI_BOARDMAGIC;
4707 /*****************************************************************************/
4710 * Scan through all the boards in the configuration and see what we
4714 static inline int stli_initbrds(void)
4716 stlibrd_t *brdp, *nxtbrdp;
4721 printk(KERN_DEBUG "stli_initbrds()\n");
4724 if (stli_nrbrds > STL_MAXBRDS) {
4725 printk(KERN_INFO "STALLION: too many boards in configuration "
4726 "table, truncating to %d\n", STL_MAXBRDS);
4727 stli_nrbrds = STL_MAXBRDS;
4731 * Firstly scan the list of static boards configured. Allocate
4732 * resources and initialize the boards as found. If this is a
4733 * module then let the module args override static configuration.
4735 for (i = 0; (i < stli_nrbrds); i++) {
4736 confp = &stli_brdconf[i];
4738 stli_parsebrd(confp, stli_brdsp[i]);
4740 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
4743 brdp->brdtype = confp->brdtype;
4744 brdp->iobase = confp->ioaddr1;
4745 brdp->memaddr = confp->memaddr;
4750 * Static configuration table done, so now use dynamic methods to
4751 * see if any more boards should be configured.
4757 stli_findeisabrds();
4763 * All found boards are initialized. Now for a little optimization, if
4764 * no boards are sharing the "shared memory" regions then we can just
4765 * leave them all enabled. This is in fact the usual case.
4768 if (stli_nrbrds > 1) {
4769 for (i = 0; (i < stli_nrbrds); i++) {
4770 brdp = stli_brds[i];
4771 if (brdp == (stlibrd_t *) NULL)
4773 for (j = i + 1; (j < stli_nrbrds); j++) {
4774 nxtbrdp = stli_brds[j];
4775 if (nxtbrdp == (stlibrd_t *) NULL)
4777 if ((brdp->membase >= nxtbrdp->membase) &&
4778 (brdp->membase <= (nxtbrdp->membase +
4779 nxtbrdp->memsize - 1))) {
4787 if (stli_shared == 0) {
4788 for (i = 0; (i < stli_nrbrds); i++) {
4789 brdp = stli_brds[i];
4790 if (brdp == (stlibrd_t *) NULL)
4792 if (brdp->state & BST_FOUND) {
4794 brdp->enable = NULL;
4795 brdp->disable = NULL;
4803 /*****************************************************************************/
4806 * Code to handle an "staliomem" read operation. This device is the
4807 * contents of the board shared memory. It is used for down loading
4808 * the slave image (and debugging :-)
4811 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4813 unsigned long flags;
4819 printk(KERN_DEBUG "stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n",
4820 (int) fp, (int) buf, count, (int) offp);
4823 brdnr = iminor(fp->f_dentry->d_inode);
4824 if (brdnr >= stli_nrbrds)
4826 brdp = stli_brds[brdnr];
4827 if (brdp == (stlibrd_t *) NULL)
4829 if (brdp->state == 0)
4831 if (fp->f_pos >= brdp->memsize)
4834 size = MIN(count, (brdp->memsize - fp->f_pos));
4840 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
4841 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
4842 if (copy_to_user(buf, memptr, n)) {
4852 restore_flags(flags);
4857 /*****************************************************************************/
4860 * Code to handle an "staliomem" write operation. This device is the
4861 * contents of the board shared memory. It is used for down loading
4862 * the slave image (and debugging :-)
4865 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4867 unsigned long flags;
4874 printk(KERN_DEBUG "stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n",
4875 (int) fp, (int) buf, count, (int) offp);
4878 brdnr = iminor(fp->f_dentry->d_inode);
4879 if (brdnr >= stli_nrbrds)
4881 brdp = stli_brds[brdnr];
4882 if (brdp == (stlibrd_t *) NULL)
4884 if (brdp->state == 0)
4886 if (fp->f_pos >= brdp->memsize)
4889 chbuf = (char __user *) buf;
4890 size = MIN(count, (brdp->memsize - fp->f_pos));
4896 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
4897 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
4898 if (copy_from_user(memptr, chbuf, n)) {
4908 restore_flags(flags);
4913 /*****************************************************************************/
4916 * Return the board stats structure to user app.
4919 static int stli_getbrdstats(combrd_t __user *bp)
4924 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4926 if (stli_brdstats.brd >= STL_MAXBRDS)
4928 brdp = stli_brds[stli_brdstats.brd];
4929 if (brdp == (stlibrd_t *) NULL)
4932 memset(&stli_brdstats, 0, sizeof(combrd_t));
4933 stli_brdstats.brd = brdp->brdnr;
4934 stli_brdstats.type = brdp->brdtype;
4935 stli_brdstats.hwid = 0;
4936 stli_brdstats.state = brdp->state;
4937 stli_brdstats.ioaddr = brdp->iobase;
4938 stli_brdstats.memaddr = brdp->memaddr;
4939 stli_brdstats.nrpanels = brdp->nrpanels;
4940 stli_brdstats.nrports = brdp->nrports;
4941 for (i = 0; (i < brdp->nrpanels); i++) {
4942 stli_brdstats.panels[i].panel = i;
4943 stli_brdstats.panels[i].hwid = brdp->panelids[i];
4944 stli_brdstats.panels[i].nrports = brdp->panels[i];
4947 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4952 /*****************************************************************************/
4955 * Resolve the referenced port number into a port struct pointer.
4958 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4963 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
4964 return((stliport_t *) NULL);
4965 brdp = stli_brds[brdnr];
4966 if (brdp == (stlibrd_t *) NULL)
4967 return((stliport_t *) NULL);
4968 for (i = 0; (i < panelnr); i++)
4969 portnr += brdp->panels[i];
4970 if ((portnr < 0) || (portnr >= brdp->nrports))
4971 return((stliport_t *) NULL);
4972 return(brdp->ports[portnr]);
4975 /*****************************************************************************/
4978 * Return the port stats structure to user app. A NULL port struct
4979 * pointer passed in means that we need to find out from the app
4980 * what port to get stats for (used through board control device).
4983 static int stli_portcmdstats(stliport_t *portp)
4985 unsigned long flags;
4989 memset(&stli_comstats, 0, sizeof(comstats_t));
4991 if (portp == (stliport_t *) NULL)
4993 brdp = stli_brds[portp->brdnr];
4994 if (brdp == (stlibrd_t *) NULL)
4997 if (brdp->state & BST_STARTED) {
4998 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4999 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
5002 memset(&stli_cdkstats, 0, sizeof(asystats_t));
5005 stli_comstats.brd = portp->brdnr;
5006 stli_comstats.panel = portp->panelnr;
5007 stli_comstats.port = portp->portnr;
5008 stli_comstats.state = portp->state;
5009 stli_comstats.flags = portp->flags;
5013 if (portp->tty != (struct tty_struct *) NULL) {
5014 if (portp->tty->driver_data == portp) {
5015 stli_comstats.ttystate = portp->tty->flags;
5016 stli_comstats.rxbuffered = portp->tty->flip.count;
5017 if (portp->tty->termios != (struct termios *) NULL) {
5018 stli_comstats.cflags = portp->tty->termios->c_cflag;
5019 stli_comstats.iflags = portp->tty->termios->c_iflag;
5020 stli_comstats.oflags = portp->tty->termios->c_oflag;
5021 stli_comstats.lflags = portp->tty->termios->c_lflag;
5025 restore_flags(flags);
5027 stli_comstats.txtotal = stli_cdkstats.txchars;
5028 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
5029 stli_comstats.txbuffered = stli_cdkstats.txringq;
5030 stli_comstats.rxbuffered += stli_cdkstats.rxringq;
5031 stli_comstats.rxoverrun = stli_cdkstats.overruns;
5032 stli_comstats.rxparity = stli_cdkstats.parity;
5033 stli_comstats.rxframing = stli_cdkstats.framing;
5034 stli_comstats.rxlost = stli_cdkstats.ringover;
5035 stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
5036 stli_comstats.txbreaks = stli_cdkstats.txbreaks;
5037 stli_comstats.txxon = stli_cdkstats.txstart;
5038 stli_comstats.txxoff = stli_cdkstats.txstop;
5039 stli_comstats.rxxon = stli_cdkstats.rxstart;
5040 stli_comstats.rxxoff = stli_cdkstats.rxstop;
5041 stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
5042 stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
5043 stli_comstats.modem = stli_cdkstats.dcdcnt;
5044 stli_comstats.hwid = stli_cdkstats.hwid;
5045 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
5050 /*****************************************************************************/
5053 * Return the port stats structure to user app. A NULL port struct
5054 * pointer passed in means that we need to find out from the app
5055 * what port to get stats for (used through board control device).
5058 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
5064 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
5066 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
5067 stli_comstats.port);
5072 brdp = stli_brds[portp->brdnr];
5076 if ((rc = stli_portcmdstats(portp)) < 0)
5079 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
5083 /*****************************************************************************/
5086 * Clear the port stats structure. We also return it zeroed out...
5089 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
5095 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
5097 portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
5098 stli_comstats.port);
5103 brdp = stli_brds[portp->brdnr];
5107 if (brdp->state & BST_STARTED) {
5108 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
5112 memset(&stli_comstats, 0, sizeof(comstats_t));
5113 stli_comstats.brd = portp->brdnr;
5114 stli_comstats.panel = portp->panelnr;
5115 stli_comstats.port = portp->portnr;
5117 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
5122 /*****************************************************************************/
5125 * Return the entire driver ports structure to a user app.
5128 static int stli_getportstruct(stliport_t __user *arg)
5132 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
5134 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
5135 stli_dummyport.portnr);
5138 if (copy_to_user(arg, portp, sizeof(stliport_t)))
5143 /*****************************************************************************/
5146 * Return the entire driver board structure to a user app.
5149 static int stli_getbrdstruct(stlibrd_t __user *arg)
5153 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
5155 if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
5157 brdp = stli_brds[stli_dummybrd.brdnr];
5160 if (copy_to_user(arg, brdp, sizeof(stlibrd_t)))
5165 /*****************************************************************************/
5168 * The "staliomem" device is also required to do some special operations on
5169 * the board. We need to be able to send an interrupt to the board,
5170 * reset it, and start/stop it.
5173 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
5176 int brdnr, rc, done;
5177 void __user *argp = (void __user *)arg;
5180 printk(KERN_DEBUG "stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n",
5181 (int) ip, (int) fp, cmd, (int) arg);
5185 * First up handle the board independent ioctls.
5191 case COM_GETPORTSTATS:
5192 rc = stli_getportstats(NULL, argp);
5195 case COM_CLRPORTSTATS:
5196 rc = stli_clrportstats(NULL, argp);
5199 case COM_GETBRDSTATS:
5200 rc = stli_getbrdstats(argp);
5204 rc = stli_getportstruct(argp);
5208 rc = stli_getbrdstruct(argp);
5217 * Now handle the board specific ioctls. These all depend on the
5218 * minor number of the device they were called from.
5221 if (brdnr >= STL_MAXBRDS)
5223 brdp = stli_brds[brdnr];
5226 if (brdp->state == 0)
5234 rc = stli_startbrd(brdp);
5237 brdp->state &= ~BST_STARTED;
5240 brdp->state &= ~BST_STARTED;
5242 if (stli_shared == 0) {
5243 if (brdp->reenable != NULL)
5244 (* brdp->reenable)(brdp);
5255 static struct tty_operations stli_ops = {
5257 .close = stli_close,
5258 .write = stli_write,
5259 .put_char = stli_putchar,
5260 .flush_chars = stli_flushchars,
5261 .write_room = stli_writeroom,
5262 .chars_in_buffer = stli_charsinbuffer,
5263 .ioctl = stli_ioctl,
5264 .set_termios = stli_settermios,
5265 .throttle = stli_throttle,
5266 .unthrottle = stli_unthrottle,
5268 .start = stli_start,
5269 .hangup = stli_hangup,
5270 .flush_buffer = stli_flushbuffer,
5271 .break_ctl = stli_breakctl,
5272 .wait_until_sent = stli_waituntilsent,
5273 .send_xchar = stli_sendxchar,
5274 .read_proc = stli_readproc,
5275 .tiocmget = stli_tiocmget,
5276 .tiocmset = stli_tiocmset,
5279 /*****************************************************************************/
5281 int __init stli_init(void)
5284 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
5288 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
5293 * Allocate a temporary write buffer.
5295 stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
5296 if (stli_tmpwritebuf == (char *) NULL)
5297 printk(KERN_ERR "STALLION: failed to allocate memory "
5298 "(size=%d)\n", STLI_TXBUFSIZE);
5299 stli_txcookbuf = stli_memalloc(STLI_TXBUFSIZE);
5300 if (stli_txcookbuf == (char *) NULL)
5301 printk(KERN_ERR "STALLION: failed to allocate memory "
5302 "(size=%d)\n", STLI_TXBUFSIZE);
5305 * Set up a character driver for the shared memory region. We need this
5306 * to down load the slave code image. Also it is a useful debugging tool.
5308 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
5309 printk(KERN_ERR "STALLION: failed to register serial memory "
5312 devfs_mk_dir("staliomem");
5313 istallion_class = class_simple_create(THIS_MODULE, "staliomem");
5314 for (i = 0; i < 4; i++) {
5315 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
5316 S_IFCHR | S_IRUSR | S_IWUSR,
5318 class_simple_device_add(istallion_class, MKDEV(STL_SIOMEMMAJOR, i),
5319 NULL, "staliomem%d", i);
5323 * Set up the tty driver structure and register us as a driver.
5325 stli_serial->owner = THIS_MODULE;
5326 stli_serial->driver_name = stli_drvname;
5327 stli_serial->name = stli_serialname;
5328 stli_serial->major = STL_SERIALMAJOR;
5329 stli_serial->minor_start = 0;
5330 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
5331 stli_serial->subtype = SERIAL_TYPE_NORMAL;
5332 stli_serial->init_termios = stli_deftermios;
5333 stli_serial->flags = TTY_DRIVER_REAL_RAW;
5334 tty_set_operations(stli_serial, &stli_ops);
5336 if (tty_register_driver(stli_serial)) {
5337 put_tty_driver(stli_serial);
5338 printk(KERN_ERR "STALLION: failed to register serial driver\n");
5344 /*****************************************************************************/