OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [drivers/] [char/] [istallion.c] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*****************************************************************************/
2
 
3
/*
4
 *      istallion.c  -- stallion intelligent multiport serial driver.
5
 *
6
 *      Copyright (C) 1996-1998  Stallion Technologies (support@stallion.oz.au).
7
 *      Copyright (C) 1994-1996  Greg Ungerer (gerg@stallion.oz.au).
8
 *
9
 *      This code is loosely based on the Linux serial driver, written by
10
 *      Linus Torvalds, Theodore T'so and others.
11
 *
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.
16
 *
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.
21
 *
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.
25
 */
26
 
27
/*****************************************************************************/
28
 
29
#include <linux/module.h>
30
#include <linux/errno.h>
31
#include <linux/sched.h>
32
#include <linux/timer.h>
33
#include <linux/wait.h>
34
#include <linux/interrupt.h>
35
#include <linux/termios.h>
36
#include <linux/fcntl.h>
37
#include <linux/tty_driver.h>
38
#include <linux/tty.h>
39
#include <linux/tty_flip.h>
40
#include <linux/serial.h>
41
#include <linux/cdk.h>
42
#include <linux/comstats.h>
43
#include <linux/istallion.h>
44
#include <linux/string.h>
45
#include <linux/malloc.h>
46
#include <linux/ioport.h>
47
#include <linux/delay.h>
48
#include <asm/io.h>
49
 
50
/*****************************************************************************/
51
 
52
/*
53
 *      Define different board types. Not all of the following board types
54
 *      are supported by this driver. But I will use the standard "assigned"
55
 *      board numbers. Currently supported boards are abbreviated as:
56
 *      ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
57
 *      STAL = Stallion.
58
 */
59
#define BRD_UNKNOWN     0
60
#define BRD_STALLION    1
61
#define BRD_BRUMBY4     2
62
#define BRD_ONBOARD2    3
63
#define BRD_ONBOARD     4
64
#define BRD_BRUMBY8     5
65
#define BRD_BRUMBY16    6
66
#define BRD_ONBOARDE    7
67
#define BRD_ONBOARD32   9
68
#define BRD_ONBOARD2_32 10
69
#define BRD_ONBOARDRS   11
70
#define BRD_EASYIO      20
71
#define BRD_ECH         21
72
#define BRD_ECHMC       22
73
#define BRD_ECP         23
74
#define BRD_ECPE        24
75
#define BRD_ECPMC       25
76
#define BRD_ECHPCI      26
77
#define BRD_ECH64PCI    27
78
#define BRD_EASYIOPCI   28
79
 
80
#define BRD_BRUMBY      BRD_BRUMBY4
81
 
82
/*
83
 *      Define a configuration structure to hold the board configuration.
84
 *      Need to set this up in the code (for now) with the boards that are
85
 *      to be configured into the system. This is what needs to be modified
86
 *      when adding/removing/modifying boards. Each line entry in the
87
 *      stli_brdconf[] array is a board. Each line contains io/irq/memory
88
 *      ranges for that board (as well as what type of board it is).
89
 *      Some examples:
90
 *              { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
91
 *      This line will configure an EasyConnection 8/64 at io address 2a0,
92
 *      and shared memory address of cc000. Multiple EasyConnection 8/64
93
 *      boards can share the same shared memory address space. No interrupt
94
 *      is required for this board type.
95
 *      Another example:
96
 *              { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
97
 *      This line will configure an EasyConnection 8/64 EISA in slot 5 and
98
 *      shared memory address of 0x80000000 (2 GByte). Multiple
99
 *      EasyConnection 8/64 EISA boards can share the same shared memory
100
 *      address space. No interrupt is required for this board type.
101
 *      Another example:
102
 *              { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
103
 *      This line will configure an ONboard (ISA type) at io address 240,
104
 *      and shared memory address of d0000. Multiple ONboards can share
105
 *      the same shared memory address space. No interrupt required.
106
 *      Another example:
107
 *              { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
108
 *      This line will configure a Brumby board (any number of ports!) at
109
 *      io address 360 and shared memory address of c8000. All Brumby boards
110
 *      configured into a system must have their own separate io and memory
111
 *      addresses. No interrupt is required.
112
 *      Another example:
113
 *              { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
114
 *      This line will configure an original Stallion board at io address 330
115
 *      and shared memory address d0000 (this would only be valid for a "V4.0"
116
 *      or Rev.O Stallion board). All Stallion boards configured into the
117
 *      system must have their own separate io and memory addresses. No
118
 *      interrupt is required.
119
 */
120
 
121
typedef struct {
122
        int             brdtype;
123
        int             ioaddr1;
124
        int             ioaddr2;
125
        unsigned long   memaddr;
126
        int             irq;
127
        int             irqtype;
128
} stlconf_t;
129
 
130
static stlconf_t        stli_brdconf[] = {
131
        { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
132
};
133
 
134
static int      stli_nrbrds = sizeof(stli_brdconf) / sizeof(stlconf_t);
135
 
136
/*
137
 *      There is some experimental EISA board detection code in this driver.
138
 *      By default it is disabled, but for those that want to try it out,
139
 *      then set the define below to be 1.
140
 */
141
#define STLI_EISAPROBE  0
142
 
143
/*****************************************************************************/
144
 
145
/*
146
 *      Define some important driver characteristics. Device major numbers
147
 *      allocated as per Linux Device Registry.
148
 */
149
#ifndef STL_SIOMEMMAJOR
150
#define STL_SIOMEMMAJOR         28
151
#endif
152
#ifndef STL_SERIALMAJOR
153
#define STL_SERIALMAJOR         24
154
#endif
155
#ifndef STL_CALLOUTMAJOR
156
#define STL_CALLOUTMAJOR        25
157
#endif
158
 
159
#define STL_DRVTYPSERIAL        1
160
#define STL_DRVTYPCALLOUT       2
161
 
162
/*****************************************************************************/
163
 
164
/*
165
 *      Define our local driver identity first. Set up stuff to deal with
166
 *      all the local structures required by a serial tty driver.
167
 */
168
static char     *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
169
static char     *stli_drvversion = "5.4.4";
170
static char     *stli_serialname = "ttyE";
171
static char     *stli_calloutname = "cue";
172
 
173
static struct tty_driver        stli_serial;
174
static struct tty_driver        stli_callout;
175
static struct tty_struct        *stli_ttys[STL_MAXDEVS];
176
static struct termios           *stli_termios[STL_MAXDEVS];
177
static struct termios           *stli_termioslocked[STL_MAXDEVS];
178
static int                      stli_refcount;
179
 
180
/*
181
 *      We will need to allocate a temporary write buffer for chars that
182
 *      come direct from user space. The problem is that a copy from user
183
 *      space might cause a page fault (typically on a system that is
184
 *      swapping!). All ports will share one buffer - since if the system
185
 *      is already swapping a shared buffer won't make things any worse.
186
 */
187
static char                     *stli_tmpwritebuf = (char *) NULL;
188
static struct semaphore         stli_tmpwritesem = MUTEX;
189
 
190
#define STLI_TXBUFSIZE          4096
191
 
192
/*
193
 *      Use a fast local buffer for cooked characters. Typically a whole
194
 *      bunch of cooked characters come in for a port, 1 at a time. So we
195
 *      save those up into a local buffer, then write out the whole lot
196
 *      with a large memcpy. Just use 1 buffer for all ports, since its
197
 *      use it is only need for short periods of time by each port.
198
 */
199
static char                     *stli_txcookbuf = (char *) NULL;
200
static int                      stli_txcooksize = 0;
201
static int                      stli_txcookrealsize = 0;
202
static struct tty_struct        *stli_txcooktty = (struct tty_struct *) NULL;
203
 
204
/*
205
 *      Define a local default termios struct. All ports will be created
206
 *      with this termios initially. Basically all it defines is a raw port
207
 *      at 9600 baud, 8 data bits, no parity, 1 stop bit.
208
 */
209
static struct termios           stli_deftermios = {
210
        0,
211
        0,
212
        (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
213
        0,
214
        0,
215
        INIT_C_CC
216
};
217
 
218
/*
219
 *      Define global stats structures. Not used often, and can be
220
 *      re-used for each stats call.
221
 */
222
static comstats_t       stli_comstats;
223
static combrd_t         stli_brdstats;
224
static asystats_t       stli_cdkstats;
225
static stlibrd_t        stli_dummybrd;
226
static stliport_t       stli_dummyport;
227
 
228
/*****************************************************************************/
229
 
230
static stlibrd_t        *stli_brds[STL_MAXBRDS];
231
 
232
static int              stli_shared = 0;
233
 
234
/*
235
 *      Per board state flags. Used with the state field of the board struct.
236
 *      Not really much here... All we need to do is keep track of whether
237
 *      the board has been detected, and whether it is actually running a slave
238
 *      or not.
239
 */
240
#define BST_FOUND       0x1
241
#define BST_STARTED     0x2
242
 
243
/*
244
 *      Define the set of port state flags. These are marked for internal
245
 *      state purposes only, usually to do with the state of communications
246
 *      with the slave. Most of them need to be updated atomically, so always
247
 *      use the bit setting operations (unless protected by cli/sti).
248
 */
249
#define ST_INITIALIZING 1
250
#define ST_OPENING      2
251
#define ST_CLOSING      3
252
#define ST_CMDING       4
253
#define ST_TXBUSY       5
254
#define ST_RXING        6
255
#define ST_DOFLUSHRX    7
256
#define ST_DOFLUSHTX    8
257
#define ST_DOSIGS       9
258
#define ST_RXSTOP       10
259
#define ST_GETSIGS      11
260
 
261
/*
262
 *      Define an array of board names as printable strings. Handy for
263
 *      referencing boards when printing trace and stuff.
264
 */
265
static char     *stli_brdnames[] = {
266
        "Unknown",
267
        "Stallion",
268
        "Brumby",
269
        "ONboard-MC",
270
        "ONboard",
271
        "Brumby",
272
        "Brumby",
273
        "ONboard-EI",
274
        (char *) NULL,
275
        "ONboard",
276
        "ONboard-MC",
277
        "ONboard-MC",
278
        (char *) NULL,
279
        (char *) NULL,
280
        (char *) NULL,
281
        (char *) NULL,
282
        (char *) NULL,
283
        (char *) NULL,
284
        (char *) NULL,
285
        (char *) NULL,
286
        "EasyIO",
287
        "EC8/32-AT",
288
        "EC8/32-MC",
289
        "EC8/64-AT",
290
        "EC8/64-EI",
291
        "EC8/64-MC",
292
        "EC8/32-PCI",
293
        "EC8/64-PCI",
294
        "EasyIO-PCI",
295
};
296
 
297
/*
298
 *      Set up a default memory address table for EISA board probing.
299
 *      The default addresses are all bellow 1Mbyte, which has to be the
300
 *      case anyway. They should be safe, since we only read values from
301
 *      them, and interrupts are disabled while we do it. If the higher
302
 *      memory support is compiled in then we also try probing around
303
 *      the 1Gb, 2Gb and 3Gb areas as well...
304
 */
305
static unsigned long    stli_eisamemprobeaddrs[] = {
306
        0xc0000,    0xd0000,    0xe0000,    0xf0000,
307
        0x80000000, 0x80010000, 0x80020000, 0x80030000,
308
        0x40000000, 0x40010000, 0x40020000, 0x40030000,
309
        0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
310
        0xff000000, 0xff010000, 0xff020000, 0xff030000,
311
};
312
 
313
static int      stli_eisamempsize = sizeof(stli_eisamemprobeaddrs) / sizeof(unsigned long);
314
int             stli_eisaprobe = STLI_EISAPROBE;
315
 
316
/*****************************************************************************/
317
 
318
/*
319
 *      Hardware configuration info for ECP boards. These defines apply
320
 *      to the directly accessible io ports of the ECP. There is a set of
321
 *      defines for each ECP board type, ISA, EISA and MCA.
322
 */
323
#define ECP_IOSIZE      4
324
#define ECP_MEMSIZE     (128 * 1024)
325
#define ECP_ATPAGESIZE  (4 * 1024)
326
#define ECP_EIPAGESIZE  (64 * 1024)
327
#define ECP_MCPAGESIZE  (4 * 1024)
328
 
329
#define STL_EISAID      0x8c4e
330
 
331
/*
332
 *      Important defines for the ISA class of ECP board.
333
 */
334
#define ECP_ATIREG      0
335
#define ECP_ATCONFR     1
336
#define ECP_ATMEMAR     2
337
#define ECP_ATMEMPR     3
338
#define ECP_ATSTOP      0x1
339
#define ECP_ATINTENAB   0x10
340
#define ECP_ATENABLE    0x20
341
#define ECP_ATDISABLE   0x00
342
#define ECP_ATADDRMASK  0x3f000
343
#define ECP_ATADDRSHFT  12
344
 
345
/*
346
 *      Important defines for the EISA class of ECP board.
347
 */
348
#define ECP_EIIREG      0
349
#define ECP_EIMEMARL    1
350
#define ECP_EICONFR     2
351
#define ECP_EIMEMARH    3
352
#define ECP_EIENABLE    0x1
353
#define ECP_EIDISABLE   0x0
354
#define ECP_EISTOP      0x4
355
#define ECP_EIEDGE      0x00
356
#define ECP_EILEVEL     0x80
357
#define ECP_EIADDRMASKL 0x00ff0000
358
#define ECP_EIADDRSHFTL 16
359
#define ECP_EIADDRMASKH 0xff000000
360
#define ECP_EIADDRSHFTH 24
361
#define ECP_EIBRDENAB   0xc84
362
 
363
#define ECP_EISAID      0x4
364
 
365
/*
366
 *      Important defines for the Micro-channel class of ECP board.
367
 *      (It has a lot in common with the ISA boards.)
368
 */
369
#define ECP_MCIREG      0
370
#define ECP_MCCONFR     1
371
#define ECP_MCSTOP      0x20
372
#define ECP_MCENABLE    0x80
373
#define ECP_MCDISABLE   0x00
374
 
375
/*
376
 *      Hardware configuration info for ONboard and Brumby boards. These
377
 *      defines apply to the directly accessible io ports of these boards.
378
 */
379
#define ONB_IOSIZE      16
380
#define ONB_MEMSIZE     (64 * 1024)
381
#define ONB_ATPAGESIZE  (64 * 1024)
382
#define ONB_MCPAGESIZE  (64 * 1024)
383
#define ONB_EIMEMSIZE   (128 * 1024)
384
#define ONB_EIPAGESIZE  (64 * 1024)
385
 
386
/*
387
 *      Important defines for the ISA class of ONboard board.
388
 */
389
#define ONB_ATIREG      0
390
#define ONB_ATMEMAR     1
391
#define ONB_ATCONFR     2
392
#define ONB_ATSTOP      0x4
393
#define ONB_ATENABLE    0x01
394
#define ONB_ATDISABLE   0x00
395
#define ONB_ATADDRMASK  0xff0000
396
#define ONB_ATADDRSHFT  16
397
 
398
#define ONB_MEMENABLO   0
399
#define ONB_MEMENABHI   0x02
400
 
401
/*
402
 *      Important defines for the EISA class of ONboard board.
403
 */
404
#define ONB_EIIREG      0
405
#define ONB_EIMEMARL    1
406
#define ONB_EICONFR     2
407
#define ONB_EIMEMARH    3
408
#define ONB_EIENABLE    0x1
409
#define ONB_EIDISABLE   0x0
410
#define ONB_EISTOP      0x4
411
#define ONB_EIEDGE      0x00
412
#define ONB_EILEVEL     0x80
413
#define ONB_EIADDRMASKL 0x00ff0000
414
#define ONB_EIADDRSHFTL 16
415
#define ONB_EIADDRMASKH 0xff000000
416
#define ONB_EIADDRSHFTH 24
417
#define ONB_EIBRDENAB   0xc84
418
 
419
#define ONB_EISAID      0x1
420
 
421
/*
422
 *      Important defines for the Brumby boards. They are pretty simple,
423
 *      there is not much that is programmably configurable.
424
 */
425
#define BBY_IOSIZE      16
426
#define BBY_MEMSIZE     (64 * 1024)
427
#define BBY_PAGESIZE    (16 * 1024)
428
 
429
#define BBY_ATIREG      0
430
#define BBY_ATCONFR     1
431
#define BBY_ATSTOP      0x4
432
 
433
/*
434
 *      Important defines for the Stallion boards. They are pretty simple,
435
 *      there is not much that is programmably configurable.
436
 */
437
#define STAL_IOSIZE     16
438
#define STAL_MEMSIZE    (64 * 1024)
439
#define STAL_PAGESIZE   (64 * 1024)
440
 
441
/*
442
 *      Define the set of status register values for EasyConnection panels.
443
 *      The signature will return with the status value for each panel. From
444
 *      this we can determine what is attached to the board - before we have
445
 *      actually down loaded any code to it.
446
 */
447
#define ECH_PNLSTATUS   2
448
#define ECH_PNL16PORT   0x20
449
#define ECH_PNLIDMASK   0x07
450
#define ECH_PNLXPID     0x40
451
#define ECH_PNLINTRPEND 0x80
452
 
453
/*
454
 *      Define some macros to do things to the board. Even those these boards
455
 *      are somewhat related there is often significantly different ways of
456
 *      doing some operation on it (like enable, paging, reset, etc). So each
457
 *      board class has a set of functions which do the commonly required
458
 *      operations. The macros below basically just call these functions,
459
 *      generally checking for a NULL function - which means that the board
460
 *      needs nothing done to it to achieve this operation!
461
 */
462
#define EBRDINIT(brdp)                                          \
463
        if (brdp->init != NULL)                                 \
464
                (* brdp->init)(brdp)
465
 
466
#define EBRDENABLE(brdp)                                        \
467
        if (brdp->enable != NULL)                               \
468
                (* brdp->enable)(brdp);
469
 
470
#define EBRDDISABLE(brdp)                                       \
471
        if (brdp->disable != NULL)                              \
472
                (* brdp->disable)(brdp);
473
 
474
#define EBRDINTR(brdp)                                          \
475
        if (brdp->intr != NULL)                                 \
476
                (* brdp->intr)(brdp);
477
 
478
#define EBRDRESET(brdp)                                         \
479
        if (brdp->reset != NULL)                                \
480
                (* brdp->reset)(brdp);
481
 
482
#define EBRDGETMEMPTR(brdp,offset)                              \
483
        (* brdp->getmemptr)(brdp, offset, __LINE__)
484
 
485
/*
486
 *      Define the maximal baud rate, and the default baud base for ports.
487
 */
488
#define STL_MAXBAUD     460800
489
#define STL_BAUDBASE    115200
490
#define STL_CLOSEDELAY  (5 * HZ / 10)
491
 
492
/*****************************************************************************/
493
 
494
/*
495
 *      Define macros to extract a brd or port number from a minor number.
496
 */
497
#define MKDEV2BRD(min)          (((min) & 0xc0) >> 6)
498
#define MKDEV2PORT(min)         ((min) & 0x3f)
499
 
500
/*
501
 *      Define a baud rate table that converts termios baud rate selector
502
 *      into the actual baud rate value. All baud rate calculations are based
503
 *      on the actual baud rate required.
504
 */
505
static unsigned int     stli_baudrates[] = {
506
        0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
507
        9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
508
};
509
 
510
/*****************************************************************************/
511
 
512
/*
513
 *      Define some handy local macros...
514
 */
515
#define MIN(a,b)                (((a) <= (b)) ? (a) : (b))
516
 
517
/*****************************************************************************/
518
 
519
/*
520
 *      Prototype all functions in this driver!
521
 */
522
 
523
#ifdef MODULE
524
int             init_module(void);
525
void            cleanup_module(void);
526
#endif
527
 
528
int             stli_init(void);
529
static int      stli_open(struct tty_struct *tty, struct file *filp);
530
static void     stli_close(struct tty_struct *tty, struct file *filp);
531
static int      stli_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
532
static void     stli_putchar(struct tty_struct *tty, unsigned char ch);
533
static void     stli_flushchars(struct tty_struct *tty);
534
static int      stli_writeroom(struct tty_struct *tty);
535
static int      stli_charsinbuffer(struct tty_struct *tty);
536
static int      stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
537
static void     stli_settermios(struct tty_struct *tty, struct termios *old);
538
static void     stli_throttle(struct tty_struct *tty);
539
static void     stli_unthrottle(struct tty_struct *tty);
540
static void     stli_stop(struct tty_struct *tty);
541
static void     stli_start(struct tty_struct *tty);
542
static void     stli_flushbuffer(struct tty_struct *tty);
543
static void     stli_hangup(struct tty_struct *tty);
544
 
545
static int      stli_brdinit(stlibrd_t *brdp);
546
static int      stli_startbrd(stlibrd_t *brdp);
547
static int      stli_memopen(struct inode *ip, struct file *fp);
548
static void     stli_memclose(struct inode *ip, struct file *fp);
549
static int      stli_memread(struct inode *ip, struct file *fp, char *buf, int count);
550
static int      stli_memwrite(struct inode *ip, struct file *fp, const char *buf, int count);
551
static int      stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
552
static void     stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp);
553
static void     stli_poll(unsigned long arg);
554
static int      stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
555
static int      stli_initopen(stlibrd_t *brdp, stliport_t *portp);
556
static int      stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
557
static int      stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
558
static int      stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
559
static void     stli_dohangup(void *arg);
560
static void     stli_delay(int len);
561
static int      stli_setport(stliport_t *portp);
562
static int      stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
563
static void     stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
564
static void     stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp);
565
static void     stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
566
static void     stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
567
static long     stli_mktiocm(unsigned long sigvalue);
568
static void     stli_read(stlibrd_t *brdp, stliport_t *portp);
569
static void     stli_getserial(stliport_t *portp, struct serial_struct *sp);
570
static int      stli_setserial(stliport_t *portp, struct serial_struct *sp);
571
static int      stli_getbrdstats(combrd_t *bp);
572
static int      stli_getportstats(stliport_t *portp, comstats_t *cp);
573
static int      stli_portcmdstats(stliport_t *portp);
574
static int      stli_clrportstats(stliport_t *portp, comstats_t *cp);
575
static int      stli_getportstruct(unsigned long arg);
576
static int      stli_getbrdstruct(unsigned long arg);
577
static void     *stli_memalloc(int len);
578
 
579
static void     stli_ecpinit(stlibrd_t *brdp);
580
static void     stli_ecpenable(stlibrd_t *brdp);
581
static void     stli_ecpdisable(stlibrd_t *brdp);
582
static char     *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
583
static void     stli_ecpreset(stlibrd_t *brdp);
584
static void     stli_ecpintr(stlibrd_t *brdp);
585
static void     stli_ecpeiinit(stlibrd_t *brdp);
586
static void     stli_ecpeienable(stlibrd_t *brdp);
587
static void     stli_ecpeidisable(stlibrd_t *brdp);
588
static char     *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
589
static void     stli_ecpeireset(stlibrd_t *brdp);
590
static void     stli_ecpmcenable(stlibrd_t *brdp);
591
static void     stli_ecpmcdisable(stlibrd_t *brdp);
592
static char     *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
593
static void     stli_ecpmcreset(stlibrd_t *brdp);
594
 
595
static void     stli_onbinit(stlibrd_t *brdp);
596
static void     stli_onbenable(stlibrd_t *brdp);
597
static void     stli_onbdisable(stlibrd_t *brdp);
598
static char     *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
599
static void     stli_onbreset(stlibrd_t *brdp);
600
static void     stli_onbeinit(stlibrd_t *brdp);
601
static void     stli_onbeenable(stlibrd_t *brdp);
602
static void     stli_onbedisable(stlibrd_t *brdp);
603
static char     *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
604
static void     stli_onbereset(stlibrd_t *brdp);
605
static void     stli_bbyinit(stlibrd_t *brdp);
606
static char     *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
607
static void     stli_bbyreset(stlibrd_t *brdp);
608
static void     stli_stalinit(stlibrd_t *brdp);
609
static char     *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
610
static void     stli_stalreset(stlibrd_t *brdp);
611
 
612
static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
613
 
614
static inline int       stli_initbrds(void);
615
static inline int       stli_initecp(stlibrd_t *brdp);
616
static inline int       stli_initonb(stlibrd_t *brdp);
617
static inline int       stli_findeisabrds(void);
618
static inline int       stli_eisamemprobe(stlibrd_t *brdp);
619
static inline int       stli_initports(stlibrd_t *brdp);
620
 
621
/*****************************************************************************/
622
 
623
/*
624
 *      Define the driver info for a user level shared memory device. This
625
 *      device will work sort of like the /dev/kmem device - except that it
626
 *      will give access to the shared memory on the Stallion intelligent
627
 *      board. This is also a very useful debugging tool.
628
 */
629
static struct file_operations   stli_fsiomem = {
630
        NULL,
631
        stli_memread,
632
        stli_memwrite,
633
        NULL,
634
        NULL,
635
        stli_memioctl,
636
        NULL,
637
        stli_memopen,
638
        stli_memclose,
639
        NULL
640
};
641
 
642
/*****************************************************************************/
643
 
644
/*
645
 *      Define a timer_list entry for our poll routine. The slave board
646
 *      is polled every so often to see if anything needs doing. This is
647
 *      much cheaper on host cpu than using interrupts. It turns out to
648
 *      not increase character latency by much either...
649
 */
650
static struct timer_list        stli_timerlist = {
651
        NULL, NULL, 0, 0, stli_poll
652
};
653
 
654
static int      stli_timeron = 0;
655
 
656
/*
657
 *      Define the calculation for the timeout routine.
658
 */
659
#define STLI_TIMEOUT    (jiffies + 1)
660
 
661
/*****************************************************************************/
662
 
663
#ifdef MODULE
664
 
665
/*
666
 *      Loadable module initialization stuff.
667
 */
668
 
669
int init_module()
670
{
671
        unsigned long   flags;
672
 
673
#if DEBUG
674
        printk("init_module()\n");
675
#endif
676
 
677
        save_flags(flags);
678
        cli();
679
        stli_init();
680
        restore_flags(flags);
681
 
682
        return(0);
683
}
684
 
685
/*****************************************************************************/
686
 
687
void cleanup_module()
688
{
689
        stlibrd_t       *brdp;
690
        stliport_t      *portp;
691
        unsigned long   flags;
692
        int             i, j;
693
 
694
#if DEBUG
695
        printk("cleanup_module()\n");
696
#endif
697
 
698
        printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
699
                stli_drvversion);
700
 
701
        save_flags(flags);
702
        cli();
703
 
704
/*
705
 *      Free up all allocated resources used by the ports. This includes
706
 *      memory and interrupts.
707
 */
708
        if (stli_timeron) {
709
                stli_timeron = 0;
710
                del_timer(&stli_timerlist);
711
        }
712
 
713
        i = tty_unregister_driver(&stli_serial);
714
        j = tty_unregister_driver(&stli_callout);
715
        if (i || j) {
716
                printk("STALLION: failed to un-register tty driver, "
717
                        "errno=%d,%d\n", -i, -j);
718
                restore_flags(flags);
719
                return;
720
        }
721
        if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
722
                printk("STALLION: failed to un-register serial memory device, "
723
                        "errno=%d\n", -i);
724
 
725
        if (stli_tmpwritebuf != (char *) NULL)
726
                kfree_s(stli_tmpwritebuf, STLI_TXBUFSIZE);
727
        if (stli_txcookbuf != (char *) NULL)
728
                kfree_s(stli_txcookbuf, STLI_TXBUFSIZE);
729
 
730
        for (i = 0; (i < stli_nrbrds); i++) {
731
                brdp = stli_brds[i];
732
                if (brdp == (stlibrd_t *) NULL)
733
                        continue;
734
                for (j = 0; (j < STL_MAXPORTS); j++) {
735
                        portp = brdp->ports[j];
736
                        if (portp != (stliport_t *) NULL) {
737
                                if (portp->tty != (struct tty_struct *) NULL)
738
                                        tty_hangup(portp->tty);
739
                                kfree_s(portp, sizeof(stliport_t));
740
                        }
741
                }
742
 
743
                if (brdp->memaddr >= 0x100000)
744
                        vfree(brdp->membase);
745
                if (brdp->iosize > 0)
746
                        release_region(brdp->iobase, brdp->iosize);
747
                kfree_s(brdp, sizeof(stlibrd_t));
748
                stli_brds[i] = (stlibrd_t *) NULL;
749
        }
750
 
751
        restore_flags(flags);
752
}
753
 
754
#endif
755
 
756
/*****************************************************************************/
757
 
758
/*
759
 *      Local driver kernel malloc routine.
760
 */
761
 
762
static void *stli_memalloc(int len)
763
{
764
        return((void *) kmalloc(len, GFP_KERNEL));
765
}
766
 
767
/*****************************************************************************/
768
 
769
static int stli_open(struct tty_struct *tty, struct file *filp)
770
{
771
        stlibrd_t       *brdp;
772
        stliport_t      *portp;
773
        unsigned int    minordev;
774
        int             brdnr, portnr, rc;
775
 
776
#if DEBUG
777
        printk("stli_open(tty=%x,filp=%x): device=%x\n", (int) tty,
778
                (int) filp, tty->device);
779
#endif
780
 
781
        minordev = MINOR(tty->device);
782
        brdnr = MKDEV2BRD(minordev);
783
        if (brdnr >= stli_nrbrds)
784
                return(-ENODEV);
785
        brdp = stli_brds[brdnr];
786
        if (brdp == (stlibrd_t *) NULL)
787
                return(-ENODEV);
788
        if ((brdp->state & BST_STARTED) == 0)
789
                return(-ENODEV);
790
        portnr = MKDEV2PORT(minordev);
791
        if ((portnr < 0) || (portnr > brdp->nrports))
792
                return(-ENODEV);
793
 
794
        portp = brdp->ports[portnr];
795
        if (portp == (stliport_t *) NULL)
796
                return(-ENODEV);
797
        if (portp->devnr < 1)
798
                return(-ENODEV);
799
 
800
        MOD_INC_USE_COUNT;
801
 
802
/*
803
 *      Check if this port is in the middle of closing. If so then wait
804
 *      until it is closed then return error status based on flag settings.
805
 *      The sleep here does not need interrupt protection since the wakeup
806
 *      for it is done with the same context.
807
 */
808
        if (portp->flags & ASYNC_CLOSING) {
809
                interruptible_sleep_on(&portp->close_wait);
810
                if (portp->flags & ASYNC_HUP_NOTIFY)
811
                        return(-EAGAIN);
812
                return(-ERESTARTSYS);
813
        }
814
 
815
/*
816
 *      On the first open of the device setup the port hardware, and
817
 *      initialize the per port data structure. Since initializing the port
818
 *      requires several commands to the board we will need to wait for any
819
 *      other open that is already initializing the port.
820
 */
821
        portp->tty = tty;
822
        tty->driver_data = portp;
823
        portp->refcount++;
824
 
825
        while (test_bit(ST_INITIALIZING, &portp->state)) {
826
                if (current->signal & ~current->blocked)
827
                        return(-ERESTARTSYS);
828
                interruptible_sleep_on(&portp->raw_wait);
829
        }
830
 
831
        if ((portp->flags & ASYNC_INITIALIZED) == 0) {
832
                set_bit(ST_INITIALIZING, &portp->state);
833
                if ((rc = stli_initopen(brdp, portp)) >= 0) {
834
                        portp->flags |= ASYNC_INITIALIZED;
835
                        clear_bit(TTY_IO_ERROR, &tty->flags);
836
                }
837
                clear_bit(ST_INITIALIZING, &portp->state);
838
                wake_up_interruptible(&portp->raw_wait);
839
                if (rc < 0)
840
                        return(rc);
841
        }
842
 
843
/*
844
 *      Check if this port is in the middle of closing. If so then wait
845
 *      until it is closed then return error status, based on flag settings.
846
 *      The sleep here does not need interrupt protection since the wakeup
847
 *      for it is done with the same context.
848
 */
849
        if (portp->flags & ASYNC_CLOSING) {
850
                interruptible_sleep_on(&portp->close_wait);
851
                if (portp->flags & ASYNC_HUP_NOTIFY)
852
                        return(-EAGAIN);
853
                return(-ERESTARTSYS);
854
        }
855
 
856
/*
857
 *      Based on type of open being done check if it can overlap with any
858
 *      previous opens still in effect. If we are a normal serial device
859
 *      then also we might have to wait for carrier.
860
 */
861
        if (tty->driver.subtype == STL_DRVTYPCALLOUT) {
862
                if (portp->flags & ASYNC_NORMAL_ACTIVE)
863
                        return(-EBUSY);
864
                if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
865
                        if ((portp->flags & ASYNC_SESSION_LOCKOUT) &&
866
                            (portp->session != current->session))
867
                                return(-EBUSY);
868
                        if ((portp->flags & ASYNC_PGRP_LOCKOUT) &&
869
                            (portp->pgrp != current->pgrp))
870
                                return(-EBUSY);
871
                }
872
                portp->flags |= ASYNC_CALLOUT_ACTIVE;
873
        } else {
874
                if (filp->f_flags & O_NONBLOCK) {
875
                        if (portp->flags & ASYNC_CALLOUT_ACTIVE)
876
                                return(-EBUSY);
877
                } else {
878
                        if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
879
                                return(rc);
880
                }
881
                portp->flags |= ASYNC_NORMAL_ACTIVE;
882
        }
883
 
884
        if ((portp->refcount == 1) && (portp->flags & ASYNC_SPLIT_TERMIOS)) {
885
                if (tty->driver.subtype == STL_DRVTYPSERIAL)
886
                        *tty->termios = portp->normaltermios;
887
                else
888
                        *tty->termios = portp->callouttermios;
889
                stli_setport(portp);
890
        }
891
 
892
        portp->session = current->session;
893
        portp->pgrp = current->pgrp;
894
        return(0);
895
}
896
 
897
/*****************************************************************************/
898
 
899
static void stli_close(struct tty_struct *tty, struct file *filp)
900
{
901
        stlibrd_t       *brdp;
902
        stliport_t      *portp;
903
        unsigned long   flags;
904
 
905
#if DEBUG
906
        printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
907
#endif
908
 
909
        portp = tty->driver_data;
910
        if (portp == (stliport_t *) NULL)
911
                return;
912
 
913
        save_flags(flags);
914
        cli();
915
        if (tty_hung_up_p(filp)) {
916
                MOD_DEC_USE_COUNT;
917
                restore_flags(flags);
918
                return;
919
        }
920
        if ((tty->count == 1) && (portp->refcount != 1))
921
                portp->refcount = 1;
922
        if (portp->refcount-- > 1) {
923
                MOD_DEC_USE_COUNT;
924
                restore_flags(flags);
925
                return;
926
        }
927
 
928
        portp->flags |= ASYNC_CLOSING;
929
 
930
        if (portp->flags & ASYNC_NORMAL_ACTIVE)
931
                portp->normaltermios = *tty->termios;
932
        if (portp->flags & ASYNC_CALLOUT_ACTIVE)
933
                portp->callouttermios = *tty->termios;
934
 
935
/*
936
 *      May want to wait for data to drain before closing. The BUSY flag
937
 *      keeps track of whether we are still transmitting or not. It is
938
 *      updated by messages from the slave - indicating when all chars
939
 *      really have drained.
940
 */
941
        if (tty == stli_txcooktty)
942
                stli_flushchars(tty);
943
        tty->closing = 1;
944
        if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
945
                tty_wait_until_sent(tty, portp->closing_wait);
946
 
947
        portp->flags &= ~ASYNC_INITIALIZED;
948
        brdp = stli_brds[portp->brdnr];
949
        stli_rawclose(brdp, portp, 0, 0);
950
        if (tty->termios->c_cflag & HUPCL) {
951
                stli_mkasysigs(&portp->asig, 0, 0);
952
                if (test_bit(ST_CMDING, &portp->state))
953
                        set_bit(ST_DOSIGS, &portp->state);
954
                else
955
                        stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
956
                                sizeof(asysigs_t), 0);
957
        }
958
        clear_bit(ST_TXBUSY, &portp->state);
959
        clear_bit(ST_RXSTOP, &portp->state);
960
        set_bit(TTY_IO_ERROR, &tty->flags);
961
        if (tty->ldisc.flush_buffer)
962
                (tty->ldisc.flush_buffer)(tty);
963
        set_bit(ST_DOFLUSHRX, &portp->state);
964
        stli_flushbuffer(tty);
965
 
966
        tty->closing = 0;
967
        portp->tty = (struct tty_struct *) NULL;
968
 
969
        if (portp->openwaitcnt) {
970
                if (portp->close_delay)
971
                        stli_delay(portp->close_delay);
972
                wake_up_interruptible(&portp->open_wait);
973
        }
974
 
975
        portp->flags &= ~(ASYNC_CALLOUT_ACTIVE | ASYNC_NORMAL_ACTIVE |
976
                ASYNC_CLOSING);
977
        wake_up_interruptible(&portp->close_wait);
978
        MOD_DEC_USE_COUNT;
979
        restore_flags(flags);
980
}
981
 
982
/*****************************************************************************/
983
 
984
/*
985
 *      Carry out first open operations on a port. This involves a number of
986
 *      commands to be sent to the slave. We need to open the port, set the
987
 *      notification events, set the initial port settings, get and set the
988
 *      initial signal values. We sleep and wait in between each one. But
989
 *      this still all happens pretty quickly.
990
 */
991
 
992
static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
993
{
994
        struct tty_struct       *tty;
995
        asynotify_t             nt;
996
        asyport_t               aport;
997
        int                     rc;
998
 
999
#if DEBUG
1000
        printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
1001
#endif
1002
 
1003
        if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1004
                return(rc);
1005
 
1006
        memset(&nt, 0, sizeof(asynotify_t));
1007
        nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1008
        nt.signal = SG_DCD;
1009
        if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1010
            sizeof(asynotify_t), 0)) < 0)
1011
                return(rc);
1012
 
1013
        tty = portp->tty;
1014
        if (tty == (struct tty_struct *) NULL)
1015
                return(-ENODEV);
1016
        stli_mkasyport(portp, &aport, tty->termios);
1017
        if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1018
            sizeof(asyport_t), 0)) < 0)
1019
                return(rc);
1020
 
1021
        set_bit(ST_GETSIGS, &portp->state);
1022
        if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1023
            sizeof(asysigs_t), 1)) < 0)
1024
                return(rc);
1025
        if (clear_bit(ST_GETSIGS, &portp->state))
1026
                portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1027
        stli_mkasysigs(&portp->asig, 1, 1);
1028
        if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1029
            sizeof(asysigs_t), 0)) < 0)
1030
                return(rc);
1031
 
1032
        return(0);
1033
}
1034
 
1035
/*****************************************************************************/
1036
 
1037
/*
1038
 *      Send an open message to the slave. This will sleep waiting for the
1039
 *      acknowledgement, so must have user context. We need to co-ordinate
1040
 *      with close events here, since we don't want open and close events
1041
 *      to overlap.
1042
 */
1043
 
1044
static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1045
{
1046
        volatile cdkhdr_t       *hdrp;
1047
        volatile cdkctrl_t      *cp;
1048
        volatile unsigned char  *bits;
1049
        unsigned long           flags;
1050
        int                     rc;
1051
 
1052
#if DEBUG
1053
        printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1054
                (int) brdp, (int) portp, (int) arg, wait);
1055
#endif
1056
 
1057
/*
1058
 *      Send a message to the slave to open this port.
1059
 */
1060
        save_flags(flags);
1061
        cli();
1062
 
1063
/*
1064
 *      Slave is already closing this port. This can happen if a hangup
1065
 *      occurs on this port. So we must wait until it is complete. The
1066
 *      order of opens and closes may not be preserved across shared
1067
 *      memory, so we must wait until it is complete.
1068
 */
1069
        while (test_bit(ST_CLOSING, &portp->state)) {
1070
                if (current->signal & ~current->blocked) {
1071
                        restore_flags(flags);
1072
                        return(-ERESTARTSYS);
1073
                }
1074
                interruptible_sleep_on(&portp->raw_wait);
1075
        }
1076
 
1077
/*
1078
 *      Everything is ready now, so write the open message into shared
1079
 *      memory. Once the message is in set the service bits to say that
1080
 *      this port wants service.
1081
 */
1082
        EBRDENABLE(brdp);
1083
        cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1084
        cp->openarg = arg;
1085
        cp->open = 1;
1086
        hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1087
        bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1088
                portp->portidx;
1089
        *bits |= portp->portbit;
1090
        EBRDDISABLE(brdp);
1091
 
1092
        if (wait == 0) {
1093
                restore_flags(flags);
1094
                return(0);
1095
        }
1096
 
1097
/*
1098
 *      Slave is in action, so now we must wait for the open acknowledgment
1099
 *      to come back.
1100
 */
1101
        rc = 0;
1102
        set_bit(ST_OPENING, &portp->state);
1103
        while (test_bit(ST_OPENING, &portp->state)) {
1104
                if (current->signal & ~current->blocked) {
1105
                        rc = -ERESTARTSYS;
1106
                        break;
1107
                }
1108
                interruptible_sleep_on(&portp->raw_wait);
1109
        }
1110
        restore_flags(flags);
1111
 
1112
        if ((rc == 0) && (portp->rc != 0))
1113
                rc = -EIO;
1114
        return(rc);
1115
}
1116
 
1117
/*****************************************************************************/
1118
 
1119
/*
1120
 *      Send a close message to the slave. Normally this will sleep waiting
1121
 *      for the acknowledgement, but if wait parameter is 0 it will not. If
1122
 *      wait is true then must have user context (to sleep).
1123
 */
1124
 
1125
static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1126
{
1127
        volatile cdkhdr_t       *hdrp;
1128
        volatile cdkctrl_t      *cp;
1129
        volatile unsigned char  *bits;
1130
        unsigned long           flags;
1131
        int                     rc;
1132
 
1133
#if DEBUG
1134
        printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1135
                (int) brdp, (int) portp, (int) arg, wait);
1136
#endif
1137
 
1138
        save_flags(flags);
1139
        cli();
1140
 
1141
/*
1142
 *      Slave is already closing this port. This can happen if a hangup
1143
 *      occurs on this port.
1144
 */
1145
        if (wait) {
1146
                while (test_bit(ST_CLOSING, &portp->state)) {
1147
                        if (current->signal & ~current->blocked) {
1148
                                restore_flags(flags);
1149
                                return(-ERESTARTSYS);
1150
                        }
1151
                        interruptible_sleep_on(&portp->raw_wait);
1152
                }
1153
        }
1154
 
1155
/*
1156
 *      Write the close command into shared memory.
1157
 */
1158
        EBRDENABLE(brdp);
1159
        cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1160
        cp->closearg = arg;
1161
        cp->close = 1;
1162
        hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1163
        bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1164
                portp->portidx;
1165
        *bits |= portp->portbit;
1166
        EBRDDISABLE(brdp);
1167
 
1168
        set_bit(ST_CLOSING, &portp->state);
1169
        if (wait == 0) {
1170
                restore_flags(flags);
1171
                return(0);
1172
        }
1173
 
1174
/*
1175
 *      Slave is in action, so now we must wait for the open acknowledgment
1176
 *      to come back.
1177
 */
1178
        rc = 0;
1179
        while (test_bit(ST_CLOSING, &portp->state)) {
1180
                if (current->signal & ~current->blocked) {
1181
                        rc = -ERESTARTSYS;
1182
                        break;
1183
                }
1184
                interruptible_sleep_on(&portp->raw_wait);
1185
        }
1186
        restore_flags(flags);
1187
 
1188
        if ((rc == 0) && (portp->rc != 0))
1189
                rc = -EIO;
1190
        return(rc);
1191
}
1192
 
1193
/*****************************************************************************/
1194
 
1195
/*
1196
 *      Send a command to the slave and wait for the response. This must
1197
 *      have user context (it sleeps). This routine is generic in that it
1198
 *      can send any type of command. Its purpose is to wait for that command
1199
 *      to complete (as opposed to initiating the command then returning).
1200
 */
1201
 
1202
static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1203
{
1204
        unsigned long   flags;
1205
 
1206
#if DEBUG
1207
        printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
1208
                "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
1209
                (int) arg, size, copyback);
1210
#endif
1211
 
1212
        save_flags(flags);
1213
        cli();
1214
        while (test_bit(ST_CMDING, &portp->state)) {
1215
                if (current->signal & ~current->blocked) {
1216
                        restore_flags(flags);
1217
                        return(-ERESTARTSYS);
1218
                }
1219
                interruptible_sleep_on(&portp->raw_wait);
1220
        }
1221
 
1222
        stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1223
 
1224
        while (test_bit(ST_CMDING, &portp->state)) {
1225
                if (current->signal & ~current->blocked) {
1226
                        restore_flags(flags);
1227
                        return(-ERESTARTSYS);
1228
                }
1229
                interruptible_sleep_on(&portp->raw_wait);
1230
        }
1231
        restore_flags(flags);
1232
 
1233
        if (portp->rc != 0)
1234
                return(-EIO);
1235
        return(0);
1236
}
1237
 
1238
/*****************************************************************************/
1239
 
1240
/*
1241
 *      Send the termios settings for this port to the slave. This sleeps
1242
 *      waiting for the command to complete - so must have user context.
1243
 */
1244
 
1245
static int stli_setport(stliport_t *portp)
1246
{
1247
        stlibrd_t       *brdp;
1248
        asyport_t       aport;
1249
 
1250
#if DEBUG
1251
        printk("stli_setport(portp=%x)\n", (int) portp);
1252
#endif
1253
 
1254
        if (portp == (stliport_t *) NULL)
1255
                return(-ENODEV);
1256
        if (portp->tty == (struct tty_struct *) NULL)
1257
                return(-ENODEV);
1258
        if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds))
1259
                return(-ENODEV);
1260
        brdp = stli_brds[portp->brdnr];
1261
        if (brdp == (stlibrd_t *) NULL)
1262
                return(-ENODEV);
1263
 
1264
        stli_mkasyport(portp, &aport, portp->tty->termios);
1265
        return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1266
}
1267
 
1268
/*****************************************************************************/
1269
 
1270
/*
1271
 *      Wait for a specified delay period, this is not a busy-loop. It will
1272
 *      give up the processor while waiting. Unfortunately this has some
1273
 *      rather intimate knowledge of the process management stuff.
1274
 */
1275
 
1276
static void stli_delay(int len)
1277
{
1278
#if DEBUG
1279
        printk("stli_delay(len=%d)\n", len);
1280
#endif
1281
        if (len > 0) {
1282
                current->state = TASK_INTERRUPTIBLE;
1283
                current->timeout = jiffies + len;
1284
                schedule();
1285
        }
1286
}
1287
 
1288
/*****************************************************************************/
1289
 
1290
/*
1291
 *      Possibly need to wait for carrier (DCD signal) to come high. Say
1292
 *      maybe because if we are clocal then we don't need to wait...
1293
 */
1294
 
1295
static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1296
{
1297
        unsigned long   flags;
1298
        int             rc, doclocal;
1299
 
1300
#if DEBUG
1301
        printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
1302
                (int) brdp, (int) portp, (int) filp);
1303
#endif
1304
 
1305
        rc = 0;
1306
        doclocal = 0;
1307
 
1308
        if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
1309
                if (portp->normaltermios.c_cflag & CLOCAL)
1310
                        doclocal++;
1311
        } else {
1312
                if (portp->tty->termios->c_cflag & CLOCAL)
1313
                        doclocal++;
1314
        }
1315
 
1316
        save_flags(flags);
1317
        cli();
1318
        portp->openwaitcnt++;
1319
        if (! tty_hung_up_p(filp))
1320
                portp->refcount--;
1321
 
1322
        for (;;) {
1323
                if ((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) {
1324
                        stli_mkasysigs(&portp->asig, 1, 1);
1325
                        if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1326
                            &portp->asig, sizeof(asysigs_t), 0)) < 0)
1327
                                break;
1328
                }
1329
                if (tty_hung_up_p(filp) ||
1330
                    ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1331
                        if (portp->flags & ASYNC_HUP_NOTIFY)
1332
                                rc = -EBUSY;
1333
                        else
1334
                                rc = -ERESTARTSYS;
1335
                        break;
1336
                }
1337
                if (((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) &&
1338
                    ((portp->flags & ASYNC_CLOSING) == 0) &&
1339
                    (doclocal || (portp->sigs & TIOCM_CD))) {
1340
                        break;
1341
                }
1342
                if (current->signal & ~current->blocked) {
1343
                        rc = -ERESTARTSYS;
1344
                        break;
1345
                }
1346
                interruptible_sleep_on(&portp->open_wait);
1347
        }
1348
 
1349
        if (! tty_hung_up_p(filp))
1350
                portp->refcount++;
1351
        portp->openwaitcnt--;
1352
        restore_flags(flags);
1353
 
1354
        return(rc);
1355
}
1356
 
1357
/*****************************************************************************/
1358
 
1359
/*
1360
 *      Write routine. Take the data and put it in the shared memory ring
1361
 *      queue. If port is not already sending chars then need to mark the
1362
 *      service bits for this port.
1363
 */
1364
 
1365
static int stli_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1366
{
1367
        volatile cdkasy_t       *ap;
1368
        volatile cdkhdr_t       *hdrp;
1369
        volatile unsigned char  *bits;
1370
        unsigned char           *shbuf, *chbuf;
1371
        stliport_t              *portp;
1372
        stlibrd_t               *brdp;
1373
        unsigned int            len, stlen, head, tail, size;
1374
        unsigned long           flags;
1375
 
1376
#if DEBUG
1377
        printk("stli_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1378
                (int) tty, from_user, (int) buf, count);
1379
#endif
1380
 
1381
        if ((tty == (struct tty_struct *) NULL) ||
1382
            (stli_tmpwritebuf == (char *) NULL))
1383
                return(0);
1384
        if (tty == stli_txcooktty)
1385
                stli_flushchars(tty);
1386
        portp = tty->driver_data;
1387
        if (portp == (stliport_t *) NULL)
1388
                return(0);
1389
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1390
                return(0);
1391
        brdp = stli_brds[portp->brdnr];
1392
        if (brdp == (stlibrd_t *) NULL)
1393
                return(0);
1394
        chbuf = (unsigned char *) buf;
1395
 
1396
/*
1397
 *      If copying direct from user space we need to be able to handle page
1398
 *      faults while we are copying. To do this copy as much as we can now
1399
 *      into a kernel buffer. From there we copy it into shared memory. The
1400
 *      big problem is that we do not want shared memory enabled when we are
1401
 *      sleeping (other boards may be serviced while asleep). Something else
1402
 *      to note here is the reading of the tail twice. Since the boards
1403
 *      shared memory can be on an 8-bit bus then we need to be very careful
1404
 *      reading 16 bit quantities - since both the board (slave) and host
1405
 *      could be writing and reading at the same time.
1406
 */
1407
        if (from_user) {
1408
                save_flags(flags);
1409
                cli();
1410
                EBRDENABLE(brdp);
1411
                ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1412
                head = (unsigned int) ap->txq.head;
1413
                tail = (unsigned int) ap->txq.tail;
1414
                if (tail != ((unsigned int) ap->txq.tail))
1415
                        tail = (unsigned int) ap->txq.tail;
1416
                len = (head >= tail) ? (portp->txsize - (head - tail) - 1) :
1417
                        (tail - head - 1);
1418
                count = MIN(len, count);
1419
                EBRDDISABLE(brdp);
1420
 
1421
                down(&stli_tmpwritesem);
1422
                memcpy_fromfs(stli_tmpwritebuf, chbuf, count);
1423
                up(&stli_tmpwritesem);
1424
                chbuf = &stli_tmpwritebuf[0];
1425
                restore_flags(flags);
1426
        }
1427
 
1428
/*
1429
 *      All data is now local, shove as much as possible into shared memory.
1430
 */
1431
        save_flags(flags);
1432
        cli();
1433
        EBRDENABLE(brdp);
1434
        ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1435
        head = (unsigned int) ap->txq.head;
1436
        tail = (unsigned int) ap->txq.tail;
1437
        if (tail != ((unsigned int) ap->txq.tail))
1438
                tail = (unsigned int) ap->txq.tail;
1439
        size = portp->txsize;
1440
        if (head >= tail) {
1441
                len = size - (head - tail) - 1;
1442
                stlen = size - head;
1443
        } else {
1444
                len = tail - head - 1;
1445
                stlen = len;
1446
        }
1447
 
1448
        len = MIN(len, count);
1449
        count = 0;
1450
        shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1451
 
1452
        while (len > 0) {
1453
                stlen = MIN(len, stlen);
1454
                memcpy((shbuf + head), chbuf, stlen);
1455
                chbuf += stlen;
1456
                len -= stlen;
1457
                count += stlen;
1458
                head += stlen;
1459
                if (head >= size) {
1460
                        head = 0;
1461
                        stlen = tail;
1462
                }
1463
        }
1464
 
1465
        ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1466
        ap->txq.head = head;
1467
        if (test_bit(ST_TXBUSY, &portp->state)) {
1468
                if (ap->changed.data & DT_TXEMPTY)
1469
                        ap->changed.data &= ~DT_TXEMPTY;
1470
        }
1471
        hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1472
        bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1473
                portp->portidx;
1474
        *bits |= portp->portbit;
1475
        set_bit(ST_TXBUSY, &portp->state);
1476
 
1477
        EBRDDISABLE(brdp);
1478
        restore_flags(flags);
1479
 
1480
        return(count);
1481
}
1482
 
1483
/*****************************************************************************/
1484
 
1485
/*
1486
 *      Output a single character. We put it into a temporary local buffer
1487
 *      (for speed) then write out that buffer when the flushchars routine
1488
 *      is called. There is a safety catch here so that if some other port
1489
 *      writes chars before the current buffer has been, then we write them
1490
 *      first them do the new ports.
1491
 */
1492
 
1493
static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1494
{
1495
#if DEBUG
1496
        printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1497
#endif
1498
 
1499
        if (tty == (struct tty_struct *) NULL)
1500
                return;
1501
        if (tty != stli_txcooktty) {
1502
                if (stli_txcooktty != (struct tty_struct *) NULL)
1503
                        stli_flushchars(stli_txcooktty);
1504
                stli_txcooktty = tty;
1505
        }
1506
 
1507
        stli_txcookbuf[stli_txcooksize++] = ch;
1508
}
1509
 
1510
/*****************************************************************************/
1511
 
1512
/*
1513
 *      Transfer characters from the local TX cooking buffer to the board.
1514
 *      We sort of ignore the tty that gets passed in here. We rely on the
1515
 *      info stored with the TX cook buffer to tell us which port to flush
1516
 *      the data on. In any case we clean out the TX cook buffer, for re-use
1517
 *      by someone else.
1518
 */
1519
 
1520
static void stli_flushchars(struct tty_struct *tty)
1521
{
1522
        volatile cdkhdr_t       *hdrp;
1523
        volatile unsigned char  *bits;
1524
        volatile cdkasy_t       *ap;
1525
        struct tty_struct       *cooktty;
1526
        stliport_t              *portp;
1527
        stlibrd_t               *brdp;
1528
        unsigned int            len, stlen, head, tail, size, count, cooksize;
1529
        unsigned char           *buf, *shbuf;
1530
        unsigned long           flags;
1531
 
1532
#if DEBUG
1533
        printk("stli_flushchars(tty=%x)\n", (int) tty);
1534
#endif
1535
 
1536
        cooksize = stli_txcooksize;
1537
        cooktty = stli_txcooktty;
1538
        stli_txcooksize = 0;
1539
        stli_txcookrealsize = 0;
1540
        stli_txcooktty = (struct tty_struct *) NULL;
1541
 
1542
        if (tty == (struct tty_struct *) NULL)
1543
                return;
1544
        if (cooktty == (struct tty_struct *) NULL)
1545
                return;
1546
        if (tty != cooktty)
1547
                tty = cooktty;
1548
        if (cooksize == 0)
1549
                return;
1550
 
1551
        portp = tty->driver_data;
1552
        if (portp == (stliport_t *) NULL)
1553
                return;
1554
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1555
                return;
1556
        brdp = stli_brds[portp->brdnr];
1557
        if (brdp == (stlibrd_t *) NULL)
1558
                return;
1559
 
1560
        save_flags(flags);
1561
        cli();
1562
        EBRDENABLE(brdp);
1563
 
1564
        ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1565
        head = (unsigned int) ap->txq.head;
1566
        tail = (unsigned int) ap->txq.tail;
1567
        if (tail != ((unsigned int) ap->txq.tail))
1568
                tail = (unsigned int) ap->txq.tail;
1569
        size = portp->txsize;
1570
        if (head >= tail) {
1571
                len = size - (head - tail) - 1;
1572
                stlen = size - head;
1573
        } else {
1574
                len = tail - head - 1;
1575
                stlen = len;
1576
        }
1577
 
1578
        len = MIN(len, cooksize);
1579
        count = 0;
1580
        shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
1581
        buf = stli_txcookbuf;
1582
 
1583
        while (len > 0) {
1584
                stlen = MIN(len, stlen);
1585
                memcpy((shbuf + head), buf, stlen);
1586
                buf += stlen;
1587
                len -= stlen;
1588
                count += stlen;
1589
                head += stlen;
1590
                if (head >= size) {
1591
                        head = 0;
1592
                        stlen = tail;
1593
                }
1594
        }
1595
 
1596
        ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
1597
        ap->txq.head = head;
1598
 
1599
        if (test_bit(ST_TXBUSY, &portp->state)) {
1600
                if (ap->changed.data & DT_TXEMPTY)
1601
                        ap->changed.data &= ~DT_TXEMPTY;
1602
        }
1603
        hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1604
        bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
1605
                portp->portidx;
1606
        *bits |= portp->portbit;
1607
        set_bit(ST_TXBUSY, &portp->state);
1608
 
1609
        EBRDDISABLE(brdp);
1610
        restore_flags(flags);
1611
}
1612
 
1613
/*****************************************************************************/
1614
 
1615
static int stli_writeroom(struct tty_struct *tty)
1616
{
1617
        volatile cdkasyrq_t     *rp;
1618
        stliport_t              *portp;
1619
        stlibrd_t               *brdp;
1620
        unsigned int            head, tail, len;
1621
        unsigned long           flags;
1622
 
1623
#if DEBUG
1624
        printk("stli_writeroom(tty=%x)\n", (int) tty);
1625
#endif
1626
 
1627
        if (tty == (struct tty_struct *) NULL)
1628
                return(0);
1629
        if (tty == stli_txcooktty) {
1630
                if (stli_txcookrealsize != 0) {
1631
                        len = stli_txcookrealsize - stli_txcooksize;
1632
                        return(len);
1633
                }
1634
        }
1635
 
1636
        portp = tty->driver_data;
1637
        if (portp == (stliport_t *) NULL)
1638
                return(0);
1639
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1640
                return(0);
1641
        brdp = stli_brds[portp->brdnr];
1642
        if (brdp == (stlibrd_t *) NULL)
1643
                return(0);
1644
 
1645
        save_flags(flags);
1646
        cli();
1647
        EBRDENABLE(brdp);
1648
        rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1649
        head = (unsigned int) rp->head;
1650
        tail = (unsigned int) rp->tail;
1651
        if (tail != ((unsigned int) rp->tail))
1652
                tail = (unsigned int) rp->tail;
1653
        len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1654
        len--;
1655
        EBRDDISABLE(brdp);
1656
        restore_flags(flags);
1657
 
1658
        if (tty == stli_txcooktty) {
1659
                stli_txcookrealsize = len;
1660
                len -= stli_txcooksize;
1661
        }
1662
        return(len);
1663
}
1664
 
1665
/*****************************************************************************/
1666
 
1667
/*
1668
 *      Return the number of characters in the transmit buffer. Normally we
1669
 *      will return the number of chars in the shared memory ring queue.
1670
 *      We need to kludge around the case where the shared memory buffer is
1671
 *      empty but not all characters have drained yet, for this case just
1672
 *      return that there is 1 character in the buffer!
1673
 */
1674
 
1675
static int stli_charsinbuffer(struct tty_struct *tty)
1676
{
1677
        volatile cdkasyrq_t     *rp;
1678
        stliport_t              *portp;
1679
        stlibrd_t               *brdp;
1680
        unsigned int            head, tail, len;
1681
        unsigned long           flags;
1682
 
1683
#if DEBUG
1684
        printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
1685
#endif
1686
 
1687
        if (tty == (struct tty_struct *) NULL)
1688
                return(0);
1689
        if (tty == stli_txcooktty)
1690
                stli_flushchars(tty);
1691
        portp = tty->driver_data;
1692
        if (portp == (stliport_t *) NULL)
1693
                return(0);
1694
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1695
                return(0);
1696
        brdp = stli_brds[portp->brdnr];
1697
        if (brdp == (stlibrd_t *) NULL)
1698
                return(0);
1699
 
1700
        save_flags(flags);
1701
        cli();
1702
        EBRDENABLE(brdp);
1703
        rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1704
        head = (unsigned int) rp->head;
1705
        tail = (unsigned int) rp->tail;
1706
        if (tail != ((unsigned int) rp->tail))
1707
                tail = (unsigned int) rp->tail;
1708
        len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1709
        if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1710
                len = 1;
1711
        EBRDDISABLE(brdp);
1712
        restore_flags(flags);
1713
 
1714
        return(len);
1715
}
1716
 
1717
/*****************************************************************************/
1718
 
1719
/*
1720
 *      Generate the serial struct info.
1721
 */
1722
 
1723
static void stli_getserial(stliport_t *portp, struct serial_struct *sp)
1724
{
1725
        struct serial_struct    sio;
1726
        stlibrd_t               *brdp;
1727
 
1728
#if DEBUG
1729
        printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1730
#endif
1731
 
1732
        memset(&sio, 0, sizeof(struct serial_struct));
1733
        sio.type = PORT_UNKNOWN;
1734
        sio.line = portp->portnr;
1735
        sio.irq = 0;
1736
        sio.flags = portp->flags;
1737
        sio.baud_base = portp->baud_base;
1738
        sio.close_delay = portp->close_delay;
1739
        sio.closing_wait = portp->closing_wait;
1740
        sio.custom_divisor = portp->custom_divisor;
1741
        sio.xmit_fifo_size = 0;
1742
        sio.hub6 = 0;
1743
 
1744
        brdp = stli_brds[portp->brdnr];
1745
        if (brdp != (stlibrd_t *) NULL)
1746
                sio.port = brdp->iobase;
1747
 
1748
        memcpy_tofs(sp, &sio, sizeof(struct serial_struct));
1749
}
1750
 
1751
/*****************************************************************************/
1752
 
1753
/*
1754
 *      Set port according to the serial struct info.
1755
 *      At this point we do not do any auto-configure stuff, so we will
1756
 *      just quietly ignore any requests to change irq, etc.
1757
 */
1758
 
1759
static int stli_setserial(stliport_t *portp, struct serial_struct *sp)
1760
{
1761
        struct serial_struct    sio;
1762
        int                     rc;
1763
 
1764
#if DEBUG
1765
        printk("stli_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1766
#endif
1767
 
1768
        memcpy_fromfs(&sio, sp, sizeof(struct serial_struct));
1769
        if (!suser()) {
1770
                if ((sio.baud_base != portp->baud_base) ||
1771
                    (sio.close_delay != portp->close_delay) ||
1772
                    ((sio.flags & ~ASYNC_USR_MASK) !=
1773
                    (portp->flags & ~ASYNC_USR_MASK)))
1774
                        return(-EPERM);
1775
        }
1776
 
1777
        portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1778
                (sio.flags & ASYNC_USR_MASK);
1779
        portp->baud_base = sio.baud_base;
1780
        portp->close_delay = sio.close_delay;
1781
        portp->closing_wait = sio.closing_wait;
1782
        portp->custom_divisor = sio.custom_divisor;
1783
 
1784
        if ((rc = stli_setport(portp)) < 0)
1785
                return(rc);
1786
        return(0);
1787
}
1788
 
1789
/*****************************************************************************/
1790
 
1791
static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1792
{
1793
        stliport_t      *portp;
1794
        stlibrd_t       *brdp;
1795
        unsigned long   val;
1796
        int             rc;
1797
 
1798
#if DEBUG
1799
        printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1800
                (int) tty, (int) file, cmd, (int) arg);
1801
#endif
1802
 
1803
        if (tty == (struct tty_struct *) NULL)
1804
                return(-ENODEV);
1805
        portp = tty->driver_data;
1806
        if (portp == (stliport_t *) NULL)
1807
                return(-ENODEV);
1808
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1809
                return(0);
1810
        brdp = stli_brds[portp->brdnr];
1811
        if (brdp == (stlibrd_t *) NULL)
1812
                return(0);
1813
 
1814
        if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1815
            (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1816
                if (tty->flags & (1 << TTY_IO_ERROR))
1817
                        return(-EIO);
1818
        }
1819
 
1820
        rc = 0;
1821
 
1822
        switch (cmd) {
1823
        case TCSBRK:
1824
                if ((rc = tty_check_change(tty)) == 0) {
1825
                        tty_wait_until_sent(tty, 0);
1826
                        if (! arg) {
1827
                                val = 250;
1828
                                rc = stli_cmdwait(brdp, portp, A_BREAK, &val,
1829
                                        sizeof(unsigned long), 0);
1830
                        }
1831
                }
1832
                break;
1833
        case TCSBRKP:
1834
                if ((rc = tty_check_change(tty)) == 0) {
1835
                        tty_wait_until_sent(tty, 0);
1836
                        val = (arg ? (arg * 100) : 250);
1837
                        rc = stli_cmdwait(brdp, portp, A_BREAK, &val,
1838
                                sizeof(unsigned long), 0);
1839
                }
1840
                break;
1841
        case TIOCGSOFTCAR:
1842
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1843
                    sizeof(long))) == 0)
1844
                        put_fs_long(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1845
                                (unsigned long *) arg);
1846
                break;
1847
        case TIOCSSOFTCAR:
1848
                if ((rc = verify_area(VERIFY_READ, (void *) arg,
1849
                    sizeof(long))) == 0) {
1850
                        arg = get_fs_long((unsigned long *) arg);
1851
                        tty->termios->c_cflag =
1852
                                (tty->termios->c_cflag & ~CLOCAL) |
1853
                                (arg ? CLOCAL : 0);
1854
                }
1855
                break;
1856
        case TIOCMGET:
1857
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1858
                    sizeof(unsigned int))) == 0) {
1859
                        if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1860
                            &portp->asig, sizeof(asysigs_t), 1)) < 0)
1861
                                return(rc);
1862
                        val = stli_mktiocm(portp->asig.sigvalue);
1863
                        put_fs_long(val, (unsigned long *) arg);
1864
                }
1865
                break;
1866
        case TIOCMBIS:
1867
                if ((rc = verify_area(VERIFY_READ, (void *) arg,
1868
                    sizeof(long))) == 0) {
1869
                        arg = get_fs_long((unsigned long *) arg);
1870
                        stli_mkasysigs(&portp->asig,
1871
                                ((arg & TIOCM_DTR) ? 1 : -1),
1872
                                ((arg & TIOCM_RTS) ? 1 : -1));
1873
                        rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1874
                                &portp->asig, sizeof(asysigs_t), 0);
1875
                }
1876
                break;
1877
        case TIOCMBIC:
1878
                if ((rc = verify_area(VERIFY_READ, (void *) arg,
1879
                    sizeof(long))) == 0) {
1880
                        arg = get_fs_long((unsigned long *) arg);
1881
                        stli_mkasysigs(&portp->asig,
1882
                                ((arg & TIOCM_DTR) ? 0 : -1),
1883
                                ((arg & TIOCM_RTS) ? 0 : -1));
1884
                        rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1885
                                &portp->asig, sizeof(asysigs_t), 0);
1886
                }
1887
                break;
1888
        case TIOCMSET:
1889
                if ((rc = verify_area(VERIFY_READ, (void *) arg,
1890
                    sizeof(long))) == 0) {
1891
                        arg = get_fs_long((unsigned long *) arg);
1892
                        stli_mkasysigs(&portp->asig,
1893
                                ((arg & TIOCM_DTR) ? 1 : 0),
1894
                                ((arg & TIOCM_RTS) ? 1 : 0));
1895
                        rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1896
                                &portp->asig, sizeof(asysigs_t), 0);
1897
                }
1898
                break;
1899
        case TIOCGSERIAL:
1900
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1901
                    sizeof(struct serial_struct))) == 0)
1902
                        stli_getserial(portp, (struct serial_struct *) arg);
1903
                break;
1904
        case TIOCSSERIAL:
1905
                if ((rc = verify_area(VERIFY_READ, (void *) arg,
1906
                    sizeof(struct serial_struct))) == 0)
1907
                        rc = stli_setserial(portp, (struct serial_struct *)arg);
1908
                break;
1909
        case STL_GETPFLAG:
1910
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1911
                    sizeof(unsigned long))) == 0)
1912
                        put_fs_long(portp->pflag, (unsigned long *) arg);
1913
                break;
1914
        case STL_SETPFLAG:
1915
                if ((rc = verify_area(VERIFY_READ, (void *) arg,
1916
                    sizeof(unsigned long))) == 0) {
1917
                        portp->pflag = get_fs_long((unsigned long *) arg);
1918
                        stli_setport(portp);
1919
                }
1920
                break;
1921
        case COM_GETPORTSTATS:
1922
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1923
                    sizeof(comstats_t))) == 0)
1924
                        rc = stli_getportstats(portp, (comstats_t *) arg);
1925
                break;
1926
        case COM_CLRPORTSTATS:
1927
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1928
                    sizeof(comstats_t))) == 0)
1929
                        rc = stli_clrportstats(portp, (comstats_t *) arg);
1930
                break;
1931
        case TIOCSERCONFIG:
1932
        case TIOCSERGWILD:
1933
        case TIOCSERSWILD:
1934
        case TIOCSERGETLSR:
1935
        case TIOCSERGSTRUCT:
1936
        case TIOCSERGETMULTI:
1937
        case TIOCSERSETMULTI:
1938
        default:
1939
                rc = -ENOIOCTLCMD;
1940
                break;
1941
        }
1942
 
1943
        return(rc);
1944
}
1945
 
1946
/*****************************************************************************/
1947
 
1948
/*
1949
 *      This routine assumes that we have user context and can sleep.
1950
 *      Looks like it is true for the current ttys implementation..!!
1951
 */
1952
 
1953
static void stli_settermios(struct tty_struct *tty, struct termios *old)
1954
{
1955
        stliport_t      *portp;
1956
        stlibrd_t       *brdp;
1957
        struct termios  *tiosp;
1958
        asyport_t       aport;
1959
 
1960
#if DEBUG
1961
        printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1962
#endif
1963
 
1964
        if (tty == (struct tty_struct *) NULL)
1965
                return;
1966
        portp = tty->driver_data;
1967
        if (portp == (stliport_t *) NULL)
1968
                return;
1969
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1970
                return;
1971
        brdp = stli_brds[portp->brdnr];
1972
        if (brdp == (stlibrd_t *) NULL)
1973
                return;
1974
 
1975
        tiosp = tty->termios;
1976
        if ((tiosp->c_cflag == old->c_cflag) &&
1977
            (tiosp->c_iflag == old->c_iflag))
1978
                return;
1979
 
1980
        stli_mkasyport(portp, &aport, tiosp);
1981
        stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1982
        stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
1983
        stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1984
                sizeof(asysigs_t), 0);
1985
        if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
1986
                tty->hw_stopped = 0;
1987
        if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1988
                wake_up_interruptible(&portp->open_wait);
1989
}
1990
 
1991
/*****************************************************************************/
1992
 
1993
/*
1994
 *      Attempt to flow control who ever is sending us data. We won't really
1995
 *      do any flow control action here. We can't directly, and even if we
1996
 *      wanted to we would have to send a command to the slave. The slave
1997
 *      knows how to flow control, and will do so when its buffers reach its
1998
 *      internal high water marks. So what we will do is set a local state
1999
 *      bit that will stop us sending any RX data up from the poll routine
2000
 *      (which is the place where RX data from the slave is handled).
2001
 */
2002
 
2003
static void stli_throttle(struct tty_struct *tty)
2004
{
2005
        stliport_t      *portp;
2006
 
2007
#if DEBUG
2008
        printk("stli_throttle(tty=%x)\n", (int) tty);
2009
#endif
2010
 
2011
        if (tty == (struct tty_struct *) NULL)
2012
                return;
2013
        portp = tty->driver_data;
2014
        if (portp == (stliport_t *) NULL)
2015
                return;
2016
 
2017
        set_bit(ST_RXSTOP, &portp->state);
2018
}
2019
 
2020
/*****************************************************************************/
2021
 
2022
/*
2023
 *      Unflow control the device sending us data... That means that all
2024
 *      we have to do is clear the RXSTOP state bit. The next poll call
2025
 *      will then be able to pass the RX data back up.
2026
 */
2027
 
2028
static void stli_unthrottle(struct tty_struct *tty)
2029
{
2030
        stliport_t      *portp;
2031
 
2032
#if DEBUG
2033
        printk("stli_unthrottle(tty=%x)\n", (int) tty);
2034
#endif
2035
 
2036
        if (tty == (struct tty_struct *) NULL)
2037
                return;
2038
        portp = tty->driver_data;
2039
        if (portp == (stliport_t *) NULL)
2040
                return;
2041
 
2042
        clear_bit(ST_RXSTOP, &portp->state);
2043
}
2044
 
2045
/*****************************************************************************/
2046
 
2047
/*
2048
 *      Stop the transmitter. Basically to do this we will just turn TX
2049
 *      interrupts off.
2050
 */
2051
 
2052
static void stli_stop(struct tty_struct *tty)
2053
{
2054
        stlibrd_t       *brdp;
2055
        stliport_t      *portp;
2056
        asyctrl_t       actrl;
2057
 
2058
#if DEBUG
2059
        printk("stli_stop(tty=%x)\n", (int) tty);
2060
#endif
2061
 
2062
        if (tty == (struct tty_struct *) NULL)
2063
                return;
2064
        portp = tty->driver_data;
2065
        if (portp == (stliport_t *) NULL)
2066
                return;
2067
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2068
                return;
2069
        brdp = stli_brds[portp->brdnr];
2070
        if (brdp == (stlibrd_t *) NULL)
2071
                return;
2072
 
2073
        memset(&actrl, 0, sizeof(asyctrl_t));
2074
        actrl.txctrl = CT_STOPFLOW;
2075
#if 0
2076
        stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2077
#endif
2078
}
2079
 
2080
/*****************************************************************************/
2081
 
2082
/*
2083
 *      Start the transmitter again. Just turn TX interrupts back on.
2084
 */
2085
 
2086
static void stli_start(struct tty_struct *tty)
2087
{
2088
        stliport_t      *portp;
2089
        stlibrd_t       *brdp;
2090
        asyctrl_t       actrl;
2091
 
2092
#if DEBUG
2093
        printk("stli_start(tty=%x)\n", (int) tty);
2094
#endif
2095
 
2096
        if (tty == (struct tty_struct *) NULL)
2097
                return;
2098
        portp = tty->driver_data;
2099
        if (portp == (stliport_t *) NULL)
2100
                return;
2101
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2102
                return;
2103
        brdp = stli_brds[portp->brdnr];
2104
        if (brdp == (stlibrd_t *) NULL)
2105
                return;
2106
 
2107
        memset(&actrl, 0, sizeof(asyctrl_t));
2108
        actrl.txctrl = CT_STARTFLOW;
2109
#if 0
2110
        stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2111
#endif
2112
}
2113
 
2114
/*****************************************************************************/
2115
 
2116
/*
2117
 *      Scheduler called hang up routine. This is called from the scheduler,
2118
 *      not direct from the driver "poll" routine. We can't call it there
2119
 *      since the real local hangup code will enable/disable the board and
2120
 *      other things that we can't do while handling the poll. Much easier
2121
 *      to deal with it some time later (don't really care when, hangups
2122
 *      aren't that time critical).
2123
 */
2124
 
2125
static void stli_dohangup(void *arg)
2126
{
2127
        stliport_t      *portp;
2128
 
2129
#if DEBUG
2130
        printk("stli_dohangup(portp=%x)\n", (int) arg);
2131
#endif
2132
 
2133
        portp = (stliport_t *) arg;
2134
        if (portp == (stliport_t *) NULL)
2135
                return;
2136
        if (portp->tty == (struct tty_struct *) NULL)
2137
                return;
2138
        tty_hangup(portp->tty);
2139
}
2140
 
2141
/*****************************************************************************/
2142
 
2143
/*
2144
 *      Hangup this port. This is pretty much like closing the port, only
2145
 *      a little more brutal. No waiting for data to drain. Shutdown the
2146
 *      port and maybe drop signals. This is rather tricky really. We want
2147
 *      to close the port as well.
2148
 */
2149
 
2150
static void stli_hangup(struct tty_struct *tty)
2151
{
2152
        stliport_t      *portp;
2153
        stlibrd_t       *brdp;
2154
        unsigned long   flags;
2155
 
2156
#if DEBUG
2157
        printk("stli_hangup(tty=%x)\n", (int) tty);
2158
#endif
2159
 
2160
        if (tty == (struct tty_struct *) NULL)
2161
                return;
2162
        portp = tty->driver_data;
2163
        if (portp == (stliport_t *) NULL)
2164
                return;
2165
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2166
                return;
2167
        brdp = stli_brds[portp->brdnr];
2168
        if (brdp == (stlibrd_t *) NULL)
2169
                return;
2170
 
2171
        portp->flags &= ~ASYNC_INITIALIZED;
2172
 
2173
        save_flags(flags);
2174
        cli();
2175
        if (! test_bit(ST_CLOSING, &portp->state))
2176
                stli_rawclose(brdp, portp, 0, 0);
2177
        if (tty->termios->c_cflag & HUPCL) {
2178
                stli_mkasysigs(&portp->asig, 0, 0);
2179
                if (test_bit(ST_CMDING, &portp->state)) {
2180
                        set_bit(ST_DOSIGS, &portp->state);
2181
                        set_bit(ST_DOFLUSHTX, &portp->state);
2182
                        set_bit(ST_DOFLUSHRX, &portp->state);
2183
                } else {
2184
                        stli_sendcmd(brdp, portp, A_SETSIGNALSF,
2185
                                &portp->asig, sizeof(asysigs_t), 0);
2186
                }
2187
        }
2188
        restore_flags(flags);
2189
 
2190
        clear_bit(ST_TXBUSY, &portp->state);
2191
        clear_bit(ST_RXSTOP, &portp->state);
2192
        set_bit(TTY_IO_ERROR, &tty->flags);
2193
        portp->tty = (struct tty_struct *) NULL;
2194
        portp->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CALLOUT_ACTIVE);
2195
        portp->refcount = 0;
2196
        wake_up_interruptible(&portp->open_wait);
2197
}
2198
 
2199
/*****************************************************************************/
2200
 
2201
/*
2202
 *      Flush characters from the lower buffer. We may not have user context
2203
 *      so we cannot sleep waiting for it to complete. Also we need to check
2204
 *      if there is chars for this port in the TX cook buffer, and flush them
2205
 *      as well.
2206
 */
2207
 
2208
static void stli_flushbuffer(struct tty_struct *tty)
2209
{
2210
        stliport_t      *portp;
2211
        stlibrd_t       *brdp;
2212
        unsigned long   ftype, flags;
2213
 
2214
#if DEBUG
2215
        printk("stli_flushbuffer(tty=%x)\n", (int) tty);
2216
#endif
2217
 
2218
        if (tty == (struct tty_struct *) NULL)
2219
                return;
2220
        portp = tty->driver_data;
2221
        if (portp == (stliport_t *) NULL)
2222
                return;
2223
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2224
                return;
2225
        brdp = stli_brds[portp->brdnr];
2226
        if (brdp == (stlibrd_t *) NULL)
2227
                return;
2228
 
2229
        save_flags(flags);
2230
        cli();
2231
        if (tty == stli_txcooktty) {
2232
                stli_txcooktty = (struct tty_struct *) NULL;
2233
                stli_txcooksize = 0;
2234
                stli_txcookrealsize = 0;
2235
        }
2236
        if (test_bit(ST_CMDING, &portp->state)) {
2237
                set_bit(ST_DOFLUSHTX, &portp->state);
2238
        } else {
2239
                ftype = FLUSHTX;
2240
                if (test_bit(ST_DOFLUSHRX, &portp->state)) {
2241
                        ftype |= FLUSHRX;
2242
                        clear_bit(ST_DOFLUSHRX, &portp->state);
2243
                }
2244
                stli_sendcmd(brdp, portp, A_FLUSH, &ftype,
2245
                        sizeof(unsigned long), 0);
2246
        }
2247
        restore_flags(flags);
2248
 
2249
        wake_up_interruptible(&tty->write_wait);
2250
        if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2251
            tty->ldisc.write_wakeup)
2252
                (tty->ldisc.write_wakeup)(tty);
2253
}
2254
 
2255
/*****************************************************************************/
2256
 
2257
/*
2258
 *      Generic send command routine. This will send a message to the slave,
2259
 *      of the specified type with the specified argument. Must be very
2260
 *      careful of data that will be copied out from shared memory -
2261
 *      containing command results. The command completion is all done from
2262
 *      a poll routine that does not have user context. Therefore you cannot
2263
 *      copy back directly into user space, or to the kernel stack of a
2264
 *      process. This routine does not sleep, so can be called from anywhere.
2265
 */
2266
 
2267
static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2268
{
2269
        volatile cdkhdr_t       *hdrp;
2270
        volatile cdkctrl_t      *cp;
2271
        volatile unsigned char  *bits;
2272
        unsigned long           flags;
2273
 
2274
#if DEBUG
2275
        printk("stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
2276
                "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
2277
                (int) arg, size, copyback);
2278
#endif
2279
 
2280
        save_flags(flags);
2281
        cli();
2282
 
2283
        if (test_bit(ST_CMDING, &portp->state)) {
2284
                printk("STALLION: command already busy, cmd=%x!\n", (int) cmd);
2285
                restore_flags(flags);
2286
                return;
2287
        }
2288
 
2289
        EBRDENABLE(brdp);
2290
        cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2291
        if (size > 0) {
2292
                memcpy((void *) &(cp->args[0]), arg, size);
2293
                if (copyback) {
2294
                        portp->argp = arg;
2295
                        portp->argsize = size;
2296
                }
2297
        }
2298
        cp->status = 0;
2299
        cp->cmd = cmd;
2300
        hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2301
        bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
2302
                portp->portidx;
2303
        *bits |= portp->portbit;
2304
        set_bit(ST_CMDING, &portp->state);
2305
        EBRDDISABLE(brdp);
2306
        restore_flags(flags);
2307
}
2308
 
2309
/*****************************************************************************/
2310
 
2311
/*
2312
 *      Read data from shared memory. This assumes that the shared memory
2313
 *      is enabled and that interrupts are off. Basically we just empty out
2314
 *      the shared memory buffer into the tty buffer. Must be careful to
2315
 *      handle the case where we fill up the tty buffer, but still have
2316
 *      more chars to unload.
2317
 */
2318
 
2319
static inline void stli_read(stlibrd_t *brdp, stliport_t *portp)
2320
{
2321
        volatile cdkasyrq_t     *rp;
2322
        volatile char           *shbuf;
2323
        struct tty_struct       *tty;
2324
        unsigned int            head, tail, size;
2325
        unsigned int            len, stlen;
2326
 
2327
#if DEBUG
2328
        printk("stli_read(brdp=%x,portp=%d)\n", (int) brdp, (int) portp);
2329
#endif
2330
 
2331
        if (test_bit(ST_RXSTOP, &portp->state))
2332
                return;
2333
        tty = portp->tty;
2334
        if (tty == (struct tty_struct *) NULL)
2335
                return;
2336
 
2337
        rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2338
        head = (unsigned int) rp->head;
2339
        if (head != ((unsigned int) rp->head))
2340
                head = (unsigned int) rp->head;
2341
        tail = (unsigned int) rp->tail;
2342
        size = portp->rxsize;
2343
        if (head >= tail) {
2344
                len = head - tail;
2345
                stlen = len;
2346
        } else {
2347
                len = size - (tail - head);
2348
                stlen = size - tail;
2349
        }
2350
 
2351
        len = MIN(len, (TTY_FLIPBUF_SIZE - tty->flip.count));
2352
        shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2353
 
2354
        while (len > 0) {
2355
                stlen = MIN(len, stlen);
2356
                memcpy(tty->flip.char_buf_ptr, (char *) (shbuf + tail), stlen);
2357
                memset(tty->flip.flag_buf_ptr, 0, stlen);
2358
                tty->flip.char_buf_ptr += stlen;
2359
                tty->flip.flag_buf_ptr += stlen;
2360
                tty->flip.count += stlen;
2361
 
2362
                len -= stlen;
2363
                tail += stlen;
2364
                if (tail >= size) {
2365
                        tail = 0;
2366
                        stlen = head;
2367
                }
2368
        }
2369
        rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2370
        rp->tail = tail;
2371
 
2372
        if (head != tail)
2373
                set_bit(ST_RXING, &portp->state);
2374
 
2375
        tty_schedule_flip(tty);
2376
}
2377
 
2378
/*****************************************************************************/
2379
 
2380
/*
2381
 *      Set up and carry out any delayed commands. There is only a small set
2382
 *      of slave commands that can be done "off-level". So it is not too
2383
 *      difficult to deal with them here.
2384
 */
2385
 
2386
static inline void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2387
{
2388
        int     cmd;
2389
 
2390
        if (test_bit(ST_DOSIGS, &portp->state)) {
2391
                if (test_bit(ST_DOFLUSHTX, &portp->state) &&
2392
                    test_bit(ST_DOFLUSHRX, &portp->state))
2393
                        cmd = A_SETSIGNALSF;
2394
                else if (test_bit(ST_DOFLUSHTX, &portp->state))
2395
                        cmd = A_SETSIGNALSFTX;
2396
                else if (test_bit(ST_DOFLUSHRX, &portp->state))
2397
                        cmd = A_SETSIGNALSFRX;
2398
                else
2399
                        cmd = A_SETSIGNALS;
2400
                clear_bit(ST_DOFLUSHTX, &portp->state);
2401
                clear_bit(ST_DOFLUSHRX, &portp->state);
2402
                clear_bit(ST_DOSIGS, &portp->state);
2403
                memcpy((void *) &(cp->args[0]), (void *) &portp->asig,
2404
                        sizeof(asysigs_t));
2405
                cp->status = 0;
2406
                cp->cmd = cmd;
2407
                set_bit(ST_CMDING, &portp->state);
2408
        } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2409
            test_bit(ST_DOFLUSHRX, &portp->state)) {
2410
                cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
2411
                cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2412
                clear_bit(ST_DOFLUSHTX, &portp->state);
2413
                clear_bit(ST_DOFLUSHRX, &portp->state);
2414
                memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2415
                cp->status = 0;
2416
                cp->cmd = A_FLUSH;
2417
                set_bit(ST_CMDING, &portp->state);
2418
        }
2419
}
2420
 
2421
/*****************************************************************************/
2422
 
2423
/*
2424
 *      Host command service checking. This handles commands or messages
2425
 *      coming from the slave to the host. Must have board shared memory
2426
 *      enabled and interrupts off when called. Notice that by servicing the
2427
 *      read data last we don't need to change the shared memory pointer
2428
 *      during processing (which is a slow IO operation).
2429
 *      Return value indicates if this port is still awaiting actions from
2430
 *      the slave (like open, command, or even TX data being sent). If 0
2431
 *      then port is still busy, otherwise no longer busy.
2432
 */
2433
 
2434
static inline int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2435
{
2436
        volatile cdkasy_t       *ap;
2437
        volatile cdkctrl_t      *cp;
2438
        struct tty_struct       *tty;
2439
        asynotify_t             nt;
2440
        unsigned long           oldsigs;
2441
        int                     rc, donerx;
2442
 
2443
#if DEBUG
2444
        printk("stli_hostcmd(brdp=%x,channr=%d)\n", (int) brdp, channr);
2445
#endif
2446
 
2447
        ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
2448
        cp = &ap->ctrl;
2449
 
2450
/*
2451
 *      Check if we are waiting for an open completion message.
2452
 */
2453
        if (test_bit(ST_OPENING, &portp->state)) {
2454
                rc = (int) cp->openarg;
2455
                if ((cp->open == 0) && (rc != 0)) {
2456
                        if (rc > 0)
2457
                                rc--;
2458
                        cp->openarg = 0;
2459
                        portp->rc = rc;
2460
                        clear_bit(ST_OPENING, &portp->state);
2461
                        wake_up_interruptible(&portp->raw_wait);
2462
                }
2463
        }
2464
 
2465
/*
2466
 *      Check if we are waiting for a close completion message.
2467
 */
2468
        if (test_bit(ST_CLOSING, &portp->state)) {
2469
                rc = (int) cp->closearg;
2470
                if ((cp->close == 0) && (rc != 0)) {
2471
                        if (rc > 0)
2472
                                rc--;
2473
                        cp->closearg = 0;
2474
                        portp->rc = rc;
2475
                        clear_bit(ST_CLOSING, &portp->state);
2476
                        wake_up_interruptible(&portp->raw_wait);
2477
                }
2478
        }
2479
 
2480
/*
2481
 *      Check if we are waiting for a command completion message. We may
2482
 *      need to copy out the command results associated with this command.
2483
 */
2484
        if (test_bit(ST_CMDING, &portp->state)) {
2485
                rc = cp->status;
2486
                if ((cp->cmd == 0) && (rc != 0)) {
2487
                        if (rc > 0)
2488
                                rc--;
2489
                        if (portp->argp != (void *) NULL) {
2490
                                memcpy(portp->argp, (void *) &(cp->args[0]),
2491
                                        portp->argsize);
2492
                                portp->argp = (void *) NULL;
2493
                        }
2494
                        cp->status = 0;
2495
                        portp->rc = rc;
2496
                        clear_bit(ST_CMDING, &portp->state);
2497
                        stli_dodelaycmd(portp, cp);
2498
                        wake_up_interruptible(&portp->raw_wait);
2499
                }
2500
        }
2501
 
2502
/*
2503
 *      Check for any notification messages ready. This includes lots of
2504
 *      different types of events - RX chars ready, RX break received,
2505
 *      TX data low or empty in the slave, modem signals changed state.
2506
 */
2507
        donerx = 0;
2508
 
2509
        if (ap->notify) {
2510
                nt = ap->changed;
2511
                ap->notify = 0;
2512
                tty = portp->tty;
2513
 
2514
                if (nt.signal & SG_DCD) {
2515
                        oldsigs = portp->sigs;
2516
                        portp->sigs = stli_mktiocm(nt.sigvalue);
2517
                        clear_bit(ST_GETSIGS, &portp->state);
2518
                        if ((portp->sigs & TIOCM_CD) &&
2519
                            ((oldsigs & TIOCM_CD) == 0))
2520
                                wake_up_interruptible(&portp->open_wait);
2521
                        if ((oldsigs & TIOCM_CD) &&
2522
                            ((portp->sigs & TIOCM_CD) == 0)) {
2523
                                if (portp->flags & ASYNC_CHECK_CD) {
2524
                                        if (! ((portp->flags & ASYNC_CALLOUT_ACTIVE) &&
2525
                                            (portp->flags & ASYNC_CALLOUT_NOHUP))) {
2526
                                                if (tty != (struct tty_struct *) NULL)
2527
                                                        queue_task_irq_off(&portp->tqhangup, &tq_scheduler);
2528
                                        }
2529
                                }
2530
                        }
2531
                }
2532
 
2533
                if (nt.data & DT_TXEMPTY)
2534
                        clear_bit(ST_TXBUSY, &portp->state);
2535
                if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2536
                        if (tty != (struct tty_struct *) NULL) {
2537
                                if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2538
                                    tty->ldisc.write_wakeup) {
2539
                                        (tty->ldisc.write_wakeup)(tty);
2540
                                        EBRDENABLE(brdp);
2541
                                }
2542
                                wake_up_interruptible(&tty->write_wait);
2543
                        }
2544
                }
2545
 
2546
                if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2547
                        if (tty != (struct tty_struct *) NULL) {
2548
                                if (tty->flip.count < TTY_FLIPBUF_SIZE) {
2549
                                        tty->flip.count++;
2550
                                        *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2551
                                        *tty->flip.char_buf_ptr++ = 0;
2552
                                        if (portp->flags & ASYNC_SAK) {
2553
                                                do_SAK(tty);
2554
                                                EBRDENABLE(brdp);
2555
                                        }
2556
                                        tty_schedule_flip(tty);
2557
                                }
2558
                        }
2559
                }
2560
 
2561
                if (nt.data & DT_RXBUSY) {
2562
                        donerx++;
2563
                        stli_read(brdp, portp);
2564
                }
2565
        }
2566
 
2567
/*
2568
 *      It might seem odd that we are checking for more RX chars here.
2569
 *      But, we need to handle the case where the tty buffer was previously
2570
 *      filled, but we had more characters to pass up. The slave will not
2571
 *      send any more RX notify messages until the RX buffer has been emptied.
2572
 *      But it will leave the service bits on (since the buffer is not empty).
2573
 *      So from here we can try to process more RX chars.
2574
 */
2575
        if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
2576
                clear_bit(ST_RXING, &portp->state);
2577
                stli_read(brdp, portp);
2578
        }
2579
 
2580
        return((test_bit(ST_OPENING, &portp->state) ||
2581
                test_bit(ST_CLOSING, &portp->state) ||
2582
                test_bit(ST_CMDING, &portp->state) ||
2583
                test_bit(ST_TXBUSY, &portp->state) ||
2584
                test_bit(ST_RXING, &portp->state)) ? 0 : 1);
2585
}
2586
 
2587
/*****************************************************************************/
2588
 
2589
/*
2590
 *      Service all ports on a particular board. Assumes that the boards
2591
 *      shared memory is enabled, and that the page pointer is pointed
2592
 *      at the cdk header structure.
2593
 */
2594
 
2595
static inline void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
2596
{
2597
        stliport_t      *portp;
2598
        unsigned char   hostbits[(STL_MAXCHANS / 8) + 1];
2599
        unsigned char   slavebits[(STL_MAXCHANS / 8) + 1];
2600
        unsigned char   *slavep;
2601
        int             bitpos, bitat, bitsize;
2602
        int             channr, nrdevs, slavebitchange;
2603
 
2604
        bitsize = brdp->bitsize;
2605
        nrdevs = brdp->nrdevs;
2606
 
2607
/*
2608
 *      Check if slave wants any service. Basically we try to do as
2609
 *      little work as possible here. There are 2 levels of service
2610
 *      bits. So if there is nothing to do we bail early. We check
2611
 *      8 service bits at a time in the inner loop, so we can bypass
2612
 *      the lot if none of them want service.
2613
 */
2614
        memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset),
2615
                bitsize);
2616
 
2617
        memset(&slavebits[0], 0, bitsize);
2618
        slavebitchange = 0;
2619
 
2620
        for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2621
                if (hostbits[bitpos] == 0)
2622
                        continue;
2623
                channr = bitpos * 8;
2624
                for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
2625
                        if (hostbits[bitpos] & bitat) {
2626
                                portp = brdp->ports[(channr - 1)];
2627
                                if (stli_hostcmd(brdp, portp)) {
2628
                                        slavebitchange++;
2629
                                        slavebits[bitpos] |= bitat;
2630
                                }
2631
                        }
2632
                }
2633
        }
2634
 
2635
/*
2636
 *      If any of the ports are no longer busy then update them in the
2637
 *      slave request bits. We need to do this after, since a host port
2638
 *      service may initiate more slave requests.
2639
 */
2640
        if (slavebitchange) {
2641
                hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2642
                slavep = ((unsigned char *) hdrp) + brdp->slaveoffset;
2643
                for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2644
                        if (slavebits[bitpos])
2645
                                slavep[bitpos] &= ~slavebits[bitpos];
2646
                }
2647
        }
2648
}
2649
 
2650
/*****************************************************************************/
2651
 
2652
/*
2653
 *      Driver poll routine. This routine polls the boards in use and passes
2654
 *      messages back up to host when necessary. This is actually very
2655
 *      CPU efficient, since we will always have the kernel poll clock, it
2656
 *      adds only a few cycles when idle (since board service can be
2657
 *      determined very easily), but when loaded generates no interrupts
2658
 *      (with their expensive associated context change).
2659
 */
2660
 
2661
static void stli_poll(unsigned long arg)
2662
{
2663
        volatile cdkhdr_t       *hdrp;
2664
        stlibrd_t               *brdp;
2665
        int                     brdnr;
2666
 
2667
        stli_timerlist.expires = STLI_TIMEOUT;
2668
        add_timer(&stli_timerlist);
2669
 
2670
/*
2671
 *      Check each board and do any servicing required.
2672
 */
2673
        for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2674
                brdp = stli_brds[brdnr];
2675
                if (brdp == (stlibrd_t *) NULL)
2676
                        continue;
2677
                if ((brdp->state & BST_STARTED) == 0)
2678
                        continue;
2679
 
2680
                EBRDENABLE(brdp);
2681
                hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2682
                if (hdrp->hostreq)
2683
                        stli_brdpoll(brdp, hdrp);
2684
                EBRDDISABLE(brdp);
2685
        }
2686
}
2687
 
2688
/*****************************************************************************/
2689
 
2690
/*
2691
 *      Translate the termios settings into the port setting structure of
2692
 *      the slave.
2693
 */
2694
 
2695
static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
2696
{
2697
#if DEBUG
2698
        printk("stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
2699
                (int) portp, (int) pp, (int) tiosp);
2700
#endif
2701
 
2702
        memset(pp, 0, sizeof(asyport_t));
2703
 
2704
/*
2705
 *      Start of by setting the baud, char size, parity and stop bit info.
2706
 */
2707
        pp->baudout = tiosp->c_cflag & CBAUD;
2708
        if (pp->baudout & CBAUDEX) {
2709
                pp->baudout &= ~CBAUDEX;
2710
                if ((pp->baudout < 1) || (pp->baudout > 5))
2711
                        tiosp->c_cflag &= ~CBAUDEX;
2712
                else
2713
                        pp->baudout += 15;
2714
        }
2715
        pp->baudout = stli_baudrates[pp->baudout];
2716
        if ((tiosp->c_cflag & CBAUD) == B38400) {
2717
                if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2718
                        pp->baudout = 57600;
2719
                else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2720
                        pp->baudout = 115200;
2721
                else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2722
                        pp->baudout = (portp->baud_base / portp->custom_divisor);
2723
        }
2724
        if (pp->baudout > STL_MAXBAUD)
2725
                pp->baudout = STL_MAXBAUD;
2726
        pp->baudin = pp->baudout;
2727
 
2728
        switch (tiosp->c_cflag & CSIZE) {
2729
        case CS5:
2730
                pp->csize = 5;
2731
                break;
2732
        case CS6:
2733
                pp->csize = 6;
2734
                break;
2735
        case CS7:
2736
                pp->csize = 7;
2737
                break;
2738
        default:
2739
                pp->csize = 8;
2740
                break;
2741
        }
2742
 
2743
        if (tiosp->c_cflag & CSTOPB)
2744
                pp->stopbs = PT_STOP2;
2745
        else
2746
                pp->stopbs = PT_STOP1;
2747
 
2748
        if (tiosp->c_cflag & PARENB) {
2749
                if (tiosp->c_cflag & PARODD)
2750
                        pp->parity = PT_ODDPARITY;
2751
                else
2752
                        pp->parity = PT_EVENPARITY;
2753
        } else {
2754
                pp->parity = PT_NOPARITY;
2755
        }
2756
 
2757
/*
2758
 *      Set up any flow control options enabled.
2759
 */
2760
        if (tiosp->c_iflag & IXON) {
2761
                pp->flow |= F_IXON;
2762
                if (tiosp->c_iflag & IXANY)
2763
                        pp->flow |= F_IXANY;
2764
        }
2765
        if (tiosp->c_cflag & CRTSCTS)
2766
                pp->flow |= (F_RTSFLOW | F_CTSFLOW);
2767
 
2768
        pp->startin = tiosp->c_cc[VSTART];
2769
        pp->stopin = tiosp->c_cc[VSTOP];
2770
        pp->startout = tiosp->c_cc[VSTART];
2771
        pp->stopout = tiosp->c_cc[VSTOP];
2772
 
2773
/*
2774
 *      Set up the RX char marking mask with those RX error types we must
2775
 *      catch. We can get the slave to help us out a little here, it will
2776
 *      ignore parity errors and breaks for us, and mark parity errors in
2777
 *      the data stream.
2778
 */
2779
        if (tiosp->c_iflag & IGNPAR)
2780
                pp->iflag |= FI_IGNRXERRS;
2781
        if (tiosp->c_iflag & IGNBRK)
2782
                pp->iflag |= FI_IGNBREAK;
2783
 
2784
        portp->rxmarkmsk = 0;
2785
        if (tiosp->c_iflag & (INPCK | PARMRK))
2786
                pp->iflag |= FI_1MARKRXERRS;
2787
        if (tiosp->c_iflag & BRKINT)
2788
                portp->rxmarkmsk |= BRKINT;
2789
 
2790
/*
2791
 *      Set up clocal processing as required.
2792
 */
2793
        if (tiosp->c_cflag & CLOCAL)
2794
                portp->flags &= ~ASYNC_CHECK_CD;
2795
        else
2796
                portp->flags |= ASYNC_CHECK_CD;
2797
 
2798
/*
2799
 *      Transfer any persistent flags into the asyport structure.
2800
 */
2801
        pp->pflag = (portp->pflag & 0xffff);
2802
        pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
2803
        pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
2804
        pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
2805
}
2806
 
2807
/*****************************************************************************/
2808
 
2809
/*
2810
 *      Construct a slave signals structure for setting the DTR and RTS
2811
 *      signals as specified.
2812
 */
2813
 
2814
static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
2815
{
2816
#if DEBUG
2817
        printk("stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n", (int) sp, dtr, rts);
2818
#endif
2819
 
2820
        memset(sp, 0, sizeof(asysigs_t));
2821
        if (dtr >= 0) {
2822
                sp->signal |= SG_DTR;
2823
                sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
2824
        }
2825
        if (rts >= 0) {
2826
                sp->signal |= SG_RTS;
2827
                sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
2828
        }
2829
}
2830
 
2831
/*****************************************************************************/
2832
 
2833
/*
2834
 *      Convert the signals returned from the slave into a local TIOCM type
2835
 *      signals value. We keep them locally in TIOCM format.
2836
 */
2837
 
2838
static long stli_mktiocm(unsigned long sigvalue)
2839
{
2840
        long    tiocm;
2841
 
2842
#if DEBUG
2843
        printk("stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
2844
#endif
2845
 
2846
        tiocm = 0;
2847
        tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
2848
        tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
2849
        tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
2850
        tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
2851
        tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
2852
        tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
2853
        return(tiocm);
2854
}
2855
 
2856
/*****************************************************************************/
2857
 
2858
/*
2859
 *      All panels and ports actually attached have been worked out. All
2860
 *      we need to do here is set up the appropriate per port data structures.
2861
 */
2862
 
2863
static inline int stli_initports(stlibrd_t *brdp)
2864
{
2865
        stliport_t      *portp;
2866
        int             i, panelnr, panelport;
2867
 
2868
#if DEBUG
2869
        printk("stli_initports(brdp=%x)\n", (int) brdp);
2870
#endif
2871
 
2872
        for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2873
                portp = (stliport_t *) stli_memalloc(sizeof(stliport_t));
2874
                if (portp == (stliport_t *) NULL) {
2875
                        printk("STALLION: failed to allocate port structure\n");
2876
                        continue;
2877
                }
2878
 
2879
                memset(portp, 0, sizeof(stliport_t));
2880
                portp->magic = STLI_PORTMAGIC;
2881
                portp->portnr = i;
2882
                portp->brdnr = brdp->brdnr;
2883
                portp->panelnr = panelnr;
2884
                portp->baud_base = STL_BAUDBASE;
2885
                portp->close_delay = STL_CLOSEDELAY;
2886
                portp->closing_wait = 30 * HZ;
2887
                portp->tqhangup.routine = stli_dohangup;
2888
                portp->tqhangup.data = portp;
2889
                portp->normaltermios = stli_deftermios;
2890
                portp->callouttermios = stli_deftermios;
2891
                panelport++;
2892
                if (panelport >= brdp->panels[panelnr]) {
2893
                        panelport = 0;
2894
                        panelnr++;
2895
                }
2896
                brdp->ports[i] = portp;
2897
        }
2898
 
2899
        return(0);
2900
}
2901
 
2902
/*****************************************************************************/
2903
 
2904
/*
2905
 *      All the following routines are board specific hardware operations.
2906
 */
2907
 
2908
static void stli_ecpinit(stlibrd_t *brdp)
2909
{
2910
        unsigned long   memconf;
2911
 
2912
#if DEBUG
2913
        printk("stli_ecpinit(brdp=%d)\n", (int) brdp);
2914
#endif
2915
 
2916
        outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2917
        udelay(10);
2918
        outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2919
        udelay(100);
2920
 
2921
        memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
2922
        outb(memconf, (brdp->iobase + ECP_ATMEMAR));
2923
}
2924
 
2925
/*****************************************************************************/
2926
 
2927
static void stli_ecpenable(stlibrd_t *brdp)
2928
{
2929
#if DEBUG
2930
        printk("stli_ecpenable(brdp=%x)\n", (int) brdp);
2931
#endif
2932
        outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2933
}
2934
 
2935
/*****************************************************************************/
2936
 
2937
static void stli_ecpdisable(stlibrd_t *brdp)
2938
{
2939
#if DEBUG
2940
        printk("stli_ecpdisable(brdp=%x)\n", (int) brdp);
2941
#endif
2942
        outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2943
}
2944
 
2945
/*****************************************************************************/
2946
 
2947
static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
2948
{
2949
        void            *ptr;
2950
        unsigned char   val;
2951
 
2952
#if DEBUG
2953
        printk("stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
2954
                (int) offset);
2955
#endif
2956
 
2957
        if (offset > brdp->memsize) {
2958
                printk("STALLION: shared memory pointer=%x out of range at "
2959
                        "line=%d(%d), brd=%d\n", (int) offset, line,
2960
                        __LINE__, brdp->brdnr);
2961
                ptr = 0;
2962
                val = 0;
2963
        } else {
2964
                ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
2965
                val = (unsigned char) (offset / ECP_ATPAGESIZE);
2966
        }
2967
        outb(val, (brdp->iobase + ECP_ATMEMPR));
2968
        return(ptr);
2969
}
2970
 
2971
/*****************************************************************************/
2972
 
2973
static void stli_ecpreset(stlibrd_t *brdp)
2974
{
2975
#if DEBUG
2976
        printk("stli_ecpreset(brdp=%x)\n", (int) brdp);
2977
#endif
2978
 
2979
        outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2980
        udelay(10);
2981
        outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2982
        udelay(500);
2983
}
2984
 
2985
/*****************************************************************************/
2986
 
2987
static void stli_ecpintr(stlibrd_t *brdp)
2988
{
2989
#if DEBUG
2990
        printk("stli_ecpintr(brdp=%x)\n", (int) brdp);
2991
#endif
2992
        outb(0x1, brdp->iobase);
2993
}
2994
 
2995
/*****************************************************************************/
2996
 
2997
/*
2998
 *      The following set of functions act on ECP EISA boards.
2999
 */
3000
 
3001
static void stli_ecpeiinit(stlibrd_t *brdp)
3002
{
3003
        unsigned long   memconf;
3004
 
3005
#if DEBUG
3006
        printk("stli_ecpeiinit(brdp=%x)\n", (int) brdp);
3007
#endif
3008
 
3009
        outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3010
        outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3011
        udelay(10);
3012
        outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3013
        udelay(500);
3014
 
3015
        memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
3016
        outb(memconf, (brdp->iobase + ECP_EIMEMARL));
3017
        memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
3018
        outb(memconf, (brdp->iobase + ECP_EIMEMARH));
3019
}
3020
 
3021
/*****************************************************************************/
3022
 
3023
static void stli_ecpeienable(stlibrd_t *brdp)
3024
{
3025
        outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
3026
}
3027
 
3028
/*****************************************************************************/
3029
 
3030
static void stli_ecpeidisable(stlibrd_t *brdp)
3031
{
3032
        outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3033
}
3034
 
3035
/*****************************************************************************/
3036
 
3037
static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3038
{
3039
        void            *ptr;
3040
        unsigned char   val;
3041
 
3042
#if DEBUG
3043
        printk("stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3044
                (int) brdp, (int) offset, line);
3045
#endif
3046
 
3047
        if (offset > brdp->memsize) {
3048
                printk("STALLION: shared memory pointer=%x out of range at "
3049
                        "line=%d(%d), brd=%d\n", (int) offset, line,
3050
                        __LINE__, brdp->brdnr);
3051
                ptr = 0;
3052
                val = 0;
3053
        } else {
3054
                ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
3055
                if (offset < ECP_EIPAGESIZE)
3056
                        val = ECP_EIENABLE;
3057
                else
3058
                        val = ECP_EIENABLE | 0x40;
3059
        }
3060
        outb(val, (brdp->iobase + ECP_EICONFR));
3061
        return(ptr);
3062
}
3063
 
3064
/*****************************************************************************/
3065
 
3066
static void stli_ecpeireset(stlibrd_t *brdp)
3067
{
3068
        outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3069
        udelay(10);
3070
        outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3071
        udelay(500);
3072
}
3073
 
3074
/*****************************************************************************/
3075
 
3076
/*
3077
 *      The following set of functions act on ECP MCA boards.
3078
 */
3079
 
3080
static void stli_ecpmcenable(stlibrd_t *brdp)
3081
{
3082
        outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
3083
}
3084
 
3085
/*****************************************************************************/
3086
 
3087
static void stli_ecpmcdisable(stlibrd_t *brdp)
3088
{
3089
        outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3090
}
3091
 
3092
/*****************************************************************************/
3093
 
3094
static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3095
{
3096
        void            *ptr;
3097
        unsigned char   val;
3098
 
3099
        if (offset > brdp->memsize) {
3100
                printk("STALLION: shared memory pointer=%x out of range at "
3101
                        "line=%d(%d), brd=%d\n", (int) offset, line,
3102
                        __LINE__, brdp->brdnr);
3103
                ptr = 0;
3104
                val = 0;
3105
        } else {
3106
                ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
3107
                val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
3108
        }
3109
        outb(val, (brdp->iobase + ECP_MCCONFR));
3110
        return(ptr);
3111
}
3112
 
3113
/*****************************************************************************/
3114
 
3115
static void stli_ecpmcreset(stlibrd_t *brdp)
3116
{
3117
        outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3118
        udelay(10);
3119
        outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3120
        udelay(500);
3121
}
3122
 
3123
/*****************************************************************************/
3124
 
3125
/*
3126
 *      The following routines act on ONboards.
3127
 */
3128
 
3129
static void stli_onbinit(stlibrd_t *brdp)
3130
{
3131
        unsigned long   memconf;
3132
        int             i;
3133
 
3134
#if DEBUG
3135
        printk("stli_onbinit(brdp=%d)\n", (int) brdp);
3136
#endif
3137
 
3138
        outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3139
        udelay(10);
3140
        outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3141
        for (i = 0; (i < 1000); i++)
3142
                udelay(1000);
3143
 
3144
        memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
3145
        outb(memconf, (brdp->iobase + ONB_ATMEMAR));
3146
        outb(0x1, brdp->iobase);
3147
        udelay(1000);
3148
}
3149
 
3150
/*****************************************************************************/
3151
 
3152
static void stli_onbenable(stlibrd_t *brdp)
3153
{
3154
#if DEBUG
3155
        printk("stli_onbenable(brdp=%x)\n", (int) brdp);
3156
#endif
3157
        outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3158
}
3159
 
3160
/*****************************************************************************/
3161
 
3162
static void stli_onbdisable(stlibrd_t *brdp)
3163
{
3164
#if DEBUG
3165
        printk("stli_onbdisable(brdp=%x)\n", (int) brdp);
3166
#endif
3167
        outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3168
}
3169
 
3170
/*****************************************************************************/
3171
 
3172
static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3173
{
3174
        void    *ptr;
3175
 
3176
#if DEBUG
3177
        printk("stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3178
                (int) offset);
3179
#endif
3180
 
3181
        if (offset > brdp->memsize) {
3182
                printk("STALLION: shared memory pointer=%x out of range at "
3183
                        "line=%d(%d), brd=%d\n", (int) offset, line,
3184
                        __LINE__, brdp->brdnr);
3185
                ptr = 0;
3186
        } else {
3187
                ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
3188
        }
3189
        return(ptr);
3190
}
3191
 
3192
/*****************************************************************************/
3193
 
3194
static void stli_onbreset(stlibrd_t *brdp)
3195
{
3196
        int     i;
3197
 
3198
#if DEBUG
3199
        printk("stli_onbreset(brdp=%x)\n", (int) brdp);
3200
#endif
3201
 
3202
        outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3203
        udelay(10);
3204
        outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
3205
        for (i = 0; (i < 1000); i++)
3206
                udelay(1000);
3207
}
3208
 
3209
/*****************************************************************************/
3210
 
3211
/*
3212
 *      The following routines act on ONboard EISA.
3213
 */
3214
 
3215
static void stli_onbeinit(stlibrd_t *brdp)
3216
{
3217
        unsigned long   memconf;
3218
        int             i;
3219
 
3220
#if DEBUG
3221
        printk("stli_onbeinit(brdp=%d)\n", (int) brdp);
3222
#endif
3223
 
3224
        outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3225
        outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3226
        udelay(10);
3227
        outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3228
        for (i = 0; (i < 1000); i++)
3229
                udelay(1000);
3230
 
3231
        memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
3232
        outb(memconf, (brdp->iobase + ONB_EIMEMARL));
3233
        memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
3234
        outb(memconf, (brdp->iobase + ONB_EIMEMARH));
3235
        outb(0x1, brdp->iobase);
3236
        udelay(1000);
3237
}
3238
 
3239
/*****************************************************************************/
3240
 
3241
static void stli_onbeenable(stlibrd_t *brdp)
3242
{
3243
#if DEBUG
3244
        printk("stli_onbeenable(brdp=%x)\n", (int) brdp);
3245
#endif
3246
        outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3247
}
3248
 
3249
/*****************************************************************************/
3250
 
3251
static void stli_onbedisable(stlibrd_t *brdp)
3252
{
3253
#if DEBUG
3254
        printk("stli_onbedisable(brdp=%x)\n", (int) brdp);
3255
#endif
3256
        outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3257
}
3258
 
3259
/*****************************************************************************/
3260
 
3261
static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3262
{
3263
        void            *ptr;
3264
        unsigned char   val;
3265
 
3266
#if DEBUG
3267
        printk("stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
3268
                (int) brdp, (int) offset, line);
3269
#endif
3270
 
3271
        if (offset > brdp->memsize) {
3272
                printk("STALLION: shared memory pointer=%x out of range at "
3273
                        "line=%d(%d), brd=%d\n", (int) offset, line,
3274
                        __LINE__, brdp->brdnr);
3275
                ptr = 0;
3276
                val = 0;
3277
        } else {
3278
                ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
3279
                if (offset < ONB_EIPAGESIZE)
3280
                        val = ONB_EIENABLE;
3281
                else
3282
                        val = ONB_EIENABLE | 0x40;
3283
        }
3284
        outb(val, (brdp->iobase + ONB_EICONFR));
3285
        return(ptr);
3286
}
3287
 
3288
/*****************************************************************************/
3289
 
3290
static void stli_onbereset(stlibrd_t *brdp)
3291
{
3292
        int     i;
3293
 
3294
#if DEBUG
3295
        printk("stli_onbereset(brdp=%x)\n", (int) brdp);
3296
#endif
3297
 
3298
        outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3299
        udelay(10);
3300
        outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3301
        for (i = 0; (i < 1000); i++)
3302
                udelay(1000);
3303
}
3304
 
3305
/*****************************************************************************/
3306
 
3307
/*
3308
 *      The following routines act on Brumby boards.
3309
 */
3310
 
3311
static void stli_bbyinit(stlibrd_t *brdp)
3312
{
3313
        int     i;
3314
 
3315
#if DEBUG
3316
        printk("stli_bbyinit(brdp=%d)\n", (int) brdp);
3317
#endif
3318
 
3319
        outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3320
        udelay(10);
3321
        outb(0, (brdp->iobase + BBY_ATCONFR));
3322
        for (i = 0; (i < 1000); i++)
3323
                udelay(1000);
3324
        outb(0x1, brdp->iobase);
3325
        udelay(1000);
3326
}
3327
 
3328
/*****************************************************************************/
3329
 
3330
static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3331
{
3332
        void            *ptr;
3333
        unsigned char   val;
3334
 
3335
#if DEBUG
3336
        printk("stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3337
                (int) offset);
3338
#endif
3339
 
3340
        if (offset > brdp->memsize) {
3341
                printk("STALLION: shared memory pointer=%x out of range at "
3342
                        "line=%d(%d), brd=%d\n", (int) offset, line,
3343
                        __LINE__, brdp->brdnr);
3344
                ptr = 0;
3345
                val = 0;
3346
        } else {
3347
                ptr = brdp->membase + (offset % BBY_PAGESIZE);
3348
                val = (unsigned char) (offset / BBY_PAGESIZE);
3349
        }
3350
        outb(val, (brdp->iobase + BBY_ATCONFR));
3351
        return(ptr);
3352
}
3353
 
3354
/*****************************************************************************/
3355
 
3356
static void stli_bbyreset(stlibrd_t *brdp)
3357
{
3358
        int     i;
3359
 
3360
#if DEBUG
3361
        printk("stli_bbyreset(brdp=%x)\n", (int) brdp);
3362
#endif
3363
 
3364
        outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3365
        udelay(10);
3366
        outb(0, (brdp->iobase + BBY_ATCONFR));
3367
        for (i = 0; (i < 1000); i++)
3368
                udelay(1000);
3369
}
3370
 
3371
/*****************************************************************************/
3372
 
3373
/*
3374
 *      The following routines act on original old Stallion boards.
3375
 */
3376
 
3377
static void stli_stalinit(stlibrd_t *brdp)
3378
{
3379
        int     i;
3380
 
3381
#if DEBUG
3382
        printk("stli_stalinit(brdp=%d)\n", (int) brdp);
3383
#endif
3384
 
3385
        outb(0x1, brdp->iobase);
3386
        for (i = 0; (i < 1000); i++)
3387
                udelay(1000);
3388
}
3389
 
3390
/*****************************************************************************/
3391
 
3392
static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3393
{
3394
        void    *ptr;
3395
 
3396
#if DEBUG
3397
        printk("stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3398
                (int) offset);
3399
#endif
3400
 
3401
        if (offset > brdp->memsize) {
3402
                printk("STALLION: shared memory pointer=%x out of range at "
3403
                        "line=%d(%d), brd=%d\n", (int) offset, line,
3404
                        __LINE__, brdp->brdnr);
3405
                ptr = 0;
3406
        } else {
3407
                ptr = brdp->membase + (offset % STAL_PAGESIZE);
3408
        }
3409
        return(ptr);
3410
}
3411
 
3412
/*****************************************************************************/
3413
 
3414
static void stli_stalreset(stlibrd_t *brdp)
3415
{
3416
        volatile unsigned long  *vecp;
3417
        int                     i;
3418
 
3419
#if DEBUG
3420
        printk("stli_stalreset(brdp=%x)\n", (int) brdp);
3421
#endif
3422
 
3423
        vecp = (volatile unsigned long *) (brdp->membase + 0x30);
3424
        *vecp = 0xffff0000;
3425
        outb(0, brdp->iobase);
3426
        for (i = 0; (i < 1000); i++)
3427
                udelay(1000);
3428
}
3429
 
3430
/*****************************************************************************/
3431
 
3432
/*
3433
 *      Try to find an ECP board and initialize it. This handles only ECP
3434
 *      board types.
3435
 */
3436
 
3437
static inline int stli_initecp(stlibrd_t *brdp)
3438
{
3439
        cdkecpsig_t     sig;
3440
        cdkecpsig_t     *sigsp;
3441
        unsigned int    status, nxtid;
3442
        char            *name;
3443
        int             panelnr, nrports;
3444
 
3445
#if DEBUG
3446
        printk("stli_initecp(brdp=%x)\n", (int) brdp);
3447
#endif
3448
 
3449
/*
3450
 *      Do a basic sanity check on the IO and memory addresses.
3451
 */
3452
        if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3453
                return(-ENODEV);
3454
 
3455
        brdp->iosize = ECP_IOSIZE;
3456
        if (check_region(brdp->iobase, brdp->iosize))
3457
                printk("STALLION: Warning, unit %d I/O address %x conflicts "
3458
                        "with another device\n", brdp->brdnr, brdp->iobase);
3459
 
3460
/*
3461
 *      Based on the specific board type setup the common vars to access
3462
 *      and enable shared memory. Set all board specific information now
3463
 *      as well.
3464
 */
3465
        switch (brdp->brdtype) {
3466
        case BRD_ECP:
3467
                brdp->membase = (void *) brdp->memaddr;
3468
                brdp->memsize = ECP_MEMSIZE;
3469
                brdp->pagesize = ECP_ATPAGESIZE;
3470
                brdp->init = stli_ecpinit;
3471
                brdp->enable = stli_ecpenable;
3472
                brdp->reenable = stli_ecpenable;
3473
                brdp->disable = stli_ecpdisable;
3474
                brdp->getmemptr = stli_ecpgetmemptr;
3475
                brdp->intr = stli_ecpintr;
3476
                brdp->reset = stli_ecpreset;
3477
                name = "serial(EC8/64)";
3478
                break;
3479
 
3480
        case BRD_ECPE:
3481
                brdp->membase = (void *) brdp->memaddr;
3482
                brdp->memsize = ECP_MEMSIZE;
3483
                brdp->pagesize = ECP_EIPAGESIZE;
3484
                brdp->init = stli_ecpeiinit;
3485
                brdp->enable = stli_ecpeienable;
3486
                brdp->reenable = stli_ecpeienable;
3487
                brdp->disable = stli_ecpeidisable;
3488
                brdp->getmemptr = stli_ecpeigetmemptr;
3489
                brdp->intr = stli_ecpintr;
3490
                brdp->reset = stli_ecpeireset;
3491
                name = "serial(EC8/64-EI)";
3492
                break;
3493
 
3494
        case BRD_ECPMC:
3495
                brdp->membase = (void *) brdp->memaddr;
3496
                brdp->memsize = ECP_MEMSIZE;
3497
                brdp->pagesize = ECP_MCPAGESIZE;
3498
                brdp->init = NULL;
3499
                brdp->enable = stli_ecpmcenable;
3500
                brdp->reenable = stli_ecpmcenable;
3501
                brdp->disable = stli_ecpmcdisable;
3502
                brdp->getmemptr = stli_ecpmcgetmemptr;
3503
                brdp->intr = stli_ecpintr;
3504
                brdp->reset = stli_ecpmcreset;
3505
                name = "serial(EC8/64-MCA)";
3506
                break;
3507
 
3508
        default:
3509
                return(-EINVAL);
3510
        }
3511
 
3512
/*
3513
 *      The per-board operations structure is all set up, so now let's go
3514
 *      and get the board operational. Firstly initialize board configuration
3515
 *      registers. Then if we are using the higher 1Mb support then set up
3516
 *      the memory mapping info so we can get at the boards shared memory.
3517
 */
3518
        EBRDINIT(brdp);
3519
 
3520
        if (brdp->memaddr > 0x100000) {
3521
                brdp->membase = vremap(brdp->memaddr, brdp->memsize);
3522
                if (brdp->membase == (void *) NULL)
3523
                        return(-ENOMEM);
3524
        }
3525
 
3526
/*
3527
 *      Now that all specific code is set up, enable the shared memory and
3528
 *      look for the a signature area that will tell us exactly what board
3529
 *      this is, and what it is connected to it.
3530
 */
3531
        EBRDENABLE(brdp);
3532
        sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3533
        memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
3534
        EBRDDISABLE(brdp);
3535
 
3536
#if 0
3537
        printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
3538
                __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
3539
                (int) sig.panelid[1], (int) sig.panelid[2],
3540
                (int) sig.panelid[3], (int) sig.panelid[4],
3541
                (int) sig.panelid[5], (int) sig.panelid[6],
3542
                (int) sig.panelid[7]);
3543
#endif
3544
 
3545
        if (sig.magic != ECP_MAGIC)
3546
                return(-ENODEV);
3547
 
3548
/*
3549
 *      Scan through the signature looking at the panels connected to the
3550
 *      board. Calculate the total number of ports as we go.
3551
 */
3552
        for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
3553
                status = sig.panelid[nxtid];
3554
                if ((status & ECH_PNLIDMASK) != nxtid)
3555
                        break;
3556
 
3557
                brdp->panelids[panelnr] = status;
3558
                nrports = (status & ECH_PNL16PORT) ? 16 : 8;
3559
                if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
3560
                        nxtid++;
3561
                brdp->panels[panelnr] = nrports;
3562
                brdp->nrports += nrports;
3563
                nxtid++;
3564
                brdp->nrpanels++;
3565
        }
3566
 
3567
        request_region(brdp->iobase, brdp->iosize, name);
3568
        brdp->state |= BST_FOUND;
3569
        return(0);
3570
}
3571
 
3572
/*****************************************************************************/
3573
 
3574
/*
3575
 *      Try to find an ONboard, Brumby or Stallion board and initialize it.
3576
 *      This handles only these board types.
3577
 */
3578
 
3579
static inline int stli_initonb(stlibrd_t *brdp)
3580
{
3581
        cdkonbsig_t     sig;
3582
        cdkonbsig_t     *sigsp;
3583
        char            *name;
3584
        int             i;
3585
 
3586
#if DEBUG
3587
        printk("stli_initonb(brdp=%x)\n", (int) brdp);
3588
#endif
3589
 
3590
/*
3591
 *      Do a basic sanity check on the IO and memory addresses.
3592
 */
3593
        if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3594
                return(-ENODEV);
3595
 
3596
        brdp->iosize = ONB_IOSIZE;
3597
        if (check_region(brdp->iobase, brdp->iosize))
3598
                printk("STALLION: Warning, unit %d I/O address %x conflicts "
3599
                        "with another device\n", brdp->brdnr, brdp->iobase);
3600
 
3601
/*
3602
 *      Based on the specific board type setup the common vars to access
3603
 *      and enable shared memory. Set all board specific information now
3604
 *      as well.
3605
 */
3606
        switch (brdp->brdtype) {
3607
        case BRD_ONBOARD:
3608
        case BRD_ONBOARD32:
3609
        case BRD_ONBOARD2:
3610
        case BRD_ONBOARD2_32:
3611
        case BRD_ONBOARDRS:
3612
                brdp->membase = (void *) brdp->memaddr;
3613
                brdp->memsize = ONB_MEMSIZE;
3614
                brdp->pagesize = ONB_ATPAGESIZE;
3615
                brdp->init = stli_onbinit;
3616
                brdp->enable = stli_onbenable;
3617
                brdp->reenable = stli_onbenable;
3618
                brdp->disable = stli_onbdisable;
3619
                brdp->getmemptr = stli_onbgetmemptr;
3620
                brdp->intr = stli_ecpintr;
3621
                brdp->reset = stli_onbreset;
3622
                if (brdp->memaddr > 0x100000)
3623
                        brdp->enabval = ONB_MEMENABHI;
3624
                else
3625
                        brdp->enabval = ONB_MEMENABLO;
3626
                name = "serial(ONBoard)";
3627
                break;
3628
 
3629
        case BRD_ONBOARDE:
3630
                brdp->membase = (void *) brdp->memaddr;
3631
                brdp->memsize = ONB_EIMEMSIZE;
3632
                brdp->pagesize = ONB_EIPAGESIZE;
3633
                brdp->init = stli_onbeinit;
3634
                brdp->enable = stli_onbeenable;
3635
                brdp->reenable = stli_onbeenable;
3636
                brdp->disable = stli_onbedisable;
3637
                brdp->getmemptr = stli_onbegetmemptr;
3638
                brdp->intr = stli_ecpintr;
3639
                brdp->reset = stli_onbereset;
3640
                name = "serial(ONBoard/E)";
3641
                break;
3642
 
3643
        case BRD_BRUMBY4:
3644
        case BRD_BRUMBY8:
3645
        case BRD_BRUMBY16:
3646
                brdp->membase = (void *) brdp->memaddr;
3647
                brdp->memsize = BBY_MEMSIZE;
3648
                brdp->pagesize = BBY_PAGESIZE;
3649
                brdp->init = stli_bbyinit;
3650
                brdp->enable = NULL;
3651
                brdp->reenable = NULL;
3652
                brdp->disable = NULL;
3653
                brdp->getmemptr = stli_bbygetmemptr;
3654
                brdp->intr = stli_ecpintr;
3655
                brdp->reset = stli_bbyreset;
3656
                name = "serial(Brumby)";
3657
                break;
3658
 
3659
        case BRD_STALLION:
3660
                brdp->membase = (void *) brdp->memaddr;
3661
                brdp->memsize = STAL_MEMSIZE;
3662
                brdp->pagesize = STAL_PAGESIZE;
3663
                brdp->init = stli_stalinit;
3664
                brdp->enable = NULL;
3665
                brdp->reenable = NULL;
3666
                brdp->disable = NULL;
3667
                brdp->getmemptr = stli_stalgetmemptr;
3668
                brdp->intr = stli_ecpintr;
3669
                brdp->reset = stli_stalreset;
3670
                name = "serial(Stallion)";
3671
                break;
3672
 
3673
        default:
3674
                return(-EINVAL);
3675
        }
3676
 
3677
/*
3678
 *      The per-board operations structure is all set up, so now let's go
3679
 *      and get the board operational. Firstly initialize board configuration
3680
 *      registers. Then if we are using the higher 1Mb support then set up
3681
 *      the memory mapping info so we can get at the boards shared memory.
3682
 */
3683
        EBRDINIT(brdp);
3684
 
3685
        if (brdp->memaddr > 0x100000) {
3686
                brdp->membase = vremap(brdp->memaddr, brdp->memsize);
3687
                if (brdp->membase == (void *) NULL)
3688
                        return(-ENOMEM);
3689
        }
3690
 
3691
/*
3692
 *      Now that all specific code is set up, enable the shared memory and
3693
 *      look for the a signature area that will tell us exactly what board
3694
 *      this is, and how many ports.
3695
 */
3696
        EBRDENABLE(brdp);
3697
        sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3698
        memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
3699
        EBRDDISABLE(brdp);
3700
 
3701
#if 0
3702
        printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
3703
                __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
3704
                sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
3705
#endif
3706
 
3707
        if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
3708
            (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
3709
                return(-ENODEV);
3710
 
3711
/*
3712
 *      Scan through the signature alive mask and calculate how many ports
3713
 *      there are on this board.
3714
 */
3715
        brdp->nrpanels = 1;
3716
        if (sig.amask1) {
3717
                brdp->nrports = 32;
3718
        } else {
3719
                for (i = 0; (i < 16); i++) {
3720
                        if (((sig.amask0 << i) & 0x8000) == 0)
3721
                                break;
3722
                }
3723
                brdp->nrports = i;
3724
        }
3725
        brdp->panels[0] = brdp->nrports;
3726
 
3727
        request_region(brdp->iobase, brdp->iosize, name);
3728
        brdp->state |= BST_FOUND;
3729
        return(0);
3730
}
3731
 
3732
/*****************************************************************************/
3733
 
3734
/*
3735
 *      Start up a running board. This routine is only called after the
3736
 *      code has been down loaded to the board and is operational. It will
3737
 *      read in the memory map, and get the show on the road...
3738
 */
3739
 
3740
static int stli_startbrd(stlibrd_t *brdp)
3741
{
3742
        volatile cdkhdr_t       *hdrp;
3743
        volatile cdkmem_t       *memp;
3744
        volatile cdkasy_t       *ap;
3745
        unsigned long           flags;
3746
        stliport_t              *portp;
3747
        int                     portnr, nrdevs, i, rc;
3748
 
3749
#if DEBUG
3750
        printk("stli_startbrd(brdp=%x)\n", (int) brdp);
3751
#endif
3752
 
3753
        rc = 0;
3754
 
3755
        save_flags(flags);
3756
        cli();
3757
        EBRDENABLE(brdp);
3758
        hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3759
        nrdevs = hdrp->nrdevs;
3760
 
3761
#if 0
3762
        printk("%s(%d): CDK version %d.%d.%d --> "
3763
                "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
3764
                 __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification,
3765
                 hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp,
3766
                 (int) hdrp->slavep);
3767
#endif
3768
 
3769
        if (nrdevs < (brdp->nrports + 1)) {
3770
                printk("STALLION: slave failed to allocate memory for all "
3771
                        "devices, devices=%d\n", nrdevs);
3772
                brdp->nrports = nrdevs - 1;
3773
        }
3774
        brdp->nrdevs = nrdevs;
3775
        brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
3776
        brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
3777
        brdp->bitsize = (nrdevs + 7) / 8;
3778
        memp = (volatile cdkmem_t *) hdrp->memp;
3779
        if (((unsigned long) memp) > brdp->memsize) {
3780
                printk("STALLION: corrupted shared memory region?\n");
3781
                rc = -EIO;
3782
                goto stli_donestartup;
3783
        }
3784
        memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp);
3785
        if (memp->dtype != TYP_ASYNCTRL) {
3786
                printk("STALLION: no slave control device found\n");
3787
                goto stli_donestartup;
3788
        }
3789
        memp++;
3790
 
3791
/*
3792
 *      Cycle through memory allocation of each port. We are guaranteed to
3793
 *      have all ports inside the first page of slave window, so no need to
3794
 *      change pages while reading memory map.
3795
 */
3796
        for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
3797
                if (memp->dtype != TYP_ASYNC)
3798
                        break;
3799
                portp = brdp->ports[portnr];
3800
                if (portp == (stliport_t *) NULL)
3801
                        break;
3802
                portp->devnr = i;
3803
                portp->addr = memp->offset;
3804
                portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
3805
                portp->portidx = (unsigned char) (i / 8);
3806
                portp->portbit = (unsigned char) (0x1 << (i % 8));
3807
        }
3808
 
3809
        hdrp->slavereq = 0xff;
3810
 
3811
/*
3812
 *      For each port setup a local copy of the RX and TX buffer offsets
3813
 *      and sizes. We do this separate from the above, because we need to
3814
 *      move the shared memory page...
3815
 */
3816
        for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
3817
                portp = brdp->ports[portnr];
3818
                if (portp == (stliport_t *) NULL)
3819
                        break;
3820
                if (portp->addr == 0)
3821
                        break;
3822
                ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
3823
                if (ap != (volatile cdkasy_t *) NULL) {
3824
                        portp->rxsize = ap->rxq.size;
3825
                        portp->txsize = ap->txq.size;
3826
                        portp->rxoffset = ap->rxq.offset;
3827
                        portp->txoffset = ap->txq.offset;
3828
                }
3829
        }
3830
 
3831
stli_donestartup:
3832
        EBRDDISABLE(brdp);
3833
        restore_flags(flags);
3834
 
3835
        if (rc == 0)
3836
                brdp->state |= BST_STARTED;
3837
 
3838
        if (! stli_timeron) {
3839
                stli_timeron++;
3840
                stli_timerlist.expires = STLI_TIMEOUT;
3841
                add_timer(&stli_timerlist);
3842
        }
3843
 
3844
        return(rc);
3845
}
3846
 
3847
/*****************************************************************************/
3848
 
3849
/*
3850
 *      Probe and initialize the specified board.
3851
 */
3852
 
3853
static int stli_brdinit(stlibrd_t *brdp)
3854
{
3855
#if DEBUG
3856
        printk("stli_brdinit(brdp=%x)\n", (int) brdp);
3857
#endif
3858
 
3859
        stli_brds[brdp->brdnr] = brdp;
3860
 
3861
        switch (brdp->brdtype) {
3862
        case BRD_ECP:
3863
        case BRD_ECPE:
3864
        case BRD_ECPMC:
3865
                stli_initecp(brdp);
3866
                break;
3867
        case BRD_ONBOARD:
3868
        case BRD_ONBOARDE:
3869
        case BRD_ONBOARD2:
3870
        case BRD_ONBOARD32:
3871
        case BRD_ONBOARD2_32:
3872
        case BRD_ONBOARDRS:
3873
        case BRD_BRUMBY4:
3874
        case BRD_BRUMBY8:
3875
        case BRD_BRUMBY16:
3876
        case BRD_STALLION:
3877
                stli_initonb(brdp);
3878
                break;
3879
        case BRD_EASYIO:
3880
        case BRD_ECH:
3881
        case BRD_ECHMC:
3882
        case BRD_ECHPCI:
3883
                printk("STALLION: %s board type not supported in this driver\n",
3884
                        stli_brdnames[brdp->brdtype]);
3885
                return(ENODEV);
3886
        default:
3887
                printk("STALLION: unit=%d is unknown board type=%d\n",
3888
                        brdp->brdnr, brdp->brdtype);
3889
                return(ENODEV);
3890
        }
3891
 
3892
        if ((brdp->state & BST_FOUND) == 0) {
3893
                printk("STALLION: %s board not found, unit=%d io=%x mem=%x\n",
3894
                        stli_brdnames[brdp->brdtype], brdp->brdnr,
3895
                        brdp->iobase, (int) brdp->memaddr);
3896
                return(ENODEV);
3897
        }
3898
 
3899
        stli_initports(brdp);
3900
        printk("STALLION: %s found, unit=%d io=%x mem=%x "
3901
                "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
3902
                brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
3903
                brdp->nrpanels, brdp->nrports);
3904
        return(0);
3905
}
3906
 
3907
/*****************************************************************************/
3908
 
3909
/*
3910
 *      Probe around trying to find where the EISA boards shared memory
3911
 *      might be. This is a bit if hack, but it is the best we can do.
3912
 */
3913
 
3914
static inline int stli_eisamemprobe(stlibrd_t *brdp)
3915
{
3916
        cdkecpsig_t     ecpsig, *ecpsigp;
3917
        cdkonbsig_t     onbsig, *onbsigp;
3918
        int             i, foundit;
3919
 
3920
#if DEBUG
3921
        printk("stli_eisamemprobe(brdp=%x)\n", (int) brdp);
3922
#endif
3923
 
3924
/*
3925
 *      First up we reset the board, to get it into a known state. There
3926
 *      is only 2 board types here we need to worry about. Don;t use the
3927
 *      standard board init routine here, it programs up the shared
3928
 *      memory address, and we don't know it yet...
3929
 */
3930
        if (brdp->brdtype == BRD_ECPE) {
3931
                outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3932
                outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3933
                udelay(10);
3934
                outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3935
                udelay(500);
3936
                stli_ecpeienable(brdp);
3937
        } else if (brdp->brdtype == BRD_ONBOARDE) {
3938
                outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3939
                outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3940
                udelay(10);
3941
                outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3942
                for (i = 0; (i < 100); i++)
3943
                        udelay(1000);
3944
                outb(0x1, brdp->iobase);
3945
                udelay(1000);
3946
                stli_onbeenable(brdp);
3947
        } else {
3948
                return(-ENODEV);
3949
        }
3950
 
3951
        foundit = 0;
3952
        brdp->memsize = ECP_MEMSIZE;
3953
 
3954
/*
3955
 *      Board shared memory is enabled, so now we have a poke around and
3956
 *      see if we can find it.
3957
 */
3958
        for (i = 0; (i < stli_eisamempsize); i++) {
3959
                brdp->memaddr = stli_eisamemprobeaddrs[i];
3960
                brdp->membase = (void *) brdp->memaddr;
3961
                if (brdp->memaddr > 0x100000) {
3962
                        brdp->membase = vremap(brdp->memaddr, brdp->memsize);
3963
                        if (brdp->membase == (void *) NULL)
3964
                                continue;
3965
                }
3966
                if (brdp->brdtype == BRD_ECPE) {
3967
                        ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp,
3968
                                CDK_SIGADDR, __LINE__);
3969
                        memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
3970
                        if (ecpsig.magic == ECP_MAGIC)
3971
                                foundit = 1;
3972
                } else {
3973
                        onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp,
3974
                                CDK_SIGADDR, __LINE__);
3975
                        memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t));
3976
                        if ((onbsig.magic0 == ONB_MAGIC0) &&
3977
                            (onbsig.magic1 == ONB_MAGIC1) &&
3978
                            (onbsig.magic2 == ONB_MAGIC2) &&
3979
                            (onbsig.magic3 == ONB_MAGIC3))
3980
                                foundit = 1;
3981
                }
3982
                if (brdp->memaddr >= 0x100000)
3983
                        vfree(brdp->membase);
3984
                if (foundit)
3985
                        break;
3986
        }
3987
 
3988
/*
3989
 *      Regardless of whether we found the shared memory or not we must
3990
 *      disable the region. After that return success or failure.
3991
 */
3992
        if (brdp->brdtype == BRD_ECPE)
3993
                stli_ecpeidisable(brdp);
3994
        else
3995
                stli_onbedisable(brdp);
3996
 
3997
        if (! foundit) {
3998
                brdp->memaddr = 0;
3999
                brdp->membase = 0;
4000
                printk("STALLION: failed to probe shared memory region for "
4001
                        "%s in EISA slot=%d\n", stli_brdnames[brdp->brdtype],
4002
                        (brdp->iobase >> 12));
4003
                return(-ENODEV);
4004
        }
4005
        return(0);
4006
}
4007
 
4008
/*****************************************************************************/
4009
 
4010
/*
4011
 *      Probe around and try to find any EISA boards in system. The biggest
4012
 *      problem here is finding out what memory address is associated with
4013
 *      an EISA board after it is found. The registers of the ECPE and
4014
 *      ONboardE are not readable - so we can't read them from there. We
4015
 *      don't have access to the EISA CMOS (or EISA BIOS) so we don't
4016
 *      actually have any way to find out the real value. The best we can
4017
 *      do is go probing around in the usual places hoping we can find it.
4018
 */
4019
 
4020
static inline int stli_findeisabrds()
4021
{
4022
        stlibrd_t       *brdp;
4023
        unsigned int    iobase, eid;
4024
        int             i;
4025
 
4026
#if DEBUG
4027
        printk("stli_findeisabrds()\n");
4028
#endif
4029
 
4030
/*
4031
 *      Firstly check if this is an EISA system. Do this by probing for
4032
 *      the system board EISA ID. If this is not an EISA system then
4033
 *      don't bother going any further!
4034
 */
4035
        outb(0xff, 0xc80);
4036
        if (inb(0xc80) == 0xff)
4037
                return(0);
4038
 
4039
/*
4040
 *      Looks like an EISA system, so go searching for EISA boards.
4041
 */
4042
        for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
4043
                outb(0xff, (iobase + 0xc80));
4044
                eid = inb(iobase + 0xc80);
4045
                eid |= inb(iobase + 0xc81) << 8;
4046
                if (eid != STL_EISAID)
4047
                        continue;
4048
 
4049
/*
4050
 *              We have found a board. Need to check if this board was
4051
 *              statically configured already (just in case!).
4052
 */
4053
                for (i = 0; (i < STL_MAXBRDS); i++) {
4054
                        brdp = stli_brds[i];
4055
                        if (brdp == (stlibrd_t *) NULL)
4056
                                continue;
4057
                        if (brdp->iobase == iobase)
4058
                                break;
4059
                }
4060
                if (i < STL_MAXBRDS)
4061
                        continue;
4062
 
4063
/*
4064
 *              Check that we have room for this new board in our board
4065
 *              info table.
4066
 */
4067
                if (stli_nrbrds >= STL_MAXBRDS) {
4068
                        printk("STALLION: no room for more probed boards, "
4069
                                "maximum supported %d\n", STL_MAXBRDS);
4070
                        break;
4071
                }
4072
 
4073
/*
4074
 *              We have found a Stallion board and it is not configured already.
4075
 *              Allocate a board structure and initialize it.
4076
 */
4077
                brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
4078
                if (brdp == (stlibrd_t *) NULL) {
4079
                        printk("STALLION: failed to allocate memory "
4080
                                "(size=%d)\n", sizeof(stlibrd_t));
4081
                        return(-ENOMEM);
4082
                }
4083
                memset(brdp, 0, sizeof(stlibrd_t));
4084
 
4085
                brdp->magic = STLI_BOARDMAGIC;
4086
                brdp->brdnr = stli_nrbrds++;
4087
                eid = inb(iobase + 0xc82);
4088
                if (eid == ECP_EISAID)
4089
                        brdp->brdtype = BRD_ECPE;
4090
                else if (eid == ONB_EISAID)
4091
                        brdp->brdtype = BRD_ONBOARDE;
4092
                else
4093
                        brdp->brdtype = BRD_UNKNOWN;
4094
                brdp->iobase = iobase;
4095
                outb(0x1, (iobase + 0xc84));
4096
                if (stli_eisamemprobe(brdp))
4097
                        outb(0, (iobase + 0xc84));
4098
                stli_brdinit(brdp);
4099
        }
4100
 
4101
        return(0);
4102
}
4103
 
4104
/*****************************************************************************/
4105
 
4106
/*
4107
 *      Scan through all the boards in the configuration and see what we
4108
 *      can find.
4109
 */
4110
 
4111
static inline int stli_initbrds()
4112
{
4113
        stlibrd_t       *brdp, *nxtbrdp;
4114
        stlconf_t       *confp;
4115
        int             i, j;
4116
 
4117
#if DEBUG
4118
        printk("stli_initbrds()\n");
4119
#endif
4120
 
4121
        if (stli_nrbrds > STL_MAXBRDS) {
4122
                printk("STALLION: too many boards in configuration table, "
4123
                        "truncating to %d\n", STL_MAXBRDS);
4124
                stli_nrbrds = STL_MAXBRDS;
4125
        }
4126
 
4127
/*
4128
 *      Firstly scan the list of static boards configured. Allocate
4129
 *      resources and initialize the boards as found.
4130
 */
4131
        for (i = 0; (i < stli_nrbrds); i++) {
4132
                confp = &stli_brdconf[i];
4133
                brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
4134
                if (brdp == (stlibrd_t *) NULL) {
4135
                        printk("STALLION: failed to allocate memory "
4136
                                "(size=%d)\n", sizeof(stlibrd_t));
4137
                        return(-ENOMEM);
4138
                }
4139
                memset(brdp, 0, sizeof(stlibrd_t));
4140
 
4141
                brdp->magic = STLI_BOARDMAGIC;
4142
                brdp->brdnr = i;
4143
                brdp->brdtype = confp->brdtype;
4144
                brdp->iobase = confp->ioaddr1;
4145
                brdp->memaddr = confp->memaddr;
4146
                stli_brdinit(brdp);
4147
        }
4148
 
4149
/*
4150
 *      Now go probing for EISA boards if enabled.
4151
 */
4152
        if (stli_eisaprobe)
4153
                stli_findeisabrds();
4154
 
4155
/*
4156
 *      All found boards are initialized. Now for a little optimization, if
4157
 *      no boards are sharing the "shared memory" regions then we can just
4158
 *      leave them all enabled. This is in fact the usual case.
4159
 */
4160
        stli_shared = 0;
4161
        if (stli_nrbrds > 1) {
4162
                for (i = 0; (i < stli_nrbrds); i++) {
4163
                        brdp = stli_brds[i];
4164
                        if (brdp == (stlibrd_t *) NULL)
4165
                                continue;
4166
                        for (j = i + 1; (j < stli_nrbrds); j++) {
4167
                                nxtbrdp = stli_brds[j];
4168
                                if (nxtbrdp == (stlibrd_t *) NULL)
4169
                                        continue;
4170
                                if ((brdp->membase >= nxtbrdp->membase) &&
4171
                                    (brdp->membase <= (nxtbrdp->membase +
4172
                                    nxtbrdp->memsize - 1))) {
4173
                                        stli_shared++;
4174
                                        break;
4175
                                }
4176
                        }
4177
                }
4178
        }
4179
 
4180
        if (stli_shared == 0) {
4181
                for (i = 0; (i < stli_nrbrds); i++) {
4182
                        brdp = stli_brds[i];
4183
                        if (brdp == (stlibrd_t *) NULL)
4184
                                continue;
4185
                        if (brdp->state & BST_FOUND) {
4186
                                EBRDENABLE(brdp);
4187
                                brdp->enable = NULL;
4188
                                brdp->disable = NULL;
4189
                        }
4190
                }
4191
        }
4192
 
4193
        return(0);
4194
}
4195
 
4196
/*****************************************************************************/
4197
 
4198
/*
4199
 *      Code to handle an "staliomem" read operation. This device is the
4200
 *      contents of the board shared memory. It is used for down loading
4201
 *      the slave image (and debugging :-)
4202
 */
4203
 
4204
static int stli_memread(struct inode *ip, struct file *fp, char *buf, int count)
4205
{
4206
        unsigned long   flags;
4207
        void            *memptr;
4208
        stlibrd_t       *brdp;
4209
        int             brdnr, size, n;
4210
 
4211
#if DEBUG
4212
        printk("stli_memread(ip=%x,fp=%x,buf=%x,count=%d)\n", (int) ip,
4213
                (int) fp, (int) buf, count);
4214
#endif
4215
 
4216
        brdnr = MINOR(ip->i_rdev);
4217
        if (brdnr >= stli_nrbrds)
4218
                return(-ENODEV);
4219
        brdp = stli_brds[brdnr];
4220
        if (brdp == (stlibrd_t *) NULL)
4221
                return(-ENODEV);
4222
        if (brdp->state == 0)
4223
                return(-ENODEV);
4224
        if (fp->f_pos >= brdp->memsize)
4225
                return(0);
4226
 
4227
        size = MIN(count, (brdp->memsize - fp->f_pos));
4228
 
4229
        save_flags(flags);
4230
        cli();
4231
        EBRDENABLE(brdp);
4232
        while (size > 0) {
4233
                memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
4234
                n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
4235
                memcpy_tofs(buf, memptr, n);
4236
                fp->f_pos += n;
4237
                buf += n;
4238
                size -= n;
4239
        }
4240
        EBRDDISABLE(brdp);
4241
        restore_flags(flags);
4242
 
4243
        return(count);
4244
}
4245
 
4246
/*****************************************************************************/
4247
 
4248
/*
4249
 *      Code to handle an "staliomem" write operation. This device is the
4250
 *      contents of the board shared memory. It is used for down loading
4251
 *      the slave image (and debugging :-)
4252
 */
4253
 
4254
static int stli_memwrite(struct inode *ip, struct file *fp, const char *buf, int count)
4255
{
4256
        unsigned long   flags;
4257
        void            *memptr;
4258
        stlibrd_t       *brdp;
4259
        char            *chbuf;
4260
        int             brdnr, size, n;
4261
 
4262
#if DEBUG
4263
        printk("stli_memwrite(ip=%x,fp=%x,buf=%x,count=%x)\n", (int) ip,
4264
                (int) fp, (int) buf, count);
4265
#endif
4266
 
4267
        brdnr = MINOR(ip->i_rdev);
4268
        if (brdnr >= stli_nrbrds)
4269
                return(-ENODEV);
4270
        brdp = stli_brds[brdnr];
4271
        if (brdp == (stlibrd_t *) NULL)
4272
                return(-ENODEV);
4273
        if (brdp->state == 0)
4274
                return(-ENODEV);
4275
        if (fp->f_pos >= brdp->memsize)
4276
                return(0);
4277
 
4278
        chbuf = (char *) buf;
4279
        size = MIN(count, (brdp->memsize - fp->f_pos));
4280
 
4281
        save_flags(flags);
4282
        cli();
4283
        EBRDENABLE(brdp);
4284
        while (size > 0) {
4285
                memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
4286
                n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
4287
                memcpy_fromfs(memptr, chbuf, n);
4288
                fp->f_pos += n;
4289
                chbuf += n;
4290
                size -= n;
4291
        }
4292
        EBRDDISABLE(brdp);
4293
        restore_flags(flags);
4294
 
4295
        return(count);
4296
}
4297
 
4298
/*****************************************************************************/
4299
 
4300
/*
4301
 *      Return the board stats structure to user app.
4302
 */
4303
 
4304
static int stli_getbrdstats(combrd_t *bp)
4305
{
4306
        stlibrd_t       *brdp;
4307
        int             i;
4308
 
4309
        memcpy_fromfs(&stli_brdstats, bp, sizeof(combrd_t));
4310
        if (stli_brdstats.brd >= STL_MAXBRDS)
4311
                return(-ENODEV);
4312
        brdp = stli_brds[stli_brdstats.brd];
4313
        if (brdp == (stlibrd_t *) NULL)
4314
                return(-ENODEV);
4315
 
4316
        memset(&stli_brdstats, 0, sizeof(combrd_t));
4317
        stli_brdstats.brd = brdp->brdnr;
4318
        stli_brdstats.type = brdp->brdtype;
4319
        stli_brdstats.hwid = 0;
4320
        stli_brdstats.state = brdp->state;
4321
        stli_brdstats.ioaddr = brdp->iobase;
4322
        stli_brdstats.memaddr = brdp->memaddr;
4323
        stli_brdstats.nrpanels = brdp->nrpanels;
4324
        stli_brdstats.nrports = brdp->nrports;
4325
        for (i = 0; (i < brdp->nrpanels); i++) {
4326
                stli_brdstats.panels[i].panel = i;
4327
                stli_brdstats.panels[i].hwid = brdp->panelids[i];
4328
                stli_brdstats.panels[i].nrports = brdp->panels[i];
4329
        }
4330
 
4331
        memcpy_tofs(bp, &stli_brdstats, sizeof(combrd_t));
4332
        return(0);
4333
}
4334
 
4335
/*****************************************************************************/
4336
 
4337
/*
4338
 *      Resolve the referenced port number into a port struct pointer.
4339
 */
4340
 
4341
static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4342
{
4343
        stlibrd_t       *brdp;
4344
        int             i;
4345
 
4346
        if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
4347
                return((stliport_t *) NULL);
4348
        brdp = stli_brds[brdnr];
4349
        if (brdp == (stlibrd_t *) NULL)
4350
                return((stliport_t *) NULL);
4351
        for (i = 0; (i < panelnr); i++)
4352
                portnr += brdp->panels[i];
4353
        if ((portnr < 0) || (portnr >= brdp->nrports))
4354
                return((stliport_t *) NULL);
4355
        return(brdp->ports[portnr]);
4356
}
4357
 
4358
/*****************************************************************************/
4359
 
4360
/*
4361
 *      Return the port stats structure to user app. A NULL port struct
4362
 *      pointer passed in means that we need to find out from the app
4363
 *      what port to get stats for (used through board control device).
4364
 */
4365
 
4366
static int stli_portcmdstats(stliport_t *portp)
4367
{
4368
        unsigned long   flags;
4369
        stlibrd_t       *brdp;
4370
        int             rc;
4371
 
4372
        memset(&stli_comstats, 0, sizeof(comstats_t));
4373
 
4374
        if (portp == (stliport_t *) NULL)
4375
                return(-ENODEV);
4376
        brdp = stli_brds[portp->brdnr];
4377
        if (brdp == (stlibrd_t *) NULL)
4378
                return(-ENODEV);
4379
 
4380
        if (brdp->state & BST_STARTED) {
4381
                if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4382
                    &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
4383
                        return(rc);
4384
        } else {
4385
                memset(&stli_cdkstats, 0, sizeof(asystats_t));
4386
        }
4387
 
4388
        stli_comstats.brd = portp->brdnr;
4389
        stli_comstats.panel = portp->panelnr;
4390
        stli_comstats.port = portp->portnr;
4391
        stli_comstats.state = portp->state;
4392
        stli_comstats.flags = portp->flags;
4393
 
4394
        save_flags(flags);
4395
        cli();
4396
        if (portp->tty != (struct tty_struct *) NULL) {
4397
                if (portp->tty->driver_data == portp) {
4398
                        stli_comstats.ttystate = portp->tty->flags;
4399
                        stli_comstats.rxbuffered = portp->tty->flip.count;
4400
                        if (portp->tty->termios != (struct termios *) NULL) {
4401
                                stli_comstats.cflags = portp->tty->termios->c_cflag;
4402
                                stli_comstats.iflags = portp->tty->termios->c_iflag;
4403
                                stli_comstats.oflags = portp->tty->termios->c_oflag;
4404
                                stli_comstats.lflags = portp->tty->termios->c_lflag;
4405
                        }
4406
                }
4407
        }
4408
        restore_flags(flags);
4409
 
4410
        stli_comstats.txtotal = stli_cdkstats.txchars;
4411
        stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
4412
        stli_comstats.txbuffered = stli_cdkstats.txringq;
4413
        stli_comstats.rxbuffered += stli_cdkstats.rxringq;
4414
        stli_comstats.rxoverrun = stli_cdkstats.overruns;
4415
        stli_comstats.rxparity = stli_cdkstats.parity;
4416
        stli_comstats.rxframing = stli_cdkstats.framing;
4417
        stli_comstats.rxlost = stli_cdkstats.ringover;
4418
        stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
4419
        stli_comstats.txbreaks = stli_cdkstats.txbreaks;
4420
        stli_comstats.txxon = stli_cdkstats.txstart;
4421
        stli_comstats.txxoff = stli_cdkstats.txstop;
4422
        stli_comstats.rxxon = stli_cdkstats.rxstart;
4423
        stli_comstats.rxxoff = stli_cdkstats.rxstop;
4424
        stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
4425
        stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
4426
        stli_comstats.modem = stli_cdkstats.dcdcnt;
4427
        stli_comstats.hwid = stli_cdkstats.hwid;
4428
        stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4429
 
4430
        return(0);
4431
}
4432
 
4433
/*****************************************************************************/
4434
 
4435
/*
4436
 *      Return the port stats structure to user app. A NULL port struct
4437
 *      pointer passed in means that we need to find out from the app
4438
 *      what port to get stats for (used through board control device).
4439
 */
4440
 
4441
static int stli_getportstats(stliport_t *portp, comstats_t *cp)
4442
{
4443
        stlibrd_t       *brdp;
4444
        int             rc;
4445
 
4446
        if (portp == (stliport_t *) NULL) {
4447
                memcpy_fromfs(&stli_comstats, cp, sizeof(comstats_t));
4448
                portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4449
                        stli_comstats.port);
4450
                if (portp == (stliport_t *) NULL)
4451
                        return(-ENODEV);
4452
        }
4453
 
4454
        brdp = stli_brds[portp->brdnr];
4455
        if (brdp == (stlibrd_t *) NULL)
4456
                return(-ENODEV);
4457
 
4458
        if ((rc = stli_portcmdstats(portp)) < 0)
4459
                return(rc);
4460
 
4461
        memcpy_tofs(cp, &stli_comstats, sizeof(comstats_t));
4462
        return(0);
4463
}
4464
 
4465
/*****************************************************************************/
4466
 
4467
/*
4468
 *      Clear the port stats structure. We also return it zeroed out...
4469
 */
4470
 
4471
static int stli_clrportstats(stliport_t *portp, comstats_t *cp)
4472
{
4473
        stlibrd_t       *brdp;
4474
        int             rc;
4475
 
4476
        if (portp == (stliport_t *) NULL) {
4477
                memcpy_fromfs(&stli_comstats, cp, sizeof(comstats_t));
4478
                portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
4479
                        stli_comstats.port);
4480
                if (portp == (stliport_t *) NULL)
4481
                        return(-ENODEV);
4482
        }
4483
 
4484
        brdp = stli_brds[portp->brdnr];
4485
        if (brdp == (stlibrd_t *) NULL)
4486
                return(-ENODEV);
4487
 
4488
        if (brdp->state & BST_STARTED) {
4489
                if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, 0, 0, 0)) < 0)
4490
                        return(rc);
4491
        }
4492
 
4493
        memset(&stli_comstats, 0, sizeof(comstats_t));
4494
        stli_comstats.brd = portp->brdnr;
4495
        stli_comstats.panel = portp->panelnr;
4496
        stli_comstats.port = portp->portnr;
4497
 
4498
        memcpy_tofs(cp, &stli_comstats, sizeof(comstats_t));
4499
        return(0);
4500
}
4501
 
4502
/*****************************************************************************/
4503
 
4504
/*
4505
 *      Return the entire driver ports structure to a user app.
4506
 */
4507
 
4508
static int stli_getportstruct(unsigned long arg)
4509
{
4510
        stliport_t      *portp;
4511
 
4512
        memcpy_fromfs(&stli_dummyport, (void *) arg, sizeof(stliport_t));
4513
        portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
4514
                 stli_dummyport.portnr);
4515
        if (portp == (stliport_t *) NULL)
4516
                return(-ENODEV);
4517
        memcpy_tofs((void *) arg, portp, sizeof(stliport_t));
4518
        return(0);
4519
}
4520
 
4521
/*****************************************************************************/
4522
 
4523
/*
4524
 *      Return the entire driver board structure to a user app.
4525
 */
4526
 
4527
static int stli_getbrdstruct(unsigned long arg)
4528
{
4529
        stlibrd_t       *brdp;
4530
 
4531
        memcpy_fromfs(&stli_dummybrd, (void *) arg, sizeof(stlibrd_t));
4532
        if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
4533
                return(-ENODEV);
4534
        brdp = stli_brds[stli_dummybrd.brdnr];
4535
        if (brdp == (stlibrd_t *) NULL)
4536
                return(-ENODEV);
4537
        memcpy_tofs((void *) arg, brdp, sizeof(stlibrd_t));
4538
        return(0);
4539
}
4540
 
4541
/*****************************************************************************/
4542
 
4543
/*
4544
 *      Memory device open code. Need to keep track of opens and close
4545
 *      for module handling.
4546
 */
4547
 
4548
static int stli_memopen(struct inode *ip, struct file *fp)
4549
{
4550
        MOD_INC_USE_COUNT;
4551
        return(0);
4552
}
4553
 
4554
/*****************************************************************************/
4555
 
4556
static void stli_memclose(struct inode *ip, struct file *fp)
4557
{
4558
        MOD_DEC_USE_COUNT;
4559
}
4560
 
4561
/*****************************************************************************/
4562
 
4563
/*
4564
 *      The "staliomem" device is also required to do some special operations on
4565
 *      the board. We need to be able to send an interrupt to the board,
4566
 *      reset it, and start/stop it.
4567
 */
4568
 
4569
static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4570
{
4571
        stlibrd_t       *brdp;
4572
        int             brdnr, rc, done;
4573
 
4574
#if DEBUG
4575
        printk("stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
4576
                (int) fp, cmd, (int) arg);
4577
#endif
4578
 
4579
/*
4580
 *      First up handle the board independent ioctls.
4581
 */
4582
        done = 0;
4583
        rc = 0;
4584
 
4585
        switch (cmd) {
4586
        case COM_GETPORTSTATS:
4587
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
4588
                    sizeof(comstats_t))) == 0)
4589
                        rc = stli_getportstats((stliport_t *) NULL,
4590
                                (comstats_t *) arg);
4591
                done++;
4592
                break;
4593
        case COM_CLRPORTSTATS:
4594
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
4595
                    sizeof(comstats_t))) == 0)
4596
                        rc = stli_clrportstats((stliport_t *) NULL,
4597
                                (comstats_t *) arg);
4598
                done++;
4599
                break;
4600
        case COM_GETBRDSTATS:
4601
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
4602
                    sizeof(combrd_t))) == 0)
4603
                        rc = stli_getbrdstats((combrd_t *) arg);
4604
                done++;
4605
                break;
4606
        case COM_READPORT:
4607
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
4608
                    sizeof(stliport_t))) == 0)
4609
                        rc = stli_getportstruct(arg);
4610
                done++;
4611
                break;
4612
        case COM_READBOARD:
4613
                if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
4614
                    sizeof(stlibrd_t))) == 0)
4615
                        rc = stli_getbrdstruct(arg);
4616
                done++;
4617
                break;
4618
        default:
4619
                break;
4620
        }
4621
 
4622
        if (done)
4623
                return(rc);
4624
 
4625
/*
4626
 *      Now handle the board specific ioctls. These all depend on the
4627
 *      minor number of the device they were called from.
4628
 */
4629
        brdnr = MINOR(ip->i_rdev);
4630
        if (brdnr >= STL_MAXBRDS)
4631
                return(-ENODEV);
4632
        brdp = stli_brds[brdnr];
4633
        if (brdp == (stlibrd_t *) NULL)
4634
                return(-ENODEV);
4635
        if (brdp->state == 0)
4636
                return(-ENODEV);
4637
 
4638
        switch (cmd) {
4639
        case STL_BINTR:
4640
                EBRDINTR(brdp);
4641
                break;
4642
        case STL_BSTART:
4643
                rc = stli_startbrd(brdp);
4644
                break;
4645
        case STL_BSTOP:
4646
                brdp->state &= ~BST_STARTED;
4647
                break;
4648
        case STL_BRESET:
4649
                brdp->state &= ~BST_STARTED;
4650
                EBRDRESET(brdp);
4651
                if (stli_shared == 0) {
4652
                        if (brdp->reenable != NULL)
4653
                                (* brdp->reenable)(brdp);
4654
                }
4655
                break;
4656
        default:
4657
                rc = -ENOIOCTLCMD;
4658
                break;
4659
        }
4660
 
4661
        return(rc);
4662
}
4663
 
4664
/*****************************************************************************/
4665
 
4666
int stli_init()
4667
{
4668
        printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
4669
 
4670
        stli_initbrds();
4671
 
4672
/*
4673
 *      Allocate a temporary write buffer.
4674
 */
4675
        stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
4676
        if (stli_tmpwritebuf == (char *) NULL)
4677
                printk("STALLION: failed to allocate memory (size=%d)\n",
4678
                        STLI_TXBUFSIZE);
4679
        stli_txcookbuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
4680
        if (stli_txcookbuf == (char *) NULL)
4681
                printk("STALLION: failed to allocate memory (size=%d)\n",
4682
                        STLI_TXBUFSIZE);
4683
 
4684
/*
4685
 *      Set up a character driver for the shared memory region. We need this
4686
 *      to down load the slave code image. Also it is a useful debugging tool.
4687
 */
4688
        if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
4689
                printk("STALLION: failed to register serial memory device\n");
4690
 
4691
/*
4692
 *      Set up the tty driver structure and register us as a driver.
4693
 *      Also setup the callout tty device.
4694
 */
4695
        memset(&stli_serial, 0, sizeof(struct tty_driver));
4696
        stli_serial.magic = TTY_DRIVER_MAGIC;
4697
        stli_serial.name = stli_serialname;
4698
        stli_serial.major = STL_SERIALMAJOR;
4699
        stli_serial.minor_start = 0;
4700
        stli_serial.num = STL_MAXBRDS * STL_MAXPORTS;
4701
        stli_serial.type = TTY_DRIVER_TYPE_SERIAL;
4702
        stli_serial.subtype = STL_DRVTYPSERIAL;
4703
        stli_serial.init_termios = stli_deftermios;
4704
        stli_serial.flags = TTY_DRIVER_REAL_RAW;
4705
        stli_serial.refcount = &stli_refcount;
4706
        stli_serial.table = stli_ttys;
4707
        stli_serial.termios = stli_termios;
4708
        stli_serial.termios_locked = stli_termioslocked;
4709
 
4710
        stli_serial.open = stli_open;
4711
        stli_serial.close = stli_close;
4712
        stli_serial.write = stli_write;
4713
        stli_serial.put_char = stli_putchar;
4714
        stli_serial.flush_chars = stli_flushchars;
4715
        stli_serial.write_room = stli_writeroom;
4716
        stli_serial.chars_in_buffer = stli_charsinbuffer;
4717
        stli_serial.ioctl = stli_ioctl;
4718
        stli_serial.set_termios = stli_settermios;
4719
        stli_serial.throttle = stli_throttle;
4720
        stli_serial.unthrottle = stli_unthrottle;
4721
        stli_serial.stop = stli_stop;
4722
        stli_serial.start = stli_start;
4723
        stli_serial.hangup = stli_hangup;
4724
        stli_serial.flush_buffer = stli_flushbuffer;
4725
 
4726
        stli_callout = stli_serial;
4727
        stli_callout.name = stli_calloutname;
4728
        stli_callout.major = STL_CALLOUTMAJOR;
4729
        stli_callout.subtype = STL_DRVTYPCALLOUT;
4730
 
4731
        if (tty_register_driver(&stli_serial))
4732
                printk("STALLION: failed to register serial driver\n");
4733
        if (tty_register_driver(&stli_callout))
4734
                printk("STALLION: failed to register callout driver\n");
4735
 
4736
        return(0);
4737
}
4738
 
4739
/*****************************************************************************/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.