aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/epca.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/epca.c')
-rw-r--r--drivers/char/epca.c1634
1 files changed, 484 insertions, 1150 deletions
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 6025e1866c7e..407708a001e4 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -6,6 +6,8 @@
6 For technical support please email digiLinux@dgii.com or 6 For technical support please email digiLinux@dgii.com or
7 call Digi tech support at (612) 912-3456 7 call Digi tech support at (612) 912-3456
8 8
9 ** This driver is no longer supported by Digi **
10
9 Much of this design and code came from epca.c which was 11 Much of this design and code came from epca.c which was
10 copyright (C) 1994, 1995 Troy De Jongh, and subsquently 12 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
11 modified by David Nugent, Christoph Lameter, Mike McLagan. 13 modified by David Nugent, Christoph Lameter, Mike McLagan.
@@ -43,31 +45,19 @@
43#include <linux/interrupt.h> 45#include <linux/interrupt.h>
44#include <asm/uaccess.h> 46#include <asm/uaccess.h>
45#include <asm/io.h> 47#include <asm/io.h>
46 48#include <linux/spinlock.h>
47#ifdef CONFIG_PCI
48#define ENABLE_PCI
49#endif /* CONFIG_PCI */
50
51#define putUser(arg1, arg2) put_user(arg1, (unsigned long __user *)arg2)
52#define getUser(arg1, arg2) get_user(arg1, (unsigned __user *)arg2)
53
54#ifdef ENABLE_PCI
55#include <linux/pci.h> 49#include <linux/pci.h>
56#include "digiPCI.h" 50#include "digiPCI.h"
57#endif /* ENABLE_PCI */ 51
58 52
59#include "digi1.h" 53#include "digi1.h"
60#include "digiFep1.h" 54#include "digiFep1.h"
61#include "epca.h" 55#include "epca.h"
62#include "epcaconfig.h" 56#include "epcaconfig.h"
63 57
64#if BITS_PER_LONG != 32
65# error FIXME: this driver only works on 32-bit platforms
66#endif
67
68/* ---------------------- Begin defines ------------------------ */ 58/* ---------------------- Begin defines ------------------------ */
69 59
70#define VERSION "1.3.0.1-LK" 60#define VERSION "1.3.0.1-LK2.6"
71 61
72/* This major needs to be submitted to Linux to join the majors list */ 62/* This major needs to be submitted to Linux to join the majors list */
73 63
@@ -81,13 +71,17 @@
81 71
82/* ----------------- Begin global definitions ------------------- */ 72/* ----------------- Begin global definitions ------------------- */
83 73
84static char mesg[100];
85static int nbdevs, num_cards, liloconfig; 74static int nbdevs, num_cards, liloconfig;
86static int digi_poller_inhibited = 1 ; 75static int digi_poller_inhibited = 1 ;
87 76
88static int setup_error_code; 77static int setup_error_code;
89static int invalid_lilo_config; 78static int invalid_lilo_config;
90 79
80/* The ISA boards do window flipping into the same spaces so its only sane
81 with a single lock. It's still pretty efficient */
82
83static spinlock_t epca_lock = SPIN_LOCK_UNLOCKED;
84
91/* ----------------------------------------------------------------------- 85/* -----------------------------------------------------------------------
92 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to 86 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
93 7 below. 87 7 below.
@@ -129,58 +123,58 @@ static struct timer_list epca_timer;
129 configured. 123 configured.
130----------------------------------------------------------------------- */ 124----------------------------------------------------------------------- */
131 125
132static inline void memwinon(struct board_info *b, unsigned int win); 126static void memwinon(struct board_info *b, unsigned int win);
133static inline void memwinoff(struct board_info *b, unsigned int win); 127static void memwinoff(struct board_info *b, unsigned int win);
134static inline void globalwinon(struct channel *ch); 128static void globalwinon(struct channel *ch);
135static inline void rxwinon(struct channel *ch); 129static void rxwinon(struct channel *ch);
136static inline void txwinon(struct channel *ch); 130static void txwinon(struct channel *ch);
137static inline void memoff(struct channel *ch); 131static void memoff(struct channel *ch);
138static inline void assertgwinon(struct channel *ch); 132static void assertgwinon(struct channel *ch);
139static inline void assertmemoff(struct channel *ch); 133static void assertmemoff(struct channel *ch);
140 134
141/* ---- Begin more 'specific' memory functions for cx_like products --- */ 135/* ---- Begin more 'specific' memory functions for cx_like products --- */
142 136
143static inline void pcxem_memwinon(struct board_info *b, unsigned int win); 137static void pcxem_memwinon(struct board_info *b, unsigned int win);
144static inline void pcxem_memwinoff(struct board_info *b, unsigned int win); 138static void pcxem_memwinoff(struct board_info *b, unsigned int win);
145static inline void pcxem_globalwinon(struct channel *ch); 139static void pcxem_globalwinon(struct channel *ch);
146static inline void pcxem_rxwinon(struct channel *ch); 140static void pcxem_rxwinon(struct channel *ch);
147static inline void pcxem_txwinon(struct channel *ch); 141static void pcxem_txwinon(struct channel *ch);
148static inline void pcxem_memoff(struct channel *ch); 142static void pcxem_memoff(struct channel *ch);
149 143
150/* ------ Begin more 'specific' memory functions for the pcxe ------- */ 144/* ------ Begin more 'specific' memory functions for the pcxe ------- */
151 145
152static inline void pcxe_memwinon(struct board_info *b, unsigned int win); 146static void pcxe_memwinon(struct board_info *b, unsigned int win);
153static inline void pcxe_memwinoff(struct board_info *b, unsigned int win); 147static void pcxe_memwinoff(struct board_info *b, unsigned int win);
154static inline void pcxe_globalwinon(struct channel *ch); 148static void pcxe_globalwinon(struct channel *ch);
155static inline void pcxe_rxwinon(struct channel *ch); 149static void pcxe_rxwinon(struct channel *ch);
156static inline void pcxe_txwinon(struct channel *ch); 150static void pcxe_txwinon(struct channel *ch);
157static inline void pcxe_memoff(struct channel *ch); 151static void pcxe_memoff(struct channel *ch);
158 152
159/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */ 153/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
160/* Note : pc64xe and pcxi share the same windowing routines */ 154/* Note : pc64xe and pcxi share the same windowing routines */
161 155
162static inline void pcxi_memwinon(struct board_info *b, unsigned int win); 156static void pcxi_memwinon(struct board_info *b, unsigned int win);
163static inline void pcxi_memwinoff(struct board_info *b, unsigned int win); 157static void pcxi_memwinoff(struct board_info *b, unsigned int win);
164static inline void pcxi_globalwinon(struct channel *ch); 158static void pcxi_globalwinon(struct channel *ch);
165static inline void pcxi_rxwinon(struct channel *ch); 159static void pcxi_rxwinon(struct channel *ch);
166static inline void pcxi_txwinon(struct channel *ch); 160static void pcxi_txwinon(struct channel *ch);
167static inline void pcxi_memoff(struct channel *ch); 161static void pcxi_memoff(struct channel *ch);
168 162
169/* - Begin 'specific' do nothing memory functions needed for some cards - */ 163/* - Begin 'specific' do nothing memory functions needed for some cards - */
170 164
171static inline void dummy_memwinon(struct board_info *b, unsigned int win); 165static void dummy_memwinon(struct board_info *b, unsigned int win);
172static inline void dummy_memwinoff(struct board_info *b, unsigned int win); 166static void dummy_memwinoff(struct board_info *b, unsigned int win);
173static inline void dummy_globalwinon(struct channel *ch); 167static void dummy_globalwinon(struct channel *ch);
174static inline void dummy_rxwinon(struct channel *ch); 168static void dummy_rxwinon(struct channel *ch);
175static inline void dummy_txwinon(struct channel *ch); 169static void dummy_txwinon(struct channel *ch);
176static inline void dummy_memoff(struct channel *ch); 170static void dummy_memoff(struct channel *ch);
177static inline void dummy_assertgwinon(struct channel *ch); 171static void dummy_assertgwinon(struct channel *ch);
178static inline void dummy_assertmemoff(struct channel *ch); 172static void dummy_assertmemoff(struct channel *ch);
179 173
180/* ------------------- Begin declare functions ----------------------- */ 174/* ------------------- Begin declare functions ----------------------- */
181 175
182static inline struct channel *verifyChannel(register struct tty_struct *); 176static struct channel *verifyChannel(struct tty_struct *);
183static inline void pc_sched_event(struct channel *, int); 177static void pc_sched_event(struct channel *, int);
184static void epca_error(int, char *); 178static void epca_error(int, char *);
185static void pc_close(struct tty_struct *, struct file *); 179static void pc_close(struct tty_struct *, struct file *);
186static void shutdown(struct channel *); 180static void shutdown(struct channel *);
@@ -215,15 +209,11 @@ static void pc_unthrottle(struct tty_struct *tty);
215static void digi_send_break(struct channel *ch, int msec); 209static void digi_send_break(struct channel *ch, int msec);
216static void setup_empty_event(struct tty_struct *tty, struct channel *ch); 210static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
217void epca_setup(char *, int *); 211void epca_setup(char *, int *);
218void console_print(const char *);
219 212
220static int get_termio(struct tty_struct *, struct termio __user *); 213static int get_termio(struct tty_struct *, struct termio __user *);
221static int pc_write(struct tty_struct *, const unsigned char *, int); 214static int pc_write(struct tty_struct *, const unsigned char *, int);
222int pc_init(void); 215static int pc_init(void);
223
224#ifdef ENABLE_PCI
225static int init_PCI(void); 216static int init_PCI(void);
226#endif /* ENABLE_PCI */
227 217
228 218
229/* ------------------------------------------------------------------ 219/* ------------------------------------------------------------------
@@ -237,41 +227,41 @@ static int init_PCI(void);
237 making direct calls deserves what they get. 227 making direct calls deserves what they get.
238-------------------------------------------------------------------- */ 228-------------------------------------------------------------------- */
239 229
240static inline void memwinon(struct board_info *b, unsigned int win) 230static void memwinon(struct board_info *b, unsigned int win)
241{ 231{
242 (b->memwinon)(b, win); 232 (b->memwinon)(b, win);
243} 233}
244 234
245static inline void memwinoff(struct board_info *b, unsigned int win) 235static void memwinoff(struct board_info *b, unsigned int win)
246{ 236{
247 (b->memwinoff)(b, win); 237 (b->memwinoff)(b, win);
248} 238}
249 239
250static inline void globalwinon(struct channel *ch) 240static void globalwinon(struct channel *ch)
251{ 241{
252 (ch->board->globalwinon)(ch); 242 (ch->board->globalwinon)(ch);
253} 243}
254 244
255static inline void rxwinon(struct channel *ch) 245static void rxwinon(struct channel *ch)
256{ 246{
257 (ch->board->rxwinon)(ch); 247 (ch->board->rxwinon)(ch);
258} 248}
259 249
260static inline void txwinon(struct channel *ch) 250static void txwinon(struct channel *ch)
261{ 251{
262 (ch->board->txwinon)(ch); 252 (ch->board->txwinon)(ch);
263} 253}
264 254
265static inline void memoff(struct channel *ch) 255static void memoff(struct channel *ch)
266{ 256{
267 (ch->board->memoff)(ch); 257 (ch->board->memoff)(ch);
268} 258}
269static inline void assertgwinon(struct channel *ch) 259static void assertgwinon(struct channel *ch)
270{ 260{
271 (ch->board->assertgwinon)(ch); 261 (ch->board->assertgwinon)(ch);
272} 262}
273 263
274static inline void assertmemoff(struct channel *ch) 264static void assertmemoff(struct channel *ch)
275{ 265{
276 (ch->board->assertmemoff)(ch); 266 (ch->board->assertmemoff)(ch);
277} 267}
@@ -281,66 +271,66 @@ static inline void assertmemoff(struct channel *ch)
281 and CX series cards. 271 and CX series cards.
282------------------------------------------------------------ */ 272------------------------------------------------------------ */
283 273
284static inline void pcxem_memwinon(struct board_info *b, unsigned int win) 274static void pcxem_memwinon(struct board_info *b, unsigned int win)
285{ 275{
286 outb_p(FEPWIN|win, (int)b->port + 1); 276 outb_p(FEPWIN|win, b->port + 1);
287} 277}
288 278
289static inline void pcxem_memwinoff(struct board_info *b, unsigned int win) 279static void pcxem_memwinoff(struct board_info *b, unsigned int win)
290{ 280{
291 outb_p(0, (int)b->port + 1); 281 outb_p(0, b->port + 1);
292} 282}
293 283
294static inline void pcxem_globalwinon(struct channel *ch) 284static void pcxem_globalwinon(struct channel *ch)
295{ 285{
296 outb_p( FEPWIN, (int)ch->board->port + 1); 286 outb_p( FEPWIN, (int)ch->board->port + 1);
297} 287}
298 288
299static inline void pcxem_rxwinon(struct channel *ch) 289static void pcxem_rxwinon(struct channel *ch)
300{ 290{
301 outb_p(ch->rxwin, (int)ch->board->port + 1); 291 outb_p(ch->rxwin, (int)ch->board->port + 1);
302} 292}
303 293
304static inline void pcxem_txwinon(struct channel *ch) 294static void pcxem_txwinon(struct channel *ch)
305{ 295{
306 outb_p(ch->txwin, (int)ch->board->port + 1); 296 outb_p(ch->txwin, (int)ch->board->port + 1);
307} 297}
308 298
309static inline void pcxem_memoff(struct channel *ch) 299static void pcxem_memoff(struct channel *ch)
310{ 300{
311 outb_p(0, (int)ch->board->port + 1); 301 outb_p(0, (int)ch->board->port + 1);
312} 302}
313 303
314/* ----------------- Begin pcxe memory window stuff ------------------ */ 304/* ----------------- Begin pcxe memory window stuff ------------------ */
315 305
316static inline void pcxe_memwinon(struct board_info *b, unsigned int win) 306static void pcxe_memwinon(struct board_info *b, unsigned int win)
317{ 307{
318 outb_p(FEPWIN | win, (int)b->port + 1); 308 outb_p(FEPWIN | win, b->port + 1);
319} 309}
320 310
321static inline void pcxe_memwinoff(struct board_info *b, unsigned int win) 311static void pcxe_memwinoff(struct board_info *b, unsigned int win)
322{ 312{
323 outb_p(inb((int)b->port) & ~FEPMEM, 313 outb_p(inb(b->port) & ~FEPMEM,
324 (int)b->port + 1); 314 b->port + 1);
325 outb_p(0, (int)b->port + 1); 315 outb_p(0, b->port + 1);
326} 316}
327 317
328static inline void pcxe_globalwinon(struct channel *ch) 318static void pcxe_globalwinon(struct channel *ch)
329{ 319{
330 outb_p( FEPWIN, (int)ch->board->port + 1); 320 outb_p( FEPWIN, (int)ch->board->port + 1);
331} 321}
332 322
333static inline void pcxe_rxwinon(struct channel *ch) 323static void pcxe_rxwinon(struct channel *ch)
334{ 324{
335 outb_p(ch->rxwin, (int)ch->board->port + 1); 325 outb_p(ch->rxwin, (int)ch->board->port + 1);
336} 326}
337 327
338static inline void pcxe_txwinon(struct channel *ch) 328static void pcxe_txwinon(struct channel *ch)
339{ 329{
340 outb_p(ch->txwin, (int)ch->board->port + 1); 330 outb_p(ch->txwin, (int)ch->board->port + 1);
341} 331}
342 332
343static inline void pcxe_memoff(struct channel *ch) 333static void pcxe_memoff(struct channel *ch)
344{ 334{
345 outb_p(0, (int)ch->board->port); 335 outb_p(0, (int)ch->board->port);
346 outb_p(0, (int)ch->board->port + 1); 336 outb_p(0, (int)ch->board->port + 1);
@@ -348,44 +338,44 @@ static inline void pcxe_memoff(struct channel *ch)
348 338
349/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */ 339/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
350 340
351static inline void pcxi_memwinon(struct board_info *b, unsigned int win) 341static void pcxi_memwinon(struct board_info *b, unsigned int win)
352{ 342{
353 outb_p(inb((int)b->port) | FEPMEM, (int)b->port); 343 outb_p(inb(b->port) | FEPMEM, b->port);
354} 344}
355 345
356static inline void pcxi_memwinoff(struct board_info *b, unsigned int win) 346static void pcxi_memwinoff(struct board_info *b, unsigned int win)
357{ 347{
358 outb_p(inb((int)b->port) & ~FEPMEM, (int)b->port); 348 outb_p(inb(b->port) & ~FEPMEM, b->port);
359} 349}
360 350
361static inline void pcxi_globalwinon(struct channel *ch) 351static void pcxi_globalwinon(struct channel *ch)
362{ 352{
363 outb_p(FEPMEM, (int)ch->board->port); 353 outb_p(FEPMEM, ch->board->port);
364} 354}
365 355
366static inline void pcxi_rxwinon(struct channel *ch) 356static void pcxi_rxwinon(struct channel *ch)
367{ 357{
368 outb_p(FEPMEM, (int)ch->board->port); 358 outb_p(FEPMEM, ch->board->port);
369} 359}
370 360
371static inline void pcxi_txwinon(struct channel *ch) 361static void pcxi_txwinon(struct channel *ch)
372{ 362{
373 outb_p(FEPMEM, (int)ch->board->port); 363 outb_p(FEPMEM, ch->board->port);
374} 364}
375 365
376static inline void pcxi_memoff(struct channel *ch) 366static void pcxi_memoff(struct channel *ch)
377{ 367{
378 outb_p(0, (int)ch->board->port); 368 outb_p(0, ch->board->port);
379} 369}
380 370
381static inline void pcxi_assertgwinon(struct channel *ch) 371static void pcxi_assertgwinon(struct channel *ch)
382{ 372{
383 epcaassert(inb((int)ch->board->port) & FEPMEM, "Global memory off"); 373 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
384} 374}
385 375
386static inline void pcxi_assertmemoff(struct channel *ch) 376static void pcxi_assertmemoff(struct channel *ch)
387{ 377{
388 epcaassert(!(inb((int)ch->board->port) & FEPMEM), "Memory on"); 378 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
389} 379}
390 380
391 381
@@ -398,185 +388,143 @@ static inline void pcxi_assertmemoff(struct channel *ch)
398 may or may not do anything. 388 may or may not do anything.
399---------------------------------------------------------------------------*/ 389---------------------------------------------------------------------------*/
400 390
401static inline void dummy_memwinon(struct board_info *b, unsigned int win) 391static void dummy_memwinon(struct board_info *b, unsigned int win)
402{ 392{
403} 393}
404 394
405static inline void dummy_memwinoff(struct board_info *b, unsigned int win) 395static void dummy_memwinoff(struct board_info *b, unsigned int win)
406{ 396{
407} 397}
408 398
409static inline void dummy_globalwinon(struct channel *ch) 399static void dummy_globalwinon(struct channel *ch)
410{ 400{
411} 401}
412 402
413static inline void dummy_rxwinon(struct channel *ch) 403static void dummy_rxwinon(struct channel *ch)
414{ 404{
415} 405}
416 406
417static inline void dummy_txwinon(struct channel *ch) 407static void dummy_txwinon(struct channel *ch)
418{ 408{
419} 409}
420 410
421static inline void dummy_memoff(struct channel *ch) 411static void dummy_memoff(struct channel *ch)
422{ 412{
423} 413}
424 414
425static inline void dummy_assertgwinon(struct channel *ch) 415static void dummy_assertgwinon(struct channel *ch)
426{ 416{
427} 417}
428 418
429static inline void dummy_assertmemoff(struct channel *ch) 419static void dummy_assertmemoff(struct channel *ch)
430{ 420{
431} 421}
432 422
433/* ----------------- Begin verifyChannel function ----------------------- */ 423/* ----------------- Begin verifyChannel function ----------------------- */
434static inline struct channel *verifyChannel(register struct tty_struct *tty) 424static struct channel *verifyChannel(struct tty_struct *tty)
435{ /* Begin verifyChannel */ 425{ /* Begin verifyChannel */
436
437 /* -------------------------------------------------------------------- 426 /* --------------------------------------------------------------------
438 This routine basically provides a sanity check. It insures that 427 This routine basically provides a sanity check. It insures that
439 the channel returned is within the proper range of addresses as 428 the channel returned is within the proper range of addresses as
440 well as properly initialized. If some bogus info gets passed in 429 well as properly initialized. If some bogus info gets passed in
441 through tty->driver_data this should catch it. 430 through tty->driver_data this should catch it.
442 --------------------------------------------------------------------- */ 431 --------------------------------------------------------------------- */
443 432 if (tty) {
444 if (tty) 433 struct channel *ch = (struct channel *)tty->driver_data;
445 { /* Begin if tty */ 434 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
446
447 register struct channel *ch = (struct channel *)tty->driver_data;
448
449 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs]))
450 {
451 if (ch->magic == EPCA_MAGIC) 435 if (ch->magic == EPCA_MAGIC)
452 return ch; 436 return ch;
453 } 437 }
454 438 }
455 } /* End if tty */
456
457 /* Else return a NULL for invalid */
458 return NULL; 439 return NULL;
459 440
460} /* End verifyChannel */ 441} /* End verifyChannel */
461 442
462/* ------------------ Begin pc_sched_event ------------------------- */ 443/* ------------------ Begin pc_sched_event ------------------------- */
463 444
464static inline void pc_sched_event(struct channel *ch, int event) 445static void pc_sched_event(struct channel *ch, int event)
465{ /* Begin pc_sched_event */ 446{
466
467
468 /* ---------------------------------------------------------------------- 447 /* ----------------------------------------------------------------------
469 We call this to schedule interrupt processing on some event. The 448 We call this to schedule interrupt processing on some event. The
470 kernel sees our request and calls the related routine in OUR driver. 449 kernel sees our request and calls the related routine in OUR driver.
471 -------------------------------------------------------------------------*/ 450 -------------------------------------------------------------------------*/
472
473 ch->event |= 1 << event; 451 ch->event |= 1 << event;
474 schedule_work(&ch->tqueue); 452 schedule_work(&ch->tqueue);
475
476
477} /* End pc_sched_event */ 453} /* End pc_sched_event */
478 454
479/* ------------------ Begin epca_error ------------------------- */ 455/* ------------------ Begin epca_error ------------------------- */
480 456
481static void epca_error(int line, char *msg) 457static void epca_error(int line, char *msg)
482{ /* Begin epca_error */ 458{
483
484 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg); 459 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
485 return; 460}
486
487} /* End epca_error */
488 461
489/* ------------------ Begin pc_close ------------------------- */ 462/* ------------------ Begin pc_close ------------------------- */
490static void pc_close(struct tty_struct * tty, struct file * filp) 463static void pc_close(struct tty_struct * tty, struct file * filp)
491{ /* Begin pc_close */ 464{
492
493 struct channel *ch; 465 struct channel *ch;
494 unsigned long flags; 466 unsigned long flags;
495
496 /* --------------------------------------------------------- 467 /* ---------------------------------------------------------
497 verifyChannel returns the channel from the tty struct 468 verifyChannel returns the channel from the tty struct
498 if it is valid. This serves as a sanity check. 469 if it is valid. This serves as a sanity check.
499 ------------------------------------------------------------- */ 470 ------------------------------------------------------------- */
500 471 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
501 if ((ch = verifyChannel(tty)) != NULL) 472 spin_lock_irqsave(&epca_lock, flags);
502 { /* Begin if ch != NULL */ 473 if (tty_hung_up_p(filp)) {
503 474 spin_unlock_irqrestore(&epca_lock, flags);
504 save_flags(flags);
505 cli();
506
507 if (tty_hung_up_p(filp))
508 {
509 restore_flags(flags);
510 return; 475 return;
511 } 476 }
512
513 /* Check to see if the channel is open more than once */ 477 /* Check to see if the channel is open more than once */
514 if (ch->count-- > 1) 478 if (ch->count-- > 1) {
515 { /* Begin channel is open more than once */ 479 /* Begin channel is open more than once */
516
517 /* ------------------------------------------------------------- 480 /* -------------------------------------------------------------
518 Return without doing anything. Someone might still be using 481 Return without doing anything. Someone might still be using
519 the channel. 482 the channel.
520 ---------------------------------------------------------------- */ 483 ---------------------------------------------------------------- */
521 484 spin_unlock_irqrestore(&epca_lock, flags);
522 restore_flags(flags);
523 return; 485 return;
524 } /* End channel is open more than once */ 486 } /* End channel is open more than once */
525 487
526 /* Port open only once go ahead with shutdown & reset */ 488 /* Port open only once go ahead with shutdown & reset */
527 489 if (ch->count < 0)
528 if (ch->count < 0) 490 BUG();
529 {
530 ch->count = 0;
531 }
532 491
533 /* --------------------------------------------------------------- 492 /* ---------------------------------------------------------------
534 Let the rest of the driver know the channel is being closed. 493 Let the rest of the driver know the channel is being closed.
535 This becomes important if an open is attempted before close 494 This becomes important if an open is attempted before close
536 is finished. 495 is finished.
537 ------------------------------------------------------------------ */ 496 ------------------------------------------------------------------ */
538
539 ch->asyncflags |= ASYNC_CLOSING; 497 ch->asyncflags |= ASYNC_CLOSING;
540
541 tty->closing = 1; 498 tty->closing = 1;
542 499
543 if (ch->asyncflags & ASYNC_INITIALIZED) 500 spin_unlock_irqrestore(&epca_lock, flags);
544 { 501
502 if (ch->asyncflags & ASYNC_INITIALIZED) {
545 /* Setup an event to indicate when the transmit buffer empties */ 503 /* Setup an event to indicate when the transmit buffer empties */
546 setup_empty_event(tty, ch); 504 setup_empty_event(tty, ch);
547 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */ 505 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
548 } 506 }
549
550 if (tty->driver->flush_buffer) 507 if (tty->driver->flush_buffer)
551 tty->driver->flush_buffer(tty); 508 tty->driver->flush_buffer(tty);
552 509
553 tty_ldisc_flush(tty); 510 tty_ldisc_flush(tty);
554 shutdown(ch); 511 shutdown(ch);
512
513 spin_lock_irqsave(&epca_lock, flags);
555 tty->closing = 0; 514 tty->closing = 0;
556 ch->event = 0; 515 ch->event = 0;
557 ch->tty = NULL; 516 ch->tty = NULL;
517 spin_unlock_irqrestore(&epca_lock, flags);
558 518
559 if (ch->blocked_open) 519 if (ch->blocked_open) { /* Begin if blocked_open */
560 { /* Begin if blocked_open */
561
562 if (ch->close_delay) 520 if (ch->close_delay)
563 {
564 msleep_interruptible(jiffies_to_msecs(ch->close_delay)); 521 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
565 }
566
567 wake_up_interruptible(&ch->open_wait); 522 wake_up_interruptible(&ch->open_wait);
568
569 } /* End if blocked_open */ 523 } /* End if blocked_open */
570
571 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED | 524 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
572 ASYNC_CLOSING); 525 ASYNC_CLOSING);
573 wake_up_interruptible(&ch->close_wait); 526 wake_up_interruptible(&ch->close_wait);
574
575
576 restore_flags(flags);
577
578 } /* End if ch != NULL */ 527 } /* End if ch != NULL */
579
580} /* End pc_close */ 528} /* End pc_close */
581 529
582/* ------------------ Begin shutdown ------------------------- */ 530/* ------------------ Begin shutdown ------------------------- */
@@ -586,15 +534,14 @@ static void shutdown(struct channel *ch)
586 534
587 unsigned long flags; 535 unsigned long flags;
588 struct tty_struct *tty; 536 struct tty_struct *tty;
589 volatile struct board_chan *bc; 537 struct board_chan __iomem *bc;
590 538
591 if (!(ch->asyncflags & ASYNC_INITIALIZED)) 539 if (!(ch->asyncflags & ASYNC_INITIALIZED))
592 return; 540 return;
593 541
594 save_flags(flags); 542 spin_lock_irqsave(&epca_lock, flags);
595 cli();
596 globalwinon(ch);
597 543
544 globalwinon(ch);
598 bc = ch->brdchan; 545 bc = ch->brdchan;
599 546
600 /* ------------------------------------------------------------------ 547 /* ------------------------------------------------------------------
@@ -604,20 +551,17 @@ static void shutdown(struct channel *ch)
604 --------------------------------------------------------------------- */ 551 --------------------------------------------------------------------- */
605 552
606 if (bc) 553 if (bc)
607 bc->idata = 0; 554 writeb(0, &bc->idata);
608
609 tty = ch->tty; 555 tty = ch->tty;
610 556
611 /* ---------------------------------------------------------------- 557 /* ----------------------------------------------------------------
612 If we're a modem control device and HUPCL is on, drop RTS & DTR. 558 If we're a modem control device and HUPCL is on, drop RTS & DTR.
613 ------------------------------------------------------------------ */ 559 ------------------------------------------------------------------ */
614 560
615 if (tty->termios->c_cflag & HUPCL) 561 if (tty->termios->c_cflag & HUPCL) {
616 {
617 ch->omodem &= ~(ch->m_rts | ch->m_dtr); 562 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
618 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1); 563 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
619 } 564 }
620
621 memoff(ch); 565 memoff(ch);
622 566
623 /* ------------------------------------------------------------------ 567 /* ------------------------------------------------------------------
@@ -628,7 +572,7 @@ static void shutdown(struct channel *ch)
628 /* Prevent future Digi programmed interrupts from coming active */ 572 /* Prevent future Digi programmed interrupts from coming active */
629 573
630 ch->asyncflags &= ~ASYNC_INITIALIZED; 574 ch->asyncflags &= ~ASYNC_INITIALIZED;
631 restore_flags(flags); 575 spin_unlock_irqrestore(&epca_lock, flags);
632 576
633} /* End shutdown */ 577} /* End shutdown */
634 578
@@ -636,7 +580,6 @@ static void shutdown(struct channel *ch)
636 580
637static void pc_hangup(struct tty_struct *tty) 581static void pc_hangup(struct tty_struct *tty)
638{ /* Begin pc_hangup */ 582{ /* Begin pc_hangup */
639
640 struct channel *ch; 583 struct channel *ch;
641 584
642 /* --------------------------------------------------------- 585 /* ---------------------------------------------------------
@@ -644,25 +587,21 @@ static void pc_hangup(struct tty_struct *tty)
644 if it is valid. This serves as a sanity check. 587 if it is valid. This serves as a sanity check.
645 ------------------------------------------------------------- */ 588 ------------------------------------------------------------- */
646 589
647 if ((ch = verifyChannel(tty)) != NULL) 590 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
648 { /* Begin if ch != NULL */
649
650 unsigned long flags; 591 unsigned long flags;
651 592
652 save_flags(flags);
653 cli();
654 if (tty->driver->flush_buffer) 593 if (tty->driver->flush_buffer)
655 tty->driver->flush_buffer(tty); 594 tty->driver->flush_buffer(tty);
656 tty_ldisc_flush(tty); 595 tty_ldisc_flush(tty);
657 shutdown(ch); 596 shutdown(ch);
658 597
598 spin_lock_irqsave(&epca_lock, flags);
659 ch->tty = NULL; 599 ch->tty = NULL;
660 ch->event = 0; 600 ch->event = 0;
661 ch->count = 0; 601 ch->count = 0;
662 restore_flags(flags);
663 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED); 602 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
603 spin_unlock_irqrestore(&epca_lock, flags);
664 wake_up_interruptible(&ch->open_wait); 604 wake_up_interruptible(&ch->open_wait);
665
666 } /* End if ch != NULL */ 605 } /* End if ch != NULL */
667 606
668} /* End pc_hangup */ 607} /* End pc_hangup */
@@ -672,18 +611,14 @@ static void pc_hangup(struct tty_struct *tty)
672static int pc_write(struct tty_struct * tty, 611static int pc_write(struct tty_struct * tty,
673 const unsigned char *buf, int bytesAvailable) 612 const unsigned char *buf, int bytesAvailable)
674{ /* Begin pc_write */ 613{ /* Begin pc_write */
675 614 unsigned int head, tail;
676 register unsigned int head, tail; 615 int dataLen;
677 register int dataLen; 616 int size;
678 register int size; 617 int amountCopied;
679 register int amountCopied;
680
681
682 struct channel *ch; 618 struct channel *ch;
683 unsigned long flags; 619 unsigned long flags;
684 int remain; 620 int remain;
685 volatile struct board_chan *bc; 621 struct board_chan __iomem *bc;
686
687 622
688 /* ---------------------------------------------------------------- 623 /* ----------------------------------------------------------------
689 pc_write is primarily called directly by the kernel routine 624 pc_write is primarily called directly by the kernel routine
@@ -706,24 +641,20 @@ static int pc_write(struct tty_struct * tty,
706 641
707 bc = ch->brdchan; 642 bc = ch->brdchan;
708 size = ch->txbufsize; 643 size = ch->txbufsize;
709
710 amountCopied = 0; 644 amountCopied = 0;
711 save_flags(flags);
712 cli();
713 645
646 spin_lock_irqsave(&epca_lock, flags);
714 globalwinon(ch); 647 globalwinon(ch);
715 648
716 head = bc->tin & (size - 1); 649 head = readw(&bc->tin) & (size - 1);
717 tail = bc->tout; 650 tail = readw(&bc->tout);
718 651
719 if (tail != bc->tout) 652 if (tail != readw(&bc->tout))
720 tail = bc->tout; 653 tail = readw(&bc->tout);
721 tail &= (size - 1); 654 tail &= (size - 1);
722 655
723 /* If head >= tail, head has not wrapped around. */ 656 /* If head >= tail, head has not wrapped around. */
724 if (head >= tail) 657 if (head >= tail) { /* Begin head has not wrapped */
725 { /* Begin head has not wrapped */
726
727 /* --------------------------------------------------------------- 658 /* ---------------------------------------------------------------
728 remain (much like dataLen above) represents the total amount of 659 remain (much like dataLen above) represents the total amount of
729 space available on the card for data. Here dataLen represents 660 space available on the card for data. Here dataLen represents
@@ -731,26 +662,19 @@ static int pc_write(struct tty_struct * tty,
731 buffer. This is important because a memcpy cannot be told to 662 buffer. This is important because a memcpy cannot be told to
732 automatically wrap around when it hits the buffer end. 663 automatically wrap around when it hits the buffer end.
733 ------------------------------------------------------------------ */ 664 ------------------------------------------------------------------ */
734
735 dataLen = size - head; 665 dataLen = size - head;
736 remain = size - (head - tail) - 1; 666 remain = size - (head - tail) - 1;
737 667 } else { /* Begin head has wrapped around */
738 } /* End head has not wrapped */
739 else
740 { /* Begin head has wrapped around */
741 668
742 remain = tail - head - 1; 669 remain = tail - head - 1;
743 dataLen = remain; 670 dataLen = remain;
744 671
745 } /* End head has wrapped around */ 672 } /* End head has wrapped around */
746
747 /* ------------------------------------------------------------------- 673 /* -------------------------------------------------------------------
748 Check the space on the card. If we have more data than 674 Check the space on the card. If we have more data than
749 space; reduce the amount of data to fit the space. 675 space; reduce the amount of data to fit the space.
750 ---------------------------------------------------------------------- */ 676 ---------------------------------------------------------------------- */
751
752 bytesAvailable = min(remain, bytesAvailable); 677 bytesAvailable = min(remain, bytesAvailable);
753
754 txwinon(ch); 678 txwinon(ch);
755 while (bytesAvailable > 0) 679 while (bytesAvailable > 0)
756 { /* Begin while there is data to copy onto card */ 680 { /* Begin while there is data to copy onto card */
@@ -761,32 +685,27 @@ static int pc_write(struct tty_struct * tty,
761 ------------------------------------------------------------------- */ 685 ------------------------------------------------------------------- */
762 686
763 dataLen = min(bytesAvailable, dataLen); 687 dataLen = min(bytesAvailable, dataLen);
764 memcpy(ch->txptr + head, buf, dataLen); 688 memcpy_toio(ch->txptr + head, buf, dataLen);
765 buf += dataLen; 689 buf += dataLen;
766 head += dataLen; 690 head += dataLen;
767 amountCopied += dataLen; 691 amountCopied += dataLen;
768 bytesAvailable -= dataLen; 692 bytesAvailable -= dataLen;
769 693
770 if (head >= size) 694 if (head >= size) {
771 {
772 head = 0; 695 head = 0;
773 dataLen = tail; 696 dataLen = tail;
774 } 697 }
775
776 } /* End while there is data to copy onto card */ 698 } /* End while there is data to copy onto card */
777
778 ch->statusflags |= TXBUSY; 699 ch->statusflags |= TXBUSY;
779 globalwinon(ch); 700 globalwinon(ch);
780 bc->tin = head; 701 writew(head, &bc->tin);
781 702
782 if ((ch->statusflags & LOWWAIT) == 0) 703 if ((ch->statusflags & LOWWAIT) == 0) {
783 {
784 ch->statusflags |= LOWWAIT; 704 ch->statusflags |= LOWWAIT;
785 bc->ilow = 1; 705 writeb(1, &bc->ilow);
786 } 706 }
787 memoff(ch); 707 memoff(ch);
788 restore_flags(flags); 708 spin_unlock_irqrestore(&epca_lock, flags);
789
790 return(amountCopied); 709 return(amountCopied);
791 710
792} /* End pc_write */ 711} /* End pc_write */
@@ -795,11 +714,7 @@ static int pc_write(struct tty_struct * tty,
795 714
796static void pc_put_char(struct tty_struct *tty, unsigned char c) 715static void pc_put_char(struct tty_struct *tty, unsigned char c)
797{ /* Begin pc_put_char */ 716{ /* Begin pc_put_char */
798
799
800 pc_write(tty, &c, 1); 717 pc_write(tty, &c, 1);
801 return;
802
803} /* End pc_put_char */ 718} /* End pc_put_char */
804 719
805/* ------------------ Begin pc_write_room ------------------------- */ 720/* ------------------ Begin pc_write_room ------------------------- */
@@ -811,7 +726,7 @@ static int pc_write_room(struct tty_struct *tty)
811 struct channel *ch; 726 struct channel *ch;
812 unsigned long flags; 727 unsigned long flags;
813 unsigned int head, tail; 728 unsigned int head, tail;
814 volatile struct board_chan *bc; 729 struct board_chan __iomem *bc;
815 730
816 remain = 0; 731 remain = 0;
817 732
@@ -820,33 +735,29 @@ static int pc_write_room(struct tty_struct *tty)
820 if it is valid. This serves as a sanity check. 735 if it is valid. This serves as a sanity check.
821 ------------------------------------------------------------- */ 736 ------------------------------------------------------------- */
822 737
823 if ((ch = verifyChannel(tty)) != NULL) 738 if ((ch = verifyChannel(tty)) != NULL) {
824 { 739 spin_lock_irqsave(&epca_lock, flags);
825 save_flags(flags);
826 cli();
827 globalwinon(ch); 740 globalwinon(ch);
828 741
829 bc = ch->brdchan; 742 bc = ch->brdchan;
830 head = bc->tin & (ch->txbufsize - 1); 743 head = readw(&bc->tin) & (ch->txbufsize - 1);
831 tail = bc->tout; 744 tail = readw(&bc->tout);
832 745
833 if (tail != bc->tout) 746 if (tail != readw(&bc->tout))
834 tail = bc->tout; 747 tail = readw(&bc->tout);
835 /* Wrap tail if necessary */ 748 /* Wrap tail if necessary */
836 tail &= (ch->txbufsize - 1); 749 tail &= (ch->txbufsize - 1);
837 750
838 if ((remain = tail - head - 1) < 0 ) 751 if ((remain = tail - head - 1) < 0 )
839 remain += ch->txbufsize; 752 remain += ch->txbufsize;
840 753
841 if (remain && (ch->statusflags & LOWWAIT) == 0) 754 if (remain && (ch->statusflags & LOWWAIT) == 0) {
842 {
843 ch->statusflags |= LOWWAIT; 755 ch->statusflags |= LOWWAIT;
844 bc->ilow = 1; 756 writeb(1, &bc->ilow);
845 } 757 }
846 memoff(ch); 758 memoff(ch);
847 restore_flags(flags); 759 spin_unlock_irqrestore(&epca_lock, flags);
848 } 760 }
849
850 /* Return how much room is left on card */ 761 /* Return how much room is left on card */
851 return remain; 762 return remain;
852 763
@@ -862,8 +773,7 @@ static int pc_chars_in_buffer(struct tty_struct *tty)
862 int remain; 773 int remain;
863 unsigned long flags; 774 unsigned long flags;
864 struct channel *ch; 775 struct channel *ch;
865 volatile struct board_chan *bc; 776 struct board_chan __iomem *bc;
866
867 777
868 /* --------------------------------------------------------- 778 /* ---------------------------------------------------------
869 verifyChannel returns the channel from the tty struct 779 verifyChannel returns the channel from the tty struct
@@ -873,34 +783,27 @@ static int pc_chars_in_buffer(struct tty_struct *tty)
873 if ((ch = verifyChannel(tty)) == NULL) 783 if ((ch = verifyChannel(tty)) == NULL)
874 return(0); 784 return(0);
875 785
876 save_flags(flags); 786 spin_lock_irqsave(&epca_lock, flags);
877 cli();
878 globalwinon(ch); 787 globalwinon(ch);
879 788
880 bc = ch->brdchan; 789 bc = ch->brdchan;
881 tail = bc->tout; 790 tail = readw(&bc->tout);
882 head = bc->tin; 791 head = readw(&bc->tin);
883 ctail = ch->mailbox->cout; 792 ctail = readw(&ch->mailbox->cout);
884 793
885 if (tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0) 794 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
886 chars = 0; 795 chars = 0;
887 else 796 else { /* Begin if some space on the card has been used */
888 { /* Begin if some space on the card has been used */ 797 head = readw(&bc->tin) & (ch->txbufsize - 1);
889
890 head = bc->tin & (ch->txbufsize - 1);
891 tail &= (ch->txbufsize - 1); 798 tail &= (ch->txbufsize - 1);
892
893 /* -------------------------------------------------------------- 799 /* --------------------------------------------------------------
894 The logic here is basically opposite of the above pc_write_room 800 The logic here is basically opposite of the above pc_write_room
895 here we are finding the amount of bytes in the buffer filled. 801 here we are finding the amount of bytes in the buffer filled.
896 Not the amount of bytes empty. 802 Not the amount of bytes empty.
897 ------------------------------------------------------------------- */ 803 ------------------------------------------------------------------- */
898
899 if ((remain = tail - head - 1) < 0 ) 804 if ((remain = tail - head - 1) < 0 )
900 remain += ch->txbufsize; 805 remain += ch->txbufsize;
901
902 chars = (int)(ch->txbufsize - remain); 806 chars = (int)(ch->txbufsize - remain);
903
904 /* ------------------------------------------------------------- 807 /* -------------------------------------------------------------
905 Make it possible to wakeup anything waiting for output 808 Make it possible to wakeup anything waiting for output
906 in tty_ioctl.c, etc. 809 in tty_ioctl.c, etc.
@@ -908,15 +811,12 @@ static int pc_chars_in_buffer(struct tty_struct *tty)
908 If not already set. Setup an event to indicate when the 811 If not already set. Setup an event to indicate when the
909 transmit buffer empties 812 transmit buffer empties
910 ----------------------------------------------------------------- */ 813 ----------------------------------------------------------------- */
911
912 if (!(ch->statusflags & EMPTYWAIT)) 814 if (!(ch->statusflags & EMPTYWAIT))
913 setup_empty_event(tty,ch); 815 setup_empty_event(tty,ch);
914 816
915 } /* End if some space on the card has been used */ 817 } /* End if some space on the card has been used */
916
917 memoff(ch); 818 memoff(ch);
918 restore_flags(flags); 819 spin_unlock_irqrestore(&epca_lock, flags);
919
920 /* Return number of characters residing on card. */ 820 /* Return number of characters residing on card. */
921 return(chars); 821 return(chars);
922 822
@@ -930,67 +830,46 @@ static void pc_flush_buffer(struct tty_struct *tty)
930 unsigned int tail; 830 unsigned int tail;
931 unsigned long flags; 831 unsigned long flags;
932 struct channel *ch; 832 struct channel *ch;
933 volatile struct board_chan *bc; 833 struct board_chan __iomem *bc;
934
935
936 /* --------------------------------------------------------- 834 /* ---------------------------------------------------------
937 verifyChannel returns the channel from the tty struct 835 verifyChannel returns the channel from the tty struct
938 if it is valid. This serves as a sanity check. 836 if it is valid. This serves as a sanity check.
939 ------------------------------------------------------------- */ 837 ------------------------------------------------------------- */
940
941 if ((ch = verifyChannel(tty)) == NULL) 838 if ((ch = verifyChannel(tty)) == NULL)
942 return; 839 return;
943 840
944 save_flags(flags); 841 spin_lock_irqsave(&epca_lock, flags);
945 cli();
946
947 globalwinon(ch); 842 globalwinon(ch);
948
949 bc = ch->brdchan; 843 bc = ch->brdchan;
950 tail = bc->tout; 844 tail = readw(&bc->tout);
951
952 /* Have FEP move tout pointer; effectively flushing transmit buffer */ 845 /* Have FEP move tout pointer; effectively flushing transmit buffer */
953
954 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0); 846 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
955
956 memoff(ch); 847 memoff(ch);
957 restore_flags(flags); 848 spin_unlock_irqrestore(&epca_lock, flags);
958
959 wake_up_interruptible(&tty->write_wait); 849 wake_up_interruptible(&tty->write_wait);
960 tty_wakeup(tty); 850 tty_wakeup(tty);
961
962} /* End pc_flush_buffer */ 851} /* End pc_flush_buffer */
963 852
964/* ------------------ Begin pc_flush_chars ---------------------- */ 853/* ------------------ Begin pc_flush_chars ---------------------- */
965 854
966static void pc_flush_chars(struct tty_struct *tty) 855static void pc_flush_chars(struct tty_struct *tty)
967{ /* Begin pc_flush_chars */ 856{ /* Begin pc_flush_chars */
968
969 struct channel * ch; 857 struct channel * ch;
970
971 /* --------------------------------------------------------- 858 /* ---------------------------------------------------------
972 verifyChannel returns the channel from the tty struct 859 verifyChannel returns the channel from the tty struct
973 if it is valid. This serves as a sanity check. 860 if it is valid. This serves as a sanity check.
974 ------------------------------------------------------------- */ 861 ------------------------------------------------------------- */
975 862 if ((ch = verifyChannel(tty)) != NULL) {
976 if ((ch = verifyChannel(tty)) != NULL)
977 {
978 unsigned long flags; 863 unsigned long flags;
979 864 spin_lock_irqsave(&epca_lock, flags);
980 save_flags(flags);
981 cli();
982
983 /* ---------------------------------------------------------------- 865 /* ----------------------------------------------------------------
984 If not already set and the transmitter is busy setup an event 866 If not already set and the transmitter is busy setup an event
985 to indicate when the transmit empties. 867 to indicate when the transmit empties.
986 ------------------------------------------------------------------- */ 868 ------------------------------------------------------------------- */
987
988 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT)) 869 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
989 setup_empty_event(tty,ch); 870 setup_empty_event(tty,ch);
990 871 spin_unlock_irqrestore(&epca_lock, flags);
991 restore_flags(flags);
992 } 872 }
993
994} /* End pc_flush_chars */ 873} /* End pc_flush_chars */
995 874
996/* ------------------ Begin block_til_ready ---------------------- */ 875/* ------------------ Begin block_til_ready ---------------------- */
@@ -998,14 +877,11 @@ static void pc_flush_chars(struct tty_struct *tty)
998static int block_til_ready(struct tty_struct *tty, 877static int block_til_ready(struct tty_struct *tty,
999 struct file *filp, struct channel *ch) 878 struct file *filp, struct channel *ch)
1000{ /* Begin block_til_ready */ 879{ /* Begin block_til_ready */
1001
1002 DECLARE_WAITQUEUE(wait,current); 880 DECLARE_WAITQUEUE(wait,current);
1003 int retval, do_clocal = 0; 881 int retval, do_clocal = 0;
1004 unsigned long flags; 882 unsigned long flags;
1005 883
1006 884 if (tty_hung_up_p(filp)) {
1007 if (tty_hung_up_p(filp))
1008 {
1009 if (ch->asyncflags & ASYNC_HUP_NOTIFY) 885 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1010 retval = -EAGAIN; 886 retval = -EAGAIN;
1011 else 887 else
@@ -1017,8 +893,7 @@ static int block_til_ready(struct tty_struct *tty,
1017 If the device is in the middle of being closed, then block 893 If the device is in the middle of being closed, then block
1018 until it's done, and then try again. 894 until it's done, and then try again.
1019 -------------------------------------------------------------------- */ 895 -------------------------------------------------------------------- */
1020 if (ch->asyncflags & ASYNC_CLOSING) 896 if (ch->asyncflags & ASYNC_CLOSING) {
1021 {
1022 interruptible_sleep_on(&ch->close_wait); 897 interruptible_sleep_on(&ch->close_wait);
1023 898
1024 if (ch->asyncflags & ASYNC_HUP_NOTIFY) 899 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
@@ -1027,43 +902,29 @@ static int block_til_ready(struct tty_struct *tty,
1027 return -ERESTARTSYS; 902 return -ERESTARTSYS;
1028 } 903 }
1029 904
1030 if (filp->f_flags & O_NONBLOCK) 905 if (filp->f_flags & O_NONBLOCK) {
1031 {
1032 /* ----------------------------------------------------------------- 906 /* -----------------------------------------------------------------
1033 If non-blocking mode is set, then make the check up front 907 If non-blocking mode is set, then make the check up front
1034 and then exit. 908 and then exit.
1035 -------------------------------------------------------------------- */ 909 -------------------------------------------------------------------- */
1036
1037 ch->asyncflags |= ASYNC_NORMAL_ACTIVE; 910 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1038
1039 return 0; 911 return 0;
1040 } 912 }
1041
1042
1043 if (tty->termios->c_cflag & CLOCAL) 913 if (tty->termios->c_cflag & CLOCAL)
1044 do_clocal = 1; 914 do_clocal = 1;
1045 915 /* Block waiting for the carrier detect and the line to become free */
1046 /* Block waiting for the carrier detect and the line to become free */
1047 916
1048 retval = 0; 917 retval = 0;
1049 add_wait_queue(&ch->open_wait, &wait); 918 add_wait_queue(&ch->open_wait, &wait);
1050 save_flags(flags);
1051 cli();
1052
1053 919
920 spin_lock_irqsave(&epca_lock, flags);
1054 /* We dec count so that pc_close will know when to free things */ 921 /* We dec count so that pc_close will know when to free things */
1055 if (!tty_hung_up_p(filp)) 922 if (!tty_hung_up_p(filp))
1056 ch->count--; 923 ch->count--;
1057
1058 restore_flags(flags);
1059
1060 ch->blocked_open++; 924 ch->blocked_open++;
1061
1062 while(1) 925 while(1)
1063 { /* Begin forever while */ 926 { /* Begin forever while */
1064
1065 set_current_state(TASK_INTERRUPTIBLE); 927 set_current_state(TASK_INTERRUPTIBLE);
1066
1067 if (tty_hung_up_p(filp) || 928 if (tty_hung_up_p(filp) ||
1068 !(ch->asyncflags & ASYNC_INITIALIZED)) 929 !(ch->asyncflags & ASYNC_INITIALIZED))
1069 { 930 {
@@ -1073,17 +934,14 @@ static int block_til_ready(struct tty_struct *tty,
1073 retval = -ERESTARTSYS; 934 retval = -ERESTARTSYS;
1074 break; 935 break;
1075 } 936 }
1076
1077 if (!(ch->asyncflags & ASYNC_CLOSING) && 937 if (!(ch->asyncflags & ASYNC_CLOSING) &&
1078 (do_clocal || (ch->imodem & ch->dcd))) 938 (do_clocal || (ch->imodem & ch->dcd)))
1079 break; 939 break;
1080 940 if (signal_pending(current)) {
1081 if (signal_pending(current))
1082 {
1083 retval = -ERESTARTSYS; 941 retval = -ERESTARTSYS;
1084 break; 942 break;
1085 } 943 }
1086 944 spin_unlock_irqrestore(&epca_lock, flags);
1087 /* --------------------------------------------------------------- 945 /* ---------------------------------------------------------------
1088 Allow someone else to be scheduled. We will occasionally go 946 Allow someone else to be scheduled. We will occasionally go
1089 through this loop until one of the above conditions change. 947 through this loop until one of the above conditions change.
@@ -1091,25 +949,23 @@ static int block_til_ready(struct tty_struct *tty,
1091 prevent this loop from hogging the cpu. 949 prevent this loop from hogging the cpu.
1092 ------------------------------------------------------------------ */ 950 ------------------------------------------------------------------ */
1093 schedule(); 951 schedule();
952 spin_lock_irqsave(&epca_lock, flags);
1094 953
1095 } /* End forever while */ 954 } /* End forever while */
1096 955
1097 current->state = TASK_RUNNING; 956 current->state = TASK_RUNNING;
1098 remove_wait_queue(&ch->open_wait, &wait); 957 remove_wait_queue(&ch->open_wait, &wait);
1099 cli();
1100 if (!tty_hung_up_p(filp)) 958 if (!tty_hung_up_p(filp))
1101 ch->count++; 959 ch->count++;
1102 restore_flags(flags);
1103
1104 ch->blocked_open--; 960 ch->blocked_open--;
1105 961
962 spin_unlock_irqrestore(&epca_lock, flags);
963
1106 if (retval) 964 if (retval)
1107 return retval; 965 return retval;
1108 966
1109 ch->asyncflags |= ASYNC_NORMAL_ACTIVE; 967 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1110
1111 return 0; 968 return 0;
1112
1113} /* End block_til_ready */ 969} /* End block_til_ready */
1114 970
1115/* ------------------ Begin pc_open ---------------------- */ 971/* ------------------ Begin pc_open ---------------------- */
@@ -1120,17 +976,12 @@ static int pc_open(struct tty_struct *tty, struct file * filp)
1120 struct channel *ch; 976 struct channel *ch;
1121 unsigned long flags; 977 unsigned long flags;
1122 int line, retval, boardnum; 978 int line, retval, boardnum;
1123 volatile struct board_chan *bc; 979 struct board_chan __iomem *bc;
1124 volatile unsigned int head; 980 unsigned int head;
1125 981
1126 line = tty->index; 982 line = tty->index;
1127 if (line < 0 || line >= nbdevs) 983 if (line < 0 || line >= nbdevs)
1128 { 984 return -ENODEV;
1129 printk(KERN_ERR "<Error> - pc_open : line out of range in pc_open\n");
1130 tty->driver_data = NULL;
1131 return(-ENODEV);
1132 }
1133
1134 985
1135 ch = &digi_channels[line]; 986 ch = &digi_channels[line];
1136 boardnum = ch->boardnum; 987 boardnum = ch->boardnum;
@@ -1143,78 +994,61 @@ static int pc_open(struct tty_struct *tty, struct file * filp)
1143 goes here. 994 goes here.
1144 ---------------------------------------------------------------------- */ 995 ---------------------------------------------------------------------- */
1145 996
1146 if (invalid_lilo_config) 997 if (invalid_lilo_config) {
1147 {
1148 if (setup_error_code & INVALID_BOARD_TYPE) 998 if (setup_error_code & INVALID_BOARD_TYPE)
1149 printk(KERN_ERR "<Error> - pc_open: Invalid board type specified in LILO command\n"); 999 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
1150
1151 if (setup_error_code & INVALID_NUM_PORTS) 1000 if (setup_error_code & INVALID_NUM_PORTS)
1152 printk(KERN_ERR "<Error> - pc_open: Invalid number of ports specified in LILO command\n"); 1001 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
1153
1154 if (setup_error_code & INVALID_MEM_BASE) 1002 if (setup_error_code & INVALID_MEM_BASE)
1155 printk(KERN_ERR "<Error> - pc_open: Invalid board memory address specified in LILO command\n"); 1003 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
1156
1157 if (setup_error_code & INVALID_PORT_BASE) 1004 if (setup_error_code & INVALID_PORT_BASE)
1158 printk(KERN_ERR "<Error> - pc_open: Invalid board port address specified in LILO command\n"); 1005 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
1159
1160 if (setup_error_code & INVALID_BOARD_STATUS) 1006 if (setup_error_code & INVALID_BOARD_STATUS)
1161 printk(KERN_ERR "<Error> - pc_open: Invalid board status specified in LILO command\n"); 1007 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
1162
1163 if (setup_error_code & INVALID_ALTPIN) 1008 if (setup_error_code & INVALID_ALTPIN)
1164 printk(KERN_ERR "<Error> - pc_open: Invalid board altpin specified in LILO command\n"); 1009 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
1165
1166 tty->driver_data = NULL; /* Mark this device as 'down' */ 1010 tty->driver_data = NULL; /* Mark this device as 'down' */
1167 return(-ENODEV); 1011 return -ENODEV;
1168 } 1012 }
1169 1013 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
1170 if ((boardnum >= num_cards) || (boards[boardnum].status == DISABLED))
1171 {
1172 tty->driver_data = NULL; /* Mark this device as 'down' */ 1014 tty->driver_data = NULL; /* Mark this device as 'down' */
1173 return(-ENODEV); 1015 return(-ENODEV);
1174 } 1016 }
1175 1017
1176 if (( bc = ch->brdchan) == 0) 1018 if ((bc = ch->brdchan) == 0) {
1177 {
1178 tty->driver_data = NULL; 1019 tty->driver_data = NULL;
1179 return(-ENODEV); 1020 return -ENODEV;
1180 } 1021 }
1181 1022
1023 spin_lock_irqsave(&epca_lock, flags);
1182 /* ------------------------------------------------------------------ 1024 /* ------------------------------------------------------------------
1183 Every time a channel is opened, increment a counter. This is 1025 Every time a channel is opened, increment a counter. This is
1184 necessary because we do not wish to flush and shutdown the channel 1026 necessary because we do not wish to flush and shutdown the channel
1185 until the last app holding the channel open, closes it. 1027 until the last app holding the channel open, closes it.
1186 --------------------------------------------------------------------- */ 1028 --------------------------------------------------------------------- */
1187
1188 ch->count++; 1029 ch->count++;
1189
1190 /* ---------------------------------------------------------------- 1030 /* ----------------------------------------------------------------
1191 Set a kernel structures pointer to our local channel 1031 Set a kernel structures pointer to our local channel
1192 structure. This way we can get to it when passed only 1032 structure. This way we can get to it when passed only
1193 a tty struct. 1033 a tty struct.
1194 ------------------------------------------------------------------ */ 1034 ------------------------------------------------------------------ */
1195
1196 tty->driver_data = ch; 1035 tty->driver_data = ch;
1197
1198 /* ---------------------------------------------------------------- 1036 /* ----------------------------------------------------------------
1199 If this is the first time the channel has been opened, initialize 1037 If this is the first time the channel has been opened, initialize
1200 the tty->termios struct otherwise let pc_close handle it. 1038 the tty->termios struct otherwise let pc_close handle it.
1201 -------------------------------------------------------------------- */ 1039 -------------------------------------------------------------------- */
1202
1203 save_flags(flags);
1204 cli();
1205
1206 globalwinon(ch); 1040 globalwinon(ch);
1207 ch->statusflags = 0; 1041 ch->statusflags = 0;
1208 1042
1209 /* Save boards current modem status */ 1043 /* Save boards current modem status */
1210 ch->imodem = bc->mstat; 1044 ch->imodem = readb(&bc->mstat);
1211 1045
1212 /* ---------------------------------------------------------------- 1046 /* ----------------------------------------------------------------
1213 Set receive head and tail ptrs to each other. This indicates 1047 Set receive head and tail ptrs to each other. This indicates
1214 no data available to read. 1048 no data available to read.
1215 ----------------------------------------------------------------- */ 1049 ----------------------------------------------------------------- */
1216 head = bc->rin; 1050 head = readw(&bc->rin);
1217 bc->rout = head; 1051 writew(head, &bc->rout);
1218 1052
1219 /* Set the channels associated tty structure */ 1053 /* Set the channels associated tty structure */
1220 ch->tty = tty; 1054 ch->tty = tty;
@@ -1224,122 +1058,74 @@ static int pc_open(struct tty_struct *tty, struct file * filp)
1224 issues, etc.... It effect both control flags and input flags. 1058 issues, etc.... It effect both control flags and input flags.
1225 -------------------------------------------------------------------- */ 1059 -------------------------------------------------------------------- */
1226 epcaparam(tty,ch); 1060 epcaparam(tty,ch);
1227
1228 ch->asyncflags |= ASYNC_INITIALIZED; 1061 ch->asyncflags |= ASYNC_INITIALIZED;
1229 memoff(ch); 1062 memoff(ch);
1230 1063 spin_unlock_irqrestore(&epca_lock, flags);
1231 restore_flags(flags);
1232 1064
1233 retval = block_til_ready(tty, filp, ch); 1065 retval = block_til_ready(tty, filp, ch);
1234 if (retval) 1066 if (retval)
1235 {
1236 return retval; 1067 return retval;
1237 }
1238
1239 /* ------------------------------------------------------------- 1068 /* -------------------------------------------------------------
1240 Set this again in case a hangup set it to zero while this 1069 Set this again in case a hangup set it to zero while this
1241 open() was waiting for the line... 1070 open() was waiting for the line...
1242 --------------------------------------------------------------- */ 1071 --------------------------------------------------------------- */
1072 spin_lock_irqsave(&epca_lock, flags);
1243 ch->tty = tty; 1073 ch->tty = tty;
1244
1245 save_flags(flags);
1246 cli();
1247 globalwinon(ch); 1074 globalwinon(ch);
1248
1249 /* Enable Digi Data events */ 1075 /* Enable Digi Data events */
1250 bc->idata = 1; 1076 writeb(1, &bc->idata);
1251
1252 memoff(ch); 1077 memoff(ch);
1253 restore_flags(flags); 1078 spin_unlock_irqrestore(&epca_lock, flags);
1254
1255 return 0; 1079 return 0;
1256
1257} /* End pc_open */ 1080} /* End pc_open */
1258 1081
1259#ifdef MODULE
1260static int __init epca_module_init(void) 1082static int __init epca_module_init(void)
1261{ /* Begin init_module */ 1083{ /* Begin init_module */
1262 1084 return pc_init();
1263 unsigned long flags;
1264
1265 save_flags(flags);
1266 cli();
1267
1268 pc_init();
1269
1270 restore_flags(flags);
1271
1272 return(0);
1273} 1085}
1274 1086
1275module_init(epca_module_init); 1087module_init(epca_module_init);
1276#endif
1277 1088
1278#ifdef ENABLE_PCI
1279static struct pci_driver epca_driver; 1089static struct pci_driver epca_driver;
1280#endif
1281
1282#ifdef MODULE
1283/* -------------------- Begin cleanup_module ---------------------- */
1284 1090
1285static void __exit epca_module_exit(void) 1091static void __exit epca_module_exit(void)
1286{ 1092{
1287
1288 int count, crd; 1093 int count, crd;
1289 struct board_info *bd; 1094 struct board_info *bd;
1290 struct channel *ch; 1095 struct channel *ch;
1291 unsigned long flags;
1292 1096
1293 del_timer_sync(&epca_timer); 1097 del_timer_sync(&epca_timer);
1294 1098
1295 save_flags(flags);
1296 cli();
1297
1298 if ((tty_unregister_driver(pc_driver)) || 1099 if ((tty_unregister_driver(pc_driver)) ||
1299 (tty_unregister_driver(pc_info))) 1100 (tty_unregister_driver(pc_info)))
1300 { 1101 {
1301 printk(KERN_WARNING "<Error> - DIGI : cleanup_module failed to un-register tty driver\n"); 1102 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1302 restore_flags(flags);
1303 return; 1103 return;
1304 } 1104 }
1305 put_tty_driver(pc_driver); 1105 put_tty_driver(pc_driver);
1306 put_tty_driver(pc_info); 1106 put_tty_driver(pc_info);
1307 1107
1308 for (crd = 0; crd < num_cards; crd++) 1108 for (crd = 0; crd < num_cards; crd++) { /* Begin for each card */
1309 { /* Begin for each card */
1310
1311 bd = &boards[crd]; 1109 bd = &boards[crd];
1312
1313 if (!bd) 1110 if (!bd)
1314 { /* Begin sanity check */ 1111 { /* Begin sanity check */
1315 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n"); 1112 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1316 return; 1113 return;
1317 } /* End sanity check */ 1114 } /* End sanity check */
1318 1115 ch = card_ptr[crd];
1319 ch = card_ptr[crd];
1320
1321 for (count = 0; count < bd->numports; count++, ch++) 1116 for (count = 0; count < bd->numports; count++, ch++)
1322 { /* Begin for each port */ 1117 { /* Begin for each port */
1323 1118 if (ch) {
1324 if (ch)
1325 {
1326 if (ch->tty) 1119 if (ch->tty)
1327 tty_hangup(ch->tty); 1120 tty_hangup(ch->tty);
1328 kfree(ch->tmp_buf); 1121 kfree(ch->tmp_buf);
1329 } 1122 }
1330
1331 } /* End for each port */ 1123 } /* End for each port */
1332 } /* End for each card */ 1124 } /* End for each card */
1333
1334#ifdef ENABLE_PCI
1335 pci_unregister_driver (&epca_driver); 1125 pci_unregister_driver (&epca_driver);
1336#endif
1337
1338 restore_flags(flags);
1339
1340} 1126}
1127
1341module_exit(epca_module_exit); 1128module_exit(epca_module_exit);
1342#endif /* MODULE */
1343 1129
1344static struct tty_operations pc_ops = { 1130static struct tty_operations pc_ops = {
1345 .open = pc_open, 1131 .open = pc_open,
@@ -1371,34 +1157,15 @@ static struct tty_operations info_ops = {
1371 1157
1372/* ------------------ Begin pc_init ---------------------- */ 1158/* ------------------ Begin pc_init ---------------------- */
1373 1159
1374int __init pc_init(void) 1160static int __init pc_init(void)
1375{ /* Begin pc_init */ 1161{ /* Begin pc_init */
1376
1377 /* ----------------------------------------------------------------
1378 pc_init is called by the operating system during boot up prior to
1379 any open calls being made. In the older versions of Linux (Prior
1380 to 2.0.0) an entry is made into tty_io.c. A pointer to the last
1381 memory location (from kernel space) used (kmem_start) is passed
1382 to pc_init. It is pc_inits responsibility to modify this value
1383 for any memory that the Digi driver might need and then return
1384 this value to the operating system. For example if the driver
1385 wishes to allocate 1K of kernel memory, pc_init would return
1386 (kmem_start + 1024). This memory (Between kmem_start and kmem_start
1387 + 1024) would then be available for use exclusively by the driver.
1388 In this case our driver does not allocate any of this kernel
1389 memory.
1390 ------------------------------------------------------------------*/
1391
1392 ulong flags;
1393 int crd; 1162 int crd;
1394 struct board_info *bd; 1163 struct board_info *bd;
1395 unsigned char board_id = 0; 1164 unsigned char board_id = 0;
1396 1165
1397#ifdef ENABLE_PCI
1398 int pci_boards_found, pci_count; 1166 int pci_boards_found, pci_count;
1399 1167
1400 pci_count = 0; 1168 pci_count = 0;
1401#endif /* ENABLE_PCI */
1402 1169
1403 pc_driver = alloc_tty_driver(MAX_ALLOC); 1170 pc_driver = alloc_tty_driver(MAX_ALLOC);
1404 if (!pc_driver) 1171 if (!pc_driver)
@@ -1416,8 +1183,7 @@ int __init pc_init(void)
1416 Note : If LILO has ran epca_setup then epca_setup will handle defining 1183 Note : If LILO has ran epca_setup then epca_setup will handle defining
1417 num_cards as well as copying the data into the board structure. 1184 num_cards as well as copying the data into the board structure.
1418 -------------------------------------------------------------------------- */ 1185 -------------------------------------------------------------------------- */
1419 if (!liloconfig) 1186 if (!liloconfig) { /* Begin driver has been configured via. epcaconfig */
1420 { /* Begin driver has been configured via. epcaconfig */
1421 1187
1422 nbdevs = NBDEVS; 1188 nbdevs = NBDEVS;
1423 num_cards = NUMCARDS; 1189 num_cards = NUMCARDS;
@@ -1440,8 +1206,6 @@ int __init pc_init(void)
1440 1206
1441 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION); 1207 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1442 1208
1443#ifdef ENABLE_PCI
1444
1445 /* ------------------------------------------------------------------ 1209 /* ------------------------------------------------------------------
1446 NOTE : This code assumes that the number of ports found in 1210 NOTE : This code assumes that the number of ports found in
1447 the boards array is correct. This could be wrong if 1211 the boards array is correct. This could be wrong if
@@ -1467,8 +1231,6 @@ int __init pc_init(void)
1467 pci_boards_found += init_PCI(); 1231 pci_boards_found += init_PCI();
1468 num_cards += pci_boards_found; 1232 num_cards += pci_boards_found;
1469 1233
1470#endif /* ENABLE_PCI */
1471
1472 pc_driver->owner = THIS_MODULE; 1234 pc_driver->owner = THIS_MODULE;
1473 pc_driver->name = "ttyD"; 1235 pc_driver->name = "ttyD";
1474 pc_driver->devfs_name = "tts/D"; 1236 pc_driver->devfs_name = "tts/D";
@@ -1499,9 +1261,6 @@ int __init pc_init(void)
1499 tty_set_operations(pc_info, &info_ops); 1261 tty_set_operations(pc_info, &info_ops);
1500 1262
1501 1263
1502 save_flags(flags);
1503 cli();
1504
1505 for (crd = 0; crd < num_cards; crd++) 1264 for (crd = 0; crd < num_cards; crd++)
1506 { /* Begin for each card */ 1265 { /* Begin for each card */
1507 1266
@@ -1610,11 +1369,7 @@ int __init pc_init(void)
1610 if ((board_id & 0x30) == 0x30) 1369 if ((board_id & 0x30) == 0x30)
1611 bd->memory_seg = 0x8000; 1370 bd->memory_seg = 0x8000;
1612 1371
1613 } /* End it is an XI card */ 1372 } else printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1614 else
1615 {
1616 printk(KERN_ERR "<Error> - Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1617 }
1618 break; 1373 break;
1619 1374
1620 } /* End switch on bd->type */ 1375 } /* End switch on bd->type */
@@ -1634,9 +1389,6 @@ int __init pc_init(void)
1634 init_timer(&epca_timer); 1389 init_timer(&epca_timer);
1635 epca_timer.function = epcapoll; 1390 epca_timer.function = epcapoll;
1636 mod_timer(&epca_timer, jiffies + HZ/25); 1391 mod_timer(&epca_timer, jiffies + HZ/25);
1637
1638 restore_flags(flags);
1639
1640 return 0; 1392 return 0;
1641 1393
1642} /* End pc_init */ 1394} /* End pc_init */
@@ -1647,10 +1399,10 @@ static void post_fep_init(unsigned int crd)
1647{ /* Begin post_fep_init */ 1399{ /* Begin post_fep_init */
1648 1400
1649 int i; 1401 int i;
1650 unchar *memaddr; 1402 void __iomem *memaddr;
1651 volatile struct global_data *gd; 1403 struct global_data __iomem *gd;
1652 struct board_info *bd; 1404 struct board_info *bd;
1653 volatile struct board_chan *bc; 1405 struct board_chan __iomem *bc;
1654 struct channel *ch; 1406 struct channel *ch;
1655 int shrinkmem = 0, lowwater ; 1407 int shrinkmem = 0, lowwater ;
1656 1408
@@ -1669,9 +1421,7 @@ static void post_fep_init(unsigned int crd)
1669 after DIGI_INIT has been called will return the proper values. 1421 after DIGI_INIT has been called will return the proper values.
1670 ------------------------------------------------------------------- */ 1422 ------------------------------------------------------------------- */
1671 1423
1672 if (bd->type >= PCIXEM) /* If the board in question is PCI */ 1424 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
1673 { /* Begin get PCI number of ports */
1674
1675 /* -------------------------------------------------------------------- 1425 /* --------------------------------------------------------------------
1676 Below we use XEMPORTS as a memory offset regardless of which PCI 1426 Below we use XEMPORTS as a memory offset regardless of which PCI
1677 card it is. This is because all of the supported PCI cards have 1427 card it is. This is because all of the supported PCI cards have
@@ -1685,15 +1435,15 @@ static void post_fep_init(unsigned int crd)
1685 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes 1435 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1686 if the box in question is a XEM or CX)). 1436 if the box in question is a XEM or CX)).
1687 ------------------------------------------------------------------------ */ 1437 ------------------------------------------------------------------------ */
1688 1438 /* PCI cards are already remapped at this point ISA are not */
1689 bd->numports = (unsigned short)*(unsigned char *)bus_to_virt((unsigned long) 1439 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1690 (bd->re_map_membase + XEMPORTS));
1691
1692
1693 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports"); 1440 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1694 nbdevs += (bd->numports); 1441 nbdevs += (bd->numports);
1695 1442 } else {
1696 } /* End get PCI number of ports */ 1443 /* Fix up the mappings for ISA/EISA etc */
1444 /* FIXME: 64K - can we be smarter ? */
1445 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1446 }
1697 1447
1698 if (crd != 0) 1448 if (crd != 0)
1699 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports; 1449 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
@@ -1701,19 +1451,9 @@ static void post_fep_init(unsigned int crd)
1701 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */ 1451 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1702 1452
1703 ch = card_ptr[crd]; 1453 ch = card_ptr[crd];
1704
1705
1706 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range"); 1454 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1707 1455
1708 memaddr = (unchar *)bd->re_map_membase; 1456 memaddr = bd->re_map_membase;
1709
1710 /*
1711 The below command is necessary because newer kernels (2.1.x and
1712 up) do not have a 1:1 virtual to physical mapping. The below
1713 call adjust for that.
1714 */
1715
1716 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
1717 1457
1718 /* ----------------------------------------------------------------- 1458 /* -----------------------------------------------------------------
1719 The below assignment will set bc to point at the BEGINING of 1459 The below assignment will set bc to point at the BEGINING of
@@ -1721,7 +1461,7 @@ static void post_fep_init(unsigned int crd)
1721 8 and 64 of these structures. 1461 8 and 64 of these structures.
1722 -------------------------------------------------------------------- */ 1462 -------------------------------------------------------------------- */
1723 1463
1724 bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT); 1464 bc = memaddr + CHANSTRUCT;
1725 1465
1726 /* ------------------------------------------------------------------- 1466 /* -------------------------------------------------------------------
1727 The below assignment will set gd to point at the BEGINING of 1467 The below assignment will set gd to point at the BEGINING of
@@ -1730,20 +1470,18 @@ static void post_fep_init(unsigned int crd)
1730 pointer begins at 0xd10. 1470 pointer begins at 0xd10.
1731 ---------------------------------------------------------------------- */ 1471 ---------------------------------------------------------------------- */
1732 1472
1733 gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL); 1473 gd = memaddr + GLOBAL;
1734 1474
1735 /* -------------------------------------------------------------------- 1475 /* --------------------------------------------------------------------
1736 XEPORTS (address 0xc22) points at the number of channels the 1476 XEPORTS (address 0xc22) points at the number of channels the
1737 card supports. (For 64XE, XI, XEM, and XR use 0xc02) 1477 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1738 ----------------------------------------------------------------------- */ 1478 ----------------------------------------------------------------------- */
1739 1479
1740 if (((bd->type == PCXEVE) | (bd->type == PCXE)) && 1480 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
1741 (*(ushort *)((ulong)memaddr + XEPORTS) < 3))
1742 shrinkmem = 1; 1481 shrinkmem = 1;
1743 if (bd->type < PCIXEM) 1482 if (bd->type < PCIXEM)
1744 if (!request_region((int)bd->port, 4, board_desc[bd->type])) 1483 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1745 return; 1484 return;
1746
1747 memwinon(bd, 0); 1485 memwinon(bd, 0);
1748 1486
1749 /* -------------------------------------------------------------------- 1487 /* --------------------------------------------------------------------
@@ -1753,17 +1491,17 @@ static void post_fep_init(unsigned int crd)
1753 1491
1754 /* For every port on the card do ..... */ 1492 /* For every port on the card do ..... */
1755 1493
1756 for (i = 0; i < bd->numports; i++, ch++, bc++) 1494 for (i = 0; i < bd->numports; i++, ch++, bc++) { /* Begin for each port */
1757 { /* Begin for each port */ 1495 unsigned long flags;
1496 u16 tseg, rseg;
1758 1497
1759 ch->brdchan = bc; 1498 ch->brdchan = bc;
1760 ch->mailbox = gd; 1499 ch->mailbox = gd;
1761 INIT_WORK(&ch->tqueue, do_softint, ch); 1500 INIT_WORK(&ch->tqueue, do_softint, ch);
1762 ch->board = &boards[crd]; 1501 ch->board = &boards[crd];
1763 1502
1764 switch (bd->type) 1503 spin_lock_irqsave(&epca_lock, flags);
1765 { /* Begin switch bd->type */ 1504 switch (bd->type) {
1766
1767 /* ---------------------------------------------------------------- 1505 /* ----------------------------------------------------------------
1768 Since some of the boards use different bitmaps for their 1506 Since some of the boards use different bitmaps for their
1769 control signals we cannot hard code these values and retain 1507 control signals we cannot hard code these values and retain
@@ -1796,14 +1534,12 @@ static void post_fep_init(unsigned int crd)
1796 1534
1797 } /* End switch bd->type */ 1535 } /* End switch bd->type */
1798 1536
1799 if (boards[crd].altpin) 1537 if (boards[crd].altpin) {
1800 {
1801 ch->dsr = ch->m_dcd; 1538 ch->dsr = ch->m_dcd;
1802 ch->dcd = ch->m_dsr; 1539 ch->dcd = ch->m_dsr;
1803 ch->digiext.digi_flags |= DIGI_ALTPIN; 1540 ch->digiext.digi_flags |= DIGI_ALTPIN;
1804 } 1541 }
1805 else 1542 else {
1806 {
1807 ch->dcd = ch->m_dcd; 1543 ch->dcd = ch->m_dcd;
1808 ch->dsr = ch->m_dsr; 1544 ch->dsr = ch->m_dsr;
1809 } 1545 }
@@ -1813,57 +1549,58 @@ static void post_fep_init(unsigned int crd)
1813 ch->magic = EPCA_MAGIC; 1549 ch->magic = EPCA_MAGIC;
1814 ch->tty = NULL; 1550 ch->tty = NULL;
1815 1551
1816 if (shrinkmem) 1552 if (shrinkmem) {
1817 {
1818 fepcmd(ch, SETBUFFER, 32, 0, 0, 0); 1553 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1819 shrinkmem = 0; 1554 shrinkmem = 0;
1820 } 1555 }
1821 1556
1822 switch (bd->type) 1557 tseg = readw(&bc->tseg);
1823 { /* Begin switch bd->type */ 1558 rseg = readw(&bc->rseg);
1559
1560 switch (bd->type) {
1824 1561
1825 case PCIXEM: 1562 case PCIXEM:
1826 case PCIXRJ: 1563 case PCIXRJ:
1827 case PCIXR: 1564 case PCIXR:
1828 /* Cover all the 2MEG cards */ 1565 /* Cover all the 2MEG cards */
1829 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x1fffff); 1566 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1830 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x1fffff); 1567 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1831 ch->txwin = FEPWIN | ((bc->tseg) >> 11); 1568 ch->txwin = FEPWIN | (tseg >> 11);
1832 ch->rxwin = FEPWIN | ((bc->rseg) >> 11); 1569 ch->rxwin = FEPWIN | (rseg >> 11);
1833 break; 1570 break;
1834 1571
1835 case PCXEM: 1572 case PCXEM:
1836 case EISAXEM: 1573 case EISAXEM:
1837 /* Cover all the 32K windowed cards */ 1574 /* Cover all the 32K windowed cards */
1838 /* Mask equal to window size - 1 */ 1575 /* Mask equal to window size - 1 */
1839 ch->txptr = memaddr + (((bc->tseg) << 4) & 0x7fff); 1576 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1840 ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x7fff); 1577 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1841 ch->txwin = FEPWIN | ((bc->tseg) >> 11); 1578 ch->txwin = FEPWIN | (tseg >> 11);
1842 ch->rxwin = FEPWIN | ((bc->rseg) >> 11); 1579 ch->rxwin = FEPWIN | (rseg >> 11);
1843 break; 1580 break;
1844 1581
1845 case PCXEVE: 1582 case PCXEVE:
1846 case PCXE: 1583 case PCXE:
1847 ch->txptr = memaddr + (((bc->tseg - bd->memory_seg) << 4) & 0x1fff); 1584 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
1848 ch->txwin = FEPWIN | ((bc->tseg - bd->memory_seg) >> 9); 1585 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1849 ch->rxptr = memaddr + (((bc->rseg - bd->memory_seg) << 4) & 0x1fff); 1586 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
1850 ch->rxwin = FEPWIN | ((bc->rseg - bd->memory_seg) >>9 ); 1587 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
1851 break; 1588 break;
1852 1589
1853 case PCXI: 1590 case PCXI:
1854 case PC64XE: 1591 case PC64XE:
1855 ch->txptr = memaddr + ((bc->tseg - bd->memory_seg) << 4); 1592 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1856 ch->rxptr = memaddr + ((bc->rseg - bd->memory_seg) << 4); 1593 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1857 ch->txwin = ch->rxwin = 0; 1594 ch->txwin = ch->rxwin = 0;
1858 break; 1595 break;
1859 1596
1860 } /* End switch bd->type */ 1597 } /* End switch bd->type */
1861 1598
1862 ch->txbufhead = 0; 1599 ch->txbufhead = 0;
1863 ch->txbufsize = bc->tmax + 1; 1600 ch->txbufsize = readw(&bc->tmax) + 1;
1864 1601
1865 ch->rxbufhead = 0; 1602 ch->rxbufhead = 0;
1866 ch->rxbufsize = bc->rmax + 1; 1603 ch->rxbufsize = readw(&bc->rmax) + 1;
1867 1604
1868 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2); 1605 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1869 1606
@@ -1878,13 +1615,13 @@ static void post_fep_init(unsigned int crd)
1878 1615
1879 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0); 1616 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1880 1617
1881 bc->edelay = 100; 1618 writew(100, &bc->edelay);
1882 bc->idata = 1; 1619 writeb(1, &bc->idata);
1883 1620
1884 ch->startc = bc->startc; 1621 ch->startc = readb(&bc->startc);
1885 ch->stopc = bc->stopc; 1622 ch->stopc = readb(&bc->stopc);
1886 ch->startca = bc->startca; 1623 ch->startca = readb(&bc->startca);
1887 ch->stopca = bc->stopca; 1624 ch->stopca = readb(&bc->stopca);
1888 1625
1889 ch->fepcflag = 0; 1626 ch->fepcflag = 0;
1890 ch->fepiflag = 0; 1627 ch->fepiflag = 0;
@@ -1899,27 +1636,23 @@ static void post_fep_init(unsigned int crd)
1899 ch->blocked_open = 0; 1636 ch->blocked_open = 0;
1900 init_waitqueue_head(&ch->open_wait); 1637 init_waitqueue_head(&ch->open_wait);
1901 init_waitqueue_head(&ch->close_wait); 1638 init_waitqueue_head(&ch->close_wait);
1639
1640 spin_unlock_irqrestore(&epca_lock, flags);
1641
1902 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL); 1642 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
1903 if (!(ch->tmp_buf)) 1643 if (!ch->tmp_buf) {
1904 {
1905 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i); 1644 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
1906 release_region((int)bd->port, 4); 1645 release_region((int)bd->port, 4);
1907 while(i-- > 0) 1646 while(i-- > 0)
1908 kfree((ch--)->tmp_buf); 1647 kfree((ch--)->tmp_buf);
1909 return; 1648 return;
1910 } 1649 } else
1911 else
1912 memset((void *)ch->tmp_buf,0,ch->txbufsize); 1650 memset((void *)ch->tmp_buf,0,ch->txbufsize);
1913 } /* End for each port */ 1651 } /* End for each port */
1914 1652
1915 printk(KERN_INFO 1653 printk(KERN_INFO
1916 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n", 1654 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1917 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports); 1655 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
1918 sprintf(mesg,
1919 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1920 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
1921 console_print(mesg);
1922
1923 memwinoff(bd, 0); 1656 memwinoff(bd, 0);
1924 1657
1925} /* End post_fep_init */ 1658} /* End post_fep_init */
@@ -1943,9 +1676,6 @@ static void epcapoll(unsigned long ignored)
1943 buffer empty) and acts on those events. 1676 buffer empty) and acts on those events.
1944 ----------------------------------------------------------------------- */ 1677 ----------------------------------------------------------------------- */
1945 1678
1946 save_flags(flags);
1947 cli();
1948
1949 for (crd = 0; crd < num_cards; crd++) 1679 for (crd = 0; crd < num_cards; crd++)
1950 { /* Begin for each card */ 1680 { /* Begin for each card */
1951 1681
@@ -1961,6 +1691,8 @@ static void epcapoll(unsigned long ignored)
1961 some legacy boards. 1691 some legacy boards.
1962 ---------------------------------------------------------------- */ 1692 ---------------------------------------------------------------- */
1963 1693
1694 spin_lock_irqsave(&epca_lock, flags);
1695
1964 assertmemoff(ch); 1696 assertmemoff(ch);
1965 1697
1966 globalwinon(ch); 1698 globalwinon(ch);
@@ -1970,21 +1702,19 @@ static void epcapoll(unsigned long ignored)
1970 the transmit or receive queue. 1702 the transmit or receive queue.
1971 ------------------------------------------------------------------- */ 1703 ------------------------------------------------------------------- */
1972 1704
1973 head = ch->mailbox->ein; 1705 head = readw(&ch->mailbox->ein);
1974 tail = ch->mailbox->eout; 1706 tail = readw(&ch->mailbox->eout);
1975 1707
1976 /* If head isn't equal to tail we have an event */ 1708 /* If head isn't equal to tail we have an event */
1977 1709
1978 if (head != tail) 1710 if (head != tail)
1979 doevent(crd); 1711 doevent(crd);
1980
1981 memoff(ch); 1712 memoff(ch);
1982 1713
1983 } /* End for each card */ 1714 spin_unlock_irqrestore(&epca_lock, flags);
1984 1715
1716 } /* End for each card */
1985 mod_timer(&epca_timer, jiffies + (HZ / 25)); 1717 mod_timer(&epca_timer, jiffies + (HZ / 25));
1986
1987 restore_flags(flags);
1988} /* End epcapoll */ 1718} /* End epcapoll */
1989 1719
1990/* --------------------- Begin doevent ------------------------ */ 1720/* --------------------- Begin doevent ------------------------ */
@@ -1992,53 +1722,42 @@ static void epcapoll(unsigned long ignored)
1992static void doevent(int crd) 1722static void doevent(int crd)
1993{ /* Begin doevent */ 1723{ /* Begin doevent */
1994 1724
1995 volatile unchar *eventbuf; 1725 void __iomem *eventbuf;
1996 struct channel *ch, *chan0; 1726 struct channel *ch, *chan0;
1997 static struct tty_struct *tty; 1727 static struct tty_struct *tty;
1998 volatile struct board_info *bd; 1728 struct board_info *bd;
1999 volatile struct board_chan *bc; 1729 struct board_chan __iomem *bc;
2000 register volatile unsigned int tail, head; 1730 unsigned int tail, head;
2001 register int event, channel; 1731 int event, channel;
2002 register int mstat, lstat; 1732 int mstat, lstat;
2003 1733
2004 /* ------------------------------------------------------------------- 1734 /* -------------------------------------------------------------------
2005 This subroutine is called by epcapoll when an event is detected 1735 This subroutine is called by epcapoll when an event is detected
2006 in the event queue. This routine responds to those events. 1736 in the event queue. This routine responds to those events.
2007 --------------------------------------------------------------------- */ 1737 --------------------------------------------------------------------- */
2008
2009 bd = &boards[crd]; 1738 bd = &boards[crd];
2010 1739
2011 chan0 = card_ptr[crd]; 1740 chan0 = card_ptr[crd];
2012 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range"); 1741 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
2013
2014 assertgwinon(chan0); 1742 assertgwinon(chan0);
2015 1743 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein)))
2016 while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein))
2017 { /* Begin while something in event queue */ 1744 { /* Begin while something in event queue */
2018
2019 assertgwinon(chan0); 1745 assertgwinon(chan0);
2020 1746 eventbuf = bd->re_map_membase + tail + ISTART;
2021 eventbuf = (volatile unchar *)bus_to_virt((ulong)(bd->re_map_membase + tail + ISTART));
2022
2023 /* Get the channel the event occurred on */ 1747 /* Get the channel the event occurred on */
2024 channel = eventbuf[0]; 1748 channel = readb(eventbuf);
2025
2026 /* Get the actual event code that occurred */ 1749 /* Get the actual event code that occurred */
2027 event = eventbuf[1]; 1750 event = readb(eventbuf + 1);
2028
2029 /* ---------------------------------------------------------------- 1751 /* ----------------------------------------------------------------
2030 The two assignments below get the current modem status (mstat) 1752 The two assignments below get the current modem status (mstat)
2031 and the previous modem status (lstat). These are useful becuase 1753 and the previous modem status (lstat). These are useful becuase
2032 an event could signal a change in modem signals itself. 1754 an event could signal a change in modem signals itself.
2033 ------------------------------------------------------------------- */ 1755 ------------------------------------------------------------------- */
2034 1756 mstat = readb(eventbuf + 2);
2035 mstat = eventbuf[2]; 1757 lstat = readb(eventbuf + 3);
2036 lstat = eventbuf[3];
2037 1758
2038 ch = chan0 + channel; 1759 ch = chan0 + channel;
2039 1760 if ((unsigned)channel >= bd->numports || !ch) {
2040 if ((unsigned)channel >= bd->numports || !ch)
2041 {
2042 if (channel >= bd->numports) 1761 if (channel >= bd->numports)
2043 ch = chan0; 1762 ch = chan0;
2044 bc = ch->brdchan; 1763 bc = ch->brdchan;
@@ -2048,97 +1767,53 @@ static void doevent(int crd)
2048 if ((bc = ch->brdchan) == NULL) 1767 if ((bc = ch->brdchan) == NULL)
2049 goto next; 1768 goto next;
2050 1769
2051 if (event & DATA_IND) 1770 if (event & DATA_IND) { /* Begin DATA_IND */
2052 { /* Begin DATA_IND */
2053
2054 receive_data(ch); 1771 receive_data(ch);
2055 assertgwinon(ch); 1772 assertgwinon(ch);
2056
2057 } /* End DATA_IND */ 1773 } /* End DATA_IND */
2058 /* else *//* Fix for DCD transition missed bug */ 1774 /* else *//* Fix for DCD transition missed bug */
2059 if (event & MODEMCHG_IND) 1775 if (event & MODEMCHG_IND) { /* Begin MODEMCHG_IND */
2060 { /* Begin MODEMCHG_IND */
2061
2062 /* A modem signal change has been indicated */ 1776 /* A modem signal change has been indicated */
2063
2064 ch->imodem = mstat; 1777 ch->imodem = mstat;
2065 1778 if (ch->asyncflags & ASYNC_CHECK_CD) {
2066 if (ch->asyncflags & ASYNC_CHECK_CD)
2067 {
2068 if (mstat & ch->dcd) /* We are now receiving dcd */ 1779 if (mstat & ch->dcd) /* We are now receiving dcd */
2069 wake_up_interruptible(&ch->open_wait); 1780 wake_up_interruptible(&ch->open_wait);
2070 else 1781 else
2071 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */ 1782 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
2072 } 1783 }
2073
2074 } /* End MODEMCHG_IND */ 1784 } /* End MODEMCHG_IND */
2075
2076 tty = ch->tty; 1785 tty = ch->tty;
2077 if (tty) 1786 if (tty) { /* Begin if valid tty */
2078 { /* Begin if valid tty */ 1787 if (event & BREAK_IND) { /* Begin if BREAK_IND */
2079
2080 if (event & BREAK_IND)
2081 { /* Begin if BREAK_IND */
2082
2083 /* A break has been indicated */ 1788 /* A break has been indicated */
2084
2085 tty->flip.count++; 1789 tty->flip.count++;
2086 *tty->flip.flag_buf_ptr++ = TTY_BREAK; 1790 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2087
2088 *tty->flip.char_buf_ptr++ = 0; 1791 *tty->flip.char_buf_ptr++ = 0;
2089
2090 tty_schedule_flip(tty); 1792 tty_schedule_flip(tty);
2091 1793 } else if (event & LOWTX_IND) { /* Begin LOWTX_IND */
2092 } /* End if BREAK_IND */
2093 else
2094 if (event & LOWTX_IND)
2095 { /* Begin LOWTX_IND */
2096
2097 if (ch->statusflags & LOWWAIT) 1794 if (ch->statusflags & LOWWAIT)
2098 { /* Begin if LOWWAIT */ 1795 { /* Begin if LOWWAIT */
2099
2100 ch->statusflags &= ~LOWWAIT; 1796 ch->statusflags &= ~LOWWAIT;
2101 tty_wakeup(tty); 1797 tty_wakeup(tty);
2102 wake_up_interruptible(&tty->write_wait); 1798 wake_up_interruptible(&tty->write_wait);
2103
2104 } /* End if LOWWAIT */ 1799 } /* End if LOWWAIT */
2105 1800 } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */
2106 } /* End LOWTX_IND */
2107 else
2108 if (event & EMPTYTX_IND)
2109 { /* Begin EMPTYTX_IND */
2110
2111 /* This event is generated by setup_empty_event */ 1801 /* This event is generated by setup_empty_event */
2112
2113 ch->statusflags &= ~TXBUSY; 1802 ch->statusflags &= ~TXBUSY;
2114 if (ch->statusflags & EMPTYWAIT) 1803 if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */
2115 { /* Begin if EMPTYWAIT */
2116
2117 ch->statusflags &= ~EMPTYWAIT; 1804 ch->statusflags &= ~EMPTYWAIT;
2118 tty_wakeup(tty); 1805 tty_wakeup(tty);
2119
2120 wake_up_interruptible(&tty->write_wait); 1806 wake_up_interruptible(&tty->write_wait);
2121
2122 } /* End if EMPTYWAIT */ 1807 } /* End if EMPTYWAIT */
2123
2124 } /* End EMPTYTX_IND */ 1808 } /* End EMPTYTX_IND */
2125
2126 } /* End if valid tty */ 1809 } /* End if valid tty */
2127
2128
2129 next: 1810 next:
2130 globalwinon(ch); 1811 globalwinon(ch);
2131 1812 BUG_ON(!bc);
2132 if (!bc) 1813 writew(1, &bc->idata);
2133 printk(KERN_ERR "<Error> - bc == NULL in doevent!\n"); 1814 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
2134 else
2135 bc->idata = 1;
2136
2137 chan0->mailbox->eout = (tail + 4) & (IMAX - ISTART - 4);
2138 globalwinon(chan0); 1815 globalwinon(chan0);
2139
2140 } /* End while something in event queue */ 1816 } /* End while something in event queue */
2141
2142} /* End doevent */ 1817} /* End doevent */
2143 1818
2144/* --------------------- Begin fepcmd ------------------------ */ 1819/* --------------------- Begin fepcmd ------------------------ */
@@ -2146,8 +1821,7 @@ static void doevent(int crd)
2146static void fepcmd(struct channel *ch, int cmd, int word_or_byte, 1821static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2147 int byte2, int ncmds, int bytecmd) 1822 int byte2, int ncmds, int bytecmd)
2148{ /* Begin fepcmd */ 1823{ /* Begin fepcmd */
2149 1824 unchar __iomem *memaddr;
2150 unchar *memaddr;
2151 unsigned int head, cmdTail, cmdStart, cmdMax; 1825 unsigned int head, cmdTail, cmdStart, cmdMax;
2152 long count; 1826 long count;
2153 int n; 1827 int n;
@@ -2155,93 +1829,57 @@ static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2155 /* This is the routine in which commands may be passed to the card. */ 1829 /* This is the routine in which commands may be passed to the card. */
2156 1830
2157 if (ch->board->status == DISABLED) 1831 if (ch->board->status == DISABLED)
2158 {
2159 return; 1832 return;
2160 }
2161
2162 assertgwinon(ch); 1833 assertgwinon(ch);
2163
2164 /* Remember head (As well as max) is just an offset not a base addr */ 1834 /* Remember head (As well as max) is just an offset not a base addr */
2165 head = ch->mailbox->cin; 1835 head = readw(&ch->mailbox->cin);
2166
2167 /* cmdStart is a base address */ 1836 /* cmdStart is a base address */
2168 cmdStart = ch->mailbox->cstart; 1837 cmdStart = readw(&ch->mailbox->cstart);
2169
2170 /* ------------------------------------------------------------------ 1838 /* ------------------------------------------------------------------
2171 We do the addition below because we do not want a max pointer 1839 We do the addition below because we do not want a max pointer
2172 relative to cmdStart. We want a max pointer that points at the 1840 relative to cmdStart. We want a max pointer that points at the
2173 physical end of the command queue. 1841 physical end of the command queue.
2174 -------------------------------------------------------------------- */ 1842 -------------------------------------------------------------------- */
2175 1843 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
2176 cmdMax = (cmdStart + 4 + (ch->mailbox->cmax));
2177
2178 memaddr = ch->board->re_map_membase; 1844 memaddr = ch->board->re_map_membase;
2179 1845
2180 /* 1846 if (head >= (cmdMax - cmdStart) || (head & 03)) {
2181 The below command is necessary because newer kernels (2.1.x and 1847 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
2182 up) do not have a 1:1 virtual to physical mapping. The below 1848 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
2183 call adjust for that.
2184 */
2185
2186 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
2187
2188 if (head >= (cmdMax - cmdStart) || (head & 03))
2189 {
2190 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__,
2191 cmd, head);
2192 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__,
2193 cmdMax, cmdStart);
2194 return; 1849 return;
2195 } 1850 }
2196 1851 if (bytecmd) {
2197 if (bytecmd) 1852 writeb(cmd, memaddr + head + cmdStart + 0);
2198 { 1853 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
2199 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2200
2201 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2202 /* Below word_or_byte is bits to set */ 1854 /* Below word_or_byte is bits to set */
2203 *(volatile unchar *)(memaddr + head + cmdStart + 2) = (unchar)word_or_byte; 1855 writeb(word_or_byte, memaddr + head + cmdStart + 2);
2204 /* Below byte2 is bits to reset */ 1856 /* Below byte2 is bits to reset */
2205 *(volatile unchar *)(memaddr + head + cmdStart + 3) = (unchar)byte2; 1857 writeb(byte2, memaddr + head + cmdStart + 3);
2206 1858 } else {
2207 } 1859 writeb(cmd, memaddr + head + cmdStart + 0);
2208 else 1860 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
2209 { 1861 writeb(word_or_byte, memaddr + head + cmdStart + 2);
2210 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2211 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2212 *(volatile ushort*)(memaddr + head + cmdStart + 2) = (ushort)word_or_byte;
2213 } 1862 }
2214
2215 head = (head + 4) & (cmdMax - cmdStart - 4); 1863 head = (head + 4) & (cmdMax - cmdStart - 4);
2216 ch->mailbox->cin = head; 1864 writew(head, &ch->mailbox->cin);
2217
2218 count = FEPTIMEOUT; 1865 count = FEPTIMEOUT;
2219 1866
2220 for (;;) 1867 for (;;) { /* Begin forever loop */
2221 { /* Begin forever loop */
2222
2223 count--; 1868 count--;
2224 if (count == 0) 1869 if (count == 0) {
2225 {
2226 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n"); 1870 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
2227 return; 1871 return;
2228 } 1872 }
2229 1873 head = readw(&ch->mailbox->cin);
2230 head = ch->mailbox->cin; 1874 cmdTail = readw(&ch->mailbox->cout);
2231 cmdTail = ch->mailbox->cout;
2232
2233 n = (head - cmdTail) & (cmdMax - cmdStart - 4); 1875 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
2234
2235 /* ---------------------------------------------------------- 1876 /* ----------------------------------------------------------
2236 Basically this will break when the FEP acknowledges the 1877 Basically this will break when the FEP acknowledges the
2237 command by incrementing cmdTail (Making it equal to head). 1878 command by incrementing cmdTail (Making it equal to head).
2238 ------------------------------------------------------------- */ 1879 ------------------------------------------------------------- */
2239
2240 if (n <= ncmds * (sizeof(short) * 4)) 1880 if (n <= ncmds * (sizeof(short) * 4))
2241 break; /* Well nearly forever :-) */ 1881 break; /* Well nearly forever :-) */
2242
2243 } /* End forever loop */ 1882 } /* End forever loop */
2244
2245} /* End fepcmd */ 1883} /* End fepcmd */
2246 1884
2247/* --------------------------------------------------------------------- 1885/* ---------------------------------------------------------------------
@@ -2255,11 +1893,9 @@ static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2255 1893
2256static unsigned termios2digi_h(struct channel *ch, unsigned cflag) 1894static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
2257{ /* Begin termios2digi_h */ 1895{ /* Begin termios2digi_h */
2258
2259 unsigned res = 0; 1896 unsigned res = 0;
2260 1897
2261 if (cflag & CRTSCTS) 1898 if (cflag & CRTSCTS) {
2262 {
2263 ch->digiext.digi_flags |= (RTSPACE | CTSPACE); 1899 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
2264 res |= ((ch->m_cts) | (ch->m_rts)); 1900 res |= ((ch->m_cts) | (ch->m_rts));
2265 } 1901 }
@@ -2295,7 +1931,6 @@ static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
2295 1931
2296 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | 1932 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2297 INPCK | ISTRIP|IXON|IXANY|IXOFF); 1933 INPCK | ISTRIP|IXON|IXANY|IXOFF);
2298
2299 if (ch->digiext.digi_flags & DIGI_AIXON) 1934 if (ch->digiext.digi_flags & DIGI_AIXON)
2300 res |= IAIXON; 1935 res |= IAIXON;
2301 return res; 1936 return res;
@@ -2308,28 +1943,15 @@ static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2308{ /* Begin termios2digi_c */ 1943{ /* Begin termios2digi_c */
2309 1944
2310 unsigned res = 0; 1945 unsigned res = 0;
2311 1946 if (cflag & CBAUDEX) { /* Begin detected CBAUDEX */
2312#ifdef SPEED_HACK
2313 /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */
2314 if ((cflag & CBAUD)== B38400) cflag=cflag - B38400 + B115200;
2315 if ((cflag & CBAUD)== B19200) cflag=cflag - B19200 + B57600;
2316#endif /* SPEED_HACK */
2317
2318 if (cflag & CBAUDEX)
2319 { /* Begin detected CBAUDEX */
2320
2321 ch->digiext.digi_flags |= DIGI_FAST; 1947 ch->digiext.digi_flags |= DIGI_FAST;
2322
2323 /* ------------------------------------------------------------- 1948 /* -------------------------------------------------------------
2324 HUPCL bit is used by FEP to indicate fast baud 1949 HUPCL bit is used by FEP to indicate fast baud
2325 table is to be used. 1950 table is to be used.
2326 ----------------------------------------------------------------- */ 1951 ----------------------------------------------------------------- */
2327
2328 res |= FEP_HUPCL; 1952 res |= FEP_HUPCL;
2329
2330 } /* End detected CBAUDEX */ 1953 } /* End detected CBAUDEX */
2331 else ch->digiext.digi_flags &= ~DIGI_FAST; 1954 else ch->digiext.digi_flags &= ~DIGI_FAST;
2332
2333 /* ------------------------------------------------------------------- 1955 /* -------------------------------------------------------------------
2334 CBAUD has bit position 0x1000 set these days to indicate Linux 1956 CBAUD has bit position 0x1000 set these days to indicate Linux
2335 baud rate remap. Digi hardware can't handle the bit assignment. 1957 baud rate remap. Digi hardware can't handle the bit assignment.
@@ -2337,7 +1959,6 @@ static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2337 bit out. 1959 bit out.
2338 ---------------------------------------------------------------------- */ 1960 ---------------------------------------------------------------------- */
2339 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE); 1961 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
2340
2341 /* ------------------------------------------------------------- 1962 /* -------------------------------------------------------------
2342 This gets a little confusing. The Digi cards have their own 1963 This gets a little confusing. The Digi cards have their own
2343 representation of c_cflags controling baud rate. For the most 1964 representation of c_cflags controling baud rate. For the most
@@ -2357,10 +1978,8 @@ static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2357 should be checked for a screened out prior to termios2digi_c 1978 should be checked for a screened out prior to termios2digi_c
2358 returning. Since CLOCAL isn't used by the board this can be 1979 returning. Since CLOCAL isn't used by the board this can be
2359 ignored as long as the returned value is used only by Digi hardware. 1980 ignored as long as the returned value is used only by Digi hardware.
2360 ----------------------------------------------------------------- */ 1981 ----------------------------------------------------------------- */
2361 1982 if (cflag & CBAUDEX) {
2362 if (cflag & CBAUDEX)
2363 {
2364 /* ------------------------------------------------------------- 1983 /* -------------------------------------------------------------
2365 The below code is trying to guarantee that only baud rates 1984 The below code is trying to guarantee that only baud rates
2366 115200 and 230400 are remapped. We use exclusive or because 1985 115200 and 230400 are remapped. We use exclusive or because
@@ -2371,138 +1990,96 @@ static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2371 1990
2372 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) || 1991 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
2373 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX)))) 1992 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
2374 {
2375 res += 1; 1993 res += 1;
2376 }
2377 } 1994 }
2378
2379 return res; 1995 return res;
2380 1996
2381} /* End termios2digi_c */ 1997} /* End termios2digi_c */
2382 1998
2383/* --------------------- Begin epcaparam ----------------------- */ 1999/* --------------------- Begin epcaparam ----------------------- */
2384 2000
2001/* Caller must hold the locks */
2385static void epcaparam(struct tty_struct *tty, struct channel *ch) 2002static void epcaparam(struct tty_struct *tty, struct channel *ch)
2386{ /* Begin epcaparam */ 2003{ /* Begin epcaparam */
2387 2004
2388 unsigned int cmdHead; 2005 unsigned int cmdHead;
2389 struct termios *ts; 2006 struct termios *ts;
2390 volatile struct board_chan *bc; 2007 struct board_chan __iomem *bc;
2391 unsigned mval, hflow, cflag, iflag; 2008 unsigned mval, hflow, cflag, iflag;
2392 2009
2393 bc = ch->brdchan; 2010 bc = ch->brdchan;
2394 epcaassert(bc !=0, "bc out of range"); 2011 epcaassert(bc !=0, "bc out of range");
2395 2012
2396 assertgwinon(ch); 2013 assertgwinon(ch);
2397
2398 ts = tty->termios; 2014 ts = tty->termios;
2399 2015 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
2400 if ((ts->c_cflag & CBAUD) == 0) 2016 cmdHead = readw(&bc->rin);
2401 { /* Begin CBAUD detected */ 2017 writew(cmdHead, &bc->rout);
2402 2018 cmdHead = readw(&bc->tin);
2403 cmdHead = bc->rin;
2404 bc->rout = cmdHead;
2405 cmdHead = bc->tin;
2406
2407 /* Changing baud in mid-stream transmission can be wonderful */ 2019 /* Changing baud in mid-stream transmission can be wonderful */
2408 /* --------------------------------------------------------------- 2020 /* ---------------------------------------------------------------
2409 Flush current transmit buffer by setting cmdTail pointer (tout) 2021 Flush current transmit buffer by setting cmdTail pointer (tout)
2410 to cmdHead pointer (tin). Hopefully the transmit buffer is empty. 2022 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2411 ----------------------------------------------------------------- */ 2023 ----------------------------------------------------------------- */
2412
2413 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0); 2024 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2414 mval = 0; 2025 mval = 0;
2415 2026 } else { /* Begin CBAUD not detected */
2416 } /* End CBAUD detected */
2417 else
2418 { /* Begin CBAUD not detected */
2419
2420 /* ------------------------------------------------------------------- 2027 /* -------------------------------------------------------------------
2421 c_cflags have changed but that change had nothing to do with BAUD. 2028 c_cflags have changed but that change had nothing to do with BAUD.
2422 Propagate the change to the card. 2029 Propagate the change to the card.
2423 ---------------------------------------------------------------------- */ 2030 ---------------------------------------------------------------------- */
2424
2425 cflag = termios2digi_c(ch, ts->c_cflag); 2031 cflag = termios2digi_c(ch, ts->c_cflag);
2426 2032 if (cflag != ch->fepcflag) {
2427 if (cflag != ch->fepcflag)
2428 {
2429 ch->fepcflag = cflag; 2033 ch->fepcflag = cflag;
2430 /* Set baud rate, char size, stop bits, parity */ 2034 /* Set baud rate, char size, stop bits, parity */
2431 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0); 2035 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2432 } 2036 }
2433
2434
2435 /* ---------------------------------------------------------------- 2037 /* ----------------------------------------------------------------
2436 If the user has not forced CLOCAL and if the device is not a 2038 If the user has not forced CLOCAL and if the device is not a
2437 CALLOUT device (Which is always CLOCAL) we set flags such that 2039 CALLOUT device (Which is always CLOCAL) we set flags such that
2438 the driver will wait on carrier detect. 2040 the driver will wait on carrier detect.
2439 ------------------------------------------------------------------- */ 2041 ------------------------------------------------------------------- */
2440
2441 if (ts->c_cflag & CLOCAL) 2042 if (ts->c_cflag & CLOCAL)
2442 { /* Begin it is a cud device or a ttyD device with CLOCAL on */
2443 ch->asyncflags &= ~ASYNC_CHECK_CD; 2043 ch->asyncflags &= ~ASYNC_CHECK_CD;
2444 } /* End it is a cud device or a ttyD device with CLOCAL on */
2445 else 2044 else
2446 { /* Begin it is a ttyD device */
2447 ch->asyncflags |= ASYNC_CHECK_CD; 2045 ch->asyncflags |= ASYNC_CHECK_CD;
2448 } /* End it is a ttyD device */
2449
2450 mval = ch->m_dtr | ch->m_rts; 2046 mval = ch->m_dtr | ch->m_rts;
2451
2452 } /* End CBAUD not detected */ 2047 } /* End CBAUD not detected */
2453
2454 iflag = termios2digi_i(ch, ts->c_iflag); 2048 iflag = termios2digi_i(ch, ts->c_iflag);
2455
2456 /* Check input mode flags */ 2049 /* Check input mode flags */
2457 2050 if (iflag != ch->fepiflag) {
2458 if (iflag != ch->fepiflag)
2459 {
2460 ch->fepiflag = iflag; 2051 ch->fepiflag = iflag;
2461
2462 /* --------------------------------------------------------------- 2052 /* ---------------------------------------------------------------
2463 Command sets channels iflag structure on the board. Such things 2053 Command sets channels iflag structure on the board. Such things
2464 as input soft flow control, handling of parity errors, and 2054 as input soft flow control, handling of parity errors, and
2465 break handling are all set here. 2055 break handling are all set here.
2466 ------------------------------------------------------------------- */ 2056 ------------------------------------------------------------------- */
2467
2468 /* break handling, parity handling, input stripping, flow control chars */ 2057 /* break handling, parity handling, input stripping, flow control chars */
2469 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0); 2058 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2470 } 2059 }
2471
2472 /* --------------------------------------------------------------- 2060 /* ---------------------------------------------------------------
2473 Set the board mint value for this channel. This will cause hardware 2061 Set the board mint value for this channel. This will cause hardware
2474 events to be generated each time the DCD signal (Described in mint) 2062 events to be generated each time the DCD signal (Described in mint)
2475 changes. 2063 changes.
2476 ------------------------------------------------------------------- */ 2064 ------------------------------------------------------------------- */
2477 bc->mint = ch->dcd; 2065 writeb(ch->dcd, &bc->mint);
2478
2479 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD)) 2066 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2480 if (ch->digiext.digi_flags & DIGI_FORCEDCD) 2067 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
2481 bc->mint = 0; 2068 writeb(0, &bc->mint);
2482 2069 ch->imodem = readb(&bc->mstat);
2483 ch->imodem = bc->mstat;
2484
2485 hflow = termios2digi_h(ch, ts->c_cflag); 2070 hflow = termios2digi_h(ch, ts->c_cflag);
2486 2071 if (hflow != ch->hflow) {
2487 if (hflow != ch->hflow)
2488 {
2489 ch->hflow = hflow; 2072 ch->hflow = hflow;
2490
2491 /* -------------------------------------------------------------- 2073 /* --------------------------------------------------------------
2492 Hard flow control has been selected but the board is not 2074 Hard flow control has been selected but the board is not
2493 using it. Activate hard flow control now. 2075 using it. Activate hard flow control now.
2494 ----------------------------------------------------------------- */ 2076 ----------------------------------------------------------------- */
2495
2496 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1); 2077 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2497 } 2078 }
2498
2499
2500 mval ^= ch->modemfake & (mval ^ ch->modem); 2079 mval ^= ch->modemfake & (mval ^ ch->modem);
2501 2080
2502 if (ch->omodem ^ mval) 2081 if (ch->omodem ^ mval) {
2503 {
2504 ch->omodem = mval; 2082 ch->omodem = mval;
2505
2506 /* -------------------------------------------------------------- 2083 /* --------------------------------------------------------------
2507 The below command sets the DTR and RTS mstat structure. If 2084 The below command sets the DTR and RTS mstat structure. If
2508 hard flow control is NOT active these changes will drive the 2085 hard flow control is NOT active these changes will drive the
@@ -2514,87 +2091,65 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
2514 /* First reset DTR & RTS; then set them */ 2091 /* First reset DTR & RTS; then set them */
2515 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1); 2092 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2516 fepcmd(ch, SETMODEM, mval, 0, 0, 1); 2093 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
2517
2518 } 2094 }
2519 2095 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
2520 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc)
2521 {
2522 ch->fepstartc = ch->startc; 2096 ch->fepstartc = ch->startc;
2523 ch->fepstopc = ch->stopc; 2097 ch->fepstopc = ch->stopc;
2524
2525 /* ------------------------------------------------------------ 2098 /* ------------------------------------------------------------
2526 The XON / XOFF characters have changed; propagate these 2099 The XON / XOFF characters have changed; propagate these
2527 changes to the card. 2100 changes to the card.
2528 --------------------------------------------------------------- */ 2101 --------------------------------------------------------------- */
2529
2530 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1); 2102 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2531 } 2103 }
2532 2104 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
2533 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca)
2534 {
2535 ch->fepstartca = ch->startca; 2105 ch->fepstartca = ch->startca;
2536 ch->fepstopca = ch->stopca; 2106 ch->fepstopca = ch->stopca;
2537
2538 /* --------------------------------------------------------------- 2107 /* ---------------------------------------------------------------
2539 Similar to the above, this time the auxilarly XON / XOFF 2108 Similar to the above, this time the auxilarly XON / XOFF
2540 characters have changed; propagate these changes to the card. 2109 characters have changed; propagate these changes to the card.
2541 ------------------------------------------------------------------ */ 2110 ------------------------------------------------------------------ */
2542
2543 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1); 2111 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2544 } 2112 }
2545
2546} /* End epcaparam */ 2113} /* End epcaparam */
2547 2114
2548/* --------------------- Begin receive_data ----------------------- */ 2115/* --------------------- Begin receive_data ----------------------- */
2549 2116/* Caller holds lock */
2550static void receive_data(struct channel *ch) 2117static void receive_data(struct channel *ch)
2551{ /* Begin receive_data */ 2118{ /* Begin receive_data */
2552 2119
2553 unchar *rptr; 2120 unchar *rptr;
2554 struct termios *ts = NULL; 2121 struct termios *ts = NULL;
2555 struct tty_struct *tty; 2122 struct tty_struct *tty;
2556 volatile struct board_chan *bc; 2123 struct board_chan __iomem *bc;
2557 register int dataToRead, wrapgap, bytesAvailable; 2124 int dataToRead, wrapgap, bytesAvailable;
2558 register unsigned int tail, head; 2125 unsigned int tail, head;
2559 unsigned int wrapmask; 2126 unsigned int wrapmask;
2560 int rc; 2127 int rc;
2561 2128
2562
2563 /* --------------------------------------------------------------- 2129 /* ---------------------------------------------------------------
2564 This routine is called by doint when a receive data event 2130 This routine is called by doint when a receive data event
2565 has taken place. 2131 has taken place.
2566 ------------------------------------------------------------------- */ 2132 ------------------------------------------------------------------- */
2567 2133
2568 globalwinon(ch); 2134 globalwinon(ch);
2569
2570 if (ch->statusflags & RXSTOPPED) 2135 if (ch->statusflags & RXSTOPPED)
2571 return; 2136 return;
2572
2573 tty = ch->tty; 2137 tty = ch->tty;
2574 if (tty) 2138 if (tty)
2575 ts = tty->termios; 2139 ts = tty->termios;
2576
2577 bc = ch->brdchan; 2140 bc = ch->brdchan;
2578 2141 BUG_ON(!bc);
2579 if (!bc)
2580 {
2581 printk(KERN_ERR "<Error> - bc is NULL in receive_data!\n");
2582 return;
2583 }
2584
2585 wrapmask = ch->rxbufsize - 1; 2142 wrapmask = ch->rxbufsize - 1;
2586 2143
2587 /* --------------------------------------------------------------------- 2144 /* ---------------------------------------------------------------------
2588 Get the head and tail pointers to the receiver queue. Wrap the 2145 Get the head and tail pointers to the receiver queue. Wrap the
2589 head pointer if it has reached the end of the buffer. 2146 head pointer if it has reached the end of the buffer.
2590 ------------------------------------------------------------------------ */ 2147 ------------------------------------------------------------------------ */
2591 2148 head = readw(&bc->rin);
2592 head = bc->rin;
2593 head &= wrapmask; 2149 head &= wrapmask;
2594 tail = bc->rout & wrapmask; 2150 tail = readw(&bc->rout) & wrapmask;
2595 2151
2596 bytesAvailable = (head - tail) & wrapmask; 2152 bytesAvailable = (head - tail) & wrapmask;
2597
2598 if (bytesAvailable == 0) 2153 if (bytesAvailable == 0)
2599 return; 2154 return;
2600 2155
@@ -2602,73 +2157,53 @@ static void receive_data(struct channel *ch)
2602 If CREAD bit is off or device not open, set TX tail to head 2157 If CREAD bit is off or device not open, set TX tail to head
2603 --------------------------------------------------------------------- */ 2158 --------------------------------------------------------------------- */
2604 2159
2605 if (!tty || !ts || !(ts->c_cflag & CREAD)) 2160 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
2606 { 2161 writew(head, &bc->rout);
2607 bc->rout = head;
2608 return; 2162 return;
2609 } 2163 }
2610 2164
2611 if (tty->flip.count == TTY_FLIPBUF_SIZE) 2165 if (tty->flip.count == TTY_FLIPBUF_SIZE)
2612 return; 2166 return;
2613 2167
2614 if (bc->orun) 2168 if (readb(&bc->orun)) {
2615 { 2169 writeb(0, &bc->orun);
2616 bc->orun = 0; 2170 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
2617 printk(KERN_WARNING "overrun! DigiBoard device %s\n",tty->name);
2618 } 2171 }
2619
2620 rxwinon(ch); 2172 rxwinon(ch);
2621 rptr = tty->flip.char_buf_ptr; 2173 rptr = tty->flip.char_buf_ptr;
2622 rc = tty->flip.count; 2174 rc = tty->flip.count;
2623 2175 while (bytesAvailable > 0) { /* Begin while there is data on the card */
2624 while (bytesAvailable > 0)
2625 { /* Begin while there is data on the card */
2626
2627 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail; 2176 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2628
2629 /* --------------------------------------------------------------- 2177 /* ---------------------------------------------------------------
2630 Even if head has wrapped around only report the amount of 2178 Even if head has wrapped around only report the amount of
2631 data to be equal to the size - tail. Remember memcpy can't 2179 data to be equal to the size - tail. Remember memcpy can't
2632 automaticly wrap around the receive buffer. 2180 automaticly wrap around the receive buffer.
2633 ----------------------------------------------------------------- */ 2181 ----------------------------------------------------------------- */
2634
2635 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable; 2182 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
2636
2637 /* -------------------------------------------------------------- 2183 /* --------------------------------------------------------------
2638 Make sure we don't overflow the buffer 2184 Make sure we don't overflow the buffer
2639 ----------------------------------------------------------------- */ 2185 ----------------------------------------------------------------- */
2640
2641 if ((rc + dataToRead) > TTY_FLIPBUF_SIZE) 2186 if ((rc + dataToRead) > TTY_FLIPBUF_SIZE)
2642 dataToRead = TTY_FLIPBUF_SIZE - rc; 2187 dataToRead = TTY_FLIPBUF_SIZE - rc;
2643
2644 if (dataToRead == 0) 2188 if (dataToRead == 0)
2645 break; 2189 break;
2646
2647 /* --------------------------------------------------------------- 2190 /* ---------------------------------------------------------------
2648 Move data read from our card into the line disciplines buffer 2191 Move data read from our card into the line disciplines buffer
2649 for translation if necessary. 2192 for translation if necessary.
2650 ------------------------------------------------------------------ */ 2193 ------------------------------------------------------------------ */
2651 2194 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
2652 if ((memcpy(rptr, ch->rxptr + tail, dataToRead)) != rptr)
2653 printk(KERN_ERR "<Error> - receive_data : memcpy failed\n");
2654
2655 rc += dataToRead; 2195 rc += dataToRead;
2656 rptr += dataToRead; 2196 rptr += dataToRead;
2657 tail = (tail + dataToRead) & wrapmask; 2197 tail = (tail + dataToRead) & wrapmask;
2658 bytesAvailable -= dataToRead; 2198 bytesAvailable -= dataToRead;
2659
2660 } /* End while there is data on the card */ 2199 } /* End while there is data on the card */
2661
2662
2663 tty->flip.count = rc; 2200 tty->flip.count = rc;
2664 tty->flip.char_buf_ptr = rptr; 2201 tty->flip.char_buf_ptr = rptr;
2665 globalwinon(ch); 2202 globalwinon(ch);
2666 bc->rout = tail; 2203 writew(tail, &bc->rout);
2667
2668 /* Must be called with global data */ 2204 /* Must be called with global data */
2669 tty_schedule_flip(ch->tty); 2205 tty_schedule_flip(ch->tty);
2670 return; 2206 return;
2671
2672} /* End receive_data */ 2207} /* End receive_data */
2673 2208
2674static int info_ioctl(struct tty_struct *tty, struct file * file, 2209static int info_ioctl(struct tty_struct *tty, struct file * file,
@@ -2676,17 +2211,15 @@ static int info_ioctl(struct tty_struct *tty, struct file * file,
2676{ 2211{
2677 switch (cmd) 2212 switch (cmd)
2678 { /* Begin switch cmd */ 2213 { /* Begin switch cmd */
2679
2680 case DIGI_GETINFO: 2214 case DIGI_GETINFO:
2681 { /* Begin case DIGI_GETINFO */ 2215 { /* Begin case DIGI_GETINFO */
2682
2683 struct digi_info di ; 2216 struct digi_info di ;
2684 int brd; 2217 int brd;
2685 2218
2686 getUser(brd, (unsigned int __user *)arg); 2219 if(get_user(brd, (unsigned int __user *)arg))
2687 2220 return -EFAULT;
2688 if ((brd < 0) || (brd >= num_cards) || (num_cards == 0)) 2221 if (brd < 0 || brd >= num_cards || num_cards == 0)
2689 return (-ENODEV); 2222 return -ENODEV;
2690 2223
2691 memset(&di, 0, sizeof(di)); 2224 memset(&di, 0, sizeof(di));
2692 2225
@@ -2694,8 +2227,9 @@ static int info_ioctl(struct tty_struct *tty, struct file * file,
2694 di.status = boards[brd].status; 2227 di.status = boards[brd].status;
2695 di.type = boards[brd].type ; 2228 di.type = boards[brd].type ;
2696 di.numports = boards[brd].numports ; 2229 di.numports = boards[brd].numports ;
2697 di.port = boards[brd].port ; 2230 /* Legacy fixups - just move along nothing to see */
2698 di.membase = boards[brd].membase ; 2231 di.port = (unsigned char *)boards[brd].port ;
2232 di.membase = (unsigned char *)boards[brd].membase ;
2699 2233
2700 if (copy_to_user((void __user *)arg, &di, sizeof (di))) 2234 if (copy_to_user((void __user *)arg, &di, sizeof (di)))
2701 return -EFAULT; 2235 return -EFAULT;
@@ -2709,39 +2243,29 @@ static int info_ioctl(struct tty_struct *tty, struct file * file,
2709 int brd = arg & 0xff000000 >> 16 ; 2243 int brd = arg & 0xff000000 >> 16 ;
2710 unsigned char state = arg & 0xff ; 2244 unsigned char state = arg & 0xff ;
2711 2245
2712 if ((brd < 0) || (brd >= num_cards)) 2246 if (brd < 0 || brd >= num_cards) {
2713 { 2247 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
2714 printk(KERN_ERR "<Error> - DIGI POLLER : brd not valid!\n");
2715 return (-ENODEV); 2248 return (-ENODEV);
2716 } 2249 }
2717
2718 digi_poller_inhibited = state ; 2250 digi_poller_inhibited = state ;
2719 break ; 2251 break ;
2720
2721 } /* End case DIGI_POLLER */ 2252 } /* End case DIGI_POLLER */
2722 2253
2723 case DIGI_INIT: 2254 case DIGI_INIT:
2724 { /* Begin case DIGI_INIT */ 2255 { /* Begin case DIGI_INIT */
2725
2726 /* ------------------------------------------------------------ 2256 /* ------------------------------------------------------------
2727 This call is made by the apps to complete the initilization 2257 This call is made by the apps to complete the initilization
2728 of the board(s). This routine is responsible for setting 2258 of the board(s). This routine is responsible for setting
2729 the card to its initial state and setting the drivers control 2259 the card to its initial state and setting the drivers control
2730 fields to the sutianle settings for the card in question. 2260 fields to the sutianle settings for the card in question.
2731 ---------------------------------------------------------------- */ 2261 ---------------------------------------------------------------- */
2732
2733 int crd ; 2262 int crd ;
2734 for (crd = 0; crd < num_cards; crd++) 2263 for (crd = 0; crd < num_cards; crd++)
2735 post_fep_init (crd); 2264 post_fep_init (crd);
2736
2737 break ; 2265 break ;
2738
2739 } /* End case DIGI_INIT */ 2266 } /* End case DIGI_INIT */
2740
2741
2742 default: 2267 default:
2743 return -ENOIOCTLCMD; 2268 return -ENOTTY;
2744
2745 } /* End switch cmd */ 2269 } /* End switch cmd */
2746 return (0) ; 2270 return (0) ;
2747} 2271}
@@ -2750,43 +2274,33 @@ static int info_ioctl(struct tty_struct *tty, struct file * file,
2750static int pc_tiocmget(struct tty_struct *tty, struct file *file) 2274static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2751{ 2275{
2752 struct channel *ch = (struct channel *) tty->driver_data; 2276 struct channel *ch = (struct channel *) tty->driver_data;
2753 volatile struct board_chan *bc; 2277 struct board_chan __iomem *bc;
2754 unsigned int mstat, mflag = 0; 2278 unsigned int mstat, mflag = 0;
2755 unsigned long flags; 2279 unsigned long flags;
2756 2280
2757 if (ch) 2281 if (ch)
2758 bc = ch->brdchan; 2282 bc = ch->brdchan;
2759 else 2283 else
2760 { 2284 return -EINVAL;
2761 printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmget!\n");
2762 return(-EINVAL);
2763 }
2764 2285
2765 save_flags(flags); 2286 spin_lock_irqsave(&epca_lock, flags);
2766 cli();
2767 globalwinon(ch); 2287 globalwinon(ch);
2768 mstat = bc->mstat; 2288 mstat = readb(&bc->mstat);
2769 memoff(ch); 2289 memoff(ch);
2770 restore_flags(flags); 2290 spin_unlock_irqrestore(&epca_lock, flags);
2771 2291
2772 if (mstat & ch->m_dtr) 2292 if (mstat & ch->m_dtr)
2773 mflag |= TIOCM_DTR; 2293 mflag |= TIOCM_DTR;
2774
2775 if (mstat & ch->m_rts) 2294 if (mstat & ch->m_rts)
2776 mflag |= TIOCM_RTS; 2295 mflag |= TIOCM_RTS;
2777
2778 if (mstat & ch->m_cts) 2296 if (mstat & ch->m_cts)
2779 mflag |= TIOCM_CTS; 2297 mflag |= TIOCM_CTS;
2780
2781 if (mstat & ch->dsr) 2298 if (mstat & ch->dsr)
2782 mflag |= TIOCM_DSR; 2299 mflag |= TIOCM_DSR;
2783
2784 if (mstat & ch->m_ri) 2300 if (mstat & ch->m_ri)
2785 mflag |= TIOCM_RI; 2301 mflag |= TIOCM_RI;
2786
2787 if (mstat & ch->dcd) 2302 if (mstat & ch->dcd)
2788 mflag |= TIOCM_CD; 2303 mflag |= TIOCM_CD;
2789
2790 return mflag; 2304 return mflag;
2791} 2305}
2792 2306
@@ -2796,13 +2310,10 @@ static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2796 struct channel *ch = (struct channel *) tty->driver_data; 2310 struct channel *ch = (struct channel *) tty->driver_data;
2797 unsigned long flags; 2311 unsigned long flags;
2798 2312
2799 if (!ch) { 2313 if (!ch)
2800 printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmset!\n"); 2314 return -EINVAL;
2801 return(-EINVAL);
2802 }
2803 2315
2804 save_flags(flags); 2316 spin_lock_irqsave(&epca_lock, flags);
2805 cli();
2806 /* 2317 /*
2807 * I think this modemfake stuff is broken. It doesn't 2318 * I think this modemfake stuff is broken. It doesn't
2808 * correctly reflect the behaviour desired by the TIOCM* 2319 * correctly reflect the behaviour desired by the TIOCM*
@@ -2824,17 +2335,14 @@ static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2824 ch->modemfake |= ch->m_dtr; 2335 ch->modemfake |= ch->m_dtr;
2825 ch->modem &= ~ch->m_dtr; 2336 ch->modem &= ~ch->m_dtr;
2826 } 2337 }
2827
2828 globalwinon(ch); 2338 globalwinon(ch);
2829
2830 /* -------------------------------------------------------------- 2339 /* --------------------------------------------------------------
2831 The below routine generally sets up parity, baud, flow control 2340 The below routine generally sets up parity, baud, flow control
2832 issues, etc.... It effect both control flags and input flags. 2341 issues, etc.... It effect both control flags and input flags.
2833 ------------------------------------------------------------------ */ 2342 ------------------------------------------------------------------ */
2834
2835 epcaparam(tty,ch); 2343 epcaparam(tty,ch);
2836 memoff(ch); 2344 memoff(ch);
2837 restore_flags(flags); 2345 spin_unlock_irqrestore(&epca_lock, flags);
2838 return 0; 2346 return 0;
2839} 2347}
2840 2348
@@ -2847,19 +2355,14 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2847 unsigned long flags; 2355 unsigned long flags;
2848 unsigned int mflag, mstat; 2356 unsigned int mflag, mstat;
2849 unsigned char startc, stopc; 2357 unsigned char startc, stopc;
2850 volatile struct board_chan *bc; 2358 struct board_chan __iomem *bc;
2851 struct channel *ch = (struct channel *) tty->driver_data; 2359 struct channel *ch = (struct channel *) tty->driver_data;
2852 void __user *argp = (void __user *)arg; 2360 void __user *argp = (void __user *)arg;
2853 2361
2854 if (ch) 2362 if (ch)
2855 bc = ch->brdchan; 2363 bc = ch->brdchan;
2856 else 2364 else
2857 { 2365 return -EINVAL;
2858 printk(KERN_ERR "<Error> - ch is NULL in pc_ioctl!\n");
2859 return(-EINVAL);
2860 }
2861
2862 save_flags(flags);
2863 2366
2864 /* ------------------------------------------------------------------- 2367 /* -------------------------------------------------------------------
2865 For POSIX compliance we need to add more ioctls. See tty_ioctl.c 2368 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
@@ -2871,46 +2374,39 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2871 { /* Begin switch cmd */ 2374 { /* Begin switch cmd */
2872 2375
2873 case TCGETS: 2376 case TCGETS:
2874 if (copy_to_user(argp, 2377 if (copy_to_user(argp, tty->termios, sizeof(struct termios)))
2875 tty->termios, sizeof(struct termios)))
2876 return -EFAULT; 2378 return -EFAULT;
2877 return(0); 2379 return 0;
2878
2879 case TCGETA: 2380 case TCGETA:
2880 return get_termio(tty, argp); 2381 return get_termio(tty, argp);
2881
2882 case TCSBRK: /* SVID version: non-zero arg --> no break */ 2382 case TCSBRK: /* SVID version: non-zero arg --> no break */
2883
2884 retval = tty_check_change(tty); 2383 retval = tty_check_change(tty);
2885 if (retval) 2384 if (retval)
2886 return retval; 2385 return retval;
2887
2888 /* Setup an event to indicate when the transmit buffer empties */ 2386 /* Setup an event to indicate when the transmit buffer empties */
2889 2387 spin_lock_irqsave(&epca_lock, flags);
2890 setup_empty_event(tty,ch); 2388 setup_empty_event(tty,ch);
2389 spin_unlock_irqrestore(&epca_lock, flags);
2891 tty_wait_until_sent(tty, 0); 2390 tty_wait_until_sent(tty, 0);
2892 if (!arg) 2391 if (!arg)
2893 digi_send_break(ch, HZ/4); /* 1/4 second */ 2392 digi_send_break(ch, HZ/4); /* 1/4 second */
2894 return 0; 2393 return 0;
2895
2896 case TCSBRKP: /* support for POSIX tcsendbreak() */ 2394 case TCSBRKP: /* support for POSIX tcsendbreak() */
2897
2898 retval = tty_check_change(tty); 2395 retval = tty_check_change(tty);
2899 if (retval) 2396 if (retval)
2900 return retval; 2397 return retval;
2901 2398
2902 /* Setup an event to indicate when the transmit buffer empties */ 2399 /* Setup an event to indicate when the transmit buffer empties */
2903 2400 spin_lock_irqsave(&epca_lock, flags);
2904 setup_empty_event(tty,ch); 2401 setup_empty_event(tty,ch);
2402 spin_unlock_irqrestore(&epca_lock, flags);
2905 tty_wait_until_sent(tty, 0); 2403 tty_wait_until_sent(tty, 0);
2906 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4); 2404 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2907 return 0; 2405 return 0;
2908
2909 case TIOCGSOFTCAR: 2406 case TIOCGSOFTCAR:
2910 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg)) 2407 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
2911 return -EFAULT; 2408 return -EFAULT;
2912 return 0; 2409 return 0;
2913
2914 case TIOCSSOFTCAR: 2410 case TIOCSSOFTCAR:
2915 { 2411 {
2916 unsigned int value; 2412 unsigned int value;
@@ -2922,75 +2418,63 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2922 (value ? CLOCAL : 0)); 2418 (value ? CLOCAL : 0));
2923 return 0; 2419 return 0;
2924 } 2420 }
2925
2926 case TIOCMODG: 2421 case TIOCMODG:
2927 mflag = pc_tiocmget(tty, file); 2422 mflag = pc_tiocmget(tty, file);
2928 if (put_user(mflag, (unsigned long __user *)argp)) 2423 if (put_user(mflag, (unsigned long __user *)argp))
2929 return -EFAULT; 2424 return -EFAULT;
2930 break; 2425 break;
2931
2932 case TIOCMODS: 2426 case TIOCMODS:
2933 if (get_user(mstat, (unsigned __user *)argp)) 2427 if (get_user(mstat, (unsigned __user *)argp))
2934 return -EFAULT; 2428 return -EFAULT;
2935 return pc_tiocmset(tty, file, mstat, ~mstat); 2429 return pc_tiocmset(tty, file, mstat, ~mstat);
2936
2937 case TIOCSDTR: 2430 case TIOCSDTR:
2431 spin_lock_irqsave(&epca_lock, flags);
2938 ch->omodem |= ch->m_dtr; 2432 ch->omodem |= ch->m_dtr;
2939 cli();
2940 globalwinon(ch); 2433 globalwinon(ch);
2941 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1); 2434 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2942 memoff(ch); 2435 memoff(ch);
2943 restore_flags(flags); 2436 spin_unlock_irqrestore(&epca_lock, flags);
2944 break; 2437 break;
2945 2438
2946 case TIOCCDTR: 2439 case TIOCCDTR:
2440 spin_lock_irqsave(&epca_lock, flags);
2947 ch->omodem &= ~ch->m_dtr; 2441 ch->omodem &= ~ch->m_dtr;
2948 cli();
2949 globalwinon(ch); 2442 globalwinon(ch);
2950 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1); 2443 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2951 memoff(ch); 2444 memoff(ch);
2952 restore_flags(flags); 2445 spin_unlock_irqrestore(&epca_lock, flags);
2953 break; 2446 break;
2954
2955 case DIGI_GETA: 2447 case DIGI_GETA:
2956 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t))) 2448 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2957 return -EFAULT; 2449 return -EFAULT;
2958 break; 2450 break;
2959
2960 case DIGI_SETAW: 2451 case DIGI_SETAW:
2961 case DIGI_SETAF: 2452 case DIGI_SETAF:
2962 if ((cmd) == (DIGI_SETAW)) 2453 if (cmd == DIGI_SETAW) {
2963 {
2964 /* Setup an event to indicate when the transmit buffer empties */ 2454 /* Setup an event to indicate when the transmit buffer empties */
2965 2455 spin_lock_irqsave(&epca_lock, flags);
2966 setup_empty_event(tty,ch); 2456 setup_empty_event(tty,ch);
2457 spin_unlock_irqrestore(&epca_lock, flags);
2967 tty_wait_until_sent(tty, 0); 2458 tty_wait_until_sent(tty, 0);
2968 } 2459 } else {
2969 else
2970 {
2971 /* ldisc lock already held in ioctl */ 2460 /* ldisc lock already held in ioctl */
2972 if (tty->ldisc.flush_buffer) 2461 if (tty->ldisc.flush_buffer)
2973 tty->ldisc.flush_buffer(tty); 2462 tty->ldisc.flush_buffer(tty);
2974 } 2463 }
2975
2976 /* Fall Thru */ 2464 /* Fall Thru */
2977
2978 case DIGI_SETA: 2465 case DIGI_SETA:
2979 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t))) 2466 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2980 return -EFAULT; 2467 return -EFAULT;
2981 2468
2982 if (ch->digiext.digi_flags & DIGI_ALTPIN) 2469 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2983 {
2984 ch->dcd = ch->m_dsr; 2470 ch->dcd = ch->m_dsr;
2985 ch->dsr = ch->m_dcd; 2471 ch->dsr = ch->m_dcd;
2986 } 2472 } else {
2987 else
2988 {
2989 ch->dcd = ch->m_dcd; 2473 ch->dcd = ch->m_dcd;
2990 ch->dsr = ch->m_dsr; 2474 ch->dsr = ch->m_dsr;
2991 } 2475 }
2992 2476
2993 cli(); 2477 spin_lock_irqsave(&epca_lock, flags);
2994 globalwinon(ch); 2478 globalwinon(ch);
2995 2479
2996 /* ----------------------------------------------------------------- 2480 /* -----------------------------------------------------------------
@@ -3000,25 +2484,22 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
3000 2484
3001 epcaparam(tty,ch); 2485 epcaparam(tty,ch);
3002 memoff(ch); 2486 memoff(ch);
3003 restore_flags(flags); 2487 spin_unlock_irqrestore(&epca_lock, flags);
3004 break; 2488 break;
3005 2489
3006 case DIGI_GETFLOW: 2490 case DIGI_GETFLOW:
3007 case DIGI_GETAFLOW: 2491 case DIGI_GETAFLOW:
3008 cli(); 2492 spin_lock_irqsave(&epca_lock, flags);
3009 globalwinon(ch); 2493 globalwinon(ch);
3010 if ((cmd) == (DIGI_GETFLOW)) 2494 if (cmd == DIGI_GETFLOW) {
3011 { 2495 dflow.startc = readb(&bc->startc);
3012 dflow.startc = bc->startc; 2496 dflow.stopc = readb(&bc->stopc);
3013 dflow.stopc = bc->stopc; 2497 } else {
3014 } 2498 dflow.startc = readb(&bc->startca);
3015 else 2499 dflow.stopc = readb(&bc->stopca);
3016 {
3017 dflow.startc = bc->startca;
3018 dflow.stopc = bc->stopca;
3019 } 2500 }
3020 memoff(ch); 2501 memoff(ch);
3021 restore_flags(flags); 2502 spin_unlock_irqrestore(&epca_lock, flags);
3022 2503
3023 if (copy_to_user(argp, &dflow, sizeof(dflow))) 2504 if (copy_to_user(argp, &dflow, sizeof(dflow)))
3024 return -EFAULT; 2505 return -EFAULT;
@@ -3026,13 +2507,10 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
3026 2507
3027 case DIGI_SETAFLOW: 2508 case DIGI_SETAFLOW:
3028 case DIGI_SETFLOW: 2509 case DIGI_SETFLOW:
3029 if ((cmd) == (DIGI_SETFLOW)) 2510 if (cmd == DIGI_SETFLOW) {
3030 {
3031 startc = ch->startc; 2511 startc = ch->startc;
3032 stopc = ch->stopc; 2512 stopc = ch->stopc;
3033 } 2513 } else {
3034 else
3035 {
3036 startc = ch->startca; 2514 startc = ch->startca;
3037 stopc = ch->stopca; 2515 stopc = ch->stopca;
3038 } 2516 }
@@ -3040,40 +2518,31 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
3040 if (copy_from_user(&dflow, argp, sizeof(dflow))) 2518 if (copy_from_user(&dflow, argp, sizeof(dflow)))
3041 return -EFAULT; 2519 return -EFAULT;
3042 2520
3043 if (dflow.startc != startc || dflow.stopc != stopc) 2521 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
3044 { /* Begin if setflow toggled */ 2522 spin_lock_irqsave(&epca_lock, flags);
3045 cli();
3046 globalwinon(ch); 2523 globalwinon(ch);
3047 2524
3048 if ((cmd) == (DIGI_SETFLOW)) 2525 if (cmd == DIGI_SETFLOW) {
3049 {
3050 ch->fepstartc = ch->startc = dflow.startc; 2526 ch->fepstartc = ch->startc = dflow.startc;
3051 ch->fepstopc = ch->stopc = dflow.stopc; 2527 ch->fepstopc = ch->stopc = dflow.stopc;
3052 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1); 2528 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
3053 } 2529 } else {
3054 else
3055 {
3056 ch->fepstartca = ch->startca = dflow.startc; 2530 ch->fepstartca = ch->startca = dflow.startc;
3057 ch->fepstopca = ch->stopca = dflow.stopc; 2531 ch->fepstopca = ch->stopca = dflow.stopc;
3058 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1); 2532 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
3059 } 2533 }
3060 2534
3061 if (ch->statusflags & TXSTOPPED) 2535 if (ch->statusflags & TXSTOPPED)
3062 pc_start(tty); 2536 pc_start(tty);
3063 2537
3064 memoff(ch); 2538 memoff(ch);
3065 restore_flags(flags); 2539 spin_unlock_irqrestore(&epca_lock, flags);
3066
3067 } /* End if setflow toggled */ 2540 } /* End if setflow toggled */
3068 break; 2541 break;
3069
3070 default: 2542 default:
3071 return -ENOIOCTLCMD; 2543 return -ENOIOCTLCMD;
3072
3073 } /* End switch cmd */ 2544 } /* End switch cmd */
3074
3075 return 0; 2545 return 0;
3076
3077} /* End pc_ioctl */ 2546} /* End pc_ioctl */
3078 2547
3079/* --------------------- Begin pc_set_termios ----------------------- */ 2548/* --------------------- Begin pc_set_termios ----------------------- */
@@ -3083,20 +2552,16 @@ static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3083 2552
3084 struct channel *ch; 2553 struct channel *ch;
3085 unsigned long flags; 2554 unsigned long flags;
3086
3087 /* --------------------------------------------------------- 2555 /* ---------------------------------------------------------
3088 verifyChannel returns the channel from the tty struct 2556 verifyChannel returns the channel from the tty struct
3089 if it is valid. This serves as a sanity check. 2557 if it is valid. This serves as a sanity check.
3090 ------------------------------------------------------------- */ 2558 ------------------------------------------------------------- */
3091 2559 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
3092 if ((ch = verifyChannel(tty)) != NULL) 2560 spin_lock_irqsave(&epca_lock, flags);
3093 { /* Begin if channel valid */
3094
3095 save_flags(flags);
3096 cli();
3097 globalwinon(ch); 2561 globalwinon(ch);
3098 epcaparam(tty, ch); 2562 epcaparam(tty, ch);
3099 memoff(ch); 2563 memoff(ch);
2564 spin_unlock_irqrestore(&epca_lock, flags);
3100 2565
3101 if ((old_termios->c_cflag & CRTSCTS) && 2566 if ((old_termios->c_cflag & CRTSCTS) &&
3102 ((tty->termios->c_cflag & CRTSCTS) == 0)) 2567 ((tty->termios->c_cflag & CRTSCTS) == 0))
@@ -3106,8 +2571,6 @@ static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3106 (tty->termios->c_cflag & CLOCAL)) 2571 (tty->termios->c_cflag & CLOCAL))
3107 wake_up_interruptible(&ch->open_wait); 2572 wake_up_interruptible(&ch->open_wait);
3108 2573
3109 restore_flags(flags);
3110
3111 } /* End if channel valid */ 2574 } /* End if channel valid */
3112 2575
3113} /* End pc_set_termios */ 2576} /* End pc_set_termios */
@@ -3116,29 +2579,18 @@ static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3116 2579
3117static void do_softint(void *private_) 2580static void do_softint(void *private_)
3118{ /* Begin do_softint */ 2581{ /* Begin do_softint */
3119
3120 struct channel *ch = (struct channel *) private_; 2582 struct channel *ch = (struct channel *) private_;
3121
3122
3123 /* Called in response to a modem change event */ 2583 /* Called in response to a modem change event */
3124 2584 if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */
3125 if (ch && ch->magic == EPCA_MAGIC)
3126 { /* Begin EPCA_MAGIC */
3127
3128 struct tty_struct *tty = ch->tty; 2585 struct tty_struct *tty = ch->tty;
3129 2586
3130 if (tty && tty->driver_data) 2587 if (tty && tty->driver_data) {
3131 { 2588 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { /* Begin if clear_bit */
3132 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event))
3133 { /* Begin if clear_bit */
3134
3135 tty_hangup(tty); /* FIXME: module removal race here - AKPM */ 2589 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
3136 wake_up_interruptible(&ch->open_wait); 2590 wake_up_interruptible(&ch->open_wait);
3137 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE; 2591 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
3138
3139 } /* End if clear_bit */ 2592 } /* End if clear_bit */
3140 } 2593 }
3141
3142 } /* End EPCA_MAGIC */ 2594 } /* End EPCA_MAGIC */
3143} /* End do_softint */ 2595} /* End do_softint */
3144 2596
@@ -3154,82 +2606,49 @@ static void pc_stop(struct tty_struct *tty)
3154 2606
3155 struct channel *ch; 2607 struct channel *ch;
3156 unsigned long flags; 2608 unsigned long flags;
3157
3158 /* --------------------------------------------------------- 2609 /* ---------------------------------------------------------
3159 verifyChannel returns the channel from the tty struct 2610 verifyChannel returns the channel from the tty struct
3160 if it is valid. This serves as a sanity check. 2611 if it is valid. This serves as a sanity check.
3161 ------------------------------------------------------------- */ 2612 ------------------------------------------------------------- */
3162 2613 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if valid channel */
3163 if ((ch = verifyChannel(tty)) != NULL) 2614 spin_lock_irqsave(&epca_lock, flags);
3164 { /* Begin if valid channel */ 2615 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
3165
3166 save_flags(flags);
3167 cli();
3168
3169 if ((ch->statusflags & TXSTOPPED) == 0)
3170 { /* Begin if transmit stop requested */
3171
3172 globalwinon(ch); 2616 globalwinon(ch);
3173
3174 /* STOP transmitting now !! */ 2617 /* STOP transmitting now !! */
3175
3176 fepcmd(ch, PAUSETX, 0, 0, 0, 0); 2618 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
3177
3178 ch->statusflags |= TXSTOPPED; 2619 ch->statusflags |= TXSTOPPED;
3179 memoff(ch); 2620 memoff(ch);
3180
3181 } /* End if transmit stop requested */ 2621 } /* End if transmit stop requested */
3182 2622 spin_unlock_irqrestore(&epca_lock, flags);
3183 restore_flags(flags);
3184
3185 } /* End if valid channel */ 2623 } /* End if valid channel */
3186
3187} /* End pc_stop */ 2624} /* End pc_stop */
3188 2625
3189/* --------------------- Begin pc_start ----------------------- */ 2626/* --------------------- Begin pc_start ----------------------- */
3190 2627
3191static void pc_start(struct tty_struct *tty) 2628static void pc_start(struct tty_struct *tty)
3192{ /* Begin pc_start */ 2629{ /* Begin pc_start */
3193
3194 struct channel *ch; 2630 struct channel *ch;
3195
3196 /* --------------------------------------------------------- 2631 /* ---------------------------------------------------------
3197 verifyChannel returns the channel from the tty struct 2632 verifyChannel returns the channel from the tty struct
3198 if it is valid. This serves as a sanity check. 2633 if it is valid. This serves as a sanity check.
3199 ------------------------------------------------------------- */ 2634 ------------------------------------------------------------- */
3200 2635 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
3201 if ((ch = verifyChannel(tty)) != NULL)
3202 { /* Begin if channel valid */
3203
3204 unsigned long flags; 2636 unsigned long flags;
3205 2637 spin_lock_irqsave(&epca_lock, flags);
3206 save_flags(flags);
3207 cli();
3208
3209 /* Just in case output was resumed because of a change in Digi-flow */ 2638 /* Just in case output was resumed because of a change in Digi-flow */
3210 if (ch->statusflags & TXSTOPPED) 2639 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
3211 { /* Begin transmit resume requested */ 2640 struct board_chan __iomem *bc;
3212
3213 volatile struct board_chan *bc;
3214
3215 globalwinon(ch); 2641 globalwinon(ch);
3216 bc = ch->brdchan; 2642 bc = ch->brdchan;
3217 if (ch->statusflags & LOWWAIT) 2643 if (ch->statusflags & LOWWAIT)
3218 bc->ilow = 1; 2644 writeb(1, &bc->ilow);
3219
3220 /* Okay, you can start transmitting again... */ 2645 /* Okay, you can start transmitting again... */
3221
3222 fepcmd(ch, RESUMETX, 0, 0, 0, 0); 2646 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
3223
3224 ch->statusflags &= ~TXSTOPPED; 2647 ch->statusflags &= ~TXSTOPPED;
3225 memoff(ch); 2648 memoff(ch);
3226
3227 } /* End transmit resume requested */ 2649 } /* End transmit resume requested */
3228 2650 spin_unlock_irqrestore(&epca_lock, flags);
3229 restore_flags(flags);
3230
3231 } /* End if channel valid */ 2651 } /* End if channel valid */
3232
3233} /* End pc_start */ 2652} /* End pc_start */
3234 2653
3235/* ------------------------------------------------------------------ 2654/* ------------------------------------------------------------------
@@ -3244,86 +2663,55 @@ ______________________________________________________________________ */
3244 2663
3245static void pc_throttle(struct tty_struct * tty) 2664static void pc_throttle(struct tty_struct * tty)
3246{ /* Begin pc_throttle */ 2665{ /* Begin pc_throttle */
3247
3248 struct channel *ch; 2666 struct channel *ch;
3249 unsigned long flags; 2667 unsigned long flags;
3250
3251 /* --------------------------------------------------------- 2668 /* ---------------------------------------------------------
3252 verifyChannel returns the channel from the tty struct 2669 verifyChannel returns the channel from the tty struct
3253 if it is valid. This serves as a sanity check. 2670 if it is valid. This serves as a sanity check.
3254 ------------------------------------------------------------- */ 2671 ------------------------------------------------------------- */
3255 2672 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
3256 if ((ch = verifyChannel(tty)) != NULL) 2673 spin_lock_irqsave(&epca_lock, flags);
3257 { /* Begin if channel valid */ 2674 if ((ch->statusflags & RXSTOPPED) == 0) {
3258
3259
3260 save_flags(flags);
3261 cli();
3262
3263 if ((ch->statusflags & RXSTOPPED) == 0)
3264 {
3265 globalwinon(ch); 2675 globalwinon(ch);
3266 fepcmd(ch, PAUSERX, 0, 0, 0, 0); 2676 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
3267
3268 ch->statusflags |= RXSTOPPED; 2677 ch->statusflags |= RXSTOPPED;
3269 memoff(ch); 2678 memoff(ch);
3270 } 2679 }
3271 restore_flags(flags); 2680 spin_unlock_irqrestore(&epca_lock, flags);
3272
3273 } /* End if channel valid */ 2681 } /* End if channel valid */
3274
3275} /* End pc_throttle */ 2682} /* End pc_throttle */
3276 2683
3277/* --------------------- Begin unthrottle ----------------------- */ 2684/* --------------------- Begin unthrottle ----------------------- */
3278 2685
3279static void pc_unthrottle(struct tty_struct *tty) 2686static void pc_unthrottle(struct tty_struct *tty)
3280{ /* Begin pc_unthrottle */ 2687{ /* Begin pc_unthrottle */
3281
3282 struct channel *ch; 2688 struct channel *ch;
3283 unsigned long flags; 2689 unsigned long flags;
3284 volatile struct board_chan *bc;
3285
3286
3287 /* --------------------------------------------------------- 2690 /* ---------------------------------------------------------
3288 verifyChannel returns the channel from the tty struct 2691 verifyChannel returns the channel from the tty struct
3289 if it is valid. This serves as a sanity check. 2692 if it is valid. This serves as a sanity check.
3290 ------------------------------------------------------------- */ 2693 ------------------------------------------------------------- */
3291 2694 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
3292 if ((ch = verifyChannel(tty)) != NULL)
3293 { /* Begin if channel valid */
3294
3295
3296 /* Just in case output was resumed because of a change in Digi-flow */ 2695 /* Just in case output was resumed because of a change in Digi-flow */
3297 save_flags(flags); 2696 spin_lock_irqsave(&epca_lock, flags);
3298 cli(); 2697 if (ch->statusflags & RXSTOPPED) {
3299
3300 if (ch->statusflags & RXSTOPPED)
3301 {
3302
3303 globalwinon(ch); 2698 globalwinon(ch);
3304 bc = ch->brdchan;
3305 fepcmd(ch, RESUMERX, 0, 0, 0, 0); 2699 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
3306
3307 ch->statusflags &= ~RXSTOPPED; 2700 ch->statusflags &= ~RXSTOPPED;
3308 memoff(ch); 2701 memoff(ch);
3309 } 2702 }
3310 restore_flags(flags); 2703 spin_unlock_irqrestore(&epca_lock, flags);
3311
3312 } /* End if channel valid */ 2704 } /* End if channel valid */
3313
3314} /* End pc_unthrottle */ 2705} /* End pc_unthrottle */
3315 2706
3316/* --------------------- Begin digi_send_break ----------------------- */ 2707/* --------------------- Begin digi_send_break ----------------------- */
3317 2708
3318void digi_send_break(struct channel *ch, int msec) 2709void digi_send_break(struct channel *ch, int msec)
3319{ /* Begin digi_send_break */ 2710{ /* Begin digi_send_break */
3320
3321 unsigned long flags; 2711 unsigned long flags;
3322 2712
3323 save_flags(flags); 2713 spin_lock_irqsave(&epca_lock, flags);
3324 cli();
3325 globalwinon(ch); 2714 globalwinon(ch);
3326
3327 /* -------------------------------------------------------------------- 2715 /* --------------------------------------------------------------------
3328 Maybe I should send an infinite break here, schedule() for 2716 Maybe I should send an infinite break here, schedule() for
3329 msec amount of time, and then stop the break. This way, 2717 msec amount of time, and then stop the break. This way,
@@ -3331,36 +2719,28 @@ void digi_send_break(struct channel *ch, int msec)
3331 to be called (i.e. via an ioctl()) more than once in msec amount 2719 to be called (i.e. via an ioctl()) more than once in msec amount
3332 of time. Try this for now... 2720 of time. Try this for now...
3333 ------------------------------------------------------------------------ */ 2721 ------------------------------------------------------------------------ */
3334
3335 fepcmd(ch, SENDBREAK, msec, 0, 10, 0); 2722 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
3336 memoff(ch); 2723 memoff(ch);
3337 2724 spin_unlock_irqrestore(&epca_lock, flags);
3338 restore_flags(flags);
3339
3340} /* End digi_send_break */ 2725} /* End digi_send_break */
3341 2726
3342/* --------------------- Begin setup_empty_event ----------------------- */ 2727/* --------------------- Begin setup_empty_event ----------------------- */
3343 2728
2729/* Caller MUST hold the lock */
2730
3344static void setup_empty_event(struct tty_struct *tty, struct channel *ch) 2731static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
3345{ /* Begin setup_empty_event */ 2732{ /* Begin setup_empty_event */
3346 2733
3347 volatile struct board_chan *bc = ch->brdchan; 2734 struct board_chan __iomem *bc = ch->brdchan;
3348 unsigned long int flags;
3349 2735
3350 save_flags(flags);
3351 cli();
3352 globalwinon(ch); 2736 globalwinon(ch);
3353 ch->statusflags |= EMPTYWAIT; 2737 ch->statusflags |= EMPTYWAIT;
3354
3355 /* ------------------------------------------------------------------ 2738 /* ------------------------------------------------------------------
3356 When set the iempty flag request a event to be generated when the 2739 When set the iempty flag request a event to be generated when the
3357 transmit buffer is empty (If there is no BREAK in progress). 2740 transmit buffer is empty (If there is no BREAK in progress).
3358 --------------------------------------------------------------------- */ 2741 --------------------------------------------------------------------- */
3359 2742 writeb(1, &bc->iempty);
3360 bc->iempty = 1;
3361 memoff(ch); 2743 memoff(ch);
3362 restore_flags(flags);
3363
3364} /* End setup_empty_event */ 2744} /* End setup_empty_event */
3365 2745
3366/* --------------------- Begin get_termio ----------------------- */ 2746/* --------------------- Begin get_termio ----------------------- */
@@ -3369,10 +2749,10 @@ static int get_termio(struct tty_struct * tty, struct termio __user * termio)
3369{ /* Begin get_termio */ 2749{ /* Begin get_termio */
3370 return kernel_termios_to_user_termio(termio, tty->termios); 2750 return kernel_termios_to_user_termio(termio, tty->termios);
3371} /* End get_termio */ 2751} /* End get_termio */
2752
3372/* ---------------------- Begin epca_setup -------------------------- */ 2753/* ---------------------- Begin epca_setup -------------------------- */
3373void epca_setup(char *str, int *ints) 2754void epca_setup(char *str, int *ints)
3374{ /* Begin epca_setup */ 2755{ /* Begin epca_setup */
3375
3376 struct board_info board; 2756 struct board_info board;
3377 int index, loop, last; 2757 int index, loop, last;
3378 char *temp, *t2; 2758 char *temp, *t2;
@@ -3394,49 +2774,41 @@ void epca_setup(char *str, int *ints)
3394 for (last = 0, index = 1; index <= ints[0]; index++) 2774 for (last = 0, index = 1; index <= ints[0]; index++)
3395 switch(index) 2775 switch(index)
3396 { /* Begin parse switch */ 2776 { /* Begin parse switch */
3397
3398 case 1: 2777 case 1:
3399 board.status = ints[index]; 2778 board.status = ints[index];
3400
3401 /* --------------------------------------------------------- 2779 /* ---------------------------------------------------------
3402 We check for 2 (As opposed to 1; because 2 is a flag 2780 We check for 2 (As opposed to 1; because 2 is a flag
3403 instructing the driver to ignore epcaconfig.) For this 2781 instructing the driver to ignore epcaconfig.) For this
3404 reason we check for 2. 2782 reason we check for 2.
3405 ------------------------------------------------------------ */ 2783 ------------------------------------------------------------ */
3406 if (board.status == 2) 2784 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
3407 { /* Begin ignore epcaconfig as well as lilo cmd line */
3408 nbdevs = 0; 2785 nbdevs = 0;
3409 num_cards = 0; 2786 num_cards = 0;
3410 return; 2787 return;
3411 } /* End ignore epcaconfig as well as lilo cmd line */ 2788 } /* End ignore epcaconfig as well as lilo cmd line */
3412 2789
3413 if (board.status > 2) 2790 if (board.status > 2) {
3414 { 2791 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
3415 printk(KERN_ERR "<Error> - epca_setup: Invalid board status 0x%x\n", board.status);
3416 invalid_lilo_config = 1; 2792 invalid_lilo_config = 1;
3417 setup_error_code |= INVALID_BOARD_STATUS; 2793 setup_error_code |= INVALID_BOARD_STATUS;
3418 return; 2794 return;
3419 } 2795 }
3420 last = index; 2796 last = index;
3421 break; 2797 break;
3422
3423 case 2: 2798 case 2:
3424 board.type = ints[index]; 2799 board.type = ints[index];
3425 if (board.type >= PCIXEM) 2800 if (board.type >= PCIXEM) {
3426 { 2801 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
3427 printk(KERN_ERR "<Error> - epca_setup: Invalid board type 0x%x\n", board.type);
3428 invalid_lilo_config = 1; 2802 invalid_lilo_config = 1;
3429 setup_error_code |= INVALID_BOARD_TYPE; 2803 setup_error_code |= INVALID_BOARD_TYPE;
3430 return; 2804 return;
3431 } 2805 }
3432 last = index; 2806 last = index;
3433 break; 2807 break;
3434
3435 case 3: 2808 case 3:
3436 board.altpin = ints[index]; 2809 board.altpin = ints[index];
3437 if (board.altpin > 1) 2810 if (board.altpin > 1) {
3438 { 2811 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
3439 printk(KERN_ERR "<Error> - epca_setup: Invalid board altpin 0x%x\n", board.altpin);
3440 invalid_lilo_config = 1; 2812 invalid_lilo_config = 1;
3441 setup_error_code |= INVALID_ALTPIN; 2813 setup_error_code |= INVALID_ALTPIN;
3442 return; 2814 return;
@@ -3446,9 +2818,8 @@ void epca_setup(char *str, int *ints)
3446 2818
3447 case 4: 2819 case 4:
3448 board.numports = ints[index]; 2820 board.numports = ints[index];
3449 if ((board.numports < 2) || (board.numports > 256)) 2821 if (board.numports < 2 || board.numports > 256) {
3450 { 2822 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
3451 printk(KERN_ERR "<Error> - epca_setup: Invalid board numports 0x%x\n", board.numports);
3452 invalid_lilo_config = 1; 2823 invalid_lilo_config = 1;
3453 setup_error_code |= INVALID_NUM_PORTS; 2824 setup_error_code |= INVALID_NUM_PORTS;
3454 return; 2825 return;
@@ -3458,10 +2829,9 @@ void epca_setup(char *str, int *ints)
3458 break; 2829 break;
3459 2830
3460 case 5: 2831 case 5:
3461 board.port = (unsigned char *)ints[index]; 2832 board.port = ints[index];
3462 if (ints[index] <= 0) 2833 if (ints[index] <= 0) {
3463 { 2834 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
3464 printk(KERN_ERR "<Error> - epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
3465 invalid_lilo_config = 1; 2835 invalid_lilo_config = 1;
3466 setup_error_code |= INVALID_PORT_BASE; 2836 setup_error_code |= INVALID_PORT_BASE;
3467 return; 2837 return;
@@ -3470,10 +2840,9 @@ void epca_setup(char *str, int *ints)
3470 break; 2840 break;
3471 2841
3472 case 6: 2842 case 6:
3473 board.membase = (unsigned char *)ints[index]; 2843 board.membase = ints[index];
3474 if (ints[index] <= 0) 2844 if (ints[index] <= 0) {
3475 { 2845 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
3476 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
3477 invalid_lilo_config = 1; 2846 invalid_lilo_config = 1;
3478 setup_error_code |= INVALID_MEM_BASE; 2847 setup_error_code |= INVALID_MEM_BASE;
3479 return; 2848 return;
@@ -3487,21 +2856,16 @@ void epca_setup(char *str, int *ints)
3487 2856
3488 } /* End parse switch */ 2857 } /* End parse switch */
3489 2858
3490 while (str && *str) 2859 while (str && *str) { /* Begin while there is a string arg */
3491 { /* Begin while there is a string arg */
3492
3493 /* find the next comma or terminator */ 2860 /* find the next comma or terminator */
3494 temp = str; 2861 temp = str;
3495
3496 /* While string is not null, and a comma hasn't been found */ 2862 /* While string is not null, and a comma hasn't been found */
3497 while (*temp && (*temp != ',')) 2863 while (*temp && (*temp != ','))
3498 temp++; 2864 temp++;
3499
3500 if (!*temp) 2865 if (!*temp)
3501 temp = NULL; 2866 temp = NULL;
3502 else 2867 else
3503 *temp++ = 0; 2868 *temp++ = 0;
3504
3505 /* Set index to the number of args + 1 */ 2869 /* Set index to the number of args + 1 */
3506 index = last + 1; 2870 index = last + 1;
3507 2871
@@ -3511,12 +2875,10 @@ void epca_setup(char *str, int *ints)
3511 len = strlen(str); 2875 len = strlen(str);
3512 if (strncmp("Disable", str, len) == 0) 2876 if (strncmp("Disable", str, len) == 0)
3513 board.status = 0; 2877 board.status = 0;
3514 else 2878 else if (strncmp("Enable", str, len) == 0)
3515 if (strncmp("Enable", str, len) == 0)
3516 board.status = 1; 2879 board.status = 1;
3517 else 2880 else {
3518 { 2881 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
3519 printk(KERN_ERR "<Error> - epca_setup: Invalid status %s\n", str);
3520 invalid_lilo_config = 1; 2882 invalid_lilo_config = 1;
3521 setup_error_code |= INVALID_BOARD_STATUS; 2883 setup_error_code |= INVALID_BOARD_STATUS;
3522 return; 2884 return;
@@ -3525,22 +2887,17 @@ void epca_setup(char *str, int *ints)
3525 break; 2887 break;
3526 2888
3527 case 2: 2889 case 2:
3528
3529 for(loop = 0; loop < EPCA_NUM_TYPES; loop++) 2890 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
3530 if (strcmp(board_desc[loop], str) == 0) 2891 if (strcmp(board_desc[loop], str) == 0)
3531 break; 2892 break;
3532
3533
3534 /* --------------------------------------------------------------- 2893 /* ---------------------------------------------------------------
3535 If the index incremented above refers to a legitamate board 2894 If the index incremented above refers to a legitamate board
3536 type set it here. 2895 type set it here.
3537 ------------------------------------------------------------------*/ 2896 ------------------------------------------------------------------*/
3538
3539 if (index < EPCA_NUM_TYPES) 2897 if (index < EPCA_NUM_TYPES)
3540 board.type = loop; 2898 board.type = loop;
3541 else 2899 else {
3542 { 2900 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
3543 printk(KERN_ERR "<Error> - epca_setup: Invalid board type: %s\n", str);
3544 invalid_lilo_config = 1; 2901 invalid_lilo_config = 1;
3545 setup_error_code |= INVALID_BOARD_TYPE; 2902 setup_error_code |= INVALID_BOARD_TYPE;
3546 return; 2903 return;
@@ -3552,12 +2909,10 @@ void epca_setup(char *str, int *ints)
3552 len = strlen(str); 2909 len = strlen(str);
3553 if (strncmp("Disable", str, len) == 0) 2910 if (strncmp("Disable", str, len) == 0)
3554 board.altpin = 0; 2911 board.altpin = 0;
3555 else 2912 else if (strncmp("Enable", str, len) == 0)
3556 if (strncmp("Enable", str, len) == 0)
3557 board.altpin = 1; 2913 board.altpin = 1;
3558 else 2914 else {
3559 { 2915 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
3560 printk(KERN_ERR "<Error> - epca_setup: Invalid altpin %s\n", str);
3561 invalid_lilo_config = 1; 2916 invalid_lilo_config = 1;
3562 setup_error_code |= INVALID_ALTPIN; 2917 setup_error_code |= INVALID_ALTPIN;
3563 return; 2918 return;
@@ -3570,9 +2925,8 @@ void epca_setup(char *str, int *ints)
3570 while (isdigit(*t2)) 2925 while (isdigit(*t2))
3571 t2++; 2926 t2++;
3572 2927
3573 if (*t2) 2928 if (*t2) {
3574 { 2929 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
3575 printk(KERN_ERR "<Error> - epca_setup: Invalid port count %s\n", str);
3576 invalid_lilo_config = 1; 2930 invalid_lilo_config = 1;
3577 setup_error_code |= INVALID_NUM_PORTS; 2931 setup_error_code |= INVALID_NUM_PORTS;
3578 return; 2932 return;
@@ -3601,15 +2955,14 @@ void epca_setup(char *str, int *ints)
3601 while (isxdigit(*t2)) 2955 while (isxdigit(*t2))
3602 t2++; 2956 t2++;
3603 2957
3604 if (*t2) 2958 if (*t2) {
3605 { 2959 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
3606 printk(KERN_ERR "<Error> - epca_setup: Invalid i/o address %s\n", str);
3607 invalid_lilo_config = 1; 2960 invalid_lilo_config = 1;
3608 setup_error_code |= INVALID_PORT_BASE; 2961 setup_error_code |= INVALID_PORT_BASE;
3609 return; 2962 return;
3610 } 2963 }
3611 2964
3612 board.port = (unsigned char *)simple_strtoul(str, NULL, 16); 2965 board.port = simple_strtoul(str, NULL, 16);
3613 last = index; 2966 last = index;
3614 break; 2967 break;
3615 2968
@@ -3618,52 +2971,38 @@ void epca_setup(char *str, int *ints)
3618 while (isxdigit(*t2)) 2971 while (isxdigit(*t2))
3619 t2++; 2972 t2++;
3620 2973
3621 if (*t2) 2974 if (*t2) {
3622 { 2975 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
3623 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base %s\n",str);
3624 invalid_lilo_config = 1; 2976 invalid_lilo_config = 1;
3625 setup_error_code |= INVALID_MEM_BASE; 2977 setup_error_code |= INVALID_MEM_BASE;
3626 return; 2978 return;
3627 } 2979 }
3628 2980 board.membase = simple_strtoul(str, NULL, 16);
3629 board.membase = (unsigned char *)simple_strtoul(str, NULL, 16);
3630 last = index; 2981 last = index;
3631 break; 2982 break;
3632
3633 default: 2983 default:
3634 printk(KERN_ERR "PC/Xx: Too many string parms\n"); 2984 printk(KERN_ERR "epca: Too many string parms\n");
3635 return; 2985 return;
3636 } 2986 }
3637 str = temp; 2987 str = temp;
3638
3639 } /* End while there is a string arg */ 2988 } /* End while there is a string arg */
3640 2989
3641 2990 if (last < 6) {
3642 if (last < 6) 2991 printk(KERN_ERR "epca: Insufficient parms specified\n");
3643 {
3644 printk(KERN_ERR "PC/Xx: Insufficient parms specified\n");
3645 return; 2992 return;
3646 } 2993 }
3647 2994
3648 /* I should REALLY validate the stuff here */ 2995 /* I should REALLY validate the stuff here */
3649
3650 /* Copies our local copy of board into boards */ 2996 /* Copies our local copy of board into boards */
3651 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board)); 2997 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
3652
3653
3654 /* Does this get called once per lilo arg are what ? */ 2998 /* Does this get called once per lilo arg are what ? */
3655
3656 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n", 2999 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
3657 num_cards, board_desc[board.type], 3000 num_cards, board_desc[board.type],
3658 board.numports, (int)board.port, (unsigned int) board.membase); 3001 board.numports, (int)board.port, (unsigned int) board.membase);
3659
3660 num_cards++; 3002 num_cards++;
3661
3662} /* End epca_setup */ 3003} /* End epca_setup */
3663 3004
3664 3005
3665
3666#ifdef ENABLE_PCI
3667/* ------------------------ Begin init_PCI --------------------------- */ 3006/* ------------------------ Begin init_PCI --------------------------- */
3668 3007
3669enum epic_board_types { 3008enum epic_board_types {
@@ -3685,7 +3024,6 @@ static struct {
3685 { PCIXRJ, 2, }, 3024 { PCIXRJ, 2, },
3686}; 3025};
3687 3026
3688
3689static int __devinit epca_init_one (struct pci_dev *pdev, 3027static int __devinit epca_init_one (struct pci_dev *pdev,
3690 const struct pci_device_id *ent) 3028 const struct pci_device_id *ent)
3691{ 3029{
@@ -3711,10 +3049,8 @@ static int __devinit epca_init_one (struct pci_dev *pdev,
3711 boards[board_idx].status = ENABLED; 3049 boards[board_idx].status = ENABLED;
3712 boards[board_idx].type = epca_info_tbl[info_idx].board_type; 3050 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3713 boards[board_idx].numports = 0x0; 3051 boards[board_idx].numports = 0x0;
3714 boards[board_idx].port = 3052 boards[board_idx].port = addr + PCI_IO_OFFSET;
3715 (unsigned char *)((char *) addr + PCI_IO_OFFSET); 3053 boards[board_idx].membase = addr;
3716 boards[board_idx].membase =
3717 (unsigned char *)((char *) addr);
3718 3054
3719 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) { 3055 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3720 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n", 3056 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
@@ -3775,15 +3111,13 @@ static struct pci_device_id epca_pci_tbl[] = {
3775MODULE_DEVICE_TABLE(pci, epca_pci_tbl); 3111MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3776 3112
3777int __init init_PCI (void) 3113int __init init_PCI (void)
3778{ /* Begin init_PCI */ 3114{ /* Begin init_PCI */
3779 memset (&epca_driver, 0, sizeof (epca_driver)); 3115 memset (&epca_driver, 0, sizeof (epca_driver));
3780 epca_driver.name = "epca"; 3116 epca_driver.name = "epca";
3781 epca_driver.id_table = epca_pci_tbl; 3117 epca_driver.id_table = epca_pci_tbl;
3782 epca_driver.probe = epca_init_one; 3118 epca_driver.probe = epca_init_one;
3783 3119
3784 return pci_register_driver(&epca_driver); 3120 return pci_register_driver(&epca_driver);
3785} /* End init_PCI */ 3121}
3786
3787#endif /* ENABLE_PCI */
3788 3122
3789MODULE_LICENSE("GPL"); 3123MODULE_LICENSE("GPL");